@univerjs/sheets-numfmt 0.2.9 → 0.2.11
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 +2 -2
- package/lib/es/index.js +367 -340
- package/lib/index.css +1 -1
- package/lib/types/controllers/numfmt.menu.controller.d.ts +0 -6
- package/lib/types/numfmt-plugin.d.ts +0 -1
- package/lib/types/service/menu.currency.service.d.ts +10 -0
- package/lib/types/utils/decimal.d.ts +1 -1
- package/lib/types/utils/pattern.d.ts +3 -3
- package/lib/umd/index.js +2 -2
- package/package.json +19 -19
package/lib/es/index.js
CHANGED
|
@@ -2,16 +2,16 @@ 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 { numfmt, LocaleType, Disposable, ObjectMatrix, CellValueType, Range, UniverInstanceType, OnLifecycle, LifecycleStages, Inject, ThemeService, ICommandService, LocaleService, IUniverInstanceService, CommandType, IUndoRedoService, sequenceExecute, createIdentifier, runOnLifecycle,
|
|
6
|
-
import { INTERCEPTOR_POINT, InterceptCellContentPriority, SetNumfmtMutation, SetRangeValuesMutation, SheetInterceptorService, INumfmtService, getSheetCommandTarget, transformCellsToRange, rangeMerge, factorySetNumfmtUndoMutation, RemoveNumfmtMutation, factoryRemoveNumfmtUndoMutation, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, RangeProtectionPermissionEditPoint,
|
|
7
|
-
import { getCurrentRangeDisable$, deriveStateFromActiveSheet$,
|
|
8
|
-
import { switchMap, of, skip,
|
|
9
|
-
import {
|
|
10
|
-
import { MenuItemType, MenuGroup, MenuPosition, getMenuHiddenObservable,
|
|
5
|
+
import { numfmt, 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, InterceptCellContentPriority, 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, BehaviorSubject, Observable, combineLatest, merge } from "rxjs";
|
|
9
|
+
import { IRenderManagerService, ITextSelectionRenderManager } from "@univerjs/engine-render";
|
|
10
|
+
import { ComponentManager, ISidebarService, MenuItemType, MenuGroup, MenuPosition, getMenuHiddenObservable, IMenuService } from "@univerjs/ui";
|
|
11
11
|
import { map, switchMap as switchMap$1, tap, debounceTime } from "rxjs/operators";
|
|
12
|
-
import { DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
|
|
13
12
|
import require$$0, { createContext, useState, useEffect, useRef, useContext, useMemo, forwardRef, createElement } from "react";
|
|
14
13
|
import { InputNumber, Select, SelectList, Input, Button } from "@univerjs/design";
|
|
14
|
+
import { DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
|
|
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) => {
|
|
16
16
|
const info = numfmt.getInfo(pattern), locale = _locale === LocaleType.ZH_CN ? "zh-CN" : "en", negInfo = info._partitions[1], result = numfmt.format(pattern, value, { locale });
|
|
17
17
|
return value < 0 ? {
|
|
@@ -44,7 +44,7 @@ let SheetsNumfmtCellContentController = (_a = class extends Disposable {
|
|
|
44
44
|
if (numfmtValue || (numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col)), !numfmtValue)
|
|
45
45
|
return next(cell);
|
|
46
46
|
const originCellValue = cell;
|
|
47
|
-
if (!originCellValue || originCellValue.t !== CellValueType.NUMBER)
|
|
47
|
+
if (!originCellValue || originCellValue.t !== CellValueType.NUMBER || originCellValue.v == null || Number.isNaN(originCellValue.v))
|
|
48
48
|
return next(cell);
|
|
49
49
|
let numfmtRes = "";
|
|
50
50
|
const cache = renderCache.getValue(location.row, location.col);
|
|
@@ -180,8 +180,19 @@ const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0)
|
|
|
180
180
|
selections.forEach((selection) => {
|
|
181
181
|
Range.foreach(selection.range, (row, col) => {
|
|
182
182
|
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
183
|
-
if (!numfmtValue)
|
|
183
|
+
if (!numfmtValue) {
|
|
184
|
+
const cell = target.worksheet.getCellRaw(row, col);
|
|
185
|
+
if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
|
|
186
|
+
const regResult = /\.(\d*)$/.exec(String(cell.v));
|
|
187
|
+
if (regResult) {
|
|
188
|
+
const length = regResult[1].length;
|
|
189
|
+
if (!length)
|
|
190
|
+
return;
|
|
191
|
+
maxDecimals = Math.max(maxDecimals, length);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
184
194
|
return;
|
|
195
|
+
}
|
|
185
196
|
const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
|
|
186
197
|
maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
|
|
187
198
|
});
|
|
@@ -376,60 +387,38 @@ const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0)
|
|
|
376
387
|
SI: "€",
|
|
377
388
|
ES: "€"
|
|
378
389
|
// Add more mappings as needed
|
|
379
|
-
},
|
|
380
|
-
{
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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: ""
|
|
390
|
+
}, _MenuCurrencyService = class _MenuCurrencyService {
|
|
391
|
+
constructor() {
|
|
392
|
+
__publicField(this, "_currencySymbol$", new BehaviorSubject("US"));
|
|
393
|
+
__publicField(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Set the currency symbol by setting the country code.
|
|
397
|
+
*/
|
|
398
|
+
setCurrencySymbolByCountryCode(symbol) {
|
|
399
|
+
this._currencySymbol$.next(symbol);
|
|
400
|
+
}
|
|
401
|
+
getCurrencySymbol() {
|
|
402
|
+
return this._currencySymbol$.getValue();
|
|
431
403
|
}
|
|
432
|
-
|
|
404
|
+
};
|
|
405
|
+
__name(_MenuCurrencyService, "MenuCurrencyService");
|
|
406
|
+
let MenuCurrencyService = _MenuCurrencyService;
|
|
407
|
+
const SetCurrencyCommand = {
|
|
408
|
+
id: "sheet.command.numfmt.set.currency",
|
|
409
|
+
type: CommandType.COMMAND,
|
|
410
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
411
|
+
const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), menuCurrencyService = accessor.get(MenuCurrencyService), symbol = countryCurrencyMap[menuCurrencyService.getCurrencySymbol()] || "$", selections = selectionManagerService.getCurrentSelections();
|
|
412
|
+
if (!selections || !selections.length)
|
|
413
|
+
return !1;
|
|
414
|
+
const values = [], suffix = CURRENCYFORMAT[0].suffix(symbol);
|
|
415
|
+
return selections.forEach((selection) => {
|
|
416
|
+
Range.foreach(selection.range, (row, col) => {
|
|
417
|
+
values.push({ row, col, pattern: suffix, type: "currency" });
|
|
418
|
+
});
|
|
419
|
+
}), await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
420
|
+
}, "handler")
|
|
421
|
+
}, SubtractDecimalCommand = {
|
|
433
422
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
434
423
|
type: CommandType.COMMAND,
|
|
435
424
|
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
@@ -443,8 +432,19 @@ const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0)
|
|
|
443
432
|
selections.forEach((selection) => {
|
|
444
433
|
Range.foreach(selection.range, (row, col) => {
|
|
445
434
|
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
446
|
-
if (!numfmtValue)
|
|
435
|
+
if (!numfmtValue) {
|
|
436
|
+
const cell = target.worksheet.getCellRaw(row, col);
|
|
437
|
+
if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
|
|
438
|
+
const regResult = /\.(\d*)$/.exec(String(cell.v));
|
|
439
|
+
if (regResult) {
|
|
440
|
+
const length = regResult[1].length;
|
|
441
|
+
if (!length)
|
|
442
|
+
return;
|
|
443
|
+
maxDecimals = Math.max(maxDecimals, length);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
447
446
|
return;
|
|
447
|
+
}
|
|
448
448
|
const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
|
|
449
449
|
maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
|
|
450
450
|
});
|
|
@@ -470,6 +470,13 @@ const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0)
|
|
|
470
470
|
});
|
|
471
471
|
}), await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
472
472
|
}, "handler")
|
|
473
|
+
}, CloseNumfmtPanelOperator = {
|
|
474
|
+
id: "sheet.operation.close.numfmt.panel",
|
|
475
|
+
type: CommandType.OPERATION,
|
|
476
|
+
handler: /* @__PURE__ */ __name(() => (
|
|
477
|
+
// do nothing,just notify panel is closed
|
|
478
|
+
!0
|
|
479
|
+
), "handler")
|
|
473
480
|
}, INumfmtController = createIdentifier("INumfmtController");
|
|
474
481
|
runOnLifecycle(LifecycleStages.Rendered, INumfmtController);
|
|
475
482
|
const OpenNumfmtPanelOperator = {
|
|
@@ -493,231 +500,21 @@ function q(c, a, g) {
|
|
|
493
500
|
g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
|
|
494
501
|
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
495
502
|
if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
|
|
496
|
-
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
497
|
-
}
|
|
498
|
-
__name(q, "q");
|
|
499
|
-
reactJsxRuntime_production_min.Fragment = l;
|
|
500
|
-
reactJsxRuntime_production_min.jsx = q;
|
|
501
|
-
reactJsxRuntime_production_min.jsxs = q;
|
|
502
|
-
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
503
|
-
var jsxRuntimeExports = jsxRuntime.exports;
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
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");
|
|
657
|
-
var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
658
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
659
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
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--)
|
|
503
|
+
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
504
|
+
}
|
|
505
|
+
__name(q, "q");
|
|
506
|
+
reactJsxRuntime_production_min.Fragment = l;
|
|
507
|
+
reactJsxRuntime_production_min.jsx = q;
|
|
508
|
+
reactJsxRuntime_production_min.jsxs = q;
|
|
509
|
+
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
510
|
+
var jsxRuntimeExports = jsxRuntime.exports;
|
|
511
|
+
const UserHabitCurrencyContext = createContext([]);
|
|
512
|
+
var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
513
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
717
514
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
718
|
-
return kind && result && __defProp$
|
|
719
|
-
}, "__decorateClass$
|
|
720
|
-
let UserHabitController = (
|
|
515
|
+
return kind && result && __defProp$5(target, key2, result), result;
|
|
516
|
+
}, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$5"), _a2;
|
|
517
|
+
let UserHabitController = (_a2 = class {
|
|
721
518
|
constructor(_localStorageService) {
|
|
722
519
|
this._localStorageService = _localStorageService;
|
|
723
520
|
}
|
|
@@ -760,9 +557,9 @@ let UserHabitController = (_a3 = class {
|
|
|
760
557
|
deleteHabit(habit) {
|
|
761
558
|
this._localStorageService.removeItem(habit);
|
|
762
559
|
}
|
|
763
|
-
}, __name(
|
|
764
|
-
UserHabitController = __decorateClass$
|
|
765
|
-
__decorateParam$
|
|
560
|
+
}, __name(_a2, "UserHabitController"), _a2);
|
|
561
|
+
UserHabitController = __decorateClass$5([
|
|
562
|
+
__decorateParam$5(0, Inject(ILocalStorageService))
|
|
766
563
|
], UserHabitController);
|
|
767
564
|
const key$1 = "numfmtCurrency", useCurrencyOptions = /* @__PURE__ */ __name((onOptionChange) => {
|
|
768
565
|
const userHabitController = useDependency(UserHabitController), [options, optionsSet] = useState(currencySymbols);
|
|
@@ -1046,13 +843,27 @@ const SheetNumfmtPanel = /* @__PURE__ */ __name((props) => {
|
|
|
1046
843
|
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "primary", size: "small", onClick: handleConfirm, children: t("sheet.numfmt.confirm") })
|
|
1047
844
|
] })
|
|
1048
845
|
] });
|
|
1049
|
-
}, "SheetNumfmtPanel")
|
|
1050
|
-
|
|
1051
|
-
|
|
846
|
+
}, "SheetNumfmtPanel"), SetPercentCommand = {
|
|
847
|
+
id: "sheet.command.numfmt.set.percent",
|
|
848
|
+
type: CommandType.COMMAND,
|
|
849
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
850
|
+
const commandService = accessor.get(ICommandService), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
|
|
851
|
+
if (!selections || !selections.length)
|
|
852
|
+
return !1;
|
|
853
|
+
const values = [], suffix = "0%";
|
|
854
|
+
return selections.forEach((selection) => {
|
|
855
|
+
Range.foreach(selection.range, (row, col) => {
|
|
856
|
+
values.push({ row, col, pattern: suffix, type: "percent" });
|
|
857
|
+
});
|
|
858
|
+
}), await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
859
|
+
}, "handler")
|
|
860
|
+
};
|
|
861
|
+
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
862
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1052
863
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
1053
|
-
return kind && result && __defProp$
|
|
1054
|
-
}, "__decorateClass$
|
|
1055
|
-
let NumfmtController = (
|
|
864
|
+
return kind && result && __defProp$4(target, key2, result), result;
|
|
865
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$4"), _a3;
|
|
866
|
+
let NumfmtController = (_a3 = class extends Disposable {
|
|
1056
867
|
constructor(_sheetInterceptorService, _themeService, _univerInstanceService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _sidebarService, _localeService) {
|
|
1057
868
|
super();
|
|
1058
869
|
/**
|
|
@@ -1220,25 +1031,25 @@ let NumfmtController = (_a4 = class extends Disposable {
|
|
|
1220
1031
|
unit || ((_a8 = this._sidebarDisposable) == null || _a8.dispose(), this._sidebarDisposable = null);
|
|
1221
1032
|
});
|
|
1222
1033
|
}
|
|
1223
|
-
}, __name(
|
|
1224
|
-
NumfmtController = __decorateClass$
|
|
1034
|
+
}, __name(_a3, "NumfmtController"), _a3);
|
|
1035
|
+
NumfmtController = __decorateClass$4([
|
|
1225
1036
|
OnLifecycle(LifecycleStages.Rendered, NumfmtController),
|
|
1226
|
-
__decorateParam$
|
|
1227
|
-
__decorateParam$
|
|
1228
|
-
__decorateParam$
|
|
1229
|
-
__decorateParam$
|
|
1230
|
-
__decorateParam$
|
|
1231
|
-
__decorateParam$
|
|
1232
|
-
__decorateParam$
|
|
1233
|
-
__decorateParam$
|
|
1234
|
-
__decorateParam$
|
|
1235
|
-
__decorateParam$
|
|
1037
|
+
__decorateParam$4(0, Inject(SheetInterceptorService)),
|
|
1038
|
+
__decorateParam$4(1, Inject(ThemeService)),
|
|
1039
|
+
__decorateParam$4(2, IUniverInstanceService),
|
|
1040
|
+
__decorateParam$4(3, ICommandService),
|
|
1041
|
+
__decorateParam$4(4, Inject(SheetsSelectionsService)),
|
|
1042
|
+
__decorateParam$4(5, IRenderManagerService),
|
|
1043
|
+
__decorateParam$4(6, INumfmtService),
|
|
1044
|
+
__decorateParam$4(7, Inject(ComponentManager)),
|
|
1045
|
+
__decorateParam$4(8, ISidebarService),
|
|
1046
|
+
__decorateParam$4(9, Inject(LocaleService))
|
|
1236
1047
|
], NumfmtController);
|
|
1237
|
-
var __defProp$
|
|
1238
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
1048
|
+
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
1049
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1239
1050
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
1240
|
-
return kind && result && __defProp$
|
|
1241
|
-
}, "__decorateClass$
|
|
1051
|
+
return kind && result && __defProp$3(target, key2, result), result;
|
|
1052
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$3");
|
|
1242
1053
|
const createCollectEffectMutation = /* @__PURE__ */ __name(() => {
|
|
1243
1054
|
let list = [];
|
|
1244
1055
|
return {
|
|
@@ -1249,8 +1060,8 @@ const createCollectEffectMutation = /* @__PURE__ */ __name(() => {
|
|
|
1249
1060
|
}, "clean")
|
|
1250
1061
|
};
|
|
1251
1062
|
}, "createCollectEffectMutation");
|
|
1252
|
-
var
|
|
1253
|
-
let NumfmtEditorController = (
|
|
1063
|
+
var _a4;
|
|
1064
|
+
let NumfmtEditorController = (_a4 = class extends Disposable {
|
|
1254
1065
|
constructor(_sheetInterceptorService, _numfmtService, _univerInstanceService, _injector, _editorBridgeService) {
|
|
1255
1066
|
super();
|
|
1256
1067
|
// collect effect mutations when edit end and push this to commands stack in next commands progress
|
|
@@ -1273,11 +1084,11 @@ let NumfmtEditorController = (_a5 = class extends Disposable {
|
|
|
1273
1084
|
if (numfmtCell)
|
|
1274
1085
|
switch (getPatternType(numfmtCell.pattern)) {
|
|
1275
1086
|
case "scientific":
|
|
1276
|
-
case "percent":
|
|
1277
1087
|
case "currency":
|
|
1278
1088
|
case "grouped":
|
|
1279
1089
|
case "number":
|
|
1280
1090
|
return context.worksheet.getCellRaw(row, col);
|
|
1091
|
+
case "percent":
|
|
1281
1092
|
case "date":
|
|
1282
1093
|
case "time":
|
|
1283
1094
|
case "datetime":
|
|
@@ -1321,21 +1132,21 @@ let NumfmtEditorController = (_a5 = class extends Disposable {
|
|
|
1321
1132
|
}, "clean");
|
|
1322
1133
|
if (!(value != null && value.v))
|
|
1323
1134
|
return next(value);
|
|
1324
|
-
const content = String(value.v),
|
|
1325
|
-
if (
|
|
1326
|
-
if (
|
|
1327
|
-
const v = Number(
|
|
1135
|
+
const content = String(value.v), numfmtInfo = numfmt.parseDate(content) || numfmt.parseTime(content) || numfmt.parseNumber(content);
|
|
1136
|
+
if (numfmtInfo) {
|
|
1137
|
+
if (numfmtInfo.z) {
|
|
1138
|
+
const v = Number(numfmtInfo.v);
|
|
1328
1139
|
return this._collectEffectMutation.add(
|
|
1329
1140
|
context.unitId,
|
|
1330
1141
|
context.subUnitId,
|
|
1331
1142
|
context.row,
|
|
1332
1143
|
context.col,
|
|
1333
1144
|
{
|
|
1334
|
-
pattern:
|
|
1145
|
+
pattern: numfmtInfo.z
|
|
1335
1146
|
}
|
|
1336
1147
|
), { ...value, v, t: CellValueType.NUMBER };
|
|
1337
1148
|
}
|
|
1338
|
-
} else (["date", "time", "datetime"].includes(currentNumfmtType) || !isNumeric(content)) && clean();
|
|
1149
|
+
} else (["date", "time", "datetime", "percent"].includes(currentNumfmtType) || !isNumeric(content)) && clean();
|
|
1339
1150
|
return next(value);
|
|
1340
1151
|
}, "handler")
|
|
1341
1152
|
}
|
|
@@ -1411,33 +1222,252 @@ let NumfmtEditorController = (_a5 = class extends Disposable {
|
|
|
1411
1222
|
})
|
|
1412
1223
|
);
|
|
1413
1224
|
}
|
|
1414
|
-
}, __name(
|
|
1415
|
-
NumfmtEditorController = __decorateClass$
|
|
1225
|
+
}, __name(_a4, "NumfmtEditorController"), _a4);
|
|
1226
|
+
NumfmtEditorController = __decorateClass$3([
|
|
1416
1227
|
OnLifecycle(LifecycleStages.Rendered, NumfmtEditorController),
|
|
1417
|
-
__decorateParam$
|
|
1418
|
-
__decorateParam$
|
|
1419
|
-
__decorateParam$
|
|
1420
|
-
__decorateParam$
|
|
1421
|
-
__decorateParam$
|
|
1228
|
+
__decorateParam$3(0, Inject(SheetInterceptorService)),
|
|
1229
|
+
__decorateParam$3(1, Inject(INumfmtService)),
|
|
1230
|
+
__decorateParam$3(2, Inject(IUniverInstanceService)),
|
|
1231
|
+
__decorateParam$3(3, Inject(Injector)),
|
|
1232
|
+
__decorateParam$3(4, Optional(IEditorBridgeService))
|
|
1422
1233
|
], NumfmtEditorController);
|
|
1423
1234
|
function isNumeric(str) {
|
|
1424
1235
|
return /^-?\d+(\.\d+)?$/.test(str);
|
|
1425
1236
|
}
|
|
1426
1237
|
__name(isNumeric, "isNumeric");
|
|
1427
|
-
var __defProp$
|
|
1428
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
1238
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
1239
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1429
1240
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
1430
|
-
return kind && result && __defProp$
|
|
1431
|
-
}, "__decorateClass$
|
|
1432
|
-
let NumfmtI18nController = (
|
|
1241
|
+
return kind && result && __defProp$2(target, key2, result), result;
|
|
1242
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$2"), _a5;
|
|
1243
|
+
let NumfmtI18nController = (_a5 = class extends Disposable {
|
|
1433
1244
|
constructor(_localeService) {
|
|
1434
1245
|
super(), this._localeService = _localeService;
|
|
1435
1246
|
}
|
|
1436
|
-
}, __name(
|
|
1437
|
-
NumfmtI18nController = __decorateClass$
|
|
1247
|
+
}, __name(_a5, "NumfmtI18nController"), _a5);
|
|
1248
|
+
NumfmtI18nController = __decorateClass$2([
|
|
1438
1249
|
OnLifecycle(LifecycleStages.Rendered, NumfmtI18nController),
|
|
1439
|
-
__decorateParam$
|
|
1250
|
+
__decorateParam$2(0, Inject(LocaleService))
|
|
1440
1251
|
], NumfmtI18nController);
|
|
1252
|
+
const MENU_OPTIONS = [
|
|
1253
|
+
{
|
|
1254
|
+
label: "sheet.numfmt.general",
|
|
1255
|
+
pattern: null
|
|
1256
|
+
},
|
|
1257
|
+
{
|
|
1258
|
+
label: "sheet.numfmt.text",
|
|
1259
|
+
pattern: DEFAULT_TEXT_FORMAT
|
|
1260
|
+
},
|
|
1261
|
+
"|",
|
|
1262
|
+
{
|
|
1263
|
+
label: "sheet.numfmt.number",
|
|
1264
|
+
pattern: "0"
|
|
1265
|
+
},
|
|
1266
|
+
"|",
|
|
1267
|
+
{
|
|
1268
|
+
label: "sheet.numfmt.accounting",
|
|
1269
|
+
pattern: '"¥" #,##0.00_);[Red]("¥"#,##0.00)'
|
|
1270
|
+
},
|
|
1271
|
+
{
|
|
1272
|
+
label: "sheet.numfmt.financialValue",
|
|
1273
|
+
pattern: "#,##0.00;[Red]#,##0.00"
|
|
1274
|
+
},
|
|
1275
|
+
{
|
|
1276
|
+
label: "sheet.numfmt.currency",
|
|
1277
|
+
pattern: '"¥"#,##0.00_);[Red]("¥"#,##0.00)'
|
|
1278
|
+
},
|
|
1279
|
+
{
|
|
1280
|
+
label: "sheet.numfmt.roundingCurrency",
|
|
1281
|
+
pattern: '"¥"#,##0;[Red]"¥"#,##0'
|
|
1282
|
+
},
|
|
1283
|
+
"|",
|
|
1284
|
+
{
|
|
1285
|
+
label: "sheet.numfmt.date",
|
|
1286
|
+
pattern: "yyyy-mm-dd;@"
|
|
1287
|
+
},
|
|
1288
|
+
{
|
|
1289
|
+
label: "sheet.numfmt.time",
|
|
1290
|
+
pattern: 'am/pm h":"mm":"ss'
|
|
1291
|
+
},
|
|
1292
|
+
{
|
|
1293
|
+
label: "sheet.numfmt.dateTime",
|
|
1294
|
+
pattern: "yyyy-m-d am/pm h:mm"
|
|
1295
|
+
},
|
|
1296
|
+
{
|
|
1297
|
+
label: "sheet.numfmt.timeDuration",
|
|
1298
|
+
pattern: "h:mm:ss"
|
|
1299
|
+
},
|
|
1300
|
+
"|",
|
|
1301
|
+
{
|
|
1302
|
+
label: "sheet.numfmt.moreFmt",
|
|
1303
|
+
pattern: ""
|
|
1304
|
+
}
|
|
1305
|
+
], MORE_NUMFMT_TYPE_KEY = "sheet.numfmt.moreNumfmtType", OPTIONS_KEY = "sheet.numfmt.moreNumfmtType.options", MoreNumfmtType = /* @__PURE__ */ __name((props) => {
|
|
1306
|
+
var _a8;
|
|
1307
|
+
const localeService = useDependency(LocaleService), value = (_a8 = props.value) != null ? _a8 : localeService.t("sheet.numfmt.general");
|
|
1308
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "more-numfmt-type", children: value });
|
|
1309
|
+
}, "MoreNumfmtType"), Options = /* @__PURE__ */ __name(() => {
|
|
1310
|
+
const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), injector = useInjector(), selectionManagerService = useDependency(SheetsSelectionsService), setNumfmt = /* @__PURE__ */ __name((pattern) => {
|
|
1311
|
+
const selection = selectionManagerService.getCurrentLastSelection();
|
|
1312
|
+
if (!selection)
|
|
1313
|
+
return;
|
|
1314
|
+
const textSelectionRenderManager = injector.get(ITextSelectionRenderManager), range = selection.range, values = [];
|
|
1315
|
+
Range.foreach(range, (row, col) => {
|
|
1316
|
+
pattern ? values.push({ row, col, pattern, type: getPatternType(pattern) }) : values.push({ row, col });
|
|
1317
|
+
}), commandService.executeCommand(SetNumfmtCommand.id, { values }), textSelectionRenderManager.focus();
|
|
1318
|
+
}, "setNumfmt"), handleOnclick = /* @__PURE__ */ __name((index) => {
|
|
1319
|
+
if (index === 0)
|
|
1320
|
+
setNumfmt(null);
|
|
1321
|
+
else if (index === MENU_OPTIONS.length - 1)
|
|
1322
|
+
commandService.executeCommand(OpenNumfmtPanelOperator.id);
|
|
1323
|
+
else {
|
|
1324
|
+
const item = MENU_OPTIONS[index];
|
|
1325
|
+
item.pattern && setNumfmt(item.pattern);
|
|
1326
|
+
}
|
|
1327
|
+
}, "handleOnclick"), defaultValue = 1220;
|
|
1328
|
+
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(
|
|
1329
|
+
"div",
|
|
1330
|
+
{
|
|
1331
|
+
className: "option-item m-t-4",
|
|
1332
|
+
onClick: /* @__PURE__ */ __name(() => {
|
|
1333
|
+
handleOnclick(index);
|
|
1334
|
+
}, "onClick"),
|
|
1335
|
+
children: [
|
|
1336
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t(item.label) }),
|
|
1337
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-l-26", children: item.pattern ? getPatternPreview(item.pattern || "", defaultValue, localeService.getCurrentLocale()).result : "" })
|
|
1338
|
+
]
|
|
1339
|
+
},
|
|
1340
|
+
index
|
|
1341
|
+
)) });
|
|
1342
|
+
}, "Options"), CurrencyMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
1343
|
+
icon: new Observable((subscribe) => {
|
|
1344
|
+
const menuCurrencyService = accessor.get(MenuCurrencyService);
|
|
1345
|
+
function getIconKey(symbol2) {
|
|
1346
|
+
return {
|
|
1347
|
+
[countryCurrencyMap.US]: "DollarSingle",
|
|
1348
|
+
[countryCurrencyMap.RU]: "RoubleSingle",
|
|
1349
|
+
[countryCurrencyMap.CN]: "RmbSingle",
|
|
1350
|
+
[countryCurrencyMap.AT]: "EuroSingle"
|
|
1351
|
+
}[symbol2] || "DollarSingle";
|
|
1352
|
+
}
|
|
1353
|
+
__name(getIconKey, "getIconKey");
|
|
1354
|
+
const symbol = countryCurrencyMap[menuCurrencyService.getCurrencySymbol()] || "$";
|
|
1355
|
+
return subscribe.next(getIconKey(symbol)), menuCurrencyService.currencySymbol$.subscribe((code) => {
|
|
1356
|
+
const symbol2 = countryCurrencyMap[code] || "$";
|
|
1357
|
+
subscribe.next(getIconKey(symbol2));
|
|
1358
|
+
});
|
|
1359
|
+
}),
|
|
1360
|
+
id: SetCurrencyCommand.id,
|
|
1361
|
+
title: "sheet.numfmt.currency",
|
|
1362
|
+
tooltip: "sheet.numfmt.currency",
|
|
1363
|
+
type: MenuItemType.BUTTON,
|
|
1364
|
+
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
|
|
1365
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
1366
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1367
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
1368
|
+
}), "CurrencyMenuItem"), AddDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
1369
|
+
icon: "AddDigitsSingle",
|
|
1370
|
+
id: AddDecimalCommand.id,
|
|
1371
|
+
title: "sheet.numfmt.addDecimal",
|
|
1372
|
+
tooltip: "sheet.numfmt.addDecimal",
|
|
1373
|
+
type: MenuItemType.BUTTON,
|
|
1374
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
1375
|
+
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
|
|
1376
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1377
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
1378
|
+
}), "AddDecimalMenuItem"), SubtractDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
1379
|
+
icon: "ReduceDigitsSingle",
|
|
1380
|
+
id: SubtractDecimalCommand.id,
|
|
1381
|
+
title: "sheet.numfmt.subtractDecimal",
|
|
1382
|
+
tooltip: "sheet.numfmt.subtractDecimal",
|
|
1383
|
+
type: MenuItemType.BUTTON,
|
|
1384
|
+
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
|
|
1385
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
1386
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1387
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
1388
|
+
}), "SubtractDecimalMenuItem"), PercentMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
1389
|
+
icon: "PercentSingle",
|
|
1390
|
+
id: SetPercentCommand.id,
|
|
1391
|
+
title: "sheet.numfmt.percent",
|
|
1392
|
+
tooltip: "sheet.numfmt.percent",
|
|
1393
|
+
type: MenuItemType.BUTTON,
|
|
1394
|
+
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
|
|
1395
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
1396
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1397
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
1398
|
+
}), "PercentMenuItem"), FactoryOtherMenuItem = /* @__PURE__ */ __name((accessor) => {
|
|
1399
|
+
const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), localeService = accessor.get(LocaleService), selectionManagerService = accessor.get(SheetsSelectionsService), value$ = deriveStateFromActiveSheet$(univerInstanceService, "", ({ workbook, worksheet }) => new Observable(
|
|
1400
|
+
(subscribe) => merge(
|
|
1401
|
+
selectionManagerService.selectionMoveEnd$,
|
|
1402
|
+
new Observable((commandSubscribe) => {
|
|
1403
|
+
const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id], disposable = commandService.onCommandExecuted((commandInfo) => {
|
|
1404
|
+
commandList.includes(commandInfo.id) && commandSubscribe.next(null);
|
|
1405
|
+
});
|
|
1406
|
+
return () => disposable.dispose();
|
|
1407
|
+
})
|
|
1408
|
+
).subscribe(() => {
|
|
1409
|
+
var _a8, _b;
|
|
1410
|
+
const selections = selectionManagerService.getCurrentSelections();
|
|
1411
|
+
if (selections && selections[0]) {
|
|
1412
|
+
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;
|
|
1413
|
+
let value = localeService.t("sheet.numfmt.general");
|
|
1414
|
+
if (pattern) {
|
|
1415
|
+
const item = MENU_OPTIONS.filter((item2) => typeof item2 == "object" && item2.pattern).find(
|
|
1416
|
+
(item2) => isPatternEqualWithoutDecimal(pattern, item2.pattern)
|
|
1417
|
+
);
|
|
1418
|
+
item && typeof item == "object" && item.pattern ? value = localeService.t(item.label) : value = localeService.t("sheet.numfmt.moreFmt");
|
|
1419
|
+
}
|
|
1420
|
+
subscribe.next(value);
|
|
1421
|
+
}
|
|
1422
|
+
})
|
|
1423
|
+
));
|
|
1424
|
+
return {
|
|
1425
|
+
label: MORE_NUMFMT_TYPE_KEY,
|
|
1426
|
+
id: OpenNumfmtPanelOperator.id,
|
|
1427
|
+
tooltip: "sheet.numfmt.title",
|
|
1428
|
+
type: MenuItemType.SELECTOR,
|
|
1429
|
+
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
|
|
1430
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
1431
|
+
selections: [
|
|
1432
|
+
{
|
|
1433
|
+
label: {
|
|
1434
|
+
name: OPTIONS_KEY,
|
|
1435
|
+
hoverable: !1
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
],
|
|
1439
|
+
value$,
|
|
1440
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1441
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
1442
|
+
};
|
|
1443
|
+
}, "FactoryOtherMenuItem");
|
|
1444
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
1445
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1446
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
1447
|
+
return kind && result && __defProp$1(target, key2, result), result;
|
|
1448
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$1");
|
|
1449
|
+
const DefaultSheetNumfmtConfig = {};
|
|
1450
|
+
var _a6;
|
|
1451
|
+
let NumfmtMenuController = (_a6 = class extends Disposable {
|
|
1452
|
+
constructor(_config, _injector, _componentManager, _menuService) {
|
|
1453
|
+
super();
|
|
1454
|
+
__publicField(this, "_currencySymbol$", new BehaviorSubject("US"));
|
|
1455
|
+
__publicField(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
1456
|
+
this._config = _config, this._injector = _injector, this._componentManager = _componentManager, this._menuService = _menuService, this._initMenu();
|
|
1457
|
+
}
|
|
1458
|
+
_initMenu() {
|
|
1459
|
+
const { menu = {} } = this._config;
|
|
1460
|
+
[PercentMenuItem, AddDecimalMenuItem, SubtractDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem].forEach((factory) => {
|
|
1461
|
+
this.disposeWithMe(this._menuService.addMenuItem(factory(this._injector), menu));
|
|
1462
|
+
}), this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY, MoreNumfmtType)), this.disposeWithMe(this._componentManager.register(OPTIONS_KEY, Options));
|
|
1463
|
+
}
|
|
1464
|
+
}, __name(_a6, "NumfmtMenuController"), _a6);
|
|
1465
|
+
NumfmtMenuController = __decorateClass$1([
|
|
1466
|
+
OnLifecycle(LifecycleStages.Rendered, NumfmtMenuController),
|
|
1467
|
+
__decorateParam$1(1, Inject(Injector)),
|
|
1468
|
+
__decorateParam$1(2, Inject(ComponentManager)),
|
|
1469
|
+
__decorateParam$1(3, Inject(IMenuService))
|
|
1470
|
+
], NumfmtMenuController);
|
|
1441
1471
|
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) => {
|
|
1442
1472
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1443
1473
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
@@ -1445,10 +1475,7 @@ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnProperty
|
|
|
1445
1475
|
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key2, value) => __defNormalProp2(obj, typeof key2 != "symbol" ? key2 + "" : key2, value), "__publicField"), _a7;
|
|
1446
1476
|
let UniverSheetsNumfmtPlugin = (_a7 = class extends Plugin {
|
|
1447
1477
|
constructor(_config = {}, _injector) {
|
|
1448
|
-
super(), this._config = _config, this._injector = _injector, this._config = Tools.deepMerge({}, DefaultSheetNumfmtConfig, this._config)
|
|
1449
|
-
}
|
|
1450
|
-
onStarting() {
|
|
1451
|
-
this._injector.add([INumfmtController, { useClass: NumfmtController, lazy: !1 }]), this._injector.add([NumfmtEditorController]), this._injector.add([UserHabitController]), this._injector.add([SheetsNumfmtCellContentController]), this._injector.add([NumfmtI18nController]), this._injector.add(
|
|
1478
|
+
super(), this._config = _config, this._injector = _injector, this._config = Tools.deepMerge({}, DefaultSheetNumfmtConfig, this._config), this._injector.add([INumfmtController, { useClass: NumfmtController, lazy: !1 }]), this._injector.add([NumfmtEditorController]), this._injector.add([UserHabitController]), this._injector.add([SheetsNumfmtCellContentController]), this._injector.add([NumfmtI18nController]), this._injector.add([MenuCurrencyService]), this._injector.add(
|
|
1452
1479
|
[
|
|
1453
1480
|
NumfmtMenuController,
|
|
1454
1481
|
{
|