@univerjs/sheets-numfmt 0.10.8 → 0.10.9-experimental.20250925-61b61a0
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 +1 -1
- package/lib/es/index.js +244 -251
- package/lib/index.js +244 -251
- package/lib/types/index.d.ts +1 -1
- package/lib/types/utils/pattern.d.ts +1 -5
- package/lib/umd/index.js +1 -1
- package/package.json +5 -5
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Y=Object.defineProperty;var X=(e,r,s)=>r in e?Y(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var O=(e,r,s)=>X(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),I=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function w(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function A(e,r=2){let s=r;r>127&&(s=127);let n="";return s>0&&(n=`.${"0".repeat(s)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const j=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],G=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],P=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${L(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${L(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:i}=o,u=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=f.transformCellsToRange(l,d,u),S={unitId:l,subUnitId:d,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],C=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const v=i.getCellRaw(m.row,m.col);if(v){const N=f.checkCellValueType(v.v);N!==v.t&&g.setValue(m.row,m.col,{t:N})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?h.setValue(g,m,{t:v.t}):h.setValue(g,m,{t:void 0})}),Object.keys(T.values).forEach(g=>{const m=T.values[g];m.ranges=f.rangeMerge(m.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:T});const y=f.factorySetNumfmtUndoMutation(e,T);C.push(...y)}if(_.length){S.ranges=f.rangeMerge(S.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const N=f.checkCellValueType(v.v);N!==v.t&&g.setValue(m.row,m.col,{t:N})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?h.setValue(g,m,{t:v.t}):h.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:S},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,S);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:h.getMatrix()}},...y)}const p=t.sequenceExecute(M,s).result;return p&&a.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),p}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,p)=>{const c=n.getValue(d,i,C,p);if(!c){const y=l.worksheet.getCellRaw(C,p);if(!u&&y&&y.t===t.CellValueType.NUMBER&&y.v){const g=/\.(\d*)$/.exec(String(y.v));if(g){const m=g[1].length;if(!m)return;u=Math.max(u,m)}}return}const h=P(c.pattern);u=h>u?h:u})});const _=u+1,T=$(`0${_>0?".0":""}`,_),S=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,p)=>{const c=n.getValue(d,i,C,p);if(!c)S.push({row:C,col:p,pattern:T});else{const h=P(c.pattern),y=$(c.pattern,h+1);y!==c.pattern&&S.push({row:C,col:p,pattern:y})}})}),S.length?await r.executeCommand(R.id,{values:S}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const o=[],l=w(n.getCurrentLocale()),d=A(l.locale);return a.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(R.id,{values:o})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{a.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.range,(p,c)=>{const h=n.getValue(d,i,p,c);if(!h){const g=l.worksheet.getCellRaw(p,c);if(!u&&g&&g.t===t.CellValueType.NUMBER&&g.v){const m=/\.(\d*)$/.exec(String(g.v));if(m){const v=m[1].length;if(!v)return;u=Math.max(u,v)}}return}const y=P(h.pattern);u=y>u?y:u})});const _=u-1,T=$(`0${_>0?".0":"."}`,_),S=[];return o.forEach(C=>{t.Range.foreach(C.range,(p,c)=>{const h=n.getValue(d,i,p,c);if(!h)S.push({row:p,col:c,pattern:T});else{const y=P(h.pattern);S.push({row:p,col:c,pattern:$(h.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:S})}},V="sheets-numfmt.config",D={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,s="en")=>{const n=t.numfmt.formatColor(e,r),a=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a}:{result:o}},k=(e,r,s)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,s),te=new Set(["m d"]),ne=new Set(["h:mm AM/PM","hh:mm AM/PM"]),re=e=>{var n,a;const r=(a=(n=t.numfmt.parseDate(e))!=null?n:t.numfmt.parseTime(e))!=null?a:t.numfmt.parseNumber(e);if(!r)return null;const{z:s}=r;return s&&(te.has(s)||ne.has(s)&&!/\s(A|AM|P|PM)$/i.test(e))?null:r};var se=Object.getOwnPropertyDescriptor,ae=(e,r,s,n)=>{for(var a=n>1?void 0:n?se(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},b=(e,r)=>(s,n)=>r(s,n,e);const oe={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,d,i){super();O(this,"_locale$",new I.BehaviorSubject("en"));O(this,"locale$",this._locale$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const s=this._locale$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var C,p;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return o(n);const l=a.unitId,d=a.subUnitId;let i;if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,a.row,a.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===a.rawData)&&(n={...a.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(C=this._configService.getConfig(V))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...oe},o(n));let _="";const T=s.getValue(a.row,a.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const S=k(i==null?void 0:i.pattern,Number(u.v),this.locale);if(_=S.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(S.color){const c=(p=this._themeService.getColorFromTheme(`${S.color}.500`))!=null?p:S.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{s.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:I.of(null)}),I.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._locale$.next(s)}};exports.SheetsNumfmtCellContentController=ae([b(0,t.IUniverInstanceService),b(1,t.Inject(f.SheetInterceptorService)),b(2,t.Inject(t.ThemeService)),b(3,t.Inject(t.ICommandService)),b(4,t.Inject(f.INumfmtService)),b(5,t.Inject(t.LocaleService)),b(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const ce="SHEET_NUMFMT_PLUGIN";var ie=Object.defineProperty,le=Object.getOwnPropertyDescriptor,ue=(e,r,s)=>r in e?ie(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,me=(e,r,s,n)=>{for(var a=n>1?void 0:n?le(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},U=(e,r)=>(s,n)=>r(s,n,e),z=(e,r,s)=>ue(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=D,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},D,this._config);this._configService.setConfig(V,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){[H,q,W,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",ce);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=me([t.DependentOn(f.UniverSheetsPlugin),U(1,t.Inject(t.Injector)),U(2,t.IConfigService),U(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const fe=e=>x.find(s=>e.includes(s)),ge=()=>x.map(e=>({label:e,value:e})),de=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),pe=()=>j.map(e=>({label:e.label,value:e.suffix})),Se=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=j;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=V;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=x;exports.getCurrencyFormat=A;exports.getCurrencyFormatOptions=de;exports.getCurrencyOptions=ge;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=w;exports.getCurrencyType=fe;exports.getDateFormatOptions=pe;exports.getDecimalFromPattern=P;exports.getDecimalString=L;exports.getNumberFormatOptions=Se;exports.getNumfmtParseValueFilter=re;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=$;
|
|
1
|
+
"use strict";var z=Object.defineProperty;var X=(e,r,a)=>r in e?z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a;var U=(e,r,a)=>X(e,typeof r!="symbol"?r+"":r,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function V(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function j(e,r=2){let a=r;r>127&&(a=127);let n="";return a>0&&(n=`.${"0".repeat(a)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const A=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],G=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],$=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),O=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${L(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${L(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const a=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:i}=o,u=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=f.transformCellsToRange(l,d,u),h={unitId:l,subUnitId:d,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],C=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.t}):p.setValue(g,m,{t:void 0})}),Object.keys(T.values).forEach(g=>{const m=T.values[g];m.ranges=f.rangeMerge(m.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:T});const y=f.factorySetNumfmtUndoMutation(e,T);C.push(...y)}if(_.length){h.ranges=f.rangeMerge(h.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.t}):p.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,h);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:p.getMatrix()}},...y)}const S=t.sequenceExecute(M,a).result;return S&&s.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),S}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(!c){const y=l.worksheet.getCellRaw(C,S);if(!u&&y&&y.t===t.CellValueType.NUMBER&&y.v){const g=/\.(\d*)$/.exec(String(y.v));if(g){const m=g[1].length;if(!m)return;u=Math.max(u,m)}}return}const p=$(c.pattern);u=p>u?p:u})});const _=u+1,T=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(t.isDefaultFormat(c==null?void 0:c.pattern))h.push({row:C,col:S,pattern:T});else{const p=$(c.pattern),y=O(c.pattern,p+1);y!==c.pattern&&h.push({row:C,col:S,pattern:y})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),s=a.getCurrentSelections();if(!s||!s.length)return!1;const o=[],l=V(n.getCurrentLocale()),d=j(l.locale);return s.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(R.id,{values:o})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{s.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(!p){const g=l.worksheet.getCellRaw(S,c);if(!u&&g&&g.t===t.CellValueType.NUMBER&&g.v){const m=/\.(\d*)$/.exec(String(g.v));if(m){const v=m[1].length;if(!v)return;u=Math.max(u,v)}}return}const y=$(p.pattern);u=y>u?y:u})});const _=u-1,T=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(C=>{t.Range.foreach(C.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(t.isDefaultFormat(p==null?void 0:p.pattern))h.push({row:S,col:c,pattern:T});else{const y=$(p.pattern);h.push({row:S,col:c,pattern:O(p.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:h})}},D="sheets-numfmt.config",w={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,a="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:a,throws:!1});return r<0?{result:o,color:s}:{result:o}},k=(e,r,a)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,a);var te=Object.getOwnPropertyDescriptor,ne=(e,r,a,n)=>{for(var s=n>1?void 0:n?te(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},b=(e,r)=>(a,n)=>r(a,n,e);const re={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(a,n,s,o,l,d,i){super();U(this,"_locale$",new N.BehaviorSubject("en"));U(this,"locale$",this._locale$.asObservable());this._instanceService=a,this._sheetInterceptorService=n,this._themeService=s,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const a=this._locale$.getValue();if(a)return a;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const a=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{a.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,o)=>{var C,S;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return o(n);const l=s.unitId,d=s.subUnitId;let i;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,s.row,s.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(C=this._configService.getConfig(D))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...re},o(n));let _="";const T=a.getValue(s.row,s.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const h=k(i==null?void 0:i.pattern,Number(u.v),this.locale);if(_=h.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(h.color){const c=(S=this._themeService.getColorFromTheme(`${h.color}.500`))!=null?S:h.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return a.setValue(s.row,s.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(o=>{s.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{a.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((o,l)=>{a.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>a.reset()))}setNumfmtLocal(a){this._locale$.next(a)}};exports.SheetsNumfmtCellContentController=ne([b(0,t.IUniverInstanceService),b(1,t.Inject(f.SheetInterceptorService)),b(2,t.Inject(t.ThemeService)),b(3,t.Inject(t.ICommandService)),b(4,t.Inject(f.INumfmtService)),b(5,t.Inject(t.LocaleService)),b(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var se=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,a)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,ie=(e,r,a,n)=>{for(var s=n>1?void 0:n?oe(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},P=(e,r)=>(a,n)=>r(a,n,e),Y=(e,r,a)=>ce(e,typeof r!="symbol"?r+"":r,a);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=w,a,n,s){super(),this._config=r,this._injector=a,this._configService=n,this._commandService=s;const{...o}=t.merge({},w,this._config);this._configService.setConfig(D,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){[H,q,W,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};Y(exports.UniverSheetsNumfmtPlugin,"pluginName",ae);Y(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(f.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>x.find(a=>e.includes(a)),ue=()=>x.map(e=>({label:e,value:e})),me=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>A.map(e=>({label:e.label,value:e.suffix})),ge=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=A;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=x;exports.getCurrencyFormat=j;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=V;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=$;exports.getDecimalString=L;exports.getNumberFormatOptions=ge;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=O;
|