@univerjs/sheets-data-validation 0.15.2-insiders.20260124-12fc7f0 → 0.15.3-insiders.20260131-b9b8805
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 +236 -220
- package/lib/es/index.js +4 -4
- package/lib/facade.js +236 -220
- package/lib/index.js +4 -4
- package/lib/umd/facade.js +1 -1
- package/package.json +8 -8
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var Mt = Object.defineProperty;
|
|
2
2
|
var Vt = (s, a, e) => a in s ? Mt(s, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[a] = e;
|
|
3
3
|
var m = (s, a, e) => Vt(s, typeof a != "symbol" ? a + "" : a, e);
|
|
4
|
-
import { Inject as v, ICommandService as U, IUniverInstanceService as D, Disposable as B, ObjectMatrix as Me, getIntersectRange as ot, UniverInstanceType as N, Range as H, Rectangle as w, isFormulaString as S, getOriginCellValue as yt, Injector as be, numfmt as L, DataValidationType as T, RBush as Tt, debounce as Ct, Tools as M, DataValidationStatus as A, WrapStrategy as Se, DataValidationOperator as h, dayjs as nt, DataValidationRenderMode as We, CommandType as z, IUndoRedoService as Z, sequenceExecute as Le, isRangesEqual as lt, IPermissionService as Ft, generateRandomId as Xe, toDisposable as Ke, CellValueType as Nt, RxDisposable as Ot, LifecycleService as wt, LifecycleStages as et, bufferDebounceTime as At, DependentOn as It,
|
|
4
|
+
import { Inject as v, ICommandService as U, IUniverInstanceService as D, Disposable as B, ObjectMatrix as Me, getIntersectRange as ot, UniverInstanceType as N, Range as H, Rectangle as w, isFormulaString as S, getOriginCellValue as yt, Injector as be, numfmt as L, DataValidationType as T, RBush as Tt, debounce as Ct, Tools as M, DataValidationStatus as A, WrapStrategy as Se, DataValidationOperator as h, dayjs as nt, DataValidationRenderMode as We, CommandType as z, IUndoRedoService as Z, sequenceExecute as Le, isRangesEqual as lt, IPermissionService as Ft, generateRandomId as Xe, toDisposable as Ke, CellValueType as Nt, RxDisposable as Ot, LifecycleService as wt, LifecycleStages as et, bufferDebounceTime as At, DependentOn as It, Plugin as Dt, merge as bt, IConfigService as Lt } from "@univerjs/core";
|
|
5
5
|
import { DataValidationModel as de, DataValidatorRegistryService as q, UpdateRuleType as V, BaseDataValidator as Y, TextLengthErrorTitleMap as Ut, AddDataValidationMutation as b, RemoveDataValidationMutation as I, UpdateDataValidationMutation as y, getRuleSetting as Bt, getRuleOptions as xt, UniverDataValidationPlugin as Pt } from "@univerjs/data-validation";
|
|
6
6
|
import { ERROR_TYPE_SET as Ht, RegisterOtherFormulaService as ut, OtherFormulaBizType as ct, LexerTreeBuilder as X, isReferenceString as dt, sequenceNodeType as Wt, deserializeRangeWithSheet as $t, deserializeRangeWithSheetWithCache as kt, operatorToken as jt } from "@univerjs/engine-formula";
|
|
7
7
|
import { SetRangeValuesMutation as ne, RemoveSheetMutation as ht, getSheetCommandTarget as ze, SetRangeValuesUndoMutationFactory as mt, WorksheetViewPermission as Qt, RefRangeService as Gt, handleCommonDefaultRangeChangeWithEffectRefCommands as qt, SheetInterceptorService as gt, RemoveSheetCommand as Yt, CopySheetCommand as Xt, SheetsSelectionsService as pt, ClearSelectionAllCommand as Kt } from "@univerjs/sheets";
|
|
@@ -2530,10 +2530,10 @@ var Qa = Object.defineProperty, Ga = Object.getOwnPropertyDescriptor, qa = (s, a
|
|
|
2530
2530
|
(o = s[i]) && (r = o(r) || r);
|
|
2531
2531
|
return r;
|
|
2532
2532
|
}, qe = (s, a) => (e, t) => a(e, t, s), Et = (s, a, e) => qa(s, typeof a != "symbol" ? a + "" : a, e);
|
|
2533
|
-
let De = class extends
|
|
2533
|
+
let De = class extends Dt {
|
|
2534
2534
|
constructor(s = st, a, e, t) {
|
|
2535
2535
|
super(), this._config = s, this._injector = a, this._commandService = e, this._configService = t;
|
|
2536
|
-
const { ...r } =
|
|
2536
|
+
const { ...r } = bt(
|
|
2537
2537
|
{},
|
|
2538
2538
|
st,
|
|
2539
2539
|
this._config
|
|
@@ -2580,7 +2580,7 @@ De = Ya([
|
|
|
2580
2580
|
It(Zt, Pt),
|
|
2581
2581
|
qe(1, v(be)),
|
|
2582
2582
|
qe(2, U),
|
|
2583
|
-
qe(3,
|
|
2583
|
+
qe(3, Lt)
|
|
2584
2584
|
], De);
|
|
2585
2585
|
function ir(s) {
|
|
2586
2586
|
const e = s.get(pt).getCurrentSelections().map((i) => i.range);
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/core/facade"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-data-validation","@univerjs/sheets/facade","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/core/facade","rxjs"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverSheetsDataValidationFacade={},g.UniverCore,g.UniverSheetsDataValidation,g.UniverSheetsFacade,g.UniverDataValidation,g.UniverEngineFormula,g.UniverCoreFacade,g.rxjs))})(this,(function(g,a,n,f,v,b,y,C){"use strict";var B=Object.defineProperty;var L=(g,a,n)=>a in g?B(g,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):g[a]=n;var k=(g,a,n)=>L(g,typeof a!="symbol"?a+"":a,n);class V{constructor(t){k(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new S(this._rule)}copy(){return new V({...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=`=${b.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 S{constructor(t,e,r){k(this,"rule");k(this,"_worksheet");k(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 V(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(v.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(f.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:{...v.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 U extends f.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 S(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new S(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}async getDataValidationErrorAsync(){const t=this._workbook.getUnitId(),e=this._worksheet.getSheetId();return this._collectValidationErrorsForRange(t,e,[this._range])}async _collectValidationErrorsForRange(t,e,r){if(!r.length)return[];const i=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,h=o.getName(),l=[];for(const s of r){const u=[];for(let c=s.startRow;c<=s.endRow;c++)for(let d=s.startColumn;d<=s.endColumn;d++)u.push((async()=>{var m;try{if(await i.validatorCell(t,e,c,d)!==a.DataValidationStatus.VALID){const _=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(t,e,c,d);if(_){const w=((m=o.getCell(c,d))==null?void 0:m.v)||null,I=this._createDataValidationError(h,c,d,_,w);l.push(I)}}}catch(p){console.warn(`Failed to validate cell [${c}, ${d}]:`,p)}})());await Promise.all(u)}return l}_createDataValidationError(t,e,r,i,o){return{sheetName:t,row:e,column:r,ruleId:i.uid,inputValue:o,rule:i}}}f.FRange.extend(U);class T extends y.FUniver{static newDataValidation(){return new V}newDataValidation(){return new V}_initialize(t){const e=t.get(a.ICommandService);this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>t.has(n.SheetDataValidationModel)?t.get(n.SheetDataValidationModel).ruleChange$.subscribe(i=>{const{unitId:o,subUnitId:h,rule:l,oldRule:s,type:u}=i,c=this.getSheetTarget(o,h);if(!c)return;const{workbook:d,worksheet:m}=c,p=new S(l,m.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:i,worksheet:m,workbook:d,changeType:u,oldRule:s,rule:p})}):{dispose:()=>{}}),this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>t.has(n.SheetDataValidationModel)?t.get(n.SheetDataValidationModel).validStatusChange$.subscribe(i=>{const{unitId:o,subUnitId:h,ruleId:l,status:s,row:u,col:c}=i,d=this.getSheetTarget(o,h);if(!d)return;const{workbook:m,worksheet:p}=d,D=p.getDataValidation(l);D&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:m,worksheet:p,row:u,column:c,rule:D,status:s})}):{dispose:()=>{}}),this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>e.beforeCommandExecuted(r=>{if(r.id===n.AddSheetDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s={worksheet:l,workbook:h,rule:i.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,s),s.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationSettingCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId,newCriteria:i.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationRangeCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId,newRanges:i.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationOptionsCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId,newOptions:i.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>e.beforeCommandExecuted(r=>{if(r.id===n.RemoveSheetDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,u),u.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>e.beforeCommandExecuted(r=>{if(r.id===n.RemoveSheetAllDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s={worksheet:l,workbook:h,rules:l.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,s),s.cancel)throw new a.CanceledError}}))}}y.FUniver.extend(T);class A extends f.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}async getAllDataValidationErrorAsync(){const t=this._workbook.getUnitId(),e=this._dataValidationModel.getSubUnitIds(t),r=[];for(const i of e){const o=await this._collectValidationErrorsForSheet(t,i);r.push(...o)}return r}async _collectValidationErrorsForSheet(t,e){const r=this._dataValidationModel.getRules(t,e);if(!r.length)return[];const i=r.flatMap(o=>o.ranges);return this._collectValidationErrorsForRange(t,e,i)}async _collectValidationErrorsForRange(t,e,r){if(!r.length)return[];const i=this._injector.get(n.SheetsDataValidationValidatorService),h=this._workbook.getSheetBySheetId(e);if(!h)throw new Error(`Cannot find worksheet with sheetId: ${e}`);const l=h.getName(),s=[];for(const u of r){const c=[];for(let d=u.startRow;d<=u.endRow;d++)for(let m=u.startColumn;m<=u.endColumn;m++)c.push((async()=>{var p;try{if(await i.validatorCell(t,e,d,m)!==a.DataValidationStatus.VALID){const _=this._dataValidationModel.getRuleByLocation(t,e,d,m);if(_){const w=((p=h.getCell(d,m))==null?void 0:p.v)||null,I=this._createDataValidationError(l,d,m,_,w);s.push(I)}}}catch(D){console.warn(`Failed to validate cell [${d}, ${m}]:`,D)}})());await Promise.all(c)}return s}_createDataValidationError(t,e,r,i,o){return{sheetName:t,row:e,column:r,ruleId:i.uid,inputValue:o,rule:i}}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(C.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(C.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")}}))}}f.FWorkbook.extend(A);class R extends f.FWorksheet{getDataValidations(){return this._injector.get(v.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new S(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(v.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);return r?new S(r,this._worksheet,this._injector):null}async getAllDataValidationErrorAsync(){const t=this._workbook.getUnitId(),e=this._worksheet.getSheetId();return this._collectValidationErrorsForSheet(t,e)}async _collectValidationErrorsForSheet(t,e){const i=this._injector.get(v.DataValidationModel).getRules(t,e);if(!i.length)return[];const o=i.flatMap(h=>h.ranges);return this._collectValidationErrorsForRange(t,e,o)}async _collectValidationErrorsForRange(t,e,r){if(!r.length)return[];const i=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,h=o.getName(),l=[];for(const s of r){const u=[];for(let c=s.startRow;c<=s.endRow;c++)for(let d=s.startColumn;d<=s.endColumn;d++)u.push((async()=>{var m;try{if(await i.validatorCell(t,e,c,d)!==a.DataValidationStatus.VALID){const _=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(t,e,c,d);if(_){const w=((m=o.getCell(c,d))==null?void 0:m.v)||null,I=this._createDataValidationError(h,c,d,_,w);l.push(I)}}}catch(p){console.warn(`Failed to validate cell [${c}, ${d}]:`,p)}})());await Promise.all(u)}return l}_createDataValidationError(t,e,r,i,o){return{sheetName:t,row:e,column:r,ruleId:i.uid,inputValue:o,rule:i}}}f.FWorksheet.extend(R);class O{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"}}y.FEventName.extend(O),g.FDataValidation=S,g.FDataValidationBuilder=V,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/core/facade"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-data-validation","@univerjs/sheets/facade","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/core/facade","rxjs"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverSheetsDataValidationFacade={},g.UniverCore,g.UniverSheetsDataValidation,g.UniverSheetsFacade,g.UniverDataValidation,g.UniverEngineFormula,g.UniverCoreFacade,g.rxjs))})(this,(function(g,a,n,f,v,b,y,C){"use strict";var O=Object.defineProperty;var B=(g,a,n)=>a in g?O(g,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):g[a]=n;var k=(g,a,n)=>B(g,typeof a!="symbol"?a+"":a,n);class V{constructor(t){k(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new S(this._rule)}copy(){return new V({...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=`=${b.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 S{constructor(t,e,r){k(this,"rule");k(this,"_worksheet");k(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 V(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(v.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(f.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:{...v.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 U extends f.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 S(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new S(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}async getDataValidationErrorAsync(){const t=this._workbook.getUnitId(),e=this._worksheet.getSheetId();return this._collectValidationErrorsForRange(t,e,[this._range])}async _collectValidationErrorsForRange(t,e,r){if(!r.length)return[];const i=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,h=o.getName(),l=[];for(const s of r){const u=[];for(let c=s.startRow;c<=s.endRow;c++)for(let d=s.startColumn;d<=s.endColumn;d++)u.push((async()=>{var m;try{if(await i.validatorCell(t,e,c,d)!==a.DataValidationStatus.VALID){const _=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(t,e,c,d);if(_){const w=((m=o.getCell(c,d))==null?void 0:m.v)||null,I=this._createDataValidationError(h,c,d,_,w);l.push(I)}}}catch(p){console.warn(`Failed to validate cell [${c}, ${d}]:`,p)}})());await Promise.all(u)}return l}_createDataValidationError(t,e,r,i,o){return{sheetName:t,row:e,column:r,ruleId:i.uid,inputValue:o,rule:i}}}f.FRange.extend(U);class T extends y.FUniver{static newDataValidation(){return new V}newDataValidation(){return new V}_initialize(t){const e=t.get(a.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>t.has(n.SheetDataValidationModel)?t.get(n.SheetDataValidationModel).ruleChange$.subscribe(i=>{const{unitId:o,subUnitId:h,rule:l,oldRule:s,type:u}=i,c=this.getSheetTarget(o,h);if(!c)return;const{workbook:d,worksheet:m}=c,p=new S(l,m.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:i,worksheet:m,workbook:d,changeType:u,oldRule:s,rule:p})}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>t.has(n.SheetDataValidationModel)?t.get(n.SheetDataValidationModel).validStatusChange$.subscribe(i=>{const{unitId:o,subUnitId:h,ruleId:l,status:s,row:u,col:c}=i,d=this.getSheetTarget(o,h);if(!d)return;const{workbook:m,worksheet:p}=d,D=p.getDataValidation(l);D&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:m,worksheet:p,row:u,column:c,rule:D,status:s})}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>e.beforeCommandExecuted(r=>{if(r.id===n.AddSheetDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s={worksheet:l,workbook:h,rule:i.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,s),s.cancel)throw new a.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationSettingCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId,newCriteria:i.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,u),u.cancel)throw new a.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationRangeCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId,newRanges:i.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,u),u.cancel)throw new a.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationOptionsCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId,newOptions:i.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,u),u.cancel)throw new a.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>e.beforeCommandExecuted(r=>{if(r.id===n.RemoveSheetDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,u),u.cancel)throw new a.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>e.beforeCommandExecuted(r=>{if(r.id===n.RemoveSheetAllDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s={worksheet:l,workbook:h,rules:l.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,s),s.cancel)throw new a.CanceledError}})))}}y.FUniver.extend(T);class A extends f.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}async getAllDataValidationErrorAsync(){const t=this._workbook.getUnitId(),e=this._dataValidationModel.getSubUnitIds(t),r=[];for(const i of e){const o=await this._collectValidationErrorsForSheet(t,i);r.push(...o)}return r}async _collectValidationErrorsForSheet(t,e){const r=this._dataValidationModel.getRules(t,e);if(!r.length)return[];const i=r.flatMap(o=>o.ranges);return this._collectValidationErrorsForRange(t,e,i)}async _collectValidationErrorsForRange(t,e,r){if(!r.length)return[];const i=this._injector.get(n.SheetsDataValidationValidatorService),h=this._workbook.getSheetBySheetId(e);if(!h)throw new Error(`Cannot find worksheet with sheetId: ${e}`);const l=h.getName(),s=[];for(const u of r){const c=[];for(let d=u.startRow;d<=u.endRow;d++)for(let m=u.startColumn;m<=u.endColumn;m++)c.push((async()=>{var p;try{if(await i.validatorCell(t,e,d,m)!==a.DataValidationStatus.VALID){const _=this._dataValidationModel.getRuleByLocation(t,e,d,m);if(_){const w=((p=h.getCell(d,m))==null?void 0:p.v)||null,I=this._createDataValidationError(l,d,m,_,w);s.push(I)}}}catch(D){console.warn(`Failed to validate cell [${d}, ${m}]:`,D)}})());await Promise.all(c)}return s}_createDataValidationError(t,e,r,i,o){return{sheetName:t,row:e,column:r,ruleId:i.uid,inputValue:o,rule:i}}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(C.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(C.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")}}))}}f.FWorkbook.extend(A);class R extends f.FWorksheet{getDataValidations(){return this._injector.get(v.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new S(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(v.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);return r?new S(r,this._worksheet,this._injector):null}async getAllDataValidationErrorAsync(){const t=this._workbook.getUnitId(),e=this._worksheet.getSheetId();return this._collectValidationErrorsForSheet(t,e)}async _collectValidationErrorsForSheet(t,e){const i=this._injector.get(v.DataValidationModel).getRules(t,e);if(!i.length)return[];const o=i.flatMap(h=>h.ranges);return this._collectValidationErrorsForRange(t,e,o)}async _collectValidationErrorsForRange(t,e,r){if(!r.length)return[];const i=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,h=o.getName(),l=[];for(const s of r){const u=[];for(let c=s.startRow;c<=s.endRow;c++)for(let d=s.startColumn;d<=s.endColumn;d++)u.push((async()=>{var m;try{if(await i.validatorCell(t,e,c,d)!==a.DataValidationStatus.VALID){const _=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(t,e,c,d);if(_){const w=((m=o.getCell(c,d))==null?void 0:m.v)||null,I=this._createDataValidationError(h,c,d,_,w);l.push(I)}}}catch(p){console.warn(`Failed to validate cell [${c}, ${d}]:`,p)}})());await Promise.all(u)}return l}_createDataValidationError(t,e,r,i,o){return{sheetName:t,row:e,column:r,ruleId:i.uid,inputValue:o,rule:i}}}f.FWorksheet.extend(R);class M{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"}}y.FEventName.extend(M),g.FDataValidation=S,g.FDataValidationBuilder=V,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-data-validation",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3-insiders.20260131-b9b8805",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Data validation for Univer Sheets",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -59,18 +59,18 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@univerjs/protocol": "0.1.48",
|
|
62
|
-
"@univerjs/
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/
|
|
65
|
-
"@univerjs/
|
|
66
|
-
"@univerjs/sheets-formula": "0.15.
|
|
62
|
+
"@univerjs/data-validation": "0.15.3-insiders.20260131-b9b8805",
|
|
63
|
+
"@univerjs/engine-formula": "0.15.3-insiders.20260131-b9b8805",
|
|
64
|
+
"@univerjs/sheets": "0.15.3-insiders.20260131-b9b8805",
|
|
65
|
+
"@univerjs/core": "0.15.3-insiders.20260131-b9b8805",
|
|
66
|
+
"@univerjs/sheets-formula": "0.15.3-insiders.20260131-b9b8805"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"rxjs": "^7.8.2",
|
|
70
70
|
"typescript": "^5.9.3",
|
|
71
71
|
"vite": "^7.3.1",
|
|
72
|
-
"vitest": "^4.0.
|
|
73
|
-
"@univerjs-infra/shared": "0.15.
|
|
72
|
+
"vitest": "^4.0.18",
|
|
73
|
+
"@univerjs-infra/shared": "0.15.3"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"dev": "vite",
|