@univerjs/sheets-numfmt 0.2.4 → 0.2.6

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