@univerjs/sheets-numfmt 0.5.4-nightly.202501200849 → 0.5.5-experimental.20250122-3362a4a
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/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +20 -14
- package/lib/es/index.js +354 -350
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});const sheetsNumfmt=require("@univerjs/sheets-numfmt"),facade=require("@univerjs/sheets/facade"),_FRangeLegacy=class _FRangeLegacy extends facade.FRange{setNumberFormat(pattern){const values=[];return this.forEach((row,col)=>values.push({row,col,pattern})),this._commandService.syncExecuteCommand(sheetsNumfmt.SetNumfmtCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),values}),this}};__name(_FRangeLegacy,"FRangeLegacy");let FRangeLegacy=_FRangeLegacy;facade.FRange.extend(FRangeLegacy);const _FWorkbookLegacy=class _FWorkbookLegacy extends facade.FWorkbook{setNumfmtLocal(local){return this._injector.get(sheetsNumfmt.SheetsNumfmtCellContentController).setNumfmtLocal(local),this}};__name(_FWorkbookLegacy,"FWorkbookLegacy");let FWorkbookLegacy=_FWorkbookLegacy;facade.FWorkbook.extend(FWorkbookLegacy);
|
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 __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),sheets=require("@univerjs/sheets"),rxjs=require("rxjs"),engineNumfmt=require("@univerjs/engine-numfmt"),engineFormula=require("@univerjs/engine-formula"),currencySymbols=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],countryCurrencyMap={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:"€"},DATEFMTLISG=[{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"}],NUMBERFORMAT=[{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"}],CURRENCYFORMAT=[{label:__name(suffix=>`${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);"${suffix}"#,##0.00`,"suffix")},{label:__name(suffix=>`${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]"${suffix}"#,##0.00`,"suffix"),color:"red"},{label:__name(suffix=>`(${suffix}1,235)`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);("${suffix}"#,##0.00)`,"suffix")},{label:__name(suffix=>`(${suffix}1,235)`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]("${suffix}"#,##0.00)`,"suffix"),color:"red"},{label:__name(suffix=>`-${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);-"${suffix}"#,##0.00`,"suffix")},{label:__name(suffix=>`-${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`,"suffix"),color:"red"}],SHEET_NUMFMT_PLUGIN="SHEET_NUMFMT_PLUGIN",getDecimalFromPattern=__name((pattern,defaultValue=0)=>{var _a3;return pattern&&(_a3=core.numfmt.getInfo(pattern).maxDecimals)!=null?_a3:defaultValue},"getDecimalFromPattern"),isPatternEqualWithoutDecimal=__name((patternA,patternB)=>{if(patternA&&!patternB||!patternA&&patternB)return!1;const getString=__name(tokens=>tokens.reduce((pre,cur)=>{if(pre.isEnd)return pre;const str=cur.value||cur.num;return cur.type==="point"?(pre.isEnd=!0,pre):{...pre,result:pre.result+str}},{isEnd:!1,result:""}).result,"getString"),partitionsA=core.numfmt.getInfo(patternA)._partitions,partitionsB=core.numfmt.getInfo(patternB)._partitions,A1=getString(partitionsA[0].tokens),B1=getString(partitionsB[0].tokens),A2=getString(partitionsA[1].tokens),B2=getString(partitionsB[1].tokens);return A1===B1&&A2===B2&&partitionsA[1].color===partitionsB[1].color},"isPatternEqualWithoutDecimal"),getDecimalString=__name(length=>new Array(Math.min(Math.max(0,Number(length)),30)).fill(0).join(""),"getDecimalString"),setPatternDecimal=__name((patterns,decimalLength)=>patterns.split(";").map(pattern=>/\.0?/.test(pattern)?pattern.replace(/\.0*/g,`${decimalLength>0?".":""}${getDecimalString(Number(decimalLength||0))}`):/0([^0]?)|0$/.test(pattern)?pattern.replace(/0([^0]+)|0$/,`0${decimalLength>0?".":""}${getDecimalString(Number(decimalLength||0))}$1`):pattern).join(";"),"setPatternDecimal"),isPatternHasDecimal=__name(pattern=>/\.0?/.test(pattern)||/0([^0]?)|0$/.test(pattern),"isPatternHasDecimal"),SetNumfmtCommand={id:"sheet.command.numfmt.set.numfmt",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{if(!params)return!1;const commandService=accessor.get(core.ICommandService),univerInstanceService=accessor.get(core.IUniverInstanceService),undoRedoService=accessor.get(core.IUndoRedoService),target=sheets.getSheetCommandTarget(univerInstanceService,params);if(!target)return!1;const{unitId,subUnitId}=target,setCells=params.values.filter(value=>!!value.pattern),removeCells=params.values.filter(value=>!value.pattern),setRedos=sheets.transformCellsToRange(unitId,subUnitId,setCells),removeRedos={unitId,subUnitId,ranges:removeCells.map(cell=>({startColumn:cell.col,startRow:cell.row,endColumn:cell.col,endRow:cell.row}))},redos=[],undos=[];if(setCells.length){Object.keys(setRedos.values).forEach(key=>{const v=setRedos.values[key];v.ranges=sheets.rangeMerge(v.ranges)}),redos.push({id:sheets.SetNumfmtMutation.id,params:setRedos});const undo=sheets.factorySetNumfmtUndoMutation(accessor,setRedos);undos.push(...undo)}if(removeCells.length){removeRedos.ranges=sheets.rangeMerge(removeRedos.ranges),redos.push({id:sheets.RemoveNumfmtMutation.id,params:removeRedos});const undo=sheets.factoryRemoveNumfmtUndoMutation(accessor,removeRedos);undos.push(...undo)}const result=core.sequenceExecute(redos,commandService).result;return result&&undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:undos,redoMutations:redos}),result},"handler")},AddDecimalCommand={id:"sheet.command.numfmt.add.decimal.command",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),numfmtService=accessor.get(sheets.INumfmtService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const target=sheets.getSheetCommandTarget(univerInstanceService);if(!target)return!1;const{unitId,subUnitId}=target;let maxDecimals=0;selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}return}const decimals2=getDecimalFromPattern(numfmtValue.pattern);maxDecimals=decimals2>maxDecimals?decimals2:maxDecimals})});const decimals=maxDecimals+1,defaultPattern=setPatternDecimal(`0${decimals>0?".0":""}`,decimals),values=[];return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)values.push({row,col,pattern:defaultPattern});else{const decimals2=getDecimalFromPattern(numfmtValue.pattern),pattern=setPatternDecimal(numfmtValue.pattern,decimals2+1);pattern!==numfmtValue.pattern&&values.push({row,col,pattern})}})}),values.length?await commandService.executeCommand(SetNumfmtCommand.id,{values}):!1},"handler")},_MenuCurrencyService=class _MenuCurrencyService{constructor(){__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}};__name(_MenuCurrencyService,"MenuCurrencyService");let MenuCurrencyService=_MenuCurrencyService;const SetCurrencyCommand={id:"sheet.command.numfmt.set.currency",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),menuCurrencyService=accessor.get(MenuCurrencyService),symbol=countryCurrencyMap[menuCurrencyService.getCurrencySymbol()]||"$",selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix=CURRENCYFORMAT[4].suffix(symbol);return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{values.push({row,col,pattern:suffix,type:"currency"})})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")},SetPercentCommand={id:"sheet.command.numfmt.set.percent",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selections=accessor.get(sheets.SheetsSelectionsService).getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix="0%";return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{values.push({row,col,pattern:suffix,type:"percent"})})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")},SubtractDecimalCommand={id:"sheet.command.numfmt.subtract.decimal.command",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),numfmtService=accessor.get(sheets.INumfmtService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const target=sheets.getSheetCommandTarget(univerInstanceService);if(!target)return!1;const{unitId,subUnitId}=target;let maxDecimals=0;selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}return}const decimals2=getDecimalFromPattern(numfmtValue.pattern);maxDecimals=decimals2>maxDecimals?decimals2:maxDecimals})});const decimals=maxDecimals-1,defaultPattern=setPatternDecimal(`0${decimals>0?".0":"."}`,decimals),values=[];return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)values.push({row,col,pattern:defaultPattern});else{const decimals2=getDecimalFromPattern(numfmtValue.pattern);values.push({row,col,pattern:setPatternDecimal(numfmtValue.pattern,decimals2-1)})}})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")},getPatternType=__name(pattern=>core.numfmt.getInfo(pattern).type||"unknown","getPatternType"),getPatternPreview=__name((pattern,value,locale="en")=>{const negInfo=core.numfmt.getInfo(pattern)._partitions[1],result=core.numfmt.format(pattern,value,{locale,throws:!1});return value<0?{result,color:negInfo.color}:{result}},"getPatternPreview"),getPatternPreviewIgnoreGeneral=__name((pattern,value,locale)=>pattern==="General"?{result:String(engineFormula.stripErrorMargin(value))}:getPatternPreview(pattern,value,locale),"getPatternPreviewIgnoreGeneral");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a;exports.SheetsNumfmtCellContentController=(_a=class extends core.Disposable{constructor(_instanceService,_sheetInterceptorService,_themeService,_commandService,_numfmtService,_localeService){super();__publicField(this,"_local$",new rxjs.BehaviorSubject("en"));__publicField(this,"local$",this._local$.asObservable());this._instanceService=_instanceService,this._sheetInterceptorService=_sheetInterceptorService,this._themeService=_themeService,this._commandService=_commandService,this._numfmtService=_numfmtService,this._localeService=_localeService,this._initInterceptorCellContent()}get local(){const _local=this._local$.getValue();if(_local)return _local;switch(this._localeService.getCurrentLocale()){case core.LocaleType.FR_FR:return"fr";case core.LocaleType.RU_RU:return"ru";case core.LocaleType.VI_VN:return"vi";case core.LocaleType.ZH_CN:return"zh-CN";case core.LocaleType.ZH_TW:return"zh-TW";case core.LocaleType.EN_US:case core.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const TEXT_FORMAT_MARK={tl:{size:6,color:"#409f11"}},renderCache=new core.ObjectMatrix;this.disposeWithMe(rxjs.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{renderCache.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{effect:core.InterceptorEffectEnum.Value|core.InterceptorEffectEnum.Style,handler:__name((cell,location,next)=>{const unitId=location.unitId,sheetId=location.subUnitId;let numfmtValue;const originCellValue=cell;if(!originCellValue)return next(cell);if(cell!=null&&cell.s){const style=location.workbook.getStyles().get(cell.s);style!=null&&style.n&&(numfmtValue=style.n)}if(numfmtValue||(numfmtValue=this._numfmtService.getValue(unitId,sheetId,location.row,location.col)),!numfmtValue)return next(cell);if(numfmtValue.pattern===engineNumfmt.DEFAULT_TEXT_FORMAT&&originCellValue.v&&core.isRealNum(originCellValue.v))return next({...cell,markers:{...cell==null?void 0:cell.markers,...TEXT_FORMAT_MARK}});if(originCellValue.t!==core.CellValueType.NUMBER||originCellValue.v==null||Number.isNaN(originCellValue.v))return next(cell);let numfmtRes="";const cache=renderCache.getValue(location.row,location.col);if(cache&&cache.parameters===`${originCellValue.v}_${numfmtValue.pattern}`)return next({...cell,...cache.result});const info=getPatternPreviewIgnoreGeneral(numfmtValue.pattern,Number(originCellValue.v),this.local);if(numfmtRes=info.result,!numfmtRes)return next(cell);const res={v:numfmtRes};if(info.color){const color=this._themeService.getCurrentTheme()[`${info.color}500`];color&&(res.interceptorStyle={cl:{rgb:color}})}return renderCache.setValue(location.row,location.col,{result:res,parameters:`${originCellValue.v}_${numfmtValue.pattern}`}),next({...cell,...res})},"handler"),priority:sheets.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===sheets.SetNumfmtMutation.id){const params=commandInfo.params;Object.keys(params.values).forEach(key=>{params.values[key].ranges.forEach(range=>{core.Range.foreach(range,(row,col)=>{renderCache.realDeleteValue(row,col)})})})}else if(commandInfo.id===sheets.SetRangeValuesMutation.id){const params=commandInfo.params;new core.ObjectMatrix(params.cellValue).forValue((row,col)=>{renderCache.realDeleteValue(row,col)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.switchMap(workbook=>{var _a3;return(_a3=workbook==null?void 0:workbook.activeSheet$)!=null?_a3:rxjs.of(null)}),rxjs.skip(1)).subscribe(()=>renderCache.reset()))}setNumfmtLocal(local){this._local$.next(local)}},__name(_a,"SheetsNumfmtCellContentController"),_a);exports.SheetsNumfmtCellContentController=__decorateClass$1([__decorateParam$1(0,core.IUniverInstanceService),__decorateParam$1(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$1(2,core.Inject(core.ThemeService)),__decorateParam$1(3,core.Inject(core.ICommandService)),__decorateParam$1(4,core.Inject(sheets.INumfmtService)),__decorateParam$1(5,core.Inject(core.LocaleService))],exports.SheetsNumfmtCellContentController);const _NumfmtCurrencyController=class _NumfmtCurrencyController extends core.Disposable{constructor(){super(...arguments);__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}};__name(_NumfmtCurrencyController,"NumfmtCurrencyController");let NumfmtCurrencyController=_NumfmtCurrencyController;var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField"),_a2;exports.UniverSheetsNumfmtPlugin=(_a2=class extends core.Plugin{constructor(_config=void 0,_injector,_commandService){super(),this._config=_config,this._injector=_injector,this._commandService=_commandService}onStarting(){core.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[MenuCurrencyService],[NumfmtCurrencyController]]),core.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){core.touchDependencies(this._injector,[[NumfmtCurrencyController]]),[AddDecimalCommand,SubtractDecimalCommand,SetCurrencyCommand,SetPercentCommand,SetNumfmtCommand].forEach(config=>{this.disposeWithMe(this._commandService.registerCommand(config))})}},__name(_a2,"UniverSheetsNumfmtPlugin"),_a2);__publicField2(exports.UniverSheetsNumfmtPlugin,"pluginName",SHEET_NUMFMT_PLUGIN);__publicField2(exports.UniverSheetsNumfmtPlugin,"type",core.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.ICommandService)],exports.UniverSheetsNumfmtPlugin);const getCurrencyType=__name(pattern=>currencySymbols.find(code=>pattern.includes(code)),"getCurrencyType"),getCurrencyOptions=__name(()=>currencySymbols.map(item=>({label:item,value:item})),"getCurrencyOptions"),getCurrencyFormatOptions=__name(suffix=>CURRENCYFORMAT.map(item=>({label:item.label(suffix),value:item.suffix(suffix),color:item.color})),"getCurrencyFormatOptions"),getDateFormatOptions=__name(()=>DATEFMTLISG.map(item=>({label:item.label,value:item.suffix})),"getDateFormatOptions"),getNumberFormatOptions=__name(()=>NUMBERFORMAT.map(item=>({label:item.label,value:item.suffix,color:item.color})),"getNumberFormatOptions");exports.AddDecimalCommand=AddDecimalCommand;exports.CURRENCYFORMAT=CURRENCYFORMAT;exports.DATEFMTLISG=DATEFMTLISG;exports.MenuCurrencyService=MenuCurrencyService;exports.NUMBERFORMAT=NUMBERFORMAT;exports.SetCurrencyCommand=SetCurrencyCommand;exports.SetNumfmtCommand=SetNumfmtCommand;exports.SetPercentCommand=SetPercentCommand;exports.SubtractDecimalCommand=SubtractDecimalCommand;exports.countryCurrencyMap=countryCurrencyMap;exports.currencySymbols=currencySymbols;exports.getCurrencyFormatOptions=getCurrencyFormatOptions;exports.getCurrencyOptions=getCurrencyOptions;exports.getCurrencyType=getCurrencyType;exports.getDateFormatOptions=getDateFormatOptions;exports.getDecimalFromPattern=getDecimalFromPattern;exports.getDecimalString=getDecimalString;exports.getNumberFormatOptions=getNumberFormatOptions;exports.getPatternPreview=getPatternPreview;exports.getPatternPreviewIgnoreGeneral=getPatternPreviewIgnoreGeneral;exports.getPatternType=getPatternType;exports.isPatternEqualWithoutDecimal=isPatternEqualWithoutDecimal;exports.isPatternHasDecimal=isPatternHasDecimal;exports.setPatternDecimal=setPatternDecimal;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
3
|
+
import { SetNumfmtCommand, SheetsNumfmtCellContentController } from "@univerjs/sheets-numfmt";
|
|
4
|
+
import { FRange, FWorkbook } from "@univerjs/sheets/facade";
|
|
5
|
+
const _FRangeLegacy = class _FRangeLegacy extends FRange {
|
|
6
|
+
setNumberFormat(pattern) {
|
|
7
|
+
const values = [];
|
|
8
|
+
return this.forEach((row, col) => values.push({ row, col, pattern })), this._commandService.syncExecuteCommand(SetNumfmtCommand.id, {
|
|
7
9
|
unitId: this._workbook.getUnitId(),
|
|
8
10
|
subUnitId: this._worksheet.getSheetId(),
|
|
9
|
-
values
|
|
11
|
+
values
|
|
10
12
|
}), this;
|
|
11
13
|
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
};
|
|
15
|
+
__name(_FRangeLegacy, "FRangeLegacy");
|
|
16
|
+
let FRangeLegacy = _FRangeLegacy;
|
|
17
|
+
FRange.extend(FRangeLegacy);
|
|
18
|
+
const _FWorkbookLegacy = class _FWorkbookLegacy extends FWorkbook {
|
|
19
|
+
setNumfmtLocal(local) {
|
|
20
|
+
return this._injector.get(SheetsNumfmtCellContentController).setNumfmtLocal(local), this;
|
|
17
21
|
}
|
|
18
|
-
}
|
|
19
|
-
|
|
22
|
+
};
|
|
23
|
+
__name(_FWorkbookLegacy, "FWorkbookLegacy");
|
|
24
|
+
let FWorkbookLegacy = _FWorkbookLegacy;
|
|
25
|
+
FWorkbook.extend(FWorkbookLegacy);
|
package/lib/es/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { numfmt, CommandType, ICommandService, IUniverInstanceService, IUndoRedoService, sequenceExecute, Range, CellValueType, Inject, ThemeService, LocaleService, Disposable, LocaleType, ObjectMatrix, InterceptorEffectEnum, isRealNum, UniverInstanceType, DependentOn, Injector, Plugin, registerDependencies, touchDependencies } from "@univerjs/core";
|
|
6
|
+
import { getSheetCommandTarget, transformCellsToRange, rangeMerge, SetNumfmtMutation, factorySetNumfmtUndoMutation, RemoveNumfmtMutation, factoryRemoveNumfmtUndoMutation, SheetsSelectionsService, INumfmtService, SheetInterceptorService, INTERCEPTOR_POINT, InterceptCellContentPriority, SetRangeValuesMutation, UniverSheetsPlugin } from "@univerjs/sheets";
|
|
7
|
+
import { BehaviorSubject, merge, switchMap, of, skip } from "rxjs";
|
|
8
|
+
import { DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
|
|
9
|
+
import { stripErrorMargin } from "@univerjs/engine-formula";
|
|
10
|
+
const currencySymbols = [
|
|
10
11
|
"$",
|
|
11
12
|
"£",
|
|
12
13
|
"¥",
|
|
@@ -34,7 +35,7 @@ const J = [
|
|
|
34
35
|
"₽",
|
|
35
36
|
"₾",
|
|
36
37
|
"₿"
|
|
37
|
-
],
|
|
38
|
+
], countryCurrencyMap = {
|
|
38
39
|
US: "$",
|
|
39
40
|
// United States Dollar
|
|
40
41
|
CA: "C$",
|
|
@@ -74,7 +75,7 @@ const J = [
|
|
|
74
75
|
SI: "€",
|
|
75
76
|
ES: "€"
|
|
76
77
|
// Add more mappings as needed
|
|
77
|
-
},
|
|
78
|
+
}, DATEFMTLISG = [
|
|
78
79
|
{
|
|
79
80
|
label: "1930-08-05",
|
|
80
81
|
suffix: "yyyy-MM-dd"
|
|
@@ -119,7 +120,7 @@ const J = [
|
|
|
119
120
|
label: "08-05 下午 01:30",
|
|
120
121
|
suffix: "MM-dd A/P hh:mm"
|
|
121
122
|
}
|
|
122
|
-
],
|
|
123
|
+
], NUMBERFORMAT = [
|
|
123
124
|
{
|
|
124
125
|
label: "(1,235)",
|
|
125
126
|
suffix: "#,##0_);(#,##0)"
|
|
@@ -147,468 +148,471 @@ const J = [
|
|
|
147
148
|
suffix: "#,##0.00_);[Red]-#,##0.00",
|
|
148
149
|
color: "red"
|
|
149
150
|
}
|
|
150
|
-
],
|
|
151
|
+
], CURRENCYFORMAT = [
|
|
151
152
|
{
|
|
152
|
-
label: (
|
|
153
|
-
suffix: (
|
|
153
|
+
label: /* @__PURE__ */ __name((suffix) => `${suffix}1,235`, "label"),
|
|
154
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);"${suffix}"#,##0.00`, "suffix")
|
|
154
155
|
},
|
|
155
156
|
{
|
|
156
|
-
label: (
|
|
157
|
-
suffix: (
|
|
157
|
+
label: /* @__PURE__ */ __name((suffix) => `${suffix}1,235`, "label"),
|
|
158
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]"${suffix}"#,##0.00`, "suffix"),
|
|
158
159
|
color: "red"
|
|
159
160
|
},
|
|
160
161
|
{
|
|
161
|
-
label: (
|
|
162
|
-
suffix: (
|
|
162
|
+
label: /* @__PURE__ */ __name((suffix) => `(${suffix}1,235)`, "label"),
|
|
163
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);("${suffix}"#,##0.00)`, "suffix")
|
|
163
164
|
},
|
|
164
165
|
{
|
|
165
|
-
label: (
|
|
166
|
-
suffix: (
|
|
166
|
+
label: /* @__PURE__ */ __name((suffix) => `(${suffix}1,235)`, "label"),
|
|
167
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]("${suffix}"#,##0.00)`, "suffix"),
|
|
167
168
|
color: "red"
|
|
168
169
|
},
|
|
169
170
|
{
|
|
170
|
-
label: (
|
|
171
|
-
suffix: (
|
|
171
|
+
label: /* @__PURE__ */ __name((suffix) => `-${suffix}1,235`, "label"),
|
|
172
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);-"${suffix}"#,##0.00`, "suffix")
|
|
172
173
|
},
|
|
173
174
|
{
|
|
174
|
-
label: (
|
|
175
|
-
suffix: (
|
|
175
|
+
label: /* @__PURE__ */ __name((suffix) => `-${suffix}1,235`, "label"),
|
|
176
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`, "suffix"),
|
|
176
177
|
color: "red"
|
|
177
178
|
}
|
|
178
|
-
],
|
|
179
|
-
var
|
|
180
|
-
return
|
|
181
|
-
},
|
|
182
|
-
if (
|
|
179
|
+
], SHEET_NUMFMT_PLUGIN = "SHEET_NUMFMT_PLUGIN", getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0) => {
|
|
180
|
+
var _a3;
|
|
181
|
+
return pattern && (_a3 = numfmt.getInfo(pattern).maxDecimals) != null ? _a3 : defaultValue;
|
|
182
|
+
}, "getDecimalFromPattern"), isPatternEqualWithoutDecimal = /* @__PURE__ */ __name((patternA, patternB) => {
|
|
183
|
+
if (patternA && !patternB || !patternA && patternB)
|
|
183
184
|
return !1;
|
|
184
|
-
const
|
|
185
|
-
(
|
|
186
|
-
if (
|
|
187
|
-
return
|
|
188
|
-
const
|
|
189
|
-
return
|
|
185
|
+
const getString = /* @__PURE__ */ __name((tokens) => tokens.reduce(
|
|
186
|
+
(pre, cur) => {
|
|
187
|
+
if (pre.isEnd)
|
|
188
|
+
return pre;
|
|
189
|
+
const str = cur.value || cur.num;
|
|
190
|
+
return cur.type === "point" ? (pre.isEnd = !0, pre) : { ...pre, result: pre.result + str };
|
|
190
191
|
},
|
|
191
192
|
{ isEnd: !1, result: "" }
|
|
192
|
-
).result,
|
|
193
|
-
return
|
|
194
|
-
},
|
|
193
|
+
).result, "getString"), partitionsA = numfmt.getInfo(patternA)._partitions, partitionsB = numfmt.getInfo(patternB)._partitions, A1 = getString(partitionsA[0].tokens), B1 = getString(partitionsB[0].tokens), A2 = getString(partitionsA[1].tokens), B2 = getString(partitionsB[1].tokens);
|
|
194
|
+
return A1 === B1 && A2 === B2 && partitionsA[1].color === partitionsB[1].color;
|
|
195
|
+
}, "isPatternEqualWithoutDecimal"), getDecimalString = /* @__PURE__ */ __name((length) => new Array(Math.min(Math.max(0, Number(length)), 30)).fill(0).join(""), "getDecimalString"), setPatternDecimal = /* @__PURE__ */ __name((patterns, decimalLength) => patterns.split(";").map((pattern) => /\.0?/.test(pattern) ? pattern.replace(
|
|
195
196
|
/\.0*/g,
|
|
196
|
-
`${
|
|
197
|
-
) : /0([^0]?)|0$/.test(
|
|
197
|
+
`${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}`
|
|
198
|
+
) : /0([^0]?)|0$/.test(pattern) ? pattern.replace(
|
|
198
199
|
/0([^0]+)|0$/,
|
|
199
|
-
`0${
|
|
200
|
-
) :
|
|
200
|
+
`0${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}$1`
|
|
201
|
+
) : pattern).join(";"), "setPatternDecimal"), isPatternHasDecimal = /* @__PURE__ */ __name((pattern) => /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern), "isPatternHasDecimal"), SetNumfmtCommand = {
|
|
201
202
|
id: "sheet.command.numfmt.set.numfmt",
|
|
202
|
-
type:
|
|
203
|
-
handler: (
|
|
204
|
-
if (!
|
|
203
|
+
type: CommandType.COMMAND,
|
|
204
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
205
|
+
if (!params)
|
|
205
206
|
return !1;
|
|
206
|
-
const
|
|
207
|
-
if (!
|
|
208
|
-
const { unitId
|
|
209
|
-
unitId
|
|
210
|
-
subUnitId
|
|
211
|
-
ranges:
|
|
212
|
-
startColumn:
|
|
213
|
-
startRow:
|
|
214
|
-
endColumn:
|
|
215
|
-
endRow:
|
|
207
|
+
const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), undoRedoService = accessor.get(IUndoRedoService), target = getSheetCommandTarget(univerInstanceService, params);
|
|
208
|
+
if (!target) return !1;
|
|
209
|
+
const { unitId, subUnitId } = target, setCells = params.values.filter((value) => !!value.pattern), removeCells = params.values.filter((value) => !value.pattern), setRedos = transformCellsToRange(unitId, subUnitId, setCells), removeRedos = {
|
|
210
|
+
unitId,
|
|
211
|
+
subUnitId,
|
|
212
|
+
ranges: removeCells.map((cell) => ({
|
|
213
|
+
startColumn: cell.col,
|
|
214
|
+
startRow: cell.row,
|
|
215
|
+
endColumn: cell.col,
|
|
216
|
+
endRow: cell.row
|
|
216
217
|
}))
|
|
217
|
-
},
|
|
218
|
-
if (
|
|
219
|
-
Object.keys(
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
}),
|
|
223
|
-
id:
|
|
224
|
-
params:
|
|
218
|
+
}, redos = [], undos = [];
|
|
219
|
+
if (setCells.length) {
|
|
220
|
+
Object.keys(setRedos.values).forEach((key) => {
|
|
221
|
+
const v = setRedos.values[key];
|
|
222
|
+
v.ranges = rangeMerge(v.ranges);
|
|
223
|
+
}), redos.push({
|
|
224
|
+
id: SetNumfmtMutation.id,
|
|
225
|
+
params: setRedos
|
|
225
226
|
});
|
|
226
|
-
const
|
|
227
|
-
|
|
227
|
+
const undo = factorySetNumfmtUndoMutation(accessor, setRedos);
|
|
228
|
+
undos.push(...undo);
|
|
228
229
|
}
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
id:
|
|
232
|
-
params:
|
|
230
|
+
if (removeCells.length) {
|
|
231
|
+
removeRedos.ranges = rangeMerge(removeRedos.ranges), redos.push({
|
|
232
|
+
id: RemoveNumfmtMutation.id,
|
|
233
|
+
params: removeRedos
|
|
233
234
|
});
|
|
234
|
-
const
|
|
235
|
-
|
|
235
|
+
const undo = factoryRemoveNumfmtUndoMutation(accessor, removeRedos);
|
|
236
|
+
undos.push(...undo);
|
|
236
237
|
}
|
|
237
|
-
const
|
|
238
|
-
return
|
|
239
|
-
unitID:
|
|
240
|
-
undoMutations:
|
|
241
|
-
redoMutations:
|
|
242
|
-
}),
|
|
243
|
-
}
|
|
244
|
-
},
|
|
238
|
+
const result = sequenceExecute(redos, commandService).result;
|
|
239
|
+
return result && undoRedoService.pushUndoRedo({
|
|
240
|
+
unitID: unitId,
|
|
241
|
+
undoMutations: undos,
|
|
242
|
+
redoMutations: redos
|
|
243
|
+
}), result;
|
|
244
|
+
}, "handler")
|
|
245
|
+
}, AddDecimalCommand = {
|
|
245
246
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
246
|
-
type:
|
|
247
|
-
handler: async (
|
|
248
|
-
const
|
|
249
|
-
if (!
|
|
247
|
+
type: CommandType.COMMAND,
|
|
248
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
249
|
+
const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), selections = selectionManagerService.getCurrentSelections();
|
|
250
|
+
if (!selections || !selections.length)
|
|
250
251
|
return !1;
|
|
251
|
-
const
|
|
252
|
-
if (!
|
|
253
|
-
const { unitId
|
|
254
|
-
let
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
if (!
|
|
259
|
-
const
|
|
260
|
-
if (!
|
|
261
|
-
const
|
|
262
|
-
if (
|
|
263
|
-
const
|
|
264
|
-
if (!
|
|
252
|
+
const target = getSheetCommandTarget(univerInstanceService);
|
|
253
|
+
if (!target) return !1;
|
|
254
|
+
const { unitId, subUnitId } = target;
|
|
255
|
+
let maxDecimals = 0;
|
|
256
|
+
selections.forEach((selection) => {
|
|
257
|
+
Range.foreach(selection.range, (row, col) => {
|
|
258
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
259
|
+
if (!numfmtValue) {
|
|
260
|
+
const cell = target.worksheet.getCellRaw(row, col);
|
|
261
|
+
if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
|
|
262
|
+
const regResult = /\.(\d*)$/.exec(String(cell.v));
|
|
263
|
+
if (regResult) {
|
|
264
|
+
const length = regResult[1].length;
|
|
265
|
+
if (!length)
|
|
265
266
|
return;
|
|
266
|
-
|
|
267
|
+
maxDecimals = Math.max(maxDecimals, length);
|
|
267
268
|
}
|
|
268
269
|
}
|
|
269
270
|
return;
|
|
270
271
|
}
|
|
271
|
-
const
|
|
272
|
-
|
|
272
|
+
const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
|
|
273
|
+
maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
|
|
273
274
|
});
|
|
274
275
|
});
|
|
275
|
-
const
|
|
276
|
-
return
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
if (!
|
|
280
|
-
|
|
281
|
-
row
|
|
282
|
-
col
|
|
283
|
-
pattern:
|
|
276
|
+
const decimals = maxDecimals + 1, defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : ""}`, decimals), values = [];
|
|
277
|
+
return selections.forEach((selection) => {
|
|
278
|
+
Range.foreach(selection.range, (row, col) => {
|
|
279
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
280
|
+
if (!numfmtValue)
|
|
281
|
+
values.push({
|
|
282
|
+
row,
|
|
283
|
+
col,
|
|
284
|
+
pattern: defaultPattern
|
|
284
285
|
});
|
|
285
286
|
else {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
row
|
|
289
|
-
col
|
|
290
|
-
pattern
|
|
287
|
+
const decimals2 = getDecimalFromPattern(numfmtValue.pattern), pattern = setPatternDecimal(numfmtValue.pattern, decimals2 + 1);
|
|
288
|
+
pattern !== numfmtValue.pattern && values.push({
|
|
289
|
+
row,
|
|
290
|
+
col,
|
|
291
|
+
pattern
|
|
291
292
|
});
|
|
292
293
|
}
|
|
293
294
|
});
|
|
294
|
-
}),
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
class k {
|
|
295
|
+
}), values.length ? await commandService.executeCommand(SetNumfmtCommand.id, { values }) : !1;
|
|
296
|
+
}, "handler")
|
|
297
|
+
}, _MenuCurrencyService = class _MenuCurrencyService {
|
|
298
298
|
constructor() {
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
__publicField(this, "_currencySymbol$", new BehaviorSubject("US"));
|
|
300
|
+
__publicField(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
301
301
|
}
|
|
302
302
|
/**
|
|
303
303
|
* Set the currency symbol by setting the country code.
|
|
304
304
|
*/
|
|
305
|
-
setCurrencySymbolByCountryCode(
|
|
306
|
-
this._currencySymbol$.next(
|
|
305
|
+
setCurrencySymbolByCountryCode(symbol) {
|
|
306
|
+
this._currencySymbol$.next(symbol);
|
|
307
307
|
}
|
|
308
308
|
getCurrencySymbol() {
|
|
309
309
|
return this._currencySymbol$.getValue();
|
|
310
310
|
}
|
|
311
|
-
}
|
|
312
|
-
|
|
311
|
+
};
|
|
312
|
+
__name(_MenuCurrencyService, "MenuCurrencyService");
|
|
313
|
+
let MenuCurrencyService = _MenuCurrencyService;
|
|
314
|
+
const SetCurrencyCommand = {
|
|
313
315
|
id: "sheet.command.numfmt.set.currency",
|
|
314
|
-
type:
|
|
315
|
-
handler: async (
|
|
316
|
-
const
|
|
317
|
-
if (!
|
|
316
|
+
type: CommandType.COMMAND,
|
|
317
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
318
|
+
const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), menuCurrencyService = accessor.get(MenuCurrencyService), symbol = countryCurrencyMap[menuCurrencyService.getCurrencySymbol()] || "$", selections = selectionManagerService.getCurrentSelections();
|
|
319
|
+
if (!selections || !selections.length)
|
|
318
320
|
return !1;
|
|
319
|
-
const
|
|
320
|
-
return
|
|
321
|
-
|
|
322
|
-
|
|
321
|
+
const values = [], suffix = CURRENCYFORMAT[4].suffix(symbol);
|
|
322
|
+
return selections.forEach((selection) => {
|
|
323
|
+
Range.foreach(selection.range, (row, col) => {
|
|
324
|
+
values.push({ row, col, pattern: suffix, type: "currency" });
|
|
323
325
|
});
|
|
324
|
-
}), await
|
|
325
|
-
}
|
|
326
|
-
},
|
|
326
|
+
}), await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
327
|
+
}, "handler")
|
|
328
|
+
}, SetPercentCommand = {
|
|
327
329
|
id: "sheet.command.numfmt.set.percent",
|
|
328
|
-
type:
|
|
329
|
-
handler: async (
|
|
330
|
-
const
|
|
331
|
-
if (!
|
|
330
|
+
type: CommandType.COMMAND,
|
|
331
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
332
|
+
const commandService = accessor.get(ICommandService), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
|
|
333
|
+
if (!selections || !selections.length)
|
|
332
334
|
return !1;
|
|
333
|
-
const
|
|
334
|
-
return
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
const values = [], suffix = "0%";
|
|
336
|
+
return selections.forEach((selection) => {
|
|
337
|
+
Range.foreach(selection.range, (row, col) => {
|
|
338
|
+
values.push({ row, col, pattern: suffix, type: "percent" });
|
|
337
339
|
});
|
|
338
|
-
}), await
|
|
339
|
-
}
|
|
340
|
-
},
|
|
340
|
+
}), await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
341
|
+
}, "handler")
|
|
342
|
+
}, SubtractDecimalCommand = {
|
|
341
343
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
342
|
-
type:
|
|
343
|
-
handler: async (
|
|
344
|
-
const
|
|
345
|
-
if (!
|
|
344
|
+
type: CommandType.COMMAND,
|
|
345
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
346
|
+
const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), selections = selectionManagerService.getCurrentSelections();
|
|
347
|
+
if (!selections || !selections.length)
|
|
346
348
|
return !1;
|
|
347
|
-
const
|
|
348
|
-
if (!
|
|
349
|
-
const { unitId
|
|
350
|
-
let
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
if (!
|
|
355
|
-
const
|
|
356
|
-
if (!
|
|
357
|
-
const
|
|
358
|
-
if (
|
|
359
|
-
const
|
|
360
|
-
if (!
|
|
349
|
+
const target = getSheetCommandTarget(univerInstanceService);
|
|
350
|
+
if (!target) return !1;
|
|
351
|
+
const { unitId, subUnitId } = target;
|
|
352
|
+
let maxDecimals = 0;
|
|
353
|
+
selections.forEach((selection) => {
|
|
354
|
+
Range.foreach(selection.range, (row, col) => {
|
|
355
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
356
|
+
if (!numfmtValue) {
|
|
357
|
+
const cell = target.worksheet.getCellRaw(row, col);
|
|
358
|
+
if (!maxDecimals && cell && cell.t === CellValueType.NUMBER && cell.v) {
|
|
359
|
+
const regResult = /\.(\d*)$/.exec(String(cell.v));
|
|
360
|
+
if (regResult) {
|
|
361
|
+
const length = regResult[1].length;
|
|
362
|
+
if (!length)
|
|
361
363
|
return;
|
|
362
|
-
|
|
364
|
+
maxDecimals = Math.max(maxDecimals, length);
|
|
363
365
|
}
|
|
364
366
|
}
|
|
365
367
|
return;
|
|
366
368
|
}
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
+
const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
|
|
370
|
+
maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
|
|
369
371
|
});
|
|
370
372
|
});
|
|
371
|
-
const
|
|
372
|
-
return
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
if (!
|
|
376
|
-
|
|
377
|
-
row
|
|
378
|
-
col
|
|
379
|
-
pattern:
|
|
373
|
+
const decimals = maxDecimals - 1, defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : "."}`, decimals), values = [];
|
|
374
|
+
return selections.forEach((selection) => {
|
|
375
|
+
Range.foreach(selection.range, (row, col) => {
|
|
376
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
377
|
+
if (!numfmtValue)
|
|
378
|
+
values.push({
|
|
379
|
+
row,
|
|
380
|
+
col,
|
|
381
|
+
pattern: defaultPattern
|
|
380
382
|
});
|
|
381
383
|
else {
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
row
|
|
385
|
-
col
|
|
386
|
-
pattern:
|
|
384
|
+
const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
|
|
385
|
+
values.push({
|
|
386
|
+
row,
|
|
387
|
+
col,
|
|
388
|
+
pattern: setPatternDecimal(numfmtValue.pattern, decimals2 - 1)
|
|
387
389
|
});
|
|
388
390
|
}
|
|
389
391
|
});
|
|
390
|
-
}), await
|
|
391
|
-
}
|
|
392
|
-
},
|
|
393
|
-
const
|
|
394
|
-
return
|
|
395
|
-
result
|
|
396
|
-
color:
|
|
392
|
+
}), await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
393
|
+
}, "handler")
|
|
394
|
+
}, getPatternType = /* @__PURE__ */ __name((pattern) => numfmt.getInfo(pattern).type || "unknown", "getPatternType"), getPatternPreview = /* @__PURE__ */ __name((pattern, value, locale = "en") => {
|
|
395
|
+
const negInfo = numfmt.getInfo(pattern)._partitions[1], result = numfmt.format(pattern, value, { locale, throws: !1 });
|
|
396
|
+
return value < 0 ? {
|
|
397
|
+
result,
|
|
398
|
+
color: negInfo.color
|
|
397
399
|
} : {
|
|
398
|
-
result
|
|
400
|
+
result
|
|
399
401
|
};
|
|
400
|
-
},
|
|
401
|
-
result: String(
|
|
402
|
+
}, "getPatternPreview"), getPatternPreviewIgnoreGeneral = /* @__PURE__ */ __name((pattern, value, locale) => pattern === "General" ? {
|
|
403
|
+
result: String(stripErrorMargin(value))
|
|
402
404
|
// In Excel, the default General format also needs to handle numeric precision.
|
|
403
|
-
} :
|
|
404
|
-
var
|
|
405
|
-
for (var
|
|
406
|
-
(
|
|
407
|
-
return
|
|
408
|
-
}, $ = (
|
|
409
|
-
let
|
|
410
|
-
constructor(
|
|
405
|
+
} : getPatternPreview(pattern, value, locale), "getPatternPreviewIgnoreGeneral");
|
|
406
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
407
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
408
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
409
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
410
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a;
|
|
411
|
+
let SheetsNumfmtCellContentController = (_a = class extends Disposable {
|
|
412
|
+
constructor(_instanceService, _sheetInterceptorService, _themeService, _commandService, _numfmtService, _localeService) {
|
|
411
413
|
super();
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
this._instanceService =
|
|
414
|
+
__publicField(this, "_local$", new BehaviorSubject("en"));
|
|
415
|
+
__publicField(this, "local$", this._local$.asObservable());
|
|
416
|
+
this._instanceService = _instanceService, this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._commandService = _commandService, this._numfmtService = _numfmtService, this._localeService = _localeService, this._initInterceptorCellContent();
|
|
415
417
|
}
|
|
416
418
|
get local() {
|
|
417
|
-
const
|
|
418
|
-
if (
|
|
419
|
-
return
|
|
419
|
+
const _local = this._local$.getValue();
|
|
420
|
+
if (_local)
|
|
421
|
+
return _local;
|
|
420
422
|
switch (this._localeService.getCurrentLocale()) {
|
|
421
|
-
case
|
|
423
|
+
case LocaleType.FR_FR:
|
|
422
424
|
return "fr";
|
|
423
|
-
case
|
|
425
|
+
case LocaleType.RU_RU:
|
|
424
426
|
return "ru";
|
|
425
|
-
case
|
|
427
|
+
case LocaleType.VI_VN:
|
|
426
428
|
return "vi";
|
|
427
|
-
case
|
|
429
|
+
case LocaleType.ZH_CN:
|
|
428
430
|
return "zh-CN";
|
|
429
|
-
case
|
|
431
|
+
case LocaleType.ZH_TW:
|
|
430
432
|
return "zh-TW";
|
|
431
|
-
case
|
|
432
|
-
case
|
|
433
|
+
case LocaleType.EN_US:
|
|
434
|
+
case LocaleType.FA_IR:
|
|
433
435
|
default:
|
|
434
436
|
return "en";
|
|
435
437
|
}
|
|
436
438
|
}
|
|
437
439
|
// eslint-disable-next-line max-lines-per-function
|
|
438
440
|
_initInterceptorCellContent() {
|
|
439
|
-
const
|
|
441
|
+
const TEXT_FORMAT_MARK = {
|
|
440
442
|
tl: {
|
|
441
443
|
size: 6,
|
|
442
444
|
color: "#409f11"
|
|
443
445
|
}
|
|
444
|
-
},
|
|
445
|
-
this.disposeWithMe(
|
|
446
|
-
|
|
447
|
-
})), this.disposeWithMe(this._sheetInterceptorService.intercept(
|
|
448
|
-
effect:
|
|
449
|
-
handler: (
|
|
450
|
-
const
|
|
451
|
-
let
|
|
452
|
-
const
|
|
453
|
-
if (!
|
|
454
|
-
return
|
|
455
|
-
if (
|
|
456
|
-
const
|
|
457
|
-
|
|
446
|
+
}, renderCache = new ObjectMatrix();
|
|
447
|
+
this.disposeWithMe(merge(this._local$, this._localeService.currentLocale$).subscribe(() => {
|
|
448
|
+
renderCache.reset();
|
|
449
|
+
})), this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
450
|
+
effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
|
|
451
|
+
handler: /* @__PURE__ */ __name((cell, location, next) => {
|
|
452
|
+
const unitId = location.unitId, sheetId = location.subUnitId;
|
|
453
|
+
let numfmtValue;
|
|
454
|
+
const originCellValue = cell;
|
|
455
|
+
if (!originCellValue)
|
|
456
|
+
return next(cell);
|
|
457
|
+
if (cell != null && cell.s) {
|
|
458
|
+
const style = location.workbook.getStyles().get(cell.s);
|
|
459
|
+
style != null && style.n && (numfmtValue = style.n);
|
|
458
460
|
}
|
|
459
|
-
if (
|
|
460
|
-
return
|
|
461
|
-
if (
|
|
462
|
-
return
|
|
463
|
-
...
|
|
461
|
+
if (numfmtValue || (numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col)), !numfmtValue)
|
|
462
|
+
return next(cell);
|
|
463
|
+
if (numfmtValue.pattern === DEFAULT_TEXT_FORMAT && originCellValue.v && isRealNum(originCellValue.v))
|
|
464
|
+
return next({
|
|
465
|
+
...cell,
|
|
464
466
|
markers: {
|
|
465
|
-
...
|
|
466
|
-
...
|
|
467
|
+
...cell == null ? void 0 : cell.markers,
|
|
468
|
+
...TEXT_FORMAT_MARK
|
|
467
469
|
}
|
|
468
470
|
});
|
|
469
|
-
if (
|
|
470
|
-
return
|
|
471
|
-
let
|
|
472
|
-
const
|
|
473
|
-
if (
|
|
474
|
-
return
|
|
475
|
-
const
|
|
476
|
-
if (
|
|
477
|
-
return
|
|
478
|
-
const
|
|
479
|
-
if (
|
|
480
|
-
const
|
|
481
|
-
|
|
471
|
+
if (originCellValue.t !== CellValueType.NUMBER || originCellValue.v == null || Number.isNaN(originCellValue.v))
|
|
472
|
+
return next(cell);
|
|
473
|
+
let numfmtRes = "";
|
|
474
|
+
const cache = renderCache.getValue(location.row, location.col);
|
|
475
|
+
if (cache && cache.parameters === `${originCellValue.v}_${numfmtValue.pattern}`)
|
|
476
|
+
return next({ ...cell, ...cache.result });
|
|
477
|
+
const info = getPatternPreviewIgnoreGeneral(numfmtValue.pattern, Number(originCellValue.v), this.local);
|
|
478
|
+
if (numfmtRes = info.result, !numfmtRes)
|
|
479
|
+
return next(cell);
|
|
480
|
+
const res = { v: numfmtRes };
|
|
481
|
+
if (info.color) {
|
|
482
|
+
const color = this._themeService.getCurrentTheme()[`${info.color}500`];
|
|
483
|
+
color && (res.interceptorStyle = { cl: { rgb: color } });
|
|
482
484
|
}
|
|
483
|
-
return
|
|
484
|
-
result:
|
|
485
|
-
parameters: `${
|
|
486
|
-
}),
|
|
487
|
-
},
|
|
488
|
-
priority:
|
|
489
|
-
})), this.disposeWithMe(this._commandService.onCommandExecuted((
|
|
490
|
-
if (
|
|
491
|
-
const
|
|
492
|
-
Object.keys(
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
485
|
+
return renderCache.setValue(location.row, location.col, {
|
|
486
|
+
result: res,
|
|
487
|
+
parameters: `${originCellValue.v}_${numfmtValue.pattern}`
|
|
488
|
+
}), next({ ...cell, ...res });
|
|
489
|
+
}, "handler"),
|
|
490
|
+
priority: InterceptCellContentPriority.NUMFMT
|
|
491
|
+
})), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
492
|
+
if (commandInfo.id === SetNumfmtMutation.id) {
|
|
493
|
+
const params = commandInfo.params;
|
|
494
|
+
Object.keys(params.values).forEach((key) => {
|
|
495
|
+
params.values[key].ranges.forEach((range) => {
|
|
496
|
+
Range.foreach(range, (row, col) => {
|
|
497
|
+
renderCache.realDeleteValue(row, col);
|
|
496
498
|
});
|
|
497
499
|
});
|
|
498
500
|
});
|
|
499
|
-
} else if (
|
|
500
|
-
const
|
|
501
|
-
new
|
|
502
|
-
|
|
501
|
+
} else if (commandInfo.id === SetRangeValuesMutation.id) {
|
|
502
|
+
const params = commandInfo.params;
|
|
503
|
+
new ObjectMatrix(params.cellValue).forValue((row, col) => {
|
|
504
|
+
renderCache.realDeleteValue(row, col);
|
|
503
505
|
});
|
|
504
506
|
}
|
|
505
507
|
})), this.disposeWithMe(
|
|
506
|
-
this._instanceService.getCurrentTypeOfUnit$(
|
|
507
|
-
|
|
508
|
-
var
|
|
509
|
-
return (
|
|
508
|
+
this._instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(
|
|
509
|
+
switchMap((workbook) => {
|
|
510
|
+
var _a3;
|
|
511
|
+
return (_a3 = workbook == null ? void 0 : workbook.activeSheet$) != null ? _a3 : of(null);
|
|
510
512
|
}),
|
|
511
|
-
|
|
512
|
-
).subscribe(() =>
|
|
513
|
+
skip(1)
|
|
514
|
+
).subscribe(() => renderCache.reset())
|
|
513
515
|
);
|
|
514
516
|
}
|
|
515
|
-
setNumfmtLocal(
|
|
516
|
-
this._local$.next(
|
|
517
|
+
setNumfmtLocal(local) {
|
|
518
|
+
this._local$.next(local);
|
|
517
519
|
}
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
$(0,
|
|
521
|
-
$(1,
|
|
522
|
-
$(2,
|
|
523
|
-
$(3,
|
|
524
|
-
$(4,
|
|
525
|
-
$(5,
|
|
526
|
-
],
|
|
527
|
-
class
|
|
520
|
+
}, __name(_a, "SheetsNumfmtCellContentController"), _a);
|
|
521
|
+
SheetsNumfmtCellContentController = __decorateClass$1([
|
|
522
|
+
__decorateParam$1(0, IUniverInstanceService),
|
|
523
|
+
__decorateParam$1(1, Inject(SheetInterceptorService)),
|
|
524
|
+
__decorateParam$1(2, Inject(ThemeService)),
|
|
525
|
+
__decorateParam$1(3, Inject(ICommandService)),
|
|
526
|
+
__decorateParam$1(4, Inject(INumfmtService)),
|
|
527
|
+
__decorateParam$1(5, Inject(LocaleService))
|
|
528
|
+
], SheetsNumfmtCellContentController);
|
|
529
|
+
const _NumfmtCurrencyController = class _NumfmtCurrencyController extends Disposable {
|
|
528
530
|
constructor() {
|
|
529
531
|
super(...arguments);
|
|
530
|
-
|
|
531
|
-
|
|
532
|
+
__publicField(this, "_currencySymbol$", new BehaviorSubject("US"));
|
|
533
|
+
__publicField(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
532
534
|
}
|
|
533
535
|
/**
|
|
534
536
|
* Set the currency symbol by setting the country code.
|
|
535
537
|
*/
|
|
536
|
-
setCurrencySymbolByCountryCode(
|
|
537
|
-
this._currencySymbol$.next(
|
|
538
|
+
setCurrencySymbolByCountryCode(symbol) {
|
|
539
|
+
this._currencySymbol$.next(symbol);
|
|
538
540
|
}
|
|
539
541
|
getCurrencySymbol() {
|
|
540
542
|
return this._currencySymbol$.getValue();
|
|
541
543
|
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
544
|
+
};
|
|
545
|
+
__name(_NumfmtCurrencyController, "NumfmtCurrencyController");
|
|
546
|
+
let NumfmtCurrencyController = _NumfmtCurrencyController;
|
|
547
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
548
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
549
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
550
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
551
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a2;
|
|
552
|
+
let UniverSheetsNumfmtPlugin = (_a2 = class extends Plugin {
|
|
553
|
+
constructor(_config = void 0, _injector, _commandService) {
|
|
554
|
+
super(), this._config = _config, this._injector = _injector, this._commandService = _commandService;
|
|
551
555
|
}
|
|
552
556
|
onStarting() {
|
|
553
|
-
|
|
554
|
-
[
|
|
555
|
-
[
|
|
556
|
-
[
|
|
557
|
-
]),
|
|
558
|
-
[
|
|
557
|
+
registerDependencies(this._injector, [
|
|
558
|
+
[SheetsNumfmtCellContentController],
|
|
559
|
+
[MenuCurrencyService],
|
|
560
|
+
[NumfmtCurrencyController]
|
|
561
|
+
]), touchDependencies(this._injector, [
|
|
562
|
+
[SheetsNumfmtCellContentController]
|
|
559
563
|
]);
|
|
560
564
|
}
|
|
561
565
|
onRendered() {
|
|
562
|
-
|
|
563
|
-
[
|
|
566
|
+
touchDependencies(this._injector, [
|
|
567
|
+
[NumfmtCurrencyController]
|
|
564
568
|
]), [
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
].forEach((
|
|
571
|
-
this.disposeWithMe(this._commandService.registerCommand(
|
|
569
|
+
AddDecimalCommand,
|
|
570
|
+
SubtractDecimalCommand,
|
|
571
|
+
SetCurrencyCommand,
|
|
572
|
+
SetPercentCommand,
|
|
573
|
+
SetNumfmtCommand
|
|
574
|
+
].forEach((config) => {
|
|
575
|
+
this.disposeWithMe(this._commandService.registerCommand(config));
|
|
572
576
|
});
|
|
573
577
|
}
|
|
574
|
-
};
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
],
|
|
582
|
-
const
|
|
583
|
-
label:
|
|
584
|
-
value:
|
|
585
|
-
color:
|
|
586
|
-
})),
|
|
578
|
+
}, __name(_a2, "UniverSheetsNumfmtPlugin"), _a2);
|
|
579
|
+
__publicField2(UniverSheetsNumfmtPlugin, "pluginName", SHEET_NUMFMT_PLUGIN);
|
|
580
|
+
__publicField2(UniverSheetsNumfmtPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
581
|
+
UniverSheetsNumfmtPlugin = __decorateClass([
|
|
582
|
+
DependentOn(UniverSheetsPlugin),
|
|
583
|
+
__decorateParam(1, Inject(Injector)),
|
|
584
|
+
__decorateParam(2, ICommandService)
|
|
585
|
+
], UniverSheetsNumfmtPlugin);
|
|
586
|
+
const getCurrencyType = /* @__PURE__ */ __name((pattern) => currencySymbols.find((code) => pattern.includes(code)), "getCurrencyType"), getCurrencyOptions = /* @__PURE__ */ __name(() => currencySymbols.map((item) => ({ label: item, value: item })), "getCurrencyOptions"), getCurrencyFormatOptions = /* @__PURE__ */ __name((suffix) => CURRENCYFORMAT.map((item) => ({
|
|
587
|
+
label: item.label(suffix),
|
|
588
|
+
value: item.suffix(suffix),
|
|
589
|
+
color: item.color
|
|
590
|
+
})), "getCurrencyFormatOptions"), getDateFormatOptions = /* @__PURE__ */ __name(() => DATEFMTLISG.map((item) => ({ label: item.label, value: item.suffix })), "getDateFormatOptions"), getNumberFormatOptions = /* @__PURE__ */ __name(() => NUMBERFORMAT.map((item) => ({ label: item.label, value: item.suffix, color: item.color })), "getNumberFormatOptions");
|
|
587
591
|
export {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
592
|
+
AddDecimalCommand,
|
|
593
|
+
CURRENCYFORMAT,
|
|
594
|
+
DATEFMTLISG,
|
|
595
|
+
MenuCurrencyService,
|
|
596
|
+
NUMBERFORMAT,
|
|
597
|
+
SetCurrencyCommand,
|
|
598
|
+
SetNumfmtCommand,
|
|
599
|
+
SetPercentCommand,
|
|
600
|
+
SheetsNumfmtCellContentController,
|
|
601
|
+
SubtractDecimalCommand,
|
|
602
|
+
UniverSheetsNumfmtPlugin,
|
|
603
|
+
countryCurrencyMap,
|
|
604
|
+
currencySymbols,
|
|
605
|
+
getCurrencyFormatOptions,
|
|
606
|
+
getCurrencyOptions,
|
|
607
|
+
getCurrencyType,
|
|
608
|
+
getDateFormatOptions,
|
|
609
|
+
getDecimalFromPattern,
|
|
610
|
+
getDecimalString,
|
|
611
|
+
getNumberFormatOptions,
|
|
612
|
+
getPatternPreview,
|
|
613
|
+
getPatternPreviewIgnoreGeneral,
|
|
614
|
+
getPatternType,
|
|
615
|
+
isPatternEqualWithoutDecimal,
|
|
616
|
+
isPatternHasDecimal,
|
|
617
|
+
setPatternDecimal
|
|
614
618
|
};
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(require("@univerjs/sheets-numfmt"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["@univerjs/sheets-numfmt","@univerjs/sheets/facade"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsNumfmt,global.UniverSheetsFacade))})(this,function(sheetsNumfmt,facade){"use strict";var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});const _FRangeLegacy=class _FRangeLegacy extends facade.FRange{setNumberFormat(pattern){const values=[];return this.forEach((row,col)=>values.push({row,col,pattern})),this._commandService.syncExecuteCommand(sheetsNumfmt.SetNumfmtCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),values}),this}};__name(_FRangeLegacy,"FRangeLegacy");let FRangeLegacy=_FRangeLegacy;facade.FRange.extend(FRangeLegacy);const _FWorkbookLegacy=class _FWorkbookLegacy extends facade.FWorkbook{setNumfmtLocal(local){return this._injector.get(sheetsNumfmt.SheetsNumfmtCellContentController).setNumfmtLocal(local),this}};__name(_FWorkbookLegacy,"FWorkbookLegacy");let FWorkbookLegacy=_FWorkbookLegacy;facade.FWorkbook.extend(FWorkbookLegacy)});
|
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(global,factory){typeof exports=="object"&&typeof module<"u"?factory(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"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsNumfmt={},global.UniverCore,global.UniverSheets,global.rxjs,global.UniverEngineNumfmt,global.UniverEngineFormula))})(this,function(exports2,core,sheets,rxjs,engineNumfmt,engineFormula){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b;const currencySymbols=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],countryCurrencyMap={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:"€"},DATEFMTLISG=[{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"}],NUMBERFORMAT=[{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"}],CURRENCYFORMAT=[{label:__name(suffix=>`${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);"${suffix}"#,##0.00`,"suffix")},{label:__name(suffix=>`${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]"${suffix}"#,##0.00`,"suffix"),color:"red"},{label:__name(suffix=>`(${suffix}1,235)`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);("${suffix}"#,##0.00)`,"suffix")},{label:__name(suffix=>`(${suffix}1,235)`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]("${suffix}"#,##0.00)`,"suffix"),color:"red"},{label:__name(suffix=>`-${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);-"${suffix}"#,##0.00`,"suffix")},{label:__name(suffix=>`-${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`,"suffix"),color:"red"}],SHEET_NUMFMT_PLUGIN="SHEET_NUMFMT_PLUGIN",getDecimalFromPattern=__name((pattern,defaultValue=0)=>{var _a2;return pattern&&(_a2=core.numfmt.getInfo(pattern).maxDecimals)!=null?_a2:defaultValue},"getDecimalFromPattern"),isPatternEqualWithoutDecimal=__name((patternA,patternB)=>{if(patternA&&!patternB||!patternA&&patternB)return!1;const getString=__name(tokens=>tokens.reduce((pre,cur)=>{if(pre.isEnd)return pre;const str=cur.value||cur.num;return cur.type==="point"?(pre.isEnd=!0,pre):{...pre,result:pre.result+str}},{isEnd:!1,result:""}).result,"getString"),partitionsA=core.numfmt.getInfo(patternA)._partitions,partitionsB=core.numfmt.getInfo(patternB)._partitions,A1=getString(partitionsA[0].tokens),B1=getString(partitionsB[0].tokens),A2=getString(partitionsA[1].tokens),B2=getString(partitionsB[1].tokens);return A1===B1&&A2===B2&&partitionsA[1].color===partitionsB[1].color},"isPatternEqualWithoutDecimal"),getDecimalString=__name(length=>new Array(Math.min(Math.max(0,Number(length)),30)).fill(0).join(""),"getDecimalString"),setPatternDecimal=__name((patterns,decimalLength)=>patterns.split(";").map(pattern=>/\.0?/.test(pattern)?pattern.replace(/\.0*/g,`${decimalLength>0?".":""}${getDecimalString(Number(decimalLength||0))}`):/0([^0]?)|0$/.test(pattern)?pattern.replace(/0([^0]+)|0$/,`0${decimalLength>0?".":""}${getDecimalString(Number(decimalLength||0))}$1`):pattern).join(";"),"setPatternDecimal"),isPatternHasDecimal=__name(pattern=>/\.0?/.test(pattern)||/0([^0]?)|0$/.test(pattern),"isPatternHasDecimal"),SetNumfmtCommand={id:"sheet.command.numfmt.set.numfmt",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{if(!params)return!1;const commandService=accessor.get(core.ICommandService),univerInstanceService=accessor.get(core.IUniverInstanceService),undoRedoService=accessor.get(core.IUndoRedoService),target=sheets.getSheetCommandTarget(univerInstanceService,params);if(!target)return!1;const{unitId,subUnitId}=target,setCells=params.values.filter(value=>!!value.pattern),removeCells=params.values.filter(value=>!value.pattern),setRedos=sheets.transformCellsToRange(unitId,subUnitId,setCells),removeRedos={unitId,subUnitId,ranges:removeCells.map(cell=>({startColumn:cell.col,startRow:cell.row,endColumn:cell.col,endRow:cell.row}))},redos=[],undos=[];if(setCells.length){Object.keys(setRedos.values).forEach(key=>{const v=setRedos.values[key];v.ranges=sheets.rangeMerge(v.ranges)}),redos.push({id:sheets.SetNumfmtMutation.id,params:setRedos});const undo=sheets.factorySetNumfmtUndoMutation(accessor,setRedos);undos.push(...undo)}if(removeCells.length){removeRedos.ranges=sheets.rangeMerge(removeRedos.ranges),redos.push({id:sheets.RemoveNumfmtMutation.id,params:removeRedos});const undo=sheets.factoryRemoveNumfmtUndoMutation(accessor,removeRedos);undos.push(...undo)}const result=core.sequenceExecute(redos,commandService).result;return result&&undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:undos,redoMutations:redos}),result},"handler")},AddDecimalCommand={id:"sheet.command.numfmt.add.decimal.command",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),numfmtService=accessor.get(sheets.INumfmtService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const target=sheets.getSheetCommandTarget(univerInstanceService);if(!target)return!1;const{unitId,subUnitId}=target;let maxDecimals=0;selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}return}const decimals2=getDecimalFromPattern(numfmtValue.pattern);maxDecimals=decimals2>maxDecimals?decimals2:maxDecimals})});const decimals=maxDecimals+1,defaultPattern=setPatternDecimal(`0${decimals>0?".0":""}`,decimals),values=[];return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)values.push({row,col,pattern:defaultPattern});else{const decimals2=getDecimalFromPattern(numfmtValue.pattern),pattern=setPatternDecimal(numfmtValue.pattern,decimals2+1);pattern!==numfmtValue.pattern&&values.push({row,col,pattern})}})}),values.length?await commandService.executeCommand(SetNumfmtCommand.id,{values}):!1},"handler")},_MenuCurrencyService=class _MenuCurrencyService{constructor(){__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}};__name(_MenuCurrencyService,"MenuCurrencyService");let MenuCurrencyService=_MenuCurrencyService;const SetCurrencyCommand={id:"sheet.command.numfmt.set.currency",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),menuCurrencyService=accessor.get(MenuCurrencyService),symbol=countryCurrencyMap[menuCurrencyService.getCurrencySymbol()]||"$",selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix=CURRENCYFORMAT[4].suffix(symbol);return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{values.push({row,col,pattern:suffix,type:"currency"})})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")},SetPercentCommand={id:"sheet.command.numfmt.set.percent",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selections=accessor.get(sheets.SheetsSelectionsService).getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix="0%";return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{values.push({row,col,pattern:suffix,type:"percent"})})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")},SubtractDecimalCommand={id:"sheet.command.numfmt.subtract.decimal.command",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),numfmtService=accessor.get(sheets.INumfmtService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const target=sheets.getSheetCommandTarget(univerInstanceService);if(!target)return!1;const{unitId,subUnitId}=target;let maxDecimals=0;selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}return}const decimals2=getDecimalFromPattern(numfmtValue.pattern);maxDecimals=decimals2>maxDecimals?decimals2:maxDecimals})});const decimals=maxDecimals-1,defaultPattern=setPatternDecimal(`0${decimals>0?".0":"."}`,decimals),values=[];return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)values.push({row,col,pattern:defaultPattern});else{const decimals2=getDecimalFromPattern(numfmtValue.pattern);values.push({row,col,pattern:setPatternDecimal(numfmtValue.pattern,decimals2-1)})}})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")},getPatternType=__name(pattern=>core.numfmt.getInfo(pattern).type||"unknown","getPatternType"),getPatternPreview=__name((pattern,value,locale="en")=>{const negInfo=core.numfmt.getInfo(pattern)._partitions[1],result=core.numfmt.format(pattern,value,{locale,throws:!1});return value<0?{result,color:negInfo.color}:{result}},"getPatternPreview"),getPatternPreviewIgnoreGeneral=__name((pattern,value,locale)=>pattern==="General"?{result:String(engineFormula.stripErrorMargin(value))}:getPatternPreview(pattern,value,locale),"getPatternPreviewIgnoreGeneral");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");exports2.SheetsNumfmtCellContentController=(_a=class extends core.Disposable{constructor(_instanceService,_sheetInterceptorService,_themeService,_commandService,_numfmtService,_localeService){super();__publicField(this,"_local$",new rxjs.BehaviorSubject("en"));__publicField(this,"local$",this._local$.asObservable());this._instanceService=_instanceService,this._sheetInterceptorService=_sheetInterceptorService,this._themeService=_themeService,this._commandService=_commandService,this._numfmtService=_numfmtService,this._localeService=_localeService,this._initInterceptorCellContent()}get local(){const _local=this._local$.getValue();if(_local)return _local;switch(this._localeService.getCurrentLocale()){case core.LocaleType.FR_FR:return"fr";case core.LocaleType.RU_RU:return"ru";case core.LocaleType.VI_VN:return"vi";case core.LocaleType.ZH_CN:return"zh-CN";case core.LocaleType.ZH_TW:return"zh-TW";case core.LocaleType.EN_US:case core.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const TEXT_FORMAT_MARK={tl:{size:6,color:"#409f11"}},renderCache=new core.ObjectMatrix;this.disposeWithMe(rxjs.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{renderCache.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{effect:core.InterceptorEffectEnum.Value|core.InterceptorEffectEnum.Style,handler:__name((cell,location,next)=>{const unitId=location.unitId,sheetId=location.subUnitId;let numfmtValue;const originCellValue=cell;if(!originCellValue)return next(cell);if(cell!=null&&cell.s){const style=location.workbook.getStyles().get(cell.s);style!=null&&style.n&&(numfmtValue=style.n)}if(numfmtValue||(numfmtValue=this._numfmtService.getValue(unitId,sheetId,location.row,location.col)),!numfmtValue)return next(cell);if(numfmtValue.pattern===engineNumfmt.DEFAULT_TEXT_FORMAT&&originCellValue.v&&core.isRealNum(originCellValue.v))return next({...cell,markers:{...cell==null?void 0:cell.markers,...TEXT_FORMAT_MARK}});if(originCellValue.t!==core.CellValueType.NUMBER||originCellValue.v==null||Number.isNaN(originCellValue.v))return next(cell);let numfmtRes="";const cache=renderCache.getValue(location.row,location.col);if(cache&&cache.parameters===`${originCellValue.v}_${numfmtValue.pattern}`)return next({...cell,...cache.result});const info=getPatternPreviewIgnoreGeneral(numfmtValue.pattern,Number(originCellValue.v),this.local);if(numfmtRes=info.result,!numfmtRes)return next(cell);const res={v:numfmtRes};if(info.color){const color=this._themeService.getCurrentTheme()[`${info.color}500`];color&&(res.interceptorStyle={cl:{rgb:color}})}return renderCache.setValue(location.row,location.col,{result:res,parameters:`${originCellValue.v}_${numfmtValue.pattern}`}),next({...cell,...res})},"handler"),priority:sheets.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===sheets.SetNumfmtMutation.id){const params=commandInfo.params;Object.keys(params.values).forEach(key=>{params.values[key].ranges.forEach(range=>{core.Range.foreach(range,(row,col)=>{renderCache.realDeleteValue(row,col)})})})}else if(commandInfo.id===sheets.SetRangeValuesMutation.id){const params=commandInfo.params;new core.ObjectMatrix(params.cellValue).forValue((row,col)=>{renderCache.realDeleteValue(row,col)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.switchMap(workbook=>{var _a2;return(_a2=workbook==null?void 0:workbook.activeSheet$)!=null?_a2:rxjs.of(null)}),rxjs.skip(1)).subscribe(()=>renderCache.reset()))}setNumfmtLocal(local){this._local$.next(local)}},__name(_a,"SheetsNumfmtCellContentController"),_a),exports2.SheetsNumfmtCellContentController=__decorateClass$1([__decorateParam$1(0,core.IUniverInstanceService),__decorateParam$1(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$1(2,core.Inject(core.ThemeService)),__decorateParam$1(3,core.Inject(core.ICommandService)),__decorateParam$1(4,core.Inject(sheets.INumfmtService)),__decorateParam$1(5,core.Inject(core.LocaleService))],exports2.SheetsNumfmtCellContentController);const _NumfmtCurrencyController=class _NumfmtCurrencyController extends core.Disposable{constructor(){super(...arguments);__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}};__name(_NumfmtCurrencyController,"NumfmtCurrencyController");let NumfmtCurrencyController=_NumfmtCurrencyController;var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");exports2.UniverSheetsNumfmtPlugin=(_b=class extends core.Plugin{constructor(_config=void 0,_injector,_commandService){super(),this._config=_config,this._injector=_injector,this._commandService=_commandService}onStarting(){core.registerDependencies(this._injector,[[exports2.SheetsNumfmtCellContentController],[MenuCurrencyService],[NumfmtCurrencyController]]),core.touchDependencies(this._injector,[[exports2.SheetsNumfmtCellContentController]])}onRendered(){core.touchDependencies(this._injector,[[NumfmtCurrencyController]]),[AddDecimalCommand,SubtractDecimalCommand,SetCurrencyCommand,SetPercentCommand,SetNumfmtCommand].forEach(config=>{this.disposeWithMe(this._commandService.registerCommand(config))})}},__name(_b,"UniverSheetsNumfmtPlugin"),_b),__publicField2(exports2.UniverSheetsNumfmtPlugin,"pluginName",SHEET_NUMFMT_PLUGIN),__publicField2(exports2.UniverSheetsNumfmtPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),exports2.UniverSheetsNumfmtPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.ICommandService)],exports2.UniverSheetsNumfmtPlugin);const getCurrencyType=__name(pattern=>currencySymbols.find(code=>pattern.includes(code)),"getCurrencyType"),getCurrencyOptions=__name(()=>currencySymbols.map(item=>({label:item,value:item})),"getCurrencyOptions"),getCurrencyFormatOptions=__name(suffix=>CURRENCYFORMAT.map(item=>({label:item.label(suffix),value:item.suffix(suffix),color:item.color})),"getCurrencyFormatOptions"),getDateFormatOptions=__name(()=>DATEFMTLISG.map(item=>({label:item.label,value:item.suffix})),"getDateFormatOptions"),getNumberFormatOptions=__name(()=>NUMBERFORMAT.map(item=>({label:item.label,value:item.suffix,color:item.color})),"getNumberFormatOptions");exports2.AddDecimalCommand=AddDecimalCommand,exports2.CURRENCYFORMAT=CURRENCYFORMAT,exports2.DATEFMTLISG=DATEFMTLISG,exports2.MenuCurrencyService=MenuCurrencyService,exports2.NUMBERFORMAT=NUMBERFORMAT,exports2.SetCurrencyCommand=SetCurrencyCommand,exports2.SetNumfmtCommand=SetNumfmtCommand,exports2.SetPercentCommand=SetPercentCommand,exports2.SubtractDecimalCommand=SubtractDecimalCommand,exports2.countryCurrencyMap=countryCurrencyMap,exports2.currencySymbols=currencySymbols,exports2.getCurrencyFormatOptions=getCurrencyFormatOptions,exports2.getCurrencyOptions=getCurrencyOptions,exports2.getCurrencyType=getCurrencyType,exports2.getDateFormatOptions=getDateFormatOptions,exports2.getDecimalFromPattern=getDecimalFromPattern,exports2.getDecimalString=getDecimalString,exports2.getNumberFormatOptions=getNumberFormatOptions,exports2.getPatternPreview=getPatternPreview,exports2.getPatternPreviewIgnoreGeneral=getPatternPreviewIgnoreGeneral,exports2.getPatternType=getPatternType,exports2.isPatternEqualWithoutDecimal=isPatternEqualWithoutDecimal,exports2.isPatternHasDecimal=isPatternHasDecimal,exports2.setPatternDecimal=setPatternDecimal,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5-experimental.20250122-3362a4a",
|
|
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.5.
|
|
57
|
-
"@univerjs/engine-
|
|
58
|
-
"@univerjs/engine-
|
|
59
|
-
"@univerjs/sheets": "0.5.
|
|
56
|
+
"@univerjs/core": "0.5.5-experimental.20250122-3362a4a",
|
|
57
|
+
"@univerjs/engine-formula": "0.5.5-experimental.20250122-3362a4a",
|
|
58
|
+
"@univerjs/engine-numfmt": "0.5.5-experimental.20250122-3362a4a",
|
|
59
|
+
"@univerjs/sheets": "0.5.5-experimental.20250122-3362a4a"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"rxjs": "^7.8.1",
|
|
63
63
|
"typescript": "^5.7.2",
|
|
64
64
|
"vite": "^6.0.7",
|
|
65
65
|
"vitest": "^2.1.8",
|
|
66
|
-
"@univerjs-infra/shared": "0.5.
|
|
66
|
+
"@univerjs-infra/shared": "0.5.5"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"test": "vitest run",
|