@univerjs/sheets-numfmt 0.17.0 → 0.18.0

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/index.js CHANGED
@@ -1,640 +1 @@
1
- var ce = Object.defineProperty;
2
- var ie = (e, r, t) => r in e ? ce(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
- var K = (e, r, t) => ie(e, typeof r != "symbol" ? r + "" : r, t);
4
- import { LocaleType as i, numfmt as P, CommandType as O, ICommandService as $, IUniverInstanceService as V, IUndoRedoService as le, isTextFormat as Q, CellValueType as M, ObjectMatrix as R, sequenceExecute as ue, Range as E, isDefaultFormat as W, LocaleService as ee, DEFAULT_NUMBER_FORMAT as fe, Inject as I, ThemeService as me, IConfigService as te, Disposable as de, InterceptorEffectEnum as z, UniverInstanceType as re, DependentOn as ge, Injector as he, Plugin as pe, merge as _e, registerDependencies as Se, touchDependencies as ve } from "@univerjs/core";
5
- import { getSheetCommandTarget as k, transformCellsToRange as Ce, checkCellValueType as H, rangeMerge as Y, SetNumfmtMutation as ne, factorySetNumfmtUndoMutation as ye, RemoveNumfmtMutation as be, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as Me, SheetsSelectionsService as j, INumfmtService as Z, SheetInterceptorService as Re, INTERCEPTOR_POINT as Ne, InterceptCellContentPriority as Ee, UniverSheetsPlugin as $e } from "@univerjs/sheets";
6
- import { BehaviorSubject as Ie, merge as Te, switchMap as Ue, of as Oe, skip as we } from "rxjs";
7
- import { stripErrorMargin as xe } from "@univerjs/engine-formula";
8
- const se = [
9
- "$",
10
- "£",
11
- "¥",
12
- "¤",
13
- "֏",
14
- "؋",
15
- "৳",
16
- "฿",
17
- "៛",
18
- "₡",
19
- "₦",
20
- "₩",
21
- "₪",
22
- "₫",
23
- "€",
24
- "₭",
25
- "₮",
26
- "₱",
27
- "₲",
28
- "₴",
29
- "₸",
30
- "₹",
31
- "₺",
32
- "₼",
33
- "₽",
34
- "₾",
35
- "₿",
36
- "﷼"
37
- ], x = /* @__PURE__ */ new Map([
38
- [i.EN_US, "$"],
39
- [i.RU_RU, "₽"],
40
- [i.VI_VN, "₫"],
41
- [i.ZH_CN, "¥"],
42
- [i.ZH_TW, "NT$"],
43
- [i.FR_FR, "€"],
44
- [i.FA_IR, "﷼"],
45
- [i.KO_KR, "₩"],
46
- [i.ES_ES, "€"],
47
- [i.CA_ES, "€"],
48
- [i.SK_SK, "€"]
49
- ]);
50
- function Pe(e) {
51
- switch (e) {
52
- case i.CA_ES:
53
- case i.ES_ES:
54
- case i.FR_FR:
55
- case i.SK_SK:
56
- return {
57
- icon: "EuroIcon",
58
- symbol: x.get(e) || "€",
59
- locale: e
60
- };
61
- case i.RU_RU:
62
- return {
63
- icon: "RoubleIcon",
64
- symbol: x.get(e) || "₽",
65
- locale: e
66
- };
67
- case i.ZH_CN:
68
- return {
69
- icon: "RmbIcon",
70
- symbol: x.get(e) || "¥",
71
- locale: e
72
- };
73
- case i.EN_US:
74
- default:
75
- return {
76
- icon: "DollarIcon",
77
- symbol: "$",
78
- locale: i.EN_US
79
- };
80
- }
81
- }
82
- function q(e) {
83
- return x.get(e) || "$";
84
- }
85
- function Fe(e, r = 2) {
86
- let t = r;
87
- r > 127 && (t = 127);
88
- let n = "";
89
- return t > 0 && (n = `.${"0".repeat(t)}`), `"${q(e)}"#,##0${n}_);[Red]("${q(e)}"#,##0${n})`;
90
- }
91
- const De = [
92
- {
93
- label: "1930-08-05",
94
- suffix: "yyyy-MM-dd"
95
- },
96
- {
97
- label: "1930/08/05",
98
- suffix: "yyyy/MM/dd"
99
- },
100
- {
101
- label: "1930年08月05日",
102
- suffix: 'yyyy"年"MM"月"dd"日"'
103
- },
104
- {
105
- label: "08-05",
106
- suffix: "MM-dd"
107
- },
108
- {
109
- label: "8月5日",
110
- suffix: 'M"月"d"日"'
111
- },
112
- {
113
- label: "13:30:30",
114
- suffix: "h:mm:ss"
115
- },
116
- {
117
- label: "13:30",
118
- suffix: "h:mm"
119
- },
120
- {
121
- label: "下午01:30",
122
- suffix: "A/P hh:mm"
123
- },
124
- {
125
- label: "下午1:30",
126
- suffix: "A/P h:mm"
127
- },
128
- {
129
- label: "下午1:30:30",
130
- suffix: "A/P h:mm:ss"
131
- },
132
- {
133
- label: "08-05 下午 01:30",
134
- suffix: "MM-dd A/P hh:mm"
135
- }
136
- ], Ae = [
137
- {
138
- label: "(1,235)",
139
- suffix: "#,##0_);(#,##0)"
140
- },
141
- {
142
- label: "(1,235) ",
143
- suffix: "#,##0_);[Red](#,##0)",
144
- color: "red"
145
- },
146
- {
147
- label: "1,234.56",
148
- suffix: "#,##0.00_);#,##0.00"
149
- },
150
- {
151
- label: "1,234.56",
152
- suffix: "#,##0.00_);[Red]#,##0.00",
153
- color: "red"
154
- },
155
- {
156
- label: "-1,234.56",
157
- suffix: "#,##0.00_);-#,##0.00"
158
- },
159
- {
160
- label: "-1,234.56",
161
- suffix: "#,##0.00_);[Red]-#,##0.00",
162
- color: "red"
163
- }
164
- ], Ve = [
165
- {
166
- label: (e) => `${e}1,235`,
167
- suffix: (e) => `"${e}"#,##0.00_);"${e}"#,##0.00`
168
- },
169
- {
170
- label: (e) => `${e}1,235`,
171
- suffix: (e) => `"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,
172
- color: "red"
173
- },
174
- {
175
- label: (e) => `(${e}1,235)`,
176
- suffix: (e) => `"${e}"#,##0.00_);("${e}"#,##0.00)`
177
- },
178
- {
179
- label: (e) => `(${e}1,235)`,
180
- suffix: (e) => `"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,
181
- color: "red"
182
- },
183
- {
184
- label: (e) => `-${e}1,235`,
185
- suffix: (e) => `"${e}"#,##0.00_);-"${e}"#,##0.00`
186
- },
187
- {
188
- label: (e) => `-${e}1,235`,
189
- suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
190
- color: "red"
191
- }
192
- ], F = (e, r = 0) => {
193
- var n;
194
- return e && (n = P.getFormatInfo(e).maxDecimals) != null ? n : r;
195
- }, X = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), D = (e, r) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
196
- /\.0*/g,
197
- `${r > 0 ? "." : ""}${X(Number(r || 0))}`
198
- ) : /0([^0]?)|0$/.test(n) ? n.replace(
199
- /0([^0]+)|0$/,
200
- `0${r > 0 ? "." : ""}${X(Number(r || 0))}$1`
201
- ) : n).join(";"), at = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), w = {
202
- id: "sheet.command.numfmt.set.numfmt",
203
- type: O.COMMAND,
204
- // eslint-disable-next-line max-lines-per-function
205
- handler: (e, r) => {
206
- if (!r)
207
- return !1;
208
- const t = e.get($), n = e.get(V), s = e.get(le), a = k(n, r);
209
- if (!a) return !1;
210
- const { unitId: u, subUnitId: o, worksheet: h } = a, f = r.values.filter((c) => !!c.pattern), C = r.values.filter((c) => !c.pattern), y = Ce(u, o, f), p = {
211
- unitId: u,
212
- subUnitId: o,
213
- ranges: C.map((c) => ({
214
- startColumn: c.col,
215
- startRow: c.row,
216
- endColumn: c.col,
217
- endRow: c.row
218
- }))
219
- }, b = [], _ = [];
220
- if (f.length) {
221
- const c = f.reduce((d, l) => {
222
- Q(l.pattern) && d.setValue(l.row, l.col, { t: M.STRING });
223
- const v = h.getCellRaw(l.row, l.col);
224
- if (v) {
225
- const U = H(v.v);
226
- U !== v.t && d.setValue(l.row, l.col, { t: U });
227
- }
228
- return d;
229
- }, new R()).getMatrix(), g = new R();
230
- new R(c).forValue((d, l) => {
231
- const v = h.getCellRaw(d, l);
232
- v ? g.setValue(d, l, { t: v.t }) : g.setValue(d, l, { t: void 0 });
233
- }), Object.keys(y.values).forEach((d) => {
234
- const l = y.values[d];
235
- l.ranges = Y(l.ranges);
236
- }), b.push({
237
- id: ne.id,
238
- params: y
239
- });
240
- const S = ye(e, y);
241
- _.push(...S);
242
- }
243
- if (C.length) {
244
- p.ranges = Y(p.ranges);
245
- const c = C.reduce((d, l) => {
246
- const v = h.getCellRaw(l.row, l.col);
247
- if (v) {
248
- const U = H(v.v);
249
- U !== v.t && d.setValue(l.row, l.col, { t: U });
250
- }
251
- return d;
252
- }, new R()).getMatrix(), g = new R();
253
- new R(c).forValue((d, l) => {
254
- const v = h.getCellRaw(d, l);
255
- v ? g.setValue(d, l, { t: v.t }) : g.setValue(d, l, { t: void 0 });
256
- }), b.push({
257
- id: be.id,
258
- params: p
259
- }, {
260
- id: G.id,
261
- params: {
262
- unitId: u,
263
- subUnitId: o,
264
- cellValue: c
265
- }
266
- });
267
- const S = Me(e, p);
268
- _.push({
269
- id: G.id,
270
- params: {
271
- unitId: u,
272
- subUnitId: o,
273
- cellValue: g.getMatrix()
274
- }
275
- }, ...S);
276
- }
277
- const m = ue(b, t).result;
278
- return m && s.pushUndoRedo({
279
- unitID: u,
280
- undoMutations: _,
281
- redoMutations: b
282
- }), m;
283
- }
284
- }, je = {
285
- id: "sheet.command.numfmt.add.decimal.command",
286
- type: O.COMMAND,
287
- handler: async (e) => {
288
- const r = e.get($), t = e.get(j), n = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
289
- if (!a || !a.length)
290
- return !1;
291
- const u = k(s);
292
- if (!u) return !1;
293
- const { unitId: o, subUnitId: h } = u;
294
- let f = 0;
295
- a.forEach((b) => {
296
- E.foreach(b.range, (_, m) => {
297
- const c = n.getValue(o, h, _, m);
298
- if (!c) {
299
- const S = u.worksheet.getCellRaw(_, m);
300
- if (!f && S && S.t === M.NUMBER && S.v) {
301
- const d = /\.(\d*)$/.exec(String(S.v));
302
- if (d) {
303
- const l = d[1].length;
304
- if (!l)
305
- return;
306
- f = Math.max(f, l);
307
- }
308
- }
309
- return;
310
- }
311
- const g = F(c.pattern);
312
- f = g > f ? g : f;
313
- });
314
- });
315
- const C = f + 1, y = D(`0${C > 0 ? ".0" : ""}`, C), p = [];
316
- return a.forEach((b) => {
317
- E.foreach(b.range, (_, m) => {
318
- const c = n.getValue(o, h, _, m);
319
- if (W(c == null ? void 0 : c.pattern))
320
- p.push({
321
- row: _,
322
- col: m,
323
- pattern: y
324
- });
325
- else {
326
- const g = F(c.pattern), S = D(c.pattern, g + 1);
327
- S !== c.pattern && p.push({
328
- row: _,
329
- col: m,
330
- pattern: S
331
- });
332
- }
333
- });
334
- }), p.length ? await r.executeCommand(w.id, { values: p }) : !1;
335
- }
336
- }, Le = {
337
- id: "sheet.command.numfmt.set.currency",
338
- type: O.COMMAND,
339
- handler: async (e) => {
340
- const r = e.get($), t = e.get(j), n = e.get(ee), s = t.getCurrentSelections();
341
- if (!s || !s.length)
342
- return !1;
343
- const a = [], u = Pe(n.getCurrentLocale()), o = Fe(u.locale);
344
- return s.forEach((f) => {
345
- E.foreach(f.range, (C, y) => {
346
- a.push({ row: C, col: y, pattern: o, type: "currency" });
347
- });
348
- }), await r.executeCommand(w.id, { values: a });
349
- }
350
- }, Ke = {
351
- id: "sheet.command.numfmt.set.percent",
352
- type: O.COMMAND,
353
- handler: async (e) => {
354
- const r = e.get($), n = e.get(j).getCurrentSelections();
355
- if (!n || !n.length)
356
- return !1;
357
- const s = [], a = "0%";
358
- return n.forEach((o) => {
359
- E.foreach(o.range, (h, f) => {
360
- s.push({ row: h, col: f, pattern: a, type: "percent" });
361
- });
362
- }), await r.executeCommand(w.id, { values: s });
363
- }
364
- }, Be = {
365
- id: "sheet.command.numfmt.subtract.decimal.command",
366
- type: O.COMMAND,
367
- handler: async (e) => {
368
- const r = e.get($), t = e.get(j), n = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
369
- if (!a || !a.length)
370
- return !1;
371
- const u = k(s);
372
- if (!u) return !1;
373
- const { unitId: o, subUnitId: h } = u;
374
- let f = 0;
375
- a.forEach((_) => {
376
- E.foreach(_.range, (m, c) => {
377
- const g = n.getValue(o, h, m, c);
378
- if (!g) {
379
- const d = u.worksheet.getCellRaw(m, c);
380
- if (!f && d && d.t === M.NUMBER && d.v) {
381
- const l = /\.(\d*)$/.exec(String(d.v));
382
- if (l) {
383
- const v = l[1].length;
384
- if (!v)
385
- return;
386
- f = Math.max(f, v);
387
- }
388
- }
389
- return;
390
- }
391
- const S = F(g.pattern);
392
- f = S > f ? S : f;
393
- });
394
- });
395
- const C = f - 1, y = D(`0${C > 0 ? ".0" : "."}`, C), p = [];
396
- return a.forEach((_) => {
397
- E.foreach(_.range, (m, c) => {
398
- const g = n.getValue(o, h, m, c);
399
- if (W(g == null ? void 0 : g.pattern))
400
- p.push({
401
- row: m,
402
- col: c,
403
- pattern: y
404
- });
405
- else {
406
- const S = F(g.pattern);
407
- p.push({
408
- row: m,
409
- col: c,
410
- pattern: D(g.pattern, S - 1)
411
- });
412
- }
413
- });
414
- }), await r.executeCommand(w.id, { values: p });
415
- }
416
- }, oe = "sheets-numfmt.config", J = {}, ct = (e) => P.getFormatInfo(e).type || "unknown", He = (e, r, t = "en") => {
417
- try {
418
- const n = P.formatColor(e, r), s = n ? String(n) : void 0, a = P.format(e, r, { locale: t, throws: !1 });
419
- return r < 0 ? {
420
- result: a,
421
- color: s
422
- } : {
423
- result: a
424
- };
425
- } catch (n) {
426
- console.warn("getPatternPreview error:", e, n);
427
- }
428
- return {
429
- result: String(r)
430
- };
431
- }, Ge = (e, r, t) => e === fe ? {
432
- result: String(xe(r))
433
- // In Excel, the default General format also needs to handle numeric precision.
434
- } : He(e, r, t);
435
- var We = Object.getOwnPropertyDescriptor, ke = (e, r, t, n) => {
436
- for (var s = n > 1 ? void 0 : n ? We(r, t) : r, a = e.length - 1, u; a >= 0; a--)
437
- (u = e[a]) && (s = u(s) || s);
438
- return s;
439
- }, N = (e, r) => (t, n) => r(t, n, e);
440
- const Ze = {
441
- tl: {
442
- size: 6,
443
- color: "#409f11"
444
- }
445
- };
446
- let A = class extends de {
447
- constructor(r, t, n, s, a, u, o) {
448
- super();
449
- K(this, "_locale$", new Ie("en"));
450
- K(this, "locale$", this._locale$.asObservable());
451
- this._instanceService = r, this._sheetInterceptorService = t, this._themeService = n, this._commandService = s, this._numfmtService = a, this._localeService = u, this._configService = o, this._initInterceptorCellContent();
452
- }
453
- get locale() {
454
- const r = this._locale$.getValue();
455
- if (r)
456
- return r;
457
- switch (this._localeService.getCurrentLocale()) {
458
- case i.FR_FR:
459
- return "fr";
460
- case i.RU_RU:
461
- return "ru";
462
- case i.VI_VN:
463
- return "vi";
464
- case i.ZH_CN:
465
- return "zh-CN";
466
- case i.KO_KR:
467
- return "ko";
468
- case i.ZH_TW:
469
- return "zh-TW";
470
- case i.ES_ES:
471
- case i.CA_ES:
472
- return "es";
473
- case i.SK_SK:
474
- return "sk";
475
- case i.EN_US:
476
- case i.FA_IR:
477
- default:
478
- return "en";
479
- }
480
- }
481
- // eslint-disable-next-line max-lines-per-function
482
- _initInterceptorCellContent() {
483
- const r = new R();
484
- this.disposeWithMe(Te(this._locale$, this._localeService.currentLocale$).subscribe(() => {
485
- r.reset();
486
- })), this.disposeWithMe(this._sheetInterceptorService.intercept(Ne.CELL_CONTENT, {
487
- effect: z.Value | z.Style,
488
- // eslint-disable-next-line max-lines-per-function, complexity
489
- handler: (t, n, s) => {
490
- var b, _;
491
- if (!t || t.v === void 0 || t.v === null || t.t === M.BOOLEAN || t.t === M.FORCE_STRING)
492
- return s(t);
493
- const a = n.unitId, u = n.subUnitId;
494
- let o;
495
- if (t != null && t.s) {
496
- const m = n.workbook.getStyles().get(t.s);
497
- m != null && m.n && (o = m.n);
498
- }
499
- if (o || (o = this._numfmtService.getValue(a, u, n.row, n.col)), W(o == null ? void 0 : o.pattern) || t.t !== M.NUMBER && H(t.v, t.t) !== M.NUMBER)
500
- return s(t);
501
- const h = t;
502
- if ((!t || t === n.rawData) && (t = { ...n.rawData }), Q(o == null ? void 0 : o.pattern))
503
- return (b = this._configService.getConfig(oe)) != null && b.disableTextFormatMark ? (t.t = M.STRING, s(t)) : (t.t = M.STRING, t.markers = { ...t == null ? void 0 : t.markers, ...Ze }, s(t));
504
- let f = "";
505
- const C = r.getValue(n.row, n.col);
506
- if (C && C.parameters === `${h.v}_${o == null ? void 0 : o.pattern}`)
507
- return s({ ...t, ...C.result });
508
- const y = Ge(o == null ? void 0 : o.pattern, Number(h.v), this.locale);
509
- if (f = y.result, !f)
510
- return s(t);
511
- const p = { v: f, t: M.NUMBER };
512
- if (y.color) {
513
- const m = (_ = this._themeService.getColorFromTheme(`${y.color}.500`)) != null ? _ : y.color;
514
- m && (p.interceptorStyle = { cl: { rgb: m } });
515
- }
516
- return r.setValue(n.row, n.col, {
517
- result: p,
518
- parameters: `${h.v}_${o == null ? void 0 : o.pattern}`
519
- }), Object.assign(t, p), s(t);
520
- },
521
- priority: Ee.NUMFMT
522
- })), this.disposeWithMe(this._commandService.onCommandExecuted((t) => {
523
- if (t.id === ne.id) {
524
- const n = t.params;
525
- Object.keys(n.values).forEach((s) => {
526
- n.values[s].ranges.forEach((u) => {
527
- E.foreach(u, (o, h) => {
528
- r.realDeleteValue(o, h);
529
- });
530
- });
531
- });
532
- } else if (t.id === G.id) {
533
- const n = t.params;
534
- new R(n.cellValue).forValue((s, a) => {
535
- r.realDeleteValue(s, a);
536
- });
537
- }
538
- })), this.disposeWithMe(
539
- this._instanceService.getCurrentTypeOfUnit$(re.UNIVER_SHEET).pipe(
540
- Ue((t) => {
541
- var n;
542
- return (n = t == null ? void 0 : t.activeSheet$) != null ? n : Oe(null);
543
- }),
544
- we(1)
545
- ).subscribe(() => r.reset())
546
- );
547
- }
548
- setNumfmtLocal(r) {
549
- this._locale$.next(r);
550
- }
551
- };
552
- A = ke([
553
- N(0, V),
554
- N(1, I(Re)),
555
- N(2, I(me)),
556
- N(3, I($)),
557
- N(4, I(Z)),
558
- N(5, I(ee)),
559
- N(6, te)
560
- ], A);
561
- const ze = "@univerjs/sheets-numfmt", Ye = "0.17.0", ae = {
562
- name: ze,
563
- version: Ye
564
- }, qe = "SHEET_NUMFMT_PLUGIN";
565
- var Xe = Object.defineProperty, Je = Object.getOwnPropertyDescriptor, Qe = (e, r, t) => r in e ? Xe(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, et = (e, r, t, n) => {
566
- for (var s = n > 1 ? void 0 : n ? Je(r, t) : r, a = e.length - 1, u; a >= 0; a--)
567
- (u = e[a]) && (s = u(s) || s);
568
- return s;
569
- }, B = (e, r) => (t, n) => r(t, n, e), L = (e, r, t) => Qe(e, typeof r != "symbol" ? r + "" : r, t);
570
- let T = class extends pe {
571
- constructor(e = J, r, t, n) {
572
- super(), this._config = e, this._injector = r, this._configService = t, this._commandService = n;
573
- const { ...s } = _e(
574
- {},
575
- J,
576
- this._config
577
- );
578
- this._configService.setConfig(oe, s);
579
- }
580
- onStarting() {
581
- Se(this._injector, [
582
- [A]
583
- ]), ve(this._injector, [
584
- [A]
585
- ]), [
586
- je,
587
- Be,
588
- Le,
589
- Ke,
590
- w
591
- ].forEach((e) => {
592
- this.disposeWithMe(this._commandService.registerCommand(e));
593
- });
594
- }
595
- };
596
- L(T, "pluginName", qe);
597
- L(T, "packageName", ae.name);
598
- L(T, "version", ae.version);
599
- L(T, "type", re.UNIVER_SHEET);
600
- T = et([
601
- ge($e),
602
- B(1, I(he)),
603
- B(2, te),
604
- B(3, $)
605
- ], T);
606
- const it = (e) => se.find((t) => e.includes(t)), lt = () => se.map((e) => ({ label: e, value: e })), ut = (e) => Ve.map((r) => ({
607
- label: r.label(e),
608
- value: r.suffix(e),
609
- color: r.color
610
- })), ft = () => De.map((e) => ({ label: e.label, value: e.suffix })), mt = () => Ae.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
611
- export {
612
- je as AddDecimalCommand,
613
- Ve as CURRENCYFORMAT,
614
- De as DATEFMTLISG,
615
- Ae as NUMBERFORMAT,
616
- oe as SHEETS_NUMFMT_PLUGIN_CONFIG_KEY,
617
- Le as SetCurrencyCommand,
618
- w as SetNumfmtCommand,
619
- Ke as SetPercentCommand,
620
- A as SheetsNumfmtCellContentController,
621
- Be as SubtractDecimalCommand,
622
- T as UniverSheetsNumfmtPlugin,
623
- se as currencySymbols,
624
- Fe as getCurrencyFormat,
625
- ut as getCurrencyFormatOptions,
626
- lt as getCurrencyOptions,
627
- q as getCurrencySymbolByLocale,
628
- Pe as getCurrencySymbolIconByLocale,
629
- it as getCurrencyType,
630
- ft as getDateFormatOptions,
631
- F as getDecimalFromPattern,
632
- X as getDecimalString,
633
- mt as getNumberFormatOptions,
634
- He as getPatternPreview,
635
- Ge as getPatternPreviewIgnoreGeneral,
636
- ct as getPatternType,
637
- at as isPatternHasDecimal,
638
- x as localeCurrencySymbolMap,
639
- D as setPatternDecimal
640
- };
1
+ import{CellValueType as e,CommandType as t,DEFAULT_NUMBER_FORMAT as n,DependentOn as r,Disposable as i,ICommandService as a,IConfigService as o,IUndoRedoService as s,IUniverInstanceService as c,Inject as l,Injector as u,InterceptorEffectEnum as d,LocaleService as f,LocaleType as p,ObjectMatrix as m,Plugin as h,Range as g,ThemeService as _,UniverInstanceType as v,isDefaultFormat as y,isTextFormat as b,merge as x,numfmt as S,registerDependencies as ee,sequenceExecute as te,touchDependencies as ne}from"@univerjs/core";import{INTERCEPTOR_POINT as re,INumfmtService as C,InterceptCellContentPriority as ie,RemoveNumfmtMutation as ae,SetNumfmtMutation as oe,SetRangeValuesMutation as w,SheetInterceptorService as se,SheetsSelectionsService as T,UniverSheetsPlugin as ce,checkCellValueType as E,factoryRemoveNumfmtUndoMutation as le,factorySetNumfmtUndoMutation as ue,getSheetCommandTarget as D,rangeMerge as O,transformCellsToRange as de}from"@univerjs/sheets";import{BehaviorSubject as fe,merge as pe,of as me,skip as he,switchMap as ge}from"rxjs";import{stripErrorMargin as _e}from"@univerjs/engine-formula";const k=`$.£.¥.¤.֏.؋.৳.฿.៛.₡.₦.₩.₪.₫.€.₭.₮.₱.₲.₴.₸.₹.₺.₼.₽.₾.₿.﷼`.split(`.`),A=new Map([[p.EN_US,`$`],[p.RU_RU,`₽`],[p.VI_VN,`₫`],[p.ZH_CN,`¥`],[p.ZH_TW,`NT$`],[p.FR_FR,`€`],[p.FA_IR,`﷼`],[p.KO_KR,`₩`],[p.ES_ES,`€`],[p.CA_ES,`€`],[p.SK_SK,`€`]]);function j(e){switch(e){case p.CA_ES:case p.ES_ES:case p.FR_FR:case p.SK_SK:return{icon:`EuroIcon`,symbol:A.get(e)||`€`,locale:e};case p.RU_RU:return{icon:`RoubleIcon`,symbol:A.get(e)||`₽`,locale:e};case p.ZH_CN:return{icon:`RmbIcon`,symbol:A.get(e)||`¥`,locale:e};case p.EN_US:default:return{icon:`DollarIcon`,symbol:`$`,locale:p.EN_US}}}function M(e){return A.get(e)||`$`}function N(e,t=2){let n=t;t>127&&(n=127);let r=``;return n>0&&(r=`.${`0`.repeat(n)}`),`"${M(e)}"#,##0${r}_);[Red]("${M(e)}"#,##0${r})`}const P=[{label:`1930-08-05`,suffix:`yyyy-MM-dd`},{label:`1930/08/05`,suffix:`yyyy/MM/dd`},{label:`1930年08月05日`,suffix:`yyyy"年"MM"月"dd"日"`},{label:`08-05`,suffix:`MM-dd`},{label:`8月5日`,suffix:`M"月"d"日"`},{label:`13:30:30`,suffix:`h:mm:ss`},{label:`13:30`,suffix:`h:mm`},{label:`下午01:30`,suffix:`A/P hh:mm`},{label:`下午1:30`,suffix:`A/P h:mm`},{label:`下午1:30:30`,suffix:`A/P h:mm:ss`},{label:`08-05 下午 01:30`,suffix:`MM-dd A/P hh:mm`}],F=[{label:`(1,235)`,suffix:`#,##0_);(#,##0)`},{label:`(1,235) `,suffix:`#,##0_);[Red](#,##0)`,color:`red`},{label:`1,234.56`,suffix:`#,##0.00_);#,##0.00`},{label:`1,234.56`,suffix:`#,##0.00_);[Red]#,##0.00`,color:`red`},{label:`-1,234.56`,suffix:`#,##0.00_);-#,##0.00`},{label:`-1,234.56`,suffix:`#,##0.00_);[Red]-#,##0.00`,color:`red`}],I=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:`red`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:`red`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:`red`}],L=(e,t=0)=>{var n;return e?(n=S.getFormatInfo(e).maxDecimals)==null?t:n:t},R=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),z=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${R(Number(t||0))}`):/0([^0]?)|0$/.test(e)?e.replace(/0([^0]+)|0$/,`0${t>0?`.`:``}${R(Number(t||0))}$1`):e).join(`;`),ve=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),B={id:`sheet.command.numfmt.set.numfmt`,type:t.COMMAND,handler:(t,n)=>{if(!n)return!1;let r=t.get(a),i=t.get(c),o=t.get(s),l=D(i,n);if(!l)return!1;let{unitId:u,subUnitId:d,worksheet:f}=l,p=n.values.filter(e=>!!e.pattern),h=n.values.filter(e=>!e.pattern),g=de(u,d,p),_={unitId:u,subUnitId:d,ranges:h.map(e=>({startColumn:e.col,startRow:e.row,endColumn:e.col,endRow:e.row}))},v=[],y=[];if(p.length){let n=p.reduce((t,n)=>{b(n.pattern)&&t.setValue(n.row,n.col,{t:e.STRING});let r=f.getCellRaw(n.row,n.col);if(r){let e=E(r.v);e!==r.t&&t.setValue(n.row,n.col,{t:e})}return t},new m).getMatrix(),r=new m;new m(n).forValue((e,t)=>{let n=f.getCellRaw(e,t);n?r.setValue(e,t,{t:n.t}):r.setValue(e,t,{t:void 0})}),Object.keys(g.values).forEach(e=>{let t=g.values[e];t.ranges=O(t.ranges)}),v.push({id:oe.id,params:g});let i=ue(t,g);y.push(...i)}if(h.length){_.ranges=O(_.ranges);let e=h.reduce((e,t)=>{let n=f.getCellRaw(t.row,t.col);if(n){let r=E(n.v);r!==n.t&&e.setValue(t.row,t.col,{t:r})}return e},new m).getMatrix(),n=new m;new m(e).forValue((e,t)=>{let r=f.getCellRaw(e,t);r?n.setValue(e,t,{t:r.t}):n.setValue(e,t,{t:void 0})}),v.push({id:ae.id,params:_},{id:w.id,params:{unitId:u,subUnitId:d,cellValue:e}});let r=le(t,_);y.push({id:w.id,params:{unitId:u,subUnitId:d,cellValue:n.getMatrix()}},...r)}let x=te(v,r).result;return x&&o.pushUndoRedo({unitID:u,undoMutations:y,redoMutations:v}),x}},V={id:`sheet.command.numfmt.add.decimal.command`,type:t.COMMAND,handler:async t=>{let n=t.get(a),r=t.get(T),i=t.get(C),o=t.get(c),s=r.getCurrentSelections();if(!s||!s.length)return!1;let l=D(o);if(!l)return!1;let{unitId:u,subUnitId:d}=l,f=0;s.forEach(t=>{g.foreach(t.range,(t,n)=>{let r=i.getValue(u,d,t,n);if(!r){let r=l.worksheet.getCellRaw(t,n);if(!f&&r&&r.t===e.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;f=Math.max(f,t)}}return}let a=L(r.pattern);f=a>f?a:f})});let p=f+1,m=z(`0${p>0?`.0`:``}`,p),h=[];return s.forEach(e=>{g.foreach(e.range,(e,t)=>{let n=i.getValue(u,d,e,t);if(y(n==null?void 0:n.pattern))h.push({row:e,col:t,pattern:m});else{let r=L(n.pattern),i=z(n.pattern,r+1);i!==n.pattern&&h.push({row:e,col:t,pattern:i})}})}),h.length?await n.executeCommand(B.id,{values:h}):!1}},H={id:`sheet.command.numfmt.set.currency`,type:t.COMMAND,handler:async e=>{let t=e.get(a),n=e.get(T),r=e.get(f),i=n.getCurrentSelections();if(!i||!i.length)return!1;let o=[],s=N(j(r.getCurrentLocale()).locale);return i.forEach(e=>{g.foreach(e.range,(e,t)=>{o.push({row:e,col:t,pattern:s,type:`currency`})})}),await t.executeCommand(B.id,{values:o})}},U={id:`sheet.command.numfmt.set.percent`,type:t.COMMAND,handler:async e=>{let t=e.get(a),n=e.get(T).getCurrentSelections();if(!n||!n.length)return!1;let r=[];return n.forEach(e=>{g.foreach(e.range,(e,t)=>{r.push({row:e,col:t,pattern:`0%`,type:`percent`})})}),await t.executeCommand(B.id,{values:r})}},W={id:`sheet.command.numfmt.subtract.decimal.command`,type:t.COMMAND,handler:async t=>{let n=t.get(a),r=t.get(T),i=t.get(C),o=t.get(c),s=r.getCurrentSelections();if(!s||!s.length)return!1;let l=D(o);if(!l)return!1;let{unitId:u,subUnitId:d}=l,f=0;s.forEach(t=>{g.foreach(t.range,(t,n)=>{let r=i.getValue(u,d,t,n);if(!r){let r=l.worksheet.getCellRaw(t,n);if(!f&&r&&r.t===e.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;f=Math.max(f,t)}}return}let a=L(r.pattern);f=a>f?a:f})});let p=f-1,m=z(`0${p>0?`.0`:`.`}`,p),h=[];return s.forEach(e=>{g.foreach(e.range,(e,t)=>{let n=i.getValue(u,d,e,t);if(y(n==null?void 0:n.pattern))h.push({row:e,col:t,pattern:m});else{let r=L(n.pattern);h.push({row:e,col:t,pattern:z(n.pattern,r-1)})}})}),await n.executeCommand(B.id,{values:h})}},G=`sheets-numfmt.config`;Symbol(G);const K={},ye=e=>S.getFormatInfo(e).type||`unknown`,q=(e,t,n=`en`)=>{try{let r=S.formatColor(e,t),i=r?String(r):void 0,a=S.format(e,t,{locale:n,throws:!1});return t<0?{result:a,color:i}:{result:a}}catch(t){console.warn(`getPatternPreview error:`,e,t)}return{result:String(t)}},J=(e,t,r)=>e===n?{result:String(_e(t))}:q(e,t,r);function Y(e){"@babel/helpers - typeof";return Y=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Y(e)}function be(e,t){if(Y(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Y(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function xe(e){var t=be(e,`string`);return Y(t)==`symbol`?t:t+``}function X(e,t,n){return(t=xe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Z(e,t){return function(n,r){t(n,r,e)}}function Se(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const Ce={tl:{size:6,color:`#409f11`}};let Q=class extends i{constructor(e,t,n,r,i,a,o){super(),this._instanceService=e,this._sheetInterceptorService=t,this._themeService=n,this._commandService=r,this._numfmtService=i,this._localeService=a,this._configService=o,X(this,`_locale$`,new fe(`en`)),X(this,`locale$`,this._locale$.asObservable()),this._initInterceptorCellContent()}get locale(){let e=this._locale$.getValue();if(e)return e;switch(this._localeService.getCurrentLocale()){case p.FR_FR:return`fr`;case p.RU_RU:return`ru`;case p.VI_VN:return`vi`;case p.ZH_CN:return`zh-CN`;case p.KO_KR:return`ko`;case p.ZH_TW:return`zh-TW`;case p.ES_ES:case p.CA_ES:return`es`;case p.SK_SK:return`sk`;case p.EN_US:case p.FA_IR:default:return`en`}}_initInterceptorCellContent(){let t=new m;this.disposeWithMe(pe(this._locale$,this._localeService.currentLocale$).subscribe(()=>{t.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(re.CELL_CONTENT,{effect:d.Value|d.Style,handler:(n,r,i)=>{if(!n||n.v===void 0||n.v===null||n.t===e.BOOLEAN||n.t===e.FORCE_STRING)return i(n);let a=r.unitId,o=r.subUnitId,s;if(n!=null&&n.s){let e=r.workbook.getStyles().get(n.s);e!=null&&e.n&&(s=e.n)}if(s||(s=this._numfmtService.getValue(a,o,r.row,r.col)),y(s==null?void 0:s.pattern)||n.t!==e.NUMBER&&E(n.v,n.t)!==e.NUMBER)return i(n);let c=n;if((!n||n===r.rawData)&&(n={...r.rawData}),b(s==null?void 0:s.pattern)){var l;return(l=this._configService.getConfig(`sheets-numfmt.config`))!=null&&l.disableTextFormatMark?(n.t=e.STRING,i(n)):(n.t=e.STRING,n.markers={...n==null?void 0:n.markers,...Ce},i(n))}let u=``,d=t.getValue(r.row,r.col);if(d&&d.parameters===`${c.v}_${s==null?void 0:s.pattern}`)return i({...n,...d.result});let f=J(s==null?void 0:s.pattern,Number(c.v),this.locale);if(u=f.result,!u)return i(n);let p={v:u,t:e.NUMBER};if(f.color){var m;let e=(m=this._themeService.getColorFromTheme(`${f.color}.500`))==null?f.color:m;e&&(p.interceptorStyle={cl:{rgb:e}})}return t.setValue(r.row,r.col,{result:p,parameters:`${c.v}_${s==null?void 0:s.pattern}`}),Object.assign(n,p),i(n)},priority:ie.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===oe.id){let n=e.params;Object.keys(n.values).forEach(e=>{n.values[e].ranges.forEach(e=>{g.foreach(e,(e,n)=>{t.realDeleteValue(e,n)})})})}else if(e.id===w.id){let n=e.params;new m(n.cellValue).forValue((e,n)=>{t.realDeleteValue(e,n)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(v.UNIVER_SHEET).pipe(ge(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?me(null):t}),he(1)).subscribe(()=>t.reset()))}setNumfmtLocal(e){this._locale$.next(e)}};Q=Se([Z(0,c),Z(1,l(se)),Z(2,l(_)),Z(3,l(a)),Z(4,l(C)),Z(5,l(f)),Z(6,o)],Q);var we=`@univerjs/sheets-numfmt`,Te=`0.18.0`;let $=class extends h{constructor(e=K,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._commandService=r;let{...i}=x({},K,this._config);this._configService.setConfig(G,i)}onStarting(){ee(this._injector,[[Q]]),ne(this._injector,[[Q]]),[V,W,H,U,B].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};X($,`pluginName`,`SHEET_NUMFMT_PLUGIN`),X($,`packageName`,we),X($,`version`,Te),X($,`type`,v.UNIVER_SHEET),$=Se([r(ce),Z(1,l(u)),Z(2,o),Z(3,a)],$);const Ee=e=>k.find(t=>e.includes(t)),De=()=>k.map(e=>({label:e,value:e})),Oe=e=>I.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),ke=()=>P.map(e=>({label:e.label,value:e.suffix})),Ae=()=>F.map(e=>({label:e.label,value:e.suffix,color:e.color}));export{V as AddDecimalCommand,I as CURRENCYFORMAT,P as DATEFMTLISG,F as NUMBERFORMAT,G as SHEETS_NUMFMT_PLUGIN_CONFIG_KEY,H as SetCurrencyCommand,B as SetNumfmtCommand,U as SetPercentCommand,Q as SheetsNumfmtCellContentController,W as SubtractDecimalCommand,$ as UniverSheetsNumfmtPlugin,k as currencySymbols,N as getCurrencyFormat,Oe as getCurrencyFormatOptions,De as getCurrencyOptions,M as getCurrencySymbolByLocale,j as getCurrencySymbolIconByLocale,Ee as getCurrencyType,ke as getDateFormatOptions,L as getDecimalFromPattern,R as getDecimalString,Ae as getNumberFormatOptions,q as getPatternPreview,J as getPatternPreviewIgnoreGeneral,ye as getPatternType,ve as isPatternHasDecimal,A as localeCurrencySymbolMap,z as setPatternDecimal};
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
  import { LocaleType } from '@univerjs/core';
2
17
  export declare const currencySymbols: string[];
3
18
  export declare const localeCurrencySymbolMap: Map<LocaleType, string>;
@@ -1,2 +1,17 @@
1
- import { ICommand } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ICommand } from '@univerjs/core';
2
17
  export declare const AddDecimalCommand: ICommand;