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

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/index.js CHANGED
@@ -247,8 +247,8 @@ const tableDefaultThemeStyleArr = [
247
247
  [[
248
248
  "#6280F9",
249
249
  "#FFFFFF",
250
- "#BAC6F8",
251
- "#D2DAFA"
250
+ "#EEF2FF",
251
+ "#DCE4FF"
252
252
  ], ["#fff"]],
253
253
  [[
254
254
  "#16BDCA",
@@ -1838,7 +1838,8 @@ let TableManager = class TableManager extends Disposable {
1838
1838
  }
1839
1839
  } else if (newRange.endColumn > oldRange.endColumn) {
1840
1840
  const diff = newRange.endColumn - oldRange.endColumn;
1841
- for (let i = 0; i < diff; i++) table.insertColumn(oldRange.endColumn, new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1, "Column")));
1841
+ const columnPrefix = this._localeService.t("sheets-table.columnPrefix");
1842
+ for (let i = 0; i < diff; i++) table.insertColumn(oldRange.endColumn, new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1, columnPrefix)));
1842
1843
  }
1843
1844
  table.setRange(newRange);
1844
1845
  this._tableRangeChanged$.next({
@@ -2304,6 +2305,37 @@ const RemoveTableThemeCommand = {
2304
2305
  }
2305
2306
  };
2306
2307
 
2308
+ //#endregion
2309
+ //#region src/util/table-name.ts
2310
+ /**
2311
+ * Copyright 2023-present DreamNum Co., Ltd.
2312
+ *
2313
+ * Licensed under the Apache License, Version 2.0 (the "License");
2314
+ * you may not use this file except in compliance with the License.
2315
+ * You may obtain a copy of the License at
2316
+ *
2317
+ * http://www.apache.org/licenses/LICENSE-2.0
2318
+ *
2319
+ * Unless required by applicable law or agreed to in writing, software
2320
+ * distributed under the License is distributed on an "AS IS" BASIS,
2321
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2322
+ * See the License for the specific language governing permissions and
2323
+ * limitations under the License.
2324
+ */
2325
+ function validateSheetTableName(name, existingNamesSet) {
2326
+ const trimmedName = name.trim();
2327
+ if (!trimmedName) return {
2328
+ valid: false,
2329
+ reason: "empty"
2330
+ };
2331
+ const normalizedExistingNames = new Set(Array.from(existingNamesSet, (item) => item.toLowerCase()));
2332
+ if (!customNameCharacterCheck(trimmedName.toLowerCase(), normalizedExistingNames)) return {
2333
+ valid: false,
2334
+ reason: "invalid"
2335
+ };
2336
+ return { valid: true };
2337
+ }
2338
+
2307
2339
  //#endregion
2308
2340
  //#region src/commands/commands/set-sheet-table.command.ts
2309
2341
  const SetSheetTableCommand = {
@@ -2324,7 +2356,7 @@ const SetSheetTableCommand = {
2324
2356
  definedNamesService: accessor.get(IDefinedNamesService)
2325
2357
  });
2326
2358
  if (name) {
2327
- if (!customNameCharacterCheck(name.toLowerCase(), existingNamesSet)) {
2359
+ if (!validateSheetTableName(name, existingNamesSet).valid) {
2328
2360
  accessor.get(ILogService).warn(localeService.t("sheets-table.tableNameError"));
2329
2361
  return false;
2330
2362
  }
@@ -2677,6 +2709,17 @@ SheetsTableController = __decorate([
2677
2709
 
2678
2710
  //#endregion
2679
2711
  //#region src/commands/commands/sheet-table-row-col.command.ts
2712
+ function executeTableMutationSequence(accessor, unitId, redos, undos) {
2713
+ if (sequenceExecute(redos, accessor.get(ICommandService)).result) {
2714
+ accessor.get(IUndoRedoService).pushUndoRedo({
2715
+ unitID: unitId,
2716
+ undoMutations: undos,
2717
+ redoMutations: redos
2718
+ });
2719
+ return true;
2720
+ }
2721
+ return false;
2722
+ }
2680
2723
  const SheetTableInsertRowCommand = {
2681
2724
  id: "sheet.command.table-insert-row",
2682
2725
  type: CommandType.COMMAND,
@@ -2791,6 +2834,70 @@ const SheetTableInsertRowCommand = {
2791
2834
  return false;
2792
2835
  }
2793
2836
  };
2837
+ const SheetTableInsertRowAtCommand = {
2838
+ id: "sheet.command.table-insert-row-at",
2839
+ type: CommandType.COMMAND,
2840
+ handler: (accessor, params) => {
2841
+ if (!params) return false;
2842
+ const { unitId, subUnitId, tableId, index, count = 1 } = params;
2843
+ if (count <= 0) return false;
2844
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), {
2845
+ unitId,
2846
+ subUnitId
2847
+ });
2848
+ if (!target) return false;
2849
+ const table = accessor.get(TableManager).getTableById(unitId, tableId);
2850
+ if (!table || table.getSubunitId() !== subUnitId) return false;
2851
+ const oldRange = table.getRange();
2852
+ if (index <= oldRange.startRow || index > oldRange.endRow + 1) return false;
2853
+ const redos = [{
2854
+ id: SetSheetTableMutation.id,
2855
+ params: {
2856
+ unitId,
2857
+ subUnitId,
2858
+ tableId,
2859
+ config: { updateRange: { newRange: {
2860
+ ...oldRange,
2861
+ endRow: oldRange.endRow + count
2862
+ } } }
2863
+ }
2864
+ }];
2865
+ const undos = [{
2866
+ id: SetSheetTableMutation.id,
2867
+ params: {
2868
+ unitId,
2869
+ subUnitId,
2870
+ tableId,
2871
+ config: { updateRange: { newRange: { ...oldRange } } }
2872
+ }
2873
+ }];
2874
+ const rowContentIndex = target.worksheet.getCellMatrix().getDataRange().endRow;
2875
+ const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
2876
+ unitId,
2877
+ subUnitId,
2878
+ range: {
2879
+ startRow: index,
2880
+ endRow: rowContentIndex,
2881
+ startColumn: oldRange.startColumn,
2882
+ endColumn: oldRange.endColumn
2883
+ }
2884
+ }, {
2885
+ unitId,
2886
+ subUnitId,
2887
+ range: {
2888
+ startRow: index + count,
2889
+ endRow: rowContentIndex + count,
2890
+ startColumn: oldRange.startColumn,
2891
+ endColumn: oldRange.endColumn
2892
+ }
2893
+ });
2894
+ if (moveRangeMutations) {
2895
+ redos.push(...moveRangeMutations.redos);
2896
+ undos.push(...moveRangeMutations.undos);
2897
+ }
2898
+ return executeTableMutationSequence(accessor, unitId, redos, undos);
2899
+ }
2900
+ };
2794
2901
  const SheetTableInsertColCommand = {
2795
2902
  id: "sheet.command.table-insert-col",
2796
2903
  type: CommandType.COMMAND,
@@ -2918,6 +3025,159 @@ const SheetTableInsertColCommand = {
2918
3025
  return false;
2919
3026
  }
2920
3027
  };
3028
+ const SheetTableInsertColumnAtCommand = {
3029
+ id: "sheet.command.table-insert-column-at",
3030
+ type: CommandType.COMMAND,
3031
+ handler: (accessor, params) => {
3032
+ if (!params) return false;
3033
+ const { unitId, subUnitId, tableId, index, count = 1 } = params;
3034
+ if (count <= 0) return false;
3035
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), {
3036
+ unitId,
3037
+ subUnitId
3038
+ });
3039
+ if (!target) return false;
3040
+ const table = accessor.get(TableManager).getTableById(unitId, tableId);
3041
+ if (!table || table.getSubunitId() !== subUnitId) return false;
3042
+ const oldRange = table.getRange();
3043
+ if (index < oldRange.startColumn || index > oldRange.endColumn + 1) return false;
3044
+ const redos = [{
3045
+ id: SetSheetTableMutation.id,
3046
+ params: {
3047
+ unitId,
3048
+ subUnitId,
3049
+ tableId,
3050
+ config: { rowColOperation: {
3051
+ operationType: "insert",
3052
+ rowColType: "column",
3053
+ index,
3054
+ count
3055
+ } }
3056
+ }
3057
+ }];
3058
+ const undos = [{
3059
+ id: SetSheetTableMutation.id,
3060
+ params: {
3061
+ unitId,
3062
+ subUnitId,
3063
+ tableId,
3064
+ config: { rowColOperation: {
3065
+ operationType: "delete",
3066
+ rowColType: "column",
3067
+ index,
3068
+ count
3069
+ } }
3070
+ }
3071
+ }];
3072
+ const colContentIndex = target.worksheet.getCellMatrix().getDataRange().endColumn;
3073
+ if (index <= colContentIndex) {
3074
+ const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
3075
+ unitId,
3076
+ subUnitId,
3077
+ range: {
3078
+ startRow: oldRange.startRow,
3079
+ endRow: oldRange.endRow,
3080
+ startColumn: index,
3081
+ endColumn: colContentIndex
3082
+ }
3083
+ }, {
3084
+ unitId,
3085
+ subUnitId,
3086
+ range: {
3087
+ startRow: oldRange.startRow,
3088
+ endRow: oldRange.endRow,
3089
+ startColumn: index + count,
3090
+ endColumn: colContentIndex + count
3091
+ }
3092
+ });
3093
+ if (moveRangeMutations) {
3094
+ redos.push(...moveRangeMutations.redos);
3095
+ undos.push(...moveRangeMutations.undos);
3096
+ }
3097
+ }
3098
+ return executeTableMutationSequence(accessor, unitId, redos, undos);
3099
+ }
3100
+ };
3101
+ const SheetTableRemoveColumnAtCommand = {
3102
+ id: "sheet.command.table-remove-column-at",
3103
+ type: CommandType.COMMAND,
3104
+ handler: (accessor, params) => {
3105
+ if (!params) return false;
3106
+ const { unitId, subUnitId, tableId, index, count = 1 } = params;
3107
+ if (count <= 0) return false;
3108
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), {
3109
+ unitId,
3110
+ subUnitId
3111
+ });
3112
+ if (!target) return false;
3113
+ const table = accessor.get(TableManager).getTableById(unitId, tableId);
3114
+ if (!table || table.getSubunitId() !== subUnitId) return false;
3115
+ const oldRange = table.getRange();
3116
+ if (index < oldRange.startColumn || index + count - 1 > oldRange.endColumn || count >= oldRange.endColumn - oldRange.startColumn + 1) return false;
3117
+ const columns = [];
3118
+ const gap = index - oldRange.startColumn;
3119
+ for (let i = 0; i < count; i++) {
3120
+ const column = table.getTableInfo().columns[gap + i];
3121
+ if (column) columns.push(column);
3122
+ }
3123
+ const redos = [{
3124
+ id: SetSheetTableMutation.id,
3125
+ params: {
3126
+ unitId,
3127
+ subUnitId,
3128
+ tableId,
3129
+ config: { rowColOperation: {
3130
+ operationType: "delete",
3131
+ rowColType: "column",
3132
+ index,
3133
+ count
3134
+ } }
3135
+ }
3136
+ }];
3137
+ const undos = [{
3138
+ id: SetSheetTableMutation.id,
3139
+ params: {
3140
+ unitId,
3141
+ subUnitId,
3142
+ tableId,
3143
+ config: { rowColOperation: {
3144
+ operationType: "insert",
3145
+ rowColType: "column",
3146
+ index,
3147
+ count,
3148
+ columnsJson: columns
3149
+ } }
3150
+ }
3151
+ }];
3152
+ const colContentIndex = target.worksheet.getCellMatrix().getDataRange().endColumn;
3153
+ if (index + count <= colContentIndex) {
3154
+ const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
3155
+ unitId,
3156
+ subUnitId,
3157
+ range: {
3158
+ startRow: oldRange.startRow,
3159
+ endRow: oldRange.endRow,
3160
+ startColumn: index + count,
3161
+ endColumn: colContentIndex
3162
+ }
3163
+ }, {
3164
+ unitId,
3165
+ subUnitId,
3166
+ range: {
3167
+ startRow: oldRange.startRow,
3168
+ endRow: oldRange.endRow,
3169
+ startColumn: index,
3170
+ endColumn: colContentIndex - count
3171
+ }
3172
+ });
3173
+ if (moveRangeMutations) {
3174
+ redos.push(...moveRangeMutations.redos);
3175
+ undos.push(...moveRangeMutations.undos);
3176
+ }
3177
+ }
3178
+ return executeTableMutationSequence(accessor, unitId, redos, undos);
3179
+ }
3180
+ };
2921
3181
  const SheetTableRemoveRowCommand = {
2922
3182
  id: "sheet.command.table-remove-row",
2923
3183
  type: CommandType.COMMAND,
@@ -3083,7 +3343,7 @@ const SheetTableRemoveColCommand = {
3083
3343
  //#endregion
3084
3344
  //#region package.json
3085
3345
  var name = "@univerjs/sheets-table";
3086
- var version = "0.22.1";
3346
+ var version = "0.23.0-insiders.20260522-e8f2a3b";
3087
3347
 
3088
3348
  //#endregion
3089
3349
  //#region src/controllers/sheet-table-formula.controller.ts
@@ -3888,8 +4148,11 @@ let UniverSheetsTablePlugin = class UniverSheetsTablePlugin extends Plugin {
3888
4148
  RemoveTableThemeCommand,
3889
4149
  SheetTableInsertRowCommand,
3890
4150
  SheetTableInsertColCommand,
4151
+ SheetTableInsertRowAtCommand,
4152
+ SheetTableInsertColumnAtCommand,
3891
4153
  SheetTableRemoveRowCommand,
3892
- SheetTableRemoveColCommand
4154
+ SheetTableRemoveColCommand,
4155
+ SheetTableRemoveColumnAtCommand
3893
4156
  ].forEach((m) => this._commandService.registerCommand(m));
3894
4157
  }
3895
4158
  };
