@univerjs-pro/bases 1.0.0-alpha.1 → 1.0.0-alpha.3

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 (127) hide show
  1. package/README.md +8 -5
  2. package/lib/cjs/facade.js +1 -1
  3. package/lib/cjs/index.js +1 -1
  4. package/lib/cjs/locale/ar-SA.js +1 -1
  5. package/lib/cjs/locale/ca-ES.js +1 -1
  6. package/lib/cjs/locale/de-DE.js +1 -1
  7. package/lib/cjs/locale/en-US.js +1 -1
  8. package/lib/cjs/locale/es-ES.js +1 -1
  9. package/lib/cjs/locale/fa-IR.js +1 -1
  10. package/lib/cjs/locale/fr-FR.js +1 -1
  11. package/lib/cjs/locale/id-ID.js +1 -1
  12. package/lib/cjs/locale/it-IT.js +1 -1
  13. package/lib/cjs/locale/ja-JP.js +1 -1
  14. package/lib/cjs/locale/ko-KR.js +1 -1
  15. package/lib/cjs/locale/pl-PL.js +1 -1
  16. package/lib/cjs/locale/pt-BR.js +1 -1
  17. package/lib/cjs/locale/ru-RU.js +1 -1
  18. package/lib/cjs/locale/sk-SK.js +1 -1
  19. package/lib/cjs/locale/vi-VN.js +1 -1
  20. package/lib/cjs/locale/zh-CN.js +1 -1
  21. package/lib/cjs/locale/zh-HK.js +1 -1
  22. package/lib/cjs/locale/zh-TW.js +1 -1
  23. package/lib/es/facade.js +1 -1
  24. package/lib/es/index.js +1 -1
  25. package/lib/es/locale/ar-SA.js +1 -1
  26. package/lib/es/locale/ca-ES.js +1 -1
  27. package/lib/es/locale/de-DE.js +1 -1
  28. package/lib/es/locale/en-US.js +1 -1
  29. package/lib/es/locale/es-ES.js +1 -1
  30. package/lib/es/locale/fa-IR.js +1 -1
  31. package/lib/es/locale/fr-FR.js +1 -1
  32. package/lib/es/locale/id-ID.js +1 -1
  33. package/lib/es/locale/it-IT.js +1 -1
  34. package/lib/es/locale/ja-JP.js +1 -1
  35. package/lib/es/locale/ko-KR.js +1 -1
  36. package/lib/es/locale/pl-PL.js +1 -1
  37. package/lib/es/locale/pt-BR.js +1 -1
  38. package/lib/es/locale/ru-RU.js +1 -1
  39. package/lib/es/locale/sk-SK.js +1 -1
  40. package/lib/es/locale/vi-VN.js +1 -1
  41. package/lib/es/locale/zh-CN.js +1 -1
  42. package/lib/es/locale/zh-HK.js +1 -1
  43. package/lib/es/locale/zh-TW.js +1 -1
  44. package/lib/facade.js +1 -1
  45. package/lib/index.js +1 -1
  46. package/lib/locale/ar-SA.js +1 -1
  47. package/lib/locale/ca-ES.js +1 -1
  48. package/lib/locale/de-DE.js +1 -1
  49. package/lib/locale/en-US.js +1 -1
  50. package/lib/locale/es-ES.js +1 -1
  51. package/lib/locale/fa-IR.js +1 -1
  52. package/lib/locale/fr-FR.js +1 -1
  53. package/lib/locale/id-ID.js +1 -1
  54. package/lib/locale/it-IT.js +1 -1
  55. package/lib/locale/ja-JP.js +1 -1
  56. package/lib/locale/ko-KR.js +1 -1
  57. package/lib/locale/pl-PL.js +1 -1
  58. package/lib/locale/pt-BR.js +1 -1
  59. package/lib/locale/ru-RU.js +1 -1
  60. package/lib/locale/sk-SK.js +1 -1
  61. package/lib/locale/vi-VN.js +1 -1
  62. package/lib/locale/zh-CN.js +1 -1
  63. package/lib/locale/zh-HK.js +1 -1
  64. package/lib/locale/zh-TW.js +1 -1
  65. package/lib/types/commands/commands/set-base-view-filter.command.d.ts +2 -2
  66. package/lib/types/commands/commands/set-base-view-group.command.d.ts +2 -2
  67. package/lib/types/commands/commands/set-base-view-sort.command.d.ts +2 -2
  68. package/lib/types/commands/utils/base-validation.d.ts +6 -0
  69. package/lib/types/config/config.d.ts +11 -0
  70. package/lib/types/controllers/base-active-dirty.controller.d.ts +5 -6
  71. package/lib/types/controllers/base-formula-calculation.controller.d.ts +8 -14
  72. package/lib/types/embed-host-anchor.d.ts +46 -0
  73. package/lib/types/facade/f-base.d.ts +126 -577
  74. package/lib/types/facade/f-enum.d.ts +117 -89
  75. package/lib/types/facade/f-event.d.ts +255 -132
  76. package/lib/types/facade/f-field.d.ts +137 -313
  77. package/lib/types/facade/f-range.d.ts +86 -326
  78. package/lib/types/facade/f-record.d.ts +93 -216
  79. package/lib/types/facade/f-table.d.ts +473 -1317
  80. package/lib/types/facade/f-types.d.ts +1 -0
  81. package/lib/types/facade/f-univer.d.ts +27 -154
  82. package/lib/types/facade/f-view.d.ts +207 -484
  83. package/lib/types/facade/field-key.d.ts +6 -6
  84. package/lib/types/facade/index.d.ts +11 -14
  85. package/lib/types/fields/field-core-plugin.d.ts +9 -8
  86. package/lib/types/index.d.ts +17 -47
  87. package/lib/types/models/base-cell-data.d.ts +6 -6
  88. package/lib/types/models/default-table.d.ts +13 -0
  89. package/lib/types/ot/json1-adapter.d.ts +3 -3
  90. package/lib/types/ot/json1-invalidation.d.ts +2 -2
  91. package/lib/types/ot/json1-op-applier.d.ts +2 -2
  92. package/lib/types/ot/json1-op-factory.d.ts +9 -8
  93. package/lib/types/plugin.d.ts +6 -4
  94. package/lib/types/search/base-search.d.ts +4 -3
  95. package/lib/types/services/base-active-dirty.service.d.ts +2 -2
  96. package/lib/types/services/base-command.service.d.ts +16 -16
  97. package/lib/types/services/base-compression.service.d.ts +3 -3
  98. package/lib/types/services/base-field-registry.service.d.ts +5 -5
  99. package/lib/types/services/base-formula.service.d.ts +11 -20
  100. package/lib/types/services/base-view-registry.service.d.ts +3 -3
  101. package/lib/types/views/view-core-plugin.d.ts +4 -3
  102. package/lib/umd/facade.js +1 -1
  103. package/lib/umd/index.js +1 -1
  104. package/lib/umd/locale/ar-SA.js +1 -1
  105. package/lib/umd/locale/ca-ES.js +1 -1
  106. package/lib/umd/locale/de-DE.js +1 -1
  107. package/lib/umd/locale/en-US.js +1 -1
  108. package/lib/umd/locale/es-ES.js +1 -1
  109. package/lib/umd/locale/fa-IR.js +1 -1
  110. package/lib/umd/locale/fr-FR.js +1 -1
  111. package/lib/umd/locale/id-ID.js +1 -1
  112. package/lib/umd/locale/it-IT.js +1 -1
  113. package/lib/umd/locale/ja-JP.js +1 -1
  114. package/lib/umd/locale/ko-KR.js +1 -1
  115. package/lib/umd/locale/pl-PL.js +1 -1
  116. package/lib/umd/locale/pt-BR.js +1 -1
  117. package/lib/umd/locale/ru-RU.js +1 -1
  118. package/lib/umd/locale/sk-SK.js +1 -1
  119. package/lib/umd/locale/vi-VN.js +1 -1
  120. package/lib/umd/locale/zh-CN.js +1 -1
  121. package/lib/umd/locale/zh-HK.js +1 -1
  122. package/lib/umd/locale/zh-TW.js +1 -1
  123. package/package.json +7 -8
  124. package/lib/types/controllers/base-remote-formula.controller.d.ts +0 -13
  125. package/lib/types/facade/f-error.d.ts +0 -30
  126. package/lib/types/facade/f-permission.d.ts +0 -749
  127. package/lib/types/facade/transaction.d.ts +0 -19
