@ai-table/state 0.4.0 → 0.4.2

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.
@@ -2,6 +2,7 @@ import { AITable, AITableContextMenuItem, AITableActions } from '@ai-table/grid'
2
2
  export declare const RemoveRecordsItem: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
3
3
  export declare const InsertUpwardRecords: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
4
4
  export declare const InsertDownwardRecords: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
5
+ export declare const CopyRecords: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
5
6
  export declare const CopyCellsItem: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
6
7
  export declare const PasteCellsItem: (aiTable: AITable, actions: AITableActions) => AITableContextMenuItem;
7
8
  //# sourceMappingURL=context-menu-item.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context-menu-item.d.ts","sourceRoot":"","sources":["../../../packages/state/src/constants/context-menu-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAyB,MAAM,gBAAgB,CAAC;AAOxG,eAAO,MAAM,iBAAiB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAa7E,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAsB/E,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAsBjF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAiBzE,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,KAAK,sBAoB3E,CAAC"}
1
+ {"version":3,"file":"context-menu-item.d.ts","sourceRoot":"","sources":["../../../packages/state/src/constants/context-menu-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAyB,MAAM,gBAAgB,CAAC;AAOxG,eAAO,MAAM,iBAAiB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAa7E,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAsB/E,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAsBjF,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAcvE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,OAAO,EAAE,SAAS,cAAc,KAAG,sBAiBzE,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,KAAK,sBAoB3E,CAAC"}
@@ -1326,6 +1326,7 @@ var AITableStateI18nKey;
1326
1326
  AITableStateI18nKey["pasteOverMaxFields"] = "pasteOverMaxFields";
1327
1327
  AITableStateI18nKey["insertUpward"] = "insertUpward";
1328
1328
  AITableStateI18nKey["insertDownward"] = "insertDownward";
1329
+ AITableStateI18nKey["copyRecords"] = "copyRecords";
1329
1330
  AITableStateI18nKey["upward"] = "upward";
1330
1331
  AITableStateI18nKey["downward"] = "downward";
1331
1332
  AITableStateI18nKey["freezeToThisColumn"] = "freezeToThisColumn";
@@ -1345,6 +1346,7 @@ const AITableStateI18nText = {
1345
1346
  [AITableStateI18nKey.pasteOverMaxFields]: '粘贴数据超过最大列数',
1346
1347
  [AITableStateI18nKey.insertUpward]: '向上插入',
1347
1348
  [AITableStateI18nKey.insertDownward]: '向下插入',
1349
+ [AITableStateI18nKey.copyRecords]: '复制行',
1348
1350
  [AITableStateI18nKey.upward]: '行',
1349
1351
  [AITableStateI18nKey.downward]: '行',
1350
1352
  [AITableStateI18nKey.freezeToThisColumn]: '冻结至此列',
@@ -1857,6 +1859,31 @@ function addRecords(aiTable, options, recordCreatedInfo) {
1857
1859
  activeCell: [activeRecordId, activeFieldId]
1858
1860
  });
1859
1861
  }
1862
+ function copyRecords(aiTable, options, recordCreatedInfo) {
1863
+ const newRecords = [];
1864
+ (options.recordIds || []).forEach((recordId) => {
1865
+ const record = aiTable.recordsMap()[recordId];
1866
+ if (record) {
1867
+ newRecords.push({
1868
+ ...record,
1869
+ ...recordCreatedInfo,
1870
+ _id: idCreator(),
1871
+ short_id: shortIdCreator()
1872
+ });
1873
+ }
1874
+ });
1875
+ Actions.addRecords(aiTable, newRecords, options);
1876
+ const recentAddRecord = newRecords[0];
1877
+ const activeRecordId = recentAddRecord._id;
1878
+ const activeFieldId = aiTable.gridData().fields[0]._id;
1879
+ closeExpendCell(aiTable);
1880
+ setSelection(aiTable, {
1881
+ selectedRecords: new Set([]),
1882
+ selectedFields: new Set([]),
1883
+ selectedCells: new Set([`${activeRecordId}:${activeFieldId}`]),
1884
+ activeCell: [activeRecordId, activeFieldId]
1885
+ });
1886
+ }
1860
1887
  function getDefaultRecordValues(aiTable, isDuplicate = false, recordId) {
1861
1888
  let newRecordValues = {};
1862
1889
  if (isDuplicate && recordId) {
@@ -2616,6 +2643,21 @@ const InsertDownwardRecords = (aiTable, actions) => {
2616
2643
  }
2617
2644
  };
2618
2645
  };