@@ -3904,4 +4167,4 @@ UniverSheetsTablePlugin = __decorate([
3904
4167
  ], UniverSheetsTablePlugin);
3905
4168
 
3906
4169
  //#endregion
3907
- export { AddSheetTableCommand, AddSheetTableMutation, AddTableThemeCommand, DeleteSheetTableCommand, DeleteSheetTableMutation, RemoveTableThemeCommand, SHEET_TABLE_CUSTOM_THEME_PREFIX, SetSheetTableCommand, SetSheetTableFilterCommand, SetSheetTableFilterMutation, SetSheetTableMutation, SheetTableInsertColCommand, SheetTableInsertRowCommand, SheetTableRemoveColCommand, SheetTableRemoveRowCommand, SheetTableService, SheetsTableButtonStateEnum, SheetsTableController, SheetsTableSortStateEnum, TableColumnDataTypeEnum, TableColumnFilterTypeEnum, TableConditionTypeEnum, TableDateCompareTypeEnum, TableManager, TableNumberCompareTypeEnum, TableStringCompareTypeEnum, UniverSheetsTablePlugin, customEmptyThemeWithBorderStyle, isConditionFilter, isManualTableFilter, processStyleWithBorderStyle };
4170
+ export { AddSheetTableCommand, AddSheetTableMutation, AddTableThemeCommand, DeleteSheetTableCommand, DeleteSheetTableMutation, RemoveTableThemeCommand, SHEET_TABLE_CUSTOM_THEME_PREFIX, SetSheetTableCommand, SetSheetTableFilterCommand, SetSheetTableFilterMutation, SetSheetTableMutation, SheetTableInsertColCommand, SheetTableInsertColumnAtCommand, SheetTableInsertRowAtCommand, SheetTableInsertRowCommand, SheetTableRemoveColCommand, SheetTableRemoveColumnAtCommand, SheetTableRemoveRowCommand, SheetTableService, SheetsTableButtonStateEnum, SheetsTableController, SheetsTableSortStateEnum, TableColumnDataTypeEnum, TableColumnFilterTypeEnum, TableConditionTypeEnum, TableDateCompareTypeEnum, TableManager, TableNumberCompareTypeEnum, TableStringCompareTypeEnum, UniverSheetsTablePlugin, customEmptyThemeWithBorderStyle, getExistingNamesSet, isConditionFilter, isManualTableFilter, processStyleWithBorderStyle, validateSheetTableName };
@@ -19,8 +19,15 @@ interface ISheetTableRowColOperationCommandParams {
19
19
  unitId: string;
20
20
  subUnitId: string;
21
21
  }
