@univerjs/sheets-numfmt 0.20.1 → 0.21.0
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 +64 -1
- package/lib/cjs/index.js +951 -1
- package/lib/es/facade.js +65 -1
- package/lib/es/index.js +913 -1
- package/lib/facade.js +65 -1
- package/lib/index.js +913 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,951 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets`),n=require(`rxjs`),r=require(`@univerjs/engine-formula`);const i=`$.£.¥.¤.֏.؋.৳.฿.៛.₡.₦.₩.₪.₫.€.₭.₮.₱.₲.₴.₸.₹.₺.₼.₽.₾.₿.﷼`.split(`.`),a=new Map([[e.LocaleType.EN_US,`$`],[e.LocaleType.RU_RU,`₽`],[e.LocaleType.VI_VN,`₫`],[e.LocaleType.ZH_CN,`¥`],[e.LocaleType.ZH_TW,`NT$`],[e.LocaleType.FR_FR,`€`],[e.LocaleType.FA_IR,`﷼`],[e.LocaleType.KO_KR,`₩`],[e.LocaleType.ES_ES,`€`],[e.LocaleType.CA_ES,`€`],[e.LocaleType.SK_SK,`€`]]);function o(t){switch(t){case e.LocaleType.CA_ES:case e.LocaleType.ES_ES:case e.LocaleType.FR_FR:case e.LocaleType.SK_SK:return{icon:`EuroIcon`,symbol:a.get(t)||`€`,locale:t};case e.LocaleType.RU_RU:return{icon:`RoubleIcon`,symbol:a.get(t)||`₽`,locale:t};case e.LocaleType.ZH_CN:return{icon:`RmbIcon`,symbol:a.get(t)||`¥`,locale:t};case e.LocaleType.EN_US:default:return{icon:`DollarIcon`,symbol:`$`,locale:e.LocaleType.EN_US}}}function s(e){return a.get(e)||`$`}function c(e,t=2){let n=t;t>127&&(n=127);let r=``;return n>0&&(r=`.${`0`.repeat(n)}`),`"${s(e)}"#,##0${r}_);[Red]("${s(e)}"#,##0${r})`}const 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`}],u=[{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`}],d=[{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`}],f=(t,n=0)=>{var r;return t?(r=e.numfmt.getFormatInfo(t).maxDecimals)==null?n:r:n},p=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),m=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${p(Number(t||0))}`):/0([^0]?)|0$/.test(e)?e.replace(/0([^0]+)|0$/,`0${t>0?`.`:``}${p(Number(t||0))}$1`):e).join(`;`),h=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),g={id:`sheet.command.numfmt.set.numfmt`,type:e.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;let i=n.get(e.ICommandService),a=n.get(e.IUniverInstanceService),o=n.get(e.IUndoRedoService),s=(0,t.getSheetCommandTarget)(a,r);if(!s)return!1;let{unitId:c,subUnitId:l,worksheet:u}=s,d=r.values.filter(e=>!!e.pattern),f=r.values.filter(e=>!e.pattern),p=(0,t.transformCellsToRange)(c,l,d),m={unitId:c,subUnitId:l,ranges:f.map(e=>({startColumn:e.col,startRow:e.row,endColumn:e.col,endRow:e.row}))},h=[],g=[];if(d.length){let r=d.reduce((n,r)=>{(0,e.isTextFormat)(r.pattern)&&n.setValue(r.row,r.col,{t:e.CellValueType.STRING});let i=u.getCellRaw(r.row,r.col);if(i){let e=(0,t.checkCellValueType)(i.v);e!==i.t&&n.setValue(r.row,r.col,{t:e})}return n},new e.ObjectMatrix).getMatrix(),i=new e.ObjectMatrix;new e.ObjectMatrix(r).forValue((e,t)=>{let n=u.getCellRaw(e,t);n?i.setValue(e,t,{t:n.t}):i.setValue(e,t,{t:void 0})}),Object.keys(p.values).forEach(e=>{let n=p.values[e];n.ranges=(0,t.rangeMerge)(n.ranges)}),h.push({id:t.SetNumfmtMutation.id,params:p});let a=(0,t.factorySetNumfmtUndoMutation)(n,p);g.push(...a)}if(f.length){m.ranges=(0,t.rangeMerge)(m.ranges);let r=f.reduce((e,n)=>{let r=u.getCellRaw(n.row,n.col);if(r){let i=(0,t.checkCellValueType)(r.v);i!==r.t&&e.setValue(n.row,n.col,{t:i})}return e},new e.ObjectMatrix).getMatrix(),i=new e.ObjectMatrix;new e.ObjectMatrix(r).forValue((e,t)=>{let n=u.getCellRaw(e,t);n?i.setValue(e,t,{t:n.t}):i.setValue(e,t,{t:void 0})}),h.push({id:t.RemoveNumfmtMutation.id,params:m},{id:t.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:r}});let a=(0,t.factoryRemoveNumfmtUndoMutation)(n,m);g.push({id:t.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:i.getMatrix()}},...a)}let _=(0,e.sequenceExecute)(h,i).result;return _&&o.pushUndoRedo({unitID:c,undoMutations:g,redoMutations:h}),_}},_={id:`sheet.command.numfmt.add.decimal.command`,type:e.CommandType.COMMAND,handler:async n=>{let r=n.get(e.ICommandService),i=n.get(t.SheetsSelectionsService),a=n.get(t.INumfmtService),o=n.get(e.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,t.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(t=>{e.Range.foreach(t.range,(t,n)=>{let r=a.getValue(l,u,t,n);if(!r){let r=c.worksheet.getCellRaw(t,n);if(!d&&r&&r.t===e.CellValueType.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;d=Math.max(d,t)}}return}let i=f(r.pattern);d=i>d?i:d})});let p=d+1,h=m(`0${p>0?`.0`:``}`,p),_=[];return s.forEach(t=>{e.Range.foreach(t.range,(t,n)=>{let r=a.getValue(l,u,t,n);if((0,e.isDefaultFormat)(r==null?void 0:r.pattern))_.push({row:t,col:n,pattern:h});else{let e=f(r.pattern),i=m(r.pattern,e+1);i!==r.pattern&&_.push({row:t,col:n,pattern:i})}})}),_.length?await r.executeCommand(g.id,{values:_}):!1}},v={id:`sheet.command.numfmt.set.currency`,type:e.CommandType.COMMAND,handler:async n=>{let r=n.get(e.ICommandService),i=n.get(t.SheetsSelectionsService),a=n.get(e.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let l=[],u=c(o(a.getCurrentLocale()).locale);return s.forEach(t=>{e.Range.foreach(t.range,(e,t)=>{l.push({row:e,col:t,pattern:u,type:`currency`})})}),await r.executeCommand(g.id,{values:l})}},y={id:`sheet.command.numfmt.set.percent`,type:e.CommandType.COMMAND,handler:async n=>{let r=n.get(e.ICommandService),i=n.get(t.SheetsSelectionsService).getCurrentSelections();if(!i||!i.length)return!1;let a=[];return i.forEach(t=>{e.Range.foreach(t.range,(e,t)=>{a.push({row:e,col:t,pattern:`0%`,type:`percent`})})}),await r.executeCommand(g.id,{values:a})}},b={id:`sheet.command.numfmt.subtract.decimal.command`,type:e.CommandType.COMMAND,handler:async n=>{let r=n.get(e.ICommandService),i=n.get(t.SheetsSelectionsService),a=n.get(t.INumfmtService),o=n.get(e.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,t.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(t=>{e.Range.foreach(t.range,(t,n)=>{let r=a.getValue(l,u,t,n);if(!r){let r=c.worksheet.getCellRaw(t,n);if(!d&&r&&r.t===e.CellValueType.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;d=Math.max(d,t)}}return}let i=f(r.pattern);d=i>d?i:d})});let p=d-1,h=m(`0${p>0?`.0`:`.`}`,p),_=[];return s.forEach(t=>{e.Range.foreach(t.range,(t,n)=>{let r=a.getValue(l,u,t,n);if((0,e.isDefaultFormat)(r==null?void 0:r.pattern))_.push({row:t,col:n,pattern:h});else{let e=f(r.pattern);_.push({row:t,col:n,pattern:m(r.pattern,e-1)})}})}),await r.executeCommand(g.id,{values:_})}},x=`sheets-numfmt.config`;Symbol(x);const S={},C=t=>e.numfmt.getFormatInfo(t).type||`unknown`,w=(t,n,r=`en`)=>{try{let i=e.numfmt.formatColor(t,n),a=i?String(i):void 0,o=e.numfmt.format(t,n,{locale:r,throws:!1});return n<0?{result:o,color:a}:{result:o}}catch(e){console.warn(`getPatternPreview error:`,t,e)}return{result:String(n)}},T=(t,n,i)=>t===e.DEFAULT_NUMBER_FORMAT?{result:String((0,r.stripErrorMargin)(n))}:w(t,n,i);function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function D(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){var t=D(e,`string`);return E(t)==`symbol`?t:t+``}function k(e,t,n){return(t=O(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function A(e,t){return function(n,r){t(n,r,e)}}function j(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const M={tl:{size:6,color:`#409f11`}};let N=class extends e.Disposable{constructor(e,t,r,i,a,o,s){super(),this._instanceService=e,this._sheetInterceptorService=t,this._themeService=r,this._commandService=i,this._numfmtService=a,this._localeService=o,this._configService=s,k(this,`_locale$`,new n.BehaviorSubject(`en`)),k(this,`locale$`,this._locale$.asObservable()),this._initInterceptorCellContent()}get locale(){let t=this._locale$.getValue();if(t)return t;switch(this._localeService.getCurrentLocale()){case e.LocaleType.FR_FR:return`fr`;case e.LocaleType.RU_RU:return`ru`;case e.LocaleType.VI_VN:return`vi`;case e.LocaleType.ZH_CN:return`zh-CN`;case e.LocaleType.KO_KR:return`ko`;case e.LocaleType.ZH_TW:return`zh-TW`;case e.LocaleType.ES_ES:case e.LocaleType.CA_ES:return`es`;case e.LocaleType.SK_SK:return`sk`;case e.LocaleType.EN_US:case e.LocaleType.FA_IR:default:return`en`}}_initInterceptorCellContent(){let r=new e.ObjectMatrix;this.disposeWithMe((0,n.merge)(this._locale$,this._localeService.currentLocale$).subscribe(()=>{r.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(t.INTERCEPTOR_POINT.CELL_CONTENT,{effect:e.InterceptorEffectEnum.Value|e.InterceptorEffectEnum.Style,handler:(n,i,a)=>{if(!n||n.v===void 0||n.v===null||n.t===e.CellValueType.BOOLEAN||n.t===e.CellValueType.FORCE_STRING)return a(n);let o=i.unitId,s=i.subUnitId,c;if(n!=null&&n.s){let e=i.workbook.getStyles().get(n.s);e!=null&&e.n&&(c=e.n)}if(c||(c=this._numfmtService.getValue(o,s,i.row,i.col)),(0,e.isDefaultFormat)(c==null?void 0:c.pattern)||n.t!==e.CellValueType.NUMBER&&(0,t.checkCellValueType)(n.v,n.t)!==e.CellValueType.NUMBER)return a(n);let l=n;if((!n||n===i.rawData)&&(n={...i.rawData}),(0,e.isTextFormat)(c==null?void 0:c.pattern)){var u;return(u=this._configService.getConfig(`sheets-numfmt.config`))!=null&&u.disableTextFormatMark?(n.t=e.CellValueType.STRING,a(n)):(n.t=e.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...M},a(n))}let d=``,f=r.getValue(i.row,i.col);if(f&&f.parameters===`${l.v}_${c==null?void 0:c.pattern}`)return a({...n,...f.result});let p=T(c==null?void 0:c.pattern,Number(l.v),this.locale);if(d=p.result,!d)return a(n);let m={v:d,t:e.CellValueType.NUMBER};if(p.color){var h;let e=(h=this._themeService.getColorFromTheme(`${p.color}.500`))==null?p.color:h;e&&(m.interceptorStyle={cl:{rgb:e}})}return r.setValue(i.row,i.col,{result:m,parameters:`${l.v}_${c==null?void 0:c.pattern}`}),Object.assign(n,m),a(n)},priority:t.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===t.SetNumfmtMutation.id){let t=n.params;Object.keys(t.values).forEach(n=>{t.values[n].ranges.forEach(t=>{e.Range.foreach(t,(e,t)=>{r.realDeleteValue(e,t)})})})}else if(n.id===t.SetRangeValuesMutation.id){let t=n.params;new e.ObjectMatrix(t.cellValue).forValue((e,t)=>{r.realDeleteValue(e,t)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).pipe((0,n.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,n.of)(null):t}),(0,n.skip)(1)).subscribe(()=>r.reset()))}setNumfmtLocal(e){this._locale$.next(e)}};N=j([A(0,e.IUniverInstanceService),A(1,(0,e.Inject)(t.SheetInterceptorService)),A(2,(0,e.Inject)(e.ThemeService)),A(3,(0,e.Inject)(e.ICommandService)),A(4,(0,e.Inject)(t.INumfmtService)),A(5,(0,e.Inject)(e.LocaleService)),A(6,e.IConfigService)],N);var P=`@univerjs/sheets-numfmt`,F=`0.20.1`;let I=class extends e.Plugin{constructor(t=S,n,r,i){super(),this._config=t,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,e.merge)({},S,this._config);this._configService.setConfig(x,a)}onStarting(){(0,e.registerDependencies)(this._injector,[[N]]),(0,e.touchDependencies)(this._injector,[[N]]),[_,b,v,y,g].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};k(I,`pluginName`,`SHEET_NUMFMT_PLUGIN`),k(I,`packageName`,P),k(I,`version`,F),k(I,`type`,e.UniverInstanceType.UNIVER_SHEET),I=j([(0,e.DependentOn)(t.UniverSheetsPlugin),A(1,(0,e.Inject)(e.Injector)),A(2,e.IConfigService),A(3,e.ICommandService)],I);const L=e=>i.find(t=>e.includes(t)),R=()=>i.map(e=>({label:e,value:e})),z=e=>d.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),B=()=>l.map(e=>({label:e.label,value:e.suffix})),V=()=>u.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=_,exports.CURRENCYFORMAT=d,exports.DATEFMTLISG=l,exports.NUMBERFORMAT=u,exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=x,exports.SetCurrencyCommand=v,exports.SetNumfmtCommand=g,exports.SetPercentCommand=y,Object.defineProperty(exports,`SheetsNumfmtCellContentController`,{enumerable:!0,get:function(){return N}}),exports.SubtractDecimalCommand=b,Object.defineProperty(exports,`UniverSheetsNumfmtPlugin`,{enumerable:!0,get:function(){return I}}),exports.currencySymbols=i,exports.getCurrencyFormat=c,exports.getCurrencyFormatOptions=z,exports.getCurrencyOptions=R,exports.getCurrencySymbolByLocale=s,exports.getCurrencySymbolIconByLocale=o,exports.getCurrencyType=L,exports.getDateFormatOptions=B,exports.getDecimalFromPattern=f,exports.getDecimalString=p,exports.getNumberFormatOptions=V,exports.getPatternPreview=w,exports.getPatternPreviewIgnoreGeneral=T,exports.getPatternType=C,exports.isPatternHasDecimal=h,exports.localeCurrencySymbolMap=a,exports.setPatternDecimal=m;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_sheets = require("@univerjs/sheets");
|
|
4
|
+
let rxjs = require("rxjs");
|
|
5
|
+
let _univerjs_engine_formula = require("@univerjs/engine-formula");
|
|
6
|
+
|
|
7
|
+
//#region src/base/const/currency-symbols.ts
|
|
8
|
+
/**
|
|
9
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
const currencySymbols = [
|
|
24
|
+
"$",
|
|
25
|
+
"£",
|
|
26
|
+
"¥",
|
|
27
|
+
"¤",
|
|
28
|
+
"֏",
|
|
29
|
+
"؋",
|
|
30
|
+
"৳",
|
|
31
|
+
"฿",
|
|
32
|
+
"៛",
|
|
33
|
+
"₡",
|
|
34
|
+
"₦",
|
|
35
|
+
"₩",
|
|
36
|
+
"₪",
|
|
37
|
+
"₫",
|
|
38
|
+
"€",
|
|
39
|
+
"₭",
|
|
40
|
+
"₮",
|
|
41
|
+
"₱",
|
|
42
|
+
"₲",
|
|
43
|
+
"₴",
|
|
44
|
+
"₸",
|
|
45
|
+
"₹",
|
|
46
|
+
"₺",
|
|
47
|
+
"₼",
|
|
48
|
+
"₽",
|
|
49
|
+
"₾",
|
|
50
|
+
"₿",
|
|
51
|
+
"﷼"
|
|
52
|
+
];
|
|
53
|
+
const localeCurrencySymbolMap = new Map([
|
|
54
|
+
[_univerjs_core.LocaleType.EN_US, "$"],
|
|
55
|
+
[_univerjs_core.LocaleType.RU_RU, "₽"],
|
|
56
|
+
[_univerjs_core.LocaleType.VI_VN, "₫"],
|
|
57
|
+
[_univerjs_core.LocaleType.ZH_CN, "¥"],
|
|
58
|
+
[_univerjs_core.LocaleType.ZH_TW, "NT$"],
|
|
59
|
+
[_univerjs_core.LocaleType.FR_FR, "€"],
|
|
60
|
+
[_univerjs_core.LocaleType.FA_IR, "﷼"],
|
|
61
|
+
[_univerjs_core.LocaleType.KO_KR, "₩"],
|
|
62
|
+
[_univerjs_core.LocaleType.ES_ES, "€"],
|
|
63
|
+
[_univerjs_core.LocaleType.CA_ES, "€"],
|
|
64
|
+
[_univerjs_core.LocaleType.SK_SK, "€"]
|
|
65
|
+
]);
|
|
66
|
+
/**
|
|
67
|
+
* Get the currency symbol icon based on the locale.
|
|
68
|
+
* TODO@wpxp123456: supplement more currency symbols icons. missing icons: ₩, ₫, NT$, ﷼.
|
|
69
|
+
*/
|
|
70
|
+
function getCurrencySymbolIconByLocale(locale) {
|
|
71
|
+
switch (locale) {
|
|
72
|
+
case _univerjs_core.LocaleType.CA_ES:
|
|
73
|
+
case _univerjs_core.LocaleType.ES_ES:
|
|
74
|
+
case _univerjs_core.LocaleType.FR_FR:
|
|
75
|
+
case _univerjs_core.LocaleType.SK_SK: return {
|
|
76
|
+
icon: "EuroIcon",
|
|
77
|
+
symbol: localeCurrencySymbolMap.get(locale) || "€",
|
|
78
|
+
locale
|
|
79
|
+
};
|
|
80
|
+
case _univerjs_core.LocaleType.RU_RU: return {
|
|
81
|
+
icon: "RoubleIcon",
|
|
82
|
+
symbol: localeCurrencySymbolMap.get(locale) || "₽",
|
|
83
|
+
locale
|
|
84
|
+
};
|
|
85
|
+
case _univerjs_core.LocaleType.ZH_CN: return {
|
|
86
|
+
icon: "RmbIcon",
|
|
87
|
+
symbol: localeCurrencySymbolMap.get(locale) || "¥",
|
|
88
|
+
locale
|
|
89
|
+
};
|
|
90
|
+
case _univerjs_core.LocaleType.EN_US:
|
|
91
|
+
default: return {
|
|
92
|
+
icon: "DollarIcon",
|
|
93
|
+
symbol: "$",
|
|
94
|
+
locale: _univerjs_core.LocaleType.EN_US
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the currency symbol by locale.
|
|
100
|
+
*/
|
|
101
|
+
function getCurrencySymbolByLocale(locale) {
|
|
102
|
+
return localeCurrencySymbolMap.get(locale) || "$";
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get the currency format string based on the locale and number of digits.
|
|
106
|
+
*/
|
|
107
|
+
function getCurrencyFormat(locale, numberDigits = 2) {
|
|
108
|
+
let _numberDigits = numberDigits;
|
|
109
|
+
if (numberDigits > 127) _numberDigits = 127;
|
|
110
|
+
let decimal = "";
|
|
111
|
+
if (_numberDigits > 0) decimal = `.${"0".repeat(_numberDigits)}`;
|
|
112
|
+
return `"${getCurrencySymbolByLocale(locale)}"#,##0${decimal}_);[Red]("${getCurrencySymbolByLocale(locale)}"#,##0${decimal})`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/base/const/formatdetail.ts
|
|
117
|
+
/**
|
|
118
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
119
|
+
*
|
|
120
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
121
|
+
* you may not use this file except in compliance with the License.
|
|
122
|
+
* You may obtain a copy of the License at
|
|
123
|
+
*
|
|
124
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
125
|
+
*
|
|
126
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
127
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
128
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
129
|
+
* See the License for the specific language governing permissions and
|
|
130
|
+
* limitations under the License.
|
|
131
|
+
*/
|
|
132
|
+
const DATEFMTLISG = [
|
|
133
|
+
{
|
|
134
|
+
label: "1930-08-05",
|
|
135
|
+
suffix: "yyyy-MM-dd"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
label: "1930/08/05",
|
|
139
|
+
suffix: "yyyy/MM/dd"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
label: "1930年08月05日",
|
|
143
|
+
suffix: "yyyy\"年\"MM\"月\"dd\"日\""
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
label: "08-05",
|
|
147
|
+
suffix: "MM-dd"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
label: "8月5日",
|
|
151
|
+
suffix: "M\"月\"d\"日\""
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
label: "13:30:30",
|
|
155
|
+
suffix: "h:mm:ss"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
label: "13:30",
|
|
159
|
+
suffix: "h:mm"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
label: "下午01:30",
|
|
163
|
+
suffix: "A/P hh:mm"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
label: "下午1:30",
|
|
167
|
+
suffix: "A/P h:mm"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
label: "下午1:30:30",
|
|
171
|
+
suffix: "A/P h:mm:ss"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
label: "08-05 下午 01:30",
|
|
175
|
+
suffix: "MM-dd A/P hh:mm"
|
|
176
|
+
}
|
|
177
|
+
];
|
|
178
|
+
const NUMBERFORMAT = [
|
|
179
|
+
{
|
|
180
|
+
label: "(1,235)",
|
|
181
|
+
suffix: "#,##0_);(#,##0)"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
label: "(1,235) ",
|
|
185
|
+
suffix: "#,##0_);[Red](#,##0)",
|
|
186
|
+
color: "red"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
label: "1,234.56",
|
|
190
|
+
suffix: "#,##0.00_);#,##0.00"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
label: "1,234.56",
|
|
194
|
+
suffix: "#,##0.00_);[Red]#,##0.00",
|
|
195
|
+
color: "red"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
label: "-1,234.56",
|
|
199
|
+
suffix: "#,##0.00_);-#,##0.00"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
label: "-1,234.56",
|
|
203
|
+
suffix: "#,##0.00_);[Red]-#,##0.00",
|
|
204
|
+
color: "red"
|
|
205
|
+
}
|
|
206
|
+
];
|
|
207
|
+
const CURRENCYFORMAT = [
|
|
208
|
+
{
|
|
209
|
+
label: (suffix) => `${suffix}1,235`,
|
|
210
|
+
suffix: (suffix) => `"${suffix}"#,##0.00_);"${suffix}"#,##0.00`
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
label: (suffix) => `${suffix}1,235`,
|
|
214
|
+
suffix: (suffix) => `"${suffix}"#,##0.00_);[Red]"${suffix}"#,##0.00`,
|
|
215
|
+
color: "red"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
label: (suffix) => `(${suffix}1,235)`,
|
|
219
|
+
suffix: (suffix) => `"${suffix}"#,##0.00_);("${suffix}"#,##0.00)`
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
label: (suffix) => `(${suffix}1,235)`,
|
|
223
|
+
suffix: (suffix) => `"${suffix}"#,##0.00_);[Red]("${suffix}"#,##0.00)`,
|
|
224
|
+
color: "red"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
label: (suffix) => `-${suffix}1,235`,
|
|
228
|
+
suffix: (suffix) => `"${suffix}"#,##0.00_);-"${suffix}"#,##0.00`
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
label: (suffix) => `-${suffix}1,235`,
|
|
232
|
+
suffix: (suffix) => `"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`,
|
|
233
|
+
color: "red"
|
|
234
|
+
}
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/utils/decimal.ts
|
|
239
|
+
/**
|
|
240
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
241
|
+
*
|
|
242
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
243
|
+
* you may not use this file except in compliance with the License.
|
|
244
|
+
* You may obtain a copy of the License at
|
|
245
|
+
*
|
|
246
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
247
|
+
*
|
|
248
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
249
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
250
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
251
|
+
* See the License for the specific language governing permissions and
|
|
252
|
+
* limitations under the License.
|
|
253
|
+
*/
|
|
254
|
+
/**
|
|
255
|
+
* the function decimal just use positive,negative configuration ignored
|
|
256
|
+
*/
|
|
257
|
+
const getDecimalFromPattern = (pattern, defaultValue = 0) => {
|
|
258
|
+
var _info$maxDecimals;
|
|
259
|
+
if (!pattern) return defaultValue;
|
|
260
|
+
return (_info$maxDecimals = _univerjs_core.numfmt.getFormatInfo(pattern).maxDecimals) !== null && _info$maxDecimals !== void 0 ? _info$maxDecimals : defaultValue;
|
|
261
|
+
};
|
|
262
|
+
const getDecimalString = (length) => new Array(Math.min(Math.max(0, Number(length)), 30)).fill(0).join("");
|
|
263
|
+
const setPatternDecimal = (patterns, decimalLength) => {
|
|
264
|
+
return patterns.split(";").map((pattern) => {
|
|
265
|
+
if (/\.0?/.test(pattern)) return pattern.replace(/\.0*/g, `${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}`);
|
|
266
|
+
if (/0([^0]?)|0$/.test(pattern)) return pattern.replace(/0([^0]+)|0$/, `0${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}$1`);
|
|
267
|
+
return pattern;
|
|
268
|
+
}).join(";");
|
|
269
|
+
};
|
|
270
|
+
const isPatternHasDecimal = (pattern) => /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern);
|
|
271
|
+
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/commands/commands/set-numfmt.command.ts
|
|
274
|
+
const SetNumfmtCommand = {
|
|
275
|
+
id: "sheet.command.numfmt.set.numfmt",
|
|
276
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
277
|
+
handler: (accessor, params) => {
|
|
278
|
+
if (!params) return false;
|
|
279
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
280
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
281
|
+
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
282
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, params);
|
|
283
|
+
if (!target) return false;
|
|
284
|
+
const { unitId, subUnitId, worksheet } = target;
|
|
285
|
+
const setCells = params.values.filter((value) => !!value.pattern);
|
|
286
|
+
const removeCells = params.values.filter((value) => !value.pattern);
|
|
287
|
+
const setRedos = (0, _univerjs_sheets.transformCellsToRange)(unitId, subUnitId, setCells);
|
|
288
|
+
const removeRedos = {
|
|
289
|
+
unitId,
|
|
290
|
+
subUnitId,
|
|
291
|
+
ranges: removeCells.map((cell) => ({
|
|
292
|
+
startColumn: cell.col,
|
|
293
|
+
startRow: cell.row,
|
|
294
|
+
endColumn: cell.col,
|
|
295
|
+
endRow: cell.row
|
|
296
|
+
}))
|
|
297
|
+
};
|
|
298
|
+
const redos = [];
|
|
299
|
+
const undos = [];
|
|
300
|
+
if (setCells.length) {
|
|
301
|
+
const setCellTypeObj = setCells.reduce((pre, cur) => {
|
|
302
|
+
if ((0, _univerjs_core.isTextFormat)(cur.pattern)) pre.setValue(cur.row, cur.col, { t: _univerjs_core.CellValueType.STRING });
|
|
303
|
+
const cell = worksheet.getCellRaw(cur.row, cur.col);
|
|
304
|
+
if (cell) {
|
|
305
|
+
const type = (0, _univerjs_sheets.checkCellValueType)(cell.v);
|
|
306
|
+
if (type !== cell.t) pre.setValue(cur.row, cur.col, { t: type });
|
|
307
|
+
}
|
|
308
|
+
return pre;
|
|
309
|
+
}, new _univerjs_core.ObjectMatrix()).getMatrix();
|
|
310
|
+
const undoSetCellTypeObj = new _univerjs_core.ObjectMatrix();
|
|
311
|
+
new _univerjs_core.ObjectMatrix(setCellTypeObj).forValue((row, col) => {
|
|
312
|
+
const cell = worksheet.getCellRaw(row, col);
|
|
313
|
+
if (cell) undoSetCellTypeObj.setValue(row, col, { t: cell.t });
|
|
314
|
+
else undoSetCellTypeObj.setValue(row, col, { t: void 0 });
|
|
315
|
+
});
|
|
316
|
+
Object.keys(setRedos.values).forEach((key) => {
|
|
317
|
+
const v = setRedos.values[key];
|
|
318
|
+
v.ranges = (0, _univerjs_sheets.rangeMerge)(v.ranges);
|
|
319
|
+
});
|
|
320
|
+
redos.push({
|
|
321
|
+
id: _univerjs_sheets.SetNumfmtMutation.id,
|
|
322
|
+
params: setRedos
|
|
323
|
+
});
|
|
324
|
+
const undo = (0, _univerjs_sheets.factorySetNumfmtUndoMutation)(accessor, setRedos);
|
|
325
|
+
undos.push(...undo);
|
|
326
|
+
}
|
|
327
|
+
if (removeCells.length) {
|
|
328
|
+
removeRedos.ranges = (0, _univerjs_sheets.rangeMerge)(removeRedos.ranges);
|
|
329
|
+
const setCellTypeObj = removeCells.reduce((pre, cur) => {
|
|
330
|
+
const cell = worksheet.getCellRaw(cur.row, cur.col);
|
|
331
|
+
if (cell) {
|
|
332
|
+
const type = (0, _univerjs_sheets.checkCellValueType)(cell.v);
|
|
333
|
+
if (type !== cell.t) pre.setValue(cur.row, cur.col, { t: type });
|
|
334
|
+
}
|
|
335
|
+
return pre;
|
|
336
|
+
}, new _univerjs_core.ObjectMatrix()).getMatrix();
|
|
337
|
+
const undoSetCellTypeObj = new _univerjs_core.ObjectMatrix();
|
|
338
|
+
new _univerjs_core.ObjectMatrix(setCellTypeObj).forValue((row, col) => {
|
|
339
|
+
const cell = worksheet.getCellRaw(row, col);
|
|
340
|
+
if (cell) undoSetCellTypeObj.setValue(row, col, { t: cell.t });
|
|
341
|
+
else undoSetCellTypeObj.setValue(row, col, { t: void 0 });
|
|
342
|
+
});
|
|
343
|
+
redos.push({
|
|
344
|
+
id: _univerjs_sheets.RemoveNumfmtMutation.id,
|
|
345
|
+
params: removeRedos
|
|
346
|
+
}, {
|
|
347
|
+
id: _univerjs_sheets.SetRangeValuesMutation.id,
|
|
348
|
+
params: {
|
|
349
|
+
unitId,
|
|
350
|
+
subUnitId,
|
|
351
|
+
cellValue: setCellTypeObj
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
const undo = (0, _univerjs_sheets.factoryRemoveNumfmtUndoMutation)(accessor, removeRedos);
|
|
355
|
+
undos.push({
|
|
356
|
+
id: _univerjs_sheets.SetRangeValuesMutation.id,
|
|
357
|
+
params: {
|
|
358
|
+
unitId,
|
|
359
|
+
subUnitId,
|
|
360
|
+
cellValue: undoSetCellTypeObj.getMatrix()
|
|
361
|
+
}
|
|
362
|
+
}, ...undo);
|
|
363
|
+
}
|
|
364
|
+
const result = (0, _univerjs_core.sequenceExecute)(redos, commandService).result;
|
|
365
|
+
if (result) undoRedoService.pushUndoRedo({
|
|
366
|
+
unitID: unitId,
|
|
367
|
+
undoMutations: undos,
|
|
368
|
+
redoMutations: redos
|
|
369
|
+
});
|
|
370
|
+
return result;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region src/commands/commands/add-decimal.command.ts
|
|
376
|
+
const AddDecimalCommand = {
|
|
377
|
+
id: "sheet.command.numfmt.add.decimal.command",
|
|
378
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
379
|
+
handler: async (accessor) => {
|
|
380
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
381
|
+
const selectionManagerService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
|
|
382
|
+
const numfmtService = accessor.get(_univerjs_sheets.INumfmtService);
|
|
383
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
384
|
+
const selections = selectionManagerService.getCurrentSelections();
|
|
385
|
+
if (!selections || !selections.length) return false;
|
|
386
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
|
|
387
|
+
if (!target) return false;
|
|
388
|
+
const { unitId, subUnitId } = target;
|
|
389
|
+
let maxDecimals = 0;
|
|
390
|
+
selections.forEach((selection) => {
|
|
391
|
+
_univerjs_core.Range.foreach(selection.range, (row, col) => {
|
|
392
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
393
|
+
if (!numfmtValue) {
|
|
394
|
+
const cell = target.worksheet.getCellRaw(row, col);
|
|
395
|
+
if (!maxDecimals && cell && cell.t === _univerjs_core.CellValueType.NUMBER && cell.v) {
|
|
396
|
+
const regResult = /\.(\d*)$/.exec(String(cell.v));
|
|
397
|
+
if (regResult) {
|
|
398
|
+
const length = regResult[1].length;
|
|
399
|
+
if (!length) return;
|
|
400
|
+
maxDecimals = Math.max(maxDecimals, length);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const decimals = getDecimalFromPattern(numfmtValue.pattern);
|
|
406
|
+
maxDecimals = decimals > maxDecimals ? decimals : maxDecimals;
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
const decimals = maxDecimals + 1;
|
|
410
|
+
const defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : ""}`, decimals);
|
|
411
|
+
const values = [];
|
|
412
|
+
selections.forEach((selection) => {
|
|
413
|
+
_univerjs_core.Range.foreach(selection.range, (row, col) => {
|
|
414
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
415
|
+
if ((0, _univerjs_core.isDefaultFormat)(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) values.push({
|
|
416
|
+
row,
|
|
417
|
+
col,
|
|
418
|
+
pattern: defaultPattern
|
|
419
|
+
});
|
|
420
|
+
else {
|
|
421
|
+
const decimals = getDecimalFromPattern(numfmtValue.pattern);
|
|
422
|
+
const pattern = setPatternDecimal(numfmtValue.pattern, decimals + 1);
|
|
423
|
+
pattern !== numfmtValue.pattern && values.push({
|
|
424
|
+
row,
|
|
425
|
+
col,
|
|
426
|
+
pattern
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
if (values.length) return await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/commands/commands/set-currency.command.ts
|
|
438
|
+
/**
|
|
439
|
+
* This command is triggered by clicking the currency symbol icon in the menu.
|
|
440
|
+
* So the currency format is determined by the currency symbol icon.
|
|
441
|
+
*/
|
|
442
|
+
const SetCurrencyCommand = {
|
|
443
|
+
id: "sheet.command.numfmt.set.currency",
|
|
444
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
445
|
+
handler: async (accessor) => {
|
|
446
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
447
|
+
const selectionManagerService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
|
|
448
|
+
const localeService = accessor.get(_univerjs_core.LocaleService);
|
|
449
|
+
const selections = selectionManagerService.getCurrentSelections();
|
|
450
|
+
if (!selections || !selections.length) return false;
|
|
451
|
+
const values = [];
|
|
452
|
+
const currencyFormat = getCurrencyFormat(getCurrencySymbolIconByLocale(localeService.getCurrentLocale()).locale);
|
|
453
|
+
selections.forEach((selection) => {
|
|
454
|
+
_univerjs_core.Range.foreach(selection.range, (row, col) => {
|
|
455
|
+
values.push({
|
|
456
|
+
row,
|
|
457
|
+
col,
|
|
458
|
+
pattern: currencyFormat,
|
|
459
|
+
type: "currency"
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
return await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region src/commands/commands/set-percent.command.ts
|
|
469
|
+
const SetPercentCommand = {
|
|
470
|
+
id: "sheet.command.numfmt.set.percent",
|
|
471
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
472
|
+
handler: async (accessor) => {
|
|
473
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
474
|
+
const selections = accessor.get(_univerjs_sheets.SheetsSelectionsService).getCurrentSelections();
|
|
475
|
+
if (!selections || !selections.length) return false;
|
|
476
|
+
const values = [];
|
|
477
|
+
const suffix = "0%";
|
|
478
|
+
selections.forEach((selection) => {
|
|
479
|
+
_univerjs_core.Range.foreach(selection.range, (row, col) => {
|
|
480
|
+
values.push({
|
|
481
|
+
row,
|
|
482
|
+
col,
|
|
483
|
+
pattern: suffix,
|
|
484
|
+
type: "percent"
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
return await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/commands/commands/subtract-decimal.command.ts
|
|
494
|
+
const SubtractDecimalCommand = {
|
|
495
|
+
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
496
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
497
|
+
handler: async (accessor) => {
|
|
498
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
499
|
+
const selectionManagerService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
|
|
500
|
+
const numfmtService = accessor.get(_univerjs_sheets.INumfmtService);
|
|
501
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
502
|
+
const selections = selectionManagerService.getCurrentSelections();
|
|
503
|
+
if (!selections || !selections.length) return false;
|
|
504
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
|
|
505
|
+
if (!target) return false;
|
|
506
|
+
const { unitId, subUnitId } = target;
|
|
507
|
+
let maxDecimals = 0;
|
|
508
|
+
selections.forEach((selection) => {
|
|
509
|
+
_univerjs_core.Range.foreach(selection.range, (row, col) => {
|
|
510
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
511
|
+
if (!numfmtValue) {
|
|
512
|
+
const cell = target.worksheet.getCellRaw(row, col);
|
|
513
|
+
if (!maxDecimals && cell && cell.t === _univerjs_core.CellValueType.NUMBER && cell.v) {
|
|
514
|
+
const regResult = /\.(\d*)$/.exec(String(cell.v));
|
|
515
|
+
if (regResult) {
|
|
516
|
+
const length = regResult[1].length;
|
|
517
|
+
if (!length) return;
|
|
518
|
+
maxDecimals = Math.max(maxDecimals, length);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const decimals = getDecimalFromPattern(numfmtValue.pattern);
|
|
524
|
+
maxDecimals = decimals > maxDecimals ? decimals : maxDecimals;
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
const decimals = maxDecimals - 1;
|
|
528
|
+
const defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : "."}`, decimals);
|
|
529
|
+
const values = [];
|
|
530
|
+
selections.forEach((selection) => {
|
|
531
|
+
_univerjs_core.Range.foreach(selection.range, (row, col) => {
|
|
532
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
533
|
+
if ((0, _univerjs_core.isDefaultFormat)(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) values.push({
|
|
534
|
+
row,
|
|
535
|
+
col,
|
|
536
|
+
pattern: defaultPattern
|
|
537
|
+
});
|
|
538
|
+
else {
|
|
539
|
+
const decimals = getDecimalFromPattern(numfmtValue.pattern);
|
|
540
|
+
values.push({
|
|
541
|
+
row,
|
|
542
|
+
col,
|
|
543
|
+
pattern: setPatternDecimal(numfmtValue.pattern, decimals - 1)
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
return await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
//#endregion
|
|
553
|
+
//#region src/config/config.ts
|
|
554
|
+
/**
|
|
555
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
556
|
+
*
|
|
557
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
558
|
+
* you may not use this file except in compliance with the License.
|
|
559
|
+
* You may obtain a copy of the License at
|
|
560
|
+
*
|
|
561
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
562
|
+
*
|
|
563
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
564
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
565
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
566
|
+
* See the License for the specific language governing permissions and
|
|
567
|
+
* limitations under the License.
|
|
568
|
+
*/
|
|
569
|
+
const SHEETS_NUMFMT_PLUGIN_CONFIG_KEY = "sheets-numfmt.config";
|
|
570
|
+
const configSymbol = Symbol(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY);
|
|
571
|
+
const defaultPluginConfig = {};
|
|
572
|
+
|
|
573
|
+
//#endregion
|
|
574
|
+
//#region src/utils/pattern.ts
|
|
575
|
+
const getPatternType = (pattern) => _univerjs_core.numfmt.getFormatInfo(pattern).type || "unknown";
|
|
576
|
+
const getPatternPreview = (pattern, value, locale = "en") => {
|
|
577
|
+
try {
|
|
578
|
+
const formatColor = _univerjs_core.numfmt.formatColor(pattern, value);
|
|
579
|
+
const color = formatColor ? String(formatColor) : void 0;
|
|
580
|
+
const result = _univerjs_core.numfmt.format(pattern, value, {
|
|
581
|
+
locale,
|
|
582
|
+
throws: false
|
|
583
|
+
});
|
|
584
|
+
if (value < 0) return {
|
|
585
|
+
result,
|
|
586
|
+
color
|
|
587
|
+
};
|
|
588
|
+
return { result };
|
|
589
|
+
} catch (e) {
|
|
590
|
+
console.warn("getPatternPreview error:", pattern, e);
|
|
591
|
+
}
|
|
592
|
+
return { result: String(value) };
|
|
593
|
+
};
|
|
594
|
+
const getPatternPreviewIgnoreGeneral = (pattern, value, locale) => {
|
|
595
|
+
if (pattern === _univerjs_core.DEFAULT_NUMBER_FORMAT) return { result: String((0, _univerjs_engine_formula.stripErrorMargin)(value)) };
|
|
596
|
+
return getPatternPreview(pattern, value, locale);
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
//#endregion
|
|
600
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
601
|
+
function _typeof(o) {
|
|
602
|
+
"@babel/helpers - typeof";
|
|
603
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
604
|
+
return typeof o;
|
|
605
|
+
} : function(o) {
|
|
606
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
607
|
+
}, _typeof(o);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
//#endregion
|
|
611
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
612
|
+
function toPrimitive(t, r) {
|
|
613
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
614
|
+
var e = t[Symbol.toPrimitive];
|
|
615
|
+
if (void 0 !== e) {
|
|
616
|
+
var i = e.call(t, r || "default");
|
|
617
|
+
if ("object" != _typeof(i)) return i;
|
|
618
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
619
|
+
}
|
|
620
|
+
return ("string" === r ? String : Number)(t);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
//#endregion
|
|
624
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
625
|
+
function toPropertyKey(t) {
|
|
626
|
+
var i = toPrimitive(t, "string");
|
|
627
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
632
|
+
function _defineProperty(e, r, t) {
|
|
633
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
634
|
+
value: t,
|
|
635
|
+
enumerable: !0,
|
|
636
|
+
configurable: !0,
|
|
637
|
+
writable: !0
|
|
638
|
+
}) : e[r] = t, e;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
//#endregion
|
|
642
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
643
|
+
function __decorateParam(paramIndex, decorator) {
|
|
644
|
+
return function(target, key) {
|
|
645
|
+
decorator(target, key, paramIndex);
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
//#endregion
|
|
650
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
651
|
+
function __decorate(decorators, target, key, desc) {
|
|
652
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
653
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
654
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
655
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
//#endregion
|
|
659
|
+
//#region src/controllers/numfmt-cell-content.controller.ts
|
|
660
|
+
const TEXT_FORMAT_MARK = { tl: {
|
|
661
|
+
size: 6,
|
|
662
|
+
color: "#409f11"
|
|
663
|
+
} };
|
|
664
|
+
let SheetsNumfmtCellContentController = class SheetsNumfmtCellContentController extends _univerjs_core.Disposable {
|
|
665
|
+
constructor(_instanceService, _sheetInterceptorService, _themeService, _commandService, _numfmtService, _localeService, _configService) {
|
|
666
|
+
super();
|
|
667
|
+
this._instanceService = _instanceService;
|
|
668
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
669
|
+
this._themeService = _themeService;
|
|
670
|
+
this._commandService = _commandService;
|
|
671
|
+
this._numfmtService = _numfmtService;
|
|
672
|
+
this._localeService = _localeService;
|
|
673
|
+
this._configService = _configService;
|
|
674
|
+
_defineProperty(this, "_locale$", new rxjs.BehaviorSubject("en"));
|
|
675
|
+
_defineProperty(this, "locale$", this._locale$.asObservable());
|
|
676
|
+
this._initInterceptorCellContent();
|
|
677
|
+
}
|
|
678
|
+
get locale() {
|
|
679
|
+
const _locale = this._locale$.getValue();
|
|
680
|
+
if (_locale) return _locale;
|
|
681
|
+
switch (this._localeService.getCurrentLocale()) {
|
|
682
|
+
case _univerjs_core.LocaleType.FR_FR: return "fr";
|
|
683
|
+
case _univerjs_core.LocaleType.RU_RU: return "ru";
|
|
684
|
+
case _univerjs_core.LocaleType.VI_VN: return "vi";
|
|
685
|
+
case _univerjs_core.LocaleType.ZH_CN: return "zh-CN";
|
|
686
|
+
case _univerjs_core.LocaleType.KO_KR: return "ko";
|
|
687
|
+
case _univerjs_core.LocaleType.ZH_TW: return "zh-TW";
|
|
688
|
+
case _univerjs_core.LocaleType.ES_ES:
|
|
689
|
+
case _univerjs_core.LocaleType.CA_ES: return "es";
|
|
690
|
+
case _univerjs_core.LocaleType.SK_SK: return "sk";
|
|
691
|
+
case _univerjs_core.LocaleType.EN_US:
|
|
692
|
+
case _univerjs_core.LocaleType.FA_IR:
|
|
693
|
+
default: return "en";
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
_initInterceptorCellContent() {
|
|
697
|
+
const renderCache = new _univerjs_core.ObjectMatrix();
|
|
698
|
+
this.disposeWithMe((0, rxjs.merge)(this._locale$, this._localeService.currentLocale$).subscribe(() => {
|
|
699
|
+
renderCache.reset();
|
|
700
|
+
}));
|
|
701
|
+
this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
702
|
+
effect: _univerjs_core.InterceptorEffectEnum.Value | _univerjs_core.InterceptorEffectEnum.Style,
|
|
703
|
+
handler: (cell, location, next) => {
|
|
704
|
+
if (!cell || cell.v === void 0 || cell.v === null || cell.t === _univerjs_core.CellValueType.BOOLEAN || cell.t === _univerjs_core.CellValueType.FORCE_STRING) return next(cell);
|
|
705
|
+
const unitId = location.unitId;
|
|
706
|
+
const sheetId = location.subUnitId;
|
|
707
|
+
let numfmtValue;
|
|
708
|
+
if (cell === null || cell === void 0 ? void 0 : cell.s) {
|
|
709
|
+
const style = location.workbook.getStyles().get(cell.s);
|
|
710
|
+
if (style === null || style === void 0 ? void 0 : style.n) numfmtValue = style.n;
|
|
711
|
+
}
|
|
712
|
+
if (!numfmtValue) numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col);
|
|
713
|
+
if ((0, _univerjs_core.isDefaultFormat)(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) return next(cell);
|
|
714
|
+
if (cell.t !== _univerjs_core.CellValueType.NUMBER) {
|
|
715
|
+
if ((0, _univerjs_sheets.checkCellValueType)(cell.v, cell.t) !== _univerjs_core.CellValueType.NUMBER) return next(cell);
|
|
716
|
+
}
|
|
717
|
+
const originCellValue = cell;
|
|
718
|
+
if (!cell || cell === location.rawData) cell = { ...location.rawData };
|
|
719
|
+
if ((0, _univerjs_core.isTextFormat)(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) {
|
|
720
|
+
var _this$_configService$;
|
|
721
|
+
if ((_this$_configService$ = this._configService.getConfig("sheets-numfmt.config")) === null || _this$_configService$ === void 0 ? void 0 : _this$_configService$.disableTextFormatMark) {
|
|
722
|
+
cell.t = _univerjs_core.CellValueType.STRING;
|
|
723
|
+
return next(cell);
|
|
724
|
+
}
|
|
725
|
+
cell.t = _univerjs_core.CellValueType.STRING;
|
|
726
|
+
cell.markers = {
|
|
727
|
+
...cell === null || cell === void 0 ? void 0 : cell.markers,
|
|
728
|
+
...TEXT_FORMAT_MARK
|
|
729
|
+
};
|
|
730
|
+
return next(cell);
|
|
731
|
+
}
|
|
732
|
+
let numfmtRes = "";
|
|
733
|
+
const cache = renderCache.getValue(location.row, location.col);
|
|
734
|
+
if (cache && cache.parameters === `${originCellValue.v}_${numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern}`) return next({
|
|
735
|
+
...cell,
|
|
736
|
+
...cache.result
|
|
737
|
+
});
|
|
738
|
+
const info = getPatternPreviewIgnoreGeneral(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern, Number(originCellValue.v), this.locale);
|
|
739
|
+
numfmtRes = info.result;
|
|
740
|
+
if (!numfmtRes) return next(cell);
|
|
741
|
+
const res = {
|
|
742
|
+
v: numfmtRes,
|
|
743
|
+
t: _univerjs_core.CellValueType.NUMBER
|
|
744
|
+
};
|
|
745
|
+
if (info.color) {
|
|
746
|
+
var _this$_themeService$g;
|
|
747
|
+
const color = (_this$_themeService$g = this._themeService.getColorFromTheme(`${info.color}.500`)) !== null && _this$_themeService$g !== void 0 ? _this$_themeService$g : info.color;
|
|
748
|
+
if (color) res.interceptorStyle = { cl: { rgb: color } };
|
|
749
|
+
}
|
|
750
|
+
renderCache.setValue(location.row, location.col, {
|
|
751
|
+
result: res,
|
|
752
|
+
parameters: `${originCellValue.v}_${numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern}`
|
|
753
|
+
});
|
|
754
|
+
Object.assign(cell, res);
|
|
755
|
+
return next(cell);
|
|
756
|
+
},
|
|
757
|
+
priority: _univerjs_sheets.InterceptCellContentPriority.NUMFMT
|
|
758
|
+
}));
|
|
759
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
760
|
+
if (commandInfo.id === _univerjs_sheets.SetNumfmtMutation.id) {
|
|
761
|
+
const params = commandInfo.params;
|
|
762
|
+
Object.keys(params.values).forEach((key) => {
|
|
763
|
+
params.values[key].ranges.forEach((range) => {
|
|
764
|
+
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
765
|
+
renderCache.realDeleteValue(row, col);
|
|
766
|
+
});
|
|
767
|
+
});
|
|
768
|
+
});
|
|
769
|
+
} else if (commandInfo.id === _univerjs_sheets.SetRangeValuesMutation.id) {
|
|
770
|
+
const params = commandInfo.params;
|
|
771
|
+
new _univerjs_core.ObjectMatrix(params.cellValue).forValue((row, col) => {
|
|
772
|
+
renderCache.realDeleteValue(row, col);
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
}));
|
|
776
|
+
this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.switchMap)((workbook) => {
|
|
777
|
+
var _workbook$activeSheet;
|
|
778
|
+
return (_workbook$activeSheet = workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) !== null && _workbook$activeSheet !== void 0 ? _workbook$activeSheet : (0, rxjs.of)(null);
|
|
779
|
+
}), (0, rxjs.skip)(1)).subscribe(() => renderCache.reset()));
|
|
780
|
+
}
|
|
781
|
+
setNumfmtLocal(locale) {
|
|
782
|
+
this._locale$.next(locale);
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
SheetsNumfmtCellContentController = __decorate([
|
|
786
|
+
__decorateParam(0, _univerjs_core.IUniverInstanceService),
|
|
787
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
|
|
788
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService)),
|
|
789
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.ICommandService)),
|
|
790
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.INumfmtService)),
|
|
791
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
|
|
792
|
+
__decorateParam(6, _univerjs_core.IConfigService)
|
|
793
|
+
], SheetsNumfmtCellContentController);
|
|
794
|
+
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region package.json
|
|
797
|
+
var name = "@univerjs/sheets-numfmt";
|
|
798
|
+
var version = "0.21.0";
|
|
799
|
+
|
|
800
|
+
//#endregion
|
|
801
|
+
//#region src/base/const/plugin-name.ts
|
|
802
|
+
/**
|
|
803
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
804
|
+
*
|
|
805
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
806
|
+
* you may not use this file except in compliance with the License.
|
|
807
|
+
* You may obtain a copy of the License at
|
|
808
|
+
*
|
|
809
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
810
|
+
*
|
|
811
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
812
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
813
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
814
|
+
* See the License for the specific language governing permissions and
|
|
815
|
+
* limitations under the License.
|
|
816
|
+
*/
|
|
817
|
+
const SHEET_NUMFMT_PLUGIN = "SHEET_NUMFMT_PLUGIN";
|
|
818
|
+
|
|
819
|
+
//#endregion
|
|
820
|
+
//#region src/plugin.ts
|
|
821
|
+
let UniverSheetsNumfmtPlugin = class UniverSheetsNumfmtPlugin extends _univerjs_core.Plugin {
|
|
822
|
+
constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
|
|
823
|
+
super();
|
|
824
|
+
this._config = _config;
|
|
825
|
+
this._injector = _injector;
|
|
826
|
+
this._configService = _configService;
|
|
827
|
+
this._commandService = _commandService;
|
|
828
|
+
const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
829
|
+
this._configService.setConfig(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY, rest);
|
|
830
|
+
}
|
|
831
|
+
onStarting() {
|
|
832
|
+
(0, _univerjs_core.registerDependencies)(this._injector, [[SheetsNumfmtCellContentController]]);
|
|
833
|
+
(0, _univerjs_core.touchDependencies)(this._injector, [[SheetsNumfmtCellContentController]]);
|
|
834
|
+
[
|
|
835
|
+
AddDecimalCommand,
|
|
836
|
+
SubtractDecimalCommand,
|
|
837
|
+
SetCurrencyCommand,
|
|
838
|
+
SetPercentCommand,
|
|
839
|
+
SetNumfmtCommand
|
|
840
|
+
].forEach((config) => {
|
|
841
|
+
this.disposeWithMe(this._commandService.registerCommand(config));
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
_defineProperty(UniverSheetsNumfmtPlugin, "pluginName", SHEET_NUMFMT_PLUGIN);
|
|
846
|
+
_defineProperty(UniverSheetsNumfmtPlugin, "packageName", name);
|
|
847
|
+
_defineProperty(UniverSheetsNumfmtPlugin, "version", version);
|
|
848
|
+
_defineProperty(UniverSheetsNumfmtPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
849
|
+
UniverSheetsNumfmtPlugin = __decorate([
|
|
850
|
+
(0, _univerjs_core.DependentOn)(_univerjs_sheets.UniverSheetsPlugin),
|
|
851
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
852
|
+
__decorateParam(2, _univerjs_core.IConfigService),
|
|
853
|
+
__decorateParam(3, _univerjs_core.ICommandService)
|
|
854
|
+
], UniverSheetsNumfmtPlugin);
|
|
855
|
+
|
|
856
|
+
//#endregion
|
|
857
|
+
//#region src/utils/currency.ts
|
|
858
|
+
/**
|
|
859
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
860
|
+
*
|
|
861
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
862
|
+
* you may not use this file except in compliance with the License.
|
|
863
|
+
* You may obtain a copy of the License at
|
|
864
|
+
*
|
|
865
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
866
|
+
*
|
|
867
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
868
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
869
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
870
|
+
* See the License for the specific language governing permissions and
|
|
871
|
+
* limitations under the License.
|
|
872
|
+
*/
|
|
873
|
+
const getCurrencyType = (pattern) => {
|
|
874
|
+
return currencySymbols.find((code) => pattern.includes(code));
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
//#endregion
|
|
878
|
+
//#region src/utils/options.ts
|
|
879
|
+
/**
|
|
880
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
881
|
+
*
|
|
882
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
883
|
+
* you may not use this file except in compliance with the License.
|
|
884
|
+
* You may obtain a copy of the License at
|
|
885
|
+
*
|
|
886
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
887
|
+
*
|
|
888
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
889
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
890
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
891
|
+
* See the License for the specific language governing permissions and
|
|
892
|
+
* limitations under the License.
|
|
893
|
+
*/
|
|
894
|
+
const getCurrencyOptions = () => currencySymbols.map((item) => ({
|
|
895
|
+
label: item,
|
|
896
|
+
value: item
|
|
897
|
+
}));
|
|
898
|
+
const getCurrencyFormatOptions = (suffix) => CURRENCYFORMAT.map((item) => ({
|
|
899
|
+
label: item.label(suffix),
|
|
900
|
+
value: item.suffix(suffix),
|
|
901
|
+
color: item.color
|
|
902
|
+
}));
|
|
903
|
+
const getDateFormatOptions = () => DATEFMTLISG.map((item) => ({
|
|
904
|
+
label: item.label,
|
|
905
|
+
value: item.suffix
|
|
906
|
+
}));
|
|
907
|
+
const getNumberFormatOptions = () => NUMBERFORMAT.map((item) => ({
|
|
908
|
+
label: item.label,
|
|
909
|
+
value: item.suffix,
|
|
910
|
+
color: item.color
|
|
911
|
+
}));
|
|
912
|
+
|
|
913
|
+
//#endregion
|
|
914
|
+
exports.AddDecimalCommand = AddDecimalCommand;
|
|
915
|
+
exports.CURRENCYFORMAT = CURRENCYFORMAT;
|
|
916
|
+
exports.DATEFMTLISG = DATEFMTLISG;
|
|
917
|
+
exports.NUMBERFORMAT = NUMBERFORMAT;
|
|
918
|
+
exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY = SHEETS_NUMFMT_PLUGIN_CONFIG_KEY;
|
|
919
|
+
exports.SetCurrencyCommand = SetCurrencyCommand;
|
|
920
|
+
exports.SetNumfmtCommand = SetNumfmtCommand;
|
|
921
|
+
exports.SetPercentCommand = SetPercentCommand;
|
|
922
|
+
Object.defineProperty(exports, 'SheetsNumfmtCellContentController', {
|
|
923
|
+
enumerable: true,
|
|
924
|
+
get: function () {
|
|
925
|
+
return SheetsNumfmtCellContentController;
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
exports.SubtractDecimalCommand = SubtractDecimalCommand;
|
|
929
|
+
Object.defineProperty(exports, 'UniverSheetsNumfmtPlugin', {
|
|
930
|
+
enumerable: true,
|
|
931
|
+
get: function () {
|
|
932
|
+
return UniverSheetsNumfmtPlugin;
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
exports.currencySymbols = currencySymbols;
|
|
936
|
+
exports.getCurrencyFormat = getCurrencyFormat;
|
|
937
|
+
exports.getCurrencyFormatOptions = getCurrencyFormatOptions;
|
|
938
|
+
exports.getCurrencyOptions = getCurrencyOptions;
|
|
939
|
+
exports.getCurrencySymbolByLocale = getCurrencySymbolByLocale;
|
|
940
|
+
exports.getCurrencySymbolIconByLocale = getCurrencySymbolIconByLocale;
|
|
941
|
+
exports.getCurrencyType = getCurrencyType;
|
|
942
|
+
exports.getDateFormatOptions = getDateFormatOptions;
|
|
943
|
+
exports.getDecimalFromPattern = getDecimalFromPattern;
|
|
944
|
+
exports.getDecimalString = getDecimalString;
|
|
945
|
+
exports.getNumberFormatOptions = getNumberFormatOptions;
|
|
946
|
+
exports.getPatternPreview = getPatternPreview;
|
|
947
|
+
exports.getPatternPreviewIgnoreGeneral = getPatternPreviewIgnoreGeneral;
|
|
948
|
+
exports.getPatternType = getPatternType;
|
|
949
|
+
exports.isPatternHasDecimal = isPatternHasDecimal;
|
|
950
|
+
exports.localeCurrencySymbolMap = localeCurrencySymbolMap;
|
|
951
|
+
exports.setPatternDecimal = setPatternDecimal;
|