@univerjs/sheets-data-validation-ui 1.6.2 → 1.7.0-alpha.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.
package/lib/cjs/index.js CHANGED
@@ -11,12 +11,12 @@ let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
11
11
  let _univerjs_design = require("@univerjs/design");
12
12
  let react = require("react");
13
13
  let react_jsx_runtime = require("react/jsx-runtime");
14
+ let _univerjs_engine_formula = require("@univerjs/engine-formula");
14
15
  let _univerjs_icons = require("@univerjs/icons");
15
16
  let _univerjs_icons_svg = require("@univerjs/icons-svg");
16
- let _univerjs_engine_formula = require("@univerjs/engine-formula");
17
17
  let _univerjs_sheets_formula_ui = require("@univerjs/sheets-formula-ui");
18
18
 
19
- // \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
19
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/typeof.js
20
20
  function _typeof(o) {
21
21
  "@babel/helpers - typeof";
22
22
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -26,7 +26,7 @@ function _typeof(o) {
26
26
  }, _typeof(o);
27
27
  }
28
28
 
29
- // \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
29
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/toPrimitive.js
30
30
  function toPrimitive(t, e) {
31
31
  if ("object" != _typeof(t) || !t) return t;
32
32
  var r;
@@ -38,13 +38,13 @@ function toPrimitive(t, e) {
38
38
  return ("string" === e ? String : Number)(t);
39
39
  }
40
40
 
41
- // \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
41
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/toPropertyKey.js
42
42
  function toPropertyKey(t) {
43
43
  var i = toPrimitive(t, "string");
44
44
  return "symbol" == _typeof(i) ? i : i + "";
45
45
  }
46
46
 
47
- // \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
47
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/defineProperty.js
48
48
  function _defineProperty(e, r, t) {
49
49
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
50
50
  value: t,
@@ -54,14 +54,14 @@ function _defineProperty(e, r, t) {
54
54
  }) : e[r] = t, e;
55
55
  }
56
56
 
57
- // \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
57
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/decorateParam.js
58
58
  function __decorateParam(paramIndex, decorator) {
59
59
  return function(target, key) {
60
60
  decorator(target, key, paramIndex);
61
61
  };
62
62
  }
63
63
 
