@univerjs/sheets-numfmt 0.8.1-nightly.202506181607 → 0.8.1
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/LICENSE +176 -0
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +162 -162
- package/lib/index.js +162 -162
- package/lib/umd/index.js +1 -1
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var ie = Object.defineProperty;
|
|
2
2
|
var le = (e, t, r) => t in e ? ie(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var
|
|
4
|
-
import { numfmt as
|
|
3
|
+
var M = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { numfmt as U, CommandType as V, ICommandService as T, IUniverInstanceService as A, IUndoRedoService as ue, CellValueType as N, ObjectMatrix as b, sequenceExecute as me, Range as I, Inject as E, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as z, UniverInstanceType as ee, DependentOn as he, Injector as ge, Plugin as pe, merge as ve, registerDependencies as Se, touchDependencies as Y } from "@univerjs/core";
|
|
5
5
|
import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as Z, 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 Ne } from "@univerjs/sheets";
|
|
6
6
|
import { isTextFormat as re } from "@univerjs/engine-numfmt";
|
|
7
7
|
import { BehaviorSubject as K, merge as Ie, switchMap as Te, of as Ee, skip as xe } from "rxjs";
|
|
@@ -34,7 +34,7 @@ const ne = [
|
|
|
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 ne = [
|
|
|
74
74
|
SI: "€",
|
|
75
75
|
ES: "€"
|
|
76
76
|
// Add more mappings as needed
|
|
77
|
-
},
|
|
77
|
+
}, Ue = [
|
|
78
78
|
{
|
|
79
79
|
label: "1930-08-05",
|
|
80
80
|
suffix: "yyyy-MM-dd"
|
|
@@ -177,14 +177,14 @@ const ne = [
|
|
|
177
177
|
}
|
|
178
178
|
], Pe = "SHEET_NUMFMT_PLUGIN", O = (e, t = 0) => {
|
|
179
179
|
var n;
|
|
180
|
-
return e && (n =
|
|
180
|
+
return e && (n = U.getFormatInfo(e).maxDecimals) != null ? n : t;
|
|
181
181
|
}, k = (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(
|
|
182
182
|
/\.0*/g,
|
|
183
183
|
`${t > 0 ? "." : ""}${k(Number(t || 0))}`
|
|
184
184
|
) : /0([^0]?)|0$/.test(n) ? n.replace(
|
|
185
185
|
/0([^0]+)|0$/,
|
|
186
186
|
`0${t > 0 ? "." : ""}${k(Number(t || 0))}$1`
|
|
187
|
-
) : n).join(";"), tt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e),
|
|
187
|
+
) : n).join(";"), tt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), w = {
|
|
188
188
|
id: "sheet.command.numfmt.set.numfmt",
|
|
189
189
|
type: V.COMMAND,
|
|
190
190
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -193,32 +193,32 @@ const ne = [
|
|
|
193
193
|
return !1;
|
|
194
194
|
const r = e.get(T), n = e.get(A), s = e.get(ue), o = H(n, t);
|
|
195
195
|
if (!o) return !1;
|
|
196
|
-
const { unitId:
|
|
197
|
-
unitId:
|
|
198
|
-
subUnitId:
|
|
199
|
-
ranges: y.map((
|
|
200
|
-
startColumn:
|
|
201
|
-
startRow:
|
|
202
|
-
endColumn:
|
|
203
|
-
endRow:
|
|
196
|
+
const { unitId: c, subUnitId: l, worksheet: f } = o, u = t.values.filter((a) => !!a.pattern), y = t.values.filter((a) => !a.pattern), _ = ye(c, l, u), h = {
|
|
197
|
+
unitId: c,
|
|
198
|
+
subUnitId: l,
|
|
199
|
+
ranges: y.map((a) => ({
|
|
200
|
+
startColumn: a.col,
|
|
201
|
+
startRow: a.row,
|
|
202
|
+
endColumn: a.col,
|
|
203
|
+
endRow: a.row
|
|
204
204
|
}))
|
|
205
205
|
}, C = [], p = [];
|
|
206
206
|
if (u.length) {
|
|
207
|
-
const
|
|
208
|
-
re(
|
|
209
|
-
const S = f.getCellRaw(
|
|
207
|
+
const a = u.reduce((m, i) => {
|
|
208
|
+
re(i.pattern) && m.setValue(i.row, i.col, { t: N.STRING });
|
|
209
|
+
const S = f.getCellRaw(i.row, i.col);
|
|
210
210
|
if (S) {
|
|
211
211
|
const x = G(S.v);
|
|
212
|
-
x !== S.t &&
|
|
212
|
+
x !== S.t && m.setValue(i.row, i.col, { t: x });
|
|
213
213
|
}
|
|
214
|
-
return
|
|
215
|
-
}, new b()).getMatrix(),
|
|
216
|
-
new b(
|
|
217
|
-
const S = f.getCellRaw(
|
|
218
|
-
S ?
|
|
219
|
-
}), Object.keys(_.values).forEach((
|
|
220
|
-
const
|
|
221
|
-
|
|
214
|
+
return m;
|
|
215
|
+
}, new b()).getMatrix(), g = new b();
|
|
216
|
+
new b(a).forValue((m, i) => {
|
|
217
|
+
const S = f.getCellRaw(m, i);
|
|
218
|
+
S ? g.setValue(m, i, { t: S.t }) : g.setValue(m, i, { t: void 0 });
|
|
219
|
+
}), Object.keys(_.values).forEach((m) => {
|
|
220
|
+
const i = _.values[m];
|
|
221
|
+
i.ranges = Z(i.ranges);
|
|
222
222
|
}), C.push({
|
|
223
223
|
id: te.id,
|
|
224
224
|
params: _
|
|
@@ -227,45 +227,45 @@ const ne = [
|
|
|
227
227
|
p.push(...v);
|
|
228
228
|
}
|
|
229
229
|
if (y.length) {
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
const S = f.getCellRaw(
|
|
230
|
+
h.ranges = Z(h.ranges);
|
|
231
|
+
const a = y.reduce((m, i) => {
|
|
232
|
+
const S = f.getCellRaw(i.row, i.col);
|
|
233
233
|
if (S) {
|
|
234
234
|
const x = G(S.v);
|
|
235
|
-
x !== S.t &&
|
|
235
|
+
x !== S.t && m.setValue(i.row, i.col, { t: x });
|
|
236
236
|
}
|
|
237
|
-
return
|
|
238
|
-
}, new b()).getMatrix(),
|
|
239
|
-
new b(
|
|
240
|
-
const S = f.getCellRaw(
|
|
241
|
-
S ?
|
|
237
|
+
return m;
|
|
238
|
+
}, new b()).getMatrix(), g = new b();
|
|
239
|
+
new b(a).forValue((m, i) => {
|
|
240
|
+
const S = f.getCellRaw(m, i);
|
|
241
|
+
S ? g.setValue(m, i, { t: S.t }) : g.setValue(m, i, { t: void 0 });
|
|
242
242
|
}), C.push({
|
|
243
243
|
id: Ce.id,
|
|
244
|
-
params:
|
|
244
|
+
params: h
|
|
245
245
|
}, {
|
|
246
246
|
id: B.id,
|
|
247
247
|
params: {
|
|
248
|
-
unitId:
|
|
249
|
-
subUnitId:
|
|
250
|
-
cellValue:
|
|
248
|
+
unitId: c,
|
|
249
|
+
subUnitId: l,
|
|
250
|
+
cellValue: a
|
|
251
251
|
}
|
|
252
252
|
});
|
|
253
|
-
const v = be(e,
|
|
253
|
+
const v = be(e, h);
|
|
254
254
|
p.push({
|
|
255
255
|
id: B.id,
|
|
256
256
|
params: {
|
|
257
|
-
unitId:
|
|
258
|
-
subUnitId:
|
|
259
|
-
cellValue:
|
|
257
|
+
unitId: c,
|
|
258
|
+
subUnitId: l,
|
|
259
|
+
cellValue: g.getMatrix()
|
|
260
260
|
}
|
|
261
261
|
}, ...v);
|
|
262
262
|
}
|
|
263
|
-
const
|
|
264
|
-
return
|
|
265
|
-
unitID:
|
|
263
|
+
const d = me(C, r).result;
|
|
264
|
+
return d && s.pushUndoRedo({
|
|
265
|
+
unitID: c,
|
|
266
266
|
undoMutations: p,
|
|
267
267
|
redoMutations: C
|
|
268
|
-
}),
|
|
268
|
+
}), d;
|
|
269
269
|
}
|
|
270
270
|
}, De = {
|
|
271
271
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
@@ -274,56 +274,56 @@ const ne = [
|
|
|
274
274
|
const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
|
|
275
275
|
if (!o || !o.length)
|
|
276
276
|
return !1;
|
|
277
|
-
const
|
|
278
|
-
if (!
|
|
279
|
-
const { unitId:
|
|
277
|
+
const c = H(s);
|
|
278
|
+
if (!c) return !1;
|
|
279
|
+
const { unitId: l, subUnitId: f } = c;
|
|
280
280
|
let u = 0;
|
|
281
281
|
o.forEach((C) => {
|
|
282
|
-
I.foreach(C.range, (p,
|
|
283
|
-
const
|
|
284
|
-
if (!
|
|
285
|
-
const v =
|
|
286
|
-
if (!u && v && v.t ===
|
|
287
|
-
const
|
|
288
|
-
if (
|
|
289
|
-
const
|
|
290
|
-
if (!
|
|
282
|
+
I.foreach(C.range, (p, d) => {
|
|
283
|
+
const a = n.getValue(l, f, p, d);
|
|
284
|
+
if (!a) {
|
|
285
|
+
const v = c.worksheet.getCellRaw(p, d);
|
|
286
|
+
if (!u && v && v.t === N.NUMBER && v.v) {
|
|
287
|
+
const m = /\.(\d*)$/.exec(String(v.v));
|
|
288
|
+
if (m) {
|
|
289
|
+
const i = m[1].length;
|
|
290
|
+
if (!i)
|
|
291
291
|
return;
|
|
292
|
-
u = Math.max(u,
|
|
292
|
+
u = Math.max(u, i);
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
return;
|
|
296
296
|
}
|
|
297
|
-
const
|
|
298
|
-
u =
|
|
297
|
+
const g = O(a.pattern);
|
|
298
|
+
u = g > u ? g : u;
|
|
299
299
|
});
|
|
300
300
|
});
|
|
301
|
-
const y = u + 1, _ = P(`0${y > 0 ? ".0" : ""}`, y),
|
|
301
|
+
const y = u + 1, _ = P(`0${y > 0 ? ".0" : ""}`, y), h = [];
|
|
302
302
|
return o.forEach((C) => {
|
|
303
|
-
I.foreach(C.range, (p,
|
|
304
|
-
const
|
|
305
|
-
if (!
|
|
306
|
-
|
|
303
|
+
I.foreach(C.range, (p, d) => {
|
|
304
|
+
const a = n.getValue(l, f, p, d);
|
|
305
|
+
if (!a)
|
|
306
|
+
h.push({
|
|
307
307
|
row: p,
|
|
308
|
-
col:
|
|
308
|
+
col: d,
|
|
309
309
|
pattern: _
|
|
310
310
|
});
|
|
311
311
|
else {
|
|
312
|
-
const
|
|
313
|
-
v !==
|
|
312
|
+
const g = O(a.pattern), v = P(a.pattern, g + 1);
|
|
313
|
+
v !== a.pattern && h.push({
|
|
314
314
|
row: p,
|
|
315
|
-
col:
|
|
315
|
+
col: d,
|
|
316
316
|
pattern: v
|
|
317
317
|
});
|
|
318
318
|
}
|
|
319
319
|
});
|
|
320
|
-
}),
|
|
320
|
+
}), h.length ? await t.executeCommand(w.id, { values: h }) : !1;
|
|
321
321
|
}
|
|
322
322
|
};
|
|
323
323
|
class oe {
|
|
324
324
|
constructor() {
|
|
325
|
-
|
|
326
|
-
|
|
325
|
+
M(this, "_currencySymbol$", new K("US"));
|
|
326
|
+
M(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
329
329
|
* Set the currency symbol by setting the country code.
|
|
@@ -339,15 +339,15 @@ const Fe = {
|
|
|
339
339
|
id: "sheet.command.numfmt.set.currency",
|
|
340
340
|
type: V.COMMAND,
|
|
341
341
|
handler: async (e) => {
|
|
342
|
-
const t = e.get(T), r = e.get(j), n = e.get(oe), s =
|
|
342
|
+
const t = e.get(T), r = e.get(j), n = e.get(oe), s = we[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
|
|
343
343
|
if (!o || !o.length)
|
|
344
344
|
return !1;
|
|
345
|
-
const
|
|
345
|
+
const c = [], l = se[4].suffix(s);
|
|
346
346
|
return o.forEach((u) => {
|
|
347
347
|
I.foreach(u.range, (y, _) => {
|
|
348
|
-
|
|
348
|
+
c.push({ row: y, col: _, pattern: l, type: "currency" });
|
|
349
349
|
});
|
|
350
|
-
}), await t.executeCommand(
|
|
350
|
+
}), await t.executeCommand(w.id, { values: c });
|
|
351
351
|
}
|
|
352
352
|
}, Ae = {
|
|
353
353
|
id: "sheet.command.numfmt.set.percent",
|
|
@@ -357,11 +357,11 @@ const Fe = {
|
|
|
357
357
|
if (!n || !n.length)
|
|
358
358
|
return !1;
|
|
359
359
|
const s = [], o = "0%";
|
|
360
|
-
return n.forEach((
|
|
361
|
-
I.foreach(
|
|
360
|
+
return n.forEach((l) => {
|
|
361
|
+
I.foreach(l.range, (f, u) => {
|
|
362
362
|
s.push({ row: f, col: u, pattern: o, type: "percent" });
|
|
363
363
|
});
|
|
364
|
-
}), await t.executeCommand(
|
|
364
|
+
}), await t.executeCommand(w.id, { values: s });
|
|
365
365
|
}
|
|
366
366
|
}, je = {
|
|
367
367
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
@@ -370,19 +370,19 @@ const Fe = {
|
|
|
370
370
|
const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
|
|
371
371
|
if (!o || !o.length)
|
|
372
372
|
return !1;
|
|
373
|
-
const
|
|
374
|
-
if (!
|
|
375
|
-
const { unitId:
|
|
373
|
+
const c = H(s);
|
|
374
|
+
if (!c) return !1;
|
|
375
|
+
const { unitId: l, subUnitId: f } = c;
|
|
376
376
|
let u = 0;
|
|
377
377
|
o.forEach((p) => {
|
|
378
|
-
I.foreach(p.range, (
|
|
379
|
-
const
|
|
380
|
-
if (!
|
|
381
|
-
const
|
|
382
|
-
if (!u &&
|
|
383
|
-
const
|
|
384
|
-
if (
|
|
385
|
-
const S =
|
|
378
|
+
I.foreach(p.range, (d, a) => {
|
|
379
|
+
const g = n.getValue(l, f, d, a);
|
|
380
|
+
if (!g) {
|
|
381
|
+
const m = c.worksheet.getCellRaw(d, a);
|
|
382
|
+
if (!u && m && m.t === N.NUMBER && m.v) {
|
|
383
|
+
const i = /\.(\d*)$/.exec(String(m.v));
|
|
384
|
+
if (i) {
|
|
385
|
+
const S = i[1].length;
|
|
386
386
|
if (!S)
|
|
387
387
|
return;
|
|
388
388
|
u = Math.max(u, S);
|
|
@@ -390,33 +390,33 @@ const Fe = {
|
|
|
390
390
|
}
|
|
391
391
|
return;
|
|
392
392
|
}
|
|
393
|
-
const v = O(
|
|
393
|
+
const v = O(g.pattern);
|
|
394
394
|
u = v > u ? v : u;
|
|
395
395
|
});
|
|
396
396
|
});
|
|
397
|
-
const y = u - 1, _ = P(`0${y > 0 ? ".0" : "."}`, y),
|
|
397
|
+
const y = u - 1, _ = P(`0${y > 0 ? ".0" : "."}`, y), h = [];
|
|
398
398
|
return o.forEach((p) => {
|
|
399
|
-
I.foreach(p.range, (
|
|
400
|
-
const
|
|
401
|
-
if (!
|
|
402
|
-
|
|
403
|
-
row:
|
|
404
|
-
col:
|
|
399
|
+
I.foreach(p.range, (d, a) => {
|
|
400
|
+
const g = n.getValue(l, f, d, a);
|
|
401
|
+
if (!g)
|
|
402
|
+
h.push({
|
|
403
|
+
row: d,
|
|
404
|
+
col: a,
|
|
405
405
|
pattern: _
|
|
406
406
|
});
|
|
407
407
|
else {
|
|
408
|
-
const v = O(
|
|
409
|
-
|
|
410
|
-
row:
|
|
411
|
-
col:
|
|
412
|
-
pattern: P(
|
|
408
|
+
const v = O(g.pattern);
|
|
409
|
+
h.push({
|
|
410
|
+
row: d,
|
|
411
|
+
col: a,
|
|
412
|
+
pattern: P(g.pattern, v - 1)
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
415
|
});
|
|
416
|
-
}), await t.executeCommand(
|
|
416
|
+
}), await t.executeCommand(w.id, { values: h });
|
|
417
417
|
}
|
|
418
|
-
}, ae = "sheets-numfmt.config", q = {}, rt = (e) =>
|
|
419
|
-
const n =
|
|
418
|
+
}, ae = "sheets-numfmt.config", q = {}, rt = (e) => U.getFormatInfo(e).type || "unknown", Le = (e, t, r = "en") => {
|
|
419
|
+
const n = U.formatColor(e, t), s = n ? String(n) : void 0, o = U.format(e, t, { locale: r, throws: !1 });
|
|
420
420
|
return t < 0 ? {
|
|
421
421
|
result: o,
|
|
422
422
|
color: s
|
|
@@ -428,10 +428,10 @@ const Fe = {
|
|
|
428
428
|
// In Excel, the default General format also needs to handle numeric precision.
|
|
429
429
|
} : Le(e, t, r);
|
|
430
430
|
var Be = Object.getOwnPropertyDescriptor, He = (e, t, r, n) => {
|
|
431
|
-
for (var s = n > 1 ? void 0 : n ? Be(t, r) : t, o = e.length - 1,
|
|
432
|
-
(
|
|
431
|
+
for (var s = n > 1 ? void 0 : n ? Be(t, r) : t, o = e.length - 1, c; o >= 0; o--)
|
|
432
|
+
(c = e[o]) && (s = c(s) || s);
|
|
433
433
|
return s;
|
|
434
|
-
},
|
|
434
|
+
}, R = (e, t) => (r, n) => t(r, n, e);
|
|
435
435
|
const We = {
|
|
436
436
|
tl: {
|
|
437
437
|
size: 6,
|
|
@@ -439,29 +439,29 @@ const We = {
|
|
|
439
439
|
}
|
|
440
440
|
};
|
|
441
441
|
let D = class extends Q {
|
|
442
|
-
constructor(t, r, n, s, o,
|
|
442
|
+
constructor(t, r, n, s, o, c, l) {
|
|
443
443
|
super();
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService =
|
|
444
|
+
M(this, "_local$", new K("en"));
|
|
445
|
+
M(this, "local$", this._local$.asObservable());
|
|
446
|
+
this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = c, this._configService = l, this._initInterceptorCellContent();
|
|
447
447
|
}
|
|
448
448
|
get local() {
|
|
449
449
|
const t = this._local$.getValue();
|
|
450
450
|
if (t)
|
|
451
451
|
return t;
|
|
452
452
|
switch (this._localeService.getCurrentLocale()) {
|
|
453
|
-
case
|
|
453
|
+
case $.FR_FR:
|
|
454
454
|
return "fr";
|
|
455
|
-
case
|
|
455
|
+
case $.RU_RU:
|
|
456
456
|
return "ru";
|
|
457
|
-
case
|
|
457
|
+
case $.VI_VN:
|
|
458
458
|
return "vi";
|
|
459
|
-
case
|
|
459
|
+
case $.ZH_CN:
|
|
460
460
|
return "zh-CN";
|
|
461
|
-
case
|
|
461
|
+
case $.ZH_TW:
|
|
462
462
|
return "zh-TW";
|
|
463
|
-
case
|
|
464
|
-
case
|
|
463
|
+
case $.EN_US:
|
|
464
|
+
case $.FA_IR:
|
|
465
465
|
default:
|
|
466
466
|
return "en";
|
|
467
467
|
}
|
|
@@ -475,45 +475,45 @@ let D = class extends Q {
|
|
|
475
475
|
effect: z.Value | z.Style,
|
|
476
476
|
// eslint-disable-next-line complexity
|
|
477
477
|
handler: (r, n, s) => {
|
|
478
|
-
var
|
|
479
|
-
const o = n.unitId,
|
|
480
|
-
let
|
|
478
|
+
var p, d;
|
|
479
|
+
const o = n.unitId, c = n.subUnitId;
|
|
480
|
+
let l;
|
|
481
481
|
const f = r;
|
|
482
482
|
if (!f || f.v === void 0 || f.v === null)
|
|
483
483
|
return s(r);
|
|
484
484
|
if (r != null && r.s) {
|
|
485
|
-
const
|
|
486
|
-
|
|
485
|
+
const a = n.workbook.getStyles().get(r.s);
|
|
486
|
+
a != null && a.n && (l = a.n);
|
|
487
487
|
}
|
|
488
|
-
if (
|
|
488
|
+
if (l || (l = this._numfmtService.getValue(o, c, n.row, n.col)), !l || l.pattern === "General" || G(f.v) !== N.NUMBER)
|
|
489
489
|
return s(r);
|
|
490
|
-
if ((!r || r === n.rawData) && (r = { ...n.rawData }), re(
|
|
491
|
-
return (
|
|
492
|
-
let
|
|
493
|
-
const
|
|
494
|
-
if (
|
|
495
|
-
return s({ ...r, ...
|
|
496
|
-
const
|
|
497
|
-
if (
|
|
490
|
+
if ((!r || r === n.rawData) && (r = { ...n.rawData }), re(l.pattern))
|
|
491
|
+
return (p = this._configService.getConfig(ae)) != null && p.disableTextFormatMark ? (r.t = N.STRING, s(r)) : (r.t = N.STRING, r.markers = { ...r == null ? void 0 : r.markers, ...We }, s(r));
|
|
492
|
+
let y = "";
|
|
493
|
+
const _ = t.getValue(n.row, n.col);
|
|
494
|
+
if (_ && _.parameters === `${f.v}_${l.pattern}`)
|
|
495
|
+
return s({ ...r, ..._.result });
|
|
496
|
+
const h = Ge(l.pattern, Number(f.v), this.local);
|
|
497
|
+
if (y = h.result, !y)
|
|
498
498
|
return s(r);
|
|
499
|
-
const
|
|
500
|
-
if (
|
|
501
|
-
const
|
|
502
|
-
|
|
499
|
+
const C = { v: y, t: N.NUMBER };
|
|
500
|
+
if (h.color) {
|
|
501
|
+
const a = (d = this._themeService.getColorFromTheme(`${h.color}.500`)) != null ? d : h.color;
|
|
502
|
+
a && (C.interceptorStyle = { cl: { rgb: a } });
|
|
503
503
|
}
|
|
504
504
|
return t.setValue(n.row, n.col, {
|
|
505
|
-
result:
|
|
506
|
-
parameters: `${f.v}_${
|
|
507
|
-
}), Object.assign(r,
|
|
505
|
+
result: C,
|
|
506
|
+
parameters: `${f.v}_${l.pattern}`
|
|
507
|
+
}), Object.assign(r, C), s(r);
|
|
508
508
|
},
|
|
509
509
|
priority: Re.NUMFMT
|
|
510
510
|
})), this.disposeWithMe(this._commandService.onCommandExecuted((r) => {
|
|
511
511
|
if (r.id === te.id) {
|
|
512
512
|
const n = r.params;
|
|
513
513
|
Object.keys(n.values).forEach((s) => {
|
|
514
|
-
n.values[s].ranges.forEach((
|
|
515
|
-
I.foreach(
|
|
516
|
-
t.realDeleteValue(
|
|
514
|
+
n.values[s].ranges.forEach((c) => {
|
|
515
|
+
I.foreach(c, (l, f) => {
|
|
516
|
+
t.realDeleteValue(l, f);
|
|
517
517
|
});
|
|
518
518
|
});
|
|
519
519
|
});
|
|
@@ -538,19 +538,19 @@ let D = class extends Q {
|
|
|
538
538
|
}
|
|
539
539
|
};
|
|
540
540
|
D = He([
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
541
|
+
R(0, A),
|
|
542
|
+
R(1, E(Me)),
|
|
543
|
+
R(2, E(fe)),
|
|
544
|
+
R(3, E(T)),
|
|
545
|
+
R(4, E(W)),
|
|
546
|
+
R(5, E(de)),
|
|
547
|
+
R(6, X)
|
|
548
548
|
], D);
|
|
549
549
|
class J extends Q {
|
|
550
550
|
constructor() {
|
|
551
551
|
super(...arguments);
|
|
552
|
-
|
|
553
|
-
|
|
552
|
+
M(this, "_currencySymbol$", new K("US"));
|
|
553
|
+
M(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
554
554
|
}
|
|
555
555
|
/**
|
|
556
556
|
* Set the currency symbol by setting the country code.
|
|
@@ -563,8 +563,8 @@ class J extends Q {
|
|
|
563
563
|
}
|
|
564
564
|
}
|
|
565
565
|
var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t, r) => t in e ? Ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Ze = (e, t, r, n) => {
|
|
566
|
-
for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, o = e.length - 1,
|
|
567
|
-
(
|
|
566
|
+
for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, o = e.length - 1, c; o >= 0; o--)
|
|
567
|
+
(c = e[o]) && (s = c(s) || s);
|
|
568
568
|
return s;
|
|
569
569
|
}, L = (e, t) => (r, n) => t(r, n, e), ce = (e, t, r) => Ye(e, typeof t != "symbol" ? t + "" : t, r);
|
|
570
570
|
let F = class extends pe {
|
|
@@ -594,7 +594,7 @@ let F = class extends pe {
|
|
|
594
594
|
je,
|
|
595
595
|
Fe,
|
|
596
596
|
Ae,
|
|
597
|
-
|
|
597
|
+
w
|
|
598
598
|
].forEach((e) => {
|
|
599
599
|
this.disposeWithMe(this._commandService.registerCommand(e));
|
|
600
600
|
});
|
|
@@ -612,21 +612,21 @@ const nt = (e) => ne.find((r) => e.includes(r)), st = () => ne.map((e) => ({ lab
|
|
|
612
612
|
label: t.label(e),
|
|
613
613
|
value: t.suffix(e),
|
|
614
614
|
color: t.color
|
|
615
|
-
})), at = () =>
|
|
615
|
+
})), at = () => Ue.map((e) => ({ label: e.label, value: e.suffix })), ct = () => Oe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
616
616
|
export {
|
|
617
617
|
De as AddDecimalCommand,
|
|
618
618
|
se as CURRENCYFORMAT,
|
|
619
|
-
|
|
619
|
+
Ue as DATEFMTLISG,
|
|
620
620
|
oe as MenuCurrencyService,
|
|
621
621
|
Oe as NUMBERFORMAT,
|
|
622
622
|
ae as SHEETS_NUMFMT_PLUGIN_CONFIG_KEY,
|
|
623
623
|
Fe as SetCurrencyCommand,
|
|
624
|
-
|
|
624
|
+
w as SetNumfmtCommand,
|
|
625
625
|
Ae as SetPercentCommand,
|
|
626
626
|
D as SheetsNumfmtCellContentController,
|
|
627
627
|
je as SubtractDecimalCommand,
|
|
628
628
|
F as UniverSheetsNumfmtPlugin,
|
|
629
|
-
|
|
629
|
+
we as countryCurrencyMap,
|
|
630
630
|
ne as currencySymbols,
|
|
631
631
|
ot as getCurrencyFormatOptions,
|
|
632
632
|
st as getCurrencyOptions,
|
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 de=Object.defineProperty;var ge=(a,t,o)=>t in a?de(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o;var R=(a,t,o)=>ge(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=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},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(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(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:d}=l,c=r.values.filter(u=>!!u.pattern),b=r.values.filter(u=>!u.pattern),M=o.transformCellsToRange(m,S,c),C={unitId:m,subUnitId:S,ranges:b.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],y=[];if(c.length){const u=c.reduce((g,f)=>{A.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const P=o.checkCellValueType(_.v);P!==_.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?h.setValue(g,f,{t:_.t}):h.setValue(g,f,{t:void 0})}),Object.keys(M.values).forEach(g=>{const f=M.values[g];f.ranges=o.rangeMerge(f.ranges)}),T.push({id:o.SetNumfmtMutation.id,params:M});const p=o.factorySetNumfmtUndoMutation(e,M);y.push(...p)}if(b.length){C.ranges=o.rangeMerge(C.ranges);const u=b.reduce((g,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const P=o.checkCellValueType(_.v);P!==_.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?h.setValue(g,f,{t:_.t}):h.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 p=o.factoryRemoveNumfmtUndoMutation(e,C);y.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:h.getMatrix()}},...p)}const v=t.sequenceExecute(T,i).result;return v&&s.pushUndoRedo({unitID:m,undoMutations:y,redoMutations:T}),v}},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:d}=m;let c=0;l.forEach(T=>{t.Range.foreach(T.range,(y,v)=>{const u=n.getValue(S,d,y,v);if(!u){const p=m.worksheet.getCellRaw(y,v);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const g=/\.(\d*)$/.exec(String(p.v));if(g){const f=g[1].length;if(!f)return;c=Math.max(c,f)}}return}const h=E(u.pattern);c=h>c?h:c})});const b=c+1,M=U(`0${b>0?".0":""}`,b),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(y,v)=>{const u=n.getValue(S,d,y,v);if(!u)C.push({row:y,col:v,pattern:M});else{const h=E(u.pattern),p=U(u.pattern,h+1);p!==u.pattern&&C.push({row:y,col:v,pattern:p})}})}),C.length?await r.executeCommand($.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,(b,M)=>{m.push({row:b,col:M,pattern:S,type:"currency"})})}),await r.executeCommand($.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,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.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:d}=m;let c=0;l.forEach(y=>{t.Range.foreach(y.range,(v,u)=>{const h=n.getValue(S,d,v,u);if(!h){const g=m.worksheet.getCellRaw(v,u);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(h.pattern);c=p>c?p:c})});const b=c-1,M=U(`0${b>0?".0":"."}`,b),C=[];return l.forEach(y=>{t.Range.foreach(y.range,(v,u)=>{const h=n.getValue(S,d,v,u);if(!h)C.push({row:v,col:u,pattern:M});else{const p=E(h.pattern);C.push({row:v,col:u,pattern:U(h.pattern,p-1)})}})}),await r.executeCommand($.id,{values:C})}},w="sheets-numfmt.config",K={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,i="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,l=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:l,color:s}:{result:l}},k=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:Y(e,r,i);var te=Object.getOwnPropertyDescriptor,ne=(e,r,i,n)=>{for(var s=n>1?void 0:n?te(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 re={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,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=s,this._commandService=l,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,s,l)=>{var y,v;const m=s.unitId,S=s.subUnitId;let d;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&&(d=u.n)}if(d||(d=this._numfmtService.getValue(m,S,s.row,s.col)),!d||d.pattern==="General"||c.t!==t.CellValueType.NUMBER&&o.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),A.isTextFormat(d.pattern))return(y=this._configService.getConfig(w))!=null&&y.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...re},l(n));let b="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${c.v}_${d.pattern}`)return l({...n,...M.result});const C=k(d.pattern,Number(c.v),this.local);if(b=C.result,!b)return l(n);const T={v:b,t:t.CellValueType.NUMBER};if(C.color){const u=(v=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?v:C.color;u&&(T.interceptorStyle={cl:{rgb:u}})}return i.setValue(s.row,s.col,{result:T,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,T),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,(d,c)=>{i.realDeleteValue(d,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=ne([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,ie=Object.getOwnPropertyDescriptor,se=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,le=(e,r,i,n)=>{for(var s=n>1?void 0:n?ie(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)=>se(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,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=le([t.DependentOn(o.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ue=e=>O.find(i=>e.includes(i)),ce=()=>O.map(e=>({label:e,value:e})),oe=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>G.map(e=>({label:e.label,value:e.suffix})),fe=()=>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=$,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=oe,a.getCurrencyOptions=ce,a.getCurrencyType=ue,a.getDateFormatOptions=me,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=fe,a.getPatternPreview=Y,a.getPatternPreviewIgnoreGeneral=k,a.getPatternType=ee,a.isPatternHasDecimal=Q,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,u,A,I,J){"use strict";var de=Object.defineProperty;var ge=(a,t,u)=>t in a?de(a,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):a[t]=u;var R=(a,t,u)=>ge(a,typeof t!="symbol"?t+"":t,u);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=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},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(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(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=u.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:v,worksheet:d}=l,c=r.values.filter(o=>!!o.pattern),T=r.values.filter(o=>!o.pattern),M=u.transformCellsToRange(m,v,c),y={unitId:m,subUnitId:v,ranges:T.map(o=>({startColumn:o.col,startRow:o.row,endColumn:o.col,endRow:o.row}))},b=[],h=[];if(c.length){const o=c.reduce((S,f)=>{A.isTextFormat(f.pattern)&&S.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const P=u.checkCellValueType(_.v);P!==_.t&&S.setValue(f.row,f.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),g=new t.ObjectMatrix;new t.ObjectMatrix(o).forValue((S,f)=>{const _=d.getCellRaw(S,f);_?g.setValue(S,f,{t:_.t}):g.setValue(S,f,{t:void 0})}),Object.keys(M.values).forEach(S=>{const f=M.values[S];f.ranges=u.rangeMerge(f.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const p=u.factorySetNumfmtUndoMutation(e,M);h.push(...p)}if(T.length){y.ranges=u.rangeMerge(y.ranges);const o=T.reduce((S,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const P=u.checkCellValueType(_.v);P!==_.t&&S.setValue(f.row,f.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),g=new t.ObjectMatrix;new t.ObjectMatrix(o).forValue((S,f)=>{const _=d.getCellRaw(S,f);_?g.setValue(S,f,{t:_.t}):g.setValue(S,f,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:v,cellValue:o}});const p=u.factoryRemoveNumfmtUndoMutation(e,y);h.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:v,cellValue:g.getMatrix()}},...p)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:h,redoMutations:b}),C}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:v,subUnitId:d}=m;let c=0;l.forEach(b=>{t.Range.foreach(b.range,(h,C)=>{const o=n.getValue(v,d,h,C);if(!o){const p=m.worksheet.getCellRaw(h,C);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const S=/\.(\d*)$/.exec(String(p.v));if(S){const f=S[1].length;if(!f)return;c=Math.max(c,f)}}return}const g=E(o.pattern);c=g>c?g:c})});const T=c+1,M=U(`0${T>0?".0":""}`,T),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(h,C)=>{const o=n.getValue(v,d,h,C);if(!o)y.push({row:h,col:C,pattern:M});else{const g=E(o.pattern),p=U(o.pattern,g+1);p!==o.pattern&&y.push({row:h,col:C,pattern:p})}})}),y.length?await r.executeCommand($.id,{values:y}):!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(u.SheetsSelectionsService),n=e.get(j),s=L[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],v=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(T,M)=>{m.push({row:T,col:M,pattern:v,type:"currency"})})}),await r.executeCommand($.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(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(v=>{t.Range.foreach(v.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.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(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:v,subUnitId:d}=m;let c=0;l.forEach(h=>{t.Range.foreach(h.range,(C,o)=>{const g=n.getValue(v,d,C,o);if(!g){const S=m.worksheet.getCellRaw(C,o);if(!c&&S&&S.t===t.CellValueType.NUMBER&&S.v){const f=/\.(\d*)$/.exec(String(S.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(g.pattern);c=p>c?p:c})});const T=c-1,M=U(`0${T>0?".0":"."}`,T),y=[];return l.forEach(h=>{t.Range.foreach(h.range,(C,o)=>{const g=n.getValue(v,d,C,o);if(!g)y.push({row:C,col:o,pattern:M});else{const p=E(g.pattern);y.push({row:C,col:o,pattern:U(g.pattern,p-1)})}})}),await r.executeCommand($.id,{values:y})}},w="sheets-numfmt.config",K={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,i="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,l=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:l,color:s}:{result:l}},k=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:Y(e,r,i);var te=Object.getOwnPropertyDescriptor,ne=(e,r,i,n)=>{for(var s=n>1?void 0:n?te(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 re={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,v,d){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=v,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(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var C,o;const m=s.unitId,v=s.subUnitId;let d;const c=n;if(!c||c.v===void 0||c.v===null)return l(n);if(n!=null&&n.s){const g=s.workbook.getStyles().get(n.s);g!=null&&g.n&&(d=g.n)}if(d||(d=this._numfmtService.getValue(m,v,s.row,s.col)),!d||d.pattern==="General"||u.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),A.isTextFormat(d.pattern))return(C=this._configService.getConfig(w))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...re},l(n));let M="";const y=i.getValue(s.row,s.col);if(y&&y.parameters===`${c.v}_${d.pattern}`)return l({...n,...y.result});const b=k(d.pattern,Number(c.v),this.local);if(M=b.result,!M)return l(n);const h={v:M,t:t.CellValueType.NUMBER};if(b.color){const g=(o=this._themeService.getColorFromTheme(`${b.color}.500`))!=null?o:b.color;g&&(h.interceptorStyle={cl:{rgb:g}})}return i.setValue(s.row,s.col,{result:h,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,h),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(v=>{t.Range.foreach(v,(d,c)=>{i.realDeleteValue(d,c)})})})}else if(n.id===u.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=ne([N(0,t.IUniverInstanceService),N(1,t.Inject(u.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(u.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,ie=Object.getOwnPropertyDescriptor,se=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,le=(e,r,i,n)=>{for(var s=n>1?void 0:n?ie(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)=>se(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,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ue=e=>O.find(i=>e.includes(i)),ce=()=>O.map(e=>({label:e,value:e})),oe=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>G.map(e=>({label:e.label,value:e.suffix})),fe=()=>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=$,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=oe,a.getCurrencyOptions=ce,a.getCurrencyType=ue,a.getDateFormatOptions=me,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=fe,a.getPatternPreview=Y,a.getPatternPreviewIgnoreGeneral=k,a.getPatternType=ee,a.isPatternHasDecimal=Q,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|