@ai-table/state 0.0.43 → 0.0.44
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/constants/field-menu-item.d.ts.map +1 -1
- package/esm2022/action/general.mjs +2 -2
- package/esm2022/constants/field-menu-item.mjs +4 -7
- package/esm2022/shared/to-table/array-event.mjs +6 -6
- package/esm2022/shared/to-table/map-event.mjs +2 -2
- package/esm2022/shared/utils/translate.mjs +3 -3
- package/esm2022/utils/common.mjs +10 -1
- package/esm2022/utils/view.mjs +22 -6
- package/fesm2022/ai-table-state.mjs +41 -21
- 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/to-table/map-event.d.ts.map +1 -1
- package/shared/utils/translate.d.ts +1 -1
- package/shared/utils/translate.d.ts.map +1 -1
- package/utils/common.d.ts +1 -0
- package/utils/common.d.ts.map +1 -1
- package/utils/view.d.ts +1 -0
- package/utils/view.d.ts.map +1 -1
@@ -120,7 +120,7 @@ function toRecordSyncElement(record, fields) {
|
|
120
120
|
element.insert(0, [systemFieldValues, customFieldValues]);
|
121
121
|
return element;
|
122
122
|
}
|
123
|
-
function translatePositionToPath(data, position, activeViewId) {
|
123
|
+
function translatePositionToPath(data, position, activeViewId, indexOffset = 0) {
|
124
124
|
let index = data.findIndex((value, index) => {
|
125
125
|
if (index === 0) {
|
126
126
|
return position < value.positions[activeViewId];
|
@@ -130,7 +130,7 @@ function translatePositionToPath(data, position, activeViewId) {
|
|
130
130
|
if (index === -1) {
|
131
131
|
index = data.length;
|
132
132
|
}
|
133
|
-
return [index];
|
133
|
+
return [index + indexOffset];
|
134
134
|
}
|
135
135
|
function getShareTypeNumberPath(path) {
|
136
136
|
return path.filter((node) => typeof node === 'number');
|
@@ -330,7 +330,7 @@ function translateArrayEvent(aiTable, sharedType, event) {
|
|
330
330
|
short_id: getShortIdBySystemFieldValues(systemFieldValues),
|
331
331
|
...getTrackableEntityBySystemFieldValues(systemFieldValues),
|
332
332
|
positions: getPositionsBySystemFieldValues(systemFieldValues),
|
333
|
-
values: getValuesByCustomFieldValues(customFieldValues, aiTable.
|
333
|
+
values: getValuesByCustomFieldValues(customFieldValues, aiTable.gridData().fields)
|
334
334
|
}
|
335
335
|
});
|
336
336
|
});
|
@@ -340,9 +340,9 @@ function translateArrayEvent(aiTable, sharedType, event) {
|
|
340
340
|
const sharedRecords = sharedType.get('records');
|
341
341
|
const sharedFields = sharedType.get('fields');
|
342
342
|
let systemFieldOffset = 0;
|
343
|
-
delta.insert?.map((item) => {
|
343
|
+
delta.insert?.map((item, index) => {
|
344
344
|
const recordIndex = targetPath[0];
|
345
|
-
const fieldIndex = offset;
|
345
|
+
const fieldIndex = offset + index;
|
346
346
|
const record = aiTable.records()[recordIndex];
|
347
347
|
if (isSystemFieldOperation(targetPath)) {
|
348
348
|
if (isPositionsOperation(fieldIndex)) {
|
@@ -389,9 +389,9 @@ function translateArrayEvent(aiTable, sharedType, event) {
|
|
389
389
|
}
|
390
390
|
}
|
391
391
|
if (isFieldsTranslate) {
|
392
|
-
delta.insert?.map((item) => {
|
392
|
+
delta.insert?.map((item, index) => {
|
393
393
|
const data = item.toJSON();
|
394
|
-
const path = translatePositionToPath(aiTable.
|
394
|
+
const path = translatePositionToPath(aiTable.gridData().fields, data['positions'][activeViewId], activeViewId, index);
|
395
395
|
actions.push({
|
396
396
|
type: ActionName.AddField,
|
397
397
|
path,
|
@@ -468,7 +468,7 @@ function translateMapEvent(aiTable, sharedType, event) {
|
|
468
468
|
if (isFieldsTranslate) {
|
469
469
|
const field = sharedType.get('fields')?.get(targetPath);
|
470
470
|
const fieldId = field && field.get('_id');
|
471
|
-
targetElement = fieldId && aiTable.
|
471
|
+
targetElement = fieldId && aiTable.gridData().fields.find((item) => item._id === field.get('_id'));
|
472
472
|
}
|
473
473
|
if (isViewTranslate) {
|
474
474
|
targetElement = aiTable.views()[targetPath];
|
@@ -705,6 +705,15 @@ function sortByViewPosition(data, activeView) {
|
|
705
705
|
}
|
706
706
|
return data;
|
707
707
|
}
|
708
|
+
function generateCopyName(exsitNames, name) {
|
709
|
+
let newName = `${name} 副本`;
|
710
|
+
let index = 2;
|
711
|
+
while (exsitNames.includes(newName)) {
|
712
|
+
newName = `${name} 副本 ${index}`;
|
713
|
+
index++;
|
714
|
+
}
|
715
|
+
return newName;
|
716
|
+
}
|
708
717
|
|
709
718
|
function getSortRecords(aiTable, records, activeView, sortKeysMap) {
|
710
719
|
if (!activeView?.settings || !activeView.settings.sorts?.length) {
|
@@ -956,7 +965,7 @@ const apply = (aiTable, records, fields, views, action) => {
|
|
956
965
|
const [fieldIndex] = action.path;
|
957
966
|
if (fieldIndex > -1) {
|
958
967
|
const newField = action.field;
|
959
|
-
newField.positions = createDefaultPositions(aiTable.views(), aiTable.activeViewId(), aiTable.
|
968
|
+
newField.positions = createDefaultPositions(aiTable.views(), aiTable.activeViewId(), aiTable.gridData().fields, action.path[0]);
|
960
969
|
fields.splice(fieldIndex, 0, newField);
|
961
970
|
records.forEach((item) => {
|
962
971
|
item.values[newField._id] =
|
@@ -1242,8 +1251,12 @@ function createDefaultPositions(views, activeId, data, index) {
|
|
1242
1251
|
const positions = {};
|
1243
1252
|
const position = getPosition(data, activeId, index);
|
1244
1253
|
views.forEach((element) => {
|
1245
|
-
|
1246
|
-
|
1254
|
+
if (element._id === activeId) {
|
1255
|
+
positions[element._id] = position;
|
1256
|
+
}
|
1257
|
+
else {
|
1258
|
+
positions[element._id] = getMaxPosition(data, element._id) + 1;
|
1259
|
+
}
|
1247
1260
|
});
|
1248
1261
|
return positions;
|
1249
1262
|
}
|
@@ -1255,11 +1268,19 @@ function getPosition(data, activeViewId, index) {
|
|
1255
1268
|
position = (previousViewPosition + nextViewPosition) / 2;
|
1256
1269
|
}
|
1257
1270
|
else {
|
1258
|
-
const
|
1259
|
-
position =
|
1271
|
+
const maxPosition = getMaxPosition(data, activeViewId);
|
1272
|
+
position = maxPosition + 1;
|
1260
1273
|
}
|
1261
1274
|
return position;
|
1262
1275
|
}
|
1276
|
+
function getMaxPosition(data, activeViewId) {
|
1277
|
+
return data.reduce((maxPosition, item) => {
|
1278
|
+
if (item.positions[activeViewId] > maxPosition) {
|
1279
|
+
maxPosition = item.positions[activeViewId];
|
1280
|
+
}
|
1281
|
+
return maxPosition;
|
1282
|
+
}, 0);
|
1283
|
+
}
|
1263
1284
|
function addView(aiTable, type, viewId) {
|
1264
1285
|
let index = aiTable.views().length;
|
1265
1286
|
const newId = idCreator();
|
@@ -1273,10 +1294,13 @@ function addView(aiTable, type, viewId) {
|
|
1273
1294
|
if (type === 'copy') {
|
1274
1295
|
originViewId = viewId ?? aiTable.activeViewId();
|
1275
1296
|
const copyView = aiTable.views().find((item) => item._id === originViewId);
|
1297
|
+
const allViewNames = aiTable.views().map((item) => item.name);
|
1298
|
+
const copyName = copyView.name;
|
1299
|
+
const newViewName = generateCopyName(allViewNames, copyName);
|
1276
1300
|
newView = {
|
1277
1301
|
...copyView,
|
1278
1302
|
_id: newId,
|
1279
|
-
name:
|
1303
|
+
name: newViewName
|
1280
1304
|
};
|
1281
1305
|
index = aiTable.views().indexOf(copyView) + 1;
|
1282
1306
|
}
|
@@ -1448,12 +1472,8 @@ const CopyFieldPropertyItem = (addFieldFn) => {
|
|
1448
1472
|
icon: 'copy',
|
1449
1473
|
exec: (aiTable, field) => {
|
1450
1474
|
const allFieldNames = (aiTable.fields() || []).map((item) => item.name);
|
1451
|
-
|
1452
|
-
let
|
1453
|
-
while (allFieldNames.includes(newFieldName)) {
|
1454
|
-
newFieldName = `${field().name} 副本 ${index}`;
|
1455
|
-
index++;
|
1456
|
-
}
|
1475
|
+
const copyName = field().name;
|
1476
|
+
let newFieldName = generateCopyName(allFieldNames, copyName);
|
1457
1477
|
const fieldOptions = {
|
1458
1478
|
originId: field()._id,
|
1459
1479
|
isCopy: true,
|
@@ -1521,5 +1541,5 @@ const VIEW_ACTIONS = [ActionName.SetView, ActionName.AddView, ActionName.RemoveV
|
|
1521
1541
|
* Generated bundle index. Do not edit.
|
1522
1542
|
*/
|
1523
1543
|
|
1524
|
-
export { AITableFilterLogical, AI_TABLE_CONTENT_FIELD_NAME, ActionName, Actions, CopyCellsItem, CopyFieldPropertyItem, Direction, DividerMenuItem, EditFieldPropertyItem, ExecuteType, FLUSHING, PasteCellsItem, Positions, RemovePositions, RemoveRecordsItem, SystemFieldIndex, VIEW_ACTIONS, YjsAITable, actionMappers, addFields, addRecords, addView, applyActionOps, applyEvents, applyYjsEvents, buildFieldsByView, buildRecordsByView, buildRemoveFieldItem, createDefaultPositions, createSharedType, doFilter, getCustomFieldValues, getDataBySharedType, getDefaultRecordDataByFilter, getDefaultRecordValues, getFieldPositionInView, getFilteredRecords, getIdBySystemFieldValues, getIdBySystemFieldValuesType, getPosition, getPositionsByRecordSyncElement, getPositionsBySystemFieldValues, getRecordsBySharedJson, getShareTypeNumberPath, getSharedMapValueId, getSharedMapValueIndex, getSharedRecord, getSharedRecordId, getSharedRecordIndex, getSharedTypeByData, getShortIdBySystemFieldValues, getSortFields, getSortRecords, getSystemFieldValues, getTrackableEntityBySystemFieldValues, getValuesByCustomFieldValues, isPathEqual, moveFields, removeView, setRecordPositions$1 as setRecordPositions, setRecordUpdatedInfo, sortByViewPosition, sortRecordsBySortInfo, toRecordSyncElement, toSharedType, toSyncElement, translatePositionToPath, translateYjsEvent, updateFieldValue, updateRecordsUpdatedInfo, withState };
|
1544
|
+
export { AITableFilterLogical, AI_TABLE_CONTENT_FIELD_NAME, ActionName, Actions, CopyCellsItem, CopyFieldPropertyItem, Direction, DividerMenuItem, EditFieldPropertyItem, ExecuteType, FLUSHING, PasteCellsItem, Positions, RemovePositions, RemoveRecordsItem, SystemFieldIndex, VIEW_ACTIONS, YjsAITable, actionMappers, addFields, addRecords, addView, applyActionOps, applyEvents, applyYjsEvents, buildFieldsByView, buildRecordsByView, buildRemoveFieldItem, createDefaultPositions, createSharedType, doFilter, generateCopyName, getCustomFieldValues, getDataBySharedType, getDefaultRecordDataByFilter, getDefaultRecordValues, getFieldPositionInView, getFilteredRecords, getIdBySystemFieldValues, getIdBySystemFieldValuesType, getMaxPosition, getPosition, getPositionsByRecordSyncElement, getPositionsBySystemFieldValues, getRecordsBySharedJson, getShareTypeNumberPath, getSharedMapValueId, getSharedMapValueIndex, getSharedRecord, getSharedRecordId, getSharedRecordIndex, getSharedTypeByData, getShortIdBySystemFieldValues, getSortFields, getSortRecords, getSystemFieldValues, getTrackableEntityBySystemFieldValues, getValuesByCustomFieldValues, isPathEqual, moveFields, removeView, setRecordPositions$1 as setRecordPositions, setRecordUpdatedInfo, sortByViewPosition, sortRecordsBySortInfo, toRecordSyncElement, toSharedType, toSyncElement, translatePositionToPath, translateYjsEvent, updateFieldValue, updateRecordsUpdatedInfo, withState };
|
1525
1545
|
//# sourceMappingURL=ai-table-state.mjs.map
|