@univerjs-pro/bases 1.0.0-alpha.7 → 1.0.0-beta.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 (135) hide show
  1. package/lib/cjs/facade.js +1 -1
  2. package/lib/cjs/index.js +1 -1
  3. package/lib/cjs/locale/ar-SA.js +1 -1
  4. package/lib/cjs/locale/ca-ES.js +1 -1
  5. package/lib/cjs/locale/de-DE.js +1 -1
  6. package/lib/cjs/locale/en-US.js +1 -1
  7. package/lib/cjs/locale/es-ES.js +1 -1
  8. package/lib/cjs/locale/fa-IR.js +1 -1
  9. package/lib/cjs/locale/fr-FR.js +1 -1
  10. package/lib/cjs/locale/id-ID.js +1 -1
  11. package/lib/cjs/locale/it-IT.js +1 -1
  12. package/lib/cjs/locale/ja-JP.js +1 -1
  13. package/lib/cjs/locale/ko-KR.js +1 -1
  14. package/lib/cjs/locale/pl-PL.js +1 -1
  15. package/lib/cjs/locale/pt-BR.js +1 -1
  16. package/lib/cjs/locale/ru-RU.js +1 -1
  17. package/lib/cjs/locale/sk-SK.js +1 -1
  18. package/lib/cjs/locale/vi-VN.js +1 -1
  19. package/lib/cjs/locale/zh-CN.js +1 -1
  20. package/lib/cjs/locale/zh-HK.js +1 -1
  21. package/lib/cjs/locale/zh-TW.js +1 -1
  22. package/lib/es/facade.js +1 -1
  23. package/lib/es/index.js +1 -1
  24. package/lib/es/locale/ar-SA.js +1 -1
  25. package/lib/es/locale/ca-ES.js +1 -1
  26. package/lib/es/locale/de-DE.js +1 -1
  27. package/lib/es/locale/en-US.js +1 -1
  28. package/lib/es/locale/es-ES.js +1 -1
  29. package/lib/es/locale/fa-IR.js +1 -1
  30. package/lib/es/locale/fr-FR.js +1 -1
  31. package/lib/es/locale/id-ID.js +1 -1
  32. package/lib/es/locale/it-IT.js +1 -1
  33. package/lib/es/locale/ja-JP.js +1 -1
  34. package/lib/es/locale/ko-KR.js +1 -1
  35. package/lib/es/locale/pl-PL.js +1 -1
  36. package/lib/es/locale/pt-BR.js +1 -1
  37. package/lib/es/locale/ru-RU.js +1 -1
  38. package/lib/es/locale/sk-SK.js +1 -1
  39. package/lib/es/locale/vi-VN.js +1 -1
  40. package/lib/es/locale/zh-CN.js +1 -1
  41. package/lib/es/locale/zh-HK.js +1 -1
  42. package/lib/es/locale/zh-TW.js +1 -1
  43. package/lib/facade.js +1 -1
  44. package/lib/index.js +1 -1
  45. package/lib/locale/ar-SA.js +1 -1
  46. package/lib/locale/ca-ES.js +1 -1
  47. package/lib/locale/de-DE.js +1 -1
  48. package/lib/locale/en-US.js +1 -1
  49. package/lib/locale/es-ES.js +1 -1
  50. package/lib/locale/fa-IR.js +1 -1
  51. package/lib/locale/fr-FR.js +1 -1
  52. package/lib/locale/id-ID.js +1 -1
  53. package/lib/locale/it-IT.js +1 -1
  54. package/lib/locale/ja-JP.js +1 -1
  55. package/lib/locale/ko-KR.js +1 -1
  56. package/lib/locale/pl-PL.js +1 -1
  57. package/lib/locale/pt-BR.js +1 -1
  58. package/lib/locale/ru-RU.js +1 -1
  59. package/lib/locale/sk-SK.js +1 -1
  60. package/lib/locale/vi-VN.js +1 -1
  61. package/lib/locale/zh-CN.js +1 -1
  62. package/lib/locale/zh-HK.js +1 -1
  63. package/lib/locale/zh-TW.js +1 -1
  64. package/lib/types/commands/commands/batch-create-base-records.command.d.ts +2 -0
  65. package/lib/types/commands/commands/batch-delete-base-records.command.d.ts +2 -0
  66. package/lib/types/commands/commands/create-base-child-record.command.d.ts +15 -0
  67. package/lib/types/commands/commands/create-base-record.command.d.ts +2 -0
  68. package/lib/types/commands/commands/delete-base-record.command.d.ts +2 -0
  69. package/lib/types/commands/commands/duplicate-base-record.command.d.ts +2 -0
  70. package/lib/types/commands/commands/move-base-hierarchy-record.command.d.ts +17 -0
  71. package/lib/types/commands/commands/set-base-range-values.command.d.ts +8 -1
  72. package/lib/types/commands/commands/set-base-record-values.command.d.ts +2 -0
  73. package/lib/types/commands/commands/set-base-table-hierarchy-field.command.d.ts +9 -0
  74. package/lib/types/commands/commands/update-base-cell.command.d.ts +2 -0
  75. package/lib/types/commands/commands/update-base-view-conditional-color-rules.command.d.ts +32 -0
  76. package/lib/types/commands/mutations/apply-base-json1.mutation.d.ts +4 -0
  77. package/lib/types/commands/utils/base-record-creation.d.ts +18 -0
  78. package/lib/types/commands/utils/base-validation.d.ts +6 -1
  79. package/lib/types/controllers/base-formula-calculation.controller.d.ts +6 -1
  80. package/lib/types/facade/f-base.d.ts +4 -2
  81. package/lib/types/facade/f-enum.d.ts +277 -6
  82. package/lib/types/facade/f-event.d.ts +102 -0
  83. package/lib/types/facade/f-field.d.ts +40 -7
  84. package/lib/types/facade/f-range.d.ts +4 -1
  85. package/lib/types/facade/f-record.d.ts +377 -2
  86. package/lib/types/facade/f-table.d.ts +287 -16
  87. package/lib/types/facade/f-univer.d.ts +2 -0
  88. package/lib/types/facade/f-view.d.ts +179 -3
  89. package/lib/types/facade/field-key.d.ts +3 -1
  90. package/lib/types/facade/index.d.ts +2 -1
  91. package/lib/types/fields/date-format.d.ts +20 -1
  92. package/lib/types/fields/field-core-plugin.d.ts +7 -5
  93. package/lib/types/fields/field-stat.d.ts +10 -0
  94. package/lib/types/fields/number-format.d.ts +3 -3
  95. package/lib/types/fields/progress-format.d.ts +1 -0
  96. package/lib/types/index.d.ts +21 -4
  97. package/lib/types/locale/en-US.d.ts +1 -1
  98. package/lib/types/models/base-hierarchy.d.ts +108 -0
  99. package/lib/types/models/default-table.d.ts +0 -1
  100. package/lib/types/models/record-link.d.ts +14 -0
  101. package/lib/types/ot/json1-adapter.d.ts +0 -1
  102. package/lib/types/ot/json1-op-applier.d.ts +3 -1
  103. package/lib/types/ot/json1-op-factory.d.ts +0 -3
  104. package/lib/types/ot/json1-util.d.ts +2 -2
  105. package/lib/types/search/base-search.d.ts +0 -3
  106. package/lib/types/services/base-active-dirty.service.d.ts +0 -1
  107. package/lib/types/services/base-command.service.d.ts +1 -1
  108. package/lib/types/services/base-compression.service.d.ts +0 -5
  109. package/lib/types/services/base-formula.service.d.ts +1 -3
  110. package/lib/types/services/base-permission.service.d.ts +0 -4
  111. package/lib/types/services/base-projection.service.d.ts +4 -0
  112. package/lib/types/views/view-core-plugin.d.ts +0 -2
  113. package/lib/umd/facade.js +1 -1
  114. package/lib/umd/index.js +1 -1
  115. package/lib/umd/locale/ar-SA.js +1 -1
  116. package/lib/umd/locale/ca-ES.js +1 -1
  117. package/lib/umd/locale/de-DE.js +1 -1
  118. package/lib/umd/locale/en-US.js +1 -1
  119. package/lib/umd/locale/es-ES.js +1 -1
  120. package/lib/umd/locale/fa-IR.js +1 -1
  121. package/lib/umd/locale/fr-FR.js +1 -1
  122. package/lib/umd/locale/id-ID.js +1 -1
  123. package/lib/umd/locale/it-IT.js +1 -1
  124. package/lib/umd/locale/ja-JP.js +1 -1
  125. package/lib/umd/locale/ko-KR.js +1 -1
  126. package/lib/umd/locale/pl-PL.js +1 -1
  127. package/lib/umd/locale/pt-BR.js +1 -1
  128. package/lib/umd/locale/ru-RU.js +1 -1
  129. package/lib/umd/locale/sk-SK.js +1 -1
  130. package/lib/umd/locale/vi-VN.js +1 -1
  131. package/lib/umd/locale/zh-CN.js +1 -1
  132. package/lib/umd/locale/zh-HK.js +1 -1
  133. package/lib/umd/locale/zh-TW.js +1 -1
  134. package/package.json +7 -6
  135. package/lib/types/facade/f-types.d.ts +0 -1
