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