@univerjs/sheets-numfmt 0.12.1 → 0.12.2-nightly.202511290732

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 X=(e,r,a)=>r in e?z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a;var U=(e,r,a)=>X(e,typeof r!="symbol"?r+"":r,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],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,"€"]]);function V(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR: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 j(e,r=2){let a=r;r>127&&(a=127);let n="";return a>0&&(n=`.${"0".repeat(a)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const A=[{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"}],G=[{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},L=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?".":""}${L(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${L(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 a=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=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=[],C=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.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);C.push(...y)}if(_.length){h.ranges=f.rangeMerge(h.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.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);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:p.getMatrix()}},...y)}const S=t.sequenceExecute(M,a).result;return S&&s.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),S}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(!c){const y=l.worksheet.getCellRaw(C,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=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(t.isDefaultFormat(c==null?void 0:c.pattern))h.push({row:C,col:S,pattern:T});else{const p=$(c.pattern),y=O(c.pattern,p+1);y!==c.pattern&&h.push({row:C,col:S,pattern:y})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),s=a.getCurrentSelections();if(!s||!s.length)return!1;const o=[],l=V(n.getCurrentLocale()),d=j(l.locale);return s.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(R.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 s=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{s.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.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 v=m[1].length;if(!v)return;u=Math.max(u,v)}}return}const y=$(p.pattern);u=y>u?y:u})});const _=u-1,T=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(C=>{t.Range.foreach(C.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:O(p.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:h})}},D="sheets-numfmt.config",w={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,a="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:a,throws:!1});return r<0?{result:o,color:s}:{result:o}},k=(e,r,a)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,a);var te=Object.getOwnPropertyDescriptor,ne=(e,r,a,n)=>{for(var s=n>1?void 0:n?te(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},b=(e,r)=>(a,n)=>r(a,n,e);const re={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(a,n,s,o,l,d,i){super();U(this,"_locale$",new N.BehaviorSubject("en"));U(this,"locale$",this._locale$.asObservable());this._instanceService=a,this._sheetInterceptorService=n,this._themeService=s,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const a=this._locale$.getValue();if(a)return a;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 a=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{a.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,o)=>{var C,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=s.unitId,d=s.subUnitId;let i;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,s.row,s.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===s.rawData)&&(n={...s.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(C=this._configService.getConfig(D))!=null&&C.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 _="";const T=a.getValue(s.row,s.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const h=k(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 a.setValue(s.row,s.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 s=n.params;Object.keys(s.values).forEach(o=>{s.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{a.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((o,l)=>{a.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>a.reset()))}setNumfmtLocal(a){this._locale$.next(a)}};exports.SheetsNumfmtCellContentController=ne([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="SHEET_NUMFMT_PLUGIN";var se=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,a)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,ie=(e,r,a,n)=>{for(var s=n>1?void 0:n?oe(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},P=(e,r)=>(a,n)=>r(a,n,e),Y=(e,r,a)=>ce(e,typeof r!="symbol"?r+"":r,a);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=w,a,n,s){super(),this._config=r,this._injector=a,this._configService=n,this._commandService=s;const{...o}=t.merge({},w,this._config);this._configService.setConfig(D,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){[H,q,W,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};Y(exports.UniverSheetsNumfmtPlugin,"pluginName",ae);Y(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(f.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>x.find(a=>e.includes(a)),ue=()=>x.map(e=>({label:e,value:e})),me=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>A.map(e=>({label:e.label,value:e.suffix})),ge=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=A;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=x;exports.getCurrencyFormat=j;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=V;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=$;exports.getDecimalString=L;exports.getNumberFormatOptions=ge;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=O;
1
+ "use strict";var z=Object.defineProperty;var X=(e,r,a)=>r in e?z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a;var U=(e,r,a)=>X(e,typeof r!="symbol"?r+"":r,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],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,"€"]]);function V(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR: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 j(e,r=2){let a=r;r>127&&(a=127);let n="";return a>0&&(n=`.${"0".repeat(a)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const A=[{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"}],G=[{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},L=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?".":""}${L(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${L(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 a=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=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=[],C=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.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);C.push(...y)}if(_.length){h.ranges=f.rangeMerge(h.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.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);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:p.getMatrix()}},...y)}const S=t.sequenceExecute(M,a).result;return S&&s.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),S}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(!c){const y=l.worksheet.getCellRaw(C,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=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(t.isDefaultFormat(c==null?void 0:c.pattern))h.push({row:C,col:S,pattern:T});else{const p=$(c.pattern),y=O(c.pattern,p+1);y!==c.pattern&&h.push({row:C,col:S,pattern:y})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),s=a.getCurrentSelections();if(!s||!s.length)return!1;const o=[],l=V(n.getCurrentLocale()),d=j(l.locale);return s.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(R.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 s=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{s.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.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 v=m[1].length;if(!v)return;u=Math.max(u,v)}}return}const y=$(p.pattern);u=y>u?y:u})});const _=u-1,T=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(C=>{t.Range.foreach(C.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:O(p.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:h})}},D="sheets-numfmt.config",w={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,a="en")=>{try{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:a,throws:!1});return r<0?{result:o,color:s}:{result:o}}catch(n){console.warn("getPatternPreview error:",e,n)}return{result:String(r)}},k=(e,r,a)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,a);var te=Object.getOwnPropertyDescriptor,ne=(e,r,a,n)=>{for(var s=n>1?void 0:n?te(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},b=(e,r)=>(a,n)=>r(a,n,e);const re={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(a,n,s,o,l,d,i){super();U(this,"_locale$",new N.BehaviorSubject("en"));U(this,"locale$",this._locale$.asObservable());this._instanceService=a,this._sheetInterceptorService=n,this._themeService=s,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const a=this._locale$.getValue();if(a)return a;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 a=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{a.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,o)=>{var C,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=s.unitId,d=s.subUnitId;let i;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,s.row,s.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===s.rawData)&&(n={...s.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(C=this._configService.getConfig(D))!=null&&C.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 _="";const T=a.getValue(s.row,s.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const h=k(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 a.setValue(s.row,s.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 s=n.params;Object.keys(s.values).forEach(o=>{s.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{a.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((o,l)=>{a.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>a.reset()))}setNumfmtLocal(a){this._locale$.next(a)}};exports.SheetsNumfmtCellContentController=ne([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="SHEET_NUMFMT_PLUGIN";var se=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,a)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,ie=(e,r,a,n)=>{for(var s=n>1?void 0:n?oe(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},P=(e,r)=>(a,n)=>r(a,n,e),Y=(e,r,a)=>ce(e,typeof r!="symbol"?r+"":r,a);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=w,a,n,s){super(),this._config=r,this._injector=a,this._configService=n,this._commandService=s;const{...o}=t.merge({},w,this._config);this._configService.setConfig(D,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){[H,q,W,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};Y(exports.UniverSheetsNumfmtPlugin,"pluginName",ae);Y(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(f.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>x.find(a=>e.includes(a)),ue=()=>x.map(e=>({label:e,value:e})),me=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>A.map(e=>({label:e.label,value:e.suffix})),ge=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=A;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=x;exports.getCurrencyFormat=j;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=V;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=$;exports.getDecimalString=L;exports.getNumberFormatOptions=ge;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=O;
package/lib/es/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  var ae = Object.defineProperty;
2
- var ie = (e, n, t) => n in e ? ae(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
- var L = (e, n, t) => ie(e, typeof n != "symbol" ? n + "" : n, t);
2
+ var ie = (e, r, t) => r in e ? ae(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
+ var L = (e, r, t) => ie(e, typeof r != "symbol" ? r + "" : r, t);
4
4
  import { LocaleType as f, numfmt as x, CommandType as U, ICommandService as $, IUniverInstanceService as V, IUndoRedoService as ce, isTextFormat as J, CellValueType as M, ObjectMatrix as R, sequenceExecute as le, Range as N, isDefaultFormat as W, LocaleService as Q, DEFAULT_NUMBER_FORMAT as ue, Inject as I, ThemeService as fe, IConfigService as ee, Disposable as me, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as de, Injector as ge, Plugin as he, merge as pe, registerDependencies as _e, touchDependencies as ve } from "@univerjs/core";
5
- import { getSheetCommandTarget as K, transformCellsToRange as Se, checkCellValueType as H, rangeMerge as k, SetNumfmtMutation as ne, factorySetNumfmtUndoMutation as Ce, RemoveNumfmtMutation as ye, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as Z, SheetInterceptorService as Me, INTERCEPTOR_POINT as Re, InterceptCellContentPriority as Ee, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
5
+ import { getSheetCommandTarget as K, transformCellsToRange as Se, checkCellValueType as H, rangeMerge as k, SetNumfmtMutation as re, factorySetNumfmtUndoMutation as Ce, RemoveNumfmtMutation as ye, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as Z, SheetInterceptorService as Me, INTERCEPTOR_POINT as Re, InterceptCellContentPriority as Ee, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
6
6
  import { BehaviorSubject as $e, merge as Ie, switchMap as Te, of as Ue, skip as Oe } from "rxjs";
7
7
  import { stripErrorMargin as we } from "@univerjs/engine-formula";
8
- const re = [
8
+ const ne = [
9
9
  "$",
10
10
  "£",
11
11
  "¥",
@@ -80,11 +80,11 @@ function xe(e) {
80
80
  function Y(e) {
81
81
  return w.get(e) || "$";
82
82
  }
83
- function Pe(e, n = 2) {
84
- let t = n;
85
- n > 127 && (t = 127);
86
- let r = "";
87
- return t > 0 && (r = `.${"0".repeat(t)}`), `"${Y(e)}"#,##0${r}_);[Red]("${Y(e)}"#,##0${r})`;
83
+ function Pe(e, r = 2) {
84
+ let t = r;
85
+ r > 127 && (t = 127);
86
+ let n = "";
87
+ return t > 0 && (n = `.${"0".repeat(t)}`), `"${Y(e)}"#,##0${n}_);[Red]("${Y(e)}"#,##0${n})`;
88
88
  }
89
89
  const Fe = [
90
90
  {
@@ -187,25 +187,25 @@ const Fe = [
187
187
  suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
188
188
  color: "red"
189
189
  }
190
- ], P = (e, n = 0) => {
191
- var r;
192
- return e && (r = x.getFormatInfo(e).maxDecimals) != null ? r : n;
193
- }, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), F = (e, n) => e.split(";").map((r) => /\.0?/.test(r) ? r.replace(
190
+ ], P = (e, r = 0) => {
191
+ var n;
192
+ return e && (n = x.getFormatInfo(e).maxDecimals) != null ? n : r;
193
+ }, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), F = (e, r) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
194
194
  /\.0*/g,
195
- `${n > 0 ? "." : ""}${q(Number(n || 0))}`
196
- ) : /0([^0]?)|0$/.test(r) ? r.replace(
195
+ `${r > 0 ? "." : ""}${q(Number(r || 0))}`
196
+ ) : /0([^0]?)|0$/.test(n) ? n.replace(
197
197
  /0([^0]+)|0$/,
198
- `0${n > 0 ? "." : ""}${q(Number(n || 0))}$1`
199
- ) : r).join(";"), rt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), O = {
198
+ `0${r > 0 ? "." : ""}${q(Number(r || 0))}$1`
199
+ ) : n).join(";"), nt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), O = {
200
200
  id: "sheet.command.numfmt.set.numfmt",
201
201
  type: U.COMMAND,
202
202
  // eslint-disable-next-line max-lines-per-function
203
- handler: (e, n) => {
204
- if (!n)
203
+ handler: (e, r) => {
204
+ if (!r)
205
205
  return !1;
206
- const t = e.get($), r = e.get(V), s = e.get(ce), a = K(r, n);
206
+ const t = e.get($), n = e.get(V), s = e.get(ce), a = K(n, r);
207
207
  if (!a) return !1;
208
- const { unitId: l, subUnitId: o, worksheet: h } = a, u = n.values.filter((i) => !!i.pattern), C = n.values.filter((i) => !i.pattern), y = Se(l, o, u), p = {
208
+ const { unitId: l, subUnitId: o, worksheet: h } = a, u = r.values.filter((i) => !!i.pattern), C = r.values.filter((i) => !i.pattern), y = Se(l, o, u), p = {
209
209
  unitId: l,
210
210
  subUnitId: o,
211
211
  ranges: C.map((i) => ({
@@ -232,7 +232,7 @@ const Fe = [
232
232
  const c = y.values[d];
233
233
  c.ranges = k(c.ranges);
234
234
  }), b.push({
235
- id: ne.id,
235
+ id: re.id,
236
236
  params: y
237
237
  });
238
238
  const v = Ce(e, y);
@@ -283,7 +283,7 @@ const Fe = [
283
283
  id: "sheet.command.numfmt.add.decimal.command",
284
284
  type: U.COMMAND,
285
285
  handler: async (e) => {
286
- const n = e.get($), t = e.get(j), r = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
286
+ const r = e.get($), t = e.get(j), n = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
287
287
  if (!a || !a.length)
288
288
  return !1;
289
289
  const l = K(s);
@@ -292,7 +292,7 @@ const Fe = [
292
292
  let u = 0;
293
293
  a.forEach((b) => {
294
294
  N.foreach(b.range, (_, m) => {
295
- const i = r.getValue(o, h, _, m);
295
+ const i = n.getValue(o, h, _, m);
296
296
  if (!i) {
297
297
  const v = l.worksheet.getCellRaw(_, m);
298
298
  if (!u && v && v.t === M.NUMBER && v.v) {
@@ -313,7 +313,7 @@ const Fe = [
313
313
  const C = u + 1, y = F(`0${C > 0 ? ".0" : ""}`, C), p = [];
314
314
  return a.forEach((b) => {
315
315
  N.foreach(b.range, (_, m) => {
316
- const i = r.getValue(o, h, _, m);
316
+ const i = n.getValue(o, h, _, m);
317
317
  if (W(i == null ? void 0 : i.pattern))
318
318
  p.push({
319
319
  row: _,
@@ -329,41 +329,41 @@ const Fe = [
329
329
  });
330
330
  }
331
331
  });
332
- }), p.length ? await n.executeCommand(O.id, { values: p }) : !1;
332
+ }), p.length ? await r.executeCommand(O.id, { values: p }) : !1;
333
333
  }
334
334
  }, je = {
335
335
  id: "sheet.command.numfmt.set.currency",
336
336
  type: U.COMMAND,
337
337
  handler: async (e) => {
338
- const n = e.get($), t = e.get(j), r = e.get(Q), s = t.getCurrentSelections();
338
+ const r = e.get($), t = e.get(j), n = e.get(Q), s = t.getCurrentSelections();
339
339
  if (!s || !s.length)
340
340
  return !1;
341
- const a = [], l = xe(r.getCurrentLocale()), o = Pe(l.locale);
341
+ const a = [], l = xe(n.getCurrentLocale()), o = Pe(l.locale);
342
342
  return s.forEach((u) => {
343
343
  N.foreach(u.range, (C, y) => {
344
344
  a.push({ row: C, col: y, pattern: o, type: "currency" });
345
345
  });
346
- }), await n.executeCommand(O.id, { values: a });
346
+ }), await r.executeCommand(O.id, { values: a });
347
347
  }
348
348
  }, Le = {
349
349
  id: "sheet.command.numfmt.set.percent",
350
350
  type: U.COMMAND,
351
351
  handler: async (e) => {
352
- const n = e.get($), r = e.get(j).getCurrentSelections();
353
- if (!r || !r.length)
352
+ const r = e.get($), n = e.get(j).getCurrentSelections();
353
+ if (!n || !n.length)
354
354
  return !1;
355
355
  const s = [], a = "0%";
356
- return r.forEach((o) => {
356
+ return n.forEach((o) => {
357
357
  N.foreach(o.range, (h, u) => {
358
358
  s.push({ row: h, col: u, pattern: a, type: "percent" });
359
359
  });
360
- }), await n.executeCommand(O.id, { values: s });
360
+ }), await r.executeCommand(O.id, { values: s });
361
361
  }
362
362
  }, Be = {
363
363
  id: "sheet.command.numfmt.subtract.decimal.command",
364
364
  type: U.COMMAND,
365
365
  handler: async (e) => {
366
- const n = e.get($), t = e.get(j), r = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
366
+ const r = e.get($), t = e.get(j), n = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
367
367
  if (!a || !a.length)
368
368
  return !1;
369
369
  const l = K(s);
@@ -372,7 +372,7 @@ const Fe = [
372
372
  let u = 0;
373
373
  a.forEach((_) => {
374
374
  N.foreach(_.range, (m, i) => {
375
- const g = r.getValue(o, h, m, i);
375
+ const g = n.getValue(o, h, m, i);
376
376
  if (!g) {
377
377
  const d = l.worksheet.getCellRaw(m, i);
378
378
  if (!u && d && d.t === M.NUMBER && d.v) {
@@ -393,7 +393,7 @@ const Fe = [
393
393
  const C = u - 1, y = F(`0${C > 0 ? ".0" : "."}`, C), p = [];
394
394
  return a.forEach((_) => {
395
395
  N.foreach(_.range, (m, i) => {
396
- const g = r.getValue(o, h, m, i);
396
+ const g = n.getValue(o, h, m, i);
397
397
  if (W(g == null ? void 0 : g.pattern))
398
398
  p.push({
399
399
  row: m,
@@ -409,25 +409,32 @@ const Fe = [
409
409
  });
410
410
  }
411
411
  });
412
- }), await n.executeCommand(O.id, { values: p });
412
+ }), await r.executeCommand(O.id, { values: p });
413
413
  }
414
- }, se = "sheets-numfmt.config", X = {}, st = (e) => x.getFormatInfo(e).type || "unknown", He = (e, n, t = "en") => {
415
- const r = x.formatColor(e, n), s = r ? String(r) : void 0, a = x.format(e, n, { locale: t, throws: !1 });
416
- return n < 0 ? {
417
- result: a,
418
- color: s
419
- } : {
420
- result: a
414
+ }, se = "sheets-numfmt.config", X = {}, st = (e) => x.getFormatInfo(e).type || "unknown", He = (e, r, t = "en") => {
415
+ try {
416
+ const n = x.formatColor(e, r), s = n ? String(n) : void 0, a = x.format(e, r, { locale: t, throws: !1 });
417
+ return r < 0 ? {
418
+ result: a,
419
+ color: s
420
+ } : {
421
+ result: a
422
+ };
423
+ } catch (n) {
424
+ console.warn("getPatternPreview error:", e, n);
425
+ }
426
+ return {
427
+ result: String(r)
421
428
  };
422
- }, Ge = (e, n, t) => e === ue ? {
423
- result: String(we(n))
429
+ }, Ge = (e, r, t) => e === ue ? {
430
+ result: String(we(r))
424
431
  // In Excel, the default General format also needs to handle numeric precision.
425
- } : He(e, n, t);
426
- var We = Object.getOwnPropertyDescriptor, Ke = (e, n, t, r) => {
427
- for (var s = r > 1 ? void 0 : r ? We(n, t) : n, a = e.length - 1, l; a >= 0; a--)
432
+ } : He(e, r, t);
433
+ var We = Object.getOwnPropertyDescriptor, Ke = (e, r, t, n) => {
434
+ for (var s = n > 1 ? void 0 : n ? We(r, t) : r, a = e.length - 1, l; a >= 0; a--)
428
435
  (l = e[a]) && (s = l(s) || s);
429
436
  return s;
430
- }, E = (e, n) => (t, r) => n(t, r, e);
437
+ }, E = (e, r) => (t, n) => r(t, n, e);
431
438
  const Ze = {
432
439
  tl: {
433
440
  size: 6,
@@ -435,16 +442,16 @@ const Ze = {
435
442
  }
436
443
  };
437
444
  let D = class extends me {
438
- constructor(n, t, r, s, a, l, o) {
445
+ constructor(r, t, n, s, a, l, o) {
439
446
  super();
440
447
  L(this, "_locale$", new $e("en"));
441
448
  L(this, "locale$", this._locale$.asObservable());
442
- this._instanceService = n, this._sheetInterceptorService = t, this._themeService = r, this._commandService = s, this._numfmtService = a, this._localeService = l, this._configService = o, this._initInterceptorCellContent();
449
+ this._instanceService = r, this._sheetInterceptorService = t, this._themeService = n, this._commandService = s, this._numfmtService = a, this._localeService = l, this._configService = o, this._initInterceptorCellContent();
443
450
  }
444
451
  get locale() {
445
- const n = this._locale$.getValue();
446
- if (n)
447
- return n;
452
+ const r = this._locale$.getValue();
453
+ if (r)
454
+ return r;
448
455
  switch (this._localeService.getCurrentLocale()) {
449
456
  case f.FR_FR:
450
457
  return "fr";
@@ -469,29 +476,29 @@ let D = class extends me {
469
476
  }
470
477
  // eslint-disable-next-line max-lines-per-function
471
478
  _initInterceptorCellContent() {
472
- const n = new R();
479
+ const r = new R();
473
480
  this.disposeWithMe(Ie(this._locale$, this._localeService.currentLocale$).subscribe(() => {
474
- n.reset();
481
+ r.reset();
475
482
  })), this.disposeWithMe(this._sheetInterceptorService.intercept(Re.CELL_CONTENT, {
476
483
  effect: z.Value | z.Style,
477
484
  // eslint-disable-next-line max-lines-per-function, complexity
478
- handler: (t, r, s) => {
485
+ handler: (t, n, s) => {
479
486
  var b, _;
480
487
  if (!t || t.v === void 0 || t.v === null || t.t === M.BOOLEAN || t.t === M.FORCE_STRING)
481
488
  return s(t);
482
- const a = r.unitId, l = r.subUnitId;
489
+ const a = n.unitId, l = n.subUnitId;
483
490
  let o;
484
491
  if (t != null && t.s) {
485
- const m = r.workbook.getStyles().get(t.s);
492
+ const m = n.workbook.getStyles().get(t.s);
486
493
  m != null && m.n && (o = m.n);
487
494
  }
488
- if (o || (o = this._numfmtService.getValue(a, l, r.row, r.col)), W(o == null ? void 0 : o.pattern) || t.t !== M.NUMBER && H(t.v, t.t) !== M.NUMBER)
495
+ if (o || (o = this._numfmtService.getValue(a, l, n.row, n.col)), W(o == null ? void 0 : o.pattern) || t.t !== M.NUMBER && H(t.v, t.t) !== M.NUMBER)
489
496
  return s(t);
490
497
  const h = t;
491
- if ((!t || t === r.rawData) && (t = { ...r.rawData }), J(o == null ? void 0 : o.pattern))
498
+ if ((!t || t === n.rawData) && (t = { ...n.rawData }), J(o == null ? void 0 : o.pattern))
492
499
  return (b = this._configService.getConfig(se)) != null && b.disableTextFormatMark ? (t.t = M.STRING, s(t)) : (t.t = M.STRING, t.markers = { ...t == null ? void 0 : t.markers, ...Ze }, s(t));
493
500
  let u = "";
494
- const C = n.getValue(r.row, r.col);
501
+ const C = r.getValue(n.row, n.col);
495
502
  if (C && C.parameters === `${h.v}_${o == null ? void 0 : o.pattern}`)
496
503
  return s({ ...t, ...C.result });
497
504
  const y = Ge(o == null ? void 0 : o.pattern, Number(h.v), this.locale);
@@ -502,40 +509,40 @@ let D = class extends me {
502
509
  const m = (_ = this._themeService.getColorFromTheme(`${y.color}.500`)) != null ? _ : y.color;
503
510
  m && (p.interceptorStyle = { cl: { rgb: m } });
504
511
  }
505
- return n.setValue(r.row, r.col, {
512
+ return r.setValue(n.row, n.col, {
506
513
  result: p,
507
514
  parameters: `${h.v}_${o == null ? void 0 : o.pattern}`
508
515
  }), Object.assign(t, p), s(t);
509
516
  },
510
517
  priority: Ee.NUMFMT
511
518
  })), this.disposeWithMe(this._commandService.onCommandExecuted((t) => {
512
- if (t.id === ne.id) {
513
- const r = t.params;
514
- Object.keys(r.values).forEach((s) => {
515
- r.values[s].ranges.forEach((l) => {
519
+ if (t.id === re.id) {
520
+ const n = t.params;
521
+ Object.keys(n.values).forEach((s) => {
522
+ n.values[s].ranges.forEach((l) => {
516
523
  N.foreach(l, (o, h) => {
517
- n.realDeleteValue(o, h);
524
+ r.realDeleteValue(o, h);
518
525
  });
519
526
  });
520
527
  });
521
528
  } else if (t.id === G.id) {
522
- const r = t.params;
523
- new R(r.cellValue).forValue((s, a) => {
524
- n.realDeleteValue(s, a);
529
+ const n = t.params;
530
+ new R(n.cellValue).forValue((s, a) => {
531
+ r.realDeleteValue(s, a);
525
532
  });
526
533
  }
527
534
  })), this.disposeWithMe(
528
535
  this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
529
536
  Te((t) => {
530
- var r;
531
- return (r = t == null ? void 0 : t.activeSheet$) != null ? r : Ue(null);
537
+ var n;
538
+ return (n = t == null ? void 0 : t.activeSheet$) != null ? n : Ue(null);
532
539
  }),
533
540
  Oe(1)
534
- ).subscribe(() => n.reset())
541
+ ).subscribe(() => r.reset())
535
542
  );
536
543
  }
537
- setNumfmtLocal(n) {
538
- this._locale$.next(n);
544
+ setNumfmtLocal(r) {
545
+ this._locale$.next(r);
539
546
  }
540
547
  };
541
548
  D = Ke([
@@ -548,14 +555,14 @@ D = Ke([
548
555
  E(6, ee)
549
556
  ], D);
550
557
  const ze = "SHEET_NUMFMT_PLUGIN";
551
- var ke = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, qe = (e, n, t) => n in e ? ke(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t, Xe = (e, n, t, r) => {
552
- for (var s = r > 1 ? void 0 : r ? Ye(n, t) : n, a = e.length - 1, l; a >= 0; a--)
558
+ var ke = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, qe = (e, r, t) => r in e ? ke(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, Xe = (e, r, t, n) => {
559
+ for (var s = n > 1 ? void 0 : n ? Ye(r, t) : r, a = e.length - 1, l; a >= 0; a--)
553
560
  (l = e[a]) && (s = l(s) || s);
554
561
  return s;
555
- }, B = (e, n) => (t, r) => n(t, r, e), oe = (e, n, t) => qe(e, typeof n != "symbol" ? n + "" : n, t);
562
+ }, B = (e, r) => (t, n) => r(t, n, e), oe = (e, r, t) => qe(e, typeof r != "symbol" ? r + "" : r, t);
556
563
  let A = class extends he {
557
- constructor(e = X, n, t, r) {
558
- super(), this._config = e, this._injector = n, this._configService = t, this._commandService = r;
564
+ constructor(e = X, r, t, n) {
565
+ super(), this._config = e, this._injector = r, this._configService = t, this._commandService = n;
559
566
  const { ...s } = pe(
560
567
  {},
561
568
  X,
@@ -590,10 +597,10 @@ A = Xe([
590
597
  B(2, ee),
591
598
  B(3, $)
592
599
  ], A);
593
- const ot = (e) => re.find((t) => e.includes(t)), at = () => re.map((e) => ({ label: e, value: e })), it = (e) => Ae.map((n) => ({
594
- label: n.label(e),
595
- value: n.suffix(e),
596
- color: n.color
600
+ const ot = (e) => ne.find((t) => e.includes(t)), at = () => ne.map((e) => ({ label: e, value: e })), it = (e) => Ae.map((r) => ({
601
+ label: r.label(e),
602
+ value: r.suffix(e),
603
+ color: r.color
597
604
  })), ct = () => Fe.map((e) => ({ label: e.label, value: e.suffix })), lt = () => De.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
598
605
  export {
599
606
  Ve as AddDecimalCommand,
@@ -607,7 +614,7 @@ export {
607
614
  D as SheetsNumfmtCellContentController,
608
615
  Be as SubtractDecimalCommand,
609
616
  A as UniverSheetsNumfmtPlugin,
610
- re as currencySymbols,
617
+ ne as currencySymbols,
611
618
  Pe as getCurrencyFormat,
612
619
  it as getCurrencyFormatOptions,
613
620
  at as getCurrencyOptions,
@@ -621,7 +628,7 @@ export {
621
628
  He as getPatternPreview,
622
629
  Ge as getPatternPreviewIgnoreGeneral,
623
630
  st as getPatternType,
624
- rt as isPatternHasDecimal,
631
+ nt as isPatternHasDecimal,
625
632
  w as localeCurrencySymbolMap,
626
633
  F as setPatternDecimal
627
634
  };
package/lib/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  var ae = Object.defineProperty;
2
- var ie = (e, n, t) => n in e ? ae(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
- var L = (e, n, t) => ie(e, typeof n != "symbol" ? n + "" : n, t);
2
+ var ie = (e, r, t) => r in e ? ae(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
+ var L = (e, r, t) => ie(e, typeof r != "symbol" ? r + "" : r, t);
4
4
  import { LocaleType as f, numfmt as x, CommandType as U, ICommandService as $, IUniverInstanceService as V, IUndoRedoService as ce, isTextFormat as J, CellValueType as M, ObjectMatrix as R, sequenceExecute as le, Range as N, isDefaultFormat as W, LocaleService as Q, DEFAULT_NUMBER_FORMAT as ue, Inject as I, ThemeService as fe, IConfigService as ee, Disposable as me, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as de, Injector as ge, Plugin as he, merge as pe, registerDependencies as _e, touchDependencies as ve } from "@univerjs/core";
5
- import { getSheetCommandTarget as K, transformCellsToRange as Se, checkCellValueType as H, rangeMerge as k, SetNumfmtMutation as ne, factorySetNumfmtUndoMutation as Ce, RemoveNumfmtMutation as ye, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as Z, SheetInterceptorService as Me, INTERCEPTOR_POINT as Re, InterceptCellContentPriority as Ee, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
5
+ import { getSheetCommandTarget as K, transformCellsToRange as Se, checkCellValueType as H, rangeMerge as k, SetNumfmtMutation as re, factorySetNumfmtUndoMutation as Ce, RemoveNumfmtMutation as ye, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as Z, SheetInterceptorService as Me, INTERCEPTOR_POINT as Re, InterceptCellContentPriority as Ee, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
6
6
  import { BehaviorSubject as $e, merge as Ie, switchMap as Te, of as Ue, skip as Oe } from "rxjs";
7
7
  import { stripErrorMargin as we } from "@univerjs/engine-formula";
8
- const re = [
8
+ const ne = [
9
9
  "$",
10
10
  "£",
11
11
  "¥",
@@ -80,11 +80,11 @@ function xe(e) {
80
80
  function Y(e) {
81
81
  return w.get(e) || "$";
82
82
  }
83
- function Pe(e, n = 2) {
84
- let t = n;
85
- n > 127 && (t = 127);
86
- let r = "";
87
- return t > 0 && (r = `.${"0".repeat(t)}`), `"${Y(e)}"#,##0${r}_);[Red]("${Y(e)}"#,##0${r})`;
83
+ function Pe(e, r = 2) {
84
+ let t = r;
85
+ r > 127 && (t = 127);
86
+ let n = "";
87
+ return t > 0 && (n = `.${"0".repeat(t)}`), `"${Y(e)}"#,##0${n}_);[Red]("${Y(e)}"#,##0${n})`;
88
88
  }
89
89
  const Fe = [
90
90
  {
@@ -187,25 +187,25 @@ const Fe = [
187
187
  suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
188
188
  color: "red"
189
189
  }
190
- ], P = (e, n = 0) => {
191
- var r;
192
- return e && (r = x.getFormatInfo(e).maxDecimals) != null ? r : n;
193
- }, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), F = (e, n) => e.split(";").map((r) => /\.0?/.test(r) ? r.replace(
190
+ ], P = (e, r = 0) => {
191
+ var n;
192
+ return e && (n = x.getFormatInfo(e).maxDecimals) != null ? n : r;
193
+ }, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), F = (e, r) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
194
194
  /\.0*/g,
195
- `${n > 0 ? "." : ""}${q(Number(n || 0))}`
196
- ) : /0([^0]?)|0$/.test(r) ? r.replace(
195
+ `${r > 0 ? "." : ""}${q(Number(r || 0))}`
196
+ ) : /0([^0]?)|0$/.test(n) ? n.replace(
197
197
  /0([^0]+)|0$/,
198
- `0${n > 0 ? "." : ""}${q(Number(n || 0))}$1`
199
- ) : r).join(";"), rt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), O = {
198
+ `0${r > 0 ? "." : ""}${q(Number(r || 0))}$1`
199
+ ) : n).join(";"), nt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), O = {
200
200
  id: "sheet.command.numfmt.set.numfmt",
201
201
  type: U.COMMAND,
202
202
  // eslint-disable-next-line max-lines-per-function
203
- handler: (e, n) => {
204
- if (!n)
203
+ handler: (e, r) => {
204
+ if (!r)
205
205
  return !1;
206
- const t = e.get($), r = e.get(V), s = e.get(ce), a = K(r, n);
206
+ const t = e.get($), n = e.get(V), s = e.get(ce), a = K(n, r);
207
207
  if (!a) return !1;
208
- const { unitId: l, subUnitId: o, worksheet: h } = a, u = n.values.filter((i) => !!i.pattern), C = n.values.filter((i) => !i.pattern), y = Se(l, o, u), p = {
208
+ const { unitId: l, subUnitId: o, worksheet: h } = a, u = r.values.filter((i) => !!i.pattern), C = r.values.filter((i) => !i.pattern), y = Se(l, o, u), p = {
209
209
  unitId: l,
210
210
  subUnitId: o,
211
211
  ranges: C.map((i) => ({
@@ -232,7 +232,7 @@ const Fe = [
232
232
  const c = y.values[d];
233
233
  c.ranges = k(c.ranges);
234
234
  }), b.push({
235
- id: ne.id,
235
+ id: re.id,
236
236
  params: y
237
237
  });
238
238
  const v = Ce(e, y);
@@ -283,7 +283,7 @@ const Fe = [
283
283
  id: "sheet.command.numfmt.add.decimal.command",
284
284
  type: U.COMMAND,
285
285
  handler: async (e) => {
286
- const n = e.get($), t = e.get(j), r = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
286
+ const r = e.get($), t = e.get(j), n = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
287
287
  if (!a || !a.length)
288
288
  return !1;
289
289
  const l = K(s);
@@ -292,7 +292,7 @@ const Fe = [
292
292
  let u = 0;
293
293
  a.forEach((b) => {
294
294
  N.foreach(b.range, (_, m) => {
295
- const i = r.getValue(o, h, _, m);
295
+ const i = n.getValue(o, h, _, m);
296
296
  if (!i) {
297
297
  const v = l.worksheet.getCellRaw(_, m);
298
298
  if (!u && v && v.t === M.NUMBER && v.v) {
@@ -313,7 +313,7 @@ const Fe = [
313
313
  const C = u + 1, y = F(`0${C > 0 ? ".0" : ""}`, C), p = [];
314
314
  return a.forEach((b) => {
315
315
  N.foreach(b.range, (_, m) => {
316
- const i = r.getValue(o, h, _, m);
316
+ const i = n.getValue(o, h, _, m);
317
317
  if (W(i == null ? void 0 : i.pattern))
318
318
  p.push({
319
319
  row: _,
@@ -329,41 +329,41 @@ const Fe = [
329
329
  });
330
330
  }
331
331
  });
332
- }), p.length ? await n.executeCommand(O.id, { values: p }) : !1;
332
+ }), p.length ? await r.executeCommand(O.id, { values: p }) : !1;
333
333
  }
334
334
  }, je = {
335
335
  id: "sheet.command.numfmt.set.currency",
336
336
  type: U.COMMAND,
337
337
  handler: async (e) => {
338
- const n = e.get($), t = e.get(j), r = e.get(Q), s = t.getCurrentSelections();
338
+ const r = e.get($), t = e.get(j), n = e.get(Q), s = t.getCurrentSelections();
339
339
  if (!s || !s.length)
340
340
  return !1;
341
- const a = [], l = xe(r.getCurrentLocale()), o = Pe(l.locale);
341
+ const a = [], l = xe(n.getCurrentLocale()), o = Pe(l.locale);
342
342
  return s.forEach((u) => {
343
343
  N.foreach(u.range, (C, y) => {
344
344
  a.push({ row: C, col: y, pattern: o, type: "currency" });
345
345
  });
346
- }), await n.executeCommand(O.id, { values: a });
346
+ }), await r.executeCommand(O.id, { values: a });
347
347
  }
348
348
  }, Le = {
349
349
  id: "sheet.command.numfmt.set.percent",
350
350
  type: U.COMMAND,
351
351
  handler: async (e) => {
352
- const n = e.get($), r = e.get(j).getCurrentSelections();
353
- if (!r || !r.length)
352
+ const r = e.get($), n = e.get(j).getCurrentSelections();
353
+ if (!n || !n.length)
354
354
  return !1;
355
355
  const s = [], a = "0%";
356
- return r.forEach((o) => {
356
+ return n.forEach((o) => {
357
357
  N.foreach(o.range, (h, u) => {
358
358
  s.push({ row: h, col: u, pattern: a, type: "percent" });
359
359
  });
360
- }), await n.executeCommand(O.id, { values: s });
360
+ }), await r.executeCommand(O.id, { values: s });
361
361
  }
362
362
  }, Be = {
363
363
  id: "sheet.command.numfmt.subtract.decimal.command",
364
364
  type: U.COMMAND,
365
365
  handler: async (e) => {
366
- const n = e.get($), t = e.get(j), r = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
366
+ const r = e.get($), t = e.get(j), n = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
367
367
  if (!a || !a.length)
368
368
  return !1;
369
369
  const l = K(s);
@@ -372,7 +372,7 @@ const Fe = [
372
372
  let u = 0;
373
373
  a.forEach((_) => {
374
374
  N.foreach(_.range, (m, i) => {
375
- const g = r.getValue(o, h, m, i);
375
+ const g = n.getValue(o, h, m, i);
376
376
  if (!g) {
377
377
  const d = l.worksheet.getCellRaw(m, i);
378
378
  if (!u && d && d.t === M.NUMBER && d.v) {
@@ -393,7 +393,7 @@ const Fe = [
393
393
  const C = u - 1, y = F(`0${C > 0 ? ".0" : "."}`, C), p = [];
394
394
  return a.forEach((_) => {
395
395
  N.foreach(_.range, (m, i) => {
396
- const g = r.getValue(o, h, m, i);
396
+ const g = n.getValue(o, h, m, i);
397
397
  if (W(g == null ? void 0 : g.pattern))
398
398
  p.push({
399
399
  row: m,
@@ -409,25 +409,32 @@ const Fe = [
409
409
  });
410
410
  }
411
411
  });
412
- }), await n.executeCommand(O.id, { values: p });
412
+ }), await r.executeCommand(O.id, { values: p });
413
413
  }
414
- }, se = "sheets-numfmt.config", X = {}, st = (e) => x.getFormatInfo(e).type || "unknown", He = (e, n, t = "en") => {
415
- const r = x.formatColor(e, n), s = r ? String(r) : void 0, a = x.format(e, n, { locale: t, throws: !1 });
416
- return n < 0 ? {
417
- result: a,
418
- color: s
419
- } : {
420
- result: a
414
+ }, se = "sheets-numfmt.config", X = {}, st = (e) => x.getFormatInfo(e).type || "unknown", He = (e, r, t = "en") => {
415
+ try {
416
+ const n = x.formatColor(e, r), s = n ? String(n) : void 0, a = x.format(e, r, { locale: t, throws: !1 });
417
+ return r < 0 ? {
418
+ result: a,
419
+ color: s
420
+ } : {
421
+ result: a
422
+ };
423
+ } catch (n) {
424
+ console.warn("getPatternPreview error:", e, n);
425
+ }
426
+ return {
427
+ result: String(r)
421
428
  };
422
- }, Ge = (e, n, t) => e === ue ? {
423
- result: String(we(n))
429
+ }, Ge = (e, r, t) => e === ue ? {
430
+ result: String(we(r))
424
431
  // In Excel, the default General format also needs to handle numeric precision.
425
- } : He(e, n, t);
426
- var We = Object.getOwnPropertyDescriptor, Ke = (e, n, t, r) => {
427
- for (var s = r > 1 ? void 0 : r ? We(n, t) : n, a = e.length - 1, l; a >= 0; a--)
432
+ } : He(e, r, t);
433
+ var We = Object.getOwnPropertyDescriptor, Ke = (e, r, t, n) => {
434
+ for (var s = n > 1 ? void 0 : n ? We(r, t) : r, a = e.length - 1, l; a >= 0; a--)
428
435
  (l = e[a]) && (s = l(s) || s);
429
436
  return s;
430
- }, E = (e, n) => (t, r) => n(t, r, e);
437
+ }, E = (e, r) => (t, n) => r(t, n, e);
431
438
  const Ze = {
432
439
  tl: {
433
440
  size: 6,
@@ -435,16 +442,16 @@ const Ze = {
435
442
  }
436
443
  };
437
444
  let D = class extends me {
438
- constructor(n, t, r, s, a, l, o) {
445
+ constructor(r, t, n, s, a, l, o) {
439
446
  super();
440
447
  L(this, "_locale$", new $e("en"));
441
448
  L(this, "locale$", this._locale$.asObservable());
442
- this._instanceService = n, this._sheetInterceptorService = t, this._themeService = r, this._commandService = s, this._numfmtService = a, this._localeService = l, this._configService = o, this._initInterceptorCellContent();
449
+ this._instanceService = r, this._sheetInterceptorService = t, this._themeService = n, this._commandService = s, this._numfmtService = a, this._localeService = l, this._configService = o, this._initInterceptorCellContent();
443
450
  }
444
451
  get locale() {
445
- const n = this._locale$.getValue();
446
- if (n)
447
- return n;
452
+ const r = this._locale$.getValue();
453
+ if (r)
454
+ return r;
448
455
  switch (this._localeService.getCurrentLocale()) {
449
456
  case f.FR_FR:
450
457
  return "fr";
@@ -469,29 +476,29 @@ let D = class extends me {
469
476
  }
470
477
  // eslint-disable-next-line max-lines-per-function
471
478
  _initInterceptorCellContent() {
472
- const n = new R();
479
+ const r = new R();
473
480
  this.disposeWithMe(Ie(this._locale$, this._localeService.currentLocale$).subscribe(() => {
474
- n.reset();
481
+ r.reset();
475
482
  })), this.disposeWithMe(this._sheetInterceptorService.intercept(Re.CELL_CONTENT, {
476
483
  effect: z.Value | z.Style,
477
484
  // eslint-disable-next-line max-lines-per-function, complexity
478
- handler: (t, r, s) => {
485
+ handler: (t, n, s) => {
479
486
  var b, _;
480
487
  if (!t || t.v === void 0 || t.v === null || t.t === M.BOOLEAN || t.t === M.FORCE_STRING)
481
488
  return s(t);
482
- const a = r.unitId, l = r.subUnitId;
489
+ const a = n.unitId, l = n.subUnitId;
483
490
  let o;
484
491
  if (t != null && t.s) {
485
- const m = r.workbook.getStyles().get(t.s);
492
+ const m = n.workbook.getStyles().get(t.s);
486
493
  m != null && m.n && (o = m.n);
487
494
  }
488
- if (o || (o = this._numfmtService.getValue(a, l, r.row, r.col)), W(o == null ? void 0 : o.pattern) || t.t !== M.NUMBER && H(t.v, t.t) !== M.NUMBER)
495
+ if (o || (o = this._numfmtService.getValue(a, l, n.row, n.col)), W(o == null ? void 0 : o.pattern) || t.t !== M.NUMBER && H(t.v, t.t) !== M.NUMBER)
489
496
  return s(t);
490
497
  const h = t;
491
- if ((!t || t === r.rawData) && (t = { ...r.rawData }), J(o == null ? void 0 : o.pattern))
498
+ if ((!t || t === n.rawData) && (t = { ...n.rawData }), J(o == null ? void 0 : o.pattern))
492
499
  return (b = this._configService.getConfig(se)) != null && b.disableTextFormatMark ? (t.t = M.STRING, s(t)) : (t.t = M.STRING, t.markers = { ...t == null ? void 0 : t.markers, ...Ze }, s(t));
493
500
  let u = "";
494
- const C = n.getValue(r.row, r.col);
501
+ const C = r.getValue(n.row, n.col);
495
502
  if (C && C.parameters === `${h.v}_${o == null ? void 0 : o.pattern}`)
496
503
  return s({ ...t, ...C.result });
497
504
  const y = Ge(o == null ? void 0 : o.pattern, Number(h.v), this.locale);
@@ -502,40 +509,40 @@ let D = class extends me {
502
509
  const m = (_ = this._themeService.getColorFromTheme(`${y.color}.500`)) != null ? _ : y.color;
503
510
  m && (p.interceptorStyle = { cl: { rgb: m } });
504
511
  }
505
- return n.setValue(r.row, r.col, {
512
+ return r.setValue(n.row, n.col, {
506
513
  result: p,
507
514
  parameters: `${h.v}_${o == null ? void 0 : o.pattern}`
508
515
  }), Object.assign(t, p), s(t);
509
516
  },
510
517
  priority: Ee.NUMFMT
511
518
  })), this.disposeWithMe(this._commandService.onCommandExecuted((t) => {
512
- if (t.id === ne.id) {
513
- const r = t.params;
514
- Object.keys(r.values).forEach((s) => {
515
- r.values[s].ranges.forEach((l) => {
519
+ if (t.id === re.id) {
520
+ const n = t.params;
521
+ Object.keys(n.values).forEach((s) => {
522
+ n.values[s].ranges.forEach((l) => {
516
523
  N.foreach(l, (o, h) => {
517
- n.realDeleteValue(o, h);
524
+ r.realDeleteValue(o, h);
518
525
  });
519
526
  });
520
527
  });
521
528
  } else if (t.id === G.id) {
522
- const r = t.params;
523
- new R(r.cellValue).forValue((s, a) => {
524
- n.realDeleteValue(s, a);
529
+ const n = t.params;
530
+ new R(n.cellValue).forValue((s, a) => {
531
+ r.realDeleteValue(s, a);
525
532
  });
526
533
  }
527
534
  })), this.disposeWithMe(
528
535
  this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
529
536
  Te((t) => {
530
- var r;
531
- return (r = t == null ? void 0 : t.activeSheet$) != null ? r : Ue(null);
537
+ var n;
538
+ return (n = t == null ? void 0 : t.activeSheet$) != null ? n : Ue(null);
532
539
  }),
533
540
  Oe(1)
534
- ).subscribe(() => n.reset())
541
+ ).subscribe(() => r.reset())
535
542
  );
536
543
  }
537
- setNumfmtLocal(n) {
538
- this._locale$.next(n);
544
+ setNumfmtLocal(r) {
545
+ this._locale$.next(r);
539
546
  }
540
547
  };
541
548
  D = Ke([
@@ -548,14 +555,14 @@ D = Ke([
548
555
  E(6, ee)
549
556
  ], D);
550
557
  const ze = "SHEET_NUMFMT_PLUGIN";
551
- var ke = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, qe = (e, n, t) => n in e ? ke(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t, Xe = (e, n, t, r) => {
552
- for (var s = r > 1 ? void 0 : r ? Ye(n, t) : n, a = e.length - 1, l; a >= 0; a--)
558
+ var ke = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, qe = (e, r, t) => r in e ? ke(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, Xe = (e, r, t, n) => {
559
+ for (var s = n > 1 ? void 0 : n ? Ye(r, t) : r, a = e.length - 1, l; a >= 0; a--)
553
560
  (l = e[a]) && (s = l(s) || s);
554
561
  return s;
555
- }, B = (e, n) => (t, r) => n(t, r, e), oe = (e, n, t) => qe(e, typeof n != "symbol" ? n + "" : n, t);
562
+ }, B = (e, r) => (t, n) => r(t, n, e), oe = (e, r, t) => qe(e, typeof r != "symbol" ? r + "" : r, t);
556
563
  let A = class extends he {
557
- constructor(e = X, n, t, r) {
558
- super(), this._config = e, this._injector = n, this._configService = t, this._commandService = r;
564
+ constructor(e = X, r, t, n) {
565
+ super(), this._config = e, this._injector = r, this._configService = t, this._commandService = n;
559
566
  const { ...s } = pe(
560
567
  {},
561
568
  X,
@@ -590,10 +597,10 @@ A = Xe([
590
597
  B(2, ee),
591
598
  B(3, $)
592
599
  ], A);
593
- const ot = (e) => re.find((t) => e.includes(t)), at = () => re.map((e) => ({ label: e, value: e })), it = (e) => Ae.map((n) => ({
594
- label: n.label(e),
595
- value: n.suffix(e),
596
- color: n.color
600
+ const ot = (e) => ne.find((t) => e.includes(t)), at = () => ne.map((e) => ({ label: e, value: e })), it = (e) => Ae.map((r) => ({
601
+ label: r.label(e),
602
+ value: r.suffix(e),
603
+ color: r.color
597
604
  })), ct = () => Fe.map((e) => ({ label: e.label, value: e.suffix })), lt = () => De.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
598
605
  export {
599
606
  Ve as AddDecimalCommand,
@@ -607,7 +614,7 @@ export {
607
614
  D as SheetsNumfmtCellContentController,
608
615
  Be as SubtractDecimalCommand,
609
616
  A as UniverSheetsNumfmtPlugin,
610
- re as currencySymbols,
617
+ ne as currencySymbols,
611
618
  Pe as getCurrencyFormat,
612
619
  it as getCurrencyFormatOptions,
613
620
  at as getCurrencyOptions,
@@ -621,7 +628,7 @@ export {
621
628
  He as getPatternPreview,
622
629
  Ge as getPatternPreviewIgnoreGeneral,
623
630
  st as getPatternType,
624
- rt as isPatternHasDecimal,
631
+ nt as isPatternHasDecimal,
625
632
  w as localeCurrencySymbolMap,
626
633
  F as setPatternDecimal
627
634
  };
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(r,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-formula"],t):(r=typeof globalThis<"u"?globalThis:r||self,t(r.UniverSheetsNumfmt={},r.UniverCore,r.UniverSheets,r.rxjs,r.UniverEngineFormula))})(this,(function(r,t,u,N,X){"use strict";var de=Object.defineProperty;var ge=(r,t,u)=>t in r?de(r,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[t]=u;var V=(r,t,u)=>ge(r,typeof t!="symbol"?t+"":t,u);const P=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],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,"€"]]);function j(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR: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,a=2){let i=a;a>127&&(i=127);let n="";return i>0&&(n=`.${"0".repeat(i)}`),`"${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"}],U=(e,a=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:a},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,a)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${L(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${L(Number(a||0))}$1`):n).join(";"),J=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),I={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,a)=>{if(!a)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.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),y={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)=>{t.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.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 t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.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(e,M);p.push(...h)}if(T.length){y.ranges=u.rangeMerge(y.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 t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.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:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const h=u.factoryRemoveNumfmtUndoMutation(e,y);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:v.getMatrix()}},...h)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),C}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(!c){const h=m.worksheet.getCellRaw(p,C);if(!f&&h&&h.t===t.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),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(t.isDefaultFormat(c==null?void 0:c.pattern))y.push({row:p,col:C,pattern:M});else{const v=U(c.pattern),h=$(c.pattern,v+1);h!==c.pattern&&y.push({row:p,col:C,pattern:h})}})}),y.length?await a.executeCommand(I.id,{values:y}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(t.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=j(n.getCurrentLocale()),S=A(m.locale);return s.forEach(f=>{t.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(I.id,{values:l})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(o,f)=>{s.push({row:o,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(I.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(!v){const g=m.worksheet.getCellRaw(C,c);if(!f&&g&&g.t===t.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),y=[];return l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(t.isDefaultFormat(v==null?void 0:v.pattern))y.push({row:C,col:c,pattern:M});else{const h=U(v.pattern);y.push({row:C,col:c,pattern:$(v.pattern,h-1)})}})}),await a.executeCommand(I.id,{values:y})}},D="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,i="en")=>{const n=t.numfmt.formatColor(e,a),s=n?String(n):void 0,l=t.numfmt.format(e,a,{locale:i,throws:!1});return a<0?{result:l,color:s}:{result:l}},Y=(e,a,i)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(X.stripErrorMargin(a))}:k(e,a,i);var ee=Object.getOwnPropertyDescriptor,te=(e,a,i,n)=>{for(var s=n>1?void 0:n?ee(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},R=(e,a)=>(i,n)=>a(i,n,e);const ne={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,o){super();V(this,"_locale$",new N.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 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 i=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,C;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.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)),t.isDefaultFormat(o==null?void 0:o.pattern)||n.t!==t.CellValueType.NUMBER&&u.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(o==null?void 0:o.pattern))return(p=this._configService.getConfig(D))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},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 y=Y(o==null?void 0:o.pattern,Number(f.v),this.locale);if(T=y.result,!T)return l(n);const b={v:T,t:t.CellValueType.NUMBER};if(y.color){const c=(C=this._themeService.getColorFromTheme(`${y.color}.500`))!=null?C:y.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=>{t.Range.foreach(S,(o,f)=>{i.realDeleteValue(o,f)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},r.SheetsNumfmtCellContentController=te([R(0,t.IUniverInstanceService),R(1,t.Inject(u.SheetInterceptorService)),R(2,t.Inject(t.ThemeService)),R(3,t.Inject(t.ICommandService)),R(4,t.Inject(u.INumfmtService)),R(5,t.Inject(t.LocaleService)),R(6,t.IConfigService)],r.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var re=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,a,i)=>a in e?re(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,le=(e,a,i,n)=>{for(var s=n>1?void 0:n?ie(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},w=(e,a)=>(i,n)=>a(i,n,e),z=(e,a,i)=>se(e,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,i,n,s){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},Z,this._config);this._configService.setConfig(D,l)}onStarting(){t.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]])}onRendered(){[x,q,W,K,I].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},z(r.UniverSheetsNumfmtPlugin,"pluginName",ae),z(r.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),w(1,t.Inject(t.Injector)),w(2,t.IConfigService),w(3,t.ICommandService)],r.UniverSheetsNumfmtPlugin);const ce=e=>P.find(i=>e.includes(i)),oe=()=>P.map(e=>({label:e,value:e})),ue=e=>H.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),me=()=>B.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=H,r.DATEFMTLISG=B,r.NUMBERFORMAT=G,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,r.SetCurrencyCommand=W,r.SetNumfmtCommand=I,r.SetPercentCommand=K,r.SubtractDecimalCommand=q,r.currencySymbols=P,r.getCurrencyFormat=A,r.getCurrencyFormatOptions=ue,r.getCurrencyOptions=oe,r.getCurrencySymbolByLocale=F,r.getCurrencySymbolIconByLocale=j,r.getCurrencyType=ce,r.getDateFormatOptions=me,r.getDecimalFromPattern=U,r.getDecimalString=L,r.getNumberFormatOptions=fe,r.getPatternPreview=k,r.getPatternPreviewIgnoreGeneral=Y,r.getPatternType=Q,r.isPatternHasDecimal=J,r.localeCurrencySymbolMap=E,r.setPatternDecimal=$,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(r,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-formula"],t):(r=typeof globalThis<"u"?globalThis:r||self,t(r.UniverSheetsNumfmt={},r.UniverCore,r.UniverSheets,r.rxjs,r.UniverEngineFormula))})(this,(function(r,t,u,N,X){"use strict";var de=Object.defineProperty;var ge=(r,t,u)=>t in r?de(r,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[t]=u;var V=(r,t,u)=>ge(r,typeof t!="symbol"?t+"":t,u);const P=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],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,"€"]]);function j(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR: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,a=2){let i=a;a>127&&(i=127);let n="";return i>0&&(n=`.${"0".repeat(i)}`),`"${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"}],U=(e,a=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:a},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,a)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${L(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${L(Number(a||0))}$1`):n).join(";"),J=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),I={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,a)=>{if(!a)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.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),y={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)=>{t.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.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 t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.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(e,M);p.push(...h)}if(T.length){y.ranges=u.rangeMerge(y.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 t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.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:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const h=u.factoryRemoveNumfmtUndoMutation(e,y);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:v.getMatrix()}},...h)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),C}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(!c){const h=m.worksheet.getCellRaw(p,C);if(!f&&h&&h.t===t.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),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(t.isDefaultFormat(c==null?void 0:c.pattern))y.push({row:p,col:C,pattern:M});else{const v=U(c.pattern),h=$(c.pattern,v+1);h!==c.pattern&&y.push({row:p,col:C,pattern:h})}})}),y.length?await a.executeCommand(I.id,{values:y}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(t.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=j(n.getCurrentLocale()),S=A(m.locale);return s.forEach(f=>{t.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(I.id,{values:l})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(o,f)=>{s.push({row:o,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(I.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(!v){const g=m.worksheet.getCellRaw(C,c);if(!f&&g&&g.t===t.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),y=[];return l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(t.isDefaultFormat(v==null?void 0:v.pattern))y.push({row:C,col:c,pattern:M});else{const h=U(v.pattern);y.push({row:C,col:c,pattern:$(v.pattern,h-1)})}})}),await a.executeCommand(I.id,{values:y})}},D="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,i="en")=>{try{const n=t.numfmt.formatColor(e,a),s=n?String(n):void 0,l=t.numfmt.format(e,a,{locale:i,throws:!1});return a<0?{result:l,color:s}:{result:l}}catch(n){console.warn("getPatternPreview error:",e,n)}return{result:String(a)}},Y=(e,a,i)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(X.stripErrorMargin(a))}:k(e,a,i);var ee=Object.getOwnPropertyDescriptor,te=(e,a,i,n)=>{for(var s=n>1?void 0:n?ee(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},R=(e,a)=>(i,n)=>a(i,n,e);const ne={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,o){super();V(this,"_locale$",new N.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 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 i=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,C;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.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)),t.isDefaultFormat(o==null?void 0:o.pattern)||n.t!==t.CellValueType.NUMBER&&u.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(o==null?void 0:o.pattern))return(p=this._configService.getConfig(D))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},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 y=Y(o==null?void 0:o.pattern,Number(f.v),this.locale);if(T=y.result,!T)return l(n);const b={v:T,t:t.CellValueType.NUMBER};if(y.color){const c=(C=this._themeService.getColorFromTheme(`${y.color}.500`))!=null?C:y.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=>{t.Range.foreach(S,(o,f)=>{i.realDeleteValue(o,f)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},r.SheetsNumfmtCellContentController=te([R(0,t.IUniverInstanceService),R(1,t.Inject(u.SheetInterceptorService)),R(2,t.Inject(t.ThemeService)),R(3,t.Inject(t.ICommandService)),R(4,t.Inject(u.INumfmtService)),R(5,t.Inject(t.LocaleService)),R(6,t.IConfigService)],r.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var re=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,a,i)=>a in e?re(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,le=(e,a,i,n)=>{for(var s=n>1?void 0:n?ie(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},w=(e,a)=>(i,n)=>a(i,n,e),z=(e,a,i)=>se(e,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,i,n,s){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},Z,this._config);this._configService.setConfig(D,l)}onStarting(){t.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]])}onRendered(){[x,q,W,K,I].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},z(r.UniverSheetsNumfmtPlugin,"pluginName",ae),z(r.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),w(1,t.Inject(t.Injector)),w(2,t.IConfigService),w(3,t.ICommandService)],r.UniverSheetsNumfmtPlugin);const ce=e=>P.find(i=>e.includes(i)),oe=()=>P.map(e=>({label:e,value:e})),ue=e=>H.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),me=()=>B.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=H,r.DATEFMTLISG=B,r.NUMBERFORMAT=G,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,r.SetCurrencyCommand=W,r.SetNumfmtCommand=I,r.SetPercentCommand=K,r.SubtractDecimalCommand=q,r.currencySymbols=P,r.getCurrencyFormat=A,r.getCurrencyFormatOptions=ue,r.getCurrencyOptions=oe,r.getCurrencySymbolByLocale=F,r.getCurrencySymbolIconByLocale=j,r.getCurrencyType=ce,r.getDateFormatOptions=me,r.getDecimalFromPattern=U,r.getDecimalString=L,r.getNumberFormatOptions=fe,r.getPatternPreview=k,r.getPatternPreviewIgnoreGeneral=Y,r.getPatternType=Q,r.isPatternHasDecimal=J,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.12.1",
3
+ "version": "0.12.2-nightly.202511290732",
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.12.1",
62
- "@univerjs/engine-formula": "0.12.1",
63
- "@univerjs/sheets": "0.12.1"
61
+ "@univerjs/core": "0.12.2-nightly.202511290732",
62
+ "@univerjs/engine-formula": "0.12.2-nightly.202511290732",
63
+ "@univerjs/sheets": "0.12.2-nightly.202511290732"
64
64
  },
65
65
  "devDependencies": {
66
66
  "rxjs": "^7.8.2",
67
67
  "typescript": "^5.9.3",
68
- "vite": "^7.2.2",
69
- "vitest": "^3.2.4",
70
- "@univerjs-infra/shared": "0.12.1"
68
+ "vite": "^7.2.4",
69
+ "vitest": "^4.0.14",
70
+ "@univerjs-infra/shared": "0.12.2"
71
71
  },
72
72
  "scripts": {
73
73
  "test": "vitest run",
package/LICENSE DELETED
@@ -1,176 +0,0 @@
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