2646
+ const CopyRecords = (aiTable, actions) => {
2647
+ return {
2648
+ type: 'copyRecords',
2649
+ name: getStateI18nTextByKey(aiTable, AITableStateI18nKey.copyRecords),
2650
+ icon: 'copy',
2651
+ exec: (aiTable, targetName, position) => {
2652
+ let selectedRecordIds = AITable.getActiveRecordIds(aiTable);
2653
+ const copyRecordOptions = {
2654
+ afterRecordId: selectedRecordIds[selectedRecordIds.length - 1],
2655
+ recordIds: selectedRecordIds
2656
+ };
2657
+ actions.copyRecords(copyRecordOptions);
2658
+ }
2659
+ };
2660
+ };
2619
2661
  const CopyCellsItem = (aiTable, actions) => {
2620
2662
  return {
2621
2663
  type: 'copyCells',
@@ -2655,5 +2697,5 @@ const VIEW_ACTIONS = [ActionName.SetView, ActionName.AddView, ActionName.RemoveV
2655
2697
  * Generated bundle index. Do not edit.
2656
2698
  */
2657
2699
 
2658
- export { AITableStateI18nKey, AITableStateI18nText, Actions, CopyCellsItem, CopyFieldPropertyItem, DEFAULT_INITIAL_GAP, DEFAULT_PRECISION_THRESHOLD, DividerMenuItem, EditFieldPropertyItem, FLUSHING, GroupCalculator, InsertDownwardRecords, InsertUpwardRecords, PasteCellsItem, RemoveRecordsItem, UndoManagerService, VIEW_ACTIONS, YjsAITable, actionMappers, addFields, addRecords, addView, applyActionOps, applyActions, applyEvents, applyYjsEvents, buildFieldsByView, buildLinearRows, buildRecordsByView, buildRecordsWithWillMoveRecords, buildRemoveFieldItem, buildSetFieldAction, buildSetRecordPositionsAction, buildSorts, calculateAdaptiveFrozenColumnCount, checkConditions, createMultiplePositions, createPositions, createSharedType, doFilter, freezeToThisColumn, generateCopyName, getDataBySharedType, getDefaultI18nTextByKey, getDefaultRecordDataByFilter, getDefaultRecordValues, getFieldPositionInView, getFilteredRecords, getFrozenFieldId, getGroupRecordLength, getMaxPosition, getParentGroupValuesByGroupId, getParentLinearRowGroups, getPosition, getPositions, getPrevRecordIdByAddGroupId, getRecordsBySharedJson, getSharedTypeByData, getSortFields, getStateI18nTextByKey, insertAtEnd, insertAtStart, insertBetween, isPathEqual, isSameParentGroup, mergeSorts, moveFields, moveRecords, removeView, restoreDefaultFrozenColumn, sortRecordsByConditions, sortViews, toSharedType, translateYjsEvent, updateFieldAndValues, updateFieldValues, withState };
2700
+ export { AITableStateI18nKey, AITableStateI18nText, Actions, CopyCellsItem, CopyFieldPropertyItem, CopyRecords, DEFAULT_INITIAL_GAP, DEFAULT_PRECISION_THRESHOLD, DividerMenuItem, EditFieldPropertyItem, FLUSHING, GroupCalculator, InsertDownwardRecords, InsertUpwardRecords, PasteCellsItem, RemoveRecordsItem, UndoManagerService, VIEW_ACTIONS, YjsAITable, actionMappers, addFields, addRecords, addView, applyActionOps, applyActions, applyEvents, applyYjsEvents, buildFieldsByView, buildLinearRows, buildRecordsByView, buildRecordsWithWillMoveRecords, buildRemoveFieldItem, buildSetFieldAction, buildSetRecordPositionsAction, buildSorts, calculateAdaptiveFrozenColumnCount, checkConditions, copyRecords, createMultiplePositions, createPositions, createSharedType, doFilter, freezeToThisColumn, generateCopyName, getDataBySharedType, getDefaultI18nTextByKey, getDefaultRecordDataByFilter, getDefaultRecordValues, getFieldPositionInView, getFilteredRecords, getFrozenFieldId, getGroupRecordLength, getMaxPosition, getParentGroupValuesByGroupId, getParentLinearRowGroups, getPosition, getPositions, getPrevRecordIdByAddGroupId, getRecordsBySharedJson, getSharedTypeByData, getSortFields, getStateI18nTextByKey, insertAtEnd, insertAtStart, insertBetween, isPathEqual, isSameParentGroup, mergeSorts, moveFields, moveRecords, removeView, restoreDefaultFrozenColumn, sortRecordsByConditions, sortViews, toSharedType, translateYjsEvent, updateFieldAndValues, updateFieldValues, withState };
2659
2701
  //# sourceMappingURL=ai-table-state.mjs.map