@univerjs/data-validation 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +13 -13
- package/lib/es/index.js +9 -9
- package/lib/index.js +9 -9
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/cjs/index.js
CHANGED
|
@@ -54,7 +54,7 @@ let UpdateRuleType = /* @__PURE__ */ function(UpdateRuleType) {
|
|
|
54
54
|
}({});
|
|
55
55
|
|
|
56
56
|
//#endregion
|
|
57
|
-
//#region \0@oxc-project+runtime@0.
|
|
57
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
58
58
|
function _typeof(o) {
|
|
59
59
|
"@babel/helpers - typeof";
|
|
60
60
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -65,7 +65,7 @@ function _typeof(o) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
//#endregion
|
|
68
|
-
//#region \0@oxc-project+runtime@0.
|
|
68
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
69
69
|
function toPrimitive(t, r) {
|
|
70
70
|
if ("object" != _typeof(t) || !t) return t;
|
|
71
71
|
var e = t[Symbol.toPrimitive];
|
|
@@ -78,14 +78,14 @@ function toPrimitive(t, r) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
//#endregion
|
|
81
|
-
//#region \0@oxc-project+runtime@0.
|
|
81
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
82
82
|
function toPropertyKey(t) {
|
|
83
83
|
var i = toPrimitive(t, "string");
|
|
84
84
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
//#endregion
|
|
88
|
-
//#region \0@oxc-project+runtime@0.
|
|
88
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
89
89
|
function _defineProperty(e, r, t) {
|
|
90
90
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
91
91
|
value: t,
|
|
@@ -96,7 +96,7 @@ function _defineProperty(e, r, t) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
//#endregion
|
|
99
|
-
//#region \0@oxc-project+runtime@0.
|
|
99
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
100
100
|
function __decorateParam(paramIndex, decorator) {
|
|
101
101
|
return function(target, key) {
|
|
102
102
|
decorator(target, key, paramIndex);
|
|
@@ -104,7 +104,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
//#endregion
|
|
107
|
-
//#region \0@oxc-project+runtime@0.
|
|
107
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
108
108
|
function __decorate(decorators, target, key, desc) {
|
|
109
109
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
110
110
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -320,7 +320,7 @@ let DataValidationResourceController = class DataValidationResourceController ex
|
|
|
320
320
|
const resultMap = {};
|
|
321
321
|
if (map) {
|
|
322
322
|
map.forEach(([key, v]) => {
|
|
323
|
-
resultMap[key] = v;
|
|
323
|
+
if (v.length > 0) resultMap[key] = v;
|
|
324
324
|
});
|
|
325
325
|
return JSON.stringify(resultMap);
|
|
326
326
|
}
|
|
@@ -330,7 +330,7 @@ let DataValidationResourceController = class DataValidationResourceController ex
|
|
|
330
330
|
if (!json) return {};
|
|
331
331
|
try {
|
|
332
332
|
return JSON.parse(json);
|
|
333
|
-
} catch
|
|
333
|
+
} catch {
|
|
334
334
|
return {};
|
|
335
335
|
}
|
|
336
336
|
};
|
|
@@ -361,7 +361,7 @@ DataValidationResourceController = __decorate([
|
|
|
361
361
|
//#endregion
|
|
362
362
|
//#region package.json
|
|
363
363
|
var name = "@univerjs/data-validation";
|
|
364
|
-
var version = "1.0
|
|
364
|
+
var version = "1.1.0";
|
|
365
365
|
|
|
366
366
|
//#endregion
|
|
367
367
|
//#region src/config/config.ts
|
|
@@ -689,19 +689,19 @@ BaseDataValidator = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_u
|
|
|
689
689
|
|
|
690
690
|
//#endregion
|
|
691
691
|
exports.AddDataValidationMutation = AddDataValidationMutation;
|
|
692
|
-
Object.defineProperty(exports,
|
|
692
|
+
Object.defineProperty(exports, "BaseDataValidator", {
|
|
693
693
|
enumerable: true,
|
|
694
694
|
get: function () {
|
|
695
695
|
return BaseDataValidator;
|
|
696
696
|
}
|
|
697
697
|
});
|
|
698
|
-
Object.defineProperty(exports,
|
|
698
|
+
Object.defineProperty(exports, "DataValidationModel", {
|
|
699
699
|
enumerable: true,
|
|
700
700
|
get: function () {
|
|
701
701
|
return DataValidationModel;
|
|
702
702
|
}
|
|
703
703
|
});
|
|
704
|
-
Object.defineProperty(exports,
|
|
704
|
+
Object.defineProperty(exports, "DataValidationResourceController", {
|
|
705
705
|
enumerable: true,
|
|
706
706
|
get: function () {
|
|
707
707
|
return DataValidationResourceController;
|
|
@@ -715,7 +715,7 @@ exports.FORMULA2 = FORMULA2;
|
|
|
715
715
|
exports.RemoveDataValidationMutation = RemoveDataValidationMutation;
|
|
716
716
|
exports.TWO_FORMULA_OPERATOR_COUNT = TWO_FORMULA_OPERATOR_COUNT;
|
|
717
717
|
exports.TYPE = TYPE;
|
|
718
|
-
Object.defineProperty(exports,
|
|
718
|
+
Object.defineProperty(exports, "UniverDataValidationPlugin", {
|
|
719
719
|
enumerable: true,
|
|
720
720
|
get: function () {
|
|
721
721
|
return UniverDataValidationPlugin;
|
package/lib/es/index.js
CHANGED
|
@@ -53,7 +53,7 @@ let UpdateRuleType = /* @__PURE__ */ function(UpdateRuleType) {
|
|
|
53
53
|
}({});
|
|
54
54
|
|
|
55
55
|
//#endregion
|
|
56
|
-
//#region \0@oxc-project+runtime@0.
|
|
56
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
57
57
|
function _typeof(o) {
|
|
58
58
|
"@babel/helpers - typeof";
|
|
59
59
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -64,7 +64,7 @@ function _typeof(o) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
//#endregion
|
|
67
|
-
//#region \0@oxc-project+runtime@0.
|
|
67
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
68
68
|
function toPrimitive(t, r) {
|
|
69
69
|
if ("object" != _typeof(t) || !t) return t;
|
|
70
70
|
var e = t[Symbol.toPrimitive];
|
|
@@ -77,14 +77,14 @@ function toPrimitive(t, r) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
//#endregion
|
|
80
|
-
//#region \0@oxc-project+runtime@0.
|
|
80
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
81
81
|
function toPropertyKey(t) {
|
|
82
82
|
var i = toPrimitive(t, "string");
|
|
83
83
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
//#endregion
|
|
87
|
-
//#region \0@oxc-project+runtime@0.
|
|
87
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
88
88
|
function _defineProperty(e, r, t) {
|
|
89
89
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
90
90
|
value: t,
|
|
@@ -95,7 +95,7 @@ function _defineProperty(e, r, t) {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
//#endregion
|
|
98
|
-
//#region \0@oxc-project+runtime@0.
|
|
98
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
99
99
|
function __decorateParam(paramIndex, decorator) {
|
|
100
100
|
return function(target, key) {
|
|
101
101
|
decorator(target, key, paramIndex);
|
|
@@ -103,7 +103,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
//#endregion
|
|
106
|
-
//#region \0@oxc-project+runtime@0.
|
|
106
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
107
107
|
function __decorate(decorators, target, key, desc) {
|
|
108
108
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
109
109
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -319,7 +319,7 @@ let DataValidationResourceController = class DataValidationResourceController ex
|
|
|
319
319
|
const resultMap = {};
|
|
320
320
|
if (map) {
|
|
321
321
|
map.forEach(([key, v]) => {
|
|
322
|
-
resultMap[key] = v;
|
|
322
|
+
if (v.length > 0) resultMap[key] = v;
|
|
323
323
|
});
|
|
324
324
|
return JSON.stringify(resultMap);
|
|
325
325
|
}
|
|
@@ -329,7 +329,7 @@ let DataValidationResourceController = class DataValidationResourceController ex
|
|
|
329
329
|
if (!json) return {};
|
|
330
330
|
try {
|
|
331
331
|
return JSON.parse(json);
|
|
332
|
-
} catch
|
|
332
|
+
} catch {
|
|
333
333
|
return {};
|
|
334
334
|
}
|
|
335
335
|
};
|
|
@@ -360,7 +360,7 @@ DataValidationResourceController = __decorate([
|
|
|
360
360
|
//#endregion
|
|
361
361
|
//#region package.json
|
|
362
362
|
var name = "@univerjs/data-validation";
|
|
363
|
-
var version = "1.0
|
|
363
|
+
var version = "1.1.0";
|
|
364
364
|
|
|
365
365
|
//#endregion
|
|
366
366
|
//#region src/config/config.ts
|
package/lib/index.js
CHANGED
|
@@ -53,7 +53,7 @@ let UpdateRuleType = /* @__PURE__ */ function(UpdateRuleType) {
|
|
|
53
53
|
}({});
|
|
54
54
|
|
|
55
55
|
//#endregion
|
|
56
|
-
//#region \0@oxc-project+runtime@0.
|
|
56
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
57
57
|
function _typeof(o) {
|
|
58
58
|
"@babel/helpers - typeof";
|
|
59
59
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -64,7 +64,7 @@ function _typeof(o) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
//#endregion
|
|
67
|
-
//#region \0@oxc-project+runtime@0.
|
|
67
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
68
68
|
function toPrimitive(t, r) {
|
|
69
69
|
if ("object" != _typeof(t) || !t) return t;
|
|
70
70
|
var e = t[Symbol.toPrimitive];
|
|
@@ -77,14 +77,14 @@ function toPrimitive(t, r) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
//#endregion
|
|
80
|
-
//#region \0@oxc-project+runtime@0.
|
|
80
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
81
81
|
function toPropertyKey(t) {
|
|
82
82
|
var i = toPrimitive(t, "string");
|
|
83
83
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
//#endregion
|
|
87
|
-
//#region \0@oxc-project+runtime@0.
|
|
87
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
88
88
|
function _defineProperty(e, r, t) {
|
|
89
89
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
90
90
|
value: t,
|
|
@@ -95,7 +95,7 @@ function _defineProperty(e, r, t) {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
//#endregion
|
|
98
|
-
//#region \0@oxc-project+runtime@0.
|
|
98
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
99
99
|
function __decorateParam(paramIndex, decorator) {
|
|
100
100
|
return function(target, key) {
|
|
101
101
|
decorator(target, key, paramIndex);
|
|
@@ -103,7 +103,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
//#endregion
|
|
106
|
-
//#region \0@oxc-project+runtime@0.
|
|
106
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
107
107
|
function __decorate(decorators, target, key, desc) {
|
|
108
108
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
109
109
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -319,7 +319,7 @@ let DataValidationResourceController = class DataValidationResourceController ex
|
|
|
319
319
|
const resultMap = {};
|
|
320
320
|
if (map) {
|
|
321
321
|
map.forEach(([key, v]) => {
|
|
322
|
-
resultMap[key] = v;
|
|
322
|
+
if (v.length > 0) resultMap[key] = v;
|
|
323
323
|
});
|
|
324
324
|
return JSON.stringify(resultMap);
|
|
325
325
|
}
|
|
@@ -329,7 +329,7 @@ let DataValidationResourceController = class DataValidationResourceController ex
|
|
|
329
329
|
if (!json) return {};
|
|
330
330
|
try {
|
|
331
331
|
return JSON.parse(json);
|
|
332
|
-
} catch
|
|
332
|
+
} catch {
|
|
333
333
|
return {};
|
|
334
334
|
}
|
|
335
335
|
};
|
|
@@ -360,7 +360,7 @@ DataValidationResourceController = __decorate([
|
|
|
360
360
|
//#endregion
|
|
361
361
|
//#region package.json
|
|
362
362
|
var name = "@univerjs/data-validation";
|
|
363
|
-
var version = "1.0
|
|
363
|
+
var version = "1.1.0";
|
|
364
364
|
|
|
365
365
|
//#endregion
|
|
366
366
|
//#region src/config/config.ts
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDataValidation={},e.UniverCore,e.rxjs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function r(e){return{type:e.type,operator:e.operator,formula1:e.formula1,formula2:e.formula2,allowBlank:e.allowBlank}}function i(e){return{error:e.error,errorStyle:e.errorStyle,errorTitle:e.errorTitle,imeMode:e.imeMode,prompt:e.prompt,promptTitle:e.promptTitle,showDropDown:e.showDropDown,showErrorMessage:e.showErrorMessage,showInputMessage:e.showInputMessage,renderMode:e.renderMode,bizInfo:e.bizInfo}}let a=function(e){return e[e.SETTING=0]=`SETTING`,e[e.RANGE=1]=`RANGE`,e[e.OPTIONS=2]=`OPTIONS`,e[e.ALL=3]=`ALL`,e}({});function o(e){"@babel/helpers - typeof";return o=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},o(e)}function s(e,t){if(o(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(o(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e){var t=s(e,`string`);return o(t)==`symbol`?t:t+``}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){return function(n,r){t(n,r,e)}}function d(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 f=class extends t.Disposable{constructor(e){super(),this._logService=e,l(this,`_model`,new Map),l(this,`_ruleChange$`,new n.Subject),l(this,`ruleChange$`,this._ruleChange$.asObservable()),l(this,`ruleChangeDebounce$`,this.ruleChange$.pipe((0,n.debounceTime)(20))),this.disposeWithMe({dispose:()=>{this._ruleChange$.complete()}})}_ensureMap(e,t){this._model.has(e)||this._model.set(e,new Map);let n=this._model.get(e);if(n.has(t))return n.get(t);let r={map:new Map,list:[]};return n.set(t,r),r}_addSubUnitRule(e,t,n){let{map:r,list:i}=e,a=(Array.isArray(t)?t:[t]).filter(e=>!r.has(e.uid));typeof n==`number`&&n<i.length?i.splice(n,0,...a):i.push(...a),a.forEach(e=>{r.set(e.uid,e)})}_removeSubUnitRule(e,t){let{map:n,list:r}=e,i=r.findIndex(e=>e.uid===t);i>-1&&(r.splice(i,1),n.delete(t))}_updateSubUnitRule(e,t,n){let{map:a,list:o}=e,s=a.get(t),c=o.findIndex(e=>t===e.uid);if(!s)throw Error(`Data validation rule is not found, ruleId: ${t}.`);let l={...s};switch(n.type){case 1:l.ranges=n.payload;break;case 0:Object.assign(l,r(n.payload));break;case 2:Object.assign(l,i(n.payload));break;case 3:Object.assign(l,n.payload)}return o[c]=l,a.set(t,l),l}_addRuleSideEffect(e,t,n,r){if(!this._ensureMap(e,t).map.get(n.uid))return{rule:n,type:`add`,unitId:e,subUnitId:t,source:r}}addRule(e,t,n,r,i){try{let a=this._ensureMap(e,t),o=(Array.isArray(n)?n:[n]).map(n=>this._addRuleSideEffect(e,t,n,r));this._addSubUnitRule(a,n,i),o.forEach(e=>{e&&this._ruleChange$.next(e)})}catch(e){this._logService.error(e)}}updateRule(e,n,r,i,a){try{let o=this._ensureMap(e,n),s=t.Tools.deepClone(o.map.get(r));if(!s)throw Error(`Data validation rule is not found, ruleId: ${r}.`);let c=this._updateSubUnitRule(o,r,i);this._ruleChange$.next({rule:c,type:`update`,unitId:e,subUnitId:n,source:a,updatePayload:i,oldRule:s})}catch(e){this._logService.error(e)}}removeRule(e,t,n,r){try{let i=this._ensureMap(e,t),a=i.map.get(n);a&&(this._removeSubUnitRule(i,n),this._ruleChange$.next({rule:a,type:`remove`,unitId:e,subUnitId:t,source:r}))}catch(e){this._logService.error(e)}}getRuleById(e,t,n){return this._ensureMap(e,t).map.get(n)}getRuleIndex(e,t,n){return this._ensureMap(e,t).list.findIndex(e=>e.uid===n)}getRules(e,t){return[...this._ensureMap(e,t).list]}getUnitRules(e){let t=this._model.get(e);if(!t)return[];let n=[];return t.forEach((e,t)=>{n.push([t,e.list])}),n}deleteUnitRules(e){this._model.delete(e)}getSubUnitIds(e){var t;return Array.from(((t=this._model.get(e))==null?void 0:t.keys())??[])}getAll(){return Array.from(this._model.keys()).map(e=>[e,this.getUnitRules(e)])}};f=d([u(0,t.ILogService)],f);let p={type:t.CommandType.MUTATION,id:`data-validation.mutation.addRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,rule:i,index:a,source:o=`command`}=t;return e.get(f).addRule(n,r,i,o,a),!0}},m={type:t.CommandType.MUTATION,id:`data-validation.mutation.removeRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,ruleId:i,source:a=`command`}=t,o=e.get(f);return Array.isArray(i)?i.forEach(e=>{o.removeRule(n,r,e,a)}):o.removeRule(n,r,i,a),!0}},h={type:t.CommandType.MUTATION,id:`data-validation.mutation.updateRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,ruleId:i,payload:a,source:o=`command`}=t;return e.get(f).updateRule(n,r,i,a,o),!0}},g=class extends t.Disposable{constructor(e,t,n){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._dataValidationModel=n,this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._dataValidationModel.getUnitRules(e),n={};return t?(t.forEach(([e,t])=>{n[e]=t}),JSON.stringify(n)):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_DATA_VALIDATION_PLUGIN`,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>n(e),onUnLoad:e=>{this._dataValidationModel.deleteUnitRules(e)},onLoad:(e,t)=>{Object.keys(t).forEach(n=>{t[n].forEach(t=>{this._dataValidationModel.addRule(e,n,t,`patched`)})})}}))}};g=d([u(0,t.IResourceManagerService),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(f))],g);var _=`@univerjs/data-validation`,v=`1.0.3`;let y={},b=function(e){return e.SHEET=`sheet`,e}({});var x=class{constructor(){l(this,`_validatorByScopes`,new Map),l(this,`_validatorMap`,new Map),l(this,`_validatorsChange$`,new n.BehaviorSubject(void 0)),l(this,`validatorsChange$`,this._validatorsChange$.asObservable())}_addValidatorToScope(e,t){this._validatorByScopes.has(t)||this._validatorByScopes.set(t,[]);let n=this._validatorByScopes.get(t);if(n.findIndex(t=>t.id===e.id)>-1)throw Error(`Validator item with the same id ${e.id} has already been added!`);n.push(e)}_removeValidatorFromScope(e,t){let n=this._validatorByScopes.get(t);if(!n)return;let r=n.findIndex(t=>t.id===e.id);r>-1&&n.splice(r,1)}register(e){return this._validatorMap.set(e.id,e),Array.isArray(e.scopes)?e.scopes.forEach(t=>{this._addValidatorToScope(e,t)}):this._addValidatorToScope(e,e.scopes),this._validatorsChange$.next(),(0,t.toDisposable)(()=>{this._validatorMap.delete(e.id),Array.isArray(e.scopes)?e.scopes.forEach(t=>{this._removeValidatorFromScope(e,t)}):this._removeValidatorFromScope(e,e.scopes),this._validatorsChange$.next()})}getValidatorItem(e){return this._validatorMap.get(e)}getValidatorsByScope(e){return this._validatorByScopes.get(e)}};let S=class extends t.Plugin{constructor(e=y,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},y,this._config);this._configService.setConfig(`data-validation.config`,a)}onStarting(){[[f],[x],[g]].forEach(e=>this._injector.add(e)),[p,h,m].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(g)}};l(S,`pluginName`,`UNIVER_DATA_VALIDATION_PLUGIN`),l(S,`packageName`,_),l(S,`version`,v),l(S,`type`,t.UniverInstanceType.UNIVER_SHEET),S=d([u(1,(0,t.Inject)(t.Injector)),u(2,t.ICommandService),u(3,t.IConfigService)],S);let C=[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.NOT_BETWEEN];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 w={[t.DataValidationOperator.BETWEEN]:`data-validation.ruleName.between`,[t.DataValidationOperator.EQUAL]:`data-validation.ruleName.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.ruleName.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.ruleName.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.ruleName.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.ruleName.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.ruleName.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.ruleName.notEqual`,NONE:`data-validation.ruleName.legal`},T={[t.DataValidationOperator.BETWEEN]:`data-validation.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`data-validation.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.errorMsg.notEqual`,NONE:`data-validation.errorMsg.legal`},E=`{FORMULA1}`,D=`{FORMULA2}`,O=`{TYPE}`,k={[t.DataValidationOperator.BETWEEN]:`data-validation.operators.between`,[t.DataValidationOperator.EQUAL]:`data-validation.operators.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.operators.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.operators.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.operators.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.operators.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.operators.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.operators.notEqual`},A=function(e){return e.DATE=`date`,e.TIME=`time`,e.DATETIME=`datetime`,e.LIST=`list`,e.MULTIPLE_LIST=`multipleList`,e.COLOR=`color`,e.CASCADE=`cascade`,e}({}),j=class{constructor(e,t){this.localeService=e,this.injector=t,l(this,`offsetFormulaByRange`,!0),l(this,`formulaInput`,void 0),l(this,`canvasRender`,null),l(this,`dropdownType`,void 0),l(this,`optionsInput`,void 0),l(this,`skipDefaultFontRender`,void 0)}get operatorNames(){return this.operators.map(e=>this.localeService.t(k[e]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(e){if(!e.operator)return this.localeService.t(w.NONE).replace(O,this.titleStr);let t=this.localeService.t(w[e.operator]).replace(E,e.formula1??``).replace(D,e.formula2??``);return`${this.titleStr} ${t}`}generateRuleErrorMessage(e,t){return e.operator?`${this.localeService.t(T[e.operator]).replace(E,e.formula1??``).replace(D,e.formula2??``)}`:this.localeService.t(T.NONE).replace(O,this.titleStr)}getExtraStyle(e,t,n,r,i){}getRuleFinalError(e,t){return e.showErrorMessage&&e.error?e.error:this.generateRuleErrorMessage(e,t)}isEmptyCellValue(e){return e===``||e==null}normalizeFormula(e,t,n){return{formula1:e.formula1,formula2:e.formula2}}async isValidType(e,t,n){return!0}transform(e,t,n){return e}async validatorIsEqual(e,t,n){let{formula1:r}=t,{value:i}=e;return Number.isNaN(r)?!0:i===r}async validatorIsNotEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value!==r}async validatorIsBetween(e,t,n){let{formula1:r,formula2:i}=t;if(Number.isNaN(r)||Number.isNaN(i))return!0;let a=Math.min(r,i),o=Math.max(r,i);return e.value>=a&&e.value<=o}async validatorIsNotBetween(e,t,n){let{formula1:r,formula2:i}=t;if(Number.isNaN(r)||Number.isNaN(i))return!0;let a=Math.min(r,i),o=Math.max(r,i);return e.value<a||e.value>o}async validatorIsGreaterThan(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value>r}async validatorIsGreaterThanOrEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value>=r}async validatorIsLessThan(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value<r}async validatorIsLessThanOrEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value<=r}async validator(e,n){let{value:r,unitId:i,subUnitId:a}=e,o=this.isEmptyCellValue(r),{allowBlank:s=!0,operator:c}=n;if(o)return s;let l=await this.parseFormula(n,i,a,e.row,e.column);if(!l.isFormulaValid||!await this.isValidType(e,l,n))return!1;if(!c)return!0;let u=this.transform(e,l,n);switch(c){case t.DataValidationOperator.BETWEEN:return this.validatorIsBetween(u,l,n);case t.DataValidationOperator.EQUAL:return this.validatorIsEqual(u,l,n);case t.DataValidationOperator.GREATER_THAN:return this.validatorIsGreaterThan(u,l,n);case t.DataValidationOperator.GREATER_THAN_OR_EQUAL:return this.validatorIsGreaterThanOrEqual(u,l,n);case t.DataValidationOperator.LESS_THAN:return this.validatorIsLessThan(u,l,n);case t.DataValidationOperator.LESS_THAN_OR_EQUAL:return this.validatorIsLessThanOrEqual(u,l,n);case t.DataValidationOperator.NOT_BETWEEN:return this.validatorIsNotBetween(u,l,n);case t.DataValidationOperator.NOT_EQUAL:return this.validatorIsNotEqual(u,l,n);default:throw Error(`Unknown operator.`)}}};j=d([u(0,(0,t.Inject)(t.LocaleService)),u(1,(0,t.Inject)(t.Injector))],j),e.AddDataValidationMutation=p,Object.defineProperty(e,"BaseDataValidator",{enumerable:!0,get:function(){return j}}),Object.defineProperty(e,"DataValidationModel",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"DataValidationResourceController",{enumerable:!0,get:function(){return g}}),e.DataValidatorDropdownType=A,e.DataValidatorRegistryScope=b,e.DataValidatorRegistryService=x,e.FORMULA1=E,e.FORMULA2=D,e.RemoveDataValidationMutation=m,e.TWO_FORMULA_OPERATOR_COUNT=C,e.TYPE=O,Object.defineProperty(e,"UniverDataValidationPlugin",{enumerable:!0,get:function(){return S}}),e.UpdateDataValidationMutation=h,e.UpdateRuleType=a,e.getRuleOptions=i,e.getRuleSetting=r});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDataValidation={},e.UniverCore,e.rxjs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function r(e){return{type:e.type,operator:e.operator,formula1:e.formula1,formula2:e.formula2,allowBlank:e.allowBlank}}function i(e){return{error:e.error,errorStyle:e.errorStyle,errorTitle:e.errorTitle,imeMode:e.imeMode,prompt:e.prompt,promptTitle:e.promptTitle,showDropDown:e.showDropDown,showErrorMessage:e.showErrorMessage,showInputMessage:e.showInputMessage,renderMode:e.renderMode,bizInfo:e.bizInfo}}let a=/* @__PURE__ */ function(e){return e[e.SETTING=0]=`SETTING`,e[e.RANGE=1]=`RANGE`,e[e.OPTIONS=2]=`OPTIONS`,e[e.ALL=3]=`ALL`,e}({});function o(e){"@babel/helpers - typeof";return o=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},o(e)}function s(e,t){if(o(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(o(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e){var t=s(e,`string`);return o(t)==`symbol`?t:t+``}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){return function(n,r){t(n,r,e)}}function d(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 f=class extends t.Disposable{constructor(e){super(),this._logService=e,l(this,`_model`,/* @__PURE__ */ new Map),l(this,`_ruleChange$`,new n.Subject),l(this,`ruleChange$`,this._ruleChange$.asObservable()),l(this,`ruleChangeDebounce$`,this.ruleChange$.pipe((0,n.debounceTime)(20))),this.disposeWithMe({dispose:()=>{this._ruleChange$.complete()}})}_ensureMap(e,t){this._model.has(e)||this._model.set(e,/* @__PURE__ */ new Map);let n=this._model.get(e);if(n.has(t))return n.get(t);let r={map:/* @__PURE__ */ new Map,list:[]};return n.set(t,r),r}_addSubUnitRule(e,t,n){let{map:r,list:i}=e,a=(Array.isArray(t)?t:[t]).filter(e=>!r.has(e.uid));typeof n==`number`&&n<i.length?i.splice(n,0,...a):i.push(...a),a.forEach(e=>{r.set(e.uid,e)})}_removeSubUnitRule(e,t){let{map:n,list:r}=e,i=r.findIndex(e=>e.uid===t);i>-1&&(r.splice(i,1),n.delete(t))}_updateSubUnitRule(e,t,n){let{map:a,list:o}=e,s=a.get(t),c=o.findIndex(e=>t===e.uid);if(!s)throw Error(`Data validation rule is not found, ruleId: ${t}.`);let l={...s};switch(n.type){case 1:l.ranges=n.payload;break;case 0:Object.assign(l,r(n.payload));break;case 2:Object.assign(l,i(n.payload));break;case 3:Object.assign(l,n.payload)}return o[c]=l,a.set(t,l),l}_addRuleSideEffect(e,t,n,r){if(!this._ensureMap(e,t).map.get(n.uid))return{rule:n,type:`add`,unitId:e,subUnitId:t,source:r}}addRule(e,t,n,r,i){try{let a=this._ensureMap(e,t),o=(Array.isArray(n)?n:[n]).map(n=>this._addRuleSideEffect(e,t,n,r));this._addSubUnitRule(a,n,i),o.forEach(e=>{e&&this._ruleChange$.next(e)})}catch(e){this._logService.error(e)}}updateRule(e,n,r,i,a){try{let o=this._ensureMap(e,n),s=t.Tools.deepClone(o.map.get(r));if(!s)throw Error(`Data validation rule is not found, ruleId: ${r}.`);let c=this._updateSubUnitRule(o,r,i);this._ruleChange$.next({rule:c,type:`update`,unitId:e,subUnitId:n,source:a,updatePayload:i,oldRule:s})}catch(e){this._logService.error(e)}}removeRule(e,t,n,r){try{let i=this._ensureMap(e,t),a=i.map.get(n);a&&(this._removeSubUnitRule(i,n),this._ruleChange$.next({rule:a,type:`remove`,unitId:e,subUnitId:t,source:r}))}catch(e){this._logService.error(e)}}getRuleById(e,t,n){return this._ensureMap(e,t).map.get(n)}getRuleIndex(e,t,n){return this._ensureMap(e,t).list.findIndex(e=>e.uid===n)}getRules(e,t){return[...this._ensureMap(e,t).list]}getUnitRules(e){let t=this._model.get(e);if(!t)return[];let n=[];return t.forEach((e,t)=>{n.push([t,e.list])}),n}deleteUnitRules(e){this._model.delete(e)}getSubUnitIds(e){var t;return Array.from(((t=this._model.get(e))==null?void 0:t.keys())??[])}getAll(){return Array.from(this._model.keys()).map(e=>[e,this.getUnitRules(e)])}};f=d([u(0,t.ILogService)],f);let p={type:t.CommandType.MUTATION,id:`data-validation.mutation.addRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,rule:i,index:a,source:o=`command`}=t;return e.get(f).addRule(n,r,i,o,a),!0}},m={type:t.CommandType.MUTATION,id:`data-validation.mutation.removeRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,ruleId:i,source:a=`command`}=t,o=e.get(f);return Array.isArray(i)?i.forEach(e=>{o.removeRule(n,r,e,a)}):o.removeRule(n,r,i,a),!0}},h={type:t.CommandType.MUTATION,id:`data-validation.mutation.updateRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,ruleId:i,payload:a,source:o=`command`}=t;return e.get(f).updateRule(n,r,i,a,o),!0}},g=class extends t.Disposable{constructor(e,t,n){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._dataValidationModel=n,this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._dataValidationModel.getUnitRules(e),n={};return t?(t.forEach(([e,t])=>{t.length>0&&(n[e]=t)}),JSON.stringify(n)):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_DATA_VALIDATION_PLUGIN`,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>n(e),onUnLoad:e=>{this._dataValidationModel.deleteUnitRules(e)},onLoad:(e,t)=>{Object.keys(t).forEach(n=>{t[n].forEach(t=>{this._dataValidationModel.addRule(e,n,t,`patched`)})})}}))}};g=d([u(0,t.IResourceManagerService),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(f))],g);var _=`@univerjs/data-validation`,v=`1.1.0`;let y={},b=/* @__PURE__ */ function(e){return e.SHEET=`sheet`,e}({});var x=class{constructor(){l(this,`_validatorByScopes`,/* @__PURE__ */ new Map),l(this,`_validatorMap`,/* @__PURE__ */ new Map),l(this,`_validatorsChange$`,new n.BehaviorSubject(void 0)),l(this,`validatorsChange$`,this._validatorsChange$.asObservable())}_addValidatorToScope(e,t){this._validatorByScopes.has(t)||this._validatorByScopes.set(t,[]);let n=this._validatorByScopes.get(t);if(n.findIndex(t=>t.id===e.id)>-1)throw Error(`Validator item with the same id ${e.id} has already been added!`);n.push(e)}_removeValidatorFromScope(e,t){let n=this._validatorByScopes.get(t);if(!n)return;let r=n.findIndex(t=>t.id===e.id);r>-1&&n.splice(r,1)}register(e){return this._validatorMap.set(e.id,e),Array.isArray(e.scopes)?e.scopes.forEach(t=>{this._addValidatorToScope(e,t)}):this._addValidatorToScope(e,e.scopes),this._validatorsChange$.next(),(0,t.toDisposable)(()=>{this._validatorMap.delete(e.id),Array.isArray(e.scopes)?e.scopes.forEach(t=>{this._removeValidatorFromScope(e,t)}):this._removeValidatorFromScope(e,e.scopes),this._validatorsChange$.next()})}getValidatorItem(e){return this._validatorMap.get(e)}getValidatorsByScope(e){return this._validatorByScopes.get(e)}};let S=class extends t.Plugin{constructor(e=y,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},y,this._config);this._configService.setConfig(`data-validation.config`,a)}onStarting(){[[f],[x],[g]].forEach(e=>this._injector.add(e)),[p,h,m].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(g)}};l(S,`pluginName`,`UNIVER_DATA_VALIDATION_PLUGIN`),l(S,`packageName`,_),l(S,`version`,v),l(S,`type`,t.UniverInstanceType.UNIVER_SHEET),S=d([u(1,(0,t.Inject)(t.Injector)),u(2,t.ICommandService),u(3,t.IConfigService)],S);let C=[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.NOT_BETWEEN];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 w={[t.DataValidationOperator.BETWEEN]:`data-validation.ruleName.between`,[t.DataValidationOperator.EQUAL]:`data-validation.ruleName.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.ruleName.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.ruleName.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.ruleName.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.ruleName.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.ruleName.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.ruleName.notEqual`,NONE:`data-validation.ruleName.legal`},T={[t.DataValidationOperator.BETWEEN]:`data-validation.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`data-validation.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.errorMsg.notEqual`,NONE:`data-validation.errorMsg.legal`},E=`{FORMULA1}`,D=`{FORMULA2}`,O=`{TYPE}`,k={[t.DataValidationOperator.BETWEEN]:`data-validation.operators.between`,[t.DataValidationOperator.EQUAL]:`data-validation.operators.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.operators.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.operators.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.operators.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.operators.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.operators.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.operators.notEqual`},A=/* @__PURE__ */ function(e){return e.DATE=`date`,e.TIME=`time`,e.DATETIME=`datetime`,e.LIST=`list`,e.MULTIPLE_LIST=`multipleList`,e.COLOR=`color`,e.CASCADE=`cascade`,e}({}),j=class{constructor(e,t){this.localeService=e,this.injector=t,l(this,`offsetFormulaByRange`,!0),l(this,`formulaInput`,void 0),l(this,`canvasRender`,null),l(this,`dropdownType`,void 0),l(this,`optionsInput`,void 0),l(this,`skipDefaultFontRender`,void 0)}get operatorNames(){return this.operators.map(e=>this.localeService.t(k[e]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(e){if(!e.operator)return this.localeService.t(w.NONE).replace(O,this.titleStr);let t=this.localeService.t(w[e.operator]).replace(E,e.formula1??``).replace(D,e.formula2??``);return`${this.titleStr} ${t}`}generateRuleErrorMessage(e,t){return e.operator?`${this.localeService.t(T[e.operator]).replace(E,e.formula1??``).replace(D,e.formula2??``)}`:this.localeService.t(T.NONE).replace(O,this.titleStr)}getExtraStyle(e,t,n,r,i){}getRuleFinalError(e,t){return e.showErrorMessage&&e.error?e.error:this.generateRuleErrorMessage(e,t)}isEmptyCellValue(e){return e===``||e==null}normalizeFormula(e,t,n){return{formula1:e.formula1,formula2:e.formula2}}async isValidType(e,t,n){return!0}transform(e,t,n){return e}async validatorIsEqual(e,t,n){let{formula1:r}=t,{value:i}=e;return Number.isNaN(r)?!0:i===r}async validatorIsNotEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value!==r}async validatorIsBetween(e,t,n){let{formula1:r,formula2:i}=t;if(Number.isNaN(r)||Number.isNaN(i))return!0;let a=Math.min(r,i),o=Math.max(r,i);return e.value>=a&&e.value<=o}async validatorIsNotBetween(e,t,n){let{formula1:r,formula2:i}=t;if(Number.isNaN(r)||Number.isNaN(i))return!0;let a=Math.min(r,i),o=Math.max(r,i);return e.value<a||e.value>o}async validatorIsGreaterThan(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value>r}async validatorIsGreaterThanOrEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value>=r}async validatorIsLessThan(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value<r}async validatorIsLessThanOrEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value<=r}async validator(e,n){let{value:r,unitId:i,subUnitId:a}=e,o=this.isEmptyCellValue(r),{allowBlank:s=!0,operator:c}=n;if(o)return s;let l=await this.parseFormula(n,i,a,e.row,e.column);if(!l.isFormulaValid||!await this.isValidType(e,l,n))return!1;if(!c)return!0;let u=this.transform(e,l,n);switch(c){case t.DataValidationOperator.BETWEEN:return this.validatorIsBetween(u,l,n);case t.DataValidationOperator.EQUAL:return this.validatorIsEqual(u,l,n);case t.DataValidationOperator.GREATER_THAN:return this.validatorIsGreaterThan(u,l,n);case t.DataValidationOperator.GREATER_THAN_OR_EQUAL:return this.validatorIsGreaterThanOrEqual(u,l,n);case t.DataValidationOperator.LESS_THAN:return this.validatorIsLessThan(u,l,n);case t.DataValidationOperator.LESS_THAN_OR_EQUAL:return this.validatorIsLessThanOrEqual(u,l,n);case t.DataValidationOperator.NOT_BETWEEN:return this.validatorIsNotBetween(u,l,n);case t.DataValidationOperator.NOT_EQUAL:return this.validatorIsNotEqual(u,l,n);default:throw Error(`Unknown operator.`)}}};j=d([u(0,(0,t.Inject)(t.LocaleService)),u(1,(0,t.Inject)(t.Injector))],j),e.AddDataValidationMutation=p,Object.defineProperty(e,"BaseDataValidator",{enumerable:!0,get:function(){return j}}),Object.defineProperty(e,"DataValidationModel",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"DataValidationResourceController",{enumerable:!0,get:function(){return g}}),e.DataValidatorDropdownType=A,e.DataValidatorRegistryScope=b,e.DataValidatorRegistryService=x,e.FORMULA1=E,e.FORMULA2=D,e.RemoveDataValidationMutation=m,e.TWO_FORMULA_OPERATOR_COUNT=C,e.TYPE=O,Object.defineProperty(e,"UniverDataValidationPlugin",{enumerable:!0,get:function(){return S}}),e.UpdateDataValidationMutation=h,e.UpdateRuleType=a,e.getRuleOptions=i,e.getRuleSetting=r});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/data-validation",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared data validation models and rule services for Univer.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -57,15 +57,15 @@
|
|
|
57
57
|
"rxjs": ">=7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/core": "1.0
|
|
60
|
+
"@univerjs/core": "1.1.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@univerjs-infra/shared": "1.0
|
|
64
|
-
"@univerjs/protocol": "1.0
|
|
65
|
-
"@univerjs/sheets": "1.0
|
|
63
|
+
"@univerjs-infra/shared": "1.1.0",
|
|
64
|
+
"@univerjs/protocol": "1.1.0",
|
|
65
|
+
"@univerjs/sheets": "1.1.0",
|
|
66
66
|
"rxjs": "^7.8.2",
|
|
67
67
|
"typescript": "^6.0.3",
|
|
68
|
-
"vitest": "^5.0.
|
|
68
|
+
"vitest": "^5.0.4"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"test": "vitest run",
|