@univerjs/sheets-conditional-formatting-ui 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.
package/lib/index.js CHANGED
@@ -388,7 +388,7 @@ const AddUniqueValuesCfCommand = {
388
388
  const CF_PANEL_KEY = "sheet.conditional.formatting.panel";
389
389
 
390
390
  //#endregion
391
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
391
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
392
392
  function _typeof(o) {
393
393
  "@babel/helpers - typeof";
394
394
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -399,7 +399,7 @@ function _typeof(o) {
399
399
  }
400
400
 
401
401
  //#endregion
402
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
402
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
403
403
  function toPrimitive(t, r) {
404
404
  if ("object" != _typeof(t) || !t) return t;
405
405
  var e = t[Symbol.toPrimitive];
@@ -412,14 +412,14 @@ function toPrimitive(t, r) {
412
412
  }
413
413
 
414
414
  //#endregion
415
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
415
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
416
416
  function toPropertyKey(t) {
417
417
  var i = toPrimitive(t, "string");
418
418
  return "symbol" == _typeof(i) ? i : i + "";
419
419
  }
420
420
 
421
421
  //#endregion
422
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
422
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
423
423
  function _defineProperty(e, r, t) {
424
424
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
425
425
  value: t,
@@ -430,7 +430,7 @@ function _defineProperty(e, r, t) {
430
430
  }
431
431
 
432
432
  //#endregion
433
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
433
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
434
434
  function __decorateParam(paramIndex, decorator) {
435
435
  return function(target, key) {
436
436
  decorator(target, key, paramIndex);
@@ -438,7 +438,7 @@ function __decorateParam(paramIndex, decorator) {
438
438
  }
439
439
 
440
440
  //#endregion
441
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
441
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
442
442
  function __decorate(decorators, target, key, desc) {
443
443
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
444
444
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -985,8 +985,7 @@ const conditionalFormattingRuleMenuSchema = { [RibbonDataGroup.RULES]: { [OpenCo
985
985
  order: 1,
986
986
  gridLayout: {
987
987
  row: 2,
988
- column: 1,
989
- showLabel: true
988
+ column: 1
990
989
  },
991
990
  menuItemFactory: FactoryManageConditionalFormattingRule
992
991
  } } };
@@ -1007,7 +1006,7 @@ const menuSchema = {
1007
1006
  //#endregion
1008
1007
  //#region package.json
1009
1008
  var name = "@univerjs/sheets-conditional-formatting-ui";
1010
- var version = "1.0.3";
1009
+ var version = "1.1.0";
1011
1010
 
1012
1011
  //#endregion
1013
1012
  //#region src/config/config.ts
@@ -1699,8 +1698,9 @@ const ColorPicker$1 = (props) => {
1699
1698
  };
1700
1699
 
1701
1700
  //#endregion
1702
- //#region src/views/Preview.tsx
1703
- function Preview(props) {
1701
+ //#region src/views/ConditionalFormattingRulePreview.tsx
1702
+ /** Shows a rule's configured appearance without evaluating worksheet values. */
1703
+ function ConditionalFormattingRulePreview(props) {
1704
1704
  const { rule } = props;
1705
1705
  const colorList = useMemo(() => {
1706
1706
  if ((rule === null || rule === void 0 ? void 0 : rule.type) === CFRuleType.colorScale) {
@@ -1786,6 +1786,56 @@ function Preview(props) {
1786
1786
  }
1787
1787
  }
1788
1788
 
1789
+ //#endregion
1790
+ //#region src/views/panel/rule-edit/RuleNumberInput.tsx
1791
+ /**
1792
+ * Copyright 2023-present DreamNum Co., Ltd.
1793
+ *
1794
+ * Licensed under the Apache License, Version 2.0 (the "License");
1795
+ * you may not use this file except in compliance with the License.
1796
+ * You may obtain a copy of the License at
1797
+ *
1798
+ * http://www.apache.org/licenses/LICENSE-2.0
1799
+ *
1800
+ * Unless required by applicable law or agreed to in writing, software
1801
+ * distributed under the License is distributed on an "AS IS" BASIS,
1802
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1803
+ * See the License for the specific language governing permissions and
1804
+ * limitations under the License.
1805
+ */
1806
+ function RuleNumberInput({ value, onChange, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER, disabled, className }) {
1807
+ const [draftState, setDraftState] = useState({
1808
+ value,
1809
+ text: String(value)
1810
+ });
1811
+ if (!Object.is(draftState.value, value)) setDraftState({
1812
+ value,
1813
+ text: String(value)
1814
+ });
1815
+ const draft = draftState.text;
1816
+ const setDraft = (text) => setDraftState({
1817
+ value,
1818
+ text
1819
+ });
1820
+ return /* @__PURE__ */ jsx(Input, {
1821
+ className,
1822
+ disabled,
1823
+ inputMode: "decimal",
1824
+ value: draft,
1825
+ "aria-invalid": !Number.isFinite(Number(draft)),
1826
+ onChange: (next) => {
1827
+ setDraft(next);
1828
+ const number = Number(next);
1829
+ if (Number.isFinite(number)) {
1830
+ const bounded = Math.min(max, Math.max(min, number));
1831
+ if (bounded !== number) setDraft(String(bounded));
1832
+ onChange(bounded);
1833
+ }
1834
+ },
1835
+ onBlur: () => setDraft(String(value))
1836
+ });
1837
+ }
1838
+
1789
1839
  //#endregion
1790
1840
  //#region src/views/panel/rule-edit/styles.ts
1791
1841
  /**
@@ -1856,7 +1906,7 @@ const TextInput$1 = (props) => {
1856
1906
  onFocus: () => setIsFocusFormulaEditor(true)
1857
1907
  })
1858
1908
  });
1859
- else return /* @__PURE__ */ jsx(InputNumber, {
1909
+ else return /* @__PURE__ */ jsx(RuleNumberInput, {
1860
1910
  className,
1861
1911
  value: Number(props.value) || 0,
1862
1912
  onChange: (v) => props.onChange(v || 0),
@@ -2014,7 +2064,7 @@ const ColorScaleStyleEditor = (props) => {
2014
2064
  }),
2015
2065
  /* @__PURE__ */ jsx("div", {
2016
2066
  className: previewClassName,
2017
- children: /* @__PURE__ */ jsx(Preview, { rule: getResult({
2067
+ children: /* @__PURE__ */ jsx(ConditionalFormattingRulePreview, { rule: getResult({
2018
2068
  minType,
2019
2069
  medianType,
2020
2070
  maxType,
@@ -2280,7 +2330,7 @@ const InputText = (props) => {
2280
2330
  })
2281
2331
  });
2282
2332
  }
2283
- return /* @__PURE__ */ jsx(InputNumber, {
2333
+ return /* @__PURE__ */ jsx(RuleNumberInput, {
2284
2334
  className,
2285
2335
  value: Number(value) || 0,
2286
2336
  disabled,
@@ -2440,7 +2490,7 @@ const DataBarStyleEditor = (props) => {
2440
2490
  }),
2441
2491
  /* @__PURE__ */ jsx("div", {
2442
2492
  className: previewClassName,
2443
- children: /* @__PURE__ */ jsx(Preview, { rule: getResult({
2493
+ children: /* @__PURE__ */ jsx(ConditionalFormattingRulePreview, { rule: getResult({
2444
2494
  isGradient,
2445
2495
  minValue,
2446
2496
  minValueType,
@@ -2814,7 +2864,7 @@ const FormulaStyleEditor = (props) => {
2814
2864
  }),
2815
2865
  /* @__PURE__ */ jsx("div", {
2816
2866
  className: previewClassName,
2817
- children: /* @__PURE__ */ jsx(Preview, { rule: getResult({
2867
+ children: /* @__PURE__ */ jsx(ConditionalFormattingRulePreview, { rule: getResult({
2818
2868
  style,
2819
2869
  formula
2820
2870
  }) })
@@ -2967,7 +3017,7 @@ function HighlightCellInput(props) {
2967
3017
  className: "univer-mt-3",
2968
3018
  children: /* @__PURE__ */ jsx(WrapperError, {
2969
3019
  errorText: numberError,
2970
- children: /* @__PURE__ */ jsx(InputNumber, {
3020
+ children: /* @__PURE__ */ jsx(RuleNumberInput, {
2971
3021
  className: "univer-w-full",
2972
3022
  min: Number.MIN_SAFE_INTEGER,
2973
3023
  max: Number.MAX_SAFE_INTEGER,
@@ -2992,7 +3042,7 @@ function HighlightCellInput(props) {
2992
3042
  className: "univer-mt-3 univer-flex univer-items-center",
2993
3043
  children: [/* @__PURE__ */ jsx(WrapperError, {
2994
3044
  errorText: numberMinError,
2995
- children: /* @__PURE__ */ jsx(InputNumber, {
3045
+ children: /* @__PURE__ */ jsx(RuleNumberInput, {
2996
3046
  min: Number.MIN_SAFE_INTEGER,
2997
3047
  max: Number.MAX_SAFE_INTEGER,
2998
3048
  value: inputNumberMin,
@@ -3000,7 +3050,7 @@ function HighlightCellInput(props) {
3000
3050
  })
3001
3051
  }), /* @__PURE__ */ jsx(WrapperError, {
3002
3052
  errorText: numberMaxError,
3003
- children: /* @__PURE__ */ jsx(InputNumber, {
3053
+ children: /* @__PURE__ */ jsx(RuleNumberInput, {
3004
3054
  className: "univer-ml-3",
3005
3055
  min: Number.MIN_SAFE_INTEGER,
3006
3056
  max: Number.MAX_SAFE_INTEGER,
@@ -3221,7 +3271,7 @@ const HighlightCellStyleEditor = (props) => {
3221
3271
  }, `${subType}_${operator}`),
3222
3272
  /* @__PURE__ */ jsx("div", {
3223
3273
  className: previewClassName,
3224
- children: /* @__PURE__ */ jsx(Preview, { rule: getResult({}) })
3274
+ children: /* @__PURE__ */ jsx(ConditionalFormattingRulePreview, { rule: getResult({}) })
3225
3275
  }),
3226
3276
  /* @__PURE__ */ jsx(ConditionalStyleEditor, {
3227
3277
  ColorPickerComponent,
@@ -3254,7 +3304,7 @@ const TextInput = (props) => {
3254
3304
  });
3255
3305
  return /* @__PURE__ */ jsx("div", {
3256
3306
  className: "univer-relative",
3257
- children: type !== CFValueType.formula ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(InputNumber, {
3307
+ children: type !== CFValueType.formula ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(RuleNumberInput, {
3258
3308
  className: clsx({ "univer-border-red-500": error }),
3259
3309
  value: Number(props.value) || 0,
3260
3310
  onChange: (v) => onChange(v ?? 0)
@@ -3908,7 +3958,7 @@ const RankStyleEditor = (props) => {
3908
3958
  }),
3909
3959
  /* @__PURE__ */ jsx("div", {
3910
3960
  className: previewClassName,
3911
- children: /* @__PURE__ */ jsx(Preview, { rule: getResult({
3961
+ children: /* @__PURE__ */ jsx(ConditionalFormattingRulePreview, { rule: getResult({
3912
3962
  type,
3913
3963
  isPercent,
3914
3964
  value,
@@ -4171,8 +4221,9 @@ const RuleEdit = (props) => {
4171
4221
  };
4172
4222
 
4173
4223
  //#endregion
4174
- //#region src/views/panel/RuleList.tsx
4175
- const getRuleDescribe = (rule, localeService) => {
4224
+ //#region src/utils/get-rule-describe.ts
4225
+ /** Returns the localized description used by the built-in conditional formatting rule list. */
4226
+ function getRuleDescribe(rule, localeService) {
4176
4227
  const ruleConfig = rule.rule;
4177
4228
  switch (ruleConfig.type) {
4178
4229
  case CFRuleType.colorScale: return localeService.t("sheets-conditional-formatting-ui.ruleType.colorScale");
@@ -4187,7 +4238,8 @@ const getRuleDescribe = (rule, localeService) => {
4187
4238
  case CFSubRuleType.uniqueValues: return localeService.t("sheets-conditional-formatting-ui.subRuleType.uniqueValues");
4188
4239
  case CFSubRuleType.number: {
4189
4240
  const operator = ruleConfig.operator;
4190
- return localeService.t(`sheets-conditional-formatting-ui.preview.describe.${operator}`, ...Array.isArray(ruleConfig.value) ? ruleConfig.value.map((e) => String(e)) : [String(ruleConfig.value || "")]);
4241
+ const values = Array.isArray(ruleConfig.value) ? ruleConfig.value.map((value) => String(value)) : [String(ruleConfig.value ?? "")];
4242
+ return localeService.t(`sheets-conditional-formatting-ui.preview.describe.${operator}`, ...values);
4191
4243
  }
4192
4244
  case CFSubRuleType.text: {
4193
4245
  const operator = ruleConfig.operator;
@@ -4197,15 +4249,16 @@ const getRuleDescribe = (rule, localeService) => {
4197
4249
  const operator = ruleConfig.operator;
4198
4250
  return localeService.t(`sheets-conditional-formatting-ui.preview.describe.${operator}`);
4199
4251
  }
4200
- case CFSubRuleType.rank: if (ruleConfig.isPercent) {
4201
- if (ruleConfig.isBottom) return localeService.t("sheets-conditional-formatting-ui.preview.describe.bottomNPercent", String(ruleConfig.value));
4202
- else return localeService.t("sheets-conditional-formatting-ui.preview.describe.topNPercent", String(ruleConfig.value));
4203
- } else if (ruleConfig.isBottom) return localeService.t("sheets-conditional-formatting-ui.preview.describe.bottomN", String(ruleConfig.value));
4204
- else return localeService.t("sheets-conditional-formatting-ui.preview.describe.topN", String(ruleConfig.value));
4252
+ case CFSubRuleType.rank:
4253
+ if (ruleConfig.isPercent) return localeService.t(ruleConfig.isBottom ? "sheets-conditional-formatting-ui.preview.describe.bottomNPercent" : "sheets-conditional-formatting-ui.preview.describe.topNPercent", String(ruleConfig.value));
4254
+ return localeService.t(ruleConfig.isBottom ? "sheets-conditional-formatting-ui.preview.describe.bottomN" : "sheets-conditional-formatting-ui.preview.describe.topN", String(ruleConfig.value));
4205
4255
  case CFSubRuleType.formula: return localeService.t("sheets-conditional-formatting-ui.ruleType.formula");
4206
4256
  }
4207
4257
  }
4208
- };
4258
+ }
4259
+
4260
+ //#endregion
4261
+ //#region src/views/panel/RuleList.tsx
4209
4262
  function RuleList(props) {
4210
4263
  const { SelectComponent = Select } = props;
4211
4264
  const { onClick } = props;
@@ -4408,7 +4461,7 @@ function RuleList(props) {
4408
4461
  children: rule.ranges.map((range) => serializeRange(range)).join(",")
4409
4462
  })]
4410
4463
  }),
4411
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Preview, { rule: rule.rule }) }),
4464
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(ConditionalFormattingRulePreview, { rule: rule.rule }) }),
4412
4465
  /* @__PURE__ */ jsx("div", {
4413
4466
  className: clsx("univer-absolute univer-right-1 univer-hidden univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-red-500 group-hover:univer-flex hover:univer-bg-gray-200 rtl:univer-left-1 rtl:univer-right-auto", { "univer-flex univer-items-center univer-justify-center": draggingId === rule.cfId }),
4414
4467
  onClick: (e) => {
@@ -4433,8 +4486,10 @@ const ConditionFormattingPanel = (props) => {
4433
4486
  setIsShowRuleEditor(true);
4434
4487
  };
4435
4488
  const handleCancel = () => {
4489
+ var _props$onEditorExit;
4436
4490
  setIsShowRuleEditor(false);
4437
4491
  setCurrentEditRule(void 0);
4492
+ (_props$onEditorExit = props.onEditorExit) === null || _props$onEditorExit === void 0 || _props$onEditorExit.call(props);
4438
4493
  };
4439
4494
  const handleRuleClick = (rule) => {
4440
4495
  setCurrentEditRule(rule);
@@ -5266,4 +5321,4 @@ UniverSheetsConditionalFormattingUIPlugin = __decorate([
5266
5321
  ], UniverSheetsConditionalFormattingUIPlugin);
5267
5322
 
5268
5323
  //#endregion
5269
- export { AddAverageCfCommand, AddColorScaleConditionalRuleCommand, AddDataBarConditionalRuleCommand, AddDuplicateValuesCfCommand, AddIconSetConditionalRuleCommand, AddNumberCfCommand, AddRankCfCommand, AddTextCfCommand, AddTimePeriodCfCommand, AddUniqueValuesCfCommand, ConditionalFormattingClearController, OpenConditionalFormattingOperator, menuSchema as SheetsConditionalFormattingUIMenuSchema, UniverSheetsConditionalFormattingMobileUIPlugin, UniverSheetsConditionalFormattingUIPlugin };
5324
+ export { AddAverageCfCommand, AddColorScaleConditionalRuleCommand, AddDataBarConditionalRuleCommand, AddDuplicateValuesCfCommand, AddIconSetConditionalRuleCommand, AddNumberCfCommand, AddRankCfCommand, AddTextCfCommand, AddTimePeriodCfCommand, AddUniqueValuesCfCommand, CF_PANEL_KEY, ConditionalFormattingClearController, ConditionalFormattingRulePreview, OpenConditionalFormattingOperator, menuSchema as SheetsConditionalFormattingUIMenuSchema, UniverSheetsConditionalFormattingMobileUIPlugin, UniverSheetsConditionalFormattingUIPlugin, getRuleDescribe };
@@ -26,7 +26,12 @@ export { AddTimePeriodCfCommand } from './commands/commands/add-time-period-cf.c
26
26
  export { AddUniqueValuesCfCommand } from './commands/commands/add-unique-values-cf.command';
27
27
  export { OpenConditionalFormattingOperator } from './commands/operations/open-conditional-formatting-panel';
28
28
  export type { IUniverSheetsConditionalFormattingUIConfig } from './config/config';
29
+ export { CF_PANEL_KEY } from './const';
29
30
  export { ConditionalFormattingClearController } from './controllers/cf.clear.controller';
30
31
  export { menuSchema as SheetsConditionalFormattingUIMenuSchema } from './menu/schema';
31
32
  export { UniverSheetsConditionalFormattingMobileUIPlugin } from './mobile-plugin';
32
33
  export { UniverSheetsConditionalFormattingUIPlugin } from './plugin';
34
+ export { getRuleDescribe } from './utils/get-rule-describe';
35
+ export type { IConditionalFormattingRulePreviewProps } from './views/ConditionalFormattingRulePreview';
36
+ export { ConditionalFormattingRulePreview } from './views/ConditionalFormattingRulePreview';
37
+ export type { IConditionFormattingPanelProps } from './views/ConditionFormattingPanel';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { LocaleService } from '@univerjs/core';
17
+ import type { IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';
18
+ /** Returns the localized description used by the built-in conditional formatting rule list. */
19
+ export declare function getRuleDescribe(rule: IConditionFormattingRule, localeService: LocaleService): string;
@@ -18,6 +18,11 @@ import { RuleEdit } from './panel/RuleEdit';
18
18
  import { RuleList } from './panel/RuleList';
19
19
  export interface IConditionFormattingPanelProps {
20
20
  rule?: IConditionFormattingRule;
21
+ /**
22
+ * Called when editing ends after submission, cancellation, or worksheet activation/removal.
23
+ * Does not indicate that saving succeeded or that the sidebar closed.
24
+ */
25
+ onEditorExit?: () => void;
21
26
  RuleEditComponent?: typeof RuleEdit;
22
27
  RuleListComponent?: typeof RuleList;
23
28
  }
@@ -14,6 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { IConditionalFormattingRuleConfig } from '@univerjs/sheets-conditional-formatting';
17
- export declare function Preview(props: {
17
+ export interface IConditionalFormattingRulePreviewProps {
18
18
  rule?: IConditionalFormattingRuleConfig;
19
- }): import("react").JSX.Element | null | undefined;
19
+ }
20
+ /** Shows a rule's configured appearance without evaluating worksheet values. */
21
+ export declare function ConditionalFormattingRulePreview(props: IConditionalFormattingRulePreviewProps): import("react").JSX.Element | null | undefined;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ interface IRuleNumberInputProps {
17
+ value: number;
18
+ onChange: (value: number) => void;
19
+ min?: number;
20
+ max?: number;
21
+ disabled?: boolean;
22
+ className?: string;
23
+ }
24
+ export declare function RuleNumberInput({ value, onChange, min, max, disabled, className }: IRuleNumberInputProps): import("react").JSX.Element;
25
+ export {};