@@ -1,4 +1,6 @@
1
- import type { BaseDataModel, ICommandService, IFieldSnapshot } from '@univerjs/core';
1
+ import type { BaseFieldType, FieldConfig, IFieldSnapshot, Injector } from '@univerjs/core';
2
+ import type { FBase } from './f-base';
3
+ import type { FBaseTable } from './f-table';
2
4
  /**
3
5
  * Facade API object bound to a Base field.
4
6
  *
@@ -9,263 +11,143 @@ import type { BaseDataModel, ICommandService, IFieldSnapshot } from '@univerjs/c
9
11
  *
10
12
  * @example Update field metadata
11
13
  * ```ts
12
- * const field = table.getFieldByName('Status');
14
+ * const fBase = univerAPI.getActiveBase();
15
+ * const fBaseTable = fBase.getTableById('table-1');
16
+ * const field = fBaseTable.getFieldByName('Name');
17
+ *
13
18
  * if (field) {
14
19
  * field.setName('Stage');
15
- * field.setConfig({
16
- * options: [{ id: 'done', name: 'Done', color: 'green' }],
17
- * });
20
+ * field.changeType(
21
+ * univerAPI.Enum.BaseFieldType.SingleSelect,
22
+ * {
23
+ * options: [
24
+ * { id: 'todo', name: 'To Do', color: 'blue' },
25
+ * { id: 'inProgress', name: 'In Progress', color: 'yellow' },
26
+ * { id: 'done', name: 'Done', color: 'green' },
27
+ * ]
28
+ * }
29
+ * );
30
+ * field.setDefaultValue('todo');
18
31
  * field.update({ description: 'Workflow stage from server auth.' });
19
32
  * }
20
33
  * ```
21
34
  */
