@univerjs/sheets-data-validation 0.2.6 → 0.2.7

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/es/index.js CHANGED
@@ -354,25 +354,26 @@ var __defProp$i = Object.defineProperty, __getOwnPropDesc$i = Object.getOwnPrope
354
354
  return kind && result && __defProp$i(target, key, result), result;
355
355
  }, "__decorateClass$i"), __decorateParam$i = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$i"), _a3;
356
356
  let DataValidationFormulaService = (_a3 = class extends Disposable {
357
- constructor(_registerOtherFormulaService, _dataValidationCacheService, _dataValidationModel) {
357
+ constructor(_instanceService, _registerOtherFormulaService, _dataValidationCacheService, _dataValidationModel) {
358
358
  super();
359
359
  __publicField(this, "_formulaRuleMap", /* @__PURE__ */ new Map());
360
- this._registerOtherFormulaService = _registerOtherFormulaService, this._dataValidationCacheService = _dataValidationCacheService, this._dataValidationModel = _dataValidationModel, this._initFormulaResultHandler();
360
+ this._instanceService = _instanceService, this._registerOtherFormulaService = _registerOtherFormulaService, this._dataValidationCacheService = _dataValidationCacheService, this._dataValidationModel = _dataValidationModel, this._initFormulaResultHandler();
361
361
  }
362
362
  _initFormulaResultHandler() {
363
363
  this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
364
364
  for (const unitId in resultMap) {
365
365
  const unitMap = resultMap[unitId];
366
- for (const subUnitId in unitMap) {
367
- const results = unitMap[subUnitId], formulaMap = this._ensureRuleFormulaMap(unitId, subUnitId), manager = this._dataValidationModel.ensureManager(unitId, subUnitId);
368
- results.forEach((result) => {
369
- var _a23, _b;
370
- if (formulaMap.get((_a23 = result.extra) == null ? void 0 : _a23.ruleId)) {
371
- const rule = manager.getRuleById((_b = result.extra) == null ? void 0 : _b.ruleId);
372
- rule && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
373
- }
374
- });
375
- }
366
+ if (this._instanceService.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET)
367
+ for (const subUnitId in unitMap) {
368
+ const results = unitMap[subUnitId], formulaMap = this._ensureRuleFormulaMap(unitId, subUnitId), manager = this._dataValidationModel.ensureManager(unitId, subUnitId);
369
+ results.forEach((result) => {
370
+ var _a23, _b;
371
+ if (formulaMap.get((_a23 = result.extra) == null ? void 0 : _a23.ruleId)) {
372
+ const rule = manager.getRuleById((_b = result.extra) == null ? void 0 : _b.ruleId);
373
+ rule && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
374
+ }
375
+ });
376
+ }
376
377
  }
377
378
  }));
378
379
  }
@@ -453,9 +454,10 @@ let DataValidationFormulaService = (_a3 = class extends Disposable {
453
454
  }
454
455
  }, __name(_a3, "DataValidationFormulaService"), _a3);
455
456
  DataValidationFormulaService = __decorateClass$i([
456
- __decorateParam$i(0, Inject(RegisterOtherFormulaService)),
457
- __decorateParam$i(1, Inject(DataValidationCacheService)),
458
- __decorateParam$i(2, Inject(DataValidationModel))
457
+ __decorateParam$i(0, IUniverInstanceService),
458
+ __decorateParam$i(1, Inject(RegisterOtherFormulaService)),
459
+ __decorateParam$i(2, Inject(DataValidationCacheService)),
460
+ __decorateParam$i(3, Inject(DataValidationModel))
459
461
  ], DataValidationFormulaService);
460
462
  function getFormulaResult(result) {
461
463
  var _a23, _b;
@@ -1275,7 +1277,7 @@ function DataValidationDetail() {
1275
1277
  }, [commandService, dataValidationModel, ruleId, subUnitId, unitId]), !validator)
1276
1278
  return null;
1277
1279
  const operators = validator.operators, operatorNames = validator.operatorNames, isTwoFormula = localRule.operator ? TWO_FORMULA_OPERATOR_COUNT$1.includes(localRule.operator) : !1, handleOk = /* @__PURE__ */ __name(() => {
1278
- validator.validatorFormula(localRule, unitId, subUnitId).success ? dataValidationPanelService.setActiveRule(null) : setShowError(!0);
1280
+ localRule.ranges.length && (validator.validatorFormula(localRule, unitId, subUnitId).success ? dataValidationPanelService.setActiveRule(null) : setShowError(!0));
1279
1281
  }, "handleOk"), handleUpdateRuleRanges = useEvent((unitRanges) => {
1280
1282
  if (isUnitRangesEqual(unitRanges, localRanges))
1281
1283
  return;
@@ -1358,20 +1360,27 @@ function DataValidationDetail() {
1358
1360
  ));
1359
1361
  }, "handleUpdateRuleOptions");
