@univerjs/sheets-numfmt 0.2.14 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var __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"),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,throws:!1});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={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
package/lib/es/index.js CHANGED
@@ -410,7 +410,7 @@ const OpenNumfmtPanelOperator = {
410
410
  type: CommandType.OPERATION,
411
411
  handler: /* @__PURE__ */ __name((accessor) => (accessor.get(INumfmtController).openPanel(), !0), "handler")
412
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 });
413
+ 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 });
414
414
  return value < 0 ? {
415
415
  result,
416
416
  color: negInfo.color
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("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,throws:!1});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={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -52,24 +52,24 @@
52
52
  "peerDependencies": {
53
53
  "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
54
54
  "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"
55
+ "@univerjs/core": "0.2.15",
56
+ "@univerjs/design": "0.2.15",
57
+ "@univerjs/engine-numfmt": "0.2.15",
58
+ "@univerjs/engine-render": "0.2.15",
59
+ "@univerjs/sheets": "0.2.15",
60
+ "@univerjs/sheets-ui": "0.2.15",
61
+ "@univerjs/ui": "0.2.15"
62
62
  },
63
63
  "dependencies": {
64
64
  "@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"
65
+ "@univerjs/design": "0.2.15",
66
+ "@univerjs/core": "0.2.15",
67
+ "@univerjs/engine-formula": "0.2.15",
68
+ "@univerjs/engine-numfmt": "0.2.15",
69
+ "@univerjs/sheets": "0.2.15",
70
+ "@univerjs/sheets-ui": "0.2.15",
71
+ "@univerjs/ui": "0.2.15",
72
+ "@univerjs/engine-render": "0.2.15"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@types/react": "^18.3.5",
@@ -79,7 +79,7 @@
79
79
  "typescript": "^5.6.2",
80
80
  "vite": "^5.4.4",
81
81
  "vitest": "^2.0.5",
82
- "@univerjs-infra/shared": "0.2.14"
82
+ "@univerjs-infra/shared": "0.2.15"
83
83
  },
84
84
  "univerSpace": {
85
85
  ".": {