22
- export declare class FField {
35
+ export declare class FBaseTableField {
23
36
  private readonly _base;
24
- private readonly _tableId;
37
+ private readonly _table;
25
38
  private readonly _fieldId;
26
- private readonly _commandService;
27
- constructor(_base: BaseDataModel, _tableId: string, _fieldId: string, _commandService: ICommandService);
39
+ private readonly _inject;
40
+ constructor(_base: FBase, _table: FBaseTable, _fieldId: string, _inject: Injector);
28
41
  /**
29
42
  * Get the field id.
30
- * @returns The field id.
43
+ * @returns {string} The field id.
31
44
  * @example
32
45
  * ```ts
33
- * console.log(field.getId());
34
- * ```
35
- *
36
- * @example Browser console
37
- * ```ts
38
- * console.log((() => {
39
- * const unitId = `facade_example_${Date.now()}`;
40
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
41
- * try {
42
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
43
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
44
- * return field.getId();
45
- * } finally {
46
- * univerAPI.disposeUnit(unitId);
47
- * }
48
- * })());
46
+ * const fBase = univerAPI.getActiveBase();
47
+ * const fBaseTable = fBase.getTableById('table-1');
48
+ * const fields = fBaseTable.getFields();
49
+ * console.log(fields[0]?.getId());
49
50
  * ```
50
51
  */
51
52
  getId(): string;
52
53
  /**
53
54
  * Get the field snapshot.
54
- * @returns The field snapshot.
55
+ * @returns {IFieldSnapshot} The field snapshot.
55
56
  * @example
56
57
  * ```ts
57
- * const rawField = field.getField();
58
- * ```
59
- *
60
- * @example Browser console
61
- * ```ts
62
- * console.log((() => {
63
- * const unitId = `facade_example_${Date.now()}`;
64
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
65
- * try {
66
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
67
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
68
- * return field.getField();
69
- * } finally {
70
- * univerAPI.disposeUnit(unitId);
71
- * }
72
- * })());
58
+ * const fBase = univerAPI.getActiveBase();
59
+ * const fBaseTable = fBase.getTableById('table-1');
60
+ * const fields = fBaseTable.getFields();
61
+ * console.log(fields[0]?.getField());
73
62
  * ```
74
63
  */
75
64
  getField(): IFieldSnapshot;
76
- /**
77
- * Get the field snapshot.
78
- * @returns The field snapshot.
79
- * @example
80
- * ```ts
81
- * const snapshot = field.getSnapshot();
82
- * ```
83
- *
84
- * @example Browser console
85
- * ```ts
86
- * console.log((() => {
87
- * const unitId = `facade_example_${Date.now()}`;
88
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
89
- * try {
90
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
91
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
92
- * return field.getSnapshot();
93
- * } finally {
94
- * univerAPI.disposeUnit(unitId);
95
- * }
96
- * })());
97
- * ```
98
- */
99
- getSnapshot(): IFieldSnapshot;
100
65
  /**
101
66
  * Get the field name.
102
- * @returns The field name.
67
+ * @returns {string} The field name.
103
68
  * @example
104
69
  * ```ts
105
- * console.log(field.getName());
106
- * ```
107
- *
108
- * @example Browser console
109
- * ```ts
110
- * console.log((() => {
111
- * const unitId = `facade_example_${Date.now()}`;
112
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
113
- * try {
114
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
115
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
116
- * return field.getName();
117
- * } finally {
118
- * univerAPI.disposeUnit(unitId);
119
- * }
120
- * })());
70
+ * const fBase = univerAPI.getActiveBase();
71
+ * const fBaseTable = fBase.getTableById('table-1');
72
+ * const fields = fBaseTable.getFields();
73
+ * console.log(fields[0]?.getName());
121
74
  * ```
122
75
  */
123
76
  getName(): string;
124
77
  /**
125
78
  * Get the field type.
126
- * @returns The field type.
79
+ * @returns {BaseFieldType} The field type.
127
80
  * @example
128
81
  * ```ts
129
- * console.log(field.getType());
130
- * ```
131
- *
132
- * @example Browser console
133
- * ```ts
134
- * console.log((() => {
135
- * const unitId = `facade_example_${Date.now()}`;
136
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
137
- * try {
138
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
139
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
140
- * return field.getType();
141
- * } finally {
142
- * univerAPI.disposeUnit(unitId);
143
- * }
144
- * })());
82
+ * const fBase = univerAPI.getActiveBase();
83
+ * const fBaseTable = fBase.getTableById('table-1');
84
+ * const fields = fBaseTable.getFields();
85
+ * console.log(fields[0]?.getType());
145
86
  * ```
146
87
  */
147
- getType(): IFieldSnapshot['type'];
88
+ getType(): BaseFieldType;
148
89
  /**
149
90
  * Get the field configuration.
150
- * @returns The field configuration.
91
+ * @returns {FieldConfig} The field configuration.
151
92
  * @example
152
93
  * ```ts
153
- * const config = field.getConfig();
154
- * ```
155
- *
156
- * @example Browser console
157
- * ```ts
158
- * console.log((() => {
159
- * const unitId = `facade_example_${Date.now()}`;
160
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
161
- * try {
162
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
163
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
164
- * return field.getConfig();
165
- * } finally {
166
- * univerAPI.disposeUnit(unitId);
167
- * }
168
- * })());
94
+ * const fBase = univerAPI.getActiveBase();
95
+ * const fBaseTable = fBase.getTableById('table-1');
96
+ * const fields = fBaseTable.getFields();
97
+ * console.log(fields[0]?.getConfig());
169
98
  * ```
170
99
  */
171
- getConfig(): IFieldSnapshot['config'];
100
+ getConfig(): FieldConfig;
172
101
  /**
173
102
  * Get the default value configured for this field.
174
- * @returns The default value.
103
+ * @returns {IFieldSnapshot['defaultValue']} The default value for this field, if any.
175
104
  * @example
176
105
  * ```ts
177
- * const defaultValue = field.getDefaultValue();
178
- * ```
179
- *
180
- * @example Browser console
181
- * ```ts
182
- * console.log((() => {
183
- * const unitId = `facade_example_${Date.now()}`;
184
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
185
- * try {
186
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
187
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
188
- * return field.getDefaultValue();
189
- * } finally {
190
- * univerAPI.disposeUnit(unitId);
191
- * }
192
- * })());
106
+ * const fBase = univerAPI.getActiveBase();
107
+ * const fBaseTable = fBase.getTableById('table-1');
108
+ * const fields = fBaseTable.getFields();
109
+ * console.log(fields[0]?.getDefaultValue());
193
110
  * ```
194
111
  */
195
112
  getDefaultValue(): IFieldSnapshot['defaultValue'];
196
113
  /**
197
114
  * Get the field description.
198
- * @returns The field description, if any.
115
+ * @returns {string | undefined} The field description, if any.
199
116
  * @example
200
117
  * ```ts
201
- * console.log(field.getDescription());
202
- * ```
203
- *
204
- * @example Browser console
205
- * ```ts
206
- * console.log((() => {
207
- * const unitId = `facade_example_${Date.now()}`;
208
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
209
- * try {
210
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
211
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
212
- * return field.getDescription();
213
- * } finally {
214
- * univerAPI.disposeUnit(unitId);
215
- * }
216
- * })());
118
+ * const fBase = univerAPI.getActiveBase();
119
+ * const fBaseTable = fBase.getTableById('table-1');
120
+ * const fields = fBaseTable.getFields();
121
+ * console.log(fields[0]?.getDescription());
217
122
  * ```
218
123
  */
219
124
  getDescription(): string | undefined;
220
125
  /**
221
126
  * Check whether this field is readonly.
222
- * @returns True when the field is readonly.
127
+ * @returns {boolean} True if the field is readonly, false otherwise.
223
128
  * @example
224
129
  * ```ts
225
- * if (field.isReadonly()) return;
226
- * ```
227
- *
228
- * @example Browser console
229
- * ```ts
230
- * console.log((() => {
231
- * const unitId = `facade_example_${Date.now()}`;
232
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
233
- * try {
234
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
235
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
236
- * return field.isReadonly();
237
- * } finally {
238
- * univerAPI.disposeUnit(unitId);
239
- * }
240
- * })());
130
+ * const fBase = univerAPI.getActiveBase();
131
+ * const fBaseTable = fBase.getTableById('table-1');
132
+ * const fields = fBaseTable.getFields();
133
+ * console.log(fields[0]?.isReadonly());
241
134
  * ```
242
135
  */
243
136
  isReadonly(): boolean;
244
137
  /**
245
138
  * Rename this field.
246
- * @param name The new field name.
139
+ * @param {string} name The new field name.
140
+ * @returns {boolean} True if the rename was successful, false otherwise.
247
141
  * @example
248
142
  * ```ts
249
- * field.setName('Priority');
250
- * ```
251
- *
252
- * @example Browser console
253
- * ```ts
254
- * console.log((() => {
255
- * const unitId = `facade_example_${Date.now()}`;
256
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
257
- * try {
258
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
259
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
260
- * field.setName('Renamed Status');
261
- * return field.getName();
262
- * } finally {
263
- * univerAPI.disposeUnit(unitId);
264
- * }
265
- * })());
143
+ * const fBase = univerAPI.getActiveBase();
144
+ * const fBaseTable = fBase.getTableById('table-1');
145
+ * const field = fBaseTable.getFieldByName('Status');
146
+ * const success = field.setName('Priority');
147
+ * console.log(success ? 'Field renamed' : 'Failed to rename field');
266
148
  * ```
267
149
  */
268
- setName(name: string): void;
150
+ setName(name: string): boolean;
269
151
  /**
270
152
  * Replace the field configuration.
271
153
  *
@@ -273,168 +155,110 @@ export declare class FField {
273
155
  * formula expressions, number/date formatting, and similar field metadata
274
156
  * here so formulas and renderers can resolve behavior from the field.
275
157
  *
276
- * @param config The new field configuration. It replaces the current config.
158
+ * @param {FieldConfig} config The new field configuration.
159
+ * @returns {boolean} True if the config update was successful, false otherwise.
277
160
  * @example
278
161
  * ```ts
279
- * formulaField.setConfig({
162
+ * const fBase = univerAPI.getActiveBase();
163
+ * const fBaseTable = fBase.getTableById('table-1');
164
+ * const field = fBaseTable.getFieldByName('Total');
165
+ * const success = field.setConfig({
280
166
  * formula: '=SUM(table[Amount], Pricing[Tax])',
281
- * numberFormat: { type: 'currency', pattern: '"$"#,##0.00' },
167
+ * numberFormat: {
168
+ * type: 'currency',
169
+ * pattern: '"$"#,##0.00'
170
+ * },
282
171
  * });
283
- * ```
284
- *
285
- * @example Browser console
286
- * ```ts
287
- * console.log((() => {
288
- * const unitId = `facade_example_${Date.now()}`;
289
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
290
- * try {
291
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
292
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
293
- * field.setConfig({ options: [{ id: 'todo', name: 'Todo' }, { id: 'blocked', name: 'Blocked' }] });
294
- * return field.getConfig();
295
- * } finally {
296
- * univerAPI.disposeUnit(unitId);
297
- * }
298
- * })());
172
+ * console.log(success ? 'Field config updated' : 'Failed to update field config');
299
173
  * ```
300
174
  */
301
- setConfig(config: IFieldSnapshot['config']): void;
175
+ setConfig(config: FieldConfig): boolean;
302
176
  /**
303
177
  * Set the default value for this field.
304
- * @param defaultValue The new default value.
178
+ * @param {IFieldSnapshot['defaultValue']} defaultValue The new default value.
179
+ * @returns {boolean} True if the default value update was successful, false otherwise.
305
180
  * @example
306
181
  * ```ts
307
- * statusField.setDefaultValue('todo');
308
- * ```
309
- *
310
- * @example Browser console
311
- * ```ts
312
- * console.log((() => {
313
- * const unitId = `facade_example_${Date.now()}`;
314
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
315
- * try {
316
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
317
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
318
- * field.setDefaultValue('done');
319
- * return field.getDefaultValue();
320
- * } finally {
321
- * univerAPI.disposeUnit(unitId);
322
- * }
323
- * })());
182
+ * const fBase = univerAPI.getActiveBase();
183
+ * const fBaseTable = fBase.getTableById('table-1');
184
+ * const field = fBaseTable.getFieldByName('Status');
185
+ * const success = field.setDefaultValue('todo');
186
+ * console.log(success ? 'Default value set' : 'Failed to set default value');
324
187
  * ```
325
188
  */
326
- setDefaultValue(defaultValue: IFieldSnapshot['defaultValue']): void;
189
+ setDefaultValue(defaultValue: IFieldSnapshot['defaultValue']): boolean;
327
190
  /**
328
191
  * Update this field.
329
- * @param patch Partial field snapshot to merge into the field. Common
330
- * fields are `name`, `config`, `defaultValue`, `description`, and
331
- * `readonly`. Use `changeType()` when changing `type`.
192
+ * @param {Partial<IFieldSnapshot>} patch The field snapshot patch to apply.
193
+ * @returns {boolean} True if the update was successful, false otherwise.
332
194
  * @example
333
195
  * ```ts
334
- * field.update({ name: 'Score', description: 'Calculated score' });
335
- * ```
336
- *
337
- * @example Browser console
338
- * ```ts
339
- * console.log((() => {
340
- * const unitId = `facade_example_${Date.now()}`;
341
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
342
- * try {
343
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
344
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
345
- * field.update({ description: 'Updated from facade example' });
346
- * return field.getDescription();
347
- * } finally {
348
- * univerAPI.disposeUnit(unitId);
349
- * }
350
- * })());
196
+ * const fBase = univerAPI.getActiveBase();
197
+ * const fBaseTable = fBase.getTableById('table-1');
198
+ * const field = fBaseTable.getFieldByName('Status');
199
+ * const success = field.update({
200
+ * name: 'Stage',
201
+ * description: 'Workflow stage from server auth.'
202
+ * });
203
+ * console.log(success ? 'Field updated' : 'Failed to update field');
351
204
  * ```
352
205
  */
353
- update(patch: Partial<IFieldSnapshot>): void;
206
+ update(patch: Partial<IFieldSnapshot>): boolean;
354
207
  /**
355
208
  * Change this field type.
356
- * @param input The target type and configuration. The `type` changes how
357
- * existing and future cell values are interpreted, and `config` should be
358
- * supplied for the new type.
209
+ * @param {BaseFieldType} type The new field type.
210
+ * @param {FieldConfig} config The new field configuration.
211
+ * @returns {boolean} True if the type change was successful, false otherwise.
359
212
  * @example
360
213
  * ```ts
361
- * field.changeType({ type: 'number', config: { decimalPlaces: 2 } });
362
- * ```
363
- *
364
- * @example Browser console
365
- * ```ts
366
- * console.log((() => {
367
- * const unitId = `facade_example_${Date.now()}`;
368
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
369
- * try {
370
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
371
- * const field = table.addField({ id: `${unitId}_score`, name: 'Score', type: 'text', config: {} });
372
- * field.changeType({ type: 'number', config: { decimalPlaces: 0 } });
373
- * return field.getType();
374
- * } finally {
375
- * univerAPI.disposeUnit(unitId);
214
+ * const fBase = univerAPI.getActiveBase();
215
+ * const fBaseTable = fBase.getTableById('table-1');
216
+ * const field = fBaseTable.getFieldByName('Status');
217
+ * const success = field.changeType(
218
+ * univerAPI.Enum.BaseFieldType.Number,
219
+ * {
220
+ * decimalPlaces: 2
376
221
  * }
377
- * })());
222
+ * );
223
+ * console.log(success ? 'Field type changed' : 'Failed to change field type');
378
224
  * ```
379
225
  */
380
- changeType(input: Pick<IFieldSnapshot, 'type' | 'config'>): void;
226
+ changeType(type: BaseFieldType, config?: FieldConfig): boolean;
381
227
  /**
382
228
  * Delete this field.
383
- * @example
384
- * ```ts
385
- * field.delete();
386
- * ```
387
229
  *
388
- * @example Browser console
230
+ * The table's primary field cannot be deleted. Calling this method on the
231
+ * primary field leaves the table unchanged and returns `false`.
232
+ *
233
+ * @returns {boolean} True if the deletion was successful, false if the field is the primary field or the deletion otherwise failed.
234
+ * @example
389
235
  * ```ts
390
- * console.log((() => {
391
- * const unitId = `facade_example_${Date.now()}`;
392
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
393
- * try {
394
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
395
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
396
- * const fieldId = field.getId();
397
- * field.delete();
398
- * return table.getField(fieldId);
399
- * } finally {
400
- * univerAPI.disposeUnit(unitId);
401
- * }
402
- * })());
236
+ * const fBase = univerAPI.getActiveBase();
237
+ * const fBaseTable = fBase.getTableById('table-1');
238
+ * const field = fBaseTable.getFieldByName('Status');
239
+ * const success = field.delete();
240
+ * console.log(success ? 'Field deleted' : 'Failed to delete field');
403
241
  * ```
404
242
  */
405
- delete(): void;
243
+ delete(): boolean;
406
244
  /**
407
245
  * Move this field relative to another field.
408
- * @param target Target position descriptor. Pass exactly one of
409
- * `beforeFieldId` or `afterFieldId`.
410
- * @param target.beforeFieldId Optional field id to move this field before.
411
- * @param target.afterFieldId Optional field id to move this field after.
246
+ * @param {object} target The target field to move before or after.
247
+ * @param {string} [target.beforeFieldId] The field id to move this field before.
248
+ * @param {string} [target.afterFieldId] The field id to move this field after.
249
+ * @returns {boolean} True if the move was successful, false otherwise.
412
250
  * @example
413
251
  * ```ts
414
- * field.move({ beforeFieldId: 'status' });
415
- * field.move({ afterFieldId: 'title' });
416
- * ```
417
- *
418
- * @example Browser console
419
- * ```ts
420
- * console.log((() => {
421
- * const unitId = `facade_example_${Date.now()}`;
422
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
423
- * try {
424
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
425
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
426
- * const next = table.addField({ id: `${unitId}_next`, name: 'Next', type: 'text', config: {} });
427
- * next.move({ afterFieldId: field.getId() });
428
- * return table.getFields().map((field) => field.getName());
429
- * } finally {
430
- * univerAPI.disposeUnit(unitId);
431
- * }
432
- * })());
252
+ * const fBase = univerAPI.getActiveBase();
253
+ * const fBaseTable = fBase.getTableById('table-1');
254
+ * const field = fBaseTable.getFieldByName('Status');
255
+ * const success = field.move({ afterFieldId: 'Priority' });
256
+ * console.log(success ? 'Field moved' : 'Failed to move field');
433
257
  * ```
434
258
  */
435
259
  move(target: {
436
260
  beforeFieldId?: string;
437
261
  afterFieldId?: string;
438
- }): void;
262
+ }): boolean;
439
263
  private _getField;
440
264
  }