@univerjs/sheets-data-validation 0.5.3-nightly.202501061606 → 0.5.3-nightly.202501071618
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +1 -1
- package/lib/es/facade.js +247 -83
- package/lib/types/facade/f-event.d.ts +269 -0
- package/lib/types/facade/f-univer.d.ts +4 -1
- package/lib/types/facade/f-worksheet.d.ts +22 -0
- package/lib/types/facade/index.d.ts +2 -0
- package/lib/umd/facade.js +1 -1
- package/package.json +6 -6
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var p=(n,t,e)=>t in n?m(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var d=(n,t,e)=>p(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/sheets-data-validation"),s=require("@univerjs/sheets/facade"),a=require("@univerjs/core"),h=require("@univerjs/data-validation"),c=require("@univerjs/engine-formula"),_=require("rxjs");class l{constructor(t){d(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new u(this._rule)}copy(){return new l({...this._rule,uid:a.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(t,e){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=t,this._rule.formula2=void 0,this}requireNumberBetween(t,e,i){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=i?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,i){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=i?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(t,e,i){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=t.join(","),this._rule.formula2=void 0,this._rule.showDropDown=i!=null?i:!0,this}requireValueInRange(t,e,i){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${c.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=i!=null?i:!0,this}setAllowInvalid(t){return this._rule.errorStyle=t?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setHelpText(t){return this._rule.error=t,this._rule.showErrorMessage=!0,this}withCriteriaValues(t,e){return this._rule.type=t,this._rule.operator=e[0],this._rule.formula1=e[1],this._rule.formula2=e[2],this}setAllowBlank(t){return this._rule.allowBlank=t,this}setOptions(t){return Object.assign(this._rule,t),this}}class u{constructor(t,e,i){d(this,"rule");d(this,"_worksheet");d(this,"_injector");this._injector=i,this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new l(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(h.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];const t=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(e=>this._injector.createInstance(s.FRange,t,this._worksheet,e))}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e,i=!0){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(o.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:e[0],formula1:e[1],formula2:e[2],type:this.rule.type,allowBlank:i}}))throw new Error("setCriteria failed");return this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,this.rule.allowBlank=i,this}setOptions(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(o.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...h.getRuleOptions(this.rule),...t}}))throw new Error("setOptions failed");return Object.assign(this.rule,t),this}setRanges(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(o.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(r=>r.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=t.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(a.ICommandService).syncExecuteCommand(o.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class g extends s.FRange{setDataValidation(t){if(!t)return this._commandService.syncExecuteCommand(o.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...t.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(o.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(o.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new u(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(o.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new u(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(o.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}s.FRange.extend(g);class D{static newDataValidation(){return new l}newDataValidation(){return new l}}a.FUniver.extend(D);class V extends s.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(o.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(o.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(_.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(_.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const r=e.params;if(e.id===o.AddSheetDataValidationCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,i)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const r=e.params;if(e.id===o.UpdateSheetDataValidationSettingCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,i)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const r=e.params;if(e.id===o.UpdateSheetDataValidationRangeCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,i)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const r=e.params;if(e.id===o.UpdateSheetDataValidationOptionsCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,i)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const r=e.params;if(e.id===o.RemoveSheetDataValidationCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,i)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const r=e.params;if(e.id===o.RemoveSheetAllDataValidationCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,i)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}s.FWorkbook.extend(V);class f extends s.FWorksheet{getDataValidations(){return this._injector.get(h.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new u(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(o.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}}s.FWorksheet.extend(f);exports.FDataValidation=u;exports.FDataValidationBuilder=l;
|
|
1
|
+
"use strict";var k=Object.defineProperty;var w=(c,t,e)=>t in c?k(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e;var _=(c,t,e)=>w(c,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@univerjs/sheets-data-validation"),g=require("@univerjs/sheets/facade"),a=require("@univerjs/core"),f=require("@univerjs/data-validation"),v=require("@univerjs/engine-formula"),E=require("rxjs");class m{constructor(t){_(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new p(this._rule)}copy(){return new m({...this._rule,uid:a.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(t,e){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=t,this._rule.formula2=void 0,this}requireNumberBetween(t,e,i){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=i?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,i){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=i?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(t,e,i){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=t.join(","),this._rule.formula2=void 0,this._rule.showDropDown=i!=null?i:!0,this}requireValueInRange(t,e,i){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${v.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=i!=null?i:!0,this}setAllowInvalid(t){return this._rule.errorStyle=t?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setHelpText(t){return this._rule.error=t,this._rule.showErrorMessage=!0,this}withCriteriaValues(t,e){return this._rule.type=t,this._rule.operator=e[0],this._rule.formula1=e[1],this._rule.formula2=e[2],this}setAllowBlank(t){return this._rule.allowBlank=t,this}setOptions(t){return Object.assign(this._rule,t),this}}class p{constructor(t,e,i){_(this,"rule");_(this,"_worksheet");_(this,"_injector");this._injector=i,this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new m(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(f.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];const t=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(e=>this._injector.createInstance(g.FRange,t,this._worksheet,e))}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e,i=!0){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:e[0],formula1:e[1],formula2:e[2],type:this.rule.type,allowBlank:i}}))throw new Error("setCriteria failed");return this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,this.rule.allowBlank=i,this}setOptions(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...f.getRuleOptions(this.rule),...t}}))throw new Error("setOptions failed");return Object.assign(this.rule,t),this}setRanges(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(o=>o.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=t.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(a.ICommandService).syncExecuteCommand(n.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class b extends g.FRange{setDataValidation(t){if(!t)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...t.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(n.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new p(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new p(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}g.FRange.extend(b);class T extends a.FUniver{static newDataValidation(){return new m}newDataValidation(){return new m}_initialize(t){if(!t.has(n.SheetDataValidationModel))return;const e=t.get(n.SheetDataValidationModel),i=t.get(a.ICommandService);this.disposeWithMe(e.ruleChange$.subscribe(o=>{const{unitId:r,subUnitId:s,rule:h,oldRule:d,type:l}=o,u=this.getSheetTarget(r,s);if(!u)return;const{workbook:D,worksheet:V}=u,S=new p(h,V.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:o,worksheet:V,workbook:D,changeType:l,oldRule:d,rule:S})})),this.disposeWithMe(e.validStatusChange$.subscribe(o=>{const{unitId:r,subUnitId:s,ruleId:h,status:d,row:l,col:u}=o,D=this.getSheetTarget(r,s);if(!D)return;const{workbook:V,worksheet:S}=D,I=S.getDataValidation(h);I&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:V,worksheet:S,row:l,column:u,rule:I,status:d})})),this.disposeWithMe(i.beforeCommandExecuted(o=>{switch(o.id){case n.AddSheetDataValidationCommand.id:{const r=o.params,s=this.getSheetTarget(r.unitId,r.subUnitId);if(!s)return;const{workbook:h,worksheet:d}=s,l={worksheet:d,workbook:h,rule:r.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,l),l.cancel)throw new a.CanceledError;break}case n.UpdateSheetDataValidationSettingCommand.id:{const r=o.params,s=this.getSheetTarget(r.unitId,r.subUnitId);if(!s)return;const{workbook:h,worksheet:d}=s,l=d.getDataValidation(r.ruleId);if(!l)return;const u={worksheet:d,workbook:h,rule:l,ruleId:r.ruleId,newCriteria:r.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,u),u.cancel)throw new a.CanceledError;break}case n.UpdateSheetDataValidationRangeCommand.id:{const r=o.params,s=this.getSheetTarget(r.unitId,r.subUnitId);if(!s)return;const{workbook:h,worksheet:d}=s,l=d.getDataValidation(r.ruleId);if(!l)return;const u={worksheet:d,workbook:h,rule:l,ruleId:r.ruleId,newRanges:r.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,u),u.cancel)throw new a.CanceledError;break}case n.UpdateSheetDataValidationOptionsCommand.id:{const r=o.params,s=this.getSheetTarget(r.unitId,r.subUnitId);if(!s)return;const{workbook:h,worksheet:d}=s,l=d.getDataValidation(r.ruleId);if(!l)return;const u={worksheet:d,workbook:h,rule:l,ruleId:r.ruleId,newOptions:r.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,u),u.cancel)throw new a.CanceledError;break}case n.RemoveSheetDataValidationCommand.id:{const r=o.params,s=this.getSheetTarget(r.unitId,r.subUnitId);if(!s)return;const{workbook:h,worksheet:d}=s,l=d.getDataValidation(r.ruleId);if(!l)return;const u={worksheet:d,workbook:h,rule:l,ruleId:r.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,u),u.cancel)throw new a.CanceledError;break}case n.RemoveSheetAllDataValidationCommand.id:{const r=o.params,s=this.getSheetTarget(r.unitId,r.subUnitId);if(!s)return;const{workbook:h,worksheet:d}=s,l={worksheet:d,workbook:h,rules:d.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,l),l.cancel)throw new a.CanceledError;break}}}))}}a.FUniver.extend(T);class y extends g.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(E.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(E.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const o=e.params;if(e.id===n.AddSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,i)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const o=e.params;if(e.id===n.UpdateSheetDataValidationSettingCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,i)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const o=e.params;if(e.id===n.UpdateSheetDataValidationRangeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,i)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const o=e.params;if(e.id===n.UpdateSheetDataValidationOptionsCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,i)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const o=e.params;if(e.id===n.RemoveSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,i)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,i)=>{const o=e.params;if(e.id===n.RemoveSheetAllDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,i)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}g.FWorkbook.extend(y);class C extends g.FWorksheet{getDataValidations(){return this._injector.get(f.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new p(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getDataValidation(t){const i=this._injector.get(f.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);return i?new p(i,this._worksheet,this._injector):null}}g.FWorksheet.extend(C);class U{get SheetDataValidationChanged(){return"SheetDataValidationChanged"}get SheetDataValidatorStatusChanged(){return"SheetDataValidatorStatusChanged"}get BeforeSheetDataValidationAdd(){return"BeforeSheetDataValidationAdd"}get BeforeSheetDataValidationDelete(){return"BeforeSheetDataValidationDelete"}get BeforeSheetDataValidationDeleteAll(){return"BeforeSheetDataValidationDeleteAll"}get BeforeSheetDataValidationCriteriaUpdate(){return"BeforeSheetDataValidationCriteriaUpdate"}get BeforeSheetDataValidationRangeUpdate(){return"BeforeSheetDataValidationRangeUpdate"}get BeforeSheetDataValidationOptionsUpdate(){return"BeforeSheetDataValidationOptionsUpdate"}}a.FEventName.extend(U);exports.FDataValidation=p;exports.FDataValidationBuilder=m;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { UpdateSheetDataValidationSettingCommand as
|
|
5
|
-
import { FRange as
|
|
6
|
-
import { generateRandomId as
|
|
7
|
-
import { DataValidationModel as
|
|
8
|
-
import { serializeRangeToRefString as
|
|
9
|
-
import { filter as
|
|
10
|
-
class
|
|
1
|
+
var j = Object.defineProperty;
|
|
2
|
+
var q = (c, e, t) => e in c ? j(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
|
|
3
|
+
var f = (c, e, t) => q(c, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { UpdateSheetDataValidationSettingCommand as v, UpdateSheetDataValidationOptionsCommand as U, UpdateSheetDataValidationRangeCommand as C, RemoveSheetDataValidationCommand as T, ClearRangeDataValidationCommand as W, AddSheetDataValidationCommand as A, SheetsDataValidationValidatorService as S, SheetDataValidationModel as V, RemoveSheetAllDataValidationCommand as O } from "@univerjs/sheets-data-validation";
|
|
5
|
+
import { FRange as y, FWorkbook as M, FWorksheet as x } from "@univerjs/sheets/facade";
|
|
6
|
+
import { generateRandomId as B, DataValidationType as o, DataValidationErrorStyle as w, DataValidationOperator as d, IUniverInstanceService as H, ICommandService as p, FUniver as N, CanceledError as _, toDisposable as g, FEventName as $ } from "@univerjs/core";
|
|
7
|
+
import { DataValidationModel as b, getRuleOptions as F } from "@univerjs/data-validation";
|
|
8
|
+
import { serializeRangeToRefString as P } from "@univerjs/engine-formula";
|
|
9
|
+
import { filter as R } from "rxjs";
|
|
10
|
+
class D {
|
|
11
11
|
constructor(e) {
|
|
12
|
-
|
|
12
|
+
f(this, "_rule");
|
|
13
13
|
this._rule = e != null ? e : {
|
|
14
|
-
uid:
|
|
14
|
+
uid: B(),
|
|
15
15
|
ranges: void 0,
|
|
16
|
-
type:
|
|
16
|
+
type: o.CUSTOM
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -30,9 +30,9 @@ class h {
|
|
|
30
30
|
* @return {FDataValidationBuilder} A new instance of the DataValidationBuilder class
|
|
31
31
|
*/
|
|
32
32
|
copy() {
|
|
33
|
-
return new
|
|
33
|
+
return new D({
|
|
34
34
|
...this._rule,
|
|
35
|
-
uid:
|
|
35
|
+
uid: B()
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
@@ -41,7 +41,7 @@ class h {
|
|
|
41
41
|
* @returns {boolean} True if invalid data is allowed, False otherwise
|
|
42
42
|
*/
|
|
43
43
|
getAllowInvalid() {
|
|
44
|
-
return this._rule.errorStyle !==
|
|
44
|
+
return this._rule.errorStyle !== w.STOP;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Gets the data validation type of the rule
|
|
@@ -75,7 +75,7 @@ class h {
|
|
|
75
75
|
* @returns The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
76
76
|
*/
|
|
77
77
|
requireCheckbox(e, t) {
|
|
78
|
-
return this._rule.type =
|
|
78
|
+
return this._rule.type = o.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Set the data validation type to DATE and configure the validation rules to be after a specific date
|
|
@@ -84,7 +84,7 @@ class h {
|
|
|
84
84
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
85
85
|
*/
|
|
86
86
|
requireDateAfter(e) {
|
|
87
|
-
return this._rule.type =
|
|
87
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = d.GREATER_THAN, this;
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Set the data validation type to DATE and configure the validation rules to be before a specific date
|
|
@@ -93,7 +93,7 @@ class h {
|
|
|
93
93
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
94
94
|
*/
|
|
95
95
|
requireDateBefore(e) {
|
|
96
|
-
return this._rule.type =
|
|
96
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN, this;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* Set the data validation type to DATE and configure the validation rules to be within a specific date range
|
|
@@ -103,7 +103,7 @@ class h {
|
|
|
103
103
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
104
104
|
*/
|
|
105
105
|
requireDateBetween(e, t) {
|
|
106
|
-
return this._rule.type =
|
|
106
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = d.BETWEEN, this;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Set the data validation type to DATE and configure the validation rules to be equal to a specific date
|
|
@@ -112,7 +112,7 @@ class h {
|
|
|
112
112
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
113
113
|
*/
|
|
114
114
|
requireDateEqualTo(e) {
|
|
115
|
-
return this._rule.type =
|
|
115
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.EQUAL, this;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* Set the data validation type to DATE and configure the validation rules to be not within a specific date range
|
|
@@ -122,7 +122,7 @@ class h {
|
|
|
122
122
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
123
123
|
*/
|
|
124
124
|
requireDateNotBetween(e, t) {
|
|
125
|
-
return this._rule.type =
|
|
125
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = d.NOT_BETWEEN, this;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Set the data validation type to DATE and configure the validation rules to be on or after a specific date
|
|
@@ -131,7 +131,7 @@ class h {
|
|
|
131
131
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
132
132
|
*/
|
|
133
133
|
requireDateOnOrAfter(e) {
|
|
134
|
-
return this._rule.type =
|
|
134
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.GREATER_THAN_OR_EQUAL, this;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Set the data validation type to DATE and configure the validation rules to be on or before a specific date
|
|
@@ -140,7 +140,7 @@ class h {
|
|
|
140
140
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
141
141
|
*/
|
|
142
142
|
requireDateOnOrBefore(e) {
|
|
143
|
-
return this._rule.type =
|
|
143
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN_OR_EQUAL, this;
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
146
|
* Requires that a custom formula be satisfied.
|
|
@@ -150,7 +150,7 @@ class h {
|
|
|
150
150
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
151
151
|
*/
|
|
152
152
|
requireFormulaSatisfied(e) {
|
|
153
|
-
return this._rule.type =
|
|
153
|
+
return this._rule.type = o.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* Requires the user to enter a number within a specific range, which can be integer or decimal.
|
|
@@ -162,7 +162,7 @@ class h {
|
|
|
162
162
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
163
163
|
*/
|
|
164
164
|
requireNumberBetween(e, t, r) {
|
|
165
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator =
|
|
165
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = d.BETWEEN, this._rule.type = r ? o.WHOLE : o.DECIMAL, this;
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
168
|
* Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal.
|
|
@@ -173,7 +173,7 @@ class h {
|
|
|
173
173
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
174
174
|
*/
|
|
175
175
|
requireNumberEqualTo(e, t) {
|
|
176
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
176
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal.
|
|
@@ -184,7 +184,7 @@ class h {
|
|
|
184
184
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
185
185
|
*/
|
|
186
186
|
requireNumberGreaterThan(e, t) {
|
|
187
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
187
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.GREATER_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
190
|
* Requires the user to enter a number that is greater than or equal to a specific value, which can be an integer or a decimal.
|
|
@@ -195,7 +195,7 @@ class h {
|
|
|
195
195
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
196
196
|
*/
|
|
197
197
|
requireNumberGreaterThanOrEqualTo(e, t) {
|
|
198
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
198
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.GREATER_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
201
201
|
* Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal.
|
|
@@ -206,7 +206,7 @@ class h {
|
|
|
206
206
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
207
207
|
*/
|
|
208
208
|
requireNumberLessThan(e, t) {
|
|
209
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
209
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
210
210
|
}
|
|
211
211
|
/**
|
|
212
212
|
* Sets the data validation rule to require a number less than or equal to a specified value
|
|
@@ -217,7 +217,7 @@ class h {
|
|
|
217
217
|
* @return The current instance of the DataValidationBuilder class, allowing for method chaining
|
|
218
218
|
*/
|
|
219
219
|
requireNumberLessThanOrEqualTo(e, t) {
|
|
220
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
220
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.LESS_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
223
223
|
* Sets a data validation rule that requires the user to enter a number outside a specified range
|
|
@@ -229,7 +229,7 @@ class h {
|
|
|
229
229
|
* @return An instance of the FDataValidationBuilder class, allowing for method chaining
|
|
230
230
|
*/
|
|
231
231
|
requireNumberNotBetween(e, t, r) {
|
|
232
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator =
|
|
232
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = d.NOT_BETWEEN, this._rule.type = r ? o.WHOLE : o.DECIMAL, this;
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
235
235
|
* Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
|
|
@@ -240,7 +240,7 @@ class h {
|
|
|
240
240
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining
|
|
241
241
|
*/
|
|
242
242
|
requireNumberNotEqualTo(e, t) {
|
|
243
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator =
|
|
243
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = d.NOT_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
244
244
|
}
|
|
245
245
|
/**
|
|
246
246
|
* Sets a data validation rule that requires the user to enter a value from a list of specific values.
|
|
@@ -252,7 +252,7 @@ class h {
|
|
|
252
252
|
* @return An instance of the FDataValidationBuilder class, allowing for method chaining.
|
|
253
253
|
*/
|
|
254
254
|
requireValueInList(e, t, r) {
|
|
255
|
-
return this._rule.type = t ?
|
|
255
|
+
return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = e.join(","), this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : !0, this;
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
258
|
* Sets a data validation rule that requires the user to enter a value within a specific range.
|
|
@@ -264,7 +264,7 @@ class h {
|
|
|
264
264
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
265
265
|
*/
|
|
266
266
|
requireValueInRange(e, t, r) {
|
|
267
|
-
return this._rule.type = t ?
|
|
267
|
+
return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = `=${P({
|
|
268
268
|
unitId: e.getUnitId(),
|
|
269
269
|
sheetName: e.getSheetName(),
|
|
270
270
|
range: e.getRange()
|
|
@@ -279,7 +279,7 @@ class h {
|
|
|
279
279
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
280
280
|
*/
|
|
281
281
|
setAllowInvalid(e) {
|
|
282
|
-
return this._rule.errorStyle = e ?
|
|
282
|
+
return this._rule.errorStyle = e ? w.WARNING : w.STOP, this;
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
285
285
|
* Sets the help text and enables the display of error messages for data validation.
|
|
@@ -320,9 +320,9 @@ class h {
|
|
|
320
320
|
}
|
|
321
321
|
class m {
|
|
322
322
|
constructor(e, t, r) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
323
|
+
f(this, "rule");
|
|
324
|
+
f(this, "_worksheet");
|
|
325
|
+
f(this, "_injector");
|
|
326
326
|
this._injector = r, this.rule = e, this._worksheet = t;
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
@@ -331,7 +331,7 @@ class m {
|
|
|
331
331
|
* @return true if invalid data is allowed, false otherwise.
|
|
332
332
|
*/
|
|
333
333
|
getAllowInvalid() {
|
|
334
|
-
return this.rule.errorStyle !==
|
|
334
|
+
return this.rule.errorStyle !== w.STOP;
|
|
335
335
|
}
|
|
336
336
|
/**
|
|
337
337
|
* Gets the data validation type of the rule
|
|
@@ -364,7 +364,7 @@ class m {
|
|
|
364
364
|
* @return A new FDataValidationBuilder instance with the same rule configuration.
|
|
365
365
|
*/
|
|
366
366
|
copy() {
|
|
367
|
-
return new
|
|
367
|
+
return new D(this.rule);
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
370
|
* Gets whether the data validation rule is applied to the worksheet.
|
|
@@ -374,7 +374,7 @@ class m {
|
|
|
374
374
|
getApplied() {
|
|
375
375
|
if (!this._worksheet)
|
|
376
376
|
return !1;
|
|
377
|
-
const t = this._injector.get(
|
|
377
|
+
const t = this._injector.get(b).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
|
|
378
378
|
return !!(t && t.ranges.length);
|
|
379
379
|
}
|
|
380
380
|
/**
|
|
@@ -385,8 +385,8 @@ class m {
|
|
|
385
385
|
getRanges() {
|
|
386
386
|
if (!this.getApplied())
|
|
387
387
|
return [];
|
|
388
|
-
const e = this._injector.get(
|
|
389
|
-
return this.rule.ranges.map((t) => this._injector.createInstance(
|
|
388
|
+
const e = this._injector.get(H).getUnit(this._worksheet.getUnitId());
|
|
389
|
+
return this.rule.ranges.map((t) => this._injector.createInstance(y, e, this._worksheet, t));
|
|
390
390
|
}
|
|
391
391
|
/**
|
|
392
392
|
* Gets the title of the error message dialog box.
|
|
@@ -413,7 +413,7 @@ class m {
|
|
|
413
413
|
* @returns true if the criteria is set successfully, false otherwise.
|
|
414
414
|
*/
|
|
415
415
|
setCriteria(e, t, r = !0) {
|
|
416
|
-
if (this.getApplied() && !this._injector.get(
|
|
416
|
+
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(v.id, {
|
|
417
417
|
unitId: this.getUnitId(),
|
|
418
418
|
subUnitId: this.getSheetId(),
|
|
419
419
|
ruleId: this.rule.uid,
|
|
@@ -435,12 +435,12 @@ class m {
|
|
|
435
435
|
* @returns true if the options are set successfully, false otherwise.
|
|
436
436
|
*/
|
|
437
437
|
setOptions(e) {
|
|
438
|
-
if (this.getApplied() && !this._injector.get(
|
|
438
|
+
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(U.id, {
|
|
439
439
|
unitId: this.getUnitId(),
|
|
440
440
|
subUnitId: this.getSheetId(),
|
|
441
441
|
ruleId: this.rule.uid,
|
|
442
442
|
options: {
|
|
443
|
-
...
|
|
443
|
+
...F(this.rule),
|
|
444
444
|
...e
|
|
445
445
|
}
|
|
446
446
|
}))
|
|
@@ -453,7 +453,7 @@ class m {
|
|
|
453
453
|
* @returns true if the ranges are set successfully, false otherwise.
|
|
454
454
|
*/
|
|
455
455
|
setRanges(e) {
|
|
456
|
-
if (this.getApplied() && !this._injector.get(
|
|
456
|
+
if (this.getApplied() && !this._injector.get(p).syncExecuteCommand(C.id, {
|
|
457
457
|
unitId: this.getUnitId(),
|
|
458
458
|
subUnitId: this.getSheetId(),
|
|
459
459
|
ruleId: this.rule.uid,
|
|
@@ -467,17 +467,17 @@ class m {
|
|
|
467
467
|
* @returns true if the rule is deleted successfully, false otherwise.
|
|
468
468
|
*/
|
|
469
469
|
delete() {
|
|
470
|
-
return this.getApplied() ? this._injector.get(
|
|
470
|
+
return this.getApplied() ? this._injector.get(p).syncExecuteCommand(T.id, {
|
|
471
471
|
unitId: this.getUnitId(),
|
|
472
472
|
subUnitId: this.getSheetId(),
|
|
473
473
|
ruleId: this.rule.uid
|
|
474
474
|
}) : !1;
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
|
-
class
|
|
477
|
+
class G extends y {
|
|
478
478
|
setDataValidation(e) {
|
|
479
479
|
if (!e)
|
|
480
|
-
return this._commandService.syncExecuteCommand(
|
|
480
|
+
return this._commandService.syncExecuteCommand(W.id, {
|
|
481
481
|
unitId: this._workbook.getUnitId(),
|
|
482
482
|
subUnitId: this._worksheet.getSheetId(),
|
|
483
483
|
ranges: [this._range]
|
|
@@ -490,10 +490,10 @@ class R extends c {
|
|
|
490
490
|
ranges: [this._range]
|
|
491
491
|
}
|
|
492
492
|
};
|
|
493
|
-
return this._commandService.syncExecuteCommand(
|
|
493
|
+
return this._commandService.syncExecuteCommand(A.id, t), this;
|
|
494
494
|
}
|
|
495
495
|
getDataValidation() {
|
|
496
|
-
const t = this._injector.get(
|
|
496
|
+
const t = this._injector.get(S).getDataValidation(
|
|
497
497
|
this._workbook.getUnitId(),
|
|
498
498
|
this._worksheet.getSheetId(),
|
|
499
499
|
[this._range]
|
|
@@ -501,55 +501,188 @@ class R extends c {
|
|
|
501
501
|
return t && new m(t, this._worksheet, this._injector);
|
|
502
502
|
}
|
|
503
503
|
getDataValidations() {
|
|
504
|
-
return this._injector.get(
|
|
504
|
+
return this._injector.get(S).getDataValidations(
|
|
505
505
|
this._workbook.getUnitId(),
|
|
506
506
|
this._worksheet.getSheetId(),
|
|
507
507
|
[this._range]
|
|
508
508
|
).map((t) => new m(t, this._worksheet, this._injector));
|
|
509
509
|
}
|
|
510
510
|
async getValidatorStatus() {
|
|
511
|
-
return this._injector.get(
|
|
511
|
+
return this._injector.get(S).validatorRanges(
|
|
512
512
|
this._workbook.getUnitId(),
|
|
513
513
|
this._worksheet.getSheetId(),
|
|
514
514
|
[this._range]
|
|
515
515
|
);
|
|
516
516
|
}
|
|
517
517
|
}
|
|
518
|
-
|
|
519
|
-
class N {
|
|
518
|
+
y.extend(G);
|
|
519
|
+
class Q extends N {
|
|
520
|
+
/**
|
|
520
521
|
/**
|
|
521
522
|
* @deparecated use `univerAPI.newDataValidation()` as instead.
|
|
522
523
|
*/
|
|
523
524
|
static newDataValidation() {
|
|
524
|
-
return new
|
|
525
|
+
return new D();
|
|
525
526
|
}
|
|
526
527
|
newDataValidation() {
|
|
527
|
-
return new
|
|
528
|
+
return new D();
|
|
529
|
+
}
|
|
530
|
+
// eslint-disable-next-line max-lines-per-function
|
|
531
|
+
_initialize(e) {
|
|
532
|
+
if (!e.has(V)) return;
|
|
533
|
+
const t = e.get(V), r = e.get(p);
|
|
534
|
+
this.disposeWithMe(t.ruleChange$.subscribe((a) => {
|
|
535
|
+
const { unitId: i, subUnitId: s, rule: h, oldRule: l, type: n } = a, u = this.getSheetTarget(i, s);
|
|
536
|
+
if (!u)
|
|
537
|
+
return;
|
|
538
|
+
const { workbook: I, worksheet: k } = u, E = new m(h, k.getSheet(), this._injector);
|
|
539
|
+
this.fireEvent(this.Event.SheetDataValidationChanged, {
|
|
540
|
+
origin: a,
|
|
541
|
+
worksheet: k,
|
|
542
|
+
workbook: I,
|
|
543
|
+
changeType: n,
|
|
544
|
+
oldRule: l,
|
|
545
|
+
rule: E
|
|
546
|
+
});
|
|
547
|
+
})), this.disposeWithMe(t.validStatusChange$.subscribe((a) => {
|
|
548
|
+
const { unitId: i, subUnitId: s, ruleId: h, status: l, row: n, col: u } = a, I = this.getSheetTarget(i, s);
|
|
549
|
+
if (!I)
|
|
550
|
+
return;
|
|
551
|
+
const { workbook: k, worksheet: E } = I, L = E.getDataValidation(h);
|
|
552
|
+
L && this.fireEvent(this.Event.SheetDataValidatorStatusChanged, {
|
|
553
|
+
workbook: k,
|
|
554
|
+
worksheet: E,
|
|
555
|
+
row: n,
|
|
556
|
+
column: u,
|
|
557
|
+
rule: L,
|
|
558
|
+
status: l
|
|
559
|
+
});
|
|
560
|
+
})), this.disposeWithMe(r.beforeCommandExecuted((a) => {
|
|
561
|
+
switch (a.id) {
|
|
562
|
+
case A.id: {
|
|
563
|
+
const i = a.params, s = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
564
|
+
if (!s)
|
|
565
|
+
return;
|
|
566
|
+
const { workbook: h, worksheet: l } = s, n = {
|
|
567
|
+
worksheet: l,
|
|
568
|
+
workbook: h,
|
|
569
|
+
rule: i.rule
|
|
570
|
+
};
|
|
571
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationAdd, n), n.cancel)
|
|
572
|
+
throw new _();
|
|
573
|
+
break;
|
|
574
|
+
}
|
|
575
|
+
case v.id: {
|
|
576
|
+
const i = a.params, s = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
577
|
+
if (!s)
|
|
578
|
+
return;
|
|
579
|
+
const { workbook: h, worksheet: l } = s, n = l.getDataValidation(i.ruleId);
|
|
580
|
+
if (!n)
|
|
581
|
+
return;
|
|
582
|
+
const u = {
|
|
583
|
+
worksheet: l,
|
|
584
|
+
workbook: h,
|
|
585
|
+
rule: n,
|
|
586
|
+
ruleId: i.ruleId,
|
|
587
|
+
newCriteria: i.setting
|
|
588
|
+
};
|
|
589
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate, u), u.cancel)
|
|
590
|
+
throw new _();
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
case C.id: {
|
|
594
|
+
const i = a.params, s = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
595
|
+
if (!s)
|
|
596
|
+
return;
|
|
597
|
+
const { workbook: h, worksheet: l } = s, n = l.getDataValidation(i.ruleId);
|
|
598
|
+
if (!n)
|
|
599
|
+
return;
|
|
600
|
+
const u = {
|
|
601
|
+
worksheet: l,
|
|
602
|
+
workbook: h,
|
|
603
|
+
rule: n,
|
|
604
|
+
ruleId: i.ruleId,
|
|
605
|
+
newRanges: i.ranges
|
|
606
|
+
};
|
|
607
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate, u), u.cancel)
|
|
608
|
+
throw new _();
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
case U.id: {
|
|
612
|
+
const i = a.params, s = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
613
|
+
if (!s)
|
|
614
|
+
return;
|
|
615
|
+
const { workbook: h, worksheet: l } = s, n = l.getDataValidation(i.ruleId);
|
|
616
|
+
if (!n)
|
|
617
|
+
return;
|
|
618
|
+
const u = {
|
|
619
|
+
worksheet: l,
|
|
620
|
+
workbook: h,
|
|
621
|
+
rule: n,
|
|
622
|
+
ruleId: i.ruleId,
|
|
623
|
+
newOptions: i.options
|
|
624
|
+
};
|
|
625
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate, u), u.cancel)
|
|
626
|
+
throw new _();
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
case T.id: {
|
|
630
|
+
const i = a.params, s = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
631
|
+
if (!s)
|
|
632
|
+
return;
|
|
633
|
+
const { workbook: h, worksheet: l } = s, n = l.getDataValidation(i.ruleId);
|
|
634
|
+
if (!n)
|
|
635
|
+
return;
|
|
636
|
+
const u = {
|
|
637
|
+
worksheet: l,
|
|
638
|
+
workbook: h,
|
|
639
|
+
rule: n,
|
|
640
|
+
ruleId: i.ruleId
|
|
641
|
+
};
|
|
642
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationDelete, u), u.cancel)
|
|
643
|
+
throw new _();
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
case O.id: {
|
|
647
|
+
const i = a.params, s = this.getSheetTarget(i.unitId, i.subUnitId);
|
|
648
|
+
if (!s)
|
|
649
|
+
return;
|
|
650
|
+
const { workbook: h, worksheet: l } = s, n = {
|
|
651
|
+
worksheet: l,
|
|
652
|
+
workbook: h,
|
|
653
|
+
rules: l.getDataValidations()
|
|
654
|
+
};
|
|
655
|
+
if (this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll, n), n.cancel)
|
|
656
|
+
throw new _();
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}));
|
|
528
661
|
}
|
|
529
662
|
}
|
|
530
|
-
|
|
531
|
-
class
|
|
663
|
+
N.extend(Q);
|
|
664
|
+
class z extends M {
|
|
532
665
|
_initialize() {
|
|
533
666
|
Object.defineProperty(this, "_dataValidationModel", {
|
|
534
667
|
get() {
|
|
535
|
-
return this._injector.get(
|
|
668
|
+
return this._injector.get(V);
|
|
536
669
|
}
|
|
537
670
|
});
|
|
538
671
|
}
|
|
539
672
|
getValidatorStatus() {
|
|
540
|
-
return this._injector.get(
|
|
673
|
+
return this._injector.get(S).validatorWorkbook(this._workbook.getUnitId());
|
|
541
674
|
}
|
|
542
675
|
// region DataValidationHooks
|
|
543
676
|
onDataValidationChange(e) {
|
|
544
|
-
return
|
|
677
|
+
return g(this._dataValidationModel.ruleChange$.pipe(R((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
|
|
545
678
|
}
|
|
546
679
|
onDataValidationStatusChange(e) {
|
|
547
|
-
return
|
|
680
|
+
return g(this._dataValidationModel.validStatusChange$.pipe(R((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
|
|
548
681
|
}
|
|
549
682
|
onBeforeAddDataValidation(e) {
|
|
550
|
-
return
|
|
683
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
551
684
|
const a = t.params;
|
|
552
|
-
if (t.id ===
|
|
685
|
+
if (t.id === A.id) {
|
|
553
686
|
if (a.unitId !== this._workbook.getUnitId())
|
|
554
687
|
return;
|
|
555
688
|
if (e(a, r) === !1)
|
|
@@ -558,9 +691,9 @@ class x extends k {
|
|
|
558
691
|
}));
|
|
559
692
|
}
|
|
560
693
|
onBeforeUpdateDataValidationCriteria(e) {
|
|
561
|
-
return
|
|
694
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
562
695
|
const a = t.params;
|
|
563
|
-
if (t.id ===
|
|
696
|
+
if (t.id === v.id) {
|
|
564
697
|
if (a.unitId !== this._workbook.getUnitId())
|
|
565
698
|
return;
|
|
566
699
|
if (e(a, r) === !1)
|
|
@@ -569,9 +702,9 @@ class x extends k {
|
|
|
569
702
|
}));
|
|
570
703
|
}
|
|
571
704
|
onBeforeUpdateDataValidationRange(e) {
|
|
572
|
-
return
|
|
705
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
573
706
|
const a = t.params;
|
|
574
|
-
if (t.id ===
|
|
707
|
+
if (t.id === C.id) {
|
|
575
708
|
if (a.unitId !== this._workbook.getUnitId())
|
|
576
709
|
return;
|
|
577
710
|
if (e(a, r) === !1)
|
|
@@ -580,9 +713,9 @@ class x extends k {
|
|
|
580
713
|
}));
|
|
581
714
|
}
|
|
582
715
|
onBeforeUpdateDataValidationOptions(e) {
|
|
583
|
-
return
|
|
716
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
584
717
|
const a = t.params;
|
|
585
|
-
if (t.id ===
|
|
718
|
+
if (t.id === U.id) {
|
|
586
719
|
if (a.unitId !== this._workbook.getUnitId())
|
|
587
720
|
return;
|
|
588
721
|
if (e(a, r) === !1)
|
|
@@ -591,9 +724,9 @@ class x extends k {
|
|
|
591
724
|
}));
|
|
592
725
|
}
|
|
593
726
|
onBeforeDeleteDataValidation(e) {
|
|
594
|
-
return
|
|
727
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
595
728
|
const a = t.params;
|
|
596
|
-
if (t.id ===
|
|
729
|
+
if (t.id === T.id) {
|
|
597
730
|
if (a.unitId !== this._workbook.getUnitId())
|
|
598
731
|
return;
|
|
599
732
|
if (e(a, r) === !1)
|
|
@@ -602,9 +735,9 @@ class x extends k {
|
|
|
602
735
|
}));
|
|
603
736
|
}
|
|
604
737
|
onBeforeDeleteAllDataValidation(e) {
|
|
605
|
-
return
|
|
738
|
+
return g(this._commandService.beforeCommandExecuted((t, r) => {
|
|
606
739
|
const a = t.params;
|
|
607
|
-
if (t.id ===
|
|
740
|
+
if (t.id === O.id) {
|
|
608
741
|
if (a.unitId !== this._workbook.getUnitId())
|
|
609
742
|
return;
|
|
610
743
|
if (e(a, r) === !1)
|
|
@@ -613,20 +746,51 @@ class x extends k {
|
|
|
613
746
|
}));
|
|
614
747
|
}
|
|
615
748
|
}
|
|
616
|
-
|
|
617
|
-
class
|
|
749
|
+
M.extend(z);
|
|
750
|
+
class K extends x {
|
|
618
751
|
getDataValidations() {
|
|
619
|
-
return this._injector.get(
|
|
752
|
+
return this._injector.get(b).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
|
|
620
753
|
}
|
|
621
754
|
getValidatorStatus() {
|
|
622
|
-
return this._injector.get(
|
|
755
|
+
return this._injector.get(S).validatorWorksheet(
|
|
623
756
|
this._workbook.getUnitId(),
|
|
624
757
|
this._worksheet.getSheetId()
|
|
625
758
|
);
|
|
626
759
|
}
|
|
760
|
+
getDataValidation(e) {
|
|
761
|
+
const r = this._injector.get(b).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
|
|
762
|
+
return r ? new m(r, this._worksheet, this._injector) : null;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
x.extend(K);
|
|
766
|
+
class X {
|
|
767
|
+
get SheetDataValidationChanged() {
|
|
768
|
+
return "SheetDataValidationChanged";
|
|
769
|
+
}
|
|
770
|
+
get SheetDataValidatorStatusChanged() {
|
|
771
|
+
return "SheetDataValidatorStatusChanged";
|
|
772
|
+
}
|
|
773
|
+
get BeforeSheetDataValidationAdd() {
|
|
774
|
+
return "BeforeSheetDataValidationAdd";
|
|
775
|
+
}
|
|
776
|
+
get BeforeSheetDataValidationDelete() {
|
|
777
|
+
return "BeforeSheetDataValidationDelete";
|
|
778
|
+
}
|
|
779
|
+
get BeforeSheetDataValidationDeleteAll() {
|
|
780
|
+
return "BeforeSheetDataValidationDeleteAll";
|
|
781
|
+
}
|
|
782
|
+
get BeforeSheetDataValidationCriteriaUpdate() {
|
|
783
|
+
return "BeforeSheetDataValidationCriteriaUpdate";
|
|
784
|
+
}
|
|
785
|
+
get BeforeSheetDataValidationRangeUpdate() {
|
|
786
|
+
return "BeforeSheetDataValidationRangeUpdate";
|
|
787
|
+
}
|
|
788
|
+
get BeforeSheetDataValidationOptionsUpdate() {
|
|
789
|
+
return "BeforeSheetDataValidationOptionsUpdate";
|
|
790
|
+
}
|
|
627
791
|
}
|
|
628
|
-
|
|
792
|
+
$.extend(X);
|
|
629
793
|
export {
|
|
630
794
|
m as FDataValidation,
|
|
631
|
-
|
|
795
|
+
D as FDataValidationBuilder
|
|
632
796
|
};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { DataValidationStatus, IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions, IEventBase, IRange, ISheetDataValidationRule } from '@univerjs/core';
|
|
2
|
+
import { DataValidationChangeType, IRuleChange } from '@univerjs/data-validation';
|
|
3
|
+
import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
|
|
4
|
+
import { FDataValidation } from './f-data-validation';
|
|
5
|
+
/**
|
|
6
|
+
* Event interface triggered when a data validation rule is changed
|
|
7
|
+
* @interface ISheetDataValidationChangedEvent
|
|
8
|
+
* @augments {IEventBase}
|
|
9
|
+
*/
|
|
10
|
+
export interface ISheetDataValidationChangedEvent extends IEventBase {
|
|
11
|
+
/** The source of the rule change */
|
|
12
|
+
origin: IRuleChange;
|
|
13
|
+
/** The worksheet containing the validation rule */
|
|
14
|
+
worksheet: FWorksheet;
|
|
15
|
+
/** The workbook instance */
|
|
16
|
+
workbook: FWorkbook;
|
|
17
|
+
/** Type of change made to the validation rule */
|
|
18
|
+
changeType: DataValidationChangeType;
|
|
19
|
+
/** The previous validation rule, if it exists */
|
|
20
|
+
oldRule?: IDataValidationRule;
|
|
21
|
+
/** The new or modified validation rule */
|
|
22
|
+
rule: FDataValidation;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Event interface triggered when a data validation status changes
|
|
26
|
+
* @interface ISheetDataValidatorStatusChangedEvent
|
|
27
|
+
* @augments {IEventBase}
|
|
28
|
+
*/
|
|
29
|
+
export interface ISheetDataValidatorStatusChangedEvent extends IEventBase {
|
|
30
|
+
/** The worksheet containing the validation */
|
|
31
|
+
worksheet: FWorksheet;
|
|
32
|
+
/** The workbook instance */
|
|
33
|
+
workbook: FWorkbook;
|
|
34
|
+
/** Row index of the validated cell */
|
|
35
|
+
row: number;
|
|
36
|
+
/** Column index of the validated cell */
|
|
37
|
+
column: number;
|
|
38
|
+
/** Current validation status */
|
|
39
|
+
status: DataValidationStatus;
|
|
40
|
+
/** The validation rule that was checked */
|
|
41
|
+
rule: FDataValidation;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Event interface triggered before adding a new data validation rule
|
|
45
|
+
* @interface IBeforeSheetDataValidationAddEvent
|
|
46
|
+
* @augments {IEventBase}
|
|
47
|
+
*/
|
|
48
|
+
export interface IBeforeSheetDataValidationAddEvent extends IEventBase {
|
|
49
|
+
/** The worksheet to add the validation to */
|
|
50
|
+
worksheet: FWorksheet;
|
|
51
|
+
/** The workbook instance */
|
|
52
|
+
workbook: FWorkbook;
|
|
53
|
+
/** The validation rule to be added */
|
|
54
|
+
rule: ISheetDataValidationRule;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Event interface triggered before deleting a data validation rule
|
|
58
|
+
* @interface IBeforeSheetDataValidationDeleteEvent
|
|
59
|
+
* @augments {IEventBase}
|
|
60
|
+
*/
|
|
61
|
+
export interface IBeforeSheetDataValidationDeleteEvent extends IEventBase {
|
|
62
|
+
/** The worksheet containing the validation */
|
|
63
|
+
worksheet: FWorksheet;
|
|
64
|
+
/** The workbook instance */
|
|
65
|
+
workbook: FWorkbook;
|
|
66
|
+
/** Unique identifier of the rule to be deleted */
|
|
67
|
+
ruleId: string;
|
|
68
|
+
/** The validation rule to be deleted */
|
|
69
|
+
rule: FDataValidation;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Event interface triggered before updating a data validation rule's criteria
|
|
73
|
+
* @interface IBeforeSheetDataValidationCriteriaUpdateEvent
|
|
74
|
+
* @augments {IEventBase}
|
|
75
|
+
*/
|
|
76
|
+
export interface IBeforeSheetDataValidationCriteriaUpdateEvent extends IEventBase {
|
|
77
|
+
/** The worksheet containing the validation */
|
|
78
|
+
worksheet: FWorksheet;
|
|
79
|
+
/** The workbook instance */
|
|
80
|
+
workbook: FWorkbook;
|
|
81
|
+
/** Unique identifier of the rule to be updated */
|
|
82
|
+
ruleId: string;
|
|
83
|
+
/** The current validation rule */
|
|
84
|
+
rule: FDataValidation;
|
|
85
|
+
/** The new criteria to be applied */
|
|
86
|
+
newCriteria: IDataValidationRuleBase;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Event interface triggered before updating a data validation rule's ranges
|
|
90
|
+
* @interface IBeforeSheetDataValidationRangeUpdateEvent
|
|
91
|
+
* @augments {IEventBase}
|
|
92
|
+
*/
|
|
93
|
+
export interface IBeforeSheetDataValidationRangeUpdateEvent extends IEventBase {
|
|
94
|
+
/** The worksheet containing the validation */
|
|
95
|
+
worksheet: FWorksheet;
|
|
96
|
+
/** The workbook instance */
|
|
97
|
+
workbook: FWorkbook;
|
|
98
|
+
/** Unique identifier of the rule to be updated */
|
|
99
|
+
ruleId: string;
|
|
100
|
+
/** The current validation rule */
|
|
101
|
+
rule: FDataValidation;
|
|
102
|
+
/** The new ranges to be applied */
|
|
103
|
+
newRanges: IRange[];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Event interface triggered before updating a data validation rule's options
|
|
107
|
+
* @interface IBeforeSheetDataValidationOptionsUpdateEvent
|
|
108
|
+
* @augments {IEventBase}
|
|
109
|
+
*/
|
|
110
|
+
export interface IBeforeSheetDataValidationOptionsUpdateEvent extends IEventBase {
|
|
111
|
+
/** The worksheet containing the validation */
|
|
112
|
+
worksheet: FWorksheet;
|
|
113
|
+
/** The workbook instance */
|
|
114
|
+
workbook: FWorkbook;
|
|
115
|
+
/** Unique identifier of the rule to be updated */
|
|
116
|
+
ruleId: string;
|
|
117
|
+
/** The current validation rule */
|
|
118
|
+
rule: FDataValidation;
|
|
119
|
+
/** The new options to be applied */
|
|
120
|
+
newOptions: IDataValidationRuleOptions;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Event interface triggered before deleting all data validation rules
|
|
124
|
+
* @interface IBeforeSheetDataValidationDeleteAllEvent
|
|
125
|
+
* @augments {IEventBase}
|
|
126
|
+
*/
|
|
127
|
+
export interface IBeforeSheetDataValidationDeleteAllEvent extends IEventBase {
|
|
128
|
+
/** The worksheet containing the validations */
|
|
129
|
+
worksheet: FWorksheet;
|
|
130
|
+
/** The workbook instance */
|
|
131
|
+
workbook: FWorkbook;
|
|
132
|
+
/** Array of all validation rules to be deleted */
|
|
133
|
+
rules: FDataValidation[];
|
|
134
|
+
}
|
|
135
|
+
export interface IDataValidationEventParamConfig {
|
|
136
|
+
SheetDataValidationChanged: ISheetDataValidationChangedEvent;
|
|
137
|
+
SheetDataValidatorStatusChanged: ISheetDataValidatorStatusChangedEvent;
|
|
138
|
+
BeforeSheetDataValidationAdd: IBeforeSheetDataValidationAddEvent;
|
|
139
|
+
BeforeSheetDataValidationDelete: IBeforeSheetDataValidationDeleteEvent;
|
|
140
|
+
BeforeSheetDataValidationDeleteAll: IBeforeSheetDataValidationDeleteAllEvent;
|
|
141
|
+
BeforeSheetDataValidationCriteriaUpdate: IBeforeSheetDataValidationCriteriaUpdateEvent;
|
|
142
|
+
BeforeSheetDataValidationRangeUpdate: IBeforeSheetDataValidationRangeUpdateEvent;
|
|
143
|
+
BeforeSheetDataValidationOptionsUpdate: IBeforeSheetDataValidationOptionsUpdateEvent;
|
|
144
|
+
}
|
|
145
|
+
interface IDataValidationEvent {
|
|
146
|
+
/**
|
|
147
|
+
* Event fired when a rule is added, deleted, or modified
|
|
148
|
+
* @see {@link ISheetDataValidationChangedEvent}
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* univerAPI.on(univerAPI.Event.SheetDataValidationChanged, (event) => {
|
|
152
|
+
* const { worksheet, workbook, changeType, oldRule, rule } = event;
|
|
153
|
+
* console.log(event);
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
readonly SheetDataValidationChanged: 'SheetDataValidationChanged';
|
|
158
|
+
/**
|
|
159
|
+
* Event fired when a cell validator status is changed
|
|
160
|
+
* @see {@link ISheetDataValidatorStatusChangedEvent}
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* univerAPI.on(univerAPI.Event.SheetDataValidatorStatusChanged, (event) => {
|
|
164
|
+
* const { worksheet, workbook, row, column, status, rule } = event;
|
|
165
|
+
* console.log(event);
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
readonly SheetDataValidatorStatusChanged: 'SheetDataValidatorStatusChanged';
|
|
170
|
+
/**
|
|
171
|
+
* Event fired before a rule is added
|
|
172
|
+
* @see {@link IBeforeSheetDataValidationAddEvent}
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationAdd, (event) => {
|
|
176
|
+
* const { worksheet, workbook, rule } = event;
|
|
177
|
+
* console.log(event);
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
readonly BeforeSheetDataValidationAdd: 'BeforeSheetDataValidationAdd';
|
|
182
|
+
/**
|
|
183
|
+
* Event fired before a rule is deleted
|
|
184
|
+
* @see {@link IBeforeSheetDataValidationDeleteEvent}
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationDelete, (event) => {
|
|
188
|
+
* const { worksheet, workbook, rule } = event;
|
|
189
|
+
* console.log(event);
|
|
190
|
+
* });
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
readonly BeforeSheetDataValidationDelete: 'BeforeSheetDataValidationDelete';
|
|
194
|
+
/**
|
|
195
|
+
* Event fired before all rules are deleted
|
|
196
|
+
* @see {@link IBeforeSheetDataValidationDeleteAllEvent}
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationDeleteAll, (event) => {
|
|
200
|
+
* const { worksheet, workbook, rules } = event;
|
|
201
|
+
* console.log(event);
|
|
202
|
+
* });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
readonly BeforeSheetDataValidationDeleteAll: 'BeforeSheetDataValidationDeleteAll';
|
|
206
|
+
/**
|
|
207
|
+
* Event fired before the criteria of a rule are updated
|
|
208
|
+
* @see {@link IBeforeSheetDataValidationCriteriaUpdateEvent}
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationCriteriaUpdate, (event) => {
|
|
212
|
+
* const { worksheet, workbook, rule, newCriteria } = event;
|
|
213
|
+
* console.log(event);
|
|
214
|
+
* });
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
readonly BeforeSheetDataValidationCriteriaUpdate: 'BeforeSheetDataValidationCriteriaUpdate';
|
|
218
|
+
/**
|
|
219
|
+
* Event fired before the range of a rule is updated
|
|
220
|
+
* @see {@link IBeforeSheetDataValidationRangeUpdateEvent}
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationRangeUpdate, (event) => {
|
|
224
|
+
* const { worksheet, workbook, rule, newRanges } = event;
|
|
225
|
+
* console.log(event);
|
|
226
|
+
* });
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
readonly BeforeSheetDataValidationRangeUpdate: 'BeforeSheetDataValidationRangeUpdate';
|
|
230
|
+
/**
|
|
231
|
+
* Event fired before the options of a rule are updated
|
|
232
|
+
* @see {@link IBeforeSheetDataValidationOptionsUpdateEvent}
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* univerAPI.on(univerAPI.Event.BeforeSheetDataValidationOptionsUpdate, (event) => {
|
|
236
|
+
* const { worksheet, workbook, rule, newOptions } = event;
|
|
237
|
+
* console.log(event);
|
|
238
|
+
* });
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
readonly BeforeSheetDataValidationOptionsUpdate: 'BeforeSheetDataValidationOptionsUpdate';
|
|
242
|
+
}
|
|
243
|
+
export declare class FDataValidationEvent implements IDataValidationEvent {
|
|
244
|
+
get SheetDataValidationChanged(): 'SheetDataValidationChanged';
|
|
245
|
+
get SheetDataValidatorStatusChanged(): 'SheetDataValidatorStatusChanged';
|
|
246
|
+
get BeforeSheetDataValidationAdd(): 'BeforeSheetDataValidationAdd';
|
|
247
|
+
get BeforeSheetDataValidationDelete(): 'BeforeSheetDataValidationDelete';
|
|
248
|
+
get BeforeSheetDataValidationDeleteAll(): 'BeforeSheetDataValidationDeleteAll';
|
|
249
|
+
get BeforeSheetDataValidationCriteriaUpdate(): 'BeforeSheetDataValidationCriteriaUpdate';
|
|
250
|
+
get BeforeSheetDataValidationRangeUpdate(): 'BeforeSheetDataValidationRangeUpdate';
|
|
251
|
+
get BeforeSheetDataValidationOptionsUpdate(): 'BeforeSheetDataValidationOptionsUpdate';
|
|
252
|
+
}
|
|
253
|
+
export interface IDataValidationEventConfig {
|
|
254
|
+
SheetDataValidationChanged: ISheetDataValidationChangedEvent;
|
|
255
|
+
SheetDataValidatorStatusChanged: ISheetDataValidatorStatusChangedEvent;
|
|
256
|
+
BeforeSheetDataValidationAdd: IBeforeSheetDataValidationAddEvent;
|
|
257
|
+
BeforeSheetDataValidationDelete: IBeforeSheetDataValidationDeleteEvent;
|
|
258
|
+
BeforeSheetDataValidationDeleteAll: IBeforeSheetDataValidationDeleteAllEvent;
|
|
259
|
+
BeforeSheetDataValidationCriteriaUpdate: IBeforeSheetDataValidationCriteriaUpdateEvent;
|
|
260
|
+
BeforeSheetDataValidationRangeUpdate: IBeforeSheetDataValidationRangeUpdateEvent;
|
|
261
|
+
BeforeSheetDataValidationOptionsUpdate: IBeforeSheetDataValidationOptionsUpdateEvent;
|
|
262
|
+
}
|
|
263
|
+
declare module '@univerjs/core' {
|
|
264
|
+
interface FEventName extends IDataValidationEvent {
|
|
265
|
+
}
|
|
266
|
+
interface IEventParamConfig extends IDataValidationEventParamConfig {
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
export {};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { Injector, FUniver } from '@univerjs/core';
|
|
1
2
|
import { FDataValidationBuilder } from './f-data-validation-builder';
|
|
2
|
-
export declare class FUnvierDataValidationMixin {
|
|
3
|
+
export declare class FUnvierDataValidationMixin extends FUniver {
|
|
4
|
+
/**
|
|
3
5
|
/**
|
|
4
6
|
* @deparecated use `univerAPI.newDataValidation()` as instead.
|
|
5
7
|
*/
|
|
6
8
|
static newDataValidation(): FDataValidationBuilder;
|
|
7
9
|
newDataValidation(): FDataValidationBuilder;
|
|
10
|
+
_initialize(injector: Injector): void;
|
|
8
11
|
}
|
|
9
12
|
declare module '@univerjs/core' {
|
|
10
13
|
namespace FUniver {
|
|
@@ -5,17 +5,39 @@ export interface IFWorksheetDataValidationMixin {
|
|
|
5
5
|
/**
|
|
6
6
|
* Get all data validation rules in current sheet.
|
|
7
7
|
* @returns all data validation rules
|
|
8
|
+
* ```ts
|
|
9
|
+
* const workbook = univerAPI.getActiveUniverSheet();
|
|
10
|
+
* const worksheet = workbook.getWorksheet('sheet1');
|
|
11
|
+
* const dataValidations = worksheet.getDataValidations();
|
|
12
|
+
* ```
|
|
8
13
|
*/
|
|
9
14
|
getDataValidations(): FDataValidation[];
|
|
10
15
|
/**
|
|
11
16
|
* Get data validation validator status for current sheet.
|
|
12
17
|
* @returns matrix of validator status
|
|
18
|
+
* ```ts
|
|
19
|
+
* const workbook = univerAPI.getActiveUniverSheet();
|
|
20
|
+
* const worksheet = workbook.getWorksheet('sheet1');
|
|
21
|
+
* const validatorStatus = worksheet.getValidatorStatus();
|
|
22
|
+
* ```
|
|
13
23
|
*/
|
|
14
24
|
getValidatorStatus(): Promise<ObjectMatrix<Nullable<DataValidationStatus>>>;
|
|
25
|
+
/**
|
|
26
|
+
* get data validation rule by rule id
|
|
27
|
+
* @param ruleId - the rule id
|
|
28
|
+
* @returns data validation rule
|
|
29
|
+
* ```ts
|
|
30
|
+
* const workbook = univerAPI.getActiveUniverSheet();
|
|
31
|
+
* const worksheet = workbook.getWorksheet('sheet1');
|
|
32
|
+
* const dataValidation = worksheet.getDataValidation('ruleId');
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
getDataValidation(ruleId: string): Nullable<FDataValidation>;
|
|
15
36
|
}
|
|
16
37
|
export declare class FWorksheetDataValidationMixin extends FWorksheet implements IFWorksheetDataValidationMixin {
|
|
17
38
|
getDataValidations(): FDataValidation[];
|
|
18
39
|
getValidatorStatus(): Promise<ObjectMatrix<Nullable<DataValidationStatus>>>;
|
|
40
|
+
getDataValidation(ruleId: string): Nullable<FDataValidation>;
|
|
19
41
|
}
|
|
20
42
|
declare module '@univerjs/sheets/facade' {
|
|
21
43
|
interface FWorksheet extends IFWorksheetDataValidationMixin {
|
|
@@ -17,8 +17,10 @@ import './f-range';
|
|
|
17
17
|
import './f-univer';
|
|
18
18
|
import './f-workbook';
|
|
19
19
|
import './f-worksheet';
|
|
20
|
+
import './f-event';
|
|
20
21
|
export { FDataValidation } from './f-data-validation';
|
|
21
22
|
export { FDataValidationBuilder } from './f-data-validation-builder';
|
|
23
|
+
export type * from './f-event';
|
|
22
24
|
export type * from './f-range';
|
|
23
25
|
export type * from './f-univer';
|
|
24
26
|
export type * from './f-workbook';
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(n,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets-data-validation","@univerjs/sheets/facade","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","rxjs"],a):(n=typeof globalThis<"u"?globalThis:n||self,a(n.UniverSheetsDataValidationFacade={},n.UniverSheetsDataValidation,n.UniverSheetsFacade,n.UniverCore,n.UniverDataValidation,n.UniverEngineFormula,n.rxjs))})(this,function(n,a,s,i,_,p,m){"use strict";var V=Object.defineProperty;var E=(n,a,s)=>a in n?V(n,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[a]=s;var d=(n,a,s)=>E(n,typeof a!="symbol"?a+"":a,s);class l{constructor(t){d(this,"_rule");this._rule=t!=null?t:{uid:i.generateRandomId(),ranges:void 0,type:i.DataValidationType.CUSTOM}}build(){return new u(this._rule)}copy(){return new l({...this._rule,uid:i.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==i.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(t,e){return this._rule.type=i.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=i.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=i.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=i.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=i.DataValidationType.CUSTOM,this._rule.formula1=t,this._rule.formula2=void 0,this}requireNumberBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=i.DataValidationOperator.BETWEEN,this._rule.type=r?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.EQUAL,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.GREATER_THAN,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=i.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.NOT_EQUAL,this._rule.type=e?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireValueInList(t,e,r){return this._rule.type=e?i.DataValidationType.LIST_MULTIPLE:i.DataValidationType.LIST,this._rule.formula1=t.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(t,e,r){return this._rule.type=e?i.DataValidationType.LIST_MULTIPLE:i.DataValidationType.LIST,this._rule.formula1=`=${p.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(t){return this._rule.errorStyle=t?i.DataValidationErrorStyle.WARNING:i.DataValidationErrorStyle.STOP,this}setHelpText(t){return this._rule.error=t,this._rule.showErrorMessage=!0,this}withCriteriaValues(t,e){return this._rule.type=t,this._rule.operator=e[0],this._rule.formula1=e[1],this._rule.formula2=e[2],this}setAllowBlank(t){return this._rule.allowBlank=t,this}setOptions(t){return Object.assign(this._rule,t),this}}class u{constructor(t,e,r){d(this,"rule");d(this,"_worksheet");d(this,"_injector");this._injector=r,this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==i.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new l(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(_.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];const t=this._injector.get(i.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(e=>this._injector.createInstance(s.FRange,t,this._worksheet,e))}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e,r=!0){if(this.getApplied()&&!this._injector.get(i.ICommandService).syncExecuteCommand(a.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:e[0],formula1:e[1],formula2:e[2],type:this.rule.type,allowBlank:r}}))throw new Error("setCriteria failed");return this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,this.rule.allowBlank=r,this}setOptions(t){if(this.getApplied()&&!this._injector.get(i.ICommandService).syncExecuteCommand(a.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{..._.getRuleOptions(this.rule),...t}}))throw new Error("setOptions failed");return Object.assign(this.rule,t),this}setRanges(t){if(this.getApplied()&&!this._injector.get(i.ICommandService).syncExecuteCommand(a.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(o=>o.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=t.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(i.ICommandService).syncExecuteCommand(a.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class g extends s.FRange{setDataValidation(t){if(!t)return this._commandService.syncExecuteCommand(a.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...t.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(a.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(a.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new u(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(a.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new u(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(a.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}s.FRange.extend(g);class D{static newDataValidation(){return new l}newDataValidation(){return new l}}i.FUniver.extend(D);class f extends s.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(a.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(a.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return i.toDisposable(this._dataValidationModel.ruleChange$.pipe(m.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return i.toDisposable(this._dataValidationModel.validStatusChange$.pipe(m.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.AddSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.UpdateSheetDataValidationSettingCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.UpdateSheetDataValidationRangeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.UpdateSheetDataValidationOptionsCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.RemoveSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return i.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===a.RemoveSheetAllDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}s.FWorkbook.extend(f);class S extends s.FWorksheet{getDataValidations(){return this._injector.get(_.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new u(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(a.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}}s.FWorksheet.extend(S),n.FDataValidation=u,n.FDataValidationBuilder=l,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(u,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets-data-validation","@univerjs/sheets/facade","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","rxjs"],i):(u=typeof globalThis<"u"?globalThis:u||self,i(u.UniverSheetsDataValidationFacade={},u.UniverSheetsDataValidation,u.UniverSheetsFacade,u.UniverCore,u.UniverDataValidation,u.UniverEngineFormula,u.rxjs))})(this,function(u,i,m,a,D,k,I){"use strict";var U=Object.defineProperty;var A=(u,i,m)=>i in u?U(u,i,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[i]=m;var f=(u,i,m)=>A(u,typeof i!="symbol"?i+"":i,m);class _{constructor(t){f(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new g(this._rule)}copy(){return new _({...this._rule,uid:a.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(t,e){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=t,this._rule.formula2=void 0,this}requireNumberBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=t.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${k.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(t){return this._rule.errorStyle=t?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setHelpText(t){return this._rule.error=t,this._rule.showErrorMessage=!0,this}withCriteriaValues(t,e){return this._rule.type=t,this._rule.operator=e[0],this._rule.formula1=e[1],this._rule.formula2=e[2],this}setAllowBlank(t){return this._rule.allowBlank=t,this}setOptions(t){return Object.assign(this._rule,t),this}}class g{constructor(t,e,r){f(this,"rule");f(this,"_worksheet");f(this,"_injector");this._injector=r,this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new _(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(D.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];const t=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(e=>this._injector.createInstance(m.FRange,t,this._worksheet,e))}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e,r=!0){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(i.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:e[0],formula1:e[1],formula2:e[2],type:this.rule.type,allowBlank:r}}))throw new Error("setCriteria failed");return this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,this.rule.allowBlank=r,this}setOptions(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(i.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...D.getRuleOptions(this.rule),...t}}))throw new Error("setOptions failed");return Object.assign(this.rule,t),this}setRanges(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(i.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(o=>o.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=t.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(a.ICommandService).syncExecuteCommand(i.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class w extends m.FRange{setDataValidation(t){if(!t)return this._commandService.syncExecuteCommand(i.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...t.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(i.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(i.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new g(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(i.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new g(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(i.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}m.FRange.extend(w);class T extends a.FUniver{static newDataValidation(){return new _}newDataValidation(){return new _}_initialize(t){if(!t.has(i.SheetDataValidationModel))return;const e=t.get(i.SheetDataValidationModel),r=t.get(a.ICommandService);this.disposeWithMe(e.ruleChange$.subscribe(o=>{const{unitId:n,subUnitId:s,rule:p,oldRule:d,type:l}=o,h=this.getSheetTarget(n,s);if(!h)return;const{workbook:c,worksheet:V}=h,v=new g(p,V.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:o,worksheet:V,workbook:c,changeType:l,oldRule:d,rule:v})})),this.disposeWithMe(e.validStatusChange$.subscribe(o=>{const{unitId:n,subUnitId:s,ruleId:p,status:d,row:l,col:h}=o,c=this.getSheetTarget(n,s);if(!c)return;const{workbook:V,worksheet:v}=c,E=v.getDataValidation(p);E&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:V,worksheet:v,row:l,column:h,rule:E,status:d})})),this.disposeWithMe(r.beforeCommandExecuted(o=>{switch(o.id){case i.AddSheetDataValidationCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l={worksheet:d,workbook:p,rule:n.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,l),l.cancel)throw new a.CanceledError;break}case i.UpdateSheetDataValidationSettingCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l=d.getDataValidation(n.ruleId);if(!l)return;const h={worksheet:d,workbook:p,rule:l,ruleId:n.ruleId,newCriteria:n.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,h),h.cancel)throw new a.CanceledError;break}case i.UpdateSheetDataValidationRangeCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l=d.getDataValidation(n.ruleId);if(!l)return;const h={worksheet:d,workbook:p,rule:l,ruleId:n.ruleId,newRanges:n.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,h),h.cancel)throw new a.CanceledError;break}case i.UpdateSheetDataValidationOptionsCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l=d.getDataValidation(n.ruleId);if(!l)return;const h={worksheet:d,workbook:p,rule:l,ruleId:n.ruleId,newOptions:n.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,h),h.cancel)throw new a.CanceledError;break}case i.RemoveSheetDataValidationCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l=d.getDataValidation(n.ruleId);if(!l)return;const h={worksheet:d,workbook:p,rule:l,ruleId:n.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,h),h.cancel)throw new a.CanceledError;break}case i.RemoveSheetAllDataValidationCommand.id:{const n=o.params,s=this.getSheetTarget(n.unitId,n.subUnitId);if(!s)return;const{workbook:p,worksheet:d}=s,l={worksheet:d,workbook:p,rules:d.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,l),l.cancel)throw new a.CanceledError;break}}}))}}a.FUniver.extend(T);class b extends m.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(i.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(i.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(I.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(I.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.AddSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.UpdateSheetDataValidationSettingCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.UpdateSheetDataValidationRangeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.UpdateSheetDataValidationOptionsCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.RemoveSheetDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const o=e.params;if(e.id===i.RemoveSheetAllDataValidationCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}m.FWorkbook.extend(b);class y extends m.FWorksheet{getDataValidations(){return this._injector.get(D.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new g(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(i.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getDataValidation(t){const r=this._injector.get(D.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);return r?new g(r,this._worksheet,this._injector):null}}m.FWorksheet.extend(y);class C{get SheetDataValidationChanged(){return"SheetDataValidationChanged"}get SheetDataValidatorStatusChanged(){return"SheetDataValidatorStatusChanged"}get BeforeSheetDataValidationAdd(){return"BeforeSheetDataValidationAdd"}get BeforeSheetDataValidationDelete(){return"BeforeSheetDataValidationDelete"}get BeforeSheetDataValidationDeleteAll(){return"BeforeSheetDataValidationDeleteAll"}get BeforeSheetDataValidationCriteriaUpdate(){return"BeforeSheetDataValidationCriteriaUpdate"}get BeforeSheetDataValidationRangeUpdate(){return"BeforeSheetDataValidationRangeUpdate"}get BeforeSheetDataValidationOptionsUpdate(){return"BeforeSheetDataValidationOptionsUpdate"}}a.FEventName.extend(C),u.FDataValidation=g,u.FDataValidationBuilder=_,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-data-validation",
|
|
3
|
-
"version": "0.5.3-nightly.
|
|
3
|
+
"version": "0.5.3-nightly.202501071618",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Data validation for Univer Sheets",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@univerjs/protocol": "0.1.40",
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/sheets-formula": "0.5.3-nightly.
|
|
61
|
-
"@univerjs/
|
|
57
|
+
"@univerjs/core": "0.5.3-nightly.202501071618",
|
|
58
|
+
"@univerjs/data-validation": "0.5.3-nightly.202501071618",
|
|
59
|
+
"@univerjs/engine-formula": "0.5.3-nightly.202501071618",
|
|
60
|
+
"@univerjs/sheets-formula": "0.5.3-nightly.202501071618",
|
|
61
|
+
"@univerjs/sheets": "0.5.3-nightly.202501071618"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"less": "^4.2.1",
|