feat(editor): add block meta for more blocks (#11034)

This commit is contained in:
Saul-Mirone
2025-03-20 10:08:01 +00:00
parent 27a8afa33f
commit c1ec17ccba
4 changed files with 40 additions and 14 deletions

View File

@@ -9,7 +9,7 @@ import {
defineBlockSchema, defineBlockSchema,
} from '@blocksuite/store'; } from '@blocksuite/store';
import type { EmbedCardStyle } from '../../utils/index.js'; import type { BlockMeta, EmbedCardStyle } from '../../utils/index.js';
import { AttachmentBlockTransformer } from './attachment-transformer.js'; import { AttachmentBlockTransformer } from './attachment-transformer.js';
/** /**
@@ -55,7 +55,8 @@ export type AttachmentBlockProps = {
embed: boolean | BackwardCompatibleUndefined; embed: boolean | BackwardCompatibleUndefined;
style?: (typeof AttachmentBlockStyles)[number]; style?: (typeof AttachmentBlockStyles)[number];
} & Omit<GfxCommonBlockProps, 'scale'>; } & Omit<GfxCommonBlockProps, 'scale'> &
BlockMeta;
export const defaultAttachmentProps: AttachmentBlockProps = { export const defaultAttachmentProps: AttachmentBlockProps = {
name: '', name: '',
@@ -69,6 +70,10 @@ export const defaultAttachmentProps: AttachmentBlockProps = {
xywh: '[0,0,0,0]', xywh: '[0,0,0,0]',
lockedBySelf: false, lockedBySelf: false,
rotate: 0, rotate: 0,
'meta:createdAt': undefined,
'meta:updatedAt': undefined,
'meta:createdBy': undefined,
'meta:updatedBy': undefined,
}; };
export const AttachmentBlockSchema = defineBlockSchema({ export const AttachmentBlockSchema = defineBlockSchema({

View File

@@ -9,7 +9,11 @@ import {
defineBlockSchema, defineBlockSchema,
} from '@blocksuite/store'; } from '@blocksuite/store';
import type { EmbedCardStyle, LinkPreviewData } from '../../utils/index.js'; import type {
BlockMeta,
EmbedCardStyle,
LinkPreviewData,
} from '../../utils/index.js';
export const BookmarkStyles: EmbedCardStyle[] = [ export const BookmarkStyles: EmbedCardStyle[] = [
'vertical', 'vertical',
@@ -23,7 +27,8 @@ export type BookmarkBlockProps = {
url: string; url: string;
caption: string | null; caption: string | null;
} & LinkPreviewData & } & LinkPreviewData &
Omit<GfxCommonBlockProps, 'scale'>; Omit<GfxCommonBlockProps, 'scale'> &
BlockMeta;
const defaultBookmarkProps: BookmarkBlockProps = { const defaultBookmarkProps: BookmarkBlockProps = {
style: BookmarkStyles[1], style: BookmarkStyles[1],
@@ -39,6 +44,10 @@ const defaultBookmarkProps: BookmarkBlockProps = {
xywh: '[0,0,0,0]', xywh: '[0,0,0,0]',
lockedBySelf: false, lockedBySelf: false,
rotate: 0, rotate: 0,
'meta:createdAt': undefined,
'meta:updatedAt': undefined,
'meta:createdBy': undefined,
'meta:updatedBy': undefined,
}; };
export const BookmarkBlockSchema = defineBlockSchema({ export const BookmarkBlockSchema = defineBlockSchema({

View File

@@ -5,11 +5,22 @@ import {
type Text, type Text,
} from '@blocksuite/store'; } from '@blocksuite/store';
import type { BlockMeta } from '../../utils/types';
export type CalloutProps = {
emoji: string;
text: Text;
} & BlockMeta;
export const CalloutBlockSchema = defineBlockSchema({ export const CalloutBlockSchema = defineBlockSchema({
flavour: 'affine:callout', flavour: 'affine:callout',
props: internal => ({ props: (internal): CalloutProps => ({
emoji: '😀', emoji: '😀',
text: internal.Text(), text: internal.Text(),
'meta:createdAt': undefined,
'meta:updatedAt': undefined,
'meta:createdBy': undefined,
'meta:updatedBy': undefined,
}), }),
metadata: { metadata: {
version: 1, version: 1,
@@ -26,11 +37,6 @@ export const CalloutBlockSchema = defineBlockSchema({
toModel: () => new CalloutBlockModel(), toModel: () => new CalloutBlockModel(),
}); });
export type CalloutProps = {
emoji: string;
text: Text;
};
export class CalloutBlockModel extends BlockModel<CalloutProps> {} export class CalloutBlockModel extends BlockModel<CalloutProps> {}
export const CalloutBlockSchemaExtension = export const CalloutBlockSchemaExtension =

View File

@@ -8,17 +8,19 @@ import {
type InternalPrimitives, type InternalPrimitives,
} from '@blocksuite/store'; } from '@blocksuite/store';
import type { BlockMeta } from './types';
export type EmbedProps<Props = object> = Props & GfxCompatibleProps & BlockMeta;
export function defineEmbedModel< export function defineEmbedModel<
Props extends object, Props extends object,
T extends Constructor<BlockModel<Props>> = Constructor<BlockModel<Props>>, T extends Constructor<BlockModel<Props>> = Constructor<BlockModel<Props>>,
>(BlockModelSuperClass: T) { >(BlockModelSuperClass: T) {
return GfxCompatible<Props & GfxCompatibleProps>( return GfxCompatible<EmbedProps<Props>>(
BlockModelSuperClass as Constructor<BlockModel<Props & GfxCompatibleProps>> BlockModelSuperClass as Constructor<BlockModel<EmbedProps<Props>>>
); );
} }
export type EmbedProps<Props = object> = Props & GfxCompatibleProps;
export type EmbedBlockModel<Props = object> = BlockModel<EmbedProps<Props>>; export type EmbedBlockModel<Props = object> = BlockModel<EmbedProps<Props>>;
export function createEmbedBlockSchema< export function createEmbedBlockSchema<
@@ -50,6 +52,10 @@ export function createEmbedBlockSchema<
xywh: '[0,0,0,0]', xywh: '[0,0,0,0]',
lockedBySelf: false, lockedBySelf: false,
rotate: 0, rotate: 0,
'meta:createdAt': undefined,
'meta:updatedAt': undefined,
'meta:createdBy': undefined,
'meta:updatedBy': undefined,
...userProps, ...userProps,
} as unknown as EmbedProps<Props>; } as unknown as EmbedProps<Props>;
}, },