mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-23 04:04:27 +08:00
feat(editor): add block meta for table block (#10915)
This commit is contained in:
@@ -6,6 +6,8 @@ import {
|
|||||||
defineBlockSchema,
|
defineBlockSchema,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
|
import type { BlockMeta } from '../../utils/types';
|
||||||
|
|
||||||
export type TableCell = {
|
export type TableCell = {
|
||||||
text: Text;
|
text: Text;
|
||||||
};
|
};
|
||||||
@@ -23,7 +25,7 @@ export interface TableColumn {
|
|||||||
width?: number;
|
width?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableBlockProps {
|
export interface TableBlockProps extends BlockMeta {
|
||||||
rows: Record<string, TableRow>;
|
rows: Record<string, TableRow>;
|
||||||
columns: Record<string, TableColumn>;
|
columns: Record<string, TableColumn>;
|
||||||
// key = `${rowId}:${columnId}`
|
// key = `${rowId}:${columnId}`
|
||||||
@@ -50,6 +52,10 @@ export const TableBlockSchema = defineBlockSchema({
|
|||||||
rows: {},
|
rows: {},
|
||||||
columns: {},
|
columns: {},
|
||||||
cells: {},
|
cells: {},
|
||||||
|
'meta:createdAt': undefined,
|
||||||
|
'meta:createdBy': undefined,
|
||||||
|
'meta:updatedAt': undefined,
|
||||||
|
'meta:updatedBy': undefined,
|
||||||
}),
|
}),
|
||||||
metadata: {
|
metadata: {
|
||||||
isFlatData: true,
|
isFlatData: true,
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ function updateSignal(
|
|||||||
basePath,
|
basePath,
|
||||||
initialized,
|
initialized,
|
||||||
onDispose,
|
onDispose,
|
||||||
|
shouldByPassYjs,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
const fullPath = basePath ? `${basePath}.${prop}` : prop;
|
const fullPath = basePath ? `${basePath}.${prop}` : prop;
|
||||||
@@ -69,6 +70,7 @@ function updateSignal(
|
|||||||
root,
|
root,
|
||||||
firstKey,
|
firstKey,
|
||||||
shouldByPassSignal,
|
shouldByPassSignal,
|
||||||
|
shouldByPassYjs,
|
||||||
byPassSignalUpdate,
|
byPassSignalUpdate,
|
||||||
onChange,
|
onChange,
|
||||||
basePath,
|
basePath,
|
||||||
|
|||||||
@@ -3,7 +3,12 @@ import type { CreateProxyOptions } from './types';
|
|||||||
|
|
||||||
type UpdateSignalOptions = Pick<
|
type UpdateSignalOptions = Pick<
|
||||||
CreateProxyOptions,
|
CreateProxyOptions,
|
||||||
'shouldByPassSignal' | 'root' | 'onChange' | 'byPassSignalUpdate' | 'basePath'
|
| 'shouldByPassSignal'
|
||||||
|
| 'root'
|
||||||
|
| 'onChange'
|
||||||
|
| 'byPassSignalUpdate'
|
||||||
|
| 'basePath'
|
||||||
|
| 'shouldByPassYjs'
|
||||||
> & {
|
> & {
|
||||||
firstKey: string;
|
firstKey: string;
|
||||||
value: unknown;
|
value: unknown;
|
||||||
@@ -19,6 +24,7 @@ export function signalUpdater({
|
|||||||
basePath,
|
basePath,
|
||||||
value,
|
value,
|
||||||
handleNestedUpdate,
|
handleNestedUpdate,
|
||||||
|
shouldByPassYjs,
|
||||||
}: UpdateSignalOptions): void {
|
}: UpdateSignalOptions): void {
|
||||||
const isRoot = !basePath;
|
const isRoot = !basePath;
|
||||||
if (shouldByPassSignal()) {
|
if (shouldByPassSignal()) {
|
||||||
@@ -44,6 +50,9 @@ export function signalUpdater({
|
|||||||
: prev;
|
: prev;
|
||||||
// @ts-expect-error allow magic props
|
// @ts-expect-error allow magic props
|
||||||
root[signalKey].value = next;
|
root[signalKey].value = next;
|
||||||
onChange?.(firstKey, true);
|
// If the update is from yjs, it's already called from y-event-handler
|
||||||
|
if (!shouldByPassYjs()) {
|
||||||
|
onChange?.(firstKey, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user