@univerjs/sheets-numfmt 0.10.6 → 0.10.7-nightly.202509090319

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 Y=Object.defineProperty;var X=(e,r,s)=>r in e?Y(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var U=(e,r,s)=>X(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),I=require("rxjs"),J=require("@univerjs/engine-formula"),L=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],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 A(e,r=2){let s=r;r>127&&(s=127);let n="";return s>0&&(n=`.${"0".repeat(s)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const j=[{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"}],P=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},x=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${x(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${x(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=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),S={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 N=f.checkCellValueType(v.v);N!==v.t&&g.setValue(m.row,m.col,{t:N})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?h.setValue(g,m,{t:v.t}):h.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){S.ranges=f.rangeMerge(S.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const N=f.checkCellValueType(v.v);N!==v.t&&g.setValue(m.row,m.col,{t:N})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?h.setValue(g,m,{t:v.t}):h.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:S},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,S);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:h.getMatrix()}},...y)}const p=t.sequenceExecute(M,s).result;return p&&a.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),p}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,p)=>{const c=n.getValue(d,i,C,p);if(!c){const y=l.worksheet.getCellRaw(C,p);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 h=P(c.pattern);u=h>u?h:u})});const _=u+1,T=$(`0${_>0?".0":""}`,_),S=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,p)=>{const c=n.getValue(d,i,C,p);if(!c)S.push({row:C,col:p,pattern:T});else{const h=P(c.pattern),y=$(c.pattern,h+1);y!==c.pattern&&S.push({row:C,col:p,pattern:y})}})}),S.length?await r.executeCommand(R.id,{values:S}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const o=[],l=V(n.getCurrentLocale()),d=A(l.locale);return a.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(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 a=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{a.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.range,(p,c)=>{const h=n.getValue(d,i,p,c);if(!h){const g=l.worksheet.getCellRaw(p,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(h.pattern);u=y>u?y:u})});const _=u-1,T=$(`0${_>0?".0":"."}`,_),S=[];return o.forEach(C=>{t.Range.foreach(C.range,(p,c)=>{const h=n.getValue(d,i,p,c);if(!h)S.push({row:p,col:c,pattern:T});else{const y=P(h.pattern);S.push({row:p,col:c,pattern:$(h.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:S})}},D="sheets-numfmt.config",w={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,s="en")=>{const n=t.numfmt.formatColor(e,r),a=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a}:{result:o}},k=(e,r,s)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,s),te=new Set(["m d"]),ne=new Set(["h:mm AM/PM","hh:mm AM/PM"]),re=e=>{var n,a;const r=(a=(n=t.numfmt.parseDate(e))!=null?n:t.numfmt.parseTime(e))!=null?a:t.numfmt.parseNumber(e);if(!r)return null;const{z:s}=r;return s&&(te.has(s)||ne.has(s)&&!/\s(A|AM|P|PM)$/i.test(e))?null:r};var se=Object.getOwnPropertyDescriptor,ae=(e,r,s,n)=>{for(var a=n>1?void 0:n?se(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},b=(e,r)=>(s,n)=>r(s,n,e);const oe={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,d,i){super();U(this,"_locale$",new I.BehaviorSubject("en"));U(this,"locale$",this._locale$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const s=this._locale$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var C,p;if(!n||n.v===void 0||n.v===null)return o(n);const l=a.unitId,d=a.subUnitId;let i;if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,a.row,a.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===a.rawData)&&(n={...a.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(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,...oe},o(n));let _="";const T=s.getValue(a.row,a.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const S=k(i==null?void 0:i.pattern,Number(u.v),this.locale);if(_=S.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(S.color){const c=(p=this._themeService.getColorFromTheme(`${S.color}.500`))!=null?p:S.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{s.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:I.of(null)}),I.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._locale$.next(s)}};exports.SheetsNumfmtCellContentController=ae([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 ce="SHEET_NUMFMT_PLUGIN";var ie=Object.defineProperty,le=Object.getOwnPropertyDescriptor,ue=(e,r,s)=>r in e?ie(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,me=(e,r,s,n)=>{for(var a=n>1?void 0:n?le(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},O=(e,r)=>(s,n)=>r(s,n,e),z=(e,r,s)=>ue(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=w,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;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))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",ce);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=me([t.DependentOn(f.UniverSheetsPlugin),O(1,t.Inject(t.Injector)),O(2,t.IConfigService),O(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const fe=e=>L.find(s=>e.includes(s)),ge=()=>L.map(e=>({label:e,value:e})),de=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),pe=()=>j.map(e=>({label:e.label,value:e.suffix})),Se=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=j;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=L;exports.getCurrencyFormat=A;exports.getCurrencyFormatOptions=de;exports.getCurrencyOptions=ge;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=V;exports.getCurrencyType=fe;exports.getDateFormatOptions=pe;exports.getDecimalFromPattern=P;exports.getDecimalString=x;exports.getNumberFormatOptions=Se;exports.getNumfmtParseValueFilter=re;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=$;
1
+ "use strict";var Y=Object.defineProperty;var X=(e,r,s)=>r in e?Y(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var O=(e,r,s)=>X(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),I=require("rxjs"),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 w(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,r=2){let s=r;r>127&&(s=127);let n="";return s>0&&(n=`.${"0".repeat(s)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const j=[{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"}],P=(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(""),$=(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 s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:i}=o,u=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=f.transformCellsToRange(l,d,u),S={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 N=f.checkCellValueType(v.v);N!==v.t&&g.setValue(m.row,m.col,{t:N})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?h.setValue(g,m,{t:v.t}):h.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){S.ranges=f.rangeMerge(S.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const N=f.checkCellValueType(v.v);N!==v.t&&g.setValue(m.row,m.col,{t:N})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?h.setValue(g,m,{t:v.t}):h.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:S},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,S);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:h.getMatrix()}},...y)}const p=t.sequenceExecute(M,s).result;return p&&a.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),p}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,p)=>{const c=n.getValue(d,i,C,p);if(!c){const y=l.worksheet.getCellRaw(C,p);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 h=P(c.pattern);u=h>u?h:u})});const _=u+1,T=$(`0${_>0?".0":""}`,_),S=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,p)=>{const c=n.getValue(d,i,C,p);if(!c)S.push({row:C,col:p,pattern:T});else{const h=P(c.pattern),y=$(c.pattern,h+1);y!==c.pattern&&S.push({row:C,col:p,pattern:y})}})}),S.length?await r.executeCommand(R.id,{values:S}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const o=[],l=w(n.getCurrentLocale()),d=A(l.locale);return a.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(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 a=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{a.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.range,(p,c)=>{const h=n.getValue(d,i,p,c);if(!h){const g=l.worksheet.getCellRaw(p,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(h.pattern);u=y>u?y:u})});const _=u-1,T=$(`0${_>0?".0":"."}`,_),S=[];return o.forEach(C=>{t.Range.foreach(C.range,(p,c)=>{const h=n.getValue(d,i,p,c);if(!h)S.push({row:p,col:c,pattern:T});else{const y=P(h.pattern);S.push({row:p,col:c,pattern:$(h.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:S})}},V="sheets-numfmt.config",D={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,s="en")=>{const n=t.numfmt.formatColor(e,r),a=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a}:{result:o}},k=(e,r,s)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,s),te=new Set(["m d"]),ne=new Set(["h:mm AM/PM","hh:mm AM/PM"]),re=e=>{var n,a;const r=(a=(n=t.numfmt.parseDate(e))!=null?n:t.numfmt.parseTime(e))!=null?a:t.numfmt.parseNumber(e);if(!r)return null;const{z:s}=r;return s&&(te.has(s)||ne.has(s)&&!/\s(A|AM|P|PM)$/i.test(e))?null:r};var se=Object.getOwnPropertyDescriptor,ae=(e,r,s,n)=>{for(var a=n>1?void 0:n?se(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},b=(e,r)=>(s,n)=>r(s,n,e);const oe={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,d,i){super();O(this,"_locale$",new I.BehaviorSubject("en"));O(this,"locale$",this._locale$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const s=this._locale$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var C,p;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return o(n);const l=a.unitId,d=a.subUnitId;let i;if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,a.row,a.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===a.rawData)&&(n={...a.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(C=this._configService.getConfig(V))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...oe},o(n));let _="";const T=s.getValue(a.row,a.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const S=k(i==null?void 0:i.pattern,Number(u.v),this.locale);if(_=S.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(S.color){const c=(p=this._themeService.getColorFromTheme(`${S.color}.500`))!=null?p:S.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{s.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:I.of(null)}),I.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._locale$.next(s)}};exports.SheetsNumfmtCellContentController=ae([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 ce="SHEET_NUMFMT_PLUGIN";var ie=Object.defineProperty,le=Object.getOwnPropertyDescriptor,ue=(e,r,s)=>r in e?ie(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,me=(e,r,s,n)=>{for(var a=n>1?void 0:n?le(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},U=(e,r)=>(s,n)=>r(s,n,e),z=(e,r,s)=>ue(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=D,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},D,this._config);this._configService.setConfig(V,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))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",ce);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=me([t.DependentOn(f.UniverSheetsPlugin),U(1,t.Inject(t.Injector)),U(2,t.IConfigService),U(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const fe=e=>x.find(s=>e.includes(s)),ge=()=>x.map(e=>({label:e,value:e})),de=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),pe=()=>j.map(e=>({label:e.label,value:e.suffix})),Se=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=j;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=V;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=x;exports.getCurrencyFormat=A;exports.getCurrencyFormatOptions=de;exports.getCurrencyOptions=ge;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=w;exports.getCurrencyType=fe;exports.getDateFormatOptions=pe;exports.getDecimalFromPattern=P;exports.getDecimalString=L;exports.getNumberFormatOptions=Se;exports.getNumfmtParseValueFilter=re;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=$;
package/lib/es/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  var oe = Object.defineProperty;
2
2
  var ae = (e, n, t) => n in e ? oe(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
3
  var L = (e, n, t) => ae(e, typeof n != "symbol" ? n + "" : n, t);
4
- import { LocaleType as m, numfmt as $, CommandType as U, ICommandService as I, IUniverInstanceService as A, IUndoRedoService as ie, isTextFormat as X, CellValueType as R, ObjectMatrix as b, sequenceExecute as ce, Range as E, LocaleService as J, DEFAULT_NUMBER_FORMAT as le, Inject as T, ThemeService as ue, IConfigService as Q, Disposable as me, isDefaultFormat as fe, InterceptorEffectEnum as Z, UniverInstanceType as ee, DependentOn as de, Injector as ge, Plugin as he, merge as pe, registerDependencies as _e, touchDependencies as Se } from "@univerjs/core";
5
- import { getSheetCommandTarget as W, transformCellsToRange as ve, checkCellValueType as B, rangeMerge as z, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as Ce, RemoveNumfmtMutation as Me, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as ye, SheetsSelectionsService as j, INumfmtService as K, SheetInterceptorService as be, INTERCEPTOR_POINT as Re, InterceptCellContentPriority as Ne, UniverSheetsPlugin as $e } from "@univerjs/sheets";
6
- import { BehaviorSubject as Ee, merge as Ie, switchMap as Te, of as Pe, skip as Ue } from "rxjs";
7
- import { stripErrorMargin as we } from "@univerjs/engine-formula";
4
+ import { LocaleType as m, numfmt as E, CommandType as U, ICommandService as I, IUniverInstanceService as V, IUndoRedoService as ie, isTextFormat as X, CellValueType as b, ObjectMatrix as R, sequenceExecute as ce, Range as $, LocaleService as J, DEFAULT_NUMBER_FORMAT as le, Inject as T, ThemeService as ue, IConfigService as Q, Disposable as me, isDefaultFormat as fe, InterceptorEffectEnum as Z, UniverInstanceType as ee, DependentOn as de, Injector as ge, Plugin as he, merge as pe, registerDependencies as _e, touchDependencies as Se } from "@univerjs/core";
5
+ import { getSheetCommandTarget as W, transformCellsToRange as ve, checkCellValueType as H, rangeMerge as z, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as Ce, RemoveNumfmtMutation as Me, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as ye, SheetsSelectionsService as j, INumfmtService as K, SheetInterceptorService as be, INTERCEPTOR_POINT as Re, InterceptCellContentPriority as Ne, UniverSheetsPlugin as Ee } from "@univerjs/sheets";
6
+ import { BehaviorSubject as $e, merge as Ie, switchMap as Te, of as Pe, skip as Ue } from "rxjs";
7
+ import { stripErrorMargin as Oe } from "@univerjs/engine-formula";
8
8
  const ne = [
9
9
  "$",
10
10
  "£",
@@ -34,7 +34,7 @@ const ne = [
34
34
  "₾",
35
35
  "₿",
36
36
  "﷼"
37
- ], x = /* @__PURE__ */ new Map([
37
+ ], w = /* @__PURE__ */ new Map([
38
38
  [m.EN_US, "$"],
39
39
  [m.RU_RU, "₽"],
40
40
  [m.VI_VN, "₫"],
@@ -46,26 +46,26 @@ const ne = [
46
46
  [m.ES_ES, "€"],
47
47
  [m.CA_ES, "€"]
48
48
  ]);
49
- function xe(e) {
49
+ function we(e) {
50
50
  switch (e) {
51
51
  case m.CA_ES:
52
52
  case m.ES_ES:
53
53
  case m.FR_FR:
54
54
  return {
55
55
  icon: "EuroIcon",
56
- symbol: x.get(e) || "€",
56
+ symbol: w.get(e) || "€",
57
57
  locale: e
58
58
  };
59
59
  case m.RU_RU:
60
60
  return {
61
61
  icon: "RoubleIcon",
62
- symbol: x.get(e) || "₽",
62
+ symbol: w.get(e) || "₽",
63
63
  locale: e
64
64
  };
65
65
  case m.ZH_CN:
66
66
  return {
67
67
  icon: "RmbIcon",
68
- symbol: x.get(e) || "¥",
68
+ symbol: w.get(e) || "¥",
69
69
  locale: e
70
70
  };
71
71
  case m.EN_US:
@@ -78,9 +78,9 @@ function xe(e) {
78
78
  }
79
79
  }
80
80
  function k(e) {
81
- return x.get(e) || "$";
81
+ return w.get(e) || "$";
82
82
  }
83
- function Oe(e, n = 2) {
83
+ function xe(e, n = 2) {
84
84
  let t = n;
85
85
  n > 127 && (t = 127);
86
86
  let r = "";
@@ -159,7 +159,7 @@ const De = [
159
159
  suffix: "#,##0.00_);[Red]-#,##0.00",
160
160
  color: "red"
161
161
  }
162
- ], Ve = [
162
+ ], Ae = [
163
163
  {
164
164
  label: (e) => `${e}1,235`,
165
165
  suffix: (e) => `"${e}"#,##0.00_);"${e}"#,##0.00`
@@ -187,23 +187,23 @@ const De = [
187
187
  suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
188
188
  color: "red"
189
189
  }
190
- ], O = (e, n = 0) => {
190
+ ], x = (e, n = 0) => {
191
191
  var r;
192
- return e && (r = $.getFormatInfo(e).maxDecimals) != null ? r : n;
192
+ return e && (r = E.getFormatInfo(e).maxDecimals) != null ? r : n;
193
193
  }, Y = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), D = (e, n) => e.split(";").map((r) => /\.0?/.test(r) ? r.replace(
194
194
  /\.0*/g,
195
195
  `${n > 0 ? "." : ""}${Y(Number(n || 0))}`
196
196
  ) : /0([^0]?)|0$/.test(r) ? r.replace(
197
197
  /0([^0]+)|0$/,
198
198
  `0${n > 0 ? "." : ""}${Y(Number(n || 0))}$1`
199
- ) : r).join(";"), ot = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), w = {
199
+ ) : r).join(";"), ot = (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
203
  handler: (e, n) => {
204
204
  if (!n)
205
205
  return !1;
206
- const t = e.get(I), r = e.get(A), s = e.get(ie), a = W(r, n);
206
+ const t = e.get(I), r = e.get(V), s = e.get(ie), a = W(r, n);
207
207
  if (!a) return !1;
208
208
  const { unitId: c, subUnitId: o, worksheet: g } = a, u = n.values.filter((l) => !!l.pattern), C = n.values.filter((l) => !l.pattern), M = ve(c, o, u), p = {
209
209
  unitId: c,
@@ -217,15 +217,15 @@ const De = [
217
217
  }, y = [], _ = [];
218
218
  if (u.length) {
219
219
  const l = u.reduce((d, i) => {
220
- X(i.pattern) && d.setValue(i.row, i.col, { t: R.STRING });
220
+ X(i.pattern) && d.setValue(i.row, i.col, { t: b.STRING });
221
221
  const v = g.getCellRaw(i.row, i.col);
222
222
  if (v) {
223
- const P = B(v.v);
223
+ const P = H(v.v);
224
224
  P !== v.t && d.setValue(i.row, i.col, { t: P });
225
225
  }
226
226
  return d;
227
- }, new b()).getMatrix(), h = new b();
228
- new b(l).forValue((d, i) => {
227
+ }, new R()).getMatrix(), h = new R();
228
+ new R(l).forValue((d, i) => {
229
229
  const v = g.getCellRaw(d, i);
230
230
  v ? h.setValue(d, i, { t: v.t }) : h.setValue(d, i, { t: void 0 });
231
231
  }), Object.keys(M.values).forEach((d) => {
@@ -243,12 +243,12 @@ const De = [
243
243
  const l = C.reduce((d, i) => {
244
244
  const v = g.getCellRaw(i.row, i.col);
245
245
  if (v) {
246
- const P = B(v.v);
246
+ const P = H(v.v);
247
247
  P !== v.t && d.setValue(i.row, i.col, { t: P });
248
248
  }
249
249
  return d;
250
- }, new b()).getMatrix(), h = new b();
251
- new b(l).forValue((d, i) => {
250
+ }, new R()).getMatrix(), h = new R();
251
+ new R(l).forValue((d, i) => {
252
252
  const v = g.getCellRaw(d, i);
253
253
  v ? h.setValue(d, i, { t: v.t }) : h.setValue(d, i, { t: void 0 });
254
254
  }), y.push({
@@ -279,11 +279,11 @@ const De = [
279
279
  redoMutations: y
280
280
  }), f;
281
281
  }
282
- }, Ae = {
282
+ }, Ve = {
283
283
  id: "sheet.command.numfmt.add.decimal.command",
284
284
  type: U.COMMAND,
285
285
  handler: async (e) => {
286
- const n = e.get(I), t = e.get(j), r = e.get(K), s = e.get(A), a = t.getCurrentSelections();
286
+ const n = e.get(I), t = e.get(j), r = e.get(K), s = e.get(V), a = t.getCurrentSelections();
287
287
  if (!a || !a.length)
288
288
  return !1;
289
289
  const c = W(s);
@@ -291,11 +291,11 @@ const De = [
291
291
  const { unitId: o, subUnitId: g } = c;
292
292
  let u = 0;
293
293
  a.forEach((y) => {
294
- E.foreach(y.range, (_, f) => {
294
+ $.foreach(y.range, (_, f) => {
295
295
  const l = r.getValue(o, g, _, f);
296
296
  if (!l) {
297
297
  const S = c.worksheet.getCellRaw(_, f);
298
- if (!u && S && S.t === R.NUMBER && S.v) {
298
+ if (!u && S && S.t === b.NUMBER && S.v) {
299
299
  const d = /\.(\d*)$/.exec(String(S.v));
300
300
  if (d) {
301
301
  const i = d[1].length;
@@ -306,13 +306,13 @@ const De = [
306
306
  }
307
307
  return;
308
308
  }
309
- const h = O(l.pattern);
309
+ const h = x(l.pattern);
310
310
  u = h > u ? h : u;
311
311
  });
312
312
  });
313
313
  const C = u + 1, M = D(`0${C > 0 ? ".0" : ""}`, C), p = [];
314
314
  return a.forEach((y) => {
315
- E.foreach(y.range, (_, f) => {
315
+ $.foreach(y.range, (_, f) => {
316
316
  const l = r.getValue(o, g, _, f);
317
317
  if (!l)
318
318
  p.push({
@@ -321,7 +321,7 @@ const De = [
321
321
  pattern: M
322
322
  });
323
323
  else {
324
- const h = O(l.pattern), S = D(l.pattern, h + 1);
324
+ const h = x(l.pattern), S = D(l.pattern, h + 1);
325
325
  S !== l.pattern && p.push({
326
326
  row: _,
327
327
  col: f,
@@ -329,7 +329,7 @@ const De = [
329
329
  });
330
330
  }
331
331
  });
332
- }), p.length ? await n.executeCommand(w.id, { values: p }) : !1;
332
+ }), p.length ? await n.executeCommand(O.id, { values: p }) : !1;
333
333
  }
334
334
  }, je = {
335
335
  id: "sheet.command.numfmt.set.currency",
@@ -338,12 +338,12 @@ const De = [
338
338
  const n = e.get(I), t = e.get(j), r = e.get(J), s = t.getCurrentSelections();
339
339
  if (!s || !s.length)
340
340
  return !1;
341
- const a = [], c = xe(r.getCurrentLocale()), o = Oe(c.locale);
341
+ const a = [], c = we(r.getCurrentLocale()), o = xe(c.locale);
342
342
  return s.forEach((u) => {
343
- E.foreach(u.range, (C, M) => {
343
+ $.foreach(u.range, (C, M) => {
344
344
  a.push({ row: C, col: M, pattern: o, type: "currency" });
345
345
  });
346
- }), await n.executeCommand(w.id, { values: a });
346
+ }), await n.executeCommand(O.id, { values: a });
347
347
  }
348
348
  }, Le = {
349
349
  id: "sheet.command.numfmt.set.percent",
@@ -354,16 +354,16 @@ const De = [
354
354
  return !1;
355
355
  const s = [], a = "0%";
356
356
  return r.forEach((o) => {
357
- E.foreach(o.range, (g, u) => {
357
+ $.foreach(o.range, (g, u) => {
358
358
  s.push({ row: g, col: u, pattern: a, type: "percent" });
359
359
  });
360
- }), await n.executeCommand(w.id, { values: s });
360
+ }), await n.executeCommand(O.id, { values: s });
361
361
  }
362
- }, He = {
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(I), t = e.get(j), r = e.get(K), s = e.get(A), a = t.getCurrentSelections();
366
+ const n = e.get(I), t = e.get(j), r = e.get(K), s = e.get(V), a = t.getCurrentSelections();
367
367
  if (!a || !a.length)
368
368
  return !1;
369
369
  const c = W(s);
@@ -371,11 +371,11 @@ const De = [
371
371
  const { unitId: o, subUnitId: g } = c;
372
372
  let u = 0;
373
373
  a.forEach((_) => {
374
- E.foreach(_.range, (f, l) => {
374
+ $.foreach(_.range, (f, l) => {
375
375
  const h = r.getValue(o, g, f, l);
376
376
  if (!h) {
377
377
  const d = c.worksheet.getCellRaw(f, l);
378
- if (!u && d && d.t === R.NUMBER && d.v) {
378
+ if (!u && d && d.t === b.NUMBER && d.v) {
379
379
  const i = /\.(\d*)$/.exec(String(d.v));
380
380
  if (i) {
381
381
  const v = i[1].length;
@@ -386,13 +386,13 @@ const De = [
386
386
  }
387
387
  return;
388
388
  }
389
- const S = O(h.pattern);
389
+ const S = x(h.pattern);
390
390
  u = S > u ? S : u;
391
391
  });
392
392
  });
393
393
  const C = u - 1, M = D(`0${C > 0 ? ".0" : "."}`, C), p = [];
394
394
  return a.forEach((_) => {
395
- E.foreach(_.range, (f, l) => {
395
+ $.foreach(_.range, (f, l) => {
396
396
  const h = r.getValue(o, g, f, l);
397
397
  if (!h)
398
398
  p.push({
@@ -401,7 +401,7 @@ const De = [
401
401
  pattern: M
402
402
  });
403
403
  else {
404
- const S = O(h.pattern);
404
+ const S = x(h.pattern);
405
405
  p.push({
406
406
  row: f,
407
407
  col: l,
@@ -409,10 +409,10 @@ const De = [
409
409
  });
410
410
  }
411
411
  });
412
- }), await n.executeCommand(w.id, { values: p });
412
+ }), await n.executeCommand(O.id, { values: p });
413
413
  }
414
- }, re = "sheets-numfmt.config", q = {}, at = (e) => $.getFormatInfo(e).type || "unknown", Be = (e, n, t = "en") => {
415
- const r = $.formatColor(e, n), s = r ? String(r) : void 0, a = $.format(e, n, { locale: t, throws: !1 });
414
+ }, re = "sheets-numfmt.config", q = {}, at = (e) => E.getFormatInfo(e).type || "unknown", He = (e, n, t = "en") => {
415
+ const r = E.formatColor(e, n), s = r ? String(r) : void 0, a = E.format(e, n, { locale: t, throws: !1 });
416
416
  return n < 0 ? {
417
417
  result: a,
418
418
  color: s
@@ -420,11 +420,11 @@ const De = [
420
420
  result: a
421
421
  };
422
422
  }, Ge = (e, n, t) => e === le ? {
423
- result: String(we(n))
423
+ result: String(Oe(n))
424
424
  // In Excel, the default General format also needs to handle numeric precision.
425
- } : Be(e, n, t), We = /* @__PURE__ */ new Set(["m d"]), Ke = /* @__PURE__ */ new Set(["h:mm AM/PM", "hh:mm AM/PM"]), it = (e) => {
425
+ } : He(e, n, t), We = /* @__PURE__ */ new Set(["m d"]), Ke = /* @__PURE__ */ new Set(["h:mm AM/PM", "hh:mm AM/PM"]), it = (e) => {
426
426
  var r, s;
427
- const n = (s = (r = $.parseDate(e)) != null ? r : $.parseTime(e)) != null ? s : $.parseNumber(e);
427
+ const n = (s = (r = E.parseDate(e)) != null ? r : E.parseTime(e)) != null ? s : E.parseNumber(e);
428
428
  if (!n) return null;
429
429
  const { z: t } = n;
430
430
  return t && (We.has(t) || Ke.has(t) && !/\s(A|AM|P|PM)$/i.test(e)) ? null : n;
@@ -443,7 +443,7 @@ const ke = {
443
443
  let F = class extends me {
444
444
  constructor(n, t, r, s, a, c, o) {
445
445
  super();
446
- L(this, "_locale$", new Ee("en"));
446
+ L(this, "_locale$", new $e("en"));
447
447
  L(this, "locale$", this._locale$.asObservable());
448
448
  this._instanceService = n, this._sheetInterceptorService = t, this._themeService = r, this._commandService = s, this._numfmtService = a, this._localeService = c, this._configService = o, this._initInterceptorCellContent();
449
449
  }
@@ -475,7 +475,7 @@ let F = class extends me {
475
475
  }
476
476
  // eslint-disable-next-line max-lines-per-function
477
477
  _initInterceptorCellContent() {
478
- const n = new b();
478
+ const n = new R();
479
479
  this.disposeWithMe(Ie(this._locale$, this._localeService.currentLocale$).subscribe(() => {
480
480
  n.reset();
481
481
  })), this.disposeWithMe(this._sheetInterceptorService.intercept(Re.CELL_CONTENT, {
@@ -483,7 +483,7 @@ let F = class extends me {
483
483
  // eslint-disable-next-line max-lines-per-function, complexity
484
484
  handler: (t, r, s) => {
485
485
  var y, _;
486
- if (!t || t.v === void 0 || t.v === null)
486
+ if (!t || t.v === void 0 || t.v === null || t.t === b.BOOLEAN || t.t === b.FORCE_STRING)
487
487
  return s(t);
488
488
  const a = r.unitId, c = r.subUnitId;
489
489
  let o;
@@ -491,11 +491,11 @@ let F = class extends me {
491
491
  const f = r.workbook.getStyles().get(t.s);
492
492
  f != null && f.n && (o = f.n);
493
493
  }
494
- if (o || (o = this._numfmtService.getValue(a, c, r.row, r.col)), fe(o == null ? void 0 : o.pattern) || t.t !== R.NUMBER && B(t.v) !== R.NUMBER)
494
+ if (o || (o = this._numfmtService.getValue(a, c, r.row, r.col)), fe(o == null ? void 0 : o.pattern) || t.t !== b.NUMBER && H(t.v, t.t) !== b.NUMBER)
495
495
  return s(t);
496
496
  const g = t;
497
497
  if ((!t || t === r.rawData) && (t = { ...r.rawData }), X(o == null ? void 0 : o.pattern))
498
- return (y = this._configService.getConfig(re)) != null && y.disableTextFormatMark ? (t.t = R.STRING, s(t)) : (t.t = R.STRING, t.markers = { ...t == null ? void 0 : t.markers, ...ke }, s(t));
498
+ return (y = this._configService.getConfig(re)) != null && y.disableTextFormatMark ? (t.t = b.STRING, s(t)) : (t.t = b.STRING, t.markers = { ...t == null ? void 0 : t.markers, ...ke }, s(t));
499
499
  let u = "";
500
500
  const C = n.getValue(r.row, r.col);
501
501
  if (C && C.parameters === `${g.v}_${o == null ? void 0 : o.pattern}`)
@@ -503,7 +503,7 @@ let F = class extends me {
503
503
  const M = Ge(o == null ? void 0 : o.pattern, Number(g.v), this.locale);
504
504
  if (u = M.result, !u)
505
505
  return s(t);
506
- const p = { v: u, t: R.NUMBER };
506
+ const p = { v: u, t: b.NUMBER };
507
507
  if (M.color) {
508
508
  const f = (_ = this._themeService.getColorFromTheme(`${M.color}.500`)) != null ? _ : M.color;
509
509
  f && (p.interceptorStyle = { cl: { rgb: f } });
@@ -519,14 +519,14 @@ let F = class extends me {
519
519
  const r = t.params;
520
520
  Object.keys(r.values).forEach((s) => {
521
521
  r.values[s].ranges.forEach((c) => {
522
- E.foreach(c, (o, g) => {
522
+ $.foreach(c, (o, g) => {
523
523
  n.realDeleteValue(o, g);
524
524
  });
525
525
  });
526
526
  });
527
527
  } else if (t.id === G.id) {
528
528
  const r = t.params;
529
- new b(r.cellValue).forValue((s, a) => {
529
+ new R(r.cellValue).forValue((s, a) => {
530
530
  n.realDeleteValue(s, a);
531
531
  });
532
532
  }
@@ -545,7 +545,7 @@ let F = class extends me {
545
545
  }
546
546
  };
547
547
  F = ze([
548
- N(0, A),
548
+ N(0, V),
549
549
  N(1, T(be)),
550
550
  N(2, T(ue)),
551
551
  N(3, T(I)),
@@ -558,8 +558,8 @@ var qe = Object.defineProperty, Xe = Object.getOwnPropertyDescriptor, Je = (e, n
558
558
  for (var s = r > 1 ? void 0 : r ? Xe(n, t) : n, a = e.length - 1, c; a >= 0; a--)
559
559
  (c = e[a]) && (s = c(s) || s);
560
560
  return s;
561
- }, H = (e, n) => (t, r) => n(t, r, e), se = (e, n, t) => Je(e, typeof n != "symbol" ? n + "" : n, t);
562
- let V = class extends he {
561
+ }, B = (e, n) => (t, r) => n(t, r, e), se = (e, n, t) => Je(e, typeof n != "symbol" ? n + "" : n, t);
562
+ let A = class extends he {
563
563
  constructor(e = q, n, t, r) {
564
564
  super(), this._config = e, this._injector = n, this._configService = t, this._commandService = r;
565
565
  const { ...s } = pe(
@@ -578,57 +578,57 @@ let V = class extends he {
578
578
  }
579
579
  onRendered() {
580
580
  [
581
- Ae,
582
- He,
581
+ Ve,
582
+ Be,
583
583
  je,
584
584
  Le,
585
- w
585
+ O
586
586
  ].forEach((e) => {
587
587
  this.disposeWithMe(this._commandService.registerCommand(e));
588
588
  });
589
589
  }
590
590
  };
591
- se(V, "pluginName", Ye);
592
- se(V, "type", ee.UNIVER_SHEET);
593
- V = Qe([
594
- de($e),
595
- H(1, T(ge)),
596
- H(2, Q),
597
- H(3, I)
598
- ], V);
599
- const ct = (e) => ne.find((t) => e.includes(t)), lt = () => ne.map((e) => ({ label: e, value: e })), ut = (e) => Ve.map((n) => ({
591
+ se(A, "pluginName", Ye);
592
+ se(A, "type", ee.UNIVER_SHEET);
593
+ A = Qe([
594
+ de(Ee),
595
+ B(1, T(ge)),
596
+ B(2, Q),
597
+ B(3, I)
598
+ ], A);
599
+ const ct = (e) => ne.find((t) => e.includes(t)), lt = () => ne.map((e) => ({ label: e, value: e })), ut = (e) => Ae.map((n) => ({
600
600
  label: n.label(e),
601
601
  value: n.suffix(e),
602
602
  color: n.color
603
603
  })), mt = () => De.map((e) => ({ label: e.label, value: e.suffix })), ft = () => Fe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
604
604
  export {
605
- Ae as AddDecimalCommand,
606
- Ve as CURRENCYFORMAT,
605
+ Ve as AddDecimalCommand,
606
+ Ae as CURRENCYFORMAT,
607
607
  De as DATEFMTLISG,
608
608
  Fe as NUMBERFORMAT,
609
609
  re as SHEETS_NUMFMT_PLUGIN_CONFIG_KEY,
610
610
  je as SetCurrencyCommand,
611
- w as SetNumfmtCommand,
611
+ O as SetNumfmtCommand,
612
612
  Le as SetPercentCommand,
613
613
  F as SheetsNumfmtCellContentController,
614
- He as SubtractDecimalCommand,
615
- V as UniverSheetsNumfmtPlugin,
614
+ Be as SubtractDecimalCommand,
615
+ A as UniverSheetsNumfmtPlugin,
616
616
  ne as currencySymbols,
617
- Oe as getCurrencyFormat,
617
+ xe as getCurrencyFormat,
618
618
  ut as getCurrencyFormatOptions,
619
619
  lt as getCurrencyOptions,
620
620
  k as getCurrencySymbolByLocale,
621
- xe as getCurrencySymbolIconByLocale,
621
+ we as getCurrencySymbolIconByLocale,
622
622
  ct as getCurrencyType,
623
623
  mt as getDateFormatOptions,
624
- O as getDecimalFromPattern,
624
+ x as getDecimalFromPattern,
625
625
  Y as getDecimalString,
626
626
  ft as getNumberFormatOptions,
627
627
  it as getNumfmtParseValueFilter,
628
- Be as getPatternPreview,
628
+ He as getPatternPreview,
629
629
  Ge as getPatternPreviewIgnoreGeneral,
630
630
  at as getPatternType,
631
631
  ot as isPatternHasDecimal,
632
- x as localeCurrencySymbolMap,
632
+ w as localeCurrencySymbolMap,
633
633
  D as setPatternDecimal
634
634
  };
package/lib/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  var oe = Object.defineProperty;
2
2
  var ae = (e, n, t) => n in e ? oe(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
3
  var L = (e, n, t) => ae(e, typeof n != "symbol" ? n + "" : n, t);
4
- import { LocaleType as m, numfmt as $, CommandType as U, ICommandService as I, IUniverInstanceService as A, IUndoRedoService as ie, isTextFormat as X, CellValueType as R, ObjectMatrix as b, sequenceExecute as ce, Range as E, LocaleService as J, DEFAULT_NUMBER_FORMAT as le, Inject as T, ThemeService as ue, IConfigService as Q, Disposable as me, isDefaultFormat as fe, InterceptorEffectEnum as Z, UniverInstanceType as ee, DependentOn as de, Injector as ge, Plugin as he, merge as pe, registerDependencies as _e, touchDependencies as Se } from "@univerjs/core";
5
- import { getSheetCommandTarget as W, transformCellsToRange as ve, checkCellValueType as B, rangeMerge as z, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as Ce, RemoveNumfmtMutation as Me, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as ye, SheetsSelectionsService as j, INumfmtService as K, SheetInterceptorService as be, INTERCEPTOR_POINT as Re, InterceptCellContentPriority as Ne, UniverSheetsPlugin as $e } from "@univerjs/sheets";
6
- import { BehaviorSubject as Ee, merge as Ie, switchMap as Te, of as Pe, skip as Ue } from "rxjs";
7
- import { stripErrorMargin as we } from "@univerjs/engine-formula";
4
+ import { LocaleType as m, numfmt as E, CommandType as U, ICommandService as I, IUniverInstanceService as V, IUndoRedoService as ie, isTextFormat as X, CellValueType as b, ObjectMatrix as R, sequenceExecute as ce, Range as $, LocaleService as J, DEFAULT_NUMBER_FORMAT as le, Inject as T, ThemeService as ue, IConfigService as Q, Disposable as me, isDefaultFormat as fe, InterceptorEffectEnum as Z, UniverInstanceType as ee, DependentOn as de, Injector as ge, Plugin as he, merge as pe, registerDependencies as _e, touchDependencies as Se } from "@univerjs/core";
5
+ import { getSheetCommandTarget as W, transformCellsToRange as ve, checkCellValueType as H, rangeMerge as z, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as Ce, RemoveNumfmtMutation as Me, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as ye, SheetsSelectionsService as j, INumfmtService as K, SheetInterceptorService as be, INTERCEPTOR_POINT as Re, InterceptCellContentPriority as Ne, UniverSheetsPlugin as Ee } from "@univerjs/sheets";
6
+ import { BehaviorSubject as $e, merge as Ie, switchMap as Te, of as Pe, skip as Ue } from "rxjs";
7
+ import { stripErrorMargin as Oe } from "@univerjs/engine-formula";
8
8
  const ne = [
9
9
  "$",
10
10
  "£",
@@ -34,7 +34,7 @@ const ne = [
34
34
  "₾",
35
35
  "₿",
36
36
  "﷼"
37
- ], x = /* @__PURE__ */ new Map([
37
+ ], w = /* @__PURE__ */ new Map([
38
38
  [m.EN_US, "$"],
39
39
  [m.RU_RU, "₽"],
40
40
  [m.VI_VN, "₫"],
@@ -46,26 +46,26 @@ const ne = [
46
46
  [m.ES_ES, "€"],
47
47
  [m.CA_ES, "€"]
48
48
  ]);
49
- function xe(e) {
49
+ function we(e) {
50
50
  switch (e) {
51
51
  case m.CA_ES:
52
52
  case m.ES_ES:
53
53
  case m.FR_FR:
54
54
  return {
55
55
  icon: "EuroIcon",
56
- symbol: x.get(e) || "€",
56
+ symbol: w.get(e) || "€",
57
57
  locale: e
58
58
  };
59
59
  case m.RU_RU:
60
60
  return {
61
61
  icon: "RoubleIcon",
62
- symbol: x.get(e) || "₽",
62
+ symbol: w.get(e) || "₽",
63
63
  locale: e
64
64
  };
65
65
  case m.ZH_CN:
66
66
  return {
67
67
  icon: "RmbIcon",
68
- symbol: x.get(e) || "¥",
68
+ symbol: w.get(e) || "¥",
69
69
  locale: e
70
70
  };
71
71
  case m.EN_US:
@@ -78,9 +78,9 @@ function xe(e) {
78
78
  }
79
79
  }
80
80
  function k(e) {
81
- return x.get(e) || "$";
81
+ return w.get(e) || "$";
82
82
  }
83
- function Oe(e, n = 2) {
83
+ function xe(e, n = 2) {
84
84
  let t = n;
85
85
  n > 127 && (t = 127);
86
86
  let r = "";
@@ -159,7 +159,7 @@ const De = [
159
159
  suffix: "#,##0.00_);[Red]-#,##0.00",
160
160
  color: "red"
161
161
  }
162
- ], Ve = [
162
+ ], Ae = [
163
163
  {
164
164
  label: (e) => `${e}1,235`,
165
165
  suffix: (e) => `"${e}"#,##0.00_);"${e}"#,##0.00`
@@ -187,23 +187,23 @@ const De = [
187
187
  suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
188
188
  color: "red"
189
189
  }
190
- ], O = (e, n = 0) => {
190
+ ], x = (e, n = 0) => {
191
191
  var r;
192
- return e && (r = $.getFormatInfo(e).maxDecimals) != null ? r : n;
192
+ return e && (r = E.getFormatInfo(e).maxDecimals) != null ? r : n;
193
193
  }, Y = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), D = (e, n) => e.split(";").map((r) => /\.0?/.test(r) ? r.replace(
194
194
  /\.0*/g,
195
195
  `${n > 0 ? "." : ""}${Y(Number(n || 0))}`
196
196
  ) : /0([^0]?)|0$/.test(r) ? r.replace(
197
197
  /0([^0]+)|0$/,
198
198
  `0${n > 0 ? "." : ""}${Y(Number(n || 0))}$1`
199
- ) : r).join(";"), ot = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), w = {
199
+ ) : r).join(";"), ot = (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
203
  handler: (e, n) => {
204
204
  if (!n)
205
205
  return !1;
206
- const t = e.get(I), r = e.get(A), s = e.get(ie), a = W(r, n);
206
+ const t = e.get(I), r = e.get(V), s = e.get(ie), a = W(r, n);
207
207
  if (!a) return !1;
208
208
  const { unitId: c, subUnitId: o, worksheet: g } = a, u = n.values.filter((l) => !!l.pattern), C = n.values.filter((l) => !l.pattern), M = ve(c, o, u), p = {
209
209
  unitId: c,
@@ -217,15 +217,15 @@ const De = [
217
217
  }, y = [], _ = [];
218
218
  if (u.length) {
219
219
  const l = u.reduce((d, i) => {
220
- X(i.pattern) && d.setValue(i.row, i.col, { t: R.STRING });
220
+ X(i.pattern) && d.setValue(i.row, i.col, { t: b.STRING });
221
221
  const v = g.getCellRaw(i.row, i.col);
222
222
  if (v) {
223
- const P = B(v.v);
223
+ const P = H(v.v);
224
224
  P !== v.t && d.setValue(i.row, i.col, { t: P });
225
225
  }
226
226
  return d;
227
- }, new b()).getMatrix(), h = new b();
228
- new b(l).forValue((d, i) => {
227
+ }, new R()).getMatrix(), h = new R();
228
+ new R(l).forValue((d, i) => {
229
229
  const v = g.getCellRaw(d, i);
230
230
  v ? h.setValue(d, i, { t: v.t }) : h.setValue(d, i, { t: void 0 });
231
231
  }), Object.keys(M.values).forEach((d) => {
@@ -243,12 +243,12 @@ const De = [
243
243
  const l = C.reduce((d, i) => {
244
244
  const v = g.getCellRaw(i.row, i.col);
245
245
  if (v) {
246
- const P = B(v.v);
246
+ const P = H(v.v);
247
247
  P !== v.t && d.setValue(i.row, i.col, { t: P });
248
248
  }
249
249
  return d;
250
- }, new b()).getMatrix(), h = new b();
251
- new b(l).forValue((d, i) => {
250
+ }, new R()).getMatrix(), h = new R();
251
+ new R(l).forValue((d, i) => {
252
252
  const v = g.getCellRaw(d, i);
253
253
  v ? h.setValue(d, i, { t: v.t }) : h.setValue(d, i, { t: void 0 });
254
254
  }), y.push({
@@ -279,11 +279,11 @@ const De = [
279
279
  redoMutations: y
280
280
  }), f;
281
281
  }
282
- }, Ae = {
282
+ }, Ve = {
283
283
  id: "sheet.command.numfmt.add.decimal.command",
284
284
  type: U.COMMAND,
285
285
  handler: async (e) => {
286
- const n = e.get(I), t = e.get(j), r = e.get(K), s = e.get(A), a = t.getCurrentSelections();
286
+ const n = e.get(I), t = e.get(j), r = e.get(K), s = e.get(V), a = t.getCurrentSelections();
287
287
  if (!a || !a.length)
288
288
  return !1;
289
289
  const c = W(s);
@@ -291,11 +291,11 @@ const De = [
291
291
  const { unitId: o, subUnitId: g } = c;
292
292
  let u = 0;
293
293
  a.forEach((y) => {
294
- E.foreach(y.range, (_, f) => {
294
+ $.foreach(y.range, (_, f) => {
295
295
  const l = r.getValue(o, g, _, f);
296
296
  if (!l) {
297
297
  const S = c.worksheet.getCellRaw(_, f);
298
- if (!u && S && S.t === R.NUMBER && S.v) {
298
+ if (!u && S && S.t === b.NUMBER && S.v) {
299
299
  const d = /\.(\d*)$/.exec(String(S.v));
300
300
  if (d) {
301
301
  const i = d[1].length;
@@ -306,13 +306,13 @@ const De = [
306
306
  }
307
307
  return;
308
308
  }
309
- const h = O(l.pattern);
309
+ const h = x(l.pattern);
310
310
  u = h > u ? h : u;
311
311
  });
312
312
  });
313
313
  const C = u + 1, M = D(`0${C > 0 ? ".0" : ""}`, C), p = [];
314
314
  return a.forEach((y) => {
315
- E.foreach(y.range, (_, f) => {
315
+ $.foreach(y.range, (_, f) => {
316
316
  const l = r.getValue(o, g, _, f);
317
317
  if (!l)
318
318
  p.push({
@@ -321,7 +321,7 @@ const De = [
321
321
  pattern: M
322
322
  });
323
323
  else {
324
- const h = O(l.pattern), S = D(l.pattern, h + 1);
324
+ const h = x(l.pattern), S = D(l.pattern, h + 1);
325
325
  S !== l.pattern && p.push({
326
326
  row: _,
327
327
  col: f,
@@ -329,7 +329,7 @@ const De = [
329
329
  });
330
330
  }
331
331
  });
332
- }), p.length ? await n.executeCommand(w.id, { values: p }) : !1;
332
+ }), p.length ? await n.executeCommand(O.id, { values: p }) : !1;
333
333
  }
334
334
  }, je = {
335
335
  id: "sheet.command.numfmt.set.currency",
@@ -338,12 +338,12 @@ const De = [
338
338
  const n = e.get(I), t = e.get(j), r = e.get(J), s = t.getCurrentSelections();
339
339
  if (!s || !s.length)
340
340
  return !1;
341
- const a = [], c = xe(r.getCurrentLocale()), o = Oe(c.locale);
341
+ const a = [], c = we(r.getCurrentLocale()), o = xe(c.locale);
342
342
  return s.forEach((u) => {
343
- E.foreach(u.range, (C, M) => {
343
+ $.foreach(u.range, (C, M) => {
344
344
  a.push({ row: C, col: M, pattern: o, type: "currency" });
345
345
  });
346
- }), await n.executeCommand(w.id, { values: a });
346
+ }), await n.executeCommand(O.id, { values: a });
347
347
  }
348
348
  }, Le = {
349
349
  id: "sheet.command.numfmt.set.percent",
@@ -354,16 +354,16 @@ const De = [
354
354
  return !1;
355
355
  const s = [], a = "0%";
356
356
  return r.forEach((o) => {
357
- E.foreach(o.range, (g, u) => {
357
+ $.foreach(o.range, (g, u) => {
358
358
  s.push({ row: g, col: u, pattern: a, type: "percent" });
359
359
  });
360
- }), await n.executeCommand(w.id, { values: s });
360
+ }), await n.executeCommand(O.id, { values: s });
361
361
  }
362
- }, He = {
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(I), t = e.get(j), r = e.get(K), s = e.get(A), a = t.getCurrentSelections();
366
+ const n = e.get(I), t = e.get(j), r = e.get(K), s = e.get(V), a = t.getCurrentSelections();
367
367
  if (!a || !a.length)
368
368
  return !1;
369
369
  const c = W(s);
@@ -371,11 +371,11 @@ const De = [
371
371
  const { unitId: o, subUnitId: g } = c;
372
372
  let u = 0;
373
373
  a.forEach((_) => {
374
- E.foreach(_.range, (f, l) => {
374
+ $.foreach(_.range, (f, l) => {
375
375
  const h = r.getValue(o, g, f, l);
376
376
  if (!h) {
377
377
  const d = c.worksheet.getCellRaw(f, l);
378
- if (!u && d && d.t === R.NUMBER && d.v) {
378
+ if (!u && d && d.t === b.NUMBER && d.v) {
379
379
  const i = /\.(\d*)$/.exec(String(d.v));
380
380
  if (i) {
381
381
  const v = i[1].length;
@@ -386,13 +386,13 @@ const De = [
386
386
  }
387
387
  return;
388
388
  }
389
- const S = O(h.pattern);
389
+ const S = x(h.pattern);
390
390
  u = S > u ? S : u;
391
391
  });
392
392
  });
393
393
  const C = u - 1, M = D(`0${C > 0 ? ".0" : "."}`, C), p = [];
394
394
  return a.forEach((_) => {
395
- E.foreach(_.range, (f, l) => {
395
+ $.foreach(_.range, (f, l) => {
396
396
  const h = r.getValue(o, g, f, l);
397
397
  if (!h)
398
398
  p.push({
@@ -401,7 +401,7 @@ const De = [
401
401
  pattern: M
402
402
  });
403
403
  else {
404
- const S = O(h.pattern);
404
+ const S = x(h.pattern);
405
405
  p.push({
406
406
  row: f,
407
407
  col: l,
@@ -409,10 +409,10 @@ const De = [
409
409
  });
410
410
  }
411
411
  });
412
- }), await n.executeCommand(w.id, { values: p });
412
+ }), await n.executeCommand(O.id, { values: p });
413
413
  }
414
- }, re = "sheets-numfmt.config", q = {}, at = (e) => $.getFormatInfo(e).type || "unknown", Be = (e, n, t = "en") => {
415
- const r = $.formatColor(e, n), s = r ? String(r) : void 0, a = $.format(e, n, { locale: t, throws: !1 });
414
+ }, re = "sheets-numfmt.config", q = {}, at = (e) => E.getFormatInfo(e).type || "unknown", He = (e, n, t = "en") => {
415
+ const r = E.formatColor(e, n), s = r ? String(r) : void 0, a = E.format(e, n, { locale: t, throws: !1 });
416
416
  return n < 0 ? {
417
417
  result: a,
418
418
  color: s
@@ -420,11 +420,11 @@ const De = [
420
420
  result: a
421
421
  };
422
422
  }, Ge = (e, n, t) => e === le ? {
423
- result: String(we(n))
423
+ result: String(Oe(n))
424
424
  // In Excel, the default General format also needs to handle numeric precision.
425
- } : Be(e, n, t), We = /* @__PURE__ */ new Set(["m d"]), Ke = /* @__PURE__ */ new Set(["h:mm AM/PM", "hh:mm AM/PM"]), it = (e) => {
425
+ } : He(e, n, t), We = /* @__PURE__ */ new Set(["m d"]), Ke = /* @__PURE__ */ new Set(["h:mm AM/PM", "hh:mm AM/PM"]), it = (e) => {
426
426
  var r, s;
427
- const n = (s = (r = $.parseDate(e)) != null ? r : $.parseTime(e)) != null ? s : $.parseNumber(e);
427
+ const n = (s = (r = E.parseDate(e)) != null ? r : E.parseTime(e)) != null ? s : E.parseNumber(e);
428
428
  if (!n) return null;
429
429
  const { z: t } = n;
430
430
  return t && (We.has(t) || Ke.has(t) && !/\s(A|AM|P|PM)$/i.test(e)) ? null : n;
@@ -443,7 +443,7 @@ const ke = {
443
443
  let F = class extends me {
444
444
  constructor(n, t, r, s, a, c, o) {
445
445
  super();
446
- L(this, "_locale$", new Ee("en"));
446
+ L(this, "_locale$", new $e("en"));
447
447
  L(this, "locale$", this._locale$.asObservable());
448
448
  this._instanceService = n, this._sheetInterceptorService = t, this._themeService = r, this._commandService = s, this._numfmtService = a, this._localeService = c, this._configService = o, this._initInterceptorCellContent();
449
449
  }
@@ -475,7 +475,7 @@ let F = class extends me {
475
475
  }
476
476
  // eslint-disable-next-line max-lines-per-function
477
477
  _initInterceptorCellContent() {
478
- const n = new b();
478
+ const n = new R();
479
479
  this.disposeWithMe(Ie(this._locale$, this._localeService.currentLocale$).subscribe(() => {
480
480
  n.reset();
481
481
  })), this.disposeWithMe(this._sheetInterceptorService.intercept(Re.CELL_CONTENT, {
@@ -483,7 +483,7 @@ let F = class extends me {
483
483
  // eslint-disable-next-line max-lines-per-function, complexity
484
484
  handler: (t, r, s) => {
485
485
  var y, _;
486
- if (!t || t.v === void 0 || t.v === null)
486
+ if (!t || t.v === void 0 || t.v === null || t.t === b.BOOLEAN || t.t === b.FORCE_STRING)
487
487
  return s(t);
488
488
  const a = r.unitId, c = r.subUnitId;
489
489
  let o;
@@ -491,11 +491,11 @@ let F = class extends me {
491
491
  const f = r.workbook.getStyles().get(t.s);
492
492
  f != null && f.n && (o = f.n);
493
493
  }
494
- if (o || (o = this._numfmtService.getValue(a, c, r.row, r.col)), fe(o == null ? void 0 : o.pattern) || t.t !== R.NUMBER && B(t.v) !== R.NUMBER)
494
+ if (o || (o = this._numfmtService.getValue(a, c, r.row, r.col)), fe(o == null ? void 0 : o.pattern) || t.t !== b.NUMBER && H(t.v, t.t) !== b.NUMBER)
495
495
  return s(t);
496
496
  const g = t;
497
497
  if ((!t || t === r.rawData) && (t = { ...r.rawData }), X(o == null ? void 0 : o.pattern))
498
- return (y = this._configService.getConfig(re)) != null && y.disableTextFormatMark ? (t.t = R.STRING, s(t)) : (t.t = R.STRING, t.markers = { ...t == null ? void 0 : t.markers, ...ke }, s(t));
498
+ return (y = this._configService.getConfig(re)) != null && y.disableTextFormatMark ? (t.t = b.STRING, s(t)) : (t.t = b.STRING, t.markers = { ...t == null ? void 0 : t.markers, ...ke }, s(t));
499
499
  let u = "";
500
500
  const C = n.getValue(r.row, r.col);
501
501
  if (C && C.parameters === `${g.v}_${o == null ? void 0 : o.pattern}`)
@@ -503,7 +503,7 @@ let F = class extends me {
503
503
  const M = Ge(o == null ? void 0 : o.pattern, Number(g.v), this.locale);
504
504
  if (u = M.result, !u)
505
505
  return s(t);
506
- const p = { v: u, t: R.NUMBER };
506
+ const p = { v: u, t: b.NUMBER };
507
507
  if (M.color) {
508
508
  const f = (_ = this._themeService.getColorFromTheme(`${M.color}.500`)) != null ? _ : M.color;
509
509
  f && (p.interceptorStyle = { cl: { rgb: f } });
@@ -519,14 +519,14 @@ let F = class extends me {
519
519
  const r = t.params;
520
520
  Object.keys(r.values).forEach((s) => {
521
521
  r.values[s].ranges.forEach((c) => {
522
- E.foreach(c, (o, g) => {
522
+ $.foreach(c, (o, g) => {
523
523
  n.realDeleteValue(o, g);
524
524
  });
525
525
  });
526
526
  });
527
527
  } else if (t.id === G.id) {
528
528
  const r = t.params;
529
- new b(r.cellValue).forValue((s, a) => {
529
+ new R(r.cellValue).forValue((s, a) => {
530
530
  n.realDeleteValue(s, a);
531
531
  });
532
532
  }
@@ -545,7 +545,7 @@ let F = class extends me {
545
545
  }
546
546
  };
547
547
  F = ze([
548
- N(0, A),
548
+ N(0, V),
549
549
  N(1, T(be)),
550
550
  N(2, T(ue)),
551
551
  N(3, T(I)),
@@ -558,8 +558,8 @@ var qe = Object.defineProperty, Xe = Object.getOwnPropertyDescriptor, Je = (e, n
558
558
  for (var s = r > 1 ? void 0 : r ? Xe(n, t) : n, a = e.length - 1, c; a >= 0; a--)
559
559
  (c = e[a]) && (s = c(s) || s);
560
560
  return s;
561
- }, H = (e, n) => (t, r) => n(t, r, e), se = (e, n, t) => Je(e, typeof n != "symbol" ? n + "" : n, t);
562
- let V = class extends he {
561
+ }, B = (e, n) => (t, r) => n(t, r, e), se = (e, n, t) => Je(e, typeof n != "symbol" ? n + "" : n, t);
562
+ let A = class extends he {
563
563
  constructor(e = q, n, t, r) {
564
564
  super(), this._config = e, this._injector = n, this._configService = t, this._commandService = r;
565
565
  const { ...s } = pe(
@@ -578,57 +578,57 @@ let V = class extends he {
578
578
  }
579
579
  onRendered() {
580
580
  [
581
- Ae,
582
- He,
581
+ Ve,
582
+ Be,
583
583
  je,
584
584
  Le,
585
- w
585
+ O
586
586
  ].forEach((e) => {
587
587
  this.disposeWithMe(this._commandService.registerCommand(e));
588
588
  });
589
589
  }
590
590
  };
591
- se(V, "pluginName", Ye);
592
- se(V, "type", ee.UNIVER_SHEET);
593
- V = Qe([
594
- de($e),
595
- H(1, T(ge)),
596
- H(2, Q),
597
- H(3, I)
598
- ], V);
599
- const ct = (e) => ne.find((t) => e.includes(t)), lt = () => ne.map((e) => ({ label: e, value: e })), ut = (e) => Ve.map((n) => ({
591
+ se(A, "pluginName", Ye);
592
+ se(A, "type", ee.UNIVER_SHEET);
593
+ A = Qe([
594
+ de(Ee),
595
+ B(1, T(ge)),
596
+ B(2, Q),
597
+ B(3, I)
598
+ ], A);
599
+ const ct = (e) => ne.find((t) => e.includes(t)), lt = () => ne.map((e) => ({ label: e, value: e })), ut = (e) => Ae.map((n) => ({
600
600
  label: n.label(e),
601
601
  value: n.suffix(e),
602
602
  color: n.color
603
603
  })), mt = () => De.map((e) => ({ label: e.label, value: e.suffix })), ft = () => Fe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
604
604
  export {
605
- Ae as AddDecimalCommand,
606
- Ve as CURRENCYFORMAT,
605
+ Ve as AddDecimalCommand,
606
+ Ae as CURRENCYFORMAT,
607
607
  De as DATEFMTLISG,
608
608
  Fe as NUMBERFORMAT,
609
609
  re as SHEETS_NUMFMT_PLUGIN_CONFIG_KEY,
610
610
  je as SetCurrencyCommand,
611
- w as SetNumfmtCommand,
611
+ O as SetNumfmtCommand,
612
612
  Le as SetPercentCommand,
613
613
  F as SheetsNumfmtCellContentController,
614
- He as SubtractDecimalCommand,
615
- V as UniverSheetsNumfmtPlugin,
614
+ Be as SubtractDecimalCommand,
615
+ A as UniverSheetsNumfmtPlugin,
616
616
  ne as currencySymbols,
617
- Oe as getCurrencyFormat,
617
+ xe as getCurrencyFormat,
618
618
  ut as getCurrencyFormatOptions,
619
619
  lt as getCurrencyOptions,
620
620
  k as getCurrencySymbolByLocale,
621
- xe as getCurrencySymbolIconByLocale,
621
+ we as getCurrencySymbolIconByLocale,
622
622
  ct as getCurrencyType,
623
623
  mt as getDateFormatOptions,
624
- O as getDecimalFromPattern,
624
+ x as getDecimalFromPattern,
625
625
  Y as getDecimalString,
626
626
  ft as getNumberFormatOptions,
627
627
  it as getNumfmtParseValueFilter,
628
- Be as getPatternPreview,
628
+ He as getPatternPreview,
629
629
  Ge as getPatternPreviewIgnoreGeneral,
630
630
  at as getPatternType,
631
631
  ot as isPatternHasDecimal,
632
- x as localeCurrencySymbolMap,
632
+ w as localeCurrencySymbolMap,
633
633
  D as setPatternDecimal
634
634
  };
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(i,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):(i=typeof globalThis<"u"?globalThis:i||self,t(i.UniverSheetsNumfmt={},i.UniverCore,i.UniverSheets,i.rxjs,i.UniverEngineFormula))})(this,(function(i,t,o,I,X){"use strict";var ve=Object.defineProperty;var Ce=(i,t,o)=>t in i?ve(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o;var V=(i,t,o)=>Ce(i,typeof t!="symbol"?t+"":t,o);const O=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],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 r=a;a>127&&(r=127);let n="";return r>0&&(n=`.${"0".repeat(r)}`),`"${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"}],P=(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(""),U=(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),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,a)=>{if(!a)return!1;const r=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=o.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:u}=l,f=a.values.filter(c=>!!c.pattern),T=a.values.filter(c=>!c.pattern),M=o.transformCellsToRange(m,S,f),C={unitId:m,subUnitId:S,ranges:T.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},b=[],h=[];if(f.length){const c=f.reduce((g,d)=>{t.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.CellValueType.STRING});const _=u.getCellRaw(d.row,d.col);if(_){const $=o.checkCellValueType(_.v);$!==_.t&&g.setValue(d.row,d.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=u.getCellRaw(g,d);_?y.setValue(g,d,{t:_.t}):y.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=o.rangeMerge(d.ranges)}),b.push({id:o.SetNumfmtMutation.id,params:M});const p=o.factorySetNumfmtUndoMutation(e,M);h.push(...p)}if(T.length){C.ranges=o.rangeMerge(C.ranges);const c=T.reduce((g,d)=>{const _=u.getCellRaw(d.row,d.col);if(_){const $=o.checkCellValueType(_.v);$!==_.t&&g.setValue(d.row,d.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=u.getCellRaw(g,d);_?y.setValue(g,d,{t:_.t}):y.setValue(g,d,{t:void 0})}),b.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const p=o.factoryRemoveNumfmtUndoMutation(e,C);h.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:y.getMatrix()}},...p)}const v=t.sequenceExecute(b,r).result;return v&&s.pushUndoRedo({unitID:m,undoMutations:h,redoMutations:b}),v}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),r=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=r.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:u}=m;let f=0;l.forEach(b=>{t.Range.foreach(b.range,(h,v)=>{const c=n.getValue(S,u,h,v);if(!c){const p=m.worksheet.getCellRaw(h,v);if(!f&&p&&p.t===t.CellValueType.NUMBER&&p.v){const g=/\.(\d*)$/.exec(String(p.v));if(g){const d=g[1].length;if(!d)return;f=Math.max(f,d)}}return}const y=P(c.pattern);f=y>f?y:f})});const T=f+1,M=U(`0${T>0?".0":""}`,T),C=[];return l.forEach(b=>{t.Range.foreach(b.range,(h,v)=>{const c=n.getValue(S,u,h,v);if(!c)C.push({row:h,col:v,pattern:M});else{const y=P(c.pattern),p=U(c.pattern,y+1);p!==c.pattern&&C.push({row:h,col:v,pattern:p})}})}),C.length?await a.executeCommand(R.id,{values:C}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),r=e.get(o.SheetsSelectionsService),n=e.get(t.LocaleService),s=r.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(R.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(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(u,f)=>{s.push({row:u,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),r=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=r.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:u}=m;let f=0;l.forEach(h=>{t.Range.foreach(h.range,(v,c)=>{const y=n.getValue(S,u,v,c);if(!y){const g=m.worksheet.getCellRaw(v,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 p=P(y.pattern);f=p>f?p:f})});const T=f-1,M=U(`0${T>0?".0":"."}`,T),C=[];return l.forEach(h=>{t.Range.foreach(h.range,(v,c)=>{const y=n.getValue(S,u,v,c);if(!y)C.push({row:v,col:c,pattern:M});else{const p=P(y.pattern);C.push({row:v,col:c,pattern:U(y.pattern,p-1)})}})}),await a.executeCommand(R.id,{values:C})}},D="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,r="en")=>{const n=t.numfmt.formatColor(e,a),s=n?String(n):void 0,l=t.numfmt.format(e,a,{locale:r,throws:!1});return a<0?{result:l,color:s}:{result:l}},z=(e,a,r)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(X.stripErrorMargin(a))}:k(e,a,r),ee=new Set(["m d"]),te=new Set(["h:mm AM/PM","hh:mm AM/PM"]),ne=e=>{var n,s;const a=(s=(n=t.numfmt.parseDate(e))!=null?n:t.numfmt.parseTime(e))!=null?s:t.numfmt.parseNumber(e);if(!a)return null;const{z:r}=a;return r&&(ee.has(r)||te.has(r)&&!/\s(A|AM|P|PM)$/i.test(e))?null:a};var ae=Object.getOwnPropertyDescriptor,re=(e,a,r,n)=>{for(var s=n>1?void 0:n?ae(a,r):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,a)=>(r,n)=>a(r,n,e);const ie={tl:{size:6,color:"#409f11"}};i.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(r,n,s,l,m,S,u){super();V(this,"_locale$",new I.BehaviorSubject("en"));V(this,"locale$",this._locale$.asObservable());this._instanceService=r,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=u,this._initInterceptorCellContent()}get locale(){const r=this._locale$.getValue();if(r)return r;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 r=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{r.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var h,v;if(!n||n.v===void 0||n.v===null)return l(n);const m=s.unitId,S=s.subUnitId;let u;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(u=c.n)}if(u||(u=this._numfmtService.getValue(m,S,s.row,s.col)),t.isDefaultFormat(u==null?void 0:u.pattern)||n.t!==t.CellValueType.NUMBER&&o.checkCellValueType(n.v)!==t.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(u==null?void 0:u.pattern))return(h=this._configService.getConfig(D))!=null&&h.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ie},l(n));let T="";const M=r.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${u==null?void 0:u.pattern}`)return l({...n,...M.result});const C=z(u==null?void 0:u.pattern,Number(f.v),this.locale);if(T=C.result,!T)return l(n);const b={v:T,t:t.CellValueType.NUMBER};if(C.color){const c=(v=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?v:C.color;c&&(b.interceptorStyle={cl:{rgb:c}})}return r.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${u==null?void 0:u.pattern}`}),Object.assign(n,b),l(n)},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(u,f)=>{r.realDeleteValue(u,f)})})})}else if(n.id===o.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{r.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>r.reset()))}setNumfmtLocal(r){this._locale$.next(r)}},i.SheetsNumfmtCellContentController=re([N(0,t.IUniverInstanceService),N(1,t.Inject(o.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(o.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],i.SheetsNumfmtCellContentController);const se="SHEET_NUMFMT_PLUGIN";var le=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,ue=(e,a,r)=>a in e?le(e,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[a]=r,oe=(e,a,r,n)=>{for(var s=n>1?void 0:n?ce(a,r):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},w=(e,a)=>(r,n)=>a(r,n,e),Y=(e,a,r)=>ue(e,typeof a!="symbol"?a+"":a,r);i.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,r,n,s){super(),this._config=a,this._injector=r,this._configService=n,this._commandService=s;const{...l}=t.merge({},Z,this._config);this._configService.setConfig(D,l)}onStarting(){t.registerDependencies(this._injector,[[i.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[i.SheetsNumfmtCellContentController]])}onRendered(){[x,q,W,K,R].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},Y(i.UniverSheetsNumfmtPlugin,"pluginName",se),Y(i.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),i.UniverSheetsNumfmtPlugin=oe([t.DependentOn(o.UniverSheetsPlugin),w(1,t.Inject(t.Injector)),w(2,t.IConfigService),w(3,t.ICommandService)],i.UniverSheetsNumfmtPlugin);const me=e=>O.find(r=>e.includes(r)),fe=()=>O.map(e=>({label:e,value:e})),de=e=>H.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),ge=()=>B.map(e=>({label:e.label,value:e.suffix})),Se=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));i.AddDecimalCommand=x,i.CURRENCYFORMAT=H,i.DATEFMTLISG=B,i.NUMBERFORMAT=G,i.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,i.SetCurrencyCommand=W,i.SetNumfmtCommand=R,i.SetPercentCommand=K,i.SubtractDecimalCommand=q,i.currencySymbols=O,i.getCurrencyFormat=A,i.getCurrencyFormatOptions=de,i.getCurrencyOptions=fe,i.getCurrencySymbolByLocale=F,i.getCurrencySymbolIconByLocale=j,i.getCurrencyType=me,i.getDateFormatOptions=ge,i.getDecimalFromPattern=P,i.getDecimalString=L,i.getNumberFormatOptions=Se,i.getNumfmtParseValueFilter=ne,i.getPatternPreview=k,i.getPatternPreviewIgnoreGeneral=z,i.getPatternType=Q,i.isPatternHasDecimal=J,i.localeCurrencySymbolMap=E,i.setPatternDecimal=U,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(i,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):(i=typeof globalThis<"u"?globalThis:i||self,t(i.UniverSheetsNumfmt={},i.UniverCore,i.UniverSheets,i.rxjs,i.UniverEngineFormula))})(this,(function(i,t,o,I,X){"use strict";var ve=Object.defineProperty;var Ce=(i,t,o)=>t in i?ve(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o;var w=(i,t,o)=>Ce(i,typeof t!="symbol"?t+"":t,o);const O=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],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 r=a;a>127&&(r=127);let n="";return r>0&&(n=`.${"0".repeat(r)}`),`"${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"}],P=(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(""),U=(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),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,a)=>{if(!a)return!1;const r=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=o.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:c}=l,f=a.values.filter(u=>!!u.pattern),T=a.values.filter(u=>!u.pattern),M=o.transformCellsToRange(m,S,f),C={unitId:m,subUnitId:S,ranges:T.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},b=[],p=[];if(f.length){const u=f.reduce((g,d)=>{t.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.CellValueType.STRING});const _=c.getCellRaw(d.row,d.col);if(_){const $=o.checkCellValueType(_.v);$!==_.t&&g.setValue(d.row,d.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,d)=>{const _=c.getCellRaw(g,d);_?y.setValue(g,d,{t:_.t}):y.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=o.rangeMerge(d.ranges)}),b.push({id:o.SetNumfmtMutation.id,params:M});const h=o.factorySetNumfmtUndoMutation(e,M);p.push(...h)}if(T.length){C.ranges=o.rangeMerge(C.ranges);const u=T.reduce((g,d)=>{const _=c.getCellRaw(d.row,d.col);if(_){const $=o.checkCellValueType(_.v);$!==_.t&&g.setValue(d.row,d.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,d)=>{const _=c.getCellRaw(g,d);_?y.setValue(g,d,{t:_.t}):y.setValue(g,d,{t:void 0})}),b.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const h=o.factoryRemoveNumfmtUndoMutation(e,C);p.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:y.getMatrix()}},...h)}const v=t.sequenceExecute(b,r).result;return v&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),v}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),r=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=r.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:c}=m;let f=0;l.forEach(b=>{t.Range.foreach(b.range,(p,v)=>{const u=n.getValue(S,c,p,v);if(!u){const h=m.worksheet.getCellRaw(p,v);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 y=P(u.pattern);f=y>f?y:f})});const T=f+1,M=U(`0${T>0?".0":""}`,T),C=[];return l.forEach(b=>{t.Range.foreach(b.range,(p,v)=>{const u=n.getValue(S,c,p,v);if(!u)C.push({row:p,col:v,pattern:M});else{const y=P(u.pattern),h=U(u.pattern,y+1);h!==u.pattern&&C.push({row:p,col:v,pattern:h})}})}),C.length?await a.executeCommand(R.id,{values:C}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),r=e.get(o.SheetsSelectionsService),n=e.get(t.LocaleService),s=r.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(R.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(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(c,f)=>{s.push({row:c,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),r=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=r.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:c}=m;let f=0;l.forEach(p=>{t.Range.foreach(p.range,(v,u)=>{const y=n.getValue(S,c,v,u);if(!y){const g=m.worksheet.getCellRaw(v,u);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=P(y.pattern);f=h>f?h:f})});const T=f-1,M=U(`0${T>0?".0":"."}`,T),C=[];return l.forEach(p=>{t.Range.foreach(p.range,(v,u)=>{const y=n.getValue(S,c,v,u);if(!y)C.push({row:v,col:u,pattern:M});else{const h=P(y.pattern);C.push({row:v,col:u,pattern:U(y.pattern,h-1)})}})}),await a.executeCommand(R.id,{values:C})}},V="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,r="en")=>{const n=t.numfmt.formatColor(e,a),s=n?String(n):void 0,l=t.numfmt.format(e,a,{locale:r,throws:!1});return a<0?{result:l,color:s}:{result:l}},z=(e,a,r)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(X.stripErrorMargin(a))}:k(e,a,r),ee=new Set(["m d"]),te=new Set(["h:mm AM/PM","hh:mm AM/PM"]),ne=e=>{var n,s;const a=(s=(n=t.numfmt.parseDate(e))!=null?n:t.numfmt.parseTime(e))!=null?s:t.numfmt.parseNumber(e);if(!a)return null;const{z:r}=a;return r&&(ee.has(r)||te.has(r)&&!/\s(A|AM|P|PM)$/i.test(e))?null:a};var ae=Object.getOwnPropertyDescriptor,re=(e,a,r,n)=>{for(var s=n>1?void 0:n?ae(a,r):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,a)=>(r,n)=>a(r,n,e);const ie={tl:{size:6,color:"#409f11"}};i.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(r,n,s,l,m,S,c){super();w(this,"_locale$",new I.BehaviorSubject("en"));w(this,"locale$",this._locale$.asObservable());this._instanceService=r,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=c,this._initInterceptorCellContent()}get locale(){const r=this._locale$.getValue();if(r)return r;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 r=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{r.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,v;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 c;if(n!=null&&n.s){const u=s.workbook.getStyles().get(n.s);u!=null&&u.n&&(c=u.n)}if(c||(c=this._numfmtService.getValue(m,S,s.row,s.col)),t.isDefaultFormat(c==null?void 0:c.pattern)||n.t!==t.CellValueType.NUMBER&&o.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(c==null?void 0:c.pattern))return(p=this._configService.getConfig(V))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ie},l(n));let T="";const M=r.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${c==null?void 0:c.pattern}`)return l({...n,...M.result});const C=z(c==null?void 0:c.pattern,Number(f.v),this.locale);if(T=C.result,!T)return l(n);const b={v:T,t:t.CellValueType.NUMBER};if(C.color){const u=(v=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?v:C.color;u&&(b.interceptorStyle={cl:{rgb:u}})}return r.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${c==null?void 0:c.pattern}`}),Object.assign(n,b),l(n)},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(c,f)=>{r.realDeleteValue(c,f)})})})}else if(n.id===o.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{r.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>r.reset()))}setNumfmtLocal(r){this._locale$.next(r)}},i.SheetsNumfmtCellContentController=re([N(0,t.IUniverInstanceService),N(1,t.Inject(o.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(o.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],i.SheetsNumfmtCellContentController);const se="SHEET_NUMFMT_PLUGIN";var le=Object.defineProperty,ue=Object.getOwnPropertyDescriptor,ce=(e,a,r)=>a in e?le(e,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[a]=r,oe=(e,a,r,n)=>{for(var s=n>1?void 0:n?ue(a,r):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},D=(e,a)=>(r,n)=>a(r,n,e),Y=(e,a,r)=>ce(e,typeof a!="symbol"?a+"":a,r);i.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,r,n,s){super(),this._config=a,this._injector=r,this._configService=n,this._commandService=s;const{...l}=t.merge({},Z,this._config);this._configService.setConfig(V,l)}onStarting(){t.registerDependencies(this._injector,[[i.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[i.SheetsNumfmtCellContentController]])}onRendered(){[x,q,W,K,R].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},Y(i.UniverSheetsNumfmtPlugin,"pluginName",se),Y(i.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),i.UniverSheetsNumfmtPlugin=oe([t.DependentOn(o.UniverSheetsPlugin),D(1,t.Inject(t.Injector)),D(2,t.IConfigService),D(3,t.ICommandService)],i.UniverSheetsNumfmtPlugin);const me=e=>O.find(r=>e.includes(r)),fe=()=>O.map(e=>({label:e,value:e})),de=e=>H.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),ge=()=>B.map(e=>({label:e.label,value:e.suffix})),Se=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));i.AddDecimalCommand=x,i.CURRENCYFORMAT=H,i.DATEFMTLISG=B,i.NUMBERFORMAT=G,i.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=V,i.SetCurrencyCommand=W,i.SetNumfmtCommand=R,i.SetPercentCommand=K,i.SubtractDecimalCommand=q,i.currencySymbols=O,i.getCurrencyFormat=A,i.getCurrencyFormatOptions=de,i.getCurrencyOptions=fe,i.getCurrencySymbolByLocale=F,i.getCurrencySymbolIconByLocale=j,i.getCurrencyType=me,i.getDateFormatOptions=ge,i.getDecimalFromPattern=P,i.getDecimalString=L,i.getNumberFormatOptions=Se,i.getNumfmtParseValueFilter=ne,i.getPatternPreview=k,i.getPatternPreviewIgnoreGeneral=z,i.getPatternType=Q,i.isPatternHasDecimal=J,i.localeCurrencySymbolMap=E,i.setPatternDecimal=U,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt",
3
- "version": "0.10.6",
3
+ "version": "0.10.7-nightly.202509090319",
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/engine-formula": "0.10.6",
62
- "@univerjs/sheets": "0.10.6",
63
- "@univerjs/core": "0.10.6"
61
+ "@univerjs/core": "0.10.7-nightly.202509090319",
62
+ "@univerjs/sheets": "0.10.7-nightly.202509090319",
63
+ "@univerjs/engine-formula": "0.10.7-nightly.202509090319"
64
64
  },
65
65
  "devDependencies": {
66
66
  "rxjs": "^7.8.2",
67
67
  "typescript": "^5.9.2",
68
- "vite": "^7.1.3",
68
+ "vite": "^7.1.4",
69
69
  "vitest": "^3.2.4",
70
- "@univerjs-infra/shared": "0.10.6"
70
+ "@univerjs-infra/shared": "0.10.7"
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