@@ -1,3 +1,4 @@
1
+ import type { BaseEventSource, IBaseHierarchyChange } from '@univerjs-pro/bases';
1
2
  import type { BaseCellValue, IFieldSnapshot, IRecordSnapshot, ITableSnapshot, IViewSnapshot } from '@univerjs/core';
2
3
  import type { IEventBase } from '@univerjs/core/facade';
3
4
  import type { FBase } from './f-base';
@@ -60,6 +61,31 @@ export interface IBaseTableCellValueChangedEventParams extends IEventBase {
60
61
  }
61
62
  export interface IBeforeBaseTableCellValueChangeEventParams extends IBaseTableCellValueChangedEventParams, IEventBase {
62
63
  }
64
+ /**
65
+ * Parameters emitted after one atomic hierarchy mutation is applied.
66
+ *
67
+ * `changes` contains semantic Parent-edge changes from the same JSON1 mutation.
68
+ * A single record move normally contributes one item; a range write or deletion
69
+ * that promotes several children can contribute multiple items. Consumers should
70
+ * process the array as one transaction rather than assuming one event per record.
71
+ */
72
+ export interface IBaseHierarchyChangedEventParams extends IEventBase {
73
+ /** Facade object for the Base containing the changed table. */
74
+ base: FBase;
75
+ /** Facade object for the table whose effective hierarchy changed. */
76
+ table: FBaseTable;
77
+ /** Ordered semantic edge changes committed by the atomic mutation. */
78
+ changes: readonly IBaseHierarchyChange[];
79
+ /** Origin of the applied mutation. Compare with `univerAPI.Enum.BaseEventSource`. */
80
+ source: BaseEventSource;
81
+ }
82
+ /**
83
+ * Parameters emitted before a local semantic hierarchy command is validated and
84
+ * applied. Set the inherited `cancel` property to `true` to reject the entire
85
+ * command. Remote collaboration mutations and Undo/Redo replay are not cancellable.
86
+ */
87
+ export interface IBeforeBaseHierarchyChangeEventParams extends IBaseHierarchyChangedEventParams, IEventBase {
88
+ }
63
89
  /**
64
90
  * Interface for base-related events
65
91
  * @ignore
@@ -220,6 +246,78 @@ export interface IFBasesEventNameMixin {
220
246
  * ```
221
247
  */
