@univerjs/sheets-data-validation 0.20.1 → 0.21.0
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 +1761 -1
- package/lib/cjs/index.js +3336 -1
- package/lib/es/facade.js +1759 -1
- package/lib/es/index.js +3258 -1
- package/lib/facade.js +1759 -1
- package/lib/index.js +3258 -1
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,3336 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/data-validation`),n=require(`@univerjs/engine-formula`),r=require(`@univerjs/sheets`),i=require(`rxjs`),a=require(`@univerjs/protocol`),o=require(`@univerjs/sheets-formula`);function s(e){"@babel/helpers - typeof";return s=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},s(e)}function c(e,t){if(s(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(s(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){var t=c(e,`string`);return s(t)==`symbol`?t:t+``}function u(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function d(e,t){return function(n,r){t(n,r,e)}}function f(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let p=class extends e.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._sheetDataValidationModel=n,u(this,`_cacheMatrix`,new Map),u(this,`_dirtyRanges$`,new i.Subject),u(this,`dirtyRanges$`,this._dirtyRanges$.asObservable()),this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{if(t.id===r.SetRangeValuesMutation.id&&!(n!=null&&n.onlyLocal)){let{cellValue:n,unitId:r,subUnitId:i}=t.params;if(n){let t=new e.ObjectMatrix(n).getDataRange();if(t.endRow===-1)return;let a=this._sheetDataValidationModel.getRules(r,i).map(e=>e.ranges).flat().map(n=>(0,e.getIntersectRange)(n,t)).filter(Boolean);a.length&&this.markRangeDirty(r,i,a,!0)}}}))}_initSheetRemove(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===r.RemoveSheetMutation.id){var t;let{unitId:n,subUnitId:r}=e.params;(t=this._cacheMatrix.get(n))==null||t.delete(r)}})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{t.type===e.UniverInstanceType.UNIVER_SHEET&&this._cacheMatrix.delete(t.getUnitId())}))}_ensureCache(t,n){let r=this._cacheMatrix.get(t);r||(r=new Map,this._cacheMatrix.set(t,r));let i=r.get(n);return i||(i=new e.ObjectMatrix,r.set(n,i)),i}ensureCache(e,t){return this._ensureCache(e,t)}addRule(e,t,n){this.markRangeDirty(e,t,n.ranges)}removeRule(e,t,n){this._deleteRange(e,t,n.ranges)}markRangeDirty(t,n,r,i){let a=this._ensureCache(t,n);r.forEach(t=>{e.Range.foreach(t,(e,t)=>{a.getValue(e,t)!==void 0&&a.setValue(e,t,void 0)})}),this._dirtyRanges$.next({unitId:t,subUnitId:n,ranges:r,isSetRange:i})}_deleteRange(t,n,r){let i=this._ensureCache(t,n);r.forEach(t=>{e.Range.foreach(t,(e,t)=>{i.realDeleteValue(e,t)})}),this._dirtyRanges$.next({unitId:t,subUnitId:n,ranges:r})}getValue(e,t,n,r){return this._ensureCache(e,t).getValue(n,r)}};p=f([d(0,(0,e.Inject)(e.ICommandService)),d(1,(0,e.Inject)(e.IUniverInstanceService)),d(2,(0,e.Inject)(t.DataValidationModel))],p);function m(e){var t;return e==null||(t=e[0])==null||(t=t[0])==null?void 0:t.v}function h(e){var t;return e==null||(t=e[0])==null?void 0:t[0]}function g(e){return!n.ERROR_TYPE_SET.has(e)}function _(e,t){var n;let r=t.getValidatorItem(e);return(n=r==null?void 0:r.offsetFormulaByRange)==null?!1:n}let v=class extends e.Disposable{constructor(e,t,n,r,i){super(),this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=n,this._dataValidationCacheService=r,this._validatorRegistryService=i,u(this,`_ruleFormulaMap`,new Map),u(this,`_ruleFormulaMap2`,new Map),this._initFormulaResultHandler(),this._initDirtyRanges()}dispose(){super.dispose(),this._ruleFormulaMap.clear(),this._ruleFormulaMap2.clear()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(t=>{for(let n in t){let r=t[n];if(this._instanceSrv.getUnitType(n)===e.UniverInstanceType.UNIVER_SHEET)for(let e in r){let t=r[e],{ruleFormulaMap:i}=this._ensureMaps(n,e);t.forEach(t=>{var r,a;let o=i.get((r=t.extra)==null?void 0:r.ruleId),s=this._dataValidationModel.getRuleById(n,e,(a=t.extra)==null?void 0:a.ruleId);s&&o&&this._dataValidationCacheService.markRangeDirty(n,e,s.ranges)})}}}))}_ensureMaps(e,t){let n=this._ruleFormulaMap.get(e),r=this._ruleFormulaMap2.get(e);n||(n=new Map,this._ruleFormulaMap.set(e,n)),r||(r=new Map,this._ruleFormulaMap2.set(e,r));let i=n.get(t);i||(i=new Map,n.set(t,i));let a=r.get(t);return a||(a=new Map,r.set(t,a)),{ruleFormulaMap:i,ruleFormulaMap2:a}}_registerFormula(e,t,r,i,a){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,i,a,{ruleId:r},n.OtherFormulaBizType.DATA_VALIDATION_CUSTOM,r)}_handleDirtyRanges(t,n,r){this._dataValidationModel.getRules(t,n).forEach(i=>{let a=i.ranges;e.Rectangle.doAnyRangesIntersect(a,r)&&this.makeRuleDirty(t,n,i.uid)})}_initDirtyRanges(){this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.subscribe(e=>{e.isSetRange&&this._handleDirtyRanges(e.unitId,e.subUnitId,e.ranges)}))}deleteByRuleId(e,t,n){let{ruleFormulaMap:r,ruleFormulaMap2:i}=this._ensureMaps(e,t),a=this._dataValidationModel.getRuleById(e,t,n),o=r.get(n);if(!a||!o)return;let s=r.get(n);s&&(r.delete(n),this._registerOtherFormulaService.deleteFormula(e,t,[s.formulaId]));let c=i.get(n);c&&(i.delete(n),this._registerOtherFormulaService.deleteFormula(e,t,[c.formulaId]))}_addFormulaByRange(t,n,r,i,a,o){let{ruleFormulaMap:s,ruleFormulaMap2:c}=this._ensureMaps(t,n),l=o[0].startRow,u=o[0].startColumn;if(i&&(0,e.isFormulaString)(i)){let e=this._registerFormula(t,n,r,i,o);s.set(r,{formula:i,originCol:u,originRow:l,formulaId:e})}if(a&&(0,e.isFormulaString)(a)){let e=this._registerFormula(t,n,r,a,o);c.set(r,{formula:a,originCol:u,originRow:l,formulaId:e})}}addRule(e,t,n){if(_(n.type,this._validatorRegistryService)){let{ranges:r,formula1:i,formula2:a,uid:o}=n;this._addFormulaByRange(e,t,o,i,a,r)}}async getCellFormulaValue(e,t,n,r,i){var a;let{ruleFormulaMap:o}=this._ensureMaps(e,t),s=o.get(n);if(!s)return Promise.resolve(void 0);let c=await this._registerOtherFormulaService.getFormulaValue(e,t,s.formulaId),{originRow:l,originCol:u}=s,d=r-l,f=i-u;return h(c==null||(a=c.result)==null||(a=a[d])==null?void 0:a[f])}async getCellFormula2Value(e,t,n,r,i){var a;let{ruleFormulaMap2:o}=this._ensureMaps(e,t),s=o.get(n);if(!s)return Promise.resolve(void 0);let c=await this._registerOtherFormulaService.getFormulaValue(e,t,s.formulaId),{originRow:l,originCol:u}=s,d=r-l,f=i-u;return h(c==null||(a=c.result)==null||(a=a[d])==null?void 0:a[f])}getCellFormulaValueSync(e,t,n,r,i){var a;let{ruleFormulaMap:o}=this._ensureMaps(e,t),s=o.get(n);if(!s)return;let c=this._registerOtherFormulaService.getFormulaValueSync(e,t,s.formulaId),{originRow:l,originCol:u}=s,d=r-l,f=i-u;return h(c==null||(a=c.result)==null||(a=a[d])==null?void 0:a[f])}getCellFormula2ValueSync(e,t,n,r,i){var a;let{ruleFormulaMap2:o}=this._ensureMaps(e,t),s=o.get(n);if(!s)return;let c=this._registerOtherFormulaService.getFormulaValueSync(e,t,s.formulaId),{originRow:l,originCol:u}=s,d=r-l,f=i-u;return h(c==null||(a=c.result)==null||(a=a[d])==null?void 0:a[f])}getRuleFormulaInfo(e,t,n){let{ruleFormulaMap:r}=this._ensureMaps(e,t);return r.get(n)}makeRuleDirty(e,t,n){var r,i;let a=(r=this._ruleFormulaMap.get(e))==null||(r=r.get(t))==null?void 0:r.get(n),o=(i=this._ruleFormulaMap2.get(e))==null||(i=i.get(t))==null?void 0:i.get(n);a&&this._registerOtherFormulaService.markFormulaDirty(e,t,a.formulaId),o&&this._registerOtherFormulaService.markFormulaDirty(e,t,o.formulaId)}};v=f([d(0,e.IUniverInstanceService),d(1,(0,e.Inject)(n.RegisterOtherFormulaService)),d(2,(0,e.Inject)(t.DataValidationModel)),d(3,(0,e.Inject)(p)),d(4,(0,e.Inject)(t.DataValidatorRegistryService))],v);function y(t){return(0,e.getOriginCellValue)(t)}function b(e){var t;return String((t=y(e))==null?``:t)}function x(e){return e.filter(Boolean).join(`,`)}function S(e){return e.split(`,`).filter(Boolean)}function ee(e){let t=y(e);return t==null?``:t.toString()}function C(t,n,r){let{formula1:i,formula2:a}=n,o=n.ranges[0].startRow,s=n.ranges[0].startColumn,c=r.row-o,l=r.col-s;return{transformedFormula1:(0,e.isFormulaString)(i)?t.moveFormulaRefOffset(i,l,c,!0):i,transformedFormula2:(0,e.isFormulaString)(a)?t.moveFormulaRefOffset(a,l,c,!0):a}}let w=class extends e.Disposable{constructor(e,t){super(),this._injector=e,this._dataValidationModel=t,u(this,`_cache`,new Map),this._initRuleChangeListener()}_initRuleChangeListener(){this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{(e.type===`remove`||e.type===`update`)&&this.markRuleDirty(e.unitId,e.subUnitId,e.rule.uid)}))}getOrCompute(e,t,n){let r=this.getCache(e,t,n.uid);if(r)return r;let i=this._injector.get(T).getRuleFormulaResultSync(e,t,n.uid);return this.computeAndCache(e,t,n,i)}_ensureCache(e,t){let n=this._cache.get(e);n||(n=new Map,this._cache.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}getCache(e,t,n){var r;return(r=this._cache.get(e))==null||(r=r.get(t))==null?void 0:r.get(n)}setCache(e,t,n,r){this._ensureCache(e,t).set(n,r)}markRuleDirty(e,t,n){var r;(r=this._cache.get(e))==null||(r=r.get(t))==null||r.delete(n)}clear(){this._cache.clear()}computeAndCache(t,n,r,i){var a;let{formula1:o=``,formula2:s=``}=r,c=(0,e.isFormulaString)(o)?this._getRuleFormulaResultSet(i==null||(a=i[0])==null||(a=a.result)==null||(a=a[0])==null?void 0:a[0]):S(o),l=s.split(`,`),u=c.map((e,t)=>({label:e,color:l[t]||``})),d={};for(let e of u)e.color&&(d[e.label]=e.color);let f={list:c,listWithColor:u,colorMap:d,set:new Set(c)};return this.setCache(t,n,r.uid,f),f}_getRuleFormulaResultSet(t){if(!t)return[];let n=new Set;for(let i=0,a=t.length;i<a;i++){let a=t[i];if(a)for(let t=0,i=a.length;t<i;t++){let i=a[t],o=y(i);if(o!=null){var r;if(typeof o!=`string`&&typeof(i==null?void 0:i.s)==`object`&&!((r=i.s)==null||(r=r.n)==null)&&r.pattern){n.add(e.numfmt.format(i.s.n.pattern,o,{throws:!1}));continue}let t=typeof o==`string`?o:String(o);g(t)&&n.add(t)}}}return[...n]}};w=f([d(0,(0,e.Inject)(e.Injector)),d(1,(0,e.Inject)(t.DataValidationModel))],w);let T=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._instanceService=e,this._registerOtherFormulaService=t,this._dataValidationCacheService=n,this._dataValidationModel=r,this._validatorRegistryService=i,this._listCacheService=a,u(this,`_formulaRuleMap`,new Map),this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(t=>{for(let n in t){let r=t[n];if(this._instanceService.getUnitType(n)===e.UniverInstanceType.UNIVER_SHEET)for(let e in r){let t=r[e],i=this._ensureRuleFormulaMap(n,e);t.forEach(t=>{var r;let a=(r=t.extra)==null?void 0:r.ruleId;if(a&&i.get(a)){let t=this._dataValidationModel.getRuleById(n,e,a);t&&(this._listCacheService.markRuleDirty(n,e,a),this._dataValidationCacheService.markRangeDirty(n,e,t.ranges))}})}}}))}_ensureRuleFormulaMap(e,t){let n=this._formulaRuleMap.get(e);n||(n=new Map,this._formulaRuleMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_registerSingleFormula(e,t,r,i){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,r,[{startColumn:0,endColumn:0,startRow:0,endRow:0}],{ruleId:i},n.OtherFormulaBizType.DATA_VALIDATION,i)}addRule(t,n,r){if(!_(r.type,this._validatorRegistryService)&&r.type!==e.DataValidationType.CHECKBOX){let{formula1:i,formula2:a,uid:o}=r,s=(0,e.isFormulaString)(i),c=(0,e.isFormulaString)(a);if(!s&&!c)return;let l=this._ensureRuleFormulaMap(t,n),u=[void 0,void 0];s&&(u[0]={id:this._registerSingleFormula(t,n,i,o),text:i}),c&&(u[1]={id:this._registerSingleFormula(t,n,a,o),text:a}),l.set(o,u)}}removeRule(e,t,n){let r=this._ensureRuleFormulaMap(e,t).get(n);if(!r)return;let[i,a]=r,o=[i==null?void 0:i.id,a==null?void 0:a.id].filter(Boolean);o.length&&this._registerOtherFormulaService.deleteFormula(e,t,o)}getRuleFormulaResult(e,t,n){let r=this._ensureRuleFormulaMap(e,t).get(n);if(!r)return Promise.resolve(null);let i=async n=>n&&this._registerOtherFormulaService.getFormulaValue(e,t,n.id);return Promise.all([i(r[0]),i(r[1])])}getRuleFormulaResultSync(e,t,n){let r=this._ensureRuleFormulaMap(e,t).get(n);if(r)return r.map(n=>{if(n)return this._registerOtherFormulaService.getFormulaValueSync(e,t,n.id)})}getRuleFormulaInfo(e,t,n){return this._ensureRuleFormulaMap(e,t).get(n)}};T=f([d(0,e.IUniverInstanceService),d(1,(0,e.Inject)(n.RegisterOtherFormulaService)),d(2,(0,e.Inject)(p)),d(3,(0,e.Inject)(t.DataValidationModel)),d(4,(0,e.Inject)(t.DataValidatorRegistryService)),d(5,(0,e.Inject)(w))],T);var te=class t{constructor(t,n,r,i,a=!1){this._unitId=n,this._subUnitId=r,this._univerInstanceService=i,this._disableTree=a,u(this,`_map`,void 0),u(this,`_tree`,new e.RBush),u(this,`_dirty`,!0),u(this,`_buildTree`,()=>{if(!this._dirty||this._disableTree)return;this._tree.clear();let e=[];this._map.forEach((t,n)=>{t.forEach(t=>{e.push({minX:t.startRow,maxX:t.endRow,minY:t.startColumn,maxY:t.endColumn,ruleId:n})})}),this._tree.load(e),this._dirty=!1}),u(this,`_debonceBuildTree`,(0,e.debounce)(this._buildTree,0)),this._map=t,this._buildTree()}get _worksheet(){var t;return(t=this._univerInstanceService.getUnit(this._unitId,e.UniverInstanceType.UNIVER_SHEET))==null?void 0:t.getSheetBySheetId(this._subUnitId)}_addRule(t,n){if(!this._worksheet)return;let r=e.Rectangle.mergeRanges(n.map(t=>e.Range.transformRange(t,this._worksheet)));this._map.forEach((t,n)=>{let i=e.Rectangle.subtractMulti(t,r);i.length===0?this._map.delete(n):this._map.set(n,i)}),this._dirty=!0,this._map.set(t,r),this._debonceBuildTree()}addRule(e){this._addRule(e.uid,e.ranges)}removeRange(t){if(!this._worksheet)return;let n=t.map(t=>e.Range.transformRange(t,this._worksheet));this._map.forEach((t,r)=>{let i=e.Rectangle.subtractMulti(t,n);i.length===0?this._map.delete(r):this._map.set(r,i)}),this._dirty=!0,this._debonceBuildTree()}_removeRule(e){this._map.delete(e),this._dirty=!0,this._debonceBuildTree()}removeRule(e){this._removeRule(e.uid)}updateRange(e,t){this._removeRule(e),this._addRule(e,t)}addRangeRules(t){t.forEach(({id:t,ranges:n})=>{if(!n.length)return;let r=this._map.get(t);r?(this._map.set(t,e.Rectangle.mergeRanges([...r,...n])),r=this._map.get(t)):(r=n,this._map.set(t,r)),this._map.forEach((r,i)=>{if(i===t)return;let a=e.Rectangle.subtractMulti(r,n);a.length===0?this._map.delete(i):this._map.set(i,a)})}),this._dirty=!0,this._debonceBuildTree()}diff(t){let n=[],r=0;return t.forEach((t,i)=>{var a;let o=(a=this._map.get(t.uid))==null?[]:a,s=t.ranges;o.length!==0&&(o.length!==s.length||o.some((t,n)=>!e.Rectangle.equals(t,s[n])))&&n.push({type:`update`,ruleId:t.uid,oldRanges:s,newRanges:e.Rectangle.sort(o),rule:t}),o.length===0&&(n.push({type:`delete`,rule:t,index:i-r}),r++)}),n}diffWithAddition(t,n){let r=[],i=0;return t.forEach((t,n)=>{var a;let o=(a=this._map.get(t.uid))==null?[]:a,s=t.ranges;o.length!==0&&(o.length!==s.length||o.some((t,n)=>!e.Rectangle.equals(t,s[n])))&&r.push({type:`update`,ruleId:t.uid,oldRanges:s,newRanges:e.Rectangle.sort(o),rule:t}),o.length===0&&(r.push({type:`delete`,rule:t,index:n-i}),i++)}),Array.from(n).forEach(t=>{var n;let i=(n=this._map.get(t.uid))==null?[]:n;r.push({type:`add`,rule:{...t,ranges:e.Rectangle.sort(i)}})}),r}clone(){return new t(new Map(e.Tools.deepClone(Array.from(this._map.entries()))),this._unitId,this._subUnitId,this._univerInstanceService,!0)}getValue(e,t){this._dirty&&this._buildTree();let n=this._tree.search({minX:e,maxX:e,minY:t,maxY:t});return n.length>0?n[0].ruleId:void 0}};let E=class extends e.Disposable{constructor(e,t,n,r,a,o,s){super(),this._dataValidationModel=e,this._univerInstanceService=t,this._dataValidatorRegistryService=n,this._dataValidationCacheService=r,this._dataValidationFormulaService=a,this._dataValidationCustomFormulaService=o,this._commandService=s,u(this,`_ruleMatrixMap`,new Map),u(this,`_validStatusChange$`,new i.Subject),u(this,`_ruleChange$`,new i.Subject),u(this,`ruleChange$`,this._ruleChange$.asObservable()),u(this,`validStatusChange$`,this._validStatusChange$.asObservable()),this._initRuleUpdateListener(),this.disposeWithMe(()=>{this._ruleChange$.complete(),this._validStatusChange$.complete()}),this._initUniverInstanceListener()}_initUniverInstanceListener(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{this._ruleMatrixMap.delete(e.getUnitId())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===r.RemoveSheetMutation.id){let{unitId:t,subUnitId:n}=e.params,r=this._ruleMatrixMap.get(t);r&&r.delete(n)}}))}_initRuleUpdateListener(){let e=this._dataValidationModel.getAll();for(let[t,n]of e)for(let[e,r]of n)for(let n of r)this._addRule(t,e,n),this._ruleChange$.next({type:`add`,unitId:t,subUnitId:e,rule:n,source:`patched`});this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{switch(e.type){case`add`:this._addRule(e.unitId,e.subUnitId,e.rule);break;case`update`:this._updateRule(e.unitId,e.subUnitId,e.rule.uid,e.oldRule,e.updatePayload);break;case`remove`:this._removeRule(e.unitId,e.subUnitId,e.rule);break}this._ruleChange$.next(e)}))}_ensureRuleMatrix(e,t){let n=this._ruleMatrixMap.get(e);n||(n=new Map,this._ruleMatrixMap.set(e,n));let r=n.get(t);return r||(r=new te(new Map,e,t,this._univerInstanceService),n.set(t,r)),r}_addRuleSideEffect(e,t,n){this._ensureRuleMatrix(e,t).addRule(n),this._dataValidationCacheService.addRule(e,t,n),this._dataValidationFormulaService.addRule(e,t,n),this._dataValidationCustomFormulaService.addRule(e,t,n)}_addRule(e,t,n){(Array.isArray(n)?n:[n]).forEach(n=>{this._addRuleSideEffect(e,t,n)})}_updateRule(e,n,r,i,a){let o=this._ensureRuleMatrix(e,n),s={...i,...a.payload};a.type===t.UpdateRuleType.RANGE?o.updateRange(r,a.payload):a.type===t.UpdateRuleType.ALL&&o.updateRange(r,a.payload.ranges),this._dataValidationCacheService.removeRule(e,n,i),this._dataValidationCacheService.addRule(e,n,s),this._dataValidationFormulaService.removeRule(e,n,i.uid),this._dataValidationFormulaService.addRule(e,n,s),this._dataValidationCustomFormulaService.deleteByRuleId(e,n,r),this._dataValidationCustomFormulaService.addRule(e,n,s)}_removeRule(e,t,n){this._ensureRuleMatrix(e,t).removeRule(n),this._dataValidationCacheService.removeRule(e,t,n),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,n.uid)}getValidator(e){return this._dataValidatorRegistryService.getValidatorItem(e)}getRuleIdByLocation(e,t,n,r){return this._ensureRuleMatrix(e,t).getValue(n,r)}getRuleByLocation(e,t,n,r){let i=this.getRuleIdByLocation(e,t,n,r);if(i)return this._dataValidationModel.getRuleById(e,t,i)}validator(t,n,r){let{col:i,row:a,unitId:o,subUnitId:s,worksheet:c}=n,l=(e,n)=>{r&&r(e,n),n&&this._validStatusChange$.next({unitId:o,subUnitId:s,ruleId:t.uid,status:e,row:a,col:i})},u=c.getCellValueOnly(a,i),d=this.getValidator(t.type),f=c.getCellRaw(a,i),p=y(f);if(d){let r=this._dataValidationCacheService.ensureCache(o,s),c=r.getValue(a,i);return c==null?(r.setValue(a,i,e.DataValidationStatus.VALIDATING),d.validator({value:p,unitId:o,subUnitId:s,row:a,column:i,worksheet:n.worksheet,workbook:n.workbook,interceptValue:y(u),t:f==null?void 0:f.t},t).then(t=>{let n=t?e.DataValidationStatus.VALID:e.DataValidationStatus.INVALID,o=r.getValue(a,i);n===e.DataValidationStatus.VALID?r.realDeleteValue(a,i):r.setValue(a,i,n),l(n,c!==o)}),e.DataValidationStatus.VALIDATING):(l(c==null?e.DataValidationStatus.VALID:c,!1),c==null?e.DataValidationStatus.VALID:c)}else return l(e.DataValidationStatus.VALID,!1),e.DataValidationStatus.VALID}getRuleObjectMatrix(e,t){return this._ensureRuleMatrix(e,t)}getRuleById(e,t,n){return this._dataValidationModel.getRuleById(e,t,n)}getRuleIndex(e,t,n){return this._dataValidationModel.getRuleIndex(e,t,n)}getRules(e,t){return[...this._dataValidationModel.getRules(e,t)]}getUnitRules(e){return this._dataValidationModel.getUnitRules(e)}deleteUnitRules(e){return this._dataValidationModel.deleteUnitRules(e)}getSubUnitIds(e){return this._dataValidationModel.getSubUnitIds(e)}getAll(){return this._dataValidationModel.getAll()}};E=f([d(0,(0,e.Inject)(t.DataValidationModel)),d(1,e.IUniverInstanceService),d(2,(0,e.Inject)(t.DataValidatorRegistryService)),d(3,(0,e.Inject)(p)),d(4,(0,e.Inject)(T)),d(5,(0,e.Inject)(v)),d(6,e.ICommandService)],E);function D(t,n){return e.Tools.isBlank(t)?n.t(`dataValidation.validFail.value`):(0,e.isFormulaString)(t)?n.t(`dataValidation.validFail.primitive`):``}const O=t=>e.Tools.isDefine(t)&&String(t).toLowerCase()===`true`?`1`:String(t).toLowerCase()===`false`?`0`:t;var ne=class extends t.BaseDataValidator{constructor(...t){super(...t),u(this,`id`,e.DataValidationType.CHECKBOX),u(this,`title`,`dataValidation.checkbox.title`),u(this,`operators`,[]),u(this,`scopes`,[`sheet`]),u(this,`order`,41),u(this,`offsetFormulaByRange`,!1),u(this,`_formulaService`,this.injector.get(T)),u(this,`skipDefaultFontRender`,(e,t,n)=>{let{unitId:r,subUnitId:i}=n,{formula1:a,formula2:o}=this.parseFormulaSync(e,r,i),s=`${t==null?``:t}`;return!s||s===`${a}`||s===`${o}`})}validatorFormula(t,n,r){let{formula1:i,formula2:a}=t,o=i===a;if(e.Tools.isBlank(i)&&e.Tools.isBlank(a))return{success:!0};if(o)return{success:!1,formula1:this.localeService.t(`dataValidation.validFail.checkboxEqual`),formula2:this.localeService.t(`dataValidation.validFail.checkboxEqual`)};let s=D(i,this.localeService),c=D(a,this.localeService);return{success:!s&&!c,formula1:s,formula2:c}}async parseFormula(t,n,r){var i,a;let{formula1:o=1,formula2:s=0}=t,c=await this._formulaService.getRuleFormulaResult(n,r,t.uid),l=(0,e.isFormulaString)(o)?m(c==null||(i=c[0])==null||(i=i.result)==null?void 0:i[0][0]):o,u=(0,e.isFormulaString)(s)?m(c==null||(a=c[1])==null||(a=a.result)==null?void 0:a[0][0]):s,d=g(String(l))&&g(String(u));return{formula1:O(l),formula2:O(u),originFormula1:l,originFormula2:u,isFormulaValid:d}}getExtraStyle(t,n){return{tb:e.WrapStrategy.CLIP}}parseFormulaSync(t,n,r){var i,a;let{formula1:o=1,formula2:s=0}=t,c=this._formulaService.getRuleFormulaResultSync(n,r,t.uid),l=(0,e.isFormulaString)(o)?m(c==null||(i=c[0])==null||(i=i.result)==null?void 0:i[0][0]):o,u=(0,e.isFormulaString)(s)?m(c==null||(a=c[1])==null||(a=a.result)==null?void 0:a[0][0]):s,d=g(String(l))&&g(String(u));return{formula1:O(l),formula2:O(u),originFormula1:l,originFormula2:u,isFormulaValid:d}}async isValidType(t,n,r){let{value:i,unitId:a,subUnitId:o}=t,{formula1:s,formula2:c,originFormula1:l,originFormula2:u}=await this.parseFormula(r,a,o);return!e.Tools.isDefine(s)||!e.Tools.isDefine(c)?!0:e.Tools.isDefine(i)&&(String(i)===String(s)||String(i)===String(c)||String(i)===String(l==null?``:l)||String(i)===String(u==null?``:u))}generateRuleErrorMessage(e){return this.localeService.t(`dataValidation.checkbox.error`)}generateRuleName(e){return this.titleStr}};const re={[e.DataValidationOperator.BETWEEN]:`dataValidation.date.operators.between`,[e.DataValidationOperator.EQUAL]:`dataValidation.date.operators.equal`,[e.DataValidationOperator.GREATER_THAN]:`dataValidation.date.operators.greaterThan`,[e.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.operators.greaterThanOrEqual`,[e.DataValidationOperator.LESS_THAN]:`dataValidation.date.operators.lessThan`,[e.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.operators.lessThanOrEqual`,[e.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.operators.notBetween`,[e.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.operators.notEqual`};e.DataValidationOperator.BETWEEN,e.DataValidationOperator.EQUAL,e.DataValidationOperator.GREATER_THAN,e.DataValidationOperator.GREATER_THAN_OR_EQUAL,e.DataValidationOperator.LESS_THAN,e.DataValidationOperator.LESS_THAN_OR_EQUAL,e.DataValidationOperator.NOT_BETWEEN,e.DataValidationOperator.NOT_EQUAL;const ie={[e.DataValidationOperator.BETWEEN]:`dataValidation.date.ruleName.between`,[e.DataValidationOperator.EQUAL]:`dataValidation.date.ruleName.equal`,[e.DataValidationOperator.GREATER_THAN]:`dataValidation.date.ruleName.greaterThan`,[e.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.ruleName.greaterThanOrEqual`,[e.DataValidationOperator.LESS_THAN]:`dataValidation.date.ruleName.lessThan`,[e.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.ruleName.lessThanOrEqual`,[e.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.ruleName.notBetween`,[e.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.ruleName.notEqual`,NONE:`dataValidation.date.ruleName.legal`},ae={[e.DataValidationOperator.BETWEEN]:`dataValidation.date.errorMsg.between`,[e.DataValidationOperator.EQUAL]:`dataValidation.date.errorMsg.equal`,[e.DataValidationOperator.GREATER_THAN]:`dataValidation.date.errorMsg.greaterThan`,[e.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.errorMsg.greaterThanOrEqual`,[e.DataValidationOperator.LESS_THAN]:`dataValidation.date.errorMsg.lessThan`,[e.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.errorMsg.lessThanOrEqual`,[e.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.errorMsg.notBetween`,[e.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.errorMsg.notEqual`,NONE:`dataValidation.date.errorMsg.legal`},k=[e.DataValidationOperator.BETWEEN,e.DataValidationOperator.NOT_BETWEEN],A=`{FORMULA1}`,j=`{FORMULA2}`,M=t=>{var n,r;if(t==null||typeof t==`boolean`)return;if(typeof t==`number`||!Number.isNaN(+t))return+t;let i=(n=e.numfmt.parseDate(t))==null?void 0:n.v;return e.Tools.isDefine(i)?i:(r=e.numfmt.parseDate((0,e.dateKit)(t).format(`YYYY-MM-DD HH:mm:ss`)))==null?void 0:r.v};var N=class extends t.BaseDataValidator{constructor(...t){super(...t),u(this,`id`,e.DataValidationType.DATE),u(this,`title`,`dataValidation.date.title`),u(this,`order`,40),u(this,`operators`,[e.DataValidationOperator.BETWEEN,e.DataValidationOperator.EQUAL,e.DataValidationOperator.GREATER_THAN,e.DataValidationOperator.GREATER_THAN_OR_EQUAL,e.DataValidationOperator.LESS_THAN,e.DataValidationOperator.LESS_THAN_OR_EQUAL,e.DataValidationOperator.NOT_BETWEEN,e.DataValidationOperator.NOT_EQUAL]),u(this,`scopes`,[`sheet`]),u(this,`_customFormulaService`,this.injector.get(v)),u(this,`_lexerTreeBuilder`,this.injector.get(n.LexerTreeBuilder))}async parseFormula(t,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,t.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,t.uid,i,a),{formula1:c,formula2:l}=t,u=g(String(o==null?void 0:o.v))&&g(String(s==null?void 0:s.v));return{formula1:M((0,e.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:M((0,e.isFormulaString)(l)?s==null?void 0:s.v:l),isFormulaValid:u}}async isValidType(t){let{interceptValue:n,value:r}=t;return typeof r==`number`&&typeof n==`string`||typeof n==`string`?!!e.numfmt.parseDate(n):!1}_validatorSingleFormula(t){return!e.Tools.isBlank(t)&&((0,e.isFormulaString)(t)||!Number.isNaN(+t)||!!(t&&e.numfmt.parseDate(t)))}validatorFormula(e,t,n){let r=e.operator;if(!r)return{success:!0};let i=this._validatorSingleFormula(e.formula1),a=this.localeService.t(`dataValidation.validFail.date`);if(k.includes(r)){let t=this._validatorSingleFormula(e.formula2);return{success:i&&t,formula1:i?void 0:a,formula2:t?void 0:a}}return{success:i,formula1:i?void 0:a}}normalizeFormula(t,n,r){let{formula1:i,formula2:a,bizInfo:o}=t,s=t=>{if(!t)return t;let n;if(!Number.isNaN(+t))n=e.numfmt.dateFromSerial(+t);else{var r;let i=(r=e.numfmt.parseDate(t))==null?void 0:r.v;if(i==null)return``;n=e.numfmt.dateFromSerial(i)}return(0,e.dateKit)(`${n[0]}/${n[1]}/${n[2]} ${n[3]}:${n[4]}:${n[5]}`).format(o!=null&&o.showTime?`YYYY-MM-DD HH:mm:ss`:`YYYY-MM-DD`)};return{formula1:(0,e.isFormulaString)(i)?i:s(`${i}`),formula2:(0,e.isFormulaString)(a)?a:s(`${a}`)}}transform(e,t,n){let{value:r}=e;return{...e,value:M(r)}}get operatorNames(){return this.operators.map(e=>this.localeService.t(re[e]))}generateRuleName(e){var t,n;if(!e.operator)return this.localeService.t(ie.NONE);let r=this.localeService.t(ie[e.operator]).replace(A,(t=e.formula1)==null?``:t).replace(j,(n=e.formula2)==null?``:n);return`${this.titleStr} ${r}`}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;let{transformedFormula1:n,transformedFormula2:r}=C(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ae[e.operator]).replace(A,n==null?``:n).replace(j,r==null?``:r)}`}};e.DataValidationOperator.BETWEEN,e.DataValidationOperator.EQUAL,e.DataValidationOperator.GREATER_THAN,e.DataValidationOperator.GREATER_THAN_OR_EQUAL,e.DataValidationOperator.LESS_THAN,e.DataValidationOperator.LESS_THAN_OR_EQUAL,e.DataValidationOperator.NOT_BETWEEN,e.DataValidationOperator.NOT_EQUAL,e.DataValidationOperator.BETWEEN,e.DataValidationOperator.EQUAL,e.DataValidationOperator.GREATER_THAN,e.DataValidationOperator.GREATER_THAN_OR_EQUAL,e.DataValidationOperator.LESS_THAN,e.DataValidationOperator.LESS_THAN_OR_EQUAL,e.DataValidationOperator.NOT_BETWEEN,e.DataValidationOperator.NOT_EQUAL;const P={[e.DataValidationOperator.BETWEEN]:`dataValidation.errorMsg.between`,[e.DataValidationOperator.EQUAL]:`dataValidation.errorMsg.equal`,[e.DataValidationOperator.GREATER_THAN]:`dataValidation.errorMsg.greaterThan`,[e.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.errorMsg.greaterThanOrEqual`,[e.DataValidationOperator.LESS_THAN]:`dataValidation.errorMsg.lessThan`,[e.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.errorMsg.lessThanOrEqual`,[e.DataValidationOperator.NOT_BETWEEN]:`dataValidation.errorMsg.notBetween`,[e.DataValidationOperator.NOT_EQUAL]:`dataValidation.errorMsg.notEqual`,NONE:`dataValidation.errorMsg.legal`};function F(e){return+e}var oe=class extends t.BaseDataValidator{constructor(...t){super(...t),u(this,`_customFormulaService`,this.injector.get(v)),u(this,`id`,e.DataValidationType.DECIMAL),u(this,`_lexerTreeBuilder`,this.injector.get(n.LexerTreeBuilder)),u(this,`title`,`dataValidation.decimal.title`),u(this,`order`,20),u(this,`operators`,[e.DataValidationOperator.BETWEEN,e.DataValidationOperator.EQUAL,e.DataValidationOperator.GREATER_THAN,e.DataValidationOperator.GREATER_THAN_OR_EQUAL,e.DataValidationOperator.LESS_THAN,e.DataValidationOperator.LESS_THAN_OR_EQUAL,e.DataValidationOperator.NOT_BETWEEN,e.DataValidationOperator.NOT_EQUAL]),u(this,`scopes`,[`sheet`])}_isFormulaOrNumber(t){return!e.Tools.isBlank(t)&&((0,e.isFormulaString)(t)||!Number.isNaN(+t))}async isValidType(e,t,n){let{value:r}=e;return!Number.isNaN(F(r))}transform(e,t,n){let{value:r}=e;return{...e,value:F(r)}}_parseNumber(e){return e==null?NaN:+e}async parseFormula(t,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,t.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,t.uid,i,a),{formula1:c,formula2:l}=t,u=g(String(o==null?void 0:o.v))&&g(String(s==null?void 0:s.v));return{formula1:this._parseNumber((0,e.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:this._parseNumber((0,e.isFormulaString)(l)?s==null?void 0:s.v:l),isFormulaValid:u}}validatorFormula(t,n,r){let i=t.operator;if(!i)return{success:!0};let a=e.Tools.isDefine(t.formula1)&&this._isFormulaOrNumber(t.formula1),o=e.Tools.isDefine(t.formula2)&&this._isFormulaOrNumber(t.formula2),s=k.includes(i),c=this.localeService.t(`dataValidation.validFail.number`);return s?{success:a&&o,formula1:a?void 0:c,formula2:o?void 0:c}:{success:a,formula1:a?``:c}}generateRuleErrorMessage(e,t){if(!e.operator)return this.localeService.t(P.NONE).replace(`{TYPE}`,this.titleStr);let{transformedFormula1:n,transformedFormula2:r}=C(this._lexerTreeBuilder,e,t);return`${this.localeService.t(P[e.operator]).replace(A,n==null?``:n).replace(j,r==null?``:r)}`}};function se(t){if(!t)return[];let n=new Set;for(let i=0,a=t.length;i<a;i++){let a=t[i];if(a)for(let t=0,i=a.length;t<i;t++){let i=a[t],o=y(i);if(o!=null){var r;if(typeof o!=`string`&&typeof(i==null?void 0:i.s)==`object`&&!((r=i.s)==null||(r=r.n)==null)&&r.pattern){n.add(e.numfmt.format(i.s.n.pattern,o,{throws:!1}));continue}let t=typeof o==`string`?o:String(o);g(t)&&n.add(t)}}}return[...n]}const ce=[`if`,`indirect`,`choose`,`offset`];function le(t,r){if(!(0,e.isFormulaString)(t)||(0,n.isReferenceString)(t.slice(1)))return!0;let i=r.sequenceNodesBuilder(t);return i&&i.some(e=>typeof e==`object`&&e.nodeType===n.sequenceNodeType.FUNCTION&&ce.indexOf(e.token.toLowerCase())>-1)}function ue(t,r){let{formula1:i=``,ranges:a}=t;if((0,n.isReferenceString)(i.slice(1))){let t=(0,n.deserializeRangeWithSheet)(i.slice(1));if((!t.sheetName||t.sheetName===r)&&a.some(n=>e.Rectangle.intersects(n,t.range)))return!0}return!1}var I=class extends t.BaseDataValidator{constructor(...t){super(...t),u(this,`formulaService`,this.injector.get(T)),u(this,`_lexer`,this.injector.get(n.LexerTreeBuilder)),u(this,`_univerInstanceService`,this.injector.get(e.IUniverInstanceService)),u(this,`_listCacheService`,this.injector.get(w)),u(this,`order`,50),u(this,`offsetFormulaByRange`,!1),u(this,`id`,e.DataValidationType.LIST),u(this,`title`,`dataValidation.list.title`),u(this,`operators`,[]),u(this,`scopes`,[`sheet`]),u(this,`skipDefaultFontRender`,t=>t.renderMode!==e.DataValidationRenderMode.TEXT)}validatorFormula(t,n,r){var i,a;let o=!e.Tools.isBlank(t.formula1),s=le((i=t.formula1)==null?``:i,this._lexer),c=(a=this._univerInstanceService.getUnit(n,e.UniverInstanceType.UNIVER_SHEET))==null||(a=a.getSheetBySheetId(r))==null?void 0:a.getName(),l=ue(t,c==null?``:c);return{success:!!(o&&s&&!l),formula1:o?s?l?this.localeService.t(`dataValidation.validFail.listIntersects`):void 0:this.localeService.t(`dataValidation.validFail.listInvalid`):this.localeService.t(`dataValidation.validFail.list`)}}getExtraStyle(t,n,{style:r}){var i;let a=(i=r.tb===e.WrapStrategy.OVERFLOW?e.WrapStrategy.CLIP:r.tb)==null?e.WrapStrategy.WRAP:i;if(t.type===e.DataValidationType.LIST&&(t.renderMode===e.DataValidationRenderMode.ARROW||t.renderMode===e.DataValidationRenderMode.TEXT)){let e=this.getListWithColorMap(t)[`${n==null?``:n}`];if(e)return{bg:{rgb:e},tb:a}}return{tb:a}}parseCellValue(e){return S(e.toString())}async parseFormula(e,t,n){var r;let i=await this.formulaService.getRuleFormulaResult(t,n,e.uid),a=m(i==null||(r=i[0])==null||(r=r.result)==null?void 0:r[0][0]);return{formula1:void 0,formula2:void 0,isFormulaValid:g(String(a))}}async isValidType(t,n,r){let{value:i,unitId:a,subUnitId:o}=t,{formula1:s=``}=r,c=(0,e.isFormulaString)(s)?this._listCacheService.getOrCompute(a,o,r).list:S(s);return this.parseCellValue(i).every(e=>c.includes(e))}generateRuleName(){return this.localeService.t(`dataValidation.list.name`)}generateRuleErrorMessage(){return this.localeService.t(`dataValidation.list.error`)}_getUnitAndSubUnit(t,n){var r,i;let a=(r=t?this._univerInstanceService.getUniverSheetInstance(t):void 0)==null?this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET):r;if(!a)return null;let o=(i=n?a.getSheetBySheetId(n):void 0)==null?a.getActiveSheet():i;return o?{unitId:a.getUnitId(),subUnitId:o.getSheetId()}:null}getList(e,t,n){let r=this._getUnitAndSubUnit(t,n);if(!r)return[];let{unitId:i,subUnitId:a}=r;return this._listCacheService.getOrCompute(i,a,e).list}async getListAsync(t,n,r){var i;let{formula1:a=``}=t,o=this._getUnitAndSubUnit(n,r);if(!o)return[];let{unitId:s,subUnitId:c}=o,l=await this.formulaService.getRuleFormulaResult(s,c,t.uid);return(0,e.isFormulaString)(a)?se(l==null||(i=l[0])==null||(i=i.result)==null?void 0:i[0][0]):S(a)}getListWithColor(e,t,n){let r=this._getUnitAndSubUnit(t,n);if(!r)return[];let{unitId:i,subUnitId:a}=r;return this._listCacheService.getOrCompute(i,a,e).listWithColor}getListWithColorMap(e,t,n){let r=this._getUnitAndSubUnit(t,n);if(!r)return{};let{unitId:i,subUnitId:a}=r;return this._listCacheService.getOrCompute(i,a,e).colorMap}},de=class extends t.BaseDataValidator{constructor(...t){super(...t),u(this,`id`,e.DataValidationType.TEXT_LENGTH),u(this,`title`,`dataValidation.textLength.title`),u(this,`_lexerTreeBuilder`,this.injector.get(n.LexerTreeBuilder)),u(this,`order`,30),u(this,`operators`,[e.DataValidationOperator.BETWEEN,e.DataValidationOperator.EQUAL,e.DataValidationOperator.GREATER_THAN,e.DataValidationOperator.GREATER_THAN_OR_EQUAL,e.DataValidationOperator.LESS_THAN,e.DataValidationOperator.LESS_THAN_OR_EQUAL,e.DataValidationOperator.NOT_BETWEEN,e.DataValidationOperator.NOT_EQUAL]),u(this,`scopes`,[`sheet`]),u(this,`_customFormulaService`,this.injector.get(v))}_isFormulaOrInt(t){return!e.Tools.isBlank(t)&&((0,e.isFormulaString)(t)||!Number.isNaN(+t)&&Number.isInteger(+t))}validatorFormula(t,n,r){let i=t.operator;if(!i)return{success:!1};let a=e.Tools.isDefine(t.formula1)&&this._isFormulaOrInt(t.formula1),o=e.Tools.isDefine(t.formula2)&&this._isFormulaOrInt(t.formula2),s=k.includes(i),c=this.localeService.t(`dataValidation.validFail.number`);return s?{success:a&&o,formula1:a?void 0:c,formula2:o?void 0:c}:{success:a,formula1:c}}_parseNumber(e){return e==null?NaN:+e}async parseFormula(t,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,t.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,t.uid,i,a),{formula1:c,formula2:l}=t,u=g(String(o==null?void 0:o.v))&&g(String(s==null?void 0:s.v));return{formula1:this._parseNumber((0,e.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:this._parseNumber((0,e.isFormulaString)(l)?s==null?void 0:s.v:l),isFormulaValid:u}}transform(e,t,n){return{...e,value:e.value.toString().length}}async isValidType(e,t,n){let{value:r}=e;return typeof r==`string`||typeof r==`number`}generateRuleErrorMessage(e,n){if(!e.operator)return this.titleStr;let{transformedFormula1:r,transformedFormula2:i}=C(this._lexerTreeBuilder,e,n);return`${this.localeService.t(t.TextLengthErrorTitleMap[e.operator]).replace(A,r==null?``:r).replace(j,i==null?``:i)}`}};function L(t){var n,r;return t?t.p?!((n=(r=t.p.body)==null?void 0:r.dataStream)==null?``:n).slice(0,-2).trim():e.Tools.isBlank(t.v):!0}function R(i,a,o,s,c=`command`,l=!0){let u=s.get(n.LexerTreeBuilder),d=s.get(t.DataValidatorRegistryService),f=[],p=[],m=s.get(E),h=(0,r.getSheetCommandTarget)(s.get(e.IUniverInstanceService),{unitId:i,subUnitId:a});if(!h)return{redoMutations:f,undoMutations:p};let{worksheet:g}=h,v=new e.ObjectMatrix,y=!1;function x(t,n){l&&t.forEach(t=>{e.Range.foreach(t,(e,t)=>{let r=g.getCellRaw(e,t),i=b(r);(L(r)||i===n)&&!(r!=null&&r.p)&&(y=!0,v.setValue(e,t,{v:n,p:null}))})})}if(o.forEach(n=>{switch(n.type){case`delete`:f.push({id:t.RemoveDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:n.rule.uid,source:c}}),p.unshift({id:t.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:n.rule,index:n.index,source:c}});break;case`update`:{if(_(n.rule.type,d)){let r=n.oldRanges[0].startRow,o=n.oldRanges[0].startColumn,s=n.newRanges[0].startRow,l=n.newRanges[0].startColumn,d=s-r,m=l-o,h=(0,e.isFormulaString)(n.rule.formula1)?u.moveFormulaRefOffset(n.rule.formula1,m,d):n.rule.formula1,g=(0,e.isFormulaString)(n.rule.formula2)?u.moveFormulaRefOffset(n.rule.formula2,m,d):n.rule.formula2;h!==n.rule.formula1||g!==n.rule.formula2||!(0,e.isRangesEqual)(n.newRanges,n.oldRanges)?(f.push({id:t.UpdateDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:n.ruleId,payload:{type:t.UpdateRuleType.ALL,payload:{formula1:h,formula2:g,ranges:n.newRanges}}}}),p.unshift({id:t.UpdateDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:n.ruleId,payload:{type:t.UpdateRuleType.ALL,payload:{formula1:n.rule.formula1,formula2:n.rule.formula2,ranges:n.oldRanges}}}})):(f.push({id:t.UpdateDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:n.ruleId,payload:{type:t.UpdateRuleType.RANGE,payload:n.newRanges},source:c}}),p.unshift({id:t.UpdateDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:n.ruleId,payload:{type:t.UpdateRuleType.RANGE,payload:n.oldRanges},source:c}}))}else f.push({id:t.UpdateDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:n.ruleId,payload:{type:t.UpdateRuleType.RANGE,payload:n.newRanges},source:c}}),p.unshift({id:t.UpdateDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:n.ruleId,payload:{type:t.UpdateRuleType.RANGE,payload:n.oldRanges},source:c}});let r=m.getRuleById(i,a,n.ruleId);if(r&&r.type===e.DataValidationType.CHECKBOX){let t=m.getValidator(e.DataValidationType.CHECKBOX).parseFormulaSync(r,i,a);x(n.newRanges,t.formula2)}break}case`add`:if(f.push({id:t.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:n.rule,source:c}}),p.unshift({id:t.RemoveDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:n.rule.uid,source:c}}),n.rule.type===e.DataValidationType.CHECKBOX){let t=m.getValidator(e.DataValidationType.CHECKBOX).parseFormulaSync(n.rule,i,a);x(n.rule.ranges,t.originFormula2)}break;default:break}}),y){let e={id:r.SetRangeValuesMutation.id,params:{unitId:i,subUnitId:a,cellValue:v.getData()}},t={id:r.SetRangeValuesMutation.id,params:(0,r.SetRangeValuesUndoMutationFactory)(s,e.params)};f.push(e),p.push(t)}return{redoMutations:f,undoMutations:p}}const z={type:e.CommandType.COMMAND,id:`sheet.command.updateDataValidationRuleRange`,handler(t,n){if(!n)return!1;let{unitId:r,subUnitId:i,ranges:a,ruleId:o}=n,s=t.get(E),c=t.get(e.ICommandService),l=t.get(e.IUndoRedoService);if(!s.getRuleById(r,i,o))return!1;let u=s.getRuleObjectMatrix(r,i).clone();u.updateRange(o,a);let{redoMutations:d,undoMutations:f}=R(r,i,u.diff(s.getRules(r,i)),t);return l.pushUndoRedo({undoMutations:f,redoMutations:d,unitID:r}),(0,e.sequenceExecute)(d,c),!0}},B={type:e.CommandType.COMMAND,id:`sheet.command.addDataValidation`,handler(n,r){if(!r)return!1;let{unitId:i,subUnitId:a,rule:o}=r,s=n.get(E),c=n.get(e.ICommandService),l=n.get(e.IUndoRedoService),u=s.getRuleObjectMatrix(i,a).clone();u.addRule(o);let d=u.diff(s.getRules(i,a)),f=s.getValidator(o.type),p={unitId:i,subUnitId:a,rule:{...o,...f==null?void 0:f.normalizeFormula(o,i,a)}},{redoMutations:m,undoMutations:h}=R(i,a,d,n);return m.push({id:t.AddDataValidationMutation.id,params:p}),h.unshift({id:t.RemoveDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:o.uid}}),l.pushUndoRedo({unitID:i,redoMutations:m,undoMutations:h}),(0,e.sequenceExecute)(m,c),!0}},V={type:e.CommandType.COMMAND,id:`sheets.command.update-data-validation-setting`,handler(n,i){if(!i)return!1;let a=n.get(e.ICommandService),o=n.get(e.IUndoRedoService),s=n.get(E),c=n.get(t.DataValidatorRegistryService),{unitId:l,subUnitId:u,ruleId:d,setting:f}=i,p=c.getValidatorItem(f.type);if(!p)return!1;let m=s.getRuleById(l,u,d);if(!m)return!1;let h={...m,...f};if(!p.validatorFormula(h,l,u).success)return!1;let g={unitId:l,subUnitId:u,ruleId:d,payload:{type:t.UpdateRuleType.SETTING,payload:{...f,...p.normalizeFormula(h,l,u)}}},_=[{id:t.UpdateDataValidationMutation.id,params:g}],v={unitId:l,subUnitId:u,ruleId:d,payload:{type:t.UpdateRuleType.SETTING,payload:(0,t.getRuleSetting)(m)}},y=[{id:t.UpdateDataValidationMutation.id,params:v}];if(f.type===e.DataValidationType.CHECKBOX){let t=m.ranges,i=(0,r.getSheetCommandTarget)(n.get(e.IUniverInstanceService),{unitId:l,subUnitId:u});if(i){let a=new e.ObjectMatrix,{worksheet:o}=i,{formula2:s=0,formula1:c=1}=m,{formula2:d=0,formula1:p=1}=f,h=!1;if(t.forEach(t=>{e.Range.foreach(t,(e,t)=>{let n=o.getCellRaw(e,t),r=b(n);(L(n)||r===String(s))&&!(n!=null&&n.p)?(a.setValue(e,t,{v:d,p:null}),h=!0):r===String(c)&&!(n!=null&&n.p)&&(a.setValue(e,t,{v:p,p:null}),h=!0)})}),h){let e={id:r.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:u,cellValue:a.getData()}},t={id:r.SetRangeValuesMutation.id,params:(0,r.SetRangeValuesUndoMutationFactory)(n,e.params)};_.push(e),y.push(t)}}}return(0,e.sequenceExecute)(_,a).result?(o.pushUndoRedo({unitID:l,redoMutations:_,undoMutations:y}),!0):!1}},H={type:e.CommandType.COMMAND,id:`sheets.command.update-data-validation-options`,handler(n,r){if(!r)return!1;let i=n.get(e.ICommandService),a=n.get(e.IUndoRedoService),o=n.get(E),{unitId:s,subUnitId:c,ruleId:l,options:u}=r,d=o.getRuleById(s,c,l);if(!d)return!1;let f={unitId:s,subUnitId:c,ruleId:l,payload:{type:t.UpdateRuleType.OPTIONS,payload:u}},p=[{id:t.UpdateDataValidationMutation.id,params:f}],m={unitId:s,subUnitId:c,ruleId:l,payload:{type:t.UpdateRuleType.OPTIONS,payload:(0,t.getRuleOptions)(d)}},h=[{id:t.UpdateDataValidationMutation.id,params:m}];return a.pushUndoRedo({unitID:s,redoMutations:p,undoMutations:h}),i.executeCommand(t.UpdateDataValidationMutation.id,f),!0}},U={type:e.CommandType.COMMAND,id:`sheets.command.clear-range-data-validation`,handler(t,n){if(!n)return!1;let{unitId:i,subUnitId:a,ranges:o}=n,s=t.get(e.ICommandService),c=(0,r.getSheetCommandTarget)(t.get(e.IUniverInstanceService),{unitId:i,subUnitId:a}),l=t.get(E);if(!c)return!1;let u=t.get(e.IUndoRedoService),d=l.getRuleObjectMatrix(i,a).clone();d.removeRange(o);let{redoMutations:f,undoMutations:p}=R(i,a,d.diff(l.getRules(i,a)),t);return u.pushUndoRedo({unitID:i,redoMutations:f,undoMutations:p}),(0,e.sequenceExecute)(f,s).result}},W={type:e.CommandType.COMMAND,id:`sheet.command.remove-all-data-validation`,handler(n,r){if(!r)return!1;let{unitId:i,subUnitId:a}=r,o=n.get(e.ICommandService),s=n.get(E),c=n.get(e.IUndoRedoService),l=[...s.getRules(i,a)],u={unitId:i,subUnitId:a,ruleId:l.map(e=>e.uid)},d=[{id:t.RemoveDataValidationMutation.id,params:u}],f=[{id:t.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:l}}];return c.pushUndoRedo({redoMutations:d,undoMutations:f,unitID:i}),o.executeCommand(t.RemoveDataValidationMutation.id,u),!0}},fe=(e,n)=>{let r=e.get(E),{unitId:i,subUnitId:a,ruleId:o,source:s}=n;if(Array.isArray(o)){let e=o.map(e=>r.getRuleById(i,a,e)).filter(Boolean);return[{id:t.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:e,source:s}}]}return[{id:t.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:{...r.getRuleById(i,a,o)},index:r.getRuleIndex(i,a,o)}}]},G={type:e.CommandType.COMMAND,id:`sheet.command.remove-data-validation-rule`,handler(n,r){if(!r)return!1;let{unitId:i,subUnitId:a,ruleId:o}=r,s=n.get(e.ICommandService),c=n.get(e.IUndoRedoService),l=n.get(E),u=[{id:t.RemoveDataValidationMutation.id,params:r}],d=[{id:t.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:{...l.getRuleById(i,a,o)},index:l.getRuleIndex(i,a,o)}}];return c.pushUndoRedo({undoMutations:d,redoMutations:u,unitID:r.unitId}),s.executeCommand(t.RemoveDataValidationMutation.id,r),!0}},K=`SHEET_DATA_VALIDATION_PLUGIN`;let q=class extends e.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._permissionService=t,this._lexerTreeBuilder=n}getFormulaRefCheck(t){let i=this._lexerTreeBuilder.sequenceNodesBuilder(t);if(!i)return!0;for(let t=0;t<i.length;t++){let s=i[t];if(typeof s==`string`)continue;let{token:c}=s,l=(0,n.deserializeRangeWithSheetWithCache)(c),u=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET),d=u.getActiveSheet(),f=u.getUnitId();if(l.sheetName){if(d=u.getSheetBySheetName(l.sheetName),!d)return!1;let e=d==null?void 0:d.getSheetId();if(!this._permissionService.getPermissionPoint(new r.WorksheetViewPermission(f,e).id))return!1}if(!d)return!1;let{startRow:p,endRow:m,startColumn:h,endColumn:g}=l.range;for(let e=p;e<=m;e++)for(let t=h;t<=g;t++){var o;let n=(o=d.getCell(e,t))==null||(o=o.selectionProtection)==null?void 0:o[0];if((n==null?void 0:n[a.UnitAction.View])===!1)return!1}}return!0}};q=f([d(0,e.IUniverInstanceService),d(1,e.IPermissionService),d(2,(0,e.Inject)(n.LexerTreeBuilder))],q);var pe=`@univerjs/sheets-data-validation`,me=`0.20.1`;const he=`sheets-data-validation.config`;Symbol(he);const ge={};let J=class extends e.Disposable{constructor(e,t,n){super(),this._dataValidationModel=e,this._formulaRefRangeService=t,this._validatorRegistryService=n,u(this,`_disposableMap`,new Map),u(this,`registerRule`,(e,t,n)=>{_(n.type,this._validatorRegistryService)&&this.register(e,t,n)}),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}_${t}_${n}`}register(n,r,i){let a=i.ranges,o=i.formula1,s=i.formula2,c=this._formulaRefRangeService.registerRangeFormula(n,r,a,[o==null?``:o,s==null?``:s],c=>{if(c.length===0)return{undos:[{id:t.AddDataValidationMutation.id,params:{unitId:n,subUnitId:r,rule:i,source:`patched`}}],redos:[{id:t.RemoveDataValidationMutation.id,params:{unitId:n,subUnitId:r,ruleId:i.uid,source:`patched`}}]};let l=[],u=[],d=c[0];l.push({id:t.UpdateDataValidationMutation.id,params:{unitId:n,subUnitId:r,ruleId:i.uid,payload:{type:t.UpdateRuleType.ALL,payload:{ranges:d.ranges,formula1:d.formulas[0],formula2:d.formulas[1]}},source:`patched`}}),u.push({id:t.UpdateDataValidationMutation.id,params:{unitId:n,subUnitId:r,ruleId:i.uid,payload:{type:t.UpdateRuleType.ALL,payload:{ranges:a,formula1:o,formula2:s}},source:`patched`}});for(let a=1;a<c.length;a++){let o=c[a],s=(0,e.generateRandomId)();l.push({id:t.AddDataValidationMutation.id,params:{unitId:n,subUnitId:r,rule:{...i,uid:s,formula1:o.formulas[0],formula2:o.formulas[1],ranges:o.ranges},source:`patched`}}),u.push({id:t.RemoveDataValidationMutation.id,params:{unitId:n,subUnitId:r,ruleId:s,source:`patched`}})}return{undos:u,redos:l}}),l=this._getIdWithUnitId(n,r,i.uid);this._disposableMap.set(l,c)}_initRefRange(){let t=this._dataValidationModel.getAll();for(let[e,n]of t)for(let[t,r]of n)for(let n of r)this.registerRule(e,t,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{let{unitId:t,subUnitId:n,rule:r}=e;switch(e.type){case`add`:{let t=e.rule;this.registerRule(e.unitId,e.subUnitId,t);break}case`remove`:{let e=this._disposableMap.get(this._getIdWithUnitId(t,n,r.uid));e&&e.dispose();break}case`update`:{let r=e.rule,i=this._disposableMap.get(this._getIdWithUnitId(t,n,r.uid));i&&i.dispose(),this.registerRule(e.unitId,e.subUnitId,r);break}}})),this.disposeWithMe((0,e.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};J=f([d(0,(0,e.Inject)(E)),d(1,(0,e.Inject)(o.FormulaRefRangeService)),d(2,(0,e.Inject)(t.DataValidatorRegistryService))],J);let Y=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._dataValidationModel=e,this._injector=t,this._refRangeService=n,this._dataValidationFormulaService=r,this._formulaRefRangeService=i,this._validatorRegistryService=a,u(this,`_disposableMap`,new Map),u(this,`registerRule`,(e,t,n)=>{_(n.type,this._validatorRegistryService)||(this.register(e,t,n),this.registerFormula(e,t,n))}),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}_${t}_${n}`}registerFormula(e,n,r){var i;let a=r.uid,o=this._getIdWithUnitId(e,n,a),s=(i=this._disposableMap.get(o))==null?new Set:i,c=(i,o)=>{let s=this._dataValidationModel.getRuleById(e,n,a);if(!s)return{redos:[],undos:[]};let c=s[i];if(!c||c===o)return{redos:[],undos:[]};let l={unitId:e,subUnitId:n,ruleId:r.uid,payload:{type:t.UpdateRuleType.SETTING,payload:{type:s.type,formula1:s.formula1,formula2:s.formula2,[i]:o}},source:`patched`},u={unitId:e,subUnitId:n,ruleId:r.uid,payload:{type:t.UpdateRuleType.SETTING,payload:{type:s.type,formula1:s.formula1,formula2:s.formula2}},source:`patched`};return{redos:[{id:t.UpdateDataValidationMutation.id,params:l}],undos:[{id:t.UpdateDataValidationMutation.id,params:u}]}},l=this._dataValidationFormulaService.getRuleFormulaInfo(e,n,a);if(l){let[t,r]=l;if(t){let r=this._formulaRefRangeService.registerFormula(e,n,t.text,e=>c(`formula1`,e));s.add(()=>r.dispose())}if(r){let t=this._formulaRefRangeService.registerFormula(e,n,r.text,e=>c(`formula2`,e));s.add(()=>t.dispose())}}}register(n,i,a){var o;let s=o=>{let s=[...a.ranges],c=s.map(e=>(0,r.handleCommonDefaultRangeChangeWithEffectRefCommands)(e,o)).filter(e=>!!e).flat();if((0,e.isRangesEqual)(c,s))return{redos:[],undos:[]};if(c.length){let e={unitId:n,subUnitId:i,ruleId:a.uid,payload:{type:t.UpdateRuleType.RANGE,payload:c},source:`patched`};return{redos:[{id:t.UpdateDataValidationMutation.id,params:e}],undos:[{id:t.UpdateDataValidationMutation.id,params:{unitId:n,subUnitId:i,ruleId:a.uid,payload:{type:t.UpdateRuleType.RANGE,payload:s},source:`patched`}}]}}else{let e={unitId:n,subUnitId:i,ruleId:a.uid};return{redos:[{id:t.RemoveDataValidationMutation.id,params:e}],undos:fe(this._injector,e)}}},c=[];a.ranges.forEach(e=>{let t=this._refRangeService.registerRefRange(e,s,n,i);c.push(()=>t.dispose())});let l=this._getIdWithUnitId(n,i,a.uid),u=(o=this._disposableMap.get(l))==null?new Set:o;u.add(()=>c.forEach(e=>e())),this._disposableMap.set(l,u)}_initRefRange(){let t=this._dataValidationModel.getAll();for(let[e,n]of t)for(let[t,r]of n)for(let n of r)this.registerRule(e,t,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{let{unitId:t,subUnitId:n,rule:r}=e;switch(e.type){case`add`:{let t=e.rule;this.registerRule(e.unitId,e.subUnitId,t);break}case`remove`:{let e=this._disposableMap.get(this._getIdWithUnitId(t,n,r.uid));e&&e.forEach(e=>e());break}case`update`:{let r=e.rule,i=this._disposableMap.get(this._getIdWithUnitId(t,n,r.uid));i&&i.forEach(e=>e()),this.registerRule(e.unitId,e.subUnitId,r);break}}})),this.disposeWithMe((0,e.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.forEach(e=>e())}),this._disposableMap.clear()}))}};Y=f([d(0,(0,e.Inject)(E)),d(1,(0,e.Inject)(e.Injector)),d(2,(0,e.Inject)(r.RefRangeService)),d(3,(0,e.Inject)(T)),d(4,(0,e.Inject)(o.FormulaRefRangeService)),d(5,(0,e.Inject)(t.DataValidatorRegistryService))],Y);let X=class extends e.Disposable{constructor(e,t,n){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._sheetDataValidationModel=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>{if(n.id===r.RemoveSheetCommand.id){var i;let r=n.params,a=r.unitId||this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=this._univerInstanceService.getUniverSheetInstance(a);if(!o)return{redos:[],undos:[]};let s=r.subUnitId||((i=o.getActiveSheet())==null?void 0:i.getSheetId());if(!s)return{redos:[],undos:[]};let c=this._sheetDataValidationModel.getRules(a,s);if(c.length===0)return{redos:[],undos:[]};let l={unitId:a,subUnitId:s,ruleId:c.map(e=>e.uid),source:`patched`},u={unitId:a,subUnitId:s,rule:[...c],source:`patched`};return{redos:[{id:t.RemoveDataValidationMutation.id,params:l}],undos:[{id:t.AddDataValidationMutation.id,params:u}]}}else if(n.id===r.CopySheetCommand.id){let{unitId:r,subUnitId:i,targetSubUnitId:a}=n.params;if(!r||!i||!a)return{redos:[],undos:[]};let o=this._sheetDataValidationModel.getRules(r,i);if(o.length===0)return{redos:[],undos:[]};let s=o.map(t=>({...t,uid:(0,e.generateRandomId)(6)}));return{redos:[{id:t.AddDataValidationMutation.id,params:{unitId:r,subUnitId:a,rule:s,source:`patched`}}],undos:[{id:t.RemoveDataValidationMutation.id,params:{unitId:r,subUnitId:a,ruleId:s.map(e=>e.uid),source:`patched`}}]}}return{redos:[],undos:[]}}}))}};X=f([d(0,(0,e.Inject)(r.SheetInterceptorService)),d(1,(0,e.Inject)(e.IUniverInstanceService)),d(2,(0,e.Inject)(E))],X);var _e=class extends t.BaseDataValidator{constructor(...t){super(...t),u(this,`id`,e.DataValidationType.ANY),u(this,`title`,`dataValidation.any.title`),u(this,`operators`,[]),u(this,`scopes`,[`sheet`]),u(this,`order`,0),u(this,`offsetFormulaByRange`,!1)}async parseFormula(e,t,n){return{formula1:e.formula1,formula2:e.formula2,isFormulaValid:!0}}validatorFormula(e,t,n){return{success:!0}}async isValidType(e,t,n){return!0}generateRuleErrorMessage(e){return this.localeService.t(`dataValidation.any.error`)}},ve=class extends t.BaseDataValidator{constructor(...t){super(...t),u(this,`id`,e.DataValidationType.CUSTOM),u(this,`title`,`dataValidation.custom.title`),u(this,`operators`,[]),u(this,`scopes`,[`sheet`]),u(this,`order`,60),u(this,`_customFormulaService`,this.injector.get(v)),u(this,`_lexerTreeBuilder`,this.injector.get(n.LexerTreeBuilder))}validatorFormula(t,r,i){var a;let o=(0,e.isFormulaString)(t.formula1),s=(a=t.formula1)==null?``:a,c=this._lexerTreeBuilder.checkIfAddBracket(s)===0&&s.startsWith(n.operatorToken.EQUALS);return{success:o&&c,formula1:o&&c?``:this.localeService.t(`dataValidation.validFail.formula`)}}async parseFormula(e,t,n){return{formula1:void 0,formula2:void 0,isFormulaValid:!0}}async isValidType(t,n,r){let{column:i,row:a,unitId:o,subUnitId:s}=t,c=await this._customFormulaService.getCellFormulaValue(o,s,r.uid,a,i),l=c==null?void 0:c.v;return g(String(l))&&e.Tools.isDefine(l)&&l!==``?c.t===e.CellValueType.BOOLEAN?!!l:typeof l==`boolean`?l:typeof l==`number`?!!l:typeof l==`string`?g(l):!!l:!1}generateRuleErrorMessage(e){return this.localeService.t(`dataValidation.custom.error`)}generateRuleName(e){var t;return this.localeService.t(`dataValidation.custom.ruleName`).replace(`{FORMULA1}`,(t=e.formula1)==null?``:t)}},ye=class extends I{constructor(...t){super(...t),u(this,`id`,e.DataValidationType.LIST_MULTIPLE),u(this,`title`,`dataValidation.listMultiple.title`),u(this,`offsetFormulaByRange`,!1),u(this,`skipDefaultFontRender`,()=>!0)}},be=class extends t.BaseDataValidator{constructor(...t){super(...t),u(this,`_customFormulaService`,this.injector.get(v)),u(this,`_lexerTreeBuilder`,this.injector.get(n.LexerTreeBuilder)),u(this,`id`,e.DataValidationType.WHOLE),u(this,`title`,`dataValidation.whole.title`),u(this,`order`,10),u(this,`operators`,[e.DataValidationOperator.BETWEEN,e.DataValidationOperator.EQUAL,e.DataValidationOperator.GREATER_THAN,e.DataValidationOperator.GREATER_THAN_OR_EQUAL,e.DataValidationOperator.LESS_THAN,e.DataValidationOperator.LESS_THAN_OR_EQUAL,e.DataValidationOperator.NOT_BETWEEN,e.DataValidationOperator.NOT_EQUAL]),u(this,`scopes`,[`sheet`])}_isFormulaOrInt(t){return!e.Tools.isBlank(t)&&((0,e.isFormulaString)(t)||!Number.isNaN(+t)&&Number.isInteger(+t))}async isValidType(e,t,n){let{value:r}=e,i=F(r);return!Number.isNaN(i)&&Number.isInteger(i)}transform(e,t,n){let{value:r}=e;return{...e,value:F(r)}}_parseNumber(e){return e==null?NaN:+e}async parseFormula(t,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,t.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,t.uid,i,a),{formula1:c,formula2:l}=t,u=(0,e.isFormulaString)(c)?o==null?void 0:o.v:c,d=(0,e.isFormulaString)(l)?s==null?void 0:s.v:l,f=g(`${u}`)&&g(`${d}`);return{formula1:this._parseNumber(u),formula2:this._parseNumber(d),isFormulaValid:f}}validatorFormula(t,n,r){let i=t.operator;if(!i)return{success:!0};let a=e.Tools.isDefine(t.formula1)&&this._isFormulaOrInt(t.formula1),o=e.Tools.isDefine(t.formula2)&&this._isFormulaOrInt(t.formula2),s=k.includes(i),c=this.localeService.t(`dataValidation.validFail.number`);return s?{success:a&&o,formula1:a?void 0:c,formula2:o?void 0:c}:{success:a,formula1:c}}generateRuleErrorMessage(e,t){if(!e.operator)return this.localeService.t(P.NONE).replace(`{TYPE}`,this.titleStr);let{transformedFormula1:n,transformedFormula2:r}=C(this._lexerTreeBuilder,e,t);return`${this.localeService.t(P[e.operator]).replace(A,n==null?``:n).replace(j,r==null?``:r)}`}};let Z=class extends e.RxDisposable{constructor(e,t,n,r,i,a){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._injector=n,this._selectionManagerService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._init()}_init(){this._registerValidators(),this._initCommandInterceptor()}_registerValidators(){[_e,oe,be,de,N,ne,I,ye,ve].forEach(t=>{let n=this._injector.createInstance(t);this.disposeWithMe(this._dataValidatorRegistryService.register(n)),this.disposeWithMe((0,e.toDisposable)(()=>this._injector.delete(t)))})}_initCommandInterceptor(){this._sheetInterceptorService.interceptCommand({getMutations:t=>{if(t.id===r.ClearSelectionAllCommand.id){var n;let t=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET),r=t.getUnitId(),i=t.getActiveSheet();if(!i)throw Error(`No active sheet found`);let a=i.getSheetId(),o=(n=this._selectionManagerService.getCurrentSelections())==null?void 0:n.map(e=>e.range),s=this._sheetDataValidationModel.getRuleObjectMatrix(r,a).clone();o&&s.removeRange(o);let{redoMutations:c,undoMutations:l}=R(r,a,s.diff(this._sheetDataValidationModel.getRules(r,a)),this._injector,`patched`);return{undos:l,redos:c}}return{undos:[],redos:[]}}})}};Z=f([d(0,e.IUniverInstanceService),d(1,(0,e.Inject)(t.DataValidatorRegistryService)),d(2,(0,e.Inject)(e.Injector)),d(3,(0,e.Inject)(r.SheetsSelectionsService)),d(4,(0,e.Inject)(r.SheetInterceptorService)),d(5,(0,e.Inject)(E))],Z);let Q=class extends e.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetDataValidationModel=t,this._dataValidationCacheService=n,this._lifecycleService=r,this._initRecalculate()}_initRecalculate(){let t=t=>{if(t.length===0)return;let n=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getActiveSheet(),i={};t.flat().forEach(t=>{i[t.unitId]||(i[t.unitId]={}),i[t.unitId][t.subUnitId]||(i[t.unitId][t.subUnitId]=[]);let n=this._univerInstanceService.getUnit(t.unitId,e.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getSheetBySheetId(t.subUnitId);r&&i[t.unitId][t.subUnitId].push(...t.ranges.map(t=>e.Range.transformRange(t,r)))}),Object.entries(i).forEach(([e,t])=>{Object.entries(t).forEach(([t,i])=>{(n==null?void 0:n.getUnitId())===e&&(r==null?void 0:r.getSheetId())===t?this.validatorRanges(e,t,i):requestIdleCallback(()=>{this.validatorRanges(e,t,i)})})})};this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe((0,i.bufferWhen)(()=>this._lifecycleService.lifecycle$.pipe((0,i.filter)(t=>t===e.LifecycleStages.Rendered)))).subscribe(t)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe((0,i.filter)(()=>this._lifecycleService.stage>=e.LifecycleStages.Rendered),(0,e.bufferDebounceTime)(20)).subscribe(t))}async _validatorByCell(t,n,r,i){let a=t.getUnitId(),o=n.getSheetId();if(!e.Tools.isDefine(r)||!e.Tools.isDefine(i))throw Error(`row or col is not defined, row: ${r}, col: ${i}`);let s=r,c=i,l=n.getMergedCell(r,i);l&&(s=l.startRow,c=l.startColumn);let u=this._sheetDataValidationModel.getRuleByLocation(a,o,s,c);return u?new Promise(e=>{this._sheetDataValidationModel.validator(u,{unitId:a,subUnitId:o,row:s,col:c,worksheet:n,workbook:t},t=>{e(t)})}):e.DataValidationStatus.VALID}async validatorCell(t,n,r,i){let a=this._univerInstanceService.getUnit(t,e.UniverInstanceType.UNIVER_SHEET);if(!a)throw Error(`cannot find current workbook, unitId: ${t}`);let o=a.getSheetBySheetId(n);if(!o)throw Error(`cannot find current worksheet, sheetId: ${n}`);return this._validatorByCell(a,o,r,i)}async validatorRanges(t,n,r){if(!r.length)return Promise.resolve([]);let i=this._univerInstanceService.getUnit(t,e.UniverInstanceType.UNIVER_SHEET);if(!i)throw Error(`cannot find current workbook, unitId: ${t}`);let a=i.getSheetBySheetId(n);if(!a)throw Error(`cannot find current worksheet, sheetId: ${n}`);let o=this._sheetDataValidationModel.getRules(t,n).map(e=>e.ranges).flat(),s=r.map(t=>o.map(n=>(0,e.getIntersectRange)(t,n))).flat().filter(Boolean),c=[],l=await Promise.all(s.map((e,t)=>{let n=[];for(let r=e.startRow;r<=e.endRow;r++)for(let o=e.startColumn;o<=e.endColumn;o++){n.push(this._validatorByCell(i,a,r,o));let e=a.getMergedCell(r,o);e&&c.push({resultRowIndex:t,resultColIndex:n.length-1,row:e.startRow,col:e.startColumn})}return Promise.all(n)}));return c.length&&c.forEach(({resultRowIndex:r,resultColIndex:i,row:a,col:o})=>{if(l[r][i]===e.DataValidationStatus.VALIDATING){var s;l[r][i]=(s=this._dataValidationCacheService.getValue(t,n,a,o))==null?e.DataValidationStatus.VALID:s}}),l}async validatorWorksheet(t,n){let r=this._univerInstanceService.getUnit(t,e.UniverInstanceType.UNIVER_SHEET);if(!r)throw Error(`cannot find current workbook, unitId: ${t}`);let i=r.getSheetBySheetId(n);if(!i)throw Error(`cannot find current worksheet, sheetId: ${n}`);let a=this._sheetDataValidationModel.getRules(t,n);return await Promise.all(a.map(t=>Promise.all(t.ranges.map(t=>{let n=[];return e.Range.foreach(t,(e,t)=>{n.push(this._validatorByCell(r,i,e,t))}),Promise.all(n)})))),this._dataValidationCacheService.ensureCache(t,n)}async validatorWorkbook(e){let t=this._sheetDataValidationModel.getSubUnitIds(e),n=await Promise.all(t.map(t=>this.validatorWorksheet(e,t))),r={};return n.forEach((e,n)=>{r[t[n]]=e}),r}getDataValidations(t,n,r){let i=this._sheetDataValidationModel.getRuleObjectMatrix(t,n),a=new Set;return r.forEach(t=>{e.Range.foreach(t,(e,t)=>{let n=i.getValue(e,t);n&&a.add(n)})}),Array.from(a).map(e=>this._sheetDataValidationModel.getRuleById(t,n,e)).filter(Boolean)}getDataValidation(e,t,n){return this.getDataValidations(e,t,n)[0]}};Q=f([d(0,e.IUniverInstanceService),d(1,(0,e.Inject)(E)),d(2,(0,e.Inject)(p)),d(3,(0,e.Inject)(e.LifecycleService))],Q);let $=class extends e.Plugin{constructor(t=ge,n,r,i){super(),this._config=t,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,e.merge)({},ge,this._config);this._configService.setConfig(he,a)}onStarting(){[[p],[w],[T],[v],[Q],[E],[Z],[q],[X],[Y],[J]].forEach(e=>{this._injector.add(e)}),[B,z,V,H,G,W,U].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(p),this._injector.get(Q),this._injector.get(Z),this._injector.get(J),this._injector.get(Y)}onReady(){this._injector.get(X)}onRendered(){this._injector.get(q)}};u($,`pluginName`,K),u($,`packageName`,pe),u($,`version`,me),u($,`type`,e.UniverInstanceType.UNIVER_SHEET),$=f([(0,e.DependentOn)(o.UniverSheetsFormulaPlugin,t.UniverDataValidationPlugin),d(1,(0,e.Inject)(e.Injector)),d(2,e.ICommandService),d(3,e.IConfigService)],$);function xe(t){let n=t.get(r.SheetsSelectionsService).getCurrentSelections().map(e=>e.range);return{uid:(0,e.generateRandomId)(6),type:e.DataValidationType.DECIMAL,operator:e.DataValidationOperator.EQUAL,formula1:`100`,ranges:n==null?[{startColumn:0,endColumn:0,startRow:0,endRow:0}]:n}}exports.AddSheetDataValidationCommand=B,exports.BASE_FORMULA_INPUT_NAME=`data-validation.formula-input`,exports.CHECKBOX_FORMULA_1=1,exports.CHECKBOX_FORMULA_2=0,exports.CHECKBOX_FORMULA_INPUT_NAME=`data-validation.checkbox-formula-input`,exports.CUSTOM_FORMULA_INPUT_NAME=`data-validation.custom-formula-input`,exports.CheckboxValidator=ne,exports.ClearRangeDataValidationCommand=U,exports.DATA_VALIDATION_PLUGIN_NAME=K,Object.defineProperty(exports,`DataValidationCacheService`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`DataValidationCustomFormulaService`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`DataValidationFormulaController`,{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,`DataValidationFormulaService`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`DataValidationListCacheService`,{enumerable:!0,get:function(){return w}}),exports.DateValidator=N,exports.LIST_FORMULA_INPUT_NAME=`data-validation.list-formula-input`,exports.ListMultipleValidator=ye,exports.ListValidator=I,exports.RemoveSheetAllDataValidationCommand=W,exports.RemoveSheetDataValidationCommand=G,Object.defineProperty(exports,`SheetDataValidationModel`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`SheetsDataValidationValidatorService`,{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,`UniverSheetsDataValidationPlugin`,{enumerable:!0,get:function(){return $}}),exports.UpdateSheetDataValidationOptionsCommand=H,exports.UpdateSheetDataValidationRangeCommand=z,exports.UpdateSheetDataValidationSettingCommand=V,exports.createDefaultNewRule=xe,exports.deserializeListOptions=S,exports.getCellValueNumber=F,exports.getCellValueOrigin=y,exports.getDataValidationCellValue=ee,exports.getDataValidationDiffMutations=R,exports.getFormulaCellData=h,exports.getFormulaResult=m,exports.getTransformedFormula=C,exports.isLegalFormulaResult=g,exports.serializeListOptions=x,exports.transformCheckboxValue=O;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_data_validation = require("@univerjs/data-validation");
|
|
4
|
+
let _univerjs_engine_formula = require("@univerjs/engine-formula");
|
|
5
|
+
let _univerjs_sheets = require("@univerjs/sheets");
|
|
6
|
+
let rxjs = require("rxjs");
|
|
7
|
+
let _univerjs_protocol = require("@univerjs/protocol");
|
|
8
|
+
let _univerjs_sheets_formula = require("@univerjs/sheets-formula");
|
|
9
|
+
|
|
10
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
11
|
+
function _typeof(o) {
|
|
12
|
+
"@babel/helpers - typeof";
|
|
13
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
14
|
+
return typeof o;
|
|
15
|
+
} : function(o) {
|
|
16
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
17
|
+
}, _typeof(o);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
22
|
+
function toPrimitive(t, r) {
|
|
23
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
24
|
+
var e = t[Symbol.toPrimitive];
|
|
25
|
+
if (void 0 !== e) {
|
|
26
|
+
var i = e.call(t, r || "default");
|
|
27
|
+
if ("object" != _typeof(i)) return i;
|
|
28
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
29
|
+
}
|
|
30
|
+
return ("string" === r ? String : Number)(t);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
35
|
+
function toPropertyKey(t) {
|
|
36
|
+
var i = toPrimitive(t, "string");
|
|
37
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
42
|
+
function _defineProperty(e, r, t) {
|
|
43
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
44
|
+
value: t,
|
|
45
|
+
enumerable: !0,
|
|
46
|
+
configurable: !0,
|
|
47
|
+
writable: !0
|
|
48
|
+
}) : e[r] = t, e;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
53
|
+
function __decorateParam(paramIndex, decorator) {
|
|
54
|
+
return function(target, key) {
|
|
55
|
+
decorator(target, key, paramIndex);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
61
|
+
function __decorate(decorators, target, key, desc) {
|
|
62
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
63
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
64
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
65
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/services/dv-cache.service.ts
|
|
70
|
+
let DataValidationCacheService = class DataValidationCacheService extends _univerjs_core.Disposable {
|
|
71
|
+
constructor(_commandService, _univerInstanceService, _sheetDataValidationModel) {
|
|
72
|
+
super();
|
|
73
|
+
this._commandService = _commandService;
|
|
74
|
+
this._univerInstanceService = _univerInstanceService;
|
|
75
|
+
this._sheetDataValidationModel = _sheetDataValidationModel;
|
|
76
|
+
_defineProperty(this, "_cacheMatrix", /* @__PURE__ */ new Map());
|
|
77
|
+
_defineProperty(this, "_dirtyRanges$", new rxjs.Subject());
|
|
78
|
+
_defineProperty(this, "dirtyRanges$", this._dirtyRanges$.asObservable());
|
|
79
|
+
this._initDirtyRanges();
|
|
80
|
+
this._initSheetRemove();
|
|
81
|
+
}
|
|
82
|
+
_initDirtyRanges() {
|
|
83
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo, options) => {
|
|
84
|
+
if (commandInfo.id === _univerjs_sheets.SetRangeValuesMutation.id && !(options === null || options === void 0 ? void 0 : options.onlyLocal)) {
|
|
85
|
+
const { cellValue, unitId, subUnitId } = commandInfo.params;
|
|
86
|
+
if (cellValue) {
|
|
87
|
+
const range = new _univerjs_core.ObjectMatrix(cellValue).getDataRange();
|
|
88
|
+
if (range.endRow === -1) return;
|
|
89
|
+
const intersectsRanges = this._sheetDataValidationModel.getRules(unitId, subUnitId).map((rule) => rule.ranges).flat().map((ruleRange) => (0, _univerjs_core.getIntersectRange)(ruleRange, range)).filter(Boolean);
|
|
90
|
+
if (intersectsRanges.length) this.markRangeDirty(unitId, subUnitId, intersectsRanges, true);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
_initSheetRemove() {
|
|
96
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
97
|
+
if (commandInfo.id === _univerjs_sheets.RemoveSheetMutation.id) {
|
|
98
|
+
var _this$_cacheMatrix$ge;
|
|
99
|
+
const { unitId, subUnitId } = commandInfo.params;
|
|
100
|
+
(_this$_cacheMatrix$ge = this._cacheMatrix.get(unitId)) === null || _this$_cacheMatrix$ge === void 0 || _this$_cacheMatrix$ge.delete(subUnitId);
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
103
|
+
this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((univerInstance) => {
|
|
104
|
+
if (univerInstance.type === _univerjs_core.UniverInstanceType.UNIVER_SHEET) this._cacheMatrix.delete(univerInstance.getUnitId());
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
_ensureCache(unitId, subUnitId) {
|
|
108
|
+
let unitMap = this._cacheMatrix.get(unitId);
|
|
109
|
+
if (!unitMap) {
|
|
110
|
+
unitMap = /* @__PURE__ */ new Map();
|
|
111
|
+
this._cacheMatrix.set(unitId, unitMap);
|
|
112
|
+
}
|
|
113
|
+
let cacheMatrix = unitMap.get(subUnitId);
|
|
114
|
+
if (!cacheMatrix) {
|
|
115
|
+
cacheMatrix = new _univerjs_core.ObjectMatrix();
|
|
116
|
+
unitMap.set(subUnitId, cacheMatrix);
|
|
117
|
+
}
|
|
118
|
+
return cacheMatrix;
|
|
119
|
+
}
|
|
120
|
+
ensureCache(unitId, subUnitId) {
|
|
121
|
+
return this._ensureCache(unitId, subUnitId);
|
|
122
|
+
}
|
|
123
|
+
addRule(unitId, subUnitId, rule) {
|
|
124
|
+
this.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
125
|
+
}
|
|
126
|
+
removeRule(unitId, subUnitId, rule) {
|
|
127
|
+
this._deleteRange(unitId, subUnitId, rule.ranges);
|
|
128
|
+
}
|
|
129
|
+
markRangeDirty(unitId, subUnitId, ranges, isSetRange) {
|
|
130
|
+
const cache = this._ensureCache(unitId, subUnitId);
|
|
131
|
+
ranges.forEach((range) => {
|
|
132
|
+
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
133
|
+
if (cache.getValue(row, col) !== void 0) cache.setValue(row, col, void 0);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
this._dirtyRanges$.next({
|
|
137
|
+
unitId,
|
|
138
|
+
subUnitId,
|
|
139
|
+
ranges,
|
|
140
|
+
isSetRange
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
_deleteRange(unitId, subUnitId, ranges) {
|
|
144
|
+
const cache = this._ensureCache(unitId, subUnitId);
|
|
145
|
+
ranges.forEach((range) => {
|
|
146
|
+
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
147
|
+
cache.realDeleteValue(row, col);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
this._dirtyRanges$.next({
|
|
151
|
+
unitId,
|
|
152
|
+
subUnitId,
|
|
153
|
+
ranges
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
getValue(unitId, subUnitId, row, col) {
|
|
157
|
+
return this._ensureCache(unitId, subUnitId).getValue(row, col);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
DataValidationCacheService = __decorate([
|
|
161
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.ICommandService)),
|
|
162
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
|
|
163
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidationModel))
|
|
164
|
+
], DataValidationCacheService);
|
|
165
|
+
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/utils/formula.ts
|
|
168
|
+
function getFormulaResult(result) {
|
|
169
|
+
var _result$;
|
|
170
|
+
return result === null || result === void 0 || (_result$ = result[0]) === null || _result$ === void 0 || (_result$ = _result$[0]) === null || _result$ === void 0 ? void 0 : _result$.v;
|
|
171
|
+
}
|
|
172
|
+
function getFormulaCellData(result) {
|
|
173
|
+
var _result$2;
|
|
174
|
+
return result === null || result === void 0 || (_result$2 = result[0]) === null || _result$2 === void 0 ? void 0 : _result$2[0];
|
|
175
|
+
}
|
|
176
|
+
function isLegalFormulaResult(res) {
|
|
177
|
+
return !_univerjs_engine_formula.ERROR_TYPE_SET.has(res);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Judge if the data-validation's formula need to be offseted by ranges
|
|
181
|
+
*/
|
|
182
|
+
function shouldOffsetFormulaByRange(type, validatorRegistryService) {
|
|
183
|
+
var _validator$offsetForm;
|
|
184
|
+
const validator = validatorRegistryService.getValidatorItem(type);
|
|
185
|
+
return (_validator$offsetForm = validator === null || validator === void 0 ? void 0 : validator.offsetFormulaByRange) !== null && _validator$offsetForm !== void 0 ? _validator$offsetForm : false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/services/dv-custom-formula.service.ts
|
|
190
|
+
let DataValidationCustomFormulaService = class DataValidationCustomFormulaService extends _univerjs_core.Disposable {
|
|
191
|
+
constructor(_instanceSrv, _registerOtherFormulaService, _dataValidationModel, _dataValidationCacheService, _validatorRegistryService) {
|
|
192
|
+
super();
|
|
193
|
+
this._instanceSrv = _instanceSrv;
|
|
194
|
+
this._registerOtherFormulaService = _registerOtherFormulaService;
|
|
195
|
+
this._dataValidationModel = _dataValidationModel;
|
|
196
|
+
this._dataValidationCacheService = _dataValidationCacheService;
|
|
197
|
+
this._validatorRegistryService = _validatorRegistryService;
|
|
198
|
+
_defineProperty(this, "_ruleFormulaMap", /* @__PURE__ */ new Map());
|
|
199
|
+
_defineProperty(this, "_ruleFormulaMap2", /* @__PURE__ */ new Map());
|
|
200
|
+
this._initFormulaResultHandler();
|
|
201
|
+
this._initDirtyRanges();
|
|
202
|
+
}
|
|
203
|
+
dispose() {
|
|
204
|
+
super.dispose();
|
|
205
|
+
this._ruleFormulaMap.clear();
|
|
206
|
+
this._ruleFormulaMap2.clear();
|
|
207
|
+
}
|
|
208
|
+
_initFormulaResultHandler() {
|
|
209
|
+
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
|
|
210
|
+
for (const unitId in resultMap) {
|
|
211
|
+
const unitMap = resultMap[unitId];
|
|
212
|
+
if (this._instanceSrv.getUnitType(unitId) !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) continue;
|
|
213
|
+
for (const subUnitId in unitMap) {
|
|
214
|
+
const results = unitMap[subUnitId];
|
|
215
|
+
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
|
|
216
|
+
results.forEach((result) => {
|
|
217
|
+
var _result$extra, _result$extra2;
|
|
218
|
+
const ruleInfo = ruleFormulaMap.get((_result$extra = result.extra) === null || _result$extra === void 0 ? void 0 : _result$extra.ruleId);
|
|
219
|
+
const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, (_result$extra2 = result.extra) === null || _result$extra2 === void 0 ? void 0 : _result$extra2.ruleId);
|
|
220
|
+
if (rule && ruleInfo) this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}));
|
|
225
|
+
}
|
|
226
|
+
_ensureMaps(unitId, subUnitId) {
|
|
227
|
+
let ruleFormulaUnitMap = this._ruleFormulaMap.get(unitId);
|
|
228
|
+
let ruleFormulaUnitMap2 = this._ruleFormulaMap2.get(unitId);
|
|
229
|
+
if (!ruleFormulaUnitMap) {
|
|
230
|
+
ruleFormulaUnitMap = /* @__PURE__ */ new Map();
|
|
231
|
+
this._ruleFormulaMap.set(unitId, ruleFormulaUnitMap);
|
|
232
|
+
}
|
|
233
|
+
if (!ruleFormulaUnitMap2) {
|
|
234
|
+
ruleFormulaUnitMap2 = /* @__PURE__ */ new Map();
|
|
235
|
+
this._ruleFormulaMap2.set(unitId, ruleFormulaUnitMap2);
|
|
236
|
+
}
|
|
237
|
+
let ruleFormulaMap = ruleFormulaUnitMap.get(subUnitId);
|
|
238
|
+
if (!ruleFormulaMap) {
|
|
239
|
+
ruleFormulaMap = /* @__PURE__ */ new Map();
|
|
240
|
+
ruleFormulaUnitMap.set(subUnitId, ruleFormulaMap);
|
|
241
|
+
}
|
|
242
|
+
let ruleFormulaMap2 = ruleFormulaUnitMap2.get(subUnitId);
|
|
243
|
+
if (!ruleFormulaMap2) {
|
|
244
|
+
ruleFormulaMap2 = /* @__PURE__ */ new Map();
|
|
245
|
+
ruleFormulaUnitMap2.set(subUnitId, ruleFormulaMap2);
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
ruleFormulaMap,
|
|
249
|
+
ruleFormulaMap2
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
_registerFormula(unitId, subUnitId, ruleId, formulaString, ranges) {
|
|
253
|
+
return this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formulaString, ranges, { ruleId }, _univerjs_engine_formula.OtherFormulaBizType.DATA_VALIDATION_CUSTOM, ruleId);
|
|
254
|
+
}
|
|
255
|
+
_handleDirtyRanges(unitId, subUnitId, ranges) {
|
|
256
|
+
this._dataValidationModel.getRules(unitId, subUnitId).forEach((rule) => {
|
|
257
|
+
const ruleRanges = rule.ranges;
|
|
258
|
+
if (_univerjs_core.Rectangle.doAnyRangesIntersect(ruleRanges, ranges)) this.makeRuleDirty(unitId, subUnitId, rule.uid);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
_initDirtyRanges() {
|
|
262
|
+
this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.subscribe((data) => {
|
|
263
|
+
if (data.isSetRange) this._handleDirtyRanges(data.unitId, data.subUnitId, data.ranges);
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
deleteByRuleId(unitId, subUnitId, ruleId) {
|
|
267
|
+
const { ruleFormulaMap, ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId);
|
|
268
|
+
const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
269
|
+
const formulaInfo = ruleFormulaMap.get(ruleId);
|
|
270
|
+
if (!rule || !formulaInfo) return;
|
|
271
|
+
const current = ruleFormulaMap.get(ruleId);
|
|
272
|
+
if (current) {
|
|
273
|
+
ruleFormulaMap.delete(ruleId);
|
|
274
|
+
this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [current.formulaId]);
|
|
275
|
+
}
|
|
276
|
+
const current2 = ruleFormulaMap2.get(ruleId);
|
|
277
|
+
if (current2) {
|
|
278
|
+
ruleFormulaMap2.delete(ruleId);
|
|
279
|
+
this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [current2.formulaId]);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
_addFormulaByRange(unitId, subUnitId, ruleId, formula, formula2, ranges) {
|
|
283
|
+
const { ruleFormulaMap, ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId);
|
|
284
|
+
const originRow = ranges[0].startRow;
|
|
285
|
+
const originCol = ranges[0].startColumn;
|
|
286
|
+
if (formula && (0, _univerjs_core.isFormulaString)(formula)) {
|
|
287
|
+
const formulaId = this._registerFormula(unitId, subUnitId, ruleId, formula, ranges);
|
|
288
|
+
ruleFormulaMap.set(ruleId, {
|
|
289
|
+
formula,
|
|
290
|
+
originCol,
|
|
291
|
+
originRow,
|
|
292
|
+
formulaId
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (formula2 && (0, _univerjs_core.isFormulaString)(formula2)) {
|
|
296
|
+
const formulaId2 = this._registerFormula(unitId, subUnitId, ruleId, formula2, ranges);
|
|
297
|
+
ruleFormulaMap2.set(ruleId, {
|
|
298
|
+
formula: formula2,
|
|
299
|
+
originCol,
|
|
300
|
+
originRow,
|
|
301
|
+
formulaId: formulaId2
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
addRule(unitId, subUnitId, rule) {
|
|
306
|
+
if (shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService)) {
|
|
307
|
+
const { ranges, formula1, formula2, uid: ruleId } = rule;
|
|
308
|
+
this._addFormulaByRange(unitId, subUnitId, ruleId, formula1, formula2, ranges);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async getCellFormulaValue(unitId, subUnitId, ruleId, row, column) {
|
|
312
|
+
var _result$result;
|
|
313
|
+
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
|
|
314
|
+
const current = ruleFormulaMap.get(ruleId);
|
|
315
|
+
if (!current) return Promise.resolve(void 0);
|
|
316
|
+
const result = await this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, current.formulaId);
|
|
317
|
+
const { originRow, originCol } = current;
|
|
318
|
+
const offsetRow = row - originRow;
|
|
319
|
+
const offsetCol = column - originCol;
|
|
320
|
+
return getFormulaCellData(result === null || result === void 0 || (_result$result = result.result) === null || _result$result === void 0 || (_result$result = _result$result[offsetRow]) === null || _result$result === void 0 ? void 0 : _result$result[offsetCol]);
|
|
321
|
+
}
|
|
322
|
+
async getCellFormula2Value(unitId, subUnitId, ruleId, row, column) {
|
|
323
|
+
var _result$result2;
|
|
324
|
+
const { ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId);
|
|
325
|
+
const current = ruleFormulaMap2.get(ruleId);
|
|
326
|
+
if (!current) return Promise.resolve(void 0);
|
|
327
|
+
const result = await this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, current.formulaId);
|
|
328
|
+
const { originRow, originCol } = current;
|
|
329
|
+
const offsetRow = row - originRow;
|
|
330
|
+
const offsetCol = column - originCol;
|
|
331
|
+
return getFormulaCellData(result === null || result === void 0 || (_result$result2 = result.result) === null || _result$result2 === void 0 || (_result$result2 = _result$result2[offsetRow]) === null || _result$result2 === void 0 ? void 0 : _result$result2[offsetCol]);
|
|
332
|
+
}
|
|
333
|
+
getCellFormulaValueSync(unitId, subUnitId, ruleId, row, column) {
|
|
334
|
+
var _result$result3;
|
|
335
|
+
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
|
|
336
|
+
const current = ruleFormulaMap.get(ruleId);
|
|
337
|
+
if (!current) return;
|
|
338
|
+
const result = this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, current.formulaId);
|
|
339
|
+
const { originRow, originCol } = current;
|
|
340
|
+
const offsetRow = row - originRow;
|
|
341
|
+
const offsetCol = column - originCol;
|
|
342
|
+
return getFormulaCellData(result === null || result === void 0 || (_result$result3 = result.result) === null || _result$result3 === void 0 || (_result$result3 = _result$result3[offsetRow]) === null || _result$result3 === void 0 ? void 0 : _result$result3[offsetCol]);
|
|
343
|
+
}
|
|
344
|
+
getCellFormula2ValueSync(unitId, subUnitId, ruleId, row, column) {
|
|
345
|
+
var _result$result4;
|
|
346
|
+
const { ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId);
|
|
347
|
+
const current = ruleFormulaMap2.get(ruleId);
|
|
348
|
+
if (!current) return;
|
|
349
|
+
const result = this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, current.formulaId);
|
|
350
|
+
const { originRow, originCol } = current;
|
|
351
|
+
const offsetRow = row - originRow;
|
|
352
|
+
const offsetCol = column - originCol;
|
|
353
|
+
return getFormulaCellData(result === null || result === void 0 || (_result$result4 = result.result) === null || _result$result4 === void 0 || (_result$result4 = _result$result4[offsetRow]) === null || _result$result4 === void 0 ? void 0 : _result$result4[offsetCol]);
|
|
354
|
+
}
|
|
355
|
+
getRuleFormulaInfo(unitId, subUnitId, ruleId) {
|
|
356
|
+
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
|
|
357
|
+
return ruleFormulaMap.get(ruleId);
|
|
358
|
+
}
|
|
359
|
+
makeRuleDirty(unitId, subUnitId, ruleId) {
|
|
360
|
+
var _this$_ruleFormulaMap, _this$_ruleFormulaMap2;
|
|
361
|
+
const formula1 = (_this$_ruleFormulaMap = this._ruleFormulaMap.get(unitId)) === null || _this$_ruleFormulaMap === void 0 || (_this$_ruleFormulaMap = _this$_ruleFormulaMap.get(subUnitId)) === null || _this$_ruleFormulaMap === void 0 ? void 0 : _this$_ruleFormulaMap.get(ruleId);
|
|
362
|
+
const formula2 = (_this$_ruleFormulaMap2 = this._ruleFormulaMap2.get(unitId)) === null || _this$_ruleFormulaMap2 === void 0 || (_this$_ruleFormulaMap2 = _this$_ruleFormulaMap2.get(subUnitId)) === null || _this$_ruleFormulaMap2 === void 0 ? void 0 : _this$_ruleFormulaMap2.get(ruleId);
|
|
363
|
+
if (formula1) this._registerOtherFormulaService.markFormulaDirty(unitId, subUnitId, formula1.formulaId);
|
|
364
|
+
if (formula2) this._registerOtherFormulaService.markFormulaDirty(unitId, subUnitId, formula2.formulaId);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
DataValidationCustomFormulaService = __decorate([
|
|
368
|
+
__decorateParam(0, _univerjs_core.IUniverInstanceService),
|
|
369
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_engine_formula.RegisterOtherFormulaService)),
|
|
370
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidationModel)),
|
|
371
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(DataValidationCacheService)),
|
|
372
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService))
|
|
373
|
+
], DataValidationCustomFormulaService);
|
|
374
|
+
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/utils/get-cell-data-origin.ts
|
|
377
|
+
function getCellValueOrigin(cell) {
|
|
378
|
+
return (0, _univerjs_core.getOriginCellValue)(cell);
|
|
379
|
+
}
|
|
380
|
+
function getStringCellValue(cell) {
|
|
381
|
+
var _getCellValueOrigin;
|
|
382
|
+
return String((_getCellValueOrigin = getCellValueOrigin(cell)) !== null && _getCellValueOrigin !== void 0 ? _getCellValueOrigin : "");
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/validators/util.ts
|
|
387
|
+
function serializeListOptions(options) {
|
|
388
|
+
return options.filter(Boolean).join(",");
|
|
389
|
+
}
|
|
390
|
+
function deserializeListOptions(optionsStr) {
|
|
391
|
+
return optionsStr.split(",").filter(Boolean);
|
|
392
|
+
}
|
|
393
|
+
function getDataValidationCellValue(cellData) {
|
|
394
|
+
const cellValue = getCellValueOrigin(cellData);
|
|
395
|
+
if (cellValue === void 0 || cellValue === null) return "";
|
|
396
|
+
return cellValue.toString();
|
|
397
|
+
}
|
|
398
|
+
function getTransformedFormula(lexerTreeBuilder, rule, position) {
|
|
399
|
+
const { formula1, formula2 } = rule;
|
|
400
|
+
const originStartRow = rule.ranges[0].startRow;
|
|
401
|
+
const originStartColumn = rule.ranges[0].startColumn;
|
|
402
|
+
const offsetRow = position.row - originStartRow;
|
|
403
|
+
const offsetColumn = position.col - originStartColumn;
|
|
404
|
+
return {
|
|
405
|
+
transformedFormula1: (0, _univerjs_core.isFormulaString)(formula1) ? lexerTreeBuilder.moveFormulaRefOffset(formula1, offsetColumn, offsetRow, true) : formula1,
|
|
406
|
+
transformedFormula2: (0, _univerjs_core.isFormulaString)(formula2) ? lexerTreeBuilder.moveFormulaRefOffset(formula2, offsetColumn, offsetRow, true) : formula2
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/services/dv-list-cache.service.ts
|
|
412
|
+
let DataValidationListCacheService = class DataValidationListCacheService extends _univerjs_core.Disposable {
|
|
413
|
+
constructor(_injector, _dataValidationModel) {
|
|
414
|
+
super();
|
|
415
|
+
this._injector = _injector;
|
|
416
|
+
this._dataValidationModel = _dataValidationModel;
|
|
417
|
+
_defineProperty(this, "_cache", /* @__PURE__ */ new Map());
|
|
418
|
+
this._initRuleChangeListener();
|
|
419
|
+
}
|
|
420
|
+
_initRuleChangeListener() {
|
|
421
|
+
this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe((change) => {
|
|
422
|
+
if (change.type === "remove" || change.type === "update") this.markRuleDirty(change.unitId, change.subUnitId, change.rule.uid);
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Get cached list data or compute and cache it if not exists.
|
|
427
|
+
*/
|
|
428
|
+
getOrCompute(unitId, subUnitId, rule) {
|
|
429
|
+
const cached = this.getCache(unitId, subUnitId, rule.uid);
|
|
430
|
+
if (cached) return cached;
|
|
431
|
+
const results = this._injector.get(DataValidationFormulaService).getRuleFormulaResultSync(unitId, subUnitId, rule.uid);
|
|
432
|
+
return this.computeAndCache(unitId, subUnitId, rule, results);
|
|
433
|
+
}
|
|
434
|
+
_ensureCache(unitId, subUnitId) {
|
|
435
|
+
let unitMap = this._cache.get(unitId);
|
|
436
|
+
if (!unitMap) {
|
|
437
|
+
unitMap = /* @__PURE__ */ new Map();
|
|
438
|
+
this._cache.set(unitId, unitMap);
|
|
439
|
+
}
|
|
440
|
+
let subUnitMap = unitMap.get(subUnitId);
|
|
441
|
+
if (!subUnitMap) {
|
|
442
|
+
subUnitMap = /* @__PURE__ */ new Map();
|
|
443
|
+
unitMap.set(subUnitId, subUnitMap);
|
|
444
|
+
}
|
|
445
|
+
return subUnitMap;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Get cached list data for a rule. Returns undefined if not cached.
|
|
449
|
+
*/
|
|
450
|
+
getCache(unitId, subUnitId, ruleId) {
|
|
451
|
+
var _this$_cache$get;
|
|
452
|
+
return (_this$_cache$get = this._cache.get(unitId)) === null || _this$_cache$get === void 0 || (_this$_cache$get = _this$_cache$get.get(subUnitId)) === null || _this$_cache$get === void 0 ? void 0 : _this$_cache$get.get(ruleId);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Set cache for a rule.
|
|
456
|
+
*/
|
|
457
|
+
setCache(unitId, subUnitId, ruleId, item) {
|
|
458
|
+
this._ensureCache(unitId, subUnitId).set(ruleId, item);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Mark a rule's cache as dirty (invalidate it).
|
|
462
|
+
* Called when formula results change.
|
|
463
|
+
*/
|
|
464
|
+
markRuleDirty(unitId, subUnitId, ruleId) {
|
|
465
|
+
var _this$_cache$get2;
|
|
466
|
+
(_this$_cache$get2 = this._cache.get(unitId)) === null || _this$_cache$get2 === void 0 || (_this$_cache$get2 = _this$_cache$get2.get(subUnitId)) === null || _this$_cache$get2 === void 0 || _this$_cache$get2.delete(ruleId);
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Clear all caches.
|
|
470
|
+
*/
|
|
471
|
+
clear() {
|
|
472
|
+
this._cache.clear();
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Compute list data from formula result and cache it.
|
|
476
|
+
*/
|
|
477
|
+
computeAndCache(unitId, subUnitId, rule, formulaResult) {
|
|
478
|
+
var _formulaResult$;
|
|
479
|
+
const { formula1 = "", formula2 = "" } = rule;
|
|
480
|
+
const list = (0, _univerjs_core.isFormulaString)(formula1) ? this._getRuleFormulaResultSet(formulaResult === null || formulaResult === void 0 || (_formulaResult$ = formulaResult[0]) === null || _formulaResult$ === void 0 || (_formulaResult$ = _formulaResult$.result) === null || _formulaResult$ === void 0 || (_formulaResult$ = _formulaResult$[0]) === null || _formulaResult$ === void 0 ? void 0 : _formulaResult$[0]) : deserializeListOptions(formula1);
|
|
481
|
+
const colorList = formula2.split(",");
|
|
482
|
+
const listWithColor = list.map((label, i) => ({
|
|
483
|
+
label,
|
|
484
|
+
color: colorList[i] || ""
|
|
485
|
+
}));
|
|
486
|
+
const colorMap = {};
|
|
487
|
+
for (const item of listWithColor) if (item.color) colorMap[item.label] = item.color;
|
|
488
|
+
const cacheItem = {
|
|
489
|
+
list,
|
|
490
|
+
listWithColor,
|
|
491
|
+
colorMap,
|
|
492
|
+
set: new Set(list)
|
|
493
|
+
};
|
|
494
|
+
this.setCache(unitId, subUnitId, rule.uid, cacheItem);
|
|
495
|
+
return cacheItem;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Extract string list from formula result cells.
|
|
499
|
+
*/
|
|
500
|
+
_getRuleFormulaResultSet(result) {
|
|
501
|
+
if (!result) return [];
|
|
502
|
+
const resultSet = /* @__PURE__ */ new Set();
|
|
503
|
+
for (let i = 0, rowLen = result.length; i < rowLen; i++) {
|
|
504
|
+
const row = result[i];
|
|
505
|
+
if (!row) continue;
|
|
506
|
+
for (let j = 0, colLen = row.length; j < colLen; j++) {
|
|
507
|
+
const cell = row[j];
|
|
508
|
+
const value = getCellValueOrigin(cell);
|
|
509
|
+
if (value !== null && value !== void 0) {
|
|
510
|
+
var _cell$s;
|
|
511
|
+
if (typeof value !== "string" && typeof (cell === null || cell === void 0 ? void 0 : cell.s) === "object" && ((_cell$s = cell.s) === null || _cell$s === void 0 || (_cell$s = _cell$s.n) === null || _cell$s === void 0 ? void 0 : _cell$s.pattern)) {
|
|
512
|
+
resultSet.add(_univerjs_core.numfmt.format(cell.s.n.pattern, value, { throws: false }));
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
const valueStr = typeof value === "string" ? value : String(value);
|
|
516
|
+
if (isLegalFormulaResult(valueStr)) resultSet.add(valueStr);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return [...resultSet];
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
DataValidationListCacheService = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidationModel))], DataValidationListCacheService);
|
|
524
|
+
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/services/dv-formula.service.ts
|
|
527
|
+
let DataValidationFormulaService = class DataValidationFormulaService extends _univerjs_core.Disposable {
|
|
528
|
+
constructor(_instanceService, _registerOtherFormulaService, _dataValidationCacheService, _dataValidationModel, _validatorRegistryService, _listCacheService) {
|
|
529
|
+
super();
|
|
530
|
+
this._instanceService = _instanceService;
|
|
531
|
+
this._registerOtherFormulaService = _registerOtherFormulaService;
|
|
532
|
+
this._dataValidationCacheService = _dataValidationCacheService;
|
|
533
|
+
this._dataValidationModel = _dataValidationModel;
|
|
534
|
+
this._validatorRegistryService = _validatorRegistryService;
|
|
535
|
+
this._listCacheService = _listCacheService;
|
|
536
|
+
_defineProperty(this, "_formulaRuleMap", /* @__PURE__ */ new Map());
|
|
537
|
+
this._initFormulaResultHandler();
|
|
538
|
+
}
|
|
539
|
+
_initFormulaResultHandler() {
|
|
540
|
+
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
|
|
541
|
+
for (const unitId in resultMap) {
|
|
542
|
+
const unitMap = resultMap[unitId];
|
|
543
|
+
if (this._instanceService.getUnitType(unitId) !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) continue;
|
|
544
|
+
for (const subUnitId in unitMap) {
|
|
545
|
+
const results = unitMap[subUnitId];
|
|
546
|
+
const formulaMap = this._ensureRuleFormulaMap(unitId, subUnitId);
|
|
547
|
+
results.forEach((result) => {
|
|
548
|
+
var _result$extra;
|
|
549
|
+
const ruleId = (_result$extra = result.extra) === null || _result$extra === void 0 ? void 0 : _result$extra.ruleId;
|
|
550
|
+
if (ruleId && formulaMap.get(ruleId)) {
|
|
551
|
+
const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
552
|
+
if (rule) {
|
|
553
|
+
this._listCacheService.markRuleDirty(unitId, subUnitId, ruleId);
|
|
554
|
+
this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}));
|
|
561
|
+
}
|
|
562
|
+
_ensureRuleFormulaMap(unitId, subUnitId) {
|
|
563
|
+
let unitMap = this._formulaRuleMap.get(unitId);
|
|
564
|
+
if (!unitMap) {
|
|
565
|
+
unitMap = /* @__PURE__ */ new Map();
|
|
566
|
+
this._formulaRuleMap.set(unitId, unitMap);
|
|
567
|
+
}
|
|
568
|
+
let subUnitMap = unitMap.get(subUnitId);
|
|
569
|
+
if (!subUnitMap) {
|
|
570
|
+
subUnitMap = /* @__PURE__ */ new Map();
|
|
571
|
+
unitMap.set(subUnitId, subUnitMap);
|
|
572
|
+
}
|
|
573
|
+
return subUnitMap;
|
|
574
|
+
}
|
|
575
|
+
_registerSingleFormula(unitId, subUnitId, formula, ruleId) {
|
|
576
|
+
return this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formula, [{
|
|
577
|
+
startColumn: 0,
|
|
578
|
+
endColumn: 0,
|
|
579
|
+
startRow: 0,
|
|
580
|
+
endRow: 0
|
|
581
|
+
}], { ruleId }, _univerjs_engine_formula.OtherFormulaBizType.DATA_VALIDATION, ruleId);
|
|
582
|
+
}
|
|
583
|
+
addRule(unitId, subUnitId, rule) {
|
|
584
|
+
if (!shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService) && rule.type !== _univerjs_core.DataValidationType.CHECKBOX) {
|
|
585
|
+
const { formula1, formula2, uid: ruleId } = rule;
|
|
586
|
+
const isFormula1Legal = (0, _univerjs_core.isFormulaString)(formula1);
|
|
587
|
+
const isFormula2Legal = (0, _univerjs_core.isFormulaString)(formula2);
|
|
588
|
+
if (!isFormula1Legal && !isFormula2Legal) return;
|
|
589
|
+
const formulaRuleMap = this._ensureRuleFormulaMap(unitId, subUnitId);
|
|
590
|
+
const item = [void 0, void 0];
|
|
591
|
+
if (isFormula1Legal) item[0] = {
|
|
592
|
+
id: this._registerSingleFormula(unitId, subUnitId, formula1, ruleId),
|
|
593
|
+
text: formula1
|
|
594
|
+
};
|
|
595
|
+
if (isFormula2Legal) item[1] = {
|
|
596
|
+
id: this._registerSingleFormula(unitId, subUnitId, formula2, ruleId),
|
|
597
|
+
text: formula2
|
|
598
|
+
};
|
|
599
|
+
formulaRuleMap.set(ruleId, item);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
removeRule(unitId, subUnitId, ruleId) {
|
|
603
|
+
const item = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
604
|
+
if (!item) return;
|
|
605
|
+
const [formula1, formula2] = item;
|
|
606
|
+
const idList = [formula1 === null || formula1 === void 0 ? void 0 : formula1.id, formula2 === null || formula2 === void 0 ? void 0 : formula2.id].filter(Boolean);
|
|
607
|
+
idList.length && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, idList);
|
|
608
|
+
}
|
|
609
|
+
getRuleFormulaResult(unitId, subUnitId, ruleId) {
|
|
610
|
+
const formulaInfo = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
611
|
+
if (!formulaInfo) return Promise.resolve(null);
|
|
612
|
+
const getResult = async (info) => info && this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, info.id);
|
|
613
|
+
return Promise.all([getResult(formulaInfo[0]), getResult(formulaInfo[1])]);
|
|
614
|
+
}
|
|
615
|
+
getRuleFormulaResultSync(unitId, subUnitId, ruleId) {
|
|
616
|
+
const formulaInfo = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
617
|
+
if (!formulaInfo) return;
|
|
618
|
+
return formulaInfo.map((i) => {
|
|
619
|
+
if (i) return this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, i.id);
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
getRuleFormulaInfo(unitId, subUnitId, ruleId) {
|
|
623
|
+
return this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
DataValidationFormulaService = __decorate([
|
|
627
|
+
__decorateParam(0, _univerjs_core.IUniverInstanceService),
|
|
628
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_engine_formula.RegisterOtherFormulaService)),
|
|
629
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(DataValidationCacheService)),
|
|
630
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidationModel)),
|
|
631
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
|
|
632
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(DataValidationListCacheService))
|
|
633
|
+
], DataValidationFormulaService);
|
|
634
|
+
|
|
635
|
+
//#endregion
|
|
636
|
+
//#region src/models/rule-matrix.ts
|
|
637
|
+
var RuleMatrix = class RuleMatrix {
|
|
638
|
+
constructor(value, _unitId, _subUnitId, _univerInstanceService, _disableTree = false) {
|
|
639
|
+
this._unitId = _unitId;
|
|
640
|
+
this._subUnitId = _subUnitId;
|
|
641
|
+
this._univerInstanceService = _univerInstanceService;
|
|
642
|
+
this._disableTree = _disableTree;
|
|
643
|
+
_defineProperty(this, "_map", void 0);
|
|
644
|
+
_defineProperty(this, "_tree", new _univerjs_core.RBush());
|
|
645
|
+
_defineProperty(this, "_dirty", true);
|
|
646
|
+
_defineProperty(this, "_buildTree", () => {
|
|
647
|
+
if (!this._dirty || this._disableTree) return;
|
|
648
|
+
this._tree.clear();
|
|
649
|
+
const items = [];
|
|
650
|
+
this._map.forEach((ranges, ruleId) => {
|
|
651
|
+
ranges.forEach((range) => {
|
|
652
|
+
items.push({
|
|
653
|
+
minX: range.startRow,
|
|
654
|
+
maxX: range.endRow,
|
|
655
|
+
minY: range.startColumn,
|
|
656
|
+
maxY: range.endColumn,
|
|
657
|
+
ruleId
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
this._tree.load(items);
|
|
662
|
+
this._dirty = false;
|
|
663
|
+
});
|
|
664
|
+
_defineProperty(this, "_debonceBuildTree", (0, _univerjs_core.debounce)(this._buildTree, 0));
|
|
665
|
+
this._map = value;
|
|
666
|
+
this._buildTree();
|
|
667
|
+
}
|
|
668
|
+
get _worksheet() {
|
|
669
|
+
var _this$_univerInstance;
|
|
670
|
+
return (_this$_univerInstance = this._univerInstanceService.getUnit(this._unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(this._subUnitId);
|
|
671
|
+
}
|
|
672
|
+
_addRule(ruleId, _ranges) {
|
|
673
|
+
if (!this._worksheet) return;
|
|
674
|
+
const ranges = _univerjs_core.Rectangle.mergeRanges(_ranges.map((range) => _univerjs_core.Range.transformRange(range, this._worksheet)));
|
|
675
|
+
this._map.forEach((value, key) => {
|
|
676
|
+
const newRanges = _univerjs_core.Rectangle.subtractMulti(value, ranges);
|
|
677
|
+
if (newRanges.length === 0) this._map.delete(key);
|
|
678
|
+
else this._map.set(key, newRanges);
|
|
679
|
+
});
|
|
680
|
+
this._dirty = true;
|
|
681
|
+
this._map.set(ruleId, ranges);
|
|
682
|
+
this._debonceBuildTree();
|
|
683
|
+
}
|
|
684
|
+
addRule(rule) {
|
|
685
|
+
this._addRule(rule.uid, rule.ranges);
|
|
686
|
+
}
|
|
687
|
+
removeRange(_ranges) {
|
|
688
|
+
if (!this._worksheet) return;
|
|
689
|
+
const ranges = _ranges.map((range) => _univerjs_core.Range.transformRange(range, this._worksheet));
|
|
690
|
+
this._map.forEach((value, key) => {
|
|
691
|
+
const newRanges = _univerjs_core.Rectangle.subtractMulti(value, ranges);
|
|
692
|
+
if (newRanges.length === 0) this._map.delete(key);
|
|
693
|
+
else this._map.set(key, newRanges);
|
|
694
|
+
});
|
|
695
|
+
this._dirty = true;
|
|
696
|
+
this._debonceBuildTree();
|
|
697
|
+
}
|
|
698
|
+
_removeRule(ruleId) {
|
|
699
|
+
this._map.delete(ruleId);
|
|
700
|
+
this._dirty = true;
|
|
701
|
+
this._debonceBuildTree();
|
|
702
|
+
}
|
|
703
|
+
removeRule(rule) {
|
|
704
|
+
this._removeRule(rule.uid);
|
|
705
|
+
}
|
|
706
|
+
updateRange(ruleId, _newRanges) {
|
|
707
|
+
this._removeRule(ruleId);
|
|
708
|
+
this._addRule(ruleId, _newRanges);
|
|
709
|
+
}
|
|
710
|
+
addRangeRules(rules) {
|
|
711
|
+
rules.forEach(({ id: ruleId, ranges }) => {
|
|
712
|
+
if (!ranges.length) return;
|
|
713
|
+
let current = this._map.get(ruleId);
|
|
714
|
+
if (!current) {
|
|
715
|
+
current = ranges;
|
|
716
|
+
this._map.set(ruleId, current);
|
|
717
|
+
} else {
|
|
718
|
+
this._map.set(ruleId, _univerjs_core.Rectangle.mergeRanges([...current, ...ranges]));
|
|
719
|
+
current = this._map.get(ruleId);
|
|
720
|
+
}
|
|
721
|
+
this._map.forEach((value, key) => {
|
|
722
|
+
if (key === ruleId) return;
|
|
723
|
+
const newRanges = _univerjs_core.Rectangle.subtractMulti(value, ranges);
|
|
724
|
+
if (newRanges.length === 0) this._map.delete(key);
|
|
725
|
+
else this._map.set(key, newRanges);
|
|
726
|
+
});
|
|
727
|
+
});
|
|
728
|
+
this._dirty = true;
|
|
729
|
+
this._debonceBuildTree();
|
|
730
|
+
}
|
|
731
|
+
diff(rules) {
|
|
732
|
+
const mutations = [];
|
|
733
|
+
let deleteIndex = 0;
|
|
734
|
+
rules.forEach((rule, index) => {
|
|
735
|
+
var _this$_map$get;
|
|
736
|
+
const newRanges = (_this$_map$get = this._map.get(rule.uid)) !== null && _this$_map$get !== void 0 ? _this$_map$get : [];
|
|
737
|
+
const oldRanges = rule.ranges;
|
|
738
|
+
if (newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !_univerjs_core.Rectangle.equals(range, oldRanges[i])))) mutations.push({
|
|
739
|
+
type: "update",
|
|
740
|
+
ruleId: rule.uid,
|
|
741
|
+
oldRanges,
|
|
742
|
+
newRanges: _univerjs_core.Rectangle.sort(newRanges),
|
|
743
|
+
rule
|
|
744
|
+
});
|
|
745
|
+
if (newRanges.length === 0) {
|
|
746
|
+
mutations.push({
|
|
747
|
+
type: "delete",
|
|
748
|
+
rule,
|
|
749
|
+
index: index - deleteIndex
|
|
750
|
+
});
|
|
751
|
+
deleteIndex++;
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
return mutations;
|
|
755
|
+
}
|
|
756
|
+
diffWithAddition(rules, additionRules) {
|
|
757
|
+
const mutations = [];
|
|
758
|
+
let deleteIndex = 0;
|
|
759
|
+
rules.forEach((rule, index) => {
|
|
760
|
+
var _this$_map$get2;
|
|
761
|
+
const newRanges = (_this$_map$get2 = this._map.get(rule.uid)) !== null && _this$_map$get2 !== void 0 ? _this$_map$get2 : [];
|
|
762
|
+
const oldRanges = rule.ranges;
|
|
763
|
+
if (newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !_univerjs_core.Rectangle.equals(range, oldRanges[i])))) mutations.push({
|
|
764
|
+
type: "update",
|
|
765
|
+
ruleId: rule.uid,
|
|
766
|
+
oldRanges,
|
|
767
|
+
newRanges: _univerjs_core.Rectangle.sort(newRanges),
|
|
768
|
+
rule
|
|
769
|
+
});
|
|
770
|
+
if (newRanges.length === 0) {
|
|
771
|
+
mutations.push({
|
|
772
|
+
type: "delete",
|
|
773
|
+
rule,
|
|
774
|
+
index: index - deleteIndex
|
|
775
|
+
});
|
|
776
|
+
deleteIndex++;
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
Array.from(additionRules).forEach((rule) => {
|
|
780
|
+
var _this$_map$get3;
|
|
781
|
+
const newRanges = (_this$_map$get3 = this._map.get(rule.uid)) !== null && _this$_map$get3 !== void 0 ? _this$_map$get3 : [];
|
|
782
|
+
mutations.push({
|
|
783
|
+
type: "add",
|
|
784
|
+
rule: {
|
|
785
|
+
...rule,
|
|
786
|
+
ranges: _univerjs_core.Rectangle.sort(newRanges)
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
return mutations;
|
|
791
|
+
}
|
|
792
|
+
clone() {
|
|
793
|
+
return new RuleMatrix(new Map(_univerjs_core.Tools.deepClone(Array.from(this._map.entries()))), this._unitId, this._subUnitId, this._univerInstanceService, true);
|
|
794
|
+
}
|
|
795
|
+
getValue(row, col) {
|
|
796
|
+
if (this._dirty) this._buildTree();
|
|
797
|
+
const result = this._tree.search({
|
|
798
|
+
minX: row,
|
|
799
|
+
maxX: row,
|
|
800
|
+
minY: col,
|
|
801
|
+
maxY: col
|
|
802
|
+
});
|
|
803
|
+
return result.length > 0 ? result[0].ruleId : void 0;
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
//#endregion
|
|
808
|
+
//#region src/models/sheet-data-validation-model.ts
|
|
809
|
+
let SheetDataValidationModel = class SheetDataValidationModel extends _univerjs_core.Disposable {
|
|
810
|
+
constructor(_dataValidationModel, _univerInstanceService, _dataValidatorRegistryService, _dataValidationCacheService, _dataValidationFormulaService, _dataValidationCustomFormulaService, _commandService) {
|
|
811
|
+
super();
|
|
812
|
+
this._dataValidationModel = _dataValidationModel;
|
|
813
|
+
this._univerInstanceService = _univerInstanceService;
|
|
814
|
+
this._dataValidatorRegistryService = _dataValidatorRegistryService;
|
|
815
|
+
this._dataValidationCacheService = _dataValidationCacheService;
|
|
816
|
+
this._dataValidationFormulaService = _dataValidationFormulaService;
|
|
817
|
+
this._dataValidationCustomFormulaService = _dataValidationCustomFormulaService;
|
|
818
|
+
this._commandService = _commandService;
|
|
819
|
+
_defineProperty(this, "_ruleMatrixMap", /* @__PURE__ */ new Map());
|
|
820
|
+
_defineProperty(this, "_validStatusChange$", new rxjs.Subject());
|
|
821
|
+
_defineProperty(this, "_ruleChange$", new rxjs.Subject());
|
|
822
|
+
_defineProperty(this, "ruleChange$", this._ruleChange$.asObservable());
|
|
823
|
+
_defineProperty(this, "validStatusChange$", this._validStatusChange$.asObservable());
|
|
824
|
+
this._initRuleUpdateListener();
|
|
825
|
+
this.disposeWithMe(() => {
|
|
826
|
+
this._ruleChange$.complete();
|
|
827
|
+
this._validStatusChange$.complete();
|
|
828
|
+
});
|
|
829
|
+
this._initUniverInstanceListener();
|
|
830
|
+
}
|
|
831
|
+
_initUniverInstanceListener() {
|
|
832
|
+
this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((unit) => {
|
|
833
|
+
this._ruleMatrixMap.delete(unit.getUnitId());
|
|
834
|
+
}));
|
|
835
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
836
|
+
if (command.id === _univerjs_sheets.RemoveSheetMutation.id) {
|
|
837
|
+
const { unitId, subUnitId } = command.params;
|
|
838
|
+
const subUnitMap = this._ruleMatrixMap.get(unitId);
|
|
839
|
+
if (subUnitMap) subUnitMap.delete(subUnitId);
|
|
840
|
+
}
|
|
841
|
+
}));
|
|
842
|
+
}
|
|
843
|
+
_initRuleUpdateListener() {
|
|
844
|
+
const allRules = this._dataValidationModel.getAll();
|
|
845
|
+
for (const [unitId, subUnitMap] of allRules) for (const [subUnitId, rules] of subUnitMap) for (const rule of rules) {
|
|
846
|
+
this._addRule(unitId, subUnitId, rule);
|
|
847
|
+
this._ruleChange$.next({
|
|
848
|
+
type: "add",
|
|
849
|
+
unitId,
|
|
850
|
+
subUnitId,
|
|
851
|
+
rule,
|
|
852
|
+
source: "patched"
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe((ruleChange) => {
|
|
856
|
+
switch (ruleChange.type) {
|
|
857
|
+
case "add":
|
|
858
|
+
this._addRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
|
|
859
|
+
break;
|
|
860
|
+
case "update":
|
|
861
|
+
this._updateRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule.uid, ruleChange.oldRule, ruleChange.updatePayload);
|
|
862
|
+
break;
|
|
863
|
+
case "remove":
|
|
864
|
+
this._removeRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
this._ruleChange$.next(ruleChange);
|
|
868
|
+
}));
|
|
869
|
+
}
|
|
870
|
+
_ensureRuleMatrix(unitId, subUnitId) {
|
|
871
|
+
let unitMap = this._ruleMatrixMap.get(unitId);
|
|
872
|
+
if (!unitMap) {
|
|
873
|
+
unitMap = /* @__PURE__ */ new Map();
|
|
874
|
+
this._ruleMatrixMap.set(unitId, unitMap);
|
|
875
|
+
}
|
|
876
|
+
let matrix = unitMap.get(subUnitId);
|
|
877
|
+
if (!matrix) {
|
|
878
|
+
matrix = new RuleMatrix(/* @__PURE__ */ new Map(), unitId, subUnitId, this._univerInstanceService);
|
|
879
|
+
unitMap.set(subUnitId, matrix);
|
|
880
|
+
}
|
|
881
|
+
return matrix;
|
|
882
|
+
}
|
|
883
|
+
_addRuleSideEffect(unitId, subUnitId, rule) {
|
|
884
|
+
this._ensureRuleMatrix(unitId, subUnitId).addRule(rule);
|
|
885
|
+
this._dataValidationCacheService.addRule(unitId, subUnitId, rule);
|
|
886
|
+
this._dataValidationFormulaService.addRule(unitId, subUnitId, rule);
|
|
887
|
+
this._dataValidationCustomFormulaService.addRule(unitId, subUnitId, rule);
|
|
888
|
+
}
|
|
889
|
+
_addRule(unitId, subUnitId, rule) {
|
|
890
|
+
(Array.isArray(rule) ? rule : [rule]).forEach((item) => {
|
|
891
|
+
this._addRuleSideEffect(unitId, subUnitId, item);
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
_updateRule(unitId, subUnitId, ruleId, oldRule, payload) {
|
|
895
|
+
const ruleMatrix = this._ensureRuleMatrix(unitId, subUnitId);
|
|
896
|
+
const newRule = {
|
|
897
|
+
...oldRule,
|
|
898
|
+
...payload.payload
|
|
899
|
+
};
|
|
900
|
+
if (payload.type === _univerjs_data_validation.UpdateRuleType.RANGE) ruleMatrix.updateRange(ruleId, payload.payload);
|
|
901
|
+
else if (payload.type === _univerjs_data_validation.UpdateRuleType.ALL) ruleMatrix.updateRange(ruleId, payload.payload.ranges);
|
|
902
|
+
this._dataValidationCacheService.removeRule(unitId, subUnitId, oldRule);
|
|
903
|
+
this._dataValidationCacheService.addRule(unitId, subUnitId, newRule);
|
|
904
|
+
this._dataValidationFormulaService.removeRule(unitId, subUnitId, oldRule.uid);
|
|
905
|
+
this._dataValidationFormulaService.addRule(unitId, subUnitId, newRule);
|
|
906
|
+
this._dataValidationCustomFormulaService.deleteByRuleId(unitId, subUnitId, ruleId);
|
|
907
|
+
this._dataValidationCustomFormulaService.addRule(unitId, subUnitId, newRule);
|
|
908
|
+
}
|
|
909
|
+
_removeRule(unitId, subUnitId, oldRule) {
|
|
910
|
+
this._ensureRuleMatrix(unitId, subUnitId).removeRule(oldRule);
|
|
911
|
+
this._dataValidationCacheService.removeRule(unitId, subUnitId, oldRule);
|
|
912
|
+
this._dataValidationCustomFormulaService.deleteByRuleId(unitId, subUnitId, oldRule.uid);
|
|
913
|
+
}
|
|
914
|
+
getValidator(type) {
|
|
915
|
+
return this._dataValidatorRegistryService.getValidatorItem(type);
|
|
916
|
+
}
|
|
917
|
+
getRuleIdByLocation(unitId, subUnitId, row, col) {
|
|
918
|
+
return this._ensureRuleMatrix(unitId, subUnitId).getValue(row, col);
|
|
919
|
+
}
|
|
920
|
+
getRuleByLocation(unitId, subUnitId, row, col) {
|
|
921
|
+
const ruleId = this.getRuleIdByLocation(unitId, subUnitId, row, col);
|
|
922
|
+
if (!ruleId) return;
|
|
923
|
+
return this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
924
|
+
}
|
|
925
|
+
validator(rule, pos, _onCompete) {
|
|
926
|
+
const { col, row, unitId, subUnitId, worksheet } = pos;
|
|
927
|
+
const onCompete = (status, changed) => {
|
|
928
|
+
if (_onCompete) _onCompete(status, changed);
|
|
929
|
+
if (changed) this._validStatusChange$.next({
|
|
930
|
+
unitId,
|
|
931
|
+
subUnitId,
|
|
932
|
+
ruleId: rule.uid,
|
|
933
|
+
status,
|
|
934
|
+
row,
|
|
935
|
+
col
|
|
936
|
+
});
|
|
937
|
+
};
|
|
938
|
+
const cell = worksheet.getCellValueOnly(row, col);
|
|
939
|
+
const validator = this.getValidator(rule.type);
|
|
940
|
+
const cellRaw = worksheet.getCellRaw(row, col);
|
|
941
|
+
const cellValue = getCellValueOrigin(cellRaw);
|
|
942
|
+
if (validator) {
|
|
943
|
+
const cache = this._dataValidationCacheService.ensureCache(unitId, subUnitId);
|
|
944
|
+
const current = cache.getValue(row, col);
|
|
945
|
+
if (current === null || current === void 0) {
|
|
946
|
+
cache.setValue(row, col, _univerjs_core.DataValidationStatus.VALIDATING);
|
|
947
|
+
validator.validator({
|
|
948
|
+
value: cellValue,
|
|
949
|
+
unitId,
|
|
950
|
+
subUnitId,
|
|
951
|
+
row,
|
|
952
|
+
column: col,
|
|
953
|
+
worksheet: pos.worksheet,
|
|
954
|
+
workbook: pos.workbook,
|
|
955
|
+
interceptValue: getCellValueOrigin(cell),
|
|
956
|
+
t: cellRaw === null || cellRaw === void 0 ? void 0 : cellRaw.t
|
|
957
|
+
}, rule).then((status) => {
|
|
958
|
+
const realStatus = status ? _univerjs_core.DataValidationStatus.VALID : _univerjs_core.DataValidationStatus.INVALID;
|
|
959
|
+
const now = cache.getValue(row, col);
|
|
960
|
+
if (realStatus === _univerjs_core.DataValidationStatus.VALID) cache.realDeleteValue(row, col);
|
|
961
|
+
else cache.setValue(row, col, realStatus);
|
|
962
|
+
onCompete(realStatus, current !== now);
|
|
963
|
+
});
|
|
964
|
+
return _univerjs_core.DataValidationStatus.VALIDATING;
|
|
965
|
+
}
|
|
966
|
+
onCompete(current !== null && current !== void 0 ? current : _univerjs_core.DataValidationStatus.VALID, false);
|
|
967
|
+
return current !== null && current !== void 0 ? current : _univerjs_core.DataValidationStatus.VALID;
|
|
968
|
+
} else {
|
|
969
|
+
onCompete(_univerjs_core.DataValidationStatus.VALID, false);
|
|
970
|
+
return _univerjs_core.DataValidationStatus.VALID;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
getRuleObjectMatrix(unitId, subUnitId) {
|
|
974
|
+
return this._ensureRuleMatrix(unitId, subUnitId);
|
|
975
|
+
}
|
|
976
|
+
getRuleById(unitId, subUnitId, ruleId) {
|
|
977
|
+
return this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
978
|
+
}
|
|
979
|
+
getRuleIndex(unitId, subUnitId, ruleId) {
|
|
980
|
+
return this._dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId);
|
|
981
|
+
}
|
|
982
|
+
getRules(unitId, subUnitId) {
|
|
983
|
+
return [...this._dataValidationModel.getRules(unitId, subUnitId)];
|
|
984
|
+
}
|
|
985
|
+
getUnitRules(unitId) {
|
|
986
|
+
return this._dataValidationModel.getUnitRules(unitId);
|
|
987
|
+
}
|
|
988
|
+
deleteUnitRules(unitId) {
|
|
989
|
+
return this._dataValidationModel.deleteUnitRules(unitId);
|
|
990
|
+
}
|
|
991
|
+
getSubUnitIds(unitId) {
|
|
992
|
+
return this._dataValidationModel.getSubUnitIds(unitId);
|
|
993
|
+
}
|
|
994
|
+
getAll() {
|
|
995
|
+
return this._dataValidationModel.getAll();
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
SheetDataValidationModel = __decorate([
|
|
999
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidationModel)),
|
|
1000
|
+
__decorateParam(1, _univerjs_core.IUniverInstanceService),
|
|
1001
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
|
|
1002
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(DataValidationCacheService)),
|
|
1003
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(DataValidationFormulaService)),
|
|
1004
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(DataValidationCustomFormulaService)),
|
|
1005
|
+
__decorateParam(6, _univerjs_core.ICommandService)
|
|
1006
|
+
], SheetDataValidationModel);
|
|
1007
|
+
|
|
1008
|
+
//#endregion
|
|
1009
|
+
//#region src/validators/checkbox-validator.ts
|
|
1010
|
+
const CHECKBOX_FORMULA_1 = 1;
|
|
1011
|
+
const CHECKBOX_FORMULA_2 = 0;
|
|
1012
|
+
function getFailMessage(formula, localeService) {
|
|
1013
|
+
if (_univerjs_core.Tools.isBlank(formula)) return localeService.t("dataValidation.validFail.value");
|
|
1014
|
+
if ((0, _univerjs_core.isFormulaString)(formula)) return localeService.t("dataValidation.validFail.primitive");
|
|
1015
|
+
return "";
|
|
1016
|
+
}
|
|
1017
|
+
const transformCheckboxValue = (value) => _univerjs_core.Tools.isDefine(value) && String(value).toLowerCase() === "true" ? "1" : String(value).toLowerCase() === "false" ? "0" : value;
|
|
1018
|
+
var CheckboxValidator = class extends _univerjs_data_validation.BaseDataValidator {
|
|
1019
|
+
constructor(..._args) {
|
|
1020
|
+
super(..._args);
|
|
1021
|
+
_defineProperty(this, "id", _univerjs_core.DataValidationType.CHECKBOX);
|
|
1022
|
+
_defineProperty(this, "title", "dataValidation.checkbox.title");
|
|
1023
|
+
_defineProperty(this, "operators", []);
|
|
1024
|
+
_defineProperty(this, "scopes", ["sheet"]);
|
|
1025
|
+
_defineProperty(this, "order", 41);
|
|
1026
|
+
_defineProperty(this, "offsetFormulaByRange", false);
|
|
1027
|
+
_defineProperty(this, "_formulaService", this.injector.get(DataValidationFormulaService));
|
|
1028
|
+
_defineProperty(this, "skipDefaultFontRender", (rule, cellValue, pos) => {
|
|
1029
|
+
const { unitId, subUnitId } = pos;
|
|
1030
|
+
const { formula1, formula2 } = this.parseFormulaSync(rule, unitId, subUnitId);
|
|
1031
|
+
const valueStr = `${cellValue !== null && cellValue !== void 0 ? cellValue : ""}`;
|
|
1032
|
+
return !valueStr || valueStr === `${formula1}` || valueStr === `${formula2}`;
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
1036
|
+
const { formula1, formula2 } = rule;
|
|
1037
|
+
const isEqual = formula1 === formula2;
|
|
1038
|
+
if (_univerjs_core.Tools.isBlank(formula1) && _univerjs_core.Tools.isBlank(formula2)) return { success: true };
|
|
1039
|
+
if (isEqual) return {
|
|
1040
|
+
success: false,
|
|
1041
|
+
formula1: this.localeService.t("dataValidation.validFail.checkboxEqual"),
|
|
1042
|
+
formula2: this.localeService.t("dataValidation.validFail.checkboxEqual")
|
|
1043
|
+
};
|
|
1044
|
+
const error1 = getFailMessage(formula1, this.localeService);
|
|
1045
|
+
const error2 = getFailMessage(formula2, this.localeService);
|
|
1046
|
+
return {
|
|
1047
|
+
success: !error1 && !error2,
|
|
1048
|
+
formula1: error1,
|
|
1049
|
+
formula2: error2
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
async parseFormula(rule, unitId, subUnitId) {
|
|
1053
|
+
var _results$, _results$2;
|
|
1054
|
+
const { formula1 = 1, formula2 = 0 } = rule;
|
|
1055
|
+
const results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
|
|
1056
|
+
const originFormula1 = (0, _univerjs_core.isFormulaString)(formula1) ? getFormulaResult(results === null || results === void 0 || (_results$ = results[0]) === null || _results$ === void 0 || (_results$ = _results$.result) === null || _results$ === void 0 ? void 0 : _results$[0][0]) : formula1;
|
|
1057
|
+
const originFormula2 = (0, _univerjs_core.isFormulaString)(formula2) ? getFormulaResult(results === null || results === void 0 || (_results$2 = results[1]) === null || _results$2 === void 0 || (_results$2 = _results$2.result) === null || _results$2 === void 0 ? void 0 : _results$2[0][0]) : formula2;
|
|
1058
|
+
const isFormulaValid = isLegalFormulaResult(String(originFormula1)) && isLegalFormulaResult(String(originFormula2));
|
|
1059
|
+
return {
|
|
1060
|
+
formula1: transformCheckboxValue(originFormula1),
|
|
1061
|
+
formula2: transformCheckboxValue(originFormula2),
|
|
1062
|
+
originFormula1,
|
|
1063
|
+
originFormula2,
|
|
1064
|
+
isFormulaValid
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
getExtraStyle(rule, value) {
|
|
1068
|
+
return { tb: _univerjs_core.WrapStrategy.CLIP };
|
|
1069
|
+
}
|
|
1070
|
+
parseFormulaSync(rule, unitId, subUnitId) {
|
|
1071
|
+
var _results$3, _results$4;
|
|
1072
|
+
const { formula1 = 1, formula2 = 0 } = rule;
|
|
1073
|
+
const results = this._formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid);
|
|
1074
|
+
const originFormula1 = (0, _univerjs_core.isFormulaString)(formula1) ? getFormulaResult(results === null || results === void 0 || (_results$3 = results[0]) === null || _results$3 === void 0 || (_results$3 = _results$3.result) === null || _results$3 === void 0 ? void 0 : _results$3[0][0]) : formula1;
|
|
1075
|
+
const originFormula2 = (0, _univerjs_core.isFormulaString)(formula2) ? getFormulaResult(results === null || results === void 0 || (_results$4 = results[1]) === null || _results$4 === void 0 || (_results$4 = _results$4.result) === null || _results$4 === void 0 ? void 0 : _results$4[0][0]) : formula2;
|
|
1076
|
+
const isFormulaValid = isLegalFormulaResult(String(originFormula1)) && isLegalFormulaResult(String(originFormula2));
|
|
1077
|
+
return {
|
|
1078
|
+
formula1: transformCheckboxValue(originFormula1),
|
|
1079
|
+
formula2: transformCheckboxValue(originFormula2),
|
|
1080
|
+
originFormula1,
|
|
1081
|
+
originFormula2,
|
|
1082
|
+
isFormulaValid
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
async isValidType(cellInfo, formula, rule) {
|
|
1086
|
+
const { value, unitId, subUnitId } = cellInfo;
|
|
1087
|
+
const { formula1, formula2, originFormula1, originFormula2 } = await this.parseFormula(rule, unitId, subUnitId);
|
|
1088
|
+
if (!_univerjs_core.Tools.isDefine(formula1) || !_univerjs_core.Tools.isDefine(formula2)) return true;
|
|
1089
|
+
return _univerjs_core.Tools.isDefine(value) && (String(value) === String(formula1) || String(value) === String(formula2) || String(value) === String(originFormula1 !== null && originFormula1 !== void 0 ? originFormula1 : "") || String(value) === String(originFormula2 !== null && originFormula2 !== void 0 ? originFormula2 : ""));
|
|
1090
|
+
}
|
|
1091
|
+
generateRuleErrorMessage(rule) {
|
|
1092
|
+
return this.localeService.t("dataValidation.checkbox.error");
|
|
1093
|
+
}
|
|
1094
|
+
generateRuleName(rule) {
|
|
1095
|
+
return this.titleStr;
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
|
|
1099
|
+
//#endregion
|
|
1100
|
+
//#region src/common/date-text-map.ts
|
|
1101
|
+
/**
|
|
1102
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1103
|
+
*
|
|
1104
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1105
|
+
* you may not use this file except in compliance with the License.
|
|
1106
|
+
* You may obtain a copy of the License at
|
|
1107
|
+
*
|
|
1108
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1109
|
+
*
|
|
1110
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1111
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1112
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1113
|
+
* See the License for the specific language governing permissions and
|
|
1114
|
+
* limitations under the License.
|
|
1115
|
+
*/
|
|
1116
|
+
const DateOperatorNameMap = {
|
|
1117
|
+
[_univerjs_core.DataValidationOperator.BETWEEN]: "dataValidation.date.operators.between",
|
|
1118
|
+
[_univerjs_core.DataValidationOperator.EQUAL]: "dataValidation.date.operators.equal",
|
|
1119
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
|
|
1120
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
|
|
1121
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN]: "dataValidation.date.operators.lessThan",
|
|
1122
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
|
|
1123
|
+
[_univerjs_core.DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
|
|
1124
|
+
[_univerjs_core.DataValidationOperator.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
|
|
1125
|
+
};
|
|
1126
|
+
const DateOperatorTextMap = {
|
|
1127
|
+
[_univerjs_core.DataValidationOperator.BETWEEN]: "dataValidation.date.operators.between",
|
|
1128
|
+
[_univerjs_core.DataValidationOperator.EQUAL]: "dataValidation.date.operators.equal",
|
|
1129
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
|
|
1130
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
|
|
1131
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN]: "dataValidation.date.operators.lessThan",
|
|
1132
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
|
|
1133
|
+
[_univerjs_core.DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
|
|
1134
|
+
[_univerjs_core.DataValidationOperator.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
|
|
1135
|
+
};
|
|
1136
|
+
const DateOperatorTitleMap = {
|
|
1137
|
+
[_univerjs_core.DataValidationOperator.BETWEEN]: "dataValidation.date.ruleName.between",
|
|
1138
|
+
[_univerjs_core.DataValidationOperator.EQUAL]: "dataValidation.date.ruleName.equal",
|
|
1139
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN]: "dataValidation.date.ruleName.greaterThan",
|
|
1140
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.ruleName.greaterThanOrEqual",
|
|
1141
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN]: "dataValidation.date.ruleName.lessThan",
|
|
1142
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.ruleName.lessThanOrEqual",
|
|
1143
|
+
[_univerjs_core.DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.ruleName.notBetween",
|
|
1144
|
+
[_univerjs_core.DataValidationOperator.NOT_EQUAL]: "dataValidation.date.ruleName.notEqual",
|
|
1145
|
+
NONE: "dataValidation.date.ruleName.legal"
|
|
1146
|
+
};
|
|
1147
|
+
const DateOperatorErrorTitleMap = {
|
|
1148
|
+
[_univerjs_core.DataValidationOperator.BETWEEN]: "dataValidation.date.errorMsg.between",
|
|
1149
|
+
[_univerjs_core.DataValidationOperator.EQUAL]: "dataValidation.date.errorMsg.equal",
|
|
1150
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN]: "dataValidation.date.errorMsg.greaterThan",
|
|
1151
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.greaterThanOrEqual",
|
|
1152
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN]: "dataValidation.date.errorMsg.lessThan",
|
|
1153
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.lessThanOrEqual",
|
|
1154
|
+
[_univerjs_core.DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.errorMsg.notBetween",
|
|
1155
|
+
[_univerjs_core.DataValidationOperator.NOT_EQUAL]: "dataValidation.date.errorMsg.notEqual",
|
|
1156
|
+
NONE: "dataValidation.date.errorMsg.legal"
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
//#endregion
|
|
1160
|
+
//#region src/types/const/two-formula-operators.ts
|
|
1161
|
+
/**
|
|
1162
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1163
|
+
*
|
|
1164
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1165
|
+
* you may not use this file except in compliance with the License.
|
|
1166
|
+
* You may obtain a copy of the License at
|
|
1167
|
+
*
|
|
1168
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1169
|
+
*
|
|
1170
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1171
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1172
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1173
|
+
* See the License for the specific language governing permissions and
|
|
1174
|
+
* limitations under the License.
|
|
1175
|
+
*/
|
|
1176
|
+
const TWO_FORMULA_OPERATOR_COUNT = [_univerjs_core.DataValidationOperator.BETWEEN, _univerjs_core.DataValidationOperator.NOT_BETWEEN];
|
|
1177
|
+
|
|
1178
|
+
//#endregion
|
|
1179
|
+
//#region src/validators/const.ts
|
|
1180
|
+
/**
|
|
1181
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1182
|
+
*
|
|
1183
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1184
|
+
* you may not use this file except in compliance with the License.
|
|
1185
|
+
* You may obtain a copy of the License at
|
|
1186
|
+
*
|
|
1187
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1188
|
+
*
|
|
1189
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1190
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1191
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1192
|
+
* See the License for the specific language governing permissions and
|
|
1193
|
+
* limitations under the License.
|
|
1194
|
+
*/
|
|
1195
|
+
const FORMULA1 = "{FORMULA1}";
|
|
1196
|
+
const FORMULA2 = "{FORMULA2}";
|
|
1197
|
+
|
|
1198
|
+
//#endregion
|
|
1199
|
+
//#region src/validators/date-validator.ts
|
|
1200
|
+
const transformDate2SerialNumber = (value) => {
|
|
1201
|
+
var _numfmt$parseDate, _numfmt$parseDate2;
|
|
1202
|
+
if (value === void 0 || value === null || typeof value === "boolean") return;
|
|
1203
|
+
if (typeof value === "number" || !Number.isNaN(+value)) return +value;
|
|
1204
|
+
const v = (_numfmt$parseDate = _univerjs_core.numfmt.parseDate(value)) === null || _numfmt$parseDate === void 0 ? void 0 : _numfmt$parseDate.v;
|
|
1205
|
+
if (_univerjs_core.Tools.isDefine(v)) return v;
|
|
1206
|
+
return (_numfmt$parseDate2 = _univerjs_core.numfmt.parseDate((0, _univerjs_core.dateKit)(value).format("YYYY-MM-DD HH:mm:ss"))) === null || _numfmt$parseDate2 === void 0 ? void 0 : _numfmt$parseDate2.v;
|
|
1207
|
+
};
|
|
1208
|
+
var DateValidator = class extends _univerjs_data_validation.BaseDataValidator {
|
|
1209
|
+
constructor(..._args) {
|
|
1210
|
+
super(..._args);
|
|
1211
|
+
_defineProperty(this, "id", _univerjs_core.DataValidationType.DATE);
|
|
1212
|
+
_defineProperty(this, "title", "dataValidation.date.title");
|
|
1213
|
+
_defineProperty(this, "order", 40);
|
|
1214
|
+
_defineProperty(this, "operators", [
|
|
1215
|
+
_univerjs_core.DataValidationOperator.BETWEEN,
|
|
1216
|
+
_univerjs_core.DataValidationOperator.EQUAL,
|
|
1217
|
+
_univerjs_core.DataValidationOperator.GREATER_THAN,
|
|
1218
|
+
_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL,
|
|
1219
|
+
_univerjs_core.DataValidationOperator.LESS_THAN,
|
|
1220
|
+
_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL,
|
|
1221
|
+
_univerjs_core.DataValidationOperator.NOT_BETWEEN,
|
|
1222
|
+
_univerjs_core.DataValidationOperator.NOT_EQUAL
|
|
1223
|
+
]);
|
|
1224
|
+
_defineProperty(this, "scopes", ["sheet"]);
|
|
1225
|
+
_defineProperty(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
|
|
1226
|
+
_defineProperty(this, "_lexerTreeBuilder", this.injector.get(_univerjs_engine_formula.LexerTreeBuilder));
|
|
1227
|
+
}
|
|
1228
|
+
async parseFormula(rule, unitId, subUnitId, row, column) {
|
|
1229
|
+
const formulaResult1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column);
|
|
1230
|
+
const formulaResult2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column);
|
|
1231
|
+
const { formula1, formula2 } = rule;
|
|
1232
|
+
const isFormulaValid = isLegalFormulaResult(String(formulaResult1 === null || formulaResult1 === void 0 ? void 0 : formulaResult1.v)) && isLegalFormulaResult(String(formulaResult2 === null || formulaResult2 === void 0 ? void 0 : formulaResult2.v));
|
|
1233
|
+
return {
|
|
1234
|
+
formula1: transformDate2SerialNumber((0, _univerjs_core.isFormulaString)(formula1) ? formulaResult1 === null || formulaResult1 === void 0 ? void 0 : formulaResult1.v : formula1),
|
|
1235
|
+
formula2: transformDate2SerialNumber((0, _univerjs_core.isFormulaString)(formula2) ? formulaResult2 === null || formulaResult2 === void 0 ? void 0 : formulaResult2.v : formula2),
|
|
1236
|
+
isFormulaValid
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
async isValidType(info) {
|
|
1240
|
+
const { interceptValue, value } = info;
|
|
1241
|
+
if (typeof value === "number" && typeof interceptValue === "string") return Boolean(_univerjs_core.numfmt.parseDate(interceptValue));
|
|
1242
|
+
if (typeof interceptValue === "string") return Boolean(_univerjs_core.numfmt.parseDate(interceptValue));
|
|
1243
|
+
return false;
|
|
1244
|
+
}
|
|
1245
|
+
_validatorSingleFormula(formula) {
|
|
1246
|
+
return !_univerjs_core.Tools.isBlank(formula) && ((0, _univerjs_core.isFormulaString)(formula) || !Number.isNaN(+formula) || Boolean(formula && _univerjs_core.numfmt.parseDate(formula)));
|
|
1247
|
+
}
|
|
1248
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
1249
|
+
const operator = rule.operator;
|
|
1250
|
+
if (!operator) return { success: true };
|
|
1251
|
+
const formula1Success = this._validatorSingleFormula(rule.formula1);
|
|
1252
|
+
const errorMsg = this.localeService.t("dataValidation.validFail.date");
|
|
1253
|
+
if (TWO_FORMULA_OPERATOR_COUNT.includes(operator)) {
|
|
1254
|
+
const formula2Success = this._validatorSingleFormula(rule.formula2);
|
|
1255
|
+
return {
|
|
1256
|
+
success: formula1Success && formula2Success,
|
|
1257
|
+
formula1: formula1Success ? void 0 : errorMsg,
|
|
1258
|
+
formula2: formula2Success ? void 0 : errorMsg
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
return {
|
|
1262
|
+
success: formula1Success,
|
|
1263
|
+
formula1: formula1Success ? void 0 : errorMsg
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
normalizeFormula(rule, _unitId, _subUnitId) {
|
|
1267
|
+
const { formula1, formula2, bizInfo } = rule;
|
|
1268
|
+
const normlizeSingleFormula = (formula) => {
|
|
1269
|
+
if (!formula) return formula;
|
|
1270
|
+
let date;
|
|
1271
|
+
if (!Number.isNaN(+formula)) date = _univerjs_core.numfmt.dateFromSerial(+formula);
|
|
1272
|
+
else {
|
|
1273
|
+
var _numfmt$parseDate3;
|
|
1274
|
+
const res = (_numfmt$parseDate3 = _univerjs_core.numfmt.parseDate(formula)) === null || _numfmt$parseDate3 === void 0 ? void 0 : _numfmt$parseDate3.v;
|
|
1275
|
+
if (res === void 0 || res === null) return "";
|
|
1276
|
+
date = _univerjs_core.numfmt.dateFromSerial(res);
|
|
1277
|
+
}
|
|
1278
|
+
return (0, _univerjs_core.dateKit)(`${date[0]}/${date[1]}/${date[2]} ${date[3]}:${date[4]}:${date[5]}`).format((bizInfo === null || bizInfo === void 0 ? void 0 : bizInfo.showTime) ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD");
|
|
1279
|
+
};
|
|
1280
|
+
return {
|
|
1281
|
+
formula1: (0, _univerjs_core.isFormulaString)(formula1) ? formula1 : normlizeSingleFormula(`${formula1}`),
|
|
1282
|
+
formula2: (0, _univerjs_core.isFormulaString)(formula2) ? formula2 : normlizeSingleFormula(`${formula2}`)
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
transform(cellInfo, _formula, _rule) {
|
|
1286
|
+
const { value } = cellInfo;
|
|
1287
|
+
return {
|
|
1288
|
+
...cellInfo,
|
|
1289
|
+
value: transformDate2SerialNumber(value)
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
get operatorNames() {
|
|
1293
|
+
return this.operators.map((operator) => this.localeService.t(DateOperatorNameMap[operator]));
|
|
1294
|
+
}
|
|
1295
|
+
generateRuleName(rule) {
|
|
1296
|
+
var _rule$formula, _rule$formula2;
|
|
1297
|
+
if (!rule.operator) return this.localeService.t(DateOperatorTitleMap.NONE);
|
|
1298
|
+
const ruleName = this.localeService.t(DateOperatorTitleMap[rule.operator]).replace(FORMULA1, (_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "").replace(FORMULA2, (_rule$formula2 = rule.formula2) !== null && _rule$formula2 !== void 0 ? _rule$formula2 : "");
|
|
1299
|
+
return `${this.titleStr} ${ruleName}`;
|
|
1300
|
+
}
|
|
1301
|
+
generateRuleErrorMessage(rule, pos) {
|
|
1302
|
+
if (!rule.operator) return this.titleStr;
|
|
1303
|
+
const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, pos);
|
|
1304
|
+
return `${this.localeService.t(DateOperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 !== null && transformedFormula1 !== void 0 ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 !== null && transformedFormula2 !== void 0 ? transformedFormula2 : "")}`;
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
//#endregion
|
|
1309
|
+
//#region src/types/const/operator-text-map.ts
|
|
1310
|
+
/**
|
|
1311
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1312
|
+
*
|
|
1313
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1314
|
+
* you may not use this file except in compliance with the License.
|
|
1315
|
+
* You may obtain a copy of the License at
|
|
1316
|
+
*
|
|
1317
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1318
|
+
*
|
|
1319
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1320
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1321
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1322
|
+
* See the License for the specific language governing permissions and
|
|
1323
|
+
* limitations under the License.
|
|
1324
|
+
*/
|
|
1325
|
+
const OperatorTextMap = {
|
|
1326
|
+
[_univerjs_core.DataValidationOperator.BETWEEN]: "dataValidation.operators.between",
|
|
1327
|
+
[_univerjs_core.DataValidationOperator.EQUAL]: "dataValidation.operators.equal",
|
|
1328
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN]: "dataValidation.operators.greaterThan",
|
|
1329
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.operators.greaterThanOrEqual",
|
|
1330
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN]: "dataValidation.operators.lessThan",
|
|
1331
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.operators.lessThanOrEqual",
|
|
1332
|
+
[_univerjs_core.DataValidationOperator.NOT_BETWEEN]: "dataValidation.operators.notBetween",
|
|
1333
|
+
[_univerjs_core.DataValidationOperator.NOT_EQUAL]: "dataValidation.operators.notEqual"
|
|
1334
|
+
};
|
|
1335
|
+
const OperatorTitleMap = {
|
|
1336
|
+
[_univerjs_core.DataValidationOperator.BETWEEN]: "dataValidation.ruleName.between",
|
|
1337
|
+
[_univerjs_core.DataValidationOperator.EQUAL]: "dataValidation.ruleName.equal",
|
|
1338
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN]: "dataValidation.ruleName.greaterThan",
|
|
1339
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.ruleName.greaterThanOrEqual",
|
|
1340
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN]: "dataValidation.ruleName.lessThan",
|
|
1341
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.ruleName.lessThanOrEqual",
|
|
1342
|
+
[_univerjs_core.DataValidationOperator.NOT_BETWEEN]: "dataValidation.ruleName.notBetween",
|
|
1343
|
+
[_univerjs_core.DataValidationOperator.NOT_EQUAL]: "dataValidation.ruleName.notEqual"
|
|
1344
|
+
};
|
|
1345
|
+
const OperatorErrorTitleMap = {
|
|
1346
|
+
[_univerjs_core.DataValidationOperator.BETWEEN]: "dataValidation.errorMsg.between",
|
|
1347
|
+
[_univerjs_core.DataValidationOperator.EQUAL]: "dataValidation.errorMsg.equal",
|
|
1348
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
|
|
1349
|
+
[_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
|
|
1350
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN]: "dataValidation.errorMsg.lessThan",
|
|
1351
|
+
[_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
|
|
1352
|
+
[_univerjs_core.DataValidationOperator.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
|
|
1353
|
+
[_univerjs_core.DataValidationOperator.NOT_EQUAL]: "dataValidation.errorMsg.notEqual",
|
|
1354
|
+
NONE: "dataValidation.errorMsg.legal"
|
|
1355
|
+
};
|
|
1356
|
+
|
|
1357
|
+
//#endregion
|
|
1358
|
+
//#region src/validators/decimal-validator.ts
|
|
1359
|
+
function getCellValueNumber(cellValue) {
|
|
1360
|
+
return +cellValue;
|
|
1361
|
+
}
|
|
1362
|
+
var DecimalValidator = class extends _univerjs_data_validation.BaseDataValidator {
|
|
1363
|
+
constructor(..._args) {
|
|
1364
|
+
super(..._args);
|
|
1365
|
+
_defineProperty(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
|
|
1366
|
+
_defineProperty(this, "id", _univerjs_core.DataValidationType.DECIMAL);
|
|
1367
|
+
_defineProperty(this, "_lexerTreeBuilder", this.injector.get(_univerjs_engine_formula.LexerTreeBuilder));
|
|
1368
|
+
_defineProperty(this, "title", "dataValidation.decimal.title");
|
|
1369
|
+
_defineProperty(this, "order", 20);
|
|
1370
|
+
_defineProperty(this, "operators", [
|
|
1371
|
+
_univerjs_core.DataValidationOperator.BETWEEN,
|
|
1372
|
+
_univerjs_core.DataValidationOperator.EQUAL,
|
|
1373
|
+
_univerjs_core.DataValidationOperator.GREATER_THAN,
|
|
1374
|
+
_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL,
|
|
1375
|
+
_univerjs_core.DataValidationOperator.LESS_THAN,
|
|
1376
|
+
_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL,
|
|
1377
|
+
_univerjs_core.DataValidationOperator.NOT_BETWEEN,
|
|
1378
|
+
_univerjs_core.DataValidationOperator.NOT_EQUAL
|
|
1379
|
+
]);
|
|
1380
|
+
_defineProperty(this, "scopes", ["sheet"]);
|
|
1381
|
+
}
|
|
1382
|
+
_isFormulaOrNumber(formula) {
|
|
1383
|
+
return !_univerjs_core.Tools.isBlank(formula) && ((0, _univerjs_core.isFormulaString)(formula) || !Number.isNaN(+formula));
|
|
1384
|
+
}
|
|
1385
|
+
async isValidType(cellInfo, formula, rule) {
|
|
1386
|
+
const { value: cellValue } = cellInfo;
|
|
1387
|
+
return !Number.isNaN(getCellValueNumber(cellValue));
|
|
1388
|
+
}
|
|
1389
|
+
transform(cellInfo, formula, rule) {
|
|
1390
|
+
const { value: cellValue } = cellInfo;
|
|
1391
|
+
return {
|
|
1392
|
+
...cellInfo,
|
|
1393
|
+
value: getCellValueNumber(cellValue)
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
_parseNumber(formula) {
|
|
1397
|
+
if (formula === void 0 || formula === null) return NaN;
|
|
1398
|
+
return +formula;
|
|
1399
|
+
}
|
|
1400
|
+
async parseFormula(rule, unitId, subUnitId, row, column) {
|
|
1401
|
+
const formulaResult1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column);
|
|
1402
|
+
const formulaResult2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column);
|
|
1403
|
+
const { formula1, formula2 } = rule;
|
|
1404
|
+
const isFormulaValid = isLegalFormulaResult(String(formulaResult1 === null || formulaResult1 === void 0 ? void 0 : formulaResult1.v)) && isLegalFormulaResult(String(formulaResult2 === null || formulaResult2 === void 0 ? void 0 : formulaResult2.v));
|
|
1405
|
+
return {
|
|
1406
|
+
formula1: this._parseNumber((0, _univerjs_core.isFormulaString)(formula1) ? formulaResult1 === null || formulaResult1 === void 0 ? void 0 : formulaResult1.v : formula1),
|
|
1407
|
+
formula2: this._parseNumber((0, _univerjs_core.isFormulaString)(formula2) ? formulaResult2 === null || formulaResult2 === void 0 ? void 0 : formulaResult2.v : formula2),
|
|
1408
|
+
isFormulaValid
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
1412
|
+
const operator = rule.operator;
|
|
1413
|
+
if (!operator) return { success: true };
|
|
1414
|
+
const formula1Success = _univerjs_core.Tools.isDefine(rule.formula1) && this._isFormulaOrNumber(rule.formula1);
|
|
1415
|
+
const formula2Success = _univerjs_core.Tools.isDefine(rule.formula2) && this._isFormulaOrNumber(rule.formula2);
|
|
1416
|
+
const isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator);
|
|
1417
|
+
const errorMsg = this.localeService.t("dataValidation.validFail.number");
|
|
1418
|
+
if (isTwoFormula) return {
|
|
1419
|
+
success: formula1Success && formula2Success,
|
|
1420
|
+
formula1: formula1Success ? void 0 : errorMsg,
|
|
1421
|
+
formula2: formula2Success ? void 0 : errorMsg
|
|
1422
|
+
};
|
|
1423
|
+
return {
|
|
1424
|
+
success: formula1Success,
|
|
1425
|
+
formula1: formula1Success ? "" : errorMsg
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
generateRuleErrorMessage(rule, position) {
|
|
1429
|
+
if (!rule.operator) return this.localeService.t(OperatorErrorTitleMap.NONE).replace("{TYPE}", this.titleStr);
|
|
1430
|
+
const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, position);
|
|
1431
|
+
return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 !== null && transformedFormula1 !== void 0 ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 !== null && transformedFormula2 !== void 0 ? transformedFormula2 : "")}`;
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
|
|
1435
|
+
//#endregion
|
|
1436
|
+
//#region src/validators/list-validator.ts
|
|
1437
|
+
function getRuleFormulaResultSet(result) {
|
|
1438
|
+
if (!result) return [];
|
|
1439
|
+
const resultSet = /* @__PURE__ */ new Set();
|
|
1440
|
+
for (let i = 0, rowLen = result.length; i < rowLen; i++) {
|
|
1441
|
+
const row = result[i];
|
|
1442
|
+
if (!row) continue;
|
|
1443
|
+
for (let j = 0, colLen = row.length; j < colLen; j++) {
|
|
1444
|
+
const cell = row[j];
|
|
1445
|
+
const value = getCellValueOrigin(cell);
|
|
1446
|
+
if (value !== null && value !== void 0) {
|
|
1447
|
+
var _cell$s;
|
|
1448
|
+
if (typeof value !== "string" && typeof (cell === null || cell === void 0 ? void 0 : cell.s) === "object" && ((_cell$s = cell.s) === null || _cell$s === void 0 || (_cell$s = _cell$s.n) === null || _cell$s === void 0 ? void 0 : _cell$s.pattern)) {
|
|
1449
|
+
resultSet.add(_univerjs_core.numfmt.format(cell.s.n.pattern, value, { throws: false }));
|
|
1450
|
+
continue;
|
|
1451
|
+
}
|
|
1452
|
+
const valueStr = typeof value === "string" ? value : String(value);
|
|
1453
|
+
if (isLegalFormulaResult(valueStr)) resultSet.add(valueStr);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
return [...resultSet];
|
|
1458
|
+
}
|
|
1459
|
+
const supportedFormula = [
|
|
1460
|
+
"if",
|
|
1461
|
+
"indirect",
|
|
1462
|
+
"choose",
|
|
1463
|
+
"offset"
|
|
1464
|
+
];
|
|
1465
|
+
function isValidListFormula(formula, lexer) {
|
|
1466
|
+
if (!(0, _univerjs_core.isFormulaString)(formula)) return true;
|
|
1467
|
+
if ((0, _univerjs_engine_formula.isReferenceString)(formula.slice(1))) return true;
|
|
1468
|
+
const nodes = lexer.sequenceNodesBuilder(formula);
|
|
1469
|
+
return nodes && nodes.some((node) => typeof node === "object" && node.nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION && supportedFormula.indexOf(node.token.toLowerCase()) > -1);
|
|
1470
|
+
}
|
|
1471
|
+
function isRuleIntersects(rule, sheetName) {
|
|
1472
|
+
const { formula1 = "", ranges } = rule;
|
|
1473
|
+
if ((0, _univerjs_engine_formula.isReferenceString)(formula1.slice(1))) {
|
|
1474
|
+
const refRange = (0, _univerjs_engine_formula.deserializeRangeWithSheet)(formula1.slice(1));
|
|
1475
|
+
if ((!refRange.sheetName || refRange.sheetName === sheetName) && ranges.some((range) => _univerjs_core.Rectangle.intersects(range, refRange.range))) return true;
|
|
1476
|
+
}
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1479
|
+
var ListValidator = class extends _univerjs_data_validation.BaseDataValidator {
|
|
1480
|
+
constructor(..._args) {
|
|
1481
|
+
super(..._args);
|
|
1482
|
+
_defineProperty(this, "formulaService", this.injector.get(DataValidationFormulaService));
|
|
1483
|
+
_defineProperty(this, "_lexer", this.injector.get(_univerjs_engine_formula.LexerTreeBuilder));
|
|
1484
|
+
_defineProperty(this, "_univerInstanceService", this.injector.get(_univerjs_core.IUniverInstanceService));
|
|
1485
|
+
_defineProperty(this, "_listCacheService", this.injector.get(DataValidationListCacheService));
|
|
1486
|
+
_defineProperty(this, "order", 50);
|
|
1487
|
+
_defineProperty(this, "offsetFormulaByRange", false);
|
|
1488
|
+
_defineProperty(this, "id", _univerjs_core.DataValidationType.LIST);
|
|
1489
|
+
_defineProperty(this, "title", "dataValidation.list.title");
|
|
1490
|
+
_defineProperty(this, "operators", []);
|
|
1491
|
+
_defineProperty(this, "scopes", ["sheet"]);
|
|
1492
|
+
_defineProperty(this, "skipDefaultFontRender", (rule) => {
|
|
1493
|
+
return rule.renderMode !== _univerjs_core.DataValidationRenderMode.TEXT;
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
1497
|
+
var _rule$formula, _this$_univerInstance;
|
|
1498
|
+
const success = !_univerjs_core.Tools.isBlank(rule.formula1);
|
|
1499
|
+
const valid = isValidListFormula((_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "", this._lexer);
|
|
1500
|
+
const sheetName = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 || (_this$_univerInstance = _this$_univerInstance.getSheetBySheetId(subUnitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getName();
|
|
1501
|
+
const isIntersects = isRuleIntersects(rule, sheetName !== null && sheetName !== void 0 ? sheetName : "");
|
|
1502
|
+
return {
|
|
1503
|
+
success: Boolean(success && valid && !isIntersects),
|
|
1504
|
+
formula1: success ? valid ? !isIntersects ? void 0 : this.localeService.t("dataValidation.validFail.listIntersects") : this.localeService.t("dataValidation.validFail.listInvalid") : this.localeService.t("dataValidation.validFail.list")
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
getExtraStyle(rule, value, { style: defaultStyle }) {
|
|
1508
|
+
var _ref;
|
|
1509
|
+
const tb = (_ref = defaultStyle.tb !== _univerjs_core.WrapStrategy.OVERFLOW ? defaultStyle.tb : _univerjs_core.WrapStrategy.CLIP) !== null && _ref !== void 0 ? _ref : _univerjs_core.WrapStrategy.WRAP;
|
|
1510
|
+
if (rule.type === _univerjs_core.DataValidationType.LIST && (rule.renderMode === _univerjs_core.DataValidationRenderMode.ARROW || rule.renderMode === _univerjs_core.DataValidationRenderMode.TEXT)) {
|
|
1511
|
+
const color = this.getListWithColorMap(rule)[`${value !== null && value !== void 0 ? value : ""}`];
|
|
1512
|
+
if (color) return {
|
|
1513
|
+
bg: { rgb: color },
|
|
1514
|
+
tb
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
return { tb };
|
|
1518
|
+
}
|
|
1519
|
+
parseCellValue(cellValue) {
|
|
1520
|
+
return deserializeListOptions(cellValue.toString());
|
|
1521
|
+
}
|
|
1522
|
+
async parseFormula(rule, unitId, subUnitId) {
|
|
1523
|
+
var _results$;
|
|
1524
|
+
const results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
|
|
1525
|
+
const formulaResult1 = getFormulaResult(results === null || results === void 0 || (_results$ = results[0]) === null || _results$ === void 0 || (_results$ = _results$.result) === null || _results$ === void 0 ? void 0 : _results$[0][0]);
|
|
1526
|
+
return {
|
|
1527
|
+
formula1: void 0,
|
|
1528
|
+
formula2: void 0,
|
|
1529
|
+
isFormulaValid: isLegalFormulaResult(String(formulaResult1))
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
async isValidType(cellInfo, formula, rule) {
|
|
1533
|
+
const { value, unitId, subUnitId } = cellInfo;
|
|
1534
|
+
const { formula1 = "" } = rule;
|
|
1535
|
+
const formula1Result = (0, _univerjs_core.isFormulaString)(formula1) ? this._listCacheService.getOrCompute(unitId, subUnitId, rule).list : deserializeListOptions(formula1);
|
|
1536
|
+
return this.parseCellValue(value).every((i) => formula1Result.includes(i));
|
|
1537
|
+
}
|
|
1538
|
+
generateRuleName() {
|
|
1539
|
+
return this.localeService.t("dataValidation.list.name");
|
|
1540
|
+
}
|
|
1541
|
+
generateRuleErrorMessage() {
|
|
1542
|
+
return this.localeService.t("dataValidation.list.error");
|
|
1543
|
+
}
|
|
1544
|
+
_getUnitAndSubUnit(currentUnitId, currentSubUnitId) {
|
|
1545
|
+
var _ref2, _ref3;
|
|
1546
|
+
const workbook = (_ref2 = currentUnitId ? this._univerInstanceService.getUniverSheetInstance(currentUnitId) : void 0) !== null && _ref2 !== void 0 ? _ref2 : this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
1547
|
+
if (!workbook) return null;
|
|
1548
|
+
const worksheet = (_ref3 = currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : void 0) !== null && _ref3 !== void 0 ? _ref3 : workbook.getActiveSheet();
|
|
1549
|
+
if (!worksheet) return null;
|
|
1550
|
+
return {
|
|
1551
|
+
unitId: workbook.getUnitId(),
|
|
1552
|
+
subUnitId: worksheet.getSheetId()
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
getList(rule, currentUnitId, currentSubUnitId) {
|
|
1556
|
+
const location = this._getUnitAndSubUnit(currentUnitId, currentSubUnitId);
|
|
1557
|
+
if (!location) return [];
|
|
1558
|
+
const { unitId, subUnitId } = location;
|
|
1559
|
+
return this._listCacheService.getOrCompute(unitId, subUnitId, rule).list;
|
|
1560
|
+
}
|
|
1561
|
+
async getListAsync(rule, currentUnitId, currentSubUnitId) {
|
|
1562
|
+
var _results$2;
|
|
1563
|
+
const { formula1 = "" } = rule;
|
|
1564
|
+
const location = this._getUnitAndSubUnit(currentUnitId, currentSubUnitId);
|
|
1565
|
+
if (!location) return [];
|
|
1566
|
+
const { unitId, subUnitId } = location;
|
|
1567
|
+
const results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
|
|
1568
|
+
return (0, _univerjs_core.isFormulaString)(formula1) ? getRuleFormulaResultSet(results === null || results === void 0 || (_results$2 = results[0]) === null || _results$2 === void 0 || (_results$2 = _results$2.result) === null || _results$2 === void 0 ? void 0 : _results$2[0][0]) : deserializeListOptions(formula1);
|
|
1569
|
+
}
|
|
1570
|
+
getListWithColor(rule, currentUnitId, currentSubUnitId) {
|
|
1571
|
+
const location = this._getUnitAndSubUnit(currentUnitId, currentSubUnitId);
|
|
1572
|
+
if (!location) return [];
|
|
1573
|
+
const { unitId, subUnitId } = location;
|
|
1574
|
+
return this._listCacheService.getOrCompute(unitId, subUnitId, rule).listWithColor;
|
|
1575
|
+
}
|
|
1576
|
+
getListWithColorMap(rule, currentUnitId, currentSubUnitId) {
|
|
1577
|
+
const location = this._getUnitAndSubUnit(currentUnitId, currentSubUnitId);
|
|
1578
|
+
if (!location) return {};
|
|
1579
|
+
const { unitId, subUnitId } = location;
|
|
1580
|
+
return this._listCacheService.getOrCompute(unitId, subUnitId, rule).colorMap;
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
|
|
1584
|
+
//#endregion
|
|
1585
|
+
//#region src/validators/text-length-validator.ts
|
|
1586
|
+
var TextLengthValidator = class extends _univerjs_data_validation.BaseDataValidator {
|
|
1587
|
+
constructor(..._args) {
|
|
1588
|
+
super(..._args);
|
|
1589
|
+
_defineProperty(this, "id", _univerjs_core.DataValidationType.TEXT_LENGTH);
|
|
1590
|
+
_defineProperty(this, "title", "dataValidation.textLength.title");
|
|
1591
|
+
_defineProperty(this, "_lexerTreeBuilder", this.injector.get(_univerjs_engine_formula.LexerTreeBuilder));
|
|
1592
|
+
_defineProperty(this, "order", 30);
|
|
1593
|
+
_defineProperty(this, "operators", [
|
|
1594
|
+
_univerjs_core.DataValidationOperator.BETWEEN,
|
|
1595
|
+
_univerjs_core.DataValidationOperator.EQUAL,
|
|
1596
|
+
_univerjs_core.DataValidationOperator.GREATER_THAN,
|
|
1597
|
+
_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL,
|
|
1598
|
+
_univerjs_core.DataValidationOperator.LESS_THAN,
|
|
1599
|
+
_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL,
|
|
1600
|
+
_univerjs_core.DataValidationOperator.NOT_BETWEEN,
|
|
1601
|
+
_univerjs_core.DataValidationOperator.NOT_EQUAL
|
|
1602
|
+
]);
|
|
1603
|
+
_defineProperty(this, "scopes", ["sheet"]);
|
|
1604
|
+
_defineProperty(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
|
|
1605
|
+
}
|
|
1606
|
+
_isFormulaOrInt(formula) {
|
|
1607
|
+
return !_univerjs_core.Tools.isBlank(formula) && ((0, _univerjs_core.isFormulaString)(formula) || !Number.isNaN(+formula) && Number.isInteger(+formula));
|
|
1608
|
+
}
|
|
1609
|
+
validatorFormula(rule, _unitId, _subUnitId) {
|
|
1610
|
+
const operator = rule.operator;
|
|
1611
|
+
if (!operator) return { success: false };
|
|
1612
|
+
const formula1Success = _univerjs_core.Tools.isDefine(rule.formula1) && this._isFormulaOrInt(rule.formula1);
|
|
1613
|
+
const formula2Success = _univerjs_core.Tools.isDefine(rule.formula2) && this._isFormulaOrInt(rule.formula2);
|
|
1614
|
+
const isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator);
|
|
1615
|
+
const errorMsg = this.localeService.t("dataValidation.validFail.number");
|
|
1616
|
+
if (isTwoFormula) return {
|
|
1617
|
+
success: formula1Success && formula2Success,
|
|
1618
|
+
formula1: formula1Success ? void 0 : errorMsg,
|
|
1619
|
+
formula2: formula2Success ? void 0 : errorMsg
|
|
1620
|
+
};
|
|
1621
|
+
return {
|
|
1622
|
+
success: formula1Success,
|
|
1623
|
+
formula1: errorMsg
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1626
|
+
_parseNumber(formula) {
|
|
1627
|
+
if (formula === void 0 || formula === null) return NaN;
|
|
1628
|
+
return +formula;
|
|
1629
|
+
}
|
|
1630
|
+
async parseFormula(rule, unitId, subUnitId, row, column) {
|
|
1631
|
+
const formulaResult1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column);
|
|
1632
|
+
const formulaResult2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column);
|
|
1633
|
+
const { formula1, formula2 } = rule;
|
|
1634
|
+
const isFormulaValid = isLegalFormulaResult(String(formulaResult1 === null || formulaResult1 === void 0 ? void 0 : formulaResult1.v)) && isLegalFormulaResult(String(formulaResult2 === null || formulaResult2 === void 0 ? void 0 : formulaResult2.v));
|
|
1635
|
+
return {
|
|
1636
|
+
formula1: this._parseNumber((0, _univerjs_core.isFormulaString)(formula1) ? formulaResult1 === null || formulaResult1 === void 0 ? void 0 : formulaResult1.v : formula1),
|
|
1637
|
+
formula2: this._parseNumber((0, _univerjs_core.isFormulaString)(formula2) ? formulaResult2 === null || formulaResult2 === void 0 ? void 0 : formulaResult2.v : formula2),
|
|
1638
|
+
isFormulaValid
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
transform(cellInfo, _formula, _rule) {
|
|
1642
|
+
return {
|
|
1643
|
+
...cellInfo,
|
|
1644
|
+
value: cellInfo.value.toString().length
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
async isValidType(cellInfo, _formula, _rule) {
|
|
1648
|
+
const { value: cellValue } = cellInfo;
|
|
1649
|
+
return typeof cellValue === "string" || typeof cellValue === "number";
|
|
1650
|
+
}
|
|
1651
|
+
generateRuleErrorMessage(rule, pos) {
|
|
1652
|
+
if (!rule.operator) return this.titleStr;
|
|
1653
|
+
const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, pos);
|
|
1654
|
+
return `${this.localeService.t(_univerjs_data_validation.TextLengthErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 !== null && transformedFormula1 !== void 0 ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 !== null && transformedFormula2 !== void 0 ? transformedFormula2 : "")}`;
|
|
1655
|
+
}
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
//#endregion
|
|
1659
|
+
//#region src/commands/commands/data-validation.command.ts
|
|
1660
|
+
function isBlankCell(cellData) {
|
|
1661
|
+
var _cellData$p$body$data, _cellData$p$body;
|
|
1662
|
+
if (!cellData) return true;
|
|
1663
|
+
if (!cellData.p) return _univerjs_core.Tools.isBlank(cellData.v);
|
|
1664
|
+
return !((_cellData$p$body$data = (_cellData$p$body = cellData.p.body) === null || _cellData$p$body === void 0 ? void 0 : _cellData$p$body.dataStream) !== null && _cellData$p$body$data !== void 0 ? _cellData$p$body$data : "").slice(0, -2).trim();
|
|
1665
|
+
}
|
|
1666
|
+
function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, source = "command", fillDefaultValue = true) {
|
|
1667
|
+
const lexerTreeBuilder = accessor.get(_univerjs_engine_formula.LexerTreeBuilder);
|
|
1668
|
+
const validatorRegistryService = accessor.get(_univerjs_data_validation.DataValidatorRegistryService);
|
|
1669
|
+
const redoMutations = [];
|
|
1670
|
+
const undoMutations = [];
|
|
1671
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
1672
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
|
|
1673
|
+
unitId,
|
|
1674
|
+
subUnitId
|
|
1675
|
+
});
|
|
1676
|
+
if (!target) return {
|
|
1677
|
+
redoMutations,
|
|
1678
|
+
undoMutations
|
|
1679
|
+
};
|
|
1680
|
+
const { worksheet } = target;
|
|
1681
|
+
const redoMatrix = new _univerjs_core.ObjectMatrix();
|
|
1682
|
+
let setRangeValue = false;
|
|
1683
|
+
function setRangesDefaultValue(ranges, defaultValue) {
|
|
1684
|
+
if (!fillDefaultValue) return;
|
|
1685
|
+
ranges.forEach((range) => {
|
|
1686
|
+
_univerjs_core.Range.foreach(range, (row, column) => {
|
|
1687
|
+
const cellData = worksheet.getCellRaw(row, column);
|
|
1688
|
+
const value = getStringCellValue(cellData);
|
|
1689
|
+
if ((isBlankCell(cellData) || value === defaultValue) && !(cellData === null || cellData === void 0 ? void 0 : cellData.p)) {
|
|
1690
|
+
setRangeValue = true;
|
|
1691
|
+
redoMatrix.setValue(row, column, {
|
|
1692
|
+
v: defaultValue,
|
|
1693
|
+
p: null
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
});
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
diffs.forEach((diff) => {
|
|
1700
|
+
switch (diff.type) {
|
|
1701
|
+
case "delete":
|
|
1702
|
+
redoMutations.push({
|
|
1703
|
+
id: _univerjs_data_validation.RemoveDataValidationMutation.id,
|
|
1704
|
+
params: {
|
|
1705
|
+
unitId,
|
|
1706
|
+
subUnitId,
|
|
1707
|
+
ruleId: diff.rule.uid,
|
|
1708
|
+
source
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
undoMutations.unshift({
|
|
1712
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
1713
|
+
params: {
|
|
1714
|
+
unitId,
|
|
1715
|
+
subUnitId,
|
|
1716
|
+
rule: diff.rule,
|
|
1717
|
+
index: diff.index,
|
|
1718
|
+
source
|
|
1719
|
+
}
|
|
1720
|
+
});
|
|
1721
|
+
break;
|
|
1722
|
+
case "update": {
|
|
1723
|
+
if (shouldOffsetFormulaByRange(diff.rule.type, validatorRegistryService)) {
|
|
1724
|
+
const originRow = diff.oldRanges[0].startRow;
|
|
1725
|
+
const originColumn = diff.oldRanges[0].startColumn;
|
|
1726
|
+
const newRow = diff.newRanges[0].startRow;
|
|
1727
|
+
const newColumn = diff.newRanges[0].startColumn;
|
|
1728
|
+
const rowDiff = newRow - originRow;
|
|
1729
|
+
const columnDiff = newColumn - originColumn;
|
|
1730
|
+
const newFormula = (0, _univerjs_core.isFormulaString)(diff.rule.formula1) ? lexerTreeBuilder.moveFormulaRefOffset(diff.rule.formula1, columnDiff, rowDiff) : diff.rule.formula1;
|
|
1731
|
+
const newFormula2 = (0, _univerjs_core.isFormulaString)(diff.rule.formula2) ? lexerTreeBuilder.moveFormulaRefOffset(diff.rule.formula2, columnDiff, rowDiff) : diff.rule.formula2;
|
|
1732
|
+
if (newFormula !== diff.rule.formula1 || newFormula2 !== diff.rule.formula2 || !(0, _univerjs_core.isRangesEqual)(diff.newRanges, diff.oldRanges)) {
|
|
1733
|
+
redoMutations.push({
|
|
1734
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
1735
|
+
params: {
|
|
1736
|
+
unitId,
|
|
1737
|
+
subUnitId,
|
|
1738
|
+
ruleId: diff.ruleId,
|
|
1739
|
+
payload: {
|
|
1740
|
+
type: _univerjs_data_validation.UpdateRuleType.ALL,
|
|
1741
|
+
payload: {
|
|
1742
|
+
formula1: newFormula,
|
|
1743
|
+
formula2: newFormula2,
|
|
1744
|
+
ranges: diff.newRanges
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
});
|
|
1749
|
+
undoMutations.unshift({
|
|
1750
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
1751
|
+
params: {
|
|
1752
|
+
unitId,
|
|
1753
|
+
subUnitId,
|
|
1754
|
+
ruleId: diff.ruleId,
|
|
1755
|
+
payload: {
|
|
1756
|
+
type: _univerjs_data_validation.UpdateRuleType.ALL,
|
|
1757
|
+
payload: {
|
|
1758
|
+
formula1: diff.rule.formula1,
|
|
1759
|
+
formula2: diff.rule.formula2,
|
|
1760
|
+
ranges: diff.oldRanges
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
});
|
|
1765
|
+
} else {
|
|
1766
|
+
redoMutations.push({
|
|
1767
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
1768
|
+
params: {
|
|
1769
|
+
unitId,
|
|
1770
|
+
subUnitId,
|
|
1771
|
+
ruleId: diff.ruleId,
|
|
1772
|
+
payload: {
|
|
1773
|
+
type: _univerjs_data_validation.UpdateRuleType.RANGE,
|
|
1774
|
+
payload: diff.newRanges
|
|
1775
|
+
},
|
|
1776
|
+
source
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1779
|
+
undoMutations.unshift({
|
|
1780
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
1781
|
+
params: {
|
|
1782
|
+
unitId,
|
|
1783
|
+
subUnitId,
|
|
1784
|
+
ruleId: diff.ruleId,
|
|
1785
|
+
payload: {
|
|
1786
|
+
type: _univerjs_data_validation.UpdateRuleType.RANGE,
|
|
1787
|
+
payload: diff.oldRanges
|
|
1788
|
+
},
|
|
1789
|
+
source
|
|
1790
|
+
}
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
} else {
|
|
1794
|
+
redoMutations.push({
|
|
1795
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
1796
|
+
params: {
|
|
1797
|
+
unitId,
|
|
1798
|
+
subUnitId,
|
|
1799
|
+
ruleId: diff.ruleId,
|
|
1800
|
+
payload: {
|
|
1801
|
+
type: _univerjs_data_validation.UpdateRuleType.RANGE,
|
|
1802
|
+
payload: diff.newRanges
|
|
1803
|
+
},
|
|
1804
|
+
source
|
|
1805
|
+
}
|
|
1806
|
+
});
|
|
1807
|
+
undoMutations.unshift({
|
|
1808
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
1809
|
+
params: {
|
|
1810
|
+
unitId,
|
|
1811
|
+
subUnitId,
|
|
1812
|
+
ruleId: diff.ruleId,
|
|
1813
|
+
payload: {
|
|
1814
|
+
type: _univerjs_data_validation.UpdateRuleType.RANGE,
|
|
1815
|
+
payload: diff.oldRanges
|
|
1816
|
+
},
|
|
1817
|
+
source
|
|
1818
|
+
}
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, diff.ruleId);
|
|
1822
|
+
if (rule && rule.type === _univerjs_core.DataValidationType.CHECKBOX) {
|
|
1823
|
+
const formula = sheetDataValidationModel.getValidator(_univerjs_core.DataValidationType.CHECKBOX).parseFormulaSync(rule, unitId, subUnitId);
|
|
1824
|
+
setRangesDefaultValue(diff.newRanges, formula.formula2);
|
|
1825
|
+
}
|
|
1826
|
+
break;
|
|
1827
|
+
}
|
|
1828
|
+
case "add":
|
|
1829
|
+
redoMutations.push({
|
|
1830
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
1831
|
+
params: {
|
|
1832
|
+
unitId,
|
|
1833
|
+
subUnitId,
|
|
1834
|
+
rule: diff.rule,
|
|
1835
|
+
source
|
|
1836
|
+
}
|
|
1837
|
+
});
|
|
1838
|
+
undoMutations.unshift({
|
|
1839
|
+
id: _univerjs_data_validation.RemoveDataValidationMutation.id,
|
|
1840
|
+
params: {
|
|
1841
|
+
unitId,
|
|
1842
|
+
subUnitId,
|
|
1843
|
+
ruleId: diff.rule.uid,
|
|
1844
|
+
source
|
|
1845
|
+
}
|
|
1846
|
+
});
|
|
1847
|
+
if (diff.rule.type === _univerjs_core.DataValidationType.CHECKBOX) {
|
|
1848
|
+
const formula = sheetDataValidationModel.getValidator(_univerjs_core.DataValidationType.CHECKBOX).parseFormulaSync(diff.rule, unitId, subUnitId);
|
|
1849
|
+
setRangesDefaultValue(diff.rule.ranges, formula.originFormula2);
|
|
1850
|
+
}
|
|
1851
|
+
break;
|
|
1852
|
+
default: break;
|
|
1853
|
+
}
|
|
1854
|
+
});
|
|
1855
|
+
if (setRangeValue) {
|
|
1856
|
+
const redoSetRangeValues = {
|
|
1857
|
+
id: _univerjs_sheets.SetRangeValuesMutation.id,
|
|
1858
|
+
params: {
|
|
1859
|
+
unitId,
|
|
1860
|
+
subUnitId,
|
|
1861
|
+
cellValue: redoMatrix.getData()
|
|
1862
|
+
}
|
|
1863
|
+
};
|
|
1864
|
+
const undoSetRangeValues = {
|
|
1865
|
+
id: _univerjs_sheets.SetRangeValuesMutation.id,
|
|
1866
|
+
params: (0, _univerjs_sheets.SetRangeValuesUndoMutationFactory)(accessor, redoSetRangeValues.params)
|
|
1867
|
+
};
|
|
1868
|
+
redoMutations.push(redoSetRangeValues);
|
|
1869
|
+
undoMutations.push(undoSetRangeValues);
|
|
1870
|
+
}
|
|
1871
|
+
return {
|
|
1872
|
+
redoMutations,
|
|
1873
|
+
undoMutations
|
|
1874
|
+
};
|
|
1875
|
+
}
|
|
1876
|
+
const UpdateSheetDataValidationRangeCommand = {
|
|
1877
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
1878
|
+
id: "sheet.command.updateDataValidationRuleRange",
|
|
1879
|
+
handler(accessor, params) {
|
|
1880
|
+
if (!params) return false;
|
|
1881
|
+
const { unitId, subUnitId, ranges, ruleId } = params;
|
|
1882
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
1883
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
1884
|
+
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
1885
|
+
if (!sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId)) return false;
|
|
1886
|
+
const matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
1887
|
+
matrix.updateRange(ruleId, ranges);
|
|
1888
|
+
const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), accessor);
|
|
1889
|
+
undoRedoService.pushUndoRedo({
|
|
1890
|
+
undoMutations,
|
|
1891
|
+
redoMutations,
|
|
1892
|
+
unitID: unitId
|
|
1893
|
+
});
|
|
1894
|
+
(0, _univerjs_core.sequenceExecute)(redoMutations, commandService);
|
|
1895
|
+
return true;
|
|
1896
|
+
}
|
|
1897
|
+
};
|
|
1898
|
+
const AddSheetDataValidationCommand = {
|
|
1899
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
1900
|
+
id: "sheet.command.addDataValidation",
|
|
1901
|
+
handler(accessor, params) {
|
|
1902
|
+
if (!params) return false;
|
|
1903
|
+
const { unitId, subUnitId, rule } = params;
|
|
1904
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
1905
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
1906
|
+
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
1907
|
+
const matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
1908
|
+
matrix.addRule(rule);
|
|
1909
|
+
const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId));
|
|
1910
|
+
const validator = sheetDataValidationModel.getValidator(rule.type);
|
|
1911
|
+
const mutationParams = {
|
|
1912
|
+
unitId,
|
|
1913
|
+
subUnitId,
|
|
1914
|
+
rule: {
|
|
1915
|
+
...rule,
|
|
1916
|
+
...validator === null || validator === void 0 ? void 0 : validator.normalizeFormula(rule, unitId, subUnitId)
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1919
|
+
const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
1920
|
+
redoMutations.push({
|
|
1921
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
1922
|
+
params: mutationParams
|
|
1923
|
+
});
|
|
1924
|
+
undoMutations.unshift({
|
|
1925
|
+
id: _univerjs_data_validation.RemoveDataValidationMutation.id,
|
|
1926
|
+
params: {
|
|
1927
|
+
unitId,
|
|
1928
|
+
subUnitId,
|
|
1929
|
+
ruleId: rule.uid
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1932
|
+
undoRedoService.pushUndoRedo({
|
|
1933
|
+
unitID: unitId,
|
|
1934
|
+
redoMutations,
|
|
1935
|
+
undoMutations
|
|
1936
|
+
});
|
|
1937
|
+
(0, _univerjs_core.sequenceExecute)(redoMutations, commandService);
|
|
1938
|
+
return true;
|
|
1939
|
+
}
|
|
1940
|
+
};
|
|
1941
|
+
const UpdateSheetDataValidationSettingCommand = {
|
|
1942
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
1943
|
+
id: "sheets.command.update-data-validation-setting",
|
|
1944
|
+
handler(accessor, params) {
|
|
1945
|
+
if (!params) return false;
|
|
1946
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
1947
|
+
const redoUndoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
1948
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
1949
|
+
const dataValidatorRegistryService = accessor.get(_univerjs_data_validation.DataValidatorRegistryService);
|
|
1950
|
+
const { unitId, subUnitId, ruleId, setting } = params;
|
|
1951
|
+
const validator = dataValidatorRegistryService.getValidatorItem(setting.type);
|
|
1952
|
+
if (!validator) return false;
|
|
1953
|
+
const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1954
|
+
if (!rule) return false;
|
|
1955
|
+
const newRule = {
|
|
1956
|
+
...rule,
|
|
1957
|
+
...setting
|
|
1958
|
+
};
|
|
1959
|
+
if (!validator.validatorFormula(newRule, unitId, subUnitId).success) return false;
|
|
1960
|
+
const mutationParams = {
|
|
1961
|
+
unitId,
|
|
1962
|
+
subUnitId,
|
|
1963
|
+
ruleId,
|
|
1964
|
+
payload: {
|
|
1965
|
+
type: _univerjs_data_validation.UpdateRuleType.SETTING,
|
|
1966
|
+
payload: {
|
|
1967
|
+
...setting,
|
|
1968
|
+
...validator.normalizeFormula(newRule, unitId, subUnitId)
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
const redoMutations = [{
|
|
1973
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
1974
|
+
params: mutationParams
|
|
1975
|
+
}];
|
|
1976
|
+
const undoMutationParams = {
|
|
1977
|
+
unitId,
|
|
1978
|
+
subUnitId,
|
|
1979
|
+
ruleId,
|
|
1980
|
+
payload: {
|
|
1981
|
+
type: _univerjs_data_validation.UpdateRuleType.SETTING,
|
|
1982
|
+
payload: (0, _univerjs_data_validation.getRuleSetting)(rule)
|
|
1983
|
+
}
|
|
1984
|
+
};
|
|
1985
|
+
const undoMutations = [{
|
|
1986
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
1987
|
+
params: undoMutationParams
|
|
1988
|
+
}];
|
|
1989
|
+
if (setting.type === _univerjs_core.DataValidationType.CHECKBOX) {
|
|
1990
|
+
const ranges = rule.ranges;
|
|
1991
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
|
|
1992
|
+
unitId,
|
|
1993
|
+
subUnitId
|
|
1994
|
+
});
|
|
1995
|
+
if (target) {
|
|
1996
|
+
const redoMatrix = new _univerjs_core.ObjectMatrix();
|
|
1997
|
+
const { worksheet } = target;
|
|
1998
|
+
const { formula2: oldFormula2 = 0, formula1: oldFormula1 = 1 } = rule;
|
|
1999
|
+
const { formula2 = 0, formula1 = 1 } = setting;
|
|
2000
|
+
let setted = false;
|
|
2001
|
+
ranges.forEach((range) => {
|
|
2002
|
+
_univerjs_core.Range.foreach(range, (row, column) => {
|
|
2003
|
+
const cellData = worksheet.getCellRaw(row, column);
|
|
2004
|
+
const value = getStringCellValue(cellData);
|
|
2005
|
+
if ((isBlankCell(cellData) || value === String(oldFormula2)) && !(cellData === null || cellData === void 0 ? void 0 : cellData.p)) {
|
|
2006
|
+
redoMatrix.setValue(row, column, {
|
|
2007
|
+
v: formula2,
|
|
2008
|
+
p: null
|
|
2009
|
+
});
|
|
2010
|
+
setted = true;
|
|
2011
|
+
} else if (value === String(oldFormula1) && !(cellData === null || cellData === void 0 ? void 0 : cellData.p)) {
|
|
2012
|
+
redoMatrix.setValue(row, column, {
|
|
2013
|
+
v: formula1,
|
|
2014
|
+
p: null
|
|
2015
|
+
});
|
|
2016
|
+
setted = true;
|
|
2017
|
+
}
|
|
2018
|
+
});
|
|
2019
|
+
});
|
|
2020
|
+
if (setted) {
|
|
2021
|
+
const redoSetRangeValues = {
|
|
2022
|
+
id: _univerjs_sheets.SetRangeValuesMutation.id,
|
|
2023
|
+
params: {
|
|
2024
|
+
unitId,
|
|
2025
|
+
subUnitId,
|
|
2026
|
+
cellValue: redoMatrix.getData()
|
|
2027
|
+
}
|
|
2028
|
+
};
|
|
2029
|
+
const undoSetRangeValues = {
|
|
2030
|
+
id: _univerjs_sheets.SetRangeValuesMutation.id,
|
|
2031
|
+
params: (0, _univerjs_sheets.SetRangeValuesUndoMutationFactory)(accessor, redoSetRangeValues.params)
|
|
2032
|
+
};
|
|
2033
|
+
redoMutations.push(redoSetRangeValues);
|
|
2034
|
+
undoMutations.push(undoSetRangeValues);
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
if ((0, _univerjs_core.sequenceExecute)(redoMutations, commandService).result) {
|
|
2039
|
+
redoUndoService.pushUndoRedo({
|
|
2040
|
+
unitID: unitId,
|
|
2041
|
+
redoMutations,
|
|
2042
|
+
undoMutations
|
|
2043
|
+
});
|
|
2044
|
+
return true;
|
|
2045
|
+
}
|
|
2046
|
+
return false;
|
|
2047
|
+
}
|
|
2048
|
+
};
|
|
2049
|
+
const UpdateSheetDataValidationOptionsCommand = {
|
|
2050
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
2051
|
+
id: "sheets.command.update-data-validation-options",
|
|
2052
|
+
handler(accessor, params) {
|
|
2053
|
+
if (!params) return false;
|
|
2054
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
2055
|
+
const redoUndoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
2056
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
2057
|
+
const { unitId, subUnitId, ruleId, options } = params;
|
|
2058
|
+
const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
2059
|
+
if (!rule) return false;
|
|
2060
|
+
const mutationParams = {
|
|
2061
|
+
unitId,
|
|
2062
|
+
subUnitId,
|
|
2063
|
+
ruleId,
|
|
2064
|
+
payload: {
|
|
2065
|
+
type: _univerjs_data_validation.UpdateRuleType.OPTIONS,
|
|
2066
|
+
payload: options
|
|
2067
|
+
}
|
|
2068
|
+
};
|
|
2069
|
+
const redoMutations = [{
|
|
2070
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
2071
|
+
params: mutationParams
|
|
2072
|
+
}];
|
|
2073
|
+
const undoMutationParams = {
|
|
2074
|
+
unitId,
|
|
2075
|
+
subUnitId,
|
|
2076
|
+
ruleId,
|
|
2077
|
+
payload: {
|
|
2078
|
+
type: _univerjs_data_validation.UpdateRuleType.OPTIONS,
|
|
2079
|
+
payload: (0, _univerjs_data_validation.getRuleOptions)(rule)
|
|
2080
|
+
}
|
|
2081
|
+
};
|
|
2082
|
+
const undoMutations = [{
|
|
2083
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
2084
|
+
params: undoMutationParams
|
|
2085
|
+
}];
|
|
2086
|
+
redoUndoService.pushUndoRedo({
|
|
2087
|
+
unitID: unitId,
|
|
2088
|
+
redoMutations,
|
|
2089
|
+
undoMutations
|
|
2090
|
+
});
|
|
2091
|
+
commandService.executeCommand(_univerjs_data_validation.UpdateDataValidationMutation.id, mutationParams);
|
|
2092
|
+
return true;
|
|
2093
|
+
}
|
|
2094
|
+
};
|
|
2095
|
+
const ClearRangeDataValidationCommand = {
|
|
2096
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
2097
|
+
id: "sheets.command.clear-range-data-validation",
|
|
2098
|
+
handler(accessor, params) {
|
|
2099
|
+
if (!params) return false;
|
|
2100
|
+
const { unitId, subUnitId, ranges } = params;
|
|
2101
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
2102
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
|
|
2103
|
+
unitId,
|
|
2104
|
+
subUnitId
|
|
2105
|
+
});
|
|
2106
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
2107
|
+
if (!target) return false;
|
|
2108
|
+
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
2109
|
+
const matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
2110
|
+
matrix.removeRange(ranges);
|
|
2111
|
+
const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), accessor);
|
|
2112
|
+
undoRedoService.pushUndoRedo({
|
|
2113
|
+
unitID: unitId,
|
|
2114
|
+
redoMutations,
|
|
2115
|
+
undoMutations
|
|
2116
|
+
});
|
|
2117
|
+
return (0, _univerjs_core.sequenceExecute)(redoMutations, commandService).result;
|
|
2118
|
+
}
|
|
2119
|
+
};
|
|
2120
|
+
const RemoveSheetAllDataValidationCommand = {
|
|
2121
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
2122
|
+
id: "sheet.command.remove-all-data-validation",
|
|
2123
|
+
handler(accessor, params) {
|
|
2124
|
+
if (!params) return false;
|
|
2125
|
+
const { unitId, subUnitId } = params;
|
|
2126
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
2127
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
2128
|
+
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
2129
|
+
const currentRules = [...sheetDataValidationModel.getRules(unitId, subUnitId)];
|
|
2130
|
+
const redoParams = {
|
|
2131
|
+
unitId,
|
|
2132
|
+
subUnitId,
|
|
2133
|
+
ruleId: currentRules.map((rule) => rule.uid)
|
|
2134
|
+
};
|
|
2135
|
+
const redoMutations = [{
|
|
2136
|
+
id: _univerjs_data_validation.RemoveDataValidationMutation.id,
|
|
2137
|
+
params: redoParams
|
|
2138
|
+
}];
|
|
2139
|
+
const undoMutations = [{
|
|
2140
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
2141
|
+
params: {
|
|
2142
|
+
unitId,
|
|
2143
|
+
subUnitId,
|
|
2144
|
+
rule: currentRules
|
|
2145
|
+
}
|
|
2146
|
+
}];
|
|
2147
|
+
undoRedoService.pushUndoRedo({
|
|
2148
|
+
redoMutations,
|
|
2149
|
+
undoMutations,
|
|
2150
|
+
unitID: unitId
|
|
2151
|
+
});
|
|
2152
|
+
commandService.executeCommand(_univerjs_data_validation.RemoveDataValidationMutation.id, redoParams);
|
|
2153
|
+
return true;
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
2156
|
+
const removeDataValidationUndoFactory = (accessor, redoParams) => {
|
|
2157
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
2158
|
+
const { unitId, subUnitId, ruleId, source } = redoParams;
|
|
2159
|
+
if (Array.isArray(ruleId)) {
|
|
2160
|
+
const rules = ruleId.map((id) => sheetDataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
|
|
2161
|
+
return [{
|
|
2162
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
2163
|
+
params: {
|
|
2164
|
+
unitId,
|
|
2165
|
+
subUnitId,
|
|
2166
|
+
rule: rules,
|
|
2167
|
+
source
|
|
2168
|
+
}
|
|
2169
|
+
}];
|
|
2170
|
+
}
|
|
2171
|
+
return [{
|
|
2172
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
2173
|
+
params: {
|
|
2174
|
+
unitId,
|
|
2175
|
+
subUnitId,
|
|
2176
|
+
rule: { ...sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId) },
|
|
2177
|
+
index: sheetDataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
|
|
2178
|
+
}
|
|
2179
|
+
}];
|
|
2180
|
+
};
|
|
2181
|
+
const RemoveSheetDataValidationCommand = {
|
|
2182
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
2183
|
+
id: "sheet.command.remove-data-validation-rule",
|
|
2184
|
+
handler(accessor, params) {
|
|
2185
|
+
if (!params) return false;
|
|
2186
|
+
const { unitId, subUnitId, ruleId } = params;
|
|
2187
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
2188
|
+
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
2189
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
2190
|
+
const redoMutations = [{
|
|
2191
|
+
id: _univerjs_data_validation.RemoveDataValidationMutation.id,
|
|
2192
|
+
params
|
|
2193
|
+
}];
|
|
2194
|
+
const undoMutations = [{
|
|
2195
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
2196
|
+
params: {
|
|
2197
|
+
unitId,
|
|
2198
|
+
subUnitId,
|
|
2199
|
+
rule: { ...sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId) },
|
|
2200
|
+
index: sheetDataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
|
|
2201
|
+
}
|
|
2202
|
+
}];
|
|
2203
|
+
undoRedoService.pushUndoRedo({
|
|
2204
|
+
undoMutations,
|
|
2205
|
+
redoMutations,
|
|
2206
|
+
unitID: params.unitId
|
|
2207
|
+
});
|
|
2208
|
+
commandService.executeCommand(_univerjs_data_validation.RemoveDataValidationMutation.id, params);
|
|
2209
|
+
return true;
|
|
2210
|
+
}
|
|
2211
|
+
};
|
|
2212
|
+
|
|
2213
|
+
//#endregion
|
|
2214
|
+
//#region src/common/const.ts
|
|
2215
|
+
/**
|
|
2216
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2217
|
+
*
|
|
2218
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2219
|
+
* you may not use this file except in compliance with the License.
|
|
2220
|
+
* You may obtain a copy of the License at
|
|
2221
|
+
*
|
|
2222
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2223
|
+
*
|
|
2224
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2225
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2226
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2227
|
+
* See the License for the specific language governing permissions and
|
|
2228
|
+
* limitations under the License.
|
|
2229
|
+
*/
|
|
2230
|
+
const DATA_VALIDATION_PLUGIN_NAME = "SHEET_DATA_VALIDATION_PLUGIN";
|
|
2231
|
+
|
|
2232
|
+
//#endregion
|
|
2233
|
+
//#region src/controllers/dv-formula.controller.ts
|
|
2234
|
+
let DataValidationFormulaController = class DataValidationFormulaController extends _univerjs_core.Disposable {
|
|
2235
|
+
constructor(_univerInstanceService, _permissionService, _lexerTreeBuilder) {
|
|
2236
|
+
super();
|
|
2237
|
+
this._univerInstanceService = _univerInstanceService;
|
|
2238
|
+
this._permissionService = _permissionService;
|
|
2239
|
+
this._lexerTreeBuilder = _lexerTreeBuilder;
|
|
2240
|
+
}
|
|
2241
|
+
getFormulaRefCheck(formulaString) {
|
|
2242
|
+
const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
|
|
2243
|
+
if (!sequenceNodes) return true;
|
|
2244
|
+
for (let i = 0; i < sequenceNodes.length; i++) {
|
|
2245
|
+
const node = sequenceNodes[i];
|
|
2246
|
+
if (typeof node === "string") continue;
|
|
2247
|
+
const { token } = node;
|
|
2248
|
+
const sequenceGrid = (0, _univerjs_engine_formula.deserializeRangeWithSheetWithCache)(token);
|
|
2249
|
+
const workbook = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
2250
|
+
let targetSheet = workbook.getActiveSheet();
|
|
2251
|
+
const unitId = workbook.getUnitId();
|
|
2252
|
+
if (sequenceGrid.sheetName) {
|
|
2253
|
+
targetSheet = workbook.getSheetBySheetName(sequenceGrid.sheetName);
|
|
2254
|
+
if (!targetSheet) return false;
|
|
2255
|
+
const subUnitId = targetSheet === null || targetSheet === void 0 ? void 0 : targetSheet.getSheetId();
|
|
2256
|
+
if (!this._permissionService.getPermissionPoint(new _univerjs_sheets.WorksheetViewPermission(unitId, subUnitId).id)) return false;
|
|
2257
|
+
}
|
|
2258
|
+
if (!targetSheet) return false;
|
|
2259
|
+
const { startRow, endRow, startColumn, endColumn } = sequenceGrid.range;
|
|
2260
|
+
for (let i = startRow; i <= endRow; i++) for (let j = startColumn; j <= endColumn; j++) {
|
|
2261
|
+
var _targetSheet$getCell;
|
|
2262
|
+
const permission = (_targetSheet$getCell = targetSheet.getCell(i, j)) === null || _targetSheet$getCell === void 0 || (_targetSheet$getCell = _targetSheet$getCell.selectionProtection) === null || _targetSheet$getCell === void 0 ? void 0 : _targetSheet$getCell[0];
|
|
2263
|
+
if ((permission === null || permission === void 0 ? void 0 : permission[_univerjs_protocol.UnitAction.View]) === false) return false;
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
return true;
|
|
2267
|
+
}
|
|
2268
|
+
};
|
|
2269
|
+
DataValidationFormulaController = __decorate([
|
|
2270
|
+
__decorateParam(0, _univerjs_core.IUniverInstanceService),
|
|
2271
|
+
__decorateParam(1, _univerjs_core.IPermissionService),
|
|
2272
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder))
|
|
2273
|
+
], DataValidationFormulaController);
|
|
2274
|
+
|
|
2275
|
+
//#endregion
|
|
2276
|
+
//#region package.json
|
|
2277
|
+
var name = "@univerjs/sheets-data-validation";
|
|
2278
|
+
var version = "0.21.0";
|
|
2279
|
+
|
|
2280
|
+
//#endregion
|
|
2281
|
+
//#region src/config/config.ts
|
|
2282
|
+
/**
|
|
2283
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2284
|
+
*
|
|
2285
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2286
|
+
* you may not use this file except in compliance with the License.
|
|
2287
|
+
* You may obtain a copy of the License at
|
|
2288
|
+
*
|
|
2289
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2290
|
+
*
|
|
2291
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2292
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2293
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2294
|
+
* See the License for the specific language governing permissions and
|
|
2295
|
+
* limitations under the License.
|
|
2296
|
+
*/
|
|
2297
|
+
const SHEETS_DATA_VALIDATION_PLUGIN_CONFIG_KEY = "sheets-data-validation.config";
|
|
2298
|
+
const configSymbol = Symbol(SHEETS_DATA_VALIDATION_PLUGIN_CONFIG_KEY);
|
|
2299
|
+
const defaultPluginConfig = {};
|
|
2300
|
+
|
|
2301
|
+
//#endregion
|
|
2302
|
+
//#region src/controllers/dv-formula-ref-range.controller.ts
|
|
2303
|
+
let DataValidationFormulaRefRangeController = class DataValidationFormulaRefRangeController extends _univerjs_core.Disposable {
|
|
2304
|
+
constructor(_dataValidationModel, _formulaRefRangeService, _validatorRegistryService) {
|
|
2305
|
+
super();
|
|
2306
|
+
this._dataValidationModel = _dataValidationModel;
|
|
2307
|
+
this._formulaRefRangeService = _formulaRefRangeService;
|
|
2308
|
+
this._validatorRegistryService = _validatorRegistryService;
|
|
2309
|
+
_defineProperty(this, "_disposableMap", /* @__PURE__ */ new Map());
|
|
2310
|
+
_defineProperty(this, "registerRule", (unitId, subUnitId, rule) => {
|
|
2311
|
+
if (!shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService)) return;
|
|
2312
|
+
this.register(unitId, subUnitId, rule);
|
|
2313
|
+
});
|
|
2314
|
+
this._initRefRange();
|
|
2315
|
+
}
|
|
2316
|
+
_getIdWithUnitId(unitID, subUnitId, ruleId) {
|
|
2317
|
+
return `${unitID}_${subUnitId}_${ruleId}`;
|
|
2318
|
+
}
|
|
2319
|
+
register(unitId, subUnitId, rule) {
|
|
2320
|
+
const oldRanges = rule.ranges;
|
|
2321
|
+
const oldFormula1 = rule.formula1;
|
|
2322
|
+
const oldFormula2 = rule.formula2;
|
|
2323
|
+
const disposable = this._formulaRefRangeService.registerRangeFormula(unitId, subUnitId, oldRanges, [oldFormula1 !== null && oldFormula1 !== void 0 ? oldFormula1 : "", oldFormula2 !== null && oldFormula2 !== void 0 ? oldFormula2 : ""], (res) => {
|
|
2324
|
+
if (res.length === 0) return {
|
|
2325
|
+
undos: [{
|
|
2326
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
2327
|
+
params: {
|
|
2328
|
+
unitId,
|
|
2329
|
+
subUnitId,
|
|
2330
|
+
rule,
|
|
2331
|
+
source: "patched"
|
|
2332
|
+
}
|
|
2333
|
+
}],
|
|
2334
|
+
redos: [{
|
|
2335
|
+
id: _univerjs_data_validation.RemoveDataValidationMutation.id,
|
|
2336
|
+
params: {
|
|
2337
|
+
unitId,
|
|
2338
|
+
subUnitId,
|
|
2339
|
+
ruleId: rule.uid,
|
|
2340
|
+
source: "patched"
|
|
2341
|
+
}
|
|
2342
|
+
}]
|
|
2343
|
+
};
|
|
2344
|
+
const redos = [];
|
|
2345
|
+
const undos = [];
|
|
2346
|
+
const first = res[0];
|
|
2347
|
+
redos.push({
|
|
2348
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
2349
|
+
params: {
|
|
2350
|
+
unitId,
|
|
2351
|
+
subUnitId,
|
|
2352
|
+
ruleId: rule.uid,
|
|
2353
|
+
payload: {
|
|
2354
|
+
type: _univerjs_data_validation.UpdateRuleType.ALL,
|
|
2355
|
+
payload: {
|
|
2356
|
+
ranges: first.ranges,
|
|
2357
|
+
formula1: first.formulas[0],
|
|
2358
|
+
formula2: first.formulas[1]
|
|
2359
|
+
}
|
|
2360
|
+
},
|
|
2361
|
+
source: "patched"
|
|
2362
|
+
}
|
|
2363
|
+
});
|
|
2364
|
+
undos.push({
|
|
2365
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
2366
|
+
params: {
|
|
2367
|
+
unitId,
|
|
2368
|
+
subUnitId,
|
|
2369
|
+
ruleId: rule.uid,
|
|
2370
|
+
payload: {
|
|
2371
|
+
type: _univerjs_data_validation.UpdateRuleType.ALL,
|
|
2372
|
+
payload: {
|
|
2373
|
+
ranges: oldRanges,
|
|
2374
|
+
formula1: oldFormula1,
|
|
2375
|
+
formula2: oldFormula2
|
|
2376
|
+
}
|
|
2377
|
+
},
|
|
2378
|
+
source: "patched"
|
|
2379
|
+
}
|
|
2380
|
+
});
|
|
2381
|
+
for (let i = 1; i < res.length; i++) {
|
|
2382
|
+
const item = res[i];
|
|
2383
|
+
const id = (0, _univerjs_core.generateRandomId)();
|
|
2384
|
+
redos.push({
|
|
2385
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
2386
|
+
params: {
|
|
2387
|
+
unitId,
|
|
2388
|
+
subUnitId,
|
|
2389
|
+
rule: {
|
|
2390
|
+
...rule,
|
|
2391
|
+
uid: id,
|
|
2392
|
+
formula1: item.formulas[0],
|
|
2393
|
+
formula2: item.formulas[1],
|
|
2394
|
+
ranges: item.ranges
|
|
2395
|
+
},
|
|
2396
|
+
source: "patched"
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
undos.push({
|
|
2400
|
+
id: _univerjs_data_validation.RemoveDataValidationMutation.id,
|
|
2401
|
+
params: {
|
|
2402
|
+
unitId,
|
|
2403
|
+
subUnitId,
|
|
2404
|
+
ruleId: id,
|
|
2405
|
+
source: "patched"
|
|
2406
|
+
}
|
|
2407
|
+
});
|
|
2408
|
+
}
|
|
2409
|
+
return {
|
|
2410
|
+
undos,
|
|
2411
|
+
redos
|
|
2412
|
+
};
|
|
2413
|
+
});
|
|
2414
|
+
const id = this._getIdWithUnitId(unitId, subUnitId, rule.uid);
|
|
2415
|
+
this._disposableMap.set(id, disposable);
|
|
2416
|
+
}
|
|
2417
|
+
_initRefRange() {
|
|
2418
|
+
const allRules = this._dataValidationModel.getAll();
|
|
2419
|
+
for (const [unitId, subUnitMap] of allRules) for (const [subUnitId, rules] of subUnitMap) for (const rule of rules) this.registerRule(unitId, subUnitId, rule);
|
|
2420
|
+
this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe((option) => {
|
|
2421
|
+
const { unitId, subUnitId, rule } = option;
|
|
2422
|
+
switch (option.type) {
|
|
2423
|
+
case "add": {
|
|
2424
|
+
const rule = option.rule;
|
|
2425
|
+
this.registerRule(option.unitId, option.subUnitId, rule);
|
|
2426
|
+
break;
|
|
2427
|
+
}
|
|
2428
|
+
case "remove": {
|
|
2429
|
+
const disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule.uid));
|
|
2430
|
+
if (disposeSet) disposeSet.dispose();
|
|
2431
|
+
break;
|
|
2432
|
+
}
|
|
2433
|
+
case "update": {
|
|
2434
|
+
const rule = option.rule;
|
|
2435
|
+
const disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule.uid));
|
|
2436
|
+
if (disposeSet) disposeSet.dispose();
|
|
2437
|
+
this.registerRule(option.unitId, option.subUnitId, rule);
|
|
2438
|
+
break;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
}));
|
|
2442
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(() => {
|
|
2443
|
+
this._disposableMap.forEach((item) => {
|
|
2444
|
+
item.dispose();
|
|
2445
|
+
});
|
|
2446
|
+
this._disposableMap.clear();
|
|
2447
|
+
}));
|
|
2448
|
+
}
|
|
2449
|
+
};
|
|
2450
|
+
DataValidationFormulaRefRangeController = __decorate([
|
|
2451
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(SheetDataValidationModel)),
|
|
2452
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_formula.FormulaRefRangeService)),
|
|
2453
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService))
|
|
2454
|
+
], DataValidationFormulaRefRangeController);
|
|
2455
|
+
|
|
2456
|
+
//#endregion
|
|
2457
|
+
//#region src/controllers/dv-ref-range.controller.ts
|
|
2458
|
+
let DataValidationRefRangeController = class DataValidationRefRangeController extends _univerjs_core.Disposable {
|
|
2459
|
+
constructor(_dataValidationModel, _injector, _refRangeService, _dataValidationFormulaService, _formulaRefRangeService, _validatorRegistryService) {
|
|
2460
|
+
super();
|
|
2461
|
+
this._dataValidationModel = _dataValidationModel;
|
|
2462
|
+
this._injector = _injector;
|
|
2463
|
+
this._refRangeService = _refRangeService;
|
|
2464
|
+
this._dataValidationFormulaService = _dataValidationFormulaService;
|
|
2465
|
+
this._formulaRefRangeService = _formulaRefRangeService;
|
|
2466
|
+
this._validatorRegistryService = _validatorRegistryService;
|
|
2467
|
+
_defineProperty(this, "_disposableMap", /* @__PURE__ */ new Map());
|
|
2468
|
+
_defineProperty(this, "registerRule", (unitId, subUnitId, rule) => {
|
|
2469
|
+
if (shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService)) return;
|
|
2470
|
+
this.register(unitId, subUnitId, rule);
|
|
2471
|
+
this.registerFormula(unitId, subUnitId, rule);
|
|
2472
|
+
});
|
|
2473
|
+
this._initRefRange();
|
|
2474
|
+
}
|
|
2475
|
+
_getIdWithUnitId(unitID, subUnitId, ruleId) {
|
|
2476
|
+
return `${unitID}_${subUnitId}_${ruleId}`;
|
|
2477
|
+
}
|
|
2478
|
+
registerFormula(unitId, subUnitId, rule) {
|
|
2479
|
+
var _this$_disposableMap$;
|
|
2480
|
+
const ruleId = rule.uid;
|
|
2481
|
+
const id = this._getIdWithUnitId(unitId, subUnitId, ruleId);
|
|
2482
|
+
const disposeSet = (_this$_disposableMap$ = this._disposableMap.get(id)) !== null && _this$_disposableMap$ !== void 0 ? _this$_disposableMap$ : /* @__PURE__ */ new Set();
|
|
2483
|
+
const handleFormulaChange = (type, formulaString) => {
|
|
2484
|
+
const oldRule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
2485
|
+
if (!oldRule) return {
|
|
2486
|
+
redos: [],
|
|
2487
|
+
undos: []
|
|
2488
|
+
};
|
|
2489
|
+
const oldFormula = oldRule[type];
|
|
2490
|
+
if (!oldFormula || oldFormula === formulaString) return {
|
|
2491
|
+
redos: [],
|
|
2492
|
+
undos: []
|
|
2493
|
+
};
|
|
2494
|
+
const redoParams = {
|
|
2495
|
+
unitId,
|
|
2496
|
+
subUnitId,
|
|
2497
|
+
ruleId: rule.uid,
|
|
2498
|
+
payload: {
|
|
2499
|
+
type: _univerjs_data_validation.UpdateRuleType.SETTING,
|
|
2500
|
+
payload: {
|
|
2501
|
+
type: oldRule.type,
|
|
2502
|
+
formula1: oldRule.formula1,
|
|
2503
|
+
formula2: oldRule.formula2,
|
|
2504
|
+
[type]: formulaString
|
|
2505
|
+
}
|
|
2506
|
+
},
|
|
2507
|
+
source: "patched"
|
|
2508
|
+
};
|
|
2509
|
+
const undoParams = {
|
|
2510
|
+
unitId,
|
|
2511
|
+
subUnitId,
|
|
2512
|
+
ruleId: rule.uid,
|
|
2513
|
+
payload: {
|
|
2514
|
+
type: _univerjs_data_validation.UpdateRuleType.SETTING,
|
|
2515
|
+
payload: {
|
|
2516
|
+
type: oldRule.type,
|
|
2517
|
+
formula1: oldRule.formula1,
|
|
2518
|
+
formula2: oldRule.formula2
|
|
2519
|
+
}
|
|
2520
|
+
},
|
|
2521
|
+
source: "patched"
|
|
2522
|
+
};
|
|
2523
|
+
return {
|
|
2524
|
+
redos: [{
|
|
2525
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
2526
|
+
params: redoParams
|
|
2527
|
+
}],
|
|
2528
|
+
undos: [{
|
|
2529
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
2530
|
+
params: undoParams
|
|
2531
|
+
}]
|
|
2532
|
+
};
|
|
2533
|
+
};
|
|
2534
|
+
const currentFormula = this._dataValidationFormulaService.getRuleFormulaInfo(unitId, subUnitId, ruleId);
|
|
2535
|
+
if (currentFormula) {
|
|
2536
|
+
const [formula1, formula2] = currentFormula;
|
|
2537
|
+
if (formula1) {
|
|
2538
|
+
const disposable = this._formulaRefRangeService.registerFormula(unitId, subUnitId, formula1.text, (newFormulaString) => handleFormulaChange("formula1", newFormulaString));
|
|
2539
|
+
disposeSet.add(() => disposable.dispose());
|
|
2540
|
+
}
|
|
2541
|
+
if (formula2) {
|
|
2542
|
+
const disposable = this._formulaRefRangeService.registerFormula(unitId, subUnitId, formula2.text, (newFormulaString) => handleFormulaChange("formula2", newFormulaString));
|
|
2543
|
+
disposeSet.add(() => disposable.dispose());
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
register(unitId, subUnitId, rule) {
|
|
2548
|
+
var _this$_disposableMap$2;
|
|
2549
|
+
const handleRangeChange = (commandInfo) => {
|
|
2550
|
+
const oldRanges = [...rule.ranges];
|
|
2551
|
+
const resultRanges = oldRanges.map((range) => {
|
|
2552
|
+
return (0, _univerjs_sheets.handleCommonDefaultRangeChangeWithEffectRefCommands)(range, commandInfo);
|
|
2553
|
+
}).filter((range) => !!range).flat();
|
|
2554
|
+
if ((0, _univerjs_core.isRangesEqual)(resultRanges, oldRanges)) return {
|
|
2555
|
+
redos: [],
|
|
2556
|
+
undos: []
|
|
2557
|
+
};
|
|
2558
|
+
if (resultRanges.length) {
|
|
2559
|
+
const redoParams = {
|
|
2560
|
+
unitId,
|
|
2561
|
+
subUnitId,
|
|
2562
|
+
ruleId: rule.uid,
|
|
2563
|
+
payload: {
|
|
2564
|
+
type: _univerjs_data_validation.UpdateRuleType.RANGE,
|
|
2565
|
+
payload: resultRanges
|
|
2566
|
+
},
|
|
2567
|
+
source: "patched"
|
|
2568
|
+
};
|
|
2569
|
+
return {
|
|
2570
|
+
redos: [{
|
|
2571
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
2572
|
+
params: redoParams
|
|
2573
|
+
}],
|
|
2574
|
+
undos: [{
|
|
2575
|
+
id: _univerjs_data_validation.UpdateDataValidationMutation.id,
|
|
2576
|
+
params: {
|
|
2577
|
+
unitId,
|
|
2578
|
+
subUnitId,
|
|
2579
|
+
ruleId: rule.uid,
|
|
2580
|
+
payload: {
|
|
2581
|
+
type: _univerjs_data_validation.UpdateRuleType.RANGE,
|
|
2582
|
+
payload: oldRanges
|
|
2583
|
+
},
|
|
2584
|
+
source: "patched"
|
|
2585
|
+
}
|
|
2586
|
+
}]
|
|
2587
|
+
};
|
|
2588
|
+
} else {
|
|
2589
|
+
const redoParams = {
|
|
2590
|
+
unitId,
|
|
2591
|
+
subUnitId,
|
|
2592
|
+
ruleId: rule.uid
|
|
2593
|
+
};
|
|
2594
|
+
return {
|
|
2595
|
+
redos: [{
|
|
2596
|
+
id: _univerjs_data_validation.RemoveDataValidationMutation.id,
|
|
2597
|
+
params: redoParams
|
|
2598
|
+
}],
|
|
2599
|
+
undos: removeDataValidationUndoFactory(this._injector, redoParams)
|
|
2600
|
+
};
|
|
2601
|
+
}
|
|
2602
|
+
};
|
|
2603
|
+
const disposeList = [];
|
|
2604
|
+
rule.ranges.forEach((range) => {
|
|
2605
|
+
const disposable = this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId);
|
|
2606
|
+
disposeList.push(() => disposable.dispose());
|
|
2607
|
+
});
|
|
2608
|
+
const id = this._getIdWithUnitId(unitId, subUnitId, rule.uid);
|
|
2609
|
+
const current = (_this$_disposableMap$2 = this._disposableMap.get(id)) !== null && _this$_disposableMap$2 !== void 0 ? _this$_disposableMap$2 : /* @__PURE__ */ new Set();
|
|
2610
|
+
current.add(() => disposeList.forEach((dispose) => dispose()));
|
|
2611
|
+
this._disposableMap.set(id, current);
|
|
2612
|
+
}
|
|
2613
|
+
_initRefRange() {
|
|
2614
|
+
const allRules = this._dataValidationModel.getAll();
|
|
2615
|
+
for (const [unitId, subUnitMap] of allRules) for (const [subUnitId, rules] of subUnitMap) for (const rule of rules) this.registerRule(unitId, subUnitId, rule);
|
|
2616
|
+
this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe((option) => {
|
|
2617
|
+
const { unitId, subUnitId, rule } = option;
|
|
2618
|
+
switch (option.type) {
|
|
2619
|
+
case "add": {
|
|
2620
|
+
const rule = option.rule;
|
|
2621
|
+
this.registerRule(option.unitId, option.subUnitId, rule);
|
|
2622
|
+
break;
|
|
2623
|
+
}
|
|
2624
|
+
case "remove": {
|
|
2625
|
+
const disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule.uid));
|
|
2626
|
+
if (disposeSet) disposeSet.forEach((dispose) => dispose());
|
|
2627
|
+
break;
|
|
2628
|
+
}
|
|
2629
|
+
case "update": {
|
|
2630
|
+
const rule = option.rule;
|
|
2631
|
+
const disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule.uid));
|
|
2632
|
+
if (disposeSet) disposeSet.forEach((dispose) => dispose());
|
|
2633
|
+
this.registerRule(option.unitId, option.subUnitId, rule);
|
|
2634
|
+
break;
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
}));
|
|
2638
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(() => {
|
|
2639
|
+
this._disposableMap.forEach((item) => {
|
|
2640
|
+
item.forEach((dispose) => dispose());
|
|
2641
|
+
});
|
|
2642
|
+
this._disposableMap.clear();
|
|
2643
|
+
}));
|
|
2644
|
+
}
|
|
2645
|
+
};
|
|
2646
|
+
DataValidationRefRangeController = __decorate([
|
|
2647
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(SheetDataValidationModel)),
|
|
2648
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
2649
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.RefRangeService)),
|
|
2650
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(DataValidationFormulaService)),
|
|
2651
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_formula.FormulaRefRangeService)),
|
|
2652
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService))
|
|
2653
|
+
], DataValidationRefRangeController);
|
|
2654
|
+
|
|
2655
|
+
//#endregion
|
|
2656
|
+
//#region src/controllers/dv-sheet.controller.ts
|
|
2657
|
+
let SheetDataValidationSheetController = class SheetDataValidationSheetController extends _univerjs_core.Disposable {
|
|
2658
|
+
constructor(_sheetInterceptorService, _univerInstanceService, _sheetDataValidationModel) {
|
|
2659
|
+
super();
|
|
2660
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
2661
|
+
this._univerInstanceService = _univerInstanceService;
|
|
2662
|
+
this._sheetDataValidationModel = _sheetDataValidationModel;
|
|
2663
|
+
this._initSheetChange();
|
|
2664
|
+
}
|
|
2665
|
+
_initSheetChange() {
|
|
2666
|
+
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
|
|
2667
|
+
if (commandInfo.id === _univerjs_sheets.RemoveSheetCommand.id) {
|
|
2668
|
+
var _workbook$getActiveSh;
|
|
2669
|
+
const params = commandInfo.params;
|
|
2670
|
+
const unitId = params.unitId || this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).getUnitId();
|
|
2671
|
+
const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
|
|
2672
|
+
if (!workbook) return {
|
|
2673
|
+
redos: [],
|
|
2674
|
+
undos: []
|
|
2675
|
+
};
|
|
2676
|
+
const subUnitId = params.subUnitId || ((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId());
|
|
2677
|
+
if (!subUnitId) return {
|
|
2678
|
+
redos: [],
|
|
2679
|
+
undos: []
|
|
2680
|
+
};
|
|
2681
|
+
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
2682
|
+
if (rules.length === 0) return {
|
|
2683
|
+
redos: [],
|
|
2684
|
+
undos: []
|
|
2685
|
+
};
|
|
2686
|
+
const redoParams = {
|
|
2687
|
+
unitId,
|
|
2688
|
+
subUnitId,
|
|
2689
|
+
ruleId: rules.map((i) => i.uid),
|
|
2690
|
+
source: "patched"
|
|
2691
|
+
};
|
|
2692
|
+
const undoParams = {
|
|
2693
|
+
unitId,
|
|
2694
|
+
subUnitId,
|
|
2695
|
+
rule: [...rules],
|
|
2696
|
+
source: "patched"
|
|
2697
|
+
};
|
|
2698
|
+
return {
|
|
2699
|
+
redos: [{
|
|
2700
|
+
id: _univerjs_data_validation.RemoveDataValidationMutation.id,
|
|
2701
|
+
params: redoParams
|
|
2702
|
+
}],
|
|
2703
|
+
undos: [{
|
|
2704
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
2705
|
+
params: undoParams
|
|
2706
|
+
}]
|
|
2707
|
+
};
|
|
2708
|
+
} else if (commandInfo.id === _univerjs_sheets.CopySheetCommand.id) {
|
|
2709
|
+
const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
|
|
2710
|
+
if (!unitId || !subUnitId || !targetSubUnitId) return {
|
|
2711
|
+
redos: [],
|
|
2712
|
+
undos: []
|
|
2713
|
+
};
|
|
2714
|
+
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
2715
|
+
if (rules.length === 0) return {
|
|
2716
|
+
redos: [],
|
|
2717
|
+
undos: []
|
|
2718
|
+
};
|
|
2719
|
+
const newRules = rules.map((rule) => {
|
|
2720
|
+
return {
|
|
2721
|
+
...rule,
|
|
2722
|
+
uid: (0, _univerjs_core.generateRandomId)(6)
|
|
2723
|
+
};
|
|
2724
|
+
});
|
|
2725
|
+
return {
|
|
2726
|
+
redos: [{
|
|
2727
|
+
id: _univerjs_data_validation.AddDataValidationMutation.id,
|
|
2728
|
+
params: {
|
|
2729
|
+
unitId,
|
|
2730
|
+
subUnitId: targetSubUnitId,
|
|
2731
|
+
rule: newRules,
|
|
2732
|
+
source: "patched"
|
|
2733
|
+
}
|
|
2734
|
+
}],
|
|
2735
|
+
undos: [{
|
|
2736
|
+
id: _univerjs_data_validation.RemoveDataValidationMutation.id,
|
|
2737
|
+
params: {
|
|
2738
|
+
unitId,
|
|
2739
|
+
subUnitId: targetSubUnitId,
|
|
2740
|
+
ruleId: newRules.map((r) => r.uid),
|
|
2741
|
+
source: "patched"
|
|
2742
|
+
}
|
|
2743
|
+
}]
|
|
2744
|
+
};
|
|
2745
|
+
}
|
|
2746
|
+
return {
|
|
2747
|
+
redos: [],
|
|
2748
|
+
undos: []
|
|
2749
|
+
};
|
|
2750
|
+
} }));
|
|
2751
|
+
}
|
|
2752
|
+
};
|
|
2753
|
+
SheetDataValidationSheetController = __decorate([
|
|
2754
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
|
|
2755
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
|
|
2756
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(SheetDataValidationModel))
|
|
2757
|
+
], SheetDataValidationSheetController);
|
|
2758
|
+
|
|
2759
|
+
//#endregion
|
|
2760
|
+
//#region src/validators/any-validator.ts
|
|
2761
|
+
var AnyValidator = class extends _univerjs_data_validation.BaseDataValidator {
|
|
2762
|
+
constructor(..._args) {
|
|
2763
|
+
super(..._args);
|
|
2764
|
+
_defineProperty(this, "id", _univerjs_core.DataValidationType.ANY);
|
|
2765
|
+
_defineProperty(this, "title", "dataValidation.any.title");
|
|
2766
|
+
_defineProperty(this, "operators", []);
|
|
2767
|
+
_defineProperty(this, "scopes", ["sheet"]);
|
|
2768
|
+
_defineProperty(this, "order", 0);
|
|
2769
|
+
_defineProperty(this, "offsetFormulaByRange", false);
|
|
2770
|
+
}
|
|
2771
|
+
async parseFormula(rule, unitId, subUnitId) {
|
|
2772
|
+
return {
|
|
2773
|
+
formula1: rule.formula1,
|
|
2774
|
+
formula2: rule.formula2,
|
|
2775
|
+
isFormulaValid: true
|
|
2776
|
+
};
|
|
2777
|
+
}
|
|
2778
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
2779
|
+
return { success: true };
|
|
2780
|
+
}
|
|
2781
|
+
async isValidType(cellInfo, formula, rule) {
|
|
2782
|
+
return true;
|
|
2783
|
+
}
|
|
2784
|
+
generateRuleErrorMessage(rule) {
|
|
2785
|
+
return this.localeService.t("dataValidation.any.error");
|
|
2786
|
+
}
|
|
2787
|
+
};
|
|
2788
|
+
|
|
2789
|
+
//#endregion
|
|
2790
|
+
//#region src/validators/custom-validator.ts
|
|
2791
|
+
var CustomFormulaValidator = class extends _univerjs_data_validation.BaseDataValidator {
|
|
2792
|
+
constructor(..._args) {
|
|
2793
|
+
super(..._args);
|
|
2794
|
+
_defineProperty(this, "id", _univerjs_core.DataValidationType.CUSTOM);
|
|
2795
|
+
_defineProperty(this, "title", "dataValidation.custom.title");
|
|
2796
|
+
_defineProperty(this, "operators", []);
|
|
2797
|
+
_defineProperty(this, "scopes", ["sheet"]);
|
|
2798
|
+
_defineProperty(this, "order", 60);
|
|
2799
|
+
_defineProperty(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
|
|
2800
|
+
_defineProperty(this, "_lexerTreeBuilder", this.injector.get(_univerjs_engine_formula.LexerTreeBuilder));
|
|
2801
|
+
}
|
|
2802
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
2803
|
+
var _rule$formula;
|
|
2804
|
+
const success = (0, _univerjs_core.isFormulaString)(rule.formula1);
|
|
2805
|
+
const formulaText = (_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "";
|
|
2806
|
+
const valid = this._lexerTreeBuilder.checkIfAddBracket(formulaText) === 0 && formulaText.startsWith(_univerjs_engine_formula.operatorToken.EQUALS);
|
|
2807
|
+
return {
|
|
2808
|
+
success: success && valid,
|
|
2809
|
+
formula1: success && valid ? "" : this.localeService.t("dataValidation.validFail.formula")
|
|
2810
|
+
};
|
|
2811
|
+
}
|
|
2812
|
+
async parseFormula(_rule, _unitId, _subUnitId) {
|
|
2813
|
+
return {
|
|
2814
|
+
formula1: void 0,
|
|
2815
|
+
formula2: void 0,
|
|
2816
|
+
isFormulaValid: true
|
|
2817
|
+
};
|
|
2818
|
+
}
|
|
2819
|
+
async isValidType(cellInfo, _formula, _rule) {
|
|
2820
|
+
const { column, row, unitId, subUnitId } = cellInfo;
|
|
2821
|
+
const cellData = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, _rule.uid, row, column);
|
|
2822
|
+
const formulaResult = cellData === null || cellData === void 0 ? void 0 : cellData.v;
|
|
2823
|
+
if (!isLegalFormulaResult(String(formulaResult))) return false;
|
|
2824
|
+
if (_univerjs_core.Tools.isDefine(formulaResult) && formulaResult !== "") {
|
|
2825
|
+
if (cellData.t === _univerjs_core.CellValueType.BOOLEAN) return Boolean(formulaResult);
|
|
2826
|
+
if (typeof formulaResult === "boolean") return formulaResult;
|
|
2827
|
+
if (typeof formulaResult === "number") return Boolean(formulaResult);
|
|
2828
|
+
if (typeof formulaResult === "string") return isLegalFormulaResult(formulaResult);
|
|
2829
|
+
return Boolean(formulaResult);
|
|
2830
|
+
}
|
|
2831
|
+
return false;
|
|
2832
|
+
}
|
|
2833
|
+
generateRuleErrorMessage(rule) {
|
|
2834
|
+
return this.localeService.t("dataValidation.custom.error");
|
|
2835
|
+
}
|
|
2836
|
+
generateRuleName(rule) {
|
|
2837
|
+
var _rule$formula2;
|
|
2838
|
+
return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (_rule$formula2 = rule.formula1) !== null && _rule$formula2 !== void 0 ? _rule$formula2 : "");
|
|
2839
|
+
}
|
|
2840
|
+
};
|
|
2841
|
+
|
|
2842
|
+
//#endregion
|
|
2843
|
+
//#region src/validators/list-multiple-validator.ts
|
|
2844
|
+
/**
|
|
2845
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2846
|
+
*
|
|
2847
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2848
|
+
* you may not use this file except in compliance with the License.
|
|
2849
|
+
* You may obtain a copy of the License at
|
|
2850
|
+
*
|
|
2851
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2852
|
+
*
|
|
2853
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2854
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2855
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2856
|
+
* See the License for the specific language governing permissions and
|
|
2857
|
+
* limitations under the License.
|
|
2858
|
+
*/
|
|
2859
|
+
var ListMultipleValidator = class extends ListValidator {
|
|
2860
|
+
constructor(..._args) {
|
|
2861
|
+
super(..._args);
|
|
2862
|
+
_defineProperty(this, "id", _univerjs_core.DataValidationType.LIST_MULTIPLE);
|
|
2863
|
+
_defineProperty(this, "title", "dataValidation.listMultiple.title");
|
|
2864
|
+
_defineProperty(this, "offsetFormulaByRange", false);
|
|
2865
|
+
_defineProperty(this, "skipDefaultFontRender", () => {
|
|
2866
|
+
return true;
|
|
2867
|
+
});
|
|
2868
|
+
}
|
|
2869
|
+
};
|
|
2870
|
+
|
|
2871
|
+
//#endregion
|
|
2872
|
+
//#region src/validators/whole-validator.ts
|
|
2873
|
+
var WholeValidator = class extends _univerjs_data_validation.BaseDataValidator {
|
|
2874
|
+
constructor(..._args) {
|
|
2875
|
+
super(..._args);
|
|
2876
|
+
_defineProperty(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
|
|
2877
|
+
_defineProperty(this, "_lexerTreeBuilder", this.injector.get(_univerjs_engine_formula.LexerTreeBuilder));
|
|
2878
|
+
_defineProperty(this, "id", _univerjs_core.DataValidationType.WHOLE);
|
|
2879
|
+
_defineProperty(this, "title", "dataValidation.whole.title");
|
|
2880
|
+
_defineProperty(this, "order", 10);
|
|
2881
|
+
_defineProperty(this, "operators", [
|
|
2882
|
+
_univerjs_core.DataValidationOperator.BETWEEN,
|
|
2883
|
+
_univerjs_core.DataValidationOperator.EQUAL,
|
|
2884
|
+
_univerjs_core.DataValidationOperator.GREATER_THAN,
|
|
2885
|
+
_univerjs_core.DataValidationOperator.GREATER_THAN_OR_EQUAL,
|
|
2886
|
+
_univerjs_core.DataValidationOperator.LESS_THAN,
|
|
2887
|
+
_univerjs_core.DataValidationOperator.LESS_THAN_OR_EQUAL,
|
|
2888
|
+
_univerjs_core.DataValidationOperator.NOT_BETWEEN,
|
|
2889
|
+
_univerjs_core.DataValidationOperator.NOT_EQUAL
|
|
2890
|
+
]);
|
|
2891
|
+
_defineProperty(this, "scopes", ["sheet"]);
|
|
2892
|
+
}
|
|
2893
|
+
_isFormulaOrInt(formula) {
|
|
2894
|
+
return !_univerjs_core.Tools.isBlank(formula) && ((0, _univerjs_core.isFormulaString)(formula) || !Number.isNaN(+formula) && Number.isInteger(+formula));
|
|
2895
|
+
}
|
|
2896
|
+
async isValidType(cellInfo, _formula, _rule) {
|
|
2897
|
+
const { value: cellValue } = cellInfo;
|
|
2898
|
+
const num = getCellValueNumber(cellValue);
|
|
2899
|
+
return !Number.isNaN(num) && Number.isInteger(num);
|
|
2900
|
+
}
|
|
2901
|
+
transform(cellInfo, _formula, _rule) {
|
|
2902
|
+
const { value: cellValue } = cellInfo;
|
|
2903
|
+
return {
|
|
2904
|
+
...cellInfo,
|
|
2905
|
+
value: getCellValueNumber(cellValue)
|
|
2906
|
+
};
|
|
2907
|
+
}
|
|
2908
|
+
_parseNumber(formula) {
|
|
2909
|
+
if (formula === void 0 || formula === null) return NaN;
|
|
2910
|
+
return +formula;
|
|
2911
|
+
}
|
|
2912
|
+
async parseFormula(rule, unitId, subUnitId, row, column) {
|
|
2913
|
+
const res1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column);
|
|
2914
|
+
const res2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column);
|
|
2915
|
+
const { formula1, formula2 } = rule;
|
|
2916
|
+
const formula1Result = (0, _univerjs_core.isFormulaString)(formula1) ? res1 === null || res1 === void 0 ? void 0 : res1.v : formula1;
|
|
2917
|
+
const formula2Result = (0, _univerjs_core.isFormulaString)(formula2) ? res2 === null || res2 === void 0 ? void 0 : res2.v : formula2;
|
|
2918
|
+
const isFormulaValid = isLegalFormulaResult(`${formula1Result}`) && isLegalFormulaResult(`${formula2Result}`);
|
|
2919
|
+
return {
|
|
2920
|
+
formula1: this._parseNumber(formula1Result),
|
|
2921
|
+
formula2: this._parseNumber(formula2Result),
|
|
2922
|
+
isFormulaValid
|
|
2923
|
+
};
|
|
2924
|
+
}
|
|
2925
|
+
validatorFormula(rule, _unitId, _subUnitId) {
|
|
2926
|
+
const operator = rule.operator;
|
|
2927
|
+
if (!operator) return { success: true };
|
|
2928
|
+
const formula1Success = _univerjs_core.Tools.isDefine(rule.formula1) && this._isFormulaOrInt(rule.formula1);
|
|
2929
|
+
const formula2Success = _univerjs_core.Tools.isDefine(rule.formula2) && this._isFormulaOrInt(rule.formula2);
|
|
2930
|
+
const isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator);
|
|
2931
|
+
const errorMsg = this.localeService.t("dataValidation.validFail.number");
|
|
2932
|
+
if (isTwoFormula) return {
|
|
2933
|
+
success: formula1Success && formula2Success,
|
|
2934
|
+
formula1: formula1Success ? void 0 : errorMsg,
|
|
2935
|
+
formula2: formula2Success ? void 0 : errorMsg
|
|
2936
|
+
};
|
|
2937
|
+
return {
|
|
2938
|
+
success: formula1Success,
|
|
2939
|
+
formula1: errorMsg
|
|
2940
|
+
};
|
|
2941
|
+
}
|
|
2942
|
+
generateRuleErrorMessage(rule, position) {
|
|
2943
|
+
if (!rule.operator) return this.localeService.t(OperatorErrorTitleMap.NONE).replace("{TYPE}", this.titleStr);
|
|
2944
|
+
const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, position);
|
|
2945
|
+
return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 !== null && transformedFormula1 !== void 0 ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 !== null && transformedFormula2 !== void 0 ? transformedFormula2 : "")}`;
|
|
2946
|
+
}
|
|
2947
|
+
};
|
|
2948
|
+
|
|
2949
|
+
//#endregion
|
|
2950
|
+
//#region src/controllers/dv.controller.ts
|
|
2951
|
+
let DataValidationController = class DataValidationController extends _univerjs_core.RxDisposable {
|
|
2952
|
+
constructor(_univerInstanceService, _dataValidatorRegistryService, _injector, _selectionManagerService, _sheetInterceptorService, _sheetDataValidationModel) {
|
|
2953
|
+
super();
|
|
2954
|
+
this._univerInstanceService = _univerInstanceService;
|
|
2955
|
+
this._dataValidatorRegistryService = _dataValidatorRegistryService;
|
|
2956
|
+
this._injector = _injector;
|
|
2957
|
+
this._selectionManagerService = _selectionManagerService;
|
|
2958
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
2959
|
+
this._sheetDataValidationModel = _sheetDataValidationModel;
|
|
2960
|
+
this._init();
|
|
2961
|
+
}
|
|
2962
|
+
_init() {
|
|
2963
|
+
this._registerValidators();
|
|
2964
|
+
this._initCommandInterceptor();
|
|
2965
|
+
}
|
|
2966
|
+
_registerValidators() {
|
|
2967
|
+
[
|
|
2968
|
+
AnyValidator,
|
|
2969
|
+
DecimalValidator,
|
|
2970
|
+
WholeValidator,
|
|
2971
|
+
TextLengthValidator,
|
|
2972
|
+
DateValidator,
|
|
2973
|
+
CheckboxValidator,
|
|
2974
|
+
ListValidator,
|
|
2975
|
+
ListMultipleValidator,
|
|
2976
|
+
CustomFormulaValidator
|
|
2977
|
+
].forEach((Validator) => {
|
|
2978
|
+
const validator = this._injector.createInstance(Validator);
|
|
2979
|
+
this.disposeWithMe(this._dataValidatorRegistryService.register(validator));
|
|
2980
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(() => this._injector.delete(Validator)));
|
|
2981
|
+
});
|
|
2982
|
+
}
|
|
2983
|
+
_initCommandInterceptor() {
|
|
2984
|
+
this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
|
|
2985
|
+
if (commandInfo.id === _univerjs_sheets.ClearSelectionAllCommand.id) {
|
|
2986
|
+
var _this$_selectionManag;
|
|
2987
|
+
const workbook = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
2988
|
+
const unitId = workbook.getUnitId();
|
|
2989
|
+
const worksheet = workbook.getActiveSheet();
|
|
2990
|
+
if (!worksheet) throw new Error("No active sheet found");
|
|
2991
|
+
const subUnitId = worksheet.getSheetId();
|
|
2992
|
+
const selections = (_this$_selectionManag = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag === void 0 ? void 0 : _this$_selectionManag.map((s) => s.range);
|
|
2993
|
+
const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
2994
|
+
if (selections) ruleMatrix.removeRange(selections);
|
|
2995
|
+
const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, ruleMatrix.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId)), this._injector, "patched");
|
|
2996
|
+
return {
|
|
2997
|
+
undos: undoMutations,
|
|
2998
|
+
redos: redoMutations
|
|
2999
|
+
};
|
|
3000
|
+
}
|
|
3001
|
+
return {
|
|
3002
|
+
undos: [],
|
|
3003
|
+
redos: []
|
|
3004
|
+
};
|
|
3005
|
+
} });
|
|
3006
|
+
}
|
|
3007
|
+
};
|
|
3008
|
+
DataValidationController = __decorate([
|
|
3009
|
+
__decorateParam(0, _univerjs_core.IUniverInstanceService),
|
|
3010
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
|
|
3011
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
3012
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
|
|
3013
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
|
|
3014
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(SheetDataValidationModel))
|
|
3015
|
+
], DataValidationController);
|
|
3016
|
+
|
|
3017
|
+
//#endregion
|
|
3018
|
+
//#region src/services/dv-validator-service.ts
|
|
3019
|
+
let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorService extends _univerjs_core.Disposable {
|
|
3020
|
+
constructor(_univerInstanceService, _sheetDataValidationModel, _dataValidationCacheService, _lifecycleService) {
|
|
3021
|
+
super();
|
|
3022
|
+
this._univerInstanceService = _univerInstanceService;
|
|
3023
|
+
this._sheetDataValidationModel = _sheetDataValidationModel;
|
|
3024
|
+
this._dataValidationCacheService = _dataValidationCacheService;
|
|
3025
|
+
this._lifecycleService = _lifecycleService;
|
|
3026
|
+
this._initRecalculate();
|
|
3027
|
+
}
|
|
3028
|
+
_initRecalculate() {
|
|
3029
|
+
const handleDirtyRanges = (ranges) => {
|
|
3030
|
+
if (ranges.length === 0) return;
|
|
3031
|
+
const workbook = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
3032
|
+
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
|
|
3033
|
+
const map = {};
|
|
3034
|
+
ranges.flat().forEach((range) => {
|
|
3035
|
+
if (!map[range.unitId]) map[range.unitId] = {};
|
|
3036
|
+
if (!map[range.unitId][range.subUnitId]) map[range.unitId][range.subUnitId] = [];
|
|
3037
|
+
const workbook = this._univerInstanceService.getUnit(range.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
3038
|
+
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(range.subUnitId);
|
|
3039
|
+
if (!worksheet) return;
|
|
3040
|
+
map[range.unitId][range.subUnitId].push(...range.ranges.map((range) => _univerjs_core.Range.transformRange(range, worksheet)));
|
|
3041
|
+
});
|
|
3042
|
+
Object.entries(map).forEach(([unitId, subUnitMap]) => {
|
|
3043
|
+
Object.entries(subUnitMap).forEach(([subUnitId, ranges]) => {
|
|
3044
|
+
if ((workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId()) === unitId && (worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId()) === subUnitId) this.validatorRanges(unitId, subUnitId, ranges);
|
|
3045
|
+
else requestIdleCallback(() => {
|
|
3046
|
+
this.validatorRanges(unitId, subUnitId, ranges);
|
|
3047
|
+
});
|
|
3048
|
+
});
|
|
3049
|
+
});
|
|
3050
|
+
};
|
|
3051
|
+
this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe((0, rxjs.bufferWhen)(() => this._lifecycleService.lifecycle$.pipe((0, rxjs.filter)((stage) => stage === _univerjs_core.LifecycleStages.Rendered)))).subscribe(handleDirtyRanges));
|
|
3052
|
+
this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe((0, rxjs.filter)(() => this._lifecycleService.stage >= _univerjs_core.LifecycleStages.Rendered), (0, _univerjs_core.bufferDebounceTime)(20)).subscribe(handleDirtyRanges));
|
|
3053
|
+
}
|
|
3054
|
+
async _validatorByCell(workbook, worksheet, row, col) {
|
|
3055
|
+
const unitId = workbook.getUnitId();
|
|
3056
|
+
const subUnitId = worksheet.getSheetId();
|
|
3057
|
+
if (!_univerjs_core.Tools.isDefine(row) || !_univerjs_core.Tools.isDefine(col)) throw new Error(`row or col is not defined, row: ${row}, col: ${col}`);
|
|
3058
|
+
let _row = row;
|
|
3059
|
+
let _col = col;
|
|
3060
|
+
const mergedCell = worksheet.getMergedCell(row, col);
|
|
3061
|
+
if (mergedCell) {
|
|
3062
|
+
_row = mergedCell.startRow;
|
|
3063
|
+
_col = mergedCell.startColumn;
|
|
3064
|
+
}
|
|
3065
|
+
const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, _row, _col);
|
|
3066
|
+
if (!rule) return _univerjs_core.DataValidationStatus.VALID;
|
|
3067
|
+
return new Promise((resolve) => {
|
|
3068
|
+
this._sheetDataValidationModel.validator(rule, {
|
|
3069
|
+
unitId,
|
|
3070
|
+
subUnitId,
|
|
3071
|
+
row: _row,
|
|
3072
|
+
col: _col,
|
|
3073
|
+
worksheet,
|
|
3074
|
+
workbook
|
|
3075
|
+
}, (status) => {
|
|
3076
|
+
resolve(status);
|
|
3077
|
+
});
|
|
3078
|
+
});
|
|
3079
|
+
}
|
|
3080
|
+
async validatorCell(unitId, subUnitId, row, col) {
|
|
3081
|
+
const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
3082
|
+
if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
3083
|
+
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
3084
|
+
if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
3085
|
+
return this._validatorByCell(workbook, worksheet, row, col);
|
|
3086
|
+
}
|
|
3087
|
+
async validatorRanges(unitId, subUnitId, ranges) {
|
|
3088
|
+
if (!ranges.length) return Promise.resolve([]);
|
|
3089
|
+
const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
3090
|
+
if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
3091
|
+
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
3092
|
+
if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
3093
|
+
const ruleRanges = this._sheetDataValidationModel.getRules(unitId, subUnitId).map((i) => i.ranges).flat();
|
|
3094
|
+
const intersectRanges = ranges.map((range) => ruleRanges.map((ruleRange) => (0, _univerjs_core.getIntersectRange)(range, ruleRange))).flat().filter(Boolean);
|
|
3095
|
+
const mergeCells = [];
|
|
3096
|
+
const result = await Promise.all(intersectRanges.map((range, resultRowIndex) => {
|
|
3097
|
+
const promises = [];
|
|
3098
|
+
for (let row = range.startRow; row <= range.endRow; row++) for (let col = range.startColumn; col <= range.endColumn; col++) {
|
|
3099
|
+
promises.push(this._validatorByCell(workbook, worksheet, row, col));
|
|
3100
|
+
const mergedCell = worksheet.getMergedCell(row, col);
|
|
3101
|
+
if (mergedCell) mergeCells.push({
|
|
3102
|
+
resultRowIndex,
|
|
3103
|
+
resultColIndex: promises.length - 1,
|
|
3104
|
+
row: mergedCell.startRow,
|
|
3105
|
+
col: mergedCell.startColumn
|
|
3106
|
+
});
|
|
3107
|
+
}
|
|
3108
|
+
return Promise.all(promises);
|
|
3109
|
+
}));
|
|
3110
|
+
/**
|
|
3111
|
+
* If this range has merged cells, the validation status of merged cells should be the same as the main cell, so we need to update the status of merged cells here after all validations are done.
|
|
3112
|
+
* Because during the validation process, merged cells are all marked as VALIDATING status in cache.
|
|
3113
|
+
*/
|
|
3114
|
+
if (mergeCells.length) mergeCells.forEach(({ resultRowIndex, resultColIndex, row, col }) => {
|
|
3115
|
+
if (result[resultRowIndex][resultColIndex] === _univerjs_core.DataValidationStatus.VALIDATING) {
|
|
3116
|
+
var _this$_dataValidation;
|
|
3117
|
+
result[resultRowIndex][resultColIndex] = (_this$_dataValidation = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col)) !== null && _this$_dataValidation !== void 0 ? _this$_dataValidation : _univerjs_core.DataValidationStatus.VALID;
|
|
3118
|
+
}
|
|
3119
|
+
});
|
|
3120
|
+
return result;
|
|
3121
|
+
}
|
|
3122
|
+
async validatorWorksheet(unitId, subUnitId) {
|
|
3123
|
+
const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
3124
|
+
if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
3125
|
+
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
3126
|
+
if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
3127
|
+
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
3128
|
+
await Promise.all(rules.map((rule) => {
|
|
3129
|
+
return Promise.all(rule.ranges.map((range) => {
|
|
3130
|
+
const promises = [];
|
|
3131
|
+
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
3132
|
+
promises.push(this._validatorByCell(workbook, worksheet, row, col));
|
|
3133
|
+
});
|
|
3134
|
+
return Promise.all(promises);
|
|
3135
|
+
}));
|
|
3136
|
+
}));
|
|
3137
|
+
return this._dataValidationCacheService.ensureCache(unitId, subUnitId);
|
|
3138
|
+
}
|
|
3139
|
+
async validatorWorkbook(unitId) {
|
|
3140
|
+
const sheetIds = this._sheetDataValidationModel.getSubUnitIds(unitId);
|
|
3141
|
+
const results = await Promise.all(sheetIds.map((id) => this.validatorWorksheet(unitId, id)));
|
|
3142
|
+
const map = {};
|
|
3143
|
+
results.forEach((result, i) => {
|
|
3144
|
+
map[sheetIds[i]] = result;
|
|
3145
|
+
});
|
|
3146
|
+
return map;
|
|
3147
|
+
}
|
|
3148
|
+
getDataValidations(unitId, subUnitId, ranges) {
|
|
3149
|
+
const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId);
|
|
3150
|
+
const ruleIdSet = /* @__PURE__ */ new Set();
|
|
3151
|
+
ranges.forEach((range) => {
|
|
3152
|
+
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
3153
|
+
const ruleId = ruleMatrix.getValue(row, col);
|
|
3154
|
+
if (ruleId) ruleIdSet.add(ruleId);
|
|
3155
|
+
});
|
|
3156
|
+
});
|
|
3157
|
+
return Array.from(ruleIdSet).map((id) => this._sheetDataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
|
|
3158
|
+
}
|
|
3159
|
+
getDataValidation(unitId, subUnitId, ranges) {
|
|
3160
|
+
return this.getDataValidations(unitId, subUnitId, ranges)[0];
|
|
3161
|
+
}
|
|
3162
|
+
};
|
|
3163
|
+
SheetsDataValidationValidatorService = __decorate([
|
|
3164
|
+
__decorateParam(0, _univerjs_core.IUniverInstanceService),
|
|
3165
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(SheetDataValidationModel)),
|
|
3166
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(DataValidationCacheService)),
|
|
3167
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.LifecycleService))
|
|
3168
|
+
], SheetsDataValidationValidatorService);
|
|
3169
|
+
|
|
3170
|
+
//#endregion
|
|
3171
|
+
//#region src/plugin.ts
|
|
3172
|
+
let UniverSheetsDataValidationPlugin = class UniverSheetsDataValidationPlugin extends _univerjs_core.Plugin {
|
|
3173
|
+
constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
|
|
3174
|
+
super();
|
|
3175
|
+
this._config = _config;
|
|
3176
|
+
this._injector = _injector;
|
|
3177
|
+
this._commandService = _commandService;
|
|
3178
|
+
this._configService = _configService;
|
|
3179
|
+
const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
3180
|
+
this._configService.setConfig(SHEETS_DATA_VALIDATION_PLUGIN_CONFIG_KEY, rest);
|
|
3181
|
+
}
|
|
3182
|
+
onStarting() {
|
|
3183
|
+
[
|
|
3184
|
+
[DataValidationCacheService],
|
|
3185
|
+
[DataValidationListCacheService],
|
|
3186
|
+
[DataValidationFormulaService],
|
|
3187
|
+
[DataValidationCustomFormulaService],
|
|
3188
|
+
[SheetsDataValidationValidatorService],
|
|
3189
|
+
[SheetDataValidationModel],
|
|
3190
|
+
[DataValidationController],
|
|
3191
|
+
[DataValidationFormulaController],
|
|
3192
|
+
[SheetDataValidationSheetController],
|
|
3193
|
+
[DataValidationRefRangeController],
|
|
3194
|
+
[DataValidationFormulaRefRangeController]
|
|
3195
|
+
].forEach((dep) => {
|
|
3196
|
+
this._injector.add(dep);
|
|
3197
|
+
});
|
|
3198
|
+
[
|
|
3199
|
+
AddSheetDataValidationCommand,
|
|
3200
|
+
UpdateSheetDataValidationRangeCommand,
|
|
3201
|
+
UpdateSheetDataValidationSettingCommand,
|
|
3202
|
+
UpdateSheetDataValidationOptionsCommand,
|
|
3203
|
+
RemoveSheetDataValidationCommand,
|
|
3204
|
+
RemoveSheetAllDataValidationCommand,
|
|
3205
|
+
ClearRangeDataValidationCommand
|
|
3206
|
+
].forEach((command) => {
|
|
3207
|
+
this._commandService.registerCommand(command);
|
|
3208
|
+
});
|
|
3209
|
+
this._injector.get(DataValidationCacheService);
|
|
3210
|
+
this._injector.get(SheetsDataValidationValidatorService);
|
|
3211
|
+
this._injector.get(DataValidationController);
|
|
3212
|
+
this._injector.get(DataValidationFormulaRefRangeController);
|
|
3213
|
+
this._injector.get(DataValidationRefRangeController);
|
|
3214
|
+
}
|
|
3215
|
+
onReady() {
|
|
3216
|
+
this._injector.get(SheetDataValidationSheetController);
|
|
3217
|
+
}
|
|
3218
|
+
onRendered() {
|
|
3219
|
+
this._injector.get(DataValidationFormulaController);
|
|
3220
|
+
}
|
|
3221
|
+
};
|
|
3222
|
+
_defineProperty(UniverSheetsDataValidationPlugin, "pluginName", DATA_VALIDATION_PLUGIN_NAME);
|
|
3223
|
+
_defineProperty(UniverSheetsDataValidationPlugin, "packageName", name);
|
|
3224
|
+
_defineProperty(UniverSheetsDataValidationPlugin, "version", version);
|
|
3225
|
+
_defineProperty(UniverSheetsDataValidationPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
3226
|
+
UniverSheetsDataValidationPlugin = __decorate([
|
|
3227
|
+
(0, _univerjs_core.DependentOn)(_univerjs_sheets_formula.UniverSheetsFormulaPlugin, _univerjs_data_validation.UniverDataValidationPlugin),
|
|
3228
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
3229
|
+
__decorateParam(2, _univerjs_core.ICommandService),
|
|
3230
|
+
__decorateParam(3, _univerjs_core.IConfigService)
|
|
3231
|
+
], UniverSheetsDataValidationPlugin);
|
|
3232
|
+
|
|
3233
|
+
//#endregion
|
|
3234
|
+
//#region src/utils/create.ts
|
|
3235
|
+
function createDefaultNewRule(accessor) {
|
|
3236
|
+
const currentRanges = accessor.get(_univerjs_sheets.SheetsSelectionsService).getCurrentSelections().map((s) => s.range);
|
|
3237
|
+
return {
|
|
3238
|
+
uid: (0, _univerjs_core.generateRandomId)(6),
|
|
3239
|
+
type: _univerjs_core.DataValidationType.DECIMAL,
|
|
3240
|
+
operator: _univerjs_core.DataValidationOperator.EQUAL,
|
|
3241
|
+
formula1: "100",
|
|
3242
|
+
ranges: currentRanges !== null && currentRanges !== void 0 ? currentRanges : [{
|
|
3243
|
+
startColumn: 0,
|
|
3244
|
+
endColumn: 0,
|
|
3245
|
+
startRow: 0,
|
|
3246
|
+
endRow: 0
|
|
3247
|
+
}]
|
|
3248
|
+
};
|
|
3249
|
+
}
|
|
3250
|
+
|
|
3251
|
+
//#endregion
|
|
3252
|
+
//#region src/index.ts
|
|
3253
|
+
const CUSTOM_FORMULA_INPUT_NAME = "data-validation.custom-formula-input";
|
|
3254
|
+
const BASE_FORMULA_INPUT_NAME = "data-validation.formula-input";
|
|
3255
|
+
const LIST_FORMULA_INPUT_NAME = "data-validation.list-formula-input";
|
|
3256
|
+
const CHECKBOX_FORMULA_INPUT_NAME = "data-validation.checkbox-formula-input";
|
|
3257
|
+
|
|
3258
|
+
//#endregion
|
|
3259
|
+
exports.AddSheetDataValidationCommand = AddSheetDataValidationCommand;
|
|
3260
|
+
exports.BASE_FORMULA_INPUT_NAME = BASE_FORMULA_INPUT_NAME;
|
|
3261
|
+
exports.CHECKBOX_FORMULA_1 = CHECKBOX_FORMULA_1;
|
|
3262
|
+
exports.CHECKBOX_FORMULA_2 = CHECKBOX_FORMULA_2;
|
|
3263
|
+
exports.CHECKBOX_FORMULA_INPUT_NAME = CHECKBOX_FORMULA_INPUT_NAME;
|
|
3264
|
+
exports.CUSTOM_FORMULA_INPUT_NAME = CUSTOM_FORMULA_INPUT_NAME;
|
|
3265
|
+
exports.CheckboxValidator = CheckboxValidator;
|
|
3266
|
+
exports.ClearRangeDataValidationCommand = ClearRangeDataValidationCommand;
|
|
3267
|
+
exports.DATA_VALIDATION_PLUGIN_NAME = DATA_VALIDATION_PLUGIN_NAME;
|
|
3268
|
+
Object.defineProperty(exports, 'DataValidationCacheService', {
|
|
3269
|
+
enumerable: true,
|
|
3270
|
+
get: function () {
|
|
3271
|
+
return DataValidationCacheService;
|
|
3272
|
+
}
|
|
3273
|
+
});
|
|
3274
|
+
Object.defineProperty(exports, 'DataValidationCustomFormulaService', {
|
|
3275
|
+
enumerable: true,
|
|
3276
|
+
get: function () {
|
|
3277
|
+
return DataValidationCustomFormulaService;
|
|
3278
|
+
}
|
|
3279
|
+
});
|
|
3280
|
+
Object.defineProperty(exports, 'DataValidationFormulaController', {
|
|
3281
|
+
enumerable: true,
|
|
3282
|
+
get: function () {
|
|
3283
|
+
return DataValidationFormulaController;
|
|
3284
|
+
}
|
|
3285
|
+
});
|
|
3286
|
+
Object.defineProperty(exports, 'DataValidationFormulaService', {
|
|
3287
|
+
enumerable: true,
|
|
3288
|
+
get: function () {
|
|
3289
|
+
return DataValidationFormulaService;
|
|
3290
|
+
}
|
|
3291
|
+
});
|
|
3292
|
+
Object.defineProperty(exports, 'DataValidationListCacheService', {
|
|
3293
|
+
enumerable: true,
|
|
3294
|
+
get: function () {
|
|
3295
|
+
return DataValidationListCacheService;
|
|
3296
|
+
}
|
|
3297
|
+
});
|
|
3298
|
+
exports.DateValidator = DateValidator;
|
|
3299
|
+
exports.LIST_FORMULA_INPUT_NAME = LIST_FORMULA_INPUT_NAME;
|
|
3300
|
+
exports.ListMultipleValidator = ListMultipleValidator;
|
|
3301
|
+
exports.ListValidator = ListValidator;
|
|
3302
|
+
exports.RemoveSheetAllDataValidationCommand = RemoveSheetAllDataValidationCommand;
|
|
3303
|
+
exports.RemoveSheetDataValidationCommand = RemoveSheetDataValidationCommand;
|
|
3304
|
+
Object.defineProperty(exports, 'SheetDataValidationModel', {
|
|
3305
|
+
enumerable: true,
|
|
3306
|
+
get: function () {
|
|
3307
|
+
return SheetDataValidationModel;
|
|
3308
|
+
}
|
|
3309
|
+
});
|
|
3310
|
+
Object.defineProperty(exports, 'SheetsDataValidationValidatorService', {
|
|
3311
|
+
enumerable: true,
|
|
3312
|
+
get: function () {
|
|
3313
|
+
return SheetsDataValidationValidatorService;
|
|
3314
|
+
}
|
|
3315
|
+
});
|
|
3316
|
+
Object.defineProperty(exports, 'UniverSheetsDataValidationPlugin', {
|
|
3317
|
+
enumerable: true,
|
|
3318
|
+
get: function () {
|
|
3319
|
+
return UniverSheetsDataValidationPlugin;
|
|
3320
|
+
}
|
|
3321
|
+
});
|
|
3322
|
+
exports.UpdateSheetDataValidationOptionsCommand = UpdateSheetDataValidationOptionsCommand;
|
|
3323
|
+
exports.UpdateSheetDataValidationRangeCommand = UpdateSheetDataValidationRangeCommand;
|
|
3324
|
+
exports.UpdateSheetDataValidationSettingCommand = UpdateSheetDataValidationSettingCommand;
|
|
3325
|
+
exports.createDefaultNewRule = createDefaultNewRule;
|
|
3326
|
+
exports.deserializeListOptions = deserializeListOptions;
|
|
3327
|
+
exports.getCellValueNumber = getCellValueNumber;
|
|
3328
|
+
exports.getCellValueOrigin = getCellValueOrigin;
|
|
3329
|
+
exports.getDataValidationCellValue = getDataValidationCellValue;
|
|
3330
|
+
exports.getDataValidationDiffMutations = getDataValidationDiffMutations;
|
|
3331
|
+
exports.getFormulaCellData = getFormulaCellData;
|
|
3332
|
+
exports.getFormulaResult = getFormulaResult;
|
|
3333
|
+
exports.getTransformedFormula = getTransformedFormula;
|
|
3334
|
+
exports.isLegalFormulaResult = isLegalFormulaResult;
|
|
3335
|
+
exports.serializeListOptions = serializeListOptions;
|
|
3336
|
+
exports.transformCheckboxValue = transformCheckboxValue;
|