@univerjs/sheets-numfmt 0.2.14 → 0.3.0-alpha.0

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 __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"),rxjs=require("rxjs"),sheetsUi=require("@univerjs/sheets-ui"),engineRender=require("@univerjs/engine-render"),ui=require("@univerjs/ui"),operators=require("rxjs/operators"),require$$0=require("react"),design=require("@univerjs/design"),engineNumfmt=require("@univerjs/engine-numfmt"),currencySymbols=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],countryCurrencyMap={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},getDecimalFromPattern=__name((pattern,defaultValue=0)=>{var _a9;return pattern&&(_a9=core.numfmt.getInfo(pattern).maxDecimals)!=null?_a9: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=core.numfmt.getInfo(patternA)._partitions,partitionsB=core.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){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}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"}],_MenuCurrencyService=class _MenuCurrencyService{constructor(){__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}};__name(_MenuCurrencyService,"MenuCurrencyService");let MenuCurrencyService=_MenuCurrencyService;const SetCurrencyCommand={id:"sheet.command.numfmt.set.currency",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),menuCurrencyService=accessor.get(MenuCurrencyService),symbol=countryCurrencyMap[menuCurrencyService.getCurrencySymbol()]||"$",selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix=CURRENCYFORMAT[4].suffix(symbol);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")},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")},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){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}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")},SHEET_NUMFMT_PLUGIN="SHEET_NUMFMT_PLUGIN",getPatternType=__name(pattern=>core.numfmt.getInfo(pattern).type||"unknown","getPatternType"),getPatternPreview=__name((pattern,value,_locale)=>{const info=core.numfmt.getInfo(pattern),locale=_locale===core.LocaleType.ZH_CN?"zh-CN":"en",negInfo=info._partitions[1],result=core.numfmt.format(pattern,value,{locale});return value<0?{result,color:negInfo.color}:{result}},"getPatternPreview");var __defProp$7=Object.defineProperty,__getOwnPropDesc$7=Object.getOwnPropertyDescriptor,__decorateClass$7=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$7(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$7(target,key2,result),result},"__decorateClass$7"),__decorateParam$7=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$7"),_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;let numfmtValue;if(cell!=null&&cell.s){const style=location.workbook.getStyles().get(cell.s);style!=null&&style.n&&(numfmtValue=style.n)}if(numfmtValue||(numfmtValue=this._numfmtService.getValue(unitId,sheetId,location.row,location.col)),!numfmtValue)return next(cell);const originCellValue=cell;if(!originCellValue||originCellValue.t!==core.CellValueType.NUMBER||originCellValue.v==null||Number.isNaN(originCellValue.v))return next(cell);let numfmtRes="";const cache=renderCache.getValue(location.row,location.col);if(cache&&cache.parameters===`${originCellValue.v}_${numfmtValue.pattern}`)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}_${numfmtValue.pattern}`}),next({...cell,...res})},"handler"),priority:sheets.InterceptCellContentPriority.NUMFMT})),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 _a9;return(_a9=workbook==null?void 0:workbook.activeSheet$)!=null?_a9:rxjs.of(null)}),rxjs.skip(1)).subscribe(()=>renderCache.reset()))}},__name(_a,"SheetsNumfmtCellContentController"),_a);SheetsNumfmtCellContentController=__decorateClass$7([core.OnLifecycle(core.LifecycleStages.Rendered,SheetsNumfmtCellContentController),__decorateParam$7(0,core.IUniverInstanceService),__decorateParam$7(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$7(2,core.Inject(core.ThemeService)),__decorateParam$7(3,core.Inject(core.ICommandService)),__decorateParam$7(4,core.Inject(sheets.INumfmtService)),__decorateParam$7(5,core.Inject(core.LocaleService))],SheetsNumfmtCellContentController);var jsxRuntime={exports:{}},reactJsxRuntime_production_min={};/**
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"),engineRender=require("@univerjs/engine-render"),ui=require("@univerjs/ui"),operators=require("rxjs/operators"),require$$0=require("react"),design=require("@univerjs/design"),engineNumfmt=require("@univerjs/engine-numfmt"),currencySymbols=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],countryCurrencyMap={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},SHEET_NUMFMT_PLUGIN="SHEET_NUMFMT_PLUGIN",getPatternType=__name(pattern=>core.numfmt.getInfo(pattern).type||"unknown","getPatternType"),getPatternPreview=__name((pattern,value,_locale)=>{const info=core.numfmt.getInfo(pattern),locale=_locale===core.LocaleType.ZH_CN?"zh-CN":"en",negInfo=info._partitions[1],result=core.numfmt.format(pattern,value,{locale,throws:!1});return value<0?{result,color:negInfo.color}:{result}},"getPatternPreview"),getPatternPreviewIgnoreGeneral=__name((pattern,value,_locale)=>pattern==="General"?{result:String(value)}:getPatternPreview(pattern,value,_locale),"getPatternPreviewIgnoreGeneral");var __defProp$7=Object.defineProperty,__getOwnPropDesc$7=Object.getOwnPropertyDescriptor,__decorateClass$7=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$7(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$7(target,key2,result),result},"__decorateClass$7"),__decorateParam$7=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$7"),_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,{effect:core.InterceptorEffectEnum.Value|core.InterceptorEffectEnum.Style,handler:__name((cell,location,next)=>{const unitId=location.unitId,sheetId=location.subUnitId;let numfmtValue;const originCellValue=cell;if(!originCellValue||originCellValue.t!==core.CellValueType.NUMBER||originCellValue.v==null||Number.isNaN(originCellValue.v))return next(cell);if(cell!=null&&cell.s){const style=location.workbook.getStyles().get(cell.s);style!=null&&style.n&&(numfmtValue=style.n)}if(numfmtValue||(numfmtValue=this._numfmtService.getValue(unitId,sheetId,location.row,location.col)),!numfmtValue)return next(cell);let numfmtRes="";const cache=renderCache.getValue(location.row,location.col);if(cache&&cache.parameters===`${originCellValue.v}_${numfmtValue.pattern}`)return next({...cell,...cache.result});const info=getPatternPreviewIgnoreGeneral(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}_${numfmtValue.pattern}`}),next({...cell,...res})},"handler"),priority:sheets.InterceptCellContentPriority.NUMFMT})),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 _a9;return(_a9=workbook==null?void 0:workbook.activeSheet$)!=null?_a9:rxjs.of(null)}),rxjs.skip(1)).subscribe(()=>renderCache.reset()))}},__name(_a,"SheetsNumfmtCellContentController"),_a);SheetsNumfmtCellContentController=__decorateClass$7([core.OnLifecycle(core.LifecycleStages.Rendered,SheetsNumfmtCellContentController),__decorateParam$7(0,core.IUniverInstanceService),__decorateParam$7(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$7(2,core.Inject(core.ThemeService)),__decorateParam$7(3,core.Inject(core.ICommandService)),__decorateParam$7(4,core.Inject(sheets.INumfmtService)),__decorateParam$7(5,core.Inject(core.LocaleService))],SheetsNumfmtCellContentController);const getDecimalFromPattern=__name((pattern,defaultValue=0)=>{var _a9;return pattern&&(_a9=core.numfmt.getInfo(pattern).maxDecimals)!=null?_a9: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=core.numfmt.getInfo(patternA)._partitions,partitionsB=core.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){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}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"}],_MenuCurrencyService=class _MenuCurrencyService{constructor(){__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}};__name(_MenuCurrencyService,"MenuCurrencyService");let MenuCurrencyService=_MenuCurrencyService;const SetCurrencyCommand={id:"sheet.command.numfmt.set.currency",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),menuCurrencyService=accessor.get(MenuCurrencyService),symbol=countryCurrencyMap[menuCurrencyService.getCurrencySymbol()]||"$",selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix=CURRENCYFORMAT[4].suffix(symbol);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")},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")},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){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}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 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([]);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"),_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 _a9,_b;const ap=((_a9=priority.find(item=>item.value===a))==null?void 0:_a9.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$6([__decorateParam$6(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 _a9;const negativeOptions2=getCurrencyFormatOptions(suffix);return((_a9=negativeOptions2.find(item=>isPatternEqualWithoutDecimal(item.value,props.defaultPattern)))==null?void 0:_a9.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=core.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(_a9){var key2=_a9[0],value=_a9[1];typeof value=="string"&&(attrs[key2]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a9,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a9=node.children)===null||_a9===void 0)&&_a9.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 _a9;return(_a9=typeOptions.find(item=>item.label===type))==null?void 0:_a9.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");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"),_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 _a9;const sidebarService=this._sidebarService,selectionManagerService=this._selectionManagerService,commandService=this._commandService,univerInstanceService=this._univerInstanceService,numfmtService=this._numfmtService,localeService=this._localeService,range=(((_a9=selectionManagerService.getCurrentSelections())==null?void 0:_a9.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 _a10;if(config.type==="change")this._previewPattern=config.value,this._forceUpdate();else if(config.type==="confirm"){const selections2=((_a10=selectionManagerService.getCurrentSelections())==null?void 0:_a10.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 _a9;const renderUnit=this._renderManagerService.getRenderById(unitId!=null?unitId:this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET).getUnitId());renderUnit==null||renderUnit.with(sheetsUi.SheetSkeletonManagerService).reCalculate(),(_a9=renderUnit==null?void 0:renderUnit.mainComponent)==null||_a9.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 _a9,_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=(_a9=this._renderManagerService.getRenderById(workbook.getUnitId()))==null?void 0:_a9.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 _a9;unit||((_a9=this._sidebarDisposable)==null||_a9.dispose(),this._sidebarDisposable=null)})}},__name(_a3,"NumfmtController"),_a3);NumfmtController=__decorateClass$5([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtController),__decorateParam$5(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$5(1,core.Inject(core.ThemeService)),__decorateParam$5(2,core.IUniverInstanceService),__decorateParam$5(3,core.ICommandService),__decorateParam$5(4,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$5(5,engineRender.IRenderManagerService),__decorateParam$5(6,sheets.INumfmtService),__decorateParam$5(7,core.Inject(ui.ComponentManager)),__decorateParam$5(8,ui.ISidebarService),__decorateParam$5(9,core.Inject(core.LocaleService))],NumfmtController);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");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"currency":case"grouped":case"number":return context.worksheet.getCellRaw(row,col);case"percent":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 _a9;this._collectEffectMutation.clean();const currentNumfmtValue=this._numfmtService.getValue(context.unitId,context.subUnitId,context.row,context.col),currentNumfmtType=(_a9=currentNumfmtValue&&getPatternType(currentNumfmtValue.pattern))!=null?_a9:"",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),numfmtInfo=core.numfmt.parseDate(content)||core.numfmt.parseTime(content)||core.numfmt.parseNumber(content);if(numfmtInfo){if(numfmtInfo.z){const v=Number(numfmtInfo.v);return this._collectEffectMutation.add(context.unitId,context.subUnitId,context.row,context.col,{pattern:numfmtInfo.z}),{...value,v,t:core.CellValueType.NUMBER}}}else(["date","time","datetime","percent"].includes(currentNumfmtType)||!isNumeric(content))&&clean();return next(value)},"handler")})))}_initInterceptorCommands(){const self=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(command){var _a9;switch(command.id){case sheets.SetRangeValuesCommand.id:{const workbook=self._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),unitId=workbook.getUnitId(),subUnitId=(_a9=workbook.getActiveSheet())==null?void 0:_a9.getSheetId();if(!subUnitId)return{redos:[],undos:[]};const list=self._collectEffectMutation.getEffects();if(self._collectEffectMutation.clean(),!list.length)return{redos:[],undos:[]};const cells=list.filter(item=>{var _a10;return!!((_a10=item.value)!=null&&_a10.pattern)}).map(item=>({row:item.row,col:item.col,pattern:item.value.pattern})),removeCells=list.filter(item=>{var _a10;return!((_a10=item.value)!=null&&_a10.pattern)}).map(item=>({startRow:item.row,endColumn:item.col,startColumn:item.col,endRow:item.row})),redos=[],undos=[];if(cells.length){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.length){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$4([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtEditorController),__decorateParam$4(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$4(1,core.Inject(sheets.INumfmtService)),__decorateParam$4(2,core.Inject(core.IUniverInstanceService)),__decorateParam$4(3,core.Inject(core.Injector)),__decorateParam$4(4,core.Optional(sheetsUi.IEditorBridgeService))],NumfmtEditorController);function isNumeric(str){return/^-?\d+(\.\d+)?$/.test(str)}__name(isNumeric,"isNumeric");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"),_a5;let NumfmtI18nController=(_a5=class extends core.Disposable{constructor(_localeService){super(),this._localeService=_localeService}},__name(_a5,"NumfmtI18nController"),_a5);NumfmtI18nController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtI18nController),__decorateParam$3(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 _a9;const localeService=core.useDependency(core.LocaleService),value=(_a9=props.value)!=null?_a9: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),layoutService=core.useDependency(ui.ILayoutService);core.useInjector();const selectionManagerService=core.useDependency(sheets.SheetsSelectionsService),setNumfmt=__name(pattern=>{const selection=selectionManagerService.getCurrentLastSelection();if(!selection)return;const 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}),layoutService.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:new rxjs.Observable(subscribe=>{const menuCurrencyService=accessor.get(MenuCurrencyService);function getIconKey(symbol2){return{[countryCurrencyMap.US]:"DollarSingle",[countryCurrencyMap.RU]:"RoubleSingle",[countryCurrencyMap.CN]:"RmbSingle",[countryCurrencyMap.AT]:"EuroSingle"}[symbol2]||"DollarSingle"}__name(getIconKey,"getIconKey");const symbol=countryCurrencyMap[menuCurrencyService.getCurrencySymbol()]||"$";return subscribe.next(getIconKey(symbol)),menuCurrencyService.currencySymbol$.subscribe(code=>{const symbol2=countryCurrencyMap[code]||"$";subscribe.next(getIconKey(symbol2))})}),id:SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:ui.MenuItemType.BUTTON,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,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,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,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 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(()=>{var _a9,_b;const selections=selectionManagerService.getCurrentSelections();if(selections&&selections[0]){const range=selections[0].range,row=range.startRow,col=range.startColumn,numfmtValue=(_b=workbook.getStyles().get((_a9=worksheet.getCell(row,col))==null?void 0:_a9.s))==null?void 0:_b.n,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,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"),menuSchema={[ui.RibbonStartGroup.FORMULAS_INSERT]:{[SetCurrencyCommand.id]:{order:4,menuItemFactory:CurrencyMenuItem},[AddDecimalCommand.id]:{order:5,menuItemFactory:AddDecimalMenuItem},[SubtractDecimalCommand.id]:{order:6,menuItemFactory:SubtractDecimalMenuItem},[SetPercentCommand.id]:{order:7,menuItemFactory:PercentMenuItem},[OpenNumfmtPanelOperator.id]:{order:8,menuItemFactory:FactoryOtherMenuItem}}};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"),_a6;let NumfmtMenuController=(_a6=class extends core.Disposable{constructor(_injector,_componentManager,_menuManagerService){super(),this._injector=_injector,this._componentManager=_componentManager,this._menuManagerService=_menuManagerService,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(menuSchema),this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY,MoreNumfmtType)),this.disposeWithMe(this._componentManager.register(OPTIONS_KEY,Options))}},__name(_a6,"NumfmtMenuController"),_a6);NumfmtMenuController=__decorateClass$2([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtMenuController),__decorateParam$2(0,core.Inject(core.Injector)),__decorateParam$2(1,core.Inject(ui.ComponentManager)),__decorateParam$2(2,ui.IMenuManagerService)],NumfmtMenuController);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"),_a7;let NumfmtCurrencyController=(_a7=class extends core.Disposable{constructor(_injector){super();__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable());this._injector=_injector}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}},__name(_a7,"NumfmtCurrencyController"),_a7);NumfmtCurrencyController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtCurrencyController),__decorateParam$1(0,core.Inject(core.Injector))],NumfmtCurrencyController);const PLUGIN_CONFIG_KEY="sheets-numfmt.config",defaultPluginConfig={};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"),_a8;exports.UniverSheetsNumfmtPlugin=(_a8=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{menu,...rest}=this._config;menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}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([MenuCurrencyService]),this._injector.add([NumfmtCurrencyController]),this._injector.add([NumfmtMenuController])}},__name(_a8,"UniverSheetsNumfmtPlugin"),_a8);__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)),__decorateParam(2,core.IConfigService)],exports.UniverSheetsNumfmtPlugin);exports.AddDecimalCommand=AddDecimalCommand;exports.CloseNumfmtPanelOperator=CloseNumfmtPanelOperator;exports.MenuCurrencyService=MenuCurrencyService;exports.OpenNumfmtPanelOperator=OpenNumfmtPanelOperator;exports.SetCurrencyCommand=SetCurrencyCommand;exports.SetNumfmtCommand=SetNumfmtCommand;exports.SetPercentCommand=SetPercentCommand;exports.SubtractDecimalCommand=SubtractDecimalCommand;exports.countryCurrencyMap=countryCurrencyMap;exports.getPatternPreview=getPatternPreview;exports.getPatternType=getPatternType;
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([]);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"),_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 _a9,_b;const ap=((_a9=priority.find(item=>item.value===a))==null?void 0:_a9.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$6([__decorateParam$6(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 _a9;const negativeOptions2=getCurrencyFormatOptions(suffix);return((_a9=negativeOptions2.find(item=>isPatternEqualWithoutDecimal(item.value,props.defaultPattern)))==null?void 0:_a9.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");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(_a9){var key2=_a9[0],value=_a9[1];typeof value=="string"&&(attrs[key2]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a9,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a9=node.children)===null||_a9===void 0)&&_a9.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 isDatePanel=__name(pattern=>{const info=core.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"),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 _a9;return(_a9=typeOptions.find(item=>item.label===type))==null?void 0:_a9.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");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"),_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 _a9;const sidebarService=this._sidebarService,selectionManagerService=this._selectionManagerService,commandService=this._commandService,univerInstanceService=this._univerInstanceService,numfmtService=this._numfmtService,localeService=this._localeService,range=(((_a9=selectionManagerService.getCurrentSelections())==null?void 0:_a9.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 _a10;if(config.type==="change")this._previewPattern=config.value,this._forceUpdate();else if(config.type==="confirm"){const selections2=((_a10=selectionManagerService.getCurrentSelections())==null?void 0:_a10.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 _a9;const renderUnit=this._renderManagerService.getRenderById(unitId!=null?unitId:this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET).getUnitId());renderUnit==null||renderUnit.with(sheetsUi.SheetSkeletonManagerService).reCalculate(),(_a9=renderUnit==null?void 0:renderUnit.mainComponent)==null||_a9.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 _a9,_b;const workbook=this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET);this.openPanel(),disposableCollection.add(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:core.InterceptorEffectEnum.Value|core.InterceptorEffectEnum.Style,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=getPatternPreviewIgnoreGeneral(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=(_a9=this._renderManagerService.getRenderById(workbook.getUnitId()))==null?void 0:_a9.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 _a9;unit||((_a9=this._sidebarDisposable)==null||_a9.dispose(),this._sidebarDisposable=null)})}},__name(_a3,"NumfmtController"),_a3);NumfmtController=__decorateClass$5([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtController),__decorateParam$5(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$5(1,core.Inject(core.ThemeService)),__decorateParam$5(2,core.IUniverInstanceService),__decorateParam$5(3,core.ICommandService),__decorateParam$5(4,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$5(5,engineRender.IRenderManagerService),__decorateParam$5(6,sheets.INumfmtService),__decorateParam$5(7,core.Inject(ui.ComponentManager)),__decorateParam$5(8,ui.ISidebarService),__decorateParam$5(9,core.Inject(core.LocaleService))],NumfmtController);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");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"currency":case"grouped":case"number":return context.worksheet.getCellRaw(row,col);case"percent":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 _a9;this._collectEffectMutation.clean();const currentNumfmtValue=this._numfmtService.getValue(context.unitId,context.subUnitId,context.row,context.col),currentNumfmtType=(_a9=currentNumfmtValue&&getPatternType(currentNumfmtValue.pattern))!=null?_a9:"",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),numfmtInfo=core.numfmt.parseDate(content)||core.numfmt.parseTime(content)||core.numfmt.parseNumber(content);if(numfmtInfo){if(numfmtInfo.z){const v=Number(numfmtInfo.v);return this._collectEffectMutation.add(context.unitId,context.subUnitId,context.row,context.col,{pattern:numfmtInfo.z}),{...value,v,t:core.CellValueType.NUMBER}}}else(["date","time","datetime","percent"].includes(currentNumfmtType)||!isNumeric(content))&&clean();return next(value)},"handler")})))}_initInterceptorCommands(){const self=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(command){var _a9;switch(command.id){case sheets.SetRangeValuesCommand.id:{const workbook=self._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),unitId=workbook.getUnitId(),subUnitId=(_a9=workbook.getActiveSheet())==null?void 0:_a9.getSheetId();if(!subUnitId)return{redos:[],undos:[]};const list=self._collectEffectMutation.getEffects();if(self._collectEffectMutation.clean(),!list.length)return{redos:[],undos:[]};const cells=list.filter(item=>{var _a10;return!!((_a10=item.value)!=null&&_a10.pattern)}).map(item=>({row:item.row,col:item.col,pattern:item.value.pattern})),removeCells=list.filter(item=>{var _a10;return!((_a10=item.value)!=null&&_a10.pattern)}).map(item=>({startRow:item.row,endColumn:item.col,startColumn:item.col,endRow:item.row})),redos=[],undos=[];if(cells.length){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.length){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$4([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtEditorController),__decorateParam$4(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$4(1,core.Inject(sheets.INumfmtService)),__decorateParam$4(2,core.Inject(core.IUniverInstanceService)),__decorateParam$4(3,core.Inject(core.Injector)),__decorateParam$4(4,core.Optional(sheetsUi.IEditorBridgeService))],NumfmtEditorController);function isNumeric(str){return/^-?\d+(\.\d+)?$/.test(str)}__name(isNumeric,"isNumeric");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"),_a5;let NumfmtI18nController=(_a5=class extends core.Disposable{constructor(_localeService){super(),this._localeService=_localeService}},__name(_a5,"NumfmtI18nController"),_a5);NumfmtI18nController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtI18nController),__decorateParam$3(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 _a9;const localeService=core.useDependency(core.LocaleService),value=(_a9=props.value)!=null?_a9: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),layoutService=core.useDependency(ui.ILayoutService);core.useInjector();const selectionManagerService=core.useDependency(sheets.SheetsSelectionsService),setNumfmt=__name(pattern=>{const selection=selectionManagerService.getCurrentLastSelection();if(!selection)return;const 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}),layoutService.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:new rxjs.Observable(subscribe=>{const menuCurrencyService=accessor.get(MenuCurrencyService);function getIconKey(symbol2){return{[countryCurrencyMap.US]:"DollarSingle",[countryCurrencyMap.RU]:"RoubleSingle",[countryCurrencyMap.CN]:"RmbSingle",[countryCurrencyMap.AT]:"EuroSingle"}[symbol2]||"DollarSingle"}__name(getIconKey,"getIconKey");const symbol=countryCurrencyMap[menuCurrencyService.getCurrencySymbol()]||"$";return subscribe.next(getIconKey(symbol)),menuCurrencyService.currencySymbol$.subscribe(code=>{const symbol2=countryCurrencyMap[code]||"$";subscribe.next(getIconKey(symbol2))})}),id:SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:ui.MenuItemType.BUTTON,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,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,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,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 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(()=>{var _a9,_b;const selections=selectionManagerService.getCurrentSelections();if(selections&&selections[0]){const range=selections[0].range,row=range.startRow,col=range.startColumn,numfmtValue=(_b=workbook.getStyles().get((_a9=worksheet.getCell(row,col))==null?void 0:_a9.s))==null?void 0:_b.n,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,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"),menuSchema={[ui.RibbonStartGroup.FORMULAS_INSERT]:{[SetCurrencyCommand.id]:{order:4,menuItemFactory:CurrencyMenuItem},[AddDecimalCommand.id]:{order:5,menuItemFactory:AddDecimalMenuItem},[SubtractDecimalCommand.id]:{order:6,menuItemFactory:SubtractDecimalMenuItem},[SetPercentCommand.id]:{order:7,menuItemFactory:PercentMenuItem},[OpenNumfmtPanelOperator.id]:{order:8,menuItemFactory:FactoryOtherMenuItem}}};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"),_a6;let NumfmtMenuController=(_a6=class extends core.Disposable{constructor(_injector,_componentManager,_menuManagerService){super(),this._injector=_injector,this._componentManager=_componentManager,this._menuManagerService=_menuManagerService,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(menuSchema),this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY,MoreNumfmtType)),this.disposeWithMe(this._componentManager.register(OPTIONS_KEY,Options))}},__name(_a6,"NumfmtMenuController"),_a6);NumfmtMenuController=__decorateClass$2([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtMenuController),__decorateParam$2(0,core.Inject(core.Injector)),__decorateParam$2(1,core.Inject(ui.ComponentManager)),__decorateParam$2(2,ui.IMenuManagerService)],NumfmtMenuController);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"),_a7;let NumfmtCurrencyController=(_a7=class extends core.Disposable{constructor(_injector){super();__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable());this._injector=_injector}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}},__name(_a7,"NumfmtCurrencyController"),_a7);NumfmtCurrencyController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtCurrencyController),__decorateParam$1(0,core.Inject(core.Injector))],NumfmtCurrencyController);const PLUGIN_CONFIG_KEY="sheets-numfmt.config",defaultPluginConfig={};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"),_a8;exports.UniverSheetsNumfmtPlugin=(_a8=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{menu,...rest}=this._config;menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}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([MenuCurrencyService]),this._injector.add([NumfmtCurrencyController]),this._injector.add([NumfmtMenuController])}},__name(_a8,"UniverSheetsNumfmtPlugin"),_a8);__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)),__decorateParam(2,core.IConfigService)],exports.UniverSheetsNumfmtPlugin);exports.AddDecimalCommand=AddDecimalCommand;exports.CloseNumfmtPanelOperator=CloseNumfmtPanelOperator;exports.MenuCurrencyService=MenuCurrencyService;exports.OpenNumfmtPanelOperator=OpenNumfmtPanelOperator;exports.SetCurrencyCommand=SetCurrencyCommand;exports.SetNumfmtCommand=SetNumfmtCommand;exports.SetPercentCommand=SetPercentCommand;exports.SubtractDecimalCommand=SubtractDecimalCommand;exports.countryCurrencyMap=countryCurrencyMap;exports.getPatternPreview=getPatternPreview;exports.getPatternType=getPatternType;
package/lib/es/index.js CHANGED
@@ -2,10 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key2] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 != "symbol" ? key2 + "" : key2, value);
5
- import { numfmt, CommandType, ICommandService, IUniverInstanceService, IUndoRedoService, sequenceExecute, Range, CellValueType, createIdentifier, runOnLifecycle, LifecycleStages, LocaleType, Disposable, ObjectMatrix, UniverInstanceType, OnLifecycle, Inject, ThemeService, LocaleService, ILocalStorageService, useDependency, toDisposable, DisposableCollection, Injector, Optional, useInjector, Plugin, DependentOn, IConfigService } from "@univerjs/core";
6
- import { getSheetCommandTarget, transformCellsToRange, rangeMerge, SetNumfmtMutation, factorySetNumfmtUndoMutation, RemoveNumfmtMutation, factoryRemoveNumfmtUndoMutation, SheetsSelectionsService, INumfmtService, INTERCEPTOR_POINT, InterceptCellContentPriority, SetRangeValuesMutation, SheetInterceptorService, SetRangeValuesCommand, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, RangeProtectionPermissionEditPoint, UniverSheetsPlugin } from "@univerjs/sheets";
7
- import { BehaviorSubject, switchMap, of, skip, Observable, combineLatest, merge } from "rxjs";
5
+ import { numfmt, LocaleType, OnLifecycle, LifecycleStages, Inject, ThemeService, ICommandService, LocaleService, Disposable, ObjectMatrix, InterceptorEffectEnum, CellValueType, Range, UniverInstanceType, IUniverInstanceService, CommandType, IUndoRedoService, sequenceExecute, createIdentifier, runOnLifecycle, ILocalStorageService, useDependency, toDisposable, DisposableCollection, Injector, Optional, useInjector, DependentOn, Plugin, IConfigService } from "@univerjs/core";
6
+ import { SheetInterceptorService, INumfmtService, INTERCEPTOR_POINT, InterceptCellContentPriority, SetNumfmtMutation, SetRangeValuesMutation, getSheetCommandTarget, transformCellsToRange, rangeMerge, factorySetNumfmtUndoMutation, RemoveNumfmtMutation, factoryRemoveNumfmtUndoMutation, SheetsSelectionsService, SetRangeValuesCommand, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, RangeProtectionPermissionEditPoint, UniverSheetsPlugin } from "@univerjs/sheets";
8
7
  import { SheetSkeletonManagerService, IEditorBridgeService, getCurrentRangeDisable$, deriveStateFromActiveSheet$, UniverSheetsUIPlugin } from "@univerjs/sheets-ui";
