@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 +75 -62
- package/lib/es/index.js +75 -62
- package/lib/index.js +75 -62
- package/lib/umd/index.js +1 -1
- package/package.json +20 -20
- package/lib/types/views/components/formula-input/formula-input.d.ts +0 -19
package/lib/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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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
|
-
|
|
1338
|
+
const target = getSheetCommandTarget(this._univerInstanceService, {
|
|
1334
1339
|
unitId: pastedUnitId,
|
|
1335
1340
|
subUnitId: pastedSubUnitId
|
|
1336
|
-
})
|
|
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
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
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:
|
|
1369
|
-
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
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
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:
|
|
1396
|
-
})
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
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([
|