@univerjs/sheets-numfmt 0.5.5-experimental.20250122-3362a4a → 0.5.5-nightly.202501201336
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/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +14 -20
- package/lib/es/index.js +350 -354
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +5 -5
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";const s=require("@univerjs/sheets-numfmt"),e=require("@univerjs/sheets/facade");class c extends e.FRange{setNumberFormat(t){const o=[];return this.forEach((r,m)=>o.push({row:r,col:m,pattern:t})),this._commandService.syncExecuteCommand(s.SetNumfmtCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),values:o}),this}}e.FRange.extend(c);class u extends e.FWorkbook{setNumfmtLocal(t){return this._injector.get(s.SheetsNumfmtCellContentController).setNumfmtLocal(t),this}}e.FWorkbook.extend(u);
|
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"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);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),sheets=require("@univerjs/sheets"),rxjs=require("rxjs"),engineNumfmt=require("@univerjs/engine-numfmt"),engineFormula=require("@univerjs/engine-formula"),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:"€"},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"}],SHEET_NUMFMT_PLUGIN="SHEET_NUMFMT_PLUGIN",getDecimalFromPattern=__name((pattern,defaultValue=0)=>{var _a3;return pattern&&(_a3=core.numfmt.getInfo(pattern).maxDecimals)!=null?_a3: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(key=>{const v=setRedos.values[key];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")},_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")},getPatternType=__name(pattern=>core.numfmt.getInfo(pattern).type||"unknown","getPatternType"),getPatternPreview=__name((pattern,value,locale="en")=>{const negInfo=core.numfmt.getInfo(pattern)._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(engineFormula.stripErrorMargin(value))}:getPatternPreview(pattern,value,locale),"getPatternPreviewIgnoreGeneral");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a;exports.SheetsNumfmtCellContentController=(_a=class extends core.Disposable{constructor(_instanceService,_sheetInterceptorService,_themeService,_commandService,_numfmtService,_localeService){super();__publicField(this,"_local$",new rxjs.BehaviorSubject("en"));__publicField(this,"local$",this._local$.asObservable());this._instanceService=_instanceService,this._sheetInterceptorService=_sheetInterceptorService,this._themeService=_themeService,this._commandService=_commandService,this._numfmtService=_numfmtService,this._localeService=_localeService,this._initInterceptorCellContent()}get local(){const _local=this._local$.getValue();if(_local)return _local;switch(this._localeService.getCurrentLocale()){case core.LocaleType.FR_FR:return"fr";case core.LocaleType.RU_RU:return"ru";case core.LocaleType.VI_VN:return"vi";case core.LocaleType.ZH_CN:return"zh-CN";case core.LocaleType.ZH_TW:return"zh-TW";case core.LocaleType.EN_US:case core.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const TEXT_FORMAT_MARK={tl:{size:6,color:"#409f11"}},renderCache=new core.ObjectMatrix;this.disposeWithMe(rxjs.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{renderCache.reset()})),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)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);if(numfmtValue.pattern===engineNumfmt.DEFAULT_TEXT_FORMAT&&originCellValue.v&&core.isRealNum(originCellValue.v))return next({...cell,markers:{...cell==null?void 0:cell.markers,...TEXT_FORMAT_MARK}});if(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=getPatternPreviewIgnoreGeneral(numfmtValue.pattern,Number(originCellValue.v),this.local);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(key=>{params.values[key].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 _a3;return(_a3=workbook==null?void 0:workbook.activeSheet$)!=null?_a3:rxjs.of(null)}),rxjs.skip(1)).subscribe(()=>renderCache.reset()))}setNumfmtLocal(local){this._local$.next(local)}},__name(_a,"SheetsNumfmtCellContentController"),_a);exports.SheetsNumfmtCellContentController=__decorateClass$1([__decorateParam$1(0,core.IUniverInstanceService),__decorateParam$1(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$1(2,core.Inject(core.ThemeService)),__decorateParam$1(3,core.Inject(core.ICommandService)),__decorateParam$1(4,core.Inject(sheets.INumfmtService)),__decorateParam$1(5,core.Inject(core.LocaleService))],exports.SheetsNumfmtCellContentController);const _NumfmtCurrencyController=class _NumfmtCurrencyController extends core.Disposable{constructor(){super(...arguments);__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(_NumfmtCurrencyController,"NumfmtCurrencyController");let NumfmtCurrencyController=_NumfmtCurrencyController;var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField"),_a2;exports.UniverSheetsNumfmtPlugin=(_a2=class extends core.Plugin{constructor(_config=void 0,_injector,_commandService){super(),this._config=_config,this._injector=_injector,this._commandService=_commandService}onStarting(){core.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[MenuCurrencyService],[NumfmtCurrencyController]]),core.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){core.touchDependencies(this._injector,[[NumfmtCurrencyController]]),[AddDecimalCommand,SubtractDecimalCommand,SetCurrencyCommand,SetPercentCommand,SetNumfmtCommand].forEach(config=>{this.disposeWithMe(this._commandService.registerCommand(config))})}},__name(_a2,"UniverSheetsNumfmtPlugin"),_a2);__publicField2(exports.UniverSheetsNumfmtPlugin,"pluginName",SHEET_NUMFMT_PLUGIN);__publicField2(exports.UniverSheetsNumfmtPlugin,"type",core.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.ICommandService)],exports.UniverSheetsNumfmtPlugin);const getCurrencyType=__name(pattern=>currencySymbols.find(code=>pattern.includes(code)),"getCurrencyType"),getCurrencyOptions=__name(()=>currencySymbols.map(item=>({label:item,value:item})),"getCurrencyOptions"),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");exports.AddDecimalCommand=AddDecimalCommand;exports.CURRENCYFORMAT=CURRENCYFORMAT;exports.DATEFMTLISG=DATEFMTLISG;exports.MenuCurrencyService=MenuCurrencyService;exports.NUMBERFORMAT=NUMBERFORMAT;exports.SetCurrencyCommand=SetCurrencyCommand;exports.SetNumfmtCommand=SetNumfmtCommand;exports.SetPercentCommand=SetPercentCommand;exports.SubtractDecimalCommand=SubtractDecimalCommand;exports.countryCurrencyMap=countryCurrencyMap;exports.currencySymbols=currencySymbols;exports.getCurrencyFormatOptions=getCurrencyFormatOptions;exports.getCurrencyOptions=getCurrencyOptions;exports.getCurrencyType=getCurrencyType;exports.getDateFormatOptions=getDateFormatOptions;exports.getDecimalFromPattern=getDecimalFromPattern;exports.getDecimalString=getDecimalString;exports.getNumberFormatOptions=getNumberFormatOptions;exports.getPatternPreview=getPatternPreview;exports.getPatternPreviewIgnoreGeneral=getPatternPreviewIgnoreGeneral;exports.getPatternType=getPatternType;exports.isPatternEqualWithoutDecimal=isPatternEqualWithoutDecimal;exports.isPatternHasDecimal=isPatternHasDecimal;exports.setPatternDecimal=setPatternDecimal;
|
|
1
|
+
"use strict";var K=Object.defineProperty;var Y=(e,t,s)=>t in e?K(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var b=(e,t,s)=>Y(e,typeof t!="symbol"?t+"":t,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@univerjs/core"),m=require("@univerjs/sheets"),M=require("rxjs"),X=require("@univerjs/engine-numfmt"),Z=require("@univerjs/engine-formula"),P=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],A={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:"€"},F=[{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"}],w=[{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"}],U=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],J="SHEET_NUMFMT_PLUGIN",$=(e,t=0)=>{var o;return e&&(o=n.numfmt.getInfo(e).maxDecimals)!=null?o:t},Q=(e,t)=>{if(e&&!t||!e&&t)return!1;const s=i=>i.reduce((l,h)=>{if(l.isEnd)return l;const d=h.value||h.num;return h.type==="point"?(l.isEnd=!0,l):{...l,result:l.result+d}},{isEnd:!1,result:""}).result,o=n.numfmt.getInfo(e)._partitions,r=n.numfmt.getInfo(t)._partitions,c=s(o[0].tokens),a=s(r[0].tokens),f=s(o[1].tokens),g=s(r[1].tokens);return c===a&&f===g&&o[1].color===r[1].color},E=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),R=(e,t)=>e.split(";").map(o=>/\.0?/.test(o)?o.replace(/\.0*/g,`${t>0?".":""}${E(Number(t||0))}`):/0([^0]?)|0$/.test(o)?o.replace(/0([^0]+)|0$/,`0${t>0?".":""}${E(Number(t||0))}$1`):o).join(";"),k=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),N={id:"sheet.command.numfmt.set.numfmt",type:n.CommandType.COMMAND,handler:(e,t)=>{if(!t)return!1;const s=e.get(n.ICommandService),o=e.get(n.IUniverInstanceService),r=e.get(n.IUndoRedoService),c=m.getSheetCommandTarget(o,t);if(!c)return!1;const{unitId:a,subUnitId:f}=c,g=t.values.filter(u=>!!u.pattern),i=t.values.filter(u=>!u.pattern),l=m.transformCellsToRange(a,f,g),h={unitId:a,subUnitId:f,ranges:i.map(u=>({startColumn:u.col,startRow:u.row,endColumn:u.col,endRow:u.row}))},d=[],C=[];if(g.length){Object.keys(l.values).forEach(v=>{const p=l.values[v];p.ranges=m.rangeMerge(p.ranges)}),d.push({id:m.SetNumfmtMutation.id,params:l});const u=m.factorySetNumfmtUndoMutation(e,l);C.push(...u)}if(i.length){h.ranges=m.rangeMerge(h.ranges),d.push({id:m.RemoveNumfmtMutation.id,params:h});const u=m.factoryRemoveNumfmtUndoMutation(e,h);C.push(...u)}const S=n.sequenceExecute(d,s).result;return S&&r.pushUndoRedo({unitID:a,undoMutations:C,redoMutations:d}),S}},j={id:"sheet.command.numfmt.add.decimal.command",type:n.CommandType.COMMAND,handler:async e=>{const t=e.get(n.ICommandService),s=e.get(m.SheetsSelectionsService),o=e.get(m.INumfmtService),r=e.get(n.IUniverInstanceService),c=s.getCurrentSelections();if(!c||!c.length)return!1;const a=m.getSheetCommandTarget(r);if(!a)return!1;const{unitId:f,subUnitId:g}=a;let i=0;c.forEach(C=>{n.Range.foreach(C.range,(S,u)=>{const v=o.getValue(f,g,S,u);if(!v){const y=a.worksheet.getCellRaw(S,u);if(!i&&y&&y.t===n.CellValueType.NUMBER&&y.v){const _=/\.(\d*)$/.exec(String(y.v));if(_){const T=_[1].length;if(!T)return;i=Math.max(i,T)}}return}const p=$(v.pattern);i=p>i?p:i})});const l=i+1,h=R(`0${l>0?".0":""}`,l),d=[];return c.forEach(C=>{n.Range.foreach(C.range,(S,u)=>{const v=o.getValue(f,g,S,u);if(!v)d.push({row:S,col:u,pattern:h});else{const p=$(v.pattern),y=R(v.pattern,p+1);y!==v.pattern&&d.push({row:S,col:u,pattern:y})}})}),d.length?await t.executeCommand(N.id,{values:d}):!1}};class D{constructor(){b(this,"_currencySymbol$",new M.BehaviorSubject("US"));b(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(t){this._currencySymbol$.next(t)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const L={id:"sheet.command.numfmt.set.currency",type:n.CommandType.COMMAND,handler:async e=>{const t=e.get(n.ICommandService),s=e.get(m.SheetsSelectionsService),o=e.get(D),r=A[o.getCurrencySymbol()]||"$",c=s.getCurrentSelections();if(!c||!c.length)return!1;const a=[],f=U[4].suffix(r);return c.forEach(i=>{n.Range.foreach(i.range,(l,h)=>{a.push({row:l,col:h,pattern:f,type:"currency"})})}),await t.executeCommand(N.id,{values:a})}},B={id:"sheet.command.numfmt.set.percent",type:n.CommandType.COMMAND,handler:async e=>{const t=e.get(n.ICommandService),o=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!o||!o.length)return!1;const r=[],c="0%";return o.forEach(f=>{n.Range.foreach(f.range,(g,i)=>{r.push({row:g,col:i,pattern:c,type:"percent"})})}),await t.executeCommand(N.id,{values:r})}},G={id:"sheet.command.numfmt.subtract.decimal.command",type:n.CommandType.COMMAND,handler:async e=>{const t=e.get(n.ICommandService),s=e.get(m.SheetsSelectionsService),o=e.get(m.INumfmtService),r=e.get(n.IUniverInstanceService),c=s.getCurrentSelections();if(!c||!c.length)return!1;const a=m.getSheetCommandTarget(r);if(!a)return!1;const{unitId:f,subUnitId:g}=a;let i=0;c.forEach(S=>{n.Range.foreach(S.range,(u,v)=>{const p=o.getValue(f,g,u,v);if(!p){const _=a.worksheet.getCellRaw(u,v);if(!i&&_&&_.t===n.CellValueType.NUMBER&&_.v){const T=/\.(\d*)$/.exec(String(_.v));if(T){const O=T[1].length;if(!O)return;i=Math.max(i,O)}}return}const y=$(p.pattern);i=y>i?y:i})});const l=i-1,h=R(`0${l>0?".0":"."}`,l),d=[];return c.forEach(S=>{n.Range.foreach(S.range,(u,v)=>{const p=o.getValue(f,g,u,v);if(!p)d.push({row:u,col:v,pattern:h});else{const y=$(p.pattern);d.push({row:u,col:v,pattern:R(p.pattern,y-1)})}})}),await t.executeCommand(N.id,{values:d})}},ee=e=>n.numfmt.getInfo(e).type||"unknown",W=(e,t,s="en")=>{const r=n.numfmt.getInfo(e)._partitions[1],c=n.numfmt.format(e,t,{locale:s,throws:!1});return t<0?{result:c,color:r.color}:{result:c}},q=(e,t,s)=>e==="General"?{result:String(Z.stripErrorMargin(t))}:W(e,t,s);var te=Object.defineProperty,ne=Object.getOwnPropertyDescriptor,re=(e,t,s,o)=>{for(var r=o>1?void 0:o?ne(t,s):t,c=e.length-1,a;c>=0;c--)(a=e[c])&&(r=(o?a(t,s,r):a(r))||r);return o&&r&&te(t,s,r),r},I=(e,t)=>(s,o)=>t(s,o,e);exports.SheetsNumfmtCellContentController=class extends n.Disposable{constructor(s,o,r,c,a,f){super();b(this,"_local$",new M.BehaviorSubject("en"));b(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=o,this._themeService=r,this._commandService=c,this._numfmtService=a,this._localeService=f,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case n.LocaleType.FR_FR:return"fr";case n.LocaleType.RU_RU:return"ru";case n.LocaleType.VI_VN:return"vi";case n.LocaleType.ZH_CN:return"zh-CN";case n.LocaleType.ZH_TW:return"zh-TW";case n.LocaleType.EN_US:case n.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s={tl:{size:6,color:"#409f11"}},o=new n.ObjectMatrix;this.disposeWithMe(M.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{o.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{effect:n.InterceptorEffectEnum.Value|n.InterceptorEffectEnum.Style,handler:(r,c,a)=>{const f=c.unitId,g=c.subUnitId;let i;const l=r;if(!l)return a(r);if(r!=null&&r.s){const u=c.workbook.getStyles().get(r.s);u!=null&&u.n&&(i=u.n)}if(i||(i=this._numfmtService.getValue(f,g,c.row,c.col)),!i)return a(r);if(i.pattern===X.DEFAULT_TEXT_FORMAT&&l.v&&n.isRealNum(l.v))return a({...r,markers:{...r==null?void 0:r.markers,...s}});if(l.t!==n.CellValueType.NUMBER||l.v==null||Number.isNaN(l.v))return a(r);let h="";const d=o.getValue(c.row,c.col);if(d&&d.parameters===`${l.v}_${i.pattern}`)return a({...r,...d.result});const C=q(i.pattern,Number(l.v),this.local);if(h=C.result,!h)return a(r);const S={v:h};if(C.color){const u=this._themeService.getCurrentTheme()[`${C.color}500`];u&&(S.interceptorStyle={cl:{rgb:u}})}return o.setValue(c.row,c.col,{result:S,parameters:`${l.v}_${i.pattern}`}),a({...r,...S})},priority:m.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===m.SetNumfmtMutation.id){const c=r.params;Object.keys(c.values).forEach(a=>{c.values[a].ranges.forEach(g=>{n.Range.foreach(g,(i,l)=>{o.realDeleteValue(i,l)})})})}else if(r.id===m.SetRangeValuesMutation.id){const c=r.params;new n.ObjectMatrix(c.cellValue).forValue((a,f)=>{o.realDeleteValue(a,f)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(n.UniverInstanceType.UNIVER_SHEET).pipe(M.switchMap(r=>{var c;return(c=r==null?void 0:r.activeSheet$)!=null?c:M.of(null)}),M.skip(1)).subscribe(()=>o.reset()))}setNumfmtLocal(s){this._local$.next(s)}};exports.SheetsNumfmtCellContentController=re([I(0,n.IUniverInstanceService),I(1,n.Inject(m.SheetInterceptorService)),I(2,n.Inject(n.ThemeService)),I(3,n.Inject(n.ICommandService)),I(4,n.Inject(m.INumfmtService)),I(5,n.Inject(n.LocaleService))],exports.SheetsNumfmtCellContentController);class x extends n.Disposable{constructor(){super(...arguments);b(this,"_currencySymbol$",new M.BehaviorSubject("US"));b(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var H=Object.defineProperty,se=Object.getOwnPropertyDescriptor,oe=(e,t,s)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,ce=(e,t,s,o)=>{for(var r=o>1?void 0:o?se(t,s):t,c=e.length-1,a;c>=0;c--)(a=e[c])&&(r=(o?a(t,s,r):a(r))||r);return o&&r&&H(t,s,r),r},V=(e,t)=>(s,o)=>t(s,o,e),z=(e,t,s)=>oe(e,typeof t!="symbol"?t+"":t,s);exports.UniverSheetsNumfmtPlugin=class extends n.Plugin{constructor(t=void 0,s,o){super(),this._config=t,this._injector=s,this._commandService=o}onStarting(){n.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController],[D],[x]]),n.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){n.touchDependencies(this._injector,[[x]]),[j,G,L,B,N].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",J);z(exports.UniverSheetsNumfmtPlugin,"type",n.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=ce([n.DependentOn(m.UniverSheetsPlugin),V(1,n.Inject(n.Injector)),V(2,n.ICommandService)],exports.UniverSheetsNumfmtPlugin);const ae=e=>P.find(s=>e.includes(s)),ie=()=>P.map(e=>({label:e,value:e})),ue=e=>U.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),le=()=>F.map(e=>({label:e.label,value:e.suffix})),me=()=>w.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=j;exports.CURRENCYFORMAT=U;exports.DATEFMTLISG=F;exports.MenuCurrencyService=D;exports.NUMBERFORMAT=w;exports.SetCurrencyCommand=L;exports.SetNumfmtCommand=N;exports.SetPercentCommand=B;exports.SubtractDecimalCommand=G;exports.countryCurrencyMap=A;exports.currencySymbols=P;exports.getCurrencyFormatOptions=ue;exports.getCurrencyOptions=ie;exports.getCurrencyType=ae;exports.getDateFormatOptions=le;exports.getDecimalFromPattern=$;exports.getDecimalString=E;exports.getNumberFormatOptions=me;exports.getPatternPreview=W;exports.getPatternPreviewIgnoreGeneral=q;exports.getPatternType=ee;exports.isPatternEqualWithoutDecimal=Q;exports.isPatternHasDecimal=k;exports.setPatternDecimal=R;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const values = [];
|
|
8
|
-
return this.forEach((row, col) => values.push({ row, col, pattern })), this._commandService.syncExecuteCommand(SetNumfmtCommand.id, {
|
|
1
|
+
import { SetNumfmtCommand as l, SheetsNumfmtCellContentController as i } from "@univerjs/sheets-numfmt";
|
|
2
|
+
import { FRange as o, FWorkbook as s } from "@univerjs/sheets/facade";
|
|
3
|
+
class a extends o {
|
|
4
|
+
setNumberFormat(t) {
|
|
5
|
+
const e = [];
|
|
6
|
+
return this.forEach((m, r) => e.push({ row: m, col: r, pattern: t })), this._commandService.syncExecuteCommand(l.id, {
|
|
9
7
|
unitId: this._workbook.getUnitId(),
|
|
10
8
|
subUnitId: this._worksheet.getSheetId(),
|
|
11
|
-
values
|
|
9
|
+
values: e
|
|
12
10
|
}), this;
|
|
13
11
|
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
setNumfmtLocal(local) {
|
|
20
|
-
return this._injector.get(SheetsNumfmtCellContentController).setNumfmtLocal(local), this;
|
|
12
|
+
}
|
|
13
|
+
o.extend(a);
|
|
14
|
+
class c extends s {
|
|
15
|
+
setNumfmtLocal(t) {
|
|
16
|
+
return this._injector.get(i).setNumfmtLocal(t), this;
|
|
21
17
|
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let FWorkbookLegacy = _FWorkbookLegacy;
|
|
25
|
-
FWorkbook.extend(FWorkbookLegacy);
|
|
18
|
+
}
|
|
19
|
+
s.extend(c);
|
package/lib/es/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
const currencySymbols = [
|
|
1
|
+
var ne = Object.defineProperty;
|
|
2
|
+
var re = (e, t, r) => t in e ? ne(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var y = (e, t, r) => re(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { numfmt as N, CommandType as I, ICommandService as M, IUniverInstanceService as D, IUndoRedoService as se, sequenceExecute as oe, Range as C, CellValueType as A, Inject as E, ThemeService as ce, LocaleService as ae, Disposable as X, LocaleType as b, ObjectMatrix as B, InterceptorEffectEnum as W, isRealNum as ie, UniverInstanceType as Y, DependentOn as ue, Injector as le, Plugin as me, registerDependencies as fe, touchDependencies as G } from "@univerjs/core";
|
|
5
|
+
import { getSheetCommandTarget as w, transformCellsToRange as de, rangeMerge as H, SetNumfmtMutation as Z, factorySetNumfmtUndoMutation as he, RemoveNumfmtMutation as ge, factoryRemoveNumfmtUndoMutation as pe, SheetsSelectionsService as V, INumfmtService as F, SheetInterceptorService as ve, INTERCEPTOR_POINT as Se, InterceptCellContentPriority as _e, SetRangeValuesMutation as ye, UniverSheetsPlugin as be } from "@univerjs/sheets";
|
|
6
|
+
import { BehaviorSubject as j, merge as Ce, switchMap as Me, of as $e, skip as Ee } from "rxjs";
|
|
7
|
+
import { DEFAULT_TEXT_FORMAT as Ne } from "@univerjs/engine-numfmt";
|
|
8
|
+
import { stripErrorMargin as Re } from "@univerjs/engine-formula";
|
|
9
|
+
const J = [
|
|
11
10
|
"$",
|
|
12
11
|
"£",
|
|
13
12
|
"¥",
|
|
@@ -35,7 +34,7 @@ const currencySymbols = [
|
|
|
35
34
|
"₽",
|
|
36
35
|
"₾",
|
|
37
36
|
"₿"
|
|
38
|
-
],
|
|
37
|
+
], Ie = {
|
|
39
38
|
US: "$",
|
|
40
39
|
// United States Dollar
|
|
41
40
|
CA: "C$",
|
|
@@ -75,7 +74,7 @@ const currencySymbols = [
|
|
|
75
74
|
SI: "€",
|
|
76
75
|
ES: "€"
|
|
77
76
|
// Add more mappings as needed
|
|
78
|
-
},
|
|
77
|
+
}, Te = [
|
|
79
78
|
{
|
|
80
79
|
label: "1930-08-05",
|
|
81
80
|
suffix: "yyyy-MM-dd"
|
|
@@ -120,7 +119,7 @@ const currencySymbols = [
|
|
|
120
119
|
label: "08-05 下午 01:30",
|
|
121
120
|
suffix: "MM-dd A/P hh:mm"
|
|
122
121
|
}
|
|
123
|
-
],
|
|
122
|
+
], xe = [
|
|
124
123
|
{
|
|
125
124
|
label: "(1,235)",
|
|
126
125
|
suffix: "#,##0_);(#,##0)"
|
|
@@ -148,471 +147,468 @@ const currencySymbols = [
|
|
|
148
147
|
suffix: "#,##0.00_);[Red]-#,##0.00",
|
|
149
148
|
color: "red"
|
|
150
149
|
}
|
|
151
|
-
],
|
|
150
|
+
], Q = [
|
|
152
151
|
{
|
|
153
|
-
label:
|
|
154
|
-
suffix:
|
|
152
|
+
label: (e) => `${e}1,235`,
|
|
153
|
+
suffix: (e) => `"${e}"#,##0.00_);"${e}"#,##0.00`
|
|
155
154
|
},
|
|
156
155
|
{
|
|
157
|
-
label:
|
|
158
|
-
suffix:
|
|
156
|
+
label: (e) => `${e}1,235`,
|
|
157
|
+
suffix: (e) => `"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,
|
|
159
158
|
color: "red"
|
|
160
159
|
},
|
|
161
160
|
{
|
|
162
|
-
label:
|
|
163
|
-
suffix:
|
|
161
|
+
label: (e) => `(${e}1,235)`,
|
|
162
|
+
suffix: (e) => `"${e}"#,##0.00_);("${e}"#,##0.00)`
|
|
164
163
|
},
|
|
165
164
|
{
|
|
166
|
-
label:
|
|
167
|
-
suffix:
|
|
165
|
+
label: (e) => `(${e}1,235)`,
|
|
166
|
+
suffix: (e) => `"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,
|
|
168
167
|
color: "red"
|
|
169
168
|
},
|
|
170
169
|
{
|
|
171
|
-
label:
|
|
172
|
-
suffix:
|
|
170
|
+
label: (e) => `-${e}1,235`,
|
|
171
|
+
suffix: (e) => `"${e}"#,##0.00_);-"${e}"#,##0.00`
|
|
173
172
|
},
|
|
174
173
|
{
|
|
175
|
-
label:
|
|
176
|
-
suffix:
|
|
174
|
+
label: (e) => `-${e}1,235`,
|
|
175
|
+
suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,
|
|
177
176
|
color: "red"
|
|
178
177
|
}
|
|
179
|
-
],
|
|
180
|
-
var
|
|
181
|
-
return
|
|
182
|
-
},
|
|
183
|
-
if (
|
|
178
|
+
], Pe = "SHEET_NUMFMT_PLUGIN", x = (e, t = 0) => {
|
|
179
|
+
var n;
|
|
180
|
+
return e && (n = N.getInfo(e).maxDecimals) != null ? n : t;
|
|
181
|
+
}, Ze = (e, t) => {
|
|
182
|
+
if (e && !t || !e && t)
|
|
184
183
|
return !1;
|
|
185
|
-
const
|
|
186
|
-
(
|
|
187
|
-
if (
|
|
188
|
-
return
|
|
189
|
-
const
|
|
190
|
-
return
|
|
184
|
+
const r = (c) => c.reduce(
|
|
185
|
+
(l, h) => {
|
|
186
|
+
if (l.isEnd)
|
|
187
|
+
return l;
|
|
188
|
+
const f = h.value || h.num;
|
|
189
|
+
return h.type === "point" ? (l.isEnd = !0, l) : { ...l, result: l.result + f };
|
|
191
190
|
},
|
|
192
191
|
{ isEnd: !1, result: "" }
|
|
193
|
-
).result,
|
|
194
|
-
return
|
|
195
|
-
},
|
|
192
|
+
).result, n = N.getInfo(e)._partitions, s = N.getInfo(t)._partitions, o = r(n[0].tokens), a = r(s[0].tokens), d = r(n[1].tokens), u = r(s[1].tokens);
|
|
193
|
+
return o === a && d === u && n[1].color === s[1].color;
|
|
194
|
+
}, z = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), P = (e, t) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace(
|
|
196
195
|
/\.0*/g,
|
|
197
|
-
`${
|
|
198
|
-
) : /0([^0]?)|0$/.test(
|
|
196
|
+
`${t > 0 ? "." : ""}${z(Number(t || 0))}`
|
|
197
|
+
) : /0([^0]?)|0$/.test(n) ? n.replace(
|
|
199
198
|
/0([^0]+)|0$/,
|
|
200
|
-
`0${
|
|
201
|
-
) :
|
|
199
|
+
`0${t > 0 ? "." : ""}${z(Number(t || 0))}$1`
|
|
200
|
+
) : n).join(";"), Je = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), T = {
|
|
202
201
|
id: "sheet.command.numfmt.set.numfmt",
|
|
203
|
-
type:
|
|
204
|
-
handler:
|
|
205
|
-
if (!
|
|
202
|
+
type: I.COMMAND,
|
|
203
|
+
handler: (e, t) => {
|
|
204
|
+
if (!t)
|
|
206
205
|
return !1;
|
|
207
|
-
const
|
|
208
|
-
if (!
|
|
209
|
-
const { unitId, subUnitId } =
|
|
210
|
-
unitId,
|
|
211
|
-
subUnitId,
|
|
212
|
-
ranges:
|
|
213
|
-
startColumn:
|
|
214
|
-
startRow:
|
|
215
|
-
endColumn:
|
|
216
|
-
endRow:
|
|
206
|
+
const r = e.get(M), n = e.get(D), s = e.get(se), o = w(n, t);
|
|
207
|
+
if (!o) return !1;
|
|
208
|
+
const { unitId: a, subUnitId: d } = o, u = t.values.filter((i) => !!i.pattern), c = t.values.filter((i) => !i.pattern), l = de(a, d, u), h = {
|
|
209
|
+
unitId: a,
|
|
210
|
+
subUnitId: d,
|
|
211
|
+
ranges: c.map((i) => ({
|
|
212
|
+
startColumn: i.col,
|
|
213
|
+
startRow: i.row,
|
|
214
|
+
endColumn: i.col,
|
|
215
|
+
endRow: i.row
|
|
217
216
|
}))
|
|
218
|
-
},
|
|
219
|
-
if (
|
|
220
|
-
Object.keys(
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
}),
|
|
224
|
-
id:
|
|
225
|
-
params:
|
|
217
|
+
}, f = [], v = [];
|
|
218
|
+
if (u.length) {
|
|
219
|
+
Object.keys(l.values).forEach((g) => {
|
|
220
|
+
const p = l.values[g];
|
|
221
|
+
p.ranges = H(p.ranges);
|
|
222
|
+
}), f.push({
|
|
223
|
+
id: Z.id,
|
|
224
|
+
params: l
|
|
226
225
|
});
|
|
227
|
-
const
|
|
228
|
-
|
|
226
|
+
const i = he(e, l);
|
|
227
|
+
v.push(...i);
|
|
229
228
|
}
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
id:
|
|
233
|
-
params:
|
|
229
|
+
if (c.length) {
|
|
230
|
+
h.ranges = H(h.ranges), f.push({
|
|
231
|
+
id: ge.id,
|
|
232
|
+
params: h
|
|
234
233
|
});
|
|
235
|
-
const
|
|
236
|
-
|
|
234
|
+
const i = pe(e, h);
|
|
235
|
+
v.push(...i);
|
|
237
236
|
}
|
|
238
|
-
const
|
|
239
|
-
return
|
|
240
|
-
unitID:
|
|
241
|
-
undoMutations:
|
|
242
|
-
redoMutations:
|
|
243
|
-
}),
|
|
244
|
-
}
|
|
245
|
-
},
|
|
237
|
+
const m = oe(f, r).result;
|
|
238
|
+
return m && s.pushUndoRedo({
|
|
239
|
+
unitID: a,
|
|
240
|
+
undoMutations: v,
|
|
241
|
+
redoMutations: f
|
|
242
|
+
}), m;
|
|
243
|
+
}
|
|
244
|
+
}, Ue = {
|
|
246
245
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
247
|
-
type:
|
|
248
|
-
handler:
|
|
249
|
-
const
|
|
250
|
-
if (!
|
|
246
|
+
type: I.COMMAND,
|
|
247
|
+
handler: async (e) => {
|
|
248
|
+
const t = e.get(M), r = e.get(V), n = e.get(F), s = e.get(D), o = r.getCurrentSelections();
|
|
249
|
+
if (!o || !o.length)
|
|
251
250
|
return !1;
|
|
252
|
-
const
|
|
253
|
-
if (!
|
|
254
|
-
const { unitId, subUnitId } =
|
|
255
|
-
let
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
if (!
|
|
260
|
-
const
|
|
261
|
-
if (!
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
264
|
-
const
|
|
265
|
-
if (!
|
|
251
|
+
const a = w(s);
|
|
252
|
+
if (!a) return !1;
|
|
253
|
+
const { unitId: d, subUnitId: u } = a;
|
|
254
|
+
let c = 0;
|
|
255
|
+
o.forEach((v) => {
|
|
256
|
+
C.foreach(v.range, (m, i) => {
|
|
257
|
+
const g = n.getValue(d, u, m, i);
|
|
258
|
+
if (!g) {
|
|
259
|
+
const S = a.worksheet.getCellRaw(m, i);
|
|
260
|
+
if (!c && S && S.t === A.NUMBER && S.v) {
|
|
261
|
+
const _ = /\.(\d*)$/.exec(String(S.v));
|
|
262
|
+
if (_) {
|
|
263
|
+
const R = _[1].length;
|
|
264
|
+
if (!R)
|
|
266
265
|
return;
|
|
267
|
-
|
|
266
|
+
c = Math.max(c, R);
|
|
268
267
|
}
|
|
269
268
|
}
|
|
270
269
|
return;
|
|
271
270
|
}
|
|
272
|
-
const
|
|
273
|
-
|
|
271
|
+
const p = x(g.pattern);
|
|
272
|
+
c = p > c ? p : c;
|
|
274
273
|
});
|
|
275
274
|
});
|
|
276
|
-
const
|
|
277
|
-
return
|
|
278
|
-
|
|
279
|
-
const
|
|
280
|
-
if (!
|
|
281
|
-
|
|
282
|
-
row,
|
|
283
|
-
col,
|
|
284
|
-
pattern:
|
|
275
|
+
const l = c + 1, h = P(`0${l > 0 ? ".0" : ""}`, l), f = [];
|
|
276
|
+
return o.forEach((v) => {
|
|
277
|
+
C.foreach(v.range, (m, i) => {
|
|
278
|
+
const g = n.getValue(d, u, m, i);
|
|
279
|
+
if (!g)
|
|
280
|
+
f.push({
|
|
281
|
+
row: m,
|
|
282
|
+
col: i,
|
|
283
|
+
pattern: h
|
|
285
284
|
});
|
|
286
285
|
else {
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
row,
|
|
290
|
-
col,
|
|
291
|
-
pattern
|
|
286
|
+
const p = x(g.pattern), S = P(g.pattern, p + 1);
|
|
287
|
+
S !== g.pattern && f.push({
|
|
288
|
+
row: m,
|
|
289
|
+
col: i,
|
|
290
|
+
pattern: S
|
|
292
291
|
});
|
|
293
292
|
}
|
|
294
293
|
});
|
|
295
|
-
}),
|
|
296
|
-
}
|
|
297
|
-
}
|
|
294
|
+
}), f.length ? await t.executeCommand(T.id, { values: f }) : !1;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
class k {
|
|
298
298
|
constructor() {
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
y(this, "_currencySymbol$", new j("US"));
|
|
300
|
+
y(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
301
301
|
}
|
|
302
302
|
/**
|
|
303
303
|
* Set the currency symbol by setting the country code.
|
|
304
304
|
*/
|
|
305
|
-
setCurrencySymbolByCountryCode(
|
|
306
|
-
this._currencySymbol$.next(
|
|
305
|
+
setCurrencySymbolByCountryCode(t) {
|
|
306
|
+
this._currencySymbol$.next(t);
|
|
307
307
|
}
|
|
308
308
|
getCurrencySymbol() {
|
|
309
309
|
return this._currencySymbol$.getValue();
|
|
310
310
|
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
let MenuCurrencyService = _MenuCurrencyService;
|
|
314
|
-
const SetCurrencyCommand = {
|
|
311
|
+
}
|
|
312
|
+
const Oe = {
|
|
315
313
|
id: "sheet.command.numfmt.set.currency",
|
|
316
|
-
type:
|
|
317
|
-
handler:
|
|
318
|
-
const
|
|
319
|
-
if (!
|
|
314
|
+
type: I.COMMAND,
|
|
315
|
+
handler: async (e) => {
|
|
316
|
+
const t = e.get(M), r = e.get(V), n = e.get(k), s = Ie[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections();
|
|
317
|
+
if (!o || !o.length)
|
|
320
318
|
return !1;
|
|
321
|
-
const
|
|
322
|
-
return
|
|
323
|
-
|
|
324
|
-
|
|
319
|
+
const a = [], d = Q[4].suffix(s);
|
|
320
|
+
return o.forEach((c) => {
|
|
321
|
+
C.foreach(c.range, (l, h) => {
|
|
322
|
+
a.push({ row: l, col: h, pattern: d, type: "currency" });
|
|
325
323
|
});
|
|
326
|
-
}), await
|
|
327
|
-
}
|
|
328
|
-
},
|
|
324
|
+
}), await t.executeCommand(T.id, { values: a });
|
|
325
|
+
}
|
|
326
|
+
}, De = {
|
|
329
327
|
id: "sheet.command.numfmt.set.percent",
|
|
330
|
-
type:
|
|
331
|
-
handler:
|
|
332
|
-
const
|
|
333
|
-
if (!
|
|
328
|
+
type: I.COMMAND,
|
|
329
|
+
handler: async (e) => {
|
|
330
|
+
const t = e.get(M), n = e.get(V).getCurrentSelections();
|
|
331
|
+
if (!n || !n.length)
|
|
334
332
|
return !1;
|
|
335
|
-
const
|
|
336
|
-
return
|
|
337
|
-
|
|
338
|
-
|
|
333
|
+
const s = [], o = "0%";
|
|
334
|
+
return n.forEach((d) => {
|
|
335
|
+
C.foreach(d.range, (u, c) => {
|
|
336
|
+
s.push({ row: u, col: c, pattern: o, type: "percent" });
|
|
339
337
|
});
|
|
340
|
-
}), await
|
|
341
|
-
}
|
|
342
|
-
},
|
|
338
|
+
}), await t.executeCommand(T.id, { values: s });
|
|
339
|
+
}
|
|
340
|
+
}, Ve = {
|
|
343
341
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
344
|
-
type:
|
|
345
|
-
handler:
|
|
346
|
-
const
|
|
347
|
-
if (!
|
|
342
|
+
type: I.COMMAND,
|
|
343
|
+
handler: async (e) => {
|
|
344
|
+
const t = e.get(M), r = e.get(V), n = e.get(F), s = e.get(D), o = r.getCurrentSelections();
|
|
345
|
+
if (!o || !o.length)
|
|
348
346
|
return !1;
|
|
349
|
-
const
|
|
350
|
-
if (!
|
|
351
|
-
const { unitId, subUnitId } =
|
|
352
|
-
let
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const
|
|
356
|
-
if (!
|
|
357
|
-
const
|
|
358
|
-
if (!
|
|
359
|
-
const
|
|
360
|
-
if (
|
|
361
|
-
const
|
|
362
|
-
if (!
|
|
347
|
+
const a = w(s);
|
|
348
|
+
if (!a) return !1;
|
|
349
|
+
const { unitId: d, subUnitId: u } = a;
|
|
350
|
+
let c = 0;
|
|
351
|
+
o.forEach((m) => {
|
|
352
|
+
C.foreach(m.range, (i, g) => {
|
|
353
|
+
const p = n.getValue(d, u, i, g);
|
|
354
|
+
if (!p) {
|
|
355
|
+
const _ = a.worksheet.getCellRaw(i, g);
|
|
356
|
+
if (!c && _ && _.t === A.NUMBER && _.v) {
|
|
357
|
+
const R = /\.(\d*)$/.exec(String(_.v));
|
|
358
|
+
if (R) {
|
|
359
|
+
const L = R[1].length;
|
|
360
|
+
if (!L)
|
|
363
361
|
return;
|
|
364
|
-
|
|
362
|
+
c = Math.max(c, L);
|
|
365
363
|
}
|
|
366
364
|
}
|
|
367
365
|
return;
|
|
368
366
|
}
|
|
369
|
-
const
|
|
370
|
-
|
|
367
|
+
const S = x(p.pattern);
|
|
368
|
+
c = S > c ? S : c;
|
|
371
369
|
});
|
|
372
370
|
});
|
|
373
|
-
const
|
|
374
|
-
return
|
|
375
|
-
|
|
376
|
-
const
|
|
377
|
-
if (!
|
|
378
|
-
|
|
379
|
-
row,
|
|
380
|
-
col,
|
|
381
|
-
pattern:
|
|
371
|
+
const l = c - 1, h = P(`0${l > 0 ? ".0" : "."}`, l), f = [];
|
|
372
|
+
return o.forEach((m) => {
|
|
373
|
+
C.foreach(m.range, (i, g) => {
|
|
374
|
+
const p = n.getValue(d, u, i, g);
|
|
375
|
+
if (!p)
|
|
376
|
+
f.push({
|
|
377
|
+
row: i,
|
|
378
|
+
col: g,
|
|
379
|
+
pattern: h
|
|
382
380
|
});
|
|
383
381
|
else {
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
row,
|
|
387
|
-
col,
|
|
388
|
-
pattern:
|
|
382
|
+
const S = x(p.pattern);
|
|
383
|
+
f.push({
|
|
384
|
+
row: i,
|
|
385
|
+
col: g,
|
|
386
|
+
pattern: P(p.pattern, S - 1)
|
|
389
387
|
});
|
|
390
388
|
}
|
|
391
389
|
});
|
|
392
|
-
}), await
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
const
|
|
396
|
-
return
|
|
397
|
-
result,
|
|
398
|
-
color:
|
|
390
|
+
}), await t.executeCommand(T.id, { values: f });
|
|
391
|
+
}
|
|
392
|
+
}, Qe = (e) => N.getInfo(e).type || "unknown", Ae = (e, t, r = "en") => {
|
|
393
|
+
const s = N.getInfo(e)._partitions[1], o = N.format(e, t, { locale: r, throws: !1 });
|
|
394
|
+
return t < 0 ? {
|
|
395
|
+
result: o,
|
|
396
|
+
color: s.color
|
|
399
397
|
} : {
|
|
400
|
-
result
|
|
398
|
+
result: o
|
|
401
399
|
};
|
|
402
|
-
},
|
|
403
|
-
result: String(
|
|
400
|
+
}, we = (e, t, r) => e === "General" ? {
|
|
401
|
+
result: String(Re(t))
|
|
404
402
|
// In Excel, the default General format also needs to handle numeric precision.
|
|
405
|
-
} :
|
|
406
|
-
var
|
|
407
|
-
for (var
|
|
408
|
-
(
|
|
409
|
-
return
|
|
410
|
-
},
|
|
411
|
-
let
|
|
412
|
-
constructor(
|
|
403
|
+
} : Ae(e, t, r);
|
|
404
|
+
var Fe = Object.defineProperty, je = Object.getOwnPropertyDescriptor, Le = (e, t, r, n) => {
|
|
405
|
+
for (var s = n > 1 ? void 0 : n ? je(t, r) : t, o = e.length - 1, a; o >= 0; o--)
|
|
406
|
+
(a = e[o]) && (s = (n ? a(t, r, s) : a(s)) || s);
|
|
407
|
+
return n && s && Fe(t, r, s), s;
|
|
408
|
+
}, $ = (e, t) => (r, n) => t(r, n, e);
|
|
409
|
+
let U = class extends X {
|
|
410
|
+
constructor(t, r, n, s, o, a) {
|
|
413
411
|
super();
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
this._instanceService =
|
|
412
|
+
y(this, "_local$", new j("en"));
|
|
413
|
+
y(this, "local$", this._local$.asObservable());
|
|
414
|
+
this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = a, this._initInterceptorCellContent();
|
|
417
415
|
}
|
|
418
416
|
get local() {
|
|
419
|
-
const
|
|
420
|
-
if (
|
|
421
|
-
return
|
|
417
|
+
const t = this._local$.getValue();
|
|
418
|
+
if (t)
|
|
419
|
+
return t;
|
|
422
420
|
switch (this._localeService.getCurrentLocale()) {
|
|
423
|
-
case
|
|
421
|
+
case b.FR_FR:
|
|
424
422
|
return "fr";
|
|
425
|
-
case
|
|
423
|
+
case b.RU_RU:
|
|
426
424
|
return "ru";
|
|
427
|
-
case
|
|
425
|
+
case b.VI_VN:
|
|
428
426
|
return "vi";
|
|
429
|
-
case
|
|
427
|
+
case b.ZH_CN:
|
|
430
428
|
return "zh-CN";
|
|
431
|
-
case
|
|
429
|
+
case b.ZH_TW:
|
|
432
430
|
return "zh-TW";
|
|
433
|
-
case
|
|
434
|
-
case
|
|
431
|
+
case b.EN_US:
|
|
432
|
+
case b.FA_IR:
|
|
435
433
|
default:
|
|
436
434
|
return "en";
|
|
437
435
|
}
|
|
438
436
|
}
|
|
439
437
|
// eslint-disable-next-line max-lines-per-function
|
|
440
438
|
_initInterceptorCellContent() {
|
|
441
|
-
const
|
|
439
|
+
const t = {
|
|
442
440
|
tl: {
|
|
443
441
|
size: 6,
|
|
444
442
|
color: "#409f11"
|
|
445
443
|
}
|
|
446
|
-
},
|
|
447
|
-
this.disposeWithMe(
|
|
448
|
-
|
|
449
|
-
})), this.disposeWithMe(this._sheetInterceptorService.intercept(
|
|
450
|
-
effect:
|
|
451
|
-
handler:
|
|
452
|
-
const
|
|
453
|
-
let
|
|
454
|
-
const
|
|
455
|
-
if (!
|
|
456
|
-
return
|
|
457
|
-
if (
|
|
458
|
-
const
|
|
459
|
-
|
|
444
|
+
}, r = new B();
|
|
445
|
+
this.disposeWithMe(Ce(this._local$, this._localeService.currentLocale$).subscribe(() => {
|
|
446
|
+
r.reset();
|
|
447
|
+
})), this.disposeWithMe(this._sheetInterceptorService.intercept(Se.CELL_CONTENT, {
|
|
448
|
+
effect: W.Value | W.Style,
|
|
449
|
+
handler: (n, s, o) => {
|
|
450
|
+
const a = s.unitId, d = s.subUnitId;
|
|
451
|
+
let u;
|
|
452
|
+
const c = n;
|
|
453
|
+
if (!c)
|
|
454
|
+
return o(n);
|
|
455
|
+
if (n != null && n.s) {
|
|
456
|
+
const m = s.workbook.getStyles().get(n.s);
|
|
457
|
+
m != null && m.n && (u = m.n);
|
|
460
458
|
}
|
|
461
|
-
if (
|
|
462
|
-
return
|
|
463
|
-
if (
|
|
464
|
-
return
|
|
465
|
-
...
|
|
459
|
+
if (u || (u = this._numfmtService.getValue(a, d, s.row, s.col)), !u)
|
|
460
|
+
return o(n);
|
|
461
|
+
if (u.pattern === Ne && c.v && ie(c.v))
|
|
462
|
+
return o({
|
|
463
|
+
...n,
|
|
466
464
|
markers: {
|
|
467
|
-
...
|
|
468
|
-
...
|
|
465
|
+
...n == null ? void 0 : n.markers,
|
|
466
|
+
...t
|
|
469
467
|
}
|
|
470
468
|
});
|
|
471
|
-
if (
|
|
472
|
-
return
|
|
473
|
-
let
|
|
474
|
-
const
|
|
475
|
-
if (
|
|
476
|
-
return
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
479
|
-
return
|
|
480
|
-
const
|
|
481
|
-
if (
|
|
482
|
-
const
|
|
483
|
-
|
|
469
|
+
if (c.t !== A.NUMBER || c.v == null || Number.isNaN(c.v))
|
|
470
|
+
return o(n);
|
|
471
|
+
let l = "";
|
|
472
|
+
const h = r.getValue(s.row, s.col);
|
|
473
|
+
if (h && h.parameters === `${c.v}_${u.pattern}`)
|
|
474
|
+
return o({ ...n, ...h.result });
|
|
475
|
+
const f = we(u.pattern, Number(c.v), this.local);
|
|
476
|
+
if (l = f.result, !l)
|
|
477
|
+
return o(n);
|
|
478
|
+
const v = { v: l };
|
|
479
|
+
if (f.color) {
|
|
480
|
+
const m = this._themeService.getCurrentTheme()[`${f.color}500`];
|
|
481
|
+
m && (v.interceptorStyle = { cl: { rgb: m } });
|
|
484
482
|
}
|
|
485
|
-
return
|
|
486
|
-
result:
|
|
487
|
-
parameters: `${
|
|
488
|
-
}),
|
|
489
|
-
},
|
|
490
|
-
priority:
|
|
491
|
-
})), this.disposeWithMe(this._commandService.onCommandExecuted((
|
|
492
|
-
if (
|
|
493
|
-
const
|
|
494
|
-
Object.keys(
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
483
|
+
return r.setValue(s.row, s.col, {
|
|
484
|
+
result: v,
|
|
485
|
+
parameters: `${c.v}_${u.pattern}`
|
|
486
|
+
}), o({ ...n, ...v });
|
|
487
|
+
},
|
|
488
|
+
priority: _e.NUMFMT
|
|
489
|
+
})), this.disposeWithMe(this._commandService.onCommandExecuted((n) => {
|
|
490
|
+
if (n.id === Z.id) {
|
|
491
|
+
const s = n.params;
|
|
492
|
+
Object.keys(s.values).forEach((o) => {
|
|
493
|
+
s.values[o].ranges.forEach((d) => {
|
|
494
|
+
C.foreach(d, (u, c) => {
|
|
495
|
+
r.realDeleteValue(u, c);
|
|
498
496
|
});
|
|
499
497
|
});
|
|
500
498
|
});
|
|
501
|
-
} else if (
|
|
502
|
-
const
|
|
503
|
-
new
|
|
504
|
-
|
|
499
|
+
} else if (n.id === ye.id) {
|
|
500
|
+
const s = n.params;
|
|
501
|
+
new B(s.cellValue).forValue((o, a) => {
|
|
502
|
+
r.realDeleteValue(o, a);
|
|
505
503
|
});
|
|
506
504
|
}
|
|
507
505
|
})), this.disposeWithMe(
|
|
508
|
-
this._instanceService.getCurrentTypeOfUnit$(
|
|
509
|
-
|
|
510
|
-
var
|
|
511
|
-
return (
|
|
506
|
+
this._instanceService.getCurrentTypeOfUnit$(Y.UNIVER_SHEET).pipe(
|
|
507
|
+
Me((n) => {
|
|
508
|
+
var s;
|
|
509
|
+
return (s = n == null ? void 0 : n.activeSheet$) != null ? s : $e(null);
|
|
512
510
|
}),
|
|
513
|
-
|
|
514
|
-
).subscribe(() =>
|
|
511
|
+
Ee(1)
|
|
512
|
+
).subscribe(() => r.reset())
|
|
515
513
|
);
|
|
516
514
|
}
|
|
517
|
-
setNumfmtLocal(
|
|
518
|
-
this._local$.next(
|
|
515
|
+
setNumfmtLocal(t) {
|
|
516
|
+
this._local$.next(t);
|
|
519
517
|
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
],
|
|
529
|
-
|
|
518
|
+
};
|
|
519
|
+
U = Le([
|
|
520
|
+
$(0, D),
|
|
521
|
+
$(1, E(ve)),
|
|
522
|
+
$(2, E(ce)),
|
|
523
|
+
$(3, E(M)),
|
|
524
|
+
$(4, E(F)),
|
|
525
|
+
$(5, E(ae))
|
|
526
|
+
], U);
|
|
527
|
+
class K extends X {
|
|
530
528
|
constructor() {
|
|
531
529
|
super(...arguments);
|
|
532
|
-
|
|
533
|
-
|
|
530
|
+
y(this, "_currencySymbol$", new j("US"));
|
|
531
|
+
y(this, "currencySymbol$", this._currencySymbol$.asObservable());
|
|
534
532
|
}
|
|
535
533
|
/**
|
|
536
534
|
* Set the currency symbol by setting the country code.
|
|
537
535
|
*/
|
|
538
|
-
setCurrencySymbolByCountryCode(
|
|
539
|
-
this._currencySymbol$.next(
|
|
536
|
+
setCurrencySymbolByCountryCode(r) {
|
|
537
|
+
this._currencySymbol$.next(r);
|
|
540
538
|
}
|
|
541
539
|
getCurrencySymbol() {
|
|
542
540
|
return this._currencySymbol$.getValue();
|
|
543
541
|
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
constructor(_config = void 0, _injector, _commandService) {
|
|
554
|
-
super(), this._config = _config, this._injector = _injector, this._commandService = _commandService;
|
|
542
|
+
}
|
|
543
|
+
var ee = Object.defineProperty, Be = Object.getOwnPropertyDescriptor, We = (e, t, r) => t in e ? ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Ge = (e, t, r, n) => {
|
|
544
|
+
for (var s = n > 1 ? void 0 : n ? Be(t, r) : t, o = e.length - 1, a; o >= 0; o--)
|
|
545
|
+
(a = e[o]) && (s = (n ? a(t, r, s) : a(s)) || s);
|
|
546
|
+
return n && s && ee(t, r, s), s;
|
|
547
|
+
}, q = (e, t) => (r, n) => t(r, n, e), te = (e, t, r) => We(e, typeof t != "symbol" ? t + "" : t, r);
|
|
548
|
+
let O = class extends me {
|
|
549
|
+
constructor(e = void 0, t, r) {
|
|
550
|
+
super(), this._config = e, this._injector = t, this._commandService = r;
|
|
555
551
|
}
|
|
556
552
|
onStarting() {
|
|
557
|
-
|
|
558
|
-
[
|
|
559
|
-
[
|
|
560
|
-
[
|
|
561
|
-
]),
|
|
562
|
-
[
|
|
553
|
+
fe(this._injector, [
|
|
554
|
+
[U],
|
|
555
|
+
[k],
|
|
556
|
+
[K]
|
|
557
|
+
]), G(this._injector, [
|
|
558
|
+
[U]
|
|
563
559
|
]);
|
|
564
560
|
}
|
|
565
561
|
onRendered() {
|
|
566
|
-
|
|
567
|
-
[
|
|
562
|
+
G(this._injector, [
|
|
563
|
+
[K]
|
|
568
564
|
]), [
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
].forEach((
|
|
575
|
-
this.disposeWithMe(this._commandService.registerCommand(
|
|
565
|
+
Ue,
|
|
566
|
+
Ve,
|
|
567
|
+
Oe,
|
|
568
|
+
De,
|
|
569
|
+
T
|
|
570
|
+
].forEach((e) => {
|
|
571
|
+
this.disposeWithMe(this._commandService.registerCommand(e));
|
|
576
572
|
});
|
|
577
573
|
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
],
|
|
586
|
-
const
|
|
587
|
-
label:
|
|
588
|
-
value:
|
|
589
|
-
color:
|
|
590
|
-
})),
|
|
574
|
+
};
|
|
575
|
+
te(O, "pluginName", Pe);
|
|
576
|
+
te(O, "type", Y.UNIVER_SHEET);
|
|
577
|
+
O = Ge([
|
|
578
|
+
ue(be),
|
|
579
|
+
q(1, E(le)),
|
|
580
|
+
q(2, M)
|
|
581
|
+
], O);
|
|
582
|
+
const ke = (e) => J.find((r) => e.includes(r)), et = () => J.map((e) => ({ label: e, value: e })), tt = (e) => Q.map((t) => ({
|
|
583
|
+
label: t.label(e),
|
|
584
|
+
value: t.suffix(e),
|
|
585
|
+
color: t.color
|
|
586
|
+
})), nt = () => Te.map((e) => ({ label: e.label, value: e.suffix })), rt = () => xe.map((e) => ({ label: e.label, value: e.suffix, color: e.color }));
|
|
591
587
|
export {
|
|
592
|
-
AddDecimalCommand,
|
|
593
|
-
CURRENCYFORMAT,
|
|
594
|
-
DATEFMTLISG,
|
|
595
|
-
MenuCurrencyService,
|
|
596
|
-
NUMBERFORMAT,
|
|
597
|
-
SetCurrencyCommand,
|
|
598
|
-
SetNumfmtCommand,
|
|
599
|
-
SetPercentCommand,
|
|
600
|
-
SheetsNumfmtCellContentController,
|
|
601
|
-
SubtractDecimalCommand,
|
|
602
|
-
UniverSheetsNumfmtPlugin,
|
|
603
|
-
countryCurrencyMap,
|
|
604
|
-
currencySymbols,
|
|
605
|
-
getCurrencyFormatOptions,
|
|
606
|
-
getCurrencyOptions,
|
|
607
|
-
getCurrencyType,
|
|
608
|
-
getDateFormatOptions,
|
|
609
|
-
getDecimalFromPattern,
|
|
610
|
-
getDecimalString,
|
|
611
|
-
getNumberFormatOptions,
|
|
612
|
-
getPatternPreview,
|
|
613
|
-
getPatternPreviewIgnoreGeneral,
|
|
614
|
-
getPatternType,
|
|
615
|
-
isPatternEqualWithoutDecimal,
|
|
616
|
-
isPatternHasDecimal,
|
|
617
|
-
setPatternDecimal
|
|
588
|
+
Ue as AddDecimalCommand,
|
|
589
|
+
Q as CURRENCYFORMAT,
|
|
590
|
+
Te as DATEFMTLISG,
|
|
591
|
+
k as MenuCurrencyService,
|
|
592
|
+
xe as NUMBERFORMAT,
|
|
593
|
+
Oe as SetCurrencyCommand,
|
|
594
|
+
T as SetNumfmtCommand,
|
|
595
|
+
De as SetPercentCommand,
|
|
596
|
+
U as SheetsNumfmtCellContentController,
|
|
597
|
+
Ve as SubtractDecimalCommand,
|
|
598
|
+
O as UniverSheetsNumfmtPlugin,
|
|
599
|
+
Ie as countryCurrencyMap,
|
|
600
|
+
J as currencySymbols,
|
|
601
|
+
tt as getCurrencyFormatOptions,
|
|
602
|
+
et as getCurrencyOptions,
|
|
603
|
+
ke as getCurrencyType,
|
|
604
|
+
nt as getDateFormatOptions,
|
|
605
|
+
x as getDecimalFromPattern,
|
|
606
|
+
z as getDecimalString,
|
|
607
|
+
rt as getNumberFormatOptions,
|
|
608
|
+
Ae as getPatternPreview,
|
|
609
|
+
we as getPatternPreviewIgnoreGeneral,
|
|
610
|
+
Qe as getPatternType,
|
|
611
|
+
Ze as isPatternEqualWithoutDecimal,
|
|
612
|
+
Je as isPatternHasDecimal,
|
|
613
|
+
P as setPatternDecimal
|
|
618
614
|
};
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(t,e){typeof exports=="object"&&typeof module<"u"?e(require("@univerjs/sheets-numfmt"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["@univerjs/sheets-numfmt","@univerjs/sheets/facade"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.UniverSheetsNumfmt,t.UniverSheetsFacade))})(this,function(t,e){"use strict";class o extends e.FRange{setNumberFormat(n){const s=[];return this.forEach((u,m)=>s.push({row:u,col:m,pattern:n})),this._commandService.syncExecuteCommand(t.SetNumfmtCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),values:s}),this}}e.FRange.extend(o);class i extends e.FWorkbook{setNumfmtLocal(n){return this._injector.get(t.SheetsNumfmtCellContentController).setNumfmtLocal(n),this}}e.FWorkbook.extend(i)});
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-numfmt"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-numfmt","@univerjs/engine-formula"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsNumfmt={},global.UniverCore,global.UniverSheets,global.rxjs,global.UniverEngineNumfmt,global.UniverEngineFormula))})(this,function(exports2,core,sheets,rxjs,engineNumfmt,engineFormula){"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;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:"€"},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"}],SHEET_NUMFMT_PLUGIN="SHEET_NUMFMT_PLUGIN",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(key=>{const v=setRedos.values[key];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")},_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")},getPatternType=__name(pattern=>core.numfmt.getInfo(pattern).type||"unknown","getPatternType"),getPatternPreview=__name((pattern,value,locale="en")=>{const negInfo=core.numfmt.getInfo(pattern)._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(engineFormula.stripErrorMargin(value))}:getPatternPreview(pattern,value,locale),"getPatternPreviewIgnoreGeneral");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");exports2.SheetsNumfmtCellContentController=(_a=class extends core.Disposable{constructor(_instanceService,_sheetInterceptorService,_themeService,_commandService,_numfmtService,_localeService){super();__publicField(this,"_local$",new rxjs.BehaviorSubject("en"));__publicField(this,"local$",this._local$.asObservable());this._instanceService=_instanceService,this._sheetInterceptorService=_sheetInterceptorService,this._themeService=_themeService,this._commandService=_commandService,this._numfmtService=_numfmtService,this._localeService=_localeService,this._initInterceptorCellContent()}get local(){const _local=this._local$.getValue();if(_local)return _local;switch(this._localeService.getCurrentLocale()){case core.LocaleType.FR_FR:return"fr";case core.LocaleType.RU_RU:return"ru";case core.LocaleType.VI_VN:return"vi";case core.LocaleType.ZH_CN:return"zh-CN";case core.LocaleType.ZH_TW:return"zh-TW";case core.LocaleType.EN_US:case core.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const TEXT_FORMAT_MARK={tl:{size:6,color:"#409f11"}},renderCache=new core.ObjectMatrix;this.disposeWithMe(rxjs.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{renderCache.reset()})),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)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);if(numfmtValue.pattern===engineNumfmt.DEFAULT_TEXT_FORMAT&&originCellValue.v&&core.isRealNum(originCellValue.v))return next({...cell,markers:{...cell==null?void 0:cell.markers,...TEXT_FORMAT_MARK}});if(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=getPatternPreviewIgnoreGeneral(numfmtValue.pattern,Number(originCellValue.v),this.local);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(key=>{params.values[key].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()))}setNumfmtLocal(local){this._local$.next(local)}},__name(_a,"SheetsNumfmtCellContentController"),_a),exports2.SheetsNumfmtCellContentController=__decorateClass$1([__decorateParam$1(0,core.IUniverInstanceService),__decorateParam$1(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$1(2,core.Inject(core.ThemeService)),__decorateParam$1(3,core.Inject(core.ICommandService)),__decorateParam$1(4,core.Inject(sheets.INumfmtService)),__decorateParam$1(5,core.Inject(core.LocaleService))],exports2.SheetsNumfmtCellContentController);const _NumfmtCurrencyController=class _NumfmtCurrencyController extends core.Disposable{constructor(){super(...arguments);__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(_NumfmtCurrencyController,"NumfmtCurrencyController");let NumfmtCurrencyController=_NumfmtCurrencyController;var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");exports2.UniverSheetsNumfmtPlugin=(_b=class extends core.Plugin{constructor(_config=void 0,_injector,_commandService){super(),this._config=_config,this._injector=_injector,this._commandService=_commandService}onStarting(){core.registerDependencies(this._injector,[[exports2.SheetsNumfmtCellContentController],[MenuCurrencyService],[NumfmtCurrencyController]]),core.touchDependencies(this._injector,[[exports2.SheetsNumfmtCellContentController]])}onRendered(){core.touchDependencies(this._injector,[[NumfmtCurrencyController]]),[AddDecimalCommand,SubtractDecimalCommand,SetCurrencyCommand,SetPercentCommand,SetNumfmtCommand].forEach(config=>{this.disposeWithMe(this._commandService.registerCommand(config))})}},__name(_b,"UniverSheetsNumfmtPlugin"),_b),__publicField2(exports2.UniverSheetsNumfmtPlugin,"pluginName",SHEET_NUMFMT_PLUGIN),__publicField2(exports2.UniverSheetsNumfmtPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),exports2.UniverSheetsNumfmtPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.ICommandService)],exports2.UniverSheetsNumfmtPlugin);const getCurrencyType=__name(pattern=>currencySymbols.find(code=>pattern.includes(code)),"getCurrencyType"),getCurrencyOptions=__name(()=>currencySymbols.map(item=>({label:item,value:item})),"getCurrencyOptions"),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");exports2.AddDecimalCommand=AddDecimalCommand,exports2.CURRENCYFORMAT=CURRENCYFORMAT,exports2.DATEFMTLISG=DATEFMTLISG,exports2.MenuCurrencyService=MenuCurrencyService,exports2.NUMBERFORMAT=NUMBERFORMAT,exports2.SetCurrencyCommand=SetCurrencyCommand,exports2.SetNumfmtCommand=SetNumfmtCommand,exports2.SetPercentCommand=SetPercentCommand,exports2.SubtractDecimalCommand=SubtractDecimalCommand,exports2.countryCurrencyMap=countryCurrencyMap,exports2.currencySymbols=currencySymbols,exports2.getCurrencyFormatOptions=getCurrencyFormatOptions,exports2.getCurrencyOptions=getCurrencyOptions,exports2.getCurrencyType=getCurrencyType,exports2.getDateFormatOptions=getDateFormatOptions,exports2.getDecimalFromPattern=getDecimalFromPattern,exports2.getDecimalString=getDecimalString,exports2.getNumberFormatOptions=getNumberFormatOptions,exports2.getPatternPreview=getPatternPreview,exports2.getPatternPreviewIgnoreGeneral=getPatternPreviewIgnoreGeneral,exports2.getPatternType=getPatternType,exports2.isPatternEqualWithoutDecimal=isPatternEqualWithoutDecimal,exports2.isPatternHasDecimal=isPatternHasDecimal,exports2.setPatternDecimal=setPatternDecimal,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(u,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-numfmt"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-numfmt","@univerjs/engine-formula"],t):(u=typeof globalThis<"u"?globalThis:u||self,t(u.UniverSheetsNumfmt={},u.UniverCore,u.UniverSheets,u.rxjs,u.UniverEngineNumfmt,u.UniverEngineFormula))})(this,function(u,t,f,b,Y,X){"use strict";var me=Object.defineProperty;var fe=(u,t,f)=>t in u?me(u,t,{enumerable:!0,configurable:!0,writable:!0,value:f}):u[t]=f;var I=(u,t,f)=>fe(u,typeof t!="symbol"?t+"":t,f);const P=["$","£","¥","¤","֏","؋","৳","฿","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],j={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:"€"},V=[{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"}],A=[{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"}],U=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],Z="SHEET_NUMFMT_PLUGIN",$=(e,n=0)=>{var i;return e&&(i=t.numfmt.getInfo(e).maxDecimals)!=null?i:n},J=(e,n)=>{if(e&&!n||!e&&n)return!1;const s=l=>l.reduce((m,S)=>{if(m.isEnd)return m;const g=S.value||S.num;return S.type==="point"?(m.isEnd=!0,m):{...m,result:m.result+g}},{isEnd:!1,result:""}).result,i=t.numfmt.getInfo(e)._partitions,r=t.numfmt.getInfo(n)._partitions,a=s(i[0].tokens),c=s(r[0].tokens),d=s(i[1].tokens),v=s(r[1].tokens);return a===c&&d===v&&i[1].color===r[1].color},D=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),R=(e,n)=>e.split(";").map(i=>/\.0?/.test(i)?i.replace(/\.0*/g,`${n>0?".":""}${D(Number(n||0))}`):/0([^0]?)|0$/.test(i)?i.replace(/0([^0]+)|0$/,`0${n>0?".":""}${D(Number(n||0))}$1`):i).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),N={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,n)=>{if(!n)return!1;const s=e.get(t.ICommandService),i=e.get(t.IUniverInstanceService),r=e.get(t.IUndoRedoService),a=f.getSheetCommandTarget(i,n);if(!a)return!1;const{unitId:c,subUnitId:d}=a,v=n.values.filter(o=>!!o.pattern),l=n.values.filter(o=>!o.pattern),m=f.transformCellsToRange(c,d,v),S={unitId:c,subUnitId:d,ranges:l.map(o=>({startColumn:o.col,startRow:o.row,endColumn:o.col,endRow:o.row}))},g=[],p=[];if(v.length){Object.keys(m.values).forEach(C=>{const y=m.values[C];y.ranges=f.rangeMerge(y.ranges)}),g.push({id:f.SetNumfmtMutation.id,params:m});const o=f.factorySetNumfmtUndoMutation(e,m);p.push(...o)}if(l.length){S.ranges=f.rangeMerge(S.ranges),g.push({id:f.RemoveNumfmtMutation.id,params:S});const o=f.factoryRemoveNumfmtUndoMutation(e,S);p.push(...o)}const h=t.sequenceExecute(g,s).result;return h&&r.pushUndoRedo({unitID:c,undoMutations:p,redoMutations:g}),h}},F={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),i=e.get(f.INumfmtService),r=e.get(t.IUniverInstanceService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const c=f.getSheetCommandTarget(r);if(!c)return!1;const{unitId:d,subUnitId:v}=c;let l=0;a.forEach(p=>{t.Range.foreach(p.range,(h,o)=>{const C=i.getValue(d,v,h,o);if(!C){const _=c.worksheet.getCellRaw(h,o);if(!l&&_&&_.t===t.CellValueType.NUMBER&&_.v){const M=/\.(\d*)$/.exec(String(_.v));if(M){const E=M[1].length;if(!E)return;l=Math.max(l,E)}}return}const y=$(C.pattern);l=y>l?y:l})});const m=l+1,S=R(`0${m>0?".0":""}`,m),g=[];return a.forEach(p=>{t.Range.foreach(p.range,(h,o)=>{const C=i.getValue(d,v,h,o);if(!C)g.push({row:h,col:o,pattern:S});else{const y=$(C.pattern),_=R(C.pattern,y+1);_!==C.pattern&&g.push({row:h,col:o,pattern:_})}})}),g.length?await n.executeCommand(N.id,{values:g}):!1}};class O{constructor(){I(this,"_currencySymbol$",new b.BehaviorSubject("US"));I(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(n){this._currencySymbol$.next(n)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}const w={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),i=e.get(O),r=j[i.getCurrencySymbol()]||"$",a=s.getCurrentSelections();if(!a||!a.length)return!1;const c=[],d=U[4].suffix(r);return a.forEach(l=>{t.Range.foreach(l.range,(m,S)=>{c.push({row:m,col:S,pattern:d,type:"currency"})})}),await n.executeCommand(N.id,{values:c})}},L={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),i=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!i||!i.length)return!1;const r=[],a="0%";return i.forEach(d=>{t.Range.foreach(d.range,(v,l)=>{r.push({row:v,col:l,pattern:a,type:"percent"})})}),await n.executeCommand(N.id,{values:r})}},B={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const n=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),i=e.get(f.INumfmtService),r=e.get(t.IUniverInstanceService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const c=f.getSheetCommandTarget(r);if(!c)return!1;const{unitId:d,subUnitId:v}=c;let l=0;a.forEach(h=>{t.Range.foreach(h.range,(o,C)=>{const y=i.getValue(d,v,o,C);if(!y){const M=c.worksheet.getCellRaw(o,C);if(!l&&M&&M.t===t.CellValueType.NUMBER&&M.v){const E=/\.(\d*)$/.exec(String(M.v));if(E){const K=E[1].length;if(!K)return;l=Math.max(l,K)}}return}const _=$(y.pattern);l=_>l?_:l})});const m=l-1,S=R(`0${m>0?".0":"."}`,m),g=[];return a.forEach(h=>{t.Range.foreach(h.range,(o,C)=>{const y=i.getValue(d,v,o,C);if(!y)g.push({row:o,col:C,pattern:S});else{const _=$(y.pattern);g.push({row:o,col:C,pattern:R(y.pattern,_-1)})}})}),await n.executeCommand(N.id,{values:g})}},k=e=>t.numfmt.getInfo(e).type||"unknown",G=(e,n,s="en")=>{const r=t.numfmt.getInfo(e)._partitions[1],a=t.numfmt.format(e,n,{locale:s,throws:!1});return n<0?{result:a,color:r.color}:{result:a}},W=(e,n,s)=>e==="General"?{result:String(X.stripErrorMargin(n))}:G(e,n,s);var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(e,n,s,i)=>{for(var r=i>1?void 0:i?te(n,s):n,a=e.length-1,c;a>=0;a--)(c=e[a])&&(r=(i?c(n,s,r):c(r))||r);return i&&r&&ee(n,s,r),r},T=(e,n)=>(s,i)=>n(s,i,e);u.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,i,r,a,c,d){super();I(this,"_local$",new b.BehaviorSubject("en"));I(this,"local$",this._local$.asObservable());this._instanceService=s,this._sheetInterceptorService=i,this._themeService=r,this._commandService=a,this._numfmtService=c,this._localeService=d,this._initInterceptorCellContent()}get local(){const s=this._local$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s={tl:{size:6,color:"#409f11"}},i=new t.ObjectMatrix;this.disposeWithMe(b.merge(this._local$,this._localeService.currentLocale$).subscribe(()=>{i.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(r,a,c)=>{const d=a.unitId,v=a.subUnitId;let l;const m=r;if(!m)return c(r);if(r!=null&&r.s){const o=a.workbook.getStyles().get(r.s);o!=null&&o.n&&(l=o.n)}if(l||(l=this._numfmtService.getValue(d,v,a.row,a.col)),!l)return c(r);if(l.pattern===Y.DEFAULT_TEXT_FORMAT&&m.v&&t.isRealNum(m.v))return c({...r,markers:{...r==null?void 0:r.markers,...s}});if(m.t!==t.CellValueType.NUMBER||m.v==null||Number.isNaN(m.v))return c(r);let S="";const g=i.getValue(a.row,a.col);if(g&&g.parameters===`${m.v}_${l.pattern}`)return c({...r,...g.result});const p=W(l.pattern,Number(m.v),this.local);if(S=p.result,!S)return c(r);const h={v:S};if(p.color){const o=this._themeService.getCurrentTheme()[`${p.color}500`];o&&(h.interceptorStyle={cl:{rgb:o}})}return i.setValue(a.row,a.col,{result:h,parameters:`${m.v}_${l.pattern}`}),c({...r,...h})},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===f.SetNumfmtMutation.id){const a=r.params;Object.keys(a.values).forEach(c=>{a.values[c].ranges.forEach(v=>{t.Range.foreach(v,(l,m)=>{i.realDeleteValue(l,m)})})})}else if(r.id===f.SetRangeValuesMutation.id){const a=r.params;new t.ObjectMatrix(a.cellValue).forValue((c,d)=>{i.realDeleteValue(c,d)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(b.switchMap(r=>{var a;return(a=r==null?void 0:r.activeSheet$)!=null?a:b.of(null)}),b.skip(1)).subscribe(()=>i.reset()))}setNumfmtLocal(s){this._local$.next(s)}},u.SheetsNumfmtCellContentController=ne([T(0,t.IUniverInstanceService),T(1,t.Inject(f.SheetInterceptorService)),T(2,t.Inject(t.ThemeService)),T(3,t.Inject(t.ICommandService)),T(4,t.Inject(f.INumfmtService)),T(5,t.Inject(t.LocaleService))],u.SheetsNumfmtCellContentController);class q extends t.Disposable{constructor(){super(...arguments);I(this,"_currencySymbol$",new b.BehaviorSubject("US"));I(this,"currencySymbol$",this._currencySymbol$.asObservable())}setCurrencySymbolByCountryCode(s){this._currencySymbol$.next(s)}getCurrencySymbol(){return this._currencySymbol$.getValue()}}var H=Object.defineProperty,re=Object.getOwnPropertyDescriptor,ie=(e,n,s)=>n in e?H(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s,se=(e,n,s,i)=>{for(var r=i>1?void 0:i?re(n,s):n,a=e.length-1,c;a>=0;a--)(c=e[a])&&(r=(i?c(n,s,r):c(r))||r);return i&&r&&H(n,s,r),r},x=(e,n)=>(s,i)=>n(s,i,e),z=(e,n,s)=>ie(e,typeof n!="symbol"?n+"":n,s);u.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(n=void 0,s,i){super(),this._config=n,this._injector=s,this._commandService=i}onStarting(){t.registerDependencies(this._injector,[[u.SheetsNumfmtCellContentController],[O],[q]]),t.touchDependencies(this._injector,[[u.SheetsNumfmtCellContentController]])}onRendered(){t.touchDependencies(this._injector,[[q]]),[F,B,w,L,N].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}},z(u.UniverSheetsNumfmtPlugin,"pluginName",Z),z(u.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET),u.UniverSheetsNumfmtPlugin=se([t.DependentOn(f.UniverSheetsPlugin),x(1,t.Inject(t.Injector)),x(2,t.ICommandService)],u.UniverSheetsNumfmtPlugin);const ae=e=>P.find(s=>e.includes(s)),ue=()=>P.map(e=>({label:e,value:e})),ce=e=>U.map(n=>({label:n.label(e),value:n.suffix(e),color:n.color})),le=()=>V.map(e=>({label:e.label,value:e.suffix})),oe=()=>A.map(e=>({label:e.label,value:e.suffix,color:e.color}));u.AddDecimalCommand=F,u.CURRENCYFORMAT=U,u.DATEFMTLISG=V,u.MenuCurrencyService=O,u.NUMBERFORMAT=A,u.SetCurrencyCommand=w,u.SetNumfmtCommand=N,u.SetPercentCommand=L,u.SubtractDecimalCommand=B,u.countryCurrencyMap=j,u.currencySymbols=P,u.getCurrencyFormatOptions=ce,u.getCurrencyOptions=ue,u.getCurrencyType=ae,u.getDateFormatOptions=le,u.getDecimalFromPattern=$,u.getDecimalString=D,u.getNumberFormatOptions=oe,u.getPatternPreview=G,u.getPatternPreviewIgnoreGeneral=W,u.getPatternType=k,u.isPatternEqualWithoutDecimal=J,u.isPatternHasDecimal=Q,u.setPatternDecimal=R,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "0.5.5-
|
|
3
|
+
"version": "0.5.5-nightly.202501201336",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"rxjs": ">=7.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/engine-
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/
|
|
56
|
+
"@univerjs/engine-formula": "0.5.5-nightly.202501201336",
|
|
57
|
+
"@univerjs/engine-numfmt": "0.5.5-nightly.202501201336",
|
|
58
|
+
"@univerjs/sheets": "0.5.5-nightly.202501201336",
|
|
59
|
+
"@univerjs/core": "0.5.5-nightly.202501201336"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"rxjs": "^7.8.1",
|