@univerjs/sheets-numfmt 0.5.3 → 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 CHANGED
@@ -1 +1 @@
1
- "use strict";const i=require("@univerjs/sheets-numfmt"),t=require("@univerjs/sheets/facade");class r extends t.FRange{setNumberFormat(s){const e=[];return this.forEach((n,a)=>e.push({row:n,col:a,pattern:s})),this._commandService.syncExecuteCommand(i.SetNumfmtCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),values:e}),this}}t.FRange.extend(r);
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 K=Object.defineProperty;var z=(e,t,n)=>t in e?K(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var N=(e,t,n)=>z(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),d=require("@univerjs/sheets"),$=require("rxjs"),T=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],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:"€"},w=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],A=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],U=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],J="SHEET_NUMFMT_PLUGIN",P=(e,t=0)=>{var r;return e&&(r=s.numfmt.getInfo(e).maxDecimals)!=null?r:t},Z=(e,t)=>{if(e&&!t||!e&&t)return!1;const n=a=>a.reduce((f,S)=>{if(f.isEnd)return f;const g=S.value||S.num;return S.type==="point"?(f.isEnd=!0,f):{...f,result:f.result+g}},{isEnd:!1,result:""}).result,r=s.numfmt.getInfo(e)._partitions,o=s.numfmt.getInfo(t)._partitions,c=n(r[0].tokens),i=n(o[0].tokens),l=n(r[1].tokens),m=n(o[1].tokens);return c===i&&l===m&&r[1].color===o[1].color},E=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),R=(e,t)=>e.split(";").map(r=>/\.0?/.test(r)?r.replace(/\.0*/g,`${t>0?".":""}${E(Number(t||0))}`):/0([^0]?)|0$/.test(r)?r.replace(/0([^0]+)|0$/,`0${t>0?".":""}${E(Number(t||0))}$1`):r).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),M={id:"sheet.command.numfmt.set.numfmt",type:s.CommandType.COMMAND,handler:(e,t)=>{if(!t)return!1;const n=e.get(s.ICommandService),r=e.get(s.IUniverInstanceService),o=e.get(s.IUndoRedoService),c=d.getSheetCommandTarget(r,t);if(!c)return!1;const{unitId:i,subUnitId:l}=c,m=t.values.filter(u=>!!u.pattern),a=t.values.filter(u=>!u.pattern),f=d.transformCellsToRange(i,l,m),S={unitId:i,subUnitId:l,ranges:a.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},g=[],h=[];if(m.length){Object.keys(f.values).forEach(v=>{const C=f.values[v];C.ranges=d.rangeMerge(C.ranges)}),g.push({id:d.SetNumfmtMutation.id,params:f});const u=d.factorySetNumfmtUndoMutation(e,f);h.push(...u)}if(a.length){S.ranges=d.rangeMerge(S.ranges),g.push({id:d.RemoveNumfmtMutation.id,params:S});const u=d.factoryRemoveNumfmtUndoMutation(e,S);h.push(...u)}const p=s.sequenceExecute(g,n).result;return p&&o.pushUndoRedo({unitID:i,undoMutations:h,redoMutations:g}),p}},F={id:"sheet.command.numfmt.add.decimal.command",type:s.CommandType.COMMAND,handler:async e=>{const t=e.get(s.ICommandService),n=e.get(d.SheetsSelectionsService),r=e.get(d.INumfmtService),o=e.get(s.IUniverInstanceService),c=n.getCurrentSelections();if(!c||!c.length)return!1;const i=d.getSheetCommandTarget(o);if(!i)return!1;const{unitId:l,subUnitId:m}=i;let a=0;c.forEach(h=>{s.Range.foreach(h.range,(p,u)=>{const v=r.getValue(l,m,p,u);if(!v){const y=i.worksheet.getCellRaw(p,u);if(!a&&y&&y.t===s.CellValueType.NUMBER&&y.v){const b=/\.(\d*)$/.exec(String(y.v));if(b){const I=b[1].length;if(!I)return;a=Math.max(a,I)}}return}const C=P(v.pattern);a=C>a?C:a})});const f=a+1,S=R(`0${f>0?".0":""}`,f),g=[];return c.forEach(h=>{s.Range.foreach(h.range,(p,u)=>{const v=r.getValue(l,m,p,u);if(!v)g.push({row:p,col:u,pattern:S});else{const C=P(v.pattern),y=R(v.pattern,C+1);y!==v.pattern&&g.push({row:p,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:s.CommandType.COMMAND,handler:async e=>{const t=e.get(s.ICommandService),n=e.get(d.SheetsSelectionsService),r=e.get(D),o=j[r.getCurrencySymbol()]||"$",c=n.getCurrentSelections();if(!c||!c.length)return!1;const i=[],l=U[4].suffix(o);return c.forEach(a=>{s.Range.foreach(a.range,(f,S)=>{i.push({row:f,col:S,pattern:l,type:"currency"})})}),await t.executeCommand(M.id,{values:i})}},L={id:"sheet.command.numfmt.set.percent",type:s.CommandType.COMMAND,handler:async e=>{const t=e.get(s.ICommandService),r=e.get(d.SheetsSelectionsService).getCurrentSelections();if(!r||!r.length)return!1;const o=[],c="0%";return r.forEach(l=>{s.Range.foreach(l.range,(m,a)=>{o.push({row:m,col:a,pattern:c,type:"percent"})})}),await t.executeCommand(M.id,{values:o})}},G={id:"sheet.command.numfmt.subtract.decimal.command",type:s.CommandType.COMMAND,handler:async e=>{const t=e.get(s.ICommandService),n=e.get(d.SheetsSelectionsService),r=e.get(d.INumfmtService),o=e.get(s.IUniverInstanceService),c=n.getCurrentSelections();if(!c||!c.length)return!1;const i=d.getSheetCommandTarget(o);if(!i)return!1;const{unitId:l,subUnitId:m}=i;let a=0;c.forEach(p=>{s.Range.foreach(p.range,(u,v)=>{const C=r.getValue(l,m,u,v);if(!C){const b=i.worksheet.getCellRaw(u,v);if(!a&&b&&b.t===s.CellValueType.NUMBER&&b.v){const I=/\.(\d*)$/.exec(String(b.v));if(I){const x=I[1].length;if(!x)return;a=Math.max(a,x)}}return}const y=P(C.pattern);a=y>a?y:a})});const f=a-1,S=R(`0${f>0?".0":"."}`,f),g=[];return c.forEach(p=>{s.Range.foreach(p.range,(u,v)=>{const C=r.getValue(l,m,u,v);if(!C)g.push({row:u,col:v,pattern:S});else{const y=P(C.pattern);g.push({row:u,col:v,pattern:R(C.pattern,y-1)})}})}),await t.executeCommand(M.id,{values:g})}},X=e=>s.numfmt.getInfo(e).type||"unknown",H=(e,t,n)=>{const r=s.numfmt.getInfo(e),o=n===s.LocaleType.ZH_CN?"zh-CN":"en",c=r._partitions[1],i=s.numfmt.format(e,t,{locale:o,throws:!1});return t<0?{result:i,color:c.color}:{result:i}},q=(e,t,n)=>e==="General"?{result:String(t)}:H(e,t,n);var k=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=(e,t,n,r)=>{for(var o=r>1?void 0:r?ee(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&k(t,n,o),o},_=(e,t)=>(n,r)=>t(n,r,e);exports.SheetsNumfmtCellContentController=class extends s.Disposable{constructor(t,n,r,o,c,i){super(),this._instanceService=t,this._sheetInterceptorService=n,this._themeService=r,this._commandService=o,this._numfmtService=c,this._localeService=i,this._initInterceptorCellContent()}_initInterceptorCellContent(){const t=new s.ObjectMatrix;this.disposeWithMe(this._sheetInterceptorService.intercept(d.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Value|s.InterceptorEffectEnum.Style,handler:(n,r,o)=>{const c=r.unitId,i=r.subUnitId;let l;const m=n;if(!m||m.t!==s.CellValueType.NUMBER||m.v==null||Number.isNaN(m.v))return o(n);if(n!=null&&n.s){const h=r.workbook.getStyles().get(n.s);h!=null&&h.n&&(l=h.n)}if(l||(l=this._numfmtService.getValue(c,i,r.row,r.col)),!l)return o(n);let a="";const f=t.getValue(r.row,r.col);if(f&&f.parameters===`${m.v}_${l.pattern}`)return o({...n,...f.result});const S=q(l.pattern,Number(m.v),this._localeService.getCurrentLocale());if(a=S.result,!a)return o(n);const g={v:a};if(S.color){const h=this._themeService.getCurrentTheme()[`${S.color}500`];h&&(g.interceptorStyle={cl:{rgb:h}})}return t.setValue(r.row,r.col,{result:g,parameters:`${m.v}_${l.pattern}`}),o({...n,...g})},priority:d.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===d.SetNumfmtMutation.id){const r=n.params;Object.keys(r.values).forEach(o=>{r.values[o].ranges.forEach(i=>{s.Range.foreach(i,(l,m)=>{t.realDeleteValue(l,m)})})})}else if(n.id===d.SetRangeValuesMutation.id){const r=n.params;new s.ObjectMatrix(r.cellValue).forValue((o,c)=>{t.realDeleteValue(o,c)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).pipe($.switchMap(n=>{var r;return(r=n==null?void 0:n.activeSheet$)!=null?r:$.of(null)}),$.skip(1)).subscribe(()=>t.reset()))}};exports.SheetsNumfmtCellContentController=te([_(0,s.IUniverInstanceService),_(1,s.Inject(d.SheetInterceptorService)),_(2,s.Inject(s.ThemeService)),_(3,s.Inject(s.ICommandService)),_(4,s.Inject(d.INumfmtService)),_(5,s.Inject(s.LocaleService))],exports.SheetsNumfmtCellContentController);class O extends s.Disposable{constructor(){super(...arguments);N(this,"_currencySymbol$",new $.BehaviorSubject("US"));N(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(n){this._currencySymbol$.next(n)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var W=Object.defineProperty,ne=Object.getOwnPropertyDescriptor,re=(e,t,n)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,se=(e,t,n,r)=>{for(var o=r>1?void 0:r?ne(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&W(t,n,o),o},V=(e,t)=>(n,r)=>t(n,r,e),Y=(e,t,n)=>re(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsNumfmtPlugin=class extends s.Plugin{constructor(t=void 0,n,r){super(),this._config=t,this._injector=n,this._commandService=r}onStarting(){s.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[O]]),s.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){s.touchDependencies(this._injector,[[O]]),[F,G,B,L,M].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}};Y(exports.UniverSheetsNumfmtPlugin,"pluginName",J);Y(exports.UniverSheetsNumfmtPlugin,"type",s.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=se([s.DependentOn(d.UniverSheetsPlugin),V(1,s.Inject(s.Injector)),V(2,s.ICommandService)],exports.UniverSheetsNumfmtPlugin);const oe=e=>T.find(n=>e.includes(n)),ce=()=>T.map(e=>({label:e,value:e})),ie=e=>U.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),ae=()=>w.map(e=>({label:e.label,value:e.suffix})),ue=()=>A.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=F;exports.CURRENCYFORMAT=U;exports.DATEFMTLISG=w;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=A;exports.SetCurrencyCommand=B;exports.SetNumfmtCommand=M;exports.SetPercentCommand=L;exports.SubtractDecimalCommand=G;exports.countryCurrencyMap=j;exports.currencySymbols=T;exports.getCurrencyFormatOptions=ie;exports.getCurrencyOptions=ce;exports.getCurrencyType=oe;exports.getDateFormatOptions=ae;exports.getDecimalFromPattern=P;exports.getDecimalString=E;exports.getNumberFormatOptions=ue;exports.getPatternPreview=H;exports.getPatternPreviewIgnoreGeneral=q;exports.getPatternType=X;exports.isPatternEqualWithoutDecimal=Z;exports.isPatternHasDecimal=Q;exports.setPatternDecimal=R;
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 n } from "@univerjs/sheets-numfmt";
2
- import { FRange as e } from "@univerjs/sheets/facade";
3
- class i extends e {
4
- setNumberFormat(s) {
5
- const t = [];
6
- return this.forEach((m, o) => t.push({ row: m, col: o, pattern: s })), this._commandService.syncExecuteCommand(n.id, {
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: t
9
+ values: e
10
10
  }), this;
11
11
  }
12
12
  }
13
- e.extend(i);
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,11 @@
1
- var te = Object.defineProperty;
2
- var ne = (e, t, n) => t in e ? te(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var N = (e, t, n) => ne(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { numfmt as $, CommandType as E, ICommandService as b, IUniverInstanceService as D, IUndoRedoService as re, sequenceExecute as se, Range as C, CellValueType as V, LocaleType as oe, Inject as M, ThemeService as ce, LocaleService as ie, Disposable as K, ObjectMatrix as F, InterceptorEffectEnum as B, UniverInstanceType as Y, DependentOn as ae, Injector as le, Plugin as ue, registerDependencies as me, touchDependencies as L } from "@univerjs/core";
5
- import { getSheetCommandTarget as w, transformCellsToRange as fe, rangeMerge as G, SetNumfmtMutation as z, factorySetNumfmtUndoMutation as de, RemoveNumfmtMutation as he, factoryRemoveNumfmtUndoMutation as ge, SheetsSelectionsService as O, INumfmtService as A, SheetInterceptorService as ve, INTERCEPTOR_POINT as pe, InterceptCellContentPriority as Se, SetRangeValuesMutation as ye, UniverSheetsPlugin as Ce } from "@univerjs/sheets";
6
- import { BehaviorSubject as J, switchMap as be, of as _e, skip as Me } from "rxjs";
7
- const Z = [
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
+ const J = [
8
9
  "$",
9
10
  "£",
10
11
  "¥",
@@ -32,7 +33,7 @@ const Z = [
32
33
  "₽",
33
34
  "₾",
34
35
  "₿"
35
- ], $e = {
36
+ ], Ee = {
36
37
  US: "$",
37
38
  // United States Dollar
38
39
  CA: "C$",
@@ -117,7 +118,7 @@ const Z = [
117
118
  label: "08-05 下午 01:30",
118
119
  suffix: "MM-dd A/P hh:mm"
119
120
  }
120
- ], Ne = [
121
+ ], Te = [
121
122
  {
122
123
  label: "(1,235)",
123
124
  suffix: "#,##0_);(#,##0)"
@@ -173,129 +174,129 @@ const Z = [
173
174
  suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
174
175
  color: "red"
175
176
  }
176
- ], Ee = "SHEET_NUMFMT_PLUGIN", x = (e, t = 0) => {
177
- var r;
178
- return e && (r = $.getInfo(e).maxDecimals) != null ? r : t;
179
- }, We = (e, t) => {
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) => {
180
181
  if (e && !t || !e && t)
181
182
  return !1;
182
- const n = (i) => i.reduce(
183
- (u, f) => {
184
- if (u.isEnd)
185
- return u;
186
- const m = f.value || f.num;
187
- return f.type === "point" ? (u.isEnd = !0, u) : { ...u, result: u.result + m };
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 };
188
189
  },
189
190
  { isEnd: !1, result: "" }
190
- ).result, r = $.getInfo(e)._partitions, s = $.getInfo(t)._partitions, c = n(r[0].tokens), o = n(s[0].tokens), l = n(r[1].tokens), d = n(s[1].tokens);
191
- return c === o && l === d && r[1].color === s[1].color;
192
- }, H = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), P = (e, t) => e.split(";").map((r) => /\.0?/.test(r) ? r.replace(
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(
193
194
  /\.0*/g,
194
- `${t > 0 ? "." : ""}${H(Number(t || 0))}`
195
- ) : /0([^0]?)|0$/.test(r) ? r.replace(
195
+ `${t > 0 ? "." : ""}${z(Number(t || 0))}`
196
+ ) : /0([^0]?)|0$/.test(n) ? n.replace(
196
197
  /0([^0]+)|0$/,
197
- `0${t > 0 ? "." : ""}${H(Number(t || 0))}$1`
198
- ) : r).join(";"), qe = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), R = {
198
+ `0${t > 0 ? "." : ""}${z(Number(t || 0))}$1`
199
+ ) : n).join(";"), Ye = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), T = {
199
200
  id: "sheet.command.numfmt.set.numfmt",
200
- type: E.COMMAND,
201
+ type: I.COMMAND,
201
202
  handler: (e, t) => {
202
203
  if (!t)
203
204
  return !1;
204
- const n = e.get(b), r = e.get(D), s = e.get(re), c = w(r, t);
205
- if (!c) return !1;
206
- const { unitId: o, subUnitId: l } = c, d = t.values.filter((a) => !!a.pattern), i = t.values.filter((a) => !a.pattern), u = fe(o, l, d), f = {
207
- unitId: o,
208
- subUnitId: l,
209
- ranges: i.map((a) => ({
210
- startColumn: a.col,
211
- startRow: a.row,
212
- endColumn: a.col,
213
- endRow: a.row
205
+ const r = e.get(M), n = e.get(D), s = e.get(se), o = w(n, t);
206
+ if (!o) return !1;
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
214
215
  }))
215
- }, m = [], S = [];
216
- if (d.length) {
217
- Object.keys(u.values).forEach((h) => {
218
- const g = u.values[h];
219
- g.ranges = G(g.ranges);
220
- }), m.push({
221
- id: z.id,
222
- params: u
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
+ }), f.push({
222
+ id: Z.id,
223
+ params: l
223
224
  });
224
- const a = de(e, u);
225
- S.push(...a);
225
+ const i = he(e, l);
226
+ v.push(...i);
226
227
  }
227
- if (i.length) {
228
- f.ranges = G(f.ranges), m.push({
229
- id: he.id,
230
- params: f
228
+ if (c.length) {
229
+ h.ranges = H(h.ranges), f.push({
230
+ id: ge.id,
231
+ params: h
231
232
  });
232
- const a = ge(e, f);
233
- S.push(...a);
233
+ const i = pe(e, h);
234
+ v.push(...i);
234
235
  }
235
- const v = se(m, n).result;
236
- return v && s.pushUndoRedo({
237
- unitID: o,
238
- undoMutations: S,
239
- redoMutations: m
240
- }), v;
236
+ const m = oe(f, r).result;
237
+ return m && s.pushUndoRedo({
238
+ unitID: a,
239
+ undoMutations: v,
240
+ redoMutations: f
241
+ }), m;
241
242
  }
242
- }, Re = {
243
+ }, Pe = {
243
244
  id: "sheet.command.numfmt.add.decimal.command",
244
- type: E.COMMAND,
245
+ type: I.COMMAND,
245
246
  handler: async (e) => {
246
- const t = e.get(b), n = e.get(O), r = e.get(A), s = e.get(D), c = n.getCurrentSelections();
247
- if (!c || !c.length)
247
+ const t = e.get(M), r = e.get(V), n = e.get(F), s = e.get(D), o = r.getCurrentSelections();
248
+ if (!o || !o.length)
248
249
  return !1;
249
- const o = w(s);
250
- if (!o) return !1;
251
- const { unitId: l, subUnitId: d } = o;
252
- let i = 0;
253
- c.forEach((S) => {
254
- C.foreach(S.range, (v, a) => {
255
- const h = r.getValue(l, d, v, a);
256
- if (!h) {
257
- const p = o.worksheet.getCellRaw(v, a);
258
- if (!i && p && p.t === V.NUMBER && p.v) {
259
- const y = /\.(\d*)$/.exec(String(p.v));
260
- if (y) {
261
- const I = y[1].length;
262
- if (!I)
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
+ if (!g) {
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
+ if (!E)
263
264
  return;
264
- i = Math.max(i, I);
265
+ c = Math.max(c, E);
265
266
  }
266
267
  }
267
268
  return;
268
269
  }
269
- const g = x(h.pattern);
270
- i = g > i ? g : i;
270
+ const p = x(g.pattern);
271
+ c = p > c ? p : c;
271
272
  });
272
273
  });
273
- const u = i + 1, f = P(`0${u > 0 ? ".0" : ""}`, u), m = [];
274
- return c.forEach((S) => {
275
- C.foreach(S.range, (v, a) => {
276
- const h = r.getValue(l, d, v, a);
277
- if (!h)
278
- m.push({
279
- row: v,
280
- col: a,
281
- pattern: f
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
+ if (!g)
279
+ f.push({
280
+ row: m,
281
+ col: i,
282
+ pattern: h
282
283
  });
283
284
  else {
284
- const g = x(h.pattern), p = P(h.pattern, g + 1);
285
- p !== h.pattern && m.push({
286
- row: v,
287
- col: a,
288
- pattern: p
285
+ const p = x(g.pattern), S = P(g.pattern, p + 1);
286
+ S !== g.pattern && f.push({
287
+ row: m,
288
+ col: i,
289
+ pattern: S
289
290
  });
290
291
  }
291
292
  });
292
- }), m.length ? await t.executeCommand(R.id, { values: m }) : !1;
293
+ }), f.length ? await t.executeCommand(T.id, { values: f }) : !1;
293
294
  }
294
295
  };
295
- class X {
296
+ class k {
296
297
  constructor() {
297
- N(this, "_currencySymbol$", new J("US"));
298
- N(this, "currencySymbol$", this._currencySymbol$.asObservable());
298
+ y(this, "_currencySymbol$", new j("US"));
299
+ y(this, "currencySymbol$", this._currencySymbol$.asObservable());
299
300
  }
300
301
  /**
301
302
  * Set the currency symbol by setting the country code.
@@ -307,261 +308,305 @@ class X {
307
308
  return this._currencySymbol$.getValue();
308
309
  }
309
310
  }
310
- const xe = {
311
+ const Ue = {
311
312
  id: "sheet.command.numfmt.set.currency",
312
- type: E.COMMAND,
313
+ type: I.COMMAND,
313
314
  handler: async (e) => {
314
- const t = e.get(b), n = e.get(O), r = e.get(X), s = $e[r.getCurrencySymbol()] || "$", c = n.getCurrentSelections();
315
- if (!c || !c.length)
315
+ const t = e.get(M), r = e.get(V), n = e.get(k), s = Ee[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
316
+ if (!o || !o.length)
316
317
  return !1;
317
- const o = [], l = Q[4].suffix(s);
318
- return c.forEach((i) => {
319
- C.foreach(i.range, (u, f) => {
320
- o.push({ row: u, col: f, pattern: l, type: "currency" });
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" });
321
322
  });
322
- }), await t.executeCommand(R.id, { values: o });
323
+ }), await t.executeCommand(T.id, { values: a });
323
324
  }
324
- }, Pe = {
325
+ }, Oe = {
325
326
  id: "sheet.command.numfmt.set.percent",
326
- type: E.COMMAND,
327
+ type: I.COMMAND,
327
328
  handler: async (e) => {
328
- const t = e.get(b), r = e.get(O).getCurrentSelections();
329
- if (!r || !r.length)
329
+ const t = e.get(M), n = e.get(V).getCurrentSelections();
330
+ if (!n || !n.length)
330
331
  return !1;
331
- const s = [], c = "0%";
332
- return r.forEach((l) => {
333
- C.foreach(l.range, (d, i) => {
334
- s.push({ row: d, col: i, pattern: c, type: "percent" });
332
+ const s = [], o = "0%";
333
+ return n.forEach((d) => {
334
+ C.foreach(d.range, (u, c) => {
335
+ s.push({ row: u, col: c, pattern: o, type: "percent" });
335
336
  });
336
- }), await t.executeCommand(R.id, { values: s });
337
+ }), await t.executeCommand(T.id, { values: s });
337
338
  }
338
- }, Te = {
339
+ }, De = {
339
340
  id: "sheet.command.numfmt.subtract.decimal.command",
340
- type: E.COMMAND,
341
+ type: I.COMMAND,
341
342
  handler: async (e) => {
342
- const t = e.get(b), n = e.get(O), r = e.get(A), s = e.get(D), c = n.getCurrentSelections();
343
- if (!c || !c.length)
343
+ const t = e.get(M), r = e.get(V), n = e.get(F), s = e.get(D), o = r.getCurrentSelections();
344
+ if (!o || !o.length)
344
345
  return !1;
345
- const o = w(s);
346
- if (!o) return !1;
347
- const { unitId: l, subUnitId: d } = o;
348
- let i = 0;
349
- c.forEach((v) => {
350
- C.foreach(v.range, (a, h) => {
351
- const g = r.getValue(l, d, a, h);
352
- if (!g) {
353
- const y = o.worksheet.getCellRaw(a, h);
354
- if (!i && y && y.t === V.NUMBER && y.v) {
355
- const I = /\.(\d*)$/.exec(String(y.v));
356
- if (I) {
357
- const j = I[1].length;
358
- if (!j)
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
+ if (!p) {
354
+ const _ = a.worksheet.getCellRaw(i, g);
355
+ if (!c && _ && _.t === A.NUMBER && _.v) {
356
+ const E = /\.(\d*)$/.exec(String(_.v));
357
+ if (E) {
358
+ const L = E[1].length;
359
+ if (!L)
359
360
  return;
360
- i = Math.max(i, j);
361
+ c = Math.max(c, L);
361
362
  }
362
363
  }
363
364
  return;
364
365
  }
365
- const p = x(g.pattern);
366
- i = p > i ? p : i;
366
+ const S = x(p.pattern);
367
+ c = S > c ? S : c;
367
368
  });
368
369
  });
369
- const u = i - 1, f = P(`0${u > 0 ? ".0" : "."}`, u), m = [];
370
- return c.forEach((v) => {
371
- C.foreach(v.range, (a, h) => {
372
- const g = r.getValue(l, d, a, h);
373
- if (!g)
374
- m.push({
375
- row: a,
376
- col: h,
377
- pattern: f
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
+ if (!p)
375
+ f.push({
376
+ row: i,
377
+ col: g,
378
+ pattern: h
378
379
  });
379
380
  else {
380
- const p = x(g.pattern);
381
- m.push({
382
- row: a,
383
- col: h,
384
- pattern: P(g.pattern, p - 1)
381
+ const S = x(p.pattern);
382
+ f.push({
383
+ row: i,
384
+ col: g,
385
+ pattern: P(p.pattern, S - 1)
385
386
  });
386
387
  }
387
388
  });
388
- }), await t.executeCommand(R.id, { values: m });
389
+ }), await t.executeCommand(T.id, { values: f });
389
390
  }
390
- }, Ke = (e) => $.getInfo(e).type || "unknown", Ue = (e, t, n) => {
391
- const r = $.getInfo(e), s = n === oe.ZH_CN ? "zh-CN" : "en", c = r._partitions[1], o = $.format(e, t, { locale: s, throws: !1 });
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 });
392
393
  return t < 0 ? {
393
394
  result: o,
394
- color: c.color
395
+ color: s.color
395
396
  } : {
396
397
  result: o
397
398
  };
398
- }, De = (e, t, n) => e === "General" ? {
399
+ }, Ae = (e, t, r) => e === "General" ? {
399
400
  result: String(t)
400
- } : Ue(e, t, n);
401
- var Oe = Object.defineProperty, Ve = Object.getOwnPropertyDescriptor, we = (e, t, n, r) => {
402
- for (var s = r > 1 ? void 0 : r ? Ve(t, n) : t, c = e.length - 1, o; c >= 0; c--)
403
- (o = e[c]) && (s = (r ? o(t, n, s) : o(s)) || s);
404
- return r && s && Oe(t, n, s), s;
405
- }, _ = (e, t) => (n, r) => t(n, r, e);
406
- let T = class extends K {
407
- constructor(e, t, n, r, s, c) {
408
- super(), this._instanceService = e, this._sheetInterceptorService = t, this._themeService = n, this._commandService = r, this._numfmtService = s, this._localeService = c, this._initInterceptorCellContent();
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
+ }
409
434
  }
410
435
  // eslint-disable-next-line max-lines-per-function
411
436
  _initInterceptorCellContent() {
412
- const e = new F();
413
- this.disposeWithMe(this._sheetInterceptorService.intercept(pe.CELL_CONTENT, {
414
- effect: B.Value | B.Style,
415
- handler: (t, n, r) => {
416
- const s = n.unitId, c = n.subUnitId;
417
- let o;
418
- const l = t;
419
- if (!l || l.t !== V.NUMBER || l.v == null || Number.isNaN(l.v))
420
- return r(t);
421
- if (t != null && t.s) {
422
- const m = n.workbook.getStyles().get(t.s);
423
- m != null && m.n && (o = m.n);
437
+ const t = {
438
+ tl: {
439
+ size: 6,
440
+ color: "#409f11"
441
+ }
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;
449
+ let u;
450
+ const c = n;
451
+ if (!c)
452
+ return o(n);
453
+ if (n != null && n.s) {
454
+ const m = s.workbook.getStyles().get(n.s);
455
+ m != null && m.n && (u = m.n);
424
456
  }
425
- if (o || (o = this._numfmtService.getValue(s, c, n.row, n.col)), !o)
426
- return r(t);
427
- let d = "";
428
- const i = e.getValue(n.row, n.col);
429
- if (i && i.parameters === `${l.v}_${o.pattern}`)
430
- return r({ ...t, ...i.result });
431
- const u = De(o.pattern, Number(l.v), this._localeService.getCurrentLocale());
432
- if (d = u.result, !d)
433
- return r(t);
434
- const f = { v: d };
435
- if (u.color) {
436
- const m = this._themeService.getCurrentTheme()[`${u.color}500`];
437
- m && (f.interceptorStyle = { cl: { rgb: m } });
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({
461
+ ...n,
462
+ markers: {
463
+ ...n == null ? void 0 : n.markers,
464
+ ...t
465
+ }
466
+ });
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 } });
438
480
  }
439
- return e.setValue(n.row, n.col, {
440
- result: f,
441
- parameters: `${l.v}_${o.pattern}`
442
- }), r({ ...t, ...f });
481
+ return r.setValue(s.row, s.col, {
482
+ result: v,
483
+ parameters: `${c.v}_${u.pattern}`
484
+ }), o({ ...n, ...v });
443
485
  },
444
- priority: Se.NUMFMT
445
- })), this.disposeWithMe(this._commandService.onCommandExecuted((t) => {
446
- if (t.id === z.id) {
447
- const n = t.params;
448
- Object.keys(n.values).forEach((r) => {
449
- n.values[r].ranges.forEach((c) => {
450
- C.foreach(c, (o, l) => {
451
- e.realDeleteValue(o, l);
486
+ priority: _e.NUMFMT
487
+ })), this.disposeWithMe(this._commandService.onCommandExecuted((n) => {
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);
452
494
  });
453
495
  });
454
496
  });
455
- } else if (t.id === ye.id) {
456
- const n = t.params;
457
- new F(n.cellValue).forValue((r, s) => {
458
- e.realDeleteValue(r, s);
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);
459
501
  });
460
502
  }
461
503
  })), this.disposeWithMe(
462
504
  this._instanceService.getCurrentTypeOfUnit$(Y.UNIVER_SHEET).pipe(
463
- be((t) => {
464
- var n;
465
- return (n = t == null ? void 0 : t.activeSheet$) != null ? n : _e(null);
505
+ Me((n) => {
506
+ var s;
507
+ return (s = n == null ? void 0 : n.activeSheet$) != null ? s : $e(null);
466
508
  }),
467
- Me(1)
468
- ).subscribe(() => e.reset())
509
+ Ne(1)
510
+ ).subscribe(() => r.reset())
469
511
  );
470
512
  }
513
+ setNumfmtLocal(t) {
514
+ this._local$.next(t);
515
+ }
471
516
  };
472
- T = we([
473
- _(0, D),
474
- _(1, M(ve)),
475
- _(2, M(ce)),
476
- _(3, M(b)),
477
- _(4, M(A)),
478
- _(5, M(ie))
479
- ], T);
480
- class W extends K {
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 {
481
526
  constructor() {
482
527
  super(...arguments);
483
- N(this, "_currencySymbol$", new J("US"));
484
- N(this, "currencySymbol$", this._currencySymbol$.asObservable());
528
+ y(this, "_currencySymbol$", new j("US"));
529
+ y(this, "currencySymbol$", this._currencySymbol$.asObservable());
485
530
  }
486
531
  /**
487
532
  * Set the currency symbol by setting the country code.
488
533
  */
489
- setCurrencySymbolByCountryCode(n) {
490
- this._currencySymbol$.next(n);
534
+ setCurrencySymbolByCountryCode(r) {
535
+ this._currencySymbol$.next(r);
491
536
  }
492
537
  getCurrencySymbol() {
493
538
  return this._currencySymbol$.getValue();
494
539
  }
495
540
  }
496
- var k = Object.defineProperty, Ae = Object.getOwnPropertyDescriptor, je = (e, t, n) => t in e ? k(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, Fe = (e, t, n, r) => {
497
- for (var s = r > 1 ? void 0 : r ? Ae(t, n) : t, c = e.length - 1, o; c >= 0; c--)
498
- (o = e[c]) && (s = (r ? o(t, n, s) : o(s)) || s);
499
- return r && s && k(t, n, s), s;
500
- }, q = (e, t) => (n, r) => t(n, r, e), ee = (e, t, n) => je(e, typeof t != "symbol" ? t + "" : t, n);
501
- let U = class extends ue {
502
- constructor(e = void 0, t, n) {
503
- super(), this._config = e, this._injector = t, this._commandService = n;
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;
504
549
  }
505
550
  onStarting() {
506
- me(this._injector, [
507
- [T],
508
- [X],
509
- [W]
510
- ]), L(this._injector, [
511
- [T]
551
+ fe(this._injector, [
552
+ [U],
553
+ [k],
554
+ [K]
555
+ ]), G(this._injector, [
556
+ [U]
512
557
  ]);
513
558
  }
514
559
  onRendered() {
515
- L(this._injector, [
516
- [W]
560
+ G(this._injector, [
561
+ [K]
517
562
  ]), [
518
- Re,
519
- Te,
520
- xe,
521
563
  Pe,
522
- R
564
+ De,
565
+ Ue,
566
+ Oe,
567
+ T
523
568
  ].forEach((e) => {
524
569
  this.disposeWithMe(this._commandService.registerCommand(e));
525
570
  });
526
571
  }
527
572
  };
528
- ee(U, "pluginName", Ee);
529
- ee(U, "type", Y.UNIVER_SHEET);
530
- U = Fe([
531
- ae(Ce),
532
- q(1, M(le)),
533
- q(2, b)
534
- ], U);
535
- const Ye = (e) => Z.find((n) => e.includes(n)), ze = () => Z.map((e) => ({ label: e, value: e })), Je = (e) => Q.map((t) => ({
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) => ({
536
581
  label: t.label(e),
537
582
  value: t.suffix(e),
538
583
  color: t.color
539
- })), Ze = () => Ie.map((e) => ({ label: e.label, value: e.suffix })), Qe = () => Ne.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
584
+ })), et = () => Ie.map((e) => ({ label: e.label, value: e.suffix })), tt = () => Te.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
540
585
  export {
541
- Re as AddDecimalCommand,
586
+ Pe as AddDecimalCommand,
542
587
  Q as CURRENCYFORMAT,
543
588
  Ie as DATEFMTLISG,
544
- X as MenuCurrencyService,
545
- Ne as NUMBERFORMAT,
546
- xe as SetCurrencyCommand,
547
- R as SetNumfmtCommand,
548
- Pe as SetPercentCommand,
549
- T as SheetsNumfmtCellContentController,
550
- Te as SubtractDecimalCommand,
551
- U as UniverSheetsNumfmtPlugin,
552
- $e as countryCurrencyMap,
553
- Z as currencySymbols,
554
- Je as getCurrencyFormatOptions,
555
- ze as getCurrencyOptions,
556
- Ye as getCurrencyType,
557
- Ze as getDateFormatOptions,
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,
598
+ J as currencySymbols,
599
+ ke as getCurrencyFormatOptions,
600
+ Qe as getCurrencyOptions,
601
+ Je as getCurrencyType,
602
+ et as getDateFormatOptions,
558
603
  x as getDecimalFromPattern,
559
- H as getDecimalString,
560
- Qe as getNumberFormatOptions,
561
- Ue as getPatternPreview,
562
- De as getPatternPreviewIgnoreGeneral,
563
- Ke as getPatternType,
564
- We as isPatternEqualWithoutDecimal,
565
- qe as isPatternHasDecimal,
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,
566
611
  P as setPatternDecimal
567
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
+ }
@@ -14,4 +14,6 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import './f-range';
17
+ import './f-workbook';
17
18
  export type * from './f-range';
19
+ export type * from './f-workbook';
@@ -1,10 +1,10 @@
1
- import { LocaleType } from '@univerjs/core';
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, _locale?: LocaleType) => IPatternPreview;
9
- export declare const getPatternPreviewIgnoreGeneral: (pattern: string, value: number, _locale?: LocaleType) => IPatternPreview;
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,t){typeof exports=="object"&&typeof module<"u"?t(require("@univerjs/sheets-numfmt"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["@univerjs/sheets-numfmt","@univerjs/sheets/facade"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e.UniverSheetsNumfmt,e.UniverSheetsFacade))})(this,function(e,t){"use strict";class n extends t.FRange{setNumberFormat(i){const s=[];return this.forEach((u,d)=>s.push({row:u,col:d,pattern:i})),this._commandService.syncExecuteCommand(e.SetNumfmtCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),values:s}),this}}t.FRange.extend(n)});
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(s,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs"],n):(s=typeof globalThis<"u"?globalThis:s||self,n(s.UniverSheetsNumfmt={},s.UniverCore,s.UniverSheets,s.rxjs))})(this,function(s,n,l,N){"use strict";var le=Object.defineProperty;var oe=(s,n,l)=>n in s?le(s,n,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[n]=l;var E=(s,n,l)=>oe(s,typeof n!="symbol"?n+"":n,l);const T=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],j={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},V=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],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 i;return e&&(i=n.numfmt.getInfo(e).maxDecimals)!=null?i:t},J=(e,t)=>{if(e&&!t||!e&&t)return!1;const r=o=>o.reduce((S,v)=>{if(S.isEnd)return S;const g=v.value||v.num;return v.type==="point"?(S.isEnd=!0,S):{...S,result:S.result+g}},{isEnd:!1,result:""}).result,i=n.numfmt.getInfo(e)._partitions,a=n.numfmt.getInfo(t)._partitions,u=r(i[0].tokens),c=r(a[0].tokens),f=r(i[1].tokens),d=r(a[1].tokens);return u===c&&f===d&&i[1].color===a[1].color},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,t)=>e.split(";").map(i=>/\.0?/.test(i)?i.replace(/\.0*/g,`${t>0?".":""}${D(Number(t||0))}`):/0([^0]?)|0$/.test(i)?i.replace(/0([^0]+)|0$/,`0${t>0?".":""}${D(Number(t||0))}$1`):i).join(";"),Z=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),M={id:"sheet.command.numfmt.set.numfmt",type:n.CommandType.COMMAND,handler:(e,t)=>{if(!t)return!1;const r=e.get(n.ICommandService),i=e.get(n.IUniverInstanceService),a=e.get(n.IUndoRedoService),u=l.getSheetCommandTarget(i,t);if(!u)return!1;const{unitId:c,subUnitId:f}=u,d=t.values.filter(m=>!!m.pattern),o=t.values.filter(m=>!m.pattern),S=l.transformCellsToRange(c,f,d),v={unitId:c,subUnitId:f,ranges:o.map(m=>({startColumn:m.col,startRow:m.row,endColumn:m.col,endRow:m.row}))},g=[],h=[];if(d.length){Object.keys(S.values).forEach(C=>{const y=S.values[C];y.ranges=l.rangeMerge(y.ranges)}),g.push({id:l.SetNumfmtMutation.id,params:S});const m=l.factorySetNumfmtUndoMutation(e,S);h.push(...m)}if(o.length){v.ranges=l.rangeMerge(v.ranges),g.push({id:l.RemoveNumfmtMutation.id,params:v});const m=l.factoryRemoveNumfmtUndoMutation(e,v);h.push(...m)}const p=n.sequenceExecute(g,r).result;return p&&a.pushUndoRedo({unitID:c,undoMutations:h,redoMutations:g}),p}},A={id:"sheet.command.numfmt.add.decimal.command",type:n.CommandType.COMMAND,handler:async e=>{const t=e.get(n.ICommandService),r=e.get(l.SheetsSelectionsService),i=e.get(l.INumfmtService),a=e.get(n.IUniverInstanceService),u=r.getCurrentSelections();if(!u||!u.length)return!1;const c=l.getSheetCommandTarget(a);if(!c)return!1;const{unitId:f,subUnitId:d}=c;let o=0;u.forEach(h=>{n.Range.foreach(h.range,(p,m)=>{const C=i.getValue(f,d,p,m);if(!C){const b=c.worksheet.getCellRaw(p,m);if(!o&&b&&b.t===n.CellValueType.NUMBER&&b.v){const _=/\.(\d*)$/.exec(String(b.v));if(_){const R=_[1].length;if(!R)return;o=Math.max(o,R)}}return}const y=$(C.pattern);o=y>o?y:o})});const S=o+1,v=P(`0${S>0?".0":""}`,S),g=[];return u.forEach(h=>{n.Range.foreach(h.range,(p,m)=>{const C=i.getValue(f,d,p,m);if(!C)g.push({row:p,col:m,pattern:v});else{const y=$(C.pattern),b=P(C.pattern,y+1);b!==C.pattern&&g.push({row:p,col:m,pattern:b})}})}),g.length?await t.executeCommand(M.id,{values:g}):!1}};class O{constructor(){E(this,"_currencySymbol$",new N.BehaviorSubject("US"));E(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(t){this._currencySymbol$.next(t)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const F={id:"sheet.command.numfmt.set.currency",type:n.CommandType.COMMAND,handler:async e=>{const t=e.get(n.ICommandService),r=e.get(l.SheetsSelectionsService),i=e.get(O),a=j[i.getCurrencySymbol()]||"$",u=r.getCurrentSelections();if(!u||!u.length)return!1;const c=[],f=U[4].suffix(a);return u.forEach(o=>{n.Range.foreach(o.range,(S,v)=>{c.push({row:S,col:v,pattern:f,type:"currency"})})}),await t.executeCommand(M.id,{values:c})}},B={id:"sheet.command.numfmt.set.percent",type:n.CommandType.COMMAND,handler:async e=>{const t=e.get(n.ICommandService),i=e.get(l.SheetsSelectionsService).getCurrentSelections();if(!i||!i.length)return!1;const a=[],u="0%";return i.forEach(f=>{n.Range.foreach(f.range,(d,o)=>{a.push({row:d,col:o,pattern:u,type:"percent"})})}),await t.executeCommand(M.id,{values:a})}},L={id:"sheet.command.numfmt.subtract.decimal.command",type:n.CommandType.COMMAND,handler:async e=>{const t=e.get(n.ICommandService),r=e.get(l.SheetsSelectionsService),i=e.get(l.INumfmtService),a=e.get(n.IUniverInstanceService),u=r.getCurrentSelections();if(!u||!u.length)return!1;const c=l.getSheetCommandTarget(a);if(!c)return!1;const{unitId:f,subUnitId:d}=c;let o=0;u.forEach(p=>{n.Range.foreach(p.range,(m,C)=>{const y=i.getValue(f,d,m,C);if(!y){const _=c.worksheet.getCellRaw(m,C);if(!o&&_&&_.t===n.CellValueType.NUMBER&&_.v){const R=/\.(\d*)$/.exec(String(_.v));if(R){const K=R[1].length;if(!K)return;o=Math.max(o,K)}}return}const b=$(y.pattern);o=b>o?b:o})});const S=o-1,v=P(`0${S>0?".0":"."}`,S),g=[];return u.forEach(p=>{n.Range.foreach(p.range,(m,C)=>{const y=i.getValue(f,d,m,C);if(!y)g.push({row:m,col:C,pattern:v});else{const b=$(y.pattern);g.push({row:m,col:C,pattern:P(y.pattern,b-1)})}})}),await t.executeCommand(M.id,{values:g})}},Q=e=>n.numfmt.getInfo(e).type||"unknown",G=(e,t,r)=>{const i=n.numfmt.getInfo(e),a=r===n.LocaleType.ZH_CN?"zh-CN":"en",u=i._partitions[1],c=n.numfmt.format(e,t,{locale:a,throws:!1});return t<0?{result:c,color:u.color}:{result:c}},H=(e,t,r)=>e==="General"?{result:String(t)}:G(e,t,r);var X=Object.defineProperty,k=Object.getOwnPropertyDescriptor,ee=(e,t,r,i)=>{for(var a=i>1?void 0:i?k(t,r):t,u=e.length-1,c;u>=0;u--)(c=e[u])&&(a=(i?c(t,r,a):c(a))||a);return i&&a&&X(t,r,a),a},I=(e,t)=>(r,i)=>t(r,i,e);s.SheetsNumfmtCellContentController=class extends n.Disposable{constructor(t,r,i,a,u,c){super(),this._instanceService=t,this._sheetInterceptorService=r,this._themeService=i,this._commandService=a,this._numfmtService=u,this._localeService=c,this._initInterceptorCellContent()}_initInterceptorCellContent(){const t=new n.ObjectMatrix;this.disposeWithMe(this._sheetInterceptorService.intercept(l.INTERCEPTOR_POINT.CELL_CONTENT,{effect:n.InterceptorEffectEnum.Value|n.InterceptorEffectEnum.Style,handler:(r,i,a)=>{const u=i.unitId,c=i.subUnitId;let f;const d=r;if(!d||d.t!==n.CellValueType.NUMBER||d.v==null||Number.isNaN(d.v))return a(r);if(r!=null&&r.s){const h=i.workbook.getStyles().get(r.s);h!=null&&h.n&&(f=h.n)}if(f||(f=this._numfmtService.getValue(u,c,i.row,i.col)),!f)return a(r);let o="";const S=t.getValue(i.row,i.col);if(S&&S.parameters===`${d.v}_${f.pattern}`)return a({...r,...S.result});const v=H(f.pattern,Number(d.v),this._localeService.getCurrentLocale());if(o=v.result,!o)return a(r);const g={v:o};if(v.color){const h=this._themeService.getCurrentTheme()[`${v.color}500`];h&&(g.interceptorStyle={cl:{rgb:h}})}return t.setValue(i.row,i.col,{result:g,parameters:`${d.v}_${f.pattern}`}),a({...r,...g})},priority:l.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===l.SetNumfmtMutation.id){const i=r.params;Object.keys(i.values).forEach(a=>{i.values[a].ranges.forEach(c=>{n.Range.foreach(c,(f,d)=>{t.realDeleteValue(f,d)})})})}else if(r.id===l.SetRangeValuesMutation.id){const i=r.params;new n.ObjectMatrix(i.cellValue).forValue((a,u)=>{t.realDeleteValue(a,u)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(n.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(r=>{var i;return(i=r==null?void 0:r.activeSheet$)!=null?i:N.of(null)}),N.skip(1)).subscribe(()=>t.reset()))}},s.SheetsNumfmtCellContentController=ee([I(0,n.IUniverInstanceService),I(1,n.Inject(l.SheetInterceptorService)),I(2,n.Inject(n.ThemeService)),I(3,n.Inject(n.ICommandService)),I(4,n.Inject(l.INumfmtService)),I(5,n.Inject(n.LocaleService))],s.SheetsNumfmtCellContentController);class q extends n.Disposable{constructor(){super(...arguments);E(this,"_currencySymbol$",new N.BehaviorSubject("US"));E(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var x=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(e,t,r)=>t in e?x(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,re=(e,t,r,i)=>{for(var a=i>1?void 0:i?te(t,r):t,u=e.length-1,c;u>=0;u--)(c=e[u])&&(a=(i?c(t,r,a):c(a))||a);return i&&a&&x(t,r,a),a},W=(e,t)=>(r,i)=>t(r,i,e),Y=(e,t,r)=>ne(e,typeof t!="symbol"?t+"":t,r);s.UniverSheetsNumfmtPlugin=class extends n.Plugin{constructor(t=void 0,r,i){super(),this._config=t,this._injector=r,this._commandService=i}onStarting(){n.registerDependencies(this._injector,[[s.SheetsNumfmtCellContentController],[O],[q]]),n.touchDependencies(this._injector,[[s.SheetsNumfmtCellContentController]])}onRendered(){n.touchDependencies(this._injector,[[q]]),[A,L,F,B,M].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}},Y(s.UniverSheetsNumfmtPlugin,"pluginName",z),Y(s.UniverSheetsNumfmtPlugin,"type",n.UniverInstanceType.UNIVER_SHEET),s.UniverSheetsNumfmtPlugin=re([n.DependentOn(l.UniverSheetsPlugin),W(1,n.Inject(n.Injector)),W(2,n.ICommandService)],s.UniverSheetsNumfmtPlugin);const ie=e=>T.find(r=>e.includes(r)),se=()=>T.map(e=>({label:e,value:e})),ae=e=>U.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),ue=()=>V.map(e=>({label:e.label,value:e.suffix})),ce=()=>w.map(e=>({label:e.label,value:e.suffix,color:e.color}));s.AddDecimalCommand=A,s.CURRENCYFORMAT=U,s.DATEFMTLISG=V,s.MenuCurrencyService=O,s.NUMBERFORMAT=w,s.SetCurrencyCommand=F,s.SetNumfmtCommand=M,s.SetPercentCommand=B,s.SubtractDecimalCommand=L,s.countryCurrencyMap=j,s.currencySymbols=T,s.getCurrencyFormatOptions=ae,s.getCurrencyOptions=se,s.getCurrencyType=ie,s.getDateFormatOptions=ue,s.getDecimalFromPattern=$,s.getDecimalString=D,s.getNumberFormatOptions=ce,s.getPatternPreview=G,s.getPatternPreviewIgnoreGeneral=H,s.getPatternType=Q,s.isPatternEqualWithoutDecimal=J,s.isPatternHasDecimal=Z,s.setPatternDecimal=P,Object.defineProperty(s,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",
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,15 +53,16 @@
53
53
  "rxjs": ">=7.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@univerjs/sheets": "0.5.3",
57
- "@univerjs/core": "0.5.3"
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"
58
59
  },
59
60
  "devDependencies": {
60
61
  "rxjs": "^7.8.1",
61
62
  "typescript": "^5.7.2",
62
- "vite": "^6.0.6",
63
+ "vite": "^6.0.7",
63
64
  "vitest": "^2.1.8",
64
- "@univerjs-infra/shared": "0.5.3"
65
+ "@univerjs-infra/shared": "0.5.4"
65
66
  },
66
67
  "scripts": {
67
68
  "test": "vitest run",
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS