@univerjs/sheets-data-validation 0.22.1 → 0.23.0-insiders.20260522-ee0b0a4
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/index.js +24 -6
- package/lib/es/index.js +24 -6
- package/lib/index.js +24 -6
- package/lib/types/index.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
- package/LICENSE +0 -176
- /package/lib/types/services/{dv-validator-service.d.ts → dv-validator.service.d.ts} +0 -0
package/lib/cjs/index.js
CHANGED
|
@@ -86,7 +86,14 @@ let DataValidationCacheService = class DataValidationCacheService extends _unive
|
|
|
86
86
|
if (cellValue) {
|
|
87
87
|
const range = new _univerjs_core.ObjectMatrix(cellValue).getDataRange();
|
|
88
88
|
if (range.endRow === -1) return;
|
|
89
|
-
const
|
|
89
|
+
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
90
|
+
const ranges = [];
|
|
91
|
+
for (const rule of rules) ranges.push(...rule.ranges);
|
|
92
|
+
const intersectsRanges = [];
|
|
93
|
+
for (const ruleRange of ranges) {
|
|
94
|
+
const intersect = (0, _univerjs_core.getIntersectRange)(ruleRange, range);
|
|
95
|
+
if (intersect) intersectsRanges.push(intersect);
|
|
96
|
+
}
|
|
90
97
|
if (intersectsRanges.length) this.markRangeDirty(unitId, subUnitId, intersectsRanges, true);
|
|
91
98
|
}
|
|
92
99
|
}
|
|
@@ -2275,7 +2282,7 @@ DataValidationFormulaController = __decorate([
|
|
|
2275
2282
|
//#endregion
|
|
2276
2283
|
//#region package.json
|
|
2277
2284
|
var name = "@univerjs/sheets-data-validation";
|
|
2278
|
-
var version = "0.
|
|
2285
|
+
var version = "0.23.0-insiders.20260522-ee0b0a4";
|
|
2279
2286
|
|
|
2280
2287
|
//#endregion
|
|
2281
2288
|
//#region src/config/config.ts
|
|
@@ -3015,7 +3022,7 @@ DataValidationController = __decorate([
|
|
|
3015
3022
|
], DataValidationController);
|
|
3016
3023
|
|
|
3017
3024
|
//#endregion
|
|
3018
|
-
//#region src/services/dv-validator
|
|
3025
|
+
//#region src/services/dv-validator.service.ts
|
|
3019
3026
|
let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorService extends _univerjs_core.Disposable {
|
|
3020
3027
|
constructor(_univerInstanceService, _sheetDataValidationModel, _dataValidationCacheService, _lifecycleService) {
|
|
3021
3028
|
super();
|
|
@@ -3090,8 +3097,14 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3090
3097
|
if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
3091
3098
|
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
3092
3099
|
if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
3093
|
-
const
|
|
3094
|
-
const
|
|
3100
|
+
const allRules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
3101
|
+
const ruleRanges = [];
|
|
3102
|
+
for (const rule of allRules) ruleRanges.push(...rule.ranges);
|
|
3103
|
+
const intersectRanges = [];
|
|
3104
|
+
for (const range of ranges) for (const ruleRange of ruleRanges) {
|
|
3105
|
+
const intersect = (0, _univerjs_core.getIntersectRange)(range, ruleRange);
|
|
3106
|
+
if (intersect) intersectRanges.push(intersect);
|
|
3107
|
+
}
|
|
3095
3108
|
const mergeCells = [];
|
|
3096
3109
|
const result = await Promise.all(intersectRanges.map((range, resultRowIndex) => {
|
|
3097
3110
|
const promises = [];
|
|
@@ -3154,7 +3167,12 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3154
3167
|
if (ruleId) ruleIdSet.add(ruleId);
|
|
3155
3168
|
});
|
|
3156
3169
|
});
|
|
3157
|
-
|
|
3170
|
+
const rules = [];
|
|
3171
|
+
for (const id of ruleIdSet) {
|
|
3172
|
+
const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, id);
|
|
3173
|
+
if (rule) rules.push(rule);
|
|
3174
|
+
}
|
|
3175
|
+
return rules;
|
|
3158
3176
|
}
|
|
3159
3177
|
getDataValidation(unitId, subUnitId, ranges) {
|
|
3160
3178
|
return this.getDataValidations(unitId, subUnitId, ranges)[0];
|
package/lib/es/index.js
CHANGED
|
@@ -85,7 +85,14 @@ let DataValidationCacheService = class DataValidationCacheService extends Dispos
|
|
|
85
85
|
if (cellValue) {
|
|
86
86
|
const range = new ObjectMatrix(cellValue).getDataRange();
|
|
87
87
|
if (range.endRow === -1) return;
|
|
88
|
-
const
|
|
88
|
+
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
89
|
+
const ranges = [];
|
|
90
|
+
for (const rule of rules) ranges.push(...rule.ranges);
|
|
91
|
+
const intersectsRanges = [];
|
|
92
|
+
for (const ruleRange of ranges) {
|
|
93
|
+
const intersect = getIntersectRange(ruleRange, range);
|
|
94
|
+
if (intersect) intersectsRanges.push(intersect);
|
|
95
|
+
}
|
|
89
96
|
if (intersectsRanges.length) this.markRangeDirty(unitId, subUnitId, intersectsRanges, true);
|
|
90
97
|
}
|
|
91
98
|
}
|
|
@@ -2274,7 +2281,7 @@ DataValidationFormulaController = __decorate([
|
|
|
2274
2281
|
//#endregion
|
|
2275
2282
|
//#region package.json
|
|
2276
2283
|
var name = "@univerjs/sheets-data-validation";
|
|
2277
|
-
var version = "0.
|
|
2284
|
+
var version = "0.23.0-insiders.20260522-ee0b0a4";
|
|
2278
2285
|
|
|
2279
2286
|
//#endregion
|
|
2280
2287
|
//#region src/config/config.ts
|
|
@@ -3014,7 +3021,7 @@ DataValidationController = __decorate([
|
|
|
3014
3021
|
], DataValidationController);
|
|
3015
3022
|
|
|
3016
3023
|
//#endregion
|
|
3017
|
-
//#region src/services/dv-validator
|
|
3024
|
+
//#region src/services/dv-validator.service.ts
|
|
3018
3025
|
let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorService extends Disposable {
|
|
3019
3026
|
constructor(_univerInstanceService, _sheetDataValidationModel, _dataValidationCacheService, _lifecycleService) {
|
|
3020
3027
|
super();
|
|
@@ -3089,8 +3096,14 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3089
3096
|
if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
3090
3097
|
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
3091
3098
|
if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
3092
|
-
const
|
|
3093
|
-
const
|
|
3099
|
+
const allRules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
3100
|
+
const ruleRanges = [];
|
|
3101
|
+
for (const rule of allRules) ruleRanges.push(...rule.ranges);
|
|
3102
|
+
const intersectRanges = [];
|
|
3103
|
+
for (const range of ranges) for (const ruleRange of ruleRanges) {
|
|
3104
|
+
const intersect = getIntersectRange(range, ruleRange);
|
|
3105
|
+
if (intersect) intersectRanges.push(intersect);
|
|
3106
|
+
}
|
|
3094
3107
|
const mergeCells = [];
|
|
3095
3108
|
const result = await Promise.all(intersectRanges.map((range, resultRowIndex) => {
|
|
3096
3109
|
const promises = [];
|
|
@@ -3153,7 +3166,12 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3153
3166
|
if (ruleId) ruleIdSet.add(ruleId);
|
|
3154
3167
|
});
|
|
3155
3168
|
});
|
|
3156
|
-
|
|
3169
|
+
const rules = [];
|
|
3170
|
+
for (const id of ruleIdSet) {
|
|
3171
|
+
const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, id);
|
|
3172
|
+
if (rule) rules.push(rule);
|
|
3173
|
+
}
|
|
3174
|
+
return rules;
|
|
3157
3175
|
}
|
|
3158
3176
|
getDataValidation(unitId, subUnitId, ranges) {
|
|
3159
3177
|
return this.getDataValidations(unitId, subUnitId, ranges)[0];
|
package/lib/index.js
CHANGED
|
@@ -85,7 +85,14 @@ let DataValidationCacheService = class DataValidationCacheService extends Dispos
|
|
|
85
85
|
if (cellValue) {
|
|
86
86
|
const range = new ObjectMatrix(cellValue).getDataRange();
|
|
87
87
|
if (range.endRow === -1) return;
|
|
88
|
-
const
|
|
88
|
+
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
89
|
+
const ranges = [];
|
|
90
|
+
for (const rule of rules) ranges.push(...rule.ranges);
|
|
91
|
+
const intersectsRanges = [];
|
|
92
|
+
for (const ruleRange of ranges) {
|
|
93
|
+
const intersect = getIntersectRange(ruleRange, range);
|
|
94
|
+
if (intersect) intersectsRanges.push(intersect);
|
|
95
|
+
}
|
|
89
96
|
if (intersectsRanges.length) this.markRangeDirty(unitId, subUnitId, intersectsRanges, true);
|
|
90
97
|
}
|
|
91
98
|
}
|
|
@@ -2274,7 +2281,7 @@ DataValidationFormulaController = __decorate([
|
|
|
2274
2281
|
//#endregion
|
|
2275
2282
|
//#region package.json
|
|
2276
2283
|
var name = "@univerjs/sheets-data-validation";
|
|
2277
|
-
var version = "0.
|
|
2284
|
+
var version = "0.23.0-insiders.20260522-ee0b0a4";
|
|
2278
2285
|
|
|
2279
2286
|
//#endregion
|
|
2280
2287
|
//#region src/config/config.ts
|
|
@@ -3014,7 +3021,7 @@ DataValidationController = __decorate([
|
|
|
3014
3021
|
], DataValidationController);
|
|
3015
3022
|
|
|
3016
3023
|
//#endregion
|
|
3017
|
-
//#region src/services/dv-validator
|
|
3024
|
+
//#region src/services/dv-validator.service.ts
|
|
3018
3025
|
let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorService extends Disposable {
|
|
3019
3026
|
constructor(_univerInstanceService, _sheetDataValidationModel, _dataValidationCacheService, _lifecycleService) {
|
|
3020
3027
|
super();
|
|
@@ -3089,8 +3096,14 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3089
3096
|
if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
3090
3097
|
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
3091
3098
|
if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
3092
|
-
const
|
|
3093
|
-
const
|
|
3099
|
+
const allRules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
3100
|
+
const ruleRanges = [];
|
|
3101
|
+
for (const rule of allRules) ruleRanges.push(...rule.ranges);
|
|
3102
|
+
const intersectRanges = [];
|
|
3103
|
+
for (const range of ranges) for (const ruleRange of ruleRanges) {
|
|
3104
|
+
const intersect = getIntersectRange(range, ruleRange);
|
|
3105
|
+
if (intersect) intersectRanges.push(intersect);
|
|
3106
|
+
}
|
|
3094
3107
|
const mergeCells = [];
|
|
3095
3108
|
const result = await Promise.all(intersectRanges.map((range, resultRowIndex) => {
|
|
3096
3109
|
const promises = [];
|
|
@@ -3153,7 +3166,12 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3153
3166
|
if (ruleId) ruleIdSet.add(ruleId);
|
|
3154
3167
|
});
|
|
3155
3168
|
});
|
|
3156
|
-
|
|
3169
|
+
const rules = [];
|
|
3170
|
+
for (const id of ruleIdSet) {
|
|
3171
|
+
const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, id);
|
|
3172
|
+
if (rule) rules.push(rule);
|
|
3173
|
+
}
|
|
3174
|
+
return rules;
|
|
3157
3175
|
}
|
|
3158
3176
|
getDataValidation(unitId, subUnitId, ranges) {
|
|
3159
3177
|
return this.getDataValidations(unitId, subUnitId, ranges)[0];
|
package/lib/types/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export { DataValidationCacheService } from './services/dv-cache.service';
|
|
|
23
23
|
export { DataValidationCustomFormulaService } from './services/dv-custom-formula.service';
|
|
24
24
|
export { DataValidationFormulaService } from './services/dv-formula.service';
|
|
25
25
|
export { DataValidationListCacheService, type IListCacheItem } from './services/dv-list-cache.service';
|
|
26
|
-
export { SheetsDataValidationValidatorService } from './services/dv-validator
|
|
26
|
+
export { SheetsDataValidationValidatorService } from './services/dv-validator.service';
|
|
27
27
|
export { createDefaultNewRule } from './utils/create';
|
|
28
28
|
export { getFormulaCellData, getFormulaResult } from './utils/formula';
|
|
29
29
|
export { isLegalFormulaResult } from './utils/formula';
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/data-validation`),require(`@univerjs/engine-formula`),require(`@univerjs/sheets`),require(`rxjs`),require(`@univerjs/protocol`),require(`@univerjs/sheets-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/data-validation`,`@univerjs/engine-formula`,`@univerjs/sheets`,`rxjs`,`@univerjs/protocol`,`@univerjs/sheets-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidation={},e.UniverCore,e.UniverDataValidation,e.UniverEngineFormula,e.UniverSheets,e.rxjs,e.UniverProtocol,e.UniverSheetsFormula))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function c(e){"@babel/helpers - typeof";return c=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},c(e)}function l(e,t){if(c(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(c(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function u(e){var t=l(e,`string`);return c(t)==`symbol`?t:t+``}function d(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){return function(n,r){t(n,r,e)}}function p(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 m=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._sheetDataValidationModel=n,d(this,`_cacheMatrix`,new Map),d(this,`_dirtyRanges$`,new a.Subject),d(this,`dirtyRanges$`,this._dirtyRanges$.asObservable()),this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted((e,n)=>{if(e.id===i.SetRangeValuesMutation.id&&!(n!=null&&n.onlyLocal)){let{cellValue:n,unitId:r,subUnitId:i}=e.params;if(n){let e=new t.ObjectMatrix(n).getDataRange();if(e.endRow===-1)return;let a=this._sheetDataValidationModel.getRules(r,i).map(e=>e.ranges).flat().map(n=>(0,t.getIntersectRange)(n,e)).filter(Boolean);a.length&&this.markRangeDirty(r,i,a,!0)}}}))}_initSheetRemove(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===i.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(e=>{e.type===t.UniverInstanceType.UNIVER_SHEET&&this._cacheMatrix.delete(e.getUnitId())}))}_ensureCache(e,n){let r=this._cacheMatrix.get(e);r||(r=new Map,this._cacheMatrix.set(e,r));let i=r.get(n);return i||(i=new t.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(e,n,r,i){let a=this._ensureCache(e,n);r.forEach(e=>{t.Range.foreach(e,(e,t)=>{a.getValue(e,t)!==void 0&&a.setValue(e,t,void 0)})}),this._dirtyRanges$.next({unitId:e,subUnitId:n,ranges:r,isSetRange:i})}_deleteRange(e,n,r){let i=this._ensureCache(e,n);r.forEach(e=>{t.Range.foreach(e,(e,t)=>{i.realDeleteValue(e,t)})}),this._dirtyRanges$.next({unitId:e,subUnitId:n,ranges:r})}getValue(e,t,n,r){return this._ensureCache(e,t).getValue(n,r)}};m=p([f(0,(0,t.Inject)(t.ICommandService)),f(1,(0,t.Inject)(t.IUniverInstanceService)),f(2,(0,t.Inject)(n.DataValidationModel))],m);function h(e){var t;return e==null||(t=e[0])==null||(t=t[0])==null?void 0:t.v}function g(e){var t;return e==null||(t=e[0])==null?void 0:t[0]}function _(e){return!r.ERROR_TYPE_SET.has(e)}function v(e,t){var n;let r=t.getValidatorItem(e);return(n=r==null?void 0:r.offsetFormulaByRange)==null?!1:n}let y=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=n,this._dataValidationCacheService=r,this._validatorRegistryService=i,d(this,`_ruleFormulaMap`,new Map),d(this,`_ruleFormulaMap2`,new Map),this._initFormulaResultHandler(),this._initDirtyRanges()}dispose(){super.dispose(),this._ruleFormulaMap.clear(),this._ruleFormulaMap2.clear()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(let n in e){let r=e[n];if(this._instanceSrv.getUnitType(n)===t.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,n,i,a){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,i,a,{ruleId:n},r.OtherFormulaBizType.DATA_VALIDATION_CUSTOM,n)}_handleDirtyRanges(e,n,r){this._dataValidationModel.getRules(e,n).forEach(i=>{let a=i.ranges;t.Rectangle.doAnyRangesIntersect(a,r)&&this.makeRuleDirty(e,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(e,n,r,i,a,o){let{ruleFormulaMap:s,ruleFormulaMap2:c}=this._ensureMaps(e,n),l=o[0].startRow,u=o[0].startColumn;if(i&&(0,t.isFormulaString)(i)){let t=this._registerFormula(e,n,r,i,o);s.set(r,{formula:i,originCol:u,originRow:l,formulaId:t})}if(a&&(0,t.isFormulaString)(a)){let t=this._registerFormula(e,n,r,a,o);c.set(r,{formula:a,originCol:u,originRow:l,formulaId:t})}}addRule(e,t,n){if(v(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 g(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 g(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 g(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 g(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)}};y=p([f(0,t.IUniverInstanceService),f(1,(0,t.Inject)(r.RegisterOtherFormulaService)),f(2,(0,t.Inject)(n.DataValidationModel)),f(3,(0,t.Inject)(m)),f(4,(0,t.Inject)(n.DataValidatorRegistryService))],y);function b(e){return(0,t.getOriginCellValue)(e)}function ee(e){var t;return String((t=b(e))==null?``:t)}function te(e){return e.filter(Boolean).join(`,`)}function x(e){return e.split(`,`).filter(Boolean)}function ne(e){let t=b(e);return t==null?``:t.toString()}function S(e,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,t.isFormulaString)(i)?e.moveFormulaRefOffset(i,l,c,!0):i,transformedFormula2:(0,t.isFormulaString)(a)?e.moveFormulaRefOffset(a,l,c,!0):a}}let C=class extends t.Disposable{constructor(e,t){super(),this._injector=e,this._dataValidationModel=t,d(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(w).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(e,n,r,i){var a;let{formula1:o=``,formula2:s=``}=r,c=(0,t.isFormulaString)(o)?this._getRuleFormulaResultSet(i==null||(a=i[0])==null||(a=a.result)==null||(a=a[0])==null?void 0:a[0]):x(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(e,n,r.uid,f),f}_getRuleFormulaResultSet(e){if(!e)return[];let n=new Set;for(let i=0,a=e.length;i<a;i++){let a=e[i];if(a)for(let e=0,i=a.length;e<i;e++){let i=a[e],o=b(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(t.numfmt.format(i.s.n.pattern,o,{throws:!1}));continue}let e=typeof o==`string`?o:String(o);_(e)&&n.add(e)}}}return[...n]}};C=p([f(0,(0,t.Inject)(t.Injector)),f(1,(0,t.Inject)(n.DataValidationModel))],C);let w=class extends t.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,d(this,`_formulaRuleMap`,new Map),this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(let n in e){let r=e[n];if(this._instanceService.getUnitType(n)===t.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,n,i){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,n,[{startColumn:0,endColumn:0,startRow:0,endRow:0}],{ruleId:i},r.OtherFormulaBizType.DATA_VALIDATION,i)}addRule(e,n,r){if(!v(r.type,this._validatorRegistryService)&&r.type!==t.DataValidationType.CHECKBOX){let{formula1:i,formula2:a,uid:o}=r,s=(0,t.isFormulaString)(i),c=(0,t.isFormulaString)(a);if(!s&&!c)return;let l=this._ensureRuleFormulaMap(e,n),u=[void 0,void 0];s&&(u[0]={id:this._registerSingleFormula(e,n,i,o),text:i}),c&&(u[1]={id:this._registerSingleFormula(e,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)}};w=p([f(0,t.IUniverInstanceService),f(1,(0,t.Inject)(r.RegisterOtherFormulaService)),f(2,(0,t.Inject)(m)),f(3,(0,t.Inject)(n.DataValidationModel)),f(4,(0,t.Inject)(n.DataValidatorRegistryService)),f(5,(0,t.Inject)(C))],w);var re=class e{constructor(e,n,r,i,a=!1){this._unitId=n,this._subUnitId=r,this._univerInstanceService=i,this._disableTree=a,d(this,`_map`,void 0),d(this,`_tree`,new t.RBush),d(this,`_dirty`,!0),d(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}),d(this,`_debonceBuildTree`,(0,t.debounce)(this._buildTree,0)),this._map=e,this._buildTree()}get _worksheet(){var e;return(e=this._univerInstanceService.getUnit(this._unitId,t.UniverInstanceType.UNIVER_SHEET))==null?void 0:e.getSheetBySheetId(this._subUnitId)}_addRule(e,n){if(!this._worksheet)return;let r=t.Rectangle.mergeRanges(n.map(e=>t.Range.transformRange(e,this._worksheet)));this._map.forEach((e,n)=>{let i=t.Rectangle.subtractMulti(e,r);i.length===0?this._map.delete(n):this._map.set(n,i)}),this._dirty=!0,this._map.set(e,r),this._debonceBuildTree()}addRule(e){this._addRule(e.uid,e.ranges)}removeRange(e){if(!this._worksheet)return;let n=e.map(e=>t.Range.transformRange(e,this._worksheet));this._map.forEach((e,r)=>{let i=t.Rectangle.subtractMulti(e,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(e){e.forEach(({id:e,ranges:n})=>{if(!n.length)return;let r=this._map.get(e);r?(this._map.set(e,t.Rectangle.mergeRanges([...r,...n])),r=this._map.get(e)):(r=n,this._map.set(e,r)),this._map.forEach((r,i)=>{if(i===e)return;let a=t.Rectangle.subtractMulti(r,n);a.length===0?this._map.delete(i):this._map.set(i,a)})}),this._dirty=!0,this._debonceBuildTree()}diff(e){let n=[],r=0;return e.forEach((e,i)=>{var a;let o=(a=this._map.get(e.uid))==null?[]:a,s=e.ranges;o.length!==0&&(o.length!==s.length||o.some((e,n)=>!t.Rectangle.equals(e,s[n])))&&n.push({type:`update`,ruleId:e.uid,oldRanges:s,newRanges:t.Rectangle.sort(o),rule:e}),o.length===0&&(n.push({type:`delete`,rule:e,index:i-r}),r++)}),n}diffWithAddition(e,n){let r=[],i=0;return e.forEach((e,n)=>{var a;let o=(a=this._map.get(e.uid))==null?[]:a,s=e.ranges;o.length!==0&&(o.length!==s.length||o.some((e,n)=>!t.Rectangle.equals(e,s[n])))&&r.push({type:`update`,ruleId:e.uid,oldRanges:s,newRanges:t.Rectangle.sort(o),rule:e}),o.length===0&&(r.push({type:`delete`,rule:e,index:n-i}),i++)}),Array.from(n).forEach(e=>{var n;let i=(n=this._map.get(e.uid))==null?[]:n;r.push({type:`add`,rule:{...e,ranges:t.Rectangle.sort(i)}})}),r}clone(){return new e(new Map(t.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 T=class extends t.Disposable{constructor(e,t,n,r,i,o,s){super(),this._dataValidationModel=e,this._univerInstanceService=t,this._dataValidatorRegistryService=n,this._dataValidationCacheService=r,this._dataValidationFormulaService=i,this._dataValidationCustomFormulaService=o,this._commandService=s,d(this,`_ruleMatrixMap`,new Map),d(this,`_validStatusChange$`,new a.Subject),d(this,`_ruleChange$`,new a.Subject),d(this,`ruleChange$`,this._ruleChange$.asObservable()),d(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===i.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 re(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,t,r,i,a){let o=this._ensureRuleMatrix(e,t),s={...i,...a.payload};a.type===n.UpdateRuleType.RANGE?o.updateRange(r,a.payload):a.type===n.UpdateRuleType.ALL&&o.updateRange(r,a.payload.ranges),this._dataValidationCacheService.removeRule(e,t,i),this._dataValidationCacheService.addRule(e,t,s),this._dataValidationFormulaService.removeRule(e,t,i.uid),this._dataValidationFormulaService.addRule(e,t,s),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,r),this._dataValidationCustomFormulaService.addRule(e,t,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(e,n,r){let{col:i,row:a,unitId:o,subUnitId:s,worksheet:c}=n,l=(t,n)=>{r&&r(t,n),n&&this._validStatusChange$.next({unitId:o,subUnitId:s,ruleId:e.uid,status:t,row:a,col:i})},u=c.getCellValueOnly(a,i),d=this.getValidator(e.type),f=c.getCellRaw(a,i),p=b(f);if(d){let r=this._dataValidationCacheService.ensureCache(o,s),c=r.getValue(a,i);return c==null?(r.setValue(a,i,t.DataValidationStatus.VALIDATING),d.validator({value:p,unitId:o,subUnitId:s,row:a,column:i,worksheet:n.worksheet,workbook:n.workbook,interceptValue:b(u),t:f==null?void 0:f.t},e).then(e=>{let n=e?t.DataValidationStatus.VALID:t.DataValidationStatus.INVALID,o=r.getValue(a,i);n===t.DataValidationStatus.VALID?r.realDeleteValue(a,i):r.setValue(a,i,n),l(n,c!==o)}),t.DataValidationStatus.VALIDATING):(l(c==null?t.DataValidationStatus.VALID:c,!1),c==null?t.DataValidationStatus.VALID:c)}else return l(t.DataValidationStatus.VALID,!1),t.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()}};T=p([f(0,(0,t.Inject)(n.DataValidationModel)),f(1,t.IUniverInstanceService),f(2,(0,t.Inject)(n.DataValidatorRegistryService)),f(3,(0,t.Inject)(m)),f(4,(0,t.Inject)(w)),f(5,(0,t.Inject)(y)),f(6,t.ICommandService)],T);function ie(e,n){return t.Tools.isBlank(e)?n.t(`dataValidation.validFail.value`):(0,t.isFormulaString)(e)?n.t(`dataValidation.validFail.primitive`):``}let E=e=>t.Tools.isDefine(e)&&String(e).toLowerCase()===`true`?`1`:String(e).toLowerCase()===`false`?`0`:e;var D=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.CHECKBOX),d(this,`title`,`dataValidation.checkbox.title`),d(this,`operators`,[]),d(this,`scopes`,[`sheet`]),d(this,`order`,41),d(this,`offsetFormulaByRange`,!1),d(this,`_formulaService`,this.injector.get(w)),d(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(e,n,r){let{formula1:i,formula2:a}=e,o=i===a;if(t.Tools.isBlank(i)&&t.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=ie(i,this.localeService),c=ie(a,this.localeService);return{success:!s&&!c,formula1:s,formula2:c}}async parseFormula(e,n,r){var i,a;let{formula1:o=1,formula2:s=0}=e,c=await this._formulaService.getRuleFormulaResult(n,r,e.uid),l=(0,t.isFormulaString)(o)?h(c==null||(i=c[0])==null||(i=i.result)==null?void 0:i[0][0]):o,u=(0,t.isFormulaString)(s)?h(c==null||(a=c[1])==null||(a=a.result)==null?void 0:a[0][0]):s,d=_(String(l))&&_(String(u));return{formula1:E(l),formula2:E(u),originFormula1:l,originFormula2:u,isFormulaValid:d}}getExtraStyle(e,n){return{tb:t.WrapStrategy.CLIP}}parseFormulaSync(e,n,r){var i,a;let{formula1:o=1,formula2:s=0}=e,c=this._formulaService.getRuleFormulaResultSync(n,r,e.uid),l=(0,t.isFormulaString)(o)?h(c==null||(i=c[0])==null||(i=i.result)==null?void 0:i[0][0]):o,u=(0,t.isFormulaString)(s)?h(c==null||(a=c[1])==null||(a=a.result)==null?void 0:a[0][0]):s,d=_(String(l))&&_(String(u));return{formula1:E(l),formula2:E(u),originFormula1:l,originFormula2:u,isFormulaValid:d}}async isValidType(e,n,r){let{value:i,unitId:a,subUnitId:o}=e,{formula1:s,formula2:c,originFormula1:l,originFormula2:u}=await this.parseFormula(r,a,o);return!t.Tools.isDefine(s)||!t.Tools.isDefine(c)?!0:t.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}};let ae={[t.DataValidationOperator.BETWEEN]:`dataValidation.date.operators.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.date.operators.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.date.operators.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.operators.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.date.operators.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.operators.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.operators.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.operators.notEqual`};t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL;let O={[t.DataValidationOperator.BETWEEN]:`dataValidation.date.ruleName.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.date.ruleName.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.date.ruleName.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.ruleName.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.date.ruleName.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.ruleName.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.ruleName.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.ruleName.notEqual`,NONE:`dataValidation.date.ruleName.legal`},oe={[t.DataValidationOperator.BETWEEN]:`dataValidation.date.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.date.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.date.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.date.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.errorMsg.notEqual`,NONE:`dataValidation.date.errorMsg.legal`},k=[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.NOT_BETWEEN],A=`{FORMULA1}`,j=`{FORMULA2}`,M=e=>{var n,r;if(e==null||typeof e==`boolean`)return;if(typeof e==`number`||!Number.isNaN(+e))return+e;let i=(n=t.numfmt.parseDate(e))==null?void 0:n.v;return t.Tools.isDefine(i)?i:(r=t.numfmt.parseDate((0,t.dateKit)(e).format(`YYYY-MM-DD HH:mm:ss`)))==null?void 0:r.v};var N=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.DATE),d(this,`title`,`dataValidation.date.title`),d(this,`order`,40),d(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),d(this,`scopes`,[`sheet`]),d(this,`_customFormulaService`,this.injector.get(y)),d(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder))}async parseFormula(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=_(String(o==null?void 0:o.v))&&_(String(s==null?void 0:s.v));return{formula1:M((0,t.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:M((0,t.isFormulaString)(l)?s==null?void 0:s.v:l),isFormulaValid:u}}async isValidType(e){let{interceptValue:n,value:r}=e;return typeof r==`number`&&typeof n==`string`||typeof n==`string`?!!t.numfmt.parseDate(n):!1}_validatorSingleFormula(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e)||!!(e&&t.numfmt.parseDate(e)))}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(e,n,r){let{formula1:i,formula2:a,bizInfo:o}=e,s=e=>{if(!e)return e;let n;if(!Number.isNaN(+e))n=t.numfmt.dateFromSerial(+e);else{var r;let i=(r=t.numfmt.parseDate(e))==null?void 0:r.v;if(i==null)return``;n=t.numfmt.dateFromSerial(i)}return(0,t.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,t.isFormulaString)(i)?i:s(`${i}`),formula2:(0,t.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(ae[e]))}generateRuleName(e){var t,n;if(!e.operator)return this.localeService.t(O.NONE);let r=this.localeService.t(O[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}=S(this._lexerTreeBuilder,e,t);return`${this.localeService.t(oe[e.operator]).replace(A,n==null?``:n).replace(j,r==null?``:r)}`}};t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL,t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL;let P={[t.DataValidationOperator.BETWEEN]:`dataValidation.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.errorMsg.notEqual`,NONE:`dataValidation.errorMsg.legal`};function F(e){return+e}var se=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`_customFormulaService`,this.injector.get(y)),d(this,`id`,t.DataValidationType.DECIMAL),d(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder)),d(this,`title`,`dataValidation.decimal.title`),d(this,`order`,20),d(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),d(this,`scopes`,[`sheet`])}_isFormulaOrNumber(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e))}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(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=_(String(o==null?void 0:o.v))&&_(String(s==null?void 0:s.v));return{formula1:this._parseNumber((0,t.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:this._parseNumber((0,t.isFormulaString)(l)?s==null?void 0:s.v:l),isFormulaValid:u}}validatorFormula(e,n,r){let i=e.operator;if(!i)return{success:!0};let a=t.Tools.isDefine(e.formula1)&&this._isFormulaOrNumber(e.formula1),o=t.Tools.isDefine(e.formula2)&&this._isFormulaOrNumber(e.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}=S(this._lexerTreeBuilder,e,t);return`${this.localeService.t(P[e.operator]).replace(A,n==null?``:n).replace(j,r==null?``:r)}`}};function ce(e){if(!e)return[];let n=new Set;for(let i=0,a=e.length;i<a;i++){let a=e[i];if(a)for(let e=0,i=a.length;e<i;e++){let i=a[e],o=b(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(t.numfmt.format(i.s.n.pattern,o,{throws:!1}));continue}let e=typeof o==`string`?o:String(o);_(e)&&n.add(e)}}}return[...n]}let le=[`if`,`indirect`,`choose`,`offset`];function ue(e,n){if(!(0,t.isFormulaString)(e)||(0,r.isReferenceString)(e.slice(1)))return!0;let i=n.sequenceNodesBuilder(e);return i&&i.some(e=>typeof e==`object`&&e.nodeType===r.sequenceNodeType.FUNCTION&&le.indexOf(e.token.toLowerCase())>-1)}function de(e,n){let{formula1:i=``,ranges:a}=e;if((0,r.isReferenceString)(i.slice(1))){let e=(0,r.deserializeRangeWithSheet)(i.slice(1));if((!e.sheetName||e.sheetName===n)&&a.some(n=>t.Rectangle.intersects(n,e.range)))return!0}return!1}var I=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`formulaService`,this.injector.get(w)),d(this,`_lexer`,this.injector.get(r.LexerTreeBuilder)),d(this,`_univerInstanceService`,this.injector.get(t.IUniverInstanceService)),d(this,`_listCacheService`,this.injector.get(C)),d(this,`order`,50),d(this,`offsetFormulaByRange`,!1),d(this,`id`,t.DataValidationType.LIST),d(this,`title`,`dataValidation.list.title`),d(this,`operators`,[]),d(this,`scopes`,[`sheet`]),d(this,`skipDefaultFontRender`,e=>e.renderMode!==t.DataValidationRenderMode.TEXT)}validatorFormula(e,n,r){var i,a;let o=!t.Tools.isBlank(e.formula1),s=ue((i=e.formula1)==null?``:i,this._lexer),c=(a=this._univerInstanceService.getUnit(n,t.UniverInstanceType.UNIVER_SHEET))==null||(a=a.getSheetBySheetId(r))==null?void 0:a.getName(),l=de(e,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(e,n,{style:r}){var i;let a=(i=r.tb===t.WrapStrategy.OVERFLOW?t.WrapStrategy.CLIP:r.tb)==null?t.WrapStrategy.WRAP:i;if(e.type===t.DataValidationType.LIST&&(e.renderMode===t.DataValidationRenderMode.ARROW||e.renderMode===t.DataValidationRenderMode.TEXT)){let t=this.getListWithColorMap(e)[`${n==null?``:n}`];if(t)return{bg:{rgb:t},tb:a}}return{tb:a}}parseCellValue(e){return x(e.toString())}async parseFormula(e,t,n){var r;let i=await this.formulaService.getRuleFormulaResult(t,n,e.uid),a=h(i==null||(r=i[0])==null||(r=r.result)==null?void 0:r[0][0]);return{formula1:void 0,formula2:void 0,isFormulaValid:_(String(a))}}async isValidType(e,n,r){let{value:i,unitId:a,subUnitId:o}=e,{formula1:s=``}=r,c=(0,t.isFormulaString)(s)?this._listCacheService.getOrCompute(a,o,r).list:x(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(e,n){var r,i;let a=(r=e?this._univerInstanceService.getUniverSheetInstance(e):void 0)==null?this._univerInstanceService.getCurrentUnitForType(t.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(e,n,r){var i;let{formula1:a=``}=e,o=this._getUnitAndSubUnit(n,r);if(!o)return[];let{unitId:s,subUnitId:c}=o,l=await this.formulaService.getRuleFormulaResult(s,c,e.uid);return(0,t.isFormulaString)(a)?ce(l==null||(i=l[0])==null||(i=i.result)==null?void 0:i[0][0]):x(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}},fe=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.TEXT_LENGTH),d(this,`title`,`dataValidation.textLength.title`),d(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder)),d(this,`order`,30),d(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),d(this,`scopes`,[`sheet`]),d(this,`_customFormulaService`,this.injector.get(y))}_isFormulaOrInt(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}validatorFormula(e,n,r){let i=e.operator;if(!i)return{success:!1};let a=t.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),o=t.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.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(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=_(String(o==null?void 0:o.v))&&_(String(s==null?void 0:s.v));return{formula1:this._parseNumber((0,t.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:this._parseNumber((0,t.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,t){if(!e.operator)return this.titleStr;let{transformedFormula1:r,transformedFormula2:i}=S(this._lexerTreeBuilder,e,t);return`${this.localeService.t(n.TextLengthErrorTitleMap[e.operator]).replace(A,r==null?``:r).replace(j,i==null?``:i)}`}};function L(e){var n,r;return e?e.p?!((n=(r=e.p.body)==null?void 0:r.dataStream)==null?``:n).slice(0,-2).trim():t.Tools.isBlank(e.v):!0}function R(e,a,o,s,c=`command`,l=!0){let u=s.get(r.LexerTreeBuilder),d=s.get(n.DataValidatorRegistryService),f=[],p=[],m=s.get(T),h=(0,i.getSheetCommandTarget)(s.get(t.IUniverInstanceService),{unitId:e,subUnitId:a});if(!h)return{redoMutations:f,undoMutations:p};let{worksheet:g}=h,_=new t.ObjectMatrix,y=!1;function b(e,n){l&&e.forEach(e=>{t.Range.foreach(e,(e,t)=>{let r=g.getCellRaw(e,t),i=ee(r);(L(r)||i===n)&&!(r!=null&&r.p)&&(y=!0,_.setValue(e,t,{v:n,p:null}))})})}if(o.forEach(r=>{switch(r.type){case`delete`:f.push({id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.rule.uid,source:c}}),p.unshift({id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:a,rule:r.rule,index:r.index,source:c}});break;case`update`:{if(v(r.rule.type,d)){let i=r.oldRanges[0].startRow,o=r.oldRanges[0].startColumn,s=r.newRanges[0].startRow,l=r.newRanges[0].startColumn,d=s-i,m=l-o,h=(0,t.isFormulaString)(r.rule.formula1)?u.moveFormulaRefOffset(r.rule.formula1,m,d):r.rule.formula1,g=(0,t.isFormulaString)(r.rule.formula2)?u.moveFormulaRefOffset(r.rule.formula2,m,d):r.rule.formula2;h!==r.rule.formula1||g!==r.rule.formula2||!(0,t.isRangesEqual)(r.newRanges,r.oldRanges)?(f.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.ALL,payload:{formula1:h,formula2:g,ranges:r.newRanges}}}}),p.unshift({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.ALL,payload:{formula1:r.rule.formula1,formula2:r.rule.formula2,ranges:r.oldRanges}}}})):(f.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.newRanges},source:c}}),p.unshift({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.oldRanges},source:c}}))}else f.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.newRanges},source:c}}),p.unshift({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.oldRanges},source:c}});let i=m.getRuleById(e,a,r.ruleId);if(i&&i.type===t.DataValidationType.CHECKBOX){let n=m.getValidator(t.DataValidationType.CHECKBOX).parseFormulaSync(i,e,a);b(r.newRanges,n.formula2)}break}case`add`:if(f.push({id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:a,rule:r.rule,source:c}}),p.unshift({id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.rule.uid,source:c}}),r.rule.type===t.DataValidationType.CHECKBOX){let n=m.getValidator(t.DataValidationType.CHECKBOX).parseFormulaSync(r.rule,e,a);b(r.rule.ranges,n.originFormula2)}break;default:break}}),y){let t={id:i.SetRangeValuesMutation.id,params:{unitId:e,subUnitId:a,cellValue:_.getData()}},n={id:i.SetRangeValuesMutation.id,params:(0,i.SetRangeValuesUndoMutationFactory)(s,t.params)};f.push(t),p.push(n)}return{redoMutations:f,undoMutations:p}}let z={type:t.CommandType.COMMAND,id:`sheet.command.updateDataValidationRuleRange`,handler(e,n){if(!n)return!1;let{unitId:r,subUnitId:i,ranges:a,ruleId:o}=n,s=e.get(T),c=e.get(t.ICommandService),l=e.get(t.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)),e);return l.pushUndoRedo({undoMutations:f,redoMutations:d,unitID:r}),(0,t.sequenceExecute)(d,c),!0}},B={type:t.CommandType.COMMAND,id:`sheet.command.addDataValidation`,handler(e,r){if(!r)return!1;let{unitId:i,subUnitId:a,rule:o}=r,s=e.get(T),c=e.get(t.ICommandService),l=e.get(t.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,e);return m.push({id:n.AddDataValidationMutation.id,params:p}),h.unshift({id:n.RemoveDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:o.uid}}),l.pushUndoRedo({unitID:i,redoMutations:m,undoMutations:h}),(0,t.sequenceExecute)(m,c),!0}},V={type:t.CommandType.COMMAND,id:`sheets.command.update-data-validation-setting`,handler(e,r){if(!r)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(T),c=e.get(n.DataValidatorRegistryService),{unitId:l,subUnitId:u,ruleId:d,setting:f}=r,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:n.UpdateRuleType.SETTING,payload:{...f,...p.normalizeFormula(h,l,u)}}},_=[{id:n.UpdateDataValidationMutation.id,params:g}],v={unitId:l,subUnitId:u,ruleId:d,payload:{type:n.UpdateRuleType.SETTING,payload:(0,n.getRuleSetting)(m)}},y=[{id:n.UpdateDataValidationMutation.id,params:v}];if(f.type===t.DataValidationType.CHECKBOX){let n=m.ranges,r=(0,i.getSheetCommandTarget)(e.get(t.IUniverInstanceService),{unitId:l,subUnitId:u});if(r){let a=new t.ObjectMatrix,{worksheet:o}=r,{formula2:s=0,formula1:c=1}=m,{formula2:d=0,formula1:p=1}=f,h=!1;if(n.forEach(e=>{t.Range.foreach(e,(e,t)=>{let n=o.getCellRaw(e,t),r=ee(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 t={id:i.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:u,cellValue:a.getData()}},n={id:i.SetRangeValuesMutation.id,params:(0,i.SetRangeValuesUndoMutationFactory)(e,t.params)};_.push(t),y.push(n)}}}return(0,t.sequenceExecute)(_,a).result?(o.pushUndoRedo({unitID:l,redoMutations:_,undoMutations:y}),!0):!1}},H={type:t.CommandType.COMMAND,id:`sheets.command.update-data-validation-options`,handler(e,r){if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(T),{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:n.UpdateRuleType.OPTIONS,payload:u}},p=[{id:n.UpdateDataValidationMutation.id,params:f}],m={unitId:s,subUnitId:c,ruleId:l,payload:{type:n.UpdateRuleType.OPTIONS,payload:(0,n.getRuleOptions)(d)}},h=[{id:n.UpdateDataValidationMutation.id,params:m}];return a.pushUndoRedo({unitID:s,redoMutations:p,undoMutations:h}),i.executeCommand(n.UpdateDataValidationMutation.id,f),!0}},U={type:t.CommandType.COMMAND,id:`sheets.command.clear-range-data-validation`,handler(e,n){if(!n)return!1;let{unitId:r,subUnitId:a,ranges:o}=n,s=e.get(t.ICommandService),c=(0,i.getSheetCommandTarget)(e.get(t.IUniverInstanceService),{unitId:r,subUnitId:a}),l=e.get(T);if(!c)return!1;let u=e.get(t.IUndoRedoService),d=l.getRuleObjectMatrix(r,a).clone();d.removeRange(o);let{redoMutations:f,undoMutations:p}=R(r,a,d.diff(l.getRules(r,a)),e);return u.pushUndoRedo({unitID:r,redoMutations:f,undoMutations:p}),(0,t.sequenceExecute)(f,s).result}},W={type:t.CommandType.COMMAND,id:`sheet.command.remove-all-data-validation`,handler(e,r){if(!r)return!1;let{unitId:i,subUnitId:a}=r,o=e.get(t.ICommandService),s=e.get(T),c=e.get(t.IUndoRedoService),l=[...s.getRules(i,a)],u={unitId:i,subUnitId:a,ruleId:l.map(e=>e.uid)},d=[{id:n.RemoveDataValidationMutation.id,params:u}],f=[{id:n.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:l}}];return c.pushUndoRedo({redoMutations:d,undoMutations:f,unitID:i}),o.executeCommand(n.RemoveDataValidationMutation.id,u),!0}},pe=(e,t)=>{let r=e.get(T),{unitId:i,subUnitId:a,ruleId:o,source:s}=t;if(Array.isArray(o)){let e=o.map(e=>r.getRuleById(i,a,e)).filter(Boolean);return[{id:n.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:e,source:s}}]}return[{id:n.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:{...r.getRuleById(i,a,o)},index:r.getRuleIndex(i,a,o)}}]},me={type:t.CommandType.COMMAND,id:`sheet.command.remove-data-validation-rule`,handler(e,r){if(!r)return!1;let{unitId:i,subUnitId:a,ruleId:o}=r,s=e.get(t.ICommandService),c=e.get(t.IUndoRedoService),l=e.get(T),u=[{id:n.RemoveDataValidationMutation.id,params:r}],d=[{id:n.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(n.RemoveDataValidationMutation.id,r),!0}},G=`SHEET_DATA_VALIDATION_PLUGIN`,K=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._permissionService=t,this._lexerTreeBuilder=n}getFormulaRefCheck(e){let n=this._lexerTreeBuilder.sequenceNodesBuilder(e);if(!n)return!0;for(let e=0;e<n.length;e++){let s=n[e];if(typeof s==`string`)continue;let{token:c}=s,l=(0,r.deserializeRangeWithSheetWithCache)(c),u=this._univerInstanceService.getCurrentUnitForType(t.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 i.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 a;let n=(a=d.getCell(e,t))==null||(a=a.selectionProtection)==null?void 0:a[0];if((n==null?void 0:n[o.UnitAction.View])===!1)return!1}}return!0}};K=p([f(0,t.IUniverInstanceService),f(1,t.IPermissionService),f(2,(0,t.Inject)(r.LexerTreeBuilder))],K);var he=`@univerjs/sheets-data-validation`,ge=`0.22.1`;let q=`sheets-data-validation.config`;Symbol(q);let _e={},J=class extends t.Disposable{constructor(e,t,n){super(),this._dataValidationModel=e,this._formulaRefRangeService=t,this._validatorRegistryService=n,d(this,`_disposableMap`,new Map),d(this,`registerRule`,(e,t,n)=>{v(n.type,this._validatorRegistryService)&&this.register(e,t,n)}),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}_${t}_${n}`}register(e,r,i){let a=i.ranges,o=i.formula1,s=i.formula2,c=this._formulaRefRangeService.registerRangeFormula(e,r,a,[o==null?``:o,s==null?``:s],c=>{if(c.length===0)return{undos:[{id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:r,rule:i,source:`patched`}}],redos:[{id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:i.uid,source:`patched`}}]};let l=[],u=[],d=c[0];l.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:i.uid,payload:{type:n.UpdateRuleType.ALL,payload:{ranges:d.ranges,formula1:d.formulas[0],formula2:d.formulas[1]}},source:`patched`}}),u.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:i.uid,payload:{type:n.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,t.generateRandomId)();l.push({id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:r,rule:{...i,uid:s,formula1:o.formulas[0],formula2:o.formulas[1],ranges:o.ranges},source:`patched`}}),u.push({id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:s,source:`patched`}})}return{undos:u,redos:l}}),l=this._getIdWithUnitId(e,r,i.uid);this._disposableMap.set(l,c)}_initRefRange(){let e=this._dataValidationModel.getAll();for(let[t,n]of e)for(let[e,r]of n)for(let n of r)this.registerRule(t,e,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,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};J=p([f(0,(0,t.Inject)(T)),f(1,(0,t.Inject)(s.FormulaRefRangeService)),f(2,(0,t.Inject)(n.DataValidatorRegistryService))],J);let Y=class extends t.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,d(this,`_disposableMap`,new Map),d(this,`registerRule`,(e,t,n)=>{v(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,t,r){var i;let a=r.uid,o=this._getIdWithUnitId(e,t,a),s=(i=this._disposableMap.get(o))==null?new Set:i,c=(i,o)=>{let s=this._dataValidationModel.getRuleById(e,t,a);if(!s)return{redos:[],undos:[]};let c=s[i];if(!c||c===o)return{redos:[],undos:[]};let l={unitId:e,subUnitId:t,ruleId:r.uid,payload:{type:n.UpdateRuleType.SETTING,payload:{type:s.type,formula1:s.formula1,formula2:s.formula2,[i]:o}},source:`patched`},u={unitId:e,subUnitId:t,ruleId:r.uid,payload:{type:n.UpdateRuleType.SETTING,payload:{type:s.type,formula1:s.formula1,formula2:s.formula2}},source:`patched`};return{redos:[{id:n.UpdateDataValidationMutation.id,params:l}],undos:[{id:n.UpdateDataValidationMutation.id,params:u}]}},l=this._dataValidationFormulaService.getRuleFormulaInfo(e,t,a);if(l){let[n,r]=l;if(n){let r=this._formulaRefRangeService.registerFormula(e,t,n.text,e=>c(`formula1`,e));s.add(()=>r.dispose())}if(r){let n=this._formulaRefRangeService.registerFormula(e,t,r.text,e=>c(`formula2`,e));s.add(()=>n.dispose())}}}register(e,r,a){var o;let s=o=>{let s=[...a.ranges],c=s.map(e=>(0,i.handleCommonDefaultRangeChangeWithEffectRefCommands)(e,o)).filter(e=>!!e).flat();if((0,t.isRangesEqual)(c,s))return{redos:[],undos:[]};if(c.length){let t={unitId:e,subUnitId:r,ruleId:a.uid,payload:{type:n.UpdateRuleType.RANGE,payload:c},source:`patched`};return{redos:[{id:n.UpdateDataValidationMutation.id,params:t}],undos:[{id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:a.uid,payload:{type:n.UpdateRuleType.RANGE,payload:s},source:`patched`}}]}}else{let t={unitId:e,subUnitId:r,ruleId:a.uid};return{redos:[{id:n.RemoveDataValidationMutation.id,params:t}],undos:pe(this._injector,t)}}},c=[];a.ranges.forEach(t=>{let n=this._refRangeService.registerRefRange(t,s,e,r);c.push(()=>n.dispose())});let l=this._getIdWithUnitId(e,r,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 e=this._dataValidationModel.getAll();for(let[t,n]of e)for(let[e,r]of n)for(let n of r)this.registerRule(t,e,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,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.forEach(e=>e())}),this._disposableMap.clear()}))}};Y=p([f(0,(0,t.Inject)(T)),f(1,(0,t.Inject)(t.Injector)),f(2,(0,t.Inject)(i.RefRangeService)),f(3,(0,t.Inject)(w)),f(4,(0,t.Inject)(s.FormulaRefRangeService)),f(5,(0,t.Inject)(n.DataValidatorRegistryService))],Y);let X=class extends t.Disposable{constructor(e,t,n){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._sheetDataValidationModel=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===i.RemoveSheetCommand.id){var r;let i=e.params,a=i.unitId||this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=this._univerInstanceService.getUniverSheetInstance(a);if(!o)return{redos:[],undos:[]};let s=i.subUnitId||((r=o.getActiveSheet())==null?void 0:r.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:n.RemoveDataValidationMutation.id,params:l}],undos:[{id:n.AddDataValidationMutation.id,params:u}]}}else if(e.id===i.CopySheetCommand.id){let{unitId:r,subUnitId:i,targetSubUnitId:a}=e.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(e=>({...e,uid:(0,t.generateRandomId)(6)}));return{redos:[{id:n.AddDataValidationMutation.id,params:{unitId:r,subUnitId:a,rule:s,source:`patched`}}],undos:[{id:n.RemoveDataValidationMutation.id,params:{unitId:r,subUnitId:a,ruleId:s.map(e=>e.uid),source:`patched`}}]}}return{redos:[],undos:[]}}}))}};X=p([f(0,(0,t.Inject)(i.SheetInterceptorService)),f(1,(0,t.Inject)(t.IUniverInstanceService)),f(2,(0,t.Inject)(T))],X);var ve=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.ANY),d(this,`title`,`dataValidation.any.title`),d(this,`operators`,[]),d(this,`scopes`,[`sheet`]),d(this,`order`,0),d(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`)}},ye=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.CUSTOM),d(this,`title`,`dataValidation.custom.title`),d(this,`operators`,[]),d(this,`scopes`,[`sheet`]),d(this,`order`,60),d(this,`_customFormulaService`,this.injector.get(y)),d(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder))}validatorFormula(e,n,i){var a;let o=(0,t.isFormulaString)(e.formula1),s=(a=e.formula1)==null?``:a,c=this._lexerTreeBuilder.checkIfAddBracket(s)===0&&s.startsWith(r.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(e,n,r){let{column:i,row:a,unitId:o,subUnitId:s}=e,c=await this._customFormulaService.getCellFormulaValue(o,s,r.uid,a,i),l=c==null?void 0:c.v;return _(String(l))&&t.Tools.isDefine(l)&&l!==``?c.t===t.CellValueType.BOOLEAN?!!l:typeof l==`boolean`?l:typeof l==`number`?!!l:typeof l==`string`?_(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)}},be=class extends I{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.LIST_MULTIPLE),d(this,`title`,`dataValidation.listMultiple.title`),d(this,`offsetFormulaByRange`,!1),d(this,`skipDefaultFontRender`,()=>!0)}},xe=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`_customFormulaService`,this.injector.get(y)),d(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder)),d(this,`id`,t.DataValidationType.WHOLE),d(this,`title`,`dataValidation.whole.title`),d(this,`order`,10),d(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),d(this,`scopes`,[`sheet`])}_isFormulaOrInt(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}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(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=(0,t.isFormulaString)(c)?o==null?void 0:o.v:c,d=(0,t.isFormulaString)(l)?s==null?void 0:s.v:l,f=_(`${u}`)&&_(`${d}`);return{formula1:this._parseNumber(u),formula2:this._parseNumber(d),isFormulaValid:f}}validatorFormula(e,n,r){let i=e.operator;if(!i)return{success:!0};let a=t.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),o=t.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.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}=S(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 t.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(){[ve,se,xe,fe,N,D,I,be,ye].forEach(e=>{let n=this._injector.createInstance(e);this.disposeWithMe(this._dataValidatorRegistryService.register(n)),this.disposeWithMe((0,t.toDisposable)(()=>this._injector.delete(e)))})}_initCommandInterceptor(){this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===i.ClearSelectionAllCommand.id){var n;let e=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),r=e.getUnitId(),i=e.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=p([f(0,t.IUniverInstanceService),f(1,(0,t.Inject)(n.DataValidatorRegistryService)),f(2,(0,t.Inject)(t.Injector)),f(3,(0,t.Inject)(i.SheetsSelectionsService)),f(4,(0,t.Inject)(i.SheetInterceptorService)),f(5,(0,t.Inject)(T))],Z);let Q=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetDataValidationModel=t,this._dataValidationCacheService=n,this._lifecycleService=r,this._initRecalculate()}_initRecalculate(){let e=e=>{if(e.length===0)return;let n=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getActiveSheet(),i={};e.flat().forEach(e=>{i[e.unitId]||(i[e.unitId]={}),i[e.unitId][e.subUnitId]||(i[e.unitId][e.subUnitId]=[]);let n=this._univerInstanceService.getUnit(e.unitId,t.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getSheetBySheetId(e.subUnitId);r&&i[e.unitId][e.subUnitId].push(...e.ranges.map(e=>t.Range.transformRange(e,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,a.bufferWhen)(()=>this._lifecycleService.lifecycle$.pipe((0,a.skip)(1),(0,a.filter)(e=>e===t.LifecycleStages.Rendered)))).subscribe(e)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe((0,a.filter)(()=>this._lifecycleService.stage>=t.LifecycleStages.Rendered),(0,t.bufferDebounceTime)(20)).subscribe(e))}async _validatorByCell(e,n,r,i){let a=e.getUnitId(),o=n.getSheetId();if(!t.Tools.isDefine(r)||!t.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(t=>{this._sheetDataValidationModel.validator(u,{unitId:a,subUnitId:o,row:s,col:c,worksheet:n,workbook:e},e=>{t(e)})}):t.DataValidationStatus.VALID}async validatorCell(e,n,r,i){let a=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!a)throw Error(`cannot find current workbook, unitId: ${e}`);let o=a.getSheetBySheetId(n);if(!o)throw Error(`cannot find current worksheet, sheetId: ${n}`);return this._validatorByCell(a,o,r,i)}async validatorRanges(e,n,r){if(!r.length)return Promise.resolve([]);let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)throw Error(`cannot find current workbook, unitId: ${e}`);let a=i.getSheetBySheetId(n);if(!a)throw Error(`cannot find current worksheet, sheetId: ${n}`);let o=this._sheetDataValidationModel.getRules(e,n).map(e=>e.ranges).flat(),s=r.map(e=>o.map(n=>(0,t.getIntersectRange)(e,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]===t.DataValidationStatus.VALIDATING){var s;l[r][i]=(s=this._dataValidationCacheService.getValue(e,n,a,o))==null?t.DataValidationStatus.VALID:s}}),l}async validatorWorksheet(e,n){let r=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!r)throw Error(`cannot find current workbook, unitId: ${e}`);let i=r.getSheetBySheetId(n);if(!i)throw Error(`cannot find current worksheet, sheetId: ${n}`);let a=this._sheetDataValidationModel.getRules(e,n);return await Promise.all(a.map(e=>Promise.all(e.ranges.map(e=>{let n=[];return t.Range.foreach(e,(e,t)=>{n.push(this._validatorByCell(r,i,e,t))}),Promise.all(n)})))),this._dataValidationCacheService.ensureCache(e,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(e,n,r){let i=this._sheetDataValidationModel.getRuleObjectMatrix(e,n),a=new Set;return r.forEach(e=>{t.Range.foreach(e,(e,t)=>{let n=i.getValue(e,t);n&&a.add(n)})}),Array.from(a).map(t=>this._sheetDataValidationModel.getRuleById(e,n,t)).filter(Boolean)}getDataValidation(e,t,n){return this.getDataValidations(e,t,n)[0]}};Q=p([f(0,t.IUniverInstanceService),f(1,(0,t.Inject)(T)),f(2,(0,t.Inject)(m)),f(3,(0,t.Inject)(t.LifecycleService))],Q);let $=class extends t.Plugin{constructor(e=_e,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},_e,this._config);this._configService.setConfig(q,a)}onStarting(){[[m],[C],[w],[y],[Q],[T],[Z],[K],[X],[Y],[J]].forEach(e=>{this._injector.add(e)}),[B,z,V,H,me,W,U].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(m),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(K)}};d($,`pluginName`,G),d($,`packageName`,he),d($,`version`,ge),d($,`type`,t.UniverInstanceType.UNIVER_SHEET),$=p([(0,t.DependentOn)(s.UniverSheetsFormulaPlugin,n.UniverDataValidationPlugin),f(1,(0,t.Inject)(t.Injector)),f(2,t.ICommandService),f(3,t.IConfigService)],$);function Se(e){let n=e.get(i.SheetsSelectionsService).getCurrentSelections().map(e=>e.range);return{uid:(0,t.generateRandomId)(6),type:t.DataValidationType.DECIMAL,operator:t.DataValidationOperator.EQUAL,formula1:`100`,ranges:n==null?[{startColumn:0,endColumn:0,startRow:0,endRow:0}]:n}}e.AddSheetDataValidationCommand=B,e.BASE_FORMULA_INPUT_NAME=`data-validation.formula-input`,e.CHECKBOX_FORMULA_1=1,e.CHECKBOX_FORMULA_2=0,e.CHECKBOX_FORMULA_INPUT_NAME=`data-validation.checkbox-formula-input`,e.CUSTOM_FORMULA_INPUT_NAME=`data-validation.custom-formula-input`,e.CheckboxValidator=D,e.ClearRangeDataValidationCommand=U,e.DATA_VALIDATION_PLUGIN_NAME=G,Object.defineProperty(e,`DataValidationCacheService`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(e,`DataValidationCustomFormulaService`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(e,`DataValidationFormulaController`,{enumerable:!0,get:function(){return K}}),Object.defineProperty(e,`DataValidationFormulaService`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(e,`DataValidationListCacheService`,{enumerable:!0,get:function(){return C}}),e.DateValidator=N,e.LIST_FORMULA_INPUT_NAME=`data-validation.list-formula-input`,e.ListMultipleValidator=be,e.ListValidator=I,e.RemoveSheetAllDataValidationCommand=W,e.RemoveSheetDataValidationCommand=me,Object.defineProperty(e,`SheetDataValidationModel`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(e,`SheetsDataValidationValidatorService`,{enumerable:!0,get:function(){return Q}}),Object.defineProperty(e,`UniverSheetsDataValidationPlugin`,{enumerable:!0,get:function(){return $}}),e.UpdateSheetDataValidationOptionsCommand=H,e.UpdateSheetDataValidationRangeCommand=z,e.UpdateSheetDataValidationSettingCommand=V,e.createDefaultNewRule=Se,e.deserializeListOptions=x,e.getCellValueNumber=F,e.getCellValueOrigin=b,e.getDataValidationCellValue=ne,e.getDataValidationDiffMutations=R,e.getFormulaCellData=g,e.getFormulaResult=h,e.getTransformedFormula=S,e.isLegalFormulaResult=_,e.serializeListOptions=te,e.transformCheckboxValue=E});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/data-validation`),require(`@univerjs/engine-formula`),require(`@univerjs/sheets`),require(`rxjs`),require(`@univerjs/protocol`),require(`@univerjs/sheets-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/data-validation`,`@univerjs/engine-formula`,`@univerjs/sheets`,`rxjs`,`@univerjs/protocol`,`@univerjs/sheets-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidation={},e.UniverCore,e.UniverDataValidation,e.UniverEngineFormula,e.UniverSheets,e.rxjs,e.UniverProtocol,e.UniverSheetsFormula))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function c(e){"@babel/helpers - typeof";return c=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},c(e)}function l(e,t){if(c(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(c(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function u(e){var t=l(e,`string`);return c(t)==`symbol`?t:t+``}function d(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){return function(n,r){t(n,r,e)}}function p(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 m=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._sheetDataValidationModel=n,d(this,`_cacheMatrix`,new Map),d(this,`_dirtyRanges$`,new a.Subject),d(this,`dirtyRanges$`,this._dirtyRanges$.asObservable()),this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted((e,n)=>{if(e.id===i.SetRangeValuesMutation.id&&!(n!=null&&n.onlyLocal)){let{cellValue:n,unitId:r,subUnitId:i}=e.params;if(n){let e=new t.ObjectMatrix(n).getDataRange();if(e.endRow===-1)return;let a=this._sheetDataValidationModel.getRules(r,i),o=[];for(let e of a)o.push(...e.ranges);let s=[];for(let n of o){let r=(0,t.getIntersectRange)(n,e);r&&s.push(r)}s.length&&this.markRangeDirty(r,i,s,!0)}}}))}_initSheetRemove(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===i.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(e=>{e.type===t.UniverInstanceType.UNIVER_SHEET&&this._cacheMatrix.delete(e.getUnitId())}))}_ensureCache(e,n){let r=this._cacheMatrix.get(e);r||(r=new Map,this._cacheMatrix.set(e,r));let i=r.get(n);return i||(i=new t.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(e,n,r,i){let a=this._ensureCache(e,n);r.forEach(e=>{t.Range.foreach(e,(e,t)=>{a.getValue(e,t)!==void 0&&a.setValue(e,t,void 0)})}),this._dirtyRanges$.next({unitId:e,subUnitId:n,ranges:r,isSetRange:i})}_deleteRange(e,n,r){let i=this._ensureCache(e,n);r.forEach(e=>{t.Range.foreach(e,(e,t)=>{i.realDeleteValue(e,t)})}),this._dirtyRanges$.next({unitId:e,subUnitId:n,ranges:r})}getValue(e,t,n,r){return this._ensureCache(e,t).getValue(n,r)}};m=p([f(0,(0,t.Inject)(t.ICommandService)),f(1,(0,t.Inject)(t.IUniverInstanceService)),f(2,(0,t.Inject)(n.DataValidationModel))],m);function h(e){var t;return e==null||(t=e[0])==null||(t=t[0])==null?void 0:t.v}function g(e){var t;return e==null||(t=e[0])==null?void 0:t[0]}function _(e){return!r.ERROR_TYPE_SET.has(e)}function v(e,t){var n;let r=t.getValidatorItem(e);return(n=r==null?void 0:r.offsetFormulaByRange)==null?!1:n}let y=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=n,this._dataValidationCacheService=r,this._validatorRegistryService=i,d(this,`_ruleFormulaMap`,new Map),d(this,`_ruleFormulaMap2`,new Map),this._initFormulaResultHandler(),this._initDirtyRanges()}dispose(){super.dispose(),this._ruleFormulaMap.clear(),this._ruleFormulaMap2.clear()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(let n in e){let r=e[n];if(this._instanceSrv.getUnitType(n)===t.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,n,i,a){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,i,a,{ruleId:n},r.OtherFormulaBizType.DATA_VALIDATION_CUSTOM,n)}_handleDirtyRanges(e,n,r){this._dataValidationModel.getRules(e,n).forEach(i=>{let a=i.ranges;t.Rectangle.doAnyRangesIntersect(a,r)&&this.makeRuleDirty(e,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(e,n,r,i,a,o){let{ruleFormulaMap:s,ruleFormulaMap2:c}=this._ensureMaps(e,n),l=o[0].startRow,u=o[0].startColumn;if(i&&(0,t.isFormulaString)(i)){let t=this._registerFormula(e,n,r,i,o);s.set(r,{formula:i,originCol:u,originRow:l,formulaId:t})}if(a&&(0,t.isFormulaString)(a)){let t=this._registerFormula(e,n,r,a,o);c.set(r,{formula:a,originCol:u,originRow:l,formulaId:t})}}addRule(e,t,n){if(v(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 g(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 g(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 g(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 g(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)}};y=p([f(0,t.IUniverInstanceService),f(1,(0,t.Inject)(r.RegisterOtherFormulaService)),f(2,(0,t.Inject)(n.DataValidationModel)),f(3,(0,t.Inject)(m)),f(4,(0,t.Inject)(n.DataValidatorRegistryService))],y);function b(e){return(0,t.getOriginCellValue)(e)}function ee(e){var t;return String((t=b(e))==null?``:t)}function te(e){return e.filter(Boolean).join(`,`)}function x(e){return e.split(`,`).filter(Boolean)}function ne(e){let t=b(e);return t==null?``:t.toString()}function S(e,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,t.isFormulaString)(i)?e.moveFormulaRefOffset(i,l,c,!0):i,transformedFormula2:(0,t.isFormulaString)(a)?e.moveFormulaRefOffset(a,l,c,!0):a}}let C=class extends t.Disposable{constructor(e,t){super(),this._injector=e,this._dataValidationModel=t,d(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(w).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(e,n,r,i){var a;let{formula1:o=``,formula2:s=``}=r,c=(0,t.isFormulaString)(o)?this._getRuleFormulaResultSet(i==null||(a=i[0])==null||(a=a.result)==null||(a=a[0])==null?void 0:a[0]):x(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(e,n,r.uid,f),f}_getRuleFormulaResultSet(e){if(!e)return[];let n=new Set;for(let i=0,a=e.length;i<a;i++){let a=e[i];if(a)for(let e=0,i=a.length;e<i;e++){let i=a[e],o=b(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(t.numfmt.format(i.s.n.pattern,o,{throws:!1}));continue}let e=typeof o==`string`?o:String(o);_(e)&&n.add(e)}}}return[...n]}};C=p([f(0,(0,t.Inject)(t.Injector)),f(1,(0,t.Inject)(n.DataValidationModel))],C);let w=class extends t.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,d(this,`_formulaRuleMap`,new Map),this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(let n in e){let r=e[n];if(this._instanceService.getUnitType(n)===t.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,n,i){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,n,[{startColumn:0,endColumn:0,startRow:0,endRow:0}],{ruleId:i},r.OtherFormulaBizType.DATA_VALIDATION,i)}addRule(e,n,r){if(!v(r.type,this._validatorRegistryService)&&r.type!==t.DataValidationType.CHECKBOX){let{formula1:i,formula2:a,uid:o}=r,s=(0,t.isFormulaString)(i),c=(0,t.isFormulaString)(a);if(!s&&!c)return;let l=this._ensureRuleFormulaMap(e,n),u=[void 0,void 0];s&&(u[0]={id:this._registerSingleFormula(e,n,i,o),text:i}),c&&(u[1]={id:this._registerSingleFormula(e,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)}};w=p([f(0,t.IUniverInstanceService),f(1,(0,t.Inject)(r.RegisterOtherFormulaService)),f(2,(0,t.Inject)(m)),f(3,(0,t.Inject)(n.DataValidationModel)),f(4,(0,t.Inject)(n.DataValidatorRegistryService)),f(5,(0,t.Inject)(C))],w);var re=class e{constructor(e,n,r,i,a=!1){this._unitId=n,this._subUnitId=r,this._univerInstanceService=i,this._disableTree=a,d(this,`_map`,void 0),d(this,`_tree`,new t.RBush),d(this,`_dirty`,!0),d(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}),d(this,`_debonceBuildTree`,(0,t.debounce)(this._buildTree,0)),this._map=e,this._buildTree()}get _worksheet(){var e;return(e=this._univerInstanceService.getUnit(this._unitId,t.UniverInstanceType.UNIVER_SHEET))==null?void 0:e.getSheetBySheetId(this._subUnitId)}_addRule(e,n){if(!this._worksheet)return;let r=t.Rectangle.mergeRanges(n.map(e=>t.Range.transformRange(e,this._worksheet)));this._map.forEach((e,n)=>{let i=t.Rectangle.subtractMulti(e,r);i.length===0?this._map.delete(n):this._map.set(n,i)}),this._dirty=!0,this._map.set(e,r),this._debonceBuildTree()}addRule(e){this._addRule(e.uid,e.ranges)}removeRange(e){if(!this._worksheet)return;let n=e.map(e=>t.Range.transformRange(e,this._worksheet));this._map.forEach((e,r)=>{let i=t.Rectangle.subtractMulti(e,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(e){e.forEach(({id:e,ranges:n})=>{if(!n.length)return;let r=this._map.get(e);r?(this._map.set(e,t.Rectangle.mergeRanges([...r,...n])),r=this._map.get(e)):(r=n,this._map.set(e,r)),this._map.forEach((r,i)=>{if(i===e)return;let a=t.Rectangle.subtractMulti(r,n);a.length===0?this._map.delete(i):this._map.set(i,a)})}),this._dirty=!0,this._debonceBuildTree()}diff(e){let n=[],r=0;return e.forEach((e,i)=>{var a;let o=(a=this._map.get(e.uid))==null?[]:a,s=e.ranges;o.length!==0&&(o.length!==s.length||o.some((e,n)=>!t.Rectangle.equals(e,s[n])))&&n.push({type:`update`,ruleId:e.uid,oldRanges:s,newRanges:t.Rectangle.sort(o),rule:e}),o.length===0&&(n.push({type:`delete`,rule:e,index:i-r}),r++)}),n}diffWithAddition(e,n){let r=[],i=0;return e.forEach((e,n)=>{var a;let o=(a=this._map.get(e.uid))==null?[]:a,s=e.ranges;o.length!==0&&(o.length!==s.length||o.some((e,n)=>!t.Rectangle.equals(e,s[n])))&&r.push({type:`update`,ruleId:e.uid,oldRanges:s,newRanges:t.Rectangle.sort(o),rule:e}),o.length===0&&(r.push({type:`delete`,rule:e,index:n-i}),i++)}),Array.from(n).forEach(e=>{var n;let i=(n=this._map.get(e.uid))==null?[]:n;r.push({type:`add`,rule:{...e,ranges:t.Rectangle.sort(i)}})}),r}clone(){return new e(new Map(t.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 T=class extends t.Disposable{constructor(e,t,n,r,i,o,s){super(),this._dataValidationModel=e,this._univerInstanceService=t,this._dataValidatorRegistryService=n,this._dataValidationCacheService=r,this._dataValidationFormulaService=i,this._dataValidationCustomFormulaService=o,this._commandService=s,d(this,`_ruleMatrixMap`,new Map),d(this,`_validStatusChange$`,new a.Subject),d(this,`_ruleChange$`,new a.Subject),d(this,`ruleChange$`,this._ruleChange$.asObservable()),d(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===i.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 re(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,t,r,i,a){let o=this._ensureRuleMatrix(e,t),s={...i,...a.payload};a.type===n.UpdateRuleType.RANGE?o.updateRange(r,a.payload):a.type===n.UpdateRuleType.ALL&&o.updateRange(r,a.payload.ranges),this._dataValidationCacheService.removeRule(e,t,i),this._dataValidationCacheService.addRule(e,t,s),this._dataValidationFormulaService.removeRule(e,t,i.uid),this._dataValidationFormulaService.addRule(e,t,s),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,r),this._dataValidationCustomFormulaService.addRule(e,t,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(e,n,r){let{col:i,row:a,unitId:o,subUnitId:s,worksheet:c}=n,l=(t,n)=>{r&&r(t,n),n&&this._validStatusChange$.next({unitId:o,subUnitId:s,ruleId:e.uid,status:t,row:a,col:i})},u=c.getCellValueOnly(a,i),d=this.getValidator(e.type),f=c.getCellRaw(a,i),p=b(f);if(d){let r=this._dataValidationCacheService.ensureCache(o,s),c=r.getValue(a,i);return c==null?(r.setValue(a,i,t.DataValidationStatus.VALIDATING),d.validator({value:p,unitId:o,subUnitId:s,row:a,column:i,worksheet:n.worksheet,workbook:n.workbook,interceptValue:b(u),t:f==null?void 0:f.t},e).then(e=>{let n=e?t.DataValidationStatus.VALID:t.DataValidationStatus.INVALID,o=r.getValue(a,i);n===t.DataValidationStatus.VALID?r.realDeleteValue(a,i):r.setValue(a,i,n),l(n,c!==o)}),t.DataValidationStatus.VALIDATING):(l(c==null?t.DataValidationStatus.VALID:c,!1),c==null?t.DataValidationStatus.VALID:c)}else return l(t.DataValidationStatus.VALID,!1),t.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()}};T=p([f(0,(0,t.Inject)(n.DataValidationModel)),f(1,t.IUniverInstanceService),f(2,(0,t.Inject)(n.DataValidatorRegistryService)),f(3,(0,t.Inject)(m)),f(4,(0,t.Inject)(w)),f(5,(0,t.Inject)(y)),f(6,t.ICommandService)],T);function ie(e,n){return t.Tools.isBlank(e)?n.t(`dataValidation.validFail.value`):(0,t.isFormulaString)(e)?n.t(`dataValidation.validFail.primitive`):``}let E=e=>t.Tools.isDefine(e)&&String(e).toLowerCase()===`true`?`1`:String(e).toLowerCase()===`false`?`0`:e;var D=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.CHECKBOX),d(this,`title`,`dataValidation.checkbox.title`),d(this,`operators`,[]),d(this,`scopes`,[`sheet`]),d(this,`order`,41),d(this,`offsetFormulaByRange`,!1),d(this,`_formulaService`,this.injector.get(w)),d(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(e,n,r){let{formula1:i,formula2:a}=e,o=i===a;if(t.Tools.isBlank(i)&&t.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=ie(i,this.localeService),c=ie(a,this.localeService);return{success:!s&&!c,formula1:s,formula2:c}}async parseFormula(e,n,r){var i,a;let{formula1:o=1,formula2:s=0}=e,c=await this._formulaService.getRuleFormulaResult(n,r,e.uid),l=(0,t.isFormulaString)(o)?h(c==null||(i=c[0])==null||(i=i.result)==null?void 0:i[0][0]):o,u=(0,t.isFormulaString)(s)?h(c==null||(a=c[1])==null||(a=a.result)==null?void 0:a[0][0]):s,d=_(String(l))&&_(String(u));return{formula1:E(l),formula2:E(u),originFormula1:l,originFormula2:u,isFormulaValid:d}}getExtraStyle(e,n){return{tb:t.WrapStrategy.CLIP}}parseFormulaSync(e,n,r){var i,a;let{formula1:o=1,formula2:s=0}=e,c=this._formulaService.getRuleFormulaResultSync(n,r,e.uid),l=(0,t.isFormulaString)(o)?h(c==null||(i=c[0])==null||(i=i.result)==null?void 0:i[0][0]):o,u=(0,t.isFormulaString)(s)?h(c==null||(a=c[1])==null||(a=a.result)==null?void 0:a[0][0]):s,d=_(String(l))&&_(String(u));return{formula1:E(l),formula2:E(u),originFormula1:l,originFormula2:u,isFormulaValid:d}}async isValidType(e,n,r){let{value:i,unitId:a,subUnitId:o}=e,{formula1:s,formula2:c,originFormula1:l,originFormula2:u}=await this.parseFormula(r,a,o);return!t.Tools.isDefine(s)||!t.Tools.isDefine(c)?!0:t.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}};let ae={[t.DataValidationOperator.BETWEEN]:`dataValidation.date.operators.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.date.operators.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.date.operators.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.operators.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.date.operators.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.operators.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.operators.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.operators.notEqual`};t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL;let O={[t.DataValidationOperator.BETWEEN]:`dataValidation.date.ruleName.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.date.ruleName.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.date.ruleName.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.ruleName.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.date.ruleName.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.ruleName.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.ruleName.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.ruleName.notEqual`,NONE:`dataValidation.date.ruleName.legal`},oe={[t.DataValidationOperator.BETWEEN]:`dataValidation.date.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.date.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.date.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.date.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.errorMsg.notEqual`,NONE:`dataValidation.date.errorMsg.legal`},k=[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.NOT_BETWEEN],A=`{FORMULA1}`,j=`{FORMULA2}`,M=e=>{var n,r;if(e==null||typeof e==`boolean`)return;if(typeof e==`number`||!Number.isNaN(+e))return+e;let i=(n=t.numfmt.parseDate(e))==null?void 0:n.v;return t.Tools.isDefine(i)?i:(r=t.numfmt.parseDate((0,t.dateKit)(e).format(`YYYY-MM-DD HH:mm:ss`)))==null?void 0:r.v};var N=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.DATE),d(this,`title`,`dataValidation.date.title`),d(this,`order`,40),d(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),d(this,`scopes`,[`sheet`]),d(this,`_customFormulaService`,this.injector.get(y)),d(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder))}async parseFormula(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=_(String(o==null?void 0:o.v))&&_(String(s==null?void 0:s.v));return{formula1:M((0,t.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:M((0,t.isFormulaString)(l)?s==null?void 0:s.v:l),isFormulaValid:u}}async isValidType(e){let{interceptValue:n,value:r}=e;return typeof r==`number`&&typeof n==`string`||typeof n==`string`?!!t.numfmt.parseDate(n):!1}_validatorSingleFormula(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e)||!!(e&&t.numfmt.parseDate(e)))}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(e,n,r){let{formula1:i,formula2:a,bizInfo:o}=e,s=e=>{if(!e)return e;let n;if(!Number.isNaN(+e))n=t.numfmt.dateFromSerial(+e);else{var r;let i=(r=t.numfmt.parseDate(e))==null?void 0:r.v;if(i==null)return``;n=t.numfmt.dateFromSerial(i)}return(0,t.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,t.isFormulaString)(i)?i:s(`${i}`),formula2:(0,t.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(ae[e]))}generateRuleName(e){var t,n;if(!e.operator)return this.localeService.t(O.NONE);let r=this.localeService.t(O[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}=S(this._lexerTreeBuilder,e,t);return`${this.localeService.t(oe[e.operator]).replace(A,n==null?``:n).replace(j,r==null?``:r)}`}};t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL,t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL;let P={[t.DataValidationOperator.BETWEEN]:`dataValidation.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.errorMsg.notEqual`,NONE:`dataValidation.errorMsg.legal`};function F(e){return+e}var se=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`_customFormulaService`,this.injector.get(y)),d(this,`id`,t.DataValidationType.DECIMAL),d(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder)),d(this,`title`,`dataValidation.decimal.title`),d(this,`order`,20),d(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),d(this,`scopes`,[`sheet`])}_isFormulaOrNumber(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e))}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(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=_(String(o==null?void 0:o.v))&&_(String(s==null?void 0:s.v));return{formula1:this._parseNumber((0,t.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:this._parseNumber((0,t.isFormulaString)(l)?s==null?void 0:s.v:l),isFormulaValid:u}}validatorFormula(e,n,r){let i=e.operator;if(!i)return{success:!0};let a=t.Tools.isDefine(e.formula1)&&this._isFormulaOrNumber(e.formula1),o=t.Tools.isDefine(e.formula2)&&this._isFormulaOrNumber(e.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}=S(this._lexerTreeBuilder,e,t);return`${this.localeService.t(P[e.operator]).replace(A,n==null?``:n).replace(j,r==null?``:r)}`}};function ce(e){if(!e)return[];let n=new Set;for(let i=0,a=e.length;i<a;i++){let a=e[i];if(a)for(let e=0,i=a.length;e<i;e++){let i=a[e],o=b(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(t.numfmt.format(i.s.n.pattern,o,{throws:!1}));continue}let e=typeof o==`string`?o:String(o);_(e)&&n.add(e)}}}return[...n]}let le=[`if`,`indirect`,`choose`,`offset`];function ue(e,n){if(!(0,t.isFormulaString)(e)||(0,r.isReferenceString)(e.slice(1)))return!0;let i=n.sequenceNodesBuilder(e);return i&&i.some(e=>typeof e==`object`&&e.nodeType===r.sequenceNodeType.FUNCTION&&le.indexOf(e.token.toLowerCase())>-1)}function de(e,n){let{formula1:i=``,ranges:a}=e;if((0,r.isReferenceString)(i.slice(1))){let e=(0,r.deserializeRangeWithSheet)(i.slice(1));if((!e.sheetName||e.sheetName===n)&&a.some(n=>t.Rectangle.intersects(n,e.range)))return!0}return!1}var I=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`formulaService`,this.injector.get(w)),d(this,`_lexer`,this.injector.get(r.LexerTreeBuilder)),d(this,`_univerInstanceService`,this.injector.get(t.IUniverInstanceService)),d(this,`_listCacheService`,this.injector.get(C)),d(this,`order`,50),d(this,`offsetFormulaByRange`,!1),d(this,`id`,t.DataValidationType.LIST),d(this,`title`,`dataValidation.list.title`),d(this,`operators`,[]),d(this,`scopes`,[`sheet`]),d(this,`skipDefaultFontRender`,e=>e.renderMode!==t.DataValidationRenderMode.TEXT)}validatorFormula(e,n,r){var i,a;let o=!t.Tools.isBlank(e.formula1),s=ue((i=e.formula1)==null?``:i,this._lexer),c=(a=this._univerInstanceService.getUnit(n,t.UniverInstanceType.UNIVER_SHEET))==null||(a=a.getSheetBySheetId(r))==null?void 0:a.getName(),l=de(e,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(e,n,{style:r}){var i;let a=(i=r.tb===t.WrapStrategy.OVERFLOW?t.WrapStrategy.CLIP:r.tb)==null?t.WrapStrategy.WRAP:i;if(e.type===t.DataValidationType.LIST&&(e.renderMode===t.DataValidationRenderMode.ARROW||e.renderMode===t.DataValidationRenderMode.TEXT)){let t=this.getListWithColorMap(e)[`${n==null?``:n}`];if(t)return{bg:{rgb:t},tb:a}}return{tb:a}}parseCellValue(e){return x(e.toString())}async parseFormula(e,t,n){var r;let i=await this.formulaService.getRuleFormulaResult(t,n,e.uid),a=h(i==null||(r=i[0])==null||(r=r.result)==null?void 0:r[0][0]);return{formula1:void 0,formula2:void 0,isFormulaValid:_(String(a))}}async isValidType(e,n,r){let{value:i,unitId:a,subUnitId:o}=e,{formula1:s=``}=r,c=(0,t.isFormulaString)(s)?this._listCacheService.getOrCompute(a,o,r).list:x(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(e,n){var r,i;let a=(r=e?this._univerInstanceService.getUniverSheetInstance(e):void 0)==null?this._univerInstanceService.getCurrentUnitForType(t.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(e,n,r){var i;let{formula1:a=``}=e,o=this._getUnitAndSubUnit(n,r);if(!o)return[];let{unitId:s,subUnitId:c}=o,l=await this.formulaService.getRuleFormulaResult(s,c,e.uid);return(0,t.isFormulaString)(a)?ce(l==null||(i=l[0])==null||(i=i.result)==null?void 0:i[0][0]):x(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}},fe=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.TEXT_LENGTH),d(this,`title`,`dataValidation.textLength.title`),d(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder)),d(this,`order`,30),d(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),d(this,`scopes`,[`sheet`]),d(this,`_customFormulaService`,this.injector.get(y))}_isFormulaOrInt(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}validatorFormula(e,n,r){let i=e.operator;if(!i)return{success:!1};let a=t.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),o=t.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.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(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=_(String(o==null?void 0:o.v))&&_(String(s==null?void 0:s.v));return{formula1:this._parseNumber((0,t.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:this._parseNumber((0,t.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,t){if(!e.operator)return this.titleStr;let{transformedFormula1:r,transformedFormula2:i}=S(this._lexerTreeBuilder,e,t);return`${this.localeService.t(n.TextLengthErrorTitleMap[e.operator]).replace(A,r==null?``:r).replace(j,i==null?``:i)}`}};function L(e){var n,r;return e?e.p?!((n=(r=e.p.body)==null?void 0:r.dataStream)==null?``:n).slice(0,-2).trim():t.Tools.isBlank(e.v):!0}function R(e,a,o,s,c=`command`,l=!0){let u=s.get(r.LexerTreeBuilder),d=s.get(n.DataValidatorRegistryService),f=[],p=[],m=s.get(T),h=(0,i.getSheetCommandTarget)(s.get(t.IUniverInstanceService),{unitId:e,subUnitId:a});if(!h)return{redoMutations:f,undoMutations:p};let{worksheet:g}=h,_=new t.ObjectMatrix,y=!1;function b(e,n){l&&e.forEach(e=>{t.Range.foreach(e,(e,t)=>{let r=g.getCellRaw(e,t),i=ee(r);(L(r)||i===n)&&!(r!=null&&r.p)&&(y=!0,_.setValue(e,t,{v:n,p:null}))})})}if(o.forEach(r=>{switch(r.type){case`delete`:f.push({id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.rule.uid,source:c}}),p.unshift({id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:a,rule:r.rule,index:r.index,source:c}});break;case`update`:{if(v(r.rule.type,d)){let i=r.oldRanges[0].startRow,o=r.oldRanges[0].startColumn,s=r.newRanges[0].startRow,l=r.newRanges[0].startColumn,d=s-i,m=l-o,h=(0,t.isFormulaString)(r.rule.formula1)?u.moveFormulaRefOffset(r.rule.formula1,m,d):r.rule.formula1,g=(0,t.isFormulaString)(r.rule.formula2)?u.moveFormulaRefOffset(r.rule.formula2,m,d):r.rule.formula2;h!==r.rule.formula1||g!==r.rule.formula2||!(0,t.isRangesEqual)(r.newRanges,r.oldRanges)?(f.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.ALL,payload:{formula1:h,formula2:g,ranges:r.newRanges}}}}),p.unshift({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.ALL,payload:{formula1:r.rule.formula1,formula2:r.rule.formula2,ranges:r.oldRanges}}}})):(f.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.newRanges},source:c}}),p.unshift({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.oldRanges},source:c}}))}else f.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.newRanges},source:c}}),p.unshift({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.oldRanges},source:c}});let i=m.getRuleById(e,a,r.ruleId);if(i&&i.type===t.DataValidationType.CHECKBOX){let n=m.getValidator(t.DataValidationType.CHECKBOX).parseFormulaSync(i,e,a);b(r.newRanges,n.formula2)}break}case`add`:if(f.push({id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:a,rule:r.rule,source:c}}),p.unshift({id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.rule.uid,source:c}}),r.rule.type===t.DataValidationType.CHECKBOX){let n=m.getValidator(t.DataValidationType.CHECKBOX).parseFormulaSync(r.rule,e,a);b(r.rule.ranges,n.originFormula2)}break;default:break}}),y){let t={id:i.SetRangeValuesMutation.id,params:{unitId:e,subUnitId:a,cellValue:_.getData()}},n={id:i.SetRangeValuesMutation.id,params:(0,i.SetRangeValuesUndoMutationFactory)(s,t.params)};f.push(t),p.push(n)}return{redoMutations:f,undoMutations:p}}let z={type:t.CommandType.COMMAND,id:`sheet.command.updateDataValidationRuleRange`,handler(e,n){if(!n)return!1;let{unitId:r,subUnitId:i,ranges:a,ruleId:o}=n,s=e.get(T),c=e.get(t.ICommandService),l=e.get(t.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)),e);return l.pushUndoRedo({undoMutations:f,redoMutations:d,unitID:r}),(0,t.sequenceExecute)(d,c),!0}},B={type:t.CommandType.COMMAND,id:`sheet.command.addDataValidation`,handler(e,r){if(!r)return!1;let{unitId:i,subUnitId:a,rule:o}=r,s=e.get(T),c=e.get(t.ICommandService),l=e.get(t.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,e);return m.push({id:n.AddDataValidationMutation.id,params:p}),h.unshift({id:n.RemoveDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:o.uid}}),l.pushUndoRedo({unitID:i,redoMutations:m,undoMutations:h}),(0,t.sequenceExecute)(m,c),!0}},V={type:t.CommandType.COMMAND,id:`sheets.command.update-data-validation-setting`,handler(e,r){if(!r)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(T),c=e.get(n.DataValidatorRegistryService),{unitId:l,subUnitId:u,ruleId:d,setting:f}=r,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:n.UpdateRuleType.SETTING,payload:{...f,...p.normalizeFormula(h,l,u)}}},_=[{id:n.UpdateDataValidationMutation.id,params:g}],v={unitId:l,subUnitId:u,ruleId:d,payload:{type:n.UpdateRuleType.SETTING,payload:(0,n.getRuleSetting)(m)}},y=[{id:n.UpdateDataValidationMutation.id,params:v}];if(f.type===t.DataValidationType.CHECKBOX){let n=m.ranges,r=(0,i.getSheetCommandTarget)(e.get(t.IUniverInstanceService),{unitId:l,subUnitId:u});if(r){let a=new t.ObjectMatrix,{worksheet:o}=r,{formula2:s=0,formula1:c=1}=m,{formula2:d=0,formula1:p=1}=f,h=!1;if(n.forEach(e=>{t.Range.foreach(e,(e,t)=>{let n=o.getCellRaw(e,t),r=ee(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 t={id:i.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:u,cellValue:a.getData()}},n={id:i.SetRangeValuesMutation.id,params:(0,i.SetRangeValuesUndoMutationFactory)(e,t.params)};_.push(t),y.push(n)}}}return(0,t.sequenceExecute)(_,a).result?(o.pushUndoRedo({unitID:l,redoMutations:_,undoMutations:y}),!0):!1}},H={type:t.CommandType.COMMAND,id:`sheets.command.update-data-validation-options`,handler(e,r){if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(T),{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:n.UpdateRuleType.OPTIONS,payload:u}},p=[{id:n.UpdateDataValidationMutation.id,params:f}],m={unitId:s,subUnitId:c,ruleId:l,payload:{type:n.UpdateRuleType.OPTIONS,payload:(0,n.getRuleOptions)(d)}},h=[{id:n.UpdateDataValidationMutation.id,params:m}];return a.pushUndoRedo({unitID:s,redoMutations:p,undoMutations:h}),i.executeCommand(n.UpdateDataValidationMutation.id,f),!0}},U={type:t.CommandType.COMMAND,id:`sheets.command.clear-range-data-validation`,handler(e,n){if(!n)return!1;let{unitId:r,subUnitId:a,ranges:o}=n,s=e.get(t.ICommandService),c=(0,i.getSheetCommandTarget)(e.get(t.IUniverInstanceService),{unitId:r,subUnitId:a}),l=e.get(T);if(!c)return!1;let u=e.get(t.IUndoRedoService),d=l.getRuleObjectMatrix(r,a).clone();d.removeRange(o);let{redoMutations:f,undoMutations:p}=R(r,a,d.diff(l.getRules(r,a)),e);return u.pushUndoRedo({unitID:r,redoMutations:f,undoMutations:p}),(0,t.sequenceExecute)(f,s).result}},W={type:t.CommandType.COMMAND,id:`sheet.command.remove-all-data-validation`,handler(e,r){if(!r)return!1;let{unitId:i,subUnitId:a}=r,o=e.get(t.ICommandService),s=e.get(T),c=e.get(t.IUndoRedoService),l=[...s.getRules(i,a)],u={unitId:i,subUnitId:a,ruleId:l.map(e=>e.uid)},d=[{id:n.RemoveDataValidationMutation.id,params:u}],f=[{id:n.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:l}}];return c.pushUndoRedo({redoMutations:d,undoMutations:f,unitID:i}),o.executeCommand(n.RemoveDataValidationMutation.id,u),!0}},pe=(e,t)=>{let r=e.get(T),{unitId:i,subUnitId:a,ruleId:o,source:s}=t;if(Array.isArray(o)){let e=o.map(e=>r.getRuleById(i,a,e)).filter(Boolean);return[{id:n.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:e,source:s}}]}return[{id:n.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:{...r.getRuleById(i,a,o)},index:r.getRuleIndex(i,a,o)}}]},me={type:t.CommandType.COMMAND,id:`sheet.command.remove-data-validation-rule`,handler(e,r){if(!r)return!1;let{unitId:i,subUnitId:a,ruleId:o}=r,s=e.get(t.ICommandService),c=e.get(t.IUndoRedoService),l=e.get(T),u=[{id:n.RemoveDataValidationMutation.id,params:r}],d=[{id:n.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(n.RemoveDataValidationMutation.id,r),!0}},G=`SHEET_DATA_VALIDATION_PLUGIN`,K=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._permissionService=t,this._lexerTreeBuilder=n}getFormulaRefCheck(e){let n=this._lexerTreeBuilder.sequenceNodesBuilder(e);if(!n)return!0;for(let e=0;e<n.length;e++){let s=n[e];if(typeof s==`string`)continue;let{token:c}=s,l=(0,r.deserializeRangeWithSheetWithCache)(c),u=this._univerInstanceService.getCurrentUnitForType(t.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 i.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 a;let n=(a=d.getCell(e,t))==null||(a=a.selectionProtection)==null?void 0:a[0];if((n==null?void 0:n[o.UnitAction.View])===!1)return!1}}return!0}};K=p([f(0,t.IUniverInstanceService),f(1,t.IPermissionService),f(2,(0,t.Inject)(r.LexerTreeBuilder))],K);var he=`@univerjs/sheets-data-validation`,ge=`0.23.0-insiders.20260522-ee0b0a4`;let q=`sheets-data-validation.config`;Symbol(q);let _e={},J=class extends t.Disposable{constructor(e,t,n){super(),this._dataValidationModel=e,this._formulaRefRangeService=t,this._validatorRegistryService=n,d(this,`_disposableMap`,new Map),d(this,`registerRule`,(e,t,n)=>{v(n.type,this._validatorRegistryService)&&this.register(e,t,n)}),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}_${t}_${n}`}register(e,r,i){let a=i.ranges,o=i.formula1,s=i.formula2,c=this._formulaRefRangeService.registerRangeFormula(e,r,a,[o==null?``:o,s==null?``:s],c=>{if(c.length===0)return{undos:[{id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:r,rule:i,source:`patched`}}],redos:[{id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:i.uid,source:`patched`}}]};let l=[],u=[],d=c[0];l.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:i.uid,payload:{type:n.UpdateRuleType.ALL,payload:{ranges:d.ranges,formula1:d.formulas[0],formula2:d.formulas[1]}},source:`patched`}}),u.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:i.uid,payload:{type:n.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,t.generateRandomId)();l.push({id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:r,rule:{...i,uid:s,formula1:o.formulas[0],formula2:o.formulas[1],ranges:o.ranges},source:`patched`}}),u.push({id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:s,source:`patched`}})}return{undos:u,redos:l}}),l=this._getIdWithUnitId(e,r,i.uid);this._disposableMap.set(l,c)}_initRefRange(){let e=this._dataValidationModel.getAll();for(let[t,n]of e)for(let[e,r]of n)for(let n of r)this.registerRule(t,e,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,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};J=p([f(0,(0,t.Inject)(T)),f(1,(0,t.Inject)(s.FormulaRefRangeService)),f(2,(0,t.Inject)(n.DataValidatorRegistryService))],J);let Y=class extends t.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,d(this,`_disposableMap`,new Map),d(this,`registerRule`,(e,t,n)=>{v(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,t,r){var i;let a=r.uid,o=this._getIdWithUnitId(e,t,a),s=(i=this._disposableMap.get(o))==null?new Set:i,c=(i,o)=>{let s=this._dataValidationModel.getRuleById(e,t,a);if(!s)return{redos:[],undos:[]};let c=s[i];if(!c||c===o)return{redos:[],undos:[]};let l={unitId:e,subUnitId:t,ruleId:r.uid,payload:{type:n.UpdateRuleType.SETTING,payload:{type:s.type,formula1:s.formula1,formula2:s.formula2,[i]:o}},source:`patched`},u={unitId:e,subUnitId:t,ruleId:r.uid,payload:{type:n.UpdateRuleType.SETTING,payload:{type:s.type,formula1:s.formula1,formula2:s.formula2}},source:`patched`};return{redos:[{id:n.UpdateDataValidationMutation.id,params:l}],undos:[{id:n.UpdateDataValidationMutation.id,params:u}]}},l=this._dataValidationFormulaService.getRuleFormulaInfo(e,t,a);if(l){let[n,r]=l;if(n){let r=this._formulaRefRangeService.registerFormula(e,t,n.text,e=>c(`formula1`,e));s.add(()=>r.dispose())}if(r){let n=this._formulaRefRangeService.registerFormula(e,t,r.text,e=>c(`formula2`,e));s.add(()=>n.dispose())}}}register(e,r,a){var o;let s=o=>{let s=[...a.ranges],c=s.map(e=>(0,i.handleCommonDefaultRangeChangeWithEffectRefCommands)(e,o)).filter(e=>!!e).flat();if((0,t.isRangesEqual)(c,s))return{redos:[],undos:[]};if(c.length){let t={unitId:e,subUnitId:r,ruleId:a.uid,payload:{type:n.UpdateRuleType.RANGE,payload:c},source:`patched`};return{redos:[{id:n.UpdateDataValidationMutation.id,params:t}],undos:[{id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:a.uid,payload:{type:n.UpdateRuleType.RANGE,payload:s},source:`patched`}}]}}else{let t={unitId:e,subUnitId:r,ruleId:a.uid};return{redos:[{id:n.RemoveDataValidationMutation.id,params:t}],undos:pe(this._injector,t)}}},c=[];a.ranges.forEach(t=>{let n=this._refRangeService.registerRefRange(t,s,e,r);c.push(()=>n.dispose())});let l=this._getIdWithUnitId(e,r,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 e=this._dataValidationModel.getAll();for(let[t,n]of e)for(let[e,r]of n)for(let n of r)this.registerRule(t,e,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,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.forEach(e=>e())}),this._disposableMap.clear()}))}};Y=p([f(0,(0,t.Inject)(T)),f(1,(0,t.Inject)(t.Injector)),f(2,(0,t.Inject)(i.RefRangeService)),f(3,(0,t.Inject)(w)),f(4,(0,t.Inject)(s.FormulaRefRangeService)),f(5,(0,t.Inject)(n.DataValidatorRegistryService))],Y);let X=class extends t.Disposable{constructor(e,t,n){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._sheetDataValidationModel=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===i.RemoveSheetCommand.id){var r;let i=e.params,a=i.unitId||this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=this._univerInstanceService.getUniverSheetInstance(a);if(!o)return{redos:[],undos:[]};let s=i.subUnitId||((r=o.getActiveSheet())==null?void 0:r.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:n.RemoveDataValidationMutation.id,params:l}],undos:[{id:n.AddDataValidationMutation.id,params:u}]}}else if(e.id===i.CopySheetCommand.id){let{unitId:r,subUnitId:i,targetSubUnitId:a}=e.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(e=>({...e,uid:(0,t.generateRandomId)(6)}));return{redos:[{id:n.AddDataValidationMutation.id,params:{unitId:r,subUnitId:a,rule:s,source:`patched`}}],undos:[{id:n.RemoveDataValidationMutation.id,params:{unitId:r,subUnitId:a,ruleId:s.map(e=>e.uid),source:`patched`}}]}}return{redos:[],undos:[]}}}))}};X=p([f(0,(0,t.Inject)(i.SheetInterceptorService)),f(1,(0,t.Inject)(t.IUniverInstanceService)),f(2,(0,t.Inject)(T))],X);var ve=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.ANY),d(this,`title`,`dataValidation.any.title`),d(this,`operators`,[]),d(this,`scopes`,[`sheet`]),d(this,`order`,0),d(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`)}},ye=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.CUSTOM),d(this,`title`,`dataValidation.custom.title`),d(this,`operators`,[]),d(this,`scopes`,[`sheet`]),d(this,`order`,60),d(this,`_customFormulaService`,this.injector.get(y)),d(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder))}validatorFormula(e,n,i){var a;let o=(0,t.isFormulaString)(e.formula1),s=(a=e.formula1)==null?``:a,c=this._lexerTreeBuilder.checkIfAddBracket(s)===0&&s.startsWith(r.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(e,n,r){let{column:i,row:a,unitId:o,subUnitId:s}=e,c=await this._customFormulaService.getCellFormulaValue(o,s,r.uid,a,i),l=c==null?void 0:c.v;return _(String(l))&&t.Tools.isDefine(l)&&l!==``?c.t===t.CellValueType.BOOLEAN?!!l:typeof l==`boolean`?l:typeof l==`number`?!!l:typeof l==`string`?_(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)}},be=class extends I{constructor(...e){super(...e),d(this,`id`,t.DataValidationType.LIST_MULTIPLE),d(this,`title`,`dataValidation.listMultiple.title`),d(this,`offsetFormulaByRange`,!1),d(this,`skipDefaultFontRender`,()=>!0)}},xe=class extends n.BaseDataValidator{constructor(...e){super(...e),d(this,`_customFormulaService`,this.injector.get(y)),d(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder)),d(this,`id`,t.DataValidationType.WHOLE),d(this,`title`,`dataValidation.whole.title`),d(this,`order`,10),d(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),d(this,`scopes`,[`sheet`])}_isFormulaOrInt(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}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(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=(0,t.isFormulaString)(c)?o==null?void 0:o.v:c,d=(0,t.isFormulaString)(l)?s==null?void 0:s.v:l,f=_(`${u}`)&&_(`${d}`);return{formula1:this._parseNumber(u),formula2:this._parseNumber(d),isFormulaValid:f}}validatorFormula(e,n,r){let i=e.operator;if(!i)return{success:!0};let a=t.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),o=t.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.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}=S(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 t.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(){[ve,se,xe,fe,N,D,I,be,ye].forEach(e=>{let n=this._injector.createInstance(e);this.disposeWithMe(this._dataValidatorRegistryService.register(n)),this.disposeWithMe((0,t.toDisposable)(()=>this._injector.delete(e)))})}_initCommandInterceptor(){this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===i.ClearSelectionAllCommand.id){var n;let e=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),r=e.getUnitId(),i=e.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=p([f(0,t.IUniverInstanceService),f(1,(0,t.Inject)(n.DataValidatorRegistryService)),f(2,(0,t.Inject)(t.Injector)),f(3,(0,t.Inject)(i.SheetsSelectionsService)),f(4,(0,t.Inject)(i.SheetInterceptorService)),f(5,(0,t.Inject)(T))],Z);let Q=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetDataValidationModel=t,this._dataValidationCacheService=n,this._lifecycleService=r,this._initRecalculate()}_initRecalculate(){let e=e=>{if(e.length===0)return;let n=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getActiveSheet(),i={};e.flat().forEach(e=>{i[e.unitId]||(i[e.unitId]={}),i[e.unitId][e.subUnitId]||(i[e.unitId][e.subUnitId]=[]);let n=this._univerInstanceService.getUnit(e.unitId,t.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getSheetBySheetId(e.subUnitId);r&&i[e.unitId][e.subUnitId].push(...e.ranges.map(e=>t.Range.transformRange(e,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,a.bufferWhen)(()=>this._lifecycleService.lifecycle$.pipe((0,a.skip)(1),(0,a.filter)(e=>e===t.LifecycleStages.Rendered)))).subscribe(e)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe((0,a.filter)(()=>this._lifecycleService.stage>=t.LifecycleStages.Rendered),(0,t.bufferDebounceTime)(20)).subscribe(e))}async _validatorByCell(e,n,r,i){let a=e.getUnitId(),o=n.getSheetId();if(!t.Tools.isDefine(r)||!t.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(t=>{this._sheetDataValidationModel.validator(u,{unitId:a,subUnitId:o,row:s,col:c,worksheet:n,workbook:e},e=>{t(e)})}):t.DataValidationStatus.VALID}async validatorCell(e,n,r,i){let a=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!a)throw Error(`cannot find current workbook, unitId: ${e}`);let o=a.getSheetBySheetId(n);if(!o)throw Error(`cannot find current worksheet, sheetId: ${n}`);return this._validatorByCell(a,o,r,i)}async validatorRanges(e,n,r){if(!r.length)return Promise.resolve([]);let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)throw Error(`cannot find current workbook, unitId: ${e}`);let a=i.getSheetBySheetId(n);if(!a)throw Error(`cannot find current worksheet, sheetId: ${n}`);let o=this._sheetDataValidationModel.getRules(e,n),s=[];for(let e of o)s.push(...e.ranges);let c=[];for(let e of r)for(let n of s){let r=(0,t.getIntersectRange)(e,n);r&&c.push(r)}let l=[],u=await Promise.all(c.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&&l.push({resultRowIndex:t,resultColIndex:n.length-1,row:e.startRow,col:e.startColumn})}return Promise.all(n)}));return l.length&&l.forEach(({resultRowIndex:r,resultColIndex:i,row:a,col:o})=>{if(u[r][i]===t.DataValidationStatus.VALIDATING){var s;u[r][i]=(s=this._dataValidationCacheService.getValue(e,n,a,o))==null?t.DataValidationStatus.VALID:s}}),u}async validatorWorksheet(e,n){let r=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!r)throw Error(`cannot find current workbook, unitId: ${e}`);let i=r.getSheetBySheetId(n);if(!i)throw Error(`cannot find current worksheet, sheetId: ${n}`);let a=this._sheetDataValidationModel.getRules(e,n);return await Promise.all(a.map(e=>Promise.all(e.ranges.map(e=>{let n=[];return t.Range.foreach(e,(e,t)=>{n.push(this._validatorByCell(r,i,e,t))}),Promise.all(n)})))),this._dataValidationCacheService.ensureCache(e,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(e,n,r){let i=this._sheetDataValidationModel.getRuleObjectMatrix(e,n),a=new Set;r.forEach(e=>{t.Range.foreach(e,(e,t)=>{let n=i.getValue(e,t);n&&a.add(n)})});let o=[];for(let t of a){let r=this._sheetDataValidationModel.getRuleById(e,n,t);r&&o.push(r)}return o}getDataValidation(e,t,n){return this.getDataValidations(e,t,n)[0]}};Q=p([f(0,t.IUniverInstanceService),f(1,(0,t.Inject)(T)),f(2,(0,t.Inject)(m)),f(3,(0,t.Inject)(t.LifecycleService))],Q);let $=class extends t.Plugin{constructor(e=_e,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},_e,this._config);this._configService.setConfig(q,a)}onStarting(){[[m],[C],[w],[y],[Q],[T],[Z],[K],[X],[Y],[J]].forEach(e=>{this._injector.add(e)}),[B,z,V,H,me,W,U].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(m),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(K)}};d($,`pluginName`,G),d($,`packageName`,he),d($,`version`,ge),d($,`type`,t.UniverInstanceType.UNIVER_SHEET),$=p([(0,t.DependentOn)(s.UniverSheetsFormulaPlugin,n.UniverDataValidationPlugin),f(1,(0,t.Inject)(t.Injector)),f(2,t.ICommandService),f(3,t.IConfigService)],$);function Se(e){let n=e.get(i.SheetsSelectionsService).getCurrentSelections().map(e=>e.range);return{uid:(0,t.generateRandomId)(6),type:t.DataValidationType.DECIMAL,operator:t.DataValidationOperator.EQUAL,formula1:`100`,ranges:n==null?[{startColumn:0,endColumn:0,startRow:0,endRow:0}]:n}}e.AddSheetDataValidationCommand=B,e.BASE_FORMULA_INPUT_NAME=`data-validation.formula-input`,e.CHECKBOX_FORMULA_1=1,e.CHECKBOX_FORMULA_2=0,e.CHECKBOX_FORMULA_INPUT_NAME=`data-validation.checkbox-formula-input`,e.CUSTOM_FORMULA_INPUT_NAME=`data-validation.custom-formula-input`,e.CheckboxValidator=D,e.ClearRangeDataValidationCommand=U,e.DATA_VALIDATION_PLUGIN_NAME=G,Object.defineProperty(e,`DataValidationCacheService`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(e,`DataValidationCustomFormulaService`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(e,`DataValidationFormulaController`,{enumerable:!0,get:function(){return K}}),Object.defineProperty(e,`DataValidationFormulaService`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(e,`DataValidationListCacheService`,{enumerable:!0,get:function(){return C}}),e.DateValidator=N,e.LIST_FORMULA_INPUT_NAME=`data-validation.list-formula-input`,e.ListMultipleValidator=be,e.ListValidator=I,e.RemoveSheetAllDataValidationCommand=W,e.RemoveSheetDataValidationCommand=me,Object.defineProperty(e,`SheetDataValidationModel`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(e,`SheetsDataValidationValidatorService`,{enumerable:!0,get:function(){return Q}}),Object.defineProperty(e,`UniverSheetsDataValidationPlugin`,{enumerable:!0,get:function(){return $}}),e.UpdateSheetDataValidationOptionsCommand=H,e.UpdateSheetDataValidationRangeCommand=z,e.UpdateSheetDataValidationSettingCommand=V,e.createDefaultNewRule=Se,e.deserializeListOptions=x,e.getCellValueNumber=F,e.getCellValueOrigin=b,e.getDataValidationCellValue=ne,e.getDataValidationDiffMutations=R,e.getFormulaCellData=g,e.getFormulaResult=h,e.getTransformedFormula=S,e.isLegalFormulaResult=_,e.serializeListOptions=te,e.transformCheckboxValue=E});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-data-validation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0-insiders.20260522-ee0b0a4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Sheet-specific data validation commands, services, and Facade APIs for Univer Sheets.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -62,18 +62,18 @@
|
|
|
62
62
|
"rxjs": ">=7.0.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@univerjs/core": "0.
|
|
66
|
-
"@univerjs/data-validation": "0.
|
|
67
|
-
"@univerjs/
|
|
68
|
-
"@univerjs/
|
|
69
|
-
"@univerjs/sheets-formula": "0.
|
|
70
|
-
"@univerjs/
|
|
65
|
+
"@univerjs/core": "0.23.0-insiders.20260522-ee0b0a4",
|
|
66
|
+
"@univerjs/data-validation": "0.23.0-insiders.20260522-ee0b0a4",
|
|
67
|
+
"@univerjs/protocol": "0.23.0-insiders.20260522-ee0b0a4",
|
|
68
|
+
"@univerjs/engine-formula": "0.23.0-insiders.20260522-ee0b0a4",
|
|
69
|
+
"@univerjs/sheets-formula": "0.23.0-insiders.20260522-ee0b0a4",
|
|
70
|
+
"@univerjs/sheets": "0.23.0-insiders.20260522-ee0b0a4"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"rxjs": "^7.8.2",
|
|
74
74
|
"typescript": "^6.0.3",
|
|
75
75
|
"vitest": "^4.1.5",
|
|
76
|
-
"@univerjs-infra/shared": "0.
|
|
76
|
+
"@univerjs-infra/shared": "0.23.0"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"dev": "vite",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
File without changes
|