8
+ import { switchMap, of, skip, BehaviorSubject, Observable, combineLatest, merge } from "rxjs";
9
9
  import { IRenderManagerService } from "@univerjs/engine-render";
10
10
  import { ComponentManager, ISidebarService, ILayoutService, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, IMenuManagerService } from "@univerjs/ui";
11
11
  import { map, switchMap as switchMap$1, tap, debounceTime } from "rxjs/operators";
@@ -80,7 +80,98 @@ const currencySymbols = [
80
80
  SI: "€",
81
81
  ES: "€"
82
82
  // Add more mappings as needed
83
- }, getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0) => {
83
+ }, SHEET_NUMFMT_PLUGIN = "SHEET_NUMFMT_PLUGIN", getPatternType = /* @__PURE__ */ __name((pattern) => numfmt.getInfo(pattern).type || "unknown", "getPatternType"), getPatternPreview = /* @__PURE__ */ __name((pattern, value, _locale) => {
84
+ const info = numfmt.getInfo(pattern), locale = _locale === LocaleType.ZH_CN ? "zh-CN" : "en", negInfo = info._partitions[1], result = numfmt.format(pattern, value, { locale, throws: !1 });
85
+ return value < 0 ? {
86
+ result,
87
+ color: negInfo.color
88
+ } : {
89
+ result
90
+ };
91
+ }, "getPatternPreview"), getPatternPreviewIgnoreGeneral = /* @__PURE__ */ __name((pattern, value, _locale) => pattern === "General" ? {
92
+ result: String(value)
93
+ } : getPatternPreview(pattern, value, _locale), "getPatternPreviewIgnoreGeneral");
94
+ var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
95
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
96
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
97
+ return kind && result && __defProp$7(target, key2, result), result;
98
+ }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$7"), _a;
99
+ let SheetsNumfmtCellContentController = (_a = class extends Disposable {
100
+ constructor(_instanceService, _sheetInterceptorService, _themeService, _commandService, _numfmtService, _localeService) {
101
+ super(), this._instanceService = _instanceService, this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._commandService = _commandService, this._numfmtService = _numfmtService, this._localeService = _localeService, this._initInterceptorCellContent();
102
+ }
103
+ // eslint-disable-next-line max-lines-per-function
104
+ _initInterceptorCellContent() {
105
+ const renderCache = new ObjectMatrix();
106
+ this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
107
+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
108
+ handler: /* @__PURE__ */ __name((cell, location, next) => {
109
+ const unitId = location.unitId, sheetId = location.subUnitId;
110
+ let numfmtValue;
111
+ const originCellValue = cell;
112
+ if (!originCellValue || originCellValue.t !== CellValueType.NUMBER || originCellValue.v == null || Number.isNaN(originCellValue.v))
113
+ return next(cell);
114
+ if (cell != null && cell.s) {
115
+ const style = location.workbook.getStyles().get(cell.s);
116
+ style != null && style.n && (numfmtValue = style.n);
117
+ }
118
+ if (numfmtValue || (numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col)), !numfmtValue)
119
+ return next(cell);
120
+ let numfmtRes = "";
121
+ const cache = renderCache.getValue(location.row, location.col);
122
+ if (cache && cache.parameters === `${originCellValue.v}_${numfmtValue.pattern}`)
123
+ return next({ ...cell, ...cache.result });
124
+ const info = getPatternPreviewIgnoreGeneral(numfmtValue.pattern, Number(originCellValue.v), this._localeService.getCurrentLocale());
125
+ if (numfmtRes = info.result, !numfmtRes)
126
+ return next(cell);
127
+ const res = { v: numfmtRes };
128
+ if (info.color) {
129
+ const color = this._themeService.getCurrentTheme()[`${info.color}500`];
130
+ color && (res.interceptorStyle = { cl: { rgb: color } });
131
+ }
132
+ return renderCache.setValue(location.row, location.col, {
133
+ result: res,
134
+ parameters: `${originCellValue.v}_${numfmtValue.pattern}`
135
+ }), next({ ...cell, ...res });
136
+ }, "handler"),
137
+ priority: InterceptCellContentPriority.NUMFMT
138
+ })), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
139
+ if (commandInfo.id === SetNumfmtMutation.id) {
140
+ const params = commandInfo.params;
141
+ Object.keys(params.values).forEach((key2) => {
142
+ params.values[key2].ranges.forEach((range) => {
143
+ Range.foreach(range, (row, col) => {
144
+ renderCache.realDeleteValue(row, col);
145
+ });
146
+ });
147
+ });
148
+ } else if (commandInfo.id === SetRangeValuesMutation.id) {
149
+ const params = commandInfo.params;
150
+ new ObjectMatrix(params.cellValue).forValue((row, col) => {
151
+ renderCache.realDeleteValue(row, col);
152
+ });
153
+ }
154
+ })), this.disposeWithMe(
155
+ this._instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(
156
+ switchMap((workbook) => {
157
+ var _a9;
158
+ return (_a9 = workbook == null ? void 0 : workbook.activeSheet$) != null ? _a9 : of(null);
159
+ }),
160
+ skip(1)
161
+ ).subscribe(() => renderCache.reset())
162
+ );
163
+ }
164
+ }, __name(_a, "SheetsNumfmtCellContentController"), _a);
165
+ SheetsNumfmtCellContentController = __decorateClass$7([
166
+ OnLifecycle(LifecycleStages.Rendered, SheetsNumfmtCellContentController),
167
+ __decorateParam$7(0, IUniverInstanceService),
168
+ __decorateParam$7(1, Inject(SheetInterceptorService)),
169
+ __decorateParam$7(2, Inject(ThemeService)),
170
+ __decorateParam$7(3, Inject(ICommandService)),
171
+ __decorateParam$7(4, Inject(INumfmtService)),
172
+ __decorateParam$7(5, Inject(LocaleService))
173
+ ], SheetsNumfmtCellContentController);
174
+ const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0) => {
84
175
  var _a9;
85
176
  return pattern && (_a9 = numfmt.getInfo(pattern).maxDecimals) != null ? _a9 : defaultValue;
86
177
  }, "getDecimalFromPattern"), isPatternEqualWithoutDecimal = /* @__PURE__ */ __name((patternA, patternB) => {
@@ -409,94 +500,7 @@ const OpenNumfmtPanelOperator = {
409
500
  id: "sheet.operation.open.numfmt.panel",
410
501
  type: CommandType.OPERATION,
411
502
  handler: /* @__PURE__ */ __name((accessor) => (accessor.get(INumfmtController).openPanel(), !0), "handler")
412
- }, SHEET_NUMFMT_PLUGIN = "SHEET_NUMFMT_PLUGIN", getPatternType = /* @__PURE__ */ __name((pattern) => numfmt.getInfo(pattern).type || "unknown", "getPatternType"), getPatternPreview = /* @__PURE__ */ __name((pattern, value, _locale) => {
413
- const info = numfmt.getInfo(pattern), locale = _locale === LocaleType.ZH_CN ? "zh-CN" : "en", negInfo = info._partitions[1], result = numfmt.format(pattern, value, { locale });
414
- return value < 0 ? {
415
- result,
416
- color: negInfo.color
417
- } : {
418
- result
419
- };
420
- }, "getPatternPreview");
421
- var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
422
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
423
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
424
- return kind && result && __defProp$7(target, key2, result), result;
425
- }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$7"), _a;
426
- let SheetsNumfmtCellContentController = (_a = class extends Disposable {
427
- constructor(_instanceService, _sheetInterceptorService, _themeService, _commandService, _numfmtService, _localeService) {
428
- super(), this._instanceService = _instanceService, this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._commandService = _commandService, this._numfmtService = _numfmtService, this._localeService = _localeService, this._initInterceptorCellContent();
429
- }
430
- // eslint-disable-next-line max-lines-per-function
431
- _initInterceptorCellContent() {
432
- const renderCache = new ObjectMatrix();
433
- this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
434
- handler: /* @__PURE__ */ __name((cell, location, next) => {
435
- const unitId = location.unitId, sheetId = location.subUnitId;
436
- let numfmtValue;
437
- if (cell != null && cell.s) {
438
- const style = location.workbook.getStyles().get(cell.s);
439
- style != null && style.n && (numfmtValue = style.n);
440
- }
441
- if (numfmtValue || (numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col)), !numfmtValue)
442
- return next(cell);
443
- const originCellValue = cell;
444
- if (!originCellValue || originCellValue.t !== CellValueType.NUMBER || originCellValue.v == null || Number.isNaN(originCellValue.v))
445
- return next(cell);
446
- let numfmtRes = "";
447
- const cache = renderCache.getValue(location.row, location.col);
448
- if (cache && cache.parameters === `${originCellValue.v}_${numfmtValue.pattern}`)
449
- return next({ ...cell, ...cache.result });
450
- const info = getPatternPreview(numfmtValue.pattern, Number(originCellValue.v), this._localeService.getCurrentLocale());
451
- if (numfmtRes = info.result, !numfmtRes)
452
- return next(cell);
453
- const res = { v: numfmtRes };
454
- if (info.color) {
455
- const color = this._themeService.getCurrentTheme()[`${info.color}500`];
456
- color && (res.interceptorStyle = { cl: { rgb: color } });
457
- }
458
- return renderCache.setValue(location.row, location.col, {
459
- result: res,
460
- parameters: `${originCellValue.v}_${numfmtValue.pattern}`
461
- }), next({ ...cell, ...res });
462
- }, "handler"),
463
- priority: InterceptCellContentPriority.NUMFMT
464
- })), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
465
- if (commandInfo.id === SetNumfmtMutation.id) {
466
- const params = commandInfo.params;
467
- Object.keys(params.values).forEach((key2) => {
468
- params.values[key2].ranges.forEach((range) => {
469
- Range.foreach(range, (row, col) => {
470
- renderCache.realDeleteValue(row, col);
471
- });
472
- });
473
- });
474
- } else if (commandInfo.id === SetRangeValuesMutation.id) {
475
- const params = commandInfo.params;
476
- new ObjectMatrix(params.cellValue).forValue((row, col) => {
477
- renderCache.realDeleteValue(row, col);
478
- });
479
- }
480
- })), this.disposeWithMe(
481
- this._instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(
482
- switchMap((workbook) => {
483
- var _a9;
484
- return (_a9 = workbook == null ? void 0 : workbook.activeSheet$) != null ? _a9 : of(null);
485
- }),
486
- skip(1)
487
- ).subscribe(() => renderCache.reset())
488
- );
489
- }
490
- }, __name(_a, "SheetsNumfmtCellContentController"), _a);
491
- SheetsNumfmtCellContentController = __decorateClass$7([
492
- OnLifecycle(LifecycleStages.Rendered, SheetsNumfmtCellContentController),
493
- __decorateParam$7(0, IUniverInstanceService),
494
- __decorateParam$7(1, Inject(SheetInterceptorService)),
495
- __decorateParam$7(2, Inject(ThemeService)),
496
- __decorateParam$7(3, Inject(ICommandService)),
497
- __decorateParam$7(4, Inject(INumfmtService)),
498
- __decorateParam$7(5, Inject(LocaleService))
499
- ], SheetsNumfmtCellContentController);
503
+ };
500
504
  var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