222
248
  readonly BeforeBaseTableCellValueChange: 'BeforeBaseTableCellValueChange';
249
+ /**
250
+ * Fired after an atomic hierarchy mutation is applied.
251
+ *
252
+ * The event covers Facade and UI writes, remote collaboration mutations,
253
+ * Undo/Redo replay, and import mutations that carry hierarchy metadata. One
254
+ * event represents one committed mutation and may contain several Parent-edge
255
+ * changes. It is suitable for notifications, analytics, or SDK-side automation;
256
+ * do not write the same Parent edge again from the handler or an event loop may
257
+ * be created.
258
+ *
259
+ * Use `source` to distinguish local SDK work from remote or history replay. The
260
+ * source values are exposed through `univerAPI.Enum.BaseEventSource`; integrations
261
+ * do not need to hard-code strings.
262
+ *
263
+ * @see {@link IBaseHierarchyChangedEventParams}
264
+ * @example Trigger automation only for Facade writes
265
+ * ```ts
266
+ * const disposable = univerAPI.addEvent(
267
+ * univerAPI.Event.BaseHierarchyChanged,
268
+ * ({ table, changes, source }) => {
269
+ * if (source !== univerAPI.Enum.BaseEventSource.Facade) return;
270
+ *
271
+ * for (const { recordId, oldParentRecordId, parentRecordId } of changes) {
272
+ * console.log({
273
+ * tableId: table.getId(),
274
+ * recordId,
275
+ * oldParentRecordId,
276
+ * parentRecordId,
277
+ * });
278
+ * }
279
+ * }
280
+ * );
281
+ *
282
+ * // Call disposable.dispose() when the integration is torn down.
283
+ * ```
284
+ */
285
+ readonly BaseHierarchyChanged: 'BaseHierarchyChanged';
286
+ /**
287
+ * Fired before a local semantic hierarchy command is applied.
288
+ *
289
+ * Covered writes include `addChild()`, `setParent()`, standard record creation
290
+ * or duplication with an initial Parent value, deleting a parent whose surviving
291
+ * children would be promoted, a direct Parent-cell update, and multi-record or
292
+ * range writes touching the canonical Parent field.
293
+ * Setting `cancel = true` rejects the complete command, including every Parent
294
+ * edge, order update, and first-write field materialization in that command. No
295
+ * partial mutation or Undo entry is produced.
296
+ *
297
+ * The event is intentionally local: remote collaboration mutations and
298
+ * Undo/Redo replay have already been accepted and cannot be cancelled here.
299
+ * Use `BaseHierarchyChanged` to observe those sources.
300
+ *
301
+ * @see {@link IBeforeBaseHierarchyChangeEventParams}
302
+ * @example Prevent records from moving below a protected parent
303
+ * ```ts
304
+ * const disposable = univerAPI.addEvent(
305
+ * univerAPI.Event.BeforeBaseHierarchyChange,
306
+ * (event) => {
307
+ * const movesBelowProtectedParent = event.changes.some(
308
+ * ({ parentRecordId }) => parentRecordId === 'protected-task'
309
+ * );
310
+ *
311
+ * if (movesBelowProtectedParent) {
312
+ * event.cancel = true;
313
+ * }
314
+ * }
315
+ * );
316
+ *
317
+ * // Call disposable.dispose() when the integration is torn down.
318
+ * ```
319
+ */
320
+ readonly BeforeBaseHierarchyChange: 'BeforeBaseHierarchyChange';
223
321
  }
