@univerjs/sheets-data-validation 0.5.2-nightly.202412301606 → 0.5.2-nightly.202501011606
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
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}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){return 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}})?!1:(this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,!0)}setOptions(t){return 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}})?!1:(Object.assign(this.rule,t),!0)}setRanges(t){return 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())})?!1:(this.rule.ranges=t.map(e=>e.getRange()),!0)}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 D extends s.FRange{async setDataValidation(t){if(!t)return this._commandService.executeCommand(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 await this._commandService.executeCommand(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(D);class g{static newDataValidation(){return new l}newDataValidation(){return new l}}a.FUniver.extend(g);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 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;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var V = (s, e, t) => e in s ?
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var V = (s, e, t) => e in s ? b(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
3
|
var u = (s, e, t) => V(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import { UpdateSheetDataValidationSettingCommand as f, UpdateSheetDataValidationOptionsCommand as S, UpdateSheetDataValidationRangeCommand as
|
|
5
|
-
import { FRange as c, FWorkbook as k, FWorksheet as
|
|
6
|
-
import { generateRandomId as g, DataValidationType as
|
|
7
|
-
import { DataValidationModel as
|
|
4
|
+
import { UpdateSheetDataValidationSettingCommand as f, UpdateSheetDataValidationOptionsCommand as S, UpdateSheetDataValidationRangeCommand as E, RemoveSheetDataValidationCommand as I, ClearRangeDataValidationCommand as U, AddSheetDataValidationCommand as D, SheetsDataValidationValidatorService as l, SheetDataValidationModel as A, RemoveSheetAllDataValidationCommand as C } from "@univerjs/sheets-data-validation";
|
|
5
|
+
import { FRange as c, FWorkbook as k, FWorksheet as w } from "@univerjs/sheets/facade";
|
|
6
|
+
import { generateRandomId as g, DataValidationType as i, DataValidationErrorStyle as _, DataValidationOperator as o, IUniverInstanceService as T, ICommandService as d, FUniver as y, toDisposable as n } from "@univerjs/core";
|
|
7
|
+
import { DataValidationModel as v, getRuleOptions as L } from "@univerjs/data-validation";
|
|
8
8
|
import { serializeRangeToRefString as O } from "@univerjs/engine-formula";
|
|
9
9
|
import { filter as p } from "rxjs";
|
|
10
10
|
class h {
|
|
@@ -13,7 +13,7 @@ class h {
|
|
|
13
13
|
this._rule = e != null ? e : {
|
|
14
14
|
uid: g(),
|
|
15
15
|
ranges: void 0,
|
|
16
|
-
type:
|
|
16
|
+
type: i.CUSTOM
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -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 = i.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 = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = o.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 = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.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 = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = o.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 = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.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 = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = o.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 = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.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 = i.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = o.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 = i.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.
|
|
@@ -161,8 +161,8 @@ class h {
|
|
|
161
161
|
* @param isInteger Indicates whether the required number is an integer. Default is undefined, meaning it can be an integer or decimal.
|
|
162
162
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
163
163
|
*/
|
|
164
|
-
requireNumberBetween(e, t,
|
|
165
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = o.BETWEEN, this._rule.type =
|
|
164
|
+
requireNumberBetween(e, t, r) {
|
|
165
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = o.BETWEEN, this._rule.type = r ? i.WHOLE : i.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 = o.EQUAL, this._rule.type = t ?
|
|
176
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.EQUAL, this._rule.type = t ? i.WHOLE : i.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 = o.GREATER_THAN, this._rule.type = t ?
|
|
187
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.GREATER_THAN, this._rule.type = t ? i.WHOLE : i.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 = o.GREATER_THAN_OR_EQUAL, this._rule.type = t ?
|
|
198
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.GREATER_THAN_OR_EQUAL, this._rule.type = t ? i.WHOLE : i.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 = o.LESS_THAN, this._rule.type = t ?
|
|
209
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.LESS_THAN, this._rule.type = t ? i.WHOLE : i.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 = o.LESS_THAN_OR_EQUAL, this._rule.type = t ?
|
|
220
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.LESS_THAN_OR_EQUAL, this._rule.type = t ? i.WHOLE : i.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
|
|
@@ -228,8 +228,8 @@ class h {
|
|
|
228
228
|
* @param isInteger Optional parameter, indicating whether the number to be verified is an integer. Default value is false
|
|
229
229
|
* @return An instance of the FDataValidationBuilder class, allowing for method chaining
|
|
230
230
|
*/
|
|
231
|
-
requireNumberNotBetween(e, t,
|
|
232
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = o.NOT_BETWEEN, this._rule.type =
|
|
231
|
+
requireNumberNotBetween(e, t, r) {
|
|
232
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = o.NOT_BETWEEN, this._rule.type = r ? i.WHOLE : i.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 = o.NOT_EQUAL, this._rule.type = t ?
|
|
243
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = o.NOT_EQUAL, this._rule.type = t ? i.WHOLE : i.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.
|
|
@@ -251,8 +251,8 @@ class h {
|
|
|
251
251
|
* @param showDropdown Optional parameter indicating whether to display the list in a dropdown. Default is true, meaning the list will be displayed as a dropdown.
|
|
252
252
|
* @return An instance of the FDataValidationBuilder class, allowing for method chaining.
|
|
253
253
|
*/
|
|
254
|
-
requireValueInList(e, t,
|
|
255
|
-
return this._rule.type = t ?
|
|
254
|
+
requireValueInList(e, t, r) {
|
|
255
|
+
return this._rule.type = t ? i.LIST_MULTIPLE : i.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.
|
|
@@ -263,12 +263,12 @@ class h {
|
|
|
263
263
|
* @param showDropdown Optional parameter indicating whether to display the list in a dropdown. Default is true, meaning the list will be displayed as a dropdown.
|
|
264
264
|
* @return The current instance of the FDataValidationBuilder class to allow for method chaining.
|
|
265
265
|
*/
|
|
266
|
-
requireValueInRange(e, t,
|
|
267
|
-
return this._rule.type = t ?
|
|
266
|
+
requireValueInRange(e, t, r) {
|
|
267
|
+
return this._rule.type = t ? i.LIST_MULTIPLE : i.LIST, this._rule.formula1 = `=${O({
|
|
268
268
|
unitId: e.getUnitId(),
|
|
269
269
|
sheetName: e.getSheetName(),
|
|
270
270
|
range: e.getRange()
|
|
271
|
-
})}`, this._rule.formula2 = void 0, this._rule.showDropDown =
|
|
271
|
+
})}`, this._rule.formula2 = void 0, this._rule.showDropDown = r != null ? r : !0, this;
|
|
272
272
|
}
|
|
273
273
|
/**
|
|
274
274
|
* Sets whether to allow invalid data and configures the error style for data validation.
|
|
@@ -304,6 +304,9 @@ class h {
|
|
|
304
304
|
withCriteriaValues(e, t) {
|
|
305
305
|
return this._rule.type = e, this._rule.operator = t[0], this._rule.formula1 = t[1], this._rule.formula2 = t[2], this;
|
|
306
306
|
}
|
|
307
|
+
setAllowBlank(e) {
|
|
308
|
+
return this._rule.allowBlank = e, this;
|
|
309
|
+
}
|
|
307
310
|
/**
|
|
308
311
|
* Sets the options for the data validation rule.
|
|
309
312
|
* For details of options, please refer to https://univer.ai/typedoc/@univerjs/core/interfaces/IDataValidationRuleOptions
|
|
@@ -316,11 +319,11 @@ class h {
|
|
|
316
319
|
}
|
|
317
320
|
}
|
|
318
321
|
class m {
|
|
319
|
-
constructor(e, t,
|
|
322
|
+
constructor(e, t, r) {
|
|
320
323
|
u(this, "rule");
|
|
321
324
|
u(this, "_worksheet");
|
|
322
325
|
u(this, "_injector");
|
|
323
|
-
this._injector =
|
|
326
|
+
this._injector = r, this.rule = e, this._worksheet = t;
|
|
324
327
|
}
|
|
325
328
|
/**
|
|
326
329
|
* Gets whether invalid data is allowed based on the error style value.
|
|
@@ -371,7 +374,7 @@ class m {
|
|
|
371
374
|
getApplied() {
|
|
372
375
|
if (!this._worksheet)
|
|
373
376
|
return !1;
|
|
374
|
-
const t = this._injector.get(
|
|
377
|
+
const t = this._injector.get(v).getRuleById(this._worksheet.getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
|
|
375
378
|
return !!(t && t.ranges.length);
|
|
376
379
|
}
|
|
377
380
|
/**
|
|
@@ -382,7 +385,7 @@ class m {
|
|
|
382
385
|
getRanges() {
|
|
383
386
|
if (!this.getApplied())
|
|
384
387
|
return [];
|
|
385
|
-
const e = this._injector.get(
|
|
388
|
+
const e = this._injector.get(T).getUnit(this._worksheet.getUnitId());
|
|
386
389
|
return this.rule.ranges.map((t) => this._injector.createInstance(c, e, this._worksheet, t));
|
|
387
390
|
}
|
|
388
391
|
/**
|
|
@@ -409,8 +412,8 @@ class m {
|
|
|
409
412
|
* @param values An array containing the operator, formula1, and formula2 values.
|
|
410
413
|
* @returns true if the criteria is set successfully, false otherwise.
|
|
411
414
|
*/
|
|
412
|
-
setCriteria(e, t) {
|
|
413
|
-
|
|
415
|
+
setCriteria(e, t, r = !0) {
|
|
416
|
+
if (this.getApplied() && !this._injector.get(d).syncExecuteCommand(f.id, {
|
|
414
417
|
unitId: this.getUnitId(),
|
|
415
418
|
subUnitId: this.getSheetId(),
|
|
416
419
|
ruleId: this.rule.uid,
|
|
@@ -418,9 +421,12 @@ class m {
|
|
|
418
421
|
operator: t[0],
|
|
419
422
|
formula1: t[1],
|
|
420
423
|
formula2: t[2],
|
|
421
|
-
type: this.rule.type
|
|
424
|
+
type: this.rule.type,
|
|
425
|
+
allowBlank: r
|
|
422
426
|
}
|
|
423
|
-
})
|
|
427
|
+
}))
|
|
428
|
+
throw new Error("setCriteria failed");
|
|
429
|
+
return this.rule.operator = t[0], this.rule.formula1 = t[1], this.rule.formula2 = t[2], this.rule.type = e, this.rule.allowBlank = r, this;
|
|
424
430
|
}
|
|
425
431
|
/**
|
|
426
432
|
* Set the options for the data validation rule.
|
|
@@ -429,7 +435,7 @@ class m {
|
|
|
429
435
|
* @returns true if the options are set successfully, false otherwise.
|
|
430
436
|
*/
|
|
431
437
|
setOptions(e) {
|
|
432
|
-
|
|
438
|
+
if (this.getApplied() && !this._injector.get(d).syncExecuteCommand(S.id, {
|
|
433
439
|
unitId: this.getUnitId(),
|
|
434
440
|
subUnitId: this.getSheetId(),
|
|
435
441
|
ruleId: this.rule.uid,
|
|
@@ -437,7 +443,9 @@ class m {
|
|
|
437
443
|
...L(this.rule),
|
|
438
444
|
...e
|
|
439
445
|
}
|
|
440
|
-
})
|
|
446
|
+
}))
|
|
447
|
+
throw new Error("setOptions failed");
|
|
448
|
+
return Object.assign(this.rule, e), this;
|
|
441
449
|
}
|
|
442
450
|
/**
|
|
443
451
|
* Set the ranges to the data validation rule.
|
|
@@ -445,19 +453,21 @@ class m {
|
|
|
445
453
|
* @returns true if the ranges are set successfully, false otherwise.
|
|
446
454
|
*/
|
|
447
455
|
setRanges(e) {
|
|
448
|
-
|
|
456
|
+
if (this.getApplied() && !this._injector.get(d).syncExecuteCommand(E.id, {
|
|
449
457
|
unitId: this.getUnitId(),
|
|
450
458
|
subUnitId: this.getSheetId(),
|
|
451
459
|
ruleId: this.rule.uid,
|
|
452
460
|
ranges: e.map((a) => a.getRange())
|
|
453
|
-
})
|
|
461
|
+
}))
|
|
462
|
+
throw new Error("setRanges failed");
|
|
463
|
+
return this.rule.ranges = e.map((t) => t.getRange()), this;
|
|
454
464
|
}
|
|
455
465
|
/**
|
|
456
466
|
* Delete the data validation rule from the worksheet.
|
|
457
467
|
* @returns true if the rule is deleted successfully, false otherwise.
|
|
458
468
|
*/
|
|
459
469
|
delete() {
|
|
460
|
-
return this.getApplied() ? this._injector.get(d).syncExecuteCommand(
|
|
470
|
+
return this.getApplied() ? this._injector.get(d).syncExecuteCommand(I.id, {
|
|
461
471
|
unitId: this.getUnitId(),
|
|
462
472
|
subUnitId: this.getSheetId(),
|
|
463
473
|
ruleId: this.rule.uid
|
|
@@ -465,9 +475,9 @@ class m {
|
|
|
465
475
|
}
|
|
466
476
|
}
|
|
467
477
|
class R extends c {
|
|
468
|
-
|
|
478
|
+
setDataValidation(e) {
|
|
469
479
|
if (!e)
|
|
470
|
-
return this._commandService.
|
|
480
|
+
return this._commandService.syncExecuteCommand(U.id, {
|
|
471
481
|
unitId: this._workbook.getUnitId(),
|
|
472
482
|
subUnitId: this._worksheet.getSheetId(),
|
|
473
483
|
ranges: [this._range]
|
|
@@ -480,7 +490,7 @@ class R extends c {
|
|
|
480
490
|
ranges: [this._range]
|
|
481
491
|
}
|
|
482
492
|
};
|
|
483
|
-
return
|
|
493
|
+
return this._commandService.syncExecuteCommand(D.id, t), this;
|
|
484
494
|
}
|
|
485
495
|
getDataValidation() {
|
|
486
496
|
const t = this._injector.get(l).getDataValidation(
|
|
@@ -522,7 +532,7 @@ class x extends k {
|
|
|
522
532
|
_initialize() {
|
|
523
533
|
Object.defineProperty(this, "_dataValidationModel", {
|
|
524
534
|
get() {
|
|
525
|
-
return this._injector.get(
|
|
535
|
+
return this._injector.get(A);
|
|
526
536
|
}
|
|
527
537
|
});
|
|
528
538
|
}
|
|
@@ -556,76 +566,76 @@ class x extends k {
|
|
|
556
566
|
* @returns A disposable object that can be used to unsubscribe from the event
|
|
557
567
|
*/
|
|
558
568
|
onBeforeAddDataValidation(e) {
|
|
559
|
-
return n(this._commandService.beforeCommandExecuted((t,
|
|
569
|
+
return n(this._commandService.beforeCommandExecuted((t, r) => {
|
|
560
570
|
const a = t.params;
|
|
561
571
|
if (t.id === D.id) {
|
|
562
572
|
if (a.unitId !== this._workbook.getUnitId())
|
|
563
573
|
return;
|
|
564
|
-
if (e(a,
|
|
574
|
+
if (e(a, r) === !1)
|
|
565
575
|
throw new Error("Command is stopped by the hook onBeforeAddDataValidation");
|
|
566
576
|
}
|
|
567
577
|
}));
|
|
568
578
|
}
|
|
569
579
|
onBeforeUpdateDataValidationCriteria(e) {
|
|
570
|
-
return n(this._commandService.beforeCommandExecuted((t,
|
|
580
|
+
return n(this._commandService.beforeCommandExecuted((t, r) => {
|
|
571
581
|
const a = t.params;
|
|
572
582
|
if (t.id === f.id) {
|
|
573
583
|
if (a.unitId !== this._workbook.getUnitId())
|
|
574
584
|
return;
|
|
575
|
-
if (e(a,
|
|
585
|
+
if (e(a, r) === !1)
|
|
576
586
|
throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria");
|
|
577
587
|
}
|
|
578
588
|
}));
|
|
579
589
|
}
|
|
580
590
|
onBeforeUpdateDataValidationRange(e) {
|
|
581
|
-
return n(this._commandService.beforeCommandExecuted((t,
|
|
591
|
+
return n(this._commandService.beforeCommandExecuted((t, r) => {
|
|
582
592
|
const a = t.params;
|
|
583
|
-
if (t.id ===
|
|
593
|
+
if (t.id === E.id) {
|
|
584
594
|
if (a.unitId !== this._workbook.getUnitId())
|
|
585
595
|
return;
|
|
586
|
-
if (e(a,
|
|
596
|
+
if (e(a, r) === !1)
|
|
587
597
|
throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange");
|
|
588
598
|
}
|
|
589
599
|
}));
|
|
590
600
|
}
|
|
591
601
|
onBeforeUpdateDataValidationOptions(e) {
|
|
592
|
-
return n(this._commandService.beforeCommandExecuted((t,
|
|
602
|
+
return n(this._commandService.beforeCommandExecuted((t, r) => {
|
|
593
603
|
const a = t.params;
|
|
594
604
|
if (t.id === S.id) {
|
|
595
605
|
if (a.unitId !== this._workbook.getUnitId())
|
|
596
606
|
return;
|
|
597
|
-
if (e(a,
|
|
607
|
+
if (e(a, r) === !1)
|
|
598
608
|
throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions");
|
|
599
609
|
}
|
|
600
610
|
}));
|
|
601
611
|
}
|
|
602
612
|
onBeforeDeleteDataValidation(e) {
|
|
603
|
-
return n(this._commandService.beforeCommandExecuted((t,
|
|
613
|
+
return n(this._commandService.beforeCommandExecuted((t, r) => {
|
|
604
614
|
const a = t.params;
|
|
605
|
-
if (t.id ===
|
|
615
|
+
if (t.id === I.id) {
|
|
606
616
|
if (a.unitId !== this._workbook.getUnitId())
|
|
607
617
|
return;
|
|
608
|
-
if (e(a,
|
|
618
|
+
if (e(a, r) === !1)
|
|
609
619
|
throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation");
|
|
610
620
|
}
|
|
611
621
|
}));
|
|
612
622
|
}
|
|
613
623
|
onBeforeDeleteAllDataValidation(e) {
|
|
614
|
-
return n(this._commandService.beforeCommandExecuted((t,
|
|
624
|
+
return n(this._commandService.beforeCommandExecuted((t, r) => {
|
|
615
625
|
const a = t.params;
|
|
616
|
-
if (t.id ===
|
|
626
|
+
if (t.id === C.id) {
|
|
617
627
|
if (a.unitId !== this._workbook.getUnitId())
|
|
618
628
|
return;
|
|
619
|
-
if (e(a,
|
|
629
|
+
if (e(a, r) === !1)
|
|
620
630
|
throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation");
|
|
621
631
|
}
|
|
622
632
|
}));
|
|
623
633
|
}
|
|
624
634
|
}
|
|
625
635
|
k.extend(x);
|
|
626
|
-
class
|
|
636
|
+
class B extends w {
|
|
627
637
|
getDataValidations() {
|
|
628
|
-
return this._injector.get(
|
|
638
|
+
return this._injector.get(v).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
|
|
629
639
|
}
|
|
630
640
|
getValidatorStatus() {
|
|
631
641
|
return this._injector.get(l).validatorWorksheet(
|
|
@@ -634,7 +644,7 @@ class M extends v {
|
|
|
634
644
|
);
|
|
635
645
|
}
|
|
636
646
|
}
|
|
637
|
-
|
|
647
|
+
w.extend(B);
|
|
638
648
|
export {
|
|
639
649
|
m as FDataValidation,
|
|
640
650
|
h as FDataValidationBuilder
|
|
@@ -236,6 +236,7 @@ export declare class FDataValidationBuilder {
|
|
|
236
236
|
* @return The current instance of the FDataValidationBuilder class, allowing for method chaining.
|
|
237
237
|
*/
|
|
238
238
|
withCriteriaValues(type: DataValidationType | string, values: [DataValidationOperator, string, string]): this;
|
|
239
|
+
setAllowBlank(allowBlank: boolean): FDataValidationBuilder;
|
|
239
240
|
/**
|
|
240
241
|
* Sets the options for the data validation rule.
|
|
241
242
|
* For details of options, please refer to https://univer.ai/typedoc/@univerjs/core/interfaces/IDataValidationRuleOptions
|
|
@@ -67,20 +67,20 @@ export declare class FDataValidation {
|
|
|
67
67
|
* @param values An array containing the operator, formula1, and formula2 values.
|
|
68
68
|
* @returns true if the criteria is set successfully, false otherwise.
|
|
69
69
|
*/
|
|
70
|
-
setCriteria(type: DataValidationType, values: [DataValidationOperator, string, string]):
|
|
70
|
+
setCriteria(type: DataValidationType, values: [DataValidationOperator, string, string], allowBlank?: boolean): FDataValidation;
|
|
71
71
|
/**
|
|
72
72
|
* Set the options for the data validation rule.
|
|
73
73
|
* For details of options, please refer to https://univer.ai/typedoc/@univerjs/core/interfaces/IDataValidationRuleOptions
|
|
74
74
|
* @param options An object containing the options to set. `IDataValidationRuleOptions`
|
|
75
75
|
* @returns true if the options are set successfully, false otherwise.
|
|
76
76
|
*/
|
|
77
|
-
setOptions(options: Partial<IDataValidationRuleOptions>):
|
|
77
|
+
setOptions(options: Partial<IDataValidationRuleOptions>): FDataValidation;
|
|
78
78
|
/**
|
|
79
79
|
* Set the ranges to the data validation rule.
|
|
80
80
|
* @param ranges new ranges array.
|
|
81
81
|
* @returns true if the ranges are set successfully, false otherwise.
|
|
82
82
|
*/
|
|
83
|
-
setRanges(ranges: FRange[]):
|
|
83
|
+
setRanges(ranges: FRange[]): FDataValidation;
|
|
84
84
|
/**
|
|
85
85
|
* Delete the data validation rule from the worksheet.
|
|
86
86
|
* @returns true if the rule is deleted successfully, false otherwise.
|
|
@@ -7,7 +7,7 @@ export interface IFRangeDataValidationMixin {
|
|
|
7
7
|
* @param rule data validation rule, build by `FUniver.newDataValidation`
|
|
8
8
|
* @returns current range
|
|
9
9
|
*/
|
|
10
|
-
setDataValidation(this: FRange, rule: Nullable<FDataValidation>):
|
|
10
|
+
setDataValidation(this: FRange, rule: Nullable<FDataValidation>): FRange;
|
|
11
11
|
/**
|
|
12
12
|
* get first data validation rule in current range
|
|
13
13
|
* @returns data validation rule
|
|
@@ -21,7 +21,7 @@ export interface IFRangeDataValidationMixin {
|
|
|
21
21
|
getValidatorStatus(): Promise<Promise<DataValidationStatus>[][]>;
|
|
22
22
|
}
|
|
23
23
|
export declare class FRangeDataValidationMixin extends FRange implements IFRangeDataValidationMixin {
|
|
24
|
-
setDataValidation(rule: Nullable<FDataValidation>):
|
|
24
|
+
setDataValidation(rule: Nullable<FDataValidation>): FRange;
|
|
25
25
|
getDataValidation(): Nullable<FDataValidation>;
|
|
26
26
|
getDataValidations(): FDataValidation[];
|
|
27
27
|
getValidatorStatus(): Promise<Promise<DataValidationStatus>[][]>;
|
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 I=(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)=>I(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}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){return 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}})?!1:(this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,!0)}setOptions(t){return 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}})?!1:(Object.assign(this.rule,t),!0)}setRanges(t){return 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())})?!1:(this.rule.ranges=t.map(e=>e.getRange()),!0)}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{async setDataValidation(t){if(!t)return this._commandService.executeCommand(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 await this._commandService.executeCommand(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(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"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-data-validation",
|
|
3
|
-
"version": "0.5.2-nightly.
|
|
3
|
+
"version": "0.5.2-nightly.202501011606",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Data validation for Univer Sheets",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,39 +53,21 @@
|
|
|
53
53
|
"rxjs": ">=7.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@univerjs/protocol": "0.1.
|
|
57
|
-
"@univerjs/core": "0.5.2-nightly.
|
|
58
|
-
"@univerjs/engine-formula": "0.5.2-nightly.
|
|
59
|
-
"@univerjs/data-validation": "0.5.2-nightly.
|
|
60
|
-
"@univerjs/sheets-formula": "0.5.2-nightly.
|
|
61
|
-
"@univerjs/sheets": "0.5.2-nightly.
|
|
56
|
+
"@univerjs/protocol": "0.1.40",
|
|
57
|
+
"@univerjs/core": "0.5.2-nightly.202501011606",
|
|
58
|
+
"@univerjs/engine-formula": "0.5.2-nightly.202501011606",
|
|
59
|
+
"@univerjs/data-validation": "0.5.2-nightly.202501011606",
|
|
60
|
+
"@univerjs/sheets-formula": "0.5.2-nightly.202501011606",
|
|
61
|
+
"@univerjs/sheets": "0.5.2-nightly.202501011606"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"less": "^4.2.1",
|
|
65
65
|
"rxjs": "^7.8.1",
|
|
66
66
|
"typescript": "^5.7.2",
|
|
67
|
-
"vite": "^6.0.
|
|
67
|
+
"vite": "^6.0.6",
|
|
68
68
|
"vitest": "^2.1.8",
|
|
69
69
|
"@univerjs-infra/shared": "0.5.2"
|
|
70
70
|
},
|
|
71
|
-
"space": {
|
|
72
|
-
".": {
|
|
73
|
-
"import": "./lib/es/index.js",
|
|
74
|
-
"require": "./lib/cjs/index.js",
|
|
75
|
-
"types": "./lib/types/index.d.ts"
|
|
76
|
-
},
|
|
77
|
-
"./*": {
|
|
78
|
-
"import": "./lib/es/*",
|
|
79
|
-
"require": "./lib/cjs/*",
|
|
80
|
-
"types": "./lib/types/index.d.ts"
|
|
81
|
-
},
|
|
82
|
-
"./facade": {
|
|
83
|
-
"import": "./lib/es/facade.js",
|
|
84
|
-
"require": "./lib/cjs/facade.js",
|
|
85
|
-
"types": "./lib/types/facade/index.d.ts"
|
|
86
|
-
},
|
|
87
|
-
"./lib/*": "./lib/*"
|
|
88
|
-
},
|
|
89
71
|
"scripts": {
|
|
90
72
|
"dev": "vite",
|
|
91
73
|
"test": "vitest run",
|