@univerjs/sheets-numfmt 0.4.1 → 0.4.2-nightly.202410301606

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 (51) hide show
  1. package/README.md +10 -10
  2. package/lib/es/facade.js +16 -0
  3. package/lib/es/index.js +228 -1203
  4. package/lib/set-numfmt.command-CzUTkdYu.mjs +52 -0
  5. package/lib/types/{controllers/__tests__/editor.controller.spec.d.ts → facade/f-range.d.ts} +12 -0
  6. package/lib/types/facade/index.d.ts +0 -0
  7. package/lib/types/index.d.ts +7 -1
  8. package/lib/types/numfmt-plugin.d.ts +3 -4
  9. package/lib/umd/facade.js +1 -0
  10. package/lib/umd/index.js +1 -9
  11. package/package.json +14 -28
  12. package/LICENSE +0 -176
  13. package/lib/cjs/index.js +0 -9
  14. package/lib/index.css +0 -1
  15. package/lib/locale/en-US.json +0 -38
  16. package/lib/locale/fa-IR.json +0 -38
  17. package/lib/locale/ru-RU.json +0 -38
  18. package/lib/locale/vi-VN.json +0 -38
  19. package/lib/locale/zh-CN.json +0 -38
  20. package/lib/locale/zh-TW.json +0 -38
  21. package/lib/types/base/const/MENU-OPTIONS.d.ts +0 -19
  22. package/lib/types/base/types/index.d.ts +0 -7
  23. package/lib/types/components/accounting/index.d.ts +0 -4
  24. package/lib/types/components/currency/index.d.ts +0 -4
  25. package/lib/types/components/custom-format/index.d.ts +0 -3
  26. package/lib/types/components/date/index.d.ts +0 -4
  27. package/lib/types/components/general/index.d.ts +0 -4
  28. package/lib/types/components/index.d.ts +0 -14
  29. package/lib/types/components/more-numfmt-type/MoreNumfmtType.d.ts +0 -7
  30. package/lib/types/components/stories/Panel.stories.d.ts +0 -5
  31. package/lib/types/components/thousandth-percentile/index.d.ts +0 -4
  32. package/lib/types/context/user-habit.d.ts +0 -16
  33. package/lib/types/controllers/__tests__/cell-content.controller.spec.d.ts +0 -16
  34. package/lib/types/controllers/__tests__/test.util.d.ts +0 -15
  35. package/lib/types/controllers/config.schema.d.ts +0 -7
  36. package/lib/types/controllers/menu.schema.d.ts +0 -2
  37. package/lib/types/controllers/numfmt.controller.d.ts +0 -33
  38. package/lib/types/controllers/numfmt.editor.controller.d.ts +0 -20
  39. package/lib/types/controllers/numfmt.menu.controller.d.ts +0 -8
  40. package/lib/types/controllers/user-habit.controller.d.ts +0 -18
  41. package/lib/types/hooks/useCurrencyOptions.d.ts +0 -19
  42. package/lib/types/hooks/useNextTick.d.ts +0 -16
  43. package/lib/types/locale/en-US.d.ts +0 -3
  44. package/lib/types/locale/fa-IR.d.ts +0 -3
  45. package/lib/types/locale/ru-RU.d.ts +0 -3
  46. package/lib/types/locale/vi-VN.d.ts +0 -3
  47. package/lib/types/locale/zh-CN.d.ts +0 -54
  48. package/lib/types/locale/zh-TW.d.ts +0 -3
  49. package/lib/types/menu/menu.d.ts +0 -40
  50. /package/lib/types/controllers/{numfmt.cell-content.controller.d.ts → numfmt-cell-content.controller.d.ts} +0 -0
  51. /package/lib/types/controllers/{numfmt.currency.controller.d.ts → numfmt-currency.controller.d.ts} +0 -0
package/lib/es/index.js CHANGED
@@ -1,17 +1,11 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key2] = value;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
- var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 != "symbol" ? key2 + "" : key2, value);
5
- import { numfmt, LocaleType, Inject, ThemeService, ICommandService, LocaleService, IUniverInstanceService, Disposable, ObjectMatrix, InterceptorEffectEnum, CellValueType, Range, UniverInstanceType, CommandType, IUndoRedoService, sequenceExecute, createIdentifier, ILocalStorageService, useDependency, toDisposable, DisposableCollection, Injector, Optional, useInjector, DependentOn, Plugin, IConfigService } from "@univerjs/core";
6
- import { SheetInterceptorService, INumfmtService, INTERCEPTOR_POINT, InterceptCellContentPriority, SetNumfmtMutation, SetRangeValuesMutation, 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 } from "@univerjs/engine-render";
10
- import { ComponentManager, ISidebarService, ILayoutService, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, IMenuManagerService } from "@univerjs/ui";
11
- import { map, switchMap as switchMap$1, tap, debounceTime } from "rxjs/operators";
12
- import require$$0, { createContext, useState, useEffect, useRef, useContext, useMemo, forwardRef, createElement } from "react";
13
- import { InputNumber, Select, SelectList, Input, Button } from "@univerjs/design";
14
- import { DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
+ import { numfmt, CommandType, ICommandService, IUniverInstanceService, Range, CellValueType, LocaleType, Inject, ThemeService, LocaleService, Disposable, ObjectMatrix, InterceptorEffectEnum, UniverInstanceType, createIdentifier, DependentOn, Injector, Plugin, registerDependencies, touchDependencies } from "@univerjs/core";
6
+ import { SheetsSelectionsService, INumfmtService, getSheetCommandTarget, SheetInterceptorService, INTERCEPTOR_POINT, InterceptCellContentPriority, SetNumfmtMutation, SetRangeValuesMutation, UniverSheetsPlugin } from "@univerjs/sheets";
7
+ import { S as SetNumfmtCommand } from "../set-numfmt.command-CzUTkdYu.mjs";
8
+ import { BehaviorSubject, switchMap, of, skip } from "rxjs";
15
9
  const currencySymbols = [
16
10
  "$",
17
11
  "£",
@@ -80,214 +74,6 @@ const currencySymbols = [
80
74
  SI: "€",
81
75
  ES: "€"
82
76
  // Add more mappings as needed
83
- }, SHEET_NUMFMT_PLUGIN = "SHEET_NUMFMT_PLUGIN", PLUGIN_CONFIG_KEY = "sheets-numfmt.config", defaultPluginConfig = {}, getPatternType = /* @__PURE__ */ __name((pattern) => numfmt.getInfo(pattern).type || "unknown", "getPatternType"), getPatternPreview = /* @__PURE__ */ __name((pattern, value, _locale) => {
84
- const info = numfmt.getInfo(pattern), locale = _locale === LocaleType.ZH_CN ? "zh-CN" : "en", negInfo = info._partitions[1], result = numfmt.format(pattern, value, { locale, throws: !1 });
85
- return value < 0 ? {
86
- result,
87
- color: negInfo.color
88
- } : {
89
- result
90
- };
91
- }, "getPatternPreview"), getPatternPreviewIgnoreGeneral = /* @__PURE__ */ __name((pattern, value, _locale) => pattern === "General" ? {
92
- result: String(value)
93
- } : getPatternPreview(pattern, value, _locale), "getPatternPreviewIgnoreGeneral");
94
- var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
95
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
96
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
97
- return kind && result && __defProp$5(target, key2, result), result;
98
- }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$5"), _a;
99
- let SheetsNumfmtCellContentController = (_a = class extends Disposable {
100
- constructor(_instanceService, _sheetInterceptorService, _themeService, _commandService, _numfmtService, _localeService) {
101
- super(), this._instanceService = _instanceService, this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._commandService = _commandService, this._numfmtService = _numfmtService, this._localeService = _localeService, this._initInterceptorCellContent();
102
- }
103
- // eslint-disable-next-line max-lines-per-function
104
- _initInterceptorCellContent() {
105
- const renderCache = new ObjectMatrix();
106
- this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
107
- effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
108
- handler: /* @__PURE__ */ __name((cell, location, next) => {
109
- const unitId = location.unitId, sheetId = location.subUnitId;
110
- let numfmtValue;
111
- const originCellValue = cell;
112
- if (!originCellValue || originCellValue.t !== CellValueType.NUMBER || originCellValue.v == null || Number.isNaN(originCellValue.v))
113
- return next(cell);
114
- if (cell != null && cell.s) {
115
- const style = location.workbook.getStyles().get(cell.s);
116
- style != null && style.n && (numfmtValue = style.n);
117
- }
118
- if (numfmtValue || (numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col)), !numfmtValue)
119
- return next(cell);
120
- let numfmtRes = "";
121
- const cache = renderCache.getValue(location.row, location.col);
122
- if (cache && cache.parameters === `${originCellValue.v}_${numfmtValue.pattern}`)
123
- return next({ ...cell, ...cache.result });
124
- const info = getPatternPreviewIgnoreGeneral(numfmtValue.pattern, Number(originCellValue.v), this._localeService.getCurrentLocale());
125
- if (numfmtRes = info.result, !numfmtRes)
126
- return next(cell);
127
- const res = { v: numfmtRes };
128
- if (info.color) {
129
- const color = this._themeService.getCurrentTheme()[`${info.color}500`];
130
- color && (res.interceptorStyle = { cl: { rgb: color } });
131
- }
132
- return renderCache.setValue(location.row, location.col, {
133
- result: res,
134
- parameters: `${originCellValue.v}_${numfmtValue.pattern}`
135
- }), next({ ...cell, ...res });
136
- }, "handler"),
137
- priority: InterceptCellContentPriority.NUMFMT
138
- })), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
139
- if (commandInfo.id === SetNumfmtMutation.id) {
140
- const params = commandInfo.params;
141
- Object.keys(params.values).forEach((key2) => {
142
- params.values[key2].ranges.forEach((range) => {
143
- Range.foreach(range, (row, col) => {
144
- renderCache.realDeleteValue(row, col);
145
- });
146
- });
147
- });
148
- } else if (commandInfo.id === SetRangeValuesMutation.id) {
149
- const params = commandInfo.params;
150
- new ObjectMatrix(params.cellValue).forValue((row, col) => {
151
- renderCache.realDeleteValue(row, col);
152
- });
153
- }
154
- })), this.disposeWithMe(
155
- this._instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(
156
- switchMap((workbook) => {
157
- var _a7;
158
- return (_a7 = workbook == null ? void 0 : workbook.activeSheet$) != null ? _a7 : of(null);
159
- }),
160
- skip(1)
161
- ).subscribe(() => renderCache.reset())
162
- );
163
- }
164
- }, __name(_a, "SheetsNumfmtCellContentController"), _a);
165
- SheetsNumfmtCellContentController = __decorateClass$5([
166
- __decorateParam$5(0, IUniverInstanceService),
167
- __decorateParam$5(1, Inject(SheetInterceptorService)),
168
- __decorateParam$5(2, Inject(ThemeService)),
169
- __decorateParam$5(3, Inject(ICommandService)),
170
- __decorateParam$5(4, Inject(INumfmtService)),
171
- __decorateParam$5(5, Inject(LocaleService))
172
- ], SheetsNumfmtCellContentController);
173
- const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0) => {
174
- var _a7;
175
- return pattern && (_a7 = numfmt.getInfo(pattern).maxDecimals) != null ? _a7 : defaultValue;
176
- }, "getDecimalFromPattern"), isPatternEqualWithoutDecimal = /* @__PURE__ */ __name((patternA, patternB) => {
177
- if (patternA && !patternB || !patternA && patternB)
178
- return !1;
179
- const getString = /* @__PURE__ */ __name((tokens) => tokens.reduce(
180
- (pre, cur) => {
181
- if (pre.isEnd)
182
- return pre;
183
- const str = cur.value || cur.num;
184
- return cur.type === "point" ? (pre.isEnd = !0, pre) : { ...pre, result: pre.result + str };
185
- },
186
- { isEnd: !1, result: "" }
187
- ).result, "getString"), partitionsA = numfmt.getInfo(patternA)._partitions, partitionsB = numfmt.getInfo(patternB)._partitions, A1 = getString(partitionsA[0].tokens), B1 = getString(partitionsB[0].tokens), A2 = getString(partitionsA[1].tokens), B2 = getString(partitionsB[1].tokens);
188
- return A1 === B1 && A2 === B2 && partitionsA[1].color === partitionsB[1].color;
189
- }, "isPatternEqualWithoutDecimal"), getDecimalString = /* @__PURE__ */ __name((length) => new Array(Math.min(Math.max(0, Number(length)), 30)).fill(0).join(""), "getDecimalString"), setPatternDecimal = /* @__PURE__ */ __name((patterns, decimalLength) => patterns.split(";").map((pattern) => /\.0?/.test(pattern) ? pattern.replace(
190
- /\.0*/g,
191
- `${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}`
192
- ) : /0([^0]?)|0$/.test(pattern) ? pattern.replace(
193
- /0([^0]+)|0$/,
194
- `0${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}$1`
195
- ) : pattern).join(";"), "setPatternDecimal"), isPatternHasDecimal = /* @__PURE__ */ __name((pattern) => /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern), "isPatternHasDecimal"), SetNumfmtCommand = {
196
- id: "sheet.command.numfmt.set.numfmt",
197
- type: CommandType.COMMAND,
198
- handler: /* @__PURE__ */ __name((accessor, params) => {
199
- if (!params)
200
- return !1;
201
- const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), undoRedoService = accessor.get(IUndoRedoService), target = getSheetCommandTarget(univerInstanceService, params);
202
- if (!target) return !1;
203
- const { unitId, subUnitId } = target, setCells = params.values.filter((value) => !!value.pattern), removeCells = params.values.filter((value) => !value.pattern), setRedos = transformCellsToRange(unitId, subUnitId, setCells), removeRedos = {
204
- unitId,
205
- subUnitId,
206
- ranges: removeCells.map((cell) => ({
207
- startColumn: cell.col,
208
- startRow: cell.row,
209
- endColumn: cell.col,
210
- endRow: cell.row
211
- }))
212
- }, redos = [], undos = [];
213
- if (setCells.length) {
214
- Object.keys(setRedos.values).forEach((key2) => {
215
- const v = setRedos.values[key2];
216
- v.ranges = rangeMerge(v.ranges);
217
- }), redos.push({
218
- id: SetNumfmtMutation.id,
219
- params: setRedos
220
- });
221
- const undo = factorySetNumfmtUndoMutation(accessor, setRedos);
222
- undos.push(...undo);
223
- }
224
- if (removeCells.length) {
225
- removeRedos.ranges = rangeMerge(removeRedos.ranges), redos.push({
226
- id: RemoveNumfmtMutation.id,
227
- params: removeRedos
228
- });
229
- const undo = factoryRemoveNumfmtUndoMutation(accessor, removeRedos);
230
- undos.push(...undo);
231
- }
232
- const result = sequenceExecute(redos, commandService).result;
233
- return result && undoRedoService.pushUndoRedo({
234
- unitID: unitId,
235
- undoMutations: undos,
236
- redoMutations: redos
237
- }), result;
238
- }, "handler")
239
- }, AddDecimalCommand = {
240
- id: "sheet.command.numfmt.add.decimal.command",
241
- type: CommandType.COMMAND,
242
- handler: /* @__PURE__ */ __name(async (accessor) => {
243
- const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), selections = selectionManagerService.getCurrentSelections();
244
- if (!selections || !selections.length)
245
- return !1;
246
- const target = getSheetCommandTarget(univerInstanceService);
247
- if (!target) return !1;
248
- const { unitId, subUnitId } = target;
249
- let maxDecimals = 0;
250
- selections.forEach((selection) => {
251
- Range.foreach(selection.range, (row, col) => {
252
- const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
253
- if (!numfmtValue) {
254
- const cell = target.worksheet.getCellRaw(row, col);
255
- if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
256
- const regResult = /\.(\d*)$/.exec(String(cell.v));
257
- if (regResult) {
258
- const length = regResult[1].length;
259
- if (!length)
260
- return;
261
- maxDecimals = Math.max(maxDecimals, length);
262
- }
263
- }
264
- return;
265
- }
266
- const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
267
- maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
268
- });
269
- });
270
- const decimals = maxDecimals + 1, defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : ""}`, decimals), values = [];
271
- return selections.forEach((selection) => {
272
- Range.foreach(selection.range, (row, col) => {
273
- const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
274
- if (!numfmtValue)
275
- values.push({
276
- row,
277
- col,
278
- pattern: defaultPattern
279
- });
280
- else {
281
- const decimals2 = getDecimalFromPattern(numfmtValue.pattern), pattern = setPatternDecimal(numfmtValue.pattern, decimals2 + 1);
282
- pattern !== numfmtValue.pattern && values.push({
283
- row,
284
- col,
285
- pattern
286
- });
287
- }
288
- });
289
- }), values.length ? await commandService.executeCommand(SetNumfmtCommand.id, { values }) : !1;
290
- }, "handler")
291
77
  }, DATEFMTLISG = [
292
78
  {
293
79
  label: "1930-08-05",
@@ -389,7 +175,81 @@ const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0)
389
175
  suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`, "suffix"),
390
176
  color: "red"
391
177
  }
392
- ], _MenuCurrencyService = class _MenuCurrencyService {
178
+ ], SHEET_NUMFMT_PLUGIN = "SHEET_NUMFMT_PLUGIN", getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0) => {
179
+ var _a3;
180
+ return pattern && (_a3 = numfmt.getInfo(pattern).maxDecimals) != null ? _a3 : defaultValue;
181
+ }, "getDecimalFromPattern"), isPatternEqualWithoutDecimal = /* @__PURE__ */ __name((patternA, patternB) => {
182
+ if (patternA && !patternB || !patternA && patternB)
183
+ return !1;
184
+ const getString = /* @__PURE__ */ __name((tokens) => tokens.reduce(
185
+ (pre, cur) => {
186
+ if (pre.isEnd)
187
+ return pre;
188
+ const str = cur.value || cur.num;
189
+ return cur.type === "point" ? (pre.isEnd = !0, pre) : { ...pre, result: pre.result + str };
190
+ },
191
+ { isEnd: !1, result: "" }
192
+ ).result, "getString"), partitionsA = numfmt.getInfo(patternA)._partitions, partitionsB = numfmt.getInfo(patternB)._partitions, A1 = getString(partitionsA[0].tokens), B1 = getString(partitionsB[0].tokens), A2 = getString(partitionsA[1].tokens), B2 = getString(partitionsB[1].tokens);
193
+ return A1 === B1 && A2 === B2 && partitionsA[1].color === partitionsB[1].color;
194
+ }, "isPatternEqualWithoutDecimal"), getDecimalString = /* @__PURE__ */ __name((length) => new Array(Math.min(Math.max(0, Number(length)), 30)).fill(0).join(""), "getDecimalString"), setPatternDecimal = /* @__PURE__ */ __name((patterns, decimalLength) => patterns.split(";").map((pattern) => /\.0?/.test(pattern) ? pattern.replace(
195
+ /\.0*/g,
196
+ `${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}`
197
+ ) : /0([^0]?)|0$/.test(pattern) ? pattern.replace(
198
+ /0([^0]+)|0$/,
199
+ `0${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}$1`
200
+ ) : pattern).join(";"), "setPatternDecimal"), isPatternHasDecimal = /* @__PURE__ */ __name((pattern) => /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern), "isPatternHasDecimal"), AddDecimalCommand = {
201
+ id: "sheet.command.numfmt.add.decimal.command",
202
+ type: CommandType.COMMAND,
203
+ handler: /* @__PURE__ */ __name(async (accessor) => {
204
+ const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), selections = selectionManagerService.getCurrentSelections();
205
+ if (!selections || !selections.length)
206
+ return !1;
207
+ const target = getSheetCommandTarget(univerInstanceService);
208
+ if (!target) return !1;
209
+ const { unitId, subUnitId } = target;
210
+ let maxDecimals = 0;
211
+ selections.forEach((selection) => {
212
+ Range.foreach(selection.range, (row, col) => {
213
+ const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
214
+ if (!numfmtValue) {
215
+ const cell = target.worksheet.getCellRaw(row, col);
216
+ if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
217
+ const regResult = /\.(\d*)$/.exec(String(cell.v));
218
+ if (regResult) {
219
+ const length = regResult[1].length;
220
+ if (!length)
221
+ return;
222
+ maxDecimals = Math.max(maxDecimals, length);
223
+ }
224
+ }
225
+ return;
226
+ }
227
+ const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
228
+ maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
229
+ });
230
+ });
231
+ const decimals = maxDecimals + 1, defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : ""}`, decimals), values = [];
232
+ return selections.forEach((selection) => {
233
+ Range.foreach(selection.range, (row, col) => {
234
+ const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
235
+ if (!numfmtValue)
236
+ values.push({
237
+ row,
238
+ col,
239
+ pattern: defaultPattern
240
+ });
241
+ else {
242
+ const decimals2 = getDecimalFromPattern(numfmtValue.pattern), pattern = setPatternDecimal(numfmtValue.pattern, decimals2 + 1);
243
+ pattern !== numfmtValue.pattern && values.push({
244
+ row,
245
+ col,
246
+ pattern
247
+ });
248
+ }
249
+ });
250
+ }), values.length ? await commandService.executeCommand(SetNumfmtCommand.id, { values }) : !1;
251
+ }, "handler")
252
+ }, _MenuCurrencyService = class _MenuCurrencyService {
393
253
  constructor() {
394
254
  __publicField(this, "_currencySymbol$", new BehaviorSubject("US"));
395
255
  __publicField(this, "currencySymbol$", this._currencySymbol$.asObservable());
@@ -486,565 +346,96 @@ const SetCurrencyCommand = {
486
346
  });
487
347
  }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
488
348
  }, "handler")
489
- }, CloseNumfmtPanelOperator = {
490
- id: "sheet.operation.close.numfmt.panel",
491
- type: CommandType.OPERATION,
492
- handler: /* @__PURE__ */ __name(() => (
493
- // do nothing,just notify panel is closed
494
- !0
495
- ), "handler")
496
- }, INumfmtController = createIdentifier("INumfmtController"), OpenNumfmtPanelOperator = {
497
- id: "sheet.operation.open.numfmt.panel",
498
- type: CommandType.OPERATION,
499
- handler: /* @__PURE__ */ __name((accessor) => (accessor.get(INumfmtController).openPanel(), !0), "handler")
500
- };
501
- var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
502
- /**
503
- * @license React
504
- * react-jsx-runtime.production.min.js
505
- *
506
- * Copyright (c) Facebook, Inc. and its affiliates.
507
- *
508
- * This source code is licensed under the MIT license found in the
509
- * LICENSE file in the root directory of this source tree.
510
- */
511
- var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
512
- function q(c, a, g) {
513
- var b, d = {}, e = null, h = null;
514
- g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
515
- for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
516
- if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
517
- return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
518
- }
519
- __name(q, "q");
520
- reactJsxRuntime_production_min.Fragment = l;
521
- reactJsxRuntime_production_min.jsx = q;
522
- reactJsxRuntime_production_min.jsxs = q;
523
- jsxRuntime.exports = reactJsxRuntime_production_min;
524
- var jsxRuntimeExports = jsxRuntime.exports;
525
- const UserHabitCurrencyContext = createContext([]);
526
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
527
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
528
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
529
- return kind && result && __defProp$4(target, key2, result), result;
530
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$4"), _a2;
531
- let UserHabitController = (_a2 = class {
532
- constructor(_localStorageService) {
533
- this._localStorageService = _localStorageService;
534
- }
535
- _getKey(habit) {
536
- return `userHabitController_${habit}`;
537
- }
538
- async addHabit(habit, initValue) {
539
- const key2 = this._getKey(habit);
540
- return this._localStorageService.getItem(key2).then((item) => {
541
- item || this._localStorageService.setItem(key2, initValue);
542
- });
543
- }
544
- markHabit(habit, value) {
545
- const key2 = this._getKey(habit);
546
- this._localStorageService.getItem(key2).then((list) => {
547
- if (list) {
548
- const index = list.findIndex((item) => item === value);
549
- index > -1 && list.splice(index, 1), list.unshift(value), this._localStorageService.setItem(key2, list);
550
- }
551
- });
552
- }
553
- async getHabit(habit, sortList) {
554
- const key2 = this._getKey(habit), result = await this._localStorageService.getItem(key2);
555
- if (sortList && result) {
556
- const priority = result.map((item, index, arr) => {
557
- const length = arr.length;
558
- return {
559
- value: item,
560
- priority: length - index
561
- };
562
- });
563
- return sortList.sort((a, b) => {
564
- var _a7, _b;
565
- const ap = ((_a7 = priority.find((item) => item.value === a)) == null ? void 0 : _a7.priority) || -1;
566
- return (((_b = priority.find((item) => item.value === b)) == null ? void 0 : _b.priority) || -1) - ap;
567
- });
568
- }
569
- return result || [];
570
- }
571
- deleteHabit(habit) {
572
- this._localStorageService.removeItem(habit);
573
- }
574
- }, __name(_a2, "UserHabitController"), _a2);
575
- UserHabitController = __decorateClass$4([
576
- __decorateParam$4(0, Inject(ILocalStorageService))
577
- ], UserHabitController);
578
- const key$1 = "numfmtCurrency", useCurrencyOptions = /* @__PURE__ */ __name((onOptionChange) => {
579
- const userHabitController = useDependency(UserHabitController), [options, optionsSet] = useState(currencySymbols);
580
- return useEffect(() => {
581
- userHabitController.addHabit("numfmtCurrency", []).then(() => {
582
- userHabitController.getHabit(key$1, [...currencySymbols]).then((list) => {
583
- optionsSet(list), onOptionChange && onOptionChange(list);
584
- });
585
- });
586
- }, []), { userHabitCurrency: options, mark: /* @__PURE__ */ __name((v) => {
587
- userHabitController.markHabit(key$1, v);
588
- }, "mark") };
589
- }, "useCurrencyOptions"), useNextTick = /* @__PURE__ */ __name(() => {
590
- const effectList = useRef([]), [value, dispatch] = useState({});
591
- return useEffect(() => {
592
- effectList.current.forEach((fn) => {
593
- fn();
594
- }), effectList.current = [];
595
- }, [value]), /* @__PURE__ */ __name((fn) => {
596
- effectList.current.push(fn), dispatch({});
597
- }, "nextTick");
598
- }, "useNextTick"), getCurrencyType = /* @__PURE__ */ __name((pattern) => currencySymbols.find((code) => pattern.includes(code)), "getCurrencyType"), isAccountingPanel = /* @__PURE__ */ __name((pattern) => !!getCurrencyType(pattern) && pattern.startsWith("_("), "isAccountingPanel"), AccountingPanel = /* @__PURE__ */ __name((props) => {
599
- const [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 2)), userHabitCurrency = useContext(UserHabitCurrencyContext), [suffix, suffixSet] = useState(() => getCurrencyType(props.defaultPattern) || userHabitCurrency[0]), options = useMemo(() => userHabitCurrency.map((key2) => ({ label: key2, value: key2 })), []), t = useDependency(LocaleService).t;
600
- props.action.current = () => setPatternDecimal(`_("${suffix}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal);
601
- const onSelect = /* @__PURE__ */ __name((v) => {
602
- suffixSet(v), props.onChange(setPatternDecimal(`_("${v}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal));
603
- }, "onSelect"), onDecimalChange = /* @__PURE__ */ __name((v) => {
604
- const decimal2 = v || 0;
605
- decimalSet(decimal2), props.onChange(setPatternDecimal(`_("${suffix}"* #,##0${decimal2 > 0 ? ".0" : ""}_)`, decimal2));
606
- }, "onDecimalChange");
607
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
608
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 options ", children: [
609
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
610
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.decimalLength") }),
611
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ jsxRuntimeExports.jsx(InputNumber, { value: decimal, max: 20, min: 0, onChange: onDecimalChange }) })
612
- ] }),
613
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
614
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.currencyType") }),
615
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: onSelect, options, value: suffix }) })
616
- ] })
617
- ] }),
618
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.accountingDes") })
619
- ] });
620
- }, "AccountingPanel"), getCurrencyFormatOptions = /* @__PURE__ */ __name((suffix) => CURRENCYFORMAT.map((item) => ({
621
- label: item.label(suffix),
622
- value: item.suffix(suffix),
623
- color: item.color
624
- })), "getCurrencyFormatOptions"), getDateFormatOptions = /* @__PURE__ */ __name(() => DATEFMTLISG.map((item) => ({ label: item.label, value: item.suffix })), "getDateFormatOptions"), getNumberFormatOptions = /* @__PURE__ */ __name(() => NUMBERFORMAT.map((item) => ({ label: item.label, value: item.suffix, color: item.color })), "getNumberFormatOptions"), isCurrencyPanel = /* @__PURE__ */ __name((pattern) => !!getCurrencyType(pattern) && !pattern.startsWith("_("), "isCurrencyPanel"), CurrencyPanel = /* @__PURE__ */ __name((props) => {
625
- const t = useDependency(LocaleService).t, userHabitCurrency = useContext(UserHabitCurrencyContext), [suffix, suffixSet] = useState(() => getCurrencyType(props.defaultPattern) || userHabitCurrency[0]), [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 2)), [pattern, patternSet] = useState(() => {
626
- var _a7;
627
- const negativeOptions2 = getCurrencyFormatOptions(suffix);
628
- return ((_a7 = negativeOptions2.find((item) => isPatternEqualWithoutDecimal(item.value, props.defaultPattern))) == null ? void 0 : _a7.value) || negativeOptions2[0].value;
629
- }), negativeOptions = useMemo(() => getCurrencyFormatOptions(suffix), [suffix]), options = useMemo(() => userHabitCurrency.map((key2) => ({ label: key2, value: key2 })), [userHabitCurrency]);
630
- props.action.current = () => setPatternDecimal(pattern, decimal);
631
- const onSelect = /* @__PURE__ */ __name((value) => {
632
- if (value === void 0)
633
- return;
634
- suffixSet(value);
635
- const pattern2 = getCurrencyFormatOptions(value)[0].value;
636
- patternSet(pattern2), props.onChange(setPatternDecimal(pattern2, decimal));
637
- }, "onSelect"), onChange = /* @__PURE__ */ __name((value) => {
638
- value !== void 0 && (patternSet(value), props.onChange(setPatternDecimal(value, decimal)));
639
- }, "onChange"), onDecimalChange = /* @__PURE__ */ __name((v) => {
640
- decimalSet(v || 0), props.onChange(setPatternDecimal(pattern, v || 0));
641
- }, "onDecimalChange");
642
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
643
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 options ", children: [
644
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
645
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.decimalLength") }),
646
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ jsxRuntimeExports.jsx(InputNumber, { value: decimal, max: 20, min: 0, onChange: onDecimalChange }) })
647
- ] }),
648
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
649
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.currencyType") }),
650
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: onSelect, options, value: suffix }) })
651
- ] })
652
- ] }),
653
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.negType") }),
654
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange, options: negativeOptions, value: pattern }) }),
655
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.currencyDes") })
656
- ] });
657
- }, "CurrencyPanel");
658
- var __assign = function() {
659
- return __assign = Object.assign || function(t) {
660
- for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
661
- s = arguments[i];
662
- for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && (t[p2] = s[p2]);
663
- }
664
- return t;
665
- }, __assign.apply(this, arguments);
666
- }, __rest = function(s, e) {
667
- var t = {};
668
- for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0 && (t[p2] = s[p2]);
669
- if (s != null && typeof Object.getOwnPropertySymbols == "function")
670
- for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++)
671
- e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i]) && (t[p2[i]] = s[p2[i]]);
672
- return t;
673
- }, IconBase = forwardRef(function(props, ref) {
674
- var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
675
- return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
676
- });
677
- function render(node, id, runtimeProps, rootProps, extend) {
678
- return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
679
- return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
680
- }));
681
- }
682
- __name(render, "render");
683
- function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
684
- var attrs = __assign({}, node.attrs);
685
- extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
686
- var defIds = runtimeProps.defIds;
687
- return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a7) {
688
- var key2 = _a7[0], value = _a7[1];
689
- typeof value == "string" && (attrs[key2] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
690
- })), attrs;
691
- }
692
- __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
693
- function replaceRuntimeIdsInDefs(node, runtimeProps) {
694
- var _a7, defIds = runtimeProps.defIds;
695
- return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a7 = node.children) === null || _a7 === void 0) && _a7.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
696
- return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
697
- }) }) : node;
698
- }
699
- __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
700
- function generateShortUuid() {
701
- return Math.random().toString(36).substring(2, 8);
702
- }
703
- __name(generateShortUuid, "generateShortUuid");
704
- IconBase.displayName = "UniverIcon";
705
- var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, CheckMarkSingle = forwardRef(function(props, ref) {
706
- return createElement(IconBase, Object.assign({}, props, {
707
- id: "check-mark-single",
708
- ref,
709
- icon: element
710
- }));
711
- });
712
- CheckMarkSingle.displayName = "CheckMarkSingle";
713
- const customFormatTitle = "univer-custom-format-title", customFormatInput = "univer-custom-format-input", customFormatHistoryList = "univer-custom-format-history-list", customFormatHistoryListItem = "univer-custom-format-history-list-item", customFormatHistoryListItemIconWrap = "univer-custom-format-history-list-item-icon-wrap", customFormatDes = "univer-custom-format-des", styles = {
714
- customFormatTitle,
715
- customFormatInput,
716
- customFormatHistoryList,
717
- customFormatHistoryListItem,
718
- customFormatHistoryListItemIconWrap,
719
- customFormatDes
720
- }, key = "customFormat", historyPatternKey = "numfmt_custom_pattern";
721
- function CustomFormat(props) {
722
- const { defaultPattern, action, onChange } = props, userHabitController = useDependency(UserHabitController), localStorageService = useDependency(ILocalStorageService), localeService = useDependency(LocaleService), [pattern, patternSet] = useState(defaultPattern);
723
- action.current = () => (userHabitController.markHabit(key, pattern), localStorageService.getItem(historyPatternKey).then((list = []) => {
724
- const _list = [.../* @__PURE__ */ new Set([pattern, ...list || []])].splice(0, 10).filter((e) => !!e);
725
- localStorageService.setItem(historyPatternKey, _list);
726
- }), pattern);
727
- const [options, optionsSet] = useState([]);
728
- useEffect(() => {
729
- localStorageService.getItem(historyPatternKey).then((historyList) => {
730
- const list = [
731
- ...CURRENCYFORMAT.map((item) => item.suffix("$")),
732
- ...DATEFMTLISG.map((item) => item.suffix),
733
- ...NUMBERFORMAT.map((item) => item.suffix)
734
- ];
735
- list.push(...historyList || []), userHabitController.addHabit(key, []).finally(() => {
736
- userHabitController.getHabit(key, list).then((list2) => {
737
- optionsSet([...new Set(list2)]);
738
- });
739
- });
740
- });
741
- }, []);
742
- const handleClick = /* @__PURE__ */ __name((p2) => {
743
- patternSet(p2), onChange(p2);
744
- }, "handleClick"), handleBlur = /* @__PURE__ */ __name(() => {
745
- onChange(pattern);
746
- }, "handleBlur");
747
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.customFormat, children: [
748
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatTitle, children: localeService.t("sheet.numfmt.customFormat") }),
749
- /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { placeholder: localeService.t("sheet.numfmt.customFormat"), onBlur: handleBlur, value: pattern, onChange: patternSet, className: styles.customFormatInput }),
750
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatHistoryList, children: options.map((p2) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { onClick: /* @__PURE__ */ __name(() => handleClick(p2), "onClick"), className: styles.customFormatHistoryListItem, children: [
751
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatHistoryListItemIconWrap, children: pattern === p2 && /* @__PURE__ */ jsxRuntimeExports.jsx(CheckMarkSingle, {}) }),
752
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: p2 })
753
- ] }, p2)) }),
754
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatDes, children: localeService.t("sheet.numfmt.customFormatDes") })
755
- ] });
756
- }
757
- __name(CustomFormat, "CustomFormat");
758
- const isDatePanel = /* @__PURE__ */ __name((pattern) => {
759
- const info = numfmt.getInfo(pattern);
760
- return getDateFormatOptions().map((item) => item.value).includes(pattern) || ["date", "datetime", "time"].includes(info.type);
761
- }, "isDatePanel"), DatePanel = /* @__PURE__ */ __name((props) => {
762
- const options = useMemo(getDateFormatOptions, []), t = useDependency(LocaleService).t, [suffix, suffixSet] = useState(() => {
763
- if (props.defaultPattern) {
764
- const item = options.find((item2) => item2.value === props.defaultPattern);
765
- if (item)
766
- return item.value;
767
- }
768
- return options[0].value;
769
- });
770
- props.action.current = () => suffix;
771
- const onChange = /* @__PURE__ */ __name((v) => {
772
- v !== void 0 && (suffixSet(v), props.onChange(v));
773
- }, "onChange");
774
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
775
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.dateType") }),
776
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { value: suffix, options, onChange }) }),
777
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.dateDes") })
778
- ] });
779
- }, "DatePanel"), isGeneralPanel = /* @__PURE__ */ __name((pattern) => !pattern, "isGeneralPanel"), GeneralPanel = /* @__PURE__ */ __name((props) => {
780
- const t = useDependency(LocaleService).t;
781
- return props.action.current = () => "", /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.generalDes") }) });
782
- }, "GeneralPanel"), isThousandthPercentilePanel = /* @__PURE__ */ __name((pattern) => getNumberFormatOptions().some((item) => isPatternEqualWithoutDecimal(item.value, pattern)), "isThousandthPercentilePanel"), ThousandthPercentilePanel = /* @__PURE__ */ __name((props) => {
783
- const localeService = useDependency(LocaleService), options = useMemo(getNumberFormatOptions, []), [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 0)), [suffix, suffixSet] = useState(() => {
784
- const item = options.find((item2) => isPatternEqualWithoutDecimal(item2.value, props.defaultPattern || ""));
785
- return (item == null ? void 0 : item.value) || options[0].value;
786
- }), pattern = useMemo(() => setPatternDecimal(suffix, Number(decimal || 0)), [suffix, decimal]), isInputDisable = useMemo(() => !isPatternHasDecimal(suffix), [suffix]), handleDecimalChange = /* @__PURE__ */ __name((decimal2) => {
787
- decimalSet(decimal2 || 0), props.onChange(setPatternDecimal(suffix, Number(decimal2 || 0)));
788
- }, "handleDecimalChange"), handleClick = /* @__PURE__ */ __name((v) => {
789
- v !== void 0 && (decimalSet(getDecimalFromPattern(v, 0)), suffixSet(v), props.onChange(v));
790
- }, "handleClick");
791
- return props.action.current = () => pattern, /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
792
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: localeService.t("sheet.numfmt.decimalLength") }),
793
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
794
- InputNumber,
795
- {
796
- disabled: isInputDisable,
797
- value: decimal,
798
- max: 20,
799
- min: 0,
800
- onChange: handleDecimalChange
801
- }
802
- ) }),
803
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 label", children: [
804
- " ",
805
- localeService.t("sheet.numfmt.negType")
806
- ] }),
807
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange: handleClick, options, value: suffix }) }),
808
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: localeService.t("sheet.numfmt.thousandthPercentileDes") })
809
- ] });
810
- }, "ThousandthPercentilePanel"), SheetNumfmtPanel = /* @__PURE__ */ __name((props) => {
811
- const { defaultValue, defaultPattern, row, col } = props.value, localeService = useDependency(LocaleService), getCurrentPattern = useRef(() => ""), t = localeService.t, nextTick = useNextTick(), typeOptions = useMemo(
812
- () => [
813
- { label: "sheet.numfmt.general", component: GeneralPanel },
814
- { label: "sheet.numfmt.accounting", component: AccountingPanel },
815
- { label: "sheet.numfmt.currency", component: CurrencyPanel },
816
- { label: "sheet.numfmt.date", component: DatePanel },
817
- { label: "sheet.numfmt.thousandthPercentile", component: ThousandthPercentilePanel },
818
- { label: "sheet.numfmt.customFormat", component: CustomFormat }
819
- ].map((item) => ({ ...item, label: t(item.label) })),
820
- []
821
- ), [type, typeSet] = useState(findDefaultType), [key2, keySet] = useState(() => `${row}_${col}`), { mark, userHabitCurrency } = useCurrencyOptions(() => keySet(`${row}_${col}_userCurrency'`)), BusinessComponent = useMemo(() => {
822
- var _a7;
823
- return (_a7 = typeOptions.find((item) => item.label === type)) == null ? void 0 : _a7.component;
824
- }, [type]);
825
- function findDefaultType() {
826
- return [isGeneralPanel, isAccountingPanel, isCurrencyPanel, isDatePanel, isThousandthPercentilePanel].reduce((pre, curFn, index) => pre || (curFn(defaultPattern) ? typeOptions[index].label : ""), "") || typeOptions[0].label;
827
- }
828
- __name(findDefaultType, "findDefaultType");
829
- const selectOptions = typeOptions.map((option) => ({
830
- label: option.label,
831
- value: option.label
832
- })), handleSelect = /* @__PURE__ */ __name((value) => {
833
- typeSet(value), nextTick(() => props.onChange({ type: "change", value: getCurrentPattern.current() || "" }));
834
- }, "handleSelect"), handleChange = /* @__PURE__ */ __name((v) => {
835
- props.onChange({ type: "change", value: v });
836
- }, "handleChange"), handleConfirm = /* @__PURE__ */ __name(() => {
837
- const pattern = getCurrentPattern.current() || "", currency = getCurrencyType(pattern);
838
- currency && mark(currency), props.onChange({ type: "confirm", value: pattern });
839
- }, "handleConfirm"), handleCancel = /* @__PURE__ */ __name(() => {
840
- props.onChange({ type: "cancel", value: "" });
841
- }, "handleCancel"), subProps = {
842
- onChange: handleChange,
843
- defaultValue,
844
- defaultPattern,
845
- action: getCurrentPattern
349
+ }, getPatternType = /* @__PURE__ */ __name((pattern) => numfmt.getInfo(pattern).type || "unknown", "getPatternType"), getPatternPreview = /* @__PURE__ */ __name((pattern, value, _locale) => {
350
+ const info = numfmt.getInfo(pattern), locale = _locale === LocaleType.ZH_CN ? "zh-CN" : "en", negInfo = info._partitions[1], result = numfmt.format(pattern, value, { locale, throws: !1 });
351
+ return value < 0 ? {
352
+ result,
353
+ color: negInfo.color
354
+ } : {
355
+ result
846
356
  };
847
- return useEffect(() => {
848
- typeSet(findDefaultType()), keySet(`${row}_${col}`);
849
- }, [row, col]), /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "numfmt-panel p-b-20", children: [
850
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
851
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label m-t-14", children: t("sheet.numfmt.numfmtType") }),
852
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: handleSelect, options: selectOptions, value: type, style: { width: "100%" } }) }),
853
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: BusinessComponent && /* @__PURE__ */ jsxRuntimeExports.jsx(UserHabitCurrencyContext.Provider, { value: userHabitCurrency, children: /* @__PURE__ */ createElement(BusinessComponent, { ...subProps, key: key2 }) }) })
854
- ] }),
855
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "btn-list m-t-14 m-b-20", children: [
856
- /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "small", onClick: handleCancel, className: "m-r-12", children: t("sheet.numfmt.cancel") }),
857
- /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "primary", size: "small", onClick: handleConfirm, children: t("sheet.numfmt.confirm") })
858
- ] })
859
- ] });
860
- }, "SheetNumfmtPanel");
861
- var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
862
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
863
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
864
- return kind && result && __defProp$3(target, key2, result), result;
865
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$3"), _a3;
866
- let NumfmtController = (_a3 = class extends Disposable {
867
- constructor(_sheetInterceptorService, _themeService, _univerInstanceService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _sidebarService, _localeService) {
868
- super();
869
- /**
870
- * If _previewPattern is null ,the realTimeRenderingInterceptor will skip and if it is '',realTimeRenderingInterceptor will clear numfmt.
871
- * @private
872
- * @type {(string | null)}
873
- * @memberof NumfmtController
874
- */
875
- __publicField(this, "_previewPattern", "");
876
- __publicField(this, "_sidebarDisposable", null);
877
- this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._selectionManagerService = _selectionManagerService, this._renderManagerService = _renderManagerService, this._numfmtService = _numfmtService, this._componentManager = _componentManager, this._sidebarService = _sidebarService, this._localeService = _localeService, this._initRealTimeRenderingInterceptor(), this._initPanel(), this._initCommands(), this._initCloseListener(), this._commandExecutedListener();
357
+ }, "getPatternPreview"), getPatternPreviewIgnoreGeneral = /* @__PURE__ */ __name((pattern, value, _locale) => pattern === "General" ? {
358
+ result: String(value)
359
+ } : getPatternPreview(pattern, value, _locale), "getPatternPreviewIgnoreGeneral");
360
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
361
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
362
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
363
+ return kind && result && __defProp$1(target, key, result), result;
364
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a;
365
+ let SheetsNumfmtCellContentController = (_a = class extends Disposable {
366
+ constructor(_instanceService, _sheetInterceptorService, _themeService, _commandService, _numfmtService, _localeService) {
367
+ super(), this._instanceService = _instanceService, this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._commandService = _commandService, this._numfmtService = _numfmtService, this._localeService = _localeService, this._initInterceptorCellContent();
878
368
  }
879
- openPanel() {
880
- var _a7;
881
- const sidebarService = this._sidebarService, selectionManagerService = this._selectionManagerService, commandService = this._commandService, univerInstanceService = this._univerInstanceService, numfmtService = this._numfmtService, localeService = this._localeService, range = (((_a7 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a7.map((s) => s.range)) || [])[0];
882
- if (!range)
883
- return !1;
884
- const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), sheet = workbook.getActiveSheet();
885
- if (!sheet)
886
- return !1;
887
- const cellValue = sheet.getCellRaw(range.startRow, range.startColumn), numfmtValue = numfmtService.getValue(
888
- workbook.getUnitId(),
889
- sheet.getSheetId(),
890
- range.startRow,
891
- range.startColumn
892
- );
893
- let pattern = "";
894
- numfmtValue && (pattern = numfmtValue.pattern);
895
- const defaultValue = (cellValue == null ? void 0 : cellValue.t) === CellValueType.NUMBER ? cellValue.v : 12345678, props = {
896
- onChange: /* @__PURE__ */ __name((config) => {
897
- var _a8;
898
- if (config.type === "change")
899
- this._previewPattern = config.value, this._forceUpdate();
900
- else if (config.type === "confirm") {
901
- const selections2 = ((_a8 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a8.map((s) => s.range)) || [], params = { values: [] }, patternType = getPatternType(config.value);
902
- selections2.forEach((rangeInfo) => {
903
- Range.foreach(rangeInfo, (row, col) => {
904
- params.values.push({
905
- row,
906
- col,
907
- pattern: config.value,
908
- type: patternType
909
- });
369
+ // eslint-disable-next-line max-lines-per-function
370
+ _initInterceptorCellContent() {
371
+ const renderCache = new ObjectMatrix();
372
+ this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
373
+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
374
+ handler: /* @__PURE__ */ __name((cell, location, next) => {
375
+ const unitId = location.unitId, sheetId = location.subUnitId;
376
+ let numfmtValue;
377
+ const originCellValue = cell;
378
+ if (!originCellValue || originCellValue.t !== CellValueType.NUMBER || originCellValue.v == null || Number.isNaN(originCellValue.v))
379
+ return next(cell);
380
+ if (cell != null && cell.s) {
381
+ const style = location.workbook.getStyles().get(cell.s);
382
+ style != null && style.n && (numfmtValue = style.n);
383
+ }
384
+ if (numfmtValue || (numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col)), !numfmtValue)
385
+ return next(cell);
386
+ let numfmtRes = "";
387
+ const cache = renderCache.getValue(location.row, location.col);
388
+ if (cache && cache.parameters === `${originCellValue.v}_${numfmtValue.pattern}`)
389
+ return next({ ...cell, ...cache.result });
390
+ const info = getPatternPreviewIgnoreGeneral(numfmtValue.pattern, Number(originCellValue.v), this._localeService.getCurrentLocale());
391
+ if (numfmtRes = info.result, !numfmtRes)
392
+ return next(cell);
393
+ const res = { v: numfmtRes };
394
+ if (info.color) {
395
+ const color = this._themeService.getCurrentTheme()[`${info.color}500`];
396
+ color && (res.interceptorStyle = { cl: { rgb: color } });
397
+ }
398
+ return renderCache.setValue(location.row, location.col, {
399
+ result: res,
400
+ parameters: `${originCellValue.v}_${numfmtValue.pattern}`
401
+ }), next({ ...cell, ...res });
402
+ }, "handler"),
403
+ priority: InterceptCellContentPriority.NUMFMT
404
+ })), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
405
+ if (commandInfo.id === SetNumfmtMutation.id) {
406
+ const params = commandInfo.params;
407
+ Object.keys(params.values).forEach((key) => {
408
+ params.values[key].ranges.forEach((range) => {
409
+ Range.foreach(range, (row, col) => {
410
+ renderCache.realDeleteValue(row, col);
910
411
  });
911
- }), commandService.executeCommand(SetNumfmtCommand.id, params), sidebarService.close();
912
- } else config.type === "cancel" && sidebarService.close();
913
- }, "onChange"),
914
- value: { defaultPattern: pattern, defaultValue, row: range.startRow, col: range.startColumn }
915
- };
916
- return this._sidebarDisposable = sidebarService.open({
917
- header: { title: localeService.t("sheet.numfmt.title") },
918
- children: {
919
- label: SHEET_NUMFMT_PLUGIN,
920
- ...props
921
- // need passthrough to react props.
922
- },
923
- onClose: /* @__PURE__ */ __name(() => {
924
- this._forceUpdate(), commandService.executeCommand(CloseNumfmtPanelOperator.id);
925
- }, "onClose")
926
- }), !0;
927
- }
928
- _forceUpdate(unitId) {
929
- var _a7;
930
- const renderUnit = this._renderManagerService.getRenderById(
931
- unitId != null ? unitId : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getUnitId()
932
- );
933
- renderUnit == null || renderUnit.with(SheetSkeletonManagerService).reCalculate(), (_a7 = renderUnit == null ? void 0 : renderUnit.mainComponent) == null || _a7.makeDirty();
934
- }
935
- _initCommands() {
936
- [
937
- AddDecimalCommand,
938
- SubtractDecimalCommand,
939
- SetCurrencyCommand,
940
- SetPercentCommand,
941
- OpenNumfmtPanelOperator,
942
- CloseNumfmtPanelOperator,
943
- SetNumfmtCommand
944
- ].forEach((config) => {
945
- this.disposeWithMe(this._commandService.registerCommand(config));
946
- });
947
- }
948
- _initPanel() {
949
- this._componentManager.register(SHEET_NUMFMT_PLUGIN, SheetNumfmtPanel);
950
- }
951
- _initRealTimeRenderingInterceptor() {
952
- const isPanelOpenObserver = new Observable((subscriber) => {
953
- this._commandService.onCommandExecuted((commandInfo) => {
954
- commandInfo.id === OpenNumfmtPanelOperator.id && subscriber.next(!0), commandInfo.id === CloseNumfmtPanelOperator.id && subscriber.next(!1);
955
- });
956
- }), combineOpenAndSelection$ = combineLatest([
957
- isPanelOpenObserver,
958
- this._selectionManagerService.selectionMoveEnd$.pipe(
959
- map((selectionInfos) => selectionInfos ? selectionInfos.map((selectionInfo) => selectionInfo.range) : [])
960
- )
961
- ]);
962
- this.disposeWithMe(
963
- toDisposable(
964
- combineOpenAndSelection$.pipe(
965
- switchMap$1(
966
- ([isOpen, selectionRanges]) => new Observable((subscribe) => {
967
- const disposableCollection = new DisposableCollection();
968
- return isOpen && selectionRanges.length && subscribe.next({ selectionRanges, disposableCollection }), () => {
969
- disposableCollection.dispose();
970
- };
971
- })
972
- ),
973
- tap(() => {
974
- this._previewPattern = null;
975
- })
976
- ).subscribe(({ disposableCollection, selectionRanges }) => {
977
- var _a7, _b;
978
- const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
979
- this.openPanel(), disposableCollection.add(
980
- this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
981
- priority: 99,
982
- effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
983
- handler: /* @__PURE__ */ __name((cell, location, next) => {
984
- const { row, col } = location, defaultValue = next(cell) || {};
985
- if (selectionRanges.find(
986
- (range) => range.startColumn <= col && range.endColumn >= col && range.startRow <= row && range.endRow >= row
987
- )) {
988
- const rawValue = location.worksheet.getCellRaw(row, col), value = rawValue == null ? void 0 : rawValue.v, type = rawValue == null ? void 0 : rawValue.t;
989
- if (value == null || type !== CellValueType.NUMBER || this._previewPattern === null)
990
- return defaultValue;
991
- const info = getPatternPreviewIgnoreGeneral(this._previewPattern, value, this._localeService.getCurrentLocale());
992
- if (info.color) {
993
- const color = this._themeService.getCurrentTheme()[`${info.color}500`];
994
- return {
995
- ...defaultValue,
996
- v: info.result,
997
- t: CellValueType.STRING,
998
- s: { cl: { rgb: color } }
999
- };
1000
- }
1001
- return {
1002
- ...defaultValue,
1003
- v: info.result,
1004
- t: CellValueType.STRING
1005
- };
1006
- }
1007
- return defaultValue;
1008
- }, "handler")
1009
- })
1010
- ), (_b = (_a7 = this._renderManagerService.getRenderById(workbook.getUnitId())) == null ? void 0 : _a7.mainComponent) == null || _b.makeDirty();
1011
- })
1012
- )
1013
- );
1014
- }
1015
- _commandExecutedListener() {
1016
- const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id];
1017
- this.disposeWithMe(
1018
- new Observable((subscribe) => {
1019
- const disposable = this._commandService.onCommandExecuted((command) => {
1020
- if (commandList.includes(command.id)) {
1021
- const params = command.params;
1022
- subscribe.next(params.unitId);
1023
- }
412
+ });
413
+ });
414
+ } else if (commandInfo.id === SetRangeValuesMutation.id) {
415
+ const params = commandInfo.params;
416
+ new ObjectMatrix(params.cellValue).forValue((row, col) => {
417
+ renderCache.realDeleteValue(row, col);
1024
418
  });
1025
- return () => disposable.dispose();
1026
- }).pipe(debounceTime(16)).subscribe((unitId) => this._forceUpdate(unitId))
419
+ }
420
+ })), this.disposeWithMe(
421
+ this._instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(
422
+ switchMap((workbook) => {
423
+ var _a3;
424
+ return (_a3 = workbook == null ? void 0 : workbook.activeSheet$) != null ? _a3 : of(null);
425
+ }),
426
+ skip(1)
427
+ ).subscribe(() => renderCache.reset())
1027
428
  );
1028
429
  }
