@univerjs/sheets-numfmt 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Z=Object.defineProperty;var J=(e,r,s)=>r in e?Z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var T=(e,r,s)=>J(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),m=require("@univerjs/sheets"),A=require("@univerjs/engine-numfmt"),N=require("rxjs"),X=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},U=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${U(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${U(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={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=m.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:g,worksheet:f}=o,i=r.values.filter(c=>!!c.pattern),b=r.values.filter(c=>!c.pattern),_=m.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:b.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],v=[];if(i.length){const c=i.reduce((d,u)=>{A.isTextFormat(u.pattern)&&d.setValue(u.row,u.col,{t:t.CellValueType.STRING});const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),Object.keys(_.values).forEach(d=>{const u=_.values[d];u.ranges=m.rangeMerge(u.ranges)}),M.push({id:m.SetNumfmtMutation.id,params:_});const p=m.factorySetNumfmtUndoMutation(e,_);v.push(...p)}if(b.length){h.ranges=m.rangeMerge(h.ranges);const c=b.reduce((d,u)=>{const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),M.push({id:m.RemoveNumfmtMutation.id,params:h},{id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const p=m.factoryRemoveNumfmtUndoMutation(e,h);v.push({id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:C.getMatrix()}},...p)}const S=t.sequenceExecute(M,s).result;return S&&a.pushUndoRedo({unitID:l,undoMutations:v,redoMutations:M}),S}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:g,subUnitId:f}=l;let i=0;o.forEach(M=>{t.Range.foreach(M.range,(v,S)=>{const c=n.getValue(g,f,v,S);if(!c){const p=l.worksheet.getCellRaw(v,S);if(!i&&p&&p.t===t.CellValueType.NUMBER&&p.v){const d=/\.(\d*)$/.exec(String(p.v));if(d){const u=d[1].length;if(!u)return;i=Math.max(i,u)}}return}const C=E(c.pattern);i=C>i?C:i})});const b=i+1,_=P(`0${b>0?".0":""}`,b),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(v,S)=>{const c=n.getValue(g,f,v,S);if(!c)h.push({row:v,col:S,pattern:_});else{const C=E(c.pattern),p=P(c.pattern,C+1);p!==c.pattern&&h.push({row:v,col:S,pattern:p})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(D),a=L[n.getCurrencySymbol()]||"$",o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=[],g=V[4].suffix(a);return o.forEach(i=>{t.Range.foreach(i.range,(b,_)=>{l.push({row:b,col:_,pattern:g,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},q={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(g=>{t.Range.foreach(g.range,(f,i)=>{a.push({row:f,col:i,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},K={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:g,subUnitId:f}=l;let i=0;o.forEach(v=>{t.Range.foreach(v.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C){const d=l.worksheet.getCellRaw(S,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const u=/\.(\d*)$/.exec(String(d.v));if(u){const y=u[1].length;if(!y)return;i=Math.max(i,y)}}return}const p=E(C.pattern);i=p>i?p:i})});const b=i-1,_=P(`0${b>0?".0":"."}`,b),h=[];return o.forEach(v=>{t.Range.foreach(v.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C)h.push({row:S,col:c,pattern:_});else{const p=E(C.pattern);h.push({row:S,col:c,pattern:P(C.pattern,p-1)})}})}),await r.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",F={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,s="en")=>{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}},k=(e,r,s)=>e==="General"?{result:String(X.stripErrorMargin(r))}:Y(e,r,s);var te=Object.getOwnPropertyDescriptor,ne=(e,r,s,n)=>{for(var a=n>1?void 0:n?te(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},I=(e,r)=>(s,n)=>r(s,n,e);const re={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,g,f){super();T(this,"_local$",new N.BehaviorSubject("en"));T(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=g,this._configService=f,this._initInterceptorCellContent()}get local(){const s=this._local$.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.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var v,S;const l=a.unitId,g=a.subUnitId;let f;const i=n;if(!i||i.v===void 0||i.v===null)return o(n);if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(f=c.n)}if(f||(f=this._numfmtService.getValue(l,g,a.row,a.col)),!f||f.pattern==="General"||i.t!==t.CellValueType.NUMBER&&m.checkCellValueType(i.v)!==t.CellValueType.NUMBER)return o(n);if((!n||n===a.rawData)&&(n={...a.rawData}),A.isTextFormat(f.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,...re},o(n));let b="";const _=s.getValue(a.row,a.col);if(_&&_.parameters===`${i.v}_${f.pattern}`)return o({...n,..._.result});const h=k(f.pattern,Number(i.v),this.local);if(b=h.result,!b)return o(n);const M={v:b,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:`${i.v}_${f.pattern}`}),Object.assign(n,M),o(n)},priority:m.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===m.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(g=>{t.Range.foreach(g,(f,i)=>{s.realDeleteValue(f,i)})})})}else if(n.id===m.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(N.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=ne([I(0,t.IUniverInstanceService),I(1,t.Inject(m.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(m.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const se="SHEET_NUMFMT_PLUGIN";class j extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,s)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,ie=(e,r,s,n)=>{for(var a=n>1?void 0:n?oe(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},O=(e,r)=>(s,n)=>r(s,n,e),z=(e,r,s)=>ce(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=F,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},F,this._config);this._configService.setConfig(w,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[j]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[j]]),[H,K,W,q,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",se);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(m.UniverSheetsPlugin),O(1,t.Inject(t.Injector)),O(2,t.IConfigService),O(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>x.find(s=>e.includes(s)),ue=()=>x.map(e=>({label:e,value:e})),me=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>G.map(e=>({label:e.label,value:e.suffix})),de=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=G;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=q;exports.SubtractDecimalCommand=K;exports.countryCurrencyMap=L;exports.currencySymbols=x;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=E;exports.getDecimalString=U;exports.getNumberFormatOptions=de;exports.getPatternPreview=Y;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.setPatternDecimal=P;
1
+ "use strict";var z=Object.defineProperty;var Z=(e,r,s)=>r in e?z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var T=(e,r,s)=>Z(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),m=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],A={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},L=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],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"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},U=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),O=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${U(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${U(Number(r||0))}$1`):n).join(";"),X=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={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=m.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:g,worksheet:f}=o,i=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),b=m.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],p=[];if(i.length){const c=i.reduce((d,u)=>{t.isTextFormat(u.pattern)&&d.setValue(u.row,u.col,{t:t.CellValueType.STRING});const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),Object.keys(b.values).forEach(d=>{const u=b.values[d];u.ranges=m.rangeMerge(u.ranges)}),M.push({id:m.SetNumfmtMutation.id,params:b});const v=m.factorySetNumfmtUndoMutation(e,b);p.push(...v)}if(_.length){h.ranges=m.rangeMerge(h.ranges);const c=_.reduce((d,u)=>{const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),M.push({id:m.RemoveNumfmtMutation.id,params:h},{id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const v=m.factoryRemoveNumfmtUndoMutation(e,h);p.push({id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:C.getMatrix()}},...v)}const S=t.sequenceExecute(M,s).result;return S&&a.pushUndoRedo({unitID:l,undoMutations:p,redoMutations:M}),S}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:g,subUnitId:f}=l;let i=0;o.forEach(M=>{t.Range.foreach(M.range,(p,S)=>{const c=n.getValue(g,f,p,S);if(!c){const v=l.worksheet.getCellRaw(p,S);if(!i&&v&&v.t===t.CellValueType.NUMBER&&v.v){const d=/\.(\d*)$/.exec(String(v.v));if(d){const u=d[1].length;if(!u)return;i=Math.max(i,u)}}return}const C=E(c.pattern);i=C>i?C:i})});const _=i+1,b=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(p,S)=>{const c=n.getValue(g,f,p,S);if(!c)h.push({row:p,col:S,pattern:b});else{const C=E(c.pattern),v=O(c.pattern,C+1);v!==c.pattern&&h.push({row:p,col:S,pattern:v})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(D),a=A[n.getCurrencySymbol()]||"$",o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=[],g=V[4].suffix(a);return o.forEach(i=>{t.Range.foreach(i.range,(_,b)=>{l.push({row:_,col:b,pattern:g,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(g=>{t.Range.foreach(g.range,(f,i)=>{a.push({row:f,col:i,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},W={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:g,subUnitId:f}=l;let i=0;o.forEach(p=>{t.Range.foreach(p.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C){const d=l.worksheet.getCellRaw(S,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const u=/\.(\d*)$/.exec(String(d.v));if(u){const y=u[1].length;if(!y)return;i=Math.max(i,y)}}return}const v=E(C.pattern);i=v>i?v:i})});const _=i-1,b=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(p=>{t.Range.foreach(p.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C)h.push({row:S,col:c,pattern:b});else{const v=E(C.pattern);h.push({row:S,col:c,pattern:O(C.pattern,v-1)})}})}),await r.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",F={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",q=(e,r,s="en")=>{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}},Y=(e,r,s)=>e==="General"?{result:String(J.stripErrorMargin(r))}:q(e,r,s);var ee=Object.getOwnPropertyDescriptor,te=(e,r,s,n)=>{for(var a=n>1?void 0:n?ee(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},I=(e,r)=>(s,n)=>r(s,n,e);const ne={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,g,f){super();T(this,"_locale$",new N.BehaviorSubject("en"));T(this,"locale$",this._locale$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=g,this._configService=f,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.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var p,S;const l=a.unitId,g=a.subUnitId;let f;const i=n;if(!i||i.v===void 0||i.v===null)return o(n);if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(f=c.n)}if(f||(f=this._numfmtService.getValue(l,g,a.row,a.col)),!f||f.pattern==="General"||i.t!==t.CellValueType.NUMBER&&m.checkCellValueType(i.v)!==t.CellValueType.NUMBER)return o(n);if((!n||n===a.rawData)&&(n={...a.rawData}),t.isTextFormat(f.pattern))return(p=this._configService.getConfig(w))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},o(n));let _="";const b=s.getValue(a.row,a.col);if(b&&b.parameters===`${i.v}_${f.pattern}`)return o({...n,...b.result});const h=Y(f.pattern,Number(i.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:`${i.v}_${f.pattern}`}),Object.assign(n,M),o(n)},priority:m.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===m.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(g=>{t.Range.foreach(g,(f,i)=>{s.realDeleteValue(f,i)})})})}else if(n.id===m.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(N.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._locale$.next(s)}};exports.SheetsNumfmtCellContentController=te([I(0,t.IUniverInstanceService),I(1,t.Inject(m.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(m.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const re="SHEET_NUMFMT_PLUGIN";class j extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var se=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,oe=(e,r,s)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,ce=(e,r,s,n)=>{for(var a=n>1?void 0:n?ae(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},P=(e,r)=>(s,n)=>r(s,n,e),k=(e,r,s)=>oe(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=F,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},F,this._config);this._configService.setConfig(w,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[j]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[j]]),[B,W,H,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};k(exports.UniverSheetsNumfmtPlugin,"pluginName",re);k(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ce([t.DependentOn(m.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ie=e=>x.find(s=>e.includes(s)),le=()=>x.map(e=>({label:e,value:e})),ue=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>L.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=B;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=L;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=G;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=H;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=W;exports.countryCurrencyMap=A;exports.currencySymbols=x;exports.getCurrencyFormatOptions=ue;exports.getCurrencyOptions=le;exports.getCurrencyType=ie;exports.getDateFormatOptions=me;exports.getDecimalFromPattern=E;exports.getDecimalString=U;exports.getNumberFormatOptions=fe;exports.getPatternPreview=q;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=Q;exports.isPatternHasDecimal=X;exports.setPatternDecimal=O;
package/lib/es/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  var ie = Object.defineProperty;
2
2
  var le = (e, t, r) => t in e ? ie(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var $ = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { numfmt as w, CommandType as V, ICommandService as T, IUniverInstanceService as A, IUndoRedoService as ue, CellValueType as M, ObjectMatrix as b, sequenceExecute as me, Range as I, Inject as E, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as R, InterceptorEffectEnum as z, UniverInstanceType as ee, DependentOn as he, Injector as ge, Plugin as pe, merge as ve, registerDependencies as Se, touchDependencies as Y } from "@univerjs/core";
5
- import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as Z, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
6
- import { isTextFormat as re } from "@univerjs/engine-numfmt";
7
- import { BehaviorSubject as K, merge as Ie, switchMap as Te, of as Ee, skip as xe } from "rxjs";
3
+ var R = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { numfmt as w, CommandType as V, ICommandService as I, IUniverInstanceService as A, IUndoRedoService as ue, isTextFormat as X, CellValueType as $, ObjectMatrix as M, sequenceExecute as me, Range as E, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as Q, Disposable as ee, LocaleType as b, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as he, Injector as ge, Plugin as Se, merge as pe, registerDependencies as ve, touchDependencies as Y } from "@univerjs/core";
5
+ import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as k, SetNumfmtMutation as re, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
6
+ import { BehaviorSubject as K, merge as Ee, switchMap as Ie, of as Te, skip as xe } from "rxjs";
8
7
  import { stripErrorMargin as Ve } from "@univerjs/engine-formula";
9
8
  const ne = [
10
9
  "$",
@@ -178,20 +177,20 @@ const ne = [
178
177
  ], O = (e, t = 0) => {
179
178
  var n;
180
179
  return e && (n = w.getFormatInfo(e).maxDecimals) != null ? n : t;
181
- }, k = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), P = (e, t) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
180
+ }, Z = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), P = (e, t) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
182
181
  /\.0*/g,
183
- `${t > 0 ? "." : ""}${k(Number(t || 0))}`
182
+ `${t > 0 ? "." : ""}${Z(Number(t || 0))}`
184
183
  ) : /0([^0]?)|0$/.test(n) ? n.replace(
185
184
  /0([^0]+)|0$/,
186
- `0${t > 0 ? "." : ""}${k(Number(t || 0))}$1`
187
- ) : n).join(";"), tt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), U = {
185
+ `0${t > 0 ? "." : ""}${Z(Number(t || 0))}$1`
186
+ ) : n).join(";"), et = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), U = {
188
187
  id: "sheet.command.numfmt.set.numfmt",
189
188
  type: V.COMMAND,
190
189
  // eslint-disable-next-line max-lines-per-function
191
190
  handler: (e, t) => {
192
191
  if (!t)
193
192
  return !1;
194
- const r = e.get(T), n = e.get(A), s = e.get(ue), o = H(n, t);
193
+ const r = e.get(I), n = e.get(A), s = e.get(ue), o = H(n, t);
195
194
  if (!o) return !1;
196
195
  const { unitId: a, subUnitId: i, worksheet: f } = o, u = t.values.filter((l) => !!l.pattern), y = t.values.filter((l) => !l.pattern), _ = ye(a, i, u), g = {
197
196
  unitId: a,
@@ -202,43 +201,43 @@ const ne = [
202
201
  endColumn: l.col,
203
202
  endRow: l.row
204
203
  }))
205
- }, C = [], p = [];
204
+ }, C = [], S = [];
206
205
  if (u.length) {
207
206
  const l = u.reduce((d, c) => {
208
- re(c.pattern) && d.setValue(c.row, c.col, { t: M.STRING });
209
- const S = f.getCellRaw(c.row, c.col);
210
- if (S) {
211
- const x = G(S.v);
212
- x !== S.t && d.setValue(c.row, c.col, { t: x });
207
+ X(c.pattern) && d.setValue(c.row, c.col, { t: $.STRING });
208
+ const v = f.getCellRaw(c.row, c.col);
209
+ if (v) {
210
+ const x = G(v.v);
211
+ x !== v.t && d.setValue(c.row, c.col, { t: x });
213
212
  }
214
213
  return d;
215
- }, new b()).getMatrix(), h = new b();
216
- new b(l).forValue((d, c) => {
217
- const S = f.getCellRaw(d, c);
218
- S ? h.setValue(d, c, { t: S.t }) : h.setValue(d, c, { t: void 0 });
214
+ }, new M()).getMatrix(), h = new M();
215
+ new M(l).forValue((d, c) => {
216
+ const v = f.getCellRaw(d, c);
217
+ v ? h.setValue(d, c, { t: v.t }) : h.setValue(d, c, { t: void 0 });
219
218
  }), Object.keys(_.values).forEach((d) => {
220
219
  const c = _.values[d];
221
- c.ranges = Z(c.ranges);
220
+ c.ranges = k(c.ranges);
222
221
  }), C.push({
223
- id: te.id,
222
+ id: re.id,
224
223
  params: _
225
224
  });
226
- const v = _e(e, _);
227
- p.push(...v);
225
+ const p = _e(e, _);
226
+ S.push(...p);
228
227
  }
229
228
  if (y.length) {
230
- g.ranges = Z(g.ranges);
229
+ g.ranges = k(g.ranges);
231
230
  const l = y.reduce((d, c) => {
232
- const S = f.getCellRaw(c.row, c.col);
233
- if (S) {
234
- const x = G(S.v);
235
- x !== S.t && d.setValue(c.row, c.col, { t: x });
231
+ const v = f.getCellRaw(c.row, c.col);
232
+ if (v) {
233
+ const x = G(v.v);
234
+ x !== v.t && d.setValue(c.row, c.col, { t: x });
236
235
  }
237
236
  return d;
238
- }, new b()).getMatrix(), h = new b();
239
- new b(l).forValue((d, c) => {
240
- const S = f.getCellRaw(d, c);
241
- S ? h.setValue(d, c, { t: S.t }) : h.setValue(d, c, { t: void 0 });
237
+ }, new M()).getMatrix(), h = new M();
238
+ new M(l).forValue((d, c) => {
239
+ const v = f.getCellRaw(d, c);
240
+ v ? h.setValue(d, c, { t: v.t }) : h.setValue(d, c, { t: void 0 });
242
241
  }), C.push({
243
242
  id: Ce.id,
244
243
  params: g
@@ -250,20 +249,20 @@ const ne = [
250
249
  cellValue: l
251
250
  }
252
251
  });
253
- const v = be(e, g);
254
- p.push({
252
+ const p = be(e, g);
253
+ S.push({
255
254
  id: B.id,
256
255
  params: {
257
256
  unitId: a,
258
257
  subUnitId: i,
259
258
  cellValue: h.getMatrix()
260
259
  }
261
- }, ...v);
260
+ }, ...p);
262
261
  }
263
262
  const m = me(C, r).result;
264
263
  return m && s.pushUndoRedo({
265
264
  unitID: a,
266
- undoMutations: p,
265
+ undoMutations: S,
267
266
  redoMutations: C
268
267
  }), m;
269
268
  }
@@ -271,7 +270,7 @@ const ne = [
271
270
  id: "sheet.command.numfmt.add.decimal.command",
272
271
  type: V.COMMAND,
273
272
  handler: async (e) => {
274
- const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
273
+ const t = e.get(I), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
275
274
  if (!o || !o.length)
276
275
  return !1;
277
276
  const a = H(s);
@@ -279,12 +278,12 @@ const ne = [
279
278
  const { unitId: i, subUnitId: f } = a;
280
279
  let u = 0;
281
280
  o.forEach((C) => {
282
- I.foreach(C.range, (p, m) => {
283
- const l = n.getValue(i, f, p, m);
281
+ E.foreach(C.range, (S, m) => {
282
+ const l = n.getValue(i, f, S, m);
284
283
  if (!l) {
285
- const v = a.worksheet.getCellRaw(p, m);
286
- if (!u && v && v.t === M.NUMBER && v.v) {
287
- const d = /\.(\d*)$/.exec(String(v.v));
284
+ const p = a.worksheet.getCellRaw(S, m);
285
+ if (!u && p && p.t === $.NUMBER && p.v) {
286
+ const d = /\.(\d*)$/.exec(String(p.v));
288
287
  if (d) {
289
288
  const c = d[1].length;
290
289
  if (!c)
@@ -300,20 +299,20 @@ const ne = [
300
299
  });
301
300
  const y = u + 1, _ = P(`0${y > 0 ? ".0" : ""}`, y), g = [];
302
301
  return o.forEach((C) => {
303
- I.foreach(C.range, (p, m) => {
304
- const l = n.getValue(i, f, p, m);
302
+ E.foreach(C.range, (S, m) => {
303
+ const l = n.getValue(i, f, S, m);
305
304
  if (!l)
306
305
  g.push({
307
- row: p,
306
+ row: S,
308
307
  col: m,
309
308
  pattern: _
310
309
  });
311
310
  else {
312
- const h = O(l.pattern), v = P(l.pattern, h + 1);
313
- v !== l.pattern && g.push({
314
- row: p,
311
+ const h = O(l.pattern), p = P(l.pattern, h + 1);
312
+ p !== l.pattern && g.push({
313
+ row: S,
315
314
  col: m,
316
- pattern: v
315
+ pattern: p
317
316
  });
318
317
  }
319
318
  });
@@ -322,8 +321,8 @@ const ne = [
322
321
  };
323
322
  class oe {
324
323
  constructor() {
325
- $(this, "_currencySymbol$", new K("US"));
326
- $(this, "currencySymbol$", this._currencySymbol$.asObservable());
324
+ R(this, "_currencySymbol$", new K("US"));
325
+ R(this, "currencySymbol$", this._currencySymbol$.asObservable());
327
326
  }
328
327
  /**
329
328
  * Set the currency symbol by setting the country code.
@@ -339,12 +338,12 @@ const De = {
339
338
  id: "sheet.command.numfmt.set.currency",
340
339
  type: V.COMMAND,
341
340
  handler: async (e) => {
342
- const t = e.get(T), r = e.get(j), n = e.get(oe), s = Ue[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
341
+ const t = e.get(I), r = e.get(j), n = e.get(oe), s = Ue[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
343
342
  if (!o || !o.length)
344
343
  return !1;
345
344
  const a = [], i = se[4].suffix(s);
346
345
  return o.forEach((u) => {
347
- I.foreach(u.range, (y, _) => {
346
+ E.foreach(u.range, (y, _) => {
348
347
  a.push({ row: y, col: _, pattern: i, type: "currency" });
349
348
  });
350
349
  }), await t.executeCommand(U.id, { values: a });
@@ -353,12 +352,12 @@ const De = {
353
352
  id: "sheet.command.numfmt.set.percent",
354
353
  type: V.COMMAND,
355
354
  handler: async (e) => {
356
- const t = e.get(T), n = e.get(j).getCurrentSelections();
355
+ const t = e.get(I), n = e.get(j).getCurrentSelections();
357
356
  if (!n || !n.length)
358
357
  return !1;
359
358
  const s = [], o = "0%";
360
359
  return n.forEach((i) => {
361
- I.foreach(i.range, (f, u) => {
360
+ E.foreach(i.range, (f, u) => {
362
361
  s.push({ row: f, col: u, pattern: o, type: "percent" });
363
362
  });
364
363
  }), await t.executeCommand(U.id, { values: s });
@@ -367,36 +366,36 @@ const De = {
367
366
  id: "sheet.command.numfmt.subtract.decimal.command",
368
367
  type: V.COMMAND,
369
368
  handler: async (e) => {
370
- const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
369
+ const t = e.get(I), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
371
370
  if (!o || !o.length)
372
371
  return !1;
373
372
  const a = H(s);
374
373
  if (!a) return !1;
375
374
  const { unitId: i, subUnitId: f } = a;
376
375
  let u = 0;
377
- o.forEach((p) => {
378
- I.foreach(p.range, (m, l) => {
376
+ o.forEach((S) => {
377
+ E.foreach(S.range, (m, l) => {
379
378
  const h = n.getValue(i, f, m, l);
380
379
  if (!h) {
381
380
  const d = a.worksheet.getCellRaw(m, l);
382
- if (!u && d && d.t === M.NUMBER && d.v) {
381
+ if (!u && d && d.t === $.NUMBER && d.v) {
383
382
  const c = /\.(\d*)$/.exec(String(d.v));
384
383
  if (c) {
385
- const S = c[1].length;
386
- if (!S)
384
+ const v = c[1].length;
385
+ if (!v)
387
386
  return;
388
- u = Math.max(u, S);
387
+ u = Math.max(u, v);
389
388
  }
390
389
  }
391
390
  return;
392
391
  }
393
- const v = O(h.pattern);
394
- u = v > u ? v : u;
392
+ const p = O(h.pattern);
393
+ u = p > u ? p : u;
395
394
  });
396
395
  });
397
396
  const y = u - 1, _ = P(`0${y > 0 ? ".0" : "."}`, y), g = [];
398
- return o.forEach((p) => {
399
- I.foreach(p.range, (m, l) => {
397
+ return o.forEach((S) => {
398
+ E.foreach(S.range, (m, l) => {
400
399
  const h = n.getValue(i, f, m, l);
401
400
  if (!h)
402
401
  g.push({
@@ -405,17 +404,17 @@ const De = {
405
404
  pattern: _
406
405
  });
407
406
  else {
408
- const v = O(h.pattern);
407
+ const p = O(h.pattern);
409
408
  g.push({
410
409
  row: m,
411
410
  col: l,
412
- pattern: P(h.pattern, v - 1)
411
+ pattern: P(h.pattern, p - 1)
413
412
  });
414
413
  }
415
414
  });
416
415
  }), await t.executeCommand(U.id, { values: g });
417
416
  }
418
- }, ae = "sheets-numfmt.config", q = {}, rt = (e) => w.getFormatInfo(e).type || "unknown", je = (e, t, r = "en") => {
417
+ }, ae = "sheets-numfmt.config", q = {}, tt = (e) => w.getFormatInfo(e).type || "unknown", je = (e, t, r = "en") => {
419
418
  const n = w.formatColor(e, t), s = n ? String(n) : void 0, o = w.format(e, t, { locale: r, throws: !1 });
420
419
  return t < 0 ? {
421
420
  result: o,
@@ -438,44 +437,49 @@ const He = {
438
437
  color: "#409f11"
439
438
  }
440
439
  };
441
- let D = class extends Q {
440
+ let D = class extends ee {
442
441
  constructor(t, r, n, s, o, a, i) {
443
442
  super();
444
- $(this, "_local$", new K("en"));
445
- $(this, "local$", this._local$.asObservable());
443
+ R(this, "_locale$", new K("en"));
444
+ R(this, "locale$", this._locale$.asObservable());
446
445
  this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = a, this._configService = i, this._initInterceptorCellContent();
447
446
  }
448
- get local() {
449
- const t = this._local$.getValue();
447
+ get locale() {
448
+ const t = this._locale$.getValue();
450
449
  if (t)
451
450
  return t;
452
451
  switch (this._localeService.getCurrentLocale()) {
453
- case R.FR_FR:
452
+ case b.FR_FR:
454
453
  return "fr";
455
- case R.RU_RU:
454
+ case b.RU_RU:
456
455
  return "ru";
457
- case R.VI_VN:
456
+ case b.VI_VN:
458
457
  return "vi";
459
- case R.ZH_CN:
458
+ case b.ZH_CN:
460
459
  return "zh-CN";
461
- case R.ZH_TW:
460
+ case b.KO_KR:
461
+ return "ko";
462
+ case b.ZH_TW:
462
463
  return "zh-TW";
463
- case R.EN_US:
464
- case R.FA_IR:
464
+ case b.ES_ES:
465
+ case b.CA_ES:
466
+ return "es";
467
+ case b.EN_US:
468
+ case b.FA_IR:
465
469
  default:
466
470
  return "en";
467
471
  }
468
472
  }
469
473
  // eslint-disable-next-line max-lines-per-function
470
474
  _initInterceptorCellContent() {
471
- const t = new b();
472
- this.disposeWithMe(Ie(this._local$, this._localeService.currentLocale$).subscribe(() => {
475
+ const t = new M();
476
+ this.disposeWithMe(Ee(this._locale$, this._localeService.currentLocale$).subscribe(() => {
473
477
  t.reset();
474
478
  })), this.disposeWithMe(this._sheetInterceptorService.intercept($e.CELL_CONTENT, {
475
479
  effect: z.Value | z.Style,
476
480
  // eslint-disable-next-line complexity
477
481
  handler: (r, n, s) => {
478
- var C, p;
482
+ var C, S;
479
483
  const o = n.unitId, a = n.subUnitId;
480
484
  let i;
481
485
  const f = r;
@@ -485,20 +489,20 @@ let D = class extends Q {
485
489
  const m = n.workbook.getStyles().get(r.s);
486
490
  m != null && m.n && (i = m.n);
487
491
  }
488
- if (i || (i = this._numfmtService.getValue(o, a, n.row, n.col)), !i || i.pattern === "General" || f.t !== M.NUMBER && G(f.v) !== M.NUMBER)
492
+ if (i || (i = this._numfmtService.getValue(o, a, n.row, n.col)), !i || i.pattern === "General" || f.t !== $.NUMBER && G(f.v) !== $.NUMBER)
489
493
  return s(r);
490
- if ((!r || r === n.rawData) && (r = { ...n.rawData }), re(i.pattern))
491
- return (C = this._configService.getConfig(ae)) != null && C.disableTextFormatMark ? (r.t = M.STRING, s(r)) : (r.t = M.STRING, r.markers = { ...r == null ? void 0 : r.markers, ...He }, s(r));
494
+ if ((!r || r === n.rawData) && (r = { ...n.rawData }), X(i.pattern))
495
+ return (C = this._configService.getConfig(ae)) != null && C.disableTextFormatMark ? (r.t = $.STRING, s(r)) : (r.t = $.STRING, r.markers = { ...r == null ? void 0 : r.markers, ...He }, s(r));
492
496
  let u = "";
493
497
  const y = t.getValue(n.row, n.col);
494
498
  if (y && y.parameters === `${f.v}_${i.pattern}`)
495
499
  return s({ ...r, ...y.result });
496
- const _ = Le(i.pattern, Number(f.v), this.local);
500
+ const _ = Le(i.pattern, Number(f.v), this.locale);
497
501
  if (u = _.result, !u)
498
502
  return s(r);
499
- const g = { v: u, t: M.NUMBER };
503
+ const g = { v: u, t: $.NUMBER };
500
504
  if (_.color) {
501
- const m = (p = this._themeService.getColorFromTheme(`${_.color}.500`)) != null ? p : _.color;
505
+ const m = (S = this._themeService.getColorFromTheme(`${_.color}.500`)) != null ? S : _.color;
502
506
  m && (g.interceptorStyle = { cl: { rgb: m } });
503
507
  }
504
508
  return t.setValue(n.row, n.col, {
@@ -508,50 +512,50 @@ let D = class extends Q {
508
512
  },
509
513
  priority: Re.NUMFMT
510
514
  })), this.disposeWithMe(this._commandService.onCommandExecuted((r) => {
511
- if (r.id === te.id) {
515
+ if (r.id === re.id) {
512
516
  const n = r.params;
513
517
  Object.keys(n.values).forEach((s) => {
514
518
  n.values[s].ranges.forEach((a) => {
515
- I.foreach(a, (i, f) => {
519
+ E.foreach(a, (i, f) => {
516
520
  t.realDeleteValue(i, f);
517
521
  });
518
522
  });
519
523
  });
520
524
  } else if (r.id === B.id) {
521
525
  const n = r.params;
522
- new b(n.cellValue).forValue((s, o) => {
526
+ new M(n.cellValue).forValue((s, o) => {
523
527
  t.realDeleteValue(s, o);
524
528
  });
525
529
  }
526
530
  })), this.disposeWithMe(
527
- this._instanceService.getCurrentTypeOfUnit$(ee.UNIVER_SHEET).pipe(
528
- Te((r) => {
531
+ this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
532
+ Ie((r) => {
529
533
  var n;
530
- return (n = r == null ? void 0 : r.activeSheet$) != null ? n : Ee(null);
534
+ return (n = r == null ? void 0 : r.activeSheet$) != null ? n : Te(null);
531
535
  }),
532
536
  xe(1)
533
537
  ).subscribe(() => t.reset())
534
538
  );
535
539
  }
536
540
  setNumfmtLocal(t) {
537
- this._local$.next(t);
541
+ this._locale$.next(t);
538
542
  }
539
543
  };
540
544
  D = Be([
541
545
  N(0, A),
542
- N(1, E(Me)),
543
- N(2, E(fe)),
544
- N(3, E(T)),
545
- N(4, E(W)),
546
- N(5, E(de)),
547
- N(6, X)
546
+ N(1, T(Me)),
547
+ N(2, T(fe)),
548
+ N(3, T(I)),
549
+ N(4, T(W)),
550
+ N(5, T(de)),
551
+ N(6, Q)
548
552
  ], D);
549
553
  const We = "SHEET_NUMFMT_PLUGIN";
550
- class J extends Q {
554
+ class J extends ee {
551
555
  constructor() {
552
556
  super(...arguments);
553
- $(this, "_currencySymbol$", new K("US"));
554
- $(this, "currencySymbol$", this._currencySymbol$.asObservable());
557
+ R(this, "_currencySymbol$", new K("US"));
558
+ R(this, "currencySymbol$", this._currencySymbol$.asObservable());
555
559
  }
556
560
  /**
557
561
  * Set the currency symbol by setting the country code.
@@ -563,15 +567,15 @@ class J extends Q {
563
567
  return this._currencySymbol$.getValue();
564
568
  }
565
569
  }
566
- var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t, r) => t in e ? Ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Ze = (e, t, r, n) => {
570
+ var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t, r) => t in e ? Ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, ke = (e, t, r, n) => {
567
571
  for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, o = e.length - 1, a; o >= 0; o--)
568
572
  (a = e[o]) && (s = a(s) || s);
569
573
  return s;
570
574
  }, L = (e, t) => (r, n) => t(r, n, e), ce = (e, t, r) => Ye(e, typeof t != "symbol" ? t + "" : t, r);
571
- let F = class extends pe {
575
+ let F = class extends Se {
572
576
  constructor(e = q, t, r, n) {
573
577
  super(), this._config = e, this._injector = t, this._configService = r, this._commandService = n;
574
- const { ...s } = ve(
578
+ const { ...s } = pe(
575
579
  {},
576
580
  q,
577
581
  this._config
@@ -579,7 +583,7 @@ let F = class extends pe {
579
583
  this._configService.setConfig(ae, s);
580
584
  }
581
585
  onStarting() {
582
- Se(this._injector, [
586
+ ve(this._injector, [
583
587
  [D],
584
588
  [oe],
585
589
  [J]
@@ -602,18 +606,18 @@ let F = class extends pe {
602
606
  }
603
607
  };
604
608
  ce(F, "pluginName", We);
605
- ce(F, "type", ee.UNIVER_SHEET);
606
- F = Ze([
609
+ ce(F, "type", te.UNIVER_SHEET);
610
+ F = ke([
607
611
  he(Ne),
608
- L(1, E(ge)),
609
- L(2, X),
610
- L(3, T)
612
+ L(1, T(ge)),
613
+ L(2, Q),
614
+ L(3, I)
611
615
  ], F);
612
- const nt = (e) => ne.find((r) => e.includes(r)), st = () => ne.map((e) => ({ label: e, value: e })), ot = (e) => se.map((t) => ({
616
+ const rt = (e) => ne.find((r) => e.includes(r)), nt = () => ne.map((e) => ({ label: e, value: e })), st = (e) => se.map((t) => ({
613
617
  label: t.label(e),
614
618
  value: t.suffix(e),
615
619
  color: t.color
616
- })), at = () => we.map((e) => ({ label: e.label, value: e.suffix })), ct = () => Oe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
620
+ })), ot = () => we.map((e) => ({ label: e.label, value: e.suffix })), at = () => Oe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
617
621
  export {
618
622
  Pe as AddDecimalCommand,
619
623
  se as CURRENCYFORMAT,
@@ -629,16 +633,16 @@ export {
629
633
  F as UniverSheetsNumfmtPlugin,
630
634
  Ue as countryCurrencyMap,
631
635
  ne as currencySymbols,
632
- ot as getCurrencyFormatOptions,
633
- st as getCurrencyOptions,
634
- nt as getCurrencyType,
635
- at as getDateFormatOptions,
636
+ st as getCurrencyFormatOptions,
637
+ nt as getCurrencyOptions,
638
+ rt as getCurrencyType,
639
+ ot as getDateFormatOptions,
636
640
  O as getDecimalFromPattern,
637
- k as getDecimalString,
638
- ct as getNumberFormatOptions,
641
+ Z as getDecimalString,
642
+ at as getNumberFormatOptions,
639
643
  je as getPatternPreview,
640
644
  Le as getPatternPreviewIgnoreGeneral,
641
- rt as getPatternType,
642
- tt as isPatternHasDecimal,
645
+ tt as getPatternType,
646
+ et as isPatternHasDecimal,
643
647
  P as setPatternDecimal
644
648
  };