@ai-table/state 0.4.9 → 0.5.0

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.
@@ -3,7 +3,7 @@ import { UndoManager } from 'yjs';
3
3
  import { getShareTypeNumberPath, ActionName, translateArrayEvent, getSharedRecordIndex, getSharedMapValueIndex, toMapSyncElement, getIdBySystemFieldValuesType, setRecordUpdatedInfo, getPositionsByRecordSyncElement, setRecordPositions as setRecordPositions$1, toRecordSyncElement, AI_TABLE_CONTENT_FIELD_NAME, getValuesByCustomFieldValues, getPositionsBySystemFieldValues, getTrackableEntityBySystemFieldValues, getShortIdBySystemFieldValues, getIdBySystemFieldValues, AITableFilterLogical, AITableFilterOperation, AITableFieldType, isEmpty, sortByViewPosition, idCreator, AI_TABLE_DEFAULT_MIN_UNFROZEN_WIDTH, AI_TABLE_MIN_FROZEN_COLUMN_COUNT } from '@ai-table/utils';
4
4
  import * as i0 from '@angular/core';
5
5
  import { signal, Injectable } from '@angular/core';
6
- import { FieldModelMap, AITableQueries, isSystemField, AITableRowType, shortIdCreator, generateNewName, idsCreator, shortIdsCreator, closeExpendCell, setSelection, buildNormalLinearRows, AITable, getColumnIndicesSizeMap, getI18nTextByKey, AITableGridI18nKey, generateNewFieldName, AI_TABLE_GRID_FIELD_SERVICE_MAP, clearSelection, isMac } from '@ai-table/grid';
6
+ import { FieldModelMap, AITableQueries, isSystemField, AITableRowType, shortIdCreator, generateNewName, idsCreator, shortIdsCreator, closeExpendCell, setSelection, buildNormalLinearRows, AITable, getColumnIndicesSizeMap, getI18nTextByKey, AITableGridI18nKey, generateNewFieldName, AI_TABLE_GRID_FIELD_SERVICE_MAP, createDefaultField, clearSelection, isMac } from '@ai-table/grid';
7
7
  import { nanoid } from 'nanoid';
8
8
  import * as _ from 'lodash';
9
9
  import ___default, { map, unionBy } from 'lodash';
@@ -1331,6 +1331,8 @@ var AITableStateI18nKey;
1331
1331
  AITableStateI18nKey["downward"] = "downward";
1332
1332
  AITableStateI18nKey["freezeToThisColumn"] = "freezeToThisColumn";
1333
1333
  AITableStateI18nKey["restoreDefaultFrozenColumn"] = "restoreDefaultFrozenColumn";
1334
+ AITableStateI18nKey["addFieldBefore"] = "addFieldBefore";
1335
+ AITableStateI18nKey["addFieldAfter"] = "addFieldAfter";
1334
1336
  })(AITableStateI18nKey || (AITableStateI18nKey = {}));
