@univerjs/data-validation 1.0.0-alpha.8 → 1.0.0-beta.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 CHANGED
@@ -260,8 +260,8 @@ let DataValidationModel = class DataValidationModel extends _univerjs_core.Dispo
260
260
  this._model.delete(unitId);
261
261
  }
262
262
  getSubUnitIds(unitId) {
263
- var _this$_model$get$keys, _this$_model$get;
264
- return Array.from((_this$_model$get$keys = (_this$_model$get = this._model.get(unitId)) === null || _this$_model$get === void 0 ? void 0 : _this$_model$get.keys()) !== null && _this$_model$get$keys !== void 0 ? _this$_model$get$keys : []);
263
+ var _this$_model$get;
264
+ return Array.from(((_this$_model$get = this._model.get(unitId)) === null || _this$_model$get === void 0 ? void 0 : _this$_model$get.keys()) ?? []);
265
265
  }
266
266
  getAll() {
267
267
  return Array.from(this._model.keys()).map((unitId) => [unitId, this.getUnitRules(unitId)]);
@@ -364,7 +364,7 @@ DataValidationResourceController = __decorate([
364
364
  //#endregion
365
365
  //#region package.json
366
366
  var name = "@univerjs/data-validation";
367
- var version = "1.0.0-alpha.8";
367
+ var version = "1.0.0-beta.0";
368
368
 
369
369
  //#endregion
370
370
  //#region src/config/config.ts
@@ -591,15 +591,13 @@ let BaseDataValidator = class BaseDataValidator {
591
591
  return this.localeService.t(this.title);
592
592
  }
593
593
  generateRuleName(rule) {
594
- var _rule$formula, _rule$formula2;
595
594
  if (!rule.operator) return this.localeService.t(OperatorTitleMap.NONE).replace(TYPE, this.titleStr);
596
- const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1, (_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "").replace(FORMULA2, (_rule$formula2 = rule.formula2) !== null && _rule$formula2 !== void 0 ? _rule$formula2 : "");
595
+ const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1, rule.formula1 ?? "").replace(FORMULA2, rule.formula2 ?? "");
597
596
  return `${this.titleStr} ${ruleName}`;
598
597
  }
599
598
  generateRuleErrorMessage(rule, position) {
600
- var _rule$formula3, _rule$formula4;
601
599
  if (!rule.operator) return this.localeService.t(OperatorErrorTitleMap.NONE).replace(TYPE, this.titleStr);
602
- return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, (_rule$formula3 = rule.formula1) !== null && _rule$formula3 !== void 0 ? _rule$formula3 : "").replace(FORMULA2, (_rule$formula4 = rule.formula2) !== null && _rule$formula4 !== void 0 ? _rule$formula4 : "")}`;
600
+ return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, rule.formula1 ?? "").replace(FORMULA2, rule.formula2 ?? "")}`;
603
601
  }
604
602
  getExtraStyle(rule, value, ctx, row, column) {}
