@univerjs/sheets-numfmt 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var z=Object.defineProperty;var X=(e,r,a)=>r in e?z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a;var U=(e,r,a)=>X(e,typeof r!="symbol"?r+"":r,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function V(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function j(e,r=2){let a=r;r>127&&(a=127);let n="";return a>0&&(n=`.${"0".repeat(a)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const A=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],G=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],$=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),O=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${L(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${L(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const a=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:i}=o,u=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=f.transformCellsToRange(l,d,u),h={unitId:l,subUnitId:d,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],C=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.t}):p.setValue(g,m,{t:void 0})}),Object.keys(T.values).forEach(g=>{const m=T.values[g];m.ranges=f.rangeMerge(m.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:T});const y=f.factorySetNumfmtUndoMutation(e,T);C.push(...y)}if(_.length){h.ranges=f.rangeMerge(h.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.t}):p.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,h);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:p.getMatrix()}},...y)}const S=t.sequenceExecute(M,a).result;return S&&s.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),S}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(!c){const y=l.worksheet.getCellRaw(C,S);if(!u&&y&&y.t===t.CellValueType.NUMBER&&y.v){const g=/\.(\d*)$/.exec(String(y.v));if(g){const m=g[1].length;if(!m)return;u=Math.max(u,m)}}return}const p=$(c.pattern);u=p>u?p:u})});const _=u+1,T=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(t.isDefaultFormat(c==null?void 0:c.pattern))h.push({row:C,col:S,pattern:T});else{const p=$(c.pattern),y=O(c.pattern,p+1);y!==c.pattern&&h.push({row:C,col:S,pattern:y})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),s=a.getCurrentSelections();if(!s||!s.length)return!1;const o=[],l=V(n.getCurrentLocale()),d=j(l.locale);return s.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(R.id,{values:o})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{s.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(!p){const g=l.worksheet.getCellRaw(S,c);if(!u&&g&&g.t===t.CellValueType.NUMBER&&g.v){const m=/\.(\d*)$/.exec(String(g.v));if(m){const v=m[1].length;if(!v)return;u=Math.max(u,v)}}return}const y=$(p.pattern);u=y>u?y:u})});const _=u-1,T=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(C=>{t.Range.foreach(C.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(t.isDefaultFormat(p==null?void 0:p.pattern))h.push({row:S,col:c,pattern:T});else{const y=$(p.pattern);h.push({row:S,col:c,pattern:O(p.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:h})}},D="sheets-numfmt.config",w={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,a="en")=>{try{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:a,throws:!1});return r<0?{result:o,color:s}:{result:o}}catch(n){console.warn("getPatternPreview error:",e,n)}return{result:String(r)}},k=(e,r,a)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,a);var te=Object.getOwnPropertyDescriptor,ne=(e,r,a,n)=>{for(var s=n>1?void 0:n?te(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},b=(e,r)=>(a,n)=>r(a,n,e);const re={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(a,n,s,o,l,d,i){super();U(this,"_locale$",new N.BehaviorSubject("en"));U(this,"locale$",this._locale$.asObservable());this._instanceService=a,this._sheetInterceptorService=n,this._themeService=s,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const a=this._locale$.getValue();if(a)return a;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const a=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{a.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,o)=>{var C,S;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return o(n);const l=s.unitId,d=s.subUnitId;let i;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,s.row,s.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(C=this._configService.getConfig(D))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...re},o(n));let _="";const T=a.getValue(s.row,s.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const h=k(i==null?void 0:i.pattern,Number(u.v),this.locale);if(_=h.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(h.color){const c=(S=this._themeService.getColorFromTheme(`${h.color}.500`))!=null?S:h.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return a.setValue(s.row,s.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(o=>{s.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{a.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((o,l)=>{a.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>a.reset()))}setNumfmtLocal(a){this._locale$.next(a)}};exports.SheetsNumfmtCellContentController=ne([b(0,t.IUniverInstanceService),b(1,t.Inject(f.SheetInterceptorService)),b(2,t.Inject(t.ThemeService)),b(3,t.Inject(t.ICommandService)),b(4,t.Inject(f.INumfmtService)),b(5,t.Inject(t.LocaleService)),b(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var se=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,a)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,ie=(e,r,a,n)=>{for(var s=n>1?void 0:n?oe(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},P=(e,r)=>(a,n)=>r(a,n,e),Y=(e,r,a)=>ce(e,typeof r!="symbol"?r+"":r,a);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=w,a,n,s){super(),this._config=r,this._injector=a,this._configService=n,this._commandService=s;const{...o}=t.merge({},w,this._config);this._configService.setConfig(D,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){[H,q,W,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};Y(exports.UniverSheetsNumfmtPlugin,"pluginName",ae);Y(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(f.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>x.find(a=>e.includes(a)),ue=()=>x.map(e=>({label:e,value:e})),me=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>A.map(e=>({label:e.label,value:e.suffix})),ge=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=A;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=x;exports.getCurrencyFormat=j;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=V;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=$;exports.getDecimalString=L;exports.getNumberFormatOptions=ge;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=O;
1
+ "use strict";var z=Object.defineProperty;var X=(e,r,a)=>r in e?z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a;var U=(e,r,a)=>X(e,typeof r!="symbol"?r+"":r,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function V(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function j(e,r=2){let a=r;r>127&&(a=127);let n="";return a>0&&(n=`.${"0".repeat(a)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const A=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],G=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],$=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),O=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${L(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${L(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const a=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:i}=o,u=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=f.transformCellsToRange(l,d,u),h={unitId:l,subUnitId:d,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],C=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.t}):p.setValue(g,m,{t:void 0})}),Object.keys(T.values).forEach(g=>{const m=T.values[g];m.ranges=f.rangeMerge(m.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:T});const y=f.factorySetNumfmtUndoMutation(e,T);C.push(...y)}if(_.length){h.ranges=f.rangeMerge(h.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.t}):p.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,h);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:p.getMatrix()}},...y)}const S=t.sequenceExecute(M,a).result;return S&&s.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),S}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(!c){const y=l.worksheet.getCellRaw(C,S);if(!u&&y&&y.t===t.CellValueType.NUMBER&&y.v){const g=/\.(\d*)$/.exec(String(y.v));if(g){const m=g[1].length;if(!m)return;u=Math.max(u,m)}}return}const p=$(c.pattern);u=p>u?p:u})});const _=u+1,T=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(t.isDefaultFormat(c==null?void 0:c.pattern))h.push({row:C,col:S,pattern:T});else{const p=$(c.pattern),y=O(c.pattern,p+1);y!==c.pattern&&h.push({row:C,col:S,pattern:y})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),s=a.getCurrentSelections();if(!s||!s.length)return!1;const o=[],l=V(n.getCurrentLocale()),d=j(l.locale);return s.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(R.id,{values:o})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{s.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(!p){const g=l.worksheet.getCellRaw(S,c);if(!u&&g&&g.t===t.CellValueType.NUMBER&&g.v){const m=/\.(\d*)$/.exec(String(g.v));if(m){const v=m[1].length;if(!v)return;u=Math.max(u,v)}}return}const y=$(p.pattern);u=y>u?y:u})});const _=u-1,T=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(C=>{t.Range.foreach(C.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(t.isDefaultFormat(p==null?void 0:p.pattern))h.push({row:S,col:c,pattern:T});else{const y=$(p.pattern);h.push({row:S,col:c,pattern:O(p.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:h})}},D="sheets-numfmt.config",w={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,a="en")=>{try{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:a,throws:!1});return r<0?{result:o,color:s}:{result:o}}catch(n){console.warn("getPatternPreview error:",e,n)}return{result:String(r)}},k=(e,r,a)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,a);var te=Object.getOwnPropertyDescriptor,ne=(e,r,a,n)=>{for(var s=n>1?void 0:n?te(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},b=(e,r)=>(a,n)=>r(a,n,e);const re={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(a,n,s,o,l,d,i){super();U(this,"_locale$",new N.BehaviorSubject("en"));U(this,"locale$",this._locale$.asObservable());this._instanceService=a,this._sheetInterceptorService=n,this._themeService=s,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const a=this._locale$.getValue();if(a)return a;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const a=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{a.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,o)=>{var C,S;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return o(n);const l=s.unitId,d=s.subUnitId;let i;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,s.row,s.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(C=this._configService.getConfig(D))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...re},o(n));let _="";const T=a.getValue(s.row,s.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const h=k(i==null?void 0:i.pattern,Number(u.v),this.locale);if(_=h.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(h.color){const c=(S=this._themeService.getColorFromTheme(`${h.color}.500`))!=null?S:h.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return a.setValue(s.row,s.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(o=>{s.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{a.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((o,l)=>{a.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>a.reset()))}setNumfmtLocal(a){this._locale$.next(a)}};exports.SheetsNumfmtCellContentController=ne([b(0,t.IUniverInstanceService),b(1,t.Inject(f.SheetInterceptorService)),b(2,t.Inject(t.ThemeService)),b(3,t.Inject(t.ICommandService)),b(4,t.Inject(f.INumfmtService)),b(5,t.Inject(t.LocaleService)),b(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var se=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,a)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,ie=(e,r,a,n)=>{for(var s=n>1?void 0:n?oe(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},P=(e,r)=>(a,n)=>r(a,n,e),Y=(e,r,a)=>ce(e,typeof r!="symbol"?r+"":r,a);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=w,a,n,s){super(),this._config=r,this._injector=a,this._configService=n,this._commandService=s;const{...o}=t.merge({},w,this._config);this._configService.setConfig(D,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),[H,q,W,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};Y(exports.UniverSheetsNumfmtPlugin,"pluginName",ae);Y(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(f.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>x.find(a=>e.includes(a)),ue=()=>x.map(e=>({label:e,value:e})),me=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>A.map(e=>({label:e.label,value:e.suffix})),ge=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=A;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=x;exports.getCurrencyFormat=j;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=V;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=$;exports.getDecimalString=L;exports.getNumberFormatOptions=ge;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=O;
package/lib/es/index.js CHANGED
@@ -575,10 +575,7 @@ let A = class extends he {
575
575
  [D]
576
576
  ]), ve(this._injector, [
577
577
  [D]
578
- ]);
579
- }
580
- onRendered() {
581
- [
578
+ ]), [
582
579
  Ve,
583
580
  Be,
584
581
  je,
package/lib/index.js CHANGED
@@ -575,10 +575,7 @@ let A = class extends he {
575
575
  [D]
576
576
  ]), ve(this._injector, [
577
577
  [D]
578
- ]);
579
- }
580
- onRendered() {
581
- [
578
+ ]), [
582
579
  Ve,
583
580
  Be,
584
581
  je,
@@ -9,5 +9,4 @@ export declare class UniverSheetsNumfmtPlugin extends Plugin {
9
9
  static type: UniverInstanceType;
10
10
  constructor(_config: Partial<IUniverSheetsNumfmtConfig> | undefined, _injector: Injector, _configService: IConfigService, _commandService: ICommandService);
11
11
  onStarting(): void;
12
- onRendered(): void;
13
12
  }
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(r,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-formula"],t):(r=typeof globalThis<"u"?globalThis:r||self,t(r.UniverSheetsNumfmt={},r.UniverCore,r.UniverSheets,r.rxjs,r.UniverEngineFormula))})(this,(function(r,t,u,N,X){"use strict";var de=Object.defineProperty;var ge=(r,t,u)=>t in r?de(r,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[t]=u;var V=(r,t,u)=>ge(r,typeof t!="symbol"?t+"":t,u);const P=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function j(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function A(e,a=2){let i=a;a>127&&(i=127);let n="";return i>0&&(n=`.${"0".repeat(i)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const B=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],G=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],H=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],U=(e,a=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:a},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,a)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${L(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${L(Number(a||0))}$1`):n).join(";"),J=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),I={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,a)=>{if(!a)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=u.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:o}=l,f=a.values.filter(c=>!!c.pattern),T=a.values.filter(c=>!c.pattern),M=u.transformCellsToRange(m,S,f),y={unitId:m,subUnitId:S,ranges:T.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},b=[],p=[];if(f.length){const c=f.reduce((g,d)=>{t.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.CellValueType.STRING});const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=u.rangeMerge(d.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const h=u.factorySetNumfmtUndoMutation(e,M);p.push(...h)}if(T.length){y.ranges=u.rangeMerge(y.ranges);const c=T.reduce((g,d)=>{const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const h=u.factoryRemoveNumfmtUndoMutation(e,y);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:v.getMatrix()}},...h)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),C}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(!c){const h=m.worksheet.getCellRaw(p,C);if(!f&&h&&h.t===t.CellValueType.NUMBER&&h.v){const g=/\.(\d*)$/.exec(String(h.v));if(g){const d=g[1].length;if(!d)return;f=Math.max(f,d)}}return}const v=U(c.pattern);f=v>f?v:f})});const T=f+1,M=$(`0${T>0?".0":""}`,T),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(t.isDefaultFormat(c==null?void 0:c.pattern))y.push({row:p,col:C,pattern:M});else{const v=U(c.pattern),h=$(c.pattern,v+1);h!==c.pattern&&y.push({row:p,col:C,pattern:h})}})}),y.length?await a.executeCommand(I.id,{values:y}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(t.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=j(n.getCurrentLocale()),S=A(m.locale);return s.forEach(f=>{t.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(I.id,{values:l})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(o,f)=>{s.push({row:o,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(I.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(!v){const g=m.worksheet.getCellRaw(C,c);if(!f&&g&&g.t===t.CellValueType.NUMBER&&g.v){const d=/\.(\d*)$/.exec(String(g.v));if(d){const _=d[1].length;if(!_)return;f=Math.max(f,_)}}return}const h=U(v.pattern);f=h>f?h:f})});const T=f-1,M=$(`0${T>0?".0":"."}`,T),y=[];return l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(t.isDefaultFormat(v==null?void 0:v.pattern))y.push({row:C,col:c,pattern:M});else{const h=U(v.pattern);y.push({row:C,col:c,pattern:$(v.pattern,h-1)})}})}),await a.executeCommand(I.id,{values:y})}},D="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,i="en")=>{try{const n=t.numfmt.formatColor(e,a),s=n?String(n):void 0,l=t.numfmt.format(e,a,{locale:i,throws:!1});return a<0?{result:l,color:s}:{result:l}}catch(n){console.warn("getPatternPreview error:",e,n)}return{result:String(a)}},Y=(e,a,i)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(X.stripErrorMargin(a))}:k(e,a,i);var ee=Object.getOwnPropertyDescriptor,te=(e,a,i,n)=>{for(var s=n>1?void 0:n?ee(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},R=(e,a)=>(i,n)=>a(i,n,e);const ne={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,o){super();V(this,"_locale$",new N.BehaviorSubject("en"));V(this,"locale$",this._locale$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=o,this._initInterceptorCellContent()}get locale(){const i=this._locale$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,C;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return l(n);const m=s.unitId,S=s.subUnitId;let o;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(o=c.n)}if(o||(o=this._numfmtService.getValue(m,S,s.row,s.col)),t.isDefaultFormat(o==null?void 0:o.pattern)||n.t!==t.CellValueType.NUMBER&&u.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(o==null?void 0:o.pattern))return(p=this._configService.getConfig(D))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},l(n));let T="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${o==null?void 0:o.pattern}`)return l({...n,...M.result});const y=Y(o==null?void 0:o.pattern,Number(f.v),this.locale);if(T=y.result,!T)return l(n);const b={v:T,t:t.CellValueType.NUMBER};if(y.color){const c=(C=this._themeService.getColorFromTheme(`${y.color}.500`))!=null?C:y.color;c&&(b.interceptorStyle={cl:{rgb:c}})}return i.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${o==null?void 0:o.pattern}`}),Object.assign(n,b),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(o,f)=>{i.realDeleteValue(o,f)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},r.SheetsNumfmtCellContentController=te([R(0,t.IUniverInstanceService),R(1,t.Inject(u.SheetInterceptorService)),R(2,t.Inject(t.ThemeService)),R(3,t.Inject(t.ICommandService)),R(4,t.Inject(u.INumfmtService)),R(5,t.Inject(t.LocaleService)),R(6,t.IConfigService)],r.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var re=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,a,i)=>a in e?re(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,le=(e,a,i,n)=>{for(var s=n>1?void 0:n?ie(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},w=(e,a)=>(i,n)=>a(i,n,e),z=(e,a,i)=>se(e,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,i,n,s){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},Z,this._config);this._configService.setConfig(D,l)}onStarting(){t.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]])}onRendered(){[x,q,W,K,I].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},z(r.UniverSheetsNumfmtPlugin,"pluginName",ae),z(r.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),w(1,t.Inject(t.Injector)),w(2,t.IConfigService),w(3,t.ICommandService)],r.UniverSheetsNumfmtPlugin);const ce=e=>P.find(i=>e.includes(i)),oe=()=>P.map(e=>({label:e,value:e})),ue=e=>H.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),me=()=>B.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=H,r.DATEFMTLISG=B,r.NUMBERFORMAT=G,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,r.SetCurrencyCommand=W,r.SetNumfmtCommand=I,r.SetPercentCommand=K,r.SubtractDecimalCommand=q,r.currencySymbols=P,r.getCurrencyFormat=A,r.getCurrencyFormatOptions=ue,r.getCurrencyOptions=oe,r.getCurrencySymbolByLocale=F,r.getCurrencySymbolIconByLocale=j,r.getCurrencyType=ce,r.getDateFormatOptions=me,r.getDecimalFromPattern=U,r.getDecimalString=L,r.getNumberFormatOptions=fe,r.getPatternPreview=k,r.getPatternPreviewIgnoreGeneral=Y,r.getPatternType=Q,r.isPatternHasDecimal=J,r.localeCurrencySymbolMap=E,r.setPatternDecimal=$,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(r,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-formula"],t):(r=typeof globalThis<"u"?globalThis:r||self,t(r.UniverSheetsNumfmt={},r.UniverCore,r.UniverSheets,r.rxjs,r.UniverEngineFormula))})(this,(function(r,t,u,N,X){"use strict";var de=Object.defineProperty;var ge=(r,t,u)=>t in r?de(r,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[t]=u;var V=(r,t,u)=>ge(r,typeof t!="symbol"?t+"":t,u);const P=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function j(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function A(e,a=2){let i=a;a>127&&(i=127);let n="";return i>0&&(n=`.${"0".repeat(i)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const B=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],G=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],H=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],U=(e,a=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:a},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,a)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${L(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${L(Number(a||0))}$1`):n).join(";"),J=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),I={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,a)=>{if(!a)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=u.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:o}=l,f=a.values.filter(c=>!!c.pattern),T=a.values.filter(c=>!c.pattern),M=u.transformCellsToRange(m,S,f),y={unitId:m,subUnitId:S,ranges:T.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},b=[],p=[];if(f.length){const c=f.reduce((g,d)=>{t.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.CellValueType.STRING});const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=u.rangeMerge(d.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const h=u.factorySetNumfmtUndoMutation(e,M);p.push(...h)}if(T.length){y.ranges=u.rangeMerge(y.ranges);const c=T.reduce((g,d)=>{const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const h=u.factoryRemoveNumfmtUndoMutation(e,y);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:v.getMatrix()}},...h)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),C}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(!c){const h=m.worksheet.getCellRaw(p,C);if(!f&&h&&h.t===t.CellValueType.NUMBER&&h.v){const g=/\.(\d*)$/.exec(String(h.v));if(g){const d=g[1].length;if(!d)return;f=Math.max(f,d)}}return}const v=U(c.pattern);f=v>f?v:f})});const T=f+1,M=$(`0${T>0?".0":""}`,T),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(t.isDefaultFormat(c==null?void 0:c.pattern))y.push({row:p,col:C,pattern:M});else{const v=U(c.pattern),h=$(c.pattern,v+1);h!==c.pattern&&y.push({row:p,col:C,pattern:h})}})}),y.length?await a.executeCommand(I.id,{values:y}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(t.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=j(n.getCurrentLocale()),S=A(m.locale);return s.forEach(f=>{t.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(I.id,{values:l})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(o,f)=>{s.push({row:o,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(I.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(!v){const g=m.worksheet.getCellRaw(C,c);if(!f&&g&&g.t===t.CellValueType.NUMBER&&g.v){const d=/\.(\d*)$/.exec(String(g.v));if(d){const _=d[1].length;if(!_)return;f=Math.max(f,_)}}return}const h=U(v.pattern);f=h>f?h:f})});const T=f-1,M=$(`0${T>0?".0":"."}`,T),y=[];return l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(t.isDefaultFormat(v==null?void 0:v.pattern))y.push({row:C,col:c,pattern:M});else{const h=U(v.pattern);y.push({row:C,col:c,pattern:$(v.pattern,h-1)})}})}),await a.executeCommand(I.id,{values:y})}},D="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,i="en")=>{try{const n=t.numfmt.formatColor(e,a),s=n?String(n):void 0,l=t.numfmt.format(e,a,{locale:i,throws:!1});return a<0?{result:l,color:s}:{result:l}}catch(n){console.warn("getPatternPreview error:",e,n)}return{result:String(a)}},Y=(e,a,i)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(X.stripErrorMargin(a))}:k(e,a,i);var ee=Object.getOwnPropertyDescriptor,te=(e,a,i,n)=>{for(var s=n>1?void 0:n?ee(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},R=(e,a)=>(i,n)=>a(i,n,e);const ne={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,o){super();V(this,"_locale$",new N.BehaviorSubject("en"));V(this,"locale$",this._locale$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=o,this._initInterceptorCellContent()}get locale(){const i=this._locale$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,C;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return l(n);const m=s.unitId,S=s.subUnitId;let o;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(o=c.n)}if(o||(o=this._numfmtService.getValue(m,S,s.row,s.col)),t.isDefaultFormat(o==null?void 0:o.pattern)||n.t!==t.CellValueType.NUMBER&&u.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(o==null?void 0:o.pattern))return(p=this._configService.getConfig(D))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},l(n));let T="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${o==null?void 0:o.pattern}`)return l({...n,...M.result});const y=Y(o==null?void 0:o.pattern,Number(f.v),this.locale);if(T=y.result,!T)return l(n);const b={v:T,t:t.CellValueType.NUMBER};if(y.color){const c=(C=this._themeService.getColorFromTheme(`${y.color}.500`))!=null?C:y.color;c&&(b.interceptorStyle={cl:{rgb:c}})}return i.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${o==null?void 0:o.pattern}`}),Object.assign(n,b),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(o,f)=>{i.realDeleteValue(o,f)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},r.SheetsNumfmtCellContentController=te([R(0,t.IUniverInstanceService),R(1,t.Inject(u.SheetInterceptorService)),R(2,t.Inject(t.ThemeService)),R(3,t.Inject(t.ICommandService)),R(4,t.Inject(u.INumfmtService)),R(5,t.Inject(t.LocaleService)),R(6,t.IConfigService)],r.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var re=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,a,i)=>a in e?re(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,le=(e,a,i,n)=>{for(var s=n>1?void 0:n?ie(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},w=(e,a)=>(i,n)=>a(i,n,e),z=(e,a,i)=>se(e,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,i,n,s){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},Z,this._config);this._configService.setConfig(D,l)}onStarting(){t.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),[x,q,W,K,I].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},z(r.UniverSheetsNumfmtPlugin,"pluginName",ae),z(r.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),w(1,t.Inject(t.Injector)),w(2,t.IConfigService),w(3,t.ICommandService)],r.UniverSheetsNumfmtPlugin);const ce=e=>P.find(i=>e.includes(i)),oe=()=>P.map(e=>({label:e,value:e})),ue=e=>H.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),me=()=>B.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=H,r.DATEFMTLISG=B,r.NUMBERFORMAT=G,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,r.SetCurrencyCommand=W,r.SetNumfmtCommand=I,r.SetPercentCommand=K,r.SubtractDecimalCommand=q,r.currencySymbols=P,r.getCurrencyFormat=A,r.getCurrencyFormatOptions=ue,r.getCurrencyOptions=oe,r.getCurrencySymbolByLocale=F,r.getCurrencySymbolIconByLocale=j,r.getCurrencyType=ce,r.getDateFormatOptions=me,r.getDecimalFromPattern=U,r.getDecimalString=L,r.getNumberFormatOptions=fe,r.getPatternPreview=k,r.getPatternPreviewIgnoreGeneral=Y,r.getPatternType=Q,r.isPatternHasDecimal=J,r.localeCurrencySymbolMap=E,r.setPatternDecimal=$,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -58,16 +58,16 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/engine-formula": "0.13.0",
62
- "@univerjs/sheets": "0.13.0",
63
- "@univerjs/core": "0.13.0"
61
+ "@univerjs/engine-formula": "0.14.0",
62
+ "@univerjs/sheets": "0.14.0",
63
+ "@univerjs/core": "0.14.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "rxjs": "^7.8.2",
67
67
  "typescript": "^5.9.3",
68
68
  "vite": "^7.2.7",
69
69
  "vitest": "^4.0.15",
70
- "@univerjs-infra/shared": "0.13.0"
70
+ "@univerjs-infra/shared": "0.14.0"
71
71
  },
72
72
  "scripts": {
73
73
  "test": "vitest run",