@univerjs/sheets-data-validation-ui 1.5.2 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -11,10 +11,11 @@ import { ActionRow, Button, Checkbox, DraggableList, Dropdown as Dropdown$1, For
11
11
  import { createElement, useEffect, useMemo, useRef, useState } from "react";
12
12
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
13
  import { CheckboxIcon, DataValidationIcon, DatePickerIcon, DeleteIcon, DropdownListIcon, GripVerticalIcon, IncreaseIcon, MoreDownIcon, MoreUpIcon } from "@univerjs/icons";
14
+ import { drawCanvasIcon } from "@univerjs/icons-svg";
14
15
  import { deserializeRangeWithSheet, serializeRange } from "@univerjs/engine-formula";
15
16
  import { FormulaEditor, RangeSelector } from "@univerjs/sheets-formula-ui";
16
17
 
17
- // \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
18
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
18
19
  function _typeof(o) {
19
20
  "@babel/helpers - typeof";
20
21
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -24,7 +25,7 @@ function _typeof(o) {
24
25
  }, _typeof(o);
25
26
  }
26
27
 
27
- // \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
28
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
28
29
  function toPrimitive(t, e) {
29
30
  if ("object" != _typeof(t) || !t) return t;
30
31
  var r;
@@ -36,13 +37,13 @@ function toPrimitive(t, e) {
36
37
  return ("string" === e ? String : Number)(t);
37
38
  }
38
39
 
39
- // \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
40
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
40
41
  function toPropertyKey(t) {
41
42
  var i = toPrimitive(t, "string");
42
43
  return "symbol" == _typeof(i) ? i : i + "";
43
44
  }
44
45
 
45
- // \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
46
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
46
47
  function _defineProperty(e, r, t) {
47
48
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
48
49
  value: t,
@@ -52,14 +53,14 @@ function _defineProperty(e, r, t) {
52
53
  }) : e[r] = t, e;
53
54
  }
54
55
 
55
- // \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
56
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
56
57
  function __decorateParam(paramIndex, decorator) {
57
58
  return function(target, key) {
58
59
  decorator(target, key, paramIndex);
59
60
  };
60
61
  }
61
62
 
62
- // \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
63
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
63
64
  function __decorate(decorators, target, key, desc) {
64
65
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
65
66
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -509,6 +510,11 @@ let DataValidationDropdownManagerService = class DataValidationDropdownManagerSe
509
510
  const showColor = (rule === null || rule === void 0 ? void 0 : rule.renderMode) === DataValidationRenderMode.CUSTOM || (rule === null || rule === void 0 ? void 0 : rule.renderMode) === void 0;
510
511
  const list = validator.getListWithColor(rule, unitId, subUnitId);
511
512
  const cellStr = getDataValidationCellValue(worksheet.getCellRaw(row, col));
513
+ const toOptionLabel = (value) => {
514
+ var _list$find;
515
+ return ((_list$find = list.find((item) => item.label.toLowerCase() === value.toLowerCase())) === null || _list$find === void 0 ? void 0 : _list$find.label) ?? value;
516
+ };
517
+ const defaultValue = multiple ? serializeListOptions(deserializeListOptions(cellStr).map(toOptionLabel)) : toOptionLabel(cellStr);
512
518
  const handleEdit = () => {
513
519
  this._commandService.executeCommand(OpenValidationPanelOperation.id, { ruleId: rule.uid });
514
520
  popupDisposable === null || popupDisposable === void 0 || popupDisposable.dispose();
@@ -524,7 +530,7 @@ let DataValidationDropdownManagerService = class DataValidationDropdownManagerSe
524
530
  color: showColor || item.color ? item.color || "gray.100" : "transparent"
525
531
  })),
526
532
  onEdit: handleEdit,
527
- defaultValue: cellStr,
533
+ defaultValue,
528
534
  multiple,
529
535
  showEdit: ((_this$_configService$ = this._configService.getConfig("sheets-data-validation-ui.config")) === null || _this$_configService$ === void 0 ? void 0 : _this$_configService$.showEditOnDropdown) ?? true,
530
536
  showSearch: ((_this$_configService$2 = this._configService.getConfig("sheets-data-validation-ui.config")) === null || _this$_configService$2 === void 0 ? void 0 : _this$_configService$2.showSearchOnDropdown) ?? true
