@univerjs/sheets-numfmt 0.9.2-nightly.202507131606 → 0.9.2-nightly.202507151607
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +130 -126
- package/lib/index.js +130 -126
- package/lib/types/controllers/numfmt-cell-content.controller.d.ts +5 -5
- package/lib/types/facade/f-workbook.d.ts +4 -4
- package/lib/types/utils/pattern.d.ts +3 -3
- package/lib/umd/index.js +1 -1
- package/package.json +4 -5
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Z=Object.defineProperty;var J=(e,r,s)=>r in e?Z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var T=(e,r,s)=>J(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),m=require("@univerjs/sheets"),A=require("@univerjs/engine-numfmt"),N=require("rxjs"),X=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},U=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${U(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${U(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=m.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:g,worksheet:f}=o,i=r.values.filter(c=>!!c.pattern),b=r.values.filter(c=>!c.pattern),_=m.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:b.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],v=[];if(i.length){const c=i.reduce((d,u)=>{A.isTextFormat(u.pattern)&&d.setValue(u.row,u.col,{t:t.CellValueType.STRING});const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),Object.keys(_.values).forEach(d=>{const u=_.values[d];u.ranges=m.rangeMerge(u.ranges)}),M.push({id:m.SetNumfmtMutation.id,params:_});const p=m.factorySetNumfmtUndoMutation(e,_);v.push(...p)}if(b.length){h.ranges=m.rangeMerge(h.ranges);const c=b.reduce((d,u)=>{const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),M.push({id:m.RemoveNumfmtMutation.id,params:h},{id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const p=m.factoryRemoveNumfmtUndoMutation(e,h);v.push({id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:C.getMatrix()}},...p)}const S=t.sequenceExecute(M,s).result;return S&&a.pushUndoRedo({unitID:l,undoMutations:v,redoMutations:M}),S}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:g,subUnitId:f}=l;let i=0;o.forEach(M=>{t.Range.foreach(M.range,(v,S)=>{const c=n.getValue(g,f,v,S);if(!c){const p=l.worksheet.getCellRaw(v,S);if(!i&&p&&p.t===t.CellValueType.NUMBER&&p.v){const d=/\.(\d*)$/.exec(String(p.v));if(d){const u=d[1].length;if(!u)return;i=Math.max(i,u)}}return}const C=E(c.pattern);i=C>i?C:i})});const b=i+1,_=P(`0${b>0?".0":""}`,b),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(v,S)=>{const c=n.getValue(g,f,v,S);if(!c)h.push({row:v,col:S,pattern:_});else{const C=E(c.pattern),p=P(c.pattern,C+1);p!==c.pattern&&h.push({row:v,col:S,pattern:p})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(D),a=L[n.getCurrencySymbol()]||"$",o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=[],g=V[4].suffix(a);return o.forEach(i=>{t.Range.foreach(i.range,(b,_)=>{l.push({row:b,col:_,pattern:g,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},q={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(g=>{t.Range.foreach(g.range,(f,i)=>{a.push({row:f,col:i,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},K={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:g,subUnitId:f}=l;let i=0;o.forEach(v=>{t.Range.foreach(v.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C){const d=l.worksheet.getCellRaw(S,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const u=/\.(\d*)$/.exec(String(d.v));if(u){const y=u[1].length;if(!y)return;i=Math.max(i,y)}}return}const p=E(C.pattern);i=p>i?p:i})});const b=i-1,_=P(`0${b>0?".0":"."}`,b),h=[];return o.forEach(v=>{t.Range.foreach(v.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C)h.push({row:S,col:c,pattern:_});else{const p=E(C.pattern);h.push({row:S,col:c,pattern:P(C.pattern,p-1)})}})}),await r.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",F={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,s="en")=>{const n=t.numfmt.formatColor(e,r),a=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a}:{result:o}},k=(e,r,s)=>e==="General"?{result:String(X.stripErrorMargin(r))}:Y(e,r,s);var te=Object.getOwnPropertyDescriptor,ne=(e,r,s,n)=>{for(var a=n>1?void 0:n?te(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},I=(e,r)=>(s,n)=>r(s,n,e);const re={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,g,f){super();T(this,"_local$",new N.BehaviorSubject("en"));T(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=g,this._configService=f,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var v,S;const l=a.unitId,g=a.subUnitId;let f;const i=n;if(!i||i.v===void 0||i.v===null)return o(n);if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(f=c.n)}if(f||(f=this._numfmtService.getValue(l,g,a.row,a.col)),!f||f.pattern==="General"||i.t!==t.CellValueType.NUMBER&&m.checkCellValueType(i.v)!==t.CellValueType.NUMBER)return o(n);if((!n||n===a.rawData)&&(n={...a.rawData}),A.isTextFormat(f.pattern))return(v=this._configService.getConfig(w))!=null&&v.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...re},o(n));let b="";const _=s.getValue(a.row,a.col);if(_&&_.parameters===`${i.v}_${f.pattern}`)return o({...n,..._.result});const h=k(f.pattern,Number(i.v),this.local);if(b=h.result,!b)return o(n);const M={v:b,t:t.CellValueType.NUMBER};if(h.color){const c=(S=this._themeService.getColorFromTheme(`${h.color}.500`))!=null?S:h.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:M,parameters:`${i.v}_${f.pattern}`}),Object.assign(n,M),o(n)},priority:m.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===m.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(g=>{t.Range.foreach(g,(f,i)=>{s.realDeleteValue(f,i)})})})}else if(n.id===m.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=ne([I(0,t.IUniverInstanceService),I(1,t.Inject(m.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(m.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const se="SHEET_NUMFMT_PLUGIN";class j extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,s)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,ie=(e,r,s,n)=>{for(var a=n>1?void 0:n?oe(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},O=(e,r)=>(s,n)=>r(s,n,e),z=(e,r,s)=>ce(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=F,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},F,this._config);this._configService.setConfig(w,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[j]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[j]]),[H,K,W,q,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",se);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(m.UniverSheetsPlugin),O(1,t.Inject(t.Injector)),O(2,t.IConfigService),O(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>x.find(s=>e.includes(s)),ue=()=>x.map(e=>({label:e,value:e})),me=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>G.map(e=>({label:e.label,value:e.suffix})),de=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=G;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=q;exports.SubtractDecimalCommand=K;exports.countryCurrencyMap=L;exports.currencySymbols=x;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=E;exports.getDecimalString=U;exports.getNumberFormatOptions=de;exports.getPatternPreview=Y;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.setPatternDecimal=P;
|
|
1
|
+
"use strict";var z=Object.defineProperty;var Z=(e,r,s)=>r in e?z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var T=(e,r,s)=>Z(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),m=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],A={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},L=[{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"}],G=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},U=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),O=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${U(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${U(Number(r||0))}$1`):n).join(";"),X=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=m.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:g,worksheet:f}=o,i=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),b=m.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],p=[];if(i.length){const c=i.reduce((d,u)=>{t.isTextFormat(u.pattern)&&d.setValue(u.row,u.col,{t:t.CellValueType.STRING});const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),Object.keys(b.values).forEach(d=>{const u=b.values[d];u.ranges=m.rangeMerge(u.ranges)}),M.push({id:m.SetNumfmtMutation.id,params:b});const v=m.factorySetNumfmtUndoMutation(e,b);p.push(...v)}if(_.length){h.ranges=m.rangeMerge(h.ranges);const c=_.reduce((d,u)=>{const y=f.getCellRaw(u.row,u.col);if(y){const $=m.checkCellValueType(y.v);$!==y.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),C=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const y=f.getCellRaw(d,u);y?C.setValue(d,u,{t:y.t}):C.setValue(d,u,{t:void 0})}),M.push({id:m.RemoveNumfmtMutation.id,params:h},{id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const v=m.factoryRemoveNumfmtUndoMutation(e,h);p.push({id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:C.getMatrix()}},...v)}const S=t.sequenceExecute(M,s).result;return S&&a.pushUndoRedo({unitID:l,undoMutations:p,redoMutations:M}),S}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:g,subUnitId:f}=l;let i=0;o.forEach(M=>{t.Range.foreach(M.range,(p,S)=>{const c=n.getValue(g,f,p,S);if(!c){const v=l.worksheet.getCellRaw(p,S);if(!i&&v&&v.t===t.CellValueType.NUMBER&&v.v){const d=/\.(\d*)$/.exec(String(v.v));if(d){const u=d[1].length;if(!u)return;i=Math.max(i,u)}}return}const C=E(c.pattern);i=C>i?C:i})});const _=i+1,b=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(p,S)=>{const c=n.getValue(g,f,p,S);if(!c)h.push({row:p,col:S,pattern:b});else{const C=E(c.pattern),v=O(c.pattern,C+1);v!==c.pattern&&h.push({row:p,col:S,pattern:v})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(D),a=A[n.getCurrencySymbol()]||"$",o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=[],g=V[4].suffix(a);return o.forEach(i=>{t.Range.foreach(i.range,(_,b)=>{l.push({row:_,col:b,pattern:g,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(g=>{t.Range.foreach(g.range,(f,i)=>{a.push({row:f,col:i,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},W={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(a);if(!l)return!1;const{unitId:g,subUnitId:f}=l;let i=0;o.forEach(p=>{t.Range.foreach(p.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C){const d=l.worksheet.getCellRaw(S,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const u=/\.(\d*)$/.exec(String(d.v));if(u){const y=u[1].length;if(!y)return;i=Math.max(i,y)}}return}const v=E(C.pattern);i=v>i?v:i})});const _=i-1,b=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(p=>{t.Range.foreach(p.range,(S,c)=>{const C=n.getValue(g,f,S,c);if(!C)h.push({row:S,col:c,pattern:b});else{const v=E(C.pattern);h.push({row:S,col:c,pattern:O(C.pattern,v-1)})}})}),await r.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",F={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",q=(e,r,s="en")=>{const n=t.numfmt.formatColor(e,r),a=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a}:{result:o}},Y=(e,r,s)=>e==="General"?{result:String(J.stripErrorMargin(r))}:q(e,r,s);var ee=Object.getOwnPropertyDescriptor,te=(e,r,s,n)=>{for(var a=n>1?void 0:n?ee(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},I=(e,r)=>(s,n)=>r(s,n,e);const ne={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,g,f){super();T(this,"_locale$",new N.BehaviorSubject("en"));T(this,"locale$",this._locale$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=g,this._configService=f,this._initInterceptorCellContent()}get locale(){const s=this._locale$.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.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var p,S;const l=a.unitId,g=a.subUnitId;let f;const i=n;if(!i||i.v===void 0||i.v===null)return o(n);if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(f=c.n)}if(f||(f=this._numfmtService.getValue(l,g,a.row,a.col)),!f||f.pattern==="General"||i.t!==t.CellValueType.NUMBER&&m.checkCellValueType(i.v)!==t.CellValueType.NUMBER)return o(n);if((!n||n===a.rawData)&&(n={...a.rawData}),t.isTextFormat(f.pattern))return(p=this._configService.getConfig(w))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},o(n));let _="";const b=s.getValue(a.row,a.col);if(b&&b.parameters===`${i.v}_${f.pattern}`)return o({...n,...b.result});const h=Y(f.pattern,Number(i.v),this.locale);if(_=h.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(h.color){const c=(S=this._themeService.getColorFromTheme(`${h.color}.500`))!=null?S:h.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:M,parameters:`${i.v}_${f.pattern}`}),Object.assign(n,M),o(n)},priority:m.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===m.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(g=>{t.Range.foreach(g,(f,i)=>{s.realDeleteValue(f,i)})})})}else if(n.id===m.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._locale$.next(s)}};exports.SheetsNumfmtCellContentController=te([I(0,t.IUniverInstanceService),I(1,t.Inject(m.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(m.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const re="SHEET_NUMFMT_PLUGIN";class j extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var se=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,oe=(e,r,s)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,ce=(e,r,s,n)=>{for(var a=n>1?void 0:n?ae(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},P=(e,r)=>(s,n)=>r(s,n,e),k=(e,r,s)=>oe(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=F,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},F,this._config);this._configService.setConfig(w,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[j]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[j]]),[B,W,H,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};k(exports.UniverSheetsNumfmtPlugin,"pluginName",re);k(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ce([t.DependentOn(m.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ie=e=>x.find(s=>e.includes(s)),le=()=>x.map(e=>({label:e,value:e})),ue=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>L.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=B;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=L;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=G;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=H;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=W;exports.countryCurrencyMap=A;exports.currencySymbols=x;exports.getCurrencyFormatOptions=ue;exports.getCurrencyOptions=le;exports.getCurrencyType=ie;exports.getDateFormatOptions=me;exports.getDecimalFromPattern=E;exports.getDecimalString=U;exports.getNumberFormatOptions=fe;exports.getPatternPreview=q;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=Q;exports.isPatternHasDecimal=X;exports.setPatternDecimal=O;
|
package/lib/es/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
var ie = Object.defineProperty;
|
|
2
2
|
var le = (e, t, r) => t in e ? ie(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var
|
|
4
|
-
import { numfmt as w, CommandType as V, ICommandService as
|
|
5
|
-
import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as
|
|
6
|
-
import {
|
|
7
|
-
import { BehaviorSubject as K, merge as Ie, switchMap as Te, of as Ee, skip as xe } from "rxjs";
|
|
3
|
+
var R = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { numfmt as w, CommandType as V, ICommandService as I, IUniverInstanceService as A, IUndoRedoService as ue, isTextFormat as X, CellValueType as $, ObjectMatrix as M, sequenceExecute as me, Range as E, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as Q, Disposable as ee, LocaleType as b, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as he, Injector as ge, Plugin as Se, merge as pe, registerDependencies as ve, touchDependencies as Y } from "@univerjs/core";
|
|
5
|
+
import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as k, SetNumfmtMutation as re, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
|
|
6
|
+
import { BehaviorSubject as K, merge as Ee, switchMap as Ie, of as Te, skip as xe } from "rxjs";
|
|
8
7
|
import { stripErrorMargin as Ve } from "@univerjs/engine-formula";
|
|
9
8
|
const ne = [
|
|
10
9
|
"$",
|
|
@@ -178,20 +177,20 @@ const ne = [
|
|
|
178
177
|
], O = (e, t = 0) => {
|
|
179
178
|
var n;
|
|
180
179
|
return e && (n = w.getFormatInfo(e).maxDecimals) != null ? n : t;
|
|
181
|
-
},
|
|
180
|
+
}, Z = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), P = (e, t) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
|
|
182
181
|
/\.0*/g,
|
|
183
|
-
`${t > 0 ? "." : ""}${
|
|
182
|
+
`${t > 0 ? "." : ""}${Z(Number(t || 0))}`
|
|
184
183
|
) : /0([^0]?)|0$/.test(n) ? n.replace(
|
|
185
184
|
/0([^0]+)|0$/,
|
|
186
|
-
`0${t > 0 ? "." : ""}${
|
|
187
|
-
) : n).join(";"),
|
|
185
|
+
`0${t > 0 ? "." : ""}${Z(Number(t || 0))}$1`
|
|
186
|
+
) : n).join(";"), et = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), U = {
|
|
188
187
|
id: "sheet.command.numfmt.set.numfmt",
|
|
189
188
|
type: V.COMMAND,
|
|
190
189
|
// eslint-disable-next-line max-lines-per-function
|
|
191
190
|
handler: (e, t) => {
|
|
192
191
|
if (!t)
|
|
193
192
|
return !1;
|
|
194
|
-
const r = e.get(
|
|
193
|
+
const r = e.get(I), n = e.get(A), s = e.get(ue), o = H(n, t);
|
|
195
194
|
if (!o) return !1;
|
|
196
195
|
const { unitId: a, subUnitId: i, worksheet: f } = o, u = t.values.filter((l) => !!l.pattern), y = t.values.filter((l) => !l.pattern), _ = ye(a, i, u), g = {
|
|
197
196
|
unitId: a,
|
|
@@ -202,43 +201,43 @@ const ne = [
|
|
|
202
201
|
endColumn: l.col,
|
|
203
202
|
endRow: l.row
|
|
204
203
|
}))
|
|
205
|
-
}, C = [],
|
|
204
|
+
}, C = [], S = [];
|
|
206
205
|
if (u.length) {
|
|
207
206
|
const l = u.reduce((d, c) => {
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
211
|
-
const x = G(
|
|
212
|
-
x !==
|
|
207
|
+
X(c.pattern) && d.setValue(c.row, c.col, { t: $.STRING });
|
|
208
|
+
const v = f.getCellRaw(c.row, c.col);
|
|
209
|
+
if (v) {
|
|
210
|
+
const x = G(v.v);
|
|
211
|
+
x !== v.t && d.setValue(c.row, c.col, { t: x });
|
|
213
212
|
}
|
|
214
213
|
return d;
|
|
215
|
-
}, new
|
|
216
|
-
new
|
|
217
|
-
const
|
|
218
|
-
|
|
214
|
+
}, new M()).getMatrix(), h = new M();
|
|
215
|
+
new M(l).forValue((d, c) => {
|
|
216
|
+
const v = f.getCellRaw(d, c);
|
|
217
|
+
v ? h.setValue(d, c, { t: v.t }) : h.setValue(d, c, { t: void 0 });
|
|
219
218
|
}), Object.keys(_.values).forEach((d) => {
|
|
220
219
|
const c = _.values[d];
|
|
221
|
-
c.ranges =
|
|
220
|
+
c.ranges = k(c.ranges);
|
|
222
221
|
}), C.push({
|
|
223
|
-
id:
|
|
222
|
+
id: re.id,
|
|
224
223
|
params: _
|
|
225
224
|
});
|
|
226
|
-
const
|
|
227
|
-
|
|
225
|
+
const p = _e(e, _);
|
|
226
|
+
S.push(...p);
|
|
228
227
|
}
|
|
229
228
|
if (y.length) {
|
|
230
|
-
g.ranges =
|
|
229
|
+
g.ranges = k(g.ranges);
|
|
231
230
|
const l = y.reduce((d, c) => {
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
234
|
-
const x = G(
|
|
235
|
-
x !==
|
|
231
|
+
const v = f.getCellRaw(c.row, c.col);
|
|
232
|
+
if (v) {
|
|
233
|
+
const x = G(v.v);
|
|
234
|
+
x !== v.t && d.setValue(c.row, c.col, { t: x });
|
|
236
235
|
}
|
|
237
236
|
return d;
|
|
238
|
-
}, new
|
|
239
|
-
new
|
|
240
|
-
const
|
|
241
|
-
|
|
237
|
+
}, new M()).getMatrix(), h = new M();
|
|
238
|
+
new M(l).forValue((d, c) => {
|
|
239
|
+
const v = f.getCellRaw(d, c);
|
|
240
|
+
v ? h.setValue(d, c, { t: v.t }) : h.setValue(d, c, { t: void 0 });
|
|
242
241
|
}), C.push({
|
|
243
242
|
id: Ce.id,
|
|
244
243
|
params: g
|
|
@@ -250,20 +249,20 @@ const ne = [
|
|
|
250
249
|
cellValue: l
|
|
251
250
|
}
|
|
252
251
|
});
|
|
253
|
-
const
|
|
254
|
-
|
|
252
|
+
const p = be(e, g);
|
|
253
|
+
S.push({
|
|
255
254
|
id: B.id,
|
|
256
255
|
params: {
|
|
257
256
|
unitId: a,
|
|
258
257
|
subUnitId: i,
|
|
259
258
|
cellValue: h.getMatrix()
|
|
260
259
|
}
|
|
261
|
-
}, ...
|
|
260
|
+
}, ...p);
|
|
262
261
|
}
|
|
263
262
|
const m = me(C, r).result;
|
|
264
263
|
return m && s.pushUndoRedo({
|
|
265
264
|
unitID: a,
|
|
266
|
-
undoMutations:
|
|
265
|
+
undoMutations: S,
|
|
267
266
|
redoMutations: C
|
|
268
267
|
}), m;
|
|
269
268
|
}
|
|
@@ -271,7 +270,7 @@ const ne = [
|
|
|
271
270
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
272
271
|
type: V.COMMAND,
|
|
273
272
|
handler: async (e) => {
|
|
274
|
-
const t = e.get(
|
|
273
|
+
const t = e.get(I), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
|
|
275
274
|
if (!o || !o.length)
|
|
276
275
|
return !1;
|
|
277
276
|
const a = H(s);
|
|
@@ -279,12 +278,12 @@ const ne = [
|
|
|
279
278
|
const { unitId: i, subUnitId: f } = a;
|
|
280
279
|
let u = 0;
|
|
281
280
|
o.forEach((C) => {
|
|
282
|
-
|
|
283
|
-
const l = n.getValue(i, f,
|
|
281
|
+
E.foreach(C.range, (S, m) => {
|
|
282
|
+
const l = n.getValue(i, f, S, m);
|
|
284
283
|
if (!l) {
|
|
285
|
-
const
|
|
286
|
-
if (!u &&
|
|
287
|
-
const d = /\.(\d*)$/.exec(String(
|
|
284
|
+
const p = a.worksheet.getCellRaw(S, m);
|
|
285
|
+
if (!u && p && p.t === $.NUMBER && p.v) {
|
|
286
|
+
const d = /\.(\d*)$/.exec(String(p.v));
|
|
288
287
|
if (d) {
|
|
289
288
|
const c = d[1].length;
|
|
290
289
|
if (!c)
|
|
@@ -300,20 +299,20 @@ const ne = [
|
|
|
300
299
|
});
|
|
301
300
|
const y = u + 1, _ = P(`0${y > 0 ? ".0" : ""}`, y), g = [];
|
|
302
301
|
return o.forEach((C) => {
|
|
303
|
-
|
|
304
|
-
const l = n.getValue(i, f,
|
|
302
|
+
E.foreach(C.range, (S, m) => {
|
|
303
|
+
const l = n.getValue(i, f, S, m);
|
|
305
304
|
if (!l)
|
|
306
305
|
g.push({
|
|
307
|
-
row:
|
|
306
|
+
row: S,
|
|
308
307
|
col: m,
|
|
309
308
|
pattern: _
|
|
310
309
|
});
|
|
311
310
|
else {
|
|
312
|
-
const h = O(l.pattern),
|
|
313
|
-
|
|
314
|
-
row:
|
|
311
|
+
const h = O(l.pattern), p = P(l.pattern, h + 1);
|
|
312
|
+
p !== l.pattern && g.push({
|
|
313
|
+
row: S,
|
|
315
314
|
col: m,
|
|
316
|
-
pattern:
|
|
315
|
+
pattern: p
|
|
317
316
|
});
|
|
318
317
|
}
|
|
319
318
|
});
|
|
@@ -322,8 +321,8 @@ const ne = [
|
|
|
322
321
|
};
|
|
323
322
|
class oe {
|
|
324
323
|
constructor() {
|
|
325
|
-
|
|
326
|
-
|
|
324
|
+
R(this, "_currencySymbol$", new K("US"));
|
|
325
|
+
R(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
327
326
|
}
|
|
328
327
|
/**
|
|
329
328
|
* Set the currency symbol by setting the country code.
|
|
@@ -339,12 +338,12 @@ const De = {
|
|
|
339
338
|
id: "sheet.command.numfmt.set.currency",
|
|
340
339
|
type: V.COMMAND,
|
|
341
340
|
handler: async (e) => {
|
|
342
|
-
const t = e.get(
|
|
341
|
+
const t = e.get(I), r = e.get(j), n = e.get(oe), s = Ue[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
|
|
343
342
|
if (!o || !o.length)
|
|
344
343
|
return !1;
|
|
345
344
|
const a = [], i = se[4].suffix(s);
|
|
346
345
|
return o.forEach((u) => {
|
|
347
|
-
|
|
346
|
+
E.foreach(u.range, (y, _) => {
|
|
348
347
|
a.push({ row: y, col: _, pattern: i, type: "currency" });
|
|
349
348
|
});
|
|
350
349
|
}), await t.executeCommand(U.id, { values: a });
|
|
@@ -353,12 +352,12 @@ const De = {
|
|
|
353
352
|
id: "sheet.command.numfmt.set.percent",
|
|
354
353
|
type: V.COMMAND,
|
|
355
354
|
handler: async (e) => {
|
|
356
|
-
const t = e.get(
|
|
355
|
+
const t = e.get(I), n = e.get(j).getCurrentSelections();
|
|
357
356
|
if (!n || !n.length)
|
|
358
357
|
return !1;
|
|
359
358
|
const s = [], o = "0%";
|
|
360
359
|
return n.forEach((i) => {
|
|
361
|
-
|
|
360
|
+
E.foreach(i.range, (f, u) => {
|
|
362
361
|
s.push({ row: f, col: u, pattern: o, type: "percent" });
|
|
363
362
|
});
|
|
364
363
|
}), await t.executeCommand(U.id, { values: s });
|
|
@@ -367,36 +366,36 @@ const De = {
|
|
|
367
366
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
368
367
|
type: V.COMMAND,
|
|
369
368
|
handler: async (e) => {
|
|
370
|
-
const t = e.get(
|
|
369
|
+
const t = e.get(I), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
|
|
371
370
|
if (!o || !o.length)
|
|
372
371
|
return !1;
|
|
373
372
|
const a = H(s);
|
|
374
373
|
if (!a) return !1;
|
|
375
374
|
const { unitId: i, subUnitId: f } = a;
|
|
376
375
|
let u = 0;
|
|
377
|
-
o.forEach((
|
|
378
|
-
|
|
376
|
+
o.forEach((S) => {
|
|
377
|
+
E.foreach(S.range, (m, l) => {
|
|
379
378
|
const h = n.getValue(i, f, m, l);
|
|
380
379
|
if (!h) {
|
|
381
380
|
const d = a.worksheet.getCellRaw(m, l);
|
|
382
|
-
if (!u && d && d.t ===
|
|
381
|
+
if (!u && d && d.t === $.NUMBER && d.v) {
|
|
383
382
|
const c = /\.(\d*)$/.exec(String(d.v));
|
|
384
383
|
if (c) {
|
|
385
|
-
const
|
|
386
|
-
if (!
|
|
384
|
+
const v = c[1].length;
|
|
385
|
+
if (!v)
|
|
387
386
|
return;
|
|
388
|
-
u = Math.max(u,
|
|
387
|
+
u = Math.max(u, v);
|
|
389
388
|
}
|
|
390
389
|
}
|
|
391
390
|
return;
|
|
392
391
|
}
|
|
393
|
-
const
|
|
394
|
-
u =
|
|
392
|
+
const p = O(h.pattern);
|
|
393
|
+
u = p > u ? p : u;
|
|
395
394
|
});
|
|
396
395
|
});
|
|
397
396
|
const y = u - 1, _ = P(`0${y > 0 ? ".0" : "."}`, y), g = [];
|
|
398
|
-
return o.forEach((
|
|
399
|
-
|
|
397
|
+
return o.forEach((S) => {
|
|
398
|
+
E.foreach(S.range, (m, l) => {
|
|
400
399
|
const h = n.getValue(i, f, m, l);
|
|
401
400
|
if (!h)
|
|
402
401
|
g.push({
|
|
@@ -405,17 +404,17 @@ const De = {
|
|
|
405
404
|
pattern: _
|
|
406
405
|
});
|
|
407
406
|
else {
|
|
408
|
-
const
|
|
407
|
+
const p = O(h.pattern);
|
|
409
408
|
g.push({
|
|
410
409
|
row: m,
|
|
411
410
|
col: l,
|
|
412
|
-
pattern: P(h.pattern,
|
|
411
|
+
pattern: P(h.pattern, p - 1)
|
|
413
412
|
});
|
|
414
413
|
}
|
|
415
414
|
});
|
|
416
415
|
}), await t.executeCommand(U.id, { values: g });
|
|
417
416
|
}
|
|
418
|
-
}, ae = "sheets-numfmt.config", q = {},
|
|
417
|
+
}, ae = "sheets-numfmt.config", q = {}, tt = (e) => w.getFormatInfo(e).type || "unknown", je = (e, t, r = "en") => {
|
|
419
418
|
const n = w.formatColor(e, t), s = n ? String(n) : void 0, o = w.format(e, t, { locale: r, throws: !1 });
|
|
420
419
|
return t < 0 ? {
|
|
421
420
|
result: o,
|
|
@@ -438,44 +437,49 @@ const He = {
|
|
|
438
437
|
color: "#409f11"
|
|
439
438
|
}
|
|
440
439
|
};
|
|
441
|
-
let D = class extends
|
|
440
|
+
let D = class extends ee {
|
|
442
441
|
constructor(t, r, n, s, o, a, i) {
|
|
443
442
|
super();
|
|
444
|
-
|
|
445
|
-
|
|
443
|
+
R(this, "_locale$", new K("en"));
|
|
444
|
+
R(this, "locale$", this._locale$.asObservable());
|
|
446
445
|
this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = a, this._configService = i, this._initInterceptorCellContent();
|
|
447
446
|
}
|
|
448
|
-
get
|
|
449
|
-
const t = this.
|
|
447
|
+
get locale() {
|
|
448
|
+
const t = this._locale$.getValue();
|
|
450
449
|
if (t)
|
|
451
450
|
return t;
|
|
452
451
|
switch (this._localeService.getCurrentLocale()) {
|
|
453
|
-
case
|
|
452
|
+
case b.FR_FR:
|
|
454
453
|
return "fr";
|
|
455
|
-
case
|
|
454
|
+
case b.RU_RU:
|
|
456
455
|
return "ru";
|
|
457
|
-
case
|
|
456
|
+
case b.VI_VN:
|
|
458
457
|
return "vi";
|
|
459
|
-
case
|
|
458
|
+
case b.ZH_CN:
|
|
460
459
|
return "zh-CN";
|
|
461
|
-
case
|
|
460
|
+
case b.KO_KR:
|
|
461
|
+
return "ko";
|
|
462
|
+
case b.ZH_TW:
|
|
462
463
|
return "zh-TW";
|
|
463
|
-
case
|
|
464
|
-
case
|
|
464
|
+
case b.ES_ES:
|
|
465
|
+
case b.CA_ES:
|
|
466
|
+
return "es";
|
|
467
|
+
case b.EN_US:
|
|
468
|
+
case b.FA_IR:
|
|
465
469
|
default:
|
|
466
470
|
return "en";
|
|
467
471
|
}
|
|
468
472
|
}
|
|
469
473
|
// eslint-disable-next-line max-lines-per-function
|
|
470
474
|
_initInterceptorCellContent() {
|
|
471
|
-
const t = new
|
|
472
|
-
this.disposeWithMe(
|
|
475
|
+
const t = new M();
|
|
476
|
+
this.disposeWithMe(Ee(this._locale$, this._localeService.currentLocale$).subscribe(() => {
|
|
473
477
|
t.reset();
|
|
474
478
|
})), this.disposeWithMe(this._sheetInterceptorService.intercept($e.CELL_CONTENT, {
|
|
475
479
|
effect: z.Value | z.Style,
|
|
476
480
|
// eslint-disable-next-line complexity
|
|
477
481
|
handler: (r, n, s) => {
|
|
478
|
-
var C,
|
|
482
|
+
var C, S;
|
|
479
483
|
const o = n.unitId, a = n.subUnitId;
|
|
480
484
|
let i;
|
|
481
485
|
const f = r;
|
|
@@ -485,20 +489,20 @@ let D = class extends Q {
|
|
|
485
489
|
const m = n.workbook.getStyles().get(r.s);
|
|
486
490
|
m != null && m.n && (i = m.n);
|
|
487
491
|
}
|
|
488
|
-
if (i || (i = this._numfmtService.getValue(o, a, n.row, n.col)), !i || i.pattern === "General" || f.t !==
|
|
492
|
+
if (i || (i = this._numfmtService.getValue(o, a, n.row, n.col)), !i || i.pattern === "General" || f.t !== $.NUMBER && G(f.v) !== $.NUMBER)
|
|
489
493
|
return s(r);
|
|
490
|
-
if ((!r || r === n.rawData) && (r = { ...n.rawData }),
|
|
491
|
-
return (C = this._configService.getConfig(ae)) != null && C.disableTextFormatMark ? (r.t =
|
|
494
|
+
if ((!r || r === n.rawData) && (r = { ...n.rawData }), X(i.pattern))
|
|
495
|
+
return (C = this._configService.getConfig(ae)) != null && C.disableTextFormatMark ? (r.t = $.STRING, s(r)) : (r.t = $.STRING, r.markers = { ...r == null ? void 0 : r.markers, ...He }, s(r));
|
|
492
496
|
let u = "";
|
|
493
497
|
const y = t.getValue(n.row, n.col);
|
|
494
498
|
if (y && y.parameters === `${f.v}_${i.pattern}`)
|
|
495
499
|
return s({ ...r, ...y.result });
|
|
496
|
-
const _ = Le(i.pattern, Number(f.v), this.
|
|
500
|
+
const _ = Le(i.pattern, Number(f.v), this.locale);
|
|
497
501
|
if (u = _.result, !u)
|
|
498
502
|
return s(r);
|
|
499
|
-
const g = { v: u, t:
|
|
503
|
+
const g = { v: u, t: $.NUMBER };
|
|
500
504
|
if (_.color) {
|
|
501
|
-
const m = (
|
|
505
|
+
const m = (S = this._themeService.getColorFromTheme(`${_.color}.500`)) != null ? S : _.color;
|
|
502
506
|
m && (g.interceptorStyle = { cl: { rgb: m } });
|
|
503
507
|
}
|
|
504
508
|
return t.setValue(n.row, n.col, {
|
|
@@ -508,50 +512,50 @@ let D = class extends Q {
|
|
|
508
512
|
},
|
|
509
513
|
priority: Re.NUMFMT
|
|
510
514
|
})), this.disposeWithMe(this._commandService.onCommandExecuted((r) => {
|
|
511
|
-
if (r.id ===
|
|
515
|
+
if (r.id === re.id) {
|
|
512
516
|
const n = r.params;
|
|
513
517
|
Object.keys(n.values).forEach((s) => {
|
|
514
518
|
n.values[s].ranges.forEach((a) => {
|
|
515
|
-
|
|
519
|
+
E.foreach(a, (i, f) => {
|
|
516
520
|
t.realDeleteValue(i, f);
|
|
517
521
|
});
|
|
518
522
|
});
|
|
519
523
|
});
|
|
520
524
|
} else if (r.id === B.id) {
|
|
521
525
|
const n = r.params;
|
|
522
|
-
new
|
|
526
|
+
new M(n.cellValue).forValue((s, o) => {
|
|
523
527
|
t.realDeleteValue(s, o);
|
|
524
528
|
});
|
|
525
529
|
}
|
|
526
530
|
})), this.disposeWithMe(
|
|
527
|
-
this._instanceService.getCurrentTypeOfUnit$(
|
|
528
|
-
|
|
531
|
+
this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
|
|
532
|
+
Ie((r) => {
|
|
529
533
|
var n;
|
|
530
|
-
return (n = r == null ? void 0 : r.activeSheet$) != null ? n :
|
|
534
|
+
return (n = r == null ? void 0 : r.activeSheet$) != null ? n : Te(null);
|
|
531
535
|
}),
|
|
532
536
|
xe(1)
|
|
533
537
|
).subscribe(() => t.reset())
|
|
534
538
|
);
|
|
535
539
|
}
|
|
536
540
|
setNumfmtLocal(t) {
|
|
537
|
-
this.
|
|
541
|
+
this._locale$.next(t);
|
|
538
542
|
}
|
|
539
543
|
};
|
|
540
544
|
D = Be([
|
|
541
545
|
N(0, A),
|
|
542
|
-
N(1,
|
|
543
|
-
N(2,
|
|
544
|
-
N(3,
|
|
545
|
-
N(4,
|
|
546
|
-
N(5,
|
|
547
|
-
N(6,
|
|
546
|
+
N(1, T(Me)),
|
|
547
|
+
N(2, T(fe)),
|
|
548
|
+
N(3, T(I)),
|
|
549
|
+
N(4, T(W)),
|
|
550
|
+
N(5, T(de)),
|
|
551
|
+
N(6, Q)
|
|
548
552
|
], D);
|
|
549
553
|
const We = "SHEET_NUMFMT_PLUGIN";
|
|
550
|
-
class J extends
|
|
554
|
+
class J extends ee {
|
|
551
555
|
constructor() {
|
|
552
556
|
super(...arguments);
|
|
553
|
-
|
|
554
|
-
|
|
557
|
+
R(this, "_currencySymbol$", new K("US"));
|
|
558
|
+
R(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
555
559
|
}
|
|
556
560
|
/**
|
|
557
561
|
* Set the currency symbol by setting the country code.
|
|
@@ -563,15 +567,15 @@ class J extends Q {
|
|
|
563
567
|
return this._currencySymbol$.getValue();
|
|
564
568
|
}
|
|
565
569
|
}
|
|
566
|
-
var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t, r) => t in e ? Ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r,
|
|
570
|
+
var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t, r) => t in e ? Ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, ke = (e, t, r, n) => {
|
|
567
571
|
for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, o = e.length - 1, a; o >= 0; o--)
|
|
568
572
|
(a = e[o]) && (s = a(s) || s);
|
|
569
573
|
return s;
|
|
570
574
|
}, L = (e, t) => (r, n) => t(r, n, e), ce = (e, t, r) => Ye(e, typeof t != "symbol" ? t + "" : t, r);
|
|
571
|
-
let F = class extends
|
|
575
|
+
let F = class extends Se {
|
|
572
576
|
constructor(e = q, t, r, n) {
|
|
573
577
|
super(), this._config = e, this._injector = t, this._configService = r, this._commandService = n;
|
|
574
|
-
const { ...s } =
|
|
578
|
+
const { ...s } = pe(
|
|
575
579
|
{},
|
|
576
580
|
q,
|
|
577
581
|
this._config
|
|
@@ -579,7 +583,7 @@ let F = class extends pe {
|
|
|
579
583
|
this._configService.setConfig(ae, s);
|
|
580
584
|
}
|
|
581
585
|
onStarting() {
|
|
582
|
-
|
|
586
|
+
ve(this._injector, [
|
|
583
587
|
[D],
|
|
584
588
|
[oe],
|
|
585
589
|
[J]
|
|
@@ -602,18 +606,18 @@ let F = class extends pe {
|
|
|
602
606
|
}
|
|
603
607
|
};
|
|
604
608
|
ce(F, "pluginName", We);
|
|
605
|
-
ce(F, "type",
|
|
606
|
-
F =
|
|
609
|
+
ce(F, "type", te.UNIVER_SHEET);
|
|
610
|
+
F = ke([
|
|
607
611
|
he(Ne),
|
|
608
|
-
L(1,
|
|
609
|
-
L(2,
|
|
610
|
-
L(3,
|
|
612
|
+
L(1, T(ge)),
|
|
613
|
+
L(2, Q),
|
|
614
|
+
L(3, I)
|
|
611
615
|
], F);
|
|
612
|
-
const
|
|
616
|
+
const rt = (e) => ne.find((r) => e.includes(r)), nt = () => ne.map((e) => ({ label: e, value: e })), st = (e) => se.map((t) => ({
|
|
613
617
|
label: t.label(e),
|
|
614
618
|
value: t.suffix(e),
|
|
615
619
|
color: t.color
|
|
616
|
-
})),
|
|
620
|
+
})), ot = () => we.map((e) => ({ label: e.label, value: e.suffix })), at = () => Oe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
617
621
|
export {
|
|
618
622
|
Pe as AddDecimalCommand,
|
|
619
623
|
se as CURRENCYFORMAT,
|
|
@@ -629,16 +633,16 @@ export {
|
|
|
629
633
|
F as UniverSheetsNumfmtPlugin,
|
|
630
634
|
Ue as countryCurrencyMap,
|
|
631
635
|
ne as currencySymbols,
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
+
st as getCurrencyFormatOptions,
|
|
637
|
+
nt as getCurrencyOptions,
|
|
638
|
+
rt as getCurrencyType,
|
|
639
|
+
ot as getDateFormatOptions,
|
|
636
640
|
O as getDecimalFromPattern,
|
|
637
|
-
|
|
638
|
-
|
|
641
|
+
Z as getDecimalString,
|
|
642
|
+
at as getNumberFormatOptions,
|
|
639
643
|
je as getPatternPreview,
|
|
640
644
|
Le as getPatternPreviewIgnoreGeneral,
|
|
641
|
-
|
|
642
|
-
|
|
645
|
+
tt as getPatternType,
|
|
646
|
+
et as isPatternHasDecimal,
|
|
643
647
|
P as setPatternDecimal
|
|
644
648
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
var ie = Object.defineProperty;
|
|
2
2
|
var le = (e, t, r) => t in e ? ie(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var
|
|
4
|
-
import { numfmt as w, CommandType as V, ICommandService as
|
|
5
|
-
import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as
|
|
6
|
-
import {
|
|
7
|
-
import { BehaviorSubject as K, merge as Ie, switchMap as Te, of as Ee, skip as xe } from "rxjs";
|
|
3
|
+
var R = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { numfmt as w, CommandType as V, ICommandService as I, IUniverInstanceService as A, IUndoRedoService as ue, isTextFormat as X, CellValueType as $, ObjectMatrix as M, sequenceExecute as me, Range as E, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as Q, Disposable as ee, LocaleType as b, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as he, Injector as ge, Plugin as Se, merge as pe, registerDependencies as ve, touchDependencies as Y } from "@univerjs/core";
|
|
5
|
+
import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as k, SetNumfmtMutation as re, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
|
|
6
|
+
import { BehaviorSubject as K, merge as Ee, switchMap as Ie, of as Te, skip as xe } from "rxjs";
|
|
8
7
|
import { stripErrorMargin as Ve } from "@univerjs/engine-formula";
|
|
9
8
|
const ne = [
|
|
10
9
|
"$",
|
|
@@ -178,20 +177,20 @@ const ne = [
|
|
|
178
177
|
], O = (e, t = 0) => {
|
|
179
178
|
var n;
|
|
180
179
|
return e && (n = w.getFormatInfo(e).maxDecimals) != null ? n : t;
|
|
181
|
-
},
|
|
180
|
+
}, Z = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), P = (e, t) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
|
|
182
181
|
/\.0*/g,
|
|
183
|
-
`${t > 0 ? "." : ""}${
|
|
182
|
+
`${t > 0 ? "." : ""}${Z(Number(t || 0))}`
|
|
184
183
|
) : /0([^0]?)|0$/.test(n) ? n.replace(
|
|
185
184
|
/0([^0]+)|0$/,
|
|
186
|
-
`0${t > 0 ? "." : ""}${
|
|
187
|
-
) : n).join(";"),
|
|
185
|
+
`0${t > 0 ? "." : ""}${Z(Number(t || 0))}$1`
|
|
186
|
+
) : n).join(";"), et = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), U = {
|
|
188
187
|
id: "sheet.command.numfmt.set.numfmt",
|
|
189
188
|
type: V.COMMAND,
|
|
190
189
|
// eslint-disable-next-line max-lines-per-function
|
|
191
190
|
handler: (e, t) => {
|
|
192
191
|
if (!t)
|
|
193
192
|
return !1;
|
|
194
|
-
const r = e.get(
|
|
193
|
+
const r = e.get(I), n = e.get(A), s = e.get(ue), o = H(n, t);
|
|
195
194
|
if (!o) return !1;
|
|
196
195
|
const { unitId: a, subUnitId: i, worksheet: f } = o, u = t.values.filter((l) => !!l.pattern), y = t.values.filter((l) => !l.pattern), _ = ye(a, i, u), g = {
|
|
197
196
|
unitId: a,
|
|
@@ -202,43 +201,43 @@ const ne = [
|
|
|
202
201
|
endColumn: l.col,
|
|
203
202
|
endRow: l.row
|
|
204
203
|
}))
|
|
205
|
-
}, C = [],
|
|
204
|
+
}, C = [], S = [];
|
|
206
205
|
if (u.length) {
|
|
207
206
|
const l = u.reduce((d, c) => {
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
211
|
-
const x = G(
|
|
212
|
-
x !==
|
|
207
|
+
X(c.pattern) && d.setValue(c.row, c.col, { t: $.STRING });
|
|
208
|
+
const v = f.getCellRaw(c.row, c.col);
|
|
209
|
+
if (v) {
|
|
210
|
+
const x = G(v.v);
|
|
211
|
+
x !== v.t && d.setValue(c.row, c.col, { t: x });
|
|
213
212
|
}
|
|
214
213
|
return d;
|
|
215
|
-
}, new
|
|
216
|
-
new
|
|
217
|
-
const
|
|
218
|
-
|
|
214
|
+
}, new M()).getMatrix(), h = new M();
|
|
215
|
+
new M(l).forValue((d, c) => {
|
|
216
|
+
const v = f.getCellRaw(d, c);
|
|
217
|
+
v ? h.setValue(d, c, { t: v.t }) : h.setValue(d, c, { t: void 0 });
|
|
219
218
|
}), Object.keys(_.values).forEach((d) => {
|
|
220
219
|
const c = _.values[d];
|
|
221
|
-
c.ranges =
|
|
220
|
+
c.ranges = k(c.ranges);
|
|
222
221
|
}), C.push({
|
|
223
|
-
id:
|
|
222
|
+
id: re.id,
|
|
224
223
|
params: _
|
|
225
224
|
});
|
|
226
|
-
const
|
|
227
|
-
|
|
225
|
+
const p = _e(e, _);
|
|
226
|
+
S.push(...p);
|
|
228
227
|
}
|
|
229
228
|
if (y.length) {
|
|
230
|
-
g.ranges =
|
|
229
|
+
g.ranges = k(g.ranges);
|
|
231
230
|
const l = y.reduce((d, c) => {
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
234
|
-
const x = G(
|
|
235
|
-
x !==
|
|
231
|
+
const v = f.getCellRaw(c.row, c.col);
|
|
232
|
+
if (v) {
|
|
233
|
+
const x = G(v.v);
|
|
234
|
+
x !== v.t && d.setValue(c.row, c.col, { t: x });
|
|
236
235
|
}
|
|
237
236
|
return d;
|
|
238
|
-
}, new
|
|
239
|
-
new
|
|
240
|
-
const
|
|
241
|
-
|
|
237
|
+
}, new M()).getMatrix(), h = new M();
|
|
238
|
+
new M(l).forValue((d, c) => {
|
|
239
|
+
const v = f.getCellRaw(d, c);
|
|
240
|
+
v ? h.setValue(d, c, { t: v.t }) : h.setValue(d, c, { t: void 0 });
|
|
242
241
|
}), C.push({
|
|
243
242
|
id: Ce.id,
|
|
244
243
|
params: g
|
|
@@ -250,20 +249,20 @@ const ne = [
|
|
|
250
249
|
cellValue: l
|
|
251
250
|
}
|
|
252
251
|
});
|
|
253
|
-
const
|
|
254
|
-
|
|
252
|
+
const p = be(e, g);
|
|
253
|
+
S.push({
|
|
255
254
|
id: B.id,
|
|
256
255
|
params: {
|
|
257
256
|
unitId: a,
|
|
258
257
|
subUnitId: i,
|
|
259
258
|
cellValue: h.getMatrix()
|
|
260
259
|
}
|
|
261
|
-
}, ...
|
|
260
|
+
}, ...p);
|
|
262
261
|
}
|
|
263
262
|
const m = me(C, r).result;
|
|
264
263
|
return m && s.pushUndoRedo({
|
|
265
264
|
unitID: a,
|
|
266
|
-
undoMutations:
|
|
265
|
+
undoMutations: S,
|
|
267
266
|
redoMutations: C
|
|
268
267
|
}), m;
|
|
269
268
|
}
|
|
@@ -271,7 +270,7 @@ const ne = [
|
|
|
271
270
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
272
271
|
type: V.COMMAND,
|
|
273
272
|
handler: async (e) => {
|
|
274
|
-
const t = e.get(
|
|
273
|
+
const t = e.get(I), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
|
|
275
274
|
if (!o || !o.length)
|
|
276
275
|
return !1;
|
|
277
276
|
const a = H(s);
|
|
@@ -279,12 +278,12 @@ const ne = [
|
|
|
279
278
|
const { unitId: i, subUnitId: f } = a;
|
|
280
279
|
let u = 0;
|
|
281
280
|
o.forEach((C) => {
|
|
282
|
-
|
|
283
|
-
const l = n.getValue(i, f,
|
|
281
|
+
E.foreach(C.range, (S, m) => {
|
|
282
|
+
const l = n.getValue(i, f, S, m);
|
|
284
283
|
if (!l) {
|
|
285
|
-
const
|
|
286
|
-
if (!u &&
|
|
287
|
-
const d = /\.(\d*)$/.exec(String(
|
|
284
|
+
const p = a.worksheet.getCellRaw(S, m);
|
|
285
|
+
if (!u && p && p.t === $.NUMBER && p.v) {
|
|
286
|
+
const d = /\.(\d*)$/.exec(String(p.v));
|
|
288
287
|
if (d) {
|
|
289
288
|
const c = d[1].length;
|
|
290
289
|
if (!c)
|
|
@@ -300,20 +299,20 @@ const ne = [
|
|
|
300
299
|
});
|
|
301
300
|
const y = u + 1, _ = P(`0${y > 0 ? ".0" : ""}`, y), g = [];
|
|
302
301
|
return o.forEach((C) => {
|
|
303
|
-
|
|
304
|
-
const l = n.getValue(i, f,
|
|
302
|
+
E.foreach(C.range, (S, m) => {
|
|
303
|
+
const l = n.getValue(i, f, S, m);
|
|
305
304
|
if (!l)
|
|
306
305
|
g.push({
|
|
307
|
-
row:
|
|
306
|
+
row: S,
|
|
308
307
|
col: m,
|
|
309
308
|
pattern: _
|
|
310
309
|
});
|
|
311
310
|
else {
|
|
312
|
-
const h = O(l.pattern),
|
|
313
|
-
|
|
314
|
-
row:
|
|
311
|
+
const h = O(l.pattern), p = P(l.pattern, h + 1);
|
|
312
|
+
p !== l.pattern && g.push({
|
|
313
|
+
row: S,
|
|
315
314
|
col: m,
|
|
316
|
-
pattern:
|
|
315
|
+
pattern: p
|
|
317
316
|
});
|
|
318
317
|
}
|
|
319
318
|
});
|
|
@@ -322,8 +321,8 @@ const ne = [
|
|
|
322
321
|
};
|
|
323
322
|
class oe {
|
|
324
323
|
constructor() {
|
|
325
|
-
|
|
326
|
-
|
|
324
|
+
R(this, "_currencySymbol$", new K("US"));
|
|
325
|
+
R(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
327
326
|
}
|
|
328
327
|
/**
|
|
329
328
|
* Set the currency symbol by setting the country code.
|
|
@@ -339,12 +338,12 @@ const De = {
|
|
|
339
338
|
id: "sheet.command.numfmt.set.currency",
|
|
340
339
|
type: V.COMMAND,
|
|
341
340
|
handler: async (e) => {
|
|
342
|
-
const t = e.get(
|
|
341
|
+
const t = e.get(I), r = e.get(j), n = e.get(oe), s = Ue[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
|
|
343
342
|
if (!o || !o.length)
|
|
344
343
|
return !1;
|
|
345
344
|
const a = [], i = se[4].suffix(s);
|
|
346
345
|
return o.forEach((u) => {
|
|
347
|
-
|
|
346
|
+
E.foreach(u.range, (y, _) => {
|
|
348
347
|
a.push({ row: y, col: _, pattern: i, type: "currency" });
|
|
349
348
|
});
|
|
350
349
|
}), await t.executeCommand(U.id, { values: a });
|
|
@@ -353,12 +352,12 @@ const De = {
|
|
|
353
352
|
id: "sheet.command.numfmt.set.percent",
|
|
354
353
|
type: V.COMMAND,
|
|
355
354
|
handler: async (e) => {
|
|
356
|
-
const t = e.get(
|
|
355
|
+
const t = e.get(I), n = e.get(j).getCurrentSelections();
|
|
357
356
|
if (!n || !n.length)
|
|
358
357
|
return !1;
|
|
359
358
|
const s = [], o = "0%";
|
|
360
359
|
return n.forEach((i) => {
|
|
361
|
-
|
|
360
|
+
E.foreach(i.range, (f, u) => {
|
|
362
361
|
s.push({ row: f, col: u, pattern: o, type: "percent" });
|
|
363
362
|
});
|
|
364
363
|
}), await t.executeCommand(U.id, { values: s });
|
|
@@ -367,36 +366,36 @@ const De = {
|
|
|
367
366
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
368
367
|
type: V.COMMAND,
|
|
369
368
|
handler: async (e) => {
|
|
370
|
-
const t = e.get(
|
|
369
|
+
const t = e.get(I), r = e.get(j), n = e.get(W), s = e.get(A), o = r.getCurrentSelections();
|
|
371
370
|
if (!o || !o.length)
|
|
372
371
|
return !1;
|
|
373
372
|
const a = H(s);
|
|
374
373
|
if (!a) return !1;
|
|
375
374
|
const { unitId: i, subUnitId: f } = a;
|
|
376
375
|
let u = 0;
|
|
377
|
-
o.forEach((
|
|
378
|
-
|
|
376
|
+
o.forEach((S) => {
|
|
377
|
+
E.foreach(S.range, (m, l) => {
|
|
379
378
|
const h = n.getValue(i, f, m, l);
|
|
380
379
|
if (!h) {
|
|
381
380
|
const d = a.worksheet.getCellRaw(m, l);
|
|
382
|
-
if (!u && d && d.t ===
|
|
381
|
+
if (!u && d && d.t === $.NUMBER && d.v) {
|
|
383
382
|
const c = /\.(\d*)$/.exec(String(d.v));
|
|
384
383
|
if (c) {
|
|
385
|
-
const
|
|
386
|
-
if (!
|
|
384
|
+
const v = c[1].length;
|
|
385
|
+
if (!v)
|
|
387
386
|
return;
|
|
388
|
-
u = Math.max(u,
|
|
387
|
+
u = Math.max(u, v);
|
|
389
388
|
}
|
|
390
389
|
}
|
|
391
390
|
return;
|
|
392
391
|
}
|
|
393
|
-
const
|
|
394
|
-
u =
|
|
392
|
+
const p = O(h.pattern);
|
|
393
|
+
u = p > u ? p : u;
|
|
395
394
|
});
|
|
396
395
|
});
|
|
397
396
|
const y = u - 1, _ = P(`0${y > 0 ? ".0" : "."}`, y), g = [];
|
|
398
|
-
return o.forEach((
|
|
399
|
-
|
|
397
|
+
return o.forEach((S) => {
|
|
398
|
+
E.foreach(S.range, (m, l) => {
|
|
400
399
|
const h = n.getValue(i, f, m, l);
|
|
401
400
|
if (!h)
|
|
402
401
|
g.push({
|
|
@@ -405,17 +404,17 @@ const De = {
|
|
|
405
404
|
pattern: _
|
|
406
405
|
});
|
|
407
406
|
else {
|
|
408
|
-
const
|
|
407
|
+
const p = O(h.pattern);
|
|
409
408
|
g.push({
|
|
410
409
|
row: m,
|
|
411
410
|
col: l,
|
|
412
|
-
pattern: P(h.pattern,
|
|
411
|
+
pattern: P(h.pattern, p - 1)
|
|
413
412
|
});
|
|
414
413
|
}
|
|
415
414
|
});
|
|
416
415
|
}), await t.executeCommand(U.id, { values: g });
|
|
417
416
|
}
|
|
418
|
-
}, ae = "sheets-numfmt.config", q = {},
|
|
417
|
+
}, ae = "sheets-numfmt.config", q = {}, tt = (e) => w.getFormatInfo(e).type || "unknown", je = (e, t, r = "en") => {
|
|
419
418
|
const n = w.formatColor(e, t), s = n ? String(n) : void 0, o = w.format(e, t, { locale: r, throws: !1 });
|
|
420
419
|
return t < 0 ? {
|
|
421
420
|
result: o,
|
|
@@ -438,44 +437,49 @@ const He = {
|
|
|
438
437
|
color: "#409f11"
|
|
439
438
|
}
|
|
440
439
|
};
|
|
441
|
-
let D = class extends
|
|
440
|
+
let D = class extends ee {
|
|
442
441
|
constructor(t, r, n, s, o, a, i) {
|
|
443
442
|
super();
|
|
444
|
-
|
|
445
|
-
|
|
443
|
+
R(this, "_locale$", new K("en"));
|
|
444
|
+
R(this, "locale$", this._locale$.asObservable());
|
|
446
445
|
this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = a, this._configService = i, this._initInterceptorCellContent();
|
|
447
446
|
}
|
|
448
|
-
get
|
|
449
|
-
const t = this.
|
|
447
|
+
get locale() {
|
|
448
|
+
const t = this._locale$.getValue();
|
|
450
449
|
if (t)
|
|
451
450
|
return t;
|
|
452
451
|
switch (this._localeService.getCurrentLocale()) {
|
|
453
|
-
case
|
|
452
|
+
case b.FR_FR:
|
|
454
453
|
return "fr";
|
|
455
|
-
case
|
|
454
|
+
case b.RU_RU:
|
|
456
455
|
return "ru";
|
|
457
|
-
case
|
|
456
|
+
case b.VI_VN:
|
|
458
457
|
return "vi";
|
|
459
|
-
case
|
|
458
|
+
case b.ZH_CN:
|
|
460
459
|
return "zh-CN";
|
|
461
|
-
case
|
|
460
|
+
case b.KO_KR:
|
|
461
|
+
return "ko";
|
|
462
|
+
case b.ZH_TW:
|
|
462
463
|
return "zh-TW";
|
|
463
|
-
case
|
|
464
|
-
case
|
|
464
|
+
case b.ES_ES:
|
|
465
|
+
case b.CA_ES:
|
|
466
|
+
return "es";
|
|
467
|
+
case b.EN_US:
|
|
468
|
+
case b.FA_IR:
|
|
465
469
|
default:
|
|
466
470
|
return "en";
|
|
467
471
|
}
|
|
468
472
|
}
|
|
469
473
|
// eslint-disable-next-line max-lines-per-function
|
|
470
474
|
_initInterceptorCellContent() {
|
|
471
|
-
const t = new
|
|
472
|
-
this.disposeWithMe(
|
|
475
|
+
const t = new M();
|
|
476
|
+
this.disposeWithMe(Ee(this._locale$, this._localeService.currentLocale$).subscribe(() => {
|
|
473
477
|
t.reset();
|
|
474
478
|
})), this.disposeWithMe(this._sheetInterceptorService.intercept($e.CELL_CONTENT, {
|
|
475
479
|
effect: z.Value | z.Style,
|
|
476
480
|
// eslint-disable-next-line complexity
|
|
477
481
|
handler: (r, n, s) => {
|
|
478
|
-
var C,
|
|
482
|
+
var C, S;
|
|
479
483
|
const o = n.unitId, a = n.subUnitId;
|
|
480
484
|
let i;
|
|
481
485
|
const f = r;
|
|
@@ -485,20 +489,20 @@ let D = class extends Q {
|
|
|
485
489
|
const m = n.workbook.getStyles().get(r.s);
|
|
486
490
|
m != null && m.n && (i = m.n);
|
|
487
491
|
}
|
|
488
|
-
if (i || (i = this._numfmtService.getValue(o, a, n.row, n.col)), !i || i.pattern === "General" || f.t !==
|
|
492
|
+
if (i || (i = this._numfmtService.getValue(o, a, n.row, n.col)), !i || i.pattern === "General" || f.t !== $.NUMBER && G(f.v) !== $.NUMBER)
|
|
489
493
|
return s(r);
|
|
490
|
-
if ((!r || r === n.rawData) && (r = { ...n.rawData }),
|
|
491
|
-
return (C = this._configService.getConfig(ae)) != null && C.disableTextFormatMark ? (r.t =
|
|
494
|
+
if ((!r || r === n.rawData) && (r = { ...n.rawData }), X(i.pattern))
|
|
495
|
+
return (C = this._configService.getConfig(ae)) != null && C.disableTextFormatMark ? (r.t = $.STRING, s(r)) : (r.t = $.STRING, r.markers = { ...r == null ? void 0 : r.markers, ...He }, s(r));
|
|
492
496
|
let u = "";
|
|
493
497
|
const y = t.getValue(n.row, n.col);
|
|
494
498
|
if (y && y.parameters === `${f.v}_${i.pattern}`)
|
|
495
499
|
return s({ ...r, ...y.result });
|
|
496
|
-
const _ = Le(i.pattern, Number(f.v), this.
|
|
500
|
+
const _ = Le(i.pattern, Number(f.v), this.locale);
|
|
497
501
|
if (u = _.result, !u)
|
|
498
502
|
return s(r);
|
|
499
|
-
const g = { v: u, t:
|
|
503
|
+
const g = { v: u, t: $.NUMBER };
|
|
500
504
|
if (_.color) {
|
|
501
|
-
const m = (
|
|
505
|
+
const m = (S = this._themeService.getColorFromTheme(`${_.color}.500`)) != null ? S : _.color;
|
|
502
506
|
m && (g.interceptorStyle = { cl: { rgb: m } });
|
|
503
507
|
}
|
|
504
508
|
return t.setValue(n.row, n.col, {
|
|
@@ -508,50 +512,50 @@ let D = class extends Q {
|
|
|
508
512
|
},
|
|
509
513
|
priority: Re.NUMFMT
|
|
510
514
|
})), this.disposeWithMe(this._commandService.onCommandExecuted((r) => {
|
|
511
|
-
if (r.id ===
|
|
515
|
+
if (r.id === re.id) {
|
|
512
516
|
const n = r.params;
|
|
513
517
|
Object.keys(n.values).forEach((s) => {
|
|
514
518
|
n.values[s].ranges.forEach((a) => {
|
|
515
|
-
|
|
519
|
+
E.foreach(a, (i, f) => {
|
|
516
520
|
t.realDeleteValue(i, f);
|
|
517
521
|
});
|
|
518
522
|
});
|
|
519
523
|
});
|
|
520
524
|
} else if (r.id === B.id) {
|
|
521
525
|
const n = r.params;
|
|
522
|
-
new
|
|
526
|
+
new M(n.cellValue).forValue((s, o) => {
|
|
523
527
|
t.realDeleteValue(s, o);
|
|
524
528
|
});
|
|
525
529
|
}
|
|
526
530
|
})), this.disposeWithMe(
|
|
527
|
-
this._instanceService.getCurrentTypeOfUnit$(
|
|
528
|
-
|
|
531
|
+
this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
|
|
532
|
+
Ie((r) => {
|
|
529
533
|
var n;
|
|
530
|
-
return (n = r == null ? void 0 : r.activeSheet$) != null ? n :
|
|
534
|
+
return (n = r == null ? void 0 : r.activeSheet$) != null ? n : Te(null);
|
|
531
535
|
}),
|
|
532
536
|
xe(1)
|
|
533
537
|
).subscribe(() => t.reset())
|
|
534
538
|
);
|
|
535
539
|
}
|
|
536
540
|
setNumfmtLocal(t) {
|
|
537
|
-
this.
|
|
541
|
+
this._locale$.next(t);
|
|
538
542
|
}
|
|
539
543
|
};
|
|
540
544
|
D = Be([
|
|
541
545
|
N(0, A),
|
|
542
|
-
N(1,
|
|
543
|
-
N(2,
|
|
544
|
-
N(3,
|
|
545
|
-
N(4,
|
|
546
|
-
N(5,
|
|
547
|
-
N(6,
|
|
546
|
+
N(1, T(Me)),
|
|
547
|
+
N(2, T(fe)),
|
|
548
|
+
N(3, T(I)),
|
|
549
|
+
N(4, T(W)),
|
|
550
|
+
N(5, T(de)),
|
|
551
|
+
N(6, Q)
|
|
548
552
|
], D);
|
|
549
553
|
const We = "SHEET_NUMFMT_PLUGIN";
|
|
550
|
-
class J extends
|
|
554
|
+
class J extends ee {
|
|
551
555
|
constructor() {
|
|
552
556
|
super(...arguments);
|
|
553
|
-
|
|
554
|
-
|
|
557
|
+
R(this, "_currencySymbol$", new K("US"));
|
|
558
|
+
R(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
555
559
|
}
|
|
556
560
|
/**
|
|
557
561
|
* Set the currency symbol by setting the country code.
|
|
@@ -563,15 +567,15 @@ class J extends Q {
|
|
|
563
567
|
return this._currencySymbol$.getValue();
|
|
564
568
|
}
|
|
565
569
|
}
|
|
566
|
-
var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t, r) => t in e ? Ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r,
|
|
570
|
+
var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, Ye = (e, t, r) => t in e ? Ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, ke = (e, t, r, n) => {
|
|
567
571
|
for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, o = e.length - 1, a; o >= 0; o--)
|
|
568
572
|
(a = e[o]) && (s = a(s) || s);
|
|
569
573
|
return s;
|
|
570
574
|
}, L = (e, t) => (r, n) => t(r, n, e), ce = (e, t, r) => Ye(e, typeof t != "symbol" ? t + "" : t, r);
|
|
571
|
-
let F = class extends
|
|
575
|
+
let F = class extends Se {
|
|
572
576
|
constructor(e = q, t, r, n) {
|
|
573
577
|
super(), this._config = e, this._injector = t, this._configService = r, this._commandService = n;
|
|
574
|
-
const { ...s } =
|
|
578
|
+
const { ...s } = pe(
|
|
575
579
|
{},
|
|
576
580
|
q,
|
|
577
581
|
this._config
|
|
@@ -579,7 +583,7 @@ let F = class extends pe {
|
|
|
579
583
|
this._configService.setConfig(ae, s);
|
|
580
584
|
}
|
|
581
585
|
onStarting() {
|
|
582
|
-
|
|
586
|
+
ve(this._injector, [
|
|
583
587
|
[D],
|
|
584
588
|
[oe],
|
|
585
589
|
[J]
|
|
@@ -602,18 +606,18 @@ let F = class extends pe {
|
|
|
602
606
|
}
|
|
603
607
|
};
|
|
604
608
|
ce(F, "pluginName", We);
|
|
605
|
-
ce(F, "type",
|
|
606
|
-
F =
|
|
609
|
+
ce(F, "type", te.UNIVER_SHEET);
|
|
610
|
+
F = ke([
|
|
607
611
|
he(Ne),
|
|
608
|
-
L(1,
|
|
609
|
-
L(2,
|
|
610
|
-
L(3,
|
|
612
|
+
L(1, T(ge)),
|
|
613
|
+
L(2, Q),
|
|
614
|
+
L(3, I)
|
|
611
615
|
], F);
|
|
612
|
-
const
|
|
616
|
+
const rt = (e) => ne.find((r) => e.includes(r)), nt = () => ne.map((e) => ({ label: e, value: e })), st = (e) => se.map((t) => ({
|
|
613
617
|
label: t.label(e),
|
|
614
618
|
value: t.suffix(e),
|
|
615
619
|
color: t.color
|
|
616
|
-
})),
|
|
620
|
+
})), ot = () => we.map((e) => ({ label: e.label, value: e.suffix })), at = () => Oe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
617
621
|
export {
|
|
618
622
|
Pe as AddDecimalCommand,
|
|
619
623
|
se as CURRENCYFORMAT,
|
|
@@ -629,16 +633,16 @@ export {
|
|
|
629
633
|
F as UniverSheetsNumfmtPlugin,
|
|
630
634
|
Ue as countryCurrencyMap,
|
|
631
635
|
ne as currencySymbols,
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
+
st as getCurrencyFormatOptions,
|
|
637
|
+
nt as getCurrencyOptions,
|
|
638
|
+
rt as getCurrencyType,
|
|
639
|
+
ot as getDateFormatOptions,
|
|
636
640
|
O as getDecimalFromPattern,
|
|
637
|
-
|
|
638
|
-
|
|
641
|
+
Z as getDecimalString,
|
|
642
|
+
at as getNumberFormatOptions,
|
|
639
643
|
je as getPatternPreview,
|
|
640
644
|
Le as getPatternPreviewIgnoreGeneral,
|
|
641
|
-
|
|
642
|
-
|
|
645
|
+
tt as getPatternType,
|
|
646
|
+
et as isPatternHasDecimal,
|
|
643
647
|
P as setPatternDecimal
|
|
644
648
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INumfmtLocaleTag, Disposable, ICommandService, IConfigService, IUniverInstanceService, LocaleService, ThemeService } from '@univerjs/core';
|
|
2
2
|
import { INumfmtService, SheetInterceptorService } from '@univerjs/sheets';
|
|
3
3
|
export declare class SheetsNumfmtCellContentController extends Disposable {
|
|
4
4
|
private readonly _instanceService;
|
|
@@ -8,10 +8,10 @@ export declare class SheetsNumfmtCellContentController extends Disposable {
|
|
|
8
8
|
private _numfmtService;
|
|
9
9
|
private _localeService;
|
|
10
10
|
private readonly _configService;
|
|
11
|
-
private
|
|
12
|
-
|
|
11
|
+
private _locale$;
|
|
12
|
+
locale$: import('rxjs').Observable<INumfmtLocaleTag>;
|
|
13
13
|
constructor(_instanceService: IUniverInstanceService, _sheetInterceptorService: SheetInterceptorService, _themeService: ThemeService, _commandService: ICommandService, _numfmtService: INumfmtService, _localeService: LocaleService, _configService: IConfigService);
|
|
14
|
-
get
|
|
14
|
+
get locale(): INumfmtLocaleTag;
|
|
15
15
|
private _initInterceptorCellContent;
|
|
16
|
-
setNumfmtLocal(
|
|
16
|
+
setNumfmtLocal(locale: INumfmtLocaleTag): void;
|
|
17
17
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INumfmtLocaleTag } from '@univerjs/core';
|
|
2
2
|
import { FWorkbook } from '@univerjs/sheets/facade';
|
|
3
3
|
export interface IFWorkbookNumfmtMixin {
|
|
4
4
|
/**
|
|
5
5
|
* Set the locale for number formatting.
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {INumfmtLocaleTag} locale zh_CN,zh_TW,zh_HK,ja,ko,th,cs,da,nl,en,en_AU,en_CA,en_GB,en_IE,fi,fr,fr_CA,fr_CH,de,de_CH,el,hu,is,id,it,it_CH,nb,no,pl,pt,pt_BR,ru,sk,es,es_AR,es_BO,es_CL,es_CO,es_EC,es_MX,es_PY,es_UY,es_VE,sv,tr,cy,az,be,bg,ca,fil,gu,he,hr,hy,ka,kk,kn,lt,lv,ml,mn,mr,my,pa,ro,sl,sr,ta,te,uk,vi,ar,bn,hi
|
|
7
7
|
* @returns {FWorkbook} The FWorkbook instance for chaining.
|
|
8
8
|
* @memberof IFWorkbookNumfmtMixin
|
|
9
9
|
* @example
|
|
@@ -22,10 +22,10 @@ export interface IFWorkbookNumfmtMixin {
|
|
|
22
22
|
* console.log(fRange.getDisplayValue()); // 1.234,57
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
setNumfmtLocal(
|
|
25
|
+
setNumfmtLocal(locale: INumfmtLocaleTag): FWorkbook;
|
|
26
26
|
}
|
|
27
27
|
export declare class FWorkbookLegacy extends FWorkbook implements IFWorkbookNumfmtMixin {
|
|
28
|
-
setNumfmtLocal(
|
|
28
|
+
setNumfmtLocal(locale: INumfmtLocaleTag): FWorkbook;
|
|
29
29
|
}
|
|
30
30
|
declare module '@univerjs/sheets/facade' {
|
|
31
31
|
interface FWorkbook extends IFWorkbookNumfmtMixin {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INumfmtLocaleTag } from '@univerjs/core';
|
|
2
2
|
import { FormatType } from '@univerjs/sheets';
|
|
3
3
|
export declare const getPatternType: (pattern: string) => FormatType;
|
|
4
4
|
interface IPatternPreview {
|
|
5
5
|
result: string;
|
|
6
6
|
color?: string;
|
|
7
7
|
}
|
|
8
|
-
export declare const getPatternPreview: (pattern: string, value: number, locale?:
|
|
9
|
-
export declare const getPatternPreviewIgnoreGeneral: (pattern: string, value: number, locale?:
|
|
8
|
+
export declare const getPatternPreview: (pattern: string, value: number, locale?: INumfmtLocaleTag) => IPatternPreview;
|
|
9
|
+
export declare const getPatternPreviewIgnoreGeneral: (pattern: string, value: number, locale?: INumfmtLocaleTag) => IPatternPreview;
|
|
10
10
|
export {};
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.UniverEngineNumfmt,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,o,A,I,J){"use strict";var de=Object.defineProperty;var ge=(a,t,o)=>t in a?de(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o;var R=(a,t,o)=>ge(a,typeof t!="symbol"?t+"":t,o);const O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],x=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${D(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${D(Number(r||0))}$1`):n).join(";"),X=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),$={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=o.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:d}=l,c=r.values.filter(u=>!!u.pattern),b=r.values.filter(u=>!u.pattern),M=o.transformCellsToRange(m,S,c),C={unitId:m,subUnitId:S,ranges:b.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],y=[];if(c.length){const u=c.reduce((g,f)=>{A.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const P=o.checkCellValueType(_.v);P!==_.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?h.setValue(g,f,{t:_.t}):h.setValue(g,f,{t:void 0})}),Object.keys(M.values).forEach(g=>{const f=M.values[g];f.ranges=o.rangeMerge(f.ranges)}),T.push({id:o.SetNumfmtMutation.id,params:M});const p=o.factorySetNumfmtUndoMutation(e,M);y.push(...p)}if(b.length){C.ranges=o.rangeMerge(C.ranges);const u=b.reduce((g,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const P=o.checkCellValueType(_.v);P!==_.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?h.setValue(g,f,{t:_.t}):h.setValue(g,f,{t:void 0})}),T.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const p=o.factoryRemoveNumfmtUndoMutation(e,C);y.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:h.getMatrix()}},...p)}const v=t.sequenceExecute(T,i).result;return v&&s.pushUndoRedo({unitID:m,undoMutations:y,redoMutations:T}),v}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;l.forEach(T=>{t.Range.foreach(T.range,(y,v)=>{const u=n.getValue(S,d,y,v);if(!u){const p=m.worksheet.getCellRaw(y,v);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const g=/\.(\d*)$/.exec(String(p.v));if(g){const f=g[1].length;if(!f)return;c=Math.max(c,f)}}return}const h=E(u.pattern);c=h>c?h:c})});const b=c+1,M=U(`0${b>0?".0":""}`,b),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(y,v)=>{const u=n.getValue(S,d,y,v);if(!u)C.push({row:y,col:v,pattern:M});else{const h=E(u.pattern),p=U(u.pattern,h+1);p!==u.pattern&&C.push({row:y,col:v,pattern:p})}})}),C.length?await r.executeCommand($.id,{values:C}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(j),s=L[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],S=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(b,M)=>{m.push({row:b,col:M,pattern:S,type:"currency"})})}),await r.executeCommand($.id,{values:m})}},W={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;l.forEach(y=>{t.Range.foreach(y.range,(v,u)=>{const h=n.getValue(S,d,v,u);if(!h){const g=m.worksheet.getCellRaw(v,u);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(h.pattern);c=p>c?p:c})});const b=c-1,M=U(`0${b>0?".0":"."}`,b),C=[];return l.forEach(y=>{t.Range.foreach(y.range,(v,u)=>{const h=n.getValue(S,d,v,u);if(!h)C.push({row:v,col:u,pattern:M});else{const p=E(h.pattern);C.push({row:v,col:u,pattern:U(h.pattern,p-1)})}})}),await r.executeCommand($.id,{values:C})}},w="sheets-numfmt.config",K={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,i="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,l=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:l,color:s}:{result:l}},k=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:Y(e,r,i);var ee=Object.getOwnPropertyDescriptor,te=(e,r,i,n)=>{for(var s=n>1?void 0:n?ee(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,r)=>(i,n)=>r(i,n,e);const ne={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,d){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=d,this._initInterceptorCellContent()}get local(){const i=this._local$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var y,v;const m=s.unitId,S=s.subUnitId;let d;const c=n;if(!c||c.v===void 0||c.v===null)return l(n);if(n!=null&&n.s){const u=s.workbook.getStyles().get(n.s);u!=null&&u.n&&(d=u.n)}if(d||(d=this._numfmtService.getValue(m,S,s.row,s.col)),!d||d.pattern==="General"||c.t!==t.CellValueType.NUMBER&&o.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),A.isTextFormat(d.pattern))return(y=this._configService.getConfig(w))!=null&&y.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},l(n));let b="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${c.v}_${d.pattern}`)return l({...n,...M.result});const C=k(d.pattern,Number(c.v),this.local);if(b=C.result,!b)return l(n);const T={v:b,t:t.CellValueType.NUMBER};if(C.color){const u=(v=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?v:C.color;u&&(T.interceptorStyle={cl:{rgb:u}})}return i.setValue(s.row,s.col,{result:T,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,T),l(n)},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(d,c)=>{i.realDeleteValue(d,c)})})})}else if(n.id===o.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._local$.next(i)}},a.SheetsNumfmtCellContentController=te([N(0,t.IUniverInstanceService),N(1,t.Inject(o.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(o.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);const re="SHEET_NUMFMT_PLUGIN";class z extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(i){this._currencySymbol$.next(i)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,le=(e,r,i,n)=>{for(var s=n>1?void 0:n?ie(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},F=(e,r)=>(i,n)=>r(i,n,e),Z=(e,r,i)=>se(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=K,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},K,this._config);this._configService.setConfig(w,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[j],[z]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[z]]),[B,q,H,W,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",re),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=le([t.DependentOn(o.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ue=e=>O.find(i=>e.includes(i)),ce=()=>O.map(e=>({label:e,value:e})),oe=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>G.map(e=>({label:e.label,value:e.suffix})),fe=()=>x.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=B,a.CURRENCYFORMAT=V,a.DATEFMTLISG=G,a.MenuCurrencyService=j,a.NUMBERFORMAT=x,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,a.SetCurrencyCommand=H,a.SetNumfmtCommand=$,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=oe,a.getCurrencyOptions=ce,a.getCurrencyType=ue,a.getDateFormatOptions=me,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=fe,a.getPatternPreview=Y,a.getPatternPreviewIgnoreGeneral=k,a.getPatternType=Q,a.isPatternHasDecimal=X,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,o,I,Z){"use strict";var fe=Object.defineProperty;var de=(a,t,o)=>t in a?fe(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o;var R=(a,t,o)=>de(a,typeof t!="symbol"?t+"":t,o);const 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:"€"},L=[{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"}],G=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${D(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${D(Number(r||0))}$1`):n).join(";"),J=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),$={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=o.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:d}=l,c=r.values.filter(u=>!!u.pattern),b=r.values.filter(u=>!u.pattern),M=o.transformCellsToRange(m,S,c),C={unitId:m,subUnitId:S,ranges:b.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],h=[];if(c.length){const u=c.reduce((g,f)=>{t.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?y.setValue(g,f,{t:_.t}):y.setValue(g,f,{t:void 0})}),Object.keys(M.values).forEach(g=>{const f=M.values[g];f.ranges=o.rangeMerge(f.ranges)}),T.push({id:o.SetNumfmtMutation.id,params:M});const p=o.factorySetNumfmtUndoMutation(e,M);h.push(...p)}if(b.length){C.ranges=o.rangeMerge(C.ranges);const u=b.reduce((g,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?y.setValue(g,f,{t:_.t}):y.setValue(g,f,{t:void 0})}),T.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const p=o.factoryRemoveNumfmtUndoMutation(e,C);h.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:y.getMatrix()}},...p)}const v=t.sequenceExecute(T,i).result;return v&&s.pushUndoRedo({unitID:m,undoMutations:h,redoMutations:T}),v}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;l.forEach(T=>{t.Range.foreach(T.range,(h,v)=>{const u=n.getValue(S,d,h,v);if(!u){const p=m.worksheet.getCellRaw(h,v);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const g=/\.(\d*)$/.exec(String(p.v));if(g){const f=g[1].length;if(!f)return;c=Math.max(c,f)}}return}const y=E(u.pattern);c=y>c?y:c})});const b=c+1,M=U(`0${b>0?".0":""}`,b),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(h,v)=>{const u=n.getValue(S,d,h,v);if(!u)C.push({row:h,col:v,pattern:M});else{const y=E(u.pattern),p=U(u.pattern,y+1);p!==u.pattern&&C.push({row:h,col:v,pattern:p})}})}),C.length?await r.executeCommand($.id,{values:C}):!1}};class w{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const B={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(w),s=A[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],S=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(b,M)=>{m.push({row:b,col:M,pattern:S,type:"currency"})})}),await r.executeCommand($.id,{values:m})}},H={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.id,{values:s})}},K={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;l.forEach(h=>{t.Range.foreach(h.range,(v,u)=>{const y=n.getValue(S,d,v,u);if(!y){const g=m.worksheet.getCellRaw(v,u);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(y.pattern);c=p>c?p:c})});const b=c-1,M=U(`0${b>0?".0":"."}`,b),C=[];return l.forEach(h=>{t.Range.foreach(h.range,(v,u)=>{const y=n.getValue(S,d,v,u);if(!y)C.push({row:v,col:u,pattern:M});else{const p=E(y.pattern);C.push({row:v,col:u,pattern:U(y.pattern,p-1)})}})}),await r.executeCommand($.id,{values:C})}},j="sheets-numfmt.config",W={},X=e=>t.numfmt.getFormatInfo(e).type||"unknown",q=(e,r,i="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,l=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:l,color:s}:{result:l}},Y=(e,r,i)=>e==="General"?{result:String(Z.stripErrorMargin(r))}:q(e,r,i);var Q=Object.getOwnPropertyDescriptor,ee=(e,r,i,n)=>{for(var s=n>1?void 0:n?Q(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,r)=>(i,n)=>r(i,n,e);const te={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,d){super();R(this,"_locale$",new I.BehaviorSubject("en"));R(this,"locale$",this._locale$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=d,this._initInterceptorCellContent()}get locale(){const i=this._locale$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var h,v;const m=s.unitId,S=s.subUnitId;let d;const c=n;if(!c||c.v===void 0||c.v===null)return l(n);if(n!=null&&n.s){const u=s.workbook.getStyles().get(n.s);u!=null&&u.n&&(d=u.n)}if(d||(d=this._numfmtService.getValue(m,S,s.row,s.col)),!d||d.pattern==="General"||c.t!==t.CellValueType.NUMBER&&o.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(d.pattern))return(h=this._configService.getConfig(j))!=null&&h.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...te},l(n));let b="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${c.v}_${d.pattern}`)return l({...n,...M.result});const C=Y(d.pattern,Number(c.v),this.locale);if(b=C.result,!b)return l(n);const T={v:b,t:t.CellValueType.NUMBER};if(C.color){const u=(v=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?v:C.color;u&&(T.interceptorStyle={cl:{rgb:u}})}return i.setValue(s.row,s.col,{result:T,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,T),l(n)},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(d,c)=>{i.realDeleteValue(d,c)})})})}else if(n.id===o.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},a.SheetsNumfmtCellContentController=ee([N(0,t.IUniverInstanceService),N(1,t.Inject(o.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(o.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);const ne="SHEET_NUMFMT_PLUGIN";class k extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(i){this._currencySymbol$.next(i)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var re=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,ie=(e,r,i)=>r in e?re(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,se=(e,r,i,n)=>{for(var s=n>1?void 0:n?ae(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},F=(e,r)=>(i,n)=>r(i,n,e),z=(e,r,i)=>ie(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=W,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},W,this._config);this._configService.setConfig(j,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[w],[k]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[k]]),[x,K,B,H,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},z(a.UniverSheetsNumfmtPlugin,"pluginName",ne),z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=se([t.DependentOn(o.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const le=e=>P.find(i=>e.includes(i)),ue=()=>P.map(e=>({label:e,value:e})),ce=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),oe=()=>L.map(e=>({label:e.label,value:e.suffix})),me=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=x,a.CURRENCYFORMAT=V,a.DATEFMTLISG=L,a.MenuCurrencyService=w,a.NUMBERFORMAT=G,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=j,a.SetCurrencyCommand=B,a.SetNumfmtCommand=$,a.SetPercentCommand=H,a.SubtractDecimalCommand=K,a.countryCurrencyMap=A,a.currencySymbols=P,a.getCurrencyFormatOptions=ce,a.getCurrencyOptions=ue,a.getCurrencyType=le,a.getDateFormatOptions=oe,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=me,a.getPatternPreview=q,a.getPatternPreviewIgnoreGeneral=Y,a.getPatternType=X,a.isPatternHasDecimal=J,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.9.2-nightly.
|
|
3
|
+
"version": "0.9.2-nightly.202507151607",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -58,10 +58,9 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/
|
|
63
|
-
"@univerjs/sheets": "0.9.2-nightly.
|
|
64
|
-
"@univerjs/engine-numfmt": "0.9.2-nightly.202507131606"
|
|
61
|
+
"@univerjs/core": "0.9.2-nightly.202507151607",
|
|
62
|
+
"@univerjs/engine-formula": "0.9.2-nightly.202507151607",
|
|
63
|
+
"@univerjs/sheets": "0.9.2-nightly.202507151607"
|
|
65
64
|
},
|
|
66
65
|
"devDependencies": {
|
|
67
66
|
"rxjs": "^7.8.2",
|