@univerjs/sheets-numfmt 0.2.7 → 0.2.9

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.
Files changed (39) hide show
  1. package/lib/cjs/index.js +2 -2
  2. package/lib/es/index.js +389 -319
  3. package/lib/index.css +1 -1
  4. package/lib/types/base/const/CURRENCY-SYMBOLS.d.ts +30 -0
  5. package/lib/types/base/types/index.d.ts +0 -1
  6. package/lib/types/commands/commands/add-decimal.command.d.ts +0 -1
  7. package/lib/types/commands/commands/set-currency.command.d.ts +0 -1
  8. package/lib/types/commands/commands/set-numfmt.command.d.ts +0 -1
  9. package/lib/types/commands/commands/set-percent.command.d.ts +0 -1
  10. package/lib/types/commands/commands/subtract-decimal.command.d.ts +0 -1
  11. package/lib/types/commands/operations/close.numfmt.panel.operation.d.ts +0 -1
  12. package/lib/types/commands/operations/open.numfmt.panel.operation.d.ts +0 -1
  13. package/lib/types/components/accounting/index.d.ts +0 -1
  14. package/lib/types/components/currency/index.d.ts +0 -1
  15. package/lib/types/components/custom-format/index.d.ts +0 -1
  16. package/lib/types/components/date/index.d.ts +0 -1
  17. package/lib/types/components/general/index.d.ts +0 -1
  18. package/lib/types/components/index.d.ts +0 -1
  19. package/lib/types/components/more-numfmt-type/MoreNumfmtType.d.ts +0 -1
  20. package/lib/types/components/stories/Panel.stories.d.ts +0 -1
  21. package/lib/types/components/thousandth-percentile/index.d.ts +0 -1
  22. package/lib/types/controllers/__tests__/test.util.d.ts +0 -1
  23. package/lib/types/controllers/numfmt.cell-content.controller.d.ts +0 -1
  24. package/lib/types/controllers/numfmt.controller.d.ts +0 -1
  25. package/lib/types/controllers/numfmt.editor.controller.d.ts +0 -1
  26. package/lib/types/controllers/numfmt.i18n.controller.d.ts +0 -1
  27. package/lib/types/controllers/numfmt.menu.controller.d.ts +8 -1
  28. package/lib/types/controllers/user-habit.controller.d.ts +0 -1
  29. package/lib/types/index.d.ts +2 -0
  30. package/lib/types/locale/en-US.d.ts +0 -1
  31. package/lib/types/locale/ru-RU.d.ts +0 -1
  32. package/lib/types/locale/vi-VN.d.ts +0 -1
  33. package/lib/types/locale/zh-TW.d.ts +0 -1
  34. package/lib/types/menu/menu.d.ts +1 -2
  35. package/lib/types/numfmt-plugin.d.ts +0 -1
  36. package/lib/types/utils/mutation.d.ts +0 -1
  37. package/lib/types/utils/pattern.d.ts +0 -1
  38. package/lib/umd/index.js +2 -2
  39. package/package.json +19 -19
