@univerjs/sheets-numfmt 0.21.1 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,58 +1,42 @@
1
- # @univerjs/sheets-numfmt-ui
2
- sheets-numfmt
1
+ # @univerjs/sheets-numfmt
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@univerjs/sheets-numfmt?style=flat-square)](https://npmjs.com/package/@univerjs/sheets-numfmt)
4
+ [![license](https://img.shields.io/npm/l/@univerjs/sheets-numfmt?style=flat-square)](https://npmjs.com/package/@univerjs/sheets-numfmt)
5
+ [![downloads](https://img.shields.io/npm/dm/@univerjs/sheets-numfmt?style=flat-square)](https://npmjs.com/package/@univerjs/sheets-numfmt)
6
+
7
+ `@univerjs/sheets-numfmt` adds core number-format services and commands for Univer Sheets.
3
8
 
4
9
  ## Package Overview
5
10
 
6
- | Package Name | UMD Namespace | Version | License | Downloads | Contains CSS | Contains i18n locales |
7
- | --- | --- | --- | --- | --- | :---: | :---: |
8
- | `@univerjs/sheets-numfmt-ui` | `UniverSheetsNumfmt` | [![][npm-version-shield]][npm-version-link] | ![][npm-license-shield] | ![][npm-downloads-shield] | ⭕️ | ⭕️ |
11
+ | Package | UMD global | CSS | Locales | Facade entry |
12
+ | --- | --- | :---: | :---: | :---: |
13
+ | `@univerjs/sheets-numfmt` | `UniverSheetsNumfmt` | No | No | Yes |
9
14
 
10
- ## Introduction
15
+ ## Installation
11
16
 
12
- Providing editing/rendering capabilities around `number format`, such as edit panels, toolbar buttons, real-time previews, row/column variations, etc.
17
+ ```sh
18
+ pnpm add @univerjs/sheets-numfmt
19
+ # or
20
+ npm install @univerjs/sheets-numfmt
21
+ ```
13
22
 
14
- > [!NOTE]
15
- > Numerical format is one of the core functions of electronic spreadsheets, and therefore, parsing and handling of numerical format is done within `@univerjs/sheets`.
23
+ Keep all `@univerjs/*` packages on the same version.
16
24
 
17
25
  ## Usage
18
26
 
19
- ### Installation
27
+ ```ts
28
+ import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
20
29
 
21
- ```shell
22
- # Using npm
23
- npm install @univerjs/sheets-numfmt-ui
24
-
25
- # Using pnpm
26
- pnpm add @univerjs/sheets-numfmt-ui
30
+ univer.registerPlugin(UniverSheetsNumfmtPlugin);
27
31
  ```
28
32
 
29
- ### How to use
33
+ ## Integration Notes
30
34
 
31
- Import `@univerjs/sheets-numfmt-ui` at the entrance .
35
+ Use this package with `@univerjs/sheets-numfmt-ui` when users need number-format menus and editors.
32
36
 
33
- ```typescript
34
- import { LocaleType, LogLevel, Univer } from '@univerjs/core';
35
- import { defaultTheme } from '@univerjs/design';
36
- import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt-ui';
37
-
38
- // univer
39
- const univer = new Univer({
40
- theme: defaultTheme,
41
- locale: LocaleType.EN_US,
42
- locales,
43
- logLevel: LogLevel.VERBOSE,
44
- });
45
-
46
- // ... Other plug-ins are registered
47
-
48
- univer.registerPlugin(UniverSheetsNumfmtPlugin);
49
- ```
37
+ ## Resources
50
38
 
51
- > [!NOTE]
52
- > If you need to export the snapshot to support the export data format, you need to add [some additional code](/)
39
+ - [Documentation](https://docs.univer.ai)
40
+ - [NPM package](https://npmjs.com/package/@univerjs/sheets-numfmt)
41
+ - [GitHub repository](https://github.com/dream-num/univer)
53
42
 
54
- <!-- Links -->
55
- [npm-version-shield]: https://img.shields.io/npm/v/@univerjs/sheets-numfmt-ui?style=flat-square
56
- [npm-version-link]: https://npmjs.com/package/@univerjs/sheets-numfmt-ui
57
- [npm-license-shield]: https://img.shields.io/npm/l/@univerjs/sheets-numfmt-ui?style=flat-square
58
- [npm-downloads-shield]: https://img.shields.io/npm/dm/@univerjs/sheets-numfmt-ui?style=flat-square
package/lib/cjs/index.js CHANGED
@@ -597,7 +597,7 @@ const getPatternPreviewIgnoreGeneral = (pattern, value, locale) => {
597
597
  };
598
598
 
599
599
  //#endregion
600
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
600
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
601
601
  function _typeof(o) {
602
602
  "@babel/helpers - typeof";
603
603
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -608,7 +608,7 @@ function _typeof(o) {
608
608
  }
609
609
 
610
610
  //#endregion
611
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
611
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
612
612
  function toPrimitive(t, r) {
613
613
  if ("object" != _typeof(t) || !t) return t;
614
614
  var e = t[Symbol.toPrimitive];
@@ -621,14 +621,14 @@ function toPrimitive(t, r) {
621
621
  }
622
622
 
623
623
  //#endregion
624
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
624
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
625
625
  function toPropertyKey(t) {
626
626
  var i = toPrimitive(t, "string");
627
627
  return "symbol" == _typeof(i) ? i : i + "";
628
628
  }
629
629
 
630
630
  //#endregion
631
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
631
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
632
632
  function _defineProperty(e, r, t) {
633
633
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
634
634
  value: t,
@@ -639,7 +639,7 @@ function _defineProperty(e, r, t) {
639
639
  }
640
640
 
641
641
  //#endregion
642
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
642
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
643
643
  function __decorateParam(paramIndex, decorator) {
644
644
  return function(target, key) {
645
645
  decorator(target, key, paramIndex);
@@ -647,7 +647,7 @@ function __decorateParam(paramIndex, decorator) {
647
647
  }
648
648
 
649
649
  //#endregion
650
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
650
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
651
651
  function __decorate(decorators, target, key, desc) {
652
652
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
653
653
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -795,7 +795,7 @@ SheetsNumfmtCellContentController = __decorate([
795
795
  //#endregion
796
796
  //#region package.json
797
797
  var name = "@univerjs/sheets-numfmt";
798
- var version = "0.21.1";
798
+ var version = "0.22.0";
799
799
 
800
800
  //#endregion
801
801
  //#region src/base/const/plugin-name.ts
package/lib/es/index.js CHANGED
@@ -596,7 +596,7 @@ const getPatternPreviewIgnoreGeneral = (pattern, value, locale) => {
596
596
  };
597
597
 
598
598
  //#endregion
599
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
599
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
600
600
  function _typeof(o) {
601
601
  "@babel/helpers - typeof";
602
602
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -607,7 +607,7 @@ function _typeof(o) {
607
607
  }
608
608
 
609
609
  //#endregion
610
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
610
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
611
611
  function toPrimitive(t, r) {
612
612
  if ("object" != _typeof(t) || !t) return t;
613
613
  var e = t[Symbol.toPrimitive];
@@ -620,14 +620,14 @@ function toPrimitive(t, r) {
620
620
  }
621
621
 
622
622
  //#endregion
623
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
623
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
624
624
  function toPropertyKey(t) {
625
625
  var i = toPrimitive(t, "string");
626
626
  return "symbol" == _typeof(i) ? i : i + "";
627
627
  }
628
628
 
629
629
  //#endregion
630
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
630
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
631
631
  function _defineProperty(e, r, t) {
632
632
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
633
633
  value: t,
@@ -638,7 +638,7 @@ function _defineProperty(e, r, t) {
638
638
  }
639
639
 
640
640
  //#endregion
641
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
641
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
642
642
  function __decorateParam(paramIndex, decorator) {
643
643
  return function(target, key) {
644
644
  decorator(target, key, paramIndex);
@@ -646,7 +646,7 @@ function __decorateParam(paramIndex, decorator) {
646
646
  }
647
647
 
648
648
  //#endregion
649
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
649
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
650
650
  function __decorate(decorators, target, key, desc) {
651
651
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
652
652
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -794,7 +794,7 @@ SheetsNumfmtCellContentController = __decorate([
794
794
  //#endregion
795
795
  //#region package.json
796
796
  var name = "@univerjs/sheets-numfmt";
797
- var version = "0.21.1";
797
+ var version = "0.22.0";
798
798
 
799
799
  //#endregion
800
800
  //#region src/base/const/plugin-name.ts
package/lib/index.js CHANGED
@@ -596,7 +596,7 @@ const getPatternPreviewIgnoreGeneral = (pattern, value, locale) => {
596
596
  };
597
597
 
598
598
  //#endregion
599
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
599
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
600
600
  function _typeof(o) {
601
601
  "@babel/helpers - typeof";
602
602
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -607,7 +607,7 @@ function _typeof(o) {
607
607
  }
608
608
 
609
609
  //#endregion
610
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
610
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
611
611
  function toPrimitive(t, r) {
612
612
  if ("object" != _typeof(t) || !t) return t;
613
613
  var e = t[Symbol.toPrimitive];
@@ -620,14 +620,14 @@ function toPrimitive(t, r) {
620
620
  }
621
621
 
622
622
  //#endregion
623
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
623
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
624
624
  function toPropertyKey(t) {
625
625
  var i = toPrimitive(t, "string");
626
626
  return "symbol" == _typeof(i) ? i : i + "";
627
627
  }
628
628
 
629
629
  //#endregion
630
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
630
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
631
631
  function _defineProperty(e, r, t) {
632
632
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
633
633
  value: t,
@@ -638,7 +638,7 @@ function _defineProperty(e, r, t) {
638
638
  }
639
639
 
640
640
  //#endregion
641
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
641
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
642
642
  function __decorateParam(paramIndex, decorator) {
643
643
  return function(target, key) {
644
644
  decorator(target, key, paramIndex);
@@ -646,7 +646,7 @@ function __decorateParam(paramIndex, decorator) {
646
646
  }
647
647
 
648
648
  //#endregion
649
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
649
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
650
650
  function __decorate(decorators, target, key, desc) {
651
651
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
652
652
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -794,7 +794,7 @@ SheetsNumfmtCellContentController = __decorate([
794
794
  //#endregion
795
795
  //#region package.json
796
796
  var name = "@univerjs/sheets-numfmt";
797
- var version = "0.21.1";
797
+ var version = "0.22.0";
798
798
 
799
799
  //#endregion
800
800
  //#region src/base/const/plugin-name.ts
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=`$.£.¥.¤.֏.؋.৳.฿.៛.₡.₦.₩.₪.₫.€.₭.₮.₱.₲.₴.₸.₹.₺.₼.₽.₾.₿.﷼`.split(`.`),o=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.FR_FR,`€`],[t.LocaleType.FA_IR,`﷼`],[t.LocaleType.KO_KR,`₩`],[t.LocaleType.ES_ES,`€`],[t.LocaleType.CA_ES,`€`],[t.LocaleType.SK_SK,`€`]]);function s(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:case t.LocaleType.SK_SK:return{icon:`EuroIcon`,symbol:o.get(e)||`€`,locale:e};case t.LocaleType.RU_RU:return{icon:`RoubleIcon`,symbol:o.get(e)||`₽`,locale:e};case t.LocaleType.ZH_CN:return{icon:`RmbIcon`,symbol:o.get(e)||`¥`,locale:e};case t.LocaleType.EN_US:default:return{icon:`DollarIcon`,symbol:`$`,locale:t.LocaleType.EN_US}}}function c(e){return o.get(e)||`$`}function l(e,t=2){let n=t;t>127&&(n=127);let r=``;return n>0&&(r=`.${`0`.repeat(n)}`),`"${c(e)}"#,##0${r}_);[Red]("${c(e)}"#,##0${r})`}let u=[{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`}],d=[{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`}],f=[{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`}],p=(e,n=0)=>{var r;return e?(r=t.numfmt.getFormatInfo(e).maxDecimals)==null?n:r:n},m=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),h=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${m(Number(t||0))}`):/0([^0]?)|0$/.test(e)?e.replace(/0([^0]+)|0$/,`0${t>0?`.`:``}${m(Number(t||0))}$1`):e).join(`;`),g=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;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}),_}},v={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=p(r.pattern);d=i>d?i:d})});let f=d+1,m=h(`0${f>0?`.0`:``}`,f),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))g.push({row:e,col:n,pattern:m});else{let t=p(r.pattern),i=h(r.pattern,t+1);i!==r.pattern&&g.push({row:e,col:n,pattern:i})}})}),g.length?await r.executeCommand(_.id,{values:g}):!1}},y={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),o=i.getCurrentSelections();if(!o||!o.length)return!1;let c=[],u=l(s(a.getCurrentLocale()).locale);return o.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{c.push({row:e,col:t,pattern:u,type:`currency`})})}),await r.executeCommand(_.id,{values:c})}},b={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(_.id,{values:a})}},x={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=p(r.pattern);d=i>d?i:d})});let f=d-1,m=h(`0${f>0?`.0`:`.`}`,f),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))g.push({row:e,col:n,pattern:m});else{let t=p(r.pattern);g.push({row:e,col:n,pattern:h(r.pattern,t-1)})}})}),await r.executeCommand(_.id,{values:g})}},S=`sheets-numfmt.config`;Symbol(S);let C={},w=e=>t.numfmt.getFormatInfo(e).type||`unknown`,T=(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)}},E=(e,n,r)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String((0,i.stripErrorMargin)(n))}:T(e,n,r);function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function j(e,t){return function(n,r){t(n,r,e)}}function M(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 N={tl:{size:6,color:`#409f11`}},P=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,A(this,`_locale$`,new r.BehaviorSubject(`en`)),A(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.ES_ES:case t.LocaleType.CA_ES:return`es`;case t.LocaleType.SK_SK:return`sk`;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,...N},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=E(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)}};P=M([j(0,t.IUniverInstanceService),j(1,(0,t.Inject)(n.SheetInterceptorService)),j(2,(0,t.Inject)(t.ThemeService)),j(3,(0,t.Inject)(t.ICommandService)),j(4,(0,t.Inject)(n.INumfmtService)),j(5,(0,t.Inject)(t.LocaleService)),j(6,t.IConfigService)],P);var F=`@univerjs/sheets-numfmt`,I=`0.21.1`;let L=class extends t.Plugin{constructor(e=C,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},C,this._config);this._configService.setConfig(S,a)}onStarting(){(0,t.registerDependencies)(this._injector,[[P]]),(0,t.touchDependencies)(this._injector,[[P]]),[v,x,y,b,_].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};A(L,`pluginName`,`SHEET_NUMFMT_PLUGIN`),A(L,`packageName`,F),A(L,`version`,I),A(L,`type`,t.UniverInstanceType.UNIVER_SHEET),L=M([(0,t.DependentOn)(n.UniverSheetsPlugin),j(1,(0,t.Inject)(t.Injector)),j(2,t.IConfigService),j(3,t.ICommandService)],L),e.AddDecimalCommand=v,e.CURRENCYFORMAT=f,e.DATEFMTLISG=u,e.NUMBERFORMAT=d,e.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=S,e.SetCurrencyCommand=y,e.SetNumfmtCommand=_,e.SetPercentCommand=b,Object.defineProperty(e,`SheetsNumfmtCellContentController`,{enumerable:!0,get:function(){return P}}),e.SubtractDecimalCommand=x,Object.defineProperty(e,`UniverSheetsNumfmtPlugin`,{enumerable:!0,get:function(){return L}}),e.currencySymbols=a,e.getCurrencyFormat=l,e.getCurrencyFormatOptions=e=>f.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),e.getCurrencyOptions=()=>a.map(e=>({label:e,value:e})),e.getCurrencySymbolByLocale=c,e.getCurrencySymbolIconByLocale=s,e.getCurrencyType=e=>a.find(t=>e.includes(t)),e.getDateFormatOptions=()=>u.map(e=>({label:e.label,value:e.suffix})),e.getDecimalFromPattern=p,e.getDecimalString=m,e.getNumberFormatOptions=()=>d.map(e=>({label:e.label,value:e.suffix,color:e.color})),e.getPatternPreview=T,e.getPatternPreviewIgnoreGeneral=E,e.getPatternType=w,e.isPatternHasDecimal=g,e.localeCurrencySymbolMap=o,e.setPatternDecimal=h});
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=`$.£.¥.¤.֏.؋.৳.฿.៛.₡.₦.₩.₪.₫.€.₭.₮.₱.₲.₴.₸.₹.₺.₼.₽.₾.₿.﷼`.split(`.`),o=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.FR_FR,`€`],[t.LocaleType.FA_IR,`﷼`],[t.LocaleType.KO_KR,`₩`],[t.LocaleType.ES_ES,`€`],[t.LocaleType.CA_ES,`€`],[t.LocaleType.SK_SK,`€`]]);function s(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:case t.LocaleType.SK_SK:return{icon:`EuroIcon`,symbol:o.get(e)||`€`,locale:e};case t.LocaleType.RU_RU:return{icon:`RoubleIcon`,symbol:o.get(e)||`₽`,locale:e};case t.LocaleType.ZH_CN:return{icon:`RmbIcon`,symbol:o.get(e)||`¥`,locale:e};case t.LocaleType.EN_US:default:return{icon:`DollarIcon`,symbol:`$`,locale:t.LocaleType.EN_US}}}function c(e){return o.get(e)||`$`}function l(e,t=2){let n=t;t>127&&(n=127);let r=``;return n>0&&(r=`.${`0`.repeat(n)}`),`"${c(e)}"#,##0${r}_);[Red]("${c(e)}"#,##0${r})`}let u=[{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`}],d=[{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`}],f=[{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`}],p=(e,n=0)=>{var r;return e?(r=t.numfmt.getFormatInfo(e).maxDecimals)==null?n:r:n},m=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),h=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${m(Number(t||0))}`):/0([^0]?)|0$/.test(e)?e.replace(/0([^0]+)|0$/,`0${t>0?`.`:``}${m(Number(t||0))}$1`):e).join(`;`),g=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;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}),_}},v={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=p(r.pattern);d=i>d?i:d})});let f=d+1,m=h(`0${f>0?`.0`:``}`,f),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))g.push({row:e,col:n,pattern:m});else{let t=p(r.pattern),i=h(r.pattern,t+1);i!==r.pattern&&g.push({row:e,col:n,pattern:i})}})}),g.length?await r.executeCommand(_.id,{values:g}):!1}},y={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),o=i.getCurrentSelections();if(!o||!o.length)return!1;let c=[],u=l(s(a.getCurrentLocale()).locale);return o.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{c.push({row:e,col:t,pattern:u,type:`currency`})})}),await r.executeCommand(_.id,{values:c})}},b={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(_.id,{values:a})}},x={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=p(r.pattern);d=i>d?i:d})});let f=d-1,m=h(`0${f>0?`.0`:`.`}`,f),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))g.push({row:e,col:n,pattern:m});else{let t=p(r.pattern);g.push({row:e,col:n,pattern:h(r.pattern,t-1)})}})}),await r.executeCommand(_.id,{values:g})}},S=`sheets-numfmt.config`;Symbol(S);let C={},w=e=>t.numfmt.getFormatInfo(e).type||`unknown`,T=(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)}},E=(e,n,r)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String((0,i.stripErrorMargin)(n))}:T(e,n,r);function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function j(e,t){return function(n,r){t(n,r,e)}}function M(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 N={tl:{size:6,color:`#409f11`}},P=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,A(this,`_locale$`,new r.BehaviorSubject(`en`)),A(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.ES_ES:case t.LocaleType.CA_ES:return`es`;case t.LocaleType.SK_SK:return`sk`;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,...N},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=E(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)}};P=M([j(0,t.IUniverInstanceService),j(1,(0,t.Inject)(n.SheetInterceptorService)),j(2,(0,t.Inject)(t.ThemeService)),j(3,(0,t.Inject)(t.ICommandService)),j(4,(0,t.Inject)(n.INumfmtService)),j(5,(0,t.Inject)(t.LocaleService)),j(6,t.IConfigService)],P);var F=`@univerjs/sheets-numfmt`,I=`0.22.0`;let L=class extends t.Plugin{constructor(e=C,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},C,this._config);this._configService.setConfig(S,a)}onStarting(){(0,t.registerDependencies)(this._injector,[[P]]),(0,t.touchDependencies)(this._injector,[[P]]),[v,x,y,b,_].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};A(L,`pluginName`,`SHEET_NUMFMT_PLUGIN`),A(L,`packageName`,F),A(L,`version`,I),A(L,`type`,t.UniverInstanceType.UNIVER_SHEET),L=M([(0,t.DependentOn)(n.UniverSheetsPlugin),j(1,(0,t.Inject)(t.Injector)),j(2,t.IConfigService),j(3,t.ICommandService)],L),e.AddDecimalCommand=v,e.CURRENCYFORMAT=f,e.DATEFMTLISG=u,e.NUMBERFORMAT=d,e.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=S,e.SetCurrencyCommand=y,e.SetNumfmtCommand=_,e.SetPercentCommand=b,Object.defineProperty(e,`SheetsNumfmtCellContentController`,{enumerable:!0,get:function(){return P}}),e.SubtractDecimalCommand=x,Object.defineProperty(e,`UniverSheetsNumfmtPlugin`,{enumerable:!0,get:function(){return L}}),e.currencySymbols=a,e.getCurrencyFormat=l,e.getCurrencyFormatOptions=e=>f.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),e.getCurrencyOptions=()=>a.map(e=>({label:e,value:e})),e.getCurrencySymbolByLocale=c,e.getCurrencySymbolIconByLocale=s,e.getCurrencyType=e=>a.find(t=>e.includes(t)),e.getDateFormatOptions=()=>u.map(e=>({label:e.label,value:e.suffix})),e.getDecimalFromPattern=p,e.getDecimalString=m,e.getNumberFormatOptions=()=>d.map(e=>({label:e.label,value:e.suffix,color:e.color})),e.getPatternPreview=T,e.getPatternPreviewIgnoreGeneral=E,e.getPatternType=w,e.isPatternHasDecimal=g,e.localeCurrencySymbolMap=o,e.setPatternDecimal=h});
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "private": false,
5
- "description": "UniverSheet numfmt plugin",
6
- "author": "DreamNum <developer@univer.ai>",
5
+ "description": "Number format services and commands for Univer Sheets.",
6
+ "author": "DreamNum Co., Ltd. <developer@univer.ai>",
7
7
  "license": "Apache-2.0",