605
603
  getRuleFinalError(rule, position) {
package/lib/es/index.js CHANGED
@@ -259,8 +259,8 @@ let DataValidationModel = class DataValidationModel extends Disposable {
259
259
  this._model.delete(unitId);
260
260
  }
261
261
  getSubUnitIds(unitId) {
262
- var _this$_model$get$keys, _this$_model$get;
263
- return Array.from((_this$_model$get$keys = (_this$_model$get = this._model.get(unitId)) === null || _this$_model$get === void 0 ? void 0 : _this$_model$get.keys()) !== null && _this$_model$get$keys !== void 0 ? _this$_model$get$keys : []);
262
+ var _this$_model$get;
263
+ return Array.from(((_this$_model$get = this._model.get(unitId)) === null || _this$_model$get === void 0 ? void 0 : _this$_model$get.keys()) ?? []);
264
264
  }
265
265
  getAll() {
266
266
  return Array.from(this._model.keys()).map((unitId) => [unitId, this.getUnitRules(unitId)]);
@@ -363,7 +363,7 @@ DataValidationResourceController = __decorate([
363
363
  //#endregion
364
364
  //#region package.json
365
365
  var name = "@univerjs/data-validation";
366
- var version = "1.0.0-alpha.8";
366
+ var version = "1.0.0-beta.0";
367
367
 
368
368
  //#endregion
369
369
  //#region src/config/config.ts
@@ -590,15 +590,13 @@ let BaseDataValidator = class BaseDataValidator {
590
590
  return this.localeService.t(this.title);
591
591
  }
592
592
  generateRuleName(rule) {
593
- var _rule$formula, _rule$formula2;
594
593
  if (!rule.operator) return this.localeService.t(OperatorTitleMap.NONE).replace(TYPE, this.titleStr);
595
- const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1, (_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "").replace(FORMULA2, (_rule$formula2 = rule.formula2) !== null && _rule$formula2 !== void 0 ? _rule$formula2 : "");
594
+ const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1, rule.formula1 ?? "").replace(FORMULA2, rule.formula2 ?? "");
596
595
  return `${this.titleStr} ${ruleName}`;
597
596
  }
598
597
  generateRuleErrorMessage(rule, position) {
599
- var _rule$formula3, _rule$formula4;
600
598
  if (!rule.operator) return this.localeService.t(OperatorErrorTitleMap.NONE).replace(TYPE, this.titleStr);
601
- return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, (_rule$formula3 = rule.formula1) !== null && _rule$formula3 !== void 0 ? _rule$formula3 : "").replace(FORMULA2, (_rule$formula4 = rule.formula2) !== null && _rule$formula4 !== void 0 ? _rule$formula4 : "")}`;
599
+ return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, rule.formula1 ?? "").replace(FORMULA2, rule.formula2 ?? "")}`;
602
600
  }
603
601
  getExtraStyle(rule, value, ctx, row, column) {}
604
602
  getRuleFinalError(rule, position) {
package/lib/index.js CHANGED
@@ -259,8 +259,8 @@ let DataValidationModel = class DataValidationModel extends Disposable {
259
259
  this._model.delete(unitId);
260
260
  }
261
261
  getSubUnitIds(unitId) {
262
- var _this$_model$get$keys, _this$_model$get;
263
- return Array.from((_this$_model$get$keys = (_this$_model$get = this._model.get(unitId)) === null || _this$_model$get === void 0 ? void 0 : _this$_model$get.keys()) !== null && _this$_model$get$keys !== void 0 ? _this$_model$get$keys : []);
262
+ var _this$_model$get;
263
+ return Array.from(((_this$_model$get = this._model.get(unitId)) === null || _this$_model$get === void 0 ? void 0 : _this$_model$get.keys()) ?? []);
264
264
  }
265
265
  getAll() {
266
266
  return Array.from(this._model.keys()).map((unitId) => [unitId, this.getUnitRules(unitId)]);
@@ -363,7 +363,7 @@ DataValidationResourceController = __decorate([
363
363
  //#endregion
364
364
  //#region package.json
365
365
  var name = "@univerjs/data-validation";
366
- var version = "1.0.0-alpha.8";
366
+ var version = "1.0.0-beta.0";
367
367
 
368
368
  //#endregion
369
369
  //#region src/config/config.ts
@@ -590,15 +590,13 @@ let BaseDataValidator = class BaseDataValidator {
590
590
  return this.localeService.t(this.title);
591
591
  }
592
592
  generateRuleName(rule) {
593
- var _rule$formula, _rule$formula2;
594
593
  if (!rule.operator) return this.localeService.t(OperatorTitleMap.NONE).replace(TYPE, this.titleStr);
595
- const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1, (_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "").replace(FORMULA2, (_rule$formula2 = rule.formula2) !== null && _rule$formula2 !== void 0 ? _rule$formula2 : "");
594
+ const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1, rule.formula1 ?? "").replace(FORMULA2, rule.formula2 ?? "");
596
595
  return `${this.titleStr} ${ruleName}`;
597
596
  }
598
597
  generateRuleErrorMessage(rule, position) {
599
- var _rule$formula3, _rule$formula4;
600
598
  if (!rule.operator) return this.localeService.t(OperatorErrorTitleMap.NONE).replace(TYPE, this.titleStr);
601
- return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, (_rule$formula3 = rule.formula1) !== null && _rule$formula3 !== void 0 ? _rule$formula3 : "").replace(FORMULA2, (_rule$formula4 = rule.formula2) !== null && _rule$formula4 !== void 0 ? _rule$formula4 : "")}`;
599
+ return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, rule.formula1 ?? "").replace(FORMULA2, rule.formula2 ?? "")}`;
602
600
  }
603
601
  getExtraStyle(rule, value, ctx, row, column) {}
604
602
  getRuleFinalError(rule, position) {
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);break;default:break}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,n;return Array.from((t=(n=this._model.get(e))==null?void 0:n.keys())==null?[]:t)}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.0-alpha.8`;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){var t,n;if(!e.operator)return this.localeService.t(w.NONE).replace(O,this.titleStr);let r=this.localeService.t(w[e.operator]).replace(E,(t=e.formula1)==null?``:t).replace(D,(n=e.formula2)==null?``:n);return`${this.titleStr} ${r}`}generateRuleErrorMessage(e,t){var n,r;return e.operator?`${this.localeService.t(T[e.operator]).replace(E,(n=e.formula1)==null?``:n).replace(D,(r=e.formula2)==null?``:r)}`: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=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);break;default:break}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.0-beta.0`;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});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/data-validation",
3
- "version": "1.0.0-alpha.8",
3
+ "version": "1.0.0-beta.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.0-alpha.8"
60
+ "@univerjs/core": "1.0.0-beta.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "rxjs": "^7.8.2",
64
64
  "typescript": "^6.0.3",
65
65
  "vitest": "^4.1.10",
66
- "@univerjs-infra/shared": "1.0.0-alpha.8",
67
- "@univerjs/protocol": "1.0.0-alpha.8",
68
- "@univerjs/sheets": "1.0.0-alpha.8"
66
+ "@univerjs-infra/shared": "1.0.0-beta.0",
67
+ "@univerjs/protocol": "1.0.0-beta.0",
68
+ "@univerjs/sheets": "1.0.0-beta.0"
69
69
  },
70
70
  "scripts": {
71
71
  "test": "vitest run",