@univerjs/sheets 0.4.2 → 0.5.0-alpha.0

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.
Files changed (53) hide show
  1. package/lib/cjs/facade.js +1 -0
  2. package/lib/cjs/index.js +3 -3
  3. package/lib/cjs/locale/en-US.js +1 -0
  4. package/lib/cjs/locale/fa-IR.js +1 -0
  5. package/lib/cjs/locale/ru-RU.js +1 -0
  6. package/lib/cjs/locale/vi-VN.js +1 -0
  7. package/lib/cjs/locale/zh-CN.js +1 -0
  8. package/lib/cjs/locale/zh-TW.js +1 -0
  9. package/lib/es/facade.js +1806 -0
  10. package/lib/es/index.js +7447 -7530
  11. package/lib/es/locale/en-US.js +17 -0
  12. package/lib/es/locale/fa-IR.js +17 -0
  13. package/lib/es/locale/ru-RU.js +17 -0
  14. package/lib/es/locale/vi-VN.js +17 -0
  15. package/lib/es/locale/zh-CN.js +17 -0
  16. package/lib/es/locale/zh-TW.js +17 -0
  17. package/lib/types/commands/commands/add-worksheet-protection.command.d.ts +7 -0
  18. package/lib/types/commands/commands/delete-worksheet-protection.command.d.ts +8 -0
  19. package/lib/types/commands/commands/set-frozen.command.d.ts +13 -0
  20. package/lib/types/commands/commands/set-protection.command.d.ts +13 -0
  21. package/lib/types/commands/commands/set-worksheet-protection.command.d.ts +8 -0
  22. package/lib/types/commands/mutations/reorder-range.mutation.d.ts +1 -1
  23. package/lib/types/facade/__tests__/utils.spec.d.ts +16 -0
  24. package/lib/types/facade/f-permission.d.ts +106 -0
  25. package/lib/types/facade/f-range.d.ts +193 -0
  26. package/lib/types/facade/f-selection.d.ts +11 -0
  27. package/lib/types/facade/f-univer.d.ts +36 -0
  28. package/lib/types/facade/f-workbook.d.ts +105 -0
  29. package/lib/types/facade/f-worksheet.d.ts +408 -0
  30. package/lib/types/facade/index.d.ts +22 -0
  31. package/lib/types/facade/utils.d.ts +24 -0
  32. package/lib/types/index.d.ts +8 -5
  33. package/lib/types/model/range-protection-rule.model.d.ts +10 -1
  34. package/lib/types/services/permission/type.d.ts +3 -1
  35. package/lib/types/services/permission/worksheet-permission/worksheet-permission.service.d.ts +3 -2
  36. package/lib/types/services/sheet-interceptor/sheet-interceptor.service.d.ts +38 -7
  37. package/lib/umd/facade.js +1 -0
  38. package/lib/umd/index.js +3 -3
  39. package/lib/umd/locale/en-US.js +1 -0
  40. package/lib/umd/locale/fa-IR.js +1 -0
  41. package/lib/umd/locale/ru-RU.js +1 -0
  42. package/lib/umd/locale/vi-VN.js +1 -0
  43. package/lib/umd/locale/zh-CN.js +1 -0
  44. package/lib/umd/locale/zh-TW.js +1 -0
  45. package/package.json +36 -17
  46. package/lib/locale/en-US.json +0 -14
  47. package/lib/locale/fa-IR.json +0 -14
  48. package/lib/locale/ru-RU.json +0 -14
  49. package/lib/locale/vi-VN.json +0 -14
  50. package/lib/locale/zh-CN.json +0 -14
  51. package/lib/locale/zh-TW.json +0 -14
  52. package/lib/types/commands/commands/set-frozen-cancel.command.d.ts +0 -2
  53. package/lib/types/commands/commands/set-range-protection.command.d.ts +0 -8
