@univerjs/sheets-numfmt 0.6.10 → 0.7.0-nightly.202504291607

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Z=Object.defineProperty;var J=(e,n,s)=>n in e?Z(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s;var T=(e,n,s)=>J(e,typeof n!="symbol"?n+"":n,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),A=require("@univerjs/engine-numfmt"),N=require("rxjs"),X=require("@univerjs/engine-formula"),U=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],Q="SHEET_NUMFMT_PLUGIN",E=(e,n=0)=>{var r;return e&&(r=t.numfmt.getInfo(e).maxDecimals)!=null?r:n},ee=(e,n)=>{if(e&&!n||!e&&n)return!1;const s=i=>i.reduce((S,v)=>{if(S.isEnd)return S;const h=v.value||v.num;return v.type==="point"?(S.isEnd=!0,S):{...S,result:S.result+h}},{isEnd:!1,result:""}).result,r=t.numfmt.getInfo(e)._partitions,o=t.numfmt.getInfo(n)._partitions,a=s(r[0].tokens),l=s(o[0].tokens),g=s(r[1].tokens),m=s(o[1].tokens);return a===l&&g===m&&r[1].color===o[1].color},O=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,n)=>e.split(";").map(r=>/\.0?/.test(r)?r.replace(/\.0*/g,`${n>0?".":""}${O(Number(n||0))}`):/0([^0]?)|0$/.test(r)?r.replace(/0([^0]+)|0$/,`0${n>0?".":""}${O(Number(n||0))}$1`):r).join(";"),te=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,n)=>{if(!n)return!1;const s=e.get(t.ICommandService),r=e.get(t.IUniverInstanceService),o=e.get(t.IUndoRedoService),a=f.getSheetCommandTarget(r,n);if(!a)return!1;const{unitId:l,subUnitId:g,worksheet:m}=a,i=n.values.filter(c=>!!c.pattern),S=n.values.filter(c=>!c.pattern),v=f.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:S.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],p=[];if(i.length){const c=i.reduce((d,u)=>{A.isTextFormat(u.pattern)&&d.setValue(u.row,u.col,{t:t.CellValueType.STRING});const b=m.getCellRaw(u.row,u.col);if(b){const $=f.checkCellValueType(b.v);$!==b.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const b=m.getCellRaw(d,u);b?y.setValue(d,u,{t:b.t}):y.setValue(d,u,{t:void 0})}),Object.keys(v.values).forEach(d=>{const u=v.values[d];u.ranges=f.rangeMerge(u.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:v});const _=f.factorySetNumfmtUndoMutation(e,v);p.push(..._)}if(S.length){h.ranges=f.rangeMerge(h.ranges);const c=S.reduce((d,u)=>{const b=m.getCellRaw(u.row,u.col);if(b){const $=f.checkCellValueType(b.v);$!==b.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const b=m.getCellRaw(d,u);b?y.setValue(d,u,{t:b.t}):y.setValue(d,u,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const _=f.factoryRemoveNumfmtUndoMutation(e,h);p.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:y.getMatrix()}},..._)}const C=t.sequenceExecute(M,s).result;return C&&o.pushUndoRedo({unitID:l,undoMutations:p,redoMutations:M}),C}},H={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),r=e.get(f.INumfmtService),o=e.get(t.IUniverInstanceService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const l=f.getSheetCommandTarget(o);if(!l)return!1;const{unitId:g,subUnitId:m}=l;let i=0;a.forEach(M=>{t.Range.foreach(M.range,(p,C)=>{const c=r.getValue(g,m,p,C);if(!c){const _=l.worksheet.getCellRaw(p,C);if(!i&&_&&_.t===t.CellValueType.NUMBER&&_.v){const d=/\.(\d*)$/.exec(String(_.v));if(d){const u=d[1].length;if(!u)return;i=Math.max(i,u)}}return}const y=E(c.pattern);i=y>i?y:i})});const S=i+1,v=P(`0${S>0?".0":""}`,S),h=[];return a.forEach(M=>{t.Range.foreach(M.range,(p,C)=>{const c=r.getValue(g,m,p,C);if(!c)h.push({row:p,col:C,pattern:v});else{const y=E(c.pattern),_=P(c.pattern,y+1);_!==c.pattern&&h.push({row:p,col:C,pattern:_})}})}),h.length?await n.executeCommand(R.id,{values:h}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(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),r=e.get(D),o=L[r.getCurrencySymbol()]||"$",a=s.getCurrentSelections();if(!a||!a.length)return!1;const l=[],g=V[4].suffix(o);return a.forEach(i=>{t.Range.foreach(i.range,(S,v)=>{l.push({row:S,col:v,pattern:g,type:"currency"})})}),await n.executeCommand(R.id,{values:l})}},q={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),r=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!r||!r.length)return!1;const o=[],a="0%";return r.forEach(g=>{t.Range.foreach(g.range,(m,i)=>{o.push({row:m,col:i,pattern:a,type:"percent"})})}),await n.executeCommand(R.id,{values:o})}},k={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),r=e.get(f.INumfmtService),o=e.get(t.IUniverInstanceService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const l=f.getSheetCommandTarget(o);if(!l)return!1;const{unitId:g,subUnitId:m}=l;let i=0;a.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const y=r.getValue(g,m,C,c);if(!y){const d=l.worksheet.getCellRaw(C,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const u=/\.(\d*)$/.exec(String(d.v));if(u){const b=u[1].length;if(!b)return;i=Math.max(i,b)}}return}const _=E(y.pattern);i=_>i?_:i})});const S=i-1,v=P(`0${S>0?".0":"."}`,S),h=[];return a.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const y=r.getValue(g,m,C,c);if(!y)h.push({row:C,col:c,pattern:v});else{const _=E(y.pattern);h.push({row:C,col:c,pattern:P(y.pattern,_-1)})}})}),await n.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",j={},ne=e=>t.numfmt.getInfo(e).type||"unknown",K=(e,n,s="en")=>{const o=t.numfmt.getInfo(e)._partitions[1],a=t.numfmt.format(e,n,{locale:s,throws:!1});return n<0?{result:a,color:o.color}:{result:a}},Y=(e,n,s)=>e==="General"?{result:String(X.stripErrorMargin(n))}:K(e,n,s);var re=Object.getOwnPropertyDescriptor,se=(e,n,s,r)=>{for(var o=r>1?void 0:r?re(n,s):n,a=e.length-1,l;a>=0;a--)(l=e[a])&&(o=l(o)||o);return o},I=(e,n)=>(s,r)=>n(s,r,e);const oe={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,r,o,a,l,g,m){super();T(this,"_local$",new N.BehaviorSubject("en"));T(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=r,this._themeService=o,this._commandService=a,this._numfmtService=l,this._localeService=g,this._configService=m,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(r,o,a)=>{var C;const l=o.unitId,g=o.subUnitId;let m;const i=r;if(!i)return a(r);if(r!=null&&r.s){const c=o.workbook.getStyles().get(r.s);c!=null&&c.n&&(m=c.n)}if(m||(m=this._numfmtService.getValue(l,g,o.row,o.col)),!m||(r.t||f.checkCellValueType(i.v))!==t.CellValueType.NUMBER)return a(r);if(A.isTextFormat(m.pattern))return(C=this._configService.getConfig(w))!=null&&C.disableTextFormatMark?a({...r,t:t.CellValueType.STRING}):a({...r,t:t.CellValueType.STRING,markers:{...r==null?void 0:r.markers,...oe}});let v="";const h=s.getValue(o.row,o.col);if(h&&h.parameters===`${i.v}_${m.pattern}`)return a({...r,...h.result});const M=Y(m.pattern,Number(i.v),this.local);if(v=M.result,!v)return a(r);const p={v,t:t.CellValueType.NUMBER};if(M.color){const c=this._themeService.getCurrentTheme()[`${M.color}500`];c&&(p.interceptorStyle={cl:{rgb:c}})}return s.setValue(o.row,o.col,{result:p,parameters:`${i.v}_${m.pattern}`}),a({...r,...p})},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===f.SetNumfmtMutation.id){const o=r.params;Object.keys(o.values).forEach(a=>{o.values[a].ranges.forEach(g=>{t.Range.foreach(g,(m,i)=>{s.realDeleteValue(m,i)})})})}else if(r.id===f.SetRangeValuesMutation.id){const o=r.params;new t.ObjectMatrix(o.cellValue).forValue((a,l)=>{s.realDeleteValue(a,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(r=>{var o;return(o=r==null?void 0:r.activeSheet$)!=null?o:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=se([I(0,t.IUniverInstanceService),I(1,t.Inject(f.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(f.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);class F extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,ie=(e,n,s)=>n in e?ae(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s,le=(e,n,s,r)=>{for(var o=r>1?void 0:r?ce(n,s):n,a=e.length-1,l;a>=0;a--)(l=e[a])&&(o=l(o)||o);return o},x=(e,n)=>(s,r)=>n(s,r,e),z=(e,n,s)=>ie(e,typeof n!="symbol"?n+"":n,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(n=j,s,r,o){super(),this._config=n,this._injector=s,this._configService=r,this._commandService=o;const{...a}=t.merge({},j,this._config);this._configService.setConfig(w,a)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[F]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[F]]),[H,k,W,q,R].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",Q);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=le([t.DependentOn(f.UniverSheetsPlugin),x(1,t.Inject(t.Injector)),x(2,t.IConfigService),x(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ue=e=>U.find(s=>e.includes(s)),me=()=>U.map(e=>({label:e,value:e})),fe=e=>V.map(n=>({label:n.label(e),value:n.suffix(e),color:n.color})),de=()=>G.map(e=>({label:e.label,value:e.suffix})),ge=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=G;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=q;exports.SubtractDecimalCommand=k;exports.countryCurrencyMap=L;exports.currencySymbols=U;exports.getCurrencyFormatOptions=fe;exports.getCurrencyOptions=me;exports.getCurrencyType=ue;exports.getDateFormatOptions=de;exports.getDecimalFromPattern=E;exports.getDecimalString=O;exports.getNumberFormatOptions=ge;exports.getPatternPreview=K;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=ne;exports.isPatternEqualWithoutDecimal=ee;exports.isPatternHasDecimal=te;exports.setPatternDecimal=P;
1
+ "use strict";var Z=Object.defineProperty;var J=(e,r,s)=>r in e?Z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var T=(e,r,s)=>J(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),A=require("@univerjs/engine-numfmt"),N=require("rxjs"),X=require("@univerjs/engine-formula"),x=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],Q="SHEET_NUMFMT_PLUGIN",E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getInfo(e).maxDecimals)!=null?n:r},ee=(e,r)=>{if(e&&!r||!e&&r)return!1;const s=i=>i.reduce((S,C)=>{if(S.isEnd)return S;const h=C.value||C.num;return C.type==="point"?(S.isEnd=!0,S):{...S,result:S.result+h}},{isEnd:!1,result:""}).result,n=t.numfmt.getInfo(e)._partitions,a=t.numfmt.getInfo(r)._partitions,o=s(n[0].tokens),l=s(a[0].tokens),g=s(n[1].tokens),m=s(a[1].tokens);return o===l&&g===m&&n[1].color===a[1].color},U=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${U(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${U(Number(r||0))}$1`):n).join(";"),te=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:g,worksheet:m}=o,i=r.values.filter(c=>!!c.pattern),S=r.values.filter(c=>!c.pattern),C=f.transformCellsToRange(l,g,i),h={unitId:l,subUnitId:g,ranges:S.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],p=[];if(i.length){const c=i.reduce((d,u)=>{A.isTextFormat(u.pattern)&&d.setValue(u.row,u.col,{t:t.CellValueType.STRING});const b=m.getCellRaw(u.row,u.col);if(b){const $=f.checkCellValueType(b.v);$!==b.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const b=m.getCellRaw(d,u);b?y.setValue(d,u,{t:b.t}):y.setValue(d,u,{t:void 0})}),Object.keys(C.values).forEach(d=>{const u=C.values[d];u.ranges=f.rangeMerge(u.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:C});const _=f.factorySetNumfmtUndoMutation(e,C);p.push(..._)}if(S.length){h.ranges=f.rangeMerge(h.ranges);const c=S.reduce((d,u)=>{const b=m.getCellRaw(u.row,u.col);if(b){const $=f.checkCellValueType(b.v);$!==b.t&&d.setValue(u.row,u.col,{t:$})}return d},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((d,u)=>{const b=m.getCellRaw(d,u);b?y.setValue(d,u,{t:b.t}):y.setValue(d,u,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:h},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:c}});const _=f.factoryRemoveNumfmtUndoMutation(e,h);p.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:g,cellValue:y.getMatrix()}},..._)}const v=t.sequenceExecute(M,s).result;return v&&a.pushUndoRedo({unitID:l,undoMutations:p,redoMutations:M}),v}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:g,subUnitId:m}=l;let i=0;o.forEach(M=>{t.Range.foreach(M.range,(p,v)=>{const c=n.getValue(g,m,p,v);if(!c){const _=l.worksheet.getCellRaw(p,v);if(!i&&_&&_.t===t.CellValueType.NUMBER&&_.v){const d=/\.(\d*)$/.exec(String(_.v));if(d){const u=d[1].length;if(!u)return;i=Math.max(i,u)}}return}const y=E(c.pattern);i=y>i?y:i})});const S=i+1,C=P(`0${S>0?".0":""}`,S),h=[];return o.forEach(M=>{t.Range.foreach(M.range,(p,v)=>{const c=n.getValue(g,m,p,v);if(!c)h.push({row:p,col:v,pattern:C});else{const y=E(c.pattern),_=P(c.pattern,y+1);_!==c.pattern&&h.push({row:p,col:v,pattern:_})}})}),h.length?await r.executeCommand(R.id,{values:h}):!1}};class D{constructor(){T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(D),a=L[n.getCurrencySymbol()]||"$",o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=[],g=V[4].suffix(a);return o.forEach(i=>{t.Range.foreach(i.range,(S,C)=>{l.push({row:S,col:C,pattern:g,type:"currency"})})}),await r.executeCommand(R.id,{values:l})}},q={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(g=>{t.Range.foreach(g.range,(m,i)=>{a.push({row:m,col:i,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},k={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:g,subUnitId:m}=l;let i=0;o.forEach(p=>{t.Range.foreach(p.range,(v,c)=>{const y=n.getValue(g,m,v,c);if(!y){const d=l.worksheet.getCellRaw(v,c);if(!i&&d&&d.t===t.CellValueType.NUMBER&&d.v){const u=/\.(\d*)$/.exec(String(d.v));if(u){const b=u[1].length;if(!b)return;i=Math.max(i,b)}}return}const _=E(y.pattern);i=_>i?_:i})});const S=i-1,C=P(`0${S>0?".0":"."}`,S),h=[];return o.forEach(p=>{t.Range.foreach(p.range,(v,c)=>{const y=n.getValue(g,m,v,c);if(!y)h.push({row:v,col:c,pattern:C});else{const _=E(y.pattern);h.push({row:v,col:c,pattern:P(y.pattern,_-1)})}})}),await r.executeCommand(R.id,{values:h})}},w="sheets-numfmt.config",j={},ne=e=>t.numfmt.getInfo(e).type||"unknown",K=(e,r,s="en")=>{const a=t.numfmt.getInfo(e)._partitions[1],o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a.color}:{result:o}},Y=(e,r,s)=>e==="General"?{result:String(X.stripErrorMargin(r))}:K(e,r,s);var re=Object.getOwnPropertyDescriptor,se=(e,r,s,n)=>{for(var a=n>1?void 0:n?re(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},I=(e,r)=>(s,n)=>r(s,n,e);const oe={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,g,m){super();T(this,"_local$",new N.BehaviorSubject("en"));T(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=g,this._configService=m,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var v;const l=a.unitId,g=a.subUnitId;let m;const i=n;if(!i)return o(n);if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(m=c.n)}if(m||(m=this._numfmtService.getValue(l,g,a.row,a.col)),!m||(n.t||f.checkCellValueType(i.v))!==t.CellValueType.NUMBER)return o(n);if(A.isTextFormat(m.pattern))return(v=this._configService.getConfig(w))!=null&&v.disableTextFormatMark?o({...n,t:t.CellValueType.STRING}):o({...n,t:t.CellValueType.STRING,markers:{...n==null?void 0:n.markers,...oe}});let C="";const h=s.getValue(a.row,a.col);if(h&&h.parameters===`${i.v}_${m.pattern}`)return o({...n,...h.result});if(i.v===void 0||i.v===null)return o(n);const M=Y(m.pattern,Number(i.v),this.local);if(C=M.result,!C)return o(n);const p={v:C,t:t.CellValueType.NUMBER};if(M.color){const c=this._themeService.getCurrentTheme()[`${M.color}500`];c&&(p.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:p,parameters:`${i.v}_${m.pattern}`}),o({...n,...p})},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(g=>{t.Range.foreach(g,(m,i)=>{s.realDeleteValue(m,i)})})})}else if(n.id===f.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:N.of(null)}),N.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=se([I(0,t.IUniverInstanceService),I(1,t.Inject(f.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(f.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);class F extends t.Disposable{constructor(){super(...arguments);T(this,"_currencySymbol$",new N.BehaviorSubject("US"));T(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var ae=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,ie=(e,r,s)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,le=(e,r,s,n)=>{for(var a=n>1?void 0:n?ce(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},O=(e,r)=>(s,n)=>r(s,n,e),z=(e,r,s)=>ie(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=j,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},j,this._config);this._configService.setConfig(w,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[F]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[F]]),[H,k,W,q,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",Q);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=le([t.DependentOn(f.UniverSheetsPlugin),O(1,t.Inject(t.Injector)),O(2,t.IConfigService),O(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ue=e=>x.find(s=>e.includes(s)),me=()=>x.map(e=>({label:e,value:e})),fe=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),de=()=>G.map(e=>({label:e.label,value:e.suffix})),ge=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=V;exports.DATEFMTLISG=G;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=q;exports.SubtractDecimalCommand=k;exports.countryCurrencyMap=L;exports.currencySymbols=x;exports.getCurrencyFormatOptions=fe;exports.getCurrencyOptions=me;exports.getCurrencyType=ue;exports.getDateFormatOptions=de;exports.getDecimalFromPattern=E;exports.getDecimalString=U;exports.getNumberFormatOptions=ge;exports.getPatternPreview=K;exports.getPatternPreviewIgnoreGeneral=Y;exports.getPatternType=ne;exports.isPatternEqualWithoutDecimal=ee;exports.isPatternHasDecimal=te;exports.setPatternDecimal=P;
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var ae = Object.defineProperty;
2
2
  var le = (e, t, n) => t in e ? ae(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var M = (e, t, n) => le(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { numfmt as x, CommandType as P, ICommandService as E, IUniverInstanceService as F, IUndoRedoService as ue, CellValueType as I, ObjectMatrix as b, sequenceExecute as me, Range as N, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as K, UniverInstanceType as ee, DependentOn as ge, Injector as he, Plugin as pe, merge as Se, registerDependencies as ve, touchDependencies as z } from "@univerjs/core";
4
+ import { numfmt as x, CommandType as P, ICommandService as E, IUniverInstanceService as F, IUndoRedoService as ue, CellValueType as I, ObjectMatrix as b, sequenceExecute as me, Range as N, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as K, UniverInstanceType as ee, DependentOn as ge, Injector as he, Plugin as ve, merge as pe, registerDependencies as Se, touchDependencies as z } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as Y, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ie } from "@univerjs/sheets";
6
6
  import { isTextFormat as ne } from "@univerjs/engine-numfmt";
7
7
  import { BehaviorSubject as k, merge as Ne, switchMap as Ee, of as Te, skip as xe } from "rxjs";
@@ -182,15 +182,15 @@ const re = [
182
182
  if (e && !t || !e && t)
183
183
  return !1;
184
184
  const n = (u) => u.reduce(
185
- (g, p) => {
185
+ (g, v) => {
186
186
  if (g.isEnd)
187
187
  return g;
188
- const h = p.value || p.num;
189
- return p.type === "point" ? (g.isEnd = !0, g) : { ...g, result: g.result + h };
188
+ const h = v.value || v.num;
189
+ return v.type === "point" ? (g.isEnd = !0, g) : { ...g, result: g.result + h };
190
190
  },
191
191
  { isEnd: !1, result: "" }
192
- ).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens), c = n(s[0].tokens), i = n(r[1].tokens), d = n(s[1].tokens);
193
- return o === c && i === d && r[1].color === s[1].color;
192
+ ).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens), c = n(s[0].tokens), i = n(r[1].tokens), m = n(s[1].tokens);
193
+ return o === c && i === m && r[1].color === s[1].color;
194
194
  }, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), O = (e, t) => e.split(";").map((r) => /\.0?/.test(r) ? r.replace(
195
195
  /\.0*/g,
196
196
  `${t > 0 ? "." : ""}${q(Number(t || 0))}`
@@ -206,7 +206,7 @@ const re = [
206
206
  return !1;
207
207
  const n = e.get(E), r = e.get(F), s = e.get(ue), o = H(r, t);
208
208
  if (!o) return !1;
209
- const { unitId: c, subUnitId: i, worksheet: d } = o, u = t.values.filter((l) => !!l.pattern), g = t.values.filter((l) => !l.pattern), p = ye(c, i, u), h = {
209
+ const { unitId: c, subUnitId: i, worksheet: m } = o, u = t.values.filter((l) => !!l.pattern), g = t.values.filter((l) => !l.pattern), v = ye(c, i, u), h = {
210
210
  unitId: c,
211
211
  subUnitId: i,
212
212
  ranges: g.map((l) => ({
@@ -215,43 +215,43 @@ const re = [
215
215
  endColumn: l.col,
216
216
  endRow: l.row
217
217
  }))
218
- }, C = [], v = [];
218
+ }, C = [], S = [];
219
219
  if (u.length) {
220
- const l = u.reduce((f, a) => {
221
- ne(a.pattern) && f.setValue(a.row, a.col, { t: I.STRING });
222
- const _ = d.getCellRaw(a.row, a.col);
220
+ const l = u.reduce((d, a) => {
221
+ ne(a.pattern) && d.setValue(a.row, a.col, { t: I.STRING });
222
+ const _ = m.getCellRaw(a.row, a.col);
223
223
  if (_) {
224
224
  const V = G(_.v);
225
- V !== _.t && f.setValue(a.row, a.col, { t: V });
225
+ V !== _.t && d.setValue(a.row, a.col, { t: V });
226
226
  }
227
- return f;
228
- }, new b()).getMatrix(), S = new b();
229
- new b(l).forValue((f, a) => {
230
- const _ = d.getCellRaw(f, a);
231
- _ ? S.setValue(f, a, { t: _.t }) : S.setValue(f, a, { t: void 0 });
232
- }), Object.keys(p.values).forEach((f) => {
233
- const a = p.values[f];
227
+ return d;
228
+ }, new b()).getMatrix(), p = new b();
229
+ new b(l).forValue((d, a) => {
230
+ const _ = m.getCellRaw(d, a);
231
+ _ ? p.setValue(d, a, { t: _.t }) : p.setValue(d, a, { t: void 0 });
232
+ }), Object.keys(v.values).forEach((d) => {
233
+ const a = v.values[d];
234
234
  a.ranges = Y(a.ranges);
235
235
  }), C.push({
236
236
  id: te.id,
237
- params: p
237
+ params: v
238
238
  });
239
- const y = _e(e, p);
240
- v.push(...y);
239
+ const y = _e(e, v);
240
+ S.push(...y);
241
241
  }
242
242
  if (g.length) {
243
243
  h.ranges = Y(h.ranges);
244
- const l = g.reduce((f, a) => {
245
- const _ = d.getCellRaw(a.row, a.col);
244
+ const l = g.reduce((d, a) => {
245
+ const _ = m.getCellRaw(a.row, a.col);
246
246
  if (_) {
247
247
  const V = G(_.v);
248
- V !== _.t && f.setValue(a.row, a.col, { t: V });
248
+ V !== _.t && d.setValue(a.row, a.col, { t: V });
249
249
  }
250
- return f;
251
- }, new b()).getMatrix(), S = new b();
252
- new b(l).forValue((f, a) => {
253
- const _ = d.getCellRaw(f, a);
254
- _ ? S.setValue(f, a, { t: _.t }) : S.setValue(f, a, { t: void 0 });
250
+ return d;
251
+ }, new b()).getMatrix(), p = new b();
252
+ new b(l).forValue((d, a) => {
253
+ const _ = m.getCellRaw(d, a);
254
+ _ ? p.setValue(d, a, { t: _.t }) : p.setValue(d, a, { t: void 0 });
255
255
  }), C.push({
256
256
  id: Ce.id,
257
257
  params: h
@@ -264,21 +264,21 @@ const re = [
264
264
  }
265
265
  });
266
266
  const y = be(e, h);
267
- v.push({
267
+ S.push({
268
268
  id: B.id,
269
269
  params: {
270
270
  unitId: c,
271
271
  subUnitId: i,
272
- cellValue: S.getMatrix()
272
+ cellValue: p.getMatrix()
273
273
  }
274
274
  }, ...y);
275
275
  }
276
- const m = me(C, n).result;
277
- return m && s.pushUndoRedo({
276
+ const f = me(C, n).result;
277
+ return f && s.pushUndoRedo({
278
278
  unitID: c,
279
- undoMutations: v,
279
+ undoMutations: S,
280
280
  redoMutations: C
281
- }), m;
281
+ }), f;
282
282
  }
283
283
  }, De = {
284
284
  id: "sheet.command.numfmt.add.decimal.command",
@@ -289,17 +289,17 @@ const re = [
289
289
  return !1;
290
290
  const c = H(s);
291
291
  if (!c) return !1;
292
- const { unitId: i, subUnitId: d } = c;
292
+ const { unitId: i, subUnitId: m } = c;
293
293
  let u = 0;
294
294
  o.forEach((C) => {
295
- N.foreach(C.range, (v, m) => {
296
- const l = r.getValue(i, d, v, m);
295
+ N.foreach(C.range, (S, f) => {
296
+ const l = r.getValue(i, m, S, f);
297
297
  if (!l) {
298
- const y = c.worksheet.getCellRaw(v, m);
298
+ const y = c.worksheet.getCellRaw(S, f);
299
299
  if (!u && y && y.t === I.NUMBER && y.v) {
300
- const f = /\.(\d*)$/.exec(String(y.v));
301
- if (f) {
302
- const a = f[1].length;
300
+ const d = /\.(\d*)$/.exec(String(y.v));
301
+ if (d) {
302
+ const a = d[1].length;
303
303
  if (!a)
304
304
  return;
305
305
  u = Math.max(u, a);
@@ -307,25 +307,25 @@ const re = [
307
307
  }
308
308
  return;
309
309
  }
310
- const S = w(l.pattern);
311
- u = S > u ? S : u;
310
+ const p = w(l.pattern);
311
+ u = p > u ? p : u;
312
312
  });
313
313
  });
314
- const g = u + 1, p = O(`0${g > 0 ? ".0" : ""}`, g), h = [];
314
+ const g = u + 1, v = O(`0${g > 0 ? ".0" : ""}`, g), h = [];
315
315
  return o.forEach((C) => {
316
- N.foreach(C.range, (v, m) => {
317
- const l = r.getValue(i, d, v, m);
316
+ N.foreach(C.range, (S, f) => {
317
+ const l = r.getValue(i, m, S, f);
318
318
  if (!l)
319
319
  h.push({
320
- row: v,
321
- col: m,
322
- pattern: p
320
+ row: S,
321
+ col: f,
322
+ pattern: v
323
323
  });
324
324
  else {
325
- const S = w(l.pattern), y = O(l.pattern, S + 1);
325
+ const p = w(l.pattern), y = O(l.pattern, p + 1);
326
326
  y !== l.pattern && h.push({
327
- row: v,
328
- col: m,
327
+ row: S,
328
+ col: f,
329
329
  pattern: y
330
330
  });
331
331
  }
@@ -357,8 +357,8 @@ const Ae = {
357
357
  return !1;
358
358
  const c = [], i = se[4].suffix(s);
359
359
  return o.forEach((u) => {
360
- N.foreach(u.range, (g, p) => {
361
- c.push({ row: g, col: p, pattern: i, type: "currency" });
360
+ N.foreach(u.range, (g, v) => {
361
+ c.push({ row: g, col: v, pattern: i, type: "currency" });
362
362
  });
363
363
  }), await t.executeCommand(U.id, { values: c });
364
364
  }
@@ -371,8 +371,8 @@ const Ae = {
371
371
  return !1;
372
372
  const s = [], o = "0%";
373
373
  return r.forEach((i) => {
374
- N.foreach(i.range, (d, u) => {
375
- s.push({ row: d, col: u, pattern: o, type: "percent" });
374
+ N.foreach(i.range, (m, u) => {
375
+ s.push({ row: m, col: u, pattern: o, type: "percent" });
376
376
  });
377
377
  }), await t.executeCommand(U.id, { values: s });
378
378
  }
@@ -385,15 +385,15 @@ const Ae = {
385
385
  return !1;
386
386
  const c = H(s);
387
387
  if (!c) return !1;
388
- const { unitId: i, subUnitId: d } = c;
388
+ const { unitId: i, subUnitId: m } = c;
389
389
  let u = 0;
390
- o.forEach((v) => {
391
- N.foreach(v.range, (m, l) => {
392
- const S = r.getValue(i, d, m, l);
393
- if (!S) {
394
- const f = c.worksheet.getCellRaw(m, l);
395
- if (!u && f && f.t === I.NUMBER && f.v) {
396
- const a = /\.(\d*)$/.exec(String(f.v));
390
+ o.forEach((S) => {
391
+ N.foreach(S.range, (f, l) => {
392
+ const p = r.getValue(i, m, f, l);
393
+ if (!p) {
394
+ const d = c.worksheet.getCellRaw(f, l);
395
+ if (!u && d && d.t === I.NUMBER && d.v) {
396
+ const a = /\.(\d*)$/.exec(String(d.v));
397
397
  if (a) {
398
398
  const _ = a[1].length;
399
399
  if (!_)
@@ -403,26 +403,26 @@ const Ae = {
403
403
  }
404
404
  return;
405
405
  }
406
- const y = w(S.pattern);
406
+ const y = w(p.pattern);
407
407
  u = y > u ? y : u;
408
408
  });
409
409
  });
410
- const g = u - 1, p = O(`0${g > 0 ? ".0" : "."}`, g), h = [];
411
- return o.forEach((v) => {
412
- N.foreach(v.range, (m, l) => {
413
- const S = r.getValue(i, d, m, l);
414
- if (!S)
410
+ const g = u - 1, v = O(`0${g > 0 ? ".0" : "."}`, g), h = [];
411
+ return o.forEach((S) => {
412
+ N.foreach(S.range, (f, l) => {
413
+ const p = r.getValue(i, m, f, l);
414
+ if (!p)
415
415
  h.push({
416
- row: m,
416
+ row: f,
417
417
  col: l,
418
- pattern: p
418
+ pattern: v
419
419
  });
420
420
  else {
421
- const y = w(S.pattern);
421
+ const y = w(p.pattern);
422
422
  h.push({
423
- row: m,
423
+ row: f,
424
424
  col: l,
425
- pattern: O(S.pattern, y - 1)
425
+ pattern: O(p.pattern, y - 1)
426
426
  });
427
427
  }
428
428
  });
@@ -486,21 +486,22 @@ let D = class extends Q {
486
486
  t.reset();
487
487
  })), this.disposeWithMe(this._sheetInterceptorService.intercept($e.CELL_CONTENT, {
488
488
  effect: K.Value | K.Style,
489
+ // eslint-disable-next-line complexity
489
490
  handler: (n, r, s) => {
490
- var v;
491
+ var S;
491
492
  const o = r.unitId, c = r.subUnitId;
492
493
  let i;
493
- const d = n;
494
- if (!d)
494
+ const m = n;
495
+ if (!m)
495
496
  return s(n);
496
497
  if (n != null && n.s) {
497
- const m = r.workbook.getStyles().get(n.s);
498
- m != null && m.n && (i = m.n);
498
+ const f = r.workbook.getStyles().get(n.s);
499
+ f != null && f.n && (i = f.n);
499
500
  }
500
- if (i || (i = this._numfmtService.getValue(o, c, r.row, r.col)), !i || (n.t || G(d.v)) !== I.NUMBER)
501
+ if (i || (i = this._numfmtService.getValue(o, c, r.row, r.col)), !i || (n.t || G(m.v)) !== I.NUMBER)
501
502
  return s(n);
502
503
  if (ne(i.pattern))
503
- return (v = this._configService.getConfig(ce)) != null && v.disableTextFormatMark ? s({
504
+ return (S = this._configService.getConfig(ce)) != null && S.disableTextFormatMark ? s({
504
505
  ...n,
505
506
  t: I.STRING
506
507
  }) : s({
@@ -512,20 +513,22 @@ let D = class extends Q {
512
513
  }
513
514
  });
514
515
  let g = "";
515
- const p = t.getValue(r.row, r.col);
516
- if (p && p.parameters === `${d.v}_${i.pattern}`)
517
- return s({ ...n, ...p.result });
518
- const h = Ge(i.pattern, Number(d.v), this.local);
516
+ const v = t.getValue(r.row, r.col);
517
+ if (v && v.parameters === `${m.v}_${i.pattern}`)
518
+ return s({ ...n, ...v.result });
519
+ if (m.v === void 0 || m.v === null)
520
+ return s(n);
521
+ const h = Ge(i.pattern, Number(m.v), this.local);
519
522
  if (g = h.result, !g)
520
523
  return s(n);
521
524
  const C = { v: g, t: I.NUMBER };
522
525
  if (h.color) {
523
- const m = this._themeService.getCurrentTheme()[`${h.color}500`];
524
- m && (C.interceptorStyle = { cl: { rgb: m } });
526
+ const f = this._themeService.getCurrentTheme()[`${h.color}500`];
527
+ f && (C.interceptorStyle = { cl: { rgb: f } });
525
528
  }
526
529
  return t.setValue(r.row, r.col, {
527
530
  result: C,
528
- parameters: `${d.v}_${i.pattern}`
531
+ parameters: `${m.v}_${i.pattern}`
529
532
  }), s({ ...n, ...C });
530
533
  },
531
534
  priority: Re.NUMFMT
@@ -534,8 +537,8 @@ let D = class extends Q {
534
537
  const r = n.params;
535
538
  Object.keys(r.values).forEach((s) => {
536
539
  r.values[s].ranges.forEach((c) => {
537
- N.foreach(c, (i, d) => {
538
- t.realDeleteValue(i, d);
540
+ N.foreach(c, (i, m) => {
541
+ t.realDeleteValue(i, m);
539
542
  });
540
543
  });
541
544
  });
@@ -589,10 +592,10 @@ var ke = Object.defineProperty, Ke = Object.getOwnPropertyDescriptor, ze = (e, t
589
592
  (c = e[o]) && (s = c(s) || s);
590
593
  return s;
591
594
  }, L = (e, t) => (n, r) => t(n, r, e), ie = (e, t, n) => ze(e, typeof t != "symbol" ? t + "" : t, n);
592
- let A = class extends pe {
595
+ let A = class extends ve {
593
596
  constructor(e = Z, t, n, r) {
594
597
  super(), this._config = e, this._injector = t, this._configService = n, this._commandService = r;
595
- const { ...s } = Se(
598
+ const { ...s } = pe(
596
599
  {},
597
600
  Z,
598
601
  this._config
@@ -600,7 +603,7 @@ let A = class extends pe {
600
603
  this._configService.setConfig(ce, s);
601
604
  }
602
605
  onStarting() {
603
- ve(this._injector, [
606
+ Se(this._injector, [
604
607
  [D],
605
608
  [oe],
606
609
  [J]
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var ae = Object.defineProperty;
2
2
  var le = (e, t, n) => t in e ? ae(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var M = (e, t, n) => le(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { numfmt as x, CommandType as P, ICommandService as E, IUniverInstanceService as F, IUndoRedoService as ue, CellValueType as I, ObjectMatrix as b, sequenceExecute as me, Range as N, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as K, UniverInstanceType as ee, DependentOn as ge, Injector as he, Plugin as pe, merge as Se, registerDependencies as ve, touchDependencies as z } from "@univerjs/core";
4
+ import { numfmt as x, CommandType as P, ICommandService as E, IUniverInstanceService as F, IUndoRedoService as ue, CellValueType as I, ObjectMatrix as b, sequenceExecute as me, Range as N, Inject as T, ThemeService as fe, LocaleService as de, IConfigService as X, Disposable as Q, LocaleType as $, InterceptorEffectEnum as K, UniverInstanceType as ee, DependentOn as ge, Injector as he, Plugin as ve, merge as pe, registerDependencies as Se, touchDependencies as z } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as H, transformCellsToRange as ye, checkCellValueType as G, rangeMerge as Y, SetNumfmtMutation as te, factorySetNumfmtUndoMutation as _e, RemoveNumfmtMutation as Ce, SetRangeValuesMutation as B, factoryRemoveNumfmtUndoMutation as be, SheetsSelectionsService as j, INumfmtService as W, SheetInterceptorService as Me, INTERCEPTOR_POINT as $e, InterceptCellContentPriority as Re, UniverSheetsPlugin as Ie } from "@univerjs/sheets";
6
6
  import { isTextFormat as ne } from "@univerjs/engine-numfmt";
7
7
  import { BehaviorSubject as k, merge as Ne, switchMap as Ee, of as Te, skip as xe } from "rxjs";
@@ -182,15 +182,15 @@ const re = [
182
182
  if (e && !t || !e && t)
183
183
  return !1;
184
184
  const n = (u) => u.reduce(
185
- (g, p) => {
185
+ (g, v) => {
186
186
  if (g.isEnd)
187
187
  return g;
188
- const h = p.value || p.num;
189
- return p.type === "point" ? (g.isEnd = !0, g) : { ...g, result: g.result + h };
188
+ const h = v.value || v.num;
189
+ return v.type === "point" ? (g.isEnd = !0, g) : { ...g, result: g.result + h };
190
190
  },
191
191
  { isEnd: !1, result: "" }
192
- ).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens), c = n(s[0].tokens), i = n(r[1].tokens), d = n(s[1].tokens);
193
- return o === c && i === d && r[1].color === s[1].color;
192
+ ).result, r = x.getInfo(e)._partitions, s = x.getInfo(t)._partitions, o = n(r[0].tokens), c = n(s[0].tokens), i = n(r[1].tokens), m = n(s[1].tokens);
193
+ return o === c && i === m && r[1].color === s[1].color;
194
194
  }, q = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), O = (e, t) => e.split(";").map((r) => /\.0?/.test(r) ? r.replace(
195
195
  /\.0*/g,
196
196
  `${t > 0 ? "." : ""}${q(Number(t || 0))}`
@@ -206,7 +206,7 @@ const re = [
206
206
  return !1;
207
207
  const n = e.get(E), r = e.get(F), s = e.get(ue), o = H(r, t);
208
208
  if (!o) return !1;
209
- const { unitId: c, subUnitId: i, worksheet: d } = o, u = t.values.filter((l) => !!l.pattern), g = t.values.filter((l) => !l.pattern), p = ye(c, i, u), h = {
209
+ const { unitId: c, subUnitId: i, worksheet: m } = o, u = t.values.filter((l) => !!l.pattern), g = t.values.filter((l) => !l.pattern), v = ye(c, i, u), h = {
210
210
  unitId: c,
211
211
  subUnitId: i,
212
212
  ranges: g.map((l) => ({
@@ -215,43 +215,43 @@ const re = [
215
215
  endColumn: l.col,
216
216
  endRow: l.row
217
217
  }))
218
- }, C = [], v = [];
218
+ }, C = [], S = [];
219
219
  if (u.length) {
220
- const l = u.reduce((f, a) => {
221
- ne(a.pattern) && f.setValue(a.row, a.col, { t: I.STRING });
222
- const _ = d.getCellRaw(a.row, a.col);
220
+ const l = u.reduce((d, a) => {
221
+ ne(a.pattern) && d.setValue(a.row, a.col, { t: I.STRING });
222
+ const _ = m.getCellRaw(a.row, a.col);
223
223
  if (_) {
224
224
  const V = G(_.v);
225
- V !== _.t && f.setValue(a.row, a.col, { t: V });
225
+ V !== _.t && d.setValue(a.row, a.col, { t: V });
226
226
  }
227
- return f;
228
- }, new b()).getMatrix(), S = new b();
229
- new b(l).forValue((f, a) => {
230
- const _ = d.getCellRaw(f, a);
231
- _ ? S.setValue(f, a, { t: _.t }) : S.setValue(f, a, { t: void 0 });
232
- }), Object.keys(p.values).forEach((f) => {
233
- const a = p.values[f];
227
+ return d;
228
+ }, new b()).getMatrix(), p = new b();
229
+ new b(l).forValue((d, a) => {
230
+ const _ = m.getCellRaw(d, a);
231
+ _ ? p.setValue(d, a, { t: _.t }) : p.setValue(d, a, { t: void 0 });
232
+ }), Object.keys(v.values).forEach((d) => {
233
+ const a = v.values[d];
234
234
  a.ranges = Y(a.ranges);
235
235
  }), C.push({
236
236
  id: te.id,
237
- params: p
237
+ params: v
238
238
  });
239
- const y = _e(e, p);
240
- v.push(...y);
239
+ const y = _e(e, v);
240
+ S.push(...y);
241
241
  }
242
242
  if (g.length) {
243
243
  h.ranges = Y(h.ranges);
244
- const l = g.reduce((f, a) => {
245
- const _ = d.getCellRaw(a.row, a.col);
244
+ const l = g.reduce((d, a) => {
245
+ const _ = m.getCellRaw(a.row, a.col);
246
246
  if (_) {
247
247
  const V = G(_.v);
248
- V !== _.t && f.setValue(a.row, a.col, { t: V });
248
+ V !== _.t && d.setValue(a.row, a.col, { t: V });
249
249
  }
250
- return f;
251
- }, new b()).getMatrix(), S = new b();
252
- new b(l).forValue((f, a) => {
253
- const _ = d.getCellRaw(f, a);
254
- _ ? S.setValue(f, a, { t: _.t }) : S.setValue(f, a, { t: void 0 });
250
+ return d;
251
+ }, new b()).getMatrix(), p = new b();
252
+ new b(l).forValue((d, a) => {
253
+ const _ = m.getCellRaw(d, a);
254
+ _ ? p.setValue(d, a, { t: _.t }) : p.setValue(d, a, { t: void 0 });
255
255
  }), C.push({
256
256
  id: Ce.id,
257
257
  params: h
@@ -264,21 +264,21 @@ const re = [
264
264
  }
265
265
  });
266
266
  const y = be(e, h);
267
- v.push({
267
+ S.push({
268
268
  id: B.id,
269
269
  params: {
270
270
  unitId: c,
271
271
  subUnitId: i,
272
- cellValue: S.getMatrix()
272
+ cellValue: p.getMatrix()
273
273
  }
274
274
  }, ...y);
275
275
  }
276
- const m = me(C, n).result;
277
- return m && s.pushUndoRedo({
276
+ const f = me(C, n).result;
277
+ return f && s.pushUndoRedo({
278
278
  unitID: c,
279
- undoMutations: v,
279
+ undoMutations: S,
280
280
  redoMutations: C
281
- }), m;
281
+ }), f;
282
282
  }
283
283
  }, De = {
284
284
  id: "sheet.command.numfmt.add.decimal.command",
@@ -289,17 +289,17 @@ const re = [
289
289
  return !1;
290
290
  const c = H(s);
291
291
  if (!c) return !1;
292
- const { unitId: i, subUnitId: d } = c;
292
+ const { unitId: i, subUnitId: m } = c;
293
293
  let u = 0;
294
294
  o.forEach((C) => {
295
- N.foreach(C.range, (v, m) => {
296
- const l = r.getValue(i, d, v, m);
295
+ N.foreach(C.range, (S, f) => {
296
+ const l = r.getValue(i, m, S, f);
297
297
  if (!l) {
298
- const y = c.worksheet.getCellRaw(v, m);
298
+ const y = c.worksheet.getCellRaw(S, f);
299
299
  if (!u && y && y.t === I.NUMBER && y.v) {
300
- const f = /\.(\d*)$/.exec(String(y.v));
301
- if (f) {
302
- const a = f[1].length;
300
+ const d = /\.(\d*)$/.exec(String(y.v));
301
+ if (d) {
302
+ const a = d[1].length;
303
303
  if (!a)
304
304
  return;
305
305
  u = Math.max(u, a);
@@ -307,25 +307,25 @@ const re = [
307
307
  }
308
308
  return;
309
309
  }
310
- const S = w(l.pattern);
311
- u = S > u ? S : u;
310
+ const p = w(l.pattern);
311
+ u = p > u ? p : u;
312
312
  });
313
313
  });
314
- const g = u + 1, p = O(`0${g > 0 ? ".0" : ""}`, g), h = [];
314
+ const g = u + 1, v = O(`0${g > 0 ? ".0" : ""}`, g), h = [];
315
315
  return o.forEach((C) => {
316
- N.foreach(C.range, (v, m) => {
317
- const l = r.getValue(i, d, v, m);
316
+ N.foreach(C.range, (S, f) => {
317
+ const l = r.getValue(i, m, S, f);
318
318
  if (!l)
319
319
  h.push({
320
- row: v,
321
- col: m,
322
- pattern: p
320
+ row: S,
321
+ col: f,
322
+ pattern: v
323
323
  });
324
324
  else {
325
- const S = w(l.pattern), y = O(l.pattern, S + 1);
325
+ const p = w(l.pattern), y = O(l.pattern, p + 1);
326
326
  y !== l.pattern && h.push({
327
- row: v,
328
- col: m,
327
+ row: S,
328
+ col: f,
329
329
  pattern: y
330
330
  });
331
331
  }
@@ -357,8 +357,8 @@ const Ae = {
357
357
  return !1;
358
358
  const c = [], i = se[4].suffix(s);
359
359
  return o.forEach((u) => {
360
- N.foreach(u.range, (g, p) => {
361
- c.push({ row: g, col: p, pattern: i, type: "currency" });
360
+ N.foreach(u.range, (g, v) => {
361
+ c.push({ row: g, col: v, pattern: i, type: "currency" });
362
362
  });
363
363
  }), await t.executeCommand(U.id, { values: c });
364
364
  }
@@ -371,8 +371,8 @@ const Ae = {
371
371
  return !1;
372
372
  const s = [], o = "0%";
373
373
  return r.forEach((i) => {
374
- N.foreach(i.range, (d, u) => {
375
- s.push({ row: d, col: u, pattern: o, type: "percent" });
374
+ N.foreach(i.range, (m, u) => {
375
+ s.push({ row: m, col: u, pattern: o, type: "percent" });
376
376
  });
377
377
  }), await t.executeCommand(U.id, { values: s });
378
378
  }
@@ -385,15 +385,15 @@ const Ae = {
385
385
  return !1;
386
386
  const c = H(s);
387
387
  if (!c) return !1;
388
- const { unitId: i, subUnitId: d } = c;
388
+ const { unitId: i, subUnitId: m } = c;
389
389
  let u = 0;
390
- o.forEach((v) => {
391
- N.foreach(v.range, (m, l) => {
392
- const S = r.getValue(i, d, m, l);
393
- if (!S) {
394
- const f = c.worksheet.getCellRaw(m, l);
395
- if (!u && f && f.t === I.NUMBER && f.v) {
396
- const a = /\.(\d*)$/.exec(String(f.v));
390
+ o.forEach((S) => {
391
+ N.foreach(S.range, (f, l) => {
392
+ const p = r.getValue(i, m, f, l);
393
+ if (!p) {
394
+ const d = c.worksheet.getCellRaw(f, l);
395
+ if (!u && d && d.t === I.NUMBER && d.v) {
396
+ const a = /\.(\d*)$/.exec(String(d.v));
397
397
  if (a) {
398
398
  const _ = a[1].length;
399
399
  if (!_)
@@ -403,26 +403,26 @@ const Ae = {
403
403
  }
404
404
  return;
405
405
  }
406
- const y = w(S.pattern);
406
+ const y = w(p.pattern);
407
407
  u = y > u ? y : u;
408
408
  });
409
409
  });
410
- const g = u - 1, p = O(`0${g > 0 ? ".0" : "."}`, g), h = [];
411
- return o.forEach((v) => {
412
- N.foreach(v.range, (m, l) => {
413
- const S = r.getValue(i, d, m, l);
414
- if (!S)
410
+ const g = u - 1, v = O(`0${g > 0 ? ".0" : "."}`, g), h = [];
411
+ return o.forEach((S) => {
412
+ N.foreach(S.range, (f, l) => {
413
+ const p = r.getValue(i, m, f, l);
414
+ if (!p)
415
415
  h.push({
416
- row: m,
416
+ row: f,
417
417
  col: l,
418
- pattern: p
418
+ pattern: v
419
419
  });
420
420
  else {
421
- const y = w(S.pattern);
421
+ const y = w(p.pattern);
422
422
  h.push({
423
- row: m,
423
+ row: f,
424
424
  col: l,
425
- pattern: O(S.pattern, y - 1)
425
+ pattern: O(p.pattern, y - 1)
426
426
  });
427
427
  }
428
428
  });
@@ -486,21 +486,22 @@ let D = class extends Q {
486
486
  t.reset();
487
487
  })), this.disposeWithMe(this._sheetInterceptorService.intercept($e.CELL_CONTENT, {
488
488
  effect: K.Value | K.Style,
489
+ // eslint-disable-next-line complexity
489
490
  handler: (n, r, s) => {
490
- var v;
491
+ var S;
491
492
  const o = r.unitId, c = r.subUnitId;
492
493
  let i;
493
- const d = n;
494
- if (!d)
494
+ const m = n;
495
+ if (!m)
495
496
  return s(n);
496
497
  if (n != null && n.s) {
497
- const m = r.workbook.getStyles().get(n.s);
498
- m != null && m.n && (i = m.n);
498
+ const f = r.workbook.getStyles().get(n.s);
499
+ f != null && f.n && (i = f.n);
499
500
  }
500
- if (i || (i = this._numfmtService.getValue(o, c, r.row, r.col)), !i || (n.t || G(d.v)) !== I.NUMBER)
501
+ if (i || (i = this._numfmtService.getValue(o, c, r.row, r.col)), !i || (n.t || G(m.v)) !== I.NUMBER)
501
502
  return s(n);
502
503
  if (ne(i.pattern))
503
- return (v = this._configService.getConfig(ce)) != null && v.disableTextFormatMark ? s({
504
+ return (S = this._configService.getConfig(ce)) != null && S.disableTextFormatMark ? s({
504
505
  ...n,
505
506
  t: I.STRING
506
507
  }) : s({
@@ -512,20 +513,22 @@ let D = class extends Q {
512
513
  }
513
514
  });
514
515
  let g = "";
515
- const p = t.getValue(r.row, r.col);
516
- if (p && p.parameters === `${d.v}_${i.pattern}`)
517
- return s({ ...n, ...p.result });
518
- const h = Ge(i.pattern, Number(d.v), this.local);
516
+ const v = t.getValue(r.row, r.col);
517
+ if (v && v.parameters === `${m.v}_${i.pattern}`)
518
+ return s({ ...n, ...v.result });
519
+ if (m.v === void 0 || m.v === null)
520
+ return s(n);
521
+ const h = Ge(i.pattern, Number(m.v), this.local);
519
522
  if (g = h.result, !g)
520
523
  return s(n);
521
524
  const C = { v: g, t: I.NUMBER };
522
525
  if (h.color) {
523
- const m = this._themeService.getCurrentTheme()[`${h.color}500`];
524
- m && (C.interceptorStyle = { cl: { rgb: m } });
526
+ const f = this._themeService.getCurrentTheme()[`${h.color}500`];
527
+ f && (C.interceptorStyle = { cl: { rgb: f } });
525
528
  }
526
529
  return t.setValue(r.row, r.col, {
527
530
  result: C,
528
- parameters: `${d.v}_${i.pattern}`
531
+ parameters: `${m.v}_${i.pattern}`
529
532
  }), s({ ...n, ...C });
530
533
  },
531
534
  priority: Re.NUMFMT
@@ -534,8 +537,8 @@ let D = class extends Q {
534
537
  const r = n.params;
535
538
  Object.keys(r.values).forEach((s) => {
536
539
  r.values[s].ranges.forEach((c) => {
537
- N.foreach(c, (i, d) => {
538
- t.realDeleteValue(i, d);
540
+ N.foreach(c, (i, m) => {
541
+ t.realDeleteValue(i, m);
539
542
  });
540
543
  });
541
544
  });
@@ -589,10 +592,10 @@ var ke = Object.defineProperty, Ke = Object.getOwnPropertyDescriptor, ze = (e, t
589
592
  (c = e[o]) && (s = c(s) || s);
590
593
  return s;
591
594
  }, L = (e, t) => (n, r) => t(n, r, e), ie = (e, t, n) => ze(e, typeof t != "symbol" ? t + "" : t, n);
592
- let A = class extends pe {
595
+ let A = class extends ve {
593
596
  constructor(e = Z, t, n, r) {
594
597
  super(), this._config = e, this._injector = t, this._configService = n, this._commandService = r;
595
- const { ...s } = Se(
598
+ const { ...s } = pe(
596
599
  {},
597
600
  Z,
598
601
  this._config
@@ -600,7 +603,7 @@ let A = class extends pe {
600
603
  this._configService.setConfig(ce, s);
601
604
  }
602
605
  onStarting() {
603
- ve(this._injector, [
606
+ Se(this._injector, [
604
607
  [D],
605
608
  [oe],
606
609
  [J]
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.UniverEngineNumfmt,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,c,A,I,J){"use strict";var ge=Object.defineProperty;var Se=(a,t,c)=>t in a?ge(a,t,{enumerable:!0,configurable:!0,writable:!0,value:c}):a[t]=c;var R=(a,t,c)=>Se(a,typeof t!="symbol"?t+"":t,c);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,r=0)=>{var n;return e&&(n=t.numfmt.getInfo(e).maxDecimals)!=null?n:r},Q=(e,r)=>{if(e&&!r||!e&&r)return!1;const i=o=>o.reduce((v,y)=>{if(v.isEnd)return v;const C=y.value||y.num;return y.type==="point"?(v.isEnd=!0,v):{...v,result:v.result+C}},{isEnd:!1,result:""}).result,n=t.numfmt.getInfo(e)._partitions,s=t.numfmt.getInfo(r)._partitions,l=i(n[0].tokens),m=i(s[0].tokens),S=i(n[1].tokens),d=i(s[1].tokens);return l===m&&S===d&&n[1].color===s[1].color},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(";"),ee=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),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=c.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:d}=l,o=r.values.filter(u=>!!u.pattern),v=r.values.filter(u=>!u.pattern),y=c.transformCellsToRange(m,S,o),C={unitId:m,subUnitId:S,ranges:v.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],p=[];if(o.length){const u=o.reduce((g,f)=>{A.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const M=d.getCellRaw(f.row,f.col);if(M){const P=c.checkCellValueType(M.v);P!==M.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),_=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const M=d.getCellRaw(g,f);M?_.setValue(g,f,{t:M.t}):_.setValue(g,f,{t:void 0})}),Object.keys(y.values).forEach(g=>{const f=y.values[g];f.ranges=c.rangeMerge(f.ranges)}),T.push({id:c.SetNumfmtMutation.id,params:y});const b=c.factorySetNumfmtUndoMutation(e,y);p.push(...b)}if(v.length){C.ranges=c.rangeMerge(C.ranges);const u=v.reduce((g,f)=>{const M=d.getCellRaw(f.row,f.col);if(M){const P=c.checkCellValueType(M.v);P!==M.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),_=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const M=d.getCellRaw(g,f);M?_.setValue(g,f,{t:M.t}):_.setValue(g,f,{t:void 0})}),T.push({id:c.RemoveNumfmtMutation.id,params:C},{id:c.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const b=c.factoryRemoveNumfmtUndoMutation(e,C);p.push({id:c.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:_.getMatrix()}},...b)}const h=t.sequenceExecute(T,i).result;return h&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:T}),h}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(c.SheetsSelectionsService),n=e.get(c.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=c.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let o=0;l.forEach(T=>{t.Range.foreach(T.range,(p,h)=>{const u=n.getValue(S,d,p,h);if(!u){const b=m.worksheet.getCellRaw(p,h);if(!o&&b&&b.t===t.CellValueType.NUMBER&&b.v){const g=/\.(\d*)$/.exec(String(b.v));if(g){const f=g[1].length;if(!f)return;o=Math.max(o,f)}}return}const _=$(u.pattern);o=_>o?_:o})});const v=o+1,y=U(`0${v>0?".0":""}`,v),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(p,h)=>{const u=n.getValue(S,d,p,h);if(!u)C.push({row:p,col:h,pattern:y});else{const _=$(u.pattern),b=U(u.pattern,_+1);b!==u.pattern&&C.push({row:p,col:h,pattern:b})}})}),C.length?await r.executeCommand(E.id,{values:C}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(c.SheetsSelectionsService),n=e.get(j),s=L[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],S=V[4].suffix(s);return l.forEach(o=>{t.Range.foreach(o.range,(v,y)=>{m.push({row:v,col:y,pattern:S,type:"currency"})})}),await r.executeCommand(E.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(c.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(d,o)=>{s.push({row:d,col:o,pattern:l,type:"percent"})})}),await r.executeCommand(E.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(c.SheetsSelectionsService),n=e.get(c.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=c.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let o=0;l.forEach(p=>{t.Range.foreach(p.range,(h,u)=>{const _=n.getValue(S,d,h,u);if(!_){const g=m.worksheet.getCellRaw(h,u);if(!o&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const M=f[1].length;if(!M)return;o=Math.max(o,M)}}return}const b=$(_.pattern);o=b>o?b:o})});const v=o-1,y=U(`0${v>0?".0":"."}`,v),C=[];return l.forEach(p=>{t.Range.foreach(p.range,(h,u)=>{const _=n.getValue(S,d,h,u);if(!_)C.push({row:h,col:u,pattern:y});else{const b=$(_.pattern);C.push({row:h,col:u,pattern:U(_.pattern,b-1)})}})}),await r.executeCommand(E.id,{values:C})}},w="sheets-numfmt.config",k={},te=e=>t.numfmt.getInfo(e).type||"unknown",K=(e,r,i="en")=>{const s=t.numfmt.getInfo(e)._partitions[1],l=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:l,color:s.color}:{result:l}},Y=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:K(e,r,i);var ne=Object.getOwnPropertyDescriptor,re=(e,r,i,n)=>{for(var s=n>1?void 0:n?ne(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 ie={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,d){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=d,this._initInterceptorCellContent()}get local(){const i=this._local$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(c.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var h;const m=s.unitId,S=s.subUnitId;let d;const o=n;if(!o)return l(n);if(n!=null&&n.s){const u=s.workbook.getStyles().get(n.s);u!=null&&u.n&&(d=u.n)}if(d||(d=this._numfmtService.getValue(m,S,s.row,s.col)),!d||(n.t||c.checkCellValueType(o.v))!==t.CellValueType.NUMBER)return l(n);if(A.isTextFormat(d.pattern))return(h=this._configService.getConfig(w))!=null&&h.disableTextFormatMark?l({...n,t:t.CellValueType.STRING}):l({...n,t:t.CellValueType.STRING,markers:{...n==null?void 0:n.markers,...ie}});let y="";const C=i.getValue(s.row,s.col);if(C&&C.parameters===`${o.v}_${d.pattern}`)return l({...n,...C.result});const T=Y(d.pattern,Number(o.v),this.local);if(y=T.result,!y)return l(n);const p={v:y,t:t.CellValueType.NUMBER};if(T.color){const u=this._themeService.getCurrentTheme()[`${T.color}500`];u&&(p.interceptorStyle={cl:{rgb:u}})}return i.setValue(s.row,s.col,{result:p,parameters:`${o.v}_${d.pattern}`}),l({...n,...p})},priority:c.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===c.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(d,o)=>{i.realDeleteValue(d,o)})})})}else if(n.id===c.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=re([N(0,t.IUniverInstanceService),N(1,t.Inject(c.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(c.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,se=Object.getOwnPropertyDescriptor,le=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,ue=(e,r,i,n)=>{for(var s=n>1?void 0:n?se(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)=>le(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,E].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=ue([t.DependentOn(c.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ce=e=>O.find(i=>e.includes(i)),oe=()=>O.map(e=>({label:e,value:e})),me=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>G.map(e=>({label:e.label,value:e.suffix})),de=()=>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=E,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=me,a.getCurrencyOptions=oe,a.getCurrencyType=ce,a.getDateFormatOptions=fe,a.getDecimalFromPattern=$,a.getDecimalString=D,a.getNumberFormatOptions=de,a.getPatternPreview=K,a.getPatternPreviewIgnoreGeneral=Y,a.getPatternType=te,a.isPatternEqualWithoutDecimal=Q,a.isPatternHasDecimal=ee,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-numfmt"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-numfmt","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.UniverEngineNumfmt,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,o,A,I,J){"use strict";var ge=Object.defineProperty;var Se=(a,t,o)=>t in a?ge(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o;var R=(a,t,o)=>Se(a,typeof t!="symbol"?t+"":t,o);const O=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],L={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],X="SHEET_NUMFMT_PLUGIN",$=(e,r=0)=>{var n;return e&&(n=t.numfmt.getInfo(e).maxDecimals)!=null?n:r},Q=(e,r)=>{if(e&&!r||!e&&r)return!1;const i=c=>c.reduce((v,y)=>{if(v.isEnd)return v;const C=y.value||y.num;return y.type==="point"?(v.isEnd=!0,v):{...v,result:v.result+C}},{isEnd:!1,result:""}).result,n=t.numfmt.getInfo(e)._partitions,l=t.numfmt.getInfo(r)._partitions,s=i(n[0].tokens),m=i(l[0].tokens),S=i(n[1].tokens),d=i(l[1].tokens);return s===m&&S===d&&n[1].color===l[1].color},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(";"),ee=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),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),l=e.get(t.IUndoRedoService),s=o.getSheetCommandTarget(n,r);if(!s)return!1;const{unitId:m,subUnitId:S,worksheet:d}=s,c=r.values.filter(u=>!!u.pattern),v=r.values.filter(u=>!u.pattern),y=o.transformCellsToRange(m,S,c),C={unitId:m,subUnitId:S,ranges:v.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],p=[];if(c.length){const u=c.reduce((g,f)=>{A.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const M=d.getCellRaw(f.row,f.col);if(M){const P=o.checkCellValueType(M.v);P!==M.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),_=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const M=d.getCellRaw(g,f);M?_.setValue(g,f,{t:M.t}):_.setValue(g,f,{t:void 0})}),Object.keys(y.values).forEach(g=>{const f=y.values[g];f.ranges=o.rangeMerge(f.ranges)}),T.push({id:o.SetNumfmtMutation.id,params:y});const b=o.factorySetNumfmtUndoMutation(e,y);p.push(...b)}if(v.length){C.ranges=o.rangeMerge(C.ranges);const u=v.reduce((g,f)=>{const M=d.getCellRaw(f.row,f.col);if(M){const P=o.checkCellValueType(M.v);P!==M.t&&g.setValue(f.row,f.col,{t:P})}return g},new t.ObjectMatrix).getMatrix(),_=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const M=d.getCellRaw(g,f);M?_.setValue(g,f,{t:M.t}):_.setValue(g,f,{t:void 0})}),T.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const b=o.factoryRemoveNumfmtUndoMutation(e,C);p.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:_.getMatrix()}},...b)}const h=t.sequenceExecute(T,i).result;return h&&l.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:T}),h}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),l=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const m=o.getSheetCommandTarget(l);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;s.forEach(T=>{t.Range.foreach(T.range,(p,h)=>{const u=n.getValue(S,d,p,h);if(!u){const b=m.worksheet.getCellRaw(p,h);if(!c&&b&&b.t===t.CellValueType.NUMBER&&b.v){const g=/\.(\d*)$/.exec(String(b.v));if(g){const f=g[1].length;if(!f)return;c=Math.max(c,f)}}return}const _=$(u.pattern);c=_>c?_:c})});const v=c+1,y=U(`0${v>0?".0":""}`,v),C=[];return s.forEach(T=>{t.Range.foreach(T.range,(p,h)=>{const u=n.getValue(S,d,p,h);if(!u)C.push({row:p,col:h,pattern:y});else{const _=$(u.pattern),b=U(u.pattern,_+1);b!==u.pattern&&C.push({row:p,col:h,pattern:b})}})}),C.length?await r.executeCommand(E.id,{values:C}):!1}};class j{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const H={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(j),l=L[n.getCurrencySymbol()]||"$",s=i.getCurrentSelections();if(!s||!s.length)return!1;const m=[],S=V[4].suffix(l);return s.forEach(c=>{t.Range.foreach(c.range,(v,y)=>{m.push({row:v,col:y,pattern:S,type:"currency"})})}),await r.executeCommand(E.id,{values:m})}},W={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const l=[],s="0%";return n.forEach(S=>{t.Range.foreach(S.range,(d,c)=>{l.push({row:d,col:c,pattern:s,type:"percent"})})}),await r.executeCommand(E.id,{values:l})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),l=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const m=o.getSheetCommandTarget(l);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;s.forEach(p=>{t.Range.foreach(p.range,(h,u)=>{const _=n.getValue(S,d,h,u);if(!_){const g=m.worksheet.getCellRaw(h,u);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const M=f[1].length;if(!M)return;c=Math.max(c,M)}}return}const b=$(_.pattern);c=b>c?b:c})});const v=c-1,y=U(`0${v>0?".0":"."}`,v),C=[];return s.forEach(p=>{t.Range.foreach(p.range,(h,u)=>{const _=n.getValue(S,d,h,u);if(!_)C.push({row:h,col:u,pattern:y});else{const b=$(_.pattern);C.push({row:h,col:u,pattern:U(_.pattern,b-1)})}})}),await r.executeCommand(E.id,{values:C})}},w="sheets-numfmt.config",k={},te=e=>t.numfmt.getInfo(e).type||"unknown",K=(e,r,i="en")=>{const l=t.numfmt.getInfo(e)._partitions[1],s=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:s,color:l.color}:{result:s}},Y=(e,r,i)=>e==="General"?{result:String(J.stripErrorMargin(r))}:K(e,r,i);var ne=Object.getOwnPropertyDescriptor,re=(e,r,i,n)=>{for(var l=n>1?void 0:n?ne(r,i):r,s=e.length-1,m;s>=0;s--)(m=e[s])&&(l=m(l)||l);return l},N=(e,r)=>(i,n)=>r(i,n,e);const ie={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,l,s,m,S,d){super();R(this,"_local$",new I.BehaviorSubject("en"));R(this,"local$",this._local$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=l,this._commandService=s,this._numfmtService=m,this._localeService=S,this._configService=d,this._initInterceptorCellContent()}get local(){const i=this._local$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,l,s)=>{var h;const m=l.unitId,S=l.subUnitId;let d;const c=n;if(!c)return s(n);if(n!=null&&n.s){const u=l.workbook.getStyles().get(n.s);u!=null&&u.n&&(d=u.n)}if(d||(d=this._numfmtService.getValue(m,S,l.row,l.col)),!d||(n.t||o.checkCellValueType(c.v))!==t.CellValueType.NUMBER)return s(n);if(A.isTextFormat(d.pattern))return(h=this._configService.getConfig(w))!=null&&h.disableTextFormatMark?s({...n,t:t.CellValueType.STRING}):s({...n,t:t.CellValueType.STRING,markers:{...n==null?void 0:n.markers,...ie}});let y="";const C=i.getValue(l.row,l.col);if(C&&C.parameters===`${c.v}_${d.pattern}`)return s({...n,...C.result});if(c.v===void 0||c.v===null)return s(n);const T=Y(d.pattern,Number(c.v),this.local);if(y=T.result,!y)return s(n);const p={v:y,t:t.CellValueType.NUMBER};if(T.color){const u=this._themeService.getCurrentTheme()[`${T.color}500`];u&&(p.interceptorStyle={cl:{rgb:u}})}return i.setValue(l.row,l.col,{result:p,parameters:`${c.v}_${d.pattern}`}),s({...n,...p})},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const l=n.params;Object.keys(l.values).forEach(s=>{l.values[s].ranges.forEach(S=>{t.Range.foreach(S,(d,c)=>{i.realDeleteValue(d,c)})})})}else if(n.id===o.SetRangeValuesMutation.id){const l=n.params;new t.ObjectMatrix(l.cellValue).forValue((s,m)=>{i.realDeleteValue(s,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var l;return(l=n==null?void 0:n.activeSheet$)!=null?l:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._local$.next(i)}},a.SheetsNumfmtCellContentController=re([N(0,t.IUniverInstanceService),N(1,t.Inject(o.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(o.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);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,se=Object.getOwnPropertyDescriptor,le=(e,r,i)=>r in e?ae(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,ue=(e,r,i,n)=>{for(var l=n>1?void 0:n?se(r,i):r,s=e.length-1,m;s>=0;s--)(m=e[s])&&(l=m(l)||l);return l},F=(e,r)=>(i,n)=>r(i,n,e),Z=(e,r,i)=>le(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=k,i,n,l){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=l;const{...s}=t.merge({},k,this._config);this._configService.setConfig(w,s)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[j],[z]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[z]]),[x,q,H,W,E].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},Z(a.UniverSheetsNumfmtPlugin,"pluginName",X),Z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=ue([t.DependentOn(o.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const ce=e=>O.find(i=>e.includes(i)),oe=()=>O.map(e=>({label:e,value:e})),me=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),fe=()=>G.map(e=>({label:e.label,value:e.suffix})),de=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=x,a.CURRENCYFORMAT=V,a.DATEFMTLISG=G,a.MenuCurrencyService=j,a.NUMBERFORMAT=B,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,a.SetCurrencyCommand=H,a.SetNumfmtCommand=E,a.SetPercentCommand=W,a.SubtractDecimalCommand=q,a.countryCurrencyMap=L,a.currencySymbols=O,a.getCurrencyFormatOptions=me,a.getCurrencyOptions=oe,a.getCurrencyType=ce,a.getDateFormatOptions=fe,a.getDecimalFromPattern=$,a.getDecimalString=D,a.getNumberFormatOptions=de,a.getPatternPreview=K,a.getPatternPreviewIgnoreGeneral=Y,a.getPatternType=te,a.isPatternEqualWithoutDecimal=Q,a.isPatternHasDecimal=ee,a.setPatternDecimal=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt",
3
- "version": "0.6.10",
3
+ "version": "0.7.0-nightly.202504291607",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -58,17 +58,17 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/core": "0.6.10",
62
- "@univerjs/engine-formula": "0.6.10",
63
- "@univerjs/engine-numfmt": "0.6.10",
64
- "@univerjs/sheets": "0.6.10"
61
+ "@univerjs/core": "0.7.0-nightly.202504291607",
62
+ "@univerjs/engine-formula": "0.7.0-nightly.202504291607",
63
+ "@univerjs/engine-numfmt": "0.7.0-nightly.202504291607",
64
+ "@univerjs/sheets": "0.7.0-nightly.202504291607"
65
65
  },
66
66
  "devDependencies": {
67
67
  "rxjs": "^7.8.1",
68
68
  "typescript": "^5.8.3",
69
- "vite": "^6.3.0",
70
- "vitest": "^3.1.1",
71
- "@univerjs-infra/shared": "0.6.10"
69
+ "vite": "^6.3.3",
70
+ "vitest": "^3.1.2",
71
+ "@univerjs-infra/shared": "0.7.0-beta.0"
72
72
  },
73
73
  "scripts": {
74
74
  "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