@univerjs/sheets-numfmt 0.16.1-insiders.20260311-074e8ca → 0.17.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/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var X=Object.defineProperty;var J=(e,r,s)=>r in e?X(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var P=(e,r,s)=>J(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),I=require("rxjs"),Q=require("@univerjs/engine-formula"),D=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=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 j(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:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function A(e,r=2){let s=r;r>127&&(s=127);let n="";return s>0&&(n=`.${"0".repeat(s)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const B=[{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"}],G=[{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"}],H=[{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"}],$=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},x=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${x(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${x(Number(r||0))}$1`):n).join(";"),ee=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),N={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:i}=o,u=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=f.transformCellsToRange(l,d,u),h={unitId:l,subUnitId:d,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],v=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const C=i.getCellRaw(m.row,m.col);if(C){const R=f.checkCellValueType(C.v);R!==C.t&&g.setValue(m.row,m.col,{t:R})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const C=i.getCellRaw(g,m);C?p.setValue(g,m,{t:C.t}):p.setValue(g,m,{t:void 0})}),Object.keys(T.values).forEach(g=>{const m=T.values[g];m.ranges=f.rangeMerge(m.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:T});const y=f.factorySetNumfmtUndoMutation(e,T);v.push(...y)}if(_.length){h.ranges=f.rangeMerge(h.ranges);const c=_.reduce((g,m)=>{const C=i.getCellRaw(m.row,m.col);if(C){const R=f.checkCellValueType(C.v);R!==C.t&&g.setValue(m.row,m.col,{t:R})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const C=i.getCellRaw(g,m);C?p.setValue(g,m,{t:C.t}):p.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,h);v.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:p.getMatrix()}},...y)}const S=t.sequenceExecute(M,s).result;return S&&a.pushUndoRedo({unitID:l,undoMutations:v,redoMutations:M}),S}},K={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(v,S)=>{const c=n.getValue(d,i,v,S);if(!c){const y=l.worksheet.getCellRaw(v,S);if(!u&&y&&y.t===t.CellValueType.NUMBER&&y.v){const g=/\.(\d*)$/.exec(String(y.v));if(g){const m=g[1].length;if(!m)return;u=Math.max(u,m)}}return}const p=$(c.pattern);u=p>u?p:u})});const _=u+1,T=U(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(v,S)=>{const c=n.getValue(d,i,v,S);if(t.isDefaultFormat(c==null?void 0:c.pattern))h.push({row:v,col:S,pattern:T});else{const p=$(c.pattern),y=U(c.pattern,p+1);y!==c.pattern&&h.push({row:v,col:S,pattern:y})}})}),h.length?await r.executeCommand(N.id,{values:h}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const o=[],l=j(n.getCurrentLocale()),d=A(l.locale);return a.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(N.id,{values:o})}},k={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{a.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(N.id,{values:a})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(v=>{t.Range.foreach(v.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(!p){const g=l.worksheet.getCellRaw(S,c);if(!u&&g&&g.t===t.CellValueType.NUMBER&&g.v){const m=/\.(\d*)$/.exec(String(g.v));if(m){const C=m[1].length;if(!C)return;u=Math.max(u,C)}}return}const y=$(p.pattern);u=y>u?y:u})});const _=u-1,T=U(`0${_>0?".0":"."}`,_),h=[];return o.forEach(v=>{t.Range.foreach(v.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(t.isDefaultFormat(p==null?void 0:p.pattern))h.push({row:S,col:c,pattern:T});else{const y=$(p.pattern);h.push({row:S,col:c,pattern:U(p.pattern,y-1)})}})}),await r.executeCommand(N.id,{values:h})}},w="sheets-numfmt.config",V={},te=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,s="en")=>{try{const n=t.numfmt.formatColor(e,r),a=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a}:{result:o}}catch(n){console.warn("getPatternPreview error:",e,n)}return{result:String(r)}},Y=(e,r,s)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(Q.stripErrorMargin(r))}:Z(e,r,s);var ne=Object.getOwnPropertyDescriptor,re=(e,r,s,n)=>{for(var a=n>1?void 0:n?ne(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},b=(e,r)=>(s,n)=>r(s,n,e);const se={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,d,i){super();P(this,"_locale$",new I.BehaviorSubject("en"));P(this,"locale$",this._locale$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const s=this._locale$.getValue();if(s)return s;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(){const s=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var v,S;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return o(n);const l=a.unitId,d=a.subUnitId;let i;if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,a.row,a.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===a.rawData)&&(n={...a.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(v=this._configService.getConfig(w))!=null&&v.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...se},o(n));let _="";const T=s.getValue(a.row,a.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const h=Y(i==null?void 0:i.pattern,Number(u.v),this.locale);if(_=h.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(h.color){const c=(S=this._themeService.getColorFromTheme(`${h.color}.500`))!=null?S:h.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{s.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:I.of(null)}),I.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._locale$.next(s)}};exports.SheetsNumfmtCellContentController=re([b(0,t.IUniverInstanceService),b(1,t.Inject(f.SheetInterceptorService)),b(2,t.Inject(t.ThemeService)),b(3,t.Inject(t.ICommandService)),b(4,t.Inject(f.INumfmtService)),b(5,t.Inject(t.LocaleService)),b(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const ae="@univerjs/sheets-numfmt",oe="0.16.1-insiders.20260311-074e8ca",z={name:ae,version:oe},ce="SHEET_NUMFMT_PLUGIN";var ie=Object.defineProperty,le=Object.getOwnPropertyDescriptor,ue=(e,r,s)=>r in e?ie(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,me=(e,r,s,n)=>{for(var a=n>1?void 0:n?le(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},L=(e,r)=>(s,n)=>r(s,n,e),O=(e,r,s)=>ue(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=V,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},V,this._config);this._configService.setConfig(w,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),[K,q,W,k,N].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};O(exports.UniverSheetsNumfmtPlugin,"pluginName",ce);O(exports.UniverSheetsNumfmtPlugin,"packageName",z.name);O(exports.UniverSheetsNumfmtPlugin,"version",z.version);O(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=me([t.DependentOn(f.UniverSheetsPlugin),L(1,t.Inject(t.Injector)),L(2,t.IConfigService),L(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const fe=e=>D.find(s=>e.includes(s)),ge=()=>D.map(e=>({label:e,value:e})),de=e=>H.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),pe=()=>B.map(e=>({label:e.label,value:e.suffix})),Se=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=K;exports.CURRENCYFORMAT=H;exports.DATEFMTLISG=B;exports.NUMBERFORMAT=G;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=N;exports.SetPercentCommand=k;exports.SubtractDecimalCommand=q;exports.currencySymbols=D;exports.getCurrencyFormat=A;exports.getCurrencyFormatOptions=de;exports.getCurrencyOptions=ge;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=j;exports.getCurrencyType=fe;exports.getDateFormatOptions=pe;exports.getDecimalFromPattern=$;exports.getDecimalString=x;exports.getNumberFormatOptions=Se;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=te;exports.isPatternHasDecimal=ee;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=U;
1
+ "use strict";var X=Object.defineProperty;var J=(e,r,s)=>r in e?X(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var P=(e,r,s)=>J(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),I=require("rxjs"),Q=require("@univerjs/engine-formula"),D=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=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 j(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:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function A(e,r=2){let s=r;r>127&&(s=127);let n="";return s>0&&(n=`.${"0".repeat(s)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const B=[{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"}],G=[{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"}],H=[{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"}],$=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},x=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${x(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${x(Number(r||0))}$1`):n).join(";"),ee=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),N={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:i}=o,u=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=f.transformCellsToRange(l,d,u),h={unitId:l,subUnitId:d,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],v=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const C=i.getCellRaw(m.row,m.col);if(C){const R=f.checkCellValueType(C.v);R!==C.t&&g.setValue(m.row,m.col,{t:R})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const C=i.getCellRaw(g,m);C?p.setValue(g,m,{t:C.t}):p.setValue(g,m,{t:void 0})}),Object.keys(T.values).forEach(g=>{const m=T.values[g];m.ranges=f.rangeMerge(m.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:T});const y=f.factorySetNumfmtUndoMutation(e,T);v.push(...y)}if(_.length){h.ranges=f.rangeMerge(h.ranges);const c=_.reduce((g,m)=>{const C=i.getCellRaw(m.row,m.col);if(C){const R=f.checkCellValueType(C.v);R!==C.t&&g.setValue(m.row,m.col,{t:R})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const C=i.getCellRaw(g,m);C?p.setValue(g,m,{t:C.t}):p.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,h);v.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:p.getMatrix()}},...y)}const S=t.sequenceExecute(M,s).result;return S&&a.pushUndoRedo({unitID:l,undoMutations:v,redoMutations:M}),S}},K={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(v,S)=>{const c=n.getValue(d,i,v,S);if(!c){const y=l.worksheet.getCellRaw(v,S);if(!u&&y&&y.t===t.CellValueType.NUMBER&&y.v){const g=/\.(\d*)$/.exec(String(y.v));if(g){const m=g[1].length;if(!m)return;u=Math.max(u,m)}}return}const p=$(c.pattern);u=p>u?p:u})});const _=u+1,T=U(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(v,S)=>{const c=n.getValue(d,i,v,S);if(t.isDefaultFormat(c==null?void 0:c.pattern))h.push({row:v,col:S,pattern:T});else{const p=$(c.pattern),y=U(c.pattern,p+1);y!==c.pattern&&h.push({row:v,col:S,pattern:y})}})}),h.length?await r.executeCommand(N.id,{values:h}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const o=[],l=j(n.getCurrentLocale()),d=A(l.locale);return a.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(N.id,{values:o})}},k={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{a.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(N.id,{values:a})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(v=>{t.Range.foreach(v.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(!p){const g=l.worksheet.getCellRaw(S,c);if(!u&&g&&g.t===t.CellValueType.NUMBER&&g.v){const m=/\.(\d*)$/.exec(String(g.v));if(m){const C=m[1].length;if(!C)return;u=Math.max(u,C)}}return}const y=$(p.pattern);u=y>u?y:u})});const _=u-1,T=U(`0${_>0?".0":"."}`,_),h=[];return o.forEach(v=>{t.Range.foreach(v.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(t.isDefaultFormat(p==null?void 0:p.pattern))h.push({row:S,col:c,pattern:T});else{const y=$(p.pattern);h.push({row:S,col:c,pattern:U(p.pattern,y-1)})}})}),await r.executeCommand(N.id,{values:h})}},w="sheets-numfmt.config",V={},te=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,s="en")=>{try{const n=t.numfmt.formatColor(e,r),a=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a}:{result:o}}catch(n){console.warn("getPatternPreview error:",e,n)}return{result:String(r)}},Y=(e,r,s)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(Q.stripErrorMargin(r))}:Z(e,r,s);var ne=Object.getOwnPropertyDescriptor,re=(e,r,s,n)=>{for(var a=n>1?void 0:n?ne(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},b=(e,r)=>(s,n)=>r(s,n,e);const se={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,d,i){super();P(this,"_locale$",new I.BehaviorSubject("en"));P(this,"locale$",this._locale$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const s=this._locale$.getValue();if(s)return s;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(){const s=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var v,S;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return o(n);const l=a.unitId,d=a.subUnitId;let i;if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,a.row,a.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===a.rawData)&&(n={...a.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(v=this._configService.getConfig(w))!=null&&v.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...se},o(n));let _="";const T=s.getValue(a.row,a.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const h=Y(i==null?void 0:i.pattern,Number(u.v),this.locale);if(_=h.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(h.color){const c=(S=this._themeService.getColorFromTheme(`${h.color}.500`))!=null?S:h.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{s.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:I.of(null)}),I.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._locale$.next(s)}};exports.SheetsNumfmtCellContentController=re([b(0,t.IUniverInstanceService),b(1,t.Inject(f.SheetInterceptorService)),b(2,t.Inject(t.ThemeService)),b(3,t.Inject(t.ICommandService)),b(4,t.Inject(f.INumfmtService)),b(5,t.Inject(t.LocaleService)),b(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const ae="@univerjs/sheets-numfmt",oe="0.17.0",z={name:ae,version:oe},ce="SHEET_NUMFMT_PLUGIN";var ie=Object.defineProperty,le=Object.getOwnPropertyDescriptor,ue=(e,r,s)=>r in e?ie(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,me=(e,r,s,n)=>{for(var a=n>1?void 0:n?le(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},L=(e,r)=>(s,n)=>r(s,n,e),O=(e,r,s)=>ue(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=V,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},V,this._config);this._configService.setConfig(w,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),[K,q,W,k,N].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};O(exports.UniverSheetsNumfmtPlugin,"pluginName",ce);O(exports.UniverSheetsNumfmtPlugin,"packageName",z.name);O(exports.UniverSheetsNumfmtPlugin,"version",z.version);O(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=me([t.DependentOn(f.UniverSheetsPlugin),L(1,t.Inject(t.Injector)),L(2,t.IConfigService),L(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const fe=e=>D.find(s=>e.includes(s)),ge=()=>D.map(e=>({label:e,value:e})),de=e=>H.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),pe=()=>B.map(e=>({label:e.label,value:e.suffix})),Se=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=K;exports.CURRENCYFORMAT=H;exports.DATEFMTLISG=B;exports.NUMBERFORMAT=G;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=N;exports.SetPercentCommand=k;exports.SubtractDecimalCommand=q;exports.currencySymbols=D;exports.getCurrencyFormat=A;exports.getCurrencyFormatOptions=de;exports.getCurrencyOptions=ge;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=j;exports.getCurrencyType=fe;exports.getDateFormatOptions=pe;exports.getDecimalFromPattern=$;exports.getDecimalString=x;exports.getNumberFormatOptions=Se;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=te;exports.isPatternHasDecimal=ee;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=U;
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
- var ie = Object.defineProperty;
2
- var ce = (e, r, t) => r in e ? ie(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
- var K = (e, r, t) => ce(e, typeof r != "symbol" ? r + "" : r, t);
4
- import { LocaleType as c, numfmt as P, CommandType as O, ICommandService as $, IUniverInstanceService as V, IUndoRedoService as le, isTextFormat as Q, CellValueType as M, ObjectMatrix as R, sequenceExecute as ue, Range as E, isDefaultFormat as W, LocaleService as ee, DEFAULT_NUMBER_FORMAT as fe, Inject as I, ThemeService as me, Disposable as de, InterceptorEffectEnum as z, UniverInstanceType as te, IConfigService as re, DependentOn as ge, Injector as he, Plugin as pe, merge as _e, registerDependencies as Se, touchDependencies as ve } from "@univerjs/core";
1
+ var ce = Object.defineProperty;
2
+ var ie = (e, r, t) => r in e ? ce(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
+ var K = (e, r, t) => ie(e, typeof r != "symbol" ? r + "" : r, t);
4
+ import { LocaleType as i, numfmt as P, CommandType as O, ICommandService as $, IUniverInstanceService as V, IUndoRedoService as le, isTextFormat as Q, CellValueType as M, ObjectMatrix as R, sequenceExecute as ue, Range as E, isDefaultFormat as W, LocaleService as ee, DEFAULT_NUMBER_FORMAT as fe, Inject as I, ThemeService as me, IConfigService as te, Disposable as de, InterceptorEffectEnum as z, UniverInstanceType as re, DependentOn as ge, Injector as he, Plugin as pe, merge as _e, registerDependencies as Se, touchDependencies as ve } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as k, transformCellsToRange as Ce, checkCellValueType as H, rangeMerge as Y, SetNumfmtMutation as ne, factorySetNumfmtUndoMutation as ye, RemoveNumfmtMutation as be, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as Me, SheetsSelectionsService as j, INumfmtService as Z, SheetInterceptorService as Re, INTERCEPTOR_POINT as Ne, InterceptCellContentPriority as Ee, UniverSheetsPlugin as $e } from "@univerjs/sheets";
6
6
  import { BehaviorSubject as Ie, merge as Te, switchMap as Ue, of as Oe, skip as we } from "rxjs";
7
7
  import { stripErrorMargin as xe } from "@univerjs/engine-formula";
@@ -35,47 +35,47 @@ const se = [
35
35
  "₿",
36
36
  "﷼"
37
37
  ], x = /* @__PURE__ */ new Map([
38
- [c.EN_US, "$"],
39
- [c.RU_RU, "₽"],
40
- [c.VI_VN, "₫"],
41
- [c.ZH_CN, "¥"],
42
- [c.ZH_TW, "NT$"],
43
- [c.FR_FR, "€"],
44
- [c.FA_IR, "﷼"],
45
- [c.KO_KR, "₩"],
46
- [c.ES_ES, "€"],
47
- [c.CA_ES, "€"],
48
- [c.SK_SK, "€"]
38
+ [i.EN_US, "$"],
39
+ [i.RU_RU, "₽"],
40
+ [i.VI_VN, "₫"],
41
+ [i.ZH_CN, "¥"],
42
+ [i.ZH_TW, "NT$"],
43
+ [i.FR_FR, "€"],
44
+ [i.FA_IR, "﷼"],
45
+ [i.KO_KR, "₩"],
46
+ [i.ES_ES, "€"],
47
+ [i.CA_ES, "€"],
48
+ [i.SK_SK, "€"]
49
49
  ]);
50
50
  function Pe(e) {
51
51
  switch (e) {
52
- case c.CA_ES:
53
- case c.ES_ES:
54
- case c.FR_FR:
55
- case c.SK_SK:
52
+ case i.CA_ES:
53
+ case i.ES_ES:
54
+ case i.FR_FR:
55
+ case i.SK_SK:
56
56
  return {
57
57
  icon: "EuroIcon",
58
58
  symbol: x.get(e) || "€",
59
59
  locale: e
60
60
  };
61
- case c.RU_RU:
61
+ case i.RU_RU:
62
62
  return {
63
63
  icon: "RoubleIcon",
64
64
  symbol: x.get(e) || "₽",
65
65
  locale: e
66
66
  };
67
- case c.ZH_CN:
67
+ case i.ZH_CN:
68
68
  return {
69
69
  icon: "RmbIcon",
70
70
  symbol: x.get(e) || "¥",
71
71
  locale: e
72
72
  };
73
- case c.EN_US:
73
+ case i.EN_US:
74
74
  default:
75
75
  return {
76
76
  icon: "DollarIcon",
77
77
  symbol: "$",
78
- locale: c.EN_US
78
+ locale: i.EN_US
79
79
  };
80
80
  }
81
81
  }
@@ -207,18 +207,18 @@ const De = [
207
207
  return !1;
208
208
  const t = e.get($), n = e.get(V), s = e.get(le), a = k(n, r);
209
209
  if (!a) return !1;
210
- const { unitId: u, subUnitId: o, worksheet: h } = a, f = r.values.filter((i) => !!i.pattern), C = r.values.filter((i) => !i.pattern), y = Ce(u, o, f), p = {
210
+ const { unitId: u, subUnitId: o, worksheet: h } = a, f = r.values.filter((c) => !!c.pattern), C = r.values.filter((c) => !c.pattern), y = Ce(u, o, f), p = {
211
211
  unitId: u,
212
212
  subUnitId: o,
213
- ranges: C.map((i) => ({
214
- startColumn: i.col,
215
- startRow: i.row,
216
- endColumn: i.col,
217
- endRow: i.row
213
+ ranges: C.map((c) => ({
214
+ startColumn: c.col,
215
+ startRow: c.row,
216
+ endColumn: c.col,
217
+ endRow: c.row
218
218
  }))
219
219
  }, b = [], _ = [];
220
220
  if (f.length) {
221
- const i = f.reduce((d, l) => {
221
+ const c = f.reduce((d, l) => {
222
222
  Q(l.pattern) && d.setValue(l.row, l.col, { t: M.STRING });
223
223
  const v = h.getCellRaw(l.row, l.col);
224
224
  if (v) {
@@ -227,7 +227,7 @@ const De = [
227
227
  }
228
228
  return d;
229
229
  }, new R()).getMatrix(), g = new R();
230
- new R(i).forValue((d, l) => {
230
+ new R(c).forValue((d, l) => {
231
231
  const v = h.getCellRaw(d, l);
232
232
  v ? g.setValue(d, l, { t: v.t }) : g.setValue(d, l, { t: void 0 });
233
233
  }), Object.keys(y.values).forEach((d) => {
@@ -242,7 +242,7 @@ const De = [
242
242
  }
243
243
  if (C.length) {
244
244
  p.ranges = Y(p.ranges);
245
- const i = C.reduce((d, l) => {
245
+ const c = C.reduce((d, l) => {
246
246
  const v = h.getCellRaw(l.row, l.col);
247
247
  if (v) {
248
248
  const U = H(v.v);
@@ -250,7 +250,7 @@ const De = [
250
250
  }
251
251
  return d;
252
252
  }, new R()).getMatrix(), g = new R();
253
- new R(i).forValue((d, l) => {
253
+ new R(c).forValue((d, l) => {
254
254
  const v = h.getCellRaw(d, l);
255
255
  v ? g.setValue(d, l, { t: v.t }) : g.setValue(d, l, { t: void 0 });
256
256
  }), b.push({
@@ -261,7 +261,7 @@ const De = [
261
261
  params: {
262
262
  unitId: u,
263
263
  subUnitId: o,
264
- cellValue: i
264
+ cellValue: c
265
265
  }
266
266
  });
267
267
  const S = Me(e, p);
@@ -294,8 +294,8 @@ const De = [
294
294
  let f = 0;
295
295
  a.forEach((b) => {
296
296
  E.foreach(b.range, (_, m) => {
297
- const i = n.getValue(o, h, _, m);
298
- if (!i) {
297
+ const c = n.getValue(o, h, _, m);
298
+ if (!c) {
299
299
  const S = u.worksheet.getCellRaw(_, m);
300
300
  if (!f && S && S.t === M.NUMBER && S.v) {
301
301
  const d = /\.(\d*)$/.exec(String(S.v));
@@ -308,23 +308,23 @@ const De = [
308
308
  }
309
309
  return;
310
310
  }
311
- const g = F(i.pattern);
311
+ const g = F(c.pattern);
312
312
  f = g > f ? g : f;
313
313
  });
314
314
  });
315
315
  const C = f + 1, y = D(`0${C > 0 ? ".0" : ""}`, C), p = [];
316
316
  return a.forEach((b) => {
317
317
  E.foreach(b.range, (_, m) => {
318
- const i = n.getValue(o, h, _, m);
319
- if (W(i == null ? void 0 : i.pattern))
318
+ const c = n.getValue(o, h, _, m);
319
+ if (W(c == null ? void 0 : c.pattern))
320
320
  p.push({
321
321
  row: _,
322
322
  col: m,
323
323
  pattern: y
324
324
  });
325
325
  else {
326
- const g = F(i.pattern), S = D(i.pattern, g + 1);
327
- S !== i.pattern && p.push({
326
+ const g = F(c.pattern), S = D(c.pattern, g + 1);
327
+ S !== c.pattern && p.push({
328
328
  row: _,
329
329
  col: m,
330
330
  pattern: S
@@ -373,10 +373,10 @@ const De = [
373
373
  const { unitId: o, subUnitId: h } = u;
374
374
  let f = 0;
375
375
  a.forEach((_) => {
376
- E.foreach(_.range, (m, i) => {
377
- const g = n.getValue(o, h, m, i);
376
+ E.foreach(_.range, (m, c) => {
377
+ const g = n.getValue(o, h, m, c);
378
378
  if (!g) {
379
- const d = u.worksheet.getCellRaw(m, i);
379
+ const d = u.worksheet.getCellRaw(m, c);
380
380
  if (!f && d && d.t === M.NUMBER && d.v) {
381
381
  const l = /\.(\d*)$/.exec(String(d.v));
382
382
  if (l) {
@@ -394,26 +394,26 @@ const De = [
394
394
  });
395
395
  const C = f - 1, y = D(`0${C > 0 ? ".0" : "."}`, C), p = [];
396
396
  return a.forEach((_) => {
397
- E.foreach(_.range, (m, i) => {
398
- const g = n.getValue(o, h, m, i);
397
+ E.foreach(_.range, (m, c) => {
398
+ const g = n.getValue(o, h, m, c);
399
399
  if (W(g == null ? void 0 : g.pattern))
400
400
  p.push({
401
401
  row: m,
402
- col: i,
402
+ col: c,
403
403
  pattern: y
404
404
  });
405
405
  else {
406
406
  const S = F(g.pattern);
407
407
  p.push({
408
408
  row: m,
409
- col: i,
409
+ col: c,
410
410
  pattern: D(g.pattern, S - 1)
411
411
  });
412
412
  }
413
413
  });
414
414
  }), await r.executeCommand(w.id, { values: p });
415
415
  }
416
- }, oe = "sheets-numfmt.config", J = {}, it = (e) => P.getFormatInfo(e).type || "unknown", He = (e, r, t = "en") => {
416
+ }, oe = "sheets-numfmt.config", J = {}, ct = (e) => P.getFormatInfo(e).type || "unknown", He = (e, r, t = "en") => {
417
417
  try {
418
418
  const n = P.formatColor(e, r), s = n ? String(n) : void 0, a = P.format(e, r, { locale: t, throws: !1 });
419
419
  return r < 0 ? {
@@ -455,25 +455,25 @@ let A = class extends de {
455
455
  if (r)
456
456
  return r;
457
457
  switch (this._localeService.getCurrentLocale()) {
458
- case c.FR_FR:
458
+ case i.FR_FR:
459
459
  return "fr";
460
- case c.RU_RU:
460
+ case i.RU_RU:
461
461
  return "ru";
462
- case c.VI_VN:
462
+ case i.VI_VN:
463
463
  return "vi";
464
- case c.ZH_CN:
464
+ case i.ZH_CN:
465
465
  return "zh-CN";
466
- case c.KO_KR:
466
+ case i.KO_KR:
467
467
  return "ko";
468
- case c.ZH_TW:
468
+ case i.ZH_TW:
469
469
  return "zh-TW";
470
- case c.ES_ES:
471
- case c.CA_ES:
470
+ case i.ES_ES:
471
+ case i.CA_ES:
472
472
  return "es";
473
- case c.SK_SK:
473
+ case i.SK_SK:
474
474
  return "sk";
475
- case c.EN_US:
476
- case c.FA_IR:
475
+ case i.EN_US:
476
+ case i.FA_IR:
477
477
  default:
478
478
  return "en";
479
479
  }
@@ -536,7 +536,7 @@ let A = class extends de {
536
536
  });
537
537
  }
538
538
  })), this.disposeWithMe(
539
- this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
539
+ this._instanceService.getCurrentTypeOfUnit$(re.UNIVER_SHEET).pipe(
540
540
  Ue((t) => {
541
541
  var n;
542
542
  return (n = t == null ? void 0 : t.activeSheet$) != null ? n : Oe(null);
@@ -556,9 +556,9 @@ A = ke([
556
556
  N(3, I($)),
557
557
  N(4, I(Z)),
558
558
  N(5, I(ee)),
559
- N(6, re)
559
+ N(6, te)
560
560
  ], A);
561
- const ze = "@univerjs/sheets-numfmt", Ye = "0.16.1-insiders.20260311-074e8ca", ae = {
561
+ const ze = "@univerjs/sheets-numfmt", Ye = "0.17.0", ae = {
562
562
  name: ze,
563
563
  version: Ye
564
564
  }, qe = "SHEET_NUMFMT_PLUGIN";
@@ -596,14 +596,14 @@ let T = class extends pe {
596
596
  L(T, "pluginName", qe);
597
597
  L(T, "packageName", ae.name);
598
598
  L(T, "version", ae.version);
599
- L(T, "type", te.UNIVER_SHEET);
599
+ L(T, "type", re.UNIVER_SHEET);
600
600
  T = et([
601
601
  ge($e),
602
602
  B(1, I(he)),
603
- B(2, re),
603
+ B(2, te),
604
604
  B(3, $)
605
605
  ], T);
606
- const ct = (e) => se.find((t) => e.includes(t)), lt = () => se.map((e) => ({ label: e, value: e })), ut = (e) => Ve.map((r) => ({
606
+ const it = (e) => se.find((t) => e.includes(t)), lt = () => se.map((e) => ({ label: e, value: e })), ut = (e) => Ve.map((r) => ({
607
607
  label: r.label(e),
608
608
  value: r.suffix(e),
609
609
  color: r.color
@@ -626,14 +626,14 @@ export {
626
626
  lt as getCurrencyOptions,
627
627
  q as getCurrencySymbolByLocale,
628
628
  Pe as getCurrencySymbolIconByLocale,
629
- ct as getCurrencyType,
629
+ it as getCurrencyType,
630
630
  ft as getDateFormatOptions,
631
631
  F as getDecimalFromPattern,
632
632
  X as getDecimalString,
633
633
  mt as getNumberFormatOptions,
634
634
  He as getPatternPreview,
635
635
  Ge as getPatternPreviewIgnoreGeneral,
636
- it as getPatternType,
636
+ ct as getPatternType,
637
637
  at as isPatternHasDecimal,
638
638
  x as localeCurrencySymbolMap,
639
639
  D as setPatternDecimal
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
- var ie = Object.defineProperty;
2
- var ce = (e, r, t) => r in e ? ie(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
- var K = (e, r, t) => ce(e, typeof r != "symbol" ? r + "" : r, t);
4
- import { LocaleType as c, numfmt as P, CommandType as O, ICommandService as $, IUniverInstanceService as V, IUndoRedoService as le, isTextFormat as Q, CellValueType as M, ObjectMatrix as R, sequenceExecute as ue, Range as E, isDefaultFormat as W, LocaleService as ee, DEFAULT_NUMBER_FORMAT as fe, Inject as I, ThemeService as me, Disposable as de, InterceptorEffectEnum as z, UniverInstanceType as te, IConfigService as re, DependentOn as ge, Injector as he, Plugin as pe, merge as _e, registerDependencies as Se, touchDependencies as ve } from "@univerjs/core";
1
+ var ce = Object.defineProperty;
2
+ var ie = (e, r, t) => r in e ? ce(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
+ var K = (e, r, t) => ie(e, typeof r != "symbol" ? r + "" : r, t);
4
+ import { LocaleType as i, numfmt as P, CommandType as O, ICommandService as $, IUniverInstanceService as V, IUndoRedoService as le, isTextFormat as Q, CellValueType as M, ObjectMatrix as R, sequenceExecute as ue, Range as E, isDefaultFormat as W, LocaleService as ee, DEFAULT_NUMBER_FORMAT as fe, Inject as I, ThemeService as me, IConfigService as te, Disposable as de, InterceptorEffectEnum as z, UniverInstanceType as re, DependentOn as ge, Injector as he, Plugin as pe, merge as _e, registerDependencies as Se, touchDependencies as ve } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as k, transformCellsToRange as Ce, checkCellValueType as H, rangeMerge as Y, SetNumfmtMutation as ne, factorySetNumfmtUndoMutation as ye, RemoveNumfmtMutation as be, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as Me, SheetsSelectionsService as j, INumfmtService as Z, SheetInterceptorService as Re, INTERCEPTOR_POINT as Ne, InterceptCellContentPriority as Ee, UniverSheetsPlugin as $e } from "@univerjs/sheets";
6
6
  import { BehaviorSubject as Ie, merge as Te, switchMap as Ue, of as Oe, skip as we } from "rxjs";
7
7
  import { stripErrorMargin as xe } from "@univerjs/engine-formula";
@@ -35,47 +35,47 @@ const se = [
35
35
  "₿",
36
36
  "﷼"
37
37
  ], x = /* @__PURE__ */ new Map([
38
- [c.EN_US, "$"],
39
- [c.RU_RU, "₽"],
40
- [c.VI_VN, "₫"],
41
- [c.ZH_CN, "¥"],
42
- [c.ZH_TW, "NT$"],
43
- [c.FR_FR, "€"],
44
- [c.FA_IR, "﷼"],
45
- [c.KO_KR, "₩"],
46
- [c.ES_ES, "€"],
47
- [c.CA_ES, "€"],
48
- [c.SK_SK, "€"]
38
+ [i.EN_US, "$"],
39
+ [i.RU_RU, "₽"],
40
+ [i.VI_VN, "₫"],
41
+ [i.ZH_CN, "¥"],
42
+ [i.ZH_TW, "NT$"],
43
+ [i.FR_FR, "€"],
44
+ [i.FA_IR, "﷼"],
45
+ [i.KO_KR, "₩"],
46
+ [i.ES_ES, "€"],
47
+ [i.CA_ES, "€"],
48
+ [i.SK_SK, "€"]
49
49
  ]);
50
50
  function Pe(e) {
51
51
  switch (e) {
52
- case c.CA_ES:
53
- case c.ES_ES:
54
- case c.FR_FR:
55
- case c.SK_SK:
52
+ case i.CA_ES:
53
+ case i.ES_ES:
54
+ case i.FR_FR:
55
+ case i.SK_SK:
56
56
  return {
57
57
  icon: "EuroIcon",
58
58
  symbol: x.get(e) || "€",
59
59
  locale: e
60
60
  };
61
- case c.RU_RU:
61
+ case i.RU_RU:
62
62
  return {
63
63
  icon: "RoubleIcon",
64
64
  symbol: x.get(e) || "₽",
65
65
  locale: e
66
66
  };
67
- case c.ZH_CN:
67
+ case i.ZH_CN:
68
68
  return {
69
69
  icon: "RmbIcon",
70
70
  symbol: x.get(e) || "¥",
71
71
  locale: e
72
72
  };
73
- case c.EN_US:
73
+ case i.EN_US:
74
74
  default:
75
75
  return {
76
76
  icon: "DollarIcon",
77
77
  symbol: "$",
78
- locale: c.EN_US
78
+ locale: i.EN_US
79
79
  };
80
80
  }
81
81
  }
@@ -207,18 +207,18 @@ const De = [
207
207
  return !1;
208
208
  const t = e.get($), n = e.get(V), s = e.get(le), a = k(n, r);
209
209
  if (!a) return !1;
210
- const { unitId: u, subUnitId: o, worksheet: h } = a, f = r.values.filter((i) => !!i.pattern), C = r.values.filter((i) => !i.pattern), y = Ce(u, o, f), p = {
210
+ const { unitId: u, subUnitId: o, worksheet: h } = a, f = r.values.filter((c) => !!c.pattern), C = r.values.filter((c) => !c.pattern), y = Ce(u, o, f), p = {
211
211
  unitId: u,
212
212
  subUnitId: o,
213
- ranges: C.map((i) => ({
214
- startColumn: i.col,
215
- startRow: i.row,
216
- endColumn: i.col,
217
- endRow: i.row
213
+ ranges: C.map((c) => ({
214
+ startColumn: c.col,
215
+ startRow: c.row,
216
+ endColumn: c.col,
217
+ endRow: c.row
218
218
  }))
219
219
  }, b = [], _ = [];
220
220
  if (f.length) {
221
- const i = f.reduce((d, l) => {
221
+ const c = f.reduce((d, l) => {
222
222
  Q(l.pattern) && d.setValue(l.row, l.col, { t: M.STRING });
223
223
  const v = h.getCellRaw(l.row, l.col);
224
224
  if (v) {
@@ -227,7 +227,7 @@ const De = [
227
227
  }
228
228
  return d;
229
229
  }, new R()).getMatrix(), g = new R();
230
- new R(i).forValue((d, l) => {
230
+ new R(c).forValue((d, l) => {
231
231
  const v = h.getCellRaw(d, l);
232
232
  v ? g.setValue(d, l, { t: v.t }) : g.setValue(d, l, { t: void 0 });
233
233
  }), Object.keys(y.values).forEach((d) => {
@@ -242,7 +242,7 @@ const De = [
242
242
  }
243
243
  if (C.length) {
244
244
  p.ranges = Y(p.ranges);
245
- const i = C.reduce((d, l) => {
245
+ const c = C.reduce((d, l) => {
246
246
  const v = h.getCellRaw(l.row, l.col);
247
247
  if (v) {
248
248
  const U = H(v.v);
@@ -250,7 +250,7 @@ const De = [
250
250
  }
251
251
  return d;
252
252
  }, new R()).getMatrix(), g = new R();
253
- new R(i).forValue((d, l) => {
253
+ new R(c).forValue((d, l) => {
254
254
  const v = h.getCellRaw(d, l);
255
255
  v ? g.setValue(d, l, { t: v.t }) : g.setValue(d, l, { t: void 0 });
256
256
  }), b.push({
@@ -261,7 +261,7 @@ const De = [
261
261
  params: {
262
262
  unitId: u,
263
263
  subUnitId: o,
264
- cellValue: i
264
+ cellValue: c
265
265
  }
266
266
  });
267
267
  const S = Me(e, p);
@@ -294,8 +294,8 @@ const De = [
294
294
  let f = 0;
295
295
  a.forEach((b) => {
296
296
  E.foreach(b.range, (_, m) => {
297
- const i = n.getValue(o, h, _, m);
298
- if (!i) {
297
+ const c = n.getValue(o, h, _, m);
298
+ if (!c) {
299
299
  const S = u.worksheet.getCellRaw(_, m);
300
300
  if (!f && S && S.t === M.NUMBER && S.v) {
301
301
  const d = /\.(\d*)$/.exec(String(S.v));
@@ -308,23 +308,23 @@ const De = [
308
308
  }
309
309
  return;
310
310
  }
311
- const g = F(i.pattern);
311
+ const g = F(c.pattern);
312
312
  f = g > f ? g : f;
313
313
  });
314
314
  });
315
315
  const C = f + 1, y = D(`0${C > 0 ? ".0" : ""}`, C), p = [];
316
316
  return a.forEach((b) => {
317
317
  E.foreach(b.range, (_, m) => {
318
- const i = n.getValue(o, h, _, m);
319
- if (W(i == null ? void 0 : i.pattern))
318
+ const c = n.getValue(o, h, _, m);
319
+ if (W(c == null ? void 0 : c.pattern))
320
320
  p.push({
321
321
  row: _,
322
322
  col: m,
323
323
  pattern: y
324
324
  });
325
325
  else {
326
- const g = F(i.pattern), S = D(i.pattern, g + 1);
327
- S !== i.pattern && p.push({
326
+ const g = F(c.pattern), S = D(c.pattern, g + 1);
327
+ S !== c.pattern && p.push({
328
328
  row: _,
329
329
  col: m,
330
330
  pattern: S
@@ -373,10 +373,10 @@ const De = [
373
373
  const { unitId: o, subUnitId: h } = u;
374
374
  let f = 0;
375
375
  a.forEach((_) => {
376
- E.foreach(_.range, (m, i) => {
377
- const g = n.getValue(o, h, m, i);
376
+ E.foreach(_.range, (m, c) => {
377
+ const g = n.getValue(o, h, m, c);
378
378
  if (!g) {
379
- const d = u.worksheet.getCellRaw(m, i);
379
+ const d = u.worksheet.getCellRaw(m, c);
380
380
  if (!f && d && d.t === M.NUMBER && d.v) {
381
381
  const l = /\.(\d*)$/.exec(String(d.v));
382
382
  if (l) {
@@ -394,26 +394,26 @@ const De = [
394
394
  });
395
395
  const C = f - 1, y = D(`0${C > 0 ? ".0" : "."}`, C), p = [];
396
396
  return a.forEach((_) => {
397
- E.foreach(_.range, (m, i) => {
398
- const g = n.getValue(o, h, m, i);
397
+ E.foreach(_.range, (m, c) => {
398
+ const g = n.getValue(o, h, m, c);
399
399
  if (W(g == null ? void 0 : g.pattern))
400
400
  p.push({
401
401
  row: m,
402
- col: i,
402
+ col: c,
403
403
  pattern: y
404
404
  });
405
405
  else {
406
406
  const S = F(g.pattern);
407
407
  p.push({
408
408
  row: m,
409
- col: i,
409
+ col: c,
410
410
  pattern: D(g.pattern, S - 1)
411
411
  });
412
412
  }
413
413
  });
414
414
  }), await r.executeCommand(w.id, { values: p });
415
415
  }
416
- }, oe = "sheets-numfmt.config", J = {}, it = (e) => P.getFormatInfo(e).type || "unknown", He = (e, r, t = "en") => {
416
+ }, oe = "sheets-numfmt.config", J = {}, ct = (e) => P.getFormatInfo(e).type || "unknown", He = (e, r, t = "en") => {
417
417
  try {
418
418
  const n = P.formatColor(e, r), s = n ? String(n) : void 0, a = P.format(e, r, { locale: t, throws: !1 });
419
419
  return r < 0 ? {
@@ -455,25 +455,25 @@ let A = class extends de {
455
455
  if (r)
456
456
  return r;
457
457
  switch (this._localeService.getCurrentLocale()) {
458
- case c.FR_FR:
458
+ case i.FR_FR:
459
459
  return "fr";
460
- case c.RU_RU:
460
+ case i.RU_RU:
461
461
  return "ru";
462
- case c.VI_VN:
462
+ case i.VI_VN:
463
463
  return "vi";
464
- case c.ZH_CN:
464
+ case i.ZH_CN:
465
465
  return "zh-CN";
466
- case c.KO_KR:
466
+ case i.KO_KR:
467
467
  return "ko";
468
- case c.ZH_TW:
468
+ case i.ZH_TW:
469
469
  return "zh-TW";
470
- case c.ES_ES:
471
- case c.CA_ES:
470
+ case i.ES_ES:
471
+ case i.CA_ES:
472
472
  return "es";
473
- case c.SK_SK:
473
+ case i.SK_SK:
474
474
  return "sk";
475
- case c.EN_US:
476
- case c.FA_IR:
475
+ case i.EN_US:
476
+ case i.FA_IR:
477
477
  default:
478
478
  return "en";
479
479
  }
@@ -536,7 +536,7 @@ let A = class extends de {
536
536
  });
537
537
  }
538
538
  })), this.disposeWithMe(
539
- this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
539
+ this._instanceService.getCurrentTypeOfUnit$(re.UNIVER_SHEET).pipe(
540
540
  Ue((t) => {
541
541
  var n;
542
542
  return (n = t == null ? void 0 : t.activeSheet$) != null ? n : Oe(null);
@@ -556,9 +556,9 @@ A = ke([
556
556
  N(3, I($)),
557
557
  N(4, I(Z)),
558
558
  N(5, I(ee)),
559
- N(6, re)
559
+ N(6, te)
560
560
  ], A);
561
- const ze = "@univerjs/sheets-numfmt", Ye = "0.16.1-insiders.20260311-074e8ca", ae = {
561
+ const ze = "@univerjs/sheets-numfmt", Ye = "0.17.0", ae = {
562
562
  name: ze,
563
563
  version: Ye
564
564
  }, qe = "SHEET_NUMFMT_PLUGIN";
@@ -596,14 +596,14 @@ let T = class extends pe {
596
596
  L(T, "pluginName", qe);
597
597
  L(T, "packageName", ae.name);
598
598
  L(T, "version", ae.version);
599
- L(T, "type", te.UNIVER_SHEET);
599
+ L(T, "type", re.UNIVER_SHEET);
600
600
  T = et([
601
601
  ge($e),
602
602
  B(1, I(he)),
603
- B(2, re),
603
+ B(2, te),
604
604
  B(3, $)
605
605
  ], T);
606
- const ct = (e) => se.find((t) => e.includes(t)), lt = () => se.map((e) => ({ label: e, value: e })), ut = (e) => Ve.map((r) => ({
606
+ const it = (e) => se.find((t) => e.includes(t)), lt = () => se.map((e) => ({ label: e, value: e })), ut = (e) => Ve.map((r) => ({
607
607
  label: r.label(e),
608
608
  value: r.suffix(e),
609
609
  color: r.color
@@ -626,14 +626,14 @@ export {
626
626
  lt as getCurrencyOptions,
627
627
  q as getCurrencySymbolByLocale,
628
628
  Pe as getCurrencySymbolIconByLocale,
629
- ct as getCurrencyType,
629
+ it as getCurrencyType,
630
630
  ft as getDateFormatOptions,
631
631
  F as getDecimalFromPattern,
632
632
  X as getDecimalString,
633
633
  mt as getNumberFormatOptions,
634
634
  He as getPatternPreview,
635
635
  Ge as getPatternPreviewIgnoreGeneral,
636
- it as getPatternType,
636
+ ct as getPatternType,
637
637
  at as isPatternHasDecimal,
638
638
  x as localeCurrencySymbolMap,
639
639
  D as setPatternDecimal
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(r,e){typeof exports=="object"&&typeof module<"u"?e(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"],e):(r=typeof globalThis<"u"?globalThis:r||self,e(r.UniverSheetsNumfmt={},r.UniverCore,r.UniverSheets,r.rxjs,r.UniverEngineFormula))})(this,(function(r,e,u,I,J){"use strict";var ge=Object.defineProperty;var Se=(r,e,u)=>e in r?ge(r,e,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[e]=u;var V=(r,e,u)=>Se(r,typeof e!="symbol"?e+"":e,u);const L=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[e.LocaleType.EN_US,"$"],[e.LocaleType.RU_RU,"₽"],[e.LocaleType.VI_VN,"₫"],[e.LocaleType.ZH_CN,"¥"],[e.LocaleType.ZH_TW,"NT$"],[e.LocaleType.FR_FR,"€"],[e.LocaleType.FA_IR,"﷼"],[e.LocaleType.KO_KR,"₩"],[e.LocaleType.ES_ES,"€"],[e.LocaleType.CA_ES,"€"],[e.LocaleType.SK_SK,"€"]]);function A(t){switch(t){case e.LocaleType.CA_ES:case e.LocaleType.ES_ES:case e.LocaleType.FR_FR:case e.LocaleType.SK_SK:return{icon:"EuroIcon",symbol:E.get(t)||"€",locale:t};case e.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(t)||"₽",locale:t};case e.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(t)||"¥",locale:t};case e.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:e.LocaleType.EN_US}}}function F(t){return E.get(t)||"$"}function B(t,a=2){let i=a;a>127&&(i=127);let n="";return i>0&&(n=`.${"0".repeat(i)}`),`"${F(t)}"#,##0${n}_);[Red]("${F(t)}"#,##0${n})`}const G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],H=[{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"}],K=[{label:t=>`${t}1,235`,suffix:t=>`"${t}"#,##0.00_);"${t}"#,##0.00`},{label:t=>`${t}1,235`,suffix:t=>`"${t}"#,##0.00_);[Red]"${t}"#,##0.00`,color:"red"},{label:t=>`(${t}1,235)`,suffix:t=>`"${t}"#,##0.00_);("${t}"#,##0.00)`},{label:t=>`(${t}1,235)`,suffix:t=>`"${t}"#,##0.00_);[Red]("${t}"#,##0.00)`,color:"red"},{label:t=>`-${t}1,235`,suffix:t=>`"${t}"#,##0.00_);-"${t}"#,##0.00`},{label:t=>`-${t}1,235`,suffix:t=>`"${t}"#,##0.00_);[Red]-"${t}"#,##0.00`,color:"red"}],U=(t,a=0)=>{var n;return t&&(n=e.numfmt.getFormatInfo(t).maxDecimals)!=null?n:a},D=t=>new Array(Math.min(Math.max(0,Number(t)),30)).fill(0).join(""),$=(t,a)=>t.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${D(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${D(Number(a||0))}$1`):n).join(";"),Q=t=>/\.0?/.test(t)||/0([^0]?)|0$/.test(t),R={id:"sheet.command.numfmt.set.numfmt",type:e.CommandType.COMMAND,handler:(t,a)=>{if(!a)return!1;const i=t.get(e.ICommandService),n=t.get(e.IUniverInstanceService),s=t.get(e.IUndoRedoService),l=u.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:o}=l,f=a.values.filter(c=>!!c.pattern),T=a.values.filter(c=>!c.pattern),M=u.transformCellsToRange(m,S,f),C={unitId:m,subUnitId:S,ranges:T.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},b=[],p=[];if(f.length){const c=f.reduce((g,d)=>{e.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:e.CellValueType.STRING});const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new e.ObjectMatrix).getMatrix(),v=new e.ObjectMatrix;new e.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=u.rangeMerge(d.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const h=u.factorySetNumfmtUndoMutation(t,M);p.push(...h)}if(T.length){C.ranges=u.rangeMerge(C.ranges);const c=T.reduce((g,d)=>{const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new e.ObjectMatrix).getMatrix(),v=new e.ObjectMatrix;new e.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:C},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const h=u.factoryRemoveNumfmtUndoMutation(t,C);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:v.getMatrix()}},...h)}const y=e.sequenceExecute(b,i).result;return y&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),y}},x={id:"sheet.command.numfmt.add.decimal.command",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),i=t.get(u.SheetsSelectionsService),n=t.get(u.INumfmtService),s=t.get(e.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(b=>{e.Range.foreach(b.range,(p,y)=>{const c=n.getValue(S,o,p,y);if(!c){const h=m.worksheet.getCellRaw(p,y);if(!f&&h&&h.t===e.CellValueType.NUMBER&&h.v){const g=/\.(\d*)$/.exec(String(h.v));if(g){const d=g[1].length;if(!d)return;f=Math.max(f,d)}}return}const v=U(c.pattern);f=v>f?v:f})});const T=f+1,M=$(`0${T>0?".0":""}`,T),C=[];return l.forEach(b=>{e.Range.foreach(b.range,(p,y)=>{const c=n.getValue(S,o,p,y);if(e.isDefaultFormat(c==null?void 0:c.pattern))C.push({row:p,col:y,pattern:M});else{const v=U(c.pattern),h=$(c.pattern,v+1);h!==c.pattern&&C.push({row:p,col:y,pattern:h})}})}),C.length?await a.executeCommand(R.id,{values:C}):!1}},W={id:"sheet.command.numfmt.set.currency",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),i=t.get(u.SheetsSelectionsService),n=t.get(e.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=A(n.getCurrentLocale()),S=B(m.locale);return s.forEach(f=>{e.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(R.id,{values:l})}},k={id:"sheet.command.numfmt.set.percent",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),n=t.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{e.Range.foreach(S.range,(o,f)=>{s.push({row:o,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),i=t.get(u.SheetsSelectionsService),n=t.get(u.INumfmtService),s=t.get(e.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(p=>{e.Range.foreach(p.range,(y,c)=>{const v=n.getValue(S,o,y,c);if(!v){const g=m.worksheet.getCellRaw(y,c);if(!f&&g&&g.t===e.CellValueType.NUMBER&&g.v){const d=/\.(\d*)$/.exec(String(g.v));if(d){const _=d[1].length;if(!_)return;f=Math.max(f,_)}}return}const h=U(v.pattern);f=h>f?h:f})});const T=f-1,M=$(`0${T>0?".0":"."}`,T),C=[];return l.forEach(p=>{e.Range.foreach(p.range,(y,c)=>{const v=n.getValue(S,o,y,c);if(e.isDefaultFormat(v==null?void 0:v.pattern))C.push({row:y,col:c,pattern:M});else{const h=U(v.pattern);C.push({row:y,col:c,pattern:$(v.pattern,h-1)})}})}),await a.executeCommand(R.id,{values:C})}},w="sheets-numfmt.config",Z={},ee=t=>e.numfmt.getFormatInfo(t).type||"unknown",Y=(t,a,i="en")=>{try{const n=e.numfmt.formatColor(t,a),s=n?String(n):void 0,l=e.numfmt.format(t,a,{locale:i,throws:!1});return a<0?{result:l,color:s}:{result:l}}catch(n){console.warn("getPatternPreview error:",t,n)}return{result:String(a)}},z=(t,a,i)=>t===e.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(a))}:Y(t,a,i);var te=Object.getOwnPropertyDescriptor,ne=(t,a,i,n)=>{for(var s=n>1?void 0:n?te(a,i):a,l=t.length-1,m;l>=0;l--)(m=t[l])&&(s=m(s)||s);return s},N=(t,a)=>(i,n)=>a(i,n,t);const ae={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends e.Disposable{constructor(i,n,s,l,m,S,o){super();V(this,"_locale$",new I.BehaviorSubject("en"));V(this,"locale$",this._locale$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=o,this._initInterceptorCellContent()}get locale(){const i=this._locale$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case e.LocaleType.FR_FR:return"fr";case e.LocaleType.RU_RU:return"ru";case e.LocaleType.VI_VN:return"vi";case e.LocaleType.ZH_CN:return"zh-CN";case e.LocaleType.KO_KR:return"ko";case e.LocaleType.ZH_TW:return"zh-TW";case e.LocaleType.ES_ES:case e.LocaleType.CA_ES:return"es";case e.LocaleType.SK_SK:return"sk";case e.LocaleType.EN_US:case e.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new e.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:e.InterceptorEffectEnum.Value|e.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,y;if(!n||n.v===void 0||n.v===null||n.t===e.CellValueType.BOOLEAN||n.t===e.CellValueType.FORCE_STRING)return l(n);const m=s.unitId,S=s.subUnitId;let o;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(o=c.n)}if(o||(o=this._numfmtService.getValue(m,S,s.row,s.col)),e.isDefaultFormat(o==null?void 0:o.pattern)||n.t!==e.CellValueType.NUMBER&&u.checkCellValueType(n.v,n.t)!==e.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),e.isTextFormat(o==null?void 0:o.pattern))return(p=this._configService.getConfig(w))!=null&&p.disableTextFormatMark?(n.t=e.CellValueType.STRING,l(n)):(n.t=e.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ae},l(n));let T="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${o==null?void 0:o.pattern}`)return l({...n,...M.result});const C=z(o==null?void 0:o.pattern,Number(f.v),this.locale);if(T=C.result,!T)return l(n);const b={v:T,t:e.CellValueType.NUMBER};if(C.color){const c=(y=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?y:C.color;c&&(b.interceptorStyle={cl:{rgb:c}})}return i.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${o==null?void 0:o.pattern}`}),Object.assign(n,b),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{e.Range.foreach(S,(o,f)=>{i.realDeleteValue(o,f)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new e.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},r.SheetsNumfmtCellContentController=ne([N(0,e.IUniverInstanceService),N(1,e.Inject(u.SheetInterceptorService)),N(2,e.Inject(e.ThemeService)),N(3,e.Inject(e.ICommandService)),N(4,e.Inject(u.INumfmtService)),N(5,e.Inject(e.LocaleService)),N(6,e.IConfigService)],r.SheetsNumfmtCellContentController);const X={name:"@univerjs/sheets-numfmt",version:"0.16.1-insiders.20260311-074e8ca"},re="SHEET_NUMFMT_PLUGIN";var ie=Object.defineProperty,se=Object.getOwnPropertyDescriptor,le=(t,a,i)=>a in t?ie(t,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[a]=i,ce=(t,a,i,n)=>{for(var s=n>1?void 0:n?se(a,i):a,l=t.length-1,m;l>=0;l--)(m=t[l])&&(s=m(s)||s);return s},j=(t,a)=>(i,n)=>a(i,n,t),P=(t,a,i)=>le(t,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends e.Plugin{constructor(a=Z,i,n,s){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=s;const{...l}=e.merge({},Z,this._config);this._configService.setConfig(w,l)}onStarting(){e.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),e.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),[x,q,W,k,R].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},P(r.UniverSheetsNumfmtPlugin,"pluginName",re),P(r.UniverSheetsNumfmtPlugin,"packageName",X.name),P(r.UniverSheetsNumfmtPlugin,"version",X.version),P(r.UniverSheetsNumfmtPlugin,"type",e.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=ce([e.DependentOn(u.UniverSheetsPlugin),j(1,e.Inject(e.Injector)),j(2,e.IConfigService),j(3,e.ICommandService)],r.UniverSheetsNumfmtPlugin);const oe=t=>L.find(i=>t.includes(i)),ue=()=>L.map(t=>({label:t,value:t})),me=t=>K.map(a=>({label:a.label(t),value:a.suffix(t),color:a.color})),fe=()=>G.map(t=>({label:t.label,value:t.suffix})),de=()=>H.map(t=>({label:t.label,value:t.suffix,color:t.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=K,r.DATEFMTLISG=G,r.NUMBERFORMAT=H,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,r.SetCurrencyCommand=W,r.SetNumfmtCommand=R,r.SetPercentCommand=k,r.SubtractDecimalCommand=q,r.currencySymbols=L,r.getCurrencyFormat=B,r.getCurrencyFormatOptions=me,r.getCurrencyOptions=ue,r.getCurrencySymbolByLocale=F,r.getCurrencySymbolIconByLocale=A,r.getCurrencyType=oe,r.getDateFormatOptions=fe,r.getDecimalFromPattern=U,r.getDecimalString=D,r.getNumberFormatOptions=de,r.getPatternPreview=Y,r.getPatternPreviewIgnoreGeneral=z,r.getPatternType=ee,r.isPatternHasDecimal=Q,r.localeCurrencySymbolMap=E,r.setPatternDecimal=$,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(r,e){typeof exports=="object"&&typeof module<"u"?e(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"],e):(r=typeof globalThis<"u"?globalThis:r||self,e(r.UniverSheetsNumfmt={},r.UniverCore,r.UniverSheets,r.rxjs,r.UniverEngineFormula))})(this,(function(r,e,u,I,J){"use strict";var ge=Object.defineProperty;var Se=(r,e,u)=>e in r?ge(r,e,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[e]=u;var V=(r,e,u)=>Se(r,typeof e!="symbol"?e+"":e,u);const L=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[e.LocaleType.EN_US,"$"],[e.LocaleType.RU_RU,"₽"],[e.LocaleType.VI_VN,"₫"],[e.LocaleType.ZH_CN,"¥"],[e.LocaleType.ZH_TW,"NT$"],[e.LocaleType.FR_FR,"€"],[e.LocaleType.FA_IR,"﷼"],[e.LocaleType.KO_KR,"₩"],[e.LocaleType.ES_ES,"€"],[e.LocaleType.CA_ES,"€"],[e.LocaleType.SK_SK,"€"]]);function A(t){switch(t){case e.LocaleType.CA_ES:case e.LocaleType.ES_ES:case e.LocaleType.FR_FR:case e.LocaleType.SK_SK:return{icon:"EuroIcon",symbol:E.get(t)||"€",locale:t};case e.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(t)||"₽",locale:t};case e.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(t)||"¥",locale:t};case e.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:e.LocaleType.EN_US}}}function F(t){return E.get(t)||"$"}function B(t,a=2){let i=a;a>127&&(i=127);let n="";return i>0&&(n=`.${"0".repeat(i)}`),`"${F(t)}"#,##0${n}_);[Red]("${F(t)}"#,##0${n})`}const G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],H=[{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"}],K=[{label:t=>`${t}1,235`,suffix:t=>`"${t}"#,##0.00_);"${t}"#,##0.00`},{label:t=>`${t}1,235`,suffix:t=>`"${t}"#,##0.00_);[Red]"${t}"#,##0.00`,color:"red"},{label:t=>`(${t}1,235)`,suffix:t=>`"${t}"#,##0.00_);("${t}"#,##0.00)`},{label:t=>`(${t}1,235)`,suffix:t=>`"${t}"#,##0.00_);[Red]("${t}"#,##0.00)`,color:"red"},{label:t=>`-${t}1,235`,suffix:t=>`"${t}"#,##0.00_);-"${t}"#,##0.00`},{label:t=>`-${t}1,235`,suffix:t=>`"${t}"#,##0.00_);[Red]-"${t}"#,##0.00`,color:"red"}],U=(t,a=0)=>{var n;return t&&(n=e.numfmt.getFormatInfo(t).maxDecimals)!=null?n:a},D=t=>new Array(Math.min(Math.max(0,Number(t)),30)).fill(0).join(""),$=(t,a)=>t.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${D(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${D(Number(a||0))}$1`):n).join(";"),Q=t=>/\.0?/.test(t)||/0([^0]?)|0$/.test(t),R={id:"sheet.command.numfmt.set.numfmt",type:e.CommandType.COMMAND,handler:(t,a)=>{if(!a)return!1;const i=t.get(e.ICommandService),n=t.get(e.IUniverInstanceService),s=t.get(e.IUndoRedoService),l=u.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:o}=l,f=a.values.filter(c=>!!c.pattern),T=a.values.filter(c=>!c.pattern),M=u.transformCellsToRange(m,S,f),C={unitId:m,subUnitId:S,ranges:T.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},b=[],p=[];if(f.length){const c=f.reduce((g,d)=>{e.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:e.CellValueType.STRING});const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new e.ObjectMatrix).getMatrix(),v=new e.ObjectMatrix;new e.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=u.rangeMerge(d.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const h=u.factorySetNumfmtUndoMutation(t,M);p.push(...h)}if(T.length){C.ranges=u.rangeMerge(C.ranges);const c=T.reduce((g,d)=>{const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new e.ObjectMatrix).getMatrix(),v=new e.ObjectMatrix;new e.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:C},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const h=u.factoryRemoveNumfmtUndoMutation(t,C);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:v.getMatrix()}},...h)}const y=e.sequenceExecute(b,i).result;return y&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),y}},x={id:"sheet.command.numfmt.add.decimal.command",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),i=t.get(u.SheetsSelectionsService),n=t.get(u.INumfmtService),s=t.get(e.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(b=>{e.Range.foreach(b.range,(p,y)=>{const c=n.getValue(S,o,p,y);if(!c){const h=m.worksheet.getCellRaw(p,y);if(!f&&h&&h.t===e.CellValueType.NUMBER&&h.v){const g=/\.(\d*)$/.exec(String(h.v));if(g){const d=g[1].length;if(!d)return;f=Math.max(f,d)}}return}const v=U(c.pattern);f=v>f?v:f})});const T=f+1,M=$(`0${T>0?".0":""}`,T),C=[];return l.forEach(b=>{e.Range.foreach(b.range,(p,y)=>{const c=n.getValue(S,o,p,y);if(e.isDefaultFormat(c==null?void 0:c.pattern))C.push({row:p,col:y,pattern:M});else{const v=U(c.pattern),h=$(c.pattern,v+1);h!==c.pattern&&C.push({row:p,col:y,pattern:h})}})}),C.length?await a.executeCommand(R.id,{values:C}):!1}},W={id:"sheet.command.numfmt.set.currency",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),i=t.get(u.SheetsSelectionsService),n=t.get(e.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=A(n.getCurrentLocale()),S=B(m.locale);return s.forEach(f=>{e.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(R.id,{values:l})}},k={id:"sheet.command.numfmt.set.percent",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),n=t.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{e.Range.foreach(S.range,(o,f)=>{s.push({row:o,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),i=t.get(u.SheetsSelectionsService),n=t.get(u.INumfmtService),s=t.get(e.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(p=>{e.Range.foreach(p.range,(y,c)=>{const v=n.getValue(S,o,y,c);if(!v){const g=m.worksheet.getCellRaw(y,c);if(!f&&g&&g.t===e.CellValueType.NUMBER&&g.v){const d=/\.(\d*)$/.exec(String(g.v));if(d){const _=d[1].length;if(!_)return;f=Math.max(f,_)}}return}const h=U(v.pattern);f=h>f?h:f})});const T=f-1,M=$(`0${T>0?".0":"."}`,T),C=[];return l.forEach(p=>{e.Range.foreach(p.range,(y,c)=>{const v=n.getValue(S,o,y,c);if(e.isDefaultFormat(v==null?void 0:v.pattern))C.push({row:y,col:c,pattern:M});else{const h=U(v.pattern);C.push({row:y,col:c,pattern:$(v.pattern,h-1)})}})}),await a.executeCommand(R.id,{values:C})}},w="sheets-numfmt.config",Z={},ee=t=>e.numfmt.getFormatInfo(t).type||"unknown",Y=(t,a,i="en")=>{try{const n=e.numfmt.formatColor(t,a),s=n?String(n):void 0,l=e.numfmt.format(t,a,{locale:i,throws:!1});return a<0?{result:l,color:s}:{result:l}}catch(n){console.warn("getPatternPreview error:",t,n)}return{result:String(a)}},z=(t,a,i)=>t===e.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(a))}:Y(t,a,i);var te=Object.getOwnPropertyDescriptor,ne=(t,a,i,n)=>{for(var s=n>1?void 0:n?te(a,i):a,l=t.length-1,m;l>=0;l--)(m=t[l])&&(s=m(s)||s);return s},N=(t,a)=>(i,n)=>a(i,n,t);const ae={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends e.Disposable{constructor(i,n,s,l,m,S,o){super();V(this,"_locale$",new I.BehaviorSubject("en"));V(this,"locale$",this._locale$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=o,this._initInterceptorCellContent()}get locale(){const i=this._locale$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case e.LocaleType.FR_FR:return"fr";case e.LocaleType.RU_RU:return"ru";case e.LocaleType.VI_VN:return"vi";case e.LocaleType.ZH_CN:return"zh-CN";case e.LocaleType.KO_KR:return"ko";case e.LocaleType.ZH_TW:return"zh-TW";case e.LocaleType.ES_ES:case e.LocaleType.CA_ES:return"es";case e.LocaleType.SK_SK:return"sk";case e.LocaleType.EN_US:case e.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new e.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:e.InterceptorEffectEnum.Value|e.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,y;if(!n||n.v===void 0||n.v===null||n.t===e.CellValueType.BOOLEAN||n.t===e.CellValueType.FORCE_STRING)return l(n);const m=s.unitId,S=s.subUnitId;let o;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(o=c.n)}if(o||(o=this._numfmtService.getValue(m,S,s.row,s.col)),e.isDefaultFormat(o==null?void 0:o.pattern)||n.t!==e.CellValueType.NUMBER&&u.checkCellValueType(n.v,n.t)!==e.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),e.isTextFormat(o==null?void 0:o.pattern))return(p=this._configService.getConfig(w))!=null&&p.disableTextFormatMark?(n.t=e.CellValueType.STRING,l(n)):(n.t=e.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ae},l(n));let T="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${o==null?void 0:o.pattern}`)return l({...n,...M.result});const C=z(o==null?void 0:o.pattern,Number(f.v),this.locale);if(T=C.result,!T)return l(n);const b={v:T,t:e.CellValueType.NUMBER};if(C.color){const c=(y=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?y:C.color;c&&(b.interceptorStyle={cl:{rgb:c}})}return i.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${o==null?void 0:o.pattern}`}),Object.assign(n,b),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{e.Range.foreach(S,(o,f)=>{i.realDeleteValue(o,f)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new e.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},r.SheetsNumfmtCellContentController=ne([N(0,e.IUniverInstanceService),N(1,e.Inject(u.SheetInterceptorService)),N(2,e.Inject(e.ThemeService)),N(3,e.Inject(e.ICommandService)),N(4,e.Inject(u.INumfmtService)),N(5,e.Inject(e.LocaleService)),N(6,e.IConfigService)],r.SheetsNumfmtCellContentController);const X={name:"@univerjs/sheets-numfmt",version:"0.17.0"},re="SHEET_NUMFMT_PLUGIN";var ie=Object.defineProperty,se=Object.getOwnPropertyDescriptor,le=(t,a,i)=>a in t?ie(t,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[a]=i,ce=(t,a,i,n)=>{for(var s=n>1?void 0:n?se(a,i):a,l=t.length-1,m;l>=0;l--)(m=t[l])&&(s=m(s)||s);return s},j=(t,a)=>(i,n)=>a(i,n,t),P=(t,a,i)=>le(t,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends e.Plugin{constructor(a=Z,i,n,s){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=s;const{...l}=e.merge({},Z,this._config);this._configService.setConfig(w,l)}onStarting(){e.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),e.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),[x,q,W,k,R].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},P(r.UniverSheetsNumfmtPlugin,"pluginName",re),P(r.UniverSheetsNumfmtPlugin,"packageName",X.name),P(r.UniverSheetsNumfmtPlugin,"version",X.version),P(r.UniverSheetsNumfmtPlugin,"type",e.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=ce([e.DependentOn(u.UniverSheetsPlugin),j(1,e.Inject(e.Injector)),j(2,e.IConfigService),j(3,e.ICommandService)],r.UniverSheetsNumfmtPlugin);const oe=t=>L.find(i=>t.includes(i)),ue=()=>L.map(t=>({label:t,value:t})),me=t=>K.map(a=>({label:a.label(t),value:a.suffix(t),color:a.color})),fe=()=>G.map(t=>({label:t.label,value:t.suffix})),de=()=>H.map(t=>({label:t.label,value:t.suffix,color:t.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=K,r.DATEFMTLISG=G,r.NUMBERFORMAT=H,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,r.SetCurrencyCommand=W,r.SetNumfmtCommand=R,r.SetPercentCommand=k,r.SubtractDecimalCommand=q,r.currencySymbols=L,r.getCurrencyFormat=B,r.getCurrencyFormatOptions=me,r.getCurrencyOptions=ue,r.getCurrencySymbolByLocale=F,r.getCurrencySymbolIconByLocale=A,r.getCurrencyType=oe,r.getDateFormatOptions=fe,r.getDecimalFromPattern=U,r.getDecimalString=D,r.getNumberFormatOptions=de,r.getPatternPreview=Y,r.getPatternPreviewIgnoreGeneral=z,r.getPatternType=ee,r.isPatternHasDecimal=Q,r.localeCurrencySymbolMap=E,r.setPatternDecimal=$,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt",
3
- "version": "0.16.1-insiders.20260311-074e8ca",
3
+ "version": "0.17.0",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -58,16 +58,16 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/core": "0.16.1-insiders.20260311-074e8ca",
62
- "@univerjs/engine-formula": "0.16.1-insiders.20260311-074e8ca",
63
- "@univerjs/sheets": "0.16.1-insiders.20260311-074e8ca"
61
+ "@univerjs/core": "0.17.0",
62
+ "@univerjs/engine-formula": "0.17.0",
63
+ "@univerjs/sheets": "0.17.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "rxjs": "^7.8.2",
67
67
  "typescript": "^5.9.3",
68
68
  "vite": "^7.3.1",
69
69
  "vitest": "^4.0.18",
70
- "@univerjs-infra/shared": "0.16.1"
70
+ "@univerjs-infra/shared": "0.17.0"
71
71
  },
72
72
  "scripts": {
73
73
  "test": "vitest run",