@univerjs/sheets-numfmt-ui 0.5.4 → 0.5.5-experimental.20250123-34738ff

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,61 +1,64 @@
1
- var ht = Object.defineProperty;
2
- var ft = (t, e, n) => e in t ? ht(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var X = (t, e, n) => ft(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { Inject as S, LocaleService as T, Disposable as oe, isRealNum as pt, CommandType as Be, ILocalStorageService as We, useDependency as b, numfmt as Q, UniverInstanceType as E, CellValueType as $, Range as Ve, toDisposable as ge, DisposableCollection as vt, InterceptorEffectEnum as Oe, ThemeService as _t, IUniverInstanceService as ye, ICommandService as be, Injector as Ge, Optional as gt, useInjector as St, DependentOn as yt, Plugin as bt, merge as Ct, registerDependencies as It, touchDependencies as Nt, IConfigService as Et } from "@univerjs/core";
5
- import { IRenderManagerService as Ke } from "@univerjs/engine-render";
6
- import { currencySymbols as Ue, getDecimalFromPattern as te, getCurrencyType as W, setPatternDecimal as M, getCurrencyFormatOptions as ue, isPatternEqualWithoutDecimal as ce, CURRENCYFORMAT as Tt, DATEFMTLISG as xt, NUMBERFORMAT as Pt, getDateFormatOptions as qe, getNumberFormatOptions as Ye, isPatternHasDecimal as Mt, getPatternType as ne, SetNumfmtCommand as Ze, getPatternPreviewIgnoreGeneral as Rt, MenuCurrencyService as jt, countryCurrencyMap as O, SetCurrencyCommand as ze, AddDecimalCommand as Je, SubtractDecimalCommand as Xe, SetPercentCommand as Qe, getPatternPreview as wt, UniverSheetsNumfmtPlugin as Ot } from "@univerjs/sheets-numfmt";
7
- import { HoverManagerService as Ut, CellAlertManagerService as $t, CellAlertType as Dt, SheetSkeletonManagerService as Ft, IEditorBridgeService as Lt, getCurrentRangeDisable$ as V, deriveStateFromActiveSheet$ as Ht, UniverSheetsUIPlugin as At } from "@univerjs/sheets-ui";
8
- import { IZenZoneService as kt, ComponentManager as et, ISidebarService as Bt, MenuItemType as G, getMenuHiddenObservable as K, ILayoutService as Wt, RibbonStartGroup as Vt, IMenuManagerService as Gt, UI_PLUGIN_CONFIG_KEY as Kt } from "@univerjs/ui";
9
- import { FormulaDataModel as qt } from "@univerjs/engine-formula";
10
- import { DEFAULT_TEXT_FORMAT as Ce } from "@univerjs/engine-numfmt";
11
- import { INumfmtService as Ie, INTERCEPTOR_POINT as Yt, RemoveNumfmtMutation as Ne, SetNumfmtMutation as Ee, SheetInterceptorService as tt, SheetsSelectionsService as Te, BEFORE_CELL_EDIT as Zt, AFTER_CELL_EDIT as zt, SetRangeValuesCommand as Jt, transformCellsToRange as Xt, factorySetNumfmtUndoMutation as Qt, factoryRemoveNumfmtUndoMutation as en, WorkbookEditablePermission as q, WorksheetEditPermission as Y, WorksheetSetCellStylePermission as Z, RangeProtectionPermissionEditPoint as z } from "@univerjs/sheets";
12
- import { debounceTime as tn, Observable as D, combineLatest as nn, merge as rn } from "rxjs";
13
- import { map as sn, switchMap as on, tap as cn, debounceTime as an } from "rxjs/operators";
14
- import ln, { createContext as mn, useState as C, useEffect as ae, useRef as xe, useContext as nt, useMemo as R, forwardRef as rt, createElement as Pe } from "react";
15
- import { InputNumber as Me, Select as Re, SelectList as je, Input as un, Button as $e } from "@univerjs/design";
16
- const De = {};
17
- var dn = Object.defineProperty, hn = Object.getOwnPropertyDescriptor, fn = (t, e, n, r) => {
18
- for (var s = r > 1 ? void 0 : r ? hn(e, n) : e, i = t.length - 1, o; i >= 0; i--)
19
- (o = t[i]) && (s = (r ? o(e, n, s) : o(s)) || s);
20
- return r && s && dn(e, n, s), s;
21
- }, U = (t, e) => (n, r) => e(n, r, t);
22
- const de = "SHEET_NUMFMT_ALERT";
23
- let Se = class extends oe {
24
- constructor(t, e, n, r, s, i, o) {
25
- super(), this._context = t, this._hoverManagerService = e, this._cellAlertManagerService = n, this._localeService = r, this._formulaDataModel = s, this._zenZoneService = i, this._numfmtService = o, this._init();
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 { Inject, LocaleService, Disposable, isRealNum, CommandType, ILocalStorageService, useDependency, numfmt, UniverInstanceType, CellValueType, Range, toDisposable, DisposableCollection, InterceptorEffectEnum, ThemeService, IUniverInstanceService, ICommandService, Injector, Optional, DependentOn, Plugin, merge as merge$1, registerDependencies, touchDependencies, IConfigService } from "@univerjs/core";
6
+ import { IRenderManagerService } from "@univerjs/engine-render";
7
+ import { currencySymbols, getDecimalFromPattern, getCurrencyType, setPatternDecimal, getCurrencyFormatOptions, isPatternEqualWithoutDecimal, CURRENCYFORMAT, DATEFMTLISG, NUMBERFORMAT, getDateFormatOptions, getNumberFormatOptions, isPatternHasDecimal, getPatternType, SetNumfmtCommand, getPatternPreviewIgnoreGeneral, SheetsNumfmtCellContentController, MenuCurrencyService, countryCurrencyMap, SetCurrencyCommand, AddDecimalCommand, SubtractDecimalCommand, SetPercentCommand, getPatternPreview, UniverSheetsNumfmtPlugin } from "@univerjs/sheets-numfmt";
8
+ import { HoverManagerService, CellAlertManagerService, CellAlertType, SheetSkeletonManagerService, IEditorBridgeService, getCurrentRangeDisable$, deriveStateFromActiveSheet$, UniverSheetsUIPlugin } from "@univerjs/sheets-ui";
9
+ import { IZenZoneService, ComponentManager, ISidebarService, MenuItemType, getMenuHiddenObservable, ILayoutService, RibbonStartGroup, IMenuManagerService, UI_PLUGIN_CONFIG_KEY } from "@univerjs/ui";
10
+ import { FormulaDataModel } from "@univerjs/engine-formula";
11
+ import { DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
12
+ import { INumfmtService, INTERCEPTOR_POINT, RemoveNumfmtMutation, SetNumfmtMutation, SheetInterceptorService, SheetsSelectionsService, BEFORE_CELL_EDIT, AFTER_CELL_EDIT, SetRangeValuesCommand, transformCellsToRange, factorySetNumfmtUndoMutation, factoryRemoveNumfmtUndoMutation, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, RangeProtectionPermissionEditPoint } from "@univerjs/sheets";
13
+ import { debounceTime, merge, Observable, combineLatest } from "rxjs";
14
+ import { map, switchMap, tap, debounceTime as debounceTime$1 } from "rxjs/operators";
15
+ import { jsxs, jsx } from "react/jsx-runtime";
16
+ import { createContext, useState, useEffect, useRef, useContext, useMemo, forwardRef, createElement } from "react";
17
+ import { InputNumber, Select, SelectList, Input, Button } from "@univerjs/design";
18
+ const defaultPluginConfig = {};
19
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
20
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
21
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
22
+ return kind && result && __defProp$5(target, key2, result), result;
23
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$5");
24
+ const ALERT_KEY = "SHEET_NUMFMT_ALERT";
25
+ var _a;
26
+ let NumfmtAlertRenderController = (_a = class extends Disposable {
27
+ constructor(_context, _hoverManagerService, _cellAlertManagerService, _localeService, _formulaDataModel, _zenZoneService, _numfmtService) {
28
+ super(), this._context = _context, this._hoverManagerService = _hoverManagerService, this._cellAlertManagerService = _cellAlertManagerService, this._localeService = _localeService, this._formulaDataModel = _formulaDataModel, this._zenZoneService = _zenZoneService, this._numfmtService = _numfmtService, this._init();
26
29
  }
27
30
  _init() {
28
31
  this._initCellAlertPopup(), this._initZenService();
29
32
  }
30
33
  _initCellAlertPopup() {
31
- this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(tn(100)).subscribe((t) => {
32
- var e;
33
- if (t) {
34
- const n = t.location, r = this._context.unit, s = r.getActiveSheet();
35
- if (!s) return;
36
- const i = n.unitId, o = n.subUnitId;
37
- let c;
38
- const a = s.getCell(n.row, n.col);
39
- if (a != null && a.s) {
40
- const m = r.getStyles().get(a.s);
41
- m != null && m.n && (c = m.n);
34
+ this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(debounceTime(100)).subscribe((cellPos) => {
35
+ var _a7;
36
+ if (cellPos) {
37
+ const location = cellPos.location, workbook = this._context.unit, worksheet = workbook.getActiveSheet();
38
+ if (!worksheet) return;
39
+ const unitId = location.unitId, sheetId = location.subUnitId;
40
+ let numfmtValue;
41
+ const cellData = worksheet.getCell(location.row, location.col);
42
+ if (cellData != null && cellData.s) {
43
+ const style = workbook.getStyles().get(cellData.s);
44
+ style != null && style.n && (numfmtValue = style.n);
42
45
  }
43
- if (c || (c = this._numfmtService.getValue(i, o, n.row, n.col)), !c) {
46
+ if (numfmtValue || (numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col)), !numfmtValue) {
44
47
  this._hideAlert();
45
48
  return;
46
49
  }
47
- if (c.pattern === Ce && (a != null && a.v) && pt(a.v)) {
48
- const m = this._cellAlertManagerService.currentAlert.get(de), d = (e = m == null ? void 0 : m.alert) == null ? void 0 : e.location;
49
- if (d && d.row === n.row && d.col === n.col && d.subUnitId === n.subUnitId && d.unitId === n.unitId)
50
+ if (numfmtValue.pattern === DEFAULT_TEXT_FORMAT && (cellData != null && cellData.v) && isRealNum(cellData.v)) {
51
+ const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY), currentLoc = (_a7 = currentAlert == null ? void 0 : currentAlert.alert) == null ? void 0 : _a7.location;
52
+ if (currentLoc && currentLoc.row === location.row && currentLoc.col === location.col && currentLoc.subUnitId === location.subUnitId && currentLoc.unitId === location.unitId)
50
53
  return;
51
54
  this._cellAlertManagerService.showAlert({
52
- type: Dt.ERROR,
55
+ type: CellAlertType.ERROR,
53
56
  title: this._localeService.t("info.error"),
54
57
  message: this._localeService.t("info.forceStringInfo"),
55
- location: n,
58
+ location,
56
59
  width: 200,
57
60
  height: 74,
58
- key: de
61
+ key: ALERT_KEY
59
62
  });
60
63
  return;
61
64
  }
@@ -64,396 +67,376 @@ let Se = class extends oe {
64
67
  }));
65
68
  }
66
69
  _initZenService() {
67
- this.disposeWithMe(this._zenZoneService.visible$.subscribe((t) => {
68
- t && this._hideAlert();
70
+ this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
71
+ visible && this._hideAlert();
69
72
  }));
70
73
  }
71
74
  _hideAlert() {
72
- this._cellAlertManagerService.removeAlert(de);
75
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
73
76
  }
74
- };
75
- Se = fn([
76
- U(1, S(Ut)),
77
- U(2, S($t)),
78
- U(3, S(T)),
79
- U(4, S(qt)),
80
- U(5, kt),
81
- U(6, S(Ie))
82
- ], Se);
83
- const he = {
77
+ }, __name(_a, "NumfmtAlertRenderController"), _a);
78
+ NumfmtAlertRenderController = __decorateClass$5([
79
+ __decorateParam$5(1, Inject(HoverManagerService)),
80
+ __decorateParam$5(2, Inject(CellAlertManagerService)),
81
+ __decorateParam$5(3, Inject(LocaleService)),
82
+ __decorateParam$5(4, Inject(FormulaDataModel)),
83
+ __decorateParam$5(5, IZenZoneService),
84
+ __decorateParam$5(6, Inject(INumfmtService))
85
+ ], NumfmtAlertRenderController);
86
+ const CloseNumfmtPanelOperator = {
84
87
  id: "sheet.operation.close.numfmt.panel",
85
- type: Be.OPERATION,
86
- handler: () => (
88
+ type: CommandType.OPERATION,
89
+ handler: /* @__PURE__ */ __name(() => (
87
90
  // do nothing, just notify panel is closed
88
91
  !0
89
- )
90
- }, A = {
92
+ ), "handler")
93
+ }, OpenNumfmtPanelOperator = {
91
94
  id: "sheet.operation.open.numfmt.panel",
92
- type: Be.OPERATION,
93
- handler: (t) => (t.get(B).openPanel(), !0)
95
+ type: CommandType.OPERATION,
96
+ handler: /* @__PURE__ */ __name((accessor) => (accessor.get(SheetNumfmtUIController).openPanel(), !0), "handler")
94
97
  };
95
- var fe = { exports: {} }, L = {};
96
- /**
97
- * @license React
98
- * react-jsx-runtime.production.min.js
99
- *
100
- * Copyright (c) Facebook, Inc. and its affiliates.
101
- *
102
- * This source code is licensed under the MIT license found in the
103
- * LICENSE file in the root directory of this source tree.
104
- */
105
- var Fe;
106
- function pn() {
107
- if (Fe) return L;
108
- Fe = 1;
109
- var t = ln, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), r = Object.prototype.hasOwnProperty, s = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, i = { key: !0, ref: !0, __self: !0, __source: !0 };
110
- function o(c, a, m) {
111
- var d, u = {}, h = null, p = null;
112
- m !== void 0 && (h = "" + m), a.key !== void 0 && (h = "" + a.key), a.ref !== void 0 && (p = a.ref);
113
- for (d in a) r.call(a, d) && !i.hasOwnProperty(d) && (u[d] = a[d]);
114
- if (c && c.defaultProps) for (d in a = c.defaultProps, a) u[d] === void 0 && (u[d] = a[d]);
115
- return { $$typeof: e, type: c, key: h, ref: p, props: u, _owner: s.current };
116
- }
117
- return L.Fragment = n, L.jsx = o, L.jsxs = o, L;
118
- }
119
- var Le;
120
- function vn() {
121
- return Le || (Le = 1, fe.exports = pn()), fe.exports;
122
- }
123
- var l = vn(), _n = Object.defineProperty, gn = Object.getOwnPropertyDescriptor, Sn = (t, e, n, r) => {
124
- for (var s = r > 1 ? void 0 : r ? gn(e, n) : e, i = t.length - 1, o; i >= 0; i--)
125
- (o = t[i]) && (s = (r ? o(e, n, s) : o(s)) || s);
126
- return r && s && _n(e, n, s), s;
127
- }, yn = (t, e) => (n, r) => e(n, r, t);
128
- const we = mn([]);
129
- let k = class {
130
- constructor(t) {
131
- this._localStorageService = t;
98
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
99
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
100
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
101
+ return kind && result && __defProp$4(target, key2, result), result;
102
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$4");
103
+ const UserHabitCurrencyContext = createContext([]);
104
+ var _a2;
105
+ let UserHabitController = (_a2 = class {
106
+ constructor(_localStorageService) {
107
+ this._localStorageService = _localStorageService;
132
108
  }
133
- _getKey(t) {
134
- return `userHabitController_${t}`;
109
+ _getKey(habit) {
110
+ return `userHabitController_${habit}`;
135
111
  }
136
- async addHabit(t, e) {
137
- const n = this._getKey(t);
138
- return this._localStorageService.getItem(n).then((r) => {
139
- r || this._localStorageService.setItem(n, e);
112
+ async addHabit(habit, initValue) {
113
+ const key2 = this._getKey(habit);
114
+ return this._localStorageService.getItem(key2).then((item) => {
115
+ item || this._localStorageService.setItem(key2, initValue);
140
116
  });
141
117
  }
142
- markHabit(t, e) {
143
- const n = this._getKey(t);
144
- this._localStorageService.getItem(n).then((r) => {
145
- if (r) {
146
- const s = r.findIndex((i) => i === e);
147
- s > -1 && r.splice(s, 1), r.unshift(e), this._localStorageService.setItem(n, r);
118
+ markHabit(habit, value) {
119
+ const key2 = this._getKey(habit);
120
+ this._localStorageService.getItem(key2).then((list) => {
121
+ if (list) {
122
+ const index = list.findIndex((item) => item === value);
123
+ index > -1 && list.splice(index, 1), list.unshift(value), this._localStorageService.setItem(key2, list);
148
124
  }
149
125
  });
150
126
  }
151
- async getHabit(t, e) {
152
- const n = this._getKey(t), r = await this._localStorageService.getItem(n);
153
- if (e && r) {
154
- const s = r.map((i, o, c) => {
155
- const a = c.length;
127
+ async getHabit(habit, sortList) {
128
+ const key2 = this._getKey(habit), result = await this._localStorageService.getItem(key2);
129
+ if (sortList && result) {
130
+ const priority = result.map((item, index, arr) => {
131
+ const length = arr.length;
156
132
  return {
157
- value: i,
158
- priority: a - o
133
+ value: item,
134
+ priority: length - index
159
135
  };
160
136
  });
161
- return e.sort((i, o) => {
162
- var m, d;
163
- const c = ((m = s.find((u) => u.value === i)) == null ? void 0 : m.priority) || -1;
164
- return (((d = s.find((u) => u.value === o)) == null ? void 0 : d.priority) || -1) - c;
137
+ return sortList.sort((a, b) => {
138
+ var _a7, _b;
139
+ const ap = ((_a7 = priority.find((item) => item.value === a)) == null ? void 0 : _a7.priority) || -1;
140
+ return (((_b = priority.find((item) => item.value === b)) == null ? void 0 : _b.priority) || -1) - ap;
165
141
  });
166
142
  }
167
- return r || [];
143
+ return result || [];
168
144
  }
169
- deleteHabit(t) {
170
- this._localStorageService.removeItem(t);
145
+ deleteHabit(habit) {
146
+ this._localStorageService.removeItem(habit);
171
147
  }
172
- };
173
- k = Sn([
174
- yn(0, S(We))
175
- ], k);
176
- const He = "numfmtCurrency", bn = (t) => {
177
- const e = b(k), [n, r] = C(Ue);
178
- return ae(() => {
179
- e.addHabit("numfmtCurrency", []).then(() => {
180
- e.getHabit(He, [...Ue]).then((i) => {
181
- r(i), t(i);
148
+ }, __name(_a2, "UserHabitController"), _a2);
149
+ UserHabitController = __decorateClass$4([
150
+ __decorateParam$4(0, Inject(ILocalStorageService))
151
+ ], UserHabitController);
152
+ const key$1 = "numfmtCurrency", useCurrencyOptions = /* @__PURE__ */ __name((onOptionChange) => {
153
+ const userHabitController = useDependency(UserHabitController), [options, optionsSet] = useState(currencySymbols);
154
+ return useEffect(() => {
155
+ userHabitController.addHabit("numfmtCurrency", []).then(() => {
156
+ userHabitController.getHabit(key$1, [...currencySymbols]).then((list) => {
157
+ optionsSet(list), onOptionChange(list);
182
158
  });
183
159
  });
184
- }, []), { userHabitCurrency: n, mark: (i) => {
185
- e.markHabit(He, i);
186
- } };
187
- }, Cn = () => {
188
- const t = xe([]), [e, n] = C({});
189
- return ae(() => {
190
- t.current.forEach((s) => {
191
- s();
192
- }), t.current = [];
193
- }, [e]), (s) => {
194
- t.current.push(s), n({});
195
- };
196
- }, In = (t) => !!W(t) && t.startsWith("_("), Nn = (t) => {
197
- const { defaultPattern: e, action: n, onChange: r } = t, [s, i] = C(() => te(e || "", 2)), o = nt(we), [c, a] = C(() => W(e) || o[0]), m = R(() => o.map((v) => ({ label: v, value: v })), []), u = b(T).t;
198
- n.current = () => M(`_("${c}"* #,##0${s > 0 ? ".0" : ""}_)`, s);
199
- const h = (v) => {
200
- a(v), r(M(`_("${v}"* #,##0${s > 0 ? ".0" : ""}_)`, s));
201
- }, p = (v) => {
202
- const f = v || 0;
203
- i(f), r(M(`_("${c}"* #,##0${f > 0 ? ".0" : ""}_)`, f));
204
- };
205
- return /* @__PURE__ */ l.jsxs("div", { children: [
206
- /* @__PURE__ */ l.jsxs("div", { className: "m-t-16 options", children: [
207
- /* @__PURE__ */ l.jsxs("div", { className: "option", children: [
208
- /* @__PURE__ */ l.jsx("div", { className: "label", children: u("sheet.numfmt.decimalLength") }),
209
- /* @__PURE__ */ l.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ l.jsx(Me, { value: s, max: 20, min: 0, onChange: p }) })
160
+ }, []), { userHabitCurrency: options, mark: /* @__PURE__ */ __name((v) => {
161
+ userHabitController.markHabit(key$1, v);
162
+ }, "mark") };
163
+ }, "useCurrencyOptions"), useNextTick = /* @__PURE__ */ __name(() => {
164
+ const effectList = useRef([]), [value, dispatch] = useState({});
165
+ return useEffect(() => {
166
+ effectList.current.forEach((fn) => {
167
+ fn();
168
+ }), effectList.current = [];
169
+ }, [value]), /* @__PURE__ */ __name((fn) => {
170
+ effectList.current.push(fn), dispatch({});
171
+ }, "nextTick");
172
+ }, "useNextTick"), isAccountingPanel = /* @__PURE__ */ __name((pattern) => !!getCurrencyType(pattern) && pattern.startsWith("_("), "isAccountingPanel"), AccountingPanel = /* @__PURE__ */ __name((props) => {
173
+ const { defaultPattern, action, onChange } = props, [decimal, decimalSet] = useState(() => getDecimalFromPattern(defaultPattern || "", 2)), userHabitCurrency = useContext(UserHabitCurrencyContext), [suffix, suffixSet] = useState(() => getCurrencyType(defaultPattern) || userHabitCurrency[0]), options = useMemo(() => userHabitCurrency.map((key2) => ({ label: key2, value: key2 })), []), t = useDependency(LocaleService).t;
174
+ action.current = () => setPatternDecimal(`_("${suffix}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal);
175
+ const onSelect = /* @__PURE__ */ __name((v) => {
176
+ suffixSet(v), onChange(setPatternDecimal(`_("${v}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal));
177
+ }, "onSelect"), onDecimalChange = /* @__PURE__ */ __name((v) => {
178
+ const decimal2 = v || 0;
179
+ decimalSet(decimal2), onChange(setPatternDecimal(`_("${suffix}"* #,##0${decimal2 > 0 ? ".0" : ""}_)`, decimal2));
180
+ }, "onDecimalChange");
181
+ return /* @__PURE__ */ jsxs("div", { children: [
182
+ /* @__PURE__ */ jsxs("div", { className: "m-t-16 options", children: [
183
+ /* @__PURE__ */ jsxs("div", { className: "option", children: [
184
+ /* @__PURE__ */ jsx("div", { className: "label", children: t("sheet.numfmt.decimalLength") }),
185
+ /* @__PURE__ */ jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ jsx(InputNumber, { value: decimal, max: 20, min: 0, onChange: onDecimalChange }) })
210
186
  ] }),
211
- /* @__PURE__ */ l.jsxs("div", { className: "option", children: [
212
- /* @__PURE__ */ l.jsx("div", { className: "label", children: u("sheet.numfmt.currencyType") }),
213
- /* @__PURE__ */ l.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ l.jsx(Re, { onChange: h, options: m, value: c }) })
187
+ /* @__PURE__ */ jsxs("div", { className: "option", children: [
188
+ /* @__PURE__ */ jsx("div", { className: "label", children: t("sheet.numfmt.currencyType") }),
189
+ /* @__PURE__ */ jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ jsx(Select, { onChange: onSelect, options, value: suffix }) })
214
190
  ] })
215
191
  ] }),
216
- /* @__PURE__ */ l.jsx("div", { className: "describe m-t-14", children: u("sheet.numfmt.accountingDes") })
192
+ /* @__PURE__ */ jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.accountingDes") })
217
193
  ] });
218
- }, En = (t) => !!W(t) && !t.startsWith("_("), Tn = (t) => {
219
- const n = b(T).t, r = nt(we), [s, i] = C(() => W(t.defaultPattern) || r[0]), [o, c] = C(() => te(t.defaultPattern || "", 2)), [a, m] = C(() => {
220
- var _;
221
- const f = ue(s);
222
- return ((_ = f.find((I) => ce(I.value, t.defaultPattern))) == null ? void 0 : _.value) || f[0].value;
223
- }), d = R(() => ue(s), [s]), u = R(() => r.map((f) => ({ label: f, value: f })), [r]);
224
- t.action.current = () => M(a, o);
225
- const h = (f) => {
226
- if (f === void 0)
194
+ }, "AccountingPanel"), isCurrencyPanel = /* @__PURE__ */ __name((pattern) => !!getCurrencyType(pattern) && !pattern.startsWith("_("), "isCurrencyPanel"), CurrencyPanel = /* @__PURE__ */ __name((props) => {
195
+ 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(() => {
196
+ var _a7;
197
+ const negativeOptions2 = getCurrencyFormatOptions(suffix);
198
+ return ((_a7 = negativeOptions2.find((item) => isPatternEqualWithoutDecimal(item.value, props.defaultPattern))) == null ? void 0 : _a7.value) || negativeOptions2[0].value;
199
+ }), negativeOptions = useMemo(() => getCurrencyFormatOptions(suffix), [suffix]), options = useMemo(() => userHabitCurrency.map((key2) => ({ label: key2, value: key2 })), [userHabitCurrency]);
200
+ props.action.current = () => setPatternDecimal(pattern, decimal);
201
+ const onSelect = /* @__PURE__ */ __name((value) => {
202
+ if (value === void 0)
227
203
  return;
228
- i(f);
229
- const y = ue(f)[0].value;
230
- m(y), t.onChange(M(y, o));
231
- }, p = (f) => {
232
- f !== void 0 && (m(f), t.onChange(M(f, o)));
233
- }, v = (f) => {
234
- c(f || 0), t.onChange(M(a, f || 0));
235
- };
236
- return /* @__PURE__ */ l.jsxs("div", { children: [
237
- /* @__PURE__ */ l.jsxs("div", { className: "m-t-16 options", children: [
238
- /* @__PURE__ */ l.jsxs("div", { className: "option", children: [
239
- /* @__PURE__ */ l.jsx("div", { className: "label", children: n("sheet.numfmt.decimalLength") }),
240
- /* @__PURE__ */ l.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ l.jsx(Me, { value: o, max: 20, min: 0, onChange: v }) })
204
+ suffixSet(value);
205
+ const pattern2 = getCurrencyFormatOptions(value)[0].value;
206
+ patternSet(pattern2), props.onChange(setPatternDecimal(pattern2, decimal));
207
+ }, "onSelect"), onChange = /* @__PURE__ */ __name((value) => {
208
+ value !== void 0 && (patternSet(value), props.onChange(setPatternDecimal(value, decimal)));
209
+ }, "onChange"), onDecimalChange = /* @__PURE__ */ __name((v) => {
210
+ decimalSet(v || 0), props.onChange(setPatternDecimal(pattern, v || 0));
211
+ }, "onDecimalChange");
212
+ return /* @__PURE__ */ jsxs("div", { children: [
213
+ /* @__PURE__ */ jsxs("div", { className: "m-t-16 options", children: [
214
+ /* @__PURE__ */ jsxs("div", { className: "option", children: [
215
+ /* @__PURE__ */ jsx("div", { className: "label", children: t("sheet.numfmt.decimalLength") }),
216
+ /* @__PURE__ */ jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ jsx(InputNumber, { value: decimal, max: 20, min: 0, onChange: onDecimalChange }) })
241
217
  ] }),
242
- /* @__PURE__ */ l.jsxs("div", { className: "option", children: [
243
- /* @__PURE__ */ l.jsx("div", { className: "label", children: n("sheet.numfmt.currencyType") }),
244
- /* @__PURE__ */ l.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ l.jsx(Re, { onChange: h, options: u, value: s }) })
218
+ /* @__PURE__ */ jsxs("div", { className: "option", children: [
219
+ /* @__PURE__ */ jsx("div", { className: "label", children: t("sheet.numfmt.currencyType") }),
220
+ /* @__PURE__ */ jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ jsx(Select, { onChange: onSelect, options, value: suffix }) })
245
221
  ] })
246
222
  ] }),
247
- /* @__PURE__ */ l.jsx("div", { className: "m-t-16 label", children: n("sheet.numfmt.negType") }),
248
- /* @__PURE__ */ l.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ l.jsx(je, { onChange: p, options: d, value: a }) }),
249
- /* @__PURE__ */ l.jsx("div", { className: "describe m-t-14", children: n("sheet.numfmt.currencyDes") })
223
+ /* @__PURE__ */ jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.negType") }),
224
+ /* @__PURE__ */ jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsx(SelectList, { onChange, options: negativeOptions, value: pattern }) }),
225
+ /* @__PURE__ */ jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.currencyDes") })
250
226
  ] });
251
- };
252
- var N = function() {
253
- return N = Object.assign || function(t) {
254
- for (var e, n = 1, r = arguments.length; n < r; n++) {
255
- e = arguments[n];
256
- for (var s in e) Object.prototype.hasOwnProperty.call(e, s) && (t[s] = e[s]);
227
+ }, "CurrencyPanel");
228
+ var __assign = function() {
229
+ return __assign = Object.assign || function(t) {
230
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
231
+ s = arguments[i];
232
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
257
233
  }
258
234
  return t;
259
- }, N.apply(this, arguments);
260
- }, xn = function(t, e) {
261
- var n = {};
262
- for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && e.indexOf(r) < 0 && (n[r] = t[r]);
263
- if (t != null && typeof Object.getOwnPropertySymbols == "function")
264
- for (var s = 0, r = Object.getOwnPropertySymbols(t); s < r.length; s++)
265
- e.indexOf(r[s]) < 0 && Object.prototype.propertyIsEnumerable.call(t, r[s]) && (n[r[s]] = t[r[s]]);
266
- return n;
267
- }, st = rt(function(t, e) {
268
- var n = t.icon, r = t.id, s = t.className, i = t.extend, o = xn(t, ["icon", "id", "className", "extend"]), c = "univerjs-icon univerjs-icon-".concat(r, " ").concat(s || "").trim(), a = xe("_".concat(Rn()));
269
- return it(n, "".concat(r), { defIds: n.defIds, idSuffix: a.current }, N({ ref: e, className: c }, o), i);
235
+ }, __assign.apply(this, arguments);
236
+ }, __rest = function(s, e) {
237
+ var t = {};
238
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
239
+ if (s != null && typeof Object.getOwnPropertySymbols == "function")
240
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
241
+ e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
242
+ return t;
243
+ }, IconBase = forwardRef(function(props, ref) {
244
+ 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()));
245
+ return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
270
246
  });
271
- function it(t, e, n, r, s) {
272
- return Pe(t.tag, N(N({ key: e }, Pn(t, n, s)), r), (Mn(t, n).children || []).map(function(i, o) {
273
- return it(i, "".concat(e, "-").concat(t.tag, "-").concat(o), n, void 0, s);
247
+ function render(node, id, runtimeProps, rootProps, extend) {
248
+ return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
249
+ return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
274
250
  }));
275
251
  }
276
- function Pn(t, e, n) {
277
- var r = N({}, t.attrs);
278
- n != null && n.colorChannel1 && r.fill === "colorChannel1" && (r.fill = n.colorChannel1);
279
- var s = e.defIds;
280
- return !s || s.length === 0 || (t.tag === "use" && r["xlink:href"] && (r["xlink:href"] = r["xlink:href"] + e.idSuffix), Object.entries(r).forEach(function(i) {
281
- var o = i[0], c = i[1];
282
- typeof c == "string" && (r[o] = c.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
283
- })), r;
252
+ __name(render, "render");
253
+ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
254
+ var attrs = __assign({}, node.attrs);
255
+ extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
256
+ var defIds = runtimeProps.defIds;
257
+ return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a7) {
258
+ var key2 = _a7[0], value = _a7[1];
259
+ typeof value == "string" && (attrs[key2] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
260
+ })), attrs;
284
261
  }
285
- function Mn(t, e) {
286
- var n, r = e.defIds;
287
- return !r || r.length === 0 ? t : t.tag === "defs" && (!((n = t.children) === null || n === void 0) && n.length) ? N(N({}, t), { children: t.children.map(function(s) {
288
- return typeof s.attrs.id == "string" && r && r.indexOf(s.attrs.id) > -1 ? N(N({}, s), { attrs: N(N({}, s.attrs), { id: s.attrs.id + e.idSuffix }) }) : s;
289
- }) }) : t;
262
+ __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
263
+ function replaceRuntimeIdsInDefs(node, runtimeProps) {
264
+ var _a7, defIds = runtimeProps.defIds;
265
+ return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a7 = node.children) === null || _a7 === void 0) && _a7.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
266
+ 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;
267
+ }) }) : node;
290
268
  }
291
- function Rn() {
269
+ __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
270
+ function generateShortUuid() {
292
271
  return Math.random().toString(36).substring(2, 8);
293
272
  }
294
- st.displayName = "UniverIcon";
295
- var jn = { 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" } }] }, ot = rt(function(t, e) {
296
- return Pe(st, Object.assign({}, t, {
273
+ __name(generateShortUuid, "generateShortUuid");
274
+ IconBase.displayName = "UniverIcon";
275
+ 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) {
276
+ return createElement(IconBase, Object.assign({}, props, {
297
277
  id: "check-mark-single",
298
- ref: e,
299
- icon: jn
278
+ ref,
279
+ icon: element
300
280
  }));
301
281
  });
302
- ot.displayName = "CheckMarkSingle";
303
- const wn = "univer-custom-format-title", On = "univer-custom-format-input", Un = "univer-custom-format-history-list", $n = "univer-custom-format-history-list-item", Dn = "univer-custom-format-history-list-item-icon-wrap", Fn = "univer-custom-format-des", j = {
304
- customFormatTitle: wn,
305
- customFormatInput: On,
306
- customFormatHistoryList: Un,
307
- customFormatHistoryListItem: $n,
308
- customFormatHistoryListItemIconWrap: Dn,
309
- customFormatDes: Fn
310
- }, pe = "customFormat", ve = "numfmt_custom_pattern";
311
- function Ln(t) {
312
- const { defaultPattern: e, action: n, onChange: r } = t, s = b(k), i = b(We), o = b(T), [c, a] = C(e);
313
- n.current = () => (s.markHabit(pe, c), i.getItem(ve).then((p = []) => {
314
- const v = [.../* @__PURE__ */ new Set([c, ...p || []])].splice(0, 10).filter((f) => !!f);
315
- i.setItem(ve, v);
316
- }), c);
317
- const [m, d] = C([]);
318
- ae(() => {
319
- i.getItem(ve).then((p) => {
320
- const v = [
321
- ...Tt.map((f) => f.suffix("$")),
322
- ...xt.map((f) => f.suffix),
323
- ...Pt.map((f) => f.suffix)
282
+ CheckMarkSingle.displayName = "CheckMarkSingle";
283
+ 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 = {
284
+ customFormatTitle,
285
+ customFormatInput,
286
+ customFormatHistoryList,
287
+ customFormatHistoryListItem,
288
+ customFormatHistoryListItemIconWrap,
289
+ customFormatDes
290
+ }, key = "customFormat", historyPatternKey = "numfmt_custom_pattern";
291
+ function CustomFormat(props) {
292
+ const { defaultPattern, action, onChange } = props, userHabitController = useDependency(UserHabitController), localStorageService = useDependency(ILocalStorageService), localeService = useDependency(LocaleService), [pattern, patternSet] = useState(defaultPattern);
293
+ action.current = () => (userHabitController.markHabit(key, pattern), localStorageService.getItem(historyPatternKey).then((list = []) => {
294
+ const _list = [.../* @__PURE__ */ new Set([pattern, ...list || []])].splice(0, 10).filter((e) => !!e);
295
+ localStorageService.setItem(historyPatternKey, _list);
296
+ }), pattern);
297
+ const [options, optionsSet] = useState([]);
298
+ useEffect(() => {
299
+ localStorageService.getItem(historyPatternKey).then((historyList) => {
300
+ const list = [
301
+ ...CURRENCYFORMAT.map((item) => item.suffix("$")),
302
+ ...DATEFMTLISG.map((item) => item.suffix),
303
+ ...NUMBERFORMAT.map((item) => item.suffix)
324
304
  ];
325
- v.push(...p || []), s.addHabit(pe, []).finally(() => {
326
- s.getHabit(pe, v).then((f) => {
327
- d([...new Set(f)]);
305
+ list.push(...historyList || []), userHabitController.addHabit(key, []).finally(() => {
306
+ userHabitController.getHabit(key, list).then((list2) => {
307
+ optionsSet([...new Set(list2)]);
328
308
  });
329
309
  });
330
310
  });
331
311
  }, []);
332
- const u = (p) => {
333
- a(p), r(p);
334
- }, h = () => {
335
- r(c);
336
- };
337
- return /* @__PURE__ */ l.jsxs("div", { className: j.customFormat, children: [
338
- /* @__PURE__ */ l.jsx("div", { className: j.customFormatTitle, children: o.t("sheet.numfmt.customFormat") }),
339
- /* @__PURE__ */ l.jsx(un, { placeholder: o.t("sheet.numfmt.customFormat"), onBlur: h, value: c, onChange: a, className: j.customFormatInput }),
340
- /* @__PURE__ */ l.jsx("div", { className: j.customFormatHistoryList, children: m.map((p) => /* @__PURE__ */ l.jsxs("div", { onClick: () => u(p), className: j.customFormatHistoryListItem, children: [
341
- /* @__PURE__ */ l.jsx("div", { className: j.customFormatHistoryListItemIconWrap, children: c === p && /* @__PURE__ */ l.jsx(ot, {}) }),
342
- /* @__PURE__ */ l.jsx("div", { children: p })
312
+ const handleClick = /* @__PURE__ */ __name((p) => {
313
+ patternSet(p), onChange(p);
314
+ }, "handleClick"), handleBlur = /* @__PURE__ */ __name(() => {
315
+ onChange(pattern);
316
+ }, "handleBlur");
317
+ return /* @__PURE__ */ jsxs("div", { className: styles.customFormat, children: [
318
+ /* @__PURE__ */ jsx("div", { className: styles.customFormatTitle, children: localeService.t("sheet.numfmt.customFormat") }),
319
+ /* @__PURE__ */ jsx(Input, { placeholder: localeService.t("sheet.numfmt.customFormat"), onBlur: handleBlur, value: pattern, onChange: patternSet, className: styles.customFormatInput }),
320
+ /* @__PURE__ */ jsx("div", { className: styles.customFormatHistoryList, children: options.map((p) => /* @__PURE__ */ jsxs("div", { onClick: /* @__PURE__ */ __name(() => handleClick(p), "onClick"), className: styles.customFormatHistoryListItem, children: [
321
+ /* @__PURE__ */ jsx("div", { className: styles.customFormatHistoryListItemIconWrap, children: pattern === p && /* @__PURE__ */ jsx(CheckMarkSingle, {}) }),
322
+ /* @__PURE__ */ jsx("div", { children: p })
343
323
  ] }, p)) }),
344
- /* @__PURE__ */ l.jsx("div", { className: j.customFormatDes, children: o.t("sheet.numfmt.customFormatDes") })
324
+ /* @__PURE__ */ jsx("div", { className: styles.customFormatDes, children: localeService.t("sheet.numfmt.customFormatDes") })
345
325
  ] });
346
326
  }
347
- const Hn = (t) => {
348
- const e = Q.getInfo(t);
349
- return qe().map((n) => n.value).includes(t) || ["date", "datetime", "time"].includes(e.type);
350
- }, An = (t) => {
351
- const e = R(qe, []), r = b(T).t, [s, i] = C(() => {
352
- if (t.defaultPattern) {
353
- const c = e.find((a) => a.value === t.defaultPattern);
354
- if (c)
355
- return c.value;
327
+ __name(CustomFormat, "CustomFormat");
328
+ const isDatePanel = /* @__PURE__ */ __name((pattern) => {
329
+ const info = numfmt.getInfo(pattern);
330
+ return getDateFormatOptions().map((item) => item.value).includes(pattern) || ["date", "datetime", "time"].includes(info.type);
331
+ }, "isDatePanel"), DatePanel = /* @__PURE__ */ __name((props) => {
332
+ const options = useMemo(getDateFormatOptions, []), t = useDependency(LocaleService).t, [suffix, suffixSet] = useState(() => {
333
+ if (props.defaultPattern) {
334
+ const item = options.find((item2) => item2.value === props.defaultPattern);
335
+ if (item)
336
+ return item.value;
356
337
  }
357
- return e[0].value;
338
+ return options[0].value;
358
339
  });
359
- t.action.current = () => s;
360
- const o = (c) => {
361
- c !== void 0 && (i(c), t.onChange(c));
362
- };
363
- return /* @__PURE__ */ l.jsxs("div", { children: [
364
- /* @__PURE__ */ l.jsx("div", { className: "m-t-16 label", children: r("sheet.numfmt.dateType") }),
365
- /* @__PURE__ */ l.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ l.jsx(je, { value: s, options: e, onChange: o }) }),
366
- /* @__PURE__ */ l.jsx("div", { className: "describe m-t-14", children: r("sheet.numfmt.dateDes") })
340
+ props.action.current = () => suffix;
341
+ const onChange = /* @__PURE__ */ __name((v) => {
342
+ v !== void 0 && (suffixSet(v), props.onChange(v));
343
+ }, "onChange");
344
+ return /* @__PURE__ */ jsxs("div", { children: [
345
+ /* @__PURE__ */ jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.dateType") }),
346
+ /* @__PURE__ */ jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsx(SelectList, { value: suffix, options, onChange }) }),
347
+ /* @__PURE__ */ jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.dateDes") })
367
348
  ] });
368
- }, kn = (t) => !t, Bn = (t) => {
369
- const n = b(T).t;
370
- return t.action.current = () => "", /* @__PURE__ */ l.jsx("div", { children: /* @__PURE__ */ l.jsx("div", { className: "describe m-t-14", children: n("sheet.numfmt.generalDes") }) });
371
- }, Wn = (t) => Ye().some((e) => ce(e.value, t)), Vn = (t) => {
372
- const e = b(T), n = R(Ye, []), [r, s] = C(() => te(t.defaultPattern || "", 0)), [i, o] = C(() => {
373
- const u = n.find((h) => ce(h.value, t.defaultPattern || ""));
374
- return (u == null ? void 0 : u.value) || n[0].value;
375
- }), c = R(() => M(i, Number(r || 0)), [i, r]), a = R(() => !Mt(i), [i]), m = (u) => {
376
- s(u || 0), t.onChange(M(i, Number(u || 0)));
377
- }, d = (u) => {
378
- u !== void 0 && (s(te(u, 0)), o(u), t.onChange(u));
379
- };
380
- return t.action.current = () => c, /* @__PURE__ */ l.jsxs("div", { children: [
381
- /* @__PURE__ */ l.jsx("div", { className: "m-t-16 label", children: e.t("sheet.numfmt.decimalLength") }),
382
- /* @__PURE__ */ l.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ l.jsx(
383
- Me,
349
+ }, "DatePanel"), isGeneralPanel = /* @__PURE__ */ __name((pattern) => !pattern, "isGeneralPanel"), GeneralPanel = /* @__PURE__ */ __name((props) => {
350
+ const t = useDependency(LocaleService).t;
351
+ return props.action.current = () => "", /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.generalDes") }) });
352
+ }, "GeneralPanel"), isThousandthPercentilePanel = /* @__PURE__ */ __name((pattern) => getNumberFormatOptions().some((item) => isPatternEqualWithoutDecimal(item.value, pattern)), "isThousandthPercentilePanel"), ThousandthPercentilePanel = /* @__PURE__ */ __name((props) => {
353
+ const localeService = useDependency(LocaleService), options = useMemo(getNumberFormatOptions, []), [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 0)), [suffix, suffixSet] = useState(() => {
354
+ const item = options.find((item2) => isPatternEqualWithoutDecimal(item2.value, props.defaultPattern || ""));
355
+ return (item == null ? void 0 : item.value) || options[0].value;
356
+ }), pattern = useMemo(() => setPatternDecimal(suffix, Number(decimal || 0)), [suffix, decimal]), isInputDisable = useMemo(() => !isPatternHasDecimal(suffix), [suffix]), handleDecimalChange = /* @__PURE__ */ __name((decimal2) => {
357
+ decimalSet(decimal2 || 0), props.onChange(setPatternDecimal(suffix, Number(decimal2 || 0)));
358
+ }, "handleDecimalChange"), handleClick = /* @__PURE__ */ __name((v) => {
359
+ v !== void 0 && (decimalSet(getDecimalFromPattern(v, 0)), suffixSet(v), props.onChange(v));
360
+ }, "handleClick");
361
+ return props.action.current = () => pattern, /* @__PURE__ */ jsxs("div", { children: [
362
+ /* @__PURE__ */ jsx("div", { className: "m-t-16 label", children: localeService.t("sheet.numfmt.decimalLength") }),
363
+ /* @__PURE__ */ jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsx(
364
+ InputNumber,
384
365
  {
385
- disabled: a,
386
- value: r,
366
+ disabled: isInputDisable,
367
+ value: decimal,
387
368
  max: 20,
388
369
  min: 0,
389
- onChange: m
370
+ onChange: handleDecimalChange
390
371
  }
391
372
  ) }),
392
- /* @__PURE__ */ l.jsxs("div", { className: "m-t-16 label", children: [
373
+ /* @__PURE__ */ jsxs("div", { className: "m-t-16 label", children: [
393
374
  " ",
394
- e.t("sheet.numfmt.negType")
375
+ localeService.t("sheet.numfmt.negType")
395
376
  ] }),
396
- /* @__PURE__ */ l.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ l.jsx(je, { onChange: d, options: n, value: i }) }),
397
- /* @__PURE__ */ l.jsx("div", { className: "describe m-t-14", children: e.t("sheet.numfmt.thousandthPercentileDes") })
377
+ /* @__PURE__ */ jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsx(SelectList, { onChange: handleClick, options, value: suffix }) }),
378
+ /* @__PURE__ */ jsx("div", { className: "describe m-t-14", children: localeService.t("sheet.numfmt.thousandthPercentileDes") })
398
379
  ] });
399
- }, Gn = (t) => {
400
- const { defaultValue: e, defaultPattern: n, row: r, col: s } = t.value, i = b(T), o = xe(() => ""), c = i.t, a = Cn(), m = R(
380
+ }, "ThousandthPercentilePanel"), SheetNumfmtPanel = /* @__PURE__ */ __name((props) => {
381
+ const { defaultValue, defaultPattern, row, col } = props.value, localeService = useDependency(LocaleService), getCurrentPattern = useRef(() => ""), t = localeService.t, nextTick = useNextTick(), typeOptions = useMemo(
401
382
  () => [
402
- { label: "sheet.numfmt.general", component: Bn },
403
- { label: "sheet.numfmt.accounting", component: Nn },
404
- { label: "sheet.numfmt.currency", component: Tn },
405
- { label: "sheet.numfmt.date", component: An },
406
- { label: "sheet.numfmt.thousandthPercentile", component: Vn },
407
- { label: "sheet.numfmt.customFormat", component: Ln }
408
- ].map((g) => ({ ...g, label: c(g.label) })),
383
+ { label: "sheet.numfmt.general", component: GeneralPanel },
384
+ { label: "sheet.numfmt.accounting", component: AccountingPanel },
385
+ { label: "sheet.numfmt.currency", component: CurrencyPanel },
386
+ { label: "sheet.numfmt.date", component: DatePanel },
387
+ { label: "sheet.numfmt.thousandthPercentile", component: ThousandthPercentilePanel },
388
+ { label: "sheet.numfmt.customFormat", component: CustomFormat }
389
+ ].map((item) => ({ ...item, label: t(item.label) })),
409
390
  []
410
- ), [d, u] = C(_), [h, p] = C(() => `${r}_${s}`), { mark: v, userHabitCurrency: f } = bn(() => p(`${r}_${s}_userCurrency'`)), y = R(() => {
411
- var g;
412
- return (g = m.find((w) => w.label === d)) == null ? void 0 : g.component;
413
- }, [d]);
414
- function _() {
415
- return [kn, In, En, Hn, Wn].reduce((w, ut, dt) => w || (ut(n) ? m[dt].label : ""), "") || m[0].label;
391
+ ), [type, typeSet] = useState(findDefaultType), [key2, keySet] = useState(() => `${row}_${col}`), { mark, userHabitCurrency } = useCurrencyOptions(() => keySet(`${row}_${col}_userCurrency'`)), BusinessComponent = useMemo(() => {
392
+ var _a7;
393
+ return (_a7 = typeOptions.find((item) => item.label === type)) == null ? void 0 : _a7.component;
394
+ }, [type]);
395
+ function findDefaultType() {
396
+ return [isGeneralPanel, isAccountingPanel, isCurrencyPanel, isDatePanel, isThousandthPercentilePanel].reduce((pre, curFn, index) => pre || (curFn(defaultPattern) ? typeOptions[index].label : ""), "") || typeOptions[0].label;
416
397
  }
417
- const I = m.map((g) => ({
418
- label: g.label,
419
- value: g.label
420
- })), x = (g) => {
421
- u(g), a(() => t.onChange({ type: "change", value: o.current() || "" }));
422
- }, J = (g) => {
423
- t.onChange({ type: "change", value: g });
424
- }, le = () => {
425
- const g = o.current() || "", w = W(g);
426
- w && v(w), t.onChange({ type: "confirm", value: g });
427
- }, F = () => {
428
- t.onChange({ type: "cancel", value: "" });
429
- }, me = {
430
- onChange: J,
431
- defaultValue: e,
432
- defaultPattern: n,
433
- action: o
398
+ __name(findDefaultType, "findDefaultType");
399
+ const selectOptions = typeOptions.map((option) => ({
400
+ label: option.label,
401
+ value: option.label
402
+ })), handleSelect = /* @__PURE__ */ __name((value) => {
403
+ typeSet(value), nextTick(() => props.onChange({ type: "change", value: getCurrentPattern.current() || "" }));
404
+ }, "handleSelect"), handleChange = /* @__PURE__ */ __name((v) => {
405
+ props.onChange({ type: "change", value: v });
406
+ }, "handleChange"), handleConfirm = /* @__PURE__ */ __name(() => {
407
+ const pattern = getCurrentPattern.current() || "", currency = getCurrencyType(pattern);
408
+ currency && mark(currency), props.onChange({ type: "confirm", value: pattern });
409
+ }, "handleConfirm"), handleCancel = /* @__PURE__ */ __name(() => {
410
+ props.onChange({ type: "cancel", value: "" });
411
+ }, "handleCancel"), subProps = {
412
+ onChange: handleChange,
413
+ defaultValue,
414
+ defaultPattern,
415
+ action: getCurrentPattern
434
416
  };
435
- return ae(() => {
436
- u(_()), p(`${r}_${s}`);
437
- }, [r, s]), /* @__PURE__ */ l.jsxs("div", { className: "numfmt-panel p-b-20", children: [
438
- /* @__PURE__ */ l.jsxs("div", { children: [
439
- /* @__PURE__ */ l.jsx("div", { className: "label m-t-14", children: c("sheet.numfmt.numfmtType") }),
440
- /* @__PURE__ */ l.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ l.jsx(Re, { onChange: x, options: I, value: d, style: { width: "100%" } }) }),
441
- /* @__PURE__ */ l.jsx("div", { children: y && /* @__PURE__ */ l.jsx(we.Provider, { value: f, children: /* @__PURE__ */ Pe(y, { ...me, key: h }) }) })
417
+ return useEffect(() => {
418
+ typeSet(findDefaultType()), keySet(`${row}_${col}`);
419
+ }, [row, col]), /* @__PURE__ */ jsxs("div", { className: "numfmt-panel p-b-20", children: [
420
+ /* @__PURE__ */ jsxs("div", { children: [
421
+ /* @__PURE__ */ jsx("div", { className: "label m-t-14", children: t("sheet.numfmt.numfmtType") }),
422
+ /* @__PURE__ */ jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsx(Select, { onChange: handleSelect, options: selectOptions, value: type, style: { width: "100%" } }) }),
423
+ /* @__PURE__ */ jsx("div", { children: BusinessComponent && /* @__PURE__ */ jsx(UserHabitCurrencyContext.Provider, { value: userHabitCurrency, children: /* @__PURE__ */ createElement(BusinessComponent, { ...subProps, key: key2 }) }) })
442
424
  ] }),
443
- /* @__PURE__ */ l.jsxs("div", { className: "btn-list m-t-14 m-b-20", children: [
444
- /* @__PURE__ */ l.jsx($e, { size: "small", onClick: F, className: "m-r-12", children: c("sheet.numfmt.cancel") }),
445
- /* @__PURE__ */ l.jsx($e, { type: "primary", size: "small", onClick: le, children: c("sheet.numfmt.confirm") })
425
+ /* @__PURE__ */ jsxs("div", { className: "btn-list m-t-14 m-b-20", children: [
426
+ /* @__PURE__ */ jsx(Button, { size: "small", onClick: handleCancel, className: "m-r-12", children: t("sheet.numfmt.cancel") }),
427
+ /* @__PURE__ */ jsx(Button, { type: "primary", size: "small", onClick: handleConfirm, children: t("sheet.numfmt.confirm") })
446
428
  ] })
447
429
  ] });
448
- };
449
- var Kn = Object.defineProperty, qn = Object.getOwnPropertyDescriptor, Yn = (t, e, n, r) => {
450
- for (var s = r > 1 ? void 0 : r ? qn(e, n) : e, i = t.length - 1, o; i >= 0; i--)
451
- (o = t[i]) && (s = (r ? o(e, n, s) : o(s)) || s);
452
- return r && s && Kn(e, n, s), s;
453
- }, P = (t, e) => (n, r) => e(n, r, t);
454
- const Ae = "SHEET_NUMFMT_PANEL";
455
- let B = class extends oe {
456
- constructor(e, n, r, s, i, o, c, a, m, d) {
430
+ }, "SheetNumfmtPanel");
431
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
432
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
433
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
434
+ return kind && result && __defProp$3(target, key2, result), result;
435
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$3");
436
+ const SHEET_NUMFMT_PANEL = "SHEET_NUMFMT_PANEL";
437
+ var _a3;
438
+ let SheetNumfmtUIController = (_a3 = class extends Disposable {
439
+ constructor(_sheetInterceptorService, _themeService, _univerInstanceService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _sidebarService, _localeService, _sheetsNumfmtCellContentController) {
457
440
  super();
458
441
  /**
459
442
  * If _previewPattern is null ,the realTimeRenderingInterceptor will skip and if it is '',realTimeRenderingInterceptor will clear numfmt.
@@ -461,225 +444,235 @@ let B = class extends oe {
461
444
  * @type {(string | null)}
462
445
  * @memberof NumfmtController
463
446
  */
464
- X(this, "_previewPattern", "");
465
- X(this, "_sidebarDisposable", null);
466
- this._sheetInterceptorService = e, this._themeService = n, this._univerInstanceService = r, this._commandService = s, this._selectionManagerService = i, this._renderManagerService = o, this._numfmtService = c, this._componentManager = a, this._sidebarService = m, this._localeService = d, this._initRealTimeRenderingInterceptor(), this._initPanel(), this._initCommands(), this._initCloseListener(), this._commandExecutedListener();
447
+ __publicField(this, "_previewPattern", "");
448
+ __publicField(this, "_sidebarDisposable", null);
449
+ 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._sheetsNumfmtCellContentController = _sheetsNumfmtCellContentController, this._initRealTimeRenderingInterceptor(), this._initPanel(), this._initCommands(), this._initCloseListener(), this._commandExecutedListener(), this._initNumfmtLocalChange();
450
+ }
451
+ _initNumfmtLocalChange() {
452
+ this.disposeWithMe(merge(this._sheetsNumfmtCellContentController.local$, this._localeService.currentLocale$).subscribe(() => {
453
+ this._forceUpdate();
454
+ }));
467
455
  }
468
456
  openPanel() {
469
- var y;
470
- const e = this._sidebarService, n = this._selectionManagerService, r = this._commandService, s = this._univerInstanceService, i = this._numfmtService, o = this._localeService, a = (((y = n.getCurrentSelections()) == null ? void 0 : y.map((_) => _.range)) || [])[0];
471
- if (!a)
457
+ var _a7;
458
+ const sidebarService = this._sidebarService, selectionManagerService = this._selectionManagerService, commandService = this._commandService, univerInstanceService = this._univerInstanceService, numfmtService = this._numfmtService, localeService = this._localeService, range = (((_a7 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a7.map((s) => s.range)) || [])[0];
459
+ if (!range)
472
460
  return !1;
473
- const m = s.getCurrentUnitForType(E.UNIVER_SHEET), d = m.getActiveSheet();
474
- if (!d)
461
+ const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), sheet = workbook.getActiveSheet();
462
+ if (!sheet)
475
463
  return !1;
476
- const u = d.getCellRaw(a.startRow, a.startColumn), h = i.getValue(
477
- m.getUnitId(),
478
- d.getSheetId(),
479
- a.startRow,
480
- a.startColumn
464
+ const cellValue = sheet.getCellRaw(range.startRow, range.startColumn), numfmtValue = numfmtService.getValue(
465
+ workbook.getUnitId(),
466
+ sheet.getSheetId(),
467
+ range.startRow,
468
+ range.startColumn
481
469
  );
482
- let p = "";
483
- h && (p = h.pattern);
484
- const v = (u == null ? void 0 : u.t) === $.NUMBER ? u.v : 12345678, f = {
485
- onChange: (_) => {
486
- var I;
487
- if (_.type === "change")
488
- this._previewPattern = _.value, this._forceUpdate();
489
- else if (_.type === "confirm") {
490
- const x = ((I = n.getCurrentSelections()) == null ? void 0 : I.map((F) => F.range)) || [], J = { values: [] }, le = ne(_.value);
491
- x.forEach((F) => {
492
- Ve.foreach(F, (me, g) => {
493
- J.values.push({
494
- row: me,
495
- col: g,
496
- pattern: _.value,
497
- type: le
470
+ let pattern = "";
471
+ numfmtValue && (pattern = numfmtValue.pattern);
472
+ const defaultValue = (cellValue == null ? void 0 : cellValue.t) === CellValueType.NUMBER ? cellValue.v : 12345678, props = {
473
+ onChange: /* @__PURE__ */ __name((config) => {
474
+ var _a8;
475
+ if (config.type === "change")
476
+ this._previewPattern = config.value, this._forceUpdate();
477
+ else if (config.type === "confirm") {
478
+ const selections2 = ((_a8 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a8.map((s) => s.range)) || [], params = { values: [] }, patternType = getPatternType(config.value);
479
+ selections2.forEach((rangeInfo) => {
480
+ Range.foreach(rangeInfo, (row, col) => {
481
+ params.values.push({
482
+ row,
483
+ col,
484
+ pattern: config.value,
485
+ type: patternType
498
486
  });
499
487
  });
500
- }), r.executeCommand(Ze.id, J), e.close();
501
- } else _.type === "cancel" && e.close();
502
- },
503
- value: { defaultPattern: p, defaultValue: v, row: a.startRow, col: a.startColumn }
488
+ }), commandService.executeCommand(SetNumfmtCommand.id, params), sidebarService.close();
489
+ } else config.type === "cancel" && sidebarService.close();
490
+ }, "onChange"),
491
+ value: { defaultPattern: pattern, defaultValue, row: range.startRow, col: range.startColumn }
504
492
  };
505
- return this._sidebarDisposable = e.open({
506
- header: { title: o.t("sheet.numfmt.title") },
493
+ return this._sidebarDisposable = sidebarService.open({
494
+ header: { title: localeService.t("sheet.numfmt.title") },
507
495
  children: {
508
- label: Ae,
509
- ...f
496
+ label: SHEET_NUMFMT_PANEL,
497
+ ...props
510
498
  // need passthrough to react props.
511
499
  },
512
- onClose: () => {
513
- this._forceUpdate(), r.executeCommand(he.id);
514
- }
500
+ onClose: /* @__PURE__ */ __name(() => {
501
+ this._forceUpdate(), commandService.executeCommand(CloseNumfmtPanelOperator.id);
502
+ }, "onClose")
515
503
  }), !0;
516
504
  }
517
- _forceUpdate(e) {
518
- var r;
519
- const n = this._renderManagerService.getRenderById(
520
- e != null ? e : this._univerInstanceService.getCurrentUnitForType(E.UNIVER_SHEET).getUnitId()
505
+ _forceUpdate(unitId) {
506
+ var _a7;
507
+ const renderUnit = this._renderManagerService.getRenderById(
508
+ unitId != null ? unitId : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getUnitId()
521
509
  );
522
- n == null || n.with(Ft).reCalculate(), (r = n == null ? void 0 : n.mainComponent) == null || r.makeDirty();
510
+ renderUnit == null || renderUnit.with(SheetSkeletonManagerService).reCalculate(), (_a7 = renderUnit == null ? void 0 : renderUnit.mainComponent) == null || _a7.makeDirty();
523
511
  }
524
512
  _initCommands() {
525
513
  [
526
- A,
527
- he
528
- ].forEach((e) => {
529
- this.disposeWithMe(this._commandService.registerCommand(e));
514
+ OpenNumfmtPanelOperator,
515
+ CloseNumfmtPanelOperator
516
+ ].forEach((config) => {
517
+ this.disposeWithMe(this._commandService.registerCommand(config));
530
518
  });
531
519
  }
532
520
  _initPanel() {
533
- this._componentManager.register(Ae, Gn);
521
+ this._componentManager.register(SHEET_NUMFMT_PANEL, SheetNumfmtPanel);
534
522
  }
523
+ // eslint-disable-next-line max-lines-per-function
535
524
  _initRealTimeRenderingInterceptor() {
536
- const e = new D((r) => {
537
- this._commandService.onCommandExecuted((s) => {
538
- s.id === A.id && r.next(!0), s.id === he.id && r.next(!1);
525
+ const isPanelOpenObserver = new Observable((subscriber) => {
526
+ this._commandService.onCommandExecuted((commandInfo) => {
527
+ commandInfo.id === OpenNumfmtPanelOperator.id && subscriber.next(!0), commandInfo.id === CloseNumfmtPanelOperator.id && subscriber.next(!1);
539
528
  });
540
- }), n = nn([
541
- e,
529
+ }), combineOpenAndSelection$ = combineLatest([
530
+ isPanelOpenObserver,
542
531
  this._selectionManagerService.selectionMoveEnd$.pipe(
543
- sn((r) => r ? r.map((s) => s.range) : [])
532
+ map((selectionInfos) => selectionInfos ? selectionInfos.map((selectionInfo) => selectionInfo.range) : [])
544
533
  )
545
534
  ]);
546
535
  this.disposeWithMe(
547
- ge(
548
- n.pipe(
549
- on(
550
- ([r, s]) => new D((i) => {
551
- const o = new vt();
552
- return r && s.length && i.next({ selectionRanges: s, disposableCollection: o }), () => {
553
- o.dispose();
536
+ toDisposable(
537
+ combineOpenAndSelection$.pipe(
538
+ switchMap(
539
+ ([isOpen, selectionRanges]) => new Observable((subscribe) => {
540
+ const disposableCollection = new DisposableCollection();
541
+ return isOpen && selectionRanges.length && subscribe.next({ selectionRanges, disposableCollection }), () => {
542
+ disposableCollection.dispose();
554
543
  };
555
544
  })
556
545
  ),
557
- cn(() => {
546
+ tap(() => {
558
547
  this._previewPattern = null;
559
548
  })
560
- ).subscribe(({ disposableCollection: r, selectionRanges: s }) => {
561
- var o, c;
562
- const i = this._univerInstanceService.getCurrentUnitForType(E.UNIVER_SHEET);
563
- this.openPanel(), r.add(
564
- this._sheetInterceptorService.intercept(Yt.CELL_CONTENT, {
549
+ ).subscribe(({ disposableCollection, selectionRanges }) => {
550
+ var _a7, _b;
551
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
552
+ this.openPanel(), disposableCollection.add(
553
+ this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
565
554
  priority: 99,
566
- effect: Oe.Value | Oe.Style,
567
- handler: (a, m, d) => {
568
- const { row: u, col: h } = m, p = d(a) || {};
569
- if (s.find(
570
- (v) => v.startColumn <= h && v.endColumn >= h && v.startRow <= u && v.endRow >= u
555
+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
556
+ handler: /* @__PURE__ */ __name((cell, location, next) => {
557
+ const { row, col } = location, defaultValue = next(cell) || {};
558
+ if (selectionRanges.find(
559
+ (range) => range.startColumn <= col && range.endColumn >= col && range.startRow <= row && range.endRow >= row
571
560
  )) {
572
- const v = m.worksheet.getCellRaw(u, h), f = v == null ? void 0 : v.v, y = v == null ? void 0 : v.t;
573
- if (f == null || y !== $.NUMBER || this._previewPattern === null)
574
- return p;
575
- const _ = Rt(this._previewPattern, f, this._localeService.getCurrentLocale());
576
- if (_.color) {
577
- const x = this._themeService.getCurrentTheme()[`${_.color}500`];
561
+ const rawValue = location.worksheet.getCellRaw(row, col), value = rawValue == null ? void 0 : rawValue.v, type = rawValue == null ? void 0 : rawValue.t;
562
+ if (value == null || type !== CellValueType.NUMBER || this._previewPattern === null)
563
+ return defaultValue;
564
+ const info = getPatternPreviewIgnoreGeneral(this._previewPattern, value, this._sheetsNumfmtCellContentController.local);
565
+ if (info.color) {
566
+ const color = this._themeService.getCurrentTheme()[`${info.color}500`];
578
567
  return {
579
- ...p,
580
- v: _.result,
581
- t: $.STRING,
582
- s: { cl: { rgb: x } }
568
+ ...defaultValue,
569
+ v: info.result,
570
+ t: CellValueType.STRING,
571
+ s: { cl: { rgb: color } }
583
572
  };
584
573
  }
585
574
  return {
586
- ...p,
587
- v: _.result,
588
- t: $.STRING
575
+ ...defaultValue,
576
+ v: info.result,
577
+ t: CellValueType.STRING
589
578
  };
590
579
  }
591
- return p;
592
- }
580
+ return defaultValue;
581
+ }, "handler")
593
582
  })
594
- ), (c = (o = this._renderManagerService.getRenderById(i.getUnitId())) == null ? void 0 : o.mainComponent) == null || c.makeDirty();
583
+ ), (_b = (_a7 = this._renderManagerService.getRenderById(workbook.getUnitId())) == null ? void 0 : _a7.mainComponent) == null || _b.makeDirty();
595
584
  })
596
585
  )
597
586
  );
598
587
  }
599
588
  _commandExecutedListener() {
600
- const e = [Ne.id, Ee.id];
589
+ const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id];
601
590
  this.disposeWithMe(
602
- new D((n) => {
603
- const r = this._commandService.onCommandExecuted((s) => {
604
- if (e.includes(s.id)) {
605
- const i = s.params;
606
- n.next(i.unitId);
591
+ new Observable((subscribe) => {
592
+ const disposable = this._commandService.onCommandExecuted((command) => {
593
+ if (commandList.includes(command.id)) {
594
+ const params = command.params;
595
+ subscribe.next(params.unitId);
607
596
  }
608
597
  });
609
- return () => r.dispose();
610
- }).pipe(an(16)).subscribe((n) => this._forceUpdate(n))
598
+ return () => disposable.dispose();
599
+ }).pipe(debounceTime$1(16)).subscribe((unitId) => this._forceUpdate(unitId))
611
600
  );
612
601
  }
613
602
  _initCloseListener() {
614
- this._univerInstanceService.getCurrentTypeOfUnit$(E.UNIVER_SHEET).subscribe((e) => {
615
- var n;
616
- e || ((n = this._sidebarDisposable) == null || n.dispose(), this._sidebarDisposable = null);
603
+ this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((unit) => {
604
+ var _a7;
605
+ unit || ((_a7 = this._sidebarDisposable) == null || _a7.dispose(), this._sidebarDisposable = null);
617
606
  });
618
607
  }
619
- };
620
- B = Yn([
621
- P(0, S(tt)),
622
- P(1, S(_t)),
623
- P(2, ye),
624
- P(3, be),
625
- P(4, S(Te)),
626
- P(5, Ke),
627
- P(6, Ie),
628
- P(7, S(et)),
629
- P(8, Bt),
630
- P(9, S(T))
631
- ], B);
632
- var Zn = Object.defineProperty, zn = Object.getOwnPropertyDescriptor, Jn = (t, e, n, r) => {
633
- for (var s = r > 1 ? void 0 : r ? zn(e, n) : e, i = t.length - 1, o; i >= 0; i--)
634
- (o = t[i]) && (s = (r ? o(e, n, s) : o(s)) || s);
635
- return r && s && Zn(e, n, s), s;
636
- }, H = (t, e) => (n, r) => e(n, r, t);
637
- const Xn = () => {
638
- let t = [];
608
+ }, __name(_a3, "SheetNumfmtUIController"), _a3);
609
+ SheetNumfmtUIController = __decorateClass$3([
610
+ __decorateParam$3(0, Inject(SheetInterceptorService)),
611
+ __decorateParam$3(1, Inject(ThemeService)),
612
+ __decorateParam$3(2, IUniverInstanceService),
613
+ __decorateParam$3(3, ICommandService),
614
+ __decorateParam$3(4, Inject(SheetsSelectionsService)),
615
+ __decorateParam$3(5, IRenderManagerService),
616
+ __decorateParam$3(6, INumfmtService),
617
+ __decorateParam$3(7, Inject(ComponentManager)),
618
+ __decorateParam$3(8, ISidebarService),
619
+ __decorateParam$3(9, Inject(LocaleService)),
620
+ __decorateParam$3(10, Inject(SheetsNumfmtCellContentController))
621
+ ], SheetNumfmtUIController);
622
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
623
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
624
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
625
+ return kind && result && __defProp$2(target, key2, result), result;
626
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$2");
627
+ const createCollectEffectMutation = /* @__PURE__ */ __name(() => {
628
+ let list = [];
639
629
  return {
640
- add: (s, i, o, c, a) => t.push({ unitId: s, subUnitId: i, row: o, col: c, value: a }),
641
- getEffects: () => t,
642
- clean: () => {
643
- t = [];
644
- }
630
+ add: /* @__PURE__ */ __name((unitId, subUnitId, row, col, value) => list.push({ unitId, subUnitId, row, col, value }), "add"),
631
+ getEffects: /* @__PURE__ */ __name(() => list, "getEffects"),
632
+ clean: /* @__PURE__ */ __name(() => {
633
+ list = [];
634
+ }, "clean")
645
635
  };
646
- };
647
- let re = class extends oe {
648
- constructor(e, n, r, s, i) {
636
+ }, "createCollectEffectMutation");
637
+ var _a4;
638
+ let NumfmtEditorController = (_a4 = class extends Disposable {
639
+ constructor(_sheetInterceptorService, _numfmtService, _univerInstanceService, _injector, _editorBridgeService) {
649
640
  super();
650
641
  // collect effect mutations when edit end and push this to commands stack in next commands progress
651
- X(this, "_collectEffectMutation", Xn());
652
- this._sheetInterceptorService = e, this._numfmtService = n, this._univerInstanceService = r, this._injector = s, this._editorBridgeService = i, this._initInterceptorEditorStart(), this._initInterceptorEditorEnd(), this._initInterceptorCommands();
642
+ __publicField(this, "_collectEffectMutation", createCollectEffectMutation());
643
+ this._sheetInterceptorService = _sheetInterceptorService, this._numfmtService = _numfmtService, this._univerInstanceService = _univerInstanceService, this._injector = _injector, this._editorBridgeService = _editorBridgeService, this._initInterceptorEditorStart(), this._initInterceptorEditorEnd(), this._initInterceptorCommands();
653
644
  }
654
645
  _initInterceptorEditorStart() {
655
646
  this._editorBridgeService && this.disposeWithMe(
656
- ge(
647
+ toDisposable(
657
648
  this._sheetInterceptorService.writeCellInterceptor.intercept(
658
- Zt,
649
+ BEFORE_CELL_EDIT,
659
650
  {
660
- handler: (e, n, r) => {
661
- const s = n.row, i = n.col, o = this._numfmtService.getValue(
662
- n.unitId,
663
- n.subUnitId,
664
- s,
665
- i
651
+ handler: /* @__PURE__ */ __name((value, context, next) => {
652
+ const row = context.row, col = context.col, numfmtCell = this._numfmtService.getValue(
653
+ context.unitId,
654
+ context.subUnitId,
655
+ row,
656
+ col
666
657
  );
667
- if (o)
668
- switch (ne(o.pattern)) {
658
+ if (numfmtCell)
659
+ switch (getPatternType(numfmtCell.pattern)) {
669
660
  case "scientific":
670
661
  case "currency":
671
662
  case "grouped":
672
- case "number":
673
- return n.worksheet.getCellRaw(s, i);
663
+ case "number": {
664
+ const cell = context.worksheet.getCellRaw(row, col);
665
+ return next && next(cell);
666
+ }
674
667
  case "percent":
675
668
  case "date":
676
669
  case "time":
677
670
  case "datetime":
678
671
  default:
679
- return r && r(e);
672
+ return next && next(value);
680
673
  }
681
- return r(e);
682
- }
674
+ return next(value);
675
+ }, "handler")
683
676
  }
684
677
  )
685
678
  )
@@ -692,115 +685,115 @@ let re = class extends oe {
692
685
  */
693
686
  _initInterceptorEditorEnd() {
694
687
  this.disposeWithMe(
695
- ge(
688
+ toDisposable(
696
689
  this._sheetInterceptorService.writeCellInterceptor.intercept(
697
- zt,
690
+ AFTER_CELL_EDIT,
698
691
  {
699
692
  // eslint-disable-next-line complexity
700
- handler: (e, n, r) => {
701
- var d, u, h, p;
693
+ handler: /* @__PURE__ */ __name((value, context, next) => {
694
+ var _a7, _b, _c, _d;
702
695
  this._collectEffectMutation.clean();
703
- const s = this._numfmtService.getValue(
704
- n.unitId,
705
- n.subUnitId,
706
- n.row,
707
- n.col
708
- ), i = (d = s && ne(s.pattern)) != null ? d : "", o = () => {
709
- s && this._collectEffectMutation.add(
710
- n.unitId,
711
- n.subUnitId,
712
- n.row,
713
- n.col,
696
+ const currentNumfmtValue = this._numfmtService.getValue(
697
+ context.unitId,
698
+ context.subUnitId,
699
+ context.row,
700
+ context.col
701
+ ), currentNumfmtType = (_a7 = currentNumfmtValue && getPatternType(currentNumfmtValue.pattern)) != null ? _a7 : "", clean = /* @__PURE__ */ __name(() => {
702
+ currentNumfmtValue && this._collectEffectMutation.add(
703
+ context.unitId,
704
+ context.subUnitId,
705
+ context.row,
706
+ context.col,
714
707
  null
715
708
  );
716
- };
717
- if (!(e != null && e.v) && !(e != null && e.p) || (s == null ? void 0 : s.pattern) === Ce || e.t === $.FORCE_STRING)
718
- return r(e);
719
- const c = (u = e.p) == null ? void 0 : u.body, a = (p = (h = e == null ? void 0 : e.p) == null ? void 0 : h.body) != null && p.dataStream ? e.p.body.dataStream.replace(/\r\n$/, "") : String(e.v), m = Q.parseDate(a) || Q.parseTime(a) || Q.parseNumber(a);
720
- if (c)
721
- if (er(c)) {
722
- const { dataStream: v } = c, f = v.replace(/\r\n$/, ""), y = Number(f);
723
- if (Number.isNaN(y) && !m)
724
- return r(e);
709
+ }, "clean");
710
+ if (!(value != null && value.v) && !(value != null && value.p) || (currentNumfmtValue == null ? void 0 : currentNumfmtValue.pattern) === DEFAULT_TEXT_FORMAT || value.t === CellValueType.FORCE_STRING)
711
+ return next(value);
712
+ const body = (_b = value.p) == null ? void 0 : _b.body, content = (_d = (_c = value == null ? void 0 : value.p) == null ? void 0 : _c.body) != null && _d.dataStream ? value.p.body.dataStream.replace(/\r\n$/, "") : String(value.v), numfmtInfo = numfmt.parseDate(content) || numfmt.parseTime(content) || numfmt.parseNumber(content);
713
+ if (body)
714
+ if (canConvertRichTextToNumfmt(body)) {
715
+ const { dataStream } = body, dataStreamWithoutEnd = dataStream.replace(/\r\n$/, ""), num = Number(dataStreamWithoutEnd);
716
+ if (Number.isNaN(num) && !numfmtInfo)
717
+ return next(value);
725
718
  } else
726
- return r(e);
727
- if (m) {
728
- m.z && this._collectEffectMutation.add(
729
- n.unitId,
730
- n.subUnitId,
731
- n.row,
732
- n.col,
719
+ return next(value);
720
+ if (numfmtInfo) {
721
+ numfmtInfo.z && this._collectEffectMutation.add(
722
+ context.unitId,
723
+ context.subUnitId,
724
+ context.row,
725
+ context.col,
733
726
  {
734
- pattern: m.z
727
+ pattern: numfmtInfo.z
735
728
  }
736
729
  );
737
- const v = Number(m.v);
738
- return r({ ...e, p: void 0, v, t: $.NUMBER });
739
- } else (["date", "time", "datetime", "percent"].includes(i) || !Qn(a)) && o();
740
- return r(e);
741
- }
730
+ const v = Number(numfmtInfo.v);
731
+ return next({ ...value, p: void 0, v, t: CellValueType.NUMBER });
732
+ } else (["date", "time", "datetime", "percent"].includes(currentNumfmtType) || !isNumeric(content)) && clean();
733
+ return next(value);
734
+ }, "handler")
742
735
  }
743
736
  )
744
737
  )
745
738
  );
746
739
  }
747
740
  _initInterceptorCommands() {
748
- const e = this;
741
+ const self = this;
749
742
  this.disposeWithMe(
750
743
  this._sheetInterceptorService.interceptCommand({
751
- getMutations(n) {
752
- var r;
753
- switch (n.id) {
754
- case Jt.id: {
755
- const s = e._univerInstanceService.getCurrentUnitForType(E.UNIVER_SHEET), i = s.getUnitId(), o = (r = s.getActiveSheet()) == null ? void 0 : r.getSheetId();
756
- if (!o)
744
+ getMutations(command) {
745
+ var _a7;
746
+ switch (command.id) {
747
+ case SetRangeValuesCommand.id: {
748
+ const workbook = self._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), unitId = workbook.getUnitId(), subUnitId = (_a7 = workbook.getActiveSheet()) == null ? void 0 : _a7.getSheetId();
749
+ if (!subUnitId)
757
750
  return {
758
751
  redos: [],
759
752
  undos: []
760
753
  };
761
- const c = e._collectEffectMutation.getEffects();
762
- if (e._collectEffectMutation.clean(), !c.length)
754
+ const list = self._collectEffectMutation.getEffects();
755
+ if (self._collectEffectMutation.clean(), !list.length)
763
756
  return {
764
757
  redos: [],
765
758
  undos: []
766
759
  };
767
- const a = c.filter((h) => {
768
- var p;
769
- return !!((p = h.value) != null && p.pattern);
770
- }).map((h) => ({
771
- row: h.row,
772
- col: h.col,
773
- pattern: h.value.pattern
774
- })), m = c.filter((h) => {
775
- var p;
776
- return !((p = h.value) != null && p.pattern);
777
- }).map((h) => ({
778
- startRow: h.row,
779
- endColumn: h.col,
780
- startColumn: h.col,
781
- endRow: h.row
782
- })), d = [], u = [];
783
- if (a.length) {
784
- const h = {
785
- id: Ee.id,
786
- params: Xt(i, o, a)
760
+ const cells = list.filter((item) => {
761
+ var _a8;
762
+ return !!((_a8 = item.value) != null && _a8.pattern);
763
+ }).map((item) => ({
764
+ row: item.row,
765
+ col: item.col,
766
+ pattern: item.value.pattern
767
+ })), removeCells = list.filter((item) => {
768
+ var _a8;
769
+ return !((_a8 = item.value) != null && _a8.pattern);
770
+ }).map((item) => ({
771
+ startRow: item.row,
772
+ endColumn: item.col,
773
+ startColumn: item.col,
774
+ endRow: item.row
775
+ })), redos = [], undos = [];
776
+ if (cells.length) {
777
+ const redo = {
778
+ id: SetNumfmtMutation.id,
779
+ params: transformCellsToRange(unitId, subUnitId, cells)
787
780
  };
788
- d.push(h), u.push(...Qt(e._injector, h.params));
781
+ redos.push(redo), undos.push(...factorySetNumfmtUndoMutation(self._injector, redo.params));
789
782
  }
790
- if (m.length) {
791
- const h = {
792
- id: Ne.id,
783
+ if (removeCells.length) {
784
+ const redo = {
785
+ id: RemoveNumfmtMutation.id,
793
786
  params: {
794
- unitId: i,
795
- subUnitId: o,
796
- ranges: m
787
+ unitId,
788
+ subUnitId,
789
+ ranges: removeCells
797
790
  }
798
791
  };
799
- d.push(h), u.push(...en(e._injector, h.params));
792
+ redos.push(redo), undos.push(...factoryRemoveNumfmtUndoMutation(self._injector, redo.params));
800
793
  }
801
794
  return {
802
- redos: d,
803
- undos: u.reverse()
795
+ redos,
796
+ undos: undos.reverse()
804
797
  };
805
798
  }
806
799
  }
@@ -812,29 +805,31 @@ let re = class extends oe {
812
805
  })
813
806
  );
814
807
  }
815
- };
816
- re = Jn([
817
- H(0, S(tt)),
818
- H(1, S(Ie)),
819
- H(2, S(ye)),
820
- H(3, S(Ge)),
821
- H(4, gt(Lt))
822
- ], re);
823
- function Qn(t) {
824
- return /^-?\d+(\.\d+)?$/.test(t);
808
+ }, __name(_a4, "NumfmtEditorController"), _a4);
809
+ NumfmtEditorController = __decorateClass$2([
810
+ __decorateParam$2(0, Inject(SheetInterceptorService)),
811
+ __decorateParam$2(1, Inject(INumfmtService)),
812
+ __decorateParam$2(2, Inject(IUniverInstanceService)),
813
+ __decorateParam$2(3, Inject(Injector)),
814
+ __decorateParam$2(4, Optional(IEditorBridgeService))
815
+ ], NumfmtEditorController);
816
+ function isNumeric(str) {
817
+ return /^-?\d+(\.\d+)?$/.test(str);
825
818
  }
826
- function er(t) {
827
- const { textRuns: e = [], paragraphs: n = [], customRanges: r, customBlocks: s = [] } = t, i = ["va"];
828
- return !(e.some((o) => !!(o.ts && Object.keys(o.ts).some((a) => i.includes(a)))) || n.some((o) => o.bullet) || n.length >= 2 || r != null && r.length || s.length > 0);
819
+ __name(isNumeric, "isNumeric");
820
+ function canConvertRichTextToNumfmt(body) {
821
+ const { textRuns = [], paragraphs = [], customRanges, customBlocks = [] } = body, richTextStyle = ["va"];
822
+ return !(textRuns.some((textRun) => !!(textRun.ts && Object.keys(textRun.ts).some((property) => richTextStyle.includes(property)))) || paragraphs.some((paragraph) => paragraph.bullet) || paragraphs.length >= 2 || customRanges != null && customRanges.length || customBlocks.length > 0);
829
823
  }
830
- const ee = [
824
+ __name(canConvertRichTextToNumfmt, "canConvertRichTextToNumfmt");
825
+ const MENU_OPTIONS = [
831
826
  {
832
827
  label: "sheet.numfmt.general",
833
828
  pattern: null
834
829
  },
835
830
  {
836
831
  label: "sheet.numfmt.text",
837
- pattern: Ce
832
+ pattern: DEFAULT_TEXT_FORMAT
838
833
  },
839
834
  "|",
840
835
  {
@@ -880,223 +875,223 @@ const ee = [
880
875
  label: "sheet.numfmt.moreFmt",
881
876
  pattern: ""
882
877
  }
883
- ], tr = (t) => ({
884
- icon: new D((e) => {
885
- const n = t.get(jt);
886
- function r(i) {
878
+ ], CurrencyMenuItem = /* @__PURE__ */ __name((accessor) => ({
879
+ icon: new Observable((subscribe) => {
880
+ const menuCurrencyService = accessor.get(MenuCurrencyService);
881
+ function getIconKey(symbol2) {
887
882
  return {
888
- [O.US]: "DollarSingle",
889
- [O.RU]: "RoubleSingle",
890
- [O.CN]: "RmbSingle",
891
- [O.AT]: "EuroSingle"
892
- }[i] || "DollarSingle";
883
+ [countryCurrencyMap.US]: "DollarSingle",
884
+ [countryCurrencyMap.RU]: "RoubleSingle",
885
+ [countryCurrencyMap.CN]: "RmbSingle",
886
+ [countryCurrencyMap.AT]: "EuroSingle"
887
+ }[symbol2] || "DollarSingle";
893
888
  }
894
- const s = O[n.getCurrencySymbol()] || "$";
895
- return e.next(r(s)), n.currencySymbol$.subscribe((i) => {
896
- const o = O[i] || "$";
897
- e.next(r(o));
889
+ __name(getIconKey, "getIconKey");
890
+ const symbol = countryCurrencyMap[menuCurrencyService.getCurrencySymbol()] || "$";
891
+ return subscribe.next(getIconKey(symbol)), menuCurrencyService.currencySymbol$.subscribe((code) => {
892
+ const symbol2 = countryCurrencyMap[code] || "$";
893
+ subscribe.next(getIconKey(symbol2));
898
894
  });
899
895
  }),
900
- id: ze.id,
896
+ id: SetCurrencyCommand.id,
901
897
  title: "sheet.numfmt.currency",
902
898
  tooltip: "sheet.numfmt.currency",
903
- type: G.BUTTON,
904
- hidden$: K(t, E.UNIVER_SHEET),
905
- disabled$: V(t, { workbookTypes: [q], worksheetTypes: [Y, Z], rangeTypes: [z] })
906
- }), nr = (t) => ({
899
+ type: MenuItemType.BUTTON,
900
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
901
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
902
+ }), "CurrencyMenuItem"), AddDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
907
903
  icon: "AddDigitsSingle",
908
- id: Je.id,
904
+ id: AddDecimalCommand.id,
909
905
  title: "sheet.numfmt.addDecimal",
910
906
  tooltip: "sheet.numfmt.addDecimal",
911
- type: G.BUTTON,
912
- hidden$: K(t, E.UNIVER_SHEET),
913
- disabled$: V(t, { workbookTypes: [q], worksheetTypes: [Y, Z], rangeTypes: [z] })
914
- }), rr = (t) => ({
907
+ type: MenuItemType.BUTTON,
908
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
909
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
910
+ }), "AddDecimalMenuItem"), SubtractDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
915
911
  icon: "ReduceDigitsSingle",
916
- id: Xe.id,
912
+ id: SubtractDecimalCommand.id,
917
913
  title: "sheet.numfmt.subtractDecimal",
918
914
  tooltip: "sheet.numfmt.subtractDecimal",
919
- type: G.BUTTON,
920
- hidden$: K(t, E.UNIVER_SHEET),
921
- disabled$: V(t, { workbookTypes: [q], worksheetTypes: [Y, Z], rangeTypes: [z] })
922
- }), sr = (t) => ({
915
+ type: MenuItemType.BUTTON,
916
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
917
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
918
+ }), "SubtractDecimalMenuItem"), PercentMenuItem = /* @__PURE__ */ __name((accessor) => ({
923
919
  icon: "PercentSingle",
924
- id: Qe.id,
920
+ id: SetPercentCommand.id,
925
921
  title: "sheet.numfmt.percent",
926
922
  tooltip: "sheet.numfmt.percent",
927
- type: G.BUTTON,
928
- hidden$: K(t, E.UNIVER_SHEET),
929
- disabled$: V(t, { workbookTypes: [q], worksheetTypes: [Y, Z], rangeTypes: [z] })
930
- }), ir = (t) => {
931
- const e = t.get(ye), n = t.get(be), r = t.get(T), s = t.get(Te), i = Ht(e, "", ({ workbook: o, worksheet: c }) => new D(
932
- (a) => rn(
933
- s.selectionMoveEnd$,
934
- new D((m) => {
935
- const d = [Ne.id, Ee.id], u = n.onCommandExecuted((h) => {
936
- d.includes(h.id) && m.next(null);
923
+ type: MenuItemType.BUTTON,
924
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
925
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
926
+ }), "PercentMenuItem"), FactoryOtherMenuItem = /* @__PURE__ */ __name((accessor) => {
927
+ const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), localeService = accessor.get(LocaleService), selectionManagerService = accessor.get(SheetsSelectionsService), value$ = deriveStateFromActiveSheet$(univerInstanceService, "", ({ workbook, worksheet }) => new Observable(
928
+ (subscribe) => merge(
929
+ selectionManagerService.selectionMoveEnd$,
930
+ new Observable((commandSubscribe) => {
931
+ const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id], disposable = commandService.onCommandExecuted((commandInfo) => {
932
+ commandList.includes(commandInfo.id) && commandSubscribe.next(null);
937
933
  });
938
- return () => u.dispose();
934
+ return () => disposable.dispose();
939
935
  })
940
936
  ).subscribe(() => {
941
- var d, u;
942
- const m = s.getCurrentSelections();
943
- if (m && m[0]) {
944
- const h = m[0].range, p = h.startRow, v = h.startColumn, f = (u = o.getStyles().get((d = c.getCell(p, v)) == null ? void 0 : d.s)) == null ? void 0 : u.n, y = f == null ? void 0 : f.pattern;
945
- let _ = r.t("sheet.numfmt.general");
946
- if (y) {
947
- const I = ee.filter((x) => typeof x == "object" && x.pattern).find(
948
- (x) => ce(y, x.pattern)
937
+ var _a7, _b;
938
+ const selections = selectionManagerService.getCurrentSelections();
939
+ if (selections && selections[0]) {
940
+ const range = selections[0].range, row = range.startRow, col = range.startColumn, numfmtValue = (_b = workbook.getStyles().get((_a7 = worksheet.getCell(row, col)) == null ? void 0 : _a7.s)) == null ? void 0 : _b.n, pattern = numfmtValue == null ? void 0 : numfmtValue.pattern;
941
+ let value = localeService.t("sheet.numfmt.general");
942
+ if (pattern) {
943
+ const item = MENU_OPTIONS.filter((item2) => typeof item2 == "object" && item2.pattern).find(
944
+ (item2) => isPatternEqualWithoutDecimal(pattern, item2.pattern)
949
945
  );
950
- I && typeof I == "object" && I.pattern ? _ = r.t(I.label) : _ = r.t("sheet.numfmt.moreFmt");
946
+ item && typeof item == "object" && item.pattern ? value = localeService.t(item.label) : value = localeService.t("sheet.numfmt.moreFmt");
951
947
  }
952
- a.next(_);
948
+ subscribe.next(value);
953
949
  }
954
950
  })
955
951
  ));
956
952
  return {
957
- label: ct,
958
- id: A.id,
953
+ label: MORE_NUMFMT_TYPE_KEY,
954
+ id: OpenNumfmtPanelOperator.id,
959
955
  tooltip: "sheet.numfmt.title",
960
- type: G.SELECTOR,
956
+ type: MenuItemType.SELECTOR,
961
957
  selections: [
962
958
  {
963
959
  label: {
964
- name: at,
960
+ name: OPTIONS_KEY,
965
961
  hoverable: !1
966
962
  }
967
963
  }
968
964
  ],
969
- value$: i,
970
- hidden$: K(t, E.UNIVER_SHEET),
971
- disabled$: V(t, { workbookTypes: [q], worksheetTypes: [Z, Y], rangeTypes: [z] })
965
+ value$,
966
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
967
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
972
968
  };
973
- }, ct = "sheet.numfmt.moreNumfmtType", at = "sheet.numfmt.moreNumfmtType.options", or = (t) => {
974
- var r;
975
- const e = b(T), n = (r = t.value) != null ? r : e.t("sheet.numfmt.general");
976
- return /* @__PURE__ */ l.jsx("span", { className: "more-numfmt-type", children: n });
977
- }, cr = () => {
978
- const t = b(be), e = b(T), n = b(Wt);
979
- St();
980
- const r = b(Te), s = (c) => {
981
- const a = r.getCurrentLastSelection();
982
- if (!a)
969
+ }, "FactoryOtherMenuItem"), MORE_NUMFMT_TYPE_KEY = "sheet.numfmt.moreNumfmtType", OPTIONS_KEY = "sheet.numfmt.moreNumfmtType.options", MoreNumfmtType = /* @__PURE__ */ __name((props) => {
970
+ var _a7;
971
+ const localeService = useDependency(LocaleService), value = (_a7 = props.value) != null ? _a7 : localeService.t("sheet.numfmt.general");
972
+ return /* @__PURE__ */ jsx("span", { className: "more-numfmt-type", children: value });
973
+ }, "MoreNumfmtType"), Options = /* @__PURE__ */ __name(() => {
974
+ const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), layoutService = useDependency(ILayoutService), sheetsNumfmtCellContentController = useDependency(SheetsNumfmtCellContentController), selectionManagerService = useDependency(SheetsSelectionsService), setNumfmt = /* @__PURE__ */ __name((pattern) => {
975
+ const selection = selectionManagerService.getCurrentLastSelection();
976
+ if (!selection)
983
977
  return;
984
- const m = a.range, d = [];
985
- Ve.foreach(m, (u, h) => {
986
- c ? d.push({ row: u, col: h, pattern: c, type: ne(c) }) : d.push({ row: u, col: h });
987
- }), t.executeCommand(Ze.id, { values: d }), n.focus();
988
- }, i = (c) => {
989
- if (c === 0)
990
- s(null);
991
- else if (c === ee.length - 1)
992
- t.executeCommand(A.id);
978
+ const range = selection.range, values = [];
979
+ Range.foreach(range, (row, col) => {
980
+ pattern ? values.push({ row, col, pattern, type: getPatternType(pattern) }) : values.push({ row, col });
981
+ }), commandService.executeCommand(SetNumfmtCommand.id, { values }), layoutService.focus();
982
+ }, "setNumfmt"), handleOnclick = /* @__PURE__ */ __name((index) => {
983
+ if (index === 0)
984
+ setNumfmt(null);
985
+ else if (index === MENU_OPTIONS.length - 1)
986
+ commandService.executeCommand(OpenNumfmtPanelOperator.id);
993
987
  else {
994
- const a = ee[c];
995
- a.pattern && s(a.pattern);
988
+ const item = MENU_OPTIONS[index];
989
+ item.pattern && setNumfmt(item.pattern);
996
990
  }
997
- }, o = 1220;
998
- return /* @__PURE__ */ l.jsx("div", { className: "more-numfmt-type-options", children: ee.map((c, a) => c === "|" ? /* @__PURE__ */ l.jsx("div", { className: "line m-t-4", onClick: (m) => m.stopPropagation() }, a) : /* @__PURE__ */ l.jsxs(
991
+ }, "handleOnclick"), defaultValue = 1220;
992
+ return /* @__PURE__ */ jsx("div", { className: "more-numfmt-type-options", children: MENU_OPTIONS.map((item, index) => item === "|" ? /* @__PURE__ */ jsx("div", { className: "line m-t-4", onClick: /* @__PURE__ */ __name((e) => e.stopPropagation(), "onClick") }, index) : /* @__PURE__ */ jsxs(
999
993
  "div",
1000
994
  {
1001
995
  className: "option-item m-t-4",
1002
- onClick: () => {
1003
- i(a);
1004
- },
996
+ onClick: /* @__PURE__ */ __name(() => {
997
+ handleOnclick(index);
998
+ }, "onClick"),
1005
999
  children: [
1006
- /* @__PURE__ */ l.jsx("div", { children: e.t(c.label) }),
1007
- /* @__PURE__ */ l.jsx("div", { className: "m-l-26", children: c.pattern ? wt(c.pattern || "", o, e.getCurrentLocale()).result : "" })
1000
+ /* @__PURE__ */ jsx("div", { children: localeService.t(item.label) }),
1001
+ /* @__PURE__ */ jsx("div", { className: "m-l-26", children: item.pattern ? getPatternPreview(item.pattern || "", defaultValue, sheetsNumfmtCellContentController.local).result : "" })
1008
1002
  ]
1009
1003
  },
1010
- a
1004
+ index
1011
1005
  )) });
1012
- }, ar = {
1013
- [Vt.FORMULAS_INSERT]: {
1014
- [ze.id]: {
1006
+ }, "Options"), menuSchema = {
1007
+ [RibbonStartGroup.FORMULAS_INSERT]: {
1008
+ [SetCurrencyCommand.id]: {
1015
1009
  order: 4,
1016
- menuItemFactory: tr
1010
+ menuItemFactory: CurrencyMenuItem
1017
1011
  },
1018
- [Je.id]: {
1012
+ [AddDecimalCommand.id]: {
1019
1013
  order: 5,
1020
- menuItemFactory: nr
1014
+ menuItemFactory: AddDecimalMenuItem
1021
1015
  },
1022
- [Xe.id]: {
1016
+ [SubtractDecimalCommand.id]: {
1023
1017
  order: 6,
1024
- menuItemFactory: rr
1018
+ menuItemFactory: SubtractDecimalMenuItem
1025
1019
  },
1026
- [Qe.id]: {
1020
+ [SetPercentCommand.id]: {
1027
1021
  order: 7,
1028
- menuItemFactory: sr
1022
+ menuItemFactory: PercentMenuItem
1029
1023
  },
1030
- [A.id]: {
1024
+ [OpenNumfmtPanelOperator.id]: {
1031
1025
  order: 8,
1032
- menuItemFactory: ir
1026
+ menuItemFactory: FactoryOtherMenuItem
1033
1027
  }
1034
1028
  }
1035
1029
  };
1036
- var lr = Object.defineProperty, mr = Object.getOwnPropertyDescriptor, ur = (t, e, n, r) => {
1037
- for (var s = r > 1 ? void 0 : r ? mr(e, n) : e, i = t.length - 1, o; i >= 0; i--)
1038
- (o = t[i]) && (s = (r ? o(e, n, s) : o(s)) || s);
1039
- return r && s && lr(e, n, s), s;
1040
- }, ke = (t, e) => (n, r) => e(n, r, t);
1041
- let se = class extends oe {
1042
- constructor(t, e) {
1043
- super(), this._componentManager = t, this._menuManagerService = e, this._initMenu();
1030
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
1031
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1032
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
1033
+ return kind && result && __defProp$1(target, key2, result), result;
1034
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$1"), _a5;
1035
+ let NumfmtMenuController = (_a5 = class extends Disposable {
1036
+ constructor(_componentManager, _menuManagerService) {
1037
+ super(), this._componentManager = _componentManager, this._menuManagerService = _menuManagerService, this._initMenu();
1044
1038
  }
1045
1039
  _initMenu() {
1046
- this._menuManagerService.mergeMenu(ar), this.disposeWithMe(this._componentManager.register(ct, or)), this.disposeWithMe(this._componentManager.register(at, cr));
1040
+ this._menuManagerService.mergeMenu(menuSchema), this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY, MoreNumfmtType)), this.disposeWithMe(this._componentManager.register(OPTIONS_KEY, Options));
1047
1041
  }
1048
- };
1049
- se = ur([
1050
- ke(0, S(et)),
1051
- ke(1, Gt)
1052
- ], se);
1053
- var lt = Object.defineProperty, dr = Object.getOwnPropertyDescriptor, hr = (t, e, n) => e in t ? lt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, fr = (t, e, n, r) => {
1054
- for (var s = r > 1 ? void 0 : r ? dr(e, n) : e, i = t.length - 1, o; i >= 0; i--)
1055
- (o = t[i]) && (s = (r ? o(e, n, s) : o(s)) || s);
1056
- return r && s && lt(e, n, s), s;
1057
- }, _e = (t, e) => (n, r) => e(n, r, t), mt = (t, e, n) => hr(t, typeof e != "symbol" ? e + "" : e, n);
1058
- const pr = "SHEET_NUMFMT_UI_PLUGIN";
1059
- let ie = class extends bt {
1060
- constructor(t = De, e, n, r) {
1061
- super(), this._config = t, this._injector = e, this._configService = n, this._renderManagerService = r;
1062
- const { menu: s, ...i } = Ct(
1042
+ }, __name(_a5, "NumfmtMenuController"), _a5);
1043
+ NumfmtMenuController = __decorateClass$1([
1044
+ __decorateParam$1(0, Inject(ComponentManager)),
1045
+ __decorateParam$1(1, IMenuManagerService)
1046
+ ], NumfmtMenuController);
1047
+ 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) => {
1048
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1049
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
1050
+ return kind && result && __defProp2(target, key2, result), result;
1051
+ }, "__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");
1052
+ const SHEET_NUMFMT_UI_PLUGIN = "SHEET_NUMFMT_UI_PLUGIN";
1053
+ var _a6;
1054
+ let UniverSheetsNumfmtUIPlugin = (_a6 = class extends Plugin {
1055
+ constructor(_config = defaultPluginConfig, _injector, _configService, _renderManagerService) {
1056
+ super(), this._config = _config, this._injector = _injector, this._configService = _configService, this._renderManagerService = _renderManagerService;
1057
+ const { menu, ...rest } = merge$1(
1063
1058
  {},
1064
- De,
1059
+ defaultPluginConfig,
1065
1060
  this._config
1066
1061
  );
1067
- s && this._configService.setConfig("menu", s, { merge: !0 }), this._configService.setConfig(Kt, i);
1062
+ menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._configService.setConfig(UI_PLUGIN_CONFIG_KEY, rest);
1068
1063
  }
1069
1064
  onStarting() {
1070
- It(this._injector, [
1071
- [B],
1072
- [re],
1073
- [k],
1074
- [se]
1065
+ registerDependencies(this._injector, [
1066
+ [SheetNumfmtUIController],
1067
+ [NumfmtEditorController],
1068
+ [UserHabitController],
1069
+ [NumfmtMenuController]
1075
1070
  ]);
1076
1071
  }
1077
1072
  onRendered() {
1078
- this._registerRenderModules(), Nt(this._injector, [
1079
- [B],
1080
- [re],
1081
- [se]
1073
+ this._registerRenderModules(), touchDependencies(this._injector, [
1074
+ [SheetNumfmtUIController],
1075
+ [NumfmtEditorController],
1076
+ [NumfmtMenuController]
1082
1077
  ]);
1083
1078
  }
1084
1079
  _registerRenderModules() {
1085
1080
  [
1086
- [Se]
1087
- ].forEach((e) => {
1088
- this.disposeWithMe(this._renderManagerService.registerRenderModule(E.UNIVER_SHEET, e));
1081
+ [NumfmtAlertRenderController]
1082
+ ].forEach((m) => {
1083
+ this.disposeWithMe(this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, m));
1089
1084
  });
1090
1085
  }
1091
- };
1092
- mt(ie, "pluginName", pr);
1093
- mt(ie, "type", E.UNIVER_SHEET);
1094
- ie = fr([
1095
- yt(At, Ot),
1096
- _e(1, S(Ge)),
1097
- _e(2, Et),
1098
- _e(3, Ke)
1099
- ], ie);
1086
+ }, __name(_a6, "UniverSheetsNumfmtUIPlugin"), _a6);
1087
+ __publicField2(UniverSheetsNumfmtUIPlugin, "pluginName", SHEET_NUMFMT_UI_PLUGIN);
1088
+ __publicField2(UniverSheetsNumfmtUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
1089
+ UniverSheetsNumfmtUIPlugin = __decorateClass([
1090
+ DependentOn(UniverSheetsUIPlugin, UniverSheetsNumfmtPlugin),
1091
+ __decorateParam(1, Inject(Injector)),
1092
+ __decorateParam(2, IConfigService),
1093
+ __decorateParam(3, IRenderManagerService)
1094
+ ], UniverSheetsNumfmtUIPlugin);
1100
1095
  export {
1101
- ie as UniverSheetsNumfmtUIPlugin
1096
+ UniverSheetsNumfmtUIPlugin
1102
1097
  };