@univerjs/sheets-numfmt 0.8.0-beta.0 → 0.8.0-nightly.202505271607

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Z=Object.defineProperty;var J=(e,r,s)=>r in e?Z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var T=(e,r,s)=>J(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),A=require("@univerjs/engine-numfmt"),N=require("rxjs"),X=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],Q="SHEET_NUMFMT_PLUGIN",E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getInfo(e).maxDecimals)!=null?n:r},ee=(e,r)=>{if(e&&!r||!e&&r)return!1;const s=i=>i.reduce((S,C)=>{if(S.isEnd)return S;const h=C.value||C.num;return C.type==="point"?(S.isEnd=!0,S):{...S,result:S.result+h}},{isEnd:!1,result:""}).result,n=t.numfmt.getInfo(e)._partitions,a=t.numfmt.getInfo(r)._partitions,o=s(n[0].tokens),l=s(a[0].tokens),g=s(n[1].tokens),m=s(a[1].tokens);return o===l&&g===m&&n[1].color===a[1].color},U=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${U(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${U(Number(r||0))}$1`):n).join(";"),te=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:g,worksheet:m}=o,i=r.values.filter(c=>!!c.pattern),S=r.values.filter(c=>!c.pattern),C=f.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:S.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],p=[];if(i.length){const c=i.reduce((d,u)=>{A.isTextFormat(u.pattern)&&d.setValue(u.row,u.col,{t:t.CellValueType.STRING});const b=m.getCellRaw(u.row,u.col);if(b){const $=f.checkCellValueType(b.v);$!==b.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const b=m.getCellRaw(d,u);b?y.setValue(d,u,{t:b.t}):y.setValue(d,u,{t:void 0})}),Object.keys(C.values).forEach(d=>{const u=C.values[d];u.ranges=f.rangeMerge(u.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:C});const _=f.factorySetNumfmtUndoMutation(e,C);p.push(..._)}if(S.length){h.ranges=f.rangeMerge(h.ranges);const c=S.reduce((d,u)=>{const b=m.getCellRaw(u.row,u.col);if(b){const $=f.checkCellValueType(b.v);$!==b.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const b=m.getCellRaw(d,u);b?y.setValue(d,u,{t:b.t}):y.setValue(d,u,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const _=f.factoryRemoveNumfmtUndoMutation(e,h);p.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:y.getMatrix()}},..._)}const v=t.sequenceExecute(M,s).result;return v&&a.pushUndoRedo({unitID:l,undoMutations:p,redoMutations:M}),v}},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:g,subUnitId:m}=l;let i=0;o.forEach(M=>{t.Range.foreach(M.range,(p,v)=>{const c=n.getValue(g,m,p,v);if(!c){const _=l.worksheet.getCellRaw(p,v);if(!i&&_&&_.t===t.CellValueType.NUMBER&&_.v){const d=/\.(\d*)$/.exec(String(_.v));if(d){const u=d[1].length;if(!u)return;i=Math.max(i,u)}}return}const y=E(c.pattern);i=y>i?y:i})});const S=i+1,C=P(`0${S>0?".0":""}`,S),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(p,v)=>{const c=n.getValue(g,m,p,v);if(!c)h.push({row:p,col:v,pattern:C});else{const y=E(c.pattern),_=P(c.pattern,y+1);_!==c.pattern&&h.push({row:p,col:v,pattern:_})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(D),a=L[n.getCurrencySymbol()]||"$",o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=[],g=V[4].suffix(a);return o.forEach(i=>{t.Range.foreach(i.range,(S,C)=>{l.push({row:S,col:C,pattern:g,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},q={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(g=>{t.Range.foreach(g.range,(m,i)=>{a.push({row:m,col:i,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},k={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(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:g,subUnitId:m}=l;let i=0;o.forEach(p=>{t.Range.foreach(p.range,(v,c)=>{const y=n.getValue(g,m,v,c);if(!y){const d=l.worksheet.getCellRaw(v,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const u=/\.(\d*)$/.exec(String(d.v));if(u){const b=u[1].length;if(!b)return;i=Math.max(i,b)}}return}const _=E(y.pattern);i=_>i?_:i})});const S=i-1,C=P(`0${S>0?".0":"."}`,S),h=[];return o.forEach(p=>{t.Range.foreach(p.range,(v,c)=>{const y=n.getValue(g,m,v,c);if(!y)h.push({row:v,col:c,pattern:C});else{const _=E(y.pattern);h.push({row:v,col:c,pattern:P(y.pattern,_-1)})}})}),await r.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",j={},ne=e=>t.numfmt.getInfo(e).type||"unknown",K=(e,r,s="en")=>{const a=t.numfmt.getInfo(e)._partitions[1],o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a.color}:{result:o}},Y=(e,r,s)=>e==="General"?{result:String(X.stripErrorMargin(r))}:K(e,r,s);var re=Object.getOwnPropertyDescriptor,se=(e,r,s,n)=>{for(var a=n>1?void 0:n?re(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},I=(e,r)=>(s,n)=>r(s,n,e);const oe={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,g,m){super();T(this,"_local$",new N.BehaviorSubject("en"));T(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=g,this._configService=m,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var v;const l=a.unitId,g=a.subUnitId;let m;const i=n;if(!i)return o(n);if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(m=c.n)}if(m||(m=this._numfmtService.getValue(l,g,a.row,a.col)),!m||(n.t||f.checkCellValueType(i.v))!==t.CellValueType.NUMBER)return o(n);if(A.isTextFormat(m.pattern))return(v=this._configService.getConfig(w))!=null&&v.disableTextFormatMark?o({...n,t:t.CellValueType.STRING}):o({...n,t:t.CellValueType.STRING,markers:{...n==null?void 0:n.markers,...oe}});let C="";const h=s.getValue(a.row,a.col);if(h&&h.parameters===`${i.v}_${m.pattern}`)return o({...n,...h.result});if(i.v===void 0||i.v===null)return o(n);const M=Y(m.pattern,Number(i.v),this.local);if(C=M.result,!C)return o(n);const p={v:C,t:t.CellValueType.NUMBER};if(M.color){const c=this._themeService.getColorFromTheme(`${M.color}.500`);c&&(p.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:p,parameters:`${i.v}_${m.pattern}`}),o({...n,...p})},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(g=>{t.Range.foreach(g,(m,i)=>{s.realDeleteValue(m,i)})})})}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(N.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=se([I(0,t.IUniverInstanceService),I(1,t.Inject(f.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(f.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);class F extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,ie=(e,r,s)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,le=(e,r,s,n)=>{for(var a=n>1?void 0:n?ce(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)=>ie(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=j,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},j,this._config);this._configService.setConfig(w,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[F]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[F]]),[H,k,W,q,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",Q);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=le([t.DependentOn(f.UniverSheetsPlugin),O(1,t.Inject(t.Injector)),O(2,t.IConfigService),O(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ue=e=>x.find(s=>e.includes(s)),me=()=>x.map(e=>({label:e,value:e})),fe=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),de=()=>G.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=V;exports.DATEFMTLISG=G;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=q;exports.SubtractDecimalCommand=k;exports.countryCurrencyMap=L;exports.currencySymbols=x;exports.getCurrencyFormatOptions=fe;exports.getCurrencyOptions=me;exports.getCurrencyType=ue;exports.getDateFormatOptions=de;exports.getDecimalFromPattern=E;exports.getDecimalString=U;exports.getNumberFormatOptions=ge;exports.getPatternPreview=K;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=ne;exports.isPatternEqualWithoutDecimal=ee;exports.isPatternHasDecimal=te;exports.setPatternDecimal=P;
1
+ "use strict";var Z=Object.defineProperty;var J=(e,r,s)=>r in e?Z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var T=(e,r,s)=>J(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),A=require("@univerjs/engine-numfmt"),N=require("rxjs"),X=require("@univerjs/engine-formula"),U=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],Q="SHEET_NUMFMT_PLUGIN",E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getInfo(e).maxDecimals)!=null?n:r},ee=(e,r)=>{if(e&&!r||!e&&r)return!1;const s=i=>i.reduce((S,C)=>{if(S.isEnd)return S;const h=C.value||C.num;return C.type==="point"?(S.isEnd=!0,S):{...S,result:S.result+h}},{isEnd:!1,result:""}).result,n=t.numfmt.getInfo(e)._partitions,o=t.numfmt.getInfo(r)._partitions,a=s(n[0].tokens),l=s(o[0].tokens),g=s(n[1].tokens),u=s(o[1].tokens);return a===l&&g===u&&n[1].color===o[1].color},x=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${x(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${x(Number(r||0))}$1`):n).join(";"),te=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),o=e.get(t.IUndoRedoService),a=f.getSheetCommandTarget(n,r);if(!a)return!1;const{unitId:l,subUnitId:g,worksheet:u}=a,i=r.values.filter(c=>!!c.pattern),S=r.values.filter(c=>!c.pattern),C=f.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:S.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],p=[];if(i.length){const c=i.reduce((d,m)=>{A.isTextFormat(m.pattern)&&d.setValue(m.row,m.col,{t:t.CellValueType.STRING});const b=u.getCellRaw(m.row,m.col);if(b){const $=f.checkCellValueType(b.v);$!==b.t&&d.setValue(m.row,m.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,m)=>{const b=u.getCellRaw(d,m);b?y.setValue(d,m,{t:b.t}):y.setValue(d,m,{t:void 0})}),Object.keys(C.values).forEach(d=>{const m=C.values[d];m.ranges=f.rangeMerge(m.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:C});const _=f.factorySetNumfmtUndoMutation(e,C);p.push(..._)}if(S.length){h.ranges=f.rangeMerge(h.ranges);const c=S.reduce((d,m)=>{const b=u.getCellRaw(m.row,m.col);if(b){const $=f.checkCellValueType(b.v);$!==b.t&&d.setValue(m.row,m.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,m)=>{const b=u.getCellRaw(d,m);b?y.setValue(d,m,{t:b.t}):y.setValue(d,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const _=f.factoryRemoveNumfmtUndoMutation(e,h);p.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:y.getMatrix()}},..._)}const v=t.sequenceExecute(M,s).result;return v&&o.pushUndoRedo({unitID:l,undoMutations:p,redoMutations:M}),v}},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),o=e.get(t.IUniverInstanceService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const l=f.getSheetCommandTarget(o);if(!l)return!1;const{unitId:g,subUnitId:u}=l;let i=0;a.forEach(M=>{t.Range.foreach(M.range,(p,v)=>{const c=n.getValue(g,u,p,v);if(!c){const _=l.worksheet.getCellRaw(p,v);if(!i&&_&&_.t===t.CellValueType.NUMBER&&_.v){const d=/\.(\d*)$/.exec(String(_.v));if(d){const m=d[1].length;if(!m)return;i=Math.max(i,m)}}return}const y=E(c.pattern);i=y>i?y:i})});const S=i+1,C=P(`0${S>0?".0":""}`,S),h=[];return a.forEach(M=>{t.Range.foreach(M.range,(p,v)=>{const c=n.getValue(g,u,p,v);if(!c)h.push({row:p,col:v,pattern:C});else{const y=E(c.pattern),_=P(c.pattern,y+1);_!==c.pattern&&h.push({row:p,col:v,pattern:_})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(D),o=L[n.getCurrencySymbol()]||"$",a=s.getCurrentSelections();if(!a||!a.length)return!1;const l=[],g=V[4].suffix(o);return a.forEach(i=>{t.Range.foreach(i.range,(S,C)=>{l.push({row:S,col:C,pattern:g,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},q={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const o=[],a="0%";return n.forEach(g=>{t.Range.foreach(g.range,(u,i)=>{o.push({row:u,col:i,pattern:a,type:"percent"})})}),await r.executeCommand(R.id,{values:o})}},k={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),o=e.get(t.IUniverInstanceService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const l=f.getSheetCommandTarget(o);if(!l)return!1;const{unitId:g,subUnitId:u}=l;let i=0;a.forEach(p=>{t.Range.foreach(p.range,(v,c)=>{const y=n.getValue(g,u,v,c);if(!y){const d=l.worksheet.getCellRaw(v,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const m=/\.(\d*)$/.exec(String(d.v));if(m){const b=m[1].length;if(!b)return;i=Math.max(i,b)}}return}const _=E(y.pattern);i=_>i?_:i})});const S=i-1,C=P(`0${S>0?".0":"."}`,S),h=[];return a.forEach(p=>{t.Range.foreach(p.range,(v,c)=>{const y=n.getValue(g,u,v,c);if(!y)h.push({row:v,col:c,pattern:C});else{const _=E(y.pattern);h.push({row:v,col:c,pattern:P(y.pattern,_-1)})}})}),await r.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",j={},ne=e=>t.numfmt.getInfo(e).type||"unknown",K=(e,r,s="en")=>{const o=t.numfmt.getInfo(e)._partitions[1],a=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:a,color:o.color}:{result:a}},Y=(e,r,s)=>e==="General"?{result:String(X.stripErrorMargin(r))}:K(e,r,s);var re=Object.getOwnPropertyDescriptor,se=(e,r,s,n)=>{for(var o=n>1?void 0:n?re(r,s):r,a=e.length-1,l;a>=0;a--)(l=e[a])&&(o=l(o)||o);return o},I=(e,r)=>(s,n)=>r(s,n,e);const oe={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,o,a,l,g,u){super();T(this,"_local$",new N.BehaviorSubject("en"));T(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=o,this._commandService=a,this._numfmtService=l,this._localeService=g,this._configService=u,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,o,a)=>{var v;const l=o.unitId,g=o.subUnitId;let u;const i=n;if(!i||i.v===void 0||i.v===null)return a(n);if(n!=null&&n.s){const c=o.workbook.getStyles().get(n.s);c!=null&&c.n&&(u=c.n)}if(u||(u=this._numfmtService.getValue(l,g,o.row,o.col)),!u||u.pattern==="General"||f.checkCellValueType(i.v)!==t.CellValueType.NUMBER)return a(n);if((!n||n===o.rawData)&&(n={...o.rawData}),A.isTextFormat(u.pattern))return(v=this._configService.getConfig(w))!=null&&v.disableTextFormatMark?(n.t=t.CellValueType.STRING,a(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...oe},a(n));let C="";const h=s.getValue(o.row,o.col);if(h&&h.parameters===`${i.v}_${u.pattern}`)return a({...n,...h.result});const M=Y(u.pattern,Number(i.v),this.local);if(C=M.result,!C)return a(n);const p={v:C,t:t.CellValueType.NUMBER};if(M.color){const c=this._themeService.getColorFromTheme(`${M.color}.500`);c&&(p.interceptorStyle={cl:{rgb:c}})}return s.setValue(o.row,o.col,{result:p,parameters:`${i.v}_${u.pattern}`}),Object.assign(n,p),a(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const o=n.params;Object.keys(o.values).forEach(a=>{o.values[a].ranges.forEach(g=>{t.Range.foreach(g,(u,i)=>{s.realDeleteValue(u,i)})})})}else if(n.id===f.SetRangeValuesMutation.id){const o=n.params;new t.ObjectMatrix(o.cellValue).forValue((a,l)=>{s.realDeleteValue(a,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var o;return(o=n==null?void 0:n.activeSheet$)!=null?o:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=se([I(0,t.IUniverInstanceService),I(1,t.Inject(f.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(f.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);class F extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,ie=(e,r,s)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,le=(e,r,s,n)=>{for(var o=n>1?void 0:n?ce(r,s):r,a=e.length-1,l;a>=0;a--)(l=e[a])&&(o=l(o)||o);return o},O=(e,r)=>(s,n)=>r(s,n,e),z=(e,r,s)=>ie(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=j,s,n,o){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=o;const{...a}=t.merge({},j,this._config);this._configService.setConfig(w,a)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[F]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[F]]),[H,k,W,q,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",Q);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=le([t.DependentOn(f.UniverSheetsPlugin),O(1,t.Inject(t.Injector)),O(2,t.IConfigService),O(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ue=e=>U.find(s=>e.includes(s)),me=()=>U.map(e=>({label:e,value:e})),fe=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),de=()=>G.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=V;exports.DATEFMTLISG=G;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=q;exports.SubtractDecimalCommand=k;exports.countryCurrencyMap=L;exports.currencySymbols=U;exports.getCurrencyFormatOptions=fe;exports.getCurrencyOptions=me;exports.getCurrencyType=ue;exports.getDateFormatOptions=de;exports.getDecimalFromPattern=E;exports.getDecimalString=x;exports.getNumberFormatOptions=ge;exports.getPatternPreview=K;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=ne;exports.isPatternEqualWithoutDecimal=ee;exports.isPatternHasDecimal=te;exports.setPatternDecimal=P;
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
- var ae = Object.defineProperty;
2
- var le = (e, t, n) => t in e ? ae(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
1
+ var ce = Object.defineProperty;
2
+ var le = (e, t, n) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var M = (e, t, n) => le(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { numfmt as x, CommandType as P, ICommandService as E, IUniverInstanceService as F, IUndoRedoService as ue, CellValueType as I, ObjectMatrix as b, sequenceExecute as me, Range as N, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as K, UniverInstanceType as ee, DependentOn as ge, Injector as he, Plugin as ve, merge as pe, registerDependencies as Se, touchDependencies as z } from "@univerjs/core";
4
+ import { numfmt as x, CommandType as w, ICommandService as E, IUniverInstanceService as F, IUndoRedoService as ue, CellValueType as I, ObjectMatrix as b, sequenceExecute as me, Range as N, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as K, UniverInstanceType as ee, DependentOn as ge, Injector as he, Plugin as pe, merge as ve, registerDependencies as Se, touchDependencies as z } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as Y, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ie } from "@univerjs/sheets";
6
6
  import { isTextFormat as ne } from "@univerjs/engine-numfmt";
7
7
  import { BehaviorSubject as k, merge as Ne, switchMap as Ee, of as Te, skip as xe } from "rxjs";
@@ -34,7 +34,7 @@ const re = [
34
34
  "₽",
35
35
  "₾",
36
36
  "₿"
37
- ], Pe = {
37
+ ], we = {
38
38
  US: "$",
39
39
  // United States Dollar
40
40
  CA: "C$",
@@ -74,7 +74,7 @@ const re = [
74
74
  SI: "€",
75
75
  ES: "€"
76
76
  // Add more mappings as needed
77
- }, Ue = [
77
+ }, Pe = [
78
78
  {
79
79
  label: "1930-08-05",
80
80
  suffix: "yyyy-MM-dd"
@@ -119,7 +119,7 @@ const re = [
119
119
  label: "08-05 下午 01:30",
120
120
  suffix: "MM-dd A/P hh:mm"
121
121
  }
122
- ], we = [
122
+ ], Ue = [
123
123
  {
124
124
  label: "(1,235)",
125
125
  suffix: "#,##0_);(#,##0)"
@@ -175,39 +175,39 @@ const re = [
175
175
  suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
176
176
  color: "red"
177
177
  }
178
- ], Oe = "SHEET_NUMFMT_PLUGIN", w = (e, t = 0) => {
178
+ ], Oe = "SHEET_NUMFMT_PLUGIN", U = (e, t = 0) => {
179
179
  var r;
180
180
  return e && (r = x.getInfo(e).maxDecimals) != null ? r : t;
181
181
  }, tt = (e, t) => {
182
182
  if (e && !t || !e && t)
183
183
  return !1;
184
184
  const n = (u) => u.reduce(
185
- (g, v) => {
185
+ (g, p) => {
186
186
  if (g.isEnd)
187
187
  return g;
188
- const h = v.value || v.num;
189
- return v.type === "point" ? (g.isEnd = !0, g) : { ...g, result: g.result + h };
188
+ const h = p.value || p.num;
189
+ return p.type === "point" ? (g.isEnd = !0, g) : { ...g, result: g.result + h };
190
190
  },
191
191
  { isEnd: !1, result: "" }
192
- ).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens), c = n(s[0].tokens), i = n(r[1].tokens), m = n(s[1].tokens);
193
- return o === c && i === m && r[1].color === s[1].color;
192
+ ).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens), a = n(s[0].tokens), i = n(r[1].tokens), m = n(s[1].tokens);
193
+ return o === a && i === m && r[1].color === s[1].color;
194
194
  }, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), O = (e, t) => e.split(";").map((r) => /\.0?/.test(r) ? r.replace(
195
195
  /\.0*/g,
196
196
  `${t > 0 ? "." : ""}${q(Number(t || 0))}`
197
197
  ) : /0([^0]?)|0$/.test(r) ? r.replace(
198
198
  /0([^0]+)|0$/,
199
199
  `0${t > 0 ? "." : ""}${q(Number(t || 0))}$1`
200
- ) : r).join(";"), nt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), U = {
200
+ ) : r).join(";"), nt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), P = {
201
201
  id: "sheet.command.numfmt.set.numfmt",
202
- type: P.COMMAND,
202
+ type: w.COMMAND,
203
203
  // eslint-disable-next-line max-lines-per-function
204
204
  handler: (e, t) => {
205
205
  if (!t)
206
206
  return !1;
207
207
  const n = e.get(E), r = e.get(F), s = e.get(ue), o = H(r, t);
208
208
  if (!o) return !1;
209
- const { unitId: c, subUnitId: i, worksheet: m } = o, u = t.values.filter((l) => !!l.pattern), g = t.values.filter((l) => !l.pattern), v = ye(c, i, u), h = {
210
- unitId: c,
209
+ const { unitId: a, subUnitId: i, worksheet: m } = o, u = t.values.filter((l) => !!l.pattern), g = t.values.filter((l) => !l.pattern), p = ye(a, i, u), h = {
210
+ unitId: a,
211
211
  subUnitId: i,
212
212
  ranges: g.map((l) => ({
213
213
  startColumn: l.col,
@@ -217,48 +217,48 @@ const re = [
217
217
  }))
218
218
  }, C = [], S = [];
219
219
  if (u.length) {
220
- const l = u.reduce((d, a) => {
221
- ne(a.pattern) && d.setValue(a.row, a.col, { t: I.STRING });
222
- const _ = m.getCellRaw(a.row, a.col);
220
+ const l = u.reduce((d, c) => {
221
+ ne(c.pattern) && d.setValue(c.row, c.col, { t: I.STRING });
222
+ const _ = m.getCellRaw(c.row, c.col);
223
223
  if (_) {
224
224
  const V = G(_.v);
225
- V !== _.t && d.setValue(a.row, a.col, { t: V });
225
+ V !== _.t && d.setValue(c.row, c.col, { t: V });
226
226
  }
227
227
  return d;
228
- }, new b()).getMatrix(), p = new b();
229
- new b(l).forValue((d, a) => {
230
- const _ = m.getCellRaw(d, a);
231
- _ ? p.setValue(d, a, { t: _.t }) : p.setValue(d, a, { t: void 0 });
232
- }), Object.keys(v.values).forEach((d) => {
233
- const a = v.values[d];
234
- a.ranges = Y(a.ranges);
228
+ }, new b()).getMatrix(), v = new b();
229
+ new b(l).forValue((d, c) => {
230
+ const _ = m.getCellRaw(d, c);
231
+ _ ? v.setValue(d, c, { t: _.t }) : v.setValue(d, c, { t: void 0 });
232
+ }), Object.keys(p.values).forEach((d) => {
233
+ const c = p.values[d];
234
+ c.ranges = Y(c.ranges);
235
235
  }), C.push({
236
236
  id: te.id,
237
- params: v
237
+ params: p
238
238
  });
239
- const y = _e(e, v);
239
+ const y = _e(e, p);
240
240
  S.push(...y);
241
241
  }
242
242
  if (g.length) {
243
243
  h.ranges = Y(h.ranges);
244
- const l = g.reduce((d, a) => {
245
- const _ = m.getCellRaw(a.row, a.col);
244
+ const l = g.reduce((d, c) => {
245
+ const _ = m.getCellRaw(c.row, c.col);
246
246
  if (_) {
247
247
  const V = G(_.v);
248
- V !== _.t && d.setValue(a.row, a.col, { t: V });
248
+ V !== _.t && d.setValue(c.row, c.col, { t: V });
249
249
  }
250
250
  return d;
251
- }, new b()).getMatrix(), p = new b();
252
- new b(l).forValue((d, a) => {
253
- const _ = m.getCellRaw(d, a);
254
- _ ? p.setValue(d, a, { t: _.t }) : p.setValue(d, a, { t: void 0 });
251
+ }, new b()).getMatrix(), v = new b();
252
+ new b(l).forValue((d, c) => {
253
+ const _ = m.getCellRaw(d, c);
254
+ _ ? v.setValue(d, c, { t: _.t }) : v.setValue(d, c, { t: void 0 });
255
255
  }), C.push({
256
256
  id: Ce.id,
257
257
  params: h
258
258
  }, {
259
259
  id: B.id,
260
260
  params: {
261
- unitId: c,
261
+ unitId: a,
262
262
  subUnitId: i,
263
263
  cellValue: l
264
264
  }
@@ -267,51 +267,51 @@ const re = [
267
267
  S.push({
268
268
  id: B.id,
269
269
  params: {
270
- unitId: c,
270
+ unitId: a,
271
271
  subUnitId: i,
272
- cellValue: p.getMatrix()
272
+ cellValue: v.getMatrix()
273
273
  }
274
274
  }, ...y);
275
275
  }
276
276
  const f = me(C, n).result;
277
277
  return f && s.pushUndoRedo({
278
- unitID: c,
278
+ unitID: a,
279
279
  undoMutations: S,
280
280
  redoMutations: C
281
281
  }), f;
282
282
  }
283
283
  }, De = {
284
284
  id: "sheet.command.numfmt.add.decimal.command",
285
- type: P.COMMAND,
285
+ type: w.COMMAND,
286
286
  handler: async (e) => {
287
287
  const t = e.get(E), n = e.get(j), r = e.get(W), s = e.get(F), o = n.getCurrentSelections();
288
288
  if (!o || !o.length)
289
289
  return !1;
290
- const c = H(s);
291
- if (!c) return !1;
292
- const { unitId: i, subUnitId: m } = c;
290
+ const a = H(s);
291
+ if (!a) return !1;
292
+ const { unitId: i, subUnitId: m } = a;
293
293
  let u = 0;
294
294
  o.forEach((C) => {
295
295
  N.foreach(C.range, (S, f) => {
296
296
  const l = r.getValue(i, m, S, f);
297
297
  if (!l) {
298
- const y = c.worksheet.getCellRaw(S, f);
298
+ const y = a.worksheet.getCellRaw(S, f);
299
299
  if (!u && y && y.t === I.NUMBER && y.v) {
300
300
  const d = /\.(\d*)$/.exec(String(y.v));
301
301
  if (d) {
302
- const a = d[1].length;
303
- if (!a)
302
+ const c = d[1].length;
303
+ if (!c)
304
304
  return;
305
- u = Math.max(u, a);
305
+ u = Math.max(u, c);
306
306
  }
307
307
  }
308
308
  return;
309
309
  }
310
- const p = w(l.pattern);
311
- u = p > u ? p : u;
310
+ const v = U(l.pattern);
311
+ u = v > u ? v : u;
312
312
  });
313
313
  });
314
- const g = u + 1, v = O(`0${g > 0 ? ".0" : ""}`, g), h = [];
314
+ const g = u + 1, p = O(`0${g > 0 ? ".0" : ""}`, g), h = [];
315
315
  return o.forEach((C) => {
316
316
  N.foreach(C.range, (S, f) => {
317
317
  const l = r.getValue(i, m, S, f);
@@ -319,10 +319,10 @@ const re = [
319
319
  h.push({
320
320
  row: S,
321
321
  col: f,
322
- pattern: v
322
+ pattern: p
323
323
  });
324
324
  else {
325
- const p = w(l.pattern), y = O(l.pattern, p + 1);
325
+ const v = U(l.pattern), y = O(l.pattern, v + 1);
326
326
  y !== l.pattern && h.push({
327
327
  row: S,
328
328
  col: f,
@@ -330,7 +330,7 @@ const re = [
330
330
  });
331
331
  }
332
332
  });
333
- }), h.length ? await t.executeCommand(U.id, { values: h }) : !1;
333
+ }), h.length ? await t.executeCommand(P.id, { values: h }) : !1;
334
334
  }
335
335
  };
336
336
  class oe {
@@ -350,21 +350,21 @@ class oe {
350
350
  }
351
351
  const Ae = {
352
352
  id: "sheet.command.numfmt.set.currency",
353
- type: P.COMMAND,
353
+ type: w.COMMAND,
354
354
  handler: async (e) => {
355
- const t = e.get(E), n = e.get(j), r = e.get(oe), s = Pe[r.getCurrencySymbol()] || "$", o = n.getCurrentSelections();
355
+ const t = e.get(E), n = e.get(j), r = e.get(oe), s = we[r.getCurrencySymbol()] || "$", o = n.getCurrentSelections();
356
356
  if (!o || !o.length)
357
357
  return !1;
358
- const c = [], i = se[4].suffix(s);
358
+ const a = [], i = se[4].suffix(s);
359
359
  return o.forEach((u) => {
360
- N.foreach(u.range, (g, v) => {
361
- c.push({ row: g, col: v, pattern: i, type: "currency" });
360
+ N.foreach(u.range, (g, p) => {
361
+ a.push({ row: g, col: p, pattern: i, type: "currency" });
362
362
  });
363
- }), await t.executeCommand(U.id, { values: c });
363
+ }), await t.executeCommand(P.id, { values: a });
364
364
  }
365
365
  }, Fe = {
366
366
  id: "sheet.command.numfmt.set.percent",
367
- type: P.COMMAND,
367
+ type: w.COMMAND,
368
368
  handler: async (e) => {
369
369
  const t = e.get(E), r = e.get(j).getCurrentSelections();
370
370
  if (!r || !r.length)
@@ -374,28 +374,28 @@ const Ae = {
374
374
  N.foreach(i.range, (m, u) => {
375
375
  s.push({ row: m, col: u, pattern: o, type: "percent" });
376
376
  });
377
- }), await t.executeCommand(U.id, { values: s });
377
+ }), await t.executeCommand(P.id, { values: s });
378
378
  }
379
379
  }, je = {
380
380
  id: "sheet.command.numfmt.subtract.decimal.command",
381
- type: P.COMMAND,
381
+ type: w.COMMAND,
382
382
  handler: async (e) => {
383
383
  const t = e.get(E), n = e.get(j), r = e.get(W), s = e.get(F), o = n.getCurrentSelections();
384
384
  if (!o || !o.length)
385
385
  return !1;
386
- const c = H(s);
387
- if (!c) return !1;
388
- const { unitId: i, subUnitId: m } = c;
386
+ const a = H(s);
387
+ if (!a) return !1;
388
+ const { unitId: i, subUnitId: m } = a;
389
389
  let u = 0;
390
390
  o.forEach((S) => {
391
391
  N.foreach(S.range, (f, l) => {
392
- const p = r.getValue(i, m, f, l);
393
- if (!p) {
394
- const d = c.worksheet.getCellRaw(f, l);
392
+ const v = r.getValue(i, m, f, l);
393
+ if (!v) {
394
+ const d = a.worksheet.getCellRaw(f, l);
395
395
  if (!u && d && d.t === I.NUMBER && d.v) {
396
- const a = /\.(\d*)$/.exec(String(d.v));
397
- if (a) {
398
- const _ = a[1].length;
396
+ const c = /\.(\d*)$/.exec(String(d.v));
397
+ if (c) {
398
+ const _ = c[1].length;
399
399
  if (!_)
400
400
  return;
401
401
  u = Math.max(u, _);
@@ -403,32 +403,32 @@ const Ae = {
403
403
  }
404
404
  return;
405
405
  }
406
- const y = w(p.pattern);
406
+ const y = U(v.pattern);
407
407
  u = y > u ? y : u;
408
408
  });
409
409
  });
410
- const g = u - 1, v = O(`0${g > 0 ? ".0" : "."}`, g), h = [];
410
+ const g = u - 1, p = O(`0${g > 0 ? ".0" : "."}`, g), h = [];
411
411
  return o.forEach((S) => {
412
412
  N.foreach(S.range, (f, l) => {
413
- const p = r.getValue(i, m, f, l);
414
- if (!p)
413
+ const v = r.getValue(i, m, f, l);
414
+ if (!v)
415
415
  h.push({
416
416
  row: f,
417
417
  col: l,
418
- pattern: v
418
+ pattern: p
419
419
  });
420
420
  else {
421
- const y = w(p.pattern);
421
+ const y = U(v.pattern);
422
422
  h.push({
423
423
  row: f,
424
424
  col: l,
425
- pattern: O(p.pattern, y - 1)
425
+ pattern: O(v.pattern, y - 1)
426
426
  });
427
427
  }
428
428
  });
429
- }), await t.executeCommand(U.id, { values: h });
429
+ }), await t.executeCommand(P.id, { values: h });
430
430
  }
431
- }, ce = "sheets-numfmt.config", Z = {}, rt = (e) => x.getInfo(e).type || "unknown", Le = (e, t, n = "en") => {
431
+ }, ae = "sheets-numfmt.config", Z = {}, rt = (e) => x.getInfo(e).type || "unknown", Le = (e, t, n = "en") => {
432
432
  const s = x.getInfo(e)._partitions[1], o = x.format(e, t, { locale: n, throws: !1 });
433
433
  return t < 0 ? {
434
434
  result: o,
@@ -441,8 +441,8 @@ const Ae = {
441
441
  // In Excel, the default General format also needs to handle numeric precision.
442
442
  } : Le(e, t, n);
443
443
  var Be = Object.getOwnPropertyDescriptor, He = (e, t, n, r) => {
444
- for (var s = r > 1 ? void 0 : r ? Be(t, n) : t, o = e.length - 1, c; o >= 0; o--)
445
- (c = e[o]) && (s = c(s) || s);
444
+ for (var s = r > 1 ? void 0 : r ? Be(t, n) : t, o = e.length - 1, a; o >= 0; o--)
445
+ (a = e[o]) && (s = a(s) || s);
446
446
  return s;
447
447
  }, R = (e, t) => (n, r) => t(n, r, e);
448
448
  const We = {
@@ -452,11 +452,11 @@ const We = {
452
452
  }
453
453
  };
454
454
  let D = class extends Q {
455
- constructor(t, n, r, s, o, c, i) {
455
+ constructor(t, n, r, s, o, a, i) {
456
456
  super();
457
457
  M(this, "_local$", new k("en"));
458
458
  M(this, "local$", this._local$.asObservable());
459
- this._instanceService = t, this._sheetInterceptorService = n, this._themeService = r, this._commandService = s, this._numfmtService = o, this._localeService = c, this._configService = i, this._initInterceptorCellContent();
459
+ this._instanceService = t, this._sheetInterceptorService = n, this._themeService = r, this._commandService = s, this._numfmtService = o, this._localeService = a, this._configService = i, this._initInterceptorCellContent();
460
460
  }
461
461
  get local() {
462
462
  const t = this._local$.getValue();
@@ -489,35 +489,23 @@ let D = class extends Q {
489
489
  // eslint-disable-next-line complexity
490
490
  handler: (n, r, s) => {
491
491
  var S;
492
- const o = r.unitId, c = r.subUnitId;
492
+ const o = r.unitId, a = r.subUnitId;
493
493
  let i;
494
494
  const m = n;
495
- if (!m)
495
+ if (!m || m.v === void 0 || m.v === null)
496
496
  return s(n);
497
497
  if (n != null && n.s) {
498
498
  const f = r.workbook.getStyles().get(n.s);
499
499
  f != null && f.n && (i = f.n);
500
500
  }
501
- if (i || (i = this._numfmtService.getValue(o, c, r.row, r.col)), !i || (n.t || G(m.v)) !== I.NUMBER)
501
+ if (i || (i = this._numfmtService.getValue(o, a, r.row, r.col)), !i || i.pattern === "General" || G(m.v) !== I.NUMBER)
502
502
  return s(n);
503
- if (ne(i.pattern))
504
- return (S = this._configService.getConfig(ce)) != null && S.disableTextFormatMark ? s({
505
- ...n,
506
- t: I.STRING
507
- }) : s({
508
- ...n,
509
- t: I.STRING,
510
- markers: {
511
- ...n == null ? void 0 : n.markers,
512
- ...We
513
- }
514
- });
503
+ if ((!n || n === r.rawData) && (n = { ...r.rawData }), ne(i.pattern))
504
+ return (S = this._configService.getConfig(ae)) != null && S.disableTextFormatMark ? (n.t = I.STRING, s(n)) : (n.t = I.STRING, n.markers = { ...n == null ? void 0 : n.markers, ...We }, s(n));
515
505
  let g = "";
516
- const v = t.getValue(r.row, r.col);
517
- if (v && v.parameters === `${m.v}_${i.pattern}`)
518
- return s({ ...n, ...v.result });
519
- if (m.v === void 0 || m.v === null)
520
- return s(n);
506
+ const p = t.getValue(r.row, r.col);
507
+ if (p && p.parameters === `${m.v}_${i.pattern}`)
508
+ return s({ ...n, ...p.result });
521
509
  const h = Ge(i.pattern, Number(m.v), this.local);
522
510
  if (g = h.result, !g)
523
511
  return s(n);
@@ -529,15 +517,15 @@ let D = class extends Q {
529
517
  return t.setValue(r.row, r.col, {
530
518
  result: C,
531
519
  parameters: `${m.v}_${i.pattern}`
532
- }), s({ ...n, ...C });
520
+ }), Object.assign(n, C), s(n);
533
521
  },
534
522
  priority: Re.NUMFMT
535
523
  })), this.disposeWithMe(this._commandService.onCommandExecuted((n) => {
536
524
  if (n.id === te.id) {
537
525
  const r = n.params;
538
526
  Object.keys(r.values).forEach((s) => {
539
- r.values[s].ranges.forEach((c) => {
540
- N.foreach(c, (i, m) => {
527
+ r.values[s].ranges.forEach((a) => {
528
+ N.foreach(a, (i, m) => {
541
529
  t.realDeleteValue(i, m);
542
530
  });
543
531
  });
@@ -588,19 +576,19 @@ class J extends Q {
588
576
  }
589
577
  }
590
578
  var ke = Object.defineProperty, Ke = Object.getOwnPropertyDescriptor, ze = (e, t, n) => t in e ? ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, Ye = (e, t, n, r) => {
591
- for (var s = r > 1 ? void 0 : r ? Ke(t, n) : t, o = e.length - 1, c; o >= 0; o--)
592
- (c = e[o]) && (s = c(s) || s);
579
+ for (var s = r > 1 ? void 0 : r ? Ke(t, n) : t, o = e.length - 1, a; o >= 0; o--)
580
+ (a = e[o]) && (s = a(s) || s);
593
581
  return s;
594
582
  }, L = (e, t) => (n, r) => t(n, r, e), ie = (e, t, n) => ze(e, typeof t != "symbol" ? t + "" : t, n);
595
- let A = class extends ve {
583
+ let A = class extends pe {
596
584
  constructor(e = Z, t, n, r) {
597
585
  super(), this._config = e, this._injector = t, this._configService = n, this._commandService = r;
598
- const { ...s } = pe(
586
+ const { ...s } = ve(
599
587
  {},
600
588
  Z,
601
589
  this._config
602
590
  );
603
- this._configService.setConfig(ce, s);
591
+ this._configService.setConfig(ae, s);
604
592
  }
605
593
  onStarting() {
606
594
  Se(this._injector, [
@@ -619,7 +607,7 @@ let A = class extends ve {
619
607
  je,
620
608
  Ae,
621
609
  Fe,
622
- U
610
+ P
623
611
  ].forEach((e) => {
624
612
  this.disposeWithMe(this._commandService.registerCommand(e));
625
613
  });
@@ -633,33 +621,33 @@ A = Ye([
633
621
  L(2, X),
634
622
  L(3, E)
635
623
  ], A);
636
- const st = (e) => re.find((n) => e.includes(n)), ot = () => re.map((e) => ({ label: e, value: e })), ct = (e) => se.map((t) => ({
624
+ const st = (e) => re.find((n) => e.includes(n)), ot = () => re.map((e) => ({ label: e, value: e })), at = (e) => se.map((t) => ({
637
625
  label: t.label(e),
638
626
  value: t.suffix(e),
639
627
  color: t.color
640
- })), it = () => Ue.map((e) => ({ label: e.label, value: e.suffix })), at = () => we.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
628
+ })), it = () => Pe.map((e) => ({ label: e.label, value: e.suffix })), ct = () => Ue.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
641
629
  export {
642
630
  De as AddDecimalCommand,
643
631
  se as CURRENCYFORMAT,
644
- Ue as DATEFMTLISG,
632
+ Pe as DATEFMTLISG,
645
633
  oe as MenuCurrencyService,
646
- we as NUMBERFORMAT,
647
- ce as SHEETS_NUMFMT_PLUGIN_CONFIG_KEY,
634
+ Ue as NUMBERFORMAT,
635
+ ae as SHEETS_NUMFMT_PLUGIN_CONFIG_KEY,
648
636
  Ae as SetCurrencyCommand,
649
- U as SetNumfmtCommand,
637
+ P as SetNumfmtCommand,
650
638
  Fe as SetPercentCommand,
651
639
  D as SheetsNumfmtCellContentController,
652
640
  je as SubtractDecimalCommand,
653
641
  A as UniverSheetsNumfmtPlugin,
654
- Pe as countryCurrencyMap,
642
+ we as countryCurrencyMap,
655
643
  re as currencySymbols,
656
- ct as getCurrencyFormatOptions,
644
+ at as getCurrencyFormatOptions,
657
645
  ot as getCurrencyOptions,
658
646
  st as getCurrencyType,
659
647
  it as getDateFormatOptions,
660
- w as getDecimalFromPattern,
648
+ U as getDecimalFromPattern,
661
649
  q as getDecimalString,
662
- at as getNumberFormatOptions,
650
+ ct as getNumberFormatOptions,
663
651
  Le as getPatternPreview,
664
652
  Ge as getPatternPreviewIgnoreGeneral,
665
653
  rt as getPatternType,