@formicoidea/labre-core 0.26.1 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/_pkgs/affine-block-database/data-source.d.ts +28 -40
  2. package/dist/_pkgs/affine-block-database/data-source.js +116 -178
  3. package/dist/_pkgs/affine-block-database/database-block.d.ts +10 -3
  4. package/dist/_pkgs/affine-block-database/database-block.js +110 -70
  5. package/dist/_pkgs/affine-block-database/external-data-source.d.ts +69 -0
  6. package/dist/_pkgs/affine-block-database/external-data-source.js +144 -0
  7. package/dist/_pkgs/affine-block-database/index.d.ts +1 -0
  8. package/dist/_pkgs/affine-block-database/index.js +1 -0
  9. package/dist/_pkgs/affine-block-embed-doc/embed-linked-doc-block/embed-linked-doc-block.js +6 -7
  10. package/dist/_pkgs/affine-block-embed-doc/embed-synced-doc-block/components/embed-synced-doc-card.js +5 -5
  11. package/dist/_pkgs/affine-block-root/configs/toolbar.d.ts +1 -1
  12. package/dist/_pkgs/affine-block-root/edgeless/configs/toolbar/misc.d.ts +18 -0
  13. package/dist/_pkgs/affine-block-root/edgeless/configs/toolbar/more.d.ts +18 -0
  14. package/dist/_pkgs/affine-block-root/edgeless/configs/toolbar/more.js +104 -2
  15. package/dist/_pkgs/affine-block-root/index.d.ts +1 -0
  16. package/dist/_pkgs/affine-block-root/index.js +1 -0
  17. package/dist/_pkgs/affine-block-root/keyboard/keyboard-manager.js +3 -21
  18. package/dist/_pkgs/affine-block-root/keyboard/shortcuts.d.ts +8 -0
  19. package/dist/_pkgs/affine-block-root/keyboard/shortcuts.js +48 -0
  20. package/dist/_pkgs/affine-block-root/view.js +6 -1
  21. package/dist/_pkgs/affine-gfx-link/effects.js +2 -2
  22. package/dist/_pkgs/affine-gfx-link/toolbar/undo-dense-menu.d.ts +3 -0
  23. package/dist/_pkgs/affine-gfx-link/toolbar/undo-dense-menu.js +12 -0
  24. package/dist/_pkgs/affine-gfx-link/toolbar/undo-tool-button.d.ts +18 -0
  25. package/dist/_pkgs/affine-gfx-link/toolbar/undo-tool-button.js +41 -0
  26. package/dist/_pkgs/affine-gfx-link/undo-tool.d.ts +6 -0
  27. package/dist/_pkgs/affine-gfx-link/undo-tool.js +17 -0
  28. package/dist/_pkgs/affine-gfx-link/view.js +4 -2
  29. package/dist/_pkgs/affine-gfx-mindmap/toolbar/mindmap-tool-button.js +13 -2
  30. package/dist/_pkgs/affine-gfx-mindmap/toolbar/senior-tool.d.ts +12 -2
  31. package/dist/_pkgs/affine-gfx-mindmap/toolbar/senior-tool.js +62 -11
  32. package/dist/_pkgs/affine-gfx-mindmap/view.d.ts +13 -2
  33. package/dist/_pkgs/affine-gfx-mindmap/view.js +24 -5
  34. package/dist/_pkgs/affine-shared/services/index.d.ts +2 -0
  35. package/dist/_pkgs/affine-shared/services/index.js +2 -0
  36. package/dist/_pkgs/affine-shared/services/keymap-override-service.d.ts +15 -0
  37. package/dist/_pkgs/affine-shared/services/keymap-override-service.js +26 -0
  38. package/dist/_pkgs/affine-shared/services/linked-doc-content-service.d.ts +42 -0
  39. package/dist/_pkgs/affine-shared/services/linked-doc-content-service.js +47 -0
  40. package/dist/_pkgs/affine-widget-edgeless-selected-rect/edgeless-element-link.d.ts +29 -0
  41. package/dist/_pkgs/affine-widget-edgeless-selected-rect/edgeless-element-link.js +233 -0
  42. package/dist/_pkgs/affine-widget-edgeless-selected-rect/effects.js +2 -0
  43. package/dist/_pkgs/affine-widget-edgeless-selected-rect/spec.d.ts +1 -0
  44. package/dist/_pkgs/affine-widget-edgeless-selected-rect/spec.js +2 -0
  45. package/dist/_pkgs/affine-widget-edgeless-selected-rect/view.js +2 -1
  46. package/dist/_pkgs/data-view/core/data-source/base.d.ts +6 -0
  47. package/dist/_pkgs/data-view/core/data-source/base.js +6 -0
  48. package/dist/_pkgs/std/extension/index.d.ts +1 -0
  49. package/dist/_pkgs/std/extension/index.js +1 -0
  50. package/dist/_pkgs/std/extension/shortcut.d.ts +69 -0
  51. package/dist/_pkgs/std/extension/shortcut.js +106 -0
  52. package/dist/_pkgs/std/gfx/model/surface/element-model.d.ts +7 -0
  53. package/dist/_pkgs/std/gfx/model/surface/element-model.js +24 -1
  54. package/dist/_pkgs/std/identifier.d.ts +7 -0
  55. package/dist/_pkgs/std/identifier.js +6 -0
  56. package/dist/_pkgs/std/inline/components/v-element.js +5 -2
  57. package/dist/extensions/view.js +5 -2
  58. package/dist/flags.d.ts +1 -1
  59. package/dist/flags.js +4 -1
  60. package/dist/shortcuts.d.ts +24 -0
  61. package/dist/shortcuts.js +39 -0
  62. package/package.json +5 -1
  63. package/dist/_pkgs/affine-gfx-link/link-tool.d.ts +0 -1
  64. package/dist/_pkgs/affine-gfx-link/link-tool.js +0 -11
  65. package/dist/_pkgs/affine-gfx-link/toolbar/link-dense-menu.d.ts +0 -2
  66. package/dist/_pkgs/affine-gfx-link/toolbar/link-dense-menu.js +0 -26
  67. package/dist/_pkgs/affine-gfx-link/toolbar/link-tool-button.d.ts +0 -10
  68. package/dist/_pkgs/affine-gfx-link/toolbar/link-tool-button.js +0 -84
