@univerjs/sheets-numfmt 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +932 -826
- package/lib/index.css +1 -1
- package/lib/locale/en-US.json +3 -1
- package/lib/locale/ru-RU.json +3 -1
- package/lib/locale/vi-VN.json +3 -1
- package/lib/locale/zh-CN.json +3 -1
- package/lib/locale/zh-TW.json +6 -4
- package/lib/types/components/custom-format/index.d.ts +4 -0
- package/lib/types/controllers/__tests__/test.util.d.ts +7 -8
- package/lib/types/controllers/numfmt.editor.controller.d.ts +1 -2
- package/lib/types/controllers/numfmt.menu.controller.d.ts +1 -2
- package/lib/types/controllers/type.d.ts +1 -1
- package/lib/types/locale/zh-CN.d.ts +2 -0
- package/lib/types/menu/menu.d.ts +1 -1
- package/lib/types/numfmt-plugin.d.ts +1 -2
- package/lib/umd/index.js +2 -2
- package/package.json +21 -23
package/lib/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.numfmt-panel{overflow-y:auto;display:flex;flex-direction:column;justify-content:space-between;height:100%}.numfmt-panel .group-title{font-size:16px;color:rgba(var(--color-black))}.numfmt-panel .label{font-size:15px;color:rgba(var(--grey-400))}.numfmt-panel .describe{font-size:13px;line-height:20px;color:rgba(var(--grey-600))}.numfmt-panel .preview{height:36px;padding:0 16px;font-size:14px;line-height:36px;color:var(--color-black);border:1px solid rgb(var(--grey-200));border-radius:4px}.numfmt-panel .btn-list{display:flex;justify-content:flex-end}.numfmt-panel .m-r-12{margin-right:12px}.numfmt-panel .m-t-16{margin-top:16px}.numfmt-panel .m-t-14{margin-top:14px}.numfmt-panel .m-t-8{margin-top:8px}.numfmt-panel .m-b-20{margin-bottom:20px}.options{display:flex;justify-content:space-between}.options .w-140{width:140px}.options .w-120{width:120px}.more-numfmt-type{display:flex;flex-shrink:0;padding:0 4px;font-size:13px;color:var(--black)}.more-numfmt-type .icon{display:flex;align-items:center;height:auto;padding-left:8px;color:rgb(var(--grey-400))}.more-numfmt-type-options .line{width:100%;height:1px;background-color:rgb(var(--grey-200))}.more-numfmt-type-options .m-t-4{margin-top:4px}.more-numfmt-type-options .option-item{display:flex;align-items:center;justify-content:space-between;height:28px;padding:0 8px;font-size:13px}.more-numfmt-type-options .option-item:hover{background-color:rgb(var(--grey-100));border-radius:var(--border-radius-base)}.more-numfmt-type-options .m-l-26{margin-left:26px}
|
|
1
|
+
.numfmt-panel{overflow-y:auto;display:flex;flex-direction:column;justify-content:space-between;height:100%}.numfmt-panel .group-title{font-size:16px;color:rgba(var(--color-black))}.numfmt-panel .label{font-size:15px;color:rgba(var(--grey-400))}.numfmt-panel .describe{font-size:13px;line-height:20px;color:rgba(var(--grey-600))}.numfmt-panel .preview{height:36px;padding:0 16px;font-size:14px;line-height:36px;color:var(--color-black);border:1px solid rgb(var(--grey-200));border-radius:4px}.numfmt-panel .btn-list{display:flex;justify-content:flex-end}.numfmt-panel .m-r-12{margin-right:12px}.numfmt-panel .m-t-16{margin-top:16px}.numfmt-panel .m-t-14{margin-top:14px}.numfmt-panel .m-t-8{margin-top:8px}.numfmt-panel .m-b-20{margin-bottom:20px}.options{display:flex;justify-content:space-between}.options .w-140{width:140px}.options .w-120{width:120px}.univer-custom-format-title{margin-top:16px}.univer-custom-format-input{margin-top:8px;width:100%}.univer-custom-format-history-list{margin-top:8px;padding:8px;border-radius:8px;border:1px solid var(---Grey-200, #e5e5e5);max-height:400px;overflow:scroll}.univer-custom-format-history-list-item{padding:6px 0;display:flex;gap:6px;align-items:center;cursor:pointer}.univer-custom-format-history-list-item-icon-wrap{width:16px;display:flex;align-items:center;color:#274fee}.univer-custom-format-des{margin-top:8px;color:var(---Grey-600, #7a7a7a);font-size:12px;font-style:normal;font-weight:400;line-height:16px}.more-numfmt-type{display:flex;flex-shrink:0;padding:0 4px;font-size:13px;color:var(--black)}.more-numfmt-type .icon{display:flex;align-items:center;height:auto;padding-left:8px;color:rgb(var(--grey-400))}.more-numfmt-type-options .line{width:100%;height:1px;background-color:rgb(var(--grey-200))}.more-numfmt-type-options .m-t-4{margin-top:4px}.more-numfmt-type-options .option-item{display:flex;align-items:center;justify-content:space-between;height:28px;padding:0 8px;font-size:13px}.more-numfmt-type-options .option-item:hover{background-color:rgb(var(--grey-100));border-radius:var(--border-radius-base)}.more-numfmt-type-options .m-l-26{margin-left:26px}
|
package/lib/locale/en-US.json
CHANGED
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"generalDes": "The regular format does not contain any specific number format.",
|
|
31
31
|
"thousandthPercentileDes": "The percentile format is used for the representation of ordinary numbers. Monetary and accounting formats provide a specialized format for monetary value calculations.",
|
|
32
32
|
"addDecimal": "Increase decimal places",
|
|
33
|
-
"subtractDecimal": "Decreasing decimal places"
|
|
33
|
+
"subtractDecimal": "Decreasing decimal places",
|
|
34
|
+
"customFormat": "Custom Format",
|
|
35
|
+
"customFormatDes": "Generate custom number formats based on existing formats."
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
}
|
package/lib/locale/ru-RU.json
CHANGED
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"generalDes": "Обычный формат не содержит никакого специфического формата числа.",
|
|
31
31
|
"thousandthPercentileDes": "Формат процента используется для представления обычных чисел. Монетарные и бухгалтерские форматы предоставляют специальный формат для вычислений монетарных значений.",
|
|
32
32
|
"addDecimal": "Увеличить количество десятичных знаков",
|
|
33
|
-
"subtractDecimal": "Уменьшить количество десятичных знаков"
|
|
33
|
+
"subtractDecimal": "Уменьшить количество десятичных знаков",
|
|
34
|
+
"customFormat": "Custom Format",
|
|
35
|
+
"customFormatDes": "Generate custom number formats based on existing formats."
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
}
|
package/lib/locale/vi-VN.json
CHANGED
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"generalDes": "Định dạng chung không chứa bất kỳ định dạng số cụ thể nào.",
|
|
31
31
|
"thousandthPercentileDes": "Định dạng phân vị phần nghìn được sử dụng để biểu thị các số thông thường. Các định dạng tiền tệ và kế toán cung cấp các định dạng chuyên dụng để tính toán giá trị tiền tệ.",
|
|
32
32
|
"addDecimal": "Thêm chữ số thập phân",
|
|
33
|
-
"subtractDecimal": "Giảm chữ số thập phân"
|
|
33
|
+
"subtractDecimal": "Giảm chữ số thập phân",
|
|
34
|
+
"customFormat": "Custom Format",
|
|
35
|
+
"customFormatDes": "Generate custom number formats based on existing formats."
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
}
|
package/lib/locale/zh-CN.json
CHANGED
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"generalDes": "常规格式不包含任何特定的数字格式。",
|
|
31
31
|
"thousandthPercentileDes": "千分位符格式用于一般数字的表示。货币和会计格式则提供货币值计算的专用格式。",
|
|
32
32
|
"addDecimal": "增加小数位",
|
|
33
|
-
"subtractDecimal": "减少小数位"
|
|
33
|
+
"subtractDecimal": "减少小数位",
|
|
34
|
+
"customFormat": "自定义格式",
|
|
35
|
+
"customFormatDes": "根据现有格式生成自定义数字格式。"
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
}
|
package/lib/locale/zh-TW.json
CHANGED
|
@@ -25,12 +25,14 @@
|
|
|
25
25
|
"currencyDes": "貨幣格式用來表示一般貨幣數值。會計格式可以對一列數值進行小數點對齊",
|
|
26
26
|
"accountingDes": "會計數字格式可對一列數值進行貨幣符號和小數點對齊",
|
|
27
27
|
"dateType": "日期類型",
|
|
28
|
-
"dateDes": "日期格式將日期和時間系列數值品顯示為日期值。
|
|
28
|
+
"dateDes": "日期格式將日期和時間系列數值品顯示為日期值。",
|
|
29
29
|
"negType": "負數型別",
|
|
30
|
-
"generalDes": "常規格式不包含任何特定的數字格式。
|
|
31
|
-
"thousandthPercentileDes": "千分位符號格式用於一般數字的表示。貨幣和會計格式則提供貨幣值計算的專用格式。
|
|
30
|
+
"generalDes": "常規格式不包含任何特定的數字格式。",
|
|
31
|
+
"thousandthPercentileDes": "千分位符號格式用於一般數字的表示。貨幣和會計格式則提供貨幣值計算的專用格式。",
|
|
32
32
|
"addDecimal": "增加小數位",
|
|
33
|
-
"subtractDecimal": "減少小數位"
|
|
33
|
+
"subtractDecimal": "減少小數位",
|
|
34
|
+
"customFormat": "Custom Format",
|
|
35
|
+
"customFormatDes": "Generate custom number formats based on existing formats."
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { Univer } from '@univerjs/core';
|
|
2
|
-
import { Dependency } from '@wendellhu/redi';
|
|
1
|
+
import { Dependency, Univer } from '@univerjs/core';
|
|
3
2
|
|
|
4
3
|
export declare const createTestBed: (dependencies?: Dependency[]) => {
|
|
5
4
|
univer: Univer;
|
|
6
5
|
get: {
|
|
7
|
-
<T>(id: import('@
|
|
8
|
-
<T>(id: import('@
|
|
9
|
-
<T>(id: import('@
|
|
10
|
-
<T>(id: import('@
|
|
11
|
-
<T>(id: import('@
|
|
12
|
-
<T>(id: import('@
|
|
6
|
+
<T>(id: import('@univerjs/core').DependencyIdentifier<T>, lookUp?: import('@univerjs/core').LookUp): T;
|
|
7
|
+
<T>(id: import('@univerjs/core').DependencyIdentifier<T>, quantity: import("@univerjs/core").Quantity.MANY, lookUp?: import('@univerjs/core').LookUp): T[];
|
|
8
|
+
<T>(id: import('@univerjs/core').DependencyIdentifier<T>, quantity: import("@univerjs/core").Quantity.OPTIONAL, lookUp?: import('@univerjs/core').LookUp): T | null;
|
|
9
|
+
<T>(id: import('@univerjs/core').DependencyIdentifier<T>, quantity: import("@univerjs/core").Quantity.REQUIRED, lookUp?: import('@univerjs/core').LookUp): T;
|
|
10
|
+
<T>(id: import('@univerjs/core').DependencyIdentifier<T>, quantity?: import('@univerjs/core').Quantity, lookUp?: import('@univerjs/core').LookUp): T[] | T | null;
|
|
11
|
+
<T>(id: import('@univerjs/core').DependencyIdentifier<T>, quantityOrLookup?: import('@univerjs/core').Quantity | import('@univerjs/core').LookUp, lookUp?: import('@univerjs/core').LookUp): T[] | T | null;
|
|
13
12
|
};
|
|
14
13
|
sheet: import('@univerjs/core').Workbook;
|
|
15
14
|
unitId: string;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Disposable, IUniverInstanceService } from '@univerjs/core';
|
|
1
|
+
import { Disposable, Injector, IUniverInstanceService } from '@univerjs/core';
|
|
2
2
|
import { INumfmtService, SheetInterceptorService } from '@univerjs/sheets';
|
|
3
3
|
import { IEditorBridgeService } from '@univerjs/sheets-ui';
|
|
4
|
-
import { Injector } from '@wendellhu/redi';
|
|
5
4
|
|
|
6
5
|
export declare class NumfmtEditorController extends Disposable {
|
|
7
6
|
private _sheetInterceptorService;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Disposable } from '@univerjs/core';
|
|
1
|
+
import { Disposable, Injector } from '@univerjs/core';
|
|
2
2
|
import { MenuConfig, ComponentManager, IMenuService } from '@univerjs/ui';
|
|
3
|
-
import { Injector } from '@wendellhu/redi';
|
|
4
3
|
|
|
5
4
|
export interface IUniverSheetsNumfmtConfig {
|
|
6
5
|
menu: MenuConfig;
|
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
export interface INumfmtController {
|
|
17
17
|
openPanel(): void;
|
|
18
18
|
}
|
|
19
|
-
export declare const INumfmtController: import('@
|
|
19
|
+
export declare const INumfmtController: import('@univerjs/core').IdentifierDecorator<INumfmtController>;
|
package/lib/types/menu/menu.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IMenuSelectorItem, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';
|
|
2
|
-
import { IAccessor } from '@
|
|
2
|
+
import { IAccessor } from '@univerjs/core';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
4
|
|
|
5
5
|
export declare const CurrencyMenuItem: (accessor: IAccessor) => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Plugin, UniverInstanceType } from '@univerjs/core';
|
|
2
|
-
import { Injector } from '@wendellhu/redi';
|
|
1
|
+
import { Injector, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
3
2
|
import { IUniverSheetsNumfmtConfig } from './controllers/numfmt.menu.controller';
|
|
4
3
|
|
|
5
4
|
export declare class UniverSheetsNumfmtPlugin extends Plugin {
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/engine-numfmt"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs/operators"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/sheets","@univerjs/sheets-ui","rxjs","@univerjs/engine-numfmt","@univerjs/engine-render","@univerjs/ui","rxjs/operators","react","@univerjs/design","@wendellhu/redi/react-bindings"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverSheetsNumfmt={},g.UniverCore,g["@wendellhu/redi"],g.UniverSheets,g.UniverSheetsUi,g.rxjs,g.UniverEngineNumfmt,g.UniverEngineRender,g.UniverUi,g.rxjs.operators,g.React,g.UniverDesign,g["@wendellhu/redi/react-bindings"]))})(this,function(g,a,I,m,D,O,j,he,T,B,b,R,N){"use strict";var xt=Object.defineProperty;var Dt=(g,a,I)=>a in g?xt(g,a,{enumerable:!0,configurable:!0,writable:!0,value:I}):g[a]=I;var se=(g,a,I)=>Dt(g,typeof a!="symbol"?a+"":a,I);const re="SHEET_NUMFMT_PLUGIN",G=e=>j.numfmt.getInfo(e).type||"unknown",z=(e,t,s)=>{const n=j.numfmt.getInfo(e),r=s===a.LocaleType.ZH_CN?"zh-CN":"en",i=n._partitions[1],o=j.numfmt.format(e,t,{locale:r});return t<0?{result:o,color:i.color}:{result:o}};var Ne=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,Oe=(e,t,s,n)=>{for(var r=n>1?void 0:n?Re(t,s):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(n?o(t,s,r):o(r))||r);return n&&r&&Ne(t,s,r),r},L=(e,t)=>(s,n)=>t(s,n,e);let K=class extends a.Disposable{constructor(e,t,s,n,r,i){super(),this._instanceService=e,this._sheetInterceptorService=t,this._themeService=s,this._commandService=n,this._numfmtService=r,this._localeService=i,this._initInterceptorCellContent()}_initInterceptorCellContent(){const e=new a.ObjectMatrix;this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{handler:(t,s,n)=>{const r=s.unitId,i=s.subUnitId,o=this._numfmtService.getValue(r,i,s.row,s.col);if(!o)return n(t);const c=t;if(!c||c.t!==a.CellValueType.NUMBER)return n(t);let l="";const v=e.getValue(s.row,s.col);if(v&&v.parameters===c.v)return n({...t,...v.result});const f=z(o.pattern,Number(c.v),this._localeService.getCurrentLocale());if(l=f.result,!l)return n(t);const u={v:l};if(f.color){const d=this._themeService.getCurrentTheme()[`${f.color}500`];d&&(u.interceptorStyle={cl:{rgb:d}})}return e.setValue(s.row,s.col,{result:u,parameters:c.v}),n({...t,...u})},priority:10})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetNumfmtMutation.id){const s=t.params;Object.keys(s.values).forEach(n=>{s.values[n].ranges.forEach(i=>{a.Range.foreach(i,(o,c)=>{e.realDeleteValue(o,c)})})})}else if(t.id===m.SetRangeValuesMutation.id){const s=t.params;new a.ObjectMatrix(s.cellValue).forValue((n,r)=>{e.realDeleteValue(n,r)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.switchMap(t=>{var s;return(s=t==null?void 0:t.activeSheet$)!=null?s:O.of(null)}),O.skip(1)).subscribe(()=>e.reset()))}};K=Oe([a.OnLifecycle(a.LifecycleStages.Rendered,K),L(0,a.IUniverInstanceService),L(1,I.Inject(m.SheetInterceptorService)),L(2,I.Inject(a.ThemeService)),L(3,I.Inject(a.ICommandService)),L(4,I.Inject(m.INumfmtService)),L(5,I.Inject(a.LocaleService))],K);const U=(e,t=0)=>{var n;return e&&(n=j.numfmt.getInfo(e).maxDecimals)!=null?n:t},Y=(e,t)=>{if(e&&!t||!e&&t)return!1;const s=v=>v.reduce((f,u)=>{if(f.isEnd)return f;const d=u.value||u.num;return u.type==="point"?(f.isEnd=!0,f):{...f,result:f.result+d}},{isEnd:!1,result:""}).result,n=j.numfmt.getInfo(e)._partitions,r=j.numfmt.getInfo(t)._partitions,i=s(n[0].tokens),o=s(r[0].tokens),c=s(n[1].tokens),l=s(r[1].tokens);return i===o&&c===l&&n[1].color===r[1].color},Se=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),E=(e,t)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${t>0?".":""}${Se(Number(t||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${t>0?".":""}${Se(Number(t||0))}$1`):n).join(";"),je=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),w={id:"sheet.command.numfmt.set.numfmt",type:a.CommandType.COMMAND,handler:(e,t)=>{if(!t)return!1;const s=e.get(a.ICommandService),n=e.get(a.IUniverInstanceService),r=e.get(a.IUndoRedoService),i=m.getSheetCommandTarget(n,t);if(!i)return!1;const{unitId:o,subUnitId:c}=i,l=t.values.filter(h=>!!h.pattern),v=t.values.filter(h=>!h.pattern),f=m.transformCellsToRange(o,c,l),u={unitId:o,subUnitId:c,ranges:v.map(h=>({startColumn:h.col,startRow:h.row,endColumn:h.col,endRow:h.row}))},d=[],_=[];if(l.length){Object.keys(f.values).forEach(C=>{const S=f.values[C];S.ranges=m.rangeMerge(S.ranges)}),d.push({id:m.SetNumfmtMutation.id,params:f});const h=m.factorySetNumfmtUndoMutation(e,f);_.push(...h)}if(v.length){u.ranges=m.rangeMerge(u.ranges),d.push({id:m.RemoveNumfmtMutation.id,params:u});const h=m.factoryRemoveNumfmtUndoMutation(e,u);_.push(...h)}const y=a.sequenceExecute(d,s).result;return y&&r.pushUndoRedo({unitID:o,undoMutations:_,redoMutations:d}),y}},ie={id:"sheet.command.numfmt.add.decimal.command",type:a.CommandType.COMMAND,handler:async e=>{const t=e.get(a.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),r=e.get(a.IUniverInstanceService),i=s.getCurrentSelections();if(!i||!i.length)return!1;const o=m.getSheetCommandTarget(r);if(!o)return!1;const{unitId:c,subUnitId:l}=o;let v=0;i.forEach(_=>{a.Range.foreach(_.range,(y,h)=>{const C=n.getValue(c,l,y,h);if(!C)return;const S=U(C.pattern);v=S>v?S:v})});const f=v+1,u=E(`0${f>0?".0":""}`,f),d=[];return i.forEach(_=>{a.Range.foreach(_.range,(y,h)=>{const C=n.getValue(c,l,y,h);if(!C)d.push({row:y,col:h,pattern:u});else{const S=U(C.pattern),P=E(C.pattern,S+1);P!==C.pattern&&d.push({row:y,col:h,pattern:P})}})}),d.length?await t.executeCommand(w.id,{values:d}):!1}},xe=[{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"}],De=[{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"}],ge=[{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"}],ae={id:"sheet.command.numfmt.set.currency",type:a.CommandType.COMMAND,handler:async e=>{const t=e.get(a.ICommandService),n=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const r=[],i=ge[0].suffix("¥");return n.forEach(c=>{a.Range.foreach(c.range,(l,v)=>{r.push({row:l,col:v,pattern:i,type:"currency"})})}),await t.executeCommand(w.id,{values:r})}},oe={id:"sheet.command.numfmt.subtract.decimal.command",type:a.CommandType.COMMAND,handler:async e=>{const t=e.get(a.ICommandService),s=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),r=e.get(a.IUniverInstanceService),i=s.getCurrentSelections();if(!i||!i.length)return!1;const o=m.getSheetCommandTarget(r);if(!o)return!1;const{unitId:c,subUnitId:l}=o;let v=0;i.forEach(y=>{a.Range.foreach(y.range,(h,C)=>{const S=n.getValue(c,l,h,C);if(!S)return;const P=U(S.pattern);v=P>v?P:v})});const f=v-1,u=E(`0${f>0?".0":"."}`,f),d=[];return i.forEach(y=>{a.Range.foreach(y.range,(h,C)=>{const S=n.getValue(c,l,h,C);if(!S)d.push({row:h,col:C,pattern:u});else{const P=U(S.pattern);d.push({row:h,col:C,pattern:E(S.pattern,P-1)})}})}),await t.executeCommand(w.id,{values:d})}},J={id:"sheet.operation.close.numfmt.panel",type:a.CommandType.OPERATION,handler:()=>!0},ce=I.createIdentifier("INumfmtController");a.runOnLifecycle(a.LifecycleStages.Rendered,ce);const V={id:"sheet.operation.open.numfmt.panel",type:a.CommandType.OPERATION,handler:e=>(e.get(ce).openPanel(),!0)};var _e={exports:{}},X={};/**
|
|
1
|
+
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/engine-numfmt"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs/operators"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/sheets-ui","rxjs","@univerjs/engine-numfmt","@univerjs/engine-render","@univerjs/ui","rxjs/operators","react","@univerjs/design"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsNumfmt={},global.UniverCore,global.UniverSheets,global.UniverSheetsUi,global.rxjs,global.UniverEngineNumfmt,global.UniverEngineRender,global.UniverUi,global.rxjs.operators,global.React,global.UniverDesign))})(this,function(exports2,core,sheets,sheetsUi,rxjs,engineNumfmt,engineRender,ui,operators,require$$0,design){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e,_f,_g;const SHEET_NUMFMT_PLUGIN="SHEET_NUMFMT_PLUGIN",getPatternType=__name(pattern=>engineNumfmt.numfmt.getInfo(pattern).type||"unknown","getPatternType"),getPatternPreview=__name((pattern,value,_locale)=>{const info=engineNumfmt.numfmt.getInfo(pattern),locale=_locale===core.LocaleType.ZH_CN?"zh-CN":"en",negInfo=info._partitions[1],result=engineNumfmt.numfmt.format(pattern,value,{locale});return value<0?{result,color:negInfo.color}:{result}},"getPatternPreview");var __defProp$6=Object.defineProperty,__getOwnPropDesc$6=Object.getOwnPropertyDescriptor,__decorateClass$6=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$6(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$6(target,key2,result),result},"__decorateClass$6"),__decorateParam$6=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$6");let SheetsNumfmtCellContentController=(_a=class extends core.Disposable{constructor(_instanceService,_sheetInterceptorService,_themeService,_commandService,_numfmtService,_localeService){super(),this._instanceService=_instanceService,this._sheetInterceptorService=_sheetInterceptorService,this._themeService=_themeService,this._commandService=_commandService,this._numfmtService=_numfmtService,this._localeService=_localeService,this._initInterceptorCellContent()}_initInterceptorCellContent(){const renderCache=new core.ObjectMatrix;this.disposeWithMe(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{handler:__name((cell,location,next)=>{const unitId=location.unitId,sheetId=location.subUnitId,numfmtValue=this._numfmtService.getValue(unitId,sheetId,location.row,location.col);if(!numfmtValue)return next(cell);const originCellValue=cell;if(!originCellValue||originCellValue.t!==core.CellValueType.NUMBER)return next(cell);let numfmtRes="";const cache=renderCache.getValue(location.row,location.col);if(cache&&cache.parameters===originCellValue.v)return next({...cell,...cache.result});const info=getPatternPreview(numfmtValue.pattern,Number(originCellValue.v),this._localeService.getCurrentLocale());if(numfmtRes=info.result,!numfmtRes)return next(cell);const res={v:numfmtRes};if(info.color){const color=this._themeService.getCurrentTheme()[`${info.color}500`];color&&(res.interceptorStyle={cl:{rgb:color}})}return renderCache.setValue(location.row,location.col,{result:res,parameters:originCellValue.v}),next({...cell,...res})},"handler"),priority:10})),this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===sheets.SetNumfmtMutation.id){const params=commandInfo.params;Object.keys(params.values).forEach(key2=>{params.values[key2].ranges.forEach(range=>{core.Range.foreach(range,(row,col)=>{renderCache.realDeleteValue(row,col)})})})}else if(commandInfo.id===sheets.SetRangeValuesMutation.id){const params=commandInfo.params;new core.ObjectMatrix(params.cellValue).forValue((row,col)=>{renderCache.realDeleteValue(row,col)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.switchMap(workbook=>{var _a2;return(_a2=workbook==null?void 0:workbook.activeSheet$)!=null?_a2:rxjs.of(null)}),rxjs.skip(1)).subscribe(()=>renderCache.reset()))}},__name(_a,"SheetsNumfmtCellContentController"),_a);SheetsNumfmtCellContentController=__decorateClass$6([core.OnLifecycle(core.LifecycleStages.Rendered,SheetsNumfmtCellContentController),__decorateParam$6(0,core.IUniverInstanceService),__decorateParam$6(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$6(2,core.Inject(core.ThemeService)),__decorateParam$6(3,core.Inject(core.ICommandService)),__decorateParam$6(4,core.Inject(sheets.INumfmtService)),__decorateParam$6(5,core.Inject(core.LocaleService))],SheetsNumfmtCellContentController);const getDecimalFromPattern=__name((pattern,defaultValue=0)=>{var _a2;return pattern&&(_a2=engineNumfmt.numfmt.getInfo(pattern).maxDecimals)!=null?_a2:defaultValue},"getDecimalFromPattern"),isPatternEqualWithoutDecimal=__name((patternA,patternB)=>{if(patternA&&!patternB||!patternA&&patternB)return!1;const getString=__name(tokens=>tokens.reduce((pre,cur)=>{if(pre.isEnd)return pre;const str=cur.value||cur.num;return cur.type==="point"?(pre.isEnd=!0,pre):{...pre,result:pre.result+str}},{isEnd:!1,result:""}).result,"getString"),partitionsA=engineNumfmt.numfmt.getInfo(patternA)._partitions,partitionsB=engineNumfmt.numfmt.getInfo(patternB)._partitions,A1=getString(partitionsA[0].tokens),B1=getString(partitionsB[0].tokens),A2=getString(partitionsA[1].tokens),B2=getString(partitionsB[1].tokens);return A1===B1&&A2===B2&&partitionsA[1].color===partitionsB[1].color},"isPatternEqualWithoutDecimal"),getDecimalString=__name(length=>new Array(Math.min(Math.max(0,Number(length)),30)).fill(0).join(""),"getDecimalString"),setPatternDecimal=__name((patterns,decimalLength)=>patterns.split(";").map(pattern=>/\.0?/.test(pattern)?pattern.replace(/\.0*/g,`${decimalLength>0?".":""}${getDecimalString(Number(decimalLength||0))}`):/0([^0]?)|0$/.test(pattern)?pattern.replace(/0([^0]+)|0$/,`0${decimalLength>0?".":""}${getDecimalString(Number(decimalLength||0))}$1`):pattern).join(";"),"setPatternDecimal"),isPatternHasDecimal=__name(pattern=>/\.0?/.test(pattern)||/0([^0]?)|0$/.test(pattern),"isPatternHasDecimal"),SetNumfmtCommand={id:"sheet.command.numfmt.set.numfmt",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{if(!params)return!1;const commandService=accessor.get(core.ICommandService),univerInstanceService=accessor.get(core.IUniverInstanceService),undoRedoService=accessor.get(core.IUndoRedoService),target=sheets.getSheetCommandTarget(univerInstanceService,params);if(!target)return!1;const{unitId,subUnitId}=target,setCells=params.values.filter(value=>!!value.pattern),removeCells=params.values.filter(value=>!value.pattern),setRedos=sheets.transformCellsToRange(unitId,subUnitId,setCells),removeRedos={unitId,subUnitId,ranges:removeCells.map(cell=>({startColumn:cell.col,startRow:cell.row,endColumn:cell.col,endRow:cell.row}))},redos=[],undos=[];if(setCells.length){Object.keys(setRedos.values).forEach(key2=>{const v=setRedos.values[key2];v.ranges=sheets.rangeMerge(v.ranges)}),redos.push({id:sheets.SetNumfmtMutation.id,params:setRedos});const undo=sheets.factorySetNumfmtUndoMutation(accessor,setRedos);undos.push(...undo)}if(removeCells.length){removeRedos.ranges=sheets.rangeMerge(removeRedos.ranges),redos.push({id:sheets.RemoveNumfmtMutation.id,params:removeRedos});const undo=sheets.factoryRemoveNumfmtUndoMutation(accessor,removeRedos);undos.push(...undo)}const result=core.sequenceExecute(redos,commandService).result;return result&&undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:undos,redoMutations:redos}),result},"handler")},AddDecimalCommand={id:"sheet.command.numfmt.add.decimal.command",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),numfmtService=accessor.get(sheets.INumfmtService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const target=sheets.getSheetCommandTarget(univerInstanceService);if(!target)return!1;const{unitId,subUnitId}=target;let maxDecimals=0;selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)return;const decimals2=getDecimalFromPattern(numfmtValue.pattern);maxDecimals=decimals2>maxDecimals?decimals2:maxDecimals})});const decimals=maxDecimals+1,defaultPattern=setPatternDecimal(`0${decimals>0?".0":""}`,decimals),values=[];return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)values.push({row,col,pattern:defaultPattern});else{const decimals2=getDecimalFromPattern(numfmtValue.pattern),pattern=setPatternDecimal(numfmtValue.pattern,decimals2+1);pattern!==numfmtValue.pattern&&values.push({row,col,pattern})}})}),values.length?await commandService.executeCommand(SetNumfmtCommand.id,{values}):!1},"handler")},DATEFMTLISG=[{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"}],NUMBERFORMAT=[{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"}],CURRENCYFORMAT=[{label:__name(suffix=>`${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);"${suffix}"#,##0.00`,"suffix")},{label:__name(suffix=>`${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]"${suffix}"#,##0.00`,"suffix"),color:"red"},{label:__name(suffix=>`(${suffix}1,235)`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);("${suffix}"#,##0.00)`,"suffix")},{label:__name(suffix=>`(${suffix}1,235)`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]("${suffix}"#,##0.00)`,"suffix"),color:"red"},{label:__name(suffix=>`-${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);-"${suffix}"#,##0.00`,"suffix")},{label:__name(suffix=>`-${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`,"suffix"),color:"red"}],SetCurrencyCommand={id:"sheet.command.numfmt.set.currency",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selections=accessor.get(sheets.SheetsSelectionsService).getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix=CURRENCYFORMAT[0].suffix("¥");return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{values.push({row,col,pattern:suffix,type:"currency"})})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")},SubtractDecimalCommand={id:"sheet.command.numfmt.subtract.decimal.command",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),numfmtService=accessor.get(sheets.INumfmtService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const target=sheets.getSheetCommandTarget(univerInstanceService);if(!target)return!1;const{unitId,subUnitId}=target;let maxDecimals=0;selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)return;const decimals2=getDecimalFromPattern(numfmtValue.pattern);maxDecimals=decimals2>maxDecimals?decimals2:maxDecimals})});const decimals=maxDecimals-1,defaultPattern=setPatternDecimal(`0${decimals>0?".0":"."}`,decimals),values=[];return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)values.push({row,col,pattern:defaultPattern});else{const decimals2=getDecimalFromPattern(numfmtValue.pattern);values.push({row,col,pattern:setPatternDecimal(numfmtValue.pattern,decimals2-1)})}})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")},CloseNumfmtPanelOperator={id:"sheet.operation.close.numfmt.panel",type:core.CommandType.OPERATION,handler:__name(()=>!0,"handler")},INumfmtController=core.createIdentifier("INumfmtController");core.runOnLifecycle(core.LifecycleStages.Rendered,INumfmtController);const OpenNumfmtPanelOperator={id:"sheet.operation.open.numfmt.panel",type:core.CommandType.OPERATION,handler:__name(accessor=>(accessor.get(INumfmtController).openPanel(),!0),"handler")};var jsxRuntime={exports:{}},reactJsxRuntime_production_min={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Ue=b,we=Symbol.for("react.element"),Le=Symbol.for("react.fragment"),Ae=Object.prototype.hasOwnProperty,Ve=Ue.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,He={key:!0,ref:!0,__self:!0,__source:!0};function ye(e,t,s){var n,r={},i=null,o=null;s!==void 0&&(i=""+s),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(o=t.ref);for(n in t)Ae.call(t,n)&&!He.hasOwnProperty(n)&&(r[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps,t)r[n]===void 0&&(r[n]=t[n]);return{$$typeof:we,type:e,key:i,ref:o,props:r,_owner:Ve.current}}X.Fragment=Le,X.jsx=ye,X.jsxs=ye,_e.exports=X;var p=_e.exports;const le=b.createContext([]),ue=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"];var $e=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,Fe=(e,t,s,n)=>{for(var r=n>1?void 0:n?ke(t,s):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(n?o(t,s,r):o(r))||r);return n&&r&&$e(t,s,r),r},We=(e,t)=>(s,n)=>t(s,n,e);let Z=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const s=this._getKey(e);return this._localStorageService.getItem(s).then(n=>{n||this._localStorageService.setItem(s,t)})}markHabit(e,t){const s=this._getKey(e);this._localStorageService.getItem(s).then(n=>{if(n){const r=n.findIndex(i=>i===t);r>-1&&n.splice(r,1),n.unshift(t),this._localStorageService.setItem(s,n)}})}async getHabit(e,t){const s=this._getKey(e),n=await this._localStorageService.getItem(s);if(t&&n){const r=n.map((i,o,c)=>{const l=c.length;return{value:i,priority:l-o}});return t.sort((i,o)=>{var v,f;const c=((v=r.find(u=>u.value===i))==null?void 0:v.priority)||-1;return(((f=r.find(u=>u.value===o))==null?void 0:f.priority)||-1)-c})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};Z=Fe([We(0,I.Inject(a.ILocalStorageService))],Z);const be="numfmtCurrency",Be=e=>{const t=N.useDependency(Z),[s,n]=b.useState(ue);return b.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(be,[...ue]).then(i=>{n(i),e&&e(i)})})},[]),{userHabitCurrency:s,mark:i=>{t.markHabit(be,i)}}},Ge=()=>{const e=b.useRef([]),[t,s]=b.useState({});return b.useEffect(()=>{e.current.forEach(r=>{r()}),e.current=[]},[t]),r=>{e.current.push(r),s({})}},H=e=>ue.find(s=>e.includes(s)),ze=e=>!!H(e)&&e.startsWith("_("),Ke=e=>{const[t,s]=b.useState(()=>U(e.defaultPattern||"",2)),n=b.useContext(le),[r,i]=b.useState(()=>H(e.defaultPattern)||n[0]),o=b.useMemo(()=>n.map(u=>({label:u,value:u})),[]),l=N.useDependency(a.LocaleService).t;e.action.current=()=>E(`_("${r}"* #,##0${t>0?".0":""}_)`,t);const v=u=>{i(u),e.onChange(E(`_("${u}"* #,##0${t>0?".0":""}_)`,t))},f=u=>{const d=u||0;s(d),e.onChange(E(`_("${r}"* #,##0${d>0?".0":""}_)`,d))};return p.jsxs("div",{children:[p.jsxs("div",{className:"m-t-16 options ",children:[p.jsxs("div",{className:"option",children:[p.jsx("div",{className:"label",children:l("sheet.numfmt.decimalLength")}),p.jsx("div",{className:"m-t-8 w-120",children:p.jsx(R.InputNumber,{value:t,max:20,min:0,onChange:f})})]}),p.jsxs("div",{className:"option",children:[p.jsx("div",{className:"label",children:l("sheet.numfmt.currencyType")}),p.jsx("div",{className:"m-t-8 w-140",children:p.jsx(R.Select,{onChange:v,options:o,value:r})})]})]}),p.jsx("div",{className:"describe m-t-14",children:l("sheet.numfmt.accountingDes")})]})},me=e=>ge.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),Ce=()=>xe.map(e=>({label:e.label,value:e.suffix})),Ie=()=>De.map(e=>({label:e.label,value:e.suffix,color:e.color})),Ye=e=>!!H(e)&&!e.startsWith("_("),Je=e=>{const s=N.useDependency(a.LocaleService).t,n=b.useContext(le),[r,i]=b.useState(()=>H(e.defaultPattern)||n[0]),[o,c]=b.useState(()=>U(e.defaultPattern||"",2)),[l,v]=b.useState(()=>{var S;const h=me(r);return((S=h.find(P=>Y(P.value,e.defaultPattern)))==null?void 0:S.value)||h[0].value}),f=b.useMemo(()=>me(r),[r]),u=b.useMemo(()=>n.map(h=>({label:h,value:h})),[n]);e.action.current=()=>E(l,o);const d=h=>{if(h===void 0)return;i(h);const C=me(h)[0].value;v(C),e.onChange(E(C,o))},_=h=>{h!==void 0&&(v(h),e.onChange(E(h,o)))},y=h=>{c(h||0),e.onChange(E(l,h||0))};return p.jsxs("div",{children:[p.jsxs("div",{className:"m-t-16 options ",children:[p.jsxs("div",{className:"option",children:[p.jsx("div",{className:"label",children:s("sheet.numfmt.decimalLength")}),p.jsx("div",{className:"m-t-8 w-120",children:p.jsx(R.InputNumber,{value:o,max:20,min:0,onChange:y})})]}),p.jsxs("div",{className:"option",children:[p.jsx("div",{className:"label",children:s("sheet.numfmt.currencyType")}),p.jsx("div",{className:"m-t-8 w-140",children:p.jsx(R.Select,{onChange:d,options:u,value:r})})]})]}),p.jsx("div",{className:"m-t-16 label",children:s("sheet.numfmt.negType")}),p.jsx("div",{className:"m-t-8",children:p.jsx(R.SelectList,{onChange:_,options:f,value:l})}),p.jsx("div",{className:"describe m-t-14",children:s("sheet.numfmt.currencyDes")})]})},Xe=e=>{const t=j.numfmt.getInfo(e);return Ce().map(s=>s.value).includes(e)||["date","datetime","time"].includes(t.type)},Ze=e=>{const t=b.useMemo(Ce,[]),n=N.useDependency(a.LocaleService).t,[r,i]=b.useState(()=>{if(e.defaultPattern){const c=t.find(l=>l.value===e.defaultPattern);if(c)return c.value}return t[0].value});e.action.current=()=>r;const o=c=>{c!==void 0&&(i(c),e.onChange(c))};return p.jsxs("div",{children:[p.jsx("div",{className:"m-t-16 label",children:n("sheet.numfmt.dateType")}),p.jsx("div",{className:"m-t-8",children:p.jsx(R.SelectList,{value:r,options:t,onChange:o})}),p.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Qe=e=>!e,qe=e=>{const s=N.useDependency(a.LocaleService).t;return e.action.current=()=>"",p.jsx("div",{children:p.jsx("div",{className:"describe m-t-14",children:s("sheet.numfmt.generalDes")})})},et=e=>Ie().some(t=>Y(t.value,e)),tt=e=>{const t=N.useDependency(a.LocaleService),s=b.useMemo(Ie,[]),[n,r]=b.useState(()=>U(e.defaultPattern||"",0)),[i,o]=b.useState(()=>{const u=s.find(d=>Y(d.value,e.defaultPattern||""));return(u==null?void 0:u.value)||s[0].value}),c=b.useMemo(()=>E(i,Number(n||0)),[i,n]),l=b.useMemo(()=>!je(i),[i]),v=u=>{r(u||0),e.onChange(E(i,Number(u||0)))},f=u=>{u!==void 0&&(r(U(u,0)),o(u),e.onChange(u))};return e.action.current=()=>c,p.jsxs("div",{children:[p.jsx("div",{className:"m-t-16 label",children:t.t("sheet.numfmt.decimalLength")}),p.jsx("div",{className:"m-t-8",children:p.jsx(R.InputNumber,{disabled:l,value:n,max:20,min:0,onChange:v})}),p.jsxs("div",{className:"m-t-16 label",children:[" ",t.t("sheet.numfmt.negType")]}),p.jsx("div",{className:"m-t-8",children:p.jsx(R.SelectList,{onChange:f,options:s,value:i})}),p.jsx("div",{className:"describe m-t-14",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})},nt=e=>{const{defaultValue:t,defaultPattern:s,row:n,col:r}=e.value,i=N.useDependency(a.LocaleService),o=b.useRef(()=>""),c=i.t,l=Ge(),v=b.useMemo(()=>[{label:"sheet.numfmt.general",component:qe},{label:"sheet.numfmt.accounting",component:Ke},{label:"sheet.numfmt.currency",component:Je},{label:"sheet.numfmt.date",component:Ze},{label:"sheet.numfmt.thousandthPercentile",component:tt}].map(M=>({...M,label:c(M.label)})),[]),[f,u]=b.useState(S),[d,_]=b.useState(()=>`${n}_${r}`),{mark:y,userHabitCurrency:h}=Be(()=>_(`${n}_${r}_userCurrency'`)),C=b.useMemo(()=>{var M;return(M=v.find(A=>A.label===f))==null?void 0:M.component},[f]);function S(){return[Qe,ze,Ye,Xe,et].reduce((A,Ot,jt)=>A||(Ot(s)?v[jt].label:""),"")||v[0].label}const P=v.map(M=>({label:M.label,value:M.label})),F=M=>{u(M),l(()=>e.onChange({type:"change",value:o.current()||""}))},ne=M=>{e.onChange({type:"change",value:M})},pe=()=>{const M=o.current()||"",A=H(M);A&&y(A),e.onChange({type:"confirm",value:M})},W=()=>{e.onChange({type:"cancel",value:""})},ve={onChange:ne,defaultValue:t,defaultPattern:s,action:o};return b.useEffect(()=>{u(S()),_(`${n}_${r}`)},[n,r]),p.jsxs("div",{className:"numfmt-panel p-b-20",children:[p.jsxs("div",{children:[p.jsx("div",{className:"label m-t-14",children:c("sheet.numfmt.numfmtType")}),p.jsx("div",{className:"m-t-8",children:p.jsx(R.Select,{onChange:F,options:P,value:f})}),p.jsx("div",{children:C&&p.jsx(le.Provider,{value:h,children:b.createElement(C,{...ve,key:d})})})]}),p.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[p.jsx(R.Button,{size:"small",onClick:W,className:"m-r-12",children:c("sheet.numfmt.cancel")}),p.jsx(R.Button,{type:"primary",size:"small",onClick:pe,children:c("sheet.numfmt.confirm")})]})]})},de={id:"sheet.command.numfmt.set.percent",type:a.CommandType.COMMAND,handler:async e=>{const t=e.get(a.ICommandService),n=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const r=[],i="0%";return n.forEach(c=>{a.Range.foreach(c.range,(l,v)=>{r.push({row:l,col:v,pattern:i,type:"percent"})})}),await t.executeCommand(w.id,{values:r})}};var st=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,it=(e,t,s,n)=>{for(var r=n>1?void 0:n?rt(t,s):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(n?o(t,s,r):o(r))||r);return n&&r&&st(t,s,r),r},x=(e,t)=>(s,n)=>t(s,n,e);let Q=class extends a.Disposable{constructor(t,s,n,r,i,o,c,l,v,f){super();se(this,"_previewPattern","");se(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=s,this._univerInstanceService=n,this._commandService=r,this._selectionManagerService=i,this._renderManagerService=o,this._numfmtService=c,this._componentManager=l,this._sidebarService=v,this._localeService=f,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var C;const t=this._sidebarService,s=this._selectionManagerService,n=this._commandService,r=this._univerInstanceService,i=this._numfmtService,o=this._localeService,l=(((C=s.getCurrentSelections())==null?void 0:C.map(S=>S.range))||[])[0];if(!l)return!1;const v=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),f=v.getActiveSheet();if(!f)return!1;const u=f.getCellRaw(l.startRow,l.startColumn),d=i.getValue(v.getUnitId(),f.getSheetId(),l.startRow,l.startColumn);let _="";d&&(_=d.pattern);const y=(u==null?void 0:u.t)===a.CellValueType.NUMBER?u.v:12345678,h={onChange:S=>{var P;if(S.type==="change")this._previewPattern=S.value,this._forceUpdate();else if(S.type==="confirm"){const F=((P=s.getCurrentSelections())==null?void 0:P.map(W=>W.range))||[],ne={values:[]},pe=G(S.value);F.forEach(W=>{a.Range.foreach(W,(ve,M)=>{ne.values.push({row:ve,col:M,pattern:S.value,type:pe})})}),n.executeCommand(w.id,ne),t.close()}else S.type==="cancel"&&t.close()},value:{defaultPattern:_,defaultValue:y,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=t.open({header:{title:o.t("sheet.numfmt.title")},children:{label:re,...h},onClose:()=>{this._forceUpdate(),n.executeCommand(J.id)}}),!0}_forceUpdate(t){var n;const s=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId());s==null||s.with(D.SheetSkeletonManagerService).reCalculate(),(n=s==null?void 0:s.mainComponent)==null||n.makeDirty()}_initCommands(){[ie,oe,ae,de,V,J,w].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this._componentManager.register(re,nt)}_initRealTimeRenderingInterceptor(){const t=new O.Observable(n=>{this._commandService.onCommandExecuted(r=>{r.id===V.id&&n.next(!0),r.id===J.id&&n.next(!1)})}),s=O.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(B.map(n=>n?n.map(r=>r.range):[]))]);this.disposeWithMe(a.toDisposable(s.pipe(B.switchMap(([n,r])=>new O.Observable(i=>{const o=new a.DisposableCollection;return n&&r.length&&i.next({selectionRanges:r,disposableCollection:o}),()=>{o.dispose()}})),B.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:r})=>{var o,c;const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,handler:(l,v,f)=>{const{row:u,col:d}=v,_=f(l)||{};if(r.find(y=>y.startColumn<=d&&y.endColumn>=d&&y.startRow<=u&&y.endRow>=u)){const y=v.worksheet.getCellRaw(u,d),h=y==null?void 0:y.v,C=y==null?void 0:y.t;if(h==null||C!==a.CellValueType.NUMBER||this._previewPattern===null)return _;const S=z(this._previewPattern,h,this._localeService.getCurrentLocale());if(S.color){const F=this._themeService.getCurrentTheme()[`${S.color}500`];return{..._,v:S.result,t:a.CellValueType.STRING,s:{cl:{rgb:F}}}}return{..._,v:S.result,t:a.CellValueType.STRING}}return _}})),(c=(o=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:o.mainComponent)==null||c.makeDirty()})))}_commandExecutedListener(){const t=[m.RemoveNumfmtMutation.id,m.SetNumfmtMutation.id];this.disposeWithMe(new O.Observable(s=>{const n=this._commandService.onCommandExecuted(r=>{if(t.includes(r.id)){const i=r.params;s.next(i.unitId)}});return()=>n.dispose()}).pipe(B.debounceTime(16)).subscribe(s=>this._forceUpdate(s)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var s;t||((s=this._sidebarDisposable)==null||s.dispose(),this._sidebarDisposable=null)})}};Q=it([a.OnLifecycle(a.LifecycleStages.Rendered,Q),x(0,I.Inject(m.SheetInterceptorService)),x(1,I.Inject(a.ThemeService)),x(2,a.IUniverInstanceService),x(3,a.ICommandService),x(4,I.Inject(m.SheetsSelectionsService)),x(5,he.IRenderManagerService),x(6,m.INumfmtService),x(7,I.Inject(T.ComponentManager)),x(8,T.ISidebarService),x(9,I.Inject(a.LocaleService))],Q);var at=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,ct=(e,t,s,n)=>{for(var r=n>1?void 0:n?ot(t,s):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(n?o(t,s,r):o(r))||r);return n&&r&&at(t,s,r),r},$=(e,t)=>(s,n)=>t(s,n,e);const lt=()=>{let e=[];return{add:(r,i,o,c,l)=>e.push({unitId:r,subUnitId:i,row:o,col:c,value:l}),getEffects:()=>e,clean:()=>{e=[]}}};let q=class extends a.Disposable{constructor(t,s,n,r,i){super();se(this,"_collectEffectMutation",lt());this._sheetInterceptorService=t,this._numfmtService=s,this._univerInstanceService=n,this._injector=r,this._editorBridgeService=i,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(a.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{handler:(t,s,n)=>{const r=s.row,i=s.col,o=this._numfmtService.getValue(s.unitId,s.subUnitId,r,i);if(o)switch(G(o.pattern)){case"scientific":case"percent":case"currency":case"grouped":case"number":return s.worksheet.getCellRaw(r,i);case"date":case"time":case"datetime":default:return n&&n(t)}return n(t)}})))}_initInterceptorEditorEnd(){this._editorBridgeService&&this.disposeWithMe(a.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{handler:(t,s,n)=>{var f;this._collectEffectMutation.clean();const r=this._numfmtService.getValue(s.unitId,s.subUnitId,s.row,s.col),i=(f=r&&G(r.pattern))!=null?f:"",o=()=>{r&&this._collectEffectMutation.add(s.unitId,s.subUnitId,s.row,s.col,null)};if(!(t!=null&&t.v))return n(t);const c=String(t.v),l=j.numfmt.parseDate(c)||j.numfmt.parseTime(c);if(!!l){if(l&&l.z){const u=Number(l.v);return this._collectEffectMutation.add(s.unitId,s.subUnitId,s.row,s.col,{pattern:l.z}),{...t,v:u,t:a.CellValueType.NUMBER}}}else(["date","time","datetime"].includes(i)||!ut(c))&&o();return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(s){var n;switch(s.id){case m.SetRangeValuesCommand.id:{const r=t._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),i=r.getUnitId(),o=(n=r.getActiveSheet())==null?void 0:n.getSheetId();if(!o)return{redos:[],undos:[]};const c=t._collectEffectMutation.getEffects();if(!c.length)return{redos:[],undos:[]};const l=c.filter(d=>{var _;return!!((_=d.value)!=null&&_.pattern)}).map(d=>({row:d.row,col:d.col,pattern:d.value.pattern})),v=c.filter(d=>{var _;return!((_=d.value)!=null&&_.pattern)}).map(d=>({startRow:d.row,endColumn:d.col,startColumn:d.col,endRow:d.row})),f=[],u=[];if(l){const d={id:m.SetNumfmtMutation.id,params:m.transformCellsToRange(i,o,l)};f.push(d),u.push(...m.factorySetNumfmtUndoMutation(t._injector,d.params))}if(v){const d={id:m.RemoveNumfmtMutation.id,params:{unitId:i,subUnitId:o,ranges:v}};f.push(d),u.push(...m.factoryRemoveNumfmtUndoMutation(t._injector,d.params))}return{redos:f,undos:u.reverse()}}}return{redos:[],undos:[]}}}))}};q=ct([a.OnLifecycle(a.LifecycleStages.Rendered,q),$(0,I.Inject(m.SheetInterceptorService)),$(1,I.Inject(m.INumfmtService)),$(2,I.Inject(a.IUniverInstanceService)),$(3,I.Inject(I.Injector)),$(4,I.Optional(D.IEditorBridgeService))],q);function ut(e){return/^-?\d+(\.\d+)?$/.test(e)}var mt=Object.defineProperty,dt=Object.getOwnPropertyDescriptor,ft=(e,t,s,n)=>{for(var r=n>1?void 0:n?dt(t,s):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(n?o(t,s,r):o(r))||r);return n&&r&&mt(t,s,r),r},pt=(e,t)=>(s,n)=>t(s,n,e);let ee=class extends a.Disposable{constructor(e){super(),this._localeService=e}};ee=ft([a.OnLifecycle(a.LifecycleStages.Rendered,ee),pt(0,I.Inject(a.LocaleService))],ee);const te=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:j.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Te="sheet.numfmt.moreNumfmtType",Pe="sheet.numfmt.moreNumfmtType.options",vt=e=>{var n;const t=N.useDependency(a.LocaleService),s=(n=e.value)!=null?n:t.t("sheet.numfmt.general");return p.jsx("span",{className:"more-numfmt-type",children:s})},ht=()=>{const e=N.useDependency(a.ICommandService),t=N.useDependency(a.LocaleService),s=N.useInjector(),n=N.useDependency(m.SheetsSelectionsService),r=c=>{const l=n.getCurrentLastSelection();if(!l)return;const v=s.get(he.ITextSelectionRenderManager),f=l.range,u=[];a.Range.foreach(f,(d,_)=>{c?u.push({row:d,col:_,pattern:c,type:G(c)}):u.push({row:d,col:_})}),e.executeCommand(w.id,{values:u}),v.focus()},i=c=>{if(c===0)r(null);else if(c===te.length-1)e.executeCommand(V.id);else{const l=te[c];l.pattern&&r(l.pattern)}},o=1220;return p.jsx("div",{className:"more-numfmt-type-options",children:te.map((c,l)=>c==="|"?p.jsx("div",{className:"line m-t-4",onClick:v=>v.stopPropagation()},l):p.jsxs("div",{className:"option-item m-t-4",onClick:()=>{i(l)},children:[p.jsx("div",{children:t.t(c.label)}),p.jsx("div",{className:"m-l-26",children:c.pattern?z(c.pattern||"",o,t.getCurrentLocale()).result:""})]},l))})},St=e=>({icon:"RmbSingle",id:ae.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:T.MenuItemType.BUTTON,group:T.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[T.MenuPosition.TOOLBAR_START],hidden$:T.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),gt=e=>({icon:"AddDigitsSingle",id:ie.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:T.MenuItemType.BUTTON,positions:[T.MenuPosition.TOOLBAR_START],group:T.MenuGroup.TOOLBAR_FORMULAS_INSERT,hidden$:T.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),_t=e=>({icon:"ReduceDigitsSingle",id:oe.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:T.MenuItemType.BUTTON,group:T.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[T.MenuPosition.TOOLBAR_START],hidden$:T.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),yt=e=>({icon:"PercentSingle",id:de.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:T.MenuItemType.BUTTON,group:T.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[T.MenuPosition.TOOLBAR_START],hidden$:T.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),bt=e=>{const t=e.get(m.INumfmtService),s=e.get(a.IUniverInstanceService),n=e.get(a.ICommandService),r=e.get(a.LocaleService),i=e.get(m.SheetsSelectionsService),o=D.deriveStateFromActiveSheet$(s,"",({workbook:c,worksheet:l})=>new O.Observable(v=>O.merge(i.selectionMoveEnd$,new O.Observable(f=>{const u=[m.RemoveNumfmtMutation.id,m.SetNumfmtMutation.id],d=n.onCommandExecuted(_=>{u.includes(_.id)&&f.next(null)});return()=>d.dispose()})).subscribe(()=>{const f=i.getCurrentSelections();if(f&&f[0]){const u=f[0].range,d=u.startRow,_=u.startColumn,y=t.getValue(c.getUnitId(),l.getSheetId(),d,_),h=y==null?void 0:y.pattern;let C=r.t("sheet.numfmt.general");if(h){const S=te.filter(P=>typeof P=="object"&&P.pattern).find(P=>Y(h,P.pattern));S&&typeof S=="object"&&S.pattern?C=r.t(S.label):C=r.t("sheet.numfmt.moreFmt")}v.next(C)}})));return{label:Te,id:V.id,tooltip:"sheet.numfmt.title",type:T.MenuItemType.SELECTOR,group:T.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[T.MenuPosition.TOOLBAR_START],selections:[{label:{name:Pe,hoverable:!1}}],value$:o,hidden$:T.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}};var Ct=Object.defineProperty,It=Object.getOwnPropertyDescriptor,Tt=(e,t,s,n)=>{for(var r=n>1?void 0:n?It(t,s):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(n?o(t,s,r):o(r))||r);return n&&r&&Ct(t,s,r),r},fe=(e,t)=>(s,n)=>t(s,n,e);const Pt={};let k=class extends a.Disposable{constructor(e,t,s,n){super(),this._config=e,this._injector=t,this._componentManager=s,this._menuService=n,this._initMenu()}_initMenu(){const{menu:e={}}=this._config;[yt,gt,_t,St,bt].forEach(t=>{this.disposeWithMe(this._menuService.addMenuItem(t(this._injector),e))}),this.disposeWithMe(this._componentManager.register(Te,vt)),this.disposeWithMe(this._componentManager.register(Pe,ht))}};k=Tt([a.OnLifecycle(a.LifecycleStages.Rendered,k),fe(1,I.Inject(I.Injector)),fe(2,I.Inject(T.ComponentManager)),fe(3,I.Inject(T.IMenuService))],k);var Me=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,Et=(e,t,s)=>t in e?Me(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,Nt=(e,t,s,n)=>{for(var r=n>1?void 0:n?Mt(t,s):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(n?o(t,s,r):o(r))||r);return n&&r&&Me(t,s,r),r},Rt=(e,t)=>(s,n)=>t(s,n,e),Ee=(e,t,s)=>Et(e,typeof t!="symbol"?t+"":t,s);g.UniverSheetsNumfmtPlugin=class extends a.Plugin{constructor(t={},s){super(),this._config=t,this._injector=s,this._config=a.Tools.deepMerge({},Pt,this._config)}onStarting(){this._injector.add([ce,{useClass:Q,lazy:!1}]),this._injector.add([q]),this._injector.add([Z]),this._injector.add([K]),this._injector.add([ee]),this._injector.add([k,{useFactory:()=>this._injector.createInstance(k,this._config)}])}},Ee(g.UniverSheetsNumfmtPlugin,"pluginName",re),Ee(g.UniverSheetsNumfmtPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsNumfmtPlugin=Nt([a.DependentOn(m.UniverSheetsPlugin,D.UniverSheetsUIPlugin),Rt(1,I.Inject(I.Injector))],g.UniverSheetsNumfmtPlugin),g.AddDecimalCommand=ie,g.CloseNumfmtPanelOperator=J,g.OpenNumfmtPanelOperator=V,g.SetCurrencyCommand=ae,g.SetNumfmtCommand=w,g.SetPercentCommand=de,g.SubtractDecimalCommand=oe,g.getPatternPreview=z,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function q(c,a,g){var b,d={},e=null,h=null;g!==void 0&&(e=""+g),a.key!==void 0&&(e=""+a.key),a.ref!==void 0&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)d[b]===void 0&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__name(q,"q"),reactJsxRuntime_production_min.Fragment=l,reactJsxRuntime_production_min.jsx=q,reactJsxRuntime_production_min.jsxs=q,jsxRuntime.exports=reactJsxRuntime_production_min;var jsxRuntimeExports=jsxRuntime.exports;const UserHabitCurrencyContext=require$$0.createContext([]),currencySymbols=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"];var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key2,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$5");let UserHabitController=(_b=class{constructor(_localStorageService){this._localStorageService=_localStorageService}_getKey(habit){return`userHabitController_${habit}`}async addHabit(habit,initValue){const key2=this._getKey(habit);return this._localStorageService.getItem(key2).then(item=>{item||this._localStorageService.setItem(key2,initValue)})}markHabit(habit,value){const key2=this._getKey(habit);this._localStorageService.getItem(key2).then(list=>{if(list){const index=list.findIndex(item=>item===value);index>-1&&list.splice(index,1),list.unshift(value),this._localStorageService.setItem(key2,list)}})}async getHabit(habit,sortList){const key2=this._getKey(habit),result=await this._localStorageService.getItem(key2);if(sortList&&result){const priority=result.map((item,index,arr)=>{const length=arr.length;return{value:item,priority:length-index}});return sortList.sort((a,b)=>{var _a2,_b2;const ap=((_a2=priority.find(item=>item.value===a))==null?void 0:_a2.priority)||-1;return(((_b2=priority.find(item=>item.value===b))==null?void 0:_b2.priority)||-1)-ap})}return result||[]}deleteHabit(habit){this._localStorageService.removeItem(habit)}},__name(_b,"UserHabitController"),_b);UserHabitController=__decorateClass$5([__decorateParam$5(0,core.Inject(core.ILocalStorageService))],UserHabitController);const key$1="numfmtCurrency",useCurrencyOptions=__name(onOptionChange=>{const userHabitController=core.useDependency(UserHabitController),[options,optionsSet]=require$$0.useState(currencySymbols);return require$$0.useEffect(()=>{userHabitController.addHabit("numfmtCurrency",[]).then(()=>{userHabitController.getHabit(key$1,[...currencySymbols]).then(list=>{optionsSet(list),onOptionChange&&onOptionChange(list)})})},[]),{userHabitCurrency:options,mark:__name(v=>{userHabitController.markHabit(key$1,v)},"mark")}},"useCurrencyOptions"),useNextTick=__name(()=>{const effectList=require$$0.useRef([]),[value,dispatch]=require$$0.useState({});return require$$0.useEffect(()=>{effectList.current.forEach(fn=>{fn()}),effectList.current=[]},[value]),__name(fn=>{effectList.current.push(fn),dispatch({})},"nextTick")},"useNextTick"),getCurrencyType=__name(pattern=>currencySymbols.find(code=>pattern.includes(code)),"getCurrencyType"),isAccountingPanel=__name(pattern=>!!getCurrencyType(pattern)&&pattern.startsWith("_("),"isAccountingPanel"),AccountingPanel=__name(props=>{const[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",2)),userHabitCurrency=require$$0.useContext(UserHabitCurrencyContext),[suffix,suffixSet]=require$$0.useState(()=>getCurrencyType(props.defaultPattern)||userHabitCurrency[0]),options=require$$0.useMemo(()=>userHabitCurrency.map(key2=>({label:key2,value:key2})),[]),t=core.useDependency(core.LocaleService).t;props.action.current=()=>setPatternDecimal(`_("${suffix}"* #,##0${decimal>0?".0":""}_)`,decimal);const onSelect=__name(v=>{suffixSet(v),props.onChange(setPatternDecimal(`_("${v}"* #,##0${decimal>0?".0":""}_)`,decimal))},"onSelect"),onDecimalChange=__name(v=>{const decimal2=v||0;decimalSet(decimal2),props.onChange(setPatternDecimal(`_("${suffix}"* #,##0${decimal2>0?".0":""}_)`,decimal2))},"onDecimalChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsxs("div",{className:"m-t-16 options ",children:[jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-120",children:jsxRuntimeExports.jsx(design.InputNumber,{value:decimal,max:20,min:0,onChange:onDecimalChange})})]}),jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.currencyType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-140",children:jsxRuntimeExports.jsx(design.Select,{onChange:onSelect,options,value:suffix})})]})]}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.accountingDes")})]})},"AccountingPanel"),getCurrencyFormatOptions=__name(suffix=>CURRENCYFORMAT.map(item=>({label:item.label(suffix),value:item.suffix(suffix),color:item.color})),"getCurrencyFormatOptions"),getDateFormatOptions=__name(()=>DATEFMTLISG.map(item=>({label:item.label,value:item.suffix})),"getDateFormatOptions"),getNumberFormatOptions=__name(()=>NUMBERFORMAT.map(item=>({label:item.label,value:item.suffix,color:item.color})),"getNumberFormatOptions"),isCurrencyPanel=__name(pattern=>!!getCurrencyType(pattern)&&!pattern.startsWith("_("),"isCurrencyPanel"),CurrencyPanel=__name(props=>{const t=core.useDependency(core.LocaleService).t,userHabitCurrency=require$$0.useContext(UserHabitCurrencyContext),[suffix,suffixSet]=require$$0.useState(()=>getCurrencyType(props.defaultPattern)||userHabitCurrency[0]),[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",2)),[pattern,patternSet]=require$$0.useState(()=>{var _a2;const negativeOptions2=getCurrencyFormatOptions(suffix);return((_a2=negativeOptions2.find(item=>isPatternEqualWithoutDecimal(item.value,props.defaultPattern)))==null?void 0:_a2.value)||negativeOptions2[0].value}),negativeOptions=require$$0.useMemo(()=>getCurrencyFormatOptions(suffix),[suffix]),options=require$$0.useMemo(()=>userHabitCurrency.map(key2=>({label:key2,value:key2})),[userHabitCurrency]);props.action.current=()=>setPatternDecimal(pattern,decimal);const onSelect=__name(value=>{if(value===void 0)return;suffixSet(value);const pattern2=getCurrencyFormatOptions(value)[0].value;patternSet(pattern2),props.onChange(setPatternDecimal(pattern2,decimal))},"onSelect"),onChange=__name(value=>{value!==void 0&&(patternSet(value),props.onChange(setPatternDecimal(value,decimal)))},"onChange"),onDecimalChange=__name(v=>{decimalSet(v||0),props.onChange(setPatternDecimal(pattern,v||0))},"onDecimalChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsxs("div",{className:"m-t-16 options ",children:[jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-120",children:jsxRuntimeExports.jsx(design.InputNumber,{value:decimal,max:20,min:0,onChange:onDecimalChange})})]}),jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.currencyType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-140",children:jsxRuntimeExports.jsx(design.Select,{onChange:onSelect,options,value:suffix})})]})]}),jsxRuntimeExports.jsx("div",{className:"m-t-16 label",children:t("sheet.numfmt.negType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.SelectList,{onChange,options:negativeOptions,value:pattern})}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.currencyDes")})]})},"CurrencyPanel"),isDatePanel=__name(pattern=>{const info=engineNumfmt.numfmt.getInfo(pattern);return getDateFormatOptions().map(item=>item.value).includes(pattern)||["date","datetime","time"].includes(info.type)},"isDatePanel"),DatePanel=__name(props=>{const options=require$$0.useMemo(getDateFormatOptions,[]),t=core.useDependency(core.LocaleService).t,[suffix,suffixSet]=require$$0.useState(()=>{if(props.defaultPattern){const item=options.find(item2=>item2.value===props.defaultPattern);if(item)return item.value}return options[0].value});props.action.current=()=>suffix;const onChange=__name(v=>{v!==void 0&&(suffixSet(v),props.onChange(v))},"onChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"m-t-16 label",children:t("sheet.numfmt.dateType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.SelectList,{value:suffix,options,onChange})}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.dateDes")})]})},"DatePanel"),isGeneralPanel=__name(pattern=>!pattern,"isGeneralPanel"),GeneralPanel=__name(props=>{const t=core.useDependency(core.LocaleService).t;return props.action.current=()=>"",jsxRuntimeExports.jsx("div",{children:jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.generalDes")})})},"GeneralPanel"),isThousandthPercentilePanel=__name(pattern=>getNumberFormatOptions().some(item=>isPatternEqualWithoutDecimal(item.value,pattern)),"isThousandthPercentilePanel"),ThousandthPercentilePanel=__name(props=>{const localeService=core.useDependency(core.LocaleService),options=require$$0.useMemo(getNumberFormatOptions,[]),[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",0)),[suffix,suffixSet]=require$$0.useState(()=>{const item=options.find(item2=>isPatternEqualWithoutDecimal(item2.value,props.defaultPattern||""));return(item==null?void 0:item.value)||options[0].value}),pattern=require$$0.useMemo(()=>setPatternDecimal(suffix,Number(decimal||0)),[suffix,decimal]),isInputDisable=require$$0.useMemo(()=>!isPatternHasDecimal(suffix),[suffix]),handleDecimalChange=__name(decimal2=>{decimalSet(decimal2||0),props.onChange(setPatternDecimal(suffix,Number(decimal2||0)))},"handleDecimalChange"),handleClick=__name(v=>{v!==void 0&&(decimalSet(getDecimalFromPattern(v,0)),suffixSet(v),props.onChange(v))},"handleClick");return props.action.current=()=>pattern,jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"m-t-16 label",children:localeService.t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.InputNumber,{disabled:isInputDisable,value:decimal,max:20,min:0,onChange:handleDecimalChange})}),jsxRuntimeExports.jsxs("div",{className:"m-t-16 label",children:[" ",localeService.t("sheet.numfmt.negType")]}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.SelectList,{onChange:handleClick,options,value:suffix})}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:localeService.t("sheet.numfmt.thousandthPercentileDes")})]})},"ThousandthPercentilePanel");var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n2=arguments.length;i<n2;i++){s=arguments[i];for(var p2 in s)Object.prototype.hasOwnProperty.call(s,p2)&&(t[p2]=s[p2])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p2 in s)Object.prototype.hasOwnProperty.call(s,p2)&&e.indexOf(p2)<0&&(t[p2]=s[p2]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p2=Object.getOwnPropertySymbols(s);i<p2.length;i++)e.indexOf(p2[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p2[i])&&(t[p2[i]]=s[p2[i]]);return t},IconBase=require$$0.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=require$$0.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return require$$0.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a2){var key2=_a2[0],value=_a2[1];typeof value=="string"&&(attrs[key2]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a2,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a2=node.children)===null||_a2===void 0)&&_a2.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid"),IconBase.displayName="UniverIcon";var element={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},CheckMarkSingle=require$$0.forwardRef(function(props,ref){return require$$0.createElement(IconBase,Object.assign({},props,{id:"check-mark-single",ref,icon:element}))});CheckMarkSingle.displayName="CheckMarkSingle";const styles={customFormatTitle:"univer-custom-format-title",customFormatInput:"univer-custom-format-input",customFormatHistoryList:"univer-custom-format-history-list",customFormatHistoryListItem:"univer-custom-format-history-list-item",customFormatHistoryListItemIconWrap:"univer-custom-format-history-list-item-icon-wrap",customFormatDes:"univer-custom-format-des"},key="customFormat",historyPatternKey="numfmt_custom_pattern";function CustomFormat(props){const{defaultPattern,action,onChange}=props,userHabitController=core.useDependency(UserHabitController),localStorageService=core.useDependency(core.ILocalStorageService),localeService=core.useDependency(core.LocaleService),[pattern,patternSet]=require$$0.useState(defaultPattern);action.current=()=>(userHabitController.markHabit(key,pattern),localStorageService.getItem(historyPatternKey).then((list=[])=>{const _list=[...new Set([pattern,...list||[]])].splice(0,10).filter(e=>!!e);localStorageService.setItem(historyPatternKey,_list)}),pattern);const[options,optionsSet]=require$$0.useState([]);require$$0.useEffect(()=>{localStorageService.getItem(historyPatternKey).then(historyList=>{const list=[...CURRENCYFORMAT.map(item=>item.suffix("$")),...DATEFMTLISG.map(item=>item.suffix),...NUMBERFORMAT.map(item=>item.suffix)];list.push(...historyList||[]),userHabitController.addHabit(key,[]).finally(()=>{userHabitController.getHabit(key,list).then(list2=>{optionsSet([...new Set(list2)])})})})},[]);const handleClick=__name(p2=>{patternSet(p2),onChange(p2)},"handleClick"),handleBlur=__name(()=>{onChange(pattern)},"handleBlur");return jsxRuntimeExports.jsxs("div",{className:styles.customFormat,children:[jsxRuntimeExports.jsx("div",{className:styles.customFormatTitle,children:localeService.t("sheet.numfmt.customFormat")}),jsxRuntimeExports.jsx(design.Input,{placeholder:localeService.t("sheet.numfmt.customFormat"),onBlur:handleBlur,value:pattern,onChange:patternSet,className:styles.customFormatInput}),jsxRuntimeExports.jsx("div",{className:styles.customFormatHistoryList,children:options.map(p2=>jsxRuntimeExports.jsxs("div",{onClick:__name(()=>handleClick(p2),"onClick"),className:styles.customFormatHistoryListItem,children:[jsxRuntimeExports.jsx("div",{className:styles.customFormatHistoryListItemIconWrap,children:pattern===p2&&jsxRuntimeExports.jsx(CheckMarkSingle,{})}),jsxRuntimeExports.jsx("div",{children:p2})]},p2))}),jsxRuntimeExports.jsx("div",{className:styles.customFormatDes,children:localeService.t("sheet.numfmt.customFormatDes")})]})}__name(CustomFormat,"CustomFormat");const SheetNumfmtPanel=__name(props=>{const{defaultValue,defaultPattern,row,col}=props.value,localeService=core.useDependency(core.LocaleService),getCurrentPattern=require$$0.useRef(()=>""),t=localeService.t,nextTick=useNextTick(),typeOptions=require$$0.useMemo(()=>[{label:"sheet.numfmt.general",component:GeneralPanel},{label:"sheet.numfmt.accounting",component:AccountingPanel},{label:"sheet.numfmt.currency",component:CurrencyPanel},{label:"sheet.numfmt.date",component:DatePanel},{label:"sheet.numfmt.thousandthPercentile",component:ThousandthPercentilePanel},{label:"sheet.numfmt.customFormat",component:CustomFormat}].map(item=>({...item,label:t(item.label)})),[]),[type,typeSet]=require$$0.useState(findDefaultType),[key2,keySet]=require$$0.useState(()=>`${row}_${col}`),{mark,userHabitCurrency}=useCurrencyOptions(()=>keySet(`${row}_${col}_userCurrency'`)),BusinessComponent=require$$0.useMemo(()=>{var _a2;return(_a2=typeOptions.find(item=>item.label===type))==null?void 0:_a2.component},[type]);function findDefaultType(){return[isGeneralPanel,isAccountingPanel,isCurrencyPanel,isDatePanel,isThousandthPercentilePanel].reduce((pre,curFn,index)=>pre||(curFn(defaultPattern)?typeOptions[index].label:""),"")||typeOptions[0].label}__name(findDefaultType,"findDefaultType");const selectOptions=typeOptions.map(option=>({label:option.label,value:option.label})),handleSelect=__name(value=>{typeSet(value),nextTick(()=>props.onChange({type:"change",value:getCurrentPattern.current()||""}))},"handleSelect"),handleChange=__name(v=>{props.onChange({type:"change",value:v})},"handleChange"),handleConfirm=__name(()=>{const pattern=getCurrentPattern.current()||"",currency=getCurrencyType(pattern);currency&&mark(currency),props.onChange({type:"confirm",value:pattern})},"handleConfirm"),handleCancel=__name(()=>{props.onChange({type:"cancel",value:""})},"handleCancel"),subProps={onChange:handleChange,defaultValue,defaultPattern,action:getCurrentPattern};return require$$0.useEffect(()=>{typeSet(findDefaultType()),keySet(`${row}_${col}`)},[row,col]),jsxRuntimeExports.jsxs("div",{className:"numfmt-panel p-b-20",children:[jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"label m-t-14",children:t("sheet.numfmt.numfmtType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.Select,{onChange:handleSelect,options:selectOptions,value:type,style:{width:"100%"}})}),jsxRuntimeExports.jsx("div",{children:BusinessComponent&&jsxRuntimeExports.jsx(UserHabitCurrencyContext.Provider,{value:userHabitCurrency,children:require$$0.createElement(BusinessComponent,{...subProps,key:key2})})})]}),jsxRuntimeExports.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[jsxRuntimeExports.jsx(design.Button,{size:"small",onClick:handleCancel,className:"m-r-12",children:t("sheet.numfmt.cancel")}),jsxRuntimeExports.jsx(design.Button,{type:"primary",size:"small",onClick:handleConfirm,children:t("sheet.numfmt.confirm")})]})]})},"SheetNumfmtPanel"),SetPercentCommand={id:"sheet.command.numfmt.set.percent",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selections=accessor.get(sheets.SheetsSelectionsService).getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix="0%";return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{values.push({row,col,pattern:suffix,type:"percent"})})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")};var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key2,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$4");let NumfmtController=(_c=class extends core.Disposable{constructor(_sheetInterceptorService,_themeService,_univerInstanceService,_commandService,_selectionManagerService,_renderManagerService,_numfmtService,_componentManager,_sidebarService,_localeService){super();__publicField(this,"_previewPattern","");__publicField(this,"_sidebarDisposable",null);this._sheetInterceptorService=_sheetInterceptorService,this._themeService=_themeService,this._univerInstanceService=_univerInstanceService,this._commandService=_commandService,this._selectionManagerService=_selectionManagerService,this._renderManagerService=_renderManagerService,this._numfmtService=_numfmtService,this._componentManager=_componentManager,this._sidebarService=_sidebarService,this._localeService=_localeService,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var _a2;const sidebarService=this._sidebarService,selectionManagerService=this._selectionManagerService,commandService=this._commandService,univerInstanceService=this._univerInstanceService,numfmtService=this._numfmtService,localeService=this._localeService,range=(((_a2=selectionManagerService.getCurrentSelections())==null?void 0:_a2.map(s=>s.range))||[])[0];if(!range)return!1;const workbook=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),sheet=workbook.getActiveSheet();if(!sheet)return!1;const cellValue=sheet.getCellRaw(range.startRow,range.startColumn),numfmtValue=numfmtService.getValue(workbook.getUnitId(),sheet.getSheetId(),range.startRow,range.startColumn);let pattern="";numfmtValue&&(pattern=numfmtValue.pattern);const defaultValue=(cellValue==null?void 0:cellValue.t)===core.CellValueType.NUMBER?cellValue.v:12345678,props={onChange:__name(config=>{var _a3;if(config.type==="change")this._previewPattern=config.value,this._forceUpdate();else if(config.type==="confirm"){const selections2=((_a3=selectionManagerService.getCurrentSelections())==null?void 0:_a3.map(s=>s.range))||[],params={values:[]},patternType=getPatternType(config.value);selections2.forEach(rangeInfo=>{core.Range.foreach(rangeInfo,(row,col)=>{params.values.push({row,col,pattern:config.value,type:patternType})})}),commandService.executeCommand(SetNumfmtCommand.id,params),sidebarService.close()}else config.type==="cancel"&&sidebarService.close()},"onChange"),value:{defaultPattern:pattern,defaultValue,row:range.startRow,col:range.startColumn}};return this._sidebarDisposable=sidebarService.open({header:{title:localeService.t("sheet.numfmt.title")},children:{label:SHEET_NUMFMT_PLUGIN,...props},onClose:__name(()=>{this._forceUpdate(),commandService.executeCommand(CloseNumfmtPanelOperator.id)},"onClose")}),!0}_forceUpdate(unitId){var _a2;const renderUnit=this._renderManagerService.getRenderById(unitId!=null?unitId:this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET).getUnitId());renderUnit==null||renderUnit.with(sheetsUi.SheetSkeletonManagerService).reCalculate(),(_a2=renderUnit==null?void 0:renderUnit.mainComponent)==null||_a2.makeDirty()}_initCommands(){[AddDecimalCommand,SubtractDecimalCommand,SetCurrencyCommand,SetPercentCommand,OpenNumfmtPanelOperator,CloseNumfmtPanelOperator,SetNumfmtCommand].forEach(config=>{this.disposeWithMe(this._commandService.registerCommand(config))})}_initPanel(){this._componentManager.register(SHEET_NUMFMT_PLUGIN,SheetNumfmtPanel)}_initRealTimeRenderingInterceptor(){const isPanelOpenObserver=new rxjs.Observable(subscriber=>{this._commandService.onCommandExecuted(commandInfo=>{commandInfo.id===OpenNumfmtPanelOperator.id&&subscriber.next(!0),commandInfo.id===CloseNumfmtPanelOperator.id&&subscriber.next(!1)})}),combineOpenAndSelection$=rxjs.combineLatest([isPanelOpenObserver,this._selectionManagerService.selectionMoveEnd$.pipe(operators.map(selectionInfos=>selectionInfos?selectionInfos.map(selectionInfo=>selectionInfo.range):[]))]);this.disposeWithMe(core.toDisposable(combineOpenAndSelection$.pipe(operators.switchMap(([isOpen,selectionRanges])=>new rxjs.Observable(subscribe=>{const disposableCollection=new core.DisposableCollection;return isOpen&&selectionRanges.length&&subscribe.next({selectionRanges,disposableCollection}),()=>{disposableCollection.dispose()}})),operators.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection,selectionRanges})=>{var _a2,_b2;const workbook=this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET);this.openPanel(),disposableCollection.add(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,handler:__name((cell,location,next)=>{const{row,col}=location,defaultValue=next(cell)||{};if(selectionRanges.find(range=>range.startColumn<=col&&range.endColumn>=col&&range.startRow<=row&&range.endRow>=row)){const rawValue=location.worksheet.getCellRaw(row,col),value=rawValue==null?void 0:rawValue.v,type=rawValue==null?void 0:rawValue.t;if(value==null||type!==core.CellValueType.NUMBER||this._previewPattern===null)return defaultValue;const info=getPatternPreview(this._previewPattern,value,this._localeService.getCurrentLocale());if(info.color){const color=this._themeService.getCurrentTheme()[`${info.color}500`];return{...defaultValue,v:info.result,t:core.CellValueType.STRING,s:{cl:{rgb:color}}}}return{...defaultValue,v:info.result,t:core.CellValueType.STRING}}return defaultValue},"handler")})),(_b2=(_a2=this._renderManagerService.getRenderById(workbook.getUnitId()))==null?void 0:_a2.mainComponent)==null||_b2.makeDirty()})))}_commandExecutedListener(){const commandList=[sheets.RemoveNumfmtMutation.id,sheets.SetNumfmtMutation.id];this.disposeWithMe(new rxjs.Observable(subscribe=>{const disposable=this._commandService.onCommandExecuted(command=>{if(commandList.includes(command.id)){const params=command.params;subscribe.next(params.unitId)}});return()=>disposable.dispose()}).pipe(operators.debounceTime(16)).subscribe(unitId=>this._forceUpdate(unitId)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).subscribe(unit=>{var _a2;unit||((_a2=this._sidebarDisposable)==null||_a2.dispose(),this._sidebarDisposable=null)})}},__name(_c,"NumfmtController"),_c);NumfmtController=__decorateClass$4([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtController),__decorateParam$4(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$4(1,core.Inject(core.ThemeService)),__decorateParam$4(2,core.IUniverInstanceService),__decorateParam$4(3,core.ICommandService),__decorateParam$4(4,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$4(5,engineRender.IRenderManagerService),__decorateParam$4(6,sheets.INumfmtService),__decorateParam$4(7,core.Inject(ui.ComponentManager)),__decorateParam$4(8,ui.ISidebarService),__decorateParam$4(9,core.Inject(core.LocaleService))],NumfmtController);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key2,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$3");const createCollectEffectMutation=__name(()=>{let list=[];return{add:__name((unitId,subUnitId,row,col,value)=>list.push({unitId,subUnitId,row,col,value}),"add"),getEffects:__name(()=>list,"getEffects"),clean:__name(()=>{list=[]},"clean")}},"createCollectEffectMutation");let NumfmtEditorController=(_d=class extends core.Disposable{constructor(_sheetInterceptorService,_numfmtService,_univerInstanceService,_injector,_editorBridgeService){super();__publicField(this,"_collectEffectMutation",createCollectEffectMutation());this._sheetInterceptorService=_sheetInterceptorService,this._numfmtService=_numfmtService,this._univerInstanceService=_univerInstanceService,this._injector=_injector,this._editorBridgeService=_editorBridgeService,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(core.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{handler:__name((value,context,next)=>{const row=context.row,col=context.col,numfmtCell=this._numfmtService.getValue(context.unitId,context.subUnitId,row,col);if(numfmtCell)switch(getPatternType(numfmtCell.pattern)){case"scientific":case"percent":case"currency":case"grouped":case"number":return context.worksheet.getCellRaw(row,col);case"date":case"time":case"datetime":default:return next&&next(value)}return next(value)},"handler")})))}_initInterceptorEditorEnd(){this._editorBridgeService&&this.disposeWithMe(core.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{handler:__name((value,context,next)=>{var _a2;this._collectEffectMutation.clean();const currentNumfmtValue=this._numfmtService.getValue(context.unitId,context.subUnitId,context.row,context.col),currentNumfmtType=(_a2=currentNumfmtValue&&getPatternType(currentNumfmtValue.pattern))!=null?_a2:"",clean=__name(()=>{currentNumfmtValue&&this._collectEffectMutation.add(context.unitId,context.subUnitId,context.row,context.col,null)},"clean");if(!(value!=null&&value.v))return next(value);const content=String(value.v),dateInfo=engineNumfmt.numfmt.parseDate(content)||engineNumfmt.numfmt.parseTime(content);if(!!dateInfo){if(dateInfo&&dateInfo.z){const v=Number(dateInfo.v);return this._collectEffectMutation.add(context.unitId,context.subUnitId,context.row,context.col,{pattern:dateInfo.z}),{...value,v,t:core.CellValueType.NUMBER}}}else(["date","time","datetime"].includes(currentNumfmtType)||!isNumeric(content))&&clean();return next(value)},"handler")})))}_initInterceptorCommands(){const self2=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(command){var _a2;switch(command.id){case sheets.SetRangeValuesCommand.id:{const workbook=self2._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),unitId=workbook.getUnitId(),subUnitId=(_a2=workbook.getActiveSheet())==null?void 0:_a2.getSheetId();if(!subUnitId)return{redos:[],undos:[]};const list=self2._collectEffectMutation.getEffects();if(!list.length)return{redos:[],undos:[]};const cells=list.filter(item=>{var _a3;return!!((_a3=item.value)!=null&&_a3.pattern)}).map(item=>({row:item.row,col:item.col,pattern:item.value.pattern})),removeCells=list.filter(item=>{var _a3;return!((_a3=item.value)!=null&&_a3.pattern)}).map(item=>({startRow:item.row,endColumn:item.col,startColumn:item.col,endRow:item.row})),redos=[],undos=[];if(cells){const redo={id:sheets.SetNumfmtMutation.id,params:sheets.transformCellsToRange(unitId,subUnitId,cells)};redos.push(redo),undos.push(...sheets.factorySetNumfmtUndoMutation(self2._injector,redo.params))}if(removeCells){const redo={id:sheets.RemoveNumfmtMutation.id,params:{unitId,subUnitId,ranges:removeCells}};redos.push(redo),undos.push(...sheets.factoryRemoveNumfmtUndoMutation(self2._injector,redo.params))}return{redos,undos:undos.reverse()}}}return{redos:[],undos:[]}}}))}},__name(_d,"NumfmtEditorController"),_d);NumfmtEditorController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtEditorController),__decorateParam$3(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$3(1,core.Inject(sheets.INumfmtService)),__decorateParam$3(2,core.Inject(core.IUniverInstanceService)),__decorateParam$3(3,core.Inject(core.Injector)),__decorateParam$3(4,core.Optional(sheetsUi.IEditorBridgeService))],NumfmtEditorController);function isNumeric(str){return/^-?\d+(\.\d+)?$/.test(str)}__name(isNumeric,"isNumeric");var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key2,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$2");let NumfmtI18nController=(_e=class extends core.Disposable{constructor(_localeService){super(),this._localeService=_localeService}},__name(_e,"NumfmtI18nController"),_e);NumfmtI18nController=__decorateClass$2([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtI18nController),__decorateParam$2(0,core.Inject(core.LocaleService))],NumfmtI18nController);const MENU_OPTIONS=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:engineNumfmt.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],MORE_NUMFMT_TYPE_KEY="sheet.numfmt.moreNumfmtType",OPTIONS_KEY="sheet.numfmt.moreNumfmtType.options",MoreNumfmtType=__name(props=>{var _a2;const localeService=core.useDependency(core.LocaleService),value=(_a2=props.value)!=null?_a2:localeService.t("sheet.numfmt.general");return jsxRuntimeExports.jsx("span",{className:"more-numfmt-type",children:value})},"MoreNumfmtType"),Options=__name(()=>{const commandService=core.useDependency(core.ICommandService),localeService=core.useDependency(core.LocaleService),injector=core.useInjector(),selectionManagerService=core.useDependency(sheets.SheetsSelectionsService),setNumfmt=__name(pattern=>{const selection=selectionManagerService.getCurrentLastSelection();if(!selection)return;const textSelectionRenderManager=injector.get(engineRender.ITextSelectionRenderManager),range=selection.range,values=[];core.Range.foreach(range,(row,col)=>{pattern?values.push({row,col,pattern,type:getPatternType(pattern)}):values.push({row,col})}),commandService.executeCommand(SetNumfmtCommand.id,{values}),textSelectionRenderManager.focus()},"setNumfmt"),handleOnclick=__name(index=>{if(index===0)setNumfmt(null);else if(index===MENU_OPTIONS.length-1)commandService.executeCommand(OpenNumfmtPanelOperator.id);else{const item=MENU_OPTIONS[index];item.pattern&&setNumfmt(item.pattern)}},"handleOnclick"),defaultValue=1220;return jsxRuntimeExports.jsx("div",{className:"more-numfmt-type-options",children:MENU_OPTIONS.map((item,index)=>item==="|"?jsxRuntimeExports.jsx("div",{className:"line m-t-4",onClick:__name(e=>e.stopPropagation(),"onClick")},index):jsxRuntimeExports.jsxs("div",{className:"option-item m-t-4",onClick:__name(()=>{handleOnclick(index)},"onClick"),children:[jsxRuntimeExports.jsx("div",{children:localeService.t(item.label)}),jsxRuntimeExports.jsx("div",{className:"m-l-26",children:item.pattern?getPatternPreview(item.pattern||"",defaultValue,localeService.getCurrentLocale()).result:""})]},index))})},"Options"),CurrencyMenuItem=__name(accessor=>({icon:"RmbSingle",id:SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:ui.MenuItemType.BUTTON,group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission,sheets.WorksheetSetCellStylePermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}),"CurrencyMenuItem"),AddDecimalMenuItem=__name(accessor=>({icon:"AddDigitsSingle",id:AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:ui.MenuItemType.BUTTON,positions:[ui.MenuPosition.TOOLBAR_START],group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission,sheets.WorksheetSetCellStylePermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}),"AddDecimalMenuItem"),SubtractDecimalMenuItem=__name(accessor=>({icon:"ReduceDigitsSingle",id:SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:ui.MenuItemType.BUTTON,group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission,sheets.WorksheetSetCellStylePermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}),"SubtractDecimalMenuItem"),PercentMenuItem=__name(accessor=>({icon:"PercentSingle",id:SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:ui.MenuItemType.BUTTON,group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission,sheets.WorksheetSetCellStylePermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}),"PercentMenuItem"),FactoryOtherMenuItem=__name(accessor=>{const numfmtService=accessor.get(sheets.INumfmtService),univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),localeService=accessor.get(core.LocaleService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),value$=sheetsUi.deriveStateFromActiveSheet$(univerInstanceService,"",({workbook,worksheet})=>new rxjs.Observable(subscribe=>rxjs.merge(selectionManagerService.selectionMoveEnd$,new rxjs.Observable(commandSubscribe=>{const commandList=[sheets.RemoveNumfmtMutation.id,sheets.SetNumfmtMutation.id],disposable=commandService.onCommandExecuted(commandInfo=>{commandList.includes(commandInfo.id)&&commandSubscribe.next(null)});return()=>disposable.dispose()})).subscribe(()=>{const selections=selectionManagerService.getCurrentSelections();if(selections&&selections[0]){const range=selections[0].range,row=range.startRow,col=range.startColumn,numfmtValue=numfmtService.getValue(workbook.getUnitId(),worksheet.getSheetId(),row,col),pattern=numfmtValue==null?void 0:numfmtValue.pattern;let value=localeService.t("sheet.numfmt.general");if(pattern){const item=MENU_OPTIONS.filter(item2=>typeof item2=="object"&&item2.pattern).find(item2=>isPatternEqualWithoutDecimal(pattern,item2.pattern));item&&typeof item=="object"&&item.pattern?value=localeService.t(item.label):value=localeService.t("sheet.numfmt.moreFmt")}subscribe.next(value)}})));return{label:MORE_NUMFMT_TYPE_KEY,id:OpenNumfmtPanelOperator.id,tooltip:"sheet.numfmt.title",type:ui.MenuItemType.SELECTOR,group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[ui.MenuPosition.TOOLBAR_START],selections:[{label:{name:OPTIONS_KEY,hoverable:!1}}],value$,hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetSetCellStylePermission,sheets.WorksheetEditPermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}},"FactoryOtherMenuItem");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key2,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$1");const DefaultSheetNumfmtConfig={};let NumfmtMenuController=(_f=class extends core.Disposable{constructor(_config,_injector,_componentManager,_menuService){super(),this._config=_config,this._injector=_injector,this._componentManager=_componentManager,this._menuService=_menuService,this._initMenu()}_initMenu(){const{menu={}}=this._config;[PercentMenuItem,AddDecimalMenuItem,SubtractDecimalMenuItem,CurrencyMenuItem,FactoryOtherMenuItem].forEach(factory=>{this.disposeWithMe(this._menuService.addMenuItem(factory(this._injector),menu))}),this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY,MoreNumfmtType)),this.disposeWithMe(this._componentManager.register(OPTIONS_KEY,Options))}},__name(_f,"NumfmtMenuController"),_f);NumfmtMenuController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtMenuController),__decorateParam$1(1,core.Inject(core.Injector)),__decorateParam$1(2,core.Inject(ui.ComponentManager)),__decorateParam$1(3,core.Inject(ui.IMenuService))],NumfmtMenuController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key2,value)=>key2 in obj?__defProp2(obj,key2,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key2]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp2(target,key2,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam"),__publicField2=__name((obj,key2,value)=>__defNormalProp2(obj,typeof key2!="symbol"?key2+"":key2,value),"__publicField");exports2.UniverSheetsNumfmtPlugin=(_g=class extends core.Plugin{constructor(_config={},_injector){super(),this._config=_config,this._injector=_injector,this._config=core.Tools.deepMerge({},DefaultSheetNumfmtConfig,this._config)}onStarting(){this._injector.add([INumfmtController,{useClass:NumfmtController,lazy:!1}]),this._injector.add([NumfmtEditorController]),this._injector.add([UserHabitController]),this._injector.add([SheetsNumfmtCellContentController]),this._injector.add([NumfmtI18nController]),this._injector.add([NumfmtMenuController,{useFactory:__name(()=>this._injector.createInstance(NumfmtMenuController,this._config),"useFactory")}])}},__name(_g,"UniverSheetsNumfmtPlugin"),_g),__publicField2(exports2.UniverSheetsNumfmtPlugin,"pluginName",SHEET_NUMFMT_PLUGIN),__publicField2(exports2.UniverSheetsNumfmtPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),exports2.UniverSheetsNumfmtPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin,sheetsUi.UniverSheetsUIPlugin),__decorateParam(1,core.Inject(core.Injector))],exports2.UniverSheetsNumfmtPlugin),exports2.AddDecimalCommand=AddDecimalCommand,exports2.CloseNumfmtPanelOperator=CloseNumfmtPanelOperator,exports2.OpenNumfmtPanelOperator=OpenNumfmtPanelOperator,exports2.SetCurrencyCommand=SetCurrencyCommand,exports2.SetNumfmtCommand=SetNumfmtCommand,exports2.SetPercentCommand=SetPercentCommand,exports2.SubtractDecimalCommand=SubtractDecimalCommand,exports2.getPatternPreview=getPatternPreview,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -50,38 +50,36 @@
|
|
|
50
50
|
"lib"
|
|
51
51
|
],
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@wendellhu/redi": "0.16.0",
|
|
54
53
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
55
54
|
"rxjs": ">=7.0.0",
|
|
56
|
-
"@univerjs/core": "0.2.
|
|
57
|
-
"@univerjs/engine-numfmt": "0.2.
|
|
58
|
-
"@univerjs/design": "0.2.
|
|
59
|
-
"@univerjs/engine-render": "0.2.
|
|
60
|
-
"@univerjs/sheets
|
|
61
|
-
"@univerjs/sheets": "0.2.
|
|
62
|
-
"@univerjs/ui": "0.2.
|
|
55
|
+
"@univerjs/core": "0.2.6",
|
|
56
|
+
"@univerjs/engine-numfmt": "0.2.6",
|
|
57
|
+
"@univerjs/design": "0.2.6",
|
|
58
|
+
"@univerjs/engine-render": "0.2.6",
|
|
59
|
+
"@univerjs/sheets": "0.2.6",
|
|
60
|
+
"@univerjs/sheets-ui": "0.2.6",
|
|
61
|
+
"@univerjs/ui": "0.2.6"
|
|
63
62
|
},
|
|
64
63
|
"dependencies": {
|
|
65
|
-
"@univerjs/icons": "^0.1.
|
|
64
|
+
"@univerjs/icons": "^0.1.70"
|
|
66
65
|
},
|
|
67
66
|
"devDependencies": {
|
|
68
67
|
"@types/react": "^18.3.3",
|
|
69
|
-
"@wendellhu/redi": "0.16.0",
|
|
70
68
|
"less": "^4.2.0",
|
|
71
69
|
"react": "18.3.1",
|
|
72
70
|
"rxjs": "^7.8.1",
|
|
73
|
-
"typescript": "^5.5.
|
|
74
|
-
"vite": "^5.3.
|
|
75
|
-
"vitest": "^2.0.
|
|
76
|
-
"@univerjs/core": "0.2.
|
|
77
|
-
"@univerjs/
|
|
78
|
-
"@univerjs/engine-
|
|
79
|
-
"@univerjs/
|
|
80
|
-
"@univerjs/
|
|
81
|
-
"@univerjs/
|
|
82
|
-
"@univerjs/
|
|
83
|
-
"@univerjs/
|
|
84
|
-
"@univerjs/ui": "0.2.
|
|
71
|
+
"typescript": "^5.5.4",
|
|
72
|
+
"vite": "^5.3.5",
|
|
73
|
+
"vitest": "^2.0.4",
|
|
74
|
+
"@univerjs/core": "0.2.6",
|
|
75
|
+
"@univerjs/engine-formula": "0.2.6",
|
|
76
|
+
"@univerjs/engine-numfmt": "0.2.6",
|
|
77
|
+
"@univerjs/design": "0.2.6",
|
|
78
|
+
"@univerjs/shared": "0.2.6",
|
|
79
|
+
"@univerjs/sheets": "0.2.6",
|
|
80
|
+
"@univerjs/sheets-ui": "0.2.6",
|
|
81
|
+
"@univerjs/engine-render": "0.2.6",
|
|
82
|
+
"@univerjs/ui": "0.2.6"
|
|
85
83
|
},
|
|
86
84
|
"univerSpace": {
|
|
87
85
|
".": {
|