index.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. var pt = Object.defineProperty;
  2. var vt = (t, e, n) => e in t ? pt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
  3. var X = (t, e, n) => vt(t, typeof e != "symbol" ? e + "" : e, n);
  4. import { Inject as S, LocaleService as T, Disposable as oe, isRealNum as _t, 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 gt, InterceptorEffectEnum as Oe, ThemeService as St, IUniverInstanceService as ye, ICommandService as be, Injector as Ge, Optional as yt, DependentOn as bt, Plugin as Ct, merge as It, registerDependencies as Nt, touchDependencies as Et, IConfigService as Tt } 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 xt, DATEFMTLISG as Pt, NUMBERFORMAT as Mt, getDateFormatOptions as qe, getNumberFormatOptions as Ye, isPatternHasDecimal as Rt, getPatternType as ne, SetNumfmtCommand as Ze, getPatternPreviewIgnoreGeneral as jt, SheetsNumfmtCellContentController as ze, MenuCurrencyService as wt, countryCurrencyMap as O, SetCurrencyCommand as Je, AddDecimalCommand as Xe, SubtractDecimalCommand as Qe, SetPercentCommand as et, getPatternPreview as Ot, UniverSheetsNumfmtPlugin as Ut } from "@univerjs/sheets-numfmt";
  7. import { HoverManagerService as $t, CellAlertManagerService as Dt, CellAlertType as Ft, SheetSkeletonManagerService as Lt, IEditorBridgeService as Ht, getCurrentRangeDisable$ as V, deriveStateFromActiveSheet$ as At, UniverSheetsUIPlugin as kt } from "@univerjs/sheets-ui";
  8. import { IZenZoneService as Bt, ComponentManager as tt, ISidebarService as Wt, MenuItemType as G, getMenuHiddenObservable as K, ILayoutService as Vt, RibbonStartGroup as Gt, IMenuManagerService as Kt, UI_PLUGIN_CONFIG_KEY as qt } from "@univerjs/ui";
  9. import { FormulaDataModel as Yt } from "@univerjs/engine-formula";
  10. import { DEFAULT_TEXT_FORMAT as Ce } from "@univerjs/engine-numfmt";
  11. import { INumfmtService as Ie, INTERCEPTOR_POINT as Zt, RemoveNumfmtMutation as Ne, SetNumfmtMutation as Ee, SheetInterceptorService as nt, SheetsSelectionsService as Te, BEFORE_CELL_EDIT as zt, AFTER_CELL_EDIT as Jt, SetRangeValuesCommand as Xt, transformCellsToRange as Qt, factorySetNumfmtUndoMutation as en, factoryRemoveNumfmtUndoMutation as tn, WorkbookEditablePermission as q, WorksheetEditPermission as Y, WorksheetSetCellStylePermission as Z, RangeProtectionPermissionEditPoint as z } from "@univerjs/sheets";
  12. import { debounceTime as nn, merge as rt, Observable as D, combineLatest 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 st, useMemo as R, forwardRef as it, 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();
  26. }
  27. _init() {
  28. this._initCellAlertPopup(), this._initZenService();
  29. }
  30. _initCellAlertPopup() {
  31. this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(nn(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 a;
  38. const c = s.getCell(n.row, n.col);
  39. if (c != null && c.s) {
  40. const m = r.getStyles().get(c.s);
  41. m != null && m.n && (a = m.n);
  42. }
  43. if (a || (a = this._numfmtService.getValue(i, o, n.row, n.col)), !a) {
  44. this._hideAlert();
  45. return;
  46. }
  47. if (a.pattern === Ce && (c != null && c.v) && _t(c.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. return;
  51. this._cellAlertManagerService.showAlert({
  52. type: Ft.ERROR,
  53. title: this._localeService.t("info.error"),
  54. message: this._localeService.t("info.forceStringInfo"),
  55. location: n,
  56. width: 200,
  57. height: 74,
  58. key: de
  59. });
  60. return;
  61. }
  62. }
  63. this._hideAlert();
  64. }));
  65. }
  66. _initZenService() {
  67. this.disposeWithMe(this._zenZoneService.visible$.subscribe((t) => {
  68. t && this._hideAlert();
  69. }));
  70. }
  71. _hideAlert() {
  72. this._cellAlertManagerService.removeAlert(de);
  73. }
  74. };
  75. Se = fn([
  76. U(1, S($t)),
  77. U(2, S(Dt)),
  78. U(3, S(T)),
  79. U(4, S(Yt)),
  80. U(5, Bt),
  81. U(6, S(Ie))
  82. ], Se);
  83. const he = {
  84. id: "sheet.operation.close.numfmt.panel",
  85. type: Be.OPERATION,
  86. handler: () => (
  87. // do nothing, just notify panel is closed
  88. !0
  89. )
  90. }, A = {
  91. id: "sheet.operation.open.numfmt.panel",
  92. type: Be.OPERATION,
  93. handler: (t) => (t.get(B).openPanel(), !0)
  94. };
  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(a, c, m) {
  111. var d, u = {}, h = null, p = null;
  112. m !== void 0 && (h = "" + m), c.key !== void 0 && (h = "" + c.key), c.ref !== void 0 && (p = c.ref);
  113. for (d in c) r.call(c, d) && !i.hasOwnProperty(d) && (u[d] = c[d]);
  114. if (a && a.defaultProps) for (d in c = a.defaultProps, c) u[d] === void 0 && (u[d] = c[d]);
  115. return { $$typeof: e, type: a, 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;
  132. }
  133. _getKey(t) {
  134. return `userHabitController_${t}`;
  135. }
  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);
  140. });
  141. }
  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);
  148. }
  149. });
  150. }
  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, a) => {
  155. const c = a.length;
  156. return {
  157. value: i,
  158. priority: c - o
  159. };
  160. });
  161. return e.sort((i, o) => {
  162. var m, d;
  163. const a = ((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) - a;
  165. });
  166. }
  167. return r || [];
  168. }
  169. deleteHabit(t) {
  170. this._localStorageService.removeItem(t);
  171. }
  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);
  182. });
  183. });
  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 = st(we), [a, c] = C(() => W(e) || o[0]), m = R(() => o.map((v) => ({ label: v, value: v })), []), u = b(T).t;
  198. n.current = () => M(`_("${a}"* #,##0${s > 0 ? ".0" : ""}_)`, s);
  199. const h = (v) => {
  200. c(v), r(M(`_("${v}"* #,##0${s > 0 ? ".0" : ""}_)`, s));
  201. }, p = (v) => {
  202. const f = v || 0;
  203. i(f), r(M(`_("${a}"* #,##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 }) })
  210. ] }),
  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: a }) })
  214. ] })
  215. ] }),
  216. /* @__PURE__ */ l.jsx("div", { className: "describe m-t-14", children: u("sheet.numfmt.accountingDes") })
  217. ] });
  218. }, En = (t) => !!W(t) && !t.startsWith("_("), Tn = (t) => {
  219. const n = b(T).t, r = st(we), [s, i] = C(() => W(t.defaultPattern) || r[0]), [o, a] = C(() => te(t.defaultPattern || "", 2)), [c, 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(c, o);
  225. const h = (f) => {
  226. if (f === void 0)
  227. 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. a(f || 0), t.onChange(M(c, 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 }) })
  241. ] }),
  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 }) })
  245. ] })
  246. ] }),
  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: c }) }),
  249. /* @__PURE__ */ l.jsx("div", { className: "describe m-t-14", children: n("sheet.numfmt.currencyDes") })
  250. ] });
  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]);
  257. }
  258. 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. }, ot = it(function(t, e) {
  268. var n = t.icon, r = t.id, s = t.className, i = t.extend, o = xn(t, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(r, " ").concat(s || "").trim(), c = xe("_".concat(Rn()));
  269. return ct(n, "".concat(r), { defIds: n.defIds, idSuffix: c.current }, N({ ref: e, className: a }, o), i);
  270. });
  271. function ct(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 ct(i, "".concat(e, "-").concat(t.tag, "-").concat(o), n, void 0, s);
  274. }));
  275. }
  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], a = i[1];
  282. typeof a == "string" && (r[o] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
  283. })), r;
  284. }
  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;
  290. }
  291. function Rn() {
  292. return Math.random().toString(36).substring(2, 8);
  293. }
  294. ot.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" } }] }, at = it(function(t, e) {
  296. return Pe(ot, Object.assign({}, t, {
  297. id: "check-mark-single",
  298. ref: e,
  299. icon: jn
  300. }));
  301. });
  302. at.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), [a, c] = C(e);
  313. n.current = () => (s.markHabit(pe, a), i.getItem(ve).then((p = []) => {
  314. const v = [.../* @__PURE__ */ new Set([a, ...p || []])].splice(0, 10).filter((f) => !!f);
  315. i.setItem(ve, v);
  316. }), a);
  317. const [m, d] = C([]);
  318. ae(() => {
  319. i.getItem(ve).then((p) => {
  320. const v = [
  321. ...xt.map((f) => f.suffix("$")),
  322. ...Pt.map((f) => f.suffix),
  323. ...Mt.map((f) => f.suffix)
  324. ];
  325. v.push(...p || []), s.addHabit(pe, []).finally(() => {
  326. s.getHabit(pe, v).then((f) => {
  327. d([...new Set(f)]);
  328. });
  329. });
  330. });
  331. }, []);
  332. const u = (p) => {
  333. c(p), r(p);
  334. }, h = () => {
  335. r(a);
  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: a, onChange: c, 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: a === p && /* @__PURE__ */ l.jsx(at, {}) }),
  342. /* @__PURE__ */ l.jsx("div", { children: p })
  343. ] }, p)) }),
  344. /* @__PURE__ */ l.jsx("div", { className: j.customFormatDes, children: o.t("sheet.numfmt.customFormatDes") })
  345. ] });
  346. }
  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 a = e.find((c) => c.value === t.defaultPattern);
  354. if (a)
  355. return a.value;
  356. }
  357. return e[0].value;
  358. });
  359. t.action.current = () => s;
  360. const o = (a) => {
  361. a !== void 0 && (i(a), t.onChange(a));
  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") })
  367. ] });
  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. }), a = R(() => M(i, Number(r || 0)), [i, r]), c = R(() => !Rt(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 = () => a, /* @__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,
  384. {
  385. disabled: c,
  386. value: r,
  387. max: 20,
  388. min: 0,
  389. onChange: m
  390. }
  391. ) }),
  392. /* @__PURE__ */ l.jsxs("div", { className: "m-t-16 label", children: [
  393. " ",
  394. e.t("sheet.numfmt.negType")
  395. ] }),
  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") })
  398. ] });
  399. }, Gn = (t) => {
  400. const { defaultValue: e, defaultPattern: n, row: r, col: s } = t.value, i = b(T), o = xe(() => ""), a = i.t, c = Cn(), m = R(
  401. () => [
  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: a(g.label) })),
  409. []
  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, ht, ft) => w || (ht(n) ? m[ft].label : ""), "") || m[0].label;
  416. }
  417. const I = m.map((g) => ({
  418. label: g.label,
  419. value: g.label
  420. })), P = (g) => {
  421. u(g), c(() => 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
  434. };
  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: a("sheet.numfmt.numfmtType") }),
  440. /* @__PURE__ */ l.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ l.jsx(Re, { onChange: P, 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 }) }) })
  442. ] }),
  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: a("sheet.numfmt.cancel") }),
  445. /* @__PURE__ */ l.jsx($e, { type: "primary", size: "small", onClick: le, children: a("sheet.numfmt.confirm") })
  446. ] })
  447. ] });
  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. }, x = (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, a, c, m, d, u) {
  457. super();
  458. /**
  459. * If _previewPattern is null ,the realTimeRenderingInterceptor will skip and if it is '',realTimeRenderingInterceptor will clear numfmt.
  460. * @private
  461. * @type {(string | null)}
  462. * @memberof NumfmtController
  463. */
  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 = a, this._componentManager = c, this._sidebarService = m, this._localeService = d, this._sheetsNumfmtCellContentController = u, this._initRealTimeRenderingInterceptor(), this._initPanel(), this._initCommands(), this._initCloseListener(), this._commandExecutedListener(), this._initNumfmtLocalChange();
  467. }
  468. _initNumfmtLocalChange() {
  469. this.disposeWithMe(rt(this._sheetsNumfmtCellContentController.local$, this._localeService.currentLocale$).subscribe(() => {
  470. this._forceUpdate();
  471. }));
  472. }
  473. openPanel() {
  474. var y;
  475. const e = this._sidebarService, n = this._selectionManagerService, r = this._commandService, s = this._univerInstanceService, i = this._numfmtService, o = this._localeService, c = (((y = n.getCurrentSelections()) == null ? void 0 : y.map((_) => _.range)) || [])[0];
  476. if (!c)
  477. return !1;
  478. const m = s.getCurrentUnitForType(E.UNIVER_SHEET), d = m.getActiveSheet();
  479. if (!d)
  480. return !1;
  481. const u = d.getCellRaw(c.startRow, c.startColumn), h = i.getValue(
  482. m.getUnitId(),
  483. d.getSheetId(),
  484. c.startRow,
  485. c.startColumn
  486. );
  487. let p = "";
  488. h && (p = h.pattern);
  489. const v = (u == null ? void 0 : u.t) === $.NUMBER ? u.v : 12345678, f = {
  490. onChange: (_) => {
  491. var I;
  492. if (_.type === "change")
  493. this._previewPattern = _.value, this._forceUpdate();
  494. else if (_.type === "confirm") {
  495. const P = ((I = n.getCurrentSelections()) == null ? void 0 : I.map((F) => F.range)) || [], J = { values: [] }, le = ne(_.value);
  496. P.forEach((F) => {
  497. Ve.foreach(F, (me, g) => {
  498. J.values.push({
  499. row: me,
  500. col: g,
  501. pattern: _.value,
  502. type: le
  503. });
  504. });
  505. }), r.executeCommand(Ze.id, J), e.close();
  506. } else _.type === "cancel" && e.close();
  507. },
  508. value: { defaultPattern: p, defaultValue: v, row: c.startRow, col: c.startColumn }
  509. };
  510. return this._sidebarDisposable = e.open({
  511. header: { title: o.t("sheet.numfmt.title") },
  512. children: {
  513. label: Ae,
  514. ...f
  515. // need passthrough to react props.
  516. },
  517. onClose: () => {
  518. this._forceUpdate(), r.executeCommand(he.id);
  519. }
  520. }), !0;
  521. }
  522. _forceUpdate(e) {
  523. var r;
  524. const n = this._renderManagerService.getRenderById(
  525. e != null ? e : this._univerInstanceService.getCurrentUnitForType(E.UNIVER_SHEET).getUnitId()
  526. );
  527. n == null || n.with(Lt).reCalculate(), (r = n == null ? void 0 : n.mainComponent) == null || r.makeDirty();
  528. }
  529. _initCommands() {
  530. [
  531. A,
  532. he
  533. ].forEach((e) => {
  534. this.disposeWithMe(this._commandService.registerCommand(e));
  535. });
  536. }
  537. _initPanel() {
  538. this._componentManager.register(Ae, Gn);
  539. }
  540. // eslint-disable-next-line max-lines-per-function
  541. _initRealTimeRenderingInterceptor() {
  542. const e = new D((r) => {
  543. this._commandService.onCommandExecuted((s) => {
  544. s.id === A.id && r.next(!0), s.id === he.id && r.next(!1);
  545. });
  546. }), n = rn([
  547. e,
  548. this._selectionManagerService.selectionMoveEnd$.pipe(
  549. sn((r) => r ? r.map((s) => s.range) : [])
  550. )
  551. ]);
  552. this.disposeWithMe(
  553. ge(
  554. n.pipe(
  555. on(
  556. ([r, s]) => new D((i) => {
  557. const o = new gt();
  558. return r && s.length && i.next({ selectionRanges: s, disposableCollection: o }), () => {
  559. o.dispose();
  560. };
  561. })
  562. ),
  563. cn(() => {
  564. this._previewPattern = null;
  565. })
  566. ).subscribe(({ disposableCollection: r, selectionRanges: s }) => {
  567. var o, a;
  568. const i = this._univerInstanceService.getCurrentUnitForType(E.UNIVER_SHEET);
  569. this.openPanel(), r.add(
  570. this._sheetInterceptorService.intercept(Zt.CELL_CONTENT, {
  571. priority: 99,
  572. effect: Oe.Value | Oe.Style,
  573. handler: (c, m, d) => {
  574. const { row: u, col: h } = m, p = d(c) || {};
  575. if (s.find(
  576. (v) => v.startColumn <= h && v.endColumn >= h && v.startRow <= u && v.endRow >= u
  577. )) {
  578. const v = m.worksheet.getCellRaw(u, h), f = v == null ? void 0 : v.v, y = v == null ? void 0 : v.t;
  579. if (f == null || y !== $.NUMBER || this._previewPattern === null)
  580. return p;
  581. const _ = jt(this._previewPattern, f, this._sheetsNumfmtCellContentController.local);
  582. if (_.color) {
  583. const P = this._themeService.getCurrentTheme()[`${_.color}500`];
  584. return {
  585. ...p,
  586. v: _.result,
  587. t: $.STRING,
  588. s: { cl: { rgb: P } }
  589. };
  590. }
  591. return {
  592. ...p,
  593. v: _.result,
  594. t: $.STRING
  595. };
  596. }
  597. return p;
  598. }
  599. })
  600. ), (a = (o = this._renderManagerService.getRenderById(i.getUnitId())) == null ? void 0 : o.mainComponent) == null || a.makeDirty();
  601. })
  602. )
  603. );
  604. }
  605. _commandExecutedListener() {
  606. const e = [Ne.id, Ee.id];
  607. this.disposeWithMe(
  608. new D((n) => {
  609. const r = this._commandService.onCommandExecuted((s) => {
  610. if (e.includes(s.id)) {
  611. const i = s.params;
  612. n.next(i.unitId);
  613. }
  614. });
  615. return () => r.dispose();
  616. }).pipe(an(16)).subscribe((n) => this._forceUpdate(n))
  617. );
  618. }
  619. _initCloseListener() {
  620. this._univerInstanceService.getCurrentTypeOfUnit$(E.UNIVER_SHEET).subscribe((e) => {
  621. var n;
  622. e || ((n = this._sidebarDisposable) == null || n.dispose(), this._sidebarDisposable = null);
  623. });
  624. }
  625. };
  626. B = Yn([
  627. x(0, S(nt)),
  628. x(1, S(St)),
  629. x(2, ye),
  630. x(3, be),
  631. x(4, S(Te)),
  632. x(5, Ke),
  633. x(6, Ie),
  634. x(7, S(tt)),
  635. x(8, Wt),
  636. x(9, S(T)),
  637. x(10, S(ze))
  638. ], B);
  639. var Zn = Object.defineProperty, zn = Object.getOwnPropertyDescriptor, Jn = (t, e, n, r) => {
  640. for (var s = r > 1 ? void 0 : r ? zn(e, n) : e, i = t.length - 1, o; i >= 0; i--)
  641. (o = t[i]) && (s = (r ? o(e, n, s) : o(s)) || s);
  642. return r && s && Zn(e, n, s), s;
  643. }, H = (t, e) => (n, r) => e(n, r, t);
  644. const Xn = () => {
  645. let t = [];
  646. return {
  647. add: (s, i, o, a, c) => t.push({ unitId: s, subUnitId: i, row: o, col: a, value: c }),
  648. getEffects: () => t,
  649. clean: () => {
  650. t = [];
  651. }
  652. };
  653. };
  654. let re = class extends oe {
  655. constructor(e, n, r, s, i) {
  656. super();
  657. // collect effect mutations when edit end and push this to commands stack in next commands progress
  658. X(this, "_collectEffectMutation", Xn());
  659. this._sheetInterceptorService = e, this._numfmtService = n, this._univerInstanceService = r, this._injector = s, this._editorBridgeService = i, this._initInterceptorEditorStart(), this._initInterceptorEditorEnd(), this._initInterceptorCommands();
  660. }
  661. _initInterceptorEditorStart() {
  662. this._editorBridgeService && this.disposeWithMe(
  663. ge(
  664. this._sheetInterceptorService.writeCellInterceptor.intercept(
  665. zt,
  666. {
  667. handler: (e, n, r) => {
  668. const s = n.row, i = n.col, o = this._numfmtService.getValue(
  669. n.unitId,
  670. n.subUnitId,
  671. s,
  672. i
  673. );
  674. if (o)
  675. switch (ne(o.pattern)) {
  676. case "scientific":
  677. case "currency":
  678. case "grouped":
  679. case "number": {
  680. const c = n.worksheet.getCellRaw(s, i);
  681. return r && r(c);
  682. }
  683. case "percent":
  684. case "date":
  685. case "time":
  686. case "datetime":
  687. default:
  688. return r && r(e);
  689. }
  690. return r(e);
  691. }
  692. }
  693. )
  694. )
  695. );
  696. }
  697. /**
  698. * Process the values after edit
  699. * @private
  700. * @memberof NumfmtService
  701. */
  702. _initInterceptorEditorEnd() {
  703. this.disposeWithMe(
  704. ge(
  705. this._sheetInterceptorService.writeCellInterceptor.intercept(
  706. Jt,
  707. {
  708. // eslint-disable-next-line complexity
  709. handler: (e, n, r) => {
  710. var d, u, h, p;
  711. this._collectEffectMutation.clean();
  712. const s = this._numfmtService.getValue(
  713. n.unitId,
  714. n.subUnitId,
  715. n.row,
  716. n.col
  717. ), i = (d = s && ne(s.pattern)) != null ? d : "", o = () => {
  718. s && this._collectEffectMutation.add(
  719. n.unitId,
  720. n.subUnitId,
  721. n.row,
  722. n.col,
  723. null
  724. );
  725. };
  726. if (!(e != null && e.v) && !(e != null && e.p) || (s == null ? void 0 : s.pattern) === Ce || e.t === $.FORCE_STRING)
  727. return r(e);
  728. const a = (u = e.p) == null ? void 0 : u.body, c = (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(c) || Q.parseTime(c) || Q.parseNumber(c);
  729. if (a)
  730. if (er(a)) {
  731. const { dataStream: v } = a, f = v.replace(/\r\n$/, ""), y = Number(f);
  732. if (Number.isNaN(y) && !m)
  733. return r(e);
  734. } else
  735. return r(e);
  736. if (m) {
  737. m.z && this._collectEffectMutation.add(
  738. n.unitId,
  739. n.subUnitId,
  740. n.row,
  741. n.col,
  742. {
  743. pattern: m.z
  744. }
  745. );
  746. const v = Number(m.v);
  747. return r({ ...e, p: void 0, v, t: $.NUMBER });
  748. } else (["date", "time", "datetime", "percent"].includes(i) || !Qn(c)) && o();
  749. return r(e);
  750. }
  751. }
  752. )
  753. )
  754. );
  755. }
  756. _initInterceptorCommands() {
  757. const e = this;
  758. this.disposeWithMe(
  759. this._sheetInterceptorService.interceptCommand({
  760. getMutations(n) {
  761. var r;
  762. switch (n.id) {
  763. case Xt.id: {
  764. const s = e._univerInstanceService.getCurrentUnitForType(E.UNIVER_SHEET), i = s.getUnitId(), o = (r = s.getActiveSheet()) == null ? void 0 : r.getSheetId();
  765. if (!o)
  766. return {
  767. redos: [],
  768. undos: []
  769. };
  770. const a = e._collectEffectMutation.getEffects();
  771. if (e._collectEffectMutation.clean(), !a.length)
  772. return {
  773. redos: [],
  774. undos: []
  775. };
  776. const c = a.filter((h) => {
  777. var p;
  778. return !!((p = h.value) != null && p.pattern);
  779. }).map((h) => ({
  780. row: h.row,
  781. col: h.col,
  782. pattern: h.value.pattern
  783. })), m = a.filter((h) => {
  784. var p;
  785. return !((p = h.value) != null && p.pattern);
  786. }).map((h) => ({
  787. startRow: h.row,
  788. endColumn: h.col,
  789. startColumn: h.col,
  790. endRow: h.row
  791. })), d = [], u = [];
  792. if (c.length) {
  793. const h = {
  794. id: Ee.id,
  795. params: Qt(i, o, c)
  796. };
  797. d.push(h), u.push(...en(e._injector, h.params));
  798. }
  799. if (m.length) {
  800. const h = {
  801. id: Ne.id,
  802. params: {
  803. unitId: i,
  804. subUnitId: o,
  805. ranges: m
  806. }
  807. };
  808. d.push(h), u.push(...tn(e._injector, h.params));
  809. }
  810. return {
  811. redos: d,
  812. undos: u.reverse()
  813. };
  814. }
  815. }
  816. return {
  817. redos: [],
  818. undos: []
  819. };
  820. }
  821. })
  822. );
  823. }
  824. };
  825. re = Jn([
  826. H(0, S(nt)),
  827. H(1, S(Ie)),
  828. H(2, S(ye)),
  829. H(3, S(Ge)),
  830. H(4, yt(Ht))
  831. ], re);
  832. function Qn(t) {
  833. return /^-?\d+(\.\d+)?$/.test(t);
  834. }
  835. function er(t) {
  836. const { textRuns: e = [], paragraphs: n = [], customRanges: r, customBlocks: s = [] } = t, i = ["va"];
  837. return !(e.some((o) => !!(o.ts && Object.keys(o.ts).some((c) => i.includes(c)))) || n.some((o) => o.bullet) || n.length >= 2 || r != null && r.length || s.length > 0);
  838. }
  839. const ee = [
  840. {
  841. label: "sheet.numfmt.general",
  842. pattern: null
  843. },
  844. {
  845. label: "sheet.numfmt.text",
  846. pattern: Ce
  847. },
  848. "|",
  849. {
  850. label: "sheet.numfmt.number",
  851. pattern: "0"
  852. },
  853. "|",
  854. {
  855. label: "sheet.numfmt.accounting",
  856. pattern: '"¥" #,##0.00_);[Red]("¥"#,##0.00)'
  857. },
  858. {
  859. label: "sheet.numfmt.financialValue",
  860. pattern: "#,##0.00;[Red]#,##0.00"
  861. },
  862. {
  863. label: "sheet.numfmt.currency",
  864. pattern: '"¥"#,##0.00_);[Red]("¥"#,##0.00)'
  865. },
  866. {
  867. label: "sheet.numfmt.roundingCurrency",
  868. pattern: '"¥"#,##0;[Red]"¥"#,##0'
  869. },
  870. "|",
  871. {
  872. label: "sheet.numfmt.date",
  873. pattern: "yyyy-mm-dd;@"
  874. },
  875. {
  876. label: "sheet.numfmt.time",
  877. pattern: 'am/pm h":"mm":"ss'
  878. },
  879. {
  880. label: "sheet.numfmt.dateTime",
  881. pattern: "yyyy-m-d am/pm h:mm"
  882. },
  883. {
  884. label: "sheet.numfmt.timeDuration",
  885. pattern: "h:mm:ss"
  886. },
  887. "|",
  888. {
  889. label: "sheet.numfmt.moreFmt",
  890. pattern: ""
  891. }
  892. ], tr = (t) => ({
  893. icon: new D((e) => {
  894. const n = t.get(wt);
  895. function r(i) {
  896. return {
  897. [O.US]: "DollarSingle",
  898. [O.RU]: "RoubleSingle",
  899. [O.CN]: "RmbSingle",
  900. [O.AT]: "EuroSingle"
  901. }[i] || "DollarSingle";
  902. }
  903. const s = O[n.getCurrencySymbol()] || "$";
  904. return e.next(r(s)), n.currencySymbol$.subscribe((i) => {
  905. const o = O[i] || "$";
  906. e.next(r(o));
  907. });
  908. }),
  909. id: Je.id,
  910. title: "sheet.numfmt.currency",
  911. tooltip: "sheet.numfmt.currency",
  912. type: G.BUTTON,
  913. hidden$: K(t, E.UNIVER_SHEET),
  914. disabled$: V(t, { workbookTypes: [q], worksheetTypes: [Y, Z], rangeTypes: [z] })
  915. }), nr = (t) => ({
  916. icon: "AddDigitsSingle",
  917. id: Xe.id,
  918. title: "sheet.numfmt.addDecimal",
  919. tooltip: "sheet.numfmt.addDecimal",
  920. type: G.BUTTON,
  921. hidden$: K(t, E.UNIVER_SHEET),
  922. disabled$: V(t, { workbookTypes: [q], worksheetTypes: [Y, Z], rangeTypes: [z] })
  923. }), rr = (t) => ({
  924. icon: "ReduceDigitsSingle",
  925. id: Qe.id,
  926. title: "sheet.numfmt.subtractDecimal",
  927. tooltip: "sheet.numfmt.subtractDecimal",
  928. type: G.BUTTON,
  929. hidden$: K(t, E.UNIVER_SHEET),
  930. disabled$: V(t, { workbookTypes: [q], worksheetTypes: [Y, Z], rangeTypes: [z] })
  931. }), sr = (t) => ({
  932. icon: "PercentSingle",
  933. id: et.id,
  934. title: "sheet.numfmt.percent",
  935. tooltip: "sheet.numfmt.percent",
  936. type: G.BUTTON,
  937. hidden$: K(t, E.UNIVER_SHEET),
  938. disabled$: V(t, { workbookTypes: [q], worksheetTypes: [Y, Z], rangeTypes: [z] })
  939. }), ir = (t) => {
  940. const e = t.get(ye), n = t.get(be), r = t.get(T), s = t.get(Te), i = At(e, "", ({ workbook: o, worksheet: a }) => new D(
  941. (c) => rt(
  942. s.selectionMoveEnd$,
  943. new D((m) => {
  944. const d = [Ne.id, Ee.id], u = n.onCommandExecuted((h) => {
  945. d.includes(h.id) && m.next(null);
  946. });
  947. return () => u.dispose();
  948. })
  949. ).subscribe(() => {
  950. var d, u;
  951. const m = s.getCurrentSelections();
  952. if (m && m[0]) {
  953. const h = m[0].range, p = h.startRow, v = h.startColumn, f = (u = o.getStyles().get((d = a.getCell(p, v)) == null ? void 0 : d.s)) == null ? void 0 : u.n, y = f == null ? void 0 : f.pattern;
  954. let _ = r.t("sheet.numfmt.general");
  955. if (y) {
  956. const I = ee.filter((P) => typeof P == "object" && P.pattern).find(
  957. (P) => ce(y, P.pattern)
  958. );
  959. I && typeof I == "object" && I.pattern ? _ = r.t(I.label) : _ = r.t("sheet.numfmt.moreFmt");
  960. }
  961. c.next(_);
  962. }
  963. })
  964. ));
  965. return {
  966. label: lt,
  967. id: A.id,
  968. tooltip: "sheet.numfmt.title",
  969. type: G.SELECTOR,
  970. selections: [
  971. {
  972. label: {
  973. name: mt,
  974. hoverable: !1
  975. }
  976. }
  977. ],
  978. value$: i,
  979. hidden$: K(t, E.UNIVER_SHEET),
  980. disabled$: V(t, { workbookTypes: [q], worksheetTypes: [Z, Y], rangeTypes: [z] })
  981. };
  982. }, lt = "sheet.numfmt.moreNumfmtType", mt = "sheet.numfmt.moreNumfmtType.options", or = (t) => {
  983. var r;
  984. const e = b(T), n = (r = t.value) != null ? r : e.t("sheet.numfmt.general");
  985. return /* @__PURE__ */ l.jsx("span", { className: "more-numfmt-type", children: n });
  986. }, cr = () => {
  987. const t = b(be), e = b(T), n = b(Vt), r = b(ze), s = b(Te), i = (c) => {
  988. const m = s.getCurrentLastSelection();
  989. if (!m)
  990. return;
  991. const d = m.range, u = [];
  992. Ve.foreach(d, (h, p) => {
  993. c ? u.push({ row: h, col: p, pattern: c, type: ne(c) }) : u.push({ row: h, col: p });
  994. }), t.executeCommand(Ze.id, { values: u }), n.focus();
  995. }, o = (c) => {
  996. if (c === 0)
  997. i(null);
  998. else if (c === ee.length - 1)
  999. t.executeCommand(A.id);
  1000. else {
  1001. const m = ee[c];
  1002. m.pattern && i(m.pattern);
  1003. }
  1004. }, a = 1220;
  1005. return /* @__PURE__ */ l.jsx("div", { className: "more-numfmt-type-options", children: ee.map((c, m) => c === "|" ? /* @__PURE__ */ l.jsx("div", { className: "line m-t-4", onClick: (d) => d.stopPropagation() }, m) : /* @__PURE__ */ l.jsxs(
  1006. "div",
  1007. {
  1008. className: "option-item m-t-4",
  1009. onClick: () => {
  1010. o(m);
  1011. },
  1012. children: [
  1013. /* @__PURE__ */ l.jsx("div", { children: e.t(c.label) }),
  1014. /* @__PURE__ */ l.jsx("div", { className: "m-l-26", children: c.pattern ? Ot(c.pattern || "", a, r.local).result : "" })
  1015. ]
  1016. },
  1017. m
  1018. )) });
  1019. }, ar = {
  1020. [Gt.FORMULAS_INSERT]: {
  1021. [Je.id]: {
  1022. order: 4,
  1023. menuItemFactory: tr
  1024. },
  1025. [Xe.id]: {
  1026. order: 5,
  1027. menuItemFactory: nr
  1028. },
  1029. [Qe.id]: {
  1030. order: 6,
  1031. menuItemFactory: rr
  1032. },
  1033. [et.id]: {
  1034. order: 7,
  1035. menuItemFactory: sr
  1036. },
  1037. [A.id]: {
  1038. order: 8,
  1039. menuItemFactory: ir
  1040. }
  1041. }
  1042. };
  1043. var lr = Object.defineProperty, mr = Object.getOwnPropertyDescriptor, ur = (t, e, n, r) => {
  1044. for (var s = r > 1 ? void 0 : r ? mr(e, n) : e, i = t.length - 1, o; i >= 0; i--)
  1045. (o = t[i]) && (s = (r ? o(e, n, s) : o(s)) || s);
  1046. return r && s && lr(e, n, s), s;
  1047. }, ke = (t, e) => (n, r) => e(n, r, t);
  1048. let se = class extends oe {
  1049. constructor(t, e) {
  1050. super(), this._componentManager = t, this._menuManagerService = e, this._initMenu();
  1051. }
  1052. _initMenu() {
  1053. this._menuManagerService.mergeMenu(ar), this.disposeWithMe(this._componentManager.register(lt, or)), this.disposeWithMe(this._componentManager.register(mt, cr));
  1054. }
  1055. };
  1056. se = ur([
  1057. ke(0, S(tt)),
  1058. ke(1, Kt)
  1059. ], se);
  1060. var ut = Object.defineProperty, dr = Object.getOwnPropertyDescriptor, hr = (t, e, n) => e in t ? ut(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, fr = (t, e, n, r) => {
  1061. for (var s = r > 1 ? void 0 : r ? dr(e, n) : e, i = t.length - 1, o; i >= 0; i--)
  1062. (o = t[i]) && (s = (r ? o(e, n, s) : o(s)) || s);
  1063. return r && s && ut(e, n, s), s;
  1064. }, _e = (t, e) => (n, r) => e(n, r, t), dt = (t, e, n) => hr(t, typeof e != "symbol" ? e + "" : e, n);
  1065. const pr = "SHEET_NUMFMT_UI_PLUGIN";
  1066. let ie = class extends Ct {
  1067. constructor(t = De, e, n, r) {
  1068. super(), this._config = t, this._injector = e, this._configService = n, this._renderManagerService = r;
  1069. const { menu: s, ...i } = It(
  1070. {},
  1071. De,
  1072. this._config
  1073. );
  1074. s && this._configService.setConfig("menu", s, { merge: !0 }), this._configService.setConfig(qt, i);
  1075. }
  1076. onStarting() {
  1077. Nt(this._injector, [
  1078. [B],
  1079. [re],
  1080. [k],
  1081. [se]
  1082. ]);
  1083. }
  1084. onRendered() {
  1085. this._registerRenderModules(), Et(this._injector, [
  1086. [B],
  1087. [re],
  1088. [se]
  1089. ]);
  1090. }
  1091. _registerRenderModules() {
  1092. [
  1093. [Se]
  1094. ].forEach((e) => {
  1095. this.disposeWithMe(this._renderManagerService.registerRenderModule(E.UNIVER_SHEET, e));
  1096. });
  1097. }
  1098. };
  1099. dt(ie, "pluginName", pr);
  1100. dt(ie, "type", E.UNIVER_SHEET);
  1101. ie = fr([
  1102. bt(kt, Ut),
  1103. _e(1, S(Ge)),
  1104. _e(2, Tt),
  1105. _e(3, Ke)
  1106. ], ie);
  1107. export {
  1108. ie as UniverSheetsNumfmtUIPlugin
  1109. };