@ai-table/state 0.0.17 → 0.0.19
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/esm2022/shared/to-table/array-event.mjs +5 -4
- package/esm2022/shared/utils/initialize.mjs +3 -2
- package/esm2022/shared/utils/translate.mjs +35 -17
- package/esm2022/types/shared.mjs +1 -1
- package/esm2022/types/view.mjs +1 -1
- package/esm2022/utils/common.mjs +1 -11
- package/esm2022/utils/field/add-fields.mjs +3 -4
- package/esm2022/utils/record/add-records.mjs +5 -5
- package/esm2022/utils/view.mjs +4 -2
- package/fesm2022/ai-table-state.mjs +46 -32
- package/fesm2022/ai-table-state.mjs.map +1 -1
- package/package.json +1 -1
- package/shared/to-table/array-event.d.ts.map +1 -1
- package/shared/utils/initialize.d.ts.map +1 -1
- package/shared/utils/translate.d.ts +10 -3
- package/shared/utils/translate.d.ts.map +1 -1
- package/types/shared.d.ts +1 -1
- package/types/shared.d.ts.map +1 -1
- package/types/view.d.ts +1 -0
- package/types/view.d.ts.map +1 -1
- package/utils/common.d.ts +0 -1
- package/utils/common.d.ts.map +1 -1
- package/utils/field/add-fields.d.ts.map +1 -1
- package/utils/record/add-records.d.ts.map +1 -1
- package/utils/view.d.ts.map +1 -1
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as Y from 'yjs';
|
2
2
|
import { isArray, isEmpty as isEmpty$1, isObject, isUndefinedOrNull, TinyDate } from 'ngx-tethys/util';
|
3
|
-
import { AITableQueries,
|
3
|
+
import { AITableQueries, AITableFieldType, getDefaultFieldValue, Direction as Direction$1, idsCreator, idCreator, shortIdCreator, shortIdsCreator, AI_TABLE_GRID_FIELD_SERVICE_MAP } from '@ai-table/grid';
|
4
4
|
import * as _ from 'lodash';
|
5
5
|
import ___default, { isEqual } from 'lodash';
|
6
6
|
import { fromUnixTime, subDays } from 'date-fns';
|
@@ -101,9 +101,16 @@ var ExecuteType;
|
|
101
101
|
ExecuteType[ExecuteType["Redo"] = 2] = "Redo";
|
102
102
|
})(ExecuteType || (ExecuteType = {}));
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
var SystemFieldIndex;
|
105
|
+
(function (SystemFieldIndex) {
|
106
|
+
SystemFieldIndex[SystemFieldIndex["Id"] = 0] = "Id";
|
107
|
+
SystemFieldIndex[SystemFieldIndex["ShortId"] = 1] = "ShortId";
|
108
|
+
SystemFieldIndex[SystemFieldIndex["CreatedAt"] = 2] = "CreatedAt";
|
109
|
+
SystemFieldIndex[SystemFieldIndex["CreatedBy"] = 3] = "CreatedBy";
|
110
|
+
SystemFieldIndex[SystemFieldIndex["Positions"] = 4] = "Positions";
|
111
|
+
SystemFieldIndex[SystemFieldIndex["UpdatedAt"] = 5] = "UpdatedAt";
|
112
|
+
SystemFieldIndex[SystemFieldIndex["UpdatedBy"] = 6] = "UpdatedBy";
|
113
|
+
})(SystemFieldIndex || (SystemFieldIndex = {}));
|
107
114
|
function toSyncElement(node) {
|
108
115
|
const element = new Y.Map();
|
109
116
|
for (const key in node) {
|
@@ -173,7 +180,15 @@ function getSharedMapValueIndex(sharedNodes, id) {
|
|
173
180
|
return nodeIndex;
|
174
181
|
}
|
175
182
|
const getSystemFieldValues = (record) => {
|
176
|
-
return [
|
183
|
+
return [
|
184
|
+
{ _id: record['_id'] },
|
185
|
+
record.short_id,
|
186
|
+
record.created_at,
|
187
|
+
record.created_by,
|
188
|
+
record['positions'],
|
189
|
+
record.updated_at,
|
190
|
+
record.updated_by
|
191
|
+
];
|
177
192
|
};
|
178
193
|
const getCustomFieldValues = (record) => {
|
179
194
|
throw new Error('No implement');
|
@@ -188,35 +203,38 @@ const getValuesByCustomFieldValues = (customFieldValues, fields) => {
|
|
188
203
|
};
|
189
204
|
const getTrackableEntityBySystemFieldValues = (systemFieldValues) => {
|
190
205
|
return {
|
191
|
-
created_at: systemFieldValues[
|
192
|
-
created_by: systemFieldValues[
|
193
|
-
updated_at: systemFieldValues[
|
194
|
-
updated_by: systemFieldValues[
|
206
|
+
created_at: systemFieldValues[SystemFieldIndex.CreatedAt],
|
207
|
+
created_by: systemFieldValues[SystemFieldIndex.CreatedBy],
|
208
|
+
updated_at: systemFieldValues[SystemFieldIndex.UpdatedAt],
|
209
|
+
updated_by: systemFieldValues[SystemFieldIndex.UpdatedBy]
|
195
210
|
};
|
196
211
|
};
|
197
212
|
const getIdBySystemFieldValues = (systemFieldValues) => {
|
198
|
-
return systemFieldValues[
|
213
|
+
return systemFieldValues[SystemFieldIndex.Id]['_id'];
|
214
|
+
};
|
215
|
+
const getShortIdBySystemFieldValues = (systemFieldValues) => {
|
216
|
+
return systemFieldValues[SystemFieldIndex.ShortId];
|
199
217
|
};
|
200
218
|
const getIdBySystemFieldValuesType = (systemFieldValuesType) => {
|
201
|
-
return systemFieldValuesType.get(
|
219
|
+
return systemFieldValuesType.get(SystemFieldIndex.Id)['_id'];
|
202
220
|
};
|
203
221
|
const getPositionsBySystemFieldValues = (systemFieldValues) => {
|
204
|
-
return systemFieldValues[
|
222
|
+
return systemFieldValues[SystemFieldIndex.Positions];
|
205
223
|
};
|
206
224
|
const getPositionsByRecordSyncElement = (recordSyncElement) => {
|
207
225
|
const systemFieldType = recordSyncElement.get(0);
|
208
|
-
const positions = systemFieldType.get(
|
226
|
+
const positions = systemFieldType.get(SystemFieldIndex.Positions);
|
209
227
|
return positions;
|
210
228
|
};
|
211
229
|
const setRecordPositions$1 = (recordSyncElement, newPositions) => {
|
212
230
|
const systemFieldType = recordSyncElement.get(0);
|
213
|
-
systemFieldType.delete(
|
214
|
-
systemFieldType.insert(
|
231
|
+
systemFieldType.delete(SystemFieldIndex.Positions);
|
232
|
+
systemFieldType.insert(SystemFieldIndex.Positions, [newPositions]);
|
215
233
|
};
|
216
234
|
const setRecordUpdatedInfo = (recordSyncElement, info) => {
|
217
235
|
const systemFieldType = recordSyncElement.get(0);
|
218
|
-
systemFieldType.delete(
|
219
|
-
systemFieldType.insert(
|
236
|
+
systemFieldType.delete(SystemFieldIndex.UpdatedAt, 2);
|
237
|
+
systemFieldType.insert(SystemFieldIndex.UpdatedAt, [info.updated_at, info.updated_by]);
|
220
238
|
};
|
221
239
|
|
222
240
|
const AI_TABLE_CONTENT_FIELD_NAME = 'content';
|
@@ -262,6 +280,7 @@ const getRecordsBySharedJson = (recordJsonArray, fields) => {
|
|
262
280
|
const [systemFieldValues, customFieldValues] = record;
|
263
281
|
return {
|
264
282
|
_id: getIdBySystemFieldValues(systemFieldValues),
|
283
|
+
short_id: getShortIdBySystemFieldValues(systemFieldValues),
|
265
284
|
...getTrackableEntityBySystemFieldValues(systemFieldValues),
|
266
285
|
positions: getPositionsBySystemFieldValues(systemFieldValues),
|
267
286
|
values: getValuesByCustomFieldValues(customFieldValues, fields)
|
@@ -321,6 +340,7 @@ function translateArrayEvent(aiTable, sharedType, event) {
|
|
321
340
|
path: path,
|
322
341
|
record: {
|
323
342
|
_id: getIdBySystemFieldValues(systemFieldValues),
|
343
|
+
short_id: getShortIdBySystemFieldValues(systemFieldValues),
|
324
344
|
...getTrackableEntityBySystemFieldValues(systemFieldValues),
|
325
345
|
positions: getPositionsBySystemFieldValues(systemFieldValues),
|
326
346
|
values: getValuesByCustomFieldValues(customFieldValues, aiTable.fields())
|
@@ -423,10 +443,10 @@ function isCustomFieldOperation(targetPath) {
|
|
423
443
|
return false;
|
424
444
|
}
|
425
445
|
function isPositionsOperation(fieldIndex) {
|
426
|
-
return fieldIndex ===
|
446
|
+
return fieldIndex === SystemFieldIndex.Positions;
|
427
447
|
}
|
428
448
|
function isUpdatedByOperation(fieldIndex) {
|
429
|
-
return fieldIndex ===
|
449
|
+
return fieldIndex === SystemFieldIndex.UpdatedBy;
|
430
450
|
}
|
431
451
|
function getRemoveIds(event, type) {
|
432
452
|
const ids = [];
|
@@ -695,15 +715,6 @@ function isEmpty(value) {
|
|
695
715
|
}
|
696
716
|
return isUndefinedOrNull(value) || value == '';
|
697
717
|
}
|
698
|
-
function getNewIdsByCount(count) {
|
699
|
-
if (count <= 0)
|
700
|
-
return [];
|
701
|
-
const newIds = [];
|
702
|
-
for (let i = 0; i < count; i++) {
|
703
|
-
newIds.push(idCreator());
|
704
|
-
}
|
705
|
-
return newIds;
|
706
|
-
}
|
707
718
|
function isPathEqual(path, another) {
|
708
719
|
return path.length === another.length && path.every((n, i) => n === another[i]);
|
709
720
|
}
|
@@ -1492,7 +1503,7 @@ function addFields(aiTable, options, updatedInfo) {
|
|
1492
1503
|
if (direction === Direction$1.after) {
|
1493
1504
|
addIndex++;
|
1494
1505
|
}
|
1495
|
-
const newFieldIds =
|
1506
|
+
const newFieldIds = idsCreator(count);
|
1496
1507
|
newFieldIds.forEach((id, index) => {
|
1497
1508
|
const newField = { _id: id, ...defaultValue };
|
1498
1509
|
Actions.addField(aiTable, newField, [addIndex + index]);
|
@@ -1536,8 +1547,10 @@ function getPosition(data, activeViewId, index) {
|
|
1536
1547
|
function addView(aiTable, type) {
|
1537
1548
|
let index = aiTable.views().length;
|
1538
1549
|
const newId = idCreator();
|
1550
|
+
const shortId = shortIdCreator();
|
1539
1551
|
let newView = {
|
1540
1552
|
_id: newId,
|
1553
|
+
short_id: shortId,
|
1541
1554
|
name: '表格视图 ' + index
|
1542
1555
|
};
|
1543
1556
|
let originViewId = aiTable.views()[aiTable.views().length - 1]._id;
|
@@ -1587,7 +1600,8 @@ function addRecords(aiTable, options, trackableEntity) {
|
|
1587
1600
|
if (direction === Direction$1.after) {
|
1588
1601
|
addIndex++;
|
1589
1602
|
}
|
1590
|
-
const newRecordIds =
|
1603
|
+
const newRecordIds = idsCreator(count);
|
1604
|
+
const newRecordShortIds = shortIdsCreator(count);
|
1591
1605
|
const newRecordValues = getDefaultRecordValues(aiTable, isDuplicate, originId);
|
1592
1606
|
// TODO: 判断如果存在筛选条件,且 newRecordValues 中没有一项满足筛选条件
|
1593
1607
|
// 把 id 添加到 RECORDS_WILL_HIDDEN 中
|
@@ -1598,7 +1612,7 @@ function addRecords(aiTable, options, trackableEntity) {
|
|
1598
1612
|
});
|
1599
1613
|
}
|
1600
1614
|
newRecordIds.forEach((id, index) => {
|
1601
|
-
const newRecord = { _id: id, values: newRecordValues, ...trackableEntity };
|
1615
|
+
const newRecord = { _id: id, short_id: newRecordShortIds[index], values: newRecordValues, ...trackableEntity };
|
1602
1616
|
Actions.addRecord(aiTable, newRecord, [addIndex + index]);
|
1603
1617
|
});
|
1604
1618
|
}
|
@@ -1683,5 +1697,5 @@ const VIEW_ACTIONS = [ActionName.SetView, ActionName.AddView, ActionName.RemoveV
|
|
1683
1697
|
* Generated bundle index. Do not edit.
|
1684
1698
|
*/
|
1685
1699
|
|
1686
|
-
export { AITableFilterLogical, AITableFilterOperation, AI_TABLE_CONTENT_FIELD_NAME, ActionName, Actions, Direction, DividerMenuItem, EditFieldPropertyItem, ExecuteType, FLUSHING,
|
1700
|
+
export { AITableFilterLogical, AITableFilterOperation, AI_TABLE_CONTENT_FIELD_NAME, ActionName, Actions, Direction, DividerMenuItem, EditFieldPropertyItem, ExecuteType, FLUSHING, Positions, RemovePositions, SystemFieldIndex, VIEW_ACTIONS, ViewOperationMap, YjsAITable, actionMappers, addFields, addRecords, addView, applyActionOps, applyEvents, applyYjsEvents, buildFieldsByView, buildRecordsByView, buildRemoveFieldItem, createDefaultPositions, createSharedType, doFilter, getCustomFieldValues, getDataBySharedType, getDefaultRecordDataByFilter, getDefaultRecordValues, getFilteredRecords, getIdBySystemFieldValues, getIdBySystemFieldValuesType, getPosition, getPositionsByRecordSyncElement, getPositionsBySystemFieldValues, getRecordsBySharedJson, getShareTypeNumberPath, getSharedMapValueId, getSharedMapValueIndex, getSharedRecord, getSharedRecordId, getSharedRecordIndex, getSharedTypeByData, getShortIdBySystemFieldValues, getSortFields, getSortRecords, getSystemFieldValues, getTrackableEntityBySystemFieldValues, getValuesByCustomFieldValues, isEmpty, isPathEqual, removeView, setRecordPositions$1 as setRecordPositions, setRecordUpdatedInfo, sortByViewPosition, sortRecordsBySortInfo, toRecordSyncElement, toSharedType, toSyncElement, translatePositionToPath, translateYjsEvent, updateFieldValue, updateRecordsUpdatedInfo, withState };
|
1687
1701
|
//# sourceMappingURL=ai-table-state.mjs.map
|