@univerjs/data-validation 0.17.0 → 0.18.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.
@@ -1,5 +1,20 @@
1
- import { ICommand, IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions, IMutationInfo, Injector, IRange } from '@univerjs/core';
2
- import { IRemoveDataValidationMutationParams } from '../mutations/data-validation.mutation';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ICommand, IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions, IMutationInfo, Injector, IRange } from '@univerjs/core';
17
+ import type { IRemoveDataValidationMutationParams } from '../mutations/data-validation.mutation';
3
18
  interface ISheetCommandSharedParams {
4
19
  unitId: string;
5
20
  subUnitId: string;
@@ -1,6 +1,21 @@
1
- import { ICommand, IDataValidationRule } from '@univerjs/core';
2
- import { DataValidationChangeSource } from '../../models/data-validation-model';
3
- import { IUpdateRulePayload } from '../../types/interfaces/i-update-rule-payload';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ICommand, IDataValidationRule } from '@univerjs/core';
17
+ import type { DataValidationChangeSource } from '../../models/data-validation-model';
18
+ import type { IUpdateRulePayload } from '../../types/interfaces/i-update-rule-payload';
4
19
  export interface IAddDataValidationMutationParams {
5
20
  rule: IDataValidationRule | IDataValidationRule[];
6
21
  index?: number;
@@ -1,3 +1,18 @@
1
- import { IDataValidationRuleBase, IDataValidationRuleOptions } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IDataValidationRuleBase, IDataValidationRuleOptions } from '@univerjs/core';
2
17
  export declare function getRuleSetting(rule: IDataValidationRuleBase): IDataValidationRuleBase;
