@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,6 +1,7 @@
1
- import type { BaseCellValue, FieldId, Injector, IRecordSnapshot } from '@univerjs/core';
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
@@ -94,6 +103,71 @@ export declare class FBaseTableRecord {
94
103
  * ```
95
104
  */
96
105
  setValue(fieldId: FieldId, value: BaseCellValue): boolean;
106
+ /**
107
+ * Set the attachments stored in one attachment field through the Base command path.
108
+ * Uploading or encoding the file is intentionally handled by the caller, so this API works in browser and
109
+ * headless environments and participates in collaboration and undo/redo.
110
+ * @param {FieldId} fieldId The attachment field id.
111
+ * @param {IBaseAttachment[]} attachments Attachment descriptors to store. Pass an empty array to clear the field.
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
+ * ```
127
+ * @example Store the file id returned by a gRPC upload in a headless process
128
+ * ```ts
129
+ * const fBase = univerAPI.getActiveBase();
130
+ * if (!fBase) throw new Error('No active Base.');
131
+ * const table = fBase.getTableById('table-1');
132
+ * if (!table) throw new Error('Table not found.');
133
+ * const record = table.getRecordById('record-1');
134
+ * if (!record) throw new Error('Record not found.');
135
+ *
136
+ * const uploadedFileId = 'file-id-returned-by-grpc';
137
+ * const success = record.setAttachments('attachments', [{
138
+ * id: uploadedFileId,
139
+ * name: 'report.pdf',
140
+ * mimeType: 'application/pdf',
141
+ * sourceType: univerAPI.Enum.ImageSourceType.UUID,
142
+ * source: uploadedFileId
143
+ * }]);
144
+ * console.log(success);
145
+ * ```
146
+ * @example Encode a local file in a Node/headless process and store it directly
147
+ * ```ts
148
+ * import { readFile } from 'node:fs/promises';
149
+ *
150
+ * const fBase = univerAPI.getActiveBase();
151
+ * if (!fBase) throw new Error('No active Base.');
152
+ * const table = fBase.getTableById('table-1');
153
+ * if (!table) throw new Error('Table not found.');
154
+ * const record = table.getRecordById('record-1');
155
+ * if (!record) throw new Error('Record not found.');
156
+ *
157
+ * const file = await readFile('/path/to/hello.txt');
158
+ * const source = `data:text/plain;base64,${file.toString('base64')}`;
159
+ * const success = record.setAttachments('attachments', [{
160
+ * id: `local-${Date.now()}`,
161
+ * name: 'hello.txt',
162
+ * mimeType: 'text/plain',
163
+ * size: file.byteLength,
164
+ * sourceType: univerAPI.Enum.ImageSourceType.BASE64,
165
+ * source
166
+ * }]);
167
+ * console.log(success);
168
+ * ```
169
+ */
170
+ setAttachments(fieldId: FieldId, attachments: IBaseAttachment[]): boolean;
97
171
  /**
98
172
  * Set multiple field values in this record.
99
173
  * @param {Record<string, BaseCellValue>} values Field-id keyed values to write. Only the provided fields are
@@ -146,8 +220,16 @@ export declare class FBaseTableRecord {
146
220
  delete(): boolean;
147
221
  /**
148
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
+ *
149
230
  * @param {Partial<Omit<IRecordSnapshot, 'id'>>} [record] Optional record snapshot to override the source record.
150
231
  * @returns {FBaseTableRecord} The new record.
232
+ * @throws {BaseHierarchyError} If the duplicated Parent edge is invalid.
151
233
  * @example
152
234
  * ```ts
153
235
  * const fBase = univerAPI.getActiveBase();
@@ -177,5 +259,298 @@ export declare class FBaseTableRecord {
177
259
  * ```
178
260
  */
179
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;
180
554
  private _getRecord;
555
+ private _getRecordLinkField;
181
556
  }