@univerjs/sheets-table 1.0.3 → 1.1.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.
Files changed (88) hide show
  1. package/lib/cjs/index.js +245 -62
  2. package/lib/cjs/locale/ar-SA.js +1 -0
  3. package/lib/cjs/locale/ca-ES.js +1 -0
  4. package/lib/cjs/locale/de-DE.js +1 -0
  5. package/lib/cjs/locale/en-US.js +1 -0
  6. package/lib/cjs/locale/es-ES.js +1 -0
  7. package/lib/cjs/locale/fa-IR.js +1 -0
  8. package/lib/cjs/locale/fr-FR.js +1 -0
  9. package/lib/cjs/locale/id-ID.js +1 -0
  10. package/lib/cjs/locale/it-IT.js +1 -0
  11. package/lib/cjs/locale/ja-JP.js +1 -0
  12. package/lib/cjs/locale/ko-KR.js +1 -0
  13. package/lib/cjs/locale/pl-PL.js +1 -0
  14. package/lib/cjs/locale/pt-BR.js +1 -0
  15. package/lib/cjs/locale/ru-RU.js +1 -0
  16. package/lib/cjs/locale/sk-SK.js +1 -0
  17. package/lib/cjs/locale/vi-VN.js +1 -0
  18. package/lib/cjs/locale/zh-CN.js +1 -0
  19. package/lib/cjs/locale/zh-HK.js +1 -0
  20. package/lib/cjs/locale/zh-TW.js +1 -0
  21. package/lib/es/index.js +242 -59
  22. package/lib/es/locale/ar-SA.js +1 -0
  23. package/lib/es/locale/ca-ES.js +1 -0
  24. package/lib/es/locale/de-DE.js +1 -0
  25. package/lib/es/locale/en-US.js +1 -0
  26. package/lib/es/locale/es-ES.js +1 -0
  27. package/lib/es/locale/fa-IR.js +1 -0
  28. package/lib/es/locale/fr-FR.js +1 -0
  29. package/lib/es/locale/id-ID.js +1 -0
  30. package/lib/es/locale/it-IT.js +1 -0
  31. package/lib/es/locale/ja-JP.js +1 -0
  32. package/lib/es/locale/ko-KR.js +1 -0
  33. package/lib/es/locale/pl-PL.js +1 -0
  34. package/lib/es/locale/pt-BR.js +1 -0
  35. package/lib/es/locale/ru-RU.js +1 -0
  36. package/lib/es/locale/sk-SK.js +1 -0
  37. package/lib/es/locale/vi-VN.js +1 -0
  38. package/lib/es/locale/zh-CN.js +1 -0
  39. package/lib/es/locale/zh-HK.js +1 -0
  40. package/lib/es/locale/zh-TW.js +1 -0
  41. package/lib/index.js +242 -59
  42. package/lib/locale/ar-SA.js +1 -0
  43. package/lib/locale/ca-ES.js +1 -0
  44. package/lib/locale/de-DE.js +1 -0
  45. package/lib/locale/en-US.js +1 -0
  46. package/lib/locale/es-ES.js +1 -0
  47. package/lib/locale/fa-IR.js +1 -0
  48. package/lib/locale/fr-FR.js +1 -0
  49. package/lib/locale/id-ID.js +1 -0
  50. package/lib/locale/it-IT.js +1 -0
  51. package/lib/locale/ja-JP.js +1 -0
  52. package/lib/locale/ko-KR.js +1 -0
  53. package/lib/locale/pl-PL.js +1 -0
  54. package/lib/locale/pt-BR.js +1 -0
  55. package/lib/locale/ru-RU.js +1 -0
  56. package/lib/locale/sk-SK.js +1 -0
  57. package/lib/locale/vi-VN.js +1 -0
  58. package/lib/locale/zh-CN.js +1 -0
  59. package/lib/locale/zh-HK.js +1 -0
  60. package/lib/locale/zh-TW.js +1 -0
  61. package/lib/types/commands/mutations/move-sheet-table.mutation.d.ts +25 -0
  62. package/lib/types/controllers/sheet-table-move.controller.d.ts +31 -0
  63. package/lib/types/controllers/table-filter.controller.d.ts +0 -1
  64. package/lib/types/locale/en-US.d.ts +1 -0
  65. package/lib/types/models/table-manager.d.ts +1 -0
  66. package/lib/types/types/type.d.ts +2 -7
  67. package/lib/umd/facade.js +1 -1
  68. package/lib/umd/index.js +1 -1
  69. package/lib/umd/locale/ar-SA.js +1 -1
  70. package/lib/umd/locale/ca-ES.js +1 -1
  71. package/lib/umd/locale/de-DE.js +1 -1
  72. package/lib/umd/locale/en-US.js +1 -1
  73. package/lib/umd/locale/es-ES.js +1 -1
  74. package/lib/umd/locale/fa-IR.js +1 -1
  75. package/lib/umd/locale/fr-FR.js +1 -1
  76. package/lib/umd/locale/id-ID.js +1 -1
  77. package/lib/umd/locale/it-IT.js +1 -1
  78. package/lib/umd/locale/ja-JP.js +1 -1
  79. package/lib/umd/locale/ko-KR.js +1 -1
  80. package/lib/umd/locale/pl-PL.js +1 -1
  81. package/lib/umd/locale/pt-BR.js +1 -1
  82. package/lib/umd/locale/ru-RU.js +1 -1
  83. package/lib/umd/locale/sk-SK.js +1 -1
  84. package/lib/umd/locale/vi-VN.js +1 -1
  85. package/lib/umd/locale/zh-CN.js +1 -1
  86. package/lib/umd/locale/zh-HK.js +1 -1
  87. package/lib/umd/locale/zh-TW.js +1 -1
  88. package/package.json +8 -8
