@univerjs-pro/bases 1.0.0-alpha.8 → 1.0.0-beta.1
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.
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/locale/ar-SA.js +1 -1
- package/lib/cjs/locale/ca-ES.js +1 -1
- package/lib/cjs/locale/de-DE.js +1 -1
- package/lib/cjs/locale/en-US.js +1 -1
- package/lib/cjs/locale/es-ES.js +1 -1
- package/lib/cjs/locale/fa-IR.js +1 -1
- package/lib/cjs/locale/fr-FR.js +1 -1
- package/lib/cjs/locale/id-ID.js +1 -1
- package/lib/cjs/locale/it-IT.js +1 -1
- package/lib/cjs/locale/ja-JP.js +1 -1
- package/lib/cjs/locale/ko-KR.js +1 -1
- package/lib/cjs/locale/pl-PL.js +1 -1
- package/lib/cjs/locale/pt-BR.js +1 -1
- package/lib/cjs/locale/ru-RU.js +1 -1
- package/lib/cjs/locale/sk-SK.js +1 -1
- package/lib/cjs/locale/vi-VN.js +1 -1
- package/lib/cjs/locale/zh-CN.js +1 -1
- package/lib/cjs/locale/zh-HK.js +1 -1
- package/lib/cjs/locale/zh-TW.js +1 -1
- package/lib/es/facade.js +1 -1
- package/lib/es/index.js +1 -1
- package/lib/es/locale/ar-SA.js +1 -1
- package/lib/es/locale/ca-ES.js +1 -1
- package/lib/es/locale/de-DE.js +1 -1
- package/lib/es/locale/en-US.js +1 -1
- package/lib/es/locale/es-ES.js +1 -1
- package/lib/es/locale/fa-IR.js +1 -1
- package/lib/es/locale/fr-FR.js +1 -1
- package/lib/es/locale/id-ID.js +1 -1
- package/lib/es/locale/it-IT.js +1 -1
- package/lib/es/locale/ja-JP.js +1 -1
- package/lib/es/locale/ko-KR.js +1 -1
- package/lib/es/locale/pl-PL.js +1 -1
- package/lib/es/locale/pt-BR.js +1 -1
- package/lib/es/locale/ru-RU.js +1 -1
- package/lib/es/locale/sk-SK.js +1 -1
- package/lib/es/locale/vi-VN.js +1 -1
- package/lib/es/locale/zh-CN.js +1 -1
- package/lib/es/locale/zh-HK.js +1 -1
- package/lib/es/locale/zh-TW.js +1 -1
- package/lib/facade.js +1 -1
- package/lib/index.js +1 -1
- package/lib/locale/ar-SA.js +1 -1
- package/lib/locale/ca-ES.js +1 -1
- package/lib/locale/de-DE.js +1 -1
- package/lib/locale/en-US.js +1 -1
- package/lib/locale/es-ES.js +1 -1
- package/lib/locale/fa-IR.js +1 -1
- package/lib/locale/fr-FR.js +1 -1
- package/lib/locale/id-ID.js +1 -1
- package/lib/locale/it-IT.js +1 -1
- package/lib/locale/ja-JP.js +1 -1
- package/lib/locale/ko-KR.js +1 -1
- package/lib/locale/pl-PL.js +1 -1
- package/lib/locale/pt-BR.js +1 -1
- package/lib/locale/ru-RU.js +1 -1
- package/lib/locale/sk-SK.js +1 -1
- package/lib/locale/vi-VN.js +1 -1
- package/lib/locale/zh-CN.js +1 -1
- package/lib/locale/zh-HK.js +1 -1
- package/lib/locale/zh-TW.js +1 -1
- package/lib/types/commands/commands/batch-create-base-records.command.d.ts +2 -0
- package/lib/types/commands/commands/batch-delete-base-records.command.d.ts +2 -0
- package/lib/types/commands/commands/create-base-child-record.command.d.ts +15 -0
- package/lib/types/commands/commands/create-base-record.command.d.ts +2 -0
- package/lib/types/commands/commands/delete-base-record.command.d.ts +2 -0
- package/lib/types/commands/commands/duplicate-base-record.command.d.ts +2 -0
- package/lib/types/commands/commands/move-base-hierarchy-record.command.d.ts +17 -0
- package/lib/types/commands/commands/set-base-range-values.command.d.ts +8 -1
- package/lib/types/commands/commands/set-base-record-values.command.d.ts +2 -0
- package/lib/types/commands/commands/set-base-table-hierarchy-field.command.d.ts +9 -0
- package/lib/types/commands/commands/update-base-cell.command.d.ts +2 -0
- package/lib/types/commands/commands/update-base-view-conditional-color-rules.command.d.ts +32 -0
- package/lib/types/commands/commands/validate-base-formula.command.d.ts +8 -0
- package/lib/types/commands/mutations/apply-base-json1.mutation.d.ts +4 -0
- package/lib/types/commands/utils/base-record-creation.d.ts +18 -0
- package/lib/types/commands/utils/base-validation.d.ts +6 -1
- package/lib/types/controllers/base-formula-calculation.controller.d.ts +1 -0
- package/lib/types/facade/f-base.d.ts +24 -9
- package/lib/types/facade/f-enum.d.ts +208 -3
- package/lib/types/facade/f-event.d.ts +102 -0
- package/lib/types/facade/f-field.d.ts +6 -6
- package/lib/types/facade/f-range.d.ts +4 -1
- package/lib/types/facade/f-record.d.ts +325 -1
- package/lib/types/facade/f-table.d.ts +293 -16
- package/lib/types/facade/f-univer.d.ts +2 -0
- package/lib/types/facade/f-view.d.ts +179 -3
- package/lib/types/facade/field-key.d.ts +3 -1
- package/lib/types/fields/date-format.d.ts +20 -1
- package/lib/types/fields/field-core-plugin.d.ts +7 -4
- package/lib/types/fields/field-stat.d.ts +10 -0
- package/lib/types/fields/progress-format.d.ts +1 -0
- package/lib/types/index.d.ts +25 -2
- package/lib/types/locale/en-US.d.ts +1 -1
- package/lib/types/models/base-hierarchy.d.ts +108 -0
- package/lib/types/models/base-table-name.d.ts +8 -0
- package/lib/types/models/record-link.d.ts +14 -0
- package/lib/types/ot/json1-op-applier.d.ts +3 -1
- package/lib/types/ot/json1-op-factory.d.ts +1 -1
- package/lib/types/ot/json1-util.d.ts +2 -2
- package/lib/types/services/base-command.service.d.ts +1 -0
- package/lib/types/services/base-formula.service.d.ts +2 -23
- package/lib/types/services/base-projection.service.d.ts +4 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/lib/umd/locale/ar-SA.js +1 -1
- package/lib/umd/locale/ca-ES.js +1 -1
- package/lib/umd/locale/de-DE.js +1 -1
- package/lib/umd/locale/en-US.js +1 -1
- package/lib/umd/locale/es-ES.js +1 -1
- package/lib/umd/locale/fa-IR.js +1 -1
- package/lib/umd/locale/fr-FR.js +1 -1
- package/lib/umd/locale/id-ID.js +1 -1
- package/lib/umd/locale/it-IT.js +1 -1
- package/lib/umd/locale/ja-JP.js +1 -1
- package/lib/umd/locale/ko-KR.js +1 -1
- package/lib/umd/locale/pl-PL.js +1 -1
- package/lib/umd/locale/pt-BR.js +1 -1
- package/lib/umd/locale/ru-RU.js +1 -1
- package/lib/umd/locale/sk-SK.js +1 -1
- package/lib/umd/locale/vi-VN.js +1 -1
- package/lib/umd/locale/zh-CN.js +1 -1
- package/lib/umd/locale/zh-HK.js +1 -1
- package/lib/umd/locale/zh-TW.js +1 -1
- package/package.json +7 -7
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
import type { IHostExternalReference } from '@univerjs-pro/engine-formula';
|
|
2
|
-
import type {
|
|
2
|
+
import type { FieldConfig, IFieldSnapshot } from '@univerjs/core';
|
|
3
3
|
import type { FBase } from './f-base';
|
|
4
4
|
import type { FBaseTable } from './f-table';
|
|
5
|
-
import { BaseFieldType
|
|
5
|
+
import { BaseFieldType, ICommandService } from '@univerjs/core';
|
|
6
6
|
export interface IBaseFormulaFieldWriteOptions {
|
|
7
7
|
/**
|
|
8
8
|
* Required, complete Host-owned bindings for this formula write.
|
|
@@ -47,8 +47,8 @@ export declare class FBaseTableField {
|
|
|
47
47
|
private readonly _base;
|
|
48
48
|
private readonly _table;
|
|
49
49
|
private readonly _fieldId;
|
|
50
|
-
private readonly
|
|
51
|
-
constructor(_base: FBase, _table: FBaseTable, _fieldId: string,
|
|
50
|
+
private readonly _commandService;
|
|
51
|
+
constructor(_base: FBase, _table: FBaseTable, _fieldId: string, _commandService: ICommandService);
|
|
52
52
|
/**
|
|
53
53
|
* Get the field id.
|
|
54
54
|
* @returns {string} The field id.
|
|
@@ -253,8 +253,8 @@ export declare class FBaseTableField {
|
|
|
253
253
|
* console.log(success ? 'Field type changed' : 'Failed to change field type');
|
|
254
254
|
* ```
|
|
255
255
|
*/
|
|
256
|
-
changeType(type:
|
|
257
|
-
changeType(type: Exclude<BaseFieldType,
|
|
256
|
+
changeType(type: BaseFieldType.Formula, config: FieldConfig, options: IBaseFormulaFieldWriteOptions): boolean;
|
|
257
|
+
changeType(type: Exclude<BaseFieldType, BaseFieldType.Formula>, config?: FieldConfig): boolean;
|
|
258
258
|
changeType(type: BaseFieldType, config: FieldConfig, options: IBaseFormulaFieldWriteOptions): boolean;
|
|
259
259
|
/**
|
|
260
260
|
* Delete this field.
|
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BaseCellValue, FieldId, IBaseAttachment, Injector, IRecordSnapshot } 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
|
import { BaseFieldKeyEnum } from './field-key';
|
|
5
6
|
/**
|
|
6
7
|
* Facade API object bound to a Base record.
|
|
@@ -30,7 +31,8 @@ export declare class FBaseTableRecord {
|
|
|
30
31
|
private readonly _table;
|
|
31
32
|
private readonly _recordId;
|
|
32
33
|
private readonly _inject;
|
|
33
|
-
|
|
34
|
+
private readonly _commandService;
|
|
35
|
+
constructor(_base: FBase, _table: FBaseTable, _recordId: string, _inject: Injector, _commandService: ICommandService);
|
|
34
36
|
/**
|
|
35
37
|
* Get the record id.
|
|
36
38
|
* @returns {string} The record id.
|
|
@@ -57,6 +59,9 @@ export declare class FBaseTableRecord {
|
|
|
57
59
|
getRecord(): IRecordSnapshot;
|
|
58
60
|
/**
|
|
59
61
|
* Get a field value from this record.
|
|
62
|
+
*
|
|
63
|
+
* For a RecordLink field, this returns its canonical storage string. Prefer
|
|
64
|
+
* `getLinkedRecordIds()` when consuming RecordLink values.
|
|
60
65
|
* @param {FieldId} fieldId The field id.
|
|
61
66
|
* @returns {BaseCellValue} The cell value, or `null` if the field is empty.
|
|
62
67
|
* @example
|
|
@@ -82,6 +87,10 @@ export declare class FBaseTableRecord {
|
|
|
82
87
|
getValues(): IRecordSnapshot['values'];
|
|
83
88
|
/**
|
|
84
89
|
* Set one field value in this record.
|
|
90
|
+
*
|
|
91
|
+
* For a RecordLink field, prefer `setLinkedRecordIds()`, `addLinkedRecord()`,
|
|
92
|
+
* or `removeLinkedRecord()`. Those methods accept Record IDs directly and
|
|
93
|
+
* document the single-link and multi-link behavior.
|
|
85
94
|
* @param fieldId The field id to write.
|
|
86
95
|
* @param value The new cell value. Pass `null` to clear the cell.
|
|
87
96
|
* @example
|
|
@@ -101,6 +110,20 @@ export declare class FBaseTableRecord {
|
|
|
101
110
|
* @param {FieldId} fieldId The attachment field id.
|
|
102
111
|
* @param {IBaseAttachment[]} attachments Attachment descriptors to store. Pass an empty array to clear the field.
|
|
103
112
|
* @returns {boolean} `true` if the undoable command succeeded, `false` otherwise.
|
|
113
|
+
* @example Store a public URL
|
|
114
|
+
* ```ts
|
|
115
|
+
* const record = univerAPI.getActiveBase()
|
|
116
|
+
* .getTableById('table-1')
|
|
117
|
+
* .getRecordById('record-1');
|
|
118
|
+
* const success = record.setAttachments('attachments', [{
|
|
119
|
+
* id: 'product-image',
|
|
120
|
+
* name: 'product.webp',
|
|
121
|
+
* source: 'https://example.com/product.webp',
|
|
122
|
+
* sourceType: univerAPI.Enum.ImageSourceType.URL,
|
|
123
|
+
* mimeType: 'image/webp'
|
|
124
|
+
* }]);
|
|
125
|
+
* console.log(success);
|
|
126
|
+
* ```
|
|
104
127
|
* @example Store the file id returned by a gRPC upload in a headless process
|
|
105
128
|
* ```ts
|
|
106
129
|
* const fBase = univerAPI.getActiveBase();
|
|
@@ -197,8 +220,16 @@ export declare class FBaseTableRecord {
|
|
|
197
220
|
delete(): boolean;
|
|
198
221
|
/**
|
|
199
222
|
* Duplicate this record.
|
|
223
|
+
*
|
|
224
|
+
* The system Record ID is regenerated by the command and is never copied from
|
|
225
|
+
* the source record. If the source or override values include the table's
|
|
226
|
+
* canonical Parent field, that edge is validated and committed atomically with
|
|
227
|
+
* the duplicate. The operation emits hierarchy events with `Facade` source and
|
|
228
|
+
* rejects a resulting depth overflow.
|
|
229
|
+
*
|
|
200
230
|
* @param {Partial<Omit<IRecordSnapshot, 'id'>>} [record] Optional record snapshot to override the source record.
|
|
201
231
|
* @returns {FBaseTableRecord} The new record.
|
|
232
|
+
* @throws {BaseHierarchyError} If the duplicated Parent edge is invalid.
|
|
202
233
|
* @example
|
|
203
234
|
* ```ts
|
|
204
235
|
* const fBase = univerAPI.getActiveBase();
|
|
@@ -228,5 +259,298 @@ export declare class FBaseTableRecord {
|
|
|
228
259
|
* ```
|
|
229
260
|
*/
|
|
230
261
|
setOrderKey(orderKey: string): boolean;
|
|
262
|
+
/**
|
|
263
|
+
* Return the ordered target Record IDs stored in a RecordLink field.
|
|
264
|
+
*
|
|
265
|
+
* This method returns IDs, not the configured display labels. Resolve a target
|
|
266
|
+
* record through the target table when more data is needed. Dangling IDs remain
|
|
267
|
+
* visible so callers can diagnose or remove links left by imported snapshots.
|
|
268
|
+
* @param {FieldId} fieldId The RecordLink field id.
|
|
269
|
+
* @returns {string[]} Ordered target Record IDs.
|
|
270
|
+
* @throws {Error} If `fieldId` is missing or is not a RecordLink field.
|
|
271
|
+
* @example Read linked records
|
|
272
|
+
* ```ts
|
|
273
|
+
* const fBase = univerAPI.getActiveBase();
|
|
274
|
+
* const tasks = fBase.getTableById('tasks-table');
|
|
275
|
+
* const projects = fBase.getTableById('projects-table');
|
|
276
|
+
* if (!tasks || !projects) {
|
|
277
|
+
* throw new Error('Expected the Tasks and Projects tables.');
|
|
278
|
+
* }
|
|
279
|
+
* const task = tasks.getRecordById('task-1');
|
|
280
|
+
* const linkField = tasks.getFieldByName('Related projects');
|
|
281
|
+
*
|
|
282
|
+
* if (task && linkField) {
|
|
283
|
+
* const linkedProjects = task
|
|
284
|
+
* .getLinkedRecordIds(linkField.getId())
|
|
285
|
+
* .map((recordId) => projects.getRecordById(recordId))
|
|
286
|
+
* .filter((record) => record !== null);
|
|
287
|
+
* console.log(linkedProjects.map((record) => record.getValues()));
|
|
288
|
+
* }
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
getLinkedRecordIds(fieldId: FieldId): string[];
|
|
292
|
+
/**
|
|
293
|
+
* Replace a RecordLink with an ordered list of target Record IDs.
|
|
294
|
+
*
|
|
295
|
+
* The supplied order is preserved and duplicate IDs keep only their first
|
|
296
|
+
* occurrence. Pass `[]` to clear the link. Every target record must exist in
|
|
297
|
+
* the configured target table, and a single-link field accepts at most one ID.
|
|
298
|
+
* @param {FieldId} fieldId The RecordLink field id.
|
|
299
|
+
* @param {readonly string[]} recordIds Target Record IDs in display order. Pass `[]` to clear the field.
|
|
300
|
+
* @returns {boolean} Whether the undoable command succeeded.
|
|
301
|
+
* @throws {Error} If the field is not a RecordLink, its config is invalid, a target is missing, or a single-link field receives multiple IDs.
|
|
302
|
+
* @example Replace or clear linked records
|
|
303
|
+
* ```ts
|
|
304
|
+
* const task = univerAPI.getActiveBase()
|
|
305
|
+
* .getTableById('tasks-table')
|
|
306
|
+
* ?.getRecordById('task-1');
|
|
307
|
+
*
|
|
308
|
+
* task?.setLinkedRecordIds('related-projects', ['project-2', 'project-1']);
|
|
309
|
+
* task?.setLinkedRecordIds('related-projects', []); // Clear all links.
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
setLinkedRecordIds(fieldId: FieldId, recordIds: readonly string[]): boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Add one target record to a RecordLink field.
|
|
315
|
+
*
|
|
316
|
+
* A multi-link field appends a new ID and treats an existing ID as a successful
|
|
317
|
+
* no-op. A single-link field replaces its current target.
|
|
318
|
+
* @param {FieldId} fieldId The RecordLink field id.
|
|
319
|
+
* @param {string} recordId The target Record ID.
|
|
320
|
+
* @returns {boolean} Whether the undoable command succeeded.
|
|
321
|
+
* @throws {Error} If the field or target record is invalid.
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* const task = univerAPI.getActiveBase()
|
|
325
|
+
* .getTableById('tasks-table')
|
|
326
|
+
* ?.getRecordById('task-1');
|
|
327
|
+
* task?.addLinkedRecord('related-projects', 'project-3');
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
addLinkedRecord(fieldId: FieldId, recordId: string): boolean;
|
|
331
|
+
/**
|
|
332
|
+
* Remove one target record while retaining the order of the remaining IDs.
|
|
333
|
+
* Removing an ID that is not linked is a successful no-op.
|
|
334
|
+
* @param {FieldId} fieldId The RecordLink field id.
|
|
335
|
+
* @param {string} recordId The target Record ID.
|
|
336
|
+
* @returns {boolean} Whether the undoable command succeeded.
|
|
337
|
+
* @throws {Error} If `fieldId` is missing or is not a RecordLink field.
|
|
338
|
+
* @example
|
|
339
|
+
* ```ts
|
|
340
|
+
* const task = univerAPI.getActiveBase()
|
|
341
|
+
* .getTableById('tasks-table')
|
|
342
|
+
* ?.getRecordById('task-1');
|
|
343
|
+
* task?.removeLinkedRecord('related-projects', 'project-3');
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
removeLinkedRecord(fieldId: FieldId, recordId: string): boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Get this record's effective parent.
|
|
349
|
+
*
|
|
350
|
+
* Invalid stored edges, including a missing parent, self-parent, cycle, or an
|
|
351
|
+
* edge beyond the five-level limit, are preserved in record data but cut from
|
|
352
|
+
* the effective tree. Such a record is exposed as a root and this method returns
|
|
353
|
+
* `null`.
|
|
354
|
+
*
|
|
355
|
+
* @param {FieldId} fieldId The id returned by `table.getHierarchyFieldId()`.
|
|
356
|
+
* The deterministic virtual id is valid before the first hierarchy write.
|
|
357
|
+
* @returns {FBaseTableRecord | null} The effective parent, or `null` when this
|
|
358
|
+
* record is a root or its stored Parent edge is invalid.
|
|
359
|
+
* @throws {Error} If `fieldId` is neither the table's materialized Parent field
|
|
360
|
+
* nor its deterministic virtual Parent field.
|
|
361
|
+
* @example
|
|
362
|
+
* ```ts
|
|
363
|
+
* const base = univerAPI.getActiveBase();
|
|
364
|
+
* if (!base) throw new Error('No active Base.');
|
|
365
|
+
*
|
|
366
|
+
* const table = base.getTableById('tasks');
|
|
367
|
+
* if (!table) throw new Error('Tasks table not found.');
|
|
368
|
+
*
|
|
369
|
+
* const record = table.getRecordById('task-2');
|
|
370
|
+
* if (!record) throw new Error('Task not found.');
|
|
371
|
+
*
|
|
372
|
+
* const fieldId = table.getHierarchyFieldId();
|
|
373
|
+
* console.log(record.getParent(fieldId)?.getId() ?? 'root');
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
getParent(fieldId: FieldId): FBaseTableRecord | null;
|
|
377
|
+
/**
|
|
378
|
+
* Get this record's direct effective children in deterministic table order.
|
|
379
|
+
*
|
|
380
|
+
* The result excludes deeper descendants. It is safe to call before the first
|
|
381
|
+
* hierarchy write and returns an empty array in that state.
|
|
382
|
+
*
|
|
383
|
+
* @param {FieldId} fieldId The id returned by `table.getHierarchyFieldId()`.
|
|
384
|
+
* @returns {FBaseTableRecord[]} Direct children ordered by the table's manual
|
|
385
|
+
* record order. The returned array is a snapshot and can be modified safely.
|
|
386
|
+
* @throws {Error} If `fieldId` is not the table's actual or virtual Parent field.
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* const fieldId = table.getHierarchyFieldId();
|
|
390
|
+
* const parent = table.getRecordById('task-1');
|
|
391
|
+
* if (!parent) throw new Error('Parent record not found.');
|
|
392
|
+
*
|
|
393
|
+
* const childIds = parent.getChildren(fieldId).map((record) => record.getId());
|
|
394
|
+
* console.log(childIds);
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
getChildren(fieldId: FieldId): FBaseTableRecord[];
|
|
398
|
+
/**
|
|
399
|
+
* Get the effective parent chain, nearest parent first.
|
|
400
|
+
*
|
|
401
|
+
* The current record is not included. For `root -> section -> task`, calling
|
|
402
|
+
* this method on `task` returns `[section, root]`.
|
|
403
|
+
*
|
|
404
|
+
* @param {FieldId} fieldId The id returned by `table.getHierarchyFieldId()`.
|
|
405
|
+
* @returns {FBaseTableRecord[]} Ancestors from the direct parent to the root.
|
|
406
|
+
* @throws {Error} If `fieldId` is not the table's actual or virtual Parent field.
|
|
407
|
+
* @example
|
|
408
|
+
* ```ts
|
|
409
|
+
* const fieldId = table.getHierarchyFieldId();
|
|
410
|
+
* const task = table.getRecordById('task-3');
|
|
411
|
+
* if (!task) throw new Error('Task not found.');
|
|
412
|
+
*
|
|
413
|
+
* console.log(task.getAncestors(fieldId).map((record) => record.getId()));
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
getAncestors(fieldId: FieldId): FBaseTableRecord[];
|
|
417
|
+
/**
|
|
418
|
+
* Get every effective descendant in depth-first display order.
|
|
419
|
+
*
|
|
420
|
+
* The current record is not included. Each parent's children follow the
|
|
421
|
+
* deterministic table order, matching the expanded hierarchy projection before
|
|
422
|
+
* a view-specific filter or sort is applied.
|
|
423
|
+
*
|
|
424
|
+
* @param {FieldId} fieldId The id returned by `table.getHierarchyFieldId()`.
|
|
425
|
+
* @returns {FBaseTableRecord[]} All descendants in pre-order depth-first order.
|
|
426
|
+
* @throws {Error} If `fieldId` is not the table's actual or virtual Parent field.
|
|
427
|
+
* @example
|
|
428
|
+
* ```ts
|
|
429
|
+
* const fieldId = table.getHierarchyFieldId();
|
|
430
|
+
* const epic = table.getRecordById('epic-1');
|
|
431
|
+
* if (!epic) throw new Error('Epic not found.');
|
|
432
|
+
*
|
|
433
|
+
* const subtreeRecordIds = epic
|
|
434
|
+
* .getDescendants(fieldId)
|
|
435
|
+
* .map((record) => record.getId());
|
|
436
|
+
* console.log(subtreeRecordIds);
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
getDescendants(fieldId: FieldId): FBaseTableRecord[];
|
|
440
|
+
/**
|
|
441
|
+
* Move this record and its entire implicit subtree under another record.
|
|
442
|
+
*
|
|
443
|
+
* Pass `null` to move the record to the root level. When `orderKey` is supplied,
|
|
444
|
+
* the Parent change and manual table-order change are applied by one command,
|
|
445
|
+
* one JSON1 operation, and one Undo entry. A view Sort is independent of the
|
|
446
|
+
* table-level `orderKey` and may hide the manual-order result until Sort is removed.
|
|
447
|
+
*
|
|
448
|
+
* Before the Parent field exists, a successful non-root move materializes it in
|
|
449
|
+
* the same atomic command. The command rejects a self-parent, a cycle, a missing
|
|
450
|
+
* record, and a move whose resulting tree would exceed five levels.
|
|
451
|
+
*
|
|
452
|
+
* @param {FieldId} fieldId The id returned by `table.getHierarchyFieldId()`.
|
|
453
|
+
* @param {string | null} parentRecordId The new direct parent's record id, or
|
|
454
|
+
* `null` to move this record to the root level.
|
|
455
|
+
* @param {string} [orderKey] Optional table-level manual order key to update in
|
|
456
|
+
* the same undoable command.
|
|
457
|
+
* @returns {boolean} `true` when the atomic command succeeds. Moving to the same
|
|
458
|
+
* parent and order is a successful no-op.
|
|
459
|
+
* @throws {BaseHierarchyError} With a code from
|
|
460
|
+
* `univerAPI.Enum.BaseHierarchyErrorCode` for an invalid field, missing record,
|
|
461
|
+
* self-parent, cycle, or depth overflow.
|
|
462
|
+
* @example Move a subtree and handle a depth failure
|
|
463
|
+
* ```ts
|
|
464
|
+
* import { BaseHierarchyError } from '@univerjs-pro/bases';
|
|
465
|
+
*
|
|
466
|
+
* const base = univerAPI.getActiveBase();
|
|
467
|
+
* if (!base) throw new Error('No active Base.');
|
|
468
|
+
*
|
|
469
|
+
* const table = base.getTableById('tasks');
|
|
470
|
+
* if (!table) throw new Error('Tasks table not found.');
|
|
471
|
+
*
|
|
472
|
+
* const task = table.getRecordById('task-3');
|
|
473
|
+
* if (!task) throw new Error('Task not found.');
|
|
474
|
+
*
|
|
475
|
+
* const fieldId = table.getHierarchyFieldId();
|
|
476
|
+
* try {
|
|
477
|
+
* task.setParent(fieldId, 'task-1', '000020');
|
|
478
|
+
* } catch (error) {
|
|
479
|
+
* if (
|
|
480
|
+
* error instanceof BaseHierarchyError &&
|
|
481
|
+
* error.code === univerAPI.Enum.BaseHierarchyErrorCode.MaxDepth
|
|
482
|
+
* ) {
|
|
483
|
+
* console.error('The resulting hierarchy would exceed five levels.');
|
|
484
|
+
* } else {
|
|
485
|
+
* throw error;
|
|
486
|
+
* }
|
|
487
|
+
* }
|
|
488
|
+
*
|
|
489
|
+
* // Move the same subtree back to the root.
|
|
490
|
+
* task.setParent(fieldId, null);
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
setParent(fieldId: FieldId, parentRecordId: string | null, orderKey?: string): boolean;
|
|
494
|
+
/**
|
|
495
|
+
* Create a direct child of this record as one undoable operation.
|
|
496
|
+
*
|
|
497
|
+
* The initial record values and Parent edge are written together. If this is the
|
|
498
|
+
* table's first hierarchy write, the canonical same-table, single-value
|
|
499
|
+
* RecordLink field is also created in the same command and the same Undo entry.
|
|
500
|
+
* Subscribers therefore never observe a committed child without its Parent.
|
|
501
|
+
* The call is synchronous and returns the new record Facade directly; do not
|
|
502
|
+
* prefix it with `await`.
|
|
503
|
+
*
|
|
504
|
+
* Value keys are field ids by default. Pass
|
|
505
|
+
* `univerAPI.Enum.BaseFieldKeyEnum.Name` to use display names. The optional
|
|
506
|
+
* `record` object can set metadata such as `orderKey`, `createdAt`, `updatedAt`,
|
|
507
|
+
* `createdBy`, or `updatedBy`; the record id is always generated by this method.
|
|
508
|
+
*
|
|
509
|
+
* @param {FieldId} fieldId The id returned by `table.getHierarchyFieldId()`.
|
|
510
|
+
* @param {Record<FieldId, BaseCellValue>} values Initial field values. Do not
|
|
511
|
+
* include the Parent field; this method writes it from the current record.
|
|
512
|
+
* @param {BaseFieldKeyEnum} [fieldKey] Whether `values` keys are field ids or
|
|
513
|
+
* field display names. Defaults to `BaseFieldKeyEnum.Id`.
|
|
514
|
+
* @param {Partial<Omit<IRecordSnapshot, 'id'>>} [record] Optional record metadata.
|
|
515
|
+
* @returns {FBaseTableRecord} A Facade object for the newly created child,
|
|
516
|
+
* returned immediately after the synchronous command succeeds.
|
|
517
|
+
* @throws {BaseHierarchyError} With a code from
|
|
518
|
+
* `univerAPI.Enum.BaseHierarchyErrorCode` for an invalid field, missing parent,
|
|
519
|
+
* or depth overflow.
|
|
520
|
+
* @throws {Error} If record validation or the atomic command fails.
|
|
521
|
+
* @example Create the first hierarchy edge using field ids
|
|
522
|
+
* ```ts
|
|
523
|
+
* const base = univerAPI.getActiveBase();
|
|
524
|
+
* if (!base) throw new Error('No active Base.');
|
|
525
|
+
*
|
|
526
|
+
* const table = base.getTableById('tasks');
|
|
527
|
+
* if (!table) throw new Error('Tasks table not found.');
|
|
528
|
+
*
|
|
529
|
+
* const parent = table.getRecordById('task-1');
|
|
530
|
+
* if (!parent) throw new Error('Parent record not found.');
|
|
531
|
+
*
|
|
532
|
+
* const fieldId = table.getHierarchyFieldId();
|
|
533
|
+
* const child = parent.addChild(fieldId, {
|
|
534
|
+
* [table.getPrimaryFieldId()]: 'Write integration tests',
|
|
535
|
+
* });
|
|
536
|
+
*
|
|
537
|
+
* console.log(child.getParent(fieldId)?.getId()); // 'task-1'
|
|
538
|
+
* console.log(parent.getChildren(fieldId).map((record) => record.getId()));
|
|
539
|
+
* ```
|
|
540
|
+
* @example Create a child using field display names
|
|
541
|
+
* ```ts
|
|
542
|
+
* const child = parent.addChild(
|
|
543
|
+
* table.getHierarchyFieldId(),
|
|
544
|
+
* { Title: 'Document the Facade API', Status: 'Todo' },
|
|
545
|
+
* univerAPI.Enum.BaseFieldKeyEnum.Name,
|
|
546
|
+
* { orderKey: '000030', createdBy: 'agent-1', updatedBy: 'agent-1' }
|
|
547
|
+
* );
|
|
548
|
+
* console.log(child.getId());
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
addChild(fieldId: FieldId, values: Record<FieldId, BaseCellValue>, fieldKey?: BaseFieldKeyEnum, record?: Partial<Omit<IRecordSnapshot, 'id'>>): FBaseTableRecord;
|
|
552
|
+
private _getHierarchyIndex;
|
|
553
|
+
private _collectDescendantIds;
|
|
231
554
|
private _getRecord;
|
|
555
|
+
private _getRecordLinkField;
|
|
232
556
|
}
|