Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

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

Saul-Mironec1ec17ccba04
diff --git a/blocksuite/affine/model/src/blocks/attachment/attachment-model.ts b/blocksuite/affine/model/src/blocks/attachment/attachment-model.ts
index 9120f3eaed..b972454e9e 100644
--- a/blocksuite/affine/model/src/blocks/attachment/attachment-model.ts
+++ b/blocksuite/affine/model/src/blocks/attachment/attachment-model.ts
@@ -9,7 +9,7 @@ import {
defineBlockSchema,
} from '@blocksuite/store';
-import type { EmbedCardStyle } from '../../utils/index.js';
+import type { BlockMeta, EmbedCardStyle } from '../../utils/index.js';
import { AttachmentBlockTransformer } from './attachment-transformer.js';
/**
@@ -55,7 +55,8 @@ export type AttachmentBlockProps = {
embed: boolean | BackwardCompatibleUndefined;
style?: (typeof AttachmentBlockStyles)[number];
-} & Omit<GfxCommonBlockProps, 'scale'>;
+} & Omit<GfxCommonBlockProps, 'scale'> &
+ BlockMeta;
export const defaultAttachmentProps: AttachmentBlockProps = {
name: '',
@@ -69,6 +70,10 @@ export const defaultAttachmentProps: AttachmentBlockProps = {
xywh: '[0,0,0,0]',
lockedBySelf: false,
rotate: 0,
+ 'meta:createdAt': undefined,
+ 'meta:updatedAt': undefined,
+ 'meta:createdBy': undefined,
+ 'meta:updatedBy': undefined,
};
export const AttachmentBlockSchema = defineBlockSchema({
diff --git a/blocksuite/affine/model/src/blocks/bookmark/bookmark-model.ts b/blocksuite/affine/model/src/blocks/bookmark/bookmark-model.ts
index b75c1791ea..4046143f99 100644
--- a/blocksuite/affine/model/src/blocks/bookmark/bookmark-model.ts
+++ b/blocksuite/affine/model/src/blocks/bookmark/bookmark-model.ts
@@ -9,7 +9,11 @@ import {
defineBlockSchema,
} from '@blocksuite/store';
-import type { EmbedCardStyle, LinkPreviewData } from '../../utils/index.js';
+import type {
+ BlockMeta,
+ EmbedCardStyle,
+ LinkPreviewData,
+} from '../../utils/index.js';
export const BookmarkStyles: EmbedCardStyle[] = [
'vertical',
@@ -23,7 +27,8 @@ export type BookmarkBlockProps = {
url: string;
caption: string | null;
} & LinkPreviewData &
- Omit<GfxCommonBlockProps, 'scale'>;
+ Omit<GfxCommonBlockProps, 'scale'> &
+ BlockMeta;
const defaultBookmarkProps: BookmarkBlockProps = {
style: BookmarkStyles[1],
@@ -39,6 +44,10 @@ const defaultBookmarkProps: BookmarkBlockProps = {
xywh: '[0,0,0,0]',
lockedBySelf: false,
rotate: 0,
+ 'meta:createdAt': undefined,
+ 'meta:updatedAt': undefined,
+ 'meta:createdBy': undefined,
+ 'meta:updatedBy': undefined,
};
export const BookmarkBlockSchema = defineBlockSchema({
diff --git a/blocksuite/affine/model/src/blocks/callout/callout-model.ts b/blocksuite/affine/model/src/blocks/callout/callout-model.ts
index 881bb6d65b..a706390d73 100644
--- a/blocksuite/affine/model/src/blocks/callout/callout-model.ts
+++ b/blocksuite/affine/model/src/blocks/callout/callout-model.ts
@@ -5,11 +5,22 @@ import {
type Text,
} from '@blocksuite/store';
+import type { BlockMeta } from '../../utils/types';
+
+export type CalloutProps = {
+ emoji: string;
+ text: Text;
+} & BlockMeta;
+
export const CalloutBlockSchema = defineBlockSchema({
flavour: 'affine:callout',
- props: internal => ({
+ props: (internal): CalloutProps => ({
emoji: '😀',
text: internal.Text(),
+ 'meta:createdAt': undefined,
+ 'meta:updatedAt': undefined,
+ 'meta:createdBy': undefined,
+ 'meta:updatedBy': undefined,
}),
metadata: {
version: 1,
@@ -26,11 +37,6 @@ export const CalloutBlockSchema = defineBlockSchema({
toModel: () => new CalloutBlockModel(),
});
-export type CalloutProps = {
- emoji: string;
- text: Text;
-};
-
export class CalloutBlockModel extends BlockModel<CalloutProps> {}
export const CalloutBlockSchemaExtension =
diff --git a/blocksuite/affine/model/src/utils/helper.ts b/blocksuite/affine/model/src/utils/helper.ts
index 2e69a14fa3..95f38d2c09 100644
--- a/blocksuite/affine/model/src/utils/helper.ts
+++ b/blocksuite/affine/model/src/utils/helper.ts
@@ -8,17 +8,19 @@ import {
type InternalPrimitives,
} from '@blocksuite/store';
+import type { BlockMeta } from './types';
+
+export type EmbedProps<Props = object> = Props & GfxCompatibleProps & BlockMeta;
+
export function defineEmbedModel<
Props extends object,
T extends Constructor<BlockModel<Props>> = Constructor<BlockModel<Props>>,
>(BlockModelSuperClass: T) {
- return GfxCompatible<Props & GfxCompatibleProps>(
- BlockModelSuperClass as Constructor<BlockModel<Props & GfxCompatibleProps>>
+ return GfxCompatible<EmbedProps<Props>>(
+ BlockModelSuperClass as Constructor<BlockModel<EmbedProps<Props>>>
);
}
-export type EmbedProps<Props = object> = Props & GfxCompatibleProps;
-
export type EmbedBlockModel<Props = object> = BlockModel<EmbedProps<Props>>;
export function createEmbedBlockSchema<
@@ -50,6 +52,10 @@ export function createEmbedBlockSchema<
xywh: '[0,0,0,0]',
lockedBySelf: false,
rotate: 0,
+ 'meta:createdAt': undefined,
+ 'meta:updatedAt': undefined,
+ 'meta:createdBy': undefined,
+ 'meta:updatedBy': undefined,
...userProps,
} as unknown as EmbedProps<Props>;
},