@univerjs/sheets-numfmt 0.8.0-nightly.202506081606 → 0.8.0-nightly.202506101607

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Z=Object.defineProperty;var J=(e,r,s)=>r in e?Z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var T=(e,r,s)=>J(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),m=require("@univerjs/sheets"),A=require("@univerjs/engine-numfmt"),N=require("rxjs"),X=require("@univerjs/engine-formula"),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.getFormatInfo(e).maxDecimals)!=null?n:r},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(";"),ee=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=m.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:S,worksheet:f}=o,c=r.values.filter(i=>!!i.pattern),M=r.values.filter(i=>!i.pattern),_=m.transformCellsToRange(l,S,c),v={unitId:l,subUnitId:S,ranges:M.map(i=>({startColumn:i.col,startRow:i.row,endColumn:i.col,endRow:i.row}))},b=[],C=[];if(c.length){const i=c.reduce((g,u)=>{A.isTextFormat(u.pattern)&&g.setValue(u.row,u.col,{t:t.CellValueType.STRING});const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&g.setValue(u.row,u.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),d=new t.ObjectMatrix;new t.ObjectMatrix(i).forValue((g,u)=>{const y=f.getCellRaw(g,u);y?d.setValue(g,u,{t:y.t}):d.setValue(g,u,{t:void 0})}),Object.keys(_.values).forEach(g=>{const u=_.values[g];u.ranges=m.rangeMerge(u.ranges)}),b.push({id:m.SetNumfmtMutation.id,params:_});const p=m.factorySetNumfmtUndoMutation(e,_);C.push(...p)}if(M.length){v.ranges=m.rangeMerge(v.ranges);const i=M.reduce((g,u)=>{const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&g.setValue(u.row,u.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),d=new t.ObjectMatrix;new t.ObjectMatrix(i).forValue((g,u)=>{const y=f.getCellRaw(g,u);y?d.setValue(g,u,{t:y.t}):d.setValue(g,u,{t:void 0})}),b.push({id:m.RemoveNumfmtMutation.id,params:v},{id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:S,cellValue:i}});const p=m.factoryRemoveNumfmtUndoMutation(e,v);C.push({id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:S,cellValue:d.getMatrix()}},...p)}const h=t.sequenceExecute(b,s).result;return h&&a.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:b}),h}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:S,subUnitId:f}=l;let c=0;o.forEach(b=>{t.Range.foreach(b.range,(C,h)=>{const i=n.getValue(S,f,C,h);if(!i){const p=l.worksheet.getCellRaw(C,h);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const g=/\.(\d*)$/.exec(String(p.v));if(g){const u=g[1].length;if(!u)return;c=Math.max(c,u)}}return}const d=E(i.pattern);c=d>c?d:c})});const M=c+1,_=P(`0${M>0?".0":""}`,M),v=[];return o.forEach(b=>{t.Range.foreach(b.range,(C,h)=>{const i=n.getValue(S,f,C,h);if(!i)v.push({row:C,col:h,pattern:_});else{const d=E(i.pattern),p=P(i.pattern,d+1);p!==i.pattern&&v.push({row:C,col:h,pattern:p})}})}),v.length?await r.executeCommand(R.id,{values:v}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(D),a=L[n.getCurrencySymbol()]||"$",o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=[],S=V[4].suffix(a);return o.forEach(c=>{t.Range.foreach(c.range,(M,_)=>{l.push({row:M,col:_,pattern:S,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},q={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(S=>{t.Range.foreach(S.range,(f,c)=>{a.push({row:f,col:c,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},K={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:S,subUnitId:f}=l;let c=0;o.forEach(C=>{t.Range.foreach(C.range,(h,i)=>{const d=n.getValue(S,f,h,i);if(!d){const g=l.worksheet.getCellRaw(h,i);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const u=/\.(\d*)$/.exec(String(g.v));if(u){const y=u[1].length;if(!y)return;c=Math.max(c,y)}}return}const p=E(d.pattern);c=p>c?p:c})});const M=c-1,_=P(`0${M>0?".0":"."}`,M),v=[];return o.forEach(C=>{t.Range.foreach(C.range,(h,i)=>{const d=n.getValue(S,f,h,i);if(!d)v.push({row:h,col:i,pattern:_});else{const p=E(d.pattern);v.push({row:h,col:i,pattern:P(d.pattern,p-1)})}})}),await r.executeCommand(R.id,{values:v})}},w="sheets-numfmt.config",F={},te=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,s="en")=>{const n=String(t.numfmt.formatColor(e,r)),a=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:a,color:n}:{result:a}},k=(e,r,s)=>e==="General"?{result:String(X.stripErrorMargin(r))}:Y(e,r,s);var ne=Object.getOwnPropertyDescriptor,re=(e,r,s,n)=>{for(var a=n>1?void 0:n?ne(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 se={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,S,f){super();T(this,"_local$",new N.BehaviorSubject("en"));T(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=S,this._configService=f,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var h,i;const l=a.unitId,S=a.subUnitId;let f;const c=n;if(!c||c.v===void 0||c.v===null)return o(n);if(n!=null&&n.s){const d=a.workbook.getStyles().get(n.s);d!=null&&d.n&&(f=d.n)}if(f||(f=this._numfmtService.getValue(l,S,a.row,a.col)),!f||f.pattern==="General"||m.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return o(n);if((!n||n===a.rawData)&&(n={...a.rawData}),A.isTextFormat(f.pattern))return(h=this._configService.getConfig(w))!=null&&h.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...se},o(n));let _="";const v=s.getValue(a.row,a.col);if(v&&v.parameters===`${c.v}_${f.pattern}`)return o({...n,...v.result});const b=k(f.pattern,Number(c.v),this.local);if(_=b.result,!_)return o(n);const C={v:_,t:t.CellValueType.NUMBER};if(b.color){const d=(i=this._themeService.getColorFromTheme(`${b.color}.500`))!=null?i:b.color;d&&(C.interceptorStyle={cl:{rgb:d}})}return s.setValue(a.row,a.col,{result:C,parameters:`${c.v}_${f.pattern}`}),Object.assign(n,C),o(n)},priority:m.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===m.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(S=>{t.Range.foreach(S,(f,c)=>{s.realDeleteValue(f,c)})})})}else if(n.id===m.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=re([I(0,t.IUniverInstanceService),I(1,t.Inject(m.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(m.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);class j extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,s)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,ie=(e,r,s,n)=>{for(var a=n>1?void 0:n?oe(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},O=(e,r)=>(s,n)=>r(s,n,e),z=(e,r,s)=>ce(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=F,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},F,this._config);this._configService.setConfig(w,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[j]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[j]]),[H,K,W,q,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",Q);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(m.UniverSheetsPlugin),O(1,t.Inject(t.Injector)),O(2,t.IConfigService),O(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>U.find(s=>e.includes(s)),ue=()=>U.map(e=>({label:e,value:e})),me=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>G.map(e=>({label:e.label,value:e.suffix})),de=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=G;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=q;exports.SubtractDecimalCommand=K;exports.countryCurrencyMap=L;exports.currencySymbols=U;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=E;exports.getDecimalString=x;exports.getNumberFormatOptions=de;exports.getPatternPreview=Y;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=te;exports.isPatternHasDecimal=ee;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"),m=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.getFormatInfo(e).maxDecimals)!=null?n:r},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(";"),ee=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=m.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:S,worksheet:f}=o,c=r.values.filter(i=>!!i.pattern),M=r.values.filter(i=>!i.pattern),_=m.transformCellsToRange(l,S,c),v={unitId:l,subUnitId:S,ranges:M.map(i=>({startColumn:i.col,startRow:i.row,endColumn:i.col,endRow:i.row}))},b=[],C=[];if(c.length){const i=c.reduce((g,u)=>{A.isTextFormat(u.pattern)&&g.setValue(u.row,u.col,{t:t.CellValueType.STRING});const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&g.setValue(u.row,u.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),d=new t.ObjectMatrix;new t.ObjectMatrix(i).forValue((g,u)=>{const y=f.getCellRaw(g,u);y?d.setValue(g,u,{t:y.t}):d.setValue(g,u,{t:void 0})}),Object.keys(_.values).forEach(g=>{const u=_.values[g];u.ranges=m.rangeMerge(u.ranges)}),b.push({id:m.SetNumfmtMutation.id,params:_});const p=m.factorySetNumfmtUndoMutation(e,_);C.push(...p)}if(M.length){v.ranges=m.rangeMerge(v.ranges);const i=M.reduce((g,u)=>{const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&g.setValue(u.row,u.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),d=new t.ObjectMatrix;new t.ObjectMatrix(i).forValue((g,u)=>{const y=f.getCellRaw(g,u);y?d.setValue(g,u,{t:y.t}):d.setValue(g,u,{t:void 0})}),b.push({id:m.RemoveNumfmtMutation.id,params:v},{id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:S,cellValue:i}});const p=m.factoryRemoveNumfmtUndoMutation(e,v);C.push({id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:S,cellValue:d.getMatrix()}},...p)}const h=t.sequenceExecute(b,s).result;return h&&a.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:b}),h}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:S,subUnitId:f}=l;let c=0;o.forEach(b=>{t.Range.foreach(b.range,(C,h)=>{const i=n.getValue(S,f,C,h);if(!i){const p=l.worksheet.getCellRaw(C,h);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const g=/\.(\d*)$/.exec(String(p.v));if(g){const u=g[1].length;if(!u)return;c=Math.max(c,u)}}return}const d=E(i.pattern);c=d>c?d:c})});const M=c+1,_=P(`0${M>0?".0":""}`,M),v=[];return o.forEach(b=>{t.Range.foreach(b.range,(C,h)=>{const i=n.getValue(S,f,C,h);if(!i)v.push({row:C,col:h,pattern:_});else{const d=E(i.pattern),p=P(i.pattern,d+1);p!==i.pattern&&v.push({row:C,col:h,pattern:p})}})}),v.length?await r.executeCommand(R.id,{values:v}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(D),a=L[n.getCurrencySymbol()]||"$",o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=[],S=V[4].suffix(a);return o.forEach(c=>{t.Range.foreach(c.range,(M,_)=>{l.push({row:M,col:_,pattern:S,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},q={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(S=>{t.Range.foreach(S.range,(f,c)=>{a.push({row:f,col:c,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},K={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:S,subUnitId:f}=l;let c=0;o.forEach(C=>{t.Range.foreach(C.range,(h,i)=>{const d=n.getValue(S,f,h,i);if(!d){const g=l.worksheet.getCellRaw(h,i);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const u=/\.(\d*)$/.exec(String(g.v));if(u){const y=u[1].length;if(!y)return;c=Math.max(c,y)}}return}const p=E(d.pattern);c=p>c?p:c})});const M=c-1,_=P(`0${M>0?".0":"."}`,M),v=[];return o.forEach(C=>{t.Range.foreach(C.range,(h,i)=>{const d=n.getValue(S,f,h,i);if(!d)v.push({row:h,col:i,pattern:_});else{const p=E(d.pattern);v.push({row:h,col:i,pattern:P(d.pattern,p-1)})}})}),await r.executeCommand(R.id,{values:v})}},w="sheets-numfmt.config",F={},te=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,s="en")=>{const n=t.numfmt.formatColor(e,r),a=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a}:{result:o}},k=(e,r,s)=>e==="General"?{result:String(X.stripErrorMargin(r))}:Y(e,r,s);var ne=Object.getOwnPropertyDescriptor,re=(e,r,s,n)=>{for(var a=n>1?void 0:n?ne(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 se={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,S,f){super();T(this,"_local$",new N.BehaviorSubject("en"));T(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=S,this._configService=f,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var h,i;const l=a.unitId,S=a.subUnitId;let f;const c=n;if(!c||c.v===void 0||c.v===null)return o(n);if(n!=null&&n.s){const d=a.workbook.getStyles().get(n.s);d!=null&&d.n&&(f=d.n)}if(f||(f=this._numfmtService.getValue(l,S,a.row,a.col)),!f||f.pattern==="General"||m.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return o(n);if((!n||n===a.rawData)&&(n={...a.rawData}),A.isTextFormat(f.pattern))return(h=this._configService.getConfig(w))!=null&&h.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...se},o(n));let _="";const v=s.getValue(a.row,a.col);if(v&&v.parameters===`${c.v}_${f.pattern}`)return o({...n,...v.result});const b=k(f.pattern,Number(c.v),this.local);if(_=b.result,!_)return o(n);const C={v:_,t:t.CellValueType.NUMBER};if(b.color){const d=(i=this._themeService.getColorFromTheme(`${b.color}.500`))!=null?i:b.color;d&&(C.interceptorStyle={cl:{rgb:d}})}return s.setValue(a.row,a.col,{result:C,parameters:`${c.v}_${f.pattern}`}),Object.assign(n,C),o(n)},priority:m.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===m.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(S=>{t.Range.foreach(S,(f,c)=>{s.realDeleteValue(f,c)})})})}else if(n.id===m.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=re([I(0,t.IUniverInstanceService),I(1,t.Inject(m.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(m.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);class j extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,s)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,ie=(e,r,s,n)=>{for(var a=n>1?void 0:n?oe(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},O=(e,r)=>(s,n)=>r(s,n,e),z=(e,r,s)=>ce(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=F,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},F,this._config);this._configService.setConfig(w,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[j]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[j]]),[H,K,W,q,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",Q);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(m.UniverSheetsPlugin),O(1,t.Inject(t.Injector)),O(2,t.IConfigService),O(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>U.find(s=>e.includes(s)),ue=()=>U.map(e=>({label:e,value:e})),me=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>G.map(e=>({label:e.label,value:e.suffix})),de=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=G;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=q;exports.SubtractDecimalCommand=K;exports.countryCurrencyMap=L;exports.currencySymbols=U;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=E;exports.getDecimalString=x;exports.getNumberFormatOptions=de;exports.getPatternPreview=Y;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=te;exports.isPatternHasDecimal=ee;exports.setPatternDecimal=P;
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var ie = Object.defineProperty;
2
2
  var le = (e, t, r) => t in e ? ie(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var M = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { numfmt as U, CommandType as V, ICommandService as T, IUniverInstanceService as A, IUndoRedoService as ue, CellValueType as N, ObjectMatrix as b, sequenceExecute as me, Range as I, Inject as E, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as z, UniverInstanceType as ee, DependentOn as he, Injector as ge, Plugin as pe, merge as Se, registerDependencies as ve, touchDependencies as Y } from "@univerjs/core";
4
+ import { numfmt as U, CommandType as V, ICommandService as T, IUniverInstanceService as A, IUndoRedoService as ue, CellValueType as N, ObjectMatrix as b, sequenceExecute as me, Range as I, Inject as E, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as z, UniverInstanceType as ee, DependentOn as he, Injector as ge, Plugin as pe, merge as ve, registerDependencies as Se, touchDependencies as Y } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as Z, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
6
6
  import { isTextFormat as re } from "@univerjs/engine-numfmt";
7
7
  import { BehaviorSubject as K, merge as Ie, switchMap as Te, of as Ee, skip as xe } from "rxjs";
@@ -191,31 +191,31 @@ const ne = [
191
191
  handler: (e, t) => {
192
192
  if (!t)
193
193
  return !1;
194
- const r = e.get(T), n = e.get(A), s = e.get(ue), a = H(n, t);
195
- if (!a) return !1;
196
- const { unitId: c, subUnitId: l, worksheet: f } = a, u = t.values.filter((o) => !!o.pattern), y = t.values.filter((o) => !o.pattern), _ = ye(c, l, u), h = {
194
+ const r = e.get(T), n = e.get(A), s = e.get(ue), o = H(n, t);
195
+ if (!o) return !1;
196
+ const { unitId: c, subUnitId: l, worksheet: f } = o, u = t.values.filter((a) => !!a.pattern), y = t.values.filter((a) => !a.pattern), _ = ye(c, l, u), h = {
197
197
  unitId: c,
198
198
  subUnitId: l,
199
- ranges: y.map((o) => ({
200
- startColumn: o.col,
201
- startRow: o.row,
202
- endColumn: o.col,
203
- endRow: o.row
199
+ ranges: y.map((a) => ({
200
+ startColumn: a.col,
201
+ startRow: a.row,
202
+ endColumn: a.col,
203
+ endRow: a.row
204
204
  }))
205
205
  }, C = [], p = [];
206
206
  if (u.length) {
207
- const o = u.reduce((m, i) => {
207
+ const a = u.reduce((m, i) => {
208
208
  re(i.pattern) && m.setValue(i.row, i.col, { t: N.STRING });
209
- const v = f.getCellRaw(i.row, i.col);
210
- if (v) {
211
- const x = G(v.v);
212
- x !== v.t && m.setValue(i.row, i.col, { t: x });
209
+ const S = f.getCellRaw(i.row, i.col);
210
+ if (S) {
211
+ const x = G(S.v);
212
+ x !== S.t && m.setValue(i.row, i.col, { t: x });
213
213
  }
214
214
  return m;
215
215
  }, new b()).getMatrix(), g = new b();
216
- new b(o).forValue((m, i) => {
217
- const v = f.getCellRaw(m, i);
218
- v ? g.setValue(m, i, { t: v.t }) : g.setValue(m, i, { t: void 0 });
216
+ new b(a).forValue((m, i) => {
217
+ const S = f.getCellRaw(m, i);
218
+ S ? g.setValue(m, i, { t: S.t }) : g.setValue(m, i, { t: void 0 });
219
219
  }), Object.keys(_.values).forEach((m) => {
220
220
  const i = _.values[m];
221
221
  i.ranges = Z(i.ranges);
@@ -223,22 +223,22 @@ const ne = [
223
223
  id: te.id,
224
224
  params: _
225
225
  });
226
- const S = _e(e, _);
227
- p.push(...S);
226
+ const v = _e(e, _);
227
+ p.push(...v);
228
228
  }
229
229
  if (y.length) {
230
230
  h.ranges = Z(h.ranges);
231
- const o = y.reduce((m, i) => {
232
- const v = f.getCellRaw(i.row, i.col);
233
- if (v) {
234
- const x = G(v.v);
235
- x !== v.t && m.setValue(i.row, i.col, { t: x });
231
+ const a = y.reduce((m, i) => {
232
+ const S = f.getCellRaw(i.row, i.col);
233
+ if (S) {
234
+ const x = G(S.v);
235
+ x !== S.t && m.setValue(i.row, i.col, { t: x });
236
236
  }
237
237
  return m;
238
238
  }, new b()).getMatrix(), g = new b();
239
- new b(o).forValue((m, i) => {
240
- const v = f.getCellRaw(m, i);
241
- v ? g.setValue(m, i, { t: v.t }) : g.setValue(m, i, { t: void 0 });
239
+ new b(a).forValue((m, i) => {
240
+ const S = f.getCellRaw(m, i);
241
+ S ? g.setValue(m, i, { t: S.t }) : g.setValue(m, i, { t: void 0 });
242
242
  }), C.push({
243
243
  id: Ce.id,
244
244
  params: h
@@ -247,10 +247,10 @@ const ne = [
247
247
  params: {
248
248
  unitId: c,
249
249
  subUnitId: l,
250
- cellValue: o
250
+ cellValue: a
251
251
  }
252
252
  });
253
- const S = be(e, h);
253
+ const v = be(e, h);
254
254
  p.push({
255
255
  id: B.id,
256
256
  params: {
@@ -258,7 +258,7 @@ const ne = [
258
258
  subUnitId: l,
259
259
  cellValue: g.getMatrix()
260
260
  }
261
- }, ...S);
261
+ }, ...v);
262
262
  }
263
263
  const d = me(C, r).result;
264
264
  return d && s.pushUndoRedo({
@@ -271,20 +271,20 @@ const ne = [
271
271
  id: "sheet.command.numfmt.add.decimal.command",
272
272
  type: V.COMMAND,
273
273
  handler: async (e) => {
274
- const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), a = r.getCurrentSelections();
275
- if (!a || !a.length)
274
+ const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
275
+ if (!o || !o.length)
276
276
  return !1;
277
277
  const c = H(s);
278
278
  if (!c) return !1;
279
279
  const { unitId: l, subUnitId: f } = c;
280
280
  let u = 0;
281
- a.forEach((C) => {
281
+ o.forEach((C) => {
282
282
  I.foreach(C.range, (p, d) => {
283
- const o = n.getValue(l, f, p, d);
284
- if (!o) {
285
- const S = c.worksheet.getCellRaw(p, d);
286
- if (!u && S && S.t === N.NUMBER && S.v) {
287
- const m = /\.(\d*)$/.exec(String(S.v));
283
+ const a = n.getValue(l, f, p, d);
284
+ if (!a) {
285
+ const v = c.worksheet.getCellRaw(p, d);
286
+ if (!u && v && v.t === N.NUMBER && v.v) {
287
+ const m = /\.(\d*)$/.exec(String(v.v));
288
288
  if (m) {
289
289
  const i = m[1].length;
290
290
  if (!i)
@@ -294,26 +294,26 @@ const ne = [
294
294
  }
295
295
  return;
296
296
  }
297
- const g = O(o.pattern);
297
+ const g = O(a.pattern);
298
298
  u = g > u ? g : u;
299
299
  });
300
300
  });
301
301
  const y = u + 1, _ = P(`0${y > 0 ? ".0" : ""}`, y), h = [];
302
- return a.forEach((C) => {
302
+ return o.forEach((C) => {
303
303
  I.foreach(C.range, (p, d) => {
304
- const o = n.getValue(l, f, p, d);
305
- if (!o)
304
+ const a = n.getValue(l, f, p, d);
305
+ if (!a)
306
306
  h.push({
307
307
  row: p,
308
308
  col: d,
309
309
  pattern: _
310
310
  });
311
311
  else {
312
- const g = O(o.pattern), S = P(o.pattern, g + 1);
313
- S !== o.pattern && h.push({
312
+ const g = O(a.pattern), v = P(a.pattern, g + 1);
313
+ v !== a.pattern && h.push({
314
314
  row: p,
315
315
  col: d,
316
- pattern: S
316
+ pattern: v
317
317
  });
318
318
  }
319
319
  });
@@ -339,11 +339,11 @@ const Fe = {
339
339
  id: "sheet.command.numfmt.set.currency",
340
340
  type: V.COMMAND,
341
341
  handler: async (e) => {
342
- const t = e.get(T), r = e.get(j), n = e.get(oe), s = we[n.getCurrencySymbol()] || "$", a = r.getCurrentSelections();
343
- if (!a || !a.length)
342
+ const t = e.get(T), r = e.get(j), n = e.get(oe), s = we[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
343
+ if (!o || !o.length)
344
344
  return !1;
345
345
  const c = [], l = se[4].suffix(s);
346
- return a.forEach((u) => {
346
+ return o.forEach((u) => {
347
347
  I.foreach(u.range, (y, _) => {
348
348
  c.push({ row: y, col: _, pattern: l, type: "currency" });
349
349
  });
@@ -356,10 +356,10 @@ const Fe = {
356
356
  const t = e.get(T), n = e.get(j).getCurrentSelections();
357
357
  if (!n || !n.length)
358
358
  return !1;
359
- const s = [], a = "0%";
359
+ const s = [], o = "0%";
360
360
  return n.forEach((l) => {
361
361
  I.foreach(l.range, (f, u) => {
362
- s.push({ row: f, col: u, pattern: a, type: "percent" });
362
+ s.push({ row: f, col: u, pattern: o, type: "percent" });
363
363
  });
364
364
  }), await t.executeCommand(w.id, { values: s });
365
365
  }
@@ -367,69 +367,69 @@ const Fe = {
367
367
  id: "sheet.command.numfmt.subtract.decimal.command",
368
368
  type: V.COMMAND,
369
369
  handler: async (e) => {
370
- const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), a = r.getCurrentSelections();
371
- if (!a || !a.length)
370
+ const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
371
+ if (!o || !o.length)
372
372
  return !1;
373
373
  const c = H(s);
374
374
  if (!c) return !1;
375
375
  const { unitId: l, subUnitId: f } = c;
376
376
  let u = 0;
377
- a.forEach((p) => {
378
- I.foreach(p.range, (d, o) => {
379
- const g = n.getValue(l, f, d, o);
377
+ o.forEach((p) => {
378
+ I.foreach(p.range, (d, a) => {
379
+ const g = n.getValue(l, f, d, a);
380
380
  if (!g) {
381
- const m = c.worksheet.getCellRaw(d, o);
381
+ const m = c.worksheet.getCellRaw(d, a);
382
382
  if (!u && m && m.t === N.NUMBER && m.v) {
383
383
  const i = /\.(\d*)$/.exec(String(m.v));
384
384
  if (i) {
385
- const v = i[1].length;
386
- if (!v)
385
+ const S = i[1].length;
386
+ if (!S)
387
387
  return;
388
- u = Math.max(u, v);
388
+ u = Math.max(u, S);
389
389
  }
390
390
  }
391
391
  return;
392
392
  }
393
- const S = O(g.pattern);
394
- u = S > u ? S : u;
393
+ const v = O(g.pattern);
394
+ u = v > u ? v : u;
395
395
  });
396
396
  });
397
397
  const y = u - 1, _ = P(`0${y > 0 ? ".0" : "."}`, y), h = [];
398
- return a.forEach((p) => {
399
- I.foreach(p.range, (d, o) => {
400
- const g = n.getValue(l, f, d, o);
398
+ return o.forEach((p) => {
399
+ I.foreach(p.range, (d, a) => {
400
+ const g = n.getValue(l, f, d, a);
401
401
  if (!g)
402
402
  h.push({
403
403
  row: d,
404
- col: o,
404
+ col: a,
405
405
  pattern: _
406
406
  });
407
407
  else {
408
- const S = O(g.pattern);
408
+ const v = O(g.pattern);
409
409
  h.push({
410
410
  row: d,
411
- col: o,
412
- pattern: P(g.pattern, S - 1)
411
+ col: a,
412
+ pattern: P(g.pattern, v - 1)
413
413
  });
414
414
  }
415
415
  });
416
416
  }), await t.executeCommand(w.id, { values: h });
417
417
  }
418
418
  }, ae = "sheets-numfmt.config", q = {}, rt = (e) => U.getFormatInfo(e).type || "unknown", Le = (e, t, r = "en") => {
419
- const n = String(U.formatColor(e, t)), s = U.format(e, t, { locale: r, throws: !1 });
419
+ const n = U.formatColor(e, t), s = n ? String(n) : void 0, o = U.format(e, t, { locale: r, throws: !1 });
420
420
  return t < 0 ? {
421
- result: s,
422
- color: n
421
+ result: o,
422
+ color: s
423
423
  } : {
424
- result: s
424
+ result: o
425
425
  };
426
426
  }, Ge = (e, t, r) => e === "General" ? {
427
427
  result: String(Ve(t))
428
428
  // In Excel, the default General format also needs to handle numeric precision.
429
429
  } : Le(e, t, r);
430
430
  var Be = Object.getOwnPropertyDescriptor, He = (e, t, r, n) => {
431
- for (var s = n > 1 ? void 0 : n ? Be(t, r) : t, a = e.length - 1, c; a >= 0; a--)
432
- (c = e[a]) && (s = c(s) || s);
431
+ for (var s = n > 1 ? void 0 : n ? Be(t, r) : t, o = e.length - 1, c; o >= 0; o--)
432
+ (c = e[o]) && (s = c(s) || s);
433
433
  return s;
434
434
  }, R = (e, t) => (r, n) => t(r, n, e);
435
435
  const We = {
@@ -439,11 +439,11 @@ const We = {
439
439
  }
440
440
  };
441
441
  let D = class extends Q {
442
- constructor(t, r, n, s, a, c, l) {
442
+ constructor(t, r, n, s, o, c, l) {
443
443
  super();
444
444
  M(this, "_local$", new K("en"));
445
445
  M(this, "local$", this._local$.asObservable());
446
- this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = a, this._localeService = c, this._configService = l, this._initInterceptorCellContent();
446
+ this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = c, this._configService = l, this._initInterceptorCellContent();
447
447
  }
448
448
  get local() {
449
449
  const t = this._local$.getValue();
@@ -476,16 +476,16 @@ let D = class extends Q {
476
476
  // eslint-disable-next-line complexity
477
477
  handler: (r, n, s) => {
478
478
  var p, d;
479
- const a = n.unitId, c = n.subUnitId;
479
+ const o = n.unitId, c = n.subUnitId;
480
480
  let l;
481
481
  const f = r;
482
482
  if (!f || f.v === void 0 || f.v === null)
483
483
  return s(r);
484
484
  if (r != null && r.s) {
485
- const o = n.workbook.getStyles().get(r.s);
486
- o != null && o.n && (l = o.n);
485
+ const a = n.workbook.getStyles().get(r.s);
486
+ a != null && a.n && (l = a.n);
487
487
  }
488
- if (l || (l = this._numfmtService.getValue(a, c, n.row, n.col)), !l || l.pattern === "General" || G(f.v) !== N.NUMBER)
488
+ if (l || (l = this._numfmtService.getValue(o, c, n.row, n.col)), !l || l.pattern === "General" || G(f.v) !== N.NUMBER)
489
489
  return s(r);
490
490
  if ((!r || r === n.rawData) && (r = { ...n.rawData }), re(l.pattern))
491
491
  return (p = this._configService.getConfig(ae)) != null && p.disableTextFormatMark ? (r.t = N.STRING, s(r)) : (r.t = N.STRING, r.markers = { ...r == null ? void 0 : r.markers, ...We }, s(r));
@@ -498,8 +498,8 @@ let D = class extends Q {
498
498
  return s(r);
499
499
  const C = { v: y, t: N.NUMBER };
500
500
  if (h.color) {
501
- const o = (d = this._themeService.getColorFromTheme(`${h.color}.500`)) != null ? d : h.color;
502
- o && (C.interceptorStyle = { cl: { rgb: o } });
501
+ const a = (d = this._themeService.getColorFromTheme(`${h.color}.500`)) != null ? d : h.color;
502
+ a && (C.interceptorStyle = { cl: { rgb: a } });
503
503
  }
504
504
  return t.setValue(n.row, n.col, {
505
505
  result: C,
@@ -519,8 +519,8 @@ let D = class extends Q {
519
519
  });
520
520
  } else if (r.id === B.id) {
521
521
  const n = r.params;
522
- new b(n.cellValue).forValue((s, a) => {
523
- t.realDeleteValue(s, a);
522
+ new b(n.cellValue).forValue((s, o) => {
523
+ t.realDeleteValue(s, o);
524
524
  });
525
525
  }
526
526
  })), this.disposeWithMe(
@@ -563,14 +563,14 @@ class J extends Q {
563
563
  }
564
564
  }
565
565
  var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t, r) => t in e ? Ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Ze = (e, t, r, n) => {
566
- for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, a = e.length - 1, c; a >= 0; a--)
567
- (c = e[a]) && (s = c(s) || s);
566
+ for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, o = e.length - 1, c; o >= 0; o--)
567
+ (c = e[o]) && (s = c(s) || s);
568
568
  return s;
569
569
  }, L = (e, t) => (r, n) => t(r, n, e), ce = (e, t, r) => Ye(e, typeof t != "symbol" ? t + "" : t, r);
570
570
  let F = class extends pe {
571
571
  constructor(e = q, t, r, n) {
572
572
  super(), this._config = e, this._injector = t, this._configService = r, this._commandService = n;
573
- const { ...s } = Se(
573
+ const { ...s } = ve(
574
574
  {},
575
575
  q,
576
576
  this._config
@@ -578,7 +578,7 @@ let F = class extends pe {
578
578
  this._configService.setConfig(ae, s);
579
579
  }
580
580
  onStarting() {
581
- ve(this._injector, [
581
+ Se(this._injector, [
582
582
  [D],
583
583
  [oe],
584
584
  [J]
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var ie = Object.defineProperty;
2
2
  var le = (e, t, r) => t in e ? ie(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var M = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { numfmt as U, CommandType as V, ICommandService as T, IUniverInstanceService as A, IUndoRedoService as ue, CellValueType as N, ObjectMatrix as b, sequenceExecute as me, Range as I, Inject as E, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as z, UniverInstanceType as ee, DependentOn as he, Injector as ge, Plugin as pe, merge as Se, registerDependencies as ve, touchDependencies as Y } from "@univerjs/core";
4
+ import { numfmt as U, CommandType as V, ICommandService as T, IUniverInstanceService as A, IUndoRedoService as ue, CellValueType as N, ObjectMatrix as b, sequenceExecute as me, Range as I, Inject as E, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as z, UniverInstanceType as ee, DependentOn as he, Injector as ge, Plugin as pe, merge as ve, registerDependencies as Se, touchDependencies as Y } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as Z, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
6
6
  import { isTextFormat as re } from "@univerjs/engine-numfmt";
7
7
  import { BehaviorSubject as K, merge as Ie, switchMap as Te, of as Ee, skip as xe } from "rxjs";
@@ -191,31 +191,31 @@ const ne = [
191
191
  handler: (e, t) => {
192
192
  if (!t)
193
193
  return !1;
194
- const r = e.get(T), n = e.get(A), s = e.get(ue), a = H(n, t);
195
- if (!a) return !1;
196
- const { unitId: c, subUnitId: l, worksheet: f } = a, u = t.values.filter((o) => !!o.pattern), y = t.values.filter((o) => !o.pattern), _ = ye(c, l, u), h = {
194
+ const r = e.get(T), n = e.get(A), s = e.get(ue), o = H(n, t);
195
+ if (!o) return !1;
196
+ const { unitId: c, subUnitId: l, worksheet: f } = o, u = t.values.filter((a) => !!a.pattern), y = t.values.filter((a) => !a.pattern), _ = ye(c, l, u), h = {
197
197
  unitId: c,
198
198
  subUnitId: l,
199
- ranges: y.map((o) => ({
200
- startColumn: o.col,
201
- startRow: o.row,
202
- endColumn: o.col,
203
- endRow: o.row
199
+ ranges: y.map((a) => ({
200
+ startColumn: a.col,
201
+ startRow: a.row,
202
+ endColumn: a.col,
203
+ endRow: a.row
204
204
  }))
205
205
  }, C = [], p = [];
206
206
  if (u.length) {
207
- const o = u.reduce((m, i) => {
207
+ const a = u.reduce((m, i) => {
208
208
  re(i.pattern) && m.setValue(i.row, i.col, { t: N.STRING });
209
- const v = f.getCellRaw(i.row, i.col);
210
- if (v) {
211
- const x = G(v.v);
212
- x !== v.t && m.setValue(i.row, i.col, { t: x });
209
+ const S = f.getCellRaw(i.row, i.col);
210
+ if (S) {
211
+ const x = G(S.v);
212
+ x !== S.t && m.setValue(i.row, i.col, { t: x });
213
213
  }
214
214
  return m;
215
215
  }, new b()).getMatrix(), g = new b();
216
- new b(o).forValue((m, i) => {
217
- const v = f.getCellRaw(m, i);
218
- v ? g.setValue(m, i, { t: v.t }) : g.setValue(m, i, { t: void 0 });
216
+ new b(a).forValue((m, i) => {
217
+ const S = f.getCellRaw(m, i);
218
+ S ? g.setValue(m, i, { t: S.t }) : g.setValue(m, i, { t: void 0 });
219
219
  }), Object.keys(_.values).forEach((m) => {
220
220
  const i = _.values[m];
221
221
  i.ranges = Z(i.ranges);
@@ -223,22 +223,22 @@ const ne = [
223
223
  id: te.id,
224
224
  params: _
225
225
  });
226
- const S = _e(e, _);
227
- p.push(...S);
226
+ const v = _e(e, _);
227
+ p.push(...v);
228
228
  }
229
229
  if (y.length) {
230
230
  h.ranges = Z(h.ranges);
231
- const o = y.reduce((m, i) => {
232
- const v = f.getCellRaw(i.row, i.col);
233
- if (v) {
234
- const x = G(v.v);
235
- x !== v.t && m.setValue(i.row, i.col, { t: x });
231
+ const a = y.reduce((m, i) => {
232
+ const S = f.getCellRaw(i.row, i.col);
233
+ if (S) {
234
+ const x = G(S.v);
235
+ x !== S.t && m.setValue(i.row, i.col, { t: x });
236
236
  }
237
237
  return m;
238
238
  }, new b()).getMatrix(), g = new b();
239
- new b(o).forValue((m, i) => {
240
- const v = f.getCellRaw(m, i);
241
- v ? g.setValue(m, i, { t: v.t }) : g.setValue(m, i, { t: void 0 });
239
+ new b(a).forValue((m, i) => {
240
+ const S = f.getCellRaw(m, i);
241
+ S ? g.setValue(m, i, { t: S.t }) : g.setValue(m, i, { t: void 0 });
242
242
  }), C.push({
243
243
  id: Ce.id,
244
244
  params: h
@@ -247,10 +247,10 @@ const ne = [
247
247
  params: {
248
248
  unitId: c,
249
249
  subUnitId: l,
250
- cellValue: o
250
+ cellValue: a
251
251
  }
252
252
  });
253
- const S = be(e, h);
253
+ const v = be(e, h);
254
254
  p.push({
255
255
  id: B.id,
256
256
  params: {
@@ -258,7 +258,7 @@ const ne = [
258
258
  subUnitId: l,
259
259
  cellValue: g.getMatrix()
260
260
  }
261
- }, ...S);
261
+ }, ...v);
262
262
  }
263
263
  const d = me(C, r).result;
264
264
  return d && s.pushUndoRedo({
@@ -271,20 +271,20 @@ const ne = [
271
271
  id: "sheet.command.numfmt.add.decimal.command",
272
272
  type: V.COMMAND,
273
273
  handler: async (e) => {
274
- const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), a = r.getCurrentSelections();
275
- if (!a || !a.length)
274
+ const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
275
+ if (!o || !o.length)
276
276
  return !1;
277
277
  const c = H(s);
278
278
  if (!c) return !1;
279
279
  const { unitId: l, subUnitId: f } = c;
280
280
  let u = 0;
281
- a.forEach((C) => {
281
+ o.forEach((C) => {
282
282
  I.foreach(C.range, (p, d) => {
283
- const o = n.getValue(l, f, p, d);
284
- if (!o) {
285
- const S = c.worksheet.getCellRaw(p, d);
286
- if (!u && S && S.t === N.NUMBER && S.v) {
287
- const m = /\.(\d*)$/.exec(String(S.v));
283
+ const a = n.getValue(l, f, p, d);
284
+ if (!a) {
285
+ const v = c.worksheet.getCellRaw(p, d);
286
+ if (!u && v && v.t === N.NUMBER && v.v) {
287
+ const m = /\.(\d*)$/.exec(String(v.v));
288
288
  if (m) {
289
289
  const i = m[1].length;
290
290
  if (!i)
@@ -294,26 +294,26 @@ const ne = [
294
294
  }
295
295
  return;
296
296
  }
297
- const g = O(o.pattern);
297
+ const g = O(a.pattern);
298
298
  u = g > u ? g : u;
299
299
  });
300
300
  });
301
301
  const y = u + 1, _ = P(`0${y > 0 ? ".0" : ""}`, y), h = [];
302
- return a.forEach((C) => {
302
+ return o.forEach((C) => {
303
303
  I.foreach(C.range, (p, d) => {
304
- const o = n.getValue(l, f, p, d);
305
- if (!o)
304
+ const a = n.getValue(l, f, p, d);
305
+ if (!a)
306
306
  h.push({
307
307
  row: p,
308
308
  col: d,
309
309
  pattern: _
310
310
  });
311
311
  else {
312
- const g = O(o.pattern), S = P(o.pattern, g + 1);
313
- S !== o.pattern && h.push({
312
+ const g = O(a.pattern), v = P(a.pattern, g + 1);
313
+ v !== a.pattern && h.push({
314
314
  row: p,
315
315
  col: d,
316
- pattern: S
316
+ pattern: v
317
317
  });
318
318
  }
319
319
  });
@@ -339,11 +339,11 @@ const Fe = {
339
339
  id: "sheet.command.numfmt.set.currency",
340
340
  type: V.COMMAND,
341
341
  handler: async (e) => {
342
- const t = e.get(T), r = e.get(j), n = e.get(oe), s = we[n.getCurrencySymbol()] || "$", a = r.getCurrentSelections();
343
- if (!a || !a.length)
342
+ const t = e.get(T), r = e.get(j), n = e.get(oe), s = we[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
343
+ if (!o || !o.length)
344
344
  return !1;
345
345
  const c = [], l = se[4].suffix(s);
346
- return a.forEach((u) => {
346
+ return o.forEach((u) => {
347
347
  I.foreach(u.range, (y, _) => {
348
348
  c.push({ row: y, col: _, pattern: l, type: "currency" });
349
349
  });
@@ -356,10 +356,10 @@ const Fe = {
356
356
  const t = e.get(T), n = e.get(j).getCurrentSelections();
357
357
  if (!n || !n.length)
358
358
  return !1;
359
- const s = [], a = "0%";
359
+ const s = [], o = "0%";
360
360
  return n.forEach((l) => {
361
361
  I.foreach(l.range, (f, u) => {
362
- s.push({ row: f, col: u, pattern: a, type: "percent" });
362
+ s.push({ row: f, col: u, pattern: o, type: "percent" });
363
363
  });
364
364
  }), await t.executeCommand(w.id, { values: s });
365
365
  }
@@ -367,69 +367,69 @@ const Fe = {
367
367
  id: "sheet.command.numfmt.subtract.decimal.command",
368
368
  type: V.COMMAND,
369
369
  handler: async (e) => {
370
- const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), a = r.getCurrentSelections();
371
- if (!a || !a.length)
370
+ const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
371
+ if (!o || !o.length)
372
372
  return !1;
373
373
  const c = H(s);
374
374
  if (!c) return !1;
375
375
  const { unitId: l, subUnitId: f } = c;
376
376
  let u = 0;
377
- a.forEach((p) => {
378
- I.foreach(p.range, (d, o) => {
379
- const g = n.getValue(l, f, d, o);
377
+ o.forEach((p) => {
378
+ I.foreach(p.range, (d, a) => {
379
+ const g = n.getValue(l, f, d, a);
380
380
  if (!g) {
381
- const m = c.worksheet.getCellRaw(d, o);
381
+ const m = c.worksheet.getCellRaw(d, a);
382
382
  if (!u && m && m.t === N.NUMBER && m.v) {
383
383
  const i = /\.(\d*)$/.exec(String(m.v));
384
384
  if (i) {
385
- const v = i[1].length;
386
- if (!v)
385
+ const S = i[1].length;
386
+ if (!S)
387
387
  return;
388
- u = Math.max(u, v);
388
+ u = Math.max(u, S);
389
389
  }
390
390
  }
391
391
  return;
392
392
  }
393
- const S = O(g.pattern);
394
- u = S > u ? S : u;
393
+ const v = O(g.pattern);
394
+ u = v > u ? v : u;
395
395
  });
396
396
  });
397
397
  const y = u - 1, _ = P(`0${y > 0 ? ".0" : "."}`, y), h = [];
398
- return a.forEach((p) => {
399
- I.foreach(p.range, (d, o) => {
400
- const g = n.getValue(l, f, d, o);
398
+ return o.forEach((p) => {
399
+ I.foreach(p.range, (d, a) => {
400
+ const g = n.getValue(l, f, d, a);
401
401
  if (!g)
402
402
  h.push({
403
403
  row: d,
404
- col: o,
404
+ col: a,
405
405
  pattern: _
406
406
  });
407
407
  else {
408
- const S = O(g.pattern);
408
+ const v = O(g.pattern);
409
409
  h.push({
410
410
  row: d,
411
- col: o,
412
- pattern: P(g.pattern, S - 1)
411
+ col: a,
412
+ pattern: P(g.pattern, v - 1)
413
413
  });
414
414
  }
415
415
  });
416
416
  }), await t.executeCommand(w.id, { values: h });
417
417
  }
418
418
  }, ae = "sheets-numfmt.config", q = {}, rt = (e) => U.getFormatInfo(e).type || "unknown", Le = (e, t, r = "en") => {
419
- const n = String(U.formatColor(e, t)), s = U.format(e, t, { locale: r, throws: !1 });
419
+ const n = U.formatColor(e, t), s = n ? String(n) : void 0, o = U.format(e, t, { locale: r, throws: !1 });
420
420
  return t < 0 ? {
421
- result: s,
422
- color: n
421
+ result: o,
422
+ color: s
423
423
  } : {
424
- result: s
424
+ result: o
425
425
  };
426
426
  }, Ge = (e, t, r) => e === "General" ? {
427
427
  result: String(Ve(t))
428
428
  // In Excel, the default General format also needs to handle numeric precision.
429
429
  } : Le(e, t, r);
430
430
  var Be = Object.getOwnPropertyDescriptor, He = (e, t, r, n) => {
431
- for (var s = n > 1 ? void 0 : n ? Be(t, r) : t, a = e.length - 1, c; a >= 0; a--)
432
- (c = e[a]) && (s = c(s) || s);
431
+ for (var s = n > 1 ? void 0 : n ? Be(t, r) : t, o = e.length - 1, c; o >= 0; o--)
432
+ (c = e[o]) && (s = c(s) || s);
433
433
  return s;
434
434
  }, R = (e, t) => (r, n) => t(r, n, e);
435
435
  const We = {
@@ -439,11 +439,11 @@ const We = {
439
439
  }
440
440
  };
441
441
  let D = class extends Q {
442
- constructor(t, r, n, s, a, c, l) {
442
+ constructor(t, r, n, s, o, c, l) {
443
443
  super();
444
444
  M(this, "_local$", new K("en"));
445
445
  M(this, "local$", this._local$.asObservable());
446
- this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = a, this._localeService = c, this._configService = l, this._initInterceptorCellContent();
446
+ this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = c, this._configService = l, this._initInterceptorCellContent();
447
447
  }
448
448
  get local() {
449
449
  const t = this._local$.getValue();
@@ -476,16 +476,16 @@ let D = class extends Q {
476
476
  // eslint-disable-next-line complexity
477
477
  handler: (r, n, s) => {
478
478
  var p, d;
479
- const a = n.unitId, c = n.subUnitId;
479
+ const o = n.unitId, c = n.subUnitId;
480
480
  let l;
481
481
  const f = r;
482
482
  if (!f || f.v === void 0 || f.v === null)
483
483
  return s(r);
484
484
  if (r != null && r.s) {
485
- const o = n.workbook.getStyles().get(r.s);
486
- o != null && o.n && (l = o.n);
485
+ const a = n.workbook.getStyles().get(r.s);
486
+ a != null && a.n && (l = a.n);
487
487
  }
488
- if (l || (l = this._numfmtService.getValue(a, c, n.row, n.col)), !l || l.pattern === "General" || G(f.v) !== N.NUMBER)
488
+ if (l || (l = this._numfmtService.getValue(o, c, n.row, n.col)), !l || l.pattern === "General" || G(f.v) !== N.NUMBER)
489
489
  return s(r);
490
490
  if ((!r || r === n.rawData) && (r = { ...n.rawData }), re(l.pattern))
491
491
  return (p = this._configService.getConfig(ae)) != null && p.disableTextFormatMark ? (r.t = N.STRING, s(r)) : (r.t = N.STRING, r.markers = { ...r == null ? void 0 : r.markers, ...We }, s(r));
@@ -498,8 +498,8 @@ let D = class extends Q {
498
498
  return s(r);
499
499
  const C = { v: y, t: N.NUMBER };
500
500
  if (h.color) {
501
- const o = (d = this._themeService.getColorFromTheme(`${h.color}.500`)) != null ? d : h.color;
502
- o && (C.interceptorStyle = { cl: { rgb: o } });
501
+ const a = (d = this._themeService.getColorFromTheme(`${h.color}.500`)) != null ? d : h.color;
502
+ a && (C.interceptorStyle = { cl: { rgb: a } });
503
503
  }
504
504
  return t.setValue(n.row, n.col, {
505
505
  result: C,
@@ -519,8 +519,8 @@ let D = class extends Q {
519
519
  });
520
520
  } else if (r.id === B.id) {
521
521
  const n = r.params;
522
- new b(n.cellValue).forValue((s, a) => {
523
- t.realDeleteValue(s, a);
522
+ new b(n.cellValue).forValue((s, o) => {
523
+ t.realDeleteValue(s, o);
524
524
  });
525
525
  }
526
526
  })), this.disposeWithMe(
@@ -563,14 +563,14 @@ class J extends Q {
563
563
  }
564
564
  }
565
565
  var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t, r) => t in e ? Ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Ze = (e, t, r, n) => {
566
- for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, a = e.length - 1, c; a >= 0; a--)
567
- (c = e[a]) && (s = c(s) || s);
566
+ for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, o = e.length - 1, c; o >= 0; o--)
567
+ (c = e[o]) && (s = c(s) || s);
568
568
  return s;
569
569
  }, L = (e, t) => (r, n) => t(r, n, e), ce = (e, t, r) => Ye(e, typeof t != "symbol" ? t + "" : t, r);
570
570
  let F = class extends pe {
571
571
  constructor(e = q, t, r, n) {
572
572
  super(), this._config = e, this._injector = t, this._configService = r, this._commandService = n;
573
- const { ...s } = Se(
573
+ const { ...s } = ve(
574
574
  {},
575
575
  q,
576
576
  this._config
@@ -578,7 +578,7 @@ let F = class extends pe {
578
578
  this._configService.setConfig(ae, s);
579
579
  }
580
580
  onStarting() {
581
- ve(this._injector, [
581
+ Se(this._injector, [
582
582
  [D],
583
583
  [oe],
584
584
  [J]
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.UniverEngineNumfmt,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,u,A,I,J){"use strict";var de=Object.defineProperty;var ge=(a,t,u)=>t in a?de(a,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):a[t]=u;var R=(a,t,u)=>ge(a,typeof t!="symbol"?t+"":t,u);const O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],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"}],x=[{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"}],X="SHEET_NUMFMT_PLUGIN",E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${D(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${D(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),$={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=u.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:v,worksheet:d}=l,c=r.values.filter(o=>!!o.pattern),T=r.values.filter(o=>!o.pattern),M=u.transformCellsToRange(m,v,c),y={unitId:m,subUnitId:v,ranges:T.map(o=>({startColumn:o.col,startRow:o.row,endColumn:o.col,endRow:o.row}))},b=[],h=[];if(c.length){const o=c.reduce((S,f)=>{A.isTextFormat(f.pattern)&&S.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const P=u.checkCellValueType(_.v);P!==_.t&&S.setValue(f.row,f.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),g=new t.ObjectMatrix;new t.ObjectMatrix(o).forValue((S,f)=>{const _=d.getCellRaw(S,f);_?g.setValue(S,f,{t:_.t}):g.setValue(S,f,{t:void 0})}),Object.keys(M.values).forEach(S=>{const f=M.values[S];f.ranges=u.rangeMerge(f.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const p=u.factorySetNumfmtUndoMutation(e,M);h.push(...p)}if(T.length){y.ranges=u.rangeMerge(y.ranges);const o=T.reduce((S,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const P=u.checkCellValueType(_.v);P!==_.t&&S.setValue(f.row,f.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),g=new t.ObjectMatrix;new t.ObjectMatrix(o).forValue((S,f)=>{const _=d.getCellRaw(S,f);_?g.setValue(S,f,{t:_.t}):g.setValue(S,f,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:v,cellValue:o}});const p=u.factoryRemoveNumfmtUndoMutation(e,y);h.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:v,cellValue:g.getMatrix()}},...p)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:h,redoMutations:b}),C}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=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:v,subUnitId:d}=m;let c=0;l.forEach(b=>{t.Range.foreach(b.range,(h,C)=>{const o=n.getValue(v,d,h,C);if(!o){const p=m.worksheet.getCellRaw(h,C);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const S=/\.(\d*)$/.exec(String(p.v));if(S){const f=S[1].length;if(!f)return;c=Math.max(c,f)}}return}const g=E(o.pattern);c=g>c?g:c})});const T=c+1,M=U(`0${T>0?".0":""}`,T),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(h,C)=>{const o=n.getValue(v,d,h,C);if(!o)y.push({row:h,col:C,pattern:M});else{const g=E(o.pattern),p=U(o.pattern,g+1);p!==o.pattern&&y.push({row:h,col:C,pattern:p})}})}),y.length?await r.executeCommand($.id,{values:y}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(j),s=L[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],v=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(T,M)=>{m.push({row:T,col:M,pattern:v,type:"currency"})})}),await r.executeCommand($.id,{values:m})}},W={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(v=>{t.Range.foreach(v.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=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:v,subUnitId:d}=m;let c=0;l.forEach(h=>{t.Range.foreach(h.range,(C,o)=>{const g=n.getValue(v,d,C,o);if(!g){const S=m.worksheet.getCellRaw(C,o);if(!c&&S&&S.t===t.CellValueType.NUMBER&&S.v){const f=/\.(\d*)$/.exec(String(S.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(g.pattern);c=p>c?p:c})});const T=c-1,M=U(`0${T>0?".0":"."}`,T),y=[];return l.forEach(h=>{t.Range.foreach(h.range,(C,o)=>{const g=n.getValue(v,d,C,o);if(!g)y.push({row:C,col:o,pattern:M});else{const p=E(g.pattern);y.push({row:C,col:o,pattern:U(g.pattern,p-1)})}})}),await r.executeCommand($.id,{values:y})}},w="sheets-numfmt.config",K={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,i="en")=>{const n=String(t.numfmt.formatColor(e,r)),s=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:s,color:n}:{result:s}},k=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:Y(e,r,i);var te=Object.getOwnPropertyDescriptor,ne=(e,r,i,n)=>{for(var s=n>1?void 0:n?te(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,r)=>(i,n)=>r(i,n,e);const re={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,v,d){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=v,this._configService=d,this._initInterceptorCellContent()}get local(){const i=this._local$.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.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,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 C,o;const m=s.unitId,v=s.subUnitId;let d;const c=n;if(!c||c.v===void 0||c.v===null)return l(n);if(n!=null&&n.s){const g=s.workbook.getStyles().get(n.s);g!=null&&g.n&&(d=g.n)}if(d||(d=this._numfmtService.getValue(m,v,s.row,s.col)),!d||d.pattern==="General"||u.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),A.isTextFormat(d.pattern))return(C=this._configService.getConfig(w))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...re},l(n));let M="";const y=i.getValue(s.row,s.col);if(y&&y.parameters===`${c.v}_${d.pattern}`)return l({...n,...y.result});const b=k(d.pattern,Number(c.v),this.local);if(M=b.result,!M)return l(n);const h={v:M,t:t.CellValueType.NUMBER};if(b.color){const g=(o=this._themeService.getColorFromTheme(`${b.color}.500`))!=null?o:b.color;g&&(h.interceptorStyle={cl:{rgb:g}})}return i.setValue(s.row,s.col,{result:h,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,h),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(v=>{t.Range.foreach(v,(d,c)=>{i.realDeleteValue(d,c)})})})}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(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._local$.next(i)}},a.SheetsNumfmtCellContentController=ne([N(0,t.IUniverInstanceService),N(1,t.Inject(u.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(u.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);class z extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(i){this._currencySymbol$.next(i)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,le=(e,r,i,n)=>{for(var s=n>1?void 0:n?ie(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},F=(e,r)=>(i,n)=>r(i,n,e),Z=(e,r,i)=>se(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=K,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},K,this._config);this._configService.setConfig(w,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[j],[z]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[z]]),[B,q,H,W,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ue=e=>O.find(i=>e.includes(i)),ce=()=>O.map(e=>({label:e,value:e})),oe=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>G.map(e=>({label:e.label,value:e.suffix})),fe=()=>x.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=B,a.CURRENCYFORMAT=V,a.DATEFMTLISG=G,a.MenuCurrencyService=j,a.NUMBERFORMAT=x,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,a.SetCurrencyCommand=H,a.SetNumfmtCommand=$,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=oe,a.getCurrencyOptions=ce,a.getCurrencyType=ue,a.getDateFormatOptions=me,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=fe,a.getPatternPreview=Y,a.getPatternPreviewIgnoreGeneral=k,a.getPatternType=ee,a.isPatternHasDecimal=Q,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.UniverEngineNumfmt,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,u,A,I,J){"use strict";var de=Object.defineProperty;var ge=(a,t,u)=>t in a?de(a,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):a[t]=u;var R=(a,t,u)=>ge(a,typeof t!="symbol"?t+"":t,u);const O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],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"}],x=[{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"}],X="SHEET_NUMFMT_PLUGIN",E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${D(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${D(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),$={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=u.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:v,worksheet:d}=l,c=r.values.filter(o=>!!o.pattern),T=r.values.filter(o=>!o.pattern),M=u.transformCellsToRange(m,v,c),y={unitId:m,subUnitId:v,ranges:T.map(o=>({startColumn:o.col,startRow:o.row,endColumn:o.col,endRow:o.row}))},b=[],h=[];if(c.length){const o=c.reduce((S,f)=>{A.isTextFormat(f.pattern)&&S.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const P=u.checkCellValueType(_.v);P!==_.t&&S.setValue(f.row,f.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),g=new t.ObjectMatrix;new t.ObjectMatrix(o).forValue((S,f)=>{const _=d.getCellRaw(S,f);_?g.setValue(S,f,{t:_.t}):g.setValue(S,f,{t:void 0})}),Object.keys(M.values).forEach(S=>{const f=M.values[S];f.ranges=u.rangeMerge(f.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const p=u.factorySetNumfmtUndoMutation(e,M);h.push(...p)}if(T.length){y.ranges=u.rangeMerge(y.ranges);const o=T.reduce((S,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const P=u.checkCellValueType(_.v);P!==_.t&&S.setValue(f.row,f.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),g=new t.ObjectMatrix;new t.ObjectMatrix(o).forValue((S,f)=>{const _=d.getCellRaw(S,f);_?g.setValue(S,f,{t:_.t}):g.setValue(S,f,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:v,cellValue:o}});const p=u.factoryRemoveNumfmtUndoMutation(e,y);h.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:v,cellValue:g.getMatrix()}},...p)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:h,redoMutations:b}),C}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=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:v,subUnitId:d}=m;let c=0;l.forEach(b=>{t.Range.foreach(b.range,(h,C)=>{const o=n.getValue(v,d,h,C);if(!o){const p=m.worksheet.getCellRaw(h,C);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const S=/\.(\d*)$/.exec(String(p.v));if(S){const f=S[1].length;if(!f)return;c=Math.max(c,f)}}return}const g=E(o.pattern);c=g>c?g:c})});const T=c+1,M=U(`0${T>0?".0":""}`,T),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(h,C)=>{const o=n.getValue(v,d,h,C);if(!o)y.push({row:h,col:C,pattern:M});else{const g=E(o.pattern),p=U(o.pattern,g+1);p!==o.pattern&&y.push({row:h,col:C,pattern:p})}})}),y.length?await r.executeCommand($.id,{values:y}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(j),s=L[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],v=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(T,M)=>{m.push({row:T,col:M,pattern:v,type:"currency"})})}),await r.executeCommand($.id,{values:m})}},W={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(v=>{t.Range.foreach(v.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=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:v,subUnitId:d}=m;let c=0;l.forEach(h=>{t.Range.foreach(h.range,(C,o)=>{const g=n.getValue(v,d,C,o);if(!g){const S=m.worksheet.getCellRaw(C,o);if(!c&&S&&S.t===t.CellValueType.NUMBER&&S.v){const f=/\.(\d*)$/.exec(String(S.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(g.pattern);c=p>c?p:c})});const T=c-1,M=U(`0${T>0?".0":"."}`,T),y=[];return l.forEach(h=>{t.Range.foreach(h.range,(C,o)=>{const g=n.getValue(v,d,C,o);if(!g)y.push({row:C,col:o,pattern:M});else{const p=E(g.pattern);y.push({row:C,col:o,pattern:U(g.pattern,p-1)})}})}),await r.executeCommand($.id,{values:y})}},w="sheets-numfmt.config",K={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,i="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,l=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:l,color:s}:{result:l}},k=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:Y(e,r,i);var te=Object.getOwnPropertyDescriptor,ne=(e,r,i,n)=>{for(var s=n>1?void 0:n?te(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,r)=>(i,n)=>r(i,n,e);const re={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,v,d){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=v,this._configService=d,this._initInterceptorCellContent()}get local(){const i=this._local$.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.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,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 C,o;const m=s.unitId,v=s.subUnitId;let d;const c=n;if(!c||c.v===void 0||c.v===null)return l(n);if(n!=null&&n.s){const g=s.workbook.getStyles().get(n.s);g!=null&&g.n&&(d=g.n)}if(d||(d=this._numfmtService.getValue(m,v,s.row,s.col)),!d||d.pattern==="General"||u.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),A.isTextFormat(d.pattern))return(C=this._configService.getConfig(w))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...re},l(n));let M="";const y=i.getValue(s.row,s.col);if(y&&y.parameters===`${c.v}_${d.pattern}`)return l({...n,...y.result});const b=k(d.pattern,Number(c.v),this.local);if(M=b.result,!M)return l(n);const h={v:M,t:t.CellValueType.NUMBER};if(b.color){const g=(o=this._themeService.getColorFromTheme(`${b.color}.500`))!=null?o:b.color;g&&(h.interceptorStyle={cl:{rgb:g}})}return i.setValue(s.row,s.col,{result:h,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,h),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(v=>{t.Range.foreach(v,(d,c)=>{i.realDeleteValue(d,c)})})})}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(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._local$.next(i)}},a.SheetsNumfmtCellContentController=ne([N(0,t.IUniverInstanceService),N(1,t.Inject(u.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(u.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);class z extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(i){this._currencySymbol$.next(i)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,le=(e,r,i,n)=>{for(var s=n>1?void 0:n?ie(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},F=(e,r)=>(i,n)=>r(i,n,e),Z=(e,r,i)=>se(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=K,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},K,this._config);this._configService.setConfig(w,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[j],[z]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[z]]),[B,q,H,W,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ue=e=>O.find(i=>e.includes(i)),ce=()=>O.map(e=>({label:e,value:e})),oe=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>G.map(e=>({label:e.label,value:e.suffix})),fe=()=>x.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=B,a.CURRENCYFORMAT=V,a.DATEFMTLISG=G,a.MenuCurrencyService=j,a.NUMBERFORMAT=x,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,a.SetCurrencyCommand=H,a.SetNumfmtCommand=$,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=oe,a.getCurrencyOptions=ce,a.getCurrencyType=ue,a.getDateFormatOptions=me,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=fe,a.getPatternPreview=Y,a.getPatternPreviewIgnoreGeneral=k,a.getPatternType=ee,a.isPatternHasDecimal=Q,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt",
3
- "version": "0.8.0-nightly.202506081606",
3
+ "version": "0.8.0-nightly.202506101607",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -58,10 +58,10 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/core": "0.8.0-nightly.202506081606",
62
- "@univerjs/engine-numfmt": "0.8.0-nightly.202506081606",
63
- "@univerjs/sheets": "0.8.0-nightly.202506081606",
64
- "@univerjs/engine-formula": "0.8.0-nightly.202506081606"
61
+ "@univerjs/core": "0.8.0-nightly.202506101607",
62
+ "@univerjs/engine-formula": "0.8.0-nightly.202506101607",
63
+ "@univerjs/sheets": "0.8.0-nightly.202506101607",
64
+ "@univerjs/engine-numfmt": "0.8.0-nightly.202506101607"
65
65
  },
66
66
  "devDependencies": {
67
67
  "rxjs": "^7.8.2",