@@ -1,19 +1,24 @@
1
1
  import type { ColumnDataType, DatabaseBlockModel } from '../affine-model/index.js';
2
2
  import { type InsertToPosition } from '../affine-shared/utils/index.js';
3
- import { type DatabaseFlags, DataSourceBase, type DataViewDataType, type PropertyMetaConfig, type TypeInstance, type ViewManager, type ViewMeta } from '../data-view/index.js';
3
+ import { type PropertyMetaConfig, type TypeInstance } from '../data-view/index.js';
4
4
  import type { EditorHost } from '../std/index.js';
5
- import { type ReadonlySignal } from '@preact/signals-core';
5
+ import { ExternalDataSourceBase } from './external-data-source.js';
6
6
  type SpacialProperty = {
7
7
  valueSet: (rowId: string, propertyId: string, value: unknown) => void;
8
8
  valueGet: (rowId: string, propertyId: string) => unknown;
9
9
  };
10
- export declare class DatabaseBlockDataSource extends DataSourceBase {
11
- get parentProvider(): import("../global/di/provider.js").ServiceProvider;
10
+ /**
11
+ * The inline blob source: rows are the block's children, cells/columns live in
12
+ * the model blob. It implements the {@link ExternalDataSourceBase} data
13
+ * contract by reading blocksuite signals directly, so it never needs to bump
14
+ * `revision` — reactivity is automatic.
15
+ */
16
+ export declare class DatabaseBlockDataSource extends ExternalDataSourceBase {
12
17
  spacialProperties: Record<string, SpacialProperty>;
13
18
  isSpacialProperty(propertyType: string): boolean;
14
19
  spacialValueGet(rowId: string, propertyId: string, propertyType: string): unknown;
15
20
  static externalProperties: import("@preact/signals-core").Signal<PropertyMetaConfig[]>;
16
- static propertiesList: ReadonlySignal<(PropertyMetaConfig | PropertyMetaConfig<"checkbox", {}, boolean, boolean> | PropertyMetaConfig<"date", {}, number | null, number | null> | PropertyMetaConfig<"image", {}, string | null, string | null> | PropertyMetaConfig<"multi-select", {
21
+ static propertiesList: import("@preact/signals-core").ReadonlySignal<(PropertyMetaConfig | PropertyMetaConfig<"checkbox", {}, boolean, boolean> | PropertyMetaConfig<"date", {}, number | null, number | null> | PropertyMetaConfig<"image", {}, string | null, string | null> | PropertyMetaConfig<"multi-select", {
17
22
  options: {
18
23
  id: string;
19
24
  value: string;
@@ -28,68 +33,51 @@ export declare class DatabaseBlockDataSource extends DataSourceBase {
28
33
  value: string;
29
34
  color: string;
30
35
  }[];
31
- }, string | null, string | null> | PropertyMetaConfig<"link", {}, string, string> | PropertyMetaConfig<"rich-text", {}, import("./properties/rich-text/define.js").RichTextCellType | undefined, string> | PropertyMetaConfig<"title", {}, import("../store/index.js").Text<{
36
+ }, string | null, string | null> | PropertyMetaConfig<"created-time", {}, number | null, number | null> | PropertyMetaConfig<"link", {}, string, string> | PropertyMetaConfig<"rich-text", {}, import("./properties/rich-text/define.js").RichTextCellType | undefined, string> | PropertyMetaConfig<"title", {}, import("../store/index.js").Text<{
32
37
  bold?: true | null | undefined;
33
38
  link?: string | null | undefined;
34
39
  strike?: true | null | undefined;
35
40
  code?: true | null | undefined;
36
41
  italic?: true | null | undefined;
37
42
  underline?: true | null | undefined;
38
- }> | undefined, string> | PropertyMetaConfig<"created-time", {}, number | null, number | null>)[]>;
39
- static propertiesMap: ReadonlySignal<{
43
+ }> | undefined, string>)[]>;
44
+ static propertiesMap: import("@preact/signals-core").ReadonlySignal<{
40
45
  [k: string]: PropertyMetaConfig;
41
46
  }>;
42
47
  private _batch;
43
- private readonly _model;
44
- featureFlags$: ReadonlySignal<DatabaseFlags>;
45
- properties$: ReadonlySignal<string[]>;
46
- readonly$: ReadonlySignal<boolean>;
47
- rows$: ReadonlySignal<string[]>;
48
- viewConverts: import("./index.js").ViewConvertConfig[];
49
- viewDataList$: ReadonlySignal<DataViewDataType[]>;
50
- viewManager: ViewManager;
51
- viewMetas: ViewMeta[];
52
- get doc(): import("../store/index.js").Store;
53
- allPropertyMetas$: ReadonlySignal<PropertyMetaConfig<any, any, any, any>[]>;
54
- propertyMetas$: ReadonlySignal<PropertyMetaConfig[]>;
55
48
  constructor(model: DatabaseBlockModel, init?: (dataSource: DatabaseBlockDataSource) => void);
56
49
  private _runCapture;
57
50
  private getModelById;
58
51
  private newPropertyName;
59
- cellValueChange(rowId: string, propertyId: string, value: unknown): void;
60
- cellValueGet(rowId: string, propertyId: string): unknown;
61
- propertyAdd(insertToPosition: InsertToPosition, ops?: {
62
- type?: string;
63
- name?: string;
64
- }): string | undefined;
52
+ protected getRows(): string[];
53
+ protected getProperties(): string[];
54
+ protected getPropertyMetas(): PropertyMetaConfig[];
55
+ protected getCellValue(rowId: string, propertyId: string): unknown;
65
56
  protected getNormalPropertyAndIndex(propertyId: string): {
66
57
  column: ColumnDataType<Record<string, unknown>>;
67
58
  index: number;
68
59
  } | undefined;
69
60
  private getPropertyAndIndex;
61
+ protected getPropertyData(propertyId: string): Record<string, unknown>;
62
+ protected getPropertyDataType(propertyId: string): TypeInstance | undefined;
63
+ protected getPropertyName(propertyId: string): string;
64
+ protected getPropertyType(propertyId: string): string | undefined;
65
+ propertyReadonlyGet(propertyId: string): boolean;
66
+ propertyMetaGet(type: string): PropertyMetaConfig | undefined;
70
67
  private updateProperty;
71
- propertyDataGet(propertyId: string): Record<string, unknown>;
68
+ cellValueChange(rowId: string, propertyId: string, value: unknown): void;
69
+ propertyAdd(insertToPosition: InsertToPosition, ops?: {
70
+ type?: string;
71
+ name?: string;
72
+ }): string | undefined;
72
73
  propertyDataSet(propertyId: string, data: Record<string, unknown>): void;
73
- propertyDataTypeGet(propertyId: string): TypeInstance | undefined;
74
74
  propertyDelete(id: string): void;
75
75
  propertyDuplicate(propertyId: string): string | undefined;
76
- propertyMetaGet(type: string): PropertyMetaConfig | undefined;
77
- propertyNameGet(propertyId: string): string;
78
76
  propertyNameSet(propertyId: string, name: string): void;
79
- propertyReadonlyGet(propertyId: string): boolean;
80
- propertyTypeGet(propertyId: string): string | undefined;
81
77
  propertyTypeSet(propertyId: string, toType: string): void;
82
78
  rowAdd(insertPosition: InsertToPosition | number): string;
83
79
  rowDelete(ids: string[]): void;
84
80
  rowMove(rowId: string, position: InsertToPosition): void;
85
- viewDataAdd(viewData: DataViewDataType): string;
86
- viewDataDelete(viewId: string): void;
87
- viewDataDuplicate(id: string): string;
88
- viewDataGet(viewId: string): DataViewDataType | undefined;
89
- viewDataMoveTo(id: string, position: InsertToPosition): void;
90
- viewDataUpdate<ViewData extends DataViewDataType>(id: string, updater: (data: ViewData) => Partial<ViewData>): void;
91
- viewMetaGet(type: string): ViewMeta;
92
- viewMetaGetById(viewId: string): ViewMeta | undefined;
93
81
  }
94
82
  export declare const databaseViewInitTemplate: (datasource: DatabaseBlockDataSource, viewType: string) => void;
95
83
  export declare const convertToDatabase: (host: EditorHost, viewType: string) => void;
@@ -1,20 +1,20 @@
1
1
  import { getSelectedModelsCommand } from '../affine-shared/commands/index.js';
2
- import { FeatureFlagService } from '../affine-shared/services/index.js';
3
2
  import { insertPositionToIndex, } from '../affine-shared/utils/index.js';
4
- import { DataSourceBase, ViewManagerBase, } from '../data-view/index.js';
3
+ import {} from '../data-view/index.js';
5
4
  import { propertyPresets } from '../data-view/property-presets/index.js';
6
- import { IS_MOBILE } from '../global/env/index.js';
7
- import { BlockSuiteError, ErrorCode } from '../global/exceptions/index.js';
8
5
  import {} from '../store/index.js';
9
6
  import { computed, signal } from '@preact/signals-core';
10
7
  import { getIcon } from './block-icons.js';
8
+ import { ExternalDataSourceBase } from './external-data-source.js';
11
9
  import { databaseBlockProperties, databasePropertyConverts, } from './properties/index.js';
12
- import { addProperty, copyCellsByProperty, deleteRows, deleteView, duplicateView, getCell, getProperty, moveViewTo, updateCell, updateCells, updateProperty, updateView, } from './utils/block-utils.js';
13
- import { databaseBlockViewConverts, databaseBlockViewMap, databaseBlockViews, } from './views/index.js';
14
- export class DatabaseBlockDataSource extends DataSourceBase {
15
- get parentProvider() {
16
- return this._model.store.provider;
17
- }
10
+ import { addProperty, copyCellsByProperty, deleteRows, getCell, getProperty, updateCell, updateCells, updateProperty, } from './utils/block-utils.js';
11
+ /**
12
+ * The inline blob source: rows are the block's children, cells/columns live in
13
+ * the model blob. It implements the {@link ExternalDataSourceBase} data
14
+ * contract by reading blocksuite signals directly, so it never needs to bump
15
+ * `revision` — reactivity is automatic.
16
+ */
17
+ export class DatabaseBlockDataSource extends ExternalDataSourceBase {
18
18
  isSpacialProperty(propertyType) {
19
19
  return this.spacialProperties[propertyType] !== undefined;
20
20
  }
@@ -31,11 +31,8 @@ export class DatabaseBlockDataSource extends DataSourceBase {
31
31
  static { this.propertiesMap = computed(() => {
32
32
  return Object.fromEntries(this.propertiesList.value.map(v => [v.type, v]));
33
33
  }); }
34
- get doc() {
35
- return this._model.store;
36
- }
37
34
  constructor(model, init) {
38
- super();
35
+ super(model);
39
36
  this.spacialProperties = {
40
37
  'created-time': {
41
38
  valueSet: () => { },
@@ -76,49 +73,7 @@ export class DatabaseBlockDataSource extends DataSourceBase {
76
73
  },
77
74
  };
78
75
  this._batch = 0;
79
- this.featureFlags$ = computed(() => {
80
- const featureFlagService = this.doc.get(FeatureFlagService);
81
- const enableNumberFormat = featureFlagService.getFlag('enable_database_number_formatting');
82
- const enableTableVirtualScroll = featureFlagService.getFlag('enable_table_virtual_scroll');
83
- return {
84
- enable_number_formatting: enableNumberFormat ?? false,
85
- enable_table_virtual_scroll: enableTableVirtualScroll ?? false,
86
- };
87
- });
88
- this.properties$ = computed(() => {
89
- const fixedPropertiesSet = new Set(this.fixedProperties$.value);
90
- const properties = [];
91
- this._model.props.columns$.value.forEach(column => {
92
- if (fixedPropertiesSet.has(column.type)) {
93
- fixedPropertiesSet.delete(column.type);
94
- }
95
- properties.push(column.id);
96
- });
97
- const result = [...fixedPropertiesSet, ...properties];
98
- return result;
99
- });
100
- this.readonly$ = computed(() => {
101
- return (this._model.store.readonly ||
102
- // TODO(@L-Sun): use block level readonly
103
- IS_MOBILE);
104
- });
105
- this.rows$ = computed(() => {
106
- return this._model.children.map(v => v.id);
107
- });
108
- this.viewConverts = databaseBlockViewConverts;
109
- this.viewDataList$ = computed(() => {
110
- return this._model.props.views$.value;
111
- });
112
- this.viewManager = new ViewManagerBase(this);
113
- this.viewMetas = databaseBlockViews;
114
- this.allPropertyMetas$ = computed(() => {
115
- return DatabaseBlockDataSource.propertiesList.value;
116
- });
117
- this.propertyMetas$ = computed(() => {
118
- return this.allPropertyMetas$.value.filter(v => !v.config.fixed && !v.config.hide);
119
- });
120
- this._model = model; // ensure invariants first
121
- init?.(this); // then allow external initialisation
76
+ init?.(this); // allow external initialisation
122
77
  }
123
78
  _runCapture() {
124
79
  if (this._batch) {
@@ -145,34 +100,26 @@ export class DatabaseBlockDataSource extends DataSourceBase {
145
100
  i++;
146
101
  }
147
102
  }
148
- cellValueChange(rowId, propertyId, value) {
149
- this._runCapture();
150
- const type = this.propertyTypeGet(propertyId);
151
- if (type == null) {
152
- return;
153
- }
154
- const update = this.propertyMetaGet(type)?.config.rawValue.setValue;
155
- const old = this.cellValueGet(rowId, propertyId);
156
- const updateFn = update ??
157
- (({ setValue, newValue }) => {
158
- setValue(newValue);
159
- });
160
- updateFn({
161
- value: old,
162
- data: this.propertyDataGet(propertyId),
163
- dataSource: this,
164
- newValue: value,
165
- setValue: newValue => {
166
- if (this._model.props.columns$.value.some(v => v.id === propertyId)) {
167
- updateCell(this._model, rowId, {
168
- columnId: propertyId,
169
- value: newValue,
170
- });
171
- }
172
- },
103
+ // --- data contract (read) ------------------------------------------------
104
+ getRows() {
105
+ return this._model.children.map(v => v.id);
106
+ }
107
+ getProperties() {
108
+ const fixedPropertiesSet = new Set(this.fixedProperties$.value);
109
+ const properties = [];
110
+ this._model.props.columns$.value.forEach(column => {
111
+ if (fixedPropertiesSet.has(column.type)) {
112
+ fixedPropertiesSet.delete(column.type);
113
+ }
114
+ properties.push(column.id);
173
115
  });
116
+ return [...fixedPropertiesSet, ...properties];
117
+ }
118
+ getPropertyMetas() {
119
+ return DatabaseBlockDataSource.propertiesList
120
+ .value;
174
121
  }
175
- cellValueGet(rowId, propertyId) {
122
+ getCellValue(rowId, propertyId) {
176
123
  if (this.isSpacialProperty(propertyId)) {
177
124
  return this.spacialValueGet(rowId, propertyId, propertyId);
178
125
  }
@@ -196,16 +143,6 @@ export class DatabaseBlockDataSource extends DataSourceBase {
196
143
  }
197
144
  return;
198
145
  }
199
- propertyAdd(insertToPosition, ops) {
200
- this.doc.captureSync();
201
- const { type, name } = ops ?? {};
202
- const property = this.propertyMetaGet(type ?? propertyPresets.multiSelectPropertyConfig.type);
203
- if (!property) {
204
- return;
205
- }
206
- const result = addProperty(this._model, insertToPosition, property.create(this.newPropertyName(name)));
207
- return result;
208
- }
209
146
  getNormalPropertyAndIndex(propertyId) {
210
147
  const index = this._model.props.columns$.value.findIndex(v => v.id === propertyId);
211
148
  if (index >= 0) {
@@ -243,6 +180,57 @@ export class DatabaseBlockDataSource extends DataSourceBase {
243
180
  }
244
181
  return undefined;
245
182
  }
183
+ getPropertyData(propertyId) {
184
+ const result = this.getPropertyAndIndex(propertyId);
185
+ if (!result) {
186
+ return {};
187
+ }
188
+ return result.column.data;
189
+ }
190
+ getPropertyDataType(propertyId) {
191
+ const result = this.getPropertyAndIndex(propertyId);
192
+ if (!result) {
193
+ return;
194
+ }
195
+ const { column } = result;
196
+ const meta = this.propertyMetaGet(column.type);
197
+ if (!meta) {
198
+ return;
199
+ }
200
+ return meta.config?.jsonValue.type({
201
+ data: column.data,
202
+ dataSource: this,
203
+ });
204
+ }
205
+ getPropertyName(propertyId) {
206
+ if (propertyId === 'type') {
207
+ return 'Block Type';
208
+ }
209
+ const result = this.getPropertyAndIndex(propertyId);
210
+ if (!result) {
211
+ return '';
212
+ }
213
+ return result.column.name;
214
+ }
215
+ getPropertyType(propertyId) {
216
+ if (propertyId === 'type') {
217
+ return 'image';
218
+ }
219
+ const result = this.getPropertyAndIndex(propertyId);
220
+ if (!result) {
221
+ return;
222
+ }
223
+ return result.column.type;
224
+ }
225
+ propertyReadonlyGet(propertyId) {
226
+ if (propertyId === 'type')
227
+ return true;
228
+ return false;
229
+ }
230
+ propertyMetaGet(type) {
231
+ return DatabaseBlockDataSource.propertiesMap.value[type];
232
+ }
233
+ // --- data contract (mutations) ------------------------------------------
246
234
  updateProperty(id, updater) {
247
235
  const result = this.getPropertyAndIndex(id);
248
236
  if (!result) {
@@ -264,32 +252,47 @@ export class DatabaseBlockDataSource extends DataSourceBase {
264
252
  });
265
253
  return id;
266
254
  }
267
- propertyDataGet(propertyId) {
268
- const result = this.getPropertyAndIndex(propertyId);
269
- if (!result) {
270
- return {};
271
- }
272
- return result.column.data;
273
- }
274
- propertyDataSet(propertyId, data) {
255
+ cellValueChange(rowId, propertyId, value) {
275
256
  this._runCapture();
276
- this.updateProperty(propertyId, () => ({ data }));
277
- }
278
- propertyDataTypeGet(propertyId) {
279
- const result = this.getPropertyAndIndex(propertyId);
280
- if (!result) {
281
- return;
282
- }
283
- const { column } = result;
284
- const meta = this.propertyMetaGet(column.type);
285
- if (!meta) {
257
+ const type = this.propertyTypeGet(propertyId);
258
+ if (type == null) {
286
259
  return;
287
260
  }
288
- return meta.config?.jsonValue.type({
289
- data: column.data,
261
+ const update = this.propertyMetaGet(type)?.config.rawValue.setValue;
262
+ const old = this.cellValueGet(rowId, propertyId);
263
+ const updateFn = update ??
264
+ (({ setValue, newValue }) => {
265
+ setValue(newValue);
266
+ });
267
+ updateFn({
268
+ value: old,
269
+ data: this.propertyDataGet(propertyId),
290
270
  dataSource: this,
271
+ newValue: value,
272
+ setValue: newValue => {
273
+ if (this._model.props.columns$.value.some(v => v.id === propertyId)) {
274
+ updateCell(this._model, rowId, {
275
+ columnId: propertyId,
276
+ value: newValue,
277
+ });
278
+ }
279
+ },
291
280
  });
292
281
  }
282
+ propertyAdd(insertToPosition, ops) {
283
+ this.doc.captureSync();
284
+ const { type, name } = ops ?? {};
285
+ const property = this.propertyMetaGet(type ?? propertyPresets.multiSelectPropertyConfig.type);
286
+ if (!property) {
287
+ return;
288
+ }
289
+ const result = addProperty(this._model, insertToPosition, property.create(this.newPropertyName(name)));
290
+ return result;
291
+ }
292
+ propertyDataSet(propertyId, data) {
293
+ this._runCapture();
294
+ this.updateProperty(propertyId, () => ({ data }));
295
+ }
293
296
  propertyDelete(id) {
294
297
  if (this.isFixedProperty(id)) {
295
298
  return;
@@ -325,38 +328,10 @@ export class DatabaseBlockDataSource extends DataSourceBase {
325
328
  copyCellsByProperty(this._model, copyId, id);
326
329
  return id;
327
330
  }
328
- propertyMetaGet(type) {
329
- return DatabaseBlockDataSource.propertiesMap.value[type];
330
- }
331
- propertyNameGet(propertyId) {
332
- if (propertyId === 'type') {
333
- return 'Block Type';
334
- }
335
- const result = this.getPropertyAndIndex(propertyId);
336
- if (!result) {
337
- return '';
338
- }
339
- return result.column.name;
340
- }
341
331
  propertyNameSet(propertyId, name) {
342
332
  this.doc.captureSync();
343
333
  this.updateProperty(propertyId, () => ({ name }));
344
334
  }
345
- propertyReadonlyGet(propertyId) {
346
- if (propertyId === 'type')
347
- return true;
348
- return false;
349
- }
350
- propertyTypeGet(propertyId) {
351
- if (propertyId === 'type') {
352
- return 'image';
353
- }
354
- const result = this.getPropertyAndIndex(propertyId);
355
- if (!result) {
356
- return;
357
- }
358
- return result.column.type;
359
- }
360
335
  propertyTypeSet(propertyId, toType) {
361
336
  if (this.isFixedProperty(propertyId)) {
362
337
  return;
@@ -418,43 +393,6 @@ export class DatabaseBlockDataSource extends DataSourceBase {
418
393
  this.doc.moveBlocks([model], this._model, target);
419
394
  }
420
395
  }
421
- viewDataAdd(viewData) {
422
- this._model.store.captureSync();
423
- this._model.store.transact(() => {
424
- this._model.props.views = [...this._model.props.views, viewData];
425
- });
426
- return viewData.id;
427
- }
428
- viewDataDelete(viewId) {
429
- this._model.store.captureSync();
430
- deleteView(this._model, viewId);
431
- }
432
- viewDataDuplicate(id) {
433
- return duplicateView(this._model, id);
434
- }
435
- viewDataGet(viewId) {
436
- return this.viewDataList$.value.find(data => data.id === viewId);
437
- }
438
- viewDataMoveTo(id, position) {
439
- moveViewTo(this._model, id, position);
440
- }
441
- viewDataUpdate(id, updater) {
442
- updateView(this._model, id, updater);
443
- }
444
- viewMetaGet(type) {
445
- const view = databaseBlockViewMap[type];
446
- if (!view) {
447
- throw new BlockSuiteError(ErrorCode.DatabaseBlockError, `Unknown view type: ${type}`);
448
- }
449
- return view;
450
- }
451
- viewMetaGetById(viewId) {
452
- const view = this.viewDataGet(viewId);
453
- if (!view) {
454
- return;
455
- }
456
- return this.viewMetaGet(view.mode);
457
- }
458
396
  }
459
397
  export const databaseViewInitTemplate = (datasource, viewType) => {
460
398
  Array.from({ length: 3 }).forEach(() => {
@@ -1,12 +1,17 @@
1
1
  import { CaptionedBlockComponent } from '../affine-components/caption/index.js';
2
2
  import { DropIndicator } from '../affine-components/drop-indicator/index.js';
3
3
  import type { DatabaseBlockModel } from '../affine-model/index.js';
4
- import { type DataViewWidget, type SingleView } from '../data-view/index.js';
4
+ import { type DataSourceBase, type DataViewWidget, type SingleView } from '../data-view/index.js';
5
5
  import { type BlockComponent } from '../std/index.js';
6
6
  import type { DatabaseViewExtensionOptions } from './view';
7
7
  export declare class DatabaseBlockComponent extends CaptionedBlockComponent<DatabaseBlockModel> {
8
8
  private readonly clickDatabaseOps;
9
- private readonly dataSource;
9
+ private _dataSource?;
10
+ private _dataViewRootLogic?;
11
+ private _sourceVersion;
12
+ private _buildDataSource;
13
+ get dataSource(): DataSourceBase;
14
+ private rebuildDataSource;
10
15
  private readonly renderTitle;
11
16
  createTemplate: (data: {
12
17
  view: SingleView;
@@ -24,8 +29,10 @@ export declare class DatabaseBlockComponent extends CaptionedBlockComponent<Data
24
29
  get topContenteditableElement(): BlockComponent<import("../store/index.js").BlockModel<object>, import("../std/index.js").BlockService, string> | null;
25
30
  private renderDatabaseOps;
26
31
  connectedCallback(): void;
32
+ disconnectedCallback(): void;
27
33
  listenFullWidthChange(): void;
28
- private readonly dataViewRootLogic;
34
+ private get dataViewRootLogic();
35
+ private _buildDataViewRootLogic;
29
36
  renderBlock(): import("lit-html").TemplateResult<1>;
30
37
  accessor useZeroWidth: boolean;
31
38
  }