@univerjs/sheets-numfmt 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -1,206 +1,212 @@
1
- var dt = Object.defineProperty;
2
- var ft = (e, t, r) => t in e ? dt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var ce = (e, t, r) => ft(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { LocaleType as ht, Disposable as K, ObjectMatrix as Le, CellValueType as V, Range as R, UniverInstanceType as T, OnLifecycle as Y, LifecycleStages as B, Inject as b, ThemeService as We, ICommandService as O, LocaleService as E, IUniverInstanceService as w, CommandType as D, IUndoRedoService as pt, sequenceExecute as vt, createIdentifier as _t, runOnLifecycle as gt, ILocalStorageService as St, useDependency as N, toDisposable as Ee, DisposableCollection as bt, Injector as Pe, Optional as Ct, useInjector as yt, Plugin as Tt, Tools as It, DependentOn as Et } from "@univerjs/core";
5
- import { INTERCEPTOR_POINT as ke, SetNumfmtMutation as q, SetRangeValuesMutation as Nt, SheetInterceptorService as Re, INumfmtService as H, getSheetCommandTarget as xe, transformCellsToRange as Ge, rangeMerge as Ve, factorySetNumfmtUndoMutation as ze, RemoveNumfmtMutation as _e, factoryRemoveNumfmtUndoMutation as Ke, SheetsSelectionsService as U, SetRangeValuesCommand as Mt, WorkbookEditablePermission as J, WorksheetEditPermission as X, WorksheetSetCellStylePermission as Z, RangeProtectionPermissionEditPoint as Q, UniverSheetsPlugin as Pt } from "@univerjs/sheets";
6
- import { SheetSkeletonManagerService as Rt, IEditorBridgeService as xt, getCurrentRangeDisable$ as ee, deriveStateFromActiveSheet$ as Ot, UniverSheetsUIPlugin as jt } from "@univerjs/sheets-ui";
7
- import { switchMap as $t, of as wt, skip as Dt, Observable as G, combineLatest as Ut, merge as At } from "rxjs";
8
- import { numfmt as x, DEFAULT_TEXT_FORMAT as Lt } from "@univerjs/engine-numfmt";
9
- import { IRenderManagerService as Vt, ITextSelectionRenderManager as Bt } from "@univerjs/engine-render";
10
- import { ComponentManager as Ye, ISidebarService as Ht, MenuItemType as te, MenuGroup as ne, MenuPosition as re, getMenuHiddenObservable as se, IMenuService as Ft } from "@univerjs/ui";
11
- import { map as Wt, switchMap as kt, tap as Gt, debounceTime as zt } from "rxjs/operators";
12
- import Kt, { createContext as Yt, useState as I, useEffect as Oe, useRef as qe, useContext as Je, useMemo as P, createElement as qt } from "react";
13
- import { InputNumber as je, Select as $e, SelectList as we, Button as Be } from "@univerjs/design";
14
- const Ne = "SHEET_NUMFMT_PLUGIN", fe = (e) => x.getInfo(e).type || "unknown", De = (e, t, r) => {
15
- const n = x.getInfo(e), s = r === ht.ZH_CN ? "zh-CN" : "en", i = n._partitions[1], o = x.format(e, t, { locale: s });
16
- return t < 0 ? {
17
- result: o,
18
- color: i.color
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;
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 { LocaleType, Disposable, ObjectMatrix, CellValueType, Range, UniverInstanceType, OnLifecycle, LifecycleStages, Inject, ThemeService, ICommandService, LocaleService, IUniverInstanceService, CommandType, IUndoRedoService, sequenceExecute, createIdentifier, runOnLifecycle, ILocalStorageService, useDependency, toDisposable, DisposableCollection, Injector, Optional, useInjector, Plugin, Tools, DependentOn } from "@univerjs/core";
6
+ import { INTERCEPTOR_POINT, SetNumfmtMutation, SetRangeValuesMutation, SheetInterceptorService, INumfmtService, getSheetCommandTarget, transformCellsToRange, rangeMerge, factorySetNumfmtUndoMutation, RemoveNumfmtMutation, factoryRemoveNumfmtUndoMutation, SheetsSelectionsService, SetRangeValuesCommand, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, RangeProtectionPermissionEditPoint, UniverSheetsPlugin } from "@univerjs/sheets";
7
+ import { SheetSkeletonManagerService, IEditorBridgeService, getCurrentRangeDisable$, deriveStateFromActiveSheet$, UniverSheetsUIPlugin } from "@univerjs/sheets-ui";
8
+ import { switchMap, of, skip, Observable, combineLatest, merge } from "rxjs";
9
+ import { numfmt, DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
10
+ import { IRenderManagerService, ITextSelectionRenderManager } from "@univerjs/engine-render";
11
+ import { ComponentManager, ISidebarService, MenuItemType, MenuGroup, MenuPosition, getMenuHiddenObservable, IMenuService } from "@univerjs/ui";
12
+ import { map, switchMap as switchMap$1, tap, debounceTime } from "rxjs/operators";
13
+ import require$$0, { createContext, useState, useEffect, useRef, useContext, useMemo, forwardRef, createElement } from "react";
14
+ import { InputNumber, Select, SelectList, Input, Button } from "@univerjs/design";
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
+ const info = numfmt.getInfo(pattern), locale = _locale === LocaleType.ZH_CN ? "zh-CN" : "en", negInfo = info._partitions[1], result = numfmt.format(pattern, value, { locale });
17
+ return value < 0 ? {
18
+ result,
19
+ color: negInfo.color
19
20
  } : {
20
- result: o
21
+ result
21
22
  };
22
- };
23
- var Jt = Object.defineProperty, Xt = Object.getOwnPropertyDescriptor, Zt = (e, t, r, n) => {
24
- for (var s = n > 1 ? void 0 : n ? Xt(t, r) : t, i = e.length - 1, o; i >= 0; i--)
25
- (o = e[i]) && (s = (n ? o(t, r, s) : o(s)) || s);
26
- return n && s && Jt(t, r, s), s;
27
- }, L = (e, t) => (r, n) => t(r, n, e);
28
- let ae = class extends K {
29
- constructor(e, t, r, n, s, i) {
30
- super(), this._instanceService = e, this._sheetInterceptorService = t, this._themeService = r, this._commandService = n, this._numfmtService = s, this._localeService = i, this._initInterceptorCellContent();
23
+ }, "getPatternPreview");
24
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
25
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
26
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
27
+ return kind && result && __defProp$6(target, key2, result), result;
28
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$6"), _a;
29
+ let SheetsNumfmtCellContentController = (_a = class extends Disposable {
30
+ constructor(_instanceService, _sheetInterceptorService, _themeService, _commandService, _numfmtService, _localeService) {
31
+ super(), this._instanceService = _instanceService, this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._commandService = _commandService, this._numfmtService = _numfmtService, this._localeService = _localeService, this._initInterceptorCellContent();
31
32
  }
32
33
  _initInterceptorCellContent() {
33
- const e = new Le();
34
- this.disposeWithMe(this._sheetInterceptorService.intercept(ke.CELL_CONTENT, {
35
- handler: (t, r, n) => {
36
- const s = r.unitId, i = r.subUnitId, o = this._numfmtService.getValue(s, i, r.row, r.col);
37
- if (!o)
38
- return n(t);
39
- const c = t;
40
- if (!c || c.t !== V.NUMBER)
41
- return n(t);
42
- let a = "";
43
- const f = e.getValue(r.row, r.col);
44
- if (f && f.parameters === c.v)
45
- return n({ ...t, ...f.result });
46
- const m = De(o.pattern, Number(c.v), this._localeService.getCurrentLocale());
47
- if (a = m.result, !a)
48
- return n(t);
49
- const l = { v: a };
50
- if (m.color) {
51
- const u = this._themeService.getCurrentTheme()[`${m.color}500`];
52
- u && (l.interceptorStyle = { cl: { rgb: u } });
34
+ const renderCache = new ObjectMatrix();
35
+ this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
36
+ handler: /* @__PURE__ */ __name((cell, location, next) => {
37
+ const unitId = location.unitId, sheetId = location.subUnitId;
38
+ let numfmtValue;
39
+ if (cell != null && cell.s) {
40
+ const style = location.workbook.getStyles().get(cell.s);
41
+ style != null && style.n && (numfmtValue = style.n);
53
42
  }
54
- return e.setValue(r.row, r.col, {
55
- result: l,
56
- parameters: c.v
57
- }), n({ ...t, ...l });
58
- },
43
+ if (numfmtValue || (numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col)), !numfmtValue)
44
+ return next(cell);
45
+ const originCellValue = cell;
46
+ if (!originCellValue || originCellValue.t !== CellValueType.NUMBER)
47
+ return next(cell);
48
+ let numfmtRes = "";
49
+ const cache = renderCache.getValue(location.row, location.col);
50
+ if (cache && cache.parameters === `${originCellValue.v}_${numfmtValue.pattern}`)
51
+ return next({ ...cell, ...cache.result });
52
+ const info = getPatternPreview(numfmtValue.pattern, Number(originCellValue.v), this._localeService.getCurrentLocale());
53
+ if (numfmtRes = info.result, !numfmtRes)
54
+ return next(cell);
55
+ const res = { v: numfmtRes };
56
+ if (info.color) {
57
+ const color = this._themeService.getCurrentTheme()[`${info.color}500`];
58
+ color && (res.interceptorStyle = { cl: { rgb: color } });
59
+ }
60
+ return renderCache.setValue(location.row, location.col, {
61
+ result: res,
62
+ parameters: `${originCellValue.v}_${numfmtValue.pattern}`
63
+ }), next({ ...cell, ...res });
64
+ }, "handler"),
59
65
  priority: 10
60
- })), this.disposeWithMe(this._commandService.onCommandExecuted((t) => {
61
- if (t.id === q.id) {
62
- const r = t.params;
63
- Object.keys(r.values).forEach((n) => {
64
- r.values[n].ranges.forEach((i) => {
65
- R.foreach(i, (o, c) => {
66
- e.realDeleteValue(o, c);
66
+ })), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
67
+ if (commandInfo.id === SetNumfmtMutation.id) {
68
+ const params = commandInfo.params;
69
+ Object.keys(params.values).forEach((key2) => {
70
+ params.values[key2].ranges.forEach((range) => {
71
+ Range.foreach(range, (row, col) => {
72
+ renderCache.realDeleteValue(row, col);
67
73
  });
68
74
  });
69
75
  });
70
- } else if (t.id === Nt.id) {
71
- const r = t.params;
72
- new Le(r.cellValue).forValue((n, s) => {
73
- e.realDeleteValue(n, s);
76
+ } else if (commandInfo.id === SetRangeValuesMutation.id) {
77
+ const params = commandInfo.params;
78
+ new ObjectMatrix(params.cellValue).forValue((row, col) => {
79
+ renderCache.realDeleteValue(row, col);
74
80
  });
75
81
  }
76
82
  })), this.disposeWithMe(
77
- this._instanceService.getCurrentTypeOfUnit$(T.UNIVER_SHEET).pipe(
78
- $t((t) => {
79
- var r;
80
- return (r = t == null ? void 0 : t.activeSheet$) != null ? r : wt(null);
83
+ this._instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(
84
+ switchMap((workbook) => {
85
+ var _a8;
86
+ return (_a8 = workbook == null ? void 0 : workbook.activeSheet$) != null ? _a8 : of(null);
81
87
  }),
82
- Dt(1)
83
- ).subscribe(() => e.reset())
88
+ skip(1)
89
+ ).subscribe(() => renderCache.reset())
84
90
  );
85
91
  }
86
- };
87
- ae = Zt([
88
- Y(B.Rendered, ae),
89
- L(0, w),
90
- L(1, b(Re)),
91
- L(2, b(We)),
92
- L(3, b(O)),
93
- L(4, b(H)),
94
- L(5, b(E))
95
- ], ae);
96
- const j = (e, t = 0) => {
97
- var n;
98
- return e && (n = x.getInfo(e).maxDecimals) != null ? n : t;
99
- }, ge = (e, t) => {
100
- if (e && !t || !e && t)
92
+ }, __name(_a, "SheetsNumfmtCellContentController"), _a);
93
+ SheetsNumfmtCellContentController = __decorateClass$6([
94
+ OnLifecycle(LifecycleStages.Rendered, SheetsNumfmtCellContentController),
95
+ __decorateParam$6(0, IUniverInstanceService),
96
+ __decorateParam$6(1, Inject(SheetInterceptorService)),
97
+ __decorateParam$6(2, Inject(ThemeService)),
98
+ __decorateParam$6(3, Inject(ICommandService)),
99
+ __decorateParam$6(4, Inject(INumfmtService)),
100
+ __decorateParam$6(5, Inject(LocaleService))
101
+ ], SheetsNumfmtCellContentController);
102
+ const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0) => {
103
+ var _a8;
104
+ return pattern && (_a8 = numfmt.getInfo(pattern).maxDecimals) != null ? _a8 : defaultValue;
105
+ }, "getDecimalFromPattern"), isPatternEqualWithoutDecimal = /* @__PURE__ */ __name((patternA, patternB) => {
106
+ if (patternA && !patternB || !patternA && patternB)
101
107
  return !1;
102
- const r = (f) => f.reduce(
103
- (m, l) => {
104
- if (m.isEnd)
105
- return m;
106
- const u = l.value || l.num;
107
- return l.type === "point" ? (m.isEnd = !0, m) : { ...m, result: m.result + u };
108
+ const getString = /* @__PURE__ */ __name((tokens) => tokens.reduce(
109
+ (pre, cur) => {
110
+ if (pre.isEnd)
111
+ return pre;
112
+ const str = cur.value || cur.num;
113
+ return cur.type === "point" ? (pre.isEnd = !0, pre) : { ...pre, result: pre.result + str };
108
114
  },
109
115
  { isEnd: !1, result: "" }
110
- ).result, n = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, i = r(n[0].tokens), o = r(s[0].tokens), c = r(n[1].tokens), a = r(s[1].tokens);
111
- return i === o && c === a && n[1].color === s[1].color;
112
- }, He = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), y = (e, t) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
116
+ ).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);
117
+ return A1 === B1 && A2 === B2 && partitionsA[1].color === partitionsB[1].color;
118
+ }, "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(
113
119
  /\.0*/g,
114
- `${t > 0 ? "." : ""}${He(Number(t || 0))}`
115
- ) : /0([^0]?)|0$/.test(n) ? n.replace(
120
+ `${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}`
121
+ ) : /0([^0]?)|0$/.test(pattern) ? pattern.replace(
116
122
  /0([^0]+)|0$/,
117
- `0${t > 0 ? "." : ""}${He(Number(t || 0))}$1`
118
- ) : n).join(";"), Qt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), $ = {
123
+ `0${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}$1`
124
+ ) : pattern).join(";"), "setPatternDecimal"), isPatternHasDecimal = /* @__PURE__ */ __name((pattern) => /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern), "isPatternHasDecimal"), SetNumfmtCommand = {
119
125
  id: "sheet.command.numfmt.set.numfmt",
120
- type: D.COMMAND,
121
- handler: (e, t) => {
122
- if (!t)
126
+ type: CommandType.COMMAND,
127
+ handler: /* @__PURE__ */ __name((accessor, params) => {
128
+ if (!params)
123
129
  return !1;
124
- const r = e.get(O), n = e.get(w), s = e.get(pt), i = xe(n, t);
125
- if (!i) return !1;
126
- const { unitId: o, subUnitId: c } = i, a = t.values.filter((h) => !!h.pattern), f = t.values.filter((h) => !h.pattern), m = Ge(o, c, a), l = {
127
- unitId: o,
128
- subUnitId: c,
129
- ranges: f.map((h) => ({
130
- startColumn: h.col,
131
- startRow: h.row,
132
- endColumn: h.col,
133
- endRow: h.row
130
+ const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), undoRedoService = accessor.get(IUndoRedoService), target = getSheetCommandTarget(univerInstanceService, params);
131
+ if (!target) return !1;
132
+ const { unitId, subUnitId } = target, setCells = params.values.filter((value) => !!value.pattern), removeCells = params.values.filter((value) => !value.pattern), setRedos = transformCellsToRange(unitId, subUnitId, setCells), removeRedos = {
133
+ unitId,
134
+ subUnitId,
135
+ ranges: removeCells.map((cell) => ({
136
+ startColumn: cell.col,
137
+ startRow: cell.row,
138
+ endColumn: cell.col,
139
+ endRow: cell.row
134
140
  }))
135
- }, u = [], v = [];
136
- if (a.length) {
137
- Object.keys(m.values).forEach((g) => {
138
- const p = m.values[g];
139
- p.ranges = Ve(p.ranges);
140
- }), u.push({
141
- id: q.id,
142
- params: m
141
+ }, redos = [], undos = [];
142
+ if (setCells.length) {
143
+ Object.keys(setRedos.values).forEach((key2) => {
144
+ const v = setRedos.values[key2];
145
+ v.ranges = rangeMerge(v.ranges);
146
+ }), redos.push({
147
+ id: SetNumfmtMutation.id,
148
+ params: setRedos
143
149
  });
144
- const h = ze(e, m);
145
- v.push(...h);
150
+ const undo = factorySetNumfmtUndoMutation(accessor, setRedos);
151
+ undos.push(...undo);
146
152
  }
147
- if (f.length) {
148
- l.ranges = Ve(l.ranges), u.push({
149
- id: _e.id,
150
- params: l
153
+ if (removeCells.length) {
154
+ removeRedos.ranges = rangeMerge(removeRedos.ranges), redos.push({
155
+ id: RemoveNumfmtMutation.id,
156
+ params: removeRedos
151
157
  });
152
- const h = Ke(e, l);
153
- v.push(...h);
158
+ const undo = factoryRemoveNumfmtUndoMutation(accessor, removeRedos);
159
+ undos.push(...undo);
154
160
  }
155
- const _ = vt(u, r).result;
156
- return _ && s.pushUndoRedo({
157
- unitID: o,
158
- undoMutations: v,
159
- redoMutations: u
160
- }), _;
161
- }
162
- }, Xe = {
161
+ const result = sequenceExecute(redos, commandService).result;
162
+ return result && undoRedoService.pushUndoRedo({
163
+ unitID: unitId,
164
+ undoMutations: undos,
165
+ redoMutations: redos
166
+ }), result;
167
+ }, "handler")
168
+ }, AddDecimalCommand = {
163
169
  id: "sheet.command.numfmt.add.decimal.command",
164
- type: D.COMMAND,
165
- handler: async (e) => {
166
- const t = e.get(O), r = e.get(U), n = e.get(H), s = e.get(w), i = r.getCurrentSelections();
167
- if (!i || !i.length)
170
+ type: CommandType.COMMAND,
171
+ handler: /* @__PURE__ */ __name(async (accessor) => {
172
+ const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), selections = selectionManagerService.getCurrentSelections();
173
+ if (!selections || !selections.length)
168
174
  return !1;
169
- const o = xe(s);
170
- if (!o) return !1;
171
- const { unitId: c, subUnitId: a } = o;
172
- let f = 0;
173
- i.forEach((v) => {
174
- R.foreach(v.range, (_, h) => {
175
- const g = n.getValue(c, a, _, h);
176
- if (!g)
175
+ const target = getSheetCommandTarget(univerInstanceService);
176
+ if (!target) return !1;
177
+ const { unitId, subUnitId } = target;
178
+ let maxDecimals = 0;
179
+ selections.forEach((selection) => {
180
+ Range.foreach(selection.range, (row, col) => {
181
+ const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
182
+ if (!numfmtValue)
177
183
  return;
178
- const p = j(g.pattern);
179
- f = p > f ? p : f;
184
+ const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
185
+ maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
180
186
  });
181
187
  });
182
- const m = f + 1, l = y(`0${m > 0 ? ".0" : ""}`, m), u = [];
183
- return i.forEach((v) => {
184
- R.foreach(v.range, (_, h) => {
185
- const g = n.getValue(c, a, _, h);
186
- if (!g)
187
- u.push({
188
- row: _,
189
- col: h,
190
- pattern: l
188
+ const decimals = maxDecimals + 1, defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : ""}`, decimals), values = [];
189
+ return selections.forEach((selection) => {
190
+ Range.foreach(selection.range, (row, col) => {
191
+ const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
192
+ if (!numfmtValue)
193
+ values.push({
194
+ row,
195
+ col,
196
+ pattern: defaultPattern
191
197
  });
192
198
  else {
193
- const p = j(g.pattern), S = y(g.pattern, p + 1);
194
- S !== g.pattern && u.push({
195
- row: _,
196
- col: h,
197
- pattern: S
199
+ const decimals2 = getDecimalFromPattern(numfmtValue.pattern), pattern = setPatternDecimal(numfmtValue.pattern, decimals2 + 1);
200
+ pattern !== numfmtValue.pattern && values.push({
201
+ row,
202
+ col,
203
+ pattern
198
204
  });
199
205
  }
200
206
  });
201
- }), u.length ? await t.executeCommand($.id, { values: u }) : !1;
202
- }
203
- }, en = [
207
+ }), values.length ? await commandService.executeCommand(SetNumfmtCommand.id, { values }) : !1;
208
+ }, "handler")
209
+ }, DATEFMTLISG = [
204
210
  {
205
211
  label: "1930-08-05",
206
212
  suffix: "yyyy-MM-dd"
@@ -245,7 +251,7 @@ const j = (e, t = 0) => {
245
251
  label: "08-05 下午 01:30",
246
252
  suffix: "MM-dd A/P hh:mm"
247
253
  }
248
- ], tn = [
254
+ ], NUMBERFORMAT = [
249
255
  {
250
256
  label: "(1,235)",
251
257
  suffix: "#,##0_);(#,##0)"
@@ -273,104 +279,104 @@ const j = (e, t = 0) => {
273
279
  suffix: "#,##0.00_);[Red]-#,##0.00",
274
280
  color: "red"
275
281
  }
276
- ], Ze = [
282
+ ], CURRENCYFORMAT = [
277
283
  {
278
- label: (e) => `${e}1,235`,
279
- suffix: (e) => `"${e}"#,##0.00_);"${e}"#,##0.00`
284
+ label: /* @__PURE__ */ __name((suffix) => `${suffix}1,235`, "label"),
285
+ suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);"${suffix}"#,##0.00`, "suffix")
280
286
  },
281
287
  {
282
- label: (e) => `${e}1,235`,
283
- suffix: (e) => `"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,
288
+ label: /* @__PURE__ */ __name((suffix) => `${suffix}1,235`, "label"),
289
+ suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]"${suffix}"#,##0.00`, "suffix"),
284
290
  color: "red"
285
291
  },
286
292
  {
287
- label: (e) => `(${e}1,235)`,
288
- suffix: (e) => `"${e}"#,##0.00_);("${e}"#,##0.00)`
293
+ label: /* @__PURE__ */ __name((suffix) => `(${suffix}1,235)`, "label"),
294
+ suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);("${suffix}"#,##0.00)`, "suffix")
289
295
  },
290
296
  {
291
- label: (e) => `(${e}1,235)`,
292
- suffix: (e) => `"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,
297
+ label: /* @__PURE__ */ __name((suffix) => `(${suffix}1,235)`, "label"),
298
+ suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]("${suffix}"#,##0.00)`, "suffix"),
293
299
  color: "red"
294
300
  },
295
301
  {
296
- label: (e) => `-${e}1,235`,
297
- suffix: (e) => `"${e}"#,##0.00_);-"${e}"#,##0.00`
302
+ label: /* @__PURE__ */ __name((suffix) => `-${suffix}1,235`, "label"),
303
+ suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);-"${suffix}"#,##0.00`, "suffix")
298
304
  },
299
305
  {
300
- label: (e) => `-${e}1,235`,
301
- suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
306
+ label: /* @__PURE__ */ __name((suffix) => `-${suffix}1,235`, "label"),
307
+ suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`, "suffix"),
302
308
  color: "red"
303
309
  }
304
- ], Qe = {
310
+ ], SetCurrencyCommand = {
305
311
  id: "sheet.command.numfmt.set.currency",
306
- type: D.COMMAND,
307
- handler: async (e) => {
308
- const t = e.get(O), n = e.get(U).getCurrentSelections();
309
- if (!n || !n.length)
312
+ type: CommandType.COMMAND,
313
+ handler: /* @__PURE__ */ __name(async (accessor) => {
314
+ const commandService = accessor.get(ICommandService), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
315
+ if (!selections || !selections.length)
310
316
  return !1;
311
- const s = [], i = Ze[0].suffix("¥");
312
- return n.forEach((c) => {
313
- R.foreach(c.range, (a, f) => {
314
- s.push({ row: a, col: f, pattern: i, type: "currency" });
317
+ const values = [], suffix = CURRENCYFORMAT[0].suffix("¥");
318
+ return selections.forEach((selection) => {
319
+ Range.foreach(selection.range, (row, col) => {
320
+ values.push({ row, col, pattern: suffix, type: "currency" });
315
321
  });
316
- }), await t.executeCommand($.id, { values: s });
317
- }
318
- }, et = {
322
+ }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
323
+ }, "handler")
324
+ }, SubtractDecimalCommand = {
319
325
  id: "sheet.command.numfmt.subtract.decimal.command",
320
- type: D.COMMAND,
321
- handler: async (e) => {
322
- const t = e.get(O), r = e.get(U), n = e.get(H), s = e.get(w), i = r.getCurrentSelections();
323
- if (!i || !i.length)
326
+ type: CommandType.COMMAND,
327
+ handler: /* @__PURE__ */ __name(async (accessor) => {
328
+ const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), selections = selectionManagerService.getCurrentSelections();
329
+ if (!selections || !selections.length)
324
330
  return !1;
325
- const o = xe(s);
326
- if (!o) return !1;
327
- const { unitId: c, subUnitId: a } = o;
328
- let f = 0;
329
- i.forEach((_) => {
330
- R.foreach(_.range, (h, g) => {
331
- const p = n.getValue(c, a, h, g);
332
- if (!p)
331
+ const target = getSheetCommandTarget(univerInstanceService);
332
+ if (!target) return !1;
333
+ const { unitId, subUnitId } = target;
334
+ let maxDecimals = 0;
335
+ selections.forEach((selection) => {
336
+ Range.foreach(selection.range, (row, col) => {
337
+ const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
338
+ if (!numfmtValue)
333
339
  return;
334
- const S = j(p.pattern);
335
- f = S > f ? S : f;
340
+ const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
341
+ maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
336
342
  });
337
343
  });
338
- const m = f - 1, l = y(`0${m > 0 ? ".0" : "."}`, m), u = [];
339
- return i.forEach((_) => {
340
- R.foreach(_.range, (h, g) => {
341
- const p = n.getValue(c, a, h, g);
342
- if (!p)
343
- u.push({
344
- row: h,
345
- col: g,
346
- pattern: l
344
+ const decimals = maxDecimals - 1, defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : "."}`, decimals), values = [];
345
+ return selections.forEach((selection) => {
346
+ Range.foreach(selection.range, (row, col) => {
347
+ const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
348
+ if (!numfmtValue)
349
+ values.push({
350
+ row,
351
+ col,
352
+ pattern: defaultPattern
347
353
  });
348
354
  else {
349
- const S = j(p.pattern);
350
- u.push({
351
- row: h,
352
- col: g,
353
- pattern: y(p.pattern, S - 1)
355
+ const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
356
+ values.push({
357
+ row,
358
+ col,
359
+ pattern: setPatternDecimal(numfmtValue.pattern, decimals2 - 1)
354
360
  });
355
361
  }
356
362
  });
357
- }), await t.executeCommand($.id, { values: u });
358
- }
359
- }, ye = {
363
+ }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
364
+ }, "handler")
365
+ }, CloseNumfmtPanelOperator = {
360
366
  id: "sheet.operation.close.numfmt.panel",
361
- type: D.OPERATION,
362
- handler: () => (
367
+ type: CommandType.OPERATION,
368
+ handler: /* @__PURE__ */ __name(() => (
363
369
  // do nothing,just notify panel is closed
364
370
  !0
365
- )
366
- }, Ue = _t("INumfmtController");
367
- gt(B.Rendered, Ue);
368
- const he = {
371
+ ), "handler")
372
+ }, INumfmtController = createIdentifier("INumfmtController");
373
+ runOnLifecycle(LifecycleStages.Rendered, INumfmtController);
374
+ const OpenNumfmtPanelOperator = {
369
375
  id: "sheet.operation.open.numfmt.panel",
370
- type: D.OPERATION,
371
- handler: (e) => (e.get(Ue).openPanel(), !0)
376
+ type: CommandType.OPERATION,
377
+ handler: /* @__PURE__ */ __name((accessor) => (accessor.get(INumfmtController).openPanel(), !0), "handler")
372
378
  };
373
- var tt = { exports: {} }, Se = {};
379
+ var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
374
380
  /**
375
381
  * @license React
376
382
  * react-jsx-runtime.production.min.js
@@ -380,20 +386,21 @@ var tt = { exports: {} }, Se = {};
380
386
  * This source code is licensed under the MIT license found in the
381
387
  * LICENSE file in the root directory of this source tree.
382
388
  */
383
- var nn = Kt, rn = Symbol.for("react.element"), sn = Symbol.for("react.fragment"), on = Object.prototype.hasOwnProperty, cn = nn.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, an = { key: !0, ref: !0, __self: !0, __source: !0 };
384
- function nt(e, t, r) {
385
- var n, s = {}, i = null, o = null;
386
- r !== void 0 && (i = "" + r), t.key !== void 0 && (i = "" + t.key), t.ref !== void 0 && (o = t.ref);
387
- for (n in t) on.call(t, n) && !an.hasOwnProperty(n) && (s[n] = t[n]);
388
- if (e && e.defaultProps) for (n in t = e.defaultProps, t) s[n] === void 0 && (s[n] = t[n]);
389
- return { $$typeof: rn, type: e, key: i, ref: o, props: s, _owner: cn.current };
389
+ 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 };
390
+ function q(c, a, g) {
391
+ var b, d = {}, e = null, h = null;
392
+ g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
393
+ for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
394
+ if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
395
+ return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
390
396
  }
391
- Se.Fragment = sn;
392
- Se.jsx = nt;
393
- Se.jsxs = nt;
394
- tt.exports = Se;
395
- var d = tt.exports;
396
- const Ae = Yt([]), Me = [
397
+ __name(q, "q");
398
+ reactJsxRuntime_production_min.Fragment = l;
399
+ reactJsxRuntime_production_min.jsx = q;
400
+ reactJsxRuntime_production_min.jsxs = q;
401
+ jsxRuntime.exports = reactJsxRuntime_production_min;
402
+ var jsxRuntimeExports = jsxRuntime.exports;
403
+ const UserHabitCurrencyContext = createContext([]), currencySymbols = [
397
404
  "$",
398
405
  "£",
399
406
  "¥",
@@ -422,259 +429,362 @@ const Ae = Yt([]), Me = [
422
429
  "₾",
423
430
  "₿"
424
431
  ];
425
- var ln = Object.defineProperty, un = Object.getOwnPropertyDescriptor, mn = (e, t, r, n) => {
426
- for (var s = n > 1 ? void 0 : n ? un(t, r) : t, i = e.length - 1, o; i >= 0; i--)
427
- (o = e[i]) && (s = (n ? o(t, r, s) : o(s)) || s);
428
- return n && s && ln(t, r, s), s;
429
- }, dn = (e, t) => (r, n) => t(r, n, e);
430
- let pe = class {
431
- constructor(e) {
432
- this._localStorageService = e;
432
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
433
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
434
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
435
+ return kind && result && __defProp$5(target, key2, result), result;
436
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$5"), _a2;
437
+ let UserHabitController = (_a2 = class {
438
+ constructor(_localStorageService) {
439
+ this._localStorageService = _localStorageService;
433
440
  }
434
- _getKey(e) {
435
- return `userHabitController_${e}`;
441
+ _getKey(habit) {
442
+ return `userHabitController_${habit}`;
436
443
  }
437
- async addHabit(e, t) {
438
- const r = this._getKey(e);
439
- return this._localStorageService.getItem(r).then((n) => {
440
- n || this._localStorageService.setItem(r, t);
444
+ async addHabit(habit, initValue) {
445
+ const key2 = this._getKey(habit);
446
+ return this._localStorageService.getItem(key2).then((item) => {
447
+ item || this._localStorageService.setItem(key2, initValue);
441
448
  });
442
449
  }
443
- markHabit(e, t) {
444
- const r = this._getKey(e);
445
- this._localStorageService.getItem(r).then((n) => {
446
- if (n) {
447
- const s = n.findIndex((i) => i === t);
448
- s > -1 && n.splice(s, 1), n.unshift(t), this._localStorageService.setItem(r, n);
450
+ markHabit(habit, value) {
451
+ const key2 = this._getKey(habit);
452
+ this._localStorageService.getItem(key2).then((list) => {
453
+ if (list) {
454
+ const index = list.findIndex((item) => item === value);
455
+ index > -1 && list.splice(index, 1), list.unshift(value), this._localStorageService.setItem(key2, list);
449
456
  }
450
457
  });
451
458
  }
452
- async getHabit(e, t) {
453
- const r = this._getKey(e), n = await this._localStorageService.getItem(r);
454
- if (t && n) {
455
- const s = n.map((i, o, c) => {
456
- const a = c.length;
459
+ async getHabit(habit, sortList) {
460
+ const key2 = this._getKey(habit), result = await this._localStorageService.getItem(key2);
461
+ if (sortList && result) {
462
+ const priority = result.map((item, index, arr) => {
463
+ const length = arr.length;
457
464
  return {
458
- value: i,
459
- priority: a - o
465
+ value: item,
466
+ priority: length - index
460
467
  };
461
468
  });
462
- return t.sort((i, o) => {
463
- var f, m;
464
- const c = ((f = s.find((l) => l.value === i)) == null ? void 0 : f.priority) || -1;
465
- return (((m = s.find((l) => l.value === o)) == null ? void 0 : m.priority) || -1) - c;
469
+ return sortList.sort((a, b) => {
470
+ var _a8, _b;
471
+ const ap = ((_a8 = priority.find((item) => item.value === a)) == null ? void 0 : _a8.priority) || -1;
472
+ return (((_b = priority.find((item) => item.value === b)) == null ? void 0 : _b.priority) || -1) - ap;
466
473
  });
467
474
  }
468
- return n || [];
475
+ return result || [];
469
476
  }
470
- deleteHabit(e) {
471
- this._localStorageService.removeItem(e);
477
+ deleteHabit(habit) {
478
+ this._localStorageService.removeItem(habit);
472
479
  }
473
- };
474
- pe = mn([
475
- dn(0, b(St))
476
- ], pe);
477
- const Fe = "numfmtCurrency", fn = (e) => {
478
- const t = N(pe), [r, n] = I(Me);
479
- return Oe(() => {
480
- t.addHabit("numfmtCurrency", []).then(() => {
481
- t.getHabit(Fe, [...Me]).then((i) => {
482
- n(i), e && e(i);
480
+ }, __name(_a2, "UserHabitController"), _a2);
481
+ UserHabitController = __decorateClass$5([
482
+ __decorateParam$5(0, Inject(ILocalStorageService))
483
+ ], UserHabitController);
484
+ const key$1 = "numfmtCurrency", useCurrencyOptions = /* @__PURE__ */ __name((onOptionChange) => {
485
+ const userHabitController = useDependency(UserHabitController), [options, optionsSet] = useState(currencySymbols);
486
+ return useEffect(() => {
487
+ userHabitController.addHabit("numfmtCurrency", []).then(() => {
488
+ userHabitController.getHabit(key$1, [...currencySymbols]).then((list) => {
489
+ optionsSet(list), onOptionChange && onOptionChange(list);
483
490
  });
484
491
  });
485
- }, []), { userHabitCurrency: r, mark: (i) => {
486
- t.markHabit(Fe, i);
487
- } };
488
- }, hn = () => {
489
- const e = qe([]), [t, r] = I({});
490
- return Oe(() => {
491
- e.current.forEach((s) => {
492
- s();
493
- }), e.current = [];
494
- }, [t]), (s) => {
495
- e.current.push(s), r({});
496
- };
497
- }, ie = (e) => Me.find((r) => e.includes(r)), pn = (e) => !!ie(e) && e.startsWith("_("), vn = (e) => {
498
- const [t, r] = I(() => j(e.defaultPattern || "", 2)), n = Je(Ae), [s, i] = I(() => ie(e.defaultPattern) || n[0]), o = P(() => n.map((l) => ({ label: l, value: l })), []), a = N(E).t;
499
- e.action.current = () => y(`_("${s}"* #,##0${t > 0 ? ".0" : ""}_)`, t);
500
- const f = (l) => {
501
- i(l), e.onChange(y(`_("${l}"* #,##0${t > 0 ? ".0" : ""}_)`, t));
502
- }, m = (l) => {
503
- const u = l || 0;
504
- r(u), e.onChange(y(`_("${s}"* #,##0${u > 0 ? ".0" : ""}_)`, u));
505
- };
506
- return /* @__PURE__ */ d.jsxs("div", { children: [
507
- /* @__PURE__ */ d.jsxs("div", { className: "m-t-16 options ", children: [
508
- /* @__PURE__ */ d.jsxs("div", { className: "option", children: [
509
- /* @__PURE__ */ d.jsx("div", { className: "label", children: a("sheet.numfmt.decimalLength") }),
510
- /* @__PURE__ */ d.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ d.jsx(je, { value: t, max: 20, min: 0, onChange: m }) })
492
+ }, []), { userHabitCurrency: options, mark: /* @__PURE__ */ __name((v) => {
493
+ userHabitController.markHabit(key$1, v);
494
+ }, "mark") };
495
+ }, "useCurrencyOptions"), useNextTick = /* @__PURE__ */ __name(() => {
496
+ const effectList = useRef([]), [value, dispatch] = useState({});
497
+ return useEffect(() => {
498
+ effectList.current.forEach((fn) => {
499
+ fn();
500
+ }), effectList.current = [];
501
+ }, [value]), /* @__PURE__ */ __name((fn) => {
502
+ effectList.current.push(fn), dispatch({});
503
+ }, "nextTick");
504
+ }, "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) => {
505
+ 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;
506
+ props.action.current = () => setPatternDecimal(`_("${suffix}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal);
507
+ const onSelect = /* @__PURE__ */ __name((v) => {
508
+ suffixSet(v), props.onChange(setPatternDecimal(`_("${v}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal));
509
+ }, "onSelect"), onDecimalChange = /* @__PURE__ */ __name((v) => {
510
+ const decimal2 = v || 0;
511
+ decimalSet(decimal2), props.onChange(setPatternDecimal(`_("${suffix}"* #,##0${decimal2 > 0 ? ".0" : ""}_)`, decimal2));
512
+ }, "onDecimalChange");
513
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
514
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 options ", children: [
515
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
516
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.decimalLength") }),
517
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ jsxRuntimeExports.jsx(InputNumber, { value: decimal, max: 20, min: 0, onChange: onDecimalChange }) })
511
518
  ] }),
512
- /* @__PURE__ */ d.jsxs("div", { className: "option", children: [
513
- /* @__PURE__ */ d.jsx("div", { className: "label", children: a("sheet.numfmt.currencyType") }),
514
- /* @__PURE__ */ d.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ d.jsx($e, { onChange: f, options: o, value: s }) })
519
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
520
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.currencyType") }),
521
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: onSelect, options, value: suffix }) })
515
522
  ] })
516
523
  ] }),
517
- /* @__PURE__ */ d.jsx("div", { className: "describe m-t-14", children: a("sheet.numfmt.accountingDes") })
524
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.accountingDes") })
518
525
  ] });
519
- }, Te = (e) => Ze.map((t) => ({
520
- label: t.label(e),
521
- value: t.suffix(e),
522
- color: t.color
523
- })), rt = () => en.map((e) => ({ label: e.label, value: e.suffix })), st = () => tn.map((e) => ({ label: e.label, value: e.suffix, color: e.color })), _n = (e) => !!ie(e) && !e.startsWith("_("), gn = (e) => {
524
- const r = N(E).t, n = Je(Ae), [s, i] = I(() => ie(e.defaultPattern) || n[0]), [o, c] = I(() => j(e.defaultPattern || "", 2)), [a, f] = I(() => {
525
- var p;
526
- const h = Te(s);
527
- return ((p = h.find((S) => ge(S.value, e.defaultPattern))) == null ? void 0 : p.value) || h[0].value;
528
- }), m = P(() => Te(s), [s]), l = P(() => n.map((h) => ({ label: h, value: h })), [n]);
529
- e.action.current = () => y(a, o);
530
- const u = (h) => {
531
- if (h === void 0)
526
+ }, "AccountingPanel"), getCurrencyFormatOptions = /* @__PURE__ */ __name((suffix) => CURRENCYFORMAT.map((item) => ({
527
+ label: item.label(suffix),
528
+ value: item.suffix(suffix),
529
+ color: item.color
530
+ })), "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) => {
531
+ 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(() => {
532
+ var _a8;
533
+ const negativeOptions2 = getCurrencyFormatOptions(suffix);
534
+ return ((_a8 = negativeOptions2.find((item) => isPatternEqualWithoutDecimal(item.value, props.defaultPattern))) == null ? void 0 : _a8.value) || negativeOptions2[0].value;
535
+ }), negativeOptions = useMemo(() => getCurrencyFormatOptions(suffix), [suffix]), options = useMemo(() => userHabitCurrency.map((key2) => ({ label: key2, value: key2 })), [userHabitCurrency]);
536
+ props.action.current = () => setPatternDecimal(pattern, decimal);
537
+ const onSelect = /* @__PURE__ */ __name((value) => {
538
+ if (value === void 0)
532
539
  return;
533
- i(h);
534
- const g = Te(h)[0].value;
535
- f(g), e.onChange(y(g, o));
536
- }, v = (h) => {
537
- h !== void 0 && (f(h), e.onChange(y(h, o)));
538
- }, _ = (h) => {
539
- c(h || 0), e.onChange(y(a, h || 0));
540
- };
541
- return /* @__PURE__ */ d.jsxs("div", { children: [
542
- /* @__PURE__ */ d.jsxs("div", { className: "m-t-16 options ", children: [
543
- /* @__PURE__ */ d.jsxs("div", { className: "option", children: [
544
- /* @__PURE__ */ d.jsx("div", { className: "label", children: r("sheet.numfmt.decimalLength") }),
545
- /* @__PURE__ */ d.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ d.jsx(je, { value: o, max: 20, min: 0, onChange: _ }) })
540
+ suffixSet(value);
541
+ const pattern2 = getCurrencyFormatOptions(value)[0].value;
542
+ patternSet(pattern2), props.onChange(setPatternDecimal(pattern2, decimal));
543
+ }, "onSelect"), onChange = /* @__PURE__ */ __name((value) => {
544
+ value !== void 0 && (patternSet(value), props.onChange(setPatternDecimal(value, decimal)));
545
+ }, "onChange"), onDecimalChange = /* @__PURE__ */ __name((v) => {
546
+ decimalSet(v || 0), props.onChange(setPatternDecimal(pattern, v || 0));
547
+ }, "onDecimalChange");
548
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
549
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 options ", children: [
550
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
551
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.decimalLength") }),
552
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ jsxRuntimeExports.jsx(InputNumber, { value: decimal, max: 20, min: 0, onChange: onDecimalChange }) })
546
553
  ] }),
547
- /* @__PURE__ */ d.jsxs("div", { className: "option", children: [
548
- /* @__PURE__ */ d.jsx("div", { className: "label", children: r("sheet.numfmt.currencyType") }),
549
- /* @__PURE__ */ d.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ d.jsx($e, { onChange: u, options: l, value: s }) })
554
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
555
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.currencyType") }),
556
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: onSelect, options, value: suffix }) })
550
557
  ] })
551
558
  ] }),
552
- /* @__PURE__ */ d.jsx("div", { className: "m-t-16 label", children: r("sheet.numfmt.negType") }),
553
- /* @__PURE__ */ d.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ d.jsx(we, { onChange: v, options: m, value: a }) }),
554
- /* @__PURE__ */ d.jsx("div", { className: "describe m-t-14", children: r("sheet.numfmt.currencyDes") })
559
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.negType") }),
560
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange, options: negativeOptions, value: pattern }) }),
561
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.currencyDes") })
555
562
  ] });
556
- }, Sn = (e) => {
557
- const t = x.getInfo(e);
558
- return rt().map((r) => r.value).includes(e) || ["date", "datetime", "time"].includes(t.type);
559
- }, bn = (e) => {
560
- const t = P(rt, []), n = N(E).t, [s, i] = I(() => {
561
- if (e.defaultPattern) {
562
- const c = t.find((a) => a.value === e.defaultPattern);
563
- if (c)
564
- return c.value;
563
+ }, "CurrencyPanel"), isDatePanel = /* @__PURE__ */ __name((pattern) => {
564
+ const info = numfmt.getInfo(pattern);
565
+ return getDateFormatOptions().map((item) => item.value).includes(pattern) || ["date", "datetime", "time"].includes(info.type);
566
+ }, "isDatePanel"), DatePanel = /* @__PURE__ */ __name((props) => {
567
+ const options = useMemo(getDateFormatOptions, []), t = useDependency(LocaleService).t, [suffix, suffixSet] = useState(() => {
568
+ if (props.defaultPattern) {
569
+ const item = options.find((item2) => item2.value === props.defaultPattern);
570
+ if (item)
571
+ return item.value;
565
572
  }
566
- return t[0].value;
573
+ return options[0].value;
567
574
  });
568
- e.action.current = () => s;
569
- const o = (c) => {
570
- c !== void 0 && (i(c), e.onChange(c));
571
- };
572
- return /* @__PURE__ */ d.jsxs("div", { children: [
573
- /* @__PURE__ */ d.jsx("div", { className: "m-t-16 label", children: n("sheet.numfmt.dateType") }),
574
- /* @__PURE__ */ d.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ d.jsx(we, { value: s, options: t, onChange: o }) }),
575
- /* @__PURE__ */ d.jsx("div", { className: "describe m-t-14", children: n("sheet.numfmt.dateDes") })
575
+ props.action.current = () => suffix;
576
+ const onChange = /* @__PURE__ */ __name((v) => {
577
+ v !== void 0 && (suffixSet(v), props.onChange(v));
578
+ }, "onChange");
579
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
580
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.dateType") }),
581
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { value: suffix, options, onChange }) }),
582
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.dateDes") })
576
583
  ] });
577
- }, Cn = (e) => !e, yn = (e) => {
578
- const r = N(E).t;
579
- return e.action.current = () => "", /* @__PURE__ */ d.jsx("div", { children: /* @__PURE__ */ d.jsx("div", { className: "describe m-t-14", children: r("sheet.numfmt.generalDes") }) });
580
- }, Tn = (e) => st().some((t) => ge(t.value, e)), In = (e) => {
581
- const t = N(E), r = P(st, []), [n, s] = I(() => j(e.defaultPattern || "", 0)), [i, o] = I(() => {
582
- const l = r.find((u) => ge(u.value, e.defaultPattern || ""));
583
- return (l == null ? void 0 : l.value) || r[0].value;
584
- }), c = P(() => y(i, Number(n || 0)), [i, n]), a = P(() => !Qt(i), [i]), f = (l) => {
585
- s(l || 0), e.onChange(y(i, Number(l || 0)));
586
- }, m = (l) => {
587
- l !== void 0 && (s(j(l, 0)), o(l), e.onChange(l));
588
- };
589
- return e.action.current = () => c, /* @__PURE__ */ d.jsxs("div", { children: [
590
- /* @__PURE__ */ d.jsx("div", { className: "m-t-16 label", children: t.t("sheet.numfmt.decimalLength") }),
591
- /* @__PURE__ */ d.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ d.jsx(
592
- je,
584
+ }, "DatePanel"), isGeneralPanel = /* @__PURE__ */ __name((pattern) => !pattern, "isGeneralPanel"), GeneralPanel = /* @__PURE__ */ __name((props) => {
585
+ const t = useDependency(LocaleService).t;
586
+ return props.action.current = () => "", /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.generalDes") }) });
587
+ }, "GeneralPanel"), isThousandthPercentilePanel = /* @__PURE__ */ __name((pattern) => getNumberFormatOptions().some((item) => isPatternEqualWithoutDecimal(item.value, pattern)), "isThousandthPercentilePanel"), ThousandthPercentilePanel = /* @__PURE__ */ __name((props) => {
588
+ const localeService = useDependency(LocaleService), options = useMemo(getNumberFormatOptions, []), [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 0)), [suffix, suffixSet] = useState(() => {
589
+ const item = options.find((item2) => isPatternEqualWithoutDecimal(item2.value, props.defaultPattern || ""));
590
+ return (item == null ? void 0 : item.value) || options[0].value;
591
+ }), pattern = useMemo(() => setPatternDecimal(suffix, Number(decimal || 0)), [suffix, decimal]), isInputDisable = useMemo(() => !isPatternHasDecimal(suffix), [suffix]), handleDecimalChange = /* @__PURE__ */ __name((decimal2) => {
592
+ decimalSet(decimal2 || 0), props.onChange(setPatternDecimal(suffix, Number(decimal2 || 0)));
593
+ }, "handleDecimalChange"), handleClick = /* @__PURE__ */ __name((v) => {
594
+ v !== void 0 && (decimalSet(getDecimalFromPattern(v, 0)), suffixSet(v), props.onChange(v));
595
+ }, "handleClick");
596
+ return props.action.current = () => pattern, /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
597
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: localeService.t("sheet.numfmt.decimalLength") }),
598
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
599
+ InputNumber,
593
600
  {
594
- disabled: a,
595
- value: n,
601
+ disabled: isInputDisable,
602
+ value: decimal,
596
603
  max: 20,
597
604
  min: 0,
598
- onChange: f
605
+ onChange: handleDecimalChange
599
606
  }
600
607
  ) }),
601
- /* @__PURE__ */ d.jsxs("div", { className: "m-t-16 label", children: [
608
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 label", children: [
602
609
  " ",
603
- t.t("sheet.numfmt.negType")
610
+ localeService.t("sheet.numfmt.negType")
604
611
  ] }),
605
- /* @__PURE__ */ d.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ d.jsx(we, { onChange: m, options: r, value: i }) }),
606
- /* @__PURE__ */ d.jsx("div", { className: "describe m-t-14", children: t.t("sheet.numfmt.thousandthPercentileDes") })
612
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange: handleClick, options, value: suffix }) }),
613
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: localeService.t("sheet.numfmt.thousandthPercentileDes") })
614
+ ] });
615
+ }, "ThousandthPercentilePanel");
616
+ var __assign = function() {
617
+ return __assign = Object.assign || function(t) {
618
+ for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
619
+ s = arguments[i];
620
+ for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && (t[p2] = s[p2]);
621
+ }
622
+ return t;
623
+ }, __assign.apply(this, arguments);
624
+ }, __rest = function(s, e) {
625
+ var t = {};
626
+ for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0 && (t[p2] = s[p2]);
627
+ if (s != null && typeof Object.getOwnPropertySymbols == "function")
628
+ for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++)
629
+ e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i]) && (t[p2[i]] = s[p2[i]]);
630
+ return t;
631
+ }, IconBase = forwardRef(function(props, ref) {
632
+ 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()));
633
+ return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
634
+ });
635
+ function render(node, id, runtimeProps, rootProps, extend) {
636
+ return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
637
+ return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
638
+ }));
639
+ }
640
+ __name(render, "render");
641
+ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
642
+ var attrs = __assign({}, node.attrs);
643
+ extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
644
+ var defIds = runtimeProps.defIds;
645
+ return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a8) {
646
+ var key2 = _a8[0], value = _a8[1];
647
+ typeof value == "string" && (attrs[key2] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
648
+ })), attrs;
649
+ }
650
+ __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
651
+ function replaceRuntimeIdsInDefs(node, runtimeProps) {
652
+ var _a8, defIds = runtimeProps.defIds;
653
+ return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a8 = node.children) === null || _a8 === void 0) && _a8.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
654
+ 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;
655
+ }) }) : node;
656
+ }
657
+ __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
658
+ function generateShortUuid() {
659
+ return Math.random().toString(36).substring(2, 8);
660
+ }
661
+ __name(generateShortUuid, "generateShortUuid");
662
+ IconBase.displayName = "UniverIcon";
663
+ 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) {
664
+ return createElement(IconBase, Object.assign({}, props, {
665
+ id: "check-mark-single",
666
+ ref,
667
+ icon: element
668
+ }));
669
+ });
670
+ CheckMarkSingle.displayName = "CheckMarkSingle";
671
+ 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 = {
672
+ customFormatTitle,
673
+ customFormatInput,
674
+ customFormatHistoryList,
675
+ customFormatHistoryListItem,
676
+ customFormatHistoryListItemIconWrap,
677
+ customFormatDes
678
+ }, key = "customFormat", historyPatternKey = "numfmt_custom_pattern";
679
+ function CustomFormat(props) {
680
+ const { defaultPattern, action, onChange } = props, userHabitController = useDependency(UserHabitController), localStorageService = useDependency(ILocalStorageService), localeService = useDependency(LocaleService), [pattern, patternSet] = useState(defaultPattern);
681
+ action.current = () => (userHabitController.markHabit(key, pattern), localStorageService.getItem(historyPatternKey).then((list = []) => {
682
+ const _list = [.../* @__PURE__ */ new Set([pattern, ...list || []])].splice(0, 10).filter((e) => !!e);
683
+ localStorageService.setItem(historyPatternKey, _list);
684
+ }), pattern);
685
+ const [options, optionsSet] = useState([]);
686
+ useEffect(() => {
687
+ localStorageService.getItem(historyPatternKey).then((historyList) => {
688
+ const list = [
689
+ ...CURRENCYFORMAT.map((item) => item.suffix("$")),
690
+ ...DATEFMTLISG.map((item) => item.suffix),
691
+ ...NUMBERFORMAT.map((item) => item.suffix)
692
+ ];
693
+ list.push(...historyList || []), userHabitController.addHabit(key, []).finally(() => {
694
+ userHabitController.getHabit(key, list).then((list2) => {
695
+ optionsSet([...new Set(list2)]);
696
+ });
697
+ });
698
+ });
699
+ }, []);
700
+ const handleClick = /* @__PURE__ */ __name((p2) => {
701
+ patternSet(p2), onChange(p2);
702
+ }, "handleClick"), handleBlur = /* @__PURE__ */ __name(() => {
703
+ onChange(pattern);
704
+ }, "handleBlur");
705
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.customFormat, children: [
706
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatTitle, children: localeService.t("sheet.numfmt.customFormat") }),
707
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { placeholder: localeService.t("sheet.numfmt.customFormat"), onBlur: handleBlur, value: pattern, onChange: patternSet, className: styles.customFormatInput }),
708
+ /* @__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: [
709
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatHistoryListItemIconWrap, children: pattern === p2 && /* @__PURE__ */ jsxRuntimeExports.jsx(CheckMarkSingle, {}) }),
710
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: p2 })
711
+ ] }, p2)) }),
712
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatDes, children: localeService.t("sheet.numfmt.customFormatDes") })
607
713
  ] });