1335
1337
  const AITableStateI18nText = {
1336
1338
  [AITableStateI18nKey.copyField]: '复制列',
@@ -1350,7 +1352,9 @@ const AITableStateI18nText = {
1350
1352
  [AITableStateI18nKey.upward]: '行',
1351
1353
  [AITableStateI18nKey.downward]: '行',
1352
1354
  [AITableStateI18nKey.freezeToThisColumn]: '冻结至此列',
1353
- [AITableStateI18nKey.restoreDefaultFrozenColumn]: '恢复默认冻结列'
1355
+ [AITableStateI18nKey.restoreDefaultFrozenColumn]: '恢复默认冻结列',
1356
+ [AITableStateI18nKey.addFieldBefore]: '左侧插入列',
1357
+ [AITableStateI18nKey.addFieldAfter]: '右侧插入列'
1354
1358
  };
1355
1359
  const getDefaultI18nTextByKey = (key) => {
1356
1360
  return AITableStateI18nText[key] || key;
@@ -2440,7 +2444,13 @@ function addFields(aiTable, options) {
2440
2444
  newField._id = idCreator();
2441
2445
  }
2442
2446
  const viewPositionOptions = { count: options.count || 1 };
2443
- if (isDuplicate) {
2447
+ if (options.beforeItemId) {
2448
+ viewPositionOptions.beforeItemId = options.beforeItemId;
2449
+ }
2450
+ else if (options.afterItemId) {
2451
+ viewPositionOptions.afterItemId = options.afterItemId;
2452
+ }
2453
+ else if (isDuplicate) {
2444
2454
  viewPositionOptions.afterItemId = originId;
2445
2455
  }
2446
2456
  let positions = getNewItemsPosition(aiTable, viewPositionOptions, aiTable.fields(), aiTable.fieldsMap());
@@ -2582,6 +2592,92 @@ const CopyFieldPropertyItem = (aiTable, actions) => {
2582
2592
  }
2583
2593
  };
2584
2594
  };
2595
+ const AddFieldBeforeItem = (aiTable, actions, references) => {
2596
+ const name = getStateI18nTextByKey(aiTable, AITableStateI18nKey.addFieldBefore);
2597
+ return {
2598
+ type: 'addFieldBefore',
2599
+ name,
2600
+ icon: 'left-insert',
2601
+ exec: (aiTable, field, origin, position) => {
2602
+ const fields = aiTable.fields() || [];
2603
+ const maxFields = aiTable.context?.maxFields();
2604
+ if (maxFields && fields.length >= maxFields) {
2605
+ return;
2606
+ }
2607
+ const fieldService = AI_TABLE_GRID_FIELD_SERVICE_MAP.get(aiTable);
2608
+ const defaultField = createDefaultField(aiTable, AITableFieldType.text);
2609
+ const targetFieldId = field()._id;
2610
+ if (origin && position) {
2611
+ const popoverRef = fieldService?.editFieldProperty(aiTable, {
2612
+ field: defaultField,
2613
+ references,
2614
+ isUpdate: false,
2615
+ origin: origin,
2616
+ position
2617
+ });
2618
+ if (popoverRef && fieldService && !fieldService.aiFieldConfig?.fieldSettingComponent) {
2619
+ popoverRef.componentInstance.addField.subscribe((fieldValue) => {
2620
+ const fieldOptions = {
2621
+ beforeItemId: targetFieldId,
2622
+ defaultValue: fieldValue
2623
+ };
2624
+ actions.addField(fieldOptions);
2625
+ });
2626
+ }
2627
+ return popoverRef;
2628
+ }
2629
+ return undefined;
2630
+ },
2631
+ disabled: () => {
2632
+ const fieldLength = aiTable.fields()?.length || 0;
2633
+ const maxFields = aiTable.context?.maxFields();
2634
+ return maxFields ? fieldLength >= maxFields : false;
2635
+ }
2636
+ };
2637
+ };
2638
+ const AddFieldAfterItem = (aiTable, actions, references) => {
2639
+ const name = getStateI18nTextByKey(aiTable, AITableStateI18nKey.addFieldAfter);
2640
+ return {
2641
+ type: 'addFieldAfter',
2642
+ name,
2643
+ icon: 'right-insert',
2644
+ exec: (aiTable, field, origin, position) => {
2645
+ const fields = aiTable.fields() || [];
2646
+ const maxFields = aiTable.context?.maxFields();
2647
+ if (maxFields && fields.length >= maxFields) {
2648
+ return;
2649
+ }
2650
+ const fieldService = AI_TABLE_GRID_FIELD_SERVICE_MAP.get(aiTable);
2651
+ const defaultField = createDefaultField(aiTable, AITableFieldType.text);
2652
+ const targetFieldId = field()._id;
2653
+ if (origin && position) {
2654
+ const popoverRef = fieldService?.editFieldProperty(aiTable, {
2655
+ field: defaultField,
2656
+ references,
2657
+ isUpdate: false,
2658
+ origin: origin,
2659
+ position
2660
+ });
2661
+ if (popoverRef && fieldService && !fieldService.aiFieldConfig?.fieldSettingComponent) {
2662
+ popoverRef.componentInstance.addField.subscribe((fieldValue) => {
2663
+ const fieldOptions = {
2664
+ afterItemId: targetFieldId,
2665
+ defaultValue: fieldValue
2666
+ };
2667
+ actions.addField(fieldOptions);
2668
+ });
2669
+ }
2670
+ return popoverRef;
2671
+ }
2672
+ return undefined;
2673
+ },
2674
+ disabled: () => {
2675
+ const fieldLength = aiTable.fields()?.length || 0;
2676
+ const maxFields = aiTable.context?.maxFields();
2677
+ return maxFields ? fieldLength >= maxFields : false;
2678
+ }
2679
+ };
2680
+ };
2585
2681
 
2586
2682
  const RemoveRecordsItem = (aiTable, actions) => {
2587
2683
  return {
@@ -2697,5 +2793,5 @@ const VIEW_ACTIONS = [ActionName.SetView, ActionName.AddView, ActionName.RemoveV
2697
2793
  * Generated bundle index. Do not edit.
2698
2794
  */
2699
2795
 
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 };
2796
+ export { AITableStateI18nKey, AITableStateI18nText, Actions, AddFieldAfterItem, AddFieldBeforeItem, 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 };
2701
2797
  //# sourceMappingURL=ai-table-state.mjs.map