@univerjs/sheets-numfmt 0.10.8 → 0.10.9
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 +1 -1
- package/lib/es/index.js +244 -251
- package/lib/index.js +244 -251
- package/lib/types/index.d.ts +1 -1
- package/lib/types/utils/pattern.d.ts +1 -5
- package/lib/umd/index.js +1 -1
- package/package.json +5 -5
package/lib/types/index.d.ts
CHANGED
|
@@ -27,4 +27,4 @@ export { UniverSheetsNumfmtPlugin } from './plugin';
|
|
|
27
27
|
export { getCurrencyType } from './utils/currency';
|
|
28
28
|
export { getDecimalFromPattern, getDecimalString, isPatternHasDecimal, setPatternDecimal } from './utils/decimal';
|
|
29
29
|
export { getCurrencyFormatOptions, getCurrencyOptions, getDateFormatOptions, getNumberFormatOptions } from './utils/options';
|
|
30
|
-
export {
|
|
30
|
+
export { getPatternPreview, getPatternPreviewIgnoreGeneral, getPatternType } from './utils/pattern';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INumfmtLocaleTag
|
|
1
|
+
import { INumfmtLocaleTag } from '@univerjs/core';
|
|
2
2
|
import { FormatType } from '@univerjs/sheets';
|
|
3
3
|
export declare const getPatternType: (pattern: string) => FormatType;
|
|
4
4
|
interface IPatternPreview {
|
|
@@ -7,8 +7,4 @@ interface IPatternPreview {
|
|
|
7
7
|
}
|
|
8
8
|
export declare const getPatternPreview: (pattern: string, value: number, locale?: INumfmtLocaleTag) => IPatternPreview;
|
|
9
9
|
export declare const getPatternPreviewIgnoreGeneral: (pattern: string, value: number, locale?: INumfmtLocaleTag) => IPatternPreview;
|
|
10
|
-
/**
|
|
11
|
-
* Get the numfmt parse value, and filter out the parse error.
|
|
12
|
-
*/
|
|
13
|
-
export declare const getNumfmtParseValueFilter: (value: string) => numfmt.ParseData | null;
|
|
14
10
|
export {};
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-formula"],t):(i=typeof globalThis<"u"?globalThis:i||self,t(i.UniverSheetsNumfmt={},i.UniverCore,i.UniverSheets,i.rxjs,i.UniverEngineFormula))})(this,(function(i,t,o,I,X){"use strict";var ve=Object.defineProperty;var Ce=(i,t,o)=>t in i?ve(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o;var w=(i,t,o)=>Ce(i,typeof t!="symbol"?t+"":t,o);const O=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function j(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function A(e,a=2){let r=a;a>127&&(r=127);let n="";return r>0&&(n=`.${"0".repeat(r)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const B=[{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"}],G=[{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"}],H=[{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"}],P=(e,a=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:a},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,a)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${L(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${L(Number(a||0))}$1`):n).join(";"),J=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,a)=>{if(!a)return!1;const r=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=o.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:c}=l,f=a.values.filter(u=>!!u.pattern),T=a.values.filter(u=>!u.pattern),M=o.transformCellsToRange(m,S,f),C={unitId:m,subUnitId:S,ranges:T.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},b=[],p=[];if(f.length){const u=f.reduce((g,d)=>{t.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.CellValueType.STRING});const _=c.getCellRaw(d.row,d.col);if(_){const $=o.checkCellValueType(_.v);$!==_.t&&g.setValue(d.row,d.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,d)=>{const _=c.getCellRaw(g,d);_?y.setValue(g,d,{t:_.t}):y.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=o.rangeMerge(d.ranges)}),b.push({id:o.SetNumfmtMutation.id,params:M});const h=o.factorySetNumfmtUndoMutation(e,M);p.push(...h)}if(T.length){C.ranges=o.rangeMerge(C.ranges);const u=T.reduce((g,d)=>{const _=c.getCellRaw(d.row,d.col);if(_){const $=o.checkCellValueType(_.v);$!==_.t&&g.setValue(d.row,d.col,{t:$})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,d)=>{const _=c.getCellRaw(g,d);_?y.setValue(g,d,{t:_.t}):y.setValue(g,d,{t:void 0})}),b.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const h=o.factoryRemoveNumfmtUndoMutation(e,C);p.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:y.getMatrix()}},...h)}const v=t.sequenceExecute(b,r).result;return v&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),v}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),r=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=r.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:c}=m;let f=0;l.forEach(b=>{t.Range.foreach(b.range,(p,v)=>{const u=n.getValue(S,c,p,v);if(!u){const h=m.worksheet.getCellRaw(p,v);if(!f&&h&&h.t===t.CellValueType.NUMBER&&h.v){const g=/\.(\d*)$/.exec(String(h.v));if(g){const d=g[1].length;if(!d)return;f=Math.max(f,d)}}return}const y=P(u.pattern);f=y>f?y:f})});const T=f+1,M=U(`0${T>0?".0":""}`,T),C=[];return l.forEach(b=>{t.Range.foreach(b.range,(p,v)=>{const u=n.getValue(S,c,p,v);if(!u)C.push({row:p,col:v,pattern:M});else{const y=P(u.pattern),h=U(u.pattern,y+1);h!==u.pattern&&C.push({row:p,col:v,pattern:h})}})}),C.length?await a.executeCommand(R.id,{values:C}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),r=e.get(o.SheetsSelectionsService),n=e.get(t.LocaleService),s=r.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=j(n.getCurrentLocale()),S=A(m.locale);return s.forEach(f=>{t.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(R.id,{values:l})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),n=e.get(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(c,f)=>{s.push({row:c,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),r=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=r.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:c}=m;let f=0;l.forEach(p=>{t.Range.foreach(p.range,(v,u)=>{const y=n.getValue(S,c,v,u);if(!y){const g=m.worksheet.getCellRaw(v,u);if(!f&&g&&g.t===t.CellValueType.NUMBER&&g.v){const d=/\.(\d*)$/.exec(String(g.v));if(d){const _=d[1].length;if(!_)return;f=Math.max(f,_)}}return}const h=P(y.pattern);f=h>f?h:f})});const T=f-1,M=U(`0${T>0?".0":"."}`,T),C=[];return l.forEach(p=>{t.Range.foreach(p.range,(v,u)=>{const y=n.getValue(S,c,v,u);if(!y)C.push({row:v,col:u,pattern:M});else{const h=P(y.pattern);C.push({row:v,col:u,pattern:U(y.pattern,h-1)})}})}),await a.executeCommand(R.id,{values:C})}},V="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,r="en")=>{const n=t.numfmt.formatColor(e,a),s=n?String(n):void 0,l=t.numfmt.format(e,a,{locale:r,throws:!1});return a<0?{result:l,color:s}:{result:l}},z=(e,a,r)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(X.stripErrorMargin(a))}:k(e,a,r),ee=new Set(["m d"]),te=new Set(["h:mm AM/PM","hh:mm AM/PM"]),ne=e=>{var n,s;const a=(s=(n=t.numfmt.parseDate(e))!=null?n:t.numfmt.parseTime(e))!=null?s:t.numfmt.parseNumber(e);if(!a)return null;const{z:r}=a;return r&&(ee.has(r)||te.has(r)&&!/\s(A|AM|P|PM)$/i.test(e))?null:a};var ae=Object.getOwnPropertyDescriptor,re=(e,a,r,n)=>{for(var s=n>1?void 0:n?ae(a,r):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,a)=>(r,n)=>a(r,n,e);const ie={tl:{size:6,color:"#409f11"}};i.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(r,n,s,l,m,S,c){super();w(this,"_locale$",new I.BehaviorSubject("en"));w(this,"locale$",this._locale$.asObservable());this._instanceService=r,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=c,this._initInterceptorCellContent()}get locale(){const r=this._locale$.getValue();if(r)return r;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.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const r=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{r.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,v;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return l(n);const m=s.unitId,S=s.subUnitId;let c;if(n!=null&&n.s){const u=s.workbook.getStyles().get(n.s);u!=null&&u.n&&(c=u.n)}if(c||(c=this._numfmtService.getValue(m,S,s.row,s.col)),t.isDefaultFormat(c==null?void 0:c.pattern)||n.t!==t.CellValueType.NUMBER&&o.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(c==null?void 0:c.pattern))return(p=this._configService.getConfig(V))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ie},l(n));let T="";const M=r.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${c==null?void 0:c.pattern}`)return l({...n,...M.result});const C=z(c==null?void 0:c.pattern,Number(f.v),this.locale);if(T=C.result,!T)return l(n);const b={v:T,t:t.CellValueType.NUMBER};if(C.color){const u=(v=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?v:C.color;u&&(b.interceptorStyle={cl:{rgb:u}})}return r.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${c==null?void 0:c.pattern}`}),Object.assign(n,b),l(n)},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(c,f)=>{r.realDeleteValue(c,f)})})})}else if(n.id===o.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{r.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(()=>r.reset()))}setNumfmtLocal(r){this._locale$.next(r)}},i.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)],i.SheetsNumfmtCellContentController);const se="SHEET_NUMFMT_PLUGIN";var le=Object.defineProperty,ue=Object.getOwnPropertyDescriptor,ce=(e,a,r)=>a in e?le(e,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[a]=r,oe=(e,a,r,n)=>{for(var s=n>1?void 0:n?ue(a,r):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},D=(e,a)=>(r,n)=>a(r,n,e),Y=(e,a,r)=>ce(e,typeof a!="symbol"?a+"":a,r);i.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,r,n,s){super(),this._config=a,this._injector=r,this._configService=n,this._commandService=s;const{...l}=t.merge({},Z,this._config);this._configService.setConfig(V,l)}onStarting(){t.registerDependencies(this._injector,[[i.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[i.SheetsNumfmtCellContentController]])}onRendered(){[x,q,W,K,R].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},Y(i.UniverSheetsNumfmtPlugin,"pluginName",se),Y(i.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),i.UniverSheetsNumfmtPlugin=oe([t.DependentOn(o.UniverSheetsPlugin),D(1,t.Inject(t.Injector)),D(2,t.IConfigService),D(3,t.ICommandService)],i.UniverSheetsNumfmtPlugin);const me=e=>O.find(r=>e.includes(r)),fe=()=>O.map(e=>({label:e,value:e})),de=e=>H.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),ge=()=>B.map(e=>({label:e.label,value:e.suffix})),Se=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));i.AddDecimalCommand=x,i.CURRENCYFORMAT=H,i.DATEFMTLISG=B,i.NUMBERFORMAT=G,i.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=V,i.SetCurrencyCommand=W,i.SetNumfmtCommand=R,i.SetPercentCommand=K,i.SubtractDecimalCommand=q,i.currencySymbols=O,i.getCurrencyFormat=A,i.getCurrencyFormatOptions=de,i.getCurrencyOptions=fe,i.getCurrencySymbolByLocale=F,i.getCurrencySymbolIconByLocale=j,i.getCurrencyType=me,i.getDateFormatOptions=ge,i.getDecimalFromPattern=P,i.getDecimalString=L,i.getNumberFormatOptions=Se,i.getNumfmtParseValueFilter=ne,i.getPatternPreview=k,i.getPatternPreviewIgnoreGeneral=z,i.getPatternType=Q,i.isPatternHasDecimal=J,i.localeCurrencySymbolMap=E,i.setPatternDecimal=U,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(r,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-formula"],t):(r=typeof globalThis<"u"?globalThis:r||self,t(r.UniverSheetsNumfmt={},r.UniverCore,r.UniverSheets,r.rxjs,r.UniverEngineFormula))})(this,(function(r,t,u,N,X){"use strict";var de=Object.defineProperty;var ge=(r,t,u)=>t in r?de(r,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[t]=u;var V=(r,t,u)=>ge(r,typeof t!="symbol"?t+"":t,u);const P=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function j(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function A(e,a=2){let i=a;a>127&&(i=127);let n="";return i>0&&(n=`.${"0".repeat(i)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const B=[{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"}],G=[{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"}],H=[{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"}],U=(e,a=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:a},L=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,a)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${L(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${L(Number(a||0))}$1`):n).join(";"),J=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),I={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,a)=>{if(!a)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=u.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:o}=l,f=a.values.filter(c=>!!c.pattern),T=a.values.filter(c=>!c.pattern),M=u.transformCellsToRange(m,S,f),y={unitId:m,subUnitId:S,ranges:T.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},b=[],p=[];if(f.length){const c=f.reduce((g,d)=>{t.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:t.CellValueType.STRING});const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=u.rangeMerge(d.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const h=u.factorySetNumfmtUndoMutation(e,M);p.push(...h)}if(T.length){y.ranges=u.rangeMerge(y.ranges);const c=T.reduce((g,d)=>{const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),v=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:y},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const h=u.factoryRemoveNumfmtUndoMutation(e,y);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:v.getMatrix()}},...h)}const C=t.sequenceExecute(b,i).result;return C&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),C}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(!c){const h=m.worksheet.getCellRaw(p,C);if(!f&&h&&h.t===t.CellValueType.NUMBER&&h.v){const g=/\.(\d*)$/.exec(String(h.v));if(g){const d=g[1].length;if(!d)return;f=Math.max(f,d)}}return}const v=U(c.pattern);f=v>f?v:f})});const T=f+1,M=$(`0${T>0?".0":""}`,T),y=[];return l.forEach(b=>{t.Range.foreach(b.range,(p,C)=>{const c=n.getValue(S,o,p,C);if(t.isDefaultFormat(c==null?void 0:c.pattern))y.push({row:p,col:C,pattern:M});else{const v=U(c.pattern),h=$(c.pattern,v+1);h!==c.pattern&&y.push({row:p,col:C,pattern:h})}})}),y.length?await a.executeCommand(I.id,{values:y}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(t.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=j(n.getCurrentLocale()),S=A(m.locale);return s.forEach(f=>{t.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(I.id,{values:l})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),n=e.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(o,f)=>{s.push({row:o,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(I.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(u.SheetsSelectionsService),n=e.get(u.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(!v){const g=m.worksheet.getCellRaw(C,c);if(!f&&g&&g.t===t.CellValueType.NUMBER&&g.v){const d=/\.(\d*)$/.exec(String(g.v));if(d){const _=d[1].length;if(!_)return;f=Math.max(f,_)}}return}const h=U(v.pattern);f=h>f?h:f})});const T=f-1,M=$(`0${T>0?".0":"."}`,T),y=[];return l.forEach(p=>{t.Range.foreach(p.range,(C,c)=>{const v=n.getValue(S,o,C,c);if(t.isDefaultFormat(v==null?void 0:v.pattern))y.push({row:C,col:c,pattern:M});else{const h=U(v.pattern);y.push({row:C,col:c,pattern:$(v.pattern,h-1)})}})}),await a.executeCommand(I.id,{values:y})}},D="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,i="en")=>{const n=t.numfmt.formatColor(e,a),s=n?String(n):void 0,l=t.numfmt.format(e,a,{locale:i,throws:!1});return a<0?{result:l,color:s}:{result:l}},Y=(e,a,i)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(X.stripErrorMargin(a))}:k(e,a,i);var ee=Object.getOwnPropertyDescriptor,te=(e,a,i,n)=>{for(var s=n>1?void 0:n?ee(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},R=(e,a)=>(i,n)=>a(i,n,e);const ne={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,o){super();V(this,"_locale$",new N.BehaviorSubject("en"));V(this,"locale$",this._locale$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=o,this._initInterceptorCellContent()}get locale(){const i=this._locale$.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.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const i=new t.ObjectMatrix;this.disposeWithMe(N.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,C;if(!n||n.v===void 0||n.v===null||n.t===t.CellValueType.BOOLEAN||n.t===t.CellValueType.FORCE_STRING)return l(n);const m=s.unitId,S=s.subUnitId;let o;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(o=c.n)}if(o||(o=this._numfmtService.getValue(m,S,s.row,s.col)),t.isDefaultFormat(o==null?void 0:o.pattern)||n.t!==t.CellValueType.NUMBER&&u.checkCellValueType(n.v,n.t)!==t.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(o==null?void 0:o.pattern))return(p=this._configService.getConfig(D))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},l(n));let T="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${o==null?void 0:o.pattern}`)return l({...n,...M.result});const y=Y(o==null?void 0:o.pattern,Number(f.v),this.locale);if(T=y.result,!T)return l(n);const b={v:T,t:t.CellValueType.NUMBER};if(y.color){const c=(C=this._themeService.getColorFromTheme(`${y.color}.500`))!=null?C:y.color;c&&(b.interceptorStyle={cl:{rgb:c}})}return i.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${o==null?void 0:o.pattern}`}),Object.assign(n,b),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{t.Range.foreach(S,(o,f)=>{i.realDeleteValue(o,f)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:N.of(null)}),N.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},r.SheetsNumfmtCellContentController=te([R(0,t.IUniverInstanceService),R(1,t.Inject(u.SheetInterceptorService)),R(2,t.Inject(t.ThemeService)),R(3,t.Inject(t.ICommandService)),R(4,t.Inject(u.INumfmtService)),R(5,t.Inject(t.LocaleService)),R(6,t.IConfigService)],r.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var re=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(e,a,i)=>a in e?re(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,le=(e,a,i,n)=>{for(var s=n>1?void 0:n?ie(a,i):a,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},w=(e,a)=>(i,n)=>a(i,n,e),z=(e,a,i)=>se(e,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,i,n,s){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},Z,this._config);this._configService.setConfig(D,l)}onStarting(){t.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]])}onRendered(){[x,q,W,K,I].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},z(r.UniverSheetsNumfmtPlugin,"pluginName",ae),z(r.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=le([t.DependentOn(u.UniverSheetsPlugin),w(1,t.Inject(t.Injector)),w(2,t.IConfigService),w(3,t.ICommandService)],r.UniverSheetsNumfmtPlugin);const ce=e=>P.find(i=>e.includes(i)),oe=()=>P.map(e=>({label:e,value:e})),ue=e=>H.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),me=()=>B.map(e=>({label:e.label,value:e.suffix})),fe=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=H,r.DATEFMTLISG=B,r.NUMBERFORMAT=G,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,r.SetCurrencyCommand=W,r.SetNumfmtCommand=I,r.SetPercentCommand=K,r.SubtractDecimalCommand=q,r.currencySymbols=P,r.getCurrencyFormat=A,r.getCurrencyFormatOptions=ue,r.getCurrencyOptions=oe,r.getCurrencySymbolByLocale=F,r.getCurrencySymbolIconByLocale=j,r.getCurrencyType=ce,r.getDateFormatOptions=me,r.getDecimalFromPattern=U,r.getDecimalString=L,r.getNumberFormatOptions=fe,r.getPatternPreview=k,r.getPatternPreviewIgnoreGeneral=Y,r.getPatternType=Q,r.isPatternHasDecimal=J,r.localeCurrencySymbolMap=E,r.setPatternDecimal=$,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -58,16 +58,16 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/core": "0.10.
|
|
62
|
-
"@univerjs/engine-formula": "0.10.
|
|
63
|
-
"@univerjs/sheets": "0.10.
|
|
61
|
+
"@univerjs/core": "0.10.9",
|
|
62
|
+
"@univerjs/engine-formula": "0.10.9",
|
|
63
|
+
"@univerjs/sheets": "0.10.9"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"rxjs": "^7.8.2",
|
|
67
67
|
"typescript": "^5.9.2",
|
|
68
68
|
"vite": "^7.1.4",
|
|
69
69
|
"vitest": "^3.2.4",
|
|
70
|
-
"@univerjs-infra/shared": "0.10.
|
|
70
|
+
"@univerjs-infra/shared": "0.10.9"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"test": "vitest run",
|