501
505
  /**
502
506
  * @license React
@@ -653,59 +657,7 @@ const key$1 = "numfmtCurrency", useCurrencyOptions = /* @__PURE__ */ __name((onO
653
657
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange, options: negativeOptions, value: pattern }) }),
654
658
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.currencyDes") })
655
659
  ] });
656
- }, "CurrencyPanel"), isDatePanel = /* @__PURE__ */ __name((pattern) => {
657
- const info = numfmt.getInfo(pattern);
658
- return getDateFormatOptions().map((item) => item.value).includes(pattern) || ["date", "datetime", "time"].includes(info.type);
659
- }, "isDatePanel"), DatePanel = /* @__PURE__ */ __name((props) => {
660
- const options = useMemo(getDateFormatOptions, []), t = useDependency(LocaleService).t, [suffix, suffixSet] = useState(() => {
661
- if (props.defaultPattern) {
662
- const item = options.find((item2) => item2.value === props.defaultPattern);
663
- if (item)
664
- return item.value;
665
- }
666
- return options[0].value;
667
- });
668
- props.action.current = () => suffix;
669
- const onChange = /* @__PURE__ */ __name((v) => {
670
- v !== void 0 && (suffixSet(v), props.onChange(v));
671
- }, "onChange");
672
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
673
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.dateType") }),
674
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { value: suffix, options, onChange }) }),
675
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.dateDes") })
676
- ] });
677
- }, "DatePanel"), isGeneralPanel = /* @__PURE__ */ __name((pattern) => !pattern, "isGeneralPanel"), GeneralPanel = /* @__PURE__ */ __name((props) => {
678
- const t = useDependency(LocaleService).t;
679
- return props.action.current = () => "", /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.generalDes") }) });
680
- }, "GeneralPanel"), isThousandthPercentilePanel = /* @__PURE__ */ __name((pattern) => getNumberFormatOptions().some((item) => isPatternEqualWithoutDecimal(item.value, pattern)), "isThousandthPercentilePanel"), ThousandthPercentilePanel = /* @__PURE__ */ __name((props) => {
681
- const localeService = useDependency(LocaleService), options = useMemo(getNumberFormatOptions, []), [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 0)), [suffix, suffixSet] = useState(() => {
682
- const item = options.find((item2) => isPatternEqualWithoutDecimal(item2.value, props.defaultPattern || ""));
683
- return (item == null ? void 0 : item.value) || options[0].value;
684
- }), pattern = useMemo(() => setPatternDecimal(suffix, Number(decimal || 0)), [suffix, decimal]), isInputDisable = useMemo(() => !isPatternHasDecimal(suffix), [suffix]), handleDecimalChange = /* @__PURE__ */ __name((decimal2) => {
685
- decimalSet(decimal2 || 0), props.onChange(setPatternDecimal(suffix, Number(decimal2 || 0)));
686
- }, "handleDecimalChange"), handleClick = /* @__PURE__ */ __name((v) => {
687
- v !== void 0 && (decimalSet(getDecimalFromPattern(v, 0)), suffixSet(v), props.onChange(v));
688
- }, "handleClick");
689
- return props.action.current = () => pattern, /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
690
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: localeService.t("sheet.numfmt.decimalLength") }),
691
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
692
- InputNumber,
693
- {
694
- disabled: isInputDisable,
695
- value: decimal,
696
- max: 20,
697
- min: 0,
698
- onChange: handleDecimalChange
699
- }
700
- ) }),
701
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 label", children: [
702
- " ",
703
- localeService.t("sheet.numfmt.negType")
704
- ] }),
705
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange: handleClick, options, value: suffix }) }),
706
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: localeService.t("sheet.numfmt.thousandthPercentileDes") })
707
- ] });
708
- }, "ThousandthPercentilePanel");
660
+ }, "CurrencyPanel");
709
661
  var __assign = function() {
710
662
  return __assign = Object.assign || function(t) {
711
663
  for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
@@ -806,7 +758,59 @@ function CustomFormat(props) {
806
758
  ] });
807
759
  }
808
760
  __name(CustomFormat, "CustomFormat");
