@univerjs/sheets-numfmt 0.12.1-nightly.202511221011 → 0.12.2-experimental.20251129-0fa20cd
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 +95 -88
- package/lib/index.js +95 -88
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var z=Object.defineProperty;var X=(e,r,a)=>r in e?z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a;var U=(e,r,a)=>X(e,typeof r!="symbol"?r+"":r,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function V(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function j(e,r=2){let a=r;r>127&&(a=127);let n="";return a>0&&(n=`.${"0".repeat(a)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const A=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],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"}],G=[{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,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},L=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?".":""}${L(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${L(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 a=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:i}=o,u=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=f.transformCellsToRange(l,d,u),h={unitId:l,subUnitId:d,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],C=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.t}):p.setValue(g,m,{t:void 0})}),Object.keys(T.values).forEach(g=>{const m=T.values[g];m.ranges=f.rangeMerge(m.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:T});const y=f.factorySetNumfmtUndoMutation(e,T);C.push(...y)}if(_.length){h.ranges=f.rangeMerge(h.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.t}):p.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,h);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:p.getMatrix()}},...y)}const S=t.sequenceExecute(M,a).result;return S&&s.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),S}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(!c){const y=l.worksheet.getCellRaw(C,S);if(!u&&y&&y.t===t.CellValueType.NUMBER&&y.v){const g=/\.(\d*)$/.exec(String(y.v));if(g){const m=g[1].length;if(!m)return;u=Math.max(u,m)}}return}const p=$(c.pattern);u=p>u?p:u})});const _=u+1,T=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(t.isDefaultFormat(c==null?void 0:c.pattern))h.push({row:C,col:S,pattern:T});else{const p=$(c.pattern),y=O(c.pattern,p+1);y!==c.pattern&&h.push({row:C,col:S,pattern:y})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),s=a.getCurrentSelections();if(!s||!s.length)return!1;const o=[],l=V(n.getCurrentLocale()),d=j(l.locale);return s.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(R.id,{values:o})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{s.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(!p){const g=l.worksheet.getCellRaw(S,c);if(!u&&g&&g.t===t.CellValueType.NUMBER&&g.v){const m=/\.(\d*)$/.exec(String(g.v));if(m){const v=m[1].length;if(!v)return;u=Math.max(u,v)}}return}const y=$(p.pattern);u=y>u?y:u})});const _=u-1,T=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(C=>{t.Range.foreach(C.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(t.isDefaultFormat(p==null?void 0:p.pattern))h.push({row:S,col:c,pattern:T});else{const y=$(p.pattern);h.push({row:S,col:c,pattern:O(p.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:h})}},D="sheets-numfmt.config",w={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,a="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:a,throws:!1});return r<0?{result:o,color:s}:{result:o}},k=(e,r,a)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,a);var te=Object.getOwnPropertyDescriptor,ne=(e,r,a,n)=>{for(var s=n>1?void 0:n?te(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},b=(e,r)=>(a,n)=>r(a,n,e);const re={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(a,n,s,o,l,d,i){super();U(this,"_locale$",new N.BehaviorSubject("en"));U(this,"locale$",this._locale$.asObservable());this._instanceService=a,this._sheetInterceptorService=n,this._themeService=s,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const a=this._locale$.getValue();if(a)return a;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.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 a=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{a.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,o)=>{var C,S;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return o(n);const l=s.unitId,d=s.subUnitId;let i;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,s.row,s.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(C=this._configService.getConfig(D))!=null&&C.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 _="";const T=a.getValue(s.row,s.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const h=k(i==null?void 0:i.pattern,Number(u.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 a.setValue(s.row,s.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(o=>{s.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{a.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((o,l)=>{a.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>a.reset()))}setNumfmtLocal(a){this._locale$.next(a)}};exports.SheetsNumfmtCellContentController=ne([b(0,t.IUniverInstanceService),b(1,t.Inject(f.SheetInterceptorService)),b(2,t.Inject(t.ThemeService)),b(3,t.Inject(t.ICommandService)),b(4,t.Inject(f.INumfmtService)),b(5,t.Inject(t.LocaleService)),b(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var se=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,a)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,ie=(e,r,a,n)=>{for(var s=n>1?void 0:n?oe(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},P=(e,r)=>(a,n)=>r(a,n,e),Y=(e,r,a)=>ce(e,typeof r!="symbol"?r+"":r,a);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=w,a,n,s){super(),this._config=r,this._injector=a,this._configService=n,this._commandService=s;const{...o}=t.merge({},w,this._config);this._configService.setConfig(D,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){[H,q,W,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};Y(exports.UniverSheetsNumfmtPlugin,"pluginName",ae);Y(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(f.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>x.find(a=>e.includes(a)),ue=()=>x.map(e=>({label:e,value:e})),me=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>A.map(e=>({label:e.label,value:e.suffix})),ge=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=A;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=x;exports.getCurrencyFormat=j;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=V;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=$;exports.getDecimalString=L;exports.getNumberFormatOptions=ge;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=O;
|
|
1
|
+
"use strict";var z=Object.defineProperty;var X=(e,r,a)=>r in e?z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a;var U=(e,r,a)=>X(e,typeof r!="symbol"?r+"":r,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),N=require("rxjs"),J=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function V(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function j(e,r=2){let a=r;r>127&&(a=127);let n="";return a>0&&(n=`.${"0".repeat(a)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const A=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],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"}],G=[{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,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},L=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?".":""}${L(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${L(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 a=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:i}=o,u=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=f.transformCellsToRange(l,d,u),h={unitId:l,subUnitId:d,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],C=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.t}):p.setValue(g,m,{t:void 0})}),Object.keys(T.values).forEach(g=>{const m=T.values[g];m.ranges=f.rangeMerge(m.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:T});const y=f.factorySetNumfmtUndoMutation(e,T);C.push(...y)}if(_.length){h.ranges=f.rangeMerge(h.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const I=f.checkCellValueType(v.v);I!==v.t&&g.setValue(m.row,m.col,{t:I})}return g},new t.ObjectMatrix).getMatrix(),p=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?p.setValue(g,m,{t:v.t}):p.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,h);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:p.getMatrix()}},...y)}const S=t.sequenceExecute(M,a).result;return S&&s.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),S}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(!c){const y=l.worksheet.getCellRaw(C,S);if(!u&&y&&y.t===t.CellValueType.NUMBER&&y.v){const g=/\.(\d*)$/.exec(String(y.v));if(g){const m=g[1].length;if(!m)return;u=Math.max(u,m)}}return}const p=$(c.pattern);u=p>u?p:u})});const _=u+1,T=O(`0${_>0?".0":""}`,_),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,S)=>{const c=n.getValue(d,i,C,S);if(t.isDefaultFormat(c==null?void 0:c.pattern))h.push({row:C,col:S,pattern:T});else{const p=$(c.pattern),y=O(c.pattern,p+1);y!==c.pattern&&h.push({row:C,col:S,pattern:y})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),s=a.getCurrentSelections();if(!s||!s.length)return!1;const o=[],l=V(n.getCurrentLocale()),d=j(l.locale);return s.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(R.id,{values:o})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{s.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(!p){const g=l.worksheet.getCellRaw(S,c);if(!u&&g&&g.t===t.CellValueType.NUMBER&&g.v){const m=/\.(\d*)$/.exec(String(g.v));if(m){const v=m[1].length;if(!v)return;u=Math.max(u,v)}}return}const y=$(p.pattern);u=y>u?y:u})});const _=u-1,T=O(`0${_>0?".0":"."}`,_),h=[];return o.forEach(C=>{t.Range.foreach(C.range,(S,c)=>{const p=n.getValue(d,i,S,c);if(t.isDefaultFormat(p==null?void 0:p.pattern))h.push({row:S,col:c,pattern:T});else{const y=$(p.pattern);h.push({row:S,col:c,pattern:O(p.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:h})}},D="sheets-numfmt.config",w={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,a="en")=>{try{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:a,throws:!1});return r<0?{result:o,color:s}:{result:o}}catch(n){console.warn("getPatternPreview error:",e,n)}return{result:String(r)}},k=(e,r,a)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,a);var te=Object.getOwnPropertyDescriptor,ne=(e,r,a,n)=>{for(var s=n>1?void 0:n?te(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},b=(e,r)=>(a,n)=>r(a,n,e);const re={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(a,n,s,o,l,d,i){super();U(this,"_locale$",new N.BehaviorSubject("en"));U(this,"locale$",this._locale$.asObservable());this._instanceService=a,this._sheetInterceptorService=n,this._themeService=s,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const a=this._locale$.getValue();if(a)return a;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.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 a=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{a.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,o)=>{var C,S;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return o(n);const l=s.unitId,d=s.subUnitId;let i;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,s.row,s.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(C=this._configService.getConfig(D))!=null&&C.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 _="";const T=a.getValue(s.row,s.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const h=k(i==null?void 0:i.pattern,Number(u.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 a.setValue(s.row,s.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(o=>{s.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{a.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((o,l)=>{a.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>a.reset()))}setNumfmtLocal(a){this._locale$.next(a)}};exports.SheetsNumfmtCellContentController=ne([b(0,t.IUniverInstanceService),b(1,t.Inject(f.SheetInterceptorService)),b(2,t.Inject(t.ThemeService)),b(3,t.Inject(t.ICommandService)),b(4,t.Inject(f.INumfmtService)),b(5,t.Inject(t.LocaleService)),b(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var se=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ce=(e,r,a)=>r in e?se(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,ie=(e,r,a,n)=>{for(var s=n>1?void 0:n?oe(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},P=(e,r)=>(a,n)=>r(a,n,e),Y=(e,r,a)=>ce(e,typeof r!="symbol"?r+"":r,a);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=w,a,n,s){super(),this._config=r,this._injector=a,this._configService=n,this._commandService=s;const{...o}=t.merge({},w,this._config);this._configService.setConfig(D,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){[H,q,W,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};Y(exports.UniverSheetsNumfmtPlugin,"pluginName",ae);Y(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ie([t.DependentOn(f.UniverSheetsPlugin),P(1,t.Inject(t.Injector)),P(2,t.IConfigService),P(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const le=e=>x.find(a=>e.includes(a)),ue=()=>x.map(e=>({label:e,value:e})),me=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>A.map(e=>({label:e.label,value:e.suffix})),ge=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=A;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=x;exports.getCurrencyFormat=j;exports.getCurrencyFormatOptions=me;exports.getCurrencyOptions=ue;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=V;exports.getCurrencyType=le;exports.getDateFormatOptions=fe;exports.getDecimalFromPattern=$;exports.getDecimalString=L;exports.getNumberFormatOptions=ge;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=O;
|
package/lib/es/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var ae = Object.defineProperty;
|
|
2
|
-
var ie = (e,
|
|
3
|
-
var L = (e,
|
|
2
|
+
var ie = (e, r, t) => r in e ? ae(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
|
|
3
|
+
var L = (e, r, t) => ie(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
4
|
import { LocaleType as f, numfmt as x, CommandType as U, ICommandService as $, IUniverInstanceService as V, IUndoRedoService as ce, isTextFormat as J, CellValueType as M, ObjectMatrix as R, sequenceExecute as le, Range as N, isDefaultFormat as W, LocaleService as Q, DEFAULT_NUMBER_FORMAT as ue, Inject as I, ThemeService as fe, IConfigService as ee, Disposable as me, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as de, Injector as ge, Plugin as he, merge as pe, registerDependencies as _e, touchDependencies as ve } from "@univerjs/core";
|
|
5
|
-
import { getSheetCommandTarget as K, transformCellsToRange as Se, checkCellValueType as H, rangeMerge as k, SetNumfmtMutation as
|
|
5
|
+
import { getSheetCommandTarget as K, transformCellsToRange as Se, checkCellValueType as H, rangeMerge as k, SetNumfmtMutation as re, factorySetNumfmtUndoMutation as Ce, RemoveNumfmtMutation as ye, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as Z, SheetInterceptorService as Me, INTERCEPTOR_POINT as Re, InterceptCellContentPriority as Ee, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
|
|
6
6
|
import { BehaviorSubject as $e, merge as Ie, switchMap as Te, of as Ue, skip as Oe } from "rxjs";
|
|
7
7
|
import { stripErrorMargin as we } from "@univerjs/engine-formula";
|
|
8
|
-
const
|
|
8
|
+
const ne = [
|
|
9
9
|
"$",
|
|
10
10
|
"£",
|
|
11
11
|
"¥",
|
|
@@ -80,11 +80,11 @@ function xe(e) {
|
|
|
80
80
|
function Y(e) {
|
|
81
81
|
return w.get(e) || "$";
|
|
82
82
|
}
|
|
83
|
-
function Pe(e,
|
|
84
|
-
let t =
|
|
85
|
-
|
|
86
|
-
let
|
|
87
|
-
return t > 0 && (
|
|
83
|
+
function Pe(e, r = 2) {
|
|
84
|
+
let t = r;
|
|
85
|
+
r > 127 && (t = 127);
|
|
86
|
+
let n = "";
|
|
87
|
+
return t > 0 && (n = `.${"0".repeat(t)}`), `"${Y(e)}"#,##0${n}_);[Red]("${Y(e)}"#,##0${n})`;
|
|
88
88
|
}
|
|
89
89
|
const Fe = [
|
|
90
90
|
{
|
|
@@ -187,25 +187,25 @@ const Fe = [
|
|
|
187
187
|
suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
|
|
188
188
|
color: "red"
|
|
189
189
|
}
|
|
190
|
-
], P = (e,
|
|
191
|
-
var
|
|
192
|
-
return e && (
|
|
193
|
-
}, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), F = (e,
|
|
190
|
+
], P = (e, r = 0) => {
|
|
191
|
+
var n;
|
|
192
|
+
return e && (n = x.getFormatInfo(e).maxDecimals) != null ? n : r;
|
|
193
|
+
}, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), F = (e, r) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
|
|
194
194
|
/\.0*/g,
|
|
195
|
-
`${
|
|
196
|
-
) : /0([^0]?)|0$/.test(
|
|
195
|
+
`${r > 0 ? "." : ""}${q(Number(r || 0))}`
|
|
196
|
+
) : /0([^0]?)|0$/.test(n) ? n.replace(
|
|
197
197
|
/0([^0]+)|0$/,
|
|
198
|
-
`0${
|
|
199
|
-
) :
|
|
198
|
+
`0${r > 0 ? "." : ""}${q(Number(r || 0))}$1`
|
|
199
|
+
) : n).join(";"), nt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), O = {
|
|
200
200
|
id: "sheet.command.numfmt.set.numfmt",
|
|
201
201
|
type: U.COMMAND,
|
|
202
202
|
// eslint-disable-next-line max-lines-per-function
|
|
203
|
-
handler: (e,
|
|
204
|
-
if (!
|
|
203
|
+
handler: (e, r) => {
|
|
204
|
+
if (!r)
|
|
205
205
|
return !1;
|
|
206
|
-
const t = e.get($),
|
|
206
|
+
const t = e.get($), n = e.get(V), s = e.get(ce), a = K(n, r);
|
|
207
207
|
if (!a) return !1;
|
|
208
|
-
const { unitId: l, subUnitId: o, worksheet: h } = a, u =
|
|
208
|
+
const { unitId: l, subUnitId: o, worksheet: h } = a, u = r.values.filter((i) => !!i.pattern), C = r.values.filter((i) => !i.pattern), y = Se(l, o, u), p = {
|
|
209
209
|
unitId: l,
|
|
210
210
|
subUnitId: o,
|
|
211
211
|
ranges: C.map((i) => ({
|
|
@@ -232,7 +232,7 @@ const Fe = [
|
|
|
232
232
|
const c = y.values[d];
|
|
233
233
|
c.ranges = k(c.ranges);
|
|
234
234
|
}), b.push({
|
|
235
|
-
id:
|
|
235
|
+
id: re.id,
|
|
236
236
|
params: y
|
|
237
237
|
});
|
|
238
238
|
const v = Ce(e, y);
|
|
@@ -283,7 +283,7 @@ const Fe = [
|
|
|
283
283
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
284
284
|
type: U.COMMAND,
|
|
285
285
|
handler: async (e) => {
|
|
286
|
-
const
|
|
286
|
+
const r = e.get($), t = e.get(j), n = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
|
|
287
287
|
if (!a || !a.length)
|
|
288
288
|
return !1;
|
|
289
289
|
const l = K(s);
|
|
@@ -292,7 +292,7 @@ const Fe = [
|
|
|
292
292
|
let u = 0;
|
|
293
293
|
a.forEach((b) => {
|
|
294
294
|
N.foreach(b.range, (_, m) => {
|
|
295
|
-
const i =
|
|
295
|
+
const i = n.getValue(o, h, _, m);
|
|
296
296
|
if (!i) {
|
|
297
297
|
const v = l.worksheet.getCellRaw(_, m);
|
|
298
298
|
if (!u && v && v.t === M.NUMBER && v.v) {
|
|
@@ -313,7 +313,7 @@ const Fe = [
|
|
|
313
313
|
const C = u + 1, y = F(`0${C > 0 ? ".0" : ""}`, C), p = [];
|
|
314
314
|
return a.forEach((b) => {
|
|
315
315
|
N.foreach(b.range, (_, m) => {
|
|
316
|
-
const i =
|
|
316
|
+
const i = n.getValue(o, h, _, m);
|
|
317
317
|
if (W(i == null ? void 0 : i.pattern))
|
|
318
318
|
p.push({
|
|
319
319
|
row: _,
|
|
@@ -329,41 +329,41 @@ const Fe = [
|
|
|
329
329
|
});
|
|
330
330
|
}
|
|
331
331
|
});
|
|
332
|
-
}), p.length ? await
|
|
332
|
+
}), p.length ? await r.executeCommand(O.id, { values: p }) : !1;
|
|
333
333
|
}
|
|
334
334
|
}, je = {
|
|
335
335
|
id: "sheet.command.numfmt.set.currency",
|
|
336
336
|
type: U.COMMAND,
|
|
337
337
|
handler: async (e) => {
|
|
338
|
-
const
|
|
338
|
+
const r = e.get($), t = e.get(j), n = e.get(Q), s = t.getCurrentSelections();
|
|
339
339
|
if (!s || !s.length)
|
|
340
340
|
return !1;
|
|
341
|
-
const a = [], l = xe(
|
|
341
|
+
const a = [], l = xe(n.getCurrentLocale()), o = Pe(l.locale);
|
|
342
342
|
return s.forEach((u) => {
|
|
343
343
|
N.foreach(u.range, (C, y) => {
|
|
344
344
|
a.push({ row: C, col: y, pattern: o, type: "currency" });
|
|
345
345
|
});
|
|
346
|
-
}), await
|
|
346
|
+
}), await r.executeCommand(O.id, { values: a });
|
|
347
347
|
}
|
|
348
348
|
}, Le = {
|
|
349
349
|
id: "sheet.command.numfmt.set.percent",
|
|
350
350
|
type: U.COMMAND,
|
|
351
351
|
handler: async (e) => {
|
|
352
|
-
const
|
|
353
|
-
if (!
|
|
352
|
+
const r = e.get($), n = e.get(j).getCurrentSelections();
|
|
353
|
+
if (!n || !n.length)
|
|
354
354
|
return !1;
|
|
355
355
|
const s = [], a = "0%";
|
|
356
|
-
return
|
|
356
|
+
return n.forEach((o) => {
|
|
357
357
|
N.foreach(o.range, (h, u) => {
|
|
358
358
|
s.push({ row: h, col: u, pattern: a, type: "percent" });
|
|
359
359
|
});
|
|
360
|
-
}), await
|
|
360
|
+
}), await r.executeCommand(O.id, { values: s });
|
|
361
361
|
}
|
|
362
362
|
}, Be = {
|
|
363
363
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
364
364
|
type: U.COMMAND,
|
|
365
365
|
handler: async (e) => {
|
|
366
|
-
const
|
|
366
|
+
const r = e.get($), t = e.get(j), n = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
|
|
367
367
|
if (!a || !a.length)
|
|
368
368
|
return !1;
|
|
369
369
|
const l = K(s);
|
|
@@ -372,7 +372,7 @@ const Fe = [
|
|
|
372
372
|
let u = 0;
|
|
373
373
|
a.forEach((_) => {
|
|
374
374
|
N.foreach(_.range, (m, i) => {
|
|
375
|
-
const g =
|
|
375
|
+
const g = n.getValue(o, h, m, i);
|
|
376
376
|
if (!g) {
|
|
377
377
|
const d = l.worksheet.getCellRaw(m, i);
|
|
378
378
|
if (!u && d && d.t === M.NUMBER && d.v) {
|
|
@@ -393,7 +393,7 @@ const Fe = [
|
|
|
393
393
|
const C = u - 1, y = F(`0${C > 0 ? ".0" : "."}`, C), p = [];
|
|
394
394
|
return a.forEach((_) => {
|
|
395
395
|
N.foreach(_.range, (m, i) => {
|
|
396
|
-
const g =
|
|
396
|
+
const g = n.getValue(o, h, m, i);
|
|
397
397
|
if (W(g == null ? void 0 : g.pattern))
|
|
398
398
|
p.push({
|
|
399
399
|
row: m,
|
|
@@ -409,25 +409,32 @@ const Fe = [
|
|
|
409
409
|
});
|
|
410
410
|
}
|
|
411
411
|
});
|
|
412
|
-
}), await
|
|
412
|
+
}), await r.executeCommand(O.id, { values: p });
|
|
413
413
|
}
|
|
414
|
-
}, se = "sheets-numfmt.config", X = {}, st = (e) => x.getFormatInfo(e).type || "unknown", He = (e,
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
414
|
+
}, se = "sheets-numfmt.config", X = {}, st = (e) => x.getFormatInfo(e).type || "unknown", He = (e, r, t = "en") => {
|
|
415
|
+
try {
|
|
416
|
+
const n = x.formatColor(e, r), s = n ? String(n) : void 0, a = x.format(e, r, { locale: t, throws: !1 });
|
|
417
|
+
return r < 0 ? {
|
|
418
|
+
result: a,
|
|
419
|
+
color: s
|
|
420
|
+
} : {
|
|
421
|
+
result: a
|
|
422
|
+
};
|
|
423
|
+
} catch (n) {
|
|
424
|
+
console.warn("getPatternPreview error:", e, n);
|
|
425
|
+
}
|
|
426
|
+
return {
|
|
427
|
+
result: String(r)
|
|
421
428
|
};
|
|
422
|
-
}, Ge = (e,
|
|
423
|
-
result: String(we(
|
|
429
|
+
}, Ge = (e, r, t) => e === ue ? {
|
|
430
|
+
result: String(we(r))
|
|
424
431
|
// In Excel, the default General format also needs to handle numeric precision.
|
|
425
|
-
} : He(e,
|
|
426
|
-
var We = Object.getOwnPropertyDescriptor, Ke = (e,
|
|
427
|
-
for (var s =
|
|
432
|
+
} : He(e, r, t);
|
|
433
|
+
var We = Object.getOwnPropertyDescriptor, Ke = (e, r, t, n) => {
|
|
434
|
+
for (var s = n > 1 ? void 0 : n ? We(r, t) : r, a = e.length - 1, l; a >= 0; a--)
|
|
428
435
|
(l = e[a]) && (s = l(s) || s);
|
|
429
436
|
return s;
|
|
430
|
-
}, E = (e,
|
|
437
|
+
}, E = (e, r) => (t, n) => r(t, n, e);
|
|
431
438
|
const Ze = {
|
|
432
439
|
tl: {
|
|
433
440
|
size: 6,
|
|
@@ -435,16 +442,16 @@ const Ze = {
|
|
|
435
442
|
}
|
|
436
443
|
};
|
|
437
444
|
let D = class extends me {
|
|
438
|
-
constructor(
|
|
445
|
+
constructor(r, t, n, s, a, l, o) {
|
|
439
446
|
super();
|
|
440
447
|
L(this, "_locale$", new $e("en"));
|
|
441
448
|
L(this, "locale$", this._locale$.asObservable());
|
|
442
|
-
this._instanceService =
|
|
449
|
+
this._instanceService = r, this._sheetInterceptorService = t, this._themeService = n, this._commandService = s, this._numfmtService = a, this._localeService = l, this._configService = o, this._initInterceptorCellContent();
|
|
443
450
|
}
|
|
444
451
|
get locale() {
|
|
445
|
-
const
|
|
446
|
-
if (
|
|
447
|
-
return
|
|
452
|
+
const r = this._locale$.getValue();
|
|
453
|
+
if (r)
|
|
454
|
+
return r;
|
|
448
455
|
switch (this._localeService.getCurrentLocale()) {
|
|
449
456
|
case f.FR_FR:
|
|
450
457
|
return "fr";
|
|
@@ -469,29 +476,29 @@ let D = class extends me {
|
|
|
469
476
|
}
|
|
470
477
|
// eslint-disable-next-line max-lines-per-function
|
|
471
478
|
_initInterceptorCellContent() {
|
|
472
|
-
const
|
|
479
|
+
const r = new R();
|
|
473
480
|
this.disposeWithMe(Ie(this._locale$, this._localeService.currentLocale$).subscribe(() => {
|
|
474
|
-
|
|
481
|
+
r.reset();
|
|
475
482
|
})), this.disposeWithMe(this._sheetInterceptorService.intercept(Re.CELL_CONTENT, {
|
|
476
483
|
effect: z.Value | z.Style,
|
|
477
484
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
478
|
-
handler: (t,
|
|
485
|
+
handler: (t, n, s) => {
|
|
479
486
|
var b, _;
|
|
480
487
|
if (!t || t.v === void 0 || t.v === null || t.t === M.BOOLEAN || t.t === M.FORCE_STRING)
|
|
481
488
|
return s(t);
|
|
482
|
-
const a =
|
|
489
|
+
const a = n.unitId, l = n.subUnitId;
|
|
483
490
|
let o;
|
|
484
491
|
if (t != null && t.s) {
|
|
485
|
-
const m =
|
|
492
|
+
const m = n.workbook.getStyles().get(t.s);
|
|
486
493
|
m != null && m.n && (o = m.n);
|
|
487
494
|
}
|
|
488
|
-
if (o || (o = this._numfmtService.getValue(a, l,
|
|
495
|
+
if (o || (o = this._numfmtService.getValue(a, l, n.row, n.col)), W(o == null ? void 0 : o.pattern) || t.t !== M.NUMBER && H(t.v, t.t) !== M.NUMBER)
|
|
489
496
|
return s(t);
|
|
490
497
|
const h = t;
|
|
491
|
-
if ((!t || t ===
|
|
498
|
+
if ((!t || t === n.rawData) && (t = { ...n.rawData }), J(o == null ? void 0 : o.pattern))
|
|
492
499
|
return (b = this._configService.getConfig(se)) != null && b.disableTextFormatMark ? (t.t = M.STRING, s(t)) : (t.t = M.STRING, t.markers = { ...t == null ? void 0 : t.markers, ...Ze }, s(t));
|
|
493
500
|
let u = "";
|
|
494
|
-
const C =
|
|
501
|
+
const C = r.getValue(n.row, n.col);
|
|
495
502
|
if (C && C.parameters === `${h.v}_${o == null ? void 0 : o.pattern}`)
|
|
496
503
|
return s({ ...t, ...C.result });
|
|
497
504
|
const y = Ge(o == null ? void 0 : o.pattern, Number(h.v), this.locale);
|
|
@@ -502,40 +509,40 @@ let D = class extends me {
|
|
|
502
509
|
const m = (_ = this._themeService.getColorFromTheme(`${y.color}.500`)) != null ? _ : y.color;
|
|
503
510
|
m && (p.interceptorStyle = { cl: { rgb: m } });
|
|
504
511
|
}
|
|
505
|
-
return
|
|
512
|
+
return r.setValue(n.row, n.col, {
|
|
506
513
|
result: p,
|
|
507
514
|
parameters: `${h.v}_${o == null ? void 0 : o.pattern}`
|
|
508
515
|
}), Object.assign(t, p), s(t);
|
|
509
516
|
},
|
|
510
517
|
priority: Ee.NUMFMT
|
|
511
518
|
})), this.disposeWithMe(this._commandService.onCommandExecuted((t) => {
|
|
512
|
-
if (t.id ===
|
|
513
|
-
const
|
|
514
|
-
Object.keys(
|
|
515
|
-
|
|
519
|
+
if (t.id === re.id) {
|
|
520
|
+
const n = t.params;
|
|
521
|
+
Object.keys(n.values).forEach((s) => {
|
|
522
|
+
n.values[s].ranges.forEach((l) => {
|
|
516
523
|
N.foreach(l, (o, h) => {
|
|
517
|
-
|
|
524
|
+
r.realDeleteValue(o, h);
|
|
518
525
|
});
|
|
519
526
|
});
|
|
520
527
|
});
|
|
521
528
|
} else if (t.id === G.id) {
|
|
522
|
-
const
|
|
523
|
-
new R(
|
|
524
|
-
|
|
529
|
+
const n = t.params;
|
|
530
|
+
new R(n.cellValue).forValue((s, a) => {
|
|
531
|
+
r.realDeleteValue(s, a);
|
|
525
532
|
});
|
|
526
533
|
}
|
|
527
534
|
})), this.disposeWithMe(
|
|
528
535
|
this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
|
|
529
536
|
Te((t) => {
|
|
530
|
-
var
|
|
531
|
-
return (
|
|
537
|
+
var n;
|
|
538
|
+
return (n = t == null ? void 0 : t.activeSheet$) != null ? n : Ue(null);
|
|
532
539
|
}),
|
|
533
540
|
Oe(1)
|
|
534
|
-
).subscribe(() =>
|
|
541
|
+
).subscribe(() => r.reset())
|
|
535
542
|
);
|
|
536
543
|
}
|
|
537
|
-
setNumfmtLocal(
|
|
538
|
-
this._locale$.next(
|
|
544
|
+
setNumfmtLocal(r) {
|
|
545
|
+
this._locale$.next(r);
|
|
539
546
|
}
|
|
540
547
|
};
|
|
541
548
|
D = Ke([
|
|
@@ -548,14 +555,14 @@ D = Ke([
|
|
|
548
555
|
E(6, ee)
|
|
549
556
|
], D);
|
|
550
557
|
const ze = "SHEET_NUMFMT_PLUGIN";
|
|
551
|
-
var ke = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, qe = (e,
|
|
552
|
-
for (var s =
|
|
558
|
+
var ke = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, qe = (e, r, t) => r in e ? ke(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, Xe = (e, r, t, n) => {
|
|
559
|
+
for (var s = n > 1 ? void 0 : n ? Ye(r, t) : r, a = e.length - 1, l; a >= 0; a--)
|
|
553
560
|
(l = e[a]) && (s = l(s) || s);
|
|
554
561
|
return s;
|
|
555
|
-
}, B = (e,
|
|
562
|
+
}, B = (e, r) => (t, n) => r(t, n, e), oe = (e, r, t) => qe(e, typeof r != "symbol" ? r + "" : r, t);
|
|
556
563
|
let A = class extends he {
|
|
557
|
-
constructor(e = X,
|
|
558
|
-
super(), this._config = e, this._injector =
|
|
564
|
+
constructor(e = X, r, t, n) {
|
|
565
|
+
super(), this._config = e, this._injector = r, this._configService = t, this._commandService = n;
|
|
559
566
|
const { ...s } = pe(
|
|
560
567
|
{},
|
|
561
568
|
X,
|
|
@@ -590,10 +597,10 @@ A = Xe([
|
|
|
590
597
|
B(2, ee),
|
|
591
598
|
B(3, $)
|
|
592
599
|
], A);
|
|
593
|
-
const ot = (e) =>
|
|
594
|
-
label:
|
|
595
|
-
value:
|
|
596
|
-
color:
|
|
600
|
+
const ot = (e) => ne.find((t) => e.includes(t)), at = () => ne.map((e) => ({ label: e, value: e })), it = (e) => Ae.map((r) => ({
|
|
601
|
+
label: r.label(e),
|
|
602
|
+
value: r.suffix(e),
|
|
603
|
+
color: r.color
|
|
597
604
|
})), ct = () => Fe.map((e) => ({ label: e.label, value: e.suffix })), lt = () => De.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
598
605
|
export {
|
|
599
606
|
Ve as AddDecimalCommand,
|
|
@@ -607,7 +614,7 @@ export {
|
|
|
607
614
|
D as SheetsNumfmtCellContentController,
|
|
608
615
|
Be as SubtractDecimalCommand,
|
|
609
616
|
A as UniverSheetsNumfmtPlugin,
|
|
610
|
-
|
|
617
|
+
ne as currencySymbols,
|
|
611
618
|
Pe as getCurrencyFormat,
|
|
612
619
|
it as getCurrencyFormatOptions,
|
|
613
620
|
at as getCurrencyOptions,
|
|
@@ -621,7 +628,7 @@ export {
|
|
|
621
628
|
He as getPatternPreview,
|
|
622
629
|
Ge as getPatternPreviewIgnoreGeneral,
|
|
623
630
|
st as getPatternType,
|
|
624
|
-
|
|
631
|
+
nt as isPatternHasDecimal,
|
|
625
632
|
w as localeCurrencySymbolMap,
|
|
626
633
|
F as setPatternDecimal
|
|
627
634
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var ae = Object.defineProperty;
|
|
2
|
-
var ie = (e,
|
|
3
|
-
var L = (e,
|
|
2
|
+
var ie = (e, r, t) => r in e ? ae(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
|
|
3
|
+
var L = (e, r, t) => ie(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
4
|
import { LocaleType as f, numfmt as x, CommandType as U, ICommandService as $, IUniverInstanceService as V, IUndoRedoService as ce, isTextFormat as J, CellValueType as M, ObjectMatrix as R, sequenceExecute as le, Range as N, isDefaultFormat as W, LocaleService as Q, DEFAULT_NUMBER_FORMAT as ue, Inject as I, ThemeService as fe, IConfigService as ee, Disposable as me, InterceptorEffectEnum as z, UniverInstanceType as te, DependentOn as de, Injector as ge, Plugin as he, merge as pe, registerDependencies as _e, touchDependencies as ve } from "@univerjs/core";
|
|
5
|
-
import { getSheetCommandTarget as K, transformCellsToRange as Se, checkCellValueType as H, rangeMerge as k, SetNumfmtMutation as
|
|
5
|
+
import { getSheetCommandTarget as K, transformCellsToRange as Se, checkCellValueType as H, rangeMerge as k, SetNumfmtMutation as re, factorySetNumfmtUndoMutation as Ce, RemoveNumfmtMutation as ye, SetRangeValuesMutation as G, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as Z, SheetInterceptorService as Me, INTERCEPTOR_POINT as Re, InterceptCellContentPriority as Ee, UniverSheetsPlugin as Ne } from "@univerjs/sheets";
|
|
6
6
|
import { BehaviorSubject as $e, merge as Ie, switchMap as Te, of as Ue, skip as Oe } from "rxjs";
|
|
7
7
|
import { stripErrorMargin as we } from "@univerjs/engine-formula";
|
|
8
|
-
const
|
|
8
|
+
const ne = [
|
|
9
9
|
"$",
|
|
10
10
|
"£",
|
|
11
11
|
"¥",
|
|
@@ -80,11 +80,11 @@ function xe(e) {
|
|
|
80
80
|
function Y(e) {
|
|
81
81
|
return w.get(e) || "$";
|
|
82
82
|
}
|
|
83
|
-
function Pe(e,
|
|
84
|
-
let t =
|
|
85
|
-
|
|
86
|
-
let
|
|
87
|
-
return t > 0 && (
|
|
83
|
+
function Pe(e, r = 2) {
|
|
84
|
+
let t = r;
|
|
85
|
+
r > 127 && (t = 127);
|
|
86
|
+
let n = "";
|
|
87
|
+
return t > 0 && (n = `.${"0".repeat(t)}`), `"${Y(e)}"#,##0${n}_);[Red]("${Y(e)}"#,##0${n})`;
|
|
88
88
|
}
|
|
89
89
|
const Fe = [
|
|
90
90
|
{
|
|
@@ -187,25 +187,25 @@ const Fe = [
|
|
|
187
187
|
suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
|
|
188
188
|
color: "red"
|
|
189
189
|
}
|
|
190
|
-
], P = (e,
|
|
191
|
-
var
|
|
192
|
-
return e && (
|
|
193
|
-
}, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), F = (e,
|
|
190
|
+
], P = (e, r = 0) => {
|
|
191
|
+
var n;
|
|
192
|
+
return e && (n = x.getFormatInfo(e).maxDecimals) != null ? n : r;
|
|
193
|
+
}, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), F = (e, r) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
|
|
194
194
|
/\.0*/g,
|
|
195
|
-
`${
|
|
196
|
-
) : /0([^0]?)|0$/.test(
|
|
195
|
+
`${r > 0 ? "." : ""}${q(Number(r || 0))}`
|
|
196
|
+
) : /0([^0]?)|0$/.test(n) ? n.replace(
|
|
197
197
|
/0([^0]+)|0$/,
|
|
198
|
-
`0${
|
|
199
|
-
) :
|
|
198
|
+
`0${r > 0 ? "." : ""}${q(Number(r || 0))}$1`
|
|
199
|
+
) : n).join(";"), nt = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), O = {
|
|
200
200
|
id: "sheet.command.numfmt.set.numfmt",
|
|
201
201
|
type: U.COMMAND,
|
|
202
202
|
// eslint-disable-next-line max-lines-per-function
|
|
203
|
-
handler: (e,
|
|
204
|
-
if (!
|
|
203
|
+
handler: (e, r) => {
|
|
204
|
+
if (!r)
|
|
205
205
|
return !1;
|
|
206
|
-
const t = e.get($),
|
|
206
|
+
const t = e.get($), n = e.get(V), s = e.get(ce), a = K(n, r);
|
|
207
207
|
if (!a) return !1;
|
|
208
|
-
const { unitId: l, subUnitId: o, worksheet: h } = a, u =
|
|
208
|
+
const { unitId: l, subUnitId: o, worksheet: h } = a, u = r.values.filter((i) => !!i.pattern), C = r.values.filter((i) => !i.pattern), y = Se(l, o, u), p = {
|
|
209
209
|
unitId: l,
|
|
210
210
|
subUnitId: o,
|
|
211
211
|
ranges: C.map((i) => ({
|
|
@@ -232,7 +232,7 @@ const Fe = [
|
|
|
232
232
|
const c = y.values[d];
|
|
233
233
|
c.ranges = k(c.ranges);
|
|
234
234
|
}), b.push({
|
|
235
|
-
id:
|
|
235
|
+
id: re.id,
|
|
236
236
|
params: y
|
|
237
237
|
});
|
|
238
238
|
const v = Ce(e, y);
|
|
@@ -283,7 +283,7 @@ const Fe = [
|
|
|
283
283
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
284
284
|
type: U.COMMAND,
|
|
285
285
|
handler: async (e) => {
|
|
286
|
-
const
|
|
286
|
+
const r = e.get($), t = e.get(j), n = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
|
|
287
287
|
if (!a || !a.length)
|
|
288
288
|
return !1;
|
|
289
289
|
const l = K(s);
|
|
@@ -292,7 +292,7 @@ const Fe = [
|
|
|
292
292
|
let u = 0;
|
|
293
293
|
a.forEach((b) => {
|
|
294
294
|
N.foreach(b.range, (_, m) => {
|
|
295
|
-
const i =
|
|
295
|
+
const i = n.getValue(o, h, _, m);
|
|
296
296
|
if (!i) {
|
|
297
297
|
const v = l.worksheet.getCellRaw(_, m);
|
|
298
298
|
if (!u && v && v.t === M.NUMBER && v.v) {
|
|
@@ -313,7 +313,7 @@ const Fe = [
|
|
|
313
313
|
const C = u + 1, y = F(`0${C > 0 ? ".0" : ""}`, C), p = [];
|
|
314
314
|
return a.forEach((b) => {
|
|
315
315
|
N.foreach(b.range, (_, m) => {
|
|
316
|
-
const i =
|
|
316
|
+
const i = n.getValue(o, h, _, m);
|
|
317
317
|
if (W(i == null ? void 0 : i.pattern))
|
|
318
318
|
p.push({
|
|
319
319
|
row: _,
|
|
@@ -329,41 +329,41 @@ const Fe = [
|
|
|
329
329
|
});
|
|
330
330
|
}
|
|
331
331
|
});
|
|
332
|
-
}), p.length ? await
|
|
332
|
+
}), p.length ? await r.executeCommand(O.id, { values: p }) : !1;
|
|
333
333
|
}
|
|
334
334
|
}, je = {
|
|
335
335
|
id: "sheet.command.numfmt.set.currency",
|
|
336
336
|
type: U.COMMAND,
|
|
337
337
|
handler: async (e) => {
|
|
338
|
-
const
|
|
338
|
+
const r = e.get($), t = e.get(j), n = e.get(Q), s = t.getCurrentSelections();
|
|
339
339
|
if (!s || !s.length)
|
|
340
340
|
return !1;
|
|
341
|
-
const a = [], l = xe(
|
|
341
|
+
const a = [], l = xe(n.getCurrentLocale()), o = Pe(l.locale);
|
|
342
342
|
return s.forEach((u) => {
|
|
343
343
|
N.foreach(u.range, (C, y) => {
|
|
344
344
|
a.push({ row: C, col: y, pattern: o, type: "currency" });
|
|
345
345
|
});
|
|
346
|
-
}), await
|
|
346
|
+
}), await r.executeCommand(O.id, { values: a });
|
|
347
347
|
}
|
|
348
348
|
}, Le = {
|
|
349
349
|
id: "sheet.command.numfmt.set.percent",
|
|
350
350
|
type: U.COMMAND,
|
|
351
351
|
handler: async (e) => {
|
|
352
|
-
const
|
|
353
|
-
if (!
|
|
352
|
+
const r = e.get($), n = e.get(j).getCurrentSelections();
|
|
353
|
+
if (!n || !n.length)
|
|
354
354
|
return !1;
|
|
355
355
|
const s = [], a = "0%";
|
|
356
|
-
return
|
|
356
|
+
return n.forEach((o) => {
|
|
357
357
|
N.foreach(o.range, (h, u) => {
|
|
358
358
|
s.push({ row: h, col: u, pattern: a, type: "percent" });
|
|
359
359
|
});
|
|
360
|
-
}), await
|
|
360
|
+
}), await r.executeCommand(O.id, { values: s });
|
|
361
361
|
}
|
|
362
362
|
}, Be = {
|
|
363
363
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
364
364
|
type: U.COMMAND,
|
|
365
365
|
handler: async (e) => {
|
|
366
|
-
const
|
|
366
|
+
const r = e.get($), t = e.get(j), n = e.get(Z), s = e.get(V), a = t.getCurrentSelections();
|
|
367
367
|
if (!a || !a.length)
|
|
368
368
|
return !1;
|
|
369
369
|
const l = K(s);
|
|
@@ -372,7 +372,7 @@ const Fe = [
|
|
|
372
372
|
let u = 0;
|
|
373
373
|
a.forEach((_) => {
|
|
374
374
|
N.foreach(_.range, (m, i) => {
|
|
375
|
-
const g =
|
|
375
|
+
const g = n.getValue(o, h, m, i);
|
|
376
376
|
if (!g) {
|
|
377
377
|
const d = l.worksheet.getCellRaw(m, i);
|
|
378
378
|
if (!u && d && d.t === M.NUMBER && d.v) {
|
|
@@ -393,7 +393,7 @@ const Fe = [
|
|
|
393
393
|
const C = u - 1, y = F(`0${C > 0 ? ".0" : "."}`, C), p = [];
|
|
394
394
|
return a.forEach((_) => {
|
|
395
395
|
N.foreach(_.range, (m, i) => {
|
|
396
|
-
const g =
|
|
396
|
+
const g = n.getValue(o, h, m, i);
|
|
397
397
|
if (W(g == null ? void 0 : g.pattern))
|
|
398
398
|
p.push({
|
|
399
399
|
row: m,
|
|
@@ -409,25 +409,32 @@ const Fe = [
|
|
|
409
409
|
});
|
|
410
410
|
}
|
|
411
411
|
});
|
|
412
|
-
}), await
|
|
412
|
+
}), await r.executeCommand(O.id, { values: p });
|
|
413
413
|
}
|
|
414
|
-
}, se = "sheets-numfmt.config", X = {}, st = (e) => x.getFormatInfo(e).type || "unknown", He = (e,
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
414
|
+
}, se = "sheets-numfmt.config", X = {}, st = (e) => x.getFormatInfo(e).type || "unknown", He = (e, r, t = "en") => {
|
|
415
|
+
try {
|
|
416
|
+
const n = x.formatColor(e, r), s = n ? String(n) : void 0, a = x.format(e, r, { locale: t, throws: !1 });
|
|
417
|
+
return r < 0 ? {
|
|
418
|
+
result: a,
|
|
419
|
+
color: s
|
|
420
|
+
} : {
|
|
421
|
+
result: a
|
|
422
|
+
};
|
|
423
|
+
} catch (n) {
|
|
424
|
+
console.warn("getPatternPreview error:", e, n);
|
|
425
|
+
}
|
|
426
|
+
return {
|
|
427
|
+
result: String(r)
|
|
421
428
|
};
|
|
422
|
-
}, Ge = (e,
|
|
423
|
-
result: String(we(
|
|
429
|
+
}, Ge = (e, r, t) => e === ue ? {
|
|
430
|
+
result: String(we(r))
|
|
424
431
|
// In Excel, the default General format also needs to handle numeric precision.
|
|
425
|
-
} : He(e,
|
|
426
|
-
var We = Object.getOwnPropertyDescriptor, Ke = (e,
|
|
427
|
-
for (var s =
|
|
432
|
+
} : He(e, r, t);
|
|
433
|
+
var We = Object.getOwnPropertyDescriptor, Ke = (e, r, t, n) => {
|
|
434
|
+
for (var s = n > 1 ? void 0 : n ? We(r, t) : r, a = e.length - 1, l; a >= 0; a--)
|
|
428
435
|
(l = e[a]) && (s = l(s) || s);
|
|
429
436
|
return s;
|
|
430
|
-
}, E = (e,
|
|
437
|
+
}, E = (e, r) => (t, n) => r(t, n, e);
|
|
431
438
|
const Ze = {
|
|
432
439
|
tl: {
|
|
433
440
|
size: 6,
|
|
@@ -435,16 +442,16 @@ const Ze = {
|
|
|
435
442
|
}
|
|
436
443
|
};
|
|
437
444
|
let D = class extends me {
|
|
438
|
-
constructor(
|
|
445
|
+
constructor(r, t, n, s, a, l, o) {
|
|
439
446
|
super();
|
|
440
447
|
L(this, "_locale$", new $e("en"));
|
|
441
448
|
L(this, "locale$", this._locale$.asObservable());
|
|
442
|
-
this._instanceService =
|
|
449
|
+
this._instanceService = r, this._sheetInterceptorService = t, this._themeService = n, this._commandService = s, this._numfmtService = a, this._localeService = l, this._configService = o, this._initInterceptorCellContent();
|
|
443
450
|
}
|
|
444
451
|
get locale() {
|
|
445
|
-
const
|
|
446
|
-
if (
|
|
447
|
-
return
|
|
452
|
+
const r = this._locale$.getValue();
|
|
453
|
+
if (r)
|
|
454
|
+
return r;
|
|
448
455
|
switch (this._localeService.getCurrentLocale()) {
|
|
449
456
|
case f.FR_FR:
|
|
450
457
|
return "fr";
|
|
@@ -469,29 +476,29 @@ let D = class extends me {
|
|
|
469
476
|
}
|
|
470
477
|
// eslint-disable-next-line max-lines-per-function
|
|
471
478
|
_initInterceptorCellContent() {
|
|
472
|
-
const
|
|
479
|
+
const r = new R();
|
|
473
480
|
this.disposeWithMe(Ie(this._locale$, this._localeService.currentLocale$).subscribe(() => {
|
|
474
|
-
|
|
481
|
+
r.reset();
|
|
475
482
|
})), this.disposeWithMe(this._sheetInterceptorService.intercept(Re.CELL_CONTENT, {
|
|
476
483
|
effect: z.Value | z.Style,
|
|
477
484
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
478
|
-
handler: (t,
|
|
485
|
+
handler: (t, n, s) => {
|
|
479
486
|
var b, _;
|
|
480
487
|
if (!t || t.v === void 0 || t.v === null || t.t === M.BOOLEAN || t.t === M.FORCE_STRING)
|
|
481
488
|
return s(t);
|
|
482
|
-
const a =
|
|
489
|
+
const a = n.unitId, l = n.subUnitId;
|
|
483
490
|
let o;
|
|
484
491
|
if (t != null && t.s) {
|
|
485
|
-
const m =
|
|
492
|
+
const m = n.workbook.getStyles().get(t.s);
|
|
486
493
|
m != null && m.n && (o = m.n);
|
|
487
494
|
}
|
|
488
|
-
if (o || (o = this._numfmtService.getValue(a, l,
|
|
495
|
+
if (o || (o = this._numfmtService.getValue(a, l, n.row, n.col)), W(o == null ? void 0 : o.pattern) || t.t !== M.NUMBER && H(t.v, t.t) !== M.NUMBER)
|
|
489
496
|
return s(t);
|
|
490
497
|
const h = t;
|
|
491
|
-
if ((!t || t ===
|
|
498
|
+
if ((!t || t === n.rawData) && (t = { ...n.rawData }), J(o == null ? void 0 : o.pattern))
|
|
492
499
|
return (b = this._configService.getConfig(se)) != null && b.disableTextFormatMark ? (t.t = M.STRING, s(t)) : (t.t = M.STRING, t.markers = { ...t == null ? void 0 : t.markers, ...Ze }, s(t));
|
|
493
500
|
let u = "";
|
|
494
|
-
const C =
|
|
501
|
+
const C = r.getValue(n.row, n.col);
|
|
495
502
|
if (C && C.parameters === `${h.v}_${o == null ? void 0 : o.pattern}`)
|
|
496
503
|
return s({ ...t, ...C.result });
|
|
497
504
|
const y = Ge(o == null ? void 0 : o.pattern, Number(h.v), this.locale);
|
|
@@ -502,40 +509,40 @@ let D = class extends me {
|
|
|
502
509
|
const m = (_ = this._themeService.getColorFromTheme(`${y.color}.500`)) != null ? _ : y.color;
|
|
503
510
|
m && (p.interceptorStyle = { cl: { rgb: m } });
|
|
504
511
|
}
|
|
505
|
-
return
|
|
512
|
+
return r.setValue(n.row, n.col, {
|
|
506
513
|
result: p,
|
|
507
514
|
parameters: `${h.v}_${o == null ? void 0 : o.pattern}`
|
|
508
515
|
}), Object.assign(t, p), s(t);
|
|
509
516
|
},
|
|
510
517
|
priority: Ee.NUMFMT
|
|
511
518
|
})), this.disposeWithMe(this._commandService.onCommandExecuted((t) => {
|
|
512
|
-
if (t.id ===
|
|
513
|
-
const
|
|
514
|
-
Object.keys(
|
|
515
|
-
|
|
519
|
+
if (t.id === re.id) {
|
|
520
|
+
const n = t.params;
|
|
521
|
+
Object.keys(n.values).forEach((s) => {
|
|
522
|
+
n.values[s].ranges.forEach((l) => {
|
|
516
523
|
N.foreach(l, (o, h) => {
|
|
517
|
-
|
|
524
|
+
r.realDeleteValue(o, h);
|
|
518
525
|
});
|
|
519
526
|
});
|
|
520
527
|
});
|
|
521
528
|
} else if (t.id === G.id) {
|
|
522
|
-
const
|
|
523
|
-
new R(
|
|
524
|
-
|
|
529
|
+
const n = t.params;
|
|
530
|
+
new R(n.cellValue).forValue((s, a) => {
|
|
531
|
+
r.realDeleteValue(s, a);
|
|
525
532
|
});
|
|
526
533
|
}
|
|
527
534
|
})), this.disposeWithMe(
|
|
528
535
|
this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
|
|
529
536
|
Te((t) => {
|
|
530
|
-
var
|
|
531
|
-
return (
|
|
537
|
+
var n;
|
|
538
|
+
return (n = t == null ? void 0 : t.activeSheet$) != null ? n : Ue(null);
|
|
532
539
|
}),
|
|
533
540
|
Oe(1)
|
|
534
|
-
).subscribe(() =>
|
|
541
|
+
).subscribe(() => r.reset())
|
|
535
542
|
);
|
|
536
543
|
}
|
|
537
|
-
setNumfmtLocal(
|
|
538
|
-
this._locale$.next(
|
|
544
|
+
setNumfmtLocal(r) {
|
|
545
|
+
this._locale$.next(r);
|
|
539
546
|
}
|
|
540
547
|
};
|
|
541
548
|
D = Ke([
|
|
@@ -548,14 +555,14 @@ D = Ke([
|
|
|
548
555
|
E(6, ee)
|
|
549
556
|
], D);
|
|
550
557
|
const ze = "SHEET_NUMFMT_PLUGIN";
|
|
551
|
-
var ke = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, qe = (e,
|
|
552
|
-
for (var s =
|
|
558
|
+
var ke = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, qe = (e, r, t) => r in e ? ke(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, Xe = (e, r, t, n) => {
|
|
559
|
+
for (var s = n > 1 ? void 0 : n ? Ye(r, t) : r, a = e.length - 1, l; a >= 0; a--)
|
|
553
560
|
(l = e[a]) && (s = l(s) || s);
|
|
554
561
|
return s;
|
|
555
|
-
}, B = (e,
|
|
562
|
+
}, B = (e, r) => (t, n) => r(t, n, e), oe = (e, r, t) => qe(e, typeof r != "symbol" ? r + "" : r, t);
|
|
556
563
|
let A = class extends he {
|
|
557
|
-
constructor(e = X,
|
|
558
|
-
super(), this._config = e, this._injector =
|
|
564
|
+
constructor(e = X, r, t, n) {
|
|
565
|
+
super(), this._config = e, this._injector = r, this._configService = t, this._commandService = n;
|
|
559
566
|
const { ...s } = pe(
|
|
560
567
|
{},
|
|
561
568
|
X,
|
|
@@ -590,10 +597,10 @@ A = Xe([
|
|
|
590
597
|
B(2, ee),
|
|
591
598
|
B(3, $)
|
|
592
599
|
], A);
|
|
593
|
-
const ot = (e) =>
|
|
594
|
-
label:
|
|
595
|
-
value:
|
|
596
|
-
color:
|
|
600
|
+
const ot = (e) => ne.find((t) => e.includes(t)), at = () => ne.map((e) => ({ label: e, value: e })), it = (e) => Ae.map((r) => ({
|
|
601
|
+
label: r.label(e),
|
|
602
|
+
value: r.suffix(e),
|
|
603
|
+
color: r.color
|
|
597
604
|
})), ct = () => Fe.map((e) => ({ label: e.label, value: e.suffix })), lt = () => De.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
598
605
|
export {
|
|
599
606
|
Ve as AddDecimalCommand,
|
|
@@ -607,7 +614,7 @@ export {
|
|
|
607
614
|
D as SheetsNumfmtCellContentController,
|
|
608
615
|
Be as SubtractDecimalCommand,
|
|
609
616
|
A as UniverSheetsNumfmtPlugin,
|
|
610
|
-
|
|
617
|
+
ne as currencySymbols,
|
|
611
618
|
Pe as getCurrencyFormat,
|
|
612
619
|
it as getCurrencyFormatOptions,
|
|
613
620
|
at as getCurrencyOptions,
|
|
@@ -621,7 +628,7 @@ export {
|
|
|
621
628
|
He as getPatternPreview,
|
|
622
629
|
Ge as getPatternPreviewIgnoreGeneral,
|
|
623
630
|
st as getPatternType,
|
|
624
|
-
|
|
631
|
+
nt as isPatternHasDecimal,
|
|
625
632
|
w as localeCurrencySymbolMap,
|
|
626
633
|
F as setPatternDecimal
|
|
627
634
|
};
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(r,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):(r=typeof globalThis<"u"?globalThis:r||self,t(r.UniverSheetsNumfmt={},r.UniverCore,r.UniverSheets,r.rxjs,r.UniverEngineFormula))})(this,(function(r,t,u,N,X){"use strict";var de=Object.defineProperty;var ge=(r,t,u)=>t in r?de(r,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[t]=u;var V=(r,t,u)=>ge(r,typeof t!="symbol"?t+"":t,u);const P=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function j(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function A(e,a=2){let i=a;a>127&&(i=127);let n="";return i>0&&(n=`.${"0".repeat(i)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const B=[{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"}],H=[{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"}],U=(e,a=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:a},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,a)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${L(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${L(Number(a||0))}$1`):n).join(";"),J=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),I={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,a)=>{if(!a)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=u.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:o}=l,f=a.values.filter(c=>!!c.pattern),T=a.values.filter(c=>!c.pattern),M=u.transformCellsToRange(m,S,f),y={unitId:m,subUnitId:S,ranges:T.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},b=[],p=[];if(f.length){const c=f.reduce((g,d)=>{t.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.CellValueType.STRING});const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=u.rangeMerge(d.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const h=u.factorySetNumfmtUndoMutation(e,M);p.push(...h)}if(T.length){y.ranges=u.rangeMerge(y.ranges);const c=T.reduce((g,d)=>{const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const h=u.factoryRemoveNumfmtUndoMutation(e,y);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:v.getMatrix()}},...h)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),C}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(!c){const h=m.worksheet.getCellRaw(p,C);if(!f&&h&&h.t===t.CellValueType.NUMBER&&h.v){const g=/\.(\d*)$/.exec(String(h.v));if(g){const d=g[1].length;if(!d)return;f=Math.max(f,d)}}return}const v=U(c.pattern);f=v>f?v:f})});const T=f+1,M=$(`0${T>0?".0":""}`,T),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(t.isDefaultFormat(c==null?void 0:c.pattern))y.push({row:p,col:C,pattern:M});else{const v=U(c.pattern),h=$(c.pattern,v+1);h!==c.pattern&&y.push({row:p,col:C,pattern:h})}})}),y.length?await a.executeCommand(I.id,{values:y}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(t.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=j(n.getCurrentLocale()),S=A(m.locale);return s.forEach(f=>{t.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(I.id,{values:l})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(o,f)=>{s.push({row:o,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(I.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(!v){const g=m.worksheet.getCellRaw(C,c);if(!f&&g&&g.t===t.CellValueType.NUMBER&&g.v){const d=/\.(\d*)$/.exec(String(g.v));if(d){const _=d[1].length;if(!_)return;f=Math.max(f,_)}}return}const h=U(v.pattern);f=h>f?h:f})});const T=f-1,M=$(`0${T>0?".0":"."}`,T),y=[];return l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(t.isDefaultFormat(v==null?void 0:v.pattern))y.push({row:C,col:c,pattern:M});else{const h=U(v.pattern);y.push({row:C,col:c,pattern:$(v.pattern,h-1)})}})}),await a.executeCommand(I.id,{values:y})}},D="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,i="en")=>{const n=t.numfmt.formatColor(e,a),s=n?String(n):void 0,l=t.numfmt.format(e,a,{locale:i,throws:!1});return a<0?{result:l,color:s}:{result:l}},Y=(e,a,i)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(X.stripErrorMargin(a))}:k(e,a,i);var ee=Object.getOwnPropertyDescriptor,te=(e,a,i,n)=>{for(var s=n>1?void 0:n?ee(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},R=(e,a)=>(i,n)=>a(i,n,e);const ne={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,o){super();V(this,"_locale$",new N.BehaviorSubject("en"));V(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=o,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(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,C;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return l(n);const m=s.unitId,S=s.subUnitId;let o;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(o=c.n)}if(o||(o=this._numfmtService.getValue(m,S,s.row,s.col)),t.isDefaultFormat(o==null?void 0:o.pattern)||n.t!==t.CellValueType.NUMBER&&u.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(o==null?void 0:o.pattern))return(p=this._configService.getConfig(D))!=null&&p.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 T="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${o==null?void 0:o.pattern}`)return l({...n,...M.result});const y=Y(o==null?void 0:o.pattern,Number(f.v),this.locale);if(T=y.result,!T)return l(n);const b={v:T,t:t.CellValueType.NUMBER};if(y.color){const c=(C=this._themeService.getColorFromTheme(`${y.color}.500`))!=null?C:y.color;c&&(b.interceptorStyle={cl:{rgb:c}})}return i.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${o==null?void 0:o.pattern}`}),Object.assign(n,b),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(o,f)=>{i.realDeleteValue(o,f)})})})}else if(n.id===u.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(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},r.SheetsNumfmtCellContentController=te([R(0,t.IUniverInstanceService),R(1,t.Inject(u.SheetInterceptorService)),R(2,t.Inject(t.ThemeService)),R(3,t.Inject(t.ICommandService)),R(4,t.Inject(u.INumfmtService)),R(5,t.Inject(t.LocaleService)),R(6,t.IConfigService)],r.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var re=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,a,i)=>a in e?re(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,le=(e,a,i,n)=>{for(var s=n>1?void 0:n?ie(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},w=(e,a)=>(i,n)=>a(i,n,e),z=(e,a,i)=>se(e,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,i,n,s){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},Z,this._config);this._configService.setConfig(D,l)}onStarting(){t.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]])}onRendered(){[x,q,W,K,I].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},z(r.UniverSheetsNumfmtPlugin,"pluginName",ae),z(r.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),w(1,t.Inject(t.Injector)),w(2,t.IConfigService),w(3,t.ICommandService)],r.UniverSheetsNumfmtPlugin);const ce=e=>P.find(i=>e.includes(i)),oe=()=>P.map(e=>({label:e,value:e})),ue=e=>H.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),me=()=>B.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=H,r.DATEFMTLISG=B,r.NUMBERFORMAT=G,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,r.SetCurrencyCommand=W,r.SetNumfmtCommand=I,r.SetPercentCommand=K,r.SubtractDecimalCommand=q,r.currencySymbols=P,r.getCurrencyFormat=A,r.getCurrencyFormatOptions=ue,r.getCurrencyOptions=oe,r.getCurrencySymbolByLocale=F,r.getCurrencySymbolIconByLocale=j,r.getCurrencyType=ce,r.getDateFormatOptions=me,r.getDecimalFromPattern=U,r.getDecimalString=L,r.getNumberFormatOptions=fe,r.getPatternPreview=k,r.getPatternPreviewIgnoreGeneral=Y,r.getPatternType=Q,r.isPatternHasDecimal=J,r.localeCurrencySymbolMap=E,r.setPatternDecimal=$,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(r,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):(r=typeof globalThis<"u"?globalThis:r||self,t(r.UniverSheetsNumfmt={},r.UniverCore,r.UniverSheets,r.rxjs,r.UniverEngineFormula))})(this,(function(r,t,u,N,X){"use strict";var de=Object.defineProperty;var ge=(r,t,u)=>t in r?de(r,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[t]=u;var V=(r,t,u)=>ge(r,typeof t!="symbol"?t+"":t,u);const P=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function j(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function A(e,a=2){let i=a;a>127&&(i=127);let n="";return i>0&&(n=`.${"0".repeat(i)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const B=[{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"}],H=[{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"}],U=(e,a=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:a},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,a)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${L(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${L(Number(a||0))}$1`):n).join(";"),J=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),I={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,a)=>{if(!a)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=u.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:o}=l,f=a.values.filter(c=>!!c.pattern),T=a.values.filter(c=>!c.pattern),M=u.transformCellsToRange(m,S,f),y={unitId:m,subUnitId:S,ranges:T.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},b=[],p=[];if(f.length){const c=f.reduce((g,d)=>{t.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.CellValueType.STRING});const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=u.rangeMerge(d.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const h=u.factorySetNumfmtUndoMutation(e,M);p.push(...h)}if(T.length){y.ranges=u.rangeMerge(y.ranges);const c=T.reduce((g,d)=>{const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const h=u.factoryRemoveNumfmtUndoMutation(e,y);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:v.getMatrix()}},...h)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),C}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(!c){const h=m.worksheet.getCellRaw(p,C);if(!f&&h&&h.t===t.CellValueType.NUMBER&&h.v){const g=/\.(\d*)$/.exec(String(h.v));if(g){const d=g[1].length;if(!d)return;f=Math.max(f,d)}}return}const v=U(c.pattern);f=v>f?v:f})});const T=f+1,M=$(`0${T>0?".0":""}`,T),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(t.isDefaultFormat(c==null?void 0:c.pattern))y.push({row:p,col:C,pattern:M});else{const v=U(c.pattern),h=$(c.pattern,v+1);h!==c.pattern&&y.push({row:p,col:C,pattern:h})}})}),y.length?await a.executeCommand(I.id,{values:y}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(t.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=j(n.getCurrentLocale()),S=A(m.locale);return s.forEach(f=>{t.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(I.id,{values:l})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(o,f)=>{s.push({row:o,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(I.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(!v){const g=m.worksheet.getCellRaw(C,c);if(!f&&g&&g.t===t.CellValueType.NUMBER&&g.v){const d=/\.(\d*)$/.exec(String(g.v));if(d){const _=d[1].length;if(!_)return;f=Math.max(f,_)}}return}const h=U(v.pattern);f=h>f?h:f})});const T=f-1,M=$(`0${T>0?".0":"."}`,T),y=[];return l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(t.isDefaultFormat(v==null?void 0:v.pattern))y.push({row:C,col:c,pattern:M});else{const h=U(v.pattern);y.push({row:C,col:c,pattern:$(v.pattern,h-1)})}})}),await a.executeCommand(I.id,{values:y})}},D="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,i="en")=>{try{const n=t.numfmt.formatColor(e,a),s=n?String(n):void 0,l=t.numfmt.format(e,a,{locale:i,throws:!1});return a<0?{result:l,color:s}:{result:l}}catch(n){console.warn("getPatternPreview error:",e,n)}return{result:String(a)}},Y=(e,a,i)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(X.stripErrorMargin(a))}:k(e,a,i);var ee=Object.getOwnPropertyDescriptor,te=(e,a,i,n)=>{for(var s=n>1?void 0:n?ee(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},R=(e,a)=>(i,n)=>a(i,n,e);const ne={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,o){super();V(this,"_locale$",new N.BehaviorSubject("en"));V(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=o,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(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,C;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return l(n);const m=s.unitId,S=s.subUnitId;let o;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(o=c.n)}if(o||(o=this._numfmtService.getValue(m,S,s.row,s.col)),t.isDefaultFormat(o==null?void 0:o.pattern)||n.t!==t.CellValueType.NUMBER&&u.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(o==null?void 0:o.pattern))return(p=this._configService.getConfig(D))!=null&&p.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 T="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${o==null?void 0:o.pattern}`)return l({...n,...M.result});const y=Y(o==null?void 0:o.pattern,Number(f.v),this.locale);if(T=y.result,!T)return l(n);const b={v:T,t:t.CellValueType.NUMBER};if(y.color){const c=(C=this._themeService.getColorFromTheme(`${y.color}.500`))!=null?C:y.color;c&&(b.interceptorStyle={cl:{rgb:c}})}return i.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${o==null?void 0:o.pattern}`}),Object.assign(n,b),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(o,f)=>{i.realDeleteValue(o,f)})})})}else if(n.id===u.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(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},r.SheetsNumfmtCellContentController=te([R(0,t.IUniverInstanceService),R(1,t.Inject(u.SheetInterceptorService)),R(2,t.Inject(t.ThemeService)),R(3,t.Inject(t.ICommandService)),R(4,t.Inject(u.INumfmtService)),R(5,t.Inject(t.LocaleService)),R(6,t.IConfigService)],r.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var re=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,a,i)=>a in e?re(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,le=(e,a,i,n)=>{for(var s=n>1?void 0:n?ie(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},w=(e,a)=>(i,n)=>a(i,n,e),z=(e,a,i)=>se(e,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,i,n,s){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},Z,this._config);this._configService.setConfig(D,l)}onStarting(){t.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]])}onRendered(){[x,q,W,K,I].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},z(r.UniverSheetsNumfmtPlugin,"pluginName",ae),z(r.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),w(1,t.Inject(t.Injector)),w(2,t.IConfigService),w(3,t.ICommandService)],r.UniverSheetsNumfmtPlugin);const ce=e=>P.find(i=>e.includes(i)),oe=()=>P.map(e=>({label:e,value:e})),ue=e=>H.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),me=()=>B.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=H,r.DATEFMTLISG=B,r.NUMBERFORMAT=G,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,r.SetCurrencyCommand=W,r.SetNumfmtCommand=I,r.SetPercentCommand=K,r.SubtractDecimalCommand=q,r.currencySymbols=P,r.getCurrencyFormat=A,r.getCurrencyFormatOptions=ue,r.getCurrencyOptions=oe,r.getCurrencySymbolByLocale=F,r.getCurrencySymbolIconByLocale=j,r.getCurrencyType=ce,r.getDateFormatOptions=me,r.getDecimalFromPattern=U,r.getDecimalString=L,r.getNumberFormatOptions=fe,r.getPatternPreview=k,r.getPatternPreviewIgnoreGeneral=Y,r.getPatternType=Q,r.isPatternHasDecimal=J,r.localeCurrencySymbolMap=E,r.setPatternDecimal=$,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2-experimental.20251129-0fa20cd",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -58,16 +58,16 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/core": "0.12.
|
|
62
|
-
"@univerjs/engine-formula": "0.12.
|
|
63
|
-
"@univerjs/sheets": "0.12.
|
|
61
|
+
"@univerjs/core": "0.12.2-experimental.20251129-0fa20cd",
|
|
62
|
+
"@univerjs/engine-formula": "0.12.2-experimental.20251129-0fa20cd",
|
|
63
|
+
"@univerjs/sheets": "0.12.2-experimental.20251129-0fa20cd"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"rxjs": "^7.8.2",
|
|
67
67
|
"typescript": "^5.9.3",
|
|
68
|
-
"vite": "^7.2.
|
|
69
|
-
"vitest": "^
|
|
70
|
-
"@univerjs-infra/shared": "0.12.
|
|
68
|
+
"vite": "^7.2.4",
|
|
69
|
+
"vitest": "^4.0.14",
|
|
70
|
+
"@univerjs-infra/shared": "0.12.2"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"test": "vitest run",
|