package/lib/cjs/index.js CHANGED
@@ -317,7 +317,7 @@ const tableThemeConfig = tableDefaultThemeStyleArr.map((item, index) => {
317
317
  });
318
318
 
319
319
  //#endregion
320
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
320
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
321
321
  function _typeof(o) {
322
322
  "@babel/helpers - typeof";
323
323
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -328,7 +328,7 @@ function _typeof(o) {
328
328
  }
329
329
 
330
330
  //#endregion
331
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
331
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
332
332
  function toPrimitive(t, r) {
333
333
  if ("object" != _typeof(t) || !t) return t;
334
334
  var e = t[Symbol.toPrimitive];
@@ -341,14 +341,14 @@ function toPrimitive(t, r) {
341
341
  }
342
342
 
343
343
  //#endregion
344
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
344
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
345
345
  function toPropertyKey(t) {
346
346
  var i = toPrimitive(t, "string");
347
347
  return "symbol" == _typeof(i) ? i : i + "";
348
348
  }
349
349
 
350
350
  //#endregion
351
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
351
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
352
352
  function _defineProperty(e, r, t) {
353
353
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
354
354
  value: t,
@@ -621,7 +621,6 @@ const getWeekStart = (date) => {
621
621
  weekStart.setDate(diff);
622
622
  return weekStart;
623
623
  };
624
- const perWeek = 6048e5;
625
624
  /**
626
625
  * The provided date is in the current week.
627
626
  * @param {Date} date - The date to compare.
@@ -641,7 +640,8 @@ const thisWeek = (date, anchorTime = /* @__PURE__ */ new Date()) => {
641
640
  */
642
641
  const nextWeek = (date, anchorTime = /* @__PURE__ */ new Date()) => {
643
642
  const weekStart = getWeekStart(date);
644
- const anchorTimeNextWeekStart = new Date(getWeekStart(anchorTime).getTime() + perWeek);
643
+ const anchorTimeNextWeekStart = getWeekStart(anchorTime);
644
+ anchorTimeNextWeekStart.setDate(anchorTimeNextWeekStart.getDate() + 7);
645
645
  return weekStart.toDateString() === anchorTimeNextWeekStart.toDateString();
646
646
  };
647
647
  /**
@@ -652,7 +652,8 @@ const nextWeek = (date, anchorTime = /* @__PURE__ */ new Date()) => {
652
652
  */
653
653
  const lastWeek = (date, anchorTime = /* @__PURE__ */ new Date()) => {
654
654
  const weekStart = getWeekStart(date);
655
- const anchorTimeLastWeekStart = /* @__PURE__ */ new Date(getWeekStart(anchorTime).getTime() - perWeek);
655
+ const anchorTimeLastWeekStart = getWeekStart(anchorTime);
656
+ anchorTimeLastWeekStart.setDate(anchorTimeLastWeekStart.getDate() - 7);
656
657
  return weekStart.toDateString() === anchorTimeLastWeekStart.toDateString();
657
658
  };
658
659
  /**
@@ -686,7 +687,7 @@ const nextMonth = (date, anchorTime = /* @__PURE__ */ new Date()) => {
686
687
  nextMonthStart.setHours(0, 0, 0, 0);
687
688
  nextMonthStart.setMonth(nextMonthStart.getMonth() + 1, 1);
688
689
  const monthEnd = new Date(nextMonthStart);
689
- monthEnd.setMonth(monthEnd.getMonth() + 1, 0);
690
+ monthEnd.setMonth(monthEnd.getMonth() + 1);
690
691
  const dateTime = date.getTime();
691
692
  return dateTime >= nextMonthStart.getTime() && dateTime < monthEnd.getTime();
692
693
  };
@@ -697,9 +698,9 @@ const nextMonth = (date, anchorTime = /* @__PURE__ */ new Date()) => {
697
698
  * @returns {boolean} return the date is match
698
699
  */
699
700
  const lastMonth = (date, anchorTime = /* @__PURE__ */ new Date()) => {
700
- const lastMonthStart = getMonthStart(anchorTime);
701
- const monthEnd = new Date(lastMonthStart);
702
- monthEnd.setMonth(monthEnd.getMonth() + 1, 0);
701
+ const monthEnd = getMonthStart(anchorTime);
702
+ const lastMonthStart = new Date(monthEnd);
703
+ lastMonthStart.setMonth(lastMonthStart.getMonth() - 1);
703
704
  const dateTime = date.getTime();
704
705
  return dateTime >= lastMonthStart.getTime() && dateTime < monthEnd.getTime();
705
706
  };
@@ -740,7 +741,7 @@ const nextQuarter = (date, anchorTime = /* @__PURE__ */ new Date()) => {
740
741
  const nextQuarterStart = new Date(quarterStart);
741
742
  nextQuarterStart.setMonth(nextQuarterStart.getMonth() + 3);
742
743
  const nextQuarterEnd = new Date(nextQuarterStart);
743
- nextQuarterEnd.setMonth(nextQuarterEnd.getMonth() + 3, 0);
744
+ nextQuarterEnd.setMonth(nextQuarterEnd.getMonth() + 3);
744
745
  const dateTime = date.getTime();
745
746
  return dateTime >= nextQuarterStart.getTime() && dateTime < nextQuarterEnd.getTime();
746
747
  };
@@ -754,10 +755,8 @@ const lastQuarter = (date, anchorTime = /* @__PURE__ */ new Date()) => {
754
755
  const quarterStart = getQuarterStart(anchorTime);
755
756
  const lastQuarterStart = new Date(quarterStart);
756
757
  lastQuarterStart.setMonth(lastQuarterStart.getMonth() - 3);
757
- const lastQuarterEnd = new Date(quarterStart);
758
- lastQuarterEnd.setDate(0);
759
758
  const dateTime = date.getTime();
760
- return dateTime >= lastQuarterStart.getTime() && dateTime < lastQuarterEnd.getTime();
759
+ return dateTime >= lastQuarterStart.getTime() && dateTime < quarterStart.getTime();
761
760
  };
762
761
  /**
763
762
  * The provided date is in the current year.
@@ -1496,7 +1495,7 @@ var TableFilters = class {
1496
1495
  }
1497
1496
  getExecuteFunc(sheet, range, columnIndex, filter) {
1498
1497
  if (filter.filterType === "manual") {
1499
- const valuesSet = new Set(filter.values);
1498
+ const valuesSet = new Set(filter.values.map(String));
1500
1499
  return (value) => {
1501
1500
  if (value == null) return valuesSet.has(TABLE_FILTER_EMPTY_VALUE);
1502
1501
  return valuesSet.has(String(value));
@@ -1725,10 +1724,7 @@ var Table = class {
1725
1724
  return this._tableFilters.getFilterStates(range);
1726
1725
  }
1727
1726
  toJSON() {
1728
- const columns = [];
1729
- this._columns.forEach((column) => {
1730
- columns.push(column.toJSON());
1731
- });
1727
+ const columns = this._columnOrder.map((columnId) => this._columns.get(columnId).toJSON());
1732
1728
  return {
1733
1729
  id: this._id,
1734
1730
  name: this._name,
@@ -1778,7 +1774,7 @@ var Table = class {
1778
1774
  };
1779
1775
 
1780
1776
  //#endregion
1781
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
1777
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
1782
1778
  function __decorateParam(paramIndex, decorator) {
1783
1779
  return function(target, key) {
1784
1780
  decorator(target, key, paramIndex);
@@ -1786,7 +1782,7 @@ function __decorateParam(paramIndex, decorator) {
1786
1782
  }
1787
1783
 
1788
1784
  //#endregion
1789
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
1785
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
1790
1786
  function __decorate(decorators, target, key, desc) {
1791
1787
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1792
1788
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -2053,6 +2049,28 @@ let TableManager = class TableManager extends _univerjs_core.Disposable {
2053
2049
  oldRange
2054
2050
  });
2055
2051
  }
2052
+ moveTable(unitId, tableId, subUnitId, range) {
2053
+ const table = this.getTableById(unitId, tableId);
2054
+ if (!table) return;
2055
+ const oldRange = table.getRange();
2056
+ const oldSubUnitId = table.getSubunitId();
2057
+ table.setSubunitId(subUnitId);
2058
+ table.setRange({ ...range });
2059
+ this._tableRangeChanged$.next({
2060
+ unitId,
2061
+ subUnitId,
2062
+ oldSubUnitId,
2063
+ tableId,
2064
+ range: { ...range },
2065
+ oldRange
2066
+ });
2067
+ this._tableFilterChanged$.next({
2068
+ unitId,
2069
+ subUnitId,
2070
+ oldSubUnitId,
2071
+ tableId
2072
+ });
2073
+ }
2056
2074
  setTableByConfig(unitId, tableId, config) {
2057
2075
  const unitMap = this._tableMap.get(unitId);
2058
2076
  const table = unitMap === null || unitMap === void 0 ? void 0 : unitMap.get(tableId);
@@ -2394,12 +2412,35 @@ const AddTableThemeCommand = {
2394
2412
  }
2395
2413
  };
2396
2414
 
2415
+ //#endregion
2416
+ //#region src/commands/mutations/set-table-filter.mutation.ts
2417
+ const SetSheetTableFilterMutation = {
2418
+ id: "sheet.mutation.set-table-filter",
2419
+ type: _univerjs_core.CommandType.MUTATION,
2420
+ handler: (accessor, params) => {
2421
+ const { tableId, unitId, column, tableFilter } = params;
2422
+ const tableManager = accessor.get(TableManager);
2423
+ const table = tableManager.getTable(unitId, tableId);
2424
+ tableManager.addFilter(unitId, tableId, column, tableFilter);
2425
+ if (table) {
2426
+ var _tableManager$toJSON$;
2427
+ const tableFilters = table.getTableFilters();
2428
+ if (params.filterOutRows) tableFilters.setFilterOutRows(params.filterOutRows);
2429
+ else params.filterOutRows = [...tableFilters.getFilterOutRows()];
2430
+ params.subUnitId = table.getSubunitId();
2431
+ params.tableFilteredOutRows = ((_tableManager$toJSON$ = tableManager.toJSON(unitId)[params.subUnitId]) === null || _tableManager$toJSON$ === void 0 ? void 0 : _tableManager$toJSON$.tableFilteredOutRows) ?? [];
2432
+ }
2433
+ return true;
2434
+ }
2435
+ };
2436
+
2397
2437
  //#endregion
2398
2438
  //#region src/commands/commands/delete-sheet-table.command.ts
2399
2439
  const DeleteSheetTableCommand = {
2400
2440
  id: "sheet.command.delete-table",
2401
2441
  type: _univerjs_core.CommandType.COMMAND,
2402
2442
  handler: (accessor, params) => {
2443
+ var _tableConfig$filters$;
2403
2444
  if (!params) return false;
2404
2445
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
2405
2446
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -2438,6 +2479,17 @@ const DeleteSheetTableCommand = {
2438
2479
  options: tableConfig.options
2439
2480
  }
2440
2481
  });
2482
+ (_tableConfig$filters$ = tableConfig.filters.tableColumnFilterList) === null || _tableConfig$filters$ === void 0 || _tableConfig$filters$.forEach((tableFilter, column) => {
2483
+ if (tableFilter) undos.push({
2484
+ id: SetSheetTableFilterMutation.id,
2485
+ params: {
2486
+ unitId: params.unitId,
2487
+ tableId: params.tableId,
2488
+ column,
2489
+ tableFilter
2490
+ }
2491
+ });
2492
+ });
2441
2493
  undos.push(...interceptorCommands.undos);
2442
2494
  if ((0, _univerjs_core.sequenceExecute)(redos, commandService).result) {
2443
2495
  undoRedoService.pushUndoRedo({
@@ -2780,28 +2832,6 @@ const SetSheetTableCommand = {
2780
2832
  }
2781
2833
  };
2782
2834
 
2783
- //#endregion
2784
- //#region src/commands/mutations/set-table-filter.mutation.ts
2785
- const SetSheetTableFilterMutation = {
2786
- id: "sheet.mutation.set-table-filter",
2787
- type: _univerjs_core.CommandType.MUTATION,
2788
- handler: (accessor, params) => {
2789
- const { tableId, unitId, column, tableFilter } = params;
2790
- const tableManager = accessor.get(TableManager);
2791
- const table = tableManager.getTable(unitId, tableId);
2792
- tableManager.addFilter(unitId, tableId, column, tableFilter);
2793
- if (table) {
2794
- var _tableManager$toJSON$;
2795
- const tableFilters = table.getTableFilters();
2796
- if (params.filterOutRows) tableFilters.setFilterOutRows(params.filterOutRows);
2797
- else params.filterOutRows = [...tableFilters.getFilterOutRows()];
2798
- params.subUnitId = table.getSubunitId();
2799
- params.tableFilteredOutRows = ((_tableManager$toJSON$ = tableManager.toJSON(unitId)[params.subUnitId]) === null || _tableManager$toJSON$ === void 0 ? void 0 : _tableManager$toJSON$.tableFilteredOutRows) ?? [];
2800
- }
2801
- return true;
2802
- }
2803
- };
2804
-
2805
2835
  //#endregion
2806
2836
  //#region src/commands/commands/set-table-filter.command.ts
2807
2837
  const SetSheetTableFilterCommand = {
@@ -2928,11 +2958,11 @@ let SheetsTableController = class SheetsTableController extends _univerjs_core.D
2928
2958
  });
2929
2959
  }));
2930
2960
  this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
2931
- const { range, tableId, unitId, subUnitId, oldRange } = event;
2961
+ const { range, tableId, unitId, subUnitId, oldRange, oldSubUnitId = subUnitId } = event;
2932
2962
  const rTree = this._ensureTableRangeRTree(unitId);
2933
2963
  rTree.remove({
2934
2964
  unitId,
2935
- sheetId: subUnitId,
2965
+ sheetId: oldSubUnitId,
2936
2966
  id: tableId,
2937
2967
  range: { ...oldRange }
2938
2968
  });
@@ -3854,7 +3884,7 @@ let SheetsTableThemeController = class SheetsTableThemeController extends _unive
3854
3884
  });
3855
3885
  }));
3856
3886
  this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
3857
- const { range, oldRange, tableId, unitId, subUnitId } = event;
3887
+ const { range, oldRange, tableId, unitId, subUnitId, oldSubUnitId = subUnitId } = event;
3858
3888
  const table = this._tableManager.getTable(unitId, tableId);
3859
3889
  let tableStyleId = table.getTableStyleId();
3860
3890
  if (!tableStyleId) {
@@ -3863,7 +3893,7 @@ let SheetsTableThemeController = class SheetsTableThemeController extends _unive
3863
3893
  }
3864
3894
  this._sheetRangeThemeService.removeRangeThemeRule(tableStyleId, {
3865
3895
  unitId,
3866
- subUnitId,
3896
+ subUnitId: oldSubUnitId,
3867
3897
  range: { ...oldRange }
3868
3898
  });
3869
3899
  this._sheetRangeThemeService.registerRangeThemeStyle(tableStyleId, {
@@ -3925,7 +3955,43 @@ SheetsTableThemeController = __decorate([
3925
3955
  //#endregion
3926
3956
  //#region package.json
3927
3957
  var name = "@univerjs/sheets-table";
3928
- var version = "1.0.3";
3958
+ var version = "1.1.0";
3959
+
3960
+ //#endregion
3961
+ //#region src/commands/mutations/move-sheet-table.mutation.ts
3962
+ const MoveSheetTableMutation = {
3963
+ id: "sheet.mutation.move-table",
3964
+ type: _univerjs_core.CommandType.MUTATION,
3965
+ handler: (accessor, params) => {
3966
+ if (!params) return false;
3967
+ const { unitId, tableId, subUnitId, range, calculatedColumns } = params;
3968
+ const manager = accessor.get(TableManager);
3969
+ const table = manager.getTableById(unitId, tableId);
3970
+ const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
3971
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
3972
+ if (!table || !worksheet) return false;
3973
+ const columns = calculatedColumns ?? table.getTableInfo().columns.map((column, columnIndex) => {
3974
+ var _worksheet$getCellRaw;
3975
+ const row = range.startRow + (table.isShowHeader() ? 1 : 0);
3976
+ const endRow = range.endRow - (table.isShowFooter() ? 1 : 0);
3977
+ const formula = column.formula && row <= endRow ? (_worksheet$getCellRaw = worksheet.getCellRaw(row, range.startColumn + columnIndex)) === null || _worksheet$getCellRaw === void 0 ? void 0 : _worksheet$getCellRaw.f : void 0;
3978
+ return {
3979
+ columnId: column.id,
3980
+ formula: formula || column.formula,
3981
+ formulaIsArray: column.formulaIsArray
3982
+ };
3983
+ }).filter((column) => column.formula);
3984
+ for (const config of columns) {
3985
+ const column = table.getColumn(config.columnId);
3986
+ if (column) {
3987
+ column.formula = config.formula;
3988
+ column.formulaIsArray = config.formulaIsArray;
3989
+ }
3990
+ }
3991
+ manager.moveTable(unitId, tableId, subUnitId, range);
3992
+ return true;
3993
+ }
3994
+ };
3929
3995
 
3930
3996
  //#endregion
3931
3997
  //#region src/controllers/sheet-table-formula.controller.ts
@@ -4021,6 +4087,114 @@ SheetTableFormulaController = __decorate([
4021
4087
  __decorateParam(2, _univerjs_engine_formula.IActiveDirtyManagerService)
4022
4088
  ], SheetTableFormulaController);
4023
4089
 
4090
+ //#endregion
4091
+ //#region src/controllers/sheet-table-move.controller.ts
4092
+ let SheetTableMoveController = class SheetTableMoveController extends _univerjs_core.Disposable {
4093
+ constructor(_tableManager, _sheetInterceptorService, _univerInstanceService, _injector, _localeService, _errorService) {
4094
+ super();
4095
+ this._tableManager = _tableManager;
4096
+ this._sheetInterceptorService = _sheetInterceptorService;
4097
+ this._univerInstanceService = _univerInstanceService;
4098
+ this._injector = _injector;
4099
+ this._localeService = _localeService;
4100
+ this._errorService = _errorService;
4101
+ this.disposeWithMe(this._sheetInterceptorService.interceptBeforeCommand({ performCheck: async (command) => command.id !== _univerjs_sheets.MoveRangeCommand.id || this._checkMove(command.params) }));
4102
+ this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({ getMutations: (command) => command.id === _univerjs_sheets.MoveRangeCommand.id ? this._getMoveMutations(command.params) : {
4103
+ redos: [],
4104
+ undos: []
4105
+ } }));
4106
+ }
4107
+ _getTargets(params) {
4108
+ const source = (0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, {
4109
+ unitId: params.fromUnitId ?? params.toUnitId,
4110
+ subUnitId: params.fromSubUnitId
4111
+ });
4112
+ return {
4113
+ source,
4114
+ target: (0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, {
4115
+ unitId: params.toUnitId ?? (source === null || source === void 0 ? void 0 : source.unitId),
4116
+ subUnitId: params.toSubUnitId ?? (source === null || source === void 0 ? void 0 : source.subUnitId)
4117
+ })
4118
+ };
4119
+ }
4120
+ _checkMove(params) {
4121
+ const { source, target } = this._getTargets(params);
4122
+ if (!source || !target || source.unitId !== target.unitId) return false;
4123
+ const movingTables = this._tableManager.getTablesBySubunitId(source.unitId, source.subUnitId).filter((table) => _univerjs_core.Rectangle.contains(params.fromRange, table.getRange()));
4124
+ if (!movingTables.length) return true;
4125
+ const targetTables = this._tableManager.getTablesBySubunitId(target.unitId, target.subUnitId);
4126
+ for (const table of targetTables) {
4127
+ if (movingTables.includes(table) || !_univerjs_core.Rectangle.intersects(params.toRange, table.getRange())) continue;
4128
+ this._errorService.emit(this._localeService.t("sheets-table.moveTableOverlapError"));
4129
+ return false;
4130
+ }
4131
+ const { fromRange, toRange } = params;
4132
+ if (!this._isValidMoveRange(params, target.worksheet)) return false;
4133
+ return (0, _univerjs_sheets.checkRangesEditablePermission)(this._injector, source.unitId, source.subUnitId, [fromRange]) && (0, _univerjs_sheets.checkRangesEditablePermission)(this._injector, target.unitId, target.subUnitId, [toRange]);
4134
+ }
4135
+ _isValidMoveRange(params, worksheet) {
4136
+ const { fromRange, toRange } = params;
4137
+ if (fromRange.endRow - fromRange.startRow !== toRange.endRow - toRange.startRow || fromRange.endColumn - fromRange.startColumn !== toRange.endColumn - toRange.startColumn || toRange.startRow < 0 || toRange.startColumn < 0 || toRange.endRow >= worksheet.getRowCount() || toRange.endColumn >= worksheet.getColumnCount()) return false;
4138
+ return true;
4139
+ }
4140
+ _getMoveMutations(params) {
4141
+ const redos = [];
4142
+ const undos = [];
4143
+ const { source, target } = this._getTargets(params);
4144
+ if (!source || !target || source.unitId !== target.unitId) return {
4145
+ redos,
4146
+ undos
4147
+ };
4148
+ const rowOffset = params.toRange.startRow - params.fromRange.startRow;
4149
+ const columnOffset = params.toRange.startColumn - params.fromRange.startColumn;
4150
+ const tables = this._tableManager.getTablesBySubunitId(source.unitId, source.subUnitId);
4151
+ for (const table of tables) {
4152
+ const range = table.getRange();
4153
+ if (!_univerjs_core.Rectangle.contains(params.fromRange, range)) continue;
4154
+ redos.push({
4155
+ id: MoveSheetTableMutation.id,
4156
+ params: {
4157
+ unitId: source.unitId,
4158
+ tableId: table.getId(),
4159
+ subUnitId: target.subUnitId,
4160
+ range: {
4161
+ startRow: range.startRow + rowOffset,
4162
+ endRow: range.endRow + rowOffset,
4163
+ startColumn: range.startColumn + columnOffset,
4164
+ endColumn: range.endColumn + columnOffset
4165
+ }
4166
+ }
4167
+ });
4168
+ undos.push({
4169
+ id: MoveSheetTableMutation.id,
4170
+ params: {
4171
+ unitId: source.unitId,
4172
+ tableId: table.getId(),
4173
+ subUnitId: source.subUnitId,
4174
+ range,
4175
+ calculatedColumns: table.getTableInfo().columns.filter((column) => column.formula).map((column) => ({
4176
+ columnId: column.id,
4177
+ formula: column.formula,
4178
+ formulaIsArray: column.formulaIsArray
4179
+ }))
4180
+ }
4181
+ });
4182
+ }
4183
+ return {
4184
+ redos,
4185
+ undos
4186
+ };
4187
+ }
4188
+ };
4189
+ SheetTableMoveController = __decorate([
4190
+ __decorateParam(0, (0, _univerjs_core.Inject)(TableManager)),
4191
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
4192
+ __decorateParam(2, _univerjs_core.IUniverInstanceService),
4193
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
4194
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
4195
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.ErrorService))
4196
+ ], SheetTableMoveController);
4197
+
4024
4198
  //#endregion
4025
4199
  //#region src/controllers/sheet-table-range.controller.ts
4026
4200
  /**
@@ -4047,8 +4221,8 @@ let SheetTableRangeController = class SheetTableRangeController extends _univerj
4047
4221
  }
4048
4222
  _initRangeListener() {
4049
4223
  this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
4050
- const { range, tableId, unitId, subUnitId } = event;
4051
- this._exclusiveRangeService.clearExclusiveRangesByGroupId(unitId, subUnitId, FEATURE_TABLE_ID, tableId);
4224
+ const { range, tableId, unitId, subUnitId, oldSubUnitId = subUnitId } = event;
4225
+ this._exclusiveRangeService.clearExclusiveRangesByGroupId(unitId, oldSubUnitId, FEATURE_TABLE_ID, tableId);
4052
4226
  this._exclusiveRangeService.addExclusiveRange(unitId, subUnitId, FEATURE_TABLE_ID, [{
4053
4227
  range: { ...range },
4054
4228
  groupId: tableId
@@ -4603,7 +4777,6 @@ let TableFilterController = class TableFilterController extends _univerjs_core.D
4603
4777
  this._sheetRowFilteredService = _sheetRowFilteredService;
4604
4778
  this._zebraCrossingCacheController = _zebraCrossingCacheController;
4605
4779
  _defineProperty(this, "_tableFilteredOutRows", /* @__PURE__ */ new Map());
4606
- _defineProperty(this, "_subscription", null);
4607
4780
  this.registerFilterChangeEvent();
4608
4781
  this.initTableHiddenRowIntercept();
4609
4782
  this._registerFormulaRowFiltered();
@@ -4625,18 +4798,22 @@ let TableFilterController = class TableFilterController extends _univerjs_core.D
4625
4798
  }));
