@univerjs/sheets-numfmt 0.6.0 → 0.6.1
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 +65 -65
- package/lib/types/facade/f-range.d.ts +10 -2
- package/lib/types/facade/f-workbook.d.ts +17 -8
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var K=Object.defineProperty;var X=(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)=>X(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"),Y=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:"€"},F=[{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"}],U=[{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"}],Z="SHEET_NUMFMT_PLUGIN",E=(e,n=0)=>{var r;return e&&(r=t.numfmt.getInfo(e).maxDecimals)!=null?r:n},J=(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},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(";"),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)=>{l.pattern===j.DEFAULT_TEXT_FORMAT&&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 V{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(V),o=A[r.getCurrencySymbol()]||"$",a=s.getCurrentSelections();if(!a||!a.length)return!1;const i=[],h=U[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(Y.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(f.pattern===j.DEFAULT_TEXT_FORMAT)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],[V],[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",Z);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=>x.find(s=>e.includes(s)),le=()=>x.map(e=>({label:e,value:e})),ue=e=>U.map(n=>({label:n.label(e),value:n.suffix(e),color:n.color})),me=()=>F.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=U;exports.DATEFMTLISG=F;exports.MenuCurrencyService=V;exports.NUMBERFORMAT=L;exports.SetCurrencyCommand=G;exports.SetNumfmtCommand=N;exports.SetPercentCommand=W;exports.SubtractDecimalCommand=q;exports.countryCurrencyMap=A;exports.currencySymbols=x;exports.getCurrencyFormatOptions=ue;exports.getCurrencyOptions=le;exports.getCurrencyType=ie;exports.getDateFormatOptions=me;exports.getDecimalFromPattern=E;exports.getDecimalString=O;exports.getNumberFormatOptions=fe;exports.getPatternPreview=H;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternEqualWithoutDecimal=J;exports.isPatternHasDecimal=Q;exports.setPatternDecimal=P;
|
|
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;
|
package/lib/es/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var oe = Object.defineProperty;
|
|
2
2
|
var ce = (e, t, n) => t in e ? oe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
3
|
var M = (e, t, n) => ce(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
-
import { numfmt as x, CommandType as
|
|
4
|
+
import { numfmt as x, CommandType as w, ICommandService as I, IUniverInstanceService as F, IUndoRedoService as ae, CellValueType as T, ObjectMatrix as b, sequenceExecute as ie, Range as R, Inject as N, ThemeService as le, LocaleService as ue, Disposable as J, LocaleType as $, InterceptorEffectEnum as k, UniverInstanceType as X, DependentOn as me, Injector as fe, Plugin as de, registerDependencies as he, touchDependencies as z } from "@univerjs/core";
|
|
5
5
|
import { getSheetCommandTarget as G, transformCellsToRange as ge, checkCellValueType as L, rangeMerge as K, SetNumfmtMutation as Q, factorySetNumfmtUndoMutation as pe, RemoveNumfmtMutation as ve, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as Se, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as ye, INTERCEPTOR_POINT as _e, InterceptCellContentPriority as Ce, UniverSheetsPlugin as be } from "@univerjs/sheets";
|
|
6
|
-
import {
|
|
7
|
-
import { BehaviorSubject as H, merge as Me, switchMap as $e, of as Re, skip as
|
|
8
|
-
import { stripErrorMargin as
|
|
6
|
+
import { isTextFormat as ee } from "@univerjs/engine-numfmt";
|
|
7
|
+
import { BehaviorSubject as H, merge as Me, switchMap as $e, of as Re, skip as Ie } from "rxjs";
|
|
8
|
+
import { stripErrorMargin as Ee } from "@univerjs/engine-formula";
|
|
9
9
|
const te = [
|
|
10
10
|
"$",
|
|
11
11
|
"£",
|
|
@@ -175,10 +175,10 @@ const te = [
|
|
|
175
175
|
suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
|
|
176
176
|
color: "red"
|
|
177
177
|
}
|
|
178
|
-
], Ve = "SHEET_NUMFMT_PLUGIN",
|
|
178
|
+
], Ve = "SHEET_NUMFMT_PLUGIN", U = (e, t = 0) => {
|
|
179
179
|
var r;
|
|
180
180
|
return e && (r = x.getInfo(e).maxDecimals) != null ? r : t;
|
|
181
|
-
},
|
|
181
|
+
}, Je = (e, t) => {
|
|
182
182
|
if (e && !t || !e && t)
|
|
183
183
|
return !1;
|
|
184
184
|
const n = (u) => u.reduce(
|
|
@@ -191,20 +191,20 @@ const te = [
|
|
|
191
191
|
{ isEnd: !1, result: "" }
|
|
192
192
|
).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens), c = n(s[0].tokens), l = n(r[1].tokens), f = n(s[1].tokens);
|
|
193
193
|
return o === c && l === f && r[1].color === s[1].color;
|
|
194
|
-
}, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""),
|
|
194
|
+
}, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), O = (e, t) => e.split(";").map((r) => /\.0?/.test(r) ? r.replace(
|
|
195
195
|
/\.0*/g,
|
|
196
196
|
`${t > 0 ? "." : ""}${q(Number(t || 0))}`
|
|
197
197
|
) : /0([^0]?)|0$/.test(r) ? r.replace(
|
|
198
198
|
/0([^0]+)|0$/,
|
|
199
199
|
`0${t > 0 ? "." : ""}${q(Number(t || 0))}$1`
|
|
200
|
-
) : r).join(";"),
|
|
200
|
+
) : r).join(";"), Xe = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), P = {
|
|
201
201
|
id: "sheet.command.numfmt.set.numfmt",
|
|
202
|
-
type:
|
|
202
|
+
type: w.COMMAND,
|
|
203
203
|
// eslint-disable-next-line max-lines-per-function
|
|
204
204
|
handler: (e, t) => {
|
|
205
205
|
if (!t)
|
|
206
206
|
return !1;
|
|
207
|
-
const n = e.get(
|
|
207
|
+
const n = e.get(I), r = e.get(F), s = e.get(ae), o = G(r, t);
|
|
208
208
|
if (!o) return !1;
|
|
209
209
|
const { unitId: c, subUnitId: l, worksheet: f } = o, u = t.values.filter((i) => !!i.pattern), d = t.values.filter((i) => !i.pattern), p = ge(c, l, u), g = {
|
|
210
210
|
unitId: c,
|
|
@@ -218,7 +218,7 @@ const te = [
|
|
|
218
218
|
}, C = [], h = [];
|
|
219
219
|
if (u.length) {
|
|
220
220
|
const i = u.reduce((m, a) => {
|
|
221
|
-
a.pattern
|
|
221
|
+
ee(a.pattern) && m.setValue(a.row, a.col, { t: T.STRING });
|
|
222
222
|
const _ = f.getCellRaw(a.row, a.col);
|
|
223
223
|
if (_) {
|
|
224
224
|
const V = L(_.v);
|
|
@@ -280,11 +280,11 @@ const te = [
|
|
|
280
280
|
redoMutations: C
|
|
281
281
|
}), S;
|
|
282
282
|
}
|
|
283
|
-
},
|
|
283
|
+
}, we = {
|
|
284
284
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
285
|
-
type:
|
|
285
|
+
type: w.COMMAND,
|
|
286
286
|
handler: async (e) => {
|
|
287
|
-
const t = e.get(
|
|
287
|
+
const t = e.get(I), n = e.get(j), r = e.get(W), s = e.get(F), o = n.getCurrentSelections();
|
|
288
288
|
if (!o || !o.length)
|
|
289
289
|
return !1;
|
|
290
290
|
const c = G(s);
|
|
@@ -307,11 +307,11 @@ const te = [
|
|
|
307
307
|
}
|
|
308
308
|
return;
|
|
309
309
|
}
|
|
310
|
-
const v =
|
|
310
|
+
const v = U(i.pattern);
|
|
311
311
|
u = v > u ? v : u;
|
|
312
312
|
});
|
|
313
313
|
});
|
|
314
|
-
const d = u + 1, p =
|
|
314
|
+
const d = u + 1, p = O(`0${d > 0 ? ".0" : ""}`, d), g = [];
|
|
315
315
|
return o.forEach((C) => {
|
|
316
316
|
R.foreach(C.range, (h, S) => {
|
|
317
317
|
const i = r.getValue(l, f, h, S);
|
|
@@ -322,7 +322,7 @@ const te = [
|
|
|
322
322
|
pattern: p
|
|
323
323
|
});
|
|
324
324
|
else {
|
|
325
|
-
const v =
|
|
325
|
+
const v = U(i.pattern), y = O(i.pattern, v + 1);
|
|
326
326
|
y !== i.pattern && g.push({
|
|
327
327
|
row: h,
|
|
328
328
|
col: S,
|
|
@@ -330,7 +330,7 @@ const te = [
|
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
});
|
|
333
|
-
}), g.length ? await t.executeCommand(
|
|
333
|
+
}), g.length ? await t.executeCommand(P.id, { values: g }) : !1;
|
|
334
334
|
}
|
|
335
335
|
};
|
|
336
336
|
class re {
|
|
@@ -348,11 +348,11 @@ class re {
|
|
|
348
348
|
return this._currencySymbol$.getValue();
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
-
const
|
|
351
|
+
const Pe = {
|
|
352
352
|
id: "sheet.command.numfmt.set.currency",
|
|
353
|
-
type:
|
|
353
|
+
type: w.COMMAND,
|
|
354
354
|
handler: async (e) => {
|
|
355
|
-
const t = e.get(
|
|
355
|
+
const t = e.get(I), n = e.get(j), r = e.get(re), s = Ne[r.getCurrencySymbol()] || "$", o = n.getCurrentSelections();
|
|
356
356
|
if (!o || !o.length)
|
|
357
357
|
return !1;
|
|
358
358
|
const c = [], l = ne[4].suffix(s);
|
|
@@ -360,13 +360,13 @@ const we = {
|
|
|
360
360
|
R.foreach(u.range, (d, p) => {
|
|
361
361
|
c.push({ row: d, col: p, pattern: l, type: "currency" });
|
|
362
362
|
});
|
|
363
|
-
}), await t.executeCommand(
|
|
363
|
+
}), await t.executeCommand(P.id, { values: c });
|
|
364
364
|
}
|
|
365
|
-
},
|
|
365
|
+
}, Ue = {
|
|
366
366
|
id: "sheet.command.numfmt.set.percent",
|
|
367
|
-
type:
|
|
367
|
+
type: w.COMMAND,
|
|
368
368
|
handler: async (e) => {
|
|
369
|
-
const t = e.get(
|
|
369
|
+
const t = e.get(I), r = e.get(j).getCurrentSelections();
|
|
370
370
|
if (!r || !r.length)
|
|
371
371
|
return !1;
|
|
372
372
|
const s = [], o = "0%";
|
|
@@ -374,13 +374,13 @@ const we = {
|
|
|
374
374
|
R.foreach(l.range, (f, u) => {
|
|
375
375
|
s.push({ row: f, col: u, pattern: o, type: "percent" });
|
|
376
376
|
});
|
|
377
|
-
}), await t.executeCommand(
|
|
377
|
+
}), await t.executeCommand(P.id, { values: s });
|
|
378
378
|
}
|
|
379
|
-
},
|
|
379
|
+
}, Oe = {
|
|
380
380
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
381
|
-
type:
|
|
381
|
+
type: w.COMMAND,
|
|
382
382
|
handler: async (e) => {
|
|
383
|
-
const t = e.get(
|
|
383
|
+
const t = e.get(I), n = e.get(j), r = e.get(W), s = e.get(F), o = n.getCurrentSelections();
|
|
384
384
|
if (!o || !o.length)
|
|
385
385
|
return !1;
|
|
386
386
|
const c = G(s);
|
|
@@ -403,11 +403,11 @@ const we = {
|
|
|
403
403
|
}
|
|
404
404
|
return;
|
|
405
405
|
}
|
|
406
|
-
const y =
|
|
406
|
+
const y = U(v.pattern);
|
|
407
407
|
u = y > u ? y : u;
|
|
408
408
|
});
|
|
409
409
|
});
|
|
410
|
-
const d = u - 1, p =
|
|
410
|
+
const d = u - 1, p = O(`0${d > 0 ? ".0" : "."}`, d), g = [];
|
|
411
411
|
return o.forEach((h) => {
|
|
412
412
|
R.foreach(h.range, (S, i) => {
|
|
413
413
|
const v = r.getValue(l, f, S, i);
|
|
@@ -418,15 +418,15 @@ const we = {
|
|
|
418
418
|
pattern: p
|
|
419
419
|
});
|
|
420
420
|
else {
|
|
421
|
-
const y =
|
|
421
|
+
const y = U(v.pattern);
|
|
422
422
|
g.push({
|
|
423
423
|
row: S,
|
|
424
424
|
col: i,
|
|
425
|
-
pattern:
|
|
425
|
+
pattern: O(v.pattern, y - 1)
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
428
|
});
|
|
429
|
-
}), await t.executeCommand(
|
|
429
|
+
}), await t.executeCommand(P.id, { values: g });
|
|
430
430
|
}
|
|
431
431
|
}, Qe = (e) => x.getInfo(e).type || "unknown", De = (e, t, n = "en") => {
|
|
432
432
|
const s = x.getInfo(e)._partitions[1], o = x.format(e, t, { locale: n, throws: !1 });
|
|
@@ -437,21 +437,21 @@ const we = {
|
|
|
437
437
|
result: o
|
|
438
438
|
};
|
|
439
439
|
}, Ae = (e, t, n) => e === "General" ? {
|
|
440
|
-
result: String(
|
|
440
|
+
result: String(Ee(t))
|
|
441
441
|
// In Excel, the default General format also needs to handle numeric precision.
|
|
442
442
|
} : De(e, t, n);
|
|
443
443
|
var Fe = Object.getOwnPropertyDescriptor, je = (e, t, n, r) => {
|
|
444
444
|
for (var s = r > 1 ? void 0 : r ? Fe(t, n) : t, o = e.length - 1, c; o >= 0; o--)
|
|
445
445
|
(c = e[o]) && (s = c(s) || s);
|
|
446
446
|
return s;
|
|
447
|
-
},
|
|
447
|
+
}, E = (e, t) => (n, r) => t(n, r, e);
|
|
448
448
|
const Le = {
|
|
449
449
|
tl: {
|
|
450
450
|
size: 6,
|
|
451
451
|
color: "#409f11"
|
|
452
452
|
}
|
|
453
453
|
};
|
|
454
|
-
let D = class extends
|
|
454
|
+
let D = class extends J {
|
|
455
455
|
constructor(t, n, r, s, o, c) {
|
|
456
456
|
super();
|
|
457
457
|
M(this, "_local$", new H("en"));
|
|
@@ -498,7 +498,7 @@ let D = class extends Z {
|
|
|
498
498
|
}
|
|
499
499
|
if (l || (l = this._numfmtService.getValue(o, c, r.row, r.col)), !l || L(f.v) !== T.NUMBER)
|
|
500
500
|
return s(n);
|
|
501
|
-
if (l.pattern
|
|
501
|
+
if (ee(l.pattern))
|
|
502
502
|
return s({
|
|
503
503
|
...n,
|
|
504
504
|
t: T.STRING,
|
|
@@ -542,12 +542,12 @@ let D = class extends Z {
|
|
|
542
542
|
});
|
|
543
543
|
}
|
|
544
544
|
})), this.disposeWithMe(
|
|
545
|
-
this._instanceService.getCurrentTypeOfUnit$(
|
|
545
|
+
this._instanceService.getCurrentTypeOfUnit$(X.UNIVER_SHEET).pipe(
|
|
546
546
|
$e((n) => {
|
|
547
547
|
var r;
|
|
548
548
|
return (r = n == null ? void 0 : n.activeSheet$) != null ? r : Re(null);
|
|
549
549
|
}),
|
|
550
|
-
|
|
550
|
+
Ie(1)
|
|
551
551
|
).subscribe(() => t.reset())
|
|
552
552
|
);
|
|
553
553
|
}
|
|
@@ -556,14 +556,14 @@ let D = class extends Z {
|
|
|
556
556
|
}
|
|
557
557
|
};
|
|
558
558
|
D = je([
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
559
|
+
E(0, F),
|
|
560
|
+
E(1, N(ye)),
|
|
561
|
+
E(2, N(le)),
|
|
562
|
+
E(3, N(I)),
|
|
563
|
+
E(4, N(W)),
|
|
564
|
+
E(5, N(ue))
|
|
565
565
|
], D);
|
|
566
|
-
class
|
|
566
|
+
class Y extends J {
|
|
567
567
|
constructor() {
|
|
568
568
|
super(...arguments);
|
|
569
569
|
M(this, "_currencySymbol$", new H("US"));
|
|
@@ -583,7 +583,7 @@ var Be = Object.defineProperty, Ge = Object.getOwnPropertyDescriptor, We = (e, t
|
|
|
583
583
|
for (var s = r > 1 ? void 0 : r ? Ge(t, n) : t, o = e.length - 1, c; o >= 0; o--)
|
|
584
584
|
(c = e[o]) && (s = c(s) || s);
|
|
585
585
|
return s;
|
|
586
|
-
},
|
|
586
|
+
}, Z = (e, t) => (n, r) => t(n, r, e), se = (e, t, n) => We(e, typeof t != "symbol" ? t + "" : t, n);
|
|
587
587
|
let A = class extends de {
|
|
588
588
|
constructor(e = void 0, t, n) {
|
|
589
589
|
super(), this._config = e, this._injector = t, this._commandService = n;
|
|
@@ -592,31 +592,31 @@ let A = class extends de {
|
|
|
592
592
|
he(this._injector, [
|
|
593
593
|
[D],
|
|
594
594
|
[re],
|
|
595
|
-
[
|
|
595
|
+
[Y]
|
|
596
596
|
]), z(this._injector, [
|
|
597
597
|
[D]
|
|
598
598
|
]);
|
|
599
599
|
}
|
|
600
600
|
onRendered() {
|
|
601
601
|
z(this._injector, [
|
|
602
|
-
[
|
|
602
|
+
[Y]
|
|
603
603
|
]), [
|
|
604
|
-
Ue,
|
|
605
|
-
Pe,
|
|
606
604
|
we,
|
|
607
605
|
Oe,
|
|
608
|
-
|
|
606
|
+
Pe,
|
|
607
|
+
Ue,
|
|
608
|
+
P
|
|
609
609
|
].forEach((e) => {
|
|
610
610
|
this.disposeWithMe(this._commandService.registerCommand(e));
|
|
611
611
|
});
|
|
612
612
|
}
|
|
613
613
|
};
|
|
614
614
|
se(A, "pluginName", Ve);
|
|
615
|
-
se(A, "type",
|
|
615
|
+
se(A, "type", X.UNIVER_SHEET);
|
|
616
616
|
A = He([
|
|
617
617
|
me(be),
|
|
618
|
-
|
|
619
|
-
|
|
618
|
+
Z(1, N(fe)),
|
|
619
|
+
Z(2, I)
|
|
620
620
|
], A);
|
|
621
621
|
const et = (e) => te.find((n) => e.includes(n)), tt = () => te.map((e) => ({ label: e, value: e })), nt = (e) => ne.map((t) => ({
|
|
622
622
|
label: t.label(e),
|
|
@@ -624,16 +624,16 @@ const et = (e) => te.find((n) => e.includes(n)), tt = () => te.map((e) => ({ lab
|
|
|
624
624
|
color: t.color
|
|
625
625
|
})), rt = () => Te.map((e) => ({ label: e.label, value: e.suffix })), st = () => xe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
626
626
|
export {
|
|
627
|
-
|
|
627
|
+
we as AddDecimalCommand,
|
|
628
628
|
ne as CURRENCYFORMAT,
|
|
629
629
|
Te as DATEFMTLISG,
|
|
630
630
|
re as MenuCurrencyService,
|
|
631
631
|
xe as NUMBERFORMAT,
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
632
|
+
Pe as SetCurrencyCommand,
|
|
633
|
+
P as SetNumfmtCommand,
|
|
634
|
+
Ue as SetPercentCommand,
|
|
635
635
|
D as SheetsNumfmtCellContentController,
|
|
636
|
-
|
|
636
|
+
Oe as SubtractDecimalCommand,
|
|
637
637
|
A as UniverSheetsNumfmtPlugin,
|
|
638
638
|
Ne as countryCurrencyMap,
|
|
639
639
|
te as currencySymbols,
|
|
@@ -641,13 +641,13 @@ export {
|
|
|
641
641
|
tt as getCurrencyOptions,
|
|
642
642
|
et as getCurrencyType,
|
|
643
643
|
rt as getDateFormatOptions,
|
|
644
|
-
|
|
644
|
+
U as getDecimalFromPattern,
|
|
645
645
|
q as getDecimalString,
|
|
646
646
|
st as getNumberFormatOptions,
|
|
647
647
|
De as getPatternPreview,
|
|
648
648
|
Ae as getPatternPreviewIgnoreGeneral,
|
|
649
649
|
Qe as getPatternType,
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
650
|
+
Je as isPatternEqualWithoutDecimal,
|
|
651
|
+
Xe as isPatternHasDecimal,
|
|
652
|
+
O as setPatternDecimal
|
|
653
653
|
};
|
|
@@ -5,8 +5,16 @@ import { FRange } from '@univerjs/sheets/facade';
|
|
|
5
5
|
export interface IFRangeSheetsNumfmtMixin {
|
|
6
6
|
/**
|
|
7
7
|
* Set the number format of the range.
|
|
8
|
-
* @param pattern number format pattern.
|
|
9
|
-
* @returns FRange
|
|
8
|
+
* @param {string} pattern - The number format pattern.
|
|
9
|
+
* @returns {FRange} The FRange instance for chaining.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
13
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
14
|
+
* const fRange = fWorksheet.getRange('A1');
|
|
15
|
+
* fRange.setValue(1234.567).setNumberFormat('#,##0.00');
|
|
16
|
+
* console.log(fRange.getValue()); // 1,234.57
|
|
17
|
+
* ```
|
|
10
18
|
*/
|
|
11
19
|
setNumberFormat(pattern: string): FRange;
|
|
12
20
|
}
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { INumfmtLocalTag } from '@univerjs/core';
|
|
2
2
|
import { FWorkbook } from '@univerjs/sheets/facade';
|
|
3
|
-
/**
|
|
4
|
-
* @ignore
|
|
5
|
-
*/
|
|
6
3
|
export interface IFWorkbookNumfmtMixin {
|
|
7
4
|
/**
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* univerAPI.getActiveWorkbook().setNumfmtLocal('en')
|
|
11
|
-
* ```
|
|
5
|
+
* Set the locale for number formatting.
|
|
12
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
|
|
13
|
-
* @returns {
|
|
7
|
+
* @returns {FWorkbook} The FWorkbook instance for chaining.
|
|
14
8
|
* @memberof IFWorkbookNumfmtMixin
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
12
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
13
|
+
* const fRange = fWorksheet.getRange('A1');
|
|
14
|
+
* fRange.setValue(1234.567).setNumberFormat('#,##0.00');
|
|
15
|
+
*
|
|
16
|
+
* // Set the locale en_US for number formatting.
|
|
17
|
+
* fWorkbook.setNumfmtLocal('en_US');
|
|
18
|
+
* console.log(fRange.getValue()); // 1,234.57
|
|
19
|
+
*
|
|
20
|
+
* // Set the locale de_DE for number formatting.
|
|
21
|
+
* fWorkbook.setNumfmtLocal('de_DE');
|
|
22
|
+
* console.log(fRange.getValue()); // 1.234,57
|
|
23
|
+
* ```
|
|
15
24
|
*/
|
|
16
25
|
setNumfmtLocal(local: INumfmtLocalTag): FWorkbook;
|
|
17
26
|
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(i=typeof globalThis<"u"?globalThis:i||self,t(i.UniverSheetsNumfmt={},i.UniverCore,i.UniverSheets,i.UniverEngineNumfmt,i.rxjs,i.UniverEngineFormula))})(this,function(i,t,u,w,I,X){"use strict";var fe=Object.defineProperty;var de=(i,t,u)=>t in i?fe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[t]=u;var R=(i,t,u)=>de(i,typeof t!="symbol"?t+"":t,u);const O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],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:"€"},F=[{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"}],Y="SHEET_NUMFMT_PLUGIN",E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getInfo(e).maxDecimals)!=null?n:r},Z=(e,r)=>{if(e&&!r||!e&&r)return!1;const a=c=>c.reduce((y,h)=>{if(y.isEnd)return y;const C=h.value||h.num;return h.type==="point"?(y.isEnd=!0,y):{...y,result:y.result+C}},{isEnd:!1,result:""}).result,n=t.numfmt.getInfo(e)._partitions,s=t.numfmt.getInfo(r)._partitions,l=a(n[0].tokens),o=a(s[0].tokens),v=a(n[1].tokens),d=a(s[1].tokens);return l===o&&v===d&&n[1].color===s[1].color},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),N={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),l=u.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:o,subUnitId:v,worksheet:d}=l,c=r.values.filter(f=>!!f.pattern),y=r.values.filter(f=>!f.pattern),h=u.transformCellsToRange(o,v,c),C={unitId:o,subUnitId:v,ranges:y.map(f=>({startColumn:f.col,startRow:f.row,endColumn:f.col,endRow:f.row}))},T=[],p=[];if(c.length){const f=c.reduce((S,m)=>{m.pattern===w.DEFAULT_TEXT_FORMAT&&S.setValue(m.row,m.col,{t:t.CellValueType.STRING});const M=d.getCellRaw(m.row,m.col);if(M){const P=u.checkCellValueType(M.v);P!==M.t&&S.setValue(m.row,m.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),b=new t.ObjectMatrix;new t.ObjectMatrix(f).forValue((S,m)=>{const M=d.getCellRaw(S,m);M?b.setValue(S,m,{t:M.t}):b.setValue(S,m,{t:void 0})}),Object.keys(h.values).forEach(S=>{const m=h.values[S];m.ranges=u.rangeMerge(m.ranges)}),T.push({id:u.SetNumfmtMutation.id,params:h});const _=u.factorySetNumfmtUndoMutation(e,h);p.push(..._)}if(y.length){C.ranges=u.rangeMerge(C.ranges);const f=y.reduce((S,m)=>{const M=d.getCellRaw(m.row,m.col);if(M){const P=u.checkCellValueType(M.v);P!==M.t&&S.setValue(m.row,m.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),b=new t.ObjectMatrix;new t.ObjectMatrix(f).forValue((S,m)=>{const M=d.getCellRaw(S,m);M?b.setValue(S,m,{t:M.t}):b.setValue(S,m,{t:void 0})}),T.push({id:u.RemoveNumfmtMutation.id,params:C},{id:u.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:v,cellValue:f}});const _=u.factoryRemoveNumfmtUndoMutation(e,C);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:v,cellValue:b.getMatrix()}},..._)}const g=t.sequenceExecute(T,a).result;return g&&s.pushUndoRedo({unitID:o,undoMutations:p,redoMutations:T}),g}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=a.getCurrentSelections();if(!l||!l.length)return!1;const o=u.getSheetCommandTarget(s);if(!o)return!1;const{unitId:v,subUnitId:d}=o;let c=0;l.forEach(T=>{t.Range.foreach(T.range,(p,g)=>{const f=n.getValue(v,d,p,g);if(!f){const _=o.worksheet.getCellRaw(p,g);if(!c&&_&&_.t===t.CellValueType.NUMBER&&_.v){const S=/\.(\d*)$/.exec(String(_.v));if(S){const m=S[1].length;if(!m)return;c=Math.max(c,m)}}return}const b=E(f.pattern);c=b>c?b:c})});const y=c+1,h=U(`0${y>0?".0":""}`,y),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(p,g)=>{const f=n.getValue(v,d,p,g);if(!f)C.push({row:p,col:g,pattern:h});else{const b=E(f.pattern),_=U(f.pattern,b+1);_!==f.pattern&&C.push({row:p,col:g,pattern:_})}})}),C.length?await r.executeCommand(N.id,{values:C}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const x={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(u.SheetsSelectionsService),n=e.get(j),s=A[n.getCurrencySymbol()]||"$",l=a.getCurrentSelections();if(!l||!l.length)return!1;const o=[],v=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(y,h)=>{o.push({row:y,col:h,pattern:v,type:"currency"})})}),await r.executeCommand(N.id,{values:o})}},G={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(v=>{t.Range.foreach(v.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand(N.id,{values:s})}},W={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=a.getCurrentSelections();if(!l||!l.length)return!1;const o=u.getSheetCommandTarget(s);if(!o)return!1;const{unitId:v,subUnitId:d}=o;let c=0;l.forEach(p=>{t.Range.foreach(p.range,(g,f)=>{const b=n.getValue(v,d,g,f);if(!b){const S=o.worksheet.getCellRaw(g,f);if(!c&&S&&S.t===t.CellValueType.NUMBER&&S.v){const m=/\.(\d*)$/.exec(String(S.v));if(m){const M=m[1].length;if(!M)return;c=Math.max(c,M)}}return}const _=E(b.pattern);c=_>c?_:c})});const y=c-1,h=U(`0${y>0?".0":"."}`,y),C=[];return l.forEach(p=>{t.Range.foreach(p.range,(g,f)=>{const b=n.getValue(v,d,g,f);if(!b)C.push({row:g,col:f,pattern:h});else{const _=E(b.pattern);C.push({row:g,col:f,pattern:U(b.pattern,_-1)})}})}),await r.executeCommand(N.id,{values:C})}},Q=e=>t.numfmt.getInfo(e).type||"unknown",q=(e,r,a="en")=>{const s=t.numfmt.getInfo(e)._partitions[1],l=t.numfmt.format(e,r,{locale:a,throws:!1});return r<0?{result:l,color:s.color}:{result:l}},H=(e,r,a)=>e==="General"?{result:String(X.stripErrorMargin(r))}:q(e,r,a);var ee=Object.getOwnPropertyDescriptor,te=(e,r,a,n)=>{for(var s=n>1?void 0:n?ee(r,a):r,l=e.length-1,o;l>=0;l--)(o=e[l])&&(s=o(s)||s);return s},$=(e,r)=>(a,n)=>r(a,n,e);const ne={tl:{size:6,color:"#409f11"}};i.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(a,n,s,l,o,v){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=a,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=o,this._localeService=v,this._initInterceptorCellContent()}get local(){const a=this._local$.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.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const a=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{a.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{const o=s.unitId,v=s.subUnitId;let d;const c=n;if(!c)return l(n);if(n!=null&&n.s){const g=s.workbook.getStyles().get(n.s);g!=null&&g.n&&(d=g.n)}if(d||(d=this._numfmtService.getValue(o,v,s.row,s.col)),!d||u.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if(d.pattern===w.DEFAULT_TEXT_FORMAT)return l({...n,t:t.CellValueType.STRING,markers:{...n==null?void 0:n.markers,...ne}});let h="";const C=a.getValue(s.row,s.col);if(C&&C.parameters===`${c.v}_${d.pattern}`)return l({...n,...C.result});const T=H(d.pattern,Number(c.v),this.local);if(h=T.result,!h)return l(n);const p={v:h,t:t.CellValueType.NUMBER};if(T.color){const g=this._themeService.getCurrentTheme()[`${T.color}500`];g&&(p.interceptorStyle={cl:{rgb:g}})}return a.setValue(s.row,s.col,{result:p,parameters:`${c.v}_${d.pattern}`}),l({...n,...p})},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(v=>{t.Range.foreach(v,(d,c)=>{a.realDeleteValue(d,c)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,o)=>{a.realDeleteValue(l,o)})}})),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(()=>a.reset()))}setNumfmtLocal(a){this._local$.next(a)}},i.SheetsNumfmtCellContentController=te([$(0,t.IUniverInstanceService),$(1,t.Inject(u.SheetInterceptorService)),$(2,t.Inject(t.ThemeService)),$(3,t.Inject(t.ICommandService)),$(4,t.Inject(u.INumfmtService)),$(5,t.Inject(t.LocaleService))],i.SheetsNumfmtCellContentController);class k extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(a){this._currencySymbol$.next(a)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var re=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,ie=(e,r,a)=>r in e?re(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,se=(e,r,a,n)=>{for(var s=n>1?void 0:n?ae(r,a):r,l=e.length-1,o;l>=0;l--)(o=e[l])&&(s=o(s)||s);return s},z=(e,r)=>(a,n)=>r(a,n,e),K=(e,r,a)=>ie(e,typeof r!="symbol"?r+"":r,a);i.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=void 0,a,n){super(),this._config=r,this._injector=a,this._commandService=n}onStarting(){t.registerDependencies(this._injector,[[i.SheetsNumfmtCellContentController],[j],[k]]),t.touchDependencies(this._injector,[[i.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[k]]),[B,W,x,G,N].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},K(i.UniverSheetsNumfmtPlugin,"pluginName",Y),K(i.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),i.UniverSheetsNumfmtPlugin=se([t.DependentOn(u.UniverSheetsPlugin),z(1,t.Inject(t.Injector)),z(2,t.ICommandService)],i.UniverSheetsNumfmtPlugin);const le=e=>O.find(a=>e.includes(a)),ue=()=>O.map(e=>({label:e,value:e})),ce=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),oe=()=>F.map(e=>({label:e.label,value:e.suffix})),me=()=>L.map(e=>({label:e.label,value:e.suffix,color:e.color}));i.AddDecimalCommand=B,i.CURRENCYFORMAT=V,i.DATEFMTLISG=F,i.MenuCurrencyService=j,i.NUMBERFORMAT=L,i.SetCurrencyCommand=x,i.SetNumfmtCommand=N,i.SetPercentCommand=G,i.SubtractDecimalCommand=W,i.countryCurrencyMap=A,i.currencySymbols=O,i.getCurrencyFormatOptions=ce,i.getCurrencyOptions=ue,i.getCurrencyType=le,i.getDateFormatOptions=oe,i.getDecimalFromPattern=E,i.getDecimalString=D,i.getNumberFormatOptions=me,i.getPatternPreview=q,i.getPatternPreviewIgnoreGeneral=H,i.getPatternType=Q,i.isPatternEqualWithoutDecimal=Z,i.isPatternHasDecimal=J,i.setPatternDecimal=U,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(i,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(i=typeof globalThis<"u"?globalThis:i||self,t(i.UniverSheetsNumfmt={},i.UniverCore,i.UniverSheets,i.UniverEngineNumfmt,i.rxjs,i.UniverEngineFormula))})(this,function(i,t,u,w,I,Y){"use strict";var fe=Object.defineProperty;var de=(i,t,u)=>t in i?fe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[t]=u;var R=(i,t,u)=>de(i,typeof t!="symbol"?t+"":t,u);const 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"}],Z="SHEET_NUMFMT_PLUGIN",E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getInfo(e).maxDecimals)!=null?n:r},J=(e,r)=>{if(e&&!r||!e&&r)return!1;const a=c=>c.reduce((y,h)=>{if(y.isEnd)return y;const C=h.value||h.num;return h.type==="point"?(y.isEnd=!0,y):{...y,result:y.result+C}},{isEnd:!1,result:""}).result,n=t.numfmt.getInfo(e)._partitions,s=t.numfmt.getInfo(r)._partitions,l=a(n[0].tokens),o=a(s[0].tokens),v=a(n[1].tokens),d=a(s[1].tokens);return l===o&&v===d&&n[1].color===s[1].color},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${D(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${D(Number(r||0))}$1`):n).join(";"),X=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),N={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),l=u.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:o,subUnitId:v,worksheet:d}=l,c=r.values.filter(f=>!!f.pattern),y=r.values.filter(f=>!f.pattern),h=u.transformCellsToRange(o,v,c),C={unitId:o,subUnitId:v,ranges:y.map(f=>({startColumn:f.col,startRow:f.row,endColumn:f.col,endRow:f.row}))},T=[],p=[];if(c.length){const f=c.reduce((S,m)=>{w.isTextFormat(m.pattern)&&S.setValue(m.row,m.col,{t:t.CellValueType.STRING});const M=d.getCellRaw(m.row,m.col);if(M){const U=u.checkCellValueType(M.v);U!==M.t&&S.setValue(m.row,m.col,{t:U})}return S},new t.ObjectMatrix).getMatrix(),b=new t.ObjectMatrix;new t.ObjectMatrix(f).forValue((S,m)=>{const M=d.getCellRaw(S,m);M?b.setValue(S,m,{t:M.t}):b.setValue(S,m,{t:void 0})}),Object.keys(h.values).forEach(S=>{const m=h.values[S];m.ranges=u.rangeMerge(m.ranges)}),T.push({id:u.SetNumfmtMutation.id,params:h});const _=u.factorySetNumfmtUndoMutation(e,h);p.push(..._)}if(y.length){C.ranges=u.rangeMerge(C.ranges);const f=y.reduce((S,m)=>{const M=d.getCellRaw(m.row,m.col);if(M){const U=u.checkCellValueType(M.v);U!==M.t&&S.setValue(m.row,m.col,{t:U})}return S},new t.ObjectMatrix).getMatrix(),b=new t.ObjectMatrix;new t.ObjectMatrix(f).forValue((S,m)=>{const M=d.getCellRaw(S,m);M?b.setValue(S,m,{t:M.t}):b.setValue(S,m,{t:void 0})}),T.push({id:u.RemoveNumfmtMutation.id,params:C},{id:u.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:v,cellValue:f}});const _=u.factoryRemoveNumfmtUndoMutation(e,C);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:v,cellValue:b.getMatrix()}},..._)}const g=t.sequenceExecute(T,a).result;return g&&s.pushUndoRedo({unitID:o,undoMutations:p,redoMutations:T}),g}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=a.getCurrentSelections();if(!l||!l.length)return!1;const o=u.getSheetCommandTarget(s);if(!o)return!1;const{unitId:v,subUnitId:d}=o;let c=0;l.forEach(T=>{t.Range.foreach(T.range,(p,g)=>{const f=n.getValue(v,d,p,g);if(!f){const _=o.worksheet.getCellRaw(p,g);if(!c&&_&&_.t===t.CellValueType.NUMBER&&_.v){const S=/\.(\d*)$/.exec(String(_.v));if(S){const m=S[1].length;if(!m)return;c=Math.max(c,m)}}return}const b=E(f.pattern);c=b>c?b:c})});const y=c+1,h=P(`0${y>0?".0":""}`,y),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(p,g)=>{const f=n.getValue(v,d,p,g);if(!f)C.push({row:p,col:g,pattern:h});else{const b=E(f.pattern),_=P(f.pattern,b+1);_!==f.pattern&&C.push({row:p,col:g,pattern:_})}})}),C.length?await r.executeCommand(N.id,{values:C}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const B={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(u.SheetsSelectionsService),n=e.get(j),s=F[n.getCurrencySymbol()]||"$",l=a.getCurrentSelections();if(!l||!l.length)return!1;const o=[],v=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(y,h)=>{o.push({row:y,col:h,pattern:v,type:"currency"})})}),await r.executeCommand(N.id,{values:o})}},G={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(v=>{t.Range.foreach(v.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand(N.id,{values:s})}},W={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=a.getCurrentSelections();if(!l||!l.length)return!1;const o=u.getSheetCommandTarget(s);if(!o)return!1;const{unitId:v,subUnitId:d}=o;let c=0;l.forEach(p=>{t.Range.foreach(p.range,(g,f)=>{const b=n.getValue(v,d,g,f);if(!b){const S=o.worksheet.getCellRaw(g,f);if(!c&&S&&S.t===t.CellValueType.NUMBER&&S.v){const m=/\.(\d*)$/.exec(String(S.v));if(m){const M=m[1].length;if(!M)return;c=Math.max(c,M)}}return}const _=E(b.pattern);c=_>c?_:c})});const y=c-1,h=P(`0${y>0?".0":"."}`,y),C=[];return l.forEach(p=>{t.Range.foreach(p.range,(g,f)=>{const b=n.getValue(v,d,g,f);if(!b)C.push({row:g,col:f,pattern:h});else{const _=E(b.pattern);C.push({row:g,col:f,pattern:P(b.pattern,_-1)})}})}),await r.executeCommand(N.id,{values:C})}},Q=e=>t.numfmt.getInfo(e).type||"unknown",q=(e,r,a="en")=>{const s=t.numfmt.getInfo(e)._partitions[1],l=t.numfmt.format(e,r,{locale:a,throws:!1});return r<0?{result:l,color:s.color}:{result:l}},H=(e,r,a)=>e==="General"?{result:String(Y.stripErrorMargin(r))}:q(e,r,a);var ee=Object.getOwnPropertyDescriptor,te=(e,r,a,n)=>{for(var s=n>1?void 0:n?ee(r,a):r,l=e.length-1,o;l>=0;l--)(o=e[l])&&(s=o(s)||s);return s},$=(e,r)=>(a,n)=>r(a,n,e);const ne={tl:{size:6,color:"#409f11"}};i.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(a,n,s,l,o,v){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=a,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=o,this._localeService=v,this._initInterceptorCellContent()}get local(){const a=this._local$.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.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const a=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{a.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{const o=s.unitId,v=s.subUnitId;let d;const c=n;if(!c)return l(n);if(n!=null&&n.s){const g=s.workbook.getStyles().get(n.s);g!=null&&g.n&&(d=g.n)}if(d||(d=this._numfmtService.getValue(o,v,s.row,s.col)),!d||u.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if(w.isTextFormat(d.pattern))return l({...n,t:t.CellValueType.STRING,markers:{...n==null?void 0:n.markers,...ne}});let h="";const C=a.getValue(s.row,s.col);if(C&&C.parameters===`${c.v}_${d.pattern}`)return l({...n,...C.result});const T=H(d.pattern,Number(c.v),this.local);if(h=T.result,!h)return l(n);const p={v:h,t:t.CellValueType.NUMBER};if(T.color){const g=this._themeService.getCurrentTheme()[`${T.color}500`];g&&(p.interceptorStyle={cl:{rgb:g}})}return a.setValue(s.row,s.col,{result:p,parameters:`${c.v}_${d.pattern}`}),l({...n,...p})},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(v=>{t.Range.foreach(v,(d,c)=>{a.realDeleteValue(d,c)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,o)=>{a.realDeleteValue(l,o)})}})),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(()=>a.reset()))}setNumfmtLocal(a){this._local$.next(a)}},i.SheetsNumfmtCellContentController=te([$(0,t.IUniverInstanceService),$(1,t.Inject(u.SheetInterceptorService)),$(2,t.Inject(t.ThemeService)),$(3,t.Inject(t.ICommandService)),$(4,t.Inject(u.INumfmtService)),$(5,t.Inject(t.LocaleService))],i.SheetsNumfmtCellContentController);class k extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(a){this._currencySymbol$.next(a)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var re=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,ie=(e,r,a)=>r in e?re(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,se=(e,r,a,n)=>{for(var s=n>1?void 0:n?ae(r,a):r,l=e.length-1,o;l>=0;l--)(o=e[l])&&(s=o(s)||s);return s},z=(e,r)=>(a,n)=>r(a,n,e),K=(e,r,a)=>ie(e,typeof r!="symbol"?r+"":r,a);i.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=void 0,a,n){super(),this._config=r,this._injector=a,this._commandService=n}onStarting(){t.registerDependencies(this._injector,[[i.SheetsNumfmtCellContentController],[j],[k]]),t.touchDependencies(this._injector,[[i.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[k]]),[x,W,B,G,N].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},K(i.UniverSheetsNumfmtPlugin,"pluginName",Z),K(i.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),i.UniverSheetsNumfmtPlugin=se([t.DependentOn(u.UniverSheetsPlugin),z(1,t.Inject(t.Injector)),z(2,t.ICommandService)],i.UniverSheetsNumfmtPlugin);const le=e=>O.find(a=>e.includes(a)),ue=()=>O.map(e=>({label:e,value:e})),ce=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),oe=()=>A.map(e=>({label:e.label,value:e.suffix})),me=()=>L.map(e=>({label:e.label,value:e.suffix,color:e.color}));i.AddDecimalCommand=x,i.CURRENCYFORMAT=V,i.DATEFMTLISG=A,i.MenuCurrencyService=j,i.NUMBERFORMAT=L,i.SetCurrencyCommand=B,i.SetNumfmtCommand=N,i.SetPercentCommand=G,i.SubtractDecimalCommand=W,i.countryCurrencyMap=F,i.currencySymbols=O,i.getCurrencyFormatOptions=ce,i.getCurrencyOptions=ue,i.getCurrencyType=le,i.getDateFormatOptions=oe,i.getDecimalFromPattern=E,i.getDecimalString=D,i.getNumberFormatOptions=me,i.getPatternPreview=q,i.getPatternPreviewIgnoreGeneral=H,i.getPatternType=Q,i.isPatternEqualWithoutDecimal=J,i.isPatternHasDecimal=X,i.setPatternDecimal=P,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,17 +53,17 @@
|
|
|
53
53
|
"rxjs": ">=7.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@univerjs/core": "0.6.
|
|
57
|
-
"@univerjs/engine-
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/
|
|
56
|
+
"@univerjs/core": "0.6.1",
|
|
57
|
+
"@univerjs/engine-numfmt": "0.6.1",
|
|
58
|
+
"@univerjs/engine-formula": "0.6.1",
|
|
59
|
+
"@univerjs/sheets": "0.6.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"rxjs": "^7.8.1",
|
|
63
63
|
"typescript": "^5.7.3",
|
|
64
|
-
"vite": "^6.1.
|
|
65
|
-
"vitest": "^3.0.
|
|
66
|
-
"@univerjs-infra/shared": "0.6.
|
|
64
|
+
"vite": "^6.1.1",
|
|
65
|
+
"vitest": "^3.0.6",
|
|
66
|
+
"@univerjs-infra/shared": "0.6.1"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"test": "vitest run",
|