@ai-table/state 0.0.40 → 0.0.42

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.
@@ -1,6 +1,6 @@
1
1
  import * as Y from 'yjs';
2
2
  import { isArray } from 'ngx-tethys/util';
3
- import { AITableQueries, ViewOperationMap, AITableFilterOperation, AITableFieldType, isSystemField, isEmpty, getDefaultFieldValue, Direction as Direction$1, idsCreator, idCreator, shortIdCreator, shortIdsCreator, AI_TABLE_GRID_FIELD_SERVICE_MAP, AITable } from '@ai-table/grid';
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';
4
4
  import { createDraft, finishDraft } from 'immer';
5
5
  import * as _ from 'lodash';
6
6
  import ___default from 'lodash';
@@ -725,7 +725,7 @@ function sortRecordsBySortInfo(aiTable, records, activeView, sortKeysMap) {
725
725
  if (!field || acc !== 0) {
726
726
  return acc;
727
727
  }
728
- const fieldMethod = ViewOperationMap[field.type];
728
+ const fieldMethod = FieldModelMap[field.type];
729
729
  const sortKey = sortKeysMap?.[field.type];
730
730
  const cellValue1 = AITableQueries.getFieldValue(aiTable, [prev._id, field._id]);
731
731
  const cellValue2 = AITableQueries.getFieldValue(aiTable, [current._id, field._id]);
@@ -782,7 +782,7 @@ function doFilterOperations(fields, record, condition) {
782
782
  }
783
783
  }
784
784
  function doFilter(condition, field, cellValue) {
785
- return ViewOperationMap[field.type].isMeetFilter(condition, cellValue);
785
+ return FieldModelMap[field.type].isMeetFilter(condition, cellValue);
786
786
  }
