@univerjs/sheets-numfmt-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/cjs/index.js CHANGED
@@ -21,7 +21,7 @@ const CloseNumfmtPanelOperator = {
21
21
  };
22
22
 
23
23
  //#endregion
24
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
24
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
25
25
  function _typeof(o) {
26
26
  "@babel/helpers - typeof";
27
27
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -32,7 +32,7 @@ function _typeof(o) {
32
32
  }
33
33
 
34
34
  //#endregion
35
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
35
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
36
36
  function toPrimitive(t, r) {
37
37
  if ("object" != _typeof(t) || !t) return t;
38
38
  var e = t[Symbol.toPrimitive];
@@ -45,14 +45,14 @@ function toPrimitive(t, r) {
45
45
  }
46
46
 
47
47
  //#endregion
48
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
48
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
49
49
  function toPropertyKey(t) {
50
50
  var i = toPrimitive(t, "string");
51
51
  return "symbol" == _typeof(i) ? i : i + "";
52
52
  }
53
53
 
54
54
  //#endregion
55
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
55
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
56
56
  function _defineProperty(e, r, t) {
57
57
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
58
58
  value: t,
@@ -63,7 +63,7 @@ function _defineProperty(e, r, t) {
63
63
  }
64
64
 
65
65
  //#endregion
66
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
66
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
67
67
  function __decorateParam(paramIndex, decorator) {
68
68
  return function(target, key) {
69
69
  decorator(target, key, paramIndex);
@@ -71,7 +71,7 @@ function __decorateParam(paramIndex, decorator) {
71
71
  }
72
72
 
73
73
  //#endregion
74
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
74
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
75
75
  function __decorate(decorators, target, key, desc) {
76
76
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
77
77
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -429,15 +429,56 @@ function Options() {
429
429
  });
430
430
  }
431
431
 
432
+ //#endregion
433
+ //#region src/menu/numfmt-menu-util.ts
434
+ const FORMAT_TYPE_LABELS = {
435
+ currency: "sheets-numfmt-ui.currency",
436
+ date: "sheets-numfmt-ui.date",
437
+ datetime: "sheets-numfmt-ui.dateTime",
438
+ general: "sheets-numfmt-ui.general",
439
+ grouped: "sheets-numfmt-ui.number",
440
+ number: "sheets-numfmt-ui.number",
441
+ percent: "sheets-numfmt-ui.percent",
442
+ scientific: "sheets-numfmt-ui.scientific",
443
+ text: "sheets-numfmt-ui.text",
444
+ time: "sheets-numfmt-ui.time"
445
+ };
446
+ function getNumberFormatLabelKey(pattern, currencySymbol) {
447
+ if (!pattern || (0, _univerjs_core.isDefaultFormat)(pattern)) return "sheets-numfmt-ui.general";
448
+ if ((0, _univerjs_core.isTextFormat)(pattern)) return "sheets-numfmt-ui.text";
449
+ const preset = MENU_OPTIONS(currencySymbol).find((option) => typeof option === "object" && option.pattern && (0, _univerjs_core.isPatternEqualWithoutDecimal)(pattern, option.pattern));
450
+ if (preset && typeof preset === "object") return preset.label;
451
+ return FORMAT_TYPE_LABELS[(0, _univerjs_sheets_numfmt.getPatternType)(pattern)] ?? "sheets-numfmt-ui.moreFmt";
452
+ }
453
+ function getCurrentNumfmtPattern$(accessor) {
454
+ const commandService = accessor.get(_univerjs_core.ICommandService);
455
+ const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
456
+ const selectionService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
457
+ const commandIds = [
458
+ _univerjs_sheets.RemoveNumfmtMutation.id,
459
+ _univerjs_sheets.SetNumfmtMutation.id,
460
+ _univerjs_sheets.SetRangeValuesMutation.id
461
+ ];
462
+ return (0, _univerjs_sheets_ui.deriveStateFromActiveSheet$)(instanceService, void 0, ({ worksheet }) => (0, rxjs.merge)(selectionService.selectionChanged$, (0, _univerjs_core.fromCallback)(commandService.onCommandExecuted.bind(commandService)).pipe((0, rxjs.filter)(([command]) => commandIds.includes(command.id)))).pipe((0, rxjs.startWith)(null), (0, rxjs.map)(() => {
463
+ var _worksheet$getCellSty;
464
+ const selection = selectionService.getCurrentLastSelection();
465
+ if (!selection) return;
466
+ const cell = selection.primary ?? selection.range;
467
+ return (_worksheet$getCellSty = worksheet.getCellStyle(cell.startRow, cell.startColumn)) === null || _worksheet$getCellSty === void 0 || (_worksheet$getCellSty = _worksheet$getCellSty.n) === null || _worksheet$getCellSty === void 0 ? void 0 : _worksheet$getCellSty.pattern;
468
+ }))).pipe((0, rxjs.distinctUntilChanged)());
469
+ }
470
+
432
471
  //#endregion
433
472
  //#region src/menu/menu.ts
434
473
  function CurrencySymbolIconMenuItem(accessor) {
474
+ const regionService = accessor.get(_univerjs_core.RegionService);
435
475
  return {
436
- icon: accessor.get(_univerjs_core.RegionService).currentRegion$.pipe((0, rxjs.map)((region) => (0, _univerjs_sheets_numfmt.getCurrencySymbolIconByLocale)(region).icon)),
476
+ icon: regionService.currentRegion$.pipe((0, rxjs.map)((region) => (0, _univerjs_sheets_numfmt.getCurrencySymbolIconByLocale)(region).icon)),
437
477
  id: _univerjs_sheets_numfmt.SetCurrencyCommand.id,
438
478
  title: "sheets-numfmt-ui.currency",
439
479
  tooltip: "sheets-numfmt-ui.currency",
440
480
  type: _univerjs_ui.MenuItemType.BUTTON,
481
+ activated$: (0, rxjs.combineLatest)([getCurrentNumfmtPattern$(accessor), regionService.currentRegion$]).pipe((0, rxjs.map)(([pattern, region]) => !!pattern && (0, _univerjs_sheets_numfmt.getPatternType)(pattern) === "currency" && (0, _univerjs_sheets_numfmt.getCurrencyType)(pattern) === (0, _univerjs_sheets_numfmt.getCurrencySymbolIconByLocale)(region).symbol), (0, rxjs.distinctUntilChanged)()),
441
482
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
442
483
  disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
443
484
  workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
@@ -483,6 +524,7 @@ function PercentMenuItem(accessor) {
483
524
  title: "sheets-numfmt-ui.percent",
484
525
  tooltip: "sheets-numfmt-ui.percent",
485
526
  type: _univerjs_ui.MenuItemType.BUTTON,
527
+ activated$: getCurrentNumfmtPattern$(accessor).pipe((0, rxjs.map)((pattern) => !!pattern && (0, _univerjs_sheets_numfmt.getPatternType)(pattern) === "percent"), (0, rxjs.distinctUntilChanged)()),
486
528
  hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
487
529
  disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
488
530
  workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
@@ -492,35 +534,13 @@ function PercentMenuItem(accessor) {
492
534
  };
493
535
  }
494
536
  function FactoryOtherMenuItem(accessor) {
495
- const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
496
- const commandService = accessor.get(_univerjs_core.ICommandService);
497
537
  const localeService = accessor.get(_univerjs_core.LocaleService);
498
538
  const regionService = accessor.get(_univerjs_core.RegionService);
499
- const selectionManagerService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
500
- const commandList = [_univerjs_sheets.RemoveNumfmtMutation.id, _univerjs_sheets.SetNumfmtMutation.id];
501
- const value$ = (0, _univerjs_sheets_ui.deriveStateFromActiveSheet$)(univerInstanceService, "", ({ workbook, worksheet }) => new rxjs.Observable((subscribe) => (0, rxjs.merge)(selectionManagerService.selectionMoveEnd$, regionService.currentRegion$, (0, _univerjs_core.fromCallback)(commandService.onCommandExecuted.bind(commandService)).pipe((0, rxjs.filter)(([commandInfo]) => commandList.includes(commandInfo.id)))).subscribe(() => {
502
- const selections = selectionManagerService.getCurrentSelections();
503
- if (selections && selections[0]) {
504
- var _workbook$getStyles$g, _worksheet$getCell;
505
- const range = selections[0].range;
506
- const row = range.startRow;
507
- const col = range.startColumn;
508
- const numfmtValue = (_workbook$getStyles$g = workbook.getStyles().get((_worksheet$getCell = worksheet.getCell(row, col)) === null || _worksheet$getCell === void 0 ? void 0 : _worksheet$getCell.s)) === null || _workbook$getStyles$g === void 0 ? void 0 : _workbook$getStyles$g.n;
509
- const pattern = numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern;
510
- const currencySymbol = (0, _univerjs_sheets_numfmt.getCurrencySymbolByLocale)(regionService.getCurrentRegion());
511
- let value = localeService.t("sheets-numfmt-ui.general");
512
- if ((0, _univerjs_core.isDefaultFormat)(pattern)) {
513
- subscribe.next(value);
514
- return;
515
- }
516
- if (pattern) {
517
- const item = MENU_OPTIONS(currencySymbol).filter((item) => typeof item === "object" && item.pattern).find((item) => (0, _univerjs_core.isPatternEqualWithoutDecimal)(pattern, item.pattern));
518
- if (item && typeof item === "object" && item.pattern) value = localeService.t(item.label);
519
- else value = localeService.t("sheets-numfmt-ui.moreFmt");
520
- }
521
- subscribe.next(value);
522
- }
523
- })));
539
+ const value$ = (0, rxjs.combineLatest)([
540
+ getCurrentNumfmtPattern$(accessor),
541
+ regionService.currentRegion$,
542
+ localeService.currentLocale$
543
+ ]).pipe((0, rxjs.map)(([pattern, region]) => localeService.t(getNumberFormatLabelKey(pattern, (0, _univerjs_sheets_numfmt.getCurrencySymbolByLocale)(region)))), (0, rxjs.distinctUntilChanged)());
524
544
  return {
525
545
  label: MORE_NUMFMT_TYPE_KEY,
526
546
  id: OpenNumfmtPanelOperator.id,
@@ -592,7 +612,7 @@ const menuSchema = { [_univerjs_ui.RibbonStartGroup.NUMBER]: {
592
612
  //#endregion
593
613
  //#region package.json
594
614
  var name = "@univerjs/sheets-numfmt-ui";
595
- var version = "1.0.3";
615
+ var version = "1.1.0";
596
616
 
597
617
  //#endregion
598
618
  //#region src/config/config.ts
@@ -671,39 +691,17 @@ function createMobileNumberFormatMenuConfig(currencySymbol) {
671
691
  commandId: _univerjs_sheets_numfmt.AddDecimalCommand.id
672
692
  }],
673
693
  detailOptions,
674
- customPatterns: [.../* @__PURE__ */ new Set([
675
- ..._univerjs_sheets_numfmt.CURRENCYFORMAT.map((item) => item.suffix(currencySymbol)),
676
- ..._univerjs_sheets_numfmt.DATEFMTLISG.map((item) => item.suffix),
677
- ..._univerjs_sheets_numfmt.NUMBERFORMAT.map((item) => item.suffix)
678
- ])]
694
+ customPatterns: [.../* @__PURE__ */ new Set([..._univerjs_sheets_numfmt.CURRENCYFORMAT.map((item) => item.suffix(currencySymbol)), ..._univerjs_sheets_numfmt.NUMBERFORMAT.map((item) => item.suffix)])]
679
695
  };
680
696
  }
681
697
  function FactoryMobileOtherMenuItem(accessor) {
682
- const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
683
- const commandService = accessor.get(_univerjs_core.ICommandService);
684
698
  const localeService = accessor.get(_univerjs_core.LocaleService);
685
699
  const regionService = accessor.get(_univerjs_core.RegionService);
686
- const selectionManagerService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
687
- const commandList = [_univerjs_sheets.RemoveNumfmtMutation.id, _univerjs_sheets.SetNumfmtMutation.id];
688
- const value$ = (0, _univerjs_sheets_ui.deriveStateFromActiveSheet$)(univerInstanceService, "", ({ workbook, worksheet }) => new rxjs.Observable((subscribe) => (0, rxjs.merge)(selectionManagerService.selectionMoveEnd$, regionService.currentRegion$, (0, _univerjs_core.fromCallback)(commandService.onCommandExecuted.bind(commandService)).pipe((0, rxjs.filter)(([commandInfo]) => commandList.includes(commandInfo.id)))).subscribe(() => {
689
- var _selectionManagerServ, _workbook$getStyles$g, _worksheet$getCell;
690
- const selection = (_selectionManagerServ = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ === void 0 ? void 0 : _selectionManagerServ[0];
691
- if (!selection) return;
692
- const { startRow, startColumn } = selection.range;
693
- const numfmtValue = (_workbook$getStyles$g = workbook.getStyles().get((_worksheet$getCell = worksheet.getCell(startRow, startColumn)) === null || _worksheet$getCell === void 0 ? void 0 : _worksheet$getCell.s)) === null || _workbook$getStyles$g === void 0 ? void 0 : _workbook$getStyles$g.n;
694
- const pattern = numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern;
695
- const currencySymbol = (0, _univerjs_sheets_numfmt.getCurrencySymbolByLocale)(regionService.getCurrentRegion());
696
- let value = localeService.t("sheets-numfmt-ui.general");
697
- if ((0, _univerjs_core.isDefaultFormat)(pattern)) {
698
- subscribe.next(value);
699
- return;
700
- }
701
- if (pattern) {
702
- const item = MENU_OPTIONS(currencySymbol).filter((option) => typeof option === "object" && option.pattern).find((option) => (0, _univerjs_core.isPatternEqualWithoutDecimal)(pattern, option.pattern));
703
- value = item && typeof item === "object" && item.pattern ? localeService.t(item.label) : localeService.t("sheets-numfmt-ui.moreFmt");
704
- }
705
- subscribe.next(value);
706
- })));
700
+ const value$ = (0, rxjs.combineLatest)([
701
+ getCurrentNumfmtPattern$(accessor),
702
+ regionService.currentRegion$,
703
+ localeService.currentLocale$
704
+ ]).pipe((0, rxjs.map)(([pattern, region]) => localeService.t(getNumberFormatLabelKey(pattern, (0, _univerjs_sheets_numfmt.getCurrencySymbolByLocale)(region)))), (0, rxjs.distinctUntilChanged)());
707
705
  return {
708
706
  id: MOBILE_NUMFMT_MENU_ID,
709
707
  title: "sheets-numfmt-ui.title",
@@ -726,15 +724,27 @@ function FactoryMobileOtherMenuItem(accessor) {
726
724
  function MobileCustomFormat(props) {
727
725
  const { patterns, onConfirm } = props;
728
726
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
727
+ const locale = (0, _univerjs_ui.useObservable)(localeService.currentLocale$, localeService.getCurrentLocale());
729
728
  const [pattern, setPattern] = (0, react.useState)("");
730
729
  const title = localeService.t("sheets-numfmt-ui.customFormat");
730
+ const options = (0, react.useMemo)(() => [.../* @__PURE__ */ new Set([
731
+ ...patterns,
732
+ ...(0, _univerjs_sheets_numfmt.getDateFormatOptions)(locale).map((item) => item.value),
733
+ ...pattern ? [pattern] : []
734
+ ])].map((value) => ({
735
+ label: value,
736
+ value
737
+ })), [
738
+ locale,
739
+ pattern,
740
+ patterns
741
+ ]);
731
742
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
732
743
  "data-u-comp": "mobile-custom-format",
733
744
  className: "univer-flex univer-h-full univer-min-h-0 univer-flex-col univer-gap-4",
734
745
  children: [
735
746
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
736
747
  className: "univer-shrink-0",
737
- size: "large",
738
748
  "aria-label": title,
739
749
  value: pattern,
740
750
  placeholder: title,
@@ -743,10 +753,7 @@ function MobileCustomFormat(props) {
743
753
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.MobileSelect, {
744
754
  className: "univer-w-full univer-shrink-0 [&>div]:univer-font-mono",
745
755
  value: pattern || title,
746
- options: patterns.map((item) => ({
747
- label: item,
748
- value: item
749
- })),
756
+ options,
750
757
  onChange: setPattern
751
758
  }),
752
759
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -1620,14 +1627,15 @@ function CustomFormat(props) {
1620
1627
  const userHabitController = (0, _univerjs_ui.useDependency)(UserHabitController);
1621
1628
  const localStorageService = (0, _univerjs_ui.useDependency)(_univerjs_core.ILocalStorageService);
1622
1629
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1630
+ const locale = (0, _univerjs_ui.useObservable)(localeService.currentLocale$, localeService.getCurrentLocale());
1623
1631
  const [pattern, setPattern] = (0, react.useState)(defaultPattern);
1624
1632
  (0, react.useLayoutEffect)(() => {
1625
1633
  onActionChange(() => {
1626
1634
  userHabitController.markHabit(key$1, pattern);
1627
1635
  localStorageService.getItem(historyPatternKey).then((list = []) => {
1628
1636
  const _list = [.../* @__PURE__ */ new Set([pattern, ...list || []])].splice(0, 10).filter((e) => !!e);
1629
- localStorageService.setItem(historyPatternKey, _list);
1630
- });
1637
+ return localStorageService.setItem(historyPatternKey, _list);
1638
+ }).catch(console.error);
1631
1639
  return pattern;
1632
1640
  });
1633
1641
  }, [
@@ -1642,18 +1650,22 @@ function CustomFormat(props) {
1642
1650
  localStorageService.getItem(historyPatternKey).then((historyList) => {
1643
1651
  const list = [
1644
1652
  ..._univerjs_sheets_numfmt.CURRENCYFORMAT.map((item) => item.suffix("$")),
1645
- ..._univerjs_sheets_numfmt.DATEFMTLISG.map((item) => item.suffix),
1653
+ ...(0, _univerjs_sheets_numfmt.getDateFormatOptions)(locale).map((item) => item.value),
1646
1654
  ..._univerjs_sheets_numfmt.NUMBERFORMAT.map((item) => item.suffix),
1647
1655
  ...historyList ?? []
1648
1656
  ];
1649
1657
  return userHabitController.addHabit(key$1, []).then(() => userHabitController.getHabit(key$1, list));
1650
1658
  }).then((list) => {
1651
1659
  if (!cancelled) setOptions([...new Set(list)]);
1652
- });
1660
+ }).catch(console.error);
1653
1661
  return () => {
1654
1662
  cancelled = true;
1655
1663
  };
1656
- }, [localStorageService, userHabitController]);
1664
+ }, [
1665
+ locale,
1666
+ localStorageService,
1667
+ userHabitController
1668
+ ]);
1657
1669
  const handleClick = (p) => {
1658
1670
  setPattern(p);
1659
1671
  onChange(p);
@@ -1695,7 +1707,7 @@ function CustomFormat(props) {
1695
1707
  //#region src/views/components/Date.tsx
1696
1708
  const isDatePanel = (pattern) => {
1697
1709
  const info = _univerjs_core.numfmt.getFormatInfo(pattern);
1698
- return (0, _univerjs_sheets_numfmt.getDateFormatOptions)().map((item) => item.value).includes(pattern) || [
1710
+ return [
1699
1711
  "date",
1700
1712
  "datetime",
1701
1713
  "time"
@@ -1703,20 +1715,15 @@ const isDatePanel = (pattern) => {
1703
1715
  };
1704
1716
  function DatePanel(props) {
1705
1717
  const { onActionChange, onChange, defaultPattern } = props;
1706
- const options = (0, react.useMemo)(_univerjs_sheets_numfmt.getDateFormatOptions, []);
1707
1718
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1708
- const [suffix, setSuffix] = (0, react.useState)(() => {
1709
- if (defaultPattern) {
1710
- const item = options.find((item) => item.value === defaultPattern);
1711
- if (item) return item.value;
1712
- }
1713
- return options[0].value;
1714
- });
1719
+ const locale = (0, _univerjs_ui.useObservable)(localeService.currentLocale$, localeService.getCurrentLocale());
1720
+ const [suffix, setSuffix] = (0, react.useState)(() => defaultPattern || (0, _univerjs_sheets_numfmt.getDateFormatOptions)(locale)[0].value);
1721
+ const options = (0, react.useMemo)(() => (0, _univerjs_sheets_numfmt.getDateFormatOptions)(locale, suffix), [locale, suffix]);
1715
1722
  (0, react.useLayoutEffect)(() => {
1716
1723
  onActionChange(() => suffix);
1717
1724
  }, [onActionChange, suffix]);
1718
1725
  const handleChange = (v) => {
1719
- if (v === void 0) return;
1726
+ if (typeof v !== "string") return;
1720
1727
  setSuffix(v);
1721
1728
  onChange(v);
1722
1729
  };
@@ -1889,47 +1896,51 @@ const useNextTick = () => {
1889
1896
 
1890
1897
  //#endregion
1891
1898
  //#region src/views/SheetNumfmtPanel.tsx
1899
+ const TYPE_OPTIONS = [
1900
+ {
1901
+ label: "sheets-numfmt-ui.general",
1902
+ component: GeneralPanel
1903
+ },
1904
+ {
1905
+ label: "sheets-numfmt-ui.accounting",
1906
+ component: AccountingPanel
1907
+ },
1908
+ {
1909
+ label: "sheets-numfmt-ui.currency",
1910
+ component: CurrencyPanel
1911
+ },
1912
+ {
1913
+ label: "sheets-numfmt-ui.date",
1914
+ component: DatePanel
1915
+ },
1916
+ {
1917
+ label: "sheets-numfmt-ui.thousandthPercentile",
1918
+ component: ThousandthPercentilePanel
1919
+ },
1920
+ {
1921
+ label: "sheets-numfmt-ui.customFormat",
1922
+ component: CustomFormat
1923
+ }
1924
+ ];
1892
1925
  function SheetNumfmtPanel(props) {
1893
- var _typeOptions$find;
1926
+ const { row, col, defaultPattern } = props.value;
1927
+ return /* @__PURE__ */ (0, react.createElement)(SheetNumfmtPanelContent, {
1928
+ ...props,
1929
+ key: `${row}_${col}_${defaultPattern}`
1930
+ });
1931
+ }
1932
+ function SheetNumfmtPanelContent(props) {
1933
+ var _TYPE_OPTIONS$find;
1934
+ const { onChange } = props;
1894
1935
  const { defaultValue, defaultPattern, row, col } = props.value;
1895
1936
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1937
+ (0, _univerjs_ui.useObservable)(localeService.currentLocale$, localeService.getCurrentLocale());
1896
1938
  const currentPatternRef = (0, react.useRef)(() => "");
1897
1939
  const nextTick = useNextTick();
1898
- const typeOptions = (0, react.useMemo)(() => {
1899
- return [
1900
- {
1901
- label: "sheets-numfmt-ui.general",
1902
- component: GeneralPanel
1903
- },
1904
- {
1905
- label: "sheets-numfmt-ui.accounting",
1906
- component: AccountingPanel
1907
- },
1908
- {
1909
- label: "sheets-numfmt-ui.currency",
1910
- component: CurrencyPanel
1911
- },
1912
- {
1913
- label: "sheets-numfmt-ui.date",
1914
- component: DatePanel
1915
- },
1916
- {
1917
- label: "sheets-numfmt-ui.thousandthPercentile",
1918
- component: ThousandthPercentilePanel
1919
- },
1920
- {
1921
- label: "sheets-numfmt-ui.customFormat",
1922
- component: CustomFormat
1923
- }
1924
- ].map((item) => ({
1925
- ...item,
1926
- label: localeService.t(item.label)
1927
- }));
1928
- }, [localeService]);
1929
1940
  const [type, setType] = (0, react.useState)(findDefaultType);
1930
1941
  const [key, setKey] = (0, react.useState)(() => `${row}_${col}_${defaultPattern}`);
1931
1942
  const { mark, userHabitCurrency } = useCurrencyOptions(() => setKey(`${row}_${col}_${defaultPattern}_userCurrency`));
1932
- const BusinessComponent = (_typeOptions$find = typeOptions.find((item) => item.label === type)) === null || _typeOptions$find === void 0 ? void 0 : _typeOptions$find.component;
1943
+ const BusinessComponent = (_TYPE_OPTIONS$find = TYPE_OPTIONS.find((item) => item.label === type)) === null || _TYPE_OPTIONS$find === void 0 ? void 0 : _TYPE_OPTIONS$find.component;
1933
1944
  function findDefaultType() {
1934
1945
  return [
1935
1946
  isGeneralPanel,
@@ -1937,25 +1948,25 @@ function SheetNumfmtPanel(props) {
1937
1948
  isCurrencyPanel,
1938
1949
  isDatePanel,
1939
1950
  isThousandthPercentilePanel
1940
- ].reduce((pre, curFn, index) => pre || (curFn(defaultPattern) ? typeOptions[index].label : ""), "") || typeOptions[0].label;
1951
+ ].reduce((pre, curFn, index) => pre || (curFn(defaultPattern) ? TYPE_OPTIONS[index].label : ""), "") || "sheets-numfmt-ui.customFormat";
1941
1952
  }
1942
- const selectOptions = typeOptions.map((option) => ({
1943
- label: option.label,
1953
+ const selectOptions = TYPE_OPTIONS.map((option) => ({
1954
+ label: localeService.t(option.label),
1944
1955
  value: option.label
1945
1956
  }));
1946
1957
  const handleSelect = (value) => {
1947
1958
  setType(value);
1948
- nextTick(() => props.onChange({
1959
+ nextTick(() => onChange({
1949
1960
  type: "change",
1950
1961
  value: currentPatternRef.current() || ""
1951
1962
  }));
1952
1963
  };
1953
1964
  const handleChange = (0, react.useCallback)((v) => {
1954
- props.onChange({
1965
+ onChange({
1955
1966
  type: "change",
1956
1967
  value: v
1957
1968
  });
1958
- }, []);
1969
+ }, [onChange]);
1959
1970
  const handleActionChange = (0, react.useCallback)((action) => {
1960
1971
  currentPatternRef.current = action;
1961
1972
  }, []);
@@ -1963,13 +1974,13 @@ function SheetNumfmtPanel(props) {
1963
1974
  const pattern = currentPatternRef.current() || "";
1964
1975
  const currency = (0, _univerjs_sheets_numfmt.getCurrencyType)(pattern);
1965
1976
  if (currency) mark(currency);
1966
- props.onChange({
1977
+ onChange({
1967
1978
  type: "confirm",
1968
1979
  value: pattern
1969
1980
  });
1970
1981
  };
1971
1982
  const handleCancel = () => {
1972
- props.onChange({
1983
+ onChange({
1973
1984
  type: "cancel",
1974
1985
  value: ""
1975
1986
  });
@@ -1980,14 +1991,6 @@ function SheetNumfmtPanel(props) {
1980
1991
  defaultValue,
1981
1992
  defaultPattern
1982
1993
  };
1983
- (0, react.useEffect)(() => {
1984
- setType(findDefaultType());
1985
- setKey(`${row}_${col}_${defaultPattern}`);
1986
- }, [
1987
- row,
1988
- col,
1989
- defaultPattern
1990
- ]);
1991
1994
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1992
1995
  className: (0, _univerjs_design.clsx)("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5", _univerjs_design.scrollbarClassName),
1993
1996
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
@@ -2157,13 +2160,13 @@ UniverSheetsNumfmtUIPlugin = __decorate([
2157
2160
 
2158
2161
  //#endregion
2159
2162
  exports.SheetsNumfmtUIMenuSchema = menuSchema;
2160
- Object.defineProperty(exports, 'UniverSheetsNumfmtMobileUIPlugin', {
2163
+ Object.defineProperty(exports, "UniverSheetsNumfmtMobileUIPlugin", {
2161
2164
  enumerable: true,
2162
2165
  get: function () {
2163
2166
  return UniverSheetsNumfmtMobileUIPlugin;
2164
2167
  }
2165
2168
  });
2166
- Object.defineProperty(exports, 'UniverSheetsNumfmtUIPlugin', {
2169
+ Object.defineProperty(exports, "UniverSheetsNumfmtUIPlugin", {
2167
2170
  enumerable: true,
2168
2171
  get: function () {
2169
2172
  return UniverSheetsNumfmtUIPlugin;