@univerjs/sheets-numfmt 1.0.0-alpha.0 → 1.0.0-alpha.2

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  let _univerjs_core = require("@univerjs/core");
3
3
  let _univerjs_sheets = require("@univerjs/sheets");
4
- let rxjs = require("rxjs");
5
4
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
5
+ let rxjs = require("rxjs");
6
6
 
7
7
  //#region src/base/const/currency-symbols.ts
8
8
  /**
@@ -258,6 +258,48 @@ const setPatternDecimal = (patterns, decimalLength) => {
258
258
  };
259
259
  const isPatternHasDecimal = (pattern) => /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern);
260
260
 
261
+ //#endregion
262
+ //#region src/utils/pattern.ts
263
+ const getPatternType = (pattern) => _univerjs_core.numfmt.getFormatInfo(pattern).type || "unknown";
264
+ const getPatternPreview = (pattern, value, locale = "en") => {
265
+ try {
266
+ const formatColor = _univerjs_core.numfmt.formatColor(pattern, value);
267
+ const color = formatColor ? String(formatColor) : void 0;
268
+ const result = _univerjs_core.numfmt.format(pattern, value, {
269
+ locale,
270
+ throws: false
271
+ });
272
+ if (value < 0) return {
273
+ result,
274
+ color
275
+ };
276
+ return { result };
277
+ } catch (e) {
278
+ console.warn("getPatternPreview error:", pattern, e);
279
+ }
280
+ return { result: String(value) };
281
+ };
282
+ const getPatternPreviewIgnoreGeneral = (pattern, value, locale) => {
283
+ if (pattern === _univerjs_core.DEFAULT_NUMBER_FORMAT) return { result: String((0, _univerjs_engine_formula.stripErrorMargin)(value)) };
284
+ return getPatternPreview(pattern, value, locale);
285
+ };
286
+
287
+ //#endregion
288
+ //#region src/utils/scientific-notation.ts
289
+ function isScientificNotationNumericCell(cell) {
290
+ return (cell === null || cell === void 0 ? void 0 : cell.t) === _univerjs_core.CellValueType.NUMBER && cell.v !== void 0 && cell.v !== null && /e/i.test(String(cell.v));
291
+ }
292
+ function getScientificNotationFormatFromCell(cell) {
293
+ const text = String(cell === null || cell === void 0 ? void 0 : cell.v);
294
+ const eIndex = text.search(/e/i);
295
+ const decimalIndex = text.indexOf(".");
296
+ const decimalLength = eIndex > -1 && decimalIndex > -1 ? eIndex - decimalIndex - 1 : 0;
297
+ return `0.${"0".repeat(Math.max(2, decimalLength))}E+00`;
298
+ }
299
+ function isAllowedPatternForScientificNotationNumber(pattern) {
300
+ return (0, _univerjs_core.isDefaultFormat)(pattern) || (0, _univerjs_core.isTextFormat)(pattern) || getPatternType(pattern) === "scientific";
301
+ }
302
+
261
303
  //#endregion
262
304
  //#region src/commands/commands/set-numfmt.command.ts
263
305
  const SetNumfmtCommand = {
@@ -271,8 +313,12 @@ const SetNumfmtCommand = {
271
313
  const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, params);
272
314
  if (!target) return false;
273
315
  const { unitId, subUnitId, worksheet } = target;
274
- const setCells = params.values.filter((value) => !!value.pattern);
275
- const removeCells = params.values.filter((value) => !value.pattern);
316
+ const values = params.values.filter((value) => {
317
+ return !isScientificNotationNumericCell(worksheet.getCellRaw(value.row, value.col)) || isAllowedPatternForScientificNotationNumber(value.pattern);
318
+ });
319
+ const setCells = values.filter((value) => !!value.pattern);
320
+ const removeCells = values.filter((value) => !value.pattern);
321
+ if (!setCells.length && !removeCells.length) return false;
276
322
  const setRedos = (0, _univerjs_sheets.transformCellsToRange)(unitId, subUnitId, setCells);
277
323
  const removeRedos = {
278
324
  unitId,
@@ -381,6 +427,10 @@ const AddDecimalCommand = {
381
427
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
382
428
  if (!numfmtValue) {
383
429
  const cell = target.worksheet.getCellRaw(row, col);
430
+ if (isScientificNotationNumericCell(cell)) {
431
+ maxDecimals = Math.max(maxDecimals, getDecimalFromPattern(getScientificNotationFormatFromCell(cell)));
432
+ return;
433
+ }
384
434
  if (!maxDecimals && cell && cell.t === _univerjs_core.CellValueType.NUMBER && cell.v) {
385
435
  const regResult = /\.(\d*)$/.exec(String(cell.v));
386
436
  if (regResult) {
@@ -401,12 +451,14 @@ const AddDecimalCommand = {
401
451
  selections.forEach((selection) => {
402
452
  _univerjs_core.Range.foreach(selection.range, (row, col) => {
403
453
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
404
- if ((0, _univerjs_core.isDefaultFormat)(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) values.push({
405
- row,
406
- col,
407
- pattern: defaultPattern
408
- });
409
- else {
454
+ if ((0, _univerjs_core.isDefaultFormat)(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) {
455
+ const cell = target.worksheet.getCellRaw(row, col);
456
+ values.push({
457
+ row,
458
+ col,
459
+ pattern: isScientificNotationNumericCell(cell) ? setPatternDecimal(getScientificNotationFormatFromCell(cell), decimals) : defaultPattern
460
+ });
461
+ } else {
410
462
  const decimals = getDecimalFromPattern(numfmtValue.pattern);
411
463
  const pattern = setPatternDecimal(numfmtValue.pattern, decimals + 1);
412
464
  pattern !== numfmtValue.pattern && values.push({
@@ -499,6 +551,10 @@ const SubtractDecimalCommand = {
499
551
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
500
552
  if (!numfmtValue) {
501
553
  const cell = target.worksheet.getCellRaw(row, col);
554
+ if (isScientificNotationNumericCell(cell)) {
555
+ maxDecimals = Math.max(maxDecimals, getDecimalFromPattern(getScientificNotationFormatFromCell(cell)));
556
+ return;
557
+ }
502
558
  if (!maxDecimals && cell && cell.t === _univerjs_core.CellValueType.NUMBER && cell.v) {
503
559
  const regResult = /\.(\d*)$/.exec(String(cell.v));
504
560
  if (regResult) {
@@ -519,12 +575,14 @@ const SubtractDecimalCommand = {
519
575
  selections.forEach((selection) => {
520
576
  _univerjs_core.Range.foreach(selection.range, (row, col) => {
521
577
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
522
- if ((0, _univerjs_core.isDefaultFormat)(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) values.push({
523
- row,
524
- col,
525
- pattern: defaultPattern
526
- });
527
- else {
578
+ if ((0, _univerjs_core.isDefaultFormat)(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) {
579
+ const cell = target.worksheet.getCellRaw(row, col);
580
+ values.push({
581
+ row,
582
+ col,
583
+ pattern: isScientificNotationNumericCell(cell) ? setPatternDecimal(getScientificNotationFormatFromCell(cell), decimals) : defaultPattern
584
+ });
585
+ } else {
528
586
  const decimals = getDecimalFromPattern(numfmtValue.pattern);
529
587
  values.push({
530
588
  row,
@@ -559,32 +617,6 @@ const SHEETS_NUMFMT_PLUGIN_CONFIG_KEY = "sheets-numfmt.config";
559
617
  const configSymbol = Symbol(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY);
560
618
  const defaultPluginConfig = {};
561
619
 
562
- //#endregion
563
- //#region src/utils/pattern.ts
564
- const getPatternType = (pattern) => _univerjs_core.numfmt.getFormatInfo(pattern).type || "unknown";
565
- const getPatternPreview = (pattern, value, locale = "en") => {
566
- try {
567
- const formatColor = _univerjs_core.numfmt.formatColor(pattern, value);
568
- const color = formatColor ? String(formatColor) : void 0;
569
- const result = _univerjs_core.numfmt.format(pattern, value, {
570
- locale,
571
- throws: false
572
- });
573
- if (value < 0) return {
574
- result,
575
- color
576
- };
577
- return { result };
578
- } catch (e) {
579
- console.warn("getPatternPreview error:", pattern, e);
580
- }
581
- return { result: String(value) };
582
- };
583
- const getPatternPreviewIgnoreGeneral = (pattern, value, locale) => {
584
- if (pattern === _univerjs_core.DEFAULT_NUMBER_FORMAT) return { result: String((0, _univerjs_engine_formula.stripErrorMargin)(value)) };
585
- return getPatternPreview(pattern, value, locale);
586
- };
587
-
588
620
  //#endregion
589
621
  //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
590
622
  function _typeof(o) {
@@ -792,7 +824,7 @@ SheetsNumfmtCellContentController = __decorate([
792
824
  //#endregion
793
825
  //#region package.json
794
826
  var name = "@univerjs/sheets-numfmt";
795
- var version = "1.0.0-alpha.0";
827
+ var version = "1.0.0-alpha.2";
796
828
 
797
829
  //#endregion
798
830
  //#region src/base/const/plugin-name.ts
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CellValueType, CommandType, DEFAULT_NUMBER_FORMAT, DependentOn, Disposable, ICommandService, IConfigService, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, LocaleType, ObjectMatrix, Plugin, Range, ThemeService, UniverInstanceType, currencySymbols, isDefaultFormat, isTextFormat, merge, numfmt, registerDependencies, sequenceExecute, touchDependencies } from "@univerjs/core";
2
2
  import { INTERCEPTOR_POINT, INumfmtService, InterceptCellContentPriority, RemoveNumfmtMutation, SetNumfmtMutation, SetRangeValuesMutation, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, checkCellValueType, factoryRemoveNumfmtUndoMutation, factorySetNumfmtUndoMutation, getSheetCommandTarget, rangeMerge, transformCellsToRange } from "@univerjs/sheets";
3
- import { BehaviorSubject, merge as merge$1, of, skip, switchMap } from "rxjs";
4
3
  import { stripErrorMargin } from "@univerjs/engine-formula";
4
+ import { BehaviorSubject, merge as merge$1, of, skip, switchMap } from "rxjs";
5
5
 
6
6
  //#region src/base/const/currency-symbols.ts
7
7
  /**
@@ -257,6 +257,48 @@ const setPatternDecimal = (patterns, decimalLength) => {
257
257
  };
258
258
  const isPatternHasDecimal = (pattern) => /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern);
259
259
 
260
+ //#endregion
261
+ //#region src/utils/pattern.ts
262
+ const getPatternType = (pattern) => numfmt.getFormatInfo(pattern).type || "unknown";
263
+ const getPatternPreview = (pattern, value, locale = "en") => {
264
+ try {
265
+ const formatColor = numfmt.formatColor(pattern, value);
266
+ const color = formatColor ? String(formatColor) : void 0;
267
+ const result = numfmt.format(pattern, value, {
268
+ locale,
269
+ throws: false
270
+ });
271
+ if (value < 0) return {
272
+ result,
273
+ color
274
+ };
275
+ return { result };
276
+ } catch (e) {
277
+ console.warn("getPatternPreview error:", pattern, e);
278
+ }
279
+ return { result: String(value) };
280
+ };
281
+ const getPatternPreviewIgnoreGeneral = (pattern, value, locale) => {
282
+ if (pattern === DEFAULT_NUMBER_FORMAT) return { result: String(stripErrorMargin(value)) };
283
+ return getPatternPreview(pattern, value, locale);
284
+ };
285
+
286
+ //#endregion
287
+ //#region src/utils/scientific-notation.ts
288
+ function isScientificNotationNumericCell(cell) {
289
+ return (cell === null || cell === void 0 ? void 0 : cell.t) === CellValueType.NUMBER && cell.v !== void 0 && cell.v !== null && /e/i.test(String(cell.v));
290
+ }
291
+ function getScientificNotationFormatFromCell(cell) {
292
+ const text = String(cell === null || cell === void 0 ? void 0 : cell.v);
293
+ const eIndex = text.search(/e/i);
294
+ const decimalIndex = text.indexOf(".");
295
+ const decimalLength = eIndex > -1 && decimalIndex > -1 ? eIndex - decimalIndex - 1 : 0;
296
+ return `0.${"0".repeat(Math.max(2, decimalLength))}E+00`;
297
+ }
298
+ function isAllowedPatternForScientificNotationNumber(pattern) {
299
+ return isDefaultFormat(pattern) || isTextFormat(pattern) || getPatternType(pattern) === "scientific";
300
+ }
301
+
260
302
  //#endregion
261
303
  //#region src/commands/commands/set-numfmt.command.ts
262
304
  const SetNumfmtCommand = {
@@ -270,8 +312,12 @@ const SetNumfmtCommand = {
270
312
  const target = getSheetCommandTarget(univerInstanceService, params);
271
313
  if (!target) return false;
272
314
  const { unitId, subUnitId, worksheet } = target;
273
- const setCells = params.values.filter((value) => !!value.pattern);
274
- const removeCells = params.values.filter((value) => !value.pattern);
315
+ const values = params.values.filter((value) => {
316
+ return !isScientificNotationNumericCell(worksheet.getCellRaw(value.row, value.col)) || isAllowedPatternForScientificNotationNumber(value.pattern);
317
+ });
318
+ const setCells = values.filter((value) => !!value.pattern);
319
+ const removeCells = values.filter((value) => !value.pattern);
320
+ if (!setCells.length && !removeCells.length) return false;
275
321
  const setRedos = transformCellsToRange(unitId, subUnitId, setCells);
276
322
  const removeRedos = {
277
323
  unitId,
@@ -380,6 +426,10 @@ const AddDecimalCommand = {
380
426
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
381
427
  if (!numfmtValue) {
382
428
  const cell = target.worksheet.getCellRaw(row, col);
429
+ if (isScientificNotationNumericCell(cell)) {
430
+ maxDecimals = Math.max(maxDecimals, getDecimalFromPattern(getScientificNotationFormatFromCell(cell)));
431
+ return;
432
+ }
383
433
  if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
384
434
  const regResult = /\.(\d*)$/.exec(String(cell.v));
385
435
  if (regResult) {
@@ -400,12 +450,14 @@ const AddDecimalCommand = {
400
450
  selections.forEach((selection) => {
401
451
  Range.foreach(selection.range, (row, col) => {
402
452
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
403
- if (isDefaultFormat(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) values.push({
404
- row,
405
- col,
406
- pattern: defaultPattern
407
- });
408
- else {
453
+ if (isDefaultFormat(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) {
454
+ const cell = target.worksheet.getCellRaw(row, col);
455
+ values.push({
456
+ row,
457
+ col,
458
+ pattern: isScientificNotationNumericCell(cell) ? setPatternDecimal(getScientificNotationFormatFromCell(cell), decimals) : defaultPattern
459
+ });
460
+ } else {
409
461
  const decimals = getDecimalFromPattern(numfmtValue.pattern);
410
462
  const pattern = setPatternDecimal(numfmtValue.pattern, decimals + 1);
411
463
  pattern !== numfmtValue.pattern && values.push({
@@ -498,6 +550,10 @@ const SubtractDecimalCommand = {
498
550
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
499
551
  if (!numfmtValue) {
500
552
  const cell = target.worksheet.getCellRaw(row, col);
553
+ if (isScientificNotationNumericCell(cell)) {
554
+ maxDecimals = Math.max(maxDecimals, getDecimalFromPattern(getScientificNotationFormatFromCell(cell)));
555
+ return;
556
+ }
501
557
  if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
502
558
  const regResult = /\.(\d*)$/.exec(String(cell.v));
503
559
  if (regResult) {
@@ -518,12 +574,14 @@ const SubtractDecimalCommand = {
518
574
  selections.forEach((selection) => {
519
575
  Range.foreach(selection.range, (row, col) => {
520
576
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
521
- if (isDefaultFormat(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) values.push({
522
- row,
523
- col,
524
- pattern: defaultPattern
525
- });
526
- else {
577
+ if (isDefaultFormat(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) {
578
+ const cell = target.worksheet.getCellRaw(row, col);
579
+ values.push({
580
+ row,
581
+ col,
582
+ pattern: isScientificNotationNumericCell(cell) ? setPatternDecimal(getScientificNotationFormatFromCell(cell), decimals) : defaultPattern
583
+ });
584
+ } else {
527
585
  const decimals = getDecimalFromPattern(numfmtValue.pattern);
528
586
  values.push({
529
587
  row,
@@ -558,32 +616,6 @@ const SHEETS_NUMFMT_PLUGIN_CONFIG_KEY = "sheets-numfmt.config";
558
616
  const configSymbol = Symbol(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY);
559
617
  const defaultPluginConfig = {};
560
618
 
561
- //#endregion
562
- //#region src/utils/pattern.ts
563
- const getPatternType = (pattern) => numfmt.getFormatInfo(pattern).type || "unknown";
564
- const getPatternPreview = (pattern, value, locale = "en") => {
565
- try {
566
- const formatColor = numfmt.formatColor(pattern, value);
567
- const color = formatColor ? String(formatColor) : void 0;
568
- const result = numfmt.format(pattern, value, {
569
- locale,
570
- throws: false
571
- });
572
- if (value < 0) return {
573
- result,
574
- color
575
- };
576
- return { result };
577
- } catch (e) {
578
- console.warn("getPatternPreview error:", pattern, e);
579
- }
580
- return { result: String(value) };
581
- };
582
- const getPatternPreviewIgnoreGeneral = (pattern, value, locale) => {
583
- if (pattern === DEFAULT_NUMBER_FORMAT) return { result: String(stripErrorMargin(value)) };
584
- return getPatternPreview(pattern, value, locale);
585
- };
586
-
587
619
  //#endregion
588
620
  //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
589
621
  function _typeof(o) {
@@ -791,7 +823,7 @@ SheetsNumfmtCellContentController = __decorate([
791
823
  //#endregion
792
824
  //#region package.json
793
825
  var name = "@univerjs/sheets-numfmt";
794
- var version = "1.0.0-alpha.0";
826
+ var version = "1.0.0-alpha.2";
795
827
 
796
828
  //#endregion
797
829
  //#region src/base/const/plugin-name.ts
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CellValueType, CommandType, DEFAULT_NUMBER_FORMAT, DependentOn, Disposable, ICommandService, IConfigService, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, LocaleType, ObjectMatrix, Plugin, Range, ThemeService, UniverInstanceType, currencySymbols, isDefaultFormat, isTextFormat, merge, numfmt, registerDependencies, sequenceExecute, touchDependencies } from "@univerjs/core";
2
2
  import { INTERCEPTOR_POINT, INumfmtService, InterceptCellContentPriority, RemoveNumfmtMutation, SetNumfmtMutation, SetRangeValuesMutation, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, checkCellValueType, factoryRemoveNumfmtUndoMutation, factorySetNumfmtUndoMutation, getSheetCommandTarget, rangeMerge, transformCellsToRange } from "@univerjs/sheets";
3
- import { BehaviorSubject, merge as merge$1, of, skip, switchMap } from "rxjs";
4
3
  import { stripErrorMargin } from "@univerjs/engine-formula";
4
+ import { BehaviorSubject, merge as merge$1, of, skip, switchMap } from "rxjs";
5
5
 
6
6
  //#region src/base/const/currency-symbols.ts
7
7
  /**
@@ -257,6 +257,48 @@ const setPatternDecimal = (patterns, decimalLength) => {
257
257
  };
258
258
  const isPatternHasDecimal = (pattern) => /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern);
259
259
 
260
+ //#endregion
261
+ //#region src/utils/pattern.ts
262
+ const getPatternType = (pattern) => numfmt.getFormatInfo(pattern).type || "unknown";
263
+ const getPatternPreview = (pattern, value, locale = "en") => {
264
+ try {
265
+ const formatColor = numfmt.formatColor(pattern, value);
266
+ const color = formatColor ? String(formatColor) : void 0;
267
+ const result = numfmt.format(pattern, value, {
268
+ locale,
269
+ throws: false
270
+ });
271
+ if (value < 0) return {
272
+ result,
273
+ color
274
+ };
275
+ return { result };
276
+ } catch (e) {
277
+ console.warn("getPatternPreview error:", pattern, e);
278
+ }
279
+ return { result: String(value) };
280
+ };
281
+ const getPatternPreviewIgnoreGeneral = (pattern, value, locale) => {
282
+ if (pattern === DEFAULT_NUMBER_FORMAT) return { result: String(stripErrorMargin(value)) };
283
+ return getPatternPreview(pattern, value, locale);
284
+ };
285
+
286
+ //#endregion
287
+ //#region src/utils/scientific-notation.ts
288
+ function isScientificNotationNumericCell(cell) {
289
+ return (cell === null || cell === void 0 ? void 0 : cell.t) === CellValueType.NUMBER && cell.v !== void 0 && cell.v !== null && /e/i.test(String(cell.v));
290
+ }
291
+ function getScientificNotationFormatFromCell(cell) {
292
+ const text = String(cell === null || cell === void 0 ? void 0 : cell.v);
293
+ const eIndex = text.search(/e/i);
294
+ const decimalIndex = text.indexOf(".");
295
+ const decimalLength = eIndex > -1 && decimalIndex > -1 ? eIndex - decimalIndex - 1 : 0;
296
+ return `0.${"0".repeat(Math.max(2, decimalLength))}E+00`;
297
+ }
298
+ function isAllowedPatternForScientificNotationNumber(pattern) {
299
+ return isDefaultFormat(pattern) || isTextFormat(pattern) || getPatternType(pattern) === "scientific";
300
+ }
301
+
260
302
  //#endregion
261
303
  //#region src/commands/commands/set-numfmt.command.ts
262
304
  const SetNumfmtCommand = {
@@ -270,8 +312,12 @@ const SetNumfmtCommand = {
270
312
  const target = getSheetCommandTarget(univerInstanceService, params);
271
313
  if (!target) return false;
272
314
  const { unitId, subUnitId, worksheet } = target;
273
- const setCells = params.values.filter((value) => !!value.pattern);
274
- const removeCells = params.values.filter((value) => !value.pattern);
315
+ const values = params.values.filter((value) => {
316
+ return !isScientificNotationNumericCell(worksheet.getCellRaw(value.row, value.col)) || isAllowedPatternForScientificNotationNumber(value.pattern);
317
+ });
318
+ const setCells = values.filter((value) => !!value.pattern);
319
+ const removeCells = values.filter((value) => !value.pattern);
320
+ if (!setCells.length && !removeCells.length) return false;
275
321
  const setRedos = transformCellsToRange(unitId, subUnitId, setCells);
276
322
  const removeRedos = {
277
323
  unitId,
@@ -380,6 +426,10 @@ const AddDecimalCommand = {
380
426
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
381
427
  if (!numfmtValue) {
382
428
  const cell = target.worksheet.getCellRaw(row, col);
429
+ if (isScientificNotationNumericCell(cell)) {
430
+ maxDecimals = Math.max(maxDecimals, getDecimalFromPattern(getScientificNotationFormatFromCell(cell)));
431
+ return;
432
+ }
383
433
  if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
384
434
  const regResult = /\.(\d*)$/.exec(String(cell.v));
385
435
  if (regResult) {
@@ -400,12 +450,14 @@ const AddDecimalCommand = {
400
450
  selections.forEach((selection) => {
401
451
  Range.foreach(selection.range, (row, col) => {
402
452
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
403
- if (isDefaultFormat(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) values.push({
404
- row,
405
- col,
406
- pattern: defaultPattern
407
- });
408
- else {
453
+ if (isDefaultFormat(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) {
454
+ const cell = target.worksheet.getCellRaw(row, col);
455
+ values.push({
456
+ row,
457
+ col,
458
+ pattern: isScientificNotationNumericCell(cell) ? setPatternDecimal(getScientificNotationFormatFromCell(cell), decimals) : defaultPattern
459
+ });
460
+ } else {
409
461
  const decimals = getDecimalFromPattern(numfmtValue.pattern);
410
462
  const pattern = setPatternDecimal(numfmtValue.pattern, decimals + 1);
411
463
  pattern !== numfmtValue.pattern && values.push({
@@ -498,6 +550,10 @@ const SubtractDecimalCommand = {
498
550
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
499
551
  if (!numfmtValue) {
500
552
  const cell = target.worksheet.getCellRaw(row, col);
553
+ if (isScientificNotationNumericCell(cell)) {
554
+ maxDecimals = Math.max(maxDecimals, getDecimalFromPattern(getScientificNotationFormatFromCell(cell)));
555
+ return;
556
+ }
501
557
  if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
502
558
  const regResult = /\.(\d*)$/.exec(String(cell.v));
503
559
  if (regResult) {
@@ -518,12 +574,14 @@ const SubtractDecimalCommand = {
518
574
  selections.forEach((selection) => {
519
575
  Range.foreach(selection.range, (row, col) => {
520
576
  const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
521
- if (isDefaultFormat(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) values.push({
522
- row,
523
- col,
524
- pattern: defaultPattern
525
- });
526
- else {
577
+ if (isDefaultFormat(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) {
578
+ const cell = target.worksheet.getCellRaw(row, col);
579
+ values.push({
580
+ row,
581
+ col,
582
+ pattern: isScientificNotationNumericCell(cell) ? setPatternDecimal(getScientificNotationFormatFromCell(cell), decimals) : defaultPattern
583
+ });
584
+ } else {
527
585
  const decimals = getDecimalFromPattern(numfmtValue.pattern);
528
586
  values.push({
529
587
  row,
@@ -558,32 +616,6 @@ const SHEETS_NUMFMT_PLUGIN_CONFIG_KEY = "sheets-numfmt.config";
558
616
  const configSymbol = Symbol(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY);
559
617
  const defaultPluginConfig = {};
560
618
 
561
- //#endregion
562
- //#region src/utils/pattern.ts
563
- const getPatternType = (pattern) => numfmt.getFormatInfo(pattern).type || "unknown";
564
- const getPatternPreview = (pattern, value, locale = "en") => {
565
- try {
566
- const formatColor = numfmt.formatColor(pattern, value);
567
- const color = formatColor ? String(formatColor) : void 0;
568
- const result = numfmt.format(pattern, value, {
569
- locale,
570
- throws: false
571
- });
572
- if (value < 0) return {
573
- result,
574
- color
575
- };
576
- return { result };
577
- } catch (e) {
578
- console.warn("getPatternPreview error:", pattern, e);
579
- }
580
- return { result: String(value) };
581
- };
582
- const getPatternPreviewIgnoreGeneral = (pattern, value, locale) => {
583
- if (pattern === DEFAULT_NUMBER_FORMAT) return { result: String(stripErrorMargin(value)) };
584
- return getPatternPreview(pattern, value, locale);
585
- };
586
-
587
619
  //#endregion
588
620
  //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
589
621
  function _typeof(o) {
@@ -791,7 +823,7 @@ SheetsNumfmtCellContentController = __decorate([
791
823
  //#endregion
792
824
  //#region package.json
793
825
  var name = "@univerjs/sheets-numfmt";
794
- var version = "1.0.0-alpha.0";
826
+ var version = "1.0.0-alpha.2";
795
827
 
796
828
  //#endregion
797
829
  //#region src/base/const/plugin-name.ts
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ICellData, Nullable } from '@univerjs/core';
17
+ export declare const DEFAULT_SCIENTIFIC_NOTATION_FORMAT = "0.00E+00";
18
+ export declare function isScientificNotationNumericCell(cell: Nullable<ICellData>): boolean;
19
+ export declare function getScientificNotationFormatFromCell(cell: Nullable<ICellData>): string;
20
+ export declare function isAllowedPatternForScientificNotationNumber(pattern?: string): boolean;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`rxjs`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNumfmt={},e.UniverCore,e.UniverSheets,e.rxjs,e.UniverEngineFormula))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let a=new Map([[t.LocaleType.EN_US,`$`],[t.LocaleType.RU_RU,`₽`],[t.LocaleType.VI_VN,`₫`],[t.LocaleType.ZH_CN,`¥`],[t.LocaleType.ZH_TW,`NT$`],[t.LocaleType.ZH_HK,`HK$`],[t.LocaleType.FR_FR,`€`],[t.LocaleType.FA_IR,`﷼`],[t.LocaleType.KO_KR,`₩`],[t.LocaleType.ES_ES,`€`],[t.LocaleType.CA_ES,`€`],[t.LocaleType.SK_SK,`€`],[t.LocaleType.JA_JP,`¥`],[t.LocaleType.PT_BR,`R$`],[t.LocaleType.DE_DE,`€`],[t.LocaleType.IT_IT,`€`],[t.LocaleType.ID_ID,`Rp`],[t.LocaleType.PL_PL,`zł`],[t.LocaleType.AR_SA,`﷼`]]);function o(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.DE_DE:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:case t.LocaleType.IT_IT:case t.LocaleType.SK_SK:return{icon:`EuroIcon`,symbol:a.get(e)||`€`,locale:e};case t.LocaleType.RU_RU:return{icon:`RoubleIcon`,symbol:a.get(e)||`₽`,locale:e};case t.LocaleType.JA_JP:case t.LocaleType.ZH_CN:return{icon:`RmbIcon`,symbol:a.get(e)||`¥`,locale:e};case t.LocaleType.AR_SA:case t.LocaleType.EN_US:case t.LocaleType.FA_IR:case t.LocaleType.ID_ID:case t.LocaleType.KO_KR:case t.LocaleType.PL_PL:case t.LocaleType.PT_BR:case t.LocaleType.VI_VN:case t.LocaleType.ZH_HK:case t.LocaleType.ZH_TW:default:return{icon:`DollarIcon`,symbol:a.get(e)||`$`,locale:e}}}function s(e){return a.get(e)||`$`}function c(e,t=2){let n=t;t>127&&(n=127);let r=``;return n>0&&(r=`.${`0`.repeat(n)}`),`"${s(e)}"#,##0${r}_);[Red]("${s(e)}"#,##0${r})`}let l=[{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`}],u=[{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`}],d=[{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`}],f=(e,n=0)=>{var r;return e?(r=t.numfmt.getFormatInfo(e).maxDecimals)==null?n:r:n},p=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),m=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${p(Number(t||0))}`):/0([^0]?)|0$/.test(e)?e.replace(/0([^0]+)|0$/,`0${t>0?`.`:``}${p(Number(t||0))}$1`):e).join(`;`),h=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),g={id:`sheet.command.numfmt.set.numfmt`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUniverInstanceService),o=e.get(t.IUndoRedoService),s=(0,n.getSheetCommandTarget)(a,r);if(!s)return!1;let{unitId:c,subUnitId:l,worksheet:u}=s,d=r.values.filter(e=>!!e.pattern),f=r.values.filter(e=>!e.pattern),p=(0,n.transformCellsToRange)(c,l,d),m={unitId:c,subUnitId:l,ranges:f.map(e=>({startColumn:e.col,startRow:e.row,endColumn:e.col,endRow:e.row}))},h=[],g=[];if(d.length){let r=d.reduce((e,r)=>{(0,t.isTextFormat)(r.pattern)&&e.setValue(r.row,r.col,{t:t.CellValueType.STRING});let i=u.getCellRaw(r.row,r.col);if(i){let t=(0,n.checkCellValueType)(i.v);t!==i.t&&e.setValue(r.row,r.col,{t})}return e},new t.ObjectMatrix).getMatrix(),i=new t.ObjectMatrix;new t.ObjectMatrix(r).forValue((e,t)=>{let n=u.getCellRaw(e,t);n?i.setValue(e,t,{t:n.t}):i.setValue(e,t,{t:void 0})}),Object.keys(p.values).forEach(e=>{let t=p.values[e];t.ranges=(0,n.rangeMerge)(t.ranges)}),h.push({id:n.SetNumfmtMutation.id,params:p});let a=(0,n.factorySetNumfmtUndoMutation)(e,p);g.push(...a)}if(f.length){m.ranges=(0,n.rangeMerge)(m.ranges);let r=f.reduce((e,t)=>{let r=u.getCellRaw(t.row,t.col);if(r){let i=(0,n.checkCellValueType)(r.v);i!==r.t&&e.setValue(t.row,t.col,{t:i})}return e},new t.ObjectMatrix).getMatrix(),i=new t.ObjectMatrix;new t.ObjectMatrix(r).forValue((e,t)=>{let n=u.getCellRaw(e,t);n?i.setValue(e,t,{t:n.t}):i.setValue(e,t,{t:void 0})}),h.push({id:n.RemoveNumfmtMutation.id,params:m},{id:n.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:r}});let a=(0,n.factoryRemoveNumfmtUndoMutation)(e,m);g.push({id:n.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:i.getMatrix()}},...a)}let _=(0,t.sequenceExecute)(h,i).result;return _&&o.pushUndoRedo({unitID:c,undoMutations:g,redoMutations:h}),_}},_={id:`sheet.command.numfmt.add.decimal.command`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(n.INumfmtService),o=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,n.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if(!r){let r=c.worksheet.getCellRaw(e,n);if(!d&&r&&r.t===t.CellValueType.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;d=Math.max(d,t)}}return}let i=f(r.pattern);d=i>d?i:d})});let p=d+1,h=m(`0${p>0?`.0`:``}`,p),_=[];return s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if((0,t.isDefaultFormat)(r==null?void 0:r.pattern))_.push({row:e,col:n,pattern:h});else{let t=f(r.pattern),i=m(r.pattern,t+1);i!==r.pattern&&_.push({row:e,col:n,pattern:i})}})}),_.length?await r.executeCommand(g.id,{values:_}):!1}},v={id:`sheet.command.numfmt.set.currency`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(t.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let l=[],u=c(o(a.getCurrentLocale()).locale);return s.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{l.push({row:e,col:t,pattern:u,type:`currency`})})}),await r.executeCommand(g.id,{values:l})}},y={id:`sheet.command.numfmt.set.percent`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService).getCurrentSelections();if(!i||!i.length)return!1;let a=[];return i.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{a.push({row:e,col:t,pattern:`0%`,type:`percent`})})}),await r.executeCommand(g.id,{values:a})}},b={id:`sheet.command.numfmt.subtract.decimal.command`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(n.INumfmtService),o=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,n.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if(!r){let r=c.worksheet.getCellRaw(e,n);if(!d&&r&&r.t===t.CellValueType.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;d=Math.max(d,t)}}return}let i=f(r.pattern);d=i>d?i:d})});let p=d-1,h=m(`0${p>0?`.0`:`.`}`,p),_=[];return s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if((0,t.isDefaultFormat)(r==null?void 0:r.pattern))_.push({row:e,col:n,pattern:h});else{let t=f(r.pattern);_.push({row:e,col:n,pattern:m(r.pattern,t-1)})}})}),await r.executeCommand(g.id,{values:_})}},x=`sheets-numfmt.config`,S={},C=e=>t.numfmt.getFormatInfo(e).type||`unknown`,w=(e,n,r=`en`)=>{try{let i=t.numfmt.formatColor(e,n),a=i?String(i):void 0,o=t.numfmt.format(e,n,{locale:r,throws:!1});return n<0?{result:o,color:a}:{result:o}}catch(t){console.warn(`getPatternPreview error:`,e,t)}return{result:String(n)}},T=(e,n,r)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String((0,i.stripErrorMargin)(n))}:w(e,n,r);function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function D(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){var t=D(e,`string`);return E(t)==`symbol`?t:t+``}function k(e,t,n){return(t=O(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function A(e,t){return function(n,r){t(n,r,e)}}function j(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let M={tl:{size:6,color:`#409f11`}},N=class extends t.Disposable{constructor(e,t,n,i,a,o,s){super(),this._instanceService=e,this._sheetInterceptorService=t,this._themeService=n,this._commandService=i,this._numfmtService=a,this._localeService=o,this._configService=s,k(this,`_locale$`,new r.BehaviorSubject(`en`)),k(this,`locale$`,this._locale$.asObservable()),this._initInterceptorCellContent()}get locale(){let e=this._locale$.getValue();if(e)return e;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.KO_KR:return`ko`;case t.LocaleType.ZH_TW:return`zh-TW`;case t.LocaleType.ZH_HK:return`zh-HK`;case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return`es`;case t.LocaleType.SK_SK:return`sk`;case t.LocaleType.JA_JP:return`ja`;case t.LocaleType.PT_BR:return`pt`;case t.LocaleType.DE_DE:return`de`;case t.LocaleType.IT_IT:return`it`;case t.LocaleType.ID_ID:return`id`;case t.LocaleType.PL_PL:return`pl`;case t.LocaleType.AR_SA:return`ar`;case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return`en`}}_initInterceptorCellContent(){let e=new t.ObjectMatrix;this.disposeWithMe((0,r.merge)(this._locale$,this._localeService.currentLocale$).subscribe(()=>{e.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(n.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(r,i,a)=>{if(!r||r.v===void 0||r.v===null||r.t===t.CellValueType.BOOLEAN||r.t===t.CellValueType.FORCE_STRING)return a(r);let o=i.unitId,s=i.subUnitId,c;if(r!=null&&r.s){let e=i.workbook.getStyles().get(r.s);e!=null&&e.n&&(c=e.n)}if(c||(c=this._numfmtService.getValue(o,s,i.row,i.col)),(0,t.isDefaultFormat)(c==null?void 0:c.pattern)||r.t!==t.CellValueType.NUMBER&&(0,n.checkCellValueType)(r.v,r.t)!==t.CellValueType.NUMBER)return a(r);let l=r;if((!r||r===i.rawData)&&(r={...i.rawData}),(0,t.isTextFormat)(c==null?void 0:c.pattern)){var u;return(u=this._configService.getConfig(`sheets-numfmt.config`))!=null&&u.disableTextFormatMark?(r.t=t.CellValueType.STRING,a(r)):(r.t=t.CellValueType.STRING,r.markers={...r==null?void 0:r.markers,...M},a(r))}let d=``,f=e.getValue(i.row,i.col);if(f&&f.parameters===`${l.v}_${c==null?void 0:c.pattern}`)return a({...r,...f.result});let p=T(c==null?void 0:c.pattern,Number(l.v),this.locale);if(d=p.result,!d)return a(r);let m={v:d,t:t.CellValueType.NUMBER};if(p.color){var h;let e=(h=this._themeService.getColorFromTheme(`${p.color}.500`))==null?p.color:h;e&&(m.interceptorStyle={cl:{rgb:e}})}return e.setValue(i.row,i.col,{result:m,parameters:`${l.v}_${c==null?void 0:c.pattern}`}),Object.assign(r,m),a(r)},priority:n.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===n.SetNumfmtMutation.id){let n=r.params;Object.keys(n.values).forEach(r=>{n.values[r].ranges.forEach(n=>{t.Range.foreach(n,(t,n)=>{e.realDeleteValue(t,n)})})})}else if(r.id===n.SetRangeValuesMutation.id){let n=r.params;new t.ObjectMatrix(n.cellValue).forValue((t,n)=>{e.realDeleteValue(t,n)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,r.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,r.of)(null):t}),(0,r.skip)(1)).subscribe(()=>e.reset()))}setNumfmtLocal(e){this._locale$.next(e)}};N=j([A(0,t.IUniverInstanceService),A(1,(0,t.Inject)(n.SheetInterceptorService)),A(2,(0,t.Inject)(t.ThemeService)),A(3,(0,t.Inject)(t.ICommandService)),A(4,(0,t.Inject)(n.INumfmtService)),A(5,(0,t.Inject)(t.LocaleService)),A(6,t.IConfigService)],N);var P=`@univerjs/sheets-numfmt`,F=`1.0.0-alpha.0`;let I=class extends t.Plugin{constructor(e=S,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},S,this._config);this._configService.setConfig(x,a)}onStarting(){(0,t.registerDependencies)(this._injector,[[N]]),(0,t.touchDependencies)(this._injector,[[N]]),[_,b,v,y,g].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};k(I,`pluginName`,`SHEET_NUMFMT_PLUGIN`),k(I,`packageName`,P),k(I,`version`,F),k(I,`type`,t.UniverInstanceType.UNIVER_SHEET),I=j([(0,t.DependentOn)(n.UniverSheetsPlugin),A(1,(0,t.Inject)(t.Injector)),A(2,t.IConfigService),A(3,t.ICommandService)],I),e.AddDecimalCommand=_,e.CURRENCYFORMAT=d,e.DATEFMTLISG=l,e.NUMBERFORMAT=u,e.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=x,e.SetCurrencyCommand=v,e.SetNumfmtCommand=g,e.SetPercentCommand=y,Object.defineProperty(e,"SheetsNumfmtCellContentController",{enumerable:!0,get:function(){return N}}),e.SubtractDecimalCommand=b,Object.defineProperty(e,"UniverSheetsNumfmtPlugin",{enumerable:!0,get:function(){return I}}),e.getCurrencyFormat=c,e.getCurrencyFormatOptions=e=>d.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),e.getCurrencyOptions=()=>t.currencySymbols.map(e=>({label:e,value:e})),e.getCurrencySymbolByLocale=s,e.getCurrencySymbolIconByLocale=o,e.getCurrencyType=e=>t.currencySymbols.find(t=>e.includes(t)),e.getDateFormatOptions=()=>l.map(e=>({label:e.label,value:e.suffix})),e.getDecimalFromPattern=f,e.getDecimalString=p,e.getNumberFormatOptions=()=>u.map(e=>({label:e.label,value:e.suffix,color:e.color})),e.getPatternPreview=w,e.getPatternPreviewIgnoreGeneral=T,e.getPatternType=C,e.isPatternHasDecimal=h,e.localeCurrencySymbolMap=a,e.setPatternDecimal=m});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-formula`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNumfmt={},e.UniverCore,e.UniverSheets,e.UniverEngineFormula,e.rxjs))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let a=new Map([[t.LocaleType.EN_US,`$`],[t.LocaleType.RU_RU,`₽`],[t.LocaleType.VI_VN,`₫`],[t.LocaleType.ZH_CN,`¥`],[t.LocaleType.ZH_TW,`NT$`],[t.LocaleType.ZH_HK,`HK$`],[t.LocaleType.FR_FR,`€`],[t.LocaleType.FA_IR,`﷼`],[t.LocaleType.KO_KR,`₩`],[t.LocaleType.ES_ES,`€`],[t.LocaleType.CA_ES,`€`],[t.LocaleType.SK_SK,`€`],[t.LocaleType.JA_JP,`¥`],[t.LocaleType.PT_BR,`R$`],[t.LocaleType.DE_DE,`€`],[t.LocaleType.IT_IT,`€`],[t.LocaleType.ID_ID,`Rp`],[t.LocaleType.PL_PL,`zł`],[t.LocaleType.AR_SA,`﷼`]]);function o(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.DE_DE:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:case t.LocaleType.IT_IT:case t.LocaleType.SK_SK:return{icon:`EuroIcon`,symbol:a.get(e)||`€`,locale:e};case t.LocaleType.RU_RU:return{icon:`RoubleIcon`,symbol:a.get(e)||`₽`,locale:e};case t.LocaleType.JA_JP:case t.LocaleType.ZH_CN:return{icon:`RmbIcon`,symbol:a.get(e)||`¥`,locale:e};case t.LocaleType.AR_SA:case t.LocaleType.EN_US:case t.LocaleType.FA_IR:case t.LocaleType.ID_ID:case t.LocaleType.KO_KR:case t.LocaleType.PL_PL:case t.LocaleType.PT_BR:case t.LocaleType.VI_VN:case t.LocaleType.ZH_HK:case t.LocaleType.ZH_TW:default:return{icon:`DollarIcon`,symbol:a.get(e)||`$`,locale:e}}}function s(e){return a.get(e)||`$`}function c(e,t=2){let n=t;t>127&&(n=127);let r=``;return n>0&&(r=`.${`0`.repeat(n)}`),`"${s(e)}"#,##0${r}_);[Red]("${s(e)}"#,##0${r})`}let l=[{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`}],u=[{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`}],d=[{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`}],f=(e,n=0)=>{var r;return e?(r=t.numfmt.getFormatInfo(e).maxDecimals)==null?n:r:n},p=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),m=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${p(Number(t||0))}`):/0([^0]?)|0$/.test(e)?e.replace(/0([^0]+)|0$/,`0${t>0?`.`:``}${p(Number(t||0))}$1`):e).join(`;`),h=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),g=e=>t.numfmt.getFormatInfo(e).type||`unknown`,_=(e,n,r=`en`)=>{try{let i=t.numfmt.formatColor(e,n),a=i?String(i):void 0,o=t.numfmt.format(e,n,{locale:r,throws:!1});return n<0?{result:o,color:a}:{result:o}}catch(t){console.warn(`getPatternPreview error:`,e,t)}return{result:String(n)}},v=(e,n,i)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String((0,r.stripErrorMargin)(n))}:_(e,n,i);function y(e){return(e==null?void 0:e.t)===t.CellValueType.NUMBER&&e.v!==void 0&&e.v!==null&&/e/i.test(String(e.v))}function b(e){let t=String(e==null?void 0:e.v),n=t.search(/e/i),r=t.indexOf(`.`),i=n>-1&&r>-1?n-r-1:0;return`0.${`0`.repeat(Math.max(2,i))}E+00`}function x(e){return(0,t.isDefaultFormat)(e)||(0,t.isTextFormat)(e)||g(e)===`scientific`}let S={id:`sheet.command.numfmt.set.numfmt`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUniverInstanceService),o=e.get(t.IUndoRedoService),s=(0,n.getSheetCommandTarget)(a,r);if(!s)return!1;let{unitId:c,subUnitId:l,worksheet:u}=s,d=r.values.filter(e=>!y(u.getCellRaw(e.row,e.col))||x(e.pattern)),f=d.filter(e=>!!e.pattern),p=d.filter(e=>!e.pattern);if(!f.length&&!p.length)return!1;let m=(0,n.transformCellsToRange)(c,l,f),h={unitId:c,subUnitId:l,ranges:p.map(e=>({startColumn:e.col,startRow:e.row,endColumn:e.col,endRow:e.row}))},g=[],_=[];if(f.length){let r=f.reduce((e,r)=>{(0,t.isTextFormat)(r.pattern)&&e.setValue(r.row,r.col,{t:t.CellValueType.STRING});let i=u.getCellRaw(r.row,r.col);if(i){let t=(0,n.checkCellValueType)(i.v);t!==i.t&&e.setValue(r.row,r.col,{t})}return e},new t.ObjectMatrix).getMatrix(),i=new t.ObjectMatrix;new t.ObjectMatrix(r).forValue((e,t)=>{let n=u.getCellRaw(e,t);n?i.setValue(e,t,{t:n.t}):i.setValue(e,t,{t:void 0})}),Object.keys(m.values).forEach(e=>{let t=m.values[e];t.ranges=(0,n.rangeMerge)(t.ranges)}),g.push({id:n.SetNumfmtMutation.id,params:m});let a=(0,n.factorySetNumfmtUndoMutation)(e,m);_.push(...a)}if(p.length){h.ranges=(0,n.rangeMerge)(h.ranges);let r=p.reduce((e,t)=>{let r=u.getCellRaw(t.row,t.col);if(r){let i=(0,n.checkCellValueType)(r.v);i!==r.t&&e.setValue(t.row,t.col,{t:i})}return e},new t.ObjectMatrix).getMatrix(),i=new t.ObjectMatrix;new t.ObjectMatrix(r).forValue((e,t)=>{let n=u.getCellRaw(e,t);n?i.setValue(e,t,{t:n.t}):i.setValue(e,t,{t:void 0})}),g.push({id:n.RemoveNumfmtMutation.id,params:h},{id:n.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:r}});let a=(0,n.factoryRemoveNumfmtUndoMutation)(e,h);_.push({id:n.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:i.getMatrix()}},...a)}let v=(0,t.sequenceExecute)(g,i).result;return v&&o.pushUndoRedo({unitID:c,undoMutations:_,redoMutations:g}),v}},C={id:`sheet.command.numfmt.add.decimal.command`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(n.INumfmtService),o=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,n.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if(!r){let r=c.worksheet.getCellRaw(e,n);if(y(r)){d=Math.max(d,f(b(r)));return}if(!d&&r&&r.t===t.CellValueType.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;d=Math.max(d,t)}}return}let i=f(r.pattern);d=i>d?i:d})});let p=d+1,h=m(`0${p>0?`.0`:``}`,p),g=[];return s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if((0,t.isDefaultFormat)(r==null?void 0:r.pattern)){let t=c.worksheet.getCellRaw(e,n);g.push({row:e,col:n,pattern:y(t)?m(b(t),p):h})}else{let t=f(r.pattern),i=m(r.pattern,t+1);i!==r.pattern&&g.push({row:e,col:n,pattern:i})}})}),g.length?await r.executeCommand(S.id,{values:g}):!1}},w={id:`sheet.command.numfmt.set.currency`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(t.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let l=[],u=c(o(a.getCurrentLocale()).locale);return s.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{l.push({row:e,col:t,pattern:u,type:`currency`})})}),await r.executeCommand(S.id,{values:l})}},T={id:`sheet.command.numfmt.set.percent`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService).getCurrentSelections();if(!i||!i.length)return!1;let a=[];return i.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{a.push({row:e,col:t,pattern:`0%`,type:`percent`})})}),await r.executeCommand(S.id,{values:a})}},E={id:`sheet.command.numfmt.subtract.decimal.command`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(n.INumfmtService),o=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,n.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if(!r){let r=c.worksheet.getCellRaw(e,n);if(y(r)){d=Math.max(d,f(b(r)));return}if(!d&&r&&r.t===t.CellValueType.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;d=Math.max(d,t)}}return}let i=f(r.pattern);d=i>d?i:d})});let p=d-1,h=m(`0${p>0?`.0`:`.`}`,p),g=[];return s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if((0,t.isDefaultFormat)(r==null?void 0:r.pattern)){let t=c.worksheet.getCellRaw(e,n);g.push({row:e,col:n,pattern:y(t)?m(b(t),p):h})}else{let t=f(r.pattern);g.push({row:e,col:n,pattern:m(r.pattern,t-1)})}})}),await r.executeCommand(S.id,{values:g})}},D=`sheets-numfmt.config`,O={};function k(e){"@babel/helpers - typeof";return k=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},k(e)}function A(e,t){if(k(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(k(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function j(e){var t=A(e,`string`);return k(t)==`symbol`?t:t+``}function M(e,t,n){return(t=j(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function N(e,t){return function(n,r){t(n,r,e)}}function P(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let F={tl:{size:6,color:`#409f11`}},I=class extends t.Disposable{constructor(e,t,n,r,a,o,s){super(),this._instanceService=e,this._sheetInterceptorService=t,this._themeService=n,this._commandService=r,this._numfmtService=a,this._localeService=o,this._configService=s,M(this,`_locale$`,new i.BehaviorSubject(`en`)),M(this,`locale$`,this._locale$.asObservable()),this._initInterceptorCellContent()}get locale(){let e=this._locale$.getValue();if(e)return e;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.KO_KR:return`ko`;case t.LocaleType.ZH_TW:return`zh-TW`;case t.LocaleType.ZH_HK:return`zh-HK`;case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return`es`;case t.LocaleType.SK_SK:return`sk`;case t.LocaleType.JA_JP:return`ja`;case t.LocaleType.PT_BR:return`pt`;case t.LocaleType.DE_DE:return`de`;case t.LocaleType.IT_IT:return`it`;case t.LocaleType.ID_ID:return`id`;case t.LocaleType.PL_PL:return`pl`;case t.LocaleType.AR_SA:return`ar`;case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return`en`}}_initInterceptorCellContent(){let e=new t.ObjectMatrix;this.disposeWithMe((0,i.merge)(this._locale$,this._localeService.currentLocale$).subscribe(()=>{e.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(n.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(r,i,a)=>{if(!r||r.v===void 0||r.v===null||r.t===t.CellValueType.BOOLEAN||r.t===t.CellValueType.FORCE_STRING)return a(r);let o=i.unitId,s=i.subUnitId,c;if(r!=null&&r.s){let e=i.workbook.getStyles().get(r.s);e!=null&&e.n&&(c=e.n)}if(c||(c=this._numfmtService.getValue(o,s,i.row,i.col)),(0,t.isDefaultFormat)(c==null?void 0:c.pattern)||r.t!==t.CellValueType.NUMBER&&(0,n.checkCellValueType)(r.v,r.t)!==t.CellValueType.NUMBER)return a(r);let l=r;if((!r||r===i.rawData)&&(r={...i.rawData}),(0,t.isTextFormat)(c==null?void 0:c.pattern)){var u;return(u=this._configService.getConfig(`sheets-numfmt.config`))!=null&&u.disableTextFormatMark?(r.t=t.CellValueType.STRING,a(r)):(r.t=t.CellValueType.STRING,r.markers={...r==null?void 0:r.markers,...F},a(r))}let d=``,f=e.getValue(i.row,i.col);if(f&&f.parameters===`${l.v}_${c==null?void 0:c.pattern}`)return a({...r,...f.result});let p=v(c==null?void 0:c.pattern,Number(l.v),this.locale);if(d=p.result,!d)return a(r);let m={v:d,t:t.CellValueType.NUMBER};if(p.color){var h;let e=(h=this._themeService.getColorFromTheme(`${p.color}.500`))==null?p.color:h;e&&(m.interceptorStyle={cl:{rgb:e}})}return e.setValue(i.row,i.col,{result:m,parameters:`${l.v}_${c==null?void 0:c.pattern}`}),Object.assign(r,m),a(r)},priority:n.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===n.SetNumfmtMutation.id){let n=r.params;Object.keys(n.values).forEach(r=>{n.values[r].ranges.forEach(n=>{t.Range.foreach(n,(t,n)=>{e.realDeleteValue(t,n)})})})}else if(r.id===n.SetRangeValuesMutation.id){let n=r.params;new t.ObjectMatrix(n.cellValue).forValue((t,n)=>{e.realDeleteValue(t,n)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,i.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,i.of)(null):t}),(0,i.skip)(1)).subscribe(()=>e.reset()))}setNumfmtLocal(e){this._locale$.next(e)}};I=P([N(0,t.IUniverInstanceService),N(1,(0,t.Inject)(n.SheetInterceptorService)),N(2,(0,t.Inject)(t.ThemeService)),N(3,(0,t.Inject)(t.ICommandService)),N(4,(0,t.Inject)(n.INumfmtService)),N(5,(0,t.Inject)(t.LocaleService)),N(6,t.IConfigService)],I);var L=`@univerjs/sheets-numfmt`,R=`1.0.0-alpha.2`;let z=class extends t.Plugin{constructor(e=O,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},O,this._config);this._configService.setConfig(D,a)}onStarting(){(0,t.registerDependencies)(this._injector,[[I]]),(0,t.touchDependencies)(this._injector,[[I]]),[C,E,w,T,S].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};M(z,`pluginName`,`SHEET_NUMFMT_PLUGIN`),M(z,`packageName`,L),M(z,`version`,R),M(z,`type`,t.UniverInstanceType.UNIVER_SHEET),z=P([(0,t.DependentOn)(n.UniverSheetsPlugin),N(1,(0,t.Inject)(t.Injector)),N(2,t.IConfigService),N(3,t.ICommandService)],z),e.AddDecimalCommand=C,e.CURRENCYFORMAT=d,e.DATEFMTLISG=l,e.NUMBERFORMAT=u,e.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,e.SetCurrencyCommand=w,e.SetNumfmtCommand=S,e.SetPercentCommand=T,Object.defineProperty(e,"SheetsNumfmtCellContentController",{enumerable:!0,get:function(){return I}}),e.SubtractDecimalCommand=E,Object.defineProperty(e,"UniverSheetsNumfmtPlugin",{enumerable:!0,get:function(){return z}}),e.getCurrencyFormat=c,e.getCurrencyFormatOptions=e=>d.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),e.getCurrencyOptions=()=>t.currencySymbols.map(e=>({label:e,value:e})),e.getCurrencySymbolByLocale=s,e.getCurrencySymbolIconByLocale=o,e.getCurrencyType=e=>t.currencySymbols.find(t=>e.includes(t)),e.getDateFormatOptions=()=>l.map(e=>({label:e.label,value:e.suffix})),e.getDecimalFromPattern=f,e.getDecimalString=p,e.getNumberFormatOptions=()=>u.map(e=>({label:e.label,value:e.suffix,color:e.color})),e.getPatternPreview=_,e.getPatternPreviewIgnoreGeneral=v,e.getPatternType=g,e.isPatternHasDecimal=h,e.localeCurrencySymbolMap=a,e.setPatternDecimal=m});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.2",
4
4
  "private": false,
5
5
  "description": "Number format services and commands for Univer Sheets.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -62,15 +62,15 @@
62
62
  "rxjs": ">=7.0.0"
63
63
  },
64
64
  "dependencies": {
65
- "@univerjs/core": "1.0.0-alpha.0",
66
- "@univerjs/engine-formula": "1.0.0-alpha.0",
67
- "@univerjs/sheets": "1.0.0-alpha.0"
65
+ "@univerjs/core": "1.0.0-alpha.2",
66
+ "@univerjs/engine-formula": "1.0.0-alpha.2",
67
+ "@univerjs/sheets": "1.0.0-alpha.2"
68
68
  },
69
69
  "devDependencies": {
70
70
  "rxjs": "^7.8.2",
71
71
  "typescript": "^6.0.3",
72
72
  "vitest": "^4.1.9",
73
- "@univerjs-infra/shared": "1.0.0-alpha.0"
73
+ "@univerjs-infra/shared": "1.0.0-alpha.2"
74
74
  },
75
75
  "scripts": {
76
76
  "test": "vitest run",