mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 22:37:04 +08:00
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:
@@ -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';
|
||||
|
||||
@@ -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: () => {
|
||||
|
||||
1
blocksuite/affine/model/src/blocks/table/index.ts
Normal file
1
blocksuite/affine/model/src/blocks/table/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './table-model';
|
||||
65
blocksuite/affine/model/src/blocks/table/table-model.ts
Normal file
65
blocksuite/affine/model/src/blocks/table/table-model.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user