@univerjs-pro/bases 0.25.0-insiders.20260608-e4336f7

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 (157) hide show
  1. package/README.md +42 -0
  2. package/lib/cjs/facade.js +1 -0
  3. package/lib/cjs/index.js +1 -0
  4. package/lib/cjs/locale/ar-SA.js +1 -0
  5. package/lib/cjs/locale/ca-ES.js +1 -0
  6. package/lib/cjs/locale/de-DE.js +1 -0
  7. package/lib/cjs/locale/en-US.js +1 -0
  8. package/lib/cjs/locale/es-ES.js +1 -0
  9. package/lib/cjs/locale/fa-IR.js +1 -0
  10. package/lib/cjs/locale/fr-FR.js +1 -0
  11. package/lib/cjs/locale/id-ID.js +1 -0
  12. package/lib/cjs/locale/it-IT.js +1 -0
  13. package/lib/cjs/locale/ja-JP.js +1 -0
  14. package/lib/cjs/locale/ko-KR.js +1 -0
  15. package/lib/cjs/locale/pl-PL.js +1 -0
  16. package/lib/cjs/locale/pt-BR.js +1 -0
  17. package/lib/cjs/locale/ru-RU.js +1 -0
  18. package/lib/cjs/locale/sk-SK.js +1 -0
  19. package/lib/cjs/locale/vi-VN.js +1 -0
  20. package/lib/cjs/locale/zh-CN.js +1 -0
  21. package/lib/cjs/locale/zh-HK.js +1 -0
  22. package/lib/cjs/locale/zh-TW.js +1 -0
  23. package/lib/es/facade.js +1 -0
  24. package/lib/es/index.js +1 -0
  25. package/lib/es/locale/ar-SA.js +1 -0
  26. package/lib/es/locale/ca-ES.js +1 -0
  27. package/lib/es/locale/de-DE.js +1 -0
  28. package/lib/es/locale/en-US.js +1 -0
  29. package/lib/es/locale/es-ES.js +1 -0
  30. package/lib/es/locale/fa-IR.js +1 -0
  31. package/lib/es/locale/fr-FR.js +1 -0
  32. package/lib/es/locale/id-ID.js +1 -0
  33. package/lib/es/locale/it-IT.js +1 -0
  34. package/lib/es/locale/ja-JP.js +1 -0
  35. package/lib/es/locale/ko-KR.js +1 -0
  36. package/lib/es/locale/pl-PL.js +1 -0
  37. package/lib/es/locale/pt-BR.js +1 -0
  38. package/lib/es/locale/ru-RU.js +1 -0
  39. package/lib/es/locale/sk-SK.js +1 -0
  40. package/lib/es/locale/vi-VN.js +1 -0
  41. package/lib/es/locale/zh-CN.js +1 -0
  42. package/lib/es/locale/zh-HK.js +1 -0
  43. package/lib/es/locale/zh-TW.js +1 -0
  44. package/lib/facade.js +1 -0
  45. package/lib/index.js +1 -0
  46. package/lib/locale/ar-SA.js +1 -0
  47. package/lib/locale/ca-ES.js +1 -0
  48. package/lib/locale/de-DE.js +1 -0
  49. package/lib/locale/en-US.js +1 -0
  50. package/lib/locale/es-ES.js +1 -0
  51. package/lib/locale/fa-IR.js +1 -0
  52. package/lib/locale/fr-FR.js +1 -0
  53. package/lib/locale/id-ID.js +1 -0
  54. package/lib/locale/it-IT.js +1 -0
  55. package/lib/locale/ja-JP.js +1 -0
  56. package/lib/locale/ko-KR.js +1 -0
  57. package/lib/locale/pl-PL.js +1 -0
  58. package/lib/locale/pt-BR.js +1 -0
  59. package/lib/locale/ru-RU.js +1 -0
  60. package/lib/locale/sk-SK.js +1 -0
  61. package/lib/locale/vi-VN.js +1 -0
  62. package/lib/locale/zh-CN.js +1 -0
  63. package/lib/locale/zh-HK.js +1 -0
  64. package/lib/locale/zh-TW.js +1 -0
  65. package/lib/types/commands/cell.command.d.ts +32 -0
  66. package/lib/types/commands/field.command.d.ts +53 -0
  67. package/lib/types/commands/record.command.d.ts +39 -0
  68. package/lib/types/commands/table.command.d.ts +18 -0
  69. package/lib/types/commands/undo-redo.d.ts +2 -0
  70. package/lib/types/commands/view.command.d.ts +107 -0
  71. package/lib/types/controllers/base-active-dirty.controller.d.ts +16 -0
  72. package/lib/types/controllers/base-formula-calculation.controller.d.ts +23 -0
  73. package/lib/types/controllers/base-formula-optional-identifier.d.ts +1 -0
  74. package/lib/types/controllers/base-remote-formula.controller.d.ts +13 -0
  75. package/lib/types/facade/f-base.d.ts +362 -0
  76. package/lib/types/facade/f-event.d.ts +61 -0
  77. package/lib/types/facade/f-field.d.ts +191 -0
  78. package/lib/types/facade/f-permission.d.ts +299 -0
  79. package/lib/types/facade/f-range.d.ts +179 -0
  80. package/lib/types/facade/f-record.d.ts +137 -0
  81. package/lib/types/facade/f-table.d.ts +769 -0
  82. package/lib/types/facade/f-univer.d.ts +148 -0
  83. package/lib/types/facade/f-view.d.ts +275 -0
  84. package/lib/types/facade/index.d.ts +10 -0
  85. package/lib/types/fields/date-format.d.ts +6 -0
  86. package/lib/types/fields/field-core-plugin.d.ts +21 -0
  87. package/lib/types/fields/number-format.d.ts +15 -0
  88. package/lib/types/index.d.ts +48 -0
  89. package/lib/types/locale/ar-SA.d.ts +3 -0
  90. package/lib/types/locale/ca-ES.d.ts +3 -0
  91. package/lib/types/locale/de-DE.d.ts +3 -0
  92. package/lib/types/locale/en-US.d.ts +59 -0
  93. package/lib/types/locale/es-ES.d.ts +3 -0
  94. package/lib/types/locale/fa-IR.d.ts +3 -0
  95. package/lib/types/locale/fr-FR.d.ts +3 -0
  96. package/lib/types/locale/id-ID.d.ts +3 -0
  97. package/lib/types/locale/it-IT.d.ts +3 -0
  98. package/lib/types/locale/ja-JP.d.ts +3 -0
  99. package/lib/types/locale/ko-KR.d.ts +3 -0
  100. package/lib/types/locale/pl-PL.d.ts +3 -0
  101. package/lib/types/locale/pt-BR.d.ts +3 -0
  102. package/lib/types/locale/ru-RU.d.ts +3 -0
  103. package/lib/types/locale/sk-SK.d.ts +3 -0
  104. package/lib/types/locale/vi-VN.d.ts +3 -0
  105. package/lib/types/locale/zh-CN.d.ts +3 -0
  106. package/lib/types/locale/zh-HK.d.ts +3 -0
  107. package/lib/types/locale/zh-TW.d.ts +3 -0
  108. package/lib/types/models/base-cell-data.d.ts +14 -0
  109. package/lib/types/models/base-snapshot.d.ts +1 -0
  110. package/lib/types/models/default-table.d.ts +12 -0
  111. package/lib/types/models/field-snapshot.d.ts +1 -0
  112. package/lib/types/models/record-snapshot.d.ts +1 -0
  113. package/lib/types/models/table-snapshot.d.ts +1 -0
  114. package/lib/types/models/value.d.ts +1 -0
  115. package/lib/types/models/view-snapshot.d.ts +1 -0
  116. package/lib/types/mutations/json1.mutation.d.ts +7 -0
  117. package/lib/types/mutations/utils.d.ts +2 -0
  118. package/lib/types/ot/json1-adapter.d.ts +103 -0
  119. package/lib/types/ot/json1-invalidation.d.ts +2 -0
  120. package/lib/types/ot/json1-op-applier.d.ts +6 -0
  121. package/lib/types/ot/json1-op-factory.d.ts +64 -0
  122. package/lib/types/ot/json1-path.d.ts +13 -0
  123. package/lib/types/plugin.d.ts +35 -0
  124. package/lib/types/search/base-search.d.ts +24 -0
  125. package/lib/types/services/base-active-dirty.service.d.ts +24 -0
  126. package/lib/types/services/base-command.service.d.ts +122 -0
  127. package/lib/types/services/base-compression.service.d.ts +46 -0
  128. package/lib/types/services/base-field-registry.service.d.ts +17 -0
  129. package/lib/types/services/base-formula.service.d.ts +71 -0
  130. package/lib/types/services/base-performance.service.d.ts +5 -0
  131. package/lib/types/services/base-permission.service.d.ts +76 -0
  132. package/lib/types/services/base-projection.service.d.ts +97 -0
  133. package/lib/types/services/base-resource.service.d.ts +15 -0
  134. package/lib/types/services/base-view-registry.service.d.ts +15 -0
  135. package/lib/types/views/view-core-plugin.d.ts +21 -0
  136. package/lib/umd/facade.js +1 -0
  137. package/lib/umd/index.js +1 -0
  138. package/lib/umd/locale/ar-SA.js +1 -0
  139. package/lib/umd/locale/ca-ES.js +1 -0
  140. package/lib/umd/locale/de-DE.js +1 -0
  141. package/lib/umd/locale/en-US.js +1 -0
  142. package/lib/umd/locale/es-ES.js +1 -0
  143. package/lib/umd/locale/fa-IR.js +1 -0
  144. package/lib/umd/locale/fr-FR.js +1 -0
  145. package/lib/umd/locale/id-ID.js +1 -0
  146. package/lib/umd/locale/it-IT.js +1 -0
  147. package/lib/umd/locale/ja-JP.js +1 -0
  148. package/lib/umd/locale/ko-KR.js +1 -0
  149. package/lib/umd/locale/pl-PL.js +1 -0
  150. package/lib/umd/locale/pt-BR.js +1 -0
  151. package/lib/umd/locale/ru-RU.js +1 -0
  152. package/lib/umd/locale/sk-SK.js +1 -0
  153. package/lib/umd/locale/vi-VN.js +1 -0
  154. package/lib/umd/locale/zh-CN.js +1 -0
  155. package/lib/umd/locale/zh-HK.js +1 -0
  156. package/lib/umd/locale/zh-TW.js +1 -0
  157. package/package.json +86 -0
