From 3711e13e0e4bcf11d4cf82287cf399afac21abba Mon Sep 17 00:00:00 2001 From: zzj3720 <17165520+zzj3720@users.noreply.github.com> Date: Mon, 3 Mar 2025 05:58:07 +0000 Subject: [PATCH] fix(editor): database block create new row when group by rich-text (#10564) --- .../data-view/src/core/group-by/define.ts | 2 +- .../data-view/src/core/group-by/trait.ts | 20 +++++++++---------- .../data-view/src/core/group-by/types.ts | 4 ++-- .../src/core/view-manager/single-view.ts | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/blocksuite/affine/data-view/src/core/group-by/define.ts b/blocksuite/affine/data-view/src/core/group-by/define.ts index d2f23edc0b..60a8d01383 100644 --- a/blocksuite/affine/data-view/src/core/group-by/define.ts +++ b/blocksuite/affine/data-view/src/core/group-by/define.ts @@ -134,7 +134,7 @@ export const groupByMatchers = [ }, ]; }, - addToGroup: value => (typeof value === 'number' ? value * 10 : undefined), + addToGroup: value => (typeof value === 'number' ? value * 10 : null), view: createUniComponentFromWebComponent(NumberGroupView), }), groupByMatcherCreator.createMatcher(t.boolean.instance(), { diff --git a/blocksuite/affine/data-view/src/core/group-by/trait.ts b/blocksuite/affine/data-view/src/core/group-by/trait.ts index 5547541f27..f758d9dc23 100644 --- a/blocksuite/affine/data-view/src/core/group-by/trait.ts +++ b/blocksuite/affine/data-view/src/core/group-by/trait.ts @@ -168,11 +168,11 @@ export class GroupTrait { return; } const addTo = this.config$.value?.addToGroup ?? (value => value); - const newValue = addTo( - groupMap[key]?.value, - this.view.cellJsonValueGet(rowId, propertyId) - ); - this.view.cellValueSet(rowId, propertyId, newValue); + const v = groupMap[key]?.value; + if (v != null) { + const newValue = addTo(v, this.view.cellJsonValueGet(rowId, propertyId)); + this.view.cellJsonValueSet(rowId, propertyId, newValue); + } } changeCardSort(groupKey: string, cardIds: string[]) { @@ -233,9 +233,9 @@ export class GroupTrait { if (!propertyId) { return; } - const remove = this.config$.value?.removeFromGroup ?? (() => undefined); + const remove = this.config$.value?.removeFromGroup ?? (() => null); const group = fromGroupKey != null ? groupMap[fromGroupKey] : undefined; - let newValue: unknown = undefined; + let newValue: DVJSON = null; if (group) { newValue = remove( group.value, @@ -243,8 +243,8 @@ export class GroupTrait { ); } const addTo = this.config$.value?.addToGroup ?? (value => value); - newValue = addTo(groupMap[toGroupKey]?.value, newValue); - this.view.cellValueSet(rowId, propertyId, newValue); + newValue = addTo(groupMap[toGroupKey]?.value ?? null, newValue); + this.view.cellJsonValueSet(rowId, propertyId, newValue); } const rows = groupMap[toGroupKey]?.rows.filter(id => id !== rowId) ?? []; const index = insertPositionToIndex(position, rows, id => id); @@ -278,7 +278,7 @@ export class GroupTrait { } const remove = this.config$.value?.removeFromGroup ?? (() => undefined); const newValue = remove( - groupMap[key]?.value, + groupMap[key]?.value ?? null, this.view.cellJsonValueGet(rowId, propertyId) ); this.view.cellValueSet(rowId, propertyId, newValue); diff --git a/blocksuite/affine/data-view/src/core/group-by/types.ts b/blocksuite/affine/data-view/src/core/group-by/types.ts index 032b8a601a..bb2a80c4c5 100644 --- a/blocksuite/affine/data-view/src/core/group-by/types.ts +++ b/blocksuite/affine/data-view/src/core/group-by/types.ts @@ -27,7 +27,7 @@ export type GroupByConfig = { key: string; value: DVJSON; }[]; - addToGroup?: (value: unknown, oldValue: unknown) => unknown; - removeFromGroup?: (value: unknown, oldValue: unknown) => unknown; + addToGroup?: (value: DVJSON, oldValue: DVJSON) => DVJSON; + removeFromGroup?: (value: DVJSON, oldValue: DVJSON) => DVJSON; view: UniComponent; }; diff --git a/blocksuite/affine/data-view/src/core/view-manager/single-view.ts b/blocksuite/affine/data-view/src/core/view-manager/single-view.ts index 56b39681dc..37f88d10d5 100644 --- a/blocksuite/affine/data-view/src/core/view-manager/single-view.ts +++ b/blocksuite/affine/data-view/src/core/view-manager/single-view.ts @@ -50,7 +50,7 @@ export interface SingleView { cellValueSet(rowId: string, propertyId: string, value: unknown): void; - cellJsonValueGet(rowId: string, propertyId: string): unknown; + cellJsonValueGet(rowId: string, propertyId: string): DVJSON; cellJsonValueSet(rowId: string, propertyId: string, value: DVJSON): void; @@ -264,10 +264,10 @@ export abstract class SingleViewBase< return new CellBase(this, propertyId, rowId); } - cellJsonValueGet(rowId: string, propertyId: string): unknown { + cellJsonValueGet(rowId: string, propertyId: string): DVJSON { const type = this.propertyTypeGet(propertyId); if (!type) { - return; + return null; } return this.dataSource.propertyMetaGet(type).config.cellToJson({ value: this.dataSource.cellValueGet(rowId, propertyId),