4626
4799
  }
4627
4800
  _initFilteredOutRows() {
4628
- this._tableManager.tableInitStatus$.pipe((0, rxjs.filter)((initialized) => initialized), (0, rxjs.switchMap)(() => {
4801
+ this.disposeWithMe(this._tableManager.tableInitStatus$.pipe((0, rxjs.filter)((initialized) => initialized), (0, rxjs.switchMap)(() => {
4629
4802
  return this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
4630
4803
  }), (0, rxjs.filter)((workbook) => workbook !== null && workbook !== void 0), (0, rxjs.switchMap)((workbook) => workbook.activeSheet$), (0, rxjs.filter)((sheet) => sheet !== null && sheet !== void 0)).subscribe(() => {
4631
4804
  const target = (0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService);
4632
4805
  if (!target) return;
4633
4806
  const { unitId, subUnitId } = target;
4634
4807
  this._refreshTableFilteredOutRows(unitId, subUnitId);
4635
- });
4808
+ }));
4636
4809
  }
4637
4810
  registerFilterChangeEvent() {
4811
+ this.disposeWithMe(this._tableManager.tableDelete$.subscribe(({ unitId, subUnitId }) => {
4812
+ this._refreshTableFilteredOutRows(unitId, subUnitId);
4813
+ this._zebraCrossingCacheController.updateZebraCrossingCache(unitId, subUnitId);
4814
+ }));
4638
4815
  this.disposeWithMe(this._tableManager.tableFilterChanged$.subscribe((event) => {
4639
- const { unitId, subUnitId, tableId } = event;
4816
+ const { unitId, subUnitId, tableId, oldSubUnitId } = event;
4640
4817
  const workbook = this._univerInstanceService.getUnit(unitId);
4641
4818
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
4642
4819
  const table = this._tableManager.getTable(unitId, tableId);
@@ -4644,6 +4821,10 @@ let TableFilterController = class TableFilterController extends _univerjs_core.D
4644
4821
  table.getTableFilters().doFilter(worksheet, table.getTableFilterRange(), workbook === null || workbook === void 0 ? void 0 : workbook.getDateSystem());
4645
4822
  this._refreshTableFilteredOutRows(unitId, subUnitId);
4646
4823
  this._zebraCrossingCacheController.updateZebraCrossingCache(unitId, subUnitId);
4824
+ if (oldSubUnitId && oldSubUnitId !== subUnitId) {
4825
+ this._refreshTableFilteredOutRows(unitId, oldSubUnitId);
4826
+ this._zebraCrossingCacheController.updateZebraCrossingCache(unitId, oldSubUnitId);
4827
+ }
4647
4828
  }));
4648
4829
  }
4649
4830
  _refreshTableFilteredOutRows(unitId, subUnitId) {
@@ -4664,9 +4845,8 @@ let TableFilterController = class TableFilterController extends _univerjs_core.D
4664
4845
  return `${unitId}|${subUnitId}`;
4665
4846
  }
4666
4847
  dispose() {
4667
- var _this$_subscription;
4668
4848
  super.dispose();
4669
- (_this$_subscription = this._subscription) === null || _this$_subscription === void 0 || _this$_subscription.unsubscribe();
4849
+ this._tableFilteredOutRows.clear();
4670
4850
  }
4671
4851
  };
