@univerjs/sheets-numfmt 0.1.13 → 0.1.15

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 CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Re=Object.defineProperty;var Ee=(e,t,r)=>t in e?Re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var U=(e,t,r)=>(Ee(e,typeof t!="symbol"?t+"":t,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),m=require("@univerjs/sheets"),C=require("@wendellhu/redi"),O=require("@univerjs/sheets-ui"),k=require("rxjs/operators"),j=require("@univerjs/engine-numfmt"),fe=require("@univerjs/engine-render"),I=require("@univerjs/ui"),x=require("rxjs"),b=require("react"),E=require("@univerjs/design"),N=require("@wendellhu/redi/react-bindings"),D={id:"sheet.command.numfmt.set.numfmt",type:c.CommandType.COMMAND,handler:(e,t)=>{if(!t)return!1;const r=e.get(c.ICommandService),n=e.get(c.IUniverInstanceService),s=e.get(c.IUndoRedoService),i=m.getSheetCommandTarget(n,t);if(!i)return!1;const{unitId:o,subUnitId:l}=i,u=t.values.filter(p=>!!p.pattern),d=t.values.filter(p=>!p.pattern),h=m.transformCellsToRange(o,l,u),a={unitId:o,subUnitId:l,ranges:d.map(p=>({startColumn:p.col,startRow:p.row,endColumn:p.col,endRow:p.row}))},v=[],y=[];if(u.length){Object.keys(h.values).forEach(S=>{const g=h.values[S];g.ranges=m.rangeMerge(g.ranges)}),v.push({id:m.SetNumfmtMutation.id,params:h});const p=m.factorySetNumfmtUndoMutation(e,h);y.push(...p)}if(d.length){a.ranges=m.rangeMerge(a.ranges),v.push({id:m.RemoveNumfmtMutation.id,params:a});const p=m.factoryRemoveNumfmtUndoMutation(e,a);y.push(...p)}const _=c.sequenceExecute(v,r).result;return _&&s.pushUndoRedo({unitID:o,undoMutations:y,redoMutations:v}),_}},ae="SHEET_NUMFMT_PLUGIN",J=e=>j.getInfo(e).type||"unknown",X=(e,t,r)=>{const n=j.getInfo(e),s=r===c.LocaleType.ZH_CN?"zh-CN":"en",i=n._partitions[1],o=j.format(e,t,{locale:s});return t<0?{result:o,color:i.color}:{result:o}};var Oe=Object.defineProperty,je=Object.getOwnPropertyDescriptor,xe=(e,t,r,n)=>{for(var s=n>1?void 0:n?je(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&&Oe(t,r,s),s},L=(e,t)=>(r,n)=>t(r,n,e);let q=class extends c.Disposable{constructor(e,t,r,n,s,i){super(),this._sheetInterceptorService=e,this._themeService=t,this._sheetSkeletonManagerService=r,this._commandService=n,this._numfmtService=s,this._localeService=i,this._initInterceptorCellContent()}_initInterceptorCellContent(){const e=new c.ObjectMatrix;this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{handler:(t,r,n)=>{const s=r.unitId,i=r.subUnitId,o=this._numfmtService.getValue(s,i,r.row,r.col);if(!o)return n(t);const l=t;if(!l||l.t!==c.CellValueType.NUMBER)return n(t);let u="";const d=e.getValue(r.row,r.col);if(d&&d.parameters===l.v)return n({...t,...d.result});const h=X(o.pattern,Number(l.v),this._localeService.getCurrentLocale());if(u=h.result,!u)return n(t);const a={v:u};if(h.color){const v=this._themeService.getCurrentTheme()[`${h.color}500`];v&&(a.interceptorStyle={cl:{rgb:v}})}return e.setValue(r.row,r.col,{result:a,parameters:l.v}),n({...t,...a})},priority:10})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetNumfmtMutation.id){const r=t.params;Object.keys(r.values).forEach(n=>{r.values[n].ranges.forEach(i=>{c.Range.foreach(i,(o,l)=>{e.realDeleteValue(o,l)})})})}})),this.disposeWithMe(c.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.pipe(k.map(t=>t==null?void 0:t.sheetId),k.distinctUntilChanged()).subscribe(()=>{e.reset()})))}};q=xe([c.OnLifecycle(c.LifecycleStages.Rendered,q),L(0,C.Inject(m.SheetInterceptorService)),L(1,C.Inject(c.ThemeService)),L(2,C.Inject(O.SheetSkeletonManagerService)),L(3,C.Inject(c.ICommandService)),L(4,C.Inject(m.INumfmtService)),L(5,C.Inject(c.LocaleService))],q);const $=(e,t=0)=>{var n;return e&&(n=j.getInfo(e).maxDecimals)!=null?n:t},ee=(e,t)=>{if(e&&!t||!e&&t)return!1;const r=d=>d.reduce((h,a)=>{if(h.isEnd)return h;const v=a.value||a.num;return a.type==="point"?(h.isEnd=!0,h):{...h,result:h.result+v}},{isEnd:!1,result:""}).result,n=j.getInfo(e)._partitions,s=j.getInfo(t)._partitions,i=r(n[0].tokens),o=r(s[0].tokens),l=r(n[1].tokens),u=r(s[1].tokens);return i===o&&l===u&&n[1].color===s[1].color},de=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,t)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${t>0?".":""}${de(Number(t||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${t>0?".":""}${de(Number(t||0))}$1`):n).join(";"),De=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),pe={id:"sheet.command.numfmt.add.decimal.command",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),r=e.get(m.SelectionManagerService),n=e.get(m.INumfmtService),s=e.get(c.IUniverInstanceService),i=r.getSelections();if(!i||!i.length)return!1;const o=m.getSheetCommandTarget(s);if(!o)return!1;const{unitId:l,subUnitId:u}=o;let d=0;i.forEach(y=>{c.Range.foreach(y.range,(_,p)=>{const S=n.getValue(l,u,_,p);if(!S)return;const g=$(S.pattern);d=g>d?g:d})});const h=d+1,a=P(`0${h>0?".0":""}`,h),v=[];return i.forEach(y=>{c.Range.foreach(y.range,(_,p)=>{const S=n.getValue(l,u,_,p);if(!S)v.push({row:_,col:p,pattern:a});else{const g=$(S.pattern),M=P(S.pattern,g+1);M!==S.pattern&&v.push({row:_,col:p,pattern:M})}})}),v.length?await t.executeCommand(D.id,{values:v}):!1}},$e=[{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"}],we=[{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"}],ve=[{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"}],Se={id:"sheet.command.numfmt.set.currency",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),n=e.get(m.SelectionManagerService).getSelections();if(!n||!n.length)return!1;const s=[],i=ve[0].suffix("¥");return n.forEach(l=>{c.Range.foreach(l.range,(u,d)=>{s.push({row:u,col:d,pattern:i,type:"currency"})})}),await t.executeCommand(D.id,{values:s})}},ge={id:"sheet.command.numfmt.subtract.decimal.command",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),r=e.get(m.SelectionManagerService),n=e.get(m.INumfmtService),s=e.get(c.IUniverInstanceService),i=r.getSelections();if(!i||!i.length)return!1;const o=m.getSheetCommandTarget(s);if(!o)return!1;const{unitId:l,subUnitId:u}=o;let d=0;i.forEach(_=>{c.Range.foreach(_.range,(p,S)=>{const g=n.getValue(l,u,p,S);if(!g)return;const M=$(g.pattern);d=M>d?M:d})});const h=d-1,a=P(`0${h>0?".0":"."}`,h),v=[];return i.forEach(_=>{c.Range.foreach(_.range,(p,S)=>{const g=n.getValue(l,u,p,S);if(!g)v.push({row:p,col:S,pattern:a});else{const M=$(g.pattern);v.push({row:p,col:S,pattern:P(g.pattern,M-1)})}})}),await t.executeCommand(D.id,{values:v})}},ie={id:"sheet.operation.close.numfmt.panel",type:c.CommandType.OPERATION,handler:()=>!0},ue=C.createIdentifier("INumfmtController");c.runOnLifecycle(c.LifecycleStages.Rendered,ue);const Z={id:"sheet.operation.open.numfmt.panel",type:c.CommandType.OPERATION,handler:e=>(e.get(ue).openPanel(),!0)};var _e={exports:{}},te={};/**
1
+ "use strict";var Re=Object.defineProperty;var Oe=(e,t,n)=>t in e?Re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var B=(e,t,n)=>(Oe(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),m=require("@univerjs/sheets"),C=require("@wendellhu/redi"),j=require("@univerjs/sheets-ui"),O=require("rxjs"),x=require("@univerjs/engine-numfmt"),de=require("@univerjs/engine-render"),I=require("@univerjs/ui"),k=require("rxjs/operators"),b=require("react"),E=require("@univerjs/design"),N=require("@wendellhu/redi/react-bindings"),$={id:"sheet.command.numfmt.set.numfmt",type:c.CommandType.COMMAND,handler:(e,t)=>{if(!t)return!1;const n=e.get(c.ICommandService),s=e.get(c.IUniverInstanceService),r=e.get(c.IUndoRedoService),i=m.getSheetCommandTarget(s,t);if(!i)return!1;const{unitId:o,subUnitId:l}=i,u=t.values.filter(p=>!!p.pattern),d=t.values.filter(p=>!p.pattern),f=m.transformCellsToRange(o,l,u),a={unitId:o,subUnitId:l,ranges:d.map(p=>({startColumn:p.col,startRow:p.row,endColumn:p.col,endRow:p.row}))},v=[],y=[];if(u.length){Object.keys(f.values).forEach(S=>{const _=f.values[S];_.ranges=m.rangeMerge(_.ranges)}),v.push({id:m.SetNumfmtMutation.id,params:f});const p=m.factorySetNumfmtUndoMutation(e,f);y.push(...p)}if(d.length){a.ranges=m.rangeMerge(a.ranges),v.push({id:m.RemoveNumfmtMutation.id,params:a});const p=m.factoryRemoveNumfmtUndoMutation(e,a);y.push(...p)}const g=c.sequenceExecute(v,n).result;return g&&r.pushUndoRedo({unitID:o,undoMutations:y,redoMutations:v}),g}},oe="SHEET_NUMFMT_PLUGIN",K=e=>x.getInfo(e).type||"unknown",Z=(e,t,n)=>{const s=x.getInfo(e),r=n===c.LocaleType.ZH_CN?"zh-CN":"en",i=s._partitions[1],o=x.format(e,t,{locale:r});return t<0?{result:o,color:i.color}:{result:o}};var je=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,$e=(e,t,n,s)=>{for(var r=s>1?void 0:s?xe(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(s?o(t,n,r):o(r))||r);return s&&r&&je(t,n,r),r},w=(e,t)=>(n,s)=>t(n,s,e);let W=class extends c.Disposable{constructor(e,t,n,s,r,i){super(),this._instanceService=e,this._sheetInterceptorService=t,this._themeService=n,this._commandService=s,this._numfmtService=r,this._localeService=i,this._initInterceptorCellContent()}_initInterceptorCellContent(){const e=new c.ObjectMatrix;this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{handler:(t,n,s)=>{const r=n.unitId,i=n.subUnitId,o=this._numfmtService.getValue(r,i,n.row,n.col);if(!o)return s(t);const l=t;if(!l||l.t!==c.CellValueType.NUMBER)return s(t);let u="";const d=e.getValue(n.row,n.col);if(d&&d.parameters===l.v)return s({...t,...d.result});const f=Z(o.pattern,Number(l.v),this._localeService.getCurrentLocale());if(u=f.result,!u)return s(t);const a={v:u};if(f.color){const v=this._themeService.getCurrentTheme()[`${f.color}500`];v&&(a.interceptorStyle={cl:{rgb:v}})}return e.setValue(n.row,n.col,{result:a,parameters:l.v}),s({...t,...a})},priority:10})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetNumfmtMutation.id){const n=t.params;Object.keys(n.values).forEach(s=>{n.values[s].ranges.forEach(i=>{c.Range.foreach(i,(o,l)=>{e.realDeleteValue(o,l)})})})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(O.switchMap(t=>{var n;return(n=t==null?void 0:t.activeSheet$)!=null?n:O.of(null)}),O.skip(1)).subscribe(()=>e.reset()))}};W=$e([c.OnLifecycle(c.LifecycleStages.Rendered,W),w(0,c.IUniverInstanceService),w(1,C.Inject(m.SheetInterceptorService)),w(2,C.Inject(c.ThemeService)),w(3,C.Inject(c.ICommandService)),w(4,C.Inject(m.INumfmtService)),w(5,C.Inject(c.LocaleService))],W);const D=(e,t=0)=>{var s;return e&&(s=x.getInfo(e).maxDecimals)!=null?s:t},Q=(e,t)=>{if(e&&!t||!e&&t)return!1;const n=d=>d.reduce((f,a)=>{if(f.isEnd)return f;const v=a.value||a.num;return a.type==="point"?(f.isEnd=!0,f):{...f,result:f.result+v}},{isEnd:!1,result:""}).result,s=x.getInfo(e)._partitions,r=x.getInfo(t)._partitions,i=n(s[0].tokens),o=n(r[0].tokens),l=n(s[1].tokens),u=n(r[1].tokens);return i===o&&l===u&&s[1].color===r[1].color},ue=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),P=(e,t)=>e.split(";").map(s=>/\.0?/.test(s)?s.replace(/\.0*/g,`${t>0?".":""}${ue(Number(t||0))}`):/0([^0]?)|0$/.test(s)?s.replace(/0([^0]+)|0$/,`0${t>0?".":""}${ue(Number(t||0))}$1`):s).join(";"),De=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),fe={id:"sheet.command.numfmt.add.decimal.command",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),n=e.get(m.SelectionManagerService),s=e.get(m.INumfmtService),r=e.get(c.IUniverInstanceService),i=n.getSelections();if(!i||!i.length)return!1;const o=m.getSheetCommandTarget(r);if(!o)return!1;const{unitId:l,subUnitId:u}=o;let d=0;i.forEach(y=>{c.Range.foreach(y.range,(g,p)=>{const S=s.getValue(l,u,g,p);if(!S)return;const _=D(S.pattern);d=_>d?_:d})});const f=d+1,a=P(`0${f>0?".0":""}`,f),v=[];return i.forEach(y=>{c.Range.foreach(y.range,(g,p)=>{const S=s.getValue(l,u,g,p);if(!S)v.push({row:g,col:p,pattern:a});else{const _=D(S.pattern),T=P(S.pattern,_+1);T!==S.pattern&&v.push({row:g,col:p,pattern:T})}})}),v.length?await t.executeCommand($.id,{values:v}):!1}},Ue=[{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"}],we=[{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"}],he=[{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"}],pe={id:"sheet.command.numfmt.set.currency",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),s=e.get(m.SelectionManagerService).getSelections();if(!s||!s.length)return!1;const r=[],i=he[0].suffix("¥");return s.forEach(l=>{c.Range.foreach(l.range,(u,d)=>{r.push({row:u,col:d,pattern:i,type:"currency"})})}),await t.executeCommand($.id,{values:r})}},ve={id:"sheet.command.numfmt.subtract.decimal.command",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),n=e.get(m.SelectionManagerService),s=e.get(m.INumfmtService),r=e.get(c.IUniverInstanceService),i=n.getSelections();if(!i||!i.length)return!1;const o=m.getSheetCommandTarget(r);if(!o)return!1;const{unitId:l,subUnitId:u}=o;let d=0;i.forEach(g=>{c.Range.foreach(g.range,(p,S)=>{const _=s.getValue(l,u,p,S);if(!_)return;const T=D(_.pattern);d=T>d?T:d})});const f=d-1,a=P(`0${f>0?".0":"."}`,f),v=[];return i.forEach(g=>{c.Range.foreach(g.range,(p,S)=>{const _=s.getValue(l,u,p,S);if(!_)v.push({row:p,col:S,pattern:a});else{const T=D(_.pattern);v.push({row:p,col:S,pattern:P(_.pattern,T-1)})}})}),await t.executeCommand($.id,{values:v})}},se={id:"sheet.operation.close.numfmt.panel",type:c.CommandType.OPERATION,handler:()=>!0},ae=C.createIdentifier("INumfmtController");c.runOnLifecycle(c.LifecycleStages.Rendered,ae);const Y={id:"sheet.operation.open.numfmt.panel",type:c.CommandType.OPERATION,handler:e=>(e.get(ae).openPanel(),!0)};var Se={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 Ue=b,Le=Symbol.for("react.element"),ke=Symbol.for("react.fragment"),Ae=Object.prototype.hasOwnProperty,Be=Ue.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ve={key:!0,ref:!0,__self:!0,__source:!0};function be(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)Ae.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:Le,type:e,key:i,ref:o,props:s,_owner:Be.current}}te.Fragment=ke;te.jsx=be;te.jsxs=be;_e.exports=te;var f=_e.exports;const me=b.createContext([]),le=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"];var He=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Fe=(e,t,r,n)=>{for(var s=n>1?void 0:n?We(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},qe=(e,t)=>(r,n)=>t(r,n,e);let Q=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,l)=>{const u=l.length;return{value:i,priority:u-o}});return t.sort((i,o)=>{var d,h;const l=((d=s.find(a=>a.value===i))==null?void 0:d.priority)||-1;return(((h=s.find(a=>a.value===o))==null?void 0:h.priority)||-1)-l})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};Q=Fe([qe(0,C.Inject(c.ILocalStorageService))],Q);const he="numfmtCurrency",Ge=e=>{const t=N.useDependency(Q),[r,n]=b.useState(le);return b.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(he,[...le]).then(i=>{n(i),e&&e(i)})})},[]),{userHabitCurrency:r,mark:i=>{t.markHabit(he,i)}}},ze=()=>{const e=b.useRef([]),[t,r]=b.useState({});return b.useEffect(()=>{e.current.forEach(s=>{s()}),e.current=[]},[t]),s=>{e.current.push(s),r({})}},H=e=>le.find(r=>e.includes(r)),Ke=e=>!!H(e)&&e.startsWith("_("),Ye=e=>{const[t,r]=b.useState(()=>$(e.defaultPattern||"",2)),n=b.useContext(me),[s,i]=b.useState(()=>H(e.defaultPattern)||n[0]),o=b.useMemo(()=>n.map(a=>({label:a,value:a})),[]),u=N.useDependency(c.LocaleService).t;e.action.current=()=>P(`_("${s}"* #,##0${t>0?".0":""}_)`,t);const d=a=>{i(a),e.onChange(P(`_("${a}"* #,##0${t>0?".0":""}_)`,t))},h=a=>{const v=a||0;r(v),e.onChange(P(`_("${s}"* #,##0${v>0?".0":""}_)`,v))};return f.jsxs("div",{children:[f.jsxs("div",{className:"m-t-16 options ",children:[f.jsxs("div",{className:"option",children:[f.jsx("div",{className:"label",children:u("sheet.numfmt.decimalLength")}),f.jsx("div",{className:"m-t-8 w-120",children:f.jsx(E.InputNumber,{value:t,max:20,min:0,onChange:h})})]}),f.jsxs("div",{className:"option",children:[f.jsx("div",{className:"label",children:u("sheet.numfmt.currencyType")}),f.jsx("div",{className:"m-t-8 w-140",children:f.jsx(E.Select,{onChange:d,options:o,value:s})})]})]}),f.jsx("div",{className:"describe m-t-14",children:u("sheet.numfmt.accountingDes")})]})},oe=e=>ve.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),ye=()=>$e.map(e=>({label:e.label,value:e.suffix})),Ce=()=>we.map(e=>({label:e.label,value:e.suffix,color:e.color})),Je=e=>!!H(e)&&!e.startsWith("_("),Ze=e=>{const r=N.useDependency(c.LocaleService).t,n=b.useContext(me),[s,i]=b.useState(()=>H(e.defaultPattern)||n[0]),[o,l]=b.useState(()=>$(e.defaultPattern||"",2)),[u,d]=b.useState(()=>{var g;const p=oe(s);return((g=p.find(M=>ee(M.value,e.defaultPattern)))==null?void 0:g.value)||p[0].value}),h=b.useMemo(()=>oe(s),[s]),a=b.useMemo(()=>n.map(p=>({label:p,value:p})),[n]);e.action.current=()=>P(u,o);const v=p=>{i(p);const S=oe(p)[0].value;d(S),e.onChange(P(S,o))},y=p=>{d(p),e.onChange(P(p,o))},_=p=>{l(p||0),e.onChange(P(u,p||0))};return f.jsxs("div",{children:[f.jsxs("div",{className:"m-t-16 options ",children:[f.jsxs("div",{className:"option",children:[f.jsx("div",{className:"label",children:r("sheet.numfmt.decimalLength")}),f.jsx("div",{className:"m-t-8 w-120",children:f.jsx(E.InputNumber,{value:o,max:20,min:0,onChange:_})})]}),f.jsxs("div",{className:"option",children:[f.jsx("div",{className:"label",children:r("sheet.numfmt.currencyType")}),f.jsx("div",{className:"m-t-8 w-140",children:f.jsx(E.Select,{onChange:v,options:a,value:s})})]})]}),f.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.negType")}),f.jsx("div",{className:"m-t-8",children:f.jsx(E.SelectList,{onChange:y,options:h,value:u})}),f.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})},Qe=e=>{const t=j.getInfo(e);return ye().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)},Xe=e=>{const t=b.useMemo(ye,[]),n=N.useDependency(c.LocaleService).t,[s,i]=b.useState(()=>{if(e.defaultPattern){const l=t.find(u=>u.value===e.defaultPattern);if(l)return l.value}return t[0].value});e.action.current=()=>s;const o=l=>{i(l),e.onChange(l)};return f.jsxs("div",{children:[f.jsx("div",{className:"m-t-16 label",children:n("sheet.numfmt.dateType")}),f.jsx("div",{className:"m-t-8",children:f.jsx(E.SelectList,{value:s,options:t,onChange:o})}),f.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},et=e=>!e,tt=e=>{const r=N.useDependency(c.LocaleService).t;return e.action.current=()=>"",f.jsx("div",{children:f.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},nt=e=>Ce().some(t=>ee(t.value,e)),rt=e=>{const t=N.useDependency(c.LocaleService),r=b.useMemo(Ce,[]),[n,s]=b.useState(()=>$(e.defaultPattern||"",0)),[i,o]=b.useState(()=>{const a=r.find(v=>ee(v.value,e.defaultPattern||""));return(a==null?void 0:a.value)||r[0].value}),l=b.useMemo(()=>P(i,Number(n||0)),[i,n]),u=b.useMemo(()=>!De(i),[i]),d=a=>{s(a||0),e.onChange(P(i,Number(a||0)))},h=a=>{s($(a,0)),o(a),e.onChange(a)};return e.action.current=()=>l,f.jsxs("div",{children:[f.jsx("div",{className:"m-t-16 label",children:t.t("sheet.numfmt.decimalLength")}),f.jsx("div",{className:"m-t-8",children:f.jsx(E.InputNumber,{disabled:u,value:n,max:20,min:0,onChange:d})}),f.jsxs("div",{className:"m-t-16 label",children:[" ",t.t("sheet.numfmt.negType")]}),f.jsx("div",{className:"m-t-8",children:f.jsx(E.SelectList,{onChange:h,options:r,value:i})}),f.jsx("div",{className:"describe m-t-14",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})},st=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:s}=e.value,i=N.useDependency(c.LocaleService),o=b.useRef(()=>""),l=i.t,u=ze(),d=b.useMemo(()=>[{label:"sheet.numfmt.general",component:tt},{label:"sheet.numfmt.accounting",component:Ye},{label:"sheet.numfmt.currency",component:Ze},{label:"sheet.numfmt.date",component:Xe},{label:"sheet.numfmt.thousandthPercentile",component:rt}].map(T=>({...T,label:l(T.label)})),[]),[h,a]=b.useState(g),[v,y]=b.useState(()=>`${n}_${s}`),{mark:_,userHabitCurrency:p}=Ge(()=>y(`${n}_${s}_userCurrency'`)),S=b.useMemo(()=>{var T;return(T=d.find(w=>w.label===h))==null?void 0:T.component},[h]);function g(){return[et,Ke,Je,Qe,nt].reduce((w,Pe,Ne)=>w||(Pe(r)?d[Ne].label:""),"")||d[0].label}const M=d.map(T=>({label:T.label,value:T.label})),A=T=>{a(T),u(()=>e.onChange({type:"change",value:o.current()||""}))},W=T=>{e.onChange({type:"change",value:T})},ne=()=>{const T=o.current()||"",w=H(T);w&&_(w),e.onChange({type:"confirm",value:T})},re=()=>{e.onChange({type:"cancel",value:""})},se={onChange:W,defaultValue:t,defaultPattern:r,action:o};return b.useEffect(()=>{a(g()),y(`${n}_${s}`)},[n,s]),f.jsxs("div",{className:"numfmt-panel p-b-20",children:[f.jsxs("div",{children:[f.jsx("div",{className:"label m-t-14",children:l("sheet.numfmt.numfmtType")}),f.jsx("div",{className:"m-t-8",children:f.jsx(E.Select,{onChange:A,options:M,value:h})}),f.jsx("div",{children:S&&f.jsx(me.Provider,{value:p,children:b.createElement(S,{...se,key:v})})})]}),f.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[f.jsx(E.Button,{size:"small",onClick:re,className:"m-r-12",children:l("sheet.numfmt.cancel")}),f.jsx(E.Button,{type:"primary",size:"small",onClick:ne,children:l("sheet.numfmt.confirm")})]})]})},Ie={id:"sheet.command.numfmt.set.percent",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),n=e.get(m.SelectionManagerService).getSelections();if(!n||!n.length)return!1;const s=[],i="0%";return n.forEach(l=>{c.Range.foreach(l.range,(u,d)=>{s.push({row:u,col:d,pattern:i,type:"percent"})})}),await t.executeCommand(D.id,{values:s})}};var it=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,ct=(e,t,r,n)=>{for(var s=n>1?void 0:n?ot(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},R=(e,t)=>(r,n)=>t(r,n,e);let G=class extends c.Disposable{constructor(t,r,n,s,i,o,l,u,d,h,a){super();U(this,"_previewPattern","");U(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._sheetSkeletonManagerService=s,this._commandService=i,this._selectionManagerService=o,this._renderManagerService=l,this._numfmtService=u,this._componentManager=d,this._sidebarService=h,this._localeService=a,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,u=(r.getSelectionRanges()||[])[0];if(!u)return!1;const d=s.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),h=d.getActiveSheet(),a=h.getCellRaw(u.startRow,u.startColumn),v=i.getValue(d.getUnitId(),h.getSheetId(),u.startRow,u.startColumn);let y="";v&&(y=v.pattern);const _=(a==null?void 0:a.t)===c.CellValueType.NUMBER?a.v:12345678,p={onChange:S=>{var g,M;if(S.type==="change")this._previewPattern=S.value,this._sheetSkeletonManagerService.reCalculate(),(M=(g=this._renderManagerService.getRenderById(d.getUnitId()))==null?void 0:g.mainComponent)==null||M.makeDirty();else if(S.type==="confirm"){const A=r.getSelectionRanges()||[],W={values:[]},ne=J(S.value);A.forEach(re=>{c.Range.foreach(re,(se,T)=>{W.values.push({row:se,col:T,pattern:S.value,type:ne})})}),n.executeCommand(D.id,W),t.close()}else S.type==="cancel"&&t.close()},value:{defaultPattern:y,defaultValue:_,row:u.startRow,col:u.startColumn}};return this._sidebarDisposable=t.open({header:{title:o.t("sheet.numfmt.title")},children:{label:ae,...p},onClose:()=>{var S,g;this._sheetSkeletonManagerService.reCalculate(),(g=(S=this._renderManagerService.getRenderById(d.getUnitId()))==null?void 0:S.mainComponent)==null||g.makeDirty(),n.executeCommand(ie.id)}}),!0}_initCommands(){[pe,ge,Se,Ie,Z,ie,D].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this._componentManager.register(ae,st)}_initRealTimeRenderingInterceptor(){const t=new x.Observable(n=>{this._commandService.onCommandExecuted(s=>{s.id===Z.id&&n.next(!0),s.id===ie.id&&n.next(!1)})}),r=x.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(k.map(n=>n?n.map(s=>s.range):[]))]);this.disposeWithMe(c.toDisposable(r.pipe(k.switchMap(([n,s])=>new x.Observable(i=>{const o=new c.DisposableCollection;return n&&s.length&&i.next({selectionRanges:s,disposableCollection:o}),()=>{o.dispose()}})),k.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:s})=>{var o,l;const i=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,handler:(u,d,h)=>{const{row:a,col:v}=d,y=h(u)||{};if(s.find(_=>_.startColumn<=v&&_.endColumn>=v&&_.startRow<=a&&_.endRow>=a)){const _=d.worksheet.getCellRaw(a,v),p=_==null?void 0:_.v,S=_==null?void 0:_.t;if(p==null||S!==c.CellValueType.NUMBER||this._previewPattern===null)return y;const g=X(this._previewPattern,p,this._localeService.getCurrentLocale());if(g.color){const A=this._themeService.getCurrentTheme()[`${g.color}500`];return{...y,v:g.result,t:c.CellValueType.STRING,s:{cl:{rgb:A}}}}return{...y,v:g.result,t:c.CellValueType.STRING}}return y}})),(l=(o=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:o.mainComponent)==null||l.makeDirty()})))}_commandExecutedListener(){const t=[m.RemoveNumfmtMutation.id,m.SetNumfmtMutation.id];this.disposeWithMe(c.toDisposable(x.merge(new x.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(k.debounceTime(16)).subscribe(r=>{var n,s;this._sheetSkeletonManagerService.reCalculate(),(s=(n=this._renderManagerService.getRenderById(r))==null?void 0:n.mainComponent)==null||s.makeDirty()})))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};G=ct([c.OnLifecycle(c.LifecycleStages.Rendered,G),R(0,C.Inject(m.SheetInterceptorService)),R(1,C.Inject(c.ThemeService)),R(2,c.IUniverInstanceService),R(3,C.Inject(O.SheetSkeletonManagerService)),R(4,c.ICommandService),R(5,C.Inject(m.SelectionManagerService)),R(6,fe.IRenderManagerService),R(7,m.INumfmtService),R(8,C.Inject(I.ComponentManager)),R(9,I.ISidebarService),R(10,C.Inject(c.LocaleService))],G);var at=Object.defineProperty,lt=Object.getOwnPropertyDescriptor,ut=(e,t,r,n)=>{for(var s=n>1?void 0:n?lt(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&&at(t,r,s),s},B=(e,t)=>(r,n)=>t(r,n,e);const mt=()=>{let e=[];return{add:(s,i,o,l,u)=>e.push({unitId:s,subUnitId:i,row:o,col:l,value:u}),getEffects:()=>e,clean:()=>{e=[]}}};let z=class extends c.Disposable{constructor(t,r,n,s,i){super();U(this,"_collectEffectMutation",mt());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=s,this._editorBridgeService=i,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this.disposeWithMe(c.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(J(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.disposeWithMe(c.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{handler:(t,r,n)=>{var h;this._collectEffectMutation.clean();const s=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),i=(h=s&&J(s.pattern))!=null?h:"",o=()=>{s&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,null)};if(!(t!=null&&t.v))return n(t);const l=String(t.v),u=j.parseDate(l)||j.parseTime(l);if(!!u){if(u&&u.z){const a=Number(u.v);return this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:u.z}),{...t,v:a,t:c.CellValueType.NUMBER}}}else(["date","time","datetime"].includes(i)||!dt(l))&&o();return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){switch(r.id){case m.SetRangeValuesCommand.id:{const n=t._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),s=n.getUnitId(),i=n.getActiveSheet().getSheetId(),o=t._collectEffectMutation.getEffects();if(!o.length)return{redos:[],undos:[]};const l=o.filter(a=>{var v;return!!((v=a.value)!=null&&v.pattern)}).map(a=>({row:a.row,col:a.col,pattern:a.value.pattern})),u=o.filter(a=>{var v;return!((v=a.value)!=null&&v.pattern)}).map(a=>({startRow:a.row,endColumn:a.col,startColumn:a.col,endRow:a.row})),d=[],h=[];if(l){const a={id:m.SetNumfmtMutation.id,params:m.transformCellsToRange(s,i,l)};d.push(a),h.push(...m.factorySetNumfmtUndoMutation(t._injector,a.params))}if(u){const a={id:m.RemoveNumfmtMutation.id,params:{unitId:s,subUnitId:i,ranges:u}};d.push(a),h.push(...m.factoryRemoveNumfmtUndoMutation(t._injector,a.params))}return{redos:d,undos:h.reverse()}}}return{redos:[],undos:[]}}}))}};z=ut([c.OnLifecycle(c.LifecycleStages.Rendered,z),B(0,C.Inject(m.SheetInterceptorService)),B(1,C.Inject(m.INumfmtService)),B(2,C.Inject(c.IUniverInstanceService)),B(3,C.Inject(C.Injector)),B(4,C.Inject(O.IEditorBridgeService))],z);function dt(e){return/^-?\d+(\.\d+)?$/.test(e)}var ht=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,pt=(e,t,r,n)=>{for(var s=n>1?void 0:n?ft(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&&ht(t,r,s),s},vt=(e,t)=>(r,n)=>t(r,n,e);let K=class extends c.Disposable{constructor(e){super(),this._localeService=e}};K=pt([c.OnLifecycle(c.LifecycleStages.Rendered,K),vt(0,C.Inject(c.LocaleService))],K);const Y=[{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:""}],Me="sheet.numfmt.moreNumfmtType",Te="sheet.numfmt.moreNumfmtType.options",St=e=>{var n;const t=N.useDependency(c.LocaleService),r=(n=e.value)!=null?n:t.t("sheet.numfmt.general");return f.jsx("span",{className:"more-numfmt-type",children:r})},gt=()=>{const e=N.useDependency(c.ICommandService),t=N.useDependency(c.LocaleService),r=N.useInjector(),n=N.useDependency(m.SelectionManagerService),s=l=>{const u=n.getLast();if(!u)return;const d=r.get(fe.ITextSelectionRenderManager),h=u.range,a=[];c.Range.foreach(h,(v,y)=>{l?a.push({row:v,col:y,pattern:l,type:J(l)}):a.push({row:v,col:y})}),e.executeCommand(D.id,{values:a}),d.focus()},i=l=>{if(l===0)s(null);else if(l===Y.length-1)e.executeCommand(Z.id);else{const u=Y[l];u.pattern&&s(u.pattern)}},o=1220;return f.jsx("div",{className:"more-numfmt-type-options",children:Y.map((l,u)=>l==="|"?f.jsx("div",{className:"line m-t-4",onClick:d=>d.stopPropagation()},u):f.jsxs("div",{className:"option-item m-t-4",onClick:()=>{i(u)},children:[f.jsx("div",{children:t.t(l.label)}),f.jsx("div",{className:"m-l-26",children:l.pattern?X(l.pattern||"",o,t.getCurrentLocale()).result:""})]},u))})},_t=e=>({icon:"RmbSingle",id:Se.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:I.MenuItemType.BUTTON,group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[I.MenuPosition.TOOLBAR_START],hidden$:I.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:O.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),bt=e=>({icon:"AddDigitsSingle",id:pe.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:I.MenuItemType.BUTTON,positions:[I.MenuPosition.TOOLBAR_START],group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,hidden$:I.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:O.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),yt=e=>({icon:"ReduceDigitsSingle",id:ge.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:I.MenuItemType.BUTTON,group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[I.MenuPosition.TOOLBAR_START],hidden$:I.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:O.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),Ct=e=>({icon:"PercentSingle",id:Ie.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:I.MenuItemType.BUTTON,group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[I.MenuPosition.TOOLBAR_START],hidden$:I.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:O.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),It=e=>{const t=e.get(m.INumfmtService),r=e.get(c.IUniverInstanceService),n=e.get(c.ICommandService),s=e.get(c.LocaleService),i=e.get(m.SelectionManagerService),o=O.deriveStateFromActiveSheet$(r,"",({workbook:l,worksheet:u})=>new x.Observable(d=>x.merge(i.selectionMoveEnd$,new x.Observable(h=>{const a=[m.RemoveNumfmtMutation.id,m.SetNumfmtMutation.id],v=n.onCommandExecuted(y=>{a.includes(y.id)&&h.next(null)});return()=>v.dispose()})).subscribe(()=>{const h=i.getSelections();if(h&&h[0]){const a=h[0].range,v=a.startRow,y=a.startColumn,_=t.getValue(l.getUnitId(),u.getSheetId(),v,y),p=_==null?void 0:_.pattern;let S=s.t("sheet.numfmt.general");if(p){const g=Y.filter(M=>typeof M=="object"&&M.pattern).find(M=>ee(p,M.pattern));g&&typeof g=="object"&&g.pattern?S=s.t(g.label):S=s.t("sheet.numfmt.moreFmt")}d.next(S)}})));return{label:Me,id:Z.id,tooltip:"sheet.numfmt.title",type:I.MenuItemType.SELECTOR,group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[I.MenuPosition.TOOLBAR_START],selections:[{label:{name:Te,hoverable:!1}}],value$:o,hidden$:I.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:O.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}};var Mt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,Pt=(e,t,r,n)=>{for(var s=n>1?void 0:n?Tt(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&&Mt(t,r,s),s},ce=(e,t)=>(r,n)=>t(r,n,e);const Nt={};let V=class extends c.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;[Ct,bt,yt,_t,It].forEach(t=>{this.disposeWithMe(this._menuService.addMenuItem(t(this._injector),e))}),this.disposeWithMe(this._componentManager.register(Me,St)),this.disposeWithMe(this._componentManager.register(Te,gt))}};V=Pt([c.OnLifecycle(c.LifecycleStages.Rendered,V),ce(1,C.Inject(C.Injector)),ce(2,C.Inject(I.ComponentManager)),ce(3,C.Inject(I.IMenuService))],V);var Rt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,Ot=(e,t,r,n)=>{for(var s=n>1?void 0:n?Et(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&&Rt(t,r,s),s},jt=(e,t)=>(r,n)=>t(r,n,e),F;exports.UniverSheetsNumfmtPlugin=(F=class extends c.Plugin{constructor(t={},r){super(),this._config=t,this._injector=r,this._config=c.Tools.deepMerge({},Nt,this._config)}onStarting(){this._injector.add([ue,{useClass:G,lazy:!1}]),this._injector.add([z]),this._injector.add([Q]),this._injector.add([q]),this._injector.add([K]),this._injector.add([V,{useFactory:()=>this._injector.createInstance(V,this._config)}])}},U(F,"pluginName",ae),U(F,"type",c.UniverInstanceType.UNIVER_SHEET),F);exports.UniverSheetsNumfmtPlugin=Ot([jt(1,C.Inject(C.Injector))],exports.UniverSheetsNumfmtPlugin);exports.SetNumfmtCommand=D;exports.getPatternPreview=X;
9
+ */var Le=b,Ae=Symbol.for("react.element"),Ve=Symbol.for("react.fragment"),He=Object.prototype.hasOwnProperty,Be=Le.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ke={key:!0,ref:!0,__self:!0,__source:!0};function ge(e,t,n){var s,r={},i=null,o=null;n!==void 0&&(i=""+n),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(o=t.ref);for(s in t)He.call(t,s)&&!ke.hasOwnProperty(s)&&(r[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps,t)r[s]===void 0&&(r[s]=t[s]);return{$$typeof:Ae,type:e,key:i,ref:o,props:r,_owner:Be.current}}X.Fragment=Ve;X.jsx=ge;X.jsxs=ge;Se.exports=X;var h=Se.exports;const le=b.createContext([]),ce=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"];var We=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,qe=(e,t,n,s)=>{for(var r=s>1?void 0:s?Fe(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(s?o(t,n,r):o(r))||r);return s&&r&&We(t,n,r),r},Ge=(e,t)=>(n,s)=>t(n,s,e);let J=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const n=this._getKey(e);return this._localStorageService.getItem(n).then(s=>{s||this._localStorageService.setItem(n,t)})}markHabit(e,t){const n=this._getKey(e);this._localStorageService.getItem(n).then(s=>{if(s){const r=s.findIndex(i=>i===t);r>-1&&s.splice(r,1),s.unshift(t),this._localStorageService.setItem(n,s)}})}async getHabit(e,t){const n=this._getKey(e),s=await this._localStorageService.getItem(n);if(t&&s){const r=s.map((i,o,l)=>{const u=l.length;return{value:i,priority:u-o}});return t.sort((i,o)=>{var d,f;const l=((d=r.find(a=>a.value===i))==null?void 0:d.priority)||-1;return(((f=r.find(a=>a.value===o))==null?void 0:f.priority)||-1)-l})}return s||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};J=qe([Ge(0,C.Inject(c.ILocalStorageService))],J);const me="numfmtCurrency",ze=e=>{const t=N.useDependency(J),[n,s]=b.useState(ce);return b.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(me,[...ce]).then(i=>{s(i),e&&e(i)})})},[]),{userHabitCurrency:n,mark:i=>{t.markHabit(me,i)}}},Ke=()=>{const e=b.useRef([]),[t,n]=b.useState({});return b.useEffect(()=>{e.current.forEach(r=>{r()}),e.current=[]},[t]),r=>{e.current.push(r),n({})}},H=e=>ce.find(n=>e.includes(n)),Ye=e=>!!H(e)&&e.startsWith("_("),Je=e=>{const[t,n]=b.useState(()=>D(e.defaultPattern||"",2)),s=b.useContext(le),[r,i]=b.useState(()=>H(e.defaultPattern)||s[0]),o=b.useMemo(()=>s.map(a=>({label:a,value:a})),[]),u=N.useDependency(c.LocaleService).t;e.action.current=()=>P(`_("${r}"* #,##0${t>0?".0":""}_)`,t);const d=a=>{i(a),e.onChange(P(`_("${a}"* #,##0${t>0?".0":""}_)`,t))},f=a=>{const v=a||0;n(v),e.onChange(P(`_("${r}"* #,##0${v>0?".0":""}_)`,v))};return h.jsxs("div",{children:[h.jsxs("div",{className:"m-t-16 options ",children:[h.jsxs("div",{className:"option",children:[h.jsx("div",{className:"label",children:u("sheet.numfmt.decimalLength")}),h.jsx("div",{className:"m-t-8 w-120",children:h.jsx(E.InputNumber,{value:t,max:20,min:0,onChange:f})})]}),h.jsxs("div",{className:"option",children:[h.jsx("div",{className:"label",children:u("sheet.numfmt.currencyType")}),h.jsx("div",{className:"m-t-8 w-140",children:h.jsx(E.Select,{onChange:d,options:o,value:r})})]})]}),h.jsx("div",{className:"describe m-t-14",children:u("sheet.numfmt.accountingDes")})]})},re=e=>he.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),_e=()=>Ue.map(e=>({label:e.label,value:e.suffix})),be=()=>we.map(e=>({label:e.label,value:e.suffix,color:e.color})),Ze=e=>!!H(e)&&!e.startsWith("_("),Qe=e=>{const n=N.useDependency(c.LocaleService).t,s=b.useContext(le),[r,i]=b.useState(()=>H(e.defaultPattern)||s[0]),[o,l]=b.useState(()=>D(e.defaultPattern||"",2)),[u,d]=b.useState(()=>{var _;const p=re(r);return((_=p.find(T=>Q(T.value,e.defaultPattern)))==null?void 0:_.value)||p[0].value}),f=b.useMemo(()=>re(r),[r]),a=b.useMemo(()=>s.map(p=>({label:p,value:p})),[s]);e.action.current=()=>P(u,o);const v=p=>{i(p);const S=re(p)[0].value;d(S),e.onChange(P(S,o))},y=p=>{d(p),e.onChange(P(p,o))},g=p=>{l(p||0),e.onChange(P(u,p||0))};return h.jsxs("div",{children:[h.jsxs("div",{className:"m-t-16 options ",children:[h.jsxs("div",{className:"option",children:[h.jsx("div",{className:"label",children:n("sheet.numfmt.decimalLength")}),h.jsx("div",{className:"m-t-8 w-120",children:h.jsx(E.InputNumber,{value:o,max:20,min:0,onChange:g})})]}),h.jsxs("div",{className:"option",children:[h.jsx("div",{className:"label",children:n("sheet.numfmt.currencyType")}),h.jsx("div",{className:"m-t-8 w-140",children:h.jsx(E.Select,{onChange:v,options:a,value:r})})]})]}),h.jsx("div",{className:"m-t-16 label",children:n("sheet.numfmt.negType")}),h.jsx("div",{className:"m-t-8",children:h.jsx(E.SelectList,{onChange:y,options:f,value:u})}),h.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.currencyDes")})]})},Xe=e=>{const t=x.getInfo(e);return _e().map(n=>n.value).includes(e)||["date","datetime","time"].includes(t.type)},et=e=>{const t=b.useMemo(_e,[]),s=N.useDependency(c.LocaleService).t,[r,i]=b.useState(()=>{if(e.defaultPattern){const l=t.find(u=>u.value===e.defaultPattern);if(l)return l.value}return t[0].value});e.action.current=()=>r;const o=l=>{i(l),e.onChange(l)};return h.jsxs("div",{children:[h.jsx("div",{className:"m-t-16 label",children:s("sheet.numfmt.dateType")}),h.jsx("div",{className:"m-t-8",children:h.jsx(E.SelectList,{value:r,options:t,onChange:o})}),h.jsx("div",{className:"describe m-t-14",children:s("sheet.numfmt.dateDes")})]})},tt=e=>!e,nt=e=>{const n=N.useDependency(c.LocaleService).t;return e.action.current=()=>"",h.jsx("div",{children:h.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.generalDes")})})},st=e=>be().some(t=>Q(t.value,e)),rt=e=>{const t=N.useDependency(c.LocaleService),n=b.useMemo(be,[]),[s,r]=b.useState(()=>D(e.defaultPattern||"",0)),[i,o]=b.useState(()=>{const a=n.find(v=>Q(v.value,e.defaultPattern||""));return(a==null?void 0:a.value)||n[0].value}),l=b.useMemo(()=>P(i,Number(s||0)),[i,s]),u=b.useMemo(()=>!De(i),[i]),d=a=>{r(a||0),e.onChange(P(i,Number(a||0)))},f=a=>{r(D(a,0)),o(a),e.onChange(a)};return e.action.current=()=>l,h.jsxs("div",{children:[h.jsx("div",{className:"m-t-16 label",children:t.t("sheet.numfmt.decimalLength")}),h.jsx("div",{className:"m-t-8",children:h.jsx(E.InputNumber,{disabled:u,value:s,max:20,min:0,onChange:d})}),h.jsxs("div",{className:"m-t-16 label",children:[" ",t.t("sheet.numfmt.negType")]}),h.jsx("div",{className:"m-t-8",children:h.jsx(E.SelectList,{onChange:f,options:n,value:i})}),h.jsx("div",{className:"describe m-t-14",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})},it=e=>{const{defaultValue:t,defaultPattern:n,row:s,col:r}=e.value,i=N.useDependency(c.LocaleService),o=b.useRef(()=>""),l=i.t,u=Ke(),d=b.useMemo(()=>[{label:"sheet.numfmt.general",component:nt},{label:"sheet.numfmt.accounting",component:Je},{label:"sheet.numfmt.currency",component:Qe},{label:"sheet.numfmt.date",component:et},{label:"sheet.numfmt.thousandthPercentile",component:rt}].map(M=>({...M,label:l(M.label)})),[]),[f,a]=b.useState(_),[v,y]=b.useState(()=>`${s}_${r}`),{mark:g,userHabitCurrency:p}=ze(()=>y(`${s}_${r}_userCurrency'`)),S=b.useMemo(()=>{var M;return(M=d.find(U=>U.label===f))==null?void 0:M.component},[f]);function _(){return[tt,Ye,Ze,Xe,st].reduce((U,Ne,Ee)=>U||(Ne(n)?d[Ee].label:""),"")||d[0].label}const T=d.map(M=>({label:M.label,value:M.label})),L=M=>{a(M),u(()=>e.onChange({type:"change",value:o.current()||""}))},ee=M=>{e.onChange({type:"change",value:M})},te=()=>{const M=o.current()||"",U=H(M);U&&g(U),e.onChange({type:"confirm",value:M})},ne=()=>{e.onChange({type:"cancel",value:""})},Pe={onChange:ee,defaultValue:t,defaultPattern:n,action:o};return b.useEffect(()=>{a(_()),y(`${s}_${r}`)},[s,r]),h.jsxs("div",{className:"numfmt-panel p-b-20",children:[h.jsxs("div",{children:[h.jsx("div",{className:"label m-t-14",children:l("sheet.numfmt.numfmtType")}),h.jsx("div",{className:"m-t-8",children:h.jsx(E.Select,{onChange:L,options:T,value:f})}),h.jsx("div",{children:S&&h.jsx(le.Provider,{value:p,children:b.createElement(S,{...Pe,key:v})})})]}),h.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[h.jsx(E.Button,{size:"small",onClick:ne,className:"m-r-12",children:l("sheet.numfmt.cancel")}),h.jsx(E.Button,{type:"primary",size:"small",onClick:te,children:l("sheet.numfmt.confirm")})]})]})},ye={id:"sheet.command.numfmt.set.percent",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),s=e.get(m.SelectionManagerService).getSelections();if(!s||!s.length)return!1;const r=[],i="0%";return s.forEach(l=>{c.Range.foreach(l.range,(u,d)=>{r.push({row:u,col:d,pattern:i,type:"percent"})})}),await t.executeCommand($.id,{values:r})}};var ot=Object.defineProperty,ct=Object.getOwnPropertyDescriptor,at=(e,t,n,s)=>{for(var r=s>1?void 0:s?ct(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(s?o(t,n,r):o(r))||r);return s&&r&&ot(t,n,r),r},R=(e,t)=>(n,s)=>t(n,s,e);let F=class extends c.Disposable{constructor(t,n,s,r,i,o,l,u,d,f){super();B(this,"_previewPattern","");B(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=n,this._univerInstanceService=s,this._commandService=r,this._selectionManagerService=i,this._renderManagerService=o,this._numfmtService=l,this._componentManager=u,this._sidebarService=d,this._localeService=f,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){const t=this._sidebarService,n=this._selectionManagerService,s=this._commandService,r=this._univerInstanceService,i=this._numfmtService,o=this._localeService,u=(n.getSelectionRanges()||[])[0];if(!u)return!1;const d=r.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),f=d.getActiveSheet(),a=f.getCellRaw(u.startRow,u.startColumn),v=i.getValue(d.getUnitId(),f.getSheetId(),u.startRow,u.startColumn);let y="";v&&(y=v.pattern);const g=(a==null?void 0:a.t)===c.CellValueType.NUMBER?a.v:12345678,p={onChange:S=>{if(S.type==="change")this._previewPattern=S.value,this._forceUpdate();else if(S.type==="confirm"){const _=n.getSelectionRanges()||[],T={values:[]},L=K(S.value);_.forEach(ee=>{c.Range.foreach(ee,(te,ne)=>{T.values.push({row:te,col:ne,pattern:S.value,type:L})})}),s.executeCommand($.id,T),t.close()}else S.type==="cancel"&&t.close()},value:{defaultPattern:y,defaultValue:g,row:u.startRow,col:u.startColumn}};return this._sidebarDisposable=t.open({header:{title:o.t("sheet.numfmt.title")},children:{label:oe,...p},onClose:()=>{this._forceUpdate(),s.executeCommand(se.id)}}),!0}_forceUpdate(t){var s;const n=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET).getUnitId());n==null||n.with(j.SheetSkeletonManagerService).reCalculate(),(s=n==null?void 0:n.mainComponent)==null||s.makeDirty()}_initCommands(){[fe,ve,pe,ye,Y,se,$].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this._componentManager.register(oe,it)}_initRealTimeRenderingInterceptor(){const t=new O.Observable(s=>{this._commandService.onCommandExecuted(r=>{r.id===Y.id&&s.next(!0),r.id===se.id&&s.next(!1)})}),n=O.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(k.map(s=>s?s.map(r=>r.range):[]))]);this.disposeWithMe(c.toDisposable(n.pipe(k.switchMap(([s,r])=>new O.Observable(i=>{const o=new c.DisposableCollection;return s&&r.length&&i.next({selectionRanges:r,disposableCollection:o}),()=>{o.dispose()}})),k.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:s,selectionRanges:r})=>{var o,l;const i=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);this.openPanel(),s.add(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,handler:(u,d,f)=>{const{row:a,col:v}=d,y=f(u)||{};if(r.find(g=>g.startColumn<=v&&g.endColumn>=v&&g.startRow<=a&&g.endRow>=a)){const g=d.worksheet.getCellRaw(a,v),p=g==null?void 0:g.v,S=g==null?void 0:g.t;if(p==null||S!==c.CellValueType.NUMBER||this._previewPattern===null)return y;const _=Z(this._previewPattern,p,this._localeService.getCurrentLocale());if(_.color){const L=this._themeService.getCurrentTheme()[`${_.color}500`];return{...y,v:_.result,t:c.CellValueType.STRING,s:{cl:{rgb:L}}}}return{...y,v:_.result,t:c.CellValueType.STRING}}return y}})),(l=(o=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:o.mainComponent)==null||l.makeDirty()})))}_commandExecutedListener(){const t=[m.RemoveNumfmtMutation.id,m.SetNumfmtMutation.id];this.disposeWithMe(new O.Observable(n=>{const s=this._commandService.onCommandExecuted(r=>{if(t.includes(r.id)){const i=r.params;n.next(i.unitId)}});return()=>s.dispose()}).pipe(k.debounceTime(16)).subscribe(n=>this._forceUpdate(n)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var n;t||((n=this._sidebarDisposable)==null||n.dispose(),this._sidebarDisposable=null)})}};F=at([c.OnLifecycle(c.LifecycleStages.Rendered,F),R(0,C.Inject(m.SheetInterceptorService)),R(1,C.Inject(c.ThemeService)),R(2,c.IUniverInstanceService),R(3,c.ICommandService),R(4,C.Inject(m.SelectionManagerService)),R(5,de.IRenderManagerService),R(6,m.INumfmtService),R(7,C.Inject(I.ComponentManager)),R(8,I.ISidebarService),R(9,C.Inject(c.LocaleService))],F);var lt=Object.defineProperty,ut=Object.getOwnPropertyDescriptor,mt=(e,t,n,s)=>{for(var r=s>1?void 0:s?ut(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(s?o(t,n,r):o(r))||r);return s&&r&&lt(t,n,r),r},A=(e,t)=>(n,s)=>t(n,s,e);const dt=()=>{let e=[];return{add:(r,i,o,l,u)=>e.push({unitId:r,subUnitId:i,row:o,col:l,value:u}),getEffects:()=>e,clean:()=>{e=[]}}};let q=class extends c.Disposable{constructor(t,n,s,r,i){super();B(this,"_collectEffectMutation",dt());this._sheetInterceptorService=t,this._numfmtService=n,this._univerInstanceService=s,this._injector=r,this._editorBridgeService=i,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this.disposeWithMe(c.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{handler:(t,n,s)=>{const r=n.row,i=n.col,o=this._numfmtService.getValue(n.unitId,n.subUnitId,r,i);if(o)switch(K(o.pattern)){case"scientific":case"percent":case"currency":case"grouped":case"number":return n.worksheet.getCellRaw(r,i);case"date":case"time":case"datetime":default:return s&&s(t)}return s(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(c.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{handler:(t,n,s)=>{var f;this._collectEffectMutation.clean();const r=this._numfmtService.getValue(n.unitId,n.subUnitId,n.row,n.col),i=(f=r&&K(r.pattern))!=null?f:"",o=()=>{r&&this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,null)};if(!(t!=null&&t.v))return s(t);const l=String(t.v),u=x.parseDate(l)||x.parseTime(l);if(!!u){if(u&&u.z){const a=Number(u.v);return this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,{pattern:u.z}),{...t,v:a,t:c.CellValueType.NUMBER}}}else(["date","time","datetime"].includes(i)||!ft(l))&&o();return s(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(n){switch(n.id){case m.SetRangeValuesCommand.id:{const s=t._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),r=s.getUnitId(),i=s.getActiveSheet().getSheetId(),o=t._collectEffectMutation.getEffects();if(!o.length)return{redos:[],undos:[]};const l=o.filter(a=>{var v;return!!((v=a.value)!=null&&v.pattern)}).map(a=>({row:a.row,col:a.col,pattern:a.value.pattern})),u=o.filter(a=>{var v;return!((v=a.value)!=null&&v.pattern)}).map(a=>({startRow:a.row,endColumn:a.col,startColumn:a.col,endRow:a.row})),d=[],f=[];if(l){const a={id:m.SetNumfmtMutation.id,params:m.transformCellsToRange(r,i,l)};d.push(a),f.push(...m.factorySetNumfmtUndoMutation(t._injector,a.params))}if(u){const a={id:m.RemoveNumfmtMutation.id,params:{unitId:r,subUnitId:i,ranges:u}};d.push(a),f.push(...m.factoryRemoveNumfmtUndoMutation(t._injector,a.params))}return{redos:d,undos:f.reverse()}}}return{redos:[],undos:[]}}}))}};q=mt([c.OnLifecycle(c.LifecycleStages.Rendered,q),A(0,C.Inject(m.SheetInterceptorService)),A(1,C.Inject(m.INumfmtService)),A(2,C.Inject(c.IUniverInstanceService)),A(3,C.Inject(C.Injector)),A(4,C.Inject(j.IEditorBridgeService))],q);function ft(e){return/^-?\d+(\.\d+)?$/.test(e)}var ht=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,vt=(e,t,n,s)=>{for(var r=s>1?void 0:s?pt(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(s?o(t,n,r):o(r))||r);return s&&r&&ht(t,n,r),r},St=(e,t)=>(n,s)=>t(n,s,e);let G=class extends c.Disposable{constructor(e){super(),this._localeService=e}};G=vt([c.OnLifecycle(c.LifecycleStages.Rendered,G),St(0,C.Inject(c.LocaleService))],G);const z=[{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:""}],Ce="sheet.numfmt.moreNumfmtType",Ie="sheet.numfmt.moreNumfmtType.options",gt=e=>{var s;const t=N.useDependency(c.LocaleService),n=(s=e.value)!=null?s:t.t("sheet.numfmt.general");return h.jsx("span",{className:"more-numfmt-type",children:n})},_t=()=>{const e=N.useDependency(c.ICommandService),t=N.useDependency(c.LocaleService),n=N.useInjector(),s=N.useDependency(m.SelectionManagerService),r=l=>{const u=s.getLast();if(!u)return;const d=n.get(de.ITextSelectionRenderManager),f=u.range,a=[];c.Range.foreach(f,(v,y)=>{l?a.push({row:v,col:y,pattern:l,type:K(l)}):a.push({row:v,col:y})}),e.executeCommand($.id,{values:a}),d.focus()},i=l=>{if(l===0)r(null);else if(l===z.length-1)e.executeCommand(Y.id);else{const u=z[l];u.pattern&&r(u.pattern)}},o=1220;return h.jsx("div",{className:"more-numfmt-type-options",children:z.map((l,u)=>l==="|"?h.jsx("div",{className:"line m-t-4",onClick:d=>d.stopPropagation()},u):h.jsxs("div",{className:"option-item m-t-4",onClick:()=>{i(u)},children:[h.jsx("div",{children:t.t(l.label)}),h.jsx("div",{className:"m-l-26",children:l.pattern?Z(l.pattern||"",o,t.getCurrentLocale()).result:""})]},u))})},bt=e=>({icon:"RmbSingle",id:pe.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:I.MenuItemType.BUTTON,group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[I.MenuPosition.TOOLBAR_START],hidden$:I.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),yt=e=>({icon:"AddDigitsSingle",id:fe.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:I.MenuItemType.BUTTON,positions:[I.MenuPosition.TOOLBAR_START],group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,hidden$:I.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),Ct=e=>({icon:"ReduceDigitsSingle",id:ve.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:I.MenuItemType.BUTTON,group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[I.MenuPosition.TOOLBAR_START],hidden$:I.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),It=e=>({icon:"PercentSingle",id:ye.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:I.MenuItemType.BUTTON,group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[I.MenuPosition.TOOLBAR_START],hidden$:I.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}),Tt=e=>{const t=e.get(m.INumfmtService),n=e.get(c.IUniverInstanceService),s=e.get(c.ICommandService),r=e.get(c.LocaleService),i=e.get(m.SelectionManagerService),o=j.deriveStateFromActiveSheet$(n,"",({workbook:l,worksheet:u})=>new O.Observable(d=>O.merge(i.selectionMoveEnd$,new O.Observable(f=>{const a=[m.RemoveNumfmtMutation.id,m.SetNumfmtMutation.id],v=s.onCommandExecuted(y=>{a.includes(y.id)&&f.next(null)});return()=>v.dispose()})).subscribe(()=>{const f=i.getSelections();if(f&&f[0]){const a=f[0].range,v=a.startRow,y=a.startColumn,g=t.getValue(l.getUnitId(),u.getSheetId(),v,y),p=g==null?void 0:g.pattern;let S=r.t("sheet.numfmt.general");if(p){const _=z.filter(T=>typeof T=="object"&&T.pattern).find(T=>Q(p,T.pattern));_&&typeof _=="object"&&_.pattern?S=r.t(_.label):S=r.t("sheet.numfmt.moreFmt")}d.next(S)}})));return{label:Ce,id:Y.id,tooltip:"sheet.numfmt.title",type:I.MenuItemType.SELECTOR,group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[I.MenuPosition.TOOLBAR_START],selections:[{label:{name:Ie,hoverable:!1}}],value$:o,hidden$:I.getMenuHiddenObservable(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(e,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}};var Mt=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,Nt=(e,t,n,s)=>{for(var r=s>1?void 0:s?Pt(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(s?o(t,n,r):o(r))||r);return s&&r&&Mt(t,n,r),r},ie=(e,t)=>(n,s)=>t(n,s,e);const Et={};let V=class extends c.Disposable{constructor(e,t,n,s){super(),this._config=e,this._injector=t,this._componentManager=n,this._menuService=s,this._initMenu()}_initMenu(){const{menu:e={}}=this._config;[It,yt,Ct,bt,Tt].forEach(t=>{this.disposeWithMe(this._menuService.addMenuItem(t(this._injector),e))}),this.disposeWithMe(this._componentManager.register(Ce,gt)),this.disposeWithMe(this._componentManager.register(Ie,_t))}};V=Nt([c.OnLifecycle(c.LifecycleStages.Rendered,V),ie(1,C.Inject(C.Injector)),ie(2,C.Inject(I.ComponentManager)),ie(3,C.Inject(I.IMenuService))],V);var Te=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,Ot=(e,t,n)=>t in e?Te(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jt=(e,t,n,s)=>{for(var r=s>1?void 0:s?Rt(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(r=(s?o(t,n,r):o(r))||r);return s&&r&&Te(t,n,r),r},xt=(e,t)=>(n,s)=>t(n,s,e),Me=(e,t,n)=>(Ot(e,typeof t!="symbol"?t+"":t,n),n);exports.UniverSheetsNumfmtPlugin=class extends c.Plugin{constructor(t={},n){super(),this._config=t,this._injector=n,this._config=c.Tools.deepMerge({},Et,this._config)}onStarting(){this._injector.add([ae,{useClass:F,lazy:!1}]),this._injector.add([q]),this._injector.add([J]),this._injector.add([W]),this._injector.add([G]),this._injector.add([V,{useFactory:()=>this._injector.createInstance(V,this._config)}])}};Me(exports.UniverSheetsNumfmtPlugin,"pluginName",oe);Me(exports.UniverSheetsNumfmtPlugin,"type",c.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=jt([c.DependentOn(m.UniverSheetsPlugin,j.UniverSheetsUIPlugin),xt(1,C.Inject(C.Injector))],exports.UniverSheetsNumfmtPlugin);exports.SetNumfmtCommand=$;exports.getPatternPreview=Z;