22
+ interface ISheetTableInsertAtCommandParams extends ISheetTableRowColOperationCommandParams {
23
+ index: number;
24
+ count?: number;
25
+ }
22
26
  export declare const SheetTableInsertRowCommand: ICommand<ISheetTableRowColOperationCommandParams>;
27
+ export declare const SheetTableInsertRowAtCommand: ICommand<ISheetTableInsertAtCommandParams>;
23
28
  export declare const SheetTableInsertColCommand: ICommand<ISheetTableRowColOperationCommandParams>;
29
+ export declare const SheetTableInsertColumnAtCommand: ICommand<ISheetTableInsertAtCommandParams>;
30
+ export declare const SheetTableRemoveColumnAtCommand: ICommand<ISheetTableInsertAtCommandParams>;
24
31
  export declare const SheetTableRemoveRowCommand: ICommand<ISheetTableRowColOperationCommandParams>;
25
32
  export declare const SheetTableRemoveColCommand: ICommand<ISheetTableRowColOperationCommandParams>;
26
33
  export {};
@@ -22,7 +22,7 @@ export { RemoveTableThemeCommand } from './commands/commands/remove-table-theme.
22
22
  export { SetSheetTableCommand } from './commands/commands/set-sheet-table.command';
23
23
  export type { ISetSheetTableCommandParams } from './commands/commands/set-sheet-table.command';
