@univerjs-pro/bases 1.0.0-alpha.2 → 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.
- package/README.md +8 -5
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/locale/ar-SA.js +1 -1
- package/lib/cjs/locale/ca-ES.js +1 -1
- package/lib/cjs/locale/de-DE.js +1 -1
- package/lib/cjs/locale/en-US.js +1 -1
- package/lib/cjs/locale/es-ES.js +1 -1
- package/lib/cjs/locale/fa-IR.js +1 -1
- package/lib/cjs/locale/fr-FR.js +1 -1
- package/lib/cjs/locale/id-ID.js +1 -1
- package/lib/cjs/locale/it-IT.js +1 -1
- package/lib/cjs/locale/ja-JP.js +1 -1
- package/lib/cjs/locale/ko-KR.js +1 -1
- package/lib/cjs/locale/pl-PL.js +1 -1
- package/lib/cjs/locale/pt-BR.js +1 -1
- package/lib/cjs/locale/ru-RU.js +1 -1
- package/lib/cjs/locale/sk-SK.js +1 -1
- package/lib/cjs/locale/vi-VN.js +1 -1
- package/lib/cjs/locale/zh-CN.js +1 -1
- package/lib/cjs/locale/zh-HK.js +1 -1
- package/lib/cjs/locale/zh-TW.js +1 -1
- package/lib/es/facade.js +1 -1
- package/lib/es/index.js +1 -1
- package/lib/es/locale/ar-SA.js +1 -1
- package/lib/es/locale/ca-ES.js +1 -1
- package/lib/es/locale/de-DE.js +1 -1
- package/lib/es/locale/en-US.js +1 -1
- package/lib/es/locale/es-ES.js +1 -1
- package/lib/es/locale/fa-IR.js +1 -1
- package/lib/es/locale/fr-FR.js +1 -1
- package/lib/es/locale/id-ID.js +1 -1
- package/lib/es/locale/it-IT.js +1 -1
- package/lib/es/locale/ja-JP.js +1 -1
- package/lib/es/locale/ko-KR.js +1 -1
- package/lib/es/locale/pl-PL.js +1 -1
- package/lib/es/locale/pt-BR.js +1 -1
- package/lib/es/locale/ru-RU.js +1 -1
- package/lib/es/locale/sk-SK.js +1 -1
- package/lib/es/locale/vi-VN.js +1 -1
- package/lib/es/locale/zh-CN.js +1 -1
- package/lib/es/locale/zh-HK.js +1 -1
- package/lib/es/locale/zh-TW.js +1 -1
- package/lib/facade.js +1 -1
- package/lib/index.js +1 -1
- package/lib/locale/ar-SA.js +1 -1
- package/lib/locale/ca-ES.js +1 -1
- package/lib/locale/de-DE.js +1 -1
- package/lib/locale/en-US.js +1 -1
- package/lib/locale/es-ES.js +1 -1
- package/lib/locale/fa-IR.js +1 -1
- package/lib/locale/fr-FR.js +1 -1
- package/lib/locale/id-ID.js +1 -1
- package/lib/locale/it-IT.js +1 -1
- package/lib/locale/ja-JP.js +1 -1
- package/lib/locale/ko-KR.js +1 -1
- package/lib/locale/pl-PL.js +1 -1
- package/lib/locale/pt-BR.js +1 -1
- package/lib/locale/ru-RU.js +1 -1
- package/lib/locale/sk-SK.js +1 -1
- package/lib/locale/vi-VN.js +1 -1
- package/lib/locale/zh-CN.js +1 -1
- package/lib/locale/zh-HK.js +1 -1
- package/lib/locale/zh-TW.js +1 -1
- package/lib/types/commands/commands/set-base-view-filter.command.d.ts +2 -2
- package/lib/types/commands/commands/set-base-view-group.command.d.ts +2 -2
- package/lib/types/commands/commands/set-base-view-sort.command.d.ts +2 -2
- package/lib/types/commands/utils/base-validation.d.ts +6 -0
- package/lib/types/config/config.d.ts +1 -0
- package/lib/types/controllers/base-active-dirty.controller.d.ts +5 -6
- package/lib/types/controllers/base-formula-calculation.controller.d.ts +8 -14
- package/lib/types/embed-host-anchor.d.ts +46 -0
- package/lib/types/facade/f-base.d.ts +126 -577
- package/lib/types/facade/f-enum.d.ts +117 -89
- package/lib/types/facade/f-event.d.ts +255 -132
- package/lib/types/facade/f-field.d.ts +137 -313
- package/lib/types/facade/f-range.d.ts +86 -326
- package/lib/types/facade/f-record.d.ts +93 -216
- package/lib/types/facade/f-table.d.ts +473 -1317
- package/lib/types/facade/f-types.d.ts +1 -0
- package/lib/types/facade/f-univer.d.ts +27 -154
- package/lib/types/facade/f-view.d.ts +207 -484
- package/lib/types/facade/field-key.d.ts +6 -6
- package/lib/types/facade/index.d.ts +10 -20
- package/lib/types/fields/field-core-plugin.d.ts +9 -8
- package/lib/types/index.d.ts +10 -8
- package/lib/types/models/base-cell-data.d.ts +6 -6
- package/lib/types/models/default-table.d.ts +13 -0
- package/lib/types/ot/json1-adapter.d.ts +3 -3
- package/lib/types/ot/json1-invalidation.d.ts +2 -2
- package/lib/types/ot/json1-op-applier.d.ts +2 -2
- package/lib/types/ot/json1-op-factory.d.ts +9 -8
- package/lib/types/plugin.d.ts +0 -1
- package/lib/types/search/base-search.d.ts +4 -3
- package/lib/types/services/base-active-dirty.service.d.ts +2 -2
- package/lib/types/services/base-command.service.d.ts +16 -16
- package/lib/types/services/base-compression.service.d.ts +3 -3
- package/lib/types/services/base-field-registry.service.d.ts +5 -5
- package/lib/types/services/base-formula.service.d.ts +11 -20
- package/lib/types/services/base-view-registry.service.d.ts +3 -3
- package/lib/types/views/view-core-plugin.d.ts +4 -3
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/lib/umd/locale/ar-SA.js +1 -1
- package/lib/umd/locale/ca-ES.js +1 -1
- package/lib/umd/locale/de-DE.js +1 -1
- package/lib/umd/locale/en-US.js +1 -1
- package/lib/umd/locale/es-ES.js +1 -1
- package/lib/umd/locale/fa-IR.js +1 -1
- package/lib/umd/locale/fr-FR.js +1 -1
- package/lib/umd/locale/id-ID.js +1 -1
- package/lib/umd/locale/it-IT.js +1 -1
- package/lib/umd/locale/ja-JP.js +1 -1
- package/lib/umd/locale/ko-KR.js +1 -1
- package/lib/umd/locale/pl-PL.js +1 -1
- package/lib/umd/locale/pt-BR.js +1 -1
- package/lib/umd/locale/ru-RU.js +1 -1
- package/lib/umd/locale/sk-SK.js +1 -1
- package/lib/umd/locale/vi-VN.js +1 -1
- package/lib/umd/locale/zh-CN.js +1 -1
- package/lib/umd/locale/zh-HK.js +1 -1
- package/lib/umd/locale/zh-TW.js +1 -1
- package/package.json +7 -8
- package/lib/types/controllers/base-remote-formula.controller.d.ts +0 -13
- package/lib/types/facade/f-error.d.ts +0 -30
- package/lib/types/facade/f-permission.d.ts +0 -749
- package/lib/types/facade/transaction.d.ts +0 -19
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { BaseCellValue,
|
|
2
|
-
import type {
|
|
1
|
+
import type { BaseCellValue, FieldId, Injector, IRecordSnapshot } from '@univerjs/core';
|
|
2
|
+
import type { FBase } from './f-base';
|
|
3
|
+
import type { FBaseTable } from './f-table';
|
|
4
|
+
import { BaseFieldKeyEnum } from './field-key';
|
|
3
5
|
/**
|
|
4
6
|
* Facade API object bound to a Base record.
|
|
5
7
|
*
|
|
@@ -9,147 +11,72 @@ import type { IBaseFieldKeyOptions } from './field-key';
|
|
|
9
11
|
*
|
|
10
12
|
* @example Read, update, and duplicate a record
|
|
11
13
|
* ```ts
|
|
12
|
-
* const
|
|
14
|
+
* const fBase = univerAPI.getActiveBase();
|
|
15
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
16
|
+
*
|
|
17
|
+
* const record = fBaseTable.getRecordById('task-1');
|
|
13
18
|
* if (record) {
|
|
14
19
|
* record.setValue('status', 'done');
|
|
15
20
|
* record.setValues({ progress: 100 });
|
|
16
21
|
* const copy = record.duplicate({
|
|
17
|
-
* id: 'task-1-copy',
|
|
18
22
|
* values: { ...record.getValues(), status: 'todo' },
|
|
19
23
|
* });
|
|
20
24
|
* console.log(copy.getId());
|
|
21
25
|
* }
|
|
22
26
|
* ```
|
|
23
27
|
*/
|
|
24
|
-
export declare class
|
|
28
|
+
export declare class FBaseTableRecord {
|
|
25
29
|
private readonly _base;
|
|
26
|
-
private readonly
|
|
30
|
+
private readonly _table;
|
|
27
31
|
private readonly _recordId;
|
|
28
|
-
private readonly
|
|
29
|
-
constructor(_base:
|
|
32
|
+
private readonly _inject;
|
|
33
|
+
constructor(_base: FBase, _table: FBaseTable, _recordId: string, _inject: Injector);
|
|
30
34
|
/**
|
|
31
35
|
* Get the record id.
|
|
32
|
-
* @returns The record id.
|
|
36
|
+
* @returns {string} The record id.
|
|
33
37
|
* @example
|
|
34
38
|
* ```ts
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* ```ts
|
|
40
|
-
* console.log((() => {
|
|
41
|
-
* const unitId = `facade_example_${Date.now()}`;
|
|
42
|
-
* const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
|
|
43
|
-
* try {
|
|
44
|
-
* const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
|
|
45
|
-
* const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
|
|
46
|
-
* const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
|
|
47
|
-
* return record.getId();
|
|
48
|
-
* } finally {
|
|
49
|
-
* univerAPI.disposeUnit(unitId);
|
|
50
|
-
* }
|
|
51
|
-
* })());
|
|
39
|
+
* const fBase = univerAPI.getActiveBase();
|
|
40
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
41
|
+
* const records = fBaseTable.getRecords();
|
|
42
|
+
* console.log(records[0]?.getId());
|
|
52
43
|
* ```
|
|
53
44
|
*/
|
|
54
45
|
getId(): string;
|
|
55
46
|
/**
|
|
56
47
|
* Get the record snapshot.
|
|
57
|
-
* @returns The record snapshot.
|
|
48
|
+
* @returns {IRecordSnapshot} The record snapshot.
|
|
58
49
|
* @example
|
|
59
50
|
* ```ts
|
|
60
|
-
* const
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* ```ts
|
|
65
|
-
* console.log((() => {
|
|
66
|
-
* const unitId = `facade_example_${Date.now()}`;
|
|
67
|
-
* const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
|
|
68
|
-
* try {
|
|
69
|
-
* const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
|
|
70
|
-
* const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
|
|
71
|
-
* const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
|
|
72
|
-
* return record.getRecord();
|
|
73
|
-
* } finally {
|
|
74
|
-
* univerAPI.disposeUnit(unitId);
|
|
75
|
-
* }
|
|
76
|
-
* })());
|
|
51
|
+
* const fBase = univerAPI.getActiveBase();
|
|
52
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
53
|
+
* const records = fBaseTable.getRecords();
|
|
54
|
+
* console.log(records[0]?.getRecord());
|
|
77
55
|
* ```
|
|
78
56
|
*/
|
|
79
57
|
getRecord(): IRecordSnapshot;
|
|
80
|
-
/**
|
|
81
|
-
* Get the record snapshot.
|
|
82
|
-
* @returns The record snapshot.
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* const snapshot = record.getSnapshot();
|
|
86
|
-
* ```
|
|
87
|
-
*
|
|
88
|
-
* @example Browser console
|
|
89
|
-
* ```ts
|
|
90
|
-
* console.log((() => {
|
|
91
|
-
* const unitId = `facade_example_${Date.now()}`;
|
|
92
|
-
* const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
|
|
93
|
-
* try {
|
|
94
|
-
* const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
|
|
95
|
-
* const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
|
|
96
|
-
* const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
|
|
97
|
-
* return record.getSnapshot();
|
|
98
|
-
* } finally {
|
|
99
|
-
* univerAPI.disposeUnit(unitId);
|
|
100
|
-
* }
|
|
101
|
-
* })());
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
getSnapshot(): IRecordSnapshot;
|
|
105
58
|
/**
|
|
106
59
|
* Get a field value from this record.
|
|
107
|
-
* @param fieldId The field id.
|
|
108
|
-
* @returns The
|
|
60
|
+
* @param {FieldId} fieldId The field id.
|
|
61
|
+
* @returns {BaseCellValue} The cell value, or `null` if the field is empty.
|
|
109
62
|
* @example
|
|
110
63
|
* ```ts
|
|
111
|
-
* const
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* ```ts
|
|
116
|
-
* console.log((() => {
|
|
117
|
-
* const unitId = `facade_example_${Date.now()}`;
|
|
118
|
-
* const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
|
|
119
|
-
* try {
|
|
120
|
-
* const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
|
|
121
|
-
* const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
|
|
122
|
-
* const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
|
|
123
|
-
* return record.getValue(field.getId());
|
|
124
|
-
* } finally {
|
|
125
|
-
* univerAPI.disposeUnit(unitId);
|
|
126
|
-
* }
|
|
127
|
-
* })());
|
|
64
|
+
* const fBase = univerAPI.getActiveBase();
|
|
65
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
66
|
+
* const record = fBaseTable.getRecords()[0];
|
|
67
|
+
* console.log(record.getValue('status'));
|
|
128
68
|
* ```
|
|
129
69
|
*/
|
|
130
|
-
getValue(fieldId:
|
|
70
|
+
getValue(fieldId: FieldId): BaseCellValue;
|
|
131
71
|
/**
|
|
132
72
|
* Get all values from this record.
|
|
133
73
|
* @returns A field-id keyed value map.
|
|
134
74
|
* @example
|
|
135
75
|
* ```ts
|
|
136
|
-
* const
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* ```ts
|
|
141
|
-
* console.log((() => {
|
|
142
|
-
* const unitId = `facade_example_${Date.now()}`;
|
|
143
|
-
* const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
|
|
144
|
-
* try {
|
|
145
|
-
* const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
|
|
146
|
-
* const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
|
|
147
|
-
* const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
|
|
148
|
-
* return record.getValues();
|
|
149
|
-
* } finally {
|
|
150
|
-
* univerAPI.disposeUnit(unitId);
|
|
151
|
-
* }
|
|
152
|
-
* })());
|
|
76
|
+
* const fBase = univerAPI.getActiveBase();
|
|
77
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
78
|
+
* const record = fBaseTable.getRecords()[0];
|
|
79
|
+
* console.log(record.getValues());
|
|
153
80
|
* ```
|
|
154
81
|
*/
|
|
155
82
|
getValues(): IRecordSnapshot['values'];
|
|
@@ -159,146 +86,96 @@ export declare class FRecord {
|
|
|
159
86
|
* @param value The new cell value. Pass `null` to clear the cell.
|
|
160
87
|
* @example
|
|
161
88
|
* ```ts
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* console.log((() => {
|
|
168
|
-
* const unitId = `facade_example_${Date.now()}`;
|
|
169
|
-
* const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
|
|
170
|
-
* try {
|
|
171
|
-
* const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
|
|
172
|
-
* const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
|
|
173
|
-
* const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
|
|
174
|
-
* record.setValue(field.getId(), 'done');
|
|
175
|
-
* return record.getValue(field.getId());
|
|
176
|
-
* } finally {
|
|
177
|
-
* univerAPI.disposeUnit(unitId);
|
|
178
|
-
* }
|
|
179
|
-
* })());
|
|
89
|
+
* const fBase = univerAPI.getActiveBase();
|
|
90
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
91
|
+
* const record = fBaseTable.getRecordById('task-1');
|
|
92
|
+
* const success = record.setValue('status', 'done');
|
|
93
|
+
* console.log(success);
|
|
180
94
|
* ```
|
|
181
95
|
*/
|
|
182
|
-
setValue(fieldId:
|
|
96
|
+
setValue(fieldId: FieldId, value: BaseCellValue): boolean;
|
|
183
97
|
/**
|
|
184
98
|
* Set multiple field values in this record.
|
|
185
|
-
* @param values Field-id keyed values to write. Only the provided fields are
|
|
99
|
+
* @param {Record<string, BaseCellValue>} values Field-id keyed values to write. Only the provided fields are
|
|
186
100
|
* patched; omitted fields keep their existing values.
|
|
101
|
+
* @param {BaseFieldKeyEnum} fieldKey How to interpret the keys in `values`. Defaults to `BaseFieldKeyEnum.Id`.
|
|
102
|
+
* @returns {boolean} `true` if the command succeeded, `false` otherwise.
|
|
103
|
+
*
|
|
187
104
|
* @example
|
|
188
105
|
* ```ts
|
|
189
|
-
*
|
|
106
|
+
* const fBase = univerAPI.getActiveBase();
|
|
107
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
108
|
+
* const record = fBaseTable.getRecordById('task-1');
|
|
109
|
+
* const success = record.setValues(
|
|
110
|
+
* {
|
|
111
|
+
* status: 'done',
|
|
112
|
+
* progress: 100
|
|
113
|
+
* }
|
|
114
|
+
* );
|
|
115
|
+
* console.log(success);
|
|
190
116
|
* ```
|
|
191
117
|
*
|
|
192
|
-
* @example
|
|
118
|
+
* @example
|
|
193
119
|
* ```ts
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* }
|
|
206
|
-
* })());
|
|
120
|
+
* const fBase = univerAPI.getActiveBase();
|
|
121
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
122
|
+
* const record = fBaseTable.getRecordById('task-1');
|
|
123
|
+
* const success = record.setValues(
|
|
124
|
+
* {
|
|
125
|
+
* Status: 'done',
|
|
126
|
+
* Progress: 100
|
|
127
|
+
* },
|
|
128
|
+
* univerAPI.Enum.BaseFieldKeyEnum.Name
|
|
129
|
+
* );
|
|
130
|
+
* console.log(success);
|
|
207
131
|
* ```
|
|
208
132
|
*/
|
|
209
|
-
setValues(values: Record<string, BaseCellValue>,
|
|
133
|
+
setValues(values: Record<string, BaseCellValue>, fieldKey?: BaseFieldKeyEnum): boolean;
|
|
210
134
|
/**
|
|
211
135
|
* Delete this record.
|
|
136
|
+
* @returns {boolean} `true` if the command succeeded, `false` otherwise.
|
|
212
137
|
* @example
|
|
213
138
|
* ```ts
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* console.log((() => {
|
|
220
|
-
* const unitId = `facade_example_${Date.now()}`;
|
|
221
|
-
* const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
|
|
222
|
-
* try {
|
|
223
|
-
* const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
|
|
224
|
-
* const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
|
|
225
|
-
* const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
|
|
226
|
-
* const recordId = record.getId();
|
|
227
|
-
* record.delete();
|
|
228
|
-
* return table.getRecord(recordId);
|
|
229
|
-
* } finally {
|
|
230
|
-
* univerAPI.disposeUnit(unitId);
|
|
231
|
-
* }
|
|
232
|
-
* })());
|
|
139
|
+
* const fBase = univerAPI.getActiveBase();
|
|
140
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
141
|
+
* const record = fBaseTable.getRecordById('task-1');
|
|
142
|
+
* const success = record.delete();
|
|
143
|
+
* console.log(success);
|
|
233
144
|
* ```
|
|
234
145
|
*/
|
|
235
|
-
delete():
|
|
146
|
+
delete(): boolean;
|
|
236
147
|
/**
|
|
237
148
|
* Duplicate this record.
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* `input.values` as field-id keyed overrides.
|
|
241
|
-
*
|
|
242
|
-
* @param input Optional record id, values, and order key overrides.
|
|
243
|
-
* @param input.id Optional id for the duplicated record.
|
|
244
|
-
* @param input.values Optional field-id keyed values for the duplicated record.
|
|
245
|
-
* @param input.orderKey Optional order key for the duplicated record.
|
|
246
|
-
* @returns The duplicated record facade.
|
|
149
|
+
* @param {Partial<Omit<IRecordSnapshot, 'id'>>} [record] Optional record snapshot to override the source record.
|
|
150
|
+
* @returns {FBaseTableRecord} The new record.
|
|
247
151
|
* @example
|
|
248
152
|
* ```ts
|
|
249
|
-
* const
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
* @example Browser console
|
|
256
|
-
* ```ts
|
|
257
|
-
* console.log((() => {
|
|
258
|
-
* const unitId = `facade_example_${Date.now()}`;
|
|
259
|
-
* const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
|
|
260
|
-
* try {
|
|
261
|
-
* const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
|
|
262
|
-
* const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
|
|
263
|
-
* const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
|
|
264
|
-
* const copy = record.duplicate({ id: `${unitId}_copy`, values: { [field.getId()]: 'done' } });
|
|
265
|
-
* return { original: record.getId(), copy: copy.getId() };
|
|
266
|
-
* } finally {
|
|
267
|
-
* univerAPI.disposeUnit(unitId);
|
|
268
|
-
* }
|
|
269
|
-
* })());
|
|
153
|
+
* const fBase = univerAPI.getActiveBase();
|
|
154
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
155
|
+
* const record = fBaseTable.getRecordById('task-1');
|
|
156
|
+
* const copy = record.duplicate();
|
|
157
|
+
* console.log(copy);
|
|
270
158
|
* ```
|
|
271
159
|
*/
|
|
272
|
-
duplicate(
|
|
273
|
-
id?: string;
|
|
274
|
-
values?: Record<string, BaseCellValue>;
|
|
275
|
-
orderKey?: string;
|
|
276
|
-
}): FRecord;
|
|
160
|
+
duplicate(record?: Partial<Omit<IRecordSnapshot, 'id'>>): FBaseTableRecord;
|
|
277
161
|
/**
|
|
278
162
|
* Set this record's order key.
|
|
279
|
-
* @param orderKey The new order key.
|
|
163
|
+
* @param {string} orderKey The new order key.
|
|
164
|
+
* @returns {boolean} `true` if the command succeeded, `false` otherwise.
|
|
280
165
|
* @example
|
|
281
166
|
* ```ts
|
|
282
|
-
*
|
|
283
|
-
*
|
|
167
|
+
* const fBase = univerAPI.getActiveBase();
|
|
168
|
+
* const fBaseTable = fBase.getTableById('table-1');
|
|
169
|
+
* const records = fBaseTable.getRecords();
|
|
170
|
+
* const lastRecord = records[records.length - 1];
|
|
284
171
|
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
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
|
-
* const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
|
|
294
|
-
* record.setOrderKey('z');
|
|
295
|
-
* return record.getRecord().orderKey;
|
|
296
|
-
* } finally {
|
|
297
|
-
* univerAPI.disposeUnit(unitId);
|
|
298
|
-
* }
|
|
299
|
-
* })());
|
|
172
|
+
* // "0000" sorts before the timestamp-like order keys used by newly
|
|
173
|
+
* // created records, so the last record moves to the top immediately.
|
|
174
|
+
* // Clear the view's field sort first to see the underlying record order.
|
|
175
|
+
* const success = lastRecord?.setOrderKey('0000') ?? false;
|
|
176
|
+
* console.log(success ? 'Record moved to the top' : 'Failed to move record');
|
|
300
177
|
* ```
|
|
301
178
|
*/
|
|
302
|
-
setOrderKey(orderKey: string):
|
|
179
|
+
setOrderKey(orderKey: string): boolean;
|
|
303
180
|
private _getRecord;
|
|
304
181
|
}
|