@univerjs/preset-sheets-node-core 0.8.0-nightly.202506071606 → 0.8.0-nightly.202506091607

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.
Files changed (2) hide show
  1. package/lib/umd/index.js +1 -1
  2. package/package.json +16 -16
package/lib/umd/index.js CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
 
19
19
  // @univerjs/sheets-numfmt/index
20
- (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.UniverEngineNumfmt,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,u,A,I,J){"use strict";var de=Object.defineProperty;var ge=(a,t,u)=>t in a?de(a,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):a[t]=u;var R=(a,t,u)=>ge(a,typeof t!="symbol"?t+"":t,u);const O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],x=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],X="SHEET_NUMFMT_PLUGIN",E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${D(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${D(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),$={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=u.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:v,worksheet:d}=l,c=r.values.filter(o=>!!o.pattern),T=r.values.filter(o=>!o.pattern),M=u.transformCellsToRange(m,v,c),y={unitId:m,subUnitId:v,ranges:T.map(o=>({startColumn:o.col,startRow:o.row,endColumn:o.col,endRow:o.row}))},b=[],h=[];if(c.length){const o=c.reduce((S,f)=>{A.isTextFormat(f.pattern)&&S.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const P=u.checkCellValueType(_.v);P!==_.t&&S.setValue(f.row,f.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),g=new t.ObjectMatrix;new t.ObjectMatrix(o).forValue((S,f)=>{const _=d.getCellRaw(S,f);_?g.setValue(S,f,{t:_.t}):g.setValue(S,f,{t:void 0})}),Object.keys(M.values).forEach(S=>{const f=M.values[S];f.ranges=u.rangeMerge(f.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const p=u.factorySetNumfmtUndoMutation(e,M);h.push(...p)}if(T.length){y.ranges=u.rangeMerge(y.ranges);const o=T.reduce((S,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const P=u.checkCellValueType(_.v);P!==_.t&&S.setValue(f.row,f.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),g=new t.ObjectMatrix;new t.ObjectMatrix(o).forValue((S,f)=>{const _=d.getCellRaw(S,f);_?g.setValue(S,f,{t:_.t}):g.setValue(S,f,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:v,cellValue:o}});const p=u.factoryRemoveNumfmtUndoMutation(e,y);h.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:v,cellValue:g.getMatrix()}},...p)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:h,redoMutations:b}),C}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:v,subUnitId:d}=m;let c=0;l.forEach(b=>{t.Range.foreach(b.range,(h,C)=>{const o=n.getValue(v,d,h,C);if(!o){const p=m.worksheet.getCellRaw(h,C);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const S=/\.(\d*)$/.exec(String(p.v));if(S){const f=S[1].length;if(!f)return;c=Math.max(c,f)}}return}const g=E(o.pattern);c=g>c?g:c})});const T=c+1,M=U(`0${T>0?".0":""}`,T),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(h,C)=>{const o=n.getValue(v,d,h,C);if(!o)y.push({row:h,col:C,pattern:M});else{const g=E(o.pattern),p=U(o.pattern,g+1);p!==o.pattern&&y.push({row:h,col:C,pattern:p})}})}),y.length?await r.executeCommand($.id,{values:y}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(j),s=L[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],v=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(T,M)=>{m.push({row:T,col:M,pattern:v,type:"currency"})})}),await r.executeCommand($.id,{values:m})}},W={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(v=>{t.Range.foreach(v.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:v,subUnitId:d}=m;let c=0;l.forEach(h=>{t.Range.foreach(h.range,(C,o)=>{const g=n.getValue(v,d,C,o);if(!g){const S=m.worksheet.getCellRaw(C,o);if(!c&&S&&S.t===t.CellValueType.NUMBER&&S.v){const f=/\.(\d*)$/.exec(String(S.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(g.pattern);c=p>c?p:c})});const T=c-1,M=U(`0${T>0?".0":"."}`,T),y=[];return l.forEach(h=>{t.Range.foreach(h.range,(C,o)=>{const g=n.getValue(v,d,C,o);if(!g)y.push({row:C,col:o,pattern:M});else{const p=E(g.pattern);y.push({row:C,col:o,pattern:U(g.pattern,p-1)})}})}),await r.executeCommand($.id,{values:y})}},w="sheets-numfmt.config",K={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,i="en")=>{const n=String(t.numfmt.formatColor(e,r)),s=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:s,color:n}:{result:s}},k=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:Y(e,r,i);var te=Object.getOwnPropertyDescriptor,ne=(e,r,i,n)=>{for(var s=n>1?void 0:n?te(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,r)=>(i,n)=>r(i,n,e);const re={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,v,d){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=v,this._configService=d,this._initInterceptorCellContent()}get local(){const i=this._local$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var C,o;const m=s.unitId,v=s.subUnitId;let d;const c=n;if(!c||c.v===void 0||c.v===null)return l(n);if(n!=null&&n.s){const g=s.workbook.getStyles().get(n.s);g!=null&&g.n&&(d=g.n)}if(d||(d=this._numfmtService.getValue(m,v,s.row,s.col)),!d||d.pattern==="General"||u.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),A.isTextFormat(d.pattern))return(C=this._configService.getConfig(w))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...re},l(n));let M="";const y=i.getValue(s.row,s.col);if(y&&y.parameters===`${c.v}_${d.pattern}`)return l({...n,...y.result});const b=k(d.pattern,Number(c.v),this.local);if(M=b.result,!M)return l(n);const h={v:M,t:t.CellValueType.NUMBER};if(b.color){const g=(o=this._themeService.getColorFromTheme(`${b.color}.500`))!=null?o:b.color;g&&(h.interceptorStyle={cl:{rgb:g}})}return i.setValue(s.row,s.col,{result:h,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,h),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(v=>{t.Range.foreach(v,(d,c)=>{i.realDeleteValue(d,c)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._local$.next(i)}},a.SheetsNumfmtCellContentController=ne([N(0,t.IUniverInstanceService),N(1,t.Inject(u.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(u.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);class z extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(i){this._currencySymbol$.next(i)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,le=(e,r,i,n)=>{for(var s=n>1?void 0:n?ie(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},F=(e,r)=>(i,n)=>r(i,n,e),Z=(e,r,i)=>se(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=K,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},K,this._config);this._configService.setConfig(w,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[j],[z]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[z]]),[B,q,H,W,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ue=e=>O.find(i=>e.includes(i)),ce=()=>O.map(e=>({label:e,value:e})),oe=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>G.map(e=>({label:e.label,value:e.suffix})),fe=()=>x.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=B,a.CURRENCYFORMAT=V,a.DATEFMTLISG=G,a.MenuCurrencyService=j,a.NUMBERFORMAT=x,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,a.SetCurrencyCommand=H,a.SetNumfmtCommand=$,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=oe,a.getCurrencyOptions=ce,a.getCurrencyType=ue,a.getDateFormatOptions=me,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=fe,a.getPatternPreview=Y,a.getPatternPreviewIgnoreGeneral=k,a.getPatternType=ee,a.isPatternHasDecimal=Q,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
20
+ (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.UniverEngineNumfmt,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,u,A,I,J){"use strict";var de=Object.defineProperty;var ge=(a,t,u)=>t in a?de(a,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):a[t]=u;var R=(a,t,u)=>ge(a,typeof t!="symbol"?t+"":t,u);const O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],x=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],X="SHEET_NUMFMT_PLUGIN",E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${D(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${D(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),$={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=u.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:v,worksheet:d}=l,c=r.values.filter(o=>!!o.pattern),T=r.values.filter(o=>!o.pattern),M=u.transformCellsToRange(m,v,c),y={unitId:m,subUnitId:v,ranges:T.map(o=>({startColumn:o.col,startRow:o.row,endColumn:o.col,endRow:o.row}))},b=[],h=[];if(c.length){const o=c.reduce((S,f)=>{A.isTextFormat(f.pattern)&&S.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const P=u.checkCellValueType(_.v);P!==_.t&&S.setValue(f.row,f.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),g=new t.ObjectMatrix;new t.ObjectMatrix(o).forValue((S,f)=>{const _=d.getCellRaw(S,f);_?g.setValue(S,f,{t:_.t}):g.setValue(S,f,{t:void 0})}),Object.keys(M.values).forEach(S=>{const f=M.values[S];f.ranges=u.rangeMerge(f.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const p=u.factorySetNumfmtUndoMutation(e,M);h.push(...p)}if(T.length){y.ranges=u.rangeMerge(y.ranges);const o=T.reduce((S,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const P=u.checkCellValueType(_.v);P!==_.t&&S.setValue(f.row,f.col,{t:P})}return S},new t.ObjectMatrix).getMatrix(),g=new t.ObjectMatrix;new t.ObjectMatrix(o).forValue((S,f)=>{const _=d.getCellRaw(S,f);_?g.setValue(S,f,{t:_.t}):g.setValue(S,f,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:v,cellValue:o}});const p=u.factoryRemoveNumfmtUndoMutation(e,y);h.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:v,cellValue:g.getMatrix()}},...p)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:h,redoMutations:b}),C}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:v,subUnitId:d}=m;let c=0;l.forEach(b=>{t.Range.foreach(b.range,(h,C)=>{const o=n.getValue(v,d,h,C);if(!o){const p=m.worksheet.getCellRaw(h,C);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const S=/\.(\d*)$/.exec(String(p.v));if(S){const f=S[1].length;if(!f)return;c=Math.max(c,f)}}return}const g=E(o.pattern);c=g>c?g:c})});const T=c+1,M=U(`0${T>0?".0":""}`,T),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(h,C)=>{const o=n.getValue(v,d,h,C);if(!o)y.push({row:h,col:C,pattern:M});else{const g=E(o.pattern),p=U(o.pattern,g+1);p!==o.pattern&&y.push({row:h,col:C,pattern:p})}})}),y.length?await r.executeCommand($.id,{values:y}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(j),s=L[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],v=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(T,M)=>{m.push({row:T,col:M,pattern:v,type:"currency"})})}),await r.executeCommand($.id,{values:m})}},W={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(v=>{t.Range.foreach(v.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:v,subUnitId:d}=m;let c=0;l.forEach(h=>{t.Range.foreach(h.range,(C,o)=>{const g=n.getValue(v,d,C,o);if(!g){const S=m.worksheet.getCellRaw(C,o);if(!c&&S&&S.t===t.CellValueType.NUMBER&&S.v){const f=/\.(\d*)$/.exec(String(S.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(g.pattern);c=p>c?p:c})});const T=c-1,M=U(`0${T>0?".0":"."}`,T),y=[];return l.forEach(h=>{t.Range.foreach(h.range,(C,o)=>{const g=n.getValue(v,d,C,o);if(!g)y.push({row:C,col:o,pattern:M});else{const p=E(g.pattern);y.push({row:C,col:o,pattern:U(g.pattern,p-1)})}})}),await r.executeCommand($.id,{values:y})}},w="sheets-numfmt.config",K={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Y=(e,r,i="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,l=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:l,color:s}:{result:l}},k=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:Y(e,r,i);var te=Object.getOwnPropertyDescriptor,ne=(e,r,i,n)=>{for(var s=n>1?void 0:n?te(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,r)=>(i,n)=>r(i,n,e);const re={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,v,d){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=v,this._configService=d,this._initInterceptorCellContent()}get local(){const i=this._local$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var C,o;const m=s.unitId,v=s.subUnitId;let d;const c=n;if(!c||c.v===void 0||c.v===null)return l(n);if(n!=null&&n.s){const g=s.workbook.getStyles().get(n.s);g!=null&&g.n&&(d=g.n)}if(d||(d=this._numfmtService.getValue(m,v,s.row,s.col)),!d||d.pattern==="General"||u.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),A.isTextFormat(d.pattern))return(C=this._configService.getConfig(w))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...re},l(n));let M="";const y=i.getValue(s.row,s.col);if(y&&y.parameters===`${c.v}_${d.pattern}`)return l({...n,...y.result});const b=k(d.pattern,Number(c.v),this.local);if(M=b.result,!M)return l(n);const h={v:M,t:t.CellValueType.NUMBER};if(b.color){const g=(o=this._themeService.getColorFromTheme(`${b.color}.500`))!=null?o:b.color;g&&(h.interceptorStyle={cl:{rgb:g}})}return i.setValue(s.row,s.col,{result:h,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,h),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(v=>{t.Range.foreach(v,(d,c)=>{i.realDeleteValue(d,c)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._local$.next(i)}},a.SheetsNumfmtCellContentController=ne([N(0,t.IUniverInstanceService),N(1,t.Inject(u.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(u.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);class z extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(i){this._currencySymbol$.next(i)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,le=(e,r,i,n)=>{for(var s=n>1?void 0:n?ie(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},F=(e,r)=>(i,n)=>r(i,n,e),Z=(e,r,i)=>se(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=K,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},K,this._config);this._configService.setConfig(w,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[j],[z]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[z]]),[B,q,H,W,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ue=e=>O.find(i=>e.includes(i)),ce=()=>O.map(e=>({label:e,value:e})),oe=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),me=()=>G.map(e=>({label:e.label,value:e.suffix})),fe=()=>x.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=B,a.CURRENCYFORMAT=V,a.DATEFMTLISG=G,a.MenuCurrencyService=j,a.NUMBERFORMAT=x,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,a.SetCurrencyCommand=H,a.SetNumfmtCommand=$,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=oe,a.getCurrencyOptions=ce,a.getCurrencyType=ue,a.getDateFormatOptions=me,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=fe,a.getPatternPreview=Y,a.getPatternPreviewIgnoreGeneral=k,a.getPatternType=ee,a.isPatternHasDecimal=Q,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
21
21
 
22
22
 
23
23
  // @univerjs/sheets-numfmt/facade
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/preset-sheets-node-core",
3
- "version": "0.8.0-nightly.202506071606",
3
+ "version": "0.8.0-nightly.202506091607",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -60,23 +60,23 @@
60
60
  "rxjs": ">=7.0.0"
61
61
  },
62
62
  "dependencies": {
63
- "@univerjs/docs": "0.8.0-nightly.202506071606",
64
- "@univerjs/engine-formula": "0.8.0-nightly.202506071606",
65
- "@univerjs/engine-render": "0.8.0-nightly.202506071606",
66
- "@univerjs/rpc-node": "0.8.0-nightly.202506071606",
67
- "@univerjs/sheets": "0.8.0-nightly.202506071606",
68
- "@univerjs/sheets-data-validation": "0.8.0-nightly.202506071606",
69
- "@univerjs/sheets-drawing": "0.8.0-nightly.202506071606",
70
- "@univerjs/sheets-filter": "0.8.0-nightly.202506071606",
71
- "@univerjs/sheets-formula": "0.8.0-nightly.202506071606",
72
- "@univerjs/sheets-hyper-link": "0.8.0-nightly.202506071606",
73
- "@univerjs/sheets-numfmt": "0.8.0-nightly.202506071606",
74
- "@univerjs/sheets-sort": "0.8.0-nightly.202506071606",
75
- "@univerjs/sheets-thread-comment": "0.8.0-nightly.202506071606",
76
- "@univerjs/thread-comment": "0.8.0-nightly.202506071606"
63
+ "@univerjs/docs": "0.8.0-nightly.202506091607",
64
+ "@univerjs/engine-formula": "0.8.0-nightly.202506091607",
65
+ "@univerjs/engine-render": "0.8.0-nightly.202506091607",
66
+ "@univerjs/rpc-node": "0.8.0-nightly.202506091607",
67
+ "@univerjs/sheets": "0.8.0-nightly.202506091607",
68
+ "@univerjs/sheets-data-validation": "0.8.0-nightly.202506091607",
69
+ "@univerjs/sheets-drawing": "0.8.0-nightly.202506091607",
70
+ "@univerjs/sheets-filter": "0.8.0-nightly.202506091607",
71
+ "@univerjs/sheets-formula": "0.8.0-nightly.202506091607",
72
+ "@univerjs/sheets-hyper-link": "0.8.0-nightly.202506091607",
73
+ "@univerjs/sheets-numfmt": "0.8.0-nightly.202506091607",
74
+ "@univerjs/sheets-sort": "0.8.0-nightly.202506091607",
75
+ "@univerjs/sheets-thread-comment": "0.8.0-nightly.202506091607",
76
+ "@univerjs/thread-comment": "0.8.0-nightly.202506091607"
77
77
  },
78
78
  "devDependencies": {
79
- "@univerjs/core": "0.8.0-nightly.202506071606",
79
+ "@univerjs/core": "0.8.0-nightly.202506091607",
80
80
  "rxjs": "7.8.2",
81
81
  "typescript": "^5.8.3",
82
82
  "@univerjs-infra/shared": "0.8.0"