1029
- _initCloseListener() {
1030
- this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((unit) => {
1031
- var _a7;
1032
- unit || ((_a7 = this._sidebarDisposable) == null || _a7.dispose(), this._sidebarDisposable = null);
1033
- });
1034
- }
1035
- }, __name(_a3, "NumfmtController"), _a3);
1036
- NumfmtController = __decorateClass$3([
1037
- __decorateParam$3(0, Inject(SheetInterceptorService)),
1038
- __decorateParam$3(1, Inject(ThemeService)),
1039
- __decorateParam$3(2, IUniverInstanceService),
1040
- __decorateParam$3(3, ICommandService),
1041
- __decorateParam$3(4, Inject(SheetsSelectionsService)),
1042
- __decorateParam$3(5, IRenderManagerService),
1043
- __decorateParam$3(6, INumfmtService),
1044
- __decorateParam$3(7, Inject(ComponentManager)),
1045
- __decorateParam$3(8, ISidebarService),
1046
- __decorateParam$3(9, Inject(LocaleService))
1047
- ], NumfmtController);
430
+ }, __name(_a, "SheetsNumfmtCellContentController"), _a);
431
+ SheetsNumfmtCellContentController = __decorateClass$1([
432
+ __decorateParam$1(0, IUniverInstanceService),
433
+ __decorateParam$1(1, Inject(SheetInterceptorService)),
434
+ __decorateParam$1(2, Inject(ThemeService)),
435
+ __decorateParam$1(3, Inject(ICommandService)),
436
+ __decorateParam$1(4, Inject(INumfmtService)),
437
+ __decorateParam$1(5, Inject(LocaleService))
438
+ ], SheetsNumfmtCellContentController);
1048
439
  const _NumfmtCurrencyController = class _NumfmtCurrencyController extends Disposable {
1049
440
  constructor() {
1050
441
  super(...arguments);
@@ -1063,455 +454,89 @@ const _NumfmtCurrencyController = class _NumfmtCurrencyController extends Dispos
1063
454
  };
1064
455
  __name(_NumfmtCurrencyController, "NumfmtCurrencyController");
1065
456
  let NumfmtCurrencyController = _NumfmtCurrencyController;
1066
- var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1067
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1068
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
1069
- return kind && result && __defProp$2(target, key2, result), result;
1070
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$2");
1071
- const createCollectEffectMutation = /* @__PURE__ */ __name(() => {
1072
- let list = [];
1073
- return {
1074
- add: /* @__PURE__ */ __name((unitId, subUnitId, row, col, value) => list.push({ unitId, subUnitId, row, col, value }), "add"),
1075
- getEffects: /* @__PURE__ */ __name(() => list, "getEffects"),
1076
- clean: /* @__PURE__ */ __name(() => {
1077
- list = [];
1078
- }, "clean")
1079
- };
1080
- }, "createCollectEffectMutation");
1081
- var _a4;
1082
- let NumfmtEditorController = (_a4 = class extends Disposable {
1083
- constructor(_sheetInterceptorService, _numfmtService, _univerInstanceService, _injector, _editorBridgeService) {
1084
- super();
1085
- // collect effect mutations when edit end and push this to commands stack in next commands progress
1086
- __publicField(this, "_collectEffectMutation", createCollectEffectMutation());
1087
- this._sheetInterceptorService = _sheetInterceptorService, this._numfmtService = _numfmtService, this._univerInstanceService = _univerInstanceService, this._injector = _injector, this._editorBridgeService = _editorBridgeService, this._initInterceptorEditorStart(), this._initInterceptorEditorEnd(), this._initInterceptorCommands();
1088
- }
1089
- _initInterceptorEditorStart() {
1090
- this._editorBridgeService && this.disposeWithMe(
1091
- toDisposable(
1092
- this._editorBridgeService.interceptor.intercept(
1093
- this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,
1094
- {
1095
- handler: /* @__PURE__ */ __name((value, context, next) => {
1096
- const row = context.row, col = context.col, numfmtCell = this._numfmtService.getValue(
1097
- context.unitId,
1098
- context.subUnitId,
1099
- row,
1100
- col
1101
- );
1102
- if (numfmtCell)
1103
- switch (getPatternType(numfmtCell.pattern)) {
1104
- case "scientific":
1105
- case "currency":
1106
- case "grouped":
1107
- case "number":
1108
- return context.worksheet.getCellRaw(row, col);
1109
- case "percent":
1110
- case "date":
1111
- case "time":
1112
- case "datetime":
1113
- default:
1114
- return next && next(value);
1115
- }
1116
- return next(value);
1117
- }, "handler")
1118
- }
1119
- )
1120
- )
1121
- );
1122
- }
1123
- /**
1124
- * Process the values after edit
1125
- * @private
1126
- * @memberof NumfmtService
1127
- */
1128
- _initInterceptorEditorEnd() {
1129
- this._editorBridgeService && this.disposeWithMe(
1130
- toDisposable(
1131
- this._editorBridgeService.interceptor.intercept(
1132
- this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,
1133
- {
1134
- handler: /* @__PURE__ */ __name((value, context, next) => {
1135
- var _a7;
1136
- this._collectEffectMutation.clean();
1137
- const currentNumfmtValue = this._numfmtService.getValue(
1138
- context.unitId,
1139
- context.subUnitId,
1140
- context.row,
1141
- context.col
1142
- ), currentNumfmtType = (_a7 = currentNumfmtValue && getPatternType(currentNumfmtValue.pattern)) != null ? _a7 : "", clean = /* @__PURE__ */ __name(() => {
1143
- currentNumfmtValue && this._collectEffectMutation.add(
1144
- context.unitId,
1145
- context.subUnitId,
1146
- context.row,
1147
- context.col,
1148
- null
1149
- );
1150
- }, "clean");
1151
- if (!(value != null && value.v))
1152
- return next(value);
1153
- const content = String(value.v), numfmtInfo = numfmt.parseDate(content) || numfmt.parseTime(content) || numfmt.parseNumber(content);
1154
- if (numfmtInfo) {
1155
- if (numfmtInfo.z) {
1156
- const v = Number(numfmtInfo.v);
1157
- return this._collectEffectMutation.add(
1158
- context.unitId,
1159
- context.subUnitId,
1160
- context.row,
1161
- context.col,
1162
- {
1163
- pattern: numfmtInfo.z
1164
- }
1165
- ), { ...value, v, t: CellValueType.NUMBER };
1166
- }
1167
- } else (["date", "time", "datetime", "percent"].includes(currentNumfmtType) || !isNumeric(content)) && clean();
1168
- return next(value);
1169
- }, "handler")
1170
- }
1171
- )
1172
- )
1173
- );
1174
- }
1175
- _initInterceptorCommands() {
1176
- const self = this;
1177
- this.disposeWithMe(
1178
- this._sheetInterceptorService.interceptCommand({
1179
- getMutations(command) {
1180
- var _a7;
1181
- switch (command.id) {
1182
- case SetRangeValuesCommand.id: {
1183
- const workbook = self._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), unitId = workbook.getUnitId(), subUnitId = (_a7 = workbook.getActiveSheet()) == null ? void 0 : _a7.getSheetId();
1184
- if (!subUnitId)
1185
- return {
1186
- redos: [],
1187
- undos: []
1188
- };
1189
- const list = self._collectEffectMutation.getEffects();
1190
- if (self._collectEffectMutation.clean(), !list.length)
1191
- return {
1192
- redos: [],
1193
- undos: []
1194
- };
1195
- const cells = list.filter((item) => {
1196
- var _a8;
1197
- return !!((_a8 = item.value) != null && _a8.pattern);
1198
- }).map((item) => ({
1199
- row: item.row,
1200
- col: item.col,
1201
- pattern: item.value.pattern
1202
- })), removeCells = list.filter((item) => {
1203
- var _a8;
1204
- return !((_a8 = item.value) != null && _a8.pattern);
1205
- }).map((item) => ({
1206
- startRow: item.row,
1207
- endColumn: item.col,
1208
- startColumn: item.col,
1209
- endRow: item.row
1210
- })), redos = [], undos = [];
1211
- if (cells.length) {
1212
- const redo = {
1213
- id: SetNumfmtMutation.id,
1214
- params: transformCellsToRange(unitId, subUnitId, cells)
1215
- };
1216
- redos.push(redo), undos.push(...factorySetNumfmtUndoMutation(self._injector, redo.params));
1217
- }
1218
- if (removeCells.length) {
1219
- const redo = {
1220
- id: RemoveNumfmtMutation.id,
1221
- params: {
1222
- unitId,
1223
- subUnitId,
1224
- ranges: removeCells
1225
- }
1226
- };
1227
- redos.push(redo), undos.push(...factoryRemoveNumfmtUndoMutation(self._injector, redo.params));
1228
- }
1229
- return {
1230
- redos,
1231
- undos: undos.reverse()
1232
- };
1233
- }
1234
- }
1235
- return {
1236
- redos: [],
1237
- undos: []
1238
- };
1239
- }
1240
- })
1241
- );
1242
- }
1243
- }, __name(_a4, "NumfmtEditorController"), _a4);
1244
- NumfmtEditorController = __decorateClass$2([
1245
- __decorateParam$2(0, Inject(SheetInterceptorService)),
1246
- __decorateParam$2(1, Inject(INumfmtService)),
1247
- __decorateParam$2(2, Inject(IUniverInstanceService)),
1248
- __decorateParam$2(3, Inject(Injector)),
1249
- __decorateParam$2(4, Optional(IEditorBridgeService))
1250
- ], NumfmtEditorController);
1251
- function isNumeric(str) {
1252
- return /^-?\d+(\.\d+)?$/.test(str);
1253
- }
1254
- __name(isNumeric, "isNumeric");
1255
- const MENU_OPTIONS = [
1256
- {
1257
- label: "sheet.numfmt.general",
1258
- pattern: null
1259
- },
1260
- {
1261
- label: "sheet.numfmt.text",
1262
- pattern: DEFAULT_TEXT_FORMAT
1263
- },
1264
- "|",
1265
- {
1266
- label: "sheet.numfmt.number",
1267
- pattern: "0"
1268
- },
1269
- "|",
1270
- {
1271
- label: "sheet.numfmt.accounting",
1272
- pattern: '"¥" #,##0.00_);[Red]("¥"#,##0.00)'
1273
- },
1274
- {
1275
- label: "sheet.numfmt.financialValue",
1276
- pattern: "#,##0.00;[Red]#,##0.00"
1277
- },
1278
- {
1279
- label: "sheet.numfmt.currency",
1280
- pattern: '"¥"#,##0.00_);[Red]("¥"#,##0.00)'
1281
- },
1282
- {
1283
- label: "sheet.numfmt.roundingCurrency",
1284
- pattern: '"¥"#,##0;[Red]"¥"#,##0'
1285
- },
1286
- "|",
1287
- {
1288
- label: "sheet.numfmt.date",
1289
- pattern: "yyyy-mm-dd;@"
1290
- },
1291
- {
1292
- label: "sheet.numfmt.time",
1293
- pattern: 'am/pm h":"mm":"ss'
1294
- },
1295
- {
1296
- label: "sheet.numfmt.dateTime",
1297
- pattern: "yyyy-m-d am/pm h:mm"
1298
- },
1299
- {
1300
- label: "sheet.numfmt.timeDuration",
1301
- pattern: "h:mm:ss"
1302
- },
1303
- "|",
1304
- {
1305
- label: "sheet.numfmt.moreFmt",
1306
- pattern: ""
1307
- }
1308
- ], MORE_NUMFMT_TYPE_KEY = "sheet.numfmt.moreNumfmtType", OPTIONS_KEY = "sheet.numfmt.moreNumfmtType.options", MoreNumfmtType = /* @__PURE__ */ __name((props) => {
1309
- var _a7;
1310
- const localeService = useDependency(LocaleService), value = (_a7 = props.value) != null ? _a7 : localeService.t("sheet.numfmt.general");
1311
- return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "more-numfmt-type", children: value });
1312
- }, "MoreNumfmtType"), Options = /* @__PURE__ */ __name(() => {
1313
- const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), layoutService = useDependency(ILayoutService);
1314
- useInjector();
1315
- const selectionManagerService = useDependency(SheetsSelectionsService), setNumfmt = /* @__PURE__ */ __name((pattern) => {
1316
- const selection = selectionManagerService.getCurrentLastSelection();
1317
- if (!selection)
1318
- return;
1319
- const range = selection.range, values = [];
1320
- Range.foreach(range, (row, col) => {
1321
- pattern ? values.push({ row, col, pattern, type: getPatternType(pattern) }) : values.push({ row, col });
1322
- }), commandService.executeCommand(SetNumfmtCommand.id, { values }), layoutService.focus();
1323
- }, "setNumfmt"), handleOnclick = /* @__PURE__ */ __name((index) => {
1324
- if (index === 0)
1325
- setNumfmt(null);
1326
- else if (index === MENU_OPTIONS.length - 1)
1327
- commandService.executeCommand(OpenNumfmtPanelOperator.id);
1328
- else {
1329
- const item = MENU_OPTIONS[index];
1330
- item.pattern && setNumfmt(item.pattern);
1331
- }
1332
- }, "handleOnclick"), defaultValue = 1220;
1333
- 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(
1334
- "div",
1335
- {
1336
- className: "option-item m-t-4",
1337
- onClick: /* @__PURE__ */ __name(() => {
1338
- handleOnclick(index);
1339
- }, "onClick"),
1340
- children: [
1341
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t(item.label) }),
1342
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-l-26", children: item.pattern ? getPatternPreview(item.pattern || "", defaultValue, localeService.getCurrentLocale()).result : "" })
1343
- ]
1344
- },
1345
- index
1346
- )) });
1347
- }, "Options"), CurrencyMenuItem = /* @__PURE__ */ __name((accessor) => ({
1348
- icon: new Observable((subscribe) => {
1349
- const menuCurrencyService = accessor.get(MenuCurrencyService);
1350
- function getIconKey(symbol2) {
1351
- return {
1352
- [countryCurrencyMap.US]: "DollarSingle",
1353
- [countryCurrencyMap.RU]: "RoubleSingle",
1354
- [countryCurrencyMap.CN]: "RmbSingle",
1355
- [countryCurrencyMap.AT]: "EuroSingle"
1356
- }[symbol2] || "DollarSingle";
1357
- }
1358
- __name(getIconKey, "getIconKey");
1359
- const symbol = countryCurrencyMap[menuCurrencyService.getCurrencySymbol()] || "$";
1360
- return subscribe.next(getIconKey(symbol)), menuCurrencyService.currencySymbol$.subscribe((code) => {
1361
- const symbol2 = countryCurrencyMap[code] || "$";
1362
- subscribe.next(getIconKey(symbol2));
1363
- });
1364
- }),
1365
- id: SetCurrencyCommand.id,
1366
- title: "sheet.numfmt.currency",
1367
- tooltip: "sheet.numfmt.currency",
1368
- type: MenuItemType.BUTTON,
1369
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1370
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1371
- }), "CurrencyMenuItem"), AddDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
1372
- icon: "AddDigitsSingle",
1373
- id: AddDecimalCommand.id,
1374
- title: "sheet.numfmt.addDecimal",
1375
- tooltip: "sheet.numfmt.addDecimal",
1376
- type: MenuItemType.BUTTON,
1377
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1378
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1379
- }), "AddDecimalMenuItem"), SubtractDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
1380
- icon: "ReduceDigitsSingle",
1381
- id: SubtractDecimalCommand.id,
1382
- title: "sheet.numfmt.subtractDecimal",
1383
- tooltip: "sheet.numfmt.subtractDecimal",
1384
- type: MenuItemType.BUTTON,
1385
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1386
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1387
- }), "SubtractDecimalMenuItem"), PercentMenuItem = /* @__PURE__ */ __name((accessor) => ({
1388
- icon: "PercentSingle",
1389
- id: SetPercentCommand.id,
1390
- title: "sheet.numfmt.percent",
1391
- tooltip: "sheet.numfmt.percent",
1392
- type: MenuItemType.BUTTON,
1393
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1394
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1395
- }), "PercentMenuItem"), FactoryOtherMenuItem = /* @__PURE__ */ __name((accessor) => {
1396
- const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), localeService = accessor.get(LocaleService), selectionManagerService = accessor.get(SheetsSelectionsService), value$ = deriveStateFromActiveSheet$(univerInstanceService, "", ({ workbook, worksheet }) => new Observable(
1397
- (subscribe) => merge(
1398
- selectionManagerService.selectionMoveEnd$,
1399
- new Observable((commandSubscribe) => {
1400
- const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id], disposable = commandService.onCommandExecuted((commandInfo) => {
1401
- commandList.includes(commandInfo.id) && commandSubscribe.next(null);
1402
- });
1403
- return () => disposable.dispose();
1404
- })
1405
- ).subscribe(() => {
1406
- var _a7, _b;
1407
- const selections = selectionManagerService.getCurrentSelections();
1408
- if (selections && selections[0]) {
1409
- const range = selections[0].range, row = range.startRow, col = range.startColumn, numfmtValue = (_b = workbook.getStyles().get((_a7 = worksheet.getCell(row, col)) == null ? void 0 : _a7.s)) == null ? void 0 : _b.n, pattern = numfmtValue == null ? void 0 : numfmtValue.pattern;
1410
- let value = localeService.t("sheet.numfmt.general");
1411
- if (pattern) {
1412
- const item = MENU_OPTIONS.filter((item2) => typeof item2 == "object" && item2.pattern).find(
1413
- (item2) => isPatternEqualWithoutDecimal(pattern, item2.pattern)
1414
- );
1415
- item && typeof item == "object" && item.pattern ? value = localeService.t(item.label) : value = localeService.t("sheet.numfmt.moreFmt");
1416
- }
1417
- subscribe.next(value);
1418
- }
1419
- })
1420
- ));
1421
- return {
1422
- label: MORE_NUMFMT_TYPE_KEY,
1423
- id: OpenNumfmtPanelOperator.id,
1424
- tooltip: "sheet.numfmt.title",
1425
- type: MenuItemType.SELECTOR,
1426
- selections: [
1427
- {
1428
- label: {
1429
- name: OPTIONS_KEY,
1430
- hoverable: !1
1431
- }
1432
- }
1433
- ],
1434
- value$,
1435
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1436
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1437
- };
1438
- }, "FactoryOtherMenuItem"), menuSchema = {
1439
- [RibbonStartGroup.FORMULAS_INSERT]: {
1440
- [SetCurrencyCommand.id]: {
1441
- order: 4,
1442
- menuItemFactory: CurrencyMenuItem
1443
- },
1444
- [AddDecimalCommand.id]: {
1445
- order: 5,
1446
- menuItemFactory: AddDecimalMenuItem
1447
- },
1448
- [SubtractDecimalCommand.id]: {
1449
- order: 6,
1450
- menuItemFactory: SubtractDecimalMenuItem
1451
- },
1452
- [SetPercentCommand.id]: {
1453
- order: 7,
1454
- menuItemFactory: PercentMenuItem
1455
- },
1456
- [OpenNumfmtPanelOperator.id]: {
1457
- order: 8,
1458
- menuItemFactory: FactoryOtherMenuItem
1459
- }
1460
- }
1461
- };
1462
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1463
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1464
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
1465
- return kind && result && __defProp$1(target, key2, result), result;
1466
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$1"), _a5;
1467
- let NumfmtMenuController = (_a5 = class extends Disposable {
1468
- constructor(_componentManager, _menuManagerService) {
1469
- super(), this._componentManager = _componentManager, this._menuManagerService = _menuManagerService, this._initMenu();
1470
- }
1471
- _initMenu() {
1472
- this._menuManagerService.mergeMenu(menuSchema), this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY, MoreNumfmtType)), this.disposeWithMe(this._componentManager.register(OPTIONS_KEY, Options));
1473
- }
1474
- }, __name(_a5, "NumfmtMenuController"), _a5);
1475
- NumfmtMenuController = __decorateClass$1([
1476
- __decorateParam$1(0, Inject(ComponentManager)),
1477
- __decorateParam$1(1, IMenuManagerService)
1478
- ], NumfmtMenuController);
1479
- 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) => {
1480
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1481
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
1482
- return kind && result && __defProp2(target, key2, result), result;
1483
- }, "__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"), _a6;
1484
- let UniverSheetsNumfmtPlugin = (_a6 = class extends Plugin {
1485
- constructor(_config = defaultPluginConfig, _injector, _configService) {
1486
- super(), this._config = _config, this._injector = _injector, this._configService = _configService;
1487
- const { menu, ...rest } = this._config;
1488
- menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
457
+ const INumfmtController = createIdentifier("INumfmtController");
458
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
459
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
460
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
461
+ return kind && result && __defProp2(target, key, result), result;
462
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a2;
463
+ let UniverSheetsNumfmtPlugin = (_a2 = class extends Plugin {
464
+ constructor(_config = void 0, _injector, _commandService) {
465
+ super(), this._config = _config, this._injector = _injector, this._commandService = _commandService;
1489
466
  }
1490
467
  onStarting() {
1491
- this._injector.add([INumfmtController, { useClass: NumfmtController, lazy: !1 }]), this._injector.add([NumfmtEditorController]), this._injector.add([UserHabitController]), this._injector.add([SheetsNumfmtCellContentController]), this._injector.add([MenuCurrencyService]), this._injector.add([NumfmtCurrencyController]), this._injector.add([NumfmtMenuController]);
468
+ registerDependencies(this._injector, [
469
+ [SheetsNumfmtCellContentController],
470
+ [MenuCurrencyService],
471
+ [NumfmtCurrencyController]
472
+ ]);
1492
473
  }
1493
474
  onRendered() {
1494
- this._injector.get(INumfmtController), this._injector.get(SheetsNumfmtCellContentController), this._injector.get(NumfmtCurrencyController), this._injector.get(NumfmtEditorController), this._injector.get(NumfmtMenuController);
475
+ touchDependencies(this._injector, [
476
+ [INumfmtController],
477
+ [SheetsNumfmtCellContentController],
478
+ [NumfmtCurrencyController]
479
+ ]), [
480
+ AddDecimalCommand,
481
+ SubtractDecimalCommand,
482
+ SetCurrencyCommand,
483
+ SetPercentCommand,
484
+ SetNumfmtCommand
485
+ ].forEach((config) => {
486
+ this.disposeWithMe(this._commandService.registerCommand(config));
487
+ });
1495
488
  }
1496
- }, __name(_a6, "UniverSheetsNumfmtPlugin"), _a6);
489
+ }, __name(_a2, "UniverSheetsNumfmtPlugin"), _a2);
1497
490
  __publicField2(UniverSheetsNumfmtPlugin, "pluginName", SHEET_NUMFMT_PLUGIN);
1498
491
  __publicField2(UniverSheetsNumfmtPlugin, "type", UniverInstanceType.UNIVER_SHEET);
1499
492
  UniverSheetsNumfmtPlugin = __decorateClass([
1500
- DependentOn(UniverSheetsPlugin, UniverSheetsUIPlugin),
493
+ DependentOn(UniverSheetsPlugin),
1501
494
  __decorateParam(1, Inject(Injector)),
1502
- __decorateParam(2, IConfigService)
495
+ __decorateParam(2, ICommandService)
1503
496
  ], UniverSheetsNumfmtPlugin);
497
+ const getCurrencyType = /* @__PURE__ */ __name((pattern) => currencySymbols.find((code) => pattern.includes(code)), "getCurrencyType"), getCurrencyOptions = /* @__PURE__ */ __name(() => currencySymbols.map((item) => ({ label: item, value: item })), "getCurrencyOptions"), getCurrencyFormatOptions = /* @__PURE__ */ __name((suffix) => CURRENCYFORMAT.map((item) => ({
498
+ label: item.label(suffix),
499
+ value: item.suffix(suffix),
500
+ color: item.color
501
+ })), "getCurrencyFormatOptions"), getDateFormatOptions = /* @__PURE__ */ __name(() => DATEFMTLISG.map((item) => ({ label: item.label, value: item.suffix })), "getDateFormatOptions"), getNumberFormatOptions = /* @__PURE__ */ __name(() => NUMBERFORMAT.map((item) => ({ label: item.label, value: item.suffix, color: item.color })), "getNumberFormatOptions"), CloseNumfmtPanelOperator = {
502
+ id: "sheet.operation.close.numfmt.panel",
503
+ type: CommandType.OPERATION,
504
+ handler: /* @__PURE__ */ __name(() => (
505
+ // do nothing,just notify panel is closed
506
+ !0
507
+ ), "handler")
508
+ }, OpenNumfmtPanelOperator = {
509
+ id: "sheet.operation.open.numfmt.panel",
510
+ type: CommandType.OPERATION,
511
+ handler: /* @__PURE__ */ __name((accessor) => (accessor.get(INumfmtController).openPanel(), !0), "handler")
512
+ };
1504
513
  export {
1505
514
  AddDecimalCommand,
515
+ CURRENCYFORMAT,
1506
516
  CloseNumfmtPanelOperator,
517
+ DATEFMTLISG,
1507
518
  MenuCurrencyService,
519
+ NUMBERFORMAT,
1508
520
  OpenNumfmtPanelOperator,
1509
521
  SetCurrencyCommand,
1510
522
  SetNumfmtCommand,
1511
523
  SetPercentCommand,
524
+ SheetsNumfmtCellContentController,
1512
525
  SubtractDecimalCommand,
1513
526
  UniverSheetsNumfmtPlugin,
1514
527
  countryCurrencyMap,
528
+ currencySymbols,
529
+ getCurrencyFormatOptions,
530
+ getCurrencyOptions,
531
+ getCurrencyType,
532
+ getDateFormatOptions,
533
+ getDecimalFromPattern,
534
+ getDecimalString,
535
+ getNumberFormatOptions,
1515
536
  getPatternPreview,
1516
- getPatternType
537
+ getPatternPreviewIgnoreGeneral,
538
+ getPatternType,
539
+ isPatternEqualWithoutDecimal,
540
+ isPatternHasDecimal,
541
+ setPatternDecimal
1517
542
  };