608
- }, En = (e) => {
609
- const { defaultValue: t, defaultPattern: r, row: n, col: s } = e.value, i = N(E), o = qe(() => ""), c = i.t, a = hn(), f = P(
714
+ }
715
+ __name(CustomFormat, "CustomFormat");
716
+ const SheetNumfmtPanel = /* @__PURE__ */ __name((props) => {
717
+ const { defaultValue, defaultPattern, row, col } = props.value, localeService = useDependency(LocaleService), getCurrentPattern = useRef(() => ""), t = localeService.t, nextTick = useNextTick(), typeOptions = useMemo(
610
718
  () => [
611
- { label: "sheet.numfmt.general", component: yn },
612
- { label: "sheet.numfmt.accounting", component: vn },
613
- { label: "sheet.numfmt.currency", component: gn },
614
- { label: "sheet.numfmt.date", component: bn },
615
- { label: "sheet.numfmt.thousandthPercentile", component: In }
616
- ].map((C) => ({ ...C, label: c(C.label) })),
719
+ { label: "sheet.numfmt.general", component: GeneralPanel },
720
+ { label: "sheet.numfmt.accounting", component: AccountingPanel },
721
+ { label: "sheet.numfmt.currency", component: CurrencyPanel },
722
+ { label: "sheet.numfmt.date", component: DatePanel },
723
+ { label: "sheet.numfmt.thousandthPercentile", component: ThousandthPercentilePanel },
724
+ { label: "sheet.numfmt.customFormat", component: CustomFormat }
725
+ ].map((item) => ({ ...item, label: t(item.label) })),
617
726
  []
618
- ), [m, l] = I(p), [u, v] = I(() => `${n}_${s}`), { mark: _, userHabitCurrency: h } = fn(() => v(`${n}_${s}_userCurrency'`)), g = P(() => {
619
- var C;
620
- return (C = f.find((A) => A.label === m)) == null ? void 0 : C.component;
621
- }, [m]);
622
- function p() {
623
- return [Cn, pn, _n, Sn, Tn].reduce((A, ut, mt) => A || (ut(r) ? f[mt].label : ""), "") || f[0].label;
727
+ ), [type, typeSet] = useState(findDefaultType), [key2, keySet] = useState(() => `${row}_${col}`), { mark, userHabitCurrency } = useCurrencyOptions(() => keySet(`${row}_${col}_userCurrency'`)), BusinessComponent = useMemo(() => {
728
+ var _a8;
729
+ return (_a8 = typeOptions.find((item) => item.label === type)) == null ? void 0 : _a8.component;
730
+ }, [type]);
731
+ function findDefaultType() {
732
+ return [isGeneralPanel, isAccountingPanel, isCurrencyPanel, isDatePanel, isThousandthPercentilePanel].reduce((pre, curFn, index) => pre || (curFn(defaultPattern) ? typeOptions[index].label : ""), "") || typeOptions[0].label;
624
733
  }
625
- const S = f.map((C) => ({
626
- label: C.label,
627
- value: C.label
628
- })), F = (C) => {
629
- l(C), a(() => e.onChange({ type: "change", value: o.current() || "" }));
630
- }, oe = (C) => {
631
- e.onChange({ type: "change", value: C });
632
- }, be = () => {
633
- const C = o.current() || "", A = ie(C);
634
- A && _(A), e.onChange({ type: "confirm", value: C });
635
- }, W = () => {
636
- e.onChange({ type: "cancel", value: "" });
637
- }, Ce = {
638
- onChange: oe,
639
- defaultValue: t,
640
- defaultPattern: r,
641
- action: o
734
+ __name(findDefaultType, "findDefaultType");
735
+ const selectOptions = typeOptions.map((option) => ({
736
+ label: option.label,
737
+ value: option.label
738
+ })), handleSelect = /* @__PURE__ */ __name((value) => {
739
+ typeSet(value), nextTick(() => props.onChange({ type: "change", value: getCurrentPattern.current() || "" }));
740
+ }, "handleSelect"), handleChange = /* @__PURE__ */ __name((v) => {
741
+ props.onChange({ type: "change", value: v });
742
+ }, "handleChange"), handleConfirm = /* @__PURE__ */ __name(() => {
743
+ const pattern = getCurrentPattern.current() || "", currency = getCurrencyType(pattern);
744
+ currency && mark(currency), props.onChange({ type: "confirm", value: pattern });
745
+ }, "handleConfirm"), handleCancel = /* @__PURE__ */ __name(() => {
746
+ props.onChange({ type: "cancel", value: "" });
747
+ }, "handleCancel"), subProps = {
748
+ onChange: handleChange,
749
+ defaultValue,
750
+ defaultPattern,
751
+ action: getCurrentPattern
642
752
  };
643
- return Oe(() => {
644
- l(p()), v(`${n}_${s}`);
645
- }, [n, s]), /* @__PURE__ */ d.jsxs("div", { className: "numfmt-panel p-b-20", children: [
646
- /* @__PURE__ */ d.jsxs("div", { children: [
647
- /* @__PURE__ */ d.jsx("div", { className: "label m-t-14", children: c("sheet.numfmt.numfmtType") }),
648
- /* @__PURE__ */ d.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ d.jsx($e, { onChange: F, options: S, value: m }) }),
649
- /* @__PURE__ */ d.jsx("div", { children: g && /* @__PURE__ */ d.jsx(Ae.Provider, { value: h, children: /* @__PURE__ */ qt(g, { ...Ce, key: u }) }) })
753
+ return useEffect(() => {
754
+ typeSet(findDefaultType()), keySet(`${row}_${col}`);
755
+ }, [row, col]), /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "numfmt-panel p-b-20", children: [
756
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
757
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label m-t-14", children: t("sheet.numfmt.numfmtType") }),
758
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: handleSelect, options: selectOptions, value: type, style: { width: "100%" } }) }),
759
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: BusinessComponent && /* @__PURE__ */ jsxRuntimeExports.jsx(UserHabitCurrencyContext.Provider, { value: userHabitCurrency, children: /* @__PURE__ */ createElement(BusinessComponent, { ...subProps, key: key2 }) }) })
650
760
  ] }),
