@univerjs/sheets-numfmt 0.9.2-nightly.202507141607 → 0.9.2-nightly.202507151607

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 Z=(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)=>Z(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),m=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],A={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:"€"},L=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],G=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],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"}],E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},U=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),O=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${U(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${U(Number(r||0))}$1`):n).join(";"),X=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:g,worksheet:f}=o,i=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),b=m.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],v=[];if(i.length){const c=i.reduce((d,u)=>{t.isTextFormat(u.pattern)&&d.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&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),Object.keys(b.values).forEach(d=>{const u=b.values[d];u.ranges=m.rangeMerge(u.ranges)}),M.push({id:m.SetNumfmtMutation.id,params:b});const p=m.factorySetNumfmtUndoMutation(e,b);v.push(...p)}if(_.length){h.ranges=m.rangeMerge(h.ranges);const c=_.reduce((d,u)=>{const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),M.push({id:m.RemoveNumfmtMutation.id,params:h},{id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const p=m.factoryRemoveNumfmtUndoMutation(e,h);v.push({id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:C.getMatrix()}},...p)}const S=t.sequenceExecute(M,s).result;return S&&a.pushUndoRedo({unitID:l,undoMutations:v,redoMutations:M}),S}},B={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:g,subUnitId:f}=l;let i=0;o.forEach(M=>{t.Range.foreach(M.range,(v,S)=>{const c=n.getValue(g,f,v,S);if(!c){const p=l.worksheet.getCellRaw(v,S);if(!i&&p&&p.t===t.CellValueType.NUMBER&&p.v){const d=/\.(\d*)$/.exec(String(p.v));if(d){const u=d[1].length;if(!u)return;i=Math.max(i,u)}}return}const C=E(c.pattern);i=C>i?C:i})});const _=i+1,b=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(v,S)=>{const c=n.getValue(g,f,v,S);if(!c)h.push({row:v,col:S,pattern:b});else{const C=E(c.pattern),p=O(c.pattern,C+1);p!==c.pattern&&h.push({row:v,col:S,pattern:p})}})}),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 H={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=A[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,(_,b)=>{l.push({row:_,col:b,pattern:g,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},K={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(g=>{t.Range.foreach(g.range,(f,i)=>{a.push({row:f,col:i,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},W={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:g,subUnitId:f}=l;let i=0;o.forEach(v=>{t.Range.foreach(v.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C){const d=l.worksheet.getCellRaw(S,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const u=/\.(\d*)$/.exec(String(d.v));if(u){const y=u[1].length;if(!y)return;i=Math.max(i,y)}}return}const p=E(C.pattern);i=p>i?p:i})});const _=i-1,b=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(v=>{t.Range.foreach(v.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C)h.push({row:S,col:c,pattern:b});else{const p=E(C.pattern);h.push({row:S,col:c,pattern:O(C.pattern,p-1)})}})}),await r.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",F={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",q=(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}},Y=(e,r,s)=>e==="General"?{result:String(J.stripErrorMargin(r))}:q(e,r,s);var ee=Object.getOwnPropertyDescriptor,te=(e,r,s,n)=>{for(var a=n>1?void 0:n?ee(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 ne={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,g,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=g,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.KO_KR:return"ko";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 v,S;const l=a.unitId,g=a.subUnitId;let f;const i=n;if(!i||i.v===void 0||i.v===null)return o(n);if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(f=c.n)}if(f||(f=this._numfmtService.getValue(l,g,a.row,a.col)),!f||f.pattern==="General"||i.t!==t.CellValueType.NUMBER&&m.checkCellValueType(i.v)!==t.CellValueType.NUMBER)return o(n);if((!n||n===a.rawData)&&(n={...a.rawData}),t.isTextFormat(f.pattern))return(v=this._configService.getConfig(w))!=null&&v.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},o(n));let _="";const b=s.getValue(a.row,a.col);if(b&&b.parameters===`${i.v}_${f.pattern}`)return o({...n,...b.result});const h=Y(f.pattern,Number(i.v),this.local);if(_=h.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(h.color){const c=(S=this._themeService.getColorFromTheme(`${h.color}.500`))!=null?S:h.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:M,parameters:`${i.v}_${f.pattern}`}),Object.assign(n,M),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(g=>{t.Range.foreach(g,(f,i)=>{s.realDeleteValue(f,i)})})})}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=te([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);const re="SHEET_NUMFMT_PLUGIN";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 se=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,oe=(e,r,s)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,ce=(e,r,s,n)=>{for(var a=n>1?void 0:n?ae(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},P=(e,r)=>(s,n)=>r(s,n,e),k=(e,r,s)=>oe(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]]),[B,W,H,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};k(exports.UniverSheetsNumfmtPlugin,"pluginName",re);k(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ce([t.DependentOn(m.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ie=e=>x.find(s=>e.includes(s)),le=()=>x.map(e=>({label:e,value:e})),ue=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>L.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=B;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=L;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=G;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=H;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=W;exports.countryCurrencyMap=A;exports.currencySymbols=x;exports.getCurrencyFormatOptions=ue;exports.getCurrencyOptions=le;exports.getCurrencyType=ie;exports.getDateFormatOptions=me;exports.getDecimalFromPattern=E;exports.getDecimalString=U;exports.getNumberFormatOptions=fe;exports.getPatternPreview=q;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=Q;exports.isPatternHasDecimal=X;exports.setPatternDecimal=O;
1
+ "use strict";var z=Object.defineProperty;var Z=(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)=>Z(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),m=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],A={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:"€"},L=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],G=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],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"}],E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},U=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),O=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${U(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${U(Number(r||0))}$1`):n).join(";"),X=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:g,worksheet:f}=o,i=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),b=m.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:_.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)=>{t.isTextFormat(u.pattern)&&d.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&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),Object.keys(b.values).forEach(d=>{const u=b.values[d];u.ranges=m.rangeMerge(u.ranges)}),M.push({id:m.SetNumfmtMutation.id,params:b});const v=m.factorySetNumfmtUndoMutation(e,b);p.push(...v)}if(_.length){h.ranges=m.rangeMerge(h.ranges);const c=_.reduce((d,u)=>{const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),M.push({id:m.RemoveNumfmtMutation.id,params:h},{id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const v=m.factoryRemoveNumfmtUndoMutation(e,h);p.push({id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:C.getMatrix()}},...v)}const S=t.sequenceExecute(M,s).result;return S&&a.pushUndoRedo({unitID:l,undoMutations:p,redoMutations:M}),S}},B={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:g,subUnitId:f}=l;let i=0;o.forEach(M=>{t.Range.foreach(M.range,(p,S)=>{const c=n.getValue(g,f,p,S);if(!c){const v=l.worksheet.getCellRaw(p,S);if(!i&&v&&v.t===t.CellValueType.NUMBER&&v.v){const d=/\.(\d*)$/.exec(String(v.v));if(d){const u=d[1].length;if(!u)return;i=Math.max(i,u)}}return}const C=E(c.pattern);i=C>i?C:i})});const _=i+1,b=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(p,S)=>{const c=n.getValue(g,f,p,S);if(!c)h.push({row:p,col:S,pattern:b});else{const C=E(c.pattern),v=O(c.pattern,C+1);v!==c.pattern&&h.push({row:p,col:S,pattern:v})}})}),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 H={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=A[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,(_,b)=>{l.push({row:_,col:b,pattern:g,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},K={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(g=>{t.Range.foreach(g.range,(f,i)=>{a.push({row:f,col:i,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},W={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:g,subUnitId:f}=l;let i=0;o.forEach(p=>{t.Range.foreach(p.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C){const d=l.worksheet.getCellRaw(S,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const u=/\.(\d*)$/.exec(String(d.v));if(u){const y=u[1].length;if(!y)return;i=Math.max(i,y)}}return}const v=E(C.pattern);i=v>i?v:i})});const _=i-1,b=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(p=>{t.Range.foreach(p.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C)h.push({row:S,col:c,pattern:b});else{const v=E(C.pattern);h.push({row:S,col:c,pattern:O(C.pattern,v-1)})}})}),await r.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",F={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",q=(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}},Y=(e,r,s)=>e==="General"?{result:String(J.stripErrorMargin(r))}:q(e,r,s);var ee=Object.getOwnPropertyDescriptor,te=(e,r,s,n)=>{for(var a=n>1?void 0:n?ee(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 ne={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,g,f){super();T(this,"_locale$",new N.BehaviorSubject("en"));T(this,"locale$",this._locale$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=g,this._configService=f,this._initInterceptorCellContent()}get locale(){const s=this._locale$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,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 p,S;const l=a.unitId,g=a.subUnitId;let f;const i=n;if(!i||i.v===void 0||i.v===null)return o(n);if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(f=c.n)}if(f||(f=this._numfmtService.getValue(l,g,a.row,a.col)),!f||f.pattern==="General"||i.t!==t.CellValueType.NUMBER&&m.checkCellValueType(i.v)!==t.CellValueType.NUMBER)return o(n);if((!n||n===a.rawData)&&(n={...a.rawData}),t.isTextFormat(f.pattern))return(p=this._configService.getConfig(w))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},o(n));let _="";const b=s.getValue(a.row,a.col);if(b&&b.parameters===`${i.v}_${f.pattern}`)return o({...n,...b.result});const h=Y(f.pattern,Number(i.v),this.locale);if(_=h.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(h.color){const c=(S=this._themeService.getColorFromTheme(`${h.color}.500`))!=null?S:h.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:M,parameters:`${i.v}_${f.pattern}`}),Object.assign(n,M),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(g=>{t.Range.foreach(g,(f,i)=>{s.realDeleteValue(f,i)})})})}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._locale$.next(s)}};exports.SheetsNumfmtCellContentController=te([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);const re="SHEET_NUMFMT_PLUGIN";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 se=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,oe=(e,r,s)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,ce=(e,r,s,n)=>{for(var a=n>1?void 0:n?ae(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},P=(e,r)=>(s,n)=>r(s,n,e),k=(e,r,s)=>oe(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]]),[B,W,H,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};k(exports.UniverSheetsNumfmtPlugin,"pluginName",re);k(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ce([t.DependentOn(m.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ie=e=>x.find(s=>e.includes(s)),le=()=>x.map(e=>({label:e,value:e})),ue=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>L.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=B;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=L;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=G;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=H;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=W;exports.countryCurrencyMap=A;exports.currencySymbols=x;exports.getCurrencyFormatOptions=ue;exports.getCurrencyOptions=le;exports.getCurrencyType=ie;exports.getDateFormatOptions=me;exports.getDecimalFromPattern=E;exports.getDecimalString=U;exports.getNumberFormatOptions=fe;exports.getPatternPreview=q;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=Q;exports.isPatternHasDecimal=X;exports.setPatternDecimal=O;
package/lib/es/index.js CHANGED
@@ -1,9 +1,9 @@
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 R = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { numfmt as w, CommandType as V, ICommandService as T, IUniverInstanceService as A, IUndoRedoService as ue, isTextFormat as X, CellValueType as $, ObjectMatrix as M, sequenceExecute as me, Range as I, Inject as E, ThemeService as fe, LocaleService as de, IConfigService as Q, Disposable as ee, LocaleType as b, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as he, Injector as ge, Plugin as pe, merge as ve, registerDependencies as Se, touchDependencies as Y } from "@univerjs/core";
4
+ import { numfmt as w, CommandType as V, ICommandService as I, IUniverInstanceService as A, IUndoRedoService as ue, isTextFormat as X, CellValueType as $, ObjectMatrix as M, sequenceExecute as me, Range as E, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as Q, Disposable as ee, LocaleType as b, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as he, Injector as ge, Plugin as Se, merge as pe, registerDependencies as ve, touchDependencies as Y } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as k, SetNumfmtMutation as re, 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
- import { BehaviorSubject as K, merge as Ie, switchMap as Te, of as Ee, skip as xe } from "rxjs";
6
+ import { BehaviorSubject as K, merge as Ee, switchMap as Ie, of as Te, skip as xe } from "rxjs";
7
7
  import { stripErrorMargin as Ve } from "@univerjs/engine-formula";
8
8
  const ne = [
9
9
  "$",
@@ -190,7 +190,7 @@ const ne = [
190
190
  handler: (e, t) => {
191
191
  if (!t)
192
192
  return !1;
193
- const r = e.get(T), n = e.get(A), s = e.get(ue), o = H(n, t);
193
+ const r = e.get(I), n = e.get(A), s = e.get(ue), o = H(n, t);
194
194
  if (!o) return !1;
195
195
  const { unitId: a, subUnitId: i, worksheet: f } = o, u = t.values.filter((l) => !!l.pattern), y = t.values.filter((l) => !l.pattern), _ = ye(a, i, u), g = {
196
196
  unitId: a,
@@ -201,20 +201,20 @@ const ne = [
201
201
  endColumn: l.col,
202
202
  endRow: l.row
203
203
  }))
204
- }, C = [], p = [];
204
+ }, C = [], S = [];
205
205
  if (u.length) {
206
206
  const l = u.reduce((d, c) => {
207
207
  X(c.pattern) && d.setValue(c.row, c.col, { t: $.STRING });
208
- const S = f.getCellRaw(c.row, c.col);
209
- if (S) {
210
- const x = G(S.v);
211
- x !== S.t && d.setValue(c.row, c.col, { t: x });
208
+ const v = f.getCellRaw(c.row, c.col);
209
+ if (v) {
210
+ const x = G(v.v);
211
+ x !== v.t && d.setValue(c.row, c.col, { t: x });
212
212
  }
213
213
  return d;
214
214
  }, new M()).getMatrix(), h = new M();
215
215
  new M(l).forValue((d, c) => {
216
- const S = f.getCellRaw(d, c);
217
- S ? h.setValue(d, c, { t: S.t }) : h.setValue(d, c, { t: void 0 });
216
+ const v = f.getCellRaw(d, c);
217
+ v ? h.setValue(d, c, { t: v.t }) : h.setValue(d, c, { t: void 0 });
218
218
  }), Object.keys(_.values).forEach((d) => {
219
219
  const c = _.values[d];
220
220
  c.ranges = k(c.ranges);
@@ -222,22 +222,22 @@ const ne = [
222
222
  id: re.id,
223
223
  params: _
224
224
  });
225
- const v = _e(e, _);
226
- p.push(...v);
225
+ const p = _e(e, _);
226
+ S.push(...p);
227
227
  }
228
228
  if (y.length) {
229
229
  g.ranges = k(g.ranges);
230
230
  const l = y.reduce((d, c) => {
231
- const S = f.getCellRaw(c.row, c.col);
232
- if (S) {
233
- const x = G(S.v);
234
- x !== S.t && d.setValue(c.row, c.col, { t: x });
231
+ const v = f.getCellRaw(c.row, c.col);
232
+ if (v) {
233
+ const x = G(v.v);
234
+ x !== v.t && d.setValue(c.row, c.col, { t: x });
235
235
  }
236
236
  return d;
237
237
  }, new M()).getMatrix(), h = new M();
238
238
  new M(l).forValue((d, c) => {
239
- const S = f.getCellRaw(d, c);
240
- S ? h.setValue(d, c, { t: S.t }) : h.setValue(d, c, { t: void 0 });
239
+ const v = f.getCellRaw(d, c);
240
+ v ? h.setValue(d, c, { t: v.t }) : h.setValue(d, c, { t: void 0 });
241
241
  }), C.push({
242
242
  id: Ce.id,
243
243
  params: g
@@ -249,20 +249,20 @@ const ne = [
249
249
  cellValue: l
250
250
  }
251
251
  });
252
- const v = be(e, g);
253
- p.push({
252
+ const p = be(e, g);
253
+ S.push({
254
254
  id: B.id,
255
255
  params: {
256
256
  unitId: a,
257
257
  subUnitId: i,
258
258
  cellValue: h.getMatrix()
259
259
  }
260
- }, ...v);
260
+ }, ...p);
261
261
  }
262
262
  const m = me(C, r).result;
263
263
  return m && s.pushUndoRedo({
264
264
  unitID: a,
265
- undoMutations: p,
265
+ undoMutations: S,
266
266
  redoMutations: C
267
267
  }), m;
268
268
  }
@@ -270,7 +270,7 @@ const ne = [
270
270
  id: "sheet.command.numfmt.add.decimal.command",
271
271
  type: V.COMMAND,
272
272
  handler: async (e) => {
273
- const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
273
+ const t = e.get(I), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
274
274
  if (!o || !o.length)
275
275
  return !1;
276
276
  const a = H(s);
@@ -278,12 +278,12 @@ const ne = [
278
278
  const { unitId: i, subUnitId: f } = a;
279
279
  let u = 0;
280
280
  o.forEach((C) => {
281
- I.foreach(C.range, (p, m) => {
282
- const l = n.getValue(i, f, p, m);
281
+ E.foreach(C.range, (S, m) => {
282
+ const l = n.getValue(i, f, S, m);
283
283
  if (!l) {
284
- const v = a.worksheet.getCellRaw(p, m);
285
- if (!u && v && v.t === $.NUMBER && v.v) {
286
- const d = /\.(\d*)$/.exec(String(v.v));
284
+ const p = a.worksheet.getCellRaw(S, m);
285
+ if (!u && p && p.t === $.NUMBER && p.v) {
286
+ const d = /\.(\d*)$/.exec(String(p.v));
287
287
  if (d) {
288
288
  const c = d[1].length;
289
289
  if (!c)
@@ -299,20 +299,20 @@ const ne = [
299
299
  });
300
300
  const y = u + 1, _ = P(`0${y > 0 ? ".0" : ""}`, y), g = [];
301
301
  return o.forEach((C) => {
302
- I.foreach(C.range, (p, m) => {
303
- const l = n.getValue(i, f, p, m);
302
+ E.foreach(C.range, (S, m) => {
303
+ const l = n.getValue(i, f, S, m);
304
304
  if (!l)
305
305
  g.push({
306
- row: p,
306
+ row: S,
307
307
  col: m,
308
308
  pattern: _
309
309
  });
310
310
  else {
311
- const h = O(l.pattern), v = P(l.pattern, h + 1);
312
- v !== l.pattern && g.push({
313
- row: p,
311
+ const h = O(l.pattern), p = P(l.pattern, h + 1);
312
+ p !== l.pattern && g.push({
313
+ row: S,
314
314
  col: m,
315
- pattern: v
315
+ pattern: p
316
316
  });
317
317
  }
318
318
  });
@@ -338,12 +338,12 @@ const De = {
338
338
  id: "sheet.command.numfmt.set.currency",
339
339
  type: V.COMMAND,
340
340
  handler: async (e) => {
341
- const t = e.get(T), r = e.get(j), n = e.get(oe), s = Ue[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
341
+ const t = e.get(I), r = e.get(j), n = e.get(oe), s = Ue[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
342
342
  if (!o || !o.length)
343
343
  return !1;
344
344
  const a = [], i = se[4].suffix(s);
345
345
  return o.forEach((u) => {
346
- I.foreach(u.range, (y, _) => {
346
+ E.foreach(u.range, (y, _) => {
347
347
  a.push({ row: y, col: _, pattern: i, type: "currency" });
348
348
  });
349
349
  }), await t.executeCommand(U.id, { values: a });
@@ -352,12 +352,12 @@ const De = {
352
352
  id: "sheet.command.numfmt.set.percent",
353
353
  type: V.COMMAND,
354
354
  handler: async (e) => {
355
- const t = e.get(T), n = e.get(j).getCurrentSelections();
355
+ const t = e.get(I), n = e.get(j).getCurrentSelections();
356
356
  if (!n || !n.length)
357
357
  return !1;
358
358
  const s = [], o = "0%";
359
359
  return n.forEach((i) => {
360
- I.foreach(i.range, (f, u) => {
360
+ E.foreach(i.range, (f, u) => {
361
361
  s.push({ row: f, col: u, pattern: o, type: "percent" });
362
362
  });
363
363
  }), await t.executeCommand(U.id, { values: s });
@@ -366,36 +366,36 @@ const De = {
366
366
  id: "sheet.command.numfmt.subtract.decimal.command",
367
367
  type: V.COMMAND,
368
368
  handler: async (e) => {
369
- const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
369
+ const t = e.get(I), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
370
370
  if (!o || !o.length)
371
371
  return !1;
372
372
  const a = H(s);
373
373
  if (!a) return !1;
374
374
  const { unitId: i, subUnitId: f } = a;
375
375
  let u = 0;
376
- o.forEach((p) => {
377
- I.foreach(p.range, (m, l) => {
376
+ o.forEach((S) => {
377
+ E.foreach(S.range, (m, l) => {
378
378
  const h = n.getValue(i, f, m, l);
379
379
  if (!h) {
380
380
  const d = a.worksheet.getCellRaw(m, l);
381
381
  if (!u && d && d.t === $.NUMBER && d.v) {
382
382
  const c = /\.(\d*)$/.exec(String(d.v));
383
383
  if (c) {
384
- const S = c[1].length;
385
- if (!S)
384
+ const v = c[1].length;
385
+ if (!v)
386
386
  return;
387
- u = Math.max(u, S);
387
+ u = Math.max(u, v);
388
388
  }
389
389
  }
390
390
  return;
391
391
  }
392
- const v = O(h.pattern);
393
- u = v > u ? v : u;
392
+ const p = O(h.pattern);
393
+ u = p > u ? p : u;
394
394
  });
395
395
  });
396
396
  const y = u - 1, _ = P(`0${y > 0 ? ".0" : "."}`, y), g = [];
397
- return o.forEach((p) => {
398
- I.foreach(p.range, (m, l) => {
397
+ return o.forEach((S) => {
398
+ E.foreach(S.range, (m, l) => {
399
399
  const h = n.getValue(i, f, m, l);
400
400
  if (!h)
401
401
  g.push({
@@ -404,11 +404,11 @@ const De = {
404
404
  pattern: _
405
405
  });
406
406
  else {
407
- const v = O(h.pattern);
407
+ const p = O(h.pattern);
408
408
  g.push({
409
409
  row: m,
410
410
  col: l,
411
- pattern: P(h.pattern, v - 1)
411
+ pattern: P(h.pattern, p - 1)
412
412
  });
413
413
  }
414
414
  });
@@ -440,12 +440,12 @@ const He = {
440
440
  let D = class extends ee {
441
441
  constructor(t, r, n, s, o, a, i) {
442
442
  super();
443
- R(this, "_local$", new K("en"));
444
- R(this, "local$", this._local$.asObservable());
443
+ R(this, "_locale$", new K("en"));
444
+ R(this, "locale$", this._locale$.asObservable());
445
445
  this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = a, this._configService = i, this._initInterceptorCellContent();
446
446
  }
447
- get local() {
448
- const t = this._local$.getValue();
447
+ get locale() {
448
+ const t = this._locale$.getValue();
449
449
  if (t)
450
450
  return t;
451
451
  switch (this._localeService.getCurrentLocale()) {
@@ -461,6 +461,9 @@ let D = class extends ee {
461
461
  return "ko";
462
462
  case b.ZH_TW:
463
463
  return "zh-TW";
464
+ case b.ES_ES:
465
+ case b.CA_ES:
466
+ return "es";
464
467
  case b.EN_US:
465
468
  case b.FA_IR:
466
469
  default:
@@ -470,13 +473,13 @@ let D = class extends ee {
470
473
  // eslint-disable-next-line max-lines-per-function
471
474
  _initInterceptorCellContent() {
472
475
  const t = new M();
473
- this.disposeWithMe(Ie(this._local$, this._localeService.currentLocale$).subscribe(() => {
476
+ this.disposeWithMe(Ee(this._locale$, this._localeService.currentLocale$).subscribe(() => {
474
477
  t.reset();
475
478
  })), this.disposeWithMe(this._sheetInterceptorService.intercept($e.CELL_CONTENT, {
476
479
  effect: z.Value | z.Style,
477
480
  // eslint-disable-next-line complexity
478
481
  handler: (r, n, s) => {
479
- var C, p;
482
+ var C, S;
480
483
  const o = n.unitId, a = n.subUnitId;
481
484
  let i;
482
485
  const f = r;
@@ -494,12 +497,12 @@ let D = class extends ee {
494
497
  const y = t.getValue(n.row, n.col);
495
498
  if (y && y.parameters === `${f.v}_${i.pattern}`)
496
499
  return s({ ...r, ...y.result });
497
- const _ = Le(i.pattern, Number(f.v), this.local);
500
+ const _ = Le(i.pattern, Number(f.v), this.locale);
498
501
  if (u = _.result, !u)
499
502
  return s(r);
500
503
  const g = { v: u, t: $.NUMBER };
501
504
  if (_.color) {
502
- const m = (p = this._themeService.getColorFromTheme(`${_.color}.500`)) != null ? p : _.color;
505
+ const m = (S = this._themeService.getColorFromTheme(`${_.color}.500`)) != null ? S : _.color;
503
506
  m && (g.interceptorStyle = { cl: { rgb: m } });
504
507
  }
505
508
  return t.setValue(n.row, n.col, {
@@ -513,7 +516,7 @@ let D = class extends ee {
513
516
  const n = r.params;
514
517
  Object.keys(n.values).forEach((s) => {
515
518
  n.values[s].ranges.forEach((a) => {
516
- I.foreach(a, (i, f) => {
519
+ E.foreach(a, (i, f) => {
517
520
  t.realDeleteValue(i, f);
518
521
  });
519
522
  });
@@ -526,25 +529,25 @@ let D = class extends ee {
526
529
  }
527
530
  })), this.disposeWithMe(
528
531
  this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
529
- Te((r) => {
532
+ Ie((r) => {
530
533
  var n;
531
- return (n = r == null ? void 0 : r.activeSheet$) != null ? n : Ee(null);
534
+ return (n = r == null ? void 0 : r.activeSheet$) != null ? n : Te(null);
532
535
  }),
533
536
  xe(1)
534
537
  ).subscribe(() => t.reset())
535
538
  );
536
539
  }
537
540
  setNumfmtLocal(t) {
538
- this._local$.next(t);
541
+ this._locale$.next(t);
539
542
  }
540
543
  };
541
544
  D = Be([
542
545
  N(0, A),
543
- N(1, E(Me)),
544
- N(2, E(fe)),
545
- N(3, E(T)),
546
- N(4, E(W)),
547
- N(5, E(de)),
546
+ N(1, T(Me)),
547
+ N(2, T(fe)),
548
+ N(3, T(I)),
549
+ N(4, T(W)),
550
+ N(5, T(de)),
548
551
  N(6, Q)
549
552
  ], D);
550
553
  const We = "SHEET_NUMFMT_PLUGIN";
@@ -569,10 +572,10 @@ var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t
569
572
  (a = e[o]) && (s = a(s) || s);
570
573
  return s;
571
574
  }, L = (e, t) => (r, n) => t(r, n, e), ce = (e, t, r) => Ye(e, typeof t != "symbol" ? t + "" : t, r);
572
- let F = class extends pe {
575
+ let F = class extends Se {
573
576
  constructor(e = q, t, r, n) {
574
577
  super(), this._config = e, this._injector = t, this._configService = r, this._commandService = n;
575
- const { ...s } = ve(
578
+ const { ...s } = pe(
576
579
  {},
577
580
  q,
578
581
  this._config
@@ -580,7 +583,7 @@ let F = class extends pe {
580
583
  this._configService.setConfig(ae, s);
581
584
  }
582
585
  onStarting() {
583
- Se(this._injector, [
586
+ ve(this._injector, [
584
587
  [D],
585
588
  [oe],
586
589
  [J]
@@ -606,9 +609,9 @@ ce(F, "pluginName", We);
606
609
  ce(F, "type", te.UNIVER_SHEET);
607
610
  F = ke([
608
611
  he(Ne),
609
- L(1, E(ge)),
612
+ L(1, T(ge)),
610
613
  L(2, Q),
611
- L(3, T)
614
+ L(3, I)
612
615
  ], F);
613
616
  const rt = (e) => ne.find((r) => e.includes(r)), nt = () => ne.map((e) => ({ label: e, value: e })), st = (e) => se.map((t) => ({
614
617
  label: t.label(e),
package/lib/index.js CHANGED
@@ -1,9 +1,9 @@
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 R = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { numfmt as w, CommandType as V, ICommandService as T, IUniverInstanceService as A, IUndoRedoService as ue, isTextFormat as X, CellValueType as $, ObjectMatrix as M, sequenceExecute as me, Range as I, Inject as E, ThemeService as fe, LocaleService as de, IConfigService as Q, Disposable as ee, LocaleType as b, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as he, Injector as ge, Plugin as pe, merge as ve, registerDependencies as Se, touchDependencies as Y } from "@univerjs/core";
4
+ import { numfmt as w, CommandType as V, ICommandService as I, IUniverInstanceService as A, IUndoRedoService as ue, isTextFormat as X, CellValueType as $, ObjectMatrix as M, sequenceExecute as me, Range as E, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as Q, Disposable as ee, LocaleType as b, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as he, Injector as ge, Plugin as Se, merge as pe, registerDependencies as ve, touchDependencies as Y } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as k, SetNumfmtMutation as re, 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
- import { BehaviorSubject as K, merge as Ie, switchMap as Te, of as Ee, skip as xe } from "rxjs";
6
+ import { BehaviorSubject as K, merge as Ee, switchMap as Ie, of as Te, skip as xe } from "rxjs";
7
7
  import { stripErrorMargin as Ve } from "@univerjs/engine-formula";
8
8
  const ne = [
9
9
  "$",
@@ -190,7 +190,7 @@ const ne = [
190
190
  handler: (e, t) => {
191
191
  if (!t)
192
192
  return !1;
193
- const r = e.get(T), n = e.get(A), s = e.get(ue), o = H(n, t);
193
+ const r = e.get(I), n = e.get(A), s = e.get(ue), o = H(n, t);
194
194
  if (!o) return !1;
195
195
  const { unitId: a, subUnitId: i, worksheet: f } = o, u = t.values.filter((l) => !!l.pattern), y = t.values.filter((l) => !l.pattern), _ = ye(a, i, u), g = {
196
196
  unitId: a,
@@ -201,20 +201,20 @@ const ne = [
201
201
  endColumn: l.col,
202
202
  endRow: l.row
203
203
  }))
204
- }, C = [], p = [];
204
+ }, C = [], S = [];
205
205
  if (u.length) {
206
206
  const l = u.reduce((d, c) => {
207
207
  X(c.pattern) && d.setValue(c.row, c.col, { t: $.STRING });
208
- const S = f.getCellRaw(c.row, c.col);
209
- if (S) {
210
- const x = G(S.v);
211
- x !== S.t && d.setValue(c.row, c.col, { t: x });
208
+ const v = f.getCellRaw(c.row, c.col);
209
+ if (v) {
210
+ const x = G(v.v);
211
+ x !== v.t && d.setValue(c.row, c.col, { t: x });
212
212
  }
213
213
  return d;
214
214
  }, new M()).getMatrix(), h = new M();
215
215
  new M(l).forValue((d, c) => {
216
- const S = f.getCellRaw(d, c);
217
- S ? h.setValue(d, c, { t: S.t }) : h.setValue(d, c, { t: void 0 });
216
+ const v = f.getCellRaw(d, c);
217
+ v ? h.setValue(d, c, { t: v.t }) : h.setValue(d, c, { t: void 0 });
218
218
  }), Object.keys(_.values).forEach((d) => {
219
219
  const c = _.values[d];
220
220
  c.ranges = k(c.ranges);
@@ -222,22 +222,22 @@ const ne = [
222
222
  id: re.id,
223
223
  params: _
224
224
  });
225
- const v = _e(e, _);
226
- p.push(...v);
225
+ const p = _e(e, _);
226
+ S.push(...p);
227
227
  }
228
228
  if (y.length) {
229
229
  g.ranges = k(g.ranges);
230
230
  const l = y.reduce((d, c) => {
231
- const S = f.getCellRaw(c.row, c.col);
232
- if (S) {
233
- const x = G(S.v);
234
- x !== S.t && d.setValue(c.row, c.col, { t: x });
231
+ const v = f.getCellRaw(c.row, c.col);
232
+ if (v) {
233
+ const x = G(v.v);
234
+ x !== v.t && d.setValue(c.row, c.col, { t: x });
235
235
  }
236
236
  return d;
237
237
  }, new M()).getMatrix(), h = new M();
238
238
  new M(l).forValue((d, c) => {
239
- const S = f.getCellRaw(d, c);
240
- S ? h.setValue(d, c, { t: S.t }) : h.setValue(d, c, { t: void 0 });
239
+ const v = f.getCellRaw(d, c);
240
+ v ? h.setValue(d, c, { t: v.t }) : h.setValue(d, c, { t: void 0 });
241
241
  }), C.push({
242
242
  id: Ce.id,
243
243
  params: g
@@ -249,20 +249,20 @@ const ne = [
249
249
  cellValue: l
250
250
  }
251
251
  });
252
- const v = be(e, g);
253
- p.push({
252
+ const p = be(e, g);
253
+ S.push({
254
254
  id: B.id,
255
255
  params: {
256
256
  unitId: a,
257
257
  subUnitId: i,
258
258
  cellValue: h.getMatrix()
259
259
  }
260
- }, ...v);
260
+ }, ...p);
261
261
  }
262
262
  const m = me(C, r).result;
263
263
  return m && s.pushUndoRedo({
264
264
  unitID: a,
265
- undoMutations: p,
265
+ undoMutations: S,
266
266
  redoMutations: C
267
267
  }), m;
268
268
  }
@@ -270,7 +270,7 @@ const ne = [
270
270
  id: "sheet.command.numfmt.add.decimal.command",
271
271
  type: V.COMMAND,
272
272
  handler: async (e) => {
273
- const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
273
+ const t = e.get(I), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
274
274
  if (!o || !o.length)
275
275
  return !1;
276
276
  const a = H(s);
@@ -278,12 +278,12 @@ const ne = [
278
278
  const { unitId: i, subUnitId: f } = a;
279
279
  let u = 0;
280
280
  o.forEach((C) => {
281
- I.foreach(C.range, (p, m) => {
282
- const l = n.getValue(i, f, p, m);
281
+ E.foreach(C.range, (S, m) => {
282
+ const l = n.getValue(i, f, S, m);
283
283
  if (!l) {
284
- const v = a.worksheet.getCellRaw(p, m);
285
- if (!u && v && v.t === $.NUMBER && v.v) {
286
- const d = /\.(\d*)$/.exec(String(v.v));
284
+ const p = a.worksheet.getCellRaw(S, m);
285
+ if (!u && p && p.t === $.NUMBER && p.v) {
286
+ const d = /\.(\d*)$/.exec(String(p.v));
287
287
  if (d) {
288
288
  const c = d[1].length;
289
289
  if (!c)
@@ -299,20 +299,20 @@ const ne = [
299
299
  });
300
300
  const y = u + 1, _ = P(`0${y > 0 ? ".0" : ""}`, y), g = [];
301
301
  return o.forEach((C) => {
302
- I.foreach(C.range, (p, m) => {
303
- const l = n.getValue(i, f, p, m);
302
+ E.foreach(C.range, (S, m) => {
303
+ const l = n.getValue(i, f, S, m);
304
304
  if (!l)
305
305
  g.push({
306
- row: p,
306
+ row: S,
307
307
  col: m,
308
308
  pattern: _
309
309
  });
310
310
  else {
311
- const h = O(l.pattern), v = P(l.pattern, h + 1);
312
- v !== l.pattern && g.push({
313
- row: p,
311
+ const h = O(l.pattern), p = P(l.pattern, h + 1);
312
+ p !== l.pattern && g.push({
313
+ row: S,
314
314
  col: m,
315
- pattern: v
315
+ pattern: p
316
316
  });
317
317
  }
318
318
  });
@@ -338,12 +338,12 @@ const De = {
338
338
  id: "sheet.command.numfmt.set.currency",
339
339
  type: V.COMMAND,
340
340
  handler: async (e) => {
341
- const t = e.get(T), r = e.get(j), n = e.get(oe), s = Ue[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
341
+ const t = e.get(I), r = e.get(j), n = e.get(oe), s = Ue[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
342
342
  if (!o || !o.length)
343
343
  return !1;
344
344
  const a = [], i = se[4].suffix(s);
345
345
  return o.forEach((u) => {
346
- I.foreach(u.range, (y, _) => {
346
+ E.foreach(u.range, (y, _) => {
347
347
  a.push({ row: y, col: _, pattern: i, type: "currency" });
348
348
  });
349
349
  }), await t.executeCommand(U.id, { values: a });
@@ -352,12 +352,12 @@ const De = {
352
352
  id: "sheet.command.numfmt.set.percent",
353
353
  type: V.COMMAND,
354
354
  handler: async (e) => {
355
- const t = e.get(T), n = e.get(j).getCurrentSelections();
355
+ const t = e.get(I), n = e.get(j).getCurrentSelections();
356
356
  if (!n || !n.length)
357
357
  return !1;
358
358
  const s = [], o = "0%";
359
359
  return n.forEach((i) => {
360
- I.foreach(i.range, (f, u) => {
360
+ E.foreach(i.range, (f, u) => {
361
361
  s.push({ row: f, col: u, pattern: o, type: "percent" });
362
362
  });
363
363
  }), await t.executeCommand(U.id, { values: s });
@@ -366,36 +366,36 @@ const De = {
366
366
  id: "sheet.command.numfmt.subtract.decimal.command",
367
367
  type: V.COMMAND,
368
368
  handler: async (e) => {
369
- const t = e.get(T), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
369
+ const t = e.get(I), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
370
370
  if (!o || !o.length)
371
371
  return !1;
372
372
  const a = H(s);
373
373
  if (!a) return !1;
374
374
  const { unitId: i, subUnitId: f } = a;
375
375
  let u = 0;
376
- o.forEach((p) => {
377
- I.foreach(p.range, (m, l) => {
376
+ o.forEach((S) => {
377
+ E.foreach(S.range, (m, l) => {
378
378
  const h = n.getValue(i, f, m, l);
379
379
  if (!h) {
380
380
  const d = a.worksheet.getCellRaw(m, l);
381
381
  if (!u && d && d.t === $.NUMBER && d.v) {
382
382
  const c = /\.(\d*)$/.exec(String(d.v));
383
383
  if (c) {
384
- const S = c[1].length;
385
- if (!S)
384
+ const v = c[1].length;
385
+ if (!v)
386
386
  return;
387
- u = Math.max(u, S);
387
+ u = Math.max(u, v);
388
388
  }
389
389
  }
390
390
  return;
391
391
  }
392
- const v = O(h.pattern);
393
- u = v > u ? v : u;
392
+ const p = O(h.pattern);
393
+ u = p > u ? p : u;
394
394
  });
395
395
  });
396
396
  const y = u - 1, _ = P(`0${y > 0 ? ".0" : "."}`, y), g = [];
397
- return o.forEach((p) => {
398
- I.foreach(p.range, (m, l) => {
397
+ return o.forEach((S) => {
398
+ E.foreach(S.range, (m, l) => {
399
399
  const h = n.getValue(i, f, m, l);
400
400
  if (!h)
401
401
  g.push({
@@ -404,11 +404,11 @@ const De = {
404
404
  pattern: _
405
405
  });
406
406
  else {
407
- const v = O(h.pattern);
407
+ const p = O(h.pattern);
408
408
  g.push({
409
409
  row: m,
410
410
  col: l,
411
- pattern: P(h.pattern, v - 1)
411
+ pattern: P(h.pattern, p - 1)
412
412
  });
413
413
  }
414
414
  });
@@ -440,12 +440,12 @@ const He = {
440
440
  let D = class extends ee {
441
441
  constructor(t, r, n, s, o, a, i) {
442
442
  super();
443
- R(this, "_local$", new K("en"));
444
- R(this, "local$", this._local$.asObservable());
443
+ R(this, "_locale$", new K("en"));
444
+ R(this, "locale$", this._locale$.asObservable());
445
445
  this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = a, this._configService = i, this._initInterceptorCellContent();
446
446
  }
447
- get local() {
448
- const t = this._local$.getValue();
447
+ get locale() {
448
+ const t = this._locale$.getValue();
449
449
  if (t)
450
450
  return t;
451
451
  switch (this._localeService.getCurrentLocale()) {
@@ -461,6 +461,9 @@ let D = class extends ee {
461
461
  return "ko";
462
462
  case b.ZH_TW:
463
463
  return "zh-TW";
464
+ case b.ES_ES:
465
+ case b.CA_ES:
466
+ return "es";
464
467
  case b.EN_US:
465
468
  case b.FA_IR:
466
469
  default:
@@ -470,13 +473,13 @@ let D = class extends ee {
470
473
  // eslint-disable-next-line max-lines-per-function
471
474
  _initInterceptorCellContent() {
472
475
  const t = new M();
473
- this.disposeWithMe(Ie(this._local$, this._localeService.currentLocale$).subscribe(() => {
476
+ this.disposeWithMe(Ee(this._locale$, this._localeService.currentLocale$).subscribe(() => {
474
477
  t.reset();
475
478
  })), this.disposeWithMe(this._sheetInterceptorService.intercept($e.CELL_CONTENT, {
476
479
  effect: z.Value | z.Style,
477
480
  // eslint-disable-next-line complexity
478
481
  handler: (r, n, s) => {
479
- var C, p;
482
+ var C, S;
480
483
  const o = n.unitId, a = n.subUnitId;
481
484
  let i;
482
485
  const f = r;
@@ -494,12 +497,12 @@ let D = class extends ee {
494
497
  const y = t.getValue(n.row, n.col);
495
498
  if (y && y.parameters === `${f.v}_${i.pattern}`)
496
499
  return s({ ...r, ...y.result });
497
- const _ = Le(i.pattern, Number(f.v), this.local);
500
+ const _ = Le(i.pattern, Number(f.v), this.locale);
498
501
  if (u = _.result, !u)
499
502
  return s(r);
500
503
  const g = { v: u, t: $.NUMBER };
501
504
  if (_.color) {
502
- const m = (p = this._themeService.getColorFromTheme(`${_.color}.500`)) != null ? p : _.color;
505
+ const m = (S = this._themeService.getColorFromTheme(`${_.color}.500`)) != null ? S : _.color;
503
506
  m && (g.interceptorStyle = { cl: { rgb: m } });
504
507
  }
505
508
  return t.setValue(n.row, n.col, {
@@ -513,7 +516,7 @@ let D = class extends ee {
513
516
  const n = r.params;
514
517
  Object.keys(n.values).forEach((s) => {
515
518
  n.values[s].ranges.forEach((a) => {
516
- I.foreach(a, (i, f) => {
519
+ E.foreach(a, (i, f) => {
517
520
  t.realDeleteValue(i, f);
518
521
  });
519
522
  });
@@ -526,25 +529,25 @@ let D = class extends ee {
526
529
  }
527
530
  })), this.disposeWithMe(
528
531
  this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
529
- Te((r) => {
532
+ Ie((r) => {
530
533
  var n;
531
- return (n = r == null ? void 0 : r.activeSheet$) != null ? n : Ee(null);
534
+ return (n = r == null ? void 0 : r.activeSheet$) != null ? n : Te(null);
532
535
  }),
533
536
  xe(1)
534
537
  ).subscribe(() => t.reset())
535
538
  );
536
539
  }
537
540
  setNumfmtLocal(t) {
538
- this._local$.next(t);
541
+ this._locale$.next(t);
539
542
  }
540
543
  };
541
544
  D = Be([
542
545
  N(0, A),
543
- N(1, E(Me)),
544
- N(2, E(fe)),
545
- N(3, E(T)),
546
- N(4, E(W)),
547
- N(5, E(de)),
546
+ N(1, T(Me)),
547
+ N(2, T(fe)),
548
+ N(3, T(I)),
549
+ N(4, T(W)),
550
+ N(5, T(de)),
548
551
  N(6, Q)
549
552
  ], D);
550
553
  const We = "SHEET_NUMFMT_PLUGIN";
@@ -569,10 +572,10 @@ var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t
569
572
  (a = e[o]) && (s = a(s) || s);
570
573
  return s;
571
574
  }, L = (e, t) => (r, n) => t(r, n, e), ce = (e, t, r) => Ye(e, typeof t != "symbol" ? t + "" : t, r);
572
- let F = class extends pe {
575
+ let F = class extends Se {
573
576
  constructor(e = q, t, r, n) {
574
577
  super(), this._config = e, this._injector = t, this._configService = r, this._commandService = n;
575
- const { ...s } = ve(
578
+ const { ...s } = pe(
576
579
  {},
577
580
  q,
578
581
  this._config
@@ -580,7 +583,7 @@ let F = class extends pe {
580
583
  this._configService.setConfig(ae, s);
581
584
  }
582
585
  onStarting() {
583
- Se(this._injector, [
586
+ ve(this._injector, [
584
587
  [D],
585
588
  [oe],
586
589
  [J]
@@ -606,9 +609,9 @@ ce(F, "pluginName", We);
606
609
  ce(F, "type", te.UNIVER_SHEET);
607
610
  F = ke([
608
611
  he(Ne),
609
- L(1, E(ge)),
612
+ L(1, T(ge)),
610
613
  L(2, Q),
611
- L(3, T)
614
+ L(3, I)
612
615
  ], F);
613
616
  const rt = (e) => ne.find((r) => e.includes(r)), nt = () => ne.map((e) => ({ label: e, value: e })), st = (e) => se.map((t) => ({
614
617
  label: t.label(e),
@@ -1,4 +1,4 @@
1
- import { INumfmtLocalTag, Disposable, ICommandService, IConfigService, IUniverInstanceService, LocaleService, ThemeService } from '@univerjs/core';
1
+ import { INumfmtLocaleTag, Disposable, ICommandService, IConfigService, IUniverInstanceService, LocaleService, ThemeService } from '@univerjs/core';
2
2
  import { INumfmtService, SheetInterceptorService } from '@univerjs/sheets';
3
3
  export declare class SheetsNumfmtCellContentController extends Disposable {
4
4
  private readonly _instanceService;
@@ -8,10 +8,10 @@ export declare class SheetsNumfmtCellContentController extends Disposable {
8
8
  private _numfmtService;
9
9
  private _localeService;
10
10
  private readonly _configService;
11
- private _local$;
12
- local$: import('rxjs').Observable<INumfmtLocalTag>;
11
+ private _locale$;
12
+ locale$: import('rxjs').Observable<INumfmtLocaleTag>;
13
13
  constructor(_instanceService: IUniverInstanceService, _sheetInterceptorService: SheetInterceptorService, _themeService: ThemeService, _commandService: ICommandService, _numfmtService: INumfmtService, _localeService: LocaleService, _configService: IConfigService);
14
- get local(): INumfmtLocalTag;
14
+ get locale(): INumfmtLocaleTag;
15
15
  private _initInterceptorCellContent;
16
- setNumfmtLocal(local: INumfmtLocalTag): void;
16
+ setNumfmtLocal(locale: INumfmtLocaleTag): void;
17
17
  }
@@ -1,9 +1,9 @@
1
- import { INumfmtLocalTag } from '@univerjs/core';
1
+ import { INumfmtLocaleTag } from '@univerjs/core';
2
2
  import { FWorkbook } from '@univerjs/sheets/facade';
3
3
  export interface IFWorkbookNumfmtMixin {
4
4
  /**
5
5
  * Set the locale for number formatting.
6
- * @param {INumfmtLocalTag} local zh_CN,zh_TW,zh_HK,ja,ko,th,cs,da,nl,en,en_AU,en_CA,en_GB,en_IE,fi,fr,fr_CA,fr_CH,de,de_CH,el,hu,is,id,it,it_CH,nb,no,pl,pt,pt_BR,ru,sk,es,es_AR,es_BO,es_CL,es_CO,es_EC,es_MX,es_PY,es_UY,es_VE,sv,tr,cy,az,be,bg,ca,fil,gu,he,hr,hy,ka,kk,kn,lt,lv,ml,mn,mr,my,pa,ro,sl,sr,ta,te,uk,vi,ar,bn,hi
6
+ * @param {INumfmtLocaleTag} locale zh_CN,zh_TW,zh_HK,ja,ko,th,cs,da,nl,en,en_AU,en_CA,en_GB,en_IE,fi,fr,fr_CA,fr_CH,de,de_CH,el,hu,is,id,it,it_CH,nb,no,pl,pt,pt_BR,ru,sk,es,es_AR,es_BO,es_CL,es_CO,es_EC,es_MX,es_PY,es_UY,es_VE,sv,tr,cy,az,be,bg,ca,fil,gu,he,hr,hy,ka,kk,kn,lt,lv,ml,mn,mr,my,pa,ro,sl,sr,ta,te,uk,vi,ar,bn,hi
7
7
  * @returns {FWorkbook} The FWorkbook instance for chaining.
8
8
  * @memberof IFWorkbookNumfmtMixin
9
9
  * @example
@@ -22,10 +22,10 @@ export interface IFWorkbookNumfmtMixin {
22
22
  * console.log(fRange.getDisplayValue()); // 1.234,57
23
23
  * ```
24
24
  */
25
- setNumfmtLocal(local: INumfmtLocalTag): FWorkbook;
25
+ setNumfmtLocal(locale: INumfmtLocaleTag): FWorkbook;
26
26
  }
27
27
  export declare class FWorkbookLegacy extends FWorkbook implements IFWorkbookNumfmtMixin {
28
- setNumfmtLocal(local: INumfmtLocalTag): FWorkbook;
28
+ setNumfmtLocal(locale: INumfmtLocaleTag): FWorkbook;
29
29
  }
30
30
  declare module '@univerjs/sheets/facade' {
31
31
  interface FWorkbook extends IFWorkbookNumfmtMixin {
@@ -1,10 +1,10 @@
1
- import { INumfmtLocalTag } from '@univerjs/core';
1
+ import { INumfmtLocaleTag } from '@univerjs/core';
2
2
  import { FormatType } from '@univerjs/sheets';
3
3
  export declare const getPatternType: (pattern: string) => FormatType;
4
4
  interface IPatternPreview {
5
5
  result: string;
6
6
  color?: string;
7
7
  }
8
- export declare const getPatternPreview: (pattern: string, value: number, locale?: INumfmtLocalTag) => IPatternPreview;
9
- export declare const getPatternPreviewIgnoreGeneral: (pattern: string, value: number, locale?: INumfmtLocalTag) => IPatternPreview;
8
+ export declare const getPatternPreview: (pattern: string, value: number, locale?: INumfmtLocaleTag) => IPatternPreview;
9
+ export declare const getPatternPreviewIgnoreGeneral: (pattern: string, value: number, locale?: INumfmtLocaleTag) => IPatternPreview;
10
10
  export {};
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("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,o,I,Z){"use strict";var fe=Object.defineProperty;var de=(a,t,o)=>t in a?fe(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o;var R=(a,t,o)=>de(a,typeof t!="symbol"?t+"":t,o);const P=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],A={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:"€"},L=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],G=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],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"}],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(";"),J=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=o.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:d}=l,c=r.values.filter(u=>!!u.pattern),b=r.values.filter(u=>!u.pattern),M=o.transformCellsToRange(m,S,c),C={unitId:m,subUnitId:S,ranges:b.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],y=[];if(c.length){const u=c.reduce((g,f)=>{t.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?h.setValue(g,f,{t:_.t}):h.setValue(g,f,{t:void 0})}),Object.keys(M.values).forEach(g=>{const f=M.values[g];f.ranges=o.rangeMerge(f.ranges)}),T.push({id:o.SetNumfmtMutation.id,params:M});const p=o.factorySetNumfmtUndoMutation(e,M);y.push(...p)}if(b.length){C.ranges=o.rangeMerge(C.ranges);const u=b.reduce((g,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?h.setValue(g,f,{t:_.t}):h.setValue(g,f,{t:void 0})}),T.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const p=o.factoryRemoveNumfmtUndoMutation(e,C);y.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:h.getMatrix()}},...p)}const v=t.sequenceExecute(T,i).result;return v&&s.pushUndoRedo({unitID:m,undoMutations:y,redoMutations:T}),v}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;l.forEach(T=>{t.Range.foreach(T.range,(y,v)=>{const u=n.getValue(S,d,y,v);if(!u){const p=m.worksheet.getCellRaw(y,v);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const g=/\.(\d*)$/.exec(String(p.v));if(g){const f=g[1].length;if(!f)return;c=Math.max(c,f)}}return}const h=E(u.pattern);c=h>c?h:c})});const b=c+1,M=U(`0${b>0?".0":""}`,b),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(y,v)=>{const u=n.getValue(S,d,y,v);if(!u)C.push({row:y,col:v,pattern:M});else{const h=E(u.pattern),p=U(u.pattern,h+1);p!==u.pattern&&C.push({row:y,col:v,pattern:p})}})}),C.length?await r.executeCommand($.id,{values:C}):!1}};class w{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 B={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(w),s=A[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],S=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(b,M)=>{m.push({row:b,col:M,pattern:S,type:"currency"})})}),await r.executeCommand($.id,{values:m})}},H={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.id,{values:s})}},K={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;l.forEach(y=>{t.Range.foreach(y.range,(v,u)=>{const h=n.getValue(S,d,v,u);if(!h){const g=m.worksheet.getCellRaw(v,u);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(h.pattern);c=p>c?p:c})});const b=c-1,M=U(`0${b>0?".0":"."}`,b),C=[];return l.forEach(y=>{t.Range.foreach(y.range,(v,u)=>{const h=n.getValue(S,d,v,u);if(!h)C.push({row:v,col:u,pattern:M});else{const p=E(h.pattern);C.push({row:v,col:u,pattern:U(h.pattern,p-1)})}})}),await r.executeCommand($.id,{values:C})}},j="sheets-numfmt.config",W={},X=e=>t.numfmt.getFormatInfo(e).type||"unknown",q=(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}},Y=(e,r,i)=>e==="General"?{result:String(Z.stripErrorMargin(r))}:q(e,r,i);var Q=Object.getOwnPropertyDescriptor,ee=(e,r,i,n)=>{for(var s=n>1?void 0:n?Q(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 te={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,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=S,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.KO_KR:return"ko";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(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var y,v;const m=s.unitId,S=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 u=s.workbook.getStyles().get(n.s);u!=null&&u.n&&(d=u.n)}if(d||(d=this._numfmtService.getValue(m,S,s.row,s.col)),!d||d.pattern==="General"||c.t!==t.CellValueType.NUMBER&&o.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(d.pattern))return(y=this._configService.getConfig(j))!=null&&y.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...te},l(n));let b="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${c.v}_${d.pattern}`)return l({...n,...M.result});const C=Y(d.pattern,Number(c.v),this.local);if(b=C.result,!b)return l(n);const T={v:b,t:t.CellValueType.NUMBER};if(C.color){const u=(v=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?v:C.color;u&&(T.interceptorStyle={cl:{rgb:u}})}return i.setValue(s.row,s.col,{result:T,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,T),l(n)},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(d,c)=>{i.realDeleteValue(d,c)})})})}else if(n.id===o.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=ee([N(0,t.IUniverInstanceService),N(1,t.Inject(o.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(o.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);const ne="SHEET_NUMFMT_PLUGIN";class k 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 re=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,ie=(e,r,i)=>r in e?re(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,se=(e,r,i,n)=>{for(var s=n>1?void 0:n?ae(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)=>ie(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=W,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},W,this._config);this._configService.setConfig(j,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[w],[k]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[k]]),[x,K,B,H,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},z(a.UniverSheetsNumfmtPlugin,"pluginName",ne),z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=se([t.DependentOn(o.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const le=e=>P.find(i=>e.includes(i)),ue=()=>P.map(e=>({label:e,value:e})),ce=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),oe=()=>L.map(e=>({label:e.label,value:e.suffix})),me=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=x,a.CURRENCYFORMAT=V,a.DATEFMTLISG=L,a.MenuCurrencyService=w,a.NUMBERFORMAT=G,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=j,a.SetCurrencyCommand=B,a.SetNumfmtCommand=$,a.SetPercentCommand=H,a.SubtractDecimalCommand=K,a.countryCurrencyMap=A,a.currencySymbols=P,a.getCurrencyFormatOptions=ce,a.getCurrencyOptions=ue,a.getCurrencyType=le,a.getDateFormatOptions=oe,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=me,a.getPatternPreview=q,a.getPatternPreviewIgnoreGeneral=Y,a.getPatternType=X,a.isPatternHasDecimal=J,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("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,o,I,Z){"use strict";var fe=Object.defineProperty;var de=(a,t,o)=>t in a?fe(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o;var R=(a,t,o)=>de(a,typeof t!="symbol"?t+"":t,o);const P=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],A={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:"€"},L=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],G=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],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"}],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(";"),J=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=o.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:d}=l,c=r.values.filter(u=>!!u.pattern),b=r.values.filter(u=>!u.pattern),M=o.transformCellsToRange(m,S,c),C={unitId:m,subUnitId:S,ranges:b.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],h=[];if(c.length){const u=c.reduce((g,f)=>{t.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?y.setValue(g,f,{t:_.t}):y.setValue(g,f,{t:void 0})}),Object.keys(M.values).forEach(g=>{const f=M.values[g];f.ranges=o.rangeMerge(f.ranges)}),T.push({id:o.SetNumfmtMutation.id,params:M});const p=o.factorySetNumfmtUndoMutation(e,M);h.push(...p)}if(b.length){C.ranges=o.rangeMerge(C.ranges);const u=b.reduce((g,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?y.setValue(g,f,{t:_.t}):y.setValue(g,f,{t:void 0})}),T.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const p=o.factoryRemoveNumfmtUndoMutation(e,C);h.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:y.getMatrix()}},...p)}const v=t.sequenceExecute(T,i).result;return v&&s.pushUndoRedo({unitID:m,undoMutations:h,redoMutations:T}),v}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;l.forEach(T=>{t.Range.foreach(T.range,(h,v)=>{const u=n.getValue(S,d,h,v);if(!u){const p=m.worksheet.getCellRaw(h,v);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const g=/\.(\d*)$/.exec(String(p.v));if(g){const f=g[1].length;if(!f)return;c=Math.max(c,f)}}return}const y=E(u.pattern);c=y>c?y:c})});const b=c+1,M=U(`0${b>0?".0":""}`,b),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(h,v)=>{const u=n.getValue(S,d,h,v);if(!u)C.push({row:h,col:v,pattern:M});else{const y=E(u.pattern),p=U(u.pattern,y+1);p!==u.pattern&&C.push({row:h,col:v,pattern:p})}})}),C.length?await r.executeCommand($.id,{values:C}):!1}};class w{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 B={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(w),s=A[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],S=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(b,M)=>{m.push({row:b,col:M,pattern:S,type:"currency"})})}),await r.executeCommand($.id,{values:m})}},H={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.id,{values:s})}},K={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;l.forEach(h=>{t.Range.foreach(h.range,(v,u)=>{const y=n.getValue(S,d,v,u);if(!y){const g=m.worksheet.getCellRaw(v,u);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(y.pattern);c=p>c?p:c})});const b=c-1,M=U(`0${b>0?".0":"."}`,b),C=[];return l.forEach(h=>{t.Range.foreach(h.range,(v,u)=>{const y=n.getValue(S,d,v,u);if(!y)C.push({row:v,col:u,pattern:M});else{const p=E(y.pattern);C.push({row:v,col:u,pattern:U(y.pattern,p-1)})}})}),await r.executeCommand($.id,{values:C})}},j="sheets-numfmt.config",W={},X=e=>t.numfmt.getFormatInfo(e).type||"unknown",q=(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}},Y=(e,r,i)=>e==="General"?{result:String(Z.stripErrorMargin(r))}:q(e,r,i);var Q=Object.getOwnPropertyDescriptor,ee=(e,r,i,n)=>{for(var s=n>1?void 0:n?Q(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 te={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,d){super();R(this,"_locale$",new I.BehaviorSubject("en"));R(this,"locale$",this._locale$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=d,this._initInterceptorCellContent()}get locale(){const i=this._locale$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var h,v;const m=s.unitId,S=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 u=s.workbook.getStyles().get(n.s);u!=null&&u.n&&(d=u.n)}if(d||(d=this._numfmtService.getValue(m,S,s.row,s.col)),!d||d.pattern==="General"||c.t!==t.CellValueType.NUMBER&&o.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(d.pattern))return(h=this._configService.getConfig(j))!=null&&h.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...te},l(n));let b="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${c.v}_${d.pattern}`)return l({...n,...M.result});const C=Y(d.pattern,Number(c.v),this.locale);if(b=C.result,!b)return l(n);const T={v:b,t:t.CellValueType.NUMBER};if(C.color){const u=(v=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?v:C.color;u&&(T.interceptorStyle={cl:{rgb:u}})}return i.setValue(s.row,s.col,{result:T,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,T),l(n)},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(d,c)=>{i.realDeleteValue(d,c)})})})}else if(n.id===o.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._locale$.next(i)}},a.SheetsNumfmtCellContentController=ee([N(0,t.IUniverInstanceService),N(1,t.Inject(o.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(o.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);const ne="SHEET_NUMFMT_PLUGIN";class k 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 re=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,ie=(e,r,i)=>r in e?re(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,se=(e,r,i,n)=>{for(var s=n>1?void 0:n?ae(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)=>ie(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=W,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},W,this._config);this._configService.setConfig(j,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[w],[k]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[k]]),[x,K,B,H,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},z(a.UniverSheetsNumfmtPlugin,"pluginName",ne),z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=se([t.DependentOn(o.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const le=e=>P.find(i=>e.includes(i)),ue=()=>P.map(e=>({label:e,value:e})),ce=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),oe=()=>L.map(e=>({label:e.label,value:e.suffix})),me=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=x,a.CURRENCYFORMAT=V,a.DATEFMTLISG=L,a.MenuCurrencyService=w,a.NUMBERFORMAT=G,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=j,a.SetCurrencyCommand=B,a.SetNumfmtCommand=$,a.SetPercentCommand=H,a.SubtractDecimalCommand=K,a.countryCurrencyMap=A,a.currencySymbols=P,a.getCurrencyFormatOptions=ce,a.getCurrencyOptions=ue,a.getCurrencyType=le,a.getDateFormatOptions=oe,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=me,a.getPatternPreview=q,a.getPatternPreviewIgnoreGeneral=Y,a.getPatternType=X,a.isPatternHasDecimal=J,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.9.2-nightly.202507141607",
3
+ "version": "0.9.2-nightly.202507151607",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -58,9 +58,9 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/core": "0.9.2-nightly.202507141607",
62
- "@univerjs/engine-formula": "0.9.2-nightly.202507141607",
63
- "@univerjs/sheets": "0.9.2-nightly.202507141607"
61
+ "@univerjs/core": "0.9.2-nightly.202507151607",
62
+ "@univerjs/engine-formula": "0.9.2-nightly.202507151607",
63
+ "@univerjs/sheets": "0.9.2-nightly.202507151607"
64
64
  },
65
65
  "devDependencies": {
66
66
  "rxjs": "^7.8.2",