@univerjs/sheets-numfmt 0.2.2 → 0.2.3
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/README.md +21 -13
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +378 -376
- package/lib/locale/vi-VN.json +36 -0
- package/lib/locale/zh-TW.json +36 -0
- package/lib/types/controllers/numfmt.controller.d.ts +2 -2
- package/lib/types/locale/vi-VN.d.ts +4 -0
- package/lib/types/locale/zh-TW.d.ts +4 -0
- package/lib/umd/index.js +2 -2
- package/package.json +17 -17
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sheet": {
|
|
3
|
+
"numfmt": {
|
|
4
|
+
"percent": "Phần trăm",
|
|
5
|
+
"title": "Định dạng số",
|
|
6
|
+
"numfmtType": "Loại định dạng",
|
|
7
|
+
"cancel": "Hủy bỏ",
|
|
8
|
+
"confirm": "Xác nhận",
|
|
9
|
+
"general": "Chung",
|
|
10
|
+
"accounting": "Kế toán",
|
|
11
|
+
"text": "Văn bản",
|
|
12
|
+
"number": "Số",
|
|
13
|
+
"currency": "Tiền tệ",
|
|
14
|
+
"date": "Ngày",
|
|
15
|
+
"time": "Thời gian",
|
|
16
|
+
"thousandthPercentile": "Phân vị phần nghìn",
|
|
17
|
+
"preview": "Xem trước",
|
|
18
|
+
"dateTime": "Ngày giờ",
|
|
19
|
+
"decimalLength": "Số chữ số thập phân",
|
|
20
|
+
"currencyType": "Loại tiền tệ",
|
|
21
|
+
"moreFmt": "Nhiều định dạng hơn",
|
|
22
|
+
"financialValue": "Giá trị tài chính",
|
|
23
|
+
"roundingCurrency": "Tiền tệ làm tròn",
|
|
24
|
+
"timeDuration": "Thời lượng",
|
|
25
|
+
"currencyDes": "Định dạng tiền tệ được sử dụng để biểu thị các giá trị tiền tệ thông thường. Định dạng kế toán có thể căn chỉnh các giá trị trong một cột với dấu thập phân.",
|
|
26
|
+
"accountingDes": "Định dạng số kế toán có thể căn chỉnh các ký hiệu tiền tệ và dấu thập phân trong một cột các giá trị.",
|
|
27
|
+
"dateType": "Loại ngày",
|
|
28
|
+
"dateDes": "Định dạng ngày biểu thị các giá trị chuỗi ngày và thời gian dưới dạng giá trị ngày.",
|
|
29
|
+
"negType": "Loại số âm",
|
|
30
|
+
"generalDes": "Định dạng chung không chứa bất kỳ định dạng số cụ thể nào.",
|
|
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
|
+
"addDecimal": "Thêm chữ số thập phân",
|
|
33
|
+
"subtractDecimal": "Giảm chữ số thập phân"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sheet": {
|
|
3
|
+
"numfmt": {
|
|
4
|
+
"percent": "百分比",
|
|
5
|
+
"title": "數字格式",
|
|
6
|
+
"numfmtType": "格式類型",
|
|
7
|
+
"cancel": "取消",
|
|
8
|
+
"confirm": "確認",
|
|
9
|
+
"general": "常規",
|
|
10
|
+
"accounting": "會計",
|
|
11
|
+
"text": "文字",
|
|
12
|
+
"number": "數值",
|
|
13
|
+
"currency": "貨幣",
|
|
14
|
+
"date": "日期",
|
|
15
|
+
"time": "時間",
|
|
16
|
+
"thousandthPercentile": "千分位符",
|
|
17
|
+
"preview": "範例",
|
|
18
|
+
"dateTime": "日期時間",
|
|
19
|
+
"decimalLength": "小數位數",
|
|
20
|
+
"currencyType": "貨幣類型",
|
|
21
|
+
"moreFmt": "更多格式",
|
|
22
|
+
"financialValue": "財務數值",
|
|
23
|
+
"roundingCurrency": "貨幣取整",
|
|
24
|
+
"timeDuration": "持續時間",
|
|
25
|
+
"currencyDes": "貨幣格式用來表示一般貨幣數值。會計格式可以對一列數值進行小數點對齊",
|
|
26
|
+
"accountingDes": "會計數字格式可對一列數值進行貨幣符號和小數點對齊",
|
|
27
|
+
"dateType": "日期類型",
|
|
28
|
+
"dateDes": "日期格式將日期和時間系列數值品顯示為日期值。 ",
|
|
29
|
+
"negType": "負數型別",
|
|
30
|
+
"generalDes": "常規格式不包含任何特定的數字格式。 ",
|
|
31
|
+
"thousandthPercentileDes": "千分位符號格式用於一般數字的表示。貨幣和會計格式則提供貨幣值計算的專用格式。 ",
|
|
32
|
+
"addDecimal": "增加小數位",
|
|
33
|
+
"subtractDecimal": "減少小數位"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Disposable, ICommandService, IUniverInstanceService, LocaleService, ThemeService } from '@univerjs/core';
|
|
2
2
|
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
3
|
-
import { INumfmtService,
|
|
3
|
+
import { INumfmtService, SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';
|
|
4
4
|
import { ComponentManager, ISidebarService } from '@univerjs/ui';
|
|
5
5
|
import { INumfmtController } from './type';
|
|
6
6
|
|
|
@@ -22,7 +22,7 @@ export declare class NumfmtController extends Disposable implements INumfmtContr
|
|
|
22
22
|
* @memberof NumfmtController
|
|
23
23
|
*/
|
|
24
24
|
private _previewPattern;
|
|
25
|
-
constructor(_sheetInterceptorService: SheetInterceptorService, _themeService: ThemeService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _selectionManagerService:
|
|
25
|
+
constructor(_sheetInterceptorService: SheetInterceptorService, _themeService: ThemeService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _selectionManagerService: SheetsSelectionsService, _renderManagerService: IRenderManagerService, _numfmtService: INumfmtService, _componentManager: ComponentManager, _sidebarService: ISidebarService, _localeService: LocaleService);
|
|
26
26
|
openPanel(): boolean;
|
|
27
27
|
private _forceUpdate;
|
|
28
28
|
private _initCommands;
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
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,E){"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.getInfo(e).type||"unknown",z=(e,t,s)=>{const n=j.getInfo(e),r=s===a.LocaleType.ZH_CN?"zh-CN":"en",i=n._partitions[1],o=j.format(e,t,{locale:r});return t<0?{result:o,color:i.color}:{result:o}};var Ee=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&&Ee(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.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.getInfo(e)._partitions,r=j.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(""),N=(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=N(`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=N(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=N(`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:N(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={};/**
|
|
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 De=C,Ue=Symbol.for("react.element"),we=Symbol.for("react.fragment"),Le=Object.prototype.hasOwnProperty,Ae=De.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ve={key:!0,ref:!0,__self:!0,__source:!0};function _e(e,t,r){var n,s={},i=null,o=null;r!==void 0&&(i=""+r),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(o=t.ref);for(n in t)Le.call(t,n)&&!Ve.hasOwnProperty(n)&&(s[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps,t)s[n]===void 0&&(s[n]=t[n]);return{$$typeof:Ue,type:e,key:i,ref:o,props:s,_owner:Ae.current}}J.Fragment=we,J.jsx=_e,J.jsxs=_e,ge.exports=J;var p=ge.exports;const oe=C.createContext([]),ce=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"];var He=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,ke=(e,t,r,n)=>{for(var s=n>1?void 0:n?$e(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(n?o(t,r,s):o(s))||s);return n&&s&&He(t,r,s),s},We=(e,t)=>(r,n)=>t(r,n,e);let Z=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const r=this._getKey(e);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,t)})}markHabit(e,t){const r=this._getKey(e);this._localStorageService.getItem(r).then(n=>{if(n){const s=n.findIndex(i=>i===t);s>-1&&n.splice(s,1),n.unshift(t),this._localStorageService.setItem(r,n)}})}async getHabit(e,t){const r=this._getKey(e),n=await this._localStorageService.getItem(r);if(t&&n){const s=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=s.find(u=>u.value===i))==null?void 0:v.priority)||-1;return(((f=s.find(u=>u.value===o))==null?void 0:f.priority)||-1)-c})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};Z=ke([We(0,I.Inject(a.ILocalStorageService))],Z);const ye="numfmtCurrency",Fe=e=>{const t=E.useDependency(Z),[r,n]=C.useState(ce);return C.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(ye,[...ce]).then(i=>{n(i),e&&e(i)})})},[]),{userHabitCurrency:r,mark:i=>{t.markHabit(ye,i)}}},Be=()=>{const e=C.useRef([]),[t,r]=C.useState({});return C.useEffect(()=>{e.current.forEach(s=>{s()}),e.current=[]},[t]),s=>{e.current.push(s),r({})}},H=e=>ce.find(r=>e.includes(r)),Ge=e=>!!H(e)&&e.startsWith("_("),ze=e=>{const[t,r]=C.useState(()=>U(e.defaultPattern||"",2)),n=C.useContext(oe),[s,i]=C.useState(()=>H(e.defaultPattern)||n[0]),o=C.useMemo(()=>n.map(u=>({label:u,value:u})),[]),l=E.useDependency(a.LocaleService).t;e.action.current=()=>N(`_("${s}"* #,##0${t>0?".0":""}_)`,t);const v=u=>{i(u),e.onChange(N(`_("${u}"* #,##0${t>0?".0":""}_)`,t))},f=u=>{const d=u||0;r(d),e.onChange(N(`_("${s}"* #,##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:s})})]})]}),p.jsx("div",{className:"describe m-t-14",children:l("sheet.numfmt.accountingDes")})]})},le=e=>Se.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),be=()=>je.map(e=>({label:e.label,value:e.suffix})),Ce=()=>xe.map(e=>({label:e.label,value:e.suffix,color:e.color})),Ke=e=>!!H(e)&&!e.startsWith("_("),Ye=e=>{const r=E.useDependency(a.LocaleService).t,n=C.useContext(oe),[s,i]=C.useState(()=>H(e.defaultPattern)||n[0]),[o,c]=C.useState(()=>U(e.defaultPattern||"",2)),[l,v]=C.useState(()=>{var b;const h=le(s);return((b=h.find(M=>K(M.value,e.defaultPattern)))==null?void 0:b.value)||h[0].value}),f=C.useMemo(()=>le(s),[s]),u=C.useMemo(()=>n.map(h=>({label:h,value:h})),[n]);e.action.current=()=>N(l,o);const d=h=>{if(h===void 0)return;i(h);const _=le(h)[0].value;v(_),e.onChange(N(_,o))},g=h=>{h!==void 0&&(v(h),e.onChange(N(h,o)))},y=h=>{c(h||0),e.onChange(N(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:r("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:r("sheet.numfmt.currencyType")}),p.jsx("div",{className:"m-t-8 w-140",children:p.jsx(R.Select,{onChange:d,options:u,value:s})})]})]}),p.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.negType")}),p.jsx("div",{className:"m-t-8",children:p.jsx(R.SelectList,{onChange:g,options:f,value:l})}),p.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})},Je=e=>{const t=D.getInfo(e);return be().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)},Ze=e=>{const t=C.useMemo(be,[]),n=E.useDependency(a.LocaleService).t,[s,i]=C.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=()=>s;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:s,options:t,onChange:o})}),p.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Qe=e=>!e,Xe=e=>{const r=E.useDependency(a.LocaleService).t;return e.action.current=()=>"",p.jsx("div",{children:p.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},qe=e=>Ce().some(t=>K(t.value,e)),et=e=>{const t=E.useDependency(a.LocaleService),r=C.useMemo(Ce,[]),[n,s]=C.useState(()=>U(e.defaultPattern||"",0)),[i,o]=C.useState(()=>{const u=r.find(d=>K(d.value,e.defaultPattern||""));return(u==null?void 0:u.value)||r[0].value}),c=C.useMemo(()=>N(i,Number(n||0)),[i,n]),l=C.useMemo(()=>!Oe(i),[i]),v=u=>{s(u||0),e.onChange(N(i,Number(u||0)))},f=u=>{u!==void 0&&(s(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:r,value:i})}),p.jsx("div",{className:"describe m-t-14",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})},tt=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:s}=e.value,i=E.useDependency(a.LocaleService),o=C.useRef(()=>""),c=i.t,l=Be(),v=C.useMemo(()=>[{label:"sheet.numfmt.general",component:Xe},{label:"sheet.numfmt.accounting",component:ze},{label:"sheet.numfmt.currency",component:Ye},{label:"sheet.numfmt.date",component:Ze},{label:"sheet.numfmt.thousandthPercentile",component:et}].map(P=>({...P,label:c(P.label)})),[]),[f,u]=C.useState(b),[d,g]=C.useState(()=>`${n}_${s}`),{mark:y,userHabitCurrency:h}=Fe(()=>g(`${n}_${s}_userCurrency'`)),_=C.useMemo(()=>{var P;return(P=v.find(A=>A.label===f))==null?void 0:P.component},[f]);function b(){return[Qe,Ge,Ke,Je,qe].reduce((A,Ot,jt)=>A||(Ot(r)?v[jt].label:""),"")||v[0].label}const M=v.map(P=>({label:P.label,value:P.label})),W=P=>{u(P),l(()=>e.onChange({type:"change",value:o.current()||""}))},de=P=>{e.onChange({type:"change",value:P})},fe=()=>{const P=o.current()||"",A=H(P);A&&y(A),e.onChange({type:"confirm",value:P})},pe=()=>{e.onChange({type:"cancel",value:""})},Rt={onChange:de,defaultValue:t,defaultPattern:r,action:o};return C.useEffect(()=>{u(b()),g(`${n}_${s}`)},[n,s]),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:W,options:M,value:f})}),p.jsx("div",{children:_&&p.jsx(oe.Provider,{value:h,children:C.createElement(_,{...Rt,key:d})})})]}),p.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[p.jsx(R.Button,{size:"small",onClick:pe,className:"m-r-12",children:c("sheet.numfmt.cancel")}),p.jsx(R.Button,{type:"primary",size:"small",onClick:fe,children:c("sheet.numfmt.confirm")})]})]})},ue={id:"sheet.command.numfmt.set.percent",type:a.CommandType.COMMAND,handler:async e=>{const t=e.get(a.ICommandService),n=e.get(m.SelectionManagerService).getSelections();if(!n||!n.length)return!1;const s=[],i="0%";return n.forEach(c=>{a.Range.foreach(c.range,(l,v)=>{s.push({row:l,col:v,pattern:i,type:"percent"})})}),await t.executeCommand(w.id,{values:s})}};var nt=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,st=(e,t,r,n)=>{for(var s=n>1?void 0:n?rt(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(n?o(t,r,s):o(s))||s);return n&&s&&nt(t,r,s),s},j=(e,t)=>(r,n)=>t(r,n,e);let Q=class extends a.Disposable{constructor(t,r,n,s,i,o,c,l,v,f){super();te(this,"_previewPattern","");te(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=s,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(){const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,s=this._univerInstanceService,i=this._numfmtService,o=this._localeService,l=(r.getSelectionRanges()||[])[0];if(!l)return!1;const v=s.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 g="";d&&(g=d.pattern);const y=(u==null?void 0:u.t)===a.CellValueType.NUMBER?u.v:12345678,h={onChange:_=>{if(_.type==="change")this._previewPattern=_.value,this._forceUpdate();else if(_.type==="confirm"){const b=r.getSelectionRanges()||[],M={values:[]},W=B(_.value);b.forEach(de=>{a.Range.foreach(de,(fe,pe)=>{M.values.push({row:fe,col:pe,pattern:_.value,type:W})})}),n.executeCommand(w.id,M),t.close()}else _.type==="cancel"&&t.close()},value:{defaultPattern:g,defaultValue:y,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=t.open({header:{title:o.t("sheet.numfmt.title")},children:{label:ne,...h},onClose:()=>{this._forceUpdate(),n.executeCommand(Y.id)}}),!0}_forceUpdate(t){var n;const r=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(x.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[re,ie,se,ue,V,Y,w].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this._componentManager.register(ne,tt)}_initRealTimeRenderingInterceptor(){const t=new O.Observable(n=>{this._commandService.onCommandExecuted(s=>{s.id===V.id&&n.next(!0),s.id===Y.id&&n.next(!1)})}),r=O.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(F.map(n=>n?n.map(s=>s.range):[]))]);this.disposeWithMe(a.toDisposable(r.pipe(F.switchMap(([n,s])=>new O.Observable(i=>{const o=new a.DisposableCollection;return n&&s.length&&i.next({selectionRanges:s,disposableCollection:o}),()=>{o.dispose()}})),F.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:s})=>{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,g=f(l)||{};if(s.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,_=y==null?void 0:y.t;if(h==null||_!==a.CellValueType.NUMBER||this._previewPattern===null)return g;const b=G(this._previewPattern,h,this._localeService.getCurrentLocale());if(b.color){const W=this._themeService.getCurrentTheme()[`${b.color}500`];return{...g,v:b.result,t:a.CellValueType.STRING,s:{cl:{rgb:W}}}}return{...g,v:b.result,t:a.CellValueType.STRING}}return g}})),(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(r=>{const n=this._commandService.onCommandExecuted(s=>{if(t.includes(s.id)){const i=s.params;r.next(i.unitId)}});return()=>n.dispose()}).pipe(F.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};Q=st([a.OnLifecycle(a.LifecycleStages.Rendered,Q),j(0,I.Inject(m.SheetInterceptorService)),j(1,I.Inject(a.ThemeService)),j(2,a.IUniverInstanceService),j(3,a.ICommandService),j(4,I.Inject(m.SelectionManagerService)),j(5,ve.IRenderManagerService),j(6,m.INumfmtService),j(7,I.Inject(T.ComponentManager)),j(8,T.ISidebarService),j(9,I.Inject(a.LocaleService))],Q);var it=Object.defineProperty,at=Object.getOwnPropertyDescriptor,ot=(e,t,r,n)=>{for(var s=n>1?void 0:n?at(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(n?o(t,r,s):o(s))||s);return n&&s&&it(t,r,s),s},$=(e,t)=>(r,n)=>t(r,n,e);const ct=()=>{let e=[];return{add:(s,i,o,c,l)=>e.push({unitId:s,subUnitId:i,row:o,col:c,value:l}),getEffects:()=>e,clean:()=>{e=[]}}};let X=class extends a.Disposable{constructor(t,r,n,s,i){super();te(this,"_collectEffectMutation",ct());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=s,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,r,n)=>{const s=r.row,i=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,s,i);if(o)switch(B(o.pattern)){case"scientific":case"percent":case"currency":case"grouped":case"number":return r.worksheet.getCellRaw(s,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,r,n)=>{var f;this._collectEffectMutation.clean();const s=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),i=(f=s&&B(s.pattern))!=null?f:"",o=()=>{s&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,null)};if(!(t!=null&&t.v))return n(t);const c=String(t.v),l=D.parseDate(c)||D.parseTime(c);if(!!l){if(l&&l.z){const u=Number(l.v);return this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:l.z}),{...t,v:u,t:a.CellValueType.NUMBER}}}else(["date","time","datetime"].includes(i)||!lt(c))&&o();return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case m.SetRangeValuesCommand.id:{const s=t._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),i=s.getUnitId(),o=(n=s.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 g;return!!((g=d.value)!=null&&g.pattern)}).map(d=>({row:d.row,col:d.col,pattern:d.value.pattern})),v=c.filter(d=>{var g;return!((g=d.value)!=null&&g.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:[]}}}))}};X=ot([a.OnLifecycle(a.LifecycleStages.Rendered,X),$(0,I.Inject(m.SheetInterceptorService)),$(1,I.Inject(m.INumfmtService)),$(2,I.Inject(a.IUniverInstanceService)),$(3,I.Inject(I.Injector)),$(4,I.Optional(x.IEditorBridgeService))],X);function lt(e){return/^-?\d+(\.\d+)?$/.test(e)}var ut=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,dt=(e,t,r,n)=>{for(var s=n>1?void 0:n?mt(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(n?o(t,r,s):o(s))||s);return n&&s&&ut(t,r,s),s},ft=(e,t)=>(r,n)=>t(r,n,e);let q=class extends a.Disposable{constructor(e){super(),this._localeService=e}};q=dt([a.OnLifecycle(a.LifecycleStages.Rendered,q),ft(0,I.Inject(a.LocaleService))],q);const ee=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:"@@@"},"|",{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:""}],Ie="sheet.numfmt.moreNumfmtType",Te="sheet.numfmt.moreNumfmtType.options",pt=e=>{var n;const t=E.useDependency(a.LocaleService),r=(n=e.value)!=null?n:t.t("sheet.numfmt.general");return p.jsx("span",{className:"more-numfmt-type",children:r})},vt=()=>{const e=E.useDependency(a.ICommandService),t=E.useDependency(a.LocaleService),r=E.useInjector(),n=E.useDependency(m.SelectionManagerService),s=c=>{const l=n.getLast();if(!l)return;const v=r.get(ve.ITextSelectionRenderManager),f=l.range,u=[];a.Range.foreach(f,(d,g)=>{c?u.push({row:d,col:g,pattern:c,type:B(c)}):u.push({row:d,col:g})}),e.executeCommand(w.id,{values:u}),v.focus()},i=c=>{if(c===0)s(null);else if(c===ee.length-1)e.executeCommand(V.id);else{const l=ee[c];l.pattern&&s(l.pattern)}},o=1220;return p.jsx("div",{className:"more-numfmt-type-options",children:ee.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?G(c.pattern||"",o,t.getCurrentLocale()).result:""})]},l))})},ht=e=>({icon:"RmbSingle",id:se.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$:x.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),St=e=>({icon:"AddDigitsSingle",id:re.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$:x.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),gt=e=>({icon:"ReduceDigitsSingle",id:ie.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$:x.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),_t=e=>({icon:"PercentSingle",id:ue.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$:x.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),yt=e=>{const t=e.get(m.INumfmtService),r=e.get(a.IUniverInstanceService),n=e.get(a.ICommandService),s=e.get(a.LocaleService),i=e.get(m.SelectionManagerService),o=x.deriveStateFromActiveSheet$(r,"",({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(g=>{u.includes(g.id)&&f.next(null)});return()=>d.dispose()})).subscribe(()=>{const f=i.getSelections();if(f&&f[0]){const u=f[0].range,d=u.startRow,g=u.startColumn,y=t.getValue(c.getUnitId(),l.getSheetId(),d,g),h=y==null?void 0:y.pattern;let _=s.t("sheet.numfmt.general");if(h){const b=ee.filter(M=>typeof M=="object"&&M.pattern).find(M=>K(h,M.pattern));b&&typeof b=="object"&&b.pattern?_=s.t(b.label):_=s.t("sheet.numfmt.moreFmt")}v.next(_)}})));return{label:Ie,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:Te,hoverable:!1}}],value$:o,hidden$:T.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:x.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}};var bt=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,It=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ct(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(n?o(t,r,s):o(s))||s);return n&&s&&bt(t,r,s),s},me=(e,t)=>(r,n)=>t(r,n,e);const Tt={};let k=class extends a.Disposable{constructor(e,t,r,n){super(),this._config=e,this._injector=t,this._componentManager=r,this._menuService=n,this._initMenu()}_initMenu(){const{menu:e={}}=this._config;[_t,St,gt,ht,yt].forEach(t=>{this.disposeWithMe(this._menuService.addMenuItem(t(this._injector),e))}),this.disposeWithMe(this._componentManager.register(Ie,pt)),this.disposeWithMe(this._componentManager.register(Te,vt))}};k=It([a.OnLifecycle(a.LifecycleStages.Rendered,k),me(1,I.Inject(I.Injector)),me(2,I.Inject(T.ComponentManager)),me(3,I.Inject(T.IMenuService))],k);var Me=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,Pt=(e,t,r)=>t in e?Me(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Nt=(e,t,r,n)=>{for(var s=n>1?void 0:n?Mt(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(n?o(t,r,s):o(s))||s);return n&&s&&Me(t,r,s),s},Et=(e,t)=>(r,n)=>t(r,n,e),Pe=(e,t,r)=>Pt(e,typeof t!="symbol"?t+"":t,r);S.UniverSheetsNumfmtPlugin=class extends a.Plugin{constructor(t={},r){super(),this._config=t,this._injector=r,this._config=a.Tools.deepMerge({},Tt,this._config)}onStarting(){this._injector.add([ae,{useClass:Q,lazy:!1}]),this._injector.add([X]),this._injector.add([Z]),this._injector.add([z]),this._injector.add([q]),this._injector.add([k,{useFactory:()=>this._injector.createInstance(k,this._config)}])}},Pe(S.UniverSheetsNumfmtPlugin,"pluginName",ne),Pe(S.UniverSheetsNumfmtPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),S.UniverSheetsNumfmtPlugin=Nt([a.DependentOn(m.UniverSheetsPlugin,x.UniverSheetsUIPlugin),Et(1,I.Inject(I.Injector))],S.UniverSheetsNumfmtPlugin),S.AddDecimalCommand=re,S.CloseNumfmtPanelOperator=Y,S.OpenNumfmtPanelOperator=V,S.SetCurrencyCommand=se,S.SetNumfmtCommand=w,S.SetPercentCommand=ue,S.SubtractDecimalCommand=ie,S.getPatternPreview=G,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
|
|
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=E.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=E.useDependency(a.LocaleService).t;e.action.current=()=>N(`_("${r}"* #,##0${t>0?".0":""}_)`,t);const v=u=>{i(u),e.onChange(N(`_("${u}"* #,##0${t>0?".0":""}_)`,t))},f=u=>{const d=u||0;s(d),e.onChange(N(`_("${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=E.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=()=>N(l,o);const d=h=>{if(h===void 0)return;i(h);const C=me(h)[0].value;v(C),e.onChange(N(C,o))},_=h=>{h!==void 0&&(v(h),e.onChange(N(h,o)))},y=h=>{c(h||0),e.onChange(N(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.getInfo(e);return Ce().map(s=>s.value).includes(e)||["date","datetime","time"].includes(t.type)},Ze=e=>{const t=b.useMemo(Ce,[]),n=E.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=E.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=E.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(()=>N(i,Number(n||0)),[i,n]),l=b.useMemo(()=>!je(i),[i]),v=u=>{r(u||0),e.onChange(N(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=E.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.parseDate(c)||j.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=E.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=E.useDependency(a.ICommandService),t=E.useDependency(a.LocaleService),s=E.useInjector(),n=E.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,Nt=(e,t,s)=>t in e?Me(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,Et=(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),Ne=(e,t,s)=>Nt(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)}])}},Ne(g.UniverSheetsNumfmtPlugin,"pluginName",re),Ne(g.UniverSheetsNumfmtPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsNumfmtPlugin=Et([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"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"@wendellhu/redi": "0.15.5",
|
|
54
54
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
55
55
|
"rxjs": ">=7.0.0",
|
|
56
|
-
"@univerjs/core": "0.2.
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/
|
|
56
|
+
"@univerjs/core": "0.2.3",
|
|
57
|
+
"@univerjs/engine-numfmt": "0.2.3",
|
|
58
|
+
"@univerjs/design": "0.2.3",
|
|
59
|
+
"@univerjs/engine-render": "0.2.3",
|
|
60
|
+
"@univerjs/sheets-ui": "0.2.3",
|
|
61
|
+
"@univerjs/ui": "0.2.3",
|
|
62
|
+
"@univerjs/sheets": "0.2.3"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@univerjs/icons": "^0.1.58"
|
|
@@ -73,15 +73,15 @@
|
|
|
73
73
|
"typescript": "^5.5.3",
|
|
74
74
|
"vite": "^5.3.3",
|
|
75
75
|
"vitest": "^1.6.0",
|
|
76
|
-
"@univerjs/core": "0.2.
|
|
77
|
-
"@univerjs/design": "0.2.
|
|
78
|
-
"@univerjs/engine-formula": "0.2.
|
|
79
|
-
"@univerjs/engine-render": "0.2.
|
|
80
|
-
"@univerjs/
|
|
81
|
-
"@univerjs/
|
|
82
|
-
"@univerjs/sheets
|
|
83
|
-
"@univerjs/ui": "0.2.
|
|
84
|
-
"@univerjs/
|
|
76
|
+
"@univerjs/core": "0.2.3",
|
|
77
|
+
"@univerjs/design": "0.2.3",
|
|
78
|
+
"@univerjs/engine-formula": "0.2.3",
|
|
79
|
+
"@univerjs/engine-render": "0.2.3",
|
|
80
|
+
"@univerjs/shared": "0.2.3",
|
|
81
|
+
"@univerjs/engine-numfmt": "0.2.3",
|
|
82
|
+
"@univerjs/sheets": "0.2.3",
|
|
83
|
+
"@univerjs/ui": "0.2.3",
|
|
84
|
+
"@univerjs/sheets-ui": "0.2.3"
|
|
85
85
|
},
|
|
86
86
|
"univerSpace": {
|
|
87
87
|
".": {
|