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