@univerjs/sheets-numfmt 0.10.3 → 0.10.4

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.
@@ -1,46 +1,20 @@
1
+ import { LocaleType } from '@univerjs/core';
2
+ export declare const currencySymbols: string[];
3
+ export declare const localeCurrencySymbolMap: Map<LocaleType, string>;
1
4
  /**
2
- * Copyright 2023-present DreamNum Co., Ltd.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
5
+ * Get the currency symbol icon based on the locale.
6
+ * TODO@wpxp123456: supplement more currency symbols icons. missing icons: ₩, ₫, NT$, ﷼.
15
7
  */
16
- export declare const currencySymbols: string[];
17
- export declare const countryCurrencyMap: {
18
- US: string;
19
- CA: string;
20
- GB: string;
21
- JP: string;
22
- IN: string;
23
- AU: string;
24
- CN: string;
25
- KR: string;
26
- RU: string;
27
- AT: string;
28
- BE: string;
29
- CY: string;
30
- EE: string;
31
- FI: string;
32
- FR: string;
33
- DE: string;
34
- GR: string;
35
- IE: string;
36
- IT: string;
37
- LV: string;
38
- LT: string;
39
- LU: string;
40
- MT: string;
41
- NL: string;
42
- PT: string;
43
- SK: string;
44
- SI: string;
45
- ES: string;
8
+ export declare function getCurrencySymbolIconByLocale(locale: LocaleType): {
9
+ icon: string;
10
+ symbol: string;
11
+ locale: LocaleType;
46
12
  };
13
+ /**
14
+ * Get the currency symbol by locale.
15
+ */
16
+ export declare function getCurrencySymbolByLocale(locale: LocaleType): string;
17
+ /**
18
+ * Get the currency format string based on the locale and number of digits.
19
+ */
20
+ export declare function getCurrencyFormat(locale: LocaleType, numberDigits?: number): string;
@@ -1,2 +1,6 @@
1
1
  import { ICommand } from '@univerjs/core';
2
+ /**
3
+ * This command is triggered by clicking the currency symbol icon in the menu.
4
+ * So the currency format is determined by the currency symbol icon.
5
+ */
2
6
  export declare const SetCurrencyCommand: ICommand;
@@ -13,8 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { countryCurrencyMap } from './base/const/currency-symbols';
17
- export { currencySymbols } from './base/const/currency-symbols';
16
+ export { currencySymbols, getCurrencyFormat, getCurrencySymbolByLocale, getCurrencySymbolIconByLocale, localeCurrencySymbolMap } from './base/const/currency-symbols';
18
17
  export { CURRENCYFORMAT, DATEFMTLISG, NUMBERFORMAT } from './base/const/formatdetail';
19
18
  export { AddDecimalCommand } from './commands/commands/add-decimal.command';
20
19
  export { SetCurrencyCommand } from './commands/commands/set-currency.command';
@@ -25,7 +24,6 @@ export { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY } from './controllers/config.schema';
25
24
  export type { IUniverSheetsNumfmtConfig } from './controllers/config.schema';
26
25
  export { SheetsNumfmtCellContentController } from './controllers/numfmt-cell-content.controller';
27
26
  export { UniverSheetsNumfmtPlugin } from './plugin';
28
- export { MenuCurrencyService } from './service/menu.currency.service';
29
27
  export { getCurrencyType } from './utils/currency';
30
28
  export { getDecimalFromPattern, getDecimalString, isPatternHasDecimal, setPatternDecimal } from './utils/decimal';
31
29
  export { getCurrencyFormatOptions, getCurrencyOptions, getDateFormatOptions, getNumberFormatOptions } from './utils/options';
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-formula"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverSheetsNumfmt={},a.UniverCore,a.UniverSheets,a.rxjs,a.UniverEngineFormula))})(this,function(a,t,o,I,Z){"use strict";var fe=Object.defineProperty;var de=(a,t,o)=>t in a?fe(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o;var R=(a,t,o)=>de(a,typeof t!="symbol"?t+"":t,o);const 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:"€"},L=[{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"}],V=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],E=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),U=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${D(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${D(Number(r||0))}$1`):n).join(";"),J=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),$={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),l=o.getSheetCommandTarget(n,r);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:d}=l,c=r.values.filter(u=>!!u.pattern),b=r.values.filter(u=>!u.pattern),M=o.transformCellsToRange(m,S,c),C={unitId:m,subUnitId:S,ranges:b.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},T=[],h=[];if(c.length){const u=c.reduce((g,f)=>{t.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?y.setValue(g,f,{t:_.t}):y.setValue(g,f,{t:void 0})}),Object.keys(M.values).forEach(g=>{const f=M.values[g];f.ranges=o.rangeMerge(f.ranges)}),T.push({id:o.SetNumfmtMutation.id,params:M});const p=o.factorySetNumfmtUndoMutation(e,M);h.push(...p)}if(b.length){C.ranges=o.rangeMerge(C.ranges);const u=b.reduce((g,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(u).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?y.setValue(g,f,{t:_.t}):y.setValue(g,f,{t:void 0})}),T.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:u}});const p=o.factoryRemoveNumfmtUndoMutation(e,C);h.push({id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:y.getMatrix()}},...p)}const v=t.sequenceExecute(T,i).result;return v&&s.pushUndoRedo({unitID:m,undoMutations:h,redoMutations:T}),v}},x={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;l.forEach(T=>{t.Range.foreach(T.range,(h,v)=>{const u=n.getValue(S,d,h,v);if(!u){const p=m.worksheet.getCellRaw(h,v);if(!c&&p&&p.t===t.CellValueType.NUMBER&&p.v){const g=/\.(\d*)$/.exec(String(p.v));if(g){const f=g[1].length;if(!f)return;c=Math.max(c,f)}}return}const y=E(u.pattern);c=y>c?y:c})});const b=c+1,M=U(`0${b>0?".0":""}`,b),C=[];return l.forEach(T=>{t.Range.foreach(T.range,(h,v)=>{const u=n.getValue(S,d,h,v);if(!u)C.push({row:h,col:v,pattern:M});else{const y=E(u.pattern),p=U(u.pattern,y+1);p!==u.pattern&&C.push({row:h,col:v,pattern:p})}})}),C.length?await r.executeCommand($.id,{values:C}):!1}};class w{constructor(){R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(r){this._currencySymbol$.next(r)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const B={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(w),s=A[n.getCurrencySymbol()]||"$",l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=[],S=V[4].suffix(s);return l.forEach(c=>{t.Range.foreach(c.range,(b,M)=>{m.push({row:b,col:M,pattern:S,type:"currency"})})}),await r.executeCommand($.id,{values:m})}},H={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(o.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{t.Range.foreach(S.range,(d,c)=>{s.push({row:d,col:c,pattern:l,type:"percent"})})}),await r.executeCommand($.id,{values:s})}},K={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),s=e.get(t.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=o.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let c=0;l.forEach(h=>{t.Range.foreach(h.range,(v,u)=>{const y=n.getValue(S,d,v,u);if(!y){const g=m.worksheet.getCellRaw(v,u);if(!c&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const _=f[1].length;if(!_)return;c=Math.max(c,_)}}return}const p=E(y.pattern);c=p>c?p:c})});const b=c-1,M=U(`0${b>0?".0":"."}`,b),C=[];return l.forEach(h=>{t.Range.foreach(h.range,(v,u)=>{const y=n.getValue(S,d,v,u);if(!y)C.push({row:v,col:u,pattern:M});else{const p=E(y.pattern);C.push({row:v,col:u,pattern:U(y.pattern,p-1)})}})}),await r.executeCommand($.id,{values:C})}},j="sheets-numfmt.config",W={},X=e=>t.numfmt.getFormatInfo(e).type||"unknown",q=(e,r,i="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,l=t.numfmt.format(e,r,{locale:i,throws:!1});return r<0?{result:l,color:s}:{result:l}},Y=(e,r,i)=>e==="General"?{result:String(Z.stripErrorMargin(r))}:q(e,r,i);var Q=Object.getOwnPropertyDescriptor,ee=(e,r,i,n)=>{for(var s=n>1?void 0:n?Q(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},N=(e,r)=>(i,n)=>r(i,n,e);const te={tl:{size:6,color:"#409f11"}};a.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,s,l,m,S,d){super();R(this,"_locale$",new I.BehaviorSubject("en"));R(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=d,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(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var h,v;const m=s.unitId,S=s.subUnitId;let d;const c=n;if(!c||c.v===void 0||c.v===null)return l(n);if(n!=null&&n.s){const u=s.workbook.getStyles().get(n.s);u!=null&&u.n&&(d=u.n)}if(d||(d=this._numfmtService.getValue(m,S,s.row,s.col)),!d||d.pattern==="General"||c.t!==t.CellValueType.NUMBER&&o.checkCellValueType(c.v)!==t.CellValueType.NUMBER)return l(n);if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(d.pattern))return(h=this._configService.getConfig(j))!=null&&h.disableTextFormatMark?(n.t=t.CellValueType.STRING,l(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...te},l(n));let b="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${c.v}_${d.pattern}`)return l({...n,...M.result});const C=Y(d.pattern,Number(c.v),this.locale);if(b=C.result,!b)return l(n);const T={v:b,t:t.CellValueType.NUMBER};if(C.color){const u=(v=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?v:C.color;u&&(T.interceptorStyle={cl:{rgb:u}})}return i.setValue(s.row,s.col,{result:T,parameters:`${c.v}_${d.pattern}`}),Object.assign(n,T),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,(d,c)=>{i.realDeleteValue(d,c)})})})}else if(n.id===o.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:I.of(null)}),I.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},a.SheetsNumfmtCellContentController=ee([N(0,t.IUniverInstanceService),N(1,t.Inject(o.SheetInterceptorService)),N(2,t.Inject(t.ThemeService)),N(3,t.Inject(t.ICommandService)),N(4,t.Inject(o.INumfmtService)),N(5,t.Inject(t.LocaleService)),N(6,t.IConfigService)],a.SheetsNumfmtCellContentController);const ne="SHEET_NUMFMT_PLUGIN";class k extends t.Disposable{constructor(){super(...arguments);R(this,"_currencySymbol$",new I.BehaviorSubject("US"));R(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(i){this._currencySymbol$.next(i)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var re=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,ie=(e,r,i)=>r in e?re(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,se=(e,r,i,n)=>{for(var s=n>1?void 0:n?ae(r,i):r,l=e.length-1,m;l>=0;l--)(m=e[l])&&(s=m(s)||s);return s},F=(e,r)=>(i,n)=>r(i,n,e),z=(e,r,i)=>ie(e,typeof r!="symbol"?r+"":r,i);a.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=W,i,n,s){super(),this._config=r,this._injector=i,this._configService=n,this._commandService=s;const{...l}=t.merge({},W,this._config);this._configService.setConfig(j,l)}onStarting(){t.registerDependencies(this._injector,[[a.SheetsNumfmtCellContentController],[w],[k]]),t.touchDependencies(this._injector,[[a.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[k]]),[x,K,B,H,$].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}},z(a.UniverSheetsNumfmtPlugin,"pluginName",ne),z(a.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsNumfmtPlugin=se([t.DependentOn(o.UniverSheetsPlugin),F(1,t.Inject(t.Injector)),F(2,t.IConfigService),F(3,t.ICommandService)],a.UniverSheetsNumfmtPlugin);const le=e=>P.find(i=>e.includes(i)),ue=()=>P.map(e=>({label:e,value:e})),ce=e=>V.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),oe=()=>L.map(e=>({label:e.label,value:e.suffix})),me=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));a.AddDecimalCommand=x,a.CURRENCYFORMAT=V,a.DATEFMTLISG=L,a.MenuCurrencyService=w,a.NUMBERFORMAT=G,a.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=j,a.SetCurrencyCommand=B,a.SetNumfmtCommand=$,a.SetPercentCommand=H,a.SubtractDecimalCommand=K,a.countryCurrencyMap=A,a.currencySymbols=P,a.getCurrencyFormatOptions=ce,a.getCurrencyOptions=ue,a.getCurrencyType=le,a.getDateFormatOptions=oe,a.getDecimalFromPattern=E,a.getDecimalString=D,a.getNumberFormatOptions=me,a.getPatternPreview=q,a.getPatternPreviewIgnoreGeneral=Y,a.getPatternType=X,a.isPatternHasDecimal=J,a.setPatternDecimal=U,Object.defineProperty(a,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,o,N,X){"use strict";var de=Object.defineProperty;var ge=(r,t,o)=>t in r?de(r,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[t]=o;var D=(r,t,o)=>ge(r,typeof t!="symbol"?t+"":t,o);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 V(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)}`),`"${V(e)}"#,##0${n}_);[Red]("${V(e)}"#,##0${n})`}const G=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],H=[{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"}],B=[{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"}],$=(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 i=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),l=e.get(t.IUndoRedoService),s=o.getSheetCommandTarget(n,a);if(!s)return!1;const{unitId:m,subUnitId:S,worksheet:d}=s,u=a.values.filter(c=>!!c.pattern),T=a.values.filter(c=>!c.pattern),M=o.transformCellsToRange(m,S,u),C={unitId:m,subUnitId:S,ranges:T.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},b=[],p=[];if(u.length){const c=u.reduce((g,f)=>{t.isTextFormat(f.pattern)&&g.setValue(f.row,f.col,{t:t.CellValueType.STRING});const _=d.getCellRaw(f.row,f.col);if(_){const O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?y.setValue(g,f,{t:_.t}):y.setValue(g,f,{t:void 0})}),Object.keys(M.values).forEach(g=>{const f=M.values[g];f.ranges=o.rangeMerge(f.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 c=T.reduce((g,f)=>{const _=d.getCellRaw(f.row,f.col);if(_){const O=o.checkCellValueType(_.v);O!==_.t&&g.setValue(f.row,f.col,{t:O})}return g},new t.ObjectMatrix).getMatrix(),y=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,f)=>{const _=d.getCellRaw(g,f);_?y.setValue(g,f,{t:_.t}):y.setValue(g,f,{t:void 0})}),b.push({id:o.RemoveNumfmtMutation.id,params:C},{id:o.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});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,i).result;return v&&l.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),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),l=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const m=o.getSheetCommandTarget(l);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let u=0;s.forEach(b=>{t.Range.foreach(b.range,(p,v)=>{const c=n.getValue(S,d,p,v);if(!c){const h=m.worksheet.getCellRaw(p,v);if(!u&&h&&h.t===t.CellValueType.NUMBER&&h.v){const g=/\.(\d*)$/.exec(String(h.v));if(g){const f=g[1].length;if(!f)return;u=Math.max(u,f)}}return}const y=$(c.pattern);u=y>u?y:u})});const T=u+1,M=U(`0${T>0?".0":""}`,T),C=[];return s.forEach(b=>{t.Range.foreach(b.range,(p,v)=>{const c=n.getValue(S,d,p,v);if(!c)C.push({row:p,col:v,pattern:M});else{const y=$(c.pattern),h=U(c.pattern,y+1);h!==c.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),i=e.get(o.SheetsSelectionsService),n=e.get(t.LocaleService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const s=[],m=j(n.getCurrentLocale()),S=A(m.locale);return l.forEach(u=>{t.Range.foreach(u.range,(T,M)=>{s.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(R.id,{values:s})}},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 l=[],s="0%";return n.forEach(S=>{t.Range.foreach(S.range,(d,u)=>{l.push({row:d,col:u,pattern:s,type:"percent"})})}),await a.executeCommand(R.id,{values:l})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const a=e.get(t.ICommandService),i=e.get(o.SheetsSelectionsService),n=e.get(o.INumfmtService),l=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const m=o.getSheetCommandTarget(l);if(!m)return!1;const{unitId:S,subUnitId:d}=m;let u=0;s.forEach(p=>{t.Range.foreach(p.range,(v,c)=>{const y=n.getValue(S,d,v,c);if(!y){const g=m.worksheet.getCellRaw(v,c);if(!u&&g&&g.t===t.CellValueType.NUMBER&&g.v){const f=/\.(\d*)$/.exec(String(g.v));if(f){const _=f[1].length;if(!_)return;u=Math.max(u,_)}}return}const h=$(y.pattern);u=h>u?h:u})});const T=u-1,M=U(`0${T>0?".0":"."}`,T),C=[];return s.forEach(p=>{t.Range.foreach(p.range,(v,c)=>{const y=n.getValue(S,d,v,c);if(!y)C.push({row:v,col:c,pattern:M});else{const h=$(y.pattern);C.push({row:v,col:c,pattern:U(y.pattern,h-1)})}})}),await a.executeCommand(R.id,{values:C})}},F="sheets-numfmt.config",Z={},Q=e=>t.numfmt.getFormatInfo(e).type||"unknown",k=(e,a,i="en")=>{const n=t.numfmt.formatColor(e,a),l=n?String(n):void 0,s=t.numfmt.format(e,a,{locale:i,throws:!1});return a<0?{result:s,color:l}:{result:s}},Y=(e,a,i)=>e==="General"?{result:String(X.stripErrorMargin(a))}:k(e,a,i);var ee=Object.getOwnPropertyDescriptor,te=(e,a,i,n)=>{for(var l=n>1?void 0:n?ee(a,i):a,s=e.length-1,m;s>=0;s--)(m=e[s])&&(l=m(l)||l);return l},I=(e,a)=>(i,n)=>a(i,n,e);const ne={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(i,n,l,s,m,S,d){super();D(this,"_locale$",new N.BehaviorSubject("en"));D(this,"locale$",this._locale$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=l,this._commandService=s,this._numfmtService=m,this._localeService=S,this._configService=d,this._initInterceptorCellContent()}get 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(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,l,s)=>{var p,v;const m=l.unitId,S=l.subUnitId;let d;const u=n;if(!u||u.v===void 0||u.v===null)return s(n);if(n!=null&&n.s){const c=l.workbook.getStyles().get(n.s);c!=null&&c.n&&(d=c.n)}if(d||(d=this._numfmtService.getValue(m,S,l.row,l.col)),!d||d.pattern==="General"||u.t!==t.CellValueType.NUMBER&&o.checkCellValueType(u.v)!==t.CellValueType.NUMBER)return s(n);if((!n||n===l.rawData)&&(n={...l.rawData}),t.isTextFormat(d.pattern))return(p=this._configService.getConfig(F))!=null&&p.disableTextFormatMark?(n.t=t.CellValueType.STRING,s(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ne},s(n));let T="";const M=i.getValue(l.row,l.col);if(M&&M.parameters===`${u.v}_${d.pattern}`)return s({...n,...M.result});const C=Y(d.pattern,Number(u.v),this.locale);if(T=C.result,!T)return s(n);const b={v:T,t:t.CellValueType.NUMBER};if(C.color){const c=(v=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?v:C.color;c&&(b.interceptorStyle={cl:{rgb:c}})}return i.setValue(l.row,l.col,{result:b,parameters:`${u.v}_${d.pattern}`}),Object.assign(n,b),s(n)},priority:o.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===o.SetNumfmtMutation.id){const l=n.params;Object.keys(l.values).forEach(s=>{l.values[s].ranges.forEach(S=>{t.Range.foreach(S,(d,u)=>{i.realDeleteValue(d,u)})})})}else if(n.id===o.SetRangeValuesMutation.id){const l=n.params;new t.ObjectMatrix(l.cellValue).forValue((s,m)=>{i.realDeleteValue(s,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>{var l;return(l=n==null?void 0:n.activeSheet$)!=null?l:N.of(null)}),N.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(i){this._locale$.next(i)}},r.SheetsNumfmtCellContentController=te([I(0,t.IUniverInstanceService),I(1,t.Inject(o.SheetInterceptorService)),I(2,t.Inject(t.ThemeService)),I(3,t.Inject(t.ICommandService)),I(4,t.Inject(o.INumfmtService)),I(5,t.Inject(t.LocaleService)),I(6,t.IConfigService)],r.SheetsNumfmtCellContentController);const ae="SHEET_NUMFMT_PLUGIN";var re=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,le=(e,a,i)=>a in e?re(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,se=(e,a,i,n)=>{for(var l=n>1?void 0:n?ie(a,i):a,s=e.length-1,m;s>=0;s--)(m=e[s])&&(l=m(l)||l);return l},w=(e,a)=>(i,n)=>a(i,n,e),z=(e,a,i)=>le(e,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(a=Z,i,n,l){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=l;const{...s}=t.merge({},Z,this._config);this._configService.setConfig(F,s)}onStarting(){t.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]])}onRendered(){[x,q,W,K,R].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},z(r.UniverSheetsNumfmtPlugin,"pluginName",ae),z(r.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=se([t.DependentOn(o.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)),ue=()=>P.map(e=>({label:e,value:e})),oe=e=>B.map(a=>({label:a.label(e),value:a.suffix(e),color:a.color})),me=()=>G.map(e=>({label:e.label,value:e.suffix})),fe=()=>H.map(e=>({label:e.label,value:e.suffix,color:e.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=B,r.DATEFMTLISG=G,r.NUMBERFORMAT=H,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=F,r.SetCurrencyCommand=W,r.SetNumfmtCommand=R,r.SetPercentCommand=K,r.SubtractDecimalCommand=q,r.currencySymbols=P,r.getCurrencyFormat=A,r.getCurrencyFormatOptions=oe,r.getCurrencyOptions=ue,r.getCurrencySymbolByLocale=V,r.getCurrencySymbolIconByLocale=j,r.getCurrencyType=ce,r.getDateFormatOptions=me,r.getDecimalFromPattern=$,r.getDecimalString=L,r.getNumberFormatOptions=fe,r.getPatternPreview=k,r.getPatternPreviewIgnoreGeneral=Y,r.getPatternType=Q,r.isPatternHasDecimal=J,r.localeCurrencySymbolMap=E,r.setPatternDecimal=U,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",
3
+ "version": "0.10.4",
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.3",
62
- "@univerjs/sheets": "0.10.3",
63
- "@univerjs/engine-formula": "0.10.3"
61
+ "@univerjs/core": "0.10.4",
62
+ "@univerjs/engine-formula": "0.10.4",
63
+ "@univerjs/sheets": "0.10.4"
64
64
  },
65
65
  "devDependencies": {
66
66
  "rxjs": "^7.8.2",
67
67
  "typescript": "^5.8.3",
68
68
  "vite": "^7.0.6",
69
69
  "vitest": "^3.2.4",
70
- "@univerjs-infra/shared": "0.10.3"
70
+ "@univerjs-infra/shared": "0.10.4"
71
71
  },
72
72
  "scripts": {
73
73
  "test": "vitest run",
@@ -1,11 +0,0 @@
1
- import { countryCurrencyMap } from '../base/const/currency-symbols';
2
- import { Disposable } from '@univerjs/core';
3
- export declare class NumfmtCurrencyController extends Disposable {
4
- private _currencySymbol$;
5
- readonly currencySymbol$: import('rxjs').Observable<"AT" | "US" | "CA" | "GB" | "JP" | "IN" | "AU" | "CN" | "KR" | "RU" | "BE" | "CY" | "EE" | "FI" | "FR" | "DE" | "GR" | "IE" | "IT" | "LV" | "LT" | "LU" | "MT" | "NL" | "PT" | "SK" | "SI" | "ES">;
6
- /**
7
- * Set the currency symbol by setting the country code.
8
- */
9
- setCurrencySymbolByCountryCode(symbol: keyof typeof countryCurrencyMap): void;
10
- getCurrencySymbol(): "AT" | "US" | "CA" | "GB" | "JP" | "IN" | "AU" | "CN" | "KR" | "RU" | "BE" | "CY" | "EE" | "FI" | "FR" | "DE" | "GR" | "IE" | "IT" | "LV" | "LT" | "LU" | "MT" | "NL" | "PT" | "SK" | "SI" | "ES";
11
- }
@@ -1,10 +0,0 @@
1
- import { countryCurrencyMap } from '../base/const/currency-symbols';
2
- export declare class MenuCurrencyService {
3
- private _currencySymbol$;
4
- readonly currencySymbol$: import('rxjs').Observable<"AT" | "US" | "CA" | "GB" | "JP" | "IN" | "AU" | "CN" | "KR" | "RU" | "BE" | "CY" | "EE" | "FI" | "FR" | "DE" | "GR" | "IE" | "IT" | "LV" | "LT" | "LU" | "MT" | "NL" | "PT" | "SK" | "SI" | "ES">;
5
- /**
6
- * Set the currency symbol by setting the country code.
7
- */
8
- setCurrencySymbolByCountryCode(symbol: keyof typeof countryCurrencyMap): void;
9
- getCurrencySymbol(): "AT" | "US" | "CA" | "GB" | "JP" | "IN" | "AU" | "CN" | "KR" | "RU" | "BE" | "CY" | "EE" | "FI" | "FR" | "DE" | "GR" | "IE" | "IT" | "LV" | "LT" | "LU" | "MT" | "NL" | "PT" | "SK" | "SI" | "ES";
10
- }