1360
1362
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1361
- /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("dataValidation.panel.range"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1362
- RangeSelector,
1363
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1364
+ FormLayout,
1363
1365
  {
1364
- className: styles$4.dataValidationDetailFormItem,
1365
- value: rangeStr,
1366
- id: createInternalEditorID("data-validation-detail"),
1367
- openForSheetUnitId: unitId,
1368
- openForSheetSubUnitId: subUnitId,
1369
- onChange: /* @__PURE__ */ __name((newRange) => {
1370
- newRange.some((i) => !isValidRange(i.range) || i.range.endColumn < i.range.startColumn || i.range.endRow < i.range.startRow) || handleUpdateRuleRanges(newRange);
1371
- }, "onChange")
1372
- },
1373
- key
1374
- ) }),
1366
+ label: localeService.t("dataValidation.panel.range"),
1367
+ error: localRule.ranges.length ? "" : localeService.t("dataValidation.panel.rangeError"),
1368
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1369
+ RangeSelector,
1370
+ {
1371
+ className: styles$4.dataValidationDetailFormItem,
1372
+ value: rangeStr,
1373
+ id: createInternalEditorID("data-validation-detail"),
1374
+ openForSheetUnitId: unitId,
1375
+ openForSheetSubUnitId: subUnitId,
1376
+ onChange: /* @__PURE__ */ __name((newRange) => {
1377
+ newRange.some((i) => !isValidRange(i.range) || i.range.endColumn < i.range.startColumn || i.range.endRow < i.range.startRow) || handleUpdateRuleRanges(newRange);
1378
+ }, "onChange")
1379
+ },
1380
+ key
1381
+ )
1382
+ }
1383
+ ),
1375
1384
  /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("dataValidation.panel.type"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1376
1385
  Select,
1377
1386
  {
@@ -3027,8 +3036,9 @@ let SheetsDataValidationRenderController = (_a8 = class extends RxDisposable {
3027
3036
  }
3028
3037
  _initDropdown() {
3029
3038
  this._editorBridgeService && this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {
3039
+ var _a23;
3030
3040
  if (!visible.visible) {
3031
- this._dropdownManagerService.hideDropdown();
3041
+ ((_a23 = this._dropdownManagerService.activeDropdown) == null ? void 0 : _a23.trigger) === "editor-bridge" && this._dropdownManagerService.hideDropdown();
3032
3042
  return;
3033
3043
  }
3034
3044
  const state = this._editorBridgeService.getEditCellState();
@@ -3059,7 +3069,8 @@ let SheetsDataValidationRenderController = (_a8 = class extends RxDisposable {
3059
3069
  },
3060
3070
  componentKey: validator.dropdown,
3061
3071
  onHide: /* @__PURE__ */ __name(() => {
3062
- }, "onHide")
3072
+ }, "onHide"),
3073
+ trigger: "editor-bridge"
3063
3074
  },
3064
3075
  !1
3065
3076
  );
@@ -3410,7 +3421,7 @@ var __defProp$b = Object.defineProperty, __getOwnPropDesc$b = Object.getOwnPrope
3410
3421
  return kind && result && __defProp$b(target, key, result), result;
3411
3422
  }, "__decorateClass$b"), __decorateParam$b = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$b"), _a11;
