@univerjs/sheets-numfmt 0.5.5-nightly.202501220324 → 0.5.5

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,13 +1,12 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { numfmt, CommandType, ICommandService, IUniverInstanceService, IUndoRedoService, sequenceExecute, Range, CellValueType, Inject, ThemeService, LocaleService, Disposable, LocaleType, ObjectMatrix, InterceptorEffectEnum, isRealNum, UniverInstanceType, DependentOn, Injector, Plugin, registerDependencies, touchDependencies } from "@univerjs/core";
6
- import { getSheetCommandTarget, transformCellsToRange, rangeMerge, SetNumfmtMutation, factorySetNumfmtUndoMutation, RemoveNumfmtMutation, factoryRemoveNumfmtUndoMutation, SheetsSelectionsService, INumfmtService, SheetInterceptorService, INTERCEPTOR_POINT, InterceptCellContentPriority, SetRangeValuesMutation, UniverSheetsPlugin } from "@univerjs/sheets";
7
- import { BehaviorSubject, merge, switchMap, of, skip } from "rxjs";
8
- import { DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
9
- import { stripErrorMargin } from "@univerjs/engine-formula";
10
- const currencySymbols = [
1
+ var ne = Object.defineProperty;
2
+ var re = (e, t, r) => t in e ? ne(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var y = (e, t, r) => re(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { numfmt as N, CommandType as I, ICommandService as M, IUniverInstanceService as D, IUndoRedoService as se, sequenceExecute as oe, Range as C, CellValueType as A, Inject as E, ThemeService as ce, LocaleService as ae, Disposable as X, LocaleType as b, ObjectMatrix as B, InterceptorEffectEnum as W, isRealNum as ie, UniverInstanceType as Y, DependentOn as ue, Injector as le, Plugin as me, registerDependencies as fe, touchDependencies as G } from "@univerjs/core";
5
+ import { getSheetCommandTarget as w, transformCellsToRange as de, rangeMerge as H, SetNumfmtMutation as Z, factorySetNumfmtUndoMutation as he, RemoveNumfmtMutation as ge, factoryRemoveNumfmtUndoMutation as pe, SheetsSelectionsService as V, INumfmtService as F, SheetInterceptorService as ve, INTERCEPTOR_POINT as Se, InterceptCellContentPriority as _e, SetRangeValuesMutation as ye, UniverSheetsPlugin as be } from "@univerjs/sheets";
6
+ import { BehaviorSubject as j, merge as Ce, switchMap as Me, of as $e, skip as Ee } from "rxjs";
7
+ import { DEFAULT_TEXT_FORMAT as Ne } from "@univerjs/engine-numfmt";
8
+ import { stripErrorMargin as Re } from "@univerjs/engine-formula";
9
+ const J = [
11
10
  "$",
12
11
  "£",
13
12
  "¥",
@@ -35,7 +34,7 @@ const currencySymbols = [
35
34
  "₽",
36
35
  "₾",
37
36
  "₿"
38
- ], countryCurrencyMap = {
37
+ ], Ie = {
39
38
  US: "$",
40
39
  // United States Dollar
41
40
  CA: "C$",
@@ -75,7 +74,7 @@ const currencySymbols = [
75
74
  SI: "€",
76
75
  ES: "€"
77
76
  // Add more mappings as needed
78
- }, DATEFMTLISG = [
77
+ }, Te = [
79
78
  {
80
79
  label: "1930-08-05",
81
80
  suffix: "yyyy-MM-dd"
@@ -120,7 +119,7 @@ const currencySymbols = [
120
119
  label: "08-05 下午 01:30",
121
120
  suffix: "MM-dd A/P hh:mm"
122
121
  }
123
- ], NUMBERFORMAT = [
122
+ ], xe = [
124
123
  {
125
124
  label: "(1,235)",
126
125
  suffix: "#,##0_);(#,##0)"
@@ -148,471 +147,468 @@ const currencySymbols = [
148
147
  suffix: "#,##0.00_);[Red]-#,##0.00",
149
148
  color: "red"
150
149
  }
151
- ], CURRENCYFORMAT = [
150
+ ], Q = [
152
151
  {
153
- label: /* @__PURE__ */ __name((suffix) => `${suffix}1,235`, "label"),
154
- suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);"${suffix}"#,##0.00`, "suffix")
152
+ label: (e) => `${e}1,235`,
153
+ suffix: (e) => `"${e}"#,##0.00_);"${e}"#,##0.00`
155
154
  },
156
155
  {
157
- label: /* @__PURE__ */ __name((suffix) => `${suffix}1,235`, "label"),
158
- suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]"${suffix}"#,##0.00`, "suffix"),
156
+ label: (e) => `${e}1,235`,
157
+ suffix: (e) => `"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,
159
158
  color: "red"
160
159
  },
161
160
  {
162
- label: /* @__PURE__ */ __name((suffix) => `(${suffix}1,235)`, "label"),
163
- suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);("${suffix}"#,##0.00)`, "suffix")
161
+ label: (e) => `(${e}1,235)`,
162
+ suffix: (e) => `"${e}"#,##0.00_);("${e}"#,##0.00)`
164
163
  },
165
164
  {
166
- label: /* @__PURE__ */ __name((suffix) => `(${suffix}1,235)`, "label"),
167
- suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]("${suffix}"#,##0.00)`, "suffix"),
165
+ label: (e) => `(${e}1,235)`,
166
+ suffix: (e) => `"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,
168
167
  color: "red"
169
168
  },
170
169
  {
171
- label: /* @__PURE__ */ __name((suffix) => `-${suffix}1,235`, "label"),
172
- suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);-"${suffix}"#,##0.00`, "suffix")
170
+ label: (e) => `-${e}1,235`,
171
+ suffix: (e) => `"${e}"#,##0.00_);-"${e}"#,##0.00`
173
172
  },
174
173
  {
175
- label: /* @__PURE__ */ __name((suffix) => `-${suffix}1,235`, "label"),
176
- suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`, "suffix"),
174
+ label: (e) => `-${e}1,235`,
175
+ suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
177
176
  color: "red"
178
177
  }
179
- ], SHEET_NUMFMT_PLUGIN = "SHEET_NUMFMT_PLUGIN", getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0) => {
180
- var _a3;
181
- return pattern && (_a3 = numfmt.getInfo(pattern).maxDecimals) != null ? _a3 : defaultValue;
182
- }, "getDecimalFromPattern"), isPatternEqualWithoutDecimal = /* @__PURE__ */ __name((patternA, patternB) => {
183
- if (patternA && !patternB || !patternA && patternB)
178
+ ], Pe = "SHEET_NUMFMT_PLUGIN", x = (e, t = 0) => {
179
+ var n;
180
+ return e && (n = N.getInfo(e).maxDecimals) != null ? n : t;
181
+ }, Ze = (e, t) => {
182
+ if (e && !t || !e && t)
184
183
  return !1;
185
- const getString = /* @__PURE__ */ __name((tokens) => tokens.reduce(
186
- (pre, cur) => {
187
- if (pre.isEnd)
188
- return pre;
189
- const str = cur.value || cur.num;
190
- return cur.type === "point" ? (pre.isEnd = !0, pre) : { ...pre, result: pre.result + str };
184
+ const r = (c) => c.reduce(
185
+ (l, h) => {
186
+ if (l.isEnd)
187
+ return l;
188
+ const f = h.value || h.num;
189
+ return h.type === "point" ? (l.isEnd = !0, l) : { ...l, result: l.result + f };
191
190
  },
192
191
  { isEnd: !1, result: "" }
193
- ).result, "getString"), partitionsA = numfmt.getInfo(patternA)._partitions, partitionsB = numfmt.getInfo(patternB)._partitions, A1 = getString(partitionsA[0].tokens), B1 = getString(partitionsB[0].tokens), A2 = getString(partitionsA[1].tokens), B2 = getString(partitionsB[1].tokens);
194
- return A1 === B1 && A2 === B2 && partitionsA[1].color === partitionsB[1].color;
195
- }, "isPatternEqualWithoutDecimal"), getDecimalString = /* @__PURE__ */ __name((length) => new Array(Math.min(Math.max(0, Number(length)), 30)).fill(0).join(""), "getDecimalString"), setPatternDecimal = /* @__PURE__ */ __name((patterns, decimalLength) => patterns.split(";").map((pattern) => /\.0?/.test(pattern) ? pattern.replace(
192
+ ).result, n = N.getInfo(e)._partitions, s = N.getInfo(t)._partitions, o = r(n[0].tokens), a = r(s[0].tokens), d = r(n[1].tokens), u = r(s[1].tokens);
193
+ return o === a && d === u && n[1].color === s[1].color;
194
+ }, z = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), P = (e, t) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
196
195
  /\.0*/g,
197
- `${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}`
198
- ) : /0([^0]?)|0$/.test(pattern) ? pattern.replace(
196
+ `${t > 0 ? "." : ""}${z(Number(t || 0))}`
197
+ ) : /0([^0]?)|0$/.test(n) ? n.replace(
199
198
  /0([^0]+)|0$/,
200
- `0${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}$1`
201
- ) : pattern).join(";"), "setPatternDecimal"), isPatternHasDecimal = /* @__PURE__ */ __name((pattern) => /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern), "isPatternHasDecimal"), SetNumfmtCommand = {
199
+ `0${t > 0 ? "." : ""}${z(Number(t || 0))}$1`
200
+ ) : n).join(";"), Je = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), T = {
202
201
  id: "sheet.command.numfmt.set.numfmt",
203
- type: CommandType.COMMAND,
204
- handler: /* @__PURE__ */ __name((accessor, params) => {
205
- if (!params)
202
+ type: I.COMMAND,
203
+ handler: (e, t) => {
204
+ if (!t)
206
205
  return !1;
207
- const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), undoRedoService = accessor.get(IUndoRedoService), target = getSheetCommandTarget(univerInstanceService, params);
208
- if (!target) return !1;
209
- const { unitId, subUnitId } = target, setCells = params.values.filter((value) => !!value.pattern), removeCells = params.values.filter((value) => !value.pattern), setRedos = transformCellsToRange(unitId, subUnitId, setCells), removeRedos = {
210
- unitId,
211
- subUnitId,
212
- ranges: removeCells.map((cell) => ({
213
- startColumn: cell.col,
214
- startRow: cell.row,
215
- endColumn: cell.col,
216
- endRow: cell.row
206
+ const r = e.get(M), n = e.get(D), s = e.get(se), o = w(n, t);
207
+ if (!o) return !1;
208
+ const { unitId: a, subUnitId: d } = o, u = t.values.filter((i) => !!i.pattern), c = t.values.filter((i) => !i.pattern), l = de(a, d, u), h = {
209
+ unitId: a,
210
+ subUnitId: d,
211
+ ranges: c.map((i) => ({
212
+ startColumn: i.col,
213
+ startRow: i.row,
214
+ endColumn: i.col,
215
+ endRow: i.row
217
216
  }))
218
- }, redos = [], undos = [];
219
- if (setCells.length) {
220
- Object.keys(setRedos.values).forEach((key) => {
221
- const v = setRedos.values[key];
222
- v.ranges = rangeMerge(v.ranges);
223
- }), redos.push({
224
- id: SetNumfmtMutation.id,
225
- params: setRedos
217
+ }, f = [], v = [];
218
+ if (u.length) {
219
+ Object.keys(l.values).forEach((g) => {
220
+ const p = l.values[g];
221
+ p.ranges = H(p.ranges);
222
+ }), f.push({
223
+ id: Z.id,
224
+ params: l
226
225
  });
227
- const undo = factorySetNumfmtUndoMutation(accessor, setRedos);
228
- undos.push(...undo);
226
+ const i = he(e, l);
227
+ v.push(...i);
229
228
  }
230
- if (removeCells.length) {
231
- removeRedos.ranges = rangeMerge(removeRedos.ranges), redos.push({
232
- id: RemoveNumfmtMutation.id,
233
- params: removeRedos
229
+ if (c.length) {
230
+ h.ranges = H(h.ranges), f.push({
231
+ id: ge.id,
232
+ params: h
234
233
  });
235
- const undo = factoryRemoveNumfmtUndoMutation(accessor, removeRedos);
236
- undos.push(...undo);
234
+ const i = pe(e, h);
235
+ v.push(...i);
237
236
  }
238
- const result = sequenceExecute(redos, commandService).result;
239
- return result && undoRedoService.pushUndoRedo({
240
- unitID: unitId,
241
- undoMutations: undos,
242
- redoMutations: redos
243
- }), result;
244
- }, "handler")
245
- }, AddDecimalCommand = {
237
+ const m = oe(f, r).result;
238
+ return m && s.pushUndoRedo({
239
+ unitID: a,
240
+ undoMutations: v,
241
+ redoMutations: f
242
+ }), m;
243
+ }
244
+ }, Ue = {
246
245
  id: "sheet.command.numfmt.add.decimal.command",
247
- type: CommandType.COMMAND,
248
- handler: /* @__PURE__ */ __name(async (accessor) => {
249
- const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), selections = selectionManagerService.getCurrentSelections();
250
- if (!selections || !selections.length)
246
+ type: I.COMMAND,
247
+ handler: async (e) => {
248
+ const t = e.get(M), r = e.get(V), n = e.get(F), s = e.get(D), o = r.getCurrentSelections();
249
+ if (!o || !o.length)
251
250
  return !1;
252
- const target = getSheetCommandTarget(univerInstanceService);
253
- if (!target) return !1;
254
- const { unitId, subUnitId } = target;
255
- let maxDecimals = 0;
256
- selections.forEach((selection) => {
257
- Range.foreach(selection.range, (row, col) => {
258
- const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
259
- if (!numfmtValue) {
260
- const cell = target.worksheet.getCellRaw(row, col);
261
- if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
262
- const regResult = /\.(\d*)$/.exec(String(cell.v));
263
- if (regResult) {
264
- const length = regResult[1].length;
265
- if (!length)
251
+ const a = w(s);
252
+ if (!a) return !1;
253
+ const { unitId: d, subUnitId: u } = a;
254
+ let c = 0;
255
+ o.forEach((v) => {
256
+ C.foreach(v.range, (m, i) => {
257
+ const g = n.getValue(d, u, m, i);
258
+ if (!g) {
259
+ const S = a.worksheet.getCellRaw(m, i);
260
+ if (!c && S && S.t === A.NUMBER && S.v) {
261
+ const _ = /\.(\d*)$/.exec(String(S.v));
262
+ if (_) {
263
+ const R = _[1].length;
264
+ if (!R)
266
265
  return;
267
- maxDecimals = Math.max(maxDecimals, length);
266
+ c = Math.max(c, R);
268
267
  }
269
268
  }
270
269
  return;
271
270
  }
272
- const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
273
- maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
271
+ const p = x(g.pattern);
272
+ c = p > c ? p : c;
274
273
  });
275
274
  });
276
- const decimals = maxDecimals + 1, defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : ""}`, decimals), values = [];
277
- return selections.forEach((selection) => {
278
- Range.foreach(selection.range, (row, col) => {
279
- const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
280
- if (!numfmtValue)
281
- values.push({
282
- row,
283
- col,
284
- pattern: defaultPattern
275
+ const l = c + 1, h = P(`0${l > 0 ? ".0" : ""}`, l), f = [];
276
+ return o.forEach((v) => {
277
+ C.foreach(v.range, (m, i) => {
278
+ const g = n.getValue(d, u, m, i);
279
+ if (!g)
280
+ f.push({
281
+ row: m,
282
+ col: i,
283
+ pattern: h
285
284
  });
286
285
  else {
287
- const decimals2 = getDecimalFromPattern(numfmtValue.pattern), pattern = setPatternDecimal(numfmtValue.pattern, decimals2 + 1);
288
- pattern !== numfmtValue.pattern && values.push({
289
- row,
290
- col,
291
- pattern
286
+ const p = x(g.pattern), S = P(g.pattern, p + 1);
287
+ S !== g.pattern && f.push({
288
+ row: m,
289
+ col: i,
290
+ pattern: S
292
291
  });
293
292
  }
294
293
  });
295
- }), values.length ? await commandService.executeCommand(SetNumfmtCommand.id, { values }) : !1;
296
- }, "handler")
297
- }, _MenuCurrencyService = class _MenuCurrencyService {
294
+ }), f.length ? await t.executeCommand(T.id, { values: f }) : !1;
295
+ }
296
+ };
297
+ class k {
298
298
  constructor() {
299
- __publicField(this, "_currencySymbol$", new BehaviorSubject("US"));
300
- __publicField(this, "currencySymbol$", this._currencySymbol$.asObservable());
299
+ y(this, "_currencySymbol$", new j("US"));
300
+ y(this, "currencySymbol$", this._currencySymbol$.asObservable());
301
301
  }
302
302
  /**
303
303
  * Set the currency symbol by setting the country code.
304
304
  */
305
- setCurrencySymbolByCountryCode(symbol) {
306
- this._currencySymbol$.next(symbol);
305
+ setCurrencySymbolByCountryCode(t) {
306
+ this._currencySymbol$.next(t);
307
307
  }
308
308
  getCurrencySymbol() {
309
309
  return this._currencySymbol$.getValue();
310
310
  }
311
- };
312
- __name(_MenuCurrencyService, "MenuCurrencyService");
313
- let MenuCurrencyService = _MenuCurrencyService;
314
- const SetCurrencyCommand = {
311
+ }
312
+ const Oe = {
315
313
  id: "sheet.command.numfmt.set.currency",
316
- type: CommandType.COMMAND,
317
- handler: /* @__PURE__ */ __name(async (accessor) => {
318
- const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), menuCurrencyService = accessor.get(MenuCurrencyService), symbol = countryCurrencyMap[menuCurrencyService.getCurrencySymbol()] || "$", selections = selectionManagerService.getCurrentSelections();
319
- if (!selections || !selections.length)
314
+ type: I.COMMAND,
315
+ handler: async (e) => {
316
+ const t = e.get(M), r = e.get(V), n = e.get(k), s = Ie[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
317
+ if (!o || !o.length)
320
318
  return !1;
321
- const values = [], suffix = CURRENCYFORMAT[4].suffix(symbol);
322
- return selections.forEach((selection) => {
323
- Range.foreach(selection.range, (row, col) => {
324
- values.push({ row, col, pattern: suffix, type: "currency" });
319
+ const a = [], d = Q[4].suffix(s);
320
+ return o.forEach((c) => {
321
+ C.foreach(c.range, (l, h) => {
322
+ a.push({ row: l, col: h, pattern: d, type: "currency" });
325
323
  });
326
- }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
327
- }, "handler")
328
- }, SetPercentCommand = {
324
+ }), await t.executeCommand(T.id, { values: a });
325
+ }
326
+ }, De = {
329
327
  id: "sheet.command.numfmt.set.percent",
330
- type: CommandType.COMMAND,
331
- handler: /* @__PURE__ */ __name(async (accessor) => {
332
- const commandService = accessor.get(ICommandService), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
333
- if (!selections || !selections.length)
328
+ type: I.COMMAND,
329
+ handler: async (e) => {
330
+ const t = e.get(M), n = e.get(V).getCurrentSelections();
331
+ if (!n || !n.length)
334
332
  return !1;
335
- const values = [], suffix = "0%";
336
- return selections.forEach((selection) => {
337
- Range.foreach(selection.range, (row, col) => {
338
- values.push({ row, col, pattern: suffix, type: "percent" });
333
+ const s = [], o = "0%";
334
+ return n.forEach((d) => {
335
+ C.foreach(d.range, (u, c) => {
336
+ s.push({ row: u, col: c, pattern: o, type: "percent" });
339
337
  });
340
- }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
341
- }, "handler")
342
- }, SubtractDecimalCommand = {
338
+ }), await t.executeCommand(T.id, { values: s });
339
+ }
340
+ }, Ve = {
343
341
  id: "sheet.command.numfmt.subtract.decimal.command",
344
- type: CommandType.COMMAND,
345
- handler: /* @__PURE__ */ __name(async (accessor) => {
346
- const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), selections = selectionManagerService.getCurrentSelections();
347
- if (!selections || !selections.length)
342
+ type: I.COMMAND,
343
+ handler: async (e) => {
344
+ const t = e.get(M), r = e.get(V), n = e.get(F), s = e.get(D), o = r.getCurrentSelections();
345
+ if (!o || !o.length)
348
346
  return !1;
349
- const target = getSheetCommandTarget(univerInstanceService);
350
- if (!target) return !1;
351
- const { unitId, subUnitId } = target;
352
- let maxDecimals = 0;
353
- selections.forEach((selection) => {
354
- Range.foreach(selection.range, (row, col) => {
355
- const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
356
- if (!numfmtValue) {
357
- const cell = target.worksheet.getCellRaw(row, col);
358
- if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
359
- const regResult = /\.(\d*)$/.exec(String(cell.v));
360
- if (regResult) {
361
- const length = regResult[1].length;
362
- if (!length)
347
+ const a = w(s);
348
+ if (!a) return !1;
349
+ const { unitId: d, subUnitId: u } = a;
350
+ let c = 0;
351
+ o.forEach((m) => {
352
+ C.foreach(m.range, (i, g) => {
353
+ const p = n.getValue(d, u, i, g);
354
+ if (!p) {
355
+ const _ = a.worksheet.getCellRaw(i, g);
356
+ if (!c && _ && _.t === A.NUMBER && _.v) {
357
+ const R = /\.(\d*)$/.exec(String(_.v));
358
+ if (R) {
359
+ const L = R[1].length;
360
+ if (!L)
363
361
  return;
364
- maxDecimals = Math.max(maxDecimals, length);
362
+ c = Math.max(c, L);
365
363
  }
366
364
  }
367
365
  return;
368
366
  }
369
- const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
370
- maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
367
+ const S = x(p.pattern);
368
+ c = S > c ? S : c;
371
369
  });
372
370
  });
373
- const decimals = maxDecimals - 1, defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : "."}`, decimals), values = [];
374
- return selections.forEach((selection) => {
375
- Range.foreach(selection.range, (row, col) => {
376
- const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
377
- if (!numfmtValue)
378
- values.push({
379
- row,
380
- col,
381
- pattern: defaultPattern
371
+ const l = c - 1, h = P(`0${l > 0 ? ".0" : "."}`, l), f = [];
372
+ return o.forEach((m) => {
373
+ C.foreach(m.range, (i, g) => {
374
+ const p = n.getValue(d, u, i, g);
375
+ if (!p)
376
+ f.push({
377
+ row: i,
378
+ col: g,
379
+ pattern: h
382
380
  });
383
381
  else {
384
- const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
385
- values.push({
386
- row,
387
- col,
388
- pattern: setPatternDecimal(numfmtValue.pattern, decimals2 - 1)
382
+ const S = x(p.pattern);
383
+ f.push({
384
+ row: i,
385
+ col: g,
386
+ pattern: P(p.pattern, S - 1)
389
387
  });
390
388
  }
391
389
  });
392
- }), await commandService.executeCommand(SetNumfmtCommand.id, { values });
393
- }, "handler")
394
- }, getPatternType = /* @__PURE__ */ __name((pattern) => numfmt.getInfo(pattern).type || "unknown", "getPatternType"), getPatternPreview = /* @__PURE__ */ __name((pattern, value, locale = "en") => {
395
- const negInfo = numfmt.getInfo(pattern)._partitions[1], result = numfmt.format(pattern, value, { locale, throws: !1 });
396
- return value < 0 ? {
397
- result,
398
- color: negInfo.color
390
+ }), await t.executeCommand(T.id, { values: f });
391
+ }
392
+ }, Qe = (e) => N.getInfo(e).type || "unknown", Ae = (e, t, r = "en") => {
393
+ const s = N.getInfo(e)._partitions[1], o = N.format(e, t, { locale: r, throws: !1 });
394
+ return t < 0 ? {
395
+ result: o,
396
+ color: s.color
399
397
  } : {
400
- result
398
+ result: o
401
399
  };
402
- }, "getPatternPreview"), getPatternPreviewIgnoreGeneral = /* @__PURE__ */ __name((pattern, value, locale) => pattern === "General" ? {
403
- result: String(stripErrorMargin(value))
400
+ }, we = (e, t, r) => e === "General" ? {
401
+ result: String(Re(t))
404
402
  // In Excel, the default General format also needs to handle numeric precision.
405
- } : getPatternPreview(pattern, value, locale), "getPatternPreviewIgnoreGeneral");
406
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
407
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
408
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
409
- return kind && result && __defProp$1(target, key, result), result;
410
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a;
411
- let SheetsNumfmtCellContentController = (_a = class extends Disposable {
412
- constructor(_instanceService, _sheetInterceptorService, _themeService, _commandService, _numfmtService, _localeService) {
403
+ } : Ae(e, t, r);
404
+ var Fe = Object.defineProperty, je = Object.getOwnPropertyDescriptor, Le = (e, t, r, n) => {
405
+ for (var s = n > 1 ? void 0 : n ? je(t, r) : t, o = e.length - 1, a; o >= 0; o--)
406
+ (a = e[o]) && (s = (n ? a(t, r, s) : a(s)) || s);
407
+ return n && s && Fe(t, r, s), s;
408
+ }, $ = (e, t) => (r, n) => t(r, n, e);
409
+ let U = class extends X {
410
+ constructor(t, r, n, s, o, a) {
413
411
  super();
414
- __publicField(this, "_local$", new BehaviorSubject("en"));
415
- __publicField(this, "local$", this._local$.asObservable());
416
- this._instanceService = _instanceService, this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._commandService = _commandService, this._numfmtService = _numfmtService, this._localeService = _localeService, this._initInterceptorCellContent();
412
+ y(this, "_local$", new j("en"));
413
+ y(this, "local$", this._local$.asObservable());
414
+ this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = a, this._initInterceptorCellContent();
417
415
  }
418
416
  get local() {
419
- const _local = this._local$.getValue();
420
- if (_local)
421
- return _local;
417
+ const t = this._local$.getValue();
418
+ if (t)
419
+ return t;
422
420
  switch (this._localeService.getCurrentLocale()) {
423
- case LocaleType.FR_FR:
421
+ case b.FR_FR:
424
422
  return "fr";
425
- case LocaleType.RU_RU:
423
+ case b.RU_RU:
426
424
  return "ru";
427
- case LocaleType.VI_VN:
425
+ case b.VI_VN:
428
426
  return "vi";
429
- case LocaleType.ZH_CN:
427
+ case b.ZH_CN:
430
428
  return "zh-CN";
431
- case LocaleType.ZH_TW:
429
+ case b.ZH_TW:
432
430
  return "zh-TW";
433
- case LocaleType.EN_US:
434
- case LocaleType.FA_IR:
431
+ case b.EN_US:
432
+ case b.FA_IR:
435
433
  default:
436
434
  return "en";
437
435
  }
438
436
  }
439
437
  // eslint-disable-next-line max-lines-per-function
440
438
  _initInterceptorCellContent() {
441
- const TEXT_FORMAT_MARK = {
439
+ const t = {
442
440
  tl: {
443
441
  size: 6,
444
442
  color: "#409f11"
445
443
  }
446
- }, renderCache = new ObjectMatrix();
447
- this.disposeWithMe(merge(this._local$, this._localeService.currentLocale$).subscribe(() => {
448
- renderCache.reset();
449
- })), this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
450
- effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
451
- handler: /* @__PURE__ */ __name((cell, location, next) => {
452
- const unitId = location.unitId, sheetId = location.subUnitId;
453
- let numfmtValue;
454
- const originCellValue = cell;
455
- if (!originCellValue)
456
- return next(cell);
457
- if (cell != null && cell.s) {
458
- const style = location.workbook.getStyles().get(cell.s);
459
- style != null && style.n && (numfmtValue = style.n);
444
+ }, r = new B();
445
+ this.disposeWithMe(Ce(this._local$, this._localeService.currentLocale$).subscribe(() => {
446
+ r.reset();
447
+ })), this.disposeWithMe(this._sheetInterceptorService.intercept(Se.CELL_CONTENT, {
448
+ effect: W.Value | W.Style,
449
+ handler: (n, s, o) => {
450
+ const a = s.unitId, d = s.subUnitId;
451
+ let u;
452
+ const c = n;
453
+ if (!c)
454
+ return o(n);
455
+ if (n != null && n.s) {
456
+ const m = s.workbook.getStyles().get(n.s);
457
+ m != null && m.n && (u = m.n);
460
458
  }
461
- if (numfmtValue || (numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col)), !numfmtValue)
462
- return next(cell);
463
- if (numfmtValue.pattern === DEFAULT_TEXT_FORMAT && originCellValue.v && isRealNum(originCellValue.v))
464
- return next({
465
- ...cell,
459
+ if (u || (u = this._numfmtService.getValue(a, d, s.row, s.col)), !u)
460
+ return o(n);
461
+ if (u.pattern === Ne && c.v && ie(c.v))
462
+ return o({
463
+ ...n,
466
464
  markers: {
467
- ...cell == null ? void 0 : cell.markers,
468
- ...TEXT_FORMAT_MARK
465
+ ...n == null ? void 0 : n.markers,
466
+ ...t
469
467
  }
470
468
  });
471
- if (originCellValue.t !== CellValueType.NUMBER || originCellValue.v == null || Number.isNaN(originCellValue.v))
472
- return next(cell);
473
- let numfmtRes = "";
474
- const cache = renderCache.getValue(location.row, location.col);
475
- if (cache && cache.parameters === `${originCellValue.v}_${numfmtValue.pattern}`)
476
- return next({ ...cell, ...cache.result });
477
- const info = getPatternPreviewIgnoreGeneral(numfmtValue.pattern, Number(originCellValue.v), this.local);
478
- if (numfmtRes = info.result, !numfmtRes)
479
- return next(cell);
480
- const res = { v: numfmtRes };
481
- if (info.color) {
482
- const color = this._themeService.getCurrentTheme()[`${info.color}500`];
483
- color && (res.interceptorStyle = { cl: { rgb: color } });
469
+ if (c.t !== A.NUMBER || c.v == null || Number.isNaN(c.v))
470
+ return o(n);
471
+ let l = "";
472
+ const h = r.getValue(s.row, s.col);
473
+ if (h && h.parameters === `${c.v}_${u.pattern}`)
474
+ return o({ ...n, ...h.result });
475
+ const f = we(u.pattern, Number(c.v), this.local);
476
+ if (l = f.result, !l)
477
+ return o(n);
478
+ const v = { v: l };
479
+ if (f.color) {
480
+ const m = this._themeService.getCurrentTheme()[`${f.color}500`];
481
+ m && (v.interceptorStyle = { cl: { rgb: m } });
484
482
  }
485
- return renderCache.setValue(location.row, location.col, {
486
- result: res,
487
- parameters: `${originCellValue.v}_${numfmtValue.pattern}`
488
- }), next({ ...cell, ...res });
489
- }, "handler"),
490
- priority: InterceptCellContentPriority.NUMFMT
491
- })), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
492
- if (commandInfo.id === SetNumfmtMutation.id) {
493
- const params = commandInfo.params;
494
- Object.keys(params.values).forEach((key) => {
495
- params.values[key].ranges.forEach((range) => {
496
- Range.foreach(range, (row, col) => {
497
- renderCache.realDeleteValue(row, col);
483
+ return r.setValue(s.row, s.col, {
484
+ result: v,
485
+ parameters: `${c.v}_${u.pattern}`
486
+ }), o({ ...n, ...v });
487
+ },
488
+ priority: _e.NUMFMT
489
+ })), this.disposeWithMe(this._commandService.onCommandExecuted((n) => {
490
+ if (n.id === Z.id) {
491
+ const s = n.params;
492
+ Object.keys(s.values).forEach((o) => {
493
+ s.values[o].ranges.forEach((d) => {
494
+ C.foreach(d, (u, c) => {
495
+ r.realDeleteValue(u, c);
498
496
  });
499
497
  });
500
498
  });
501
- } else if (commandInfo.id === SetRangeValuesMutation.id) {
502
- const params = commandInfo.params;
503
- new ObjectMatrix(params.cellValue).forValue((row, col) => {
504
- renderCache.realDeleteValue(row, col);
499
+ } else if (n.id === ye.id) {
500
+ const s = n.params;
501
+ new B(s.cellValue).forValue((o, a) => {
502
+ r.realDeleteValue(o, a);
505
503
  });
506
504
  }
507
505
  })), this.disposeWithMe(
508
- this._instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(
509
- switchMap((workbook) => {
510
- var _a3;
511
- return (_a3 = workbook == null ? void 0 : workbook.activeSheet$) != null ? _a3 : of(null);
506
+ this._instanceService.getCurrentTypeOfUnit$(Y.UNIVER_SHEET).pipe(
507
+ Me((n) => {
508
+ var s;
509
+ return (s = n == null ? void 0 : n.activeSheet$) != null ? s : $e(null);
512
510
  }),
513
- skip(1)
514
- ).subscribe(() => renderCache.reset())
511
+ Ee(1)
512
+ ).subscribe(() => r.reset())
515
513
  );
516
514
  }
517
- setNumfmtLocal(local) {
518
- this._local$.next(local);
515
+ setNumfmtLocal(t) {
516
+ this._local$.next(t);
519
517
  }
520
- }, __name(_a, "SheetsNumfmtCellContentController"), _a);
521
- SheetsNumfmtCellContentController = __decorateClass$1([
522
- __decorateParam$1(0, IUniverInstanceService),
523
- __decorateParam$1(1, Inject(SheetInterceptorService)),
524
- __decorateParam$1(2, Inject(ThemeService)),
525
- __decorateParam$1(3, Inject(ICommandService)),
526
- __decorateParam$1(4, Inject(INumfmtService)),
527
- __decorateParam$1(5, Inject(LocaleService))
528
- ], SheetsNumfmtCellContentController);
529
- const _NumfmtCurrencyController = class _NumfmtCurrencyController extends Disposable {
518
+ };
519
+ U = Le([
520
+ $(0, D),
521
+ $(1, E(ve)),
522
+ $(2, E(ce)),
523
+ $(3, E(M)),
524
+ $(4, E(F)),
525
+ $(5, E(ae))
526
+ ], U);
527
+ class K extends X {
530
528
  constructor() {
531
529
  super(...arguments);
532
- __publicField(this, "_currencySymbol$", new BehaviorSubject("US"));
533
- __publicField(this, "currencySymbol$", this._currencySymbol$.asObservable());
530
+ y(this, "_currencySymbol$", new j("US"));
531
+ y(this, "currencySymbol$", this._currencySymbol$.asObservable());
534
532
  }
535
533
  /**
536
534
  * Set the currency symbol by setting the country code.
537
535
  */
538
- setCurrencySymbolByCountryCode(symbol) {
539
- this._currencySymbol$.next(symbol);
536
+ setCurrencySymbolByCountryCode(r) {
537
+ this._currencySymbol$.next(r);
540
538
  }
541
539
  getCurrencySymbol() {
542
540
  return this._currencySymbol$.getValue();
543
541
  }
544
- };
545
- __name(_NumfmtCurrencyController, "NumfmtCurrencyController");
546
- let NumfmtCurrencyController = _NumfmtCurrencyController;
547
- var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
548
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
549
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
550
- return kind && result && __defProp2(target, key, result), result;
551
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a2;
552
- let UniverSheetsNumfmtPlugin = (_a2 = class extends Plugin {
553
- constructor(_config = void 0, _injector, _commandService) {
554
- super(), this._config = _config, this._injector = _injector, this._commandService = _commandService;
542
+ }
543
+ var ee = Object.defineProperty, Be = Object.getOwnPropertyDescriptor, We = (e, t, r) => t in e ? ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Ge = (e, t, r, n) => {
544
+ for (var s = n > 1 ? void 0 : n ? Be(t, r) : t, o = e.length - 1, a; o >= 0; o--)
545
+ (a = e[o]) && (s = (n ? a(t, r, s) : a(s)) || s);
546
+ return n && s && ee(t, r, s), s;
547
+ }, q = (e, t) => (r, n) => t(r, n, e), te = (e, t, r) => We(e, typeof t != "symbol" ? t + "" : t, r);
548
+ let O = class extends me {
549
+ constructor(e = void 0, t, r) {
550
+ super(), this._config = e, this._injector = t, this._commandService = r;
555
551
  }
556
552
  onStarting() {
557
- registerDependencies(this._injector, [
558
- [SheetsNumfmtCellContentController],
559
- [MenuCurrencyService],
560
- [NumfmtCurrencyController]
561
- ]), touchDependencies(this._injector, [
562
- [SheetsNumfmtCellContentController]
553
+ fe(this._injector, [
554
+ [U],
555
+ [k],
556
+ [K]
557
+ ]), G(this._injector, [
558
+ [U]
563
559
  ]);
564
560
  }
565
561
  onRendered() {
566
- touchDependencies(this._injector, [
567
- [NumfmtCurrencyController]
562
+ G(this._injector, [
563
+ [K]
568
564
  ]), [
569
- AddDecimalCommand,
570
- SubtractDecimalCommand,
571
- SetCurrencyCommand,
572
- SetPercentCommand,
573
- SetNumfmtCommand
574
- ].forEach((config) => {
575
- this.disposeWithMe(this._commandService.registerCommand(config));
565
+ Ue,
566
+ Ve,
567
+ Oe,
568
+ De,
569
+ T
570
+ ].forEach((e) => {
571
+ this.disposeWithMe(this._commandService.registerCommand(e));
576
572
  });
577
573
  }
578
- }, __name(_a2, "UniverSheetsNumfmtPlugin"), _a2);
579
- __publicField2(UniverSheetsNumfmtPlugin, "pluginName", SHEET_NUMFMT_PLUGIN);
580
- __publicField2(UniverSheetsNumfmtPlugin, "type", UniverInstanceType.UNIVER_SHEET);
581
- UniverSheetsNumfmtPlugin = __decorateClass([
582
- DependentOn(UniverSheetsPlugin),
583
- __decorateParam(1, Inject(Injector)),
584
- __decorateParam(2, ICommandService)
585
- ], UniverSheetsNumfmtPlugin);
586
- const getCurrencyType = /* @__PURE__ */ __name((pattern) => currencySymbols.find((code) => pattern.includes(code)), "getCurrencyType"), getCurrencyOptions = /* @__PURE__ */ __name(() => currencySymbols.map((item) => ({ label: item, value: item })), "getCurrencyOptions"), getCurrencyFormatOptions = /* @__PURE__ */ __name((suffix) => CURRENCYFORMAT.map((item) => ({
587
- label: item.label(suffix),
588
- value: item.suffix(suffix),
589
- color: item.color
590
- })), "getCurrencyFormatOptions"), getDateFormatOptions = /* @__PURE__ */ __name(() => DATEFMTLISG.map((item) => ({ label: item.label, value: item.suffix })), "getDateFormatOptions"), getNumberFormatOptions = /* @__PURE__ */ __name(() => NUMBERFORMAT.map((item) => ({ label: item.label, value: item.suffix, color: item.color })), "getNumberFormatOptions");
574
+ };
575
+ te(O, "pluginName", Pe);
576
+ te(O, "type", Y.UNIVER_SHEET);
577
+ O = Ge([
578
+ ue(be),
579
+ q(1, E(le)),
580
+ q(2, M)
581
+ ], O);
582
+ const ke = (e) => J.find((r) => e.includes(r)), et = () => J.map((e) => ({ label: e, value: e })), tt = (e) => Q.map((t) => ({
583
+ label: t.label(e),
584
+ value: t.suffix(e),
585
+ color: t.color
586
+ })), nt = () => Te.map((e) => ({ label: e.label, value: e.suffix })), rt = () => xe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
591
587
  export {
592
- AddDecimalCommand,
593
- CURRENCYFORMAT,
594
- DATEFMTLISG,
595
- MenuCurrencyService,
596
- NUMBERFORMAT,
597
- SetCurrencyCommand,
598
- SetNumfmtCommand,
599
- SetPercentCommand,
600
- SheetsNumfmtCellContentController,
601
- SubtractDecimalCommand,
602
- UniverSheetsNumfmtPlugin,
603
- countryCurrencyMap,
604
- currencySymbols,
605
- getCurrencyFormatOptions,
606
- getCurrencyOptions,
607
- getCurrencyType,
608
- getDateFormatOptions,
609
- getDecimalFromPattern,
610
- getDecimalString,
611
- getNumberFormatOptions,
612
- getPatternPreview,
613
- getPatternPreviewIgnoreGeneral,
614
- getPatternType,
615
- isPatternEqualWithoutDecimal,
616
- isPatternHasDecimal,
617
- setPatternDecimal
588
+ Ue as AddDecimalCommand,
589
+ Q as CURRENCYFORMAT,
590
+ Te as DATEFMTLISG,
591
+ k as MenuCurrencyService,
592
+ xe as NUMBERFORMAT,
593
+ Oe as SetCurrencyCommand,
594
+ T as SetNumfmtCommand,
595
+ De as SetPercentCommand,
596
+ U as SheetsNumfmtCellContentController,
597
+ Ve as SubtractDecimalCommand,
598
+ O as UniverSheetsNumfmtPlugin,
599
+ Ie as countryCurrencyMap,
600
+ J as currencySymbols,
601
+ tt as getCurrencyFormatOptions,
602
+ et as getCurrencyOptions,
603
+ ke as getCurrencyType,
604
+ nt as getDateFormatOptions,
605
+ x as getDecimalFromPattern,
606
+ z as getDecimalString,
607
+ rt as getNumberFormatOptions,
608
+ Ae as getPatternPreview,
609
+ we as getPatternPreviewIgnoreGeneral,
610
+ Qe as getPatternType,
611
+ Ze as isPatternEqualWithoutDecimal,
612
+ Je as isPatternHasDecimal,
613
+ P as setPatternDecimal
618
614
  };