@univerjs/sheets-data-validation 0.6.0-experimental.20250212-dbe9830 → 0.6.0-experimental.20250220-d9a8e74
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 +59 -58
- package/lib/types/facade/f-event.d.ts +3 -2
- package/lib/types/facade/f-univer.d.ts +3 -2
- package/lib/umd/facade.js +1 -1
- package/package.json +9 -9
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var k=Object.defineProperty;var v=(c,e,t)=>e in c?k(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var D=(c,e,t)=>v(c,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@univerjs/sheets-data-validation"),m=require("@univerjs/sheets/facade"),a=require("@univerjs/core"),S=require("@univerjs/data-validation"),w=require("@univerjs/engine-formula"),I=require("rxjs");class p{constructor(e){D(this,"_rule");this._rule=e!=null?e:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new g(this._rule)}copy(){return new p({...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(e,t){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=e,this._rule.formula2=t,this}requireDateAfter(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(e,t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(e,t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(e){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=e,this._rule.formula2=void 0,this}requireNumberBetween(e,t,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${t}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(e,t,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${t}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(e,t,r){return this._rule.type=t?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=e.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(e,t,r){return this._rule.type=t?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${w.serializeRangeToRefString({unitId:e.getUnitId(),sheetName:e.getSheetName(),range:e.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(e){return this._rule.errorStyle=e?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setAllowBlank(e){return this._rule.allowBlank=e,this}setOptions(e){return Object.assign(this._rule,e),this}}class g{constructor(e,t,r){D(this,"rule");D(this,"_worksheet");D(this,"_injector");this._injector=r,this.rule=e,this._worksheet=t}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 p(this.rule)}getApplied(){if(!this._worksheet)return!1;const t=this._injector.get(S.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(t&&t.ranges.length)}getRanges(){if(!this.getApplied())return[];const e=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(t=>this._injector.createInstance(m.FRange,e,this._worksheet,t))}getUnitId(){var e;return(e=this._worksheet)==null?void 0:e.getUnitId()}getSheetId(){var e;return(e=this._worksheet)==null?void 0:e.getSheetId()}setCriteria(e,t,r=!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:t[0],formula1:t[1],formula2:t[2],type:this.rule.type,allowBlank:r}}))throw new Error("setCriteria failed");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}setOptions(e){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...S.getRuleOptions(this.rule),...e}}))throw new Error("setOptions failed");return Object.assign(this.rule,e),this}setRanges(e){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:e.map(i=>i.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=e.map(t=>t.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 m.FRange{setDataValidation(e){if(!e)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...e.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,t),this}getDataValidation(){const t=this._injector.get(n.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return t&&new g(t,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(t=>new g(t,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}m.FRange.extend(b);class C extends a.FUniver{static newDataValidation(){return new p}newDataValidation(){return new p}_initialize(e){if(!e.has(n.SheetDataValidationModel))return;const t=e.get(n.SheetDataValidationModel),r=e.get(a.ICommandService);this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>t.ruleChange$.subscribe(i=>{const{unitId:o,subUnitId:s,rule:h,oldRule:l,type:d}=i,u=this.getSheetTarget(o,s);if(!u)return;const{workbook:f,worksheet:_}=u,V=new g(h,_.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:i,worksheet:_,workbook:f,changeType:d,oldRule:l,rule:V})})),this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>t.validStatusChange$.subscribe(i=>{const{unitId:o,subUnitId:s,ruleId:h,status:l,row:d,col:u}=i,f=this.getSheetTarget(o,s);if(!f)return;const{workbook:_,worksheet:V}=f,E=V.getDataValidation(h);E&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:_,worksheet:V,row:d,column:u,rule:E,status:l})})),this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>r.beforeCommandExecuted(i=>{if(i.id===n.AddSheetDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d={worksheet:l,workbook:h,rule:o.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,d),d.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationSettingCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const u={worksheet:l,workbook:h,rule:d,ruleId:o.ruleId,newCriteria:o.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationRangeCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const u={worksheet:l,workbook:h,rule:d,ruleId:o.ruleId,newRanges:o.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationOptionsCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const u={worksheet:l,workbook:h,rule:d,ruleId:o.ruleId,newOptions:o.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>r.beforeCommandExecuted(i=>{if(i.id===n.RemoveSheetDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const u={worksheet:l,workbook:h,rule:d,ruleId:o.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>r.beforeCommandExecuted(i=>{if(i.id===n.RemoveSheetAllDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d={worksheet:l,workbook:h,rules:l.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,d),d.cancel)throw new a.CanceledError}}))}}a.FUniver.extend(C);class T extends m.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(e){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(I.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onDataValidationStatusChange(e){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(I.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddDataValidation(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.AddSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.UpdateSheetDataValidationSettingCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.UpdateSheetDataValidationRangeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.UpdateSheetDataValidationOptionsCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.RemoveSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.RemoveSheetAllDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}m.FWorkbook.extend(T);class y extends m.FWorksheet{getDataValidations(){return this._injector.get(S.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(t=>new g(t,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getValidatorStatusAsync(){return this.getValidatorStatus()}getDataValidation(e){const r=this._injector.get(S.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);return r?new g(r,this._worksheet,this._injector):null}}m.FWorksheet.extend(y);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=g;exports.FDataValidationBuilder=p;
|
|
1
|
+
"use strict";var v=Object.defineProperty;var w=(c,e,t)=>e in c?v(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var D=(c,e,t)=>w(c,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@univerjs/sheets-data-validation"),m=require("@univerjs/sheets/facade"),a=require("@univerjs/core"),S=require("@univerjs/data-validation"),b=require("@univerjs/engine-formula"),E=require("@univerjs/core/facade"),k=require("rxjs");class p{constructor(e){D(this,"_rule");this._rule=e!=null?e:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new g(this._rule)}copy(){return new p({...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(e,t){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=e,this._rule.formula2=t,this}requireDateAfter(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(e,t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(e,t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(e){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=e,this._rule.formula2=void 0,this}requireNumberBetween(e,t,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${t}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(e,t,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${t}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(e,t,r){return this._rule.type=t?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=e.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(e,t,r){return this._rule.type=t?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${b.serializeRangeToRefString({unitId:e.getUnitId(),sheetName:e.getSheetName(),range:e.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(e){return this._rule.errorStyle=e?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setAllowBlank(e){return this._rule.allowBlank=e,this}setOptions(e){return Object.assign(this._rule,e),this}}class g{constructor(e,t,r){D(this,"rule");D(this,"_worksheet");D(this,"_injector");this._injector=r,this.rule=e,this._worksheet=t}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 p(this.rule)}getApplied(){if(!this._worksheet)return!1;const t=this._injector.get(S.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(t&&t.ranges.length)}getRanges(){if(!this.getApplied())return[];const e=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(t=>this._injector.createInstance(m.FRange,e,this._worksheet,t))}getUnitId(){var e;return(e=this._worksheet)==null?void 0:e.getUnitId()}getSheetId(){var e;return(e=this._worksheet)==null?void 0:e.getSheetId()}setCriteria(e,t,r=!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:t[0],formula1:t[1],formula2:t[2],type:this.rule.type,allowBlank:r}}))throw new Error("setCriteria failed");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}setOptions(e){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...S.getRuleOptions(this.rule),...e}}))throw new Error("setOptions failed");return Object.assign(this.rule,e),this}setRanges(e){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:e.map(i=>i.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=e.map(t=>t.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 C extends m.FRange{setDataValidation(e){if(!e)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...e.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,t),this}getDataValidation(){const t=this._injector.get(n.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return t&&new g(t,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(t=>new g(t,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}m.FRange.extend(C);class T extends E.FUniver{static newDataValidation(){return new p}newDataValidation(){return new p}_initialize(e){if(!e.has(n.SheetDataValidationModel))return;const t=e.get(n.SheetDataValidationModel),r=e.get(a.ICommandService);this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>t.ruleChange$.subscribe(i=>{const{unitId:o,subUnitId:s,rule:h,oldRule:l,type:d}=i,u=this.getSheetTarget(o,s);if(!u)return;const{workbook:f,worksheet:_}=u,V=new g(h,_.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:i,worksheet:_,workbook:f,changeType:d,oldRule:l,rule:V})})),this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>t.validStatusChange$.subscribe(i=>{const{unitId:o,subUnitId:s,ruleId:h,status:l,row:d,col:u}=i,f=this.getSheetTarget(o,s);if(!f)return;const{workbook:_,worksheet:V}=f,I=V.getDataValidation(h);I&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:_,worksheet:V,row:d,column:u,rule:I,status:l})})),this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>r.beforeCommandExecuted(i=>{if(i.id===n.AddSheetDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d={worksheet:l,workbook:h,rule:o.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,d),d.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationSettingCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const u={worksheet:l,workbook:h,rule:d,ruleId:o.ruleId,newCriteria:o.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationRangeCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const u={worksheet:l,workbook:h,rule:d,ruleId:o.ruleId,newRanges:o.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationOptionsCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const u={worksheet:l,workbook:h,rule:d,ruleId:o.ruleId,newOptions:o.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>r.beforeCommandExecuted(i=>{if(i.id===n.RemoveSheetDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const u={worksheet:l,workbook:h,rule:d,ruleId:o.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>r.beforeCommandExecuted(i=>{if(i.id===n.RemoveSheetAllDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:h,worksheet:l}=s,d={worksheet:l,workbook:h,rules:l.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,d),d.cancel)throw new a.CanceledError}}))}}E.FUniver.extend(T);class y extends m.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(e){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(k.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onDataValidationStatusChange(e){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(k.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddDataValidation(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.AddSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.UpdateSheetDataValidationSettingCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.UpdateSheetDataValidationRangeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.UpdateSheetDataValidationOptionsCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.RemoveSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.RemoveSheetAllDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}m.FWorkbook.extend(y);class U extends m.FWorksheet{getDataValidations(){return this._injector.get(S.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(t=>new g(t,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getValidatorStatusAsync(){return this.getValidatorStatus()}getDataValidation(e){const r=this._injector.get(S.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);return r?new g(r,this._worksheet,this._injector):null}}m.FWorksheet.extend(U);class A{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"}}E.FEventName.extend(A);exports.FDataValidation=g;exports.FDataValidationBuilder=p;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
var H = Object.defineProperty;
|
|
2
2
|
var j = (g, e, t) => e in g ? H(g, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : g[e] = t;
|
|
3
|
-
var
|
|
3
|
+
var _ = (g, e, t) => j(g, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import { UpdateSheetDataValidationSettingCommand as b, UpdateSheetDataValidationOptionsCommand as U, UpdateSheetDataValidationRangeCommand as C, RemoveSheetDataValidationCommand as A, ClearRangeDataValidationCommand as q, AddSheetDataValidationCommand as T, SheetsDataValidationValidatorService as S, SheetDataValidationModel as w, RemoveSheetAllDataValidationCommand as O } from "@univerjs/sheets-data-validation";
|
|
5
5
|
import { FRange as y, FWorkbook as x, FWorksheet as N } from "@univerjs/sheets/facade";
|
|
6
|
-
import { generateRandomId as L, DataValidationType as
|
|
7
|
-
import { DataValidationModel as v, getRuleOptions as
|
|
8
|
-
import { serializeRangeToRefString as
|
|
6
|
+
import { generateRandomId as L, DataValidationType as o, DataValidationErrorStyle as k, DataValidationOperator as h, IUniverInstanceService as W, ICommandService as p, CanceledError as f, toDisposable as c } from "@univerjs/core";
|
|
7
|
+
import { DataValidationModel as v, getRuleOptions as $ } from "@univerjs/data-validation";
|
|
8
|
+
import { serializeRangeToRefString as F } from "@univerjs/engine-formula";
|
|
9
|
+
import { FUniver as M, FEventName as P } from "@univerjs/core/facade";
|
|
9
10
|
import { filter as R } from "rxjs";
|
|
10
11
|
class E {
|
|
11
12
|
constructor(e) {
|
|
12
|
-
|
|
13
|
+
_(this, "_rule");
|
|
13
14
|
this._rule = e != null ? e : {
|
|
14
15
|
uid: L(),
|
|
15
16
|
ranges: void 0,
|
|
16
|
-
type:
|
|
17
|
+
type: o.CUSTOM
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
@@ -26,7 +27,7 @@ class E {
|
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
29
|
build() {
|
|
29
|
-
return new
|
|
30
|
+
return new m(this._rule);
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* Creates a duplicate of the current DataValidationBuilder object
|
|
@@ -103,7 +104,7 @@ class E {
|
|
|
103
104
|
* ```
|
|
104
105
|
*/
|
|
105
106
|
requireCheckbox(e, t) {
|
|
106
|
-
return this._rule.type =
|
|
107
|
+
return this._rule.type = o.CHECKBOX, this._rule.formula1 = e, this._rule.formula2 = t, this;
|
|
107
108
|
}
|
|
108
109
|
/**
|
|
109
110
|
* Set the data validation type to DATE and configure the validation rules to be after a specific date
|
|
@@ -116,7 +117,7 @@ class E {
|
|
|
116
117
|
* ```
|
|
117
118
|
*/
|
|
118
119
|
requireDateAfter(e) {
|
|
119
|
-
return this._rule.type =
|
|
120
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.operator = h.GREATER_THAN, this;
|
|
120
121
|
}
|
|
121
122
|
/**
|
|
122
123
|
* Set the data validation type to DATE and configure the validation rules to be before a specific date
|
|
@@ -129,7 +130,7 @@ class E {
|
|
|
129
130
|
* ```
|
|
130
131
|
*/
|
|
131
132
|
requireDateBefore(e) {
|
|
132
|
-
return this._rule.type =
|
|
133
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN, this;
|
|
133
134
|
}
|
|
134
135
|
/**
|
|
135
136
|
* Set the data validation type to DATE and configure the validation rules to be within a specific date range
|
|
@@ -145,7 +146,7 @@ class E {
|
|
|
145
146
|
* ```
|
|
146
147
|
*/
|
|
147
148
|
requireDateBetween(e, t) {
|
|
148
|
-
return this._rule.type =
|
|
149
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = h.BETWEEN, this;
|
|
149
150
|
}
|
|
150
151
|
/**
|
|
151
152
|
* Set the data validation type to DATE and configure the validation rules to be equal to a specific date
|
|
@@ -158,7 +159,7 @@ class E {
|
|
|
158
159
|
* ```
|
|
159
160
|
*/
|
|
160
161
|
requireDateEqualTo(e) {
|
|
161
|
-
return this._rule.type =
|
|
162
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.EQUAL, this;
|
|
162
163
|
}
|
|
163
164
|
/**
|
|
164
165
|
* Set the data validation type to DATE and configure the validation rules to be not within a specific date range
|
|
@@ -174,7 +175,7 @@ class E {
|
|
|
174
175
|
* ```
|
|
175
176
|
*/
|
|
176
177
|
requireDateNotBetween(e, t) {
|
|
177
|
-
return this._rule.type =
|
|
178
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = t.toLocaleDateString(), this._rule.operator = h.NOT_BETWEEN, this;
|
|
178
179
|
}
|
|
179
180
|
/**
|
|
180
181
|
* Set the data validation type to DATE and configure the validation rules to be on or after a specific date
|
|
@@ -187,7 +188,7 @@ class E {
|
|
|
187
188
|
* ```
|
|
188
189
|
*/
|
|
189
190
|
requireDateOnOrAfter(e) {
|
|
190
|
-
return this._rule.type =
|
|
191
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN_OR_EQUAL, this;
|
|
191
192
|
}
|
|
192
193
|
/**
|
|
193
194
|
* Set the data validation type to DATE and configure the validation rules to be on or before a specific date
|
|
@@ -200,7 +201,7 @@ class E {
|
|
|
200
201
|
* ```
|
|
201
202
|
*/
|
|
202
203
|
requireDateOnOrBefore(e) {
|
|
203
|
-
return this._rule.type =
|
|
204
|
+
return this._rule.type = o.DATE, this._rule.formula1 = e.toLocaleDateString(), this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN_OR_EQUAL, this;
|
|
204
205
|
}
|
|
205
206
|
/**
|
|
206
207
|
* Requires that a custom formula be satisfied
|
|
@@ -213,7 +214,7 @@ class E {
|
|
|
213
214
|
* ```
|
|
214
215
|
*/
|
|
215
216
|
requireFormulaSatisfied(e) {
|
|
216
|
-
return this._rule.type =
|
|
217
|
+
return this._rule.type = o.CUSTOM, this._rule.formula1 = e, this._rule.formula2 = void 0, this;
|
|
217
218
|
}
|
|
218
219
|
/**
|
|
219
220
|
* Requires the user to enter a number within a specific range, which can be integer or decimal
|
|
@@ -228,7 +229,7 @@ class E {
|
|
|
228
229
|
* ```
|
|
229
230
|
*/
|
|
230
231
|
requireNumberBetween(e, t, i) {
|
|
231
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = h.BETWEEN, this._rule.type = i ?
|
|
232
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = h.BETWEEN, this._rule.type = i ? o.WHOLE : o.DECIMAL, this;
|
|
232
233
|
}
|
|
233
234
|
/**
|
|
234
235
|
* Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal
|
|
@@ -242,7 +243,7 @@ class E {
|
|
|
242
243
|
* ```
|
|
243
244
|
*/
|
|
244
245
|
requireNumberEqualTo(e, t) {
|
|
245
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.EQUAL, this._rule.type = t ?
|
|
246
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
246
247
|
}
|
|
247
248
|
/**
|
|
248
249
|
* Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal
|
|
@@ -256,7 +257,7 @@ class E {
|
|
|
256
257
|
* ```
|
|
257
258
|
*/
|
|
258
259
|
requireNumberGreaterThan(e, t) {
|
|
259
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN, this._rule.type = t ?
|
|
260
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
260
261
|
}
|
|
261
262
|
/**
|
|
262
263
|
* 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
|
|
@@ -270,7 +271,7 @@ class E {
|
|
|
270
271
|
* ```
|
|
271
272
|
*/
|
|
272
273
|
requireNumberGreaterThanOrEqualTo(e, t) {
|
|
273
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN_OR_EQUAL, this._rule.type = t ?
|
|
274
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.GREATER_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
274
275
|
}
|
|
275
276
|
/**
|
|
276
277
|
* Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal
|
|
@@ -284,7 +285,7 @@ class E {
|
|
|
284
285
|
* ```
|
|
285
286
|
*/
|
|
286
287
|
requireNumberLessThan(e, t) {
|
|
287
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN, this._rule.type = t ?
|
|
288
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
288
289
|
}
|
|
289
290
|
/**
|
|
290
291
|
* Sets the data validation rule to require a number less than or equal to a specified value
|
|
@@ -299,7 +300,7 @@ class E {
|
|
|
299
300
|
* ```
|
|
300
301
|
*/
|
|
301
302
|
requireNumberLessThanOrEqualTo(e, t) {
|
|
302
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN_OR_EQUAL, this._rule.type = t ?
|
|
303
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.LESS_THAN_OR_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
303
304
|
}
|
|
304
305
|
/**
|
|
305
306
|
* Sets a data validation rule that requires the user to enter a number outside a specified range
|
|
@@ -315,7 +316,7 @@ class E {
|
|
|
315
316
|
* ```
|
|
316
317
|
*/
|
|
317
318
|
requireNumberNotBetween(e, t, i) {
|
|
318
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = h.NOT_BETWEEN, this._rule.type = i ?
|
|
319
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = `${t}`, this._rule.operator = h.NOT_BETWEEN, this._rule.type = i ? o.WHOLE : o.DECIMAL, this;
|
|
319
320
|
}
|
|
320
321
|
/**
|
|
321
322
|
* Creates a data validation rule that requires the user to enter a number that is not equal to a specific value
|
|
@@ -330,7 +331,7 @@ class E {
|
|
|
330
331
|
* ```
|
|
331
332
|
*/
|
|
332
333
|
requireNumberNotEqualTo(e, t) {
|
|
333
|
-
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.NOT_EQUAL, this._rule.type = t ?
|
|
334
|
+
return this._rule.formula1 = `${e}`, this._rule.formula2 = void 0, this._rule.operator = h.NOT_EQUAL, this._rule.type = t ? o.WHOLE : o.DECIMAL, this;
|
|
334
335
|
}
|
|
335
336
|
/**
|
|
336
337
|
* Sets a data validation rule that requires the user to enter a value from a list of specific values
|
|
@@ -346,7 +347,7 @@ class E {
|
|
|
346
347
|
* ```
|
|
347
348
|
*/
|
|
348
349
|
requireValueInList(e, t, i) {
|
|
349
|
-
return this._rule.type = t ?
|
|
350
|
+
return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = e.join(","), this._rule.formula2 = void 0, this._rule.showDropDown = i != null ? i : !0, this;
|
|
350
351
|
}
|
|
351
352
|
/**
|
|
352
353
|
* Sets a data validation rule that requires the user to enter a value within a specific range
|
|
@@ -363,7 +364,7 @@ class E {
|
|
|
363
364
|
* ```
|
|
364
365
|
*/
|
|
365
366
|
requireValueInRange(e, t, i) {
|
|
366
|
-
return this._rule.type = t ?
|
|
367
|
+
return this._rule.type = t ? o.LIST_MULTIPLE : o.LIST, this._rule.formula1 = `=${F({
|
|
367
368
|
unitId: e.getUnitId(),
|
|
368
369
|
sheetName: e.getSheetName(),
|
|
369
370
|
range: e.getRange()
|
|
@@ -415,11 +416,11 @@ class E {
|
|
|
415
416
|
return Object.assign(this._rule, e), this;
|
|
416
417
|
}
|
|
417
418
|
}
|
|
418
|
-
class
|
|
419
|
+
class m {
|
|
419
420
|
constructor(e, t, i) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
421
|
+
_(this, "rule");
|
|
422
|
+
_(this, "_worksheet");
|
|
423
|
+
_(this, "_injector");
|
|
423
424
|
this._injector = i, this.rule = e, this._worksheet = t;
|
|
424
425
|
}
|
|
425
426
|
/**
|
|
@@ -635,7 +636,7 @@ class _ {
|
|
|
635
636
|
subUnitId: this.getSheetId(),
|
|
636
637
|
ruleId: this.rule.uid,
|
|
637
638
|
options: {
|
|
638
|
-
|
|
639
|
+
...$(this.rule),
|
|
639
640
|
...e
|
|
640
641
|
}
|
|
641
642
|
}))
|
|
@@ -712,14 +713,14 @@ class G extends y {
|
|
|
712
713
|
this._worksheet.getSheetId(),
|
|
713
714
|
[this._range]
|
|
714
715
|
);
|
|
715
|
-
return t && new
|
|
716
|
+
return t && new m(t, this._worksheet, this._injector);
|
|
716
717
|
}
|
|
717
718
|
getDataValidations() {
|
|
718
719
|
return this._injector.get(S).getDataValidations(
|
|
719
720
|
this._workbook.getUnitId(),
|
|
720
721
|
this._worksheet.getSheetId(),
|
|
721
722
|
[this._range]
|
|
722
|
-
).map((t) => new
|
|
723
|
+
).map((t) => new m(t, this._worksheet, this._injector));
|
|
723
724
|
}
|
|
724
725
|
async getValidatorStatus() {
|
|
725
726
|
return this._injector.get(S).validatorRanges(
|
|
@@ -751,10 +752,10 @@ class Q extends M {
|
|
|
751
752
|
this.registerEventHandler(
|
|
752
753
|
this.Event.SheetDataValidationChanged,
|
|
753
754
|
() => t.ruleChange$.subscribe((r) => {
|
|
754
|
-
const { unitId: a, subUnitId:
|
|
755
|
+
const { unitId: a, subUnitId: n, rule: u, oldRule: l, type: s } = r, d = this.getSheetTarget(a, n);
|
|
755
756
|
if (!d)
|
|
756
757
|
return;
|
|
757
|
-
const { workbook: D, worksheet: I } = d, V = new
|
|
758
|
+
const { workbook: D, worksheet: I } = d, V = new m(u, I.getSheet(), this._injector);
|
|
758
759
|
this.fireEvent(this.Event.SheetDataValidationChanged, {
|
|
759
760
|
origin: r,
|
|
760
761
|
worksheet: I,
|
|
@@ -767,7 +768,7 @@ class Q extends M {
|
|
|
767
768
|
), this.registerEventHandler(
|
|
768
769
|
this.Event.SheetDataValidatorStatusChanged,
|
|
769
770
|
() => t.validStatusChange$.subscribe((r) => {
|
|
770
|
-
const { unitId: a, subUnitId:
|
|
771
|
+
const { unitId: a, subUnitId: n, ruleId: u, status: l, row: s, col: d } = r, D = this.getSheetTarget(a, n);
|
|
771
772
|
if (!D)
|
|
772
773
|
return;
|
|
773
774
|
const { workbook: I, worksheet: V } = D, B = V.getDataValidation(u);
|
|
@@ -784,10 +785,10 @@ class Q extends M {
|
|
|
784
785
|
this.Event.BeforeSheetDataValidationAdd,
|
|
785
786
|
() => i.beforeCommandExecuted((r) => {
|
|
786
787
|
if (r.id === T.id) {
|
|
787
|
-
const a = r.params,
|
|
788
|
-
if (!
|
|
788
|
+
const a = r.params, n = this.getSheetTarget(a.unitId, a.subUnitId);
|
|
789
|
+
if (!n)
|
|
789
790
|
return;
|
|
790
|
-
const { workbook: u, worksheet: l } =
|
|
791
|
+
const { workbook: u, worksheet: l } = n, s = {
|
|
791
792
|
worksheet: l,
|
|
792
793
|
workbook: u,
|
|
793
794
|
rule: a.rule
|
|
@@ -800,10 +801,10 @@ class Q extends M {
|
|
|
800
801
|
this.Event.BeforeSheetDataValidationCriteriaUpdate,
|
|
801
802
|
() => i.beforeCommandExecuted((r) => {
|
|
802
803
|
if (r.id === b.id) {
|
|
803
|
-
const a = r.params,
|
|
804
|
-
if (!
|
|
804
|
+
const a = r.params, n = this.getSheetTarget(a.unitId, a.subUnitId);
|
|
805
|
+
if (!n)
|
|
805
806
|
return;
|
|
806
|
-
const { workbook: u, worksheet: l } =
|
|
807
|
+
const { workbook: u, worksheet: l } = n, s = l.getDataValidation(a.ruleId);
|
|
807
808
|
if (!s)
|
|
808
809
|
return;
|
|
809
810
|
const d = {
|
|
@@ -821,10 +822,10 @@ class Q extends M {
|
|
|
821
822
|
this.Event.BeforeSheetDataValidationRangeUpdate,
|
|
822
823
|
() => i.beforeCommandExecuted((r) => {
|
|
823
824
|
if (r.id === C.id) {
|
|
824
|
-
const a = r.params,
|
|
825
|
-
if (!
|
|
825
|
+
const a = r.params, n = this.getSheetTarget(a.unitId, a.subUnitId);
|
|
826
|
+
if (!n)
|
|
826
827
|
return;
|
|
827
|
-
const { workbook: u, worksheet: l } =
|
|
828
|
+
const { workbook: u, worksheet: l } = n, s = l.getDataValidation(a.ruleId);
|
|
828
829
|
if (!s)
|
|
829
830
|
return;
|
|
830
831
|
const d = {
|
|
@@ -842,10 +843,10 @@ class Q extends M {
|
|
|
842
843
|
this.Event.BeforeSheetDataValidationOptionsUpdate,
|
|
843
844
|
() => i.beforeCommandExecuted((r) => {
|
|
844
845
|
if (r.id === U.id) {
|
|
845
|
-
const a = r.params,
|
|
846
|
-
if (!
|
|
846
|
+
const a = r.params, n = this.getSheetTarget(a.unitId, a.subUnitId);
|
|
847
|
+
if (!n)
|
|
847
848
|
return;
|
|
848
|
-
const { workbook: u, worksheet: l } =
|
|
849
|
+
const { workbook: u, worksheet: l } = n, s = l.getDataValidation(a.ruleId);
|
|
849
850
|
if (!s)
|
|
850
851
|
return;
|
|
851
852
|
const d = {
|
|
@@ -863,10 +864,10 @@ class Q extends M {
|
|
|
863
864
|
this.Event.BeforeSheetDataValidationDelete,
|
|
864
865
|
() => i.beforeCommandExecuted((r) => {
|
|
865
866
|
if (r.id === A.id) {
|
|
866
|
-
const a = r.params,
|
|
867
|
-
if (!
|
|
867
|
+
const a = r.params, n = this.getSheetTarget(a.unitId, a.subUnitId);
|
|
868
|
+
if (!n)
|
|
868
869
|
return;
|
|
869
|
-
const { workbook: u, worksheet: l } =
|
|
870
|
+
const { workbook: u, worksheet: l } = n, s = l.getDataValidation(a.ruleId);
|
|
870
871
|
if (!s)
|
|
871
872
|
return;
|
|
872
873
|
const d = {
|
|
@@ -883,10 +884,10 @@ class Q extends M {
|
|
|
883
884
|
this.Event.BeforeSheetDataValidationDeleteAll,
|
|
884
885
|
() => i.beforeCommandExecuted((r) => {
|
|
885
886
|
if (r.id === O.id) {
|
|
886
|
-
const a = r.params,
|
|
887
|
-
if (!
|
|
887
|
+
const a = r.params, n = this.getSheetTarget(a.unitId, a.subUnitId);
|
|
888
|
+
if (!n)
|
|
888
889
|
return;
|
|
889
|
-
const { workbook: u, worksheet: l } =
|
|
890
|
+
const { workbook: u, worksheet: l } = n, s = {
|
|
890
891
|
worksheet: l,
|
|
891
892
|
workbook: u,
|
|
892
893
|
rules: l.getDataValidations()
|
|
@@ -987,7 +988,7 @@ class z extends x {
|
|
|
987
988
|
x.extend(z);
|
|
988
989
|
class K extends N {
|
|
989
990
|
getDataValidations() {
|
|
990
|
-
return this._injector.get(v).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new
|
|
991
|
+
return this._injector.get(v).getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((t) => new m(t, this._worksheet, this._injector));
|
|
991
992
|
}
|
|
992
993
|
getValidatorStatus() {
|
|
993
994
|
return this._injector.get(S).validatorWorksheet(
|
|
@@ -1000,7 +1001,7 @@ class K extends N {
|
|
|
1000
1001
|
}
|
|
1001
1002
|
getDataValidation(e) {
|
|
1002
1003
|
const i = this._injector.get(v).getRuleById(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
|
|
1003
|
-
return i ? new
|
|
1004
|
+
return i ? new m(i, this._worksheet, this._injector) : null;
|
|
1004
1005
|
}
|
|
1005
1006
|
}
|
|
1006
1007
|
N.extend(K);
|
|
@@ -1030,8 +1031,8 @@ class X {
|
|
|
1030
1031
|
return "BeforeSheetDataValidationOptionsUpdate";
|
|
1031
1032
|
}
|
|
1032
1033
|
}
|
|
1033
|
-
|
|
1034
|
+
P.extend(X);
|
|
1034
1035
|
export {
|
|
1035
|
-
|
|
1036
|
+
m as FDataValidation,
|
|
1036
1037
|
E as FDataValidationBuilder
|
|
1037
1038
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { DataValidationStatus, IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions,
|
|
1
|
+
import { DataValidationStatus, IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions, IRange, ISheetDataValidationRule } from '@univerjs/core';
|
|
2
|
+
import { IEventBase } from '@univerjs/core/facade';
|
|
2
3
|
import { DataValidationChangeType, IRuleChange } from '@univerjs/data-validation';
|
|
3
4
|
import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
|
|
4
5
|
import { FDataValidation } from './f-data-validation';
|
|
@@ -272,7 +273,7 @@ export interface IDataValidationEventConfig {
|
|
|
272
273
|
BeforeSheetDataValidationRangeUpdate: IBeforeSheetDataValidationRangeUpdateEvent;
|
|
273
274
|
BeforeSheetDataValidationOptionsUpdate: IBeforeSheetDataValidationOptionsUpdateEvent;
|
|
274
275
|
}
|
|
275
|
-
declare module '@univerjs/core' {
|
|
276
|
+
declare module '@univerjs/core/facade' {
|
|
276
277
|
interface FEventName extends IDataValidationEvent {
|
|
277
278
|
}
|
|
278
279
|
interface IEventParamConfig extends IDataValidationEventParamConfig {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Injector
|
|
1
|
+
import { Injector } from '@univerjs/core';
|
|
2
|
+
import { FUniver } from '@univerjs/core/facade';
|
|
2
3
|
import { FDataValidationBuilder } from './f-data-validation-builder';
|
|
3
4
|
/**
|
|
4
5
|
* @ignore
|
|
@@ -27,7 +28,7 @@ export declare class FUnvierDataValidationMixin extends FUniver implements IFUnv
|
|
|
27
28
|
*/
|
|
28
29
|
_initialize(injector: Injector): void;
|
|
29
30
|
}
|
|
30
|
-
declare module '@univerjs/core' {
|
|
31
|
+
declare module '@univerjs/core/facade' {
|
|
31
32
|
/**
|
|
32
33
|
* @ignore
|
|
33
34
|
*/
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(u,n){typeof exports=="object"&&typeof module<"u"?n(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"],n):(u=typeof globalThis<"u"?globalThis:u||self,n(u.UniverSheetsDataValidationFacade={},u.UniverSheetsDataValidation,u.UniverSheetsFacade,u.UniverCore,u.UniverDataValidation,u.UniverEngineFormula,u.rxjs))})(this,function(u,n,g,a,D,k,v){"use strict";var b=Object.defineProperty;var A=(u,n,g)=>n in u?b(u,n,{enumerable:!0,configurable:!0,writable:!0,value:g}):u[n]=g;var S=(u,n,g)=>A(u,typeof n!="symbol"?n+"":n,g);class f{constructor(t){S(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 f({...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}setAllowBlank(t){return this._rule.allowBlank=t,this}setOptions(t){return Object.assign(this._rule,t),this}}class p{constructor(t,e,r){S(this,"rule");S(this,"_worksheet");S(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 f(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(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,r=!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: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(n.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(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(i=>i.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 w 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(w);class C extends a.FUniver{static newDataValidation(){return new f}newDataValidation(){return new f}_initialize(t){if(!t.has(n.SheetDataValidationModel))return;const e=t.get(n.SheetDataValidationModel),r=t.get(a.ICommandService);this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>e.ruleChange$.subscribe(i=>{const{unitId:o,subUnitId:s,rule:m,oldRule:l,type:d}=i,h=this.getSheetTarget(o,s);if(!h)return;const{workbook:V,worksheet:c}=h,E=new p(m,c.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:i,worksheet:c,workbook:V,changeType:d,oldRule:l,rule:E})})),this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>e.validStatusChange$.subscribe(i=>{const{unitId:o,subUnitId:s,ruleId:m,status:l,row:d,col:h}=i,V=this.getSheetTarget(o,s);if(!V)return;const{workbook:c,worksheet:E}=V,I=E.getDataValidation(m);I&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:c,worksheet:E,row:d,column:h,rule:I,status:l})})),this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>r.beforeCommandExecuted(i=>{if(i.id===n.AddSheetDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:l}=s,d={worksheet:l,workbook:m,rule:o.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,d),d.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationSettingCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:l,workbook:m,rule:d,ruleId:o.ruleId,newCriteria:o.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationRangeCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:l,workbook:m,rule:d,ruleId:o.ruleId,newRanges:o.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationOptionsCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:l,workbook:m,rule:d,ruleId:o.ruleId,newOptions:o.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>r.beforeCommandExecuted(i=>{if(i.id===n.RemoveSheetDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:l}=s,d=l.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:l,workbook:m,rule:d,ruleId:o.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>r.beforeCommandExecuted(i=>{if(i.id===n.RemoveSheetAllDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:l}=s,d={worksheet:l,workbook:m,rules:l.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,d),d.cancel)throw new a.CanceledError}}))}}a.FUniver.extend(C);class T 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(v.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(v.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.AddSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationSettingCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationRangeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationOptionsCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.RemoveSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.RemoveSheetAllDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}g.FWorkbook.extend(T);class y extends g.FWorksheet{getDataValidations(){return this._injector.get(D.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())}getValidatorStatusAsync(){return this.getValidatorStatus()}getDataValidation(t){const r=this._injector.get(D.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);return r?new p(r,this._worksheet,this._injector):null}}g.FWorksheet.extend(y);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),u.FDataValidation=p,u.FDataValidationBuilder=f,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(l,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/core/facade"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets-data-validation","@univerjs/sheets/facade","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/core/facade","rxjs"],n):(l=typeof globalThis<"u"?globalThis:l||self,n(l.UniverSheetsDataValidationFacade={},l.UniverSheetsDataValidation,l.UniverSheetsFacade,l.UniverCore,l.UniverDataValidation,l.UniverEngineFormula,l.UniverCoreFacade,l.rxjs))})(this,function(l,n,g,a,D,w,v,I){"use strict";var A=Object.defineProperty;var O=(l,n,g)=>n in l?A(l,n,{enumerable:!0,configurable:!0,writable:!0,value:g}):l[n]=g;var S=(l,n,g)=>O(l,typeof n!="symbol"?n+"":n,g);class f{constructor(e){S(this,"_rule");this._rule=e!=null?e:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new p(this._rule)}copy(){return new f({...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(e,t){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=e,this._rule.formula2=t,this}requireDateAfter(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(e,t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(e,t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(e){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=e,this._rule.formula2=void 0,this}requireNumberBetween(e,t,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${t}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(e,t,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${t}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=t?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(e,t,r){return this._rule.type=t?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=e.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(e,t,r){return this._rule.type=t?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${w.serializeRangeToRefString({unitId:e.getUnitId(),sheetName:e.getSheetName(),range:e.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(e){return this._rule.errorStyle=e?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setAllowBlank(e){return this._rule.allowBlank=e,this}setOptions(e){return Object.assign(this._rule,e),this}}class p{constructor(e,t,r){S(this,"rule");S(this,"_worksheet");S(this,"_injector");this._injector=r,this.rule=e,this._worksheet=t}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 f(this.rule)}getApplied(){if(!this._worksheet)return!1;const t=this._injector.get(D.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(t&&t.ranges.length)}getRanges(){if(!this.getApplied())return[];const e=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(t=>this._injector.createInstance(g.FRange,e,this._worksheet,t))}getUnitId(){var e;return(e=this._worksheet)==null?void 0:e.getUnitId()}getSheetId(){var e;return(e=this._worksheet)==null?void 0:e.getSheetId()}setCriteria(e,t,r=!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:t[0],formula1:t[1],formula2:t[2],type:this.rule.type,allowBlank:r}}))throw new Error("setCriteria failed");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}setOptions(e){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...D.getRuleOptions(this.rule),...e}}))throw new Error("setOptions failed");return Object.assign(this.rule,e),this}setRanges(e){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:e.map(i=>i.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=e.map(t=>t.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 C extends g.FRange{setDataValidation(e){if(!e)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...e.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,t),this}getDataValidation(){const t=this._injector.get(n.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return t&&new p(t,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(t=>new p(t,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}g.FRange.extend(C);class T extends v.FUniver{static newDataValidation(){return new f}newDataValidation(){return new f}_initialize(e){if(!e.has(n.SheetDataValidationModel))return;const t=e.get(n.SheetDataValidationModel),r=e.get(a.ICommandService);this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>t.ruleChange$.subscribe(i=>{const{unitId:o,subUnitId:s,rule:m,oldRule:u,type:d}=i,h=this.getSheetTarget(o,s);if(!h)return;const{workbook:c,worksheet:V}=h,E=new p(m,V.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:i,worksheet:V,workbook:c,changeType:d,oldRule:u,rule:E})})),this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>t.validStatusChange$.subscribe(i=>{const{unitId:o,subUnitId:s,ruleId:m,status:u,row:d,col:h}=i,c=this.getSheetTarget(o,s);if(!c)return;const{workbook:V,worksheet:E}=c,k=E.getDataValidation(m);k&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:V,worksheet:E,row:d,column:h,rule:k,status:u})})),this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>r.beforeCommandExecuted(i=>{if(i.id===n.AddSheetDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d={worksheet:u,workbook:m,rule:o.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,d),d.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationSettingCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d=u.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:u,workbook:m,rule:d,ruleId:o.ruleId,newCriteria:o.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationRangeCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d=u.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:u,workbook:m,rule:d,ruleId:o.ruleId,newRanges:o.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationOptionsCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d=u.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:u,workbook:m,rule:d,ruleId:o.ruleId,newOptions:o.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>r.beforeCommandExecuted(i=>{if(i.id===n.RemoveSheetDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d=u.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:u,workbook:m,rule:d,ruleId:o.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>r.beforeCommandExecuted(i=>{if(i.id===n.RemoveSheetAllDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d={worksheet:u,workbook:m,rules:u.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,d),d.cancel)throw new a.CanceledError}}))}}v.FUniver.extend(T);class U 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(e){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(I.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onDataValidationStatusChange(e){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(I.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddDataValidation(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.AddSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.UpdateSheetDataValidationSettingCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.UpdateSheetDataValidationRangeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.UpdateSheetDataValidationOptionsCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.RemoveSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(e){return a.toDisposable(this._commandService.beforeCommandExecuted((t,r)=>{const i=t.params;if(t.id===n.RemoveSheetAllDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}g.FWorkbook.extend(U);class y extends g.FWorksheet{getDataValidations(){return this._injector.get(D.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(t=>new p(t,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getValidatorStatusAsync(){return this.getValidatorStatus()}getDataValidation(e){const r=this._injector.get(D.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);return r?new p(r,this._worksheet,this._injector):null}}g.FWorksheet.extend(y);class b{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"}}v.FEventName.extend(b),l.FDataValidation=p,l.FDataValidationBuilder=f,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-data-validation",
|
|
3
|
-
"version": "0.6.0-experimental.
|
|
3
|
+
"version": "0.6.0-experimental.20250220-d9a8e74",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Data validation for Univer Sheets",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -54,19 +54,19 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@univerjs/protocol": "0.1.43",
|
|
57
|
-
"@univerjs/core": "0.6.0-experimental.
|
|
58
|
-
"@univerjs/data-validation": "0.6.0-experimental.
|
|
59
|
-
"@univerjs/engine-formula": "0.6.0-experimental.
|
|
60
|
-
"@univerjs/sheets": "0.6.0-experimental.
|
|
61
|
-
"@univerjs/sheets
|
|
57
|
+
"@univerjs/core": "0.6.0-experimental.20250220-d9a8e74",
|
|
58
|
+
"@univerjs/data-validation": "0.6.0-experimental.20250220-d9a8e74",
|
|
59
|
+
"@univerjs/engine-formula": "0.6.0-experimental.20250220-d9a8e74",
|
|
60
|
+
"@univerjs/sheets-formula": "0.6.0-experimental.20250220-d9a8e74",
|
|
61
|
+
"@univerjs/sheets": "0.6.0-experimental.20250220-d9a8e74"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"less": "^4.2.2",
|
|
65
65
|
"rxjs": "^7.8.1",
|
|
66
66
|
"typescript": "^5.7.3",
|
|
67
|
-
"vite": "^6.0
|
|
68
|
-
"vitest": "^3.0.
|
|
69
|
-
"@univerjs-infra/shared": "0.6.0
|
|
67
|
+
"vite": "^6.1.0",
|
|
68
|
+
"vitest": "^3.0.5",
|
|
69
|
+
"@univerjs-infra/shared": "0.6.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"dev": "vite",
|