64
- // \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
64
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/decorate.js
65
65
  function __decorate(decorators, target, key, desc) {
66
66
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
67
67
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1065,7 +1065,7 @@ const menuSchema = {
1065
1065
 
1066
1066
  // package.json
1067
1067
  var name = "@univerjs/sheets-data-validation-ui";
1068
- var version = "1.6.2";
1068
+ var version = "1.7.0-alpha.0";
1069
1069
 
1070
1070
  // src/controllers/dv-alert.controller.ts
1071
1071
  const ALERT_KEY = "SHEET_DATA_VALIDATION_ALERT";
@@ -1292,7 +1292,7 @@ let DataValidationCopyPasteController = class DataValidationCopyPasteController
1292
1292
  _initCopyPaste() {
1293
1293
  this._sheetClipboardService.addClipboardHook({
1294
1294
  id: _univerjs_sheets_data_validation.DATA_VALIDATION_PLUGIN_NAME,
1295
- onBeforeCopy: (unitId, subUnitId, range) => this._collect(unitId, subUnitId, range),
1295
+ onBeforeCopy: (unitId, subUnitId, range, _copyType, discreteRange) => this._collect(unitId, subUnitId, range, discreteRange),
1296
1296
  onPasteCells: (pasteFrom, pasteTo, data, payload) => {
1297
1297
  if (!pasteFrom || !this._copyInfo || specialPastes.includes(payload.pasteType)) return {
1298
1298
  redos: [],
@@ -1302,24 +1302,29 @@ let DataValidationCopyPasteController = class DataValidationCopyPasteController
1302
1302
  }
1303
1303
  });
1304
1304
  }
1305
- _collect(unitId, subUnitId, range) {
1305
+ _collect(unitId, subUnitId, range, sourceRange) {
1306
+ var _getSheetCommandTarge;
1306
1307
  const rules = /* @__PURE__ */ new Map();
1307
1308
  this._copyInfo = {
1308
1309
  unitId,
1309
1310
  subUnitId,
1310
1311
  rules
1311
1312
  };
1312
- const discreteRange = this._injector.invoke((accessor) => {
1313
+ const discreteRange = sourceRange ?? this._injector.invoke((accessor) => {
1313
1314
  return (0, _univerjs_sheets.rangeToDiscreteRange)(range, accessor, unitId, subUnitId);
1314
1315
  });
1315
1316
  if (!discreteRange) return;
1316
- const { projectRange } = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([discreteRange]);
1317
+ const worksheet = (_getSheetCommandTarge = (0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, {
1318
+ unitId,
1319
+ subUnitId
1320
+ })) === null || _getSheetCommandTarge === void 0 ? void 0 : _getSheetCommandTarge.worksheet;
1321
+ const { projectRange } = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([discreteRange], worksheet);
1317
1322
  this._sheetDataValidationModel.getRules(unitId, subUnitId).forEach((rule) => {
1318
1323
  const projectedRanges = rule.ranges.flatMap((ruleRange) => {
1319
1324
  const projected = projectRange(ruleRange);
1320
1325
  return projected ? [projected] : [];
1321
1326
  });
1322
- if (projectedRanges.length) rules.set(rule.uid, projectedRanges.length > 1 ? _univerjs_core.Rectangle.mergeRanges(projectedRanges) : projectedRanges);
1327
+ if (projectedRanges.length) rules.set(rule.uid, projectedRanges);
1323
1328
  });
1324
1329
  }
1325
1330
  _generateMutations(pasteFrom, pasteTo, payload) {
@@ -1331,10 +1336,11 @@ let DataValidationCopyPasteController = class DataValidationCopyPasteController
1331
1336
  const { unitId: copyUnitId, subUnitId: copySubUnitId, range: copyRange } = pasteFrom;
1332
1337
  const { unitId: pastedUnitId, subUnitId: pastedSubUnitId, range: pastedRange } = pasteTo;
1333
1338
  const { copyType = _univerjs_sheets_ui.COPY_TYPE.COPY } = payload;
1334
- if (!(0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, {
1339
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, {
1335
1340
  unitId: pastedUnitId,
1336
1341
  subUnitId: pastedSubUnitId
1337
- })) return {
1342
+ });
1343
+ if (!target) return {
1338
1344
  redos: [],
1339
1345
  undos: []
1340
1346
  };
@@ -1346,62 +1352,69 @@ let DataValidationCopyPasteController = class DataValidationCopyPasteController
1346
1352
  };
1347
1353
  }
1348
1354
  const sourceVirtualRange = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange]).ranges[0];
1349
- const targetVirtualization = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([pastedRange]);
1355
+ const targetVirtualization = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([pastedRange], target.worksheet);
1350
1356
  const targetVirtualRange = targetVirtualization.ranges[0];
1351
1357
  const repeatRange = (0, _univerjs_sheets_ui.getRepeatRange)(sourceVirtualRange, targetVirtualRange, true);
1352
1358
  const clearTargetRanges = targetVirtualization.mapRange(targetVirtualRange);
1353
1359
  const getTargetRanges = (sourceRanges) => repeatRange.flatMap(({ startRange }) => sourceRanges.flatMap((sourceRange) => targetVirtualization.mapRange(_univerjs_core.Rectangle.moveOffset(sourceRange, startRange.startColumn, startRange.startRow))));
1354
- if (pastedUnitId !== copyUnitId || pastedSubUnitId !== copySubUnitId) {
1355
- const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(pastedUnitId, pastedSubUnitId).clone();
1356
- const additionRules = /* @__PURE__ */ new Map();
1357
- const additions = [{
1358
- id: "",
1359
- ranges: clearTargetRanges
1360
- }];
1361
- copyInfo.rules.forEach((ranges, ruleId) => {
1362
- const transformedRuleId = `${copySubUnitId}-${ruleId}`;
1363
- const oldRule = this._sheetDataValidationModel.getRuleById(copyUnitId, copySubUnitId, ruleId);
1364
- if (!this._sheetDataValidationModel.getRuleById(pastedUnitId, pastedSubUnitId, transformedRuleId) && oldRule) additionRules.set(transformedRuleId, {
1365
- ...oldRule,
1366
- uid: transformedRuleId
1367
- });
1360
+ const sameSheet = pastedUnitId === copyUnitId && pastedSubUnitId === copySubUnitId;
1361
+ const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(pastedUnitId, pastedSubUnitId).clone();
1362
+ const additionRules = /* @__PURE__ */ new Map();
1363
+ const additions = [{
1364
+ id: "",
1365
+ ranges: clearTargetRanges
1366
+ }];
1367
+ const lexer = this._injector.get(_univerjs_engine_formula.LexerTreeBuilder);
1368
+ const registry = this._injector.get(_univerjs_data_validation.DataValidatorRegistryService);
1369
+ copyInfo.rules.forEach((ranges, ruleId) => {
1370
+ var _registry$getValidato;
1371
+ const source = this._sheetDataValidationModel.getRuleById(copyUnitId, copySubUnitId, ruleId);
1372
+ const targetRanges = _univerjs_core.Rectangle.sort(getTargetRanges(ranges));
1373
+ if (!source || !targetRanges.length) return;
1374
+ const list = source.type === _univerjs_core.DataValidationType.LIST || source.type === _univerjs_core.DataValidationType.LIST_MULTIPLE;
1375
+ const x = targetRanges[0].startColumn - source.ranges[0].startColumn;
1376
+ const y = targetRanges[0].startRow - source.ranges[0].startRow;
1377
+ const offset = (formula) => formula && (0, _univerjs_core.isFormulaString)(formula) ? lexer.moveFormulaRefOffset(formula, x, y) : formula;
1378
+ const translate = list || ((_registry$getValidato = registry.getValidatorItem(source.type)) === null || _registry$getValidato === void 0 ? void 0 : _registry$getValidato.offsetFormulaByRange);
1379
+ const formula1 = translate ? offset(source.formula1) : source.formula1;
1380
+ const formula2 = translate ? offset(source.formula2) : source.formula2;
1381
+ if (sameSheet && !(list && formula1 !== source.formula1)) {
1368
1382
  additions.push({
1369
- id: transformedRuleId,
1370
- ranges: getTargetRanges(ranges)
1383
+ id: ruleId,
1384
+ ranges: targetRanges
1371
1385
  });
1372
- });
1373
- ruleMatrix.addRangeRules(additions);
1374
- const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diffWithAddition(this._sheetDataValidationModel.getRules(pastedUnitId, pastedSubUnitId), additionRules.values()), this._injector, "patched", false);
1375
- if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT) {
1376
- const copySheetRuleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1377
- copySheetRuleMatrix.addRangeRules([{
1378
- id: "",
1379
- ranges: (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange]).mapRange(sourceVirtualRange)
1380
- }]);
1381
- const { redoMutations: cutRedos, undoMutations: cutUndos } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(copyUnitId, copySubUnitId, copySheetRuleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1382
- redoMutations.push(...cutRedos);
1383
- undoMutations.push(...cutUndos);
1386
+ return;
1384
1387
  }
1385
- return {
1386
- redos: redoMutations,
1387
- undos: undoMutations
1388
- };
1389
- } else {
1390
- const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1391
- const additions = [{
1392
- id: "",
1393
- ranges: clearTargetRanges
1394
- }, ...Array.from(copyInfo.rules, ([id, ranges]) => ({
1388
+ let id = `${copySubUnitId}-${ruleId}`;
1389
+ if (this._sheetDataValidationModel.getRuleById(pastedUnitId, pastedSubUnitId, id)) id = (0, _univerjs_core.generateRandomId)();
1390
+ additionRules.set(id, {
1391
+ ...source,
1392
+ uid: id,
1393
+ ranges: targetRanges,
1394
+ formula1,
1395
+ formula2
1396
+ });
1397
+ additions.push({
1395
1398
  id,
1396
- ranges: getTargetRanges(ranges)
1397
- }))];
1398
- ruleMatrix.addRangeRules(additions);
1399
- const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1400
- return {
1401
- redos: redoMutations,
1402
- undos: undoMutations
1403
- };
1399
+ ranges: targetRanges
1400
+ });
1401
+ });
1402
+ ruleMatrix.addRangeRules(additions);
1403
+ const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diffWithAddition(this._sheetDataValidationModel.getRules(pastedUnitId, pastedSubUnitId), additionRules.values()).filter((diff) => !payload.movesCells || diff.type === "add"), this._injector, "patched", false);
1404
+ if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT && !payload.movesCells) {
1405
+ const copySheetRuleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1406
+ copySheetRuleMatrix.addRangeRules([{
1407
+ id: "",
1408
+ ranges: (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange]).mapRange(sourceVirtualRange)
1409
+ }]);
1410
+ const { redoMutations: cutRedos, undoMutations: cutUndos } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(copyUnitId, copySubUnitId, copySheetRuleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1411
+ redoMutations.push(...cutRedos);
1412
+ undoMutations.push(...cutUndos);
1404
1413
  }
1414
+ return {
1415
+ redos: redoMutations,
1416
+ undos: undoMutations
1417
+ };
1405
1418
  }
1406
1419
  };
1407
1420
  DataValidationCopyPasteController = __decorate([
package/lib/es/index.js CHANGED
@@ -10,12 +10,12 @@ import { AutoHeightController, COPY_TYPE, CellAlertManagerService, CellAlertType
10
10
  import { ActionRow, Button, Checkbox, DraggableList, Dropdown as Dropdown$1, FormLayout, Input, Radio, RadioGroup, Select, Separator, borderClassName, clsx } from "@univerjs/design";
11
11
  import { createElement, useEffect, useMemo, useRef, useState } from "react";
12
12
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
+ import { LexerTreeBuilder, deserializeRangeWithSheet, serializeRange } from "@univerjs/engine-formula";
13
14
  import { CheckboxIcon, DataValidationIcon, DatePickerIcon, DeleteIcon, DropdownListIcon, GripVerticalIcon, IncreaseIcon, MoreDownIcon, MoreUpIcon } from "@univerjs/icons";
14
15
  import { drawCanvasIcon } from "@univerjs/icons-svg";
15
- import { deserializeRangeWithSheet, serializeRange } from "@univerjs/engine-formula";
16
16
  import { FormulaEditor, RangeSelector } from "@univerjs/sheets-formula-ui";
17
17
 
18
- // \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
18
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/typeof.js
19
19
  function _typeof(o) {
20
20
  "@babel/helpers - typeof";
21
21
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -25,7 +25,7 @@ function _typeof(o) {
25
25
  }, _typeof(o);
26
26
  }
27
27
 
28
- // \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
28
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/toPrimitive.js
29
29
  function toPrimitive(t, e) {
30
30
  if ("object" != _typeof(t) || !t) return t;
31
31
  var r;
@@ -37,13 +37,13 @@ function toPrimitive(t, e) {
37
37
  return ("string" === e ? String : Number)(t);
38
38
  }
39
39
 
40
- // \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
40
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/toPropertyKey.js
41
41
  function toPropertyKey(t) {
42
42
  var i = toPrimitive(t, "string");
43
43
  return "symbol" == _typeof(i) ? i : i + "";
44
44
  }
45
45
 
46
- // \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
46
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/defineProperty.js
47
47
  function _defineProperty(e, r, t) {
48
48
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
49
49
  value: t,
@@ -53,14 +53,14 @@ function _defineProperty(e, r, t) {
53
53
  }) : e[r] = t, e;
54
54
  }
55
55
 
56
- // \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
56
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/decorateParam.js
57
57
  function __decorateParam(paramIndex, decorator) {
58
58
  return function(target, key) {
59
59
  decorator(target, key, paramIndex);
60
60
  };
61
61
  }
62
62
 
63
- // \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
63
+ // \0@oxc-project+runtime@0.160.0/helpers/esm/decorate.js
64
64
  function __decorate(decorators, target, key, desc) {
65
65
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
66
66
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1064,7 +1064,7 @@ const menuSchema = {
1064
1064
 
1065
1065
  // package.json
1066
1066
  var name = "@univerjs/sheets-data-validation-ui";
1067
- var version = "1.6.2";
1067
+ var version = "1.7.0-alpha.0";
1068
1068
 
1069
1069
  // src/controllers/dv-alert.controller.ts
1070
1070
  const ALERT_KEY = "SHEET_DATA_VALIDATION_ALERT";
@@ -1291,7 +1291,7 @@ let DataValidationCopyPasteController = class DataValidationCopyPasteController
1291
1291
  _initCopyPaste() {
1292
1292
  this._sheetClipboardService.addClipboardHook({
1293
1293
  id: DATA_VALIDATION_PLUGIN_NAME,
1294
- onBeforeCopy: (unitId, subUnitId, range) => this._collect(unitId, subUnitId, range),
1294
+ onBeforeCopy: (unitId, subUnitId, range, _copyType, discreteRange) => this._collect(unitId, subUnitId, range, discreteRange),
1295
1295
  onPasteCells: (pasteFrom, pasteTo, data, payload) => {
1296
1296
  if (!pasteFrom || !this._copyInfo || specialPastes.includes(payload.pasteType)) return {
1297
1297
  redos: [],
@@ -1301,24 +1301,29 @@ let DataValidationCopyPasteController = class DataValidationCopyPasteController
1301
1301
  }
1302
1302
  });
1303
1303
  }
1304
- _collect(unitId, subUnitId, range) {
1304
+ _collect(unitId, subUnitId, range, sourceRange) {
1305
+ var _getSheetCommandTarge;
1305
1306
  const rules = /* @__PURE__ */ new Map();
1306
1307
  this._copyInfo = {
1307
1308
  unitId,
1308
1309
  subUnitId,
1309
1310
  rules
1310
1311
  };
1311
- const discreteRange = this._injector.invoke((accessor) => {
1312
+ const discreteRange = sourceRange ?? this._injector.invoke((accessor) => {
1312
1313
  return rangeToDiscreteRange(range, accessor, unitId, subUnitId);
1313
1314
  });
1314
1315
  if (!discreteRange) return;
1315
- const { projectRange } = virtualizeDiscreteRanges([discreteRange]);
1316
+ const worksheet = (_getSheetCommandTarge = getSheetCommandTarget(this._univerInstanceService, {
1317
+ unitId,
1318
+ subUnitId
1319
+ })) === null || _getSheetCommandTarge === void 0 ? void 0 : _getSheetCommandTarge.worksheet;
1320
+ const { projectRange } = virtualizeDiscreteRanges([discreteRange], worksheet);
1316
1321
  this._sheetDataValidationModel.getRules(unitId, subUnitId).forEach((rule) => {
1317
1322
  const projectedRanges = rule.ranges.flatMap((ruleRange) => {
1318
1323
  const projected = projectRange(ruleRange);
1319
1324
  return projected ? [projected] : [];
1320
1325
  });
1321
- if (projectedRanges.length) rules.set(rule.uid, projectedRanges.length > 1 ? Rectangle.mergeRanges(projectedRanges) : projectedRanges);
1326
+ if (projectedRanges.length) rules.set(rule.uid, projectedRanges);
1322
1327
  });
1323
1328
  }
1324
1329
  _generateMutations(pasteFrom, pasteTo, payload) {
@@ -1330,10 +1335,11 @@ let DataValidationCopyPasteController = class DataValidationCopyPasteController
1330
1335
  const { unitId: copyUnitId, subUnitId: copySubUnitId, range: copyRange } = pasteFrom;
1331
1336
  const { unitId: pastedUnitId, subUnitId: pastedSubUnitId, range: pastedRange } = pasteTo;
1332
1337
  const { copyType = COPY_TYPE.COPY } = payload;
1333
- if (!getSheetCommandTarget(this._univerInstanceService, {
1338
+ const target = getSheetCommandTarget(this._univerInstanceService, {
1334
1339
  unitId: pastedUnitId,
1335
1340
  subUnitId: pastedSubUnitId
1336
- })) return {
1341
+ });
1342
+ if (!target) return {
1337
1343
  redos: [],
1338
1344
  undos: []
1339
1345
  };
@@ -1345,62 +1351,69 @@ let DataValidationCopyPasteController = class DataValidationCopyPasteController
1345
1351
  };
1346
1352
  }
1347
1353
  const sourceVirtualRange = virtualizeDiscreteRanges([copyRange]).ranges[0];
1348
- const targetVirtualization = virtualizeDiscreteRanges([pastedRange]);
1354
+ const targetVirtualization = virtualizeDiscreteRanges([pastedRange], target.worksheet);
1349
1355
  const targetVirtualRange = targetVirtualization.ranges[0];
1350
1356
  const repeatRange = getRepeatRange(sourceVirtualRange, targetVirtualRange, true);
1351
1357
  const clearTargetRanges = targetVirtualization.mapRange(targetVirtualRange);
1352
1358
  const getTargetRanges = (sourceRanges) => repeatRange.flatMap(({ startRange }) => sourceRanges.flatMap((sourceRange) => targetVirtualization.mapRange(Rectangle.moveOffset(sourceRange, startRange.startColumn, startRange.startRow))));
1353
- if (pastedUnitId !== copyUnitId || pastedSubUnitId !== copySubUnitId) {
1354
- const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(pastedUnitId, pastedSubUnitId).clone();
1355
- const additionRules = /* @__PURE__ */ new Map();
1356
- const additions = [{
1357
- id: "",
1358
- ranges: clearTargetRanges
1359
- }];
1360
- copyInfo.rules.forEach((ranges, ruleId) => {
1361
- const transformedRuleId = `${copySubUnitId}-${ruleId}`;
1362
- const oldRule = this._sheetDataValidationModel.getRuleById(copyUnitId, copySubUnitId, ruleId);
1363
- if (!this._sheetDataValidationModel.getRuleById(pastedUnitId, pastedSubUnitId, transformedRuleId) && oldRule) additionRules.set(transformedRuleId, {
1364
- ...oldRule,
1365
- uid: transformedRuleId
1366
- });
1359
+ const sameSheet = pastedUnitId === copyUnitId && pastedSubUnitId === copySubUnitId;
1360
+ const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(pastedUnitId, pastedSubUnitId).clone();
1361
+ const additionRules = /* @__PURE__ */ new Map();
1362
+ const additions = [{
1363
+ id: "",
1364
+ ranges: clearTargetRanges
1365
+ }];
1366
+ const lexer = this._injector.get(LexerTreeBuilder);
1367
+ const registry = this._injector.get(DataValidatorRegistryService);
1368
+ copyInfo.rules.forEach((ranges, ruleId) => {
1369
+ var _registry$getValidato;
1370
+ const source = this._sheetDataValidationModel.getRuleById(copyUnitId, copySubUnitId, ruleId);
1371
+ const targetRanges = Rectangle.sort(getTargetRanges(ranges));
1372
+ if (!source || !targetRanges.length) return;
1373
+ const list = source.type === DataValidationType.LIST || source.type === DataValidationType.LIST_MULTIPLE;
1374
+ const x = targetRanges[0].startColumn - source.ranges[0].startColumn;
1375
+ const y = targetRanges[0].startRow - source.ranges[0].startRow;
1376
+ const offset = (formula) => formula && isFormulaString(formula) ? lexer.moveFormulaRefOffset(formula, x, y) : formula;
1377
+ const translate = list || ((_registry$getValidato = registry.getValidatorItem(source.type)) === null || _registry$getValidato === void 0 ? void 0 : _registry$getValidato.offsetFormulaByRange);
1378
+ const formula1 = translate ? offset(source.formula1) : source.formula1;
1379
+ const formula2 = translate ? offset(source.formula2) : source.formula2;
1380
+ if (sameSheet && !(list && formula1 !== source.formula1)) {
1367
1381
  additions.push({
1368
- id: transformedRuleId,
1369
- ranges: getTargetRanges(ranges)
1382
+ id: ruleId,
1383
+ ranges: targetRanges
1370
1384
  });
1371
- });
1372
- ruleMatrix.addRangeRules(additions);
1373
- const { redoMutations, undoMutations } = getDataValidationDiffMutations(pastedUnitId, pastedSubUnitId, ruleMatrix.diffWithAddition(this._sheetDataValidationModel.getRules(pastedUnitId, pastedSubUnitId), additionRules.values()), this._injector, "patched", false);
1374
- if (copyType === COPY_TYPE.CUT) {
1375
- const copySheetRuleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1376
- copySheetRuleMatrix.addRangeRules([{
1377
- id: "",
1378
- ranges: virtualizeDiscreteRanges([copyRange]).mapRange(sourceVirtualRange)
1379
- }]);
1380
- const { redoMutations: cutRedos, undoMutations: cutUndos } = getDataValidationDiffMutations(copyUnitId, copySubUnitId, copySheetRuleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1381
- redoMutations.push(...cutRedos);
1382
- undoMutations.push(...cutUndos);
1385
+ return;
1383
1386
  }
1384
- return {
1385
- redos: redoMutations,
1386
- undos: undoMutations
1387
- };
1388
- } else {
1389
- const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1390
- const additions = [{
1391
- id: "",
1392
- ranges: clearTargetRanges
1393
- }, ...Array.from(copyInfo.rules, ([id, ranges]) => ({
1387
+ let id = `${copySubUnitId}-${ruleId}`;
1388
+ if (this._sheetDataValidationModel.getRuleById(pastedUnitId, pastedSubUnitId, id)) id = generateRandomId();
1389
+ additionRules.set(id, {
1390
+ ...source,
1391
+ uid: id,
1392
+ ranges: targetRanges,
1393
+ formula1,
1394
+ formula2
1395
+ });
1396
+ additions.push({
1394
1397
  id,
1395
- ranges: getTargetRanges(ranges)
1396
- }))];
1397
- ruleMatrix.addRangeRules(additions);
1398
- const { redoMutations, undoMutations } = getDataValidationDiffMutations(pastedUnitId, pastedSubUnitId, ruleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1399
- return {
1400
- redos: redoMutations,
1401
- undos: undoMutations
1402
- };
1398
+ ranges: targetRanges
1399
+ });
1400
+ });
1401
+ ruleMatrix.addRangeRules(additions);
1402
+ const { redoMutations, undoMutations } = getDataValidationDiffMutations(pastedUnitId, pastedSubUnitId, ruleMatrix.diffWithAddition(this._sheetDataValidationModel.getRules(pastedUnitId, pastedSubUnitId), additionRules.values()).filter((diff) => !payload.movesCells || diff.type === "add"), this._injector, "patched", false);
1403
+ if (copyType === COPY_TYPE.CUT && !payload.movesCells) {
1404
+ const copySheetRuleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1405
+ copySheetRuleMatrix.addRangeRules([{
1406
+ id: "",
1407
+ ranges: virtualizeDiscreteRanges([copyRange]).mapRange(sourceVirtualRange)
1408
+ }]);
1409
+ const { redoMutations: cutRedos, undoMutations: cutUndos } = getDataValidationDiffMutations(copyUnitId, copySubUnitId, copySheetRuleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1410
+ redoMutations.push(...cutRedos);
1411
+ undoMutations.push(...cutUndos);
1403
1412
  }
1413
+ return {
1414
+ redos: redoMutations,
1415
+ undos: undoMutations
1416
+ };
1404
1417
  }
1405
1418
  };
1406
1419
  DataValidationCopyPasteController = __decorate([