@univerjs/sheets-numfmt 0.17.0 → 0.18.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 +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +1 -47
- package/lib/es/index.js +1 -640
- package/lib/facade.js +1 -47
- package/lib/index.js +1 -640
- package/lib/types/base/const/currency-symbols.d.ts +15 -0
- package/lib/types/commands/commands/add-decimal.command.d.ts +16 -1
- package/lib/types/commands/commands/set-currency.command.d.ts +16 -1
- package/lib/types/commands/commands/set-numfmt.command.d.ts +17 -2
- package/lib/types/commands/commands/set-percent.command.d.ts +16 -1
- package/lib/types/commands/commands/subtract-decimal.command.d.ts +16 -1
- package/lib/types/controllers/numfmt-cell-content.controller.d.ts +18 -2
- package/lib/types/controllers/type.d.ts +1 -1
- package/lib/types/facade/f-range.d.ts +15 -0
- package/lib/types/facade/f-workbook.d.ts +16 -1
- package/lib/types/plugin.d.ts +16 -1
- package/lib/types/utils/mutation.d.ts +16 -1
- package/lib/types/utils/pattern.d.ts +17 -2
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +9 -8
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
import type { ICommand } from '@univerjs/core';
|
|
2
17
|
/**
|
|
3
18
|
* This command is triggered by clicking the currency symbol icon in the menu.
|
|
4
19
|
* So the currency format is determined by the currency symbol icon.
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
import type { ICommand } from '@univerjs/core';
|
|
17
|
+
import type { FormatType } from '@univerjs/sheets';
|
|
3
18
|
export interface ISetNumfmtCommandParams {
|
|
4
19
|
unitId?: string;
|
|
5
20
|
subUnitId?: string;
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
import type { ICommand } from '@univerjs/core';
|
|
2
17
|
export declare const SetPercentCommand: ICommand;
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
import type { ICommand } from '@univerjs/core';
|
|
2
17
|
export declare const SubtractDecimalCommand: ICommand;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
import type { INumfmtLocaleTag } from '@univerjs/core';
|
|
17
|
+
import { Disposable, ICommandService, IConfigService, IUniverInstanceService, LocaleService, ThemeService } from '@univerjs/core';
|
|
2
18
|
import { INumfmtService, SheetInterceptorService } from '@univerjs/sheets';
|
|
3
19
|
export declare class SheetsNumfmtCellContentController extends Disposable {
|
|
4
20
|
private readonly _instanceService;
|
|
@@ -9,7 +25,7 @@ export declare class SheetsNumfmtCellContentController extends Disposable {
|
|
|
9
25
|
private _localeService;
|
|
10
26
|
private readonly _configService;
|
|
11
27
|
private _locale$;
|
|
12
|
-
locale$: import(
|
|
28
|
+
locale$: import("rxjs").Observable<INumfmtLocaleTag>;
|
|
13
29
|
constructor(_instanceService: IUniverInstanceService, _sheetInterceptorService: SheetInterceptorService, _themeService: ThemeService, _commandService: ICommandService, _numfmtService: INumfmtService, _localeService: LocaleService, _configService: IConfigService);
|
|
14
30
|
get locale(): INumfmtLocaleTag;
|
|
15
31
|
private _initInterceptorCellContent;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export declare const INumfmtController: import(
|
|
16
|
+
export declare const INumfmtController: import("@wendellhu/redi").IdentifierDecorator<INumfmtController>;
|
|
17
17
|
export interface INumfmtController {
|
|
18
18
|
openPanel(): void;
|
|
19
19
|
}
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
1
16
|
import { FRange } from '@univerjs/sheets/facade';
|
|
2
17
|
/**
|
|
3
18
|
* @ignore
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
import type { INumfmtLocaleTag } from '@univerjs/core';
|
|
2
17
|
import { FWorkbook } from '@univerjs/sheets/facade';
|
|
3
18
|
export interface IFWorkbookNumfmtMixin {
|
|
4
19
|
/**
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
import type { IUniverSheetsNumfmtConfig } from './config/config';
|
|
2
17
|
import { ICommandService, IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
3
18
|
export declare class UniverSheetsNumfmtPlugin extends Plugin {
|
|
4
19
|
private readonly _config;
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
import type { IMutationInfo } from '@univerjs/core';
|
|
2
17
|
export declare const mergeNumfmtMutations: (list: IMutationInfo[]) => IMutationInfo<object>[];
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
import type { INumfmtLocaleTag } from '@univerjs/core';
|
|
17
|
+
import type { FormatType } from '@univerjs/sheets';
|
|
3
18
|
export declare const getPatternType: (pattern: string) => FormatType;
|
|
4
19
|
interface IPatternPreview {
|
|
5
20
|
result: string;
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(require(`@univerjs/sheets-numfmt`),require(`@univerjs/sheets/facade`)):typeof define==`function`&&define.amd?define([`@univerjs/sheets-numfmt`,`@univerjs/sheets/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNumfmt,e.UniverSheetsFacade))})(this,function(e,t){var n=class extends t.FRange{setNumberFormat(t){let n=[],{startColumn:r,startRow:i,endColumn:a,endRow:o}=this._range;for(let e=i;e<=o;e++)for(let i=r;i<=a;i++)n.push({row:e,col:i,pattern:t});return this._commandService.syncExecuteCommand(e.SetNumfmtCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),values:n}),this}setNumberFormats(t){let n=[],{startColumn:r,startRow:i,endColumn:a,endRow:o}=this._range;for(let e=i;e<=o;e++)for(let o=r;o<=a;o++){var s;let a=(s=t[e-i])==null?void 0:s[o-r];n.push({row:e,col:o,pattern:a})}return this._commandService.syncExecuteCommand(e.SetNumfmtCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),values:n}),this}getNumberFormat(){var e,t;let n=this.getCellStyle();return(e=n==null||(t=n.numberFormat)==null?void 0:t.pattern)==null?``:e}getNumberFormats(){return this.getCellStyles().map(e=>e.map(e=>{var t,n;return(t=e==null||(n=e.numberFormat)==null?void 0:n.pattern)==null?``:t}))}};t.FRange.extend(n);var r=class extends t.FWorkbook{setNumfmtLocal(t){return this._injector.get(e.SheetsNumfmtCellContentController).setNumfmtLocal(t),this}};t.FWorkbook.extend(r)});
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(r,e){typeof exports=="object"&&typeof module<"u"?e(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"],e):(r=typeof globalThis<"u"?globalThis:r||self,e(r.UniverSheetsNumfmt={},r.UniverCore,r.UniverSheets,r.rxjs,r.UniverEngineFormula))})(this,(function(r,e,u,I,J){"use strict";var ge=Object.defineProperty;var Se=(r,e,u)=>e in r?ge(r,e,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[e]=u;var V=(r,e,u)=>Se(r,typeof e!="symbol"?e+"":e,u);const L=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=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 A(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:E.get(t)||"€",locale:t};case e.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(t)||"₽",locale:t};case e.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(t)||"¥",locale:t};case e.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:e.LocaleType.EN_US}}}function F(t){return E.get(t)||"$"}function B(t,a=2){let i=a;a>127&&(i=127);let n="";return i>0&&(n=`.${"0".repeat(i)}`),`"${F(t)}"#,##0${n}_);[Red]("${F(t)}"#,##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"}],K=[{label:t=>`${t}1,235`,suffix:t=>`"${t}"#,##0.00_);"${t}"#,##0.00`},{label:t=>`${t}1,235`,suffix:t=>`"${t}"#,##0.00_);[Red]"${t}"#,##0.00`,color:"red"},{label:t=>`(${t}1,235)`,suffix:t=>`"${t}"#,##0.00_);("${t}"#,##0.00)`},{label:t=>`(${t}1,235)`,suffix:t=>`"${t}"#,##0.00_);[Red]("${t}"#,##0.00)`,color:"red"},{label:t=>`-${t}1,235`,suffix:t=>`"${t}"#,##0.00_);-"${t}"#,##0.00`},{label:t=>`-${t}1,235`,suffix:t=>`"${t}"#,##0.00_);[Red]-"${t}"#,##0.00`,color:"red"}],U=(t,a=0)=>{var n;return t&&(n=e.numfmt.getFormatInfo(t).maxDecimals)!=null?n:a},D=t=>new Array(Math.min(Math.max(0,Number(t)),30)).fill(0).join(""),$=(t,a)=>t.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${a>0?".":""}${D(Number(a||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${a>0?".":""}${D(Number(a||0))}$1`):n).join(";"),Q=t=>/\.0?/.test(t)||/0([^0]?)|0$/.test(t),R={id:"sheet.command.numfmt.set.numfmt",type:e.CommandType.COMMAND,handler:(t,a)=>{if(!a)return!1;const i=t.get(e.ICommandService),n=t.get(e.IUniverInstanceService),s=t.get(e.IUndoRedoService),l=u.getSheetCommandTarget(n,a);if(!l)return!1;const{unitId:m,subUnitId:S,worksheet:o}=l,f=a.values.filter(c=>!!c.pattern),T=a.values.filter(c=>!c.pattern),M=u.transformCellsToRange(m,S,f),C={unitId:m,subUnitId:S,ranges:T.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},b=[],p=[];if(f.length){const c=f.reduce((g,d)=>{e.isTextFormat(d.pattern)&&g.setValue(d.row,d.col,{t:e.CellValueType.STRING});const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new e.ObjectMatrix).getMatrix(),v=new e.ObjectMatrix;new e.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),Object.keys(M.values).forEach(g=>{const d=M.values[g];d.ranges=u.rangeMerge(d.ranges)}),b.push({id:u.SetNumfmtMutation.id,params:M});const h=u.factorySetNumfmtUndoMutation(t,M);p.push(...h)}if(T.length){C.ranges=u.rangeMerge(C.ranges);const c=T.reduce((g,d)=>{const _=o.getCellRaw(d.row,d.col);if(_){const O=u.checkCellValueType(_.v);O!==_.t&&g.setValue(d.row,d.col,{t:O})}return g},new e.ObjectMatrix).getMatrix(),v=new e.ObjectMatrix;new e.ObjectMatrix(c).forValue((g,d)=>{const _=o.getCellRaw(g,d);_?v.setValue(g,d,{t:_.t}):v.setValue(g,d,{t:void 0})}),b.push({id:u.RemoveNumfmtMutation.id,params:C},{id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:c}});const h=u.factoryRemoveNumfmtUndoMutation(t,C);p.push({id:u.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:S,cellValue:v.getMatrix()}},...h)}const y=e.sequenceExecute(b,i).result;return y&&s.pushUndoRedo({unitID:m,undoMutations:p,redoMutations:b}),y}},x={id:"sheet.command.numfmt.add.decimal.command",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),i=t.get(u.SheetsSelectionsService),n=t.get(u.INumfmtService),s=t.get(e.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(b=>{e.Range.foreach(b.range,(p,y)=>{const c=n.getValue(S,o,p,y);if(!c){const h=m.worksheet.getCellRaw(p,y);if(!f&&h&&h.t===e.CellValueType.NUMBER&&h.v){const g=/\.(\d*)$/.exec(String(h.v));if(g){const d=g[1].length;if(!d)return;f=Math.max(f,d)}}return}const v=U(c.pattern);f=v>f?v:f})});const T=f+1,M=$(`0${T>0?".0":""}`,T),C=[];return l.forEach(b=>{e.Range.foreach(b.range,(p,y)=>{const c=n.getValue(S,o,p,y);if(e.isDefaultFormat(c==null?void 0:c.pattern))C.push({row:p,col:y,pattern:M});else{const v=U(c.pattern),h=$(c.pattern,v+1);h!==c.pattern&&C.push({row:p,col:y,pattern:h})}})}),C.length?await a.executeCommand(R.id,{values:C}):!1}},W={id:"sheet.command.numfmt.set.currency",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),i=t.get(u.SheetsSelectionsService),n=t.get(e.LocaleService),s=i.getCurrentSelections();if(!s||!s.length)return!1;const l=[],m=A(n.getCurrentLocale()),S=B(m.locale);return s.forEach(f=>{e.Range.foreach(f.range,(T,M)=>{l.push({row:T,col:M,pattern:S,type:"currency"})})}),await a.executeCommand(R.id,{values:l})}},k={id:"sheet.command.numfmt.set.percent",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),n=t.get(u.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],l="0%";return n.forEach(S=>{e.Range.foreach(S.range,(o,f)=>{s.push({row:o,col:f,pattern:l,type:"percent"})})}),await a.executeCommand(R.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:e.CommandType.COMMAND,handler:async t=>{const a=t.get(e.ICommandService),i=t.get(u.SheetsSelectionsService),n=t.get(u.INumfmtService),s=t.get(e.IUniverInstanceService),l=i.getCurrentSelections();if(!l||!l.length)return!1;const m=u.getSheetCommandTarget(s);if(!m)return!1;const{unitId:S,subUnitId:o}=m;let f=0;l.forEach(p=>{e.Range.foreach(p.range,(y,c)=>{const v=n.getValue(S,o,y,c);if(!v){const g=m.worksheet.getCellRaw(y,c);if(!f&&g&&g.t===e.CellValueType.NUMBER&&g.v){const d=/\.(\d*)$/.exec(String(g.v));if(d){const _=d[1].length;if(!_)return;f=Math.max(f,_)}}return}const h=U(v.pattern);f=h>f?h:f})});const T=f-1,M=$(`0${T>0?".0":"."}`,T),C=[];return l.forEach(p=>{e.Range.foreach(p.range,(y,c)=>{const v=n.getValue(S,o,y,c);if(e.isDefaultFormat(v==null?void 0:v.pattern))C.push({row:y,col:c,pattern:M});else{const h=U(v.pattern);C.push({row:y,col:c,pattern:$(v.pattern,h-1)})}})}),await a.executeCommand(R.id,{values:C})}},w="sheets-numfmt.config",Z={},ee=t=>e.numfmt.getFormatInfo(t).type||"unknown",Y=(t,a,i="en")=>{try{const n=e.numfmt.formatColor(t,a),s=n?String(n):void 0,l=e.numfmt.format(t,a,{locale:i,throws:!1});return a<0?{result:l,color:s}:{result:l}}catch(n){console.warn("getPatternPreview error:",t,n)}return{result:String(a)}},z=(t,a,i)=>t===e.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(a))}:Y(t,a,i);var te=Object.getOwnPropertyDescriptor,ne=(t,a,i,n)=>{for(var s=n>1?void 0:n?te(a,i):a,l=t.length-1,m;l>=0;l--)(m=t[l])&&(s=m(s)||s);return s},N=(t,a)=>(i,n)=>a(i,n,t);const ae={tl:{size:6,color:"#409f11"}};r.SheetsNumfmtCellContentController=class extends e.Disposable{constructor(i,n,s,l,m,S,o){super();V(this,"_locale$",new I.BehaviorSubject("en"));V(this,"locale$",this._locale$.asObservable());this._instanceService=i,this._sheetInterceptorService=n,this._themeService=s,this._commandService=l,this._numfmtService=m,this._localeService=S,this._configService=o,this._initInterceptorCellContent()}get locale(){const i=this._locale$.getValue();if(i)return i;switch(this._localeService.getCurrentLocale()){case 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(){const i=new e.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:e.InterceptorEffectEnum.Value|e.InterceptorEffectEnum.Style,handler:(n,s,l)=>{var p,y;if(!n||n.v===void 0||n.v===null||n.t===e.CellValueType.BOOLEAN||n.t===e.CellValueType.FORCE_STRING)return l(n);const m=s.unitId,S=s.subUnitId;let o;if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(o=c.n)}if(o||(o=this._numfmtService.getValue(m,S,s.row,s.col)),e.isDefaultFormat(o==null?void 0:o.pattern)||n.t!==e.CellValueType.NUMBER&&u.checkCellValueType(n.v,n.t)!==e.CellValueType.NUMBER)return l(n);const f=n;if((!n||n===s.rawData)&&(n={...s.rawData}),e.isTextFormat(o==null?void 0:o.pattern))return(p=this._configService.getConfig(w))!=null&&p.disableTextFormatMark?(n.t=e.CellValueType.STRING,l(n)):(n.t=e.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...ae},l(n));let T="";const M=i.getValue(s.row,s.col);if(M&&M.parameters===`${f.v}_${o==null?void 0:o.pattern}`)return l({...n,...M.result});const C=z(o==null?void 0:o.pattern,Number(f.v),this.locale);if(T=C.result,!T)return l(n);const b={v:T,t:e.CellValueType.NUMBER};if(C.color){const c=(y=this._themeService.getColorFromTheme(`${C.color}.500`))!=null?y:C.color;c&&(b.interceptorStyle={cl:{rgb:c}})}return i.setValue(s.row,s.col,{result:b,parameters:`${f.v}_${o==null?void 0:o.pattern}`}),Object.assign(n,b),l(n)},priority:u.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===u.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(l=>{s.values[l].ranges.forEach(S=>{e.Range.foreach(S,(o,f)=>{i.realDeleteValue(o,f)})})})}else if(n.id===u.SetRangeValuesMutation.id){const s=n.params;new e.ObjectMatrix(s.cellValue).forValue((l,m)=>{i.realDeleteValue(l,m)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(e.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)}},r.SheetsNumfmtCellContentController=ne([N(0,e.IUniverInstanceService),N(1,e.Inject(u.SheetInterceptorService)),N(2,e.Inject(e.ThemeService)),N(3,e.Inject(e.ICommandService)),N(4,e.Inject(u.INumfmtService)),N(5,e.Inject(e.LocaleService)),N(6,e.IConfigService)],r.SheetsNumfmtCellContentController);const X={name:"@univerjs/sheets-numfmt",version:"0.17.0"},re="SHEET_NUMFMT_PLUGIN";var ie=Object.defineProperty,se=Object.getOwnPropertyDescriptor,le=(t,a,i)=>a in t?ie(t,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[a]=i,ce=(t,a,i,n)=>{for(var s=n>1?void 0:n?se(a,i):a,l=t.length-1,m;l>=0;l--)(m=t[l])&&(s=m(s)||s);return s},j=(t,a)=>(i,n)=>a(i,n,t),P=(t,a,i)=>le(t,typeof a!="symbol"?a+"":a,i);r.UniverSheetsNumfmtPlugin=class extends e.Plugin{constructor(a=Z,i,n,s){super(),this._config=a,this._injector=i,this._configService=n,this._commandService=s;const{...l}=e.merge({},Z,this._config);this._configService.setConfig(w,l)}onStarting(){e.registerDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),e.touchDependencies(this._injector,[[r.SheetsNumfmtCellContentController]]),[x,q,W,k,R].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}},P(r.UniverSheetsNumfmtPlugin,"pluginName",re),P(r.UniverSheetsNumfmtPlugin,"packageName",X.name),P(r.UniverSheetsNumfmtPlugin,"version",X.version),P(r.UniverSheetsNumfmtPlugin,"type",e.UniverInstanceType.UNIVER_SHEET),r.UniverSheetsNumfmtPlugin=ce([e.DependentOn(u.UniverSheetsPlugin),j(1,e.Inject(e.Injector)),j(2,e.IConfigService),j(3,e.ICommandService)],r.UniverSheetsNumfmtPlugin);const oe=t=>L.find(i=>t.includes(i)),ue=()=>L.map(t=>({label:t,value:t})),me=t=>K.map(a=>({label:a.label(t),value:a.suffix(t),color:a.color})),fe=()=>G.map(t=>({label:t.label,value:t.suffix})),de=()=>H.map(t=>({label:t.label,value:t.suffix,color:t.color}));r.AddDecimalCommand=x,r.CURRENCYFORMAT=K,r.DATEFMTLISG=G,r.NUMBERFORMAT=H,r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=w,r.SetCurrencyCommand=W,r.SetNumfmtCommand=R,r.SetPercentCommand=k,r.SubtractDecimalCommand=q,r.currencySymbols=L,r.getCurrencyFormat=B,r.getCurrencyFormatOptions=me,r.getCurrencyOptions=ue,r.getCurrencySymbolByLocale=F,r.getCurrencySymbolIconByLocale=A,r.getCurrencyType=oe,r.getDateFormatOptions=fe,r.getDecimalFromPattern=U,r.getDecimalString=D,r.getNumberFormatOptions=de,r.getPatternPreview=Y,r.getPatternPreviewIgnoreGeneral=z,r.getPatternType=ee,r.isPatternHasDecimal=Q,r.localeCurrencySymbolMap=E,r.setPatternDecimal=$,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(e,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):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNumfmt={},e.UniverCore,e.UniverSheets,e.rxjs,e.UniverEngineFormula))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let a=`$.£.¥.¤.֏.؋.৳.฿.៛.₡.₦.₩.₪.₫.€.₭.₮.₱.₲.₴.₸.₹.₺.₼.₽.₾.₿.﷼`.split(`.`),o=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,`€`],[t.LocaleType.SK_SK,`€`]]);function s(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:case t.LocaleType.SK_SK:return{icon:`EuroIcon`,symbol:o.get(e)||`€`,locale:e};case t.LocaleType.RU_RU:return{icon:`RoubleIcon`,symbol:o.get(e)||`₽`,locale:e};case t.LocaleType.ZH_CN:return{icon:`RmbIcon`,symbol:o.get(e)||`¥`,locale:e};case t.LocaleType.EN_US:default:return{icon:`DollarIcon`,symbol:`$`,locale:t.LocaleType.EN_US}}}function c(e){return o.get(e)||`$`}function l(e,t=2){let n=t;t>127&&(n=127);let r=``;return n>0&&(r=`.${`0`.repeat(n)}`),`"${c(e)}"#,##0${r}_);[Red]("${c(e)}"#,##0${r})`}let u=[{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`}],d=[{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`}],f=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:`red`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:`red`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:`red`}],p=(e,n=0)=>{var r;return e?(r=t.numfmt.getFormatInfo(e).maxDecimals)==null?n:r:n},m=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),h=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${m(Number(t||0))}`):/0([^0]?)|0$/.test(e)?e.replace(/0([^0]+)|0$/,`0${t>0?`.`:``}${m(Number(t||0))}$1`):e).join(`;`),g=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;let i=e.get(t.ICommandService),a=e.get(t.IUniverInstanceService),o=e.get(t.IUndoRedoService),s=(0,n.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,n.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((e,r)=>{(0,t.isTextFormat)(r.pattern)&&e.setValue(r.row,r.col,{t:t.CellValueType.STRING});let i=u.getCellRaw(r.row,r.col);if(i){let t=(0,n.checkCellValueType)(i.v);t!==i.t&&e.setValue(r.row,r.col,{t})}return e},new t.ObjectMatrix).getMatrix(),i=new t.ObjectMatrix;new t.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 t=p.values[e];t.ranges=(0,n.rangeMerge)(t.ranges)}),h.push({id:n.SetNumfmtMutation.id,params:p});let a=(0,n.factorySetNumfmtUndoMutation)(e,p);g.push(...a)}if(f.length){m.ranges=(0,n.rangeMerge)(m.ranges);let r=f.reduce((e,t)=>{let r=u.getCellRaw(t.row,t.col);if(r){let i=(0,n.checkCellValueType)(r.v);i!==r.t&&e.setValue(t.row,t.col,{t:i})}return e},new t.ObjectMatrix).getMatrix(),i=new t.ObjectMatrix;new t.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:n.RemoveNumfmtMutation.id,params:m},{id:n.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:r}});let a=(0,n.factoryRemoveNumfmtUndoMutation)(e,m);g.push({id:n.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:i.getMatrix()}},...a)}let _=(0,t.sequenceExecute)(h,i).result;return _&&o.pushUndoRedo({unitID:c,undoMutations:g,redoMutations:h}),_}},v={id:`sheet.command.numfmt.add.decimal.command`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(n.INumfmtService),o=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,n.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if(!r){let r=c.worksheet.getCellRaw(e,n);if(!d&&r&&r.t===t.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=p(r.pattern);d=i>d?i:d})});let f=d+1,m=h(`0${f>0?`.0`:``}`,f),g=[];return s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if((0,t.isDefaultFormat)(r==null?void 0:r.pattern))g.push({row:e,col:n,pattern:m});else{let t=p(r.pattern),i=h(r.pattern,t+1);i!==r.pattern&&g.push({row:e,col:n,pattern:i})}})}),g.length?await r.executeCommand(_.id,{values:g}):!1}},y={id:`sheet.command.numfmt.set.currency`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(t.LocaleService),o=i.getCurrentSelections();if(!o||!o.length)return!1;let c=[],u=l(s(a.getCurrentLocale()).locale);return o.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{c.push({row:e,col:t,pattern:u,type:`currency`})})}),await r.executeCommand(_.id,{values:c})}},b={id:`sheet.command.numfmt.set.percent`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService).getCurrentSelections();if(!i||!i.length)return!1;let a=[];return i.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{a.push({row:e,col:t,pattern:`0%`,type:`percent`})})}),await r.executeCommand(_.id,{values:a})}},x={id:`sheet.command.numfmt.subtract.decimal.command`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(n.INumfmtService),o=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,n.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if(!r){let r=c.worksheet.getCellRaw(e,n);if(!d&&r&&r.t===t.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=p(r.pattern);d=i>d?i:d})});let f=d-1,m=h(`0${f>0?`.0`:`.`}`,f),g=[];return s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if((0,t.isDefaultFormat)(r==null?void 0:r.pattern))g.push({row:e,col:n,pattern:m});else{let t=p(r.pattern);g.push({row:e,col:n,pattern:h(r.pattern,t-1)})}})}),await r.executeCommand(_.id,{values:g})}},S=`sheets-numfmt.config`;Symbol(S);let C={},w=e=>t.numfmt.getFormatInfo(e).type||`unknown`,T=(e,n,r=`en`)=>{try{let i=t.numfmt.formatColor(e,n),a=i?String(i):void 0,o=t.numfmt.format(e,n,{locale:r,throws:!1});return n<0?{result:o,color:a}:{result:o}}catch(t){console.warn(`getPatternPreview error:`,e,t)}return{result:String(n)}},E=(e,n,r)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String((0,i.stripErrorMargin)(n))}:T(e,n,r);function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function j(e,t){return function(n,r){t(n,r,e)}}function M(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}let N={tl:{size:6,color:`#409f11`}},P=class extends t.Disposable{constructor(e,t,n,i,a,o,s){super(),this._instanceService=e,this._sheetInterceptorService=t,this._themeService=n,this._commandService=i,this._numfmtService=a,this._localeService=o,this._configService=s,A(this,`_locale$`,new r.BehaviorSubject(`en`)),A(this,`locale$`,this._locale$.asObservable()),this._initInterceptorCellContent()}get locale(){let e=this._locale$.getValue();if(e)return e;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.SK_SK:return`sk`;case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return`en`}}_initInterceptorCellContent(){let e=new t.ObjectMatrix;this.disposeWithMe((0,r.merge)(this._locale$,this._localeService.currentLocale$).subscribe(()=>{e.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(n.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(r,i,a)=>{if(!r||r.v===void 0||r.v===null||r.t===t.CellValueType.BOOLEAN||r.t===t.CellValueType.FORCE_STRING)return a(r);let o=i.unitId,s=i.subUnitId,c;if(r!=null&&r.s){let e=i.workbook.getStyles().get(r.s);e!=null&&e.n&&(c=e.n)}if(c||(c=this._numfmtService.getValue(o,s,i.row,i.col)),(0,t.isDefaultFormat)(c==null?void 0:c.pattern)||r.t!==t.CellValueType.NUMBER&&(0,n.checkCellValueType)(r.v,r.t)!==t.CellValueType.NUMBER)return a(r);let l=r;if((!r||r===i.rawData)&&(r={...i.rawData}),(0,t.isTextFormat)(c==null?void 0:c.pattern)){var u;return(u=this._configService.getConfig(`sheets-numfmt.config`))!=null&&u.disableTextFormatMark?(r.t=t.CellValueType.STRING,a(r)):(r.t=t.CellValueType.STRING,r.markers={...r==null?void 0:r.markers,...N},a(r))}let d=``,f=e.getValue(i.row,i.col);if(f&&f.parameters===`${l.v}_${c==null?void 0:c.pattern}`)return a({...r,...f.result});let p=E(c==null?void 0:c.pattern,Number(l.v),this.locale);if(d=p.result,!d)return a(r);let m={v:d,t:t.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 e.setValue(i.row,i.col,{result:m,parameters:`${l.v}_${c==null?void 0:c.pattern}`}),Object.assign(r,m),a(r)},priority:n.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===n.SetNumfmtMutation.id){let n=r.params;Object.keys(n.values).forEach(r=>{n.values[r].ranges.forEach(n=>{t.Range.foreach(n,(t,n)=>{e.realDeleteValue(t,n)})})})}else if(r.id===n.SetRangeValuesMutation.id){let n=r.params;new t.ObjectMatrix(n.cellValue).forValue((t,n)=>{e.realDeleteValue(t,n)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,r.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,r.of)(null):t}),(0,r.skip)(1)).subscribe(()=>e.reset()))}setNumfmtLocal(e){this._locale$.next(e)}};P=M([j(0,t.IUniverInstanceService),j(1,(0,t.Inject)(n.SheetInterceptorService)),j(2,(0,t.Inject)(t.ThemeService)),j(3,(0,t.Inject)(t.ICommandService)),j(4,(0,t.Inject)(n.INumfmtService)),j(5,(0,t.Inject)(t.LocaleService)),j(6,t.IConfigService)],P);var F=`@univerjs/sheets-numfmt`,I=`0.18.0`;let L=class extends t.Plugin{constructor(e=C,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},C,this._config);this._configService.setConfig(S,a)}onStarting(){(0,t.registerDependencies)(this._injector,[[P]]),(0,t.touchDependencies)(this._injector,[[P]]),[v,x,y,b,_].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};A(L,`pluginName`,`SHEET_NUMFMT_PLUGIN`),A(L,`packageName`,F),A(L,`version`,I),A(L,`type`,t.UniverInstanceType.UNIVER_SHEET),L=M([(0,t.DependentOn)(n.UniverSheetsPlugin),j(1,(0,t.Inject)(t.Injector)),j(2,t.IConfigService),j(3,t.ICommandService)],L),e.AddDecimalCommand=v,e.CURRENCYFORMAT=f,e.DATEFMTLISG=u,e.NUMBERFORMAT=d,e.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=S,e.SetCurrencyCommand=y,e.SetNumfmtCommand=_,e.SetPercentCommand=b,Object.defineProperty(e,`SheetsNumfmtCellContentController`,{enumerable:!0,get:function(){return P}}),e.SubtractDecimalCommand=x,Object.defineProperty(e,`UniverSheetsNumfmtPlugin`,{enumerable:!0,get:function(){return L}}),e.currencySymbols=a,e.getCurrencyFormat=l,e.getCurrencyFormatOptions=e=>f.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),e.getCurrencyOptions=()=>a.map(e=>({label:e,value:e})),e.getCurrencySymbolByLocale=c,e.getCurrencySymbolIconByLocale=s,e.getCurrencyType=e=>a.find(t=>e.includes(t)),e.getDateFormatOptions=()=>u.map(e=>({label:e.label,value:e.suffix})),e.getDecimalFromPattern=p,e.getDecimalString=m,e.getNumberFormatOptions=()=>d.map(e=>({label:e.label,value:e.suffix,color:e.color})),e.getPatternPreview=T,e.getPatternPreviewIgnoreGeneral=E,e.getPatternType=w,e.isPatternHasDecimal=g,e.localeCurrencySymbolMap=o,e.setPatternDecimal=h});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -58,23 +58,24 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/core": "0.
|
|
62
|
-
"@univerjs/engine-formula": "0.
|
|
63
|
-
"@univerjs/sheets": "0.
|
|
61
|
+
"@univerjs/core": "0.18.0",
|
|
62
|
+
"@univerjs/engine-formula": "0.18.0",
|
|
63
|
+
"@univerjs/sheets": "0.18.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"rxjs": "^7.8.2",
|
|
67
67
|
"typescript": "^5.9.3",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"@univerjs-infra/shared": "0.17.0"
|
|
68
|
+
"vitest": "^4.1.0",
|
|
69
|
+
"@univerjs-infra/shared": "0.18.0"
|
|
71
70
|
},
|
|
72
71
|
"scripts": {
|
|
73
72
|
"test": "vitest run",
|
|
74
73
|
"test:watch": "vitest",
|
|
75
74
|
"coverage": "vitest run --coverage",
|
|
76
75
|
"typecheck": "tsc --noEmit",
|
|
77
|
-
"build": "univer-cli build"
|
|
76
|
+
"build:bundle": "univer-cli build",
|
|
77
|
+
"build:types": "tsc -p tsconfig.node.json",
|
|
78
|
+
"build": "pnpm run build:bundle && pnpm run build:types"
|
|
78
79
|
},
|
|
79
80
|
"module": "./lib/es/index.js"
|
|
80
81
|
}
|