@univerjs/sheets-numfmt 0.8.0-beta.0 → 0.8.0-nightly.202505271607
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/cjs/index.js +1 -1
- package/lib/es/index.js +112 -124
- package/lib/index.js +112 -124
- package/lib/umd/index.js +1 -1
- package/package.json +5 -5
- package/LICENSE +0 -176
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var le = (e, t, n) => t in e ?
|
|
1
|
+
var ce = Object.defineProperty;
|
|
2
|
+
var le = (e, t, n) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
3
|
var M = (e, t, n) => le(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
-
import { numfmt as x, CommandType as
|
|
4
|
+
import { numfmt as x, CommandType as w, ICommandService as E, IUniverInstanceService as F, IUndoRedoService as ue, CellValueType as I, ObjectMatrix as b, sequenceExecute as me, Range as N, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as K, UniverInstanceType as ee, DependentOn as ge, Injector as he, Plugin as pe, merge as ve, registerDependencies as Se, touchDependencies as z } from "@univerjs/core";
|
|
5
5
|
import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as Y, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ie } from "@univerjs/sheets";
|
|
6
6
|
import { isTextFormat as ne } from "@univerjs/engine-numfmt";
|
|
7
7
|
import { BehaviorSubject as k, merge as Ne, switchMap as Ee, of as Te, skip as xe } from "rxjs";
|
|
@@ -34,7 +34,7 @@ const re = [
|
|
|
34
34
|
"₽",
|
|
35
35
|
"₾",
|
|
36
36
|
"₿"
|
|
37
|
-
],
|
|
37
|
+
], we = {
|
|
38
38
|
US: "$",
|
|
39
39
|
// United States Dollar
|
|
40
40
|
CA: "C$",
|
|
@@ -74,7 +74,7 @@ const re = [
|
|
|
74
74
|
SI: "€",
|
|
75
75
|
ES: "€"
|
|
76
76
|
// Add more mappings as needed
|
|
77
|
-
},
|
|
77
|
+
}, Pe = [
|
|
78
78
|
{
|
|
79
79
|
label: "1930-08-05",
|
|
80
80
|
suffix: "yyyy-MM-dd"
|
|
@@ -119,7 +119,7 @@ const re = [
|
|
|
119
119
|
label: "08-05 下午 01:30",
|
|
120
120
|
suffix: "MM-dd A/P hh:mm"
|
|
121
121
|
}
|
|
122
|
-
],
|
|
122
|
+
], Ue = [
|
|
123
123
|
{
|
|
124
124
|
label: "(1,235)",
|
|
125
125
|
suffix: "#,##0_);(#,##0)"
|
|
@@ -175,39 +175,39 @@ const re = [
|
|
|
175
175
|
suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
|
|
176
176
|
color: "red"
|
|
177
177
|
}
|
|
178
|
-
], Oe = "SHEET_NUMFMT_PLUGIN",
|
|
178
|
+
], Oe = "SHEET_NUMFMT_PLUGIN", U = (e, t = 0) => {
|
|
179
179
|
var r;
|
|
180
180
|
return e && (r = x.getInfo(e).maxDecimals) != null ? r : t;
|
|
181
181
|
}, tt = (e, t) => {
|
|
182
182
|
if (e && !t || !e && t)
|
|
183
183
|
return !1;
|
|
184
184
|
const n = (u) => u.reduce(
|
|
185
|
-
(g,
|
|
185
|
+
(g, p) => {
|
|
186
186
|
if (g.isEnd)
|
|
187
187
|
return g;
|
|
188
|
-
const h =
|
|
189
|
-
return
|
|
188
|
+
const h = p.value || p.num;
|
|
189
|
+
return p.type === "point" ? (g.isEnd = !0, g) : { ...g, result: g.result + h };
|
|
190
190
|
},
|
|
191
191
|
{ isEnd: !1, result: "" }
|
|
192
|
-
).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens),
|
|
193
|
-
return o ===
|
|
192
|
+
).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens), a = n(s[0].tokens), i = n(r[1].tokens), m = n(s[1].tokens);
|
|
193
|
+
return o === a && i === m && r[1].color === s[1].color;
|
|
194
194
|
}, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), O = (e, t) => e.split(";").map((r) => /\.0?/.test(r) ? r.replace(
|
|
195
195
|
/\.0*/g,
|
|
196
196
|
`${t > 0 ? "." : ""}${q(Number(t || 0))}`
|
|
197
197
|
) : /0([^0]?)|0$/.test(r) ? r.replace(
|
|
198
198
|
/0([^0]+)|0$/,
|
|
199
199
|
`0${t > 0 ? "." : ""}${q(Number(t || 0))}$1`
|
|
200
|
-
) : r).join(";"), nt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e),
|
|
200
|
+
) : r).join(";"), nt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), P = {
|
|
201
201
|
id: "sheet.command.numfmt.set.numfmt",
|
|
202
|
-
type:
|
|
202
|
+
type: w.COMMAND,
|
|
203
203
|
// eslint-disable-next-line max-lines-per-function
|
|
204
204
|
handler: (e, t) => {
|
|
205
205
|
if (!t)
|
|
206
206
|
return !1;
|
|
207
207
|
const n = e.get(E), r = e.get(F), s = e.get(ue), o = H(r, t);
|
|
208
208
|
if (!o) return !1;
|
|
209
|
-
const { unitId:
|
|
210
|
-
unitId:
|
|
209
|
+
const { unitId: a, subUnitId: i, worksheet: m } = o, u = t.values.filter((l) => !!l.pattern), g = t.values.filter((l) => !l.pattern), p = ye(a, i, u), h = {
|
|
210
|
+
unitId: a,
|
|
211
211
|
subUnitId: i,
|
|
212
212
|
ranges: g.map((l) => ({
|
|
213
213
|
startColumn: l.col,
|
|
@@ -217,48 +217,48 @@ const re = [
|
|
|
217
217
|
}))
|
|
218
218
|
}, C = [], S = [];
|
|
219
219
|
if (u.length) {
|
|
220
|
-
const l = u.reduce((d,
|
|
221
|
-
ne(
|
|
222
|
-
const _ = m.getCellRaw(
|
|
220
|
+
const l = u.reduce((d, c) => {
|
|
221
|
+
ne(c.pattern) && d.setValue(c.row, c.col, { t: I.STRING });
|
|
222
|
+
const _ = m.getCellRaw(c.row, c.col);
|
|
223
223
|
if (_) {
|
|
224
224
|
const V = G(_.v);
|
|
225
|
-
V !== _.t && d.setValue(
|
|
225
|
+
V !== _.t && d.setValue(c.row, c.col, { t: V });
|
|
226
226
|
}
|
|
227
227
|
return d;
|
|
228
|
-
}, new b()).getMatrix(),
|
|
229
|
-
new b(l).forValue((d,
|
|
230
|
-
const _ = m.getCellRaw(d,
|
|
231
|
-
_ ?
|
|
232
|
-
}), Object.keys(
|
|
233
|
-
const
|
|
234
|
-
|
|
228
|
+
}, new b()).getMatrix(), v = new b();
|
|
229
|
+
new b(l).forValue((d, c) => {
|
|
230
|
+
const _ = m.getCellRaw(d, c);
|
|
231
|
+
_ ? v.setValue(d, c, { t: _.t }) : v.setValue(d, c, { t: void 0 });
|
|
232
|
+
}), Object.keys(p.values).forEach((d) => {
|
|
233
|
+
const c = p.values[d];
|
|
234
|
+
c.ranges = Y(c.ranges);
|
|
235
235
|
}), C.push({
|
|
236
236
|
id: te.id,
|
|
237
|
-
params:
|
|
237
|
+
params: p
|
|
238
238
|
});
|
|
239
|
-
const y = _e(e,
|
|
239
|
+
const y = _e(e, p);
|
|
240
240
|
S.push(...y);
|
|
241
241
|
}
|
|
242
242
|
if (g.length) {
|
|
243
243
|
h.ranges = Y(h.ranges);
|
|
244
|
-
const l = g.reduce((d,
|
|
245
|
-
const _ = m.getCellRaw(
|
|
244
|
+
const l = g.reduce((d, c) => {
|
|
245
|
+
const _ = m.getCellRaw(c.row, c.col);
|
|
246
246
|
if (_) {
|
|
247
247
|
const V = G(_.v);
|
|
248
|
-
V !== _.t && d.setValue(
|
|
248
|
+
V !== _.t && d.setValue(c.row, c.col, { t: V });
|
|
249
249
|
}
|
|
250
250
|
return d;
|
|
251
|
-
}, new b()).getMatrix(),
|
|
252
|
-
new b(l).forValue((d,
|
|
253
|
-
const _ = m.getCellRaw(d,
|
|
254
|
-
_ ?
|
|
251
|
+
}, new b()).getMatrix(), v = new b();
|
|
252
|
+
new b(l).forValue((d, c) => {
|
|
253
|
+
const _ = m.getCellRaw(d, c);
|
|
254
|
+
_ ? v.setValue(d, c, { t: _.t }) : v.setValue(d, c, { t: void 0 });
|
|
255
255
|
}), C.push({
|
|
256
256
|
id: Ce.id,
|
|
257
257
|
params: h
|
|
258
258
|
}, {
|
|
259
259
|
id: B.id,
|
|
260
260
|
params: {
|
|
261
|
-
unitId:
|
|
261
|
+
unitId: a,
|
|
262
262
|
subUnitId: i,
|
|
263
263
|
cellValue: l
|
|
264
264
|
}
|
|
@@ -267,51 +267,51 @@ const re = [
|
|
|
267
267
|
S.push({
|
|
268
268
|
id: B.id,
|
|
269
269
|
params: {
|
|
270
|
-
unitId:
|
|
270
|
+
unitId: a,
|
|
271
271
|
subUnitId: i,
|
|
272
|
-
cellValue:
|
|
272
|
+
cellValue: v.getMatrix()
|
|
273
273
|
}
|
|
274
274
|
}, ...y);
|
|
275
275
|
}
|
|
276
276
|
const f = me(C, n).result;
|
|
277
277
|
return f && s.pushUndoRedo({
|
|
278
|
-
unitID:
|
|
278
|
+
unitID: a,
|
|
279
279
|
undoMutations: S,
|
|
280
280
|
redoMutations: C
|
|
281
281
|
}), f;
|
|
282
282
|
}
|
|
283
283
|
}, De = {
|
|
284
284
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
285
|
-
type:
|
|
285
|
+
type: w.COMMAND,
|
|
286
286
|
handler: async (e) => {
|
|
287
287
|
const t = e.get(E), n = e.get(j), r = e.get(W), s = e.get(F), o = n.getCurrentSelections();
|
|
288
288
|
if (!o || !o.length)
|
|
289
289
|
return !1;
|
|
290
|
-
const
|
|
291
|
-
if (!
|
|
292
|
-
const { unitId: i, subUnitId: m } =
|
|
290
|
+
const a = H(s);
|
|
291
|
+
if (!a) return !1;
|
|
292
|
+
const { unitId: i, subUnitId: m } = a;
|
|
293
293
|
let u = 0;
|
|
294
294
|
o.forEach((C) => {
|
|
295
295
|
N.foreach(C.range, (S, f) => {
|
|
296
296
|
const l = r.getValue(i, m, S, f);
|
|
297
297
|
if (!l) {
|
|
298
|
-
const y =
|
|
298
|
+
const y = a.worksheet.getCellRaw(S, f);
|
|
299
299
|
if (!u && y && y.t === I.NUMBER && y.v) {
|
|
300
300
|
const d = /\.(\d*)$/.exec(String(y.v));
|
|
301
301
|
if (d) {
|
|
302
|
-
const
|
|
303
|
-
if (!
|
|
302
|
+
const c = d[1].length;
|
|
303
|
+
if (!c)
|
|
304
304
|
return;
|
|
305
|
-
u = Math.max(u,
|
|
305
|
+
u = Math.max(u, c);
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
return;
|
|
309
309
|
}
|
|
310
|
-
const
|
|
311
|
-
u =
|
|
310
|
+
const v = U(l.pattern);
|
|
311
|
+
u = v > u ? v : u;
|
|
312
312
|
});
|
|
313
313
|
});
|
|
314
|
-
const g = u + 1,
|
|
314
|
+
const g = u + 1, p = O(`0${g > 0 ? ".0" : ""}`, g), h = [];
|
|
315
315
|
return o.forEach((C) => {
|
|
316
316
|
N.foreach(C.range, (S, f) => {
|
|
317
317
|
const l = r.getValue(i, m, S, f);
|
|
@@ -319,10 +319,10 @@ const re = [
|
|
|
319
319
|
h.push({
|
|
320
320
|
row: S,
|
|
321
321
|
col: f,
|
|
322
|
-
pattern:
|
|
322
|
+
pattern: p
|
|
323
323
|
});
|
|
324
324
|
else {
|
|
325
|
-
const
|
|
325
|
+
const v = U(l.pattern), y = O(l.pattern, v + 1);
|
|
326
326
|
y !== l.pattern && h.push({
|
|
327
327
|
row: S,
|
|
328
328
|
col: f,
|
|
@@ -330,7 +330,7 @@ const re = [
|
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
});
|
|
333
|
-
}), h.length ? await t.executeCommand(
|
|
333
|
+
}), h.length ? await t.executeCommand(P.id, { values: h }) : !1;
|
|
334
334
|
}
|
|
335
335
|
};
|
|
336
336
|
class oe {
|
|
@@ -350,21 +350,21 @@ class oe {
|
|
|
350
350
|
}
|
|
351
351
|
const Ae = {
|
|
352
352
|
id: "sheet.command.numfmt.set.currency",
|
|
353
|
-
type:
|
|
353
|
+
type: w.COMMAND,
|
|
354
354
|
handler: async (e) => {
|
|
355
|
-
const t = e.get(E), n = e.get(j), r = e.get(oe), s =
|
|
355
|
+
const t = e.get(E), n = e.get(j), r = e.get(oe), s = we[r.getCurrencySymbol()] || "$", o = n.getCurrentSelections();
|
|
356
356
|
if (!o || !o.length)
|
|
357
357
|
return !1;
|
|
358
|
-
const
|
|
358
|
+
const a = [], i = se[4].suffix(s);
|
|
359
359
|
return o.forEach((u) => {
|
|
360
|
-
N.foreach(u.range, (g,
|
|
361
|
-
|
|
360
|
+
N.foreach(u.range, (g, p) => {
|
|
361
|
+
a.push({ row: g, col: p, pattern: i, type: "currency" });
|
|
362
362
|
});
|
|
363
|
-
}), await t.executeCommand(
|
|
363
|
+
}), await t.executeCommand(P.id, { values: a });
|
|
364
364
|
}
|
|
365
365
|
}, Fe = {
|
|
366
366
|
id: "sheet.command.numfmt.set.percent",
|
|
367
|
-
type:
|
|
367
|
+
type: w.COMMAND,
|
|
368
368
|
handler: async (e) => {
|
|
369
369
|
const t = e.get(E), r = e.get(j).getCurrentSelections();
|
|
370
370
|
if (!r || !r.length)
|
|
@@ -374,28 +374,28 @@ const Ae = {
|
|
|
374
374
|
N.foreach(i.range, (m, u) => {
|
|
375
375
|
s.push({ row: m, col: u, pattern: o, type: "percent" });
|
|
376
376
|
});
|
|
377
|
-
}), await t.executeCommand(
|
|
377
|
+
}), await t.executeCommand(P.id, { values: s });
|
|
378
378
|
}
|
|
379
379
|
}, je = {
|
|
380
380
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
381
|
-
type:
|
|
381
|
+
type: w.COMMAND,
|
|
382
382
|
handler: async (e) => {
|
|
383
383
|
const t = e.get(E), n = e.get(j), r = e.get(W), s = e.get(F), o = n.getCurrentSelections();
|
|
384
384
|
if (!o || !o.length)
|
|
385
385
|
return !1;
|
|
386
|
-
const
|
|
387
|
-
if (!
|
|
388
|
-
const { unitId: i, subUnitId: m } =
|
|
386
|
+
const a = H(s);
|
|
387
|
+
if (!a) return !1;
|
|
388
|
+
const { unitId: i, subUnitId: m } = a;
|
|
389
389
|
let u = 0;
|
|
390
390
|
o.forEach((S) => {
|
|
391
391
|
N.foreach(S.range, (f, l) => {
|
|
392
|
-
const
|
|
393
|
-
if (!
|
|
394
|
-
const d =
|
|
392
|
+
const v = r.getValue(i, m, f, l);
|
|
393
|
+
if (!v) {
|
|
394
|
+
const d = a.worksheet.getCellRaw(f, l);
|
|
395
395
|
if (!u && d && d.t === I.NUMBER && d.v) {
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
398
|
-
const _ =
|
|
396
|
+
const c = /\.(\d*)$/.exec(String(d.v));
|
|
397
|
+
if (c) {
|
|
398
|
+
const _ = c[1].length;
|
|
399
399
|
if (!_)
|
|
400
400
|
return;
|
|
401
401
|
u = Math.max(u, _);
|
|
@@ -403,32 +403,32 @@ const Ae = {
|
|
|
403
403
|
}
|
|
404
404
|
return;
|
|
405
405
|
}
|
|
406
|
-
const y =
|
|
406
|
+
const y = U(v.pattern);
|
|
407
407
|
u = y > u ? y : u;
|
|
408
408
|
});
|
|
409
409
|
});
|
|
410
|
-
const g = u - 1,
|
|
410
|
+
const g = u - 1, p = O(`0${g > 0 ? ".0" : "."}`, g), h = [];
|
|
411
411
|
return o.forEach((S) => {
|
|
412
412
|
N.foreach(S.range, (f, l) => {
|
|
413
|
-
const
|
|
414
|
-
if (!
|
|
413
|
+
const v = r.getValue(i, m, f, l);
|
|
414
|
+
if (!v)
|
|
415
415
|
h.push({
|
|
416
416
|
row: f,
|
|
417
417
|
col: l,
|
|
418
|
-
pattern:
|
|
418
|
+
pattern: p
|
|
419
419
|
});
|
|
420
420
|
else {
|
|
421
|
-
const y =
|
|
421
|
+
const y = U(v.pattern);
|
|
422
422
|
h.push({
|
|
423
423
|
row: f,
|
|
424
424
|
col: l,
|
|
425
|
-
pattern: O(
|
|
425
|
+
pattern: O(v.pattern, y - 1)
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
428
|
});
|
|
429
|
-
}), await t.executeCommand(
|
|
429
|
+
}), await t.executeCommand(P.id, { values: h });
|
|
430
430
|
}
|
|
431
|
-
},
|
|
431
|
+
}, ae = "sheets-numfmt.config", Z = {}, rt = (e) => x.getInfo(e).type || "unknown", Le = (e, t, n = "en") => {
|
|
432
432
|
const s = x.getInfo(e)._partitions[1], o = x.format(e, t, { locale: n, throws: !1 });
|
|
433
433
|
return t < 0 ? {
|
|
434
434
|
result: o,
|
|
@@ -441,8 +441,8 @@ const Ae = {
|
|
|
441
441
|
// In Excel, the default General format also needs to handle numeric precision.
|
|
442
442
|
} : Le(e, t, n);
|
|
443
443
|
var Be = Object.getOwnPropertyDescriptor, He = (e, t, n, r) => {
|
|
444
|
-
for (var s = r > 1 ? void 0 : r ? Be(t, n) : t, o = e.length - 1,
|
|
445
|
-
(
|
|
444
|
+
for (var s = r > 1 ? void 0 : r ? Be(t, n) : t, o = e.length - 1, a; o >= 0; o--)
|
|
445
|
+
(a = e[o]) && (s = a(s) || s);
|
|
446
446
|
return s;
|
|
447
447
|
}, R = (e, t) => (n, r) => t(n, r, e);
|
|
448
448
|
const We = {
|
|
@@ -452,11 +452,11 @@ const We = {
|
|
|
452
452
|
}
|
|
453
453
|
};
|
|
454
454
|
let D = class extends Q {
|
|
455
|
-
constructor(t, n, r, s, o,
|
|
455
|
+
constructor(t, n, r, s, o, a, i) {
|
|
456
456
|
super();
|
|
457
457
|
M(this, "_local$", new k("en"));
|
|
458
458
|
M(this, "local$", this._local$.asObservable());
|
|
459
|
-
this._instanceService = t, this._sheetInterceptorService = n, this._themeService = r, this._commandService = s, this._numfmtService = o, this._localeService =
|
|
459
|
+
this._instanceService = t, this._sheetInterceptorService = n, this._themeService = r, this._commandService = s, this._numfmtService = o, this._localeService = a, this._configService = i, this._initInterceptorCellContent();
|
|
460
460
|
}
|
|
461
461
|
get local() {
|
|
462
462
|
const t = this._local$.getValue();
|
|
@@ -489,35 +489,23 @@ let D = class extends Q {
|
|
|
489
489
|
// eslint-disable-next-line complexity
|
|
490
490
|
handler: (n, r, s) => {
|
|
491
491
|
var S;
|
|
492
|
-
const o = r.unitId,
|
|
492
|
+
const o = r.unitId, a = r.subUnitId;
|
|
493
493
|
let i;
|
|
494
494
|
const m = n;
|
|
495
|
-
if (!m)
|
|
495
|
+
if (!m || m.v === void 0 || m.v === null)
|
|
496
496
|
return s(n);
|
|
497
497
|
if (n != null && n.s) {
|
|
498
498
|
const f = r.workbook.getStyles().get(n.s);
|
|
499
499
|
f != null && f.n && (i = f.n);
|
|
500
500
|
}
|
|
501
|
-
if (i || (i = this._numfmtService.getValue(o,
|
|
501
|
+
if (i || (i = this._numfmtService.getValue(o, a, r.row, r.col)), !i || i.pattern === "General" || G(m.v) !== I.NUMBER)
|
|
502
502
|
return s(n);
|
|
503
|
-
if (ne(i.pattern))
|
|
504
|
-
return (S = this._configService.getConfig(
|
|
505
|
-
...n,
|
|
506
|
-
t: I.STRING
|
|
507
|
-
}) : s({
|
|
508
|
-
...n,
|
|
509
|
-
t: I.STRING,
|
|
510
|
-
markers: {
|
|
511
|
-
...n == null ? void 0 : n.markers,
|
|
512
|
-
...We
|
|
513
|
-
}
|
|
514
|
-
});
|
|
503
|
+
if ((!n || n === r.rawData) && (n = { ...r.rawData }), ne(i.pattern))
|
|
504
|
+
return (S = this._configService.getConfig(ae)) != null && S.disableTextFormatMark ? (n.t = I.STRING, s(n)) : (n.t = I.STRING, n.markers = { ...n == null ? void 0 : n.markers, ...We }, s(n));
|
|
515
505
|
let g = "";
|
|
516
|
-
const
|
|
517
|
-
if (
|
|
518
|
-
return s({ ...n, ...
|
|
519
|
-
if (m.v === void 0 || m.v === null)
|
|
520
|
-
return s(n);
|
|
506
|
+
const p = t.getValue(r.row, r.col);
|
|
507
|
+
if (p && p.parameters === `${m.v}_${i.pattern}`)
|
|
508
|
+
return s({ ...n, ...p.result });
|
|
521
509
|
const h = Ge(i.pattern, Number(m.v), this.local);
|
|
522
510
|
if (g = h.result, !g)
|
|
523
511
|
return s(n);
|
|
@@ -529,15 +517,15 @@ let D = class extends Q {
|
|
|
529
517
|
return t.setValue(r.row, r.col, {
|
|
530
518
|
result: C,
|
|
531
519
|
parameters: `${m.v}_${i.pattern}`
|
|
532
|
-
}),
|
|
520
|
+
}), Object.assign(n, C), s(n);
|
|
533
521
|
},
|
|
534
522
|
priority: Re.NUMFMT
|
|
535
523
|
})), this.disposeWithMe(this._commandService.onCommandExecuted((n) => {
|
|
536
524
|
if (n.id === te.id) {
|
|
537
525
|
const r = n.params;
|
|
538
526
|
Object.keys(r.values).forEach((s) => {
|
|
539
|
-
r.values[s].ranges.forEach((
|
|
540
|
-
N.foreach(
|
|
527
|
+
r.values[s].ranges.forEach((a) => {
|
|
528
|
+
N.foreach(a, (i, m) => {
|
|
541
529
|
t.realDeleteValue(i, m);
|
|
542
530
|
});
|
|
543
531
|
});
|
|
@@ -588,19 +576,19 @@ class J extends Q {
|
|
|
588
576
|
}
|
|
589
577
|
}
|
|
590
578
|
var ke = Object.defineProperty, Ke = Object.getOwnPropertyDescriptor, ze = (e, t, n) => t in e ? ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, Ye = (e, t, n, r) => {
|
|
591
|
-
for (var s = r > 1 ? void 0 : r ? Ke(t, n) : t, o = e.length - 1,
|
|
592
|
-
(
|
|
579
|
+
for (var s = r > 1 ? void 0 : r ? Ke(t, n) : t, o = e.length - 1, a; o >= 0; o--)
|
|
580
|
+
(a = e[o]) && (s = a(s) || s);
|
|
593
581
|
return s;
|
|
594
582
|
}, L = (e, t) => (n, r) => t(n, r, e), ie = (e, t, n) => ze(e, typeof t != "symbol" ? t + "" : t, n);
|
|
595
|
-
let A = class extends
|
|
583
|
+
let A = class extends pe {
|
|
596
584
|
constructor(e = Z, t, n, r) {
|
|
597
585
|
super(), this._config = e, this._injector = t, this._configService = n, this._commandService = r;
|
|
598
|
-
const { ...s } =
|
|
586
|
+
const { ...s } = ve(
|
|
599
587
|
{},
|
|
600
588
|
Z,
|
|
601
589
|
this._config
|
|
602
590
|
);
|
|
603
|
-
this._configService.setConfig(
|
|
591
|
+
this._configService.setConfig(ae, s);
|
|
604
592
|
}
|
|
605
593
|
onStarting() {
|
|
606
594
|
Se(this._injector, [
|
|
@@ -619,7 +607,7 @@ let A = class extends ve {
|
|
|
619
607
|
je,
|
|
620
608
|
Ae,
|
|
621
609
|
Fe,
|
|
622
|
-
|
|
610
|
+
P
|
|
623
611
|
].forEach((e) => {
|
|
624
612
|
this.disposeWithMe(this._commandService.registerCommand(e));
|
|
625
613
|
});
|
|
@@ -633,33 +621,33 @@ A = Ye([
|
|
|
633
621
|
L(2, X),
|
|
634
622
|
L(3, E)
|
|
635
623
|
], A);
|
|
636
|
-
const st = (e) => re.find((n) => e.includes(n)), ot = () => re.map((e) => ({ label: e, value: e })),
|
|
624
|
+
const st = (e) => re.find((n) => e.includes(n)), ot = () => re.map((e) => ({ label: e, value: e })), at = (e) => se.map((t) => ({
|
|
637
625
|
label: t.label(e),
|
|
638
626
|
value: t.suffix(e),
|
|
639
627
|
color: t.color
|
|
640
|
-
})), it = () =>
|
|
628
|
+
})), it = () => Pe.map((e) => ({ label: e.label, value: e.suffix })), ct = () => Ue.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
641
629
|
export {
|
|
642
630
|
De as AddDecimalCommand,
|
|
643
631
|
se as CURRENCYFORMAT,
|
|
644
|
-
|
|
632
|
+
Pe as DATEFMTLISG,
|
|
645
633
|
oe as MenuCurrencyService,
|
|
646
|
-
|
|
647
|
-
|
|
634
|
+
Ue as NUMBERFORMAT,
|
|
635
|
+
ae as SHEETS_NUMFMT_PLUGIN_CONFIG_KEY,
|
|
648
636
|
Ae as SetCurrencyCommand,
|
|
649
|
-
|
|
637
|
+
P as SetNumfmtCommand,
|
|
650
638
|
Fe as SetPercentCommand,
|
|
651
639
|
D as SheetsNumfmtCellContentController,
|
|
652
640
|
je as SubtractDecimalCommand,
|
|
653
641
|
A as UniverSheetsNumfmtPlugin,
|
|
654
|
-
|
|
642
|
+
we as countryCurrencyMap,
|
|
655
643
|
re as currencySymbols,
|
|
656
|
-
|
|
644
|
+
at as getCurrencyFormatOptions,
|
|
657
645
|
ot as getCurrencyOptions,
|
|
658
646
|
st as getCurrencyType,
|
|
659
647
|
it as getDateFormatOptions,
|
|
660
|
-
|
|
648
|
+
U as getDecimalFromPattern,
|
|
661
649
|
q as getDecimalString,
|
|
662
|
-
|
|
650
|
+
ct as getNumberFormatOptions,
|
|
663
651
|
Le as getPatternPreview,
|
|
664
652
|
Ge as getPatternPreviewIgnoreGeneral,
|
|
665
653
|
rt as getPatternType,
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.UniverEngineNumfmt,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,o,A,I,J){"use strict";var ge=Object.defineProperty;var Se=(a,t,o)=>t in a?ge(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o;var R=(a,t,o)=>Se(a,typeof t!="symbol"?t+"":t,o);const O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{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"}],B=[{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"}],V=[{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"}],X="SHEET_NUMFMT_PLUGIN",$=(e,r=0)=>{var n;return e&&(n=t.numfmt.getInfo(e).maxDecimals)!=null?n:r},Q=(e,r)=>{if(e&&!r||!e&&r)return!1;const i=c=>c.reduce((v,y)=>{if(v.isEnd)return v;const C=y.value||y.num;return y.type==="point"?(v.isEnd=!0,v):{...v,result:v.result+C}},{isEnd:!1,result:""}).result,n=t.numfmt.getInfo(e)._partitions,l=t.numfmt.getInfo(r)._partitions,s=i(n[0].tokens),m=i(l[0].tokens),S=i(n[1].tokens),d=i(l[1].tokens);return s===m&&S===d&&n[1].color===l[1].color},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${D(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${D(Number(r||0))}$1`):n).join(";"),ee=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),E={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),l=e.get(t.IUndoRedoService),s=o.getSheetCommandTarget(n,r);if(!s)return!1;const{unitId:m,subUnitId:S,worksheet:d}=s,c=r.values.filter(u=>!!u.pattern),v=r.values.filter(u=>!u.pattern),y=o.transformCellsToRange(m,S,c),C={unitId:m,subUnitId:S,ranges:v.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],p=[];if(c.length){const u=c.reduce((g,f)=>{A.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const M=d.getCellRaw(f.row,f.col);if(M){const P=o.checkCellValueType(M.v);P!==M.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),_=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const M=d.getCellRaw(g,f);M?_.setValue(g,f,{t:M.t}):_.setValue(g,f,{t:void 0})}),Object.keys(y.values).forEach(g=>{const f=y.values[g];f.ranges=o.rangeMerge(f.ranges)}),T.push({id:o.SetNumfmtMutation.id,params:y});const b=o.factorySetNumfmtUndoMutation(e,y);p.push(...b)}if(v.length){C.ranges=o.rangeMerge(C.ranges);const u=v.reduce((g,f)=>{const M=d.getCellRaw(f.row,f.col);if(M){const P=o.checkCellValueType(M.v);P!==M.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),_=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const M=d.getCellRaw(g,f);M?_.setValue(g,f,{t:M.t}):_.setValue(g,f,{t:void 0})}),T.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const b=o.factoryRemoveNumfmtUndoMutation(e,C);p.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:_.getMatrix()}},...b)}const h=t.sequenceExecute(T,i).result;return h&&l.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:T}),h}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),l=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const m=o.getSheetCommandTarget(l);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;s.forEach(T=>{t.Range.foreach(T.range,(p,h)=>{const u=n.getValue(S,d,p,h);if(!u){const b=m.worksheet.getCellRaw(p,h);if(!c&&b&&b.t===t.CellValueType.NUMBER&&b.v){const g=/\.(\d*)$/.exec(String(b.v));if(g){const f=g[1].length;if(!f)return;c=Math.max(c,f)}}return}const _=$(u.pattern);c=_>c?_:c})});const v=c+1,y=U(`0${v>0?".0":""}`,v),C=[];return s.forEach(T=>{t.Range.foreach(T.range,(p,h)=>{const u=n.getValue(S,d,p,h);if(!u)C.push({row:p,col:h,pattern:y});else{const _=$(u.pattern),b=U(u.pattern,_+1);b!==u.pattern&&C.push({row:p,col:h,pattern:b})}})}),C.length?await r.executeCommand(E.id,{values:C}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(j),l=L[n.getCurrencySymbol()]||"$",s=i.getCurrentSelections();if(!s||!s.length)return!1;const m=[],S=V[4].suffix(l);return s.forEach(c=>{t.Range.foreach(c.range,(v,y)=>{m.push({row:v,col:y,pattern:S,type:"currency"})})}),await r.executeCommand(E.id,{values:m})}},W={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const l=[],s="0%";return n.forEach(S=>{t.Range.foreach(S.range,(d,c)=>{l.push({row:d,col:c,pattern:s,type:"percent"})})}),await r.executeCommand(E.id,{values:l})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),l=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const m=o.getSheetCommandTarget(l);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;s.forEach(p=>{t.Range.foreach(p.range,(h,u)=>{const _=n.getValue(S,d,h,u);if(!_){const g=m.worksheet.getCellRaw(h,u);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const M=f[1].length;if(!M)return;c=Math.max(c,M)}}return}const b=$(_.pattern);c=b>c?b:c})});const v=c-1,y=U(`0${v>0?".0":"."}`,v),C=[];return s.forEach(p=>{t.Range.foreach(p.range,(h,u)=>{const _=n.getValue(S,d,h,u);if(!_)C.push({row:h,col:u,pattern:y});else{const b=$(_.pattern);C.push({row:h,col:u,pattern:U(_.pattern,b-1)})}})}),await r.executeCommand(E.id,{values:C})}},w="sheets-numfmt.config",k={},te=e=>t.numfmt.getInfo(e).type||"unknown",K=(e,r,i="en")=>{const l=t.numfmt.getInfo(e)._partitions[1],s=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:s,color:l.color}:{result:s}},Y=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:K(e,r,i);var ne=Object.getOwnPropertyDescriptor,re=(e,r,i,n)=>{for(var l=n>1?void 0:n?ne(r,i):r,s=e.length-1,m;s>=0;s--)(m=e[s])&&(l=m(l)||l);return l},N=(e,r)=>(i,n)=>r(i,n,e);const ie={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,l,s,m,S,d){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=l,this._commandService=s,this._numfmtService=m,this._localeService=S,this._configService=d,this._initInterceptorCellContent()}get local(){const i=this._local$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,l,s)=>{var h;const m=l.unitId,S=l.subUnitId;let d;const c=n;if(!c)return s(n);if(n!=null&&n.s){const u=l.workbook.getStyles().get(n.s);u!=null&&u.n&&(d=u.n)}if(d||(d=this._numfmtService.getValue(m,S,l.row,l.col)),!d||(n.t||o.checkCellValueType(c.v))!==t.CellValueType.NUMBER)return s(n);if(A.isTextFormat(d.pattern))return(h=this._configService.getConfig(w))!=null&&h.disableTextFormatMark?s({...n,t:t.CellValueType.STRING}):s({...n,t:t.CellValueType.STRING,markers:{...n==null?void 0:n.markers,...ie}});let y="";const C=i.getValue(l.row,l.col);if(C&&C.parameters===`${c.v}_${d.pattern}`)return s({...n,...C.result});if(c.v===void 0||c.v===null)return s(n);const T=Y(d.pattern,Number(c.v),this.local);if(y=T.result,!y)return s(n);const p={v:y,t:t.CellValueType.NUMBER};if(T.color){const u=this._themeService.getColorFromTheme(`${T.color}.500`);u&&(p.interceptorStyle={cl:{rgb:u}})}return i.setValue(l.row,l.col,{result:p,parameters:`${c.v}_${d.pattern}`}),s({...n,...p})},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const l=n.params;Object.keys(l.values).forEach(s=>{l.values[s].ranges.forEach(S=>{t.Range.foreach(S,(d,c)=>{i.realDeleteValue(d,c)})})})}else if(n.id===o.SetRangeValuesMutation.id){const l=n.params;new t.ObjectMatrix(l.cellValue).forValue((s,m)=>{i.realDeleteValue(s,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var l;return(l=n==null?void 0:n.activeSheet$)!=null?l:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._local$.next(i)}},a.SheetsNumfmtCellContentController=re([N(0,t.IUniverInstanceService),N(1,t.Inject(o.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(o.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);class z extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(i){this._currencySymbol$.next(i)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,se=Object.getOwnPropertyDescriptor,le=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,ue=(e,r,i,n)=>{for(var l=n>1?void 0:n?se(r,i):r,s=e.length-1,m;s>=0;s--)(m=e[s])&&(l=m(l)||l);return l},F=(e,r)=>(i,n)=>r(i,n,e),Z=(e,r,i)=>le(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=k,i,n,l){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=l;const{...s}=t.merge({},k,this._config);this._configService.setConfig(w,s)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[j],[z]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[z]]),[x,q,H,W,E].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=ue([t.DependentOn(o.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ce=e=>O.find(i=>e.includes(i)),oe=()=>O.map(e=>({label:e,value:e})),me=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>G.map(e=>({label:e.label,value:e.suffix})),de=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=x,a.CURRENCYFORMAT=V,a.DATEFMTLISG=G,a.MenuCurrencyService=j,a.NUMBERFORMAT=B,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,a.SetCurrencyCommand=H,a.SetNumfmtCommand=E,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=me,a.getCurrencyOptions=oe,a.getCurrencyType=ce,a.getDateFormatOptions=fe,a.getDecimalFromPattern=$,a.getDecimalString=D,a.getNumberFormatOptions=de,a.getPatternPreview=K,a.getPatternPreviewIgnoreGeneral=Y,a.getPatternType=te,a.isPatternEqualWithoutDecimal=Q,a.isPatternHasDecimal=ee,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.UniverEngineNumfmt,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,o,A,I,J){"use strict";var ge=Object.defineProperty;var Se=(a,t,o)=>t in a?ge(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o;var R=(a,t,o)=>Se(a,typeof t!="symbol"?t+"":t,o);const O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{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"}],x=[{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"}],V=[{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"}],X="SHEET_NUMFMT_PLUGIN",$=(e,r=0)=>{var n;return e&&(n=t.numfmt.getInfo(e).maxDecimals)!=null?n:r},Q=(e,r)=>{if(e&&!r||!e&&r)return!1;const i=c=>c.reduce((v,y)=>{if(v.isEnd)return v;const C=y.value||y.num;return y.type==="point"?(v.isEnd=!0,v):{...v,result:v.result+C}},{isEnd:!1,result:""}).result,n=t.numfmt.getInfo(e)._partitions,s=t.numfmt.getInfo(r)._partitions,l=i(n[0].tokens),m=i(s[0].tokens),S=i(n[1].tokens),f=i(s[1].tokens);return l===m&&S===f&&n[1].color===s[1].color},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${D(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${D(Number(r||0))}$1`):n).join(";"),ee=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),E={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=o.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:f}=l,c=r.values.filter(u=>!!u.pattern),v=r.values.filter(u=>!u.pattern),y=o.transformCellsToRange(m,S,c),C={unitId:m,subUnitId:S,ranges:v.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],p=[];if(c.length){const u=c.reduce((g,d)=>{A.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.CellValueType.STRING});const M=f.getCellRaw(d.row,d.col);if(M){const P=o.checkCellValueType(M.v);P!==M.t&&g.setValue(d.row,d.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),_=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,d)=>{const M=f.getCellRaw(g,d);M?_.setValue(g,d,{t:M.t}):_.setValue(g,d,{t:void 0})}),Object.keys(y.values).forEach(g=>{const d=y.values[g];d.ranges=o.rangeMerge(d.ranges)}),T.push({id:o.SetNumfmtMutation.id,params:y});const b=o.factorySetNumfmtUndoMutation(e,y);p.push(...b)}if(v.length){C.ranges=o.rangeMerge(C.ranges);const u=v.reduce((g,d)=>{const M=f.getCellRaw(d.row,d.col);if(M){const P=o.checkCellValueType(M.v);P!==M.t&&g.setValue(d.row,d.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),_=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,d)=>{const M=f.getCellRaw(g,d);M?_.setValue(g,d,{t:M.t}):_.setValue(g,d,{t:void 0})}),T.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const b=o.factoryRemoveNumfmtUndoMutation(e,C);p.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:_.getMatrix()}},...b)}const h=t.sequenceExecute(T,i).result;return h&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:T}),h}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:f}=m;let c=0;l.forEach(T=>{t.Range.foreach(T.range,(p,h)=>{const u=n.getValue(S,f,p,h);if(!u){const b=m.worksheet.getCellRaw(p,h);if(!c&&b&&b.t===t.CellValueType.NUMBER&&b.v){const g=/\.(\d*)$/.exec(String(b.v));if(g){const d=g[1].length;if(!d)return;c=Math.max(c,d)}}return}const _=$(u.pattern);c=_>c?_:c})});const v=c+1,y=U(`0${v>0?".0":""}`,v),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(p,h)=>{const u=n.getValue(S,f,p,h);if(!u)C.push({row:p,col:h,pattern:y});else{const _=$(u.pattern),b=U(u.pattern,_+1);b!==u.pattern&&C.push({row:p,col:h,pattern:b})}})}),C.length?await r.executeCommand(E.id,{values:C}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(j),s=L[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],S=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(v,y)=>{m.push({row:v,col:y,pattern:S,type:"currency"})})}),await r.executeCommand(E.id,{values:m})}},W={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(f,c)=>{s.push({row:f,col:c,pattern:l,type:"percent"})})}),await r.executeCommand(E.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:f}=m;let c=0;l.forEach(p=>{t.Range.foreach(p.range,(h,u)=>{const _=n.getValue(S,f,h,u);if(!_){const g=m.worksheet.getCellRaw(h,u);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const d=/\.(\d*)$/.exec(String(g.v));if(d){const M=d[1].length;if(!M)return;c=Math.max(c,M)}}return}const b=$(_.pattern);c=b>c?b:c})});const v=c-1,y=U(`0${v>0?".0":"."}`,v),C=[];return l.forEach(p=>{t.Range.foreach(p.range,(h,u)=>{const _=n.getValue(S,f,h,u);if(!_)C.push({row:h,col:u,pattern:y});else{const b=$(_.pattern);C.push({row:h,col:u,pattern:U(_.pattern,b-1)})}})}),await r.executeCommand(E.id,{values:C})}},w="sheets-numfmt.config",k={},te=e=>t.numfmt.getInfo(e).type||"unknown",K=(e,r,i="en")=>{const s=t.numfmt.getInfo(e)._partitions[1],l=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:l,color:s.color}:{result:l}},Y=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:K(e,r,i);var ne=Object.getOwnPropertyDescriptor,re=(e,r,i,n)=>{for(var s=n>1?void 0:n?ne(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,r)=>(i,n)=>r(i,n,e);const ie={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,f){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=f,this._initInterceptorCellContent()}get local(){const i=this._local$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var h;const m=s.unitId,S=s.subUnitId;let f;const c=n;if(!c||c.v===void 0||c.v===null)return l(n);if(n!=null&&n.s){const u=s.workbook.getStyles().get(n.s);u!=null&&u.n&&(f=u.n)}if(f||(f=this._numfmtService.getValue(m,S,s.row,s.col)),!f||f.pattern==="General"||o.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),A.isTextFormat(f.pattern))return(h=this._configService.getConfig(w))!=null&&h.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ie},l(n));let y="";const C=i.getValue(s.row,s.col);if(C&&C.parameters===`${c.v}_${f.pattern}`)return l({...n,...C.result});const T=Y(f.pattern,Number(c.v),this.local);if(y=T.result,!y)return l(n);const p={v:y,t:t.CellValueType.NUMBER};if(T.color){const u=this._themeService.getColorFromTheme(`${T.color}.500`);u&&(p.interceptorStyle={cl:{rgb:u}})}return i.setValue(s.row,s.col,{result:p,parameters:`${c.v}_${f.pattern}`}),Object.assign(n,p),l(n)},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(f,c)=>{i.realDeleteValue(f,c)})})})}else if(n.id===o.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._local$.next(i)}},a.SheetsNumfmtCellContentController=re([N(0,t.IUniverInstanceService),N(1,t.Inject(o.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(o.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);class z extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(i){this._currencySymbol$.next(i)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,se=Object.getOwnPropertyDescriptor,le=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,ue=(e,r,i,n)=>{for(var s=n>1?void 0:n?se(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},F=(e,r)=>(i,n)=>r(i,n,e),Z=(e,r,i)=>le(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=k,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},k,this._config);this._configService.setConfig(w,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[j],[z]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[z]]),[B,q,H,W,E].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=ue([t.DependentOn(o.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ce=e=>O.find(i=>e.includes(i)),oe=()=>O.map(e=>({label:e,value:e})),me=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>G.map(e=>({label:e.label,value:e.suffix})),de=()=>x.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=B,a.CURRENCYFORMAT=V,a.DATEFMTLISG=G,a.MenuCurrencyService=j,a.NUMBERFORMAT=x,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,a.SetCurrencyCommand=H,a.SetNumfmtCommand=E,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=me,a.getCurrencyOptions=oe,a.getCurrencyType=ce,a.getDateFormatOptions=fe,a.getDecimalFromPattern=$,a.getDecimalString=D,a.getNumberFormatOptions=de,a.getPatternPreview=K,a.getPatternPreviewIgnoreGeneral=Y,a.getPatternType=te,a.isPatternEqualWithoutDecimal=Q,a.isPatternHasDecimal=ee,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.8.0-
|
|
3
|
+
"version": "0.8.0-nightly.202505271607",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -58,10 +58,10 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/
|
|
63
|
-
"@univerjs/engine-numfmt": "0.8.0-
|
|
64
|
-
"@univerjs/
|
|
61
|
+
"@univerjs/core": "0.8.0-nightly.202505271607",
|
|
62
|
+
"@univerjs/engine-formula": "0.8.0-nightly.202505271607",
|
|
63
|
+
"@univerjs/engine-numfmt": "0.8.0-nightly.202505271607",
|
|
64
|
+
"@univerjs/sheets": "0.8.0-nightly.202505271607"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"rxjs": "^7.8.2",
|