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