4672
4852
  TableFilterController = __decorate([
@@ -4699,6 +4879,7 @@ let UniverSheetsTablePlugin = class UniverSheetsTablePlugin extends _univerjs_co
4699
4879
  [TableFilterController],
4700
4880
  [SheetTableRangeController],
4701
4881
  [SheetTableRefRangeController],
4882
+ [SheetTableMoveController],
4702
4883
  [SheetTableFormulaController]
4703
4884
  ]);
4704
4885
  }
@@ -4707,6 +4888,7 @@ let UniverSheetsTablePlugin = class UniverSheetsTablePlugin extends _univerjs_co
4707
4888
  [SheetTableFormulaController],
4708
4889
  [SheetTableRangeController],
4709
4890
  [SheetTableRefRangeController],
4891
+ [SheetTableMoveController],
4710
4892
  [SheetsTableThemeController],
4711
4893
  [SheetsTableController],
4712
4894
  [SheetTableService],
@@ -4720,6 +4902,7 @@ let UniverSheetsTablePlugin = class UniverSheetsTablePlugin extends _univerjs_co
4720
4902
  AddSheetTableMutation,
4721
4903
  DeleteSheetTableCommand,
4722
4904
  DeleteSheetTableMutation,
4905
+ MoveSheetTableMutation,
4723
4906
  SetSheetTableFilterMutation,