787
787
  function getDefaultRecordDataByFilter(recordValues, conditions, fields, conditionLogical) {
788
788
  const fieldMap = new Map(fields.map((field) => [field._id, field]));
@@ -796,8 +796,8 @@ function getDefaultRecordDataByFilter(recordValues, conditions, fields, conditio
796
796
  conditions.forEach((condition) => {
797
797
  if (conditionFieldCountMap.get(condition.field_id.toString()) === 1) {
798
798
  const field = fieldMap.get(condition.field_id.toString());
799
- const canMultipleOperationCondition = (!field.settings.is_multiple && condition.operation === AITableFilterOperation.eq) ||
800
- field.settings.is_multiple;
799
+ const canMultipleOperationCondition = (!field.settings?.is_multiple && condition.operation === AITableFilterOperation.eq) ||
800
+ field?.settings?.is_multiple;
801
801
  if ([AITableFilterOperation.eq, AITableFilterOperation.in].includes(condition.operation) &&
802
802
  [AITableFieldType.select, AITableFieldType.member].includes(field?.type) &&
803
803
  canMultipleOperationCondition) {
@@ -866,12 +866,14 @@ function addField(aiTable, field, path, originId, isCopy) {
866
866
  aiTable.apply(operation);
867
867
  }
868
868
  function moveField(aiTable, path, newPath) {
869
- const operation = {
870
- type: ActionName.MoveField,
871
- path,
872
- newPath
873
- };
874
- aiTable.apply(operation);
869
+ if (isPathEqual(path, newPath)) {
870
+ return;
871
+ }
872
+ const fields = aiTable.gridData().fields;
873
+ const activeView = aiTable.views().find((item) => item._id === aiTable.activeViewId());
874
+ const sourceField = fields[path[0]];
875
+ const position = getFieldPositionInView(activeView._id, fields, path, newPath);
876
+ setField(aiTable, { positions: { ...sourceField.positions, [activeView._id]: position } }, [sourceField._id]);
875
877
  }
876
878
  function removeField(aiTable, path) {
877
879
  const operation = {
@@ -972,15 +974,6 @@ const apply = (aiTable, records, fields, views, action) => {
972
974
  records.splice(action.newPath[0], 0, record);
973
975
  break;
974
976
  }
975
- case ActionName.MoveField: {
976
- if (isPathEqual(action.path, action.newPath)) {
977
- return;
978
- }
979
- const field = fields[action.path[0]];
980
- fields.splice(action.path[0], 1);
981
- fields.splice(action.newPath[0], 0, field);
982
- break;
983
- }
984
977
  case ActionName.RemoveField: {
985
978
  const [fieldId] = action.path;
986
979
  const fieldIndex = aiTable.fields().findIndex((item) => item._id === fieldId);
@@ -1086,7 +1079,7 @@ const apply = (aiTable, records, fields, views, action) => {
1086
1079
  const GeneralActions = {
1087
1080
  transform(aiTable, action) {
1088
1081
  const records = createDraft(aiTable.records());
1089
- const fields = createDraft(aiTable.fields());
1082
+ const fields = createDraft(aiTable.gridData().fields);
1090
1083
  const views = createDraft(aiTable.views());
1091
1084
  apply(aiTable, records, fields, views, action);
1092
1085
  aiTable.fields.set(finishDraft(fields));
@@ -1367,6 +1360,40 @@ function updateFieldValue(aiTable, options, updatedInfo) {
1367
1360
 
1368
1361
  const FLUSHING = new WeakMap();
1369
1362
 
1363
+ function moveFields(aiTable, options, updatedInfo) {
1364
+ const { path, newPath } = options;
1365
+ Actions.moveField(aiTable, path, newPath);
1366
+ }
1367
+ function getFieldPositionInView(viewId, fields, path, newPath) {
1368
+ const targetPosition = fields[newPath[0]].positions[viewId];
1369
+ let newPosition = 0;
1370
+ if (path[0] > newPath[0]) {
1371
+ const prevPath = newPath[0] - 1;
1372
+ if (prevPath > 0) {
1373
+ const targetPrevField = fields[prevPath];
1374
+ const targetPrevPosition = targetPrevField.positions[viewId];
1375
+ newPosition = (targetPosition + targetPrevPosition) / 2;
1376
+ }
1377
+ else {
1378
+ const firstField = fields[0];
1379
+ newPosition = firstField.positions[viewId] - 0.1;
1380
+ }
1381
+ }
1382
+ else {
1383
+ const nextPath = newPath[0] + 1;
1384
+ if (fields.length > nextPath) {
1385
+ const targetNextField = fields[nextPath];
1386
+ const targetNextPosition = targetNextField.positions[viewId];
1387
+ newPosition = (targetPosition + targetNextPosition) / 2;
1388
+ }
1389
+ else {
1390
+ const lastField = fields[fields.length - 1];
1391
+ newPosition = lastField.positions[viewId] + 1;
1392
+ }
1393
+ }
1394
+ return newPosition;
1395
+ }
1396
+
1370
1397
  const withState = (aiTable) => {
1371
1398
  const viewTable = aiTable;
1372
1399
  viewTable.actions = [];
@@ -1451,6 +1478,40 @@ const RemoveRecordsItem = {
1451
1478
  aiTableGridSelectionService.clearSelection();
1452
1479
  }
1453
1480
  };
1481
+ const CopyCellsItem = {
1482
+ type: 'copyCells',
1483
+ name: '复制',
1484
+ shortcutKey: isMac() ? `⌘ + C` : `Ctrl + C`,
1485
+ icon: 'copy',
1486
+ exec: (aiTable, targetName, position, aiTableGridSelectionService, notifyService) => {
1487
+ const clipboardData = buildClipboardData(aiTable);
1488
+ if (clipboardData) {
1489
+ writeToClipboard(clipboardData).then(() => {
1490
+ const copiedCellsCount = aiTable.selection().selectedCells.size;
1491
+ notifyService.success(`已复制 ${copiedCellsCount} 个单元格`, undefined, {
1492
+ placement: 'bottomLeft'
1493
+ });
1494
+ });
1495
+ }
1496
+ }
1497
+ };
1498
+ const PasteCellsItem = (actions) => {
1499
+ return {
1500
+ type: 'pasteCells',
1501
+ name: '粘贴',
1502
+ shortcutKey: isMac() ? `⌘ + V` : `Ctrl + V`,
1503
+ icon: 'paste',
1504
+ exec: async (aiTable, targetName, position, aiTableGridSelectionService, notifyService) => {
1505
+ writeToAITable(aiTable, actions).then((isPasteSuccess) => {
1506
+ if (!isPasteSuccess) {
1507
+ notifyService.error('粘贴内容不符合当前类型', undefined, {
1508
+ placement: 'bottomLeft'
1509
+ });
1510
+ }
1511
+ });
1512
+ }
1513
+ };
1514
+ };
1454
1515
 
1455
1516
  const VIEW_ACTIONS = [ActionName.SetView, ActionName.AddView, ActionName.RemoveView];
1456
1517
 
@@ -1458,5 +1519,5 @@ const VIEW_ACTIONS = [ActionName.SetView, ActionName.AddView, ActionName.RemoveV
1458
1519
  * Generated bundle index. Do not edit.
1459
1520
  */
1460
1521
 
1461
- export { AITableFilterLogical, AI_TABLE_CONTENT_FIELD_NAME, ActionName, Actions, CopyFieldPropertyItem, Direction, DividerMenuItem, EditFieldPropertyItem, ExecuteType, FLUSHING, Positions, RemovePositions, RemoveRecordsItem, SystemFieldIndex, VIEW_ACTIONS, 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, isPathEqual, removeView, setRecordPositions$1 as setRecordPositions, setRecordUpdatedInfo, sortByViewPosition, sortRecordsBySortInfo, toRecordSyncElement, toSharedType, toSyncElement, translatePositionToPath, translateYjsEvent, updateFieldValue, updateRecordsUpdatedInfo, withState };
1522
+ 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 };
1462
1523
  //# sourceMappingURL=ai-table-state.mjs.map