package/lib/es/index.js CHANGED
@@ -2,14 +2,14 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key2] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 != "symbol" ? key2 + "" : key2, value);
5
- import { LocaleType, Disposable, ObjectMatrix, CellValueType, Range, UniverInstanceType, OnLifecycle, LifecycleStages, Inject, ThemeService, ICommandService, LocaleService, IUniverInstanceService, CommandType, IUndoRedoService, sequenceExecute, createIdentifier, runOnLifecycle, ILocalStorageService, useDependency, toDisposable, DisposableCollection, Injector, Optional, useInjector, Plugin, Tools, DependentOn } from "@univerjs/core";
6
- import { INTERCEPTOR_POINT, SetNumfmtMutation, SetRangeValuesMutation, SheetInterceptorService, INumfmtService, getSheetCommandTarget, transformCellsToRange, rangeMerge, factorySetNumfmtUndoMutation, RemoveNumfmtMutation, factoryRemoveNumfmtUndoMutation, SheetsSelectionsService, SetRangeValuesCommand, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, RangeProtectionPermissionEditPoint, UniverSheetsPlugin } from "@univerjs/sheets";
7
- import { SheetSkeletonManagerService, IEditorBridgeService, getCurrentRangeDisable$, deriveStateFromActiveSheet$, UniverSheetsUIPlugin } from "@univerjs/sheets-ui";
8
- import { switchMap, of, skip, Observable, combineLatest, merge } from "rxjs";
9
- import { numfmt, DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
10
- import { IRenderManagerService, ITextSelectionRenderManager } from "@univerjs/engine-render";
11
- import { ComponentManager, ISidebarService, MenuItemType, MenuGroup, MenuPosition, getMenuHiddenObservable, IMenuService } from "@univerjs/ui";
5
+ import { numfmt, LocaleType, Disposable, ObjectMatrix, CellValueType, Range, UniverInstanceType, OnLifecycle, LifecycleStages, Inject, ThemeService, ICommandService, LocaleService, IUniverInstanceService, CommandType, IUndoRedoService, sequenceExecute, createIdentifier, runOnLifecycle, useDependency, useInjector, Injector, ILocalStorageService, toDisposable, DisposableCollection, Optional, Plugin, Tools, DependentOn } from "@univerjs/core";
6
+ import { INTERCEPTOR_POINT, InterceptCellContentPriority, SetNumfmtMutation, SetRangeValuesMutation, SheetInterceptorService, INumfmtService, getSheetCommandTarget, transformCellsToRange, rangeMerge, factorySetNumfmtUndoMutation, RemoveNumfmtMutation, factoryRemoveNumfmtUndoMutation, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, RangeProtectionPermissionEditPoint, SetRangeValuesCommand, UniverSheetsPlugin } from "@univerjs/sheets";
7
+ import { getCurrentRangeDisable$, deriveStateFromActiveSheet$, SheetSkeletonManagerService, IEditorBridgeService, UniverSheetsUIPlugin } from "@univerjs/sheets-ui";
8
+ import { switchMap, of, skip, Observable, merge, BehaviorSubject, combineLatest } from "rxjs";
9
+ import { ITextSelectionRenderManager, IRenderManagerService } from "@univerjs/engine-render";
10
+ import { MenuItemType, MenuGroup, MenuPosition, getMenuHiddenObservable, ComponentManager, IMenuService, ISidebarService } from "@univerjs/ui";
12
11
  import { map, switchMap as switchMap$1, tap, debounceTime } from "rxjs/operators";
12
+ import { DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
13
13
  import require$$0, { createContext, useState, useEffect, useRef, useContext, useMemo, forwardRef, createElement } from "react";
14
14
  import { InputNumber, Select, SelectList, Input, Button } from "@univerjs/design";
15
15
  const SHEET_NUMFMT_PLUGIN = "SHEET_NUMFMT_PLUGIN", getPatternType = /* @__PURE__ */ __name((pattern) => numfmt.getInfo(pattern).type || "unknown", "getPatternType"), getPatternPreview = /* @__PURE__ */ __name((pattern, value, _locale) => {
@@ -30,6 +30,7 @@ let SheetsNumfmtCellContentController = (_a = class extends Disposable {
30
30
  constructor(_instanceService, _sheetInterceptorService, _themeService, _commandService, _numfmtService, _localeService) {
31
31
  super(), this._instanceService = _instanceService, this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._commandService = _commandService, this._numfmtService = _numfmtService, this._localeService = _localeService, this._initInterceptorCellContent();
32
32
  }
33
+ // eslint-disable-next-line max-lines-per-function
33
34
  _initInterceptorCellContent() {
34
35
  const renderCache = new ObjectMatrix();
35
36
  this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
@@ -62,7 +63,7 @@ let SheetsNumfmtCellContentController = (_a = class extends Disposable {
62
63
  parameters: `${originCellValue.v}_${numfmtValue.pattern}`
63
64
  }), next({ ...cell, ...res });
64
65
  }, "handler"),
65
- priority: 10
66
+ priority: InterceptCellContentPriority.NUMFMT
66
67
  })), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
67
68
  if (commandInfo.id === SetNumfmtMutation.id) {
68
69
  const params = commandInfo.params;
@@ -307,21 +308,128 @@ const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0)
307
308
  suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`, "suffix"),
308
309
  color: "red"
309
310
  }
310
- ], SetCurrencyCommand = {
311
- id: "sheet.command.numfmt.set.currency",
312
- type: CommandType.COMMAND,
313
- handler: /* @__PURE__ */ __name(async (accessor) => {
314
- const commandService = accessor.get(ICommandService), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
315
- if (!selections || !selections.length)
316
- return !1;
317
- const values = [], suffix = CURRENCYFORMAT[0].suffix("¥");
318
- return selections.forEach((selection) => {
319
- Range.foreach(selection.range, (row, col) => {
320
- values.push({ row, col, pattern: suffix, type: "currency" });
321
- });
322
- }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
323
- }, "handler")
324
- }, SubtractDecimalCommand = {
311
+ ], currencySymbols = [
312
+ "$",
313
+ "£",
314
+ "¥",
315
+ "¤",
316
+ "֏",
317
+ "؋",
318
+ "",
319
+ "฿",
320
+ // '៛',
321
+ "",
322
+ "₦",
323
+ "₩",
324
+ "",
325
+ "₫",
326
+ "€",
327
+ "₭",
328
+ "₮",
329
+ "₱",
330
+ "₲",
331
+ "₴",
332
+ "₸",
333
+ "₹",
334
+ "₺",
335
+ "₼",
336
+ "₽",
337
+ "₾",
338
+ "₿"
339
+ ], countryCurrencyMap = {
340
+ US: "$",
341
+ // United States Dollar
342
+ CA: "C$",
343
+ // Canadian Dollar
344
+ GB: "£",
345
+ // British Pound Sterling
346
+ JP: "¥",
347
+ // Japanese Yen
348
+ IN: "₹",
349
+ // Indian Rupee
350
+ AU: "A$",
351
+ // Australian Dollar
352
+ CN: "¥",
353
+ // Chinese Yuan
354
+ KR: "₩",
355
+ // South Korean Won
356
+ RU: "₽",
357
+ // Russian Ruble
358
+ // Euro countries
359
+ AT: "€",
360
+ BE: "€",
361
+ CY: "€",
362
+ EE: "€",
363
+ FI: "€",
364
+ FR: "€",
365
+ DE: "€",
366
+ GR: "€",
367
+ IE: "€",
368
+ IT: "€",
369
+ LV: "€",
370
+ LT: "€",
371
+ LU: "€",
372
+ MT: "€",
373
+ NL: "€",
374
+ PT: "€",
375
+ SK: "€",
376
+ SI: "€",
377
+ ES: "€"
378
+ // Add more mappings as needed
379
+ }, MENU_OPTIONS = [
380
+ {
381
+ label: "sheet.numfmt.general",
382
+ pattern: null
383
+ },
384
+ {
385
+ label: "sheet.numfmt.text",
386
+ pattern: DEFAULT_TEXT_FORMAT
387
+ },
388
+ "|",
389
+ {
390
+ label: "sheet.numfmt.number",
391
+ pattern: "0"
392
+ },
393
+ "|",
394
+ {
395
+ label: "sheet.numfmt.accounting",
396
+ pattern: '"¥" #,##0.00_);[Red]("¥"#,##0.00)'
397
+ },
398
+ {
399
+ label: "sheet.numfmt.financialValue",
400
+ pattern: "#,##0.00;[Red]#,##0.00"
401
+ },
402
+ {
403
+ label: "sheet.numfmt.currency",
404
+ pattern: '"¥"#,##0.00_);[Red]("¥"#,##0.00)'
405
+ },
406
+ {
407
+ label: "sheet.numfmt.roundingCurrency",
408
+ pattern: '"¥"#,##0;[Red]"¥"#,##0'
409
+ },
410
+ "|",
411
+ {
412
+ label: "sheet.numfmt.date",
413
+ pattern: "yyyy-mm-dd;@"
414
+ },
415
+ {
416
+ label: "sheet.numfmt.time",
417
+ pattern: 'am/pm h":"mm":"ss'
418
+ },
419
+ {
420
+ label: "sheet.numfmt.dateTime",
421
+ pattern: "yyyy-m-d am/pm h:mm"
422
+ },
423
+ {
424
+ label: "sheet.numfmt.timeDuration",
425
+ pattern: "h:mm:ss"
426
+ },
427
+ "|",
428
+ {
429
+ label: "sheet.numfmt.moreFmt",
430
+ pattern: ""
431
+ }
432
+ ], SubtractDecimalCommand = {
325
433
  id: "sheet.command.numfmt.subtract.decimal.command",
326
434
  type: CommandType.COMMAND,
327
435
  handler: /* @__PURE__ */ __name(async (accessor) => {
@@ -362,13 +470,6 @@ const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0)
362
470
  });
363
471
  }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
364
472
  }, "handler")
365
- }, CloseNumfmtPanelOperator = {
366
- id: "sheet.operation.close.numfmt.panel",
367
- type: CommandType.OPERATION,
368
- handler: /* @__PURE__ */ __name(() => (
369
- // do nothing,just notify panel is closed
370
- !0
371
- ), "handler")
372
473
  }, INumfmtController = createIdentifier("INumfmtController");
373
474
  runOnLifecycle(LifecycleStages.Rendered, INumfmtController);
374
475
  const OpenNumfmtPanelOperator = {
@@ -400,41 +501,223 @@ reactJsxRuntime_production_min.jsx = q;
400
501
  reactJsxRuntime_production_min.jsxs = q;
401
502
  jsxRuntime.exports = reactJsxRuntime_production_min;
402
503
  var jsxRuntimeExports = jsxRuntime.exports;
403
- const UserHabitCurrencyContext = createContext([]), currencySymbols = [
404
- "$",
405
- "£",
406
- "¥",
407
- "¤",
408
- "֏",
409
- "؋",
410
- "৳",
411
- "฿",
412
- // '៛',
413
- "₡",
414
- "₦",
415
- "₩",
416
- "",
417
- "₫",
418
- "€",
419
- "₭",
420
- "₮",
421
- "₱",
422
- "₲",
423
- "₴",
424
- "₸",
425
- "",
426
- "",
427
- "",
428
- "₽",
429
- "",
430
- "₿"
431
- ];
504
+ const MORE_NUMFMT_TYPE_KEY = "sheet.numfmt.moreNumfmtType", OPTIONS_KEY = "sheet.numfmt.moreNumfmtType.options", MoreNumfmtType = /* @__PURE__ */ __name((props) => {
505
+ var _a8;
506
+ const localeService = useDependency(LocaleService), value = (_a8 = props.value) != null ? _a8 : localeService.t("sheet.numfmt.general");
507
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "more-numfmt-type", children: value });
508
+ }, "MoreNumfmtType"), Options = /* @__PURE__ */ __name(() => {
509
+ const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), injector = useInjector(), selectionManagerService = useDependency(SheetsSelectionsService), setNumfmt = /* @__PURE__ */ __name((pattern) => {
510
+ const selection = selectionManagerService.getCurrentLastSelection();
511
+ if (!selection)
512
+ return;
513
+ const textSelectionRenderManager = injector.get(ITextSelectionRenderManager), range = selection.range, values = [];
514
+ Range.foreach(range, (row, col) => {
515
+ pattern ? values.push({ row, col, pattern, type: getPatternType(pattern) }) : values.push({ row, col });
516
+ }), commandService.executeCommand(SetNumfmtCommand.id, { values }), textSelectionRenderManager.focus();
517
+ }, "setNumfmt"), handleOnclick = /* @__PURE__ */ __name((index) => {
518
+ if (index === 0)
519
+ setNumfmt(null);
520
+ else if (index === MENU_OPTIONS.length - 1)
521
+ commandService.executeCommand(OpenNumfmtPanelOperator.id);
522
+ else {
523
+ const item = MENU_OPTIONS[index];
524
+ item.pattern && setNumfmt(item.pattern);
525
+ }
526
+ }, "handleOnclick"), defaultValue = 1220;
527
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "more-numfmt-type-options", children: MENU_OPTIONS.map((item, index) => item === "|" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "line m-t-4", onClick: /* @__PURE__ */ __name((e) => e.stopPropagation(), "onClick") }, index) : /* @__PURE__ */ jsxRuntimeExports.jsxs(
528
+ "div",
529
+ {
530
+ className: "option-item m-t-4",
531
+ onClick: /* @__PURE__ */ __name(() => {
532
+ handleOnclick(index);
533
+ }, "onClick"),
534
+ children: [
535
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t(item.label) }),
536
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-l-26", children: item.pattern ? getPatternPreview(item.pattern || "", defaultValue, localeService.getCurrentLocale()).result : "" })
537
+ ]
538
+ },
539
+ index
540
+ )) });
541
+ }, "Options"), SetPercentCommand = {
542
+ id: "sheet.command.numfmt.set.percent",
543
+ type: CommandType.COMMAND,
544
+ handler: /* @__PURE__ */ __name(async (accessor) => {
545
+ const commandService = accessor.get(ICommandService), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
546
+ if (!selections || !selections.length)
547
+ return !1;
548
+ const values = [], suffix = "0%";
549
+ return selections.forEach((selection) => {
550
+ Range.foreach(selection.range, (row, col) => {
551
+ values.push({ row, col, pattern: suffix, type: "percent" });
552
+ });
553
+ }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
554
+ }, "handler")
555
+ }, CurrencyMenuItem = /* @__PURE__ */ __name((accessor) => ({
556
+ icon: new Observable((subscribe) => {
557
+ const numfmtMenuController = accessor.get(NumfmtMenuController);
558
+ function getIconKey(symbol2) {
559
+ return {
560
+ [countryCurrencyMap.US]: "DollarSingle",
561
+ [countryCurrencyMap.RU]: "RoubleSingle",
562
+ [countryCurrencyMap.CN]: "RmbSingle",
563
+ [countryCurrencyMap.AT]: "EuroSingle"
564
+ }[symbol2] || "DollarSingle";
565
+ }
566
+ __name(getIconKey, "getIconKey");
567
+ const symbol = countryCurrencyMap[numfmtMenuController.getCurrencySymbol()] || "$";
568
+ return subscribe.next(getIconKey(symbol)), numfmtMenuController.currencySymbol$.subscribe((code) => {
569
+ const symbol2 = countryCurrencyMap[code] || "$";
570
+ subscribe.next(getIconKey(symbol2));
571
+ });
572
+ }),
573
+ id: SetCurrencyCommand.id,
574
+ title: "sheet.numfmt.currency",
575
+ tooltip: "sheet.numfmt.currency",
576
+ type: MenuItemType.BUTTON,
577
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
578
+ positions: [MenuPosition.TOOLBAR_START],
579
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
580
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
581
+ }), "CurrencyMenuItem"), AddDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
582
+ icon: "AddDigitsSingle",
583
+ id: AddDecimalCommand.id,
584
+ title: "sheet.numfmt.addDecimal",
585
+ tooltip: "sheet.numfmt.addDecimal",
586
+ type: MenuItemType.BUTTON,
587
+ positions: [MenuPosition.TOOLBAR_START],
588
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
589
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
590
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
591
+ }), "AddDecimalMenuItem"), SubtractDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
592
+ icon: "ReduceDigitsSingle",
593
+ id: SubtractDecimalCommand.id,
594
+ title: "sheet.numfmt.subtractDecimal",
595
+ tooltip: "sheet.numfmt.subtractDecimal",
596
+ type: MenuItemType.BUTTON,
597
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
598
+ positions: [MenuPosition.TOOLBAR_START],
599
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
600
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
601
+ }), "SubtractDecimalMenuItem"), PercentMenuItem = /* @__PURE__ */ __name((accessor) => ({
602
+ icon: "PercentSingle",
603
+ id: SetPercentCommand.id,
604
+ title: "sheet.numfmt.percent",
605
+ tooltip: "sheet.numfmt.percent",
606
+ type: MenuItemType.BUTTON,
607
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
608
+ positions: [MenuPosition.TOOLBAR_START],
609
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
610
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
611
+ }), "PercentMenuItem"), FactoryOtherMenuItem = /* @__PURE__ */ __name((accessor) => {
612
+ const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), localeService = accessor.get(LocaleService), selectionManagerService = accessor.get(SheetsSelectionsService), value$ = deriveStateFromActiveSheet$(univerInstanceService, "", ({ workbook, worksheet }) => new Observable(
613
+ (subscribe) => merge(
614
+ selectionManagerService.selectionMoveEnd$,
615
+ new Observable((commandSubscribe) => {
616
+ const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id], disposable = commandService.onCommandExecuted((commandInfo) => {
617
+ commandList.includes(commandInfo.id) && commandSubscribe.next(null);
618
+ });
619
+ return () => disposable.dispose();
620
+ })
621
+ ).subscribe(() => {
622
+ var _a8, _b;
623
+ const selections = selectionManagerService.getCurrentSelections();
624
+ if (selections && selections[0]) {
625
+ const range = selections[0].range, row = range.startRow, col = range.startColumn, numfmtValue = (_b = workbook.getStyles().get((_a8 = worksheet.getCell(row, col)) == null ? void 0 : _a8.s)) == null ? void 0 : _b.n, pattern = numfmtValue == null ? void 0 : numfmtValue.pattern;
626
+ let value = localeService.t("sheet.numfmt.general");
627
+ if (pattern) {
628
+ const item = MENU_OPTIONS.filter((item2) => typeof item2 == "object" && item2.pattern).find(
629
+ (item2) => isPatternEqualWithoutDecimal(pattern, item2.pattern)
630
+ );
631
+ item && typeof item == "object" && item.pattern ? value = localeService.t(item.label) : value = localeService.t("sheet.numfmt.moreFmt");
632
+ }
633
+ subscribe.next(value);
634
+ }
635
+ })
636
+ ));
637
+ return {
638
+ label: MORE_NUMFMT_TYPE_KEY,
639
+ id: OpenNumfmtPanelOperator.id,
640
+ tooltip: "sheet.numfmt.title",
641
+ type: MenuItemType.SELECTOR,
642
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
643
+ positions: [MenuPosition.TOOLBAR_START],
644
+ selections: [
645
+ {
646
+ label: {
647
+ name: OPTIONS_KEY,
648
+ hoverable: !1
649
+ }
650
+ }
651
+ ],
652
+ value$,
653
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
654
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
655
+ };
656
+ }, "FactoryOtherMenuItem");
432
657
  var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
433
658
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
434
659
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
435
- return kind && result && __defProp$5(target, key2, result), result;
436
- }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$5"), _a2;
437
- let UserHabitController = (_a2 = class {
660
+ return kind && result && __defProp$5(target, key2, result), result;
661
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$5");
662
+ const DefaultSheetNumfmtConfig = {};
663
+ var _a2;
664
+ let NumfmtMenuController = (_a2 = class extends Disposable {
665
+ constructor(_config, _injector, _componentManager, _menuService) {
666
+ super();
667
+ __publicField(this, "_currencySymbol$", new BehaviorSubject("US"));
668
+ __publicField(this, "currencySymbol$", this._currencySymbol$.asObservable());
669
+ this._config = _config, this._injector = _injector, this._componentManager = _componentManager, this._menuService = _menuService, this._initMenu();
670
+ }
671
+ _initMenu() {
672
+ const { menu = {} } = this._config;
673
+ [PercentMenuItem, AddDecimalMenuItem, SubtractDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem].forEach((factory) => {
674
+ this.disposeWithMe(this._menuService.addMenuItem(factory(this._injector), menu));
675
+ }), this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY, MoreNumfmtType)), this.disposeWithMe(this._componentManager.register(OPTIONS_KEY, Options));
676
+ }
677
+ /**
678
+ * Set the currency symbol by setting the country code.
679
+ */
680
+ setCurrencySymbolByCountryCode(symbol) {
681
+ this._currencySymbol$.next(symbol);
682
+ }
683
+ getCurrencySymbol() {
684
+ return this._currencySymbol$.getValue();
685
+ }
686
+ }, __name(_a2, "NumfmtMenuController"), _a2);
687
+ NumfmtMenuController = __decorateClass$5([
688
+ OnLifecycle(LifecycleStages.Rendered, NumfmtMenuController),
689
+ __decorateParam$5(1, Inject(Injector)),
690
+ __decorateParam$5(2, Inject(ComponentManager)),
691
+ __decorateParam$5(3, Inject(IMenuService))
692
+ ], NumfmtMenuController);
693
+ const SetCurrencyCommand = {
694
+ id: "sheet.command.numfmt.set.currency",
695
+ type: CommandType.COMMAND,
696
+ handler: /* @__PURE__ */ __name(async (accessor) => {
697
+ const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtMenuController = accessor.get(NumfmtMenuController), symbol = countryCurrencyMap[numfmtMenuController.getCurrencySymbol()] || "$", selections = selectionManagerService.getCurrentSelections();
698
+ if (!selections || !selections.length)
699
+ return !1;
700
+ const values = [], suffix = CURRENCYFORMAT[0].suffix(symbol);
701
+ return selections.forEach((selection) => {
702
+ Range.foreach(selection.range, (row, col) => {
703
+ values.push({ row, col, pattern: suffix, type: "currency" });
704
+ });
705
+ }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
706
+ }, "handler")
707
+ }, CloseNumfmtPanelOperator = {
708
+ id: "sheet.operation.close.numfmt.panel",
709
+ type: CommandType.OPERATION,
710
+ handler: /* @__PURE__ */ __name(() => (
711
+ // do nothing,just notify panel is closed
712
+ !0
713
+ ), "handler")
714
+ }, UserHabitCurrencyContext = createContext([]);
715
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
716
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
717
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
718
+ return kind && result && __defProp$4(target, key2, result), result;
719
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$4"), _a3;
720
+ let UserHabitController = (_a3 = class {
438
721
  constructor(_localStorageService) {
439
722
  this._localStorageService = _localStorageService;
440
723
  }
@@ -477,9 +760,9 @@ let UserHabitController = (_a2 = class {
477
760
  deleteHabit(habit) {
478
761
  this._localStorageService.removeItem(habit);
479
762
  }
480
- }, __name(_a2, "UserHabitController"), _a2);
481
- UserHabitController = __decorateClass$5([
482
- __decorateParam$5(0, Inject(ILocalStorageService))
763
+ }, __name(_a3, "UserHabitController"), _a3);
764
+ UserHabitController = __decorateClass$4([
765
+ __decorateParam$4(0, Inject(ILocalStorageService))
483
766
  ], UserHabitController);
484
767
  const key$1 = "numfmtCurrency", useCurrencyOptions = /* @__PURE__ */ __name((onOptionChange) => {
485
768
  const userHabitController = useDependency(UserHabitController), [options, optionsSet] = useState(currencySymbols);
@@ -763,27 +1046,13 @@ const SheetNumfmtPanel = /* @__PURE__ */ __name((props) => {
763
1046
  /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "primary", size: "small", onClick: handleConfirm, children: t("sheet.numfmt.confirm") })
764
1047
  ] })
765
1048
  ] });
766
- }, "SheetNumfmtPanel"), SetPercentCommand = {
767
- id: "sheet.command.numfmt.set.percent",
768
- type: CommandType.COMMAND,
769
- handler: /* @__PURE__ */ __name(async (accessor) => {
770
- const commandService = accessor.get(ICommandService), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
771
- if (!selections || !selections.length)
772
- return !1;
773
- const values = [], suffix = "0%";
774
- return selections.forEach((selection) => {
775
- Range.foreach(selection.range, (row, col) => {
776
- values.push({ row, col, pattern: suffix, type: "percent" });
777
- });
778
- }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
779
- }, "handler")
780
- };
781
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
782
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1049
+ }, "SheetNumfmtPanel");
1050
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1051
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
783
1052
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
784
- return kind && result && __defProp$4(target, key2, result), result;
785
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$4"), _a3;
786
- let NumfmtController = (_a3 = class extends Disposable {
1053
+ return kind && result && __defProp$3(target, key2, result), result;
1054
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$3"), _a4;
1055
+ let NumfmtController = (_a4 = class extends Disposable {
787
1056
  constructor(_sheetInterceptorService, _themeService, _univerInstanceService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _sidebarService, _localeService) {
788
1057
  super();
789
1058
  /**
@@ -951,25 +1220,25 @@ let NumfmtController = (_a3 = class extends Disposable {
951
1220
  unit || ((_a8 = this._sidebarDisposable) == null || _a8.dispose(), this._sidebarDisposable = null);
952
1221
  });
953
1222
  }
954
- }, __name(_a3, "NumfmtController"), _a3);
955
- NumfmtController = __decorateClass$4([
1223
+ }, __name(_a4, "NumfmtController"), _a4);
1224
+ NumfmtController = __decorateClass$3([
956
1225
  OnLifecycle(LifecycleStages.Rendered, NumfmtController),
957
- __decorateParam$4(0, Inject(SheetInterceptorService)),
958
- __decorateParam$4(1, Inject(ThemeService)),
959
- __decorateParam$4(2, IUniverInstanceService),
960
- __decorateParam$4(3, ICommandService),
961
- __decorateParam$4(4, Inject(SheetsSelectionsService)),
962
- __decorateParam$4(5, IRenderManagerService),
963
- __decorateParam$4(6, INumfmtService),
964
- __decorateParam$4(7, Inject(ComponentManager)),
965
- __decorateParam$4(8, ISidebarService),
966
- __decorateParam$4(9, Inject(LocaleService))
1226
+ __decorateParam$3(0, Inject(SheetInterceptorService)),
1227
+ __decorateParam$3(1, Inject(ThemeService)),
1228
+ __decorateParam$3(2, IUniverInstanceService),
1229
+ __decorateParam$3(3, ICommandService),
1230
+ __decorateParam$3(4, Inject(SheetsSelectionsService)),
1231
+ __decorateParam$3(5, IRenderManagerService),
1232
+ __decorateParam$3(6, INumfmtService),
1233
+ __decorateParam$3(7, Inject(ComponentManager)),
1234
+ __decorateParam$3(8, ISidebarService),
1235
+ __decorateParam$3(9, Inject(LocaleService))
967
1236
  ], NumfmtController);
968
- var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
969
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1237
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1238
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
970
1239
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
971
- return kind && result && __defProp$3(target, key2, result), result;
972
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$3");
1240
+ return kind && result && __defProp$2(target, key2, result), result;
1241
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$2");
973
1242
  const createCollectEffectMutation = /* @__PURE__ */ __name(() => {
974
1243
  let list = [];
975
1244
  return {
@@ -980,8 +1249,8 @@ const createCollectEffectMutation = /* @__PURE__ */ __name(() => {
980
1249
  }, "clean")
981
1250
  };
982
1251
  }, "createCollectEffectMutation");
983
- var _a4;
984
- let NumfmtEditorController = (_a4 = class extends Disposable {
1252
+ var _a5;
1253
+ let NumfmtEditorController = (_a5 = class extends Disposable {
985
1254
  constructor(_sheetInterceptorService, _numfmtService, _univerInstanceService, _injector, _editorBridgeService) {
986
1255
  super();
987
1256
  // collect effect mutations when edit end and push this to commands stack in next commands progress
@@ -1142,234 +1411,33 @@ let NumfmtEditorController = (_a4 = class extends Disposable {
1142
1411
  })
1143
1412
  );
1144
1413
  }
1145
- }, __name(_a4, "NumfmtEditorController"), _a4);
1146
- NumfmtEditorController = __decorateClass$3([
1414
+ }, __name(_a5, "NumfmtEditorController"), _a5);
1415
+ NumfmtEditorController = __decorateClass$2([
1147
1416
  OnLifecycle(LifecycleStages.Rendered, NumfmtEditorController),
1148
- __decorateParam$3(0, Inject(SheetInterceptorService)),
1149
- __decorateParam$3(1, Inject(INumfmtService)),
1150
- __decorateParam$3(2, Inject(IUniverInstanceService)),
1151
- __decorateParam$3(3, Inject(Injector)),
1152
- __decorateParam$3(4, Optional(IEditorBridgeService))
1417
+ __decorateParam$2(0, Inject(SheetInterceptorService)),
1418
+ __decorateParam$2(1, Inject(INumfmtService)),
1419
+ __decorateParam$2(2, Inject(IUniverInstanceService)),
1420
+ __decorateParam$2(3, Inject(Injector)),
1421
+ __decorateParam$2(4, Optional(IEditorBridgeService))
1153
1422
  ], NumfmtEditorController);
1154
1423
  function isNumeric(str) {
1155
1424
  return /^-?\d+(\.\d+)?$/.test(str);
1156
1425
  }
1157
1426
  __name(isNumeric, "isNumeric");
1158
- var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1159
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1427
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1428
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1160
1429
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
1161
- return kind && result && __defProp$2(target, key2, result), result;
1162
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$2"), _a5;
1163
- let NumfmtI18nController = (_a5 = class extends Disposable {
1430
+ return kind && result && __defProp$1(target, key2, result), result;
1431
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$1"), _a6;
1432
+ let NumfmtI18nController = (_a6 = class extends Disposable {
1164
1433
  constructor(_localeService) {
1165
1434
  super(), this._localeService = _localeService;
1166
1435
  }
1167
- }, __name(_a5, "NumfmtI18nController"), _a5);
1168
- NumfmtI18nController = __decorateClass$2([
1436
+ }, __name(_a6, "NumfmtI18nController"), _a6);
1437
+ NumfmtI18nController = __decorateClass$1([
1169
1438
  OnLifecycle(LifecycleStages.Rendered, NumfmtI18nController),
1170
- __decorateParam$2(0, Inject(LocaleService))
1439
+ __decorateParam$1(0, Inject(LocaleService))
1171
1440
  ], NumfmtI18nController);
1172
- const MENU_OPTIONS = [
1173
- {
1174
- label: "sheet.numfmt.general",
1175
- pattern: null
1176
- },
1177
- {
1178
- label: "sheet.numfmt.text",
1179
- pattern: DEFAULT_TEXT_FORMAT
1180
- },
1181
- "|",
1182
- {
1183
- label: "sheet.numfmt.number",
1184
- pattern: "0"
1185
- },
1186
- "|",
1187
- {
1188
- label: "sheet.numfmt.accounting",
1189
- pattern: '"¥" #,##0.00_);[Red]("¥"#,##0.00)'
1190
- },
1191
- {
1192
- label: "sheet.numfmt.financialValue",
1193
- pattern: "#,##0.00;[Red]#,##0.00"
1194
- },
1195
- {
1196
- label: "sheet.numfmt.currency",
1197
- pattern: '"¥"#,##0.00_);[Red]("¥"#,##0.00)'
1198
- },
1199
- {
1200
- label: "sheet.numfmt.roundingCurrency",
1201
- pattern: '"¥"#,##0;[Red]"¥"#,##0'
1202
- },
1203
- "|",
1204
- {
1205
- label: "sheet.numfmt.date",
1206
- pattern: "yyyy-mm-dd;@"
1207
- },
1208
- {
1209
- label: "sheet.numfmt.time",
1210
- pattern: 'am/pm h":"mm":"ss'
1211
- },
1212
- {
1213
- label: "sheet.numfmt.dateTime",
1214
- pattern: "yyyy-m-d am/pm h:mm"
1215
- },
1216
- {
1217
- label: "sheet.numfmt.timeDuration",
1218
- pattern: "h:mm:ss"
1219
- },
1220
- "|",
1221
- {
1222
- label: "sheet.numfmt.moreFmt",
1223
- pattern: ""
1224
- }
1225
- ], MORE_NUMFMT_TYPE_KEY = "sheet.numfmt.moreNumfmtType", OPTIONS_KEY = "sheet.numfmt.moreNumfmtType.options", MoreNumfmtType = /* @__PURE__ */ __name((props) => {
1226
- var _a8;
1227
- const localeService = useDependency(LocaleService), value = (_a8 = props.value) != null ? _a8 : localeService.t("sheet.numfmt.general");
1228
- return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "more-numfmt-type", children: value });
1229
- }, "MoreNumfmtType"), Options = /* @__PURE__ */ __name(() => {
1230
- const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), injector = useInjector(), selectionManagerService = useDependency(SheetsSelectionsService), setNumfmt = /* @__PURE__ */ __name((pattern) => {
1231
- const selection = selectionManagerService.getCurrentLastSelection();
1232
- if (!selection)
1233
- return;
1234
- const textSelectionRenderManager = injector.get(ITextSelectionRenderManager), range = selection.range, values = [];
1235
- Range.foreach(range, (row, col) => {
1236
- pattern ? values.push({ row, col, pattern, type: getPatternType(pattern) }) : values.push({ row, col });
1237
- }), commandService.executeCommand(SetNumfmtCommand.id, { values }), textSelectionRenderManager.focus();
1238
- }, "setNumfmt"), handleOnclick = /* @__PURE__ */ __name((index) => {
1239
- if (index === 0)
1240
- setNumfmt(null);
1241
- else if (index === MENU_OPTIONS.length - 1)
1242
- commandService.executeCommand(OpenNumfmtPanelOperator.id);
1243
- else {
1244
- const item = MENU_OPTIONS[index];
1245
- item.pattern && setNumfmt(item.pattern);
1246
- }
1247
- }, "handleOnclick"), defaultValue = 1220;
1248
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "more-numfmt-type-options", children: MENU_OPTIONS.map((item, index) => item === "|" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "line m-t-4", onClick: /* @__PURE__ */ __name((e) => e.stopPropagation(), "onClick") }, index) : /* @__PURE__ */ jsxRuntimeExports.jsxs(
1249
- "div",
1250
- {
1251
- className: "option-item m-t-4",
1252
- onClick: /* @__PURE__ */ __name(() => {
1253
- handleOnclick(index);
1254
- }, "onClick"),
1255
- children: [
1256
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t(item.label) }),
1257
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-l-26", children: item.pattern ? getPatternPreview(item.pattern || "", defaultValue, localeService.getCurrentLocale()).result : "" })
1258
- ]
1259
- },
1260
- index
1261
- )) });
1262
- }, "Options"), CurrencyMenuItem = /* @__PURE__ */ __name((accessor) => ({
1263
- icon: "RmbSingle",
1264
- id: SetCurrencyCommand.id,
1265
- title: "sheet.numfmt.currency",
1266
- tooltip: "sheet.numfmt.currency",
1267
- type: MenuItemType.BUTTON,
1268
- group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1269
- positions: [MenuPosition.TOOLBAR_START],
1270
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1271
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1272
- }), "CurrencyMenuItem"), AddDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
1273
- icon: "AddDigitsSingle",
1274
- id: AddDecimalCommand.id,
1275
- title: "sheet.numfmt.addDecimal",
1276
- tooltip: "sheet.numfmt.addDecimal",
1277
- type: MenuItemType.BUTTON,
1278
- positions: [MenuPosition.TOOLBAR_START],
1279
- group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1280
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1281
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1282
- }), "AddDecimalMenuItem"), SubtractDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
1283
- icon: "ReduceDigitsSingle",
1284
- id: SubtractDecimalCommand.id,
1285
- title: "sheet.numfmt.subtractDecimal",
1286
- tooltip: "sheet.numfmt.subtractDecimal",
1287
- type: MenuItemType.BUTTON,
1288
- group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1289
- positions: [MenuPosition.TOOLBAR_START],
1290
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1291
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1292
- }), "SubtractDecimalMenuItem"), PercentMenuItem = /* @__PURE__ */ __name((accessor) => ({
1293
- icon: "PercentSingle",
1294
- id: SetPercentCommand.id,
1295
- title: "sheet.numfmt.percent",
1296
- tooltip: "sheet.numfmt.percent",
1297
- type: MenuItemType.BUTTON,
1298
- group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1299
- positions: [MenuPosition.TOOLBAR_START],
1300
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1301
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1302
- }), "PercentMenuItem"), FactoryOtherMenuItem = /* @__PURE__ */ __name((accessor) => {
1303
- accessor.get(INumfmtService);
1304
- const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), localeService = accessor.get(LocaleService), selectionManagerService = accessor.get(SheetsSelectionsService), value$ = deriveStateFromActiveSheet$(univerInstanceService, "", ({ workbook, worksheet }) => new Observable(
1305
- (subscribe) => merge(
1306
- selectionManagerService.selectionMoveEnd$,
1307
- new Observable((commandSubscribe) => {
1308
- const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id], disposable = commandService.onCommandExecuted((commandInfo) => {
1309
- commandList.includes(commandInfo.id) && commandSubscribe.next(null);
1310
- });
1311
- return () => disposable.dispose();
1312
- })
1313
- ).subscribe(() => {
1314
- var _a8, _b;
1315
- const selections = selectionManagerService.getCurrentSelections();
1316
- if (selections && selections[0]) {
1317
- const range = selections[0].range, row = range.startRow, col = range.startColumn, numfmtValue = (_b = workbook.getStyles().get((_a8 = worksheet.getCell(row, col)) == null ? void 0 : _a8.s)) == null ? void 0 : _b.n, pattern = numfmtValue == null ? void 0 : numfmtValue.pattern;
1318
- let value = localeService.t("sheet.numfmt.general");
1319
- if (pattern) {
1320
- const item = MENU_OPTIONS.filter((item2) => typeof item2 == "object" && item2.pattern).find(
1321
- (item2) => isPatternEqualWithoutDecimal(pattern, item2.pattern)
1322
- );
1323
- item && typeof item == "object" && item.pattern ? value = localeService.t(item.label) : value = localeService.t("sheet.numfmt.moreFmt");
1324
- }
1325
- subscribe.next(value);
1326
- }
1327
- })
1328
- ));
1329
- return {
1330
- label: MORE_NUMFMT_TYPE_KEY,
1331
- id: OpenNumfmtPanelOperator.id,
1332
- tooltip: "sheet.numfmt.title",
1333
- type: MenuItemType.SELECTOR,
1334
- group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1335
- positions: [MenuPosition.TOOLBAR_START],
1336
- selections: [
1337
- {
1338
- label: {
1339
- name: OPTIONS_KEY,
1340
- hoverable: !1
1341
- }
1342
- }
1343
- ],
1344
- value$,
1345
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1346
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1347
- };
1348
- }, "FactoryOtherMenuItem");
1349
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1350
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1351
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
1352
- return kind && result && __defProp$1(target, key2, result), result;
1353
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$1");
1354
- const DefaultSheetNumfmtConfig = {};
1355
- var _a6;
1356
- let NumfmtMenuController = (_a6 = class extends Disposable {
1357
- constructor(_config, _injector, _componentManager, _menuService) {
1358
- super(), this._config = _config, this._injector = _injector, this._componentManager = _componentManager, this._menuService = _menuService, this._initMenu();
1359
- }
1360
- _initMenu() {
1361
- const { menu = {} } = this._config;
1362
- [PercentMenuItem, AddDecimalMenuItem, SubtractDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem].forEach((factory) => {
1363
- this.disposeWithMe(this._menuService.addMenuItem(factory(this._injector), menu));
1364
- }), this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY, MoreNumfmtType)), this.disposeWithMe(this._componentManager.register(OPTIONS_KEY, Options));
1365
- }
1366
- }, __name(_a6, "NumfmtMenuController"), _a6);
1367
- NumfmtMenuController = __decorateClass$1([
1368
- OnLifecycle(LifecycleStages.Rendered, NumfmtMenuController),
1369
- __decorateParam$1(1, Inject(Injector)),
1370
- __decorateParam$1(2, Inject(ComponentManager)),
1371
- __decorateParam$1(3, Inject(IMenuService))
1372
- ], NumfmtMenuController);
1373
1441
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key2, value) => key2 in obj ? __defProp2(obj, key2, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key2] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1374
1442
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1375
1443
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
@@ -1399,11 +1467,13 @@ UniverSheetsNumfmtPlugin = __decorateClass([
1399
1467
  export {
1400
1468
  AddDecimalCommand,
1401
1469
  CloseNumfmtPanelOperator,
1470
+ NumfmtMenuController,
1402
1471
  OpenNumfmtPanelOperator,
1403
1472
  SetCurrencyCommand,
1404
1473
  SetNumfmtCommand,
1405
1474
  SetPercentCommand,
1406
1475
  SubtractDecimalCommand,
1407
1476
  UniverSheetsNumfmtPlugin,
1477
+ countryCurrencyMap,
1408
1478
  getPatternPreview
1409
1479
  };