3412
3423
  let DataValidationCustomFormulaService = (_a11 = class extends Disposable {
3413
- constructor(_registerOtherFormulaService, _lexerTreeBuilder, _dataValidationModel, _dataValidationCacheService) {
3424
+ constructor(_instanceSrv, _registerOtherFormulaService, _lexerTreeBuilder, _dataValidationModel, _dataValidationCacheService) {
3414
3425
  super();
3415
3426
  __publicField(this, "_formulaMap", /* @__PURE__ */ new Map());
3416
3427
  /**
@@ -3421,20 +3432,21 @@ let DataValidationCustomFormulaService = (_a11 = class extends Disposable {
3421
3432
  * reflect of formulaId to cell, only store transformable formula
3422
3433
  */
3423
3434
  __publicField(this, "_formulaCellMap", /* @__PURE__ */ new Map());
3424
- this._registerOtherFormulaService = _registerOtherFormulaService, this._lexerTreeBuilder = _lexerTreeBuilder, this._dataValidationModel = _dataValidationModel, this._dataValidationCacheService = _dataValidationCacheService, this._initFormulaResultHandler();
3435
+ this._instanceSrv = _instanceSrv, this._registerOtherFormulaService = _registerOtherFormulaService, this._lexerTreeBuilder = _lexerTreeBuilder, this._dataValidationModel = _dataValidationModel, this._dataValidationCacheService = _dataValidationCacheService, this._initFormulaResultHandler();
3425
3436
  }
3426
3437
  _initFormulaResultHandler() {
3427
3438
  this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
3428
3439
  for (const unitId in resultMap) {
3429
3440
  const unitMap = resultMap[unitId];
3430
- for (const subUnitId in unitMap) {
3431
- const results = unitMap[subUnitId], { formulaCellMap, ruleFormulaMap } = this._ensureMaps(unitId, subUnitId), manager = this._dataValidationModel.ensureManager(unitId, subUnitId);
3432
- results.forEach((result) => {
3433
- var _a23, _b;
3434
- const ruleInfo = ruleFormulaMap.get((_a23 = result.extra) == null ? void 0 : _a23.ruleId), cellInfo = formulaCellMap.get(result.formulaId), rule = manager.getRuleById((_b = result.extra) == null ? void 0 : _b.ruleId);
3435
- rule && ruleInfo && !ruleInfo.isTransformable && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges), cellInfo && this._dataValidationCacheService.markCellDirty(unitId, subUnitId, cellInfo.row, cellInfo.column);
3436
- });
3437
- }
3441
+ if (this._instanceSrv.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET)
3442
+ for (const subUnitId in unitMap) {
3443
+ const results = unitMap[subUnitId], { formulaCellMap, ruleFormulaMap } = this._ensureMaps(unitId, subUnitId), manager = this._dataValidationModel.ensureManager(unitId, subUnitId);
3444
+ results.forEach((result) => {
3445
+ var _a23, _b;
3446
+ const ruleInfo = ruleFormulaMap.get((_a23 = result.extra) == null ? void 0 : _a23.ruleId), cellInfo = formulaCellMap.get(result.formulaId), rule = manager.getRuleById((_b = result.extra) == null ? void 0 : _b.ruleId);
3447
+ rule && ruleInfo && !ruleInfo.isTransformable && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges), cellInfo && this._dataValidationCacheService.markCellDirty(unitId, subUnitId, cellInfo.row, cellInfo.column);
3448
+ });
3449
+ }
3438
3450
  }
3439
3451
  }));
3440
3452
  }
@@ -3563,10 +3575,11 @@ let DataValidationCustomFormulaService = (_a11 = class extends Disposable {
3563
3575
  }
3564
3576
  }, __name(_a11, "DataValidationCustomFormulaService"), _a11);
3565
3577
  DataValidationCustomFormulaService = __decorateClass$b([
3566
- __decorateParam$b(0, Inject(RegisterOtherFormulaService)),
3567
- __decorateParam$b(1, Inject(LexerTreeBuilder)),
3568
- __decorateParam$b(2, Inject(DataValidationModel)),
3569
- __decorateParam$b(3, Inject(DataValidationCacheService))
3578
+ __decorateParam$b(0, IUniverInstanceService),
3579
+ __decorateParam$b(1, Inject(RegisterOtherFormulaService)),
3580
+ __decorateParam$b(2, Inject(LexerTreeBuilder)),
3581
+ __decorateParam$b(3, Inject(DataValidationModel)),
3582
+ __decorateParam$b(4, Inject(DataValidationCacheService))
3570
3583
  ], DataValidationCustomFormulaService);