24
24
  export { SetSheetTableFilterCommand } from './commands/commands/set-table-filter.command';
25
- export { SheetTableInsertColCommand, SheetTableInsertRowCommand, SheetTableRemoveColCommand, SheetTableRemoveRowCommand } from './commands/commands/sheet-table-row-col.command';
25
+ export { SheetTableInsertColCommand, SheetTableInsertColumnAtCommand, SheetTableInsertRowAtCommand, SheetTableInsertRowCommand, SheetTableRemoveColCommand, SheetTableRemoveColumnAtCommand, SheetTableRemoveRowCommand } from './commands/commands/sheet-table-row-col.command';
26
26
  export { AddSheetTableMutation } from './commands/mutations/add-sheet-table.mutation';
27
27
  export type { IAddSheetTableParams } from './commands/mutations/add-sheet-table.mutation';
28
28
  export { DeleteSheetTableMutation } from './commands/mutations/delete-sheet-table.mutation';
@@ -41,4 +41,6 @@ export { SheetTableService } from './services/table-service';
41
41
  export { SheetsTableButtonStateEnum, SheetsTableSortStateEnum, TableColumnDataTypeEnum, TableColumnFilterTypeEnum, TableConditionTypeEnum, TableDateCompareTypeEnum, TableNumberCompareTypeEnum, TableStringCompareTypeEnum } from './types/enum';
42
42
  export type { ITableColumnJson, ITableConditionFilterItem, ITableData, ITableFilterItem, ITableInfo, ITableInfoWithUnitId, ITableManualFilterItem, ITableOptions, ITableRange, ITableRangeWithState, TableMetaType, TableRelationTupleType } from './types/type';
43
43
  export type { ITableJson, ITableSetConfig } from './types/type';
44
- export { isConditionFilter, isManualTableFilter } from './util';
44
+ export { getExistingNamesSet, isConditionFilter, isManualTableFilter } from './util';
45
+ export { validateSheetTableName } from './util/table-name';
46
+ export type { ISheetTableNameValidationResult, SheetTableNameValidationReason } from './util/table-name';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export type SheetTableNameValidationReason = 'empty' | 'invalid';
17
+ export interface ISheetTableNameValidationResult {
18
+ valid: boolean;
19
+ reason?: SheetTableNameValidationReason;
20
+ }
21
+ export declare function validateSheetTableName(name: string, existingNamesSet: Set<string>): ISheetTableNameValidationResult;