8
8
  "funding": {
9
9
  "type": "opencollective",
@@ -18,7 +18,11 @@
18
18
  "url": "https://github.com/dream-num/univer/issues"
19
19
  },
20
20
  "keywords": [
21
- "univer"
21
+ "univer",
22
+ "sheets",
23
+ "number-format",
24
+ "formatting",
25
+ "plugin"
22
26
  ],
23
27
  "exports": {
24
28
  ".": {
@@ -58,15 +62,15 @@
58
62
  "rxjs": ">=7.0.0"
59
63
  },
60
64
  "dependencies": {
61
- "@univerjs/core": "0.21.1",
62
- "@univerjs/engine-formula": "0.21.1",
63
- "@univerjs/sheets": "0.21.1"
65
+ "@univerjs/core": "0.22.0",
66
+ "@univerjs/engine-formula": "0.22.0",
67
+ "@univerjs/sheets": "0.22.0"
64
68
  },
65
69
  "devDependencies": {
66
70
  "rxjs": "^7.8.2",
67
- "typescript": "^6.0.2",
68
- "vitest": "^4.1.4",
69
- "@univerjs-infra/shared": "0.21.1"
71
+ "typescript": "^6.0.3",
72
+ "vitest": "^4.1.5",
73
+ "@univerjs-infra/shared": "0.22.0"
70
74
  },
71
75
  "scripts": {
72
76
  "test": "vitest run",