@@ -1058,7 +1064,7 @@ const menuSchema = {
1058
1064
 
1059
1065
  // package.json
1060
1066
  var name = "@univerjs/sheets-data-validation-ui";
1061
- var version = "1.5.2";
1067
+ var version = "1.6.1";
1062
1068
 
1063
1069
  // src/controllers/dv-alert.controller.ts
1064
1070
  const ALERT_KEY = "SHEET_DATA_VALIDATION_ALERT";
@@ -2194,7 +2200,6 @@ var Dropdown = class extends Shape {
2194
2200
  };
2195
2201
 
2196
2202
  // src/views/widgets/dropdown-multiple-widget.ts
2197
- const downPath$1 = new Path2D("M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z");
2198
2203
  let DropdownMultipleWidget = class DropdownMultipleWidget {
2199
2204
  constructor(_commandService, _univerInstanceService, _renderManagerService, _dataValidationModel) {
2200
2205
  this._commandService = _commandService;
@@ -2226,8 +2231,7 @@ let DropdownMultipleWidget = class DropdownMultipleWidget {
2226
2231
  }
2227
2232
  ctx.save();
2228
2233
  ctx.translateWithPrecision(cellBounding.startX + left, cellBounding.startY + top);
2229
- ctx.fillStyle = DROP_DOWN_ICON_COLOR;
2230
- ctx.fill(downPath$1);
2234
+ drawCanvasIcon(ctx, "down-icon", -2, -2, 10, DROP_DOWN_ICON_COLOR);
2231
2235
  ctx.restore();
2232
2236
  }
2233
2237
  drawWith(ctx, info, skeleton, spreadsheets) {
@@ -2257,7 +2261,6 @@ let DropdownMultipleWidget = class DropdownMultipleWidget {
2257
2261
  const vt = _vt ?? VerticalAlign.MIDDLE;
2258
2262
  const cellValue = getCellValueOrigin(data) ?? "";
2259
2263
  const items = validator.parseCellValue(cellValue);
2260
- const labelColorMap = validator.getListWithColorMap(rule);
2261
2264
  const layout = layoutDropdowns(items, fontStyle, cellWidth, cellHeight);
2262
2265
  this._drawDownIcon(ctx, cellBounding, cellWidth, cellHeight, vt);
2263
2266
  ctx.save();
@@ -2292,7 +2295,7 @@ let DropdownMultipleWidget = class DropdownMultipleWidget {
2292
2295
  ...fontStyle,
2293
2296
  info: item,
2294
2297
  color,
2295
- fill: labelColorMap[item.text]
2298
+ fill: validator.getOptionColor(rule, item.text)
2296
2299
  });
2297
2300
  ctx.restore();
2298
2301
  });
@@ -2453,7 +2456,6 @@ const PADDING_V = 1;
2453
2456
  const MARGIN_H = 6;
2454
2457
  const MARGIN_V = 3;
2455
2458
  const RADIUS_BG = 8;
2456
- const downPath = new Path2D("M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z");
2457
2459
  function calcPadding(cellWidth, cellHeight, fontWidth, fontHeight, vt, ht, margin = true) {
2458
2460
  let paddingTop = 0;
2459
2461
  const realMargin = margin ? MARGIN_V : 0;
@@ -2487,20 +2489,8 @@ let DropdownWidget = class DropdownWidget {
2487
2489
  this._commandService = _commandService;
2488
2490
  this._renderManagerService = _renderManagerService;
2489
2491
  this._dataValidationModel = _dataValidationModel;
2490
- _defineProperty(this, "_dropdownInfoMap", /* @__PURE__ */ new Map());
2491
2492
  _defineProperty(this, "zIndex", void 0);
2492
2493
  }
2493
- _ensureMap(subUnitId) {
2494
- let map = this._dropdownInfoMap.get(subUnitId);
2495
- if (!map) {
2496
- map = /* @__PURE__ */ new Map();
2497
- this._dropdownInfoMap.set(subUnitId, map);
2498
- }
2499
- return map;
2500
- }
2501
- _generateKey(row, col) {
2502
- return `${row}.${col}`;
2503
- }
2504
2494
  _drawDownIcon(ctx, cellBounding, cellWidth, cellHeight, fontHeight, vt, pd) {
2505
2495
  const { t = DEFAULT_STYLES.pd.t, b = DEFAULT_STYLES.pd.b } = pd;
2506
2496
  const left = cellWidth - ICON_PLACE;
@@ -2516,12 +2506,11 @@ let DropdownWidget = class DropdownWidget {
2516
2506
  }
2517
2507
  ctx.save();
2518
2508
  ctx.translateWithPrecision(cellBounding.startX + left, cellBounding.startY + top);
2519
- ctx.fillStyle = DROP_DOWN_ICON_COLOR;
2520
- ctx.fill(downPath);
2509
+ drawCanvasIcon(ctx, "down-icon", -2, -2, 10, DROP_DOWN_ICON_COLOR);
2521
2510
  ctx.restore();
2522
2511
  }
2523
- drawWith(ctx, info, skeleton) {
2524
- const { primaryWithCoord, row, col, style, data, subUnitId } = info;
2512
+ drawWith(ctx, info, _skeleton) {
2513
+ const { primaryWithCoord, row, col, style, data } = info;
2525
2514
  const _cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
2526
2515
  const _row = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo.startRow : row;
2527
2516
  const _col = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo.startColumn : col;
@@ -2540,11 +2529,8 @@ let DropdownWidget = class DropdownWidget {
2540
2529
  };
2541
2530
  const cellWidth = cellBounding.endX - cellBounding.startX;
2542
2531
  const cellHeight = cellBounding.endY - cellBounding.startY;
2543
- const map = this._ensureMap(subUnitId);
2544
- const key = this._generateKey(row, col);
2545
- const colorMap = validator.getListWithColorMap(rule);
2546
2532
  const valueStr = `${getCellValueOrigin(data) ?? ""}`;
2547
- const activeColor = colorMap[valueStr];
2533
+ const activeColor = validator.getOptionColor(rule, valueStr);
2548
2534
  let { tb, vt, ht, pd } = style || {};
2549
2535
  tb = tb ?? WrapStrategy.WRAP;
2550
2536
  vt = vt ?? VerticalAlign.BOTTOM;
@@ -2555,7 +2541,7 @@ let DropdownWidget = class DropdownWidget {
2555
2541
  var _style$cl, _style$st, _style$ul;
2556
2542
  const { l = DEFAULT_STYLES.pd.l, t = DEFAULT_STYLES.pd.t, r = DEFAULT_STYLES.pd.r, b = DEFAULT_STYLES.pd.b } = pd;
2557
2543
  const realWidth = cellWidth - l - r - ICON_PLACE - 4;
2558
- const textSkeleton = new DocSimpleSkeleton(valueStr, fontStyle, Boolean(tb === WrapStrategy.WRAP), realWidth, Infinity);
2544
+ const textSkeleton = new DocSimpleSkeleton(valueStr, fontStyle, Boolean(tb === WrapStrategy.WRAP), realWidth, 1e400);
2559
2545
  textSkeleton.calculate();
2560
2546
  const fontWidth = textSkeleton.getTotalWidth();
2561
2547
  const fontHeight = textSkeleton.getTotalHeight();
@@ -2585,12 +2571,6 @@ let DropdownWidget = class DropdownWidget {
2585
2571
  }, textSkeleton);
2586
2572
  ctx.restore();
2587
2573
  ctx.restore();
2588
- map.set(key, {
2589
- left: cellBounding.endX - ICON_PLACE + skeleton.rowHeaderWidth,
2590
- top: cellBounding.startY + t + skeleton.columnHeaderHeight,
2591
- width: ICON_PLACE,
2592
- height: cellHeight - t - b
2593
- });
2594
2574
  } else {
2595
2575
  var _style$cl2, _style$st2, _style$ul2;
2596
2576
  ctx.save();
@@ -2599,7 +2579,7 @@ let DropdownWidget = class DropdownWidget {
2599
2579
  ctx.rect(0, 0, cellWidth, cellHeight);
2600
2580
  ctx.clip();
2601
2581
  const realWidth = cellWidth - 12 - PADDING_H - ICON_PLACE - 4;
2602
- const textSkeleton = new DocSimpleSkeleton(valueStr, fontStyle, Boolean(tb === WrapStrategy.WRAP), realWidth, Infinity);
2582
+ const textSkeleton = new DocSimpleSkeleton(valueStr, fontStyle, Boolean(tb === WrapStrategy.WRAP), realWidth, 1e400);
2603
2583
  textSkeleton.calculate();
2604
2584
  const fontWidth = textSkeleton.getTotalWidth();
2605
2585
  const fontHeight = textSkeleton.getTotalHeight();
@@ -2631,15 +2611,8 @@ let DropdownWidget = class DropdownWidget {
2631
2611
  }, textSkeleton);
2632
2612
  ctx.restore();
2633
2613
  ctx.translateWithPrecision(realWidth + PADDING_H + 4, (fontHeight - ICON_SIZE) / 2);
2634
- ctx.fillStyle = DROP_DOWN_ICON_COLOR;
2635
- ctx.fill(downPath);
2614
+ drawCanvasIcon(ctx, "down-icon", -2, -2, 10, DROP_DOWN_ICON_COLOR);
2636
2615
  ctx.restore();
2637
- map.set(key, {
2638
- left: cellBounding.startX + MARGIN_H + skeleton.rowHeaderWidth,
2639
- top: cellBounding.startY + paddingTop + skeleton.columnHeaderHeight,
2640
- width: rectWidth,
2641
- height: rectHeight
2642
- });
2643
2616
  }
2644
2617
  }
2645
2618
  calcCellAutoHeight(info) {
@@ -2663,12 +2636,12 @@ let DropdownWidget = class DropdownWidget {
2663
2636
  if (rule.renderMode === DataValidationRenderMode.ARROW) {
2664
2637
  const { l = DEFAULT_STYLES.pd.l, r = DEFAULT_STYLES.pd.r } = pd ?? {};
2665
2638
  const realWidth = cellWidth - l - r - ICON_PLACE - 4;
2666
- const skeleton = new DocSimpleSkeleton(valueStr, getFontStyleString(style).fontCache, Boolean(tb === WrapStrategy.WRAP), realWidth, Infinity);
2639
+ const skeleton = new DocSimpleSkeleton(valueStr, getFontStyleString(style).fontCache, Boolean(tb === WrapStrategy.WRAP), realWidth, 1e400);
2667
2640
  skeleton.calculate();
2668
2641
  return skeleton.getTotalHeight() + t + b + 6;
2669
2642
  } else {
2670
2643
  const realWidth = Math.max(cellWidth - 12 - PADDING_H - ICON_PLACE - 4, 10);
2671
- const skeleton = new DocSimpleSkeleton(valueStr, getFontStyleString(style).fontCache, Boolean(tb === WrapStrategy.WRAP), realWidth, Infinity);
2644
+ const skeleton = new DocSimpleSkeleton(valueStr, getFontStyleString(style).fontCache, Boolean(tb === WrapStrategy.WRAP), realWidth, 1e400);
2672
2645
  skeleton.calculate();
2673
2646
  return skeleton.getTotalHeight() + 6 + 2;
2674
2647
  }
@@ -2702,21 +2675,14 @@ let DropdownWidget = class DropdownWidget {
2702
2675
  default: paddingAll = 34 + r + l + RADIUS_BG / 2 + 1;
2703
2676
  }
2704
2677
  const widthForTextLayout = cellWidth - paddingAll;
2705
- const skeleton = new DocSimpleSkeleton(valueStr, getFontStyleString(style).fontCache, Boolean(tb === WrapStrategy.WRAP), widthForTextLayout, Infinity);
2678
+ const skeleton = new DocSimpleSkeleton(valueStr, getFontStyleString(style).fontCache, Boolean(tb === WrapStrategy.WRAP), widthForTextLayout, 1e400);
2706
2679
  skeleton.calculate();
2707
2680
  return skeleton.getTotalWidth() + paddingAll;
2708
2681
  }
2709
- isHit(position, info) {
2710
- const { subUnitId, row, col } = info;
2711
- const dropdownInfo = this._ensureMap(subUnitId).get(this._generateKey(row, col));
2712
- const rule = this._dataValidationModel.getRuleByLocation(info.unitId, info.subUnitId, row, col);
2682
+ isHit(_position, info) {
2683
+ const rule = this._dataValidationModel.getRuleByLocation(info.unitId, info.subUnitId, info.row, info.col);
2713
2684
  if (!rule) return false;
2714
- if (!dropdownInfo) return false;
2715
- if (rule.renderMode === DataValidationRenderMode.TEXT) return false;
2716
- const { top, left, width, height } = dropdownInfo;
2717
- const { x, y } = position;
2718
- if (x >= left && x <= left + width && y >= top && y <= top + height) return true;
2719
- return false;
2685
+ return rule.type === DataValidationType.LIST;
2720
2686
  }
2721
2687
  onPointerDown(info, evt) {
2722
2688
  if (evt.button === 2) return;
@@ -31,16 +31,13 @@ export declare class DropdownWidget implements IBaseDataValidationWidget {
31
31
  private readonly _commandService;
32
32
  private readonly _renderManagerService;
33
33
  private readonly _dataValidationModel;
34
- private _dropdownInfoMap;
35
34
  constructor(_univerInstanceService: IUniverInstanceService, _localeService: LocaleService, _commandService: ICommandService, _renderManagerService: IRenderManagerService, _dataValidationModel: SheetDataValidationModel);
36
35
  zIndex?: number | undefined;
37
- private _ensureMap;
38
- private _generateKey;
39
36
  private _drawDownIcon;
40
- drawWith(ctx: UniverRenderingContext2D, info: ICellRenderContext, skeleton: SpreadsheetSkeleton): void;
37
+ drawWith(ctx: UniverRenderingContext2D, info: ICellRenderContext, _skeleton: SpreadsheetSkeleton): void;
41
38
  calcCellAutoHeight(info: ICellRenderContext): number | undefined;
42
39
  calcCellAutoWidth(info: ICellRenderContext): number | undefined;
43
- isHit(position: {
40
+ isHit(_position: {
44
41
  x: number;
45
42
  y: number;
46
43
  }, info: ICellRenderContext): boolean;