@@ -0,0 +1,362 @@
1
+ import type { BaseDataModel, FieldId, IBaseSnapshot, ICommandService, IDisposable } from '@univerjs/core';
2
+ import type { IBaseTableSearchResult } from '../search/base-search';
3
+ import type { IBasePermissionService } from '../services/base-permission.service';
4
+ import type { IBaseProjectionService } from '../services/base-projection.service';
5
+ import type { IBaseEventMap } from './f-event';
6
+ import { BaseEventName } from './f-event';
7
+ import { FBasePermission } from './f-permission';
8
+ import { FTable } from './f-table';
9
+ export interface ICreateTableInput {
10
+ /** Optional table id. A random id is generated when omitted. */
11
+ id?: string;
12
+ /** Table display name. */
13
+ name: string;
14
+ /** Primary text field display name. */
15
+ primaryFieldName?: string;
16
+ /** Optional insertion index in the Base table order. */
17
+ index?: number;
18
+ }
19
+ export interface ISearchTableInput {
20
+ /** Search text. Blank queries return no matches. */
21
+ query: string;
22
+ /** Optional view id. When provided, records are searched in the view projection. */
23
+ viewId?: string;
24
+ /** Optional field ids to search. Defaults to visible/searchable fields. */
25
+ fieldIds?: ReadonlyArray<FieldId>;
26
+ /** Optional maximum number of matches. */
27
+ limit?: number;
28
+ }
29
+ export interface ICopyTableInput {
30
+ /** Optional table id for the copied table. A random id is generated when omitted. */
31
+ id?: string;
32
+ /** Optional copied table name. Defaults to `<source name> Copy`. */
33
+ name?: string;
34
+ /** Optional insertion index in the Base table order. */
35
+ index?: number;
36
+ }
37
+ export interface IBaseSchemaSnapshot {
38
+ id: string;
39
+ name: string;
40
+ tables: Array<{
41
+ id: string;
42
+ name: string;
43
+ primaryFieldId: string;
44
+ fieldIds: string[];
45
+ viewIds: string[];
46
+ recordCount: number;
47
+ }>;
48
+ }
49
+ /**
50
+ * Facade API object bound to a Base unit.
51
+ *
52
+ * A Base contains multiple tables. In spreadsheet terms this is similar to a workbook,
53
+ * while a Base table is similar to a worksheet.
54
+ *
55
+ * Use `FBase` for runtime edits and use `getSnapshot()` / `save()` only at the
56
+ * persistence boundary. Facade writes execute commands, so Base events,
57
+ * permissions, undo/redo, formula dirty ranges, and collaboration adapters see
58
+ * the same operations as UI edits.
59
+ *
60
+ * @example Load a server snapshot, edit it, and save it back
61
+ * ```ts
62
+ * const base = univerAPI.createBase(serverSnapshot);
63
+ * const table = await base.createTable({
64
+ * id: 'tasks',
65
+ * name: 'Tasks',
66
+ * primaryFieldName: 'Title',
67
+ * });
68
+ * const status = await table.addField({
69
+ * id: 'status',
70
+ * name: 'Status',
71
+ * type: 'singleSelect',
72
+ * config: { options: [{ id: 'todo', name: 'Todo', color: 'blue' }] },
73
+ * });
74
+ * await table.addRecord({
75
+ * id: 'task-1',
76
+ * values: { [table.getPrimaryFieldId()]: 'Review protocol', [status.getId()]: 'todo' },
77
+ * });
78
+ * await saveBaseSnapshotToServer(base.save());
79
+ * ```
80
+ */
81
+ export declare class FBase {
82
+ private readonly _base;
83
+ private readonly _commandService;
84
+ private readonly _projectionService;
85
+ private readonly _permissionService;
86
+ constructor(_base: BaseDataModel, _commandService: ICommandService, _projectionService: IBaseProjectionService, _permissionService: IBasePermissionService);
87
+ /**
88
+ * Get the underlying Base data model.
89
+ * @returns The Base data model.
90
+ * @example
91
+ * ```ts
92
+ * const model = base.getBase();
93
+ * ```
94
+ */
95
+ getBase(): BaseDataModel;
96
+ /**
97
+ * Get the Base unit id.
98
+ * @returns The Base id.
99
+ * @example
100
+ * ```ts
101
+ * console.log(base.getId());
102
+ * ```
103
+ */
104
+ getId(): string;
105
+ /**
106
+ * Get the Base name.
107
+ * @returns The Base name.
108
+ * @example
109
+ * ```ts
110
+ * console.log(base.getName());
111
+ * ```
112
+ */
113
+ getName(): string;
114
+ /**
115
+ * Get all non-deleted tables in this Base.
116
+ * @returns Table facade objects ordered by the Base table order.
117
+ * @example
118
+ * ```ts
119
+ * const tables = base.getTables();
120
+ * ```
121
+ */
122
+ getTables(): FTable[];
123
+ /**
124
+ * Get the current Base snapshot.
125
+ *
126
+ * The returned object is the persisted model shape. Use it for protocol
127
+ * payloads, storage, and snapshot comparison. Use facade mutation methods
128
+ * instead of mutating this object directly.
129
+ *
130
+ * @returns The current Base snapshot.
131
+ * @example
132
+ * ```ts
133
+ * const snapshot = base.getSnapshot();
134
+ * await request('/api/base/save', { method: 'POST', body: JSON.stringify(snapshot) });
135
+ * ```
136
+ */
137
+ getSnapshot(): IBaseSnapshot;
138
+ /**
139
+ * Save and return the current Base snapshot.
140
+ *
141
+ * This method intentionally returns a snapshot instead of performing I/O.
142
+ * The caller decides how to persist the payload, for example by sending it
143
+ * to the server-side protocol adapter.
144
+ *
145
+ * @returns The current Base snapshot.
146
+ * @example
147
+ * ```ts
148
+ * const snapshot = base.save();
149
+ * await server.saveBase(snapshot.id, snapshot);
150
+ * ```
151
+ */
152
+ save(): IBaseSnapshot;
153
+ /**
154
+ * Set the Base name.
155
+ * @param name The new Base name.
156
+ * @example
157
+ * ```ts
158
+ * await base.setName('Product Roadmap');
159
+ * ```
160
+ */
161
+ setName(name: string): Promise<void>;
162
+ /**
163
+ * Get a table by id.
164
+ * @param tableId The table id.
165
+ * @returns The table facade, or null if the table does not exist.
166
+ * @example
167
+ * ```ts
168
+ * const table = base.getTable('table-1');
169
+ * ```
170
+ */
171
+ getTable(tableId: string): FTable | null;
172
+ /**
173
+ * Get a table by id.
174
+ * @param tableId The table id.
175
+ * @returns The table facade, or null if the table does not exist.
176
+ * @example
177
+ * ```ts
178
+ * const table = base.getTableById('table-1');
179
+ * ```
180
+ */
181
+ getTableById(tableId: string): FTable | null;
182
+ /**
183
+ * Get the first table matching a table name.
184
+ * @param name The table name.
185
+ * @returns The table facade, or null if no table matches.
186
+ * @example
187
+ * ```ts
188
+ * const table = base.getTableByName('Tasks');
189
+ * ```
190
+ */
191
+ getTableByName(name: string): FTable | null;
192
+ /**
193
+ * Create a table in this Base.
194
+ *
195
+ * The created table includes a primary text field. Provide `id` when the
196
+ * server or fixture needs deterministic ids; otherwise a random table id is
197
+ * generated.
198
+ *
199
+ * @param input Table creation options.
200
+ * `input.name` is required. `input.primaryFieldName` names the generated
201
+ * primary field. `input.index` inserts the table at a zero-based position in
202
+ * the Base table order.
203
+ * @returns The created table facade.
204
+ * @example
205
+ * ```ts
206
+ * const table = await base.createTable({
207
+ * id: 'tasks',
208
+ * name: 'Tasks',
209
+ * primaryFieldName: 'Title',
210
+ * });
211
+ * ```
212
+ * @example Full table creation flow
213
+ * ```ts
214
+ * const table = await base.createTable({ id: 'tasks', name: 'Tasks', primaryFieldName: 'Title' });
215
+ * const status = await table.addField({ id: 'status', name: 'Status', type: 'text', config: {} });
216
+ * await table.addRecord({
217
+ * id: 'task-1',
218
+ * values: { [table.getPrimaryFieldId()]: 'Ship beta', [status.getId()]: 'todo' },
219
+ * });
220
+ * console.log(base.save().tables.tasks.records['task-1']);
221
+ * ```
222
+ */
223
+ createTable(input: ICreateTableInput): Promise<FTable>;
224
+ /**
225
+ * Insert a table in this Base.
226
+ * @param input Table creation options. Use `index` to control the table order.
227
+ * @returns The inserted table facade.
228
+ * @example
229
+ * ```ts
230
+ * const table = await base.insertTable({ name: 'Archive', index: 1 });
231
+ * ```
232
+ */
233
+ insertTable(input: ICreateTableInput): Promise<FTable>;
234
+ /**
235
+ * Rename a table.
236
+ * @param tableId The target table id.
237
+ * @param name The new table name.
238
+ * @example
239
+ * ```ts
240
+ * await base.renameTable('tasks', 'Roadmap');
241
+ * ```
242
+ */
243
+ renameTable(tableId: string, name: string): Promise<void>;
244
+ /**
245
+ * Delete a table.
246
+ * @param tableId The target table id.
247
+ * @example
248
+ * ```ts
249
+ * await base.deleteTable('archive');
250
+ * ```
251
+ */
252
+ deleteTable(tableId: string): Promise<void>;
253
+ /**
254
+ * Copy a table including fields, views, records, and resources.
255
+ *
256
+ * This is useful for templates and archive flows. The copied table keeps
257
+ * field ids, view ids, record ids, values, and resources from the source
258
+ * table unless future migration code rewrites them.
259
+ *
260
+ * @param tableId Source table id.
261
+ * @param input Optional copied table id, name, and insertion index. `id`
262
+ * defaults to a generated table id, `name` defaults to
263
+ * `"<source name> Copy"`, and `index` controls table order.
264
+ * @returns The copied table facade.
265
+ * @example
266
+ * ```ts
267
+ * const copied = await base.copyTable('tasks', { name: 'Tasks Archive' });
268
+ * ```
269
+ */
270
+ copyTable(tableId: string, input?: ICopyTableInput): Promise<FTable>;
271
+ /**
272
+ * Run multiple facade operations in a callback.
273
+ * @param fn A callback that receives this Base facade.
274
+ * @returns The callback result.
275
+ * @example
276
+ * ```ts
277
+ * await base.batch(async (tx) => {
278
+ * await tx.createTable({ name: 'Tasks' });
279
+ * });
280
+ * ```
281
+ */
282
+ batch<T>(fn: (tx: FBase) => Promise<T>): Promise<T>;
283
+ /**
284
+ * Search records in a table.
285
+ *
286
+ * Search reads the current table snapshot. When `viewId` is provided, the
287
+ * search space follows that view projection, including hidden fields and
288
+ * projected row order.
289
+ *
290
+ * @param tableId The table id to search.
291
+ * @param input Search options. `query` is trimmed and blank queries return
292
+ * no matches. `viewId` searches in a view projection. `fieldIds` limits the
293
+ * searched fields. `limit` caps the number of matches.
294
+ * @returns Search result with the normalized query, total count, matched
295
+ * records, and matched field/cell information.
296
+ * @example
297
+ * ```ts
298
+ * const result = base.searchTable('tasks', {
299
+ * query: 'release',
300
+ * fieldIds: ['title', 'status'],
301
+ * limit: 20,
302
+ * });
303
+ * ```
304
+ */
305
+ searchTable(tableId: string, input: ISearchTableInput): IBaseTableSearchResult;
306
+ /**
307
+ * Get a compact schema snapshot for agent/tooling use.
308
+ *
309
+ * `getSchema()` intentionally omits row values. Use it when an agent,
310
+ * server route, or prompt needs structure and ids without transferring the
311
+ * full data payload.
312
+ *
313
+ * @returns The Base schema without row values.
314
+ * @example
315
+ * ```ts
316
+ * console.log(base.getSchema().tables.map((table) => table.name));
317
+ * ```
318
+ */
319
+ getSchema(): IBaseSchemaSnapshot;
320
+ /**
321
+ * Get the permission facade for this Base.
322
+ *
323
+ * Permission changes affect Base command permission checks and can be
324
+ * hydrated from server-side authorization data.
325
+ *
326
+ * @returns The Base permission facade.
327
+ * @example
328
+ * ```ts
329
+ * base.getPermission().setTablePermission('tasks', { createRecord: false });
330
+ * ```
331
+ */
332
+ getPermission(): FBasePermission;
333
+ /**
334
+ * Add a Base event listener.
335
+ *
336
+ * Events are derived from executed Base commands. They are useful for
337
+ * server sync indicators, audit logs, demos, and agent tools that need to
338
+ * observe facade writes.
339
+ *
340
+ * @param event Base event name. Use `BaseEventName.TableChanged`,
341
+ * `FieldChanged`, `RecordChanged`, `CellValueChanged`, or `ViewChanged`.
342
+ * @param listener Event callback. The payload shape depends on the event
343
+ * name and includes ids, facade wrappers for live objects when available,
344
+ * and the original command payload.
345
+ * @returns A disposable listener handle.
346
+ * @example
347
+ * ```ts
348
+ * const disposable = base.addEvent(BaseEventName.RecordChanged, (event) => {
349
+ * console.log(event.type, event.recordIds);
350
+ * });
351
+ * await table.addRecord({ values: { title: 'Observed row' } });
352
+ * disposable.dispose();
353
+ * ```
354
+ */
355
+ addEvent<T extends BaseEventName>(event: T, listener: (params: IBaseEventMap[T]) => void): IDisposable;
356
+ private _wrapTable;
357
+ private _resolveEvent;
358
+ }
359
+ export type CreateTableInput = ICreateTableInput;
360
+ export type SearchTableInput = ISearchTableInput;
361
+ export type CopyTableInput = ICopyTableInput;
362
+ export type BaseSchemaSnapshot = IBaseSchemaSnapshot;
@@ -0,0 +1,61 @@
1
+ import type { BaseCellValue, ICommandInfo } from '@univerjs/core';
2
+ import type { FTable } from './f-table';
3
+ import type { FRecord } from './f-record';
4
+ import type { FField } from './f-field';
5
+ import type { FView } from './f-view';
6
+ export declare const BaseEventName: {
7
+ readonly TableChanged: "TableChanged";
8
+ readonly FieldChanged: "FieldChanged";
9
+ readonly RecordChanged: "RecordChanged";
10
+ readonly CellValueChanged: "CellValueChanged";
11
+ readonly ViewChanged: "ViewChanged";
12
+ };
13
+ export type BaseEventName = typeof BaseEventName[keyof typeof BaseEventName];
14
+ export interface IBaseTableChangedEvent {
15
+ type: 'created' | 'renamed' | 'deleted';
16
+ table: FTable | null;
17
+ tableId: string;
18
+ payload: Readonly<ICommandInfo>;
19
+ }
20
+ export interface IBaseFieldChangedEvent {
21
+ type: 'created' | 'updated' | 'typeChanged' | 'deleted' | 'moved';
22
+ table: FTable;
23
+ field: FField | null;
24
+ tableId: string;
25
+ fieldId: string;
26
+ payload: Readonly<ICommandInfo>;
27
+ }
28
+ export interface IBaseRecordChangedEvent {
29
+ type: 'created' | 'updated' | 'deleted' | 'duplicated' | 'moved';
30
+ table: FTable;
31
+ records: FRecord[];
32
+ tableId: string;
33
+ recordIds: string[];
34
+ payload: Readonly<ICommandInfo>;
35
+ }
36
+ export interface IBaseCellValueChangedEvent {
37
+ table: FTable;
38
+ tableId: string;
39
+ changes: Array<{
40
+ recordId: string;
41
+ fieldId: string;
42
+ value: BaseCellValue;
43
+ }>;
44
+ payload: Readonly<ICommandInfo>;
45
+ }
46
+ export interface IBaseViewChangedEvent {
47
+ type: 'created' | 'updated' | 'renamed' | 'deleted' | 'moved';
48
+ table: FTable;
49
+ view: FView | null;
50
+ tableId: string;
51
+ viewId: string;
52
+ payload: Readonly<ICommandInfo>;
53
+ }
54
+ export interface IBaseEventMap {
55
+ [BaseEventName.TableChanged]: IBaseTableChangedEvent;
56
+ [BaseEventName.FieldChanged]: IBaseFieldChangedEvent;
57
+ [BaseEventName.RecordChanged]: IBaseRecordChangedEvent;
58
+ [BaseEventName.CellValueChanged]: IBaseCellValueChangedEvent;
59
+ [BaseEventName.ViewChanged]: IBaseViewChangedEvent;
60
+ }
61
+ export type BaseEventMap = IBaseEventMap;
@@ -0,0 +1,191 @@
1
+ import type { BaseDataModel, ICommandService, IFieldSnapshot } from '@univerjs/core';
2
+ /**
3
+ * Facade API object bound to a Base field.
4
+ *
5
+ * A Base field is equivalent to a column in a table.
6
+ * Field type and type-specific config live on the field snapshot. Cell values
7
+ * should reference field ids and should not duplicate field type as their
8
+ * source of truth.
9
+ *
10
+ * @example Update field metadata
11
+ * ```ts
12
+ * const field = table.getFieldByName('Status');
13
+ * if (field) {
14
+ * await field.setName('Stage');
15
+ * await field.setConfig({
16
+ * options: [{ id: 'done', name: 'Done', color: 'green' }],
17
+ * });
18
+ * await field.update({ description: 'Workflow stage from server auth.' });
19
+ * }
20
+ * ```
21
+ */
22
+ export declare class FField {
23
+ private readonly _base;
24
+ private readonly _tableId;
25
+ private readonly _fieldId;
26
+ private readonly _commandService;
27
+ constructor(_base: BaseDataModel, _tableId: string, _fieldId: string, _commandService: ICommandService);
28
+ /**
29
+ * Get the field id.
30
+ * @returns The field id.
31
+ * @example
32
+ * ```ts
33
+ * console.log(field.getId());
34
+ * ```
35
+ */
36
+ getId(): string;
37
+ /**
38
+ * Get the field snapshot.
39
+ * @returns The field snapshot.
40
+ * @example
41
+ * ```ts
42
+ * const rawField = field.getField();
43
+ * ```
44
+ */
45
+ getField(): IFieldSnapshot;
46
+ /**
47
+ * Get the field snapshot.
48
+ * @returns The field snapshot.
49
+ * @example
50
+ * ```ts
51
+ * const snapshot = field.getSnapshot();
52
+ * ```
53
+ */
54
+ getSnapshot(): IFieldSnapshot;
55
+ /**
56
+ * Get the field name.
57
+ * @returns The field name.
58
+ * @example
59
+ * ```ts
60
+ * console.log(field.getName());
61
+ * ```
62
+ */
63
+ getName(): string;
64
+ /**
65
+ * Get the field type.
66
+ * @returns The field type.
67
+ * @example
68
+ * ```ts
69
+ * console.log(field.getType());
70
+ * ```
71
+ */
72
+ getType(): IFieldSnapshot['type'];
73
+ /**
74
+ * Get the field configuration.
75
+ * @returns The field configuration.
76
+ * @example
77
+ * ```ts
78
+ * const config = field.getConfig();
79
+ * ```
80
+ */
81
+ getConfig(): IFieldSnapshot['config'];
82
+ /**
83
+ * Get the default value configured for this field.
84
+ * @returns The default value.
85
+ * @example
86
+ * ```ts
87
+ * const defaultValue = field.getDefaultValue();
88
+ * ```
89
+ */
90
+ getDefaultValue(): IFieldSnapshot['defaultValue'];
91
+ /**
92
+ * Get the field description.
93
+ * @returns The field description, if any.
94
+ * @example
95
+ * ```ts
96
+ * console.log(field.getDescription());
97
+ * ```
98
+ */
99
+ getDescription(): string | undefined;
100
+ /**
101
+ * Check whether this field is readonly.
102
+ * @returns True when the field is readonly.
103
+ * @example
104
+ * ```ts
105
+ * if (field.isReadonly()) return;
106
+ * ```
107
+ */
108
+ isReadonly(): boolean;
109
+ /**
110
+ * Rename this field.
111
+ * @param name The new field name.
112
+ * @example
113
+ * ```ts
114
+ * await field.setName('Priority');
115
+ * ```
116
+ */
117
+ setName(name: string): Promise<void>;
118
+ /**
119
+ * Replace the field configuration.
120
+ *
121
+ * Config is type-specific. Keep select options, attachment restrictions,
122
+ * formula expressions, number/date formatting, and similar field metadata
123
+ * here so formulas and renderers can resolve behavior from the field.
124
+ *
125
+ * @param config The new field configuration. It replaces the current config.
126
+ * @example
127
+ * ```ts
128
+ * await formulaField.setConfig({
129
+ * formula: '=SUM(table[Amount], Pricing[Tax])',
130
+ * numberFormat: { type: 'currency', pattern: '"$"#,##0.00' },
131
+ * });
132
+ * ```
133
+ */
134
+ setConfig(config: IFieldSnapshot['config']): Promise<void>;
135
+ /**
136
+ * Set the default value for this field.
137
+ * @param defaultValue The new default value.
138
+ * @example
139
+ * ```ts
140
+ * await statusField.setDefaultValue('todo');
141
+ * ```
142
+ */
143
+ setDefaultValue(defaultValue: IFieldSnapshot['defaultValue']): Promise<void>;
144
+ /**
145
+ * Update this field.
146
+ * @param patch Partial field snapshot to merge into the field. Common
147
+ * fields are `name`, `config`, `defaultValue`, `description`, and
148
+ * `readonly`. Use `changeType()` when changing `type`.
149
+ * @example
150
+ * ```ts
151
+ * await field.update({ name: 'Score', description: 'Calculated score' });
152
+ * ```
153
+ */
154
+ update(patch: Partial<IFieldSnapshot>): Promise<void>;
155
+ /**
156
+ * Change this field type.
157
+ * @param input The target type and configuration. The `type` changes how
158
+ * existing and future cell values are interpreted, and `config` should be
159
+ * supplied for the new type.
160
+ * @example
161
+ * ```ts
162
+ * await field.changeType({ type: 'number', config: { decimalPlaces: 2 } });
163
+ * ```
164
+ */
165
+ changeType(input: Pick<IFieldSnapshot, 'type' | 'config'>): Promise<void>;
166
+ /**
167
+ * Delete this field.
168
+ * @example
169
+ * ```ts
170
+ * await field.delete();
171
+ * ```
172
+ */
173
+ delete(): Promise<void>;
174
+ /**
175
+ * Move this field relative to another field.
176
+ * @param target Target position descriptor. Pass exactly one of
177
+ * `beforeFieldId` or `afterFieldId`.
178
+ * @param target.beforeFieldId Optional field id to move this field before.
179
+ * @param target.afterFieldId Optional field id to move this field after.
180
+ * @example
181
+ * ```ts
182
+ * await field.move({ beforeFieldId: 'status' });
183
+ * await field.move({ afterFieldId: 'title' });
184
+ * ```
185
+ */
186
+ move(target: {
187
+ beforeFieldId?: string;
188
+ afterFieldId?: string;
189
+ }): Promise<void>;
190
+ private _getField;
191
+ }