809
- const SheetNumfmtPanel = /* @__PURE__ */ __name((props) => {
761
+ const isDatePanel = /* @__PURE__ */ __name((pattern) => {
762
+ const info = numfmt.getInfo(pattern);
763
+ return getDateFormatOptions().map((item) => item.value).includes(pattern) || ["date", "datetime", "time"].includes(info.type);
764
+ }, "isDatePanel"), DatePanel = /* @__PURE__ */ __name((props) => {
765
+ const options = useMemo(getDateFormatOptions, []), t = useDependency(LocaleService).t, [suffix, suffixSet] = useState(() => {
766
+ if (props.defaultPattern) {
767
+ const item = options.find((item2) => item2.value === props.defaultPattern);
768
+ if (item)
769
+ return item.value;
770
+ }
771
+ return options[0].value;
772
+ });
773
+ props.action.current = () => suffix;
774
+ const onChange = /* @__PURE__ */ __name((v) => {
775
+ v !== void 0 && (suffixSet(v), props.onChange(v));
776
+ }, "onChange");
777
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
778
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.dateType") }),
779
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { value: suffix, options, onChange }) }),
780
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.dateDes") })
781
+ ] });
782
+ }, "DatePanel"), isGeneralPanel = /* @__PURE__ */ __name((pattern) => !pattern, "isGeneralPanel"), GeneralPanel = /* @__PURE__ */ __name((props) => {
783
+ const t = useDependency(LocaleService).t;
784
+ return props.action.current = () => "", /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.generalDes") }) });
785
+ }, "GeneralPanel"), isThousandthPercentilePanel = /* @__PURE__ */ __name((pattern) => getNumberFormatOptions().some((item) => isPatternEqualWithoutDecimal(item.value, pattern)), "isThousandthPercentilePanel"), ThousandthPercentilePanel = /* @__PURE__ */ __name((props) => {
786
+ const localeService = useDependency(LocaleService), options = useMemo(getNumberFormatOptions, []), [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 0)), [suffix, suffixSet] = useState(() => {
787
+ const item = options.find((item2) => isPatternEqualWithoutDecimal(item2.value, props.defaultPattern || ""));
788
+ return (item == null ? void 0 : item.value) || options[0].value;
789
+ }), pattern = useMemo(() => setPatternDecimal(suffix, Number(decimal || 0)), [suffix, decimal]), isInputDisable = useMemo(() => !isPatternHasDecimal(suffix), [suffix]), handleDecimalChange = /* @__PURE__ */ __name((decimal2) => {
790
+ decimalSet(decimal2 || 0), props.onChange(setPatternDecimal(suffix, Number(decimal2 || 0)));
791
+ }, "handleDecimalChange"), handleClick = /* @__PURE__ */ __name((v) => {
792
+ v !== void 0 && (decimalSet(getDecimalFromPattern(v, 0)), suffixSet(v), props.onChange(v));
793
+ }, "handleClick");
794
+ return props.action.current = () => pattern, /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
795
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: localeService.t("sheet.numfmt.decimalLength") }),
796
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
797
+ InputNumber,
798
+ {
799
+ disabled: isInputDisable,
800
+ value: decimal,
801
+ max: 20,
802
+ min: 0,
803
+ onChange: handleDecimalChange
804
+ }
805
+ ) }),
806
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 label", children: [
807
+ " ",
808
+ localeService.t("sheet.numfmt.negType")
809
+ ] }),
810
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange: handleClick, options, value: suffix }) }),
811
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: localeService.t("sheet.numfmt.thousandthPercentileDes") })
812
+ ] });
813
+ }, "ThousandthPercentilePanel"), SheetNumfmtPanel = /* @__PURE__ */ __name((props) => {
810
814
  const { defaultValue, defaultPattern, row, col } = props.value, localeService = useDependency(LocaleService), getCurrentPattern = useRef(() => ""), t = localeService.t, nextTick = useNextTick(), typeOptions = useMemo(
811
815
  () => [
812
816
  { label: "sheet.numfmt.general", component: GeneralPanel },
@@ -978,6 +982,7 @@ let NumfmtController = (_a3 = class extends Disposable {
978
982
  this.openPanel(), disposableCollection.add(
979
983
  this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
980
984
  priority: 99,
985
+ effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
981
986
  handler: /* @__PURE__ */ __name((cell, location, next) => {
982
987
  const { row, col } = location, defaultValue = next(cell) || {};
983
988
  if (selectionRanges.find(
@@ -986,7 +991,7 @@ let NumfmtController = (_a3 = class extends Disposable {
986
991
  const rawValue = location.worksheet.getCellRaw(row, col), value = rawValue == null ? void 0 : rawValue.v, type = rawValue == null ? void 0 : rawValue.t;
987
992
  if (value == null || type !== CellValueType.NUMBER || this._previewPattern === null)
988
993
  return defaultValue;
989
- const info = getPatternPreview(this._previewPattern, value, this._localeService.getCurrentLocale());
994
+ const info = getPatternPreviewIgnoreGeneral(this._previewPattern, value, this._localeService.getCurrentLocale());
990
995
  if (info.color) {
991
996
  const color = this._themeService.getCurrentTheme()[`${info.color}500`];
992
997
  return {
package/lib/index.css CHANGED
@@ -1 +1 @@
1
- .numfmt-panel{overflow-y:auto;display:flex;flex-direction:column;justify-content:space-between;height:100%}.numfmt-panel .group-title{font-size:16px;color:rgba(var(--color-black))}.numfmt-panel .label{font-size:15px;color:rgba(var(--grey-400))}.numfmt-panel .describe{font-size:13px;line-height:20px;color:rgba(var(--grey-600))}.numfmt-panel .preview{height:36px;padding:0 16px;font-size:14px;line-height:36px;color:var(--color-black);border:1px solid rgb(var(--grey-200));border-radius:4px}.numfmt-panel .btn-list{display:flex;justify-content:flex-end}.numfmt-panel .m-r-12{margin-right:12px}.numfmt-panel .m-t-16{margin-top:16px}.numfmt-panel .m-t-14{margin-top:14px}.numfmt-panel .m-t-8{margin-top:8px}.numfmt-panel .m-b-20{margin-bottom:20px}.options{display:flex;justify-content:space-between}.options .w-140{width:140px}.options .w-120{width:120px}.univer-custom-format-title{margin-top:16px}.univer-custom-format-input{margin-top:8px;width:100%}.univer-custom-format-history-list{margin-top:8px;padding:8px;border-radius:8px;border:1px solid var(---Grey-200, #e5e5e5);max-height:400px;overflow:scroll}.univer-custom-format-history-list-item{padding:6px 0;display:flex;gap:6px;align-items:center;cursor:pointer}.univer-custom-format-history-list-item-icon-wrap{width:16px;display:flex;align-items:center;color:#274fee}.univer-custom-format-des{margin-top:8px;color:var(---Grey-600, #7a7a7a);font-size:12px;font-style:normal;font-weight:400;line-height:16px}.more-numfmt-type{display:flex;flex-shrink:0;padding:0 4px;font-size:13px;color:var(--black)}.more-numfmt-type .icon{display:flex;align-items:center;height:auto;padding-left:8px;color:rgb(var(--grey-400))}.more-numfmt-type-options .line{width:100%;height:1px;background-color:rgb(var(--grey-200))}.more-numfmt-type-options .m-t-4{margin-top:4px}.more-numfmt-type-options .option-item{display:flex;align-items:center;justify-content:space-between;height:28px;padding:0 8px;font-size:13px}.more-numfmt-type-options .option-item:hover{background-color:rgb(var(--grey-100));border-radius:var(--border-radius-base)}.more-numfmt-type-options .m-l-26{margin-left:26px}
1
+ .options{display:flex;justify-content:space-between}.options .w-140{width:140px}.options .w-120{width:120px}.univer-custom-format-title{margin-top:16px}.univer-custom-format-input{margin-top:8px;width:100%}.univer-custom-format-history-list{margin-top:8px;padding:8px;border-radius:8px;border:1px solid var(---Grey-200, #e5e5e5);max-height:400px;overflow:scroll}.univer-custom-format-history-list-item{padding:6px 0;display:flex;gap:6px;align-items:center;cursor:pointer}.univer-custom-format-history-list-item-icon-wrap{width:16px;display:flex;align-items:center;color:#274fee}.univer-custom-format-des{margin-top:8px;color:var(---Grey-600, #7a7a7a);font-size:12px;font-style:normal;font-weight:400;line-height:16px}.numfmt-panel{overflow-y:auto;display:flex;flex-direction:column;justify-content:space-between;height:100%}.numfmt-panel .group-title{font-size:16px;color:rgba(var(--color-black))}.numfmt-panel .label{font-size:15px;color:rgba(var(--grey-400))}.numfmt-panel .describe{font-size:13px;line-height:20px;color:rgba(var(--grey-600))}.numfmt-panel .preview{height:36px;padding:0 16px;font-size:14px;line-height:36px;color:var(--color-black);border:1px solid rgb(var(--grey-200));border-radius:4px}.numfmt-panel .btn-list{display:flex;justify-content:flex-end}.numfmt-panel .m-r-12{margin-right:12px}.numfmt-panel .m-t-16{margin-top:16px}.numfmt-panel .m-t-14{margin-top:14px}.numfmt-panel .m-t-8{margin-top:8px}.numfmt-panel .m-b-20{margin-bottom:20px}.more-numfmt-type{display:flex;flex-shrink:0;padding:0 4px;font-size:13px;color:var(--black)}.more-numfmt-type .icon{display:flex;align-items:center;height:auto;padding-left:8px;color:rgb(var(--grey-400))}.more-numfmt-type-options .line{width:100%;height:1px;background-color:rgb(var(--grey-200))}.more-numfmt-type-options .m-t-4{margin-top:4px}.more-numfmt-type-options .option-item{display:flex;align-items:center;justify-content:space-between;height:28px;padding:0 8px;font-size:13px}.more-numfmt-type-options .option-item:hover{background-color:rgb(var(--grey-100));border-radius:var(--border-radius-base)}.more-numfmt-type-options .m-l-26{margin-left:26px}
@@ -14,6 +14,9 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export { countryCurrencyMap } from './base/const/CURRENCY-SYMBOLS';
17
+ export { UniverSheetsNumfmtPlugin } from './numfmt-plugin';
18
+ export { MenuCurrencyService } from './service/menu.currency.service';
19
+ export { getPatternPreview, getPatternType } from './utils/pattern';
17
20
  export { AddDecimalCommand } from './commands/commands/add-decimal.command';
18
21
  export { SetCurrencyCommand } from './commands/commands/set-currency.command';
19
22
  export { type ISetNumfmtCommandParams, SetNumfmtCommand } from './commands/commands/set-numfmt.command';
@@ -21,6 +24,3 @@ export { SetPercentCommand } from './commands/commands/set-percent.command';
21
24
  export { SubtractDecimalCommand } from './commands/commands/subtract-decimal.command';
22
25
  export { CloseNumfmtPanelOperator } from './commands/operations/close.numfmt.panel.operation';
23
26
  export { OpenNumfmtPanelOperator } from './commands/operations/open.numfmt.panel.operation';
24
- export { UniverSheetsNumfmtPlugin } from './numfmt-plugin';
25
- export { MenuCurrencyService } from './service/menu.currency.service';
26
- export { getPatternPreview, getPatternType } from './utils/pattern';
@@ -1,10 +1,10 @@
1
1
  import { LocaleType } from '@univerjs/core';
2
2
  import { FormatType } from '@univerjs/sheets';
3
3
  export declare const getPatternType: (pattern: string) => FormatType;
4
- export declare const getPatternPreview: (pattern: string, value: number, _locale?: LocaleType) => {
4
+ interface IPatternPreview {
5
5
  result: string;
6
- color: string;
7
- } | {
8
- result: string;
9
- color?: undefined;
10
- };
6
+ color?: string;
7
+ }
8
+ export declare const getPatternPreview: (pattern: string, value: number, _locale?: LocaleType) => IPatternPreview;
9
+ export declare const getPatternPreviewIgnoreGeneral: (pattern: string, value: number, _locale?: LocaleType) => IPatternPreview;
10
+ export {};
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/sheets-ui"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs/operators"),require("react"),require("@univerjs/design"),require("@univerjs/engine-numfmt")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/sheets-ui","@univerjs/engine-render","@univerjs/ui","rxjs/operators","react","@univerjs/design","@univerjs/engine-numfmt"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsNumfmt={},global.UniverCore,global.UniverSheets,global.rxjs,global.UniverSheetsUi,global.UniverEngineRender,global.UniverUi,global.rxjs.operators,global.React,global.UniverDesign,global.UniverEngineNumfmt))})(this,function(exports2,core,sheets,rxjs,sheetsUi,engineRender,ui,operators,require$$0,design,engineNumfmt){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e,_f,_g,_h;const currencySymbols=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],countryCurrencyMap={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},getDecimalFromPattern=__name((pattern,defaultValue=0)=>{var _a2;return pattern&&(_a2=core.numfmt.getInfo(pattern).maxDecimals)!=null?_a2:defaultValue},"getDecimalFromPattern"),isPatternEqualWithoutDecimal=__name((patternA,patternB)=>{if(patternA&&!patternB||!patternA&&patternB)return!1;const getString=__name(tokens=>tokens.reduce((pre,cur)=>{if(pre.isEnd)return pre;const str=cur.value||cur.num;return cur.type==="point"?(pre.isEnd=!0,pre):{...pre,result:pre.result+str}},{isEnd:!1,result:""}).result,"getString"),partitionsA=core.numfmt.getInfo(patternA)._partitions,partitionsB=core.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){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}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"}],_MenuCurrencyService=class _MenuCurrencyService{constructor(){__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}};__name(_MenuCurrencyService,"MenuCurrencyService");let MenuCurrencyService=_MenuCurrencyService;const SetCurrencyCommand={id:"sheet.command.numfmt.set.currency",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),menuCurrencyService=accessor.get(MenuCurrencyService),symbol=countryCurrencyMap[menuCurrencyService.getCurrencySymbol()]||"$",selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix=CURRENCYFORMAT[4].suffix(symbol);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")},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")},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){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}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")},SHEET_NUMFMT_PLUGIN="SHEET_NUMFMT_PLUGIN",getPatternType=__name(pattern=>core.numfmt.getInfo(pattern).type||"unknown","getPatternType"),getPatternPreview=__name((pattern,value,_locale)=>{const info=core.numfmt.getInfo(pattern),locale=_locale===core.LocaleType.ZH_CN?"zh-CN":"en",negInfo=info._partitions[1],result=core.numfmt.format(pattern,value,{locale});return value<0?{result,color:negInfo.color}:{result}},"getPatternPreview");var __defProp$7=Object.defineProperty,__getOwnPropDesc$7=Object.getOwnPropertyDescriptor,__decorateClass$7=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$7(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$7(target,key2,result),result},"__decorateClass$7"),__decorateParam$7=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$7");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;let numfmtValue;if(cell!=null&&cell.s){const style=location.workbook.getStyles().get(cell.s);style!=null&&style.n&&(numfmtValue=style.n)}if(numfmtValue||(numfmtValue=this._numfmtService.getValue(unitId,sheetId,location.row,location.col)),!numfmtValue)return next(cell);const originCellValue=cell;if(!originCellValue||originCellValue.t!==core.CellValueType.NUMBER||originCellValue.v==null||Number.isNaN(originCellValue.v))return next(cell);let numfmtRes="";const cache=renderCache.getValue(location.row,location.col);if(cache&&cache.parameters===`${originCellValue.v}_${numfmtValue.pattern}`)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}_${numfmtValue.pattern}`}),next({...cell,...res})},"handler"),priority:sheets.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===sheets.SetNumfmtMutation.id){const params=commandInfo.params;Object.keys(params.values).forEach(key2=>{params.values[key2].ranges.forEach(range=>{core.Range.foreach(range,(row,col)=>{renderCache.realDeleteValue(row,col)})})})}else if(commandInfo.id===sheets.SetRangeValuesMutation.id){const params=commandInfo.params;new core.ObjectMatrix(params.cellValue).forValue((row,col)=>{renderCache.realDeleteValue(row,col)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.switchMap(workbook=>{var _a2;return(_a2=workbook==null?void 0:workbook.activeSheet$)!=null?_a2:rxjs.of(null)}),rxjs.skip(1)).subscribe(()=>renderCache.reset()))}},__name(_a,"SheetsNumfmtCellContentController"),_a);SheetsNumfmtCellContentController=__decorateClass$7([core.OnLifecycle(core.LifecycleStages.Rendered,SheetsNumfmtCellContentController),__decorateParam$7(0,core.IUniverInstanceService),__decorateParam$7(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$7(2,core.Inject(core.ThemeService)),__decorateParam$7(3,core.Inject(core.ICommandService)),__decorateParam$7(4,core.Inject(sheets.INumfmtService)),__decorateParam$7(5,core.Inject(core.LocaleService))],SheetsNumfmtCellContentController);var jsxRuntime={exports:{}},reactJsxRuntime_production_min={};/**
1
+ (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs/operators"),require("react"),require("@univerjs/design"),require("@univerjs/engine-numfmt")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/sheets-ui","rxjs","@univerjs/engine-render","@univerjs/ui","rxjs/operators","react","@univerjs/design","@univerjs/engine-numfmt"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsNumfmt={},global.UniverCore,global.UniverSheets,global.UniverSheetsUi,global.rxjs,global.UniverEngineRender,global.UniverUi,global.rxjs.operators,global.React,global.UniverDesign,global.UniverEngineNumfmt))})(this,function(exports2,core,sheets,sheetsUi,rxjs,engineRender,ui,operators,require$$0,design,engineNumfmt){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e,_f,_g,_h;const currencySymbols=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],countryCurrencyMap={US:"$",CA:"C$",GB:"£",JP:"¥",IN:"₹",AU:"A$",CN:"¥",KR:"₩",RU:"₽",AT:"€",BE:"€",CY:"€",EE:"€",FI:"€",FR:"€",DE:"€",GR:"€",IE:"€",IT:"€",LV:"€",LT:"€",LU:"€",MT:"€",NL:"€",PT:"€",SK:"€",SI:"€",ES:"€"},SHEET_NUMFMT_PLUGIN="SHEET_NUMFMT_PLUGIN",getPatternType=__name(pattern=>core.numfmt.getInfo(pattern).type||"unknown","getPatternType"),getPatternPreview=__name((pattern,value,_locale)=>{const info=core.numfmt.getInfo(pattern),locale=_locale===core.LocaleType.ZH_CN?"zh-CN":"en",negInfo=info._partitions[1],result=core.numfmt.format(pattern,value,{locale,throws:!1});return value<0?{result,color:negInfo.color}:{result}},"getPatternPreview"),getPatternPreviewIgnoreGeneral=__name((pattern,value,_locale)=>pattern==="General"?{result:String(value)}:getPatternPreview(pattern,value,_locale),"getPatternPreviewIgnoreGeneral");var __defProp$7=Object.defineProperty,__getOwnPropDesc$7=Object.getOwnPropertyDescriptor,__decorateClass$7=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$7(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$7(target,key2,result),result},"__decorateClass$7"),__decorateParam$7=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$7");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,{effect:core.InterceptorEffectEnum.Value|core.InterceptorEffectEnum.Style,handler:__name((cell,location,next)=>{const unitId=location.unitId,sheetId=location.subUnitId;let numfmtValue;const originCellValue=cell;if(!originCellValue||originCellValue.t!==core.CellValueType.NUMBER||originCellValue.v==null||Number.isNaN(originCellValue.v))return next(cell);if(cell!=null&&cell.s){const style=location.workbook.getStyles().get(cell.s);style!=null&&style.n&&(numfmtValue=style.n)}if(numfmtValue||(numfmtValue=this._numfmtService.getValue(unitId,sheetId,location.row,location.col)),!numfmtValue)return next(cell);let numfmtRes="";const cache=renderCache.getValue(location.row,location.col);if(cache&&cache.parameters===`${originCellValue.v}_${numfmtValue.pattern}`)return next({...cell,...cache.result});const info=getPatternPreviewIgnoreGeneral(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}_${numfmtValue.pattern}`}),next({...cell,...res})},"handler"),priority:sheets.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===sheets.SetNumfmtMutation.id){const params=commandInfo.params;Object.keys(params.values).forEach(key2=>{params.values[key2].ranges.forEach(range=>{core.Range.foreach(range,(row,col)=>{renderCache.realDeleteValue(row,col)})})})}else if(commandInfo.id===sheets.SetRangeValuesMutation.id){const params=commandInfo.params;new core.ObjectMatrix(params.cellValue).forValue((row,col)=>{renderCache.realDeleteValue(row,col)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.switchMap(workbook=>{var _a2;return(_a2=workbook==null?void 0:workbook.activeSheet$)!=null?_a2:rxjs.of(null)}),rxjs.skip(1)).subscribe(()=>renderCache.reset()))}},__name(_a,"SheetsNumfmtCellContentController"),_a);SheetsNumfmtCellContentController=__decorateClass$7([core.OnLifecycle(core.LifecycleStages.Rendered,SheetsNumfmtCellContentController),__decorateParam$7(0,core.IUniverInstanceService),__decorateParam$7(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$7(2,core.Inject(core.ThemeService)),__decorateParam$7(3,core.Inject(core.ICommandService)),__decorateParam$7(4,core.Inject(sheets.INumfmtService)),__decorateParam$7(5,core.Inject(core.LocaleService))],SheetsNumfmtCellContentController);const getDecimalFromPattern=__name((pattern,defaultValue=0)=>{var _a2;return pattern&&(_a2=core.numfmt.getInfo(pattern).maxDecimals)!=null?_a2:defaultValue},"getDecimalFromPattern"),isPatternEqualWithoutDecimal=__name((patternA,patternB)=>{if(patternA&&!patternB||!patternA&&patternB)return!1;const getString=__name(tokens=>tokens.reduce((pre,cur)=>{if(pre.isEnd)return pre;const str=cur.value||cur.num;return cur.type==="point"?(pre.isEnd=!0,pre):{...pre,result:pre.result+str}},{isEnd:!1,result:""}).result,"getString"),partitionsA=core.numfmt.getInfo(patternA)._partitions,partitionsB=core.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){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}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"}],_MenuCurrencyService=class _MenuCurrencyService{constructor(){__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}};__name(_MenuCurrencyService,"MenuCurrencyService");let MenuCurrencyService=_MenuCurrencyService;const SetCurrencyCommand={id:"sheet.command.numfmt.set.currency",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const commandService=accessor.get(core.ICommandService),selectionManagerService=accessor.get(sheets.SheetsSelectionsService),menuCurrencyService=accessor.get(MenuCurrencyService),symbol=countryCurrencyMap[menuCurrencyService.getCurrencySymbol()]||"$",selections=selectionManagerService.getCurrentSelections();if(!selections||!selections.length)return!1;const values=[],suffix=CURRENCYFORMAT[4].suffix(symbol);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")},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")},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){const cell=target.worksheet.getCellRaw(row,col);if(!maxDecimals&&cell&&cell.t===core.CellValueType.NUMBER&&cell.v){const regResult=/\.(\d*)$/.exec(String(cell.v));if(regResult){const length=regResult[1].length;if(!length)return;maxDecimals=Math.max(maxDecimals,length)}}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 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([]);var __defProp$6=Object.defineProperty,__getOwnPropDesc$6=Object.getOwnPropertyDescriptor,__decorateClass$6=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$6(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$6(target,key2,result),result},"__decorateClass$6"),__decorateParam$6=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$6");let UserHabitController=(_b=class{constructor(_localStorageService){this._localStorageService=_localStorageService}_getKey(habit){return`userHabitController_${habit}`}async addHabit(habit,initValue){const key2=this._getKey(habit);return this._localStorageService.getItem(key2).then(item=>{item||this._localStorageService.setItem(key2,initValue)})}markHabit(habit,value){const key2=this._getKey(habit);this._localStorageService.getItem(key2).then(list=>{if(list){const index=list.findIndex(item=>item===value);index>-1&&list.splice(index,1),list.unshift(value),this._localStorageService.setItem(key2,list)}})}async getHabit(habit,sortList){const key2=this._getKey(habit),result=await this._localStorageService.getItem(key2);if(sortList&&result){const priority=result.map((item,index,arr)=>{const length=arr.length;return{value:item,priority:length-index}});return sortList.sort((a,b)=>{var _a2,_b2;const ap=((_a2=priority.find(item=>item.value===a))==null?void 0:_a2.priority)||-1;return(((_b2=priority.find(item=>item.value===b))==null?void 0:_b2.priority)||-1)-ap})}return result||[]}deleteHabit(habit){this._localStorageService.removeItem(habit)}},__name(_b,"UserHabitController"),_b);UserHabitController=__decorateClass$6([__decorateParam$6(0,core.Inject(core.ILocalStorageService))],UserHabitController);const key$1="numfmtCurrency",useCurrencyOptions=__name(onOptionChange=>{const userHabitController=core.useDependency(UserHabitController),[options,optionsSet]=require$$0.useState(currencySymbols);return require$$0.useEffect(()=>{userHabitController.addHabit("numfmtCurrency",[]).then(()=>{userHabitController.getHabit(key$1,[...currencySymbols]).then(list=>{optionsSet(list),onOptionChange&&onOptionChange(list)})})},[]),{userHabitCurrency:options,mark:__name(v=>{userHabitController.markHabit(key$1,v)},"mark")}},"useCurrencyOptions"),useNextTick=__name(()=>{const effectList=require$$0.useRef([]),[value,dispatch]=require$$0.useState({});return require$$0.useEffect(()=>{effectList.current.forEach(fn=>{fn()}),effectList.current=[]},[value]),__name(fn=>{effectList.current.push(fn),dispatch({})},"nextTick")},"useNextTick"),getCurrencyType=__name(pattern=>currencySymbols.find(code=>pattern.includes(code)),"getCurrencyType"),isAccountingPanel=__name(pattern=>!!getCurrencyType(pattern)&&pattern.startsWith("_("),"isAccountingPanel"),AccountingPanel=__name(props=>{const[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",2)),userHabitCurrency=require$$0.useContext(UserHabitCurrencyContext),[suffix,suffixSet]=require$$0.useState(()=>getCurrencyType(props.defaultPattern)||userHabitCurrency[0]),options=require$$0.useMemo(()=>userHabitCurrency.map(key2=>({label:key2,value:key2})),[]),t=core.useDependency(core.LocaleService).t;props.action.current=()=>setPatternDecimal(`_("${suffix}"* #,##0${decimal>0?".0":""}_)`,decimal);const onSelect=__name(v=>{suffixSet(v),props.onChange(setPatternDecimal(`_("${v}"* #,##0${decimal>0?".0":""}_)`,decimal))},"onSelect"),onDecimalChange=__name(v=>{const decimal2=v||0;decimalSet(decimal2),props.onChange(setPatternDecimal(`_("${suffix}"* #,##0${decimal2>0?".0":""}_)`,decimal2))},"onDecimalChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsxs("div",{className:"m-t-16 options ",children:[jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-120",children:jsxRuntimeExports.jsx(design.InputNumber,{value:decimal,max:20,min:0,onChange:onDecimalChange})})]}),jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.currencyType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-140",children:jsxRuntimeExports.jsx(design.Select,{onChange:onSelect,options,value:suffix})})]})]}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.accountingDes")})]})},"AccountingPanel"),getCurrencyFormatOptions=__name(suffix=>CURRENCYFORMAT.map(item=>({label:item.label(suffix),value:item.suffix(suffix),color:item.color})),"getCurrencyFormatOptions"),getDateFormatOptions=__name(()=>DATEFMTLISG.map(item=>({label:item.label,value:item.suffix})),"getDateFormatOptions"),getNumberFormatOptions=__name(()=>NUMBERFORMAT.map(item=>({label:item.label,value:item.suffix,color:item.color})),"getNumberFormatOptions"),isCurrencyPanel=__name(pattern=>!!getCurrencyType(pattern)&&!pattern.startsWith("_("),"isCurrencyPanel"),CurrencyPanel=__name(props=>{const t=core.useDependency(core.LocaleService).t,userHabitCurrency=require$$0.useContext(UserHabitCurrencyContext),[suffix,suffixSet]=require$$0.useState(()=>getCurrencyType(props.defaultPattern)||userHabitCurrency[0]),[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",2)),[pattern,patternSet]=require$$0.useState(()=>{var _a2;const negativeOptions2=getCurrencyFormatOptions(suffix);return((_a2=negativeOptions2.find(item=>isPatternEqualWithoutDecimal(item.value,props.defaultPattern)))==null?void 0:_a2.value)||negativeOptions2[0].value}),negativeOptions=require$$0.useMemo(()=>getCurrencyFormatOptions(suffix),[suffix]),options=require$$0.useMemo(()=>userHabitCurrency.map(key2=>({label:key2,value:key2})),[userHabitCurrency]);props.action.current=()=>setPatternDecimal(pattern,decimal);const onSelect=__name(value=>{if(value===void 0)return;suffixSet(value);const pattern2=getCurrencyFormatOptions(value)[0].value;patternSet(pattern2),props.onChange(setPatternDecimal(pattern2,decimal))},"onSelect"),onChange=__name(value=>{value!==void 0&&(patternSet(value),props.onChange(setPatternDecimal(value,decimal)))},"onChange"),onDecimalChange=__name(v=>{decimalSet(v||0),props.onChange(setPatternDecimal(pattern,v||0))},"onDecimalChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsxs("div",{className:"m-t-16 options ",children:[jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-120",children:jsxRuntimeExports.jsx(design.InputNumber,{value:decimal,max:20,min:0,onChange:onDecimalChange})})]}),jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.currencyType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-140",children:jsxRuntimeExports.jsx(design.Select,{onChange:onSelect,options,value:suffix})})]})]}),jsxRuntimeExports.jsx("div",{className:"m-t-16 label",children:t("sheet.numfmt.negType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.SelectList,{onChange,options:negativeOptions,value:pattern})}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.currencyDes")})]})},"CurrencyPanel"),isDatePanel=__name(pattern=>{const info=core.numfmt.getInfo(pattern);return getDateFormatOptions().map(item=>item.value).includes(pattern)||["date","datetime","time"].includes(info.type)},"isDatePanel"),DatePanel=__name(props=>{const options=require$$0.useMemo(getDateFormatOptions,[]),t=core.useDependency(core.LocaleService).t,[suffix,suffixSet]=require$$0.useState(()=>{if(props.defaultPattern){const item=options.find(item2=>item2.value===props.defaultPattern);if(item)return item.value}return options[0].value});props.action.current=()=>suffix;const onChange=__name(v=>{v!==void 0&&(suffixSet(v),props.onChange(v))},"onChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"m-t-16 label",children:t("sheet.numfmt.dateType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.SelectList,{value:suffix,options,onChange})}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.dateDes")})]})},"DatePanel"),isGeneralPanel=__name(pattern=>!pattern,"isGeneralPanel"),GeneralPanel=__name(props=>{const t=core.useDependency(core.LocaleService).t;return props.action.current=()=>"",jsxRuntimeExports.jsx("div",{children:jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.generalDes")})})},"GeneralPanel"),isThousandthPercentilePanel=__name(pattern=>getNumberFormatOptions().some(item=>isPatternEqualWithoutDecimal(item.value,pattern)),"isThousandthPercentilePanel"),ThousandthPercentilePanel=__name(props=>{const localeService=core.useDependency(core.LocaleService),options=require$$0.useMemo(getNumberFormatOptions,[]),[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",0)),[suffix,suffixSet]=require$$0.useState(()=>{const item=options.find(item2=>isPatternEqualWithoutDecimal(item2.value,props.defaultPattern||""));return(item==null?void 0:item.value)||options[0].value}),pattern=require$$0.useMemo(()=>setPatternDecimal(suffix,Number(decimal||0)),[suffix,decimal]),isInputDisable=require$$0.useMemo(()=>!isPatternHasDecimal(suffix),[suffix]),handleDecimalChange=__name(decimal2=>{decimalSet(decimal2||0),props.onChange(setPatternDecimal(suffix,Number(decimal2||0)))},"handleDecimalChange"),handleClick=__name(v=>{v!==void 0&&(decimalSet(getDecimalFromPattern(v,0)),suffixSet(v),props.onChange(v))},"handleClick");return props.action.current=()=>pattern,jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"m-t-16 label",children:localeService.t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.InputNumber,{disabled:isInputDisable,value:decimal,max:20,min:0,onChange:handleDecimalChange})}),jsxRuntimeExports.jsxs("div",{className:"m-t-16 label",children:[" ",localeService.t("sheet.numfmt.negType")]}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.SelectList,{onChange:handleClick,options,value:suffix})}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:localeService.t("sheet.numfmt.thousandthPercentileDes")})]})},"ThousandthPercentilePanel");var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n2=arguments.length;i<n2;i++){s=arguments[i];for(var p2 in s)Object.prototype.hasOwnProperty.call(s,p2)&&(t[p2]=s[p2])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p2 in s)Object.prototype.hasOwnProperty.call(s,p2)&&e.indexOf(p2)<0&&(t[p2]=s[p2]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p2=Object.getOwnPropertySymbols(s);i<p2.length;i++)e.indexOf(p2[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p2[i])&&(t[p2[i]]=s[p2[i]]);return t},IconBase=require$$0.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=require$$0.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return require$$0.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a2){var key2=_a2[0],value=_a2[1];typeof value=="string"&&(attrs[key2]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a2,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a2=node.children)===null||_a2===void 0)&&_a2.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid"),IconBase.displayName="UniverIcon";var element={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},CheckMarkSingle=require$$0.forwardRef(function(props,ref){return require$$0.createElement(IconBase,Object.assign({},props,{id:"check-mark-single",ref,icon:element}))});CheckMarkSingle.displayName="CheckMarkSingle";const styles={customFormatTitle:"univer-custom-format-title",customFormatInput:"univer-custom-format-input",customFormatHistoryList:"univer-custom-format-history-list",customFormatHistoryListItem:"univer-custom-format-history-list-item",customFormatHistoryListItemIconWrap:"univer-custom-format-history-list-item-icon-wrap",customFormatDes:"univer-custom-format-des"},key="customFormat",historyPatternKey="numfmt_custom_pattern";function CustomFormat(props){const{defaultPattern,action,onChange}=props,userHabitController=core.useDependency(UserHabitController),localStorageService=core.useDependency(core.ILocalStorageService),localeService=core.useDependency(core.LocaleService),[pattern,patternSet]=require$$0.useState(defaultPattern);action.current=()=>(userHabitController.markHabit(key,pattern),localStorageService.getItem(historyPatternKey).then((list=[])=>{const _list=[...new Set([pattern,...list||[]])].splice(0,10).filter(e=>!!e);localStorageService.setItem(historyPatternKey,_list)}),pattern);const[options,optionsSet]=require$$0.useState([]);require$$0.useEffect(()=>{localStorageService.getItem(historyPatternKey).then(historyList=>{const list=[...CURRENCYFORMAT.map(item=>item.suffix("$")),...DATEFMTLISG.map(item=>item.suffix),...NUMBERFORMAT.map(item=>item.suffix)];list.push(...historyList||[]),userHabitController.addHabit(key,[]).finally(()=>{userHabitController.getHabit(key,list).then(list2=>{optionsSet([...new Set(list2)])})})})},[]);const handleClick=__name(p2=>{patternSet(p2),onChange(p2)},"handleClick"),handleBlur=__name(()=>{onChange(pattern)},"handleBlur");return jsxRuntimeExports.jsxs("div",{className:styles.customFormat,children:[jsxRuntimeExports.jsx("div",{className:styles.customFormatTitle,children:localeService.t("sheet.numfmt.customFormat")}),jsxRuntimeExports.jsx(design.Input,{placeholder:localeService.t("sheet.numfmt.customFormat"),onBlur:handleBlur,value:pattern,onChange:patternSet,className:styles.customFormatInput}),jsxRuntimeExports.jsx("div",{className:styles.customFormatHistoryList,children:options.map(p2=>jsxRuntimeExports.jsxs("div",{onClick:__name(()=>handleClick(p2),"onClick"),className:styles.customFormatHistoryListItem,children:[jsxRuntimeExports.jsx("div",{className:styles.customFormatHistoryListItemIconWrap,children:pattern===p2&&jsxRuntimeExports.jsx(CheckMarkSingle,{})}),jsxRuntimeExports.jsx("div",{children:p2})]},p2))}),jsxRuntimeExports.jsx("div",{className:styles.customFormatDes,children:localeService.t("sheet.numfmt.customFormatDes")})]})}__name(CustomFormat,"CustomFormat");const SheetNumfmtPanel=__name(props=>{const{defaultValue,defaultPattern,row,col}=props.value,localeService=core.useDependency(core.LocaleService),getCurrentPattern=require$$0.useRef(()=>""),t=localeService.t,nextTick=useNextTick(),typeOptions=require$$0.useMemo(()=>[{label:"sheet.numfmt.general",component:GeneralPanel},{label:"sheet.numfmt.accounting",component:AccountingPanel},{label:"sheet.numfmt.currency",component:CurrencyPanel},{label:"sheet.numfmt.date",component:DatePanel},{label:"sheet.numfmt.thousandthPercentile",component:ThousandthPercentilePanel},{label:"sheet.numfmt.customFormat",component:CustomFormat}].map(item=>({...item,label:t(item.label)})),[]),[type,typeSet]=require$$0.useState(findDefaultType),[key2,keySet]=require$$0.useState(()=>`${row}_${col}`),{mark,userHabitCurrency}=useCurrencyOptions(()=>keySet(`${row}_${col}_userCurrency'`)),BusinessComponent=require$$0.useMemo(()=>{var _a2;return(_a2=typeOptions.find(item=>item.label===type))==null?void 0:_a2.component},[type]);function findDefaultType(){return[isGeneralPanel,isAccountingPanel,isCurrencyPanel,isDatePanel,isThousandthPercentilePanel].reduce((pre,curFn,index)=>pre||(curFn(defaultPattern)?typeOptions[index].label:""),"")||typeOptions[0].label}__name(findDefaultType,"findDefaultType");const selectOptions=typeOptions.map(option=>({label:option.label,value:option.label})),handleSelect=__name(value=>{typeSet(value),nextTick(()=>props.onChange({type:"change",value:getCurrentPattern.current()||""}))},"handleSelect"),handleChange=__name(v=>{props.onChange({type:"change",value:v})},"handleChange"),handleConfirm=__name(()=>{const pattern=getCurrentPattern.current()||"",currency=getCurrencyType(pattern);currency&&mark(currency),props.onChange({type:"confirm",value:pattern})},"handleConfirm"),handleCancel=__name(()=>{props.onChange({type:"cancel",value:""})},"handleCancel"),subProps={onChange:handleChange,defaultValue,defaultPattern,action:getCurrentPattern};return require$$0.useEffect(()=>{typeSet(findDefaultType()),keySet(`${row}_${col}`)},[row,col]),jsxRuntimeExports.jsxs("div",{className:"numfmt-panel p-b-20",children:[jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"label m-t-14",children:t("sheet.numfmt.numfmtType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.Select,{onChange:handleSelect,options:selectOptions,value:type,style:{width:"100%"}})}),jsxRuntimeExports.jsx("div",{children:BusinessComponent&&jsxRuntimeExports.jsx(UserHabitCurrencyContext.Provider,{value:userHabitCurrency,children:require$$0.createElement(BusinessComponent,{...subProps,key:key2})})})]}),jsxRuntimeExports.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[jsxRuntimeExports.jsx(design.Button,{size:"small",onClick:handleCancel,className:"m-r-12",children:t("sheet.numfmt.cancel")}),jsxRuntimeExports.jsx(design.Button,{type:"primary",size:"small",onClick:handleConfirm,children:t("sheet.numfmt.confirm")})]})]})},"SheetNumfmtPanel");var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key2,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$5");let NumfmtController=(_c=class extends core.Disposable{constructor(_sheetInterceptorService,_themeService,_univerInstanceService,_commandService,_selectionManagerService,_renderManagerService,_numfmtService,_componentManager,_sidebarService,_localeService){super();__publicField(this,"_previewPattern","");__publicField(this,"_sidebarDisposable",null);this._sheetInterceptorService=_sheetInterceptorService,this._themeService=_themeService,this._univerInstanceService=_univerInstanceService,this._commandService=_commandService,this._selectionManagerService=_selectionManagerService,this._renderManagerService=_renderManagerService,this._numfmtService=_numfmtService,this._componentManager=_componentManager,this._sidebarService=_sidebarService,this._localeService=_localeService,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var _a2;const sidebarService=this._sidebarService,selectionManagerService=this._selectionManagerService,commandService=this._commandService,univerInstanceService=this._univerInstanceService,numfmtService=this._numfmtService,localeService=this._localeService,range=(((_a2=selectionManagerService.getCurrentSelections())==null?void 0:_a2.map(s=>s.range))||[])[0];if(!range)return!1;const workbook=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),sheet=workbook.getActiveSheet();if(!sheet)return!1;const cellValue=sheet.getCellRaw(range.startRow,range.startColumn),numfmtValue=numfmtService.getValue(workbook.getUnitId(),sheet.getSheetId(),range.startRow,range.startColumn);let pattern="";numfmtValue&&(pattern=numfmtValue.pattern);const defaultValue=(cellValue==null?void 0:cellValue.t)===core.CellValueType.NUMBER?cellValue.v:12345678,props={onChange:__name(config=>{var _a3;if(config.type==="change")this._previewPattern=config.value,this._forceUpdate();else if(config.type==="confirm"){const selections2=((_a3=selectionManagerService.getCurrentSelections())==null?void 0:_a3.map(s=>s.range))||[],params={values:[]},patternType=getPatternType(config.value);selections2.forEach(rangeInfo=>{core.Range.foreach(rangeInfo,(row,col)=>{params.values.push({row,col,pattern:config.value,type:patternType})})}),commandService.executeCommand(SetNumfmtCommand.id,params),sidebarService.close()}else config.type==="cancel"&&sidebarService.close()},"onChange"),value:{defaultPattern:pattern,defaultValue,row:range.startRow,col:range.startColumn}};return this._sidebarDisposable=sidebarService.open({header:{title:localeService.t("sheet.numfmt.title")},children:{label:SHEET_NUMFMT_PLUGIN,...props},onClose:__name(()=>{this._forceUpdate(),commandService.executeCommand(CloseNumfmtPanelOperator.id)},"onClose")}),!0}_forceUpdate(unitId){var _a2;const renderUnit=this._renderManagerService.getRenderById(unitId!=null?unitId:this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET).getUnitId());renderUnit==null||renderUnit.with(sheetsUi.SheetSkeletonManagerService).reCalculate(),(_a2=renderUnit==null?void 0:renderUnit.mainComponent)==null||_a2.makeDirty()}_initCommands(){[AddDecimalCommand,SubtractDecimalCommand,SetCurrencyCommand,SetPercentCommand,OpenNumfmtPanelOperator,CloseNumfmtPanelOperator,SetNumfmtCommand].forEach(config=>{this.disposeWithMe(this._commandService.registerCommand(config))})}_initPanel(){this._componentManager.register(SHEET_NUMFMT_PLUGIN,SheetNumfmtPanel)}_initRealTimeRenderingInterceptor(){const isPanelOpenObserver=new rxjs.Observable(subscriber=>{this._commandService.onCommandExecuted(commandInfo=>{commandInfo.id===OpenNumfmtPanelOperator.id&&subscriber.next(!0),commandInfo.id===CloseNumfmtPanelOperator.id&&subscriber.next(!1)})}),combineOpenAndSelection$=rxjs.combineLatest([isPanelOpenObserver,this._selectionManagerService.selectionMoveEnd$.pipe(operators.map(selectionInfos=>selectionInfos?selectionInfos.map(selectionInfo=>selectionInfo.range):[]))]);this.disposeWithMe(core.toDisposable(combineOpenAndSelection$.pipe(operators.switchMap(([isOpen,selectionRanges])=>new rxjs.Observable(subscribe=>{const disposableCollection=new core.DisposableCollection;return isOpen&&selectionRanges.length&&subscribe.next({selectionRanges,disposableCollection}),()=>{disposableCollection.dispose()}})),operators.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection,selectionRanges})=>{var _a2,_b2;const workbook=this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET);this.openPanel(),disposableCollection.add(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,handler:__name((cell,location,next)=>{const{row,col}=location,defaultValue=next(cell)||{};if(selectionRanges.find(range=>range.startColumn<=col&&range.endColumn>=col&&range.startRow<=row&&range.endRow>=row)){const rawValue=location.worksheet.getCellRaw(row,col),value=rawValue==null?void 0:rawValue.v,type=rawValue==null?void 0:rawValue.t;if(value==null||type!==core.CellValueType.NUMBER||this._previewPattern===null)return defaultValue;const info=getPatternPreview(this._previewPattern,value,this._localeService.getCurrentLocale());if(info.color){const color=this._themeService.getCurrentTheme()[`${info.color}500`];return{...defaultValue,v:info.result,t:core.CellValueType.STRING,s:{cl:{rgb:color}}}}return{...defaultValue,v:info.result,t:core.CellValueType.STRING}}return defaultValue},"handler")})),(_b2=(_a2=this._renderManagerService.getRenderById(workbook.getUnitId()))==null?void 0:_a2.mainComponent)==null||_b2.makeDirty()})))}_commandExecutedListener(){const commandList=[sheets.RemoveNumfmtMutation.id,sheets.SetNumfmtMutation.id];this.disposeWithMe(new rxjs.Observable(subscribe=>{const disposable=this._commandService.onCommandExecuted(command=>{if(commandList.includes(command.id)){const params=command.params;subscribe.next(params.unitId)}});return()=>disposable.dispose()}).pipe(operators.debounceTime(16)).subscribe(unitId=>this._forceUpdate(unitId)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).subscribe(unit=>{var _a2;unit||((_a2=this._sidebarDisposable)==null||_a2.dispose(),this._sidebarDisposable=null)})}},__name(_c,"NumfmtController"),_c);NumfmtController=__decorateClass$5([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtController),__decorateParam$5(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$5(1,core.Inject(core.ThemeService)),__decorateParam$5(2,core.IUniverInstanceService),__decorateParam$5(3,core.ICommandService),__decorateParam$5(4,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$5(5,engineRender.IRenderManagerService),__decorateParam$5(6,sheets.INumfmtService),__decorateParam$5(7,core.Inject(ui.ComponentManager)),__decorateParam$5(8,ui.ISidebarService),__decorateParam$5(9,core.Inject(core.LocaleService))],NumfmtController);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");const createCollectEffectMutation=__name(()=>{let list=[];return{add:__name((unitId,subUnitId,row,col,value)=>list.push({unitId,subUnitId,row,col,value}),"add"),getEffects:__name(()=>list,"getEffects"),clean:__name(()=>{list=[]},"clean")}},"createCollectEffectMutation");let NumfmtEditorController=(_d=class extends core.Disposable{constructor(_sheetInterceptorService,_numfmtService,_univerInstanceService,_injector,_editorBridgeService){super();__publicField(this,"_collectEffectMutation",createCollectEffectMutation());this._sheetInterceptorService=_sheetInterceptorService,this._numfmtService=_numfmtService,this._univerInstanceService=_univerInstanceService,this._injector=_injector,this._editorBridgeService=_editorBridgeService,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(core.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{handler:__name((value,context,next)=>{const row=context.row,col=context.col,numfmtCell=this._numfmtService.getValue(context.unitId,context.subUnitId,row,col);if(numfmtCell)switch(getPatternType(numfmtCell.pattern)){case"scientific":case"currency":case"grouped":case"number":return context.worksheet.getCellRaw(row,col);case"percent":case"date":case"time":case"datetime":default:return next&&next(value)}return next(value)},"handler")})))}_initInterceptorEditorEnd(){this._editorBridgeService&&this.disposeWithMe(core.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{handler:__name((value,context,next)=>{var _a2;this._collectEffectMutation.clean();const currentNumfmtValue=this._numfmtService.getValue(context.unitId,context.subUnitId,context.row,context.col),currentNumfmtType=(_a2=currentNumfmtValue&&getPatternType(currentNumfmtValue.pattern))!=null?_a2:"",clean=__name(()=>{currentNumfmtValue&&this._collectEffectMutation.add(context.unitId,context.subUnitId,context.row,context.col,null)},"clean");if(!(value!=null&&value.v))return next(value);const content=String(value.v),numfmtInfo=core.numfmt.parseDate(content)||core.numfmt.parseTime(content)||core.numfmt.parseNumber(content);if(numfmtInfo){if(numfmtInfo.z){const v=Number(numfmtInfo.v);return this._collectEffectMutation.add(context.unitId,context.subUnitId,context.row,context.col,{pattern:numfmtInfo.z}),{...value,v,t:core.CellValueType.NUMBER}}}else(["date","time","datetime","percent"].includes(currentNumfmtType)||!isNumeric(content))&&clean();return next(value)},"handler")})))}_initInterceptorCommands(){const self2=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(command){var _a2;switch(command.id){case sheets.SetRangeValuesCommand.id:{const workbook=self2._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),unitId=workbook.getUnitId(),subUnitId=(_a2=workbook.getActiveSheet())==null?void 0:_a2.getSheetId();if(!subUnitId)return{redos:[],undos:[]};const list=self2._collectEffectMutation.getEffects();if(self2._collectEffectMutation.clean(),!list.length)return{redos:[],undos:[]};const cells=list.filter(item=>{var _a3;return!!((_a3=item.value)!=null&&_a3.pattern)}).map(item=>({row:item.row,col:item.col,pattern:item.value.pattern})),removeCells=list.filter(item=>{var _a3;return!((_a3=item.value)!=null&&_a3.pattern)}).map(item=>({startRow:item.row,endColumn:item.col,startColumn:item.col,endRow:item.row})),redos=[],undos=[];if(cells.length){const redo={id:sheets.SetNumfmtMutation.id,params:sheets.transformCellsToRange(unitId,subUnitId,cells)};redos.push(redo),undos.push(...sheets.factorySetNumfmtUndoMutation(self2._injector,redo.params))}if(removeCells.length){const redo={id:sheets.RemoveNumfmtMutation.id,params:{unitId,subUnitId,ranges:removeCells}};redos.push(redo),undos.push(...sheets.factoryRemoveNumfmtUndoMutation(self2._injector,redo.params))}return{redos,undos:undos.reverse()}}}return{redos:[],undos:[]}}}))}},__name(_d,"NumfmtEditorController"),_d);NumfmtEditorController=__decorateClass$4([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtEditorController),__decorateParam$4(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$4(1,core.Inject(sheets.INumfmtService)),__decorateParam$4(2,core.Inject(core.IUniverInstanceService)),__decorateParam$4(3,core.Inject(core.Injector)),__decorateParam$4(4,core.Optional(sheetsUi.IEditorBridgeService))],NumfmtEditorController);function isNumeric(str){return/^-?\d+(\.\d+)?$/.test(str)}__name(isNumeric,"isNumeric");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");let NumfmtI18nController=(_e=class extends core.Disposable{constructor(_localeService){super(),this._localeService=_localeService}},__name(_e,"NumfmtI18nController"),_e);NumfmtI18nController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtI18nController),__decorateParam$3(0,core.Inject(core.LocaleService))],NumfmtI18nController);const MENU_OPTIONS=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:engineNumfmt.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],MORE_NUMFMT_TYPE_KEY="sheet.numfmt.moreNumfmtType",OPTIONS_KEY="sheet.numfmt.moreNumfmtType.options",MoreNumfmtType=__name(props=>{var _a2;const localeService=core.useDependency(core.LocaleService),value=(_a2=props.value)!=null?_a2:localeService.t("sheet.numfmt.general");return jsxRuntimeExports.jsx("span",{className:"more-numfmt-type",children:value})},"MoreNumfmtType"),Options=__name(()=>{const commandService=core.useDependency(core.ICommandService),localeService=core.useDependency(core.LocaleService),layoutService=core.useDependency(ui.ILayoutService);core.useInjector();const selectionManagerService=core.useDependency(sheets.SheetsSelectionsService),setNumfmt=__name(pattern=>{const selection=selectionManagerService.getCurrentLastSelection();if(!selection)return;const 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}),layoutService.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:new rxjs.Observable(subscribe=>{const menuCurrencyService=accessor.get(MenuCurrencyService);function getIconKey(symbol2){return{[countryCurrencyMap.US]:"DollarSingle",[countryCurrencyMap.RU]:"RoubleSingle",[countryCurrencyMap.CN]:"RmbSingle",[countryCurrencyMap.AT]:"EuroSingle"}[symbol2]||"DollarSingle"}__name(getIconKey,"getIconKey");const symbol=countryCurrencyMap[menuCurrencyService.getCurrencySymbol()]||"$";return subscribe.next(getIconKey(symbol)),menuCurrencyService.currencySymbol$.subscribe(code=>{const symbol2=countryCurrencyMap[code]||"$";subscribe.next(getIconKey(symbol2))})}),id:SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:ui.MenuItemType.BUTTON,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,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,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,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 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(()=>{var _a2,_b2;const selections=selectionManagerService.getCurrentSelections();if(selections&&selections[0]){const range=selections[0].range,row=range.startRow,col=range.startColumn,numfmtValue=(_b2=workbook.getStyles().get((_a2=worksheet.getCell(row,col))==null?void 0:_a2.s))==null?void 0:_b2.n,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,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"),menuSchema={[ui.RibbonStartGroup.FORMULAS_INSERT]:{[SetCurrencyCommand.id]:{order:4,menuItemFactory:CurrencyMenuItem},[AddDecimalCommand.id]:{order:5,menuItemFactory:AddDecimalMenuItem},[SubtractDecimalCommand.id]:{order:6,menuItemFactory:SubtractDecimalMenuItem},[SetPercentCommand.id]:{order:7,menuItemFactory:PercentMenuItem},[OpenNumfmtPanelOperator.id]:{order:8,menuItemFactory:FactoryOtherMenuItem}}};var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key2,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$2");let NumfmtMenuController=(_f=class extends core.Disposable{constructor(_injector,_componentManager,_menuManagerService){super(),this._injector=_injector,this._componentManager=_componentManager,this._menuManagerService=_menuManagerService,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(menuSchema),this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY,MoreNumfmtType)),this.disposeWithMe(this._componentManager.register(OPTIONS_KEY,Options))}},__name(_f,"NumfmtMenuController"),_f);NumfmtMenuController=__decorateClass$2([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtMenuController),__decorateParam$2(0,core.Inject(core.Injector)),__decorateParam$2(1,core.Inject(ui.ComponentManager)),__decorateParam$2(2,ui.IMenuManagerService)],NumfmtMenuController);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");let NumfmtCurrencyController=(_g=class extends core.Disposable{constructor(_injector){super();__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable());this._injector=_injector}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}},__name(_g,"NumfmtCurrencyController"),_g);NumfmtCurrencyController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtCurrencyController),__decorateParam$1(0,core.Inject(core.Injector))],NumfmtCurrencyController);const PLUGIN_CONFIG_KEY="sheets-numfmt.config",defaultPluginConfig={};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key2,value)=>key2 in obj?__defProp2(obj,key2,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key2]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp2(target,key2,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam"),__publicField2=__name((obj,key2,value)=>__defNormalProp2(obj,typeof key2!="symbol"?key2+"":key2,value),"__publicField");exports2.UniverSheetsNumfmtPlugin=(_h=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{menu,...rest}=this._config;menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}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([MenuCurrencyService]),this._injector.add([NumfmtCurrencyController]),this._injector.add([NumfmtMenuController])}},__name(_h,"UniverSheetsNumfmtPlugin"),_h),__publicField2(exports2.UniverSheetsNumfmtPlugin,"pluginName",SHEET_NUMFMT_PLUGIN),__publicField2(exports2.UniverSheetsNumfmtPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),exports2.UniverSheetsNumfmtPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin,sheetsUi.UniverSheetsUIPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverSheetsNumfmtPlugin),exports2.AddDecimalCommand=AddDecimalCommand,exports2.CloseNumfmtPanelOperator=CloseNumfmtPanelOperator,exports2.MenuCurrencyService=MenuCurrencyService,exports2.OpenNumfmtPanelOperator=OpenNumfmtPanelOperator,exports2.SetCurrencyCommand=SetCurrencyCommand,exports2.SetNumfmtCommand=SetNumfmtCommand,exports2.SetPercentCommand=SetPercentCommand,exports2.SubtractDecimalCommand=SubtractDecimalCommand,exports2.countryCurrencyMap=countryCurrencyMap,exports2.getPatternPreview=getPatternPreview,exports2.getPatternType=getPatternType,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
9
+ */var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function q(c,a,g){var b,d={},e=null,h=null;g!==void 0&&(e=""+g),a.key!==void 0&&(e=""+a.key),a.ref!==void 0&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)d[b]===void 0&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__name(q,"q"),reactJsxRuntime_production_min.Fragment=l,reactJsxRuntime_production_min.jsx=q,reactJsxRuntime_production_min.jsxs=q,jsxRuntime.exports=reactJsxRuntime_production_min;var jsxRuntimeExports=jsxRuntime.exports;const UserHabitCurrencyContext=require$$0.createContext([]);var __defProp$6=Object.defineProperty,__getOwnPropDesc$6=Object.getOwnPropertyDescriptor,__decorateClass$6=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$6(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$6(target,key2,result),result},"__decorateClass$6"),__decorateParam$6=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$6");let UserHabitController=(_b=class{constructor(_localStorageService){this._localStorageService=_localStorageService}_getKey(habit){return`userHabitController_${habit}`}async addHabit(habit,initValue){const key2=this._getKey(habit);return this._localStorageService.getItem(key2).then(item=>{item||this._localStorageService.setItem(key2,initValue)})}markHabit(habit,value){const key2=this._getKey(habit);this._localStorageService.getItem(key2).then(list=>{if(list){const index=list.findIndex(item=>item===value);index>-1&&list.splice(index,1),list.unshift(value),this._localStorageService.setItem(key2,list)}})}async getHabit(habit,sortList){const key2=this._getKey(habit),result=await this._localStorageService.getItem(key2);if(sortList&&result){const priority=result.map((item,index,arr)=>{const length=arr.length;return{value:item,priority:length-index}});return sortList.sort((a,b)=>{var _a2,_b2;const ap=((_a2=priority.find(item=>item.value===a))==null?void 0:_a2.priority)||-1;return(((_b2=priority.find(item=>item.value===b))==null?void 0:_b2.priority)||-1)-ap})}return result||[]}deleteHabit(habit){this._localStorageService.removeItem(habit)}},__name(_b,"UserHabitController"),_b);UserHabitController=__decorateClass$6([__decorateParam$6(0,core.Inject(core.ILocalStorageService))],UserHabitController);const key$1="numfmtCurrency",useCurrencyOptions=__name(onOptionChange=>{const userHabitController=core.useDependency(UserHabitController),[options,optionsSet]=require$$0.useState(currencySymbols);return require$$0.useEffect(()=>{userHabitController.addHabit("numfmtCurrency",[]).then(()=>{userHabitController.getHabit(key$1,[...currencySymbols]).then(list=>{optionsSet(list),onOptionChange&&onOptionChange(list)})})},[]),{userHabitCurrency:options,mark:__name(v=>{userHabitController.markHabit(key$1,v)},"mark")}},"useCurrencyOptions"),useNextTick=__name(()=>{const effectList=require$$0.useRef([]),[value,dispatch]=require$$0.useState({});return require$$0.useEffect(()=>{effectList.current.forEach(fn=>{fn()}),effectList.current=[]},[value]),__name(fn=>{effectList.current.push(fn),dispatch({})},"nextTick")},"useNextTick"),getCurrencyType=__name(pattern=>currencySymbols.find(code=>pattern.includes(code)),"getCurrencyType"),isAccountingPanel=__name(pattern=>!!getCurrencyType(pattern)&&pattern.startsWith("_("),"isAccountingPanel"),AccountingPanel=__name(props=>{const[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",2)),userHabitCurrency=require$$0.useContext(UserHabitCurrencyContext),[suffix,suffixSet]=require$$0.useState(()=>getCurrencyType(props.defaultPattern)||userHabitCurrency[0]),options=require$$0.useMemo(()=>userHabitCurrency.map(key2=>({label:key2,value:key2})),[]),t=core.useDependency(core.LocaleService).t;props.action.current=()=>setPatternDecimal(`_("${suffix}"* #,##0${decimal>0?".0":""}_)`,decimal);const onSelect=__name(v=>{suffixSet(v),props.onChange(setPatternDecimal(`_("${v}"* #,##0${decimal>0?".0":""}_)`,decimal))},"onSelect"),onDecimalChange=__name(v=>{const decimal2=v||0;decimalSet(decimal2),props.onChange(setPatternDecimal(`_("${suffix}"* #,##0${decimal2>0?".0":""}_)`,decimal2))},"onDecimalChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsxs("div",{className:"m-t-16 options ",children:[jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-120",children:jsxRuntimeExports.jsx(design.InputNumber,{value:decimal,max:20,min:0,onChange:onDecimalChange})})]}),jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.currencyType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-140",children:jsxRuntimeExports.jsx(design.Select,{onChange:onSelect,options,value:suffix})})]})]}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.accountingDes")})]})},"AccountingPanel"),getCurrencyFormatOptions=__name(suffix=>CURRENCYFORMAT.map(item=>({label:item.label(suffix),value:item.suffix(suffix),color:item.color})),"getCurrencyFormatOptions"),getDateFormatOptions=__name(()=>DATEFMTLISG.map(item=>({label:item.label,value:item.suffix})),"getDateFormatOptions"),getNumberFormatOptions=__name(()=>NUMBERFORMAT.map(item=>({label:item.label,value:item.suffix,color:item.color})),"getNumberFormatOptions"),isCurrencyPanel=__name(pattern=>!!getCurrencyType(pattern)&&!pattern.startsWith("_("),"isCurrencyPanel"),CurrencyPanel=__name(props=>{const t=core.useDependency(core.LocaleService).t,userHabitCurrency=require$$0.useContext(UserHabitCurrencyContext),[suffix,suffixSet]=require$$0.useState(()=>getCurrencyType(props.defaultPattern)||userHabitCurrency[0]),[decimal,decimalSet]=require$$0.useState(()=>getDecimalFromPattern(props.defaultPattern||"",2)),[pattern,patternSet]=require$$0.useState(()=>{var _a2;const negativeOptions2=getCurrencyFormatOptions(suffix);return((_a2=negativeOptions2.find(item=>isPatternEqualWithoutDecimal(item.value,props.defaultPattern)))==null?void 0:_a2.value)||negativeOptions2[0].value}),negativeOptions=require$$0.useMemo(()=>getCurrencyFormatOptions(suffix),[suffix]),options=require$$0.useMemo(()=>userHabitCurrency.map(key2=>({label:key2,value:key2})),[userHabitCurrency]);props.action.current=()=>setPatternDecimal(pattern,decimal);const onSelect=__name(value=>{if(value===void 0)return;suffixSet(value);const pattern2=getCurrencyFormatOptions(value)[0].value;patternSet(pattern2),props.onChange(setPatternDecimal(pattern2,decimal))},"onSelect"),onChange=__name(value=>{value!==void 0&&(patternSet(value),props.onChange(setPatternDecimal(value,decimal)))},"onChange"),onDecimalChange=__name(v=>{decimalSet(v||0),props.onChange(setPatternDecimal(pattern,v||0))},"onDecimalChange");return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsxs("div",{className:"m-t-16 options ",children:[jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.decimalLength")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-120",children:jsxRuntimeExports.jsx(design.InputNumber,{value:decimal,max:20,min:0,onChange:onDecimalChange})})]}),jsxRuntimeExports.jsxs("div",{className:"option",children:[jsxRuntimeExports.jsx("div",{className:"label",children:t("sheet.numfmt.currencyType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8 w-140",children:jsxRuntimeExports.jsx(design.Select,{onChange:onSelect,options,value:suffix})})]})]}),jsxRuntimeExports.jsx("div",{className:"m-t-16 label",children:t("sheet.numfmt.negType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.SelectList,{onChange,options:negativeOptions,value:pattern})}),jsxRuntimeExports.jsx("div",{className:"describe m-t-14",children:t("sheet.numfmt.currencyDes")})]})},"CurrencyPanel");var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n2=arguments.length;i<n2;i++){s=arguments[i];for(var p2 in s)Object.prototype.hasOwnProperty.call(s,p2)&&(t[p2]=s[p2])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p2 in s)Object.prototype.hasOwnProperty.call(s,p2)&&e.indexOf(p2)<0&&(t[p2]=s[p2]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p2=Object.getOwnPropertySymbols(s);i<p2.length;i++)e.indexOf(p2[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p2[i])&&(t[p2[i]]=s[p2[i]]);return t},IconBase=require$$0.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=require$$0.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return require$$0.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a2){var key2=_a2[0],value=_a2[1];typeof value=="string"&&(attrs[key2]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a2,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a2=node.children)===null||_a2===void 0)&&_a2.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid"),IconBase.displayName="UniverIcon";var element={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},CheckMarkSingle=require$$0.forwardRef(function(props,ref){return require$$0.createElement(IconBase,Object.assign({},props,{id:"check-mark-single",ref,icon:element}))});CheckMarkSingle.displayName="CheckMarkSingle";const styles={customFormatTitle:"univer-custom-format-title",customFormatInput:"univer-custom-format-input",customFormatHistoryList:"univer-custom-format-history-list",customFormatHistoryListItem:"univer-custom-format-history-list-item",customFormatHistoryListItemIconWrap:"univer-custom-format-history-list-item-icon-wrap",customFormatDes:"univer-custom-format-des"},key="customFormat",historyPatternKey="numfmt_custom_pattern";function CustomFormat(props){const{defaultPattern,action,onChange}=props,userHabitController=core.useDependency(UserHabitController),localStorageService=core.useDependency(core.ILocalStorageService),localeService=core.useDependency(core.LocaleService),[pattern,patternSet]=require$$0.useState(defaultPattern);action.current=()=>(userHabitController.markHabit(key,pattern),localStorageService.getItem(historyPatternKey).then((list=[])=>{const _list=[...new Set([pattern,...list||[]])].splice(0,10).filter(e=>!!e);localStorageService.setItem(historyPatternKey,_list)}),pattern);const[options,optionsSet]=require$$0.useState([]);require$$0.useEffect(()=>{localStorageService.getItem(historyPatternKey).then(historyList=>{const list=[...CURRENCYFORMAT.map(item=>item.suffix("$")),...DATEFMTLISG.map(item=>item.suffix),...NUMBERFORMAT.map(item=>item.suffix)];list.push(...historyList||[]),userHabitController.addHabit(key,[]).finally(()=>{userHabitController.getHabit(key,list).then(list2=>{optionsSet([...new Set(list2)])})})})},[]);const handleClick=__name(p2=>{patternSet(p2),onChange(p2)},"handleClick"),handleBlur=__name(()=>{onChange(pattern)},"handleBlur");return jsxRuntimeExports.jsxs("div",{className:styles.customFormat,children:[jsxRuntimeExports.jsx("div",{className:styles.customFormatTitle,children:localeService.t("sheet.numfmt.customFormat")}),jsxRuntimeExports.jsx(design.Input,{placeholder:localeService.t("sheet.numfmt.customFormat"),onBlur:handleBlur,value:pattern,onChange:patternSet,className:styles.customFormatInput}),jsxRuntimeExports.jsx("div",{className:styles.customFormatHistoryList,children:options.map(p2=>jsxRuntimeExports.jsxs("div",{onClick:__name(()=>handleClick(p2),"onClick"),className:styles.customFormatHistoryListItem,children:[jsxRuntimeExports.jsx("div",{className:styles.customFormatHistoryListItemIconWrap,children:pattern===p2&&jsxRuntimeExports.jsx(CheckMarkSingle,{})}),jsxRuntimeExports.jsx("div",{children:p2})]},p2))}),jsxRuntimeExports.jsx("div",{className:styles.customFormatDes,children:localeService.t("sheet.numfmt.customFormatDes")})]})}__name(CustomFormat,"CustomFormat");const isDatePanel=__name(pattern=>{const info=core.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"),SheetNumfmtPanel=__name(props=>{const{defaultValue,defaultPattern,row,col}=props.value,localeService=core.useDependency(core.LocaleService),getCurrentPattern=require$$0.useRef(()=>""),t=localeService.t,nextTick=useNextTick(),typeOptions=require$$0.useMemo(()=>[{label:"sheet.numfmt.general",component:GeneralPanel},{label:"sheet.numfmt.accounting",component:AccountingPanel},{label:"sheet.numfmt.currency",component:CurrencyPanel},{label:"sheet.numfmt.date",component:DatePanel},{label:"sheet.numfmt.thousandthPercentile",component:ThousandthPercentilePanel},{label:"sheet.numfmt.customFormat",component:CustomFormat}].map(item=>({...item,label:t(item.label)})),[]),[type,typeSet]=require$$0.useState(findDefaultType),[key2,keySet]=require$$0.useState(()=>`${row}_${col}`),{mark,userHabitCurrency}=useCurrencyOptions(()=>keySet(`${row}_${col}_userCurrency'`)),BusinessComponent=require$$0.useMemo(()=>{var _a2;return(_a2=typeOptions.find(item=>item.label===type))==null?void 0:_a2.component},[type]);function findDefaultType(){return[isGeneralPanel,isAccountingPanel,isCurrencyPanel,isDatePanel,isThousandthPercentilePanel].reduce((pre,curFn,index)=>pre||(curFn(defaultPattern)?typeOptions[index].label:""),"")||typeOptions[0].label}__name(findDefaultType,"findDefaultType");const selectOptions=typeOptions.map(option=>({label:option.label,value:option.label})),handleSelect=__name(value=>{typeSet(value),nextTick(()=>props.onChange({type:"change",value:getCurrentPattern.current()||""}))},"handleSelect"),handleChange=__name(v=>{props.onChange({type:"change",value:v})},"handleChange"),handleConfirm=__name(()=>{const pattern=getCurrentPattern.current()||"",currency=getCurrencyType(pattern);currency&&mark(currency),props.onChange({type:"confirm",value:pattern})},"handleConfirm"),handleCancel=__name(()=>{props.onChange({type:"cancel",value:""})},"handleCancel"),subProps={onChange:handleChange,defaultValue,defaultPattern,action:getCurrentPattern};return require$$0.useEffect(()=>{typeSet(findDefaultType()),keySet(`${row}_${col}`)},[row,col]),jsxRuntimeExports.jsxs("div",{className:"numfmt-panel p-b-20",children:[jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"label m-t-14",children:t("sheet.numfmt.numfmtType")}),jsxRuntimeExports.jsx("div",{className:"m-t-8",children:jsxRuntimeExports.jsx(design.Select,{onChange:handleSelect,options:selectOptions,value:type,style:{width:"100%"}})}),jsxRuntimeExports.jsx("div",{children:BusinessComponent&&jsxRuntimeExports.jsx(UserHabitCurrencyContext.Provider,{value:userHabitCurrency,children:require$$0.createElement(BusinessComponent,{...subProps,key:key2})})})]}),jsxRuntimeExports.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[jsxRuntimeExports.jsx(design.Button,{size:"small",onClick:handleCancel,className:"m-r-12",children:t("sheet.numfmt.cancel")}),jsxRuntimeExports.jsx(design.Button,{type:"primary",size:"small",onClick:handleConfirm,children:t("sheet.numfmt.confirm")})]})]})},"SheetNumfmtPanel");var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key2,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$5");let NumfmtController=(_c=class extends core.Disposable{constructor(_sheetInterceptorService,_themeService,_univerInstanceService,_commandService,_selectionManagerService,_renderManagerService,_numfmtService,_componentManager,_sidebarService,_localeService){super();__publicField(this,"_previewPattern","");__publicField(this,"_sidebarDisposable",null);this._sheetInterceptorService=_sheetInterceptorService,this._themeService=_themeService,this._univerInstanceService=_univerInstanceService,this._commandService=_commandService,this._selectionManagerService=_selectionManagerService,this._renderManagerService=_renderManagerService,this._numfmtService=_numfmtService,this._componentManager=_componentManager,this._sidebarService=_sidebarService,this._localeService=_localeService,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var _a2;const sidebarService=this._sidebarService,selectionManagerService=this._selectionManagerService,commandService=this._commandService,univerInstanceService=this._univerInstanceService,numfmtService=this._numfmtService,localeService=this._localeService,range=(((_a2=selectionManagerService.getCurrentSelections())==null?void 0:_a2.map(s=>s.range))||[])[0];if(!range)return!1;const workbook=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),sheet=workbook.getActiveSheet();if(!sheet)return!1;const cellValue=sheet.getCellRaw(range.startRow,range.startColumn),numfmtValue=numfmtService.getValue(workbook.getUnitId(),sheet.getSheetId(),range.startRow,range.startColumn);let pattern="";numfmtValue&&(pattern=numfmtValue.pattern);const defaultValue=(cellValue==null?void 0:cellValue.t)===core.CellValueType.NUMBER?cellValue.v:12345678,props={onChange:__name(config=>{var _a3;if(config.type==="change")this._previewPattern=config.value,this._forceUpdate();else if(config.type==="confirm"){const selections2=((_a3=selectionManagerService.getCurrentSelections())==null?void 0:_a3.map(s=>s.range))||[],params={values:[]},patternType=getPatternType(config.value);selections2.forEach(rangeInfo=>{core.Range.foreach(rangeInfo,(row,col)=>{params.values.push({row,col,pattern:config.value,type:patternType})})}),commandService.executeCommand(SetNumfmtCommand.id,params),sidebarService.close()}else config.type==="cancel"&&sidebarService.close()},"onChange"),value:{defaultPattern:pattern,defaultValue,row:range.startRow,col:range.startColumn}};return this._sidebarDisposable=sidebarService.open({header:{title:localeService.t("sheet.numfmt.title")},children:{label:SHEET_NUMFMT_PLUGIN,...props},onClose:__name(()=>{this._forceUpdate(),commandService.executeCommand(CloseNumfmtPanelOperator.id)},"onClose")}),!0}_forceUpdate(unitId){var _a2;const renderUnit=this._renderManagerService.getRenderById(unitId!=null?unitId:this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET).getUnitId());renderUnit==null||renderUnit.with(sheetsUi.SheetSkeletonManagerService).reCalculate(),(_a2=renderUnit==null?void 0:renderUnit.mainComponent)==null||_a2.makeDirty()}_initCommands(){[AddDecimalCommand,SubtractDecimalCommand,SetCurrencyCommand,SetPercentCommand,OpenNumfmtPanelOperator,CloseNumfmtPanelOperator,SetNumfmtCommand].forEach(config=>{this.disposeWithMe(this._commandService.registerCommand(config))})}_initPanel(){this._componentManager.register(SHEET_NUMFMT_PLUGIN,SheetNumfmtPanel)}_initRealTimeRenderingInterceptor(){const isPanelOpenObserver=new rxjs.Observable(subscriber=>{this._commandService.onCommandExecuted(commandInfo=>{commandInfo.id===OpenNumfmtPanelOperator.id&&subscriber.next(!0),commandInfo.id===CloseNumfmtPanelOperator.id&&subscriber.next(!1)})}),combineOpenAndSelection$=rxjs.combineLatest([isPanelOpenObserver,this._selectionManagerService.selectionMoveEnd$.pipe(operators.map(selectionInfos=>selectionInfos?selectionInfos.map(selectionInfo=>selectionInfo.range):[]))]);this.disposeWithMe(core.toDisposable(combineOpenAndSelection$.pipe(operators.switchMap(([isOpen,selectionRanges])=>new rxjs.Observable(subscribe=>{const disposableCollection=new core.DisposableCollection;return isOpen&&selectionRanges.length&&subscribe.next({selectionRanges,disposableCollection}),()=>{disposableCollection.dispose()}})),operators.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection,selectionRanges})=>{var _a2,_b2;const workbook=this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET);this.openPanel(),disposableCollection.add(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:core.InterceptorEffectEnum.Value|core.InterceptorEffectEnum.Style,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=getPatternPreviewIgnoreGeneral(this._previewPattern,value,this._localeService.getCurrentLocale());if(info.color){const color=this._themeService.getCurrentTheme()[`${info.color}500`];return{...defaultValue,v:info.result,t:core.CellValueType.STRING,s:{cl:{rgb:color}}}}return{...defaultValue,v:info.result,t:core.CellValueType.STRING}}return defaultValue},"handler")})),(_b2=(_a2=this._renderManagerService.getRenderById(workbook.getUnitId()))==null?void 0:_a2.mainComponent)==null||_b2.makeDirty()})))}_commandExecutedListener(){const commandList=[sheets.RemoveNumfmtMutation.id,sheets.SetNumfmtMutation.id];this.disposeWithMe(new rxjs.Observable(subscribe=>{const disposable=this._commandService.onCommandExecuted(command=>{if(commandList.includes(command.id)){const params=command.params;subscribe.next(params.unitId)}});return()=>disposable.dispose()}).pipe(operators.debounceTime(16)).subscribe(unitId=>this._forceUpdate(unitId)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).subscribe(unit=>{var _a2;unit||((_a2=this._sidebarDisposable)==null||_a2.dispose(),this._sidebarDisposable=null)})}},__name(_c,"NumfmtController"),_c);NumfmtController=__decorateClass$5([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtController),__decorateParam$5(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$5(1,core.Inject(core.ThemeService)),__decorateParam$5(2,core.IUniverInstanceService),__decorateParam$5(3,core.ICommandService),__decorateParam$5(4,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$5(5,engineRender.IRenderManagerService),__decorateParam$5(6,sheets.INumfmtService),__decorateParam$5(7,core.Inject(ui.ComponentManager)),__decorateParam$5(8,ui.ISidebarService),__decorateParam$5(9,core.Inject(core.LocaleService))],NumfmtController);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");const createCollectEffectMutation=__name(()=>{let list=[];return{add:__name((unitId,subUnitId,row,col,value)=>list.push({unitId,subUnitId,row,col,value}),"add"),getEffects:__name(()=>list,"getEffects"),clean:__name(()=>{list=[]},"clean")}},"createCollectEffectMutation");let NumfmtEditorController=(_d=class extends core.Disposable{constructor(_sheetInterceptorService,_numfmtService,_univerInstanceService,_injector,_editorBridgeService){super();__publicField(this,"_collectEffectMutation",createCollectEffectMutation());this._sheetInterceptorService=_sheetInterceptorService,this._numfmtService=_numfmtService,this._univerInstanceService=_univerInstanceService,this._injector=_injector,this._editorBridgeService=_editorBridgeService,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(core.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{handler:__name((value,context,next)=>{const row=context.row,col=context.col,numfmtCell=this._numfmtService.getValue(context.unitId,context.subUnitId,row,col);if(numfmtCell)switch(getPatternType(numfmtCell.pattern)){case"scientific":case"currency":case"grouped":case"number":return context.worksheet.getCellRaw(row,col);case"percent":case"date":case"time":case"datetime":default:return next&&next(value)}return next(value)},"handler")})))}_initInterceptorEditorEnd(){this._editorBridgeService&&this.disposeWithMe(core.toDisposable(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{handler:__name((value,context,next)=>{var _a2;this._collectEffectMutation.clean();const currentNumfmtValue=this._numfmtService.getValue(context.unitId,context.subUnitId,context.row,context.col),currentNumfmtType=(_a2=currentNumfmtValue&&getPatternType(currentNumfmtValue.pattern))!=null?_a2:"",clean=__name(()=>{currentNumfmtValue&&this._collectEffectMutation.add(context.unitId,context.subUnitId,context.row,context.col,null)},"clean");if(!(value!=null&&value.v))return next(value);const content=String(value.v),numfmtInfo=core.numfmt.parseDate(content)||core.numfmt.parseTime(content)||core.numfmt.parseNumber(content);if(numfmtInfo){if(numfmtInfo.z){const v=Number(numfmtInfo.v);return this._collectEffectMutation.add(context.unitId,context.subUnitId,context.row,context.col,{pattern:numfmtInfo.z}),{...value,v,t:core.CellValueType.NUMBER}}}else(["date","time","datetime","percent"].includes(currentNumfmtType)||!isNumeric(content))&&clean();return next(value)},"handler")})))}_initInterceptorCommands(){const self2=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(command){var _a2;switch(command.id){case sheets.SetRangeValuesCommand.id:{const workbook=self2._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),unitId=workbook.getUnitId(),subUnitId=(_a2=workbook.getActiveSheet())==null?void 0:_a2.getSheetId();if(!subUnitId)return{redos:[],undos:[]};const list=self2._collectEffectMutation.getEffects();if(self2._collectEffectMutation.clean(),!list.length)return{redos:[],undos:[]};const cells=list.filter(item=>{var _a3;return!!((_a3=item.value)!=null&&_a3.pattern)}).map(item=>({row:item.row,col:item.col,pattern:item.value.pattern})),removeCells=list.filter(item=>{var _a3;return!((_a3=item.value)!=null&&_a3.pattern)}).map(item=>({startRow:item.row,endColumn:item.col,startColumn:item.col,endRow:item.row})),redos=[],undos=[];if(cells.length){const redo={id:sheets.SetNumfmtMutation.id,params:sheets.transformCellsToRange(unitId,subUnitId,cells)};redos.push(redo),undos.push(...sheets.factorySetNumfmtUndoMutation(self2._injector,redo.params))}if(removeCells.length){const redo={id:sheets.RemoveNumfmtMutation.id,params:{unitId,subUnitId,ranges:removeCells}};redos.push(redo),undos.push(...sheets.factoryRemoveNumfmtUndoMutation(self2._injector,redo.params))}return{redos,undos:undos.reverse()}}}return{redos:[],undos:[]}}}))}},__name(_d,"NumfmtEditorController"),_d);NumfmtEditorController=__decorateClass$4([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtEditorController),__decorateParam$4(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$4(1,core.Inject(sheets.INumfmtService)),__decorateParam$4(2,core.Inject(core.IUniverInstanceService)),__decorateParam$4(3,core.Inject(core.Injector)),__decorateParam$4(4,core.Optional(sheetsUi.IEditorBridgeService))],NumfmtEditorController);function isNumeric(str){return/^-?\d+(\.\d+)?$/.test(str)}__name(isNumeric,"isNumeric");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");let NumfmtI18nController=(_e=class extends core.Disposable{constructor(_localeService){super(),this._localeService=_localeService}},__name(_e,"NumfmtI18nController"),_e);NumfmtI18nController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtI18nController),__decorateParam$3(0,core.Inject(core.LocaleService))],NumfmtI18nController);const MENU_OPTIONS=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:engineNumfmt.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],MORE_NUMFMT_TYPE_KEY="sheet.numfmt.moreNumfmtType",OPTIONS_KEY="sheet.numfmt.moreNumfmtType.options",MoreNumfmtType=__name(props=>{var _a2;const localeService=core.useDependency(core.LocaleService),value=(_a2=props.value)!=null?_a2:localeService.t("sheet.numfmt.general");return jsxRuntimeExports.jsx("span",{className:"more-numfmt-type",children:value})},"MoreNumfmtType"),Options=__name(()=>{const commandService=core.useDependency(core.ICommandService),localeService=core.useDependency(core.LocaleService),layoutService=core.useDependency(ui.ILayoutService);core.useInjector();const selectionManagerService=core.useDependency(sheets.SheetsSelectionsService),setNumfmt=__name(pattern=>{const selection=selectionManagerService.getCurrentLastSelection();if(!selection)return;const 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}),layoutService.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:new rxjs.Observable(subscribe=>{const menuCurrencyService=accessor.get(MenuCurrencyService);function getIconKey(symbol2){return{[countryCurrencyMap.US]:"DollarSingle",[countryCurrencyMap.RU]:"RoubleSingle",[countryCurrencyMap.CN]:"RmbSingle",[countryCurrencyMap.AT]:"EuroSingle"}[symbol2]||"DollarSingle"}__name(getIconKey,"getIconKey");const symbol=countryCurrencyMap[menuCurrencyService.getCurrencySymbol()]||"$";return subscribe.next(getIconKey(symbol)),menuCurrencyService.currencySymbol$.subscribe(code=>{const symbol2=countryCurrencyMap[code]||"$";subscribe.next(getIconKey(symbol2))})}),id:SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:ui.MenuItemType.BUTTON,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,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,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,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 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(()=>{var _a2,_b2;const selections=selectionManagerService.getCurrentSelections();if(selections&&selections[0]){const range=selections[0].range,row=range.startRow,col=range.startColumn,numfmtValue=(_b2=workbook.getStyles().get((_a2=worksheet.getCell(row,col))==null?void 0:_a2.s))==null?void 0:_b2.n,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,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"),menuSchema={[ui.RibbonStartGroup.FORMULAS_INSERT]:{[SetCurrencyCommand.id]:{order:4,menuItemFactory:CurrencyMenuItem},[AddDecimalCommand.id]:{order:5,menuItemFactory:AddDecimalMenuItem},[SubtractDecimalCommand.id]:{order:6,menuItemFactory:SubtractDecimalMenuItem},[SetPercentCommand.id]:{order:7,menuItemFactory:PercentMenuItem},[OpenNumfmtPanelOperator.id]:{order:8,menuItemFactory:FactoryOtherMenuItem}}};var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key2,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam$2");let NumfmtMenuController=(_f=class extends core.Disposable{constructor(_injector,_componentManager,_menuManagerService){super(),this._injector=_injector,this._componentManager=_componentManager,this._menuManagerService=_menuManagerService,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(menuSchema),this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY,MoreNumfmtType)),this.disposeWithMe(this._componentManager.register(OPTIONS_KEY,Options))}},__name(_f,"NumfmtMenuController"),_f);NumfmtMenuController=__decorateClass$2([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtMenuController),__decorateParam$2(0,core.Inject(core.Injector)),__decorateParam$2(1,core.Inject(ui.ComponentManager)),__decorateParam$2(2,ui.IMenuManagerService)],NumfmtMenuController);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");let NumfmtCurrencyController=(_g=class extends core.Disposable{constructor(_injector){super();__publicField(this,"_currencySymbol$",new rxjs.BehaviorSubject("US"));__publicField(this,"currencySymbol$",this._currencySymbol$.asObservable());this._injector=_injector}setCurrencySymbolByCountryCode(symbol){this._currencySymbol$.next(symbol)}getCurrencySymbol(){return this._currencySymbol$.getValue()}},__name(_g,"NumfmtCurrencyController"),_g);NumfmtCurrencyController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,NumfmtCurrencyController),__decorateParam$1(0,core.Inject(core.Injector))],NumfmtCurrencyController);const PLUGIN_CONFIG_KEY="sheets-numfmt.config",defaultPluginConfig={};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key2,value)=>key2 in obj?__defProp2(obj,key2,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key2]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key2,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key2):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key2,result):decorator(result))||result);return kind&&result&&__defProp2(target,key2,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key2)=>decorator(target,key2,index),"__decorateParam"),__publicField2=__name((obj,key2,value)=>__defNormalProp2(obj,typeof key2!="symbol"?key2+"":key2,value),"__publicField");exports2.UniverSheetsNumfmtPlugin=(_h=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{menu,...rest}=this._config;menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}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([MenuCurrencyService]),this._injector.add([NumfmtCurrencyController]),this._injector.add([NumfmtMenuController])}},__name(_h,"UniverSheetsNumfmtPlugin"),_h),__publicField2(exports2.UniverSheetsNumfmtPlugin,"pluginName",SHEET_NUMFMT_PLUGIN),__publicField2(exports2.UniverSheetsNumfmtPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),exports2.UniverSheetsNumfmtPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin,sheetsUi.UniverSheetsUIPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverSheetsNumfmtPlugin),exports2.AddDecimalCommand=AddDecimalCommand,exports2.CloseNumfmtPanelOperator=CloseNumfmtPanelOperator,exports2.MenuCurrencyService=MenuCurrencyService,exports2.OpenNumfmtPanelOperator=OpenNumfmtPanelOperator,exports2.SetCurrencyCommand=SetCurrencyCommand,exports2.SetNumfmtCommand=SetNumfmtCommand,exports2.SetPercentCommand=SetPercentCommand,exports2.SubtractDecimalCommand=SubtractDecimalCommand,exports2.countryCurrencyMap=countryCurrencyMap,exports2.getPatternPreview=getPatternPreview,exports2.getPatternType=getPatternType,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt",
3
- "version": "0.2.14",
3
+ "version": "0.3.0-alpha.0",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -20,9 +20,6 @@
20
20
  "keywords": [
21
21
  "univer"
22
22
  ],
23
- "sideEffects": [
24
- "**/*.css"
25
- ],
26
23
  "exports": {
27
24
  ".": {
28
25
  "import": "./lib/es/index.js",
@@ -52,34 +49,34 @@
52
49
  "peerDependencies": {
53
50
  "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
54
51
  "rxjs": ">=7.0.0",
55
- "@univerjs/core": "0.2.14",
56
- "@univerjs/design": "0.2.14",
57
- "@univerjs/engine-numfmt": "0.2.14",
58
- "@univerjs/engine-render": "0.2.14",
59
- "@univerjs/sheets": "0.2.14",
60
- "@univerjs/sheets-ui": "0.2.14",
61
- "@univerjs/ui": "0.2.14"
52
+ "@univerjs/core": "0.3.0-alpha.0",
53
+ "@univerjs/design": "0.3.0-alpha.0",
54
+ "@univerjs/engine-numfmt": "0.3.0-alpha.0",
55
+ "@univerjs/engine-render": "0.3.0-alpha.0",
56
+ "@univerjs/sheets": "0.3.0-alpha.0",
57
+ "@univerjs/sheets-ui": "0.3.0-alpha.0",
58
+ "@univerjs/ui": "0.3.0-alpha.0"
62
59
  },
63
60
  "dependencies": {
64
61
  "@univerjs/icons": "^0.1.78",
65
- "@univerjs/core": "0.2.14",
66
- "@univerjs/engine-formula": "0.2.14",
67
- "@univerjs/engine-numfmt": "0.2.14",
68
- "@univerjs/engine-render": "0.2.14",
69
- "@univerjs/design": "0.2.14",
70
- "@univerjs/sheets-ui": "0.2.14",
71
- "@univerjs/sheets": "0.2.14",
72
- "@univerjs/ui": "0.2.14"
62
+ "@univerjs/core": "0.3.0-alpha.0",
63
+ "@univerjs/design": "0.3.0-alpha.0",
64
+ "@univerjs/engine-formula": "0.3.0-alpha.0",
65
+ "@univerjs/engine-numfmt": "0.3.0-alpha.0",
66
+ "@univerjs/sheets": "0.3.0-alpha.0",
67
+ "@univerjs/sheets-ui": "0.3.0-alpha.0",
68
+ "@univerjs/engine-render": "0.3.0-alpha.0",
69
+ "@univerjs/ui": "0.3.0-alpha.0"
73
70
  },
74
71
  "devDependencies": {
75
- "@types/react": "^18.3.5",
72
+ "@types/react": "^18.3.9",
76
73
  "less": "^4.2.0",
77
74
  "react": "18.3.1",
78
75
  "rxjs": "^7.8.1",
79
76
  "typescript": "^5.6.2",
80
- "vite": "^5.4.4",
81
- "vitest": "^2.0.5",
82
- "@univerjs-infra/shared": "0.2.14"
77
+ "vite": "^5.4.8",
78
+ "vitest": "^2.1.1",
79
+ "@univerjs-infra/shared": "0.3.0-alpha.0"
83
80
  },
84
81
  "univerSpace": {
85
82
  ".": {