@ai-table/state 0.0.44 → 0.0.45
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/action/general.d.ts.map +1 -1
- package/constants/context-menu-item.d.ts +4 -4
- package/constants/context-menu-item.d.ts.map +1 -1
- package/constants/field-menu-item.d.ts +3 -3
- package/constants/field-menu-item.d.ts.map +1 -1
- package/esm2022/action/general.mjs +4 -2
- package/esm2022/constants/context-menu-item.mjs +36 -30
- package/esm2022/constants/field-menu-item.mjs +9 -7
- package/esm2022/utils/common.mjs +7 -5
- package/esm2022/utils/field/remove-field.mjs +4 -3
- package/esm2022/utils/i18n.mjs +37 -0
- package/esm2022/utils/index.mjs +2 -1
- package/esm2022/utils/view.mjs +9 -5
- package/fesm2022/ai-table-state.mjs +95 -47
- package/fesm2022/ai-table-state.mjs.map +1 -1
- package/package.json +1 -1
- package/utils/common.d.ts +2 -1
- package/utils/common.d.ts.map +1 -1
- package/utils/field/remove-field.d.ts +1 -1
- package/utils/field/remove-field.d.ts.map +1 -1
- package/utils/i18n.d.ts +15 -0
- package/utils/i18n.d.ts.map +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.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 } from 'ngx-tethys/util';
|
3
|
-
import { AITableQueries, FieldModelMap, AITableFilterOperation, AITableFieldType, isSystemField, isEmpty, getDefaultFieldValue, Direction as Direction$1, idsCreator, idCreator, shortIdCreator, shortIdsCreator, AI_TABLE_GRID_FIELD_SERVICE_MAP, AITable, isMac, buildClipboardData, writeToClipboard, writeToAITable } from '@ai-table/grid';
|
3
|
+
import { AITableQueries, FieldModelMap, AITableFilterOperation, AITableFieldType, isSystemField, isEmpty, getDefaultFieldValue, Direction as Direction$1, idsCreator, idCreator, shortIdCreator, generateNewName, shortIdsCreator, AI_TABLE_GRID_FIELD_SERVICE_MAP, AITable, isMac, buildClipboardData, writeToClipboard, getI18nTextByKey, AITableGridI18nKey, writeToAITable } from '@ai-table/grid';
|
4
4
|
import { createDraft, finishDraft } from 'immer';
|
5
5
|
import * as _ from 'lodash';
|
6
6
|
import ___default from 'lodash';
|
@@ -695,6 +695,43 @@ function applyActionOps(aiTable, sharedType, actions) {
|
|
695
695
|
return sharedType;
|
696
696
|
}
|
697
697
|
|
698
|
+
var AITableStateI18nKey;
|
699
|
+
(function (AITableStateI18nKey) {
|
700
|
+
AITableStateI18nKey["copyField"] = "copyField";
|
701
|
+
AITableStateI18nKey["removeRecords"] = "removeRecords";
|
702
|
+
AITableStateI18nKey["copy"] = "copy";
|
703
|
+
AITableStateI18nKey["copySuffix"] = "copySuffix";
|
704
|
+
AITableStateI18nKey["paste"] = "paste";
|
705
|
+
AITableStateI18nKey["invalidPasteContent"] = "invalidPasteContent";
|
706
|
+
AITableStateI18nKey["tableView"] = "tableView";
|
707
|
+
AITableStateI18nKey["editField"] = "editField";
|
708
|
+
AITableStateI18nKey["removeField"] = "removeField";
|
709
|
+
})(AITableStateI18nKey || (AITableStateI18nKey = {}));
|
710
|
+
const AITableI18nText = {
|
711
|
+
[AITableStateI18nKey.copyField]: '复制列',
|
712
|
+
[AITableStateI18nKey.removeRecords]: '删除行',
|
713
|
+
[AITableStateI18nKey.copy]: '复制',
|
714
|
+
[AITableStateI18nKey.copySuffix]: '副本',
|
715
|
+
[AITableStateI18nKey.paste]: '粘贴',
|
716
|
+
[AITableStateI18nKey.invalidPasteContent]: '粘贴内容不符合当前类型',
|
717
|
+
[AITableStateI18nKey.tableView]: '表格视图',
|
718
|
+
[AITableStateI18nKey.editField]: '编辑列',
|
719
|
+
[AITableStateI18nKey.removeField]: '删除列'
|
720
|
+
};
|
721
|
+
const getDefaultI18nTextByKey = (key) => {
|
722
|
+
return AITableI18nText[key] || key;
|
723
|
+
};
|
724
|
+
const getStateI18nTextByKey = (aiTable, key) => {
|
725
|
+
if (aiTable.getI18nTextByKey) {
|
726
|
+
const customText = aiTable.getI18nTextByKey(key);
|
727
|
+
if (customText) {
|
728
|
+
return customText;
|
729
|
+
}
|
730
|
+
}
|
731
|
+
const defaultText = getDefaultI18nTextByKey(key);
|
732
|
+
return defaultText;
|
733
|
+
};
|
734
|
+
|
698
735
|
function isPathEqual(path, another) {
|
699
736
|
return path.length === another.length && path.every((n, i) => n === another[i]);
|
700
737
|
}
|
@@ -705,11 +742,12 @@ function sortByViewPosition(data, activeView) {
|
|
705
742
|
}
|
706
743
|
return data;
|
707
744
|
}
|
708
|
-
function generateCopyName(
|
709
|
-
|
745
|
+
function generateCopyName(aiTable, existNames, name) {
|
746
|
+
const copyText = getStateI18nTextByKey(aiTable, AITableStateI18nKey.copySuffix);
|
747
|
+
let newName = `${name} ${copyText}`;
|
710
748
|
let index = 2;
|
711
|
-
while (
|
712
|
-
newName = `${name}
|
749
|
+
while (existNames.includes(newName)) {
|
750
|
+
newName = `${name} ${copyText} ${index}`;
|
713
751
|
index++;
|
714
752
|
}
|
715
753
|
return newName;
|
@@ -965,7 +1003,9 @@ const apply = (aiTable, records, fields, views, action) => {
|
|
965
1003
|
const [fieldIndex] = action.path;
|
966
1004
|
if (fieldIndex > -1) {
|
967
1005
|
const newField = action.field;
|
968
|
-
newField.positions
|
1006
|
+
if (!newField.positions) {
|
1007
|
+
newField.positions = createDefaultPositions(aiTable.views(), aiTable.activeViewId(), aiTable.gridData().fields, action.path[0]);
|
1008
|
+
}
|
969
1009
|
fields.splice(fieldIndex, 0, newField);
|
970
1010
|
records.forEach((item) => {
|
971
1011
|
item.values[newField._id] =
|
@@ -1235,10 +1275,10 @@ function addFields(aiTable, options, updatedInfo) {
|
|
1235
1275
|
updateRecordsUpdatedInfo(aiTable, updatedInfo);
|
1236
1276
|
}
|
1237
1277
|
|
1238
|
-
const buildRemoveFieldItem = (getUpdatedInfo) => {
|
1278
|
+
const buildRemoveFieldItem = (aiTable, getUpdatedInfo) => {
|
1239
1279
|
return {
|
1240
1280
|
type: 'removeField',
|
1241
|
-
name:
|
1281
|
+
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.removeField),
|
1242
1282
|
icon: 'trash',
|
1243
1283
|
exec: (aiTable, field) => {
|
1244
1284
|
Actions.removeField(aiTable, [field()._id]);
|
@@ -1285,22 +1325,24 @@ function addView(aiTable, type, viewId) {
|
|
1285
1325
|
let index = aiTable.views().length;
|
1286
1326
|
const newId = idCreator();
|
1287
1327
|
const shortId = shortIdCreator();
|
1328
|
+
const allViewNames = aiTable.views().map((item) => item.name);
|
1329
|
+
const count = aiTable.views().length || 0;
|
1330
|
+
const newViewName = generateNewName(allViewNames, count, getStateI18nTextByKey(aiTable, AITableStateI18nKey.tableView));
|
1288
1331
|
let newView = {
|
1289
1332
|
_id: newId,
|
1290
1333
|
short_id: shortId,
|
1291
|
-
name:
|
1334
|
+
name: newViewName
|
1292
1335
|
};
|
1293
1336
|
let originViewId = aiTable.views()[aiTable.views().length - 1]._id;
|
1294
1337
|
if (type === 'copy') {
|
1295
1338
|
originViewId = viewId ?? aiTable.activeViewId();
|
1296
1339
|
const copyView = aiTable.views().find((item) => item._id === originViewId);
|
1297
|
-
const allViewNames = aiTable.views().map((item) => item.name);
|
1298
1340
|
const copyName = copyView.name;
|
1299
|
-
const
|
1341
|
+
const copyViewName = generateCopyName(aiTable, allViewNames, copyName);
|
1300
1342
|
newView = {
|
1301
1343
|
...copyView,
|
1302
1344
|
_id: newId,
|
1303
|
-
name:
|
1345
|
+
name: copyViewName
|
1304
1346
|
};
|
1305
1347
|
index = aiTable.views().indexOf(copyView) + 1;
|
1306
1348
|
}
|
@@ -1441,9 +1483,9 @@ const withState = (aiTable) => {
|
|
1441
1483
|
const DividerMenuItem = {
|
1442
1484
|
type: 'divider'
|
1443
1485
|
};
|
1444
|
-
const EditFieldPropertyItem = {
|
1486
|
+
const EditFieldPropertyItem = (aiTable) => ({
|
1445
1487
|
type: 'editFieldProperty',
|
1446
|
-
name:
|
1488
|
+
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.editField),
|
1447
1489
|
icon: 'edit',
|
1448
1490
|
exec: (aiTable, field, origin, position) => {
|
1449
1491
|
const fieldService = AI_TABLE_GRID_FIELD_SERVICE_MAP.get(aiTable);
|
@@ -1464,16 +1506,17 @@ const EditFieldPropertyItem = {
|
|
1464
1506
|
}
|
1465
1507
|
return undefined;
|
1466
1508
|
}
|
1467
|
-
};
|
1468
|
-
const CopyFieldPropertyItem = (addFieldFn) => {
|
1509
|
+
});
|
1510
|
+
const CopyFieldPropertyItem = (aiTable, addFieldFn) => {
|
1511
|
+
const name = getStateI18nTextByKey(aiTable, AITableStateI18nKey.copyField);
|
1469
1512
|
return {
|
1470
1513
|
type: 'copyFieldProperty',
|
1471
|
-
name
|
1514
|
+
name,
|
1472
1515
|
icon: 'copy',
|
1473
1516
|
exec: (aiTable, field) => {
|
1474
1517
|
const allFieldNames = (aiTable.fields() || []).map((item) => item.name);
|
1475
1518
|
const copyName = field().name;
|
1476
|
-
let newFieldName = generateCopyName(allFieldNames, copyName);
|
1519
|
+
let newFieldName = generateCopyName(aiTable, allFieldNames, copyName);
|
1477
1520
|
const fieldOptions = {
|
1478
1521
|
originId: field()._id,
|
1479
1522
|
isCopy: true,
|
@@ -1488,45 +1531,50 @@ const CopyFieldPropertyItem = (addFieldFn) => {
|
|
1488
1531
|
};
|
1489
1532
|
};
|
1490
1533
|
|
1491
|
-
const RemoveRecordsItem = {
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1534
|
+
const RemoveRecordsItem = (aiTable, actions) => {
|
1535
|
+
return {
|
1536
|
+
type: 'removeRecords',
|
1537
|
+
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.removeRecords),
|
1538
|
+
icon: 'trash',
|
1539
|
+
exec: (aiTable, targetName, position, aiTableGridSelectionService) => {
|
1540
|
+
let selectedRecordIds = AITable.getActiveRecordIds(aiTable);
|
1541
|
+
selectedRecordIds.forEach((id) => {
|
1542
|
+
Actions.removeRecord(aiTable, [id]);
|
1543
|
+
});
|
1544
|
+
aiTableGridSelectionService.clearSelection();
|
1545
|
+
}
|
1546
|
+
};
|
1502
1547
|
};
|
1503
|
-
const CopyCellsItem = {
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1548
|
+
const CopyCellsItem = (aiTable, actions) => {
|
1549
|
+
return {
|
1550
|
+
type: 'copyCells',
|
1551
|
+
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.copy),
|
1552
|
+
shortcutKey: isMac() ? `⌘ + C` : `Ctrl + C`,
|
1553
|
+
icon: 'copy',
|
1554
|
+
exec: (aiTable, targetName, position, aiTableGridSelectionService, notifyService) => {
|
1555
|
+
const clipboardData = buildClipboardData(aiTable);
|
1556
|
+
if (clipboardData) {
|
1557
|
+
writeToClipboard(clipboardData).then(() => {
|
1558
|
+
const copiedCellsCount = aiTable.selection().selectedCells.size;
|
1559
|
+
const message = getI18nTextByKey(aiTable, AITableGridI18nKey.copiedCells).replace('{count}', copiedCellsCount.toString());
|
1560
|
+
notifyService.success(message, undefined, {
|
1561
|
+
placement: 'bottomLeft'
|
1562
|
+
});
|
1515
1563
|
});
|
1516
|
-
}
|
1564
|
+
}
|
1517
1565
|
}
|
1518
|
-
}
|
1566
|
+
};
|
1519
1567
|
};
|
1520
|
-
const PasteCellsItem = (actions) => {
|
1568
|
+
const PasteCellsItem = (aiTable, actions) => {
|
1521
1569
|
return {
|
1522
1570
|
type: 'pasteCells',
|
1523
|
-
name:
|
1571
|
+
name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.paste),
|
1524
1572
|
shortcutKey: isMac() ? `⌘ + V` : `Ctrl + V`,
|
1525
1573
|
icon: 'paste',
|
1526
1574
|
exec: async (aiTable, targetName, position, aiTableGridSelectionService, notifyService) => {
|
1527
1575
|
writeToAITable(aiTable, actions).then((isPasteSuccess) => {
|
1528
1576
|
if (!isPasteSuccess) {
|
1529
|
-
notifyService.error(
|
1577
|
+
notifyService.error(getStateI18nTextByKey(aiTable, AITableStateI18nKey.invalidPasteContent), undefined, {
|
1530
1578
|
placement: 'bottomLeft'
|
1531
1579
|
});
|
1532
1580
|
}
|
@@ -1541,5 +1589,5 @@ const VIEW_ACTIONS = [ActionName.SetView, ActionName.AddView, ActionName.RemoveV
|
|
1541
1589
|
* Generated bundle index. Do not edit.
|
1542
1590
|
*/
|
1543
1591
|
|
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 };
|
1592
|
+
export { AITableFilterLogical, AITableStateI18nKey, 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, getDefaultI18nTextByKey, getDefaultRecordDataByFilter, getDefaultRecordValues, getFieldPositionInView, getFilteredRecords, getIdBySystemFieldValues, getIdBySystemFieldValuesType, getMaxPosition, getPosition, getPositionsByRecordSyncElement, getPositionsBySystemFieldValues, getRecordsBySharedJson, getShareTypeNumberPath, getSharedMapValueId, getSharedMapValueIndex, getSharedRecord, getSharedRecordId, getSharedRecordIndex, getSharedTypeByData, getShortIdBySystemFieldValues, getSortFields, getSortRecords, getStateI18nTextByKey, getSystemFieldValues, getTrackableEntityBySystemFieldValues, getValuesByCustomFieldValues, isPathEqual, moveFields, removeView, setRecordPositions$1 as setRecordPositions, setRecordUpdatedInfo, sortByViewPosition, sortRecordsBySortInfo, toRecordSyncElement, toSharedType, toSyncElement, translatePositionToPath, translateYjsEvent, updateFieldValue, updateRecordsUpdatedInfo, withState };
|
1545
1593
|
//# sourceMappingURL=ai-table-state.mjs.map
|