feat(editor): simple table block (#9740)

close: BS-2122, BS-2125, BS-2124, BS-2420, PD-2073, BS-2126, BS-2469, BS-2470, BS-2478, BS-2471
This commit is contained in:
zzj3720
2025-01-24 10:07:57 +00:00
parent 3f4311ff1c
commit 5a5779c05a
61 changed files with 3577 additions and 381 deletions

View File

@@ -13,3 +13,4 @@ export * from './note/index.js';
export * from './paragraph/index.js';
export * from './root/index.js';
export * from './surface-ref/index.js';
export * from './table';

View File

@@ -47,6 +47,7 @@ export const NoteZodSchema = z
},
},
});
import { TableModelFlavour } from '../table';
export const NoteBlockSchema = defineBlockSchema({
flavour: 'affine:note',
@@ -83,6 +84,7 @@ export const NoteBlockSchema = defineBlockSchema({
'affine:surface-ref',
'affine:embed-*',
'affine:latex',
TableModelFlavour,
],
},
toModel: () => {

View File

@@ -0,0 +1 @@
export * from './table-model';

View File

@@ -0,0 +1,65 @@
import type { DeltaInsert } from '@blocksuite/inline';
import type { Text } from '@blocksuite/store';
import { BlockModel, defineBlockSchema } from '@blocksuite/store';
export type TableCell = {
text: Text;
};
export interface TableRow {
rowId: string;
order: string;
backgroundColor?: string;
}
export interface TableColumn {
columnId: string;
order: string;
backgroundColor?: string;
width?: number;
}
export interface TableBlockProps {
rows: Record<string, TableRow>;
columns: Record<string, TableColumn>;
// key = `${rowId}:${columnId}`
cells: Record<string, TableCell>;
}
export interface TableCellSerialized {
text: {
delta: DeltaInsert[];
};
}
export interface TableBlockPropsSerialized {
rows: Record<string, TableRow>;
columns: Record<string, TableColumn>;
cells: Record<string, TableCellSerialized>;
}
export class TableBlockModel extends BlockModel<TableBlockProps> {}
export const TableModelFlavour = 'affine:table-test1-flavour';
export const TableBlockSchema = defineBlockSchema({
flavour: TableModelFlavour,
props: (): TableBlockProps => ({
rows: {},
columns: {},
cells: {},
}),
metadata: {
role: 'content',
version: 1,
parent: ['affine:note'],
children: [],
},
toModel: () => new TableBlockModel(),
});
declare global {
namespace BlockSuite {
interface BlockModels {
[TableModelFlavour]: TableBlockModel;
}
}
}