@@ -0,0 +1 @@
1
+ "use strict";var p=Object.defineProperty;var y=(c,o,e)=>o in c?p(c,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[o]=e;var S=(c,o,e)=>y(c,typeof o!="symbol"?o+"":o,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@univerjs/core"),a=require("@univerjs/sheets"),f=require("@univerjs/engine-formula");var P=Object.defineProperty,U=Object.getOwnPropertyDescriptor,E=(c,o,e,t)=>{for(var n=t>1?void 0:t?U(o,e):o,s=c.length-1,r;s>=0;s--)(r=c[s])&&(n=(t?r(o,e,n):r(n))||n);return t&&n&&P(o,e,n),n},g=(c,o)=>(e,t)=>o(e,t,c);exports.FPermission=class extends i.FBase{constructor(o,e,t,n,s,r,d){super(),this._injector=o,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=n,this._rangeProtectionRuleModel=s,this._worksheetProtectionPointRuleModel=r,this._authzIoService=d}setWorkbookPermissionPoint(o,e,t){const n=new e(o);this._permissionService.getPermissionPoint(n.id)||this._permissionService.addPermissionPoint(n),this._permissionService.updatePermissionPoint(n.id,t)}setWorkbookEditPermission(o,e){this.setWorkbookPermissionPoint(o,a.WorkbookEditablePermission,e)}async addWorksheetBasePermission(o,e){if(this._rangeProtectionRuleModel.getSubunitRuleList(o,e).length>0)throw new Error("sheet protection cannot intersect with range protection");const n=await this._authzIoService.create({objectType:a.UnitObject.Worksheet});if(this._commandService.syncExecuteCommand(a.AddWorksheetProtectionMutation.id,{unitId:o,subUnitId:e,rule:{permissionId:n,unitType:a.UnitObject.Worksheet,unitId:o,subUnitId:e}}))return n}removeWorksheetPermission(o,e){this._commandService.syncExecuteCommand(a.DeleteWorksheetProtectionMutation.id,{unitId:o,subUnitId:e}),[...a.getAllWorksheetPermissionPoint(),...a.getAllWorksheetPermissionPointByPointPanel()].forEach(t=>{const n=new t(o,e);this._permissionService.updatePermissionPoint(n.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(o,e)}async setWorksheetPermissionPoint(o,e,t,n){const s=this._worksheetProtectionRuleModel.getRule(o,e);let r;if(t===a.WorksheetEditPermission||t===a.WorksheetViewPermission)if(s)r=s.permissionId;else{if(this._rangeProtectionRuleModel.getSubunitRuleList(o,e).length>0)throw new Error("sheet protection cannot intersect with range protection");r=await this.addWorksheetBasePermission(o,e)}else{const u=this._worksheetProtectionPointRuleModel.getRule(o,e);u?r=u.permissionId:(r=await this._authzIoService.create({objectType:a.UnitObject.Worksheet}),this._commandService.executeCommand(a.SetWorksheetPermissionPointsMutation.id,{unitId:o,subUnitId:e,permissionId:r}))}const h=new t(o,e);return this._permissionService.getPermissionPoint(h.id)||this._permissionService.addPermissionPoint(h),this._permissionService.updatePermissionPoint(h.id,n),r}async addRangeBaseProtection(o,e,t){const n=await this._authzIoService.create({objectType:a.UnitObject.SelectRange}),s=`ruleId_${i.generateRandomId(6)}`;if(this._worksheetProtectionRuleModel.getRule(o,e))throw new Error("sheet protection cannot intersect with range protection");if(this._rangeProtectionRuleModel.getSubunitRuleList(o,e).some(u=>u.ranges.some(l=>t.some(w=>i.Rectangle.intersects(w,l)))))throw new Error("range protection cannot intersect");if(this._commandService.syncExecuteCommand(a.AddRangeProtectionMutation.id,{unitId:o,subUnitId:e,rules:[{permissionId:n,unitType:a.UnitObject.SelectRange,unitId:o,subUnitId:e,ranges:t,id:s}]}))return{permissionId:n,ruleId:s}}removeRangeProtection(o,e,t){this._commandService.syncExecuteCommand(a.DeleteRangeProtectionMutation.id,{unitId:o,subUnitId:e,ruleIds:t})&&this._rangeProtectionRuleModel.getSubunitRuleList(o,e).length===0&&(this._worksheetProtectionPointRuleModel.deleteRule(o,e),[...a.getAllWorksheetPermissionPointByPointPanel()].forEach(r=>{const d=new r(o,e);this._permissionService.updatePermissionPoint(d.id,d.value)}))}setRangeProtectionPermissionPoint(o,e,t,n,s){const r=new n(o,e,t);this._permissionService.getPermissionPoint(r.id)||this._permissionService.addPermissionPoint(r),this._permissionService.updatePermissionPoint(r.id,s)}setRangeProtectionRanges(o,e,t,n){const s=this._rangeProtectionRuleModel.getRule(o,e,t);if(s){if(this._rangeProtectionRuleModel.getSubunitRuleList(o,e).filter(h=>h.id!==t).some(h=>h.ranges.some(m=>n.some(u=>i.Rectangle.intersects(u,m)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(a.SetRangeProtectionMutation.id,{unitId:o,subUnitId:e,ruleId:t,rule:{...s,ranges:n}})}}};exports.FPermission=E([g(0,i.Inject(i.Injector)),g(1,i.ICommandService),g(2,i.IPermissionService),g(3,i.Inject(a.WorksheetProtectionRuleModel)),g(4,i.Inject(a.RangeProtectionRuleModel)),g(5,i.Inject(a.WorksheetProtectionPointModel)),g(6,i.Inject(i.IAuthzIoService))],exports.FPermission);function F(c){switch(c){case"left":return i.HorizontalAlign.LEFT;case"center":return i.HorizontalAlign.CENTER;case"normal":return i.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${c}`)}}function x(c){switch(c){case i.HorizontalAlign.LEFT:return"left";case i.HorizontalAlign.CENTER:return"center";case i.HorizontalAlign.RIGHT:return"normal";default:throw new Error(`Invalid horizontal alignment: ${c}`)}}function M(c){switch(c){case"top":return i.VerticalAlign.TOP;case"middle":return i.VerticalAlign.MIDDLE;case"bottom":return i.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${c}`)}}function A(c){switch(c){case i.VerticalAlign.TOP:return"top";case i.VerticalAlign.MIDDLE:return"middle";case i.VerticalAlign.BOTTOM:return"bottom";default:throw new Error(`Invalid vertical alignment: ${c}`)}}function v(c){return i.isFormulaString(c)?{f:c}:i.isCellV(c)?{v:c}:(i.isICellData(c),c)}function W(c,o){const e=new i.ObjectMatrix,{startRow:t,startColumn:n,endRow:s,endColumn:r}=o;if(i.Tools.isArray(c))for(let d=0;d<=s-t;d++)for(let h=0;h<=r-n;h++)e.setValue(d+t,h+n,v(c[d][h]));else new i.ObjectMatrix(c).forValue((h,m,u)=>{e.setValue(h,m,v(u))});return e.getMatrix()}function k(c,o){return{startRow:c.startRow,endRow:c.endRow,startColumn:0,endColumn:o.getColumnCount()-1,rangeType:i.RANGE_TYPE.ROW}}function C(c,o){return{startRow:0,endRow:o.getRowCount()-1,startColumn:c.startColumn,endColumn:c.endColumn,rangeType:i.RANGE_TYPE.COLUMN}}var j=Object.defineProperty,T=Object.getOwnPropertyDescriptor,D=(c,o,e,t)=>{for(var n=t>1?void 0:t?T(o,e):o,s=c.length-1,r;s>=0;s--)(r=c[s])&&(n=(t?r(o,e,n):r(n))||n);return t&&n&&j(o,e,n),n},I=(c,o)=>(e,t)=>o(e,t,c);exports.FRange=class extends i.FBase{constructor(o,e,t,n,s,r){super(),this._workbook=o,this._worksheet=e,this._range=t,this._injector=n,this._commandService=s,this._formulaDataModel=r}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(r=>i.Rectangle.equals(r,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 r,d;const{startRow:o,endRow:e,startColumn:t,endColumn:n}=this._range,s=[];for(let h=o;h<=e;h++){const m=[];for(let u=t;u<=n;u++)m.push((d=(r=this._worksheet.getCell(h,u))==null?void 0:r.v)!=null?d:null);s.push(m)}return s}getCellDataGrid(){const{startRow:o,endRow:e,startColumn:t,endColumn:n}=this._range,s=[];for(let r=o;r<=e;r++){const d=[];for(let h=t;h<=n;h++)d.push(this._worksheet.getCellRaw(r,h));s.push(d)}return s}getFormulas(){const o=[],{startRow:e,endRow:t,startColumn:n,endColumn:s}=this._range,r=this._worksheet.getSheetId(),d=this._workbook.getUnitId();for(let h=e;h<=t;h++){const m=[];for(let u=n;u<=s;u++){const l=this._formulaDataModel.getFormulaStringByCell(h,u,r,d);m.push(l||"")}o.push(m)}return o}getWrap(){return this._worksheet.getRange(this._range).getWrap()===i.BooleanNumber.TRUE}getWrapStrategy(){return this._worksheet.getRange(this._range).getWrapStrategy()}getHorizontalAlignment(){return x(this._worksheet.getRange(this._range).getHorizontalAlignment())}getVerticalAlignment(){return A(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}}})}setValue(o){const e=v(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?i.WrapStrategy.WRAP:i.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:M(o)})}setHorizontalAlignment(o){return this._commandService.executeCommand(a.SetHorizontalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:F(o)})}setValues(o){const e=W(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=i.BooleanNumber.TRUE;else if(o==="normal")e=i.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=i.BooleanNumber.TRUE;else if(o==="normal")e=i.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:i.BooleanNumber.TRUE});else if(o==="line-through")this._setFontStrikethrough({s:i.BooleanNumber.TRUE});else if(o==="none")this._setFontUnderline({s:i.BooleanNumber.FALSE}),this._setFontStrikethrough({s:i.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(){const o=this._workbook.getUnitId(),e=this._worksheet.getSheetId();return await a.addMergeCellsUtil(this._injector,o,e,[this._range]),this}async mergeAcross(){const o=a.getAddMergeMutationRangeByType([this._range],i.Dimension.ROWS),e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return await a.addMergeCellsUtil(this._injector,e,t,o),this}async mergeVertically(){const o=a.getAddMergeMutationRangeByType([this._range],i.Dimension.COLUMNS),e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return await a.addMergeCellsUtil(this._injector,e,t,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((r,d,h)=>{o(r,d,h)})}};exports.FRange=D([I(3,i.Inject(i.Injector)),I(4,i.ICommandService),I(5,i.Inject(f.FormulaDataModel))],exports.FRange);var O=Object.defineProperty,N=Object.getOwnPropertyDescriptor,B=(c,o,e,t)=>{for(var n=t>1?void 0:t?N(o,e):o,s=c.length-1,r;s>=0;s--)(r=c[s])&&(n=(t?r(o,e,n):r(n))||n);return t&&n&&O(o,e,n),n},V=(c,o)=>(e,t)=>o(e,t,c);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}};exports.FSelection=B([V(3,i.Inject(i.Injector))],exports.FSelection);var z=Object.defineProperty,H=Object.getOwnPropertyDescriptor,L=(c,o,e,t)=>{for(var n=t>1?void 0:t?H(o,e):o,s=c.length-1,r;s>=0;s--)(r=c[s])&&(n=(t?r(o,e,n):r(n))||n);return t&&n&&z(o,e,n),n},R=(c,o)=>(e,t)=>o(e,t,c);exports.FWorksheet=class extends i.FBase{constructor(e,t,n,s,r,d){super();S(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=n,this._injector=s,this._selectionManagerService=r,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(),r={unitId:n,subUnitId:s,columnData:{[e]:{s:t}}};return await this._commandService.executeCommand(a.SetColDataCommand.id,r),this}async setRowDefaultStyle(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),r={unitId:n,subUnitId:s,rowData:{[e]:{s:t}}};return await this._commandService.executeCommand(a.SetRowDataCommand.id,r),this}getRange(e,t,n,s){let r,d;if(typeof e=="string"){const{range:h,sheetName:m}=f.deserializeRangeWithSheet(e),u=m?this._workbook.getSheetBySheetName(m):this._worksheet;if(!u)throw new Error("Range not found");d=u,r={...h,unitId:this._workbook.getUnitId(),sheetId:d.getSheetId(),rangeType:i.RANGE_TYPE.NORMAL,startRow:h.rangeType===i.RANGE_TYPE.COLUMN?0:h.startRow,endRow:h.rangeType===i.RANGE_TYPE.COLUMN?d.getMaxRows()-1:h.endRow,startColumn:h.rangeType===i.RANGE_TYPE.ROW?0:h.startColumn,endColumn:h.rangeType===i.RANGE_TYPE.ROW?d.getMaxColumns()-1:h.endColumn}}else if(typeof e=="number"&&t!==void 0)d=this._worksheet,r={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,d,r)}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(),r=i.Direction.DOWN,d=e+1,h=e+t,m=0,u=this._worksheet.getColumnCount()-1,l=a.copyRangeStyles(this._worksheet,d,h,m,u,!0,e);return await this._commandService.executeCommand(a.InsertRowCommand.id,{unitId:n,subUnitId:s,direction:r,range:{startRow:d,endRow:h,startColumn:m,endColumn:u},cellValue:l}),this}async insertRowsBefore(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),r=i.Direction.UP,d=e,h=e+t-1,m=0,u=this._worksheet.getColumnCount()-1,l=a.copyRangeStyles(this._worksheet,d,h,m,u,!0,e-1);return await this._commandService.executeCommand(a.InsertRowCommand.id,{unitId:n,subUnitId:s,direction:r,range:{startRow:d,endRow:h,startColumn:m,endColumn:u},cellValue:l}),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(),r=k(e.getRange(),this._worksheet),d=r,h={startRow:t,endRow:t,startColumn:r.startColumn,endColumn:r.endColumn};return await this._commandService.executeCommand(a.MoveRowsCommand.id,{unitId:n,subUnitId:s,range:r,fromRange:d,toRange:h}),this}async hideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=k(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(),r={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:i.RANGE_TYPE.ROW};return await this._commandService.executeCommand(a.SetRowHiddenCommand.id,{unitId:n,subUnitId:s,ranges:[r]}),this}async unhideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=k(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(),r={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:i.RANGE_TYPE.ROW};return await this._commandService.executeCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:n,subUnitId:s,ranges:[r]}),this}async setRowHeight(e,t){return this.setRowHeights(e,1,t)}async setRowHeights(e,t,n){var u;const s=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),d=this._worksheet.getRowManager(),h=[],m=[];for(let l=e;l<e+t;l++){const w=((u=d.getRow(l))==null?void 0:u.ah)||this._worksheet.getConfig().defaultRowHeight,b={startRow:l,endRow:l,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};n<=w?h.push(b):m.push(b)}return m.length>0&&await this._commandService.executeCommand(a.SetRowHeightCommand.id,{unitId:s,subUnitId:r,ranges:m,value:n}),h.length>0&&await this._commandService.executeCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:s,subUnitId:r,ranges:h}),this}async setRowHeightsForced(e,t,n){const s=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),d=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return await this._commandService.executeCommand(a.SetRowHeightCommand.id,{unitId:s,subUnitId:r,ranges:d,value:n}),this}async setRowCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s={};for(const[d,h]of Object.entries(e))s[Number(d)]={custom:h};const r={unitId:t,subUnitId:n,rowData:s};return await this._commandService.executeCommand(a.SetRowDataCommand.id,r),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(),r=i.Direction.RIGHT,d=0,h=this._worksheet.getRowCount()-1,m=e+1,u=e+t,l=a.copyRangeStyles(this._worksheet,d,h,m,u,!1,e);return await this._commandService.executeCommand(a.InsertColCommand.id,{unitId:n,subUnitId:s,direction:r,range:{startRow:d,endRow:h,startColumn:m,endColumn:u},cellValue:l}),this}async insertColumnsBefore(e,t){const n=this._workbook.getUnitId(),s=this._worksheet.getSheetId(),r=i.Direction.LEFT,d=0,h=this._worksheet.getRowCount()-1,m=e,u=e+t-1,l=a.copyRangeStyles(this._worksheet,d,h,m,u,!1,e-1);return await this._commandService.executeCommand(a.InsertColCommand.id,{unitId:n,subUnitId:s,direction:r,range:{startRow:d,endRow:h,startColumn:m,endColumn:u},cellValue:l}),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(),r=C(e.getRange(),this._worksheet),d=r,h={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return await this._commandService.executeCommand(a.MoveColsCommand.id,{unitId:n,subUnitId:s,range:r,fromRange:d,toRange:h}),this}async hideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=C(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(),r={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:i.RANGE_TYPE.COLUMN};return await this._commandService.executeCommand(a.SetColHiddenCommand.id,{unitId:n,subUnitId:s,ranges:[r]}),this}async unhideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s=C(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(),r={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:i.RANGE_TYPE.COLUMN};return await this._commandService.executeCommand(a.SetSpecificColsVisibleCommand.id,{unitId:n,subUnitId:s,ranges:[r]}),this}async setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}async setColumnWidths(e,t,n){const s=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),d=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return await this._commandService.executeCommand(a.SetColWidthCommand.id,{unitId:s,subUnitId:r,ranges:d,value:n}),this}async setColumnCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),s={};for(const[d,h]of Object.entries(e))s[Number(d)]={custom:h};const r={unitId:t,subUnitId:n,columnData:s};return await this._commandService.executeCommand(a.SetColDataCommand.id,r),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._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();this.setFreeze({...t,startColumn:e>0?e:-1,xSplit:e})}setFrozenRows(e){const t=this.getFreeze();this.setFreeze({...t,startRow:e>0?e:-1,ySplit:e})}getFrozenColumns(){const e=this.getFreeze();return e.startColumn===-1?0:e.startColumn}getFrozenRows(){const e=this.getFreeze();return e.startRow===-1?0:e.startRow}hasHiddenGridLines(){return this._worksheet.getConfig().showGridlines===i.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.executeCommand(a.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE})}onCellDataChange(e){return this._injector.get(i.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 i.ObjectMatrix(s.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(i.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 i.ObjectMatrix(s.cellValue))}})}};exports.FWorksheet=L([R(3,i.Inject(i.Injector)),R(4,i.Inject(a.SheetsSelectionsService)),R(5,i.ICommandService)],exports.FWorksheet);var $=Object.defineProperty,G=Object.getOwnPropertyDescriptor,Y=(c,o,e,t)=>{for(var n=t>1?void 0:t?G(o,e):o,s=c.length-1,r;s>=0;s--)(r=c[s])&&(n=(t?r(o,e,n):r(n))||n);return t&&n&&$(o,e,n),n},_=(c,o)=>(e,t)=>o(e,t,c);exports.FWorkbook=class extends i.FBase{constructor(e,t,n,s,r,d,h,m){super();S(this,"id");this._workbook=e,this._injector=t,this._resourceLoaderService=n,this._selectionManagerService=s,this._univerInstanceService=r,this._commandService=d,this._permissionService=h,this._logService=m,this.id=this._workbook.getUnitId()}getId(){return this.id}getName(){return this._workbook.getName()}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=i.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 r=this._workbook.getActiveSheet();if(!r)throw new Error("No active sheet found");return this._injector.createInstance(exports.FWorksheet,this,this._workbook,r)}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(){this._commandService.syncExecuteCommand(a.InsertSheetCommand.id);const e=this.id,t=this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId();this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:t});const n=this._workbook.getActiveSheet();if(!n)throw new Error("No active sheet found");return this._injector.createInstance(exports.FWorksheet,this,this._workbook,n)}deleteSheet(e){const t=this.id,n=e.getSheetId();this._commandService.executeCommand(a.RemoveSheetCommand.id,{unitId:t,subUnitId:n})}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(i.UndoCommand.id)}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(i.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 i.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(t=>{this._univerInstanceService.getCurrentUnitForType(i.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 r={unitId:this.getId(),subUnitId:n,selections:[e].map(d=>({range:d.getRange(),primary:a.getPrimaryForRange(d.getRange(),s),style:null}))};this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,r)}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}};exports.FWorkbook=Y([_(1,i.Inject(i.Injector)),_(2,i.Inject(i.IResourceLoaderService)),_(3,i.Inject(a.SheetsSelectionsService)),_(4,i.IUniverInstanceService),_(5,i.ICommandService),_(6,i.IPermissionService),_(7,i.ILogService)],exports.FWorkbook);class q extends i.FUniver{createUniverSheet(o){const t=this._injector.get(i.IUniverInstanceService).createUnit(i.UniverInstanceType.UNIVER_SHEET,o);return this._injector.createInstance(exports.FWorkbook,t)}getActiveWorkbook(){const o=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET);return o?this._injector.createInstance(exports.FWorkbook,o):null}getPermission(){return this._injector.createInstance(exports.FPermission)}}i.FUniver.extend(q);