651
- /* @__PURE__ */ d.jsxs("div", { className: "btn-list m-t-14 m-b-20", children: [
652
- /* @__PURE__ */ d.jsx(Be, { size: "small", onClick: W, className: "m-r-12", children: c("sheet.numfmt.cancel") }),
653
- /* @__PURE__ */ d.jsx(Be, { type: "primary", size: "small", onClick: be, children: c("sheet.numfmt.confirm") })
761
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "btn-list m-t-14 m-b-20", children: [
762
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "small", onClick: handleCancel, className: "m-r-12", children: t("sheet.numfmt.cancel") }),
763
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "primary", size: "small", onClick: handleConfirm, children: t("sheet.numfmt.confirm") })
654
764
  ] })
655
765
  ] });
656
- }, it = {
766
+ }, "SheetNumfmtPanel"), SetPercentCommand = {
657
767
  id: "sheet.command.numfmt.set.percent",
658
- type: D.COMMAND,
659
- handler: async (e) => {
660
- const t = e.get(O), n = e.get(U).getCurrentSelections();
661
- if (!n || !n.length)
768
+ type: CommandType.COMMAND,
769
+ handler: /* @__PURE__ */ __name(async (accessor) => {
770
+ const commandService = accessor.get(ICommandService), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
771
+ if (!selections || !selections.length)
662
772
  return !1;
663
- const s = [], i = "0%";
664
- return n.forEach((c) => {
665
- R.foreach(c.range, (a, f) => {
666
- s.push({ row: a, col: f, pattern: i, type: "percent" });
773
+ const values = [], suffix = "0%";
774
+ return selections.forEach((selection) => {
775
+ Range.foreach(selection.range, (row, col) => {
776
+ values.push({ row, col, pattern: suffix, type: "percent" });
667
777
  });
668
- }), await t.executeCommand($.id, { values: s });
669
- }
778
+ }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
779
+ }, "handler")
670
780
  };
671
- var Nn = Object.defineProperty, Mn = Object.getOwnPropertyDescriptor, Pn = (e, t, r, n) => {
672
- for (var s = n > 1 ? void 0 : n ? Mn(t, r) : t, i = e.length - 1, o; i >= 0; i--)
673
- (o = e[i]) && (s = (n ? o(t, r, s) : o(s)) || s);
674
- return n && s && Nn(t, r, s), s;
675
- }, M = (e, t) => (r, n) => t(r, n, e);
676
- let le = class extends K {
677
- constructor(t, r, n, s, i, o, c, a, f, m) {
781
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
782
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
783
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
784
+ return kind && result && __defProp$4(target, key2, result), result;
785
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$4"), _a3;
786
+ let NumfmtController = (_a3 = class extends Disposable {
787
+ constructor(_sheetInterceptorService, _themeService, _univerInstanceService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _sidebarService, _localeService) {
678
788
  super();
679
789
  /**
680
790
  * If _previewPattern is null ,the realTimeRenderingInterceptor will skip and if it is '',realTimeRenderingInterceptor will clear numfmt.
@@ -682,230 +792,231 @@ let le = class extends K {
682
792
  * @type {(string | null)}
683
793
  * @memberof NumfmtController
684
794
  */
685
- ce(this, "_previewPattern", "");
686
- ce(this, "_sidebarDisposable", null);
687
- this._sheetInterceptorService = t, this._themeService = r, this._univerInstanceService = n, this._commandService = s, this._selectionManagerService = i, this._renderManagerService = o, this._numfmtService = c, this._componentManager = a, this._sidebarService = f, this._localeService = m, this._initRealTimeRenderingInterceptor(), this._initPanel(), this._initCommands(), this._initCloseListener(), this._commandExecutedListener();
795
+ __publicField(this, "_previewPattern", "");
796
+ __publicField(this, "_sidebarDisposable", null);
797
+ 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();
688
798
  }
689
799
  openPanel() {
690
- var g;
691
- const t = this._sidebarService, r = this._selectionManagerService, n = this._commandService, s = this._univerInstanceService, i = this._numfmtService, o = this._localeService, a = (((g = r.getCurrentSelections()) == null ? void 0 : g.map((p) => p.range)) || [])[0];
692
- if (!a)
800
+ var _a8;
801
+ const sidebarService = this._sidebarService, selectionManagerService = this._selectionManagerService, commandService = this._commandService, univerInstanceService = this._univerInstanceService, numfmtService = this._numfmtService, localeService = this._localeService, range = (((_a8 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a8.map((s) => s.range)) || [])[0];
802
+ if (!range)
693
803
  return !1;
694
- const f = s.getCurrentUnitForType(T.UNIVER_SHEET), m = f.getActiveSheet();
695
- if (!m)
804
+ const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), sheet = workbook.getActiveSheet();
805
+ if (!sheet)
696
806
  return !1;
697
- const l = m.getCellRaw(a.startRow, a.startColumn), u = i.getValue(
698
- f.getUnitId(),
699
- m.getSheetId(),
700
- a.startRow,
701
- a.startColumn
807
+ const cellValue = sheet.getCellRaw(range.startRow, range.startColumn), numfmtValue = numfmtService.getValue(
808
+ workbook.getUnitId(),
809
+ sheet.getSheetId(),
810
+ range.startRow,
811
+ range.startColumn
702
812
  );
703
- let v = "";
704
- u && (v = u.pattern);
705
- const _ = (l == null ? void 0 : l.t) === V.NUMBER ? l.v : 12345678, h = {
706
- onChange: (p) => {
707
- var S;
708
- if (p.type === "change")
709
- this._previewPattern = p.value, this._forceUpdate();
710
- else if (p.type === "confirm") {
711
- const F = ((S = r.getCurrentSelections()) == null ? void 0 : S.map((W) => W.range)) || [], oe = { values: [] }, be = fe(p.value);
712
- F.forEach((W) => {
713
- R.foreach(W, (Ce, C) => {
714
- oe.values.push({
715
- row: Ce,
716
- col: C,
717
- pattern: p.value,
718
- type: be
813
+ let pattern = "";
814
+ numfmtValue && (pattern = numfmtValue.pattern);
815
+ const defaultValue = (cellValue == null ? void 0 : cellValue.t) === CellValueType.NUMBER ? cellValue.v : 12345678, props = {
816
+ onChange: /* @__PURE__ */ __name((config) => {
817
+ var _a9;
818
+ if (config.type === "change")
819
+ this._previewPattern = config.value, this._forceUpdate();
820
+ else if (config.type === "confirm") {
821
+ const selections2 = ((_a9 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a9.map((s) => s.range)) || [], params = { values: [] }, patternType = getPatternType(config.value);
822
+ selections2.forEach((rangeInfo) => {
823
+ Range.foreach(rangeInfo, (row, col) => {
824
+ params.values.push({
825
+ row,
826
+ col,
827
+ pattern: config.value,
828
+ type: patternType
719
829
  });
720
830
  });
721
- }), n.executeCommand($.id, oe), t.close();
722
- } else p.type === "cancel" && t.close();
723
- },
724
- value: { defaultPattern: v, defaultValue: _, row: a.startRow, col: a.startColumn }
831
+ }), commandService.executeCommand(SetNumfmtCommand.id, params), sidebarService.close();
832
+ } else config.type === "cancel" && sidebarService.close();
833
+ }, "onChange"),
834
+ value: { defaultPattern: pattern, defaultValue, row: range.startRow, col: range.startColumn }
725
835
  };
726
- return this._sidebarDisposable = t.open({
727
- header: { title: o.t("sheet.numfmt.title") },
836
+ return this._sidebarDisposable = sidebarService.open({
837
+ header: { title: localeService.t("sheet.numfmt.title") },
728
838
  children: {
729
- label: Ne,
730
- ...h
839
+ label: SHEET_NUMFMT_PLUGIN,
840
+ ...props
731
841
  // need passthrough to react props.
732
842
  },
733
- onClose: () => {
734
- this._forceUpdate(), n.executeCommand(ye.id);
735
- }
843
+ onClose: /* @__PURE__ */ __name(() => {
844
+ this._forceUpdate(), commandService.executeCommand(CloseNumfmtPanelOperator.id);
845
+ }, "onClose")
736
846
  }), !0;
737
847
  }
738
- _forceUpdate(t) {
739
- var n;
740
- const r = this._renderManagerService.getRenderById(
741
- t != null ? t : this._univerInstanceService.getCurrentUnitForType(T.UNIVER_SHEET).getUnitId()
848
+ _forceUpdate(unitId) {
849
+ var _a8;
850
+ const renderUnit = this._renderManagerService.getRenderById(
851
+ unitId != null ? unitId : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getUnitId()
742
852
  );
743
- r == null || r.with(Rt).reCalculate(), (n = r == null ? void 0 : r.mainComponent) == null || n.makeDirty();
853
+ renderUnit == null || renderUnit.with(SheetSkeletonManagerService).reCalculate(), (_a8 = renderUnit == null ? void 0 : renderUnit.mainComponent) == null || _a8.makeDirty();
744
854
  }
745
855
  _initCommands() {
746
856
  [
747
- Xe,
748
- et,
749
- Qe,
750
- it,
751
- he,
752
- ye,
753
- $
754
- ].forEach((t) => {
755
- this.disposeWithMe(this._commandService.registerCommand(t));
857
+ AddDecimalCommand,
858
+ SubtractDecimalCommand,
859
+ SetCurrencyCommand,
860
+ SetPercentCommand,
861
+ OpenNumfmtPanelOperator,
862
+ CloseNumfmtPanelOperator,
863
+ SetNumfmtCommand
864
+ ].forEach((config) => {
865
+ this.disposeWithMe(this._commandService.registerCommand(config));
756
866
  });
757
867
  }
758
868
  _initPanel() {
759
- this._componentManager.register(Ne, En);
869
+ this._componentManager.register(SHEET_NUMFMT_PLUGIN, SheetNumfmtPanel);
760
870
  }
761
871
  _initRealTimeRenderingInterceptor() {
762
- const t = new G((n) => {
763
- this._commandService.onCommandExecuted((s) => {
764
- s.id === he.id && n.next(!0), s.id === ye.id && n.next(!1);
872
+ const isPanelOpenObserver = new Observable((subscriber) => {
873
+ this._commandService.onCommandExecuted((commandInfo) => {
874
+ commandInfo.id === OpenNumfmtPanelOperator.id && subscriber.next(!0), commandInfo.id === CloseNumfmtPanelOperator.id && subscriber.next(!1);
765
875
  });
766
- }), r = Ut([
767
- t,
876
+ }), combineOpenAndSelection$ = combineLatest([
877
+ isPanelOpenObserver,
768
878
  this._selectionManagerService.selectionMoveEnd$.pipe(
769
- Wt((n) => n ? n.map((s) => s.range) : [])
879
+ map((selectionInfos) => selectionInfos ? selectionInfos.map((selectionInfo) => selectionInfo.range) : [])
770
880
  )
771
881
  ]);
772
882
  this.disposeWithMe(
773
- Ee(
774
- r.pipe(
775
- kt(
776
- ([n, s]) => new G((i) => {
777
- const o = new bt();
778
- return n && s.length && i.next({ selectionRanges: s, disposableCollection: o }), () => {
779
- o.dispose();
883
+ toDisposable(
884
+ combineOpenAndSelection$.pipe(
885
+ switchMap$1(
886
+ ([isOpen, selectionRanges]) => new Observable((subscribe) => {
887
+ const disposableCollection = new DisposableCollection();
888
+ return isOpen && selectionRanges.length && subscribe.next({ selectionRanges, disposableCollection }), () => {
889
+ disposableCollection.dispose();
780
890
  };
781
891
  })
782
892
  ),
783
- Gt(() => {
893
+ tap(() => {
784
894
  this._previewPattern = null;
785
895
  })
786
- ).subscribe(({ disposableCollection: n, selectionRanges: s }) => {
787
- var o, c;
788
- const i = this._univerInstanceService.getCurrentUnitForType(T.UNIVER_SHEET);
789
- this.openPanel(), n.add(
790
- this._sheetInterceptorService.intercept(ke.CELL_CONTENT, {
896
+ ).subscribe(({ disposableCollection, selectionRanges }) => {
897
+ var _a8, _b;
898
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
899
+ this.openPanel(), disposableCollection.add(
900
+ this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
791
901
  priority: 99,
792
- handler: (a, f, m) => {
793
- const { row: l, col: u } = f, v = m(a) || {};
794
- if (s.find(
795
- (_) => _.startColumn <= u && _.endColumn >= u && _.startRow <= l && _.endRow >= l
902
+ handler: /* @__PURE__ */ __name((cell, location, next) => {
903
+ const { row, col } = location, defaultValue = next(cell) || {};
904
+ if (selectionRanges.find(
905
+ (range) => range.startColumn <= col && range.endColumn >= col && range.startRow <= row && range.endRow >= row
796
906
  )) {
797
- const _ = f.worksheet.getCellRaw(l, u), h = _ == null ? void 0 : _.v, g = _ == null ? void 0 : _.t;
798
- if (h == null || g !== V.NUMBER || this._previewPattern === null)
799
- return v;
800
- const p = De(this._previewPattern, h, this._localeService.getCurrentLocale());
801
- if (p.color) {
802
- const F = this._themeService.getCurrentTheme()[`${p.color}500`];
907
+ const rawValue = location.worksheet.getCellRaw(row, col), value = rawValue == null ? void 0 : rawValue.v, type = rawValue == null ? void 0 : rawValue.t;
908
+ if (value == null || type !== CellValueType.NUMBER || this._previewPattern === null)
909
+ return defaultValue;
910
+ const info = getPatternPreview(this._previewPattern, value, this._localeService.getCurrentLocale());
911
+ if (info.color) {
912
+ const color = this._themeService.getCurrentTheme()[`${info.color}500`];
803
913
  return {
804
- ...v,
805
- v: p.result,
806
- t: V.STRING,
807
- s: { cl: { rgb: F } }
914
+ ...defaultValue,
915
+ v: info.result,
916
+ t: CellValueType.STRING,
917
+ s: { cl: { rgb: color } }
808
918
  };
809
919
  }
810
920
  return {
811
- ...v,
812
- v: p.result,
813
- t: V.STRING
921
+ ...defaultValue,
922
+ v: info.result,
923
+ t: CellValueType.STRING
814
924
  };
815
925
  }
816
- return v;
817
- }
926
+ return defaultValue;
927
+ }, "handler")
818
928
  })
819
- ), (c = (o = this._renderManagerService.getRenderById(i.getUnitId())) == null ? void 0 : o.mainComponent) == null || c.makeDirty();
929
+ ), (_b = (_a8 = this._renderManagerService.getRenderById(workbook.getUnitId())) == null ? void 0 : _a8.mainComponent) == null || _b.makeDirty();
820
930
  })
821
931
  )
822
932
  );
823
933
  }
824
934
  _commandExecutedListener() {
825
- const t = [_e.id, q.id];
935
+ const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id];
826
936
  this.disposeWithMe(
827
- new G((r) => {
828
- const n = this._commandService.onCommandExecuted((s) => {
829
- if (t.includes(s.id)) {
830
- const i = s.params;
831
- r.next(i.unitId);
937
+ new Observable((subscribe) => {
938
+ const disposable = this._commandService.onCommandExecuted((command) => {
939
+ if (commandList.includes(command.id)) {
940
+ const params = command.params;
941
+ subscribe.next(params.unitId);
832
942
  }
833
943
  });
834
- return () => n.dispose();
835
- }).pipe(zt(16)).subscribe((r) => this._forceUpdate(r))
944
+ return () => disposable.dispose();
945
+ }).pipe(debounceTime(16)).subscribe((unitId) => this._forceUpdate(unitId))
836
946
  );
837
947
  }
838
948
  _initCloseListener() {
839
- this._univerInstanceService.getCurrentTypeOfUnit$(T.UNIVER_SHEET).subscribe((t) => {
840
- var r;
841
- t || ((r = this._sidebarDisposable) == null || r.dispose(), this._sidebarDisposable = null);
949
+ this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((unit) => {
950
+ var _a8;
951
+ unit || ((_a8 = this._sidebarDisposable) == null || _a8.dispose(), this._sidebarDisposable = null);
842
952
  });
843
953
  }
844
- };
845
- le = Pn([
846
- Y(B.Rendered, le),
847
- M(0, b(Re)),
848
- M(1, b(We)),
849
- M(2, w),
850
- M(3, O),
851
- M(4, b(U)),
852
- M(5, Vt),
853
- M(6, H),
854
- M(7, b(Ye)),
855
- M(8, Ht),
856
- M(9, b(E))
857
- ], le);
858
- var Rn = Object.defineProperty, xn = Object.getOwnPropertyDescriptor, On = (e, t, r, n) => {
859
- for (var s = n > 1 ? void 0 : n ? xn(t, r) : t, i = e.length - 1, o; i >= 0; i--)
860
- (o = e[i]) && (s = (n ? o(t, r, s) : o(s)) || s);
861
- return n && s && Rn(t, r, s), s;
862
- }, k = (e, t) => (r, n) => t(r, n, e);
863
- const jn = () => {
864
- let e = [];
954
+ }, __name(_a3, "NumfmtController"), _a3);
955
+ NumfmtController = __decorateClass$4([
956
+ OnLifecycle(LifecycleStages.Rendered, NumfmtController),
957
+ __decorateParam$4(0, Inject(SheetInterceptorService)),
958
+ __decorateParam$4(1, Inject(ThemeService)),
959
+ __decorateParam$4(2, IUniverInstanceService),
960
+ __decorateParam$4(3, ICommandService),
961
+ __decorateParam$4(4, Inject(SheetsSelectionsService)),
962
+ __decorateParam$4(5, IRenderManagerService),
963
+ __decorateParam$4(6, INumfmtService),
964
+ __decorateParam$4(7, Inject(ComponentManager)),
965
+ __decorateParam$4(8, ISidebarService),
966
+ __decorateParam$4(9, Inject(LocaleService))
967
+ ], NumfmtController);
968
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
969
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
970
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
971
+ return kind && result && __defProp$3(target, key2, result), result;
972
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$3");
973
+ const createCollectEffectMutation = /* @__PURE__ */ __name(() => {
974
+ let list = [];
865
975
  return {
866
- add: (s, i, o, c, a) => e.push({ unitId: s, subUnitId: i, row: o, col: c, value: a }),
867
- getEffects: () => e,
868
- clean: () => {
869
- e = [];
870
- }
976
+ add: /* @__PURE__ */ __name((unitId, subUnitId, row, col, value) => list.push({ unitId, subUnitId, row, col, value }), "add"),
977
+ getEffects: /* @__PURE__ */ __name(() => list, "getEffects"),
978
+ clean: /* @__PURE__ */ __name(() => {
979
+ list = [];
980
+ }, "clean")
871
981
  };
872
- };
873
- let ue = class extends K {
874
- constructor(t, r, n, s, i) {
982
+ }, "createCollectEffectMutation");
983
+ var _a4;
984
+ let NumfmtEditorController = (_a4 = class extends Disposable {
985
+ constructor(_sheetInterceptorService, _numfmtService, _univerInstanceService, _injector, _editorBridgeService) {
875
986
  super();
876
987
  // collect effect mutations when edit end and push this to commands stack in next commands progress
877
- ce(this, "_collectEffectMutation", jn());
878
- this._sheetInterceptorService = t, this._numfmtService = r, this._univerInstanceService = n, this._injector = s, this._editorBridgeService = i, this._initInterceptorEditorStart(), this._initInterceptorEditorEnd(), this._initInterceptorCommands();
988
+ __publicField(this, "_collectEffectMutation", createCollectEffectMutation());
989
+ this._sheetInterceptorService = _sheetInterceptorService, this._numfmtService = _numfmtService, this._univerInstanceService = _univerInstanceService, this._injector = _injector, this._editorBridgeService = _editorBridgeService, this._initInterceptorEditorStart(), this._initInterceptorEditorEnd(), this._initInterceptorCommands();
879
990
  }
880
991
  _initInterceptorEditorStart() {
881
992
  this._editorBridgeService && this.disposeWithMe(
882
- Ee(
993
+ toDisposable(
883
994
  this._editorBridgeService.interceptor.intercept(
884
995
  this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,
885
996
  {
886
- handler: (t, r, n) => {
887
- const s = r.row, i = r.col, o = this._numfmtService.getValue(
888
- r.unitId,
889
- r.subUnitId,
890
- s,
891
- i
997
+ handler: /* @__PURE__ */ __name((value, context, next) => {
998
+ const row = context.row, col = context.col, numfmtCell = this._numfmtService.getValue(
999
+ context.unitId,
1000
+ context.subUnitId,
1001
+ row,
1002
+ col
892
1003
  );
893
- if (o)
894
- switch (fe(o.pattern)) {
1004
+ if (numfmtCell)
1005
+ switch (getPatternType(numfmtCell.pattern)) {
895
1006
  case "scientific":
896
1007
  case "percent":
897
1008
  case "currency":
898
1009
  case "grouped":
899
1010
  case "number":
900
- return r.worksheet.getCellRaw(s, i);
1011
+ return context.worksheet.getCellRaw(row, col);
901
1012
  case "date":
902
1013
  case "time":
903
1014
  case "datetime":
904
1015
  default:
905
- return n && n(t);
1016
+ return next && next(value);
906
1017
  }
907
- return n(t);
908
- }
1018
+ return next(value);
1019
+ }, "handler")
909
1020
  }
910
1021
  )
911
1022
  )
@@ -918,108 +1029,108 @@ let ue = class extends K {
918
1029
  */
919
1030
  _initInterceptorEditorEnd() {
920
1031
  this._editorBridgeService && this.disposeWithMe(
921
- Ee(
1032
+ toDisposable(
922
1033
  this._editorBridgeService.interceptor.intercept(
923
1034
  this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,
924
1035
  {
925
- handler: (t, r, n) => {
926
- var m;
1036
+ handler: /* @__PURE__ */ __name((value, context, next) => {
1037
+ var _a8;
927
1038
  this._collectEffectMutation.clean();
928
- const s = this._numfmtService.getValue(
929
- r.unitId,
930
- r.subUnitId,
931
- r.row,
932
- r.col
933
- ), i = (m = s && fe(s.pattern)) != null ? m : "", o = () => {
934
- s && this._collectEffectMutation.add(
935
- r.unitId,
936
- r.subUnitId,
937
- r.row,
938
- r.col,
1039
+ const currentNumfmtValue = this._numfmtService.getValue(
1040
+ context.unitId,
1041
+ context.subUnitId,
1042
+ context.row,
1043
+ context.col
1044
+ ), currentNumfmtType = (_a8 = currentNumfmtValue && getPatternType(currentNumfmtValue.pattern)) != null ? _a8 : "", clean = /* @__PURE__ */ __name(() => {
1045
+ currentNumfmtValue && this._collectEffectMutation.add(
1046
+ context.unitId,
1047
+ context.subUnitId,
1048
+ context.row,
1049
+ context.col,
939
1050
  null
940
1051
  );
941
- };
942
- if (!(t != null && t.v))
943
- return n(t);
944
- const c = String(t.v), a = x.parseDate(c) || x.parseTime(c);
945
- if (!!a) {
946
- if (a && a.z) {
947
- const l = Number(a.v);
1052
+ }, "clean");
1053
+ if (!(value != null && value.v))
1054
+ return next(value);
1055
+ const content = String(value.v), dateInfo = numfmt.parseDate(content) || numfmt.parseTime(content);
1056
+ if (!!dateInfo) {
1057
+ if (dateInfo && dateInfo.z) {
1058
+ const v = Number(dateInfo.v);
948
1059
  return this._collectEffectMutation.add(
949
- r.unitId,
950
- r.subUnitId,
951
- r.row,
952
- r.col,
1060
+ context.unitId,
1061
+ context.subUnitId,
1062
+ context.row,
1063
+ context.col,
953
1064
  {
954
- pattern: a.z
1065
+ pattern: dateInfo.z
955
1066
  }
956
- ), { ...t, v: l, t: V.NUMBER };
1067
+ ), { ...value, v, t: CellValueType.NUMBER };
957
1068
  }
958
- } else (["date", "time", "datetime"].includes(i) || !$n(c)) && o();
959
- return n(t);
960
- }
1069
+ } else (["date", "time", "datetime"].includes(currentNumfmtType) || !isNumeric(content)) && clean();
1070
+ return next(value);
1071
+ }, "handler")
961
1072
  }
962
1073
  )
963
1074
  )
964
1075
  );
965
1076
  }
966
1077
  _initInterceptorCommands() {
967
- const t = this;
1078
+ const self = this;
968
1079
  this.disposeWithMe(
969
1080
  this._sheetInterceptorService.interceptCommand({
970
- getMutations(r) {
971
- var n;
972
- switch (r.id) {
973
- case Mt.id: {
974
- const s = t._univerInstanceService.getCurrentUnitForType(T.UNIVER_SHEET), i = s.getUnitId(), o = (n = s.getActiveSheet()) == null ? void 0 : n.getSheetId();
975
- if (!o)
1081
+ getMutations(command) {
1082
+ var _a8;
1083
+ switch (command.id) {
1084
+ case SetRangeValuesCommand.id: {
1085
+ const workbook = self._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), unitId = workbook.getUnitId(), subUnitId = (_a8 = workbook.getActiveSheet()) == null ? void 0 : _a8.getSheetId();
1086
+ if (!subUnitId)
976
1087
  return {
977
1088
  redos: [],
978
1089
  undos: []
979
1090
  };
980
- const c = t._collectEffectMutation.getEffects();
981
- if (!c.length)
1091
+ const list = self._collectEffectMutation.getEffects();
1092
+ if (self._collectEffectMutation.clean(), !list.length)
982
1093
  return {
983
1094
  redos: [],
984
1095
  undos: []
985
1096
  };
986
- const a = c.filter((u) => {
987
- var v;
988
- return !!((v = u.value) != null && v.pattern);
989
- }).map((u) => ({
990
- row: u.row,
991
- col: u.col,
992
- pattern: u.value.pattern
993
- })), f = c.filter((u) => {
994
- var v;
995
- return !((v = u.value) != null && v.pattern);
996
- }).map((u) => ({
997
- startRow: u.row,
998
- endColumn: u.col,
999
- startColumn: u.col,
1000
- endRow: u.row
1001
- })), m = [], l = [];
1002
- if (a) {
1003
- const u = {
1004
- id: q.id,
1005
- params: Ge(i, o, a)
1097
+ const cells = list.filter((item) => {
1098
+ var _a9;
1099
+ return !!((_a9 = item.value) != null && _a9.pattern);
1100
+ }).map((item) => ({
1101
+ row: item.row,
1102
+ col: item.col,
1103
+ pattern: item.value.pattern
1104
+ })), removeCells = list.filter((item) => {
1105
+ var _a9;
1106
+ return !((_a9 = item.value) != null && _a9.pattern);
1107
+ }).map((item) => ({
1108
+ startRow: item.row,
1109
+ endColumn: item.col,
1110
+ startColumn: item.col,
1111
+ endRow: item.row
1112
+ })), redos = [], undos = [];
1113
+ if (cells.length) {
1114
+ const redo = {
1115
+ id: SetNumfmtMutation.id,
1116
+ params: transformCellsToRange(unitId, subUnitId, cells)
1006
1117
  };
1007
- m.push(u), l.push(...ze(t._injector, u.params));
1118
+ redos.push(redo), undos.push(...factorySetNumfmtUndoMutation(self._injector, redo.params));
1008
1119
  }
1009
- if (f) {
1010
- const u = {
1011
- id: _e.id,
1120
+ if (removeCells.length) {
1121
+ const redo = {
1122
+ id: RemoveNumfmtMutation.id,
1012
1123
  params: {
1013
- unitId: i,
1014
- subUnitId: o,
1015
- ranges: f
1124
+ unitId,
1125
+ subUnitId,
1126
+ ranges: removeCells
1016
1127
  }
1017
1128
  };
1018
- m.push(u), l.push(...Ke(t._injector, u.params));
1129
+ redos.push(redo), undos.push(...factoryRemoveNumfmtUndoMutation(self._injector, redo.params));
1019
1130
  }
1020
1131
  return {
1021
- redos: m,
1022
- undos: l.reverse()
1132
+ redos,
1133
+ undos: undos.reverse()
1023
1134
  };
1024
1135
  }
1025
1136
  }
@@ -1031,40 +1142,41 @@ let ue = class extends K {
1031
1142
  })
1032
1143
  );
1033
1144
  }
1034
- };
1035
- ue = On([
1036
- Y(B.Rendered, ue),
1037
- k(0, b(Re)),
1038
- k(1, b(H)),
1039
- k(2, b(w)),
1040
- k(3, b(Pe)),
1041
- k(4, Ct(xt))
1042
- ], ue);
1043
- function $n(e) {
1044
- return /^-?\d+(\.\d+)?$/.test(e);
1145
+ }, __name(_a4, "NumfmtEditorController"), _a4);
1146
+ NumfmtEditorController = __decorateClass$3([
1147
+ OnLifecycle(LifecycleStages.Rendered, NumfmtEditorController),
1148
+ __decorateParam$3(0, Inject(SheetInterceptorService)),
1149
+ __decorateParam$3(1, Inject(INumfmtService)),
1150
+ __decorateParam$3(2, Inject(IUniverInstanceService)),
1151
+ __decorateParam$3(3, Inject(Injector)),
1152
+ __decorateParam$3(4, Optional(IEditorBridgeService))
1153
+ ], NumfmtEditorController);
1154
+ function isNumeric(str) {
1155
+ return /^-?\d+(\.\d+)?$/.test(str);
1045
1156
  }
1046
- var wn = Object.defineProperty, Dn = Object.getOwnPropertyDescriptor, Un = (e, t, r, n) => {
1047
- for (var s = n > 1 ? void 0 : n ? Dn(t, r) : t, i = e.length - 1, o; i >= 0; i--)
1048
- (o = e[i]) && (s = (n ? o(t, r, s) : o(s)) || s);
1049
- return n && s && wn(t, r, s), s;
1050
- }, An = (e, t) => (r, n) => t(r, n, e);
1051
- let me = class extends K {
1052
- constructor(e) {
1053
- super(), this._localeService = e;
1157
+ __name(isNumeric, "isNumeric");
1158
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1159
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1160
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
1161
+ return kind && result && __defProp$2(target, key2, result), result;
1162
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$2"), _a5;
1163
+ let NumfmtI18nController = (_a5 = class extends Disposable {
1164
+ constructor(_localeService) {
1165
+ super(), this._localeService = _localeService;
1054
1166
  }
1055
- };
1056
- me = Un([
1057
- Y(B.Rendered, me),
1058
- An(0, b(E))
1059
- ], me);
1060
- const de = [
1167
+ }, __name(_a5, "NumfmtI18nController"), _a5);
1168
+ NumfmtI18nController = __decorateClass$2([
1169
+ OnLifecycle(LifecycleStages.Rendered, NumfmtI18nController),
1170
+ __decorateParam$2(0, Inject(LocaleService))
1171
+ ], NumfmtI18nController);
1172
+ const MENU_OPTIONS = [
1061
1173
  {
1062
1174
  label: "sheet.numfmt.general",
1063
1175
  pattern: null
1064
1176
  },
1065
1177
  {
1066
1178
  label: "sheet.numfmt.text",
1067
- pattern: Lt
1179
+ pattern: DEFAULT_TEXT_FORMAT
1068
1180
  },
1069
1181
  "|",
1070
1182
  {
@@ -1110,185 +1222,188 @@ const de = [
1110
1222
  label: "sheet.numfmt.moreFmt",
1111
1223
  pattern: ""
1112
1224
  }
1113
- ], ot = "sheet.numfmt.moreNumfmtType", ct = "sheet.numfmt.moreNumfmtType.options", Ln = (e) => {
1114
- var n;
1115
- const t = N(E), r = (n = e.value) != null ? n : t.t("sheet.numfmt.general");
1116
- return /* @__PURE__ */ d.jsx("span", { className: "more-numfmt-type", children: r });
1117
- }, Vn = () => {
1118
- const e = N(O), t = N(E), r = yt(), n = N(U), s = (c) => {
1119
- const a = n.getCurrentLastSelection();
1120
- if (!a)
1225
+ ], MORE_NUMFMT_TYPE_KEY = "sheet.numfmt.moreNumfmtType", OPTIONS_KEY = "sheet.numfmt.moreNumfmtType.options", MoreNumfmtType = /* @__PURE__ */ __name((props) => {
1226
+ var _a8;
1227
+ const localeService = useDependency(LocaleService), value = (_a8 = props.value) != null ? _a8 : localeService.t("sheet.numfmt.general");
1228
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "more-numfmt-type", children: value });
1229
+ }, "MoreNumfmtType"), Options = /* @__PURE__ */ __name(() => {
1230
+ const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), injector = useInjector(), selectionManagerService = useDependency(SheetsSelectionsService), setNumfmt = /* @__PURE__ */ __name((pattern) => {
1231
+ const selection = selectionManagerService.getCurrentLastSelection();
1232
+ if (!selection)
1121
1233
  return;
1122
- const f = r.get(Bt), m = a.range, l = [];
1123
- R.foreach(m, (u, v) => {
1124
- c ? l.push({ row: u, col: v, pattern: c, type: fe(c) }) : l.push({ row: u, col: v });
1125
- }), e.executeCommand($.id, { values: l }), f.focus();
1126
- }, i = (c) => {
1127
- if (c === 0)
1128
- s(null);
1129
- else if (c === de.length - 1)
1130
- e.executeCommand(he.id);
1234
+ const textSelectionRenderManager = injector.get(ITextSelectionRenderManager), range = selection.range, values = [];
1235
+ Range.foreach(range, (row, col) => {
1236
+ pattern ? values.push({ row, col, pattern, type: getPatternType(pattern) }) : values.push({ row, col });
1237
+ }), commandService.executeCommand(SetNumfmtCommand.id, { values }), textSelectionRenderManager.focus();
1238
+ }, "setNumfmt"), handleOnclick = /* @__PURE__ */ __name((index) => {
1239
+ if (index === 0)
1240
+ setNumfmt(null);
1241
+ else if (index === MENU_OPTIONS.length - 1)
1242
+ commandService.executeCommand(OpenNumfmtPanelOperator.id);
1131
1243
  else {
1132
- const a = de[c];
1133
- a.pattern && s(a.pattern);
1244
+ const item = MENU_OPTIONS[index];
1245
+ item.pattern && setNumfmt(item.pattern);
1134
1246
  }
1135
- }, o = 1220;
1136
- return /* @__PURE__ */ d.jsx("div", { className: "more-numfmt-type-options", children: de.map((c, a) => c === "|" ? /* @__PURE__ */ d.jsx("div", { className: "line m-t-4", onClick: (f) => f.stopPropagation() }, a) : /* @__PURE__ */ d.jsxs(
1247
+ }, "handleOnclick"), defaultValue = 1220;
1248
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "more-numfmt-type-options", children: MENU_OPTIONS.map((item, index) => item === "|" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "line m-t-4", onClick: /* @__PURE__ */ __name((e) => e.stopPropagation(), "onClick") }, index) : /* @__PURE__ */ jsxRuntimeExports.jsxs(
1137
1249
  "div",
1138
1250
  {
1139
1251
  className: "option-item m-t-4",
1140
- onClick: () => {
1141
- i(a);
1142
- },
1252
+ onClick: /* @__PURE__ */ __name(() => {
1253
+ handleOnclick(index);
1254
+ }, "onClick"),
1143
1255
  children: [
1144
- /* @__PURE__ */ d.jsx("div", { children: t.t(c.label) }),
1145
- /* @__PURE__ */ d.jsx("div", { className: "m-l-26", children: c.pattern ? De(c.pattern || "", o, t.getCurrentLocale()).result : "" })
1256
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t(item.label) }),
1257
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-l-26", children: item.pattern ? getPatternPreview(item.pattern || "", defaultValue, localeService.getCurrentLocale()).result : "" })
1146
1258
  ]
1147
1259
  },
1148
- a
1260
+ index
1149
1261
  )) });
1150
- }, Bn = (e) => ({
1262
+ }, "Options"), CurrencyMenuItem = /* @__PURE__ */ __name((accessor) => ({
1151
1263
  icon: "RmbSingle",
1152
- id: Qe.id,
1264
+ id: SetCurrencyCommand.id,
1153
1265
  title: "sheet.numfmt.currency",
1154
1266
  tooltip: "sheet.numfmt.currency",
1155
- type: te.BUTTON,
1156
- group: ne.TOOLBAR_FORMULAS_INSERT,
1157
- positions: [re.TOOLBAR_START],
1158
- hidden$: se(e, T.UNIVER_SHEET),
1159
- disabled$: ee(e, { workbookTypes: [J], worksheetTypes: [X, Z], rangeTypes: [Q] })
1160
- }), Hn = (e) => ({
1267
+ type: MenuItemType.BUTTON,
1268
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1269
+ positions: [MenuPosition.TOOLBAR_START],
1270
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1271
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1272
+ }), "CurrencyMenuItem"), AddDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
1161
1273
  icon: "AddDigitsSingle",
1162
- id: Xe.id,
1274
+ id: AddDecimalCommand.id,
1163
1275
  title: "sheet.numfmt.addDecimal",
1164
1276
  tooltip: "sheet.numfmt.addDecimal",
1165
- type: te.BUTTON,
1166
- positions: [re.TOOLBAR_START],
1167
- group: ne.TOOLBAR_FORMULAS_INSERT,
1168
- hidden$: se(e, T.UNIVER_SHEET),
1169
- disabled$: ee(e, { workbookTypes: [J], worksheetTypes: [X, Z], rangeTypes: [Q] })
1170
- }), Fn = (e) => ({
1277
+ type: MenuItemType.BUTTON,
1278
+ positions: [MenuPosition.TOOLBAR_START],
1279
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1280
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1281
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1282
+ }), "AddDecimalMenuItem"), SubtractDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
1171
1283
  icon: "ReduceDigitsSingle",
1172
- id: et.id,
1284
+ id: SubtractDecimalCommand.id,
1173
1285
  title: "sheet.numfmt.subtractDecimal",
1174
1286
  tooltip: "sheet.numfmt.subtractDecimal",
1175
- type: te.BUTTON,
1176
- group: ne.TOOLBAR_FORMULAS_INSERT,
1177
- positions: [re.TOOLBAR_START],
1178
- hidden$: se(e, T.UNIVER_SHEET),
1179
- disabled$: ee(e, { workbookTypes: [J], worksheetTypes: [X, Z], rangeTypes: [Q] })
1180
- }), Wn = (e) => ({
1287
+ type: MenuItemType.BUTTON,
1288
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1289
+ positions: [MenuPosition.TOOLBAR_START],
1290
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1291
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1292
+ }), "SubtractDecimalMenuItem"), PercentMenuItem = /* @__PURE__ */ __name((accessor) => ({
1181
1293
  icon: "PercentSingle",
1182
- id: it.id,
1294
+ id: SetPercentCommand.id,
1183
1295
  title: "sheet.numfmt.percent",
1184
1296
  tooltip: "sheet.numfmt.percent",
1185
- type: te.BUTTON,
1186
- group: ne.TOOLBAR_FORMULAS_INSERT,
1187
- positions: [re.TOOLBAR_START],
1188
- hidden$: se(e, T.UNIVER_SHEET),
1189
- disabled$: ee(e, { workbookTypes: [J], worksheetTypes: [X, Z], rangeTypes: [Q] })
1190
- }), kn = (e) => {
1191
- const t = e.get(H), r = e.get(w), n = e.get(O), s = e.get(E), i = e.get(U), o = Ot(r, "", ({ workbook: c, worksheet: a }) => new G(
1192
- (f) => At(
1193
- i.selectionMoveEnd$,
1194
- new G((m) => {
1195
- const l = [_e.id, q.id], u = n.onCommandExecuted((v) => {
1196
- l.includes(v.id) && m.next(null);
1297
+ type: MenuItemType.BUTTON,
1298
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1299
+ positions: [MenuPosition.TOOLBAR_START],
1300
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1301
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1302
+ }), "PercentMenuItem"), FactoryOtherMenuItem = /* @__PURE__ */ __name((accessor) => {
1303
+ accessor.get(INumfmtService);
1304
+ const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), localeService = accessor.get(LocaleService), selectionManagerService = accessor.get(SheetsSelectionsService), value$ = deriveStateFromActiveSheet$(univerInstanceService, "", ({ workbook, worksheet }) => new Observable(
1305
+ (subscribe) => merge(
1306
+ selectionManagerService.selectionMoveEnd$,
1307
+ new Observable((commandSubscribe) => {
1308
+ const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id], disposable = commandService.onCommandExecuted((commandInfo) => {
1309
+ commandList.includes(commandInfo.id) && commandSubscribe.next(null);
1197
1310
  });
1198
- return () => u.dispose();
1311
+ return () => disposable.dispose();
1199
1312
  })
1200
1313
  ).subscribe(() => {
1201
- const m = i.getCurrentSelections();
1202
- if (m && m[0]) {
1203
- const l = m[0].range, u = l.startRow, v = l.startColumn, _ = t.getValue(c.getUnitId(), a.getSheetId(), u, v), h = _ == null ? void 0 : _.pattern;
1204
- let g = s.t("sheet.numfmt.general");
1205
- if (h) {
1206
- const p = de.filter((S) => typeof S == "object" && S.pattern).find(
1207
- (S) => ge(h, S.pattern)
1314
+ var _a8, _b;
1315
+ const selections = selectionManagerService.getCurrentSelections();
1316
+ if (selections && selections[0]) {
1317
+ const range = selections[0].range, row = range.startRow, col = range.startColumn, numfmtValue = (_b = workbook.getStyles().get((_a8 = worksheet.getCell(row, col)) == null ? void 0 : _a8.s)) == null ? void 0 : _b.n, pattern = numfmtValue == null ? void 0 : numfmtValue.pattern;
1318
+ let value = localeService.t("sheet.numfmt.general");
1319
+ if (pattern) {
1320
+ const item = MENU_OPTIONS.filter((item2) => typeof item2 == "object" && item2.pattern).find(
1321
+ (item2) => isPatternEqualWithoutDecimal(pattern, item2.pattern)
1208
1322
  );
1209
- p && typeof p == "object" && p.pattern ? g = s.t(p.label) : g = s.t("sheet.numfmt.moreFmt");
1323
+ item && typeof item == "object" && item.pattern ? value = localeService.t(item.label) : value = localeService.t("sheet.numfmt.moreFmt");
1210
1324
  }
1211
- f.next(g);
1325
+ subscribe.next(value);
1212
1326
  }
1213
1327
  })
1214
1328
  ));
1215
1329
  return {
1216
- label: ot,
1217
- id: he.id,
1330
+ label: MORE_NUMFMT_TYPE_KEY,
1331
+ id: OpenNumfmtPanelOperator.id,
1218
1332
  tooltip: "sheet.numfmt.title",
1219
- type: te.SELECTOR,
1220
- group: ne.TOOLBAR_FORMULAS_INSERT,
1221
- positions: [re.TOOLBAR_START],
1333
+ type: MenuItemType.SELECTOR,
1334
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1335
+ positions: [MenuPosition.TOOLBAR_START],
1222
1336
  selections: [
1223
1337
  {
1224
1338
  label: {
1225
- name: ct,
1339
+ name: OPTIONS_KEY,
1226
1340
  hoverable: !1
1227
1341
  }
1228
1342
  }
1229
1343
  ],
1230
- value$: o,
1231
- hidden$: se(e, T.UNIVER_SHEET),
1232
- disabled$: ee(e, { workbookTypes: [J], worksheetTypes: [Z, X], rangeTypes: [Q] })
1344
+ value$,
1345
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1346
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
1233
1347
  };
1234
- };
1235
- var Gn = Object.defineProperty, zn = Object.getOwnPropertyDescriptor, Kn = (e, t, r, n) => {
1236
- for (var s = n > 1 ? void 0 : n ? zn(t, r) : t, i = e.length - 1, o; i >= 0; i--)
1237
- (o = e[i]) && (s = (n ? o(t, r, s) : o(s)) || s);
1238
- return n && s && Gn(t, r, s), s;
1239
- }, Ie = (e, t) => (r, n) => t(r, n, e);
1240
- const Yn = {};
1241
- let z = class extends K {
1242
- constructor(e, t, r, n) {
1243
- super(), this._config = e, this._injector = t, this._componentManager = r, this._menuService = n, this._initMenu();
1348
+ }, "FactoryOtherMenuItem");
1349
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1350
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1351
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
1352
+ return kind && result && __defProp$1(target, key2, result), result;
1353
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$1");
1354
+ const DefaultSheetNumfmtConfig = {};
1355
+ var _a6;
1356
+ let NumfmtMenuController = (_a6 = class extends Disposable {
1357
+ constructor(_config, _injector, _componentManager, _menuService) {
1358
+ super(), this._config = _config, this._injector = _injector, this._componentManager = _componentManager, this._menuService = _menuService, this._initMenu();
1244
1359
  }
1245
1360
  _initMenu() {
1246
- const { menu: e = {} } = this._config;
1247
- [Wn, Hn, Fn, Bn, kn].forEach((t) => {
1248
- this.disposeWithMe(this._menuService.addMenuItem(t(this._injector), e));
1249
- }), this.disposeWithMe(this._componentManager.register(ot, Ln)), this.disposeWithMe(this._componentManager.register(ct, Vn));
1361
+ const { menu = {} } = this._config;
1362
+ [PercentMenuItem, AddDecimalMenuItem, SubtractDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem].forEach((factory) => {
1363
+ this.disposeWithMe(this._menuService.addMenuItem(factory(this._injector), menu));
1364
+ }), this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY, MoreNumfmtType)), this.disposeWithMe(this._componentManager.register(OPTIONS_KEY, Options));
1250
1365
  }
1251
- };
1252
- z = Kn([
1253
- Y(B.Rendered, z),
1254
- Ie(1, b(Pe)),
1255
- Ie(2, b(Ye)),
1256
- Ie(3, b(Ft))
1257
- ], z);
1258
- var at = Object.defineProperty, qn = Object.getOwnPropertyDescriptor, Jn = (e, t, r) => t in e ? at(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Xn = (e, t, r, n) => {
1259
- for (var s = n > 1 ? void 0 : n ? qn(t, r) : t, i = e.length - 1, o; i >= 0; i--)
1260
- (o = e[i]) && (s = (n ? o(t, r, s) : o(s)) || s);
1261
- return n && s && at(t, r, s), s;
1262
- }, Zn = (e, t) => (r, n) => t(r, n, e), lt = (e, t, r) => Jn(e, typeof t != "symbol" ? t + "" : t, r);
1263
- let ve = class extends Tt {
1264
- constructor(e = {}, t) {
1265
- super(), this._config = e, this._injector = t, this._config = It.deepMerge({}, Yn, this._config);
1366
+ }, __name(_a6, "NumfmtMenuController"), _a6);
1367
+ NumfmtMenuController = __decorateClass$1([
1368
+ OnLifecycle(LifecycleStages.Rendered, NumfmtMenuController),
1369
+ __decorateParam$1(1, Inject(Injector)),
1370
+ __decorateParam$1(2, Inject(ComponentManager)),
1371
+ __decorateParam$1(3, Inject(IMenuService))
1372
+ ], NumfmtMenuController);
1373
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key2, value) => key2 in obj ? __defProp2(obj, key2, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key2] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1374
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1375
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
1376
+ return kind && result && __defProp2(target, key2, result), result;
1377
+ }, "__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;
1378
+ let UniverSheetsNumfmtPlugin = (_a7 = class extends Plugin {
1379
+ constructor(_config = {}, _injector) {
1380
+ super(), this._config = _config, this._injector = _injector, this._config = Tools.deepMerge({}, DefaultSheetNumfmtConfig, this._config);
1266
1381
  }
1267
1382
  onStarting() {
1268
- this._injector.add([Ue, { useClass: le, lazy: !1 }]), this._injector.add([ue]), this._injector.add([pe]), this._injector.add([ae]), this._injector.add([me]), this._injector.add(
1383
+ 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(
1269
1384
  [
1270
- z,
1385
+ NumfmtMenuController,
1271
1386
  {
1272
- useFactory: () => this._injector.createInstance(z, this._config)
1387
+ useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(NumfmtMenuController, this._config), "useFactory")
1273
1388
  }
1274
1389
  ]
1275
1390
  );
1276
1391
  }
1277
- };
1278
- lt(ve, "pluginName", Ne);
1279
- lt(ve, "type", T.UNIVER_SHEET);
1280
- ve = Xn([
1281
- Et(Pt, jt),
1282
- Zn(1, b(Pe))
1283
- ], ve);
1392
+ }, __name(_a7, "UniverSheetsNumfmtPlugin"), _a7);
1393
+ __publicField2(UniverSheetsNumfmtPlugin, "pluginName", SHEET_NUMFMT_PLUGIN);
1394
+ __publicField2(UniverSheetsNumfmtPlugin, "type", UniverInstanceType.UNIVER_SHEET);
1395
+ UniverSheetsNumfmtPlugin = __decorateClass([
1396
+ DependentOn(UniverSheetsPlugin, UniverSheetsUIPlugin),
1397
+ __decorateParam(1, Inject(Injector))
1398
+ ], UniverSheetsNumfmtPlugin);
1284
1399
  export {
1285
- Xe as AddDecimalCommand,
1286
- ye as CloseNumfmtPanelOperator,
1287
- he as OpenNumfmtPanelOperator,
1288
- Qe as SetCurrencyCommand,
1289
- $ as SetNumfmtCommand,
1290
- it as SetPercentCommand,
1291
- et as SubtractDecimalCommand,
1292
- ve as UniverSheetsNumfmtPlugin,
1293
- De as getPatternPreview
1400
+ AddDecimalCommand,
1401
+ CloseNumfmtPanelOperator,
1402
+ OpenNumfmtPanelOperator,
1403
+ SetCurrencyCommand,
1404
+ SetNumfmtCommand,
1405
+ SetPercentCommand,
1406
+ SubtractDecimalCommand,
1407
+ UniverSheetsNumfmtPlugin,
1408
+ getPatternPreview
1294
1409
  };