4724
4907
  SetSheetTableFilterCommand,
4725
4908
  SetSheetTableSortStateCommand,
@@ -4768,21 +4951,21 @@ exports.SheetTableInsertRowCommand = SheetTableInsertRowCommand;
4768
4951
  exports.SheetTableRemoveColCommand = SheetTableRemoveColCommand;
4769
4952
  exports.SheetTableRemoveColumnAtCommand = SheetTableRemoveColumnAtCommand;
4770
4953
  exports.SheetTableRemoveRowCommand = SheetTableRemoveRowCommand;
4771
- Object.defineProperty(exports, 'SheetTableService', {
4954
+ Object.defineProperty(exports, "SheetTableService", {
4772
4955
  enumerable: true,
4773
4956
  get: function () {
4774
4957
  return SheetTableService;
4775
4958
  }
4776
4959
  });
4777
4960
  exports.SheetsTableButtonStateEnum = SheetsTableButtonStateEnum;
4778
- Object.defineProperty(exports, 'SheetsTableController', {
4961
+ Object.defineProperty(exports, "SheetsTableController", {
4779
4962
  enumerable: true,
4780
4963
  get: function () {
4781
4964
  return SheetsTableController;
4782
4965
  }
4783
4966
  });
4784
4967
  exports.SheetsTableSortStateEnum = SheetsTableSortStateEnum;
4785
- Object.defineProperty(exports, 'SheetsTableThemeController', {
4968
+ Object.defineProperty(exports, "SheetsTableThemeController", {
4786
4969
  enumerable: true,
4787
4970
  get: function () {
4788
4971
  return SheetsTableThemeController;
@@ -4793,7 +4976,7 @@ exports.TableColumnDataTypeEnum = TableColumnDataTypeEnum;
4793
4976
  exports.TableColumnFilterTypeEnum = TableColumnFilterTypeEnum;
4794
4977
  exports.TableConditionTypeEnum = TableConditionTypeEnum;
4795
4978
  exports.TableDateCompareTypeEnum = TableDateCompareTypeEnum;
4796
- Object.defineProperty(exports, 'TableManager', {
4979
+ Object.defineProperty(exports, "TableManager", {
4797
4980
  enumerable: true,
4798
4981
  get: function () {
4799
4982
  return TableManager;
@@ -4801,7 +4984,7 @@ Object.defineProperty(exports, 'TableManager', {
4801
4984
  });
4802
4985
  exports.TableNumberCompareTypeEnum = TableNumberCompareTypeEnum;
4803
4986
  exports.TableStringCompareTypeEnum = TableStringCompareTypeEnum;
4804
- Object.defineProperty(exports, 'UniverSheetsTablePlugin', {
4987
+ Object.defineProperty(exports, "UniverSheetsTablePlugin", {
4805
4988
  enumerable: true,
4806
4989
  get: function () {
4807
4990
  return UniverSheetsTablePlugin;
@@ -2,6 +2,7 @@
2
2
  const locale = { "sheets-table": {
3
3
  columnPrefix: "عمود",
4
4
  tablePrefix: "جدول",
5
+ moveTableOverlapError: "يتداخل نطاق الوجهة مع جدول آخر.",
5
6
  tableNameError: "لا يمكن أن يحتوي اسم الجدول على مسافات، ولا يمكن أن يبدأ برقم، ولا يمكن أن يكون مطابقًا لاسم جدول موجود"
6
7
  } };
7
8
 
@@ -2,6 +2,7 @@
2
2
  const locale = { "sheets-table": {
3
3
  columnPrefix: "Columna",
4
4
  tablePrefix: "Taula",
5
+ moveTableOverlapError: "La destinació se superposa amb una altra taula.",
5
6
  tableNameError: "El nom de la taula no pot contenir espais, no pot començar amb un número i no pot ser idèntic a un nom de taula existent"
6
7
  } };
7
8
 
@@ -2,6 +2,7 @@
2
2
  const locale = { "sheets-table": {
3
3
  columnPrefix: "Spalte",
4
4
  tablePrefix: "Tabelle",
5
+ moveTableOverlapError: "Der Zielbereich überschneidet sich mit einer anderen Tabelle.",
5
6
  tableNameError: "Tabellenname darf keine Leerzeichen enthalten, darf nicht mit einer Zahl beginnen und darf nicht mit einem vorhandenen Tabellennamen identisch sein"
6
7
  } };
7
8
 
@@ -17,6 +17,7 @@
17
17
  const locale = { "sheets-table": {
18
18
  columnPrefix: "Column",
19
19
  tablePrefix: "Table",
20
+ moveTableOverlapError: "The destination overlaps another table.",
20
21
  tableNameError: "Table name cannot contain spaces, cannot start with a number, and cannot be identical to an existing table name"
21
22
  } };
22
23
 
@@ -2,6 +2,7 @@
2
2
  const locale = { "sheets-table": {
3
3
  columnPrefix: "Columna",
4
4
  tablePrefix: "Tabla",
5
+ moveTableOverlapError: "El destino se superpone con otra tabla.",
5
6
  tableNameError: "El nombre de la tabla no puede contener espacios, no puede comenzar con un número y no puede ser idéntico a un nombre de tabla existente"
6
7
  } };
7
8
 
@@ -2,6 +2,7 @@
2
2
  const locale = { "sheets-table": {
3
3
  columnPrefix: "ستون",
4
4
  tablePrefix: "جدول",
5
+ moveTableOverlapError: "محدودهٔ مقصد با جدول دیگری هم‌پوشانی دارد.",
5
6
  tableNameError: "نام جدول نمی‌تواند شامل فاصله باشد، نمی‌تواند با عدد شروع شود و نمی‌تواند با نام جدول‌های موجود تکراری باشد"
6
7
  } };
7
8
 
@@ -2,6 +2,7 @@
2
2
  const locale = { "sheets-table": {
3
3
  columnPrefix: "Colonne",
4
4
  tablePrefix: "Tableau",
5
+ moveTableOverlapError: "La destination chevauche un autre tableau.",
5
6
  tableNameError: "Le nom du tableau ne peut pas contenir d'espaces, ne peut pas commencer par un chiffre et ne peut pas être identique à un nom de tableau existant"
6
7
  } };
7
8
 
@@ -2,6 +2,7 @@
2
2
  const locale = { "sheets-table": {
3
3
  columnPrefix: "Kolom",
4
4
  tablePrefix: "Tabel",
5
+ moveTableOverlapError: "Rentang tujuan tumpang tindih dengan tabel lain.",
5
6
  tableNameError: "Nama tabel tidak boleh mengandung spasi, tidak boleh diawali dengan angka, dan tidak boleh sama dengan nama tabel yang sudah ada"
6
7
  } };
7
8
 
@@ -2,6 +2,7 @@
2
2
  const locale = { "sheets-table": {
3
3
  columnPrefix: "Colonna",
4
4
  tablePrefix: "Tabella",
5
+ moveTableOverlapError: "La destinazione si sovrappone a un’altra tabella.",
5
6
  tableNameError: "Il nome della tabella non può contenere spazi, non può iniziare con un numero e non può essere identico a un nome di tabella esistente"
6
7
  } };
7
8
 
@@ -2,6 +2,7 @@
2
2
  const locale = { "sheets-table": {
3
3
  columnPrefix: "列",
4
4
  tablePrefix: "表",
5
+ moveTableOverlapError: "移動先が他のテーブルと重なっています。",
5
6
  tableNameError: "表の名前は空白を含めることはできず、数字で始めることはできず、既存の表名と重複できません"
6
7
  } };
7
8
 
@@ -2,6 +2,7 @@
2
2
  const locale = { "sheets-table": {
3
3
  columnPrefix: "열",
4
4
  tablePrefix: "표",
5
+ moveTableOverlapError: "대상 범위가 다른 표와 겹칩니다.",
5
6
  tableNameError: "표 이름은 공백을 포함할 수 없으며 숫자로 시작할 수 없고 기존 표 이름과 중복될 수 없습니다"
6
7
  } };
7
8