@univerjs/sheets-numfmt 0.6.6 → 0.6.7
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/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/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;
|
package/lib/es/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var M = (e, t, n) =>
|
|
4
|
-
import { numfmt as x, CommandType as
|
|
5
|
-
import { getSheetCommandTarget as
|
|
6
|
-
import { isTextFormat as
|
|
7
|
-
import { BehaviorSubject as
|
|
8
|
-
import { stripErrorMargin as
|
|
9
|
-
const
|
|
1
|
+
var ae = Object.defineProperty;
|
|
2
|
+
var le = (e, t, n) => t in e ? ae(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var M = (e, t, n) => le(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { numfmt as x, CommandType as P, ICommandService as E, IUniverInstanceService as F, IUndoRedoService as ue, CellValueType as I, ObjectMatrix as b, sequenceExecute as me, Range as N, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as K, UniverInstanceType as ee, DependentOn as ge, Injector as he, Plugin as pe, merge as Se, registerDependencies as ve, touchDependencies as z } from "@univerjs/core";
|
|
5
|
+
import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as Y, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ie } from "@univerjs/sheets";
|
|
6
|
+
import { isTextFormat as ne } from "@univerjs/engine-numfmt";
|
|
7
|
+
import { BehaviorSubject as k, merge as Ne, switchMap as Ee, of as Te, skip as xe } from "rxjs";
|
|
8
|
+
import { stripErrorMargin as Ve } from "@univerjs/engine-formula";
|
|
9
|
+
const re = [
|
|
10
10
|
"$",
|
|
11
11
|
"£",
|
|
12
12
|
"¥",
|
|
@@ -34,7 +34,7 @@ const te = [
|
|
|
34
34
|
"₽",
|
|
35
35
|
"₾",
|
|
36
36
|
"₿"
|
|
37
|
-
],
|
|
37
|
+
], Pe = {
|
|
38
38
|
US: "$",
|
|
39
39
|
// United States Dollar
|
|
40
40
|
CA: "C$",
|
|
@@ -74,7 +74,7 @@ const te = [
|
|
|
74
74
|
SI: "€",
|
|
75
75
|
ES: "€"
|
|
76
76
|
// Add more mappings as needed
|
|
77
|
-
},
|
|
77
|
+
}, Ue = [
|
|
78
78
|
{
|
|
79
79
|
label: "1930-08-05",
|
|
80
80
|
suffix: "yyyy-MM-dd"
|
|
@@ -119,7 +119,7 @@ const te = [
|
|
|
119
119
|
label: "08-05 下午 01:30",
|
|
120
120
|
suffix: "MM-dd A/P hh:mm"
|
|
121
121
|
}
|
|
122
|
-
],
|
|
122
|
+
], we = [
|
|
123
123
|
{
|
|
124
124
|
label: "(1,235)",
|
|
125
125
|
suffix: "#,##0_);(#,##0)"
|
|
@@ -147,7 +147,7 @@ const te = [
|
|
|
147
147
|
suffix: "#,##0.00_);[Red]-#,##0.00",
|
|
148
148
|
color: "red"
|
|
149
149
|
}
|
|
150
|
-
],
|
|
150
|
+
], se = [
|
|
151
151
|
{
|
|
152
152
|
label: (e) => `${e}1,235`,
|
|
153
153
|
suffix: (e) => `"${e}"#,##0.00_);"${e}"#,##0.00`
|
|
@@ -175,131 +175,131 @@ const te = [
|
|
|
175
175
|
suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
|
|
176
176
|
color: "red"
|
|
177
177
|
}
|
|
178
|
-
],
|
|
178
|
+
], Oe = "SHEET_NUMFMT_PLUGIN", w = (e, t = 0) => {
|
|
179
179
|
var r;
|
|
180
180
|
return e && (r = x.getInfo(e).maxDecimals) != null ? r : t;
|
|
181
|
-
},
|
|
181
|
+
}, tt = (e, t) => {
|
|
182
182
|
if (e && !t || !e && t)
|
|
183
183
|
return !1;
|
|
184
184
|
const n = (u) => u.reduce(
|
|
185
|
-
(
|
|
186
|
-
if (
|
|
187
|
-
return
|
|
188
|
-
const
|
|
189
|
-
return p.type === "point" ? (
|
|
185
|
+
(g, p) => {
|
|
186
|
+
if (g.isEnd)
|
|
187
|
+
return g;
|
|
188
|
+
const h = p.value || p.num;
|
|
189
|
+
return p.type === "point" ? (g.isEnd = !0, g) : { ...g, result: g.result + h };
|
|
190
190
|
},
|
|
191
191
|
{ isEnd: !1, result: "" }
|
|
192
|
-
).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens), c = n(s[0].tokens),
|
|
193
|
-
return o === c &&
|
|
192
|
+
).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens), c = n(s[0].tokens), i = n(r[1].tokens), d = n(s[1].tokens);
|
|
193
|
+
return o === c && i === d && r[1].color === s[1].color;
|
|
194
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(";"), nt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), U = {
|
|
201
201
|
id: "sheet.command.numfmt.set.numfmt",
|
|
202
|
-
type:
|
|
202
|
+
type: P.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(E), r = e.get(F), s = e.get(ue), o = H(r, t);
|
|
208
208
|
if (!o) return !1;
|
|
209
|
-
const { unitId: c, subUnitId:
|
|
209
|
+
const { unitId: c, subUnitId: i, worksheet: d } = o, u = t.values.filter((l) => !!l.pattern), g = t.values.filter((l) => !l.pattern), p = ye(c, i, u), h = {
|
|
210
210
|
unitId: c,
|
|
211
|
-
subUnitId:
|
|
212
|
-
ranges:
|
|
213
|
-
startColumn:
|
|
214
|
-
startRow:
|
|
215
|
-
endColumn:
|
|
216
|
-
endRow:
|
|
211
|
+
subUnitId: i,
|
|
212
|
+
ranges: g.map((l) => ({
|
|
213
|
+
startColumn: l.col,
|
|
214
|
+
startRow: l.row,
|
|
215
|
+
endColumn: l.col,
|
|
216
|
+
endRow: l.row
|
|
217
217
|
}))
|
|
218
|
-
}, C = [],
|
|
218
|
+
}, C = [], v = [];
|
|
219
219
|
if (u.length) {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
const _ =
|
|
220
|
+
const l = u.reduce((f, a) => {
|
|
221
|
+
ne(a.pattern) && f.setValue(a.row, a.col, { t: I.STRING });
|
|
222
|
+
const _ = d.getCellRaw(a.row, a.col);
|
|
223
223
|
if (_) {
|
|
224
|
-
const V =
|
|
225
|
-
V !== _.t &&
|
|
224
|
+
const V = G(_.v);
|
|
225
|
+
V !== _.t && f.setValue(a.row, a.col, { t: V });
|
|
226
226
|
}
|
|
227
|
-
return
|
|
228
|
-
}, new b()).getMatrix(),
|
|
229
|
-
new b(
|
|
230
|
-
const _ =
|
|
231
|
-
_ ?
|
|
232
|
-
}), Object.keys(p.values).forEach((
|
|
233
|
-
const a = p.values[
|
|
234
|
-
a.ranges =
|
|
227
|
+
return f;
|
|
228
|
+
}, new b()).getMatrix(), S = new b();
|
|
229
|
+
new b(l).forValue((f, a) => {
|
|
230
|
+
const _ = d.getCellRaw(f, a);
|
|
231
|
+
_ ? S.setValue(f, a, { t: _.t }) : S.setValue(f, a, { t: void 0 });
|
|
232
|
+
}), Object.keys(p.values).forEach((f) => {
|
|
233
|
+
const a = p.values[f];
|
|
234
|
+
a.ranges = Y(a.ranges);
|
|
235
235
|
}), C.push({
|
|
236
|
-
id:
|
|
236
|
+
id: te.id,
|
|
237
237
|
params: p
|
|
238
238
|
});
|
|
239
|
-
const y =
|
|
240
|
-
|
|
239
|
+
const y = _e(e, p);
|
|
240
|
+
v.push(...y);
|
|
241
241
|
}
|
|
242
|
-
if (
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
const _ =
|
|
242
|
+
if (g.length) {
|
|
243
|
+
h.ranges = Y(h.ranges);
|
|
244
|
+
const l = g.reduce((f, a) => {
|
|
245
|
+
const _ = d.getCellRaw(a.row, a.col);
|
|
246
246
|
if (_) {
|
|
247
|
-
const V =
|
|
248
|
-
V !== _.t &&
|
|
247
|
+
const V = G(_.v);
|
|
248
|
+
V !== _.t && f.setValue(a.row, a.col, { t: V });
|
|
249
249
|
}
|
|
250
|
-
return
|
|
251
|
-
}, new b()).getMatrix(),
|
|
252
|
-
new b(
|
|
253
|
-
const _ =
|
|
254
|
-
_ ?
|
|
250
|
+
return f;
|
|
251
|
+
}, new b()).getMatrix(), S = new b();
|
|
252
|
+
new b(l).forValue((f, a) => {
|
|
253
|
+
const _ = d.getCellRaw(f, a);
|
|
254
|
+
_ ? S.setValue(f, a, { t: _.t }) : S.setValue(f, a, { t: void 0 });
|
|
255
255
|
}), C.push({
|
|
256
|
-
id:
|
|
257
|
-
params:
|
|
256
|
+
id: Ce.id,
|
|
257
|
+
params: h
|
|
258
258
|
}, {
|
|
259
259
|
id: B.id,
|
|
260
260
|
params: {
|
|
261
261
|
unitId: c,
|
|
262
|
-
subUnitId:
|
|
263
|
-
cellValue:
|
|
262
|
+
subUnitId: i,
|
|
263
|
+
cellValue: l
|
|
264
264
|
}
|
|
265
265
|
});
|
|
266
|
-
const y =
|
|
267
|
-
|
|
266
|
+
const y = be(e, h);
|
|
267
|
+
v.push({
|
|
268
268
|
id: B.id,
|
|
269
269
|
params: {
|
|
270
270
|
unitId: c,
|
|
271
|
-
subUnitId:
|
|
272
|
-
cellValue:
|
|
271
|
+
subUnitId: i,
|
|
272
|
+
cellValue: S.getMatrix()
|
|
273
273
|
}
|
|
274
274
|
}, ...y);
|
|
275
275
|
}
|
|
276
|
-
const
|
|
277
|
-
return
|
|
276
|
+
const m = me(C, n).result;
|
|
277
|
+
return m && s.pushUndoRedo({
|
|
278
278
|
unitID: c,
|
|
279
|
-
undoMutations:
|
|
279
|
+
undoMutations: v,
|
|
280
280
|
redoMutations: C
|
|
281
|
-
}),
|
|
281
|
+
}), m;
|
|
282
282
|
}
|
|
283
|
-
},
|
|
283
|
+
}, De = {
|
|
284
284
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
285
|
-
type:
|
|
285
|
+
type: P.COMMAND,
|
|
286
286
|
handler: async (e) => {
|
|
287
|
-
const t = e.get(
|
|
287
|
+
const t = e.get(E), 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
|
-
const c =
|
|
290
|
+
const c = H(s);
|
|
291
291
|
if (!c) return !1;
|
|
292
|
-
const { unitId:
|
|
292
|
+
const { unitId: i, subUnitId: d } = c;
|
|
293
293
|
let u = 0;
|
|
294
294
|
o.forEach((C) => {
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
if (!
|
|
298
|
-
const y = c.worksheet.getCellRaw(
|
|
299
|
-
if (!u && y && y.t ===
|
|
300
|
-
const
|
|
301
|
-
if (
|
|
302
|
-
const a =
|
|
295
|
+
N.foreach(C.range, (v, m) => {
|
|
296
|
+
const l = r.getValue(i, d, v, m);
|
|
297
|
+
if (!l) {
|
|
298
|
+
const y = c.worksheet.getCellRaw(v, m);
|
|
299
|
+
if (!u && y && y.t === I.NUMBER && y.v) {
|
|
300
|
+
const f = /\.(\d*)$/.exec(String(y.v));
|
|
301
|
+
if (f) {
|
|
302
|
+
const a = f[1].length;
|
|
303
303
|
if (!a)
|
|
304
304
|
return;
|
|
305
305
|
u = Math.max(u, a);
|
|
@@ -307,35 +307,35 @@ const te = [
|
|
|
307
307
|
}
|
|
308
308
|
return;
|
|
309
309
|
}
|
|
310
|
-
const
|
|
311
|
-
u =
|
|
310
|
+
const S = w(l.pattern);
|
|
311
|
+
u = S > u ? S : u;
|
|
312
312
|
});
|
|
313
313
|
});
|
|
314
|
-
const
|
|
314
|
+
const g = u + 1, p = O(`0${g > 0 ? ".0" : ""}`, g), h = [];
|
|
315
315
|
return o.forEach((C) => {
|
|
316
|
-
|
|
317
|
-
const
|
|
318
|
-
if (!
|
|
319
|
-
|
|
320
|
-
row:
|
|
321
|
-
col:
|
|
316
|
+
N.foreach(C.range, (v, m) => {
|
|
317
|
+
const l = r.getValue(i, d, v, m);
|
|
318
|
+
if (!l)
|
|
319
|
+
h.push({
|
|
320
|
+
row: v,
|
|
321
|
+
col: m,
|
|
322
322
|
pattern: p
|
|
323
323
|
});
|
|
324
324
|
else {
|
|
325
|
-
const
|
|
326
|
-
y !==
|
|
327
|
-
row:
|
|
328
|
-
col:
|
|
325
|
+
const S = w(l.pattern), y = O(l.pattern, S + 1);
|
|
326
|
+
y !== l.pattern && h.push({
|
|
327
|
+
row: v,
|
|
328
|
+
col: m,
|
|
329
329
|
pattern: y
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
});
|
|
333
|
-
}),
|
|
333
|
+
}), h.length ? await t.executeCommand(U.id, { values: h }) : !1;
|
|
334
334
|
}
|
|
335
335
|
};
|
|
336
|
-
class
|
|
336
|
+
class oe {
|
|
337
337
|
constructor() {
|
|
338
|
-
M(this, "_currencySymbol$", new
|
|
338
|
+
M(this, "_currencySymbol$", new k("US"));
|
|
339
339
|
M(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
340
340
|
}
|
|
341
341
|
/**
|
|
@@ -348,52 +348,52 @@ class re {
|
|
|
348
348
|
return this._currencySymbol$.getValue();
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
-
const
|
|
351
|
+
const Ae = {
|
|
352
352
|
id: "sheet.command.numfmt.set.currency",
|
|
353
|
-
type:
|
|
353
|
+
type: P.COMMAND,
|
|
354
354
|
handler: async (e) => {
|
|
355
|
-
const t = e.get(
|
|
355
|
+
const t = e.get(E), n = e.get(j), r = e.get(oe), s = Pe[r.getCurrencySymbol()] || "$", o = n.getCurrentSelections();
|
|
356
356
|
if (!o || !o.length)
|
|
357
357
|
return !1;
|
|
358
|
-
const c = [],
|
|
358
|
+
const c = [], i = se[4].suffix(s);
|
|
359
359
|
return o.forEach((u) => {
|
|
360
|
-
|
|
361
|
-
c.push({ row:
|
|
360
|
+
N.foreach(u.range, (g, p) => {
|
|
361
|
+
c.push({ row: g, col: p, pattern: i, type: "currency" });
|
|
362
362
|
});
|
|
363
|
-
}), await t.executeCommand(
|
|
363
|
+
}), await t.executeCommand(U.id, { values: c });
|
|
364
364
|
}
|
|
365
|
-
},
|
|
365
|
+
}, Fe = {
|
|
366
366
|
id: "sheet.command.numfmt.set.percent",
|
|
367
|
-
type:
|
|
367
|
+
type: P.COMMAND,
|
|
368
368
|
handler: async (e) => {
|
|
369
|
-
const t = e.get(
|
|
369
|
+
const t = e.get(E), r = e.get(j).getCurrentSelections();
|
|
370
370
|
if (!r || !r.length)
|
|
371
371
|
return !1;
|
|
372
372
|
const s = [], o = "0%";
|
|
373
|
-
return r.forEach((
|
|
374
|
-
|
|
375
|
-
s.push({ row:
|
|
373
|
+
return r.forEach((i) => {
|
|
374
|
+
N.foreach(i.range, (d, u) => {
|
|
375
|
+
s.push({ row: d, col: u, pattern: o, type: "percent" });
|
|
376
376
|
});
|
|
377
|
-
}), await t.executeCommand(
|
|
377
|
+
}), await t.executeCommand(U.id, { values: s });
|
|
378
378
|
}
|
|
379
|
-
},
|
|
379
|
+
}, je = {
|
|
380
380
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
381
|
-
type:
|
|
381
|
+
type: P.COMMAND,
|
|
382
382
|
handler: async (e) => {
|
|
383
|
-
const t = e.get(
|
|
383
|
+
const t = e.get(E), 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
|
-
const c =
|
|
386
|
+
const c = H(s);
|
|
387
387
|
if (!c) return !1;
|
|
388
|
-
const { unitId:
|
|
388
|
+
const { unitId: i, subUnitId: d } = c;
|
|
389
389
|
let u = 0;
|
|
390
|
-
o.forEach((
|
|
391
|
-
|
|
392
|
-
const
|
|
393
|
-
if (!
|
|
394
|
-
const
|
|
395
|
-
if (!u &&
|
|
396
|
-
const a = /\.(\d*)$/.exec(String(
|
|
390
|
+
o.forEach((v) => {
|
|
391
|
+
N.foreach(v.range, (m, l) => {
|
|
392
|
+
const S = r.getValue(i, d, m, l);
|
|
393
|
+
if (!S) {
|
|
394
|
+
const f = c.worksheet.getCellRaw(m, l);
|
|
395
|
+
if (!u && f && f.t === I.NUMBER && f.v) {
|
|
396
|
+
const a = /\.(\d*)$/.exec(String(f.v));
|
|
397
397
|
if (a) {
|
|
398
398
|
const _ = a[1].length;
|
|
399
399
|
if (!_)
|
|
@@ -403,32 +403,32 @@ const Pe = {
|
|
|
403
403
|
}
|
|
404
404
|
return;
|
|
405
405
|
}
|
|
406
|
-
const y =
|
|
406
|
+
const y = w(S.pattern);
|
|
407
407
|
u = y > u ? y : u;
|
|
408
408
|
});
|
|
409
409
|
});
|
|
410
|
-
const
|
|
411
|
-
return o.forEach((
|
|
412
|
-
|
|
413
|
-
const
|
|
414
|
-
if (!
|
|
415
|
-
|
|
416
|
-
row:
|
|
417
|
-
col:
|
|
410
|
+
const g = u - 1, p = O(`0${g > 0 ? ".0" : "."}`, g), h = [];
|
|
411
|
+
return o.forEach((v) => {
|
|
412
|
+
N.foreach(v.range, (m, l) => {
|
|
413
|
+
const S = r.getValue(i, d, m, l);
|
|
414
|
+
if (!S)
|
|
415
|
+
h.push({
|
|
416
|
+
row: m,
|
|
417
|
+
col: l,
|
|
418
418
|
pattern: p
|
|
419
419
|
});
|
|
420
420
|
else {
|
|
421
|
-
const y =
|
|
422
|
-
|
|
423
|
-
row:
|
|
424
|
-
col:
|
|
425
|
-
pattern: O(
|
|
421
|
+
const y = w(S.pattern);
|
|
422
|
+
h.push({
|
|
423
|
+
row: m,
|
|
424
|
+
col: l,
|
|
425
|
+
pattern: O(S.pattern, y - 1)
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
428
|
});
|
|
429
|
-
}), await t.executeCommand(
|
|
429
|
+
}), await t.executeCommand(U.id, { values: h });
|
|
430
430
|
}
|
|
431
|
-
},
|
|
431
|
+
}, ce = "sheets-numfmt.config", Z = {}, rt = (e) => x.getInfo(e).type || "unknown", Le = (e, t, n = "en") => {
|
|
432
432
|
const s = x.getInfo(e)._partitions[1], o = x.format(e, t, { locale: n, throws: !1 });
|
|
433
433
|
return t < 0 ? {
|
|
434
434
|
result: o,
|
|
@@ -436,27 +436,27 @@ const Pe = {
|
|
|
436
436
|
} : {
|
|
437
437
|
result: o
|
|
438
438
|
};
|
|
439
|
-
},
|
|
440
|
-
result: String(
|
|
439
|
+
}, Ge = (e, t, n) => e === "General" ? {
|
|
440
|
+
result: String(Ve(t))
|
|
441
441
|
// In Excel, the default General format also needs to handle numeric precision.
|
|
442
|
-
} :
|
|
443
|
-
var
|
|
444
|
-
for (var s = r > 1 ? void 0 : r ?
|
|
442
|
+
} : Le(e, t, n);
|
|
443
|
+
var Be = Object.getOwnPropertyDescriptor, He = (e, t, n, r) => {
|
|
444
|
+
for (var s = r > 1 ? void 0 : r ? Be(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
|
-
},
|
|
448
|
-
const
|
|
447
|
+
}, R = (e, t) => (n, r) => t(n, r, e);
|
|
448
|
+
const We = {
|
|
449
449
|
tl: {
|
|
450
450
|
size: 6,
|
|
451
451
|
color: "#409f11"
|
|
452
452
|
}
|
|
453
453
|
};
|
|
454
|
-
let D = class extends
|
|
455
|
-
constructor(t, n, r, s, o, c) {
|
|
454
|
+
let D = class extends Q {
|
|
455
|
+
constructor(t, n, r, s, o, c, i) {
|
|
456
456
|
super();
|
|
457
|
-
M(this, "_local$", new
|
|
457
|
+
M(this, "_local$", new k("en"));
|
|
458
458
|
M(this, "local$", this._local$.asObservable());
|
|
459
|
-
this._instanceService = t, this._sheetInterceptorService = n, this._themeService = r, this._commandService = s, this._numfmtService = o, this._localeService = c, this._initInterceptorCellContent();
|
|
459
|
+
this._instanceService = t, this._sheetInterceptorService = n, this._themeService = r, this._commandService = s, this._numfmtService = o, this._localeService = c, this._configService = i, this._initInterceptorCellContent();
|
|
460
460
|
}
|
|
461
461
|
get local() {
|
|
462
462
|
const t = this._local$.getValue();
|
|
@@ -482,56 +482,60 @@ let D = class extends J {
|
|
|
482
482
|
// eslint-disable-next-line max-lines-per-function
|
|
483
483
|
_initInterceptorCellContent() {
|
|
484
484
|
const t = new b();
|
|
485
|
-
this.disposeWithMe(
|
|
485
|
+
this.disposeWithMe(Ne(this._local$, this._localeService.currentLocale$).subscribe(() => {
|
|
486
486
|
t.reset();
|
|
487
|
-
})), this.disposeWithMe(this._sheetInterceptorService.intercept(
|
|
488
|
-
effect:
|
|
487
|
+
})), this.disposeWithMe(this._sheetInterceptorService.intercept($e.CELL_CONTENT, {
|
|
488
|
+
effect: K.Value | K.Style,
|
|
489
489
|
handler: (n, r, s) => {
|
|
490
|
+
var v;
|
|
490
491
|
const o = r.unitId, c = r.subUnitId;
|
|
491
|
-
let
|
|
492
|
-
const
|
|
493
|
-
if (!
|
|
492
|
+
let i;
|
|
493
|
+
const d = n;
|
|
494
|
+
if (!d)
|
|
494
495
|
return s(n);
|
|
495
496
|
if (n != null && n.s) {
|
|
496
|
-
const
|
|
497
|
-
|
|
497
|
+
const m = r.workbook.getStyles().get(n.s);
|
|
498
|
+
m != null && m.n && (i = m.n);
|
|
498
499
|
}
|
|
499
|
-
if (
|
|
500
|
+
if (i || (i = this._numfmtService.getValue(o, c, r.row, r.col)), !i || G(d.v) !== I.NUMBER)
|
|
500
501
|
return s(n);
|
|
501
|
-
if (
|
|
502
|
-
return s({
|
|
502
|
+
if (ne(i.pattern))
|
|
503
|
+
return (v = this._configService.getConfig(ce)) != null && v.disableTextFormatMark ? s({
|
|
503
504
|
...n,
|
|
504
|
-
t:
|
|
505
|
+
t: I.STRING
|
|
506
|
+
}) : s({
|
|
507
|
+
...n,
|
|
508
|
+
t: I.STRING,
|
|
505
509
|
markers: {
|
|
506
510
|
...n == null ? void 0 : n.markers,
|
|
507
|
-
...
|
|
511
|
+
...We
|
|
508
512
|
}
|
|
509
513
|
});
|
|
510
|
-
let
|
|
514
|
+
let g = "";
|
|
511
515
|
const p = t.getValue(r.row, r.col);
|
|
512
|
-
if (p && p.parameters === `${
|
|
516
|
+
if (p && p.parameters === `${d.v}_${i.pattern}`)
|
|
513
517
|
return s({ ...n, ...p.result });
|
|
514
|
-
const
|
|
515
|
-
if (
|
|
518
|
+
const h = Ge(i.pattern, Number(d.v), this.local);
|
|
519
|
+
if (g = h.result, !g)
|
|
516
520
|
return s(n);
|
|
517
|
-
const C = { v:
|
|
518
|
-
if (
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
+
const C = { v: g, t: I.NUMBER };
|
|
522
|
+
if (h.color) {
|
|
523
|
+
const m = this._themeService.getCurrentTheme()[`${h.color}500`];
|
|
524
|
+
m && (C.interceptorStyle = { cl: { rgb: m } });
|
|
521
525
|
}
|
|
522
526
|
return t.setValue(r.row, r.col, {
|
|
523
527
|
result: C,
|
|
524
|
-
parameters: `${
|
|
528
|
+
parameters: `${d.v}_${i.pattern}`
|
|
525
529
|
}), s({ ...n, ...C });
|
|
526
530
|
},
|
|
527
|
-
priority:
|
|
531
|
+
priority: Re.NUMFMT
|
|
528
532
|
})), this.disposeWithMe(this._commandService.onCommandExecuted((n) => {
|
|
529
|
-
if (n.id ===
|
|
533
|
+
if (n.id === te.id) {
|
|
530
534
|
const r = n.params;
|
|
531
535
|
Object.keys(r.values).forEach((s) => {
|
|
532
536
|
r.values[s].ranges.forEach((c) => {
|
|
533
|
-
|
|
534
|
-
t.realDeleteValue(
|
|
537
|
+
N.foreach(c, (i, d) => {
|
|
538
|
+
t.realDeleteValue(i, d);
|
|
535
539
|
});
|
|
536
540
|
});
|
|
537
541
|
});
|
|
@@ -542,12 +546,12 @@ let D = class extends J {
|
|
|
542
546
|
});
|
|
543
547
|
}
|
|
544
548
|
})), this.disposeWithMe(
|
|
545
|
-
this._instanceService.getCurrentTypeOfUnit$(
|
|
546
|
-
|
|
549
|
+
this._instanceService.getCurrentTypeOfUnit$(ee.UNIVER_SHEET).pipe(
|
|
550
|
+
Ee((n) => {
|
|
547
551
|
var r;
|
|
548
|
-
return (r = n == null ? void 0 : n.activeSheet$) != null ? r :
|
|
552
|
+
return (r = n == null ? void 0 : n.activeSheet$) != null ? r : Te(null);
|
|
549
553
|
}),
|
|
550
|
-
|
|
554
|
+
xe(1)
|
|
551
555
|
).subscribe(() => t.reset())
|
|
552
556
|
);
|
|
553
557
|
}
|
|
@@ -555,18 +559,19 @@ let D = class extends J {
|
|
|
555
559
|
this._local$.next(t);
|
|
556
560
|
}
|
|
557
561
|
};
|
|
558
|
-
D =
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
562
|
+
D = He([
|
|
563
|
+
R(0, F),
|
|
564
|
+
R(1, T(Me)),
|
|
565
|
+
R(2, T(fe)),
|
|
566
|
+
R(3, T(E)),
|
|
567
|
+
R(4, T(W)),
|
|
568
|
+
R(5, T(de)),
|
|
569
|
+
R(6, X)
|
|
565
570
|
], D);
|
|
566
|
-
class
|
|
571
|
+
class J extends Q {
|
|
567
572
|
constructor() {
|
|
568
573
|
super(...arguments);
|
|
569
|
-
M(this, "_currencySymbol$", new
|
|
574
|
+
M(this, "_currencySymbol$", new k("US"));
|
|
570
575
|
M(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
571
576
|
}
|
|
572
577
|
/**
|
|
@@ -579,75 +584,83 @@ class Y extends J {
|
|
|
579
584
|
return this._currencySymbol$.getValue();
|
|
580
585
|
}
|
|
581
586
|
}
|
|
582
|
-
var
|
|
583
|
-
for (var s = r > 1 ? void 0 : r ?
|
|
587
|
+
var ke = Object.defineProperty, Ke = Object.getOwnPropertyDescriptor, ze = (e, t, n) => t in e ? ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, Ye = (e, t, n, r) => {
|
|
588
|
+
for (var s = r > 1 ? void 0 : r ? Ke(t, n) : t, o = e.length - 1, c; o >= 0; o--)
|
|
584
589
|
(c = e[o]) && (s = c(s) || s);
|
|
585
590
|
return s;
|
|
586
|
-
},
|
|
587
|
-
let A = class extends
|
|
588
|
-
constructor(e =
|
|
589
|
-
super(), this._config = e, this._injector = t, this._commandService =
|
|
591
|
+
}, L = (e, t) => (n, r) => t(n, r, e), ie = (e, t, n) => ze(e, typeof t != "symbol" ? t + "" : t, n);
|
|
592
|
+
let A = class extends pe {
|
|
593
|
+
constructor(e = Z, t, n, r) {
|
|
594
|
+
super(), this._config = e, this._injector = t, this._configService = n, this._commandService = r;
|
|
595
|
+
const { ...s } = Se(
|
|
596
|
+
{},
|
|
597
|
+
Z,
|
|
598
|
+
this._config
|
|
599
|
+
);
|
|
600
|
+
this._configService.setConfig(ce, s);
|
|
590
601
|
}
|
|
591
602
|
onStarting() {
|
|
592
|
-
|
|
603
|
+
ve(this._injector, [
|
|
593
604
|
[D],
|
|
594
|
-
[
|
|
595
|
-
[
|
|
605
|
+
[oe],
|
|
606
|
+
[J]
|
|
596
607
|
]), z(this._injector, [
|
|
597
608
|
[D]
|
|
598
609
|
]);
|
|
599
610
|
}
|
|
600
611
|
onRendered() {
|
|
601
612
|
z(this._injector, [
|
|
602
|
-
[
|
|
613
|
+
[J]
|
|
603
614
|
]), [
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
615
|
+
De,
|
|
616
|
+
je,
|
|
617
|
+
Ae,
|
|
618
|
+
Fe,
|
|
619
|
+
U
|
|
609
620
|
].forEach((e) => {
|
|
610
621
|
this.disposeWithMe(this._commandService.registerCommand(e));
|
|
611
622
|
});
|
|
612
623
|
}
|
|
613
624
|
};
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
A =
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
625
|
+
ie(A, "pluginName", Oe);
|
|
626
|
+
ie(A, "type", ee.UNIVER_SHEET);
|
|
627
|
+
A = Ye([
|
|
628
|
+
ge(Ie),
|
|
629
|
+
L(1, T(he)),
|
|
630
|
+
L(2, X),
|
|
631
|
+
L(3, E)
|
|
620
632
|
], A);
|
|
621
|
-
const
|
|
633
|
+
const st = (e) => re.find((n) => e.includes(n)), ot = () => re.map((e) => ({ label: e, value: e })), ct = (e) => se.map((t) => ({
|
|
622
634
|
label: t.label(e),
|
|
623
635
|
value: t.suffix(e),
|
|
624
636
|
color: t.color
|
|
625
|
-
})),
|
|
637
|
+
})), it = () => Ue.map((e) => ({ label: e.label, value: e.suffix })), at = () => we.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
626
638
|
export {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
639
|
+
De as AddDecimalCommand,
|
|
640
|
+
se as CURRENCYFORMAT,
|
|
641
|
+
Ue as DATEFMTLISG,
|
|
642
|
+
oe as MenuCurrencyService,
|
|
643
|
+
we as NUMBERFORMAT,
|
|
644
|
+
ce as SHEETS_NUMFMT_PLUGIN_CONFIG_KEY,
|
|
645
|
+
Ae as SetCurrencyCommand,
|
|
646
|
+
U as SetNumfmtCommand,
|
|
647
|
+
Fe as SetPercentCommand,
|
|
635
648
|
D as SheetsNumfmtCellContentController,
|
|
636
|
-
|
|
649
|
+
je as SubtractDecimalCommand,
|
|
637
650
|
A as UniverSheetsNumfmtPlugin,
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
651
|
+
Pe as countryCurrencyMap,
|
|
652
|
+
re as currencySymbols,
|
|
653
|
+
ct as getCurrencyFormatOptions,
|
|
654
|
+
ot as getCurrencyOptions,
|
|
655
|
+
st as getCurrencyType,
|
|
656
|
+
it as getDateFormatOptions,
|
|
657
|
+
w as getDecimalFromPattern,
|
|
645
658
|
q as getDecimalString,
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
659
|
+
at as getNumberFormatOptions,
|
|
660
|
+
Le as getPatternPreview,
|
|
661
|
+
Ge as getPatternPreviewIgnoreGeneral,
|
|
662
|
+
rt as getPatternType,
|
|
663
|
+
tt as isPatternEqualWithoutDecimal,
|
|
664
|
+
nt as isPatternHasDecimal,
|
|
652
665
|
O as setPatternDecimal
|
|
653
666
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SHEETS_NUMFMT_PLUGIN_CONFIG_KEY = "sheets-numfmt.config";
|
|
17
|
+
export declare const configSymbol: unique symbol;
|
|
18
|
+
export interface IUniverSheetsNumfmtConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Whether to disable the text format alert.
|
|
21
|
+
*/
|
|
22
|
+
disableTextFormatAlert?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to disable the text format mark.
|
|
25
|
+
*/
|
|
26
|
+
disableTextFormatMark?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare const defaultPluginConfig: IUniverSheetsNumfmtConfig;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INumfmtLocalTag, Disposable, ICommandService, IUniverInstanceService, LocaleService, ThemeService } from '@univerjs/core';
|
|
1
|
+
import { INumfmtLocalTag, Disposable, ICommandService, IConfigService, IUniverInstanceService, LocaleService, ThemeService } from '@univerjs/core';
|
|
2
2
|
import { INumfmtService, SheetInterceptorService } from '@univerjs/sheets';
|
|
3
3
|
export declare class SheetsNumfmtCellContentController extends Disposable {
|
|
4
4
|
private readonly _instanceService;
|
|
@@ -7,9 +7,10 @@ export declare class SheetsNumfmtCellContentController extends Disposable {
|
|
|
7
7
|
private _commandService;
|
|
8
8
|
private _numfmtService;
|
|
9
9
|
private _localeService;
|
|
10
|
+
private readonly _configService;
|
|
10
11
|
private _local$;
|
|
11
12
|
local$: import('rxjs').Observable<INumfmtLocalTag>;
|
|
12
|
-
constructor(_instanceService: IUniverInstanceService, _sheetInterceptorService: SheetInterceptorService, _themeService: ThemeService, _commandService: ICommandService, _numfmtService: INumfmtService, _localeService: LocaleService);
|
|
13
|
+
constructor(_instanceService: IUniverInstanceService, _sheetInterceptorService: SheetInterceptorService, _themeService: ThemeService, _commandService: ICommandService, _numfmtService: INumfmtService, _localeService: LocaleService, _configService: IConfigService);
|
|
13
14
|
get local(): INumfmtLocalTag;
|
|
14
15
|
private _initInterceptorCellContent;
|
|
15
16
|
setNumfmtLocal(local: INumfmtLocalTag): void;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export { getCurrencyType } from './utils/currency';
|
|
|
23
23
|
export { currencySymbols } from './base/const/currency-symbols';
|
|
24
24
|
export { SheetsNumfmtCellContentController } from './controllers/numfmt-cell-content.controller';
|
|
25
25
|
export { getCurrencyFormatOptions, getCurrencyOptions, getDateFormatOptions, getNumberFormatOptions } from './utils/options';
|
|
26
|
+
export { type IUniverSheetsNumfmtConfig, SHEETS_NUMFMT_PLUGIN_CONFIG_KEY } from './controllers/config.schema';
|
|
26
27
|
export { AddDecimalCommand } from './commands/commands/add-decimal.command';
|
|
27
28
|
export { SetCurrencyCommand } from './commands/commands/set-currency.command';
|
|
28
29
|
export { type ISetNumfmtCommandParams, SetNumfmtCommand } from './commands/commands/set-numfmt.command';
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IUniverSheetsNumfmtConfig } from './controllers/config.schema';
|
|
2
|
+
import { ICommandService, IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
2
3
|
export declare class UniverSheetsNumfmtPlugin extends Plugin {
|
|
3
4
|
private readonly _config;
|
|
4
5
|
readonly _injector: Injector;
|
|
6
|
+
private readonly _configService;
|
|
5
7
|
private readonly _commandService;
|
|
6
8
|
static pluginName: string;
|
|
7
9
|
static type: UniverInstanceType;
|
|
8
|
-
constructor(_config: undefined, _injector: Injector, _commandService: ICommandService);
|
|
10
|
+
constructor(_config: Partial<IUniverSheetsNumfmtConfig> | undefined, _injector: Injector, _configService: IConfigService, _commandService: ICommandService);
|
|
9
11
|
onStarting(): void;
|
|
10
12
|
onRendered(): void;
|
|
11
13
|
}
|
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,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"})});
|
|
1
|
+
(function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.UniverEngineNumfmt,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,c,A,I,J){"use strict";var ge=Object.defineProperty;var Se=(a,t,c)=>t in a?ge(a,t,{enumerable:!0,configurable:!0,writable:!0,value:c}):a[t]=c;var R=(a,t,c)=>Se(a,typeof t!="symbol"?t+"":t,c);const O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],x=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],X="SHEET_NUMFMT_PLUGIN",$=(e,r=0)=>{var n;return e&&(n=t.numfmt.getInfo(e).maxDecimals)!=null?n:r},Q=(e,r)=>{if(e&&!r||!e&&r)return!1;const i=o=>o.reduce((v,y)=>{if(v.isEnd)return v;const C=y.value||y.num;return y.type==="point"?(v.isEnd=!0,v):{...v,result:v.result+C}},{isEnd:!1,result:""}).result,n=t.numfmt.getInfo(e)._partitions,s=t.numfmt.getInfo(r)._partitions,l=i(n[0].tokens),m=i(s[0].tokens),S=i(n[1].tokens),d=i(s[1].tokens);return l===m&&S===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(";"),ee=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),E={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=c.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:d}=l,o=r.values.filter(u=>!!u.pattern),v=r.values.filter(u=>!u.pattern),y=c.transformCellsToRange(m,S,o),C={unitId:m,subUnitId:S,ranges:v.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],p=[];if(o.length){const u=o.reduce((g,f)=>{A.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const M=d.getCellRaw(f.row,f.col);if(M){const P=c.checkCellValueType(M.v);P!==M.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),_=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const M=d.getCellRaw(g,f);M?_.setValue(g,f,{t:M.t}):_.setValue(g,f,{t:void 0})}),Object.keys(y.values).forEach(g=>{const f=y.values[g];f.ranges=c.rangeMerge(f.ranges)}),T.push({id:c.SetNumfmtMutation.id,params:y});const b=c.factorySetNumfmtUndoMutation(e,y);p.push(...b)}if(v.length){C.ranges=c.rangeMerge(C.ranges);const u=v.reduce((g,f)=>{const M=d.getCellRaw(f.row,f.col);if(M){const P=c.checkCellValueType(M.v);P!==M.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),_=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const M=d.getCellRaw(g,f);M?_.setValue(g,f,{t:M.t}):_.setValue(g,f,{t:void 0})}),T.push({id:c.RemoveNumfmtMutation.id,params:C},{id:c.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const b=c.factoryRemoveNumfmtUndoMutation(e,C);p.push({id:c.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:_.getMatrix()}},...b)}const h=t.sequenceExecute(T,i).result;return h&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:T}),h}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(c.SheetsSelectionsService),n=e.get(c.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=c.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let o=0;l.forEach(T=>{t.Range.foreach(T.range,(p,h)=>{const u=n.getValue(S,d,p,h);if(!u){const b=m.worksheet.getCellRaw(p,h);if(!o&&b&&b.t===t.CellValueType.NUMBER&&b.v){const g=/\.(\d*)$/.exec(String(b.v));if(g){const f=g[1].length;if(!f)return;o=Math.max(o,f)}}return}const _=$(u.pattern);o=_>o?_:o})});const v=o+1,y=U(`0${v>0?".0":""}`,v),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(p,h)=>{const u=n.getValue(S,d,p,h);if(!u)C.push({row:p,col:h,pattern:y});else{const _=$(u.pattern),b=U(u.pattern,_+1);b!==u.pattern&&C.push({row:p,col:h,pattern:b})}})}),C.length?await r.executeCommand(E.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 H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(c.SheetsSelectionsService),n=e.get(j),s=L[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],S=V[4].suffix(s);return l.forEach(o=>{t.Range.foreach(o.range,(v,y)=>{m.push({row:v,col:y,pattern:S,type:"currency"})})}),await r.executeCommand(E.id,{values:m})}},W={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(c.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(d,o)=>{s.push({row:d,col:o,pattern:l,type:"percent"})})}),await r.executeCommand(E.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(c.SheetsSelectionsService),n=e.get(c.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=c.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let o=0;l.forEach(p=>{t.Range.foreach(p.range,(h,u)=>{const _=n.getValue(S,d,h,u);if(!_){const g=m.worksheet.getCellRaw(h,u);if(!o&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const M=f[1].length;if(!M)return;o=Math.max(o,M)}}return}const b=$(_.pattern);o=b>o?b:o})});const v=o-1,y=U(`0${v>0?".0":"."}`,v),C=[];return l.forEach(p=>{t.Range.foreach(p.range,(h,u)=>{const _=n.getValue(S,d,h,u);if(!_)C.push({row:h,col:u,pattern:y});else{const b=$(_.pattern);C.push({row:h,col:u,pattern:U(_.pattern,b-1)})}})}),await r.executeCommand(E.id,{values:C})}},w="sheets-numfmt.config",k={},te=e=>t.numfmt.getInfo(e).type||"unknown",K=(e,r,i="en")=>{const s=t.numfmt.getInfo(e)._partitions[1],l=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:l,color:s.color}:{result:l}},Y=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:K(e,r,i);var ne=Object.getOwnPropertyDescriptor,re=(e,r,i,n)=>{for(var s=n>1?void 0:n?ne(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,r)=>(i,n)=>r(i,n,e);const ie={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,d){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=d,this._initInterceptorCellContent()}get local(){const i=this._local$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(c.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var h;const m=s.unitId,S=s.subUnitId;let d;const o=n;if(!o)return l(n);if(n!=null&&n.s){const u=s.workbook.getStyles().get(n.s);u!=null&&u.n&&(d=u.n)}if(d||(d=this._numfmtService.getValue(m,S,s.row,s.col)),!d||c.checkCellValueType(o.v)!==t.CellValueType.NUMBER)return l(n);if(A.isTextFormat(d.pattern))return(h=this._configService.getConfig(w))!=null&&h.disableTextFormatMark?l({...n,t:t.CellValueType.STRING}):l({...n,t:t.CellValueType.STRING,markers:{...n==null?void 0:n.markers,...ie}});let y="";const C=i.getValue(s.row,s.col);if(C&&C.parameters===`${o.v}_${d.pattern}`)return l({...n,...C.result});const T=Y(d.pattern,Number(o.v),this.local);if(y=T.result,!y)return l(n);const p={v:y,t:t.CellValueType.NUMBER};if(T.color){const u=this._themeService.getCurrentTheme()[`${T.color}500`];u&&(p.interceptorStyle={cl:{rgb:u}})}return i.setValue(s.row,s.col,{result:p,parameters:`${o.v}_${d.pattern}`}),l({...n,...p})},priority:c.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===c.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(d,o)=>{i.realDeleteValue(d,o)})})})}else if(n.id===c.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._local$.next(i)}},a.SheetsNumfmtCellContentController=re([N(0,t.IUniverInstanceService),N(1,t.Inject(c.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(c.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);class z extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(i){this._currencySymbol$.next(i)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,se=Object.getOwnPropertyDescriptor,le=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,ue=(e,r,i,n)=>{for(var s=n>1?void 0:n?se(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},F=(e,r)=>(i,n)=>r(i,n,e),Z=(e,r,i)=>le(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=k,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},k,this._config);this._configService.setConfig(w,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[j],[z]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[z]]),[B,q,H,W,E].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=ue([t.DependentOn(c.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ce=e=>O.find(i=>e.includes(i)),oe=()=>O.map(e=>({label:e,value:e})),me=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>G.map(e=>({label:e.label,value:e.suffix})),de=()=>x.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=B,a.CURRENCYFORMAT=V,a.DATEFMTLISG=G,a.MenuCurrencyService=j,a.NUMBERFORMAT=x,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,a.SetCurrencyCommand=H,a.SetNumfmtCommand=E,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=me,a.getCurrencyOptions=oe,a.getCurrencyType=ce,a.getDateFormatOptions=fe,a.getDecimalFromPattern=$,a.getDecimalString=D,a.getNumberFormatOptions=de,a.getPatternPreview=K,a.getPatternPreviewIgnoreGeneral=Y,a.getPatternType=te,a.isPatternEqualWithoutDecimal=Q,a.isPatternHasDecimal=ee,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
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-numfmt": "0.6.
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/
|
|
56
|
+
"@univerjs/core": "0.6.7",
|
|
57
|
+
"@univerjs/engine-numfmt": "0.6.7",
|
|
58
|
+
"@univerjs/sheets": "0.6.7",
|
|
59
|
+
"@univerjs/engine-formula": "0.6.7"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"rxjs": "^7.8.1",
|
|
63
63
|
"typescript": "^5.8.2",
|
|
64
|
-
"vite": "^6.2.
|
|
65
|
-
"vitest": "^3.0.
|
|
66
|
-
"@univerjs-infra/shared": "0.6.
|
|
64
|
+
"vite": "^6.2.3",
|
|
65
|
+
"vitest": "^3.0.9",
|
|
66
|
+
"@univerjs-infra/shared": "0.6.7"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"test": "vitest run",
|