@univerjs/sheets 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +3 -3
- package/lib/es/facade.js +525 -344
- package/lib/es/index.js +4605 -3763
- package/lib/types/basics/interfaces/mutation-interface.d.ts +7 -0
- package/lib/types/commands/commands/__tests__/range-template-command.sepc.d.ts +16 -0
- package/lib/types/commands/commands/add-worksheet-merge.command.d.ts +1 -1
- package/lib/types/commands/commands/add-worksheet-range-theme.command.d.ts +2 -0
- package/lib/types/commands/commands/delete-worksheet-range-theme.command.d.ts +2 -0
- package/lib/types/commands/commands/insert-row-col.command.d.ts +2 -0
- package/lib/types/commands/commands/register-range-theme.command.d.ts +7 -0
- package/lib/types/commands/commands/remove-row-col.command.d.ts +12 -0
- package/lib/types/commands/commands/unregister-range-theme.command.d.ts +6 -0
- package/lib/types/commands/mutations/add-worksheet-range-theme.mutation.d.ts +9 -0
- package/lib/types/commands/mutations/delete-worksheet-range-theme.mutation.d.ts +9 -0
- package/lib/types/commands/mutations/register-range-theme.mutation.d.ts +8 -0
- package/lib/types/commands/mutations/unregister-range-theme-style.mutation.d.ts +6 -0
- package/lib/types/facade/f-event.d.ts +30 -0
- package/lib/types/facade/f-range.d.ts +56 -15
- package/lib/types/facade/f-selection.d.ts +1 -1
- package/lib/types/facade/f-univer.d.ts +22 -6
- package/lib/types/facade/f-workbook.d.ts +52 -16
- package/lib/types/facade/f-worksheet.d.ts +59 -59
- package/lib/types/facade/index.d.ts +2 -1
- package/lib/types/index.d.ts +15 -3
- package/lib/types/model/range-theme-model.d.ts +66 -0
- package/lib/types/model/range-theme-util.d.ts +97 -0
- package/lib/types/model/range-themes/build-in-theme.factory.d.ts +5 -0
- package/lib/types/model/range-themes/default.d.ts +2 -0
- package/lib/types/services/range-theme-service.d.ts +34 -0
- package/lib/types/services/sheet-interceptor/interceptor-const.d.ts +2 -0
- package/lib/types/services/sheet-interceptor/sheet-interceptor.service.d.ts +5 -3
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +3 -3
- package/package.json +8 -31
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var U=Object.defineProperty;var N=(h,o,e)=>o in h?U(h,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[o]=e;var k=(h,o,e)=>N(h,typeof o!="symbol"?o+"":o,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),w=require("@univerjs/engine-formula"),a=require("@univerjs/sheets");var E=Object.defineProperty,F=Object.getOwnPropertyDescriptor,x=(h,o,e,t)=>{for(var n=t>1?void 0:t?F(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&E(o,e,n),n},g=(h,o)=>(e,t)=>o(e,t,h);function j(h,o,e){const t=e.getDefinedNameMap(h);if(t==null)return o.t("definedName.defaultName")+1;const s=Array.from(Object.values(t)).length+1,i=o.t("definedName.defaultName")+s;if(e.getValueByName(h,i)==null)return i;let c=s+1;for(;;){const d=o.t("definedName.defaultName")+c;if(e.getValueByName(h,d)==null)return d;c++}}class v{constructor(){k(this,"_definedNameParam");this._definedNameParam={id:r.generateRandomId(10),unitId:"",name:"",formulaOrRefString:""}}setName(o){return this._definedNameParam.name=o,this}setFormula(o){return this._definedNameParam.formulaOrRefString=`=${o}`,this}setRef(o){return this._definedNameParam.formulaOrRefString=o,this}setRefByRange(o,e,t,n){return this._definedNameParam.formulaOrRefString=w.serializeRange({startRow:o,endRow:o+(t!=null?t:1)-1,startColumn:e,endColumn:e+(n!=null?n:1)-1}),this}setComment(o){return this._definedNameParam.comment=o,this}setHidden(o){return this._definedNameParam.hidden=o,this}build(){return this._definedNameParam}load(o){return this._definedNameParam=o,this}}let f=class extends r.FBase{constructor(h,o,e,t,n,s,i,c,d,m){super(),this._definedNameParam=h,this._injector=o,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=n,this._rangeProtectionRuleModel=s,this._worksheetProtectionPointRuleModel=i,this._authzIoService=c,this._localeService=d,this._definedNamesService=m}_apply(){this._definedNameParam.name===""&&(this._definedNameParam.name=j(this._definedNameParam.unitId,this._localeService,this._definedNamesService)),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,this._definedNameParam)}getName(){return this._definedNameParam.name}setName(h){this._definedNameParam.name=h,this._apply()}setFormula(h){this._definedNameParam.formulaOrRefString=`=${h}`,this._apply()}setRef(h){this._definedNameParam.formulaOrRefString=h,this._apply()}getFormulaOrRefString(){return this._definedNameParam.formulaOrRefString}setRefByRange(h,o,e,t){this._definedNameParam.formulaOrRefString=w.serializeRange({startRow:h,endRow:h+(e!=null?e:1)-1,startColumn:o,endColumn:o+(t!=null?t:1)-1}),this._apply()}getComment(){return this._definedNameParam.comment}setComment(h){this._definedNameParam.comment=h,this._apply()}setScopeToWorksheet(h){this._definedNameParam.localSheetId=h.getSheetId(),this._apply()}setScopeToWorkbook(){this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this._apply()}setHidden(h){this._definedNameParam.hidden=h,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 h=this._injector.createInstance(v);return h.load(this._definedNameParam),h}};f=x([g(1,r.Inject(r.Injector)),g(2,r.ICommandService),g(3,r.IPermissionService),g(4,r.Inject(a.WorksheetProtectionRuleModel)),g(5,r.Inject(a.RangeProtectionRuleModel)),g(6,r.Inject(a.WorksheetProtectionPointModel)),g(7,r.Inject(r.IAuthzIoService)),g(8,r.Inject(r.LocaleService)),g(9,w.IDefinedNamesService)],f);var W=Object.defineProperty,A=Object.getOwnPropertyDescriptor,D=(h,o,e,t)=>{for(var n=t>1?void 0:t?A(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&W(o,e,n),n},S=(h,o)=>(e,t)=>o(e,t,h);exports.FPermission=class extends r.FBase{constructor(e,t,n,s,i,c,d){super();k(this,"permissionPointsDefinition",a.PermissionPointsDefinitions);this._injector=e,this._commandService=t,this._permissionService=n,this._worksheetProtectionRuleModel=s,this._rangeProtectionRuleModel=i,this._worksheetProtectionPointRuleModel=c,this._authzIoService=d}setWorkbookPermissionPoint(e,t,n){const s=new t(e);this._permissionService.getPermissionPoint(s.id)||this._permissionService.addPermissionPoint(s),this._permissionService.updatePermissionPoint(s.id,n)}setWorkbookEditPermission(e,t){this.setWorkbookPermissionPoint(e,a.WorkbookEditablePermission,t)}async addWorksheetBasePermission(e,t){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");const s=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}});if(this._commandService.syncExecuteCommand(a.AddWorksheetProtectionMutation.id,{unitId:e,subUnitId:t,rule:{permissionId:s,unitType:a.UnitObject.Worksheet,unitId:e,subUnitId:t}}))return s}removeWorksheetPermission(e,t){this._commandService.syncExecuteCommand(a.DeleteWorksheetProtectionMutation.id,{unitId:e,subUnitId:t}),[...a.getAllWorksheetPermissionPoint(),...a.getAllWorksheetPermissionPointByPointPanel()].forEach(n=>{const s=new n(e,t);this._permissionService.updatePermissionPoint(s.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e,t)}async setWorksheetPermissionPoint(e,t,n,s){const i=this._worksheetProtectionRuleModel.getRule(e,t);let c;if(n===a.WorksheetEditPermission||n===a.WorksheetViewPermission)if(i)c=i.permissionId;else{if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");c=await this.addWorksheetBasePermission(e,t)}else{const u=this._worksheetProtectionPointRuleModel.getRule(e,t);u?c=u.permissionId:(c=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}}),this._commandService.executeCommand(a.SetWorksheetPermissionPointsMutation.id,{unitId:e,subUnitId:t,permissionId:c}))}const m=new n(e,t);return this._permissionService.getPermissionPoint(m.id)||this._permissionService.addPermissionPoint(m),this._permissionService.updatePermissionPoint(m.id,s),c}async addRangeBaseProtection(e,t,n){const s=await this._authzIoService.create({objectType:a.UnitObject.SelectRange,selectRangeObject:{collaborators:[],unitID:e,name:"",scope:void 0}}),i=`ruleId_${r.generateRandomId(6)}`;if(this._worksheetProtectionRuleModel.getRule(e,t))throw new Error("sheet protection cannot intersect with range protection");if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).some(u=>u.ranges.some(R=>n.some(C=>r.Rectangle.intersects(C,R)))))throw new Error("range protection cannot intersect");if(this._commandService.syncExecuteCommand(a.AddRangeProtectionMutation.id,{unitId:e,subUnitId:t,rules:[{permissionId:s,unitType:a.UnitObject.SelectRange,unitId:e,subUnitId:t,ranges:n,id:i}]}))return{permissionId:s,ruleId:i}}removeRangeProtection(e,t,n){this._commandService.syncExecuteCommand(a.DeleteRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleIds:n})&&this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length===0&&(this._worksheetProtectionPointRuleModel.deleteRule(e,t),[...a.getAllWorksheetPermissionPointByPointPanel()].forEach(c=>{const d=new c(e,t);this._permissionService.updatePermissionPoint(d.id,d.value)}))}setRangeProtectionPermissionPoint(e,t,n,s,i){const c=new s(e,t,n);this._permissionService.getPermissionPoint(c.id)||this._permissionService.addPermissionPoint(c),this._permissionService.updatePermissionPoint(c.id,i)}setRangeProtectionRanges(e,t,n,s){const i=this._rangeProtectionRuleModel.getRule(e,t,n);if(i){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).filter(m=>m.id!==n).some(m=>m.ranges.some(l=>s.some(u=>r.Rectangle.intersects(u,l)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(a.SetRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleId:n,rule:{...i,ranges:s}})}}setPermissionDialogVisible(e){this._permissionService.setShowComponents(e)}};exports.FPermission=D([S(0,r.Inject(r.Injector)),S(1,r.ICommandService),S(2,r.IPermissionService),S(3,r.Inject(a.WorksheetProtectionRuleModel)),S(4,r.Inject(a.RangeProtectionRuleModel)),S(5,r.Inject(a.WorksheetProtectionPointModel)),S(6,r.Inject(r.IAuthzIoService))],exports.FPermission);function O(h){switch(h){case"left":return r.HorizontalAlign.LEFT;case"center":return r.HorizontalAlign.CENTER;case"normal":return r.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${h}`)}}function M(h){switch(h){case r.HorizontalAlign.LEFT:return"left";case r.HorizontalAlign.CENTER:return"center";case r.HorizontalAlign.RIGHT:return"normal";default:throw new Error(`Invalid horizontal alignment: ${h}`)}}function T(h){switch(h){case"top":return r.VerticalAlign.TOP;case"middle":return r.VerticalAlign.MIDDLE;case"bottom":return r.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${h}`)}}function B(h){switch(h){case r.VerticalAlign.TOP:return"top";case r.VerticalAlign.MIDDLE:return"middle";case r.VerticalAlign.BOTTOM:return"bottom";default:throw new Error(`Invalid vertical alignment: ${h}`)}}function y(h){return r.isFormulaString(h)?{f:h}:r.isCellV(h)?{v:h}:(r.isICellData(h),h)}function L(h,o){const e=new r.ObjectMatrix,{startRow:t,startColumn:n,endRow:s,endColumn:i}=o;if(r.Tools.isArray(h))for(let c=0;c<=s-t;c++)for(let d=0;d<=i-n;d++)e.setValue(c+t,d+n,y(h[c][d]));else new r.ObjectMatrix(h).forValue((d,m,l)=>{e.setValue(d,m,y(l))});return e.getMatrix()}function b(h,o){return{startRow:h.startRow,endRow:h.endRow,startColumn:0,endColumn:o.getColumnCount()-1,rangeType:r.RANGE_TYPE.ROW}}function p(h,o){return{startRow:0,endRow:o.getRowCount()-1,startColumn:h.startColumn,endColumn:h.endColumn,rangeType:r.RANGE_TYPE.COLUMN}}var V=Object.defineProperty,z=Object.getOwnPropertyDescriptor,H=(h,o,e,t)=>{for(var n=t>1?void 0:t?z(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&V(o,e,n),n},P=(h,o)=>(e,t)=>o(e,t,h);exports.FRange=class extends r.FBase{constructor(o,e,t,n,s,i){super(),this._workbook=o,this._worksheet=e,this._range=t,this._injector=n,this._commandService=s,this._formulaDataModel=i}getUnitId(){return this._workbook.getUnitId()}getSheetName(){return this._worksheet.getName()}getRange(){return this._range}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}getCellData(){var o;return(o=this._worksheet.getCell(this._range.startRow,this._range.startColumn))!=null?o:null}isMerged(){const{startColumn:o,startRow:e,endColumn:t,endRow:n}=this._range;return this._worksheet.getMergedCellRange(e,o,n,t).some(i=>r.Rectangle.equals(i,this._range))}getCellStyleData(){var t;const o=this.getCellData(),e=this._workbook.getStyles();return o&&e&&(t=e.getStyleByCell(o))!=null?t:null}getValue(){var o,e;return(e=(o=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:o.v)!=null?e:null}getValues(){var i,c;const{startRow:o,endRow:e,startColumn:t,endColumn:n}=this._range,s=[];for(let d=o;d<=e;d++){const m=[];for(let l=t;l<=n;l++)m.push((c=(i=this._worksheet.getCell(d,l))==null?void 0:i.v)!=null?c:null);s.push(m)}return s}getCellDataGrid(){const{startRow:o,endRow:e,startColumn:t,endColumn:n}=this._range,s=[];for(let i=o;i<=e;i++){const c=[];for(let d=t;d<=n;d++)c.push(this._worksheet.getCellRaw(i,d));s.push(c)}return s}getFormulas(){const o=[],{startRow:e,endRow:t,startColumn:n,endColumn:s}=this._range,i=this._worksheet.getSheetId(),c=this._workbook.getUnitId();for(let d=e;d<=t;d++){const m=[];for(let l=n;l<=s;l++){const u=this._formulaDataModel.getFormulaStringByCell(d,l,i,c);m.push(u||"")}o.push(m)}return o}getWrap(){return this._worksheet.getRange(this._range).getWrap()===r.BooleanNumber.TRUE}getWrapStrategy(){return this._worksheet.getRange(this._range).getWrapStrategy()}getHorizontalAlignment(){return M(this._worksheet.getRange(this._range).getHorizontalAlignment())}getVerticalAlignment(){return B(this._worksheet.getRange(this._range).getVerticalAlignment())}setBackgroundColor(o){return this._commandService.executeCommand(a.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:o}}})}setBackground(o){return this.setBackgroundColor(o)}setValue(o){const e=y(o);if(!e)throw new Error("Invalid value");return this._commandService.executeCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e})}setWrap(o){return this._commandService.executeCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:o?r.WrapStrategy.WRAP:r.WrapStrategy.UNSPECIFIED})}setWrapStrategy(o){return this._commandService.executeCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:o})}setVerticalAlignment(o){return this._commandService.executeCommand(a.SetVerticalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:T(o)})}setHorizontalAlignment(o){return this._commandService.executeCommand(a.SetHorizontalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:O(o)})}setValues(o){const e=L(o,this._range);return this._commandService.executeCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e})}setFontWeight(o){let e;if(o==="bold")e=r.BooleanNumber.TRUE;else if(o==="normal")e=r.BooleanNumber.FALSE;else if(o===null)e=null;else throw new Error("Invalid fontWeight");const t={type:"bl",value:e},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.executeCommand(a.SetStyleCommand.id,n),this}setFontStyle(o){let e;if(o==="italic")e=r.BooleanNumber.TRUE;else if(o==="normal")e=r.BooleanNumber.FALSE;else if(o===null)e=null;else throw new Error("Invalid fontStyle");const t={type:"it",value:e},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.executeCommand(a.SetStyleCommand.id,n),this}setFontLine(o){if(o==="underline")this._setFontUnderline({s:r.BooleanNumber.TRUE});else if(o==="line-through")this._setFontStrikethrough({s:r.BooleanNumber.TRUE});else if(o==="none")this._setFontUnderline({s:r.BooleanNumber.FALSE}),this._setFontStrikethrough({s:r.BooleanNumber.FALSE});else if(o===null)this._setFontUnderline(null),this._setFontStrikethrough(null);else throw new Error("Invalid fontLine");return this}_setFontUnderline(o){const e={type:"ul",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.executeCommand(a.SetStyleCommand.id,t)}_setFontStrikethrough(o){const e={type:"st",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.executeCommand(a.SetStyleCommand.id,t)}setFontFamily(o){const e={type:"ff",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.executeCommand(a.SetStyleCommand.id,t),this}setFontSize(o){const e={type:"fs",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.executeCommand(a.SetStyleCommand.id,t),this}setFontColor(o){const t={type:"cl",value:o===null?null:{rgb:o}},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.executeCommand(a.SetStyleCommand.id,n),this}async merge(o=!0){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return await a.addMergeCellsUtil(this._injector,e,t,[this._range],o),this}async mergeAcross(o=!0){const e=a.getAddMergeMutationRangeByType([this._range],r.Dimension.ROWS),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return await a.addMergeCellsUtil(this._injector,t,n,e,o),this}async mergeVertically(o=!0){const e=a.getAddMergeMutationRangeByType([this._range],r.Dimension.COLUMNS),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return await a.addMergeCellsUtil(this._injector,t,n,e,o),this}isPartOfMerge(){const{startRow:o,startColumn:e,endRow:t,endColumn:n}=this._range;return this._worksheet.getMergedCellRange(o,e,t,n).length>0}breakApart(){return this._commandService.executeCommand(a.RemoveWorksheetMergeCommand.id,{ranges:[this._range]}),this}forEach(o){const{startColumn:e,startRow:t,endColumn:n,endRow:s}=this._range;this._worksheet.getMatrixWithMergedCells(t,e,s,n).forValue((i,c,d)=>{o(i,c,d)})}getA1Notation(o){return o?w.serializeRangeWithSheet(this._worksheet.getName(),this._range):w.serializeRange(this._range)}activate(){return this._injector.createInstance(exports.FWorkbook,this._workbook).setActiveRange(this),this}activateAsCurrentCell(){const o=this._worksheet.getMergedCell(this._range.startRow,this._range.startColumn);if(o&&r.Rectangle.equals(o,this._range)||!o&&this._range.startRow===this._range.endRow&&this._range.startColumn===this._range.endColumn)return this.activate();throw new Error("The range is not a single cell")}splitTextToColumns(o,e,t){this._commandService.executeCommand(a.SplitTextToColumnsCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,delimiter:e,customDelimiter:t,treatMultipleDelimitersAsOne:o})}};exports.FRange=H([P(3,r.Inject(r.Injector)),P(4,r.ICommandService),P(5,r.Inject(w.FormulaDataModel))],exports.FRange);var $=Object.defineProperty,G=Object.getOwnPropertyDescriptor,Y=(h,o,e,t)=>{for(var n=t>1?void 0:t?G(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&$(o,e,n),n},q=(h,o)=>(e,t)=>o(e,t,h);exports.FSelection=class{constructor(o,e,t,n){this._workbook=o,this._worksheet=e,this._selections=t,this._injector=n}getActiveRange(){const o=this._selections.find(e=>!!e.primary);return o?this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,o.range):null}getActiveRangeList(){return this._selections.map(o=>this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,o.range))}getCurrentCell(){const o=this._selections.find(e=>!!e.primary);return o?o.primary:null}getActiveSheet(){const o=this._injector.createInstance(exports.FWorkbook,this._workbook);return this._injector.createInstance(exports.FWorksheet,o,this._workbook,this._worksheet)}async updatePrimaryCell(o){const e=this._injector.get(r.ICommandService);let t=[],n=!1;for(const{range:i,style:c}of this._selections)r.Rectangle.contains(i,o.getRange())?(t.push({range:i,primary:a.getPrimaryForRange(o.getRange(),this._worksheet),style:c}),n=!0):t.push({range:i,primary:null,style:c});n||(t=[{range:o.getRange(),primary:a.getPrimaryForRange(o.getRange(),this._worksheet)}]);const s={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),selections:t};return await e.syncExecuteCommand(a.SetSelectionsOperation.id,s),new exports.FSelection(this._workbook,this._worksheet,t,this._injector)}getNextDataRange(o){if(!this._selections.find(n=>!!n.primary))return null;const t=a.getNextPrimaryCell(this._selections.concat(),o,this._worksheet);return t?this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,t):null}};exports.FSelection=Y([q(3,r.Inject(r.Injector))],exports.FSelection);var K=Object.defineProperty,J=Object.getOwnPropertyDescriptor,Q=(h,o,e,t)=>{for(var n=t>1?void 0:t?J(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&K(o,e,n),n},I=(h,o)=>(e,t)=>o(e,t,h);exports.FWorksheet=class extends r.FBase{constructor(e,t,n,s,i,c,d){super();k(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=n,this._injector=s,this._selectionManagerService=i,this._logService=c,this._commandService=d}getInject(){return this._injector}getWorkbook(){return this._workbook}getSheetId(){return this._worksheet.getSheetId()}getSheetName(){return this._worksheet.getName()}getSelection(){const e=this._selectionManagerService.getCurrentSelections();return e?this._injector.createInstance(exports.FSelection,this._workbook,this._worksheet,e):null}getDefaultStyle(){return this._worksheet.getDefaultCellStyle()}getRowDefaultStyle(e,t=!1){return this._worksheet.getRowStyle(e,t)}getColumnDefaultStyle(e,t=!1){return this._worksheet.getColumnStyle(e,t)}async setDefaultStyle(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return await this._commandService.executeCommand(a.SetWorksheetDefaultStyleMutation.id,{unitId:t,subUnitId:n,defaultStyle:e}),this._worksheet.setDefaultCellStyle(e),this}async setColumnDefaultStyle(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={unitId:n,subUnitId:s,columnData:{[e]:{s:t}}};return await this._commandService.executeCommand(a.SetColDataCommand.id,i),this}async setRowDefaultStyle(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={unitId:n,subUnitId:s,rowData:{[e]:{s:t}}};return await this._commandService.executeCommand(a.SetRowDataCommand.id,i),this}getRange(e,t,n,s){let i,c;if(typeof e=="string"){const{range:d,sheetName:m}=w.deserializeRangeWithSheet(e),l=m?this._workbook.getSheetBySheetName(m):this._worksheet;if(!l)throw new Error("Range not found");c=l,i={...d,unitId:this._workbook.getUnitId(),sheetId:c.getSheetId(),rangeType:r.RANGE_TYPE.NORMAL,startRow:d.rangeType===r.RANGE_TYPE.COLUMN?0:d.startRow,endRow:d.rangeType===r.RANGE_TYPE.COLUMN?c.getMaxRows()-1:d.endRow,startColumn:d.rangeType===r.RANGE_TYPE.ROW?0:d.startColumn,endColumn:d.rangeType===r.RANGE_TYPE.ROW?c.getMaxColumns()-1:d.endColumn}}else if(typeof e=="number"&&t!==void 0)c=this._worksheet,i={startRow:e,endRow:e+(n!=null?n:1)-1,startColumn:t,endColumn:t+(s!=null?s:1)-1,unitId:this._workbook.getUnitId(),sheetId:this._worksheet.getSheetId()};else throw new Error("Invalid range specification");return this._injector.createInstance(exports.FRange,this._workbook,c,i)}getMaxColumns(){return this._worksheet.getMaxColumns()}getMaxRows(){return this._worksheet.getMaxRows()}async insertRowAfter(e){return this.insertRowsAfter(e,1)}async insertRowBefore(e){return this.insertRowsBefore(e,1)}async insertRows(e,t=1){return this.insertRowsBefore(e,t)}async insertRowsAfter(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=r.Direction.DOWN,c=e+1,d=e+t,m=0,l=this._worksheet.getColumnCount()-1,u=a.copyRangeStyles(this._worksheet,c,d,m,l,!0,e);return await this._commandService.executeCommand(a.InsertRowCommand.id,{unitId:n,subUnitId:s,direction:i,range:{startRow:c,endRow:d,startColumn:m,endColumn:l},cellValue:u}),this}async insertRowsBefore(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=r.Direction.UP,c=e,d=e+t-1,m=0,l=this._worksheet.getColumnCount()-1,u=a.copyRangeStyles(this._worksheet,c,d,m,l,!0,e-1);return await this._commandService.executeCommand(a.InsertRowCommand.id,{unitId:n,subUnitId:s,direction:i,range:{startRow:c,endRow:d,startColumn:m,endColumn:l},cellValue:u}),this}async deleteRow(e){return this.deleteRows(e,1)}async deleteRows(e,t){const n={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return await this._commandService.executeCommand(a.RemoveRowCommand.id,{range:n}),this}async moveRows(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=b(e.getRange(),this._worksheet),c=i,d={startRow:t,endRow:t,startColumn:i.startColumn,endColumn:i.endColumn};return await this._commandService.executeCommand(a.MoveRowsCommand.id,{unitId:n,subUnitId:s,range:i,fromRange:c,toRange:d}),this}async hideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=b(e.getRange(),this._worksheet);return await this._commandService.executeCommand(a.SetRowHiddenCommand.id,{unitId:t,subUnitId:n,ranges:[s]}),this}async hideRows(e,t=1){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:r.RANGE_TYPE.ROW};return await this._commandService.executeCommand(a.SetRowHiddenCommand.id,{unitId:n,subUnitId:s,ranges:[i]}),this}async unhideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=b(e.getRange(),this._worksheet);return await this._commandService.executeCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:t,subUnitId:n,ranges:[s]}),this}async showRows(e,t=1){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:r.RANGE_TYPE.ROW};return await this._commandService.executeCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:n,subUnitId:s,ranges:[i]}),this}async setRowHeight(e,t){return this.setRowHeights(e,1,t)}async setRowHeights(e,t,n){var l;const s=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),c=this._worksheet.getRowManager(),d=[],m=[];for(let u=e;u<e+t;u++){const R=((l=c.getRow(u))==null?void 0:l.ah)||this._worksheet.getConfig().defaultRowHeight,C={startRow:u,endRow:u,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};n<=R?d.push(C):m.push(C)}return m.length>0&&await this._commandService.executeCommand(a.SetRowHeightCommand.id,{unitId:s,subUnitId:i,ranges:m,value:n}),d.length>0&&await this._commandService.executeCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:s,subUnitId:i,ranges:d}),this}async setRowHeightsForced(e,t,n){const s=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),c=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return await this._commandService.executeCommand(a.SetRowHeightCommand.id,{unitId:s,subUnitId:i,ranges:c,value:n}),this}async setRowCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s={};for(const[c,d]of Object.entries(e))s[Number(c)]={custom:d};const i={unitId:t,subUnitId:n,rowData:s};return await this._commandService.executeCommand(a.SetRowDataCommand.id,i),this}async insertColumnAfter(e){return this.insertColumnsAfter(e,1)}async insertColumnBefore(e){return this.insertColumnsBefore(e,1)}async insertColumns(e,t=1){return this.insertColumnsBefore(e,t)}async insertColumnsAfter(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=r.Direction.RIGHT,c=0,d=this._worksheet.getRowCount()-1,m=e+1,l=e+t,u=a.copyRangeStyles(this._worksheet,c,d,m,l,!1,e);return await this._commandService.executeCommand(a.InsertColCommand.id,{unitId:n,subUnitId:s,direction:i,range:{startRow:c,endRow:d,startColumn:m,endColumn:l},cellValue:u}),this}async insertColumnsBefore(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=r.Direction.LEFT,c=0,d=this._worksheet.getRowCount()-1,m=e,l=e+t-1,u=a.copyRangeStyles(this._worksheet,c,d,m,l,!1,e-1);return await this._commandService.executeCommand(a.InsertColCommand.id,{unitId:n,subUnitId:s,direction:i,range:{startRow:c,endRow:d,startColumn:m,endColumn:l},cellValue:u}),this}async deleteColumn(e){return this.deleteColumns(e,1)}async deleteColumns(e,t){const n={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1};return await this._commandService.executeCommand(a.RemoveColCommand.id,{range:n}),this}async moveColumns(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=p(e.getRange(),this._worksheet),c=i,d={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return await this._commandService.executeCommand(a.MoveColsCommand.id,{unitId:n,subUnitId:s,range:i,fromRange:c,toRange:d}),this}async hideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=p(e.getRange(),this._worksheet);return await this._commandService.executeCommand(a.SetColHiddenCommand.id,{unitId:t,subUnitId:n,ranges:[s]}),this}async hideColumns(e,t=1){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:r.RANGE_TYPE.COLUMN};return await this._commandService.executeCommand(a.SetColHiddenCommand.id,{unitId:n,subUnitId:s,ranges:[i]}),this}async unhideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=p(e.getRange(),this._worksheet);return await this._commandService.executeCommand(a.SetSpecificColsVisibleCommand.id,{unitId:t,subUnitId:n,ranges:[s]}),this}async showColumns(e,t=1){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:r.RANGE_TYPE.COLUMN};return await this._commandService.executeCommand(a.SetSpecificColsVisibleCommand.id,{unitId:n,subUnitId:s,ranges:[i]}),this}async setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}async setColumnWidths(e,t,n){const s=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),c=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return await this._commandService.executeCommand(a.SetColWidthCommand.id,{unitId:s,subUnitId:i,ranges:c,value:n}),this}async setColumnCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s={};for(const[c,d]of Object.entries(e))s[Number(c)]={custom:d};const i={unitId:t,subUnitId:n,columnData:s};return await this._commandService.executeCommand(a.SetColDataCommand.id,i),this}getMergedRanges(){return this._worksheet.getSnapshot().mergeData.map(t=>this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,t))}getCellMergeData(e,t){const s=this._worksheet.getMergedCell(e,t);if(s)return this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,s)}getActiveRange(){return this._fWorkbook.getActiveRange()}setActiveRange(e){const{unitId:t,sheetId:n}=e.getRange();if(t!==this._workbook.getUnitId()||n!==this._worksheet.getSheetId())throw new Error("Specified range must be part of the sheet.");this._fWorkbook.setActiveRange(e)}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()})}cancelFreeze(){return this._commandService.syncExecuteCommand(a.CancelFrozenCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}getFreeze(){return this._worksheet.getFreeze()}setFrozenColumns(...e){const t=this.getFreeze();if(arguments.length===1){const n=e[0];this.setFreeze({...t,startColumn:n>0?n:-1,xSplit:n})}else if(arguments.length===2){let[n=0,s=0]=e;n>s&&([n,s]=[s,n]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startColumn:s+1,xSplit:s-n+1,startRow:t.startRow,ySplit:t.ySplit,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}}setFrozenRows(...e){const t=this.getFreeze();if(arguments.length===1){const n=e[0];this.setFreeze({...t,startRow:n>0?n:-1,ySplit:n})}else if(arguments.length===2){let[n=0,s=0]=e;n>s&&([n,s]=[s,n]),this._commandService.syncExecuteCommand,this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startRow:s+1,ySplit:s-n+1,startColumn:t.startColumn,xSplit:t.xSplit,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()})}}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===r.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.executeCommand(a.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?r.BooleanNumber.FALSE:r.BooleanNumber.TRUE})}setGridLinesColor(e){return this._commandService.executeCommand(a.SetGridlinesColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e})}getGridLinesColor(){return this._worksheet.getGridlinesColor()}setTabColor(e){return this._commandService.executeCommand(a.SetTabColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e})}getTabColor(){return this._worksheet.getTabColor()}onCellDataChange(e){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===a.SetRangeValuesMutation.id){const s=n.params;s.unitId===this._workbook.getUnitId()&&s.subUnitId===this._worksheet.getSheetId()&&s.cellValue&&e(new r.ObjectMatrix(s.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(r.ICommandService).beforeCommandExecuted(n=>{if(n.id===a.SetRangeValuesMutation.id){const s=n.params;s.unitId===this._workbook.getUnitId()&&s.subUnitId===this._worksheet.getSheetId()&&s.cellValue&&e(new r.ObjectMatrix(s.cellValue))}})}hideSheet(){const e=this._injector.get(r.ICommandService);if(this._workbook.getSheets().filter(i=>i.isSheetHidden()!==r.BooleanNumber.TRUE).length<=1)throw new Error("Cannot hide the only visible sheet");e.executeCommand(a.SetWorksheetHideCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()})}showSheet(){return this._injector.get(r.ICommandService).executeCommand(a.SetWorksheetShowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()})}isSheetHidden(){return this._worksheet.isSheetHidden()===r.BooleanNumber.TRUE}setName(e){return this._commandService.executeCommand(a.SetWorksheetNameCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),name:e})}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(),n=this._worksheet.getSheetId(),s=this._injector.get(r.ICommandService),i={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return s.executeCommand(a.ClearSelectionAllCommand.id,{unitId:t,subUnitId:n,ranges:[i],options:e})}clearContents(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),n=this._injector.get(r.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return n.executeCommand(a.ClearSelectionContentCommand.id,{unitId:e,subUnitId:t,ranges:[s]})}clearFormats(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),n=this._injector.get(r.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return n.executeCommand(a.ClearSelectionFormatCommand.id,{unitId:e,subUnitId:t,ranges:[s]})}getDataRange(){const e=this.getLastRows(),t=this.getLastColumns();return this.getRange(0,0,e+1,t+1)}getLastColumns(){return this._worksheet.getLastColumnWithContent()}getLastColumn(){return this._worksheet.getLastColumnWithContent()}getLastRows(){return this._worksheet.getLastRowWithContent()}getLastRow(){return this._worksheet.getLastRowWithContent()}equalTo(e){return e instanceof exports.FWorksheet?this._worksheet.getSheetId()===e.getSheetId()&&this._workbook.getUnitId()===e.getWorkbook().getUnitId():!1}insertDefinedName(e,t){const s=this._injector.createInstance(v).setName(e).setRef(t).build();s.localSheetId=this.getSheetId(),this._fWorkbook.insertDefinedNameBuilder(s)}getDefinedNames(){return this._fWorkbook.getDefinedNames().filter(t=>t.getLocalSheetId()===this.getSheetId())}};exports.FWorksheet=Q([I(3,r.Inject(r.Injector)),I(4,r.Inject(a.SheetsSelectionsService)),I(5,r.Inject(r.ILogService)),I(6,r.ICommandService)],exports.FWorksheet);var X=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,ee=(h,o,e,t)=>{for(var n=t>1?void 0:t?Z(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&X(o,e,n),n},_=(h,o)=>(e,t)=>o(e,t,h);exports.FWorkbook=class extends r.FBase{constructor(e,t,n,s,i,c,d,m,l,u){super();k(this,"id");this._workbook=e,this._injector=t,this._resourceLoaderService=n,this._selectionManagerService=s,this._univerInstanceService=i,this._commandService=c,this._permissionService=d,this._logService=m,this._localeService=l,this._definedNamesService=u,this.id=this._workbook.getUnitId()}getId(){return this.id}getName(){return this._workbook.name}setName(e){this._workbook.setName(e)}save(){return this._resourceLoaderService.saveUnit(this._workbook.getUnitId())}getSnapshot(){return this._logService.warn("use 'save' instead of 'getSnapshot'"),this.save()}getActiveSheet(){const e=this._workbook.getActiveSheet();return this._injector.createInstance(exports.FWorksheet,this,this._workbook,e)}getSheets(){return this._workbook.getSheets().map(e=>this._injector.createInstance(exports.FWorksheet,this,this._workbook,e))}create(e,t,n){const s=r.mergeWorksheetSnapshotWithDefault({});s.rowCount=t,s.columnCount=n,s.name=e,s.id=e.toLowerCase().replace(/ /g,"-"),this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{unitId:this.id,index:this._workbook.getSheets().length,sheet:s}),this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId()});const i=this._workbook.getActiveSheet();if(!i)throw new Error("No active sheet found");return this._injector.createInstance(exports.FWorksheet,this,this._workbook,i)}getSheetBySheetId(e){const t=this._workbook.getSheetBySheetId(e);return t?this._injector.createInstance(exports.FWorksheet,this,this._workbook,t):null}getSheetByName(e){const t=this._workbook.getSheetBySheetName(e);return t?this._injector.createInstance(exports.FWorksheet,this,this._workbook,t):null}setActiveSheet(e){return this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:e.getSheetId()}),e}insertSheet(e){e!=null?this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{sheet:{name:e}}):this._commandService.syncExecuteCommand(a.InsertSheetCommand.id);const t=this.id,n=this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId();this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:t,subUnitId:n});const s=this._workbook.getActiveSheet();if(!s)throw new Error("No active sheet found");return this._injector.createInstance(exports.FWorksheet,this,this._workbook,s)}deleteSheet(e){const t=this.id,n=e.getSheetId();return this._commandService.executeCommand(a.RemoveSheetCommand.id,{unitId:t,subUnitId:n})}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(r.UndoCommand.id)}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(r.RedoCommand.id)}onBeforeCommandExecute(e){return this._commandService.beforeCommandExecuted(t=>{var n;((n=t.params)==null?void 0:n.unitId)===this.id&&e(t)})}onCommandExecuted(e){return this._commandService.onCommandExecuted(t=>{var n;((n=t.params)==null?void 0:n.unitId)===this.id&&e(t)})}onSelectionChange(e){return r.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(t=>{this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET).getUnitId()===this.id&&(t!=null&&t.length?e(t.map(n=>n.range)):e([]))}))}setEditable(e){const t=new a.WorkbookEditablePermission(this._workbook.getUnitId());this._permissionService.getPermissionPoint(t.id)||this._permissionService.addPermissionPoint(t),this._permissionService.updatePermissionPoint(t.id,e)}setActiveRange(e){const t=this.getActiveSheet(),n=e.getRange().sheetId||t.getSheetId(),s=n?this._workbook.getSheetBySheetId(n):this._workbook.getActiveSheet(!0);if(!s)throw new Error("No active sheet found");s.getSheetId()!==t.getSheetId()&&this.setActiveSheet(this._injector.createInstance(exports.FWorksheet,this,this._workbook,s));const i={unitId:this.getId(),subUnitId:n,selections:[e].map(c=>({range:c.getRange(),primary:a.getPrimaryForRange(c.getRange(),s),style:null}))};this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,i)}getActiveRange(){const e=this._workbook.getActiveSheet(),n=this._selectionManagerService.getCurrentSelections().find(s=>!!s.primary);return n?this._injector.createInstance(exports.FRange,this._workbook,e,n.range):null}deleteActiveSheet(){const e=this.getActiveSheet();return this.deleteSheet(e)}duplicateSheet(e){return this._commandService.executeCommand(a.CopySheetCommand.id,{unitId:e.getWorkbook().getUnitId(),subUnitId:e.getSheetId()})}duplicateActiveSheet(){const e=this.getActiveSheet();return this.duplicateSheet(e)}getNumSheets(){return this._workbook.getSheets().length}getLocale(){return this._localeService.getCurrentLocale()}setLocale(e){this._localeService.setLocale(e)}getUrl(){return location.href}moveSheet(e,t){let n=t;return n<0?n=0:n>this._workbook.getSheets().length-1&&(n=this._workbook.getSheets().length-1),this._commandService.executeCommand(a.SetWorksheetOrderCommand.id,{unitId:e.getWorkbook().getUnitId(),order:n,subUnitId:e.getSheetId()})}moveActiveSheet(e){const t=this.getActiveSheet();return this.moveSheet(t,e)}getPermission(){return this._injector.createInstance(exports.FPermission)}getDefinedName(e){const t=this._definedNamesService.getValueByName(this.id,e);return t?this._injector.createInstance(f,{...t,unitId:this.id}):null}getDefinedNames(){const e=this._definedNamesService.getDefinedNameMap(this.id);return e?Object.values(e).map(t=>this._injector.createInstance(f,{...t,unitId:this.id})):[]}insertDefinedName(e,t){const s=this._injector.createInstance(v).setName(e).setRef(t).build();s.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this.insertDefinedNameBuilder(s)}deleteDefinedName(e){const t=this.getDefinedName(e);return t?(t.delete(),!0):!1}insertDefinedNameBuilder(e){e.unitId=this.getId(),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}updateDefinedNameBuilder(e){this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}};exports.FWorkbook=ee([_(1,r.Inject(r.Injector)),_(2,r.Inject(r.IResourceLoaderService)),_(3,r.Inject(a.SheetsSelectionsService)),_(4,r.IUniverInstanceService),_(5,r.ICommandService),_(6,r.IPermissionService),_(7,r.ILogService),_(8,r.Inject(r.LocaleService)),_(9,w.IDefinedNamesService)],exports.FWorkbook);class te extends r.FUniver{createUniverSheet(o){const t=this._injector.get(r.IUniverInstanceService).createUnit(r.UniverInstanceType.UNIVER_SHEET,o);return this._injector.createInstance(exports.FWorkbook,t)}getActiveWorkbook(){const o=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);return o?this._injector.createInstance(exports.FWorkbook,o):null}getUniverSheet(o){const e=this._univerInstanceService.getUnit(o,r.UniverInstanceType.UNIVER_SHEET);return e?this._injector.createInstance(exports.FWorkbook,e):null}getPermission(){return this._injector.createInstance(exports.FPermission)}onUniverSheetCreated(o){const e=this._univerInstanceService.getTypeOfUnitAdded$(r.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{const n=this._injector.createInstance(exports.FWorkbook,t);o(n)});return r.toDisposable(e)}newDefinedName(){return this._injector.createInstance(v)}}r.FUniver.extend(te);var ne=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,se=(h,o,e,t)=>{for(var n=t>1?void 0:t?oe(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&ne(o,e,n),n},re=(h,o)=>(e,t)=>o(e,t,h);exports.FSheetHooks=class extends r.FBase{constructor(o){super(),this._injector=o}};exports.FSheetHooks=se([re(0,r.Inject(r.Injector))],exports.FSheetHooks);
|
|
1
|
+
"use strict";var E=Object.defineProperty;var N=(h,o,e)=>o in h?E(h,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[o]=e;var k=(h,o,e)=>N(h,typeof o!="symbol"?o+"":o,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),a=require("@univerjs/sheets"),S=require("@univerjs/engine-formula");var F=Object.defineProperty,x=Object.getOwnPropertyDescriptor,W=(h,o,e,t)=>{for(var n=t>1?void 0:t?x(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&F(o,e,n),n},g=(h,o)=>(e,t)=>o(e,t,h);function j(h,o,e){const t=e.getDefinedNameMap(h);if(t==null)return o.t("definedName.defaultName")+1;const s=Array.from(Object.values(t)).length+1,i=o.t("definedName.defaultName")+s;if(e.getValueByName(h,i)==null)return i;let c=s+1;for(;;){const d=o.t("definedName.defaultName")+c;if(e.getValueByName(h,d)==null)return d;c++}}class R{constructor(){k(this,"_definedNameParam");this._definedNameParam={id:r.generateRandomId(10),unitId:"",name:"",formulaOrRefString:""}}setName(o){return this._definedNameParam.name=o,this}setFormula(o){return this._definedNameParam.formulaOrRefString=`=${o}`,this}setRef(o){return this._definedNameParam.formulaOrRefString=o,this}setRefByRange(o,e,t,n){return this._definedNameParam.formulaOrRefString=S.serializeRange({startRow:o,endRow:o+(t!=null?t:1)-1,startColumn:e,endColumn:e+(n!=null?n:1)-1}),this}setComment(o){return this._definedNameParam.comment=o,this}setHidden(o){return this._definedNameParam.hidden=o,this}build(){return this._definedNameParam}load(o){return this._definedNameParam=o,this}}let v=class extends r.FBase{constructor(h,o,e,t,n,s,i,c,d,m){super(),this._definedNameParam=h,this._injector=o,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=n,this._rangeProtectionRuleModel=s,this._worksheetProtectionPointRuleModel=i,this._authzIoService=c,this._localeService=d,this._definedNamesService=m}_apply(){this._definedNameParam.name===""&&(this._definedNameParam.name=j(this._definedNameParam.unitId,this._localeService,this._definedNamesService)),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,this._definedNameParam)}getName(){return this._definedNameParam.name}setName(h){this._definedNameParam.name=h,this._apply()}setFormula(h){this._definedNameParam.formulaOrRefString=`=${h}`,this._apply()}setRef(h){this._definedNameParam.formulaOrRefString=h,this._apply()}getFormulaOrRefString(){return this._definedNameParam.formulaOrRefString}setRefByRange(h,o,e,t){this._definedNameParam.formulaOrRefString=S.serializeRange({startRow:h,endRow:h+(e!=null?e:1)-1,startColumn:o,endColumn:o+(t!=null?t:1)-1}),this._apply()}getComment(){return this._definedNameParam.comment}setComment(h){this._definedNameParam.comment=h,this._apply()}setScopeToWorksheet(h){this._definedNameParam.localSheetId=h.getSheetId(),this._apply()}setScopeToWorkbook(){this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this._apply()}setHidden(h){this._definedNameParam.hidden=h,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 h=this._injector.createInstance(R);return h.load(this._definedNameParam),h}};v=W([g(1,r.Inject(r.Injector)),g(2,r.ICommandService),g(3,r.IPermissionService),g(4,r.Inject(a.WorksheetProtectionRuleModel)),g(5,r.Inject(a.RangeProtectionRuleModel)),g(6,r.Inject(a.WorksheetProtectionPointModel)),g(7,r.Inject(r.IAuthzIoService)),g(8,r.Inject(r.LocaleService)),g(9,S.IDefinedNamesService)],v);var A=Object.defineProperty,D=Object.getOwnPropertyDescriptor,T=(h,o,e,t)=>{for(var n=t>1?void 0:t?D(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&A(o,e,n),n},w=(h,o)=>(e,t)=>o(e,t,h);exports.FPermission=class extends r.FBase{constructor(e,t,n,s,i,c,d){super();k(this,"permissionPointsDefinition",a.PermissionPointsDefinitions);this._injector=e,this._commandService=t,this._permissionService=n,this._worksheetProtectionRuleModel=s,this._rangeProtectionRuleModel=i,this._worksheetProtectionPointRuleModel=c,this._authzIoService=d}setWorkbookPermissionPoint(e,t,n){const s=new t(e);this._permissionService.getPermissionPoint(s.id)||this._permissionService.addPermissionPoint(s),this._permissionService.updatePermissionPoint(s.id,n)}setWorkbookEditPermission(e,t){this.setWorkbookPermissionPoint(e,a.WorkbookEditablePermission,t)}async addWorksheetBasePermission(e,t){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");const s=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}});if(this._commandService.syncExecuteCommand(a.AddWorksheetProtectionMutation.id,{unitId:e,subUnitId:t,rule:{permissionId:s,unitType:a.UnitObject.Worksheet,unitId:e,subUnitId:t}}))return s}removeWorksheetPermission(e,t){this._commandService.syncExecuteCommand(a.DeleteWorksheetProtectionMutation.id,{unitId:e,subUnitId:t}),[...a.getAllWorksheetPermissionPoint(),...a.getAllWorksheetPermissionPointByPointPanel()].forEach(n=>{const s=new n(e,t);this._permissionService.updatePermissionPoint(s.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e,t)}async setWorksheetPermissionPoint(e,t,n,s){const i=this._worksheetProtectionRuleModel.getRule(e,t);let c;if(n===a.WorksheetEditPermission||n===a.WorksheetViewPermission)if(i)c=i.permissionId;else{if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");c=await this.addWorksheetBasePermission(e,t)}else{const l=this._worksheetProtectionPointRuleModel.getRule(e,t);l?c=l.permissionId:(c=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}}),this._commandService.executeCommand(a.SetWorksheetPermissionPointsMutation.id,{unitId:e,subUnitId:t,permissionId:c}))}const m=new n(e,t);return this._permissionService.getPermissionPoint(m.id)||this._permissionService.addPermissionPoint(m),this._permissionService.updatePermissionPoint(m.id,s),c}async addRangeBaseProtection(e,t,n){const s=await this._authzIoService.create({objectType:a.UnitObject.SelectRange,selectRangeObject:{collaborators:[],unitID:e,name:"",scope:void 0}}),i=`ruleId_${r.generateRandomId(6)}`;if(this._worksheetProtectionRuleModel.getRule(e,t))throw new Error("sheet protection cannot intersect with range protection");if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).some(l=>l.ranges.some(f=>n.some(I=>r.Rectangle.intersects(I,f)))))throw new Error("range protection cannot intersect");if(this._commandService.syncExecuteCommand(a.AddRangeProtectionMutation.id,{unitId:e,subUnitId:t,rules:[{permissionId:s,unitType:a.UnitObject.SelectRange,unitId:e,subUnitId:t,ranges:n,id:i}]}))return{permissionId:s,ruleId:i}}removeRangeProtection(e,t,n){this._commandService.syncExecuteCommand(a.DeleteRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleIds:n})&&this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length===0&&(this._worksheetProtectionPointRuleModel.deleteRule(e,t),[...a.getAllWorksheetPermissionPointByPointPanel()].forEach(c=>{const d=new c(e,t);this._permissionService.updatePermissionPoint(d.id,d.value)}))}setRangeProtectionPermissionPoint(e,t,n,s,i){const c=new s(e,t,n);this._permissionService.getPermissionPoint(c.id)||this._permissionService.addPermissionPoint(c),this._permissionService.updatePermissionPoint(c.id,i)}setRangeProtectionRanges(e,t,n,s){const i=this._rangeProtectionRuleModel.getRule(e,t,n);if(i){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).filter(m=>m.id!==n).some(m=>m.ranges.some(u=>s.some(l=>r.Rectangle.intersects(l,u)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(a.SetRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleId:n,rule:{...i,ranges:s}})}}setPermissionDialogVisible(e){this._permissionService.setShowComponents(e)}};exports.FPermission=T([w(0,r.Inject(r.Injector)),w(1,r.ICommandService),w(2,r.IPermissionService),w(3,r.Inject(a.WorksheetProtectionRuleModel)),w(4,r.Inject(a.RangeProtectionRuleModel)),w(5,r.Inject(a.WorksheetProtectionPointModel)),w(6,r.Inject(r.IAuthzIoService))],exports.FPermission);function M(h){switch(h){case"left":return r.HorizontalAlign.LEFT;case"center":return r.HorizontalAlign.CENTER;case"normal":return r.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${h}`)}}function O(h){switch(h){case r.HorizontalAlign.LEFT:return"left";case r.HorizontalAlign.CENTER:return"center";case r.HorizontalAlign.RIGHT:return"normal";default:throw new Error(`Invalid horizontal alignment: ${h}`)}}function B(h){switch(h){case"top":return r.VerticalAlign.TOP;case"middle":return r.VerticalAlign.MIDDLE;case"bottom":return r.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${h}`)}}function L(h){switch(h){case r.VerticalAlign.TOP:return"top";case r.VerticalAlign.MIDDLE:return"middle";case r.VerticalAlign.BOTTOM:return"bottom";default:throw new Error(`Invalid vertical alignment: ${h}`)}}function P(h){return r.isFormulaString(h)?{f:h}:r.isCellV(h)?{v:h}:(r.isICellData(h),h)}function z(h,o){const e=new r.ObjectMatrix,{startRow:t,startColumn:n,endRow:s,endColumn:i}=o;if(r.Tools.isArray(h))for(let c=0;c<=s-t;c++)for(let d=0;d<=i-n;d++)e.setValue(c+t,d+n,P(h[c][d]));else new r.ObjectMatrix(h).forValue((d,m,u)=>{e.setValue(d,m,P(u))});return e.getMatrix()}function b(h,o){return{startRow:h.startRow,endRow:h.endRow,startColumn:0,endColumn:o.getColumnCount()-1,rangeType:r.RANGE_TYPE.ROW}}function p(h,o){return{startRow:0,endRow:o.getRowCount()-1,startColumn:h.startColumn,endColumn:h.endColumn,rangeType:r.RANGE_TYPE.COLUMN}}var V=Object.defineProperty,H=Object.getOwnPropertyDescriptor,$=(h,o,e,t)=>{for(var n=t>1?void 0:t?H(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&V(o,e,n),n},y=(h,o)=>(e,t)=>o(e,t,h);exports.FRange=class extends r.FBaseInitialable{constructor(o,e,t,n,s,i){super(n),this._workbook=o,this._worksheet=e,this._range=t,this._injector=n,this._commandService=s,this._formulaDataModel=i}getUnitId(){return this._workbook.getUnitId()}getSheetName(){return this._worksheet.getName()}getRange(){return this._range}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}getCellData(){var o;return(o=this._worksheet.getCell(this._range.startRow,this._range.startColumn))!=null?o:null}isMerged(){const{startColumn:o,startRow:e,endColumn:t,endRow:n}=this._range;return this._worksheet.getMergedCellRange(e,o,n,t).some(i=>r.Rectangle.equals(i,this._range))}getCellStyleData(){var t;const o=this.getCellData(),e=this._workbook.getStyles();return o&&e&&(t=e.getStyleByCell(o))!=null?t:null}getValue(){var o,e;return(e=(o=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:o.v)!=null?e:null}getValues(){var i,c;const{startRow:o,endRow:e,startColumn:t,endColumn:n}=this._range,s=[];for(let d=o;d<=e;d++){const m=[];for(let u=t;u<=n;u++)m.push((c=(i=this._worksheet.getCell(d,u))==null?void 0:i.v)!=null?c:null);s.push(m)}return s}getCellDataGrid(){const{startRow:o,endRow:e,startColumn:t,endColumn:n}=this._range,s=[];for(let i=o;i<=e;i++){const c=[];for(let d=t;d<=n;d++)c.push(this._worksheet.getCellRaw(i,d));s.push(c)}return s}getFormulas(){const o=[],{startRow:e,endRow:t,startColumn:n,endColumn:s}=this._range,i=this._worksheet.getSheetId(),c=this._workbook.getUnitId();for(let d=e;d<=t;d++){const m=[];for(let u=n;u<=s;u++){const l=this._formulaDataModel.getFormulaStringByCell(d,u,i,c);m.push(l||"")}o.push(m)}return o}getWrap(){return this._worksheet.getRange(this._range).getWrap()===r.BooleanNumber.TRUE}getWrapStrategy(){return this._worksheet.getRange(this._range).getWrapStrategy()}getHorizontalAlignment(){return O(this._worksheet.getRange(this._range).getHorizontalAlignment())}getVerticalAlignment(){return L(this._worksheet.getRange(this._range).getVerticalAlignment())}setBackgroundColor(o){return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:o}}}),this}setBackground(o){return this.setBackgroundColor(o),this}setValue(o){const e=P(o);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setWrap(o){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:o?r.WrapStrategy.WRAP:r.WrapStrategy.UNSPECIFIED}),this}setWrapStrategy(o){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:o}),this}setVerticalAlignment(o){return this._commandService.syncExecuteCommand(a.SetVerticalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:B(o)}),this}setHorizontalAlignment(o){return this._commandService.syncExecuteCommand(a.SetHorizontalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:M(o)}),this}setValues(o){const e=z(o,this._range);return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setFontWeight(o){let e;if(o==="bold")e=r.BooleanNumber.TRUE;else if(o==="normal")e=r.BooleanNumber.FALSE;else if(o===null)e=null;else throw new Error("Invalid fontWeight");const t={type:"bl",value:e},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.executeCommand(a.SetStyleCommand.id,n),this}setFontStyle(o){let e;if(o==="italic")e=r.BooleanNumber.TRUE;else if(o==="normal")e=r.BooleanNumber.FALSE;else if(o===null)e=null;else throw new Error("Invalid fontStyle");const t={type:"it",value:e},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.executeCommand(a.SetStyleCommand.id,n),this}setFontLine(o){if(o==="underline")this._setFontUnderline({s:r.BooleanNumber.TRUE});else if(o==="line-through")this._setFontStrikethrough({s:r.BooleanNumber.TRUE});else if(o==="none")this._setFontUnderline({s:r.BooleanNumber.FALSE}),this._setFontStrikethrough({s:r.BooleanNumber.FALSE});else if(o===null)this._setFontUnderline(null),this._setFontStrikethrough(null);else throw new Error("Invalid fontLine");return this}_setFontUnderline(o){const e={type:"ul",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.executeCommand(a.SetStyleCommand.id,t)}_setFontStrikethrough(o){const e={type:"st",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.executeCommand(a.SetStyleCommand.id,t)}setFontFamily(o){const e={type:"ff",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.executeCommand(a.SetStyleCommand.id,t),this}setFontSize(o){const e={type:"fs",value:o},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.executeCommand(a.SetStyleCommand.id,t),this}setFontColor(o){const t={type:"cl",value:o===null?null:{rgb:o}},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.executeCommand(a.SetStyleCommand.id,n),this}merge(o=!0){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,e,t,[this._range],o),this}mergeAcross(o=!0){const e=a.getAddMergeMutationRangeByType([this._range],r.Dimension.ROWS),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,n,e,o),this}mergeVertically(o=!0){const e=a.getAddMergeMutationRangeByType([this._range],r.Dimension.COLUMNS),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,n,e,o),this}isPartOfMerge(){const{startRow:o,startColumn:e,endRow:t,endColumn:n}=this._range;return this._worksheet.getMergedCellRange(o,e,t,n).length>0}breakApart(){return this._commandService.executeCommand(a.RemoveWorksheetMergeCommand.id,{ranges:[this._range]}),this}forEach(o){const{startColumn:e,startRow:t,endColumn:n,endRow:s}=this._range;this._worksheet.getMatrixWithMergedCells(t,e,s,n).forValue((i,c,d)=>{o(i,c,d)})}getA1Notation(o){return o?S.serializeRangeWithSheet(this._worksheet.getName(),this._range):S.serializeRange(this._range)}activate(){return this._injector.createInstance(exports.FWorkbook,this._workbook).setActiveRange(this),this}activateAsCurrentCell(){const o=this._worksheet.getMergedCell(this._range.startRow,this._range.startColumn);if(o&&r.Rectangle.equals(o,this._range)||!o&&this._range.startRow===this._range.endRow&&this._range.startColumn===this._range.endColumn)return this.activate();throw new Error("The range is not a single cell")}splitTextToColumns(o,e,t){this._commandService.executeCommand(a.SplitTextToColumnsCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,delimiter:e,customDelimiter:t,treatMultipleDelimitersAsOne:o})}useThemeStyle(o){if(o==null){const e=this.getUsedThemeStyle();e&&this.removeThemeStyle(e)}else this._commandService.executeCommand(a.SetWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:o})}removeThemeStyle(o){this._commandService.executeCommand(a.DeleteWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:o})}getUsedThemeStyle(){return this._injector.get(a.SheetRangeThemeService).getAppliedRangeThemeStyle({unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})}};exports.FRange=$([y(3,r.Inject(r.Injector)),y(4,r.ICommandService),y(5,r.Inject(S.FormulaDataModel))],exports.FRange);var G=Object.defineProperty,Y=Object.getOwnPropertyDescriptor,q=(h,o,e,t)=>{for(var n=t>1?void 0:t?Y(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&G(o,e,n),n},K=(h,o)=>(e,t)=>o(e,t,h);exports.FSelection=class{constructor(o,e,t,n){this._workbook=o,this._worksheet=e,this._selections=t,this._injector=n}getActiveRange(){const o=this._selections.find(e=>!!e.primary);return o?this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,o.range):null}getActiveRangeList(){return this._selections.map(o=>this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,o.range))}getCurrentCell(){const o=this._selections.find(e=>!!e.primary);return o?o.primary:null}getActiveSheet(){const o=this._injector.createInstance(exports.FWorkbook,this._workbook);return this._injector.createInstance(exports.FWorksheet,o,this._workbook,this._worksheet)}updatePrimaryCell(o){const e=this._injector.get(r.ICommandService);let t=[],n=!1;for(const{range:i,style:c}of this._selections)r.Rectangle.contains(i,o.getRange())?(t.push({range:i,primary:a.getPrimaryForRange(o.getRange(),this._worksheet),style:c}),n=!0):t.push({range:i,primary:null,style:c});n||(t=[{range:o.getRange(),primary:a.getPrimaryForRange(o.getRange(),this._worksheet)}]);const s={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),selections:t};return e.syncExecuteCommand(a.SetSelectionsOperation.id,s),new exports.FSelection(this._workbook,this._worksheet,t,this._injector)}getNextDataRange(o){if(!this._selections.find(n=>!!n.primary))return null;const t=a.getNextPrimaryCell(this._selections.concat(),o,this._worksheet);return t?this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,t):null}};exports.FSelection=q([K(3,r.Inject(r.Injector))],exports.FSelection);var J=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,X=(h,o,e,t)=>{for(var n=t>1?void 0:t?Q(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&J(o,e,n),n},C=(h,o)=>(e,t)=>o(e,t,h);exports.FWorksheet=class extends r.FBaseInitialable{constructor(e,t,n,s,i,c,d){super(s);k(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=n,this._injector=s,this._selectionManagerService=i,this._logService=c,this._commandService=d}getInject(){return this._injector}getWorkbook(){return this._workbook}getSheetId(){return this._worksheet.getSheetId()}getSheetName(){return this._worksheet.getName()}getSelection(){const e=this._selectionManagerService.getCurrentSelections();return e?this._injector.createInstance(exports.FSelection,this._workbook,this._worksheet,e):null}getDefaultStyle(){return this._worksheet.getDefaultCellStyle()}getRowDefaultStyle(e,t=!1){return this._worksheet.getRowStyle(e,t)}getColumnDefaultStyle(e,t=!1){return this._worksheet.getColumnStyle(e,t)}setDefaultStyle(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return this._commandService.syncExecuteCommand(a.SetWorksheetDefaultStyleMutation.id,{unitId:t,subUnitId:n,defaultStyle:e}),this._worksheet.setDefaultCellStyle(e),this}setColumnDefaultStyle(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={unitId:n,subUnitId:s,columnData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,i),this}setRowDefaultStyle(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={unitId:n,subUnitId:s,rowData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,i),this}getRange(e,t,n,s){let i,c;if(typeof e=="string"){const{range:d,sheetName:m}=S.deserializeRangeWithSheet(e),u=m?this._workbook.getSheetBySheetName(m):this._worksheet;if(!u)throw new Error("Range not found");c=u,i={...d,unitId:this._workbook.getUnitId(),sheetId:c.getSheetId(),rangeType:r.RANGE_TYPE.NORMAL,startRow:d.rangeType===r.RANGE_TYPE.COLUMN?0:d.startRow,endRow:d.rangeType===r.RANGE_TYPE.COLUMN?c.getMaxRows()-1:d.endRow,startColumn:d.rangeType===r.RANGE_TYPE.ROW?0:d.startColumn,endColumn:d.rangeType===r.RANGE_TYPE.ROW?c.getMaxColumns()-1:d.endColumn}}else if(typeof e=="number"&&t!==void 0)c=this._worksheet,i={startRow:e,endRow:e+(n!=null?n:1)-1,startColumn:t,endColumn:t+(s!=null?s:1)-1,unitId:this._workbook.getUnitId(),sheetId:this._worksheet.getSheetId()};else throw new Error("Invalid range specification");return this._injector.createInstance(exports.FRange,this._workbook,c,i)}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 n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=r.Direction.DOWN,c=e+1,d=e+t,m=0,u=this._worksheet.getColumnCount()-1,l=a.copyRangeStyles(this._worksheet,c,d,m,u,!0,e);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:n,subUnitId:s,direction:i,range:{startRow:c,endRow:d,startColumn:m,endColumn:u},cellValue:l}),this}insertRowsBefore(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=r.Direction.UP,c=e,d=e+t-1,m=0,u=this._worksheet.getColumnCount()-1,l=a.copyRangeStyles(this._worksheet,c,d,m,u,!0,e-1);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:n,subUnitId:s,direction:i,range:{startRow:c,endRow:d,startColumn:m,endColumn:u},cellValue:l}),this}deleteRow(e){return this.deleteRows(e,1)}deleteRows(e,t){const n={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return this._commandService.syncExecuteCommand(a.RemoveRowByRangeCommand.id,{range:n,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}moveRows(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=b(e.getRange(),this._worksheet),c=i,d={startRow:t,endRow:t,startColumn:i.startColumn,endColumn:i.endColumn};return this._commandService.syncExecuteCommand(a.MoveRowsCommand.id,{unitId:n,subUnitId:s,range:i,fromRange:c,toRange:d}),this}hideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=b(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:t,subUnitId:n,ranges:[s]}),this}hideRows(e,t=1){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:r.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:n,subUnitId:s,ranges:[i]}),this}unhideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=b(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:t,subUnitId:n,ranges:[s]}),this}showRows(e,t=1){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:r.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:n,subUnitId:s,ranges:[i]}),this}setRowHeight(e,t){return this.setRowHeights(e,1,t)}setRowHeights(e,t,n){var u;const s=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),c=this._worksheet.getRowManager(),d=[],m=[];for(let l=e;l<e+t;l++){const f=((u=c.getRow(l))==null?void 0:u.ah)||this._worksheet.getConfig().defaultRowHeight,I={startRow:l,endRow:l,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};n<=f?d.push(I):m.push(I)}return m.length>0&&this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:s,subUnitId:i,ranges:m,value:n}),d.length>0&&this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:s,subUnitId:i,ranges:d}),this}setRowHeightsForced(e,t,n){const s=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),c=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:s,subUnitId:i,ranges:c,value:n}),this}setRowCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s={};for(const[c,d]of Object.entries(e))s[Number(c)]={custom:d};const i={unitId:t,subUnitId:n,rowData:s};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,i),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 n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=r.Direction.RIGHT,c=0,d=this._worksheet.getRowCount()-1,m=e+1,u=e+t,l=a.copyRangeStyles(this._worksheet,c,d,m,u,!1,e);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:n,subUnitId:s,direction:i,range:{startRow:c,endRow:d,startColumn:m,endColumn:u},cellValue:l}),this}insertColumnsBefore(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=r.Direction.LEFT,c=0,d=this._worksheet.getRowCount()-1,m=e,u=e+t-1,l=a.copyRangeStyles(this._worksheet,c,d,m,u,!1,e-1);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:n,subUnitId:s,direction:i,range:{startRow:c,endRow:d,startColumn:m,endColumn:u},cellValue:l}),this}deleteColumn(e){return this.deleteColumns(e,1)}deleteColumns(e,t){const n={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1};return this._commandService.syncExecuteCommand(a.RemoveColByRangeCommand.id,{range:n,unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}moveColumns(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i=p(e.getRange(),this._worksheet),c=i,d={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return this._commandService.syncExecuteCommand(a.MoveColsCommand.id,{unitId:n,subUnitId:s,range:i,fromRange:c,toRange:d}),this}hideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=p(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:t,subUnitId:n,ranges:[s]}),this}hideColumns(e,t=1){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:r.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:n,subUnitId:s,ranges:[i]}),this}unhideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=p(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:t,subUnitId:n,ranges:[s]}),this}showColumns(e,t=1){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),i={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:r.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:n,subUnitId:s,ranges:[i]}),this}setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}setColumnWidths(e,t,n){const s=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),c=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return this._commandService.syncExecuteCommand(a.SetColWidthCommand.id,{unitId:s,subUnitId:i,ranges:c,value:n}),this}setColumnCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s={};for(const[c,d]of Object.entries(e))s[Number(c)]={custom:d};const i={unitId:t,subUnitId:n,columnData:s};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,i),this}getMergedRanges(){return this._worksheet.getSnapshot().mergeData.map(t=>this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,t))}getCellMergeData(e,t){const s=this._worksheet.getMergedCell(e,t);if(s)return this._injector.createInstance(exports.FRange,this._workbook,this._worksheet,s)}getActiveRange(){return this._fWorkbook.getActiveRange()}setActiveRange(e){const{unitId:t,sheetId:n}=e.getRange();if(t!==this._workbook.getUnitId()||n!==this._worksheet.getSheetId())throw new Error("Specified range must be part of the sheet.");this._fWorkbook.setActiveRange(e)}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 n=e[0];this.setFreeze({...t,startColumn:n>0?n:-1,xSplit:n})}else if(arguments.length===2){let[n=0,s=0]=e;n>s&&([n,s]=[s,n]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startColumn:s+1,xSplit:s-n+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 n=e[0];this.setFreeze({...t,startRow:n>0?n:-1,ySplit:n})}else if(arguments.length===2){let[n=0,s=0]=e;n>s&&([n,s]=[s,n]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startRow:s+1,ySplit:s-n+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===r.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.executeCommand(a.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?r.BooleanNumber.FALSE:r.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.executeCommand(a.SetTabColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getTabColor(){return this._worksheet.getTabColor()}onCellDataChange(e){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===a.SetRangeValuesMutation.id){const s=n.params;s.unitId===this._workbook.getUnitId()&&s.subUnitId===this._worksheet.getSheetId()&&s.cellValue&&e(new r.ObjectMatrix(s.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(r.ICommandService).beforeCommandExecuted(n=>{if(n.id===a.SetRangeValuesMutation.id){const s=n.params;s.unitId===this._workbook.getUnitId()&&s.subUnitId===this._worksheet.getSheetId()&&s.cellValue&&e(new r.ObjectMatrix(s.cellValue))}})}hideSheet(){const e=this._injector.get(r.ICommandService);if(this._workbook.getSheets().filter(i=>i.isSheetHidden()!==r.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(r.ICommandService).syncExecuteCommand(a.SetWorksheetShowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}isSheetHidden(){return this._worksheet.isSheetHidden()===r.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(),n=this._worksheet.getSheetId(),s=this._injector.get(r.ICommandService),i={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return s.syncExecuteCommand(a.ClearSelectionAllCommand.id,{unitId:t,subUnitId:n,ranges:[i],options:e}),this}clearContents(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),n=this._injector.get(r.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return n.syncExecuteCommand(a.ClearSelectionContentCommand.id,{unitId:e,subUnitId:t,ranges:[s]}),this}clearFormats(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),n=this._injector.get(r.ICommandService),s={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return n.syncExecuteCommand(a.ClearSelectionFormatCommand.id,{unitId:e,subUnitId:t,ranges:[s]}),this}getDataRange(){const e=this.getLastRows(),t=this.getLastColumns();return this.getRange(0,0,e+1,t+1)}getLastColumns(){return this._worksheet.getLastColumnWithContent()}getLastColumn(){return this._worksheet.getLastColumnWithContent()}getLastRows(){return this._worksheet.getLastRowWithContent()}getLastRow(){return this._worksheet.getLastRowWithContent()}equalTo(e){return e instanceof exports.FWorksheet?this._worksheet.getSheetId()===e.getSheetId()&&this._workbook.getUnitId()===e.getWorkbook().getUnitId():!1}insertDefinedName(e,t){const s=this._injector.createInstance(R).setName(e).setRef(t).build();s.localSheetId=this.getSheetId(),this._fWorkbook.insertDefinedNameBuilder(s)}getDefinedNames(){return this._fWorkbook.getDefinedNames().filter(t=>t.getLocalSheetId()===this.getSheetId())}};exports.FWorksheet=X([C(3,r.Inject(r.Injector)),C(4,r.Inject(a.SheetsSelectionsService)),C(5,r.Inject(r.ILogService)),C(6,r.ICommandService)],exports.FWorksheet);var Z=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=(h,o,e,t)=>{for(var n=t>1?void 0:t?ee(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&Z(o,e,n),n},_=(h,o)=>(e,t)=>o(e,t,h);exports.FWorkbook=class extends r.FBaseInitialable{constructor(e,t,n,s,i,c,d,m,u,l){super(t);k(this,"id");this._workbook=e,this._injector=t,this._resourceLoaderService=n,this._selectionManagerService=s,this._univerInstanceService=i,this._commandService=c,this._permissionService=d,this._logService=m,this._localeService=u,this._definedNamesService=l,this.id=this._workbook.getUnitId()}getId(){return this.id}getName(){return this._workbook.name}setName(e){this._workbook.setName(e)}save(){return this._resourceLoaderService.saveUnit(this._workbook.getUnitId())}getSnapshot(){return this._logService.warn("use 'save' instead of 'getSnapshot'"),this.save()}getActiveSheet(){const e=this._workbook.getActiveSheet();return this._injector.createInstance(exports.FWorksheet,this,this._workbook,e)}getSheets(){return this._workbook.getSheets().map(e=>this._injector.createInstance(exports.FWorksheet,this,this._workbook,e))}create(e,t,n){const s=r.mergeWorksheetSnapshotWithDefault({});s.rowCount=t,s.columnCount=n,s.name=e,s.id=e.toLowerCase().replace(/ /g,"-"),this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{unitId:this.id,index:this._workbook.getSheets().length,sheet:s}),this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId()});const i=this._workbook.getActiveSheet();if(!i)throw new Error("No active sheet found");return this._injector.createInstance(exports.FWorksheet,this,this._workbook,i)}getSheetBySheetId(e){const t=this._workbook.getSheetBySheetId(e);return t?this._injector.createInstance(exports.FWorksheet,this,this._workbook,t):null}getSheetByName(e){const t=this._workbook.getSheetBySheetName(e);return t?this._injector.createInstance(exports.FWorksheet,this,this._workbook,t):null}setActiveSheet(e){return this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:e.getSheetId()}),e}insertSheet(e){e!=null?this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{sheet:{name:e}}):this._commandService.syncExecuteCommand(a.InsertSheetCommand.id);const t=this.id,n=this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId();this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:t,subUnitId:n});const s=this._workbook.getActiveSheet();if(!s)throw new Error("No active sheet found");return this._injector.createInstance(exports.FWorksheet,this,this._workbook,s)}deleteSheet(e){const t=this.id,n=e.getSheetId();return this._commandService.syncExecuteCommand(a.RemoveSheetCommand.id,{unitId:t,subUnitId:n})}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(r.UndoCommand.id),this}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(r.RedoCommand.id),this}onBeforeCommandExecute(e){return this._commandService.beforeCommandExecuted(t=>{var n;((n=t.params)==null?void 0:n.unitId)===this.id&&e(t)})}onCommandExecuted(e){return this._commandService.onCommandExecuted(t=>{var n;((n=t.params)==null?void 0:n.unitId)===this.id&&e(t)})}onSelectionChange(e){return r.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(t=>{this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET).getUnitId()===this.id&&(t!=null&&t.length?e(t.map(n=>n.range)):e([]))}))}setEditable(e){const t=new a.WorkbookEditablePermission(this._workbook.getUnitId());this._permissionService.getPermissionPoint(t.id)||this._permissionService.addPermissionPoint(t),this._permissionService.updatePermissionPoint(t.id,e)}setActiveRange(e){const t=this.getActiveSheet(),n=e.getRange().sheetId||t.getSheetId(),s=n?this._workbook.getSheetBySheetId(n):this._workbook.getActiveSheet(!0);if(!s)throw new Error("No active sheet found");s.getSheetId()!==t.getSheetId()&&this.setActiveSheet(this._injector.createInstance(exports.FWorksheet,this,this._workbook,s));const i={unitId:this.getId(),subUnitId:n,selections:[e].map(c=>({range:c.getRange(),primary:a.getPrimaryForRange(c.getRange(),s),style:null}))};this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,i)}getActiveRange(){const e=this._workbook.getActiveSheet(),n=this._selectionManagerService.getCurrentSelections().find(s=>!!s.primary);return n?this._injector.createInstance(exports.FRange,this._workbook,e,n.range):null}deleteActiveSheet(){const e=this.getActiveSheet();return this.deleteSheet(e)}duplicateSheet(e){return this._commandService.syncExecuteCommand(a.CopySheetCommand.id,{unitId:e.getWorkbook().getUnitId(),subUnitId:e.getSheetId()}),this._injector.createInstance(exports.FWorksheet,this,this._workbook,this._workbook.getActiveSheet())}duplicateActiveSheet(){const e=this.getActiveSheet();return this.duplicateSheet(e)}getNumSheets(){return this._workbook.getSheets().length}getLocale(){return this._localeService.getCurrentLocale()}setLocale(e){this._localeService.setLocale(e)}getUrl(){return location.href}moveSheet(e,t){let n=t;return n<0?n=0:n>this._workbook.getSheets().length-1&&(n=this._workbook.getSheets().length-1),this._commandService.syncExecuteCommand(a.SetWorksheetOrderCommand.id,{unitId:e.getWorkbook().getUnitId(),order:n,subUnitId:e.getSheetId()}),this}moveActiveSheet(e){const t=this.getActiveSheet();return this.moveSheet(t,e)}getPermission(){return this._injector.createInstance(exports.FPermission)}getDefinedName(e){const t=this._definedNamesService.getValueByName(this.id,e);return t?this._injector.createInstance(v,{...t,unitId:this.id}):null}getDefinedNames(){const e=this._definedNamesService.getDefinedNameMap(this.id);return e?Object.values(e).map(t=>this._injector.createInstance(v,{...t,unitId:this.id})):[]}insertDefinedName(e,t){const s=this._injector.createInstance(R).setName(e).setRef(t).build();s.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this.insertDefinedNameBuilder(s)}deleteDefinedName(e){const t=this.getDefinedName(e);return t?(t.delete(),!0):!1}insertDefinedNameBuilder(e){e.unitId=this.getId(),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}updateDefinedNameBuilder(e){this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}getRegisteredRangeThemes(){return this._injector.get(a.SheetRangeThemeService).getRegisteredRangeThemes()}registerRangeTheme(e){this._commandService.syncExecuteCommand(a.RegisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),rangeThemeStyle:e})}unregisterRangeTheme(e){this._commandService.syncExecuteCommand(a.UnregisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),themeName:e})}};exports.FWorkbook=te([_(1,r.Inject(r.Injector)),_(2,r.Inject(r.IResourceLoaderService)),_(3,r.Inject(a.SheetsSelectionsService)),_(4,r.IUniverInstanceService),_(5,r.ICommandService),_(6,r.IPermissionService),_(7,r.ILogService),_(8,r.Inject(r.LocaleService)),_(9,S.IDefinedNamesService)],exports.FWorkbook);class ne extends r.FUniver{_initialize(o){const e=o.get(r.ICommandService);this.disposeWithMe(e.beforeCommandExecuted(t=>{var n;switch(t.id){case a.InsertSheetCommand.id:{const s=t.params,{unitId:i,index:c,sheet:d}=s||{},m=i?this.getUniverSheet(i):(n=this.getActiveWorkbook)==null?void 0:n.call(this);if(!m)return;const u={workbook:m,index:c,sheet:d};if(this.fireEvent(this.Event.BeforeSheetCreate,u),u.cancel)throw new Error("Sheet create canceled by facade api.");break}}})),this.disposeWithMe(e.onCommandExecuted(t=>{var n;switch(t.id){case a.InsertSheetCommand.id:{const s=t.params,{unitId:i}=s||{},c=i?this.getUniverSheet(i):(n=this.getActiveWorkbook)==null?void 0:n.call(this);if(!c)return;const d=c.getActiveSheet();if(!d)return;const m={workbook:c,worksheet:d};this.fireEvent(this.Event.SheetCreated,m);break}}}))}createUniverSheet(o){const t=this._injector.get(r.IUniverInstanceService).createUnit(r.UniverInstanceType.UNIVER_SHEET,o);return this._injector.createInstance(exports.FWorkbook,t)}getActiveUniverSheet(){const o=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);return o?this._injector.createInstance(exports.FWorkbook,o):null}getActiveWorkbook(){return this.getActiveUniverSheet()}getUniverSheet(o){const e=this._univerInstanceService.getUnit(o,r.UniverInstanceType.UNIVER_SHEET);return e?this._injector.createInstance(exports.FWorkbook,e):null}getPermission(){return this._injector.createInstance(exports.FPermission)}onUniverSheetCreated(o){const e=this._univerInstanceService.getTypeOfUnitAdded$(r.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{const n=this._injector.createInstance(exports.FWorkbook,t);o(n)});return r.toDisposable(e)}newDefinedName(){return this._injector.createInstance(R)}}r.FUniver.extend(ne);class U extends r.FEventName{get SheetCreated(){return"SheetCreated"}get BeforeSheetCreate(){return"BeforeSheetCreate"}}r.FEventName.extend(U);var oe=Object.defineProperty,se=Object.getOwnPropertyDescriptor,re=(h,o,e,t)=>{for(var n=t>1?void 0:t?se(o,e):o,s=h.length-1,i;s>=0;s--)(i=h[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&oe(o,e,n),n},ie=(h,o)=>(e,t)=>o(e,t,h);exports.FSheetHooks=class extends r.FBase{constructor(o){super(),this._injector=o}};exports.FSheetHooks=re([ie(0,r.Inject(r.Injector))],exports.FSheetHooks);exports.FSheetEventName=U;
|