@univerjs/sheets-numfmt 0.6.6 → 0.6.7-experimental.20250328-3aaa828
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 +251 -238
- package/lib/facade.js +42 -0
- package/lib/index.js +666 -0
- package/lib/types/controllers/config.schema.d.ts +28 -0
- package/lib/types/controllers/numfmt-cell-content.controller.d.ts +3 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/numfmt-plugin.d.ts +4 -2
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var K=Object.defineProperty;var Y=(e,n,s)=>n in e?K(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s;var T=(e,n,s)=>Y(e,typeof n!="symbol"?n+"":n,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),m=require("@univerjs/sheets"),j=require("@univerjs/engine-numfmt"),I=require("rxjs"),Z=require("@univerjs/engine-formula"),O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],F={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:"€"},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"}],L=[{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"}],J="SHEET_NUMFMT_PLUGIN",E=(e,n=0)=>{var r;return e&&(r=t.numfmt.getInfo(e).maxDecimals)!=null?r:n},X=(e,n)=>{if(e&&!n||!e&&n)return!1;const s=c=>c.reduce((S,v)=>{if(S.isEnd)return S;const p=v.value||v.num;return v.type==="point"?(S.isEnd=!0,S):{...S,result:S.result+p}},{isEnd:!1,result:""}).result,r=t.numfmt.getInfo(e)._partitions,o=t.numfmt.getInfo(n)._partitions,a=s(r[0].tokens),i=s(o[0].tokens),h=s(r[1].tokens),f=s(o[1].tokens);return a===i&&h===f&&r[1].color===o[1].color},x=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,n)=>e.split(";").map(r=>/\.0?/.test(r)?r.replace(/\.0*/g,`${n>0?".":""}${x(Number(n||0))}`):/0([^0]?)|0$/.test(r)?r.replace(/0([^0]+)|0$/,`0${n>0?".":""}${x(Number(n||0))}$1`):r).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),N={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,n)=>{if(!n)return!1;const s=e.get(t.ICommandService),r=e.get(t.IUniverInstanceService),o=e.get(t.IUndoRedoService),a=m.getSheetCommandTarget(r,n);if(!a)return!1;const{unitId:i,subUnitId:h,worksheet:f}=a,c=n.values.filter(u=>!!u.pattern),S=n.values.filter(u=>!u.pattern),v=m.transformCellsToRange(i,h,c),p={unitId:i,subUnitId:h,ranges:S.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},M=[],C=[];if(c.length){const u=c.reduce((g,l)=>{j.isTextFormat(l.pattern)&&g.setValue(l.row,l.col,{t:t.CellValueType.STRING});const _=f.getCellRaw(l.row,l.col);if(_){const $=m.checkCellValueType(_.v);$!==_.t&&g.setValue(l.row,l.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,l)=>{const _=f.getCellRaw(g,l);_?y.setValue(g,l,{t:_.t}):y.setValue(g,l,{t:void 0})}),Object.keys(v.values).forEach(g=>{const l=v.values[g];l.ranges=m.rangeMerge(l.ranges)}),M.push({id:m.SetNumfmtMutation.id,params:v});const b=m.factorySetNumfmtUndoMutation(e,v);C.push(...b)}if(S.length){p.ranges=m.rangeMerge(p.ranges);const u=S.reduce((g,l)=>{const _=f.getCellRaw(l.row,l.col);if(_){const $=m.checkCellValueType(_.v);$!==_.t&&g.setValue(l.row,l.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,l)=>{const _=f.getCellRaw(g,l);_?y.setValue(g,l,{t:_.t}):y.setValue(g,l,{t:void 0})}),M.push({id:m.RemoveNumfmtMutation.id,params:p},{id:m.SetRangeValuesMutation.id,params:{unitId:i,subUnitId:h,cellValue:u}});const b=m.factoryRemoveNumfmtUndoMutation(e,p);C.push({id:m.SetRangeValuesMutation.id,params:{unitId:i,subUnitId:h,cellValue:y.getMatrix()}},...b)}const d=t.sequenceExecute(M,s).result;return d&&o.pushUndoRedo({unitID:i,undoMutations:C,redoMutations:M}),d}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),r=e.get(m.INumfmtService),o=e.get(t.IUniverInstanceService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const i=m.getSheetCommandTarget(o);if(!i)return!1;const{unitId:h,subUnitId:f}=i;let c=0;a.forEach(M=>{t.Range.foreach(M.range,(C,d)=>{const u=r.getValue(h,f,C,d);if(!u){const b=i.worksheet.getCellRaw(C,d);if(!c&&b&&b.t===t.CellValueType.NUMBER&&b.v){const g=/\.(\d*)$/.exec(String(b.v));if(g){const l=g[1].length;if(!l)return;c=Math.max(c,l)}}return}const y=E(u.pattern);c=y>c?y:c})});const S=c+1,v=P(`0${S>0?".0":""}`,S),p=[];return a.forEach(M=>{t.Range.foreach(M.range,(C,d)=>{const u=r.getValue(h,f,C,d);if(!u)p.push({row:C,col:d,pattern:v});else{const y=E(u.pattern),b=P(u.pattern,y+1);b!==u.pattern&&p.push({row:C,col:d,pattern:b})}})}),p.length?await n.executeCommand(N.id,{values:p}):!1}};class U{constructor(){T(this,"_currencySymbol$",new I.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(n){this._currencySymbol$.next(n)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const G={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),r=e.get(U),o=F[r.getCurrencySymbol()]||"$",a=s.getCurrentSelections();if(!a||!a.length)return!1;const i=[],h=V[4].suffix(o);return a.forEach(c=>{t.Range.foreach(c.range,(S,v)=>{i.push({row:S,col:v,pattern:h,type:"currency"})})}),await n.executeCommand(N.id,{values:i})}},W={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),r=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!r||!r.length)return!1;const o=[],a="0%";return r.forEach(h=>{t.Range.foreach(h.range,(f,c)=>{o.push({row:f,col:c,pattern:a,type:"percent"})})}),await n.executeCommand(N.id,{values:o})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),r=e.get(m.INumfmtService),o=e.get(t.IUniverInstanceService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const i=m.getSheetCommandTarget(o);if(!i)return!1;const{unitId:h,subUnitId:f}=i;let c=0;a.forEach(C=>{t.Range.foreach(C.range,(d,u)=>{const y=r.getValue(h,f,d,u);if(!y){const g=i.worksheet.getCellRaw(d,u);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const l=/\.(\d*)$/.exec(String(g.v));if(l){const _=l[1].length;if(!_)return;c=Math.max(c,_)}}return}const b=E(y.pattern);c=b>c?b:c})});const S=c-1,v=P(`0${S>0?".0":"."}`,S),p=[];return a.forEach(C=>{t.Range.foreach(C.range,(d,u)=>{const y=r.getValue(h,f,d,u);if(!y)p.push({row:d,col:u,pattern:v});else{const b=E(y.pattern);p.push({row:d,col:u,pattern:P(y.pattern,b-1)})}})}),await n.executeCommand(N.id,{values:p})}},ee=e=>t.numfmt.getInfo(e).type||"unknown",H=(e,n,s="en")=>{const o=t.numfmt.getInfo(e)._partitions[1],a=t.numfmt.format(e,n,{locale:s,throws:!1});return n<0?{result:a,color:o.color}:{result:a}},k=(e,n,s)=>e==="General"?{result:String(Z.stripErrorMargin(n))}:H(e,n,s);var te=Object.getOwnPropertyDescriptor,ne=(e,n,s,r)=>{for(var o=r>1?void 0:r?te(n,s):n,a=e.length-1,i;a>=0;a--)(i=e[a])&&(o=i(o)||o);return o},R=(e,n)=>(s,r)=>n(s,r,e);const re={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,r,o,a,i,h){super();T(this,"_local$",new I.BehaviorSubject("en"));T(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=r,this._themeService=o,this._commandService=a,this._numfmtService=i,this._localeService=h,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(I.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:(r,o,a)=>{const i=o.unitId,h=o.subUnitId;let f;const c=r;if(!c)return a(r);if(r!=null&&r.s){const d=o.workbook.getStyles().get(r.s);d!=null&&d.n&&(f=d.n)}if(f||(f=this._numfmtService.getValue(i,h,o.row,o.col)),!f||m.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return a(r);if(j.isTextFormat(f.pattern))return a({...r,t:t.CellValueType.STRING,markers:{...r==null?void 0:r.markers,...re}});let v="";const p=s.getValue(o.row,o.col);if(p&&p.parameters===`${c.v}_${f.pattern}`)return a({...r,...p.result});const M=k(f.pattern,Number(c.v),this.local);if(v=M.result,!v)return a(r);const C={v,t:t.CellValueType.NUMBER};if(M.color){const d=this._themeService.getCurrentTheme()[`${M.color}500`];d&&(C.interceptorStyle={cl:{rgb:d}})}return s.setValue(o.row,o.col,{result:C,parameters:`${c.v}_${f.pattern}`}),a({...r,...C})},priority:m.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===m.SetNumfmtMutation.id){const o=r.params;Object.keys(o.values).forEach(a=>{o.values[a].ranges.forEach(h=>{t.Range.foreach(h,(f,c)=>{s.realDeleteValue(f,c)})})})}else if(r.id===m.SetRangeValuesMutation.id){const o=r.params;new t.ObjectMatrix(o.cellValue).forValue((a,i)=>{s.realDeleteValue(a,i)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(r=>{var o;return(o=r==null?void 0:r.activeSheet$)!=null?o:I.of(null)}),I.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=ne([R(0,t.IUniverInstanceService),R(1,t.Inject(m.SheetInterceptorService)),R(2,t.Inject(t.ThemeService)),R(3,t.Inject(t.ICommandService)),R(4,t.Inject(m.INumfmtService)),R(5,t.Inject(t.LocaleService))],exports.SheetsNumfmtCellContentController);class D extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new I.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var se=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ae=(e,n,s)=>n in e?se(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s,ce=(e,n,s,r)=>{for(var o=r>1?void 0:r?oe(n,s):n,a=e.length-1,i;a>=0;a--)(i=e[a])&&(o=i(o)||o);return o},w=(e,n)=>(s,r)=>n(s,r,e),z=(e,n,s)=>ae(e,typeof n!="symbol"?n+"":n,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(n=void 0,s,r){super(),this._config=n,this._injector=s,this._commandService=r}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[U],[D]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[D]]),[B,q,G,W,N].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",J);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ce([t.DependentOn(m.UniverSheetsPlugin),w(1,t.Inject(t.Injector)),w(2,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ie=e=>O.find(s=>e.includes(s)),le=()=>O.map(e=>({label:e,value:e})),ue=e=>V.map(n=>({label:n.label(e),value:n.suffix(e),color:n.color})),me=()=>A.map(e=>({label:e.label,value:e.suffix})),fe=()=>L.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=B;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=A;exports.MenuCurrencyService=U;exports.NUMBERFORMAT=L;exports.SetCurrencyCommand=G;exports.SetNumfmtCommand=N;exports.SetPercentCommand=W;exports.SubtractDecimalCommand=q;exports.countryCurrencyMap=F;exports.currencySymbols=O;exports.getCurrencyFormatOptions=ue;exports.getCurrencyOptions=le;exports.getCurrencyType=ie;exports.getDateFormatOptions=me;exports.getDecimalFromPattern=E;exports.getDecimalString=x;exports.getNumberFormatOptions=fe;exports.getPatternPreview=H;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternEqualWithoutDecimal=X;exports.isPatternHasDecimal=Q;exports.setPatternDecimal=P;
|
|
1
|
+
"use strict";var Z=Object.defineProperty;var J=(e,n,s)=>n in e?Z(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s;var T=(e,n,s)=>J(e,typeof n!="symbol"?n+"":n,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),A=require("@univerjs/engine-numfmt"),N=require("rxjs"),X=require("@univerjs/engine-formula"),U=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],Q="SHEET_NUMFMT_PLUGIN",E=(e,n=0)=>{var r;return e&&(r=t.numfmt.getInfo(e).maxDecimals)!=null?r:n},ee=(e,n)=>{if(e&&!n||!e&&n)return!1;const s=i=>i.reduce((S,v)=>{if(S.isEnd)return S;const h=v.value||v.num;return v.type==="point"?(S.isEnd=!0,S):{...S,result:S.result+h}},{isEnd:!1,result:""}).result,r=t.numfmt.getInfo(e)._partitions,o=t.numfmt.getInfo(n)._partitions,a=s(r[0].tokens),l=s(o[0].tokens),g=s(r[1].tokens),m=s(o[1].tokens);return a===l&&g===m&&r[1].color===o[1].color},O=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,n)=>e.split(";").map(r=>/\.0?/.test(r)?r.replace(/\.0*/g,`${n>0?".":""}${O(Number(n||0))}`):/0([^0]?)|0$/.test(r)?r.replace(/0([^0]+)|0$/,`0${n>0?".":""}${O(Number(n||0))}$1`):r).join(";"),te=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,n)=>{if(!n)return!1;const s=e.get(t.ICommandService),r=e.get(t.IUniverInstanceService),o=e.get(t.IUndoRedoService),a=f.getSheetCommandTarget(r,n);if(!a)return!1;const{unitId:l,subUnitId:g,worksheet:m}=a,i=n.values.filter(c=>!!c.pattern),S=n.values.filter(c=>!c.pattern),v=f.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:S.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],p=[];if(i.length){const c=i.reduce((d,u)=>{A.isTextFormat(u.pattern)&&d.setValue(u.row,u.col,{t:t.CellValueType.STRING});const b=m.getCellRaw(u.row,u.col);if(b){const $=f.checkCellValueType(b.v);$!==b.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const b=m.getCellRaw(d,u);b?y.setValue(d,u,{t:b.t}):y.setValue(d,u,{t:void 0})}),Object.keys(v.values).forEach(d=>{const u=v.values[d];u.ranges=f.rangeMerge(u.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:v});const _=f.factorySetNumfmtUndoMutation(e,v);p.push(..._)}if(S.length){h.ranges=f.rangeMerge(h.ranges);const c=S.reduce((d,u)=>{const b=m.getCellRaw(u.row,u.col);if(b){const $=f.checkCellValueType(b.v);$!==b.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const b=m.getCellRaw(d,u);b?y.setValue(d,u,{t:b.t}):y.setValue(d,u,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const _=f.factoryRemoveNumfmtUndoMutation(e,h);p.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:y.getMatrix()}},..._)}const C=t.sequenceExecute(M,s).result;return C&&o.pushUndoRedo({unitID:l,undoMutations:p,redoMutations:M}),C}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),r=e.get(f.INumfmtService),o=e.get(t.IUniverInstanceService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const l=f.getSheetCommandTarget(o);if(!l)return!1;const{unitId:g,subUnitId:m}=l;let i=0;a.forEach(M=>{t.Range.foreach(M.range,(p,C)=>{const c=r.getValue(g,m,p,C);if(!c){const _=l.worksheet.getCellRaw(p,C);if(!i&&_&&_.t===t.CellValueType.NUMBER&&_.v){const d=/\.(\d*)$/.exec(String(_.v));if(d){const u=d[1].length;if(!u)return;i=Math.max(i,u)}}return}const y=E(c.pattern);i=y>i?y:i})});const S=i+1,v=P(`0${S>0?".0":""}`,S),h=[];return a.forEach(M=>{t.Range.foreach(M.range,(p,C)=>{const c=r.getValue(g,m,p,C);if(!c)h.push({row:p,col:C,pattern:v});else{const y=E(c.pattern),_=P(c.pattern,y+1);_!==c.pattern&&h.push({row:p,col:C,pattern:_})}})}),h.length?await n.executeCommand(R.id,{values:h}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(n){this._currencySymbol$.next(n)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),r=e.get(D),o=L[r.getCurrencySymbol()]||"$",a=s.getCurrentSelections();if(!a||!a.length)return!1;const l=[],g=V[4].suffix(o);return a.forEach(i=>{t.Range.foreach(i.range,(S,v)=>{l.push({row:S,col:v,pattern:g,type:"currency"})})}),await n.executeCommand(R.id,{values:l})}},q={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),r=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!r||!r.length)return!1;const o=[],a="0%";return r.forEach(g=>{t.Range.foreach(g.range,(m,i)=>{o.push({row:m,col:i,pattern:a,type:"percent"})})}),await n.executeCommand(R.id,{values:o})}},k={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),r=e.get(f.INumfmtService),o=e.get(t.IUniverInstanceService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const l=f.getSheetCommandTarget(o);if(!l)return!1;const{unitId:g,subUnitId:m}=l;let i=0;a.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const y=r.getValue(g,m,C,c);if(!y){const d=l.worksheet.getCellRaw(C,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const u=/\.(\d*)$/.exec(String(d.v));if(u){const b=u[1].length;if(!b)return;i=Math.max(i,b)}}return}const _=E(y.pattern);i=_>i?_:i})});const S=i-1,v=P(`0${S>0?".0":"."}`,S),h=[];return a.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const y=r.getValue(g,m,C,c);if(!y)h.push({row:C,col:c,pattern:v});else{const _=E(y.pattern);h.push({row:C,col:c,pattern:P(y.pattern,_-1)})}})}),await n.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",j={},ne=e=>t.numfmt.getInfo(e).type||"unknown",K=(e,n,s="en")=>{const o=t.numfmt.getInfo(e)._partitions[1],a=t.numfmt.format(e,n,{locale:s,throws:!1});return n<0?{result:a,color:o.color}:{result:a}},Y=(e,n,s)=>e==="General"?{result:String(X.stripErrorMargin(n))}:K(e,n,s);var re=Object.getOwnPropertyDescriptor,se=(e,n,s,r)=>{for(var o=r>1?void 0:r?re(n,s):n,a=e.length-1,l;a>=0;a--)(l=e[a])&&(o=l(o)||o);return o},I=(e,n)=>(s,r)=>n(s,r,e);const oe={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,r,o,a,l,g,m){super();T(this,"_local$",new N.BehaviorSubject("en"));T(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=r,this._themeService=o,this._commandService=a,this._numfmtService=l,this._localeService=g,this._configService=m,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(r,o,a)=>{var C;const l=o.unitId,g=o.subUnitId;let m;const i=r;if(!i)return a(r);if(r!=null&&r.s){const c=o.workbook.getStyles().get(r.s);c!=null&&c.n&&(m=c.n)}if(m||(m=this._numfmtService.getValue(l,g,o.row,o.col)),!m||f.checkCellValueType(i.v)!==t.CellValueType.NUMBER)return a(r);if(A.isTextFormat(m.pattern))return(C=this._configService.getConfig(w))!=null&&C.disableTextFormatMark?a({...r,t:t.CellValueType.STRING}):a({...r,t:t.CellValueType.STRING,markers:{...r==null?void 0:r.markers,...oe}});let v="";const h=s.getValue(o.row,o.col);if(h&&h.parameters===`${i.v}_${m.pattern}`)return a({...r,...h.result});const M=Y(m.pattern,Number(i.v),this.local);if(v=M.result,!v)return a(r);const p={v,t:t.CellValueType.NUMBER};if(M.color){const c=this._themeService.getCurrentTheme()[`${M.color}500`];c&&(p.interceptorStyle={cl:{rgb:c}})}return s.setValue(o.row,o.col,{result:p,parameters:`${i.v}_${m.pattern}`}),a({...r,...p})},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===f.SetNumfmtMutation.id){const o=r.params;Object.keys(o.values).forEach(a=>{o.values[a].ranges.forEach(g=>{t.Range.foreach(g,(m,i)=>{s.realDeleteValue(m,i)})})})}else if(r.id===f.SetRangeValuesMutation.id){const o=r.params;new t.ObjectMatrix(o.cellValue).forValue((a,l)=>{s.realDeleteValue(a,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(r=>{var o;return(o=r==null?void 0:r.activeSheet$)!=null?o:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=se([I(0,t.IUniverInstanceService),I(1,t.Inject(f.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(f.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);class F extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,ie=(e,n,s)=>n in e?ae(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s,le=(e,n,s,r)=>{for(var o=r>1?void 0:r?ce(n,s):n,a=e.length-1,l;a>=0;a--)(l=e[a])&&(o=l(o)||o);return o},x=(e,n)=>(s,r)=>n(s,r,e),z=(e,n,s)=>ie(e,typeof n!="symbol"?n+"":n,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(n=j,s,r,o){super(),this._config=n,this._injector=s,this._configService=r,this._commandService=o;const{...a}=t.merge({},j,this._config);this._configService.setConfig(w,a)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[F]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[F]]),[H,k,W,q,R].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",Q);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=le([t.DependentOn(f.UniverSheetsPlugin),x(1,t.Inject(t.Injector)),x(2,t.IConfigService),x(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ue=e=>U.find(s=>e.includes(s)),me=()=>U.map(e=>({label:e,value:e})),fe=e=>V.map(n=>({label:n.label(e),value:n.suffix(e),color:n.color})),de=()=>G.map(e=>({label:e.label,value:e.suffix})),ge=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=G;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=q;exports.SubtractDecimalCommand=k;exports.countryCurrencyMap=L;exports.currencySymbols=U;exports.getCurrencyFormatOptions=fe;exports.getCurrencyOptions=me;exports.getCurrencyType=ue;exports.getDateFormatOptions=de;exports.getDecimalFromPattern=E;exports.getDecimalString=O;exports.getNumberFormatOptions=ge;exports.getPatternPreview=K;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=ne;exports.isPatternEqualWithoutDecimal=ee;exports.isPatternHasDecimal=te;exports.setPatternDecimal=P;
|