224
322
  /**
225
323
  * Configuration interface for base-related events
@@ -236,6 +334,8 @@ export interface IBasesEventParamConfig {
236
334
  BeforeBaseTableViewCreate: IBeforeBaseTableViewCreateEventParams;
237
335
  BaseTableCellValueChanged: IBaseTableCellValueChangedEventParams;
238
336
  BeforeBaseTableCellValueChange: IBeforeBaseTableCellValueChangeEventParams;
337
+ BaseHierarchyChanged: IBaseHierarchyChangedEventParams;
338
+ BeforeBaseHierarchyChange: IBeforeBaseHierarchyChangeEventParams;
239
339
  }
240
340
  export declare class FBasesEventNameMixin extends FEventName implements IFBasesEventNameMixin {
241
341
  get BaseTableCreated(): 'BaseTableCreated';
@@ -248,6 +348,8 @@ export declare class FBasesEventNameMixin extends FEventName implements IFBasesE
248
348
  get BeforeBaseTableViewCreate(): 'BeforeBaseTableViewCreate';
249
349
  get BaseTableCellValueChanged(): 'BaseTableCellValueChanged';
250
350
  get BeforeBaseTableCellValueChange(): 'BeforeBaseTableCellValueChange';
351
+ get BaseHierarchyChanged(): 'BaseHierarchyChanged';
352
+ get BeforeBaseHierarchyChange(): 'BeforeBaseHierarchyChange';
251
353
  }
252
354
  declare module '@univerjs/core/facade' {
253
355
  interface FEventName extends IFBasesEventNameMixin {
@@ -1,6 +1,17 @@
1
- import type { BaseFieldType, FieldConfig, IFieldSnapshot, Injector } from '@univerjs/core';
1
+ import type { IHostExternalReference } from '@univerjs-pro/engine-formula';
2
+ import type { FieldConfig, IFieldSnapshot } from '@univerjs/core';
2
3
  import type { FBase } from './f-base';
3
4
  import type { FBaseTable } from './f-table';
5
+ import { BaseFieldType, ICommandService } from '@univerjs/core';
6
+ export interface IBaseFormulaFieldWriteOptions {
7
+ /**
8
+ * Required, complete Host-owned bindings for this formula write.
9
+ *
10
+ * Use `[]` only when the formula has no external Unit qualifier. Include every
11
+ * external Sheet/Base Source referenced by the formula, including dynamic references.
12
+ */
13
+ externalReferences: readonly IHostExternalReference[];
14
+ }
4
15
  /**
5
16
  * Facade API object bound to a Base field.
6
17
  *
@@ -36,8 +47,8 @@ export declare class FBaseTableField {
36
47
  private readonly _base;
37
48
  private readonly _table;
38
49
  private readonly _fieldId;
39
- private readonly _inject;
40
- constructor(_base: FBase, _table: FBaseTable, _fieldId: string, _inject: Injector);
50
+ private readonly _commandService;
51
+ constructor(_base: FBase, _table: FBaseTable, _fieldId: string, _commandService: ICommandService);
41
52
  /**
42
53
  * Get the field id.
43
54
  * @returns {string} The field id.
@@ -155,7 +166,13 @@ export declare class FBaseTableField {
155
166
  * formula expressions, number/date formatting, and similar field metadata
156
167
  * here so formulas and renderers can resolve behavior from the field.
157
168
  *
169
+ * Formula fields additionally require `options.externalReferences`. The Facade
170
+ * persists those Host bindings before it updates the field config; if binding
171
+ * fails, the field is left unchanged. Pass `[]` only when the formula references
172
+ * fields in this Host Base and has no external Unit qualifier.
173
+ *
158
174
  * @param {FieldConfig} config The new field configuration.
175
+ * @param {IBaseFormulaFieldWriteOptions} [options] Required for Formula fields.
159
176
  * @returns {boolean} True if the config update was successful, false otherwise.
160
177
  * @example
161
178
  * ```ts
@@ -163,16 +180,22 @@ export declare class FBaseTableField {
163
180
  * const fBaseTable = fBase.getTableById('table-1');
164
181
  * const field = fBaseTable.getFieldByName('Total');
165
182
  * const success = field.setConfig({
166
- * formula: '=SUM(table[Amount], Pricing[Tax])',
183
+ * formula: '=SUM([Pricing]!Tax[Amount])',
167
184
  * numberFormat: {
168
185
  * type: 'currency',
169
186
  * pattern: '"$"#,##0.00'
170
187
  * },
188
+ * }, {
189
+ * externalReferences: [{
190
+ * qualifier: 'Pricing',
191
+ * sourceUnitId: 'pricing-base',
192
+ * sourceUnitType: univerAPI.Enum.UniverInstanceType.UNIVER_BASE,
193
+ * }],
171
194
  * });
172
195
  * console.log(success ? 'Field config updated' : 'Failed to update field config');
173
196
  * ```
174
197
  */
