@univerjs/sheets-numfmt 0.1.12 → 0.1.13

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 Oe=Object.defineProperty;var je=(e,t,r)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var $=(e,t,r)=>(je(e,typeof t!="symbol"?t+"":t,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),v=require("@univerjs/sheets"),C=require("@wendellhu/redi"),Q=require("@univerjs/sheets-ui"),L=require("rxjs/operators"),O=require("@univerjs/engine-numfmt"),he=require("@univerjs/engine-render"),I=require("@univerjs/ui"),j=require("rxjs"),y=require("react"),D=require("@univerjs/design"),R=require("@wendellhu/redi/react-bindings"),E={id:"sheet.command.numfmt.set.numfmt",type:a.CommandType.COMMAND,handler:(e,t)=>{if(!t)return!1;const r=e.get(a.ICommandService),n=e.get(a.IUniverInstanceService),s=e.get(a.IUndoRedoService),i=v.getSheetCommandTarget(n,t);if(!i)return!1;const{unitId:c,subUnitId:l}=i,u=t.values.filter(h=>!!h.pattern),m=t.values.filter(h=>!h.pattern),d=v.transformCellsToRange(c,l,u),o={unitId:c,subUnitId:l,ranges:m.map(h=>({startColumn:h.col,startRow:h.row,endColumn:h.col,endRow:h.row}))},p=[],b=[];if(u.length){Object.keys(d.values).forEach(g=>{const S=d.values[g];S.ranges=v.rangeMerge(S.ranges)}),p.push({id:v.SetNumfmtMutation.id,params:d});const h=v.factorySetNumfmtUndoMutation(e,d);b.push(...h)}if(m.length){o.ranges=v.rangeMerge(o.ranges),p.push({id:v.RemoveNumfmtMutation.id,params:o});const h=v.factoryRemoveNumfmtUndoMutation(e,o);b.push(...h)}const _=a.sequenceExecute(p,r).result;return _&&s.pushUndoRedo({unitID:c,undoMutations:b,redoMutations:p}),_}},Ee={sheet:{numfmt:{percent:"Percentage",title:"Number format",numfmtType:"Format types",cancel:"Cancel",confirm:"Confirm",general:"General",accounting:"Accounting",text:"Text",number:"Number",currency:"Currency",date:"Date",time:"Time",thousandthPercentile:"Thousands separator",preview:"Preview",dateTime:"Date and time",decimalLength:"Decimal places",currencyType:"Currency Symbol",moreFmt:"More Formats",financialValue:"Financial value",roundingCurrency:"Rounding up the currency",timeDuration:"Duration Time",currencyDes:"The currency format is used to represent general currency values. The accounting format aligns a column of values with decimal points",accountingDes:"The accounting number format aligns a column of values with currency symbols and decimal points",dateType:"Date Type",dateDes:"The date format presents date and time series values as date values.",negType:"A negative number type",generalDes:"The regular format does not contain any specific number format.",thousandthPercentileDes:"The percentile format is used for the representation of ordinary numbers. Monetary and accounting formats provide a specialized format for monetary value calculations.",addDecimal:"Increase decimal places",subtractDecimal:"Decreasing decimal places"}}},pe=Ee,xe={sheet:{numfmt:{percent:"百分比",title:"数字格式",numfmtType:"格式类型",cancel:"取消",confirm:"确认",general:"常规",accounting:"会计",text:"文本",number:"数值",currency:"货币",date:"日期",time:"时间",thousandthPercentile:"千分位符",preview:"示例",dateTime:"日期时间",decimalLength:"小数位数",currencyType:"货币类型",moreFmt:"更多格式",financialValue:"财务数值",roundingCurrency:"货币取整",timeDuration:"持续时间",currencyDes:"货币格式用于表示一般货币数值。会计格式可以对一列数值进行小数点对齐",accountingDes:"会计数字格式可对一列数值进行货币符号和小数点对齐",dateType:"日期类型",dateDes:"日期格式将日期和时间系列数值品示为日期值。",negType:"负数类型",generalDes:"常规格式不包含任何特定的数字格式。",thousandthPercentileDes:"千分位符格式用于一般数字的表示。货币和会计格式则提供货币值计算的专用格式。",addDecimal:"增加小数位",subtractDecimal:"减少小数位"}}},ve=xe,$e={sheet:{numfmt:{percent:"Процент",title:"Формат числа",numfmtType:"Типы форматов",cancel:"Отмена",confirm:"Подтвердить",general:"Общий",accounting:"Бухгалтерский",text:"Текст",number:"Число",currency:"Валюта",date:"Дата",time:"Время",thousandthPercentile:"Разделитель тысяч",preview:"Предпросмотр",dateTime:"Дата и время",decimalLength:"Десятичные знаки",currencyType:"Символ валюты",moreFmt:"Другие форматы",financialValue:"Финансовое значение",roundingCurrency:"Округление валюты",timeDuration:"Продолжительность времени",currencyDes:"Формат валюты используется для представления общих значений валюты. Формат бухгалтерского учета выравнивает столбец значений по десятичным точкам.",accountingDes:"Формат бухгалтерских чисел выравнивает столбец значений по символам валюты и десятичным точкам.",dateType:"Тип даты",dateDes:"Формат даты представляет значения времени и даты как значения даты.",negType:"Тип отрицательного числа",generalDes:"Обычный формат не содержит никакого специфического формата числа.",thousandthPercentileDes:"Формат процента используется для представления обычных чисел. Монетарные и бухгалтерские форматы предоставляют специальный формат для вычислений монетарных значений.",addDecimal:"Увеличить количество десятичных знаков",subtractDecimal:"Уменьшить количество десятичных знаков"}}},Ue=$e,oe="SHEET_NUMFMT_PLUGIN",Y=e=>O.getInfo(e).type||"unknown",X=(e,t,r)=>{const n=O.getInfo(e),s=r===a.LocaleType.ZH_CN?"zh-CN":"en",i=n._partitions[1],c=O.format(e,t,{locale:s});return t<0?{result:c,color:i.color}:{result:c}};var we=Object.defineProperty,Le=Object.getOwnPropertyDescriptor,Ae=(e,t,r,n)=>{for(var s=n>1?void 0:n?Le(t,r):t,i=e.length-1,c;i>=0;i--)(c=e[i])&&(s=(n?c(t,r,s):c(s))||s);return n&&s&&we(t,r,s),s},w=(e,t)=>(r,n)=>t(r,n,e);let W=class extends a.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 a.ObjectMatrix;this.disposeWithMe(this._sheetInterceptorService.intercept(v.INTERCEPTOR_POINT.CELL_CONTENT,{handler:(t,r,n)=>{const s=r.unitId,i=r.subUnitId,c=this._numfmtService.getValue(s,i,r.row,r.col);if(!c)return n(t);const l=t;if(!l||l.t!==a.CellValueType.NUMBER)return n(t);let u="";const m=e.getValue(r.row,r.col);if(m&&m.parameters===l.v)return n({...t,...m.result});const d=X(c.pattern,Number(l.v),this._localeService.getCurrentLocale());if(u=d.result,!u)return n(t);const o={v:u};if(d.color){const p=this._themeService.getCurrentTheme()[`${d.color}500`];p&&(o.interceptorStyle={cl:{rgb:p}})}return e.setValue(r.row,r.col,{result:o,parameters:l.v}),n({...t,...o})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===v.SetNumfmtMutation.id){const r=t.params;Object.keys(r.values).forEach(n=>{r.values[n].ranges.forEach(i=>{a.Range.foreach(i,(c,l)=>{e.realDeleteValue(c,l)})})})}})),this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.pipe(L.map(t=>t==null?void 0:t.sheetId),L.distinctUntilChanged()).subscribe(()=>{e.reset()})))}};W=Ae([a.OnLifecycle(a.LifecycleStages.Rendered,W),w(0,C.Inject(v.SheetInterceptorService)),w(1,C.Inject(a.ThemeService)),w(2,C.Inject(Q.SheetSkeletonManagerService)),w(3,C.Inject(a.ICommandService)),w(4,C.Inject(v.INumfmtService)),w(5,C.Inject(a.LocaleService))],W);const x=(e,t=0)=>{var n;return e&&(n=O.getInfo(e).maxDecimals)!=null?n:t},ee=(e,t)=>{if(e&&!t||!e&&t)return!1;const r=m=>m.reduce((d,o)=>{if(d.isEnd)return d;const p=o.value||o.num;return o.type==="point"?(d.isEnd=!0,d):{...d,result:d.result+p}},{isEnd:!1,result:""}).result,n=O.getInfo(e)._partitions,s=O.getInfo(t)._partitions,i=r(n[0].tokens),c=r(s[0].tokens),l=r(n[1].tokens),u=r(s[1].tokens);return i===c&&l===u&&n[1].color===s[1].color},de=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?".":""}${de(Number(t||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${t>0?".":""}${de(Number(t||0))}$1`):n).join(";"),Ve=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),ge={id:"sheet.command.numfmt.add.decimal.command",type:a.CommandType.COMMAND,handler:async e=>{const t=e.get(a.ICommandService),r=e.get(v.SelectionManagerService),n=e.get(v.INumfmtService),s=e.get(a.IUniverInstanceService),i=r.getSelections();if(!i||!i.length)return!1;const c=v.getSheetCommandTarget(s);if(!c)return!1;const{unitId:l,subUnitId:u}=c;let m=0;i.forEach(b=>{a.Range.foreach(b.range,(_,h)=>{const g=n.getValue(l,u,_,h);if(!g)return;const S=x(g.pattern);m=S>m?S:m})});const d=m+1,o=N(`0${d>0?".0":""}`,d),p=[];return i.forEach(b=>{a.Range.foreach(b.range,(_,h)=>{const g=n.getValue(l,u,_,h);if(!g)p.push({row:_,col:h,pattern:o});else{const S=x(g.pattern),T=N(g.pattern,S+1);T!==g.pattern&&p.push({row:_,col:h,pattern:T})}})}),p.length?await t.executeCommand(E.id,{values:p}):!1}},Be=[{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"}],He=[{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"}],Se=[{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"}],_e={id:"sheet.command.numfmt.set.currency",type:a.CommandType.COMMAND,handler:async e=>{const t=e.get(a.ICommandService),n=e.get(v.SelectionManagerService).getSelections();if(!n||!n.length)return!1;const s=[],i=Se[0].suffix("¥");return n.forEach(l=>{a.Range.foreach(l.range,(u,m)=>{s.push({row:u,col:m,pattern:i,type:"currency"})})}),await t.executeCommand(E.id,{values:s})}},ye={id:"sheet.command.numfmt.subtract.decimal.command",type:a.CommandType.COMMAND,handler:async e=>{const t=e.get(a.ICommandService),r=e.get(v.SelectionManagerService),n=e.get(v.INumfmtService),s=e.get(a.IUniverInstanceService),i=r.getSelections();if(!i||!i.length)return!1;const c=v.getSheetCommandTarget(s);if(!c)return!1;const{unitId:l,subUnitId:u}=c;let m=0;i.forEach(_=>{a.Range.foreach(_.range,(h,g)=>{const S=n.getValue(l,u,h,g);if(!S)return;const T=x(S.pattern);m=T>m?T:m})});const d=m-1,o=N(`0${d>0?".0":"."}`,d),p=[];return i.forEach(_=>{a.Range.foreach(_.range,(h,g)=>{const S=n.getValue(l,u,h,g);if(!S)p.push({row:h,col:g,pattern:o});else{const T=x(S.pattern);p.push({row:h,col:g,pattern:N(S.pattern,T-1)})}})}),await t.executeCommand(E.id,{values:p})}},ie={id:"sheet.operation.close.numfmt.panel",type:a.CommandType.OPERATION,handler:()=>!0},ue=C.createIdentifier("INumfmtController");a.runOnLifecycle(a.LifecycleStages.Rendered,ue);const J={id:"sheet.operation.open.numfmt.panel",type:a.CommandType.OPERATION,handler:e=>(e.get(ue).openPanel(),!0)};var be={exports:{}},te={};/**
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={};/**
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 Fe=y,qe=Symbol.for("react.element"),We=Symbol.for("react.fragment"),ke=Object.prototype.hasOwnProperty,Ge=Fe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ze={key:!0,ref:!0,__self:!0,__source:!0};function Ce(e,t,r){var n,s={},i=null,c=null;r!==void 0&&(i=""+r),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(c=t.ref);for(n in t)ke.call(t,n)&&!ze.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:qe,type:e,key:i,ref:c,props:s,_owner:Ge.current}}te.Fragment=We;te.jsx=Ce;te.jsxs=Ce;be.exports=te;var f=be.exports;const me=y.createContext([]),le=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"];var Ke=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,Je=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ye(t,r):t,i=e.length-1,c;i>=0;i--)(c=e[i])&&(s=(n?c(t,r,s):c(s))||s);return n&&s&&Ke(t,r,s),s},Ze=(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,c,l)=>{const u=l.length;return{value:i,priority:u-c}});return t.sort((i,c)=>{var m,d;const l=((m=s.find(o=>o.value===i))==null?void 0:m.priority)||-1;return(((d=s.find(o=>o.value===c))==null?void 0:d.priority)||-1)-l})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};Z=Je([Ze(0,C.Inject(a.ILocalStorageService))],Z);const fe="numfmtCurrency",Qe=e=>{const t=R.useDependency(Z),[r,n]=y.useState(le);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(fe,[...le]).then(i=>{n(i),e&&e(i)})})},[]),{userHabitCurrency:r,mark:i=>{t.markHabit(fe,i)}}},Xe=()=>{const e=y.useRef([]),[t,r]=y.useState({});return y.useEffect(()=>{e.current.forEach(s=>{s()}),e.current=[]},[t]),s=>{e.current.push(s),r({})}},H=e=>le.find(r=>e.includes(r)),et=e=>!!H(e)&&e.startsWith("_("),tt=e=>{const[t,r]=y.useState(()=>x(e.defaultPattern||"",2)),n=y.useContext(me),[s,i]=y.useState(()=>H(e.defaultPattern)||n[0]),c=y.useMemo(()=>n.map(o=>({label:o,value:o})),[]),u=R.useDependency(a.LocaleService).t;e.action.current=()=>N(`_("${s}"* #,##0${t>0?".0":""}_)`,t);const m=o=>{i(o),e.onChange(N(`_("${o}"* #,##0${t>0?".0":""}_)`,t))},d=o=>{const p=o||0;r(p),e.onChange(N(`_("${s}"* #,##0${p>0?".0":""}_)`,p))};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(D.InputNumber,{value:t,max:20,min:0,onChange:d})})]}),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(D.Select,{onChange:m,options:c,value:s})})]})]}),f.jsx("div",{className:"describe m-t-14",children:u("sheet.numfmt.accountingDes")})]})},ce=e=>Se.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),Ie=()=>Be.map(e=>({label:e.label,value:e.suffix})),Te=()=>He.map(e=>({label:e.label,value:e.suffix,color:e.color})),nt=e=>!!H(e)&&!e.startsWith("_("),rt=e=>{const r=R.useDependency(a.LocaleService).t,n=y.useContext(me),[s,i]=y.useState(()=>H(e.defaultPattern)||n[0]),[c,l]=y.useState(()=>x(e.defaultPattern||"",2)),[u,m]=y.useState(()=>{var S;const h=ce(s);return((S=h.find(T=>ee(T.value,e.defaultPattern)))==null?void 0:S.value)||h[0].value}),d=y.useMemo(()=>ce(s),[s]),o=y.useMemo(()=>n.map(h=>({label:h,value:h})),[n]);e.action.current=()=>N(u,c);const p=h=>{i(h);const g=ce(h)[0].value;m(g),e.onChange(N(g,c))},b=h=>{m(h),e.onChange(N(h,c))},_=h=>{l(h||0),e.onChange(N(u,h||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(D.InputNumber,{value:c,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(D.Select,{onChange:p,options:o,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(D.SelectList,{onChange:b,options:d,value:u})}),f.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})},st=e=>{const t=O.getInfo(e);return Ie().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)},it=e=>{const t=y.useMemo(Ie,[]),n=R.useDependency(a.LocaleService).t,[s,i]=y.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 c=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(D.SelectList,{value:s,options:t,onChange:c})}),f.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},ct=e=>!e,at=e=>{const r=R.useDependency(a.LocaleService).t;return e.action.current=()=>"",f.jsx("div",{children:f.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},ot=e=>Te().some(t=>ee(t.value,e)),lt=e=>{const t=R.useDependency(a.LocaleService),r=y.useMemo(Te,[]),[n,s]=y.useState(()=>x(e.defaultPattern||"",0)),[i,c]=y.useState(()=>{const o=r.find(p=>ee(p.value,e.defaultPattern||""));return(o==null?void 0:o.value)||r[0].value}),l=y.useMemo(()=>N(i,Number(n||0)),[i,n]),u=y.useMemo(()=>!Ve(i),[i]),m=o=>{s(o||0),e.onChange(N(i,Number(o||0)))},d=o=>{s(x(o,0)),c(o),e.onChange(o)};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(D.InputNumber,{disabled:u,value:n,max:20,min:0,onChange:m})}),f.jsxs("div",{className:"m-t-16 label",children:[" ",t.t("sheet.numfmt.negType")]}),f.jsx("div",{className:"m-t-8",children:f.jsx(D.SelectList,{onChange:d,options:r,value:i})}),f.jsx("div",{className:"describe m-t-14",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})},ut=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:s}=e.value,i=R.useDependency(a.LocaleService),c=y.useRef(()=>""),l=i.t,u=Xe(),m=y.useMemo(()=>[{label:"sheet.numfmt.general",component:at},{label:"sheet.numfmt.accounting",component:tt},{label:"sheet.numfmt.currency",component:rt},{label:"sheet.numfmt.date",component:it},{label:"sheet.numfmt.thousandthPercentile",component:lt}].map(M=>({...M,label:l(M.label)})),[]),[d,o]=y.useState(S),[p,b]=y.useState(()=>`${n}_${s}`),{mark:_,userHabitCurrency:h}=Qe(()=>b(`${n}_${s}_userCurrency'`)),g=y.useMemo(()=>{var M;return(M=m.find(U=>U.label===d))==null?void 0:M.component},[d]);function S(){return[ct,et,nt,st,ot].reduce((U,Pe,De)=>U||(Pe(r)?m[De].label:""),"")||m[0].label}const T=m.map(M=>({label:M.label,value:M.label})),A=M=>{o(M),u(()=>e.onChange({type:"change",value:c.current()||""}))},F=M=>{e.onChange({type:"change",value:M})},ne=()=>{const M=c.current()||"",U=H(M);U&&_(U),e.onChange({type:"confirm",value:M})},re=()=>{e.onChange({type:"cancel",value:""})},se={onChange:F,defaultValue:t,defaultPattern:r,action:c};return y.useEffect(()=>{o(S()),b(`${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(D.Select,{onChange:A,options:T,value:d})}),f.jsx("div",{children:g&&f.jsx(me.Provider,{value:h,children:y.createElement(g,{...se,key:p})})})]}),f.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[f.jsx(D.Button,{size:"small",onClick:re,className:"m-r-12",children:l("sheet.numfmt.cancel")}),f.jsx(D.Button,{type:"primary",size:"small",onClick:ne,children:l("sheet.numfmt.confirm")})]})]})},Me={id:"sheet.command.numfmt.set.percent",type:a.CommandType.COMMAND,handler:async e=>{const t=e.get(a.ICommandService),n=e.get(v.SelectionManagerService).getSelections();if(!n||!n.length)return!1;const s=[],i="0%";return n.forEach(l=>{a.Range.foreach(l.range,(u,m)=>{s.push({row:u,col:m,pattern:i,type:"percent"})})}),await t.executeCommand(E.id,{values:s})}};var mt=Object.defineProperty,dt=Object.getOwnPropertyDescriptor,ft=(e,t,r,n)=>{for(var s=n>1?void 0:n?dt(t,r):t,i=e.length-1,c;i>=0;i--)(c=e[i])&&(s=(n?c(t,r,s):c(s))||s);return n&&s&&mt(t,r,s),s},P=(e,t)=>(r,n)=>t(r,n,e);let k=class extends a.Disposable{constructor(t,r,n,s,i,c,l,u,m,d,o){super();$(this,"_previewPattern","");$(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._sheetSkeletonManagerService=s,this._commandService=i,this._selectionManagerService=c,this._renderManagerService=l,this._numfmtService=u,this._componentManager=m,this._sidebarService=d,this._localeService=o,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,c=this._localeService,u=(r.getSelectionRanges()||[])[0];if(!u)return!1;const m=s.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=m.getActiveSheet(),o=d.getCellRaw(u.startRow,u.startColumn),p=i.getValue(m.getUnitId(),d.getSheetId(),u.startRow,u.startColumn);let b="";p&&(b=p.pattern);const _=(o==null?void 0:o.t)===a.CellValueType.NUMBER?o.v:12345678,h={onChange:g=>{var S,T;if(g.type==="change")this._previewPattern=g.value,this._sheetSkeletonManagerService.reCalculate(),(T=(S=this._renderManagerService.getRenderById(m.getUnitId()))==null?void 0:S.mainComponent)==null||T.makeDirty();else if(g.type==="confirm"){const A=r.getSelectionRanges()||[],F={values:[]},ne=Y(g.value);A.forEach(re=>{a.Range.foreach(re,(se,M)=>{F.values.push({row:se,col:M,pattern:g.value,type:ne})})}),n.executeCommand(E.id,F),t.close()}else g.type==="cancel"&&t.close()},value:{defaultPattern:b,defaultValue:_,row:u.startRow,col:u.startColumn}};return this._sidebarDisposable=t.open({header:{title:c.t("sheet.numfmt.title")},children:{label:oe,...h},onClose:()=>{var g,S;this._sheetSkeletonManagerService.reCalculate(),(S=(g=this._renderManagerService.getRenderById(m.getUnitId()))==null?void 0:g.mainComponent)==null||S.makeDirty(),n.executeCommand(ie.id)}}),!0}_initCommands(){[ge,ye,_e,Me,J,ie,E].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this._componentManager.register(oe,ut)}_initRealTimeRenderingInterceptor(){const t=new j.Observable(n=>{this._commandService.onCommandExecuted(s=>{s.id===J.id&&n.next(!0),s.id===ie.id&&n.next(!1)})}),r=j.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(L.map(n=>n?n.map(s=>s.range):[]))]);this.disposeWithMe(a.toDisposable(r.pipe(L.switchMap(([n,s])=>new j.Observable(i=>{const c=new a.DisposableCollection;return n&&s.length&&i.next({selectionRanges:s,disposableCollection:c}),()=>{c.dispose()}})),L.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:s})=>{var c,l;const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(v.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,handler:(u,m,d)=>{const{row:o,col:p}=m,b=d(u)||{};if(s.find(_=>_.startColumn<=p&&_.endColumn>=p&&_.startRow<=o&&_.endRow>=o)){const _=m.worksheet.getCellRaw(o,p),h=_==null?void 0:_.v,g=_==null?void 0:_.t;if(h==null||g!==a.CellValueType.NUMBER||this._previewPattern===null)return b;const S=X(this._previewPattern,h,this._localeService.getCurrentLocale());if(S.color){const A=this._themeService.getCurrentTheme()[`${S.color}500`];return{...b,v:S.result,t:a.CellValueType.STRING,s:{cl:{rgb:A}}}}return{...b,v:S.result,t:a.CellValueType.STRING}}return b}})),(l=(c=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:c.mainComponent)==null||l.makeDirty()})))}_commandExecutedListener(){const t=[v.RemoveNumfmtMutation.id,v.SetNumfmtMutation.id];this.disposeWithMe(a.toDisposable(j.merge(new j.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(L.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$(a.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};k=ft([a.OnLifecycle(a.LifecycleStages.Rendered,k),P(0,C.Inject(v.SheetInterceptorService)),P(1,C.Inject(a.ThemeService)),P(2,a.IUniverInstanceService),P(3,C.Inject(Q.SheetSkeletonManagerService)),P(4,a.ICommandService),P(5,C.Inject(v.SelectionManagerService)),P(6,he.IRenderManagerService),P(7,v.INumfmtService),P(8,C.Inject(I.ComponentManager)),P(9,I.ISidebarService),P(10,C.Inject(a.LocaleService))],k);var ht=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,vt=(e,t,r,n)=>{for(var s=n>1?void 0:n?pt(t,r):t,i=e.length-1,c;i>=0;i--)(c=e[i])&&(s=(n?c(t,r,s):c(s))||s);return n&&s&&ht(t,r,s),s},V=(e,t)=>(r,n)=>t(r,n,e);const gt=()=>{let e=[];return{add:(s,i,c,l,u)=>e.push({unitId:s,subUnitId:i,row:c,col:l,value:u}),getEffects:()=>e,clean:()=>{e=[]}}};let G=class extends a.Disposable{constructor(t,r,n,s,i){super();$(this,"_collectEffectMutation",gt());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=s,this._editorBridgeService=i,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){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,c=this._numfmtService.getValue(r.unitId,r.subUnitId,s,i);if(c)switch(Y(c.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(a.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{handler:(t,r,n)=>{var d;this._collectEffectMutation.clean();const s=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),i=(d=s&&Y(s.pattern))!=null?d:"",c=()=>{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=O.parseDate(l)||O.parseTime(l);if(!!u){if(u&&u.z){const o=Number(u.v);return this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:u.z}),{...t,v:o,t:a.CellValueType.NUMBER}}}else(["date","time","datetime"].includes(i)||!St(l))&&c();return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){switch(r.id){case v.SetRangeValuesCommand.id:{const n=t._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=n.getUnitId(),i=n.getActiveSheet().getSheetId(),c=t._collectEffectMutation.getEffects();if(!c.length)return{redos:[],undos:[]};const l=c.filter(o=>{var p;return!!((p=o.value)!=null&&p.pattern)}).map(o=>({row:o.row,col:o.col,pattern:o.value.pattern})),u=c.filter(o=>{var p;return!((p=o.value)!=null&&p.pattern)}).map(o=>({startRow:o.row,endColumn:o.col,startColumn:o.col,endRow:o.row})),m=[],d=[];if(l){const o={id:v.SetNumfmtMutation.id,params:v.transformCellsToRange(s,i,l)};m.push(o),d.push(...v.factorySetNumfmtUndoMutation(t._injector,o.params))}if(u){const o={id:v.RemoveNumfmtMutation.id,params:{unitId:s,subUnitId:i,ranges:u}};m.push(o),d.push(...v.factoryRemoveNumfmtUndoMutation(t._injector,o.params))}return{redos:m,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}};G=vt([a.OnLifecycle(a.LifecycleStages.Rendered,G),V(0,C.Inject(v.SheetInterceptorService)),V(1,C.Inject(v.INumfmtService)),V(2,C.Inject(a.IUniverInstanceService)),V(3,C.Inject(C.Injector)),V(4,C.Inject(Q.IEditorBridgeService))],G);function St(e){return/^-?\d+(\.\d+)?$/.test(e)}var _t=Object.defineProperty,yt=Object.getOwnPropertyDescriptor,bt=(e,t,r,n)=>{for(var s=n>1?void 0:n?yt(t,r):t,i=e.length-1,c;i>=0;i--)(c=e[i])&&(s=(n?c(t,r,s):c(s))||s);return n&&s&&_t(t,r,s),s},Ct=(e,t)=>(r,n)=>t(r,n,e);let z=class extends a.Disposable{constructor(t){super();$(this,"_initLocal",()=>{this._localeService.load({zhCN:ve,enUS:pe})});this._localeService=t,this._initLocal()}};z=bt([a.OnLifecycle(a.LifecycleStages.Rendered,z),Ct(0,C.Inject(a.LocaleService))],z);const K=[{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:""}],Ne="sheet.numfmt.moreNumfmtType",Re="sheet.numfmt.moreNumfmtType.options",It=e=>{var n;const t=R.useDependency(a.LocaleService),r=(n=e.value)!=null?n:t.t("sheet.numfmt.general");return f.jsx("span",{className:"more-numfmt-type",children:r})},Tt=()=>{const e=R.useDependency(a.ICommandService),t=R.useDependency(a.LocaleService),r=R.useInjector(),n=R.useDependency(v.SelectionManagerService),s=l=>{const u=n.getLast();if(!u)return;const m=r.get(he.ITextSelectionRenderManager),d=u.range,o=[];a.Range.foreach(d,(p,b)=>{l?o.push({row:p,col:b,pattern:l,type:Y(l)}):o.push({row:p,col:b})}),e.executeCommand(E.id,{values:o}),m.focus()},i=l=>{if(l===0)s(null);else if(l===K.length-1)e.executeCommand(J.id);else{const u=K[l];u.pattern&&s(u.pattern)}},c=1220;return f.jsx("div",{className:"more-numfmt-type-options",children:K.map((l,u)=>l==="|"?f.jsx("div",{className:"line m-t-4",onClick:m=>m.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||"",c,t.getCurrentLocale()).result:""})]},u))})},Mt=e=>({icon:"RmbSingle",id:_e.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,a.UniverInstanceType.UNIVER_SHEET),disabled$:v.getCurrentSheetDisabled$(e)}),Nt=e=>({icon:"AddDigitsSingle",id:ge.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,a.UniverInstanceType.UNIVER_SHEET),disabled$:v.getCurrentSheetDisabled$(e)}),Rt=e=>({icon:"ReduceDigitsSingle",id:ye.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,a.UniverInstanceType.UNIVER_SHEET),disabled$:v.getCurrentSheetDisabled$(e)}),Pt=e=>({icon:"PercentSingle",id:Me.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,a.UniverInstanceType.UNIVER_SHEET),disabled$:v.getCurrentSheetDisabled$(e)}),Dt=e=>{const t=e.get(v.INumfmtService),r=e.get(a.IUniverInstanceService),n=e.get(a.ICommandService),s=e.get(a.LocaleService),i=e.get(v.SelectionManagerService),c=Q.deriveStateFromActiveSheet$(r,"",({workbook:l,worksheet:u})=>new j.Observable(m=>j.merge(i.selectionMoveEnd$,new j.Observable(d=>{const o=[v.RemoveNumfmtMutation.id,v.SetNumfmtMutation.id],p=n.onCommandExecuted(b=>{o.includes(b.id)&&d.next(null)});return()=>p.dispose()})).subscribe(()=>{const d=i.getSelections();if(d&&d[0]){const o=d[0].range,p=o.startRow,b=o.startColumn,_=t.getValue(l.getUnitId(),u.getSheetId(),p,b),h=_==null?void 0:_.pattern;let g=s.t("sheet.numfmt.general");if(h){const S=K.filter(T=>typeof T=="object"&&T.pattern).find(T=>ee(h,T.pattern));S&&typeof S=="object"&&S.pattern?g=s.t(S.label):g=s.t("sheet.numfmt.moreFmt")}m.next(g)}})));return{label:Ne,id:J.id,tooltip:"sheet.numfmt.title",type:I.MenuItemType.SELECTOR,group:I.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[I.MenuPosition.TOOLBAR_START],selections:[{label:{name:Re,hoverable:!1}}],value$:c,hidden$:I.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:v.getCurrentSheetDisabled$(e)}};var Ot=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Et=(e,t,r,n)=>{for(var s=n>1?void 0:n?jt(t,r):t,i=e.length-1,c;i>=0;i--)(c=e[i])&&(s=(n?c(t,r,s):c(s))||s);return n&&s&&Ot(t,r,s),s},ae=(e,t)=>(r,n)=>t(r,n,e);const xt={};let B=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;[Pt,Nt,Rt,Mt,Dt].forEach(t=>{this.disposeWithMe(this._menuService.addMenuItem(t(this._injector),e))}),this.disposeWithMe(this._componentManager.register(Ne,It)),this.disposeWithMe(this._componentManager.register(Re,Tt))}};B=Et([a.OnLifecycle(a.LifecycleStages.Rendered,B),ae(1,C.Inject(C.Injector)),ae(2,C.Inject(I.ComponentManager)),ae(3,C.Inject(I.IMenuService))],B);var $t=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,wt=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ut(t,r):t,i=e.length-1,c;i>=0;i--)(c=e[i])&&(s=(n?c(t,r,s):c(s))||s);return n&&s&&$t(t,r,s),s},Lt=(e,t)=>(r,n)=>t(r,n,e),q;exports.UniverSheetsNumfmtPlugin=(q=class extends a.Plugin{constructor(t={},r){super(),this._config=t,this._injector=r,this._config=a.Tools.deepMerge({},xt,this._config)}onStarting(){this._injector.add([ue,{useClass:k,lazy:!1}]),this._injector.add([G]),this._injector.add([Z]),this._injector.add([W]),this._injector.add([z]),this._injector.add([B,{useFactory:()=>this._injector.createInstance(B,this._config)}])}},$(q,"pluginName",oe),$(q,"type",a.UniverInstanceType.UNIVER_SHEET),q);exports.UniverSheetsNumfmtPlugin=wt([Lt(1,C.Inject(C.Injector))],exports.UniverSheetsNumfmtPlugin);exports.SetNumfmtCommand=E;exports.enUS=pe;exports.getPatternPreview=X;exports.ruRU=Ue;exports.zhCN=ve;
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;