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