175
- setConfig(config: FieldConfig): boolean;
198
+ setConfig(config: FieldConfig, options?: IBaseFormulaFieldWriteOptions): boolean;
176
199
  /**
177
200
  * Set the default value for this field.
178
201
  * @param {IFieldSnapshot['defaultValue']} defaultValue The new default value.
@@ -189,7 +212,13 @@ export declare class FBaseTableField {
189
212
  setDefaultValue(defaultValue: IFieldSnapshot['defaultValue']): boolean;
190
213
  /**
191
214
  * Update this field.
215
+ * When this operation writes Formula config or changes the field type to Formula,
216
+ * `options.externalReferences` is required. Metadata-only updates to an existing
217
+ * Formula field, such as changing its name or description, do not need the mapping
218
+ * again.
219
+ *
192
220
  * @param {Partial<IFieldSnapshot>} patch The field snapshot patch to apply.
221
+ * @param {IBaseFormulaFieldWriteOptions} [options] Required when this update writes a Formula field.
193
222
  * @returns {boolean} True if the update was successful, false otherwise.
194
223
  * @example
195
224
  * ```ts
@@ -203,11 +232,12 @@ export declare class FBaseTableField {
203
232
  * console.log(success ? 'Field updated' : 'Failed to update field');
204
233
  * ```
205
234
  */
