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