mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 18:26:05 +08:00
feat(editor): add block meta for more blocks (#11034)
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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>;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user