206
- update(patch: Partial<IFieldSnapshot>): boolean;
235
+ update(patch: Partial<IFieldSnapshot>, options?: IBaseFormulaFieldWriteOptions): boolean;
207
236
  /**
208
237
  * Change this field type.
209
238
  * @param {BaseFieldType} type The new field type.
210
239
  * @param {FieldConfig} config The new field configuration.
240
+ * @param {IBaseFormulaFieldWriteOptions} [options] Required when `type` is Formula.
211
241
  * @returns {boolean} True if the type change was successful, false otherwise.
212
242
  * @example
213
243
  * ```ts
@@ -223,7 +253,9 @@ export declare class FBaseTableField {
223
253
  * console.log(success ? 'Field type changed' : 'Failed to change field type');
224
254
  * ```
225
255
  */
226
- changeType(type: BaseFieldType, config?: FieldConfig): boolean;
256
+ changeType(type: BaseFieldType.Formula, config: FieldConfig, options: IBaseFormulaFieldWriteOptions): boolean;
257
+ changeType(type: Exclude<BaseFieldType, BaseFieldType.Formula>, config?: FieldConfig): boolean;
258
+ changeType(type: BaseFieldType, config: FieldConfig, options: IBaseFormulaFieldWriteOptions): boolean;
227
259
  /**
228
260
  * Delete this field.
229
261
  *
@@ -261,4 +293,5 @@ export declare class FBaseTableField {
261
293
  afterFieldId?: string;
262
294
  }): boolean;
263
295
  private _getField;
296
+ private _writeFormulaExternalReferences;
264
297
  }
@@ -1,6 +1,7 @@
1
1
  import type { BaseCellValue, IBaseCellData, Injector, IRange } from '@univerjs/core';
2
2
  import type { FBase } from './f-base';
3
3
  import type { FBaseTable } from './f-table';
4
+ import { ICommandService } from '@univerjs/core';
4
5
  /**
5
6
  * Facade API object bound to a rectangular Base table range.
6
7
  *
@@ -34,7 +35,8 @@ export declare class FBaseTableRange {
34
35
  private readonly _table;
35
36
  private readonly _range;
36
37
  private readonly _inject;
37
- constructor(_base: FBase, _table: FBaseTable, _range: IRange, _inject: Injector);
38
+ private readonly _commandService;
39
+ constructor(_base: FBase, _table: FBaseTable, _range: IRange, _inject: Injector, _commandService: ICommandService);
38
40
  /**
39
41
  * Get the Base id.
40
42
  * @returns {string} The Base id.
@@ -219,4 +221,5 @@ export declare class FBaseTableRange {
219
221
  offset(rowOffset: number, columnOffset: number, numRows?: number, numColumns?: number): FBaseTableRange;
220
222
  private _getTable;
221
223
  private _assertInBounds;
224
+ private _getFieldIds;
222
225
  }