3
18
  export declare function getRuleOptions(rule: IDataValidationRuleOptions): IDataValidationRuleOptions;
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
  import { Disposable, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
2
17
  import { DataValidationModel } from '../models/data-validation-model';
3
18
  export declare class DataValidationResourceController extends Disposable {
@@ -1,5 +1,21 @@
1
- import { IDataValidationRule, Disposable, ILogService } from '@univerjs/core';
2
- import { IUpdateRulePayload } from '../types/interfaces/i-update-rule-payload';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IDataValidationRule } from '@univerjs/core';
17
+ import type { IUpdateRulePayload } from '../types/interfaces/i-update-rule-payload';
18
+ import { Disposable, ILogService } from '@univerjs/core';
3
19
  export type DataValidationChangeType = 'update' | 'add' | 'remove';
4
20
  export type DataValidationChangeSource = 'command' | 'patched';
5
21
  export interface IRuleChange {
@@ -15,8 +31,8 @@ export declare class DataValidationModel extends Disposable {
15
31
  private readonly _logService;
16
32
  private readonly _model;
17
33
  private readonly _ruleChange$;
18
- ruleChange$: import('rxjs').Observable<IRuleChange>;
19
- ruleChangeDebounce$: import('rxjs').Observable<IRuleChange>;
34
+ ruleChange$: import("rxjs").Observable<IRuleChange>;
35
+ ruleChangeDebounce$: import("rxjs").Observable<IRuleChange>;
20
36
  constructor(_logService: ILogService);
21
37
  private _ensureMap;
22
38
  private _addSubUnitRule;
@@ -1,4 +1,19 @@
1
- import { IUniverDataValidationConfig } from './config/config';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IUniverDataValidationConfig } from './config/config';
2
17
  import { ICommandService, IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
18
  export declare class UniverDataValidationPlugin extends Plugin {
4
19
  private readonly _config;
@@ -1,4 +1,19 @@
1
- import { BaseDataValidator } from '../validators/base-data-validator';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { BaseDataValidator } from '../validators/base-data-validator';
2
17
  export declare enum DataValidatorRegistryScope {
3
18
  SHEET = "sheet"
4
19
  }
@@ -9,10 +24,10 @@ export declare class DataValidatorRegistryService {
9
24
  private _validatorByScopes;
10
25
  private _validatorMap;
11
26
  private _validatorsChange$;
12
- validatorsChange$: import('rxjs').Observable<void>;
27
+ validatorsChange$: import("rxjs").Observable<void>;
13
28
  private _addValidatorToScope;
14
29
  private _removeValidatorFromScope;
15
- register(validator: BaseDataValidator): import('@wendellhu/redi').IDisposable;
30
+ register(validator: BaseDataValidator): import("@wendellhu/redi").IDisposable;
16
31
  getValidatorItem(id: string): BaseDataValidator | undefined;
17
32
  getValidatorsByScope(scope: string): BaseDataValidator[] | undefined;
18
33
  }
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
  import { DataValidationOperator } from '@univerjs/core';
2
17
  export declare const OperatorTextMap: Record<DataValidationOperator, string>;
3
18
  export declare const OperatorTitleMap: Record<DataValidationOperator | 'NONE', string>;
@@ -1,2 +1,17 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
  import { DataValidationOperator } from '@univerjs/core';
2
17
  export declare const TWO_FORMULA_OPERATOR_COUNT: DataValidationOperator[];
@@ -1,4 +1,19 @@
1
- import { DataValidationOperator } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { DataValidationOperator } from '@univerjs/core';
2
17
  export interface IDataValidatorOperatorConfig {
3
18
  operator: DataValidationOperator;
4
19
  text: string;
@@ -1,4 +1,19 @@
1
- import { IFormulaValidResult } from '../../validators/base-data-validator';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IFormulaValidResult } from '../../validators/base-data-validator';
2
17
  export interface IFormulaValue {
3
18
  formula1?: string;
4
19
  formula2?: string;
@@ -1,5 +1,20 @@
1
- import { IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions } from '@univerjs/core';
2
- import { UpdateRuleType } from '../enum/update-rule-type';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions } from '@univerjs/core';
17
+ import type { UpdateRuleType } from '../enum/update-rule-type';
3
18
  export interface IUpdateRuleRangePayload {
4
19
  type: UpdateRuleType.RANGE;
5
20
  payload: any[];
@@ -1,7 +1,23 @@
1
- import { CellValue, IDataValidationRule, IDataValidationRuleBase, IStyleData, Nullable, Workbook, Worksheet, DataValidationOperator, Injector, LocaleService } from '@univerjs/core';
2
- import { CellValueType } from '@univerjs/protocol';
3
- import { ISheetLocationBase } from '@univerjs/sheets';
4
- import { IBaseDataValidationWidget } from './base-widget';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { CellValue, IDataValidationRule, IDataValidationRuleBase, IStyleData, Nullable, Workbook, Worksheet } from '@univerjs/core';
17
+ import type { CellValueType } from '@univerjs/protocol';
18
+ import type { ISheetLocationBase } from '@univerjs/sheets';
19
+ import type { IBaseDataValidationWidget } from './base-widget';
20
+ import { DataValidationOperator, Injector, LocaleService } from '@univerjs/core';
5
21
  export declare const FORMULA1 = "{FORMULA1}";
6
22
  export declare const FORMULA2 = "{FORMULA2}";
7
23
  export declare const TYPE = "{TYPE}";
@@ -1,4 +1,19 @@
1
- import { ICellCustomRender, ICellRenderContext } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ICellCustomRender, ICellRenderContext } from '@univerjs/core';
2
17
  export interface IBaseDataValidationWidget extends ICellCustomRender {
3
18
  calcCellAutoHeight(info: ICellRenderContext): number | undefined;
4
19
  calcCellAutoWidth(info: ICellRenderContext): number | undefined;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(s,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],r):(s=typeof globalThis<"u"?globalThis:s||self,r(s.UniverDataValidation={},s.UniverCore,s.rxjs))})(this,(function(s,r,g){"use strict";var da=Object.defineProperty;var sa=(s,r,g)=>r in s?da(s,r,{enumerable:!0,configurable:!0,writable:!0,value:g}):s[r]=g;var p=(s,r,g)=>sa(s,typeof r!="symbol"?r+"":r,g);var T;function N(n){return{type:n.type,operator:n.operator,formula1:n.formula1,formula2:n.formula2,allowBlank:n.allowBlank}}function M(n){return{error:n.error,errorStyle:n.errorStyle,errorTitle:n.errorTitle,imeMode:n.imeMode,prompt:n.prompt,promptTitle:n.promptTitle,showDropDown:n.showDropDown,showErrorMessage:n.showErrorMessage,showInputMessage:n.showInputMessage,renderMode:n.renderMode,bizInfo:n.bizInfo}}var h=(n=>(n[n.SETTING=0]="SETTING",n[n.RANGE=1]="RANGE",n[n.OPTIONS=2]="OPTIONS",n[n.ALL=3]="ALL",n))(h||{}),q=Object.getOwnPropertyDescriptor,G=(n,a,i,e)=>{for(var t=e>1?void 0:e?q(a,i):a,o=n.length-1,d;o>=0;o--)(d=n[o])&&(t=d(t)||t);return t},$=(n,a)=>(i,e)=>a(i,e,n);s.DataValidationModel=class extends r.Disposable{constructor(i){super();p(this,"_model",new Map);p(this,"_ruleChange$",new g.Subject);p(this,"ruleChange$",this._ruleChange$.asObservable());p(this,"ruleChangeDebounce$",this.ruleChange$.pipe(g.debounceTime(20)));this._logService=i,this.disposeWithMe({dispose:()=>{this._ruleChange$.complete()}})}_ensureMap(i,e){this._model.has(i)||this._model.set(i,new Map);const t=this._model.get(i);if(t.has(e))return t.get(e);const o={map:new Map,list:[]};return t.set(e,o),o}_addSubUnitRule(i,e,t){const{map:o,list:d}=i,c=(Array.isArray(e)?e:[e]).filter(u=>!o.has(u.uid));typeof t=="number"&&t<d.length?d.splice(t,0,...c):d.push(...c),c.forEach(u=>{o.set(u.uid,u)})}_removeSubUnitRule(i,e){const{map:t,list:o}=i,d=o.findIndex(l=>l.uid===e);d>-1&&(o.splice(d,1),t.delete(e))}_updateSubUnitRule(i,e,t){const{map:o,list:d}=i,l=o.get(e),c=d.findIndex(m=>e===m.uid);if(!l)throw new Error(`Data validation rule is not found, ruleId: ${e}.`);const u={...l};switch(t.type){case h.RANGE:{u.ranges=t.payload;break}case h.SETTING:{Object.assign(u,N(t.payload));break}case h.OPTIONS:{Object.assign(u,M(t.payload));break}case h.ALL:{Object.assign(u,t.payload);break}}return d[c]=u,o.set(e,u),u}_addRuleSideEffect(i,e,t,o){if(!this._ensureMap(i,e).map.get(t.uid))return{rule:t,type:"add",unitId:i,subUnitId:e,source:o}}addRule(i,e,t,o,d){try{const l=this._ensureMap(i,e),u=(Array.isArray(t)?t:[t]).map(m=>this._addRuleSideEffect(i,e,m,o));this._addSubUnitRule(l,t,d),u.forEach(m=>{m&&this._ruleChange$.next(m)})}catch(l){this._logService.error(l)}}updateRule(i,e,t,o,d){try{const l=this._ensureMap(i,e),c=r.Tools.deepClone(l.map.get(t));if(!c)throw new Error(`Data validation rule is not found, ruleId: ${t}.`);const u=this._updateSubUnitRule(l,t,o);this._ruleChange$.next({rule:u,type:"update",unitId:i,subUnitId:e,source:d,updatePayload:o,oldRule:c})}catch(l){this._logService.error(l)}}removeRule(i,e,t,o){try{const d=this._ensureMap(i,e),l=d.map.get(t);l&&(this._removeSubUnitRule(d,t),this._ruleChange$.next({rule:l,type:"remove",unitId:i,subUnitId:e,source:o}))}catch(d){this._logService.error(d)}}getRuleById(i,e,t){return this._ensureMap(i,e).map.get(t)}getRuleIndex(i,e,t){return this._ensureMap(i,e).list.findIndex(d=>d.uid===t)}getRules(i,e){return[...this._ensureMap(i,e).list]}getUnitRules(i){const e=this._model.get(i);if(!e)return[];const t=[];return e.forEach((o,d)=>{t.push([d,o.list])}),t}deleteUnitRules(i){this._model.delete(i)}getSubUnitIds(i){var e,t;return Array.from((t=(e=this._model.get(i))==null?void 0:e.keys())!=null?t:[])}getAll(){return Array.from(this._model.keys()).map(i=>[i,this.getUnitRules(i)])}},s.DataValidationModel=G([$(0,r.ILogService)],s.DataValidationModel);const O={type:r.CommandType.MUTATION,id:"data-validation.mutation.addRule",handler(n,a){if(!a)return!1;const{unitId:i,subUnitId:e,rule:t,index:o,source:d="command"}=a;return n.get(s.DataValidationModel).addRule(i,e,t,d,o),!0}},_={type:r.CommandType.MUTATION,id:"data-validation.mutation.removeRule",handler(n,a){if(!a)return!1;const{unitId:i,subUnitId:e,ruleId:t,source:o="command"}=a,d=n.get(s.DataValidationModel);return Array.isArray(t)?t.forEach(l=>{d.removeRule(i,e,l,o)}):d.removeRule(i,e,t,o),!0}},v={type:r.CommandType.MUTATION,id:"data-validation.mutation.updateRule",handler(n,a){if(!a)return!1;const{unitId:i,subUnitId:e,ruleId:t,payload:o,source:d="command"}=a;return n.get(s.DataValidationModel).updateRule(i,e,t,o,d),!0}};var H=Object.getOwnPropertyDescriptor,Q=(n,a,i,e)=>{for(var t=e>1?void 0:e?H(a,i):a,o=n.length-1,d;o>=0;o--)(d=n[o])&&(t=d(t)||t);return t},D=(n,a)=>(i,e)=>a(i,e,n);const F="SHEET_DATA_VALIDATION_PLUGIN";s.DataValidationResourceController=class extends r.Disposable{constructor(a,i,e){super(),this._resourceManagerService=a,this._univerInstanceService=i,this._dataValidationModel=e,this._initSnapshot()}_initSnapshot(){const a=e=>{const t=this._dataValidationModel.getUnitRules(e),o={};return t?(t.forEach(([d,l])=>{o[d]=l}),JSON.stringify(o)):""},i=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:F,businesses:[r.UniverInstanceType.UNIVER_SHEET],toJson:e=>a(e),parseJson:e=>i(e),onUnLoad:e=>{this._dataValidationModel.deleteUnitRules(e)},onLoad:(e,t)=>{Object.keys(t).forEach(o=>{t[o].forEach(l=>{this._dataValidationModel.addRule(e,o,l,"patched")})})}}))}},s.DataValidationResourceController=Q([D(0,r.IResourceManagerService),D(1,r.IUniverInstanceService),D(2,r.Inject(s.DataValidationModel))],s.DataValidationResourceController);const L={name:"@univerjs/data-validation",version:"0.17.0"};var C=(n=>(n.SHEET="sheet",n))(C||{});class R{constructor(){p(this,"_validatorByScopes",new Map);p(this,"_validatorMap",new Map);p(this,"_validatorsChange$",new g.BehaviorSubject(void 0));p(this,"validatorsChange$",this._validatorsChange$.asObservable())}_addValidatorToScope(a,i){this._validatorByScopes.has(i)||this._validatorByScopes.set(i,[]);const e=this._validatorByScopes.get(i);if(e.findIndex(t=>t.id===a.id)>-1)throw new Error(`Validator item with the same id ${a.id} has already been added!`);e.push(a)}_removeValidatorFromScope(a,i){const e=this._validatorByScopes.get(i);if(!e)return;const t=e.findIndex(o=>o.id===a.id);t>-1&&e.splice(t,1)}register(a){return this._validatorMap.set(a.id,a),Array.isArray(a.scopes)?a.scopes.forEach(i=>{this._addValidatorToScope(a,i)}):this._addValidatorToScope(a,a.scopes),this._validatorsChange$.next(),r.toDisposable(()=>{this._validatorMap.delete(a.id),Array.isArray(a.scopes)?a.scopes.forEach(i=>{this._removeValidatorFromScope(a,i)}):this._removeValidatorFromScope(a,a.scopes),this._validatorsChange$.next()})}getValidatorItem(a){return this._validatorMap.get(a)}getValidatorsByScope(a){return this._validatorByScopes.get(a)}}const W={type:r.CommandType.COMMAND,id:"data-validation.command.addRule",async handler(n,a){if(n.get(r.ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{rule:e,unitId:t,subUnitId:o}=a,d=n.get(r.ICommandService),l=n.get(r.IUndoRedoService),c={...a,rule:{...a.rule,ranges:[a.rule.range]}},u=[{id:O.id,params:c}],m=[{id:_.id,params:{unitId:t,subUnitId:o,ruleId:e.uid}}];return l.pushUndoRedo({unitID:t,redoMutations:u,undoMutations:m}),await d.executeCommand(O.id,c),!0}},k={type:r.CommandType.COMMAND,id:"data-validation.command.removeRule",handler(n,a){if(n.get(r.ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{unitId:e,subUnitId:t,ruleId:o}=a,d=n.get(r.ICommandService),l=n.get(r.IUndoRedoService),c=n.get(s.DataValidationModel),u=[{id:_.id,params:a}],m=[{id:O.id,params:{unitId:e,subUnitId:t,rule:{...c.getRuleById(e,t,o)},index:c.getRuleIndex(e,t,o)}}];return l.pushUndoRedo({undoMutations:m,redoMutations:u,unitID:a.unitId}),d.executeCommand(_.id,a),!0}},J={type:r.CommandType.COMMAND,id:"data-validation.command.updateDataValidationSetting",handler(n,a){if(n.get(r.ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const e=n.get(r.ICommandService),t=n.get(r.IUndoRedoService),o=n.get(s.DataValidationModel),{unitId:d,subUnitId:l,ruleId:c,options:u}=a,m=o.getRuleById(d,l,c);if(!m)return!1;const E={unitId:d,subUnitId:l,ruleId:c,payload:{type:h.OPTIONS,payload:u}},V=[{id:v.id,params:E}],S={unitId:d,subUnitId:l,ruleId:c,payload:{type:h.OPTIONS,payload:M(m)}},f=[{id:v.id,params:S}];return t.pushUndoRedo({unitID:d,redoMutations:V,undoMutations:f}),e.executeCommand(v.id,E),!0}},x={type:r.CommandType.COMMAND,id:"data-validation.command.updateDataValidationOptions",handler(n,a){if(n.get(r.ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const e=n.get(r.ICommandService),t=n.get(r.IUndoRedoService),o=n.get(s.DataValidationModel),d=n.get(R),{unitId:l,subUnitId:c,ruleId:u,setting:m}=a,E=d.getValidatorItem(m.type);if(!E)return!1;const V=o.getRuleById(l,c,u);if(!V)return!1;const S={...V,...m};if(!E.validatorFormula(S,l,c).success)return!1;const f={unitId:l,subUnitId:c,ruleId:u,payload:{type:h.SETTING,payload:{...m,...E.normalizeFormula(S,l,c)}}},ra=[{id:v.id,params:f}],na={unitId:l,subUnitId:c,ruleId:u,payload:{type:h.SETTING,payload:N(V)}},oa=[{id:v.id,params:na}];return t.pushUndoRedo({unitID:l,redoMutations:ra,undoMutations:oa}),e.executeCommand(v.id,f),!0}},z={type:r.CommandType.COMMAND,id:"data-validation.command.removeAll",handler(n,a){if(n.get(r.ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{unitId:e,subUnitId:t}=a,o=n.get(r.ICommandService),d=n.get(s.DataValidationModel),l=n.get(r.IUndoRedoService),c=[...d.getRules(e,t)],u={unitId:e,subUnitId:t,ruleId:c.map(V=>V.uid)},m=[{id:_.id,params:u}],E=[{id:O.id,params:{unitId:e,subUnitId:t,rule:c}}];return l.pushUndoRedo({redoMutations:m,undoMutations:E,unitID:e}),o.executeCommand(_.id,u),!0}},Y="data-validation.config",b={};var K=Object.getOwnPropertyDescriptor,X=(n,a,i,e)=>{for(var t=e>1?void 0:e?K(a,i):a,o=n.length-1,d;o>=0;o--)(d=n[o])&&(t=d(t)||t);return t},A=(n,a)=>(i,e)=>a(i,e,n);s.UniverDataValidationPlugin=(T=class extends r.Plugin{constructor(a=b,i,e,t){super(),this._config=a,this._injector=i,this._commandService=e,this._configService=t;const{...o}=r.merge({},b,this._config);this._configService.setConfig(Y,o)}onStarting(){[[s.DataValidationModel],[R],[s.DataValidationResourceController]].forEach(a=>this._injector.add(a)),[W,z,J,x,k,O,v,_].forEach(a=>{this._commandService.registerCommand(a)})}onReady(){this._injector.get(s.DataValidationResourceController)}},p(T,"pluginName","UNIVER_DATA_VALIDATION_PLUGIN"),p(T,"packageName",L.name),p(T,"version",L.version),p(T,"type",r.UniverInstanceType.UNIVER_SHEET),T),s.UniverDataValidationPlugin=X([A(1,r.Inject(r.Injector)),A(2,r.ICommandService),A(3,r.IConfigService)],s.UniverDataValidationPlugin),r.DataValidationOperator.BETWEEN+"",r.DataValidationOperator.EQUAL+"",r.DataValidationOperator.GREATER_THAN+"",r.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",r.DataValidationOperator.LESS_THAN+"",r.DataValidationOperator.LESS_THAN_OR_EQUAL+"",r.DataValidationOperator.NOT_BETWEEN+"",r.DataValidationOperator.NOT_EQUAL+"";const w={[r.DataValidationOperator.BETWEEN]:"dataValidation.ruleName.between",[r.DataValidationOperator.EQUAL]:"dataValidation.ruleName.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.ruleName.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.ruleName.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.ruleName.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.ruleName.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.ruleName.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.ruleName.notEqual",NONE:"dataValidation.ruleName.legal"},B={[r.DataValidationOperator.BETWEEN]:"dataValidation.errorMsg.between",[r.DataValidationOperator.EQUAL]:"dataValidation.errorMsg.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.errorMsg.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.errorMsg.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.errorMsg.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.errorMsg.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.errorMsg.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.errorMsg.notEqual",NONE:"dataValidation.errorMsg.legal"},Z={[r.DataValidationOperator.BETWEEN]:"dataValidation.textLength.errorMsg.between",[r.DataValidationOperator.EQUAL]:"dataValidation.textLength.errorMsg.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.textLength.errorMsg.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.textLength.errorMsg.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.textLength.errorMsg.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.textLength.errorMsg.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.textLength.errorMsg.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.textLength.errorMsg.notEqual"},aa=[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.NOT_BETWEEN];var ta=Object.getOwnPropertyDescriptor,ea=(n,a,i,e)=>{for(var t=e>1?void 0:e?ta(a,i):a,o=n.length-1,d;o>=0;o--)(d=n[o])&&(t=d(t)||t);return t},P=(n,a)=>(i,e)=>a(i,e,n);const I="{FORMULA1}",y="{FORMULA2}",U="{TYPE}",ia={[r.DataValidationOperator.BETWEEN]:"dataValidation.operators.between",[r.DataValidationOperator.EQUAL]:"dataValidation.operators.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.operators.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.operators.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.operators.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.operators.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.operators.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.operators.notEqual"};var j=(n=>(n.DATE="date",n.TIME="time",n.DATETIME="datetime",n.LIST="list",n.MULTIPLE_LIST="multipleList",n.COLOR="color",n.CASCADE="cascade",n))(j||{});s.BaseDataValidator=class{constructor(a,i){p(this,"offsetFormulaByRange",!0);p(this,"formulaInput");p(this,"canvasRender",null);p(this,"dropdownType");p(this,"optionsInput");p(this,"skipDefaultFontRender");this.localeService=a,this.injector=i}get operatorNames(){return this.operators.map(a=>this.localeService.t(ia[a]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(a){var e,t;if(!a.operator)return this.localeService.t(w.NONE).replace(U,this.titleStr);const i=this.localeService.t(w[a.operator]).replace(I,(e=a.formula1)!=null?e:"").replace(y,(t=a.formula2)!=null?t:"");return`${this.titleStr} ${i}`}generateRuleErrorMessage(a,i){var t,o;return a.operator?`${this.localeService.t(B[a.operator]).replace(I,(t=a.formula1)!=null?t:"").replace(y,(o=a.formula2)!=null?o:"")}`:this.localeService.t(B.NONE).replace(U,this.titleStr)}getExtraStyle(a,i,e,t,o){}getRuleFinalError(a,i){return a.showErrorMessage&&a.error?a.error:this.generateRuleErrorMessage(a,i)}isEmptyCellValue(a){return a===""||a===void 0||a===null}normalizeFormula(a,i,e){return{formula1:a.formula1,formula2:a.formula2}}async isValidType(a,i,e){return!0}transform(a,i,e){return a}async validatorIsEqual(a,i,e){const{formula1:t}=i,{value:o}=a;return Number.isNaN(t)?!0:o===t}async validatorIsNotEqual(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value!==t}async validatorIsBetween(a,i,e){const{formula1:t,formula2:o}=i;if(Number.isNaN(t)||Number.isNaN(o))return!0;const d=Math.min(t,o),l=Math.max(t,o);return a.value>=d&&a.value<=l}async validatorIsNotBetween(a,i,e){const{formula1:t,formula2:o}=i;if(Number.isNaN(t)||Number.isNaN(o))return!0;const d=Math.min(t,o),l=Math.max(t,o);return a.value<d||a.value>l}async validatorIsGreaterThan(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value>t}async validatorIsGreaterThanOrEqual(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value>=t}async validatorIsLessThan(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value<t}async validatorIsLessThanOrEqual(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value<=t}async validator(a,i){const{value:e,unitId:t,subUnitId:o}=a,d=this.isEmptyCellValue(e),{allowBlank:l=!0,operator:c}=i;if(d)return l;const u=await this.parseFormula(i,t,o,a.row,a.column);if(!u.isFormulaValid||!await this.isValidType(a,u,i))return!1;if(!c)return!0;const m=this.transform(a,u,i);switch(c){case r.DataValidationOperator.BETWEEN:return this.validatorIsBetween(m,u,i);case r.DataValidationOperator.EQUAL:return this.validatorIsEqual(m,u,i);case r.DataValidationOperator.GREATER_THAN:return this.validatorIsGreaterThan(m,u,i);case r.DataValidationOperator.GREATER_THAN_OR_EQUAL:return this.validatorIsGreaterThanOrEqual(m,u,i);case r.DataValidationOperator.LESS_THAN:return this.validatorIsLessThan(m,u,i);case r.DataValidationOperator.LESS_THAN_OR_EQUAL:return this.validatorIsLessThanOrEqual(m,u,i);case r.DataValidationOperator.NOT_BETWEEN:return this.validatorIsNotBetween(m,u,i);case r.DataValidationOperator.NOT_EQUAL:return this.validatorIsNotEqual(m,u,i);default:throw new Error("Unknown operator.")}}},s.BaseDataValidator=ea([P(0,r.Inject(r.LocaleService)),P(1,r.Inject(r.Injector))],s.BaseDataValidator),s.AddDataValidationMutation=O,s.DataValidatorDropdownType=j,s.DataValidatorRegistryScope=C,s.DataValidatorRegistryService=R,s.FORMULA1=I,s.FORMULA2=y,s.RemoveDataValidationMutation=_,s.TWO_FORMULA_OPERATOR_COUNT=aa,s.TYPE=U,s.TextLengthErrorTitleMap=Z,s.UpdateDataValidationMutation=v,s.UpdateRuleType=h,s.getRuleOptions=M,s.getRuleSetting=N,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
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:o,list:s}=e,c=o.get(t),l=s.findIndex(e=>t===e.uid);if(!c)throw Error(`Data validation rule is not found, ruleId: ${t}.`);let u={...c};switch(n.type){case a.RANGE:u.ranges=n.payload;break;case a.SETTING:Object.assign(u,r(n.payload));break;case a.OPTIONS:Object.assign(u,i(n.payload));break;case a.ALL:Object.assign(u,n.payload);break;default:break}return s[l]=u,o.set(t,u),u}_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=`0.18.0`;let y=function(e){return e.SHEET=`sheet`,e}({});var b=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 x={type:t.CommandType.COMMAND,id:`data-validation.command.addRule`,async handler(e,n){if(e.get(t.ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!n)return!1;let{rule:r,unitId:i,subUnitId:a}=n,o=e.get(t.ICommandService),s=e.get(t.IUndoRedoService),c={...n,rule:{...n.rule,ranges:[n.rule.range]}},l=[{id:p.id,params:c}],u=[{id:m.id,params:{unitId:i,subUnitId:a,ruleId:r.uid}}];return s.pushUndoRedo({unitID:i,redoMutations:l,undoMutations:u}),await o.executeCommand(p.id,c),!0}},S={type:t.CommandType.COMMAND,id:`data-validation.command.removeRule`,handler(e,n){if(e.get(t.ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!n)return!1;let{unitId:r,subUnitId:i,ruleId:a}=n,o=e.get(t.ICommandService),s=e.get(t.IUndoRedoService),c=e.get(f),l=[{id:m.id,params:n}],u=[{id:p.id,params:{unitId:r,subUnitId:i,rule:{...c.getRuleById(r,i,a)},index:c.getRuleIndex(r,i,a)}}];return s.pushUndoRedo({undoMutations:u,redoMutations:l,unitID:n.unitId}),o.executeCommand(m.id,n),!0}},C={type:t.CommandType.COMMAND,id:`data-validation.command.updateDataValidationSetting`,handler(e,n){if(e.get(t.ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"),!n)return!1;let r=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(f),{unitId:c,subUnitId:l,ruleId:u,options:d}=n,p=s.getRuleById(c,l,u);if(!p)return!1;let m={unitId:c,subUnitId:l,ruleId:u,payload:{type:a.OPTIONS,payload:d}},g=[{id:h.id,params:m}],_={unitId:c,subUnitId:l,ruleId:u,payload:{type:a.OPTIONS,payload:i(p)}},v=[{id:h.id,params:_}];return o.pushUndoRedo({unitID:c,redoMutations:g,undoMutations:v}),r.executeCommand(h.id,m),!0}},w={type:t.CommandType.COMMAND,id:`data-validation.command.updateDataValidationOptions`,handler(e,n){if(e.get(t.ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"),!n)return!1;let i=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(f),c=e.get(b),{unitId:l,subUnitId:u,ruleId:d,setting:p}=n,m=c.getValidatorItem(p.type);if(!m)return!1;let g=s.getRuleById(l,u,d);if(!g)return!1;let _={...g,...p};if(!m.validatorFormula(_,l,u).success)return!1;let v={unitId:l,subUnitId:u,ruleId:d,payload:{type:a.SETTING,payload:{...p,...m.normalizeFormula(_,l,u)}}},y=[{id:h.id,params:v}],x={unitId:l,subUnitId:u,ruleId:d,payload:{type:a.SETTING,payload:r(g)}},S=[{id:h.id,params:x}];return o.pushUndoRedo({unitID:l,redoMutations:y,undoMutations:S}),i.executeCommand(h.id,v),!0}},T={type:t.CommandType.COMMAND,id:`data-validation.command.removeAll`,handler(e,n){if(e.get(t.ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!n)return!1;let{unitId:r,subUnitId:i}=n,a=e.get(t.ICommandService),o=e.get(f),s=e.get(t.IUndoRedoService),c=[...o.getRules(r,i)],l={unitId:r,subUnitId:i,ruleId:c.map(e=>e.uid)},u=[{id:m.id,params:l}],d=[{id:p.id,params:{unitId:r,subUnitId:i,rule:c}}];return s.pushUndoRedo({redoMutations:u,undoMutations:d,unitID:r}),a.executeCommand(m.id,l),!0}},E=`data-validation.config`;Symbol(E);let D={},O=class extends t.Plugin{constructor(e=D,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},D,this._config);this._configService.setConfig(E,a)}onStarting(){[[f],[b],[g]].forEach(e=>this._injector.add(e)),[x,T,C,w,S,p,h,m].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(g)}};l(O,`pluginName`,`UNIVER_DATA_VALIDATION_PLUGIN`),l(O,`packageName`,_),l(O,`version`,v),l(O,`type`,t.UniverInstanceType.UNIVER_SHEET),O=d([u(1,(0,t.Inject)(t.Injector)),u(2,t.ICommandService),u(3,t.IConfigService)],O),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 k={[t.DataValidationOperator.BETWEEN]:`dataValidation.ruleName.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.ruleName.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.ruleName.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.ruleName.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.ruleName.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.ruleName.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.ruleName.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.ruleName.notEqual`,NONE:`dataValidation.ruleName.legal`},A={[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`},j={[t.DataValidationOperator.BETWEEN]:`dataValidation.textLength.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.textLength.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.textLength.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.textLength.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.textLength.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.textLength.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.textLength.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.textLength.errorMsg.notEqual`},M=[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.NOT_BETWEEN],N=`{FORMULA1}`,P=`{FORMULA2}`,F=`{TYPE}`,I={[t.DataValidationOperator.BETWEEN]:`dataValidation.operators.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.operators.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.operators.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.operators.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.operators.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.operators.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.operators.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.operators.notEqual`},L=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}({}),R=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(I[e]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(e){var t,n;if(!e.operator)return this.localeService.t(k.NONE).replace(F,this.titleStr);let r=this.localeService.t(k[e.operator]).replace(N,(t=e.formula1)==null?``:t).replace(P,(n=e.formula2)==null?``:n);return`${this.titleStr} ${r}`}generateRuleErrorMessage(e,t){var n,r;return e.operator?`${this.localeService.t(A[e.operator]).replace(N,(n=e.formula1)==null?``:n).replace(P,(r=e.formula2)==null?``:r)}`:this.localeService.t(A.NONE).replace(F,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.`)}}};R=d([u(0,(0,t.Inject)(t.LocaleService)),u(1,(0,t.Inject)(t.Injector))],R),e.AddDataValidationMutation=p,Object.defineProperty(e,`BaseDataValidator`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(e,`DataValidationModel`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,`DataValidationResourceController`,{enumerable:!0,get:function(){return g}}),e.DataValidatorDropdownType=L,e.DataValidatorRegistryScope=y,e.DataValidatorRegistryService=b,e.FORMULA1=N,e.FORMULA2=P,e.RemoveDataValidationMutation=m,e.TWO_FORMULA_OPERATOR_COUNT=M,e.TYPE=F,e.TextLengthErrorTitleMap=j,Object.defineProperty(e,`UniverDataValidationPlugin`,{enumerable:!0,get:function(){return O}}),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": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "private": false,
5
5
  "description": "Data validation library for Univer",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -48,24 +48,24 @@
48
48
  "rxjs": ">=7.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@univerjs/core": "0.17.0"
51
+ "@univerjs/core": "0.18.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@univerjs/protocol": "0.1.48",
55
55
  "rxjs": "^7.8.2",
56
56
  "typescript": "^5.9.3",
57
- "vite": "^7.3.1",
58
- "vitest": "^4.0.18",
59
- "@univerjs-infra/shared": "0.17.0",
60
- "@univerjs/core": "0.17.0",
61
- "@univerjs/sheets": "0.17.0"
57
+ "vitest": "^4.1.0",
58
+ "@univerjs-infra/shared": "0.18.0",
59
+ "@univerjs/sheets": "0.18.0"
62
60
  },
63
61
  "scripts": {
64
62
  "dev": "vite",
65
63
  "test": "vitest run",
66
64
  "test:watch": "vitest",
67
65
  "coverage": "vitest run --coverage",
68
- "build": "univer-cli build"
66
+ "build:bundle": "univer-cli build",
67
+ "build:types": "tsc -p tsconfig.node.json",
68
+ "build": "pnpm run build:bundle && pnpm run build:types"
69
69
  },
70
70
  "module": "./lib/es/index.js"
71
71
  }