@univerjs/sheets
Version:
UniverSheet normal base-sheets
1 lines • 101 kB
JavaScript
(function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("rxjs"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/core/facade","@univerjs/sheets","@univerjs/engine-formula","rxjs","rxjs/operators"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c.UniverSheetsFacade={},c.UniverCore,c.UniverCoreFacade,c.UniverSheets,c.UniverEngineFormula,c.rxjs,c.rxjs.operators))})(this,(function(c,h,f,a,U,N,k){"use strict";var De=Object.defineProperty;var je=(c,h,f)=>h in c?De(c,h,{enumerable:!0,configurable:!0,writable:!0,value:f}):c[h]=f;var C=(c,h,f)=>je(c,typeof h!="symbol"?h+"":h,f);var j;var re=Object.getOwnPropertyDescriptor,oe=(r,n,e,t)=>{for(var i=t>1?void 0:t?re(n,e):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=s(i)||i);return i},E=(r,n)=>(e,t)=>n(e,t,r);function se(r,n,e){const t=e.getDefinedNameMap(r);if(t==null)return n.t("definedName.defaultName")+1;const o=Array.from(Object.values(t)).length+1,s=n.t("definedName.defaultName")+o;if(e.getValueByName(r,s)==null)return s;let d=o+1;for(;;){const u=n.t("definedName.defaultName")+d;if(e.getValueByName(r,u)==null)return u;d++}}class A{constructor(){C(this,"_definedNameParam");this._definedNameParam={id:h.generateRandomId(10),unitId:"",name:"",formulaOrRefString:"",localSheetId:a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}}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=U.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}setScopeToWorksheet(n){return this._definedNameParam.localSheetId=n.getSheetId(),this}setScopeToWorkbook(){return this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this}setHidden(n){return this._definedNameParam.hidden=n,this}build(){return this._definedNameParam}load(n){return this._definedNameParam=n,this}}let x=class extends f.FBase{constructor(r,n,e,t,i,o,s,d,u,l){super(),this._definedNameParam=r,this._injector=n,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=i,this._rangeProtectionRuleModel=o,this._worksheetProtectionPointRuleModel=s,this._authzIoService=d,this._localeService=u,this._definedNamesService=l}_apply(){this._definedNameParam.name===""&&(this._definedNameParam.name=se(this._definedNameParam.unitId,this._localeService,this._definedNamesService)),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,this._definedNameParam)}getName(){return this._definedNameParam.name}setName(r){this._definedNameParam.name=r,this._apply()}setFormula(r){this._definedNameParam.formulaOrRefString=`=${r}`,this._apply()}setRef(r){this._definedNameParam.formulaOrRefString=r,this._apply()}getFormulaOrRefString(){return this._definedNameParam.formulaOrRefString}setRefByRange(r,n,e,t){this._definedNameParam.formulaOrRefString=U.serializeRange({startRow:r,endRow:r+(e!=null?e:1)-1,startColumn:n,endColumn:n+(t!=null?t:1)-1}),this._apply()}getComment(){return this._definedNameParam.comment}setComment(r){this._definedNameParam.comment=r,this._apply()}setScopeToWorksheet(r){this._definedNameParam.localSheetId=r.getSheetId(),this._apply()}setScopeToWorkbook(){this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this._apply()}setHidden(r){this._definedNameParam.hidden=r,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 r=this._injector.createInstance(A);return r.load(this._definedNameParam),r}};x=oe([E(1,h.Inject(h.Injector)),E(2,h.ICommandService),E(3,h.IPermissionService),E(4,h.Inject(a.WorksheetProtectionRuleModel)),E(5,h.Inject(a.RangeProtectionRuleModel)),E(6,h.Inject(a.WorksheetProtectionPointModel)),E(7,h.Inject(h.IAuthzIoService)),E(8,h.Inject(h.LocaleService)),E(9,U.IDefinedNamesService)],x);var M=(r=>(r[r.Reader=0]="Reader",r[r.Editor=1]="Editor",r[r.Owner=2]="Owner",r))(M||{}),_=(r=>(r.Edit="WorkbookEdit",r.View="WorkbookView",r.Print="WorkbookPrint",r.Export="WorkbookExport",r.Share="WorkbookShare",r.CopyContent="WorkbookCopy",r.DuplicateFile="WorkbookDuplicate",r.Comment="WorkbookComment",r.ManageCollaborator="WorkbookManageCollaborator",r.CreateSheet="WorkbookCreateSheet",r.DeleteSheet="WorkbookDeleteSheet",r.RenameSheet="WorkbookRenameSheet",r.MoveSheet="WorkbookMoveSheet",r.HideSheet="WorkbookHideSheet",r.ViewHistory="WorkbookViewHistory",r.ManageHistory="WorkbookHistory",r.RecoverHistory="WorkbookRecoverHistory",r.CreateProtection="WorkbookCreateProtect",r.InsertRow="WorkbookInsertRow",r.InsertColumn="WorkbookInsertColumn",r.DeleteRow="WorkbookDeleteRow",r.DeleteColumn="WorkbookDeleteColumn",r.CopySheet="WorkbookCopySheet",r))(_||{}),w=(r=>(r.Edit="WorksheetEdit",r.View="WorksheetView",r.Copy="WorksheetCopy",r.SetCellValue="WorksheetSetCellValue",r.SetCellStyle="WorksheetSetCellStyle",r.SetRowStyle="WorksheetSetRowStyle",r.SetColumnStyle="WorksheetSetColumnStyle",r.InsertRow="WorksheetInsertRow",r.InsertColumn="WorksheetInsertColumn",r.DeleteRow="WorksheetDeleteRow",r.DeleteColumn="WorksheetDeleteColumn",r.Sort="WorksheetSort",r.Filter="WorksheetFilter",r.PivotTable="WorksheetPivotTable",r.InsertHyperlink="WorksheetInsertHyperlink",r.EditExtraObject="WorksheetEditExtraObject",r.ManageCollaborator="WorksheetManageCollaborator",r.DeleteProtection="WorksheetDeleteProtection",r.SelectProtectedCells="WorksheetSelectProtectedCells",r.SelectUnProtectedCells="WorksheetSelectUnProtectedCells",r))(w||{}),b=(r=>(r.Edit="RangeEdit",r.View="RangeView",r.ManageCollaborator="RangeManageCollaborator",r.Delete="RangeDeleteProtection",r))(b||{}),ae=Object.getOwnPropertyDescriptor,he=(r,n,e,t)=>{for(var i=t>1?void 0:t?ae(n,e):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=s(i)||i);return i},W=(r,n)=>(e,t)=>n(e,t,r);c.FPermission=class extends f.FBase{constructor(e,t,i,o,s,d,u,l){super();C(this,"permissionPointsDefinition",a.PermissionPointsDefinitions);C(this,"rangeRuleChangedAfterAuth$");C(this,"sheetRuleChangedAfterAuth$");C(this,"unitPermissionInitStateChange$");this._injector=e,this._commandService=t,this._permissionService=i,this._worksheetProtectionRuleModel=o,this._rangeProtectionRuleModel=s,this._worksheetProtectionPointRuleModel=d,this._workbookPermissionService=u,this._authzIoService=l,this.rangeRuleChangedAfterAuth$=this._rangeProtectionRuleModel.ruleRefresh$,this.sheetRuleChangedAfterAuth$=this._worksheetProtectionRuleModel.ruleRefresh$,this.unitPermissionInitStateChange$=this._workbookPermissionService.unitPermissionInitStateChange$}setWorkbookPermissionPoint(e,t,i){const o=new t(e);this._permissionService.getPermissionPoint(o.id)||this._permissionService.addPermissionPoint(o),this._permissionService.updatePermissionPoint(o.id,i)}checkWorkbookPermissionPoint(e,t){const i=new t(e),o=this._permissionService.getPermissionPoint(i.id);if(o)return o.value}setWorkbookEditPermission(e,t){this.setWorkbookPermissionPoint(e,a.WorkbookEditablePermission,t)}async addWorksheetBasePermission(e,t,i){let o=[];if(i!=null&&i.allowedUsers){const u=await this._authzIoService.listCollaborators({objectID:e,unitID:e}),l=new Set(i.allowedUsers);o=u.filter(m=>{var S;return l.has(((S=m.subject)==null?void 0:S.userID)||m.id)}).map(m=>({id:m.id,role:M.Editor,subject:m.subject}));const g=new Set(o.map(m=>{var S;return((S=m.subject)==null?void 0:S.userID)||m.id}));i.allowedUsers.forEach(m=>{g.has(m)||console.error(`User ${m} not found in collaborators list`)})}const s=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:o,unitID:e,strategies:[],name:(i==null?void 0:i.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(i=>{const o=new i(e,t);this._permissionService.updatePermissionPoint(o.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e,t)}async setWorksheetPermissionPoint(e,t,i,o){const s=this._worksheetProtectionRuleModel.getRule(e,t);let d;if(i===a.WorksheetEditPermission||i===a.WorksheetViewPermission)s?d=s.permissionId:d=await this.addWorksheetBasePermission(e,t);else{const m=this._worksheetProtectionPointRuleModel.getRule(e,t);m?d=m.permissionId:(d=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:d}}))}const l=new i(e,t);if(this._permissionService.getPermissionPoint(l.id)||this._permissionService.addPermissionPoint(l),d){const m=l.subType;await this._authzIoService.update({objectType:a.UnitObject.Worksheet,objectID:d,strategies:[{action:m,role:o?M.Owner:M.Reader}],unitID:e,share:void 0,name:"",scope:void 0,collaborators:void 0})}return this._permissionService.updatePermissionPoint(l.id,o),d}checkWorksheetPermissionPoint(e,t,i){const o=new i(e,t),s=this._permissionService.getPermissionPoint(o.id);if(s)return s.value}async addRangeBaseProtection(e,t,i,o){let s=[];if(o!=null&&o.allowedUsers){const v=await this._authzIoService.listCollaborators({objectID:e,unitID:e}),Q=new Set(o.allowedUsers);s=v.filter(p=>{var V;return Q.has(((V=p.subject)==null?void 0:V.userID)||p.id)}).map(p=>({id:p.id,role:M.Editor,subject:p.subject}));const X=new Set(s.map(p=>{var V;return((V=p.subject)==null?void 0:V.userID)||p.id}));o.allowedUsers.forEach(p=>{X.has(p)||console.error(`User ${p} not found in collaborators list`)})}const d=await this._authzIoService.create({objectType:a.UnitObject.SelectRange,selectRangeObject:{collaborators:s,unitID:e,name:(o==null?void 0:o.name)||"",scope:void 0}}),u=`ruleId_${h.generateRandomId(6)}`;if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).some(v=>v.ranges.some(Q=>i.some(X=>h.Rectangle.intersects(X.getRange(),Q)))))throw new Error("range protection cannot intersect");const m=this._determineRangeViewState(o),S=this._determineRangeEditState(o),I={unitId:e,subUnitId:t,rules:[{permissionId:d,unitType:a.UnitObject.SelectRange,unitId:e,subUnitId:t,ranges:i.map(v=>v.getRange()),id:u,description:o==null?void 0:o.name,viewState:m,editState:S}]};if(this._commandService.syncExecuteCommand(a.AddRangeProtectionMutation.id,I))return{permissionId:d,ruleId:u}}_determineRangeViewState(e){return(e==null?void 0:e.allowViewByOthers)===!1?a.ViewStateEnum.NoOneElseCanView:a.ViewStateEnum.OthersCanView}_determineRangeEditState(e){var t;return(e==null?void 0:e.allowEdit)===!0&&((t=e==null?void 0:e.allowedUsers)!=null&&t.length)?a.EditStateEnum.DesignedUserCanEdit:a.EditStateEnum.OnlyMe}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(d=>{const u=new d(e,t);this._permissionService.updatePermissionPoint(u.id,u.value)}))}setRangeProtectionPermissionPoint(e,t,i,o,s){const d=new o(e,t,i);this._permissionService.getPermissionPoint(d.id)||this._permissionService.addPermissionPoint(d),this._permissionService.updatePermissionPoint(d.id,s)}setRangeProtectionRanges(e,t,i,o){const s=this._rangeProtectionRuleModel.getRule(e,t,i);if(s){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).filter(l=>l.id!==i).some(l=>l.ranges.some(g=>o.some(m=>h.Rectangle.intersects(m.getRange(),g)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(a.SetRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleId:i,rule:{...s,ranges:o.map(l=>l.getRange())}})}}getPermissionInfoWithCell(e,t,i,o){const s=h.cellToRange(i,o),d=this._rangeProtectionRuleModel.getSubunitRuleList(e,t).find(u=>u.ranges.some(g=>h.Rectangle.intersects(s,g)));if(d)return{permissionId:d.permissionId,ruleId:d.id}}},c.FPermission=he([W(0,h.Inject(h.Injector)),W(1,h.ICommandService),W(2,h.IPermissionService),W(3,h.Inject(a.WorksheetProtectionRuleModel)),W(4,h.Inject(a.RangeProtectionRuleModel)),W(5,h.Inject(a.WorksheetProtectionPointModel)),W(6,h.Inject(a.WorkbookPermissionService)),W(7,h.Inject(h.IAuthzIoService))],c.FPermission);var de=Object.getOwnPropertyDescriptor,ue=(r,n,e,t)=>{for(var i=t>1?void 0:t?de(n,e):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=s(i)||i);return i},le=(r,n)=>(e,t)=>n(e,t,r);c.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(c.FRange,this._workbook,this._worksheet,n.range):null}getActiveRangeList(){return this._selections.map(n=>this._injector.createInstance(c.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(c.FWorkbook,this._workbook);return this._injector.createInstance(c.FWorksheet,n,this._workbook,this._worksheet)}updatePrimaryCell(n){const e=this._injector.get(h.ICommandService);let t=[],i=!1;for(const{range:s,style:d}of this._selections)h.Rectangle.contains(s,n.getRange())?(t.push({range:s,primary:a.getPrimaryForRange(n.getRange(),this._worksheet),style:d}),i=!0):t.push({range:s,primary:null,style:d});i||(t=[{range:n.getRange(),primary:a.getPrimaryForRange(n.getRange(),this._worksheet)}]);const o={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),selections:t};return e.syncExecuteCommand(a.SetSelectionsOperation.id,o),new c.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(c.FRange,this._workbook,this._worksheet,t):null}},c.FSelection=ue([le(3,h.Inject(h.Injector))],c.FSelection);var $=(r=>(r[r.Reader=0]="Reader",r[r.Editor=1]="Editor",r[r.Owner=2]="Owner",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))($||{}),ce=Object.getOwnPropertyDescriptor,me=(r,n,e,t)=>{for(var i=t>1?void 0:t?ce(n,e):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=s(i)||i);return i},z=(r,n)=>(e,t)=>n(e,t,r);let y=class{constructor(r,n,e,t,i,o,s,d,u){this._unitId=r,this._subUnitId=n,this._ruleId=e,this._permissionId=t,this._ranges=i,this._options=o,this._injector=s,this._commandService=d,this._rangeProtectionRuleModel=u}get id(){return this._ruleId}get ranges(){return this._ranges}get options(){return{...this._options}}async updateRanges(r){if(!r||r.length===0)throw new Error("Ranges cannot be empty");const n=this._rangeProtectionRuleModel.getRule(this._unitId,this._subUnitId,this._ruleId);if(!n)throw new Error(`Rule ${this._ruleId} not found`);if(this._rangeProtectionRuleModel.getSubunitRuleList(this._unitId,this._subUnitId).filter(i=>i.id!==this._ruleId).some(i=>i.ranges.some(o=>r.some(s=>{const d=s.getRange();return this._rangesIntersect(d,o)}))))throw new Error("Range protection cannot intersect with other protection rules");await this._commandService.executeCommand(a.SetRangeProtectionMutation.id,{unitId:this._unitId,subUnitId:this._subUnitId,ruleId:this._ruleId,rule:{...n,ranges:r.map(i=>i.getRange())}}),this._ranges.length=0,this._ranges.push(...r)}async remove(){await this._commandService.executeCommand(a.DeleteRangeProtectionMutation.id,{unitId:this._unitId,subUnitId:this._subUnitId,ruleIds:[this._ruleId]})}_rangesIntersect(r,n){return!(r.endRow<n.startRow||r.startRow>n.endRow||r.endColumn<n.startColumn||r.startColumn>n.endColumn)}};y=me([z(6,h.Inject(h.Injector)),z(7,h.Inject(h.ICommandService)),z(8,h.Inject(a.RangeProtectionRuleModel))],y);const F={[_.Edit]:a.WorkbookEditablePermission,[_.View]:a.WorkbookViewPermission,[_.Print]:a.WorkbookPrintPermission,[_.Export]:a.WorkbookExportPermission,[_.Share]:a.WorkbookSharePermission,[_.CopyContent]:a.WorkbookCopyPermission,[_.DuplicateFile]:a.WorkbookDuplicatePermission,[_.Comment]:a.WorkbookCommentPermission,[_.ManageCollaborator]:a.WorkbookManageCollaboratorPermission,[_.CreateSheet]:a.WorkbookCreateSheetPermission,[_.DeleteSheet]:a.WorkbookDeleteSheetPermission,[_.RenameSheet]:a.WorkbookRenameSheetPermission,[_.MoveSheet]:a.WorkbookMoveSheetPermission,[_.HideSheet]:a.WorkbookHideSheetPermission,[_.ViewHistory]:a.WorkbookViewHistoryPermission,[_.ManageHistory]:a.WorkbookHistoryPermission,[_.RecoverHistory]:a.WorkbookRecoverHistoryPermission,[_.CreateProtection]:a.WorkbookCreateProtectPermission,[_.InsertRow]:a.WorkbookInsertRowPermission,[_.InsertColumn]:a.WorkbookInsertColumnPermission,[_.DeleteRow]:a.WorkbookDeleteRowPermission,[_.DeleteColumn]:a.WorkbookDeleteColumnPermission,[_.CopySheet]:a.WorkbookCopySheetPermission},B={[w.Edit]:a.WorksheetEditPermission,[w.View]:a.WorksheetViewPermission,[w.Copy]:a.WorksheetCopyPermission,[w.SetCellValue]:a.WorksheetSetCellValuePermission,[w.SetCellStyle]:a.WorksheetSetCellStylePermission,[w.SetRowStyle]:a.WorksheetSetRowStylePermission,[w.SetColumnStyle]:a.WorksheetSetColumnStylePermission,[w.InsertRow]:a.WorksheetInsertRowPermission,[w.InsertColumn]:a.WorksheetInsertColumnPermission,[w.DeleteRow]:a.WorksheetDeleteRowPermission,[w.DeleteColumn]:a.WorksheetDeleteColumnPermission,[w.Sort]:a.WorksheetSortPermission,[w.Filter]:a.WorksheetFilterPermission,[w.PivotTable]:a.WorksheetPivotTablePermission,[w.InsertHyperlink]:a.WorksheetInsertHyperlinkPermission,[w.EditExtraObject]:a.WorksheetEditExtraObjectPermission,[w.ManageCollaborator]:a.WorksheetManageCollaboratorPermission,[w.DeleteProtection]:a.WorksheetDeleteProtectionPermission,[w.SelectProtectedCells]:a.WorksheetSelectProtectedCellsPermission,[w.SelectUnProtectedCells]:a.WorksheetSelectUnProtectedCellsPermission},O={[b.Edit]:a.RangeProtectionPermissionEditPoint,[b.View]:a.RangeProtectionPermissionViewPoint,[b.ManageCollaborator]:a.RangeProtectionPermissionManageCollaPoint,[b.Delete]:a.RangeProtectionPermissionDeleteProtectionPoint};var ge=Object.getOwnPropertyDescriptor,_e=(r,n,e,t)=>{for(var i=t>1?void 0:t?ge(n,e):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=s(i)||i);return i},D=(r,n)=>(e,t)=>n(e,t,r);let L=class{constructor(r,n,e,t,i,o,s,d){C(this,"_permissionSubject");C(this,"_rangeRulesSubject");C(this,"permission$");C(this,"pointChange$");C(this,"rangeProtectionChange$");C(this,"rangeProtectionRules$");C(this,"_unitId");C(this,"_subUnitId");C(this,"_subscriptions",[]);C(this,"_fPermission");this._worksheet=r,this._injector=n,this._permissionService=e,this._authzIoService=t,this._commandService=i,this._rangeProtectionRuleModel=o,this._worksheetProtectionPointModel=s,this._worksheetProtectionRuleModel=d,this._unitId=this._worksheet.getWorkbook().getUnitId(),this._subUnitId=this._worksheet.getSheetId(),this._fPermission=this._injector.createInstance(c.FPermission),this._permissionSubject=new N.BehaviorSubject(this._buildSnapshot()),this._rangeRulesSubject=new N.BehaviorSubject(this._buildRangeProtectionRules()),this.permission$=this._createPermissionStream(),this.pointChange$=this._createPointChangeStream(),this.rangeProtectionChange$=this._createRangeProtectionChangeStream(),this.rangeProtectionRules$=this._createRangeProtectionRulesStream()}_createPermissionStream(){const r=this._permissionService.permissionPointUpdate$.pipe(k.filter(n=>n.id.includes(this._unitId)&&n.id.includes(this._subUnitId))).subscribe(()=>{this._permissionSubject.next(this._buildSnapshot())});return this._subscriptions.push(r),this._permissionSubject.asObservable().pipe(k.distinctUntilChanged((n,e)=>JSON.stringify(n)===JSON.stringify(e)),k.shareReplay({bufferSize:1,refCount:!0}))}_createPointChangeStream(){return this._permissionService.permissionPointUpdate$.pipe(k.filter(r=>r.id.includes(this._unitId)&&r.id.includes(this._subUnitId)),k.map(r=>{var e,t;const n=this._extractWorksheetPointType(r.id);return n?{point:n,value:(e=r.value)!=null?e:!1,oldValue:!((t=r.value)!=null&&t)}:null}),k.filter(r=>r!==null),k.shareReplay({bufferSize:1,refCount:!0}))}_createRangeProtectionChangeStream(){return this._rangeProtectionRuleModel.ruleChange$.pipe(k.filter(r=>r.unitId===this._unitId&&r.subUnitId===this._subUnitId),k.map(r=>{const n=this._buildRangeProtectionRules();return{type:r.type==="delete"?"delete":r.type==="set"?"update":"add",rules:n}}),k.shareReplay({bufferSize:1,refCount:!0}))}_createRangeProtectionRulesStream(){const r=this._rangeProtectionRuleModel.ruleChange$.pipe(k.filter(n=>n.unitId===this._unitId&&n.subUnitId===this._subUnitId)).subscribe(()=>{this._rangeRulesSubject.next(this._buildRangeProtectionRules())});return this._subscriptions.push(r),this._rangeRulesSubject.asObservable().pipe(k.distinctUntilChanged((n,e)=>n.length!==e.length?!1:n.every((t,i)=>t.id===e[i].id)),k.shareReplay({bufferSize:1,refCount:!0}))}_extractWorksheetPointType(r){for(const[n,e]of Object.entries(B))if(new e(this._unitId,this._subUnitId).id===r)return n;return null}_getRuleEditPermission(r){var i;const n=O[b.Edit];if(!n)return!1;const e=new n(this._unitId,this._subUnitId,r.permissionId),t=this._permissionService.getPermissionPoint(e.id);return(i=t==null?void 0:t.value)!=null?i:!1}_buildSnapshot(){const r={};for(const n in w){const e=w[n];r[e]=this.getPoint(e)}return r}_buildRangeProtectionRules(){return this._rangeProtectionRuleModel.getSubunitRuleList(this._unitId,this._subUnitId).map(n=>{const e=n.ranges.map(t=>this._worksheet.getRange(t.startRow,t.startColumn,t.endRow-t.startRow+1,t.endColumn-t.startColumn+1));return this._injector.createInstance(y,this._unitId,this._subUnitId,n.id,n.permissionId,e,{name:n.description||"",allowEdit:this._getRuleEditPermission(n)})})}_buildProtectionRule(r){const n=r.ranges.map(t=>this._worksheet.getRange(t)),e={name:r.description||"",allowViewByOthers:r.viewState!==a.ViewStateEnum.NoOneElseCanView};return r.editState===a.EditStateEnum.DesignedUserCanEdit?e.allowEdit=!0:e.allowEdit=!1,this._injector.createInstance(y,this._unitId,this._subUnitId,r.id,r.permissionId,n,e)}debugCellPermission(r,n){const e=this._fPermission.getPermissionInfoWithCell(this._unitId,this._subUnitId,r,n);if(!e)return;const{ruleId:t}=e,i=this._rangeProtectionRuleModel.getRule(this._unitId,this._subUnitId,t);if(i)return this._buildProtectionRule(i)}async protect(r){if(this.isProtected())throw new Error("Worksheet is already protected. Call unprotect() first.");const n=await this._fPermission.addWorksheetBasePermission(this._unitId,this._subUnitId,r);if(!n)throw new Error("Failed to create worksheet protection");return n}async unprotect(){if(!this.isProtected())return;this._fPermission.removeWorksheetPermission(this._unitId,this._subUnitId);const r=this._buildSnapshot();this._permissionSubject.next(r)}isProtected(){return!!this._worksheetProtectionRuleModel.getRule(this._unitId,this._subUnitId)}async setMode(r){const n=this._getModePermissions(r);await this._batchSetPermissionPoints(n)}_getModePermissions(r){const n={};switch(Object.values(w).forEach(e=>{n[e]=!1}),r){case"editable":Object.values(w).forEach(e=>{n[e]=!0});break;case"readOnly":n[w.View]=!0;break;case"filterOnly":n[w.View]=!0,n[w.Sort]=!0,n[w.Filter]=!0;break}return n}async _batchSetPermissionPoints(r){const n=[];for(const[e,t]of Object.entries(r)){const i=e,o=B[i];if(!o)throw new Error(`Unknown worksheet permission point: ${i}`);const s=this.getPoint(i);s!==t&&(await this._fPermission.setWorksheetPermissionPoint(this._unitId,this._subUnitId,o,t),n.push({point:i,value:t,oldValue:s}))}if(n.length>0){const e=this._buildSnapshot();this._permissionSubject.next(e)}}async setReadOnly(){await this.setMode("readOnly")}async setEditable(){await this.setMode("editable")}canEdit(){return this.getPoint(w.Edit)}canEditCell(r,n){if(!this.canEdit())return!1;const e=this._rangeProtectionRuleModel.getSubunitRuleList(this._unitId,this._subUnitId);for(const t of e)for(const i of t.ranges)if(r>=i.startRow&&r<=i.endRow&&n>=i.startColumn&&n<=i.endColumn)return this._getRuleEditPermission(t);return!0}canViewCell(r,n){return this.getPoint(w.View)}async setPoint(r,n){const e=B[r];if(!e)throw new Error(`Unknown worksheet permission point: ${r}`);if(this.getPoint(r)===n)return;await this._fPermission.setWorksheetPermissionPoint(this._unitId,this._subUnitId,e,n);const i=this._buildSnapshot();this._permissionSubject.next(i)}getPoint(r){var i;const n=B[r];if(!n)throw new Error(`Unknown worksheet permission point: ${r}`);const e=new n(this._unitId,this._subUnitId),t=this._permissionService.getPermissionPoint(e.id);return(i=t==null?void 0:t.value)!=null?i:!0}getSnapshot(){return this._buildSnapshot()}async applyConfig(r){if(r.mode&&await this.setMode(r.mode),r.points)for(const[n,e]of Object.entries(r.points))typeof e=="boolean"&&await this.setPoint(n,e);if(r.rangeProtections&&r.rangeProtections.length>0){const n=r.rangeProtections.map(e=>({ranges:e.rangeRefs.map(t=>this._worksheet.getRange(t)),options:e.options}));await this.protectRanges(n)}}async protectRanges(r){if(!r||r.length===0)throw new Error("Configs cannot be empty");let n=[];r.some(d=>{var u,l;return(l=(u=d.options)==null?void 0:u.allowedUsers)==null?void 0:l.length})&&(n=await this._authzIoService.listCollaborators({objectID:this._unitId,unitID:this._unitId}));const t=await Promise.all(r.map(d=>{var l,g;let u=[];if((l=d.options)!=null&&l.allowedUsers){const m=new Set(d.options.allowedUsers);u=n.filter(I=>{var R;return m.has(((R=I.subject)==null?void 0:R.userID)||I.id)}).map(I=>({id:I.id,role:$.Editor,subject:I.subject}));const S=new Set(u.map(I=>{var R;return((R=I.subject)==null?void 0:R.userID)||I.id}));d.options.allowedUsers.forEach(I=>{S.has(I)||console.error(`User ${I} not found in collaborators list`)})}return this._authzIoService.create({objectType:a.UnitObject.SelectRange,selectRangeObject:{collaborators:u,unitID:this._unitId,name:((g=d.options)==null?void 0:g.name)||"",scope:void 0}})})),i=r.map((d,u)=>{var m;const l=this._determineViewState(d.options),g=this._determineEditState(d.options);return{permissionId:t[u],unitType:a.UnitObject.SelectRange,unitId:this._unitId,subUnitId:this._subUnitId,ranges:d.ranges.map(S=>S.getRange()),id:this._rangeProtectionRuleModel.createRuleId(this._unitId,this._subUnitId),description:((m=d.options)==null?void 0:m.name)||"",viewState:l,editState:g}});if(!await this._commandService.executeCommand(a.AddRangeProtectionMutation.id,{unitId:this._unitId,subUnitId:this._subUnitId,rules:i}))throw new Error("Failed to create range protection rules");return await Promise.all(r.map((d,u)=>this._setPermissionPoints(t[u],d.options))),i.map((d,u)=>this._injector.createInstance(y,this._unitId,this._subUnitId,d.id,d.permissionId,r[u].ranges,r[u].options||{}))}_determineViewState(r){return(r==null?void 0:r.allowViewByOthers)===!1?a.ViewStateEnum.NoOneElseCanView:a.ViewStateEnum.OthersCanView}_determineEditState(r){var n;return(r==null?void 0:r.allowEdit)===!0&&((n=r==null?void 0:r.allowedUsers)!=null&&n.length)?a.EditStateEnum.DesignedUserCanEdit:a.EditStateEnum.OnlyMe}async _setPermissionPoints(r,n){if(!n)return;const e=(t,i)=>t===void 0?i:typeof t=="boolean"?t:!0;await this._setPermissionPoint(r,b.Edit,e(n.allowEdit,!1)),await this._setPermissionPoint(r,b.View,e(n.allowViewByOthers,!0))}async _setPermissionPoint(r,n,e){const t=O[n];t&&this._fPermission.setRangeProtectionPermissionPoint(this._unitId,this._subUnitId,r,t,e)}async unprotectRules(r){!r||r.length===0||this._fPermission.removeRangeProtection(this._unitId,this._subUnitId,r)}async listRangeProtectionRules(){return this._buildRangeProtectionRules()}subscribe(r){const n=this.permission$.subscribe(r);return()=>n.unsubscribe()}dispose(){this._subscriptions.forEach(r=>r.unsubscribe()),this._permissionSubject.complete(),this._rangeRulesSubject.complete()}};L=_e([D(1,h.Inject(h.Injector)),D(2,h.IPermissionService),D(3,h.IAuthzIoService),D(4,h.ICommandService),D(5,h.Inject(a.RangeProtectionRuleModel)),D(6,h.Inject(a.WorksheetProtectionPointModel)),D(7,h.Inject(a.WorksheetProtectionRuleModel))],L);function Se(r){switch(r){case"left":return h.HorizontalAlign.LEFT;case"center":return h.HorizontalAlign.CENTER;case"normal":return h.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${r}`)}}function ee(r){switch(r){case h.HorizontalAlign.LEFT:return"left";case h.HorizontalAlign.CENTER:return"center";case h.HorizontalAlign.RIGHT:return"normal";default:return"general"}}function we(r){switch(r){case"top":return h.VerticalAlign.TOP;case"middle":return h.VerticalAlign.MIDDLE;case"bottom":return h.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${r}`)}}function te(r){switch(r){case h.VerticalAlign.TOP:return"top";case h.VerticalAlign.MIDDLE:return"middle";case h.VerticalAlign.BOTTOM:return"bottom";default:return"general"}}function G(r,n){return{startRow:r.startRow,endRow:r.endRow,startColumn:0,endColumn:n.getColumnCount()-1,rangeType:h.RANGE_TYPE.ROW}}function K(r,n){return{startRow:0,endRow:n.getRowCount()-1,startColumn:r.startColumn,endColumn:r.endColumn,rangeType:h.RANGE_TYPE.COLUMN}}var Ce=Object.getOwnPropertyDescriptor,ke=(r,n,e,t)=>{for(var i=t>1?void 0:t?Ce(n,e):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=s(i)||i);return i},H=(r,n)=>(e,t)=>n(e,t,r);c.FWorksheet=class extends f.FBaseInitialable{constructor(e,t,i,o,s,d,u){super(o);C(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=i,this._injector=o,this._selectionManagerService=s,this._logService=d,this._commandService=u}dispose(){super.dispose(),delete this._fWorkbook,delete this._workbook,delete this._worksheet}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(c.FSelection,this._workbook,this._worksheet,e):null}getDefaultStyle(){return this._worksheet.getDefaultCellStyle()}getRowDefaultStyle(e,t=!1){return t?this._worksheet.getRowStyle(e,t):this._worksheet.getRowStyle(e)}getColumnDefaultStyle(e,t=!1){return t?this._worksheet.getColumnStyle(e,t):this._worksheet.getColumnStyle(e)}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(),o=this._worksheet.getSheetId(),s={unitId:i,subUnitId:o,columnData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,s),this}setRowDefaultStyle(e,t){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),s={unitId:i,subUnitId:o,rowData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,s),this}getRange(e,t,i,o){let s,d;if(typeof e=="object")s=e,d=this._worksheet;else if(typeof e=="string"){const{range:u,sheetName:l}=U.deserializeRangeWithSheet(e),g=l?this._workbook.getSheetBySheetName(l):this._worksheet;if(!g)throw new Error("Range not found");d=g,s={...u,unitId:this._workbook.getUnitId(),sheetId:d.getSheetId(),rangeType:h.RANGE_TYPE.NORMAL,startRow:u.rangeType===h.RANGE_TYPE.COLUMN?0:u.startRow,endRow:u.rangeType===h.RANGE_TYPE.COLUMN?d.getMaxRows()-1:u.endRow,startColumn:u.rangeType===h.RANGE_TYPE.ROW?0:u.startColumn,endColumn:u.rangeType===h.RANGE_TYPE.ROW?d.getMaxColumns()-1:u.endColumn}}else if(typeof e=="number"&&t!==void 0)d=this._worksheet,s={startRow:e,endRow:e+(i!=null?i:1)-1,startColumn:t,endColumn:t+(o!=null?o:1)-1,unitId:this._workbook.getUnitId(),sheetId:this._worksheet.getSheetId()};else throw new Error("Invalid range specification");return this._injector.createInstance(c.FRange,this._workbook,d,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(),o=this._worksheet.getSheetId(),s=h.Direction.DOWN,d=e+1,u=e+t,l=0,g=this._worksheet.getColumnCount()-1,m=a.copyRangeStyles(this._worksheet,d,u,l,g,!0,e);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:i,subUnitId:o,direction:s,range:{startRow:d,endRow:u,startColumn:l,endColumn:g},cellValue:m}),this}insertRowsBefore(e,t){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),s=h.Direction.UP,d=e,u=e+t-1,l=0,g=this._worksheet.getColumnCount()-1,m=a.copyRangeStyles(this._worksheet,d,u,l,g,!0,e-1);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:i,subUnitId:o,direction:s,range:{startRow:d,endRow:u,startColumn:l,endColumn:g},cellValue:m}),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}deleteRowsByPoints(e){return h.generateIntervalsByPoints(e).reverse().forEach(i=>{this.deleteRows(i[0],i[1]-i[0]+1)}),this}moveRows(e,t){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),s=G(e.getRange(),this._worksheet),d=s,u={startRow:t,endRow:t,startColumn:s.startColumn,endColumn:s.endColumn};return this._commandService.syncExecuteCommand(a.MoveRowsCommand.id,{unitId:i,subUnitId:o,range:s,fromRange:d,toRange:u}),this}hideRow(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=G(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:t,subUnitId:i,ranges:[o]}),this}hideRows(e,t=1){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),s={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:h.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:i,subUnitId:o,ranges:[s]}),this}unhideRow(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=G(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:t,subUnitId:i,ranges:[o]}),this}showRows(e,t=1){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),s={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:h.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:i,subUnitId:o,ranges:[s]}),this}setRowHeight(e,t){return this.setRowHeights(e,1,t)}autoFitRow(e,t=h.BooleanNumber.TRUE){const i=this._workbook.getUnitId(),o=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:h.WrapStrategy.WRAP}),this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightMutation.id,{unitId:i,subUnitId:o,ranges:s,autoHeightInfo:t}),this}setRowHeights(e,t,i){var g;const o=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),d=this._worksheet.getRowManager(),u=[],l=[];for(let m=e;m<e+t;m++){const S=((g=d.getRow(m))==null?void 0:g.ah)||this._worksheet.getConfig().defaultRowHeight,I={startRow:m,endRow:m,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};i<=S?u.push(I):l.push(I)}return l.length>0&&this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:o,subUnitId:s,ranges:l,value:i}),u.length>0&&this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:o,subUnitId:s,ranges:u}),this}getRowHeight(e){return this._worksheet.getRowHeight(e)}setRowAutoHeight(e,t){const i=this._workbook.getUnitId(),o=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:o,ranges:s}),this}setRangesAutoHeight(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:t,subUnitId:i,ranges:e}),this}setRowHeightsForced(e,t,i){const o=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),d=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:o,subUnitId:s,ranges:d,value:i}),this}setRowCustom(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={};for(const[d,u]of Object.entries(e))o[Number(d)]={custom:u};const s={unitId:t,subUnitId:i,rowData:o};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(),o=this._worksheet.getSheetId(),s=h.Direction.RIGHT,d=0,u=this._worksheet.getRowCount()-1,l=e+1,g=e+t,m=a.copyRangeStyles(this._worksheet,d,u,l,g,!1,e);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:i,subUnitId:o,direction:s,range:{startRow:d,endRow:u,startColumn:l,endColumn:g},cellValue:m}),this}insertColumnsBefore(e,t){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),s=h.Direction.LEFT,d=0,u=this._worksheet.getRowCount()-1,l=e,g=e+t-1,m=a.copyRangeStyles(this._worksheet,d,u,l,g,!1,e-1);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:i,subUnitId:o,direction:s,range:{startRow:d,endRow:u,startColumn:l,endColumn:g},cellValue:m}),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}deleteColumnsByPoints(e){return h.generateIntervalsByPoints(e).reverse().forEach(i=>{this.deleteColumns(i[0],i[1]-i[0]+1)}),this}moveColumns(e,t){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),s=K(e.getRange(),this._worksheet),d=s,u={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return this._commandService.syncExecuteCommand(a.MoveColsCommand.id,{unitId:i,subUnitId:o,range:s,fromRange:d,toRange:u}),this}hideColumn(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=K(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:t,subUnitId:i,ranges:[o]}),this}hideColumns(e,t=1){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:h.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:i,subUnitId:o,ranges:[s]}),this}unhideColumn(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=K(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:t,subUnitId:i,ranges:[o]}),this}showColumns(e,t=1){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:h.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:i,subUnitId:o,ranges:[s]}),this}setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}setColumnWidths(e,t,i){const o=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),d=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return this._commandService.syncExecuteCommand(a.SetColWidthCommand.id,{unitId:o,subUnitId:s,ranges:d,value:i}),this}getColumnWidth(e){return this._worksheet.getColumnWidth(e)}setColumnCustom(e){const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={};for(const[d,u]of Object.entries(e))o[Number(d)]={custom:u};const s={unitId:t,subUnitId:i,columnData:o};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,s),this}getMergeData(){return this._worksheet.getMergeData().map(e=>this._injector.createInstance(c.FRange,this._workbook,this._worksheet,e))}getMergedRanges(){return this._worksheet.getSnapshot().mergeData.map(t=>this._injector.createInstance(c.FRange,this._workbook,this._worksheet,t))}getCellMergeData(e,t){const o=this._worksheet.getMergedCell(e,t);if(o)return this._injector.createInstance(c.FRange,this._workbook,this._worksheet,o)}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}getActiveCell(){return this._fWorkbook.getActiveCell()}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,o=0]=e;i>o&&([i,o]=[o,i]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startColumn:o+1,xSplit:o-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,o=0]=e;i>o&&([i,o]=[o,i]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startRow:o+1,ySplit:o-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===h.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.syncExecuteCommand(a.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?h.BooleanNumber.FALSE:h.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(),value:e}),this}getTabColor(){return this._worksheet.getTabColor()}onCellDataChange(e){return this._injector.get(h.ICommandService).onCommandExecuted(i=>{if(i.id===a.SetRangeValuesMutation.id){const o=i.params;o.unitId===this._workbook.getUnitId()&&o.subUnitId===this._worksheet.getSheetId()&&o.cellValue&&e(new h.ObjectMatrix(o.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(h.ICommandService).beforeCommandExecuted(i=>{if(i.id===a.SetRangeValuesMutation.id){const o=i.params;o.unitId===this._workbook.getUnitId()&&o.subUnitId===this._worksheet.getSheetId()&&o.cellValue&&e(new h.ObjectMatrix(o.cellValue))}})}hideSheet(){const e=this._injector.get(h.ICommandService);if(this._workbook.getSheets().filter(s=>s.isSheetHidden()!==h.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(h.ICommandService).syncExecuteCommand(a.SetWorksheetShowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}isSheetHidden(){return this._worksheet.isSheetHidden()===h.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){if(e&&e.contentsOnly&&!e.formatOnly)return this.clearContents();if(e&&e.formatOnly&&!e.contentsOnly)return this.clearFormats();const t=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=this._injector.get(h.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return o.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(h.ICommandService),o={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:[o]}),this}clearFormats(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),i=this._injector.get(h.ICommandService),o={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:[o]}),this}getDataRange(){const{startRow:e,endRow:t,startColumn:i,endColumn:o}=this._worksheet.getDataRealRange();return this.getRange(e,i,t-e+1,o-i+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 c.FWorksheet?this._worksheet.getSheetId()===e.getSheetId()&&this._workbook.getUnitId()===e.getWorkbook().getUnitId():!1}insertDefinedName(e,t){const o=this._injector.createInstance(A).setName(e).setRef(t).build();o.localSheetId=this.getSheetId(),this._fWorkbook.insertDefinedNameBuilder(o)}getDefinedNames(){return this._fWorkbook.getDefinedNames().filter(t=>t.getLocalSheetId()===this.getSheetId())}setCustomMetadata(e){return this._worksheet.setCustomMetadata(e),this}getCustomMetadata(){return this._worksheet.getCustomMetadata()}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)}appendRow(e){const t=this._worksheet.getCellMatrix().hasValue(),i=this._worksheet.getLastRowWithContent(),o=this._worksheet.getRowCount(),s=this._worksheet.getColumnCount(),d=t?i+1:i,u=new h.ObjectMatrix;for(let l=0;l<e.length;l++)u.setValue(d,l,h.covertCellValue(e[l]));return this._commandService.syncExecuteCommand(a.AppendRowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cellValue:u.getMatrix(),insertRowNums:d>o-1?1:0,insertColumnNums:e.length>s?e.length-s:0,maxRows:o,maxColumns:s}),this}setRowCount(e){return this._commandService.syncExecuteCommand(a.SetWorksheetRowCountCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rowCount:e}),this}setColumnCount(e){return this._commandService.syncExecuteCommand(a.SetWorksheetColumnCountCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),columnCount:e}),this}getWorksheetPermission(){return this._injector.createInstance(L,this)}},c.FWorksheet=ke([H(3,h.Inject(h.Injector)),H(4,h.Inject(a.SheetsSelectionsService)),H(5,h.Inject(h.ILogService)),H(6,h.ICommandService)],c.FWorksheet);var Ie=Object.getOwnPropertyDescriptor,be=(r,n,e,t)=>{for(var i=t>1?void 0:t?Ie(n,e):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=s(i)||i);return i},T=(r,n)=>(e,t)=>n(e,t,r);let Y=class{constructor(r,n,e,t,i,o,s,d,u){C(this,"_permissionSubject");C(this,"_subscriptions",[]);C(this,"_fPermission");C(this,"permission$");C(t