New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@univerjs/sheets

Package Overview
Dependencies
Maintainers
5
Versions
248
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@univerjs/sheets - npm Package Compare versions

Comparing version 0.5.5 to 0.6.0-alpha.0

2

lib/cjs/facade.js

@@ -1,1 +0,1 @@

"use strict";var T=Object.defineProperty;var x=(d,n,e)=>n in d?T(d,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[n]=e;var w=(d,n,e)=>x(d,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@univerjs/core"),a=require("@univerjs/sheets"),k=require("@univerjs/engine-formula");var W=Object.defineProperty,A=Object.getOwnPropertyDescriptor,F=(d,n,e,t)=>{for(var r=t>1?void 0:t?A(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&W(n,e,r),r},_=(d,n)=>(e,t)=>n(e,t,d);function M(d,n,e){const t=e.getDefinedNameMap(d);if(t==null)return n.t("definedName.defaultName")+1;const s=Array.from(Object.values(t)).length+1,o=n.t("definedName.defaultName")+s;if(e.getValueByName(d,o)==null)return o;let h=s+1;for(;;){const c=n.t("definedName.defaultName")+h;if(e.getValueByName(d,c)==null)return c;h++}}class b{constructor(){w(this,"_definedNameParam");this._definedNameParam={id:i.generateRandomId(10),unitId:"",name:"",formulaOrRefString:""}}setName(n){return this._definedNameParam.name=n,this}setFormula(n){return this._definedNameParam.formulaOrRefString=`=${n}`,this}setRef(n){return this._definedNameParam.formulaOrRefString=n,this}setRefByRange(n,e,t,r){return this._definedNameParam.formulaOrRefString=k.serializeRange({startRow:n,endRow:n+(t!=null?t:1)-1,startColumn:e,endColumn:e+(r!=null?r:1)-1}),this}setComment(n){return this._definedNameParam.comment=n,this}setHidden(n){return this._definedNameParam.hidden=n,this}build(){return this._definedNameParam}load(n){return this._definedNameParam=n,this}}let I=class extends i.FBase{constructor(d,n,e,t,r,s,o,h,c,u){super(),this._definedNameParam=d,this._injector=n,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=r,this._rangeProtectionRuleModel=s,this._worksheetProtectionPointRuleModel=o,this._authzIoService=h,this._localeService=c,this._definedNamesService=u}_apply(){this._definedNameParam.name===""&&(this._definedNameParam.name=M(this._definedNameParam.unitId,this._localeService,this._definedNamesService)),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,this._definedNameParam)}getName(){return this._definedNameParam.name}setName(d){this._definedNameParam.name=d,this._apply()}setFormula(d){this._definedNameParam.formulaOrRefString=`=${d}`,this._apply()}setRef(d){this._definedNameParam.formulaOrRefString=d,this._apply()}getFormulaOrRefString(){return this._definedNameParam.formulaOrRefString}setRefByRange(d,n,e,t){this._definedNameParam.formulaOrRefString=k.serializeRange({startRow:d,endRow:d+(e!=null?e:1)-1,startColumn:n,endColumn:n+(t!=null?t:1)-1}),this._apply()}getComment(){return this._definedNameParam.comment}setComment(d){this._definedNameParam.comment=d,this._apply()}setScopeToWorksheet(d){this._definedNameParam.localSheetId=d.getSheetId(),this._apply()}setScopeToWorkbook(){this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this._apply()}setHidden(d){this._definedNameParam.hidden=d,this._apply()}delete(){this._commandService.syncExecuteCommand(a.RemoveDefinedNameCommand.id,this._definedNameParam)}getLocalSheetId(){return this._definedNameParam.localSheetId}isWorkbookScope(){return this._definedNameParam.localSheetId===a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}toBuilder(){const d=this._injector.createInstance(b);return d.load(this._definedNameParam),d}};I=F([_(1,i.Inject(i.Injector)),_(2,i.ICommandService),_(3,i.IPermissionService),_(4,i.Inject(a.WorksheetProtectionRuleModel)),_(5,i.Inject(a.RangeProtectionRuleModel)),_(6,i.Inject(a.WorksheetProtectionPointModel)),_(7,i.Inject(i.IAuthzIoService)),_(8,i.Inject(i.LocaleService)),_(9,k.IDefinedNamesService)],I);var B=Object.defineProperty,D=Object.getOwnPropertyDescriptor,j=(d,n,e,t)=>{for(var r=t>1?void 0:t?D(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&B(n,e,r),r},v=(d,n)=>(e,t)=>n(e,t,d);exports.FPermission=class extends i.FBase{constructor(e,t,r,s,o,h,c){super();w(this,"permissionPointsDefinition",a.PermissionPointsDefinitions);w(this,"rangeRuleChangedAfterAuth$");w(this,"sheetRuleChangedAfterAuth$");this._injector=e,this._commandService=t,this._permissionService=r,this._worksheetProtectionRuleModel=s,this._rangeProtectionRuleModel=o,this._worksheetProtectionPointRuleModel=h,this._authzIoService=c,this.rangeRuleChangedAfterAuth$=this._rangeProtectionRuleModel.ruleRefresh$,this.sheetRuleChangedAfterAuth$=this._worksheetProtectionRuleModel.ruleRefresh$}setWorkbookPermissionPoint(e,t,r){const s=new t(e);this._permissionService.getPermissionPoint(s.id)||this._permissionService.addPermissionPoint(s),this._permissionService.updatePermissionPoint(s.id,r)}setWorkbookEditPermission(e,t){this.setWorkbookPermissionPoint(e,a.WorkbookEditablePermission,t)}async addWorksheetBasePermission(e,t){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");const s=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}});if(this._commandService.syncExecuteCommand(a.AddWorksheetProtectionMutation.id,{unitId:e,subUnitId:t,rule:{permissionId:s,unitType:a.UnitObject.Worksheet,unitId:e,subUnitId:t}}))return s}removeWorksheetPermission(e,t){this._commandService.syncExecuteCommand(a.DeleteWorksheetProtectionMutation.id,{unitId:e,subUnitId:t}),[...a.getAllWorksheetPermissionPoint(),...a.getAllWorksheetPermissionPointByPointPanel()].forEach(r=>{const s=new r(e,t);this._permissionService.updatePermissionPoint(s.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e,t)}async setWorksheetPermissionPoint(e,t,r,s){const o=this._worksheetProtectionRuleModel.getRule(e,t);let h;if(r===a.WorksheetEditPermission||r===a.WorksheetViewPermission)if(o)h=o.permissionId;else{if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");h=await this.addWorksheetBasePermission(e,t)}else{const l=this._worksheetProtectionPointRuleModel.getRule(e,t);l?h=l.permissionId:(h=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}}),this._commandService.syncExecuteCommand(a.SetWorksheetPermissionPointsMutation.id,{unitId:e,subUnitId:t,permissionId:h}))}const u=new r(e,t);return this._permissionService.getPermissionPoint(u.id)||this._permissionService.addPermissionPoint(u),this._permissionService.updatePermissionPoint(u.id,s),h}async addRangeBaseProtection(e,t,r){const s=await this._authzIoService.create({objectType:a.UnitObject.SelectRange,selectRangeObject:{collaborators:[],unitID:e,name:"",scope:void 0}}),o=`ruleId_${i.generateRandomId(6)}`;if(this._worksheetProtectionRuleModel.getRule(e,t))throw new Error("sheet protection cannot intersect with range protection");if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).some(l=>l.ranges.some(g=>r.some(C=>i.Rectangle.intersects(C,g)))))throw new Error("range protection cannot intersect");if(this._commandService.syncExecuteCommand(a.AddRangeProtectionMutation.id,{unitId:e,subUnitId:t,rules:[{permissionId:s,unitType:a.UnitObject.SelectRange,unitId:e,subUnitId:t,ranges:r,id:o}]}))return{permissionId:s,ruleId:o}}removeRangeProtection(e,t,r){this._commandService.syncExecuteCommand(a.DeleteRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleIds:r})&&this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length===0&&(this._worksheetProtectionPointRuleModel.deleteRule(e,t),[...a.getAllWorksheetPermissionPointByPointPanel()].forEach(h=>{const c=new h(e,t);this._permissionService.updatePermissionPoint(c.id,c.value)}))}setRangeProtectionPermissionPoint(e,t,r,s,o){const h=new s(e,t,r);this._permissionService.getPermissionPoint(h.id)||this._permissionService.addPermissionPoint(h),this._permissionService.updatePermissionPoint(h.id,o)}setRangeProtectionRanges(e,t,r,s){const o=this._rangeProtectionRuleModel.getRule(e,t,r);if(o){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).filter(u=>u.id!==r).some(u=>u.ranges.some(m=>s.some(l=>i.Rectangle.intersects(l,m)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(a.SetRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleId:r,rule:{...o,ranges:s}})}}};exports.FPermission=j([v(0,i.Inject(i.Injector)),v(1,i.ICommandService),v(2,i.IPermissionService),v(3,i.Inject(a.WorksheetProtectionRuleModel)),v(4,i.Inject(a.RangeProtectionRuleModel)),v(5,i.Inject(a.WorksheetProtectionPointModel)),v(6,i.Inject(i.IAuthzIoService))],exports.FPermission);function O(d){switch(d){case"left":return i.HorizontalAlign.LEFT;case"center":return i.HorizontalAlign.CENTER;case"normal":return i.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${d}`)}}function V(d){switch(d){case i.HorizontalAlign.LEFT:return"left";case i.HorizontalAlign.CENTER:return"center";case i.HorizontalAlign.RIGHT:return"normal";default:throw new Error(`Invalid horizontal alignment: ${d}`)}}function L(d){switch(d){case"top":return i.VerticalAlign.TOP;case"middle":return i.VerticalAlign.MIDDLE;case"bottom":return i.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${d}`)}}function H(d){switch(d){case i.VerticalAlign.TOP:return"top";case i.VerticalAlign.MIDDLE:return"middle";case i.VerticalAlign.BOTTOM:return"bottom";default:throw new Error(`Invalid vertical alignment: ${d}`)}}function R(d){return i.isFormulaString(d)?{f:d,v:null,p:null}:i.isCellV(d)?{v:d,p:null,f:null}:(i.isICellData(d),d)}function U(d,n){const e=new i.ObjectMatrix,{startRow:t,startColumn:r,endRow:s,endColumn:o}=n;if(i.Tools.isArray(d))for(let h=0;h<=s-t;h++)for(let c=0;c<=o-r;c++)e.setValue(h+t,c+r,R(d[h][c]));else new i.ObjectMatrix(d).forValue((c,u,m)=>{e.setValue(c,u,R(m))});return e.getMatrix()}function p(d,n){return{startRow:d.startRow,endRow:d.endRow,startColumn:0,endColumn:n.getColumnCount()-1,rangeType:i.RANGE_TYPE.ROW}}function y(d,n){return{startRow:0,endRow:n.getRowCount()-1,startColumn:d.startColumn,endColumn:d.endColumn,rangeType:i.RANGE_TYPE.COLUMN}}var z=Object.defineProperty,G=Object.getOwnPropertyDescriptor,$=(d,n,e,t)=>{for(var r=t>1?void 0:t?G(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&z(n,e,r),r},E=(d,n)=>(e,t)=>n(e,t,d);exports.FRange=class extends i.FBaseInitialable{constructor(n,e,t,r,s,o){super(r),this._workbook=n,this._worksheet=e,this._range=t,this._injector=r,this._commandService=s,this._formulaDataModel=o}getUnitId(){return this._workbook.getUnitId()}getSheetName(){return this._worksheet.getName()}getSheetId(){return this._worksheet.getSheetId()}getRange(){return this._range}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}isMerged(){const{startColumn:n,startRow:e,endColumn:t,endRow:r}=this._range;return this._worksheet.getMergedCellRange(e,n,r,t).some(o=>i.Rectangle.equals(o,this._range))}getCellStyleData(){var t;const n=this.getCellData(),e=this._workbook.getStyles();return n&&e&&(t=e.getStyleByCell(n))!=null?t:null}getCellStyle(){const n=this.getCellStyleData();return n?i.TextStyleValue.create(n):null}getCellStyles(){const n=this.getCellDatas(),e=this._workbook.getStyles();return n.map(t=>t.map(r=>{if(!r)return null;const s=e.getStyleByCell(r);return s?i.TextStyleValue.create(s):null}))}getValue(n){var e,t;return n?this.getValueAndRichTextValue():(t=(e=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:e.v)!=null?t:null}getValues(n){var h,c;n&&this.getValueAndRichTextValues();const{startRow:e,endRow:t,startColumn:r,endColumn:s}=this._range,o=[];for(let u=e;u<=t;u++){const m=[];for(let l=r;l<=s;l++)m.push((c=(h=this._worksheet.getCell(u,l))==null?void 0:h.v)!=null?c:null);o.push(m)}return o}getCellData(){var n;return(n=this._worksheet.getCell(this._range.startRow,this._range.startColumn))!=null?n:null}getCellDatas(){return this.getCellDataGrid()}getCellDataGrid(){const{startRow:n,endRow:e,startColumn:t,endColumn:r}=this._range,s=[];for(let o=n;o<=e;o++){const h=[];for(let c=t;c<=r;c++)h.push(this._worksheet.getCellRaw(o,c));s.push(h)}return s}getRichTextValue(){const n=this.getCellData();return n!=null&&n.p?new i.RichTextValue(n.p):null}getRichTextValues(){return this.getCellDataGrid().map(e=>e.map(t=>t!=null&&t.p?new i.RichTextValue(t.p):null))}getValueAndRichTextValue(){const n=this.getCellData();return n!=null&&n.p?new i.RichTextValue(n.p):n==null?void 0:n.v}getValueAndRichTextValues(){return this.getCellDatas().map(e=>e.map(t=>t!=null&&t.p?new i.RichTextValue(t.p):t==null?void 0:t.v))}getFormulas(){const n=[],{startRow:e,endRow:t,startColumn:r,endColumn:s}=this._range,o=this._worksheet.getSheetId(),h=this._workbook.getUnitId();for(let c=e;c<=t;c++){const u=[];for(let m=r;m<=s;m++){const l=this._formulaDataModel.getFormulaStringByCell(c,m,o,h);u.push(l||"")}n.push(u)}return n}getWrap(){return this._worksheet.getRange(this._range).getWrap()===i.BooleanNumber.TRUE}getWrapStrategy(){return this._worksheet.getRange(this._range).getWrapStrategy()}getHorizontalAlignment(){return V(this._worksheet.getRange(this._range).getHorizontalAlignment())}getVerticalAlignment(){return H(this._worksheet.getRange(this._range).getVerticalAlignment())}setCustomMetaData(n){return this.setValue({custom:n})}setCustomMetaDatas(n){return this.setValues(n.map(e=>e.map(t=>({custom:t}))))}getCustomMetaData(){var e;const n=this.getCellData();return(e=n==null?void 0:n.custom)!=null?e:null}getCustomMetaDatas(){return this.getCellDataGrid().map(e=>e.map(t=>{var r;return(r=t==null?void 0:t.custom)!=null?r:null}))}setBorder(n,e,t){return this._commandService.syncExecuteCommand(a.SetBorderBasicCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),value:{type:n,style:e,color:t}}),this}setBackgroundColor(n){return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:n}}}),this}setBackground(n){return this.setBackgroundColor(n),this}setValue(n){const e=R(n);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setValueForCell(n){const e=R(n);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.endColumn,endRow:this._range.endRow},value:e}),this}setRichTextValueForCell(n){const e=n instanceof i.RichTextValue?n.getData():n,t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.endColumn,endRow:this._range.endRow},value:{p:e}};return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,t),this}setRichTextValues(n){const e=n.map(s=>s.map(o=>o&&{p:o instanceof i.RichTextValue?o.getData():o})),t=U(e,this._range),r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:t};return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,r),this}setWrap(n){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:n?i.WrapStrategy.WRAP:i.WrapStrategy.UNSPECIFIED}),this}setWrapStrategy(n){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:n}),this}setVerticalAlignment(n){return this._commandService.syncExecuteCommand(a.SetVerticalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:L(n)}),this}setHorizontalAlignment(n){return this._commandService.syncExecuteCommand(a.SetHorizontalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:O(n)}),this}setValues(n){const e=U(n,this._range);return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setFontWeight(n){let e;if(n==="bold")e=i.BooleanNumber.TRUE;else if(n==="normal")e=i.BooleanNumber.FALSE;else if(n===null)e=null;else throw new Error("Invalid fontWeight");const t={type:"bl",value:e},r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,r),this}setFontStyle(n){let e;if(n==="italic")e=i.BooleanNumber.TRUE;else if(n==="normal")e=i.BooleanNumber.FALSE;else if(n===null)e=null;else throw new Error("Invalid fontStyle");const t={type:"it",value:e},r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,r),this}setFontLine(n){if(n==="underline")this._setFontUnderline({s:i.BooleanNumber.TRUE});else if(n==="line-through")this._setFontStrikethrough({s:i.BooleanNumber.TRUE});else if(n==="none")this._setFontUnderline({s:i.BooleanNumber.FALSE}),this._setFontStrikethrough({s:i.BooleanNumber.FALSE});else if(n===null)this._setFontUnderline(null),this._setFontStrikethrough(null);else throw new Error("Invalid fontLine");return this}_setFontUnderline(n){const e={type:"ul",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t)}_setFontStrikethrough(n){const e={type:"st",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t)}setFontFamily(n){const e={type:"ff",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t),this}setFontSize(n){const e={type:"fs",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t),this}setFontColor(n){const t={type:"cl",value:n===null?null:{rgb:n}},r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,r),this}merge(n=!0){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,e,t,[this._range],n),this}mergeAcross(n=!0){const e=a.getAddMergeMutationRangeByType([this._range],i.Dimension.ROWS),t=this._workbook.getUnitId(),r=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,r,e,n),this}mergeVertically(n=!0){const e=a.getAddMergeMutationRangeByType([this._range],i.Dimension.COLUMNS),t=this._workbook.getUnitId(),r=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,r,e,n),this}isPartOfMerge(){const{startRow:n,startColumn:e,endRow:t,endColumn:r}=this._range;return this._worksheet.getMergedCellRange(n,e,t,r).length>0}breakApart(){return this._commandService.syncExecuteCommand(a.RemoveWorksheetMergeCommand.id,{ranges:[this._range]}),this}forEach(n){const{startColumn:e,startRow:t,endColumn:r,endRow:s}=this._range;this._worksheet.getMatrixWithMergedCells(t,e,s,r).forValue((o,h,c)=>{n(o,h,c)})}getA1Notation(n){return n?k.serializeRangeWithSheet(this._worksheet.getName(),this._range):k.serializeRange(this._range)}activate(){return this._injector.createInstance(exports.FWorkbook,this._workbook).setActiveRange(this),this}activateAsCurrentCell(){const n=this._worksheet.getMergedCell(this._range.startRow,this._range.startColumn);if(n&&i.Rectangle.equals(n,this._range)||!n&&this._range.startRow===this._range.endRow&&this._range.startColumn===this._range.endColumn)return this.activate();throw new Error("The range is not a single cell")}splitTextToColumns(n,e,t){this._commandService.syncExecuteCommand(a.SplitTextToColumnsCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,delimiter:e,customDelimiter:t,treatMultipleDelimitersAsOne:n})}useThemeStyle(n){if(n==null){const e=this.getUsedThemeStyle();e&&this.removeThemeStyle(e)}else this._commandService.syncExecuteCommand(a.SetWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:n})}removeThemeStyle(n){this._commandService.syncExecuteCommand(a.DeleteWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:n})}getUsedThemeStyle(){return this._injector.get(a.SheetRangeThemeService).getAppliedRangeThemeStyle({unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})}};exports.FRange=$([E(3,i.Inject(i.Injector)),E(4,i.ICommandService),E(5,i.Inject(k.FormulaDataModel))],exports.FRange);var Y=Object.defineProperty,q=Object.getOwnPropertyDescriptor,K=(d,n,e,t)=>{for(var r=t>1?void 0:t?q(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&Y(n,e,r),r},J=(d,n)=>(e,t)=>n(e,t,d);exports.FSelection=class{constructor(n,e,t,r){this._workbook=n,this._worksheet=e,this._selections=t,this._injector=r}getActiveRange(){const n=this._selections.find(e=>!!e.primary);return n?this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,n.range):null}getActiveRangeList(){return this._selections.map(n=>this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,n.range))}getCurrentCell(){const n=this._selections.find(e=>!!e.primary);return n?n.primary:null}getActiveSheet(){const n=this._injector.createInstance(exports.FWorkbook,this._workbook);return this._injector.createInstance(exports.FWorksheet,n,this._workbook,this._worksheet)}updatePrimaryCell(n){const e=this._injector.get(i.ICommandService);let t=[],r=!1;for(const{range:o,style:h}of this._selections)i.Rectangle.contains(o,n.getRange())?(t.push({range:o,primary:a.getPrimaryForRange(n.getRange(),this._worksheet),style:h}),r=!0):t.push({range:o,primary:null,style:h});r||(t=[{range:n.getRange(),primary:a.getPrimaryForRange(n.getRange(),this._worksheet)}]);const s={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),selections:t};return e.syncExecuteCommand(a.SetSelectionsOperation.id,s),new exports.FSelection(this._workbook,this._worksheet,t,this._injector)}getNextDataRange(n){if(!this._selections.find(r=>!!r.primary))return null;const t=a.getNextPrimaryCell(this._selections.concat(),n,this._worksheet);return t?this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,t):null}};exports.FSelection=K([J(3,i.Inject(i.Injector))],exports.FSelection);var Q=Object.defineProperty,X=Object.getOwnPropertyDescriptor,Z=(d,n,e,t)=>{for(var r=t>1?void 0:t?X(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&Q(n,e,r),r},f=(d,n)=>(e,t)=>n(e,t,d);exports.FWorksheet=class extends i.FBaseInitialable{constructor(e,t,r,s,o,h,c){super(s);w(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=r,this._injector=s,this._selectionManagerService=o,this._logService=h,this._commandService=c}getSheet(){return this._worksheet}getInject(){return this._injector}getWorkbook(){return this._workbook}getSheetId(){return this._worksheet.getSheetId()}getSheetName(){return this._worksheet.getName()}getSelection(){const e=this._selectionManagerService.getCurrentSelections();return e?this._injector.createInstance(exports.FSelection,this._workbook,this._worksheet,e):null}getDefaultStyle(){return this._worksheet.getDefaultCellStyle()}getRowDefaultStyle(e,t=!1){return this._worksheet.getRowStyle(e,t)}getColumnDefaultStyle(e,t=!1){return this._worksheet.getColumnStyle(e,t)}setDefaultStyle(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId();return this._commandService.syncExecuteCommand(a.SetWorksheetDefaultStyleMutation.id,{unitId:t,subUnitId:r,defaultStyle:e}),this._worksheet.setDefaultCellStyle(e),this}setColumnDefaultStyle(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={unitId:r,subUnitId:s,columnData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,o),this}setRowDefaultStyle(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={unitId:r,subUnitId:s,rowData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,o),this}getRange(e,t,r,s){let o,h;if(typeof e=="object")o=e,h=this._worksheet;else if(typeof e=="string"){const{range:c,sheetName:u}=k.deserializeRangeWithSheet(e),m=u?this._workbook.getSheetBySheetName(u):this._worksheet;if(!m)throw new Error("Range not found");h=m,o={...c,unitId:this._workbook.getUnitId(),sheetId:h.getSheetId(),rangeType:i.RANGE_TYPE.NORMAL,startRow:c.rangeType===i.RANGE_TYPE.COLUMN?0:c.startRow,endRow:c.rangeType===i.RANGE_TYPE.COLUMN?h.getMaxRows()-1:c.endRow,startColumn:c.rangeType===i.RANGE_TYPE.ROW?0:c.startColumn,endColumn:c.rangeType===i.RANGE_TYPE.ROW?h.getMaxColumns()-1:c.endColumn}}else if(typeof e=="number"&&t!==void 0)h=this._worksheet,o={startRow:e,endRow:e+(r!=null?r:1)-1,startColumn:t,endColumn:t+(s!=null?s:1)-1,unitId:this._workbook.getUnitId(),sheetId:this._worksheet.getSheetId()};else throw new Error("Invalid range specification");return this._injector.createInstance(exports.FRange,this._workbook,h,o)}getMaxColumns(){return this._worksheet.getMaxColumns()}getMaxRows(){return this._worksheet.getMaxRows()}insertRowAfter(e){return this.insertRowsAfter(e,1)}insertRowBefore(e){return this.insertRowsBefore(e,1)}insertRows(e,t=1){return this.insertRowsBefore(e,t)}insertRowsAfter(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=i.Direction.DOWN,h=e+1,c=e+t,u=0,m=this._worksheet.getColumnCount()-1,l=a.copyRangeStyles(this._worksheet,h,c,u,m,!0,e);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:r,subUnitId:s,direction:o,range:{startRow:h,endRow:c,startColumn:u,endColumn:m},cellValue:l}),this}insertRowsBefore(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=i.Direction.UP,h=e,c=e+t-1,u=0,m=this._worksheet.getColumnCount()-1,l=a.copyRangeStyles(this._worksheet,h,c,u,m,!0,e-1);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:r,subUnitId:s,direction:o,range:{startRow:h,endRow:c,startColumn:u,endColumn:m},cellValue:l}),this}deleteRow(e){return this.deleteRows(e,1)}deleteRows(e,t){const r={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return this._commandService.syncExecuteCommand(a.RemoveRowByRangeCommand.id,{range:r,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}moveRows(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=p(e.getRange(),this._worksheet),h=o,c={startRow:t,endRow:t,startColumn:o.startColumn,endColumn:o.endColumn};return this._commandService.syncExecuteCommand(a.MoveRowsCommand.id,{unitId:r,subUnitId:s,range:o,fromRange:h,toRange:c}),this}hideRow(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=p(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:t,subUnitId:r,ranges:[s]}),this}hideRows(e,t=1){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:i.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:r,subUnitId:s,ranges:[o]}),this}unhideRow(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=p(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:t,subUnitId:r,ranges:[s]}),this}showRows(e,t=1){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:i.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:r,subUnitId:s,ranges:[o]}),this}setRowHeight(e,t){return this.setRowHeights(e,1,t)}autoFitRow(e,t=i.BooleanNumber.TRUE){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=[{startRow:e,endRow:e,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:o[0],value:i.WrapStrategy.WRAP}),this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightMutation.id,{unitId:r,subUnitId:s,ranges:o,autoHeightInfo:t}),this}setRowHeights(e,t,r){var m;const s=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=this._worksheet.getRowManager(),c=[],u=[];for(let l=e;l<e+t;l++){const g=((m=h.getRow(l))==null?void 0:m.ah)||this._worksheet.getConfig().defaultRowHeight,C={startRow:l,endRow:l,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};r<=g?c.push(C):u.push(C)}return u.length>0&&this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:s,subUnitId:o,ranges:u,value:r}),c.length>0&&this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:s,subUnitId:o,ranges:c}),this}setRowAutoHeight(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:r,subUnitId:s,ranges:o}),this}setRowHeightsForced(e,t,r){const s=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:s,subUnitId:o,ranges:h,value:r}),this}setRowCustom(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={};for(const[h,c]of Object.entries(e))s[Number(h)]={custom:c};const o={unitId:t,subUnitId:r,rowData:s};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,o),this}insertColumnAfter(e){return this.insertColumnsAfter(e,1)}insertColumnBefore(e){return this.insertColumnsBefore(e,1)}insertColumns(e,t=1){return this.insertColumnsBefore(e,t)}insertColumnsAfter(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=i.Direction.RIGHT,h=0,c=this._worksheet.getRowCount()-1,u=e+1,m=e+t,l=a.copyRangeStyles(this._worksheet,h,c,u,m,!1,e);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:r,subUnitId:s,direction:o,range:{startRow:h,endRow:c,startColumn:u,endColumn:m},cellValue:l}),this}insertColumnsBefore(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=i.Direction.LEFT,h=0,c=this._worksheet.getRowCount()-1,u=e,m=e+t-1,l=a.copyRangeStyles(this._worksheet,h,c,u,m,!1,e-1);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:r,subUnitId:s,direction:o,range:{startRow:h,endRow:c,startColumn:u,endColumn:m},cellValue:l}),this}deleteColumn(e){return this.deleteColumns(e,1)}deleteColumns(e,t){const r={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1};return this._commandService.syncExecuteCommand(a.RemoveColByRangeCommand.id,{range:r,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}moveColumns(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=y(e.getRange(),this._worksheet),h=o,c={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return this._commandService.syncExecuteCommand(a.MoveColsCommand.id,{unitId:r,subUnitId:s,range:o,fromRange:h,toRange:c}),this}hideColumn(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=y(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:t,subUnitId:r,ranges:[s]}),this}hideColumns(e,t=1){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:i.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:r,subUnitId:s,ranges:[o]}),this}unhideColumn(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=y(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:t,subUnitId:r,ranges:[s]}),this}showColumns(e,t=1){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:i.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:r,subUnitId:s,ranges:[o]}),this}setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}setColumnWidths(e,t,r){const s=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return this._commandService.syncExecuteCommand(a.SetColWidthCommand.id,{unitId:s,subUnitId:o,ranges:h,value:r}),this}setColumnCustom(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={};for(const[h,c]of Object.entries(e))s[Number(h)]={custom:c};const o={unitId:t,subUnitId:r,columnData:s};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,o),this}getMergedRanges(){return this._worksheet.getSnapshot().mergeData.map(t=>this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,t))}getCellMergeData(e,t){const s=this._worksheet.getMergedCell(e,t);if(s)return this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,s)}getActiveRange(){return this._fWorkbook.getActiveRange()}setActiveRange(e){const{unitId:t,sheetId:r}=e.getRange();if(t!==this._workbook.getUnitId()||r!==this._worksheet.getSheetId())throw new Error("Specified range must be part of the sheet.");return this._fWorkbook.setActiveRange(e),this}setFreeze(e){return this._logService.warn("setFreeze is deprecated, use setFrozenRows and setFrozenColumns instead"),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{...e,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}cancelFreeze(){return this._commandService.syncExecuteCommand(a.CancelFrozenCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}getFreeze(){return this._worksheet.getFreeze()}setFrozenColumns(...e){const t=this.getFreeze();if(arguments.length===1){const r=e[0];this.setFreeze({...t,startColumn:r>0?r:-1,xSplit:r})}else if(arguments.length===2){let[r=0,s=0]=e;r>s&&([r,s]=[s,r]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startColumn:s+1,xSplit:s-r+1,startRow:t.startRow,ySplit:t.ySplit,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}return this}setFrozenRows(...e){const t=this.getFreeze();if(arguments.length===1){const r=e[0];this.setFreeze({...t,startRow:r>0?r:-1,ySplit:r})}else if(arguments.length===2){let[r=0,s=0]=e;r>s&&([r,s]=[s,r]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startRow:s+1,ySplit:s-r+1,startColumn:t.startColumn,xSplit:t.xSplit,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}return this}getFrozenColumns(){const e=this.getFreeze();return e.startColumn===-1?0:e.startColumn}getFrozenRows(){const e=this.getFreeze();return e.startRow===-1?0:e.startRow}getFrozenRowRange(){const e=this._worksheet.getFreeze();return{startRow:e.startRow-e.ySplit,endRow:e.startRow-1}}getFrozenColumnRange(){const e=this._worksheet.getFreeze();return{startColumn:e.startColumn-e.xSplit,endColumn:e.startColumn-1}}hasHiddenGridLines(){return this._worksheet.getConfig().showGridlines===i.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.syncExecuteCommand(a.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE}),this}setGridLinesColor(e){return this._commandService.syncExecuteCommand(a.SetGridlinesColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getGridLinesColor(){return this._worksheet.getGridlinesColor()}setTabColor(e){return this._commandService.syncExecuteCommand(a.SetTabColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getTabColor(){return this._worksheet.getTabColor()}onCellDataChange(e){return this._injector.get(i.ICommandService).onCommandExecuted(r=>{if(r.id===a.SetRangeValuesMutation.id){const s=r.params;s.unitId===this._workbook.getUnitId()&&s.subUnitId===this._worksheet.getSheetId()&&s.cellValue&&e(new i.ObjectMatrix(s.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(i.ICommandService).beforeCommandExecuted(r=>{if(r.id===a.SetRangeValuesMutation.id){const s=r.params;s.unitId===this._workbook.getUnitId()&&s.subUnitId===this._worksheet.getSheetId()&&s.cellValue&&e(new i.ObjectMatrix(s.cellValue))}})}hideSheet(){const e=this._injector.get(i.ICommandService);if(this._workbook.getSheets().filter(o=>o.isSheetHidden()!==i.BooleanNumber.TRUE).length<=1)throw new Error("Cannot hide the only visible sheet");return e.syncExecuteCommand(a.SetWorksheetHideCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}showSheet(){return this._injector.get(i.ICommandService).syncExecuteCommand(a.SetWorksheetShowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}isSheetHidden(){return this._worksheet.isSheetHidden()===i.BooleanNumber.TRUE}setName(e){return this._commandService.syncExecuteCommand(a.SetWorksheetNameCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),name:e}),this}activate(){return this._fWorkbook.setActiveSheet(this),this}getIndex(){return this._workbook.getSheetIndex(this._worksheet)}clear(e){e&&e.contentsOnly&&!e.formatOnly&&this.clearContents(),e&&e.formatOnly&&!e.contentsOnly&&this.clearFormats();const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=this._injector.get(i.ICommandService),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return s.syncExecuteCommand(a.ClearSelectionAllCommand.id,{unitId:t,subUnitId:r,ranges:[o],options:e}),this}clearContents(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),r=this._injector.get(i.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return r.syncExecuteCommand(a.ClearSelectionContentCommand.id,{unitId:e,subUnitId:t,ranges:[s]}),this}clearFormats(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),r=this._injector.get(i.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return r.syncExecuteCommand(a.ClearSelectionFormatCommand.id,{unitId:e,subUnitId:t,ranges:[s]}),this}getDataRange(){const e=this.getLastRows(),t=this.getLastColumns();return this.getRange(0,0,e+1,t+1)}getLastColumns(){return this._worksheet.getLastColumnWithContent()}getLastColumn(){return this._worksheet.getLastColumnWithContent()}getLastRows(){return this._worksheet.getLastRowWithContent()}getLastRow(){return this._worksheet.getLastRowWithContent()}equalTo(e){return e instanceof exports.FWorksheet?this._worksheet.getSheetId()===e.getSheetId()&&this._workbook.getUnitId()===e.getWorkbook().getUnitId():!1}insertDefinedName(e,t){const s=this._injector.createInstance(b).setName(e).setRef(t).build();s.localSheetId=this.getSheetId(),this._fWorkbook.insertDefinedNameBuilder(s)}getDefinedNames(){return this._fWorkbook.getDefinedNames().filter(t=>t.getLocalSheetId()===this.getSheetId())}setCustomMetadata(e){return this._worksheet.setCustomMetadata(e),this}setRowCustomMetadata(e,t){return this._worksheet.getRowManager().setCustomMetadata(e,t),this}setColumnCustomMetadata(e,t){return this._worksheet.getColumnManager().setCustomMetadata(e,t),this}getRowCustomMetadata(e){return this._worksheet.getRowManager().getCustomMetadata(e)}getColumnCustomMetadata(e){return this._worksheet.getColumnManager().getCustomMetadata(e)}getMergeData(){return this._worksheet.getMergeData().map(e=>this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,e))}};exports.FWorksheet=Z([f(3,i.Inject(i.Injector)),f(4,i.Inject(a.SheetsSelectionsService)),f(5,i.Inject(i.ILogService)),f(6,i.ICommandService)],exports.FWorksheet);var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(d,n,e,t)=>{for(var r=t>1?void 0:t?te(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&ee(n,e,r),r},S=(d,n)=>(e,t)=>n(e,t,d);exports.FWorkbook=class extends i.FBaseInitialable{constructor(e,t,r,s,o,h,c,u,m,l){super(t);w(this,"id");this._workbook=e,this._injector=t,this._resourceLoaderService=r,this._selectionManagerService=s,this._univerInstanceService=o,this._commandService=h,this._permissionService=c,this._logService=u,this._localeService=m,this._definedNamesService=l,this.id=this._workbook.getUnitId()}getWorkbook(){return this._workbook}getId(){return this.id}getName(){return this._workbook.name}setName(e){this._workbook.setName(e)}save(){return this._resourceLoaderService.saveUnit(this._workbook.getUnitId())}getSnapshot(){return this._logService.warn("use 'save' instead of 'getSnapshot'"),this.save()}getActiveSheet(){const e=this._workbook.getActiveSheet();return this._injector.createInstance(exports.FWorksheet,this,this._workbook,e)}getSheets(){return this._workbook.getSheets().map(e=>this._injector.createInstance(exports.FWorksheet,this,this._workbook,e))}create(e,t,r){const s=i.mergeWorksheetSnapshotWithDefault({});s.rowCount=t,s.columnCount=r,s.name=e,s.id=e.toLowerCase().replace(/ /g,"-"),this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{unitId:this.id,index:this._workbook.getSheets().length,sheet:s}),this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId()});const o=this._workbook.getActiveSheet();if(!o)throw new Error("No active sheet found");return this._injector.createInstance(exports.FWorksheet,this,this._workbook,o)}getSheetBySheetId(e){const t=this._workbook.getSheetBySheetId(e);return t?this._injector.createInstance(exports.FWorksheet,this,this._workbook,t):null}getSheetByName(e){const t=this._workbook.getSheetBySheetName(e);return t?this._injector.createInstance(exports.FWorksheet,this,this._workbook,t):null}setActiveSheet(e){return this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:typeof e=="string"?e:e.getSheetId()}),typeof e=="string"?this.getSheetBySheetId(e):e}insertSheet(e){e!=null?this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{sheet:{name:e}}):this._commandService.syncExecuteCommand(a.InsertSheetCommand.id);const t=this.id,r=this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId();this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:t,subUnitId:r});const s=this._workbook.getActiveSheet();if(!s)throw new Error("No active sheet found");return this._injector.createInstance(exports.FWorksheet,this,this._workbook,s)}deleteSheet(e){const t=this.id,r=typeof e=="string"?e:e.getSheetId();return this._commandService.syncExecuteCommand(a.RemoveSheetCommand.id,{unitId:t,subUnitId:r})}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(i.UndoCommand.id),this}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(i.RedoCommand.id),this}onBeforeCommandExecute(e){return this._commandService.beforeCommandExecuted(t=>{var r;((r=t.params)==null?void 0:r.unitId)===this.id&&e(t)})}onCommandExecuted(e){return this._commandService.onCommandExecuted(t=>{var r;((r=t.params)==null?void 0:r.unitId)===this.id&&e(t)})}onSelectionChange(e){return i.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(t=>{this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET).getUnitId()===this.id&&(t!=null&&t.length?e(t.map(r=>r.range)):e([]))}))}setEditable(e){const t=new a.WorkbookEditablePermission(this._workbook.getUnitId());return this._permissionService.getPermissionPoint(t.id)||this._permissionService.addPermissionPoint(t),this._permissionService.updatePermissionPoint(t.id,e),this}setActiveRange(e){const t=this.getActiveSheet(),r=e.getRange().sheetId||t.getSheetId(),s=r?this._workbook.getSheetBySheetId(r):this._workbook.getActiveSheet(!0);if(!s)throw new Error("No active sheet found");s.getSheetId()!==t.getSheetId()&&this.setActiveSheet(this._injector.createInstance(exports.FWorksheet,this,this._workbook,s));const o={unitId:this.getId(),subUnitId:r,selections:[e].map(h=>({range:h.getRange(),primary:a.getPrimaryForRange(h.getRange(),s),style:null}))};return this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,o),this}getActiveRange(){const e=this._workbook.getActiveSheet(),r=this._selectionManagerService.getCurrentSelections().find(s=>!!s.primary);return r?this._injector.createInstance(exports.FRange,this._workbook,e,r.range):null}deleteActiveSheet(){const e=this.getActiveSheet();return this.deleteSheet(e)}duplicateSheet(e){return this._commandService.syncExecuteCommand(a.CopySheetCommand.id,{unitId:e.getWorkbook().getUnitId(),subUnitId:e.getSheetId()}),this._injector.createInstance(exports.FWorksheet,this,this._workbook,this._workbook.getActiveSheet())}duplicateActiveSheet(){const e=this.getActiveSheet();return this.duplicateSheet(e)}getNumSheets(){return this._workbook.getSheets().length}getLocale(){return this._localeService.getCurrentLocale()}setLocale(e){this._localeService.setLocale(e)}setSpreadsheetLocale(e){return this._localeService.setLocale(e),this}getUrl(){return location.href}moveSheet(e,t){let r=t;return r<0?r=0:r>this._workbook.getSheets().length-1&&(r=this._workbook.getSheets().length-1),this._commandService.syncExecuteCommand(a.SetWorksheetOrderCommand.id,{unitId:e.getWorkbook().getUnitId(),order:r,subUnitId:e.getSheetId()}),this}moveActiveSheet(e){const t=this.getActiveSheet();return this.moveSheet(t,e)}getPermission(){return this._injector.createInstance(exports.FPermission)}getDefinedName(e){const t=this._definedNamesService.getValueByName(this.id,e);return t?this._injector.createInstance(I,{...t,unitId:this.id}):null}getDefinedNames(){const e=this._definedNamesService.getDefinedNameMap(this.id);return e?Object.values(e).map(t=>this._injector.createInstance(I,{...t,unitId:this.id})):[]}insertDefinedName(e,t){const s=this._injector.createInstance(b).setName(e).setRef(t).build();return s.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this.insertDefinedNameBuilder(s),this}deleteDefinedName(e){const t=this.getDefinedName(e);return t?(t.delete(),!0):!1}insertDefinedNameBuilder(e){e.unitId=this.getId(),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}updateDefinedNameBuilder(e){this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}getRegisteredRangeThemes(){return this._injector.get(a.SheetRangeThemeService).getRegisteredRangeThemes()}registerRangeTheme(e){this._commandService.syncExecuteCommand(a.RegisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),rangeThemeStyle:e})}unregisterRangeTheme(e){this._commandService.syncExecuteCommand(a.UnregisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),themeName:e})}setCustomMetadata(e){return this._workbook.setCustomMetadata(e),this}getCustomMetadata(){return this._workbook.getCustomMetadata()}};exports.FWorkbook=ne([S(1,i.Inject(i.Injector)),S(2,i.Inject(i.IResourceLoaderService)),S(3,i.Inject(a.SheetsSelectionsService)),S(4,i.IUniverInstanceService),S(5,i.ICommandService),S(6,i.IPermissionService),S(7,i.ILogService),S(8,i.Inject(i.LocaleService)),S(9,k.IDefinedNamesService)],exports.FWorkbook);class re extends i.FUniver{getCommandSheetTarget(n){var s;const e=n.params;if(!e)return;const t=e.unitId?this.getUniverSheet(e.unitId):(s=this.getActiveWorkbook)==null?void 0:s.call(this);if(!t)return;const r=t.getSheetBySheetId(e.subUnitId||e.sheetId)||t.getActiveSheet();if(r)return{workbook:t,worksheet:r}}getSheetTarget(n,e){const t=this.getUniverSheet(n);if(!t)return;const r=t.getSheetBySheetId(e);if(r)return{workbook:t,worksheet:r}}_initWorkbookEvent(n){const e=n.get(i.IUniverInstanceService);this.disposeWithMe(e.unitDisposed$.subscribe(t=>{this._eventRegistry.get(this.Event.WorkbookDisposed)&&t.type===i.UniverInstanceType.UNIVER_SHEET&&this.fireEvent(this.Event.WorkbookDisposed,{unitId:t.getUnitId(),unitType:t.type,snapshot:t.getSnapshot()})})),this.disposeWithMe(e.unitAdded$.subscribe(t=>{if(this._eventRegistry.get(this.Event.WorkbookCreated)&&t.type===i.UniverInstanceType.UNIVER_SHEET){const r=t,s=n.createInstance(exports.FWorkbook,r);this.fireEvent(this.Event.WorkbookCreated,{unitId:t.getUnitId(),type:t.type,workbook:s,unit:s})}}))}_initialize(n){const e=n.get(i.ICommandService);this.disposeWithMe(e.beforeCommandExecuted(t=>{var r,s,o,h;switch(t.id){case a.InsertSheetCommand.id:{const c=t.params,{unitId:u,index:m,sheet:l}=c||{},g=u?this.getUniverSheet(u):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!g)return;const C={workbook:g,index:m,sheet:l};if(this.fireEvent(this.Event.BeforeSheetCreate,C),C.cancel)throw new i.CanceledError;break}case a.SetWorksheetActivateCommand.id:{if(!this._eventListend(this.Event.BeforeActiveSheetChange))return;const{subUnitId:c,unitId:u}=t.params,m=u?this.getUniverSheet(u):(s=this.getActiveWorkbook)==null?void 0:s.call(this);if(!m||!c)return;const l=m.getSheetBySheetId(c),g=m.getActiveSheet();if(!l||!g)return;this._fireBeforeActiveSheetChange(m,l,g);break}case a.RemoveSheetCommand.id:{if(!this._eventListend(this.Event.BeforeSheetDelete))return;const c=this.getCommandSheetTarget(t);if(!c)return;const{workbook:u,worksheet:m}=c;this._fireBeforeSheetDelete(u,m);break}case a.SetWorksheetOrderCommand.id:{if(!this._eventListend(this.Event.BeforeSheetMove))return;const{fromOrder:c,toOrder:u}=t.params,m=this.getCommandSheetTarget(t);if(!m)return;this._fireBeforeSheetMove(m.workbook,m.worksheet,u,c);break}case a.SetWorksheetNameCommand.id:{if(!this._eventListend(this.Event.BeforeSheetNameChange))return;const{name:c}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetNameChange(u.workbook,u.worksheet,c,u.worksheet.getSheetName());break}case a.SetTabColorCommand.id:{if(!this._eventListend(this.Event.BeforeSheetTabColorChange))return;const{color:c}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetTabColorChange(u.workbook,u.worksheet,c,u.worksheet.getTabColor());break}case a.SetWorksheetHideCommand.id:{if(!this._eventListend(this.Event.BeforeSheetHideChange))return;const{hidden:c}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetHideChange(u.workbook,u.worksheet,!!c);break}case a.SetGridlinesColorCommand.id:{if(!this._eventListend(this.Event.BeforeGridlineColorChange))return;const c=this.getCommandSheetTarget(t);if(!c)return;this.fireEvent(this.Event.BeforeGridlineColorChange,{...c,color:(o=t.params)==null?void 0:o.color});break}case a.ToggleGridlinesCommand.id:{if(!this._eventListend(this.Event.BeforeGridlineEnableChange))return;const c=this.getCommandSheetTarget(t);if(!c)return;this.fireEvent(this.Event.BeforeGridlineEnableChange,{...c,enabled:!!((h=t.params)!=null&&h.showGridlines)});break}}})),this.disposeWithMe(e.onCommandExecuted(t=>{var r,s;if(a.COMMAND_LISTENER_VALUE_CHANGE.indexOf(t.id)>-1){if(!this._eventListend(this.Event.SheetValueChanged)||!this.getActiveSheet())return;const h=a.getValueChangedEffectedRange(t).map(c=>{var u,m;return(m=(u=this.getWorkbook(c.unitId))==null?void 0:u.getSheetBySheetId(c.subUnitId))==null?void 0:m.getRange(c.range)}).filter(Boolean);if(!h.length)return;this.fireEvent(this.Event.SheetValueChanged,{payload:t,effectedRanges:h});return}switch(t.id){case a.InsertSheetCommand.id:{const o=t.params,{unitId:h}=o||{},c=h?this.getUniverSheet(h):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!c)return;const u=c.getActiveSheet();if(!u)return;const m={workbook:c,worksheet:u};this.fireEvent(this.Event.SheetCreated,m);break}case a.SetWorksheetActivateCommand.id:{if(!this._eventListend(this.Event.ActiveSheetChanged))return;const o=this.getActiveSheet();if(!o)return;const{workbook:h,worksheet:c}=o;this._fireActiveSheetChanged(h,c);break}case a.RemoveSheetCommand.id:{if(!this._eventListend(this.Event.SheetDeleted))return;const{subUnitId:o,unitId:h}=t.params,c=h?this.getUniverSheet(h):(s=this.getActiveWorkbook)==null?void 0:s.call(this);if(!c||!o)return;this._fireSheetDeleted(c,o);break}case a.SetWorksheetOrderCommand.id:{if(!this._eventListend(this.Event.SheetMoved))return;const{toOrder:o}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetMoved(h.workbook,h.worksheet,o);break}case a.SetWorksheetNameCommand.id:{if(!this._eventListend(this.Event.SheetNameChanged))return;const{name:o}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetNameChanged(h.workbook,h.worksheet,o);break}case a.SetTabColorCommand.id:{if(!this._eventListend(this.Event.SheetTabColorChanged))return;const{color:o}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetTabColorChanged(h.workbook,h.worksheet,o);break}case a.SetWorksheetHideCommand.id:{if(!this._eventListend(this.Event.SheetHideChanged))return;const{hidden:o}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetHideChanged(h.workbook,h.worksheet,!!o);break}case a.SetGridlinesColorCommand.id:case a.ToggleGridlinesCommand.id:{if(!this._eventListend(this.Event.GridlineChanged))return;const o=this.getCommandSheetTarget(t);if(!o)return;this.fireEvent(this.Event.GridlineChanged,{...o,enabled:!o.worksheet.hasHiddenGridLines(),color:o.worksheet.getGridLinesColor()});break}}})),this._initWorkbookEvent(n)}createUniverSheet(n){const t=this._injector.get(i.IUniverInstanceService).createUnit(i.UniverInstanceType.UNIVER_SHEET,n);return this._injector.createInstance(exports.FWorkbook,t)}createWorkbook(n){return this.createUniverSheet(n)}getActiveWorkbook(){const n=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);return n?this._injector.createInstance(exports.FWorkbook,n):null}getActiveUniverSheet(){return this.getActiveWorkbook()}getUniverSheet(n){const e=this._univerInstanceService.getUnit(n,i.UniverInstanceType.UNIVER_SHEET);return e?this._injector.createInstance(exports.FWorkbook,e):null}getWorkbook(n){return this.getUniverSheet(n)}getPermission(){return this._injector.createInstance(exports.FPermission)}onUniverSheetCreated(n){const e=this._univerInstanceService.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{const r=this._injector.createInstance(exports.FWorkbook,t);n(r)});return i.toDisposable(e)}newDefinedName(){return this._injector.createInstance(b)}getActiveSheet(){const n=this.getActiveWorkbook();if(!n)return null;const e=n.getActiveSheet();return e?{workbook:n,worksheet:e}:null}_fireBeforeActiveSheetChange(n,e,t){this.fireEvent(this.Event.BeforeActiveSheetChange,{workbook:n,activeSheet:e,oldActiveSheet:t})}_fireActiveSheetChanged(n,e){this.fireEvent(this.Event.ActiveSheetChanged,{workbook:n,activeSheet:e})}_fireBeforeSheetDelete(n,e){this.fireEvent(this.Event.BeforeSheetDelete,{workbook:n,worksheet:e})}_fireSheetDeleted(n,e){this.fireEvent(this.Event.SheetDeleted,{workbook:n,sheetId:e})}_fireBeforeSheetMove(n,e,t,r){this.fireEvent(this.Event.BeforeSheetMove,{workbook:n,worksheet:e,newIndex:t,oldIndex:r})}_fireSheetMoved(n,e,t){this.fireEvent(this.Event.SheetMoved,{workbook:n,worksheet:e,newIndex:t})}_fireBeforeSheetNameChange(n,e,t,r){this.fireEvent(this.Event.BeforeSheetNameChange,{workbook:n,worksheet:e,newName:t,oldName:r})}_fireSheetNameChanged(n,e,t){this.fireEvent(this.Event.SheetNameChanged,{workbook:n,worksheet:e,newName:t})}_fireBeforeSheetTabColorChange(n,e,t,r){this.fireEvent(this.Event.BeforeSheetTabColorChange,{workbook:n,worksheet:e,newColor:t,oldColor:r})}_fireSheetTabColorChanged(n,e,t){this.fireEvent(this.Event.SheetTabColorChanged,{workbook:n,worksheet:e,newColor:t})}_fireBeforeSheetHideChange(n,e,t){this.fireEvent(this.Event.BeforeSheetHideChange,{workbook:n,worksheet:e,hidden:t})}_fireSheetHideChanged(n,e,t){this.fireEvent(this.Event.SheetHideChanged,{workbook:n,worksheet:e,hidden:t})}}i.FUniver.extend(re);class P{get SheetValueChangeType(){return a.SheetValueChangeType}get SheetSkeletonChangeType(){return a.SheetSkeletonChangeType}}i.FEnum.extend(P);class N extends i.FEventName{get SheetCreated(){return"SheetCreated"}get BeforeSheetCreate(){return"BeforeSheetCreate"}get WorkbookCreated(){return"WorkbookCreated"}get WorkbookDisposed(){return"WorkbookDisposed"}get GridlineChanged(){return"GridlineChanged"}get BeforeGridlineEnableChange(){return"BeforeGridlineEnableChange"}get BeforeGridlineColorChange(){return"BeforeGridlineColorChange"}get BeforeActiveSheetChange(){return"BeforeActiveSheetChange"}get ActiveSheetChanged(){return"ActiveSheetChanged"}get SheetDeleted(){return"SheetDeleted"}get BeforeSheetDelete(){return"BeforeSheetDelete"}get SheetMoved(){return"SheetMoved"}get BeforeSheetMove(){return"BeforeSheetMove"}get SheetNameChanged(){return"SheetNameChanged"}get BeforeSheetNameChange(){return"BeforeSheetNameChange"}get SheetTabColorChanged(){return"SheetTabColorChanged"}get BeforeSheetTabColorChange(){return"BeforeSheetTabColorChange"}get SheetHideChanged(){return"SheetHideChanged"}get BeforeSheetHideChange(){return"BeforeSheetHideChange"}get SheetValueChanged(){return"SheetValueChanged"}}i.FEventName.extend(N);var se=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ie=(d,n,e,t)=>{for(var r=t>1?void 0:t?oe(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&se(n,e,r),r},ae=(d,n)=>(e,t)=>n(e,t,d);exports.FSheetHooks=class extends i.FBase{constructor(n){super(),this._injector=n}};exports.FSheetHooks=ie([ae(0,i.Inject(i.Injector))],exports.FSheetHooks);exports.FSheetEventName=N;exports.FSheetsEnum=P;
"use strict";var T=Object.defineProperty;var x=(d,n,e)=>n in d?T(d,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[n]=e;var w=(d,n,e)=>x(d,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),i=require("@univerjs/sheets"),k=require("@univerjs/engine-formula");var W=Object.defineProperty,A=Object.getOwnPropertyDescriptor,F=(d,n,e,t)=>{for(var r=t>1?void 0:t?A(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&W(n,e,r),r},_=(d,n)=>(e,t)=>n(e,t,d);function M(d,n,e){const t=e.getDefinedNameMap(d);if(t==null)return n.t("definedName.defaultName")+1;const s=Array.from(Object.values(t)).length+1,o=n.t("definedName.defaultName")+s;if(e.getValueByName(d,o)==null)return o;let h=s+1;for(;;){const c=n.t("definedName.defaultName")+h;if(e.getValueByName(d,c)==null)return c;h++}}class b{constructor(){w(this,"_definedNameParam");this._definedNameParam={id:a.generateRandomId(10),unitId:"",name:"",formulaOrRefString:""}}setName(n){return this._definedNameParam.name=n,this}setFormula(n){return this._definedNameParam.formulaOrRefString=`=${n}`,this}setRef(n){return this._definedNameParam.formulaOrRefString=n,this}setRefByRange(n,e,t,r){return this._definedNameParam.formulaOrRefString=k.serializeRange({startRow:n,endRow:n+(t!=null?t:1)-1,startColumn:e,endColumn:e+(r!=null?r:1)-1}),this}setComment(n){return this._definedNameParam.comment=n,this}setHidden(n){return this._definedNameParam.hidden=n,this}build(){return this._definedNameParam}load(n){return this._definedNameParam=n,this}}let I=class extends a.FBase{constructor(d,n,e,t,r,s,o,h,c,u){super(),this._definedNameParam=d,this._injector=n,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=r,this._rangeProtectionRuleModel=s,this._worksheetProtectionPointRuleModel=o,this._authzIoService=h,this._localeService=c,this._definedNamesService=u}_apply(){this._definedNameParam.name===""&&(this._definedNameParam.name=M(this._definedNameParam.unitId,this._localeService,this._definedNamesService)),this._commandService.syncExecuteCommand(i.SetDefinedNameCommand.id,this._definedNameParam)}getName(){return this._definedNameParam.name}setName(d){this._definedNameParam.name=d,this._apply()}setFormula(d){this._definedNameParam.formulaOrRefString=`=${d}`,this._apply()}setRef(d){this._definedNameParam.formulaOrRefString=d,this._apply()}getFormulaOrRefString(){return this._definedNameParam.formulaOrRefString}setRefByRange(d,n,e,t){this._definedNameParam.formulaOrRefString=k.serializeRange({startRow:d,endRow:d+(e!=null?e:1)-1,startColumn:n,endColumn:n+(t!=null?t:1)-1}),this._apply()}getComment(){return this._definedNameParam.comment}setComment(d){this._definedNameParam.comment=d,this._apply()}setScopeToWorksheet(d){this._definedNameParam.localSheetId=d.getSheetId(),this._apply()}setScopeToWorkbook(){this._definedNameParam.localSheetId=i.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this._apply()}setHidden(d){this._definedNameParam.hidden=d,this._apply()}delete(){this._commandService.syncExecuteCommand(i.RemoveDefinedNameCommand.id,this._definedNameParam)}getLocalSheetId(){return this._definedNameParam.localSheetId}isWorkbookScope(){return this._definedNameParam.localSheetId===i.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}toBuilder(){const d=this._injector.createInstance(b);return d.load(this._definedNameParam),d}};I=F([_(1,a.Inject(a.Injector)),_(2,a.ICommandService),_(3,a.IPermissionService),_(4,a.Inject(i.WorksheetProtectionRuleModel)),_(5,a.Inject(i.RangeProtectionRuleModel)),_(6,a.Inject(i.WorksheetProtectionPointModel)),_(7,a.Inject(a.IAuthzIoService)),_(8,a.Inject(a.LocaleService)),_(9,k.IDefinedNamesService)],I);var B=Object.defineProperty,D=Object.getOwnPropertyDescriptor,j=(d,n,e,t)=>{for(var r=t>1?void 0:t?D(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&B(n,e,r),r},v=(d,n)=>(e,t)=>n(e,t,d);exports.FPermission=class extends a.FBase{constructor(e,t,r,s,o,h,c){super();w(this,"permissionPointsDefinition",i.PermissionPointsDefinitions);w(this,"rangeRuleChangedAfterAuth$");w(this,"sheetRuleChangedAfterAuth$");this._injector=e,this._commandService=t,this._permissionService=r,this._worksheetProtectionRuleModel=s,this._rangeProtectionRuleModel=o,this._worksheetProtectionPointRuleModel=h,this._authzIoService=c,this.rangeRuleChangedAfterAuth$=this._rangeProtectionRuleModel.ruleRefresh$,this.sheetRuleChangedAfterAuth$=this._worksheetProtectionRuleModel.ruleRefresh$}setWorkbookPermissionPoint(e,t,r){const s=new t(e);this._permissionService.getPermissionPoint(s.id)||this._permissionService.addPermissionPoint(s),this._permissionService.updatePermissionPoint(s.id,r)}setWorkbookEditPermission(e,t){this.setWorkbookPermissionPoint(e,i.WorkbookEditablePermission,t)}async addWorksheetBasePermission(e,t){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");const s=await this._authzIoService.create({objectType:i.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}});if(this._commandService.syncExecuteCommand(i.AddWorksheetProtectionMutation.id,{unitId:e,subUnitId:t,rule:{permissionId:s,unitType:i.UnitObject.Worksheet,unitId:e,subUnitId:t}}))return s}removeWorksheetPermission(e,t){this._commandService.syncExecuteCommand(i.DeleteWorksheetProtectionMutation.id,{unitId:e,subUnitId:t}),[...i.getAllWorksheetPermissionPoint(),...i.getAllWorksheetPermissionPointByPointPanel()].forEach(r=>{const s=new r(e,t);this._permissionService.updatePermissionPoint(s.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e,t)}async setWorksheetPermissionPoint(e,t,r,s){const o=this._worksheetProtectionRuleModel.getRule(e,t);let h;if(r===i.WorksheetEditPermission||r===i.WorksheetViewPermission)if(o)h=o.permissionId;else{if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");h=await this.addWorksheetBasePermission(e,t)}else{const l=this._worksheetProtectionPointRuleModel.getRule(e,t);l?h=l.permissionId:(h=await this._authzIoService.create({objectType:i.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}}),this._commandService.syncExecuteCommand(i.SetWorksheetPermissionPointsMutation.id,{unitId:e,subUnitId:t,rule:{unitId:e,subUnitId:t,permissionId:h}}))}const u=new r(e,t);return this._permissionService.getPermissionPoint(u.id)||this._permissionService.addPermissionPoint(u),this._permissionService.updatePermissionPoint(u.id,s),h}async addRangeBaseProtection(e,t,r){const s=await this._authzIoService.create({objectType:i.UnitObject.SelectRange,selectRangeObject:{collaborators:[],unitID:e,name:"",scope:void 0}}),o=`ruleId_${a.generateRandomId(6)}`;if(this._worksheetProtectionRuleModel.getRule(e,t))throw new Error("sheet protection cannot intersect with range protection");if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).some(l=>l.ranges.some(g=>r.some(C=>a.Rectangle.intersects(C.getRange(),g)))))throw new Error("range protection cannot intersect");if(this._commandService.syncExecuteCommand(i.AddRangeProtectionMutation.id,{unitId:e,subUnitId:t,rules:[{permissionId:s,unitType:i.UnitObject.SelectRange,unitId:e,subUnitId:t,ranges:r.map(l=>l.getRange()),id:o}]}))return{permissionId:s,ruleId:o}}removeRangeProtection(e,t,r){this._commandService.syncExecuteCommand(i.DeleteRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleIds:r})&&this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length===0&&(this._worksheetProtectionPointRuleModel.deleteRule(e,t),[...i.getAllWorksheetPermissionPointByPointPanel()].forEach(h=>{const c=new h(e,t);this._permissionService.updatePermissionPoint(c.id,c.value)}))}setRangeProtectionPermissionPoint(e,t,r,s,o){const h=new s(e,t,r);this._permissionService.getPermissionPoint(h.id)||this._permissionService.addPermissionPoint(h),this._permissionService.updatePermissionPoint(h.id,o)}setRangeProtectionRanges(e,t,r,s){const o=this._rangeProtectionRuleModel.getRule(e,t,r);if(o){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).filter(u=>u.id!==r).some(u=>u.ranges.some(m=>s.some(l=>a.Rectangle.intersects(l.getRange(),m)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(i.SetRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleId:r,rule:{...o,ranges:s.map(u=>u.getRange())}})}}};exports.FPermission=j([v(0,a.Inject(a.Injector)),v(1,a.ICommandService),v(2,a.IPermissionService),v(3,a.Inject(i.WorksheetProtectionRuleModel)),v(4,a.Inject(i.RangeProtectionRuleModel)),v(5,a.Inject(i.WorksheetProtectionPointModel)),v(6,a.Inject(a.IAuthzIoService))],exports.FPermission);function O(d){switch(d){case"left":return a.HorizontalAlign.LEFT;case"center":return a.HorizontalAlign.CENTER;case"normal":return a.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${d}`)}}function V(d){switch(d){case a.HorizontalAlign.LEFT:return"left";case a.HorizontalAlign.CENTER:return"center";case a.HorizontalAlign.RIGHT:return"normal";default:throw new Error(`Invalid horizontal alignment: ${d}`)}}function L(d){switch(d){case"top":return a.VerticalAlign.TOP;case"middle":return a.VerticalAlign.MIDDLE;case"bottom":return a.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${d}`)}}function H(d){switch(d){case a.VerticalAlign.TOP:return"top";case a.VerticalAlign.MIDDLE:return"middle";case a.VerticalAlign.BOTTOM:return"bottom";default:throw new Error(`Invalid vertical alignment: ${d}`)}}function R(d){return a.isFormulaString(d)?{f:d,v:null,p:null}:a.isCellV(d)?{v:d,p:null,f:null}:(a.isICellData(d),d)}function U(d,n){const e=new a.ObjectMatrix,{startRow:t,startColumn:r,endRow:s,endColumn:o}=n;if(a.Tools.isArray(d))for(let h=0;h<=s-t;h++)for(let c=0;c<=o-r;c++)e.setValue(h+t,c+r,R(d[h][c]));else new a.ObjectMatrix(d).forValue((c,u,m)=>{e.setValue(c,u,R(m))});return e.getMatrix()}function p(d,n){return{startRow:d.startRow,endRow:d.endRow,startColumn:0,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ROW}}function y(d,n){return{startRow:0,endRow:n.getRowCount()-1,startColumn:d.startColumn,endColumn:d.endColumn,rangeType:a.RANGE_TYPE.COLUMN}}var z=Object.defineProperty,G=Object.getOwnPropertyDescriptor,$=(d,n,e,t)=>{for(var r=t>1?void 0:t?G(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&z(n,e,r),r},E=(d,n)=>(e,t)=>n(e,t,d);exports.FRange=class extends a.FBaseInitialable{constructor(n,e,t,r,s,o){super(r),this._workbook=n,this._worksheet=e,this._range=t,this._injector=r,this._commandService=s,this._formulaDataModel=o}getUnitId(){return this._workbook.getUnitId()}getSheetName(){return this._worksheet.getName()}getSheetId(){return this._worksheet.getSheetId()}getRange(){return this._range}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}isMerged(){const{startColumn:n,startRow:e,endColumn:t,endRow:r}=this._range;return this._worksheet.getMergedCellRange(e,n,r,t).some(o=>a.Rectangle.equals(o,this._range))}getCellStyleData(){var t;const n=this.getCellData(),e=this._workbook.getStyles();return n&&e&&(t=e.getStyleByCell(n))!=null?t:null}getCellStyle(){const n=this.getCellStyleData();return n?a.TextStyleValue.create(n):null}getCellStyles(){const n=this.getCellDatas(),e=this._workbook.getStyles();return n.map(t=>t.map(r=>{if(!r)return null;const s=e.getStyleByCell(r);return s?a.TextStyleValue.create(s):null}))}getValue(n){var e,t;return n?this.getValueAndRichTextValue():(t=(e=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:e.v)!=null?t:null}getValues(n){var h,c;n&&this.getValueAndRichTextValues();const{startRow:e,endRow:t,startColumn:r,endColumn:s}=this._range,o=[];for(let u=e;u<=t;u++){const m=[];for(let l=r;l<=s;l++)m.push((c=(h=this._worksheet.getCell(u,l))==null?void 0:h.v)!=null?c:null);o.push(m)}return o}getCellData(){var n;return(n=this._worksheet.getCell(this._range.startRow,this._range.startColumn))!=null?n:null}getCellDatas(){return this.getCellDataGrid()}getCellDataGrid(){const{startRow:n,endRow:e,startColumn:t,endColumn:r}=this._range,s=[];for(let o=n;o<=e;o++){const h=[];for(let c=t;c<=r;c++)h.push(this._worksheet.getCellRaw(o,c));s.push(h)}return s}getRichTextValue(){const n=this.getCellData();return n!=null&&n.p?new a.RichTextValue(n.p):null}getRichTextValues(){return this.getCellDataGrid().map(e=>e.map(t=>t!=null&&t.p?new a.RichTextValue(t.p):null))}getValueAndRichTextValue(){const n=this.getCellData();return n!=null&&n.p?new a.RichTextValue(n.p):n==null?void 0:n.v}getValueAndRichTextValues(){return this.getCellDatas().map(e=>e.map(t=>t!=null&&t.p?new a.RichTextValue(t.p):t==null?void 0:t.v))}getFormulas(){const n=[],{startRow:e,endRow:t,startColumn:r,endColumn:s}=this._range,o=this._worksheet.getSheetId(),h=this._workbook.getUnitId();for(let c=e;c<=t;c++){const u=[];for(let m=r;m<=s;m++){const l=this._formulaDataModel.getFormulaStringByCell(c,m,o,h);u.push(l||"")}n.push(u)}return n}getWrap(){return this._worksheet.getRange(this._range).getWrap()===a.BooleanNumber.TRUE}getWrapStrategy(){return this._worksheet.getRange(this._range).getWrapStrategy()}getHorizontalAlignment(){return V(this._worksheet.getRange(this._range).getHorizontalAlignment())}getVerticalAlignment(){return H(this._worksheet.getRange(this._range).getVerticalAlignment())}setCustomMetaData(n){return this.setValue({custom:n})}setCustomMetaDatas(n){return this.setValues(n.map(e=>e.map(t=>({custom:t}))))}getCustomMetaData(){var e;const n=this.getCellData();return(e=n==null?void 0:n.custom)!=null?e:null}getCustomMetaDatas(){return this.getCellDataGrid().map(e=>e.map(t=>{var r;return(r=t==null?void 0:t.custom)!=null?r:null}))}setBorder(n,e,t){return this._commandService.syncExecuteCommand(i.SetBorderBasicCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),value:{type:n,style:e,color:t}}),this}setBackgroundColor(n){return this._commandService.syncExecuteCommand(i.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:n}}}),this}setBackground(n){return this.setBackgroundColor(n),this}setValue(n){const e=R(n);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(i.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setValueForCell(n){const e=R(n);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(i.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.endColumn,endRow:this._range.endRow},value:e}),this}setRichTextValueForCell(n){const e=n instanceof a.RichTextValue?n.getData():n,t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.endColumn,endRow:this._range.endRow},value:{p:e}};return this._commandService.syncExecuteCommand(i.SetRangeValuesCommand.id,t),this}setRichTextValues(n){const e=n.map(s=>s.map(o=>o&&{p:o instanceof a.RichTextValue?o.getData():o})),t=U(e,this._range),r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:t};return this._commandService.syncExecuteCommand(i.SetRangeValuesCommand.id,r),this}setWrap(n){return this._commandService.syncExecuteCommand(i.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:n?a.WrapStrategy.WRAP:a.WrapStrategy.UNSPECIFIED}),this}setWrapStrategy(n){return this._commandService.syncExecuteCommand(i.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:n}),this}setVerticalAlignment(n){return this._commandService.syncExecuteCommand(i.SetVerticalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:L(n)}),this}setHorizontalAlignment(n){return this._commandService.syncExecuteCommand(i.SetHorizontalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:O(n)}),this}setValues(n){const e=U(n,this._range);return this._commandService.syncExecuteCommand(i.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setFontWeight(n){let e;if(n==="bold")e=a.BooleanNumber.TRUE;else if(n==="normal")e=a.BooleanNumber.FALSE;else if(n===null)e=null;else throw new Error("Invalid fontWeight");const t={type:"bl",value:e},r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(i.SetStyleCommand.id,r),this}setFontStyle(n){let e;if(n==="italic")e=a.BooleanNumber.TRUE;else if(n==="normal")e=a.BooleanNumber.FALSE;else if(n===null)e=null;else throw new Error("Invalid fontStyle");const t={type:"it",value:e},r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(i.SetStyleCommand.id,r),this}setFontLine(n){if(n==="underline")this._setFontUnderline({s:a.BooleanNumber.TRUE});else if(n==="line-through")this._setFontStrikethrough({s:a.BooleanNumber.TRUE});else if(n==="none")this._setFontUnderline({s:a.BooleanNumber.FALSE}),this._setFontStrikethrough({s:a.BooleanNumber.FALSE});else if(n===null)this._setFontUnderline(null),this._setFontStrikethrough(null);else throw new Error("Invalid fontLine");return this}_setFontUnderline(n){const e={type:"ul",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(i.SetStyleCommand.id,t)}_setFontStrikethrough(n){const e={type:"st",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(i.SetStyleCommand.id,t)}setFontFamily(n){const e={type:"ff",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(i.SetStyleCommand.id,t),this}setFontSize(n){const e={type:"fs",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(i.SetStyleCommand.id,t),this}setFontColor(n){const t={type:"cl",value:n===null?null:{rgb:n}},r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(i.SetStyleCommand.id,r),this}merge(n=!0){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return i.addMergeCellsUtil(this._injector,e,t,[this._range],n),this}mergeAcross(n=!0){const e=i.getAddMergeMutationRangeByType([this._range],a.Dimension.ROWS),t=this._workbook.getUnitId(),r=this._worksheet.getSheetId();return i.addMergeCellsUtil(this._injector,t,r,e,n),this}mergeVertically(n=!0){const e=i.getAddMergeMutationRangeByType([this._range],a.Dimension.COLUMNS),t=this._workbook.getUnitId(),r=this._worksheet.getSheetId();return i.addMergeCellsUtil(this._injector,t,r,e,n),this}isPartOfMerge(){const{startRow:n,startColumn:e,endRow:t,endColumn:r}=this._range;return this._worksheet.getMergedCellRange(n,e,t,r).length>0}breakApart(){return this._commandService.syncExecuteCommand(i.RemoveWorksheetMergeCommand.id,{ranges:[this._range]}),this}forEach(n){const{startColumn:e,startRow:t,endColumn:r,endRow:s}=this._range;this._worksheet.getMatrixWithMergedCells(t,e,s,r).forValue((o,h,c)=>{n(o,h,c)})}getA1Notation(n){return n?k.serializeRangeWithSheet(this._worksheet.getName(),this._range):k.serializeRange(this._range)}activate(){return this._injector.createInstance(exports.FWorkbook,this._workbook).setActiveRange(this),this}activateAsCurrentCell(){const n=this._worksheet.getMergedCell(this._range.startRow,this._range.startColumn);if(n&&a.Rectangle.equals(n,this._range)||!n&&this._range.startRow===this._range.endRow&&this._range.startColumn===this._range.endColumn)return this.activate();throw new Error("The range is not a single cell")}splitTextToColumns(n,e,t){this._commandService.syncExecuteCommand(i.SplitTextToColumnsCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,delimiter:e,customDelimiter:t,treatMultipleDelimitersAsOne:n})}useThemeStyle(n){if(n==null){const e=this.getUsedThemeStyle();e&&this.removeThemeStyle(e)}else this._commandService.syncExecuteCommand(i.SetWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:n})}removeThemeStyle(n){this._commandService.syncExecuteCommand(i.DeleteWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:n})}getUsedThemeStyle(){return this._injector.get(i.SheetRangeThemeService).getAppliedRangeThemeStyle({unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})}};exports.FRange=$([E(3,a.Inject(a.Injector)),E(4,a.ICommandService),E(5,a.Inject(k.FormulaDataModel))],exports.FRange);var Y=Object.defineProperty,q=Object.getOwnPropertyDescriptor,K=(d,n,e,t)=>{for(var r=t>1?void 0:t?q(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&Y(n,e,r),r},J=(d,n)=>(e,t)=>n(e,t,d);exports.FSelection=class{constructor(n,e,t,r){this._workbook=n,this._worksheet=e,this._selections=t,this._injector=r}getActiveRange(){const n=this._selections.find(e=>!!e.primary);return n?this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,n.range):null}getActiveRangeList(){return this._selections.map(n=>this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,n.range))}getCurrentCell(){const n=this._selections.find(e=>!!e.primary);return n?n.primary:null}getActiveSheet(){const n=this._injector.createInstance(exports.FWorkbook,this._workbook);return this._injector.createInstance(exports.FWorksheet,n,this._workbook,this._worksheet)}updatePrimaryCell(n){const e=this._injector.get(a.ICommandService);let t=[],r=!1;for(const{range:o,style:h}of this._selections)a.Rectangle.contains(o,n.getRange())?(t.push({range:o,primary:i.getPrimaryForRange(n.getRange(),this._worksheet),style:h}),r=!0):t.push({range:o,primary:null,style:h});r||(t=[{range:n.getRange(),primary:i.getPrimaryForRange(n.getRange(),this._worksheet)}]);const s={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),selections:t};return e.syncExecuteCommand(i.SetSelectionsOperation.id,s),new exports.FSelection(this._workbook,this._worksheet,t,this._injector)}getNextDataRange(n){if(!this._selections.find(r=>!!r.primary))return null;const t=i.getNextPrimaryCell(this._selections.concat(),n,this._worksheet);return t?this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,t):null}};exports.FSelection=K([J(3,a.Inject(a.Injector))],exports.FSelection);var Q=Object.defineProperty,X=Object.getOwnPropertyDescriptor,Z=(d,n,e,t)=>{for(var r=t>1?void 0:t?X(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&Q(n,e,r),r},f=(d,n)=>(e,t)=>n(e,t,d);exports.FWorksheet=class extends a.FBaseInitialable{constructor(e,t,r,s,o,h,c){super(s);w(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=r,this._injector=s,this._selectionManagerService=o,this._logService=h,this._commandService=c}getSheet(){return this._worksheet}getInject(){return this._injector}getWorkbook(){return this._workbook}getSheetId(){return this._worksheet.getSheetId()}getSheetName(){return this._worksheet.getName()}getSelection(){const e=this._selectionManagerService.getCurrentSelections();return e?this._injector.createInstance(exports.FSelection,this._workbook,this._worksheet,e):null}getDefaultStyle(){return this._worksheet.getDefaultCellStyle()}getRowDefaultStyle(e,t=!1){return this._worksheet.getRowStyle(e,t)}getColumnDefaultStyle(e,t=!1){return this._worksheet.getColumnStyle(e,t)}setDefaultStyle(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId();return this._commandService.syncExecuteCommand(i.SetWorksheetDefaultStyleMutation.id,{unitId:t,subUnitId:r,defaultStyle:e}),this._worksheet.setDefaultCellStyle(e),this}setColumnDefaultStyle(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={unitId:r,subUnitId:s,columnData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(i.SetColDataCommand.id,o),this}setRowDefaultStyle(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={unitId:r,subUnitId:s,rowData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(i.SetRowDataCommand.id,o),this}getRange(e,t,r,s){let o,h;if(typeof e=="object")o=e,h=this._worksheet;else if(typeof e=="string"){const{range:c,sheetName:u}=k.deserializeRangeWithSheet(e),m=u?this._workbook.getSheetBySheetName(u):this._worksheet;if(!m)throw new Error("Range not found");h=m,o={...c,unitId:this._workbook.getUnitId(),sheetId:h.getSheetId(),rangeType:a.RANGE_TYPE.NORMAL,startRow:c.rangeType===a.RANGE_TYPE.COLUMN?0:c.startRow,endRow:c.rangeType===a.RANGE_TYPE.COLUMN?h.getMaxRows()-1:c.endRow,startColumn:c.rangeType===a.RANGE_TYPE.ROW?0:c.startColumn,endColumn:c.rangeType===a.RANGE_TYPE.ROW?h.getMaxColumns()-1:c.endColumn}}else if(typeof e=="number"&&t!==void 0)h=this._worksheet,o={startRow:e,endRow:e+(r!=null?r:1)-1,startColumn:t,endColumn:t+(s!=null?s:1)-1,unitId:this._workbook.getUnitId(),sheetId:this._worksheet.getSheetId()};else throw new Error("Invalid range specification");return this._injector.createInstance(exports.FRange,this._workbook,h,o)}getMaxColumns(){return this._worksheet.getMaxColumns()}getMaxRows(){return this._worksheet.getMaxRows()}insertRowAfter(e){return this.insertRowsAfter(e,1)}insertRowBefore(e){return this.insertRowsBefore(e,1)}insertRows(e,t=1){return this.insertRowsBefore(e,t)}insertRowsAfter(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=a.Direction.DOWN,h=e+1,c=e+t,u=0,m=this._worksheet.getColumnCount()-1,l=i.copyRangeStyles(this._worksheet,h,c,u,m,!0,e);return this._commandService.syncExecuteCommand(i.InsertRowByRangeCommand.id,{unitId:r,subUnitId:s,direction:o,range:{startRow:h,endRow:c,startColumn:u,endColumn:m},cellValue:l}),this}insertRowsBefore(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=a.Direction.UP,h=e,c=e+t-1,u=0,m=this._worksheet.getColumnCount()-1,l=i.copyRangeStyles(this._worksheet,h,c,u,m,!0,e-1);return this._commandService.syncExecuteCommand(i.InsertRowByRangeCommand.id,{unitId:r,subUnitId:s,direction:o,range:{startRow:h,endRow:c,startColumn:u,endColumn:m},cellValue:l}),this}deleteRow(e){return this.deleteRows(e,1)}deleteRows(e,t){const r={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return this._commandService.syncExecuteCommand(i.RemoveRowByRangeCommand.id,{range:r,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}moveRows(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=p(e.getRange(),this._worksheet),h=o,c={startRow:t,endRow:t,startColumn:o.startColumn,endColumn:o.endColumn};return this._commandService.syncExecuteCommand(i.MoveRowsCommand.id,{unitId:r,subUnitId:s,range:o,fromRange:h,toRange:c}),this}hideRow(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=p(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(i.SetRowHiddenCommand.id,{unitId:t,subUnitId:r,ranges:[s]}),this}hideRows(e,t=1){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:a.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(i.SetRowHiddenCommand.id,{unitId:r,subUnitId:s,ranges:[o]}),this}unhideRow(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=p(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(i.SetSpecificRowsVisibleCommand.id,{unitId:t,subUnitId:r,ranges:[s]}),this}showRows(e,t=1){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:a.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(i.SetSpecificRowsVisibleCommand.id,{unitId:r,subUnitId:s,ranges:[o]}),this}setRowHeight(e,t){return this.setRowHeights(e,1,t)}autoFitRow(e,t=a.BooleanNumber.TRUE){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=[{startRow:e,endRow:e,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(i.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:o[0],value:a.WrapStrategy.WRAP}),this._commandService.syncExecuteCommand(i.SetWorksheetRowIsAutoHeightMutation.id,{unitId:r,subUnitId:s,ranges:o,autoHeightInfo:t}),this}setRowHeights(e,t,r){var m;const s=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=this._worksheet.getRowManager(),c=[],u=[];for(let l=e;l<e+t;l++){const g=((m=h.getRow(l))==null?void 0:m.ah)||this._worksheet.getConfig().defaultRowHeight,C={startRow:l,endRow:l,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};r<=g?c.push(C):u.push(C)}return u.length>0&&this._commandService.syncExecuteCommand(i.SetRowHeightCommand.id,{unitId:s,subUnitId:o,ranges:u,value:r}),c.length>0&&this._commandService.syncExecuteCommand(i.SetWorksheetRowIsAutoHeightCommand.id,{unitId:s,subUnitId:o,ranges:c}),this}setRowAutoHeight(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(i.SetWorksheetRowIsAutoHeightCommand.id,{unitId:r,subUnitId:s,ranges:o}),this}setRowHeightsForced(e,t,r){const s=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(i.SetRowHeightCommand.id,{unitId:s,subUnitId:o,ranges:h,value:r}),this}setRowCustom(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={};for(const[h,c]of Object.entries(e))s[Number(h)]={custom:c};const o={unitId:t,subUnitId:r,rowData:s};return this._commandService.syncExecuteCommand(i.SetRowDataCommand.id,o),this}insertColumnAfter(e){return this.insertColumnsAfter(e,1)}insertColumnBefore(e){return this.insertColumnsBefore(e,1)}insertColumns(e,t=1){return this.insertColumnsBefore(e,t)}insertColumnsAfter(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=a.Direction.RIGHT,h=0,c=this._worksheet.getRowCount()-1,u=e+1,m=e+t,l=i.copyRangeStyles(this._worksheet,h,c,u,m,!1,e);return this._commandService.syncExecuteCommand(i.InsertColByRangeCommand.id,{unitId:r,subUnitId:s,direction:o,range:{startRow:h,endRow:c,startColumn:u,endColumn:m},cellValue:l}),this}insertColumnsBefore(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=a.Direction.LEFT,h=0,c=this._worksheet.getRowCount()-1,u=e,m=e+t-1,l=i.copyRangeStyles(this._worksheet,h,c,u,m,!1,e-1);return this._commandService.syncExecuteCommand(i.InsertColByRangeCommand.id,{unitId:r,subUnitId:s,direction:o,range:{startRow:h,endRow:c,startColumn:u,endColumn:m},cellValue:l}),this}deleteColumn(e){return this.deleteColumns(e,1)}deleteColumns(e,t){const r={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1};return this._commandService.syncExecuteCommand(i.RemoveColByRangeCommand.id,{range:r,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}moveColumns(e,t){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o=y(e.getRange(),this._worksheet),h=o,c={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return this._commandService.syncExecuteCommand(i.MoveColsCommand.id,{unitId:r,subUnitId:s,range:o,fromRange:h,toRange:c}),this}hideColumn(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=y(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(i.SetColHiddenCommand.id,{unitId:t,subUnitId:r,ranges:[s]}),this}hideColumns(e,t=1){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:a.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(i.SetColHiddenCommand.id,{unitId:r,subUnitId:s,ranges:[o]}),this}unhideColumn(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=y(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(i.SetSpecificColsVisibleCommand.id,{unitId:t,subUnitId:r,ranges:[s]}),this}showColumns(e,t=1){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:a.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(i.SetSpecificColsVisibleCommand.id,{unitId:r,subUnitId:s,ranges:[o]}),this}setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}setColumnWidths(e,t,r){const s=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return this._commandService.syncExecuteCommand(i.SetColWidthCommand.id,{unitId:s,subUnitId:o,ranges:h,value:r}),this}setColumnCustom(e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={};for(const[h,c]of Object.entries(e))s[Number(h)]={custom:c};const o={unitId:t,subUnitId:r,columnData:s};return this._commandService.syncExecuteCommand(i.SetColDataCommand.id,o),this}getMergedRanges(){return this._worksheet.getSnapshot().mergeData.map(t=>this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,t))}getCellMergeData(e,t){const s=this._worksheet.getMergedCell(e,t);if(s)return this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,s)}getActiveRange(){return this._fWorkbook.getActiveRange()}setActiveRange(e){const{unitId:t,sheetId:r}=e.getRange();if(t!==this._workbook.getUnitId()||r!==this._worksheet.getSheetId())throw new Error("Specified range must be part of the sheet.");return this._fWorkbook.setActiveRange(e),this}setFreeze(e){return this._logService.warn("setFreeze is deprecated, use setFrozenRows and setFrozenColumns instead"),this._commandService.syncExecuteCommand(i.SetFrozenCommand.id,{...e,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}cancelFreeze(){return this._commandService.syncExecuteCommand(i.CancelFrozenCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}getFreeze(){return this._worksheet.getFreeze()}setFrozenColumns(...e){const t=this.getFreeze();if(arguments.length===1){const r=e[0];this.setFreeze({...t,startColumn:r>0?r:-1,xSplit:r})}else if(arguments.length===2){let[r=0,s=0]=e;r>s&&([r,s]=[s,r]),this._commandService.syncExecuteCommand(i.SetFrozenCommand.id,{startColumn:s+1,xSplit:s-r+1,startRow:t.startRow,ySplit:t.ySplit,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}return this}setFrozenRows(...e){const t=this.getFreeze();if(arguments.length===1){const r=e[0];this.setFreeze({...t,startRow:r>0?r:-1,ySplit:r})}else if(arguments.length===2){let[r=0,s=0]=e;r>s&&([r,s]=[s,r]),this._commandService.syncExecuteCommand(i.SetFrozenCommand.id,{startRow:s+1,ySplit:s-r+1,startColumn:t.startColumn,xSplit:t.xSplit,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}return this}getFrozenColumns(){const e=this.getFreeze();return e.startColumn===-1?0:e.startColumn}getFrozenRows(){const e=this.getFreeze();return e.startRow===-1?0:e.startRow}getFrozenRowRange(){const e=this._worksheet.getFreeze();return{startRow:e.startRow-e.ySplit,endRow:e.startRow-1}}getFrozenColumnRange(){const e=this._worksheet.getFreeze();return{startColumn:e.startColumn-e.xSplit,endColumn:e.startColumn-1}}hasHiddenGridLines(){return this._worksheet.getConfig().showGridlines===a.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.syncExecuteCommand(i.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?a.BooleanNumber.FALSE:a.BooleanNumber.TRUE}),this}setGridLinesColor(e){return this._commandService.syncExecuteCommand(i.SetGridlinesColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getGridLinesColor(){return this._worksheet.getGridlinesColor()}setTabColor(e){return this._commandService.syncExecuteCommand(i.SetTabColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getTabColor(){return this._worksheet.getTabColor()}onCellDataChange(e){return this._injector.get(a.ICommandService).onCommandExecuted(r=>{if(r.id===i.SetRangeValuesMutation.id){const s=r.params;s.unitId===this._workbook.getUnitId()&&s.subUnitId===this._worksheet.getSheetId()&&s.cellValue&&e(new a.ObjectMatrix(s.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(a.ICommandService).beforeCommandExecuted(r=>{if(r.id===i.SetRangeValuesMutation.id){const s=r.params;s.unitId===this._workbook.getUnitId()&&s.subUnitId===this._worksheet.getSheetId()&&s.cellValue&&e(new a.ObjectMatrix(s.cellValue))}})}hideSheet(){const e=this._injector.get(a.ICommandService);if(this._workbook.getSheets().filter(o=>o.isSheetHidden()!==a.BooleanNumber.TRUE).length<=1)throw new Error("Cannot hide the only visible sheet");return e.syncExecuteCommand(i.SetWorksheetHideCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}showSheet(){return this._injector.get(a.ICommandService).syncExecuteCommand(i.SetWorksheetShowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}isSheetHidden(){return this._worksheet.isSheetHidden()===a.BooleanNumber.TRUE}setName(e){return this._commandService.syncExecuteCommand(i.SetWorksheetNameCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),name:e}),this}activate(){return this._fWorkbook.setActiveSheet(this),this}getIndex(){return this._workbook.getSheetIndex(this._worksheet)}clear(e){e&&e.contentsOnly&&!e.formatOnly&&this.clearContents(),e&&e.formatOnly&&!e.contentsOnly&&this.clearFormats();const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=this._injector.get(a.ICommandService),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return s.syncExecuteCommand(i.ClearSelectionAllCommand.id,{unitId:t,subUnitId:r,ranges:[o],options:e}),this}clearContents(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),r=this._injector.get(a.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return r.syncExecuteCommand(i.ClearSelectionContentCommand.id,{unitId:e,subUnitId:t,ranges:[s]}),this}clearFormats(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),r=this._injector.get(a.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return r.syncExecuteCommand(i.ClearSelectionFormatCommand.id,{unitId:e,subUnitId:t,ranges:[s]}),this}getDataRange(){const e=this.getLastRows(),t=this.getLastColumns();return this.getRange(0,0,e+1,t+1)}getLastColumns(){return this._worksheet.getLastColumnWithContent()}getLastColumn(){return this._worksheet.getLastColumnWithContent()}getLastRows(){return this._worksheet.getLastRowWithContent()}getLastRow(){return this._worksheet.getLastRowWithContent()}equalTo(e){return e instanceof exports.FWorksheet?this._worksheet.getSheetId()===e.getSheetId()&&this._workbook.getUnitId()===e.getWorkbook().getUnitId():!1}insertDefinedName(e,t){const s=this._injector.createInstance(b).setName(e).setRef(t).build();s.localSheetId=this.getSheetId(),this._fWorkbook.insertDefinedNameBuilder(s)}getDefinedNames(){return this._fWorkbook.getDefinedNames().filter(t=>t.getLocalSheetId()===this.getSheetId())}setCustomMetadata(e){return this._worksheet.setCustomMetadata(e),this}setRowCustomMetadata(e,t){return this._worksheet.getRowManager().setCustomMetadata(e,t),this}setColumnCustomMetadata(e,t){return this._worksheet.getColumnManager().setCustomMetadata(e,t),this}getRowCustomMetadata(e){return this._worksheet.getRowManager().getCustomMetadata(e)}getColumnCustomMetadata(e){return this._worksheet.getColumnManager().getCustomMetadata(e)}getMergeData(){return this._worksheet.getMergeData().map(e=>this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,e))}};exports.FWorksheet=Z([f(3,a.Inject(a.Injector)),f(4,a.Inject(i.SheetsSelectionsService)),f(5,a.Inject(a.ILogService)),f(6,a.ICommandService)],exports.FWorksheet);var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(d,n,e,t)=>{for(var r=t>1?void 0:t?te(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&ee(n,e,r),r},S=(d,n)=>(e,t)=>n(e,t,d);exports.FWorkbook=class extends a.FBaseInitialable{constructor(e,t,r,s,o,h,c,u,m,l){super(t);w(this,"id");this._workbook=e,this._injector=t,this._resourceLoaderService=r,this._selectionManagerService=s,this._univerInstanceService=o,this._commandService=h,this._permissionService=c,this._logService=u,this._localeService=m,this._definedNamesService=l,this.id=this._workbook.getUnitId()}getWorkbook(){return this._workbook}getId(){return this.id}getName(){return this._workbook.name}setName(e){this._workbook.setName(e)}save(){return this._resourceLoaderService.saveUnit(this._workbook.getUnitId())}getSnapshot(){return this._logService.warn("use 'save' instead of 'getSnapshot'"),this.save()}getActiveSheet(){const e=this._workbook.getActiveSheet();return this._injector.createInstance(exports.FWorksheet,this,this._workbook,e)}getSheets(){return this._workbook.getSheets().map(e=>this._injector.createInstance(exports.FWorksheet,this,this._workbook,e))}create(e,t,r){const s=a.mergeWorksheetSnapshotWithDefault({});s.rowCount=t,s.columnCount=r,s.name=e,s.id=e.toLowerCase().replace(/ /g,"-"),this._commandService.syncExecuteCommand(i.InsertSheetCommand.id,{unitId:this.id,index:this._workbook.getSheets().length,sheet:s}),this._commandService.syncExecuteCommand(i.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId()});const o=this._workbook.getActiveSheet();if(!o)throw new Error("No active sheet found");return this._injector.createInstance(exports.FWorksheet,this,this._workbook,o)}getSheetBySheetId(e){const t=this._workbook.getSheetBySheetId(e);return t?this._injector.createInstance(exports.FWorksheet,this,this._workbook,t):null}getSheetByName(e){const t=this._workbook.getSheetBySheetName(e);return t?this._injector.createInstance(exports.FWorksheet,this,this._workbook,t):null}setActiveSheet(e){return this._commandService.syncExecuteCommand(i.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:typeof e=="string"?e:e.getSheetId()}),typeof e=="string"?this.getSheetBySheetId(e):e}insertSheet(e){e!=null?this._commandService.syncExecuteCommand(i.InsertSheetCommand.id,{sheet:{name:e}}):this._commandService.syncExecuteCommand(i.InsertSheetCommand.id);const t=this.id,r=this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId();this._commandService.syncExecuteCommand(i.SetWorksheetActiveOperation.id,{unitId:t,subUnitId:r});const s=this._workbook.getActiveSheet();if(!s)throw new Error("No active sheet found");return this._injector.createInstance(exports.FWorksheet,this,this._workbook,s)}deleteSheet(e){const t=this.id,r=typeof e=="string"?e:e.getSheetId();return this._commandService.syncExecuteCommand(i.RemoveSheetCommand.id,{unitId:t,subUnitId:r})}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(a.UndoCommand.id),this}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(a.RedoCommand.id),this}onBeforeCommandExecute(e){return this._commandService.beforeCommandExecuted(t=>{var r;((r=t.params)==null?void 0:r.unitId)===this.id&&e(t)})}onCommandExecuted(e){return this._commandService.onCommandExecuted(t=>{var r;((r=t.params)==null?void 0:r.unitId)===this.id&&e(t)})}onSelectionChange(e){return a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(t=>{this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()===this.id&&(t!=null&&t.length?e(t.map(r=>r.range)):e([]))}))}setEditable(e){const t=new i.WorkbookEditablePermission(this._workbook.getUnitId());return this._permissionService.getPermissionPoint(t.id)||this._permissionService.addPermissionPoint(t),this._permissionService.updatePermissionPoint(t.id,e),this}setActiveRange(e){const t=this.getActiveSheet(),r=e.getRange().sheetId||t.getSheetId(),s=r?this._workbook.getSheetBySheetId(r):this._workbook.getActiveSheet(!0);if(!s)throw new Error("No active sheet found");s.getSheetId()!==t.getSheetId()&&this.setActiveSheet(this._injector.createInstance(exports.FWorksheet,this,this._workbook,s));const o={unitId:this.getId(),subUnitId:r,selections:[e].map(h=>({range:h.getRange(),primary:i.getPrimaryForRange(h.getRange(),s),style:null}))};return this._commandService.syncExecuteCommand(i.SetSelectionsOperation.id,o),this}getActiveRange(){const e=this._workbook.getActiveSheet(),r=this._selectionManagerService.getCurrentSelections().find(s=>!!s.primary);return r?this._injector.createInstance(exports.FRange,this._workbook,e,r.range):null}deleteActiveSheet(){const e=this.getActiveSheet();return this.deleteSheet(e)}duplicateSheet(e){return this._commandService.syncExecuteCommand(i.CopySheetCommand.id,{unitId:e.getWorkbook().getUnitId(),subUnitId:e.getSheetId()}),this._injector.createInstance(exports.FWorksheet,this,this._workbook,this._workbook.getActiveSheet())}duplicateActiveSheet(){const e=this.getActiveSheet();return this.duplicateSheet(e)}getNumSheets(){return this._workbook.getSheets().length}getLocale(){return this._localeService.getCurrentLocale()}setLocale(e){this._localeService.setLocale(e)}setSpreadsheetLocale(e){return this._localeService.setLocale(e),this}getUrl(){return location.href}moveSheet(e,t){let r=t;return r<0?r=0:r>this._workbook.getSheets().length-1&&(r=this._workbook.getSheets().length-1),this._commandService.syncExecuteCommand(i.SetWorksheetOrderCommand.id,{unitId:e.getWorkbook().getUnitId(),order:r,subUnitId:e.getSheetId()}),this}moveActiveSheet(e){const t=this.getActiveSheet();return this.moveSheet(t,e)}getPermission(){return this._injector.createInstance(exports.FPermission)}getDefinedName(e){const t=this._definedNamesService.getValueByName(this.id,e);return t?this._injector.createInstance(I,{...t,unitId:this.id}):null}getDefinedNames(){const e=this._definedNamesService.getDefinedNameMap(this.id);return e?Object.values(e).map(t=>this._injector.createInstance(I,{...t,unitId:this.id})):[]}insertDefinedName(e,t){const s=this._injector.createInstance(b).setName(e).setRef(t).build();return s.localSheetId=i.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this.insertDefinedNameBuilder(s),this}deleteDefinedName(e){const t=this.getDefinedName(e);return t?(t.delete(),!0):!1}insertDefinedNameBuilder(e){e.unitId=this.getId(),this._commandService.syncExecuteCommand(i.SetDefinedNameCommand.id,e)}updateDefinedNameBuilder(e){this._commandService.syncExecuteCommand(i.SetDefinedNameCommand.id,e)}getRegisteredRangeThemes(){return this._injector.get(i.SheetRangeThemeService).getRegisteredRangeThemes()}registerRangeTheme(e){this._commandService.syncExecuteCommand(i.RegisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),rangeThemeStyle:e})}unregisterRangeTheme(e){this._commandService.syncExecuteCommand(i.UnregisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),themeName:e})}createRangeThemeStyle(e,t){return new i.RangeThemeStyle(e,t)}setCustomMetadata(e){return this._workbook.setCustomMetadata(e),this}getCustomMetadata(){return this._workbook.getCustomMetadata()}};exports.FWorkbook=ne([S(1,a.Inject(a.Injector)),S(2,a.Inject(a.IResourceLoaderService)),S(3,a.Inject(i.SheetsSelectionsService)),S(4,a.IUniverInstanceService),S(5,a.ICommandService),S(6,a.IPermissionService),S(7,a.ILogService),S(8,a.Inject(a.LocaleService)),S(9,k.IDefinedNamesService)],exports.FWorkbook);class re extends a.FUniver{getCommandSheetTarget(n){var s;const e=n.params;if(!e)return;const t=e.unitId?this.getUniverSheet(e.unitId):(s=this.getActiveWorkbook)==null?void 0:s.call(this);if(!t)return;const r=t.getSheetBySheetId(e.subUnitId||e.sheetId)||t.getActiveSheet();if(r)return{workbook:t,worksheet:r}}getSheetTarget(n,e){const t=this.getUniverSheet(n);if(!t)return;const r=t.getSheetBySheetId(e);if(r)return{workbook:t,worksheet:r}}_initWorkbookEvent(n){const e=n.get(a.IUniverInstanceService);this.disposeWithMe(e.unitDisposed$.subscribe(t=>{this._eventRegistry.get(this.Event.WorkbookDisposed)&&t.type===a.UniverInstanceType.UNIVER_SHEET&&this.fireEvent(this.Event.WorkbookDisposed,{unitId:t.getUnitId(),unitType:t.type,snapshot:t.getSnapshot()})})),this.disposeWithMe(e.unitAdded$.subscribe(t=>{if(this._eventRegistry.get(this.Event.WorkbookCreated)&&t.type===a.UniverInstanceType.UNIVER_SHEET){const r=t,s=n.createInstance(exports.FWorkbook,r);this.fireEvent(this.Event.WorkbookCreated,{unitId:t.getUnitId(),type:t.type,workbook:s,unit:s})}}))}_initialize(n){const e=n.get(a.ICommandService);this.disposeWithMe(e.beforeCommandExecuted(t=>{var r,s,o,h;switch(t.id){case i.InsertSheetCommand.id:{const c=t.params,{unitId:u,index:m,sheet:l}=c||{},g=u?this.getUniverSheet(u):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!g)return;const C={workbook:g,index:m,sheet:l};if(this.fireEvent(this.Event.BeforeSheetCreate,C),C.cancel)throw new a.CanceledError;break}case i.SetWorksheetActivateCommand.id:{if(!this._eventListend(this.Event.BeforeActiveSheetChange))return;const{subUnitId:c,unitId:u}=t.params,m=u?this.getUniverSheet(u):(s=this.getActiveWorkbook)==null?void 0:s.call(this);if(!m||!c)return;const l=m.getSheetBySheetId(c),g=m.getActiveSheet();if(!l||!g)return;this._fireBeforeActiveSheetChange(m,l,g);break}case i.RemoveSheetCommand.id:{if(!this._eventListend(this.Event.BeforeSheetDelete))return;const c=this.getCommandSheetTarget(t);if(!c)return;const{workbook:u,worksheet:m}=c;this._fireBeforeSheetDelete(u,m);break}case i.SetWorksheetOrderCommand.id:{if(!this._eventListend(this.Event.BeforeSheetMove))return;const{fromOrder:c,toOrder:u}=t.params,m=this.getCommandSheetTarget(t);if(!m)return;this._fireBeforeSheetMove(m.workbook,m.worksheet,u,c);break}case i.SetWorksheetNameCommand.id:{if(!this._eventListend(this.Event.BeforeSheetNameChange))return;const{name:c}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetNameChange(u.workbook,u.worksheet,c,u.worksheet.getSheetName());break}case i.SetTabColorCommand.id:{if(!this._eventListend(this.Event.BeforeSheetTabColorChange))return;const{color:c}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetTabColorChange(u.workbook,u.worksheet,c,u.worksheet.getTabColor());break}case i.SetWorksheetHideCommand.id:{if(!this._eventListend(this.Event.BeforeSheetHideChange))return;const{hidden:c}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetHideChange(u.workbook,u.worksheet,!!c);break}case i.SetGridlinesColorCommand.id:{if(!this._eventListend(this.Event.BeforeGridlineColorChange))return;const c=this.getCommandSheetTarget(t);if(!c)return;this.fireEvent(this.Event.BeforeGridlineColorChange,{...c,color:(o=t.params)==null?void 0:o.color});break}case i.ToggleGridlinesCommand.id:{if(!this._eventListend(this.Event.BeforeGridlineEnableChange))return;const c=this.getCommandSheetTarget(t);if(!c)return;this.fireEvent(this.Event.BeforeGridlineEnableChange,{...c,enabled:!!((h=t.params)!=null&&h.showGridlines)});break}}})),this.disposeWithMe(e.onCommandExecuted(t=>{var r,s;if(i.COMMAND_LISTENER_VALUE_CHANGE.indexOf(t.id)>-1){if(!this._eventListend(this.Event.SheetValueChanged)||!this.getActiveSheet())return;const h=i.getValueChangedEffectedRange(t).map(c=>{var u,m;return(m=(u=this.getWorkbook(c.unitId))==null?void 0:u.getSheetBySheetId(c.subUnitId))==null?void 0:m.getRange(c.range)}).filter(Boolean);if(!h.length)return;this.fireEvent(this.Event.SheetValueChanged,{payload:t,effectedRanges:h});return}switch(t.id){case i.InsertSheetCommand.id:{const o=t.params,{unitId:h}=o||{},c=h?this.getUniverSheet(h):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!c)return;const u=c.getActiveSheet();if(!u)return;const m={workbook:c,worksheet:u};this.fireEvent(this.Event.SheetCreated,m);break}case i.SetWorksheetActivateCommand.id:{if(!this._eventListend(this.Event.ActiveSheetChanged))return;const o=this.getActiveSheet();if(!o)return;const{workbook:h,worksheet:c}=o;this._fireActiveSheetChanged(h,c);break}case i.RemoveSheetCommand.id:{if(!this._eventListend(this.Event.SheetDeleted))return;const{subUnitId:o,unitId:h}=t.params,c=h?this.getUniverSheet(h):(s=this.getActiveWorkbook)==null?void 0:s.call(this);if(!c||!o)return;this._fireSheetDeleted(c,o);break}case i.SetWorksheetOrderCommand.id:{if(!this._eventListend(this.Event.SheetMoved))return;const{toOrder:o}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetMoved(h.workbook,h.worksheet,o);break}case i.SetWorksheetNameCommand.id:{if(!this._eventListend(this.Event.SheetNameChanged))return;const{name:o}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetNameChanged(h.workbook,h.worksheet,o);break}case i.SetTabColorCommand.id:{if(!this._eventListend(this.Event.SheetTabColorChanged))return;const{color:o}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetTabColorChanged(h.workbook,h.worksheet,o);break}case i.SetWorksheetHideCommand.id:{if(!this._eventListend(this.Event.SheetHideChanged))return;const{hidden:o}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetHideChanged(h.workbook,h.worksheet,!!o);break}case i.SetGridlinesColorCommand.id:case i.ToggleGridlinesCommand.id:{if(!this._eventListend(this.Event.GridlineChanged))return;const o=this.getCommandSheetTarget(t);if(!o)return;this.fireEvent(this.Event.GridlineChanged,{...o,enabled:!o.worksheet.hasHiddenGridLines(),color:o.worksheet.getGridLinesColor()});break}}})),this._initWorkbookEvent(n)}createUniverSheet(n){const t=this._injector.get(a.IUniverInstanceService).createUnit(a.UniverInstanceType.UNIVER_SHEET,n);return this._injector.createInstance(exports.FWorkbook,t)}createWorkbook(n){return this.createUniverSheet(n)}getActiveWorkbook(){const n=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return n?this._injector.createInstance(exports.FWorkbook,n):null}getActiveUniverSheet(){return this.getActiveWorkbook()}getUniverSheet(n){const e=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET);return e?this._injector.createInstance(exports.FWorkbook,e):null}getWorkbook(n){return this.getUniverSheet(n)}getPermission(){return this._injector.createInstance(exports.FPermission)}onUniverSheetCreated(n){const e=this._univerInstanceService.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{const r=this._injector.createInstance(exports.FWorkbook,t);n(r)});return a.toDisposable(e)}newDefinedName(){return this._injector.createInstance(b)}getActiveSheet(){const n=this.getActiveWorkbook();if(!n)return null;const e=n.getActiveSheet();return e?{workbook:n,worksheet:e}:null}_fireBeforeActiveSheetChange(n,e,t){this.fireEvent(this.Event.BeforeActiveSheetChange,{workbook:n,activeSheet:e,oldActiveSheet:t})}_fireActiveSheetChanged(n,e){this.fireEvent(this.Event.ActiveSheetChanged,{workbook:n,activeSheet:e})}_fireBeforeSheetDelete(n,e){this.fireEvent(this.Event.BeforeSheetDelete,{workbook:n,worksheet:e})}_fireSheetDeleted(n,e){this.fireEvent(this.Event.SheetDeleted,{workbook:n,sheetId:e})}_fireBeforeSheetMove(n,e,t,r){this.fireEvent(this.Event.BeforeSheetMove,{workbook:n,worksheet:e,newIndex:t,oldIndex:r})}_fireSheetMoved(n,e,t){this.fireEvent(this.Event.SheetMoved,{workbook:n,worksheet:e,newIndex:t})}_fireBeforeSheetNameChange(n,e,t,r){this.fireEvent(this.Event.BeforeSheetNameChange,{workbook:n,worksheet:e,newName:t,oldName:r})}_fireSheetNameChanged(n,e,t){this.fireEvent(this.Event.SheetNameChanged,{workbook:n,worksheet:e,newName:t})}_fireBeforeSheetTabColorChange(n,e,t,r){this.fireEvent(this.Event.BeforeSheetTabColorChange,{workbook:n,worksheet:e,newColor:t,oldColor:r})}_fireSheetTabColorChanged(n,e,t){this.fireEvent(this.Event.SheetTabColorChanged,{workbook:n,worksheet:e,newColor:t})}_fireBeforeSheetHideChange(n,e,t){this.fireEvent(this.Event.BeforeSheetHideChange,{workbook:n,worksheet:e,hidden:t})}_fireSheetHideChanged(n,e,t){this.fireEvent(this.Event.SheetHideChanged,{workbook:n,worksheet:e,hidden:t})}}a.FUniver.extend(re);class P{get SheetValueChangeType(){return i.SheetValueChangeType}get SheetSkeletonChangeType(){return i.SheetSkeletonChangeType}}a.FEnum.extend(P);class N extends a.FEventName{get SheetCreated(){return"SheetCreated"}get BeforeSheetCreate(){return"BeforeSheetCreate"}get WorkbookCreated(){return"WorkbookCreated"}get WorkbookDisposed(){return"WorkbookDisposed"}get GridlineChanged(){return"GridlineChanged"}get BeforeGridlineEnableChange(){return"BeforeGridlineEnableChange"}get BeforeGridlineColorChange(){return"BeforeGridlineColorChange"}get BeforeActiveSheetChange(){return"BeforeActiveSheetChange"}get ActiveSheetChanged(){return"ActiveSheetChanged"}get SheetDeleted(){return"SheetDeleted"}get BeforeSheetDelete(){return"BeforeSheetDelete"}get SheetMoved(){return"SheetMoved"}get BeforeSheetMove(){return"BeforeSheetMove"}get SheetNameChanged(){return"SheetNameChanged"}get BeforeSheetNameChange(){return"BeforeSheetNameChange"}get SheetTabColorChanged(){return"SheetTabColorChanged"}get BeforeSheetTabColorChange(){return"BeforeSheetTabColorChange"}get SheetHideChanged(){return"SheetHideChanged"}get BeforeSheetHideChange(){return"BeforeSheetHideChange"}get SheetValueChanged(){return"SheetValueChanged"}}a.FEventName.extend(N);var se=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,ie=(d,n,e,t)=>{for(var r=t>1?void 0:t?oe(n,e):n,s=d.length-1,o;s>=0;s--)(o=d[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&se(n,e,r),r},ae=(d,n)=>(e,t)=>n(e,t,d);exports.FSheetHooks=class extends a.FBase{constructor(n){super(),this._injector=n}};exports.FSheetHooks=ie([ae(0,a.Inject(a.Injector))],exports.FSheetHooks);exports.FSheetEventName=N;exports.FSheetsEnum=P;

@@ -5,2 +5,5 @@ import { FWorksheet } from './f-worksheet';

import { RangeProtectionRuleModel, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets';
/**
* @hideconstructor
*/
export declare class FDefinedNameBuilder {

@@ -17,4 +20,4 @@ private _definedNameParam;

* const definedNameBuilder = univerAPI.newDefinedName()
* .setName('MyDefinedName')
* .build();
* .setName('MyDefinedName')
* .build();
* workbook.insertDefinedNameBuilder(definedNameBuilder);

@@ -32,5 +35,5 @@ * ```

* const definedNameBuilder = univerAPI.newDefinedName()
* .setFormula('SUM(Sheet1!$A$1)')
* .setName('MyDefinedName')
* .build();
* .setFormula('SUM(Sheet1!$A$1)')
* .setName('MyDefinedName')
* .build();
* workbook.insertDefinedNameBuilder(definedNameBuilder);

@@ -48,4 +51,4 @@ * ```

* const definedNameBuilder = univerAPI.newDefinedName()
* .setRef('Sheet1!$A$1')
* .build();
* .setRef('Sheet1!$A$1')
* .build();
* workbook.insertDefinedNameBuilder(definedNameBuilder);

@@ -66,4 +69,4 @@ * ```

* const definedNameBuilder = univerAPI.newDefinedName()
* .setRefByRange(1, 3, 2, 5)
* .build();
* .setRefByRange(1, 3, 2, 5)
* .build();
* workbook.insertDefinedNameBuilder(definedNameBuilder);

@@ -81,4 +84,4 @@ * ```

* const definedNameBuilder = univerAPI.newDefinedName()
* .setComment('This is a comment')
* .build();
* .setComment('This is a comment')
* .build();
* workbook.insertDefinedNameBuilder(definedNameBuilder);

@@ -96,4 +99,4 @@ * ```

* const definedNameBuilder = univerAPI.newDefinedName()
* .setHidden(true)
* .build();
* .setHidden(true)
* .build();
* workbook.insertDefinedNameBuilder(definedNameBuilder);

@@ -110,5 +113,5 @@ * ```

* const definedNameBuilder = univerAPI.newDefinedName()
* .setRef('Sheet1!$A$1')
* .setName('MyDefinedName')
* .build();
* .setRef('Sheet1!$A$1')
* .setName('MyDefinedName')
* .build();
* workbook.insertDefinedNameBuilder(definedNameBuilder);

@@ -120,2 +123,5 @@ * ```

}
/**
* @hideconstructor
*/
export declare class FDefinedName extends FBase {

@@ -122,0 +128,0 @@ protected _definedNameParam: ISetDefinedNameMutationParam;

import { SheetSkeletonChangeType, SheetValueChangeType } from '@univerjs/sheets';
/**
* @ignore
*/
export interface IFSheetsEnum {

@@ -3,0 +6,0 @@ /**

@@ -9,2 +9,3 @@ import { IEventBase, IWorkbookData, IWorksheetData, UniverInstanceType, FEventName } from '@univerjs/core';

* Provides event names for sheet creation, workbook creation, and gridline changes
* @ignore
*/

@@ -17,6 +18,6 @@ export interface IFSheetEventMixin {

* ```ts
univerAPI.addEvent(univerAPI.Event.SheetCreated, (params) => {
const { workbook, worksheet } = params;
console.log('sheet created', params);
});
* univerAPI.addEvent(univerAPI.Event.SheetCreated, (params) => {
* const { workbook, worksheet } = params;
* console.log('sheet created', params);
* });
* ```

@@ -31,4 +32,4 @@ */

* univerAPI.addEvent(univerAPI.Event.BeforeSheetCreate, (params) => {
* const { workbook, index, sheet } = params;
* console.log('before sheet create', params);
* const { workbook, index, sheet } = params;
* console.log('before sheet create', params);
* });

@@ -44,4 +45,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.ActiveSheetChanged, (params) => {
* const { workbook, activeSheet, oldActiveSheet } = params;
* console.log('before active sheet changed', params);
* const { workbook, activeSheet, oldActiveSheet } = params;
* console.log('before active sheet changed', params);
* });

@@ -57,4 +58,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.ActiveSheetChanged, (params) => {
* const { workbook, activeSheet } = params;
* console.log('after active sheet changed', params);
* const { workbook, activeSheet } = params;
* console.log('after active sheet changed', params);
* });

@@ -70,4 +71,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.BeforeSheetDelete, (params) => {
* const { workbook, worksheetId } = params;
* console.log('before sheet delete', params);
* const { workbook, worksheetId } = params;
* console.log('before sheet delete', params);
* });

@@ -83,4 +84,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.BeforeSheetDelete, (params) => {
* const { workbook, worksheet } = params;
* console.log('before sheet delete', params);
* const { workbook, worksheet } = params;
* console.log('before sheet delete', params);
* });

@@ -96,4 +97,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.SheetMoved, (params) => {
* const { workbook, worksheet, newIndex } = params;
* console.log('sheet moved', params);
* const { workbook, worksheet, newIndex } = params;
* console.log('sheet moved', params);
* });

@@ -109,4 +110,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.BeforeSheetMove, (params) => {
* const { workbook, worksheet, newIndex, oldIndex } = params;
* console.log('before sheet move', params);
* const { workbook, worksheet, newIndex, oldIndex } = params;
* console.log('before sheet move', params);
* });

@@ -122,4 +123,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.SheetNameChanged, (params) => {
* const { workbook, worksheet, newName } = params;
* console.log('sheet name changed', params);
* const { workbook, worksheet, newName } = params;
* console.log('sheet name changed', params);
* });

@@ -135,4 +136,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.BeforeSheetNameChange, (params) => {
* const { workbook, worksheet, newName, oldName } = params;
* console.log('before sheet name changed', params);
* const { workbook, worksheet, newName, oldName } = params;
* console.log('before sheet name changed', params);
* });

@@ -148,4 +149,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.SheetTabColorChanged, (params) => {
* const { workbook, worksheet, color } = params;
* console.log('sheet tab color changed', params);
* const { workbook, worksheet, color } = params;
* console.log('sheet tab color changed', params);
* });

@@ -161,4 +162,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.BeforeSheetTabColorChange, (params) => {
* const { workbook, worksheet, color, oldColor } = params;
* console.log('before sheet tab color changed', params);
* const { workbook, worksheet, color, oldColor } = params;
* console.log('before sheet tab color changed', params);
* });

@@ -174,4 +175,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.SheetHideChanged, (params) => {
* const { workbook, worksheet } = params;
* console.log('sheet hide changed', params);
* const { workbook, worksheet } = params;
* console.log('sheet hide changed', params);
* });

@@ -187,4 +188,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.BeforeSheetHideChange, (params) => {
* const { workbook, worksheet, hide } = params;
* console.log('before sheet hide changed', params);
* const { workbook, worksheet, hide } = params;
* console.log('before sheet hide changed', params);
* });

@@ -200,4 +201,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.WorkbookCreated, (params) => {
* const { unitId, type, workbook, unit } = params;
* console.log('workbook created', params);
* const { unitId, type, workbook, unit } = params;
* console.log('workbook created', params);
* });

@@ -213,4 +214,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.WorkbookDisposed, (params) => {
* const { unitId, unitType, snapshot } = params;
* console.log('unit disposed', params);
* const { unitId, unitType, snapshot } = params;
* console.log('unit disposed', params);
* });

@@ -226,4 +227,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.GridlineChanged, (params) => {
* const { workbook, worksheet, enabled, color } = params;
* console.log('gridline changed', params);
* const { workbook, worksheet, enabled, color } = params;
* console.log('gridline changed', params);
* });

@@ -239,4 +240,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.BeforeGridlineEnableChange, (params) => {
* const { workbook, worksheet, enabled } = params;
* console.log('gridline changed', params);
* const { workbook, worksheet, enabled } = params;
* console.log('gridline changed', params);
* });

@@ -252,4 +253,4 @@ * ```

* univerAPI.addEvent(univerAPI.Event.BeforeGridlineColorChange, (params) => {
* const { workbook, worksheet, color } = params;
* console.log('gridline changed', params);
* const { workbook, worksheet, color } = params;
* console.log('gridline changed', params);
* });

@@ -264,3 +265,3 @@ * ```

* univerAPI.addEvent(univerAPI.Event.SheetValueChanged, (p)=> {
* const { workbook, effectedRanges, payload } = p;
* const { workbook, effectedRanges, payload } = p;
* });

@@ -514,2 +515,3 @@ * ```

* Provides event names and their corresponding event parameter interfaces
* @ignore
*/

@@ -516,0 +518,0 @@ export interface ISheetEventParamConfig {

@@ -1,4 +0,9 @@

import { IRange, RangePermissionPointConstructor, WorkbookPermissionPointConstructor, WorkSheetPermissionPointConstructor, FBase, IAuthzIoService, ICommandService, Injector, IPermissionService } from '@univerjs/core';
import { RangePermissionPointConstructor, WorkbookPermissionPointConstructor, WorkSheetPermissionPointConstructor, FBase, IAuthzIoService, ICommandService, Injector, IPermissionService } from '@univerjs/core';
import { Observable } from 'rxjs';
import { FRange } from './f-range';
import { RangeProtectionRuleModel, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionPointModel, WorksheetProtectionRuleModel, WorksheetViewPermission } from '@univerjs/sheets';
/**
* @description Used to generate permission instances to control permissions for the entire workbook
* @hideconstructor
*/
export declare class FPermission extends FBase {

@@ -12,2 +17,5 @@ protected readonly _injector: Injector;

protected readonly _authzIoService: IAuthzIoService;
/**
* Permission point definition, can read the point constructor want to modify from here
*/
permissionPointsDefinition: {

@@ -44,4 +52,2 @@ WorkbookCommentPermission: typeof import('@univerjs/sheets').WorkbookCommentPermission;

WorksheetPivotTablePermission: typeof import('@univerjs/sheets').WorksheetPivotTablePermission;
WorksheetSelectProtectedCellsPermission: typeof import('@univerjs/sheets').WorksheetSelectProtectedCellsPermission;
WorksheetSelectUnProtectedCellsPermission: typeof import('@univerjs/sheets').WorksheetSelectUnProtectedCellsPermission;
WorksheetSetCellStylePermission: typeof import('@univerjs/sheets').WorksheetSetCellStylePermission;

@@ -56,8 +62,13 @@ WorksheetSetCellValuePermission: typeof import('@univerjs/sheets').WorksheetSetCellValuePermission;

};
rangeRuleChangedAfterAuth$: Observable<unknown>;
sheetRuleChangedAfterAuth$: Observable<unknown>;
/**
* An observable object used to monitor permission change events within a range, thereby triggering corresponding subsequent processing.
*/
rangeRuleChangedAfterAuth$: Observable<string>;
/**
* An observable object used to monitor permission change events within a worksheet, thereby triggering corresponding subsequent processing.
*/
sheetRuleChangedAfterAuth$: Observable<string>;
constructor(_injector: Injector, _commandService: ICommandService, _permissionService: IPermissionService, _worksheetProtectionRuleModel: WorksheetProtectionRuleModel, _rangeProtectionRuleModel: RangeProtectionRuleModel, _worksheetProtectionPointRuleModel: WorksheetProtectionPointModel, _authzIoService: IAuthzIoService);
/**
* Configures a specific permission point for a workbook.
*
* This function sets or updates a permission point for a workbook identified by `unitId`.

@@ -68,2 +79,10 @@ * It creates a new permission point if it does not already exist, and updates the point with the provided value.

* @param {boolean} value - The boolean value to determine whether the permission point is enabled or disabled.
*
* @example
* ```typescript
* const workbook = univerAPI.getActiveWorkbook();
* const permission = workbook.getPermission();
* const unitId = workbook.getId();
* permission.setWorkbookPermissionPoint(unitId, permission.permissionPointsDefinition.WorkbookEditablePermission, false)
* ```
*/

@@ -75,2 +94,10 @@ setWorkbookPermissionPoint(unitId: string, FPointClass: WorkbookPermissionPointConstructor, value: boolean): void;

* @param {boolean} value - A value that controls whether the workbook can be edited
*
* @example
* ```typescript
* const workbook = univerAPI.getActiveWorkbook();
* const permission = workbook.getPermission();
* const unitId = workbook.getId();
* permission.setWorkbookEditPermission(unitId, false);
* ```
*/

@@ -80,5 +107,21 @@ setWorkbookEditPermission(unitId: string, value: boolean): void;

* This function is used to add a base permission for a worksheet.
* Note that after adding, only the background mask of the permission module will be rendered. If you want to modify the function permissions,
* you need to modify the permission points with the permissionId returned by this function.
* @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
* @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
* @returns {Promise<string | undefined>} - Returns the `permissionId` if the permission is successfully added. If the operation fails or no result is returned, it resolves to `undefined`.
*
* @example
* ```typescript
* const workbook = univerAPI.getActiveWorkbook();
* const permission = workbook.getPermission();
* const unitId = workbook.getId();
* const worksheet = workbook.getActiveSheet();
* const subUnitId = worksheet.getSheetId();
* // Note that there will be no permission changes after this step is completed. It only returns an ID for subsequent permission changes.
* // For details, please see the example of the **`setWorksheetPermissionPoint`** API.
* const permissionId = await permission.addWorksheetBasePermission(unitId, subUnitId)
* // Can still edit and read it.
* console.log('debugger', permissionId)
* ```
*/

@@ -90,2 +133,12 @@ addWorksheetBasePermission(unitId: string, subUnitId: string): Promise<string | undefined>;

* @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
*
* @example
* ```typescript
* const workbook = univerAPI.getActiveWorkbook();
* const permission = workbook.getPermission();
* const unitId = workbook.getId();
* const worksheet = workbook.getActiveSheet();
* const subUnitId = worksheet.getSheetId();
* permission.removeWorksheetPermission(unitId, subUnitId);
* ```
*/

@@ -102,2 +155,13 @@ removeWorksheetPermission(unitId: string, subUnitId: string): void;

* @returns {Promise<string | undefined>} - Returns the `permissionId` if the permission point is successfully set or created. If no permission is set, it resolves to `undefined`.
*
* @example
* ```typescript
* const workbook = univerAPI.getActiveWorkbook();
* const permission = workbook.getPermission();
* const unitId = workbook.getId();
* const worksheet = workbook.getActiveSheet();
* const subUnitId = worksheet.getSheetId();
* const permissionId = await permission.addWorksheetBasePermission(unitId, subUnitId)
* // After this line of code , the worksheet will no longer be editable
* permission.setWorksheetPermissionPoint(unitId, subUnitId, permission.permissionPointsDefinition.WorksheetEditPermission, false);
*/

@@ -107,8 +171,27 @@ setWorksheetPermissionPoint(unitId: string, subUnitId: string, FPointClass: WorkSheetPermissionPointConstructor, value: boolean): Promise<string | undefined>;

* Adds a range protection to the worksheet.
* Note that after adding, only the background mask of the permission module will be rendered. If you want to modify the function permissions,
* you need to modify the permission points with the permissionId returned by this function.
* @param {string} unitId - The unique identifier of the workbook.
* @param {string} subUnitId - The unique identifier of the worksheet.
* @param {IRange[]} ranges - The ranges to be protected.
* @param {FRange[]} ranges - The ranges to be protected.
* @returns {Promise<{ permissionId: string, ruleId: string } | undefined>} - Returns an object containing the `permissionId` and `ruleId` if the range protection is successfully added. If the operation fails or no result is returned, it resolves to `undefined`. permissionId is used to stitch permission point ID,ruleId is used to store permission rules
*
* @example
* ```typescript
*const workbook = univerAPI.getActiveWorkbook();
* const permission = workbook.getPermission();
* const unitId = workbook.getId();
* const worksheet = workbook.getActiveSheet();
* const subUnitId = worksheet.getSheetId();
* const range = worksheet.getRange(0,0,2,2);
* const ranges = [];
* ranges.push(range);
* // Note that there will be no permission changes after this step is completed. It only returns an ID for subsequent permission changes.
* // For details, please see the example of the **`setRangeProtectionPermissionPoint`** API.
* const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
* const {permissionId, ruleId} = res;
* console.log('debugger', permissionId, ruleId);
* ```
*/
addRangeBaseProtection(unitId: string, subUnitId: string, ranges: IRange[]): Promise<{
addRangeBaseProtection(unitId: string, subUnitId: string, ranges: FRange[]): Promise<{
permissionId: string;

@@ -122,2 +205,17 @@ ruleId: string;

* @param {string[]} ruleIds - The rule IDs of the range protection to be removed.
*
* @example
* ```typescript
* const workbook = univerAPI.getActiveWorkbook();
* const permission = workbook.getPermission();
* const unitId = workbook.getId();
* const worksheet = workbook.getActiveSheet();
* const subUnitId = worksheet.getSheetId();
* const range = worksheet.getRange(0,0,2,2);
* const ranges = [];
* ranges.push(range);
* const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
* const ruleId = res.ruleId;
* permission.removeRangeProtection(unitId, subUnitId, [ruleId]);
* ```
*/

@@ -133,2 +231,20 @@ removeRangeProtection(unitId: string, subUnitId: string, ruleIds: string[]): void;

* @param {boolean} value - The new permission value to be set for the range (e.g., true for allowing access, false for restricting access).
*
* @example
* ```typescript
* const workbook = univerAPI.getActiveWorkbook();
* const permission = workbook.getPermission();
* const unitId = workbook.getId();
* const worksheet = workbook.getActiveSheet();
* const subUnitId = worksheet.getSheetId();
* const range = worksheet.getRange(0, 0, 2, 2);
* const ranges = [];
* ranges.push(range);
* // Note that there will be no permission changes after this step is completed. It only returns an ID for subsequent permission changes.
* // For details, please see the example of the **`setRangeProtectionPermissionPoint`** API.
* const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
* const {permissionId, ruleId} = res;
* // After passing the following line of code, the range set above will become uneditable
* permission.setRangeProtectionPermissionPoint(unitId,subUnitId,permissionId, permission.permissionPointsDefinition.RangeProtectionPermissionEditPoint, false);
* ```
*/

@@ -146,4 +262,20 @@ setRangeProtectionPermissionPoint(unitId: string, subUnitId: string, permissionId: string, FPointClass: RangePermissionPointConstructor, value: boolean): void;

* @param {IRange[]} ranges - The array of new ranges to be set for the range protection rule.
*
* @example
* ```typescript
* const workbook = univerAPI.getActiveWorkbook();
* const permission = workbook.getPermission();
* const unitId = workbook.getId();
* const worksheet = workbook.getActiveSheet();
* const subUnitId = worksheet.getSheetId();
* const range = worksheet.getRange(0, 0, 2, 2);
* const ranges = [];
* ranges.push(range);
* const res = await permission.addRangeBaseProtection(unitId, subUnitId, ranges);
* const {permissionId, ruleId} = res;
* const newRange = worksheet.getRange(3, 3, 2, 2);
* permission.setRangeProtectionRanges(unitId, subUnitId, ruleId, [newRange]);
* ```
*/
setRangeProtectionRanges(unitId: string, subUnitId: string, ruleId: string, ranges: IRange[]): void;
setRangeProtectionRanges(unitId: string, subUnitId: string, ruleId: string, ranges: FRange[]): void;
}

@@ -8,2 +8,8 @@ import { BorderStyleTypes, BorderType, CellValue, CustomData, ICellData, IDocumentData, IObjectMatrixPrimitiveType, IRange, IStyleData, Nullable, Workbook, Worksheet, FBaseInitialable, ICommandService, Injector, RichTextValue, TextStyleValue, WrapStrategy } from '@univerjs/core';

export type FontWeight = 'normal' | 'bold';
/**
* Represents a range of cells in a sheet. You can call methods on this Facade API object
* to read contents or manipulate the range.
*
* @hideconstructor
*/
export declare class FRange extends FBaseInitialable {

@@ -23,5 +29,5 @@ protected readonly _workbook: Workbook;

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getUnitId()
* .getActiveSheet()
* .getActiveRange()
* .getUnitId()
* ```

@@ -36,5 +42,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getSheetName()
* .getActiveSheet()
* .getActiveRange()
* .getSheetName()
* ```

@@ -49,5 +55,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getSheetId()
* .getActiveSheet()
* .getActiveRange()
* .getSheetId()
* ```

@@ -62,5 +68,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getRange()
* .getActiveSheet()
* .getActiveRange()
* .getRange()
* ```

@@ -75,5 +81,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getRow()
* .getActiveSheet()
* .getActiveRange()
* .getRow()
* ```

@@ -88,5 +94,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getColumn()
* .getActiveSheet()
* .getActiveRange()
* .getColumn()
* ```

@@ -101,5 +107,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getWidth()
* .getActiveSheet()
* .getActiveRange()
* .getWidth()
* ```

@@ -114,5 +120,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getHeight()
* .getActiveSheet()
* .getActiveRange()
* .getHeight()
* ```

@@ -127,5 +133,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .isMerged()
* .getActiveSheet()
* .getActiveRange()
* .isMerged()
* ```

@@ -140,5 +146,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getCellStyleData()
* .getActiveSheet()
* .getActiveRange()
* .getCellStyleData()
* ```

@@ -153,5 +159,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getCellStyle()
* .getActiveSheet()
* .getActiveRange()
* .getCellStyle()
* ```

@@ -166,5 +172,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getCellStyles()
* .getActiveSheet()
* .getActiveRange()
* .getCellStyles()
* ```

@@ -179,5 +185,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getValue()
* .getActiveSheet()
* .getActiveRange()
* .getValue()
* ```

@@ -193,5 +199,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getValue(true)
* .getActiveSheet()
* .getActiveRange()
* .getValue(true)
* ```

@@ -218,5 +224,5 @@ */

* const richTextValues = univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getValues(true)
* .getActiveSheet()
* .getActiveRange()
* .getValues(true)
* ```

@@ -231,5 +237,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getCellData()
* .getActiveSheet()
* .getActiveRange()
* .getCellData()
* ```

@@ -244,5 +250,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getCellDatas()
* .getActiveSheet()
* .getActiveRange()
* .getCellDatas()
* ```

@@ -257,5 +263,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getCellDataGrid()
* .getActiveSheet()
* .getActiveRange()
* .getCellDataGrid()
* ```

@@ -272,5 +278,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getRichTextValue()
* .getActiveSheet()
* .getActiveRange()
* .getRichTextValue()
* ```

@@ -287,5 +293,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getRichTextValues()
* .getActiveSheet()
* .getActiveRange()
* .getRichTextValues()
* ```

@@ -302,5 +308,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getValueAndRichTextValue()
* .getActiveSheet()
* .getActiveRange()
* .getValueAndRichTextValue()
* ```

@@ -315,5 +321,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getValueAndRichTextValues()
* .getActiveSheet()
* .getActiveRange()
* .getValueAndRichTextValues()
* ```

@@ -328,5 +334,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getFormulas()
* .getActiveSheet()
* .getActiveRange()
* .getFormulas()
* ```

@@ -341,5 +347,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getWrap()
* .getActiveSheet()
* .getActiveRange()
* .getWrap()
* ```

@@ -354,5 +360,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getWrapStrategy()
* .getActiveSheet()
* .getActiveRange()
* .getWrapStrategy()
* ```

@@ -367,5 +373,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getHorizontalAlignment()
* .getActiveSheet()
* .getActiveRange()
* .getHorizontalAlignment()
* ```

@@ -380,5 +386,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getVerticalAlignment()
* .getActiveSheet()
* .getActiveRange()
* .getVerticalAlignment()
* ```

@@ -393,5 +399,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setCustomMetaData({ key: 'value' });
* .getActiveSheet()
* .getActiveRange()
* .setCustomMetaData({ key: 'value' });
* ```

@@ -406,5 +412,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setCustomMetaDatas([[{ key: 'value' }]]);
* .getActiveSheet()
* .getActiveRange()
* .setCustomMetaDatas([[{ key: 'value' }]]);
* ```

@@ -419,5 +425,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getCustomMetaData()
* .getActiveSheet()
* .getActiveRange()
* .getCustomMetaData()
* ```

@@ -432,5 +438,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .getCustomMetaDatas()
* .getActiveSheet()
* .getActiveRange()
* .getCustomMetaDatas()
* ```

@@ -448,5 +454,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setBorder(BorderType.ALL, BorderStyleType.THIN, '#ff0000');
* .getActiveSheet()
* .getActiveRange()
* .setBorder(BorderType.ALL, BorderStyleType.THIN, '#ff0000');
* ```

@@ -462,5 +468,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setBackgroundColor('red')
* .getActiveSheet()
* .getActiveRange()
* .setBackgroundColor('red')
* ```

@@ -485,5 +491,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setValue(1);
* .getActiveSheet()
* .getActiveRange()
* .setValue(1);
* ```

@@ -498,5 +504,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setValueForCell(1);
* .getActiveSheet()
* .getActiveRange()
* .setValueForCell(1);
* ```

@@ -512,5 +518,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setRichTextValueForCell(new RichTextValue().insertText('Hello'));
* .getActiveSheet()
* .getActiveRange()
* .setRichTextValueForCell(new RichTextValue().insertText('Hello'));
* ```

@@ -526,6 +532,6 @@ */

* univerAPI
* .getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setRichTextValues([[new RichTextValue().insertText('Hello')]]);
* .getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setRichTextValues([[new RichTextValue().insertText('Hello')]]);
* ```

@@ -542,5 +548,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setWrap(true);
* .getActiveSheet()
* .getActiveRange()
* .setWrap(true);
* ```

@@ -556,5 +562,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setWrapStrategy(WrapStrategy.WRAP);
* .getActiveSheet()
* .getActiveRange()
* .setWrapStrategy(WrapStrategy.WRAP);
* ```

@@ -570,5 +576,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setVerticalAlignment('top');
* .getActiveSheet()
* .getActiveRange()
* .setVerticalAlignment('top');
* ```

@@ -584,5 +590,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setHorizontalAlignment('left');
* .getActiveSheet()
* .getActiveRange()
* .setHorizontalAlignment('left');
* ```

@@ -598,5 +604,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setValues([[1, 2], [3, 4]]);
* .getActiveSheet()
* .getActiveRange()
* .setValues([[1, 2], [3, 4]]);
* ```

@@ -612,5 +618,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setFontWeight('bold');
* .getActiveSheet()
* .getActiveRange()
* .setFontWeight('bold');
* ```

@@ -626,5 +632,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setFontStyle('italic');
* .getActiveSheet()
* .getActiveRange()
* .setFontStyle('italic');
* ```

@@ -640,5 +646,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setFontLine('underline');
* .getActiveSheet()
* .getActiveRange()
* .setFontLine('underline');
* ```

@@ -654,5 +660,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setFontLine('underline');
* .getActiveSheet()
* .getActiveRange()
* .setFontLine('underline');
* ```

@@ -674,5 +680,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setFontFamily('Arial');
* .getActiveSheet()
* .getActiveRange()
* .setFontFamily('Arial');
* ```

@@ -688,5 +694,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setFontSize(12);
* .getActiveSheet()
* .getActiveRange()
* .setFontSize(12);
* ```

@@ -702,5 +708,5 @@ */

* univerAPI.getActiveWorkbook()
* .getActiveSheet()
* .getActiveRange()
* .setFontColor('#ff0000');
* .getActiveSheet()
* .getActiveRange()
* .setFontColor('#ff0000');
* ```

@@ -798,3 +804,3 @@ */

* fRange.forEach((row, col, cell) => {
* console.log(row, col, cell);
* console.log(row, col, cell);
* });

@@ -801,0 +807,0 @@ * ```

@@ -6,3 +6,4 @@ import { Direction, ISelectionCell, Nullable, Workbook, Worksheet, Injector } from '@univerjs/core';

/**
* @description Represents the active selection in the sheet.
* Represents the active selection in the sheet.
*
* @example

@@ -16,2 +17,3 @@ * ```ts

* ```
* @hideconstructor
*/

@@ -18,0 +20,0 @@ export declare class FSelection {

import { FBase, Injector } from '@univerjs/core';
/**
* @hideconstructor
*/
export declare class FSheetHooks extends FBase {

@@ -3,0 +6,0 @@ protected readonly _injector: Injector;

@@ -6,2 +6,5 @@ import { ICommandInfo, IDisposable, Injector, IWorkbookData, Nullable, FUniver } from '@univerjs/core';

import { FWorkbook } from './f-workbook';
/**
* @ignore
*/
export interface IFUniverSheetsMixin {

@@ -81,5 +84,5 @@ /**

* univerAPI.addEvent(univerAPI.event.CommandExecuted, (commandInfo) => {
* const target = univerAPI.getCommandSheetTarget(commandInfo);
* if (!target) return;
* const { workbook, worksheet } = target;
* const target = univerAPI.getCommandSheetTarget(commandInfo);
* if (!target) return;
* const { workbook, worksheet } = target;
* });

@@ -117,2 +120,5 @@ * ```

private _initWorkbookEvent;
/**
* @ignore
*/
_initialize(injector: Injector): void;

@@ -119,0 +125,0 @@ createUniverSheet(data: Partial<IWorkbookData>): FWorkbook;

import { CommandListener, CustomData, IDisposable, IRange, IWorkbookData, LocaleType, Workbook, FBaseInitialable, ICommandService, ILogService, Injector, IPermissionService, IResourceLoaderService, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { ISetDefinedNameMutationParam, IDefinedNamesService } from '@univerjs/engine-formula';
import { RangeThemeStyle, SheetsSelectionsService } from '@univerjs/sheets';
import { IRangeThemeStyleJSON, RangeThemeStyle, SheetsSelectionsService } from '@univerjs/sheets';
import { FontLine as _FontLine, FRange } from './f-range';

@@ -8,2 +8,6 @@ import { FDefinedName } from './f-defined-name';

import { FWorksheet } from './f-worksheet';
/**
* Facade API object bounded to a workbook. It provides a set of methods to interact with the workbook.
* @hideconstructor
*/
export declare class FWorkbook extends FBaseInitialable {

@@ -229,3 +233,3 @@ protected readonly _workbook: Workbook;

* activeSpreadsheet.onBeforeCommandExecute((command) => {
* console.log('Command executed:', command);
* console.log('Command executed:', command);
* });

@@ -495,5 +499,5 @@ * ```

* rangeThemeStyle.setSecondRowStyle({
* bg: {
* rgb: 'rgb(214,231,241)',
* },
* bg: {
* rgb: 'rgb(214,231,241)',
* },
* });

@@ -515,2 +519,3 @@ * fWorkbook.registerRangeTheme(rangeThemeStyle);

unregisterRangeTheme(themeName: string): void;
createRangeThemeStyle(themeName: string, themeStyleJson?: Omit<IRangeThemeStyleJSON, 'name'>): RangeThemeStyle;
/**

@@ -538,2 +543,5 @@ * Set custom metadata of workbook

}
/**
* @ignore
*/
export declare namespace FWorkbook {

@@ -540,0 +548,0 @@ type FontLine = _FontLine;

@@ -12,3 +12,4 @@ import { CustomData, ICellData, IColumnRange, IDisposable, IFreeze, IObjectArrayPrimitiveType, IRange, IRowRange, IStyleData, Nullable, Workbook, Worksheet, BooleanNumber, FBaseInitialable, ICommandService, ILogService, Injector, ObjectMatrix } from '@univerjs/core';

/**
* Represents a worksheet facade api instance. Which provides a set of methods to interact with the worksheet.
* A Facade API object bounded to a worksheet. It provides a set of methods to interact with the worksheet.
* @hideconstructor
*/

@@ -15,0 +16,0 @@ export declare class FWorksheet extends FBaseInitialable {

@@ -25,2 +25,3 @@ /**

export { SheetRangeThemeService } from './services/range-theme-service';
export type { IRangeThemeStyleJSON } from './model/range-theme-util';
export * from './services/permission/permission-point';

@@ -27,0 +28,0 @@ export { WorksheetPermissionService } from './services/permission/worksheet-permission/worksheet-permission.service';

@@ -41,3 +41,3 @@ import { IRange } from '@univerjs/core';

private _ruleRefresh;
ruleRefresh$: import('rxjs').Observable<unknown>;
ruleRefresh$: import('rxjs').Observable<string>;
ruleRefresh(id: string): void;

@@ -44,0 +44,0 @@ private _rangeRuleInitStateChange;

@@ -33,4 +33,2 @@ import { RangeProtectionPermissionEditPoint } from './range/edit';

import { WorksheetPivotTablePermission } from './worksheet/pivot-table';
import { WorksheetSelectProtectedCellsPermission } from './worksheet/select-protected-cells';
import { WorksheetSelectUnProtectedCellsPermission } from './worksheet/select-un-protected-cells';
import { WorksheetSetCellStylePermission } from './worksheet/set-cell-style';

@@ -42,43 +40,158 @@ import { WorksheetSetCellValuePermission } from './worksheet/set-cell-value';

import { WorksheetViewPermission } from './worksheet/view';
/**
* @ignore
*/
export declare const PermissionPointsDefinitions: {
/**
* The permission point for adding or editing workbook comments
*/
WorkbookCommentPermission: typeof WorkbookCommentPermission;
/**
* The permission point for copy in workbook
*/
WorkbookCopyPermission: typeof WorkbookCopyPermission;
/**
* The permission point for creating protect in a workbook
*/
WorkbookCreateProtectPermission: typeof WorkbookCreateProtectPermission;
/**
* The permission point for creating new sheets in a workbook
*/
WorkbookCreateSheetPermission: typeof WorkbookCreateSheetPermission;
/**
* The permission point for deleting sheets in a workbook
*/
WorkbookDeleteSheetPermission: typeof WorkbookDeleteSheetPermission;
/**
* The permission point for duplicating a sheet in a workbook
*/
WorkbookDuplicatePermission: typeof WorkbookDuplicatePermission;
/**
* The permission point for editing workbook content
*/
WorkbookEditablePermission: typeof WorkbookEditablePermission;
/**
* The permission point for exporting workbook data
*/
WorkbookExportPermission: typeof WorkbookExportPermission;
/**
* The permission point for hiding sheets in a workbook
*/
WorkbookHideSheetPermission: typeof WorkbookHideSheetPermission;
/**
* The permission point for viewing and managing workbook history
*/
WorkbookHistoryPermission: typeof WorkbookHistoryPermission;
/**
* The permission point for managing collaborators in a workbook
*/
WorkbookManageCollaboratorPermission: typeof WorkbookManageCollaboratorPermission;
/**
* The permission point for moving sheets within a workbook
*/
WorkbookMoveSheetPermission: typeof WorkbookMoveSheetPermission;
/**
* The permission point for printing a workbook
*/
WorkbookPrintPermission: typeof WorkbookPrintPermission;
/**
* The permission point for recovering a previous history state of a workbook
*/
WorkbookRecoverHistoryPermission: typeof WorkbookRecoverHistoryPermission;
/**
* The permission point for renaming sheets in a workbook
*/
WorkbookRenameSheetPermission: typeof WorkbookRenameSheetPermission;
/**
* The permission point for sharing a workbook with others
*/
WorkbookSharePermission: typeof WorkbookSharePermission;
/**
* The permission point for viewing the history of a workbook
*/
WorkbookViewHistoryPermission: typeof WorkbookViewHistoryPermission;
/**
* The permission point for viewing a workbook
*/
WorkbookViewPermission: typeof WorkbookViewPermission;
/**
* The permission point for copying contents from a worksheet
*/
WorksheetCopyPermission: typeof WorksheetCopyPermission;
/**
* The permission point for deleting columns in a worksheet
*/
WorksheetDeleteColumnPermission: typeof WorksheetDeleteColumnPermission;
/**
* The permission point for deleting worksheet protection rules
*/
WorksheetDeleteProtectionPermission: typeof WorksheetDeleteProtectionPermission;
/**
* The permission point for deleting rows in a worksheet
*/
WorksheetDeleteRowPermission: typeof WorksheetDeleteRowPermission;
/**
* The permission point for editing extra objects (e.g. shapes) in a worksheet
*/
WorksheetEditExtraObjectPermission: typeof WorksheetEditExtraObjectPermission;
/**
* The permission point for editing the content of a worksheet
*/
WorksheetEditPermission: typeof WorksheetEditPermission;
/**
* The permission point for applying filters in a worksheet
*/
WorksheetFilterPermission: typeof WorksheetFilterPermission;
/**
* The permission point for inserting columns into a worksheet
*/
WorksheetInsertColumnPermission: typeof WorksheetInsertColumnPermission;
/**
* The permission point for inserting hyperlinks in a worksheet
*/
WorksheetInsertHyperlinkPermission: typeof WorksheetInsertHyperlinkPermission;
/**
* The permission point for inserting rows into a worksheet
*/
WorksheetInsertRowPermission: typeof WorksheetInsertRowPermission;
/**
* The permission point for managing collaborators of a worksheet
*/
WorksheetManageCollaboratorPermission: typeof WorksheetManageCollaboratorPermission;
/**
* The permission point for creating or modifying pivot tables in a worksheet
*/
WorksheetPivotTablePermission: typeof WorksheetPivotTablePermission;
WorksheetSelectProtectedCellsPermission: typeof WorksheetSelectProtectedCellsPermission;
WorksheetSelectUnProtectedCellsPermission: typeof WorksheetSelectUnProtectedCellsPermission;
/**
* The permission point for setting the style of cells in a worksheet
*/
WorksheetSetCellStylePermission: typeof WorksheetSetCellStylePermission;
/**
* The permission point for setting the value of cells in a worksheet
*/
WorksheetSetCellValuePermission: typeof WorksheetSetCellValuePermission;
/**
* The permission point for setting the style of columns in a worksheet
*/
WorksheetSetColumnStylePermission: typeof WorksheetSetColumnStylePermission;
/**
* The permission point for setting the style of rows in a worksheet
*/
WorksheetSetRowStylePermission: typeof WorksheetSetRowStylePermission;
/**
* The permission point for performing sort operations on a worksheet
*/
WorksheetSortPermission: typeof WorksheetSortPermission;
/**
* The permission point for viewing the content of a worksheet
*/
WorksheetViewPermission: typeof WorksheetViewPermission;
/**
* The permission point for editing the range protection settings
*/
RangeProtectionPermissionEditPoint: typeof RangeProtectionPermissionEditPoint;
/**
* The permission point for viewing the range protection settings
*/
RangeProtectionPermissionViewPoint: typeof RangeProtectionPermissionViewPoint;
};

@@ -6,5 +6,5 @@ import { IMutationInfo, Disposable, DisposableCollection, ICommandService, IUniverInstanceService } from '@univerjs/core';

import { EffectRefRangeParams } from '../../../services/ref-range/type';
import { RangeProtectionCache } from '../../../model/range-protection.cache';
import { RangeProtectionRenderModel } from '../../../model/range-protection-render.model';
import { RangeProtectionRuleModel } from '../../../model/range-protection-rule.model';
import { RangeProtectionCache } from '../../../model/range-protection.cache';
import { RefRangeService } from '../../../services/ref-range/ref-range.service';

@@ -11,0 +11,0 @@ import { SheetInterceptorService } from '../../sheet-interceptor/sheet-interceptor.service';

import { Disposable, IPermissionService, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
import { RangeProtectionRuleModel } from '../../../model/range-protection-rule.model';
import { RangeProtectionCache } from '../../../model/range-protection.cache';
import { RangeProtectionRuleModel } from '../../../model/range-protection-rule.model';
export declare class RangeProtectionService extends Disposable {

@@ -5,0 +5,0 @@ private _selectionProtectionRuleModel;

@@ -19,3 +19,3 @@ import { IObjectModel, IWorksheetProtectionRule } from '../type';

}>;
ruleRefresh$: import('rxjs').Observable<unknown>;
ruleRefresh$: import('rxjs').Observable<string>;
resetOrder$: import('rxjs').Observable<unknown>;

@@ -22,0 +22,0 @@ private _worksheetRuleInitStateChange;

@@ -1,1 +0,1 @@

(function(m,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-formula"],o):(m=typeof globalThis<"u"?globalThis:m||self,o(m.UniverSheetsFacade={},m.UniverCore,m.UniverSheets,m.UniverEngineFormula))})(this,function(m,o,a,C){"use strict";var ae=Object.defineProperty;var he=(m,o,a)=>o in m?ae(m,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):m[o]=a;var v=(m,o,a)=>he(m,typeof o!="symbol"?o+"":o,a);var W=Object.defineProperty,A=Object.getOwnPropertyDescriptor,F=(c,n,e,t)=>{for(var i=t>1?void 0:t?A(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&W(n,e,i),i},_=(c,n)=>(e,t)=>n(e,t,c);function M(c,n,e){const t=e.getDefinedNameMap(c);if(t==null)return n.t("definedName.defaultName")+1;const r=Array.from(Object.values(t)).length+1,s=n.t("definedName.defaultName")+r;if(e.getValueByName(c,s)==null)return s;let h=r+1;for(;;){const d=n.t("definedName.defaultName")+h;if(e.getValueByName(c,d)==null)return d;h++}}class I{constructor(){v(this,"_definedNameParam");this._definedNameParam={id:o.generateRandomId(10),unitId:"",name:"",formulaOrRefString:""}}setName(n){return this._definedNameParam.name=n,this}setFormula(n){return this._definedNameParam.formulaOrRefString=`=${n}`,this}setRef(n){return this._definedNameParam.formulaOrRefString=n,this}setRefByRange(n,e,t,i){return this._definedNameParam.formulaOrRefString=C.serializeRange({startRow:n,endRow:n+(t!=null?t:1)-1,startColumn:e,endColumn:e+(i!=null?i:1)-1}),this}setComment(n){return this._definedNameParam.comment=n,this}setHidden(n){return this._definedNameParam.hidden=n,this}build(){return this._definedNameParam}load(n){return this._definedNameParam=n,this}}let R=class extends o.FBase{constructor(c,n,e,t,i,r,s,h,d,u){super(),this._definedNameParam=c,this._injector=n,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=i,this._rangeProtectionRuleModel=r,this._worksheetProtectionPointRuleModel=s,this._authzIoService=h,this._localeService=d,this._definedNamesService=u}_apply(){this._definedNameParam.name===""&&(this._definedNameParam.name=M(this._definedNameParam.unitId,this._localeService,this._definedNamesService)),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,this._definedNameParam)}getName(){return this._definedNameParam.name}setName(c){this._definedNameParam.name=c,this._apply()}setFormula(c){this._definedNameParam.formulaOrRefString=`=${c}`,this._apply()}setRef(c){this._definedNameParam.formulaOrRefString=c,this._apply()}getFormulaOrRefString(){return this._definedNameParam.formulaOrRefString}setRefByRange(c,n,e,t){this._definedNameParam.formulaOrRefString=C.serializeRange({startRow:c,endRow:c+(e!=null?e:1)-1,startColumn:n,endColumn:n+(t!=null?t:1)-1}),this._apply()}getComment(){return this._definedNameParam.comment}setComment(c){this._definedNameParam.comment=c,this._apply()}setScopeToWorksheet(c){this._definedNameParam.localSheetId=c.getSheetId(),this._apply()}setScopeToWorkbook(){this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this._apply()}setHidden(c){this._definedNameParam.hidden=c,this._apply()}delete(){this._commandService.syncExecuteCommand(a.RemoveDefinedNameCommand.id,this._definedNameParam)}getLocalSheetId(){return this._definedNameParam.localSheetId}isWorkbookScope(){return this._definedNameParam.localSheetId===a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}toBuilder(){const c=this._injector.createInstance(I);return c.load(this._definedNameParam),c}};R=F([_(1,o.Inject(o.Injector)),_(2,o.ICommandService),_(3,o.IPermissionService),_(4,o.Inject(a.WorksheetProtectionRuleModel)),_(5,o.Inject(a.RangeProtectionRuleModel)),_(6,o.Inject(a.WorksheetProtectionPointModel)),_(7,o.Inject(o.IAuthzIoService)),_(8,o.Inject(o.LocaleService)),_(9,C.IDefinedNamesService)],R);var B=Object.defineProperty,D=Object.getOwnPropertyDescriptor,j=(c,n,e,t)=>{for(var i=t>1?void 0:t?D(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&B(n,e,i),i},w=(c,n)=>(e,t)=>n(e,t,c);m.FPermission=class extends o.FBase{constructor(e,t,i,r,s,h,d){super();v(this,"permissionPointsDefinition",a.PermissionPointsDefinitions);v(this,"rangeRuleChangedAfterAuth$");v(this,"sheetRuleChangedAfterAuth$");this._injector=e,this._commandService=t,this._permissionService=i,this._worksheetProtectionRuleModel=r,this._rangeProtectionRuleModel=s,this._worksheetProtectionPointRuleModel=h,this._authzIoService=d,this.rangeRuleChangedAfterAuth$=this._rangeProtectionRuleModel.ruleRefresh$,this.sheetRuleChangedAfterAuth$=this._worksheetProtectionRuleModel.ruleRefresh$}setWorkbookPermissionPoint(e,t,i){const r=new t(e);this._permissionService.getPermissionPoint(r.id)||this._permissionService.addPermissionPoint(r),this._permissionService.updatePermissionPoint(r.id,i)}setWorkbookEditPermission(e,t){this.setWorkbookPermissionPoint(e,a.WorkbookEditablePermission,t)}async addWorksheetBasePermission(e,t){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");const r=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}});if(this._commandService.syncExecuteCommand(a.AddWorksheetProtectionMutation.id,{unitId:e,subUnitId:t,rule:{permissionId:r,unitType:a.UnitObject.Worksheet,unitId:e,subUnitId:t}}))return r}removeWorksheetPermission(e,t){this._commandService.syncExecuteCommand(a.DeleteWorksheetProtectionMutation.id,{unitId:e,subUnitId:t}),[...a.getAllWorksheetPermissionPoint(),...a.getAllWorksheetPermissionPointByPointPanel()].forEach(i=>{const r=new i(e,t);this._permissionService.updatePermissionPoint(r.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e,t)}async setWorksheetPermissionPoint(e,t,i,r){const s=this._worksheetProtectionRuleModel.getRule(e,t);let h;if(i===a.WorksheetEditPermission||i===a.WorksheetViewPermission)if(s)h=s.permissionId;else{if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");h=await this.addWorksheetBasePermission(e,t)}else{const g=this._worksheetProtectionPointRuleModel.getRule(e,t);g?h=g.permissionId:(h=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}}),this._commandService.syncExecuteCommand(a.SetWorksheetPermissionPointsMutation.id,{unitId:e,subUnitId:t,permissionId:h}))}const u=new i(e,t);return this._permissionService.getPermissionPoint(u.id)||this._permissionService.addPermissionPoint(u),this._permissionService.updatePermissionPoint(u.id,r),h}async addRangeBaseProtection(e,t,i){const r=await this._authzIoService.create({objectType:a.UnitObject.SelectRange,selectRangeObject:{collaborators:[],unitID:e,name:"",scope:void 0}}),s=`ruleId_${o.generateRandomId(6)}`;if(this._worksheetProtectionRuleModel.getRule(e,t))throw new Error("sheet protection cannot intersect with range protection");if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).some(g=>g.ranges.some(k=>i.some(f=>o.Rectangle.intersects(f,k)))))throw new Error("range protection cannot intersect");if(this._commandService.syncExecuteCommand(a.AddRangeProtectionMutation.id,{unitId:e,subUnitId:t,rules:[{permissionId:r,unitType:a.UnitObject.SelectRange,unitId:e,subUnitId:t,ranges:i,id:s}]}))return{permissionId:r,ruleId:s}}removeRangeProtection(e,t,i){this._commandService.syncExecuteCommand(a.DeleteRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleIds:i})&&this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length===0&&(this._worksheetProtectionPointRuleModel.deleteRule(e,t),[...a.getAllWorksheetPermissionPointByPointPanel()].forEach(h=>{const d=new h(e,t);this._permissionService.updatePermissionPoint(d.id,d.value)}))}setRangeProtectionPermissionPoint(e,t,i,r,s){const h=new r(e,t,i);this._permissionService.getPermissionPoint(h.id)||this._permissionService.addPermissionPoint(h),this._permissionService.updatePermissionPoint(h.id,s)}setRangeProtectionRanges(e,t,i,r){const s=this._rangeProtectionRuleModel.getRule(e,t,i);if(s){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).filter(u=>u.id!==i).some(u=>u.ranges.some(l=>r.some(g=>o.Rectangle.intersects(g,l)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(a.SetRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleId:i,rule:{...s,ranges:r}})}}},m.FPermission=j([w(0,o.Inject(o.Injector)),w(1,o.ICommandService),w(2,o.IPermissionService),w(3,o.Inject(a.WorksheetProtectionRuleModel)),w(4,o.Inject(a.RangeProtectionRuleModel)),w(5,o.Inject(a.WorksheetProtectionPointModel)),w(6,o.Inject(o.IAuthzIoService))],m.FPermission);function x(c){switch(c){case"left":return o.HorizontalAlign.LEFT;case"center":return o.HorizontalAlign.CENTER;case"normal":return o.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${c}`)}}function O(c){switch(c){case o.HorizontalAlign.LEFT:return"left";case o.HorizontalAlign.CENTER:return"center";case o.HorizontalAlign.RIGHT:return"normal";default:throw new Error(`Invalid horizontal alignment: ${c}`)}}function V(c){switch(c){case"top":return o.VerticalAlign.TOP;case"middle":return o.VerticalAlign.MIDDLE;case"bottom":return o.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${c}`)}}function L(c){switch(c){case o.VerticalAlign.TOP:return"top";case o.VerticalAlign.MIDDLE:return"middle";case o.VerticalAlign.BOTTOM:return"bottom";default:throw new Error(`Invalid vertical alignment: ${c}`)}}function b(c){return o.isFormulaString(c)?{f:c,v:null,p:null}:o.isCellV(c)?{v:c,p:null,f:null}:(o.isICellData(c),c)}function P(c,n){const e=new o.ObjectMatrix,{startRow:t,startColumn:i,endRow:r,endColumn:s}=n;if(o.Tools.isArray(c))for(let h=0;h<=r-t;h++)for(let d=0;d<=s-i;d++)e.setValue(h+t,d+i,b(c[h][d]));else new o.ObjectMatrix(c).forValue((d,u,l)=>{e.setValue(d,u,b(l))});return e.getMatrix()}function E(c,n){return{startRow:c.startRow,endRow:c.endRow,startColumn:0,endColumn:n.getColumnCount()-1,rangeType:o.RANGE_TYPE.ROW}}function p(c,n){return{startRow:0,endRow:n.getRowCount()-1,startColumn:c.startColumn,endColumn:c.endColumn,rangeType:o.RANGE_TYPE.COLUMN}}var H=Object.defineProperty,z=Object.getOwnPropertyDescriptor,G=(c,n,e,t)=>{for(var i=t>1?void 0:t?z(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&H(n,e,i),i},U=(c,n)=>(e,t)=>n(e,t,c);m.FRange=class extends o.FBaseInitialable{constructor(n,e,t,i,r,s){super(i),this._workbook=n,this._worksheet=e,this._range=t,this._injector=i,this._commandService=r,this._formulaDataModel=s}getUnitId(){return this._workbook.getUnitId()}getSheetName(){return this._worksheet.getName()}getSheetId(){return this._worksheet.getSheetId()}getRange(){return this._range}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}isMerged(){const{startColumn:n,startRow:e,endColumn:t,endRow:i}=this._range;return this._worksheet.getMergedCellRange(e,n,i,t).some(s=>o.Rectangle.equals(s,this._range))}getCellStyleData(){var t;const n=this.getCellData(),e=this._workbook.getStyles();return n&&e&&(t=e.getStyleByCell(n))!=null?t:null}getCellStyle(){const n=this.getCellStyleData();return n?o.TextStyleValue.create(n):null}getCellStyles(){const n=this.getCellDatas(),e=this._workbook.getStyles();return n.map(t=>t.map(i=>{if(!i)return null;const r=e.getStyleByCell(i);return r?o.TextStyleValue.create(r):null}))}getValue(n){var e,t;return n?this.getValueAndRichTextValue():(t=(e=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:e.v)!=null?t:null}getValues(n){var h,d;n&&this.getValueAndRichTextValues();const{startRow:e,endRow:t,startColumn:i,endColumn:r}=this._range,s=[];for(let u=e;u<=t;u++){const l=[];for(let g=i;g<=r;g++)l.push((d=(h=this._worksheet.getCell(u,g))==null?void 0:h.v)!=null?d:null);s.push(l)}return s}getCellData(){var n;return(n=this._worksheet.getCell(this._range.startRow,this._range.startColumn))!=null?n:null}getCellDatas(){return this.getCellDataGrid()}getCellDataGrid(){const{startRow:n,endRow:e,startColumn:t,endColumn:i}=this._range,r=[];for(let s=n;s<=e;s++){const h=[];for(let d=t;d<=i;d++)h.push(this._worksheet.getCellRaw(s,d));r.push(h)}return r}getRichTextValue(){const n=this.getCellData();return n!=null&&n.p?new o.RichTextValue(n.p):null}getRichTextValues(){return this.getCellDataGrid().map(e=>e.map(t=>t!=null&&t.p?new o.RichTextValue(t.p):null))}getValueAndRichTextValue(){const n=this.getCellData();return n!=null&&n.p?new o.RichTextValue(n.p):n==null?void 0:n.v}getValueAndRichTextValues(){return this.getCellDatas().map(e=>e.map(t=>t!=null&&t.p?new o.RichTextValue(t.p):t==null?void 0:t.v))}getFormulas(){const n=[],{startRow:e,endRow:t,startColumn:i,endColumn:r}=this._range,s=this._worksheet.getSheetId(),h=this._workbook.getUnitId();for(let d=e;d<=t;d++){const u=[];for(let l=i;l<=r;l++){const g=this._formulaDataModel.getFormulaStringByCell(d,l,s,h);u.push(g||"")}n.push(u)}return n}getWrap(){return this._worksheet.getRange(this._range).getWrap()===o.BooleanNumber.TRUE}getWrapStrategy(){return this._worksheet.getRange(this._range).getWrapStrategy()}getHorizontalAlignment(){return O(this._worksheet.getRange(this._range).getHorizontalAlignment())}getVerticalAlignment(){return L(this._worksheet.getRange(this._range).getVerticalAlignment())}setCustomMetaData(n){return this.setValue({custom:n})}setCustomMetaDatas(n){return this.setValues(n.map(e=>e.map(t=>({custom:t}))))}getCustomMetaData(){var e;const n=this.getCellData();return(e=n==null?void 0:n.custom)!=null?e:null}getCustomMetaDatas(){return this.getCellDataGrid().map(e=>e.map(t=>{var i;return(i=t==null?void 0:t.custom)!=null?i:null}))}setBorder(n,e,t){return this._commandService.syncExecuteCommand(a.SetBorderBasicCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),value:{type:n,style:e,color:t}}),this}setBackgroundColor(n){return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:n}}}),this}setBackground(n){return this.setBackgroundColor(n),this}setValue(n){const e=b(n);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setValueForCell(n){const e=b(n);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.endColumn,endRow:this._range.endRow},value:e}),this}setRichTextValueForCell(n){const e=n instanceof o.RichTextValue?n.getData():n,t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.endColumn,endRow:this._range.endRow},value:{p:e}};return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,t),this}setRichTextValues(n){const e=n.map(r=>r.map(s=>s&&{p:s instanceof o.RichTextValue?s.getData():s})),t=P(e,this._range),i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:t};return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,i),this}setWrap(n){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:n?o.WrapStrategy.WRAP:o.WrapStrategy.UNSPECIFIED}),this}setWrapStrategy(n){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:n}),this}setVerticalAlignment(n){return this._commandService.syncExecuteCommand(a.SetVerticalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:V(n)}),this}setHorizontalAlignment(n){return this._commandService.syncExecuteCommand(a.SetHorizontalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:x(n)}),this}setValues(n){const e=P(n,this._range);return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setFontWeight(n){let e;if(n==="bold")e=o.BooleanNumber.TRUE;else if(n==="normal")e=o.BooleanNumber.FALSE;else if(n===null)e=null;else throw new Error("Invalid fontWeight");const t={type:"bl",value:e},i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,i),this}setFontStyle(n){let e;if(n==="italic")e=o.BooleanNumber.TRUE;else if(n==="normal")e=o.BooleanNumber.FALSE;else if(n===null)e=null;else throw new Error("Invalid fontStyle");const t={type:"it",value:e},i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,i),this}setFontLine(n){if(n==="underline")this._setFontUnderline({s:o.BooleanNumber.TRUE});else if(n==="line-through")this._setFontStrikethrough({s:o.BooleanNumber.TRUE});else if(n==="none")this._setFontUnderline({s:o.BooleanNumber.FALSE}),this._setFontStrikethrough({s:o.BooleanNumber.FALSE});else if(n===null)this._setFontUnderline(null),this._setFontStrikethrough(null);else throw new Error("Invalid fontLine");return this}_setFontUnderline(n){const e={type:"ul",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t)}_setFontStrikethrough(n){const e={type:"st",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t)}setFontFamily(n){const e={type:"ff",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t),this}setFontSize(n){const e={type:"fs",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t),this}setFontColor(n){const t={type:"cl",value:n===null?null:{rgb:n}},i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,i),this}merge(n=!0){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,e,t,[this._range],n),this}mergeAcross(n=!0){const e=a.getAddMergeMutationRangeByType([this._range],o.Dimension.ROWS),t=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,i,e,n),this}mergeVertically(n=!0){const e=a.getAddMergeMutationRangeByType([this._range],o.Dimension.COLUMNS),t=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,i,e,n),this}isPartOfMerge(){const{startRow:n,startColumn:e,endRow:t,endColumn:i}=this._range;return this._worksheet.getMergedCellRange(n,e,t,i).length>0}breakApart(){return this._commandService.syncExecuteCommand(a.RemoveWorksheetMergeCommand.id,{ranges:[this._range]}),this}forEach(n){const{startColumn:e,startRow:t,endColumn:i,endRow:r}=this._range;this._worksheet.getMatrixWithMergedCells(t,e,r,i).forValue((s,h,d)=>{n(s,h,d)})}getA1Notation(n){return n?C.serializeRangeWithSheet(this._worksheet.getName(),this._range):C.serializeRange(this._range)}activate(){return this._injector.createInstance(m.FWorkbook,this._workbook).setActiveRange(this),this}activateAsCurrentCell(){const n=this._worksheet.getMergedCell(this._range.startRow,this._range.startColumn);if(n&&o.Rectangle.equals(n,this._range)||!n&&this._range.startRow===this._range.endRow&&this._range.startColumn===this._range.endColumn)return this.activate();throw new Error("The range is not a single cell")}splitTextToColumns(n,e,t){this._commandService.syncExecuteCommand(a.SplitTextToColumnsCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,delimiter:e,customDelimiter:t,treatMultipleDelimitersAsOne:n})}useThemeStyle(n){if(n==null){const e=this.getUsedThemeStyle();e&&this.removeThemeStyle(e)}else this._commandService.syncExecuteCommand(a.SetWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:n})}removeThemeStyle(n){this._commandService.syncExecuteCommand(a.DeleteWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:n})}getUsedThemeStyle(){return this._injector.get(a.SheetRangeThemeService).getAppliedRangeThemeStyle({unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})}},m.FRange=G([U(3,o.Inject(o.Injector)),U(4,o.ICommandService),U(5,o.Inject(C.FormulaDataModel))],m.FRange);var $=Object.defineProperty,Y=Object.getOwnPropertyDescriptor,q=(c,n,e,t)=>{for(var i=t>1?void 0:t?Y(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&$(n,e,i),i},K=(c,n)=>(e,t)=>n(e,t,c);m.FSelection=class{constructor(n,e,t,i){this._workbook=n,this._worksheet=e,this._selections=t,this._injector=i}getActiveRange(){const n=this._selections.find(e=>!!e.primary);return n?this._injector.createInstance(m.FRange,this._workbook,this._worksheet,n.range):null}getActiveRangeList(){return this._selections.map(n=>this._injector.createInstance(m.FRange,this._workbook,this._worksheet,n.range))}getCurrentCell(){const n=this._selections.find(e=>!!e.primary);return n?n.primary:null}getActiveSheet(){const n=this._injector.createInstance(m.FWorkbook,this._workbook);return this._injector.createInstance(m.FWorksheet,n,this._workbook,this._worksheet)}updatePrimaryCell(n){const e=this._injector.get(o.ICommandService);let t=[],i=!1;for(const{range:s,style:h}of this._selections)o.Rectangle.contains(s,n.getRange())?(t.push({range:s,primary:a.getPrimaryForRange(n.getRange(),this._worksheet),style:h}),i=!0):t.push({range:s,primary:null,style:h});i||(t=[{range:n.getRange(),primary:a.getPrimaryForRange(n.getRange(),this._worksheet)}]);const r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),selections:t};return e.syncExecuteCommand(a.SetSelectionsOperation.id,r),new m.FSelection(this._workbook,this._worksheet,t,this._injector)}getNextDataRange(n){if(!this._selections.find(i=>!!i.primary))return null;const t=a.getNextPrimaryCell(this._selections.concat(),n,this._worksheet);return t?this._injector.createInstance(m.FRange,this._workbook,this._worksheet,t):null}},m.FSelection=q([K(3,o.Inject(o.Injector))],m.FSelection);var J=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,X=(c,n,e,t)=>{for(var i=t>1?void 0:t?Q(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&J(n,e,i),i},y=(c,n)=>(e,t)=>n(e,t,c);m.FWorksheet=class extends o.FBaseInitialable{constructor(e,t,i,r,s,h,d){super(r);v(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=i,this._injector=r,this._selectionManagerService=s,this._logService=h,this._commandService=d}getSheet(){return this._worksheet}getInject(){return this._injector}getWorkbook(){return this._workbook}getSheetId(){return this._worksheet.getSheetId()}getSheetName(){return this._worksheet.getName()}getSelection(){const e=this._selectionManagerService.getCurrentSelections();return e?this._injector.createInstance(m.FSelection,this._workbook,this._worksheet,e):null}getDefaultStyle(){return this._worksheet.getDefaultCellStyle()}getRowDefaultStyle(e,t=!1){return this._worksheet.getRowStyle(e,t)}getColumnDefaultStyle(e,t=!1){return this._worksheet.getColumnStyle(e,t)}setDefaultStyle(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return this._commandService.syncExecuteCommand(a.SetWorksheetDefaultStyleMutation.id,{unitId:t,subUnitId:i,defaultStyle:e}),this._worksheet.setDefaultCellStyle(e),this}setColumnDefaultStyle(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={unitId:i,subUnitId:r,columnData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,s),this}setRowDefaultStyle(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={unitId:i,subUnitId:r,rowData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,s),this}getRange(e,t,i,r){let s,h;if(typeof e=="object")s=e,h=this._worksheet;else if(typeof e=="string"){const{range:d,sheetName:u}=C.deserializeRangeWithSheet(e),l=u?this._workbook.getSheetBySheetName(u):this._worksheet;if(!l)throw new Error("Range not found");h=l,s={...d,unitId:this._workbook.getUnitId(),sheetId:h.getSheetId(),rangeType:o.RANGE_TYPE.NORMAL,startRow:d.rangeType===o.RANGE_TYPE.COLUMN?0:d.startRow,endRow:d.rangeType===o.RANGE_TYPE.COLUMN?h.getMaxRows()-1:d.endRow,startColumn:d.rangeType===o.RANGE_TYPE.ROW?0:d.startColumn,endColumn:d.rangeType===o.RANGE_TYPE.ROW?h.getMaxColumns()-1:d.endColumn}}else if(typeof e=="number"&&t!==void 0)h=this._worksheet,s={startRow:e,endRow:e+(i!=null?i:1)-1,startColumn:t,endColumn:t+(r!=null?r:1)-1,unitId:this._workbook.getUnitId(),sheetId:this._worksheet.getSheetId()};else throw new Error("Invalid range specification");return this._injector.createInstance(m.FRange,this._workbook,h,s)}getMaxColumns(){return this._worksheet.getMaxColumns()}getMaxRows(){return this._worksheet.getMaxRows()}insertRowAfter(e){return this.insertRowsAfter(e,1)}insertRowBefore(e){return this.insertRowsBefore(e,1)}insertRows(e,t=1){return this.insertRowsBefore(e,t)}insertRowsAfter(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=o.Direction.DOWN,h=e+1,d=e+t,u=0,l=this._worksheet.getColumnCount()-1,g=a.copyRangeStyles(this._worksheet,h,d,u,l,!0,e);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:i,subUnitId:r,direction:s,range:{startRow:h,endRow:d,startColumn:u,endColumn:l},cellValue:g}),this}insertRowsBefore(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=o.Direction.UP,h=e,d=e+t-1,u=0,l=this._worksheet.getColumnCount()-1,g=a.copyRangeStyles(this._worksheet,h,d,u,l,!0,e-1);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:i,subUnitId:r,direction:s,range:{startRow:h,endRow:d,startColumn:u,endColumn:l},cellValue:g}),this}deleteRow(e){return this.deleteRows(e,1)}deleteRows(e,t){const i={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return this._commandService.syncExecuteCommand(a.RemoveRowByRangeCommand.id,{range:i,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}moveRows(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=E(e.getRange(),this._worksheet),h=s,d={startRow:t,endRow:t,startColumn:s.startColumn,endColumn:s.endColumn};return this._commandService.syncExecuteCommand(a.MoveRowsCommand.id,{unitId:i,subUnitId:r,range:s,fromRange:h,toRange:d}),this}hideRow(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r=E(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:t,subUnitId:i,ranges:[r]}),this}hideRows(e,t=1){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:o.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:i,subUnitId:r,ranges:[s]}),this}unhideRow(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r=E(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:t,subUnitId:i,ranges:[r]}),this}showRows(e,t=1){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:o.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:i,subUnitId:r,ranges:[s]}),this}setRowHeight(e,t){return this.setRowHeights(e,1,t)}autoFitRow(e,t=o.BooleanNumber.TRUE){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=[{startRow:e,endRow:e,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:s[0],value:o.WrapStrategy.WRAP}),this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightMutation.id,{unitId:i,subUnitId:r,ranges:s,autoHeightInfo:t}),this}setRowHeights(e,t,i){var l;const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),h=this._worksheet.getRowManager(),d=[],u=[];for(let g=e;g<e+t;g++){const k=((l=h.getRow(g))==null?void 0:l.ah)||this._worksheet.getConfig().defaultRowHeight,f={startRow:g,endRow:g,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};i<=k?d.push(f):u.push(f)}return u.length>0&&this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:r,subUnitId:s,ranges:u,value:i}),d.length>0&&this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:r,subUnitId:s,ranges:d}),this}setRowAutoHeight(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:i,subUnitId:r,ranges:s}),this}setRowHeightsForced(e,t,i){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),h=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:r,subUnitId:s,ranges:h,value:i}),this}setRowCustom(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r={};for(const[h,d]of Object.entries(e))r[Number(h)]={custom:d};const s={unitId:t,subUnitId:i,rowData:r};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,s),this}insertColumnAfter(e){return this.insertColumnsAfter(e,1)}insertColumnBefore(e){return this.insertColumnsBefore(e,1)}insertColumns(e,t=1){return this.insertColumnsBefore(e,t)}insertColumnsAfter(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=o.Direction.RIGHT,h=0,d=this._worksheet.getRowCount()-1,u=e+1,l=e+t,g=a.copyRangeStyles(this._worksheet,h,d,u,l,!1,e);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:i,subUnitId:r,direction:s,range:{startRow:h,endRow:d,startColumn:u,endColumn:l},cellValue:g}),this}insertColumnsBefore(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=o.Direction.LEFT,h=0,d=this._worksheet.getRowCount()-1,u=e,l=e+t-1,g=a.copyRangeStyles(this._worksheet,h,d,u,l,!1,e-1);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:i,subUnitId:r,direction:s,range:{startRow:h,endRow:d,startColumn:u,endColumn:l},cellValue:g}),this}deleteColumn(e){return this.deleteColumns(e,1)}deleteColumns(e,t){const i={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1};return this._commandService.syncExecuteCommand(a.RemoveColByRangeCommand.id,{range:i,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}moveColumns(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=p(e.getRange(),this._worksheet),h=s,d={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return this._commandService.syncExecuteCommand(a.MoveColsCommand.id,{unitId:i,subUnitId:r,range:s,fromRange:h,toRange:d}),this}hideColumn(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r=p(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:t,subUnitId:i,ranges:[r]}),this}hideColumns(e,t=1){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:o.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:i,subUnitId:r,ranges:[s]}),this}unhideColumn(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r=p(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:t,subUnitId:i,ranges:[r]}),this}showColumns(e,t=1){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:o.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:i,subUnitId:r,ranges:[s]}),this}setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}setColumnWidths(e,t,i){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),h=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return this._commandService.syncExecuteCommand(a.SetColWidthCommand.id,{unitId:r,subUnitId:s,ranges:h,value:i}),this}setColumnCustom(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r={};for(const[h,d]of Object.entries(e))r[Number(h)]={custom:d};const s={unitId:t,subUnitId:i,columnData:r};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,s),this}getMergedRanges(){return this._worksheet.getSnapshot().mergeData.map(t=>this._injector.createInstance(m.FRange,this._workbook,this._worksheet,t))}getCellMergeData(e,t){const r=this._worksheet.getMergedCell(e,t);if(r)return this._injector.createInstance(m.FRange,this._workbook,this._worksheet,r)}getActiveRange(){return this._fWorkbook.getActiveRange()}setActiveRange(e){const{unitId:t,sheetId:i}=e.getRange();if(t!==this._workbook.getUnitId()||i!==this._worksheet.getSheetId())throw new Error("Specified range must be part of the sheet.");return this._fWorkbook.setActiveRange(e),this}setFreeze(e){return this._logService.warn("setFreeze is deprecated, use setFrozenRows and setFrozenColumns instead"),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{...e,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}cancelFreeze(){return this._commandService.syncExecuteCommand(a.CancelFrozenCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}getFreeze(){return this._worksheet.getFreeze()}setFrozenColumns(...e){const t=this.getFreeze();if(arguments.length===1){const i=e[0];this.setFreeze({...t,startColumn:i>0?i:-1,xSplit:i})}else if(arguments.length===2){let[i=0,r=0]=e;i>r&&([i,r]=[r,i]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startColumn:r+1,xSplit:r-i+1,startRow:t.startRow,ySplit:t.ySplit,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}return this}setFrozenRows(...e){const t=this.getFreeze();if(arguments.length===1){const i=e[0];this.setFreeze({...t,startRow:i>0?i:-1,ySplit:i})}else if(arguments.length===2){let[i=0,r=0]=e;i>r&&([i,r]=[r,i]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startRow:r+1,ySplit:r-i+1,startColumn:t.startColumn,xSplit:t.xSplit,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}return this}getFrozenColumns(){const e=this.getFreeze();return e.startColumn===-1?0:e.startColumn}getFrozenRows(){const e=this.getFreeze();return e.startRow===-1?0:e.startRow}getFrozenRowRange(){const e=this._worksheet.getFreeze();return{startRow:e.startRow-e.ySplit,endRow:e.startRow-1}}getFrozenColumnRange(){const e=this._worksheet.getFreeze();return{startColumn:e.startColumn-e.xSplit,endColumn:e.startColumn-1}}hasHiddenGridLines(){return this._worksheet.getConfig().showGridlines===o.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.syncExecuteCommand(a.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?o.BooleanNumber.FALSE:o.BooleanNumber.TRUE}),this}setGridLinesColor(e){return this._commandService.syncExecuteCommand(a.SetGridlinesColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getGridLinesColor(){return this._worksheet.getGridlinesColor()}setTabColor(e){return this._commandService.syncExecuteCommand(a.SetTabColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getTabColor(){return this._worksheet.getTabColor()}onCellDataChange(e){return this._injector.get(o.ICommandService).onCommandExecuted(i=>{if(i.id===a.SetRangeValuesMutation.id){const r=i.params;r.unitId===this._workbook.getUnitId()&&r.subUnitId===this._worksheet.getSheetId()&&r.cellValue&&e(new o.ObjectMatrix(r.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(o.ICommandService).beforeCommandExecuted(i=>{if(i.id===a.SetRangeValuesMutation.id){const r=i.params;r.unitId===this._workbook.getUnitId()&&r.subUnitId===this._worksheet.getSheetId()&&r.cellValue&&e(new o.ObjectMatrix(r.cellValue))}})}hideSheet(){const e=this._injector.get(o.ICommandService);if(this._workbook.getSheets().filter(s=>s.isSheetHidden()!==o.BooleanNumber.TRUE).length<=1)throw new Error("Cannot hide the only visible sheet");return e.syncExecuteCommand(a.SetWorksheetHideCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}showSheet(){return this._injector.get(o.ICommandService).syncExecuteCommand(a.SetWorksheetShowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}isSheetHidden(){return this._worksheet.isSheetHidden()===o.BooleanNumber.TRUE}setName(e){return this._commandService.syncExecuteCommand(a.SetWorksheetNameCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),name:e}),this}activate(){return this._fWorkbook.setActiveSheet(this),this}getIndex(){return this._workbook.getSheetIndex(this._worksheet)}clear(e){e&&e.contentsOnly&&!e.formatOnly&&this.clearContents(),e&&e.formatOnly&&!e.contentsOnly&&this.clearFormats();const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r=this._injector.get(o.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return r.syncExecuteCommand(a.ClearSelectionAllCommand.id,{unitId:t,subUnitId:i,ranges:[s],options:e}),this}clearContents(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),i=this._injector.get(o.ICommandService),r={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return i.syncExecuteCommand(a.ClearSelectionContentCommand.id,{unitId:e,subUnitId:t,ranges:[r]}),this}clearFormats(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),i=this._injector.get(o.ICommandService),r={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return i.syncExecuteCommand(a.ClearSelectionFormatCommand.id,{unitId:e,subUnitId:t,ranges:[r]}),this}getDataRange(){const e=this.getLastRows(),t=this.getLastColumns();return this.getRange(0,0,e+1,t+1)}getLastColumns(){return this._worksheet.getLastColumnWithContent()}getLastColumn(){return this._worksheet.getLastColumnWithContent()}getLastRows(){return this._worksheet.getLastRowWithContent()}getLastRow(){return this._worksheet.getLastRowWithContent()}equalTo(e){return e instanceof m.FWorksheet?this._worksheet.getSheetId()===e.getSheetId()&&this._workbook.getUnitId()===e.getWorkbook().getUnitId():!1}insertDefinedName(e,t){const r=this._injector.createInstance(I).setName(e).setRef(t).build();r.localSheetId=this.getSheetId(),this._fWorkbook.insertDefinedNameBuilder(r)}getDefinedNames(){return this._fWorkbook.getDefinedNames().filter(t=>t.getLocalSheetId()===this.getSheetId())}setCustomMetadata(e){return this._worksheet.setCustomMetadata(e),this}setRowCustomMetadata(e,t){return this._worksheet.getRowManager().setCustomMetadata(e,t),this}setColumnCustomMetadata(e,t){return this._worksheet.getColumnManager().setCustomMetadata(e,t),this}getRowCustomMetadata(e){return this._worksheet.getRowManager().getCustomMetadata(e)}getColumnCustomMetadata(e){return this._worksheet.getColumnManager().getCustomMetadata(e)}getMergeData(){return this._worksheet.getMergeData().map(e=>this._injector.createInstance(m.FRange,this._workbook,this._worksheet,e))}},m.FWorksheet=X([y(3,o.Inject(o.Injector)),y(4,o.Inject(a.SheetsSelectionsService)),y(5,o.Inject(o.ILogService)),y(6,o.ICommandService)],m.FWorksheet);var Z=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=(c,n,e,t)=>{for(var i=t>1?void 0:t?ee(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&Z(n,e,i),i},S=(c,n)=>(e,t)=>n(e,t,c);m.FWorkbook=class extends o.FBaseInitialable{constructor(e,t,i,r,s,h,d,u,l,g){super(t);v(this,"id");this._workbook=e,this._injector=t,this._resourceLoaderService=i,this._selectionManagerService=r,this._univerInstanceService=s,this._commandService=h,this._permissionService=d,this._logService=u,this._localeService=l,this._definedNamesService=g,this.id=this._workbook.getUnitId()}getWorkbook(){return this._workbook}getId(){return this.id}getName(){return this._workbook.name}setName(e){this._workbook.setName(e)}save(){return this._resourceLoaderService.saveUnit(this._workbook.getUnitId())}getSnapshot(){return this._logService.warn("use 'save' instead of 'getSnapshot'"),this.save()}getActiveSheet(){const e=this._workbook.getActiveSheet();return this._injector.createInstance(m.FWorksheet,this,this._workbook,e)}getSheets(){return this._workbook.getSheets().map(e=>this._injector.createInstance(m.FWorksheet,this,this._workbook,e))}create(e,t,i){const r=o.mergeWorksheetSnapshotWithDefault({});r.rowCount=t,r.columnCount=i,r.name=e,r.id=e.toLowerCase().replace(/ /g,"-"),this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{unitId:this.id,index:this._workbook.getSheets().length,sheet:r}),this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId()});const s=this._workbook.getActiveSheet();if(!s)throw new Error("No active sheet found");return this._injector.createInstance(m.FWorksheet,this,this._workbook,s)}getSheetBySheetId(e){const t=this._workbook.getSheetBySheetId(e);return t?this._injector.createInstance(m.FWorksheet,this,this._workbook,t):null}getSheetByName(e){const t=this._workbook.getSheetBySheetName(e);return t?this._injector.createInstance(m.FWorksheet,this,this._workbook,t):null}setActiveSheet(e){return this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:typeof e=="string"?e:e.getSheetId()}),typeof e=="string"?this.getSheetBySheetId(e):e}insertSheet(e){e!=null?this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{sheet:{name:e}}):this._commandService.syncExecuteCommand(a.InsertSheetCommand.id);const t=this.id,i=this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId();this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:t,subUnitId:i});const r=this._workbook.getActiveSheet();if(!r)throw new Error("No active sheet found");return this._injector.createInstance(m.FWorksheet,this,this._workbook,r)}deleteSheet(e){const t=this.id,i=typeof e=="string"?e:e.getSheetId();return this._commandService.syncExecuteCommand(a.RemoveSheetCommand.id,{unitId:t,subUnitId:i})}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(o.UndoCommand.id),this}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(o.RedoCommand.id),this}onBeforeCommandExecute(e){return this._commandService.beforeCommandExecuted(t=>{var i;((i=t.params)==null?void 0:i.unitId)===this.id&&e(t)})}onCommandExecuted(e){return this._commandService.onCommandExecuted(t=>{var i;((i=t.params)==null?void 0:i.unitId)===this.id&&e(t)})}onSelectionChange(e){return o.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(t=>{this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET).getUnitId()===this.id&&(t!=null&&t.length?e(t.map(i=>i.range)):e([]))}))}setEditable(e){const t=new a.WorkbookEditablePermission(this._workbook.getUnitId());return this._permissionService.getPermissionPoint(t.id)||this._permissionService.addPermissionPoint(t),this._permissionService.updatePermissionPoint(t.id,e),this}setActiveRange(e){const t=this.getActiveSheet(),i=e.getRange().sheetId||t.getSheetId(),r=i?this._workbook.getSheetBySheetId(i):this._workbook.getActiveSheet(!0);if(!r)throw new Error("No active sheet found");r.getSheetId()!==t.getSheetId()&&this.setActiveSheet(this._injector.createInstance(m.FWorksheet,this,this._workbook,r));const s={unitId:this.getId(),subUnitId:i,selections:[e].map(h=>({range:h.getRange(),primary:a.getPrimaryForRange(h.getRange(),r),style:null}))};return this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,s),this}getActiveRange(){const e=this._workbook.getActiveSheet(),i=this._selectionManagerService.getCurrentSelections().find(r=>!!r.primary);return i?this._injector.createInstance(m.FRange,this._workbook,e,i.range):null}deleteActiveSheet(){const e=this.getActiveSheet();return this.deleteSheet(e)}duplicateSheet(e){return this._commandService.syncExecuteCommand(a.CopySheetCommand.id,{unitId:e.getWorkbook().getUnitId(),subUnitId:e.getSheetId()}),this._injector.createInstance(m.FWorksheet,this,this._workbook,this._workbook.getActiveSheet())}duplicateActiveSheet(){const e=this.getActiveSheet();return this.duplicateSheet(e)}getNumSheets(){return this._workbook.getSheets().length}getLocale(){return this._localeService.getCurrentLocale()}setLocale(e){this._localeService.setLocale(e)}setSpreadsheetLocale(e){return this._localeService.setLocale(e),this}getUrl(){return location.href}moveSheet(e,t){let i=t;return i<0?i=0:i>this._workbook.getSheets().length-1&&(i=this._workbook.getSheets().length-1),this._commandService.syncExecuteCommand(a.SetWorksheetOrderCommand.id,{unitId:e.getWorkbook().getUnitId(),order:i,subUnitId:e.getSheetId()}),this}moveActiveSheet(e){const t=this.getActiveSheet();return this.moveSheet(t,e)}getPermission(){return this._injector.createInstance(m.FPermission)}getDefinedName(e){const t=this._definedNamesService.getValueByName(this.id,e);return t?this._injector.createInstance(R,{...t,unitId:this.id}):null}getDefinedNames(){const e=this._definedNamesService.getDefinedNameMap(this.id);return e?Object.values(e).map(t=>this._injector.createInstance(R,{...t,unitId:this.id})):[]}insertDefinedName(e,t){const r=this._injector.createInstance(I).setName(e).setRef(t).build();return r.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this.insertDefinedNameBuilder(r),this}deleteDefinedName(e){const t=this.getDefinedName(e);return t?(t.delete(),!0):!1}insertDefinedNameBuilder(e){e.unitId=this.getId(),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}updateDefinedNameBuilder(e){this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}getRegisteredRangeThemes(){return this._injector.get(a.SheetRangeThemeService).getRegisteredRangeThemes()}registerRangeTheme(e){this._commandService.syncExecuteCommand(a.RegisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),rangeThemeStyle:e})}unregisterRangeTheme(e){this._commandService.syncExecuteCommand(a.UnregisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),themeName:e})}setCustomMetadata(e){return this._workbook.setCustomMetadata(e),this}getCustomMetadata(){return this._workbook.getCustomMetadata()}},m.FWorkbook=te([S(1,o.Inject(o.Injector)),S(2,o.Inject(o.IResourceLoaderService)),S(3,o.Inject(a.SheetsSelectionsService)),S(4,o.IUniverInstanceService),S(5,o.ICommandService),S(6,o.IPermissionService),S(7,o.ILogService),S(8,o.Inject(o.LocaleService)),S(9,C.IDefinedNamesService)],m.FWorkbook);class ne extends o.FUniver{getCommandSheetTarget(n){var r;const e=n.params;if(!e)return;const t=e.unitId?this.getUniverSheet(e.unitId):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!t)return;const i=t.getSheetBySheetId(e.subUnitId||e.sheetId)||t.getActiveSheet();if(i)return{workbook:t,worksheet:i}}getSheetTarget(n,e){const t=this.getUniverSheet(n);if(!t)return;const i=t.getSheetBySheetId(e);if(i)return{workbook:t,worksheet:i}}_initWorkbookEvent(n){const e=n.get(o.IUniverInstanceService);this.disposeWithMe(e.unitDisposed$.subscribe(t=>{this._eventRegistry.get(this.Event.WorkbookDisposed)&&t.type===o.UniverInstanceType.UNIVER_SHEET&&this.fireEvent(this.Event.WorkbookDisposed,{unitId:t.getUnitId(),unitType:t.type,snapshot:t.getSnapshot()})})),this.disposeWithMe(e.unitAdded$.subscribe(t=>{if(this._eventRegistry.get(this.Event.WorkbookCreated)&&t.type===o.UniverInstanceType.UNIVER_SHEET){const i=t,r=n.createInstance(m.FWorkbook,i);this.fireEvent(this.Event.WorkbookCreated,{unitId:t.getUnitId(),type:t.type,workbook:r,unit:r})}}))}_initialize(n){const e=n.get(o.ICommandService);this.disposeWithMe(e.beforeCommandExecuted(t=>{var i,r,s,h;switch(t.id){case a.InsertSheetCommand.id:{const d=t.params,{unitId:u,index:l,sheet:g}=d||{},k=u?this.getUniverSheet(u):(i=this.getActiveWorkbook)==null?void 0:i.call(this);if(!k)return;const f={workbook:k,index:l,sheet:g};if(this.fireEvent(this.Event.BeforeSheetCreate,f),f.cancel)throw new o.CanceledError;break}case a.SetWorksheetActivateCommand.id:{if(!this._eventListend(this.Event.BeforeActiveSheetChange))return;const{subUnitId:d,unitId:u}=t.params,l=u?this.getUniverSheet(u):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!l||!d)return;const g=l.getSheetBySheetId(d),k=l.getActiveSheet();if(!g||!k)return;this._fireBeforeActiveSheetChange(l,g,k);break}case a.RemoveSheetCommand.id:{if(!this._eventListend(this.Event.BeforeSheetDelete))return;const d=this.getCommandSheetTarget(t);if(!d)return;const{workbook:u,worksheet:l}=d;this._fireBeforeSheetDelete(u,l);break}case a.SetWorksheetOrderCommand.id:{if(!this._eventListend(this.Event.BeforeSheetMove))return;const{fromOrder:d,toOrder:u}=t.params,l=this.getCommandSheetTarget(t);if(!l)return;this._fireBeforeSheetMove(l.workbook,l.worksheet,u,d);break}case a.SetWorksheetNameCommand.id:{if(!this._eventListend(this.Event.BeforeSheetNameChange))return;const{name:d}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetNameChange(u.workbook,u.worksheet,d,u.worksheet.getSheetName());break}case a.SetTabColorCommand.id:{if(!this._eventListend(this.Event.BeforeSheetTabColorChange))return;const{color:d}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetTabColorChange(u.workbook,u.worksheet,d,u.worksheet.getTabColor());break}case a.SetWorksheetHideCommand.id:{if(!this._eventListend(this.Event.BeforeSheetHideChange))return;const{hidden:d}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetHideChange(u.workbook,u.worksheet,!!d);break}case a.SetGridlinesColorCommand.id:{if(!this._eventListend(this.Event.BeforeGridlineColorChange))return;const d=this.getCommandSheetTarget(t);if(!d)return;this.fireEvent(this.Event.BeforeGridlineColorChange,{...d,color:(s=t.params)==null?void 0:s.color});break}case a.ToggleGridlinesCommand.id:{if(!this._eventListend(this.Event.BeforeGridlineEnableChange))return;const d=this.getCommandSheetTarget(t);if(!d)return;this.fireEvent(this.Event.BeforeGridlineEnableChange,{...d,enabled:!!((h=t.params)!=null&&h.showGridlines)});break}}})),this.disposeWithMe(e.onCommandExecuted(t=>{var i,r;if(a.COMMAND_LISTENER_VALUE_CHANGE.indexOf(t.id)>-1){if(!this._eventListend(this.Event.SheetValueChanged)||!this.getActiveSheet())return;const h=a.getValueChangedEffectedRange(t).map(d=>{var u,l;return(l=(u=this.getWorkbook(d.unitId))==null?void 0:u.getSheetBySheetId(d.subUnitId))==null?void 0:l.getRange(d.range)}).filter(Boolean);if(!h.length)return;this.fireEvent(this.Event.SheetValueChanged,{payload:t,effectedRanges:h});return}switch(t.id){case a.InsertSheetCommand.id:{const s=t.params,{unitId:h}=s||{},d=h?this.getUniverSheet(h):(i=this.getActiveWorkbook)==null?void 0:i.call(this);if(!d)return;const u=d.getActiveSheet();if(!u)return;const l={workbook:d,worksheet:u};this.fireEvent(this.Event.SheetCreated,l);break}case a.SetWorksheetActivateCommand.id:{if(!this._eventListend(this.Event.ActiveSheetChanged))return;const s=this.getActiveSheet();if(!s)return;const{workbook:h,worksheet:d}=s;this._fireActiveSheetChanged(h,d);break}case a.RemoveSheetCommand.id:{if(!this._eventListend(this.Event.SheetDeleted))return;const{subUnitId:s,unitId:h}=t.params,d=h?this.getUniverSheet(h):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!d||!s)return;this._fireSheetDeleted(d,s);break}case a.SetWorksheetOrderCommand.id:{if(!this._eventListend(this.Event.SheetMoved))return;const{toOrder:s}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetMoved(h.workbook,h.worksheet,s);break}case a.SetWorksheetNameCommand.id:{if(!this._eventListend(this.Event.SheetNameChanged))return;const{name:s}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetNameChanged(h.workbook,h.worksheet,s);break}case a.SetTabColorCommand.id:{if(!this._eventListend(this.Event.SheetTabColorChanged))return;const{color:s}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetTabColorChanged(h.workbook,h.worksheet,s);break}case a.SetWorksheetHideCommand.id:{if(!this._eventListend(this.Event.SheetHideChanged))return;const{hidden:s}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetHideChanged(h.workbook,h.worksheet,!!s);break}case a.SetGridlinesColorCommand.id:case a.ToggleGridlinesCommand.id:{if(!this._eventListend(this.Event.GridlineChanged))return;const s=this.getCommandSheetTarget(t);if(!s)return;this.fireEvent(this.Event.GridlineChanged,{...s,enabled:!s.worksheet.hasHiddenGridLines(),color:s.worksheet.getGridLinesColor()});break}}})),this._initWorkbookEvent(n)}createUniverSheet(n){const t=this._injector.get(o.IUniverInstanceService).createUnit(o.UniverInstanceType.UNIVER_SHEET,n);return this._injector.createInstance(m.FWorkbook,t)}createWorkbook(n){return this.createUniverSheet(n)}getActiveWorkbook(){const n=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);return n?this._injector.createInstance(m.FWorkbook,n):null}getActiveUniverSheet(){return this.getActiveWorkbook()}getUniverSheet(n){const e=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET);return e?this._injector.createInstance(m.FWorkbook,e):null}getWorkbook(n){return this.getUniverSheet(n)}getPermission(){return this._injector.createInstance(m.FPermission)}onUniverSheetCreated(n){const e=this._univerInstanceService.getTypeOfUnitAdded$(o.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{const i=this._injector.createInstance(m.FWorkbook,t);n(i)});return o.toDisposable(e)}newDefinedName(){return this._injector.createInstance(I)}getActiveSheet(){const n=this.getActiveWorkbook();if(!n)return null;const e=n.getActiveSheet();return e?{workbook:n,worksheet:e}:null}_fireBeforeActiveSheetChange(n,e,t){this.fireEvent(this.Event.BeforeActiveSheetChange,{workbook:n,activeSheet:e,oldActiveSheet:t})}_fireActiveSheetChanged(n,e){this.fireEvent(this.Event.ActiveSheetChanged,{workbook:n,activeSheet:e})}_fireBeforeSheetDelete(n,e){this.fireEvent(this.Event.BeforeSheetDelete,{workbook:n,worksheet:e})}_fireSheetDeleted(n,e){this.fireEvent(this.Event.SheetDeleted,{workbook:n,sheetId:e})}_fireBeforeSheetMove(n,e,t,i){this.fireEvent(this.Event.BeforeSheetMove,{workbook:n,worksheet:e,newIndex:t,oldIndex:i})}_fireSheetMoved(n,e,t){this.fireEvent(this.Event.SheetMoved,{workbook:n,worksheet:e,newIndex:t})}_fireBeforeSheetNameChange(n,e,t,i){this.fireEvent(this.Event.BeforeSheetNameChange,{workbook:n,worksheet:e,newName:t,oldName:i})}_fireSheetNameChanged(n,e,t){this.fireEvent(this.Event.SheetNameChanged,{workbook:n,worksheet:e,newName:t})}_fireBeforeSheetTabColorChange(n,e,t,i){this.fireEvent(this.Event.BeforeSheetTabColorChange,{workbook:n,worksheet:e,newColor:t,oldColor:i})}_fireSheetTabColorChanged(n,e,t){this.fireEvent(this.Event.SheetTabColorChanged,{workbook:n,worksheet:e,newColor:t})}_fireBeforeSheetHideChange(n,e,t){this.fireEvent(this.Event.BeforeSheetHideChange,{workbook:n,worksheet:e,hidden:t})}_fireSheetHideChanged(n,e,t){this.fireEvent(this.Event.SheetHideChanged,{workbook:n,worksheet:e,hidden:t})}}o.FUniver.extend(ne);class N{get SheetValueChangeType(){return a.SheetValueChangeType}get SheetSkeletonChangeType(){return a.SheetSkeletonChangeType}}o.FEnum.extend(N);class T extends o.FEventName{get SheetCreated(){return"SheetCreated"}get BeforeSheetCreate(){return"BeforeSheetCreate"}get WorkbookCreated(){return"WorkbookCreated"}get WorkbookDisposed(){return"WorkbookDisposed"}get GridlineChanged(){return"GridlineChanged"}get BeforeGridlineEnableChange(){return"BeforeGridlineEnableChange"}get BeforeGridlineColorChange(){return"BeforeGridlineColorChange"}get BeforeActiveSheetChange(){return"BeforeActiveSheetChange"}get ActiveSheetChanged(){return"ActiveSheetChanged"}get SheetDeleted(){return"SheetDeleted"}get BeforeSheetDelete(){return"BeforeSheetDelete"}get SheetMoved(){return"SheetMoved"}get BeforeSheetMove(){return"BeforeSheetMove"}get SheetNameChanged(){return"SheetNameChanged"}get BeforeSheetNameChange(){return"BeforeSheetNameChange"}get SheetTabColorChanged(){return"SheetTabColorChanged"}get BeforeSheetTabColorChange(){return"BeforeSheetTabColorChange"}get SheetHideChanged(){return"SheetHideChanged"}get BeforeSheetHideChange(){return"BeforeSheetHideChange"}get SheetValueChanged(){return"SheetValueChanged"}}o.FEventName.extend(T);var ie=Object.defineProperty,re=Object.getOwnPropertyDescriptor,oe=(c,n,e,t)=>{for(var i=t>1?void 0:t?re(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&ie(n,e,i),i},se=(c,n)=>(e,t)=>n(e,t,c);m.FSheetHooks=class extends o.FBase{constructor(n){super(),this._injector=n}},m.FSheetHooks=oe([se(0,o.Inject(o.Injector))],m.FSheetHooks),m.FSheetEventName=T,m.FSheetsEnum=N,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
(function(m,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-formula"],o):(m=typeof globalThis<"u"?globalThis:m||self,o(m.UniverSheetsFacade={},m.UniverCore,m.UniverSheets,m.UniverEngineFormula))})(this,function(m,o,a,C){"use strict";var ae=Object.defineProperty;var he=(m,o,a)=>o in m?ae(m,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):m[o]=a;var v=(m,o,a)=>he(m,typeof o!="symbol"?o+"":o,a);var W=Object.defineProperty,A=Object.getOwnPropertyDescriptor,F=(c,n,e,t)=>{for(var i=t>1?void 0:t?A(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&W(n,e,i),i},_=(c,n)=>(e,t)=>n(e,t,c);function M(c,n,e){const t=e.getDefinedNameMap(c);if(t==null)return n.t("definedName.defaultName")+1;const r=Array.from(Object.values(t)).length+1,s=n.t("definedName.defaultName")+r;if(e.getValueByName(c,s)==null)return s;let h=r+1;for(;;){const d=n.t("definedName.defaultName")+h;if(e.getValueByName(c,d)==null)return d;h++}}class I{constructor(){v(this,"_definedNameParam");this._definedNameParam={id:o.generateRandomId(10),unitId:"",name:"",formulaOrRefString:""}}setName(n){return this._definedNameParam.name=n,this}setFormula(n){return this._definedNameParam.formulaOrRefString=`=${n}`,this}setRef(n){return this._definedNameParam.formulaOrRefString=n,this}setRefByRange(n,e,t,i){return this._definedNameParam.formulaOrRefString=C.serializeRange({startRow:n,endRow:n+(t!=null?t:1)-1,startColumn:e,endColumn:e+(i!=null?i:1)-1}),this}setComment(n){return this._definedNameParam.comment=n,this}setHidden(n){return this._definedNameParam.hidden=n,this}build(){return this._definedNameParam}load(n){return this._definedNameParam=n,this}}let R=class extends o.FBase{constructor(c,n,e,t,i,r,s,h,d,u){super(),this._definedNameParam=c,this._injector=n,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=i,this._rangeProtectionRuleModel=r,this._worksheetProtectionPointRuleModel=s,this._authzIoService=h,this._localeService=d,this._definedNamesService=u}_apply(){this._definedNameParam.name===""&&(this._definedNameParam.name=M(this._definedNameParam.unitId,this._localeService,this._definedNamesService)),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,this._definedNameParam)}getName(){return this._definedNameParam.name}setName(c){this._definedNameParam.name=c,this._apply()}setFormula(c){this._definedNameParam.formulaOrRefString=`=${c}`,this._apply()}setRef(c){this._definedNameParam.formulaOrRefString=c,this._apply()}getFormulaOrRefString(){return this._definedNameParam.formulaOrRefString}setRefByRange(c,n,e,t){this._definedNameParam.formulaOrRefString=C.serializeRange({startRow:c,endRow:c+(e!=null?e:1)-1,startColumn:n,endColumn:n+(t!=null?t:1)-1}),this._apply()}getComment(){return this._definedNameParam.comment}setComment(c){this._definedNameParam.comment=c,this._apply()}setScopeToWorksheet(c){this._definedNameParam.localSheetId=c.getSheetId(),this._apply()}setScopeToWorkbook(){this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this._apply()}setHidden(c){this._definedNameParam.hidden=c,this._apply()}delete(){this._commandService.syncExecuteCommand(a.RemoveDefinedNameCommand.id,this._definedNameParam)}getLocalSheetId(){return this._definedNameParam.localSheetId}isWorkbookScope(){return this._definedNameParam.localSheetId===a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}toBuilder(){const c=this._injector.createInstance(I);return c.load(this._definedNameParam),c}};R=F([_(1,o.Inject(o.Injector)),_(2,o.ICommandService),_(3,o.IPermissionService),_(4,o.Inject(a.WorksheetProtectionRuleModel)),_(5,o.Inject(a.RangeProtectionRuleModel)),_(6,o.Inject(a.WorksheetProtectionPointModel)),_(7,o.Inject(o.IAuthzIoService)),_(8,o.Inject(o.LocaleService)),_(9,C.IDefinedNamesService)],R);var B=Object.defineProperty,D=Object.getOwnPropertyDescriptor,j=(c,n,e,t)=>{for(var i=t>1?void 0:t?D(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&B(n,e,i),i},w=(c,n)=>(e,t)=>n(e,t,c);m.FPermission=class extends o.FBase{constructor(e,t,i,r,s,h,d){super();v(this,"permissionPointsDefinition",a.PermissionPointsDefinitions);v(this,"rangeRuleChangedAfterAuth$");v(this,"sheetRuleChangedAfterAuth$");this._injector=e,this._commandService=t,this._permissionService=i,this._worksheetProtectionRuleModel=r,this._rangeProtectionRuleModel=s,this._worksheetProtectionPointRuleModel=h,this._authzIoService=d,this.rangeRuleChangedAfterAuth$=this._rangeProtectionRuleModel.ruleRefresh$,this.sheetRuleChangedAfterAuth$=this._worksheetProtectionRuleModel.ruleRefresh$}setWorkbookPermissionPoint(e,t,i){const r=new t(e);this._permissionService.getPermissionPoint(r.id)||this._permissionService.addPermissionPoint(r),this._permissionService.updatePermissionPoint(r.id,i)}setWorkbookEditPermission(e,t){this.setWorkbookPermissionPoint(e,a.WorkbookEditablePermission,t)}async addWorksheetBasePermission(e,t){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");const r=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}});if(this._commandService.syncExecuteCommand(a.AddWorksheetProtectionMutation.id,{unitId:e,subUnitId:t,rule:{permissionId:r,unitType:a.UnitObject.Worksheet,unitId:e,subUnitId:t}}))return r}removeWorksheetPermission(e,t){this._commandService.syncExecuteCommand(a.DeleteWorksheetProtectionMutation.id,{unitId:e,subUnitId:t}),[...a.getAllWorksheetPermissionPoint(),...a.getAllWorksheetPermissionPointByPointPanel()].forEach(i=>{const r=new i(e,t);this._permissionService.updatePermissionPoint(r.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e,t)}async setWorksheetPermissionPoint(e,t,i,r){const s=this._worksheetProtectionRuleModel.getRule(e,t);let h;if(i===a.WorksheetEditPermission||i===a.WorksheetViewPermission)if(s)h=s.permissionId;else{if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");h=await this.addWorksheetBasePermission(e,t)}else{const g=this._worksheetProtectionPointRuleModel.getRule(e,t);g?h=g.permissionId:(h=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}}),this._commandService.syncExecuteCommand(a.SetWorksheetPermissionPointsMutation.id,{unitId:e,subUnitId:t,rule:{unitId:e,subUnitId:t,permissionId:h}}))}const u=new i(e,t);return this._permissionService.getPermissionPoint(u.id)||this._permissionService.addPermissionPoint(u),this._permissionService.updatePermissionPoint(u.id,r),h}async addRangeBaseProtection(e,t,i){const r=await this._authzIoService.create({objectType:a.UnitObject.SelectRange,selectRangeObject:{collaborators:[],unitID:e,name:"",scope:void 0}}),s=`ruleId_${o.generateRandomId(6)}`;if(this._worksheetProtectionRuleModel.getRule(e,t))throw new Error("sheet protection cannot intersect with range protection");if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).some(g=>g.ranges.some(k=>i.some(f=>o.Rectangle.intersects(f.getRange(),k)))))throw new Error("range protection cannot intersect");if(this._commandService.syncExecuteCommand(a.AddRangeProtectionMutation.id,{unitId:e,subUnitId:t,rules:[{permissionId:r,unitType:a.UnitObject.SelectRange,unitId:e,subUnitId:t,ranges:i.map(g=>g.getRange()),id:s}]}))return{permissionId:r,ruleId:s}}removeRangeProtection(e,t,i){this._commandService.syncExecuteCommand(a.DeleteRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleIds:i})&&this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length===0&&(this._worksheetProtectionPointRuleModel.deleteRule(e,t),[...a.getAllWorksheetPermissionPointByPointPanel()].forEach(h=>{const d=new h(e,t);this._permissionService.updatePermissionPoint(d.id,d.value)}))}setRangeProtectionPermissionPoint(e,t,i,r,s){const h=new r(e,t,i);this._permissionService.getPermissionPoint(h.id)||this._permissionService.addPermissionPoint(h),this._permissionService.updatePermissionPoint(h.id,s)}setRangeProtectionRanges(e,t,i,r){const s=this._rangeProtectionRuleModel.getRule(e,t,i);if(s){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).filter(u=>u.id!==i).some(u=>u.ranges.some(l=>r.some(g=>o.Rectangle.intersects(g.getRange(),l)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(a.SetRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleId:i,rule:{...s,ranges:r.map(u=>u.getRange())}})}}},m.FPermission=j([w(0,o.Inject(o.Injector)),w(1,o.ICommandService),w(2,o.IPermissionService),w(3,o.Inject(a.WorksheetProtectionRuleModel)),w(4,o.Inject(a.RangeProtectionRuleModel)),w(5,o.Inject(a.WorksheetProtectionPointModel)),w(6,o.Inject(o.IAuthzIoService))],m.FPermission);function x(c){switch(c){case"left":return o.HorizontalAlign.LEFT;case"center":return o.HorizontalAlign.CENTER;case"normal":return o.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${c}`)}}function O(c){switch(c){case o.HorizontalAlign.LEFT:return"left";case o.HorizontalAlign.CENTER:return"center";case o.HorizontalAlign.RIGHT:return"normal";default:throw new Error(`Invalid horizontal alignment: ${c}`)}}function V(c){switch(c){case"top":return o.VerticalAlign.TOP;case"middle":return o.VerticalAlign.MIDDLE;case"bottom":return o.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${c}`)}}function L(c){switch(c){case o.VerticalAlign.TOP:return"top";case o.VerticalAlign.MIDDLE:return"middle";case o.VerticalAlign.BOTTOM:return"bottom";default:throw new Error(`Invalid vertical alignment: ${c}`)}}function b(c){return o.isFormulaString(c)?{f:c,v:null,p:null}:o.isCellV(c)?{v:c,p:null,f:null}:(o.isICellData(c),c)}function P(c,n){const e=new o.ObjectMatrix,{startRow:t,startColumn:i,endRow:r,endColumn:s}=n;if(o.Tools.isArray(c))for(let h=0;h<=r-t;h++)for(let d=0;d<=s-i;d++)e.setValue(h+t,d+i,b(c[h][d]));else new o.ObjectMatrix(c).forValue((d,u,l)=>{e.setValue(d,u,b(l))});return e.getMatrix()}function E(c,n){return{startRow:c.startRow,endRow:c.endRow,startColumn:0,endColumn:n.getColumnCount()-1,rangeType:o.RANGE_TYPE.ROW}}function p(c,n){return{startRow:0,endRow:n.getRowCount()-1,startColumn:c.startColumn,endColumn:c.endColumn,rangeType:o.RANGE_TYPE.COLUMN}}var H=Object.defineProperty,z=Object.getOwnPropertyDescriptor,G=(c,n,e,t)=>{for(var i=t>1?void 0:t?z(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&H(n,e,i),i},U=(c,n)=>(e,t)=>n(e,t,c);m.FRange=class extends o.FBaseInitialable{constructor(n,e,t,i,r,s){super(i),this._workbook=n,this._worksheet=e,this._range=t,this._injector=i,this._commandService=r,this._formulaDataModel=s}getUnitId(){return this._workbook.getUnitId()}getSheetName(){return this._worksheet.getName()}getSheetId(){return this._worksheet.getSheetId()}getRange(){return this._range}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}isMerged(){const{startColumn:n,startRow:e,endColumn:t,endRow:i}=this._range;return this._worksheet.getMergedCellRange(e,n,i,t).some(s=>o.Rectangle.equals(s,this._range))}getCellStyleData(){var t;const n=this.getCellData(),e=this._workbook.getStyles();return n&&e&&(t=e.getStyleByCell(n))!=null?t:null}getCellStyle(){const n=this.getCellStyleData();return n?o.TextStyleValue.create(n):null}getCellStyles(){const n=this.getCellDatas(),e=this._workbook.getStyles();return n.map(t=>t.map(i=>{if(!i)return null;const r=e.getStyleByCell(i);return r?o.TextStyleValue.create(r):null}))}getValue(n){var e,t;return n?this.getValueAndRichTextValue():(t=(e=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:e.v)!=null?t:null}getValues(n){var h,d;n&&this.getValueAndRichTextValues();const{startRow:e,endRow:t,startColumn:i,endColumn:r}=this._range,s=[];for(let u=e;u<=t;u++){const l=[];for(let g=i;g<=r;g++)l.push((d=(h=this._worksheet.getCell(u,g))==null?void 0:h.v)!=null?d:null);s.push(l)}return s}getCellData(){var n;return(n=this._worksheet.getCell(this._range.startRow,this._range.startColumn))!=null?n:null}getCellDatas(){return this.getCellDataGrid()}getCellDataGrid(){const{startRow:n,endRow:e,startColumn:t,endColumn:i}=this._range,r=[];for(let s=n;s<=e;s++){const h=[];for(let d=t;d<=i;d++)h.push(this._worksheet.getCellRaw(s,d));r.push(h)}return r}getRichTextValue(){const n=this.getCellData();return n!=null&&n.p?new o.RichTextValue(n.p):null}getRichTextValues(){return this.getCellDataGrid().map(e=>e.map(t=>t!=null&&t.p?new o.RichTextValue(t.p):null))}getValueAndRichTextValue(){const n=this.getCellData();return n!=null&&n.p?new o.RichTextValue(n.p):n==null?void 0:n.v}getValueAndRichTextValues(){return this.getCellDatas().map(e=>e.map(t=>t!=null&&t.p?new o.RichTextValue(t.p):t==null?void 0:t.v))}getFormulas(){const n=[],{startRow:e,endRow:t,startColumn:i,endColumn:r}=this._range,s=this._worksheet.getSheetId(),h=this._workbook.getUnitId();for(let d=e;d<=t;d++){const u=[];for(let l=i;l<=r;l++){const g=this._formulaDataModel.getFormulaStringByCell(d,l,s,h);u.push(g||"")}n.push(u)}return n}getWrap(){return this._worksheet.getRange(this._range).getWrap()===o.BooleanNumber.TRUE}getWrapStrategy(){return this._worksheet.getRange(this._range).getWrapStrategy()}getHorizontalAlignment(){return O(this._worksheet.getRange(this._range).getHorizontalAlignment())}getVerticalAlignment(){return L(this._worksheet.getRange(this._range).getVerticalAlignment())}setCustomMetaData(n){return this.setValue({custom:n})}setCustomMetaDatas(n){return this.setValues(n.map(e=>e.map(t=>({custom:t}))))}getCustomMetaData(){var e;const n=this.getCellData();return(e=n==null?void 0:n.custom)!=null?e:null}getCustomMetaDatas(){return this.getCellDataGrid().map(e=>e.map(t=>{var i;return(i=t==null?void 0:t.custom)!=null?i:null}))}setBorder(n,e,t){return this._commandService.syncExecuteCommand(a.SetBorderBasicCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),value:{type:n,style:e,color:t}}),this}setBackgroundColor(n){return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:n}}}),this}setBackground(n){return this.setBackgroundColor(n),this}setValue(n){const e=b(n);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setValueForCell(n){const e=b(n);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.endColumn,endRow:this._range.endRow},value:e}),this}setRichTextValueForCell(n){const e=n instanceof o.RichTextValue?n.getData():n,t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.endColumn,endRow:this._range.endRow},value:{p:e}};return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,t),this}setRichTextValues(n){const e=n.map(r=>r.map(s=>s&&{p:s instanceof o.RichTextValue?s.getData():s})),t=P(e,this._range),i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:t};return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,i),this}setWrap(n){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:n?o.WrapStrategy.WRAP:o.WrapStrategy.UNSPECIFIED}),this}setWrapStrategy(n){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:n}),this}setVerticalAlignment(n){return this._commandService.syncExecuteCommand(a.SetVerticalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:V(n)}),this}setHorizontalAlignment(n){return this._commandService.syncExecuteCommand(a.SetHorizontalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:x(n)}),this}setValues(n){const e=P(n,this._range);return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setFontWeight(n){let e;if(n==="bold")e=o.BooleanNumber.TRUE;else if(n==="normal")e=o.BooleanNumber.FALSE;else if(n===null)e=null;else throw new Error("Invalid fontWeight");const t={type:"bl",value:e},i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,i),this}setFontStyle(n){let e;if(n==="italic")e=o.BooleanNumber.TRUE;else if(n==="normal")e=o.BooleanNumber.FALSE;else if(n===null)e=null;else throw new Error("Invalid fontStyle");const t={type:"it",value:e},i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,i),this}setFontLine(n){if(n==="underline")this._setFontUnderline({s:o.BooleanNumber.TRUE});else if(n==="line-through")this._setFontStrikethrough({s:o.BooleanNumber.TRUE});else if(n==="none")this._setFontUnderline({s:o.BooleanNumber.FALSE}),this._setFontStrikethrough({s:o.BooleanNumber.FALSE});else if(n===null)this._setFontUnderline(null),this._setFontStrikethrough(null);else throw new Error("Invalid fontLine");return this}_setFontUnderline(n){const e={type:"ul",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t)}_setFontStrikethrough(n){const e={type:"st",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t)}setFontFamily(n){const e={type:"ff",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t),this}setFontSize(n){const e={type:"fs",value:n},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t),this}setFontColor(n){const t={type:"cl",value:n===null?null:{rgb:n}},i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,i),this}merge(n=!0){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,e,t,[this._range],n),this}mergeAcross(n=!0){const e=a.getAddMergeMutationRangeByType([this._range],o.Dimension.ROWS),t=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,i,e,n),this}mergeVertically(n=!0){const e=a.getAddMergeMutationRangeByType([this._range],o.Dimension.COLUMNS),t=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,i,e,n),this}isPartOfMerge(){const{startRow:n,startColumn:e,endRow:t,endColumn:i}=this._range;return this._worksheet.getMergedCellRange(n,e,t,i).length>0}breakApart(){return this._commandService.syncExecuteCommand(a.RemoveWorksheetMergeCommand.id,{ranges:[this._range]}),this}forEach(n){const{startColumn:e,startRow:t,endColumn:i,endRow:r}=this._range;this._worksheet.getMatrixWithMergedCells(t,e,r,i).forValue((s,h,d)=>{n(s,h,d)})}getA1Notation(n){return n?C.serializeRangeWithSheet(this._worksheet.getName(),this._range):C.serializeRange(this._range)}activate(){return this._injector.createInstance(m.FWorkbook,this._workbook).setActiveRange(this),this}activateAsCurrentCell(){const n=this._worksheet.getMergedCell(this._range.startRow,this._range.startColumn);if(n&&o.Rectangle.equals(n,this._range)||!n&&this._range.startRow===this._range.endRow&&this._range.startColumn===this._range.endColumn)return this.activate();throw new Error("The range is not a single cell")}splitTextToColumns(n,e,t){this._commandService.syncExecuteCommand(a.SplitTextToColumnsCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,delimiter:e,customDelimiter:t,treatMultipleDelimitersAsOne:n})}useThemeStyle(n){if(n==null){const e=this.getUsedThemeStyle();e&&this.removeThemeStyle(e)}else this._commandService.syncExecuteCommand(a.SetWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:n})}removeThemeStyle(n){this._commandService.syncExecuteCommand(a.DeleteWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:n})}getUsedThemeStyle(){return this._injector.get(a.SheetRangeThemeService).getAppliedRangeThemeStyle({unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})}},m.FRange=G([U(3,o.Inject(o.Injector)),U(4,o.ICommandService),U(5,o.Inject(C.FormulaDataModel))],m.FRange);var $=Object.defineProperty,Y=Object.getOwnPropertyDescriptor,q=(c,n,e,t)=>{for(var i=t>1?void 0:t?Y(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&$(n,e,i),i},K=(c,n)=>(e,t)=>n(e,t,c);m.FSelection=class{constructor(n,e,t,i){this._workbook=n,this._worksheet=e,this._selections=t,this._injector=i}getActiveRange(){const n=this._selections.find(e=>!!e.primary);return n?this._injector.createInstance(m.FRange,this._workbook,this._worksheet,n.range):null}getActiveRangeList(){return this._selections.map(n=>this._injector.createInstance(m.FRange,this._workbook,this._worksheet,n.range))}getCurrentCell(){const n=this._selections.find(e=>!!e.primary);return n?n.primary:null}getActiveSheet(){const n=this._injector.createInstance(m.FWorkbook,this._workbook);return this._injector.createInstance(m.FWorksheet,n,this._workbook,this._worksheet)}updatePrimaryCell(n){const e=this._injector.get(o.ICommandService);let t=[],i=!1;for(const{range:s,style:h}of this._selections)o.Rectangle.contains(s,n.getRange())?(t.push({range:s,primary:a.getPrimaryForRange(n.getRange(),this._worksheet),style:h}),i=!0):t.push({range:s,primary:null,style:h});i||(t=[{range:n.getRange(),primary:a.getPrimaryForRange(n.getRange(),this._worksheet)}]);const r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),selections:t};return e.syncExecuteCommand(a.SetSelectionsOperation.id,r),new m.FSelection(this._workbook,this._worksheet,t,this._injector)}getNextDataRange(n){if(!this._selections.find(i=>!!i.primary))return null;const t=a.getNextPrimaryCell(this._selections.concat(),n,this._worksheet);return t?this._injector.createInstance(m.FRange,this._workbook,this._worksheet,t):null}},m.FSelection=q([K(3,o.Inject(o.Injector))],m.FSelection);var J=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,X=(c,n,e,t)=>{for(var i=t>1?void 0:t?Q(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&J(n,e,i),i},y=(c,n)=>(e,t)=>n(e,t,c);m.FWorksheet=class extends o.FBaseInitialable{constructor(e,t,i,r,s,h,d){super(r);v(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=i,this._injector=r,this._selectionManagerService=s,this._logService=h,this._commandService=d}getSheet(){return this._worksheet}getInject(){return this._injector}getWorkbook(){return this._workbook}getSheetId(){return this._worksheet.getSheetId()}getSheetName(){return this._worksheet.getName()}getSelection(){const e=this._selectionManagerService.getCurrentSelections();return e?this._injector.createInstance(m.FSelection,this._workbook,this._worksheet,e):null}getDefaultStyle(){return this._worksheet.getDefaultCellStyle()}getRowDefaultStyle(e,t=!1){return this._worksheet.getRowStyle(e,t)}getColumnDefaultStyle(e,t=!1){return this._worksheet.getColumnStyle(e,t)}setDefaultStyle(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return this._commandService.syncExecuteCommand(a.SetWorksheetDefaultStyleMutation.id,{unitId:t,subUnitId:i,defaultStyle:e}),this._worksheet.setDefaultCellStyle(e),this}setColumnDefaultStyle(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={unitId:i,subUnitId:r,columnData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,s),this}setRowDefaultStyle(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={unitId:i,subUnitId:r,rowData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,s),this}getRange(e,t,i,r){let s,h;if(typeof e=="object")s=e,h=this._worksheet;else if(typeof e=="string"){const{range:d,sheetName:u}=C.deserializeRangeWithSheet(e),l=u?this._workbook.getSheetBySheetName(u):this._worksheet;if(!l)throw new Error("Range not found");h=l,s={...d,unitId:this._workbook.getUnitId(),sheetId:h.getSheetId(),rangeType:o.RANGE_TYPE.NORMAL,startRow:d.rangeType===o.RANGE_TYPE.COLUMN?0:d.startRow,endRow:d.rangeType===o.RANGE_TYPE.COLUMN?h.getMaxRows()-1:d.endRow,startColumn:d.rangeType===o.RANGE_TYPE.ROW?0:d.startColumn,endColumn:d.rangeType===o.RANGE_TYPE.ROW?h.getMaxColumns()-1:d.endColumn}}else if(typeof e=="number"&&t!==void 0)h=this._worksheet,s={startRow:e,endRow:e+(i!=null?i:1)-1,startColumn:t,endColumn:t+(r!=null?r:1)-1,unitId:this._workbook.getUnitId(),sheetId:this._worksheet.getSheetId()};else throw new Error("Invalid range specification");return this._injector.createInstance(m.FRange,this._workbook,h,s)}getMaxColumns(){return this._worksheet.getMaxColumns()}getMaxRows(){return this._worksheet.getMaxRows()}insertRowAfter(e){return this.insertRowsAfter(e,1)}insertRowBefore(e){return this.insertRowsBefore(e,1)}insertRows(e,t=1){return this.insertRowsBefore(e,t)}insertRowsAfter(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=o.Direction.DOWN,h=e+1,d=e+t,u=0,l=this._worksheet.getColumnCount()-1,g=a.copyRangeStyles(this._worksheet,h,d,u,l,!0,e);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:i,subUnitId:r,direction:s,range:{startRow:h,endRow:d,startColumn:u,endColumn:l},cellValue:g}),this}insertRowsBefore(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=o.Direction.UP,h=e,d=e+t-1,u=0,l=this._worksheet.getColumnCount()-1,g=a.copyRangeStyles(this._worksheet,h,d,u,l,!0,e-1);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:i,subUnitId:r,direction:s,range:{startRow:h,endRow:d,startColumn:u,endColumn:l},cellValue:g}),this}deleteRow(e){return this.deleteRows(e,1)}deleteRows(e,t){const i={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return this._commandService.syncExecuteCommand(a.RemoveRowByRangeCommand.id,{range:i,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}moveRows(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=E(e.getRange(),this._worksheet),h=s,d={startRow:t,endRow:t,startColumn:s.startColumn,endColumn:s.endColumn};return this._commandService.syncExecuteCommand(a.MoveRowsCommand.id,{unitId:i,subUnitId:r,range:s,fromRange:h,toRange:d}),this}hideRow(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r=E(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:t,subUnitId:i,ranges:[r]}),this}hideRows(e,t=1){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:o.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:i,subUnitId:r,ranges:[s]}),this}unhideRow(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r=E(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:t,subUnitId:i,ranges:[r]}),this}showRows(e,t=1){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:o.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:i,subUnitId:r,ranges:[s]}),this}setRowHeight(e,t){return this.setRowHeights(e,1,t)}autoFitRow(e,t=o.BooleanNumber.TRUE){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=[{startRow:e,endRow:e,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:s[0],value:o.WrapStrategy.WRAP}),this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightMutation.id,{unitId:i,subUnitId:r,ranges:s,autoHeightInfo:t}),this}setRowHeights(e,t,i){var l;const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),h=this._worksheet.getRowManager(),d=[],u=[];for(let g=e;g<e+t;g++){const k=((l=h.getRow(g))==null?void 0:l.ah)||this._worksheet.getConfig().defaultRowHeight,f={startRow:g,endRow:g,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};i<=k?d.push(f):u.push(f)}return u.length>0&&this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:r,subUnitId:s,ranges:u,value:i}),d.length>0&&this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:r,subUnitId:s,ranges:d}),this}setRowAutoHeight(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:i,subUnitId:r,ranges:s}),this}setRowHeightsForced(e,t,i){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),h=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:r,subUnitId:s,ranges:h,value:i}),this}setRowCustom(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r={};for(const[h,d]of Object.entries(e))r[Number(h)]={custom:d};const s={unitId:t,subUnitId:i,rowData:r};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,s),this}insertColumnAfter(e){return this.insertColumnsAfter(e,1)}insertColumnBefore(e){return this.insertColumnsBefore(e,1)}insertColumns(e,t=1){return this.insertColumnsBefore(e,t)}insertColumnsAfter(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=o.Direction.RIGHT,h=0,d=this._worksheet.getRowCount()-1,u=e+1,l=e+t,g=a.copyRangeStyles(this._worksheet,h,d,u,l,!1,e);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:i,subUnitId:r,direction:s,range:{startRow:h,endRow:d,startColumn:u,endColumn:l},cellValue:g}),this}insertColumnsBefore(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=o.Direction.LEFT,h=0,d=this._worksheet.getRowCount()-1,u=e,l=e+t-1,g=a.copyRangeStyles(this._worksheet,h,d,u,l,!1,e-1);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:i,subUnitId:r,direction:s,range:{startRow:h,endRow:d,startColumn:u,endColumn:l},cellValue:g}),this}deleteColumn(e){return this.deleteColumns(e,1)}deleteColumns(e,t){const i={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1};return this._commandService.syncExecuteCommand(a.RemoveColByRangeCommand.id,{range:i,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}moveColumns(e,t){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s=p(e.getRange(),this._worksheet),h=s,d={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return this._commandService.syncExecuteCommand(a.MoveColsCommand.id,{unitId:i,subUnitId:r,range:s,fromRange:h,toRange:d}),this}hideColumn(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r=p(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:t,subUnitId:i,ranges:[r]}),this}hideColumns(e,t=1){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:o.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:i,subUnitId:r,ranges:[s]}),this}unhideColumn(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r=p(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:t,subUnitId:i,ranges:[r]}),this}showColumns(e,t=1){const i=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:o.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:i,subUnitId:r,ranges:[s]}),this}setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}setColumnWidths(e,t,i){const r=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),h=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return this._commandService.syncExecuteCommand(a.SetColWidthCommand.id,{unitId:r,subUnitId:s,ranges:h,value:i}),this}setColumnCustom(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r={};for(const[h,d]of Object.entries(e))r[Number(h)]={custom:d};const s={unitId:t,subUnitId:i,columnData:r};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,s),this}getMergedRanges(){return this._worksheet.getSnapshot().mergeData.map(t=>this._injector.createInstance(m.FRange,this._workbook,this._worksheet,t))}getCellMergeData(e,t){const r=this._worksheet.getMergedCell(e,t);if(r)return this._injector.createInstance(m.FRange,this._workbook,this._worksheet,r)}getActiveRange(){return this._fWorkbook.getActiveRange()}setActiveRange(e){const{unitId:t,sheetId:i}=e.getRange();if(t!==this._workbook.getUnitId()||i!==this._worksheet.getSheetId())throw new Error("Specified range must be part of the sheet.");return this._fWorkbook.setActiveRange(e),this}setFreeze(e){return this._logService.warn("setFreeze is deprecated, use setFrozenRows and setFrozenColumns instead"),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{...e,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}cancelFreeze(){return this._commandService.syncExecuteCommand(a.CancelFrozenCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}getFreeze(){return this._worksheet.getFreeze()}setFrozenColumns(...e){const t=this.getFreeze();if(arguments.length===1){const i=e[0];this.setFreeze({...t,startColumn:i>0?i:-1,xSplit:i})}else if(arguments.length===2){let[i=0,r=0]=e;i>r&&([i,r]=[r,i]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startColumn:r+1,xSplit:r-i+1,startRow:t.startRow,ySplit:t.ySplit,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}return this}setFrozenRows(...e){const t=this.getFreeze();if(arguments.length===1){const i=e[0];this.setFreeze({...t,startRow:i>0?i:-1,ySplit:i})}else if(arguments.length===2){let[i=0,r=0]=e;i>r&&([i,r]=[r,i]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startRow:r+1,ySplit:r-i+1,startColumn:t.startColumn,xSplit:t.xSplit,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}return this}getFrozenColumns(){const e=this.getFreeze();return e.startColumn===-1?0:e.startColumn}getFrozenRows(){const e=this.getFreeze();return e.startRow===-1?0:e.startRow}getFrozenRowRange(){const e=this._worksheet.getFreeze();return{startRow:e.startRow-e.ySplit,endRow:e.startRow-1}}getFrozenColumnRange(){const e=this._worksheet.getFreeze();return{startColumn:e.startColumn-e.xSplit,endColumn:e.startColumn-1}}hasHiddenGridLines(){return this._worksheet.getConfig().showGridlines===o.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.syncExecuteCommand(a.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?o.BooleanNumber.FALSE:o.BooleanNumber.TRUE}),this}setGridLinesColor(e){return this._commandService.syncExecuteCommand(a.SetGridlinesColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getGridLinesColor(){return this._worksheet.getGridlinesColor()}setTabColor(e){return this._commandService.syncExecuteCommand(a.SetTabColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getTabColor(){return this._worksheet.getTabColor()}onCellDataChange(e){return this._injector.get(o.ICommandService).onCommandExecuted(i=>{if(i.id===a.SetRangeValuesMutation.id){const r=i.params;r.unitId===this._workbook.getUnitId()&&r.subUnitId===this._worksheet.getSheetId()&&r.cellValue&&e(new o.ObjectMatrix(r.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(o.ICommandService).beforeCommandExecuted(i=>{if(i.id===a.SetRangeValuesMutation.id){const r=i.params;r.unitId===this._workbook.getUnitId()&&r.subUnitId===this._worksheet.getSheetId()&&r.cellValue&&e(new o.ObjectMatrix(r.cellValue))}})}hideSheet(){const e=this._injector.get(o.ICommandService);if(this._workbook.getSheets().filter(s=>s.isSheetHidden()!==o.BooleanNumber.TRUE).length<=1)throw new Error("Cannot hide the only visible sheet");return e.syncExecuteCommand(a.SetWorksheetHideCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}showSheet(){return this._injector.get(o.ICommandService).syncExecuteCommand(a.SetWorksheetShowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}isSheetHidden(){return this._worksheet.isSheetHidden()===o.BooleanNumber.TRUE}setName(e){return this._commandService.syncExecuteCommand(a.SetWorksheetNameCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),name:e}),this}activate(){return this._fWorkbook.setActiveSheet(this),this}getIndex(){return this._workbook.getSheetIndex(this._worksheet)}clear(e){e&&e.contentsOnly&&!e.formatOnly&&this.clearContents(),e&&e.formatOnly&&!e.contentsOnly&&this.clearFormats();const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),r=this._injector.get(o.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return r.syncExecuteCommand(a.ClearSelectionAllCommand.id,{unitId:t,subUnitId:i,ranges:[s],options:e}),this}clearContents(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),i=this._injector.get(o.ICommandService),r={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return i.syncExecuteCommand(a.ClearSelectionContentCommand.id,{unitId:e,subUnitId:t,ranges:[r]}),this}clearFormats(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),i=this._injector.get(o.ICommandService),r={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return i.syncExecuteCommand(a.ClearSelectionFormatCommand.id,{unitId:e,subUnitId:t,ranges:[r]}),this}getDataRange(){const e=this.getLastRows(),t=this.getLastColumns();return this.getRange(0,0,e+1,t+1)}getLastColumns(){return this._worksheet.getLastColumnWithContent()}getLastColumn(){return this._worksheet.getLastColumnWithContent()}getLastRows(){return this._worksheet.getLastRowWithContent()}getLastRow(){return this._worksheet.getLastRowWithContent()}equalTo(e){return e instanceof m.FWorksheet?this._worksheet.getSheetId()===e.getSheetId()&&this._workbook.getUnitId()===e.getWorkbook().getUnitId():!1}insertDefinedName(e,t){const r=this._injector.createInstance(I).setName(e).setRef(t).build();r.localSheetId=this.getSheetId(),this._fWorkbook.insertDefinedNameBuilder(r)}getDefinedNames(){return this._fWorkbook.getDefinedNames().filter(t=>t.getLocalSheetId()===this.getSheetId())}setCustomMetadata(e){return this._worksheet.setCustomMetadata(e),this}setRowCustomMetadata(e,t){return this._worksheet.getRowManager().setCustomMetadata(e,t),this}setColumnCustomMetadata(e,t){return this._worksheet.getColumnManager().setCustomMetadata(e,t),this}getRowCustomMetadata(e){return this._worksheet.getRowManager().getCustomMetadata(e)}getColumnCustomMetadata(e){return this._worksheet.getColumnManager().getCustomMetadata(e)}getMergeData(){return this._worksheet.getMergeData().map(e=>this._injector.createInstance(m.FRange,this._workbook,this._worksheet,e))}},m.FWorksheet=X([y(3,o.Inject(o.Injector)),y(4,o.Inject(a.SheetsSelectionsService)),y(5,o.Inject(o.ILogService)),y(6,o.ICommandService)],m.FWorksheet);var Z=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=(c,n,e,t)=>{for(var i=t>1?void 0:t?ee(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&Z(n,e,i),i},S=(c,n)=>(e,t)=>n(e,t,c);m.FWorkbook=class extends o.FBaseInitialable{constructor(e,t,i,r,s,h,d,u,l,g){super(t);v(this,"id");this._workbook=e,this._injector=t,this._resourceLoaderService=i,this._selectionManagerService=r,this._univerInstanceService=s,this._commandService=h,this._permissionService=d,this._logService=u,this._localeService=l,this._definedNamesService=g,this.id=this._workbook.getUnitId()}getWorkbook(){return this._workbook}getId(){return this.id}getName(){return this._workbook.name}setName(e){this._workbook.setName(e)}save(){return this._resourceLoaderService.saveUnit(this._workbook.getUnitId())}getSnapshot(){return this._logService.warn("use 'save' instead of 'getSnapshot'"),this.save()}getActiveSheet(){const e=this._workbook.getActiveSheet();return this._injector.createInstance(m.FWorksheet,this,this._workbook,e)}getSheets(){return this._workbook.getSheets().map(e=>this._injector.createInstance(m.FWorksheet,this,this._workbook,e))}create(e,t,i){const r=o.mergeWorksheetSnapshotWithDefault({});r.rowCount=t,r.columnCount=i,r.name=e,r.id=e.toLowerCase().replace(/ /g,"-"),this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{unitId:this.id,index:this._workbook.getSheets().length,sheet:r}),this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId()});const s=this._workbook.getActiveSheet();if(!s)throw new Error("No active sheet found");return this._injector.createInstance(m.FWorksheet,this,this._workbook,s)}getSheetBySheetId(e){const t=this._workbook.getSheetBySheetId(e);return t?this._injector.createInstance(m.FWorksheet,this,this._workbook,t):null}getSheetByName(e){const t=this._workbook.getSheetBySheetName(e);return t?this._injector.createInstance(m.FWorksheet,this,this._workbook,t):null}setActiveSheet(e){return this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:typeof e=="string"?e:e.getSheetId()}),typeof e=="string"?this.getSheetBySheetId(e):e}insertSheet(e){e!=null?this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{sheet:{name:e}}):this._commandService.syncExecuteCommand(a.InsertSheetCommand.id);const t=this.id,i=this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId();this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:t,subUnitId:i});const r=this._workbook.getActiveSheet();if(!r)throw new Error("No active sheet found");return this._injector.createInstance(m.FWorksheet,this,this._workbook,r)}deleteSheet(e){const t=this.id,i=typeof e=="string"?e:e.getSheetId();return this._commandService.syncExecuteCommand(a.RemoveSheetCommand.id,{unitId:t,subUnitId:i})}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(o.UndoCommand.id),this}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(o.RedoCommand.id),this}onBeforeCommandExecute(e){return this._commandService.beforeCommandExecuted(t=>{var i;((i=t.params)==null?void 0:i.unitId)===this.id&&e(t)})}onCommandExecuted(e){return this._commandService.onCommandExecuted(t=>{var i;((i=t.params)==null?void 0:i.unitId)===this.id&&e(t)})}onSelectionChange(e){return o.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(t=>{this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET).getUnitId()===this.id&&(t!=null&&t.length?e(t.map(i=>i.range)):e([]))}))}setEditable(e){const t=new a.WorkbookEditablePermission(this._workbook.getUnitId());return this._permissionService.getPermissionPoint(t.id)||this._permissionService.addPermissionPoint(t),this._permissionService.updatePermissionPoint(t.id,e),this}setActiveRange(e){const t=this.getActiveSheet(),i=e.getRange().sheetId||t.getSheetId(),r=i?this._workbook.getSheetBySheetId(i):this._workbook.getActiveSheet(!0);if(!r)throw new Error("No active sheet found");r.getSheetId()!==t.getSheetId()&&this.setActiveSheet(this._injector.createInstance(m.FWorksheet,this,this._workbook,r));const s={unitId:this.getId(),subUnitId:i,selections:[e].map(h=>({range:h.getRange(),primary:a.getPrimaryForRange(h.getRange(),r),style:null}))};return this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,s),this}getActiveRange(){const e=this._workbook.getActiveSheet(),i=this._selectionManagerService.getCurrentSelections().find(r=>!!r.primary);return i?this._injector.createInstance(m.FRange,this._workbook,e,i.range):null}deleteActiveSheet(){const e=this.getActiveSheet();return this.deleteSheet(e)}duplicateSheet(e){return this._commandService.syncExecuteCommand(a.CopySheetCommand.id,{unitId:e.getWorkbook().getUnitId(),subUnitId:e.getSheetId()}),this._injector.createInstance(m.FWorksheet,this,this._workbook,this._workbook.getActiveSheet())}duplicateActiveSheet(){const e=this.getActiveSheet();return this.duplicateSheet(e)}getNumSheets(){return this._workbook.getSheets().length}getLocale(){return this._localeService.getCurrentLocale()}setLocale(e){this._localeService.setLocale(e)}setSpreadsheetLocale(e){return this._localeService.setLocale(e),this}getUrl(){return location.href}moveSheet(e,t){let i=t;return i<0?i=0:i>this._workbook.getSheets().length-1&&(i=this._workbook.getSheets().length-1),this._commandService.syncExecuteCommand(a.SetWorksheetOrderCommand.id,{unitId:e.getWorkbook().getUnitId(),order:i,subUnitId:e.getSheetId()}),this}moveActiveSheet(e){const t=this.getActiveSheet();return this.moveSheet(t,e)}getPermission(){return this._injector.createInstance(m.FPermission)}getDefinedName(e){const t=this._definedNamesService.getValueByName(this.id,e);return t?this._injector.createInstance(R,{...t,unitId:this.id}):null}getDefinedNames(){const e=this._definedNamesService.getDefinedNameMap(this.id);return e?Object.values(e).map(t=>this._injector.createInstance(R,{...t,unitId:this.id})):[]}insertDefinedName(e,t){const r=this._injector.createInstance(I).setName(e).setRef(t).build();return r.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this.insertDefinedNameBuilder(r),this}deleteDefinedName(e){const t=this.getDefinedName(e);return t?(t.delete(),!0):!1}insertDefinedNameBuilder(e){e.unitId=this.getId(),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}updateDefinedNameBuilder(e){this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}getRegisteredRangeThemes(){return this._injector.get(a.SheetRangeThemeService).getRegisteredRangeThemes()}registerRangeTheme(e){this._commandService.syncExecuteCommand(a.RegisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),rangeThemeStyle:e})}unregisterRangeTheme(e){this._commandService.syncExecuteCommand(a.UnregisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),themeName:e})}createRangeThemeStyle(e,t){return new a.RangeThemeStyle(e,t)}setCustomMetadata(e){return this._workbook.setCustomMetadata(e),this}getCustomMetadata(){return this._workbook.getCustomMetadata()}},m.FWorkbook=te([S(1,o.Inject(o.Injector)),S(2,o.Inject(o.IResourceLoaderService)),S(3,o.Inject(a.SheetsSelectionsService)),S(4,o.IUniverInstanceService),S(5,o.ICommandService),S(6,o.IPermissionService),S(7,o.ILogService),S(8,o.Inject(o.LocaleService)),S(9,C.IDefinedNamesService)],m.FWorkbook);class ne extends o.FUniver{getCommandSheetTarget(n){var r;const e=n.params;if(!e)return;const t=e.unitId?this.getUniverSheet(e.unitId):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!t)return;const i=t.getSheetBySheetId(e.subUnitId||e.sheetId)||t.getActiveSheet();if(i)return{workbook:t,worksheet:i}}getSheetTarget(n,e){const t=this.getUniverSheet(n);if(!t)return;const i=t.getSheetBySheetId(e);if(i)return{workbook:t,worksheet:i}}_initWorkbookEvent(n){const e=n.get(o.IUniverInstanceService);this.disposeWithMe(e.unitDisposed$.subscribe(t=>{this._eventRegistry.get(this.Event.WorkbookDisposed)&&t.type===o.UniverInstanceType.UNIVER_SHEET&&this.fireEvent(this.Event.WorkbookDisposed,{unitId:t.getUnitId(),unitType:t.type,snapshot:t.getSnapshot()})})),this.disposeWithMe(e.unitAdded$.subscribe(t=>{if(this._eventRegistry.get(this.Event.WorkbookCreated)&&t.type===o.UniverInstanceType.UNIVER_SHEET){const i=t,r=n.createInstance(m.FWorkbook,i);this.fireEvent(this.Event.WorkbookCreated,{unitId:t.getUnitId(),type:t.type,workbook:r,unit:r})}}))}_initialize(n){const e=n.get(o.ICommandService);this.disposeWithMe(e.beforeCommandExecuted(t=>{var i,r,s,h;switch(t.id){case a.InsertSheetCommand.id:{const d=t.params,{unitId:u,index:l,sheet:g}=d||{},k=u?this.getUniverSheet(u):(i=this.getActiveWorkbook)==null?void 0:i.call(this);if(!k)return;const f={workbook:k,index:l,sheet:g};if(this.fireEvent(this.Event.BeforeSheetCreate,f),f.cancel)throw new o.CanceledError;break}case a.SetWorksheetActivateCommand.id:{if(!this._eventListend(this.Event.BeforeActiveSheetChange))return;const{subUnitId:d,unitId:u}=t.params,l=u?this.getUniverSheet(u):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!l||!d)return;const g=l.getSheetBySheetId(d),k=l.getActiveSheet();if(!g||!k)return;this._fireBeforeActiveSheetChange(l,g,k);break}case a.RemoveSheetCommand.id:{if(!this._eventListend(this.Event.BeforeSheetDelete))return;const d=this.getCommandSheetTarget(t);if(!d)return;const{workbook:u,worksheet:l}=d;this._fireBeforeSheetDelete(u,l);break}case a.SetWorksheetOrderCommand.id:{if(!this._eventListend(this.Event.BeforeSheetMove))return;const{fromOrder:d,toOrder:u}=t.params,l=this.getCommandSheetTarget(t);if(!l)return;this._fireBeforeSheetMove(l.workbook,l.worksheet,u,d);break}case a.SetWorksheetNameCommand.id:{if(!this._eventListend(this.Event.BeforeSheetNameChange))return;const{name:d}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetNameChange(u.workbook,u.worksheet,d,u.worksheet.getSheetName());break}case a.SetTabColorCommand.id:{if(!this._eventListend(this.Event.BeforeSheetTabColorChange))return;const{color:d}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetTabColorChange(u.workbook,u.worksheet,d,u.worksheet.getTabColor());break}case a.SetWorksheetHideCommand.id:{if(!this._eventListend(this.Event.BeforeSheetHideChange))return;const{hidden:d}=t.params,u=this.getCommandSheetTarget(t);if(!u)return;this._fireBeforeSheetHideChange(u.workbook,u.worksheet,!!d);break}case a.SetGridlinesColorCommand.id:{if(!this._eventListend(this.Event.BeforeGridlineColorChange))return;const d=this.getCommandSheetTarget(t);if(!d)return;this.fireEvent(this.Event.BeforeGridlineColorChange,{...d,color:(s=t.params)==null?void 0:s.color});break}case a.ToggleGridlinesCommand.id:{if(!this._eventListend(this.Event.BeforeGridlineEnableChange))return;const d=this.getCommandSheetTarget(t);if(!d)return;this.fireEvent(this.Event.BeforeGridlineEnableChange,{...d,enabled:!!((h=t.params)!=null&&h.showGridlines)});break}}})),this.disposeWithMe(e.onCommandExecuted(t=>{var i,r;if(a.COMMAND_LISTENER_VALUE_CHANGE.indexOf(t.id)>-1){if(!this._eventListend(this.Event.SheetValueChanged)||!this.getActiveSheet())return;const h=a.getValueChangedEffectedRange(t).map(d=>{var u,l;return(l=(u=this.getWorkbook(d.unitId))==null?void 0:u.getSheetBySheetId(d.subUnitId))==null?void 0:l.getRange(d.range)}).filter(Boolean);if(!h.length)return;this.fireEvent(this.Event.SheetValueChanged,{payload:t,effectedRanges:h});return}switch(t.id){case a.InsertSheetCommand.id:{const s=t.params,{unitId:h}=s||{},d=h?this.getUniverSheet(h):(i=this.getActiveWorkbook)==null?void 0:i.call(this);if(!d)return;const u=d.getActiveSheet();if(!u)return;const l={workbook:d,worksheet:u};this.fireEvent(this.Event.SheetCreated,l);break}case a.SetWorksheetActivateCommand.id:{if(!this._eventListend(this.Event.ActiveSheetChanged))return;const s=this.getActiveSheet();if(!s)return;const{workbook:h,worksheet:d}=s;this._fireActiveSheetChanged(h,d);break}case a.RemoveSheetCommand.id:{if(!this._eventListend(this.Event.SheetDeleted))return;const{subUnitId:s,unitId:h}=t.params,d=h?this.getUniverSheet(h):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!d||!s)return;this._fireSheetDeleted(d,s);break}case a.SetWorksheetOrderCommand.id:{if(!this._eventListend(this.Event.SheetMoved))return;const{toOrder:s}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetMoved(h.workbook,h.worksheet,s);break}case a.SetWorksheetNameCommand.id:{if(!this._eventListend(this.Event.SheetNameChanged))return;const{name:s}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetNameChanged(h.workbook,h.worksheet,s);break}case a.SetTabColorCommand.id:{if(!this._eventListend(this.Event.SheetTabColorChanged))return;const{color:s}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetTabColorChanged(h.workbook,h.worksheet,s);break}case a.SetWorksheetHideCommand.id:{if(!this._eventListend(this.Event.SheetHideChanged))return;const{hidden:s}=t.params,h=this.getCommandSheetTarget(t);if(!h)return;this._fireSheetHideChanged(h.workbook,h.worksheet,!!s);break}case a.SetGridlinesColorCommand.id:case a.ToggleGridlinesCommand.id:{if(!this._eventListend(this.Event.GridlineChanged))return;const s=this.getCommandSheetTarget(t);if(!s)return;this.fireEvent(this.Event.GridlineChanged,{...s,enabled:!s.worksheet.hasHiddenGridLines(),color:s.worksheet.getGridLinesColor()});break}}})),this._initWorkbookEvent(n)}createUniverSheet(n){const t=this._injector.get(o.IUniverInstanceService).createUnit(o.UniverInstanceType.UNIVER_SHEET,n);return this._injector.createInstance(m.FWorkbook,t)}createWorkbook(n){return this.createUniverSheet(n)}getActiveWorkbook(){const n=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);return n?this._injector.createInstance(m.FWorkbook,n):null}getActiveUniverSheet(){return this.getActiveWorkbook()}getUniverSheet(n){const e=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET);return e?this._injector.createInstance(m.FWorkbook,e):null}getWorkbook(n){return this.getUniverSheet(n)}getPermission(){return this._injector.createInstance(m.FPermission)}onUniverSheetCreated(n){const e=this._univerInstanceService.getTypeOfUnitAdded$(o.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{const i=this._injector.createInstance(m.FWorkbook,t);n(i)});return o.toDisposable(e)}newDefinedName(){return this._injector.createInstance(I)}getActiveSheet(){const n=this.getActiveWorkbook();if(!n)return null;const e=n.getActiveSheet();return e?{workbook:n,worksheet:e}:null}_fireBeforeActiveSheetChange(n,e,t){this.fireEvent(this.Event.BeforeActiveSheetChange,{workbook:n,activeSheet:e,oldActiveSheet:t})}_fireActiveSheetChanged(n,e){this.fireEvent(this.Event.ActiveSheetChanged,{workbook:n,activeSheet:e})}_fireBeforeSheetDelete(n,e){this.fireEvent(this.Event.BeforeSheetDelete,{workbook:n,worksheet:e})}_fireSheetDeleted(n,e){this.fireEvent(this.Event.SheetDeleted,{workbook:n,sheetId:e})}_fireBeforeSheetMove(n,e,t,i){this.fireEvent(this.Event.BeforeSheetMove,{workbook:n,worksheet:e,newIndex:t,oldIndex:i})}_fireSheetMoved(n,e,t){this.fireEvent(this.Event.SheetMoved,{workbook:n,worksheet:e,newIndex:t})}_fireBeforeSheetNameChange(n,e,t,i){this.fireEvent(this.Event.BeforeSheetNameChange,{workbook:n,worksheet:e,newName:t,oldName:i})}_fireSheetNameChanged(n,e,t){this.fireEvent(this.Event.SheetNameChanged,{workbook:n,worksheet:e,newName:t})}_fireBeforeSheetTabColorChange(n,e,t,i){this.fireEvent(this.Event.BeforeSheetTabColorChange,{workbook:n,worksheet:e,newColor:t,oldColor:i})}_fireSheetTabColorChanged(n,e,t){this.fireEvent(this.Event.SheetTabColorChanged,{workbook:n,worksheet:e,newColor:t})}_fireBeforeSheetHideChange(n,e,t){this.fireEvent(this.Event.BeforeSheetHideChange,{workbook:n,worksheet:e,hidden:t})}_fireSheetHideChanged(n,e,t){this.fireEvent(this.Event.SheetHideChanged,{workbook:n,worksheet:e,hidden:t})}}o.FUniver.extend(ne);class N{get SheetValueChangeType(){return a.SheetValueChangeType}get SheetSkeletonChangeType(){return a.SheetSkeletonChangeType}}o.FEnum.extend(N);class T extends o.FEventName{get SheetCreated(){return"SheetCreated"}get BeforeSheetCreate(){return"BeforeSheetCreate"}get WorkbookCreated(){return"WorkbookCreated"}get WorkbookDisposed(){return"WorkbookDisposed"}get GridlineChanged(){return"GridlineChanged"}get BeforeGridlineEnableChange(){return"BeforeGridlineEnableChange"}get BeforeGridlineColorChange(){return"BeforeGridlineColorChange"}get BeforeActiveSheetChange(){return"BeforeActiveSheetChange"}get ActiveSheetChanged(){return"ActiveSheetChanged"}get SheetDeleted(){return"SheetDeleted"}get BeforeSheetDelete(){return"BeforeSheetDelete"}get SheetMoved(){return"SheetMoved"}get BeforeSheetMove(){return"BeforeSheetMove"}get SheetNameChanged(){return"SheetNameChanged"}get BeforeSheetNameChange(){return"BeforeSheetNameChange"}get SheetTabColorChanged(){return"SheetTabColorChanged"}get BeforeSheetTabColorChange(){return"BeforeSheetTabColorChange"}get SheetHideChanged(){return"SheetHideChanged"}get BeforeSheetHideChange(){return"BeforeSheetHideChange"}get SheetValueChanged(){return"SheetValueChanged"}}o.FEventName.extend(T);var ie=Object.defineProperty,re=Object.getOwnPropertyDescriptor,oe=(c,n,e,t)=>{for(var i=t>1?void 0:t?re(n,e):n,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&ie(n,e,i),i},se=(c,n)=>(e,t)=>n(e,t,c);m.FSheetHooks=class extends o.FBase{constructor(n){super(),this._injector=n}},m.FSheetHooks=oe([se(0,o.Inject(o.Injector))],m.FSheetHooks),m.FSheetEventName=T,m.FSheetsEnum=N,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
{
"name": "@univerjs/sheets",
"version": "0.5.5",
"version": "0.6.0-alpha.0",
"private": false,

@@ -61,14 +61,14 @@ "description": "UniverSheet normal base-sheets",

"dependencies": {
"@univerjs/protocol": "0.1.40",
"@univerjs/core": "0.5.5",
"@univerjs/engine-formula": "0.5.5",
"@univerjs/engine-numfmt": "0.5.5",
"@univerjs/rpc": "0.5.5"
"@univerjs/protocol": "0.1.43",
"@univerjs/core": "0.6.0-alpha.0",
"@univerjs/engine-numfmt": "0.6.0-alpha.0",
"@univerjs/engine-formula": "0.6.0-alpha.0",
"@univerjs/rpc": "0.6.0-alpha.0"
},
"devDependencies": {
"rxjs": "^7.8.1",
"typescript": "^5.7.2",
"typescript": "^5.7.3",
"vite": "^6.0.7",
"vitest": "^2.1.8",
"@univerjs-infra/shared": "0.5.5"
"@univerjs-infra/shared": "0.6.0-alpha.0"
},

@@ -75,0 +75,0 @@ "scripts": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc