@univerjs/preset-sheets-node-core 0.10.12 → 0.10.13
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/umd/index.js +7 -7
- package/package.json +17 -17
package/lib/umd/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
// @univerjs/sheets/facade
|
|
16
|
-
(function(u,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/sheets"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/core/facade","@univerjs/sheets","@univerjs/engine-formula"],s):(u=typeof globalThis<"u"?globalThis:u||self,s(u.UniverSheetsFacade={},u.UniverCore,u.UniverCoreFacade,u.UniverSheets,u.UniverEngineFormula))})(this,(function(u,s,S,a,I){"use strict";var te=Object.defineProperty;var ne=(u,s,S)=>s in u?te(u,s,{enumerable:!0,configurable:!0,writable:!0,value:S}):u[s]=S;var b=(u,s,S)=>ne(u,typeof s!="symbol"?s+"":s,S);var F=Object.getOwnPropertyDescriptor,D=(c,r,e,t)=>{for(var n=t>1?void 0:t?F(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},w=(c,r)=>(e,t)=>r(e,t,c);function x(c,r,e){const t=e.getDefinedNameMap(c);if(t==null)return r.t("definedName.defaultName")+1;const i=Array.from(Object.values(t)).length+1,o=r.t("definedName.defaultName")+i;if(e.getValueByName(c,o)==null)return o;let h=i+1;for(;;){const d=r.t("definedName.defaultName")+h;if(e.getValueByName(c,d)==null)return d;h++}}class E{constructor(){b(this,"_definedNameParam");this._definedNameParam={id:s.generateRandomId(10),unitId:"",name:"",formulaOrRefString:"",localSheetId:a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}}setName(r){return this._definedNameParam.name=r,this}setFormula(r){return this._definedNameParam.formulaOrRefString=`=${r}`,this}setRef(r){return this._definedNameParam.formulaOrRefString=r,this}setRefByRange(r,e,t,n){return this._definedNameParam.formulaOrRefString=I.serializeRange({startRow:r,endRow:r+(t!=null?t:1)-1,startColumn:e,endColumn:e+(n!=null?n:1)-1}),this}setComment(r){return this._definedNameParam.comment=r,this}setScopeToWorksheet(r){return this._definedNameParam.localSheetId=r.getSheetId(),this}setScopeToWorkbook(){return this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this}setHidden(r){return this._definedNameParam.hidden=r,this}build(){return this._definedNameParam}load(r){return this._definedNameParam=r,this}}let y=class extends S.FBase{constructor(c,r,e,t,n,i,o,h,d,l){super(),this._definedNameParam=c,this._injector=r,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=n,this._rangeProtectionRuleModel=i,this._worksheetProtectionPointRuleModel=o,this._authzIoService=h,this._localeService=d,this._definedNamesService=l}_apply(){this._definedNameParam.name===""&&(this._definedNameParam.name=x(this._definedNameParam.unitId,this._localeService,this._definedNamesService)),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,this._definedNameParam)}getName(){return this._definedNameParam.name}setName(c){this._definedNameParam.name=c,this._apply()}setFormula(c){this._definedNameParam.formulaOrRefString=`=${c}`,this._apply()}setRef(c){this._definedNameParam.formulaOrRefString=c,this._apply()}getFormulaOrRefString(){return this._definedNameParam.formulaOrRefString}setRefByRange(c,r,e,t){this._definedNameParam.formulaOrRefString=I.serializeRange({startRow:c,endRow:c+(e!=null?e:1)-1,startColumn:r,endColumn:r+(t!=null?t:1)-1}),this._apply()}getComment(){return this._definedNameParam.comment}setComment(c){this._definedNameParam.comment=c,this._apply()}setScopeToWorksheet(c){this._definedNameParam.localSheetId=c.getSheetId(),this._apply()}setScopeToWorkbook(){this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this._apply()}setHidden(c){this._definedNameParam.hidden=c,this._apply()}delete(){this._commandService.syncExecuteCommand(a.RemoveDefinedNameCommand.id,this._definedNameParam)}getLocalSheetId(){return this._definedNameParam.localSheetId}isWorkbookScope(){return this._definedNameParam.localSheetId===a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}toBuilder(){const c=this._injector.createInstance(E);return c.load(this._definedNameParam),c}};y=D([w(1,s.Inject(s.Injector)),w(2,s.ICommandService),w(3,s.IPermissionService),w(4,s.Inject(a.WorksheetProtectionRuleModel)),w(5,s.Inject(a.RangeProtectionRuleModel)),w(6,s.Inject(a.WorksheetProtectionPointModel)),w(7,s.Inject(s.IAuthzIoService)),w(8,s.Inject(s.LocaleService)),w(9,I.IDefinedNamesService)],y);var B=Object.getOwnPropertyDescriptor,j=(c,r,e,t)=>{for(var n=t>1?void 0:t?B(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},f=(c,r)=>(e,t)=>r(e,t,c);u.FPermission=class extends S.FBase{constructor(e,t,n,i,o,h,d){super();b(this,"permissionPointsDefinition",a.PermissionPointsDefinitions);b(this,"rangeRuleChangedAfterAuth$");b(this,"sheetRuleChangedAfterAuth$");this._injector=e,this._commandService=t,this._permissionService=n,this._worksheetProtectionRuleModel=i,this._rangeProtectionRuleModel=o,this._worksheetProtectionPointRuleModel=h,this._authzIoService=d,this.rangeRuleChangedAfterAuth$=this._rangeProtectionRuleModel.ruleRefresh$,this.sheetRuleChangedAfterAuth$=this._worksheetProtectionRuleModel.ruleRefresh$}setWorkbookPermissionPoint(e,t,n){const i=new t(e);this._permissionService.getPermissionPoint(i.id)||this._permissionService.addPermissionPoint(i),this._permissionService.updatePermissionPoint(i.id,n)}checkWorkbookPermissionPoint(e,t){const n=new t(e),i=this._permissionService.getPermissionPoint(n.id);if(i)return i.value}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 i=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:i,unitType:a.UnitObject.Worksheet,unitId:e,subUnitId:t}}))return i}removeWorksheetPermission(e,t){this._commandService.syncExecuteCommand(a.DeleteWorksheetProtectionMutation.id,{unitId:e,subUnitId:t}),[...a.getAllWorksheetPermissionPoint(),...a.getAllWorksheetPermissionPointByPointPanel()].forEach(n=>{const i=new n(e,t);this._permissionService.updatePermissionPoint(i.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e,t)}async setWorksheetPermissionPoint(e,t,n,i){const o=this._worksheetProtectionRuleModel.getRule(e,t);let h;if(n===a.WorksheetEditPermission||n===a.WorksheetViewPermission)if(o)h=o.permissionId;else{if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");h=await this.addWorksheetBasePermission(e,t)}else{const g=this._worksheetProtectionPointRuleModel.getRule(e,t);g?h=g.permissionId:(h=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}}),this._commandService.syncExecuteCommand(a.SetWorksheetPermissionPointsMutation.id,{unitId:e,subUnitId:t,rule:{unitId:e,subUnitId:t,permissionId:h}}))}const l=new n(e,t);return this._permissionService.getPermissionPoint(l.id)||this._permissionService.addPermissionPoint(l),this._permissionService.updatePermissionPoint(l.id,i),h}checkWorksheetPermissionPoint(e,t,n){const i=new n(e,t),o=this._permissionService.getPermissionPoint(i.id);if(o)return o.value}async addRangeBaseProtection(e,t,n){const i=await this._authzIoService.create({objectType:a.UnitObject.SelectRange,selectRangeObject:{collaborators:[],unitID:e,name:"",scope:void 0}}),o=`ruleId_${s.generateRandomId(6)}`;if(this._worksheetProtectionRuleModel.getRule(e,t))throw new Error("sheet protection cannot intersect with range protection");if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).some(g=>g.ranges.some(_=>n.some(k=>s.Rectangle.intersects(k.getRange(),_)))))throw new Error("range protection cannot intersect");if(this._commandService.syncExecuteCommand(a.AddRangeProtectionMutation.id,{unitId:e,subUnitId:t,rules:[{permissionId:i,unitType:a.UnitObject.SelectRange,unitId:e,subUnitId:t,ranges:n.map(g=>g.getRange()),id:o}]}))return{permissionId:i,ruleId:o}}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(h=>{const d=new h(e,t);this._permissionService.updatePermissionPoint(d.id,d.value)}))}setRangeProtectionPermissionPoint(e,t,n,i,o){const h=new i(e,t,n);this._permissionService.getPermissionPoint(h.id)||this._permissionService.addPermissionPoint(h),this._permissionService.updatePermissionPoint(h.id,o)}setRangeProtectionRanges(e,t,n,i){const o=this._rangeProtectionRuleModel.getRule(e,t,n);if(o){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).filter(l=>l.id!==n).some(l=>l.ranges.some(m=>i.some(g=>s.Rectangle.intersects(g.getRange(),m)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(a.SetRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleId:n,rule:{...o,ranges:i.map(l=>l.getRange())}})}}getPermissionInfoWithCell(e,t,n,i){const o=s.cellToRange(n,i),h=this._rangeProtectionRuleModel.getSubunitRuleList(e,t).find(d=>d.ranges.some(m=>s.Rectangle.intersects(o,m)));if(h)return{permissionId:h.permissionId,ruleId:h.id}}},u.FPermission=j([f(0,s.Inject(s.Injector)),f(1,s.ICommandService),f(2,s.IPermissionService),f(3,s.Inject(a.WorksheetProtectionRuleModel)),f(4,s.Inject(a.RangeProtectionRuleModel)),f(5,s.Inject(a.WorksheetProtectionPointModel)),f(6,s.Inject(s.IAuthzIoService))],u.FPermission);function V(c){switch(c){case"left":return s.HorizontalAlign.LEFT;case"center":return s.HorizontalAlign.CENTER;case"normal":return s.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${c}`)}}function T(c){switch(c){case s.HorizontalAlign.LEFT:return"left";case s.HorizontalAlign.CENTER:return"center";case s.HorizontalAlign.RIGHT:return"normal";default:return"general"}}function O(c){switch(c){case"top":return s.VerticalAlign.TOP;case"middle":return s.VerticalAlign.MIDDLE;case"bottom":return s.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${c}`)}}function A(c){switch(c){case s.VerticalAlign.TOP:return"top";case s.VerticalAlign.MIDDLE:return"middle";case s.VerticalAlign.BOTTOM:return"bottom";default:return"general"}}function U(c,r){return{startRow:c.startRow,endRow:c.endRow,startColumn:0,endColumn:r.getColumnCount()-1,rangeType:s.RANGE_TYPE.ROW}}function P(c,r){return{startRow:0,endRow:r.getRowCount()-1,startColumn:c.startColumn,endColumn:c.endColumn,rangeType:s.RANGE_TYPE.COLUMN}}var H=Object.getOwnPropertyDescriptor,L=(c,r,e,t)=>{for(var n=t>1?void 0:t?H(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},N=(c,r)=>(e,t)=>r(e,t,c);u.FRange=class extends S.FBaseInitialable{constructor(r,e,t,n,i,o){super(n),this._workbook=r,this._worksheet=e,this._range=t,this._injector=n,this._commandService=i,this._formulaDataModel=o}getUnitId(){return this._workbook.getUnitId()}getSheetName(){return this._worksheet.getName()}getSheetId(){return this._worksheet.getSheetId()}getRange(){return this._range}getRow(){return this._range.startRow}getLastRow(){return this._range.endRow}getColumn(){return this._range.startColumn}getLastColumn(){return this._range.endColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}isMerged(){const{startColumn:r,startRow:e,endColumn:t,endRow:n}=this._range;return this._worksheet.getMergedCellRange(e,r,n,t).some(o=>s.Rectangle.equals(o,this._range))}getCellStyleData(r="row"){return r!=="cell"?this._worksheet.getComposedCellStyle(this._range.startRow,this._range.startColumn,r==="row"):this._worksheet.getCellStyle(this._range.startRow,this._range.startColumn)}getFontFamily(r="row"){var e,t;return(t=(e=this.getCellStyleData(r))==null?void 0:e.ff)!=null?t:null}getFontSize(r="row"){var e,t;return(t=(e=this.getCellStyleData(r))==null?void 0:e.fs)!=null?t:null}getCellStyle(r="row"){const e=this.getCellStyleData(r);return e?s.TextStyleValue.create(e):null}getCellStyles(r="row"){return this.getCellDatas().map((t,n)=>t.map((i,o)=>{if(!i)return null;const h=r!=="cell"?this._worksheet.getComposedCellStyle(n+this._range.startRow,o+this._range.startColumn,r==="row"):this._worksheet.getCellStyle(n+this._range.startRow,o+this._range.startColumn);return h?s.TextStyleValue.create(h):null}))}getValue(r){var e,t;return r?this.getValueAndRichTextValue():(t=(e=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:e.v)!=null?t:null}getRawValue(){var e,t;const r=this._worksheet.getCellMatrix().getValue(this._range.startRow,this._range.startColumn);return r!=null&&r.p&&((e=r.p.body)!=null&&e.dataStream)?r.p.body.dataStream:(t=r==null?void 0:r.v)!=null?t:null}getDisplayValue(){var e,t,n;const r=this._worksheet.getCell(this._range.startRow,this._range.startColumn);return r!=null&&r.p&&((e=r.p.body)!=null&&e.dataStream)?r.p.body.dataStream:(n=(t=r==null?void 0:r.v)==null?void 0:t.toString())!=null?n:""}getValues(r){var h,d;if(r)return this.getValueAndRichTextValues();const{startRow:e,endRow:t,startColumn:n,endColumn:i}=this._range,o=[];for(let l=e;l<=t;l++){const m=[];for(let g=n;g<=i;g++)m.push((d=(h=this._worksheet.getCell(l,g))==null?void 0:h.v)!=null?d:null);o.push(m)}return o}getRawValues(){var h,d;const r=this._worksheet.getCellMatrix(),{startRow:e,endRow:t,startColumn:n,endColumn:i}=this._range,o=[];for(let l=e;l<=t;l++){const m=[];for(let g=n;g<=i;g++){const _=r.getValue(l,g);_!=null&&_.p&&((h=_.p.body)!=null&&h.dataStream)?m.push(_.p.body.dataStream):m.push((d=_==null?void 0:_.v)!=null?d:null)}o.push(m)}return o}getDisplayValues(){var o,h,d;const{startRow:r,endRow:e,startColumn:t,endColumn:n}=this._range,i=[];for(let l=r;l<=e;l++){const m=[];for(let g=t;g<=n;g++){const _=this._worksheet.getCell(l,g);_!=null&&_.p&&((o=_.p.body)!=null&&o.dataStream)?m.push(_.p.body.dataStream):m.push((d=(h=_==null?void 0:_.v)==null?void 0:h.toString())!=null?d:"")}i.push(m)}return i}getCellData(){var r;return(r=this._worksheet.getCell(this._range.startRow,this._range.startColumn))!=null?r:null}getCellDatas(){return this.getCellDataGrid()}getCellDataGrid(){const{startRow:r,endRow:e,startColumn:t,endColumn:n}=this._range,i=[];for(let o=r;o<=e;o++){const h=[];for(let d=t;d<=n;d++)h.push(this._worksheet.getCellRaw(o,d));i.push(h)}return i}getRichTextValue(){const r=this.getCellData();return r!=null&&r.p?new s.RichTextValue(r.p):null}getRichTextValues(){return this.getCellDataGrid().map(e=>e.map(t=>t!=null&&t.p?new s.RichTextValue(t.p):null))}getValueAndRichTextValue(){const r=this.getCellData();return r!=null&&r.p?new s.RichTextValue(r.p):r==null?void 0:r.v}getValueAndRichTextValues(){return this.getCellDatas().map(e=>e.map(t=>t!=null&&t.p?new s.RichTextValue(t.p):t==null?void 0:t.v))}getFormula(){var r;return(r=this._formulaDataModel.getFormulaStringByCell(this._range.startRow,this._range.startColumn,this._worksheet.getSheetId(),this._workbook.getUnitId()))!=null?r:""}getFormulas(){const r=[],{startRow:e,endRow:t,startColumn:n,endColumn:i}=this._range,o=this._worksheet.getSheetId(),h=this._workbook.getUnitId();for(let d=e;d<=t;d++){const l=[];for(let m=n;m<=i;m++){const g=this._formulaDataModel.getFormulaStringByCell(d,m,o,h);l.push(g||"")}r.push(l)}return r}getWrap(){return this._worksheet.getRange(this._range).getWrap()===s.BooleanNumber.TRUE}getWraps(){const r=this.getCellDatas(),e=this._workbook.getStyles();return r.map(t=>t.map(n=>{var i;return((i=e.getStyleByCell(n))==null?void 0:i.tb)===s.WrapStrategy.WRAP}))}getWrapStrategy(){return this._worksheet.getRange(this._range).getWrapStrategy()}getHorizontalAlignment(){const r=this._worksheet.getRange(this._range).getHorizontalAlignment();return T(r)}getHorizontalAlignments(){return this._worksheet.getRange(this._range).getHorizontalAlignments().map(e=>e.map(t=>T(t)))}getVerticalAlignment(){return A(this._worksheet.getRange(this._range).getVerticalAlignment())}getVerticalAlignments(){return this._worksheet.getRange(this._range).getVerticalAlignments().map(e=>e.map(t=>A(t)))}setCustomMetaData(r){return this.setValue({custom:r})}setCustomMetaDatas(r){return this.setValues(r.map(e=>e.map(t=>({custom:t}))))}getCustomMetaData(){var e;const r=this.getCellData();return(e=r==null?void 0:r.custom)!=null?e:null}getCustomMetaDatas(){return this.getCellDataGrid().map(e=>e.map(t=>{var n;return(n=t==null?void 0:t.custom)!=null?n:null}))}setBorder(r,e,t){return this._commandService.syncExecuteCommand(a.SetBorderBasicCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range],value:{type:r,style:e,color:t}}),this}getBackground(){var e,t;const r=this.getCellStyle();return(t=(e=r==null?void 0:r.background)==null?void 0:e.rgb)!=null?t:s.DEFAULT_STYLES.bg.rgb}getBackgrounds(){return this.getCellStyles().map(e=>e.map(t=>{var n,i;return(i=(n=t==null?void 0:t.background)==null?void 0:n.rgb)!=null?i:s.DEFAULT_STYLES.bg.rgb}))}setBackgroundColor(r){return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:r}}}),this}setBackground(r){return this.setBackgroundColor(r),this}setTextRotation(r){return this._commandService.syncExecuteCommand(a.SetTextRotationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:r}),this}setValue(r){const e=s.covertCellValue(r);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setValueForCell(r){const e=s.covertCellValue(r);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.startColumn,endRow:this._range.startRow},value:e}),this}setRichTextValueForCell(r){const e=r instanceof s.RichTextValue?r.getData():r,t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.startColumn,endRow:this._range.startRow},value:{p:e}};return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,t),this}setRichTextValues(r){const e=r.map(i=>i.map(o=>o&&{p:o instanceof s.RichTextValue?o.getData():o})),t=s.covertCellValues(e,this._range),n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:t};return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,n),this}setWrap(r){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:r?s.WrapStrategy.WRAP:s.WrapStrategy.UNSPECIFIED}),this}setWrapStrategy(r){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:r}),this}setVerticalAlignment(r){return this._commandService.syncExecuteCommand(a.SetVerticalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:O(r)}),this}setHorizontalAlignment(r){return this._commandService.syncExecuteCommand(a.SetHorizontalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:V(r)}),this}setValues(r){const e=s.covertCellValues(r,this._range);return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setFontWeight(r){let e;if(r==="bold")e=s.BooleanNumber.TRUE;else if(r==="normal")e=s.BooleanNumber.FALSE;else if(r===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.syncExecuteCommand(a.SetStyleCommand.id,n),this}setFontStyle(r){let e;if(r==="italic")e=s.BooleanNumber.TRUE;else if(r==="normal")e=s.BooleanNumber.FALSE;else if(r===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.syncExecuteCommand(a.SetStyleCommand.id,n),this}setFontLine(r){if(r==="underline")this._setFontUnderline({s:s.BooleanNumber.TRUE});else if(r==="line-through")this._setFontStrikethrough({s:s.BooleanNumber.TRUE});else if(r==="none")this._setFontUnderline({s:s.BooleanNumber.FALSE}),this._setFontStrikethrough({s:s.BooleanNumber.FALSE});else if(r===null)this._setFontUnderline(null),this._setFontStrikethrough(null);else throw new Error("Invalid fontLine");return this}_setFontUnderline(r){const e={type:"ul",value:r},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t)}_setFontStrikethrough(r){const e={type:"st",value:r},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t)}setFontFamily(r){const e={type:"ff",value:r},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t),this}setFontSize(r){const e={type:"fs",value:r},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t),this}setFontColor(r){const t={type:"cl",value:r===null?null:{rgb:r}},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,n),this}merge(r=!0){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,e,t,[this._range],r),this}mergeAcross(r=!0){const e=a.getAddMergeMutationRangeByType([this._range],s.Dimension.ROWS),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,n,e,r),this}mergeVertically(r=!0){const e=a.getAddMergeMutationRangeByType([this._range],s.Dimension.COLUMNS),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,n,e,r),this}isPartOfMerge(){const{startRow:r,startColumn:e,endRow:t,endColumn:n}=this._range;return this._worksheet.getMergedCellRange(r,e,t,n).length>0}breakApart(){return this._commandService.syncExecuteCommand(a.RemoveWorksheetMergeCommand.id,{ranges:[this._range]}),this}forEach(r){const{startColumn:e,startRow:t,endColumn:n,endRow:i}=this._range;this._worksheet.getMatrixWithMergedCells(t,e,i,n).forValue((o,h,d)=>{r(o,h,d)})}getA1Notation(r,e,t){const n={...this._range,startAbsoluteRefType:e,endAbsoluteRefType:t};return r?I.serializeRangeWithSheet(this._worksheet.getName(),n):I.serializeRange(n)}activate(){return this._injector.createInstance(u.FWorkbook,this._workbook).setActiveRange(this),this}activateAsCurrentCell(){const r=this._worksheet.getMergedCell(this._range.startRow,this._range.startColumn);if(r&&s.Rectangle.equals(r,this._range)||!r&&this._range.startRow===this._range.endRow&&this._range.startColumn===this._range.endColumn){const n=this._injector.createInstance(u.FWorkbook,this._workbook).getActiveRange();if(!n||n.getUnitId()!==this.getUnitId()||n.getSheetId()!==this.getSheetId())return this.activate();if(s.Rectangle.contains(n.getRange(),this._range)){const i={unitId:this.getUnitId(),subUnitId:this.getSheetId(),selections:[{range:n.getRange(),primary:a.getPrimaryForRange(this.getRange(),this._worksheet),style:null}]};return this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,i),this}return this.activate()}else throw new Error("The range is not a single cell")}splitTextToColumns(r,e,t){this._commandService.syncExecuteCommand(a.SplitTextToColumnsCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,delimiter:e,customDelimiter:t,treatMultipleDelimitersAsOne:r})}useThemeStyle(r){if(r==null){const e=this.getUsedThemeStyle();e&&this.removeThemeStyle(e)}else this._commandService.syncExecuteCommand(a.SetWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:r})}removeThemeStyle(r){this._commandService.syncExecuteCommand(a.DeleteWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:r})}getUsedThemeStyle(){return this._injector.get(a.SheetRangeThemeService).getAppliedRangeThemeStyle({unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})}clear(r){return r&&r.contentsOnly&&!r.formatOnly?this.clearContent():r&&r.formatOnly&&!r.contentsOnly?this.clearFormat():(this._commandService.syncExecuteCommand(a.ClearSelectionAllCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range],options:r}),this)}clearContent(){return this._commandService.syncExecuteCommand(a.ClearSelectionContentCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this}clearFormat(){return this._commandService.syncExecuteCommand(a.ClearSelectionFormatCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this}insertCells(r){r===s.Dimension.ROWS?this._commandService.executeCommand(a.InsertRangeMoveDownCommand.id,{range:this._range}):this._commandService.executeCommand(a.InsertRangeMoveRightCommand.id,{range:this._range})}deleteCells(r){r===s.Dimension.ROWS?this._commandService.executeCommand(a.DeleteRangeMoveUpCommand.id,{range:this._range}):this._commandService.executeCommand(a.DeleteRangeMoveLeftCommand.id,{range:this._range})}getDataRegion(r){const{startRow:e,startColumn:t,endRow:n,endColumn:i}=this._range,o=this._worksheet.getMaxRows(),h=this._worksheet.getMaxColumns(),d=this._worksheet.getCellMatrix();let l=e,m=t,g=n,_=i;if(r!==s.Dimension.COLUMNS){let k=!1,R=!1;for(let v=t;v<=i&&(e>0&&!s.isNullCell(d.getValue(e-1,v))&&(k=!0),n<o-1&&!s.isNullCell(d.getValue(n+1,v))&&(R=!0),!(k&&R));v++);k&&(l=e-1),R&&(g=n+1)}if(r!==s.Dimension.ROWS){let k=!1,R=!1;for(let v=e;v<=n&&(t>0&&!s.isNullCell(d.getValue(v,t-1))&&(k=!0),i<h-1&&!s.isNullCell(d.getValue(v,i+1))&&(R=!0),!(k&&R));v++);k&&(m=t-1),R&&(_=i+1)}return this._injector.createInstance(u.FRange,this._workbook,this._worksheet,{startRow:l,startColumn:m,endRow:g,endColumn:_})}isBlank(){const r=this._worksheet.getCellMatrix(),{startRow:e,startColumn:t,endRow:n,endColumn:i}=this._range;let o=!0;for(let h=e;h<=n;h++){for(let d=t;d<=i;d++)if(!s.isNullCell(r.getValue(h,d))){o=!1;break}if(!o)break}return o}offset(r,e,t,n){const{startRow:i,startColumn:o,endRow:h,endColumn:d}=this._range,l=i+r,m=o+e,g=t?l+t-1:h+r,_=n?m+n-1:d+e;if(l<0||m<0||g<0||_<0)throw new Error("The row or column index is out of range");return this._injector.createInstance(u.FRange,this._workbook,this._worksheet,{startRow:l,startColumn:m,endRow:g,endColumn:_})}setFormula(r){return this.setValue({f:r})}setFormulas(r){return this.setValues(r.map(e=>e.map(t=>({f:t}))))}},u.FRange=L([N(3,s.Inject(s.Injector)),N(4,s.ICommandService),N(5,s.Inject(I.FormulaDataModel))],u.FRange);var z=Object.getOwnPropertyDescriptor,G=(c,r,e,t)=>{for(var n=t>1?void 0:t?z(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},$=(c,r)=>(e,t)=>r(e,t,c);u.FSelection=class{constructor(r,e,t,n){this._workbook=r,this._worksheet=e,this._selections=t,this._injector=n}getActiveRange(){const r=this._selections.find(e=>!!e.primary);return r?this._injector.createInstance(u.FRange,this._workbook,this._worksheet,r.range):null}getActiveRangeList(){return this._selections.map(r=>this._injector.createInstance(u.FRange,this._workbook,this._worksheet,r.range))}getCurrentCell(){const r=this._selections.find(e=>!!e.primary);return r?r.primary:null}getActiveSheet(){const r=this._injector.createInstance(u.FWorkbook,this._workbook);return this._injector.createInstance(u.FWorksheet,r,this._workbook,this._worksheet)}updatePrimaryCell(r){const e=this._injector.get(s.ICommandService);let t=[],n=!1;for(const{range:o,style:h}of this._selections)s.Rectangle.contains(o,r.getRange())?(t.push({range:o,primary:a.getPrimaryForRange(r.getRange(),this._worksheet),style:h}),n=!0):t.push({range:o,primary:null,style:h});n||(t=[{range:r.getRange(),primary:a.getPrimaryForRange(r.getRange(),this._worksheet)}]);const i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),selections:t};return e.syncExecuteCommand(a.SetSelectionsOperation.id,i),new u.FSelection(this._workbook,this._worksheet,t,this._injector)}getNextDataRange(r){if(!this._selections.find(n=>!!n.primary))return null;const t=a.getNextPrimaryCell(this._selections.concat(),r,this._worksheet);return t?this._injector.createInstance(u.FRange,this._workbook,this._worksheet,t):null}},u.FSelection=G([$(3,s.Inject(s.Injector))],u.FSelection);var Y=Object.getOwnPropertyDescriptor,K=(c,r,e,t)=>{for(var n=t>1?void 0:t?Y(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},p=(c,r)=>(e,t)=>r(e,t,c);u.FWorksheet=class extends S.FBaseInitialable{constructor(e,t,n,i,o,h,d){super(i);b(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=n,this._injector=i,this._selectionManagerService=o,this._logService=h,this._commandService=d}dispose(){super.dispose(),delete this._fWorkbook,delete this._workbook,delete this._worksheet}getSheet(){return this._worksheet}getInject(){return this._injector}getWorkbook(){return this._workbook}getSheetId(){return this._worksheet.getSheetId()}getSheetName(){return this._worksheet.getName()}getSelection(){const e=this._selectionManagerService.getCurrentSelections();return e?this._injector.createInstance(u.FSelection,this._workbook,this._worksheet,e):null}getDefaultStyle(){return this._worksheet.getDefaultCellStyle()}getRowDefaultStyle(e,t=!1){return t?this._worksheet.getRowStyle(e,t):this._worksheet.getRowStyle(e)}getColumnDefaultStyle(e,t=!1){return t?this._worksheet.getColumnStyle(e,t):this._worksheet.getColumnStyle(e)}setDefaultStyle(e){const t=this._workbook.getUnitId(),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(),i=this._worksheet.getSheetId(),o={unitId:n,subUnitId:i,columnData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,o),this}setRowDefaultStyle(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={unitId:n,subUnitId:i,rowData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,o),this}getRange(e,t,n,i){let o,h;if(typeof e=="object")o=e,h=this._worksheet;else if(typeof e=="string"){const{range:d,sheetName:l}=I.deserializeRangeWithSheet(e),m=l?this._workbook.getSheetBySheetName(l):this._worksheet;if(!m)throw new Error("Range not found");h=m,o={...d,unitId:this._workbook.getUnitId(),sheetId:h.getSheetId(),rangeType:s.RANGE_TYPE.NORMAL,startRow:d.rangeType===s.RANGE_TYPE.COLUMN?0:d.startRow,endRow:d.rangeType===s.RANGE_TYPE.COLUMN?h.getMaxRows()-1:d.endRow,startColumn:d.rangeType===s.RANGE_TYPE.ROW?0:d.startColumn,endColumn:d.rangeType===s.RANGE_TYPE.ROW?h.getMaxColumns()-1:d.endColumn}}else if(typeof e=="number"&&t!==void 0)h=this._worksheet,o={startRow:e,endRow:e+(n!=null?n:1)-1,startColumn:t,endColumn:t+(i!=null?i:1)-1,unitId:this._workbook.getUnitId(),sheetId:this._worksheet.getSheetId()};else throw new Error("Invalid range specification");return this._injector.createInstance(u.FRange,this._workbook,h,o)}getMaxColumns(){return this._worksheet.getMaxColumns()}getMaxRows(){return this._worksheet.getMaxRows()}insertRowAfter(e){return this.insertRowsAfter(e,1)}insertRowBefore(e){return this.insertRowsBefore(e,1)}insertRows(e,t=1){return this.insertRowsBefore(e,t)}insertRowsAfter(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=s.Direction.DOWN,h=e+1,d=e+t,l=0,m=this._worksheet.getColumnCount()-1,g=a.copyRangeStyles(this._worksheet,h,d,l,m,!0,e);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:n,subUnitId:i,direction:o,range:{startRow:h,endRow:d,startColumn:l,endColumn:m},cellValue:g}),this}insertRowsBefore(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=s.Direction.UP,h=e,d=e+t-1,l=0,m=this._worksheet.getColumnCount()-1,g=a.copyRangeStyles(this._worksheet,h,d,l,m,!0,e-1);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:n,subUnitId:i,direction:o,range:{startRow:h,endRow:d,startColumn:l,endColumn:m},cellValue:g}),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(),i=this._worksheet.getSheetId(),o=U(e.getRange(),this._worksheet),h=o,d={startRow:t,endRow:t,startColumn:o.startColumn,endColumn:o.endColumn};return this._commandService.syncExecuteCommand(a.MoveRowsCommand.id,{unitId:n,subUnitId:i,range:o,fromRange:h,toRange:d}),this}hideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=U(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}hideRows(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:s.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:n,subUnitId:i,ranges:[o]}),this}unhideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=U(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}showRows(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:s.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:n,subUnitId:i,ranges:[o]}),this}setRowHeight(e,t){return this.setRowHeights(e,1,t)}autoFitRow(e,t=s.BooleanNumber.TRUE){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=[{startRow:e,endRow:e,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:o[0],value:s.WrapStrategy.WRAP}),this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightMutation.id,{unitId:n,subUnitId:i,ranges:o,autoHeightInfo:t}),this}setRowHeights(e,t,n){var m;const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=this._worksheet.getRowManager(),d=[],l=[];for(let g=e;g<e+t;g++){const _=((m=h.getRow(g))==null?void 0:m.ah)||this._worksheet.getConfig().defaultRowHeight,k={startRow:g,endRow:g,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};n<=_?d.push(k):l.push(k)}return l.length>0&&this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:i,subUnitId:o,ranges:l,value:n}),d.length>0&&this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:i,subUnitId:o,ranges:d}),this}getRowHeight(e){return this._worksheet.getRowHeight(e)}setRowAutoHeight(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:n,subUnitId:i,ranges:o}),this}setRangesAutoHeight(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:t,subUnitId:n,ranges:e}),this}setRowHeightsForced(e,t,n){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:i,subUnitId:o,ranges:h,value:n}),this}setRowCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i={};for(const[h,d]of Object.entries(e))i[Number(h)]={custom:d};const o={unitId:t,subUnitId:n,rowData:i};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,o),this}insertColumnAfter(e){return this.insertColumnsAfter(e,1)}insertColumnBefore(e){return this.insertColumnsBefore(e,1)}insertColumns(e,t=1){return this.insertColumnsBefore(e,t)}insertColumnsAfter(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=s.Direction.RIGHT,h=0,d=this._worksheet.getRowCount()-1,l=e+1,m=e+t,g=a.copyRangeStyles(this._worksheet,h,d,l,m,!1,e);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:n,subUnitId:i,direction:o,range:{startRow:h,endRow:d,startColumn:l,endColumn:m},cellValue:g}),this}insertColumnsBefore(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=s.Direction.LEFT,h=0,d=this._worksheet.getRowCount()-1,l=e,m=e+t-1,g=a.copyRangeStyles(this._worksheet,h,d,l,m,!1,e-1);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:n,subUnitId:i,direction:o,range:{startRow:h,endRow:d,startColumn:l,endColumn:m},cellValue:g}),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(),i=this._worksheet.getSheetId(),o=P(e.getRange(),this._worksheet),h=o,d={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return this._commandService.syncExecuteCommand(a.MoveColsCommand.id,{unitId:n,subUnitId:i,range:o,fromRange:h,toRange:d}),this}hideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=P(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}hideColumns(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:s.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:n,subUnitId:i,ranges:[o]}),this}unhideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=P(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}showColumns(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:s.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:n,subUnitId:i,ranges:[o]}),this}setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}setColumnWidths(e,t,n){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return this._commandService.syncExecuteCommand(a.SetColWidthCommand.id,{unitId:i,subUnitId:o,ranges:h,value:n}),this}getColumnWidth(e){return this._worksheet.getColumnWidth(e)}setColumnCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i={};for(const[h,d]of Object.entries(e))i[Number(h)]={custom:d};const o={unitId:t,subUnitId:n,columnData:i};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,o),this}getMergeData(){return this._worksheet.getMergeData().map(e=>this._injector.createInstance(u.FRange,this._workbook,this._worksheet,e))}getMergedRanges(){return this._worksheet.getSnapshot().mergeData.map(t=>this._injector.createInstance(u.FRange,this._workbook,this._worksheet,t))}getCellMergeData(e,t){const i=this._worksheet.getMergedCell(e,t);if(i)return this._injector.createInstance(u.FRange,this._workbook,this._worksheet,i)}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.");return this._fWorkbook.setActiveRange(e),this}getActiveCell(){return this._fWorkbook.getActiveCell()}setFreeze(e){return this._logService.warn("setFreeze is deprecated, use setFrozenRows and setFrozenColumns instead"),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{...e,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}cancelFreeze(){return this._commandService.syncExecuteCommand(a.CancelFrozenCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}getFreeze(){return this._worksheet.getFreeze()}setFrozenColumns(...e){const t=this.getFreeze();if(arguments.length===1){const n=e[0];this.setFreeze({...t,startColumn:n>0?n:-1,xSplit:n})}else if(arguments.length===2){let[n=0,i=0]=e;n>i&&([n,i]=[i,n]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startColumn:i+1,xSplit:i-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,i=0]=e;n>i&&([n,i]=[i,n]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startRow:i+1,ySplit:i-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===s.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.syncExecuteCommand(a.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?s.BooleanNumber.FALSE:s.BooleanNumber.TRUE}),this}setGridLinesColor(e){return this._commandService.syncExecuteCommand(a.SetGridlinesColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getGridLinesColor(){return this._worksheet.getGridlinesColor()}setTabColor(e){return this._commandService.syncExecuteCommand(a.SetTabColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),value:e}),this}getTabColor(){return this._worksheet.getTabColor()}onCellDataChange(e){return this._injector.get(s.ICommandService).onCommandExecuted(n=>{if(n.id===a.SetRangeValuesMutation.id){const i=n.params;i.unitId===this._workbook.getUnitId()&&i.subUnitId===this._worksheet.getSheetId()&&i.cellValue&&e(new s.ObjectMatrix(i.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(s.ICommandService).beforeCommandExecuted(n=>{if(n.id===a.SetRangeValuesMutation.id){const i=n.params;i.unitId===this._workbook.getUnitId()&&i.subUnitId===this._worksheet.getSheetId()&&i.cellValue&&e(new s.ObjectMatrix(i.cellValue))}})}hideSheet(){const e=this._injector.get(s.ICommandService);if(this._workbook.getSheets().filter(o=>o.isSheetHidden()!==s.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(s.ICommandService).syncExecuteCommand(a.SetWorksheetShowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}isSheetHidden(){return this._worksheet.isSheetHidden()===s.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(),i=this._injector.get(s.ICommandService),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return i.syncExecuteCommand(a.ClearSelectionAllCommand.id,{unitId:t,subUnitId:n,ranges:[o],options:e}),this}clearContents(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),n=this._injector.get(s.ICommandService),i={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:[i]}),this}clearFormats(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),n=this._injector.get(s.ICommandService),i={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:[i]}),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 u.FWorksheet?this._worksheet.getSheetId()===e.getSheetId()&&this._workbook.getUnitId()===e.getWorkbook().getUnitId():!1}insertDefinedName(e,t){const i=this._injector.createInstance(E).setName(e).setRef(t).build();i.localSheetId=this.getSheetId(),this._fWorkbook.insertDefinedNameBuilder(i)}getDefinedNames(){return this._fWorkbook.getDefinedNames().filter(t=>t.getLocalSheetId()===this.getSheetId())}setCustomMetadata(e){return this._worksheet.setCustomMetadata(e),this}getCustomMetadata(){return this._worksheet.getCustomMetadata()}setRowCustomMetadata(e,t){return this._worksheet.getRowManager().setCustomMetadata(e,t),this}setColumnCustomMetadata(e,t){return this._worksheet.getColumnManager().setCustomMetadata(e,t),this}getRowCustomMetadata(e){return this._worksheet.getRowManager().getCustomMetadata(e)}getColumnCustomMetadata(e){return this._worksheet.getColumnManager().getCustomMetadata(e)}appendRow(e){const t=this._worksheet.getCellMatrix().hasValue(),n=this._worksheet.getLastRowWithContent(),i=this._worksheet.getRowCount(),o=this._worksheet.getColumnCount(),h=t?n+1:n,d=new s.ObjectMatrix;for(let l=0;l<e.length;l++)d.setValue(h,l,s.covertCellValue(e[l]));return this._commandService.syncExecuteCommand(a.AppendRowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cellValue:d.getMatrix(),insertRowNums:h>i-1?1:0,insertColumnNums:e.length>o?e.length-o:0,maxRows:i,maxColumns:o}),this}setRowCount(e){return this._commandService.syncExecuteCommand(a.SetWorksheetRowCountCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rowCount:e}),this}setColumnCount(e){return this._commandService.syncExecuteCommand(a.SetWorksheetColumnCountCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),columnCount:e}),this}},u.FWorksheet=K([p(3,s.Inject(s.Injector)),p(4,s.Inject(a.SheetsSelectionsService)),p(5,s.Inject(s.ILogService)),p(6,s.ICommandService)],u.FWorksheet);var q=Object.getOwnPropertyDescriptor,J=(c,r,e,t)=>{for(var n=t>1?void 0:t?q(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},C=(c,r)=>(e,t)=>r(e,t,c);u.FWorkbook=class extends S.FBaseInitialable{constructor(e,t,n,i,o,h,d,l,m,g){super(t);b(this,"id");this._workbook=e,this._injector=t,this._resourceLoaderService=n,this._selectionManagerService=i,this._univerInstanceService=o,this._commandService=h,this._permissionService=d,this._logService=l,this._localeService=m,this._definedNamesService=g,this.id=this._workbook.getUnitId()}getWorkbook(){return this._workbook}dispose(){super.dispose(),this._workbook=null}getId(){return this.id}getName(){return this._workbook.name}setName(e){return this._commandService.syncExecuteCommand(a.SetWorkbookNameCommand.id,{unitId:this._workbook.getUnitId(),name:e}),this}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(u.FWorksheet,this,this._workbook,e)}getSheets(){return this._workbook.getSheets().map(e=>this._injector.createInstance(u.FWorksheet,this,this._workbook,e))}create(e,t,n,i){var l,m,g;const o=s.mergeWorksheetSnapshotWithDefault(s.Tools.deepClone((l=i==null?void 0:i.sheet)!=null?l:{}));o.name=e,o.rowCount=t,o.columnCount=n,o.id=(m=i==null?void 0:i.sheet)==null?void 0:m.id;const h=(g=i==null?void 0:i.index)!=null?g:this._workbook.getSheets().length;this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{unitId:this.id,index:h,sheet:o}),this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[h].getSheetId()});const d=this._workbook.getActiveSheet();if(!d)throw new Error("No active sheet found");return this._injector.createInstance(u.FWorksheet,this,this._workbook,d)}getSheetBySheetId(e){const t=this._workbook.getSheetBySheetId(e);return t?this._injector.createInstance(u.FWorksheet,this,this._workbook,t):null}getSheetByName(e){const t=this._workbook.getSheetBySheetName(e);return t?this._injector.createInstance(u.FWorksheet,this,this._workbook,t):null}setActiveSheet(e){return this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:typeof e=="string"?e:e.getSheetId()}),typeof e=="string"?this.getSheetBySheetId(e):e}insertSheet(e,t){var h,d,l;const n=s.mergeWorksheetSnapshotWithDefault(s.Tools.deepClone((h=t==null?void 0:t.sheet)!=null?h:{}));n.name=e,n.id=(d=t==null?void 0:t.sheet)==null?void 0:d.id;const i=(l=t==null?void 0:t.index)!=null?l:this._workbook.getSheets().length;this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{unitId:this.id,index:i,sheet:n}),this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[i].getSheetId()});const o=this._workbook.getActiveSheet();if(!o)throw new Error("No active sheet found");return this._injector.createInstance(u.FWorksheet,this,this._workbook,o)}deleteSheet(e){const t=this.id,n=typeof e=="string"?e:e.getSheetId();return this._commandService.syncExecuteCommand(a.RemoveSheetCommand.id,{unitId:t,subUnitId:n})}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(s.UndoCommand.id),this}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(s.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 s.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(t=>{this._univerInstanceService.getCurrentUnitForType(s.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());return this._permissionService.getPermissionPoint(t.id)||this._permissionService.addPermissionPoint(t),this._permissionService.updatePermissionPoint(t.id,e),this}setActiveRange(e){const t=this.getActiveSheet(),n=e.getRange().sheetId||t.getSheetId(),i=n?this._workbook.getSheetBySheetId(n):this._workbook.getActiveSheet(!0);if(!i)throw new Error("No active sheet found");i.getSheetId()!==t.getSheetId()&&this.setActiveSheet(this._injector.createInstance(u.FWorksheet,this,this._workbook,i));const o={unitId:this.getId(),subUnitId:n,selections:[e].map(h=>({range:h.getRange(),primary:a.getPrimaryForRange(h.getRange(),i),style:null}))};return this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,o),this}getActiveRange(){const e=this._workbook.getActiveSheet(),n=this._selectionManagerService.getCurrentSelections().find(i=>!!i.primary);return n?this._injector.createInstance(u.FRange,this._workbook,e,n.range):null}getActiveCell(){const e=this._workbook.getActiveSheet(),n=this._selectionManagerService.getCurrentSelections().find(o=>!!o.primary);if(!n)return null;const i={...n.primary,rangeType:s.RANGE_TYPE.NORMAL};return this._injector.createInstance(u.FRange,this._workbook,e,i)}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(u.FWorksheet,this,this._workbook,this._workbook.getActiveSheet())}duplicateActiveSheet(){const e=this.getActiveSheet();return this.duplicateSheet(e)}getNumSheets(){return this._workbook.getSheets().length}getLocale(){return this._localeService.getCurrentLocale()}setLocale(e){this._localeService.setLocale(e)}setSpreadsheetLocale(e){return this._localeService.setLocale(e),this}getUrl(){return location.href}moveSheet(e,t){let 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(u.FPermission)}getDefinedName(e){const t=this._definedNamesService.getValueByName(this.id,e);return t?this._injector.createInstance(y,{...t,unitId:this.id}):null}getDefinedNames(){const e=this._definedNamesService.getDefinedNameMap(this.id);return e?Object.values(e).map(t=>this._injector.createInstance(y,{...t,unitId:this.id})):[]}insertDefinedName(e,t){const i=this._injector.createInstance(E).setName(e).setRef(t).build();return i.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this.insertDefinedNameBuilder(i),this}deleteDefinedName(e){const t=this.getDefinedName(e);return t?(t.delete(),!0):!1}insertDefinedNameBuilder(e){e.unitId=this.getId(),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}updateDefinedNameBuilder(e){this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}getRegisteredRangeThemes(){return this._injector.get(a.SheetRangeThemeService).getRegisteredRangeThemes()}registerRangeTheme(e){this._commandService.syncExecuteCommand(a.RegisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),rangeThemeStyle:e})}unregisterRangeTheme(e){this._commandService.syncExecuteCommand(a.UnregisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),themeName:e})}createRangeThemeStyle(e,t){return new a.RangeThemeStyle(e,t)}setCustomMetadata(e){return this._workbook.setCustomMetadata(e),this}getCustomMetadata(){return this._workbook.getCustomMetadata()}addStyles(e){this._workbook.addStyles(e)}removeStyles(e){this._workbook.removeStyles(e)}},u.FWorkbook=J([C(1,s.Inject(s.Injector)),C(2,s.Inject(s.IResourceLoaderService)),C(3,s.Inject(a.SheetsSelectionsService)),C(4,s.IUniverInstanceService),C(5,s.ICommandService),C(6,s.IPermissionService),C(7,s.ILogService),C(8,s.Inject(s.LocaleService)),C(9,I.IDefinedNamesService)],u.FWorkbook);class Q extends S.FUniver{getCommandSheetTarget(r){var i;const e=r.params;if(!e)return this.getActiveSheet();const t=e.unitId?this.getUniverSheet(e.unitId):(i=this.getActiveWorkbook)==null?void 0:i.call(this);if(!t)return;const n=t.getSheetBySheetId(e.subUnitId||e.sheetId)||t.getActiveSheet();if(n)return{workbook:t,worksheet:n}}getSheetTarget(r,e){const t=this.getUniverSheet(r);if(!t)return;const n=t.getSheetBySheetId(e);if(n)return{workbook:t,worksheet:n}}_initWorkbookEvent(r){const e=r.get(s.IUniverInstanceService);this.registerEventHandler(this.Event.WorkbookDisposed,()=>e.unitDisposed$.subscribe(t=>{t.type===s.UniverInstanceType.UNIVER_SHEET&&this.fireEvent(this.Event.WorkbookDisposed,{unitId:t.getUnitId(),unitType:t.type,snapshot:t.getSnapshot()})})),this.registerEventHandler(this.Event.WorkbookCreated,()=>e.unitAdded$.subscribe(t=>{if(t.type===s.UniverInstanceType.UNIVER_SHEET){const n=t,i=r.createInstance(u.FWorkbook,n);this.fireEvent(this.Event.WorkbookCreated,{unitId:t.getUnitId(),type:t.type,workbook:i,unit:i})}}))}_initialize(r){const e=r.get(s.ICommandService);this.registerEventHandler(this.Event.BeforeSheetCreate,()=>e.beforeCommandExecuted(t=>{var n;if(t.id===a.InsertSheetCommand.id){const i=t.params,{unitId:o,index:h,sheet:d}=i||{},l=o?this.getUniverSheet(o):(n=this.getActiveWorkbook)==null?void 0:n.call(this);if(!l)return;const m={workbook:l,index:h,sheet:d};if(this.fireEvent(this.Event.BeforeSheetCreate,m),m.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeActiveSheetChange,()=>e.beforeCommandExecuted(t=>{var n;if(t.id===a.SetWorksheetActiveOperation.id){const{subUnitId:i,unitId:o}=t.params,h=o?this.getUniverSheet(o):(n=this.getActiveWorkbook)==null?void 0:n.call(this);if(!h||!i)return;const d=h.getSheetBySheetId(i),l=h.getActiveSheet();if(!d||!l)return;const m={workbook:h,activeSheet:d,oldActiveSheet:l};if(this.fireEvent(this.Event.BeforeActiveSheetChange,m),m.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDelete,()=>e.beforeCommandExecuted(t=>{if(t.id===a.RemoveSheetCommand.id){const n=this.getCommandSheetTarget(t);if(!n)return;const{workbook:i,worksheet:o}=n,h={workbook:i,worksheet:o};if(this.fireEvent(this.Event.BeforeSheetDelete,h),h.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetMove,()=>e.beforeCommandExecuted(t=>{if(t.id===a.SetWorksheetOrderMutation.id){const{fromOrder:n,toOrder:i}=t.params,o=this.getCommandSheetTarget(t);if(!o)return;const h={workbook:o.workbook,worksheet:o.worksheet,newIndex:i,oldIndex:n};if(this.fireEvent(this.Event.BeforeSheetMove,h),h.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetNameChange,()=>e.beforeCommandExecuted(t=>{if(t.id===a.SetWorksheetNameCommand.id){const{name:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;const o={workbook:i.workbook,worksheet:i.worksheet,newName:n,oldName:i.worksheet.getSheetName()};if(this.fireEvent(this.Event.BeforeSheetNameChange,o),o.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetTabColorChange,()=>e.beforeCommandExecuted(t=>{if(t.id===a.SetTabColorMutation.id){const{color:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;const o={workbook:i.workbook,worksheet:i.worksheet,newColor:n,oldColor:i.worksheet.getTabColor()};if(this.fireEvent(this.Event.BeforeSheetTabColorChange,o),o.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetHideChange,()=>e.beforeCommandExecuted(t=>{if(t.id===a.SetWorksheetHideMutation.id){const{hidden:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;const o={workbook:i.workbook,worksheet:i.worksheet,hidden:!!n};if(this.fireEvent(this.Event.BeforeSheetHideChange,o),o.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeGridlineColorChange,()=>e.beforeCommandExecuted(t=>{var n;if(t.id===a.SetGridlinesColorCommand.id){const i=this.getCommandSheetTarget(t);if(!i)return;const o={...i,color:(n=t.params)==null?void 0:n.color};if(this.fireEvent(this.Event.BeforeGridlineColorChange,o),o.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeGridlineEnableChange,()=>e.beforeCommandExecuted(t=>{var n;if(t.id===a.ToggleGridlinesCommand.id){const i=this.getCommandSheetTarget(t);if(!i)return;const o={...i,enabled:!!((n=t.params)!=null&&n.showGridlines)};if(this.fireEvent(this.Event.BeforeGridlineEnableChange,o),o.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.SheetValueChanged,()=>e.onCommandExecuted(t=>{if(a.COMMAND_LISTENER_VALUE_CHANGE.indexOf(t.id)>-1){if(!this.getActiveSheet())return;const i=a.getValueChangedEffectedRange(t).map(o=>{var h,d;return(d=(h=this.getWorkbook(o.unitId))==null?void 0:h.getSheetBySheetId(o.subUnitId))==null?void 0:d.getRange(o.range)}).filter(Boolean);if(!i.length)return;this.fireEvent(this.Event.SheetValueChanged,{payload:t,effectedRanges:i})}})),this.registerEventHandler(this.Event.SheetCreated,()=>e.onCommandExecuted(t=>{var n;if(t.id===a.InsertSheetCommand.id){const i=t.params,{unitId:o}=i||{},h=o?this.getUniverSheet(o):(n=this.getActiveWorkbook)==null?void 0:n.call(this);if(!h)return;const d=h.getActiveSheet();if(!d)return;const l={workbook:h,worksheet:d};this.fireEvent(this.Event.SheetCreated,l)}})),this.registerEventHandler(this.Event.ActiveSheetChanged,()=>e.onCommandExecuted(t=>{if(t.id===a.SetWorksheetActiveOperation.id){const n=this.getActiveSheet();if(!n)return;const{workbook:i,worksheet:o}=n;this._fireActiveSheetChanged(i,o)}})),this.registerEventHandler(this.Event.SheetDeleted,()=>e.onCommandExecuted(t=>{var n;if(t.id===a.RemoveSheetCommand.id){const{subUnitId:i,unitId:o}=t.params,h=o?this.getUniverSheet(o):(n=this.getActiveWorkbook)==null?void 0:n.call(this);if(!h||!i)return;this._fireSheetDeleted(h,i)}})),this.registerEventHandler(this.Event.SheetMoved,()=>e.onCommandExecuted(t=>{if(t.id===a.SetWorksheetOrderMutation.id){const{toOrder:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;this._fireSheetMoved(i.workbook,i.worksheet,n)}})),this.registerEventHandler(this.Event.SheetNameChanged,()=>e.onCommandExecuted(t=>{if(t.id===a.SetWorksheetNameCommand.id){const{name:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;this._fireSheetNameChanged(i.workbook,i.worksheet,n)}})),this.registerEventHandler(this.Event.SheetTabColorChanged,()=>e.onCommandExecuted(t=>{if(t.id===a.SetTabColorMutation.id){const{color:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;this._fireSheetTabColorChanged(i.workbook,i.worksheet,n)}})),this.registerEventHandler(this.Event.SheetHideChanged,()=>e.onCommandExecuted(t=>{if(t.id===a.SetWorksheetHideMutation.id){const{hidden:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;this._fireSheetHideChanged(i.workbook,i.worksheet,!!n)}})),this.registerEventHandler(this.Event.GridlineChanged,()=>e.onCommandExecuted(t=>{if(t.id===a.SetGridlinesColorCommand.id||t.id===a.ToggleGridlinesCommand.id){const n=this.getCommandSheetTarget(t);if(!n)return;this.fireEvent(this.Event.GridlineChanged,{...n,enabled:!n.worksheet.hasHiddenGridLines(),color:n.worksheet.getGridLinesColor()})}})),this._initWorkbookEvent(r)}createUniverSheet(r,e){const n=this._injector.get(s.IUniverInstanceService).createUnit(s.UniverInstanceType.UNIVER_SHEET,r,e);return this._injector.createInstance(u.FWorkbook,n)}createWorkbook(r,e){return this.createUniverSheet(r,e)}getActiveWorkbook(){const r=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);return r?this._injector.createInstance(u.FWorkbook,r):null}getActiveUniverSheet(){return this.getActiveWorkbook()}getUniverSheet(r){const e=this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_SHEET);return e?this._injector.createInstance(u.FWorkbook,e):null}getWorkbook(r){return this.getUniverSheet(r)}getPermission(){return this._injector.createInstance(u.FPermission)}onUniverSheetCreated(r){const e=this._univerInstanceService.getTypeOfUnitAdded$(s.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{const n=this._injector.createInstance(u.FWorkbook,t);r(n)});return s.toDisposable(e)}newDefinedName(){return this._injector.createInstance(E)}getActiveSheet(){const r=this.getActiveWorkbook();if(!r)return null;const e=r.getActiveSheet();return e?{workbook:r,worksheet:e}:null}setFreezeSync(r){this._injector.get(a.SheetsFreezeSyncController).setEnabled(r)}_fireActiveSheetChanged(r,e){this.fireEvent(this.Event.ActiveSheetChanged,{workbook:r,activeSheet:e})}_fireSheetDeleted(r,e){this.fireEvent(this.Event.SheetDeleted,{workbook:r,sheetId:e})}_fireSheetMoved(r,e,t){this.fireEvent(this.Event.SheetMoved,{workbook:r,worksheet:e,newIndex:t})}_fireSheetNameChanged(r,e,t){this.fireEvent(this.Event.SheetNameChanged,{workbook:r,worksheet:e,newName:t})}_fireSheetTabColorChanged(r,e,t){this.fireEvent(this.Event.SheetTabColorChanged,{workbook:r,worksheet:e,newColor:t})}_fireSheetHideChanged(r,e,t){this.fireEvent(this.Event.SheetHideChanged,{workbook:r,worksheet:e,hidden:t})}}S.FUniver.extend(Q);class W{get SheetValueChangeType(){return a.SheetValueChangeType}get SheetSkeletonChangeType(){return a.SheetSkeletonChangeType}get SplitDelimiterType(){return a.SplitDelimiterEnum}}S.FEnum.extend(W);class M{get SheetCreated(){return"SheetCreated"}get BeforeSheetCreate(){return"BeforeSheetCreate"}get WorkbookCreated(){return"WorkbookCreated"}get WorkbookDisposed(){return"WorkbookDisposed"}get GridlineChanged(){return"GridlineChanged"}get BeforeGridlineEnableChange(){return"BeforeGridlineEnableChange"}get BeforeGridlineColorChange(){return"BeforeGridlineColorChange"}get BeforeActiveSheetChange(){return"BeforeActiveSheetChange"}get ActiveSheetChanged(){return"ActiveSheetChanged"}get SheetDeleted(){return"SheetDeleted"}get BeforeSheetDelete(){return"BeforeSheetDelete"}get SheetMoved(){return"SheetMoved"}get BeforeSheetMove(){return"BeforeSheetMove"}get SheetNameChanged(){return"SheetNameChanged"}get BeforeSheetNameChange(){return"BeforeSheetNameChange"}get SheetTabColorChanged(){return"SheetTabColorChanged"}get BeforeSheetTabColorChange(){return"BeforeSheetTabColorChange"}get SheetHideChanged(){return"SheetHideChanged"}get BeforeSheetHideChange(){return"BeforeSheetHideChange"}get SheetValueChanged(){return"SheetValueChanged"}}S.FEventName.extend(M);var X=Object.getOwnPropertyDescriptor,Z=(c,r,e,t)=>{for(var n=t>1?void 0:t?X(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},ee=(c,r)=>(e,t)=>r(e,t,c);u.FSheetHooks=class extends S.FBase{constructor(r){super(),this._injector=r}},u.FSheetHooks=Z([ee(0,s.Inject(s.Injector))],u.FSheetHooks),u.FSheetEventName=M,u.FSheetsEnum=W,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
|
|
16
|
+
(function(u,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/sheets"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/core/facade","@univerjs/sheets","@univerjs/engine-formula"],s):(u=typeof globalThis<"u"?globalThis:u||self,s(u.UniverSheetsFacade={},u.UniverCore,u.UniverCoreFacade,u.UniverSheets,u.UniverEngineFormula))})(this,(function(u,s,S,a,I){"use strict";var ne=Object.defineProperty;var re=(u,s,S)=>s in u?ne(u,s,{enumerable:!0,configurable:!0,writable:!0,value:S}):u[s]=S;var R=(u,s,S)=>re(u,typeof s!="symbol"?s+"":s,S);var E;var D=Object.getOwnPropertyDescriptor,x=(c,r,e,t)=>{for(var n=t>1?void 0:t?D(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},w=(c,r)=>(e,t)=>r(e,t,c);function B(c,r,e){const t=e.getDefinedNameMap(c);if(t==null)return r.t("definedName.defaultName")+1;const i=Array.from(Object.values(t)).length+1,o=r.t("definedName.defaultName")+i;if(e.getValueByName(c,o)==null)return o;let h=i+1;for(;;){const d=r.t("definedName.defaultName")+h;if(e.getValueByName(c,d)==null)return d;h++}}class y{constructor(){R(this,"_definedNameParam");this._definedNameParam={id:s.generateRandomId(10),unitId:"",name:"",formulaOrRefString:"",localSheetId:a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}}setName(r){return this._definedNameParam.name=r,this}setFormula(r){return this._definedNameParam.formulaOrRefString=`=${r}`,this}setRef(r){return this._definedNameParam.formulaOrRefString=r,this}setRefByRange(r,e,t,n){return this._definedNameParam.formulaOrRefString=I.serializeRange({startRow:r,endRow:r+(t!=null?t:1)-1,startColumn:e,endColumn:e+(n!=null?n:1)-1}),this}setComment(r){return this._definedNameParam.comment=r,this}setScopeToWorksheet(r){return this._definedNameParam.localSheetId=r.getSheetId(),this}setScopeToWorkbook(){return this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this}setHidden(r){return this._definedNameParam.hidden=r,this}build(){return this._definedNameParam}load(r){return this._definedNameParam=r,this}}let p=class extends S.FBase{constructor(c,r,e,t,n,i,o,h,d,l){super(),this._definedNameParam=c,this._injector=r,this._commandService=e,this._permissionService=t,this._worksheetProtectionRuleModel=n,this._rangeProtectionRuleModel=i,this._worksheetProtectionPointRuleModel=o,this._authzIoService=h,this._localeService=d,this._definedNamesService=l}_apply(){this._definedNameParam.name===""&&(this._definedNameParam.name=B(this._definedNameParam.unitId,this._localeService,this._definedNamesService)),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,this._definedNameParam)}getName(){return this._definedNameParam.name}setName(c){this._definedNameParam.name=c,this._apply()}setFormula(c){this._definedNameParam.formulaOrRefString=`=${c}`,this._apply()}setRef(c){this._definedNameParam.formulaOrRefString=c,this._apply()}getFormulaOrRefString(){return this._definedNameParam.formulaOrRefString}setRefByRange(c,r,e,t){this._definedNameParam.formulaOrRefString=I.serializeRange({startRow:c,endRow:c+(e!=null?e:1)-1,startColumn:r,endColumn:r+(t!=null?t:1)-1}),this._apply()}getComment(){return this._definedNameParam.comment}setComment(c){this._definedNameParam.comment=c,this._apply()}setScopeToWorksheet(c){this._definedNameParam.localSheetId=c.getSheetId(),this._apply()}setScopeToWorkbook(){this._definedNameParam.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this._apply()}setHidden(c){this._definedNameParam.hidden=c,this._apply()}delete(){this._commandService.syncExecuteCommand(a.RemoveDefinedNameCommand.id,this._definedNameParam)}getLocalSheetId(){return this._definedNameParam.localSheetId}isWorkbookScope(){return this._definedNameParam.localSheetId===a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}toBuilder(){const c=this._injector.createInstance(y);return c.load(this._definedNameParam),c}};p=x([w(1,s.Inject(s.Injector)),w(2,s.ICommandService),w(3,s.IPermissionService),w(4,s.Inject(a.WorksheetProtectionRuleModel)),w(5,s.Inject(a.RangeProtectionRuleModel)),w(6,s.Inject(a.WorksheetProtectionPointModel)),w(7,s.Inject(s.IAuthzIoService)),w(8,s.Inject(s.LocaleService)),w(9,I.IDefinedNamesService)],p);var j=Object.getOwnPropertyDescriptor,V=(c,r,e,t)=>{for(var n=t>1?void 0:t?j(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},f=(c,r)=>(e,t)=>r(e,t,c);u.FPermission=class extends S.FBase{constructor(e,t,n,i,o,h,d,l){super();R(this,"permissionPointsDefinition",a.PermissionPointsDefinitions);R(this,"rangeRuleChangedAfterAuth$");R(this,"sheetRuleChangedAfterAuth$");R(this,"unitPermissionInitStateChange$");this._injector=e,this._commandService=t,this._permissionService=n,this._worksheetProtectionRuleModel=i,this._rangeProtectionRuleModel=o,this._worksheetProtectionPointRuleModel=h,this._workbookPermissionService=d,this._authzIoService=l,this.rangeRuleChangedAfterAuth$=this._rangeProtectionRuleModel.ruleRefresh$,this.sheetRuleChangedAfterAuth$=this._worksheetProtectionRuleModel.ruleRefresh$,this.unitPermissionInitStateChange$=this._workbookPermissionService.unitPermissionInitStateChange$}setWorkbookPermissionPoint(e,t,n){const i=new t(e);this._permissionService.getPermissionPoint(i.id)||this._permissionService.addPermissionPoint(i),this._permissionService.updatePermissionPoint(i.id,n)}checkWorkbookPermissionPoint(e,t){const n=new t(e),i=this._permissionService.getPermissionPoint(n.id);if(i)return i.value}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 i=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:i,unitType:a.UnitObject.Worksheet,unitId:e,subUnitId:t}}))return i}removeWorksheetPermission(e,t){this._commandService.syncExecuteCommand(a.DeleteWorksheetProtectionMutation.id,{unitId:e,subUnitId:t}),[...a.getAllWorksheetPermissionPoint(),...a.getAllWorksheetPermissionPointByPointPanel()].forEach(n=>{const i=new n(e,t);this._permissionService.updatePermissionPoint(i.id,!0)}),this._worksheetProtectionPointRuleModel.deleteRule(e,t)}async setWorksheetPermissionPoint(e,t,n,i){const o=this._worksheetProtectionRuleModel.getRule(e,t);let h;if(n===a.WorksheetEditPermission||n===a.WorksheetViewPermission)if(o)h=o.permissionId;else{if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).length>0)throw new Error("sheet protection cannot intersect with range protection");h=await this.addWorksheetBasePermission(e,t)}else{const g=this._worksheetProtectionPointRuleModel.getRule(e,t);g?h=g.permissionId:(h=await this._authzIoService.create({objectType:a.UnitObject.Worksheet,worksheetObject:{collaborators:[],unitID:e,strategies:[],name:"",scope:void 0}}),this._commandService.syncExecuteCommand(a.SetWorksheetPermissionPointsMutation.id,{unitId:e,subUnitId:t,rule:{unitId:e,subUnitId:t,permissionId:h}}))}const l=new n(e,t);return this._permissionService.getPermissionPoint(l.id)||this._permissionService.addPermissionPoint(l),this._permissionService.updatePermissionPoint(l.id,i),h}checkWorksheetPermissionPoint(e,t,n){const i=new n(e,t),o=this._permissionService.getPermissionPoint(i.id);if(o)return o.value}async addRangeBaseProtection(e,t,n){const i=await this._authzIoService.create({objectType:a.UnitObject.SelectRange,selectRangeObject:{collaborators:[],unitID:e,name:"",scope:void 0}}),o=`ruleId_${s.generateRandomId(6)}`;if(this._worksheetProtectionRuleModel.getRule(e,t))throw new Error("sheet protection cannot intersect with range protection");if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).some(g=>g.ranges.some(_=>n.some(k=>s.Rectangle.intersects(k.getRange(),_)))))throw new Error("range protection cannot intersect");if(this._commandService.syncExecuteCommand(a.AddRangeProtectionMutation.id,{unitId:e,subUnitId:t,rules:[{permissionId:i,unitType:a.UnitObject.SelectRange,unitId:e,subUnitId:t,ranges:n.map(g=>g.getRange()),id:o}]}))return{permissionId:i,ruleId:o}}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(h=>{const d=new h(e,t);this._permissionService.updatePermissionPoint(d.id,d.value)}))}setRangeProtectionPermissionPoint(e,t,n,i,o){const h=new i(e,t,n);this._permissionService.getPermissionPoint(h.id)||this._permissionService.addPermissionPoint(h),this._permissionService.updatePermissionPoint(h.id,o)}setRangeProtectionRanges(e,t,n,i){const o=this._rangeProtectionRuleModel.getRule(e,t,n);if(o){if(this._rangeProtectionRuleModel.getSubunitRuleList(e,t).filter(l=>l.id!==n).some(l=>l.ranges.some(m=>i.some(g=>s.Rectangle.intersects(g.getRange(),m)))))throw new Error("range protection cannot intersect");this._commandService.syncExecuteCommand(a.SetRangeProtectionMutation.id,{unitId:e,subUnitId:t,ruleId:n,rule:{...o,ranges:i.map(l=>l.getRange())}})}}getPermissionInfoWithCell(e,t,n,i){const o=s.cellToRange(n,i),h=this._rangeProtectionRuleModel.getSubunitRuleList(e,t).find(d=>d.ranges.some(m=>s.Rectangle.intersects(o,m)));if(h)return{permissionId:h.permissionId,ruleId:h.id}}},u.FPermission=V([f(0,s.Inject(s.Injector)),f(1,s.ICommandService),f(2,s.IPermissionService),f(3,s.Inject(a.WorksheetProtectionRuleModel)),f(4,s.Inject(a.RangeProtectionRuleModel)),f(5,s.Inject(a.WorksheetProtectionPointModel)),f(6,s.Inject(a.WorkbookPermissionService)),f(7,s.Inject(s.IAuthzIoService))],u.FPermission);function O(c){switch(c){case"left":return s.HorizontalAlign.LEFT;case"center":return s.HorizontalAlign.CENTER;case"normal":return s.HorizontalAlign.RIGHT;default:throw new Error(`Invalid horizontal alignment: ${c}`)}}function W(c){switch(c){case s.HorizontalAlign.LEFT:return"left";case s.HorizontalAlign.CENTER:return"center";case s.HorizontalAlign.RIGHT:return"normal";default:return"general"}}function H(c){switch(c){case"top":return s.VerticalAlign.TOP;case"middle":return s.VerticalAlign.MIDDLE;case"bottom":return s.VerticalAlign.BOTTOM;default:throw new Error(`Invalid vertical alignment: ${c}`)}}function A(c){switch(c){case s.VerticalAlign.TOP:return"top";case s.VerticalAlign.MIDDLE:return"middle";case s.VerticalAlign.BOTTOM:return"bottom";default:return"general"}}function P(c,r){return{startRow:c.startRow,endRow:c.endRow,startColumn:0,endColumn:r.getColumnCount()-1,rangeType:s.RANGE_TYPE.ROW}}function N(c,r){return{startRow:0,endRow:r.getRowCount()-1,startColumn:c.startColumn,endColumn:c.endColumn,rangeType:s.RANGE_TYPE.COLUMN}}var L=Object.getOwnPropertyDescriptor,z=(c,r,e,t)=>{for(var n=t>1?void 0:t?L(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},T=(c,r)=>(e,t)=>r(e,t,c);u.FRange=(E=class extends S.FBaseInitialable{constructor(r,e,t,n,i,o){super(n),this._workbook=r,this._worksheet=e,this._range=t,this._injector=n,this._commandService=i,this._formulaDataModel=o,this._runInitializers(this._injector,this._workbook,this._worksheet,this._range,this._commandService,this._formulaDataModel)}getUnitId(){return this._workbook.getUnitId()}getSheetName(){return this._worksheet.getName()}getSheetId(){return this._worksheet.getSheetId()}getRange(){return this._range}getRow(){return this._range.startRow}getLastRow(){return this._range.endRow}getColumn(){return this._range.startColumn}getLastColumn(){return this._range.endColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}isMerged(){const{startColumn:r,startRow:e,endColumn:t,endRow:n}=this._range;return this._worksheet.getMergedCellRange(e,r,n,t).some(o=>s.Rectangle.equals(o,this._range))}getCellStyleData(r="row"){return r!=="cell"?this._worksheet.getComposedCellStyle(this._range.startRow,this._range.startColumn,r==="row"):this._worksheet.getCellStyle(this._range.startRow,this._range.startColumn)}getFontFamily(r="row"){var e,t;return(t=(e=this.getCellStyleData(r))==null?void 0:e.ff)!=null?t:null}getFontSize(r="row"){var e,t;return(t=(e=this.getCellStyleData(r))==null?void 0:e.fs)!=null?t:null}getCellStyle(r="row"){const e=this.getCellStyleData(r);return e?s.TextStyleValue.create(e):null}getCellStyles(r="row"){return this.getCellDatas().map((t,n)=>t.map((i,o)=>{if(!i)return null;const h=r!=="cell"?this._worksheet.getComposedCellStyle(n+this._range.startRow,o+this._range.startColumn,r==="row"):this._worksheet.getCellStyle(n+this._range.startRow,o+this._range.startColumn);return h?s.TextStyleValue.create(h):null}))}getValue(r){var e,t;return r?this.getValueAndRichTextValue():(t=(e=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:e.v)!=null?t:null}getRawValue(){var e,t;const r=this._worksheet.getCellMatrix().getValue(this._range.startRow,this._range.startColumn);return r!=null&&r.p&&((e=r.p.body)!=null&&e.dataStream)?r.p.body.dataStream:(t=r==null?void 0:r.v)!=null?t:null}getDisplayValue(){var e,t,n;const r=this._worksheet.getCell(this._range.startRow,this._range.startColumn);return r!=null&&r.p&&((e=r.p.body)!=null&&e.dataStream)?r.p.body.dataStream:(n=(t=r==null?void 0:r.v)==null?void 0:t.toString())!=null?n:""}getValues(r){var h,d;if(r)return this.getValueAndRichTextValues();const{startRow:e,endRow:t,startColumn:n,endColumn:i}=this._range,o=[];for(let l=e;l<=t;l++){const m=[];for(let g=n;g<=i;g++)m.push((d=(h=this._worksheet.getCell(l,g))==null?void 0:h.v)!=null?d:null);o.push(m)}return o}getRawValues(){var h,d;const r=this._worksheet.getCellMatrix(),{startRow:e,endRow:t,startColumn:n,endColumn:i}=this._range,o=[];for(let l=e;l<=t;l++){const m=[];for(let g=n;g<=i;g++){const _=r.getValue(l,g);_!=null&&_.p&&((h=_.p.body)!=null&&h.dataStream)?m.push(_.p.body.dataStream):m.push((d=_==null?void 0:_.v)!=null?d:null)}o.push(m)}return o}getDisplayValues(){var o,h,d;const{startRow:r,endRow:e,startColumn:t,endColumn:n}=this._range,i=[];for(let l=r;l<=e;l++){const m=[];for(let g=t;g<=n;g++){const _=this._worksheet.getCell(l,g);_!=null&&_.p&&((o=_.p.body)!=null&&o.dataStream)?m.push(_.p.body.dataStream):m.push((d=(h=_==null?void 0:_.v)==null?void 0:h.toString())!=null?d:"")}i.push(m)}return i}getCellData(){var r;return(r=this._worksheet.getCell(this._range.startRow,this._range.startColumn))!=null?r:null}getCellDatas(){return this.getCellDataGrid()}getCellDataGrid(){const{startRow:r,endRow:e,startColumn:t,endColumn:n}=this._range,i=[];for(let o=r;o<=e;o++){const h=[];for(let d=t;d<=n;d++)h.push(this._worksheet.getCellRaw(o,d));i.push(h)}return i}getRichTextValue(){const r=this.getCellData();return r!=null&&r.p?new s.RichTextValue(r.p):null}getRichTextValues(){return this.getCellDataGrid().map(e=>e.map(t=>t!=null&&t.p?new s.RichTextValue(t.p):null))}getValueAndRichTextValue(){const r=this.getCellData();return r!=null&&r.p?new s.RichTextValue(r.p):r==null?void 0:r.v}getValueAndRichTextValues(){return this.getCellDatas().map(e=>e.map(t=>t!=null&&t.p?new s.RichTextValue(t.p):t==null?void 0:t.v))}getFormula(){var r;return(r=this._formulaDataModel.getFormulaStringByCell(this._range.startRow,this._range.startColumn,this._worksheet.getSheetId(),this._workbook.getUnitId()))!=null?r:""}getFormulas(){const r=[],{startRow:e,endRow:t,startColumn:n,endColumn:i}=this._range,o=this._worksheet.getSheetId(),h=this._workbook.getUnitId();for(let d=e;d<=t;d++){const l=[];for(let m=n;m<=i;m++){const g=this._formulaDataModel.getFormulaStringByCell(d,m,o,h);l.push(g||"")}r.push(l)}return r}getWrap(){return this._worksheet.getRange(this._range).getWrap()===s.BooleanNumber.TRUE}getWraps(){const r=this.getCellDatas(),e=this._workbook.getStyles();return r.map(t=>t.map(n=>{var i;return((i=e.getStyleByCell(n))==null?void 0:i.tb)===s.WrapStrategy.WRAP}))}getWrapStrategy(){return this._worksheet.getRange(this._range).getWrapStrategy()}getHorizontalAlignment(){const r=this._worksheet.getRange(this._range).getHorizontalAlignment();return W(r)}getHorizontalAlignments(){return this._worksheet.getRange(this._range).getHorizontalAlignments().map(e=>e.map(t=>W(t)))}getVerticalAlignment(){return A(this._worksheet.getRange(this._range).getVerticalAlignment())}getVerticalAlignments(){return this._worksheet.getRange(this._range).getVerticalAlignments().map(e=>e.map(t=>A(t)))}setCustomMetaData(r){return this.setValue({custom:r})}setCustomMetaDatas(r){return this.setValues(r.map(e=>e.map(t=>({custom:t}))))}getCustomMetaData(){var e;const r=this.getCellData();return(e=r==null?void 0:r.custom)!=null?e:null}getCustomMetaDatas(){return this.getCellDataGrid().map(e=>e.map(t=>{var n;return(n=t==null?void 0:t.custom)!=null?n:null}))}setBorder(r,e,t){return this._commandService.syncExecuteCommand(a.SetBorderBasicCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range],value:{type:r,style:e,color:t}}),this}getBackground(){var e,t;const r=this.getCellStyle();return(t=(e=r==null?void 0:r.background)==null?void 0:e.rgb)!=null?t:s.DEFAULT_STYLES.bg.rgb}getBackgrounds(){return this.getCellStyles().map(e=>e.map(t=>{var n,i;return(i=(n=t==null?void 0:t.background)==null?void 0:n.rgb)!=null?i:s.DEFAULT_STYLES.bg.rgb}))}setBackgroundColor(r){return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:r}}}),this}setBackground(r){return this.setBackgroundColor(r),this}setTextRotation(r){return this._commandService.syncExecuteCommand(a.SetTextRotationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:r}),this}setValue(r){const e=s.covertCellValue(r);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setValueForCell(r){const e=s.covertCellValue(r);if(!e)throw new Error("Invalid value");return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.startColumn,endRow:this._range.startRow},value:e}),this}setRichTextValueForCell(r){const e=r instanceof s.RichTextValue?r.getData():r,t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:{startColumn:this._range.startColumn,startRow:this._range.startRow,endColumn:this._range.startColumn,endRow:this._range.startRow},value:{p:e}};return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,t),this}setRichTextValues(r){const e=r.map(i=>i.map(o=>o&&{p:o instanceof s.RichTextValue?o.getData():o})),t=s.covertCellValues(e,this._range),n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:t};return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,n),this}setWrap(r){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:r?s.WrapStrategy.WRAP:s.WrapStrategy.UNSPECIFIED}),this}setWrapStrategy(r){return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:r}),this}setVerticalAlignment(r){return this._commandService.syncExecuteCommand(a.SetVerticalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:H(r)}),this}setHorizontalAlignment(r){return this._commandService.syncExecuteCommand(a.SetHorizontalTextAlignCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:O(r)}),this}setValues(r){const e=s.covertCellValues(r,this._range);return this._commandService.syncExecuteCommand(a.SetRangeValuesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,value:e}),this}setFontWeight(r){let e;if(r==="bold")e=s.BooleanNumber.TRUE;else if(r==="normal")e=s.BooleanNumber.FALSE;else if(r===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.syncExecuteCommand(a.SetStyleCommand.id,n),this}setFontStyle(r){let e;if(r==="italic")e=s.BooleanNumber.TRUE;else if(r==="normal")e=s.BooleanNumber.FALSE;else if(r===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.syncExecuteCommand(a.SetStyleCommand.id,n),this}setFontLine(r){if(r==="underline")this._setFontUnderline({s:s.BooleanNumber.TRUE});else if(r==="line-through")this._setFontStrikethrough({s:s.BooleanNumber.TRUE});else if(r==="none")this._setFontUnderline({s:s.BooleanNumber.FALSE}),this._setFontStrikethrough({s:s.BooleanNumber.FALSE});else if(r===null)this._setFontUnderline(null),this._setFontStrikethrough(null);else throw new Error("Invalid fontLine");return this}_setFontUnderline(r){const e={type:"ul",value:r},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t)}_setFontStrikethrough(r){const e={type:"st",value:r},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t)}setFontFamily(r){const e={type:"ff",value:r},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t),this}setFontSize(r){const e={type:"fs",value:r},t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:e};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,t),this}setFontColor(r){const t={type:"cl",value:r===null?null:{rgb:r}},n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:t};return this._commandService.syncExecuteCommand(a.SetStyleCommand.id,n),this}merge(r=!0){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,e,t,[this._range],r),this}mergeAcross(r=!0){const e=a.getAddMergeMutationRangeByType([this._range],s.Dimension.ROWS),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,n,e,r),this}mergeVertically(r=!0){const e=a.getAddMergeMutationRangeByType([this._range],s.Dimension.COLUMNS),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return a.addMergeCellsUtil(this._injector,t,n,e,r),this}isPartOfMerge(){const{startRow:r,startColumn:e,endRow:t,endColumn:n}=this._range;return this._worksheet.getMergedCellRange(r,e,t,n).length>0}breakApart(){return this._commandService.syncExecuteCommand(a.RemoveWorksheetMergeCommand.id,{ranges:[this._range]}),this}forEach(r){const{startColumn:e,startRow:t,endColumn:n,endRow:i}=this._range;this._worksheet.getMatrixWithMergedCells(t,e,i,n).forValue((o,h,d)=>{r(o,h,d)})}getA1Notation(r,e,t){const n={...this._range,startAbsoluteRefType:e,endAbsoluteRefType:t};return r?I.serializeRangeWithSheet(this._worksheet.getName(),n):I.serializeRange(n)}activate(){return this._injector.createInstance(u.FWorkbook,this._workbook).setActiveRange(this),this}activateAsCurrentCell(){const r=this._worksheet.getMergedCell(this._range.startRow,this._range.startColumn);if(r&&s.Rectangle.equals(r,this._range)||!r&&this._range.startRow===this._range.endRow&&this._range.startColumn===this._range.endColumn){const n=this._injector.createInstance(u.FWorkbook,this._workbook).getActiveRange();if(!n||n.getUnitId()!==this.getUnitId()||n.getSheetId()!==this.getSheetId())return this.activate();if(s.Rectangle.contains(n.getRange(),this._range)){const i={unitId:this.getUnitId(),subUnitId:this.getSheetId(),selections:[{range:n.getRange(),primary:a.getPrimaryForRange(this.getRange(),this._worksheet),style:null}]};return this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,i),this}return this.activate()}else throw new Error("The range is not a single cell")}splitTextToColumns(r,e,t){this._commandService.syncExecuteCommand(a.SplitTextToColumnsCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,delimiter:e,customDelimiter:t,treatMultipleDelimitersAsOne:r})}useThemeStyle(r){if(r==null){const e=this.getUsedThemeStyle();e&&this.removeThemeStyle(e)}else this._commandService.syncExecuteCommand(a.SetWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:r})}removeThemeStyle(r){this._commandService.syncExecuteCommand(a.DeleteWorksheetRangeThemeStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,themeName:r})}getUsedThemeStyle(){return this._injector.get(a.SheetRangeThemeService).getAppliedRangeThemeStyle({unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})}clear(r){return r&&r.contentsOnly&&!r.formatOnly?this.clearContent():r&&r.formatOnly&&!r.contentsOnly?this.clearFormat():(this._commandService.syncExecuteCommand(a.ClearSelectionAllCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range],options:r}),this)}clearContent(){return this._commandService.syncExecuteCommand(a.ClearSelectionContentCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this}clearFormat(){return this._commandService.syncExecuteCommand(a.ClearSelectionFormatCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this}insertCells(r){r===s.Dimension.ROWS?this._commandService.executeCommand(a.InsertRangeMoveDownCommand.id,{range:this._range}):this._commandService.executeCommand(a.InsertRangeMoveRightCommand.id,{range:this._range})}deleteCells(r){r===s.Dimension.ROWS?this._commandService.executeCommand(a.DeleteRangeMoveUpCommand.id,{range:this._range}):this._commandService.executeCommand(a.DeleteRangeMoveLeftCommand.id,{range:this._range})}getDataRegion(r){const{startRow:e,startColumn:t,endRow:n,endColumn:i}=this._range,o=this._worksheet.getMaxRows(),h=this._worksheet.getMaxColumns(),d=this._worksheet.getCellMatrix();let l=e,m=t,g=n,_=i;if(r!==s.Dimension.COLUMNS){let k=!1,b=!1;for(let v=t;v<=i&&(e>0&&!s.isNullCell(d.getValue(e-1,v))&&(k=!0),n<o-1&&!s.isNullCell(d.getValue(n+1,v))&&(b=!0),!(k&&b));v++);k&&(l=e-1),b&&(g=n+1)}if(r!==s.Dimension.ROWS){let k=!1,b=!1;for(let v=e;v<=n&&(t>0&&!s.isNullCell(d.getValue(v,t-1))&&(k=!0),i<h-1&&!s.isNullCell(d.getValue(v,i+1))&&(b=!0),!(k&&b));v++);k&&(m=t-1),b&&(_=i+1)}return this._injector.createInstance(u.FRange,this._workbook,this._worksheet,{startRow:l,startColumn:m,endRow:g,endColumn:_})}isBlank(){const r=this._worksheet.getCellMatrix(),{startRow:e,startColumn:t,endRow:n,endColumn:i}=this._range;let o=!0;for(let h=e;h<=n;h++){for(let d=t;d<=i;d++)if(!s.isNullCell(r.getValue(h,d))){o=!1;break}if(!o)break}return o}offset(r,e,t,n){const{startRow:i,startColumn:o,endRow:h,endColumn:d}=this._range,l=i+r,m=o+e,g=t?l+t-1:h+r,_=n?m+n-1:d+e;if(l<0||m<0||g<0||_<0)throw new Error("The row or column index is out of range");return this._injector.createInstance(u.FRange,this._workbook,this._worksheet,{startRow:l,startColumn:m,endRow:g,endColumn:_})}setFormula(r){return this.setValue({f:r})}setFormulas(r){return this.setValues(r.map(e=>e.map(t=>({f:t}))))}},E._enableManualInit(),E),u.FRange=z([T(3,s.Inject(s.Injector)),T(4,s.ICommandService),T(5,s.Inject(I.FormulaDataModel))],u.FRange);var G=Object.getOwnPropertyDescriptor,$=(c,r,e,t)=>{for(var n=t>1?void 0:t?G(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},Y=(c,r)=>(e,t)=>r(e,t,c);u.FSelection=class{constructor(r,e,t,n){this._workbook=r,this._worksheet=e,this._selections=t,this._injector=n}getActiveRange(){const r=this._selections.find(e=>!!e.primary);return r?this._injector.createInstance(u.FRange,this._workbook,this._worksheet,r.range):null}getActiveRangeList(){return this._selections.map(r=>this._injector.createInstance(u.FRange,this._workbook,this._worksheet,r.range))}getCurrentCell(){const r=this._selections.find(e=>!!e.primary);return r?r.primary:null}getActiveSheet(){const r=this._injector.createInstance(u.FWorkbook,this._workbook);return this._injector.createInstance(u.FWorksheet,r,this._workbook,this._worksheet)}updatePrimaryCell(r){const e=this._injector.get(s.ICommandService);let t=[],n=!1;for(const{range:o,style:h}of this._selections)s.Rectangle.contains(o,r.getRange())?(t.push({range:o,primary:a.getPrimaryForRange(r.getRange(),this._worksheet),style:h}),n=!0):t.push({range:o,primary:null,style:h});n||(t=[{range:r.getRange(),primary:a.getPrimaryForRange(r.getRange(),this._worksheet)}]);const i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),selections:t};return e.syncExecuteCommand(a.SetSelectionsOperation.id,i),new u.FSelection(this._workbook,this._worksheet,t,this._injector)}getNextDataRange(r){if(!this._selections.find(n=>!!n.primary))return null;const t=a.getNextPrimaryCell(this._selections.concat(),r,this._worksheet);return t?this._injector.createInstance(u.FRange,this._workbook,this._worksheet,t):null}},u.FSelection=$([Y(3,s.Inject(s.Injector))],u.FSelection);var K=Object.getOwnPropertyDescriptor,q=(c,r,e,t)=>{for(var n=t>1?void 0:t?K(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},U=(c,r)=>(e,t)=>r(e,t,c);u.FWorksheet=class extends S.FBaseInitialable{constructor(e,t,n,i,o,h,d){super(i);R(this,"setActiveSelection",this.setActiveRange);this._fWorkbook=e,this._workbook=t,this._worksheet=n,this._injector=i,this._selectionManagerService=o,this._logService=h,this._commandService=d}dispose(){super.dispose(),delete this._fWorkbook,delete this._workbook,delete this._worksheet}getSheet(){return this._worksheet}getInject(){return this._injector}getWorkbook(){return this._workbook}getSheetId(){return this._worksheet.getSheetId()}getSheetName(){return this._worksheet.getName()}getSelection(){const e=this._selectionManagerService.getCurrentSelections();return e?this._injector.createInstance(u.FSelection,this._workbook,this._worksheet,e):null}getDefaultStyle(){return this._worksheet.getDefaultCellStyle()}getRowDefaultStyle(e,t=!1){return t?this._worksheet.getRowStyle(e,t):this._worksheet.getRowStyle(e)}getColumnDefaultStyle(e,t=!1){return t?this._worksheet.getColumnStyle(e,t):this._worksheet.getColumnStyle(e)}setDefaultStyle(e){const t=this._workbook.getUnitId(),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(),i=this._worksheet.getSheetId(),o={unitId:n,subUnitId:i,columnData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,o),this}setRowDefaultStyle(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={unitId:n,subUnitId:i,rowData:{[e]:{s:t}}};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,o),this}getRange(e,t,n,i){let o,h;if(typeof e=="object")o=e,h=this._worksheet;else if(typeof e=="string"){const{range:d,sheetName:l}=I.deserializeRangeWithSheet(e),m=l?this._workbook.getSheetBySheetName(l):this._worksheet;if(!m)throw new Error("Range not found");h=m,o={...d,unitId:this._workbook.getUnitId(),sheetId:h.getSheetId(),rangeType:s.RANGE_TYPE.NORMAL,startRow:d.rangeType===s.RANGE_TYPE.COLUMN?0:d.startRow,endRow:d.rangeType===s.RANGE_TYPE.COLUMN?h.getMaxRows()-1:d.endRow,startColumn:d.rangeType===s.RANGE_TYPE.ROW?0:d.startColumn,endColumn:d.rangeType===s.RANGE_TYPE.ROW?h.getMaxColumns()-1:d.endColumn}}else if(typeof e=="number"&&t!==void 0)h=this._worksheet,o={startRow:e,endRow:e+(n!=null?n:1)-1,startColumn:t,endColumn:t+(i!=null?i:1)-1,unitId:this._workbook.getUnitId(),sheetId:this._worksheet.getSheetId()};else throw new Error("Invalid range specification");return this._injector.createInstance(u.FRange,this._workbook,h,o)}getMaxColumns(){return this._worksheet.getMaxColumns()}getMaxRows(){return this._worksheet.getMaxRows()}insertRowAfter(e){return this.insertRowsAfter(e,1)}insertRowBefore(e){return this.insertRowsBefore(e,1)}insertRows(e,t=1){return this.insertRowsBefore(e,t)}insertRowsAfter(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=s.Direction.DOWN,h=e+1,d=e+t,l=0,m=this._worksheet.getColumnCount()-1,g=a.copyRangeStyles(this._worksheet,h,d,l,m,!0,e);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:n,subUnitId:i,direction:o,range:{startRow:h,endRow:d,startColumn:l,endColumn:m},cellValue:g}),this}insertRowsBefore(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=s.Direction.UP,h=e,d=e+t-1,l=0,m=this._worksheet.getColumnCount()-1,g=a.copyRangeStyles(this._worksheet,h,d,l,m,!0,e-1);return this._commandService.syncExecuteCommand(a.InsertRowByRangeCommand.id,{unitId:n,subUnitId:i,direction:o,range:{startRow:h,endRow:d,startColumn:l,endColumn:m},cellValue:g}),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(),i=this._worksheet.getSheetId(),o=P(e.getRange(),this._worksheet),h=o,d={startRow:t,endRow:t,startColumn:o.startColumn,endColumn:o.endColumn};return this._commandService.syncExecuteCommand(a.MoveRowsCommand.id,{unitId:n,subUnitId:i,range:o,fromRange:h,toRange:d}),this}hideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=P(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}hideRows(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:s.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetRowHiddenCommand.id,{unitId:n,subUnitId:i,ranges:[o]}),this}unhideRow(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=P(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}showRows(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1,rangeType:s.RANGE_TYPE.ROW};return this._commandService.syncExecuteCommand(a.SetSpecificRowsVisibleCommand.id,{unitId:n,subUnitId:i,ranges:[o]}),this}setRowHeight(e,t){return this.setRowHeights(e,1,t)}autoFitRow(e,t=s.BooleanNumber.TRUE){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=[{startRow:e,endRow:e,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetTextWrapCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:o[0],value:s.WrapStrategy.WRAP}),this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightMutation.id,{unitId:n,subUnitId:i,ranges:o,autoHeightInfo:t}),this}setRowHeights(e,t,n){var m;const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=this._worksheet.getRowManager(),d=[],l=[];for(let g=e;g<e+t;g++){const _=((m=h.getRow(g))==null?void 0:m.ah)||this._worksheet.getConfig().defaultRowHeight,k={startRow:g,endRow:g,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};n<=_?d.push(k):l.push(k)}return l.length>0&&this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:i,subUnitId:o,ranges:l,value:n}),d.length>0&&this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:i,subUnitId:o,ranges:d}),this}getRowHeight(e){return this._worksheet.getRowHeight(e)}setRowAutoHeight(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:n,subUnitId:i,ranges:o}),this}setRangesAutoHeight(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return this._commandService.syncExecuteCommand(a.SetWorksheetRowIsAutoHeightCommand.id,{unitId:t,subUnitId:n,ranges:e}),this}setRowHeightsForced(e,t,n){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=[{startRow:e,endRow:e+t-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}];return this._commandService.syncExecuteCommand(a.SetRowHeightCommand.id,{unitId:i,subUnitId:o,ranges:h,value:n}),this}setRowCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i={};for(const[h,d]of Object.entries(e))i[Number(h)]={custom:d};const o={unitId:t,subUnitId:n,rowData:i};return this._commandService.syncExecuteCommand(a.SetRowDataCommand.id,o),this}insertColumnAfter(e){return this.insertColumnsAfter(e,1)}insertColumnBefore(e){return this.insertColumnsBefore(e,1)}insertColumns(e,t=1){return this.insertColumnsBefore(e,t)}insertColumnsAfter(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=s.Direction.RIGHT,h=0,d=this._worksheet.getRowCount()-1,l=e+1,m=e+t,g=a.copyRangeStyles(this._worksheet,h,d,l,m,!1,e);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:n,subUnitId:i,direction:o,range:{startRow:h,endRow:d,startColumn:l,endColumn:m},cellValue:g}),this}insertColumnsBefore(e,t){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o=s.Direction.LEFT,h=0,d=this._worksheet.getRowCount()-1,l=e,m=e+t-1,g=a.copyRangeStyles(this._worksheet,h,d,l,m,!1,e-1);return this._commandService.syncExecuteCommand(a.InsertColByRangeCommand.id,{unitId:n,subUnitId:i,direction:o,range:{startRow:h,endRow:d,startColumn:l,endColumn:m},cellValue:g}),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(),i=this._worksheet.getSheetId(),o=N(e.getRange(),this._worksheet),h=o,d={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:t,endColumn:t};return this._commandService.syncExecuteCommand(a.MoveColsCommand.id,{unitId:n,subUnitId:i,range:o,fromRange:h,toRange:d}),this}hideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=N(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}hideColumns(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:s.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetColHiddenCommand.id,{unitId:n,subUnitId:i,ranges:[o]}),this}unhideColumn(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=N(e.getRange(),this._worksheet);return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:t,subUnitId:n,ranges:[i]}),this}showColumns(e,t=1){const n=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:e,endColumn:e+t-1,rangeType:s.RANGE_TYPE.COLUMN};return this._commandService.syncExecuteCommand(a.SetSpecificColsVisibleCommand.id,{unitId:n,subUnitId:i,ranges:[o]}),this}setColumnWidth(e,t){return this.setColumnWidths(e,1,t)}setColumnWidths(e,t,n){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),h=[{startColumn:e,endColumn:e+t-1,startRow:0,endRow:this._worksheet.getRowCount()-1}];return this._commandService.syncExecuteCommand(a.SetColWidthCommand.id,{unitId:i,subUnitId:o,ranges:h,value:n}),this}getColumnWidth(e){return this._worksheet.getColumnWidth(e)}setColumnCustom(e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i={};for(const[h,d]of Object.entries(e))i[Number(h)]={custom:d};const o={unitId:t,subUnitId:n,columnData:i};return this._commandService.syncExecuteCommand(a.SetColDataCommand.id,o),this}getMergeData(){return this._worksheet.getMergeData().map(e=>this._injector.createInstance(u.FRange,this._workbook,this._worksheet,e))}getMergedRanges(){return this._worksheet.getSnapshot().mergeData.map(t=>this._injector.createInstance(u.FRange,this._workbook,this._worksheet,t))}getCellMergeData(e,t){const i=this._worksheet.getMergedCell(e,t);if(i)return this._injector.createInstance(u.FRange,this._workbook,this._worksheet,i)}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.");return this._fWorkbook.setActiveRange(e),this}getActiveCell(){return this._fWorkbook.getActiveCell()}setFreeze(e){return this._logService.warn("setFreeze is deprecated, use setFrozenRows and setFrozenColumns instead"),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{...e,unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}cancelFreeze(){return this._commandService.syncExecuteCommand(a.CancelFrozenCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this.getSheetId()}),this}getFreeze(){return this._worksheet.getFreeze()}setFrozenColumns(...e){const t=this.getFreeze();if(arguments.length===1){const n=e[0];this.setFreeze({...t,startColumn:n>0?n:-1,xSplit:n})}else if(arguments.length===2){let[n=0,i=0]=e;n>i&&([n,i]=[i,n]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startColumn:i+1,xSplit:i-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,i=0]=e;n>i&&([n,i]=[i,n]),this._commandService.syncExecuteCommand(a.SetFrozenCommand.id,{startRow:i+1,ySplit:i-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===s.BooleanNumber.FALSE}setHiddenGridlines(e){return this._commandService.syncExecuteCommand(a.ToggleGridlinesCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),showGridlines:e?s.BooleanNumber.FALSE:s.BooleanNumber.TRUE}),this}setGridLinesColor(e){return this._commandService.syncExecuteCommand(a.SetGridlinesColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),color:e}),this}getGridLinesColor(){return this._worksheet.getGridlinesColor()}setTabColor(e){return this._commandService.syncExecuteCommand(a.SetTabColorCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),value:e}),this}getTabColor(){return this._worksheet.getTabColor()}onCellDataChange(e){return this._injector.get(s.ICommandService).onCommandExecuted(n=>{if(n.id===a.SetRangeValuesMutation.id){const i=n.params;i.unitId===this._workbook.getUnitId()&&i.subUnitId===this._worksheet.getSheetId()&&i.cellValue&&e(new s.ObjectMatrix(i.cellValue))}})}onBeforeCellDataChange(e){return this._injector.get(s.ICommandService).beforeCommandExecuted(n=>{if(n.id===a.SetRangeValuesMutation.id){const i=n.params;i.unitId===this._workbook.getUnitId()&&i.subUnitId===this._worksheet.getSheetId()&&i.cellValue&&e(new s.ObjectMatrix(i.cellValue))}})}hideSheet(){const e=this._injector.get(s.ICommandService);if(this._workbook.getSheets().filter(o=>o.isSheetHidden()!==s.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(s.ICommandService).syncExecuteCommand(a.SetWorksheetShowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()}),this}isSheetHidden(){return this._worksheet.isSheetHidden()===s.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(),i=this._injector.get(s.ICommandService),o={startRow:0,endRow:this._worksheet.getRowCount()-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1};return i.syncExecuteCommand(a.ClearSelectionAllCommand.id,{unitId:t,subUnitId:n,ranges:[o],options:e}),this}clearContents(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),n=this._injector.get(s.ICommandService),i={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:[i]}),this}clearFormats(){const e=this._workbook.getUnitId(),t=this._worksheet.getSheetId(),n=this._injector.get(s.ICommandService),i={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:[i]}),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 u.FWorksheet?this._worksheet.getSheetId()===e.getSheetId()&&this._workbook.getUnitId()===e.getWorkbook().getUnitId():!1}insertDefinedName(e,t){const i=this._injector.createInstance(y).setName(e).setRef(t).build();i.localSheetId=this.getSheetId(),this._fWorkbook.insertDefinedNameBuilder(i)}getDefinedNames(){return this._fWorkbook.getDefinedNames().filter(t=>t.getLocalSheetId()===this.getSheetId())}setCustomMetadata(e){return this._worksheet.setCustomMetadata(e),this}getCustomMetadata(){return this._worksheet.getCustomMetadata()}setRowCustomMetadata(e,t){return this._worksheet.getRowManager().setCustomMetadata(e,t),this}setColumnCustomMetadata(e,t){return this._worksheet.getColumnManager().setCustomMetadata(e,t),this}getRowCustomMetadata(e){return this._worksheet.getRowManager().getCustomMetadata(e)}getColumnCustomMetadata(e){return this._worksheet.getColumnManager().getCustomMetadata(e)}appendRow(e){const t=this._worksheet.getCellMatrix().hasValue(),n=this._worksheet.getLastRowWithContent(),i=this._worksheet.getRowCount(),o=this._worksheet.getColumnCount(),h=t?n+1:n,d=new s.ObjectMatrix;for(let l=0;l<e.length;l++)d.setValue(h,l,s.covertCellValue(e[l]));return this._commandService.syncExecuteCommand(a.AppendRowCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cellValue:d.getMatrix(),insertRowNums:h>i-1?1:0,insertColumnNums:e.length>o?e.length-o:0,maxRows:i,maxColumns:o}),this}setRowCount(e){return this._commandService.syncExecuteCommand(a.SetWorksheetRowCountCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rowCount:e}),this}setColumnCount(e){return this._commandService.syncExecuteCommand(a.SetWorksheetColumnCountCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),columnCount:e}),this}},u.FWorksheet=q([U(3,s.Inject(s.Injector)),U(4,s.Inject(a.SheetsSelectionsService)),U(5,s.Inject(s.ILogService)),U(6,s.ICommandService)],u.FWorksheet);var J=Object.getOwnPropertyDescriptor,Q=(c,r,e,t)=>{for(var n=t>1?void 0:t?J(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},C=(c,r)=>(e,t)=>r(e,t,c);u.FWorkbook=class extends S.FBaseInitialable{constructor(e,t,n,i,o,h,d,l,m,g){super(t);R(this,"id");this._workbook=e,this._injector=t,this._resourceLoaderService=n,this._selectionManagerService=i,this._univerInstanceService=o,this._commandService=h,this._permissionService=d,this._logService=l,this._localeService=m,this._definedNamesService=g,this.id=this._workbook.getUnitId()}getWorkbook(){return this._workbook}dispose(){super.dispose(),this._workbook=null}getId(){return this.id}getName(){return this._workbook.name}setName(e){return this._commandService.syncExecuteCommand(a.SetWorkbookNameCommand.id,{unitId:this._workbook.getUnitId(),name:e}),this}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(u.FWorksheet,this,this._workbook,e)}getSheets(){return this._workbook.getSheets().map(e=>this._injector.createInstance(u.FWorksheet,this,this._workbook,e))}create(e,t,n,i){var l,m,g;const o=s.mergeWorksheetSnapshotWithDefault(s.Tools.deepClone((l=i==null?void 0:i.sheet)!=null?l:{}));o.name=e,o.rowCount=t,o.columnCount=n,o.id=(m=i==null?void 0:i.sheet)==null?void 0:m.id;const h=(g=i==null?void 0:i.index)!=null?g:this._workbook.getSheets().length;this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{unitId:this.id,index:h,sheet:o}),this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[h].getSheetId()});const d=this._workbook.getActiveSheet();if(!d)throw new Error("No active sheet found");return this._injector.createInstance(u.FWorksheet,this,this._workbook,d)}getSheetBySheetId(e){const t=this._workbook.getSheetBySheetId(e);return t?this._injector.createInstance(u.FWorksheet,this,this._workbook,t):null}getSheetByName(e){const t=this._workbook.getSheetBySheetName(e);return t?this._injector.createInstance(u.FWorksheet,this,this._workbook,t):null}setActiveSheet(e){return this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:typeof e=="string"?e:e.getSheetId()}),typeof e=="string"?this.getSheetBySheetId(e):e}insertSheet(e,t){var h,d,l;const n=s.mergeWorksheetSnapshotWithDefault(s.Tools.deepClone((h=t==null?void 0:t.sheet)!=null?h:{}));n.name=e,n.id=(d=t==null?void 0:t.sheet)==null?void 0:d.id;const i=(l=t==null?void 0:t.index)!=null?l:this._workbook.getSheets().length;this._commandService.syncExecuteCommand(a.InsertSheetCommand.id,{unitId:this.id,index:i,sheet:n}),this._commandService.syncExecuteCommand(a.SetWorksheetActiveOperation.id,{unitId:this.id,subUnitId:this._workbook.getSheets()[i].getSheetId()});const o=this._workbook.getActiveSheet();if(!o)throw new Error("No active sheet found");return this._injector.createInstance(u.FWorksheet,this,this._workbook,o)}deleteSheet(e){const t=this.id,n=typeof e=="string"?e:e.getSheetId();return this._commandService.syncExecuteCommand(a.RemoveSheetCommand.id,{unitId:t,subUnitId:n})}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(s.UndoCommand.id),this}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.syncExecuteCommand(s.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 s.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(t=>{this._univerInstanceService.getCurrentUnitForType(s.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());return this._permissionService.getPermissionPoint(t.id)||this._permissionService.addPermissionPoint(t),this._permissionService.updatePermissionPoint(t.id,e),this}setActiveRange(e){const t=this.getActiveSheet(),n=e.getRange().sheetId||t.getSheetId(),i=n?this._workbook.getSheetBySheetId(n):this._workbook.getActiveSheet(!0);if(!i)throw new Error("No active sheet found");i.getSheetId()!==t.getSheetId()&&this.setActiveSheet(this._injector.createInstance(u.FWorksheet,this,this._workbook,i));const o={unitId:this.getId(),subUnitId:n,selections:[e].map(h=>({range:h.getRange(),primary:a.getPrimaryForRange(h.getRange(),i),style:null}))};return this._commandService.syncExecuteCommand(a.SetSelectionsOperation.id,o),this}getActiveRange(){const e=this._workbook.getActiveSheet(),n=this._selectionManagerService.getCurrentSelections().find(i=>!!i.primary);return n?this._injector.createInstance(u.FRange,this._workbook,e,n.range):null}getActiveCell(){const e=this._workbook.getActiveSheet(),n=this._selectionManagerService.getCurrentSelections().find(o=>!!o.primary);if(!n)return null;const i={...n.primary,rangeType:s.RANGE_TYPE.NORMAL};return this._injector.createInstance(u.FRange,this._workbook,e,i)}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(u.FWorksheet,this,this._workbook,this._workbook.getActiveSheet())}duplicateActiveSheet(){const e=this.getActiveSheet();return this.duplicateSheet(e)}getNumSheets(){return this._workbook.getSheets().length}getLocale(){return this._localeService.getCurrentLocale()}setLocale(e){this._localeService.setLocale(e)}setSpreadsheetLocale(e){return this._localeService.setLocale(e),this}getUrl(){return location.href}moveSheet(e,t){let 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(u.FPermission)}getDefinedName(e){const t=this._definedNamesService.getValueByName(this.id,e);return t?this._injector.createInstance(p,{...t,unitId:this.id}):null}getDefinedNames(){const e=this._definedNamesService.getDefinedNameMap(this.id);return e?Object.values(e).map(t=>this._injector.createInstance(p,{...t,unitId:this.id})):[]}insertDefinedName(e,t){const i=this._injector.createInstance(y).setName(e).setRef(t).build();return i.localSheetId=a.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,this.insertDefinedNameBuilder(i),this}deleteDefinedName(e){const t=this.getDefinedName(e);return t?(t.delete(),!0):!1}insertDefinedNameBuilder(e){e.unitId=this.getId(),this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}updateDefinedNameBuilder(e){this._commandService.syncExecuteCommand(a.SetDefinedNameCommand.id,e)}getRegisteredRangeThemes(){return this._injector.get(a.SheetRangeThemeService).getRegisteredRangeThemes()}registerRangeTheme(e){this._commandService.syncExecuteCommand(a.RegisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),rangeThemeStyle:e})}unregisterRangeTheme(e){this._commandService.syncExecuteCommand(a.UnregisterWorksheetRangeThemeStyleCommand.id,{unitId:this.getId(),themeName:e})}createRangeThemeStyle(e,t){return new a.RangeThemeStyle(e,t)}setCustomMetadata(e){return this._workbook.setCustomMetadata(e),this}getCustomMetadata(){return this._workbook.getCustomMetadata()}addStyles(e){this._workbook.addStyles(e)}removeStyles(e){this._workbook.removeStyles(e)}},u.FWorkbook=Q([C(1,s.Inject(s.Injector)),C(2,s.Inject(s.IResourceLoaderService)),C(3,s.Inject(a.SheetsSelectionsService)),C(4,s.IUniverInstanceService),C(5,s.ICommandService),C(6,s.IPermissionService),C(7,s.ILogService),C(8,s.Inject(s.LocaleService)),C(9,I.IDefinedNamesService)],u.FWorkbook);class X extends S.FUniver{getCommandSheetTarget(r){var i;const e=r.params;if(!e)return this.getActiveSheet();const t=e.unitId?this.getUniverSheet(e.unitId):(i=this.getActiveWorkbook)==null?void 0:i.call(this);if(!t)return;const n=t.getSheetBySheetId(e.subUnitId||e.sheetId)||t.getActiveSheet();if(n)return{workbook:t,worksheet:n}}getSheetTarget(r,e){const t=this.getUniverSheet(r);if(!t)return;const n=t.getSheetBySheetId(e);if(n)return{workbook:t,worksheet:n}}_initWorkbookEvent(r){const e=r.get(s.IUniverInstanceService);this.registerEventHandler(this.Event.WorkbookDisposed,()=>e.unitDisposed$.subscribe(t=>{t.type===s.UniverInstanceType.UNIVER_SHEET&&this.fireEvent(this.Event.WorkbookDisposed,{unitId:t.getUnitId(),unitType:t.type,snapshot:t.getSnapshot()})})),this.registerEventHandler(this.Event.WorkbookCreated,()=>e.unitAdded$.subscribe(t=>{if(t.type===s.UniverInstanceType.UNIVER_SHEET){const n=t,i=r.createInstance(u.FWorkbook,n);this.fireEvent(this.Event.WorkbookCreated,{unitId:t.getUnitId(),type:t.type,workbook:i,unit:i})}}))}_initialize(r){const e=r.get(s.ICommandService);this.registerEventHandler(this.Event.BeforeSheetCreate,()=>e.beforeCommandExecuted(t=>{var n;if(t.id===a.InsertSheetCommand.id){const i=t.params,{unitId:o,index:h,sheet:d}=i||{},l=o?this.getUniverSheet(o):(n=this.getActiveWorkbook)==null?void 0:n.call(this);if(!l)return;const m={workbook:l,index:h,sheet:d};if(this.fireEvent(this.Event.BeforeSheetCreate,m),m.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeActiveSheetChange,()=>e.beforeCommandExecuted(t=>{var n;if(t.id===a.SetWorksheetActiveOperation.id){const{subUnitId:i,unitId:o}=t.params,h=o?this.getUniverSheet(o):(n=this.getActiveWorkbook)==null?void 0:n.call(this);if(!h||!i)return;const d=h.getSheetBySheetId(i),l=h.getActiveSheet();if(!d||!l)return;const m={workbook:h,activeSheet:d,oldActiveSheet:l};if(this.fireEvent(this.Event.BeforeActiveSheetChange,m),m.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDelete,()=>e.beforeCommandExecuted(t=>{if(t.id===a.RemoveSheetCommand.id){const n=this.getCommandSheetTarget(t);if(!n)return;const{workbook:i,worksheet:o}=n,h={workbook:i,worksheet:o};if(this.fireEvent(this.Event.BeforeSheetDelete,h),h.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetMove,()=>e.beforeCommandExecuted(t=>{if(t.id===a.SetWorksheetOrderMutation.id){const{fromOrder:n,toOrder:i}=t.params,o=this.getCommandSheetTarget(t);if(!o)return;const h={workbook:o.workbook,worksheet:o.worksheet,newIndex:i,oldIndex:n};if(this.fireEvent(this.Event.BeforeSheetMove,h),h.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetNameChange,()=>e.beforeCommandExecuted(t=>{if(t.id===a.SetWorksheetNameCommand.id){const{name:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;const o={workbook:i.workbook,worksheet:i.worksheet,newName:n,oldName:i.worksheet.getSheetName()};if(this.fireEvent(this.Event.BeforeSheetNameChange,o),o.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetTabColorChange,()=>e.beforeCommandExecuted(t=>{if(t.id===a.SetTabColorMutation.id){const{color:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;const o={workbook:i.workbook,worksheet:i.worksheet,newColor:n,oldColor:i.worksheet.getTabColor()};if(this.fireEvent(this.Event.BeforeSheetTabColorChange,o),o.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetHideChange,()=>e.beforeCommandExecuted(t=>{if(t.id===a.SetWorksheetHideMutation.id){const{hidden:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;const o={workbook:i.workbook,worksheet:i.worksheet,hidden:!!n};if(this.fireEvent(this.Event.BeforeSheetHideChange,o),o.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeGridlineColorChange,()=>e.beforeCommandExecuted(t=>{var n;if(t.id===a.SetGridlinesColorCommand.id){const i=this.getCommandSheetTarget(t);if(!i)return;const o={...i,color:(n=t.params)==null?void 0:n.color};if(this.fireEvent(this.Event.BeforeGridlineColorChange,o),o.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeGridlineEnableChange,()=>e.beforeCommandExecuted(t=>{var n;if(t.id===a.ToggleGridlinesCommand.id){const i=this.getCommandSheetTarget(t);if(!i)return;const o={...i,enabled:!!((n=t.params)!=null&&n.showGridlines)};if(this.fireEvent(this.Event.BeforeGridlineEnableChange,o),o.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.SheetValueChanged,()=>e.onCommandExecuted(t=>{if(a.COMMAND_LISTENER_VALUE_CHANGE.indexOf(t.id)>-1){if(!this.getActiveSheet())return;const i=a.getValueChangedEffectedRange(t).map(o=>{var h,d;return(d=(h=this.getWorkbook(o.unitId))==null?void 0:h.getSheetBySheetId(o.subUnitId))==null?void 0:d.getRange(o.range)}).filter(Boolean);if(!i.length)return;this.fireEvent(this.Event.SheetValueChanged,{payload:t,effectedRanges:i})}})),this.registerEventHandler(this.Event.SheetCreated,()=>e.onCommandExecuted(t=>{var n;if(t.id===a.InsertSheetCommand.id){const i=t.params,{unitId:o}=i||{},h=o?this.getUniverSheet(o):(n=this.getActiveWorkbook)==null?void 0:n.call(this);if(!h)return;const d=h.getActiveSheet();if(!d)return;const l={workbook:h,worksheet:d};this.fireEvent(this.Event.SheetCreated,l)}})),this.registerEventHandler(this.Event.ActiveSheetChanged,()=>e.onCommandExecuted(t=>{if(t.id===a.SetWorksheetActiveOperation.id){const n=this.getActiveSheet();if(!n)return;const{workbook:i,worksheet:o}=n;this._fireActiveSheetChanged(i,o)}})),this.registerEventHandler(this.Event.SheetDeleted,()=>e.onCommandExecuted(t=>{var n;if(t.id===a.RemoveSheetCommand.id){const{subUnitId:i,unitId:o}=t.params,h=o?this.getUniverSheet(o):(n=this.getActiveWorkbook)==null?void 0:n.call(this);if(!h||!i)return;this._fireSheetDeleted(h,i)}})),this.registerEventHandler(this.Event.SheetMoved,()=>e.onCommandExecuted(t=>{if(t.id===a.SetWorksheetOrderMutation.id){const{toOrder:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;this._fireSheetMoved(i.workbook,i.worksheet,n)}})),this.registerEventHandler(this.Event.SheetNameChanged,()=>e.onCommandExecuted(t=>{if(t.id===a.SetWorksheetNameCommand.id){const{name:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;this._fireSheetNameChanged(i.workbook,i.worksheet,n)}})),this.registerEventHandler(this.Event.SheetTabColorChanged,()=>e.onCommandExecuted(t=>{if(t.id===a.SetTabColorMutation.id){const{color:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;this._fireSheetTabColorChanged(i.workbook,i.worksheet,n)}})),this.registerEventHandler(this.Event.SheetHideChanged,()=>e.onCommandExecuted(t=>{if(t.id===a.SetWorksheetHideMutation.id){const{hidden:n}=t.params,i=this.getCommandSheetTarget(t);if(!i)return;this._fireSheetHideChanged(i.workbook,i.worksheet,!!n)}})),this.registerEventHandler(this.Event.GridlineChanged,()=>e.onCommandExecuted(t=>{if(t.id===a.SetGridlinesColorCommand.id||t.id===a.ToggleGridlinesCommand.id){const n=this.getCommandSheetTarget(t);if(!n)return;this.fireEvent(this.Event.GridlineChanged,{...n,enabled:!n.worksheet.hasHiddenGridLines(),color:n.worksheet.getGridLinesColor()})}})),this._initWorkbookEvent(r)}createUniverSheet(r,e){const n=this._injector.get(s.IUniverInstanceService).createUnit(s.UniverInstanceType.UNIVER_SHEET,r,e);return this._injector.createInstance(u.FWorkbook,n)}createWorkbook(r,e){return this.createUniverSheet(r,e)}getActiveWorkbook(){const r=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);return r?this._injector.createInstance(u.FWorkbook,r):null}getActiveUniverSheet(){return this.getActiveWorkbook()}getUniverSheet(r){const e=this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_SHEET);return e?this._injector.createInstance(u.FWorkbook,e):null}getWorkbook(r){return this.getUniverSheet(r)}getPermission(){return this._injector.createInstance(u.FPermission)}onUniverSheetCreated(r){const e=this._univerInstanceService.getTypeOfUnitAdded$(s.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{const n=this._injector.createInstance(u.FWorkbook,t);r(n)});return s.toDisposable(e)}newDefinedName(){return this._injector.createInstance(y)}getActiveSheet(){const r=this.getActiveWorkbook();if(!r)return null;const e=r.getActiveSheet();return e?{workbook:r,worksheet:e}:null}setFreezeSync(r){this._injector.get(a.SheetsFreezeSyncController).setEnabled(r)}_fireActiveSheetChanged(r,e){this.fireEvent(this.Event.ActiveSheetChanged,{workbook:r,activeSheet:e})}_fireSheetDeleted(r,e){this.fireEvent(this.Event.SheetDeleted,{workbook:r,sheetId:e})}_fireSheetMoved(r,e,t){this.fireEvent(this.Event.SheetMoved,{workbook:r,worksheet:e,newIndex:t})}_fireSheetNameChanged(r,e,t){this.fireEvent(this.Event.SheetNameChanged,{workbook:r,worksheet:e,newName:t})}_fireSheetTabColorChanged(r,e,t){this.fireEvent(this.Event.SheetTabColorChanged,{workbook:r,worksheet:e,newColor:t})}_fireSheetHideChanged(r,e,t){this.fireEvent(this.Event.SheetHideChanged,{workbook:r,worksheet:e,hidden:t})}}S.FUniver.extend(X);class M{get SheetValueChangeType(){return a.SheetValueChangeType}get SheetSkeletonChangeType(){return a.SheetSkeletonChangeType}get SplitDelimiterType(){return a.SplitDelimiterEnum}}S.FEnum.extend(M);class F{get SheetCreated(){return"SheetCreated"}get BeforeSheetCreate(){return"BeforeSheetCreate"}get WorkbookCreated(){return"WorkbookCreated"}get WorkbookDisposed(){return"WorkbookDisposed"}get GridlineChanged(){return"GridlineChanged"}get BeforeGridlineEnableChange(){return"BeforeGridlineEnableChange"}get BeforeGridlineColorChange(){return"BeforeGridlineColorChange"}get BeforeActiveSheetChange(){return"BeforeActiveSheetChange"}get ActiveSheetChanged(){return"ActiveSheetChanged"}get SheetDeleted(){return"SheetDeleted"}get BeforeSheetDelete(){return"BeforeSheetDelete"}get SheetMoved(){return"SheetMoved"}get BeforeSheetMove(){return"BeforeSheetMove"}get SheetNameChanged(){return"SheetNameChanged"}get BeforeSheetNameChange(){return"BeforeSheetNameChange"}get SheetTabColorChanged(){return"SheetTabColorChanged"}get BeforeSheetTabColorChange(){return"BeforeSheetTabColorChange"}get SheetHideChanged(){return"SheetHideChanged"}get BeforeSheetHideChange(){return"BeforeSheetHideChange"}get SheetValueChanged(){return"SheetValueChanged"}}S.FEventName.extend(F);var Z=Object.getOwnPropertyDescriptor,ee=(c,r,e,t)=>{for(var n=t>1?void 0:t?Z(r,e):r,i=c.length-1,o;i>=0;i--)(o=c[i])&&(n=o(n)||n);return n},te=(c,r)=>(e,t)=>r(e,t,c);u.FSheetHooks=class extends S.FBase{constructor(r){super(),this._injector=r}},u.FSheetHooks=ee([te(0,s.Inject(s.Injector))],u.FSheetHooks),u.FSheetEventName=F,u.FSheetsEnum=M,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
// @univerjs/sheets-numfmt/index
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
// @univerjs/sheets-numfmt/facade
|
|
24
|
-
(function(s,o){typeof exports=="object"&&typeof module<"u"?o(require("@univerjs/sheets-numfmt"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["@univerjs/sheets-numfmt","@univerjs/sheets/facade"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s.UniverSheetsNumfmt,s.UniverSheetsFacade))})(this,(function(s,o){"use strict";class
|
|
24
|
+
(function(s,o){typeof exports=="object"&&typeof module<"u"?o(require("@univerjs/sheets-numfmt"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["@univerjs/sheets-numfmt","@univerjs/sheets/facade"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s.UniverSheetsNumfmt,s.UniverSheetsFacade))})(this,(function(s,o){"use strict";class h extends o.FRange{setNumberFormat(n){const e=[],{startColumn:t,startRow:m,endColumn:u,endRow:a}=this._range;for(let i=m;i<=a;i++)for(let r=t;r<=u;r++)e.push({row:i,col:r,pattern:n});return this._commandService.syncExecuteCommand(s.SetNumfmtCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),values:e}),this}setNumberFormats(n){var i;const e=[],{startColumn:t,startRow:m,endColumn:u,endRow:a}=this._range;for(let r=m;r<=a;r++)for(let d=t;d<=u;d++){const f=(i=n[r-m])==null?void 0:i[d-t];e.push({row:r,col:d,pattern:f})}return this._commandService.syncExecuteCommand(s.SetNumfmtCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),values:e}),this}getNumberFormat(){var e,t;const n=this.getCellStyle();return(t=(e=n==null?void 0:n.numberFormat)==null?void 0:e.pattern)!=null?t:""}getNumberFormats(){return this.getCellStyles().map(e=>e.map(t=>{var m,u;return(u=(m=t==null?void 0:t.numberFormat)==null?void 0:m.pattern)!=null?u:""}))}}o.FRange.extend(h);class c extends o.FWorkbook{setNumfmtLocal(n){return this._injector.get(s.SheetsNumfmtCellContentController).setNumfmtLocal(n),this}}o.FWorkbook.extend(c)}));
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
// @univerjs/sheets-data-validation/index
|
|
28
|
-
(function(m,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/sheets-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/sheets","rxjs","@univerjs/sheets-formula"],r):(m=typeof globalThis<"u"?globalThis:m||self,r(m.UniverSheetsDataValidation={},m.UniverCore,m.UniverDataValidation,m.UniverEngineFormula,m.UniverSheets,m.rxjs,m.UniverSheetsFormula))})(this,(function(m,r,p,y,D,U,Z){"use strict";var It=Object.defineProperty;var Ct=(m,r,p)=>r in m?It(m,r,{enumerable:!0,configurable:!0,writable:!0,value:p}):m[r]=p;var _=(m,r,p)=>Ct(m,typeof r!="symbol"?r+"":r,p);var He=Object.getOwnPropertyDescriptor,We=(o,s,e,t)=>{for(var a=t>1?void 0:t?He(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},de=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCacheService=class extends r.Disposable{constructor(e,t,a){super();_(this,"_cacheMatrix",new Map);_(this,"_dirtyRanges$",new U.Subject);_(this,"dirtyRanges$",this._dirtyRanges$.asObservable());this._commandService=e,this._univerInstanceService=t,this._sheetDataValidationModel=a,this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.SetRangeValuesMutation.id){const{cellValue:t,unitId:a,subUnitId:i}=e.params;if(t){const n=new r.ObjectMatrix(t).getDataRange();if(n.endRow===-1)return;const d=this._sheetDataValidationModel.getRules(a,i).map(c=>c.ranges).flat().map(c=>r.getIntersectRange(c,n)).filter(Boolean);d.length&&this.markRangeDirty(a,i,d,!0)}}}))}_initSheetRemove(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t;if(e.id===D.RemoveSheetMutation.id){const{unitId:a,subUnitId:i}=e.params;(t=this._cacheMatrix.get(a))==null||t.delete(i)}})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{e.type===r.UniverInstanceType.UNIVER_SHEET&&this._cacheMatrix.delete(e.getUnitId())}))}_ensureCache(e,t){let a=this._cacheMatrix.get(e);a||(a=new Map,this._cacheMatrix.set(e,a));let i=a.get(t);return i||(i=new r.ObjectMatrix,a.set(t,i)),i}ensureCache(e,t){return this._ensureCache(e,t)}addRule(e,t,a){this.markRangeDirty(e,t,a.ranges)}removeRule(e,t,a){this._deleteRange(e,t,a.ranges)}markRangeDirty(e,t,a,i){const n=this._ensureCache(e,t);a.forEach(l=>{r.Range.foreach(l,(u,d)=>{n.getValue(u,d)!==void 0&&n.setValue(u,d,void 0)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a,isSetRange:i})}_deleteRange(e,t,a){const i=this._ensureCache(e,t);a.forEach(n=>{r.Range.foreach(n,(l,u)=>{i.realDeleteValue(l,u)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a})}getValue(e,t,a,i){return this._ensureCache(e,t).getValue(a,i)}},m.DataValidationCacheService=We([de(0,r.Inject(r.ICommandService)),de(1,r.Inject(r.IUniverInstanceService)),de(2,r.Inject(p.DataValidationModel))],m.DataValidationCacheService);function w(o){var s,e;return(e=(s=o==null?void 0:o[0])==null?void 0:s[0])==null?void 0:e.v}function j(o){var s;return(s=o==null?void 0:o[0])==null?void 0:s[0]}function E(o){return!y.ERROR_TYPE_SET.has(o)}function P(o,s){var t;const e=s.getValidatorItem(o);return(t=e==null?void 0:e.offsetFormulaByRange)!=null?t:!1}var $e=Object.getOwnPropertyDescriptor,ke=(o,s,e,t)=>{for(var a=t>1?void 0:t?$e(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},H=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCustomFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();_(this,"_ruleFormulaMap",new Map);_(this,"_ruleFormulaMap2",new Map);this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=a,this._dataValidationCacheService=i,this._validatorRegistryService=n,this._initFormulaResultHandler(),this._initDirtyRanges()}dispose(){super.dispose(),this._ruleFormulaMap.clear(),this._ruleFormulaMap2.clear()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(const t in e){const a=e[t];if(this._instanceSrv.getUnitType(t)===r.UniverInstanceType.UNIVER_SHEET)for(const n in a){const l=a[n],{ruleFormulaMap:u}=this._ensureMaps(t,n);l.forEach(d=>{var g,S;const c=u.get((g=d.extra)==null?void 0:g.ruleId),h=this._dataValidationModel.getRuleById(t,n,(S=d.extra)==null?void 0:S.ruleId);h&&c&&this._dataValidationCacheService.markRangeDirty(t,n,h.ranges)})}}}))}_ensureMaps(e,t){let a=this._ruleFormulaMap.get(e),i=this._ruleFormulaMap2.get(e);a||(a=new Map,this._ruleFormulaMap.set(e,a)),i||(i=new Map,this._ruleFormulaMap2.set(e,i));let n=a.get(t);n||(n=new Map,a.set(t,n));let l=i.get(t);return l||(l=new Map,i.set(t,l)),{ruleFormulaMap:n,ruleFormulaMap2:l}}_registerFormula(e,t,a,i,n){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,i,n,{ruleId:a})}_handleDirtyRanges(e,t,a){this._dataValidationModel.getRules(e,t).forEach(n=>{const l=n.ranges;r.Rectangle.doAnyRangesIntersect(l,a)&&this.makeRuleDirty(e,t,n.uid)})}_initDirtyRanges(){this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.subscribe(e=>{e.isSetRange&&this._handleDirtyRanges(e.unitId,e.subUnitId,e.ranges)}))}deleteByRuleId(e,t,a){const{ruleFormulaMap:i,ruleFormulaMap2:n}=this._ensureMaps(e,t),l=this._dataValidationModel.getRuleById(e,t,a),u=i.get(a);if(!l||!u)return;const d=i.get(a);d&&(i.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[d.formulaId]));const c=n.get(a);c&&(n.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[c.formulaId]))}_addFormulaByRange(e,t,a,i,n,l){const{ruleFormulaMap:u,ruleFormulaMap2:d}=this._ensureMaps(e,t),c=l[0].startRow,h=l[0].startColumn;if(i&&r.isFormulaString(i)){const g=this._registerFormula(e,t,a,i,l);u.set(a,{formula:i,originCol:h,originRow:c,formulaId:g})}if(n&&r.isFormulaString(n)){const g=this._registerFormula(e,t,a,n,l);d.set(a,{formula:n,originCol:h,originRow:c,formulaId:g})}}addRule(e,t,a){if(P(a.type,this._validatorRegistryService)){const{ranges:i,formula1:n,formula2:l,uid:u}=a;this._addFormulaByRange(e,t,u,n,l,i)}}async getCellFormulaValue(e,t,a,i,n){var v,R;const{ruleFormulaMap:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return Promise.resolve(void 0);const d=await this._registerOtherFormulaService.getFormulaValue(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}async getCellFormula2Value(e,t,a,i,n){var v,R;const{ruleFormulaMap2:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return Promise.resolve(void 0);const d=await this._registerOtherFormulaService.getFormulaValue(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}getCellFormulaValueSync(e,t,a,i,n){var v,R;const{ruleFormulaMap:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return;const d=this._registerOtherFormulaService.getFormulaValueSync(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}getCellFormula2ValueSync(e,t,a,i,n){var v,R;const{ruleFormulaMap2:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return;const d=this._registerOtherFormulaService.getFormulaValueSync(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}getRuleFormulaInfo(e,t,a){const{ruleFormulaMap:i}=this._ensureMaps(e,t);return i.get(a)}makeRuleDirty(e,t,a){var l,u,d,c;const i=(u=(l=this._ruleFormulaMap.get(e))==null?void 0:l.get(t))==null?void 0:u.get(a),n=(c=(d=this._ruleFormulaMap2.get(e))==null?void 0:d.get(t))==null?void 0:c.get(a);i&&this._registerOtherFormulaService.markFormulaDirty(e,t,i.formulaId),n&&this._registerOtherFormulaService.markFormulaDirty(e,t,n.formulaId)}},m.DataValidationCustomFormulaService=ke([H(0,r.IUniverInstanceService),H(1,r.Inject(Z.RegisterOtherFormulaService)),H(2,r.Inject(p.DataValidationModel)),H(3,r.Inject(m.DataValidationCacheService)),H(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationCustomFormulaService);var xe=Object.getOwnPropertyDescriptor,qe=(o,s,e,t)=>{for(var a=t>1?void 0:t?xe(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},W=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();_(this,"_formulaRuleMap",new Map);this._instanceService=e,this._registerOtherFormulaService=t,this._dataValidationCacheService=a,this._dataValidationModel=i,this._validatorRegistryService=n,this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(const t in e){const a=e[t];if(this._instanceService.getUnitType(t)===r.UniverInstanceType.UNIVER_SHEET)for(const n in a){const l=a[n],u=this._ensureRuleFormulaMap(t,n);l.forEach(d=>{var c,h;if(u.get((c=d.extra)==null?void 0:c.ruleId)){const g=this._dataValidationModel.getRuleById(t,n,(h=d.extra)==null?void 0:h.ruleId);g&&this._dataValidationCacheService.markRangeDirty(t,n,g.ranges)}})}}}))}_ensureRuleFormulaMap(e,t){let a=this._formulaRuleMap.get(e);a||(a=new Map,this._formulaRuleMap.set(e,a));let i=a.get(t);return i||(i=new Map,a.set(t,i)),i}_registerSingleFormula(e,t,a,i){const n=[{startColumn:0,endColumn:0,startRow:0,endRow:0}];return this._registerOtherFormulaService.registerFormulaWithRange(e,t,a,n,{ruleId:i})}addRule(e,t,a){if(!P(a.type,this._validatorRegistryService)&&a.type!==r.DataValidationType.CHECKBOX){const{formula1:i,formula2:n,uid:l}=a,u=r.isFormulaString(i),d=r.isFormulaString(n);if(!u&&!d)return;const c=this._ensureRuleFormulaMap(e,t),h=[void 0,void 0];if(u){const g=this._registerSingleFormula(e,t,i,l);h[0]={id:g,text:i}}if(d){const g=this._registerSingleFormula(e,t,n,l);h[1]={id:g,text:n}}c.set(l,h)}}removeRule(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return;const[l,u]=n,d=[l==null?void 0:l.id,u==null?void 0:u.id].filter(Boolean);d.length&&this._registerOtherFormulaService.deleteFormula(e,t,d)}getRuleFormulaResult(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return Promise.resolve(null);const l=async u=>u&&this._registerOtherFormulaService.getFormulaValue(e,t,u.id);return Promise.all([l(n[0]),l(n[1])])}getRuleFormulaResultSync(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(n)return n.map(l=>{if(l)return this._registerOtherFormulaService.getFormulaValueSync(e,t,l.id)})}getRuleFormulaInfo(e,t,a){return this._ensureRuleFormulaMap(e,t).get(a)}},m.DataValidationFormulaService=qe([W(0,r.IUniverInstanceService),W(1,r.Inject(Z.RegisterOtherFormulaService)),W(2,r.Inject(m.DataValidationCacheService)),W(3,r.Inject(p.DataValidationModel)),W(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationFormulaService);function L(o){return r.getOriginCellValue(o)}function Ve(o){var s;return String((s=L(o))!=null?s:"")}class ce{constructor(s,e,t,a,i=!1){_(this,"_map");_(this,"_tree",new r.RBush);_(this,"_dirty",!0);_(this,"_buildTree",()=>{if(!this._dirty||this._disableTree)return;this._tree.clear();const s=[];this._map.forEach((e,t)=>{e.forEach(a=>{s.push({minX:a.startRow,maxX:a.endRow,minY:a.startColumn,maxY:a.endColumn,ruleId:t})})}),this._tree.load(s),this._dirty=!1});_(this,"_debonceBuildTree",r.debounce(this._buildTree,0));this._unitId=e,this._subUnitId=t,this._univerInstanceService=a,this._disableTree=i,this._map=s,this._buildTree()}get _worksheet(){var s;return(s=this._univerInstanceService.getUnit(this._unitId,r.UniverInstanceType.UNIVER_SHEET))==null?void 0:s.getSheetBySheetId(this._subUnitId)}_addRule(s,e){if(!this._worksheet)return;const t=r.Rectangle.mergeRanges(e.map(a=>r.Range.transformRange(a,this._worksheet)));this._map.forEach((a,i)=>{const n=r.Rectangle.subtractMulti(a,t);n.length===0?this._map.delete(i):this._map.set(i,n)}),this._dirty=!0,this._map.set(s,t),this._debonceBuildTree()}addRule(s){this._addRule(s.uid,s.ranges)}removeRange(s){if(!this._worksheet)return;const e=s.map(t=>r.Range.transformRange(t,this._worksheet));this._map.forEach((t,a)=>{const i=r.Rectangle.subtractMulti(t,e);i.length===0?this._map.delete(a):this._map.set(a,i)}),this._dirty=!0,this._debonceBuildTree()}_removeRule(s){this._map.delete(s),this._dirty=!0,this._debonceBuildTree()}removeRule(s){this._removeRule(s.uid)}updateRange(s,e){this._removeRule(s),this._addRule(s,e)}addRangeRules(s){s.forEach(({id:e,ranges:t})=>{if(!t.length)return;let a=this._map.get(e);a?(this._map.set(e,r.Rectangle.mergeRanges([...a,...t])),a=this._map.get(e)):(a=t,this._map.set(e,a)),this._map.forEach((i,n)=>{if(n===e)return;const l=r.Rectangle.subtractMulti(i,t);l.length===0?this._map.delete(n):this._map.set(n,l)})}),this._dirty=!0,this._debonceBuildTree()}diff(s){const e=[];let t=0;return s.forEach((a,i)=>{var u;const n=(u=this._map.get(a.uid))!=null?u:[],l=a.ranges;n.length!==0&&(n.length!==l.length||n.some((d,c)=>!r.Rectangle.equals(d,l[c])))&&e.push({type:"update",ruleId:a.uid,oldRanges:l,newRanges:r.Rectangle.sort(n),rule:a}),n.length===0&&(e.push({type:"delete",rule:a,index:i-t}),t++)}),e}diffWithAddition(s,e){const t=[];let a=0;return s.forEach((i,n)=>{var d;const l=(d=this._map.get(i.uid))!=null?d:[],u=i.ranges;l.length!==0&&(l.length!==u.length||l.some((c,h)=>!r.Rectangle.equals(c,u[h])))&&t.push({type:"update",ruleId:i.uid,oldRanges:u,newRanges:r.Rectangle.sort(l),rule:i}),l.length===0&&(t.push({type:"delete",rule:i,index:n-a}),a++)}),Array.from(e).forEach(i=>{var l;const n=(l=this._map.get(i.uid))!=null?l:[];t.push({type:"add",rule:{...i,ranges:r.Rectangle.sort(n)}})}),t}clone(){return new ce(new Map(r.Tools.deepClone(Array.from(this._map.entries()))),this._unitId,this._subUnitId,this._univerInstanceService,!0)}getValue(s,e){this._dirty&&this._buildTree();const t=this._tree.search({minX:s,maxX:s,minY:e,maxY:e});return t.length>0?t[0].ruleId:void 0}}var Qe=Object.getOwnPropertyDescriptor,Ge=(o,s,e,t)=>{for(var a=t>1?void 0:t?Qe(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},A=(o,s)=>(e,t)=>s(e,t,o);m.SheetDataValidationModel=class extends r.Disposable{constructor(e,t,a,i,n,l,u){super();_(this,"_ruleMatrixMap",new Map);_(this,"_validStatusChange$",new U.Subject);_(this,"_ruleChange$",new U.Subject);_(this,"ruleChange$",this._ruleChange$.asObservable());_(this,"validStatusChange$",this._validStatusChange$.asObservable());this._dataValidationModel=e,this._univerInstanceService=t,this._dataValidatorRegistryService=a,this._dataValidationCacheService=i,this._dataValidationFormulaService=n,this._dataValidationCustomFormulaService=l,this._commandService=u,this._initRuleUpdateListener(),this.disposeWithMe(()=>{this._ruleChange$.complete(),this._validStatusChange$.complete()}),this._initUniverInstanceListener()}_initUniverInstanceListener(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{this._ruleMatrixMap.delete(e.getUnitId())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.RemoveSheetMutation.id){const{unitId:t,subUnitId:a}=e.params,i=this._ruleMatrixMap.get(t);i&&i.delete(a)}}))}_initRuleUpdateListener(){const e=this._dataValidationModel.getAll();for(const[t,a]of e)for(const[i,n]of a)for(const l of n)this._addRule(t,i,l),this._ruleChange$.next({type:"add",unitId:t,subUnitId:i,rule:l,source:"patched"});this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(t=>{switch(t.type){case"add":this._addRule(t.unitId,t.subUnitId,t.rule);break;case"update":this._updateRule(t.unitId,t.subUnitId,t.rule.uid,t.oldRule,t.updatePayload);break;case"remove":this._removeRule(t.unitId,t.subUnitId,t.rule);break}this._ruleChange$.next(t)}))}_ensureRuleMatrix(e,t){let a=this._ruleMatrixMap.get(e);a||(a=new Map,this._ruleMatrixMap.set(e,a));let i=a.get(t);return i||(i=new ce(new Map,e,t,this._univerInstanceService),a.set(t,i)),i}_addRuleSideEffect(e,t,a){this._ensureRuleMatrix(e,t).addRule(a),this._dataValidationCacheService.addRule(e,t,a),this._dataValidationFormulaService.addRule(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,a)}_addRule(e,t,a){(Array.isArray(a)?a:[a]).forEach(n=>{this._addRuleSideEffect(e,t,n)})}_updateRule(e,t,a,i,n){const l=this._ensureRuleMatrix(e,t),u={...i,...n.payload};n.type===p.UpdateRuleType.RANGE?l.updateRange(a,n.payload):n.type===p.UpdateRuleType.ALL&&l.updateRange(a,n.payload.ranges),this._dataValidationCacheService.removeRule(e,t,i),this._dataValidationCacheService.addRule(e,t,u),this._dataValidationFormulaService.removeRule(e,t,i.uid),this._dataValidationFormulaService.addRule(e,t,u),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,u)}_removeRule(e,t,a){this._ensureRuleMatrix(e,t).removeRule(a),this._dataValidationCacheService.removeRule(e,t,a),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a.uid)}getValidator(e){return this._dataValidatorRegistryService.getValidatorItem(e)}getRuleIdByLocation(e,t,a,i){return this._ensureRuleMatrix(e,t).getValue(a,i)}getRuleByLocation(e,t,a,i){const n=this.getRuleIdByLocation(e,t,a,i);if(n)return this._dataValidationModel.getRuleById(e,t,n)}validator(e,t,a){const{col:i,row:n,unitId:l,subUnitId:u,worksheet:d}=t,c=(R,V)=>{a&&a(R,V),V&&this._validStatusChange$.next({unitId:l,subUnitId:u,ruleId:e.uid,status:R,row:n,col:i})},h=d.getCellValueOnly(n,i),g=this.getValidator(e.type),S=d.getCellRaw(n,i),v=L(S);if(g){const R=this._dataValidationCacheService.ensureCache(l,u),V=R.getValue(n,i);return V==null?(R.setValue(n,i,r.DataValidationStatus.VALIDATING),g.validator({value:v,unitId:l,subUnitId:u,row:n,column:i,worksheet:t.worksheet,workbook:t.workbook,interceptValue:L(h),t:S==null?void 0:S.t},e).then(f=>{const M=f?r.DataValidationStatus.VALID:r.DataValidationStatus.INVALID,T=R.getValue(n,i);M===r.DataValidationStatus.VALID?R.realDeleteValue(n,i):R.setValue(n,i,M),c(M,V!==T)}),r.DataValidationStatus.VALIDATING):(c(V!=null?V:r.DataValidationStatus.VALID,!1),V!=null?V:r.DataValidationStatus.VALID)}else return c(r.DataValidationStatus.VALID,!1),r.DataValidationStatus.VALID}getRuleObjectMatrix(e,t){return this._ensureRuleMatrix(e,t)}getRuleById(e,t,a){return this._dataValidationModel.getRuleById(e,t,a)}getRuleIndex(e,t,a){return this._dataValidationModel.getRuleIndex(e,t,a)}getRules(e,t){return[...this._dataValidationModel.getRules(e,t)]}getUnitRules(e){return this._dataValidationModel.getUnitRules(e)}deleteUnitRules(e){return this._dataValidationModel.deleteUnitRules(e)}getSubUnitIds(e){return this._dataValidationModel.getSubUnitIds(e)}getAll(){return this._dataValidationModel.getAll()}},m.SheetDataValidationModel=Ge([A(0,r.Inject(p.DataValidationModel)),A(1,r.IUniverInstanceService),A(2,r.Inject(p.DataValidatorRegistryService)),A(3,r.Inject(m.DataValidationCacheService)),A(4,r.Inject(m.DataValidationFormulaService)),A(5,r.Inject(m.DataValidationCustomFormulaService)),A(6,r.ICommandService)],m.SheetDataValidationModel);const $=1,k=0;function De(o,s){return r.Tools.isBlank(o)?s.t("dataValidation.validFail.value"):r.isFormulaString(o)?s.t("dataValidation.validFail.primitive"):""}const x=o=>r.Tools.isDefine(o)&&String(o).toLowerCase()==="true"?"1":String(o).toLowerCase()==="false"?"0":o;class Me extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.CHECKBOX);_(this,"title","dataValidation.checkbox.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",41);_(this,"offsetFormulaByRange",!1);_(this,"_formulaService",this.injector.get(m.DataValidationFormulaService));_(this,"skipDefaultFontRender",(e,t,a)=>{const{unitId:i,subUnitId:n}=a,{formula1:l,formula2:u}=this.parseFormulaSync(e,i,n),d=`${t!=null?t:""}`;return!d||d===`${l}`||d===`${u}`})}validatorFormula(e,t,a){const{formula1:i,formula2:n}=e,l=i===n;if(r.Tools.isBlank(i)&&r.Tools.isBlank(n))return{success:!0};if(l)return{success:!1,formula1:this.localeService.t("dataValidation.validFail.checkboxEqual"),formula2:this.localeService.t("dataValidation.validFail.checkboxEqual")};const u=De(i,this.localeService),d=De(n,this.localeService);return{success:!u&&!d,formula1:u,formula2:d}}async parseFormula(e,t,a){var h,g,S,v;const{formula1:i=$,formula2:n=k}=e,l=await this._formulaService.getRuleFormulaResult(t,a,e.uid),u=r.isFormulaString(i)?w((g=(h=l==null?void 0:l[0])==null?void 0:h.result)==null?void 0:g[0][0]):i,d=r.isFormulaString(n)?w((v=(S=l==null?void 0:l[1])==null?void 0:S.result)==null?void 0:v[0][0]):n,c=E(String(u))&&E(String(d));return{formula1:x(u),formula2:x(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}getExtraStyle(e,t){return{tb:r.WrapStrategy.CLIP}}parseFormulaSync(e,t,a){var h,g,S,v;const{formula1:i=$,formula2:n=k}=e,l=this._formulaService.getRuleFormulaResultSync(t,a,e.uid),u=r.isFormulaString(i)?w((g=(h=l==null?void 0:l[0])==null?void 0:h.result)==null?void 0:g[0][0]):i,d=r.isFormulaString(n)?w((v=(S=l==null?void 0:l[1])==null?void 0:S.result)==null?void 0:v[0][0]):n,c=E(String(u))&&E(String(d));return{formula1:x(u),formula2:x(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}async isValidType(e,t,a){const{value:i,unitId:n,subUnitId:l}=e,{formula1:u,formula2:d,originFormula1:c,originFormula2:h}=await this.parseFormula(a,n,l);return!r.Tools.isDefine(u)||!r.Tools.isDefine(d)?!0:r.Tools.isDefine(i)&&(String(i)===String(u)||String(i)===String(d)||String(i)===String(c!=null?c:"")||String(i)===String(h!=null?h:""))}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.checkbox.error")}generateRuleName(e){return this.titleStr}}const Ye={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.operators.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.operators.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.operators.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.operators.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.operators.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.operators.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.operators.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.operators.notEqual"};r.DataValidationOperator.BETWEEN+"",r.DataValidationOperator.EQUAL+"",r.DataValidationOperator.GREATER_THAN+"",r.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",r.DataValidationOperator.LESS_THAN+"",r.DataValidationOperator.LESS_THAN_OR_EQUAL+"",r.DataValidationOperator.NOT_BETWEEN+"",r.DataValidationOperator.NOT_EQUAL+"";const Ee={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.ruleName.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.ruleName.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.ruleName.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.ruleName.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.ruleName.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.ruleName.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.ruleName.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.ruleName.notEqual",NONE:"dataValidation.date.ruleName.legal"},Xe={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.errorMsg.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.errorMsg.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.errorMsg.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.errorMsg.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.errorMsg.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.errorMsg.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.errorMsg.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.errorMsg.notEqual",NONE:"dataValidation.date.errorMsg.legal"},J=[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.NOT_BETWEEN],q="{FORMULA1}",Q="{FORMULA2}";function Ke(o){return o.filter(Boolean).join(",")}function G(o){return o.split(",").filter(Boolean)}function ze(o){const s=L(o);return s==null?"":s.toString()}function Y(o,s,e){const{formula1:t,formula2:a}=s,i=s.ranges[0].startRow,n=s.ranges[0].startColumn,l=e.row-i,u=e.col-n,d=r.isFormulaString(t)?o.moveFormulaRefOffset(t,u,l,!0):t,c=r.isFormulaString(a)?o.moveFormulaRefOffset(a,u,l,!0):a;return{transformedFormula1:d,transformedFormula2:c}}const me=o=>{var e,t;if(o==null||typeof o=="boolean")return;if(typeof o=="number"||!Number.isNaN(+o))return+o;const s=(e=r.numfmt.parseDate(o))==null?void 0:e.v;return r.Tools.isDefine(s)?s:(t=r.numfmt.parseDate(r.dayjs(o).format("YYYY-MM-DD HH:mm:ss")))==null?void 0:t.v};class ye extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.DATE);_(this,"title","dataValidation.date.title");_(this,"order",40);_(this,"operators",[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.EQUAL,r.DataValidationOperator.GREATER_THAN,r.DataValidationOperator.GREATER_THAN_OR_EQUAL,r.DataValidationOperator.LESS_THAN,r.DataValidationOperator.LESS_THAN_OR_EQUAL,r.DataValidationOperator.NOT_BETWEEN,r.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder))}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=E(String(l==null?void 0:l.v))&&E(String(u==null?void 0:u.v));return{formula1:me(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:me(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}async isValidType(e){const{interceptValue:t,value:a}=e;return typeof a=="number"&&typeof t=="string"||typeof t=="string"?!!r.numfmt.parseDate(t):!1}_validatorSingleFormula(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)||!!(e&&r.numfmt.parseDate(e)))}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=this._validatorSingleFormula(e.formula1),l=this.localeService.t("dataValidation.validFail.date");if(J.includes(i)){const d=this._validatorSingleFormula(e.formula2);return{success:n&&d,formula1:n?void 0:l,formula2:d?void 0:l}}return{success:n,formula1:n?void 0:l}}normalizeFormula(e,t,a){const{formula1:i,formula2:n,bizInfo:l}=e,u=d=>{var h;if(!d)return d;let c;if(!Number.isNaN(+d))c=r.numfmt.dateFromSerial(+d);else{const g=(h=r.numfmt.parseDate(d))==null?void 0:h.v;if(g==null)return"";c=r.numfmt.dateFromSerial(g)}return r.dayjs(`${c[0]}/${c[1]}/${c[2]} ${c[3]}:${c[4]}:${c[5]}`).format(l!=null&&l.showTime?"YYYY-MM-DD HH:mm:ss":"YYYY-MM-DD")};return{formula1:r.isFormulaString(i)?i:u(`${i}`),formula2:r.isFormulaString(n)?n:u(`${n}`)}}transform(e,t,a){const{value:i}=e;return{...e,value:me(i)}}get operatorNames(){return this.operators.map(e=>this.localeService.t(Ye[e]))}generateRuleName(e){var a,i;if(!e.operator)return this.localeService.t(Ee.NONE);const t=this.localeService.t(Ee[e.operator]).replace(q,(a=e.formula1)!=null?a:"").replace(Q,(i=e.formula2)!=null?i:"");return`${this.titleStr} ${t}`}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(Xe[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}r.DataValidationOperator.BETWEEN+"",r.DataValidationOperator.EQUAL+"",r.DataValidationOperator.GREATER_THAN+"",r.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",r.DataValidationOperator.LESS_THAN+"",r.DataValidationOperator.LESS_THAN_OR_EQUAL+"",r.DataValidationOperator.NOT_BETWEEN+"",r.DataValidationOperator.NOT_EQUAL+"",r.DataValidationOperator.BETWEEN+"",r.DataValidationOperator.EQUAL+"",r.DataValidationOperator.GREATER_THAN+"",r.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",r.DataValidationOperator.LESS_THAN+"",r.DataValidationOperator.LESS_THAN_OR_EQUAL+"",r.DataValidationOperator.NOT_BETWEEN+"",r.DataValidationOperator.NOT_EQUAL+"";const ee={[r.DataValidationOperator.BETWEEN]:"dataValidation.errorMsg.between",[r.DataValidationOperator.EQUAL]:"dataValidation.errorMsg.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.errorMsg.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.errorMsg.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.errorMsg.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.errorMsg.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.errorMsg.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.errorMsg.notEqual",NONE:"dataValidation.errorMsg.legal"};function X(o){return+o}class Ze extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"id",r.DataValidationType.DECIMAL);_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"title","dataValidation.decimal.title");_(this,"order",20);_(this,"operators",[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.EQUAL,r.DataValidationOperator.GREATER_THAN,r.DataValidationOperator.GREATER_THAN_OR_EQUAL,r.DataValidationOperator.LESS_THAN,r.DataValidationOperator.LESS_THAN_OR_EQUAL,r.DataValidationOperator.NOT_BETWEEN,r.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"])}_isFormulaOrNumber(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e))}async isValidType(e,t,a){const{value:i}=e;return!Number.isNaN(X(i))}transform(e,t,a){const{value:i}=e;return{...e,value:X(i)}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=E(String(l==null?void 0:l.v))&&E(String(u==null?void 0:u.v));return{formula1:this._parseNumber(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:this._parseNumber(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrNumber(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrNumber(e.formula2),u=J.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:n?"":d}}generateRuleErrorMessage(e,t){if(!e.operator)return this.localeService.t(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function he(o){if(!o)return[];const s=new Set;return o.forEach(e=>{e.forEach(t=>{var i,n;const a=L(t);if(a!=null){if(typeof a!="string"&&typeof(t==null?void 0:t.s)=="object"&&((n=(i=t.s)==null?void 0:i.n)!=null&&n.pattern)){s.add(r.numfmt.format(t.s.n.pattern,a,{throws:!1}));return}E(a.toString())&&s.add(a.toString())}})}),[...s]}const Je=["if","indirect","choose","offset"];function et(o,s){if(!r.isFormulaString(o)||y.isReferenceString(o.slice(1)))return!0;const t=s.sequenceNodesBuilder(o);return t&&t.some(a=>typeof a=="object"&&a.nodeType===y.sequenceNodeType.FUNCTION&&Je.indexOf(a.token.toLowerCase())>-1)}function tt(o,s){const{formula1:e="",ranges:t}=o;if(y.isReferenceString(e.slice(1))){const i=y.deserializeRangeWithSheet(e.slice(1));if((!i.sheetName||i.sheetName===s)&&t.some(n=>r.Rectangle.intersects(n,i.range)))return!0}return!1}class ge extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"formulaService",this.injector.get(m.DataValidationFormulaService));_(this,"_lexer",this.injector.get(y.LexerTreeBuilder));_(this,"_univerInstanceService",this.injector.get(r.IUniverInstanceService));_(this,"order",50);_(this,"offsetFormulaByRange",!1);_(this,"id",r.DataValidationType.LIST);_(this,"title","dataValidation.list.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"skipDefaultFontRender",e=>e.renderMode!==r.DataValidationRenderMode.TEXT)}validatorFormula(e,t,a){var d,c,h;const i=!r.Tools.isBlank(e.formula1),n=et((d=e.formula1)!=null?d:"",this._lexer),l=(h=(c=this._univerInstanceService.getUnit(t,r.UniverInstanceType.UNIVER_SHEET))==null?void 0:c.getSheetBySheetId(a))==null?void 0:h.getName(),u=tt(e,l!=null?l:"");return{success:!!(i&&n&&!u),formula1:i?n?u?this.localeService.t("dataValidation.validFail.listIntersects"):void 0:this.localeService.t("dataValidation.validFail.listInvalid"):this.localeService.t("dataValidation.validFail.list")}}getExtraStyle(e,t,{style:a}){var n;const i=(n=a.tb!==r.WrapStrategy.OVERFLOW?a.tb:r.WrapStrategy.CLIP)!=null?n:r.WrapStrategy.WRAP;if(e.type===r.DataValidationType.LIST&&(e.renderMode===r.DataValidationRenderMode.ARROW||e.renderMode===r.DataValidationRenderMode.TEXT)){const l=this.getListWithColorMap(e),u=`${t!=null?t:""}`,d=l[u];if(d)return{bg:{rgb:d},tb:i}}return{tb:i}}parseCellValue(e){const t=e.toString();return G(t)}async parseFormula(e,t,a){var u,d;const i=await this.formulaService.getRuleFormulaResult(t,a,e.uid),n=w((d=(u=i==null?void 0:i[0])==null?void 0:u.result)==null?void 0:d[0][0]);return{formula1:void 0,formula2:void 0,isFormulaValid:E(String(n))}}async isValidType(e,t,a){var g,S;const{value:i,unitId:n,subUnitId:l}=e,{formula1:u=""}=a,d=await this.formulaService.getRuleFormulaResult(n,l,a.uid),c=r.isFormulaString(u)?he((S=(g=d==null?void 0:d[0])==null?void 0:g.result)==null?void 0:S[0][0]):G(u);return this.parseCellValue(i).every(v=>c.includes(v))}generateRuleName(){return this.localeService.t("dataValidation.list.name")}generateRuleErrorMessage(){return this.localeService.t("dataValidation.list.error")}getList(e,t,a){var g,S,v,R;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(g=t?n.getUniverSheetInstance(t):void 0)!=null?g:n.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(S=a?l.getSheetBySheetId(a):void 0)!=null?S:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),h=this.formulaService.getRuleFormulaResultSync(d,c,e.uid);return r.isFormulaString(i)?he((R=(v=h==null?void 0:h[0])==null?void 0:v.result)==null?void 0:R[0][0]):G(i)}async getListAsync(e,t,a){var g,S,v,R;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(g=t?n.getUniverSheetInstance(t):void 0)!=null?g:n.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(S=a?l.getSheetBySheetId(a):void 0)!=null?S:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),h=await this.formulaService.getRuleFormulaResult(d,c,e.uid);return r.isFormulaString(i)?he((R=(v=h==null?void 0:h[0])==null?void 0:v.result)==null?void 0:R[0][0]):G(i)}getListWithColor(e,t,a){const i=this.getList(e,t,a),n=(e.formula2||"").split(",");return i.map((l,u)=>({label:l,color:n[u]}))}getListWithColorMap(e,t,a){const i=this.getListWithColor(e,t,a),n={};return i.forEach(l=>{l.color&&(n[l.label]=l.color)}),n}}class at extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.TEXT_LENGTH);_(this,"title","dataValidation.textLength.title");_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"order",30);_(this,"operators",[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.EQUAL,r.DataValidationOperator.GREATER_THAN,r.DataValidationOperator.GREATER_THAN_OR_EQUAL,r.DataValidationOperator.LESS_THAN,r.DataValidationOperator.LESS_THAN_OR_EQUAL,r.DataValidationOperator.NOT_BETWEEN,r.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService))}_isFormulaOrInt(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!1};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=J.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:d}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=E(String(l==null?void 0:l.v))&&E(String(u==null?void 0:u.v));return{formula1:this._parseNumber(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:this._parseNumber(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}transform(e,t,a){return{...e,value:e.value.toString().length}}async isValidType(e,t,a){const{value:i}=e;return typeof i=="string"||typeof i=="number"}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(p.TextLengthErrorTitleMap[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function Te(o){var e,t;return o?o.p?!((t=(e=o.p.body)==null?void 0:e.dataStream)!=null?t:"").slice(0,-2).trim():r.Tools.isBlank(o.v):!0}function K(o,s,e,t,a="command",i=!0){const n=t.get(y.LexerTreeBuilder),l=t.get(p.DataValidatorRegistryService),u=[],d=[],c=t.get(m.SheetDataValidationModel),h=t.get(r.IUniverInstanceService),g=D.getSheetCommandTarget(h,{unitId:o,subUnitId:s});if(!g)return{redoMutations:u,undoMutations:d};const{worksheet:S}=g,v=new r.ObjectMatrix;let R=!1;function V(f,M){i&&f.forEach(T=>{r.Range.foreach(T,(O,I)=>{const F=S.getCellRaw(O,I),B=Ve(F);(Te(F)||B===M)&&!(F!=null&&F.p)&&(R=!0,v.setValue(O,I,{v:M,p:null}))})})}if(e.forEach(f=>{switch(f.type){case"delete":u.push({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.rule.uid,source:a}}),d.unshift({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:f.rule,index:f.index,source:a}});break;case"update":{if(P(f.rule.type,l)){const T=f.oldRanges[0].startRow,O=f.oldRanges[0].startColumn,I=f.newRanges[0].startRow,F=f.newRanges[0].startColumn,B=I-T,oe=F-O,se=r.isFormulaString(f.rule.formula1)?n.moveFormulaRefOffset(f.rule.formula1,oe,B):f.rule.formula1,le=r.isFormulaString(f.rule.formula2)?n.moveFormulaRefOffset(f.rule.formula2,oe,B):f.rule.formula2;se!==f.rule.formula1||le!==f.rule.formula2||!r.isRangesEqual(f.newRanges,f.oldRanges)?(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:se,formula2:le,ranges:f.newRanges}}}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:f.rule.formula1,formula2:f.rule.formula2,ranges:f.oldRanges}}}})):(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.oldRanges},source:a}}))}else u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.oldRanges},source:a}});const M=c.getRuleById(o,s,f.ruleId);if(M&&M.type===r.DataValidationType.CHECKBOX){const O=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(M,o,s);V(f.newRanges,O.formula2)}break}case"add":{if(u.push({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:f.rule,source:a}}),d.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.rule.uid,source:a}}),f.rule.type===r.DataValidationType.CHECKBOX){const T=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(f.rule,o,s);V(f.rule.ranges,T.originFormula2)}break}}}),R){const f={id:D.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:s,cellValue:v.getData()}},M={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(t,f.params)};u.push(f),d.push(M)}return{redoMutations:u,undoMutations:d}}const Oe={type:r.CommandType.COMMAND,id:"sheet.command.updateDataValidationRuleRange",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ranges:a,ruleId:i}=s,n=o.get(m.SheetDataValidationModel),l=o.get(r.ICommandService),u=o.get(r.IUndoRedoService);if(!n.getRuleById(e,t,i))return!1;const c=n.getRuleObjectMatrix(e,t).clone();c.updateRange(i,a);const h=c.diff(n.getRules(e,t)),{redoMutations:g,undoMutations:S}=K(e,t,h,o);return u.pushUndoRedo({undoMutations:S,redoMutations:g,unitID:e}),r.sequenceExecute(g,l),!0}},Fe={type:r.CommandType.COMMAND,id:"sheet.command.addDataValidation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,rule:a}=s,i=o.get(m.SheetDataValidationModel),n=o.get(r.ICommandService),l=o.get(r.IUndoRedoService),u=i.getRuleObjectMatrix(e,t).clone();u.addRule(a);const d=u.diff(i.getRules(e,t)),c=i.getValidator(a.type),h={unitId:e,subUnitId:t,rule:{...a,...c==null?void 0:c.normalizeFormula(a,e,t)}},{redoMutations:g,undoMutations:S}=K(e,t,d,o);return g.push({id:p.AddDataValidationMutation.id,params:h}),S.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:t,ruleId:a.uid}}),l.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:S}),r.sequenceExecute(g,n),!0}},Ie={type:r.CommandType.COMMAND,id:"sheets.command.update-data-validation-setting",handler(o,s){if(!s)return!1;const e=o.get(r.ICommandService),t=o.get(r.IUndoRedoService),a=o.get(m.SheetDataValidationModel),i=o.get(p.DataValidatorRegistryService),{unitId:n,subUnitId:l,ruleId:u,setting:d}=s,c=i.getValidatorItem(d.type);if(!c)return!1;const h=a.getRuleById(n,l,u);if(!h)return!1;const g={...h,...d};if(!c.validatorFormula(g,n,l).success)return!1;const S={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:{...d,...c.normalizeFormula(g,n,l)}}},v=[{id:p.UpdateDataValidationMutation.id,params:S}],R={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:p.getRuleSetting(h)}},V=[{id:p.UpdateDataValidationMutation.id,params:R}];if(d.type===r.DataValidationType.CHECKBOX){const M=h.ranges,T=o.get(r.IUniverInstanceService),O=D.getSheetCommandTarget(T,{unitId:n,subUnitId:l});if(O){const I=new r.ObjectMatrix,{worksheet:F}=O,{formula2:B=k,formula1:oe=$}=h,{formula2:se=k,formula1:le=$}=d;let ve=!1;if(M.forEach(ue=>{r.Range.foreach(ue,(z,Re)=>{const C=F.getCellRaw(z,Re),Pe=Ve(C);(Te(C)||Pe===String(B))&&!(C!=null&&C.p)?(I.setValue(z,Re,{v:se,p:null}),ve=!0):Pe===String(oe)&&!(C!=null&&C.p)&&(I.setValue(z,Re,{v:le,p:null}),ve=!0)})}),ve){const ue={id:D.SetRangeValuesMutation.id,params:{unitId:n,subUnitId:l,cellValue:I.getData()}},z={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(o,ue.params)};v.push(ue),V.push(z)}}}return r.sequenceExecute(v,e).result?(t.pushUndoRedo({unitID:n,redoMutations:v,undoMutations:V}),!0):!1}},Ce={type:r.CommandType.COMMAND,id:"sheets.command.update-data-validation-options",handler(o,s){if(!s)return!1;const e=o.get(r.ICommandService),t=o.get(r.IUndoRedoService),a=o.get(m.SheetDataValidationModel),{unitId:i,subUnitId:n,ruleId:l,options:u}=s,d=a.getRuleById(i,n,l);if(!d)return!1;const c={unitId:i,subUnitId:n,ruleId:l,payload:{type:p.UpdateRuleType.OPTIONS,payload:u}},h=[{id:p.UpdateDataValidationMutation.id,params:c}],g={unitId:i,subUnitId:n,ruleId:l,payload:{type:p.UpdateRuleType.OPTIONS,payload:p.getRuleOptions(d)}},S=[{id:p.UpdateDataValidationMutation.id,params:g}];return t.pushUndoRedo({unitID:i,redoMutations:h,undoMutations:S}),e.executeCommand(p.UpdateDataValidationMutation.id,c),!0}},Ae={type:r.CommandType.COMMAND,id:"sheets.command.clear-range-data-validation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ranges:a}=s,i=o.get(r.ICommandService),n=o.get(r.IUniverInstanceService),l=D.getSheetCommandTarget(n,{unitId:e,subUnitId:t}),u=o.get(m.SheetDataValidationModel);if(!l)return!1;const d=o.get(r.IUndoRedoService),c=u.getRuleObjectMatrix(e,t).clone();c.removeRange(a);const h=c.diff(u.getRules(e,t)),{redoMutations:g,undoMutations:S}=K(e,t,h,o);return d.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:S}),r.sequenceExecute(g,i).result}},Ue={type:r.CommandType.COMMAND,id:"sheet.command.remove-all-data-validation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t}=s,a=o.get(r.ICommandService),i=o.get(m.SheetDataValidationModel),n=o.get(r.IUndoRedoService),l=[...i.getRules(e,t)],u={unitId:e,subUnitId:t,ruleId:l.map(h=>h.uid)},d=[{id:p.RemoveDataValidationMutation.id,params:u}],c=[{id:p.AddDataValidationMutation.id,params:{unitId:e,subUnitId:t,rule:l}}];return n.pushUndoRedo({redoMutations:d,undoMutations:c,unitID:e}),a.executeCommand(p.RemoveDataValidationMutation.id,u),!0}},it=(o,s)=>{const e=o.get(m.SheetDataValidationModel),{unitId:t,subUnitId:a,ruleId:i,source:n}=s;if(Array.isArray(i)){const u=i.map(d=>e.getRuleById(t,a,d)).filter(Boolean);return[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:u,source:n}}]}return[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:{...e.getRuleById(t,a,i)},index:e.getRuleIndex(t,a,i)}}]},we={type:r.CommandType.COMMAND,id:"sheet.command.remove-data-validation-rule",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ruleId:a}=s,i=o.get(r.ICommandService),n=o.get(r.IUndoRedoService),l=o.get(m.SheetDataValidationModel),u=[{id:p.RemoveDataValidationMutation.id,params:s}],d=[{id:p.AddDataValidationMutation.id,params:{unitId:e,subUnitId:t,rule:{...l.getRuleById(e,t,a)},index:l.getRuleIndex(e,t,a)}}];return n.pushUndoRedo({undoMutations:d,redoMutations:u,unitID:s.unitId}),i.executeCommand(p.RemoveDataValidationMutation.id,s),!0}},Le="SHEET_DATA_VALIDATION_PLUGIN";var Ne=(o=>(o[o.View=0]="View",o[o.Edit=1]="Edit",o[o.ManageCollaborator=2]="ManageCollaborator",o[o.Print=3]="Print",o[o.Duplicate=4]="Duplicate",o[o.Comment=5]="Comment",o[o.Copy=6]="Copy",o[o.Share=7]="Share",o[o.Export=8]="Export",o[o.MoveWorksheet=9]="MoveWorksheet",o[o.DeleteWorksheet=10]="DeleteWorksheet",o[o.HideWorksheet=11]="HideWorksheet",o[o.RenameWorksheet=12]="RenameWorksheet",o[o.CreateWorksheet=13]="CreateWorksheet",o[o.SetWorksheetStyle=14]="SetWorksheetStyle",o[o.EditWorksheetCell=15]="EditWorksheetCell",o[o.InsertHyperlink=16]="InsertHyperlink",o[o.Sort=17]="Sort",o[o.Filter=18]="Filter",o[o.PivotTable=19]="PivotTable",o[o.FloatImg=20]="FloatImg",o[o.History=21]="History",o[o.RwHgtClWdt=22]="RwHgtClWdt",o[o.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",o[o.ViewFilter=24]="ViewFilter",o[o.MoveSheet=25]="MoveSheet",o[o.DeleteSheet=26]="DeleteSheet",o[o.HideSheet=27]="HideSheet",o[o.CopySheet=28]="CopySheet",o[o.RenameSheet=29]="RenameSheet",o[o.CreateSheet=30]="CreateSheet",o[o.SelectProtectedCells=31]="SelectProtectedCells",o[o.SelectUnProtectedCells=32]="SelectUnProtectedCells",o[o.SetCellStyle=33]="SetCellStyle",o[o.SetCellValue=34]="SetCellValue",o[o.SetRowStyle=35]="SetRowStyle",o[o.SetColumnStyle=36]="SetColumnStyle",o[o.InsertRow=37]="InsertRow",o[o.InsertColumn=38]="InsertColumn",o[o.DeleteRow=39]="DeleteRow",o[o.DeleteColumn=40]="DeleteColumn",o[o.EditExtraObject=41]="EditExtraObject",o[o.Delete=42]="Delete",o[o.RecoverHistory=43]="RecoverHistory",o[o.ViewHistory=44]="ViewHistory",o[o.CreatePermissionObject=45]="CreatePermissionObject",o[o.UNRECOGNIZED=-1]="UNRECOGNIZED",o))(Ne||{}),rt=Object.getOwnPropertyDescriptor,nt=(o,s,e,t)=>{for(var a=t>1?void 0:t?rt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},pe=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaController=class extends r.Disposable{constructor(s,e,t){super(),this._univerInstanceService=s,this._permissionService=e,this._lexerTreeBuilder=t}getFormulaRefCheck(s){var t,a;const e=this._lexerTreeBuilder.sequenceNodesBuilder(s);if(!e)return!0;for(let i=0;i<e.length;i++){const n=e[i];if(typeof n=="string")continue;const{token:l}=n,u=y.deserializeRangeWithSheetWithCache(l),d=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);let c=d.getActiveSheet();const h=d.getUnitId();if(u.sheetName){if(c=d.getSheetBySheetName(u.sheetName),!c)return!1;const V=c==null?void 0:c.getSheetId();if(!this._permissionService.getPermissionPoint(new D.WorksheetViewPermission(h,V).id))return!1}if(!c)return!1;const{startRow:g,endRow:S,startColumn:v,endColumn:R}=u.range;for(let V=g;V<=S;V++)for(let f=v;f<=R;f++){const M=(a=(t=c.getCell(V,f))==null?void 0:t.selectionProtection)==null?void 0:a[0];if((M==null?void 0:M[Ne.View])===!1)return!1}}return!0}},m.DataValidationFormulaController=nt([pe(0,r.IUniverInstanceService),pe(1,r.IPermissionService),pe(2,r.Inject(y.LexerTreeBuilder))],m.DataValidationFormulaController);const ot="sheets-data-validation.config",be={};var st=Object.getOwnPropertyDescriptor,lt=(o,s,e,t)=>{for(var a=t>1?void 0:t?st(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},_e=(o,s)=>(e,t)=>s(e,t,o);let te=class extends r.Disposable{constructor(s,e,t){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(s,e,t)=>{P(t.type,this._validatorRegistryService)&&this.register(s,e,t)});this._dataValidationModel=s,this._formulaRefRangeService=e,this._validatorRegistryService=t,this._initRefRange()}_getIdWithUnitId(s,e,t){return`${s}_${e}_${t}`}register(s,e,t){const a=t.ranges,i=t.formula1,n=t.formula2,l=this._formulaRefRangeService.registerRangeFormula(s,e,a,[i!=null?i:"",n!=null?n:""],d=>{if(d.length===0)return{undos:[{id:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:t,source:"patched"}}],redos:[{id:p.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,source:"patched"}}]};const c=[],h=[],g=d[0];c.push({id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:g.ranges,formula1:g.formulas[0],formula2:g.formulas[1]}},source:"patched"}}),h.push({id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:a,formula1:i,formula2:n}},source:"patched"}});for(let S=1;S<d.length;S++){const v=d[S],R=r.generateRandomId();c.push({id:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:{...t,uid:R,formula1:v.formulas[0],formula2:v.formulas[1],ranges:v.ranges},source:"patched"}}),h.push({id:p.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:R,source:"patched"}})}return{undos:h,redos:c}}),u=this._getIdWithUnitId(s,e,t.uid);this._disposableMap.set(u,l)}_initRefRange(){const s=this._dataValidationModel.getAll();for(const[e,t]of s)for(const[a,i]of t)for(const n of i)this.registerRule(e,a,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{const{unitId:t,subUnitId:a,rule:i}=e;switch(e.type){case"add":{const n=e.rule;this.registerRule(e.unitId,e.subUnitId,n);break}case"remove":{const n=this._disposableMap.get(this._getIdWithUnitId(t,a,i.uid));n&&n.dispose();break}case"update":{const n=e.rule,l=this._disposableMap.get(this._getIdWithUnitId(t,a,n.uid));l&&l.dispose(),this.registerRule(e.unitId,e.subUnitId,n);break}}})),this.disposeWithMe(r.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};te=lt([_e(0,r.Inject(m.SheetDataValidationModel)),_e(1,r.Inject(Z.FormulaRefRangeService)),_e(2,r.Inject(p.DataValidatorRegistryService))],te);var ut=Object.getOwnPropertyDescriptor,dt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ut(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},N=(o,s)=>(e,t)=>s(e,t,o);let ae=class extends r.Disposable{constructor(s,e,t,a,i,n){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(s,e,t)=>{P(t.type,this._validatorRegistryService)||(this.register(s,e,t),this.registerFormula(s,e,t))});this._dataValidationModel=s,this._injector=e,this._refRangeService=t,this._dataValidationFormulaService=a,this._formulaRefRangeService=i,this._validatorRegistryService=n,this._initRefRange()}_getIdWithUnitId(s,e,t){return`${s}_${e}_${t}`}registerFormula(s,e,t){var d;const a=t.uid,i=this._getIdWithUnitId(s,e,a),n=(d=this._disposableMap.get(i))!=null?d:new Set,l=(c,h)=>{const g=this._dataValidationModel.getRuleById(s,e,a);if(!g)return{redos:[],undos:[]};const S=g[c];if(!S||S===h)return{redos:[],undos:[]};const v={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:g.type,formula1:g.formula1,formula2:g.formula2,[c]:h}},source:"patched"},R={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:g.type,formula1:g.formula1,formula2:g.formula2}},source:"patched"},V=[{id:p.UpdateDataValidationMutation.id,params:v}],f=[{id:p.UpdateDataValidationMutation.id,params:R}];return{redos:V,undos:f}},u=this._dataValidationFormulaService.getRuleFormulaInfo(s,e,a);if(u){const[c,h]=u;if(c){const g=this._formulaRefRangeService.registerFormula(s,e,c.text,S=>l("formula1",S));n.add(()=>g.dispose())}if(h){const g=this._formulaRefRangeService.registerFormula(s,e,h.text,S=>l("formula2",S));n.add(()=>g.dispose())}}}register(s,e,t){var u;const a=d=>{const c=[...t.ranges],g=c.map(v=>D.handleCommonDefaultRangeChangeWithEffectRefCommands(v,d)).filter(v=>!!v).flat();if(r.isRangesEqual(g,c))return{redos:[],undos:[]};if(g.length){const v={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:g},source:"patched"},R=[{id:p.UpdateDataValidationMutation.id,params:v}],V=[{id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:c},source:"patched"}}];return{redos:R,undos:V}}else{const v={unitId:s,subUnitId:e,ruleId:t.uid},R=[{id:p.RemoveDataValidationMutation.id,params:v}],V=it(this._injector,v);return{redos:R,undos:V}}},i=[];t.ranges.forEach(d=>{const c=this._refRangeService.registerRefRange(d,a,s,e);i.push(()=>c.dispose())});const n=this._getIdWithUnitId(s,e,t.uid),l=(u=this._disposableMap.get(n))!=null?u:new Set;l.add(()=>i.forEach(d=>d())),this._disposableMap.set(n,l)}_initRefRange(){const s=this._dataValidationModel.getAll();for(const[e,t]of s)for(const[a,i]of t)for(const n of i)this.registerRule(e,a,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{const{unitId:t,subUnitId:a,rule:i}=e;switch(e.type){case"add":{const n=e.rule;this.registerRule(e.unitId,e.subUnitId,n);break}case"remove":{const n=this._disposableMap.get(this._getIdWithUnitId(t,a,i.uid));n&&n.forEach(l=>l());break}case"update":{const n=e.rule,l=this._disposableMap.get(this._getIdWithUnitId(t,a,n.uid));l&&l.forEach(u=>u()),this.registerRule(e.unitId,e.subUnitId,n);break}}})),this.disposeWithMe(r.toDisposable(()=>{this._disposableMap.forEach(e=>{e.forEach(t=>t())}),this._disposableMap.clear()}))}};ae=dt([N(0,r.Inject(m.SheetDataValidationModel)),N(1,r.Inject(r.Injector)),N(2,r.Inject(D.RefRangeService)),N(3,r.Inject(m.DataValidationFormulaService)),N(4,r.Inject(Z.FormulaRefRangeService)),N(5,r.Inject(p.DataValidatorRegistryService))],ae);var ct=Object.getOwnPropertyDescriptor,mt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ct(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},Se=(o,s)=>(e,t)=>s(e,t,o);let ie=class extends r.Disposable{constructor(o,s,e){super(),this._sheetInterceptorService=o,this._univerInstanceService=s,this._sheetDataValidationModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{var s;if(o.id===D.RemoveSheetCommand.id){const e=o.params,t=e.unitId||this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=this._univerInstanceService.getUniverSheetInstance(t);if(!a)return{redos:[],undos:[]};const i=e.subUnitId||((s=a.getActiveSheet())==null?void 0:s.getSheetId());if(!i)return{redos:[],undos:[]};const n=this._sheetDataValidationModel.getRules(t,i);if(n.length===0)return{redos:[],undos:[]};const l=n.map(c=>c.uid),u={unitId:t,subUnitId:i,ruleId:l,source:"patched"},d={unitId:t,subUnitId:i,rule:[...n],source:"patched"};return{redos:[{id:p.RemoveDataValidationMutation.id,params:u}],undos:[{id:p.AddDataValidationMutation.id,params:d}]}}return{redos:[],undos:[]}}}))}};ie=mt([Se(0,r.Inject(D.SheetInterceptorService)),Se(1,r.Inject(r.IUniverInstanceService)),Se(2,r.Inject(m.SheetDataValidationModel))],ie);class ht extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.ANY);_(this,"title","dataValidation.any.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",0);_(this,"offsetFormulaByRange",!1)}async parseFormula(e,t,a){return{formula1:e.formula1,formula2:e.formula2,isFormulaValid:!0}}validatorFormula(e,t,a){return{success:!0}}async isValidType(e,t,a){return!0}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.any.error")}}class gt extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.CUSTOM);_(this,"title","dataValidation.custom.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",60);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder))}validatorFormula(e,t,a){var d;const i=r.isFormulaString(e.formula1),n=(d=e.formula1)!=null?d:"",u=this._lexerTreeBuilder.checkIfAddBracket(n)===0&&n.startsWith(y.operatorToken.EQUALS);return{success:i&&u,formula1:i&&u?"":this.localeService.t("dataValidation.validFail.formula")}}async parseFormula(e,t,a){return{formula1:void 0,formula2:void 0,isFormulaValid:!0}}async isValidType(e,t,a){const{column:i,row:n,unitId:l,subUnitId:u}=e,d=await this._customFormulaService.getCellFormulaValue(l,u,a.uid,n,i),c=d==null?void 0:d.v;return E(String(c))&&r.Tools.isDefine(c)&&c!==""?d.t===r.CellValueType.BOOLEAN?!!c:typeof c=="boolean"?c:typeof c=="number"?!!c:typeof c=="string"?E(c):!!c:!1}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.custom.error")}generateRuleName(e){var t;return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}",(t=e.formula1)!=null?t:"")}}class Be extends ge{constructor(){super(...arguments);_(this,"id",r.DataValidationType.LIST_MULTIPLE);_(this,"title","dataValidation.listMultiple.title");_(this,"offsetFormulaByRange",!1);_(this,"skipDefaultFontRender",()=>!0)}}class pt extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"id",r.DataValidationType.WHOLE);_(this,"title","dataValidation.whole.title");_(this,"order",10);_(this,"operators",[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.EQUAL,r.DataValidationOperator.GREATER_THAN,r.DataValidationOperator.GREATER_THAN_OR_EQUAL,r.DataValidationOperator.LESS_THAN,r.DataValidationOperator.LESS_THAN_OR_EQUAL,r.DataValidationOperator.NOT_BETWEEN,r.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"])}_isFormulaOrInt(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}async isValidType(e,t,a){const{value:i}=e,n=X(i);return!Number.isNaN(n)&&Number.isInteger(n)}transform(e,t,a){const{value:i}=e;return{...e,value:X(i)}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=r.isFormulaString(d)?l==null?void 0:l.v:d,g=r.isFormulaString(c)?u==null?void 0:u.v:c,S=E(`${h}`)&&E(`${g}`);return{formula1:this._parseNumber(h),formula2:this._parseNumber(g),isFormulaValid:S}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=J.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:d}}generateRuleErrorMessage(e,t){if(!e.operator)return this.localeService.t(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}var _t=Object.getOwnPropertyDescriptor,St=(o,s,e,t)=>{for(var a=t>1?void 0:t?_t(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},b=(o,s)=>(e,t)=>s(e,t,o);let re=class extends r.RxDisposable{constructor(o,s,e,t,a,i){super(),this._univerInstanceService=o,this._dataValidatorRegistryService=s,this._injector=e,this._selectionManagerService=t,this._sheetInterceptorService=a,this._sheetDataValidationModel=i,this._init()}_init(){this._registerValidators(),this._initCommandInterceptor()}_registerValidators(){[ht,Ze,pt,at,ye,Me,ge,Be,gt].forEach(o=>{const s=this._injector.createInstance(o);this.disposeWithMe(this._dataValidatorRegistryService.register(s)),this.disposeWithMe(r.toDisposable(()=>this._injector.delete(o)))})}_initCommandInterceptor(){this._sheetInterceptorService.interceptCommand({getMutations:o=>{var s;if(o.id===D.ClearSelectionAllCommand.id){const e=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET),t=e.getUnitId(),a=e.getActiveSheet();if(!a)throw new Error("No active sheet found");const i=a.getSheetId(),n=(s=this._selectionManagerService.getCurrentSelections())==null?void 0:s.map(h=>h.range),l=this._sheetDataValidationModel.getRuleObjectMatrix(t,i).clone();n&&l.removeRange(n);const u=l.diff(this._sheetDataValidationModel.getRules(t,i)),{redoMutations:d,undoMutations:c}=K(t,i,u,this._injector,"patched");return{undos:c,redos:d}}return{undos:[],redos:[]}}})}};re=St([b(0,r.IUniverInstanceService),b(1,r.Inject(p.DataValidatorRegistryService)),b(2,r.Inject(r.Injector)),b(3,r.Inject(D.SheetsSelectionsService)),b(4,r.Inject(D.SheetInterceptorService)),b(5,r.Inject(m.SheetDataValidationModel))],re);var ft=Object.getOwnPropertyDescriptor,vt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ft(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},ne=(o,s)=>(e,t)=>s(e,t,o);m.SheetsDataValidationValidatorService=class extends r.Disposable{constructor(s,e,t,a){super(),this._univerInstanceService=s,this._sheetDataValidationModel=e,this._dataValidationCacheService=t,this._lifecycleService=a,this._initRecalculate()}_initRecalculate(){const s=e=>{if(e.length===0)return;const t=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET),a=t==null?void 0:t.getActiveSheet(),i={};e.flat().forEach(n=>{i[n.unitId]||(i[n.unitId]={}),i[n.unitId][n.subUnitId]||(i[n.unitId][n.subUnitId]=[]);const l=this._univerInstanceService.getUnit(n.unitId,r.UniverInstanceType.UNIVER_SHEET),u=l==null?void 0:l.getSheetBySheetId(n.subUnitId);u&&i[n.unitId][n.subUnitId].push(...n.ranges.map(d=>r.Range.transformRange(d,u)))}),Object.entries(i).forEach(([n,l])=>{Object.entries(l).forEach(([u,d])=>{(t==null?void 0:t.getUnitId())===n&&(a==null?void 0:a.getSheetId())===u?this.validatorRanges(n,u,d):requestIdleCallback(()=>{this.validatorRanges(n,u,d)})})})};this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(U.bufferWhen(()=>this._lifecycleService.lifecycle$.pipe(U.filter(e=>e===r.LifecycleStages.Rendered)))).subscribe(s)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(U.filter(()=>this._lifecycleService.stage>=r.LifecycleStages.Rendered),r.bufferDebounceTime(20)).subscribe(s))}async _validatorByCell(s,e,t,a){const i=s.getUnitId(),n=e.getSheetId();if(!r.Tools.isDefine(t)||!r.Tools.isDefine(a))throw new Error(`row or col is not defined, row: ${t}, col: ${a}`);const l=this._sheetDataValidationModel.getRuleByLocation(i,n,t,a);return l?new Promise(u=>{this._sheetDataValidationModel.validator(l,{unitId:i,subUnitId:n,row:t,col:a,worksheet:e,workbook:s},d=>{u(d)})}):r.DataValidationStatus.VALID}async validatorCell(s,e,t,a){const i=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!i)throw new Error(`cannot find current workbook, unitId: ${s}`);const n=i.getSheetBySheetId(e);if(!n)throw new Error(`cannot find current worksheet, sheetId: ${e}`);return this._validatorByCell(i,n,t,a)}validatorRanges(s,e,t){if(!t.length)return Promise.resolve([]);const a=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!a)throw new Error(`cannot find current workbook, unitId: ${s}`);const i=a.getSheetBySheetId(e);if(!i)throw new Error(`cannot find current worksheet, sheetId: ${e}`);const l=this._sheetDataValidationModel.getRules(s,e).map(d=>d.ranges).flat(),u=t.map(d=>l.map(c=>r.getIntersectRange(d,c))).flat().filter(Boolean);return Promise.all(u.map(d=>{const c=[];return r.Range.foreach(d,(h,g)=>{c.push(this._validatorByCell(a,i,h,g))}),Promise.all(c)}))}async validatorWorksheet(s,e){const t=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!t)throw new Error(`cannot find current workbook, unitId: ${s}`);const a=t.getSheetBySheetId(e);if(!a)throw new Error(`cannot find current worksheet, sheetId: ${e}`);const i=this._sheetDataValidationModel.getRules(s,e);return await Promise.all(i.map(n=>Promise.all(n.ranges.map(l=>{const u=[];return r.Range.foreach(l,(d,c)=>{u.push(this._validatorByCell(t,a,d,c))}),Promise.all(u)})))),this._dataValidationCacheService.ensureCache(s,e)}async validatorWorkbook(s){const e=this._sheetDataValidationModel.getSubUnitIds(s),t=await Promise.all(e.map(i=>this.validatorWorksheet(s,i))),a={};return t.forEach((i,n)=>{a[e[n]]=i}),a}getDataValidations(s,e,t){const a=this._sheetDataValidationModel.getRuleObjectMatrix(s,e),i=new Set;return t.forEach(l=>{r.Range.foreach(l,(u,d)=>{const c=a.getValue(u,d);c&&i.add(c)})}),Array.from(i).map(l=>this._sheetDataValidationModel.getRuleById(s,e,l)).filter(Boolean)}getDataValidation(s,e,t){return this.getDataValidations(s,e,t)[0]}},m.SheetsDataValidationValidatorService=vt([ne(0,r.IUniverInstanceService),ne(1,r.Inject(m.SheetDataValidationModel)),ne(2,r.Inject(m.DataValidationCacheService)),ne(3,r.Inject(r.LifecycleService))],m.SheetsDataValidationValidatorService);var Rt=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,Dt=(o,s,e)=>s in o?Rt(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e,Mt=(o,s,e,t)=>{for(var a=t>1?void 0:t?Vt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},fe=(o,s)=>(e,t)=>s(e,t,o),je=(o,s,e)=>Dt(o,typeof s!="symbol"?s+"":s,e);m.UniverSheetsDataValidationPlugin=class extends r.Plugin{constructor(s=be,e,t,a){super(),this._config=s,this._injector=e,this._commandService=t,this._configService=a;const{...i}=r.merge({},be,this._config);this._configService.setConfig(ot,i)}onStarting(){[[m.DataValidationCacheService],[m.DataValidationFormulaService],[m.DataValidationCustomFormulaService],[m.SheetsDataValidationValidatorService],[m.SheetDataValidationModel],[re],[m.DataValidationFormulaController],[ie],[ae],[te]].forEach(s=>{this._injector.add(s)}),[Fe,Oe,Ie,Ce,we,Ue,Ae].forEach(s=>{this._commandService.registerCommand(s)}),this._injector.get(m.DataValidationCacheService),this._injector.get(m.SheetsDataValidationValidatorService),this._injector.get(re),this._injector.get(te),this._injector.get(ae)}onReady(){this._injector.get(ie)}onRendered(){this._injector.get(m.DataValidationFormulaController)}},je(m.UniverSheetsDataValidationPlugin,"pluginName",Le),je(m.UniverSheetsDataValidationPlugin,"type",r.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsDataValidationPlugin=Mt([r.DependentOn(p.UniverDataValidationPlugin),fe(1,r.Inject(r.Injector)),fe(2,r.ICommandService),fe(3,r.IConfigService)],m.UniverSheetsDataValidationPlugin);function Et(o){const e=o.get(D.SheetsSelectionsService).getCurrentSelections().map(i=>i.range);return{uid:r.generateRandomId(6),type:r.DataValidationType.DECIMAL,operator:r.DataValidationOperator.EQUAL,formula1:"100",ranges:e!=null?e:[{startColumn:0,endColumn:0,startRow:0,endRow:0}]}}const yt="data-validation.custom-formula-input",Tt="data-validation.formula-input",Ot="data-validation.list-formula-input",Ft="data-validation.checkbox-formula-input";m.AddSheetDataValidationCommand=Fe,m.BASE_FORMULA_INPUT_NAME=Tt,m.CHECKBOX_FORMULA_1=$,m.CHECKBOX_FORMULA_2=k,m.CHECKBOX_FORMULA_INPUT_NAME=Ft,m.CUSTOM_FORMULA_INPUT_NAME=yt,m.CheckboxValidator=Me,m.ClearRangeDataValidationCommand=Ae,m.DATA_VALIDATION_PLUGIN_NAME=Le,m.DateValidator=ye,m.LIST_FORMULA_INPUT_NAME=Ot,m.ListMultipleValidator=Be,m.ListValidator=ge,m.RemoveSheetAllDataValidationCommand=Ue,m.RemoveSheetDataValidationCommand=we,m.UpdateSheetDataValidationOptionsCommand=Ce,m.UpdateSheetDataValidationRangeCommand=Oe,m.UpdateSheetDataValidationSettingCommand=Ie,m.createDefaultNewRule=Et,m.deserializeListOptions=G,m.getCellValueNumber=X,m.getCellValueOrigin=L,m.getDataValidationCellValue=ze,m.getDataValidationDiffMutations=K,m.getFormulaCellData=j,m.getFormulaResult=w,m.getTransformedFormula=Y,m.isLegalFormulaResult=E,m.serializeListOptions=Ke,m.transformCheckboxValue=x,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
|
28
|
+
(function(m,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/sheets-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/sheets","rxjs","@univerjs/sheets-formula"],r):(m=typeof globalThis<"u"?globalThis:m||self,r(m.UniverSheetsDataValidation={},m.UniverCore,m.UniverDataValidation,m.UniverEngineFormula,m.UniverSheets,m.rxjs,m.UniverSheetsFormula))})(this,(function(m,r,p,y,D,U,Z){"use strict";var It=Object.defineProperty;var Ct=(m,r,p)=>r in m?It(m,r,{enumerable:!0,configurable:!0,writable:!0,value:p}):m[r]=p;var _=(m,r,p)=>Ct(m,typeof r!="symbol"?r+"":r,p);var He=Object.getOwnPropertyDescriptor,We=(o,s,e,t)=>{for(var a=t>1?void 0:t?He(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},de=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCacheService=class extends r.Disposable{constructor(e,t,a){super();_(this,"_cacheMatrix",new Map);_(this,"_dirtyRanges$",new U.Subject);_(this,"dirtyRanges$",this._dirtyRanges$.asObservable());this._commandService=e,this._univerInstanceService=t,this._sheetDataValidationModel=a,this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.SetRangeValuesMutation.id){const{cellValue:t,unitId:a,subUnitId:i}=e.params;if(t){const n=new r.ObjectMatrix(t).getDataRange();if(n.endRow===-1)return;const d=this._sheetDataValidationModel.getRules(a,i).map(c=>c.ranges).flat().map(c=>r.getIntersectRange(c,n)).filter(Boolean);d.length&&this.markRangeDirty(a,i,d,!0)}}}))}_initSheetRemove(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t;if(e.id===D.RemoveSheetMutation.id){const{unitId:a,subUnitId:i}=e.params;(t=this._cacheMatrix.get(a))==null||t.delete(i)}})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{e.type===r.UniverInstanceType.UNIVER_SHEET&&this._cacheMatrix.delete(e.getUnitId())}))}_ensureCache(e,t){let a=this._cacheMatrix.get(e);a||(a=new Map,this._cacheMatrix.set(e,a));let i=a.get(t);return i||(i=new r.ObjectMatrix,a.set(t,i)),i}ensureCache(e,t){return this._ensureCache(e,t)}addRule(e,t,a){this.markRangeDirty(e,t,a.ranges)}removeRule(e,t,a){this._deleteRange(e,t,a.ranges)}markRangeDirty(e,t,a,i){const n=this._ensureCache(e,t);a.forEach(l=>{r.Range.foreach(l,(u,d)=>{n.getValue(u,d)!==void 0&&n.setValue(u,d,void 0)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a,isSetRange:i})}_deleteRange(e,t,a){const i=this._ensureCache(e,t);a.forEach(n=>{r.Range.foreach(n,(l,u)=>{i.realDeleteValue(l,u)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a})}getValue(e,t,a,i){return this._ensureCache(e,t).getValue(a,i)}},m.DataValidationCacheService=We([de(0,r.Inject(r.ICommandService)),de(1,r.Inject(r.IUniverInstanceService)),de(2,r.Inject(p.DataValidationModel))],m.DataValidationCacheService);function w(o){var s,e;return(e=(s=o==null?void 0:o[0])==null?void 0:s[0])==null?void 0:e.v}function j(o){var s;return(s=o==null?void 0:o[0])==null?void 0:s[0]}function E(o){return!y.ERROR_TYPE_SET.has(o)}function P(o,s){var t;const e=s.getValidatorItem(o);return(t=e==null?void 0:e.offsetFormulaByRange)!=null?t:!1}var $e=Object.getOwnPropertyDescriptor,ke=(o,s,e,t)=>{for(var a=t>1?void 0:t?$e(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},H=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCustomFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();_(this,"_ruleFormulaMap",new Map);_(this,"_ruleFormulaMap2",new Map);this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=a,this._dataValidationCacheService=i,this._validatorRegistryService=n,this._initFormulaResultHandler(),this._initDirtyRanges()}dispose(){super.dispose(),this._ruleFormulaMap.clear(),this._ruleFormulaMap2.clear()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(const t in e){const a=e[t];if(this._instanceSrv.getUnitType(t)===r.UniverInstanceType.UNIVER_SHEET)for(const n in a){const l=a[n],{ruleFormulaMap:u}=this._ensureMaps(t,n);l.forEach(d=>{var g,S;const c=u.get((g=d.extra)==null?void 0:g.ruleId),h=this._dataValidationModel.getRuleById(t,n,(S=d.extra)==null?void 0:S.ruleId);h&&c&&this._dataValidationCacheService.markRangeDirty(t,n,h.ranges)})}}}))}_ensureMaps(e,t){let a=this._ruleFormulaMap.get(e),i=this._ruleFormulaMap2.get(e);a||(a=new Map,this._ruleFormulaMap.set(e,a)),i||(i=new Map,this._ruleFormulaMap2.set(e,i));let n=a.get(t);n||(n=new Map,a.set(t,n));let l=i.get(t);return l||(l=new Map,i.set(t,l)),{ruleFormulaMap:n,ruleFormulaMap2:l}}_registerFormula(e,t,a,i,n){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,i,n,{ruleId:a})}_handleDirtyRanges(e,t,a){this._dataValidationModel.getRules(e,t).forEach(n=>{const l=n.ranges;r.Rectangle.doAnyRangesIntersect(l,a)&&this.makeRuleDirty(e,t,n.uid)})}_initDirtyRanges(){this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.subscribe(e=>{e.isSetRange&&this._handleDirtyRanges(e.unitId,e.subUnitId,e.ranges)}))}deleteByRuleId(e,t,a){const{ruleFormulaMap:i,ruleFormulaMap2:n}=this._ensureMaps(e,t),l=this._dataValidationModel.getRuleById(e,t,a),u=i.get(a);if(!l||!u)return;const d=i.get(a);d&&(i.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[d.formulaId]));const c=n.get(a);c&&(n.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[c.formulaId]))}_addFormulaByRange(e,t,a,i,n,l){const{ruleFormulaMap:u,ruleFormulaMap2:d}=this._ensureMaps(e,t),c=l[0].startRow,h=l[0].startColumn;if(i&&r.isFormulaString(i)){const g=this._registerFormula(e,t,a,i,l);u.set(a,{formula:i,originCol:h,originRow:c,formulaId:g})}if(n&&r.isFormulaString(n)){const g=this._registerFormula(e,t,a,n,l);d.set(a,{formula:n,originCol:h,originRow:c,formulaId:g})}}addRule(e,t,a){if(P(a.type,this._validatorRegistryService)){const{ranges:i,formula1:n,formula2:l,uid:u}=a;this._addFormulaByRange(e,t,u,n,l,i)}}async getCellFormulaValue(e,t,a,i,n){var v,R;const{ruleFormulaMap:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return Promise.resolve(void 0);const d=await this._registerOtherFormulaService.getFormulaValue(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}async getCellFormula2Value(e,t,a,i,n){var v,R;const{ruleFormulaMap2:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return Promise.resolve(void 0);const d=await this._registerOtherFormulaService.getFormulaValue(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}getCellFormulaValueSync(e,t,a,i,n){var v,R;const{ruleFormulaMap:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return;const d=this._registerOtherFormulaService.getFormulaValueSync(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}getCellFormula2ValueSync(e,t,a,i,n){var v,R;const{ruleFormulaMap2:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return;const d=this._registerOtherFormulaService.getFormulaValueSync(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}getRuleFormulaInfo(e,t,a){const{ruleFormulaMap:i}=this._ensureMaps(e,t);return i.get(a)}makeRuleDirty(e,t,a){var l,u,d,c;const i=(u=(l=this._ruleFormulaMap.get(e))==null?void 0:l.get(t))==null?void 0:u.get(a),n=(c=(d=this._ruleFormulaMap2.get(e))==null?void 0:d.get(t))==null?void 0:c.get(a);i&&this._registerOtherFormulaService.markFormulaDirty(e,t,i.formulaId),n&&this._registerOtherFormulaService.markFormulaDirty(e,t,n.formulaId)}},m.DataValidationCustomFormulaService=ke([H(0,r.IUniverInstanceService),H(1,r.Inject(Z.RegisterOtherFormulaService)),H(2,r.Inject(p.DataValidationModel)),H(3,r.Inject(m.DataValidationCacheService)),H(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationCustomFormulaService);var xe=Object.getOwnPropertyDescriptor,qe=(o,s,e,t)=>{for(var a=t>1?void 0:t?xe(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},W=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();_(this,"_formulaRuleMap",new Map);this._instanceService=e,this._registerOtherFormulaService=t,this._dataValidationCacheService=a,this._dataValidationModel=i,this._validatorRegistryService=n,this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(const t in e){const a=e[t];if(this._instanceService.getUnitType(t)===r.UniverInstanceType.UNIVER_SHEET)for(const n in a){const l=a[n],u=this._ensureRuleFormulaMap(t,n);l.forEach(d=>{var c,h;if(u.get((c=d.extra)==null?void 0:c.ruleId)){const g=this._dataValidationModel.getRuleById(t,n,(h=d.extra)==null?void 0:h.ruleId);g&&this._dataValidationCacheService.markRangeDirty(t,n,g.ranges)}})}}}))}_ensureRuleFormulaMap(e,t){let a=this._formulaRuleMap.get(e);a||(a=new Map,this._formulaRuleMap.set(e,a));let i=a.get(t);return i||(i=new Map,a.set(t,i)),i}_registerSingleFormula(e,t,a,i){const n=[{startColumn:0,endColumn:0,startRow:0,endRow:0}];return this._registerOtherFormulaService.registerFormulaWithRange(e,t,a,n,{ruleId:i})}addRule(e,t,a){if(!P(a.type,this._validatorRegistryService)&&a.type!==r.DataValidationType.CHECKBOX){const{formula1:i,formula2:n,uid:l}=a,u=r.isFormulaString(i),d=r.isFormulaString(n);if(!u&&!d)return;const c=this._ensureRuleFormulaMap(e,t),h=[void 0,void 0];if(u){const g=this._registerSingleFormula(e,t,i,l);h[0]={id:g,text:i}}if(d){const g=this._registerSingleFormula(e,t,n,l);h[1]={id:g,text:n}}c.set(l,h)}}removeRule(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return;const[l,u]=n,d=[l==null?void 0:l.id,u==null?void 0:u.id].filter(Boolean);d.length&&this._registerOtherFormulaService.deleteFormula(e,t,d)}getRuleFormulaResult(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return Promise.resolve(null);const l=async u=>u&&this._registerOtherFormulaService.getFormulaValue(e,t,u.id);return Promise.all([l(n[0]),l(n[1])])}getRuleFormulaResultSync(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(n)return n.map(l=>{if(l)return this._registerOtherFormulaService.getFormulaValueSync(e,t,l.id)})}getRuleFormulaInfo(e,t,a){return this._ensureRuleFormulaMap(e,t).get(a)}},m.DataValidationFormulaService=qe([W(0,r.IUniverInstanceService),W(1,r.Inject(Z.RegisterOtherFormulaService)),W(2,r.Inject(m.DataValidationCacheService)),W(3,r.Inject(p.DataValidationModel)),W(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationFormulaService);function L(o){return r.getOriginCellValue(o)}function Ve(o){var s;return String((s=L(o))!=null?s:"")}class ce{constructor(s,e,t,a,i=!1){_(this,"_map");_(this,"_tree",new r.RBush);_(this,"_dirty",!0);_(this,"_buildTree",()=>{if(!this._dirty||this._disableTree)return;this._tree.clear();const s=[];this._map.forEach((e,t)=>{e.forEach(a=>{s.push({minX:a.startRow,maxX:a.endRow,minY:a.startColumn,maxY:a.endColumn,ruleId:t})})}),this._tree.load(s),this._dirty=!1});_(this,"_debonceBuildTree",r.debounce(this._buildTree,0));this._unitId=e,this._subUnitId=t,this._univerInstanceService=a,this._disableTree=i,this._map=s,this._buildTree()}get _worksheet(){var s;return(s=this._univerInstanceService.getUnit(this._unitId,r.UniverInstanceType.UNIVER_SHEET))==null?void 0:s.getSheetBySheetId(this._subUnitId)}_addRule(s,e){if(!this._worksheet)return;const t=r.Rectangle.mergeRanges(e.map(a=>r.Range.transformRange(a,this._worksheet)));this._map.forEach((a,i)=>{const n=r.Rectangle.subtractMulti(a,t);n.length===0?this._map.delete(i):this._map.set(i,n)}),this._dirty=!0,this._map.set(s,t),this._debonceBuildTree()}addRule(s){this._addRule(s.uid,s.ranges)}removeRange(s){if(!this._worksheet)return;const e=s.map(t=>r.Range.transformRange(t,this._worksheet));this._map.forEach((t,a)=>{const i=r.Rectangle.subtractMulti(t,e);i.length===0?this._map.delete(a):this._map.set(a,i)}),this._dirty=!0,this._debonceBuildTree()}_removeRule(s){this._map.delete(s),this._dirty=!0,this._debonceBuildTree()}removeRule(s){this._removeRule(s.uid)}updateRange(s,e){this._removeRule(s),this._addRule(s,e)}addRangeRules(s){s.forEach(({id:e,ranges:t})=>{if(!t.length)return;let a=this._map.get(e);a?(this._map.set(e,r.Rectangle.mergeRanges([...a,...t])),a=this._map.get(e)):(a=t,this._map.set(e,a)),this._map.forEach((i,n)=>{if(n===e)return;const l=r.Rectangle.subtractMulti(i,t);l.length===0?this._map.delete(n):this._map.set(n,l)})}),this._dirty=!0,this._debonceBuildTree()}diff(s){const e=[];let t=0;return s.forEach((a,i)=>{var u;const n=(u=this._map.get(a.uid))!=null?u:[],l=a.ranges;n.length!==0&&(n.length!==l.length||n.some((d,c)=>!r.Rectangle.equals(d,l[c])))&&e.push({type:"update",ruleId:a.uid,oldRanges:l,newRanges:r.Rectangle.sort(n),rule:a}),n.length===0&&(e.push({type:"delete",rule:a,index:i-t}),t++)}),e}diffWithAddition(s,e){const t=[];let a=0;return s.forEach((i,n)=>{var d;const l=(d=this._map.get(i.uid))!=null?d:[],u=i.ranges;l.length!==0&&(l.length!==u.length||l.some((c,h)=>!r.Rectangle.equals(c,u[h])))&&t.push({type:"update",ruleId:i.uid,oldRanges:u,newRanges:r.Rectangle.sort(l),rule:i}),l.length===0&&(t.push({type:"delete",rule:i,index:n-a}),a++)}),Array.from(e).forEach(i=>{var l;const n=(l=this._map.get(i.uid))!=null?l:[];t.push({type:"add",rule:{...i,ranges:r.Rectangle.sort(n)}})}),t}clone(){return new ce(new Map(r.Tools.deepClone(Array.from(this._map.entries()))),this._unitId,this._subUnitId,this._univerInstanceService,!0)}getValue(s,e){this._dirty&&this._buildTree();const t=this._tree.search({minX:s,maxX:s,minY:e,maxY:e});return t.length>0?t[0].ruleId:void 0}}var Qe=Object.getOwnPropertyDescriptor,Ge=(o,s,e,t)=>{for(var a=t>1?void 0:t?Qe(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},A=(o,s)=>(e,t)=>s(e,t,o);m.SheetDataValidationModel=class extends r.Disposable{constructor(e,t,a,i,n,l,u){super();_(this,"_ruleMatrixMap",new Map);_(this,"_validStatusChange$",new U.Subject);_(this,"_ruleChange$",new U.Subject);_(this,"ruleChange$",this._ruleChange$.asObservable());_(this,"validStatusChange$",this._validStatusChange$.asObservable());this._dataValidationModel=e,this._univerInstanceService=t,this._dataValidatorRegistryService=a,this._dataValidationCacheService=i,this._dataValidationFormulaService=n,this._dataValidationCustomFormulaService=l,this._commandService=u,this._initRuleUpdateListener(),this.disposeWithMe(()=>{this._ruleChange$.complete(),this._validStatusChange$.complete()}),this._initUniverInstanceListener()}_initUniverInstanceListener(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{this._ruleMatrixMap.delete(e.getUnitId())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.RemoveSheetMutation.id){const{unitId:t,subUnitId:a}=e.params,i=this._ruleMatrixMap.get(t);i&&i.delete(a)}}))}_initRuleUpdateListener(){const e=this._dataValidationModel.getAll();for(const[t,a]of e)for(const[i,n]of a)for(const l of n)this._addRule(t,i,l),this._ruleChange$.next({type:"add",unitId:t,subUnitId:i,rule:l,source:"patched"});this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(t=>{switch(t.type){case"add":this._addRule(t.unitId,t.subUnitId,t.rule);break;case"update":this._updateRule(t.unitId,t.subUnitId,t.rule.uid,t.oldRule,t.updatePayload);break;case"remove":this._removeRule(t.unitId,t.subUnitId,t.rule);break}this._ruleChange$.next(t)}))}_ensureRuleMatrix(e,t){let a=this._ruleMatrixMap.get(e);a||(a=new Map,this._ruleMatrixMap.set(e,a));let i=a.get(t);return i||(i=new ce(new Map,e,t,this._univerInstanceService),a.set(t,i)),i}_addRuleSideEffect(e,t,a){this._ensureRuleMatrix(e,t).addRule(a),this._dataValidationCacheService.addRule(e,t,a),this._dataValidationFormulaService.addRule(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,a)}_addRule(e,t,a){(Array.isArray(a)?a:[a]).forEach(n=>{this._addRuleSideEffect(e,t,n)})}_updateRule(e,t,a,i,n){const l=this._ensureRuleMatrix(e,t),u={...i,...n.payload};n.type===p.UpdateRuleType.RANGE?l.updateRange(a,n.payload):n.type===p.UpdateRuleType.ALL&&l.updateRange(a,n.payload.ranges),this._dataValidationCacheService.removeRule(e,t,i),this._dataValidationCacheService.addRule(e,t,u),this._dataValidationFormulaService.removeRule(e,t,i.uid),this._dataValidationFormulaService.addRule(e,t,u),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,u)}_removeRule(e,t,a){this._ensureRuleMatrix(e,t).removeRule(a),this._dataValidationCacheService.removeRule(e,t,a),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a.uid)}getValidator(e){return this._dataValidatorRegistryService.getValidatorItem(e)}getRuleIdByLocation(e,t,a,i){return this._ensureRuleMatrix(e,t).getValue(a,i)}getRuleByLocation(e,t,a,i){const n=this.getRuleIdByLocation(e,t,a,i);if(n)return this._dataValidationModel.getRuleById(e,t,n)}validator(e,t,a){const{col:i,row:n,unitId:l,subUnitId:u,worksheet:d}=t,c=(R,V)=>{a&&a(R,V),V&&this._validStatusChange$.next({unitId:l,subUnitId:u,ruleId:e.uid,status:R,row:n,col:i})},h=d.getCellValueOnly(n,i),g=this.getValidator(e.type),S=d.getCellRaw(n,i),v=L(S);if(g){const R=this._dataValidationCacheService.ensureCache(l,u),V=R.getValue(n,i);return V==null?(R.setValue(n,i,r.DataValidationStatus.VALIDATING),g.validator({value:v,unitId:l,subUnitId:u,row:n,column:i,worksheet:t.worksheet,workbook:t.workbook,interceptValue:L(h),t:S==null?void 0:S.t},e).then(f=>{const M=f?r.DataValidationStatus.VALID:r.DataValidationStatus.INVALID,T=R.getValue(n,i);M===r.DataValidationStatus.VALID?R.realDeleteValue(n,i):R.setValue(n,i,M),c(M,V!==T)}),r.DataValidationStatus.VALIDATING):(c(V!=null?V:r.DataValidationStatus.VALID,!1),V!=null?V:r.DataValidationStatus.VALID)}else return c(r.DataValidationStatus.VALID,!1),r.DataValidationStatus.VALID}getRuleObjectMatrix(e,t){return this._ensureRuleMatrix(e,t)}getRuleById(e,t,a){return this._dataValidationModel.getRuleById(e,t,a)}getRuleIndex(e,t,a){return this._dataValidationModel.getRuleIndex(e,t,a)}getRules(e,t){return[...this._dataValidationModel.getRules(e,t)]}getUnitRules(e){return this._dataValidationModel.getUnitRules(e)}deleteUnitRules(e){return this._dataValidationModel.deleteUnitRules(e)}getSubUnitIds(e){return this._dataValidationModel.getSubUnitIds(e)}getAll(){return this._dataValidationModel.getAll()}},m.SheetDataValidationModel=Ge([A(0,r.Inject(p.DataValidationModel)),A(1,r.IUniverInstanceService),A(2,r.Inject(p.DataValidatorRegistryService)),A(3,r.Inject(m.DataValidationCacheService)),A(4,r.Inject(m.DataValidationFormulaService)),A(5,r.Inject(m.DataValidationCustomFormulaService)),A(6,r.ICommandService)],m.SheetDataValidationModel);const $=1,k=0;function De(o,s){return r.Tools.isBlank(o)?s.t("dataValidation.validFail.value"):r.isFormulaString(o)?s.t("dataValidation.validFail.primitive"):""}const x=o=>r.Tools.isDefine(o)&&String(o).toLowerCase()==="true"?"1":String(o).toLowerCase()==="false"?"0":o;class Me extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.CHECKBOX);_(this,"title","dataValidation.checkbox.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",41);_(this,"offsetFormulaByRange",!1);_(this,"_formulaService",this.injector.get(m.DataValidationFormulaService));_(this,"skipDefaultFontRender",(e,t,a)=>{const{unitId:i,subUnitId:n}=a,{formula1:l,formula2:u}=this.parseFormulaSync(e,i,n),d=`${t!=null?t:""}`;return!d||d===`${l}`||d===`${u}`})}validatorFormula(e,t,a){const{formula1:i,formula2:n}=e,l=i===n;if(r.Tools.isBlank(i)&&r.Tools.isBlank(n))return{success:!0};if(l)return{success:!1,formula1:this.localeService.t("dataValidation.validFail.checkboxEqual"),formula2:this.localeService.t("dataValidation.validFail.checkboxEqual")};const u=De(i,this.localeService),d=De(n,this.localeService);return{success:!u&&!d,formula1:u,formula2:d}}async parseFormula(e,t,a){var h,g,S,v;const{formula1:i=$,formula2:n=k}=e,l=await this._formulaService.getRuleFormulaResult(t,a,e.uid),u=r.isFormulaString(i)?w((g=(h=l==null?void 0:l[0])==null?void 0:h.result)==null?void 0:g[0][0]):i,d=r.isFormulaString(n)?w((v=(S=l==null?void 0:l[1])==null?void 0:S.result)==null?void 0:v[0][0]):n,c=E(String(u))&&E(String(d));return{formula1:x(u),formula2:x(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}getExtraStyle(e,t){return{tb:r.WrapStrategy.CLIP}}parseFormulaSync(e,t,a){var h,g,S,v;const{formula1:i=$,formula2:n=k}=e,l=this._formulaService.getRuleFormulaResultSync(t,a,e.uid),u=r.isFormulaString(i)?w((g=(h=l==null?void 0:l[0])==null?void 0:h.result)==null?void 0:g[0][0]):i,d=r.isFormulaString(n)?w((v=(S=l==null?void 0:l[1])==null?void 0:S.result)==null?void 0:v[0][0]):n,c=E(String(u))&&E(String(d));return{formula1:x(u),formula2:x(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}async isValidType(e,t,a){const{value:i,unitId:n,subUnitId:l}=e,{formula1:u,formula2:d,originFormula1:c,originFormula2:h}=await this.parseFormula(a,n,l);return!r.Tools.isDefine(u)||!r.Tools.isDefine(d)?!0:r.Tools.isDefine(i)&&(String(i)===String(u)||String(i)===String(d)||String(i)===String(c!=null?c:"")||String(i)===String(h!=null?h:""))}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.checkbox.error")}generateRuleName(e){return this.titleStr}}const Ye={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.operators.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.operators.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.operators.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.operators.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.operators.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.operators.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.operators.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.operators.notEqual"};r.DataValidationOperator.BETWEEN+"",r.DataValidationOperator.EQUAL+"",r.DataValidationOperator.GREATER_THAN+"",r.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",r.DataValidationOperator.LESS_THAN+"",r.DataValidationOperator.LESS_THAN_OR_EQUAL+"",r.DataValidationOperator.NOT_BETWEEN+"",r.DataValidationOperator.NOT_EQUAL+"";const Ee={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.ruleName.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.ruleName.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.ruleName.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.ruleName.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.ruleName.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.ruleName.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.ruleName.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.ruleName.notEqual",NONE:"dataValidation.date.ruleName.legal"},Xe={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.errorMsg.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.errorMsg.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.errorMsg.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.errorMsg.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.errorMsg.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.errorMsg.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.errorMsg.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.errorMsg.notEqual",NONE:"dataValidation.date.errorMsg.legal"},J=[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.NOT_BETWEEN],q="{FORMULA1}",Q="{FORMULA2}";function Ke(o){return o.filter(Boolean).join(",")}function G(o){return o.split(",").filter(Boolean)}function ze(o){const s=L(o);return s==null?"":s.toString()}function Y(o,s,e){const{formula1:t,formula2:a}=s,i=s.ranges[0].startRow,n=s.ranges[0].startColumn,l=e.row-i,u=e.col-n,d=r.isFormulaString(t)?o.moveFormulaRefOffset(t,u,l,!0):t,c=r.isFormulaString(a)?o.moveFormulaRefOffset(a,u,l,!0):a;return{transformedFormula1:d,transformedFormula2:c}}const me=o=>{var e,t;if(o==null||typeof o=="boolean")return;if(typeof o=="number"||!Number.isNaN(+o))return+o;const s=(e=r.numfmt.parseDate(o))==null?void 0:e.v;return r.Tools.isDefine(s)?s:(t=r.numfmt.parseDate(r.dayjs(o).format("YYYY-MM-DD HH:mm:ss")))==null?void 0:t.v};class ye extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.DATE);_(this,"title","dataValidation.date.title");_(this,"order",40);_(this,"operators",[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.EQUAL,r.DataValidationOperator.GREATER_THAN,r.DataValidationOperator.GREATER_THAN_OR_EQUAL,r.DataValidationOperator.LESS_THAN,r.DataValidationOperator.LESS_THAN_OR_EQUAL,r.DataValidationOperator.NOT_BETWEEN,r.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder))}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=E(String(l==null?void 0:l.v))&&E(String(u==null?void 0:u.v));return{formula1:me(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:me(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}async isValidType(e){const{interceptValue:t,value:a}=e;return typeof a=="number"&&typeof t=="string"||typeof t=="string"?!!r.numfmt.parseDate(t):!1}_validatorSingleFormula(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)||!!(e&&r.numfmt.parseDate(e)))}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=this._validatorSingleFormula(e.formula1),l=this.localeService.t("dataValidation.validFail.date");if(J.includes(i)){const d=this._validatorSingleFormula(e.formula2);return{success:n&&d,formula1:n?void 0:l,formula2:d?void 0:l}}return{success:n,formula1:n?void 0:l}}normalizeFormula(e,t,a){const{formula1:i,formula2:n,bizInfo:l}=e,u=d=>{var h;if(!d)return d;let c;if(!Number.isNaN(+d))c=r.numfmt.dateFromSerial(+d);else{const g=(h=r.numfmt.parseDate(d))==null?void 0:h.v;if(g==null)return"";c=r.numfmt.dateFromSerial(g)}return r.dayjs(`${c[0]}/${c[1]}/${c[2]} ${c[3]}:${c[4]}:${c[5]}`).format(l!=null&&l.showTime?"YYYY-MM-DD HH:mm:ss":"YYYY-MM-DD")};return{formula1:r.isFormulaString(i)?i:u(`${i}`),formula2:r.isFormulaString(n)?n:u(`${n}`)}}transform(e,t,a){const{value:i}=e;return{...e,value:me(i)}}get operatorNames(){return this.operators.map(e=>this.localeService.t(Ye[e]))}generateRuleName(e){var a,i;if(!e.operator)return this.localeService.t(Ee.NONE);const t=this.localeService.t(Ee[e.operator]).replace(q,(a=e.formula1)!=null?a:"").replace(Q,(i=e.formula2)!=null?i:"");return`${this.titleStr} ${t}`}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(Xe[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}r.DataValidationOperator.BETWEEN+"",r.DataValidationOperator.EQUAL+"",r.DataValidationOperator.GREATER_THAN+"",r.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",r.DataValidationOperator.LESS_THAN+"",r.DataValidationOperator.LESS_THAN_OR_EQUAL+"",r.DataValidationOperator.NOT_BETWEEN+"",r.DataValidationOperator.NOT_EQUAL+"",r.DataValidationOperator.BETWEEN+"",r.DataValidationOperator.EQUAL+"",r.DataValidationOperator.GREATER_THAN+"",r.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",r.DataValidationOperator.LESS_THAN+"",r.DataValidationOperator.LESS_THAN_OR_EQUAL+"",r.DataValidationOperator.NOT_BETWEEN+"",r.DataValidationOperator.NOT_EQUAL+"";const ee={[r.DataValidationOperator.BETWEEN]:"dataValidation.errorMsg.between",[r.DataValidationOperator.EQUAL]:"dataValidation.errorMsg.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.errorMsg.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.errorMsg.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.errorMsg.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.errorMsg.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.errorMsg.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.errorMsg.notEqual",NONE:"dataValidation.errorMsg.legal"};function X(o){return+o}class Ze extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"id",r.DataValidationType.DECIMAL);_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"title","dataValidation.decimal.title");_(this,"order",20);_(this,"operators",[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.EQUAL,r.DataValidationOperator.GREATER_THAN,r.DataValidationOperator.GREATER_THAN_OR_EQUAL,r.DataValidationOperator.LESS_THAN,r.DataValidationOperator.LESS_THAN_OR_EQUAL,r.DataValidationOperator.NOT_BETWEEN,r.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"])}_isFormulaOrNumber(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e))}async isValidType(e,t,a){const{value:i}=e;return!Number.isNaN(X(i))}transform(e,t,a){const{value:i}=e;return{...e,value:X(i)}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=E(String(l==null?void 0:l.v))&&E(String(u==null?void 0:u.v));return{formula1:this._parseNumber(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:this._parseNumber(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrNumber(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrNumber(e.formula2),u=J.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:n?"":d}}generateRuleErrorMessage(e,t){if(!e.operator)return this.localeService.t(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function he(o){if(!o)return[];const s=new Set;return o.forEach(e=>{e.forEach(t=>{var i,n;const a=L(t);if(a!=null){if(typeof a!="string"&&typeof(t==null?void 0:t.s)=="object"&&((n=(i=t.s)==null?void 0:i.n)!=null&&n.pattern)){s.add(r.numfmt.format(t.s.n.pattern,a,{throws:!1}));return}E(a.toString())&&s.add(a.toString())}})}),[...s]}const Je=["if","indirect","choose","offset"];function et(o,s){if(!r.isFormulaString(o)||y.isReferenceString(o.slice(1)))return!0;const t=s.sequenceNodesBuilder(o);return t&&t.some(a=>typeof a=="object"&&a.nodeType===y.sequenceNodeType.FUNCTION&&Je.indexOf(a.token.toLowerCase())>-1)}function tt(o,s){const{formula1:e="",ranges:t}=o;if(y.isReferenceString(e.slice(1))){const i=y.deserializeRangeWithSheet(e.slice(1));if((!i.sheetName||i.sheetName===s)&&t.some(n=>r.Rectangle.intersects(n,i.range)))return!0}return!1}class ge extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"formulaService",this.injector.get(m.DataValidationFormulaService));_(this,"_lexer",this.injector.get(y.LexerTreeBuilder));_(this,"_univerInstanceService",this.injector.get(r.IUniverInstanceService));_(this,"order",50);_(this,"offsetFormulaByRange",!1);_(this,"id",r.DataValidationType.LIST);_(this,"title","dataValidation.list.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"skipDefaultFontRender",e=>e.renderMode!==r.DataValidationRenderMode.TEXT)}validatorFormula(e,t,a){var d,c,h;const i=!r.Tools.isBlank(e.formula1),n=et((d=e.formula1)!=null?d:"",this._lexer),l=(h=(c=this._univerInstanceService.getUnit(t,r.UniverInstanceType.UNIVER_SHEET))==null?void 0:c.getSheetBySheetId(a))==null?void 0:h.getName(),u=tt(e,l!=null?l:"");return{success:!!(i&&n&&!u),formula1:i?n?u?this.localeService.t("dataValidation.validFail.listIntersects"):void 0:this.localeService.t("dataValidation.validFail.listInvalid"):this.localeService.t("dataValidation.validFail.list")}}getExtraStyle(e,t,{style:a}){var n;const i=(n=a.tb!==r.WrapStrategy.OVERFLOW?a.tb:r.WrapStrategy.CLIP)!=null?n:r.WrapStrategy.WRAP;if(e.type===r.DataValidationType.LIST&&(e.renderMode===r.DataValidationRenderMode.ARROW||e.renderMode===r.DataValidationRenderMode.TEXT)){const l=this.getListWithColorMap(e),u=`${t!=null?t:""}`,d=l[u];if(d)return{bg:{rgb:d},tb:i}}return{tb:i}}parseCellValue(e){const t=e.toString();return G(t)}async parseFormula(e,t,a){var u,d;const i=await this.formulaService.getRuleFormulaResult(t,a,e.uid),n=w((d=(u=i==null?void 0:i[0])==null?void 0:u.result)==null?void 0:d[0][0]);return{formula1:void 0,formula2:void 0,isFormulaValid:E(String(n))}}async isValidType(e,t,a){var g,S;const{value:i,unitId:n,subUnitId:l}=e,{formula1:u=""}=a,d=await this.formulaService.getRuleFormulaResult(n,l,a.uid),c=r.isFormulaString(u)?he((S=(g=d==null?void 0:d[0])==null?void 0:g.result)==null?void 0:S[0][0]):G(u);return this.parseCellValue(i).every(v=>c.includes(v))}generateRuleName(){return this.localeService.t("dataValidation.list.name")}generateRuleErrorMessage(){return this.localeService.t("dataValidation.list.error")}getList(e,t,a){var g,S,v,R;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(g=t?n.getUniverSheetInstance(t):void 0)!=null?g:n.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(S=a?l.getSheetBySheetId(a):void 0)!=null?S:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),h=this.formulaService.getRuleFormulaResultSync(d,c,e.uid);return r.isFormulaString(i)?he((R=(v=h==null?void 0:h[0])==null?void 0:v.result)==null?void 0:R[0][0]):G(i)}async getListAsync(e,t,a){var g,S,v,R;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(g=t?n.getUniverSheetInstance(t):void 0)!=null?g:n.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(S=a?l.getSheetBySheetId(a):void 0)!=null?S:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),h=await this.formulaService.getRuleFormulaResult(d,c,e.uid);return r.isFormulaString(i)?he((R=(v=h==null?void 0:h[0])==null?void 0:v.result)==null?void 0:R[0][0]):G(i)}getListWithColor(e,t,a){const i=this.getList(e,t,a),n=(e.formula2||"").split(",");return i.map((l,u)=>({label:l,color:n[u]}))}getListWithColorMap(e,t,a){const i=this.getListWithColor(e,t,a),n={};return i.forEach(l=>{l.color&&(n[l.label]=l.color)}),n}}class at extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.TEXT_LENGTH);_(this,"title","dataValidation.textLength.title");_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"order",30);_(this,"operators",[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.EQUAL,r.DataValidationOperator.GREATER_THAN,r.DataValidationOperator.GREATER_THAN_OR_EQUAL,r.DataValidationOperator.LESS_THAN,r.DataValidationOperator.LESS_THAN_OR_EQUAL,r.DataValidationOperator.NOT_BETWEEN,r.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService))}_isFormulaOrInt(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!1};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=J.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:d}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=E(String(l==null?void 0:l.v))&&E(String(u==null?void 0:u.v));return{formula1:this._parseNumber(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:this._parseNumber(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}transform(e,t,a){return{...e,value:e.value.toString().length}}async isValidType(e,t,a){const{value:i}=e;return typeof i=="string"||typeof i=="number"}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(p.TextLengthErrorTitleMap[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function Te(o){var e,t;return o?o.p?!((t=(e=o.p.body)==null?void 0:e.dataStream)!=null?t:"").slice(0,-2).trim():r.Tools.isBlank(o.v):!0}function K(o,s,e,t,a="command",i=!0){const n=t.get(y.LexerTreeBuilder),l=t.get(p.DataValidatorRegistryService),u=[],d=[],c=t.get(m.SheetDataValidationModel),h=t.get(r.IUniverInstanceService),g=D.getSheetCommandTarget(h,{unitId:o,subUnitId:s});if(!g)return{redoMutations:u,undoMutations:d};const{worksheet:S}=g,v=new r.ObjectMatrix;let R=!1;function V(f,M){i&&f.forEach(T=>{r.Range.foreach(T,(O,I)=>{const F=S.getCellRaw(O,I),B=Ve(F);(Te(F)||B===M)&&!(F!=null&&F.p)&&(R=!0,v.setValue(O,I,{v:M,p:null}))})})}if(e.forEach(f=>{switch(f.type){case"delete":u.push({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.rule.uid,source:a}}),d.unshift({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:f.rule,index:f.index,source:a}});break;case"update":{if(P(f.rule.type,l)){const T=f.oldRanges[0].startRow,O=f.oldRanges[0].startColumn,I=f.newRanges[0].startRow,F=f.newRanges[0].startColumn,B=I-T,oe=F-O,se=r.isFormulaString(f.rule.formula1)?n.moveFormulaRefOffset(f.rule.formula1,oe,B):f.rule.formula1,le=r.isFormulaString(f.rule.formula2)?n.moveFormulaRefOffset(f.rule.formula2,oe,B):f.rule.formula2;se!==f.rule.formula1||le!==f.rule.formula2||!r.isRangesEqual(f.newRanges,f.oldRanges)?(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:se,formula2:le,ranges:f.newRanges}}}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:f.rule.formula1,formula2:f.rule.formula2,ranges:f.oldRanges}}}})):(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.oldRanges},source:a}}))}else u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.oldRanges},source:a}});const M=c.getRuleById(o,s,f.ruleId);if(M&&M.type===r.DataValidationType.CHECKBOX){const O=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(M,o,s);V(f.newRanges,O.formula2)}break}case"add":{if(u.push({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:f.rule,source:a}}),d.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.rule.uid,source:a}}),f.rule.type===r.DataValidationType.CHECKBOX){const T=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(f.rule,o,s);V(f.rule.ranges,T.originFormula2)}break}}}),R){const f={id:D.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:s,cellValue:v.getData()}},M={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(t,f.params)};u.push(f),d.push(M)}return{redoMutations:u,undoMutations:d}}const Oe={type:r.CommandType.COMMAND,id:"sheet.command.updateDataValidationRuleRange",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ranges:a,ruleId:i}=s,n=o.get(m.SheetDataValidationModel),l=o.get(r.ICommandService),u=o.get(r.IUndoRedoService);if(!n.getRuleById(e,t,i))return!1;const c=n.getRuleObjectMatrix(e,t).clone();c.updateRange(i,a);const h=c.diff(n.getRules(e,t)),{redoMutations:g,undoMutations:S}=K(e,t,h,o);return u.pushUndoRedo({undoMutations:S,redoMutations:g,unitID:e}),r.sequenceExecute(g,l),!0}},Fe={type:r.CommandType.COMMAND,id:"sheet.command.addDataValidation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,rule:a}=s,i=o.get(m.SheetDataValidationModel),n=o.get(r.ICommandService),l=o.get(r.IUndoRedoService),u=i.getRuleObjectMatrix(e,t).clone();u.addRule(a);const d=u.diff(i.getRules(e,t)),c=i.getValidator(a.type),h={unitId:e,subUnitId:t,rule:{...a,...c==null?void 0:c.normalizeFormula(a,e,t)}},{redoMutations:g,undoMutations:S}=K(e,t,d,o);return g.push({id:p.AddDataValidationMutation.id,params:h}),S.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:t,ruleId:a.uid}}),l.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:S}),r.sequenceExecute(g,n),!0}},Ie={type:r.CommandType.COMMAND,id:"sheets.command.update-data-validation-setting",handler(o,s){if(!s)return!1;const e=o.get(r.ICommandService),t=o.get(r.IUndoRedoService),a=o.get(m.SheetDataValidationModel),i=o.get(p.DataValidatorRegistryService),{unitId:n,subUnitId:l,ruleId:u,setting:d}=s,c=i.getValidatorItem(d.type);if(!c)return!1;const h=a.getRuleById(n,l,u);if(!h)return!1;const g={...h,...d};if(!c.validatorFormula(g,n,l).success)return!1;const S={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:{...d,...c.normalizeFormula(g,n,l)}}},v=[{id:p.UpdateDataValidationMutation.id,params:S}],R={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:p.getRuleSetting(h)}},V=[{id:p.UpdateDataValidationMutation.id,params:R}];if(d.type===r.DataValidationType.CHECKBOX){const M=h.ranges,T=o.get(r.IUniverInstanceService),O=D.getSheetCommandTarget(T,{unitId:n,subUnitId:l});if(O){const I=new r.ObjectMatrix,{worksheet:F}=O,{formula2:B=k,formula1:oe=$}=h,{formula2:se=k,formula1:le=$}=d;let ve=!1;if(M.forEach(ue=>{r.Range.foreach(ue,(z,Re)=>{const C=F.getCellRaw(z,Re),Pe=Ve(C);(Te(C)||Pe===String(B))&&!(C!=null&&C.p)?(I.setValue(z,Re,{v:se,p:null}),ve=!0):Pe===String(oe)&&!(C!=null&&C.p)&&(I.setValue(z,Re,{v:le,p:null}),ve=!0)})}),ve){const ue={id:D.SetRangeValuesMutation.id,params:{unitId:n,subUnitId:l,cellValue:I.getData()}},z={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(o,ue.params)};v.push(ue),V.push(z)}}}return r.sequenceExecute(v,e).result?(t.pushUndoRedo({unitID:n,redoMutations:v,undoMutations:V}),!0):!1}},Ce={type:r.CommandType.COMMAND,id:"sheets.command.update-data-validation-options",handler(o,s){if(!s)return!1;const e=o.get(r.ICommandService),t=o.get(r.IUndoRedoService),a=o.get(m.SheetDataValidationModel),{unitId:i,subUnitId:n,ruleId:l,options:u}=s,d=a.getRuleById(i,n,l);if(!d)return!1;const c={unitId:i,subUnitId:n,ruleId:l,payload:{type:p.UpdateRuleType.OPTIONS,payload:u}},h=[{id:p.UpdateDataValidationMutation.id,params:c}],g={unitId:i,subUnitId:n,ruleId:l,payload:{type:p.UpdateRuleType.OPTIONS,payload:p.getRuleOptions(d)}},S=[{id:p.UpdateDataValidationMutation.id,params:g}];return t.pushUndoRedo({unitID:i,redoMutations:h,undoMutations:S}),e.executeCommand(p.UpdateDataValidationMutation.id,c),!0}},Ae={type:r.CommandType.COMMAND,id:"sheets.command.clear-range-data-validation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ranges:a}=s,i=o.get(r.ICommandService),n=o.get(r.IUniverInstanceService),l=D.getSheetCommandTarget(n,{unitId:e,subUnitId:t}),u=o.get(m.SheetDataValidationModel);if(!l)return!1;const d=o.get(r.IUndoRedoService),c=u.getRuleObjectMatrix(e,t).clone();c.removeRange(a);const h=c.diff(u.getRules(e,t)),{redoMutations:g,undoMutations:S}=K(e,t,h,o);return d.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:S}),r.sequenceExecute(g,i).result}},Ue={type:r.CommandType.COMMAND,id:"sheet.command.remove-all-data-validation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t}=s,a=o.get(r.ICommandService),i=o.get(m.SheetDataValidationModel),n=o.get(r.IUndoRedoService),l=[...i.getRules(e,t)],u={unitId:e,subUnitId:t,ruleId:l.map(h=>h.uid)},d=[{id:p.RemoveDataValidationMutation.id,params:u}],c=[{id:p.AddDataValidationMutation.id,params:{unitId:e,subUnitId:t,rule:l}}];return n.pushUndoRedo({redoMutations:d,undoMutations:c,unitID:e}),a.executeCommand(p.RemoveDataValidationMutation.id,u),!0}},it=(o,s)=>{const e=o.get(m.SheetDataValidationModel),{unitId:t,subUnitId:a,ruleId:i,source:n}=s;if(Array.isArray(i)){const u=i.map(d=>e.getRuleById(t,a,d)).filter(Boolean);return[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:u,source:n}}]}return[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:{...e.getRuleById(t,a,i)},index:e.getRuleIndex(t,a,i)}}]},we={type:r.CommandType.COMMAND,id:"sheet.command.remove-data-validation-rule",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ruleId:a}=s,i=o.get(r.ICommandService),n=o.get(r.IUndoRedoService),l=o.get(m.SheetDataValidationModel),u=[{id:p.RemoveDataValidationMutation.id,params:s}],d=[{id:p.AddDataValidationMutation.id,params:{unitId:e,subUnitId:t,rule:{...l.getRuleById(e,t,a)},index:l.getRuleIndex(e,t,a)}}];return n.pushUndoRedo({undoMutations:d,redoMutations:u,unitID:s.unitId}),i.executeCommand(p.RemoveDataValidationMutation.id,s),!0}},Le="SHEET_DATA_VALIDATION_PLUGIN";var be=(o=>(o[o.View=0]="View",o[o.Edit=1]="Edit",o[o.ManageCollaborator=2]="ManageCollaborator",o[o.Print=3]="Print",o[o.Duplicate=4]="Duplicate",o[o.Comment=5]="Comment",o[o.Copy=6]="Copy",o[o.Share=7]="Share",o[o.Export=8]="Export",o[o.MoveWorksheet=9]="MoveWorksheet",o[o.DeleteWorksheet=10]="DeleteWorksheet",o[o.HideWorksheet=11]="HideWorksheet",o[o.RenameWorksheet=12]="RenameWorksheet",o[o.CreateWorksheet=13]="CreateWorksheet",o[o.SetWorksheetStyle=14]="SetWorksheetStyle",o[o.EditWorksheetCell=15]="EditWorksheetCell",o[o.InsertHyperlink=16]="InsertHyperlink",o[o.Sort=17]="Sort",o[o.Filter=18]="Filter",o[o.PivotTable=19]="PivotTable",o[o.FloatImg=20]="FloatImg",o[o.History=21]="History",o[o.RwHgtClWdt=22]="RwHgtClWdt",o[o.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",o[o.ViewFilter=24]="ViewFilter",o[o.MoveSheet=25]="MoveSheet",o[o.DeleteSheet=26]="DeleteSheet",o[o.HideSheet=27]="HideSheet",o[o.CopySheet=28]="CopySheet",o[o.RenameSheet=29]="RenameSheet",o[o.CreateSheet=30]="CreateSheet",o[o.SelectProtectedCells=31]="SelectProtectedCells",o[o.SelectUnProtectedCells=32]="SelectUnProtectedCells",o[o.SetCellStyle=33]="SetCellStyle",o[o.SetCellValue=34]="SetCellValue",o[o.SetRowStyle=35]="SetRowStyle",o[o.SetColumnStyle=36]="SetColumnStyle",o[o.InsertRow=37]="InsertRow",o[o.InsertColumn=38]="InsertColumn",o[o.DeleteRow=39]="DeleteRow",o[o.DeleteColumn=40]="DeleteColumn",o[o.EditExtraObject=41]="EditExtraObject",o[o.Delete=42]="Delete",o[o.RecoverHistory=43]="RecoverHistory",o[o.ViewHistory=44]="ViewHistory",o[o.CreatePermissionObject=45]="CreatePermissionObject",o[o.UNRECOGNIZED=-1]="UNRECOGNIZED",o))(be||{}),rt=Object.getOwnPropertyDescriptor,nt=(o,s,e,t)=>{for(var a=t>1?void 0:t?rt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},pe=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaController=class extends r.Disposable{constructor(s,e,t){super(),this._univerInstanceService=s,this._permissionService=e,this._lexerTreeBuilder=t}getFormulaRefCheck(s){var t,a;const e=this._lexerTreeBuilder.sequenceNodesBuilder(s);if(!e)return!0;for(let i=0;i<e.length;i++){const n=e[i];if(typeof n=="string")continue;const{token:l}=n,u=y.deserializeRangeWithSheetWithCache(l),d=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);let c=d.getActiveSheet();const h=d.getUnitId();if(u.sheetName){if(c=d.getSheetBySheetName(u.sheetName),!c)return!1;const V=c==null?void 0:c.getSheetId();if(!this._permissionService.getPermissionPoint(new D.WorksheetViewPermission(h,V).id))return!1}if(!c)return!1;const{startRow:g,endRow:S,startColumn:v,endColumn:R}=u.range;for(let V=g;V<=S;V++)for(let f=v;f<=R;f++){const M=(a=(t=c.getCell(V,f))==null?void 0:t.selectionProtection)==null?void 0:a[0];if((M==null?void 0:M[be.View])===!1)return!1}}return!0}},m.DataValidationFormulaController=nt([pe(0,r.IUniverInstanceService),pe(1,r.IPermissionService),pe(2,r.Inject(y.LexerTreeBuilder))],m.DataValidationFormulaController);const ot="sheets-data-validation.config",Ne={};var st=Object.getOwnPropertyDescriptor,lt=(o,s,e,t)=>{for(var a=t>1?void 0:t?st(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},_e=(o,s)=>(e,t)=>s(e,t,o);let te=class extends r.Disposable{constructor(s,e,t){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(s,e,t)=>{P(t.type,this._validatorRegistryService)&&this.register(s,e,t)});this._dataValidationModel=s,this._formulaRefRangeService=e,this._validatorRegistryService=t,this._initRefRange()}_getIdWithUnitId(s,e,t){return`${s}_${e}_${t}`}register(s,e,t){const a=t.ranges,i=t.formula1,n=t.formula2,l=this._formulaRefRangeService.registerRangeFormula(s,e,a,[i!=null?i:"",n!=null?n:""],d=>{if(d.length===0)return{undos:[{id:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:t,source:"patched"}}],redos:[{id:p.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,source:"patched"}}]};const c=[],h=[],g=d[0];c.push({id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:g.ranges,formula1:g.formulas[0],formula2:g.formulas[1]}},source:"patched"}}),h.push({id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:a,formula1:i,formula2:n}},source:"patched"}});for(let S=1;S<d.length;S++){const v=d[S],R=r.generateRandomId();c.push({id:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:{...t,uid:R,formula1:v.formulas[0],formula2:v.formulas[1],ranges:v.ranges},source:"patched"}}),h.push({id:p.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:R,source:"patched"}})}return{undos:h,redos:c}}),u=this._getIdWithUnitId(s,e,t.uid);this._disposableMap.set(u,l)}_initRefRange(){const s=this._dataValidationModel.getAll();for(const[e,t]of s)for(const[a,i]of t)for(const n of i)this.registerRule(e,a,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{const{unitId:t,subUnitId:a,rule:i}=e;switch(e.type){case"add":{const n=e.rule;this.registerRule(e.unitId,e.subUnitId,n);break}case"remove":{const n=this._disposableMap.get(this._getIdWithUnitId(t,a,i.uid));n&&n.dispose();break}case"update":{const n=e.rule,l=this._disposableMap.get(this._getIdWithUnitId(t,a,n.uid));l&&l.dispose(),this.registerRule(e.unitId,e.subUnitId,n);break}}})),this.disposeWithMe(r.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};te=lt([_e(0,r.Inject(m.SheetDataValidationModel)),_e(1,r.Inject(Z.FormulaRefRangeService)),_e(2,r.Inject(p.DataValidatorRegistryService))],te);var ut=Object.getOwnPropertyDescriptor,dt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ut(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},b=(o,s)=>(e,t)=>s(e,t,o);let ae=class extends r.Disposable{constructor(s,e,t,a,i,n){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(s,e,t)=>{P(t.type,this._validatorRegistryService)||(this.register(s,e,t),this.registerFormula(s,e,t))});this._dataValidationModel=s,this._injector=e,this._refRangeService=t,this._dataValidationFormulaService=a,this._formulaRefRangeService=i,this._validatorRegistryService=n,this._initRefRange()}_getIdWithUnitId(s,e,t){return`${s}_${e}_${t}`}registerFormula(s,e,t){var d;const a=t.uid,i=this._getIdWithUnitId(s,e,a),n=(d=this._disposableMap.get(i))!=null?d:new Set,l=(c,h)=>{const g=this._dataValidationModel.getRuleById(s,e,a);if(!g)return{redos:[],undos:[]};const S=g[c];if(!S||S===h)return{redos:[],undos:[]};const v={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:g.type,formula1:g.formula1,formula2:g.formula2,[c]:h}},source:"patched"},R={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:g.type,formula1:g.formula1,formula2:g.formula2}},source:"patched"},V=[{id:p.UpdateDataValidationMutation.id,params:v}],f=[{id:p.UpdateDataValidationMutation.id,params:R}];return{redos:V,undos:f}},u=this._dataValidationFormulaService.getRuleFormulaInfo(s,e,a);if(u){const[c,h]=u;if(c){const g=this._formulaRefRangeService.registerFormula(s,e,c.text,S=>l("formula1",S));n.add(()=>g.dispose())}if(h){const g=this._formulaRefRangeService.registerFormula(s,e,h.text,S=>l("formula2",S));n.add(()=>g.dispose())}}}register(s,e,t){var u;const a=d=>{const c=[...t.ranges],g=c.map(v=>D.handleCommonDefaultRangeChangeWithEffectRefCommands(v,d)).filter(v=>!!v).flat();if(r.isRangesEqual(g,c))return{redos:[],undos:[]};if(g.length){const v={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:g},source:"patched"},R=[{id:p.UpdateDataValidationMutation.id,params:v}],V=[{id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:c},source:"patched"}}];return{redos:R,undos:V}}else{const v={unitId:s,subUnitId:e,ruleId:t.uid},R=[{id:p.RemoveDataValidationMutation.id,params:v}],V=it(this._injector,v);return{redos:R,undos:V}}},i=[];t.ranges.forEach(d=>{const c=this._refRangeService.registerRefRange(d,a,s,e);i.push(()=>c.dispose())});const n=this._getIdWithUnitId(s,e,t.uid),l=(u=this._disposableMap.get(n))!=null?u:new Set;l.add(()=>i.forEach(d=>d())),this._disposableMap.set(n,l)}_initRefRange(){const s=this._dataValidationModel.getAll();for(const[e,t]of s)for(const[a,i]of t)for(const n of i)this.registerRule(e,a,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{const{unitId:t,subUnitId:a,rule:i}=e;switch(e.type){case"add":{const n=e.rule;this.registerRule(e.unitId,e.subUnitId,n);break}case"remove":{const n=this._disposableMap.get(this._getIdWithUnitId(t,a,i.uid));n&&n.forEach(l=>l());break}case"update":{const n=e.rule,l=this._disposableMap.get(this._getIdWithUnitId(t,a,n.uid));l&&l.forEach(u=>u()),this.registerRule(e.unitId,e.subUnitId,n);break}}})),this.disposeWithMe(r.toDisposable(()=>{this._disposableMap.forEach(e=>{e.forEach(t=>t())}),this._disposableMap.clear()}))}};ae=dt([b(0,r.Inject(m.SheetDataValidationModel)),b(1,r.Inject(r.Injector)),b(2,r.Inject(D.RefRangeService)),b(3,r.Inject(m.DataValidationFormulaService)),b(4,r.Inject(Z.FormulaRefRangeService)),b(5,r.Inject(p.DataValidatorRegistryService))],ae);var ct=Object.getOwnPropertyDescriptor,mt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ct(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},Se=(o,s)=>(e,t)=>s(e,t,o);let ie=class extends r.Disposable{constructor(o,s,e){super(),this._sheetInterceptorService=o,this._univerInstanceService=s,this._sheetDataValidationModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{var s;if(o.id===D.RemoveSheetCommand.id){const e=o.params,t=e.unitId||this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=this._univerInstanceService.getUniverSheetInstance(t);if(!a)return{redos:[],undos:[]};const i=e.subUnitId||((s=a.getActiveSheet())==null?void 0:s.getSheetId());if(!i)return{redos:[],undos:[]};const n=this._sheetDataValidationModel.getRules(t,i);if(n.length===0)return{redos:[],undos:[]};const l=n.map(c=>c.uid),u={unitId:t,subUnitId:i,ruleId:l,source:"patched"},d={unitId:t,subUnitId:i,rule:[...n],source:"patched"};return{redos:[{id:p.RemoveDataValidationMutation.id,params:u}],undos:[{id:p.AddDataValidationMutation.id,params:d}]}}else if(o.id===D.CopySheetCommand.id){const e=o.params,{unitId:t,subUnitId:a,targetSubUnitId:i}=e;if(!t||!a||!i)return{redos:[],undos:[]};const n=this._sheetDataValidationModel.getRules(t,a);if(n.length===0)return{redos:[],undos:[]};const l=n.map(u=>({...u,uid:r.generateRandomId(6)}));return{redos:[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:i,rule:l,source:"patched"}}],undos:[{id:p.RemoveDataValidationMutation.id,params:{unitId:t,subUnitId:i,ruleId:l.map(u=>u.uid),source:"patched"}}]}}return{redos:[],undos:[]}}}))}};ie=mt([Se(0,r.Inject(D.SheetInterceptorService)),Se(1,r.Inject(r.IUniverInstanceService)),Se(2,r.Inject(m.SheetDataValidationModel))],ie);class ht extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.ANY);_(this,"title","dataValidation.any.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",0);_(this,"offsetFormulaByRange",!1)}async parseFormula(e,t,a){return{formula1:e.formula1,formula2:e.formula2,isFormulaValid:!0}}validatorFormula(e,t,a){return{success:!0}}async isValidType(e,t,a){return!0}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.any.error")}}class gt extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.CUSTOM);_(this,"title","dataValidation.custom.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",60);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder))}validatorFormula(e,t,a){var d;const i=r.isFormulaString(e.formula1),n=(d=e.formula1)!=null?d:"",u=this._lexerTreeBuilder.checkIfAddBracket(n)===0&&n.startsWith(y.operatorToken.EQUALS);return{success:i&&u,formula1:i&&u?"":this.localeService.t("dataValidation.validFail.formula")}}async parseFormula(e,t,a){return{formula1:void 0,formula2:void 0,isFormulaValid:!0}}async isValidType(e,t,a){const{column:i,row:n,unitId:l,subUnitId:u}=e,d=await this._customFormulaService.getCellFormulaValue(l,u,a.uid,n,i),c=d==null?void 0:d.v;return E(String(c))&&r.Tools.isDefine(c)&&c!==""?d.t===r.CellValueType.BOOLEAN?!!c:typeof c=="boolean"?c:typeof c=="number"?!!c:typeof c=="string"?E(c):!!c:!1}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.custom.error")}generateRuleName(e){var t;return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}",(t=e.formula1)!=null?t:"")}}class Be extends ge{constructor(){super(...arguments);_(this,"id",r.DataValidationType.LIST_MULTIPLE);_(this,"title","dataValidation.listMultiple.title");_(this,"offsetFormulaByRange",!1);_(this,"skipDefaultFontRender",()=>!0)}}class pt extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"id",r.DataValidationType.WHOLE);_(this,"title","dataValidation.whole.title");_(this,"order",10);_(this,"operators",[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.EQUAL,r.DataValidationOperator.GREATER_THAN,r.DataValidationOperator.GREATER_THAN_OR_EQUAL,r.DataValidationOperator.LESS_THAN,r.DataValidationOperator.LESS_THAN_OR_EQUAL,r.DataValidationOperator.NOT_BETWEEN,r.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"])}_isFormulaOrInt(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}async isValidType(e,t,a){const{value:i}=e,n=X(i);return!Number.isNaN(n)&&Number.isInteger(n)}transform(e,t,a){const{value:i}=e;return{...e,value:X(i)}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=r.isFormulaString(d)?l==null?void 0:l.v:d,g=r.isFormulaString(c)?u==null?void 0:u.v:c,S=E(`${h}`)&&E(`${g}`);return{formula1:this._parseNumber(h),formula2:this._parseNumber(g),isFormulaValid:S}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=J.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:d}}generateRuleErrorMessage(e,t){if(!e.operator)return this.localeService.t(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}var _t=Object.getOwnPropertyDescriptor,St=(o,s,e,t)=>{for(var a=t>1?void 0:t?_t(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},N=(o,s)=>(e,t)=>s(e,t,o);let re=class extends r.RxDisposable{constructor(o,s,e,t,a,i){super(),this._univerInstanceService=o,this._dataValidatorRegistryService=s,this._injector=e,this._selectionManagerService=t,this._sheetInterceptorService=a,this._sheetDataValidationModel=i,this._init()}_init(){this._registerValidators(),this._initCommandInterceptor()}_registerValidators(){[ht,Ze,pt,at,ye,Me,ge,Be,gt].forEach(o=>{const s=this._injector.createInstance(o);this.disposeWithMe(this._dataValidatorRegistryService.register(s)),this.disposeWithMe(r.toDisposable(()=>this._injector.delete(o)))})}_initCommandInterceptor(){this._sheetInterceptorService.interceptCommand({getMutations:o=>{var s;if(o.id===D.ClearSelectionAllCommand.id){const e=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET),t=e.getUnitId(),a=e.getActiveSheet();if(!a)throw new Error("No active sheet found");const i=a.getSheetId(),n=(s=this._selectionManagerService.getCurrentSelections())==null?void 0:s.map(h=>h.range),l=this._sheetDataValidationModel.getRuleObjectMatrix(t,i).clone();n&&l.removeRange(n);const u=l.diff(this._sheetDataValidationModel.getRules(t,i)),{redoMutations:d,undoMutations:c}=K(t,i,u,this._injector,"patched");return{undos:c,redos:d}}return{undos:[],redos:[]}}})}};re=St([N(0,r.IUniverInstanceService),N(1,r.Inject(p.DataValidatorRegistryService)),N(2,r.Inject(r.Injector)),N(3,r.Inject(D.SheetsSelectionsService)),N(4,r.Inject(D.SheetInterceptorService)),N(5,r.Inject(m.SheetDataValidationModel))],re);var ft=Object.getOwnPropertyDescriptor,vt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ft(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},ne=(o,s)=>(e,t)=>s(e,t,o);m.SheetsDataValidationValidatorService=class extends r.Disposable{constructor(s,e,t,a){super(),this._univerInstanceService=s,this._sheetDataValidationModel=e,this._dataValidationCacheService=t,this._lifecycleService=a,this._initRecalculate()}_initRecalculate(){const s=e=>{if(e.length===0)return;const t=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET),a=t==null?void 0:t.getActiveSheet(),i={};e.flat().forEach(n=>{i[n.unitId]||(i[n.unitId]={}),i[n.unitId][n.subUnitId]||(i[n.unitId][n.subUnitId]=[]);const l=this._univerInstanceService.getUnit(n.unitId,r.UniverInstanceType.UNIVER_SHEET),u=l==null?void 0:l.getSheetBySheetId(n.subUnitId);u&&i[n.unitId][n.subUnitId].push(...n.ranges.map(d=>r.Range.transformRange(d,u)))}),Object.entries(i).forEach(([n,l])=>{Object.entries(l).forEach(([u,d])=>{(t==null?void 0:t.getUnitId())===n&&(a==null?void 0:a.getSheetId())===u?this.validatorRanges(n,u,d):requestIdleCallback(()=>{this.validatorRanges(n,u,d)})})})};this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(U.bufferWhen(()=>this._lifecycleService.lifecycle$.pipe(U.filter(e=>e===r.LifecycleStages.Rendered)))).subscribe(s)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(U.filter(()=>this._lifecycleService.stage>=r.LifecycleStages.Rendered),r.bufferDebounceTime(20)).subscribe(s))}async _validatorByCell(s,e,t,a){const i=s.getUnitId(),n=e.getSheetId();if(!r.Tools.isDefine(t)||!r.Tools.isDefine(a))throw new Error(`row or col is not defined, row: ${t}, col: ${a}`);const l=this._sheetDataValidationModel.getRuleByLocation(i,n,t,a);return l?new Promise(u=>{this._sheetDataValidationModel.validator(l,{unitId:i,subUnitId:n,row:t,col:a,worksheet:e,workbook:s},d=>{u(d)})}):r.DataValidationStatus.VALID}async validatorCell(s,e,t,a){const i=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!i)throw new Error(`cannot find current workbook, unitId: ${s}`);const n=i.getSheetBySheetId(e);if(!n)throw new Error(`cannot find current worksheet, sheetId: ${e}`);return this._validatorByCell(i,n,t,a)}validatorRanges(s,e,t){if(!t.length)return Promise.resolve([]);const a=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!a)throw new Error(`cannot find current workbook, unitId: ${s}`);const i=a.getSheetBySheetId(e);if(!i)throw new Error(`cannot find current worksheet, sheetId: ${e}`);const l=this._sheetDataValidationModel.getRules(s,e).map(d=>d.ranges).flat(),u=t.map(d=>l.map(c=>r.getIntersectRange(d,c))).flat().filter(Boolean);return Promise.all(u.map(d=>{const c=[];return r.Range.foreach(d,(h,g)=>{c.push(this._validatorByCell(a,i,h,g))}),Promise.all(c)}))}async validatorWorksheet(s,e){const t=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!t)throw new Error(`cannot find current workbook, unitId: ${s}`);const a=t.getSheetBySheetId(e);if(!a)throw new Error(`cannot find current worksheet, sheetId: ${e}`);const i=this._sheetDataValidationModel.getRules(s,e);return await Promise.all(i.map(n=>Promise.all(n.ranges.map(l=>{const u=[];return r.Range.foreach(l,(d,c)=>{u.push(this._validatorByCell(t,a,d,c))}),Promise.all(u)})))),this._dataValidationCacheService.ensureCache(s,e)}async validatorWorkbook(s){const e=this._sheetDataValidationModel.getSubUnitIds(s),t=await Promise.all(e.map(i=>this.validatorWorksheet(s,i))),a={};return t.forEach((i,n)=>{a[e[n]]=i}),a}getDataValidations(s,e,t){const a=this._sheetDataValidationModel.getRuleObjectMatrix(s,e),i=new Set;return t.forEach(l=>{r.Range.foreach(l,(u,d)=>{const c=a.getValue(u,d);c&&i.add(c)})}),Array.from(i).map(l=>this._sheetDataValidationModel.getRuleById(s,e,l)).filter(Boolean)}getDataValidation(s,e,t){return this.getDataValidations(s,e,t)[0]}},m.SheetsDataValidationValidatorService=vt([ne(0,r.IUniverInstanceService),ne(1,r.Inject(m.SheetDataValidationModel)),ne(2,r.Inject(m.DataValidationCacheService)),ne(3,r.Inject(r.LifecycleService))],m.SheetsDataValidationValidatorService);var Rt=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,Dt=(o,s,e)=>s in o?Rt(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e,Mt=(o,s,e,t)=>{for(var a=t>1?void 0:t?Vt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},fe=(o,s)=>(e,t)=>s(e,t,o),je=(o,s,e)=>Dt(o,typeof s!="symbol"?s+"":s,e);m.UniverSheetsDataValidationPlugin=class extends r.Plugin{constructor(s=Ne,e,t,a){super(),this._config=s,this._injector=e,this._commandService=t,this._configService=a;const{...i}=r.merge({},Ne,this._config);this._configService.setConfig(ot,i)}onStarting(){[[m.DataValidationCacheService],[m.DataValidationFormulaService],[m.DataValidationCustomFormulaService],[m.SheetsDataValidationValidatorService],[m.SheetDataValidationModel],[re],[m.DataValidationFormulaController],[ie],[ae],[te]].forEach(s=>{this._injector.add(s)}),[Fe,Oe,Ie,Ce,we,Ue,Ae].forEach(s=>{this._commandService.registerCommand(s)}),this._injector.get(m.DataValidationCacheService),this._injector.get(m.SheetsDataValidationValidatorService),this._injector.get(re),this._injector.get(te),this._injector.get(ae)}onReady(){this._injector.get(ie)}onRendered(){this._injector.get(m.DataValidationFormulaController)}},je(m.UniverSheetsDataValidationPlugin,"pluginName",Le),je(m.UniverSheetsDataValidationPlugin,"type",r.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsDataValidationPlugin=Mt([r.DependentOn(p.UniverDataValidationPlugin),fe(1,r.Inject(r.Injector)),fe(2,r.ICommandService),fe(3,r.IConfigService)],m.UniverSheetsDataValidationPlugin);function Et(o){const e=o.get(D.SheetsSelectionsService).getCurrentSelections().map(i=>i.range);return{uid:r.generateRandomId(6),type:r.DataValidationType.DECIMAL,operator:r.DataValidationOperator.EQUAL,formula1:"100",ranges:e!=null?e:[{startColumn:0,endColumn:0,startRow:0,endRow:0}]}}const yt="data-validation.custom-formula-input",Tt="data-validation.formula-input",Ot="data-validation.list-formula-input",Ft="data-validation.checkbox-formula-input";m.AddSheetDataValidationCommand=Fe,m.BASE_FORMULA_INPUT_NAME=Tt,m.CHECKBOX_FORMULA_1=$,m.CHECKBOX_FORMULA_2=k,m.CHECKBOX_FORMULA_INPUT_NAME=Ft,m.CUSTOM_FORMULA_INPUT_NAME=yt,m.CheckboxValidator=Me,m.ClearRangeDataValidationCommand=Ae,m.DATA_VALIDATION_PLUGIN_NAME=Le,m.DateValidator=ye,m.LIST_FORMULA_INPUT_NAME=Ot,m.ListMultipleValidator=Be,m.ListValidator=ge,m.RemoveSheetAllDataValidationCommand=Ue,m.RemoveSheetDataValidationCommand=we,m.UpdateSheetDataValidationOptionsCommand=Ce,m.UpdateSheetDataValidationRangeCommand=Oe,m.UpdateSheetDataValidationSettingCommand=Ie,m.createDefaultNewRule=Et,m.deserializeListOptions=G,m.getCellValueNumber=X,m.getCellValueOrigin=L,m.getDataValidationCellValue=ze,m.getDataValidationDiffMutations=K,m.getFormulaCellData=j,m.getFormulaResult=w,m.getTransformedFormula=Y,m.isLegalFormulaResult=E,m.serializeListOptions=Ke,m.transformCheckboxValue=x,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
// @univerjs/sheets-data-validation/facade
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
// @univerjs/sheets-drawing/index
|
|
36
|
-
(function(
|
|
36
|
+
(function(a,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/drawing","@univerjs/sheets"],s):(a=typeof globalThis<"u"?globalThis:a||self,s(a.UniverSheetsDrawing={},a.UniverCore,a.UniverDrawing,a.UniverSheets))})(this,(function(a,s,I,D){"use strict";var E=(e=>(e.Position="0",e.Both="1",e.None="2",e))(E||{});class P extends I.UnitDrawingService{}const _=s.createIdentifier("sheets-drawing.sheet-drawing.service");var u=(e=>(e[e.INSERT=0]="INSERT",e[e.REMOVE=1]="REMOVE",e[e.UPDATE=2]="UPDATE",e[e.ARRANGE=3]="ARRANGE",e[e.GROUP=4]="GROUP",e[e.UNGROUP=5]="UNGROUP",e))(u||{});const g={id:"sheet.mutation.set-drawing-apply",type:s.CommandType.MUTATION,handler:(e,n)=>{const t=e.get(I.IDrawingManagerService),i=e.get(_),{op:r,unitId:o,subUnitId:c,type:h,objects:d}=n;switch(t.applyJson1(o,c,r),i.applyJson1(o,c,r),h){case 0:t.addNotification(d),i.addNotification(d);break;case 1:t.removeNotification(d),i.removeNotification(d);break;case 2:t.updateNotification(d),i.updateNotification(d);break;case 3:t.orderNotification(d),i.orderNotification(d);break;case 4:t.groupUpdateNotification(d);break;case 5:t.ungroupUpdateNotification(d);break}return!0}};var R=Object.getOwnPropertyDescriptor,j=(e,n,t,i)=>{for(var r=i>1?void 0:i?R(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},v=(e,n)=>(t,i)=>n(t,i,e);const w="SHEET_DRAWING_PLUGIN";let U=class extends s.Disposable{constructor(e,n,t,i,r,o){super(),this._sheetInterceptorService=e,this._univerInstanceService=n,this._commandService=t,this._sheetDrawingService=i,this._drawingManagerService=r,this._resourceManagerService=o,this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(g))}_initSnapshot(){const e=(t,i)=>{const r=i||this._sheetDrawingService.getDrawingDataForUnit(t);return r?JSON.stringify(r):""},n=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:w,businesses:[s.UniverInstanceType.UNIVER_SHEET],toJson:(t,i)=>e(t,i),parseJson:t=>n(t),onUnLoad:t=>{this._sheetDrawingService.removeDrawingDataForUnit(t),this._drawingManagerService.removeDrawingDataForUnit(t)},onLoad:(t,i)=>{this._sheetDrawingService.registerDrawingData(t,i),this._drawingManagerService.registerDrawingData(t,i)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{var n;if(e.id===D.RemoveSheetCommand.id){const t=e.params,i=t.unitId||this._univerInstanceService.getCurrentUnitOfType(s.UniverInstanceType.UNIVER_SHEET).getUnitId(),r=t.subUnitId||((n=this._univerInstanceService.getCurrentUnitOfType(s.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:n.getSheetId());if(!i||!r)return{redos:[],undos:[]};const o=this._sheetDrawingService.getDrawingData(i,r),c=Object.values(o);if(c.length===0)return{redos:[],undos:[]};const h=this._sheetDrawingService.getBatchRemoveOp(c),{unitId:d,subUnitId:S,undo:f,redo:m,objects:p}=h;return{redos:[{id:g.id,params:{op:m,unitId:d,subUnitId:S,objects:p,type:u.REMOVE}}],undos:[{id:g.id,params:{op:f,unitId:d,subUnitId:S,objects:p,type:u.INSERT}}]}}else if(e.id===D.CopySheetCommand.id){const t=e.params,{unitId:i,subUnitId:r,targetSubUnitId:o}=t;if(!i||!r||!o)return{redos:[],undos:[]};const c=this._sheetDrawingService.getDrawingData(i,r),h=Object.values(c).map(J=>({...J,subUnitId:o,drawingId:s.generateRandomId(6)}));if(h.length===0)return{redos:[],undos:[]};const d=this._sheetDrawingService.getBatchAddOp(h),{unitId:S,subUnitId:f,undo:m,redo:p,objects:l}=d;return{redos:[{id:g.id,params:{op:p,unitId:S,subUnitId:f,objects:l,type:u.INSERT}}],undos:[{id:g.id,params:{op:m,unitId:S,subUnitId:f,objects:l,type:u.REMOVE}}]}}return{redos:[],undos:[]}}}))}};U=j([v(0,s.Inject(D.SheetInterceptorService)),v(1,s.Inject(s.IUniverInstanceService)),v(2,s.ICommandService),v(3,_),v(4,I.IDrawingManagerService),v(5,s.IResourceManagerService)],U);const M="sheets-drawing.config",N={};var C=Object.defineProperty,G=Object.getOwnPropertyDescriptor,T=(e,n,t)=>n in e?C(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,H=(e,n,t,i)=>{for(var r=i>1?void 0:i?G(n,t):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},b=(e,n)=>(t,i)=>n(t,i,e),O=(e,n,t)=>T(e,typeof n!="symbol"?n+"":n,t);a.UniverSheetsDrawingPlugin=class extends s.Plugin{constructor(n=N,t,i){super(),this._config=n,this._injector=t,this._configService=i;const{...r}=s.merge({},N,this._config);this._configService.setConfig(M,r)}onStarting(){[[U],[_,{useClass:P}]].forEach(n=>this._injector.add(n)),this._injector.get(U)}},O(a.UniverSheetsDrawingPlugin,"pluginName",w),O(a.UniverSheetsDrawingPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),a.UniverSheetsDrawingPlugin=H([s.DependentOn(I.UniverDrawingPlugin),b(1,s.Inject(s.Injector)),b(2,s.IConfigService)],a.UniverSheetsDrawingPlugin),a.DrawingApplyType=u,a.ISheetDrawingService=_,a.SHEET_DRAWING_PLUGIN=w,a.SetDrawingApplyMutation=g,a.SheetDrawingAnchorType=E,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
// @univerjs/sheets-filter/index
|
|
40
|
-
(function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/rpc"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-render","@univerjs/rpc","@univerjs/engine-formula"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsFilter={},h.UniverCore,h.UniverSheets,h.rxjs,h.UniverEngineRender,h.UniverRpc,h.UniverEngineFormula))})(this,(function(h,a,_,I,Se,Re,J){"use strict";var Ye=Object.defineProperty;var et=(h,a,_)=>a in h?Ye(h,a,{enumerable:!0,configurable:!0,writable:!0,value:_}):h[a]=_;var v=(h,a,_)=>et(h,typeof a!="symbol"?a+"":a,_);var x;const K="sheet.mutation.set-filter-range",Z="sheet.mutation.set-filter-criteria",X="sheet.mutation.remove-filter",Y="sheet.mutation.re-calc-filter",H=new Set([K,Z,X,Y]);var N=(i=>(i[i.VALUES=0]="VALUES",i[i.COLORS=1]="COLORS",i[i.CONDITIONS=2]="CONDITIONS",i))(N||{}),A=(i=>(i.EQUAL="equal",i.GREATER_THAN="greaterThan",i.GREATER_THAN_OR_EQUAL="greaterThanOrEqual",i.LESS_THAN="lessThan",i.LESS_THAN_OR_EQUAL="lessThanOrEqual",i.NOT_EQUALS="notEqual",i))(A||{});const ee={operator:A.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},te={operator:A.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},re={operator:A.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},ne={operator:A.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},ie={operator:A.EQUAL,fn:(i,n)=>U(i)?i===n:!1},z={operator:A.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=le(i);return e&&pe(n)?!a.createREGEXFromWildChar(n).test(e):e!==n}return U(i)?i!==n:!0}},se=new Map([]);[ee,te,re,ne,ie,z].forEach(i=>{se.set(i.operator,i)});function ve(i){return!!i}const Fe={fn:(i,n)=>{const e=le(i);return e===null?n==="":a.createREGEXFromWildChar(n).test(e)}};function V(i){return i?se.get(i):Fe}function U(i){return typeof i=="number"}function oe(i){return!!(typeof i=="number"||typeof i=="string"&&a.isNumeric(i))}function le(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function pe(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}const W=()=>new Set;class P extends a.Disposable{constructor(e,t,r){super();v(this,"_filteredOutRows$",new I.BehaviorSubject(W()));v(this,"filteredOutRows$",this._filteredOutRows$.asObservable());v(this,"_hasCriteria$",new I.BehaviorSubject(!1));v(this,"hasCriteria$",this._hasCriteria$.asObservable());v(this,"_filterColumnByIndex",new Map);v(this,"_alreadyFilteredOutRows",W());v(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete(),this._worksheet=null}serialize(){const e={ref:a.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([t],[r])=>t-r).map(([t,r])=>r.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,r,s){const o=new P(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut&&(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new Error("[FilterModel] could not get range before a range is set!");return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?a.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=W(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){const r=this._range;if(!r)throw new Error("[FilterModel] could not set criteria before a range is set!");const{startColumn:s,endColumn:o}=r;if(e>o||e<s)throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let l;this._filterColumnByIndex.has(e)?l=this._filterColumnByIndex.get(e):(l=new ae(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),l.setRangeAndColumn(r,e),this._filterColumnByIndex.set(e,l)),l.setCriteria(t)}_removeCriteria(e){const t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){const e=this._getAllFilterColumns().filter(t=>t.hasCache()).reduce((t,r)=>a.mergeSets(t,r.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){const e=this._getAllFilterColumns().filter(t=>!t.hasCache());for(const t of e){const r=t.reCalc();r&&(this._alreadyFilteredOutRows=a.mergeSets(this._alreadyFilteredOutRows,r))}}}class ae extends a.Disposable{constructor(e,t,r,s,o){super();v(this,"_filteredOutRows",null);v(this,"_filterFn",null);v(this,"_range",null);v(this,"_column",0);v(this,"_filterBy",N.VALUES);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw new Error("[FilterColumn]: could not serialize without a filter column!");return a.Tools.deepClone({...this._criteria,colId:this._column})}hasCache(){return this._filteredOutRows!==null}setRangeAndColumn(e,t){this._range=e,this._column=t}setCriteria(e){this._criteria=e,this._generateFilterFn(),this._filteredOutRows=null}getColumnData(){return a.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:d,rowSpan:c,col:m}=l;if(o.has(d)&&(!c||c===1))continue;if(!(this._filterBy===N.VALUES?this._filterFn(a.extractPureTextFromCell(this._worksheet.getCell(d,m))):this._filterBy===N.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(d,m)):this._filterFn(Ne(this._worksheet,d,m)))&&(s.add(d),c))for(let f=1;f<c;f++)s.add(d+f)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=we(this._criteria),this._filterBy=this._criteria.filters?N.VALUES:this._criteria.colorFilters?N.COLORS:N.CONDITIONS)}}function we(i){if(i.filters)return Me(i.filters);if(i.colorFilters)return Ee(i.colorFilters);if(i.customFilters)return ye(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Me(i){const n=!!i.blank,e=new Set(i.filters);return t=>t===void 0||t===""?n:e.has(typeof t=="string"?t:`${t}`)}function Ee(i){if(i.cellFillColors){const n=new Set(i.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);const t=new a.ColorKit(e.bg.rgb).toRgbString();return n.has(t)}}if(i.cellTextColors){const n=new Set(i.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(Se.COLOR_BLACK_RGB);const t=new a.ColorKit(e.cl.rgb).toRgbString();return n.has(t)}}throw new Error("[FilterModel]: color filters are not supported yet.")}function ye(i){const n=i.customFilters.map(e=>Ae(e));return Te(n)?i.and?Oe(n):Ie(n):n[0]}function Oe(i){const[n,e]=i;return t=>n(t)&&e(t)}function Ie(i){const[n,e]=i;return t=>n(t)||e(t)}function Te(i){return i.length===2}function Ae(i){const n=i.val;if(i.operator===A.NOT_EQUALS&&!oe(n))return r=>z.fn(r,n);if(ve(i.operator)){if(!oe(n))return()=>!1;const r=V(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=V(i.operator);return t=>e.fn(t,n)}function Ne(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?de(t):r?t.t===a.CellValueType.NUMBER&&typeof t.v=="string"?r.v:t.t===a.CellValueType.NUMBER?Number(r.v):de(r):null}function de(i){var t,r;const n=(r=(t=i.p)==null?void 0:t.body)==null?void 0:r.dataStream;if(n)return n.trimEnd();const e=i.v;return typeof e=="string"?i.t===a.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===a.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var be=Object.getOwnPropertyDescriptor,Ue=(i,n,e,t)=>{for(var r=t>1?void 0:t?be(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},q=(i,n)=>(e,t)=>n(e,t,i);const k="SHEET_FILTER_PLUGIN";h.SheetsFilterService=class extends a.Disposable{constructor(e,t,r){super();v(this,"_filterModels",new Map);v(this,"_loadedUnitId$",new I.BehaviorSubject(null));v(this,"loadedUnitId$",this._loadedUnitId$.asObservable());v(this,"_errorMsg$",new I.BehaviorSubject(null));v(this,"errorMsg$",this._errorMsg$.asObservable());v(this,"_activeFilterModel$",new I.BehaviorSubject(null));v(this,"activeFilterModel$",this._activeFilterModel$.asObservable());this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=r,this._initModel(),this._initActiveFilterModel()}get activeFilterModel(){return this._activeFilterModel$.getValue()}ensureFilterModel(e,t){const r=this.getFilterModel(e,t);if(r)return r;const s=this._univerInstanceService.getUniverSheetInstance(e);if(!s)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${e}!`);const o=s.getSheetBySheetId(t);if(!o)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${t}!`);const l=new P(e,t,o);return this._cacheFilterModel(e,t,l),l}getFilterModel(e,t){var r,s;return(s=(r=this._filterModels.get(e))==null?void 0:r.get(t))!=null?s:null}removeFilterModel(e,t){const r=this.getFilterModel(e,t);return r?(r.dispose(),this._filterModels.get(e).delete(t),!0):!1}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch(l){console.error("[SheetsFilterService]: could not get active workbook!",l);return}const t=e.getActiveSheet(!0);if(!t){this._activeFilterModel$.next(null);return}const r=t.getUnitId(),s=t.getSheetId(),o=this.getFilterModel(r,s);this._activeFilterModel$.next(o)}_initActiveFilterModel(){this.disposeWithMe(I.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([e])=>e.type===a.CommandType.MUTATION&&H.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:I.of(null)}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){const t=this._filterModels.get(e);if(!t)return"{}";const r={};return t.forEach((s,o)=>{r[o]=s.serialize()}),JSON.stringify(r)}_deserializeAutoFiltersForUnit(e,t){const r=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(s=>{const o=t[s],l=P.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(t=>t.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:k,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>this._serializeAutoFiltersForUnit(e),parseJson:e=>JSON.parse(e),onLoad:(e,t)=>{this._deserializeAutoFiltersForUnit(e,t),this._loadedUnitId$.next(e),this._updateActiveFilterModel()},onUnLoad:e=>{const t=this._filterModels.get(e);t&&(t.forEach(r=>r.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,r){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,r)}},h.SheetsFilterService=Ue([q(0,a.IResourceManagerService),q(1,a.IUniverInstanceService),q(2,a.ICommandService)],h.SheetsFilterService);const F={id:K,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(h.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:Z,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,d=i.get(h.SheetsFilterService).getFilterModel(t,e);return d?(d.setCriteria(s,r,o),!0):!1}},T={id:X,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(h.SheetsFilterService).removeFilterModel(e,t)}},$={id:Y,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n,s=i.get(h.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}},ce={id:"sheet.command.set-filter-range",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),s=i.get(a.IUniverInstanceService),{unitId:o,subUnitId:l,range:d}=n;if(!_.getSheetCommandTarget(s,n)||e.getFilterModel(o,l))return!1;if(d.endRow===d.startRow){const S=i.get(a.ErrorService),R=i.get(a.LocaleService);return S.emit(R.t("sheets-filter.command.not-valid-filter-range")),!1}const u={id:F.id,params:{unitId:o,subUnitId:l,range:d}},f=t.syncExecuteCommand(u.id,u.params);return f&&r.pushUndoRedo({unitID:o,undoMutations:[{id:T.id,params:{unitId:o,subUnitId:l}}],redoMutations:[u]}),f}},ue={id:"sheet.command.remove-sheet-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(a.IUniverInstanceService),t=i.get(h.SheetsFilterService),r=i.get(a.ICommandService),s=i.get(a.IUndoRedoService),o=_.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:d}=o,c=t.getFilterModel(l,d);if(!c)return!1;const m=c==null?void 0:c.serialize(),u=Be(l,d,m),f=r.syncExecuteCommand(T.id,{unitId:l,subUnitId:d});return f&&s.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:[{id:T.id,params:{unitId:l,subUnitId:d}}]}),f}},$e={id:"sheet.command.smart-toggle-filter",type:a.CommandType.COMMAND,handler:async i=>{const n=i.get(a.IUniverInstanceService),e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r==null?void 0:r.getActiveSheet();if(!s||!r)return!1;const o=r.getUnitId(),l=s.getSheetId();if(e.getFilterModel(o,l))return t.executeCommand(ue.id,{unitId:o,subUnitId:l});const m=i.get(_.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const u=m.range,f=_.isSingleCellSelection(m)?_.expandToContinuousRange(u,{left:!0,right:!0,up:!0,down:!0},s):u;return t.executeCommand(ce.id,{unitId:o,subUnitId:l,range:f})}},Le={id:"sheet.command.set-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:d}=n,c=e.getFilterModel(s,o);if(!c)return!1;const m=c.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const u=c.getFilterColumn(l),f=xe(s,o,l,u),S={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:d}},R=t.syncExecuteCommand(S.id,S.params);return R&&r.pushUndoRedo({unitID:s,undoMutations:[f],redoMutations:[S]}),R}},Pe={id:"sheet.command.clear-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.IUndoRedoService),r=i.get(a.ICommandService),s=i.get(a.IUniverInstanceService),o=_.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:d}=o,c=e.getFilterModel(o.unitId,o.subUnitId);if(!c)return!1;const m=c.serialize(),u=he(l,d,m),f=je(l,d,m);return a.sequenceExecute(f,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:f}),!0):!1}},De={id:"sheet.command.re-calc-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUniverInstanceService),s=_.getSheetCommandTarget(r,n);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand($.id,{unitId:o,subUnitId:l}):!1}};function Be(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),he(i,n,e).forEach(o=>t.push(o)),t}function he(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:s}};t.push(o)}),t}function je(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:null}};t.push(o)}),t}function xe(i,n,e,t){if(!t)return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:null}};const r=t.serialize();return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:r}}}const me="sheets-filter.config",fe={};function He(i,n){for(let e=0;e<i.length;e++){let t=e;if(i[e])for(let r=e+1;r<i.length;r++)i[t]&&i[r]&&n(i[t],i[r])&&(i[t]=null,t=r)}return i.filter(e=>e!==null)}function L(i){return He(i,(n,e)=>n.id===p.id&&e.id===p.id&&n.params.unitId===e.params.unitId&&n.params.subUnitId===e.params.subUnitId&&n.params.col===e.params.col)}var ze=Object.getOwnPropertyDescriptor,Ve=(i,n,e,t)=>{for(var r=t>1?void 0:t?ze(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},b=(i,n)=>(e,t)=>n(e,t,i);let D=class extends a.Disposable{constructor(n,e,t,r,s,o,l){super();v(this,"_disposableCollection",new a.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._dataSyncPrimaryController=o,this._zebraCrossingCacheController=l,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling(),this._initZebraCrossingCacheListener()}_initZebraCrossingCacheListener(){this.disposeWithMe(this._sheetsFilterService.activeFilterModel$.subscribe(n=>{n&&this.disposeWithMe(n.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(n.unitId,n.subUnitId)}))}))}_initCommands(){[p,F,$,T].forEach(n=>{var e;this.disposeWithMe(this._commandService.registerCommand(n)),(e=this._dataSyncPrimaryController)==null||e.registerSyncingMutations(n)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>this._getUpdateFilter(n)})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===_.SetWorksheetActiveOperation.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(r,t)}if(n.id===F.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(e.unitId,e.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(n=>{if(n){const e=this._univerInstanceService.getUniverSheetInstance(n),t=e==null?void 0:e.getActiveSheet();t&&this._registerRefRange(n,t.getSheetId())}}))}_registerRefRange(n,e){var l;this._disposableCollection.dispose();const t=this._univerInstanceService.getUniverSheetInstance(n),r=t==null?void 0:t.getSheetBySheetId(e);if(!t||!r)return;const s=(l=this._sheetsFilterService.getFilterModel(n,e))==null?void 0:l.getRange(),o=d=>{switch(d.id){case _.InsertRowCommand.id:{const c=d.params,m=c.unitId||n,u=c.subUnitId||e;return this._handleInsertRowCommand(c,m,u)}case _.InsertColCommand.id:{const c=d.params,m=c.unitId||n,u=c.subUnitId||e;return this.handleInsertColCommand(c.range,m,u)}case _.RemoveColCommand.id:{const c=d.params;return this.handleRemoveColCommand(c.range,n,e)}case _.RemoveRowCommand.id:{const c=d.params;return this._handleRemoveRowCommand(c,n,e)}case _.EffectRefRangId.MoveColsCommandId:{const c=d.params;return this.handleMoveColsCommand({fromRange:c.fromRange,toRange:c.toRange},n,e)}case _.EffectRefRangId.MoveRowsCommandId:{const c=d.params;return this._handleMoveRowsCommand(c,n,e)}case _.MoveRangeCommand.id:{const c=d.params;return this._handleMoveRangeCommand(c,n,e)}}return{redos:[],undos:[]}};s&&this._disposableCollection.add(this._refRangeService.registerRefRange(s,o,n,e))}_getUpdateFilter(n){const{id:e}=n;switch(e){case _.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case _.CopySheetCommand.id:{const t=n.params,{targetSubUnitId:r,unitId:s,subUnitId:o}=t;return!s||!o||!r?this._handleNull():this._handleCopySheetCommand(s,o,r)}}return{redos:[],undos:[]}}handleInsertColCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:d,endColumn:c}=n,m=c-d+1;if(c>l)return this._handleNull();const u=[],f=[],S=d,R={unitId:e,subUnitId:t,range:{...s,startColumn:d<=o?o+m:o,endColumn:l+m}},w={unitId:e,subUnitId:t,range:s};u.push({id:F.id,params:R}),f.push({id:F.id,params:w});const M=r.getAllFilterColumns().filter(C=>C[0]>=S);if(M.length!==0){const{newRange:C,oldRange:y}=this._moveCriteria(e,t,M,m);u.push(...y.redos,...C.redos),f.push(...C.undos,...y.undos)}return{redos:L(u),undos:L(f)}}_handleInsertRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t),s=(w=r==null?void 0:r.getRange())!=null?w:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{startRow:d,endRow:c}=n.range,m=c-d+1;if(c>l)return this._handleNull();const u=[],f=[],S={unitId:e,subUnitId:t,range:{...s,startRow:d<=o?o+m:o,endRow:l+m}},R={unitId:e,subUnitId:t,range:s};return u.push({id:F.id,params:S}),f.push({id:F.id,params:R}),{redos:L(u),undos:L(f)}}handleRemoveColCommand(n,e,t){var M;const r=this._sheetsFilterService.getFilterModel(e,t),s=(M=r==null?void 0:r.getRange())!=null?M:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:d,endColumn:c}=n;if(d>l)return this._handleNull();const m=[],u=[],f=c<o?0:Math.min(c,l)-Math.max(d,o)+1,S=c-d+1,R=r.getAllFilterColumns();R.forEach(g=>{const[C,y]=g;C<=c&&C>=d&&(m.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:null}}),u.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))});const w=R.filter(g=>{const[C,y]=g;return C>c});let E={undos:[],redos:[]};if(w.length>0){const{oldRange:g,newRange:C}=this._moveCriteria(e,t,w,-S);E=C,m.push(...g.redos),u.unshift(...g.undos)}if(f===l-o+1){const g={unitId:e,subUnitId:t};m.push({id:T.id,params:g}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}})}else{const g=o<=d?o:f===0?o-S:d,C=o<=d?l-f:l-S,y={unitId:e,subUnitId:t,range:{...s,startColumn:g,endColumn:C}};m.push({id:F.id,params:y}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),m.push(...E.redos),u.unshift(...E.undos)}return{undos:u,redos:m}}_handleRemoveRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange(),{startRow:o,endRow:l}=s,{startRow:d,endRow:c}=n.range;if(d>l)return this._handleNull();if(c<o)return{undos:[{id:F.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:F.id,params:{range:{...s,startRow:o-(c-d+1),endRow:l-(c-d+1)},unitId:e,subUnitId:t}}]};const m=[],u=[],f=r.getAllFilterColumns(),S=o<=c&&o>=d;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const R=Math.min(c,l)-Math.max(d,o)+1;if(R===l-o+1||S){const E={unitId:e,subUnitId:t};m.push({id:T.id,params:E}),f.forEach(M=>{const[g,C]=M,y={unitId:e,subUnitId:t,col:g,criteria:{...C.serialize(),colId:g}};u.push({id:p.id,params:y})})}else{const E=(w=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:w.getSheetBySheetId(t);if(!E)return this._handleNull();const M=[];for(let O=d;O<=c;O++)E.getRowFiltered(O)&&M.push(O);const g=Math.min(o,d),C=g+(l-o)-R+M.length,y={unitId:e,subUnitId:t,range:{...s,startRow:g,endRow:C}};m.push({id:F.id,params:y})}return{undos:L(u),redos:L(m)}}handleMoveColsCommand({fromRange:n,toRange:e},t,r){var M;const s=this._sheetsFilterService.getFilterModel(t,r),o=(M=s==null?void 0:s.getRange())!=null?M:null;if(!s||!o)return this._handleNull();const{startColumn:l,endColumn:d}=o;if(n.endColumn<l&&e.startColumn<=l||n.startColumn>d&&e.endColumn>d)return this._handleNull();const c=[],m=[],u={};for(let g=l;g<=d;g++)u[g]={colIndex:g,filter:s.getFilterColumn(g)};a.moveMatrixArray(n.startColumn,n.endColumn-n.startColumn+1,e.startColumn,u);let f=o.startColumn,S=o.endColumn;l>=n.startColumn&&l<=n.endColumn&&e.startColumn>n.startColumn&&n.endColumn<d&&(f=n.endColumn+1),d>=n.startColumn&&d<=n.endColumn&&e.startColumn<n.startColumn&&n.startColumn>l&&(S=n.startColumn-1);const R=Object.keys(u).map(g=>Number(g)),w=R.find(g=>u[g].colIndex===S),E=R.find(g=>u[g].colIndex===f);if(R.forEach(g=>{var Ce,_e;const{colIndex:C,filter:y}=u[g],O=g;if(y){if(O>=E&&O<=w){const Q={unitId:t,subUnitId:r,col:O,criteria:{...y.serialize(),colId:O}},Xe={unitId:t,subUnitId:r,col:O,criteria:s.getFilterColumn(O)?{...(Ce=s.getFilterColumn(O))==null?void 0:Ce.serialize(),colId:O}:null};c.push({id:p.id,params:Q}),m.push({id:p.id,params:Xe})}if(!((_e=u[C])!=null&&_e.filter)){const Q={unitId:t,subUnitId:r,col:C,criteria:null};c.push({id:p.id,params:Q}),m.push({id:p.id,params:{unitId:t,subUnitId:r,col:C,criteria:{...y.serialize(),colId:C}}})}}}),l!==E||d!==w){const g={unitId:t,subUnitId:r,range:{...o,startColumn:E,endColumn:w}};c.unshift({id:F.id,params:g}),m.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:r}})}return{undos:m,redos:c}}_handleMoveRowsCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:d,toRange:c}=n;if(d.endRow<o&&c.startRow<=o||d.startRow>l&&c.endRow>l)return this._handleNull();const m=[],u=[],f={};for(let C=o;C<=l;C++)f[C]={oldIndex:C};const S=o;let R=l;l>=d.startRow&&l<=d.endRow&&c.startRow<d.startRow&&d.startRow>o&&(R=d.startRow-1),a.moveMatrixArray(d.startRow,d.endRow-d.startRow+1,c.startRow,f);const w=Object.keys(f).map(C=>Number(C)),E=w.find(C=>f[C].oldIndex===R),M=w.find(C=>f[C].oldIndex===S);if(o!==M||l!==E){const C={unitId:e,subUnitId:t,range:{...s,startRow:M,endRow:E}};m.push({id:F.id,params:C},{id:$.id,params:{unitId:e,subUnitId:t}}),u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}},{id:$.id,params:{unitId:e,subUnitId:t}})}return{redos:m,undos:u}}_handleMoveRangeCommand(n,e,t){const{fromRange:r,toRange:s}=n,o=this._sheetsFilterService.getFilterModel(e,t);if(!o)return this._handleNull();const l=o.getRange();if(!l)return this._handleNull();const d=[],c=[];if(a.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,u=l.startColumn-r.startColumn,f={startRow:s.startRow+m,startColumn:s.startColumn+u,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+u+(l.endColumn-l.startColumn)},S={id:T.id,params:{unitId:e,subUnitId:t}},R={id:F.id,params:{unitId:e,subUnitId:t,range:f}},w={id:F.id,params:{unitId:e,subUnitId:t,range:l}};d.push(S,R),c.push(S,w);const E=o.getAllFilterColumns(),M=s.startColumn-r.startColumn;E.forEach(g=>{const[C,y]=g;y&&(d.push({id:p.id,params:{unitId:e,subUnitId:t,col:C+M,criteria:{...y.serialize(),colId:C+M}}}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))})}else if(a.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};d.push({id:F.id,params:{unitId:e,subUnitId:t,range:m}}),c.push({id:F.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:d,undos:c}}_handleRemoveSheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[];return r.getAllFilterColumns().forEach(([c,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:c,criteria:{...m.serialize(),colId:c}}})}),o.push({id:T.id,params:{unitId:e,subUnitId:t,range:s}}),l.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),{undos:l,redos:o}}_handleCopySheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(n,e);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[],d=[],c=[];return r.getAllFilterColumns().forEach(([u,f])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:{...f.serialize(),colId:u}}}),d.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:null}})}),d.push({id:T.id,params:{unitId:n,subUnitId:t,range:s}}),o.unshift({id:F.id,params:{range:s,unitId:n,subUnitId:t}}),{undos:l,redos:o,preUndos:d,preRedos:c}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(n,e)=>{var t,r;return n?!0:(r=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?r:!1}}))}_moveCriteria(n,e,t,r){const s={unitId:n,subUnitId:e,criteria:null,col:-1},o=[],l=[],d=[],c=[];return t.forEach(m=>{const[u,f]=m;l.push({id:p.id,params:{...s,col:u}}),o.push({id:p.id,params:{...s,col:u,criteria:{...f.serialize(),colId:u}}})}),t.forEach(m=>{const[u,f]=m;c.push({id:p.id,params:{...s,col:u+r,criteria:{...f.serialize(),colId:u+r}}}),d.push({id:p.id,params:{...s,col:u+r,criteria:null}})}),{newRange:{redos:c,undos:d},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var c,m;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((u,f)=>u-f),l=[];let d=!1;if(n.id===_.RemoveRowMutation.id){const{startRow:u,endRow:f}=n.params.range,S=o.filter(R=>R>=u&&R<=f);o.forEach(R=>{if(R<u)l.push(R);else if(d=!0,R<=f){const w=Math.max(u,l.length?l[l.length-1]+1:u);l.push(w)}else l.push(R-(f-u+1-S.length))})}if(n.id===_.InsertRowMutation.id){const{startRow:u,endRow:f}=n.params.range;o.forEach(S=>{S>=u?(d=!0,l.push(S+(f-u+1))):l.push(S)})}if(d&&(s.filteredOutRows=new Set(l)),n.id===_.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const u=this._getExtendRegion(t,r);if(u){const f=n.params.cellValue;if(f)for(let S=u.startColumn;S<=u.endColumn;S++){const R=(c=f==null?void 0:f[u.startRow])==null?void 0:c[S];if(R&&this._cellHasValue(R)){const w=(m=this._univerInstanceService.getUnit(t))==null?void 0:m.getSheetBySheetId(r);if(w){const E=_.expandToContinuousRange(u,{down:!0},w),M=this._sheetsFilterService.getFilterModel(t,r),g=M.getRange();M.setRange({...g,endRow:E.endRow}),this._registerRefRange(t,r)}}}}}}))}_getExtendRegion(n,e){var d;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(d=this._univerInstanceService.getUnit(n))==null?void 0:d.getSheetBySheetId(e);if(!r)return null;const s=t.getRange();if(!s)return null;const o=r.getRowCount()-1,l=r.getRowManager();for(let c=s.endRow+1;c<=o;c++)if(l.getRowRawVisible(c))return{startRow:c,endRow:c,startColumn:s.startColumn,endColumn:s.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(n=>{const e=n.params,t=_.getSheetCommandTarget(this._univerInstanceService);if(!t)return;const{subUnitId:r,unitId:s}=t,o=this._sheetsFilterService.getFilterModel(s,r);if(!o)return;const l=o.getRange();if(n.id===_.MoveRowsCommand.id&&e.fromRange.startRow<=l.startRow&&e.fromRange.endRow<l.endRow&&e.fromRange.endRow>=l.startRow)throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"),new Error("[SheetsFilterController]: Cannot move header row of filter")}))}_cellHasValue(n){const e=Object.values(n);return!(e.length===0||e.every(t=>t==null))}};D=Ve([b(0,a.ICommandService),b(1,a.Inject(_.SheetInterceptorService)),b(2,a.Inject(h.SheetsFilterService)),b(3,a.IUniverInstanceService),b(4,a.Inject(_.RefRangeService)),b(5,a.Optional(Re.DataSyncPrimaryController)),b(6,a.Inject(_.ZebraCrossingCacheController))],D);var We=Object.getOwnPropertyDescriptor,qe=(i,n,e,t)=>{for(var r=t>1?void 0:t?We(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},G=(i,n)=>(e,t)=>n(e,t,i);const ke=[p.id,$.id],Ge=[_.InsertColMutation.id,_.RemoveColMutation.id,_.MoveColsMutation.id];h.SheetsFilterSyncController=class extends a.Disposable{constructor(e,t,r){super();v(this,"_d",new a.DisposableCollection);v(this,"_visible$",new I.BehaviorSubject(!1));v(this,"visible$",this._visible$.asObservable());v(this,"_enabled$",new I.BehaviorSubject(!0));v(this,"enabled$",this._enabled$.asObservable());this._sheetsFilterController=e,this._commandService=t,this._configService=r;const s=this._configService.getConfig(me);s!=null&&s.enableSyncSwitch&&this._visible$.next(!0)}get visible(){return this._visible$.getValue()}get enabled(){return this._enabled$.getValue()}setEnabled(e){this._enabled$.next(e),e?this._d.dispose():this._initOnlyLocalListener()}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((e,t)=>{ke.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,t)=>{if(Ge.includes(e.id)&&(t!=null&&t.fromCollab)){if(e.id===_.InsertColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleInsertColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.RemoveColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleRemoveColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.MoveColsMutation.id){const{sourceRange:r,targetRange:s,unitId:o,subUnitId:l}=e.params,{redos:d}=this._sheetsFilterController.handleMoveColsCommand({fromRange:r,toRange:s},o,l);a.sequenceExecute(d,this._commandService,t)}}}))}},h.SheetsFilterSyncController=qe([G(0,a.Inject(D)),G(1,a.ICommandService),G(2,a.IConfigService)],h.SheetsFilterSyncController);var Qe=Object.getOwnPropertyDescriptor,Je=(i,n,e,t)=>{for(var r=t>1?void 0:t?Qe(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},B=(i,n)=>(e,t)=>n(e,t,i);let j=class extends a.Disposable{constructor(i,n,e,t){super(),this._activeDirtyManagerService=i,this._sheetRowFilteredService=n,this._sheetsFilterService=e,this._univerInstanceService=t,this._initFormulaDirtyRange(),this._registerSheetRowFiltered()}_initFormulaDirtyRange(){H.forEach(i=>{this._activeDirtyManagerService.register(i,{commandId:i,getDirtyData:n=>{const e=n.params,{unitId:t,subUnitId:r}=e;return{dirtyRanges:this._getHideRowMutation(t,r),clearDependencyTreeCache:{[t]:{[r]:"1"}}}}})})}_getHideRowMutation(i,n){var l,d;const e=(l=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:l.getRange(),t=(d=this._univerInstanceService.getUnit(i))==null?void 0:d.getSheetBySheetId(n);if(e==null||t==null)return[];const{startRow:r,endRow:s}=e;return[{unitId:i,sheetId:n,range:{startRow:r,startColumn:0,endRow:s,endColumn:t.getColumnCount()-1}}]}_registerSheetRowFiltered(){this._sheetRowFilteredService.register((i,n,e)=>{var t,r;return(r=(t=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:t.isRowFiltered(e))!=null?r:!1})}};j=Je([B(0,a.Inject(J.IActiveDirtyManagerService)),B(1,a.Inject(J.ISheetRowFilteredService)),B(2,a.Inject(h.SheetsFilterService)),B(3,a.IUniverInstanceService)],j);var Ke=Object.getOwnPropertyDescriptor,Ze=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ke(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},ge=(i,n)=>(e,t)=>n(e,t,i);h.UniverSheetsFilterPlugin=(x=class extends a.Plugin{constructor(n=fe,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=a.merge({},fe,this._config);this._configService.setConfig(me,r)}onStarting(){[[j],[h.SheetsFilterService],[D],[h.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){a.touchDependencies(this._injector,[[j],[D],[h.SheetsFilterSyncController]])}},v(x,"type",a.UniverInstanceType.UNIVER_SHEET),v(x,"pluginName",k),x),h.UniverSheetsFilterPlugin=Ze([ge(1,a.Inject(a.Injector)),ge(2,a.IConfigService)],h.UniverSheetsFilterPlugin),h.ClearSheetsFilterCriteriaCommand=Pe,h.CustomFilterOperator=A,h.FILTER_MUTATIONS=H,h.FilterBy=N,h.FilterColumn=ae,h.FilterModel=P,h.ReCalcSheetsFilterCommand=De,h.ReCalcSheetsFilterMutation=$,h.RemoveSheetFilterCommand=ue,h.RemoveSheetsFilterMutation=T,h.SHEET_FILTER_SNAPSHOT_ID=k,h.SetSheetFilterRangeCommand=ce,h.SetSheetsFilterCriteriaCommand=Le,h.SetSheetsFilterCriteriaMutation=p,h.SetSheetsFilterRangeMutation=F,h.SmartToggleSheetsFilterCommand=$e,h.equals=ie,h.getCustomFilterFn=V,h.greaterThan=ee,h.greaterThanOrEqualTo=te,h.lessThan=re,h.lessThanOrEqualTo=ne,h.notEquals=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
|
40
|
+
(function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/rpc"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-render","@univerjs/rpc","@univerjs/engine-formula"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsFilter={},h.UniverCore,h.UniverSheets,h.rxjs,h.UniverEngineRender,h.UniverRpc,h.UniverEngineFormula))})(this,(function(h,a,_,I,Se,Re,J){"use strict";var Ye=Object.defineProperty;var et=(h,a,_)=>a in h?Ye(h,a,{enumerable:!0,configurable:!0,writable:!0,value:_}):h[a]=_;var v=(h,a,_)=>et(h,typeof a!="symbol"?a+"":a,_);var x;const K="sheet.mutation.set-filter-range",Z="sheet.mutation.set-filter-criteria",X="sheet.mutation.remove-filter",Y="sheet.mutation.re-calc-filter",H=new Set([K,Z,X,Y]);var N=(i=>(i[i.VALUES=0]="VALUES",i[i.COLORS=1]="COLORS",i[i.CONDITIONS=2]="CONDITIONS",i))(N||{}),A=(i=>(i.EQUAL="equal",i.GREATER_THAN="greaterThan",i.GREATER_THAN_OR_EQUAL="greaterThanOrEqual",i.LESS_THAN="lessThan",i.LESS_THAN_OR_EQUAL="lessThanOrEqual",i.NOT_EQUALS="notEqual",i))(A||{});const ee={operator:A.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},te={operator:A.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},re={operator:A.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},ne={operator:A.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},ie={operator:A.EQUAL,fn:(i,n)=>U(i)?i===n:!1},z={operator:A.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=le(i);return e&&pe(n)?!a.createREGEXFromWildChar(n).test(e):e!==n}return U(i)?i!==n:!0}},se=new Map([]);[ee,te,re,ne,ie,z].forEach(i=>{se.set(i.operator,i)});function ve(i){return!!i}const Fe={fn:(i,n)=>{const e=le(i);return e===null?n==="":a.createREGEXFromWildChar(n).test(e)}};function V(i){return i?se.get(i):Fe}function U(i){return typeof i=="number"}function oe(i){return!!(typeof i=="number"||typeof i=="string"&&a.isNumeric(i))}function le(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function pe(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}const W=()=>new Set;class P extends a.Disposable{constructor(e,t,r){super();v(this,"_filteredOutRows$",new I.BehaviorSubject(W()));v(this,"filteredOutRows$",this._filteredOutRows$.asObservable());v(this,"_hasCriteria$",new I.BehaviorSubject(!1));v(this,"hasCriteria$",this._hasCriteria$.asObservable());v(this,"_filterColumnByIndex",new Map);v(this,"_alreadyFilteredOutRows",W());v(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete(),this._worksheet=null}serialize(){const e={ref:a.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([t],[r])=>t-r).map(([t,r])=>r.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,r,s){const o=new P(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut&&(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new Error("[FilterModel] could not get range before a range is set!");return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?a.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=W(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){const r=this._range;if(!r)throw new Error("[FilterModel] could not set criteria before a range is set!");const{startColumn:s,endColumn:o}=r;if(e>o||e<s)throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let l;this._filterColumnByIndex.has(e)?l=this._filterColumnByIndex.get(e):(l=new ae(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),l.setRangeAndColumn(r,e),this._filterColumnByIndex.set(e,l)),l.setCriteria(t)}_removeCriteria(e){const t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){const e=this._getAllFilterColumns().filter(t=>t.hasCache()).reduce((t,r)=>a.mergeSets(t,r.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){const e=this._getAllFilterColumns().filter(t=>!t.hasCache());for(const t of e){const r=t.reCalc();r&&(this._alreadyFilteredOutRows=a.mergeSets(this._alreadyFilteredOutRows,r))}}}class ae extends a.Disposable{constructor(e,t,r,s,o){super();v(this,"_filteredOutRows",null);v(this,"_filterFn",null);v(this,"_range",null);v(this,"_column",0);v(this,"_filterBy",N.VALUES);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw new Error("[FilterColumn]: could not serialize without a filter column!");return a.Tools.deepClone({...this._criteria,colId:this._column})}hasCache(){return this._filteredOutRows!==null}setRangeAndColumn(e,t){this._range=e,this._column=t}setCriteria(e){this._criteria=e,this._generateFilterFn(),this._filteredOutRows=null}getColumnData(){return a.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:d,rowSpan:c,col:m}=l;if(o.has(d)&&(!c||c===1))continue;if(!(this._filterBy===N.VALUES?this._filterFn(a.extractPureTextFromCell(this._worksheet.getCell(d,m))):this._filterBy===N.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(d,m)):this._filterFn(Ne(this._worksheet,d,m)))&&(s.add(d),c))for(let f=1;f<c;f++)s.add(d+f)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=we(this._criteria),this._filterBy=this._criteria.filters?N.VALUES:this._criteria.colorFilters?N.COLORS:N.CONDITIONS)}}function we(i){if(i.filters)return Me(i.filters);if(i.colorFilters)return Ee(i.colorFilters);if(i.customFilters)return ye(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Me(i){const n=!!i.blank,e=new Set(i.filters);return t=>t===void 0||t===""?n:e.has(typeof t=="string"?t:`${t}`)}function Ee(i){if(i.cellFillColors){const n=new Set(i.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);const t=new a.ColorKit(e.bg.rgb).toRgbString();return n.has(t)}}if(i.cellTextColors){const n=new Set(i.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(Se.COLOR_BLACK_RGB);const t=new a.ColorKit(e.cl.rgb).toRgbString();return n.has(t)}}throw new Error("[FilterModel]: color filters are not supported yet.")}function ye(i){const n=i.customFilters.map(e=>Ae(e));return Te(n)?i.and?Oe(n):Ie(n):n[0]}function Oe(i){const[n,e]=i;return t=>n(t)&&e(t)}function Ie(i){const[n,e]=i;return t=>n(t)||e(t)}function Te(i){return i.length===2}function Ae(i){const n=i.val;if(i.operator===A.NOT_EQUALS&&!oe(n))return r=>z.fn(r,n);if(ve(i.operator)){if(!oe(n))return()=>!1;const r=V(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=V(i.operator);return t=>e.fn(t,n)}function Ne(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?de(t):r?t.t===a.CellValueType.NUMBER&&typeof t.v=="string"?r.v:t.t===a.CellValueType.NUMBER?Number(r.v):de(r):null}function de(i){var t,r;const n=(r=(t=i.p)==null?void 0:t.body)==null?void 0:r.dataStream;if(n)return n.trimEnd();const e=i.v;return typeof e=="string"?i.t===a.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===a.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var be=Object.getOwnPropertyDescriptor,Ue=(i,n,e,t)=>{for(var r=t>1?void 0:t?be(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},q=(i,n)=>(e,t)=>n(e,t,i);const k="SHEET_FILTER_PLUGIN";h.SheetsFilterService=class extends a.Disposable{constructor(e,t,r){super();v(this,"_filterModels",new Map);v(this,"_loadedUnitId$",new I.BehaviorSubject(null));v(this,"loadedUnitId$",this._loadedUnitId$.asObservable());v(this,"_errorMsg$",new I.BehaviorSubject(null));v(this,"errorMsg$",this._errorMsg$.asObservable());v(this,"_activeFilterModel$",new I.BehaviorSubject(null));v(this,"activeFilterModel$",this._activeFilterModel$.asObservable());this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=r,this._initModel(),this._initActiveFilterModel()}get activeFilterModel(){return this._activeFilterModel$.getValue()}ensureFilterModel(e,t){const r=this.getFilterModel(e,t);if(r)return r;const s=this._univerInstanceService.getUniverSheetInstance(e);if(!s)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${e}!`);const o=s.getSheetBySheetId(t);if(!o)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${t}!`);const l=new P(e,t,o);return this._cacheFilterModel(e,t,l),l}getFilterModel(e,t){var r,s;return(s=(r=this._filterModels.get(e))==null?void 0:r.get(t))!=null?s:null}removeFilterModel(e,t){const r=this.getFilterModel(e,t);return r?(r.dispose(),this._filterModels.get(e).delete(t),!0):!1}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch(l){console.error("[SheetsFilterService]: could not get active workbook!",l);return}const t=e.getActiveSheet(!0);if(!t){this._activeFilterModel$.next(null);return}const r=t.getUnitId(),s=t.getSheetId(),o=this.getFilterModel(r,s);this._activeFilterModel$.next(o)}_initActiveFilterModel(){this.disposeWithMe(I.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([e])=>e.type===a.CommandType.MUTATION&&H.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:I.of(null)}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){const t=this._filterModels.get(e);if(!t)return"{}";const r={};return t.forEach((s,o)=>{r[o]=s.serialize()}),JSON.stringify(r)}_deserializeAutoFiltersForUnit(e,t){const r=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(s=>{const o=t[s],l=P.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(t=>t.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:k,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>this._serializeAutoFiltersForUnit(e),parseJson:e=>JSON.parse(e),onLoad:(e,t)=>{this._deserializeAutoFiltersForUnit(e,t),this._loadedUnitId$.next(e),this._updateActiveFilterModel()},onUnLoad:e=>{const t=this._filterModels.get(e);t&&(t.forEach(r=>r.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,r){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,r)}},h.SheetsFilterService=Ue([q(0,a.IResourceManagerService),q(1,a.IUniverInstanceService),q(2,a.ICommandService)],h.SheetsFilterService);const F={id:K,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(h.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:Z,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,d=i.get(h.SheetsFilterService).getFilterModel(t,e);return d?(d.setCriteria(s,r,o),!0):!1}},T={id:X,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(h.SheetsFilterService).removeFilterModel(e,t)}},$={id:Y,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n,s=i.get(h.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}},ce={id:"sheet.command.set-filter-range",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),s=i.get(a.IUniverInstanceService),{unitId:o,subUnitId:l,range:d}=n;if(!_.getSheetCommandTarget(s,n)||e.getFilterModel(o,l))return!1;if(d.endRow===d.startRow){const S=i.get(a.ErrorService),R=i.get(a.LocaleService);return S.emit(R.t("sheets-filter.command.not-valid-filter-range")),!1}const u={id:F.id,params:{unitId:o,subUnitId:l,range:d}},f=t.syncExecuteCommand(u.id,u.params);return f&&r.pushUndoRedo({unitID:o,undoMutations:[{id:T.id,params:{unitId:o,subUnitId:l}}],redoMutations:[u]}),f}},ue={id:"sheet.command.remove-sheet-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(a.IUniverInstanceService),t=i.get(h.SheetsFilterService),r=i.get(a.ICommandService),s=i.get(a.IUndoRedoService),o=_.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:d}=o,c=t.getFilterModel(l,d);if(!c)return!1;const m=c==null?void 0:c.serialize(),u=Be(l,d,m),f=r.syncExecuteCommand(T.id,{unitId:l,subUnitId:d});return f&&s.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:[{id:T.id,params:{unitId:l,subUnitId:d}}]}),f}},$e={id:"sheet.command.smart-toggle-filter",type:a.CommandType.COMMAND,handler:async i=>{const n=i.get(a.IUniverInstanceService),e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r==null?void 0:r.getActiveSheet();if(!s||!r)return!1;const o=r.getUnitId(),l=s.getSheetId();if(e.getFilterModel(o,l))return t.executeCommand(ue.id,{unitId:o,subUnitId:l});const m=i.get(_.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const u=m.range,f=_.isSingleCellSelection(m)?_.expandToContinuousRange(u,{left:!0,right:!0,up:!0,down:!0},s):u;return t.executeCommand(ce.id,{unitId:o,subUnitId:l,range:f})}},Le={id:"sheet.command.set-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:d}=n,c=e.getFilterModel(s,o);if(!c)return!1;const m=c.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const u=c.getFilterColumn(l),f=xe(s,o,l,u),S={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:d}},R=t.syncExecuteCommand(S.id,S.params);return R&&r.pushUndoRedo({unitID:s,undoMutations:[f],redoMutations:[S]}),R}},Pe={id:"sheet.command.clear-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.IUndoRedoService),r=i.get(a.ICommandService),s=i.get(a.IUniverInstanceService),o=_.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:d}=o,c=e.getFilterModel(o.unitId,o.subUnitId);if(!c)return!1;const m=c.serialize(),u=he(l,d,m),f=je(l,d,m);return a.sequenceExecute(f,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:f}),!0):!1}},De={id:"sheet.command.re-calc-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUniverInstanceService),s=_.getSheetCommandTarget(r,n);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand($.id,{unitId:o,subUnitId:l}):!1}};function Be(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),he(i,n,e).forEach(o=>t.push(o)),t}function he(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:s}};t.push(o)}),t}function je(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:null}};t.push(o)}),t}function xe(i,n,e,t){if(!t)return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:null}};const r=t.serialize();return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:r}}}const me="sheets-filter.config",fe={};function He(i,n){for(let e=0;e<i.length;e++){let t=e;if(i[e])for(let r=e+1;r<i.length;r++)i[t]&&i[r]&&n(i[t],i[r])&&(i[t]=null,t=r)}return i.filter(e=>e!==null)}function L(i){return He(i,(n,e)=>n.id===p.id&&e.id===p.id&&n.params.unitId===e.params.unitId&&n.params.subUnitId===e.params.subUnitId&&n.params.col===e.params.col)}var ze=Object.getOwnPropertyDescriptor,Ve=(i,n,e,t)=>{for(var r=t>1?void 0:t?ze(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},b=(i,n)=>(e,t)=>n(e,t,i);let D=class extends a.Disposable{constructor(n,e,t,r,s,o,l){super();v(this,"_disposableCollection",new a.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._dataSyncPrimaryController=o,this._zebraCrossingCacheController=l,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling(),this._initZebraCrossingCacheListener()}_initZebraCrossingCacheListener(){this.disposeWithMe(this._sheetsFilterService.activeFilterModel$.subscribe(n=>{n&&this.disposeWithMe(n.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(n.unitId,n.subUnitId)}))}))}_initCommands(){[p,F,$,T].forEach(n=>{var e;this.disposeWithMe(this._commandService.registerCommand(n)),(e=this._dataSyncPrimaryController)==null||e.registerSyncingMutations(n)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>this._getUpdateFilter(n)})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===_.SetWorksheetActiveOperation.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(r,t)}if(n.id===F.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(e.unitId,e.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(n=>{if(n){const e=this._univerInstanceService.getUniverSheetInstance(n),t=e==null?void 0:e.getActiveSheet();t&&this._registerRefRange(n,t.getSheetId())}}))}_registerRefRange(n,e){var l;this._disposableCollection.dispose();const t=this._univerInstanceService.getUniverSheetInstance(n),r=t==null?void 0:t.getSheetBySheetId(e);if(!t||!r)return;const s=(l=this._sheetsFilterService.getFilterModel(n,e))==null?void 0:l.getRange(),o=d=>{switch(d.id){case _.InsertRowCommand.id:{const c=d.params,m=c.unitId||n,u=c.subUnitId||e;return this._handleInsertRowCommand(c,m,u)}case _.InsertColCommand.id:{const c=d.params,m=c.unitId||n,u=c.subUnitId||e;return this.handleInsertColCommand(c.range,m,u)}case _.RemoveColCommand.id:{const c=d.params;return this.handleRemoveColCommand(c.range,n,e)}case _.RemoveRowCommand.id:{const c=d.params;return this._handleRemoveRowCommand(c,n,e)}case _.EffectRefRangId.MoveColsCommandId:{const c=d.params;return this.handleMoveColsCommand({fromRange:c.fromRange,toRange:c.toRange},n,e)}case _.EffectRefRangId.MoveRowsCommandId:{const c=d.params;return this._handleMoveRowsCommand(c,n,e)}case _.MoveRangeCommand.id:{const c=d.params;return this._handleMoveRangeCommand(c,n,e)}}return{redos:[],undos:[]}};s&&this._disposableCollection.add(this._refRangeService.registerRefRange(s,o,n,e))}_getUpdateFilter(n){const{id:e}=n;switch(e){case _.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case _.CopySheetCommand.id:{const t=n.params,{targetSubUnitId:r,unitId:s,subUnitId:o}=t;return!s||!o||!r?this._handleNull():this._handleCopySheetCommand(s,o,r)}}return{redos:[],undos:[]}}handleInsertColCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:d,endColumn:c}=n,m=c-d+1;if(c>l)return this._handleNull();const u=[],f=[],S=d,R={unitId:e,subUnitId:t,range:{...s,startColumn:d<=o?o+m:o,endColumn:l+m}},w={unitId:e,subUnitId:t,range:s};u.push({id:F.id,params:R}),f.push({id:F.id,params:w});const M=r.getAllFilterColumns().filter(C=>C[0]>=S);if(M.length!==0){const{newRange:C,oldRange:y}=this._moveCriteria(e,t,M,m);u.push(...y.redos,...C.redos),f.push(...C.undos,...y.undos)}return{redos:L(u),undos:L(f)}}_handleInsertRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t),s=(w=r==null?void 0:r.getRange())!=null?w:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{startRow:d,endRow:c}=n.range,m=c-d+1;if(c>l)return this._handleNull();const u=[],f=[],S={unitId:e,subUnitId:t,range:{...s,startRow:d<=o?o+m:o,endRow:l+m}},R={unitId:e,subUnitId:t,range:s};return u.push({id:F.id,params:S}),f.push({id:F.id,params:R}),{redos:L(u),undos:L(f)}}handleRemoveColCommand(n,e,t){var M;const r=this._sheetsFilterService.getFilterModel(e,t),s=(M=r==null?void 0:r.getRange())!=null?M:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:d,endColumn:c}=n;if(d>l)return this._handleNull();const m=[],u=[],f=c<o?0:Math.min(c,l)-Math.max(d,o)+1,S=c-d+1,R=r.getAllFilterColumns();R.forEach(g=>{const[C,y]=g;C<=c&&C>=d&&(m.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:null}}),u.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))});const w=R.filter(g=>{const[C,y]=g;return C>c});let E={undos:[],redos:[]};if(w.length>0){const{oldRange:g,newRange:C}=this._moveCriteria(e,t,w,-S);E=C,m.push(...g.redos),u.unshift(...g.undos)}if(f===l-o+1){const g={unitId:e,subUnitId:t};m.push({id:T.id,params:g}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}})}else{const g=o<=d?o:f===0?o-S:d,C=o<=d?l-f:l-S,y={unitId:e,subUnitId:t,range:{...s,startColumn:g,endColumn:C}};m.push({id:F.id,params:y}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),m.push(...E.redos),u.unshift(...E.undos)}return{undos:u,redos:m}}_handleRemoveRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange(),{startRow:o,endRow:l}=s,{startRow:d,endRow:c}=n.range;if(d>l)return this._handleNull();if(c<o)return{undos:[{id:F.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:F.id,params:{range:{...s,startRow:o-(c-d+1),endRow:l-(c-d+1)},unitId:e,subUnitId:t}}]};const m=[],u=[],f=r.getAllFilterColumns(),S=o<=c&&o>=d;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const R=Math.min(c,l)-Math.max(d,o)+1;if(R===l-o+1||S){const E={unitId:e,subUnitId:t};m.push({id:T.id,params:E}),f.forEach(M=>{const[g,C]=M,y={unitId:e,subUnitId:t,col:g,criteria:{...C.serialize(),colId:g}};u.push({id:p.id,params:y})})}else{const E=(w=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:w.getSheetBySheetId(t);if(!E)return this._handleNull();const M=[];for(let O=d;O<=c;O++)E.getRowFiltered(O)&&M.push(O);const g=Math.min(o,d),C=g+(l-o)-R+M.length,y={unitId:e,subUnitId:t,range:{...s,startRow:g,endRow:C}};m.push({id:F.id,params:y})}return{undos:L(u),redos:L(m)}}handleMoveColsCommand({fromRange:n,toRange:e},t,r){var M;const s=this._sheetsFilterService.getFilterModel(t,r),o=(M=s==null?void 0:s.getRange())!=null?M:null;if(!s||!o)return this._handleNull();const{startColumn:l,endColumn:d}=o;if(n.endColumn<l&&e.startColumn<=l||n.startColumn>d&&e.endColumn>d)return this._handleNull();const c=[],m=[],u={};for(let g=l;g<=d;g++)u[g]={colIndex:g,filter:s.getFilterColumn(g)};a.moveMatrixArray(n.startColumn,n.endColumn-n.startColumn+1,e.startColumn,u);let f=o.startColumn,S=o.endColumn;l>=n.startColumn&&l<=n.endColumn&&e.startColumn>n.startColumn&&n.endColumn<d&&(f=n.endColumn+1),d>=n.startColumn&&d<=n.endColumn&&e.startColumn<n.startColumn&&n.startColumn>l&&(S=n.startColumn-1);const R=Object.keys(u).map(g=>Number(g)),w=R.find(g=>u[g].colIndex===S),E=R.find(g=>u[g].colIndex===f);if(R.forEach(g=>{var Ce,_e;const{colIndex:C,filter:y}=u[g],O=g;if(y){if(O>=E&&O<=w){const Q={unitId:t,subUnitId:r,col:O,criteria:{...y.serialize(),colId:O}},Xe={unitId:t,subUnitId:r,col:O,criteria:s.getFilterColumn(O)?{...(Ce=s.getFilterColumn(O))==null?void 0:Ce.serialize(),colId:O}:null};c.push({id:p.id,params:Q}),m.push({id:p.id,params:Xe})}if(!((_e=u[C])!=null&&_e.filter)){const Q={unitId:t,subUnitId:r,col:C,criteria:null};c.push({id:p.id,params:Q}),m.push({id:p.id,params:{unitId:t,subUnitId:r,col:C,criteria:{...y.serialize(),colId:C}}})}}}),l!==E||d!==w){const g={unitId:t,subUnitId:r,range:{...o,startColumn:E,endColumn:w}};c.unshift({id:F.id,params:g}),m.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:r}})}return{undos:m,redos:c}}_handleMoveRowsCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:d,toRange:c}=n;if(d.endRow<o&&c.startRow<=o||d.startRow>l&&c.endRow>l)return this._handleNull();const m=[],u=[],f={};for(let C=o;C<=l;C++)f[C]={oldIndex:C};const S=o;let R=l;l>=d.startRow&&l<=d.endRow&&c.startRow<d.startRow&&d.startRow>o&&(R=d.startRow-1),a.moveMatrixArray(d.startRow,d.endRow-d.startRow+1,c.startRow,f);const w=Object.keys(f).map(C=>Number(C)),E=w.find(C=>f[C].oldIndex===R),M=w.find(C=>f[C].oldIndex===S);if(o!==M||l!==E){const C={unitId:e,subUnitId:t,range:{...s,startRow:M,endRow:E}};m.push({id:F.id,params:C},{id:$.id,params:{unitId:e,subUnitId:t}}),u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}},{id:$.id,params:{unitId:e,subUnitId:t}})}return{redos:m,undos:u}}_handleMoveRangeCommand(n,e,t){const{fromRange:r,toRange:s}=n,o=this._sheetsFilterService.getFilterModel(e,t);if(!o)return this._handleNull();const l=o.getRange();if(!l)return this._handleNull();const d=[],c=[];if(a.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,u=l.startColumn-r.startColumn,f={startRow:s.startRow+m,startColumn:s.startColumn+u,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+u+(l.endColumn-l.startColumn)},S={id:T.id,params:{unitId:e,subUnitId:t}},R={id:F.id,params:{unitId:e,subUnitId:t,range:f}},w={id:F.id,params:{unitId:e,subUnitId:t,range:l}};d.push(S,R),c.push(S,w);const E=o.getAllFilterColumns(),M=s.startColumn-r.startColumn;E.forEach(g=>{const[C,y]=g;y&&(d.push({id:p.id,params:{unitId:e,subUnitId:t,col:C+M,criteria:{...y.serialize(),colId:C+M}}}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))})}else if(a.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};d.push({id:F.id,params:{unitId:e,subUnitId:t,range:m}}),c.push({id:F.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:d,undos:c}}_handleRemoveSheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[];return r.getAllFilterColumns().forEach(([c,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:c,criteria:{...m.serialize(),colId:c}}})}),o.push({id:T.id,params:{unitId:e,subUnitId:t,range:s}}),l.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),{undos:l,redos:o}}_handleCopySheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(n,e);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[],d=[],c=[];return r.getAllFilterColumns().forEach(([u,f])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:{...f.serialize(),colId:u}}}),d.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:null}})}),d.push({id:T.id,params:{unitId:n,subUnitId:t,range:s}}),o.unshift({id:F.id,params:{range:s,unitId:n,subUnitId:t}}),{undos:l,redos:o,preUndos:d,preRedos:c}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(n,e)=>{var t,r;return n?!0:(r=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?r:!1}}))}_moveCriteria(n,e,t,r){const s={unitId:n,subUnitId:e,criteria:null,col:-1},o=[],l=[],d=[],c=[];return t.forEach(m=>{const[u,f]=m;l.push({id:p.id,params:{...s,col:u}}),o.push({id:p.id,params:{...s,col:u,criteria:{...f.serialize(),colId:u}}})}),t.forEach(m=>{const[u,f]=m;c.push({id:p.id,params:{...s,col:u+r,criteria:{...f.serialize(),colId:u+r}}}),d.push({id:p.id,params:{...s,col:u+r,criteria:null}})}),{newRange:{redos:c,undos:d},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var c,m;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((u,f)=>u-f),l=[];let d=!1;if(n.id===_.RemoveRowMutation.id){const{startRow:u,endRow:f}=n.params.range,S=o.filter(R=>R>=u&&R<=f);o.forEach(R=>{if(R<u)l.push(R);else if(d=!0,R<=f){const w=Math.max(u,l.length?l[l.length-1]+1:u);l.push(w)}else l.push(R-(f-u+1-S.length))})}if(n.id===_.InsertRowMutation.id){const{startRow:u,endRow:f}=n.params.range;o.forEach(S=>{S>=u?(d=!0,l.push(S+(f-u+1))):l.push(S)})}if(d&&(s.filteredOutRows=new Set(l)),n.id===_.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const u=this._getExtendRegion(t,r);if(u){const f=n.params.cellValue;if(f)for(let S=u.startColumn;S<=u.endColumn;S++){const R=(c=f==null?void 0:f[u.startRow])==null?void 0:c[S];if(R&&this._cellHasValue(R)){const w=(m=this._univerInstanceService.getUnit(t))==null?void 0:m.getSheetBySheetId(r);if(w){const E=_.expandToContinuousRange(u,{down:!0},w),M=this._sheetsFilterService.getFilterModel(t,r),g=M.getRange();M.setRange({...g,endRow:E.endRow}),this._registerRefRange(t,r)}}}}}}))}_getExtendRegion(n,e){var d;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(d=this._univerInstanceService.getUnit(n))==null?void 0:d.getSheetBySheetId(e);if(!r)return null;const s=t.getRange();if(!s)return null;const o=r.getRowCount()-1,l=r.getRowManager();for(let c=s.endRow+1;c<=o;c++)if(l.getRowRawVisible(c))return{startRow:c,endRow:c,startColumn:s.startColumn,endColumn:s.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(n=>{const e=n.params,t=_.getSheetCommandTarget(this._univerInstanceService);if(!t)return;const{subUnitId:r,unitId:s}=t,o=this._sheetsFilterService.getFilterModel(s,r);if(!o)return;const l=o.getRange();if(n.id===_.MoveRowsCommand.id&&e.fromRange.startRow<=l.startRow&&e.fromRange.endRow<l.endRow&&e.fromRange.endRow>=l.startRow)throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"),new Error("[SheetsFilterController]: Cannot move header row of filter")}))}_cellHasValue(n){const e=Object.values(n);return!(e.length===0||e.every(t=>t==null))}};D=Ve([b(0,a.ICommandService),b(1,a.Inject(_.SheetInterceptorService)),b(2,a.Inject(h.SheetsFilterService)),b(3,a.IUniverInstanceService),b(4,a.Inject(_.RefRangeService)),b(5,a.Optional(Re.DataSyncPrimaryController)),b(6,a.Inject(_.ZebraCrossingCacheController))],D);var We=Object.getOwnPropertyDescriptor,qe=(i,n,e,t)=>{for(var r=t>1?void 0:t?We(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},G=(i,n)=>(e,t)=>n(e,t,i);const ke=[p.id,$.id],Ge=[_.InsertColMutation.id,_.RemoveColMutation.id,_.MoveColsMutation.id];h.SheetsFilterSyncController=class extends a.Disposable{constructor(e,t,r){var o;super();v(this,"_d",new a.DisposableCollection);v(this,"_visible$",new I.BehaviorSubject(!1));v(this,"visible$",this._visible$.asObservable());v(this,"_enabled$",new I.BehaviorSubject(!0));v(this,"enabled$",this._enabled$.asObservable());this._sheetsFilterController=e,this._commandService=t,this._configService=r;const s=this._configService.getConfig(me);s!=null&&s.enableSyncSwitch&&(this._visible$.next(!0),typeof s.enableSyncSwitch=="object"&&this.setEnabled((o=s.enableSyncSwitch.defaultValue)!=null?o:!0))}get visible(){return this._visible$.getValue()}get enabled(){return this._enabled$.getValue()}setEnabled(e){this._enabled$.next(e),e?this._d.dispose():this._initOnlyLocalListener()}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((e,t)=>{ke.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,t)=>{if(Ge.includes(e.id)&&(t!=null&&t.fromCollab)){if(e.id===_.InsertColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleInsertColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.RemoveColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleRemoveColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.MoveColsMutation.id){const{sourceRange:r,targetRange:s,unitId:o,subUnitId:l}=e.params,{redos:d}=this._sheetsFilterController.handleMoveColsCommand({fromRange:r,toRange:s},o,l);a.sequenceExecute(d,this._commandService,t)}}}))}},h.SheetsFilterSyncController=qe([G(0,a.Inject(D)),G(1,a.ICommandService),G(2,a.IConfigService)],h.SheetsFilterSyncController);var Qe=Object.getOwnPropertyDescriptor,Je=(i,n,e,t)=>{for(var r=t>1?void 0:t?Qe(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},B=(i,n)=>(e,t)=>n(e,t,i);let j=class extends a.Disposable{constructor(i,n,e,t){super(),this._activeDirtyManagerService=i,this._sheetRowFilteredService=n,this._sheetsFilterService=e,this._univerInstanceService=t,this._initFormulaDirtyRange(),this._registerSheetRowFiltered()}_initFormulaDirtyRange(){H.forEach(i=>{this._activeDirtyManagerService.register(i,{commandId:i,getDirtyData:n=>{const e=n.params,{unitId:t,subUnitId:r}=e;return{dirtyRanges:this._getHideRowMutation(t,r),clearDependencyTreeCache:{[t]:{[r]:"1"}}}}})})}_getHideRowMutation(i,n){var l,d;const e=(l=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:l.getRange(),t=(d=this._univerInstanceService.getUnit(i))==null?void 0:d.getSheetBySheetId(n);if(e==null||t==null)return[];const{startRow:r,endRow:s}=e;return[{unitId:i,sheetId:n,range:{startRow:r,startColumn:0,endRow:s,endColumn:t.getColumnCount()-1}}]}_registerSheetRowFiltered(){this._sheetRowFilteredService.register((i,n,e)=>{var t,r;return(r=(t=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:t.isRowFiltered(e))!=null?r:!1})}};j=Je([B(0,a.Inject(J.IActiveDirtyManagerService)),B(1,a.Inject(J.ISheetRowFilteredService)),B(2,a.Inject(h.SheetsFilterService)),B(3,a.IUniverInstanceService)],j);var Ke=Object.getOwnPropertyDescriptor,Ze=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ke(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},ge=(i,n)=>(e,t)=>n(e,t,i);h.UniverSheetsFilterPlugin=(x=class extends a.Plugin{constructor(n=fe,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=a.merge({},fe,this._config);this._configService.setConfig(me,r)}onStarting(){[[j],[h.SheetsFilterService],[D],[h.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){a.touchDependencies(this._injector,[[j],[D],[h.SheetsFilterSyncController]])}},v(x,"type",a.UniverInstanceType.UNIVER_SHEET),v(x,"pluginName",k),x),h.UniverSheetsFilterPlugin=Ze([ge(1,a.Inject(a.Injector)),ge(2,a.IConfigService)],h.UniverSheetsFilterPlugin),h.ClearSheetsFilterCriteriaCommand=Pe,h.CustomFilterOperator=A,h.FILTER_MUTATIONS=H,h.FilterBy=N,h.FilterColumn=ae,h.FilterModel=P,h.ReCalcSheetsFilterCommand=De,h.ReCalcSheetsFilterMutation=$,h.RemoveSheetFilterCommand=ue,h.RemoveSheetsFilterMutation=T,h.SHEET_FILTER_SNAPSHOT_ID=k,h.SetSheetFilterRangeCommand=ce,h.SetSheetsFilterCriteriaCommand=Le,h.SetSheetsFilterCriteriaMutation=p,h.SetSheetsFilterRangeMutation=F,h.SmartToggleSheetsFilterCommand=$e,h.equals=ie,h.getCustomFilterFn=V,h.greaterThan=ee,h.greaterThanOrEqualTo=te,h.lessThan=re,h.lessThanOrEqualTo=ne,h.notEquals=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
// @univerjs/sheets-filter/facade
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
// @univerjs/sheets-hyper-link/index
|
|
56
|
-
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/sheets","rxjs","@univerjs/engine-formula"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverSheetsHyperLink={},g.UniverCore,g.UniverDocs,g.UniverSheets,g.rxjs,g.UniverEngineFormula))})(this,(function(g,a,w,m,Se,C){"use strict";var Ke=Object.defineProperty;var Ye=(g,a,w)=>a in g?Ke(g,a,{enumerable:!0,configurable:!0,writable:!0,value:w}):g[a]=w;var L=(g,a,w)=>Ye(g,typeof a!="symbol"?a+"":a,w);var Ie=Object.getOwnPropertyDescriptor,Re=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ie(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Me=(r,t)=>(e,n)=>t(e,n,r);g.HyperLinkModel=class extends a.Disposable{constructor(e){super();L(this,"_linkUpdate$",new Se.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new a.ObjectMatrix,i.set(n,s));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let d=o.get(n);return d||(d=new Map,o.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),o.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:o})),!0}updateHyperLinkRef(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var p,f,y,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(i,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(y=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:y.dataStream.slice(0,-2))!=null?_:"").toString(),u=o.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((o,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},g.HyperLinkModel=Re([Me(0,a.IUniverInstanceService)],g.HyperLinkModel);const E={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},T={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},re={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:f}=t,{payload:y,display:h,row:_,column:v,id:S}=f,k=p.getCell(_,v),I=p.getBlankCellDocumentModel(k,_,v),R=I.documentModel.getSnapshot(),M=a.Tools.deepClone(R.body);if(!M)return!1;let H;if(h?H=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:a.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:y}}]},doc:I.documentModel}):H=a.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:y,refId:S}}),!H)return!1;const j=a.TextX.apply(M,H.serialize()),b={p:{...R,body:j},t:a.CellValueType.STRING},N=o.onWriteCell(u,p,_,v,b),V={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},ie={id:m.SetRangeValuesMutation.id,params:V},Q=m.SetRangeValuesUndoMutationFactory(r,V),se={id:m.SetRangeValuesMutation.id,params:Q},A=[ie],P=[se],D=s.getHyperLinkByLocation(c,l,_,v);return D&&(A.push({id:T.id,params:{unitId:c,subUnitId:l,id:D.id}}),P.push({id:E.id,params:{unitId:c,subUnitId:l,link:D}})),await a.sequenceExecute(A,e)?await o.onValidateCell(u,p,_,v)===!1?(a.sequenceExecute(P,e),!1):(n.pushUndoRedo({redoMutations:A,undoMutations:P,unitID:c}),!0):!1}},ae={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(a.ICommandService),s=a.generateRandomId(),{payload:o}=n,d=w.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},oe={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=m.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:f}=o,y=f.getCell(d,c);if(!y)return!1;const h=f.getCellDocumentModelWithFormula(y,d,c);if(!(h!=null&&h.documentModel))return!1;const _=a.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(b=_.body)==null?void 0:b.customRanges)==null?void 0:N.find(V=>`${V.rangeId}`===l);if(!v)return!1;const S=a.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:v.rangeId});if(!S)return!1;const k=a.TextX.apply(_.body,S.serialize()),I=[],R=[],M={unitId:u,subUnitId:p,cellValue:{[d]:{[c]:{p:{..._,body:k},t:a.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const H=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:H});const j=s.getHyperLinkByLocation(u,p,d,c);return j&&(I.push({id:T.id,params:{unitId:u,subUnitId:p,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:p,link:{...j}}})),a.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},de={type:a.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(a.ICommandService),o=r.get(a.IUniverInstanceService).getUnit(n,a.UniverInstanceType.UNIVER_DOC),d=(p=(u=o==null?void 0:o.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(c={dataStream:" "});const l=w.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},ce={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var fe,ye,_e;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=t,{workbook:f,worksheet:y,unitId:h,subUnitId:_}=d,{payload:v,display:S=""}=c,k=y.getCell(l,u);if(!k)return!1;const I=y.getCellDocumentModelWithFormula(k,l,u);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(ye=(fe=R.body)==null?void 0:fe.customRanges)==null?void 0:ye.find(ve=>`${ve.rangeId}`===p);if(!M)return!1;const H=a.generateRandomId(),O=(_e=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:_e[0];O&&(O.ed=S.length+1);const b=w.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:H,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:O?[O]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!b)return!1;const N=a.TextX.apply(a.Tools.deepClone(R.body),b.textX.serialize()),V={p:{...R,body:N},t:a.CellValueType.STRING},ie=o.onWriteCell(f,y,l,u,V),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:ie}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},P=[Q],D=[A],Z=s.getHyperLinkByLocation(h,_,l,u);return Z&&(P.push({id:T.id,params:{unitId:h,subUnitId:_,id:Z.id}}),D.push({id:E.id,params:{unitId:h,subUnitId:_,link:Z}})),a.sequenceExecute(P,e)?await o.onValidateCell(f,y,l,u)===!1?(a.sequenceExecute(D,e),!1):(n.pushUndoRedo({redoMutations:P,undoMutations:D,unitID:h}),!0):!1}},le={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),d=s.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(k=>k.rangeId===i);if(!c)return!1;const l=(v=t.payload.display)!=null?v:"",u=a.generateRandomId(),f=(S=a.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];f&&(f.ed=l.length+1);const y=w.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return y?o.syncExecuteCommand(y.id,y.params):!1}},x={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:o}=t;return e.updateHyperLink(n,i,o,s,!1)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:o,column:d},c)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:o,url:d}=t,c=r.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(i,s),f=(_=(h=(y=p==null?void 0:p.p)==null?void 0:y.body)==null?void 0:h.customRanges)==null?void 0:_.find(v=>v.rangeType===a.CustomRangeType.HYPERLINK&&v.rangeId===o);return f&&(f.properties.url=d),!0}},Ce="sheets-hyper-link.config",ue={},pe="SHEET_HYPER_LINK_PLUGIN",$="err";var ke=Object.getOwnPropertyDescriptor,Le=(r,t,e,n)=>{for(var i=n>1?void 0:n?ke(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},z=(r,t)=>(e,n)=>t(e,n,r);let K=class extends a.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:s}}]}:{redos:[{id:T.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,o,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(o,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);a.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(o=c.get("range"))!=null?o:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,p=C.deserializeRangeWithSheet(l.range).range;if(a.isValidRange(p)&&l.range!==$){const f=y=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,y,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(y,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:o}=n;o.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),s||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(a.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};K=Le([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(g.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],K);var Ue=Object.getOwnPropertyDescriptor,we=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ue(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ee=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends a.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,s),d=o.map(l=>({id:T.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=we([ee(0,a.Inject(m.SheetInterceptorService)),ee(1,a.IUniverInstanceService),ee(2,a.Inject(g.HyperLinkModel))],Y);var Ee=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},te=(r,t)=>(e,n)=>t(e,n,r);let q=class extends a.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new a.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,o;const n=this._univerInstanceService.getUnit(t,a.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(o=d.get("rangeid"))!=null?o:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const p=C.deserializeRangeWithSheet(c.range).range;if(a.isValidRange(p,u)&&c.range!==$)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(p=>{var f;return p.rangeType===a.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=p.properties)==null?void 0:f.url)})){const p=new a.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(y=>{var h;if(y.rangeType===a.CustomRangeType.HYPERLINK){const _=(h=y.properties)==null?void 0:h.url,v=this._isLegalRangeUrl(t,_);if(v){const{range:S,worksheet:k}=v;f=!0,p.add(this._refRangeService.registerRefRange(S,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(S,I);return R&&a.Rectangle.equals(R,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:_}}],redos:[]}},k.getUnitId(),k.getSheetId()))}}}),f&&o.setValue(n,i,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),o=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===a.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===a.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,o=this._enusreMap(n,i);s&&new a.ObjectMatrix(s).forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,o);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,o);p&&p.p&&this._registerRange(n,i,s,o,p.p)}}}))}};q=Te([te(0,a.ICommandService),te(1,a.IUniverInstanceService),te(2,a.Inject(m.RefRangeService))],q);var He=Object.getOwnPropertyDescriptor,be=(r,t,e,n)=>{for(var i=n>1?void 0:n?He(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},G=(r,t)=>(e,n)=>t(e,n,r);let F=class extends a.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:T.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,o,d,c);l&&(t.push({id:T.id,params:{unitId:s,subUnitId:o,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&a.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i,row:s,col:o}=t,d=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),c=d==null?void 0:d.getSheetBySheetId(i);if(!c)return e(r);const l=c.getBlankCellDocumentModel(r,s,o);if(!l.documentModel)return e(r);const u=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:l.documentModel});if(!u)return e(r);const p=l.documentModel.getBody();return a.TextX.apply(p,u.serialize()),e({...r,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:p,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};F=be([G(0,a.Inject(m.SheetInterceptorService)),G(1,a.Inject(g.HyperLinkModel)),G(2,a.Inject(m.SheetsSelectionsService)),G(3,a.IUniverInstanceService)],F);var Pe=Object.getOwnPropertyDescriptor,De=(r,t,e,n)=>{for(var i=n>1?void 0:n?Pe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ge=(r,t)=>(e,n)=>t(e,n,r);let X=class extends a.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:pe,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};X=De([ge(0,a.IResourceManagerService),ge(1,a.Inject(g.HyperLinkModel))],X);var Oe=Object.getOwnPropertyDescriptor,Ne=(r,t,e,n)=>{for(var i=n>1?void 0:n?Oe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Ve=(r,t)=>(e,n)=>t(e,n,r);let J=class extends a.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[re,ce,oe,le,de,ae,E,x,T,W,B].forEach(r=>{this._commandService.registerCommand(r)})}};J=Ne([Ve(0,a.ICommandService)],J);var U=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(U||{}),$e=Object.getOwnPropertyDescriptor,je=(r,t,e,n)=>{for(var i=n>1?void 0:n?$e(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ne=(r,t)=>(e,n)=>t(e,n,r);g.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const o=new URLSearchParams(t.slice(1)),d={gid:(e=o.get("gid"))!=null?e:"",range:(n=o.get("range"))!=null?n:"",rangeid:(i=o.get("rangeid"))!=null?i:"",unitid:(s=o.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:U.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,o=s?this._univerInstanceService.getUnit(s,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d={type:U.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!o)return d;const c=e?o.getSheetBySheetId(e):o.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const p=C.deserializeRangeWithSheet(n).range;return a.isValidRange(p,c)&&n!==$?{type:U.RANGE,name:C.serializeRangeWithSheet(l,p)}:d}if(i){const p=this._definedNamesService.getValueById(o.getUnitId(),i);return p?{type:U.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=o.getSheetBySheetId(e);return p?{type:U.SHEET,name:p.getName()}:d}return d}},g.SheetsHyperLinkParserService=je([ne(0,a.IUniverInstanceService),ne(1,a.Inject(a.LocaleService)),ne(2,C.IDefinedNamesService)],g.SheetsHyperLinkParserService);var Ae=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,We=(r,t,e)=>t in r?Ae(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Be=(r,t,e,n)=>{for(var i=n>1?void 0:n?xe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},he=(r,t)=>(e,n)=>t(e,n,r),me=(r,t,e)=>We(r,typeof t!="symbol"?t+"":t,e);g.UniverSheetsHyperLinkPlugin=class extends a.Plugin{constructor(t=ue,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=a.merge({},ue,this._config);this._configService.setConfig(Ce,i)}onStarting(){a.registerDependencies(this._injector,[[g.HyperLinkModel],[g.SheetsHyperLinkParserService],[X],[J],[K],[F],[Y],[q]]),a.touchDependencies(this._injector,[[K],[X],[J],[F],[Y],[q]])}},me(g.UniverSheetsHyperLinkPlugin,"pluginName",pe),me(g.UniverSheetsHyperLinkPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsHyperLinkPlugin=Be([a.DependentOn(m.UniverSheetsPlugin),he(1,a.Inject(a.Injector)),he(2,a.IConfigService)],g.UniverSheetsHyperLinkPlugin),g.AddHyperLinkCommand=re,g.AddHyperLinkMutation=E,g.AddRichHyperLinkCommand=ae,g.CancelHyperLinkCommand=oe,g.CancelRichHyperLinkCommand=de,g.ERROR_RANGE=$,g.RemoveHyperLinkMutation=T,g.SheetHyperLinkType=U,g.UpdateHyperLinkCommand=ce,g.UpdateHyperLinkMutation=x,g.UpdateHyperLinkRefMutation=W,g.UpdateRichHyperLinkCommand=le,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
|
56
|
+
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/sheets","rxjs","@univerjs/engine-formula"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverSheetsHyperLink={},g.UniverCore,g.UniverDocs,g.UniverSheets,g.rxjs,g.UniverEngineFormula))})(this,(function(g,a,w,m,Se,C){"use strict";var Ke=Object.defineProperty;var Ye=(g,a,w)=>a in g?Ke(g,a,{enumerable:!0,configurable:!0,writable:!0,value:w}):g[a]=w;var L=(g,a,w)=>Ye(g,typeof a!="symbol"?a+"":a,w);var Ie=Object.getOwnPropertyDescriptor,Re=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ie(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Me=(r,t)=>(e,n)=>t(e,n,r);g.HyperLinkModel=class extends a.Disposable{constructor(e){super();L(this,"_linkUpdate$",new Se.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new a.ObjectMatrix,i.set(n,s));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let d=o.get(n);return d||(d=new Map,o.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),o.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:o})),!0}updateHyperLinkRef(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var p,f,y,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(i,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(y=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:y.dataStream.slice(0,-2))!=null?_:"").toString(),u=o.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((o,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},g.HyperLinkModel=Re([Me(0,a.IUniverInstanceService)],g.HyperLinkModel);const E={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},T={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},re={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:f}=t,{payload:y,display:h,row:_,column:v,id:S}=f,k=p.getCell(_,v),I=p.getBlankCellDocumentModel(k,_,v),R=I.documentModel.getSnapshot(),M=a.Tools.deepClone(R.body);if(!M)return!1;let H;if(h?H=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:a.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:y}}]},doc:I.documentModel}):H=a.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:y,refId:S}}),!H)return!1;const j=a.TextX.apply(M,H.serialize()),b={p:{...R,body:j},t:a.CellValueType.STRING},N=o.onWriteCell(u,p,_,v,b),V={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},ie={id:m.SetRangeValuesMutation.id,params:V},Q=m.SetRangeValuesUndoMutationFactory(r,V),se={id:m.SetRangeValuesMutation.id,params:Q},A=[ie],P=[se],D=s.getHyperLinkByLocation(c,l,_,v);return D&&(A.push({id:T.id,params:{unitId:c,subUnitId:l,id:D.id}}),P.push({id:E.id,params:{unitId:c,subUnitId:l,link:D}})),await a.sequenceExecute(A,e)?await o.onValidateCell(u,p,_,v)===!1?(a.sequenceExecute(P,e),!1):(n.pushUndoRedo({redoMutations:A,undoMutations:P,unitID:c}),!0):!1}},ae={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(a.ICommandService),s=a.generateRandomId(),{payload:o}=n,d=w.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},oe={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=m.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:f}=o,y=f.getCell(d,c);if(!y)return!1;const h=f.getCellDocumentModelWithFormula(y,d,c);if(!(h!=null&&h.documentModel))return!1;const _=a.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(b=_.body)==null?void 0:b.customRanges)==null?void 0:N.find(V=>`${V.rangeId}`===l);if(!v)return!1;const S=a.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:v.rangeId});if(!S)return!1;const k=a.TextX.apply(_.body,S.serialize()),I=[],R=[],M={unitId:u,subUnitId:p,cellValue:{[d]:{[c]:{p:{..._,body:k},t:a.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const H=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:H});const j=s.getHyperLinkByLocation(u,p,d,c);return j&&(I.push({id:T.id,params:{unitId:u,subUnitId:p,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:p,link:{...j}}})),a.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},de={type:a.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(a.ICommandService),o=r.get(a.IUniverInstanceService).getUnit(n,a.UniverInstanceType.UNIVER_DOC),d=(p=(u=o==null?void 0:o.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(c={dataStream:" "});const l=w.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},ce={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var fe,ye,_e;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=t,{workbook:f,worksheet:y,unitId:h,subUnitId:_}=d,{payload:v,display:S=""}=c,k=y.getCell(l,u);if(!k)return!1;const I=y.getCellDocumentModelWithFormula(k,l,u);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(ye=(fe=R.body)==null?void 0:fe.customRanges)==null?void 0:ye.find(ve=>`${ve.rangeId}`===p);if(!M)return!1;const H=a.generateRandomId(),O=(_e=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:_e[0];O&&(O.ed=S.length+1);const b=w.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:H,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:O?[O]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!b)return!1;const N=a.TextX.apply(a.Tools.deepClone(R.body),b.textX.serialize()),V={p:{...R,body:N},t:a.CellValueType.STRING},ie=o.onWriteCell(f,y,l,u,V),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:ie}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},P=[Q],D=[A],Z=s.getHyperLinkByLocation(h,_,l,u);return Z&&(P.push({id:T.id,params:{unitId:h,subUnitId:_,id:Z.id}}),D.push({id:E.id,params:{unitId:h,subUnitId:_,link:Z}})),a.sequenceExecute(P,e)?await o.onValidateCell(f,y,l,u)===!1?(a.sequenceExecute(D,e),!1):(n.pushUndoRedo({redoMutations:P,undoMutations:D,unitID:h}),!0):!1}},le={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),d=s.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(k=>k.rangeId===i);if(!c)return!1;const l=(v=t.payload.display)!=null?v:"",u=a.generateRandomId(),f=(S=a.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];f&&(f.ed=l.length+1);const y=w.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return y?o.syncExecuteCommand(y.id,y.params):!1}},x={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:o}=t;return e.updateHyperLink(n,i,o,s,!1)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:o,column:d},c)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:o,url:d}=t,c=r.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(i,s),f=(_=(h=(y=p==null?void 0:p.p)==null?void 0:y.body)==null?void 0:h.customRanges)==null?void 0:_.find(v=>v.rangeType===a.CustomRangeType.HYPERLINK&&v.rangeId===o);return f&&(f.properties.url=d),!0}},Ce="sheets-hyper-link.config",ue={},pe="SHEET_HYPER_LINK_PLUGIN",$="err";var ke=Object.getOwnPropertyDescriptor,Le=(r,t,e,n)=>{for(var i=n>1?void 0:n?ke(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},z=(r,t)=>(e,n)=>t(e,n,r);let K=class extends a.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:s}}]}:{redos:[{id:T.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,o,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(o,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);a.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(o=c.get("range"))!=null?o:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,p=C.deserializeRangeWithSheet(l.range).range;if(a.isValidRange(p)&&l.range!==$){const f=y=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,y,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(y,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:o}=n;o.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),s||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(a.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};K=Le([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(g.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],K);var Ue=Object.getOwnPropertyDescriptor,we=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ue(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ee=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends a.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,s),d=o.map(l=>({id:T.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=we([ee(0,a.Inject(m.SheetInterceptorService)),ee(1,a.IUniverInstanceService),ee(2,a.Inject(g.HyperLinkModel))],Y);var Ee=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},te=(r,t)=>(e,n)=>t(e,n,r);let q=class extends a.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new a.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,o;const n=this._univerInstanceService.getUnit(t,a.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(o=d.get("rangeid"))!=null?o:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const p=C.deserializeRangeWithSheet(c.range).range;if(a.isValidRange(p,u)&&c.range!==$)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(p=>{var f;return p.rangeType===a.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=p.properties)==null?void 0:f.url)})){const p=new a.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(y=>{var h;if(y.rangeType===a.CustomRangeType.HYPERLINK){const _=(h=y.properties)==null?void 0:h.url,v=this._isLegalRangeUrl(t,_);if(v){const{range:S,worksheet:k}=v;f=!0,p.add(this._refRangeService.registerRefRange(S,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(S,I);return R&&a.Rectangle.equals(R,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:_}}],redos:[]}},k.getUnitId(),k.getSheetId()))}}}),f&&o.setValue(n,i,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),o=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===a.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===a.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,o=this._enusreMap(n,i);s&&new a.ObjectMatrix(s).forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,o);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,o);p&&p.p&&this._registerRange(n,i,s,o,p.p)}}}))}};q=Te([te(0,a.ICommandService),te(1,a.IUniverInstanceService),te(2,a.Inject(m.RefRangeService))],q);var He=Object.getOwnPropertyDescriptor,be=(r,t,e,n)=>{for(var i=n>1?void 0:n?He(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},G=(r,t)=>(e,n)=>t(e,n,r);let F=class extends a.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:T.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,o,d,c);l&&(t.push({id:T.id,params:{unitId:s,subUnitId:o,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&a.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i,row:s,col:o}=t,d=a.Tools.normalizeUrl(r.v),c=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),l=c==null?void 0:c.getSheetBySheetId(i);if(!l)return e(r);const u=l.getBlankCellDocumentModel(r,s,o);if(!u.documentModel)return e(r);const p=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:d}}]},doc:u.documentModel});if(!p)return e(r);const f=u.documentModel.getBody();return a.TextX.apply(f,p.serialize()),e({...r,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:f,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};F=be([G(0,a.Inject(m.SheetInterceptorService)),G(1,a.Inject(g.HyperLinkModel)),G(2,a.Inject(m.SheetsSelectionsService)),G(3,a.IUniverInstanceService)],F);var Pe=Object.getOwnPropertyDescriptor,De=(r,t,e,n)=>{for(var i=n>1?void 0:n?Pe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ge=(r,t)=>(e,n)=>t(e,n,r);let X=class extends a.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:pe,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};X=De([ge(0,a.IResourceManagerService),ge(1,a.Inject(g.HyperLinkModel))],X);var Oe=Object.getOwnPropertyDescriptor,Ne=(r,t,e,n)=>{for(var i=n>1?void 0:n?Oe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Ve=(r,t)=>(e,n)=>t(e,n,r);let J=class extends a.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[re,ce,oe,le,de,ae,E,x,T,W,B].forEach(r=>{this._commandService.registerCommand(r)})}};J=Ne([Ve(0,a.ICommandService)],J);var U=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(U||{}),$e=Object.getOwnPropertyDescriptor,je=(r,t,e,n)=>{for(var i=n>1?void 0:n?$e(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ne=(r,t)=>(e,n)=>t(e,n,r);g.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const o=new URLSearchParams(t.slice(1)),d={gid:(e=o.get("gid"))!=null?e:"",range:(n=o.get("range"))!=null?n:"",rangeid:(i=o.get("rangeid"))!=null?i:"",unitid:(s=o.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:U.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,o=s?this._univerInstanceService.getUnit(s,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d={type:U.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!o)return d;const c=e?o.getSheetBySheetId(e):o.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const p=C.deserializeRangeWithSheet(n).range;return a.isValidRange(p,c)&&n!==$?{type:U.RANGE,name:C.serializeRangeWithSheet(l,p)}:d}if(i){const p=this._definedNamesService.getValueById(o.getUnitId(),i);return p?{type:U.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=o.getSheetBySheetId(e);return p?{type:U.SHEET,name:p.getName()}:d}return d}},g.SheetsHyperLinkParserService=je([ne(0,a.IUniverInstanceService),ne(1,a.Inject(a.LocaleService)),ne(2,C.IDefinedNamesService)],g.SheetsHyperLinkParserService);var Ae=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,We=(r,t,e)=>t in r?Ae(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Be=(r,t,e,n)=>{for(var i=n>1?void 0:n?xe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},he=(r,t)=>(e,n)=>t(e,n,r),me=(r,t,e)=>We(r,typeof t!="symbol"?t+"":t,e);g.UniverSheetsHyperLinkPlugin=class extends a.Plugin{constructor(t=ue,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=a.merge({},ue,this._config);this._configService.setConfig(Ce,i)}onStarting(){a.registerDependencies(this._injector,[[g.HyperLinkModel],[g.SheetsHyperLinkParserService],[X],[J],[K],[F],[Y],[q]]),a.touchDependencies(this._injector,[[K],[X],[J],[F],[Y],[q]])}},me(g.UniverSheetsHyperLinkPlugin,"pluginName",pe),me(g.UniverSheetsHyperLinkPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsHyperLinkPlugin=Be([a.DependentOn(m.UniverSheetsPlugin),he(1,a.Inject(a.Injector)),he(2,a.IConfigService)],g.UniverSheetsHyperLinkPlugin),g.AddHyperLinkCommand=re,g.AddHyperLinkMutation=E,g.AddRichHyperLinkCommand=ae,g.CancelHyperLinkCommand=oe,g.CancelRichHyperLinkCommand=de,g.ERROR_RANGE=$,g.RemoveHyperLinkMutation=T,g.SheetHyperLinkType=U,g.UpdateHyperLinkCommand=ce,g.UpdateHyperLinkMutation=x,g.UpdateHyperLinkRefMutation=W,g.UpdateRichHyperLinkCommand=le,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
// @univerjs/sheets-hyper-link/facade
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
// @univerjs/sheets-thread-comment/index
|
|
76
|
-
(function(d,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/thread-comment"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-formula","@univerjs/sheets","@univerjs/thread-comment","rxjs"],o):(d=typeof globalThis<"u"?globalThis:d||self,o(d.UniverSheetsThreadComment={},d.UniverCore,d.UniverEngineFormula,d.UniverSheets,d.UniverThreadComment,d.rxjs))})(this,(function(d,o,l,p,g,w){"use strict";var D=Object.defineProperty;var x=(d,o,l)=>o in d?D(d,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):d[o]=l;var f=(d,o,l)=>x(d,typeof o!="symbol"?o+"":o,l);var S=Object.getOwnPropertyDescriptor,T=(h,m,e,n)=>{for(var t=n>1?void 0:n?S(m,e):m,r=h.length-1,s;r>=0;r--)(s=h[r])&&(t=s(t)||t);return t},M=(h,m)=>(e,n)=>m(e,n,h);d.SheetsThreadCommentModel=class extends o.Disposable{constructor(e,n){super();f(this,"_matrixMap",new Map);f(this,"_locationMap",new Map);f(this,"_commentUpdate$",new w.Subject);f(this,"commentUpdate$",this._commentUpdate$.asObservable());this._threadCommentModel=e,this._univerInstanceService=n,this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,n){let t=this._matrixMap.get(e);t||(t=new Map,this._matrixMap.set(e,t));let r=t.get(n);return r||(r=new o.ObjectMatrix,t.set(n,r)),r}_ensureCommentLocationMap(e,n){let t=this._locationMap.get(e);t||(t=new Map,this._locationMap.set(e,t));let r=t.get(n);return r||(r=new Map,t.set(n,r)),r}_addCommentToMatrix(e,n,t,r){var a;const s=(a=e.getValue(n,t))!=null?a:new Set;s.add(r),e.setValue(n,t,s)}_deleteCommentFromMatrix(e,n,t,r){if(n>=0&&t>=0){const s=e.getValue(n,t);s&&s.has(r)&&(s.delete(r),s.size===0&&e.realDeleteValue(n,t))}}_ensure(e,n){const t=this._ensureCommentMatrix(e,n),r=this._ensureCommentLocationMap(e,n);return{matrix:t,locationMap:r}}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:s,root:a}=t;this._addComment(r,s,a)}}_addComment(e,n,t){const r=l.singleReferenceToGrid(t.ref),s=t.parentId,{row:a,column:i}=r,c=t.id,{matrix:_,locationMap:u}=this._ensure(e,n);!s&&a>=0&&i>=0&&(this._addCommentToMatrix(_,a,i,c),u.set(c,{row:a,column:i})),s||this._commentUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add",isRoot:!s,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;try{if(this._univerInstanceService.getUnitType(n)!==o.UniverInstanceType.UNIVER_SHEET)return}catch{}const{matrix:r,locationMap:s}=this._ensure(n,t);switch(e.type){case"add":{this._addComment(e.unitId,e.subUnitId,e.payload);break}case"delete":{const{isRoot:a,comment:i}=e.payload;if(a){const c=l.singleReferenceToGrid(i.ref),{row:_,column:u}=c;this._deleteCommentFromMatrix(r,_,u,i.id),this._commentUpdate$.next({...e,...c})}break}case"update":{const{commentId:a}=e.payload,i=this._threadCommentModel.getComment(n,t,a);if(!i)return;const c=l.singleReferenceToGrid(i.ref);this._commentUpdate$.next({...e,...c});break}case"updateRef":{const a=l.singleReferenceToGrid(e.payload.ref),{commentId:i}=e.payload,c=s.get(i);if(!c)return;const{row:_,column:u}=c;this._deleteCommentFromMatrix(r,_,u,i),s.delete(i),a.row>=0&&a.column>=0&&(this._addCommentToMatrix(r,a.row,a.column,i),s.set(i,{row:a.row,column:a.column})),this._commentUpdate$.next({...e,...a});break}case"resolve":{const{unitId:a,subUnitId:i,payload:c}=e,{locationMap:_}=this._ensure(a,i),u=_.get(c.commentId);u&&this._commentUpdate$.next({...e,...u});break}}}))}getByLocation(e,n,t,r){var i;return(i=this.getAllByLocation(e,n,t,r).filter(c=>!c.resolved)[0])==null?void 0:i.id}getAllByLocation(e,n,t,r){const a=this._ensureCommentMatrix(e,n).getValue(t,r);return a?Array.from(a).map(i=>this.getComment(e,n,i)).filter(Boolean):[]}getComment(e,n,t){return this._threadCommentModel.getComment(e,n,t)}getCommentWithChildren(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return;const a=this.getComment(e,n,s);if(a)return this._threadCommentModel.getThread(e,n,a.threadId)}showCommentMarker(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return!1;const a=this.getComment(e,n,s);return!!(a&&!a.resolved)}getSubUnitAll(e,n){return this._threadCommentModel.getUnit(e).filter(t=>t.subUnitId===n).map(t=>t.root)}},d.SheetsThreadCommentModel=T([M(0,o.Inject(g.ThreadCommentModel)),M(1,o.IUniverInstanceService)],d.SheetsThreadCommentModel);var y=Object.getOwnPropertyDescriptor,U=(h,m,e,n)=>{for(var t=n>1?void 0:n?y(m,e):m,r=h.length-1,s;r>=0;r--)(s=h[r])&&(t=s(t)||t);return t},C=(h,m)=>(e,n)=>m(e,n,h);d.SheetsThreadCommentRefRangeController=class extends o.Disposable{constructor(e,n,t,r,s){super();f(this,"_disposableMap",new Map);f(this,"_watcherMap",new Map);f(this,"_handleRangeChange",(e,n,t,r,s)=>{const a=t.id,i={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};return r?{redos:[{id:g.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:l.serializeRange(r),commentId:a},silent:s}}],undos:[{id:g.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:l.serializeRange(i),commentId:a},silent:s}}]}:{redos:[{id:g.DeleteCommentMutation.id,params:{unitId:e,subUnitId:n,commentId:a}}],undos:[{id:g.AddCommentMutation.id,params:{unitId:e,subUnitId:n,comment:t,sync:!0}}]}});this._refRangeService=e,this._sheetsThreadCommentModel=n,this._threadCommentModel=t,this._selectionManagerService=r,this._commandService=s,this._initData(),this._initRefRange()}_getIdWithUnitId(e,n,t){return`${e}-${n}-${t}`}_register(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._disposableMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.registerRefRange(s,a=>{const i=p.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,a,{selectionManagerService:this._selectionManagerService}),c=Array.isArray(i)?i[0]:i;return c&&c.startColumn===s.startColumn&&c.startRow===s.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,n,t,c,!1)},e,n))}_watch(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._watcherMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.watchRange(e,n,s,(a,i)=>{const{redos:c}=this._handleRangeChange(e,n,t,i,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._watcherMap.get(r))==null||s.dispose(),this._watcherMap.delete(r)}_unregister(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._disposableMap.get(r))==null||s.dispose(),this._disposableMap.delete(r)}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:s,root:a}=t,i=l.singleReferenceToGrid(a.ref),c={...a,...i};this._register(r,s,c),this._watch(r,s,c)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;switch(e.type){case"add":{if(e.payload.parentId)return;const r={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,r),this._watch(e.unitId,e.subUnitId,r);break}case"delete":{this._unregister(n,t,e.payload.commentId),this._unwatch(n,t,e.payload.commentId);break}case"updateRef":{const r=this._sheetsThreadCommentModel.getComment(n,t,e.payload.commentId);if(!r)return;this._unregister(n,t,e.payload.commentId);const s={...r,row:e.row,column:e.column};e.silent||(this._unwatch(n,t,e.payload.commentId),this._watch(n,t,s)),this._register(e.unitId,e.subUnitId,s);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}},d.SheetsThreadCommentRefRangeController=U([C(0,o.Inject(p.RefRangeService)),C(1,o.Inject(d.SheetsThreadCommentModel)),C(2,o.Inject(g.ThreadCommentModel)),C(3,o.Inject(p.SheetsSelectionsService)),C(4,o.ICommandService)],d.SheetsThreadCommentRefRangeController);const I={},b="SHEET_THREAD_COMMENT_BASE_PLUGIN";var j=Object.defineProperty,P=Object.getOwnPropertyDescriptor,E=(h,m,e)=>m in h?j(h,m,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[m]=e,$=(h,m,e,n)=>{for(var t=n>1?void 0:n?P(m,e):m,r=h.length-1,s;r>=0;r--)(s=h[r])&&(t=s(t)||t);return t},v=(h,m)=>(e,n)=>m(e,n,h),R=(h,m,e)=>E(h,typeof m!="symbol"?m+"":m,e);d.UniverSheetsThreadCommentPlugin=class extends o.Plugin{constructor(m=I,e,n){super(),this._config=m,this._injector=e,this._commandService=n}onStarting(){[[d.SheetsThreadCommentModel],[d.SheetsThreadCommentRefRangeController]].forEach(m=>{this._injector.add(m)}),this._injector.get(d.SheetsThreadCommentRefRangeController)}},R(d.UniverSheetsThreadCommentPlugin,"pluginName",b),R(d.UniverSheetsThreadCommentPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),d.UniverSheetsThreadCommentPlugin=$([o.DependentOn(g.UniverThreadCommentPlugin),v(1,o.Inject(o.Injector)),v(2,o.Inject(o.ICommandService))],d.UniverSheetsThreadCommentPlugin),Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
|
|
76
|
+
(function(m,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/core"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/thread-comment"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-formula","@univerjs/sheets","@univerjs/thread-comment","rxjs"],i):(m=typeof globalThis<"u"?globalThis:m||self,i(m.UniverSheetsThreadComment={},m.UniverCore,m.UniverEngineFormula,m.UniverSheets,m.UniverThreadComment,m.rxjs))})(this,(function(m,i,p,C,_,y){"use strict";var L=Object.defineProperty;var N=(m,i,p)=>i in m?L(m,i,{enumerable:!0,configurable:!0,writable:!0,value:p}):m[i]=p;var f=(m,i,p)=>N(m,typeof i!="symbol"?i+"":i,p);var w=Object.getOwnPropertyDescriptor,U=(c,o,e,n)=>{for(var t=n>1?void 0:n?w(o,e):o,r=c.length-1,s;r>=0;r--)(s=c[r])&&(t=s(t)||t);return t},S=(c,o)=>(e,n)=>o(e,n,c);m.SheetsThreadCommentModel=class extends i.Disposable{constructor(e,n){super();f(this,"_matrixMap",new Map);f(this,"_locationMap",new Map);f(this,"_commentUpdate$",new y.Subject);f(this,"commentUpdate$",this._commentUpdate$.asObservable());this._threadCommentModel=e,this._univerInstanceService=n,this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,n){let t=this._matrixMap.get(e);t||(t=new Map,this._matrixMap.set(e,t));let r=t.get(n);return r||(r=new i.ObjectMatrix,t.set(n,r)),r}_ensureCommentLocationMap(e,n){let t=this._locationMap.get(e);t||(t=new Map,this._locationMap.set(e,t));let r=t.get(n);return r||(r=new Map,t.set(n,r)),r}_addCommentToMatrix(e,n,t,r){var a;const s=(a=e.getValue(n,t))!=null?a:new Set;s.add(r),e.setValue(n,t,s)}_deleteCommentFromMatrix(e,n,t,r){if(n>=0&&t>=0){const s=e.getValue(n,t);s&&s.has(r)&&(s.delete(r),s.size===0&&e.realDeleteValue(n,t))}}_ensure(e,n){const t=this._ensureCommentMatrix(e,n),r=this._ensureCommentLocationMap(e,n);return{matrix:t,locationMap:r}}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:s,root:a}=t;this._addComment(r,s,a)}}_addComment(e,n,t){const r=p.singleReferenceToGrid(t.ref),s=t.parentId,{row:a,column:d}=r,h=t.id,{matrix:u,locationMap:l}=this._ensure(e,n);!s&&a>=0&&d>=0&&(this._addCommentToMatrix(u,a,d,h),l.set(h,{row:a,column:d})),s||this._commentUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add",isRoot:!s,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;try{if(this._univerInstanceService.getUnitType(n)!==i.UniverInstanceType.UNIVER_SHEET)return}catch{}const{matrix:r,locationMap:s}=this._ensure(n,t);switch(e.type){case"add":{this._addComment(e.unitId,e.subUnitId,e.payload);break}case"delete":{const{isRoot:a,comment:d}=e.payload;if(a){const h=p.singleReferenceToGrid(d.ref),{row:u,column:l}=h;this._deleteCommentFromMatrix(r,u,l,d.id),this._commentUpdate$.next({...e,...h})}break}case"update":{const{commentId:a}=e.payload,d=this._threadCommentModel.getComment(n,t,a);if(!d)return;const h=p.singleReferenceToGrid(d.ref);this._commentUpdate$.next({...e,...h});break}case"updateRef":{const a=p.singleReferenceToGrid(e.payload.ref),{commentId:d}=e.payload,h=s.get(d);if(!h)return;const{row:u,column:l}=h;this._deleteCommentFromMatrix(r,u,l,d),s.delete(d),a.row>=0&&a.column>=0&&(this._addCommentToMatrix(r,a.row,a.column,d),s.set(d,{row:a.row,column:a.column})),this._commentUpdate$.next({...e,...a});break}case"resolve":{const{unitId:a,subUnitId:d,payload:h}=e,{locationMap:u}=this._ensure(a,d),l=u.get(h.commentId);l&&this._commentUpdate$.next({...e,...l});break}}}))}getByLocation(e,n,t,r){var d;return(d=this.getAllByLocation(e,n,t,r).filter(h=>!h.resolved)[0])==null?void 0:d.id}getAllByLocation(e,n,t,r){const a=this._ensureCommentMatrix(e,n).getValue(t,r);return a?Array.from(a).map(d=>this.getComment(e,n,d)).filter(Boolean):[]}getComment(e,n,t){return this._threadCommentModel.getComment(e,n,t)}getCommentWithChildren(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return;const a=this.getComment(e,n,s);if(a)return this._threadCommentModel.getThread(e,n,a.threadId)}showCommentMarker(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return!1;const a=this.getComment(e,n,s);return!!(a&&!a.resolved)}getSubUnitAll(e,n){return this._threadCommentModel.getUnit(e).filter(t=>t.subUnitId===n).map(t=>t.root)}},m.SheetsThreadCommentModel=U([S(0,i.Inject(_.ThreadCommentModel)),S(1,i.IUniverInstanceService)],m.SheetsThreadCommentModel);var b=Object.getOwnPropertyDescriptor,j=(c,o,e,n)=>{for(var t=n>1?void 0:n?b(o,e):o,r=c.length-1,s;r>=0;r--)(s=c[r])&&(t=s(t)||t);return t},g=(c,o)=>(e,n)=>o(e,n,c);m.SheetsThreadCommentRefRangeController=class extends i.Disposable{constructor(e,n,t,r,s){super();f(this,"_disposableMap",new Map);f(this,"_watcherMap",new Map);f(this,"_handleRangeChange",(e,n,t,r,s)=>{const a=t.id,d={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};return r?{redos:[{id:_.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:p.serializeRange(r),commentId:a},silent:s}}],undos:[{id:_.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:p.serializeRange(d),commentId:a},silent:s}}]}:{redos:[{id:_.DeleteCommentMutation.id,params:{unitId:e,subUnitId:n,commentId:a}}],undos:[{id:_.AddCommentMutation.id,params:{unitId:e,subUnitId:n,comment:t,sync:!0}}]}});this._refRangeService=e,this._sheetsThreadCommentModel=n,this._threadCommentModel=t,this._selectionManagerService=r,this._commandService=s,this._initData(),this._initRefRange()}_getIdWithUnitId(e,n,t){return`${e}-${n}-${t}`}_register(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._disposableMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.registerRefRange(s,a=>{const d=C.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,a,{selectionManagerService:this._selectionManagerService}),h=Array.isArray(d)?d[0]:d;return h&&h.startColumn===s.startColumn&&h.startRow===s.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,n,t,h,!1)},e,n))}_watch(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._watcherMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.watchRange(e,n,s,(a,d)=>{const{redos:h}=this._handleRangeChange(e,n,t,d,!0);i.sequenceExecuteAsync(h,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._watcherMap.get(r))==null||s.dispose(),this._watcherMap.delete(r)}_unregister(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._disposableMap.get(r))==null||s.dispose(),this._disposableMap.delete(r)}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:s,root:a}=t,d=p.singleReferenceToGrid(a.ref),h={...a,...d};this._register(r,s,h),this._watch(r,s,h)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;switch(e.type){case"add":{if(e.payload.parentId)return;const r={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,r),this._watch(e.unitId,e.subUnitId,r);break}case"delete":{this._unregister(n,t,e.payload.commentId),this._unwatch(n,t,e.payload.commentId);break}case"updateRef":{const r=this._sheetsThreadCommentModel.getComment(n,t,e.payload.commentId);if(!r)return;this._unregister(n,t,e.payload.commentId);const s={...r,row:e.row,column:e.column};e.silent||(this._unwatch(n,t,e.payload.commentId),this._watch(n,t,s)),this._register(e.unitId,e.subUnitId,s);break}}})),this.disposeWithMe(i.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}},m.SheetsThreadCommentRefRangeController=j([g(0,i.Inject(C.RefRangeService)),g(1,i.Inject(m.SheetsThreadCommentModel)),g(2,i.Inject(_.ThreadCommentModel)),g(3,i.Inject(C.SheetsSelectionsService)),g(4,i.ICommandService)],m.SheetsThreadCommentRefRangeController);const E={};var D=Object.getOwnPropertyDescriptor,P=(c,o,e,n)=>{for(var t=n>1?void 0:n?D(o,e):o,r=c.length-1,s;r>=0;r--)(s=c[r])&&(t=s(t)||t);return t},v=(c,o)=>(e,n)=>o(e,n,c);let M=class extends i.Disposable{constructor(c,o,e,n){super(),this._univerInstanceService=c,this._sheetInterceptorService=o,this._threadCommentModel=e,this._threadCommentDataSourceService=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:c=>{var o;if(c.id===C.RemoveSheetCommand.id){const e=c.params,n=e.unitId||this._univerInstanceService.getCurrentUnitOfType(i.UniverInstanceType.UNIVER_SHEET).getUnitId(),t=e.subUnitId||((o=this._univerInstanceService.getCurrentUnitOfType(i.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:o.getSheetId());if(!n||!t)return{redos:[],undos:[]};const r=this._threadCommentModel.ensureMap(n,t),s=Array.from(r.values()).filter(u=>!u.parentId),a=this._threadCommentDataSourceService.syncUpdateMutationToColla,d=[],h=[];return s.forEach(({children:u,...l})=>{d.push({id:_.DeleteCommentMutation.id,params:{unitId:n,subUnitId:t,commentId:l.id}}),h.push({id:_.AddCommentMutation.id,params:{unitId:n,subUnitId:t,comment:{...l,children:a?u:void 0},sync:!a}})}),{redos:d,undos:h}}else if(c.id===C.CopySheetCommand.id){const e=c.params,{unitId:n,subUnitId:t,targetSubUnitId:r}=e;if(!n||!t||!r)return{redos:[],undos:[]};const s=this._threadCommentModel.ensureMap(n,t),a=Array.from(s.values()).map(l=>({...l,subUnitId:r,id:i.generateRandomId(),threadId:i.generateRandomId()})).filter(l=>!l.parentId),d=this._threadCommentDataSourceService.syncUpdateMutationToColla,h=[],u=[];return a.forEach(({children:l,...T})=>{h.push({id:_.AddCommentMutation.id,params:{unitId:n,subUnitId:r,comment:{...T,children:d?l:void 0},sync:!d}}),u.push({id:_.DeleteCommentMutation.id,params:{unitId:n,subUnitId:r,commentId:T.id}})}),{redos:h,undos:u}}return{redos:[],undos:[]}}}))}};M=P([v(0,i.IUniverInstanceService),v(1,i.Inject(C.SheetInterceptorService)),v(2,i.Inject(_.ThreadCommentModel)),v(3,_.IThreadCommentDataSourceService)],M);const $="SHEET_THREAD_COMMENT_BASE_PLUGIN";var O=Object.defineProperty,A=Object.getOwnPropertyDescriptor,x=(c,o,e)=>o in c?O(c,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[o]=e,W=(c,o,e,n)=>{for(var t=n>1?void 0:n?A(o,e):o,r=c.length-1,s;r>=0;r--)(s=c[r])&&(t=s(t)||t);return t},I=(c,o)=>(e,n)=>o(e,n,c),R=(c,o,e)=>x(c,typeof o!="symbol"?o+"":o,e);m.UniverSheetsThreadCommentPlugin=class extends i.Plugin{constructor(o=E,e,n){super(),this._config=o,this._injector=e,this._commandService=n}onStarting(){[[m.SheetsThreadCommentModel],[m.SheetsThreadCommentRefRangeController],[M]].forEach(o=>{this._injector.add(o)}),i.touchDependencies(this._injector,[[m.SheetsThreadCommentRefRangeController],[M]])}},R(m.UniverSheetsThreadCommentPlugin,"pluginName",$),R(m.UniverSheetsThreadCommentPlugin,"type",i.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsThreadCommentPlugin=W([i.DependentOn(_.UniverThreadCommentPlugin),I(1,i.Inject(i.Injector)),I(2,i.Inject(i.ICommandService))],m.UniverSheetsThreadCommentPlugin),Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
// @univerjs/sheets-thread-comment/facade
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/preset-sheets-node-core",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -61,26 +61,26 @@
|
|
|
61
61
|
"rxjs": ">=7.0.0"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@univerjs/docs": "0.10.
|
|
65
|
-
"@univerjs/engine-formula": "0.10.
|
|
66
|
-
"@univerjs/engine-render": "0.10.
|
|
67
|
-
"@univerjs/rpc-node": "0.10.
|
|
68
|
-
"@univerjs/sheets": "0.10.
|
|
69
|
-
"@univerjs/sheets-data-validation": "0.10.
|
|
70
|
-
"@univerjs/sheets-drawing": "0.10.
|
|
71
|
-
"@univerjs/sheets-filter": "0.10.
|
|
72
|
-
"@univerjs/sheets-formula": "0.10.
|
|
73
|
-
"@univerjs/sheets-hyper-link": "0.10.
|
|
74
|
-
"@univerjs/sheets-numfmt": "0.10.
|
|
75
|
-
"@univerjs/sheets-sort": "0.10.
|
|
76
|
-
"@univerjs/sheets-thread-comment": "0.10.
|
|
77
|
-
"@univerjs/thread-comment": "0.10.
|
|
64
|
+
"@univerjs/docs": "0.10.13",
|
|
65
|
+
"@univerjs/engine-formula": "0.10.13",
|
|
66
|
+
"@univerjs/engine-render": "0.10.13",
|
|
67
|
+
"@univerjs/rpc-node": "0.10.13",
|
|
68
|
+
"@univerjs/sheets": "0.10.13",
|
|
69
|
+
"@univerjs/sheets-data-validation": "0.10.13",
|
|
70
|
+
"@univerjs/sheets-drawing": "0.10.13",
|
|
71
|
+
"@univerjs/sheets-filter": "0.10.13",
|
|
72
|
+
"@univerjs/sheets-formula": "0.10.13",
|
|
73
|
+
"@univerjs/sheets-hyper-link": "0.10.13",
|
|
74
|
+
"@univerjs/sheets-numfmt": "0.10.13",
|
|
75
|
+
"@univerjs/sheets-sort": "0.10.13",
|
|
76
|
+
"@univerjs/sheets-thread-comment": "0.10.13",
|
|
77
|
+
"@univerjs/thread-comment": "0.10.13"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@univerjs/core": "0.10.
|
|
80
|
+
"@univerjs/core": "0.10.13",
|
|
81
81
|
"rxjs": "7.8.2",
|
|
82
82
|
"typescript": "^5.9.3",
|
|
83
|
-
"@univerjs-infra/shared": "0.10.
|
|
83
|
+
"@univerjs-infra/shared": "0.10.13"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"prebuild:preset": "tsx prepare.ts",
|