@univerjs-pro/bases 1.0.0-alpha.8 → 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 (122) 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/facade/f-base.d.ts +3 -2
  80. package/lib/types/facade/f-enum.d.ts +206 -2
  81. package/lib/types/facade/f-event.d.ts +102 -0
  82. package/lib/types/facade/f-field.d.ts +6 -6
  83. package/lib/types/facade/f-range.d.ts +4 -1
  84. package/lib/types/facade/f-record.d.ts +325 -1
  85. package/lib/types/facade/f-table.d.ts +246 -9
  86. package/lib/types/facade/f-univer.d.ts +2 -0
  87. package/lib/types/facade/f-view.d.ts +179 -3
  88. package/lib/types/facade/field-key.d.ts +3 -1
  89. package/lib/types/fields/date-format.d.ts +20 -1
  90. package/lib/types/fields/field-core-plugin.d.ts +7 -4
  91. package/lib/types/fields/field-stat.d.ts +10 -0
  92. package/lib/types/fields/progress-format.d.ts +1 -0
  93. package/lib/types/index.d.ts +19 -2
  94. package/lib/types/locale/en-US.d.ts +1 -1
  95. package/lib/types/models/base-hierarchy.d.ts +108 -0
  96. package/lib/types/models/record-link.d.ts +14 -0
  97. package/lib/types/ot/json1-op-applier.d.ts +3 -1
  98. package/lib/types/ot/json1-util.d.ts +2 -2
  99. package/lib/types/services/base-command.service.d.ts +1 -0
  100. package/lib/types/services/base-projection.service.d.ts +4 -0
  101. package/lib/umd/facade.js +1 -1
  102. package/lib/umd/index.js +1 -1
  103. package/lib/umd/locale/ar-SA.js +1 -1
  104. package/lib/umd/locale/ca-ES.js +1 -1
  105. package/lib/umd/locale/de-DE.js +1 -1
  106. package/lib/umd/locale/en-US.js +1 -1
  107. package/lib/umd/locale/es-ES.js +1 -1
  108. package/lib/umd/locale/fa-IR.js +1 -1
  109. package/lib/umd/locale/fr-FR.js +1 -1
  110. package/lib/umd/locale/id-ID.js +1 -1
  111. package/lib/umd/locale/it-IT.js +1 -1
  112. package/lib/umd/locale/ja-JP.js +1 -1
  113. package/lib/umd/locale/ko-KR.js +1 -1
  114. package/lib/umd/locale/pl-PL.js +1 -1
  115. package/lib/umd/locale/pt-BR.js +1 -1
  116. package/lib/umd/locale/ru-RU.js +1 -1
  117. package/lib/umd/locale/sk-SK.js +1 -1
  118. package/lib/umd/locale/vi-VN.js +1 -1
  119. package/lib/umd/locale/zh-CN.js +1 -1
  120. package/lib/umd/locale/zh-HK.js +1 -1
  121. package/lib/umd/locale/zh-TW.js +1 -1
  122. package/package.json +7 -7
@@ -1,8 +1,8 @@
1
1
  import type { IHostExternalReference } from '@univerjs-pro/engine-formula';
2
- import type { BaseFieldType, FieldConfig, IFieldSnapshot, Injector } from '@univerjs/core';
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 as BaseFieldTypeEnum } from '@univerjs/core';
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 _inject;
51
- constructor(_base: FBase, _table: FBaseTable, _fieldId: string, _inject: Injector);
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: BaseFieldTypeEnum.Formula, config: FieldConfig, options: IBaseFormulaFieldWriteOptions): boolean;
257
- changeType(type: Exclude<BaseFieldType, BaseFieldTypeEnum.Formula>, config?: FieldConfig): boolean;
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
- 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
  }
@@ -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
- constructor(_base: FBase, _table: FBaseTable, _recordId: string, _inject: Injector);
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
  }