mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-08 20:57:08 +08:00
1f45cc5dec
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import type { PropertyMetaConfig } from '@blocksuite/data-view';
|
|
import type { DisposableMember } from '@blocksuite/global/disposable';
|
|
import type { Block, BlockModel } from '@blocksuite/store';
|
|
|
|
type PropertyMeta<
|
|
T extends BlockModel = BlockModel,
|
|
RawValue = unknown,
|
|
JsonValue = unknown,
|
|
ColumnData extends NonNullable<unknown> = NonNullable<unknown>,
|
|
> = {
|
|
name: string;
|
|
key: string;
|
|
metaConfig: PropertyMetaConfig<string, ColumnData, RawValue, JsonValue>;
|
|
getColumnData?: (block: T) => ColumnData;
|
|
setColumnData?: (block: T, data: ColumnData) => void;
|
|
get: (block: T) => RawValue;
|
|
set?: (block: T, value: RawValue) => void;
|
|
updated: (block: T, callback: () => void) => DisposableMember;
|
|
};
|
|
export type BlockMeta<T extends BlockModel = BlockModel> = {
|
|
selector: (block: Block) => boolean;
|
|
properties: PropertyMeta<T>[];
|
|
};
|
|
export const createBlockMeta = <T extends BlockModel>(
|
|
options: Omit<BlockMeta<T>, 'properties'>
|
|
) => {
|
|
const meta: BlockMeta = {
|
|
...options,
|
|
properties: [],
|
|
};
|
|
return {
|
|
...meta,
|
|
addProperty: <Value>(property: PropertyMeta<T, Value>) => {
|
|
meta.properties.push(property as PropertyMeta);
|
|
},
|
|
};
|
|
};
|