@univerjs/sheets-table 0.22.1 → 0.23.0-insiders.20260522-ee0b0a4

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/lib/cjs/index.js CHANGED
@@ -248,8 +248,8 @@ const tableDefaultThemeStyleArr = [
248
248
  [[
249
249
  "#6280F9",
250
250
  "#FFFFFF",
251
- "#BAC6F8",
252
- "#D2DAFA"
251
+ "#EEF2FF",
252
+ "#DCE4FF"
253
253
  ], ["#fff"]],
254
254
  [[
255
255
  "#16BDCA",
@@ -1839,7 +1839,8 @@ let TableManager = class TableManager extends _univerjs_core.Disposable {
1839
1839
  }
1840
1840
  } else if (newRange.endColumn > oldRange.endColumn) {
1841
1841
  const diff = newRange.endColumn - oldRange.endColumn;
1842
- for (let i = 0; i < diff; i++) table.insertColumn(oldRange.endColumn, new TableColumn((0, _univerjs_core.generateRandomId)(), getColumnName(table.getColumnsCount() + 1, "Column")));
1842
+ const columnPrefix = this._localeService.t("sheets-table.columnPrefix");
1843
+ for (let i = 0; i < diff; i++) table.insertColumn(oldRange.endColumn, new TableColumn((0, _univerjs_core.generateRandomId)(), getColumnName(table.getColumnsCount() + 1, columnPrefix)));
1843
1844
  }
1844
1845
  table.setRange(newRange);
1845
1846
  this._tableRangeChanged$.next({
@@ -1966,7 +1967,7 @@ let TableManager = class TableManager extends _univerjs_core.Disposable {
1966
1967
  TableManager = __decorate([__decorateParam(0, _univerjs_core.IUniverInstanceService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService))], TableManager);
1967
1968
 
1968
1969
  //#endregion
1969
- //#region src/services/table-service.ts
1970
+ //#region src/services/table.service.ts
1970
1971
  let SheetTableService = class SheetTableService extends _univerjs_core.Disposable {
1971
1972
  constructor(_tableManager) {
1972
1973
  super();
@@ -2305,6 +2306,37 @@ const RemoveTableThemeCommand = {
2305
2306
  }
2306
2307
  };
2307
2308
 
2309
+ //#endregion
2310
+ //#region src/util/table-name.ts
2311
+ /**
2312
+ * Copyright 2023-present DreamNum Co., Ltd.
2313
+ *
2314
+ * Licensed under the Apache License, Version 2.0 (the "License");
2315
+ * you may not use this file except in compliance with the License.
2316
+ * You may obtain a copy of the License at
2317
+ *
2318
+ * http://www.apache.org/licenses/LICENSE-2.0
2319
+ *
2320
+ * Unless required by applicable law or agreed to in writing, software
2321
+ * distributed under the License is distributed on an "AS IS" BASIS,
2322
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2323
+ * See the License for the specific language governing permissions and
2324
+ * limitations under the License.
2325
+ */
2326
+ function validateSheetTableName(name, existingNamesSet) {
2327
+ const trimmedName = name.trim();
2328
+ if (!trimmedName) return {
2329
+ valid: false,
2330
+ reason: "empty"
2331
+ };
2332
+ const normalizedExistingNames = new Set(Array.from(existingNamesSet, (item) => item.toLowerCase()));
2333
+ if (!(0, _univerjs_core.customNameCharacterCheck)(trimmedName.toLowerCase(), normalizedExistingNames)) return {
2334
+ valid: false,
2335
+ reason: "invalid"
2336
+ };
2337
+ return { valid: true };
2338
+ }
2339
+
2308
2340
  //#endregion
2309
2341
  //#region src/commands/commands/set-sheet-table.command.ts
2310
2342
  const SetSheetTableCommand = {
@@ -2325,7 +2357,7 @@ const SetSheetTableCommand = {
2325
2357
  definedNamesService: accessor.get(_univerjs_engine_formula.IDefinedNamesService)
2326
2358
  });
2327
2359
  if (name) {
2328
- if (!(0, _univerjs_core.customNameCharacterCheck)(name.toLowerCase(), existingNamesSet)) {
2360
+ if (!validateSheetTableName(name, existingNamesSet).valid) {
2329
2361
  accessor.get(_univerjs_core.ILogService).warn(localeService.t("sheets-table.tableNameError"));
2330
2362
  return false;
2331
2363
  }
@@ -2678,6 +2710,17 @@ SheetsTableController = __decorate([
2678
2710
 
2679
2711
  //#endregion
2680
2712
  //#region src/commands/commands/sheet-table-row-col.command.ts
2713
+ function executeTableMutationSequence(accessor, unitId, redos, undos) {
2714
+ if ((0, _univerjs_core.sequenceExecute)(redos, accessor.get(_univerjs_core.ICommandService)).result) {
2715
+ accessor.get(_univerjs_core.IUndoRedoService).pushUndoRedo({
2716
+ unitID: unitId,
2717
+ undoMutations: undos,
2718
+ redoMutations: redos
2719
+ });
2720
+ return true;
2721
+ }
2722
+ return false;
2723
+ }
2681
2724
  const SheetTableInsertRowCommand = {
2682
2725
  id: "sheet.command.table-insert-row",
2683
2726
  type: _univerjs_core.CommandType.COMMAND,
@@ -2792,6 +2835,70 @@ const SheetTableInsertRowCommand = {
2792
2835
  return false;
2793
2836
  }
2794
2837
  };
2838
+ const SheetTableInsertRowAtCommand = {
2839
+ id: "sheet.command.table-insert-row-at",
2840
+ type: _univerjs_core.CommandType.COMMAND,
2841
+ handler: (accessor, params) => {
2842
+ if (!params) return false;
2843
+ const { unitId, subUnitId, tableId, index, count = 1 } = params;
2844
+ if (count <= 0) return false;
2845
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
2846
+ unitId,
2847
+ subUnitId
2848
+ });
2849
+ if (!target) return false;
2850
+ const table = accessor.get(TableManager).getTableById(unitId, tableId);
2851
+ if (!table || table.getSubunitId() !== subUnitId) return false;
2852
+ const oldRange = table.getRange();
2853
+ if (index <= oldRange.startRow || index > oldRange.endRow + 1) return false;
2854
+ const redos = [{
2855
+ id: SetSheetTableMutation.id,
2856
+ params: {
2857
+ unitId,
2858
+ subUnitId,
2859
+ tableId,
2860
+ config: { updateRange: { newRange: {
2861
+ ...oldRange,
2862
+ endRow: oldRange.endRow + count
2863
+ } } }
2864
+ }
2865
+ }];
2866
+ const undos = [{
2867
+ id: SetSheetTableMutation.id,
2868
+ params: {
2869
+ unitId,
2870
+ subUnitId,
2871
+ tableId,
2872
+ config: { updateRange: { newRange: { ...oldRange } } }
2873
+ }
2874
+ }];
2875
+ const rowContentIndex = target.worksheet.getCellMatrix().getDataRange().endRow;
2876
+ const moveRangeMutations = (0, _univerjs_sheets.getMoveRangeUndoRedoMutations)(accessor, {
2877
+ unitId,
2878
+ subUnitId,
2879
+ range: {
2880
+ startRow: index,
2881
+ endRow: rowContentIndex,
2882
+ startColumn: oldRange.startColumn,
2883
+ endColumn: oldRange.endColumn
2884
+ }
2885
+ }, {
2886
+ unitId,
2887
+ subUnitId,
2888
+ range: {
2889
+ startRow: index + count,
2890
+ endRow: rowContentIndex + count,
2891
+ startColumn: oldRange.startColumn,
2892
+ endColumn: oldRange.endColumn
2893
+ }
2894
+ });
2895
+ if (moveRangeMutations) {
2896
+ redos.push(...moveRangeMutations.redos);
2897
+ undos.push(...moveRangeMutations.undos);
2898
+ }
2899
+ return executeTableMutationSequence(accessor, unitId, redos, undos);
2900
+ }
2901
+ };
2795
2902
  const SheetTableInsertColCommand = {
2796
2903
  id: "sheet.command.table-insert-col",
2797
2904
  type: _univerjs_core.CommandType.COMMAND,
@@ -2919,6 +3026,159 @@ const SheetTableInsertColCommand = {
2919
3026
  return false;
2920
3027
  }
2921
3028
  };
3029
+ const SheetTableInsertColumnAtCommand = {
3030
+ id: "sheet.command.table-insert-column-at",
3031
+ type: _univerjs_core.CommandType.COMMAND,
3032
+ handler: (accessor, params) => {
3033
+ if (!params) return false;
3034
+ const { unitId, subUnitId, tableId, index, count = 1 } = params;
3035
+ if (count <= 0) return false;
3036
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
3037
+ unitId,
3038
+ subUnitId
3039
+ });
3040
+ if (!target) return false;
3041
+ const table = accessor.get(TableManager).getTableById(unitId, tableId);
3042
+ if (!table || table.getSubunitId() !== subUnitId) return false;
3043
+ const oldRange = table.getRange();
3044
+ if (index < oldRange.startColumn || index > oldRange.endColumn + 1) return false;
3045
+ const redos = [{
3046
+ id: SetSheetTableMutation.id,
3047
+ params: {
3048
+ unitId,
3049
+ subUnitId,
3050
+ tableId,
3051
+ config: { rowColOperation: {
3052
+ operationType: "insert",
3053
+ rowColType: "column",
3054
+ index,
3055
+ count
3056
+ } }
3057
+ }
3058
+ }];
3059
+ const undos = [{
3060
+ id: SetSheetTableMutation.id,
3061
+ params: {
3062
+ unitId,
3063
+ subUnitId,
3064
+ tableId,
3065
+ config: { rowColOperation: {
3066
+ operationType: "delete",
3067
+ rowColType: "column",
3068
+ index,
3069
+ count
3070
+ } }
3071
+ }
3072
+ }];
3073
+ const colContentIndex = target.worksheet.getCellMatrix().getDataRange().endColumn;
3074
+ if (index <= colContentIndex) {
3075
+ const moveRangeMutations = (0, _univerjs_sheets.getMoveRangeUndoRedoMutations)(accessor, {
3076
+ unitId,
3077
+ subUnitId,
3078
+ range: {
3079
+ startRow: oldRange.startRow,
3080
+ endRow: oldRange.endRow,
3081
+ startColumn: index,
3082
+ endColumn: colContentIndex
3083
+ }
3084
+ }, {
3085
+ unitId,
3086
+ subUnitId,
3087
+ range: {
3088
+ startRow: oldRange.startRow,
3089
+ endRow: oldRange.endRow,
3090
+ startColumn: index + count,
3091
+ endColumn: colContentIndex + count
3092
+ }
3093
+ });
3094
+ if (moveRangeMutations) {
3095
+ redos.push(...moveRangeMutations.redos);
3096
+ undos.push(...moveRangeMutations.undos);
3097
+ }
3098
+ }
3099
+ return executeTableMutationSequence(accessor, unitId, redos, undos);
3100
+ }
3101
+ };
3102
+ const SheetTableRemoveColumnAtCommand = {
3103
+ id: "sheet.command.table-remove-column-at",
3104
+ type: _univerjs_core.CommandType.COMMAND,
3105
+ handler: (accessor, params) => {
3106
+ if (!params) return false;
3107
+ const { unitId, subUnitId, tableId, index, count = 1 } = params;
3108
+ if (count <= 0) return false;
3109
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
3110
+ unitId,
3111
+ subUnitId
3112
+ });
3113
+ if (!target) return false;
3114
+ const table = accessor.get(TableManager).getTableById(unitId, tableId);
3115
+ if (!table || table.getSubunitId() !== subUnitId) return false;
3116
+ const oldRange = table.getRange();
3117
+ if (index < oldRange.startColumn || index + count - 1 > oldRange.endColumn || count >= oldRange.endColumn - oldRange.startColumn + 1) return false;
3118
+ const columns = [];
3119
+ const gap = index - oldRange.startColumn;
3120
+ for (let i = 0; i < count; i++) {
3121
+ const column = table.getTableInfo().columns[gap + i];
3122
+ if (column) columns.push(column);
3123
+ }
3124
+ const redos = [{
3125
+ id: SetSheetTableMutation.id,
3126
+ params: {
3127
+ unitId,
3128
+ subUnitId,
3129
+ tableId,
3130
+ config: { rowColOperation: {
3131
+ operationType: "delete",
3132
+ rowColType: "column",
3133
+ index,
3134
+ count
3135
+ } }
3136
+ }
3137
+ }];
3138
+ const undos = [{
3139
+ id: SetSheetTableMutation.id,
3140
+ params: {
3141
+ unitId,
3142
+ subUnitId,
3143
+ tableId,
3144
+ config: { rowColOperation: {
3145
+ operationType: "insert",
3146
+ rowColType: "column",
3147
+ index,
3148
+ count,
3149
+ columnsJson: columns
3150
+ } }
3151
+ }
3152
+ }];
3153
+ const colContentIndex = target.worksheet.getCellMatrix().getDataRange().endColumn;
3154
+ if (index + count <= colContentIndex) {
3155
+ const moveRangeMutations = (0, _univerjs_sheets.getMoveRangeUndoRedoMutations)(accessor, {
3156
+ unitId,
3157
+ subUnitId,
3158
+ range: {
3159
+ startRow: oldRange.startRow,
3160
+ endRow: oldRange.endRow,
3161
+ startColumn: index + count,
3162
+ endColumn: colContentIndex
3163
+ }
3164
+ }, {
3165
+ unitId,
3166
+ subUnitId,
3167
+ range: {
3168
+ startRow: oldRange.startRow,
3169
+ endRow: oldRange.endRow,
3170
+ startColumn: index,
3171
+ endColumn: colContentIndex - count
3172
+ }
3173
+ });
3174
+ if (moveRangeMutations) {
3175
+ redos.push(...moveRangeMutations.redos);
3176
+ undos.push(...moveRangeMutations.undos);
3177
+ }
3178
+ }
3179
+ return executeTableMutationSequence(accessor, unitId, redos, undos);
3180
+ }
3181
+ };
2922
3182
  const SheetTableRemoveRowCommand = {
2923
3183
  id: "sheet.command.table-remove-row",
2924
3184
  type: _univerjs_core.CommandType.COMMAND,
@@ -3084,7 +3344,7 @@ const SheetTableRemoveColCommand = {
3084
3344
  //#endregion
3085
3345
  //#region package.json
3086
3346
  var name = "@univerjs/sheets-table";
3087
- var version = "0.22.1";
3347
+ var version = "0.23.0-insiders.20260522-ee0b0a4";
3088
3348
 
3089
3349
  //#endregion
3090
3350
  //#region src/controllers/sheet-table-formula.controller.ts
@@ -3889,8 +4149,11 @@ let UniverSheetsTablePlugin = class UniverSheetsTablePlugin extends _univerjs_co
3889
4149
  RemoveTableThemeCommand,
3890
4150
  SheetTableInsertRowCommand,
3891
4151
  SheetTableInsertColCommand,
4152
+ SheetTableInsertRowAtCommand,
4153
+ SheetTableInsertColumnAtCommand,
3892
4154
  SheetTableRemoveRowCommand,
3893
- SheetTableRemoveColCommand
4155
+ SheetTableRemoveColCommand,
4156
+ SheetTableRemoveColumnAtCommand
3894
4157
  ].forEach((m) => this._commandService.registerCommand(m));
3895
4158
  }
3896
4159
  };
@@ -3917,8 +4180,11 @@ exports.SetSheetTableFilterCommand = SetSheetTableFilterCommand;
3917
4180
  exports.SetSheetTableFilterMutation = SetSheetTableFilterMutation;
3918
4181
  exports.SetSheetTableMutation = SetSheetTableMutation;
3919
4182
  exports.SheetTableInsertColCommand = SheetTableInsertColCommand;
4183
+ exports.SheetTableInsertColumnAtCommand = SheetTableInsertColumnAtCommand;
4184
+ exports.SheetTableInsertRowAtCommand = SheetTableInsertRowAtCommand;
3920
4185
  exports.SheetTableInsertRowCommand = SheetTableInsertRowCommand;
3921
4186
  exports.SheetTableRemoveColCommand = SheetTableRemoveColCommand;
4187
+ exports.SheetTableRemoveColumnAtCommand = SheetTableRemoveColumnAtCommand;
3922
4188
  exports.SheetTableRemoveRowCommand = SheetTableRemoveRowCommand;
3923
4189
  Object.defineProperty(exports, 'SheetTableService', {
3924
4190
  enumerable: true,
@@ -3953,6 +4219,8 @@ Object.defineProperty(exports, 'UniverSheetsTablePlugin', {
3953
4219
  }
3954
4220
  });
3955
4221
  exports.customEmptyThemeWithBorderStyle = customEmptyThemeWithBorderStyle;
4222
+ exports.getExistingNamesSet = getExistingNamesSet;
3956
4223
  exports.isConditionFilter = isConditionFilter;
3957
4224
  exports.isManualTableFilter = isManualTableFilter;
3958
- exports.processStyleWithBorderStyle = processStyleWithBorderStyle;
4225
+ exports.processStyleWithBorderStyle = processStyleWithBorderStyle;
4226
+ exports.validateSheetTableName = validateSheetTableName;