3571
3584
  const _CustomFormulaValidator = class _CustomFormulaValidator extends BaseDataValidator {
3572
3585
  constructor() {
@@ -4206,7 +4219,7 @@ let DataValidationRefRangeController = (_a15 = class extends Disposable {
4206
4219
  }
4207
4220
  }, __name(_a15, "DataValidationRefRangeController"), _a15);
4208
4221
  DataValidationRefRangeController = __decorateClass$7([
4209
- OnLifecycle(LifecycleStages.Ready, DataValidationRefRangeController),
4222
+ OnLifecycle(LifecycleStages.Starting, DataValidationRefRangeController),
4210
4223
  __decorateParam$7(0, Inject(DataValidationModel)),
4211
4224
  __decorateParam$7(1, Inject(Injector)),
4212
4225
  __decorateParam$7(2, Inject(RefRangeService)),
@@ -33,7 +33,8 @@
33
33
  "showWarning": "Show warning",
34
34
  "rejectInput": "Reject input",
35
35
  "messageInfo": "Helper message",
36
- "showInfo": "Show help text for a selected cell"
36
+ "showInfo": "Show help text for a selected cell",
37
+ "rangeError": "Ranges are not legal"
37
38
  },
38
39
  "operators": {
39
40
  "between": "between",
@@ -21,6 +21,7 @@
21
21
  "removeAll": "Удалить все",
22
22
  "add": "добавить правило",
23
23
  "range": "Диапазоны",
24
+ "rangeError": "Диапазоны не являются законными",
24
25
  "type": "Тип",
25
26
  "options": "Дополнительные параметры",
26
27
  "operator": "Оператор",
@@ -21,6 +21,7 @@
21
21
  "removeAll": "Xóa tất cả",
22
22
  "add": "Tạo quy tắc mới",
23
23
  "range": "Phạm vi áp dụng",
24
+ "rangeError": "Phạm vi không hợp pháp",
24
25
  "type": "Loại điều kiện",
25
26
  "options": "Cài đặt nâng cao",
26
27
  "operator": "Dữ liệu",
@@ -21,6 +21,7 @@
21
21
  "removeAll": "全部删除",
22
22
  "add": "新建规则",
23
23
  "range": "应用范围",
24
+ "rangeError": "请输入合法的应用范围",
24
25
  "type": "条件类型",
25
26
  "options": "高级设置",
26
27
  "operator": "数据",
@@ -21,6 +21,7 @@
21
21
  "removeAll": "全部刪除",
22
22
  "add": "新建規則",
23
23
  "range": "應用範圍",
24
+ "rangeError": "應用範圍不合法",
24
25
  "type": "條件型別",
25
26
  "options": "進階設定",
26
27
  "operator": "資料",
@@ -36,6 +36,7 @@ declare const locale: {
36
36
  removeAll: string;
37
37
  add: string;
38
38
  range: string;
39
+ rangeError: string;
39
40
  type: string;
40
41
  options: string;
41
42
  operator: string;
@@ -9,6 +9,7 @@ export interface IDropdownParam {
9
9
  location: ISheetLocation;
10
10
  onHide?: () => void;
11
11
  componentKey: string;
12
+ trigger?: 'editor-bridge';
12
13
  }
13
14
  export interface IDropdownComponentProps {
14
15
  componentKey: string;
@@ -1,4 +1,4 @@
1
- import { IRange, ISheetDataValidationRule, Disposable } from '@univerjs/core';
1
+ import { IRange, ISheetDataValidationRule, Disposable, IUniverInstanceService } from '@univerjs/core';
2
2
  import { LexerTreeBuilder } from '@univerjs/engine-formula';
3
3
  import { DataValidationModel } from '@univerjs/data-validation';
4
4
  import { RegisterOtherFormulaService } from '@univerjs/sheets-formula';
@@ -12,6 +12,7 @@ interface IFormulaData {
12
12
  formulaId?: string;
13
13
  }
14
14
  export declare class DataValidationCustomFormulaService extends Disposable {
15
+ private readonly _instanceSrv;
15
16
  private _registerOtherFormulaService;
16
17
  private _lexerTreeBuilder;
17
18
  private readonly _dataValidationModel;
@@ -25,7 +26,7 @@ export declare class DataValidationCustomFormulaService extends Disposable {
25
26
  * reflect of formulaId to cell, only store transformable formula
26
27
  */
27
28
  private _formulaCellMap;
28
- constructor(_registerOtherFormulaService: RegisterOtherFormulaService, _lexerTreeBuilder: LexerTreeBuilder, _dataValidationModel: DataValidationModel, _dataValidationCacheService: DataValidationCacheService);
29
+ constructor(_instanceSrv: IUniverInstanceService, _registerOtherFormulaService: RegisterOtherFormulaService, _lexerTreeBuilder: LexerTreeBuilder, _dataValidationModel: DataValidationModel, _dataValidationCacheService: DataValidationCacheService);
29
30
  private _initFormulaResultHandler;
30
31
  private _ensureMaps;
31
32
  private _registerFormula;
@@ -1,14 +1,15 @@
1
- import { Nullable, Disposable } from '@univerjs/core';
1
+ import { Nullable, Disposable, IUniverInstanceService } from '@univerjs/core';
2
2
  import { DataValidationModel } from '@univerjs/data-validation';
3
3
  import { IFormulaInfo, IOtherFormulaResult, RegisterOtherFormulaService } from '@univerjs/sheets-formula';
4
4
  import { DataValidationCacheService } from './dv-cache.service';
5
5
 
6
6
  export declare class DataValidationFormulaService extends Disposable {
7
+ private readonly _instanceService;
7
8
  private _registerOtherFormulaService;
8
9
  private readonly _dataValidationCacheService;
9
10
  private readonly _dataValidationModel;
10
11
  private _formulaRuleMap;
11
- constructor(_registerOtherFormulaService: RegisterOtherFormulaService, _dataValidationCacheService: DataValidationCacheService, _dataValidationModel: DataValidationModel);
12
+ constructor(_instanceService: IUniverInstanceService, _registerOtherFormulaService: RegisterOtherFormulaService, _dataValidationCacheService: DataValidationCacheService, _dataValidationModel: DataValidationModel);
12
13
  private _initFormulaResultHandler;
13
14
  private _ensureRuleFormulaMap;
14
15
  addRule(unitId: string, subUnitId: string, ruleId: string, formula1: string | undefined, formula2: string | undefined): void;