@univerjs/sheets-numfmt 0.9.2-nightly.202507131606 → 0.9.2-nightly.202507141607
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 +58 -57
- package/lib/index.js +58 -57
- 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=[],v=[];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 p=m.factorySetNumfmtUndoMutation(e,b);v.push(...p)}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 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}},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,(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 _=i+1,b=O(`0${_>0?".0":""}`,_),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:b});else{const C=E(c.pattern),p=O(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 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(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 _=i-1,b=O(`0${_>0?".0":"."}`,_),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:b});else{const p=E(C.pattern);h.push({row:S,col:c,pattern:O(C.pattern,p-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,"_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.KO_KR:return"ko";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}),t.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,...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.local);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._local$.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,9 +1,8 @@
|
|
|
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 T, IUniverInstanceService as A, IUndoRedoService as ue,
|
|
5
|
-
import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as
|
|
6
|
-
import { isTextFormat as re } from "@univerjs/engine-numfmt";
|
|
3
|
+
var R = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { numfmt as w, CommandType as V, ICommandService as T, IUniverInstanceService as A, IUndoRedoService as ue, isTextFormat as X, CellValueType as $, ObjectMatrix as M, sequenceExecute as me, Range as I, Inject as E, 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 pe, merge as ve, registerDependencies as Se, 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";
|
|
7
6
|
import { BehaviorSubject as K, merge as Ie, switchMap as Te, of as Ee, skip as xe } from "rxjs";
|
|
8
7
|
import { stripErrorMargin as Ve } from "@univerjs/engine-formula";
|
|
9
8
|
const ne = [
|
|
@@ -178,13 +177,13 @@ 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
|
|
@@ -205,29 +204,29 @@ const ne = [
|
|
|
205
204
|
}, C = [], p = [];
|
|
206
205
|
if (u.length) {
|
|
207
206
|
const l = u.reduce((d, c) => {
|
|
208
|
-
|
|
207
|
+
X(c.pattern) && d.setValue(c.row, c.col, { t: $.STRING });
|
|
209
208
|
const S = f.getCellRaw(c.row, c.col);
|
|
210
209
|
if (S) {
|
|
211
210
|
const x = G(S.v);
|
|
212
211
|
x !== S.t && d.setValue(c.row, c.col, { t: x });
|
|
213
212
|
}
|
|
214
213
|
return d;
|
|
215
|
-
}, new
|
|
216
|
-
new
|
|
214
|
+
}, new M()).getMatrix(), h = new M();
|
|
215
|
+
new M(l).forValue((d, c) => {
|
|
217
216
|
const S = f.getCellRaw(d, c);
|
|
218
217
|
S ? h.setValue(d, c, { t: S.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
225
|
const v = _e(e, _);
|
|
227
226
|
p.push(...v);
|
|
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
231
|
const S = f.getCellRaw(c.row, c.col);
|
|
233
232
|
if (S) {
|
|
@@ -235,8 +234,8 @@ const ne = [
|
|
|
235
234
|
x !== S.t && d.setValue(c.row, c.col, { t: x });
|
|
236
235
|
}
|
|
237
236
|
return d;
|
|
238
|
-
}, new
|
|
239
|
-
new
|
|
237
|
+
}, new M()).getMatrix(), h = new M();
|
|
238
|
+
new M(l).forValue((d, c) => {
|
|
240
239
|
const S = f.getCellRaw(d, c);
|
|
241
240
|
S ? h.setValue(d, c, { t: S.t }) : h.setValue(d, c, { t: void 0 });
|
|
242
241
|
}), C.push({
|
|
@@ -283,7 +282,7 @@ const ne = [
|
|
|
283
282
|
const l = n.getValue(i, f, p, m);
|
|
284
283
|
if (!l) {
|
|
285
284
|
const v = a.worksheet.getCellRaw(p, m);
|
|
286
|
-
if (!u && v && v.t ===
|
|
285
|
+
if (!u && v && v.t === $.NUMBER && v.v) {
|
|
287
286
|
const d = /\.(\d*)$/.exec(String(v.v));
|
|
288
287
|
if (d) {
|
|
289
288
|
const c = d[1].length;
|
|
@@ -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.
|
|
@@ -379,7 +378,7 @@ const De = {
|
|
|
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
384
|
const S = c[1].length;
|
|
@@ -415,7 +414,7 @@ const De = {
|
|
|
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,11 +437,11 @@ 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, "_local$", new K("en"));
|
|
444
|
+
R(this, "local$", this._local$.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
447
|
get local() {
|
|
@@ -450,25 +449,27 @@ let D = class extends Q {
|
|
|
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.EN_US:
|
|
465
|
+
case b.FA_IR:
|
|
465
466
|
default:
|
|
466
467
|
return "en";
|
|
467
468
|
}
|
|
468
469
|
}
|
|
469
470
|
// eslint-disable-next-line max-lines-per-function
|
|
470
471
|
_initInterceptorCellContent() {
|
|
471
|
-
const t = new
|
|
472
|
+
const t = new M();
|
|
472
473
|
this.disposeWithMe(Ie(this._local$, this._localeService.currentLocale$).subscribe(() => {
|
|
473
474
|
t.reset();
|
|
474
475
|
})), this.disposeWithMe(this._sheetInterceptorService.intercept($e.CELL_CONTENT, {
|
|
@@ -485,10 +486,10 @@ let D = class extends Q {
|
|
|
485
486
|
const m = n.workbook.getStyles().get(r.s);
|
|
486
487
|
m != null && m.n && (i = m.n);
|
|
487
488
|
}
|
|
488
|
-
if (i || (i = this._numfmtService.getValue(o, a, n.row, n.col)), !i || i.pattern === "General" || f.t !==
|
|
489
|
+
if (i || (i = this._numfmtService.getValue(o, a, n.row, n.col)), !i || i.pattern === "General" || f.t !== $.NUMBER && G(f.v) !== $.NUMBER)
|
|
489
490
|
return s(r);
|
|
490
|
-
if ((!r || r === n.rawData) && (r = { ...n.rawData }),
|
|
491
|
-
return (C = this._configService.getConfig(ae)) != null && C.disableTextFormatMark ? (r.t =
|
|
491
|
+
if ((!r || r === n.rawData) && (r = { ...n.rawData }), X(i.pattern))
|
|
492
|
+
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
493
|
let u = "";
|
|
493
494
|
const y = t.getValue(n.row, n.col);
|
|
494
495
|
if (y && y.parameters === `${f.v}_${i.pattern}`)
|
|
@@ -496,7 +497,7 @@ let D = class extends Q {
|
|
|
496
497
|
const _ = Le(i.pattern, Number(f.v), this.local);
|
|
497
498
|
if (u = _.result, !u)
|
|
498
499
|
return s(r);
|
|
499
|
-
const g = { v: u, t:
|
|
500
|
+
const g = { v: u, t: $.NUMBER };
|
|
500
501
|
if (_.color) {
|
|
501
502
|
const m = (p = this._themeService.getColorFromTheme(`${_.color}.500`)) != null ? p : _.color;
|
|
502
503
|
m && (g.interceptorStyle = { cl: { rgb: m } });
|
|
@@ -508,7 +509,7 @@ let D = class extends Q {
|
|
|
508
509
|
},
|
|
509
510
|
priority: Re.NUMFMT
|
|
510
511
|
})), this.disposeWithMe(this._commandService.onCommandExecuted((r) => {
|
|
511
|
-
if (r.id ===
|
|
512
|
+
if (r.id === re.id) {
|
|
512
513
|
const n = r.params;
|
|
513
514
|
Object.keys(n.values).forEach((s) => {
|
|
514
515
|
n.values[s].ranges.forEach((a) => {
|
|
@@ -519,12 +520,12 @@ let D = class extends Q {
|
|
|
519
520
|
});
|
|
520
521
|
} else if (r.id === B.id) {
|
|
521
522
|
const n = r.params;
|
|
522
|
-
new
|
|
523
|
+
new M(n.cellValue).forValue((s, o) => {
|
|
523
524
|
t.realDeleteValue(s, o);
|
|
524
525
|
});
|
|
525
526
|
}
|
|
526
527
|
})), this.disposeWithMe(
|
|
527
|
-
this._instanceService.getCurrentTypeOfUnit$(
|
|
528
|
+
this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
|
|
528
529
|
Te((r) => {
|
|
529
530
|
var n;
|
|
530
531
|
return (n = r == null ? void 0 : r.activeSheet$) != null ? n : Ee(null);
|
|
@@ -544,14 +545,14 @@ D = Be([
|
|
|
544
545
|
N(3, E(T)),
|
|
545
546
|
N(4, E(W)),
|
|
546
547
|
N(5, E(de)),
|
|
547
|
-
N(6,
|
|
548
|
+
N(6, Q)
|
|
548
549
|
], D);
|
|
549
550
|
const We = "SHEET_NUMFMT_PLUGIN";
|
|
550
|
-
class J extends
|
|
551
|
+
class J extends ee {
|
|
551
552
|
constructor() {
|
|
552
553
|
super(...arguments);
|
|
553
|
-
|
|
554
|
-
|
|
554
|
+
R(this, "_currencySymbol$", new K("US"));
|
|
555
|
+
R(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
555
556
|
}
|
|
556
557
|
/**
|
|
557
558
|
* Set the currency symbol by setting the country code.
|
|
@@ -563,7 +564,7 @@ class J extends Q {
|
|
|
563
564
|
return this._currencySymbol$.getValue();
|
|
564
565
|
}
|
|
565
566
|
}
|
|
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,
|
|
567
|
+
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
568
|
for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, o = e.length - 1, a; o >= 0; o--)
|
|
568
569
|
(a = e[o]) && (s = a(s) || s);
|
|
569
570
|
return s;
|
|
@@ -602,18 +603,18 @@ let F = class extends pe {
|
|
|
602
603
|
}
|
|
603
604
|
};
|
|
604
605
|
ce(F, "pluginName", We);
|
|
605
|
-
ce(F, "type",
|
|
606
|
-
F =
|
|
606
|
+
ce(F, "type", te.UNIVER_SHEET);
|
|
607
|
+
F = ke([
|
|
607
608
|
he(Ne),
|
|
608
609
|
L(1, E(ge)),
|
|
609
|
-
L(2,
|
|
610
|
+
L(2, Q),
|
|
610
611
|
L(3, T)
|
|
611
612
|
], F);
|
|
612
|
-
const
|
|
613
|
+
const rt = (e) => ne.find((r) => e.includes(r)), nt = () => ne.map((e) => ({ label: e, value: e })), st = (e) => se.map((t) => ({
|
|
613
614
|
label: t.label(e),
|
|
614
615
|
value: t.suffix(e),
|
|
615
616
|
color: t.color
|
|
616
|
-
})),
|
|
617
|
+
})), ot = () => we.map((e) => ({ label: e.label, value: e.suffix })), at = () => Oe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
617
618
|
export {
|
|
618
619
|
Pe as AddDecimalCommand,
|
|
619
620
|
se as CURRENCYFORMAT,
|
|
@@ -629,16 +630,16 @@ export {
|
|
|
629
630
|
F as UniverSheetsNumfmtPlugin,
|
|
630
631
|
Ue as countryCurrencyMap,
|
|
631
632
|
ne as currencySymbols,
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
633
|
+
st as getCurrencyFormatOptions,
|
|
634
|
+
nt as getCurrencyOptions,
|
|
635
|
+
rt as getCurrencyType,
|
|
636
|
+
ot as getDateFormatOptions,
|
|
636
637
|
O as getDecimalFromPattern,
|
|
637
|
-
|
|
638
|
-
|
|
638
|
+
Z as getDecimalString,
|
|
639
|
+
at as getNumberFormatOptions,
|
|
639
640
|
je as getPatternPreview,
|
|
640
641
|
Le as getPatternPreviewIgnoreGeneral,
|
|
641
|
-
|
|
642
|
-
|
|
642
|
+
tt as getPatternType,
|
|
643
|
+
et as isPatternHasDecimal,
|
|
643
644
|
P as setPatternDecimal
|
|
644
645
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
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 T, IUniverInstanceService as A, IUndoRedoService as ue,
|
|
5
|
-
import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as
|
|
6
|
-
import { isTextFormat as re } from "@univerjs/engine-numfmt";
|
|
3
|
+
var R = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { numfmt as w, CommandType as V, ICommandService as T, IUniverInstanceService as A, IUndoRedoService as ue, isTextFormat as X, CellValueType as $, ObjectMatrix as M, sequenceExecute as me, Range as I, Inject as E, 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 pe, merge as ve, registerDependencies as Se, 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";
|
|
7
6
|
import { BehaviorSubject as K, merge as Ie, switchMap as Te, of as Ee, skip as xe } from "rxjs";
|
|
8
7
|
import { stripErrorMargin as Ve } from "@univerjs/engine-formula";
|
|
9
8
|
const ne = [
|
|
@@ -178,13 +177,13 @@ 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
|
|
@@ -205,29 +204,29 @@ const ne = [
|
|
|
205
204
|
}, C = [], p = [];
|
|
206
205
|
if (u.length) {
|
|
207
206
|
const l = u.reduce((d, c) => {
|
|
208
|
-
|
|
207
|
+
X(c.pattern) && d.setValue(c.row, c.col, { t: $.STRING });
|
|
209
208
|
const S = f.getCellRaw(c.row, c.col);
|
|
210
209
|
if (S) {
|
|
211
210
|
const x = G(S.v);
|
|
212
211
|
x !== S.t && d.setValue(c.row, c.col, { t: x });
|
|
213
212
|
}
|
|
214
213
|
return d;
|
|
215
|
-
}, new
|
|
216
|
-
new
|
|
214
|
+
}, new M()).getMatrix(), h = new M();
|
|
215
|
+
new M(l).forValue((d, c) => {
|
|
217
216
|
const S = f.getCellRaw(d, c);
|
|
218
217
|
S ? h.setValue(d, c, { t: S.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
225
|
const v = _e(e, _);
|
|
227
226
|
p.push(...v);
|
|
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
231
|
const S = f.getCellRaw(c.row, c.col);
|
|
233
232
|
if (S) {
|
|
@@ -235,8 +234,8 @@ const ne = [
|
|
|
235
234
|
x !== S.t && d.setValue(c.row, c.col, { t: x });
|
|
236
235
|
}
|
|
237
236
|
return d;
|
|
238
|
-
}, new
|
|
239
|
-
new
|
|
237
|
+
}, new M()).getMatrix(), h = new M();
|
|
238
|
+
new M(l).forValue((d, c) => {
|
|
240
239
|
const S = f.getCellRaw(d, c);
|
|
241
240
|
S ? h.setValue(d, c, { t: S.t }) : h.setValue(d, c, { t: void 0 });
|
|
242
241
|
}), C.push({
|
|
@@ -283,7 +282,7 @@ const ne = [
|
|
|
283
282
|
const l = n.getValue(i, f, p, m);
|
|
284
283
|
if (!l) {
|
|
285
284
|
const v = a.worksheet.getCellRaw(p, m);
|
|
286
|
-
if (!u && v && v.t ===
|
|
285
|
+
if (!u && v && v.t === $.NUMBER && v.v) {
|
|
287
286
|
const d = /\.(\d*)$/.exec(String(v.v));
|
|
288
287
|
if (d) {
|
|
289
288
|
const c = d[1].length;
|
|
@@ -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.
|
|
@@ -379,7 +378,7 @@ const De = {
|
|
|
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
384
|
const S = c[1].length;
|
|
@@ -415,7 +414,7 @@ const De = {
|
|
|
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,11 +437,11 @@ 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, "_local$", new K("en"));
|
|
444
|
+
R(this, "local$", this._local$.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
447
|
get local() {
|
|
@@ -450,25 +449,27 @@ let D = class extends Q {
|
|
|
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.EN_US:
|
|
465
|
+
case b.FA_IR:
|
|
465
466
|
default:
|
|
466
467
|
return "en";
|
|
467
468
|
}
|
|
468
469
|
}
|
|
469
470
|
// eslint-disable-next-line max-lines-per-function
|
|
470
471
|
_initInterceptorCellContent() {
|
|
471
|
-
const t = new
|
|
472
|
+
const t = new M();
|
|
472
473
|
this.disposeWithMe(Ie(this._local$, this._localeService.currentLocale$).subscribe(() => {
|
|
473
474
|
t.reset();
|
|
474
475
|
})), this.disposeWithMe(this._sheetInterceptorService.intercept($e.CELL_CONTENT, {
|
|
@@ -485,10 +486,10 @@ let D = class extends Q {
|
|
|
485
486
|
const m = n.workbook.getStyles().get(r.s);
|
|
486
487
|
m != null && m.n && (i = m.n);
|
|
487
488
|
}
|
|
488
|
-
if (i || (i = this._numfmtService.getValue(o, a, n.row, n.col)), !i || i.pattern === "General" || f.t !==
|
|
489
|
+
if (i || (i = this._numfmtService.getValue(o, a, n.row, n.col)), !i || i.pattern === "General" || f.t !== $.NUMBER && G(f.v) !== $.NUMBER)
|
|
489
490
|
return s(r);
|
|
490
|
-
if ((!r || r === n.rawData) && (r = { ...n.rawData }),
|
|
491
|
-
return (C = this._configService.getConfig(ae)) != null && C.disableTextFormatMark ? (r.t =
|
|
491
|
+
if ((!r || r === n.rawData) && (r = { ...n.rawData }), X(i.pattern))
|
|
492
|
+
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
493
|
let u = "";
|
|
493
494
|
const y = t.getValue(n.row, n.col);
|
|
494
495
|
if (y && y.parameters === `${f.v}_${i.pattern}`)
|
|
@@ -496,7 +497,7 @@ let D = class extends Q {
|
|
|
496
497
|
const _ = Le(i.pattern, Number(f.v), this.local);
|
|
497
498
|
if (u = _.result, !u)
|
|
498
499
|
return s(r);
|
|
499
|
-
const g = { v: u, t:
|
|
500
|
+
const g = { v: u, t: $.NUMBER };
|
|
500
501
|
if (_.color) {
|
|
501
502
|
const m = (p = this._themeService.getColorFromTheme(`${_.color}.500`)) != null ? p : _.color;
|
|
502
503
|
m && (g.interceptorStyle = { cl: { rgb: m } });
|
|
@@ -508,7 +509,7 @@ let D = class extends Q {
|
|
|
508
509
|
},
|
|
509
510
|
priority: Re.NUMFMT
|
|
510
511
|
})), this.disposeWithMe(this._commandService.onCommandExecuted((r) => {
|
|
511
|
-
if (r.id ===
|
|
512
|
+
if (r.id === re.id) {
|
|
512
513
|
const n = r.params;
|
|
513
514
|
Object.keys(n.values).forEach((s) => {
|
|
514
515
|
n.values[s].ranges.forEach((a) => {
|
|
@@ -519,12 +520,12 @@ let D = class extends Q {
|
|
|
519
520
|
});
|
|
520
521
|
} else if (r.id === B.id) {
|
|
521
522
|
const n = r.params;
|
|
522
|
-
new
|
|
523
|
+
new M(n.cellValue).forValue((s, o) => {
|
|
523
524
|
t.realDeleteValue(s, o);
|
|
524
525
|
});
|
|
525
526
|
}
|
|
526
527
|
})), this.disposeWithMe(
|
|
527
|
-
this._instanceService.getCurrentTypeOfUnit$(
|
|
528
|
+
this._instanceService.getCurrentTypeOfUnit$(te.UNIVER_SHEET).pipe(
|
|
528
529
|
Te((r) => {
|
|
529
530
|
var n;
|
|
530
531
|
return (n = r == null ? void 0 : r.activeSheet$) != null ? n : Ee(null);
|
|
@@ -544,14 +545,14 @@ D = Be([
|
|
|
544
545
|
N(3, E(T)),
|
|
545
546
|
N(4, E(W)),
|
|
546
547
|
N(5, E(de)),
|
|
547
|
-
N(6,
|
|
548
|
+
N(6, Q)
|
|
548
549
|
], D);
|
|
549
550
|
const We = "SHEET_NUMFMT_PLUGIN";
|
|
550
|
-
class J extends
|
|
551
|
+
class J extends ee {
|
|
551
552
|
constructor() {
|
|
552
553
|
super(...arguments);
|
|
553
|
-
|
|
554
|
-
|
|
554
|
+
R(this, "_currencySymbol$", new K("US"));
|
|
555
|
+
R(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
555
556
|
}
|
|
556
557
|
/**
|
|
557
558
|
* Set the currency symbol by setting the country code.
|
|
@@ -563,7 +564,7 @@ class J extends Q {
|
|
|
563
564
|
return this._currencySymbol$.getValue();
|
|
564
565
|
}
|
|
565
566
|
}
|
|
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,
|
|
567
|
+
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
568
|
for (var s = n > 1 ? void 0 : n ? ze(t, r) : t, o = e.length - 1, a; o >= 0; o--)
|
|
568
569
|
(a = e[o]) && (s = a(s) || s);
|
|
569
570
|
return s;
|
|
@@ -602,18 +603,18 @@ let F = class extends pe {
|
|
|
602
603
|
}
|
|
603
604
|
};
|
|
604
605
|
ce(F, "pluginName", We);
|
|
605
|
-
ce(F, "type",
|
|
606
|
-
F =
|
|
606
|
+
ce(F, "type", te.UNIVER_SHEET);
|
|
607
|
+
F = ke([
|
|
607
608
|
he(Ne),
|
|
608
609
|
L(1, E(ge)),
|
|
609
|
-
L(2,
|
|
610
|
+
L(2, Q),
|
|
610
611
|
L(3, T)
|
|
611
612
|
], F);
|
|
612
|
-
const
|
|
613
|
+
const rt = (e) => ne.find((r) => e.includes(r)), nt = () => ne.map((e) => ({ label: e, value: e })), st = (e) => se.map((t) => ({
|
|
613
614
|
label: t.label(e),
|
|
614
615
|
value: t.suffix(e),
|
|
615
616
|
color: t.color
|
|
616
|
-
})),
|
|
617
|
+
})), ot = () => we.map((e) => ({ label: e.label, value: e.suffix })), at = () => Oe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
617
618
|
export {
|
|
618
619
|
Pe as AddDecimalCommand,
|
|
619
620
|
se as CURRENCYFORMAT,
|
|
@@ -629,16 +630,16 @@ export {
|
|
|
629
630
|
F as UniverSheetsNumfmtPlugin,
|
|
630
631
|
Ue as countryCurrencyMap,
|
|
631
632
|
ne as currencySymbols,
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
633
|
+
st as getCurrencyFormatOptions,
|
|
634
|
+
nt as getCurrencyOptions,
|
|
635
|
+
rt as getCurrencyType,
|
|
636
|
+
ot as getDateFormatOptions,
|
|
636
637
|
O as getDecimalFromPattern,
|
|
637
|
-
|
|
638
|
-
|
|
638
|
+
Z as getDecimalString,
|
|
639
|
+
at as getNumberFormatOptions,
|
|
639
640
|
je as getPatternPreview,
|
|
640
641
|
Le as getPatternPreviewIgnoreGeneral,
|
|
641
|
-
|
|
642
|
-
|
|
642
|
+
tt as getPatternType,
|
|
643
|
+
et as isPatternHasDecimal,
|
|
643
644
|
P as setPatternDecimal
|
|
644
645
|
};
|
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=[],y=[];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(),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 O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}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}},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,(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 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(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})}},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,"_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.KO_KR:return"ko";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}),t.isTextFormat(d.pattern))return(y=this._configService.getConfig(j))!=null&&y.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.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=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.202507141607",
|
|
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.202507141607",
|
|
62
|
+
"@univerjs/engine-formula": "0.9.2-nightly.202507141607",
|
|
63
|
+
"@univerjs/sheets": "0.9.2-nightly.202507141607"
|
|
65
64
|
},
|
|
66
65
|
"devDependencies": {
|
|
67
66
|
"rxjs": "^7.8.2",
|