@univerjs/sheets-numfmt 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
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 W=(e,t,n)=>Oe(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),C=require("@wendellhu/redi"),d=require("@univerjs/sheets"),x=require("@univerjs/sheets-ui"),O=require("rxjs"),j=require("@univerjs/engine-numfmt"),Se=require("@univerjs/engine-render"),I=require("@univerjs/ui"),q=require("rxjs/operators"),y=require("react"),E=require("@univerjs/design"),N=require("@wendellhu/redi/react-bindings"),ce="SHEET_NUMFMT_PLUGIN",Z=e=>j.numfmt.getInfo(e).type||"unknown",ee=(e,t,n)=>{const r=j.numfmt.getInfo(e),s=n===c.LocaleType.ZH_CN?"zh-CN":"en",i=r._partitions[1],o=j.numfmt.format(e,t,{locale:s});return t<0?{result:o,color:i.color}:{result:o}};var je=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,De=(e,t,n,r)=>{for(var s=r>1?void 0:r?xe(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(t,n,s):o(s))||s);return r&&s&&je(t,n,s),s},w=(e,t)=>(n,r)=>t(n,r,e);let G=class extends c.Disposable{constructor(e,t,n,r,s,i){super(),this._instanceService=e,this._sheetInterceptorService=t,this._themeService=n,this._commandService=r,this._numfmtService=s,this._localeService=i,this._initInterceptorCellContent()}_initInterceptorCellContent(){const e=new c.ObjectMatrix;this.disposeWithMe(this._sheetInterceptorService.intercept(d.INTERCEPTOR_POINT.CELL_CONTENT,{handler:(t,n,r)=>{const s=n.unitId,i=n.subUnitId,o=this._numfmtService.getValue(s,i,n.row,n.col);if(!o)return r(t);const a=t;if(!a||a.t!==c.CellValueType.NUMBER)return r(t);let l="";const p=e.getValue(n.row,n.col);if(p&&p.parameters===a.v)return r({...t,...p.result});const f=ee(o.pattern,Number(a.v),this._localeService.getCurrentLocale());if(l=f.result,!l)return r(t);const u={v:l};if(f.color){const m=this._themeService.getCurrentTheme()[`${f.color}500`];m&&(u.interceptorStyle={cl:{rgb:m}})}return e.setValue(n.row,n.col,{result:u,parameters:a.v}),r({...t,...u})},priority:10})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===d.SetNumfmtMutation.id){const n=t.params;Object.keys(n.values).forEach(r=>{n.values[r].ranges.forEach(i=>{c.Range.foreach(i,(o,a)=>{e.realDeleteValue(o,a)})})})}else if(t.id===d.SetRangeValuesMutation.id){const n=t.params;new c.ObjectMatrix(n.cellValue).forValue((r,s)=>{e.realDeleteValue(r,s)})}})),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()))}};G=De([c.OnLifecycle(c.LifecycleStages.Rendered,G),w(0,c.IUniverInstanceService),w(1,C.Inject(d.SheetInterceptorService)),w(2,C.Inject(c.ThemeService)),w(3,C.Inject(c.ICommandService)),w(4,C.Inject(d.INumfmtService)),w(5,C.Inject(c.LocaleService))],G);const D=(e,t=0)=>{var r;return e&&(r=j.numfmt.getInfo(e).maxDecimals)!=null?r:t},te=(e,t)=>{if(e&&!t||!e&&t)return!1;const n=p=>p.reduce((f,u)=>{if(f.isEnd)return f;const m=u.value||u.num;return u.type==="point"?(f.isEnd=!0,f):{...f,result:f.result+m}},{isEnd:!1,result:""}).result,r=j.numfmt.getInfo(e)._partitions,s=j.numfmt.getInfo(t)._partitions,i=n(r[0].tokens),o=n(s[0].tokens),a=n(r[1].tokens),l=n(s[1].tokens);return i===o&&a===l&&r[1].color===s[1].color},pe=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),M=(e,t)=>e.split(";").map(r=>/\.0?/.test(r)?r.replace(/\.0*/g,`${t>0?".":""}${pe(Number(t||0))}`):/0([^0]?)|0$/.test(r)?r.replace(/0([^0]+)|0$/,`0${t>0?".":""}${pe(Number(t||0))}$1`):r).join(";"),$e=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),$={id:"sheet.command.numfmt.set.numfmt",type:c.CommandType.COMMAND,handler:(e,t)=>{if(!t)return!1;const n=e.get(c.ICommandService),r=e.get(c.IUniverInstanceService),s=e.get(c.IUndoRedoService),i=d.getSheetCommandTarget(r,t);if(!i)return!1;const{unitId:o,subUnitId:a}=i,l=t.values.filter(v=>!!v.pattern),p=t.values.filter(v=>!v.pattern),f=d.transformCellsToRange(o,a,l),u={unitId:o,subUnitId:a,ranges:p.map(v=>({startColumn:v.col,startRow:v.row,endColumn:v.col,endRow:v.row}))},m=[],g=[];if(l.length){Object.keys(f.values).forEach(b=>{const S=f.values[b];S.ranges=d.rangeMerge(S.ranges)}),m.push({id:d.SetNumfmtMutation.id,params:f});const v=d.factorySetNumfmtUndoMutation(e,f);g.push(...v)}if(p.length){u.ranges=d.rangeMerge(u.ranges),m.push({id:d.RemoveNumfmtMutation.id,params:u});const v=d.factoryRemoveNumfmtUndoMutation(e,u);g.push(...v)}const _=c.sequenceExecute(m,n).result;return _&&s.pushUndoRedo({unitID:o,undoMutations:g,redoMutations:m}),_}},le={id:"sheet.command.numfmt.add.decimal.command",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),n=e.get(d.SheetsSelectionsService),r=e.get(d.INumfmtService),s=e.get(c.IUniverInstanceService),i=n.getCurrentSelections();if(!i||!i.length)return!1;const o=d.getSheetCommandTarget(s);if(!o)return!1;const{unitId:a,subUnitId:l}=o;let p=0;i.forEach(g=>{c.Range.foreach(g.range,(_,v)=>{const b=r.getValue(a,l,_,v);if(!b)return;const S=D(b.pattern);p=S>p?S:p})});const f=p+1,u=M(`0${f>0?".0":""}`,f),m=[];return i.forEach(g=>{c.Range.foreach(g.range,(_,v)=>{const b=r.getValue(a,l,_,v);if(!b)m.push({row:_,col:v,pattern:u});else{const S=D(b.pattern),T=M(b.pattern,S+1);T!==b.pattern&&m.push({row:_,col:v,pattern:T})}})}),m.length?await t.executeCommand($.id,{values:m}):!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"}],ge=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],ue={id:"sheet.command.numfmt.set.currency",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),r=e.get(d.SheetsSelectionsService).getCurrentSelections();if(!r||!r.length)return!1;const s=[],i=ge[0].suffix("¥");return r.forEach(a=>{c.Range.foreach(a.range,(l,p)=>{s.push({row:l,col:p,pattern:i,type:"currency"})})}),await t.executeCommand($.id,{values:s})}},me={id:"sheet.command.numfmt.subtract.decimal.command",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),n=e.get(d.SheetsSelectionsService),r=e.get(d.INumfmtService),s=e.get(c.IUniverInstanceService),i=n.getCurrentSelections();if(!i||!i.length)return!1;const o=d.getSheetCommandTarget(s);if(!o)return!1;const{unitId:a,subUnitId:l}=o;let p=0;i.forEach(_=>{c.Range.foreach(_.range,(v,b)=>{const S=r.getValue(a,l,v,b);if(!S)return;const T=D(S.pattern);p=T>p?T:p})});const f=p-1,u=M(`0${f>0?".0":"."}`,f),m=[];return i.forEach(_=>{c.Range.foreach(_.range,(v,b)=>{const S=r.getValue(a,l,v,b);if(!S)m.push({row:v,col:b,pattern:u});else{const T=D(S.pattern);m.push({row:v,col:b,pattern:M(S.pattern,T-1)})}})}),await t.executeCommand($.id,{values:m})}},z={id:"sheet.operation.close.numfmt.panel",type:c.CommandType.OPERATION,handler:()=>!0},de=C.createIdentifier("INumfmtController");c.runOnLifecycle(c.LifecycleStages.Rendered,de);const H={id:"sheet.operation.open.numfmt.panel",type:c.CommandType.OPERATION,handler:e=>(e.get(de).openPanel(),!0)};var _e={exports:{}},ne={};/**
1
+ "use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key2,value)=>key2 in obj?__defProp(obj,key2,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key2]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key2,value)=>__defNormalProp(obj,typeof key2!="symbol"?key2+"":key2,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),sheets=require("@univerjs/sheets"),sheetsUi=require("@univerjs/sheets-ui"),rxjs=require("rxjs"),engineNumfmt=require("@univerjs/engine-numfmt"),engineRender=require("@univerjs/engine-render"),ui=require("@univerjs/ui"),operators=require("rxjs/operators"),require$$0=require("react"),design=require("@univerjs/design"),SHEET_NUMFMT_PLUGIN="SHEET_NUMFMT_PLUGIN",getPatternType=__name(pattern=>engineNumfmt.numfmt.getInfo(pattern).type||"unknown","getPatternType"),getPatternPreview=__name((pattern,value,_locale)=>{const info=engineNumfmt.numfmt.getInfo(pattern),locale=_locale===core.LocaleType.ZH_CN?"zh-CN":"en",negInfo=info._partitions[1],result=engineNumfmt.numfmt.format(pattern,value,{locale});return value<0?{result,color:negInfo.color}:{result}},"getPatternPreview");var __defProp$6=Object.defineProperty,__getOwnPropDesc$6=Object.getOwnPropertyDescriptor,__decorateClass$6=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$6(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$6(target,key2,result),result},"__decorateClass$6"),__decorateParam$6=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$6"),_a;let SheetsNumfmtCellContentController=(_a=class extends core.Disposable{constructor(_instanceService,_sheetInterceptorService,_themeService,_commandService,_numfmtService,_localeService){super(),this._instanceService=_instanceService,this._sheetInterceptorService=_sheetInterceptorService,this._themeService=_themeService,this._commandService=_commandService,this._numfmtService=_numfmtService,this._localeService=_localeService,this._initInterceptorCellContent()}_initInterceptorCellContent(){const renderCache=new core.ObjectMatrix;this.disposeWithMe(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{handler:__name((cell,location,next)=>{const unitId=location.unitId,sheetId=location.subUnitId,numfmtValue=this._numfmtService.getValue(unitId,sheetId,location.row,location.col);if(!numfmtValue)return next(cell);const originCellValue=cell;if(!originCellValue||originCellValue.t!==core.CellValueType.NUMBER)return next(cell);let numfmtRes="";const cache=renderCache.getValue(location.row,location.col);if(cache&&cache.parameters===originCellValue.v)return next({...cell,...cache.result});const info=getPatternPreview(numfmtValue.pattern,Number(originCellValue.v),this._localeService.getCurrentLocale());if(numfmtRes=info.result,!numfmtRes)return next(cell);const res={v:numfmtRes};if(info.color){const color=this._themeService.getCurrentTheme()[`${info.color}500`];color&&(res.interceptorStyle={cl:{rgb:color}})}return renderCache.setValue(location.row,location.col,{result:res,parameters:originCellValue.v}),next({...cell,...res})},"handler"),priority:10})),this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===sheets.SetNumfmtMutation.id){const params=commandInfo.params;Object.keys(params.values).forEach(key2=>{params.values[key2].ranges.forEach(range=>{core.Range.foreach(range,(row,col)=>{renderCache.realDeleteValue(row,col)})})})}else if(commandInfo.id===sheets.SetRangeValuesMutation.id){const params=commandInfo.params;new core.ObjectMatrix(params.cellValue).forValue((row,col)=>{renderCache.realDeleteValue(row,col)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.switchMap(workbook=>{var _a8;return(_a8=workbook==null?void 0:workbook.activeSheet$)!=null?_a8:rxjs.of(null)}),rxjs.skip(1)).subscribe(()=>renderCache.reset()))}},__name(_a,"SheetsNumfmtCellContentController"),_a);SheetsNumfmtCellContentController=__decorateClass$6([core.OnLifecycle(core.LifecycleStages.Rendered,SheetsNumfmtCellContentController),__decorateParam$6(0,core.IUniverInstanceService),__decorateParam$6(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$6(2,core.Inject(core.ThemeService)),__decorateParam$6(3,core.Inject(core.ICommandService)),__decorateParam$6(4,core.Inject(sheets.INumfmtService)),__decorateParam$6(5,core.Inject(core.LocaleService))],SheetsNumfmtCellContentController);const getDecimalFromPattern=__name((pattern,defaultValue=0)=>{var _a8;return pattern&&(_a8=engineNumfmt.numfmt.getInfo(pattern).maxDecimals)!=null?_a8:defaultValue},"getDecimalFromPattern"),isPatternEqualWithoutDecimal=__name((patternA,patternB)=>{if(patternA&&!patternB||!patternA&&patternB)return!1;const getString=__name(tokens=>tokens.reduce((pre,cur)=>{if(pre.isEnd)return pre;const str=cur.value||cur.num;return cur.type==="point"?(pre.isEnd=!0,pre):{...pre,result:pre.result+str}},{isEnd:!1,result:""}).result,"getString"),partitionsA=engineNumfmt.numfmt.getInfo(patternA)._partitions,partitionsB=engineNumfmt.numfmt.getInfo(patternB)._partitions,A1=getString(partitionsA[0].tokens),B1=getString(partitionsB[0].tokens),A2=getString(partitionsA[1].tokens),B2=getString(partitionsB[1].tokens);return A1===B1&&A2===B2&&partitionsA[1].color===partitionsB[1].color},"isPatternEqualWithoutDecimal"),getDecimalString=__name(length=>new Array(Math.min(Math.max(0,Number(length)),30)).fill(0).join(""),"getDecimalString"),setPatternDecimal=__name((patterns,decimalLength)=>patterns.split(";").map(pattern=>/\.0?/.test(pattern)?pattern.replace(/\.0*/g,`${decimalLength>0?".":""}${getDecimalString(Number(decimalLength||0))}`):/0([^0]?)|0$/.test(pattern)?pattern.replace(/0([^0]+)|0$/,`0${decimalLength>0?".":""}${getDecimalString(Number(decimalLength||0))}$1`):pattern).join(";"),"setPatternDecimal"),isPatternHasDecimal=__name(pattern=>/\.0?/.test(pattern)||/0([^0]?)|0$/.test(pattern),"isPatternHasDecimal"),SetNumfmtCommand={id:"sheet.command.numfmt.set.numfmt",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{if(!params)return!1;const commandService=accessor.get(core.ICommandService),univerInstanceService=accessor.get(core.IUniverInstanceService),undoRedoService=accessor.get(core.IUndoRedoService),target=sheets.getSheetCommandTarget(univerInstanceService,params);if(!target)return!1;const{unitId,subUnitId}=target,setCells=params.values.filter(value=>!!value.pattern),removeCells=params.values.filter(value=>!value.pattern),setRedos=sheets.transformCellsToRange(unitId,subUnitId,setCells),removeRedos={unitId,subUnitId,ranges:removeCells.map(cell=>({startColumn:cell.col,startRow:cell.row,endColumn:cell.col,endRow:cell.row}))},redos=[],undos=[];if(setCells.length){Object.keys(setRedos.values).forEach(key2=>{const v=setRedos.values[key2];v.ranges=sheets.rangeMerge(v.ranges)}),redos.push({id:sheets.SetNumfmtMutation.id,params:setRedos});const undo=sheets.factorySetNumfmtUndoMutation(accessor,setRedos);undos.push(...undo)}if(removeCells.length){removeRedos.ranges=sheets.rangeMerge(removeRedos.ranges),redos.push({id:sheets.RemoveNumfmtMutation.id,params:removeRedos});const undo=sheets.factoryRemoveNumfmtUndoMutation(accessor,removeRedos);undos.push(...undo)}const result=core.sequenceExecute(redos,commandService).result;return result&&undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:undos,redoMutations:redos}),result},"handler")},AddDecimalCommand={id:"sheet.command.numfmt.add.decimal.command",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),numfmtService=accessor.get(sheets.INumfmtService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const target=sheets.getSheetCommandTarget(univerInstanceService);if(!target)return!1;const{unitId,subUnitId}=target;let maxDecimals=0;selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)return;const decimals2=getDecimalFromPattern(numfmtValue.pattern);maxDecimals=decimals2>maxDecimals?decimals2:maxDecimals})});const decimals=maxDecimals+1,defaultPattern=setPatternDecimal(`0${decimals>0?".0":""}`,decimals),values=[];return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)values.push({row,col,pattern:defaultPattern});else{const decimals2=getDecimalFromPattern(numfmtValue.pattern),pattern=setPatternDecimal(numfmtValue.pattern,decimals2+1);pattern!==numfmtValue.pattern&&values.push({row,col,pattern})}})}),values.length?await commandService.executeCommand(SetNumfmtCommand.id,{values}):!1},"handler")},DATEFMTLISG=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],NUMBERFORMAT=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],CURRENCYFORMAT=[{label:__name(suffix=>`${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);"${suffix}"#,##0.00`,"suffix")},{label:__name(suffix=>`${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]"${suffix}"#,##0.00`,"suffix"),color:"red"},{label:__name(suffix=>`(${suffix}1,235)`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);("${suffix}"#,##0.00)`,"suffix")},{label:__name(suffix=>`(${suffix}1,235)`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]("${suffix}"#,##0.00)`,"suffix"),color:"red"},{label:__name(suffix=>`-${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);-"${suffix}"#,##0.00`,"suffix")},{label:__name(suffix=>`-${suffix}1,235`,"label"),suffix:__name(suffix=>`"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`,"suffix"),color:"red"}],SetCurrencyCommand={id:"sheet.command.numfmt.set.currency",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selections=accessor.get(sheets.SheetsSelectionsService).getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix=CURRENCYFORMAT[0].suffix("¥");return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{values.push({row,col,pattern:suffix,type:"currency"})})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")},SubtractDecimalCommand={id:"sheet.command.numfmt.subtract.decimal.command",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),numfmtService=accessor.get(sheets.INumfmtService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const target=sheets.getSheetCommandTarget(univerInstanceService);if(!target)return!1;const{unitId,subUnitId}=target;let maxDecimals=0;selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)return;const decimals2=getDecimalFromPattern(numfmtValue.pattern);maxDecimals=decimals2>maxDecimals?decimals2:maxDecimals})});const decimals=maxDecimals-1,defaultPattern=setPatternDecimal(`0${decimals>0?".0":"."}`,decimals),values=[];return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{const numfmtValue=numfmtService.getValue(unitId,subUnitId,row,col);if(!numfmtValue)values.push({row,col,pattern:defaultPattern});else{const decimals2=getDecimalFromPattern(numfmtValue.pattern);values.push({row,col,pattern:setPatternDecimal(numfmtValue.pattern,decimals2-1)})}})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")},CloseNumfmtPanelOperator={id:"sheet.operation.close.numfmt.panel",type:core.CommandType.OPERATION,handler:__name(()=>!0,"handler")},INumfmtController=core.createIdentifier("INumfmtController");core.runOnLifecycle(core.LifecycleStages.Rendered,INumfmtController);const OpenNumfmtPanelOperator={id:"sheet.operation.open.numfmt.panel",type:core.CommandType.OPERATION,handler:__name(accessor=>(accessor.get(INumfmtController).openPanel(),!0),"handler")};var jsxRuntime={exports:{}},reactJsxRuntime_production_min={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,4 +6,4 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Le=y,Ae=Symbol.for("react.element"),Ve=Symbol.for("react.fragment"),Be=Object.prototype.hasOwnProperty,He=Le.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ke={key:!0,ref:!0,__self:!0,__source:!0};function be(e,t,n){var r,s={},i=null,o=null;n!==void 0&&(i=""+n),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(o=t.ref);for(r in t)Be.call(t,r)&&!ke.hasOwnProperty(r)&&(s[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)s[r]===void 0&&(s[r]=t[r]);return{$$typeof:Ae,type:e,key:i,ref:o,props:s,_owner:He.current}}ne.Fragment=Ve;ne.jsx=be;ne.jsxs=be;_e.exports=ne;var h=_e.exports;const fe=y.createContext([]),ae=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"];var Fe=Object.defineProperty,We=Object.getOwnPropertyDescriptor,qe=(e,t,n,r)=>{for(var s=r>1?void 0:r?We(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(t,n,s):o(s))||s);return r&&s&&Fe(t,n,s),s},Ge=(e,t)=>(n,r)=>t(n,r,e);let Q=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(r=>{r||this._localStorageService.setItem(n,t)})}markHabit(e,t){const n=this._getKey(e);this._localStorageService.getItem(n).then(r=>{if(r){const s=r.findIndex(i=>i===t);s>-1&&r.splice(s,1),r.unshift(t),this._localStorageService.setItem(n,r)}})}async getHabit(e,t){const n=this._getKey(e),r=await this._localStorageService.getItem(n);if(t&&r){const s=r.map((i,o,a)=>{const l=a.length;return{value:i,priority:l-o}});return t.sort((i,o)=>{var p,f;const a=((p=s.find(u=>u.value===i))==null?void 0:p.priority)||-1;return(((f=s.find(u=>u.value===o))==null?void 0:f.priority)||-1)-a})}return r||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};Q=qe([Ge(0,C.Inject(c.ILocalStorageService))],Q);const ve="numfmtCurrency",ze=e=>{const t=N.useDependency(Q),[n,r]=y.useState(ae);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(ve,[...ae]).then(i=>{r(i),e&&e(i)})})},[]),{userHabitCurrency:n,mark:i=>{t.markHabit(ve,i)}}},Ke=()=>{const e=y.useRef([]),[t,n]=y.useState({});return y.useEffect(()=>{e.current.forEach(s=>{s()}),e.current=[]},[t]),s=>{e.current.push(s),n({})}},k=e=>ae.find(n=>e.includes(n)),Ye=e=>!!k(e)&&e.startsWith("_("),Je=e=>{const[t,n]=y.useState(()=>D(e.defaultPattern||"",2)),r=y.useContext(fe),[s,i]=y.useState(()=>k(e.defaultPattern)||r[0]),o=y.useMemo(()=>r.map(u=>({label:u,value:u})),[]),l=N.useDependency(c.LocaleService).t;e.action.current=()=>M(`_("${s}"* #,##0${t>0?".0":""}_)`,t);const p=u=>{i(u),e.onChange(M(`_("${u}"* #,##0${t>0?".0":""}_)`,t))},f=u=>{const m=u||0;n(m),e.onChange(M(`_("${s}"* #,##0${m>0?".0":""}_)`,m))};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:l("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:l("sheet.numfmt.currencyType")}),h.jsx("div",{className:"m-t-8 w-140",children:h.jsx(E.Select,{onChange:p,options:o,value:s})})]})]}),h.jsx("div",{className:"describe m-t-14",children:l("sheet.numfmt.accountingDes")})]})},ie=e=>ge.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),ye=()=>Ue.map(e=>({label:e.label,value:e.suffix})),Ce=()=>we.map(e=>({label:e.label,value:e.suffix,color:e.color})),Xe=e=>!!k(e)&&!e.startsWith("_("),Ze=e=>{const n=N.useDependency(c.LocaleService).t,r=y.useContext(fe),[s,i]=y.useState(()=>k(e.defaultPattern)||r[0]),[o,a]=y.useState(()=>D(e.defaultPattern||"",2)),[l,p]=y.useState(()=>{var S;const v=ie(s);return((S=v.find(T=>te(T.value,e.defaultPattern)))==null?void 0:S.value)||v[0].value}),f=y.useMemo(()=>ie(s),[s]),u=y.useMemo(()=>r.map(v=>({label:v,value:v})),[r]);e.action.current=()=>M(l,o);const m=v=>{if(v===void 0)return;i(v);const b=ie(v)[0].value;p(b),e.onChange(M(b,o))},g=v=>{v!==void 0&&(p(v),e.onChange(M(v,o)))},_=v=>{a(v||0),e.onChange(M(l,v||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:_})})]}),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:m,options:u,value:s})})]})]}),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:g,options:f,value:l})}),h.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.currencyDes")})]})},Qe=e=>{const t=j.numfmt.getInfo(e);return ye().map(n=>n.value).includes(e)||["date","datetime","time"].includes(t.type)},et=e=>{const t=y.useMemo(ye,[]),r=N.useDependency(c.LocaleService).t,[s,i]=y.useState(()=>{if(e.defaultPattern){const a=t.find(l=>l.value===e.defaultPattern);if(a)return a.value}return t[0].value});e.action.current=()=>s;const o=a=>{a!==void 0&&(i(a),e.onChange(a))};return h.jsxs("div",{children:[h.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.dateType")}),h.jsx("div",{className:"m-t-8",children:h.jsx(E.SelectList,{value:s,options:t,onChange:o})}),h.jsx("div",{className:"describe m-t-14",children:r("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")})})},rt=e=>Ce().some(t=>te(t.value,e)),st=e=>{const t=N.useDependency(c.LocaleService),n=y.useMemo(Ce,[]),[r,s]=y.useState(()=>D(e.defaultPattern||"",0)),[i,o]=y.useState(()=>{const u=n.find(m=>te(m.value,e.defaultPattern||""));return(u==null?void 0:u.value)||n[0].value}),a=y.useMemo(()=>M(i,Number(r||0)),[i,r]),l=y.useMemo(()=>!$e(i),[i]),p=u=>{s(u||0),e.onChange(M(i,Number(u||0)))},f=u=>{u!==void 0&&(s(D(u,0)),o(u),e.onChange(u))};return e.action.current=()=>a,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:l,value:r,max:20,min:0,onChange:p})}),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:r,col:s}=e.value,i=N.useDependency(c.LocaleService),o=y.useRef(()=>""),a=i.t,l=Ke(),p=y.useMemo(()=>[{label:"sheet.numfmt.general",component:nt},{label:"sheet.numfmt.accounting",component:Je},{label:"sheet.numfmt.currency",component:Ze},{label:"sheet.numfmt.date",component:et},{label:"sheet.numfmt.thousandthPercentile",component:st}].map(P=>({...P,label:a(P.label)})),[]),[f,u]=y.useState(S),[m,g]=y.useState(()=>`${r}_${s}`),{mark:_,userHabitCurrency:v}=ze(()=>g(`${r}_${s}_userCurrency'`)),b=y.useMemo(()=>{var P;return(P=p.find(U=>U.label===f))==null?void 0:P.component},[f]);function S(){return[tt,Ye,Xe,Qe,rt].reduce((U,Ne,Ee)=>U||(Ne(n)?p[Ee].label:""),"")||p[0].label}const T=p.map(P=>({label:P.label,value:P.label})),L=P=>{u(P),l(()=>e.onChange({type:"change",value:o.current()||""}))},F=P=>{e.onChange({type:"change",value:P})},re=()=>{const P=o.current()||"",U=k(P);U&&_(U),e.onChange({type:"confirm",value:P})},A=()=>{e.onChange({type:"cancel",value:""})},se={onChange:F,defaultValue:t,defaultPattern:n,action:o};return y.useEffect(()=>{u(S()),g(`${r}_${s}`)},[r,s]),h.jsxs("div",{className:"numfmt-panel p-b-20",children:[h.jsxs("div",{children:[h.jsx("div",{className:"label m-t-14",children:a("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:b&&h.jsx(fe.Provider,{value:v,children:y.createElement(b,{...se,key:m})})})]}),h.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[h.jsx(E.Button,{size:"small",onClick:A,className:"m-r-12",children:a("sheet.numfmt.cancel")}),h.jsx(E.Button,{type:"primary",size:"small",onClick:re,children:a("sheet.numfmt.confirm")})]})]})},he={id:"sheet.command.numfmt.set.percent",type:c.CommandType.COMMAND,handler:async e=>{const t=e.get(c.ICommandService),r=e.get(d.SheetsSelectionsService).getCurrentSelections();if(!r||!r.length)return!1;const s=[],i="0%";return r.forEach(a=>{c.Range.foreach(a.range,(l,p)=>{s.push({row:l,col:p,pattern:i,type:"percent"})})}),await t.executeCommand($.id,{values:s})}};var ot=Object.defineProperty,ct=Object.getOwnPropertyDescriptor,at=(e,t,n,r)=>{for(var s=r>1?void 0:r?ct(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(t,n,s):o(s))||s);return r&&s&&ot(t,n,s),s},R=(e,t)=>(n,r)=>t(n,r,e);let K=class extends c.Disposable{constructor(t,n,r,s,i,o,a,l,p,f){super();W(this,"_previewPattern","");W(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=n,this._univerInstanceService=r,this._commandService=s,this._selectionManagerService=i,this._renderManagerService=o,this._numfmtService=a,this._componentManager=l,this._sidebarService=p,this._localeService=f,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var b;const t=this._sidebarService,n=this._selectionManagerService,r=this._commandService,s=this._univerInstanceService,i=this._numfmtService,o=this._localeService,l=(((b=n.getCurrentSelections())==null?void 0:b.map(S=>S.range))||[])[0];if(!l)return!1;const p=s.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),f=p.getActiveSheet();if(!f)return!1;const u=f.getCellRaw(l.startRow,l.startColumn),m=i.getValue(p.getUnitId(),f.getSheetId(),l.startRow,l.startColumn);let g="";m&&(g=m.pattern);const _=(u==null?void 0:u.t)===c.CellValueType.NUMBER?u.v:12345678,v={onChange:S=>{var T;if(S.type==="change")this._previewPattern=S.value,this._forceUpdate();else if(S.type==="confirm"){const L=((T=n.getCurrentSelections())==null?void 0:T.map(A=>A.range))||[],F={values:[]},re=Z(S.value);L.forEach(A=>{c.Range.foreach(A,(se,P)=>{F.values.push({row:se,col:P,pattern:S.value,type:re})})}),r.executeCommand($.id,F),t.close()}else S.type==="cancel"&&t.close()},value:{defaultPattern:g,defaultValue:_,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=t.open({header:{title:o.t("sheet.numfmt.title")},children:{label:ce,...v},onClose:()=>{this._forceUpdate(),r.executeCommand(z.id)}}),!0}_forceUpdate(t){var r;const n=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET).getUnitId());n==null||n.with(x.SheetSkeletonManagerService).reCalculate(),(r=n==null?void 0:n.mainComponent)==null||r.makeDirty()}_initCommands(){[le,me,ue,he,H,z,$].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this._componentManager.register(ce,it)}_initRealTimeRenderingInterceptor(){const t=new O.Observable(r=>{this._commandService.onCommandExecuted(s=>{s.id===H.id&&r.next(!0),s.id===z.id&&r.next(!1)})}),n=O.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(q.map(r=>r?r.map(s=>s.range):[]))]);this.disposeWithMe(c.toDisposable(n.pipe(q.switchMap(([r,s])=>new O.Observable(i=>{const o=new c.DisposableCollection;return r&&s.length&&i.next({selectionRanges:s,disposableCollection:o}),()=>{o.dispose()}})),q.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:r,selectionRanges:s})=>{var o,a;const i=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);this.openPanel(),r.add(this._sheetInterceptorService.intercept(d.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,handler:(l,p,f)=>{const{row:u,col:m}=p,g=f(l)||{};if(s.find(_=>_.startColumn<=m&&_.endColumn>=m&&_.startRow<=u&&_.endRow>=u)){const _=p.worksheet.getCellRaw(u,m),v=_==null?void 0:_.v,b=_==null?void 0:_.t;if(v==null||b!==c.CellValueType.NUMBER||this._previewPattern===null)return g;const S=ee(this._previewPattern,v,this._localeService.getCurrentLocale());if(S.color){const L=this._themeService.getCurrentTheme()[`${S.color}500`];return{...g,v:S.result,t:c.CellValueType.STRING,s:{cl:{rgb:L}}}}return{...g,v:S.result,t:c.CellValueType.STRING}}return g}})),(a=(o=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:o.mainComponent)==null||a.makeDirty()})))}_commandExecutedListener(){const t=[d.RemoveNumfmtMutation.id,d.SetNumfmtMutation.id];this.disposeWithMe(new O.Observable(n=>{const r=this._commandService.onCommandExecuted(s=>{if(t.includes(s.id)){const i=s.params;n.next(i.unitId)}});return()=>r.dispose()}).pipe(q.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)})}};K=at([c.OnLifecycle(c.LifecycleStages.Rendered,K),R(0,C.Inject(d.SheetInterceptorService)),R(1,C.Inject(c.ThemeService)),R(2,c.IUniverInstanceService),R(3,c.ICommandService),R(4,C.Inject(d.SheetsSelectionsService)),R(5,Se.IRenderManagerService),R(6,d.INumfmtService),R(7,C.Inject(I.ComponentManager)),R(8,I.ISidebarService),R(9,C.Inject(c.LocaleService))],K);var lt=Object.defineProperty,ut=Object.getOwnPropertyDescriptor,mt=(e,t,n,r)=>{for(var s=r>1?void 0:r?ut(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(t,n,s):o(s))||s);return r&&s&&lt(t,n,s),s},V=(e,t)=>(n,r)=>t(n,r,e);const dt=()=>{let e=[];return{add:(s,i,o,a,l)=>e.push({unitId:s,subUnitId:i,row:o,col:a,value:l}),getEffects:()=>e,clean:()=>{e=[]}}};let Y=class extends c.Disposable{constructor(t,n,r,s,i){super();W(this,"_collectEffectMutation",dt());this._sheetInterceptorService=t,this._numfmtService=n,this._univerInstanceService=r,this._injector=s,this._editorBridgeService=i,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(c.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{handler:(t,n,r)=>{const s=n.row,i=n.col,o=this._numfmtService.getValue(n.unitId,n.subUnitId,s,i);if(o)switch(Z(o.pattern)){case"scientific":case"percent":case"currency":case"grouped":case"number":return n.worksheet.getCellRaw(s,i);case"date":case"time":case"datetime":default:return r&&r(t)}return r(t)}})))}_initInterceptorEditorEnd(){this._editorBridgeService&&this.disposeWithMe(c.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{handler:(t,n,r)=>{var f;this._collectEffectMutation.clean();const s=this._numfmtService.getValue(n.unitId,n.subUnitId,n.row,n.col),i=(f=s&&Z(s.pattern))!=null?f:"",o=()=>{s&&this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,null)};if(!(t!=null&&t.v))return r(t);const a=String(t.v),l=j.numfmt.parseDate(a)||j.numfmt.parseTime(a);if(!!l){if(l&&l.z){const u=Number(l.v);return this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,{pattern:l.z}),{...t,v:u,t:c.CellValueType.NUMBER}}}else(["date","time","datetime"].includes(i)||!ft(a))&&o();return r(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(n){var r;switch(n.id){case d.SetRangeValuesCommand.id:{const s=t._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),i=s.getUnitId(),o=(r=s.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return{redos:[],undos:[]};const a=t._collectEffectMutation.getEffects();if(!a.length)return{redos:[],undos:[]};const l=a.filter(m=>{var g;return!!((g=m.value)!=null&&g.pattern)}).map(m=>({row:m.row,col:m.col,pattern:m.value.pattern})),p=a.filter(m=>{var g;return!((g=m.value)!=null&&g.pattern)}).map(m=>({startRow:m.row,endColumn:m.col,startColumn:m.col,endRow:m.row})),f=[],u=[];if(l){const m={id:d.SetNumfmtMutation.id,params:d.transformCellsToRange(i,o,l)};f.push(m),u.push(...d.factorySetNumfmtUndoMutation(t._injector,m.params))}if(p){const m={id:d.RemoveNumfmtMutation.id,params:{unitId:i,subUnitId:o,ranges:p}};f.push(m),u.push(...d.factoryRemoveNumfmtUndoMutation(t._injector,m.params))}return{redos:f,undos:u.reverse()}}}return{redos:[],undos:[]}}}))}};Y=mt([c.OnLifecycle(c.LifecycleStages.Rendered,Y),V(0,C.Inject(d.SheetInterceptorService)),V(1,C.Inject(d.INumfmtService)),V(2,C.Inject(c.IUniverInstanceService)),V(3,C.Inject(C.Injector)),V(4,C.Optional(x.IEditorBridgeService))],Y);function ft(e){return/^-?\d+(\.\d+)?$/.test(e)}var ht=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,vt=(e,t,n,r)=>{for(var s=r>1?void 0:r?pt(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(t,n,s):o(s))||s);return r&&s&&ht(t,n,s),s},St=(e,t)=>(n,r)=>t(n,r,e);let J=class extends c.Disposable{constructor(e){super(),this._localeService=e}};J=vt([c.OnLifecycle(c.LifecycleStages.Rendered,J),St(0,C.Inject(c.LocaleService))],J);const X=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:j.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Ie="sheet.numfmt.moreNumfmtType",Te="sheet.numfmt.moreNumfmtType.options",gt=e=>{var r;const t=N.useDependency(c.LocaleService),n=(r=e.value)!=null?r: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(),r=N.useDependency(d.SheetsSelectionsService),s=a=>{const l=r.getCurrentLastSelection();if(!l)return;const p=n.get(Se.ITextSelectionRenderManager),f=l.range,u=[];c.Range.foreach(f,(m,g)=>{a?u.push({row:m,col:g,pattern:a,type:Z(a)}):u.push({row:m,col:g})}),e.executeCommand($.id,{values:u}),p.focus()},i=a=>{if(a===0)s(null);else if(a===X.length-1)e.executeCommand(H.id);else{const l=X[a];l.pattern&&s(l.pattern)}},o=1220;return h.jsx("div",{className:"more-numfmt-type-options",children:X.map((a,l)=>a==="|"?h.jsx("div",{className:"line m-t-4",onClick:p=>p.stopPropagation()},l):h.jsxs("div",{className:"option-item m-t-4",onClick:()=>{i(l)},children:[h.jsx("div",{children:t.t(a.label)}),h.jsx("div",{className:"m-l-26",children:a.pattern?ee(a.pattern||"",o,t.getCurrentLocale()).result:""})]},l))})},bt=e=>({icon:"RmbSingle",id:ue.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$:x.getCurrentRangeDisable$(e,{workbookTypes:[d.WorkbookEditablePermission],worksheetTypes:[d.WorksheetEditPermission,d.WorksheetSetCellStylePermission],rangeTypes:[d.RangeProtectionPermissionEditPoint]})}),yt=e=>({icon:"AddDigitsSingle",id:le.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$:x.getCurrentRangeDisable$(e,{workbookTypes:[d.WorkbookEditablePermission],worksheetTypes:[d.WorksheetEditPermission,d.WorksheetSetCellStylePermission],rangeTypes:[d.RangeProtectionPermissionEditPoint]})}),Ct=e=>({icon:"ReduceDigitsSingle",id:me.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$:x.getCurrentRangeDisable$(e,{workbookTypes:[d.WorkbookEditablePermission],worksheetTypes:[d.WorksheetEditPermission,d.WorksheetSetCellStylePermission],rangeTypes:[d.RangeProtectionPermissionEditPoint]})}),It=e=>({icon:"PercentSingle",id:he.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$:x.getCurrentRangeDisable$(e,{workbookTypes:[d.WorkbookEditablePermission],worksheetTypes:[d.WorksheetEditPermission,d.WorksheetSetCellStylePermission],rangeTypes:[d.RangeProtectionPermissionEditPoint]})}),Tt=e=>{const t=e.get(d.INumfmtService),n=e.get(c.IUniverInstanceService),r=e.get(c.ICommandService),s=e.get(c.LocaleService),i=e.get(d.SheetsSelectionsService),o=x.deriveStateFromActiveSheet$(n,"",({workbook:a,worksheet:l})=>new O.Observable(p=>O.merge(i.selectionMoveEnd$,new O.Observable(f=>{const u=[d.RemoveNumfmtMutation.id,d.SetNumfmtMutation.id],m=r.onCommandExecuted(g=>{u.includes(g.id)&&f.next(null)});return()=>m.dispose()})).subscribe(()=>{const f=i.getCurrentSelections();if(f&&f[0]){const u=f[0].range,m=u.startRow,g=u.startColumn,_=t.getValue(a.getUnitId(),l.getSheetId(),m,g),v=_==null?void 0:_.pattern;let b=s.t("sheet.numfmt.general");if(v){const S=X.filter(T=>typeof T=="object"&&T.pattern).find(T=>te(v,T.pattern));S&&typeof S=="object"&&S.pattern?b=s.t(S.label):b=s.t("sheet.numfmt.moreFmt")}p.next(b)}})));return{label:Ie,id:H.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$:x.getCurrentRangeDisable$(e,{workbookTypes:[d.WorkbookEditablePermission],worksheetTypes:[d.WorksheetSetCellStylePermission,d.WorksheetEditPermission],rangeTypes:[d.RangeProtectionPermissionEditPoint]})}};var Pt=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,Nt=(e,t,n,r)=>{for(var s=r>1?void 0:r?Mt(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(t,n,s):o(s))||s);return r&&s&&Pt(t,n,s),s},oe=(e,t)=>(n,r)=>t(n,r,e);const Et={};let B=class extends c.Disposable{constructor(e,t,n,r){super(),this._config=e,this._injector=t,this._componentManager=n,this._menuService=r,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(Ie,gt)),this.disposeWithMe(this._componentManager.register(Te,_t))}};B=Nt([c.OnLifecycle(c.LifecycleStages.Rendered,B),oe(1,C.Inject(C.Injector)),oe(2,C.Inject(I.ComponentManager)),oe(3,C.Inject(I.IMenuService))],B);var Pe=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,Ot=(e,t,n)=>t in e?Pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jt=(e,t,n,r)=>{for(var s=r>1?void 0:r?Rt(t,n):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(t,n,s):o(s))||s);return r&&s&&Pe(t,n,s),s},xt=(e,t)=>(n,r)=>t(n,r,e),Me=(e,t,n)=>Ot(e,typeof t!="symbol"?t+"":t,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([de,{useClass:K,lazy:!1}]),this._injector.add([Y]),this._injector.add([Q]),this._injector.add([G]),this._injector.add([J]),this._injector.add([B,{useFactory:()=>this._injector.createInstance(B,this._config)}])}};Me(exports.UniverSheetsNumfmtPlugin,"pluginName",ce);Me(exports.UniverSheetsNumfmtPlugin,"type",c.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=jt([c.DependentOn(d.UniverSheetsPlugin,x.UniverSheetsUIPlugin),xt(1,C.Inject(C.Injector))],exports.UniverSheetsNumfmtPlugin);exports.AddDecimalCommand=le;exports.CloseNumfmtPanelOperator=z;exports.OpenNumfmtPanelOperator=H;exports.SetCurrencyCommand=ue;exports.SetNumfmtCommand=$;exports.SetPercentCommand=he;exports.SubtractDecimalCommand=me;exports.getPatternPreview=ee;
9
+ */var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function q(c,a,g){var b,d={},e=null,h=null;g!==void 0&&(e=""+g),a.key!==void 0&&(e=""+a.key),a.ref!==void 0&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)d[b]===void 0&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__name(q,"q");reactJsxRuntime_production_min.Fragment=l;reactJsxRuntime_production_min.jsx=q;reactJsxRuntime_production_min.jsxs=q;jsxRuntime.exports=reactJsxRuntime_production_min;var jsxRuntimeExports=jsxRuntime.exports;const UserHabitCurrencyContext=require$$0.createContext([]),currencySymbols=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"];var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key2,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$5"),_a2;let UserHabitController=(_a2=class{constructor(_localStorageService){this._localStorageService=_localStorageService}_getKey(habit){return`userHabitController_${habit}`}async addHabit(habit,initValue){const key2=this._getKey(habit);return this._localStorageService.getItem(key2).then(item=>{item||this._localStorageService.setItem(key2,initValue)})}markHabit(habit,value){const key2=this._getKey(habit);this._localStorageService.getItem(key2).then(list=>{if(list){const index=list.findIndex(item=>item===value);index>-1&&list.splice(index,1),list.unshift(value),this._localStorageService.setItem(key2,list)}})}async getHabit(habit,sortList){const key2=this._getKey(habit),result=await this._localStorageService.getItem(key2);if(sortList&&result){const priority=result.map((item,index,arr)=>{const length=arr.length;return{value:item,priority:length-index}});return sortList.sort((a,b)=>{var _a8,_b;const ap=((_a8=priority.find(item=>item.value===a))==null?void 0:_a8.priority)||-1;return(((_b=priority.find(item=>item.value===b))==null?void 0:_b.priority)||-1)-ap})}return result||[]}deleteHabit(habit){this._localStorageService.removeItem(habit)}},__name(_a2,"UserHabitController"),_a2);UserHabitController=__decorateClass$5([__decorateParam$5(0,core.Inject(core.ILocalStorageService))],UserHabitController);const key$1="numfmtCurrency",useCurrencyOptions=__name(onOptionChange=>{const userHabitController=core.useDependency(UserHabitController),[options,optionsSet]=require$$0.useState(currencySymbols);return require$$0.useEffect(()=>{userHabitController.addHabit("numfmtCurrency",[]).then(()=>{userHabitController.getHabit(key$1,[...currencySymbols]).then(list=>{optionsSet(list),onOptionChange&&onOptionChange(list)})})},[]),{userHabitCurrency:options,mark:__name(v=>{userHabitController.markHabit(key$1,v)},"mark")}},"useCurrencyOptions"),useNextTick=__name(()=>{const effectList=require$$0.useRef([]),[value,dispatch]=require$$0.useState({});return require$$0.useEffect(()=>{effectList.current.forEach(fn=>{fn()}),effectList.current=[]},[value]),__name(fn=>{effectList.current.push(fn),dispatch({})},"nextTick")},"useNextTick"),getCurrencyType=__name(pattern=>currencySymbols.find(code=>pattern.includes(code)),"getCurrencyType"),isAccountingPanel=__name(pattern=>!!getCurrencyType(pattern)&&pattern.startsWith("_("),"isAccountingPanel"),AccountingPanel=__name(props=>{const[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",2)),userHabitCurrency=require$$0.useContext(UserHabitCurrencyContext),[suffix,suffixSet]=require$$0.useState(()=>getCurrencyType(props.defaultPattern)||userHabitCurrency[0]),options=require$$0.useMemo(()=>userHabitCurrency.map(key2=>({label:key2,value:key2})),[]),t=core.useDependency(core.LocaleService).t;props.action.current=()=>setPatternDecimal(`_("${suffix}"* #,##0${decimal>0?".0":""}_)`,decimal);const onSelect=__name(v=>{suffixSet(v),props.onChange(setPatternDecimal(`_("${v}"* #,##0${decimal>0?".0":""}_)`,decimal))},"onSelect"),onDecimalChange=__name(v=>{const decimal2=v||0;decimalSet(decimal2),props.onChange(setPatternDecimal(`_("${suffix}"* #,##0${decimal2>0?".0":""}_)`,decimal2))},"onDecimalChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsxs("div",{className:"m-t-16 options ",children:[jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-120",children:jsxRuntimeExports.jsx(design.InputNumber,{value:decimal,max:20,min:0,onChange:onDecimalChange})})]}),jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.currencyType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-140",children:jsxRuntimeExports.jsx(design.Select,{onChange:onSelect,options,value:suffix})})]})]}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.accountingDes")})]})},"AccountingPanel"),getCurrencyFormatOptions=__name(suffix=>CURRENCYFORMAT.map(item=>({label:item.label(suffix),value:item.suffix(suffix),color:item.color})),"getCurrencyFormatOptions"),getDateFormatOptions=__name(()=>DATEFMTLISG.map(item=>({label:item.label,value:item.suffix})),"getDateFormatOptions"),getNumberFormatOptions=__name(()=>NUMBERFORMAT.map(item=>({label:item.label,value:item.suffix,color:item.color})),"getNumberFormatOptions"),isCurrencyPanel=__name(pattern=>!!getCurrencyType(pattern)&&!pattern.startsWith("_("),"isCurrencyPanel"),CurrencyPanel=__name(props=>{const t=core.useDependency(core.LocaleService).t,userHabitCurrency=require$$0.useContext(UserHabitCurrencyContext),[suffix,suffixSet]=require$$0.useState(()=>getCurrencyType(props.defaultPattern)||userHabitCurrency[0]),[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",2)),[pattern,patternSet]=require$$0.useState(()=>{var _a8;const negativeOptions2=getCurrencyFormatOptions(suffix);return((_a8=negativeOptions2.find(item=>isPatternEqualWithoutDecimal(item.value,props.defaultPattern)))==null?void 0:_a8.value)||negativeOptions2[0].value}),negativeOptions=require$$0.useMemo(()=>getCurrencyFormatOptions(suffix),[suffix]),options=require$$0.useMemo(()=>userHabitCurrency.map(key2=>({label:key2,value:key2})),[userHabitCurrency]);props.action.current=()=>setPatternDecimal(pattern,decimal);const onSelect=__name(value=>{if(value===void 0)return;suffixSet(value);const pattern2=getCurrencyFormatOptions(value)[0].value;patternSet(pattern2),props.onChange(setPatternDecimal(pattern2,decimal))},"onSelect"),onChange=__name(value=>{value!==void 0&&(patternSet(value),props.onChange(setPatternDecimal(value,decimal)))},"onChange"),onDecimalChange=__name(v=>{decimalSet(v||0),props.onChange(setPatternDecimal(pattern,v||0))},"onDecimalChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsxs("div",{className:"m-t-16 options ",children:[jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-120",children:jsxRuntimeExports.jsx(design.InputNumber,{value:decimal,max:20,min:0,onChange:onDecimalChange})})]}),jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.currencyType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-140",children:jsxRuntimeExports.jsx(design.Select,{onChange:onSelect,options,value:suffix})})]})]}),jsxRuntimeExports.jsx("div",{className:"m-t-16 label",children:t("sheet.numfmt.negType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.SelectList,{onChange,options:negativeOptions,value:pattern})}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.currencyDes")})]})},"CurrencyPanel"),isDatePanel=__name(pattern=>{const info=engineNumfmt.numfmt.getInfo(pattern);return getDateFormatOptions().map(item=>item.value).includes(pattern)||["date","datetime","time"].includes(info.type)},"isDatePanel"),DatePanel=__name(props=>{const options=require$$0.useMemo(getDateFormatOptions,[]),t=core.useDependency(core.LocaleService).t,[suffix,suffixSet]=require$$0.useState(()=>{if(props.defaultPattern){const item=options.find(item2=>item2.value===props.defaultPattern);if(item)return item.value}return options[0].value});props.action.current=()=>suffix;const onChange=__name(v=>{v!==void 0&&(suffixSet(v),props.onChange(v))},"onChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"m-t-16 label",children:t("sheet.numfmt.dateType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.SelectList,{value:suffix,options,onChange})}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.dateDes")})]})},"DatePanel"),isGeneralPanel=__name(pattern=>!pattern,"isGeneralPanel"),GeneralPanel=__name(props=>{const t=core.useDependency(core.LocaleService).t;return props.action.current=()=>"",jsxRuntimeExports.jsx("div",{children:jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.generalDes")})})},"GeneralPanel"),isThousandthPercentilePanel=__name(pattern=>getNumberFormatOptions().some(item=>isPatternEqualWithoutDecimal(item.value,pattern)),"isThousandthPercentilePanel"),ThousandthPercentilePanel=__name(props=>{const localeService=core.useDependency(core.LocaleService),options=require$$0.useMemo(getNumberFormatOptions,[]),[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",0)),[suffix,suffixSet]=require$$0.useState(()=>{const item=options.find(item2=>isPatternEqualWithoutDecimal(item2.value,props.defaultPattern||""));return(item==null?void 0:item.value)||options[0].value}),pattern=require$$0.useMemo(()=>setPatternDecimal(suffix,Number(decimal||0)),[suffix,decimal]),isInputDisable=require$$0.useMemo(()=>!isPatternHasDecimal(suffix),[suffix]),handleDecimalChange=__name(decimal2=>{decimalSet(decimal2||0),props.onChange(setPatternDecimal(suffix,Number(decimal2||0)))},"handleDecimalChange"),handleClick=__name(v=>{v!==void 0&&(decimalSet(getDecimalFromPattern(v,0)),suffixSet(v),props.onChange(v))},"handleClick");return props.action.current=()=>pattern,jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"m-t-16 label",children:localeService.t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.InputNumber,{disabled:isInputDisable,value:decimal,max:20,min:0,onChange:handleDecimalChange})}),jsxRuntimeExports.jsxs("div",{className:"m-t-16 label",children:[" ",localeService.t("sheet.numfmt.negType")]}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.SelectList,{onChange:handleClick,options,value:suffix})}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:localeService.t("sheet.numfmt.thousandthPercentileDes")})]})},"ThousandthPercentilePanel");var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n2=arguments.length;i<n2;i++){s=arguments[i];for(var p2 in s)Object.prototype.hasOwnProperty.call(s,p2)&&(t[p2]=s[p2])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p2 in s)Object.prototype.hasOwnProperty.call(s,p2)&&e.indexOf(p2)<0&&(t[p2]=s[p2]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p2=Object.getOwnPropertySymbols(s);i<p2.length;i++)e.indexOf(p2[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p2[i])&&(t[p2[i]]=s[p2[i]]);return t},IconBase=require$$0.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=require$$0.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return require$$0.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a8){var key2=_a8[0],value=_a8[1];typeof value=="string"&&(attrs[key2]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a8,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a8=node.children)===null||_a8===void 0)&&_a8.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid");IconBase.displayName="UniverIcon";var element={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},CheckMarkSingle=require$$0.forwardRef(function(props,ref){return require$$0.createElement(IconBase,Object.assign({},props,{id:"check-mark-single",ref,icon:element}))});CheckMarkSingle.displayName="CheckMarkSingle";const customFormatTitle="univer-custom-format-title",customFormatInput="univer-custom-format-input",customFormatHistoryList="univer-custom-format-history-list",customFormatHistoryListItem="univer-custom-format-history-list-item",customFormatHistoryListItemIconWrap="univer-custom-format-history-list-item-icon-wrap",customFormatDes="univer-custom-format-des",styles={customFormatTitle,customFormatInput,customFormatHistoryList,customFormatHistoryListItem,customFormatHistoryListItemIconWrap,customFormatDes},key="customFormat",historyPatternKey="numfmt_custom_pattern";function CustomFormat(props){const{defaultPattern,action,onChange}=props,userHabitController=core.useDependency(UserHabitController),localStorageService=core.useDependency(core.ILocalStorageService),localeService=core.useDependency(core.LocaleService),[pattern,patternSet]=require$$0.useState(defaultPattern);action.current=()=>(userHabitController.markHabit(key,pattern),localStorageService.getItem(historyPatternKey).then((list=[])=>{const _list=[...new Set([pattern,...list||[]])].splice(0,10).filter(e=>!!e);localStorageService.setItem(historyPatternKey,_list)}),pattern);const[options,optionsSet]=require$$0.useState([]);require$$0.useEffect(()=>{localStorageService.getItem(historyPatternKey).then(historyList=>{const list=[...CURRENCYFORMAT.map(item=>item.suffix("$")),...DATEFMTLISG.map(item=>item.suffix),...NUMBERFORMAT.map(item=>item.suffix)];list.push(...historyList||[]),userHabitController.addHabit(key,[]).finally(()=>{userHabitController.getHabit(key,list).then(list2=>{optionsSet([...new Set(list2)])})})})},[]);const handleClick=__name(p2=>{patternSet(p2),onChange(p2)},"handleClick"),handleBlur=__name(()=>{onChange(pattern)},"handleBlur");return jsxRuntimeExports.jsxs("div",{className:styles.customFormat,children:[jsxRuntimeExports.jsx("div",{className:styles.customFormatTitle,children:localeService.t("sheet.numfmt.customFormat")}),jsxRuntimeExports.jsx(design.Input,{placeholder:localeService.t("sheet.numfmt.customFormat"),onBlur:handleBlur,value:pattern,onChange:patternSet,className:styles.customFormatInput}),jsxRuntimeExports.jsx("div",{className:styles.customFormatHistoryList,children:options.map(p2=>jsxRuntimeExports.jsxs("div",{onClick:__name(()=>handleClick(p2),"onClick"),className:styles.customFormatHistoryListItem,children:[jsxRuntimeExports.jsx("div",{className:styles.customFormatHistoryListItemIconWrap,children:pattern===p2&&jsxRuntimeExports.jsx(CheckMarkSingle,{})}),jsxRuntimeExports.jsx("div",{children:p2})]},p2))}),jsxRuntimeExports.jsx("div",{className:styles.customFormatDes,children:localeService.t("sheet.numfmt.customFormatDes")})]})}__name(CustomFormat,"CustomFormat");const SheetNumfmtPanel=__name(props=>{const{defaultValue,defaultPattern,row,col}=props.value,localeService=core.useDependency(core.LocaleService),getCurrentPattern=require$$0.useRef(()=>""),t=localeService.t,nextTick=useNextTick(),typeOptions=require$$0.useMemo(()=>[{label:"sheet.numfmt.general",component:GeneralPanel},{label:"sheet.numfmt.accounting",component:AccountingPanel},{label:"sheet.numfmt.currency",component:CurrencyPanel},{label:"sheet.numfmt.date",component:DatePanel},{label:"sheet.numfmt.thousandthPercentile",component:ThousandthPercentilePanel},{label:"sheet.numfmt.customFormat",component:CustomFormat}].map(item=>({...item,label:t(item.label)})),[]),[type,typeSet]=require$$0.useState(findDefaultType),[key2,keySet]=require$$0.useState(()=>`${row}_${col}`),{mark,userHabitCurrency}=useCurrencyOptions(()=>keySet(`${row}_${col}_userCurrency'`)),BusinessComponent=require$$0.useMemo(()=>{var _a8;return(_a8=typeOptions.find(item=>item.label===type))==null?void 0:_a8.component},[type]);function findDefaultType(){return[isGeneralPanel,isAccountingPanel,isCurrencyPanel,isDatePanel,isThousandthPercentilePanel].reduce((pre,curFn,index)=>pre||(curFn(defaultPattern)?typeOptions[index].label:""),"")||typeOptions[0].label}__name(findDefaultType,"findDefaultType");const selectOptions=typeOptions.map(option=>({label:option.label,value:option.label})),handleSelect=__name(value=>{typeSet(value),nextTick(()=>props.onChange({type:"change",value:getCurrentPattern.current()||""}))},"handleSelect"),handleChange=__name(v=>{props.onChange({type:"change",value:v})},"handleChange"),handleConfirm=__name(()=>{const pattern=getCurrentPattern.current()||"",currency=getCurrencyType(pattern);currency&&mark(currency),props.onChange({type:"confirm",value:pattern})},"handleConfirm"),handleCancel=__name(()=>{props.onChange({type:"cancel",value:""})},"handleCancel"),subProps={onChange:handleChange,defaultValue,defaultPattern,action:getCurrentPattern};return require$$0.useEffect(()=>{typeSet(findDefaultType()),keySet(`${row}_${col}`)},[row,col]),jsxRuntimeExports.jsxs("div",{className:"numfmt-panel p-b-20",children:[jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"label m-t-14",children:t("sheet.numfmt.numfmtType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.Select,{onChange:handleSelect,options:selectOptions,value:type,style:{width:"100%"}})}),jsxRuntimeExports.jsx("div",{children:BusinessComponent&&jsxRuntimeExports.jsx(UserHabitCurrencyContext.Provider,{value:userHabitCurrency,children:require$$0.createElement(BusinessComponent,{...subProps,key:key2})})})]}),jsxRuntimeExports.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[jsxRuntimeExports.jsx(design.Button,{size:"small",onClick:handleCancel,className:"m-r-12",children:t("sheet.numfmt.cancel")}),jsxRuntimeExports.jsx(design.Button,{type:"primary",size:"small",onClick:handleConfirm,children:t("sheet.numfmt.confirm")})]})]})},"SheetNumfmtPanel"),SetPercentCommand={id:"sheet.command.numfmt.set.percent",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selections=accessor.get(sheets.SheetsSelectionsService).getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix="0%";return selections.forEach(selection=>{core.Range.foreach(selection.range,(row,col)=>{values.push({row,col,pattern:suffix,type:"percent"})})}),await commandService.executeCommand(SetNumfmtCommand.id,{values})},"handler")};var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key2,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$4"),_a3;let NumfmtController=(_a3=class extends core.Disposable{constructor(_sheetInterceptorService,_themeService,_univerInstanceService,_commandService,_selectionManagerService,_renderManagerService,_numfmtService,_componentManager,_sidebarService,_localeService){super();__publicField(this,"_previewPattern","");__publicField(this,"_sidebarDisposable",null);this._sheetInterceptorService=_sheetInterceptorService,this._themeService=_themeService,this._univerInstanceService=_univerInstanceService,this._commandService=_commandService,this._selectionManagerService=_selectionManagerService,this._renderManagerService=_renderManagerService,this._numfmtService=_numfmtService,this._componentManager=_componentManager,this._sidebarService=_sidebarService,this._localeService=_localeService,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var _a8;const sidebarService=this._sidebarService,selectionManagerService=this._selectionManagerService,commandService=this._commandService,univerInstanceService=this._univerInstanceService,numfmtService=this._numfmtService,localeService=this._localeService,range=(((_a8=selectionManagerService.getCurrentSelections())==null?void 0:_a8.map(s=>s.range))||[])[0];if(!range)return!1;const workbook=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),sheet=workbook.getActiveSheet();if(!sheet)return!1;const cellValue=sheet.getCellRaw(range.startRow,range.startColumn),numfmtValue=numfmtService.getValue(workbook.getUnitId(),sheet.getSheetId(),range.startRow,range.startColumn);let pattern="";numfmtValue&&(pattern=numfmtValue.pattern);const defaultValue=(cellValue==null?void 0:cellValue.t)===core.CellValueType.NUMBER?cellValue.v:12345678,props={onChange:__name(config=>{var _a9;if(config.type==="change")this._previewPattern=config.value,this._forceUpdate();else if(config.type==="confirm"){const selections2=((_a9=selectionManagerService.getCurrentSelections())==null?void 0:_a9.map(s=>s.range))||[],params={values:[]},patternType=getPatternType(config.value);selections2.forEach(rangeInfo=>{core.Range.foreach(rangeInfo,(row,col)=>{params.values.push({row,col,pattern:config.value,type:patternType})})}),commandService.executeCommand(SetNumfmtCommand.id,params),sidebarService.close()}else config.type==="cancel"&&sidebarService.close()},"onChange"),value:{defaultPattern:pattern,defaultValue,row:range.startRow,col:range.startColumn}};return this._sidebarDisposable=sidebarService.open({header:{title:localeService.t("sheet.numfmt.title")},children:{label:SHEET_NUMFMT_PLUGIN,...props},onClose:__name(()=>{this._forceUpdate(),commandService.executeCommand(CloseNumfmtPanelOperator.id)},"onClose")}),!0}_forceUpdate(unitId){var _a8;const renderUnit=this._renderManagerService.getRenderById(unitId!=null?unitId:this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET).getUnitId());renderUnit==null||renderUnit.with(sheetsUi.SheetSkeletonManagerService).reCalculate(),(_a8=renderUnit==null?void 0:renderUnit.mainComponent)==null||_a8.makeDirty()}_initCommands(){[AddDecimalCommand,SubtractDecimalCommand,SetCurrencyCommand,SetPercentCommand,OpenNumfmtPanelOperator,CloseNumfmtPanelOperator,SetNumfmtCommand].forEach(config=>{this.disposeWithMe(this._commandService.registerCommand(config))})}_initPanel(){this._componentManager.register(SHEET_NUMFMT_PLUGIN,SheetNumfmtPanel)}_initRealTimeRenderingInterceptor(){const isPanelOpenObserver=new rxjs.Observable(subscriber=>{this._commandService.onCommandExecuted(commandInfo=>{commandInfo.id===OpenNumfmtPanelOperator.id&&subscriber.next(!0),commandInfo.id===CloseNumfmtPanelOperator.id&&subscriber.next(!1)})}),combineOpenAndSelection$=rxjs.combineLatest([isPanelOpenObserver,this._selectionManagerService.selectionMoveEnd$.pipe(operators.map(selectionInfos=>selectionInfos?selectionInfos.map(selectionInfo=>selectionInfo.range):[]))]);this.disposeWithMe(core.toDisposable(combineOpenAndSelection$.pipe(operators.switchMap(([isOpen,selectionRanges])=>new rxjs.Observable(subscribe=>{const disposableCollection=new core.DisposableCollection;return isOpen&&selectionRanges.length&&subscribe.next({selectionRanges,disposableCollection}),()=>{disposableCollection.dispose()}})),operators.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection,selectionRanges})=>{var _a8,_b;const workbook=this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET);this.openPanel(),disposableCollection.add(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,handler:__name((cell,location,next)=>{const{row,col}=location,defaultValue=next(cell)||{};if(selectionRanges.find(range=>range.startColumn<=col&&range.endColumn>=col&&range.startRow<=row&&range.endRow>=row)){const rawValue=location.worksheet.getCellRaw(row,col),value=rawValue==null?void 0:rawValue.v,type=rawValue==null?void 0:rawValue.t;if(value==null||type!==core.CellValueType.NUMBER||this._previewPattern===null)return defaultValue;const info=getPatternPreview(this._previewPattern,value,this._localeService.getCurrentLocale());if(info.color){const color=this._themeService.getCurrentTheme()[`${info.color}500`];return{...defaultValue,v:info.result,t:core.CellValueType.STRING,s:{cl:{rgb:color}}}}return{...defaultValue,v:info.result,t:core.CellValueType.STRING}}return defaultValue},"handler")})),(_b=(_a8=this._renderManagerService.getRenderById(workbook.getUnitId()))==null?void 0:_a8.mainComponent)==null||_b.makeDirty()})))}_commandExecutedListener(){const commandList=[sheets.RemoveNumfmtMutation.id,sheets.SetNumfmtMutation.id];this.disposeWithMe(new rxjs.Observable(subscribe=>{const disposable=this._commandService.onCommandExecuted(command=>{if(commandList.includes(command.id)){const params=command.params;subscribe.next(params.unitId)}});return()=>disposable.dispose()}).pipe(operators.debounceTime(16)).subscribe(unitId=>this._forceUpdate(unitId)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).subscribe(unit=>{var _a8;unit||((_a8=this._sidebarDisposable)==null||_a8.dispose(),this._sidebarDisposable=null)})}},__name(_a3,"NumfmtController"),_a3);NumfmtController=__decorateClass$4([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtController),__decorateParam$4(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$4(1,core.Inject(core.ThemeService)),__decorateParam$4(2,core.IUniverInstanceService),__decorateParam$4(3,core.ICommandService),__decorateParam$4(4,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$4(5,engineRender.IRenderManagerService),__decorateParam$4(6,sheets.INumfmtService),__decorateParam$4(7,core.Inject(ui.ComponentManager)),__decorateParam$4(8,ui.ISidebarService),__decorateParam$4(9,core.Inject(core.LocaleService))],NumfmtController);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key2,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$3");const createCollectEffectMutation=__name(()=>{let list=[];return{add:__name((unitId,subUnitId,row,col,value)=>list.push({unitId,subUnitId,row,col,value}),"add"),getEffects:__name(()=>list,"getEffects"),clean:__name(()=>{list=[]},"clean")}},"createCollectEffectMutation");var _a4;let NumfmtEditorController=(_a4=class extends core.Disposable{constructor(_sheetInterceptorService,_numfmtService,_univerInstanceService,_injector,_editorBridgeService){super();__publicField(this,"_collectEffectMutation",createCollectEffectMutation());this._sheetInterceptorService=_sheetInterceptorService,this._numfmtService=_numfmtService,this._univerInstanceService=_univerInstanceService,this._injector=_injector,this._editorBridgeService=_editorBridgeService,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(core.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{handler:__name((value,context,next)=>{const row=context.row,col=context.col,numfmtCell=this._numfmtService.getValue(context.unitId,context.subUnitId,row,col);if(numfmtCell)switch(getPatternType(numfmtCell.pattern)){case"scientific":case"percent":case"currency":case"grouped":case"number":return context.worksheet.getCellRaw(row,col);case"date":case"time":case"datetime":default:return next&&next(value)}return next(value)},"handler")})))}_initInterceptorEditorEnd(){this._editorBridgeService&&this.disposeWithMe(core.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{handler:__name((value,context,next)=>{var _a8;this._collectEffectMutation.clean();const currentNumfmtValue=this._numfmtService.getValue(context.unitId,context.subUnitId,context.row,context.col),currentNumfmtType=(_a8=currentNumfmtValue&&getPatternType(currentNumfmtValue.pattern))!=null?_a8:"",clean=__name(()=>{currentNumfmtValue&&this._collectEffectMutation.add(context.unitId,context.subUnitId,context.row,context.col,null)},"clean");if(!(value!=null&&value.v))return next(value);const content=String(value.v),dateInfo=engineNumfmt.numfmt.parseDate(content)||engineNumfmt.numfmt.parseTime(content);if(!!dateInfo){if(dateInfo&&dateInfo.z){const v=Number(dateInfo.v);return this._collectEffectMutation.add(context.unitId,context.subUnitId,context.row,context.col,{pattern:dateInfo.z}),{...value,v,t:core.CellValueType.NUMBER}}}else(["date","time","datetime"].includes(currentNumfmtType)||!isNumeric(content))&&clean();return next(value)},"handler")})))}_initInterceptorCommands(){const self=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(command){var _a8;switch(command.id){case sheets.SetRangeValuesCommand.id:{const workbook=self._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),unitId=workbook.getUnitId(),subUnitId=(_a8=workbook.getActiveSheet())==null?void 0:_a8.getSheetId();if(!subUnitId)return{redos:[],undos:[]};const list=self._collectEffectMutation.getEffects();if(!list.length)return{redos:[],undos:[]};const cells=list.filter(item=>{var _a9;return!!((_a9=item.value)!=null&&_a9.pattern)}).map(item=>({row:item.row,col:item.col,pattern:item.value.pattern})),removeCells=list.filter(item=>{var _a9;return!((_a9=item.value)!=null&&_a9.pattern)}).map(item=>({startRow:item.row,endColumn:item.col,startColumn:item.col,endRow:item.row})),redos=[],undos=[];if(cells){const redo={id:sheets.SetNumfmtMutation.id,params:sheets.transformCellsToRange(unitId,subUnitId,cells)};redos.push(redo),undos.push(...sheets.factorySetNumfmtUndoMutation(self._injector,redo.params))}if(removeCells){const redo={id:sheets.RemoveNumfmtMutation.id,params:{unitId,subUnitId,ranges:removeCells}};redos.push(redo),undos.push(...sheets.factoryRemoveNumfmtUndoMutation(self._injector,redo.params))}return{redos,undos:undos.reverse()}}}return{redos:[],undos:[]}}}))}},__name(_a4,"NumfmtEditorController"),_a4);NumfmtEditorController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtEditorController),__decorateParam$3(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$3(1,core.Inject(sheets.INumfmtService)),__decorateParam$3(2,core.Inject(core.IUniverInstanceService)),__decorateParam$3(3,core.Inject(core.Injector)),__decorateParam$3(4,core.Optional(sheetsUi.IEditorBridgeService))],NumfmtEditorController);function isNumeric(str){return/^-?\d+(\.\d+)?$/.test(str)}__name(isNumeric,"isNumeric");var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key2,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$2"),_a5;let NumfmtI18nController=(_a5=class extends core.Disposable{constructor(_localeService){super(),this._localeService=_localeService}},__name(_a5,"NumfmtI18nController"),_a5);NumfmtI18nController=__decorateClass$2([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtI18nController),__decorateParam$2(0,core.Inject(core.LocaleService))],NumfmtI18nController);const MENU_OPTIONS=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:engineNumfmt.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],MORE_NUMFMT_TYPE_KEY="sheet.numfmt.moreNumfmtType",OPTIONS_KEY="sheet.numfmt.moreNumfmtType.options",MoreNumfmtType=__name(props=>{var _a8;const localeService=core.useDependency(core.LocaleService),value=(_a8=props.value)!=null?_a8:localeService.t("sheet.numfmt.general");return jsxRuntimeExports.jsx("span",{className:"more-numfmt-type",children:value})},"MoreNumfmtType"),Options=__name(()=>{const commandService=core.useDependency(core.ICommandService),localeService=core.useDependency(core.LocaleService),injector=core.useInjector(),selectionManagerService=core.useDependency(sheets.SheetsSelectionsService),setNumfmt=__name(pattern=>{const selection=selectionManagerService.getCurrentLastSelection();if(!selection)return;const textSelectionRenderManager=injector.get(engineRender.ITextSelectionRenderManager),range=selection.range,values=[];core.Range.foreach(range,(row,col)=>{pattern?values.push({row,col,pattern,type:getPatternType(pattern)}):values.push({row,col})}),commandService.executeCommand(SetNumfmtCommand.id,{values}),textSelectionRenderManager.focus()},"setNumfmt"),handleOnclick=__name(index=>{if(index===0)setNumfmt(null);else if(index===MENU_OPTIONS.length-1)commandService.executeCommand(OpenNumfmtPanelOperator.id);else{const item=MENU_OPTIONS[index];item.pattern&&setNumfmt(item.pattern)}},"handleOnclick"),defaultValue=1220;return jsxRuntimeExports.jsx("div",{className:"more-numfmt-type-options",children:MENU_OPTIONS.map((item,index)=>item==="|"?jsxRuntimeExports.jsx("div",{className:"line m-t-4",onClick:__name(e=>e.stopPropagation(),"onClick")},index):jsxRuntimeExports.jsxs("div",{className:"option-item m-t-4",onClick:__name(()=>{handleOnclick(index)},"onClick"),children:[jsxRuntimeExports.jsx("div",{children:localeService.t(item.label)}),jsxRuntimeExports.jsx("div",{className:"m-l-26",children:item.pattern?getPatternPreview(item.pattern||"",defaultValue,localeService.getCurrentLocale()).result:""})]},index))})},"Options"),CurrencyMenuItem=__name(accessor=>({icon:"RmbSingle",id:SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:ui.MenuItemType.BUTTON,group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission,sheets.WorksheetSetCellStylePermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}),"CurrencyMenuItem"),AddDecimalMenuItem=__name(accessor=>({icon:"AddDigitsSingle",id:AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:ui.MenuItemType.BUTTON,positions:[ui.MenuPosition.TOOLBAR_START],group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission,sheets.WorksheetSetCellStylePermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}),"AddDecimalMenuItem"),SubtractDecimalMenuItem=__name(accessor=>({icon:"ReduceDigitsSingle",id:SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:ui.MenuItemType.BUTTON,group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission,sheets.WorksheetSetCellStylePermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}),"SubtractDecimalMenuItem"),PercentMenuItem=__name(accessor=>({icon:"PercentSingle",id:SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:ui.MenuItemType.BUTTON,group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission,sheets.WorksheetSetCellStylePermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}),"PercentMenuItem"),FactoryOtherMenuItem=__name(accessor=>{const numfmtService=accessor.get(sheets.INumfmtService),univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),localeService=accessor.get(core.LocaleService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),value$=sheetsUi.deriveStateFromActiveSheet$(univerInstanceService,"",({workbook,worksheet})=>new rxjs.Observable(subscribe=>rxjs.merge(selectionManagerService.selectionMoveEnd$,new rxjs.Observable(commandSubscribe=>{const commandList=[sheets.RemoveNumfmtMutation.id,sheets.SetNumfmtMutation.id],disposable=commandService.onCommandExecuted(commandInfo=>{commandList.includes(commandInfo.id)&&commandSubscribe.next(null)});return()=>disposable.dispose()})).subscribe(()=>{const selections=selectionManagerService.getCurrentSelections();if(selections&&selections[0]){const range=selections[0].range,row=range.startRow,col=range.startColumn,numfmtValue=numfmtService.getValue(workbook.getUnitId(),worksheet.getSheetId(),row,col),pattern=numfmtValue==null?void 0:numfmtValue.pattern;let value=localeService.t("sheet.numfmt.general");if(pattern){const item=MENU_OPTIONS.filter(item2=>typeof item2=="object"&&item2.pattern).find(item2=>isPatternEqualWithoutDecimal(pattern,item2.pattern));item&&typeof item=="object"&&item.pattern?value=localeService.t(item.label):value=localeService.t("sheet.numfmt.moreFmt")}subscribe.next(value)}})));return{label:MORE_NUMFMT_TYPE_KEY,id:OpenNumfmtPanelOperator.id,tooltip:"sheet.numfmt.title",type:ui.MenuItemType.SELECTOR,group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,positions:[ui.MenuPosition.TOOLBAR_START],selections:[{label:{name:OPTIONS_KEY,hoverable:!1}}],value$,hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetSetCellStylePermission,sheets.WorksheetEditPermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}},"FactoryOtherMenuItem");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key2,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$1");const DefaultSheetNumfmtConfig={};var _a6;let NumfmtMenuController=(_a6=class extends core.Disposable{constructor(_config,_injector,_componentManager,_menuService){super(),this._config=_config,this._injector=_injector,this._componentManager=_componentManager,this._menuService=_menuService,this._initMenu()}_initMenu(){const{menu={}}=this._config;[PercentMenuItem,AddDecimalMenuItem,SubtractDecimalMenuItem,CurrencyMenuItem,FactoryOtherMenuItem].forEach(factory=>{this.disposeWithMe(this._menuService.addMenuItem(factory(this._injector),menu))}),this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY,MoreNumfmtType)),this.disposeWithMe(this._componentManager.register(OPTIONS_KEY,Options))}},__name(_a6,"NumfmtMenuController"),_a6);NumfmtMenuController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtMenuController),__decorateParam$1(1,core.Inject(core.Injector)),__decorateParam$1(2,core.Inject(ui.ComponentManager)),__decorateParam$1(3,core.Inject(ui.IMenuService))],NumfmtMenuController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key2,value)=>key2 in obj?__defProp2(obj,key2,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key2]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp2(target,key2,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam"),__publicField2=__name((obj,key2,value)=>__defNormalProp2(obj,typeof key2!="symbol"?key2+"":key2,value),"__publicField"),_a7;exports.UniverSheetsNumfmtPlugin=(_a7=class extends core.Plugin{constructor(_config={},_injector){super(),this._config=_config,this._injector=_injector,this._config=core.Tools.deepMerge({},DefaultSheetNumfmtConfig,this._config)}onStarting(){this._injector.add([INumfmtController,{useClass:NumfmtController,lazy:!1}]),this._injector.add([NumfmtEditorController]),this._injector.add([UserHabitController]),this._injector.add([SheetsNumfmtCellContentController]),this._injector.add([NumfmtI18nController]),this._injector.add([NumfmtMenuController,{useFactory:__name(()=>this._injector.createInstance(NumfmtMenuController,this._config),"useFactory")}])}},__name(_a7,"UniverSheetsNumfmtPlugin"),_a7);__publicField2(exports.UniverSheetsNumfmtPlugin,"pluginName",SHEET_NUMFMT_PLUGIN);__publicField2(exports.UniverSheetsNumfmtPlugin,"type",core.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin,sheetsUi.UniverSheetsUIPlugin),__decorateParam(1,core.Inject(core.Injector))],exports.UniverSheetsNumfmtPlugin);exports.AddDecimalCommand=AddDecimalCommand;exports.CloseNumfmtPanelOperator=CloseNumfmtPanelOperator;exports.OpenNumfmtPanelOperator=OpenNumfmtPanelOperator;exports.SetCurrencyCommand=SetCurrencyCommand;exports.SetNumfmtCommand=SetNumfmtCommand;exports.SetPercentCommand=SetPercentCommand;exports.SubtractDecimalCommand=SubtractDecimalCommand;exports.getPatternPreview=getPatternPreview;