@univerjs/preset-sheets-data-validation 0.17.0 → 0.19.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/index.css +1 -1
- package/lib/umd/index.js +4 -12
- package/lib/umd/locales/ca-ES.js +1 -2
- package/lib/umd/locales/en-US.js +1 -2
- package/lib/umd/locales/es-ES.js +1 -2
- package/lib/umd/locales/fa-IR.js +1 -2
- package/lib/umd/locales/fr-FR.js +1 -2
- package/lib/umd/locales/ja-JP.js +1 -2
- package/lib/umd/locales/ko-KR.js +1 -2
- package/lib/umd/locales/ru-RU.js +1 -2
- package/lib/umd/locales/sk-SK.js +1 -2
- package/lib/umd/locales/vi-VN.js +1 -2
- package/lib/umd/locales/zh-CN.js +1 -2
- package/lib/umd/locales/zh-TW.js +1 -2
- package/package.json +6 -6
package/lib/umd/index.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
// @univerjs/data-validation/index
|
|
2
|
-
(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"})}));
|
|
3
|
-
|
|
2
|
+
(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.19.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});
|
|
4
3
|
|
|
5
4
|
// @univerjs/sheets-data-validation/index
|
|
6
|
-
(function(m,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/sheets-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/sheets","rxjs","@univerjs/sheets-formula"],r):(m=typeof globalThis<"u"?globalThis:m||self,r(m.UniverSheetsDataValidation={},m.UniverCore,m.UniverDataValidation,m.UniverEngineFormula,m.UniverSheets,m.rxjs,m.UniverSheetsFormula))})(this,(function(m,r,p,E,D,U,de){"use strict";var Ut=Object.defineProperty;var wt=(m,r,p)=>r in m?Ut(m,r,{enumerable:!0,configurable:!0,writable:!0,value:p}):m[r]=p;var S=(m,r,p)=>wt(m,typeof r!="symbol"?r+"":r,p);var We=Object.getOwnPropertyDescriptor,$e=(o,s,e,t)=>{for(var a=t>1?void 0:t?We(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},ce=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCacheService=class extends r.Disposable{constructor(e,t,a){super();S(this,"_cacheMatrix",new Map);S(this,"_dirtyRanges$",new U.Subject);S(this,"dirtyRanges$",this._dirtyRanges$.asObservable());this._commandService=e,this._univerInstanceService=t,this._sheetDataValidationModel=a,this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{if(e.id===D.SetRangeValuesMutation.id&&!(t!=null&&t.onlyLocal)){const{cellValue:a,unitId:i,subUnitId:n}=e.params;if(a){const l=new r.ObjectMatrix(a).getDataRange();if(l.endRow===-1)return;const c=this._sheetDataValidationModel.getRules(i,n).map(h=>h.ranges).flat().map(h=>r.getIntersectRange(h,l)).filter(Boolean);c.length&&this.markRangeDirty(i,n,c,!0)}}}))}_initSheetRemove(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t;if(e.id===D.RemoveSheetMutation.id){const{unitId:a,subUnitId:i}=e.params;(t=this._cacheMatrix.get(a))==null||t.delete(i)}})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{e.type===r.UniverInstanceType.UNIVER_SHEET&&this._cacheMatrix.delete(e.getUnitId())}))}_ensureCache(e,t){let a=this._cacheMatrix.get(e);a||(a=new Map,this._cacheMatrix.set(e,a));let i=a.get(t);return i||(i=new r.ObjectMatrix,a.set(t,i)),i}ensureCache(e,t){return this._ensureCache(e,t)}addRule(e,t,a){this.markRangeDirty(e,t,a.ranges)}removeRule(e,t,a){this._deleteRange(e,t,a.ranges)}markRangeDirty(e,t,a,i){const n=this._ensureCache(e,t);a.forEach(l=>{r.Range.foreach(l,(u,d)=>{n.getValue(u,d)!==void 0&&n.setValue(u,d,void 0)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a,isSetRange:i})}_deleteRange(e,t,a){const i=this._ensureCache(e,t);a.forEach(n=>{r.Range.foreach(n,(l,u)=>{i.realDeleteValue(l,u)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a})}getValue(e,t,a,i){return this._ensureCache(e,t).getValue(a,i)}},m.DataValidationCacheService=$e([ce(0,r.Inject(r.ICommandService)),ce(1,r.Inject(r.IUniverInstanceService)),ce(2,r.Inject(p.DataValidationModel))],m.DataValidationCacheService);function w(o){var s,e;return(e=(s=o==null?void 0:o[0])==null?void 0:s[0])==null?void 0:e.v}function P(o){var s;return(s=o==null?void 0:o[0])==null?void 0:s[0]}function y(o){return!E.ERROR_TYPE_SET.has(o)}function H(o,s){var t;const e=s.getValidatorItem(o);return(t=e==null?void 0:e.offsetFormulaByRange)!=null?t:!1}var ke=Object.getOwnPropertyDescriptor,qe=(o,s,e,t)=>{for(var a=t>1?void 0:t?ke(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},W=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCustomFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();S(this,"_ruleFormulaMap",new Map);S(this,"_ruleFormulaMap2",new Map);this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=a,this._dataValidationCacheService=i,this._validatorRegistryService=n,this._initFormulaResultHandler(),this._initDirtyRanges()}dispose(){super.dispose(),this._ruleFormulaMap.clear(),this._ruleFormulaMap2.clear()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(const t in e){const a=e[t];if(this._instanceSrv.getUnitType(t)===r.UniverInstanceType.UNIVER_SHEET)for(const n in a){const l=a[n],{ruleFormulaMap:u}=this._ensureMaps(t,n);l.forEach(d=>{var g,f;const c=u.get((g=d.extra)==null?void 0:g.ruleId),h=this._dataValidationModel.getRuleById(t,n,(f=d.extra)==null?void 0:f.ruleId);h&&c&&this._dataValidationCacheService.markRangeDirty(t,n,h.ranges)})}}}))}_ensureMaps(e,t){let a=this._ruleFormulaMap.get(e),i=this._ruleFormulaMap2.get(e);a||(a=new Map,this._ruleFormulaMap.set(e,a)),i||(i=new Map,this._ruleFormulaMap2.set(e,i));let n=a.get(t);n||(n=new Map,a.set(t,n));let l=i.get(t);return l||(l=new Map,i.set(t,l)),{ruleFormulaMap:n,ruleFormulaMap2:l}}_registerFormula(e,t,a,i,n){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,i,n,{ruleId:a},E.OtherFormulaBizType.DATA_VALIDATION_CUSTOM,a)}_handleDirtyRanges(e,t,a){this._dataValidationModel.getRules(e,t).forEach(n=>{const l=n.ranges;r.Rectangle.doAnyRangesIntersect(l,a)&&this.makeRuleDirty(e,t,n.uid)})}_initDirtyRanges(){this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.subscribe(e=>{e.isSetRange&&this._handleDirtyRanges(e.unitId,e.subUnitId,e.ranges)}))}deleteByRuleId(e,t,a){const{ruleFormulaMap:i,ruleFormulaMap2:n}=this._ensureMaps(e,t),l=this._dataValidationModel.getRuleById(e,t,a),u=i.get(a);if(!l||!u)return;const d=i.get(a);d&&(i.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[d.formulaId]));const c=n.get(a);c&&(n.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[c.formulaId]))}_addFormulaByRange(e,t,a,i,n,l){const{ruleFormulaMap:u,ruleFormulaMap2:d}=this._ensureMaps(e,t),c=l[0].startRow,h=l[0].startColumn;if(i&&r.isFormulaString(i)){const g=this._registerFormula(e,t,a,i,l);u.set(a,{formula:i,originCol:h,originRow:c,formulaId:g})}if(n&&r.isFormulaString(n)){const g=this._registerFormula(e,t,a,n,l);d.set(a,{formula:n,originCol:h,originRow:c,formulaId:g})}}addRule(e,t,a){if(H(a.type,this._validatorRegistryService)){const{ranges:i,formula1:n,formula2:l,uid:u}=a;this._addFormulaByRange(e,t,u,n,l,i)}}async getCellFormulaValue(e,t,a,i,n){var _,R;const{ruleFormulaMap:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return Promise.resolve(void 0);const d=await this._registerOtherFormulaService.getFormulaValue(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,f=n-h;return P((R=(_=d==null?void 0:d.result)==null?void 0:_[g])==null?void 0:R[f])}async getCellFormula2Value(e,t,a,i,n){var _,R;const{ruleFormulaMap2:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return Promise.resolve(void 0);const d=await this._registerOtherFormulaService.getFormulaValue(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,f=n-h;return P((R=(_=d==null?void 0:d.result)==null?void 0:_[g])==null?void 0:R[f])}getCellFormulaValueSync(e,t,a,i,n){var _,R;const{ruleFormulaMap:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return;const d=this._registerOtherFormulaService.getFormulaValueSync(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,f=n-h;return P((R=(_=d==null?void 0:d.result)==null?void 0:_[g])==null?void 0:R[f])}getCellFormula2ValueSync(e,t,a,i,n){var _,R;const{ruleFormulaMap2:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return;const d=this._registerOtherFormulaService.getFormulaValueSync(e,t,u.formulaId),{originRow:c,originCol:h}=u,g=i-c,f=n-h;return P((R=(_=d==null?void 0:d.result)==null?void 0:_[g])==null?void 0:R[f])}getRuleFormulaInfo(e,t,a){const{ruleFormulaMap:i}=this._ensureMaps(e,t);return i.get(a)}makeRuleDirty(e,t,a){var l,u,d,c;const i=(u=(l=this._ruleFormulaMap.get(e))==null?void 0:l.get(t))==null?void 0:u.get(a),n=(c=(d=this._ruleFormulaMap2.get(e))==null?void 0:d.get(t))==null?void 0:c.get(a);i&&this._registerOtherFormulaService.markFormulaDirty(e,t,i.formulaId),n&&this._registerOtherFormulaService.markFormulaDirty(e,t,n.formulaId)}},m.DataValidationCustomFormulaService=qe([W(0,r.IUniverInstanceService),W(1,r.Inject(E.RegisterOtherFormulaService)),W(2,r.Inject(p.DataValidationModel)),W(3,r.Inject(m.DataValidationCacheService)),W(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationCustomFormulaService);function N(o){return r.getOriginCellValue(o)}function Ve(o){var s;return String((s=N(o))!=null?s:"")}function Qe(o){return o.filter(Boolean).join(",")}function $(o){return o.split(",").filter(Boolean)}function xe(o){const s=N(o);return s==null?"":s.toString()}function k(o,s,e){const{formula1:t,formula2:a}=s,i=s.ranges[0].startRow,n=s.ranges[0].startColumn,l=e.row-i,u=e.col-n,d=r.isFormulaString(t)?o.moveFormulaRefOffset(t,u,l,!0):t,c=r.isFormulaString(a)?o.moveFormulaRefOffset(a,u,l,!0):a;return{transformedFormula1:d,transformedFormula2:c}}var Ge=Object.getOwnPropertyDescriptor,Ye=(o,s,e,t)=>{for(var a=t>1?void 0:t?Ge(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},De=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationListCacheService=class extends r.Disposable{constructor(e,t){super();S(this,"_cache",new Map);this._injector=e,this._dataValidationModel=t,this._initRuleChangeListener()}_initRuleChangeListener(){this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{(e.type==="remove"||e.type==="update")&&this.markRuleDirty(e.unitId,e.subUnitId,e.rule.uid)}))}getOrCompute(e,t,a){const i=this.getCache(e,t,a.uid);if(i)return i;const l=this._injector.get(m.DataValidationFormulaService).getRuleFormulaResultSync(e,t,a.uid);return this.computeAndCache(e,t,a,l)}_ensureCache(e,t){let a=this._cache.get(e);a||(a=new Map,this._cache.set(e,a));let i=a.get(t);return i||(i=new Map,a.set(t,i)),i}getCache(e,t,a){var i,n;return(n=(i=this._cache.get(e))==null?void 0:i.get(t))==null?void 0:n.get(a)}setCache(e,t,a,i){this._ensureCache(e,t).set(a,i)}markRuleDirty(e,t,a){var i,n;(n=(i=this._cache.get(e))==null?void 0:i.get(t))==null||n.delete(a)}clear(){this._cache.clear()}computeAndCache(e,t,a,i){var _,R,V;const{formula1:n="",formula2:l=""}=a,u=r.isFormulaString(n)?this._getRuleFormulaResultSet((V=(R=(_=i==null?void 0:i[0])==null?void 0:_.result)==null?void 0:R[0])==null?void 0:V[0]):$(n),d=l.split(","),c=u.map((v,M)=>({label:v,color:d[M]||""})),h={};for(const v of c)v.color&&(h[v.label]=v.color);const g=new Set(u),f={list:u,listWithColor:c,colorMap:h,set:g};return this.setCache(e,t,a.uid,f),f}_getRuleFormulaResultSet(e){var a,i;if(!e)return[];const t=new Set;for(let n=0,l=e.length;n<l;n++){const u=e[n];if(u)for(let d=0,c=u.length;d<c;d++){const h=u[d],g=N(h);if(g!=null){if(typeof g!="string"&&typeof(h==null?void 0:h.s)=="object"&&((i=(a=h.s)==null?void 0:a.n)!=null&&i.pattern)){t.add(r.numfmt.format(h.s.n.pattern,g,{throws:!1}));continue}const f=typeof g=="string"?g:String(g);y(f)&&t.add(f)}}}return[...t]}},m.DataValidationListCacheService=Ye([De(0,r.Inject(r.Injector)),De(1,r.Inject(p.DataValidationModel))],m.DataValidationListCacheService);var Xe=Object.getOwnPropertyDescriptor,Ke=(o,s,e,t)=>{for(var a=t>1?void 0:t?Xe(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},L=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaService=class extends r.Disposable{constructor(e,t,a,i,n,l){super();S(this,"_formulaRuleMap",new Map);this._instanceService=e,this._registerOtherFormulaService=t,this._dataValidationCacheService=a,this._dataValidationModel=i,this._validatorRegistryService=n,this._listCacheService=l,this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(const t in e){const a=e[t];if(this._instanceService.getUnitType(t)===r.UniverInstanceType.UNIVER_SHEET)for(const n in a){const l=a[n],u=this._ensureRuleFormulaMap(t,n);l.forEach(d=>{var h;const c=(h=d.extra)==null?void 0:h.ruleId;if(c&&u.get(c)){const g=this._dataValidationModel.getRuleById(t,n,c);g&&(this._listCacheService.markRuleDirty(t,n,c),this._dataValidationCacheService.markRangeDirty(t,n,g.ranges))}})}}}))}_ensureRuleFormulaMap(e,t){let a=this._formulaRuleMap.get(e);a||(a=new Map,this._formulaRuleMap.set(e,a));let i=a.get(t);return i||(i=new Map,a.set(t,i)),i}_registerSingleFormula(e,t,a,i){const n=[{startColumn:0,endColumn:0,startRow:0,endRow:0}];return this._registerOtherFormulaService.registerFormulaWithRange(e,t,a,n,{ruleId:i},E.OtherFormulaBizType.DATA_VALIDATION,i)}addRule(e,t,a){if(!H(a.type,this._validatorRegistryService)&&a.type!==r.DataValidationType.CHECKBOX){const{formula1:i,formula2:n,uid:l}=a,u=r.isFormulaString(i),d=r.isFormulaString(n);if(!u&&!d)return;const c=this._ensureRuleFormulaMap(e,t),h=[void 0,void 0];if(u){const g=this._registerSingleFormula(e,t,i,l);h[0]={id:g,text:i}}if(d){const g=this._registerSingleFormula(e,t,n,l);h[1]={id:g,text:n}}c.set(l,h)}}removeRule(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return;const[l,u]=n,d=[l==null?void 0:l.id,u==null?void 0:u.id].filter(Boolean);d.length&&this._registerOtherFormulaService.deleteFormula(e,t,d)}getRuleFormulaResult(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return Promise.resolve(null);const l=async u=>u&&this._registerOtherFormulaService.getFormulaValue(e,t,u.id);return Promise.all([l(n[0]),l(n[1])])}getRuleFormulaResultSync(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(n)return n.map(l=>{if(l)return this._registerOtherFormulaService.getFormulaValueSync(e,t,l.id)})}getRuleFormulaInfo(e,t,a){return this._ensureRuleFormulaMap(e,t).get(a)}},m.DataValidationFormulaService=Ke([L(0,r.IUniverInstanceService),L(1,r.Inject(E.RegisterOtherFormulaService)),L(2,r.Inject(m.DataValidationCacheService)),L(3,r.Inject(p.DataValidationModel)),L(4,r.Inject(p.DataValidatorRegistryService)),L(5,r.Inject(m.DataValidationListCacheService))],m.DataValidationFormulaService);class he{constructor(s,e,t,a,i=!1){S(this,"_map");S(this,"_tree",new r.RBush);S(this,"_dirty",!0);S(this,"_buildTree",()=>{if(!this._dirty||this._disableTree)return;this._tree.clear();const s=[];this._map.forEach((e,t)=>{e.forEach(a=>{s.push({minX:a.startRow,maxX:a.endRow,minY:a.startColumn,maxY:a.endColumn,ruleId:t})})}),this._tree.load(s),this._dirty=!1});S(this,"_debonceBuildTree",r.debounce(this._buildTree,0));this._unitId=e,this._subUnitId=t,this._univerInstanceService=a,this._disableTree=i,this._map=s,this._buildTree()}get _worksheet(){var s;return(s=this._univerInstanceService.getUnit(this._unitId,r.UniverInstanceType.UNIVER_SHEET))==null?void 0:s.getSheetBySheetId(this._subUnitId)}_addRule(s,e){if(!this._worksheet)return;const t=r.Rectangle.mergeRanges(e.map(a=>r.Range.transformRange(a,this._worksheet)));this._map.forEach((a,i)=>{const n=r.Rectangle.subtractMulti(a,t);n.length===0?this._map.delete(i):this._map.set(i,n)}),this._dirty=!0,this._map.set(s,t),this._debonceBuildTree()}addRule(s){this._addRule(s.uid,s.ranges)}removeRange(s){if(!this._worksheet)return;const e=s.map(t=>r.Range.transformRange(t,this._worksheet));this._map.forEach((t,a)=>{const i=r.Rectangle.subtractMulti(t,e);i.length===0?this._map.delete(a):this._map.set(a,i)}),this._dirty=!0,this._debonceBuildTree()}_removeRule(s){this._map.delete(s),this._dirty=!0,this._debonceBuildTree()}removeRule(s){this._removeRule(s.uid)}updateRange(s,e){this._removeRule(s),this._addRule(s,e)}addRangeRules(s){s.forEach(({id:e,ranges:t})=>{if(!t.length)return;let a=this._map.get(e);a?(this._map.set(e,r.Rectangle.mergeRanges([...a,...t])),a=this._map.get(e)):(a=t,this._map.set(e,a)),this._map.forEach((i,n)=>{if(n===e)return;const l=r.Rectangle.subtractMulti(i,t);l.length===0?this._map.delete(n):this._map.set(n,l)})}),this._dirty=!0,this._debonceBuildTree()}diff(s){const e=[];let t=0;return s.forEach((a,i)=>{var u;const n=(u=this._map.get(a.uid))!=null?u:[],l=a.ranges;n.length!==0&&(n.length!==l.length||n.some((d,c)=>!r.Rectangle.equals(d,l[c])))&&e.push({type:"update",ruleId:a.uid,oldRanges:l,newRanges:r.Rectangle.sort(n),rule:a}),n.length===0&&(e.push({type:"delete",rule:a,index:i-t}),t++)}),e}diffWithAddition(s,e){const t=[];let a=0;return s.forEach((i,n)=>{var d;const l=(d=this._map.get(i.uid))!=null?d:[],u=i.ranges;l.length!==0&&(l.length!==u.length||l.some((c,h)=>!r.Rectangle.equals(c,u[h])))&&t.push({type:"update",ruleId:i.uid,oldRanges:u,newRanges:r.Rectangle.sort(l),rule:i}),l.length===0&&(t.push({type:"delete",rule:i,index:n-a}),a++)}),Array.from(e).forEach(i=>{var l;const n=(l=this._map.get(i.uid))!=null?l:[];t.push({type:"add",rule:{...i,ranges:r.Rectangle.sort(n)}})}),t}clone(){return new he(new Map(r.Tools.deepClone(Array.from(this._map.entries()))),this._unitId,this._subUnitId,this._univerInstanceService,!0)}getValue(s,e){this._dirty&&this._buildTree();const t=this._tree.search({minX:s,maxX:s,minY:e,maxY:e});return t.length>0?t[0].ruleId:void 0}}var ze=Object.getOwnPropertyDescriptor,Ze=(o,s,e,t)=>{for(var a=t>1?void 0:t?ze(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},A=(o,s)=>(e,t)=>s(e,t,o);m.SheetDataValidationModel=class extends r.Disposable{constructor(e,t,a,i,n,l,u){super();S(this,"_ruleMatrixMap",new Map);S(this,"_validStatusChange$",new U.Subject);S(this,"_ruleChange$",new U.Subject);S(this,"ruleChange$",this._ruleChange$.asObservable());S(this,"validStatusChange$",this._validStatusChange$.asObservable());this._dataValidationModel=e,this._univerInstanceService=t,this._dataValidatorRegistryService=a,this._dataValidationCacheService=i,this._dataValidationFormulaService=n,this._dataValidationCustomFormulaService=l,this._commandService=u,this._initRuleUpdateListener(),this.disposeWithMe(()=>{this._ruleChange$.complete(),this._validStatusChange$.complete()}),this._initUniverInstanceListener()}_initUniverInstanceListener(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{this._ruleMatrixMap.delete(e.getUnitId())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.RemoveSheetMutation.id){const{unitId:t,subUnitId:a}=e.params,i=this._ruleMatrixMap.get(t);i&&i.delete(a)}}))}_initRuleUpdateListener(){const e=this._dataValidationModel.getAll();for(const[t,a]of e)for(const[i,n]of a)for(const l of n)this._addRule(t,i,l),this._ruleChange$.next({type:"add",unitId:t,subUnitId:i,rule:l,source:"patched"});this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(t=>{switch(t.type){case"add":this._addRule(t.unitId,t.subUnitId,t.rule);break;case"update":this._updateRule(t.unitId,t.subUnitId,t.rule.uid,t.oldRule,t.updatePayload);break;case"remove":this._removeRule(t.unitId,t.subUnitId,t.rule);break}this._ruleChange$.next(t)}))}_ensureRuleMatrix(e,t){let a=this._ruleMatrixMap.get(e);a||(a=new Map,this._ruleMatrixMap.set(e,a));let i=a.get(t);return i||(i=new he(new Map,e,t,this._univerInstanceService),a.set(t,i)),i}_addRuleSideEffect(e,t,a){this._ensureRuleMatrix(e,t).addRule(a),this._dataValidationCacheService.addRule(e,t,a),this._dataValidationFormulaService.addRule(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,a)}_addRule(e,t,a){(Array.isArray(a)?a:[a]).forEach(n=>{this._addRuleSideEffect(e,t,n)})}_updateRule(e,t,a,i,n){const l=this._ensureRuleMatrix(e,t),u={...i,...n.payload};n.type===p.UpdateRuleType.RANGE?l.updateRange(a,n.payload):n.type===p.UpdateRuleType.ALL&&l.updateRange(a,n.payload.ranges),this._dataValidationCacheService.removeRule(e,t,i),this._dataValidationCacheService.addRule(e,t,u),this._dataValidationFormulaService.removeRule(e,t,i.uid),this._dataValidationFormulaService.addRule(e,t,u),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,u)}_removeRule(e,t,a){this._ensureRuleMatrix(e,t).removeRule(a),this._dataValidationCacheService.removeRule(e,t,a),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a.uid)}getValidator(e){return this._dataValidatorRegistryService.getValidatorItem(e)}getRuleIdByLocation(e,t,a,i){return this._ensureRuleMatrix(e,t).getValue(a,i)}getRuleByLocation(e,t,a,i){const n=this.getRuleIdByLocation(e,t,a,i);if(n)return this._dataValidationModel.getRuleById(e,t,n)}validator(e,t,a){const{col:i,row:n,unitId:l,subUnitId:u,worksheet:d}=t,c=(R,V)=>{a&&a(R,V),V&&this._validStatusChange$.next({unitId:l,subUnitId:u,ruleId:e.uid,status:R,row:n,col:i})},h=d.getCellValueOnly(n,i),g=this.getValidator(e.type),f=d.getCellRaw(n,i),_=N(f);if(g){const R=this._dataValidationCacheService.ensureCache(l,u),V=R.getValue(n,i);return V==null?(R.setValue(n,i,r.DataValidationStatus.VALIDATING),g.validator({value:_,unitId:l,subUnitId:u,row:n,column:i,worksheet:t.worksheet,workbook:t.workbook,interceptValue:N(h),t:f==null?void 0:f.t},e).then(v=>{const M=v?r.DataValidationStatus.VALID:r.DataValidationStatus.INVALID,T=R.getValue(n,i);M===r.DataValidationStatus.VALID?R.realDeleteValue(n,i):R.setValue(n,i,M),c(M,V!==T)}),r.DataValidationStatus.VALIDATING):(c(V!=null?V:r.DataValidationStatus.VALID,!1),V!=null?V:r.DataValidationStatus.VALID)}else return c(r.DataValidationStatus.VALID,!1),r.DataValidationStatus.VALID}getRuleObjectMatrix(e,t){return this._ensureRuleMatrix(e,t)}getRuleById(e,t,a){return this._dataValidationModel.getRuleById(e,t,a)}getRuleIndex(e,t,a){return this._dataValidationModel.getRuleIndex(e,t,a)}getRules(e,t){return[...this._dataValidationModel.getRules(e,t)]}getUnitRules(e){return this._dataValidationModel.getUnitRules(e)}deleteUnitRules(e){return this._dataValidationModel.deleteUnitRules(e)}getSubUnitIds(e){return this._dataValidationModel.getSubUnitIds(e)}getAll(){return this._dataValidationModel.getAll()}},m.SheetDataValidationModel=Ze([A(0,r.Inject(p.DataValidationModel)),A(1,r.IUniverInstanceService),A(2,r.Inject(p.DataValidatorRegistryService)),A(3,r.Inject(m.DataValidationCacheService)),A(4,r.Inject(m.DataValidationFormulaService)),A(5,r.Inject(m.DataValidationCustomFormulaService)),A(6,r.ICommandService)],m.SheetDataValidationModel);const q=1,Q=0;function Me(o,s){return r.Tools.isBlank(o)?s.t("dataValidation.validFail.value"):r.isFormulaString(o)?s.t("dataValidation.validFail.primitive"):""}const x=o=>r.Tools.isDefine(o)&&String(o).toLowerCase()==="true"?"1":String(o).toLowerCase()==="false"?"0":o;class Ee extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.CHECKBOX);S(this,"title","dataValidation.checkbox.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"order",41);S(this,"offsetFormulaByRange",!1);S(this,"_formulaService",this.injector.get(m.DataValidationFormulaService));S(this,"skipDefaultFontRender",(e,t,a)=>{const{unitId:i,subUnitId:n}=a,{formula1:l,formula2:u}=this.parseFormulaSync(e,i,n),d=`${t!=null?t:""}`;return!d||d===`${l}`||d===`${u}`})}validatorFormula(e,t,a){const{formula1:i,formula2:n}=e,l=i===n;if(r.Tools.isBlank(i)&&r.Tools.isBlank(n))return{success:!0};if(l)return{success:!1,formula1:this.localeService.t("dataValidation.validFail.checkboxEqual"),formula2:this.localeService.t("dataValidation.validFail.checkboxEqual")};const u=Me(i,this.localeService),d=Me(n,this.localeService);return{success:!u&&!d,formula1:u,formula2:d}}async parseFormula(e,t,a){var h,g,f,_;const{formula1:i=q,formula2:n=Q}=e,l=await this._formulaService.getRuleFormulaResult(t,a,e.uid),u=r.isFormulaString(i)?w((g=(h=l==null?void 0:l[0])==null?void 0:h.result)==null?void 0:g[0][0]):i,d=r.isFormulaString(n)?w((_=(f=l==null?void 0:l[1])==null?void 0:f.result)==null?void 0:_[0][0]):n,c=y(String(u))&&y(String(d));return{formula1:x(u),formula2:x(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}getExtraStyle(e,t){return{tb:r.WrapStrategy.CLIP}}parseFormulaSync(e,t,a){var h,g,f,_;const{formula1:i=q,formula2:n=Q}=e,l=this._formulaService.getRuleFormulaResultSync(t,a,e.uid),u=r.isFormulaString(i)?w((g=(h=l==null?void 0:l[0])==null?void 0:h.result)==null?void 0:g[0][0]):i,d=r.isFormulaString(n)?w((_=(f=l==null?void 0:l[1])==null?void 0:f.result)==null?void 0:_[0][0]):n,c=y(String(u))&&y(String(d));return{formula1:x(u),formula2:x(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}async isValidType(e,t,a){const{value:i,unitId:n,subUnitId:l}=e,{formula1:u,formula2:d,originFormula1:c,originFormula2:h}=await this.parseFormula(a,n,l);return!r.Tools.isDefine(u)||!r.Tools.isDefine(d)?!0:r.Tools.isDefine(i)&&(String(i)===String(u)||String(i)===String(d)||String(i)===String(c!=null?c:"")||String(i)===String(h!=null?h:""))}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.checkbox.error")}generateRuleName(e){return this.titleStr}}const Je={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.operators.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.operators.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.operators.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.operators.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.operators.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.operators.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.operators.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.operators.notEqual"};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 ye={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.ruleName.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.ruleName.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.ruleName.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.ruleName.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.ruleName.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.ruleName.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.ruleName.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.ruleName.notEqual",NONE:"dataValidation.date.ruleName.legal"},et={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.errorMsg.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.errorMsg.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.errorMsg.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.errorMsg.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.errorMsg.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.errorMsg.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.errorMsg.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.errorMsg.notEqual",NONE:"dataValidation.date.errorMsg.legal"},Z=[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.NOT_BETWEEN],G="{FORMULA1}",Y="{FORMULA2}",me=o=>{var e,t;if(o==null||typeof o=="boolean")return;if(typeof o=="number"||!Number.isNaN(+o))return+o;const s=(e=r.numfmt.parseDate(o))==null?void 0:e.v;return r.Tools.isDefine(s)?s:(t=r.numfmt.parseDate(r.dayjs(o).format("YYYY-MM-DD HH:mm:ss")))==null?void 0:t.v};class Te extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.DATE);S(this,"title","dataValidation.date.title");S(this,"order",40);S(this,"operators",[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]);S(this,"scopes",["sheet"]);S(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));S(this,"_lexerTreeBuilder",this.injector.get(E.LexerTreeBuilder))}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=y(String(l==null?void 0:l.v))&&y(String(u==null?void 0:u.v));return{formula1:me(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:me(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}async isValidType(e){const{interceptValue:t,value:a}=e;return typeof a=="number"&&typeof t=="string"||typeof t=="string"?!!r.numfmt.parseDate(t):!1}_validatorSingleFormula(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)||!!(e&&r.numfmt.parseDate(e)))}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=this._validatorSingleFormula(e.formula1),l=this.localeService.t("dataValidation.validFail.date");if(Z.includes(i)){const d=this._validatorSingleFormula(e.formula2);return{success:n&&d,formula1:n?void 0:l,formula2:d?void 0:l}}return{success:n,formula1:n?void 0:l}}normalizeFormula(e,t,a){const{formula1:i,formula2:n,bizInfo:l}=e,u=d=>{var h;if(!d)return d;let c;if(!Number.isNaN(+d))c=r.numfmt.dateFromSerial(+d);else{const g=(h=r.numfmt.parseDate(d))==null?void 0:h.v;if(g==null)return"";c=r.numfmt.dateFromSerial(g)}return r.dayjs(`${c[0]}/${c[1]}/${c[2]} ${c[3]}:${c[4]}:${c[5]}`).format(l!=null&&l.showTime?"YYYY-MM-DD HH:mm:ss":"YYYY-MM-DD")};return{formula1:r.isFormulaString(i)?i:u(`${i}`),formula2:r.isFormulaString(n)?n:u(`${n}`)}}transform(e,t,a){const{value:i}=e;return{...e,value:me(i)}}get operatorNames(){return this.operators.map(e=>this.localeService.t(Je[e]))}generateRuleName(e){var a,i;if(!e.operator)return this.localeService.t(ye.NONE);const t=this.localeService.t(ye[e.operator]).replace(G,(a=e.formula1)!=null?a:"").replace(Y,(i=e.formula2)!=null?i:"");return`${this.titleStr} ${t}`}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=k(this._lexerTreeBuilder,e,t);return`${this.localeService.t(et[e.operator]).replace(G,a!=null?a:"").replace(Y,i!=null?i:"")}`}}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+"",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 J={[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"};function X(o){return+o}class tt extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));S(this,"id",r.DataValidationType.DECIMAL);S(this,"_lexerTreeBuilder",this.injector.get(E.LexerTreeBuilder));S(this,"title","dataValidation.decimal.title");S(this,"order",20);S(this,"operators",[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]);S(this,"scopes",["sheet"])}_isFormulaOrNumber(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e))}async isValidType(e,t,a){const{value:i}=e;return!Number.isNaN(X(i))}transform(e,t,a){const{value:i}=e;return{...e,value:X(i)}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=y(String(l==null?void 0:l.v))&&y(String(u==null?void 0:u.v));return{formula1:this._parseNumber(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:this._parseNumber(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrNumber(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrNumber(e.formula2),u=Z.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:n?"":d}}generateRuleErrorMessage(e,t){if(!e.operator)return this.localeService.t(J.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=k(this._lexerTreeBuilder,e,t);return`${this.localeService.t(J[e.operator]).replace(G,a!=null?a:"").replace(Y,i!=null?i:"")}`}}function at(o){var e,t;if(!o)return[];const s=new Set;for(let a=0,i=o.length;a<i;a++){const n=o[a];if(n)for(let l=0,u=n.length;l<u;l++){const d=n[l],c=N(d);if(c!=null){if(typeof c!="string"&&typeof(d==null?void 0:d.s)=="object"&&((t=(e=d.s)==null?void 0:e.n)!=null&&t.pattern)){s.add(r.numfmt.format(d.s.n.pattern,c,{throws:!1}));continue}const h=typeof c=="string"?c:String(c);y(h)&&s.add(h)}}}return[...s]}const it=["if","indirect","choose","offset"];function rt(o,s){if(!r.isFormulaString(o)||E.isReferenceString(o.slice(1)))return!0;const t=s.sequenceNodesBuilder(o);return t&&t.some(a=>typeof a=="object"&&a.nodeType===E.sequenceNodeType.FUNCTION&&it.indexOf(a.token.toLowerCase())>-1)}function nt(o,s){const{formula1:e="",ranges:t}=o;if(E.isReferenceString(e.slice(1))){const i=E.deserializeRangeWithSheet(e.slice(1));if((!i.sheetName||i.sheetName===s)&&t.some(n=>r.Rectangle.intersects(n,i.range)))return!0}return!1}class ge extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"formulaService",this.injector.get(m.DataValidationFormulaService));S(this,"_lexer",this.injector.get(E.LexerTreeBuilder));S(this,"_univerInstanceService",this.injector.get(r.IUniverInstanceService));S(this,"_listCacheService",this.injector.get(m.DataValidationListCacheService));S(this,"order",50);S(this,"offsetFormulaByRange",!1);S(this,"id",r.DataValidationType.LIST);S(this,"title","dataValidation.list.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"skipDefaultFontRender",e=>e.renderMode!==r.DataValidationRenderMode.TEXT)}validatorFormula(e,t,a){var d,c,h;const i=!r.Tools.isBlank(e.formula1),n=rt((d=e.formula1)!=null?d:"",this._lexer),l=(h=(c=this._univerInstanceService.getUnit(t,r.UniverInstanceType.UNIVER_SHEET))==null?void 0:c.getSheetBySheetId(a))==null?void 0:h.getName(),u=nt(e,l!=null?l:"");return{success:!!(i&&n&&!u),formula1:i?n?u?this.localeService.t("dataValidation.validFail.listIntersects"):void 0:this.localeService.t("dataValidation.validFail.listInvalid"):this.localeService.t("dataValidation.validFail.list")}}getExtraStyle(e,t,{style:a}){var n;const i=(n=a.tb!==r.WrapStrategy.OVERFLOW?a.tb:r.WrapStrategy.CLIP)!=null?n:r.WrapStrategy.WRAP;if(e.type===r.DataValidationType.LIST&&(e.renderMode===r.DataValidationRenderMode.ARROW||e.renderMode===r.DataValidationRenderMode.TEXT)){const l=this.getListWithColorMap(e),u=`${t!=null?t:""}`,d=l[u];if(d)return{bg:{rgb:d},tb:i}}return{tb:i}}parseCellValue(e){const t=e.toString();return $(t)}async parseFormula(e,t,a){var u,d;const i=await this.formulaService.getRuleFormulaResult(t,a,e.uid),n=w((d=(u=i==null?void 0:i[0])==null?void 0:u.result)==null?void 0:d[0][0]);return{formula1:void 0,formula2:void 0,isFormulaValid:y(String(n))}}async isValidType(e,t,a){const{value:i,unitId:n,subUnitId:l}=e,{formula1:u=""}=a,d=r.isFormulaString(u)?this._listCacheService.getOrCompute(n,l,a).list:$(u);return this.parseCellValue(i).every(h=>d.includes(h))}generateRuleName(){return this.localeService.t("dataValidation.list.name")}generateRuleErrorMessage(){return this.localeService.t("dataValidation.list.error")}_getUnitAndSubUnit(e,t){var n,l;const a=(n=e?this._univerInstanceService.getUniverSheetInstance(e):void 0)!=null?n:this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!a)return null;const i=(l=t?a.getSheetBySheetId(t):void 0)!=null?l:a.getActiveSheet();return i?{unitId:a.getUnitId(),subUnitId:i.getSheetId()}:null}getList(e,t,a){const i=this._getUnitAndSubUnit(t,a);if(!i)return[];const{unitId:n,subUnitId:l}=i;return this._listCacheService.getOrCompute(n,l,e).list}async getListAsync(e,t,a){var c,h;const{formula1:i=""}=e,n=this._getUnitAndSubUnit(t,a);if(!n)return[];const{unitId:l,subUnitId:u}=n,d=await this.formulaService.getRuleFormulaResult(l,u,e.uid);return r.isFormulaString(i)?at((h=(c=d==null?void 0:d[0])==null?void 0:c.result)==null?void 0:h[0][0]):$(i)}getListWithColor(e,t,a){const i=this._getUnitAndSubUnit(t,a);if(!i)return[];const{unitId:n,subUnitId:l}=i;return this._listCacheService.getOrCompute(n,l,e).listWithColor}getListWithColorMap(e,t,a){const i=this._getUnitAndSubUnit(t,a);if(!i)return{};const{unitId:n,subUnitId:l}=i;return this._listCacheService.getOrCompute(n,l,e).colorMap}}class ot extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.TEXT_LENGTH);S(this,"title","dataValidation.textLength.title");S(this,"_lexerTreeBuilder",this.injector.get(E.LexerTreeBuilder));S(this,"order",30);S(this,"operators",[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]);S(this,"scopes",["sheet"]);S(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService))}_isFormulaOrInt(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!1};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=Z.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:d}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=y(String(l==null?void 0:l.v))&&y(String(u==null?void 0:u.v));return{formula1:this._parseNumber(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:this._parseNumber(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}transform(e,t,a){return{...e,value:e.value.toString().length}}async isValidType(e,t,a){const{value:i}=e;return typeof i=="string"||typeof i=="number"}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=k(this._lexerTreeBuilder,e,t);return`${this.localeService.t(p.TextLengthErrorTitleMap[e.operator]).replace(G,a!=null?a:"").replace(Y,i!=null?i:"")}`}}function Ce(o){var e,t;return o?o.p?!((t=(e=o.p.body)==null?void 0:e.dataStream)!=null?t:"").slice(0,-2).trim():r.Tools.isBlank(o.v):!0}function K(o,s,e,t,a="command",i=!0){const n=t.get(E.LexerTreeBuilder),l=t.get(p.DataValidatorRegistryService),u=[],d=[],c=t.get(m.SheetDataValidationModel),h=t.get(r.IUniverInstanceService),g=D.getSheetCommandTarget(h,{unitId:o,subUnitId:s});if(!g)return{redoMutations:u,undoMutations:d};const{worksheet:f}=g,_=new r.ObjectMatrix;let R=!1;function V(v,M){i&&v.forEach(T=>{r.Range.foreach(T,(C,F)=>{const O=f.getCellRaw(C,F),j=Ve(O);(Ce(O)||j===M)&&!(O!=null&&O.p)&&(R=!0,_.setValue(C,F,{v:M,p:null}))})})}if(e.forEach(v=>{switch(v.type){case"delete":u.push({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.rule.uid,source:a}}),d.unshift({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:v.rule,index:v.index,source:a}});break;case"update":{if(H(v.rule.type,l)){const T=v.oldRanges[0].startRow,C=v.oldRanges[0].startColumn,F=v.newRanges[0].startRow,O=v.newRanges[0].startColumn,j=F-T,oe=O-C,se=r.isFormulaString(v.rule.formula1)?n.moveFormulaRefOffset(v.rule.formula1,oe,j):v.rule.formula1,le=r.isFormulaString(v.rule.formula2)?n.moveFormulaRefOffset(v.rule.formula2,oe,j):v.rule.formula2;se!==v.rule.formula1||le!==v.rule.formula2||!r.isRangesEqual(v.newRanges,v.oldRanges)?(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:se,formula2:le,ranges:v.newRanges}}}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:v.rule.formula1,formula2:v.rule.formula2,ranges:v.oldRanges}}}})):(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:v.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:v.oldRanges},source:a}}))}else u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:v.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:v.oldRanges},source:a}});const M=c.getRuleById(o,s,v.ruleId);if(M&&M.type===r.DataValidationType.CHECKBOX){const C=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(M,o,s);V(v.newRanges,C.formula2)}break}case"add":{if(u.push({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:v.rule,source:a}}),d.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.rule.uid,source:a}}),v.rule.type===r.DataValidationType.CHECKBOX){const T=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(v.rule,o,s);V(v.rule.ranges,T.originFormula2)}break}}}),R){const v={id:D.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:s,cellValue:_.getData()}},M={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(t,v.params)};u.push(v),d.push(M)}return{redoMutations:u,undoMutations:d}}const Oe={type:r.CommandType.COMMAND,id:"sheet.command.updateDataValidationRuleRange",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ranges:a,ruleId:i}=s,n=o.get(m.SheetDataValidationModel),l=o.get(r.ICommandService),u=o.get(r.IUndoRedoService);if(!n.getRuleById(e,t,i))return!1;const c=n.getRuleObjectMatrix(e,t).clone();c.updateRange(i,a);const h=c.diff(n.getRules(e,t)),{redoMutations:g,undoMutations:f}=K(e,t,h,o);return u.pushUndoRedo({undoMutations:f,redoMutations:g,unitID:e}),r.sequenceExecute(g,l),!0}},Fe={type:r.CommandType.COMMAND,id:"sheet.command.addDataValidation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,rule:a}=s,i=o.get(m.SheetDataValidationModel),n=o.get(r.ICommandService),l=o.get(r.IUndoRedoService),u=i.getRuleObjectMatrix(e,t).clone();u.addRule(a);const d=u.diff(i.getRules(e,t)),c=i.getValidator(a.type),h={unitId:e,subUnitId:t,rule:{...a,...c==null?void 0:c.normalizeFormula(a,e,t)}},{redoMutations:g,undoMutations:f}=K(e,t,d,o);return g.push({id:p.AddDataValidationMutation.id,params:h}),f.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:t,ruleId:a.uid}}),l.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:f}),r.sequenceExecute(g,n),!0}},Ie={type:r.CommandType.COMMAND,id:"sheets.command.update-data-validation-setting",handler(o,s){if(!s)return!1;const e=o.get(r.ICommandService),t=o.get(r.IUndoRedoService),a=o.get(m.SheetDataValidationModel),i=o.get(p.DataValidatorRegistryService),{unitId:n,subUnitId:l,ruleId:u,setting:d}=s,c=i.getValidatorItem(d.type);if(!c)return!1;const h=a.getRuleById(n,l,u);if(!h)return!1;const g={...h,...d};if(!c.validatorFormula(g,n,l).success)return!1;const f={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:{...d,...c.normalizeFormula(g,n,l)}}},_=[{id:p.UpdateDataValidationMutation.id,params:f}],R={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:p.getRuleSetting(h)}},V=[{id:p.UpdateDataValidationMutation.id,params:R}];if(d.type===r.DataValidationType.CHECKBOX){const M=h.ranges,T=o.get(r.IUniverInstanceService),C=D.getSheetCommandTarget(T,{unitId:n,subUnitId:l});if(C){const F=new r.ObjectMatrix,{worksheet:O}=C,{formula2:j=Q,formula1:oe=q}=h,{formula2:se=Q,formula1:le=q}=d;let _e=!1;if(M.forEach(ue=>{r.Range.foreach(ue,(z,Re)=>{const I=O.getCellRaw(z,Re),He=Ve(I);(Ce(I)||He===String(j))&&!(I!=null&&I.p)?(F.setValue(z,Re,{v:se,p:null}),_e=!0):He===String(oe)&&!(I!=null&&I.p)&&(F.setValue(z,Re,{v:le,p:null}),_e=!0)})}),_e){const ue={id:D.SetRangeValuesMutation.id,params:{unitId:n,subUnitId:l,cellValue:F.getData()}},z={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(o,ue.params)};_.push(ue),V.push(z)}}}return r.sequenceExecute(_,e).result?(t.pushUndoRedo({unitID:n,redoMutations:_,undoMutations:V}),!0):!1}},Ne={type:r.CommandType.COMMAND,id:"sheets.command.update-data-validation-options",handler(o,s){if(!s)return!1;const e=o.get(r.ICommandService),t=o.get(r.IUndoRedoService),a=o.get(m.SheetDataValidationModel),{unitId:i,subUnitId:n,ruleId:l,options:u}=s,d=a.getRuleById(i,n,l);if(!d)return!1;const c={unitId:i,subUnitId:n,ruleId:l,payload:{type:p.UpdateRuleType.OPTIONS,payload:u}},h=[{id:p.UpdateDataValidationMutation.id,params:c}],g={unitId:i,subUnitId:n,ruleId:l,payload:{type:p.UpdateRuleType.OPTIONS,payload:p.getRuleOptions(d)}},f=[{id:p.UpdateDataValidationMutation.id,params:g}];return t.pushUndoRedo({unitID:i,redoMutations:h,undoMutations:f}),e.executeCommand(p.UpdateDataValidationMutation.id,c),!0}},Ae={type:r.CommandType.COMMAND,id:"sheets.command.clear-range-data-validation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ranges:a}=s,i=o.get(r.ICommandService),n=o.get(r.IUniverInstanceService),l=D.getSheetCommandTarget(n,{unitId:e,subUnitId:t}),u=o.get(m.SheetDataValidationModel);if(!l)return!1;const d=o.get(r.IUndoRedoService),c=u.getRuleObjectMatrix(e,t).clone();c.removeRange(a);const h=c.diff(u.getRules(e,t)),{redoMutations:g,undoMutations:f}=K(e,t,h,o);return d.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:f}),r.sequenceExecute(g,i).result}},Ue={type:r.CommandType.COMMAND,id:"sheet.command.remove-all-data-validation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t}=s,a=o.get(r.ICommandService),i=o.get(m.SheetDataValidationModel),n=o.get(r.IUndoRedoService),l=[...i.getRules(e,t)],u={unitId:e,subUnitId:t,ruleId:l.map(h=>h.uid)},d=[{id:p.RemoveDataValidationMutation.id,params:u}],c=[{id:p.AddDataValidationMutation.id,params:{unitId:e,subUnitId:t,rule:l}}];return n.pushUndoRedo({redoMutations:d,undoMutations:c,unitID:e}),a.executeCommand(p.RemoveDataValidationMutation.id,u),!0}},st=(o,s)=>{const e=o.get(m.SheetDataValidationModel),{unitId:t,subUnitId:a,ruleId:i,source:n}=s;if(Array.isArray(i)){const u=i.map(d=>e.getRuleById(t,a,d)).filter(Boolean);return[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:u,source:n}}]}return[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:{...e.getRuleById(t,a,i)},index:e.getRuleIndex(t,a,i)}}]},we={type:r.CommandType.COMMAND,id:"sheet.command.remove-data-validation-rule",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ruleId:a}=s,i=o.get(r.ICommandService),n=o.get(r.IUndoRedoService),l=o.get(m.SheetDataValidationModel),u=[{id:p.RemoveDataValidationMutation.id,params:s}],d=[{id:p.AddDataValidationMutation.id,params:{unitId:e,subUnitId:t,rule:{...l.getRuleById(e,t,a)},index:l.getRuleIndex(e,t,a)}}];return n.pushUndoRedo({undoMutations:d,redoMutations:u,unitID:s.unitId}),i.executeCommand(p.RemoveDataValidationMutation.id,s),!0}},Le="SHEET_DATA_VALIDATION_PLUGIN";var be=(o=>(o[o.View=0]="View",o[o.Edit=1]="Edit",o[o.ManageCollaborator=2]="ManageCollaborator",o[o.Print=3]="Print",o[o.Duplicate=4]="Duplicate",o[o.Comment=5]="Comment",o[o.Copy=6]="Copy",o[o.Share=7]="Share",o[o.Export=8]="Export",o[o.MoveWorksheet=9]="MoveWorksheet",o[o.DeleteWorksheet=10]="DeleteWorksheet",o[o.HideWorksheet=11]="HideWorksheet",o[o.RenameWorksheet=12]="RenameWorksheet",o[o.CreateWorksheet=13]="CreateWorksheet",o[o.SetWorksheetStyle=14]="SetWorksheetStyle",o[o.EditWorksheetCell=15]="EditWorksheetCell",o[o.InsertHyperlink=16]="InsertHyperlink",o[o.Sort=17]="Sort",o[o.Filter=18]="Filter",o[o.PivotTable=19]="PivotTable",o[o.FloatImg=20]="FloatImg",o[o.History=21]="History",o[o.RwHgtClWdt=22]="RwHgtClWdt",o[o.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",o[o.ViewFilter=24]="ViewFilter",o[o.MoveSheet=25]="MoveSheet",o[o.DeleteSheet=26]="DeleteSheet",o[o.HideSheet=27]="HideSheet",o[o.CopySheet=28]="CopySheet",o[o.RenameSheet=29]="RenameSheet",o[o.CreateSheet=30]="CreateSheet",o[o.SelectProtectedCells=31]="SelectProtectedCells",o[o.SelectUnProtectedCells=32]="SelectUnProtectedCells",o[o.SetCellStyle=33]="SetCellStyle",o[o.SetCellValue=34]="SetCellValue",o[o.SetRowStyle=35]="SetRowStyle",o[o.SetColumnStyle=36]="SetColumnStyle",o[o.InsertRow=37]="InsertRow",o[o.InsertColumn=38]="InsertColumn",o[o.DeleteRow=39]="DeleteRow",o[o.DeleteColumn=40]="DeleteColumn",o[o.EditExtraObject=41]="EditExtraObject",o[o.Delete=42]="Delete",o[o.RecoverHistory=43]="RecoverHistory",o[o.ViewHistory=44]="ViewHistory",o[o.CreatePermissionObject=45]="CreatePermissionObject",o[o.UNRECOGNIZED=-1]="UNRECOGNIZED",o))(be||{}),lt=Object.getOwnPropertyDescriptor,ut=(o,s,e,t)=>{for(var a=t>1?void 0:t?lt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},pe=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaController=class extends r.Disposable{constructor(s,e,t){super(),this._univerInstanceService=s,this._permissionService=e,this._lexerTreeBuilder=t}getFormulaRefCheck(s){var t,a;const e=this._lexerTreeBuilder.sequenceNodesBuilder(s);if(!e)return!0;for(let i=0;i<e.length;i++){const n=e[i];if(typeof n=="string")continue;const{token:l}=n,u=E.deserializeRangeWithSheetWithCache(l),d=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);let c=d.getActiveSheet();const h=d.getUnitId();if(u.sheetName){if(c=d.getSheetBySheetName(u.sheetName),!c)return!1;const V=c==null?void 0:c.getSheetId();if(!this._permissionService.getPermissionPoint(new D.WorksheetViewPermission(h,V).id))return!1}if(!c)return!1;const{startRow:g,endRow:f,startColumn:_,endColumn:R}=u.range;for(let V=g;V<=f;V++)for(let v=_;v<=R;v++){const M=(a=(t=c.getCell(V,v))==null?void 0:t.selectionProtection)==null?void 0:a[0];if((M==null?void 0:M[be.View])===!1)return!1}}return!0}},m.DataValidationFormulaController=ut([pe(0,r.IUniverInstanceService),pe(1,r.IPermissionService),pe(2,r.Inject(E.LexerTreeBuilder))],m.DataValidationFormulaController);const Be={name:"@univerjs/sheets-data-validation",version:"0.17.0"},dt="sheets-data-validation.config",je={};var ct=Object.getOwnPropertyDescriptor,ht=(o,s,e,t)=>{for(var a=t>1?void 0:t?ct(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},Se=(o,s)=>(e,t)=>s(e,t,o);let ee=class extends r.Disposable{constructor(s,e,t){super();S(this,"_disposableMap",new Map);S(this,"registerRule",(s,e,t)=>{H(t.type,this._validatorRegistryService)&&this.register(s,e,t)});this._dataValidationModel=s,this._formulaRefRangeService=e,this._validatorRegistryService=t,this._initRefRange()}_getIdWithUnitId(s,e,t){return`${s}_${e}_${t}`}register(s,e,t){const a=t.ranges,i=t.formula1,n=t.formula2,l=this._formulaRefRangeService.registerRangeFormula(s,e,a,[i!=null?i:"",n!=null?n:""],d=>{if(d.length===0)return{undos:[{id:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:t,source:"patched"}}],redos:[{id:p.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,source:"patched"}}]};const c=[],h=[],g=d[0];c.push({id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:g.ranges,formula1:g.formulas[0],formula2:g.formulas[1]}},source:"patched"}}),h.push({id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:a,formula1:i,formula2:n}},source:"patched"}});for(let f=1;f<d.length;f++){const _=d[f],R=r.generateRandomId();c.push({id:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:{...t,uid:R,formula1:_.formulas[0],formula2:_.formulas[1],ranges:_.ranges},source:"patched"}}),h.push({id:p.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:R,source:"patched"}})}return{undos:h,redos:c}}),u=this._getIdWithUnitId(s,e,t.uid);this._disposableMap.set(u,l)}_initRefRange(){const s=this._dataValidationModel.getAll();for(const[e,t]of s)for(const[a,i]of t)for(const n of i)this.registerRule(e,a,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{const{unitId:t,subUnitId:a,rule:i}=e;switch(e.type){case"add":{const n=e.rule;this.registerRule(e.unitId,e.subUnitId,n);break}case"remove":{const n=this._disposableMap.get(this._getIdWithUnitId(t,a,i.uid));n&&n.dispose();break}case"update":{const n=e.rule,l=this._disposableMap.get(this._getIdWithUnitId(t,a,n.uid));l&&l.dispose(),this.registerRule(e.unitId,e.subUnitId,n);break}}})),this.disposeWithMe(r.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};ee=ht([Se(0,r.Inject(m.SheetDataValidationModel)),Se(1,r.Inject(de.FormulaRefRangeService)),Se(2,r.Inject(p.DataValidatorRegistryService))],ee);var mt=Object.getOwnPropertyDescriptor,gt=(o,s,e,t)=>{for(var a=t>1?void 0:t?mt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},b=(o,s)=>(e,t)=>s(e,t,o);let te=class extends r.Disposable{constructor(s,e,t,a,i,n){super();S(this,"_disposableMap",new Map);S(this,"registerRule",(s,e,t)=>{H(t.type,this._validatorRegistryService)||(this.register(s,e,t),this.registerFormula(s,e,t))});this._dataValidationModel=s,this._injector=e,this._refRangeService=t,this._dataValidationFormulaService=a,this._formulaRefRangeService=i,this._validatorRegistryService=n,this._initRefRange()}_getIdWithUnitId(s,e,t){return`${s}_${e}_${t}`}registerFormula(s,e,t){var d;const a=t.uid,i=this._getIdWithUnitId(s,e,a),n=(d=this._disposableMap.get(i))!=null?d:new Set,l=(c,h)=>{const g=this._dataValidationModel.getRuleById(s,e,a);if(!g)return{redos:[],undos:[]};const f=g[c];if(!f||f===h)return{redos:[],undos:[]};const _={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:g.type,formula1:g.formula1,formula2:g.formula2,[c]:h}},source:"patched"},R={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:g.type,formula1:g.formula1,formula2:g.formula2}},source:"patched"},V=[{id:p.UpdateDataValidationMutation.id,params:_}],v=[{id:p.UpdateDataValidationMutation.id,params:R}];return{redos:V,undos:v}},u=this._dataValidationFormulaService.getRuleFormulaInfo(s,e,a);if(u){const[c,h]=u;if(c){const g=this._formulaRefRangeService.registerFormula(s,e,c.text,f=>l("formula1",f));n.add(()=>g.dispose())}if(h){const g=this._formulaRefRangeService.registerFormula(s,e,h.text,f=>l("formula2",f));n.add(()=>g.dispose())}}}register(s,e,t){var u;const a=d=>{const c=[...t.ranges],g=c.map(_=>D.handleCommonDefaultRangeChangeWithEffectRefCommands(_,d)).filter(_=>!!_).flat();if(r.isRangesEqual(g,c))return{redos:[],undos:[]};if(g.length){const _={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:g},source:"patched"},R=[{id:p.UpdateDataValidationMutation.id,params:_}],V=[{id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:c},source:"patched"}}];return{redos:R,undos:V}}else{const _={unitId:s,subUnitId:e,ruleId:t.uid},R=[{id:p.RemoveDataValidationMutation.id,params:_}],V=st(this._injector,_);return{redos:R,undos:V}}},i=[];t.ranges.forEach(d=>{const c=this._refRangeService.registerRefRange(d,a,s,e);i.push(()=>c.dispose())});const n=this._getIdWithUnitId(s,e,t.uid),l=(u=this._disposableMap.get(n))!=null?u:new Set;l.add(()=>i.forEach(d=>d())),this._disposableMap.set(n,l)}_initRefRange(){const s=this._dataValidationModel.getAll();for(const[e,t]of s)for(const[a,i]of t)for(const n of i)this.registerRule(e,a,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{const{unitId:t,subUnitId:a,rule:i}=e;switch(e.type){case"add":{const n=e.rule;this.registerRule(e.unitId,e.subUnitId,n);break}case"remove":{const n=this._disposableMap.get(this._getIdWithUnitId(t,a,i.uid));n&&n.forEach(l=>l());break}case"update":{const n=e.rule,l=this._disposableMap.get(this._getIdWithUnitId(t,a,n.uid));l&&l.forEach(u=>u()),this.registerRule(e.unitId,e.subUnitId,n);break}}})),this.disposeWithMe(r.toDisposable(()=>{this._disposableMap.forEach(e=>{e.forEach(t=>t())}),this._disposableMap.clear()}))}};te=gt([b(0,r.Inject(m.SheetDataValidationModel)),b(1,r.Inject(r.Injector)),b(2,r.Inject(D.RefRangeService)),b(3,r.Inject(m.DataValidationFormulaService)),b(4,r.Inject(de.FormulaRefRangeService)),b(5,r.Inject(p.DataValidatorRegistryService))],te);var pt=Object.getOwnPropertyDescriptor,St=(o,s,e,t)=>{for(var a=t>1?void 0:t?pt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},fe=(o,s)=>(e,t)=>s(e,t,o);let ae=class extends r.Disposable{constructor(o,s,e){super(),this._sheetInterceptorService=o,this._univerInstanceService=s,this._sheetDataValidationModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{var s;if(o.id===D.RemoveSheetCommand.id){const e=o.params,t=e.unitId||this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=this._univerInstanceService.getUniverSheetInstance(t);if(!a)return{redos:[],undos:[]};const i=e.subUnitId||((s=a.getActiveSheet())==null?void 0:s.getSheetId());if(!i)return{redos:[],undos:[]};const n=this._sheetDataValidationModel.getRules(t,i);if(n.length===0)return{redos:[],undos:[]};const l=n.map(c=>c.uid),u={unitId:t,subUnitId:i,ruleId:l,source:"patched"},d={unitId:t,subUnitId:i,rule:[...n],source:"patched"};return{redos:[{id:p.RemoveDataValidationMutation.id,params:u}],undos:[{id:p.AddDataValidationMutation.id,params:d}]}}else if(o.id===D.CopySheetCommand.id){const e=o.params,{unitId:t,subUnitId:a,targetSubUnitId:i}=e;if(!t||!a||!i)return{redos:[],undos:[]};const n=this._sheetDataValidationModel.getRules(t,a);if(n.length===0)return{redos:[],undos:[]};const l=n.map(u=>({...u,uid:r.generateRandomId(6)}));return{redos:[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:i,rule:l,source:"patched"}}],undos:[{id:p.RemoveDataValidationMutation.id,params:{unitId:t,subUnitId:i,ruleId:l.map(u=>u.uid),source:"patched"}}]}}return{redos:[],undos:[]}}}))}};ae=St([fe(0,r.Inject(D.SheetInterceptorService)),fe(1,r.Inject(r.IUniverInstanceService)),fe(2,r.Inject(m.SheetDataValidationModel))],ae);class ft extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.ANY);S(this,"title","dataValidation.any.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"order",0);S(this,"offsetFormulaByRange",!1)}async parseFormula(e,t,a){return{formula1:e.formula1,formula2:e.formula2,isFormulaValid:!0}}validatorFormula(e,t,a){return{success:!0}}async isValidType(e,t,a){return!0}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.any.error")}}class vt extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.CUSTOM);S(this,"title","dataValidation.custom.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"order",60);S(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));S(this,"_lexerTreeBuilder",this.injector.get(E.LexerTreeBuilder))}validatorFormula(e,t,a){var d;const i=r.isFormulaString(e.formula1),n=(d=e.formula1)!=null?d:"",u=this._lexerTreeBuilder.checkIfAddBracket(n)===0&&n.startsWith(E.operatorToken.EQUALS);return{success:i&&u,formula1:i&&u?"":this.localeService.t("dataValidation.validFail.formula")}}async parseFormula(e,t,a){return{formula1:void 0,formula2:void 0,isFormulaValid:!0}}async isValidType(e,t,a){const{column:i,row:n,unitId:l,subUnitId:u}=e,d=await this._customFormulaService.getCellFormulaValue(l,u,a.uid,n,i),c=d==null?void 0:d.v;return y(String(c))&&r.Tools.isDefine(c)&&c!==""?d.t===r.CellValueType.BOOLEAN?!!c:typeof c=="boolean"?c:typeof c=="number"?!!c:typeof c=="string"?y(c):!!c:!1}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.custom.error")}generateRuleName(e){var t;return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}",(t=e.formula1)!=null?t:"")}}class Pe extends ge{constructor(){super(...arguments);S(this,"id",r.DataValidationType.LIST_MULTIPLE);S(this,"title","dataValidation.listMultiple.title");S(this,"offsetFormulaByRange",!1);S(this,"skipDefaultFontRender",()=>!0)}}class _t extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));S(this,"_lexerTreeBuilder",this.injector.get(E.LexerTreeBuilder));S(this,"id",r.DataValidationType.WHOLE);S(this,"title","dataValidation.whole.title");S(this,"order",10);S(this,"operators",[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]);S(this,"scopes",["sheet"])}_isFormulaOrInt(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}async isValidType(e,t,a){const{value:i}=e,n=X(i);return!Number.isNaN(n)&&Number.isInteger(n)}transform(e,t,a){const{value:i}=e;return{...e,value:X(i)}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=r.isFormulaString(d)?l==null?void 0:l.v:d,g=r.isFormulaString(c)?u==null?void 0:u.v:c,f=y(`${h}`)&&y(`${g}`);return{formula1:this._parseNumber(h),formula2:this._parseNumber(g),isFormulaValid:f}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=Z.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:d}}generateRuleErrorMessage(e,t){if(!e.operator)return this.localeService.t(J.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=k(this._lexerTreeBuilder,e,t);return`${this.localeService.t(J[e.operator]).replace(G,a!=null?a:"").replace(Y,i!=null?i:"")}`}}var Rt=Object.getOwnPropertyDescriptor,Vt=(o,s,e,t)=>{for(var a=t>1?void 0:t?Rt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},B=(o,s)=>(e,t)=>s(e,t,o);let ie=class extends r.RxDisposable{constructor(o,s,e,t,a,i){super(),this._univerInstanceService=o,this._dataValidatorRegistryService=s,this._injector=e,this._selectionManagerService=t,this._sheetInterceptorService=a,this._sheetDataValidationModel=i,this._init()}_init(){this._registerValidators(),this._initCommandInterceptor()}_registerValidators(){[ft,tt,_t,ot,Te,Ee,ge,Pe,vt].forEach(o=>{const s=this._injector.createInstance(o);this.disposeWithMe(this._dataValidatorRegistryService.register(s)),this.disposeWithMe(r.toDisposable(()=>this._injector.delete(o)))})}_initCommandInterceptor(){this._sheetInterceptorService.interceptCommand({getMutations:o=>{var s;if(o.id===D.ClearSelectionAllCommand.id){const e=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET),t=e.getUnitId(),a=e.getActiveSheet();if(!a)throw new Error("No active sheet found");const i=a.getSheetId(),n=(s=this._selectionManagerService.getCurrentSelections())==null?void 0:s.map(h=>h.range),l=this._sheetDataValidationModel.getRuleObjectMatrix(t,i).clone();n&&l.removeRange(n);const u=l.diff(this._sheetDataValidationModel.getRules(t,i)),{redoMutations:d,undoMutations:c}=K(t,i,u,this._injector,"patched");return{undos:c,redos:d}}return{undos:[],redos:[]}}})}};ie=Vt([B(0,r.IUniverInstanceService),B(1,r.Inject(p.DataValidatorRegistryService)),B(2,r.Inject(r.Injector)),B(3,r.Inject(D.SheetsSelectionsService)),B(4,r.Inject(D.SheetInterceptorService)),B(5,r.Inject(m.SheetDataValidationModel))],ie);var Dt=Object.getOwnPropertyDescriptor,Mt=(o,s,e,t)=>{for(var a=t>1?void 0:t?Dt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},re=(o,s)=>(e,t)=>s(e,t,o);m.SheetsDataValidationValidatorService=class extends r.Disposable{constructor(s,e,t,a){super(),this._univerInstanceService=s,this._sheetDataValidationModel=e,this._dataValidationCacheService=t,this._lifecycleService=a,this._initRecalculate()}_initRecalculate(){const s=e=>{if(e.length===0)return;const t=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET),a=t==null?void 0:t.getActiveSheet(),i={};e.flat().forEach(n=>{i[n.unitId]||(i[n.unitId]={}),i[n.unitId][n.subUnitId]||(i[n.unitId][n.subUnitId]=[]);const l=this._univerInstanceService.getUnit(n.unitId,r.UniverInstanceType.UNIVER_SHEET),u=l==null?void 0:l.getSheetBySheetId(n.subUnitId);u&&i[n.unitId][n.subUnitId].push(...n.ranges.map(d=>r.Range.transformRange(d,u)))}),Object.entries(i).forEach(([n,l])=>{Object.entries(l).forEach(([u,d])=>{(t==null?void 0:t.getUnitId())===n&&(a==null?void 0:a.getSheetId())===u?this.validatorRanges(n,u,d):requestIdleCallback(()=>{this.validatorRanges(n,u,d)})})})};this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(U.bufferWhen(()=>this._lifecycleService.lifecycle$.pipe(U.filter(e=>e===r.LifecycleStages.Rendered)))).subscribe(s)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(U.filter(()=>this._lifecycleService.stage>=r.LifecycleStages.Rendered),r.bufferDebounceTime(20)).subscribe(s))}async _validatorByCell(s,e,t,a){const i=s.getUnitId(),n=e.getSheetId();if(!r.Tools.isDefine(t)||!r.Tools.isDefine(a))throw new Error(`row or col is not defined, row: ${t}, col: ${a}`);let l=t,u=a;const d=e.getMergedCell(t,a);d&&(l=d.startRow,u=d.startColumn);const c=this._sheetDataValidationModel.getRuleByLocation(i,n,l,u);return c?new Promise(h=>{this._sheetDataValidationModel.validator(c,{unitId:i,subUnitId:n,row:l,col:u,worksheet:e,workbook:s},g=>{h(g)})}):r.DataValidationStatus.VALID}async validatorCell(s,e,t,a){const i=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!i)throw new Error(`cannot find current workbook, unitId: ${s}`);const n=i.getSheetBySheetId(e);if(!n)throw new Error(`cannot find current worksheet, sheetId: ${e}`);return this._validatorByCell(i,n,t,a)}async validatorRanges(s,e,t){if(!t.length)return Promise.resolve([]);const a=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!a)throw new Error(`cannot find current workbook, unitId: ${s}`);const i=a.getSheetBySheetId(e);if(!i)throw new Error(`cannot find current worksheet, sheetId: ${e}`);const l=this._sheetDataValidationModel.getRules(s,e).map(h=>h.ranges).flat(),u=t.map(h=>l.map(g=>r.getIntersectRange(h,g))).flat().filter(Boolean),d=[],c=await Promise.all(u.map((h,g)=>{const f=[];for(let _=h.startRow;_<=h.endRow;_++)for(let R=h.startColumn;R<=h.endColumn;R++){f.push(this._validatorByCell(a,i,_,R));const V=i.getMergedCell(_,R);V&&d.push({resultRowIndex:g,resultColIndex:f.length-1,row:V.startRow,col:V.startColumn})}return Promise.all(f)}));return d.length&&d.forEach(({resultRowIndex:h,resultColIndex:g,row:f,col:_})=>{var R;c[h][g]===r.DataValidationStatus.VALIDATING&&(c[h][g]=(R=this._dataValidationCacheService.getValue(s,e,f,_))!=null?R:r.DataValidationStatus.VALID)}),c}async validatorWorksheet(s,e){const t=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!t)throw new Error(`cannot find current workbook, unitId: ${s}`);const a=t.getSheetBySheetId(e);if(!a)throw new Error(`cannot find current worksheet, sheetId: ${e}`);const i=this._sheetDataValidationModel.getRules(s,e);return await Promise.all(i.map(n=>Promise.all(n.ranges.map(l=>{const u=[];return r.Range.foreach(l,(d,c)=>{u.push(this._validatorByCell(t,a,d,c))}),Promise.all(u)})))),this._dataValidationCacheService.ensureCache(s,e)}async validatorWorkbook(s){const e=this._sheetDataValidationModel.getSubUnitIds(s),t=await Promise.all(e.map(i=>this.validatorWorksheet(s,i))),a={};return t.forEach((i,n)=>{a[e[n]]=i}),a}getDataValidations(s,e,t){const a=this._sheetDataValidationModel.getRuleObjectMatrix(s,e),i=new Set;return t.forEach(l=>{r.Range.foreach(l,(u,d)=>{const c=a.getValue(u,d);c&&i.add(c)})}),Array.from(i).map(l=>this._sheetDataValidationModel.getRuleById(s,e,l)).filter(Boolean)}getDataValidation(s,e,t){return this.getDataValidations(s,e,t)[0]}},m.SheetsDataValidationValidatorService=Mt([re(0,r.IUniverInstanceService),re(1,r.Inject(m.SheetDataValidationModel)),re(2,r.Inject(m.DataValidationCacheService)),re(3,r.Inject(r.LifecycleService))],m.SheetsDataValidationValidatorService);var Et=Object.defineProperty,yt=Object.getOwnPropertyDescriptor,Tt=(o,s,e)=>s in o?Et(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e,Ct=(o,s,e,t)=>{for(var a=t>1?void 0:t?yt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},ve=(o,s)=>(e,t)=>s(e,t,o),ne=(o,s,e)=>Tt(o,typeof s!="symbol"?s+"":s,e);m.UniverSheetsDataValidationPlugin=class extends r.Plugin{constructor(s=je,e,t,a){super(),this._config=s,this._injector=e,this._commandService=t,this._configService=a;const{...i}=r.merge({},je,this._config);this._configService.setConfig(dt,i)}onStarting(){[[m.DataValidationCacheService],[m.DataValidationListCacheService],[m.DataValidationFormulaService],[m.DataValidationCustomFormulaService],[m.SheetsDataValidationValidatorService],[m.SheetDataValidationModel],[ie],[m.DataValidationFormulaController],[ae],[te],[ee]].forEach(s=>{this._injector.add(s)}),[Fe,Oe,Ie,Ne,we,Ue,Ae].forEach(s=>{this._commandService.registerCommand(s)}),this._injector.get(m.DataValidationCacheService),this._injector.get(m.SheetsDataValidationValidatorService),this._injector.get(ie),this._injector.get(ee),this._injector.get(te)}onReady(){this._injector.get(ae)}onRendered(){this._injector.get(m.DataValidationFormulaController)}},ne(m.UniverSheetsDataValidationPlugin,"pluginName",Le),ne(m.UniverSheetsDataValidationPlugin,"packageName",Be.name),ne(m.UniverSheetsDataValidationPlugin,"version",Be.version),ne(m.UniverSheetsDataValidationPlugin,"type",r.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsDataValidationPlugin=Ct([r.DependentOn(de.UniverSheetsFormulaPlugin,p.UniverDataValidationPlugin),ve(1,r.Inject(r.Injector)),ve(2,r.ICommandService),ve(3,r.IConfigService)],m.UniverSheetsDataValidationPlugin);function Ot(o){const e=o.get(D.SheetsSelectionsService).getCurrentSelections().map(i=>i.range);return{uid:r.generateRandomId(6),type:r.DataValidationType.DECIMAL,operator:r.DataValidationOperator.EQUAL,formula1:"100",ranges:e!=null?e:[{startColumn:0,endColumn:0,startRow:0,endRow:0}]}}const Ft="data-validation.custom-formula-input",It="data-validation.formula-input",Nt="data-validation.list-formula-input",At="data-validation.checkbox-formula-input";m.AddSheetDataValidationCommand=Fe,m.BASE_FORMULA_INPUT_NAME=It,m.CHECKBOX_FORMULA_1=q,m.CHECKBOX_FORMULA_2=Q,m.CHECKBOX_FORMULA_INPUT_NAME=At,m.CUSTOM_FORMULA_INPUT_NAME=Ft,m.CheckboxValidator=Ee,m.ClearRangeDataValidationCommand=Ae,m.DATA_VALIDATION_PLUGIN_NAME=Le,m.DateValidator=Te,m.LIST_FORMULA_INPUT_NAME=Nt,m.ListMultipleValidator=Pe,m.ListValidator=ge,m.RemoveSheetAllDataValidationCommand=Ue,m.RemoveSheetDataValidationCommand=we,m.UpdateSheetDataValidationOptionsCommand=Ne,m.UpdateSheetDataValidationRangeCommand=Oe,m.UpdateSheetDataValidationSettingCommand=Ie,m.createDefaultNewRule=Ot,m.deserializeListOptions=$,m.getCellValueNumber=X,m.getCellValueOrigin=N,m.getDataValidationCellValue=xe,m.getDataValidationDiffMutations=K,m.getFormulaCellData=P,m.getFormulaResult=w,m.getTransformedFormula=k,m.isLegalFormulaResult=y,m.serializeListOptions=Qe,m.transformCheckboxValue=x,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
|
7
|
-
|
|
5
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/data-validation`),require(`@univerjs/engine-formula`),require(`@univerjs/sheets`),require(`rxjs`),require(`@univerjs/sheets-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/data-validation`,`@univerjs/engine-formula`,`@univerjs/sheets`,`rxjs`,`@univerjs/sheets-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidation={},e.UniverCore,e.UniverDataValidation,e.UniverEngineFormula,e.UniverSheets,e.rxjs,e.UniverSheetsFormula))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function s(e){"@babel/helpers - typeof";return s=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},s(e)}function c(e,t){if(s(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(s(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){var t=c(e,`string`);return s(t)==`symbol`?t:t+``}function u(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function d(e,t){return function(n,r){t(n,r,e)}}function f(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let p=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._sheetDataValidationModel=n,u(this,`_cacheMatrix`,new Map),u(this,`_dirtyRanges$`,new a.Subject),u(this,`dirtyRanges$`,this._dirtyRanges$.asObservable()),this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted((e,n)=>{if(e.id===i.SetRangeValuesMutation.id&&!(n!=null&&n.onlyLocal)){let{cellValue:n,unitId:r,subUnitId:i}=e.params;if(n){let e=new t.ObjectMatrix(n).getDataRange();if(e.endRow===-1)return;let a=this._sheetDataValidationModel.getRules(r,i).map(e=>e.ranges).flat().map(n=>(0,t.getIntersectRange)(n,e)).filter(Boolean);a.length&&this.markRangeDirty(r,i,a,!0)}}}))}_initSheetRemove(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===i.RemoveSheetMutation.id){var t;let{unitId:n,subUnitId:r}=e.params;(t=this._cacheMatrix.get(n))==null||t.delete(r)}})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{e.type===t.UniverInstanceType.UNIVER_SHEET&&this._cacheMatrix.delete(e.getUnitId())}))}_ensureCache(e,n){let r=this._cacheMatrix.get(e);r||(r=new Map,this._cacheMatrix.set(e,r));let i=r.get(n);return i||(i=new t.ObjectMatrix,r.set(n,i)),i}ensureCache(e,t){return this._ensureCache(e,t)}addRule(e,t,n){this.markRangeDirty(e,t,n.ranges)}removeRule(e,t,n){this._deleteRange(e,t,n.ranges)}markRangeDirty(e,n,r,i){let a=this._ensureCache(e,n);r.forEach(e=>{t.Range.foreach(e,(e,t)=>{a.getValue(e,t)!==void 0&&a.setValue(e,t,void 0)})}),this._dirtyRanges$.next({unitId:e,subUnitId:n,ranges:r,isSetRange:i})}_deleteRange(e,n,r){let i=this._ensureCache(e,n);r.forEach(e=>{t.Range.foreach(e,(e,t)=>{i.realDeleteValue(e,t)})}),this._dirtyRanges$.next({unitId:e,subUnitId:n,ranges:r})}getValue(e,t,n,r){return this._ensureCache(e,t).getValue(n,r)}};p=f([d(0,(0,t.Inject)(t.ICommandService)),d(1,(0,t.Inject)(t.IUniverInstanceService)),d(2,(0,t.Inject)(n.DataValidationModel))],p);function m(e){var t;return e==null||(t=e[0])==null||(t=t[0])==null?void 0:t.v}function h(e){var t;return e==null||(t=e[0])==null?void 0:t[0]}function g(e){return!r.ERROR_TYPE_SET.has(e)}function _(e,t){var n;let r=t.getValidatorItem(e);return(n=r==null?void 0:r.offsetFormulaByRange)==null?!1:n}let v=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=n,this._dataValidationCacheService=r,this._validatorRegistryService=i,u(this,`_ruleFormulaMap`,new Map),u(this,`_ruleFormulaMap2`,new Map),this._initFormulaResultHandler(),this._initDirtyRanges()}dispose(){super.dispose(),this._ruleFormulaMap.clear(),this._ruleFormulaMap2.clear()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(let n in e){let r=e[n];if(this._instanceSrv.getUnitType(n)===t.UniverInstanceType.UNIVER_SHEET)for(let e in r){let t=r[e],{ruleFormulaMap:i}=this._ensureMaps(n,e);t.forEach(t=>{var r,a;let o=i.get((r=t.extra)==null?void 0:r.ruleId),s=this._dataValidationModel.getRuleById(n,e,(a=t.extra)==null?void 0:a.ruleId);s&&o&&this._dataValidationCacheService.markRangeDirty(n,e,s.ranges)})}}}))}_ensureMaps(e,t){let n=this._ruleFormulaMap.get(e),r=this._ruleFormulaMap2.get(e);n||(n=new Map,this._ruleFormulaMap.set(e,n)),r||(r=new Map,this._ruleFormulaMap2.set(e,r));let i=n.get(t);i||(i=new Map,n.set(t,i));let a=r.get(t);return a||(a=new Map,r.set(t,a)),{ruleFormulaMap:i,ruleFormulaMap2:a}}_registerFormula(e,t,n,i,a){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,i,a,{ruleId:n},r.OtherFormulaBizType.DATA_VALIDATION_CUSTOM,n)}_handleDirtyRanges(e,n,r){this._dataValidationModel.getRules(e,n).forEach(i=>{let a=i.ranges;t.Rectangle.doAnyRangesIntersect(a,r)&&this.makeRuleDirty(e,n,i.uid)})}_initDirtyRanges(){this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.subscribe(e=>{e.isSetRange&&this._handleDirtyRanges(e.unitId,e.subUnitId,e.ranges)}))}deleteByRuleId(e,t,n){let{ruleFormulaMap:r,ruleFormulaMap2:i}=this._ensureMaps(e,t),a=this._dataValidationModel.getRuleById(e,t,n),o=r.get(n);if(!a||!o)return;let s=r.get(n);s&&(r.delete(n),this._registerOtherFormulaService.deleteFormula(e,t,[s.formulaId]));let c=i.get(n);c&&(i.delete(n),this._registerOtherFormulaService.deleteFormula(e,t,[c.formulaId]))}_addFormulaByRange(e,n,r,i,a,o){let{ruleFormulaMap:s,ruleFormulaMap2:c}=this._ensureMaps(e,n),l=o[0].startRow,u=o[0].startColumn;if(i&&(0,t.isFormulaString)(i)){let t=this._registerFormula(e,n,r,i,o);s.set(r,{formula:i,originCol:u,originRow:l,formulaId:t})}if(a&&(0,t.isFormulaString)(a)){let t=this._registerFormula(e,n,r,a,o);c.set(r,{formula:a,originCol:u,originRow:l,formulaId:t})}}addRule(e,t,n){if(_(n.type,this._validatorRegistryService)){let{ranges:r,formula1:i,formula2:a,uid:o}=n;this._addFormulaByRange(e,t,o,i,a,r)}}async getCellFormulaValue(e,t,n,r,i){var a;let{ruleFormulaMap:o}=this._ensureMaps(e,t),s=o.get(n);if(!s)return Promise.resolve(void 0);let c=await this._registerOtherFormulaService.getFormulaValue(e,t,s.formulaId),{originRow:l,originCol:u}=s,d=r-l,f=i-u;return h(c==null||(a=c.result)==null||(a=a[d])==null?void 0:a[f])}async getCellFormula2Value(e,t,n,r,i){var a;let{ruleFormulaMap2:o}=this._ensureMaps(e,t),s=o.get(n);if(!s)return Promise.resolve(void 0);let c=await this._registerOtherFormulaService.getFormulaValue(e,t,s.formulaId),{originRow:l,originCol:u}=s,d=r-l,f=i-u;return h(c==null||(a=c.result)==null||(a=a[d])==null?void 0:a[f])}getCellFormulaValueSync(e,t,n,r,i){var a;let{ruleFormulaMap:o}=this._ensureMaps(e,t),s=o.get(n);if(!s)return;let c=this._registerOtherFormulaService.getFormulaValueSync(e,t,s.formulaId),{originRow:l,originCol:u}=s,d=r-l,f=i-u;return h(c==null||(a=c.result)==null||(a=a[d])==null?void 0:a[f])}getCellFormula2ValueSync(e,t,n,r,i){var a;let{ruleFormulaMap2:o}=this._ensureMaps(e,t),s=o.get(n);if(!s)return;let c=this._registerOtherFormulaService.getFormulaValueSync(e,t,s.formulaId),{originRow:l,originCol:u}=s,d=r-l,f=i-u;return h(c==null||(a=c.result)==null||(a=a[d])==null?void 0:a[f])}getRuleFormulaInfo(e,t,n){let{ruleFormulaMap:r}=this._ensureMaps(e,t);return r.get(n)}makeRuleDirty(e,t,n){var r,i;let a=(r=this._ruleFormulaMap.get(e))==null||(r=r.get(t))==null?void 0:r.get(n),o=(i=this._ruleFormulaMap2.get(e))==null||(i=i.get(t))==null?void 0:i.get(n);a&&this._registerOtherFormulaService.markFormulaDirty(e,t,a.formulaId),o&&this._registerOtherFormulaService.markFormulaDirty(e,t,o.formulaId)}};v=f([d(0,t.IUniverInstanceService),d(1,(0,t.Inject)(r.RegisterOtherFormulaService)),d(2,(0,t.Inject)(n.DataValidationModel)),d(3,(0,t.Inject)(p)),d(4,(0,t.Inject)(n.DataValidatorRegistryService))],v);function y(e){return(0,t.getOriginCellValue)(e)}function ee(e){var t;return String((t=y(e))==null?``:t)}function b(e){return e.filter(Boolean).join(`,`)}function x(e){return e.split(`,`).filter(Boolean)}function te(e){let t=y(e);return t==null?``:t.toString()}function S(e,n,r){let{formula1:i,formula2:a}=n,o=n.ranges[0].startRow,s=n.ranges[0].startColumn,c=r.row-o,l=r.col-s;return{transformedFormula1:(0,t.isFormulaString)(i)?e.moveFormulaRefOffset(i,l,c,!0):i,transformedFormula2:(0,t.isFormulaString)(a)?e.moveFormulaRefOffset(a,l,c,!0):a}}let C=class extends t.Disposable{constructor(e,t){super(),this._injector=e,this._dataValidationModel=t,u(this,`_cache`,new Map),this._initRuleChangeListener()}_initRuleChangeListener(){this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{(e.type===`remove`||e.type===`update`)&&this.markRuleDirty(e.unitId,e.subUnitId,e.rule.uid)}))}getOrCompute(e,t,n){let r=this.getCache(e,t,n.uid);if(r)return r;let i=this._injector.get(w).getRuleFormulaResultSync(e,t,n.uid);return this.computeAndCache(e,t,n,i)}_ensureCache(e,t){let n=this._cache.get(e);n||(n=new Map,this._cache.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}getCache(e,t,n){var r;return(r=this._cache.get(e))==null||(r=r.get(t))==null?void 0:r.get(n)}setCache(e,t,n,r){this._ensureCache(e,t).set(n,r)}markRuleDirty(e,t,n){var r;(r=this._cache.get(e))==null||(r=r.get(t))==null||r.delete(n)}clear(){this._cache.clear()}computeAndCache(e,n,r,i){var a;let{formula1:o=``,formula2:s=``}=r,c=(0,t.isFormulaString)(o)?this._getRuleFormulaResultSet(i==null||(a=i[0])==null||(a=a.result)==null||(a=a[0])==null?void 0:a[0]):x(o),l=s.split(`,`),u=c.map((e,t)=>({label:e,color:l[t]||``})),d={};for(let e of u)e.color&&(d[e.label]=e.color);let f={list:c,listWithColor:u,colorMap:d,set:new Set(c)};return this.setCache(e,n,r.uid,f),f}_getRuleFormulaResultSet(e){if(!e)return[];let n=new Set;for(let i=0,a=e.length;i<a;i++){let a=e[i];if(a)for(let e=0,i=a.length;e<i;e++){let i=a[e],o=y(i);if(o!=null){var r;if(typeof o!=`string`&&typeof(i==null?void 0:i.s)==`object`&&!((r=i.s)==null||(r=r.n)==null)&&r.pattern){n.add(t.numfmt.format(i.s.n.pattern,o,{throws:!1}));continue}let e=typeof o==`string`?o:String(o);g(e)&&n.add(e)}}}return[...n]}};C=f([d(0,(0,t.Inject)(t.Injector)),d(1,(0,t.Inject)(n.DataValidationModel))],C);let w=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._instanceService=e,this._registerOtherFormulaService=t,this._dataValidationCacheService=n,this._dataValidationModel=r,this._validatorRegistryService=i,this._listCacheService=a,u(this,`_formulaRuleMap`,new Map),this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(let n in e){let r=e[n];if(this._instanceService.getUnitType(n)===t.UniverInstanceType.UNIVER_SHEET)for(let e in r){let t=r[e],i=this._ensureRuleFormulaMap(n,e);t.forEach(t=>{var r;let a=(r=t.extra)==null?void 0:r.ruleId;if(a&&i.get(a)){let t=this._dataValidationModel.getRuleById(n,e,a);t&&(this._listCacheService.markRuleDirty(n,e,a),this._dataValidationCacheService.markRangeDirty(n,e,t.ranges))}})}}}))}_ensureRuleFormulaMap(e,t){let n=this._formulaRuleMap.get(e);n||(n=new Map,this._formulaRuleMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_registerSingleFormula(e,t,n,i){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,n,[{startColumn:0,endColumn:0,startRow:0,endRow:0}],{ruleId:i},r.OtherFormulaBizType.DATA_VALIDATION,i)}addRule(e,n,r){if(!_(r.type,this._validatorRegistryService)&&r.type!==t.DataValidationType.CHECKBOX){let{formula1:i,formula2:a,uid:o}=r,s=(0,t.isFormulaString)(i),c=(0,t.isFormulaString)(a);if(!s&&!c)return;let l=this._ensureRuleFormulaMap(e,n),u=[void 0,void 0];s&&(u[0]={id:this._registerSingleFormula(e,n,i,o),text:i}),c&&(u[1]={id:this._registerSingleFormula(e,n,a,o),text:a}),l.set(o,u)}}removeRule(e,t,n){let r=this._ensureRuleFormulaMap(e,t).get(n);if(!r)return;let[i,a]=r,o=[i==null?void 0:i.id,a==null?void 0:a.id].filter(Boolean);o.length&&this._registerOtherFormulaService.deleteFormula(e,t,o)}getRuleFormulaResult(e,t,n){let r=this._ensureRuleFormulaMap(e,t).get(n);if(!r)return Promise.resolve(null);let i=async n=>n&&this._registerOtherFormulaService.getFormulaValue(e,t,n.id);return Promise.all([i(r[0]),i(r[1])])}getRuleFormulaResultSync(e,t,n){let r=this._ensureRuleFormulaMap(e,t).get(n);if(r)return r.map(n=>{if(n)return this._registerOtherFormulaService.getFormulaValueSync(e,t,n.id)})}getRuleFormulaInfo(e,t,n){return this._ensureRuleFormulaMap(e,t).get(n)}};w=f([d(0,t.IUniverInstanceService),d(1,(0,t.Inject)(r.RegisterOtherFormulaService)),d(2,(0,t.Inject)(p)),d(3,(0,t.Inject)(n.DataValidationModel)),d(4,(0,t.Inject)(n.DataValidatorRegistryService)),d(5,(0,t.Inject)(C))],w);var ne=class e{constructor(e,n,r,i,a=!1){this._unitId=n,this._subUnitId=r,this._univerInstanceService=i,this._disableTree=a,u(this,`_map`,void 0),u(this,`_tree`,new t.RBush),u(this,`_dirty`,!0),u(this,`_buildTree`,()=>{if(!this._dirty||this._disableTree)return;this._tree.clear();let e=[];this._map.forEach((t,n)=>{t.forEach(t=>{e.push({minX:t.startRow,maxX:t.endRow,minY:t.startColumn,maxY:t.endColumn,ruleId:n})})}),this._tree.load(e),this._dirty=!1}),u(this,`_debonceBuildTree`,(0,t.debounce)(this._buildTree,0)),this._map=e,this._buildTree()}get _worksheet(){var e;return(e=this._univerInstanceService.getUnit(this._unitId,t.UniverInstanceType.UNIVER_SHEET))==null?void 0:e.getSheetBySheetId(this._subUnitId)}_addRule(e,n){if(!this._worksheet)return;let r=t.Rectangle.mergeRanges(n.map(e=>t.Range.transformRange(e,this._worksheet)));this._map.forEach((e,n)=>{let i=t.Rectangle.subtractMulti(e,r);i.length===0?this._map.delete(n):this._map.set(n,i)}),this._dirty=!0,this._map.set(e,r),this._debonceBuildTree()}addRule(e){this._addRule(e.uid,e.ranges)}removeRange(e){if(!this._worksheet)return;let n=e.map(e=>t.Range.transformRange(e,this._worksheet));this._map.forEach((e,r)=>{let i=t.Rectangle.subtractMulti(e,n);i.length===0?this._map.delete(r):this._map.set(r,i)}),this._dirty=!0,this._debonceBuildTree()}_removeRule(e){this._map.delete(e),this._dirty=!0,this._debonceBuildTree()}removeRule(e){this._removeRule(e.uid)}updateRange(e,t){this._removeRule(e),this._addRule(e,t)}addRangeRules(e){e.forEach(({id:e,ranges:n})=>{if(!n.length)return;let r=this._map.get(e);r?(this._map.set(e,t.Rectangle.mergeRanges([...r,...n])),r=this._map.get(e)):(r=n,this._map.set(e,r)),this._map.forEach((r,i)=>{if(i===e)return;let a=t.Rectangle.subtractMulti(r,n);a.length===0?this._map.delete(i):this._map.set(i,a)})}),this._dirty=!0,this._debonceBuildTree()}diff(e){let n=[],r=0;return e.forEach((e,i)=>{var a;let o=(a=this._map.get(e.uid))==null?[]:a,s=e.ranges;o.length!==0&&(o.length!==s.length||o.some((e,n)=>!t.Rectangle.equals(e,s[n])))&&n.push({type:`update`,ruleId:e.uid,oldRanges:s,newRanges:t.Rectangle.sort(o),rule:e}),o.length===0&&(n.push({type:`delete`,rule:e,index:i-r}),r++)}),n}diffWithAddition(e,n){let r=[],i=0;return e.forEach((e,n)=>{var a;let o=(a=this._map.get(e.uid))==null?[]:a,s=e.ranges;o.length!==0&&(o.length!==s.length||o.some((e,n)=>!t.Rectangle.equals(e,s[n])))&&r.push({type:`update`,ruleId:e.uid,oldRanges:s,newRanges:t.Rectangle.sort(o),rule:e}),o.length===0&&(r.push({type:`delete`,rule:e,index:n-i}),i++)}),Array.from(n).forEach(e=>{var n;let i=(n=this._map.get(e.uid))==null?[]:n;r.push({type:`add`,rule:{...e,ranges:t.Rectangle.sort(i)}})}),r}clone(){return new e(new Map(t.Tools.deepClone(Array.from(this._map.entries()))),this._unitId,this._subUnitId,this._univerInstanceService,!0)}getValue(e,t){this._dirty&&this._buildTree();let n=this._tree.search({minX:e,maxX:e,minY:t,maxY:t});return n.length>0?n[0].ruleId:void 0}};let T=class extends t.Disposable{constructor(e,t,n,r,i,o,s){super(),this._dataValidationModel=e,this._univerInstanceService=t,this._dataValidatorRegistryService=n,this._dataValidationCacheService=r,this._dataValidationFormulaService=i,this._dataValidationCustomFormulaService=o,this._commandService=s,u(this,`_ruleMatrixMap`,new Map),u(this,`_validStatusChange$`,new a.Subject),u(this,`_ruleChange$`,new a.Subject),u(this,`ruleChange$`,this._ruleChange$.asObservable()),u(this,`validStatusChange$`,this._validStatusChange$.asObservable()),this._initRuleUpdateListener(),this.disposeWithMe(()=>{this._ruleChange$.complete(),this._validStatusChange$.complete()}),this._initUniverInstanceListener()}_initUniverInstanceListener(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{this._ruleMatrixMap.delete(e.getUnitId())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===i.RemoveSheetMutation.id){let{unitId:t,subUnitId:n}=e.params,r=this._ruleMatrixMap.get(t);r&&r.delete(n)}}))}_initRuleUpdateListener(){let e=this._dataValidationModel.getAll();for(let[t,n]of e)for(let[e,r]of n)for(let n of r)this._addRule(t,e,n),this._ruleChange$.next({type:`add`,unitId:t,subUnitId:e,rule:n,source:`patched`});this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{switch(e.type){case`add`:this._addRule(e.unitId,e.subUnitId,e.rule);break;case`update`:this._updateRule(e.unitId,e.subUnitId,e.rule.uid,e.oldRule,e.updatePayload);break;case`remove`:this._removeRule(e.unitId,e.subUnitId,e.rule);break}this._ruleChange$.next(e)}))}_ensureRuleMatrix(e,t){let n=this._ruleMatrixMap.get(e);n||(n=new Map,this._ruleMatrixMap.set(e,n));let r=n.get(t);return r||(r=new ne(new Map,e,t,this._univerInstanceService),n.set(t,r)),r}_addRuleSideEffect(e,t,n){this._ensureRuleMatrix(e,t).addRule(n),this._dataValidationCacheService.addRule(e,t,n),this._dataValidationFormulaService.addRule(e,t,n),this._dataValidationCustomFormulaService.addRule(e,t,n)}_addRule(e,t,n){(Array.isArray(n)?n:[n]).forEach(n=>{this._addRuleSideEffect(e,t,n)})}_updateRule(e,t,r,i,a){let o=this._ensureRuleMatrix(e,t),s={...i,...a.payload};a.type===n.UpdateRuleType.RANGE?o.updateRange(r,a.payload):a.type===n.UpdateRuleType.ALL&&o.updateRange(r,a.payload.ranges),this._dataValidationCacheService.removeRule(e,t,i),this._dataValidationCacheService.addRule(e,t,s),this._dataValidationFormulaService.removeRule(e,t,i.uid),this._dataValidationFormulaService.addRule(e,t,s),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,r),this._dataValidationCustomFormulaService.addRule(e,t,s)}_removeRule(e,t,n){this._ensureRuleMatrix(e,t).removeRule(n),this._dataValidationCacheService.removeRule(e,t,n),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,n.uid)}getValidator(e){return this._dataValidatorRegistryService.getValidatorItem(e)}getRuleIdByLocation(e,t,n,r){return this._ensureRuleMatrix(e,t).getValue(n,r)}getRuleByLocation(e,t,n,r){let i=this.getRuleIdByLocation(e,t,n,r);if(i)return this._dataValidationModel.getRuleById(e,t,i)}validator(e,n,r){let{col:i,row:a,unitId:o,subUnitId:s,worksheet:c}=n,l=(t,n)=>{r&&r(t,n),n&&this._validStatusChange$.next({unitId:o,subUnitId:s,ruleId:e.uid,status:t,row:a,col:i})},u=c.getCellValueOnly(a,i),d=this.getValidator(e.type),f=c.getCellRaw(a,i),p=y(f);if(d){let r=this._dataValidationCacheService.ensureCache(o,s),c=r.getValue(a,i);return c==null?(r.setValue(a,i,t.DataValidationStatus.VALIDATING),d.validator({value:p,unitId:o,subUnitId:s,row:a,column:i,worksheet:n.worksheet,workbook:n.workbook,interceptValue:y(u),t:f==null?void 0:f.t},e).then(e=>{let n=e?t.DataValidationStatus.VALID:t.DataValidationStatus.INVALID,o=r.getValue(a,i);n===t.DataValidationStatus.VALID?r.realDeleteValue(a,i):r.setValue(a,i,n),l(n,c!==o)}),t.DataValidationStatus.VALIDATING):(l(c==null?t.DataValidationStatus.VALID:c,!1),c==null?t.DataValidationStatus.VALID:c)}else return l(t.DataValidationStatus.VALID,!1),t.DataValidationStatus.VALID}getRuleObjectMatrix(e,t){return this._ensureRuleMatrix(e,t)}getRuleById(e,t,n){return this._dataValidationModel.getRuleById(e,t,n)}getRuleIndex(e,t,n){return this._dataValidationModel.getRuleIndex(e,t,n)}getRules(e,t){return[...this._dataValidationModel.getRules(e,t)]}getUnitRules(e){return this._dataValidationModel.getUnitRules(e)}deleteUnitRules(e){return this._dataValidationModel.deleteUnitRules(e)}getSubUnitIds(e){return this._dataValidationModel.getSubUnitIds(e)}getAll(){return this._dataValidationModel.getAll()}};T=f([d(0,(0,t.Inject)(n.DataValidationModel)),d(1,t.IUniverInstanceService),d(2,(0,t.Inject)(n.DataValidatorRegistryService)),d(3,(0,t.Inject)(p)),d(4,(0,t.Inject)(w)),d(5,(0,t.Inject)(v)),d(6,t.ICommandService)],T);function re(e,n){return t.Tools.isBlank(e)?n.t(`dataValidation.validFail.value`):(0,t.isFormulaString)(e)?n.t(`dataValidation.validFail.primitive`):``}let E=e=>t.Tools.isDefine(e)&&String(e).toLowerCase()===`true`?`1`:String(e).toLowerCase()===`false`?`0`:e;var D=class extends n.BaseDataValidator{constructor(...e){super(...e),u(this,`id`,t.DataValidationType.CHECKBOX),u(this,`title`,`dataValidation.checkbox.title`),u(this,`operators`,[]),u(this,`scopes`,[`sheet`]),u(this,`order`,41),u(this,`offsetFormulaByRange`,!1),u(this,`_formulaService`,this.injector.get(w)),u(this,`skipDefaultFontRender`,(e,t,n)=>{let{unitId:r,subUnitId:i}=n,{formula1:a,formula2:o}=this.parseFormulaSync(e,r,i),s=`${t==null?``:t}`;return!s||s===`${a}`||s===`${o}`})}validatorFormula(e,n,r){let{formula1:i,formula2:a}=e,o=i===a;if(t.Tools.isBlank(i)&&t.Tools.isBlank(a))return{success:!0};if(o)return{success:!1,formula1:this.localeService.t(`dataValidation.validFail.checkboxEqual`),formula2:this.localeService.t(`dataValidation.validFail.checkboxEqual`)};let s=re(i,this.localeService),c=re(a,this.localeService);return{success:!s&&!c,formula1:s,formula2:c}}async parseFormula(e,n,r){var i,a;let{formula1:o=1,formula2:s=0}=e,c=await this._formulaService.getRuleFormulaResult(n,r,e.uid),l=(0,t.isFormulaString)(o)?m(c==null||(i=c[0])==null||(i=i.result)==null?void 0:i[0][0]):o,u=(0,t.isFormulaString)(s)?m(c==null||(a=c[1])==null||(a=a.result)==null?void 0:a[0][0]):s,d=g(String(l))&&g(String(u));return{formula1:E(l),formula2:E(u),originFormula1:l,originFormula2:u,isFormulaValid:d}}getExtraStyle(e,n){return{tb:t.WrapStrategy.CLIP}}parseFormulaSync(e,n,r){var i,a;let{formula1:o=1,formula2:s=0}=e,c=this._formulaService.getRuleFormulaResultSync(n,r,e.uid),l=(0,t.isFormulaString)(o)?m(c==null||(i=c[0])==null||(i=i.result)==null?void 0:i[0][0]):o,u=(0,t.isFormulaString)(s)?m(c==null||(a=c[1])==null||(a=a.result)==null?void 0:a[0][0]):s,d=g(String(l))&&g(String(u));return{formula1:E(l),formula2:E(u),originFormula1:l,originFormula2:u,isFormulaValid:d}}async isValidType(e,n,r){let{value:i,unitId:a,subUnitId:o}=e,{formula1:s,formula2:c,originFormula1:l,originFormula2:u}=await this.parseFormula(r,a,o);return!t.Tools.isDefine(s)||!t.Tools.isDefine(c)?!0:t.Tools.isDefine(i)&&(String(i)===String(s)||String(i)===String(c)||String(i)===String(l==null?``:l)||String(i)===String(u==null?``:u))}generateRuleErrorMessage(e){return this.localeService.t(`dataValidation.checkbox.error`)}generateRuleName(e){return this.titleStr}};let ie={[t.DataValidationOperator.BETWEEN]:`dataValidation.date.operators.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.date.operators.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.date.operators.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.operators.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.date.operators.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.operators.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.operators.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.operators.notEqual`};t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL;let O={[t.DataValidationOperator.BETWEEN]:`dataValidation.date.ruleName.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.date.ruleName.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.date.ruleName.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.ruleName.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.date.ruleName.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.ruleName.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.ruleName.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.ruleName.notEqual`,NONE:`dataValidation.date.ruleName.legal`},ae={[t.DataValidationOperator.BETWEEN]:`dataValidation.date.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.date.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.date.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.date.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.date.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.date.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.date.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.date.errorMsg.notEqual`,NONE:`dataValidation.date.errorMsg.legal`},k=[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.NOT_BETWEEN],A=`{FORMULA1}`,j=`{FORMULA2}`,M=e=>{var n,r;if(e==null||typeof e==`boolean`)return;if(typeof e==`number`||!Number.isNaN(+e))return+e;let i=(n=t.numfmt.parseDate(e))==null?void 0:n.v;return t.Tools.isDefine(i)?i:(r=t.numfmt.parseDate((0,t.dayjs)(e).format(`YYYY-MM-DD HH:mm:ss`)))==null?void 0:r.v};var oe=class extends n.BaseDataValidator{constructor(...e){super(...e),u(this,`id`,t.DataValidationType.DATE),u(this,`title`,`dataValidation.date.title`),u(this,`order`,40),u(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),u(this,`scopes`,[`sheet`]),u(this,`_customFormulaService`,this.injector.get(v)),u(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder))}async parseFormula(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=g(String(o==null?void 0:o.v))&&g(String(s==null?void 0:s.v));return{formula1:M((0,t.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:M((0,t.isFormulaString)(l)?s==null?void 0:s.v:l),isFormulaValid:u}}async isValidType(e){let{interceptValue:n,value:r}=e;return typeof r==`number`&&typeof n==`string`||typeof n==`string`?!!t.numfmt.parseDate(n):!1}_validatorSingleFormula(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e)||!!(e&&t.numfmt.parseDate(e)))}validatorFormula(e,t,n){let r=e.operator;if(!r)return{success:!0};let i=this._validatorSingleFormula(e.formula1),a=this.localeService.t(`dataValidation.validFail.date`);if(k.includes(r)){let t=this._validatorSingleFormula(e.formula2);return{success:i&&t,formula1:i?void 0:a,formula2:t?void 0:a}}return{success:i,formula1:i?void 0:a}}normalizeFormula(e,n,r){let{formula1:i,formula2:a,bizInfo:o}=e,s=e=>{if(!e)return e;let n;if(!Number.isNaN(+e))n=t.numfmt.dateFromSerial(+e);else{var r;let i=(r=t.numfmt.parseDate(e))==null?void 0:r.v;if(i==null)return``;n=t.numfmt.dateFromSerial(i)}return(0,t.dayjs)(`${n[0]}/${n[1]}/${n[2]} ${n[3]}:${n[4]}:${n[5]}`).format(o!=null&&o.showTime?`YYYY-MM-DD HH:mm:ss`:`YYYY-MM-DD`)};return{formula1:(0,t.isFormulaString)(i)?i:s(`${i}`),formula2:(0,t.isFormulaString)(a)?a:s(`${a}`)}}transform(e,t,n){let{value:r}=e;return{...e,value:M(r)}}get operatorNames(){return this.operators.map(e=>this.localeService.t(ie[e]))}generateRuleName(e){var t,n;if(!e.operator)return this.localeService.t(O.NONE);let r=this.localeService.t(O[e.operator]).replace(A,(t=e.formula1)==null?``:t).replace(j,(n=e.formula2)==null?``:n);return`${this.titleStr} ${r}`}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;let{transformedFormula1:n,transformedFormula2:r}=S(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ae[e.operator]).replace(A,n==null?``:n).replace(j,r==null?``:r)}`}};t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL,t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL;let N={[t.DataValidationOperator.BETWEEN]:`dataValidation.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`dataValidation.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`dataValidation.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`dataValidation.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`dataValidation.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`dataValidation.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`dataValidation.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`dataValidation.errorMsg.notEqual`,NONE:`dataValidation.errorMsg.legal`};function P(e){return+e}var se=class extends n.BaseDataValidator{constructor(...e){super(...e),u(this,`_customFormulaService`,this.injector.get(v)),u(this,`id`,t.DataValidationType.DECIMAL),u(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder)),u(this,`title`,`dataValidation.decimal.title`),u(this,`order`,20),u(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),u(this,`scopes`,[`sheet`])}_isFormulaOrNumber(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e))}async isValidType(e,t,n){let{value:r}=e;return!Number.isNaN(P(r))}transform(e,t,n){let{value:r}=e;return{...e,value:P(r)}}_parseNumber(e){return e==null?NaN:+e}async parseFormula(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=g(String(o==null?void 0:o.v))&&g(String(s==null?void 0:s.v));return{formula1:this._parseNumber((0,t.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:this._parseNumber((0,t.isFormulaString)(l)?s==null?void 0:s.v:l),isFormulaValid:u}}validatorFormula(e,n,r){let i=e.operator;if(!i)return{success:!0};let a=t.Tools.isDefine(e.formula1)&&this._isFormulaOrNumber(e.formula1),o=t.Tools.isDefine(e.formula2)&&this._isFormulaOrNumber(e.formula2),s=k.includes(i),c=this.localeService.t(`dataValidation.validFail.number`);return s?{success:a&&o,formula1:a?void 0:c,formula2:o?void 0:c}:{success:a,formula1:a?``:c}}generateRuleErrorMessage(e,t){if(!e.operator)return this.localeService.t(N.NONE).replace(`{TYPE}`,this.titleStr);let{transformedFormula1:n,transformedFormula2:r}=S(this._lexerTreeBuilder,e,t);return`${this.localeService.t(N[e.operator]).replace(A,n==null?``:n).replace(j,r==null?``:r)}`}};function ce(e){if(!e)return[];let n=new Set;for(let i=0,a=e.length;i<a;i++){let a=e[i];if(a)for(let e=0,i=a.length;e<i;e++){let i=a[e],o=y(i);if(o!=null){var r;if(typeof o!=`string`&&typeof(i==null?void 0:i.s)==`object`&&!((r=i.s)==null||(r=r.n)==null)&&r.pattern){n.add(t.numfmt.format(i.s.n.pattern,o,{throws:!1}));continue}let e=typeof o==`string`?o:String(o);g(e)&&n.add(e)}}}return[...n]}let le=[`if`,`indirect`,`choose`,`offset`];function ue(e,n){if(!(0,t.isFormulaString)(e)||(0,r.isReferenceString)(e.slice(1)))return!0;let i=n.sequenceNodesBuilder(e);return i&&i.some(e=>typeof e==`object`&&e.nodeType===r.sequenceNodeType.FUNCTION&&le.indexOf(e.token.toLowerCase())>-1)}function de(e,n){let{formula1:i=``,ranges:a}=e;if((0,r.isReferenceString)(i.slice(1))){let e=(0,r.deserializeRangeWithSheet)(i.slice(1));if((!e.sheetName||e.sheetName===n)&&a.some(n=>t.Rectangle.intersects(n,e.range)))return!0}return!1}var F=class extends n.BaseDataValidator{constructor(...e){super(...e),u(this,`formulaService`,this.injector.get(w)),u(this,`_lexer`,this.injector.get(r.LexerTreeBuilder)),u(this,`_univerInstanceService`,this.injector.get(t.IUniverInstanceService)),u(this,`_listCacheService`,this.injector.get(C)),u(this,`order`,50),u(this,`offsetFormulaByRange`,!1),u(this,`id`,t.DataValidationType.LIST),u(this,`title`,`dataValidation.list.title`),u(this,`operators`,[]),u(this,`scopes`,[`sheet`]),u(this,`skipDefaultFontRender`,e=>e.renderMode!==t.DataValidationRenderMode.TEXT)}validatorFormula(e,n,r){var i,a;let o=!t.Tools.isBlank(e.formula1),s=ue((i=e.formula1)==null?``:i,this._lexer),c=(a=this._univerInstanceService.getUnit(n,t.UniverInstanceType.UNIVER_SHEET))==null||(a=a.getSheetBySheetId(r))==null?void 0:a.getName(),l=de(e,c==null?``:c);return{success:!!(o&&s&&!l),formula1:o?s?l?this.localeService.t(`dataValidation.validFail.listIntersects`):void 0:this.localeService.t(`dataValidation.validFail.listInvalid`):this.localeService.t(`dataValidation.validFail.list`)}}getExtraStyle(e,n,{style:r}){var i;let a=(i=r.tb===t.WrapStrategy.OVERFLOW?t.WrapStrategy.CLIP:r.tb)==null?t.WrapStrategy.WRAP:i;if(e.type===t.DataValidationType.LIST&&(e.renderMode===t.DataValidationRenderMode.ARROW||e.renderMode===t.DataValidationRenderMode.TEXT)){let t=this.getListWithColorMap(e)[`${n==null?``:n}`];if(t)return{bg:{rgb:t},tb:a}}return{tb:a}}parseCellValue(e){return x(e.toString())}async parseFormula(e,t,n){var r;let i=await this.formulaService.getRuleFormulaResult(t,n,e.uid),a=m(i==null||(r=i[0])==null||(r=r.result)==null?void 0:r[0][0]);return{formula1:void 0,formula2:void 0,isFormulaValid:g(String(a))}}async isValidType(e,n,r){let{value:i,unitId:a,subUnitId:o}=e,{formula1:s=``}=r,c=(0,t.isFormulaString)(s)?this._listCacheService.getOrCompute(a,o,r).list:x(s);return this.parseCellValue(i).every(e=>c.includes(e))}generateRuleName(){return this.localeService.t(`dataValidation.list.name`)}generateRuleErrorMessage(){return this.localeService.t(`dataValidation.list.error`)}_getUnitAndSubUnit(e,n){var r,i;let a=(r=e?this._univerInstanceService.getUniverSheetInstance(e):void 0)==null?this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET):r;if(!a)return null;let o=(i=n?a.getSheetBySheetId(n):void 0)==null?a.getActiveSheet():i;return o?{unitId:a.getUnitId(),subUnitId:o.getSheetId()}:null}getList(e,t,n){let r=this._getUnitAndSubUnit(t,n);if(!r)return[];let{unitId:i,subUnitId:a}=r;return this._listCacheService.getOrCompute(i,a,e).list}async getListAsync(e,n,r){var i;let{formula1:a=``}=e,o=this._getUnitAndSubUnit(n,r);if(!o)return[];let{unitId:s,subUnitId:c}=o,l=await this.formulaService.getRuleFormulaResult(s,c,e.uid);return(0,t.isFormulaString)(a)?ce(l==null||(i=l[0])==null||(i=i.result)==null?void 0:i[0][0]):x(a)}getListWithColor(e,t,n){let r=this._getUnitAndSubUnit(t,n);if(!r)return[];let{unitId:i,subUnitId:a}=r;return this._listCacheService.getOrCompute(i,a,e).listWithColor}getListWithColorMap(e,t,n){let r=this._getUnitAndSubUnit(t,n);if(!r)return{};let{unitId:i,subUnitId:a}=r;return this._listCacheService.getOrCompute(i,a,e).colorMap}},fe=class extends n.BaseDataValidator{constructor(...e){super(...e),u(this,`id`,t.DataValidationType.TEXT_LENGTH),u(this,`title`,`dataValidation.textLength.title`),u(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder)),u(this,`order`,30),u(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),u(this,`scopes`,[`sheet`]),u(this,`_customFormulaService`,this.injector.get(v))}_isFormulaOrInt(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}validatorFormula(e,n,r){let i=e.operator;if(!i)return{success:!1};let a=t.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),o=t.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),s=k.includes(i),c=this.localeService.t(`dataValidation.validFail.number`);return s?{success:a&&o,formula1:a?void 0:c,formula2:o?void 0:c}:{success:a,formula1:c}}_parseNumber(e){return e==null?NaN:+e}async parseFormula(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=g(String(o==null?void 0:o.v))&&g(String(s==null?void 0:s.v));return{formula1:this._parseNumber((0,t.isFormulaString)(c)?o==null?void 0:o.v:c),formula2:this._parseNumber((0,t.isFormulaString)(l)?s==null?void 0:s.v:l),isFormulaValid:u}}transform(e,t,n){return{...e,value:e.value.toString().length}}async isValidType(e,t,n){let{value:r}=e;return typeof r==`string`||typeof r==`number`}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;let{transformedFormula1:r,transformedFormula2:i}=S(this._lexerTreeBuilder,e,t);return`${this.localeService.t(n.TextLengthErrorTitleMap[e.operator]).replace(A,r==null?``:r).replace(j,i==null?``:i)}`}};function I(e){var n,r;return e?e.p?!((n=(r=e.p.body)==null?void 0:r.dataStream)==null?``:n).slice(0,-2).trim():t.Tools.isBlank(e.v):!0}function L(e,a,o,s,c=`command`,l=!0){let u=s.get(r.LexerTreeBuilder),d=s.get(n.DataValidatorRegistryService),f=[],p=[],m=s.get(T),h=(0,i.getSheetCommandTarget)(s.get(t.IUniverInstanceService),{unitId:e,subUnitId:a});if(!h)return{redoMutations:f,undoMutations:p};let{worksheet:g}=h,v=new t.ObjectMatrix,y=!1;function b(e,n){l&&e.forEach(e=>{t.Range.foreach(e,(e,t)=>{let r=g.getCellRaw(e,t),i=ee(r);(I(r)||i===n)&&!(r!=null&&r.p)&&(y=!0,v.setValue(e,t,{v:n,p:null}))})})}if(o.forEach(r=>{switch(r.type){case`delete`:f.push({id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.rule.uid,source:c}}),p.unshift({id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:a,rule:r.rule,index:r.index,source:c}});break;case`update`:{if(_(r.rule.type,d)){let i=r.oldRanges[0].startRow,o=r.oldRanges[0].startColumn,s=r.newRanges[0].startRow,l=r.newRanges[0].startColumn,d=s-i,m=l-o,h=(0,t.isFormulaString)(r.rule.formula1)?u.moveFormulaRefOffset(r.rule.formula1,m,d):r.rule.formula1,g=(0,t.isFormulaString)(r.rule.formula2)?u.moveFormulaRefOffset(r.rule.formula2,m,d):r.rule.formula2;h!==r.rule.formula1||g!==r.rule.formula2||!(0,t.isRangesEqual)(r.newRanges,r.oldRanges)?(f.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.ALL,payload:{formula1:h,formula2:g,ranges:r.newRanges}}}}),p.unshift({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.ALL,payload:{formula1:r.rule.formula1,formula2:r.rule.formula2,ranges:r.oldRanges}}}})):(f.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.newRanges},source:c}}),p.unshift({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.oldRanges},source:c}}))}else f.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.newRanges},source:c}}),p.unshift({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.ruleId,payload:{type:n.UpdateRuleType.RANGE,payload:r.oldRanges},source:c}});let i=m.getRuleById(e,a,r.ruleId);if(i&&i.type===t.DataValidationType.CHECKBOX){let n=m.getValidator(t.DataValidationType.CHECKBOX).parseFormulaSync(i,e,a);b(r.newRanges,n.formula2)}break}case`add`:if(f.push({id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:a,rule:r.rule,source:c}}),p.unshift({id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:a,ruleId:r.rule.uid,source:c}}),r.rule.type===t.DataValidationType.CHECKBOX){let n=m.getValidator(t.DataValidationType.CHECKBOX).parseFormulaSync(r.rule,e,a);b(r.rule.ranges,n.originFormula2)}break;default:break}}),y){let t={id:i.SetRangeValuesMutation.id,params:{unitId:e,subUnitId:a,cellValue:v.getData()}},n={id:i.SetRangeValuesMutation.id,params:(0,i.SetRangeValuesUndoMutationFactory)(s,t.params)};f.push(t),p.push(n)}return{redoMutations:f,undoMutations:p}}let R={type:t.CommandType.COMMAND,id:`sheet.command.updateDataValidationRuleRange`,handler(e,n){if(!n)return!1;let{unitId:r,subUnitId:i,ranges:a,ruleId:o}=n,s=e.get(T),c=e.get(t.ICommandService),l=e.get(t.IUndoRedoService);if(!s.getRuleById(r,i,o))return!1;let u=s.getRuleObjectMatrix(r,i).clone();u.updateRange(o,a);let{redoMutations:d,undoMutations:f}=L(r,i,u.diff(s.getRules(r,i)),e);return l.pushUndoRedo({undoMutations:f,redoMutations:d,unitID:r}),(0,t.sequenceExecute)(d,c),!0}},z={type:t.CommandType.COMMAND,id:`sheet.command.addDataValidation`,handler(e,r){if(!r)return!1;let{unitId:i,subUnitId:a,rule:o}=r,s=e.get(T),c=e.get(t.ICommandService),l=e.get(t.IUndoRedoService),u=s.getRuleObjectMatrix(i,a).clone();u.addRule(o);let d=u.diff(s.getRules(i,a)),f=s.getValidator(o.type),p={unitId:i,subUnitId:a,rule:{...o,...f==null?void 0:f.normalizeFormula(o,i,a)}},{redoMutations:m,undoMutations:h}=L(i,a,d,e);return m.push({id:n.AddDataValidationMutation.id,params:p}),h.unshift({id:n.RemoveDataValidationMutation.id,params:{unitId:i,subUnitId:a,ruleId:o.uid}}),l.pushUndoRedo({unitID:i,redoMutations:m,undoMutations:h}),(0,t.sequenceExecute)(m,c),!0}},B={type:t.CommandType.COMMAND,id:`sheets.command.update-data-validation-setting`,handler(e,r){if(!r)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(T),c=e.get(n.DataValidatorRegistryService),{unitId:l,subUnitId:u,ruleId:d,setting:f}=r,p=c.getValidatorItem(f.type);if(!p)return!1;let m=s.getRuleById(l,u,d);if(!m)return!1;let h={...m,...f};if(!p.validatorFormula(h,l,u).success)return!1;let g={unitId:l,subUnitId:u,ruleId:d,payload:{type:n.UpdateRuleType.SETTING,payload:{...f,...p.normalizeFormula(h,l,u)}}},_=[{id:n.UpdateDataValidationMutation.id,params:g}],v={unitId:l,subUnitId:u,ruleId:d,payload:{type:n.UpdateRuleType.SETTING,payload:(0,n.getRuleSetting)(m)}},y=[{id:n.UpdateDataValidationMutation.id,params:v}];if(f.type===t.DataValidationType.CHECKBOX){let n=m.ranges,r=(0,i.getSheetCommandTarget)(e.get(t.IUniverInstanceService),{unitId:l,subUnitId:u});if(r){let a=new t.ObjectMatrix,{worksheet:o}=r,{formula2:s=0,formula1:c=1}=m,{formula2:d=0,formula1:p=1}=f,h=!1;if(n.forEach(e=>{t.Range.foreach(e,(e,t)=>{let n=o.getCellRaw(e,t),r=ee(n);(I(n)||r===String(s))&&!(n!=null&&n.p)?(a.setValue(e,t,{v:d,p:null}),h=!0):r===String(c)&&!(n!=null&&n.p)&&(a.setValue(e,t,{v:p,p:null}),h=!0)})}),h){let t={id:i.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:u,cellValue:a.getData()}},n={id:i.SetRangeValuesMutation.id,params:(0,i.SetRangeValuesUndoMutationFactory)(e,t.params)};_.push(t),y.push(n)}}}return(0,t.sequenceExecute)(_,a).result?(o.pushUndoRedo({unitID:l,redoMutations:_,undoMutations:y}),!0):!1}},V={type:t.CommandType.COMMAND,id:`sheets.command.update-data-validation-options`,handler(e,r){if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(T),{unitId:s,subUnitId:c,ruleId:l,options:u}=r,d=o.getRuleById(s,c,l);if(!d)return!1;let f={unitId:s,subUnitId:c,ruleId:l,payload:{type:n.UpdateRuleType.OPTIONS,payload:u}},p=[{id:n.UpdateDataValidationMutation.id,params:f}],m={unitId:s,subUnitId:c,ruleId:l,payload:{type:n.UpdateRuleType.OPTIONS,payload:(0,n.getRuleOptions)(d)}},h=[{id:n.UpdateDataValidationMutation.id,params:m}];return a.pushUndoRedo({unitID:s,redoMutations:p,undoMutations:h}),i.executeCommand(n.UpdateDataValidationMutation.id,f),!0}},H={type:t.CommandType.COMMAND,id:`sheets.command.clear-range-data-validation`,handler(e,n){if(!n)return!1;let{unitId:r,subUnitId:a,ranges:o}=n,s=e.get(t.ICommandService),c=(0,i.getSheetCommandTarget)(e.get(t.IUniverInstanceService),{unitId:r,subUnitId:a}),l=e.get(T);if(!c)return!1;let u=e.get(t.IUndoRedoService),d=l.getRuleObjectMatrix(r,a).clone();d.removeRange(o);let{redoMutations:f,undoMutations:p}=L(r,a,d.diff(l.getRules(r,a)),e);return u.pushUndoRedo({unitID:r,redoMutations:f,undoMutations:p}),(0,t.sequenceExecute)(f,s).result}},U={type:t.CommandType.COMMAND,id:`sheet.command.remove-all-data-validation`,handler(e,r){if(!r)return!1;let{unitId:i,subUnitId:a}=r,o=e.get(t.ICommandService),s=e.get(T),c=e.get(t.IUndoRedoService),l=[...s.getRules(i,a)],u={unitId:i,subUnitId:a,ruleId:l.map(e=>e.uid)},d=[{id:n.RemoveDataValidationMutation.id,params:u}],f=[{id:n.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:l}}];return c.pushUndoRedo({redoMutations:d,undoMutations:f,unitID:i}),o.executeCommand(n.RemoveDataValidationMutation.id,u),!0}},pe=(e,t)=>{let r=e.get(T),{unitId:i,subUnitId:a,ruleId:o,source:s}=t;if(Array.isArray(o)){let e=o.map(e=>r.getRuleById(i,a,e)).filter(Boolean);return[{id:n.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:e,source:s}}]}return[{id:n.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:{...r.getRuleById(i,a,o)},index:r.getRuleIndex(i,a,o)}}]},W={type:t.CommandType.COMMAND,id:`sheet.command.remove-data-validation-rule`,handler(e,r){if(!r)return!1;let{unitId:i,subUnitId:a,ruleId:o}=r,s=e.get(t.ICommandService),c=e.get(t.IUndoRedoService),l=e.get(T),u=[{id:n.RemoveDataValidationMutation.id,params:r}],d=[{id:n.AddDataValidationMutation.id,params:{unitId:i,subUnitId:a,rule:{...l.getRuleById(i,a,o)},index:l.getRuleIndex(i,a,o)}}];return c.pushUndoRedo({undoMutations:d,redoMutations:u,unitID:r.unitId}),s.executeCommand(n.RemoveDataValidationMutation.id,r),!0}},G=`SHEET_DATA_VALIDATION_PLUGIN`;var me=(e=>(e[e.OpenOrReOpen=0]=`OpenOrReOpen`,e[e.Solved=1]=`Solved`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(me||{}),he=(e=>(e[e.Unknown=0]=`Unknown`,e[e.Add=1]=`Add`,e[e.Reply=2]=`Reply`,e[e.Edit=3]=`Edit`,e[e.Delete=4]=`Delete`,e[e.Solve=5]=`Solve`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(he||{}),ge=(e=>(e[e.UNDEFINED=0]=`UNDEFINED`,e[e.OK=1]=`OK`,e[e.INTERNAL_ERROR=2]=`INTERNAL_ERROR`,e[e.PERMISSION_DENIED=3]=`PERMISSION_DENIED`,e[e.NOT_FOUND=4]=`NOT_FOUND`,e[e.UNAUTHENTICATED=5]=`UNAUTHENTICATED`,e[e.ALREADY_EXISTS=6]=`ALREADY_EXISTS`,e[e.INVALID_ARGUMENT=7]=`INVALID_ARGUMENT`,e[e.TOO_MANY_REQUESTS=8]=`TOO_MANY_REQUESTS`,e[e.COMPLETION_FINISHED=9]=`COMPLETION_FINISHED`,e[e.LOGIN_FAILED=10]=`LOGIN_FAILED`,e[e.MOBILE_VERIFY_CODE_MISMATCH=11]=`MOBILE_VERIFY_CODE_MISMATCH`,e[e.MOBILE_VERIFY_CODE_NOT_FOUND_OR_EXPIRED=12]=`MOBILE_VERIFY_CODE_NOT_FOUND_OR_EXPIRED`,e[e.EMAIL_VERIFY_CODE_MISMATCH=13]=`EMAIL_VERIFY_CODE_MISMATCH`,e[e.EMAIL_VERIFY_CODE_NOT_FOUND_OR_EXPIRED=14]=`EMAIL_VERIFY_CODE_NOT_FOUND_OR_EXPIRED`,e[e.AUTHORIZE_CODE_ILLEGAL=15]=`AUTHORIZE_CODE_ILLEGAL`,e[e.LOGIN_TOKEN_PROCESSING_FAILED=16]=`LOGIN_TOKEN_PROCESSING_FAILED`,e[e.CURRENT_STATUS_CANNOT_OPERATE=100]=`CURRENT_STATUS_CANNOT_OPERATE`,e[e.ERROR_AGAIN=101]=`ERROR_AGAIN`,e[e.USER_NOT_FOUND=201]=`USER_NOT_FOUND`,e[e.USER_IS_ANONYMOUS=202]=`USER_IS_ANONYMOUS`,e[e.CHANGESET_REVISION_CONFILICT=5001]=`CHANGESET_REVISION_CONFILICT`,e[e.SNAPSHOT_INVALID_SNAPSHOT=6001]=`SNAPSHOT_INVALID_SNAPSHOT`,e[e.SNAPSHOT_HAS_BEEN_REMOVED=6002]=`SNAPSHOT_HAS_BEEN_REMOVED`,e[e.ENSURE_SNAPSHOT_EXECUTION=6003]=`ENSURE_SNAPSHOT_EXECUTION`,e[e.APPLY_REJECT=7001]=`APPLY_REJECT`,e[e.APPLY_NON_SEQUENTIAL_REVISION=7002]=`APPLY_NON_SEQUENTIAL_REVISION`,e[e.APPLY_REVISION_CONFILICT=7003]=`APPLY_REVISION_CONFILICT`,e[e.APPLY_PERMISSION_DENIED=7004]=`APPLY_PERMISSION_DENIED`,e[e.APPLY_DUPLICATED=7005]=`APPLY_DUPLICATED`,e[e.CONNECTOR_DATA_TOO_LARGE=8001]=`CONNECTOR_DATA_TOO_LARGE`,e[e.LICENSE_MAX_UNITS_EXCEEDED=9001]=`LICENSE_MAX_UNITS_EXCEEDED`,e[e.LICENSE_MAX_MEMBERS_PER_UNIT_EXCEEDED=9002]=`LICENSE_MAX_MEMBERS_PER_UNIT_EXCEEDED`,e[e.LICENSE_IMPORT_SIZE_EXCEEDED=9003]=`LICENSE_IMPORT_SIZE_EXCEEDED`,e[e.LICENSE_EXPORT_SIZE_EXCEEDED=9004]=`LICENSE_EXPORT_SIZE_EXCEEDED`,e[e.LICENSE_DISTRO_REJECTED=9005]=`LICENSE_DISTRO_REJECTED`,e[e.YUUMI_UNABLE_LOAD_URL=10001]=`YUUMI_UNABLE_LOAD_URL`,e[e.YUUMI_URL_COL_OUT_OF_RANGE=10002]=`YUUMI_URL_COL_OUT_OF_RANGE`,e[e.YUUMI_RATE_OVER_LIMIT=10003]=`YUUMI_RATE_OVER_LIMIT`,e[e.YUUMI_SUBSCRIPTION_NOT_FOUND=10004]=`YUUMI_SUBSCRIPTION_NOT_FOUND`,e[e.YUUMI_NO_CUBOID_FOR_QUESTION=10010]=`YUUMI_NO_CUBOID_FOR_QUESTION`,e[e.YUUMI_ASYNCIO_CANCELLED=10011]=`YUUMI_ASYNCIO_CANCELLED`,e[e.YUUMI_TABLE_NOT_FOUND_IN_UNIT=10012]=`YUUMI_TABLE_NOT_FOUND_IN_UNIT`,e[e.YUUMI_ALL_TABLES_IS_INVALID=10013]=`YUUMI_ALL_TABLES_IS_INVALID`,e[e.YUUMI_PROMPT_MAX_TOKENS_EXCEEDED=10014]=`YUUMI_PROMPT_MAX_TOKENS_EXCEEDED`,e[e.YUUMI_AI_RUN_FAILED=10015]=`YUUMI_AI_RUN_FAILED`,e[e.YUUMI_CONNECTOR_URL_NOT_FOUND=10016]=`YUUMI_CONNECTOR_URL_NOT_FOUND`,e[e.PY_RUNTIME_SCRIPT_ERROR=11001]=`PY_RUNTIME_SCRIPT_ERROR`,e[e.INVITE_CODE_HAS_BEEN_UES=12001]=`INVITE_CODE_HAS_BEEN_UES`,e[e.INVALID_INVITE_CODE=12002]=`INVALID_INVITE_CODE`,e[e.INVITE_CODE_REQUIRED=12003]=`INVITE_CODE_REQUIRED`,e[e.USER_NOT_INVITED_CODE=12004]=`USER_NOT_INVITED_CODE`,e[e.INVITE_CODE_ALREADY_BOUND=12005]=`INVITE_CODE_ALREADY_BOUND`,e[e.WECHAT_HAS_BEEN_BOUND=13001]=`WECHAT_HAS_BEEN_BOUND`,e[e.MOBILE_HAS_BEEN_BOUND=13002]=`MOBILE_HAS_BEEN_BOUND`,e[e.EMAIL_HAS_BEEN_BOUND=13003]=`EMAIL_HAS_BEEN_BOUND`,e[e.ENTITLE_CAN_NOT_BUY_LOWER_OTP=14001]=`ENTITLE_CAN_NOT_BUY_LOWER_OTP`,e[e.ENTITLE_UPDOWN_GRADE_NOT_SUPPORT=14002]=`ENTITLE_UPDOWN_GRADE_NOT_SUPPORT`,e[e.ENTITLE_DUP_SUBSCRIPTION=14003]=`ENTITLE_DUP_SUBSCRIPTION`,e[e.PAYMENT_CHANNEL_NOT_SUPPORT=14004]=`PAYMENT_CHANNEL_NOT_SUPPORT`,e[e.ENTITLE_INVALID_COUPON_CODE=14005]=`ENTITLE_INVALID_COUPON_CODE`,e[e.ENTITLE_COUPON_EXPIRED=14006]=`ENTITLE_COUPON_EXPIRED`,e[e.ENTITLE_COUPON_USED_UP=14007]=`ENTITLE_COUPON_USED_UP`,e[e.ENTITLE_USE_COUPON_NOT_1ST_TRADE=14008]=`ENTITLE_USE_COUPON_NOT_1ST_TRADE`,e[e.ENTITLE_CHAT_LIMIT_EXCEED=14101]=`ENTITLE_CHAT_LIMIT_EXCEED`,e[e.ENTITLE_REPORT_LIMIT_EXCEED=14102]=`ENTITLE_REPORT_LIMIT_EXCEED`,e[e.ENTITLE_INSUFFICIENT_QUOTA=14103]=`ENTITLE_INSUFFICIENT_QUOTA`,e[e.ENTITLE_NEED_BILLING_ADDRESS=14301]=`ENTITLE_NEED_BILLING_ADDRESS`,e[e.REDEMPTION_INVALID_CODE=15001]=`REDEMPTION_INVALID_CODE`,e[e.REDEMPTION_CODE_INACTIVE=15002]=`REDEMPTION_CODE_INACTIVE`,e[e.REDEMPTION_CODE_FULLY_REDEEMED=15003]=`REDEMPTION_CODE_FULLY_REDEEMED`,e[e.REDEMPTION_CODE_NOT_STARTED=15004]=`REDEMPTION_CODE_NOT_STARTED`,e[e.REDEMPTION_USER_NOT_ELIGIBLE=15005]=`REDEMPTION_USER_NOT_ELIGIBLE`,e[e.REDEMPTION_USER_REDEEM_TIMES_EXCEED=15006]=`REDEMPTION_USER_REDEEM_TIMES_EXCEED`,e[e.REDEMPTION_CODE_HAS_BEEN_CREATED=15007]=`REDEMPTION_CODE_HAS_BEEN_CREATED`,e[e.DATA_SOURCE_TOO_LARGE=16001]=`DATA_SOURCE_TOO_LARGE`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(ge||{}),_e=(e=>(e[e.UNIVER_UNKNOWN=0]=`UNIVER_UNKNOWN`,e[e.UNIVER_DOC=1]=`UNIVER_DOC`,e[e.UNIVER_SHEET=2]=`UNIVER_SHEET`,e[e.UNIVER_SLIDE=3]=`UNIVER_SLIDE`,e[e.UNIVER_PROJECT=4]=`UNIVER_PROJECT`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(_e||{}),ve=(e=>(e[e.UNDEFINED=0]=`UNDEFINED`,e[e.TEXT=1]=`TEXT`,e[e.URL=2]=`URL`,e[e.IMAGE=3]=`IMAGE`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(ve||{}),K=(e=>(e[e.View=0]=`View`,e[e.Edit=1]=`Edit`,e[e.ManageCollaborator=2]=`ManageCollaborator`,e[e.Print=3]=`Print`,e[e.Duplicate=4]=`Duplicate`,e[e.Comment=5]=`Comment`,e[e.Copy=6]=`Copy`,e[e.Share=7]=`Share`,e[e.Export=8]=`Export`,e[e.MoveWorksheet=9]=`MoveWorksheet`,e[e.DeleteWorksheet=10]=`DeleteWorksheet`,e[e.HideWorksheet=11]=`HideWorksheet`,e[e.RenameWorksheet=12]=`RenameWorksheet`,e[e.CreateWorksheet=13]=`CreateWorksheet`,e[e.SetWorksheetStyle=14]=`SetWorksheetStyle`,e[e.EditWorksheetCell=15]=`EditWorksheetCell`,e[e.InsertHyperlink=16]=`InsertHyperlink`,e[e.Sort=17]=`Sort`,e[e.Filter=18]=`Filter`,e[e.PivotTable=19]=`PivotTable`,e[e.FloatImg=20]=`FloatImg`,e[e.History=21]=`History`,e[e.RwHgtClWdt=22]=`RwHgtClWdt`,e[e.ViemRwHgtClWdt=23]=`ViemRwHgtClWdt`,e[e.ViewFilter=24]=`ViewFilter`,e[e.MoveSheet=25]=`MoveSheet`,e[e.DeleteSheet=26]=`DeleteSheet`,e[e.HideSheet=27]=`HideSheet`,e[e.CopySheet=28]=`CopySheet`,e[e.RenameSheet=29]=`RenameSheet`,e[e.CreateSheet=30]=`CreateSheet`,e[e.SelectProtectedCells=31]=`SelectProtectedCells`,e[e.SelectUnProtectedCells=32]=`SelectUnProtectedCells`,e[e.SetCellStyle=33]=`SetCellStyle`,e[e.SetCellValue=34]=`SetCellValue`,e[e.SetRowStyle=35]=`SetRowStyle`,e[e.SetColumnStyle=36]=`SetColumnStyle`,e[e.InsertRow=37]=`InsertRow`,e[e.InsertColumn=38]=`InsertColumn`,e[e.DeleteRow=39]=`DeleteRow`,e[e.DeleteColumn=40]=`DeleteColumn`,e[e.EditExtraObject=41]=`EditExtraObject`,e[e.Delete=42]=`Delete`,e[e.RecoverHistory=43]=`RecoverHistory`,e[e.ViewHistory=44]=`ViewHistory`,e[e.CreatePermissionObject=45]=`CreatePermissionObject`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(K||{}),ye=(e=>(e[e.Reader=0]=`Reader`,e[e.Editor=1]=`Editor`,e[e.Owner=2]=`Owner`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(ye||{}),be=(e=>(e[e.Unkonwn=0]=`Unkonwn`,e[e.Workbook=1]=`Workbook`,e[e.Worksheet=2]=`Worksheet`,e[e.SelectRange=3]=`SelectRange`,e[e.Document=4]=`Document`,e[e.Slide=5]=`Slide`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(be||{}),xe=(e=>(e[e.Private=0]=`Private`,e[e.Public=1]=`Public`,e[e.Organization=2]=`Organization`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(xe||{}),Se=(e=>(e[e.SomeCollaborator=0]=`SomeCollaborator`,e[e.AllCollaborator=1]=`AllCollaborator`,e[e.OneSelf=2]=`OneSelf`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Se||{}),Ce=(e=>(e[e.UNKNOWN=0]=`UNKNOWN`,e[e.STRING=1]=`STRING`,e[e.NUMBER=2]=`NUMBER`,e[e.BOOLEAN=3]=`BOOLEAN`,e[e.FORCE_STRING=4]=`FORCE_STRING`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Ce||{}),we=(e=>(e[e.Unknown=0]=`Unknown`,e[e.Colla=1]=`Colla`,e[e.Import=2]=`Import`,e[e.Export=3]=`Export`,e[e.CreateUnit=4]=`CreateUnit`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(we||{}),Te=(e=>(e[e.valueBetween=0]=`valueBetween`,e[e.valueEqual=1]=`valueEqual`,e[e.valueGreaterThan=2]=`valueGreaterThan`,e[e.valueGreaterThanOrEqual=3]=`valueGreaterThanOrEqual`,e[e.valueLessThan=4]=`valueLessThan`,e[e.valueLessThanOrEqual=5]=`valueLessThanOrEqual`,e[e.valueNotBetween=6]=`valueNotBetween`,e[e.valueNotEqual=7]=`valueNotEqual`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Te||{}),Ee=(e=>(e[e.DataFragmentationType_None=0]=`DataFragmentationType_None`,e[e.DataFragmentationType_Charts=1]=`DataFragmentationType_Charts`,e[e.DataFragmentationType_Unit=2]=`DataFragmentationType_Unit`,e[e.DataFragmentationType_WorkSheetRef=3]=`DataFragmentationType_WorkSheetRef`,e[e.DataFragmentationType_Code=4]=`DataFragmentationType_Code`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Ee||{}),De=(e=>(e[e.AnalyseTaskStatus_None=0]=`AnalyseTaskStatus_None`,e[e.AnalyseTaskStatus_Analysing=1]=`AnalyseTaskStatus_Analysing`,e[e.AnalyseTaskStatus_Failed=2]=`AnalyseTaskStatus_Failed`,e[e.AnalyseTaskStatus_Completed=3]=`AnalyseTaskStatus_Completed`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(De||{}),Oe=(e=>(e[e.UNKNOWN_CMD=0]=`UNKNOWN_CMD`,e[e.HELLO=1]=`HELLO`,e[e.JOIN=2]=`JOIN`,e[e.LEAVE=3]=`LEAVE`,e[e.INGEST=4]=`INGEST`,e[e.HEARTBEAT=5]=`HEARTBEAT`,e[e.RECV=6]=`RECV`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Oe||{}),ke=(e=>(e[e.UNKNOWN_CODE=0]=`UNKNOWN_CODE`,e[e.OK=1]=`OK`,e[e.FAIL=2]=`FAIL`,e[e.JOIN_ROOM_FULL=1001]=`JOIN_ROOM_FULL`,e[e.JOIN_ROOM_NOT_EXISTS=1002]=`JOIN_ROOM_NOT_EXISTS`,e[e.JOIN_ROOM_PERMISSION_DENIED=1003]=`JOIN_ROOM_PERMISSION_DENIED`,e[e.GLOBAL_ROOMS_CNT_EXCEEDS=1004]=`GLOBAL_ROOMS_CNT_EXCEEDS`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(ke||{}),Ae=(e=>(e[e.Completion_None=0]=`Completion_None`,e[e.Completion_Completed=1]=`Completion_Completed`,e[e.Completion_UserCancelled=2]=`Completion_UserCancelled`,e[e.Completion_SystemErr=3]=`Completion_SystemErr`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Ae||{}),je=(e=>(e[e.RoleType_None=0]=`RoleType_None`,e[e.RoleType_User=1]=`RoleType_User`,e[e.RoleType_Agent=2]=`RoleType_Agent`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(je||{}),Me=(e=>(e[e.ContentBlockType_None=0]=`ContentBlockType_None`,e[e.ContentBlockType_Prompt=1]=`ContentBlockType_Prompt`,e[e.ContentBlockType_Thinking=2]=`ContentBlockType_Thinking`,e[e.ContentBlockType_Report=3]=`ContentBlockType_Report`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Me||{}),Ne=(e=>(e[e.ContentType_None=0]=`ContentType_None`,e[e.ContentType_PlainText=1]=`ContentType_PlainText`,e[e.ContentType_Markdown=2]=`ContentType_Markdown`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Ne||{}),Pe=(e=>(e[e.AttachmentType_None=0]=`AttachmentType_None`,e[e.AttachmentType_Unit=1]=`AttachmentType_Unit`,e[e.AttachmentType_Recommendation=3]=`AttachmentType_Recommendation`,e[e.AttachmentType_DataSource=4]=`AttachmentType_DataSource`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Pe||{}),Fe=(e=>(e[e.Reaction_NoReact=0]=`Reaction_NoReact`,e[e.Reaction_ThumbsUp=1]=`Reaction_ThumbsUp`,e[e.Reaction_ThumbsDown=2]=`Reaction_ThumbsDown`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Fe||{}),Ie=(e=>(e[e.ChatSSEBlockType_None=0]=`ChatSSEBlockType_None`,e[e.ChatSSEBlockType_EndOfStream=1]=`ChatSSEBlockType_EndOfStream`,e[e.ChatSSEBlockType_Reject=2]=`ChatSSEBlockType_Reject`,e[e.ChatSSEBlockType_ModConversation=3]=`ChatSSEBlockType_ModConversation`,e[e.ChatSSEBlockType_PromptAck=4]=`ChatSSEBlockType_PromptAck`,e[e.ChatSSEBlockType_ChatContent=5]=`ChatSSEBlockType_ChatContent`,e[e.ChatSSEBlockType_Attachment=6]=`ChatSSEBlockType_Attachment`,e[e.ChatSSEBlockType_RespMeta=7]=`ChatSSEBlockType_RespMeta`,e[e.ChatSSEBlockType_StreamErr=8]=`ChatSSEBlockType_StreamErr`,e[e.ChatSSEBlockType_ChatThinking=9]=`ChatSSEBlockType_ChatThinking`,e[e.ChatSSEBlockType_Fragmentation=10]=`ChatSSEBlockType_Fragmentation`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Ie||{}),Le=(e=>(e[e.ChatSSEStatus_None=0]=`ChatSSEStatus_None`,e[e.ChatSSEStatus_Appending=1]=`ChatSSEStatus_Appending`,e[e.ChatSSEStatus_Success=2]=`ChatSSEStatus_Success`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Le||{}),Re=(e=>(e[e.UNDEFINED=0]=`UNDEFINED`,e[e.UNIT=1]=`UNIT`,e[e.JSON=2]=`JSON`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Re||{}),ze=(e=>(e[e.ImportScene_Unspecified=0]=`ImportScene_Unspecified`,e[e.ImportScene_General=1]=`ImportScene_General`,e[e.ImportScene_AIAnalyse=2]=`ImportScene_AIAnalyse`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(ze||{}),Be=(e=>(e[e.Undefined=0]=`Undefined`,e[e.HttpImport=1]=`HttpImport`,e[e.HttpExport=2]=`HttpExport`,e[e.UnitEmbedded=3]=`UnitEmbedded`,e[e.UnitSnapshot=4]=`UnitSnapshot`,e[e.UserProfileImg=5]=`UserProfileImg`,e[e.ClipsheetFragments=6]=`ClipsheetFragments`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Be||{}),Ve=(e=>(e[e.UNDEFINED_ENV=0]=`UNDEFINED_ENV`,e[e.NODE=1]=`NODE`,e[e.BROWSER=2]=`BROWSER`,e[e.PYTHON=3]=`PYTHON`,e[e.REQUIREMENTS_TXT=4]=`REQUIREMENTS_TXT`,e[e.WORKSPACE_ENV_VARS=5]=`WORKSPACE_ENV_VARS`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(Ve||{}),He=(e=>(e[e.UNKNOWN=0]=`UNKNOWN`,e[e.ROOT=1]=`ROOT`,e[e.TRASH=2]=`TRASH`,e[e.DEBUG=3]=`DEBUG`,e[e.AI_STASH=4]=`AI_STASH`,e[e.UNRECOGNIZED=-1]=`UNRECOGNIZED`,e))(He||{});let q=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._permissionService=t,this._lexerTreeBuilder=n}getFormulaRefCheck(e){let n=this._lexerTreeBuilder.sequenceNodesBuilder(e);if(!n)return!0;for(let e=0;e<n.length;e++){let o=n[e];if(typeof o==`string`)continue;let{token:s}=o,c=(0,r.deserializeRangeWithSheetWithCache)(s),l=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),u=l.getActiveSheet(),d=l.getUnitId();if(c.sheetName){if(u=l.getSheetBySheetName(c.sheetName),!u)return!1;let e=u==null?void 0:u.getSheetId();if(!this._permissionService.getPermissionPoint(new i.WorksheetViewPermission(d,e).id))return!1}if(!u)return!1;let{startRow:f,endRow:p,startColumn:m,endColumn:h}=c.range;for(let e=f;e<=p;e++)for(let t=m;t<=h;t++){var a;let n=(a=u.getCell(e,t))==null||(a=a.selectionProtection)==null?void 0:a[0];if((n==null?void 0:n[K.View])===!1)return!1}}return!0}};q=f([d(0,t.IUniverInstanceService),d(1,t.IPermissionService),d(2,(0,t.Inject)(r.LexerTreeBuilder))],q);var Ue=`@univerjs/sheets-data-validation`,We=`0.19.0`;let Ge=`sheets-data-validation.config`;Symbol(Ge);let Ke={},J=class extends t.Disposable{constructor(e,t,n){super(),this._dataValidationModel=e,this._formulaRefRangeService=t,this._validatorRegistryService=n,u(this,`_disposableMap`,new Map),u(this,`registerRule`,(e,t,n)=>{_(n.type,this._validatorRegistryService)&&this.register(e,t,n)}),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}_${t}_${n}`}register(e,r,i){let a=i.ranges,o=i.formula1,s=i.formula2,c=this._formulaRefRangeService.registerRangeFormula(e,r,a,[o==null?``:o,s==null?``:s],c=>{if(c.length===0)return{undos:[{id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:r,rule:i,source:`patched`}}],redos:[{id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:i.uid,source:`patched`}}]};let l=[],u=[],d=c[0];l.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:i.uid,payload:{type:n.UpdateRuleType.ALL,payload:{ranges:d.ranges,formula1:d.formulas[0],formula2:d.formulas[1]}},source:`patched`}}),u.push({id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:i.uid,payload:{type:n.UpdateRuleType.ALL,payload:{ranges:a,formula1:o,formula2:s}},source:`patched`}});for(let a=1;a<c.length;a++){let o=c[a],s=(0,t.generateRandomId)();l.push({id:n.AddDataValidationMutation.id,params:{unitId:e,subUnitId:r,rule:{...i,uid:s,formula1:o.formulas[0],formula2:o.formulas[1],ranges:o.ranges},source:`patched`}}),u.push({id:n.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:s,source:`patched`}})}return{undos:u,redos:l}}),l=this._getIdWithUnitId(e,r,i.uid);this._disposableMap.set(l,c)}_initRefRange(){let e=this._dataValidationModel.getAll();for(let[t,n]of e)for(let[e,r]of n)for(let n of r)this.registerRule(t,e,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{let{unitId:t,subUnitId:n,rule:r}=e;switch(e.type){case`add`:{let t=e.rule;this.registerRule(e.unitId,e.subUnitId,t);break}case`remove`:{let e=this._disposableMap.get(this._getIdWithUnitId(t,n,r.uid));e&&e.dispose();break}case`update`:{let r=e.rule,i=this._disposableMap.get(this._getIdWithUnitId(t,n,r.uid));i&&i.dispose(),this.registerRule(e.unitId,e.subUnitId,r);break}}})),this.disposeWithMe((0,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};J=f([d(0,(0,t.Inject)(T)),d(1,(0,t.Inject)(o.FormulaRefRangeService)),d(2,(0,t.Inject)(n.DataValidatorRegistryService))],J);let Y=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._dataValidationModel=e,this._injector=t,this._refRangeService=n,this._dataValidationFormulaService=r,this._formulaRefRangeService=i,this._validatorRegistryService=a,u(this,`_disposableMap`,new Map),u(this,`registerRule`,(e,t,n)=>{_(n.type,this._validatorRegistryService)||(this.register(e,t,n),this.registerFormula(e,t,n))}),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}_${t}_${n}`}registerFormula(e,t,r){var i;let a=r.uid,o=this._getIdWithUnitId(e,t,a),s=(i=this._disposableMap.get(o))==null?new Set:i,c=(i,o)=>{let s=this._dataValidationModel.getRuleById(e,t,a);if(!s)return{redos:[],undos:[]};let c=s[i];if(!c||c===o)return{redos:[],undos:[]};let l={unitId:e,subUnitId:t,ruleId:r.uid,payload:{type:n.UpdateRuleType.SETTING,payload:{type:s.type,formula1:s.formula1,formula2:s.formula2,[i]:o}},source:`patched`},u={unitId:e,subUnitId:t,ruleId:r.uid,payload:{type:n.UpdateRuleType.SETTING,payload:{type:s.type,formula1:s.formula1,formula2:s.formula2}},source:`patched`};return{redos:[{id:n.UpdateDataValidationMutation.id,params:l}],undos:[{id:n.UpdateDataValidationMutation.id,params:u}]}},l=this._dataValidationFormulaService.getRuleFormulaInfo(e,t,a);if(l){let[n,r]=l;if(n){let r=this._formulaRefRangeService.registerFormula(e,t,n.text,e=>c(`formula1`,e));s.add(()=>r.dispose())}if(r){let n=this._formulaRefRangeService.registerFormula(e,t,r.text,e=>c(`formula2`,e));s.add(()=>n.dispose())}}}register(e,r,a){var o;let s=o=>{let s=[...a.ranges],c=s.map(e=>(0,i.handleCommonDefaultRangeChangeWithEffectRefCommands)(e,o)).filter(e=>!!e).flat();if((0,t.isRangesEqual)(c,s))return{redos:[],undos:[]};if(c.length){let t={unitId:e,subUnitId:r,ruleId:a.uid,payload:{type:n.UpdateRuleType.RANGE,payload:c},source:`patched`};return{redos:[{id:n.UpdateDataValidationMutation.id,params:t}],undos:[{id:n.UpdateDataValidationMutation.id,params:{unitId:e,subUnitId:r,ruleId:a.uid,payload:{type:n.UpdateRuleType.RANGE,payload:s},source:`patched`}}]}}else{let t={unitId:e,subUnitId:r,ruleId:a.uid};return{redos:[{id:n.RemoveDataValidationMutation.id,params:t}],undos:pe(this._injector,t)}}},c=[];a.ranges.forEach(t=>{let n=this._refRangeService.registerRefRange(t,s,e,r);c.push(()=>n.dispose())});let l=this._getIdWithUnitId(e,r,a.uid),u=(o=this._disposableMap.get(l))==null?new Set:o;u.add(()=>c.forEach(e=>e())),this._disposableMap.set(l,u)}_initRefRange(){let e=this._dataValidationModel.getAll();for(let[t,n]of e)for(let[e,r]of n)for(let n of r)this.registerRule(t,e,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{let{unitId:t,subUnitId:n,rule:r}=e;switch(e.type){case`add`:{let t=e.rule;this.registerRule(e.unitId,e.subUnitId,t);break}case`remove`:{let e=this._disposableMap.get(this._getIdWithUnitId(t,n,r.uid));e&&e.forEach(e=>e());break}case`update`:{let r=e.rule,i=this._disposableMap.get(this._getIdWithUnitId(t,n,r.uid));i&&i.forEach(e=>e()),this.registerRule(e.unitId,e.subUnitId,r);break}}})),this.disposeWithMe((0,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.forEach(e=>e())}),this._disposableMap.clear()}))}};Y=f([d(0,(0,t.Inject)(T)),d(1,(0,t.Inject)(t.Injector)),d(2,(0,t.Inject)(i.RefRangeService)),d(3,(0,t.Inject)(w)),d(4,(0,t.Inject)(o.FormulaRefRangeService)),d(5,(0,t.Inject)(n.DataValidatorRegistryService))],Y);let X=class extends t.Disposable{constructor(e,t,n){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._sheetDataValidationModel=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===i.RemoveSheetCommand.id){var r;let i=e.params,a=i.unitId||this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=this._univerInstanceService.getUniverSheetInstance(a);if(!o)return{redos:[],undos:[]};let s=i.subUnitId||((r=o.getActiveSheet())==null?void 0:r.getSheetId());if(!s)return{redos:[],undos:[]};let c=this._sheetDataValidationModel.getRules(a,s);if(c.length===0)return{redos:[],undos:[]};let l={unitId:a,subUnitId:s,ruleId:c.map(e=>e.uid),source:`patched`},u={unitId:a,subUnitId:s,rule:[...c],source:`patched`};return{redos:[{id:n.RemoveDataValidationMutation.id,params:l}],undos:[{id:n.AddDataValidationMutation.id,params:u}]}}else if(e.id===i.CopySheetCommand.id){let{unitId:r,subUnitId:i,targetSubUnitId:a}=e.params;if(!r||!i||!a)return{redos:[],undos:[]};let o=this._sheetDataValidationModel.getRules(r,i);if(o.length===0)return{redos:[],undos:[]};let s=o.map(e=>({...e,uid:(0,t.generateRandomId)(6)}));return{redos:[{id:n.AddDataValidationMutation.id,params:{unitId:r,subUnitId:a,rule:s,source:`patched`}}],undos:[{id:n.RemoveDataValidationMutation.id,params:{unitId:r,subUnitId:a,ruleId:s.map(e=>e.uid),source:`patched`}}]}}return{redos:[],undos:[]}}}))}};X=f([d(0,(0,t.Inject)(i.SheetInterceptorService)),d(1,(0,t.Inject)(t.IUniverInstanceService)),d(2,(0,t.Inject)(T))],X);var qe=class extends n.BaseDataValidator{constructor(...e){super(...e),u(this,`id`,t.DataValidationType.ANY),u(this,`title`,`dataValidation.any.title`),u(this,`operators`,[]),u(this,`scopes`,[`sheet`]),u(this,`order`,0),u(this,`offsetFormulaByRange`,!1)}async parseFormula(e,t,n){return{formula1:e.formula1,formula2:e.formula2,isFormulaValid:!0}}validatorFormula(e,t,n){return{success:!0}}async isValidType(e,t,n){return!0}generateRuleErrorMessage(e){return this.localeService.t(`dataValidation.any.error`)}},Je=class extends n.BaseDataValidator{constructor(...e){super(...e),u(this,`id`,t.DataValidationType.CUSTOM),u(this,`title`,`dataValidation.custom.title`),u(this,`operators`,[]),u(this,`scopes`,[`sheet`]),u(this,`order`,60),u(this,`_customFormulaService`,this.injector.get(v)),u(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder))}validatorFormula(e,n,i){var a;let o=(0,t.isFormulaString)(e.formula1),s=(a=e.formula1)==null?``:a,c=this._lexerTreeBuilder.checkIfAddBracket(s)===0&&s.startsWith(r.operatorToken.EQUALS);return{success:o&&c,formula1:o&&c?``:this.localeService.t(`dataValidation.validFail.formula`)}}async parseFormula(e,t,n){return{formula1:void 0,formula2:void 0,isFormulaValid:!0}}async isValidType(e,n,r){let{column:i,row:a,unitId:o,subUnitId:s}=e,c=await this._customFormulaService.getCellFormulaValue(o,s,r.uid,a,i),l=c==null?void 0:c.v;return g(String(l))&&t.Tools.isDefine(l)&&l!==``?c.t===t.CellValueType.BOOLEAN?!!l:typeof l==`boolean`?l:typeof l==`number`?!!l:typeof l==`string`?g(l):!!l:!1}generateRuleErrorMessage(e){return this.localeService.t(`dataValidation.custom.error`)}generateRuleName(e){var t;return this.localeService.t(`dataValidation.custom.ruleName`).replace(`{FORMULA1}`,(t=e.formula1)==null?``:t)}},Ye=class extends F{constructor(...e){super(...e),u(this,`id`,t.DataValidationType.LIST_MULTIPLE),u(this,`title`,`dataValidation.listMultiple.title`),u(this,`offsetFormulaByRange`,!1),u(this,`skipDefaultFontRender`,()=>!0)}},Xe=class extends n.BaseDataValidator{constructor(...e){super(...e),u(this,`_customFormulaService`,this.injector.get(v)),u(this,`_lexerTreeBuilder`,this.injector.get(r.LexerTreeBuilder)),u(this,`id`,t.DataValidationType.WHOLE),u(this,`title`,`dataValidation.whole.title`),u(this,`order`,10),u(this,`operators`,[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL]),u(this,`scopes`,[`sheet`])}_isFormulaOrInt(e){return!t.Tools.isBlank(e)&&((0,t.isFormulaString)(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}async isValidType(e,t,n){let{value:r}=e,i=P(r);return!Number.isNaN(i)&&Number.isInteger(i)}transform(e,t,n){let{value:r}=e;return{...e,value:P(r)}}_parseNumber(e){return e==null?NaN:+e}async parseFormula(e,n,r,i,a){let o=await this._customFormulaService.getCellFormulaValue(n,r,e.uid,i,a),s=await this._customFormulaService.getCellFormula2Value(n,r,e.uid,i,a),{formula1:c,formula2:l}=e,u=(0,t.isFormulaString)(c)?o==null?void 0:o.v:c,d=(0,t.isFormulaString)(l)?s==null?void 0:s.v:l,f=g(`${u}`)&&g(`${d}`);return{formula1:this._parseNumber(u),formula2:this._parseNumber(d),isFormulaValid:f}}validatorFormula(e,n,r){let i=e.operator;if(!i)return{success:!0};let a=t.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),o=t.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),s=k.includes(i),c=this.localeService.t(`dataValidation.validFail.number`);return s?{success:a&&o,formula1:a?void 0:c,formula2:o?void 0:c}:{success:a,formula1:c}}generateRuleErrorMessage(e,t){if(!e.operator)return this.localeService.t(N.NONE).replace(`{TYPE}`,this.titleStr);let{transformedFormula1:n,transformedFormula2:r}=S(this._lexerTreeBuilder,e,t);return`${this.localeService.t(N[e.operator]).replace(A,n==null?``:n).replace(j,r==null?``:r)}`}};let Z=class extends t.RxDisposable{constructor(e,t,n,r,i,a){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._injector=n,this._selectionManagerService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._init()}_init(){this._registerValidators(),this._initCommandInterceptor()}_registerValidators(){[qe,se,Xe,fe,oe,D,F,Ye,Je].forEach(e=>{let n=this._injector.createInstance(e);this.disposeWithMe(this._dataValidatorRegistryService.register(n)),this.disposeWithMe((0,t.toDisposable)(()=>this._injector.delete(e)))})}_initCommandInterceptor(){this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===i.ClearSelectionAllCommand.id){var n;let e=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),r=e.getUnitId(),i=e.getActiveSheet();if(!i)throw Error(`No active sheet found`);let a=i.getSheetId(),o=(n=this._selectionManagerService.getCurrentSelections())==null?void 0:n.map(e=>e.range),s=this._sheetDataValidationModel.getRuleObjectMatrix(r,a).clone();o&&s.removeRange(o);let{redoMutations:c,undoMutations:l}=L(r,a,s.diff(this._sheetDataValidationModel.getRules(r,a)),this._injector,`patched`);return{undos:l,redos:c}}return{undos:[],redos:[]}}})}};Z=f([d(0,t.IUniverInstanceService),d(1,(0,t.Inject)(n.DataValidatorRegistryService)),d(2,(0,t.Inject)(t.Injector)),d(3,(0,t.Inject)(i.SheetsSelectionsService)),d(4,(0,t.Inject)(i.SheetInterceptorService)),d(5,(0,t.Inject)(T))],Z);let Q=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetDataValidationModel=t,this._dataValidationCacheService=n,this._lifecycleService=r,this._initRecalculate()}_initRecalculate(){let e=e=>{if(e.length===0)return;let n=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getActiveSheet(),i={};e.flat().forEach(e=>{i[e.unitId]||(i[e.unitId]={}),i[e.unitId][e.subUnitId]||(i[e.unitId][e.subUnitId]=[]);let n=this._univerInstanceService.getUnit(e.unitId,t.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getSheetBySheetId(e.subUnitId);r&&i[e.unitId][e.subUnitId].push(...e.ranges.map(e=>t.Range.transformRange(e,r)))}),Object.entries(i).forEach(([e,t])=>{Object.entries(t).forEach(([t,i])=>{(n==null?void 0:n.getUnitId())===e&&(r==null?void 0:r.getSheetId())===t?this.validatorRanges(e,t,i):requestIdleCallback(()=>{this.validatorRanges(e,t,i)})})})};this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe((0,a.bufferWhen)(()=>this._lifecycleService.lifecycle$.pipe((0,a.filter)(e=>e===t.LifecycleStages.Rendered)))).subscribe(e)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe((0,a.filter)(()=>this._lifecycleService.stage>=t.LifecycleStages.Rendered),(0,t.bufferDebounceTime)(20)).subscribe(e))}async _validatorByCell(e,n,r,i){let a=e.getUnitId(),o=n.getSheetId();if(!t.Tools.isDefine(r)||!t.Tools.isDefine(i))throw Error(`row or col is not defined, row: ${r}, col: ${i}`);let s=r,c=i,l=n.getMergedCell(r,i);l&&(s=l.startRow,c=l.startColumn);let u=this._sheetDataValidationModel.getRuleByLocation(a,o,s,c);return u?new Promise(t=>{this._sheetDataValidationModel.validator(u,{unitId:a,subUnitId:o,row:s,col:c,worksheet:n,workbook:e},e=>{t(e)})}):t.DataValidationStatus.VALID}async validatorCell(e,n,r,i){let a=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!a)throw Error(`cannot find current workbook, unitId: ${e}`);let o=a.getSheetBySheetId(n);if(!o)throw Error(`cannot find current worksheet, sheetId: ${n}`);return this._validatorByCell(a,o,r,i)}async validatorRanges(e,n,r){if(!r.length)return Promise.resolve([]);let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)throw Error(`cannot find current workbook, unitId: ${e}`);let a=i.getSheetBySheetId(n);if(!a)throw Error(`cannot find current worksheet, sheetId: ${n}`);let o=this._sheetDataValidationModel.getRules(e,n).map(e=>e.ranges).flat(),s=r.map(e=>o.map(n=>(0,t.getIntersectRange)(e,n))).flat().filter(Boolean),c=[],l=await Promise.all(s.map((e,t)=>{let n=[];for(let r=e.startRow;r<=e.endRow;r++)for(let o=e.startColumn;o<=e.endColumn;o++){n.push(this._validatorByCell(i,a,r,o));let e=a.getMergedCell(r,o);e&&c.push({resultRowIndex:t,resultColIndex:n.length-1,row:e.startRow,col:e.startColumn})}return Promise.all(n)}));return c.length&&c.forEach(({resultRowIndex:r,resultColIndex:i,row:a,col:o})=>{if(l[r][i]===t.DataValidationStatus.VALIDATING){var s;l[r][i]=(s=this._dataValidationCacheService.getValue(e,n,a,o))==null?t.DataValidationStatus.VALID:s}}),l}async validatorWorksheet(e,n){let r=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!r)throw Error(`cannot find current workbook, unitId: ${e}`);let i=r.getSheetBySheetId(n);if(!i)throw Error(`cannot find current worksheet, sheetId: ${n}`);let a=this._sheetDataValidationModel.getRules(e,n);return await Promise.all(a.map(e=>Promise.all(e.ranges.map(e=>{let n=[];return t.Range.foreach(e,(e,t)=>{n.push(this._validatorByCell(r,i,e,t))}),Promise.all(n)})))),this._dataValidationCacheService.ensureCache(e,n)}async validatorWorkbook(e){let t=this._sheetDataValidationModel.getSubUnitIds(e),n=await Promise.all(t.map(t=>this.validatorWorksheet(e,t))),r={};return n.forEach((e,n)=>{r[t[n]]=e}),r}getDataValidations(e,n,r){let i=this._sheetDataValidationModel.getRuleObjectMatrix(e,n),a=new Set;return r.forEach(e=>{t.Range.foreach(e,(e,t)=>{let n=i.getValue(e,t);n&&a.add(n)})}),Array.from(a).map(t=>this._sheetDataValidationModel.getRuleById(e,n,t)).filter(Boolean)}getDataValidation(e,t,n){return this.getDataValidations(e,t,n)[0]}};Q=f([d(0,t.IUniverInstanceService),d(1,(0,t.Inject)(T)),d(2,(0,t.Inject)(p)),d(3,(0,t.Inject)(t.LifecycleService))],Q);let $=class extends t.Plugin{constructor(e=Ke,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},Ke,this._config);this._configService.setConfig(Ge,a)}onStarting(){[[p],[C],[w],[v],[Q],[T],[Z],[q],[X],[Y],[J]].forEach(e=>{this._injector.add(e)}),[z,R,B,V,W,U,H].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(p),this._injector.get(Q),this._injector.get(Z),this._injector.get(J),this._injector.get(Y)}onReady(){this._injector.get(X)}onRendered(){this._injector.get(q)}};u($,`pluginName`,G),u($,`packageName`,Ue),u($,`version`,We),u($,`type`,t.UniverInstanceType.UNIVER_SHEET),$=f([(0,t.DependentOn)(o.UniverSheetsFormulaPlugin,n.UniverDataValidationPlugin),d(1,(0,t.Inject)(t.Injector)),d(2,t.ICommandService),d(3,t.IConfigService)],$);function Ze(e){let n=e.get(i.SheetsSelectionsService).getCurrentSelections().map(e=>e.range);return{uid:(0,t.generateRandomId)(6),type:t.DataValidationType.DECIMAL,operator:t.DataValidationOperator.EQUAL,formula1:`100`,ranges:n==null?[{startColumn:0,endColumn:0,startRow:0,endRow:0}]:n}}e.AddSheetDataValidationCommand=z,e.BASE_FORMULA_INPUT_NAME=`data-validation.formula-input`,e.CHECKBOX_FORMULA_1=1,e.CHECKBOX_FORMULA_2=0,e.CHECKBOX_FORMULA_INPUT_NAME=`data-validation.checkbox-formula-input`,e.CUSTOM_FORMULA_INPUT_NAME=`data-validation.custom-formula-input`,e.CheckboxValidator=D,e.ClearRangeDataValidationCommand=H,e.DATA_VALIDATION_PLUGIN_NAME=G,Object.defineProperty(e,`DataValidationCacheService`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(e,`DataValidationCustomFormulaService`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(e,`DataValidationFormulaController`,{enumerable:!0,get:function(){return q}}),Object.defineProperty(e,`DataValidationFormulaService`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(e,`DataValidationListCacheService`,{enumerable:!0,get:function(){return C}}),e.DateValidator=oe,e.LIST_FORMULA_INPUT_NAME=`data-validation.list-formula-input`,e.ListMultipleValidator=Ye,e.ListValidator=F,e.RemoveSheetAllDataValidationCommand=U,e.RemoveSheetDataValidationCommand=W,Object.defineProperty(e,`SheetDataValidationModel`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(e,`SheetsDataValidationValidatorService`,{enumerable:!0,get:function(){return Q}}),Object.defineProperty(e,`UniverSheetsDataValidationPlugin`,{enumerable:!0,get:function(){return $}}),e.UpdateSheetDataValidationOptionsCommand=V,e.UpdateSheetDataValidationRangeCommand=R,e.UpdateSheetDataValidationSettingCommand=B,e.createDefaultNewRule=Ze,e.deserializeListOptions=x,e.getCellValueNumber=P,e.getCellValueOrigin=y,e.getDataValidationCellValue=te,e.getDataValidationDiffMutations=L,e.getFormulaCellData=h,e.getFormulaResult=m,e.getTransformedFormula=S,e.isLegalFormulaResult=g,e.serializeListOptions=b,e.transformCheckboxValue=E});
|
|
8
6
|
|
|
9
7
|
// @univerjs/sheets-data-validation/facade
|
|
10
|
-
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/core/facade"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-data-validation","@univerjs/sheets/facade","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/core/facade","rxjs"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverSheetsDataValidationFacade={},g.UniverCore,g.UniverSheetsDataValidation,g.UniverSheetsFacade,g.UniverDataValidation,g.UniverEngineFormula,g.UniverCoreFacade,g.rxjs))})(this,(function(g,a,n,f,v,b,y,C){"use strict";var O=Object.defineProperty;var B=(g,a,n)=>a in g?O(g,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):g[a]=n;var k=(g,a,n)=>B(g,typeof a!="symbol"?a+"":a,n);class V{constructor(t){k(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new S(this._rule)}copy(){return new V({...this._rule,uid:a.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(t,e){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=t,this._rule.formula2=void 0,this}requireNumberBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=t.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${b.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(t){return this._rule.errorStyle=t?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setAllowBlank(t){return this._rule.allowBlank=t,this}setOptions(t){return Object.assign(this._rule,t),this}}class S{constructor(t,e,r){k(this,"rule");k(this,"_worksheet");k(this,"_injector");this._injector=r,this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new V(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(v.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];const t=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(e=>this._injector.createInstance(f.FRange,t,this._worksheet,e))}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e,r=!0){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:e[0],formula1:e[1],formula2:e[2],type:this.rule.type,allowBlank:r}}))throw new Error("setCriteria failed");return this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,this.rule.allowBlank=r,this}setOptions(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...v.getRuleOptions(this.rule),...t}}))throw new Error("setOptions failed");return Object.assign(this.rule,t),this}setRanges(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(i=>i.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=t.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(a.ICommandService).syncExecuteCommand(n.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class U extends f.FRange{setDataValidation(t){if(!t)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...t.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(n.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new S(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new S(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}async getDataValidationErrorAsync(){const t=this._workbook.getUnitId(),e=this._worksheet.getSheetId();return this._collectValidationErrorsForRange(t,e,[this._range])}async _collectValidationErrorsForRange(t,e,r){if(!r.length)return[];const i=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,h=o.getName(),l=[];for(const s of r){const u=[];for(let c=s.startRow;c<=s.endRow;c++)for(let d=s.startColumn;d<=s.endColumn;d++)u.push((async()=>{var m;try{if(await i.validatorCell(t,e,c,d)!==a.DataValidationStatus.VALID){const _=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(t,e,c,d);if(_){const w=((m=o.getCell(c,d))==null?void 0:m.v)||null,I=this._createDataValidationError(h,c,d,_,w);l.push(I)}}}catch(p){console.warn(`Failed to validate cell [${c}, ${d}]:`,p)}})());await Promise.all(u)}return l}_createDataValidationError(t,e,r,i,o){return{sheetName:t,row:e,column:r,ruleId:i.uid,inputValue:o,rule:i}}}f.FRange.extend(U);class T extends y.FUniver{static newDataValidation(){return new V}newDataValidation(){return new V}_initialize(t){const e=t.get(a.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>t.has(n.SheetDataValidationModel)?t.get(n.SheetDataValidationModel).ruleChange$.subscribe(i=>{const{unitId:o,subUnitId:h,rule:l,oldRule:s,type:u}=i,c=this.getSheetTarget(o,h);if(!c)return;const{workbook:d,worksheet:m}=c,p=new S(l,m.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:i,worksheet:m,workbook:d,changeType:u,oldRule:s,rule:p})}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>t.has(n.SheetDataValidationModel)?t.get(n.SheetDataValidationModel).validStatusChange$.subscribe(i=>{const{unitId:o,subUnitId:h,ruleId:l,status:s,row:u,col:c}=i,d=this.getSheetTarget(o,h);if(!d)return;const{workbook:m,worksheet:p}=d,D=p.getDataValidation(l);D&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:m,worksheet:p,row:u,column:c,rule:D,status:s})}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>e.beforeCommandExecuted(r=>{if(r.id===n.AddSheetDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s={worksheet:l,workbook:h,rule:i.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,s),s.cancel)throw new a.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationSettingCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId,newCriteria:i.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,u),u.cancel)throw new a.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationRangeCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId,newRanges:i.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,u),u.cancel)throw new a.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationOptionsCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId,newOptions:i.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,u),u.cancel)throw new a.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>e.beforeCommandExecuted(r=>{if(r.id===n.RemoveSheetDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const u={worksheet:l,workbook:h,rule:s,ruleId:i.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,u),u.cancel)throw new a.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>e.beforeCommandExecuted(r=>{if(r.id===n.RemoveSheetAllDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:h,worksheet:l}=o,s={worksheet:l,workbook:h,rules:l.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,s),s.cancel)throw new a.CanceledError}})))}}y.FUniver.extend(T);class A extends f.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}async getAllDataValidationErrorAsync(){const t=this._workbook.getUnitId(),e=this._dataValidationModel.getSubUnitIds(t),r=[];for(const i of e){const o=await this._collectValidationErrorsForSheet(t,i);r.push(...o)}return r}async _collectValidationErrorsForSheet(t,e){const r=this._dataValidationModel.getRules(t,e);if(!r.length)return[];const i=r.flatMap(o=>o.ranges);return this._collectValidationErrorsForRange(t,e,i)}async _collectValidationErrorsForRange(t,e,r){if(!r.length)return[];const i=this._injector.get(n.SheetsDataValidationValidatorService),h=this._workbook.getSheetBySheetId(e);if(!h)throw new Error(`Cannot find worksheet with sheetId: ${e}`);const l=h.getName(),s=[];for(const u of r){const c=[];for(let d=u.startRow;d<=u.endRow;d++)for(let m=u.startColumn;m<=u.endColumn;m++)c.push((async()=>{var p;try{if(await i.validatorCell(t,e,d,m)!==a.DataValidationStatus.VALID){const _=this._dataValidationModel.getRuleByLocation(t,e,d,m);if(_){const w=((p=h.getCell(d,m))==null?void 0:p.v)||null,I=this._createDataValidationError(l,d,m,_,w);s.push(I)}}}catch(D){console.warn(`Failed to validate cell [${d}, ${m}]:`,D)}})());await Promise.all(c)}return s}_createDataValidationError(t,e,r,i,o){return{sheetName:t,row:e,column:r,ruleId:i.uid,inputValue:o,rule:i}}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(C.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(C.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.AddSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationSettingCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationRangeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationOptionsCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.RemoveSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.RemoveSheetAllDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}f.FWorkbook.extend(A);class R extends f.FWorksheet{getDataValidations(){return this._injector.get(v.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new S(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getValidatorStatusAsync(){return this.getValidatorStatus()}getDataValidation(t){const r=this._injector.get(v.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);return r?new S(r,this._worksheet,this._injector):null}async getAllDataValidationErrorAsync(){const t=this._workbook.getUnitId(),e=this._worksheet.getSheetId();return this._collectValidationErrorsForSheet(t,e)}async _collectValidationErrorsForSheet(t,e){const i=this._injector.get(v.DataValidationModel).getRules(t,e);if(!i.length)return[];const o=i.flatMap(h=>h.ranges);return this._collectValidationErrorsForRange(t,e,o)}async _collectValidationErrorsForRange(t,e,r){if(!r.length)return[];const i=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,h=o.getName(),l=[];for(const s of r){const u=[];for(let c=s.startRow;c<=s.endRow;c++)for(let d=s.startColumn;d<=s.endColumn;d++)u.push((async()=>{var m;try{if(await i.validatorCell(t,e,c,d)!==a.DataValidationStatus.VALID){const _=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(t,e,c,d);if(_){const w=((m=o.getCell(c,d))==null?void 0:m.v)||null,I=this._createDataValidationError(h,c,d,_,w);l.push(I)}}}catch(p){console.warn(`Failed to validate cell [${c}, ${d}]:`,p)}})());await Promise.all(u)}return l}_createDataValidationError(t,e,r,i,o){return{sheetName:t,row:e,column:r,ruleId:i.uid,inputValue:o,rule:i}}}f.FWorksheet.extend(R);class M{get SheetDataValidationChanged(){return"SheetDataValidationChanged"}get SheetDataValidatorStatusChanged(){return"SheetDataValidatorStatusChanged"}get BeforeSheetDataValidationAdd(){return"BeforeSheetDataValidationAdd"}get BeforeSheetDataValidationDelete(){return"BeforeSheetDataValidationDelete"}get BeforeSheetDataValidationDeleteAll(){return"BeforeSheetDataValidationDeleteAll"}get BeforeSheetDataValidationCriteriaUpdate(){return"BeforeSheetDataValidationCriteriaUpdate"}get BeforeSheetDataValidationRangeUpdate(){return"BeforeSheetDataValidationRangeUpdate"}get BeforeSheetDataValidationOptionsUpdate(){return"BeforeSheetDataValidationOptionsUpdate"}}y.FEventName.extend(M),g.FDataValidation=S,g.FDataValidationBuilder=V,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
|
11
|
-
|
|
8
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets-data-validation`),require(`@univerjs/sheets/facade`),require(`@univerjs/data-validation`),require(`@univerjs/engine-formula`),require(`@univerjs/core/facade`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-data-validation`,`@univerjs/sheets/facade`,`@univerjs/data-validation`,`@univerjs/engine-formula`,`@univerjs/core/facade`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidationFacade={},e.UniverCore,e.UniverSheetsDataValidation,e.UniverSheetsFacade,e.UniverDataValidation,e.UniverEngineFormula,e.UniverCoreFacade,e.rxjs))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function c(e){"@babel/helpers - typeof";return c=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},c(e)}function l(e,t){if(c(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(c(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function u(e){var t=l(e,`string`);return c(t)==`symbol`?t:t+``}function d(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var f=class e{constructor(e){d(this,`_rule`,void 0),this._rule=e==null?{uid:(0,t.generateRandomId)(),ranges:void 0,type:t.DataValidationType.CUSTOM}:e}build(){return new p(this._rule)}copy(){return new e({...this._rule,uid:(0,t.generateRandomId)()})}getAllowInvalid(){return this._rule.errorStyle!==t.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(e,n){return this._rule.type=t.DataValidationType.CHECKBOX,this._rule.formula1=e,this._rule.formula2=n,this}requireDateAfter(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.GREATER_THAN,this}requireDateBefore(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN,this}requireDateBetween(e,n){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=n.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.BETWEEN,this}requireDateEqualTo(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.EQUAL,this}requireDateNotBetween(e,n){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=n.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(e){return this._rule.type=t.DataValidationType.CUSTOM,this._rule.formula1=e,this._rule.formula2=void 0,this}requireNumberBetween(e,n,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${n}`,this._rule.operator=t.DataValidationOperator.BETWEEN,this._rule.type=r?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberGreaterThan(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberLessThan(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberNotBetween(e,n,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${n}`,this._rule.operator=t.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.NOT_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireValueInList(e,n,r){return this._rule.type=n?t.DataValidationType.LIST_MULTIPLE:t.DataValidationType.LIST,this._rule.formula1=e.join(`,`),this._rule.formula2=void 0,this._rule.showDropDown=r==null?!0:r,this}requireValueInRange(e,n,r){return this._rule.type=n?t.DataValidationType.LIST_MULTIPLE:t.DataValidationType.LIST,this._rule.formula1=`=${(0,a.serializeRangeToRefString)({unitId:e.getUnitId(),sheetName:e.getSheetName(),range:e.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r==null?!0:r,this}setAllowInvalid(e){return this._rule.errorStyle=e?t.DataValidationErrorStyle.WARNING:t.DataValidationErrorStyle.STOP,this}setAllowBlank(e){return this._rule.allowBlank=e,this}setOptions(e){return Object.assign(this._rule,e),this}},p=class{constructor(e,t,n){d(this,`rule`,void 0),d(this,`_worksheet`,void 0),d(this,`_injector`,void 0),this._injector=n,this.rule=e,this._worksheet=t}getAllowInvalid(){return this.rule.errorStyle!==t.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new f(this.rule)}getApplied(){if(!this._worksheet)return!1;let e=this._injector.get(i.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];let e=this._injector.get(t.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(t=>this._injector.createInstance(r.FRange,e,this._worksheet,t))}getUnitId(){var e;return(e=this._worksheet)==null?void 0:e.getUnitId()}getSheetId(){var e;return(e=this._worksheet)==null?void 0:e.getSheetId()}setCriteria(e,r,i=!0){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:r[0],formula1:r[1],formula2:r[2],type:this.rule.type,allowBlank:i}}))throw Error(`setCriteria failed`);return this.rule.operator=r[0],this.rule.formula1=r[1],this.rule.formula2=r[2],this.rule.type=e,this.rule.allowBlank=i,this}setOptions(e){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...(0,i.getRuleOptions)(this.rule),...e}}))throw Error(`setOptions failed`);return Object.assign(this.rule,e),this}setRanges(e){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:e.map(e=>e.getRange())}))throw Error(`setRanges failed`);return this.rule.ranges=e.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(t.ICommandService).syncExecuteCommand(n.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}},m=class extends r.FRange{setDataValidation(e){if(!e)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;let t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...e.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,t),this}getDataValidation(){let e=this._injector.get(n.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new p(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new p(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}async getDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return this._collectValidationErrorsForRange(e,t,[this._range])}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,s=o.getName(),c=[];for(let l of i){let i=[];for(let u=l.startRow;u<=l.endRow;u++)for(let d=l.startColumn;d<=l.endColumn;d++)i.push((async()=>{try{if(await a.validatorCell(e,r,u,d)!==t.DataValidationStatus.VALID){let t=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(e,r,u,d);if(t){var i;let e=((i=o.getCell(u,d))==null?void 0:i.v)||null,n=this._createDataValidationError(s,u,d,t,e);c.push(n)}}}catch(e){console.warn(`Failed to validate cell [${u}, ${d}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FRange.extend(m);var h=class extends o.FUniver{static newDataValidation(){return new f}newDataValidation(){return new f}_initialize(e){let r=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>e.has(n.SheetDataValidationModel)?e.get(n.SheetDataValidationModel).ruleChange$.subscribe(e=>{let{unitId:t,subUnitId:n,rule:r,oldRule:i,type:a}=e,o=this.getSheetTarget(t,n);if(!o)return;let{workbook:s,worksheet:c}=o,l=new p(r,c.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:e,worksheet:c,workbook:s,changeType:a,oldRule:i,rule:l})}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>e.has(n.SheetDataValidationModel)?e.get(n.SheetDataValidationModel).validStatusChange$.subscribe(e=>{let{unitId:t,subUnitId:n,ruleId:r,status:i,row:a,col:o}=e,s=this.getSheetTarget(t,n);if(!s)return;let{workbook:c,worksheet:l}=s,u=l.getDataValidation(r);u&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:c,worksheet:l,row:a,column:o,rule:u,status:i})}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>r.beforeCommandExecuted(e=>{if(e.id===n.AddSheetDataValidationCommand.id){let n=e.params,r=this.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o={worksheet:a,workbook:i,rule:n.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,o),o.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationSettingCommand.id){let n=e.params,r=this.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o=a.getDataValidation(n.ruleId);if(!o)return;let s={worksheet:a,workbook:i,rule:o,ruleId:n.ruleId,newCriteria:n.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,s),s.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationRangeCommand.id){let n=e.params,r=this.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o=a.getDataValidation(n.ruleId);if(!o)return;let s={worksheet:a,workbook:i,rule:o,ruleId:n.ruleId,newRanges:n.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,s),s.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationOptionsCommand.id){let n=e.params,r=this.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o=a.getDataValidation(n.ruleId);if(!o)return;let s={worksheet:a,workbook:i,rule:o,ruleId:n.ruleId,newOptions:n.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,s),s.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>r.beforeCommandExecuted(e=>{if(e.id===n.RemoveSheetDataValidationCommand.id){let n=e.params,r=this.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o=a.getDataValidation(n.ruleId);if(!o)return;let s={worksheet:a,workbook:i,rule:o,ruleId:n.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,s),s.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>r.beforeCommandExecuted(e=>{if(e.id===n.RemoveSheetAllDataValidationCommand.id){let n=e.params,r=this.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o={worksheet:a,workbook:i,rules:a.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,o),o.cancel)throw new t.CanceledError}})))}};o.FUniver.extend(h);var g=class extends r.FWorkbook{_initialize(){Object.defineProperty(this,`_dataValidationModel`,{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}async getAllDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._dataValidationModel.getSubUnitIds(e),n=[];for(let r of t){let t=await this._collectValidationErrorsForSheet(e,r);n.push(...t)}return n}async _collectValidationErrorsForSheet(e,t){let n=this._dataValidationModel.getRules(e,t);if(!n.length)return[];let r=n.flatMap(e=>e.ranges);return this._collectValidationErrorsForRange(e,t,r)}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._workbook.getSheetBySheetId(r);if(!o)throw Error(`Cannot find worksheet with sheetId: ${r}`);let s=o.getName(),c=[];for(let n of i){let i=[];for(let l=n.startRow;l<=n.endRow;l++)for(let u=n.startColumn;u<=n.endColumn;u++)i.push((async()=>{try{if(await a.validatorCell(e,r,l,u)!==t.DataValidationStatus.VALID){let t=this._dataValidationModel.getRuleByLocation(e,r,l,u);if(t){var n;let e=((n=o.getCell(l,u))==null?void 0:n.v)||null,r=this._createDataValidationError(s,l,u,t,e);c.push(r)}}}catch(e){console.warn(`Failed to validate cell [${l}, ${u}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}onDataValidationChange(e){return(0,t.toDisposable)(this._dataValidationModel.ruleChange$.pipe((0,s.filter)(e=>e.unitId===this._workbook.getUnitId())).subscribe(e))}onDataValidationStatusChange(e){return(0,t.toDisposable)(this._dataValidationModel.validStatusChange$.pipe((0,s.filter)(e=>e.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddDataValidation(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,r)=>{let i=t.params;if(t.id===n.AddSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw Error(`Command is stopped by the hook onBeforeAddDataValidation`)}}))}onBeforeUpdateDataValidationCriteria(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,r)=>{let i=t.params;if(t.id===n.UpdateSheetDataValidationSettingCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateDataValidationCriteria`)}}))}onBeforeUpdateDataValidationRange(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,r)=>{let i=t.params;if(t.id===n.UpdateSheetDataValidationRangeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateDataValidationRange`)}}))}onBeforeUpdateDataValidationOptions(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,r)=>{let i=t.params;if(t.id===n.UpdateSheetDataValidationOptionsCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateDataValidationOptions`)}}))}onBeforeDeleteDataValidation(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,r)=>{let i=t.params;if(t.id===n.RemoveSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteDataValidation`)}}))}onBeforeDeleteAllDataValidation(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,r)=>{let i=t.params;if(t.id===n.RemoveSheetAllDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(e(i,r)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteAllDataValidation`)}}))}};r.FWorkbook.extend(g);var _=class extends r.FWorksheet{getDataValidations(){return this._injector.get(i.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new p(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getValidatorStatusAsync(){return this.getValidatorStatus()}getDataValidation(e){let t=this._injector.get(i.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);return t?new p(t,this._worksheet,this._injector):null}async getAllDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return this._collectValidationErrorsForSheet(e,t)}async _collectValidationErrorsForSheet(e,t){let n=this._injector.get(i.DataValidationModel).getRules(e,t);if(!n.length)return[];let r=n.flatMap(e=>e.ranges);return this._collectValidationErrorsForRange(e,t,r)}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,s=o.getName(),c=[];for(let l of i){let i=[];for(let u=l.startRow;u<=l.endRow;u++)for(let d=l.startColumn;d<=l.endColumn;d++)i.push((async()=>{try{if(await a.validatorCell(e,r,u,d)!==t.DataValidationStatus.VALID){let t=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(e,r,u,d);if(t){var i;let e=((i=o.getCell(u,d))==null?void 0:i.v)||null,n=this._createDataValidationError(s,u,d,t,e);c.push(n)}}}catch(e){console.warn(`Failed to validate cell [${u}, ${d}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FWorksheet.extend(_);var v=class{get SheetDataValidationChanged(){return`SheetDataValidationChanged`}get SheetDataValidatorStatusChanged(){return`SheetDataValidatorStatusChanged`}get BeforeSheetDataValidationAdd(){return`BeforeSheetDataValidationAdd`}get BeforeSheetDataValidationDelete(){return`BeforeSheetDataValidationDelete`}get BeforeSheetDataValidationDeleteAll(){return`BeforeSheetDataValidationDeleteAll`}get BeforeSheetDataValidationCriteriaUpdate(){return`BeforeSheetDataValidationCriteriaUpdate`}get BeforeSheetDataValidationRangeUpdate(){return`BeforeSheetDataValidationRangeUpdate`}get BeforeSheetDataValidationOptionsUpdate(){return`BeforeSheetDataValidationOptionsUpdate`}};o.FEventName.extend(v),e.FDataValidation=p,e.FDataValidationBuilder=f});
|
|
12
9
|
|
|
13
10
|
// @univerjs/sheets-data-validation-ui/index
|
|
14
|
-
(function(U,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-data-validation"),require("@univerjs/data-validation"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/design"),require("react"),require("react/jsx-runtime"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula-ui")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-data-validation","@univerjs/data-validation","@univerjs/ui","rxjs","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/design","react","react/jsx-runtime","@univerjs/engine-formula","@univerjs/sheets-formula-ui"],o):(U=typeof globalThis<"u"?globalThis:U||self,o(U.UniverSheetsDataValidationUi={},U.UniverCore,U.UniverEngineRender,U.UniverSheets,U.UniverSheetsDataValidation,U.UniverDataValidation,U.UniverUi,U.rxjs,U.UniverSheetsNumfmt,U.UniverSheetsUi,U.UniverDesign,U.React,U.React,U.UniverEngineFormula,U.UniverSheetsFormulaUi))})(this,(function(U,o,O,N,_,X,E,oe,Ft,x,M,R,p,qe,Je){"use strict";var cr=Object.defineProperty;var ur=(U,o,O)=>o in U?cr(U,o,{enumerable:!0,configurable:!0,writable:!0,value:O}):U[o]=O;var L=(U,o,O)=>ur(U,typeof o!="symbol"?o+"":o,O);var Pe;const ke={name:"@univerjs/sheets-data-validation-ui",version:"0.17.0"};var kt=Object.getOwnPropertyDescriptor,Nt=(e,t,n,r)=>{for(var a=r>1?void 0:r?kt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},mt=(e,t)=>(n,r)=>t(n,r,e);let ue=class extends o.Disposable{constructor(t,n){super();L(this,"_open$",new oe.BehaviorSubject(!1));L(this,"open$",this._open$.pipe(oe.distinctUntilChanged()));L(this,"_activeRule");L(this,"_activeRule$",new oe.BehaviorSubject(void 0));L(this,"activeRule$",this._activeRule$.asObservable());L(this,"_closeDisposable",null);L(this,"_focusFormulaEditorActiveRuleSubUnitId",null);this._univerInstanceService=t,this._sidebarService=n,this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).pipe(oe.filter(r=>!r)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(r=>{r.id===Be&&(r.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}dispose(){var t;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(t=this._closeDisposable)==null||t.dispose()}open(){this._open$.next(!0)}close(){var t;this._open$.next(!1),(t=this._closeDisposable)==null||t.dispose()}setCloseDisposable(t){this._closeDisposable=o.toDisposable(()=>{t.dispose(),this._closeDisposable=null})}setActiveRule(t){this._activeRule=t,this._activeRule$.next(t)}setFocusFormulaEditorActiveRuleSubUnitId(t){this._focusFormulaEditorActiveRuleSubUnitId=t}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};ue=Nt([mt(0,o.IUniverInstanceService),mt(1,E.ISidebarService)],ue);const Ne="sheets-data-validation-ui.config",je={},me="#ECECEC";var jt=Object.getOwnPropertyDescriptor,Bt=(e,t,n,r)=>{for(var a=r>1?void 0:r?jt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},we=(e,t)=>(n,r)=>t(n,r,e);let Ee=class extends o.Disposable{constructor(e,t,n,r,a,i){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=a,this._sheetsDataValidationValidatorService=i,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(N.VALIDATE_CELL,{handler:async(e,t,n)=>{const r=await e,{row:a,col:i,unitId:s,subUnitId:d}=t,l=this._dataValidationModel.getRuleIdByLocation(s,d,a,i),c=l?this._dataValidationModel.getRuleById(s,d,l):void 0;if(r===!1)return n(Promise.resolve(!1));if(!c||c.errorStyle!==o.DataValidationErrorStyle.STOP)return n(Promise.resolve(!0));const h=this._dataValidatorRegistryService.getValidatorItem(c.type);return!h||await this._sheetsDataValidationValidatorService.validatorCell(s,d,a,i)===o.DataValidationStatus.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t("dataValidation.alert.title")},id:"reject-input-dialog",children:{title:h.getRuleFinalError(c,{row:a,col:i,unitId:s,subUnitId:d})},footer:{title:R.createElement(M.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t("dataValidation.alert.title")},id:"reject-input-dialog",children:{title:e},footer:{title:R.createElement(M.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}})}};Ee=Bt([we(0,o.Inject(N.SheetInterceptorService)),we(1,o.Inject(_.SheetDataValidationModel)),we(2,o.Inject(X.DataValidatorRegistryService)),we(3,E.IDialogService),we(4,o.Inject(o.LocaleService)),we(5,o.Inject(_.SheetsDataValidationValidatorService))],Ee);var Wt=Object.getOwnPropertyDescriptor,$t=(e,t,n,r)=>{for(var a=r>1?void 0:r?Wt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},he=(e,t)=>(n,r)=>t(n,r,e);const Qe=e=>{if(e==null||typeof e=="boolean")return;if(e==="")return o.dayjs();if(typeof e=="number"||!Number.isNaN(+e))return o.dayjs(o.numfmt.format("yyyy-MM-dd HH:mm:ss",Number(e)));const t=o.dayjs(e);if(t.isValid())return t};function Ht(e,t){const n=Ft.getPatternType(t);if(e===n)return t;switch(e){case"datetime":return"yyyy-MM-dd hh:mm:ss";case"date":return"yyyy-MM-dd";case"time":return"HH:mm:ss"}}let Se=class extends o.Disposable{constructor(t,n,r,a,i,s,d,l,c,h,v){super();L(this,"_activeDropdown");L(this,"_activeDropdown$",new oe.Subject);L(this,"_currentPopup",null);L(this,"activeDropdown$",this._activeDropdown$.asObservable());L(this,"_zenVisible",!1);this._univerInstanceService=t,this._dataValidatorRegistryService=n,this._zenZoneService=r,this._dataValidationModel=a,this._sheetsSelectionsService=i,this._cellDropdownManagerService=s,this._sheetDataValidationModel=d,this._commandService=l,this._editorBridgeService=c,this._injector=h,this._configService=v,this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}get activeDropdown(){return this._activeDropdown}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{this._zenVisible=t,t&&this.hideDropdown()}))}_getDropdownByCell(t,n,r,a){const i=t?this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!i)return;const s=n?i.getSheetBySheetId(n):i.getActiveSheet();if(!s)return;const d=this._dataValidationModel.getRuleByLocation(i.getUnitId(),s.getSheetId(),r,a);if(!d)return;const l=this._dataValidatorRegistryService.getValidatorItem(d.type);return l==null?void 0:l.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(t=>{t&&t.every(n=>!(n.primary&&this._getDropdownByCell(n.primary.unitId,n.primary.sheetId,n.primary.actualRow,n.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){var P,m,y,I,D,A;const{location:n}=t,{row:r,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=n;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);const c=this._sheetDataValidationModel.getRuleByLocation(i,s,r,a);if(!c)return;const h=this._dataValidatorRegistryService.getValidatorItem(c.type);if(!(h!=null&&h.dropdownType))return;let v;const u=async(f,g)=>{var Y,$,K;if(!f)return!0;const C=f,F=l.getCell(r,a),j=C.format(g==="date"?"YYYY-MM-DD 00:00:00":"YYYY-MM-DD HH:mm:ss"),B=(Y=o.numfmt.parseDate(j))==null?void 0:Y.v,W=g==="time"?B%1:B,T=d.getStyles().getStyleByCell(F),k=(K=($=T==null?void 0:T.n)==null?void 0:$.pattern)!=null?K:"";return c.errorStyle!==o.DataValidationErrorStyle.STOP||await h.validator({value:W,unitId:i,subUnitId:s,row:r,column:a,worksheet:l,workbook:d,interceptValue:j.replace("Z","").replace("T"," "),t:o.CellValueType.NUMBER},c)?(await this._commandService.executeCommand(N.SetRangeValuesCommand.id,{unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:W,t:2,p:null,f:null,si:null,s:{n:{pattern:Ht(g,k)}}}}),await this._commandService.executeCommand(x.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:E.KeyCode.ESC}),!0):(this._injector.has(Ee)&&this._injector.get(Ee).showReject(h.getRuleFinalError(c,{row:r,col:a,unitId:i,subUnitId:s})),!1)};let S;switch(h.dropdownType){case X.DataValidatorDropdownType.DATE:{const f=_.getCellValueOrigin(l.getCellRaw(r,a)),g=Qe(f),C=!!((P=c.bizInfo)!=null&&P.showTime);S={location:n,type:"datepicker",props:{showTime:C,onChange:F=>u(F,C?"datetime":"date"),defaultValue:g,patternType:"date"}};break}case X.DataValidatorDropdownType.TIME:{const f=_.getCellValueOrigin(l.getCellRaw(r,a)),g=Qe(f);S={location:n,type:"datepicker",props:{onChange:C=>u(C,"time"),defaultValue:g,patternType:"time"}};break}case X.DataValidatorDropdownType.DATETIME:{const f=_.getCellValueOrigin(l.getCellRaw(r,a)),g=Qe(f);S={location:n,type:"datepicker",props:{onChange:C=>u(C,"datetime"),defaultValue:g,patternType:"datetime"}};break}case X.DataValidatorDropdownType.LIST:case X.DataValidatorDropdownType.MULTIPLE_LIST:{const f=h.dropdownType===X.DataValidatorDropdownType.MULTIPLE_LIST,g=async T=>{const k=_.serializeListOptions(T),Y={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:k,p:null,f:null,si:null}};return this._commandService.executeCommand(N.SetRangeValuesCommand.id,Y),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(x.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:E.KeyCode.ESC}),!f},C=(c==null?void 0:c.renderMode)===o.DataValidationRenderMode.CUSTOM||(c==null?void 0:c.renderMode)===void 0,F=h.getListWithColor(c,i,s),j=_.getDataValidationCellValue(l.getCellRaw(r,a)),B=()=>{this._commandService.executeCommand(_e.id,{ruleId:c.uid}),v==null||v.dispose()},W=F.map(T=>({label:T.label,value:T.label,color:C||T.color?T.color||me:"transparent"}));S={location:n,type:"list",props:{onChange:T=>g(T),options:W,onEdit:B,defaultValue:j,multiple:f,showEdit:(y=(m=this._configService.getConfig(Ne))==null?void 0:m.showEditOnDropdown)!=null?y:!0,showSearch:(D=(I=this._configService.getConfig(Ne))==null?void 0:I.showSearchOnDropdown)!=null?D:!0}};break}case X.DataValidatorDropdownType.CASCADE:{S={type:"cascader",props:{onChange:g=>{const C={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:g.join("/"),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(N.SetRangeValuesCommand.id,C),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(x.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:E.KeyCode.ESC}),!0},defaultValue:_.getDataValidationCellValue(l.getCellRaw(r,a)).split("/"),options:JSON.parse((A=c.formula1)!=null?A:"[]")},location:n};break}case X.DataValidatorDropdownType.COLOR:{S={type:"color",props:{onChange:g=>{const C={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:g,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(N.SetRangeValuesCommand.id,C),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(x.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:E.KeyCode.ESC}),!0},defaultValue:_.getDataValidationCellValue(l.getCellRaw(r,a))},location:n};break}default:throw new Error("[DataValidationDropdownManagerService]: unknown type!")}if(v=this._cellDropdownManagerService.showDropdown({...S,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!v)throw new Error("[DataValidationDropdownManagerService]: cannot show dropdown!");const w=new o.DisposableCollection;w.add(v),w.add({dispose:()=>{var f,g;(g=(f=this._activeDropdown)==null?void 0:f.onHide)==null||g.call(f)}}),this._currentPopup=w}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(t,n,r,a,i){const s=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!s)return;const d=s.getSheetBySheetId(n);if(!d)return;const l=this._dataValidationModel.getRuleByLocation(s.getUnitId(),d.getSheetId(),r,a);if(!l)return;const c=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!c||!c.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:s,worksheet:d,row:r,col:a,unitId:t,subUnitId:n},onHide:i})}};Se=$t([he(0,o.IUniverInstanceService),he(1,o.Inject(X.DataValidatorRegistryService)),he(2,E.IZenZoneService),he(3,o.Inject(_.SheetDataValidationModel)),he(4,o.Inject(N.SheetsSelectionsService)),he(5,o.Inject(x.ISheetCellDropdownManagerService)),he(6,o.Inject(_.SheetDataValidationModel)),he(7,o.ICommandService),he(8,x.IEditorBridgeService),he(9,o.Inject(o.Injector)),he(10,o.IConfigService)],Se);const Be="DataValidationPanel",_e={id:"data-validation.operation.open-validation-panel",type:o.CommandType.OPERATION,handler(e,t){if(!t)return!1;const{ruleId:n,isAdd:r}=t,a=e.get(ue),i=e.get(X.DataValidationModel),s=e.get(o.IUniverInstanceService),d=e.get(E.ISidebarService),l=N.getSheetCommandTarget(s);if(!l)return!1;const{unitId:c,subUnitId:h}=l,v=n?i.getRuleById(c,h,n):void 0;a.open(),a.setActiveRule(v&&{unitId:c,subUnitId:h,rule:v});const u=d.open({id:Be,header:{title:r?"dataValidation.panel.addTitle":"dataValidation.panel.title"},children:{label:Be},width:312,onClose:()=>a.close()});return a.setCloseDisposable(u),!0}},et={id:"data-validation.operation.close-validation-panel",type:o.CommandType.OPERATION,handler(e){return e.get(ue).close(),!0}},St={id:"data-validation.operation.toggle-validation-panel",type:o.CommandType.OPERATION,handler(e){const t=e.get(o.ICommandService),n=e.get(ue);return n.open(),n.isOpen?t.executeCommand(et.id):t.executeCommand(_e.id),!0}},We={type:o.CommandType.OPERATION,id:"sheet.operation.show-data-validation-dropdown",handler(e,t){if(!t)return!1;const n=e.get(Se),{unitId:r,subUnitId:a,row:i,column:s}=t,d=n.activeDropdown,l=d==null?void 0:d.location;return l&&l.unitId===r&&l.subUnitId===a&&l.row===i&&l.col===s||n.showDataValidationDropdown(r,a,i,s),!0}},_t={type:o.CommandType.OPERATION,id:"sheet.operation.hide-data-validation-dropdown",handler(e,t){return t?(e.get(Se).hideDropdown(),!0):!1}},$e={type:o.CommandType.COMMAND,id:"data-validation.command.addRuleAndOpen",handler(e){const t=e.get(o.IUniverInstanceService),n=N.getSheetCommandTarget(t);if(!n)return!1;const{workbook:r,worksheet:a}=n,i=_.createDefaultNewRule(e),s=e.get(o.ICommandService),d=r.getUnitId(),l=a.getSheetId(),c={rule:i,unitId:d,subUnitId:l};return s.syncExecuteCommand(_.AddSheetDataValidationCommand.id,c)?(s.syncExecuteCommand(_e.id,{ruleId:i.uid,isAdd:!0}),!0):!1}};var xt=Object.getOwnPropertyDescriptor,Yt=(e,t,n,r)=>{for(var a=r>1?void 0:r?xt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},De=(e,t)=>(n,r)=>t(n,r,e);const Ie="SHEET_DATA_VALIDATION_ALERT";let Ue=class extends o.Disposable{constructor(e,t,n,r,a,i){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=a,this._dataValidationModel=i,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(oe.debounceTime(100)).subscribe(e=>{var t;if(e){const n=this._univerInstanceService.getUnit(e.location.unitId,o.UniverInstanceType.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;const a=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!a){this._cellAlertManagerService.removeAlert(Ie);return}if(this._dataValidationModel.validator(a,{...e.location,workbook:n,worksheet:r})===o.DataValidationStatus.INVALID){const s=this._cellAlertManagerService.currentAlert.get(Ie),d=(t=s==null?void 0:s.alert)==null?void 0:t.location;if(d&&d.row===e.location.row&&d.col===e.location.col&&d.subUnitId===e.location.subUnitId&&d.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(Ie);return}const l=this._dataValidationModel.getValidator(a.type);if(!l){this._cellAlertManagerService.removeAlert(Ie);return}this._cellAlertManagerService.showAlert({type:x.CellAlertType.ERROR,title:this._localeService.t("dataValidation.error.title"),message:l==null?void 0:l.getRuleFinalError(a,e.location),location:e.location,width:200,height:74,key:Ie});return}}this._cellAlertManagerService.removeAlert(Ie)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(Ie)}))}};Ue=Yt([De(0,o.Inject(x.HoverManagerService)),De(1,o.Inject(x.CellAlertManagerService)),De(2,o.IUniverInstanceService),De(3,o.Inject(o.LocaleService)),De(4,E.IZenZoneService),De(5,o.Inject(_.SheetDataValidationModel))],Ue);var Xt=Object.getOwnPropertyDescriptor,zt=(e,t,n,r)=>{for(var a=r>1?void 0:r?Xt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},tt=(e,t)=>(n,r)=>t(n,r,e);let Me=class extends o.Disposable{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),t=(r,a)=>{const{source:i,target:s,unitId:d,subUnitId:l}=r,c=this._sheetDataValidationModel.getRuleObjectMatrix(d,l).clone(),h=x.virtualizeDiscreteRanges([i,s]),[v,u]=h.ranges,{mapFunc:S}=h,w={row:v.startRow,col:v.startColumn},P=N.AutoFillTools.getAutoFillRepeatRange(v,u),m=new o.ObjectMatrix,y=new Set;P.forEach(g=>{const C=g.repeatStartCell,F=g.relativeRange,j={startRow:w.row,startColumn:w.col,endColumn:w.col,endRow:w.row},B={startRow:C.row,startColumn:C.col,endColumn:C.col,endRow:C.row};o.Range.foreach(F,(W,T)=>{const k=o.Rectangle.getPositionRange({startRow:W,startColumn:T,endColumn:T,endRow:W},j),{row:Y,col:$}=S(k.startRow,k.startColumn),K=this._sheetDataValidationModel.getRuleIdByLocation(d,l,Y,$)||"",ae=o.Rectangle.getPositionRange({startRow:W,startColumn:T,endColumn:T,endRow:W},B),{row:G,col:se}=S(ae.startRow,ae.startColumn);m.setValue(G,se,K),y.add(K)})});const I=Array.from(y).map(g=>({id:g,ranges:o.queryObjectMatrix(m,C=>C===g)}));c.addRangeRules(I);const D=c.diff(this._sheetDataValidationModel.getRules(d,l)),{redoMutations:A,undoMutations:f}=_.getDataValidationDiffMutations(d,l,D,this._injector,"patched",a===N.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);return{undos:f,redos:A}},n={id:_.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:r=>{const{source:a,unitId:i,subUnitId:s}=r;for(const d of a.rows)for(const l of a.cols){const c=this._sheetDataValidationModel.getRuleByLocation(i,s,d,l);if(c&&c.type===o.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(N.AUTO_FILL_APPLY_TYPE.SERIES,!0);return}}},onFillData:(r,a,i)=>i===N.AUTO_FILL_APPLY_TYPE.COPY||i===N.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT||i===N.AUTO_FILL_APPLY_TYPE.SERIES?t(r,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};Me=zt([tt(0,N.IAutoFillService),tt(1,o.Inject(_.SheetDataValidationModel)),tt(2,o.Inject(o.Injector))],Me);var Kt=Object.getOwnPropertyDescriptor,Zt=(e,t,n,r)=>{for(var a=r>1?void 0:r?Kt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},nt=(e,t)=>(n,r)=>t(n,r,e);let be=class extends o.Disposable{constructor(t,n,r){super();L(this,"_copyInfo");this._sheetClipboardService=t,this._sheetDataValidationModel=n,this._injector=r,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:_.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(t,n,r)=>this._collect(t,n,r),onPasteCells:(t,n,r,a)=>{const{copyType:i=x.COPY_TYPE.COPY,pasteType:s}=a,{range:d}=t||{},{range:l,unitId:c,subUnitId:h}=n;return this._generateMutations(l,{copyType:i,pasteType:s,copyRange:d,unitId:c,subUnitId:h})}})}_collect(t,n,r){const a=new o.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:n,matrix:a};const i=this._injector.invoke(l=>N.rangeToDiscreteRange(r,l,t,n));if(!i)return;const{rows:s,cols:d}=i;s.forEach((l,c)=>{d.forEach((h,v)=>{const u=this._sheetDataValidationModel.getRuleIdByLocation(t,n,l,h);a.setValue(c,v,u!=null?u:"")})})}_generateMutations(t,n){if(!this._copyInfo)return{redos:[],undos:[]};if(n.copyType===x.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!n.copyRange)return{redos:[],undos:[]};if([x.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,x.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,x.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,x.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};const{unitId:a,subUnitId:i}=this._copyInfo;if(n.unitId!==a||i!==n.subUnitId){const s=this._sheetDataValidationModel.getRuleObjectMatrix(n.unitId,n.subUnitId).clone(),d=new o.ObjectMatrix,l=new Set,{ranges:[c,h],mapFunc:v}=x.virtualizeDiscreteRanges([n.copyRange,t]),u=x.getRepeatRange(c,h,!0),S=new Map;u.forEach(({startRange:y})=>{var I;(I=this._copyInfo)==null||I.matrix.forValue((D,A,f)=>{const g=o.Rectangle.getPositionRange({startRow:D,endRow:D,startColumn:A,endColumn:A},y),C=`${i}-${f}`,F=this._sheetDataValidationModel.getRuleById(a,i,f);!this._sheetDataValidationModel.getRuleById(n.unitId,n.subUnitId,C)&&F&&S.set(C,{...F,uid:C});const{row:j,col:B}=v(g.startRow,g.startColumn);l.add(C),d.setValue(j,B,C)})});const w=Array.from(l).map(y=>({id:y,ranges:o.queryObjectMatrix(d,I=>I===y)}));s.addRangeRules(w);const{redoMutations:P,undoMutations:m}=_.getDataValidationDiffMutations(n.unitId,n.subUnitId,s.diffWithAddition(this._sheetDataValidationModel.getRules(n.unitId,n.subUnitId),S.values()),this._injector,"patched",!1);return{redos:P,undos:m}}else{const s=this._sheetDataValidationModel.getRuleObjectMatrix(a,i).clone(),d=new o.ObjectMatrix,l=new Set,{ranges:[c,h],mapFunc:v}=x.virtualizeDiscreteRanges([n.copyRange,t]);x.getRepeatRange(c,h,!0).forEach(({startRange:m})=>{var y;(y=this._copyInfo)==null||y.matrix.forValue((I,D,A)=>{const f=o.Rectangle.getPositionRange({startRow:I,endRow:I,startColumn:D,endColumn:D},m),{row:g,col:C}=v(f.startRow,f.startColumn);d.setValue(g,C,A),l.add(A)})});const S=Array.from(l).map(m=>({id:m,ranges:o.queryObjectMatrix(d,y=>y===m)}));s.addRangeRules(S);const{redoMutations:w,undoMutations:P}=_.getDataValidationDiffMutations(a,i,s.diff(this._sheetDataValidationModel.getRules(a,i)),this._injector,"patched",!1);return{redos:w,undos:P}}}};be=Zt([nt(0,x.ISheetClipboardService),nt(1,o.Inject(_.SheetDataValidationModel)),nt(2,o.Inject(o.Injector))],be);var Gt=Object.getOwnPropertyDescriptor,qt=(e,t,n,r)=>{for(var a=r>1?void 0:r?Gt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},rt=(e,t)=>(n,r)=>t(n,r,e);let Te=class extends o.Disposable{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===_.AddSheetDataValidationCommand.id){const{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[N.WorkbookEditablePermission],rangeTypes:[N.RangeProtectionPermissionEditPoint],worksheetTypes:[N.WorksheetEditPermission,N.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))}if(e.id===_.UpdateSheetDataValidationRangeCommand.id){const{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[N.WorkbookEditablePermission],rangeTypes:[N.RangeProtectionPermissionEditPoint],worksheetTypes:[N.WorksheetEditPermission,N.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))}}))}};Te=qt([rt(0,o.Inject(o.LocaleService)),rt(1,o.ICommandService),rt(2,o.Inject(N.SheetPermissionCheckController))],Te);const It="sheet.menu.data-validation";function Jt(e){return{id:It,type:E.MenuItemType.SUBITEMS,icon:"DataValidationIcon",tooltip:"dataValidation.title",hidden$:E.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:x.getCurrentRangeDisable$(e,{workbookTypes:[N.WorkbookEditablePermission],worksheetTypes:[N.WorksheetSetCellStylePermission,N.WorksheetEditPermission],rangeTypes:[N.RangeProtectionPermissionEditPoint]})}}function Qt(e){return{id:_e.id,title:"dataValidation.panel.title",type:E.MenuItemType.BUTTON}}function en(e){return{id:$e.id,title:"dataValidation.panel.add",type:E.MenuItemType.BUTTON}}const tn={[E.RibbonDataGroup.RULES]:{[It]:{order:0,menuItemFactory:Jt,[_e.id]:{order:0,menuItemFactory:Qt},[$e.id]:{order:1,menuItemFactory:en}}}};var nn=Object.getOwnPropertyDescriptor,Ct=(e,t,n,r)=>{for(var a=r>1?void 0:r?nn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},q=(e,t)=>(n,r)=>t(n,r,e);const yt={tr:{size:6,color:"#fe4b4b"}};let Re=class extends o.RxDisposable{constructor(e,t,n,r,a,i,s,d,l,c,h){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=a,this._dropdownManagerService=i,this._sheetDataValidationModel=s,this._dataValidatorRegistryService=d,this._sheetInterceptorService=l,this._dataValidationCacheService=c,this._editorBridgeService=h,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(tn)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{var n;if(!e.visible){((n=this._dropdownManagerService.activeDropdown)==null?void 0:n.trigger)==="editor-bridge"&&this._dropdownManagerService.hideDropdown();return}const t=this._editorBridgeService.getEditCellState();if(t){const{unitId:r,sheetId:a,row:i,column:s}=t,d=this._univerInstanceService.getUniverSheetInstance(r);if(!d)return;const l=this._sheetDataValidationModel.getRuleByLocation(r,a,i,s);if(!l)return;const c=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!(c!=null&&c.dropdownType))return;const h=d.getActiveSheet();if(!h)return;const v=this._dropdownManagerService.activeDropdown,u=v==null?void 0:v.location;if(u&&u.unitId===r&&u.subUnitId===a&&u.row===i&&u.col===s)return;this._dropdownManagerService.showDropdown({location:{unitId:r,subUnitId:a,row:i,col:s,workbook:d,worksheet:h},trigger:"editor-bridge",closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(N.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:N.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var y,I,D,A,f;const{row:r,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=t,c=this._sheetDataValidationModel.getRuleIdByLocation(i,s,r,a);if(!c)return n(e);const h=this._sheetDataValidationModel.getRuleById(i,s,c);if(!h)return n(e);const v=(y=this._dataValidationCacheService.getValue(i,s,r,a))!=null?y:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=t.rawData;let w;const P={get value(){var g;return w!==void 0||(w=(g=_.getCellValueOrigin(S))!=null?g:null),w}},m={get value(){var g;return`${(g=P.value)!=null?g:""}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...v===o.DataValidationStatus.INVALID?yt:null},e.customRender=[...(I=e==null?void 0:e.customRender)!=null?I:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:((D=e==null?void 0:e.fontRenderExtension)==null?void 0:D.isSkip)||((A=u==null?void 0:u.skipDefaultFontRender)==null?void 0:A.call(u,h,P.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,m.value,{get style(){const g=d.getStyles();return(typeof(e==null?void 0:e.s)=="string"?g.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},r,a)},e.interceptorAutoHeight=()=>{var j,B,W,T,k,Y;const g=(B=(j=this._renderManagerService.getRenderById(i))==null?void 0:j.with(x.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:B.skeleton;if(!g)return;const C=g.worksheet.getMergedCell(r,a),F={data:e,style:g.getStyles().getStyleByCell(e),primaryWithCoord:g.getCellWithCoordByIndex((W=C==null?void 0:C.startRow)!=null?W:r,(T=C==null?void 0:C.startColumn)!=null?T:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(Y=(k=u==null?void 0:u.canvasRender)==null?void 0:k.calcCellAutoHeight)==null?void 0:Y.call(k,F)},e.interceptorAutoWidth=()=>{var j,B,W,T,k,Y;const g=(B=(j=this._renderManagerService.getRenderById(i))==null?void 0:j.with(x.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:B.skeleton;if(!g)return;const C=g.worksheet.getMergedCell(r,a),F={data:e,style:g.getStyles().getStyleByCell(e),primaryWithCoord:g.getCellWithCoordByIndex((W=C==null?void 0:C.startRow)!=null?W:r,(T=C==null?void 0:C.startColumn)!=null?T:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(Y=(k=u==null?void 0:u.canvasRender)==null?void 0:k.calcCellAutoWidth)==null?void 0:Y.call(k,F)},e.coverable=((f=e==null?void 0:e.coverable)!=null?f:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(oe.filter(e=>e.source==="command"),oe.bufferTime(100)).subscribe(e=>{if(e.length===0)return;const t=[];if(e.forEach(n=>{var r;(n.rule.type===o.DataValidationType.LIST_MULTIPLE||n.rule.type===o.DataValidationType.LIST)&&(r=n.rule)!=null&&r.ranges&&t.push(...n.rule.ranges)}),t.length){const n=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(n.redos,this._commandService)}})}};Re=Ct([q(0,o.ICommandService),q(1,E.IMenuManagerService),q(2,O.IRenderManagerService),q(3,o.IUniverInstanceService),q(4,o.Inject(x.AutoHeightController)),q(5,o.Inject(Se)),q(6,o.Inject(_.SheetDataValidationModel)),q(7,o.Inject(X.DataValidatorRegistryService)),q(8,o.Inject(N.SheetInterceptorService)),q(9,o.Inject(_.DataValidationCacheService)),q(10,o.Optional(x.IEditorBridgeService))],Re);let wt=class extends o.RxDisposable{constructor(e,t,n,r,a,i,s){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=a,this._sheetDataValidationModel=i,this._dataValidationCacheService=s,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(N.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:N.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var m,y,I,D,A;const{row:r,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=t,c=this._sheetDataValidationModel.getRuleIdByLocation(i,s,r,a);if(!c)return n(e);const h=this._sheetDataValidationModel.getRuleById(i,s,c);if(!h)return n(e);const v=(m=this._dataValidationCacheService.getValue(i,s,r,a))!=null?m:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=l.getCellRaw(r,a),w=_.getCellValueOrigin(S),P=`${w!=null?w:""}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...v===o.DataValidationStatus.INVALID?yt:null},e.customRender=[...(y=e==null?void 0:e.customRender)!=null?y:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:((I=e==null?void 0:e.fontRenderExtension)==null?void 0:I.isSkip)||((D=u==null?void 0:u.skipDefaultFontRender)==null?void 0:D.call(u,h,w,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,P,{get style(){const f=d.getStyles();return(typeof(e==null?void 0:e.s)=="string"?f.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},r,a)},e.interceptorAutoHeight=()=>{var F,j,B,W,T,k;const f=(j=(F=this._renderManagerService.getRenderById(i))==null?void 0:F.with(x.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:j.skeleton;if(!f)return;const g=f.worksheet.getMergedCell(r,a),C={data:e,style:f.getStyles().getStyleByCell(e),primaryWithCoord:f.getCellWithCoordByIndex((B=g==null?void 0:g.startRow)!=null?B:r,(W=g==null?void 0:g.startColumn)!=null?W:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(k=(T=u==null?void 0:u.canvasRender)==null?void 0:T.calcCellAutoHeight)==null?void 0:k.call(T,C)},e.interceptorAutoWidth=()=>{var F,j,B,W,T,k;const f=(j=(F=this._renderManagerService.getRenderById(i))==null?void 0:F.with(x.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:j.skeleton;if(!f)return;const g=f.worksheet.getMergedCell(r,a),C={data:e,style:f.getStyles().getStyleByCell(e),primaryWithCoord:f.getCellWithCoordByIndex((B=g==null?void 0:g.startRow)!=null?B:r,(W=g==null?void 0:g.startColumn)!=null?W:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(k=(T=u==null?void 0:u.canvasRender)==null?void 0:T.calcCellAutoWidth)==null?void 0:k.call(T,C)},e.coverable=((A=e==null?void 0:e.coverable)!=null?A:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(oe.filter(e=>e.source==="command"),oe.bufferTime(16)).subscribe(e=>{const t=[];if(e.forEach(n=>{var r;(n.rule.type===o.DataValidationType.LIST_MULTIPLE||n.rule.type===o.DataValidationType.LIST)&&(r=n.rule)!=null&&r.ranges&&t.push(...n.rule.ranges)}),t.length){const n=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(n.redos,this._commandService)}})}};wt=Ct([q(0,o.ICommandService),q(1,O.IRenderManagerService),q(2,o.Inject(x.AutoHeightController)),q(3,o.Inject(X.DataValidatorRegistryService)),q(4,o.Inject(N.SheetInterceptorService)),q(5,o.Inject(_.SheetDataValidationModel)),q(6,o.Inject(_.DataValidationCacheService))],wt);var rn=Object.getOwnPropertyDescriptor,an=(e,t,n,r)=>{for(var a=r>1?void 0:r?rn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Et=(e,t)=>(n,r)=>t(n,r,e);let He=class extends o.Disposable{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){const e=t=>{var r;if(!t.length)return;const n=new Set;t.forEach(a=>{n.add(a.subUnitId)}),n.forEach(a=>{var i;(i=this._sheetSkeletonManagerService.getSkeletonParam(a))==null||i.skeleton.makeDirty(!0)}),(r=this._context.mainComponent)==null||r.makeForceDirty()};this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(o.bufferDebounceTime(16)).subscribe(e))}};He=an([Et(1,o.Inject(_.SheetDataValidationModel)),Et(2,o.Inject(x.SheetSkeletonManagerService))],He);function Ce({ref:e,...t}){const{icon:n,id:r,className:a,extend:i,...s}=t,d=`univerjs-icon univerjs-icon-${r} ${a||""}`.trim(),l=R.useRef(`_${ln()}`);return Dt(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:d,...s},i)}function Dt(e,t,n,r,a){return R.createElement(e.tag,{key:t,...on(e,n,a),...r},(sn(e,n).children||[]).map((i,s)=>Dt(i,`${t}-${e.tag}-${s}`,n,void 0,a)))}function on(e,t,n){const r={...e.attrs};n!=null&&n.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=n.colorChannel1),e.tag==="mask"&&r.id&&(r.id=r.id+t.idSuffix),Object.entries(r).forEach(([i,s])=>{i==="mask"&&typeof s=="string"&&(r[i]=s.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:a}=t;return!a||a.length===0||(e.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+t.idSuffix),Object.entries(r).forEach(([i,s])=>{typeof s=="string"&&(r[i]=s.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function sn(e,t){var r;const{defIds:n}=t;return!n||n.length===0?e:e.tag==="defs"&&((r=e.children)!=null&&r.length)?{...e,children:e.children.map(a=>typeof a.attrs.id=="string"&&n&&n.includes(a.attrs.id)?{...a,attrs:{...a.attrs,id:a.attrs.id+t.idSuffix}}:a)}:e}function ln(){return Math.random().toString(36).substring(2,8)}Ce.displayName="UniverIcon";const dn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.4917 3.07803C1.4917 2.19437 2.20804 1.47803 3.0917 1.47803H5.6917C6.57536 1.47803 7.2917 2.19437 7.2917 3.07803V5.67803C7.2917 6.56168 6.57535 7.27803 5.6917 7.27803H3.0917C2.20804 7.27803 1.4917 6.56168 1.4917 5.67803V3.07803ZM3.0917 2.67803C2.87078 2.67803 2.6917 2.85711 2.6917 3.07803V5.67803C2.6917 5.89894 2.87079 6.07803 3.0917 6.07803H5.6917C5.91261 6.07803 6.0917 5.89894 6.0917 5.67803V3.07803C6.0917 2.85711 5.91261 2.67803 5.6917 2.67803H3.0917Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.6175 2.45279C14.8518 2.68711 14.8518 3.06701 14.6175 3.30132L11.6151 6.30365C11.3957 6.52307 11.0451 6.53897 10.8067 6.34031L8.80915 4.67566C8.55458 4.46352 8.52019 4.08518 8.73233 3.83062C8.94447 3.57605 9.32281 3.54166 9.57737 3.7538L11.154 5.06767L13.769 2.45278C14.0033 2.21847 14.3832 2.21848 14.6175 2.45279Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.1175 9.19746C14.3518 9.43178 14.3518 9.81168 14.1175 10.046L12.5418 11.6217L14.1175 13.1975C14.3518 13.4318 14.3518 13.8117 14.1175 14.046C13.8832 14.2803 13.5033 14.2803 13.269 14.046L11.6933 12.4703L10.1175 14.046C9.88321 14.2803 9.50331 14.2803 9.269 14.046C9.03468 13.8117 9.03468 13.4318 9.269 13.1975L10.8447 11.6217L9.269 10.046C9.03468 9.81168 9.03468 9.43178 9.269 9.19746C9.50331 8.96315 9.88321 8.96315 10.1175 9.19746L11.6933 10.7732L13.269 9.19746C13.5033 8.96315 13.8832 8.96315 14.1175 9.19746Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.0917 8.72168C2.20804 8.72168 1.4917 9.43802 1.4917 10.3217V12.9217C1.4917 13.8053 2.20804 14.5217 3.0917 14.5217H5.6917C6.57535 14.5217 7.2917 13.8053 7.2917 12.9217V10.3217C7.2917 9.43802 6.57536 8.72168 5.6917 8.72168H3.0917ZM2.6917 10.3217C2.6917 10.1008 2.87078 9.92168 3.0917 9.92168H5.6917C5.91261 9.92168 6.0917 10.1008 6.0917 10.3217V12.9217C6.0917 13.1426 5.91261 13.3217 5.6917 13.3217H3.0917C2.87079 13.3217 2.6917 13.1426 2.6917 12.9217V10.3217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Mt=R.forwardRef(function(t,n){return R.createElement(Ce,Object.assign({},t,{id:"data-validation-icon",ref:n,icon:dn}))});Mt.displayName="DataValidationIcon";const cn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},at=R.forwardRef(function(t,n){return R.createElement(Ce,Object.assign({},t,{id:"delete-icon",ref:n,icon:cn}))});at.displayName="DeleteIcon";const un={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},bt=R.forwardRef(function(t,n){return R.createElement(Ce,Object.assign({},t,{id:"increase-icon",ref:n,icon:un}))});bt.displayName="IncreaseIcon";const hn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},it=R.forwardRef(function(t,n){return R.createElement(Ce,Object.assign({},t,{id:"more-down-icon",ref:n,icon:hn}))});it.displayName="MoreDownIcon";const pn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.64645 9.85355C4.45118 9.65829 4.45118 9.34171 4.64645 9.14645L7.64645 6.14645C7.84171 5.95118 8.15829 5.95118 8.35355 6.14645L11.3536 9.14645C11.5488 9.34171 11.5488 9.65829 11.3536 9.85355C11.1583 10.0488 10.8417 10.0488 10.6464 9.85355L8 7.20711L5.35355 9.85355C5.15829 10.0488 4.84171 10.0488 4.64645 9.85355Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Tt=R.forwardRef(function(t,n){return R.createElement(Ce,Object.assign({},t,{id:"more-up-icon",ref:n,icon:pn}))});Tt.displayName="MoreUpIcon";const vn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M6 5C6.55228 5 7 4.55228 7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4C5 4.55228 5.44772 5 6 5Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6 9C6.55228 9 7 8.55229 7 8C7 7.44772 6.55228 7 6 7C5.44772 7 5 7.44772 5 8C5 8.55229 5.44772 9 6 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M7 12C7 12.5523 6.55228 13 6 13C5.44772 13 5 12.5523 5 12C5 11.4477 5.44772 11 6 11C6.55228 11 7 11.4477 7 12Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M10 5C10.5523 5 11 4.55228 11 4C11 3.44772 10.5523 3 10 3C9.44771 3 9 3.44772 9 4C9 4.55228 9.44771 5 10 5Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M11 8C11 8.55229 10.5523 9 10 9C9.44771 9 9 8.55229 9 8C9 7.44772 9.44771 7 10 7C10.5523 7 11 7.44772 11 8Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M10 13C10.5523 13 11 12.5523 11 12C11 11.4477 10.5523 11 10 11C9.44771 11 9 11.4477 9 12C9 12.5523 9.44771 13 10 13Z"}}]},Rt=R.forwardRef(function(t,n){return R.createElement(Ce,Object.assign({},t,{id:"sequence-icon",ref:n,icon:vn}))});Rt.displayName="SequenceIcon";function gn(e){var c;const t=E.useDependency(o.LocaleService),n=E.useDependency(E.ComponentManager),{value:r,onChange:a,extraComponent:i}=e,[s,d]=R.useState(!1),l=i?n.get(i):null;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white",onClick:()=>d(!s),children:[t.t("dataValidation.panel.options"),s?p.jsx(Tt,{className:"univer-ml-1"}):p.jsx(it,{className:"univer-ml-1"})]}),s&&p.jsxs(p.Fragment,{children:[l?p.jsx(l,{value:r,onChange:a}):null,p.jsx(M.FormLayout,{label:t.t("dataValidation.panel.invalid"),children:p.jsxs(M.RadioGroup,{value:`${(c=r.errorStyle)!=null?c:o.DataValidationErrorStyle.WARNING}`,onChange:h=>a({...r,errorStyle:+h}),children:[p.jsx(M.Radio,{value:`${o.DataValidationErrorStyle.WARNING}`,children:t.t("dataValidation.panel.showWarning")}),p.jsx(M.Radio,{value:`${o.DataValidationErrorStyle.STOP}`,children:t.t("dataValidation.panel.rejectInput")})]})}),p.jsx(M.FormLayout,{label:t.t("dataValidation.panel.messageInfo"),children:p.jsx(M.Checkbox,{checked:r.showErrorMessage,onChange:()=>a({...r,showErrorMessage:!r.showErrorMessage}),children:t.t("dataValidation.panel.showInfo")})}),r.showErrorMessage?p.jsx(M.FormLayout,{children:p.jsx(M.Input,{value:r.error,onChange:h=>a({...r,error:h})})}):null]})]})}const fn=e=>o.debounce(async(t,n,r,a)=>{const i=await e.executeCommand(t,n,r);a==null||a(i)},1e3);function mn(e,t,n){var r,a,i,s;return t?((a=(r=e.getUnit(t))==null?void 0:r.getSheetBySheetName(n))==null?void 0:a.getSheetId())||"":((s=(i=e.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetName(n))==null?void 0:s.getSheetId())||""}function Sn(){var H,te;const[e,t]=R.useState(0),n=E.useDependency(ue),r=E.useObservable(n.activeRule$,n.activeRule),{unitId:a,subUnitId:i,rule:s}=r||{},d=s.uid,l=E.useDependency(X.DataValidatorRegistryService),c=E.useDependency(o.IUniverInstanceService),h=E.useDependency(E.ComponentManager),v=E.useDependency(o.ICommandService),u=E.useDependency(X.DataValidationModel),S=E.useDependency(o.LocaleService),w=E.useObservable(()=>c.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),P=E.useObservable(()=>{var b;return(b=w==null?void 0:w.activeSheet$)!=null?b:oe.of(null)},void 0,void 0,[]),[m,y]=R.useState(s),I=l.getValidatorItem(m.type),[D,A]=R.useState(!1),f=l.getValidatorsByScope(X.DataValidatorRegistryScope.SHEET),[g,C]=R.useState(()=>m.ranges.map(b=>({unitId:"",sheetId:"",range:b}))),F=R.useMemo(()=>fn(v),[v]),[j,B]=R.useState(!1),[W,T]=R.useState(!1),k=R.useRef(null),Y=E.useDependency(N.SheetsSelectionsService);if(R.useEffect(()=>()=>{const b=Y.getCurrentLastSelection();b&&Y.setSelections([b])},[Y]),R.useEffect(()=>{v.onCommandExecuted(b=>{(b.id===o.UndoCommand.id||b.id===o.RedoCommand.id)&&setTimeout(()=>{const Z=u.getRuleById(a,i,d);t(J=>J+1),Z&&(y(Z),C(Z.ranges.map(J=>({unitId:"",sheetId:"",range:J}))))},20)})},[v,u,d,i,a]),!I)return null;const $=I.operators,K=I.operatorNames,ae=m.operator?X.TWO_FORMULA_OPERATOR_COUNT.includes(m.operator):!1,G=()=>{(P==null?void 0:P.getSheetId())!==i&&v.syncExecuteCommand(N.SetWorksheetActiveOperation.id,{unitId:a,subUnitId:i})},se=()=>{var b,Z,J;(Z=(b=k.current)==null?void 0:b.editor)!=null&&Z.isFocus()&&le((J=k.current)==null?void 0:J.getValue()),!(!m.ranges.length||j)&&(I.validatorFormula(m,a,i).success?n.setActiveRule(null):A(!0),G())},le=E.useEvent(b=>{const Z=b.split(",").filter(Boolean).map(qe.deserializeRangeWithSheet).map(ie=>{const Ut=ie.sheetName;if(Ut){const dr=mn(c,ie.unitId,Ut);return{...ie,sheetId:dr}}return{...ie,sheetId:""}});if(o.isUnitRangesEqual(Z,g))return;C(Z);const J=Z.filter(ie=>(!ie.unitId||ie.unitId===a)&&(!ie.sheetId||ie.sheetId===i)).map(ie=>ie.range);if(y({...m,ranges:J}),J.length===0)return;const ge={unitId:a,subUnitId:i,ruleId:d,ranges:J};F(_.UpdateSheetDataValidationRangeCommand.id,ge)}),de=b=>{if(o.shallowEqual(b,X.getRuleSetting(m)))return;y({...m,...b});const Z={unitId:a,subUnitId:i,ruleId:d,setting:b};F(_.UpdateSheetDataValidationSettingCommand.id,Z,void 0)},fe=async()=>{await v.executeCommand(_.RemoveSheetDataValidationCommand.id,{ruleId:d,unitId:a,subUnitId:i}),n.setActiveRule(null),G()},ne={type:m.type,operator:m.operator,formula1:m.formula1,formula2:m.formula2,allowBlank:m.allowBlank},Q=b=>{const Z=l.getValidatorItem(b);if(!Z)return;const J=Z.operators,ge=u.getRuleById(a,i,d),ie=b===(ge==null?void 0:ge.type)||b.includes("list")&&(ge!=null&&ge.type.includes("list"))?{...ge,type:b}:{...m,type:b,operator:J[0],formula1:void 0,formula2:void 0};y(ie),v.executeCommand(_.UpdateSheetDataValidationSettingCommand.id,{unitId:a,subUnitId:i,ruleId:m.uid,setting:X.getRuleSetting(ie)})},ce=h.get(I.formulaInput),re=R.useMemo(()=>g.map(b=>qe.serializeRange(b.range)).join(","),[]),ee=X.getRuleOptions(m),V=b=>{o.shallowEqual(b,X.getRuleOptions(m))||(y({...m,...b}),F(_.UpdateSheetDataValidationOptionsCommand.id,{unitId:a,subUnitId:i,ruleId:d,options:b}))},z=$.length&&!m.operator;return p.jsxs("div",{"data-u-comp":"data-validation-detail",className:"univer-py-2",children:[p.jsx(M.FormLayout,{label:S.t("dataValidation.panel.range"),error:!m.ranges.length||j?S.t("dataValidation.panel.rangeError"):"",children:p.jsx(Je.RangeSelector,{selectorRef:k,unitId:a,subUnitId:i,initialValue:re,onChange:(b,Z)=>{var J;!W&&((J=k.current)!=null&&J.verify())&&le(Z)},onFocusChange:(b,Z)=>{var J;T(b),!b&&Z&&((J=k.current)!=null&&J.verify())&&le(Z)},onVerify:b=>B(!b)})}),p.jsx(M.FormLayout,{label:S.t("dataValidation.panel.type"),children:p.jsx(M.Select,{className:"univer-w-full",value:m.type,options:(H=f==null?void 0:f.sort((b,Z)=>b.order-Z.order))==null?void 0:H.map(b=>({label:S.t(b.title),value:b.id})),onChange:Q})}),$!=null&&$.length?p.jsx(M.FormLayout,{label:S.t("dataValidation.panel.operator"),children:p.jsx(M.Select,{className:"univer-w-full",value:`${m.operator}`,options:[{value:"",label:S.t("dataValidation.operators.legal")},...$.map((b,Z)=>({value:`${b}`,label:K[Z]}))],onChange:b=>{de({...ne,operator:b})}})}):null,ce&&!z?p.jsx(ce,{isTwoFormula:ae,value:{formula1:m.formula1,formula2:m.formula2},onChange:b=>{de({...ne,...b})},showError:D,validResult:I.validatorFormula(m,a,i),unitId:a,subUnitId:i,ruleId:d},e+m.type):null,p.jsx(M.FormLayout,{children:p.jsx(M.Checkbox,{checked:(te=m.allowBlank)!=null?te:!0,onChange:()=>{var b;return de({...ne,allowBlank:!((b=m.allowBlank)==null||b)})},children:S.t("dataValidation.panel.allowBlank")})}),p.jsx(gn,{value:ee,onChange:V,extraComponent:I.optionsInput}),p.jsxs("div",{className:"univer-mt-5 univer-flex univer-flex-row univer-justify-end",children:[p.jsx(M.Button,{className:"univer-ml-3",onClick:fe,children:S.t("dataValidation.panel.removeRule")}),p.jsx(M.Button,{className:"univer-ml-3",variant:"primary",onClick:se,children:S.t("dataValidation.panel.done")})]})]})}const _n=e=>{const{rule:t,onClick:n,unitId:r,subUnitId:a,disable:i}=e,s=E.useDependency(X.DataValidatorRegistryService),d=E.useDependency(o.ICommandService),l=E.useDependency(x.IMarkSelectionService),c=s.getValidatorItem(t.type),h=R.useRef(void 0),[v,u]=R.useState(!1),S=E.useDependency(o.ThemeService),w=E.useObservable(S.currentTheme$),P=R.useMemo(()=>{var f;const y=S.getColorFromTheme("primary.600"),I=S.getColorFromTheme("loop-color.2"),D=(f=S.getColorFromTheme(I))!=null?f:y,A=new o.ColorKit(D).toRgb();return{fill:`rgba(${A.r}, ${A.g}, ${A.b}, 0.1)`,stroke:D}},[w]),m=y=>{d.executeCommand(_.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:r,subUnitId:a}),y.stopPropagation()};return R.useEffect(()=>()=>{var y;h.current&&((y=h.current)==null||y.forEach(I=>{I&&l.removeShape(I)}))},[l]),p.jsxs("div",{className:M.clsx(`
|
|
15
|
-
univer-bg-secondary univer-relative univer--mx-2 univer-box-border univer-flex univer-w-[287px]
|
|
16
|
-
univer-cursor-pointer univer-flex-col univer-justify-between univer-overflow-hidden univer-rounded-md
|
|
17
|
-
univer-p-2 univer-pr-9
|
|
18
|
-
`,{"hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700":!i,"univer-opacity-50":i}),onClick:n,onMouseEnter:()=>{i||(u(!0),h.current=t.ranges.map(y=>l.addShape({range:y,style:P,primary:null})))},onMouseLeave:()=>{var y;u(!1),(y=h.current)==null||y.forEach(I=>{I&&l.removeShape(I)}),h.current=void 0},children:[p.jsx("div",{className:"univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900 dark:!univer-text-white",children:c==null?void 0:c.generateRuleName(t)}),p.jsx("div",{className:"univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px] dark:!univer-text-gray-300",children:t.ranges.map(y=>qe.serializeRange(y)).join(",")}),v?p.jsx("div",{className:"univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-size-5 univer-items-center univer-justify-center univer-rounded hover:univer-bg-gray-200 dark:!univer-text-gray-300 dark:hover:!univer-bg-gray-700",onClick:m,children:p.jsx(at,{})}):null]})};function In(e){const t=E.useDependency(_.SheetDataValidationModel),n=E.useDependency(o.IUniverInstanceService),r=E.useDependency(o.ICommandService),a=E.useDependency(o.Injector),i=E.useDependency(ue),s=E.useDependency(o.LocaleService),[d,l]=R.useState([]),{workbook:c}=e,h=E.useObservable(c.activeSheet$,void 0,!0),v=c.getUnitId(),u=h==null?void 0:h.getSheetId();R.useEffect(()=>{l(t.getRules(v,u));const I=t.ruleChange$.subscribe(D=>{D.unitId===v&&D.subUnitId===u&&l(t.getRules(v,u))});return()=>{I.unsubscribe()}},[v,u,t]);const S=async()=>{const I=_.createDefaultNewRule(a),D={unitId:v,subUnitId:u,rule:I};await r.executeCommand(_.AddSheetDataValidationCommand.id,D),i.setActiveRule({unitId:v,subUnitId:u,rule:I})},w=()=>{r.executeCommand(_.RemoveSheetAllDataValidationCommand.id,{unitId:v,subUnitId:u})},m=(I=>{const D=n.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),A=D.getActiveSheet(),f=D.getUnitId(),g=A.getSheetId();return I.map(F=>N.checkRangesEditablePermission(a,f,g,F.ranges)?{...F}:{...F,disable:!0})})(d),y=m==null?void 0:m.some(I=>I.disable);return p.jsxs("div",{className:"univer-pb-4",children:[m==null?void 0:m.map(I=>{var D;return p.jsx(_n,{unitId:v,subUnitId:u,onClick:()=>{I.disable||i.setActiveRule({unitId:v,subUnitId:u,rule:I})},rule:I,disable:(D=I.disable)!=null?D:!1},I.uid)}),p.jsxs("div",{className:"univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[d.length&&!y?p.jsx(M.Button,{onClick:w,children:s.t("dataValidation.panel.removeAll")}):null,p.jsx(M.Button,{variant:"primary",onClick:S,children:s.t("dataValidation.panel.add")})]})]})}const Cn=()=>{const e=E.useDependency(ue),t=E.useObservable(e.activeRule$,e.activeRule),n=E.useDependency(o.IUniverInstanceService),r=E.useObservable(()=>n.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),a=E.useObservable(()=>{var i;return(i=r==null?void 0:r.activeSheet$)!=null?i:oe.of(null)},void 0,void 0,[]);return!r||!a?null:t&&(t.subUnitId===a.getSheetId()||t.subUnitId===e.getFocusFormulaEditorActiveRuleSubUnitId())?p.jsx(Sn,{},t.rule.uid):p.jsx(In,{workbook:r})},yn=e=>{const{isTwoFormula:t=!1,value:n,onChange:r,showError:a,validResult:i}=e,s=E.useDependency(o.LocaleService),d=a?i==null?void 0:i.formula1:"",l=a?i==null?void 0:i.formula2:"";return t?p.jsxs(p.Fragment,{children:[p.jsx(M.FormLayout,{error:d,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:n==null?void 0:n.formula1,onChange:c=>{r==null||r({...n,formula1:c})}})}),p.jsx("div",{className:"-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400",children:s.t("dataValidation.panel.formulaAnd")}),p.jsx(M.FormLayout,{error:l,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:n==null?void 0:n.formula2,onChange:c=>{r==null||r({...n,formula2:c})}})})]}):p.jsx(M.FormLayout,{error:d,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:n==null?void 0:n.formula1,onChange:c=>{r==null||r({formula1:c})}})})};function wn(e){const{value:t,onChange:n,showError:r,validResult:a}=e,i=E.useDependency(o.LocaleService),s=r?a==null?void 0:a.formula1:"",d=r?a==null?void 0:a.formula2:"",[l,c]=R.useState(!((t==null?void 0:t.formula1)===void 0&&(t==null?void 0:t.formula2)===void 0));return p.jsxs(p.Fragment,{children:[p.jsx(M.FormLayout,{children:p.jsx(M.Checkbox,{checked:l,onChange:h=>{h?c(!0):(c(!1),n==null||n({...t,formula1:void 0,formula2:void 0}))},children:i.t("dataValidation.checkbox.tips")})}),l?p.jsx(M.FormLayout,{label:i.t("dataValidation.checkbox.checked"),error:s,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula1,onChange:h=>{n==null||n({...t,formula1:h||void 0})}})}):null,l?p.jsx(M.FormLayout,{label:i.t("dataValidation.checkbox.unchecked"),error:d,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula2,onChange:h=>{n==null||n({...t,formula2:h||void 0})}})}):null]})}function En(e){var v;const{unitId:t,subUnitId:n,value:r,onChange:a,showError:i,validResult:s}=e,d=i?s==null?void 0:s.formula1:void 0,l=R.useRef(null),[c,h]=R.useState(!1);return E.useSidebarClick(u=>{var w;(w=l.current)!=null&&w.isClickOutSide(u)&&h(!1)}),p.jsx(M.FormLayout,{error:d,children:p.jsx(Je.FormulaEditor,{ref:l,className:M.clsx("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent",M.borderClassName),initValue:(v=r==null?void 0:r.formula1)!=null?v:"=",unitId:t,subUnitId:n,isFocus:c,isSupportAcrossSheet:!0,onChange:u=>{const S=(u!=null?u:"").trim();S!==(r==null?void 0:r.formula1)&&(a==null||a({...r,formula1:S}))},onFocus:()=>h(!0)})})}const Dn=["#FFFFFF","#FEE7E7","#FEF0E6","#EFFBD0","#E4F4FE","#E8ECFD","#F1EAFA","#FDE8F3","#E5E5E5","#FDCECE","#FDC49B","#DEF6A2","#9FDAFF","#D0D9FB","#E3D5F6","#FBD0E8","#656565","#FE4B4B","#FF8C51","#8BBB11","#0B9EFB","#3A60F7","#9E6DE3","#F248A6"],Mn=e=>{const{value:t,onChange:n,disabled:r}=e,[a,i]=R.useState(!1);return p.jsx(M.Dropdown,{align:"start",disabled:r,open:a,onOpenChange:i,overlay:p.jsx("div",{className:"univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5",children:Dn.map(s=>p.jsx("div",{className:M.clsx("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded",M.borderClassName),style:{background:s},onClick:()=>{n(s),i(!1)}},s))}),children:p.jsxs("div",{className:M.clsx("univer-box-border univer-inline-flex univer-h-8 univer-w-16 univer-cursor-pointer univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white",M.borderClassName),children:[p.jsx("div",{className:"univer-box-border univer-size-4 univer-rounded univer-text-base",style:{background:t}}),p.jsx(it,{})]})})},Vt=e=>{const{item:t,commonProps:n,className:r}=e,{onItemChange:a,onItemDelete:i}=n;return p.jsxs("div",{className:M.clsx("univer-flex univer-items-center univer-gap-2",r),children:[!t.isRef&&p.jsx("div",{className:M.clsx("univer-cursor-move","draggableHandle"),children:p.jsx(Rt,{})}),p.jsx(Mn,{value:t.color,onChange:s=>{a(t.id,t.label,s)}}),p.jsx(M.Input,{disabled:t.isRef,value:t.label,onChange:s=>{a(t.id,s,t.color)}}),t.isRef?null:p.jsx("div",{className:"univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",children:p.jsx(at,{onClick:()=>i(t.id)})})]})};function bn(e){const{value:t,onChange:n=()=>{},unitId:r,subUnitId:a,validResult:i,showError:s,ruleId:d}=e,{formula1:l="",formula2:c=""}=t||{},[h,v]=R.useState(()=>o.isFormulaString(l)?"1":"0"),[u,S]=R.useState(h==="1"?l:"="),[w,P]=R.useState(h==="1"?l:"="),m=E.useDependency(o.LocaleService),y=E.useDependency(X.DataValidatorRegistryService),I=E.useDependency(X.DataValidationModel),D=E.useDependency(_.DataValidationFormulaController),A=E.useDependency(ue),[f,g]=R.useState(()=>c.split(",")),C=y.getValidatorItem(o.DataValidationType.LIST),[F,j]=R.useState([]),[B,W]=R.useState(""),T=s?i==null?void 0:i.formula1:"",k=R.useMemo(()=>I.ruleChange$.pipe(oe.debounceTime(16)),[]),Y=E.useObservable(k),$=E.useEvent(n);R.useEffect(()=>{(async()=>{await new Promise(H=>{setTimeout(()=>H(!0),100)});const V=I.getRuleById(r,a,d),z=V==null?void 0:V.formula1;if(o.isFormulaString(z)&&C&&V){const H=await C.getListAsync(V,r,a);j(H)}})()},[I,Y,C,d,a,r]),R.useEffect(()=>{o.isFormulaString(l)&&l!==w&&(S(l),P(w))},[w,l]);const[K,ae]=R.useState(()=>{const V=h!=="1"?_.deserializeListOptions(l):[],z=c.split(",");return V.map((H,te)=>({label:H,color:z[te]||me,isRef:!1,id:o.generateRandomId(4)}))}),G=(V,z,H)=>{const te=K.find(b=>b.id===V);te&&(te.label=z,te.color=H,ae([...K]))},se=V=>{const z=K.findIndex(H=>H.id===V);z!==-1&&(K.splice(z,1),ae([...K]))},le=c.split(","),de=R.useMemo(()=>F.map((V,z)=>({label:V,color:le[z]||me,id:`${z}`,isRef:!0})),[le,F]),fe=(V,z,H)=>{const te=[...f];te[+V]=H,g(te),$({formula1:l,formula2:te.join(",")})},ne=()=>{ae([...K,{label:"",color:me,isRef:!1,id:o.generateRandomId(4)}])};R.useEffect(()=>{if(h==="1")return;const V=new Set,z=[];K.map(H=>({labelList:H.label.split(","),item:H})).forEach(({item:H,labelList:te})=>{te.forEach(b=>{V.has(b)||(V.add(b),z.push({label:b,color:H.color}))})}),$({formula1:_.serializeListOptions(z.map(H=>H.label)),formula2:z.map(H=>H.color===me?"":H.color).join(",")})},[K,$,h,w,f]);const Q=E.useEvent(async V=>{if(!o.isFormulaString(V)){$==null||$({formula1:"",formula2:c});return}D.getFormulaRefCheck(V)?($==null||$({formula1:o.isFormulaString(V)?V:"",formula2:c}),W("")):($==null||$({formula1:"",formula2:c}),S("="),W(m.t("dataValidation.validFail.formulaError")))}),ce=R.useRef(null),[re,ee]=R.useState(!1);return E.useSidebarClick(V=>{var H;(H=ce.current)!=null&&H.isClickOutSide(V)&&ee(!1)}),R.useEffect(()=>{re?A.setFocusFormulaEditorActiveRuleSubUnitId(a):A.setFocusFormulaEditorActiveRuleSubUnitId(null)},[re,a,A]),p.jsxs(p.Fragment,{children:[p.jsx(M.FormLayout,{label:m.t("dataValidation.list.options"),children:p.jsxs(M.RadioGroup,{value:h,onChange:V=>{v(V),S(w),V==="1"&&$({formula1:w==="="?"":w,formula2:f.join(",")})},children:[p.jsx(M.Radio,{value:"0",children:m.t("dataValidation.list.customOptions")}),p.jsx(M.Radio,{value:"1",children:m.t("dataValidation.list.refOptions")})]})}),h==="1"?p.jsxs(M.FormLayout,{error:T||B||void 0,children:[p.jsx(Je.FormulaEditor,{ref:ce,className:M.clsx("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent",M.borderClassName),initValue:u,unitId:r,subUnitId:a,isFocus:re,isSupportAcrossSheet:!0,onFocus:()=>ee(!0),onChange:(V="")=>{const z=(V!=null?V:"").trim();P(z),Q(z)}}),de.length>0&&p.jsx("div",{className:"univer-mt-3",children:de.map(V=>p.jsx(Vt,{className:"univer-mb-3",item:V,commonProps:{onItemChange:fe}},V.id))})]}):p.jsx(M.FormLayout,{error:T,children:p.jsxs("div",{className:"-univer-mt-3",children:[p.jsx(M.DraggableList,{list:K,onListChange:ae,rowHeight:28,margin:[0,12],draggableHandle:".draggableHandle",itemRender:V=>p.jsx(Vt,{item:V,commonProps:{onItemChange:G,onItemDelete:se}},V.id),idKey:"id"}),p.jsxs("a",{className:"univer-text-primary univer-flex univer-w-fit univer-cursor-pointer univer-flex-row univer-items-center univer-rounded univer-p-1 univer-px-2 univer-text-sm hover:univer-bg-primary-50 dark:hover:!univer-bg-gray-800",onClick:ne,children:[p.jsx(bt,{className:"univer-mr-1"}),m.t("dataValidation.list.add")]})]})})]})}const Tn=[[_.CUSTOM_FORMULA_INPUT_NAME,En],[_.BASE_FORMULA_INPUT_NAME,yn],[_.LIST_FORMULA_INPUT_NAME,bn],[_.CHECKBOX_FORMULA_INPUT_NAME,wn]],Rn="LIST_RENDER_MODE_OPTION_INPUT";function xe(e){var a;const{value:t,onChange:n}=e,r=E.useDependency(o.LocaleService);return p.jsx(M.FormLayout,{label:r.t("dataValidation.renderMode.label"),children:p.jsxs(M.RadioGroup,{value:`${(a=t.renderMode)!=null?a:o.DataValidationRenderMode.CUSTOM}`,onChange:i=>n({...t,renderMode:+i}),children:[p.jsx(M.Radio,{value:`${o.DataValidationRenderMode.CUSTOM}`,children:r.t("dataValidation.renderMode.chip")}),p.jsx(M.Radio,{value:`${o.DataValidationRenderMode.ARROW}`,children:r.t("dataValidation.renderMode.arrow")}),p.jsx(M.Radio,{value:`${o.DataValidationRenderMode.TEXT}`,children:r.t("dataValidation.renderMode.text")})]})})}xe.componentKey=Rn;const Vn="DATE_SHOW_TIME_OPTION";function Ye(e){var a;const{value:t,onChange:n}=e,r=E.useDependency(o.LocaleService);return p.jsx(M.FormLayout,{children:p.jsx(M.Checkbox,{checked:(a=t.bizInfo)==null?void 0:a.showTime,onChange:i=>{n({...t,bizInfo:{...t.bizInfo,showTime:i}})},children:r.t("dataValidation.showTime.label")})})}Ye.componentKey=Vn;var On=Object.getOwnPropertyDescriptor,An=(e,t,n,r)=>{for(var a=r>1?void 0:r?On(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Ve=(e,t)=>(n,r)=>t(n,r,e);const Xe=6;let ot=class{constructor(e,t,n,r,a,i){this._commandService=e,this._univerInstanceService=t,this._formulaService=n,this._themeService=r,this._renderManagerService=a,this._dataValidationModel=i}_calc(e,t){var c,h,v;const{vt:n,ht:r}=t||{},a=e.endX-e.startX-Xe*2,i=e.endY-e.startY,s=((c=t==null?void 0:t.fs)!=null?c:10)*1.6;let d=0,l=0;switch(n){case o.VerticalAlign.TOP:l=0;break;case o.VerticalAlign.BOTTOM:l=0+(i-s);break;default:l=0+(i-s)/2;break}switch(r){case o.HorizontalAlign.LEFT:d=Xe;break;case o.HorizontalAlign.RIGHT:d=Xe+(a-s);break;default:d=Xe+(a-s)/2;break}return{left:e.startX+d,top:e.startY+l,width:((h=t==null?void 0:t.fs)!=null?h:10)*1.6,height:((v=t==null?void 0:t.fs)!=null?v:10)*1.6}}calcCellAutoHeight(e){var n;const{style:t}=e;return((n=t==null?void 0:t.fs)!=null?n:10)*1.6}calcCellAutoWidth(e){var n;const{style:t}=e;return((n=t==null?void 0:t.fs)!=null?n:10)*1.6}async _parseFormula(e,t,n){var c,h,v,u,S,w,P,m,y;const{formula1:r=_.CHECKBOX_FORMULA_1,formula2:a=_.CHECKBOX_FORMULA_2}=e,i=await this._formulaService.getRuleFormulaResult(t,n,e.uid),s=_.getFormulaResult((v=(h=(c=i==null?void 0:i[0])==null?void 0:c.result)==null?void 0:h[0])==null?void 0:v[0]),d=_.getFormulaResult((w=(S=(u=i==null?void 0:i[1])==null?void 0:u.result)==null?void 0:S[0])==null?void 0:w[0]),l=_.isLegalFormulaResult(String(s))&&_.isLegalFormulaResult(String(d));return{formula1:o.isFormulaString(r)?_.getFormulaResult((y=(m=(P=i==null?void 0:i[0])==null?void 0:P.result)==null?void 0:m[0])==null?void 0:y[0]):r,formula2:o.isFormulaString(a)?d:a,isFormulaValid:l}}drawWith(e,t){var W,T,k,Y;const{style:n,primaryWithCoord:r,unitId:a,subUnitId:i,worksheet:s,row:d,col:l}=t,c=r.isMergedMainCell?r.mergeInfo:r,h=_.getCellValueOrigin(s.getCellRaw(d,l)),v=this._dataValidationModel.getRuleByLocation(a,i,d,l);if(!v)return;const u=this._dataValidationModel.getValidator(v.type);if(!u||!((W=u.skipDefaultFontRender)!=null&&W.call(u,v,h,{unitId:a,subUnitId:i,row:d,column:l})))return;const S=u.parseFormulaSync(v,a,i),{formula1:w}=S,P=this._calc(c,n),{a:m,d:y}=e.getTransform(),I=O.fixLineWidthByScale(P.left,m),D=O.fixLineWidthByScale(P.top,y),A=O.Transform.create().composeMatrix({left:I,top:D,scaleX:1,scaleY:1,angle:0,skewX:0,skewY:0,flipX:!1,flipY:!1}),f=c.endX-c.startX,g=c.endY-c.startY;e.save(),e.beginPath(),e.rect(c.startX,c.startY,f,g),e.clip();const C=A.getMatrix();e.transform(C[0],C[1],C[2],C[3],C[4],C[5]);const F=((T=n==null?void 0:n.fs)!=null?T:10)*1.6,j=String(h)===String(w),B=this._themeService.getColorFromTheme("primary.600");O.CheckboxShape.drawWith(e,{checked:j,width:F,height:F,fill:(Y=(k=n==null?void 0:n.cl)==null?void 0:k.rgb)!=null?Y:B}),e.restore()}isHit(e,t){const n=t.primaryWithCoord.isMergedMainCell?t.primaryWithCoord.mergeInfo:t.primaryWithCoord,r=this._calc(n,t.style),a=r.top,i=r.top+r.height,s=r.left,d=r.left+r.width,{x:l,y:c}=e;return l<=d&&l>=s&&c<=i&&c>=a}async onPointerDown(e,t){var w;if(t.button===2)return;const{primaryWithCoord:n,unitId:r,subUnitId:a,worksheet:i,row:s,col:d}=e,l=_.getCellValueOrigin(i.getCellRaw(s,d)),c=this._dataValidationModel.getRuleByLocation(r,a,s,d);if(!c)return;const h=this._dataValidationModel.getValidator(c.type);if(!h||!((w=h.skipDefaultFontRender)!=null&&w.call(h,c,l,{unitId:r,subUnitId:a,row:s,column:d})))return;const{formula1:v,formula2:u}=await this._parseFormula(c,r,a),S={range:{startColumn:n.actualColumn,endColumn:n.actualColumn,startRow:n.actualRow,endRow:n.actualRow},value:{v:String(l)===_.transformCheckboxValue(String(v))?u:v,p:null}};this._commandService.executeCommand(N.SetRangeValuesCommand.id,S)}onPointerEnter(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.DEFAULT)}};ot=An([Ve(0,o.ICommandService),Ve(1,o.IUniverInstanceService),Ve(2,o.Inject(_.DataValidationFormulaService)),Ve(3,o.Inject(o.ThemeService)),Ve(4,o.Inject(O.IRenderManagerService)),Ve(5,o.Inject(_.SheetDataValidationModel))],ot);var Ln=Object.getOwnPropertyDescriptor,Pn=(e,t,n,r)=>{for(var a=r>1?void 0:r?Ln(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Un=(e,t)=>(n,r)=>t(n,r,e);U.BaseSheetDataValidatorView=class{constructor(t){L(this,"canvasRender",null);L(this,"dropdownType");L(this,"optionsInput");L(this,"formulaInput",_.LIST_FORMULA_INPUT_NAME);this.injector=t}},U.BaseSheetDataValidatorView=Pn([Un(0,o.Inject(o.Injector))],U.BaseSheetDataValidatorView);class Fn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);L(this,"id",o.DataValidationType.CHECKBOX);L(this,"canvasRender",this.injector.createInstance(ot));L(this,"formulaInput",_.CHECKBOX_FORMULA_INPUT_NAME)}}class kn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);L(this,"id",o.DataValidationType.CUSTOM);L(this,"formulaInput",_.CUSTOM_FORMULA_INPUT_NAME)}}const Nn="data-validation.formula-input";class jn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);L(this,"id",o.DataValidationType.DATE);L(this,"formulaInput",Nn);L(this,"optionsInput",Ye.componentKey);L(this,"dropdownType",X.DataValidatorDropdownType.DATE)}}class Bn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);L(this,"id",o.DataValidationType.DECIMAL);L(this,"formulaInput",_.BASE_FORMULA_INPUT_NAME)}}const Ot=4,Wn=0,st=4,At=4,lt=6,ze=6,ye=14;function $n(e,t){const n=O.FontCache.getTextSize(e,t),r=n.width+Ot*2,{ba:a,bd:i}=n,s=a+i;return{width:r,height:s+Wn*2,ba:a}}function dt(e,t,n,r){const a=ye+lt*2,i=n-a,s=r-ze*2,d=e.map(u=>({layout:$n(u,t),text:u}));let l;const c=[];d.forEach(u=>{const{layout:S}=u,{width:w,height:P}=S;!l||l.width+w+st>i?(l={width:w,height:P,items:[{...u,left:0}]},c.push(l)):(l.items.push({...u,left:l.width+st}),l.width=l.width+w+st)});let h=0,v=0;return c.forEach((u,S)=>{v=Math.max(v,u.width),S===c.length-1?h+=u.height:h+=u.height+At}),{lines:c,totalHeight:h,contentWidth:i,contentHeight:s,cellAutoHeight:h+ze*2,calcAutoWidth:v+a}}const Hn=8;class xn extends O.Shape{static drawWith(t,n){const{fontString:r,info:a,fill:i,color:s}=n,{layout:d,text:l}=a;t.save(),O.Rect.drawWith(t,{width:d.width,height:d.height,radius:Hn,fill:i||me}),t.translateWithPrecision(Ot,d.ba),t.font=r,t.fillStyle=s,t.fillText(l,0,0),t.restore()}}var Yn=Object.getOwnPropertyDescriptor,Xn=(e,t,n,r)=>{for(var a=r>1?void 0:r?Yn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Ke=(e,t)=>(n,r)=>t(n,r,e);const zn=new Path2D("M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z");let ct=class{constructor(e,t,n,r){L(this,"zIndex");L(this,"_dropdownInfoMap",new Map);this._commandService=e,this._univerInstanceService=t,this._renderManagerService=n,this._dataValidationModel=r}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,t,n,r,a){const i=n-ye+4;let s=4;switch(a){case o.VerticalAlign.MIDDLE:s=(r-ye)/2+4;break;case o.VerticalAlign.BOTTOM:s=r-ye+4;break}e.save(),e.translateWithPrecision(t.startX+i,t.startY+s),e.fillStyle="#565656",e.fill(zn),e.restore()}drawWith(e,t,n,r){var le,de;const{primaryWithCoord:a,row:i,col:s,style:d,data:l,subUnitId:c}=t,h=a.isMergedMainCell?a.mergeInfo:a,v=l==null?void 0:l.fontRenderExtension,{leftOffset:u=0,rightOffset:S=0,topOffset:w=0,downOffset:P=0}=v||{},m=this._ensureMap(c),y=this._generateKey(i,s),I=a.isMergedMainCell?a.mergeInfo.startRow:i,D=a.isMergedMainCell?a.mergeInfo.startColumn:s,A=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,I,D);if(!A)return;const f=this._dataValidationModel.getValidator(A.type);if(!f)return;const g={startX:h.startX+u,endX:h.endX-S,startY:h.startY+w,endY:h.endY-P},C=g.endX-g.startX,F=g.endY-g.startY,{cl:j}=d||{},B=(le=typeof j=="object"?j==null?void 0:j.rgb:j)!=null?le:"#000",W=O.getFontStyleString(d!=null?d:void 0),{vt:T,ht:k}=d||{},Y=T!=null?T:o.VerticalAlign.MIDDLE,$=(de=_.getCellValueOrigin(l))!=null?de:"",K=f.parseCellValue($),ae=f.getListWithColorMap(A),G=dt(K,W,C,F);this._drawDownIcon(e,g,C,F,Y),e.save(),e.translateWithPrecision(g.startX,g.startY),e.beginPath(),e.rect(0,0,C-ye,F),e.clip(),e.translateWithPrecision(lt,ze);let se=0;switch(Y){case o.VerticalAlign.MIDDLE:se=(G.contentHeight-G.totalHeight)/2;break;case o.VerticalAlign.BOTTOM:se=G.contentHeight-G.totalHeight;break}e.translateWithPrecision(0,se),G.lines.forEach((fe,ne)=>{e.save();const{width:Q,height:ce,items:re}=fe;let ee=0;switch(k){case o.HorizontalAlign.RIGHT:ee=G.contentWidth-Q;break;case o.HorizontalAlign.CENTER:ee=(G.contentWidth-Q)/2;break}e.translate(ee,ne*(ce+At)),re.forEach(V=>{e.save(),e.translateWithPrecision(V.left,0),xn.drawWith(e,{...W,info:V,color:B,fill:ae[V.text]}),e.restore()}),e.restore()}),e.restore(),m.set(y,{left:g.startX,top:g.startY,width:G.contentWidth+lt+ye,height:G.contentHeight+ze*2})}calcCellAutoHeight(e){var f;const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=r==null?void 0:r.fontRenderExtension,{leftOffset:d=0,rightOffset:l=0,topOffset:c=0,downOffset:h=0}=s||{},v=t.isMergedMainCell?t.mergeInfo:t,u={startX:v.startX+d,endX:v.endX-l,startY:v.startY+c,endY:v.endY-h},S=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!S)return;const w=this._dataValidationModel.getValidator(S.type);if(!w)return;const P=u.endX-u.startX,m=u.endY-u.startY,y=(f=_.getCellValueOrigin(r))!=null?f:"",I=w.parseCellValue(y),D=O.getFontStyleString(n!=null?n:void 0);return dt(I,D,P,m).cellAutoHeight}calcCellAutoWidth(e){var f;const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=r==null?void 0:r.fontRenderExtension,{leftOffset:d=0,rightOffset:l=0,topOffset:c=0,downOffset:h=0}=s||{},v=t.isMergedMainCell?t.mergeInfo:t,u={startX:v.startX+d,endX:v.endX-l,startY:v.startY+c,endY:v.endY-h},S=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!S)return;const w=this._dataValidationModel.getValidator(S.type);if(!w)return;const P=u.endX-u.startX,m=u.endY-u.startY,y=(f=_.getCellValueOrigin(r))!=null?f:"",I=w.parseCellValue(y),D=O.getFontStyleString(n!=null?n:void 0);return dt(I,D,P,m).calcAutoWidth}isHit(e,t){const{primaryWithCoord:n}=t,r=n.isMergedMainCell?n.mergeInfo:n,{endX:a}=r,{x:i}=e;return i>=a-ye&&i<=a}onPointerDown(e,t){if(t.button===2)return;const{unitId:n,subUnitId:r,row:a,col:i}=e,s={unitId:n,subUnitId:r,row:a,column:i};this._commandService.executeCommand(We.id,s)}onPointerEnter(e,t){var n,r;return(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null?void 0:r.setCursor(O.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n,r;return(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null?void 0:r.setCursor(O.CURSOR_TYPE.DEFAULT)}};ct=Xn([Ke(0,o.ICommandService),Ke(1,o.IUniverInstanceService),Ke(2,o.Inject(O.IRenderManagerService)),Ke(3,o.Inject(_.SheetDataValidationModel))],ct);class Kn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);L(this,"id",o.DataValidationType.LIST_MULTIPLE);L(this,"canvasRender",this.injector.createInstance(ct));L(this,"dropdownType",X.DataValidatorDropdownType.MULTIPLE_LIST)}}var Zn=Object.getOwnPropertyDescriptor,Gn=(e,t,n,r)=>{for(var a=r>1?void 0:r?Zn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Fe=(e,t)=>(n,r)=>t(n,r,e);const Oe=4,Ze=4,pe=14,ut=1,ve=6,Ae=3,ht=8,qn="#565656",Lt=new Path2D("M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z");function Pt(e,t,n,r,a,i,s=!0){let d=0;const l=s?Ae:0;switch(a){case o.VerticalAlign.BOTTOM:d=t-r-l;break;case o.VerticalAlign.MIDDLE:d=(t-r)/2;break;default:d=l;break}d=Math.max(Ae,d);let c=0;switch(i){case o.HorizontalAlign.CENTER:c=(e-n)/2;break;case o.HorizontalAlign.RIGHT:c=e-n;break}return c=Math.max(ve,c),{paddingLeft:c,paddingTop:d}}let pt=class{constructor(e,t,n,r,a){L(this,"_dropdownInfoMap",new Map);L(this,"zIndex");this._univerInstanceService=e,this._localeService=t,this._commandService=n,this._renderManagerService=r,this._dataValidationModel=a}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,t,n,r,a,i,s){const{t:d=o.DEFAULT_STYLES.pd.t,b:l=o.DEFAULT_STYLES.pd.b}=s,c=n-pe;let h;switch(i){case o.VerticalAlign.MIDDLE:h=(r-Ze)/2;break;case o.VerticalAlign.BOTTOM:h=r-l-a-Ae+(a/2-Ze/2);break;default:h=d+Ae+(a/2-Ze/2);break}e.save(),e.translateWithPrecision(t.startX+c,t.startY+h),e.fillStyle="#565656",e.fill(Lt),e.restore()}drawWith(e,t,n){var ae,G,se,le,de,fe;const{primaryWithCoord:r,row:a,col:i,style:s,data:d,subUnitId:l}=t,c=r.isMergedMainCell?r.mergeInfo:r,h=r.isMergedMainCell?r.mergeInfo.startRow:a,v=r.isMergedMainCell?r.mergeInfo.startColumn:i,u=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,h,v);if(!u)return;const S=this._dataValidationModel.getValidator(u.type);if(!S)return;const w=d==null?void 0:d.fontRenderExtension,{leftOffset:P=0,rightOffset:m=0,topOffset:y=0,downOffset:I=0}=w||{};if(!u||!S||!S||S.id.indexOf(o.DataValidationType.LIST)!==0||!S.skipDefaultFontRender(u))return;const D={startX:c.startX+P,endX:c.endX-m,startY:c.startY+y,endY:c.endY-I},A=D.endX-D.startX,f=D.endY-D.startY,g=this._ensureMap(l),C=this._generateKey(a,i),F=S.getListWithColorMap(u),j=_.getCellValueOrigin(d),B=`${j!=null?j:""}`,W=F[B];let{tb:T,vt:k,ht:Y,pd:$}=s||{};T=T!=null?T:o.WrapStrategy.WRAP,k=k!=null?k:o.VerticalAlign.BOTTOM,Y=Y!=null?Y:o.DEFAULT_STYLES.ht,$=$!=null?$:o.DEFAULT_STYLES.pd;const K=O.getFontStyleString(s).fontCache;if(u.renderMode===o.DataValidationRenderMode.ARROW){const{l:ne=o.DEFAULT_STYLES.pd.l,t:Q=o.DEFAULT_STYLES.pd.t,r:ce=o.DEFAULT_STYLES.pd.r,b:re=o.DEFAULT_STYLES.pd.b}=$,ee=A-ne-ce-pe-4,V=new O.DocSimpleSkeleton(B,K,T===o.WrapStrategy.WRAP,ee,1/0);V.calculate();const z=V.getTotalWidth(),H=V.getTotalHeight(),{paddingTop:te,paddingLeft:b}=Pt(ee,f-Q-re,z,H,k,Y,!0);this._drawDownIcon(e,D,A,f,H,k,$),e.save(),e.translateWithPrecision(D.startX+ne,D.startY+Q),e.beginPath(),e.rect(0,0,A-ne-ce,f-Q-re),e.clip(),e.translateWithPrecision(0,te),e.save(),e.translateWithPrecision(b,0),e.beginPath(),e.rect(0,0,ee,H),e.clip(),O.Text.drawWith(e,{text:B,fontStyle:K,width:ee,height:H,color:(ae=s==null?void 0:s.cl)==null?void 0:ae.rgb,strokeLine:!!((G=s==null?void 0:s.st)!=null&&G.s),underline:!!((se=s==null?void 0:s.ul)!=null&&se.s),warp:T===o.WrapStrategy.WRAP,hAlign:o.HorizontalAlign.LEFT},V),e.restore(),e.restore(),g.set(C,{left:D.endX-pe+n.rowHeaderWidth,top:D.startY+Q+n.columnHeaderHeight,width:pe,height:f-Q-re})}else{e.save(),e.translateWithPrecision(D.startX,D.startY),e.beginPath(),e.rect(0,0,A,f),e.clip();const ne=A-ve*2-Oe-pe-4,Q=new O.DocSimpleSkeleton(B,K,T===o.WrapStrategy.WRAP,ne,1/0);Q.calculate();const ce=Q.getTotalWidth(),re=Q.getTotalHeight(),ee=re+ut*2,V=Math.max(A-ve*2,1),{paddingTop:z}=Pt(V,f,ce,ee,k,Y);e.translateWithPrecision(ve,z),O.Rect.drawWith(e,{width:V,height:ee,fill:W||me,radius:ht}),e.save(),e.translateWithPrecision(Oe,ut),e.beginPath(),e.rect(0,0,ne,re),e.clip(),O.Text.drawWith(e,{text:B,fontStyle:K,width:ne,height:re,color:(le=s==null?void 0:s.cl)==null?void 0:le.rgb,strokeLine:!!((de=s==null?void 0:s.st)!=null&&de.s),underline:!!((fe=s==null?void 0:s.ul)!=null&&fe.s),warp:T===o.WrapStrategy.WRAP,hAlign:o.HorizontalAlign.LEFT},Q),e.restore(),e.translateWithPrecision(ne+Oe+4,(re-Ze)/2),e.fillStyle=qn,e.fill(Lt),e.restore(),g.set(C,{left:D.startX+ve+n.rowHeaderWidth,top:D.startY+z+n.columnHeaderHeight,width:V,height:ee})}}calcCellAutoHeight(e){const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=t.isMergedMainCell?t.mergeInfo:t,d=r==null?void 0:r.fontRenderExtension,{leftOffset:l=0,rightOffset:c=0,topOffset:h=0,downOffset:v=0}=d||{},u=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!u||u.renderMode===o.DataValidationRenderMode.TEXT)return;const S={startX:s.startX+l,endX:s.endX-c,startY:s.startY+h,endY:s.endY-v},w=S.endX-S.startX,P=_.getCellValueOrigin(r),m=`${P!=null?P:""}`;let{tb:y,pd:I}=n||{};const{t:D=o.DEFAULT_STYLES.pd.t,b:A=o.DEFAULT_STYLES.pd.b}=I!=null?I:{};if(y=y!=null?y:o.WrapStrategy.WRAP,u.renderMode===o.DataValidationRenderMode.ARROW){const{l:f=o.DEFAULT_STYLES.pd.l,r:g=o.DEFAULT_STYLES.pd.r}=I!=null?I:{},C=w-f-g-pe-4,F=new O.DocSimpleSkeleton(m,O.getFontStyleString(n).fontCache,y===o.WrapStrategy.WRAP,C,1/0);return F.calculate(),F.getTotalHeight()+D+A+Ae*2}else{const f=Math.max(w-ve*2-Oe-pe-4,10),g=new O.DocSimpleSkeleton(m,O.getFontStyleString(n).fontCache,y===o.WrapStrategy.WRAP,f,1/0);return g.calculate(),g.getTotalHeight()+Ae*2+ut*2}}calcCellAutoWidth(e){const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=t.isMergedMainCell?t.mergeInfo:t,d=r==null?void 0:r.fontRenderExtension,{leftOffset:l=0,rightOffset:c=0,topOffset:h=0,downOffset:v=0}=d||{},u=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!u||u.renderMode===o.DataValidationRenderMode.TEXT)return;const S={startX:s.startX+l,endX:s.endX-c,startY:s.startY+h,endY:s.endY-v},w=S.endX-S.startX,P=_.getCellValueOrigin(r),m=`${P!=null?P:""}`;let{tb:y,pd:I}=n||{};const{l:D=o.DEFAULT_STYLES.pd.l,r:A=o.DEFAULT_STYLES.pd.r}=I!=null?I:{};y=y!=null?y:o.WrapStrategy.WRAP;let f=ve*2+pe;switch(u.renderMode){case o.DataValidationRenderMode.ARROW:f=pe+4+A+D;break;case o.DataValidationRenderMode.CUSTOM:f=pe+ve*2+Oe*2+A+D+ht/2+1;break;default:f=pe+ve*2+Oe*2+A+D+ht/2+1}const g=w-f,C=new O.DocSimpleSkeleton(m,O.getFontStyleString(n).fontCache,y===o.WrapStrategy.WRAP,g,1/0);return C.calculate(),C.getTotalWidth()+f}isHit(e,t){const{subUnitId:n,row:r,col:a}=t,s=this._ensureMap(n).get(this._generateKey(r,a)),d=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,r,a);if(!d||!s||d.renderMode===o.DataValidationRenderMode.TEXT)return!1;const{top:l,left:c,width:h,height:v}=s,{x:u,y:S}=e;return u>=c&&u<=c+h&&S>=l&&S<=l+v}onPointerDown(e,t){if(t.button===2)return;const{unitId:n,subUnitId:r,row:a,col:i}=e,s={unitId:n,subUnitId:r,row:a,column:i};this._commandService.executeCommand(We.id,s)}onPointerEnter(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.DEFAULT)}};pt=Gn([Fe(0,o.IUniverInstanceService),Fe(1,o.Inject(o.LocaleService)),Fe(2,o.ICommandService),Fe(3,o.Inject(O.IRenderManagerService)),Fe(4,o.Inject(_.SheetDataValidationModel))],pt);class Jn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);L(this,"id",o.DataValidationType.LIST);L(this,"canvasRender",this.injector.createInstance(pt));L(this,"dropdownType",X.DataValidatorDropdownType.LIST);L(this,"optionsInput",xe.componentKey);L(this,"formulaInput",_.LIST_FORMULA_INPUT_NAME)}}class Qn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);L(this,"id",o.DataValidationType.TEXT_LENGTH);L(this,"formulaInput",_.BASE_FORMULA_INPUT_NAME)}}class er extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);L(this,"id",o.DataValidationType.WHOLE);L(this,"formulaInput",_.BASE_FORMULA_INPUT_NAME)}}var tr=Object.getOwnPropertyDescriptor,nr=(e,t,n,r)=>{for(var a=r>1?void 0:r?tr(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},vt=(e,t)=>(n,r)=>t(n,r,e);let Le=class extends o.RxDisposable{constructor(e,t,n){super(),this._injector=e,this._componentManger=t,this._dataValidatorRegistryService=n,this._initComponents(),this._registerValidatorViews()}_initComponents(){[["DataValidationIcon",Mt],[Be,Cn],[xe.componentKey,xe],[Ye.componentKey,Ye],...Tn].forEach(([e,t])=>{this.disposeWithMe(this._componentManger.register(e,t))})}_registerValidatorViews(){[Bn,er,Qn,jn,Fn,Jn,Kn,kn].forEach(e=>{const t=this._injector.createInstance(e),n=this._dataValidatorRegistryService.getValidatorItem(t.id);n&&(n.formulaInput=t.formulaInput,n.canvasRender=t.canvasRender,n.dropdownType=t.dropdownType,n.optionsInput=t.optionsInput)})}};Le=nr([vt(0,o.Inject(o.Injector)),vt(1,o.Inject(E.ComponentManager)),vt(2,o.Inject(X.DataValidatorRegistryService))],Le);var rr=Object.getOwnPropertyDescriptor,ar=(e,t,n,r)=>{for(var a=r>1?void 0:r?rr(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},gt=(e,t)=>(n,r)=>t(n,r,e);U.UniverSheetsDataValidationMobileUIPlugin=(Pe=class extends o.Plugin{constructor(t=je,n,r,a){super(),this._config=t,this._injector=n,this._commandService=r,this._configService=a;const{menu:i,...s}=o.merge({},je,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Ne,s)}onStarting(){[[ue],[Se],[Ue],[Me],[Re],[Te],[be],[Le]].forEach(t=>{this._injector.add(t)}),[$e,We,_t,et,_e,St].forEach(t=>{this._commandService.registerCommand(t)})}onReady(){this._injector.get(be),this._injector.get(Te),this._injector.get(O.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[He])}onRendered(){this._injector.get(Le),this._injector.get(Re)}onSteady(){this._injector.get(Me)}},L(Pe,"pluginName","SHEET_DATA_VALIDATION_UI_PLUGIN"),L(Pe,"packageName",ke.name),L(Pe,"version",ke.version),L(Pe,"type",o.UniverInstanceType.UNIVER_SHEET),Pe),U.UniverSheetsDataValidationMobileUIPlugin=ar([gt(1,o.Inject(o.Injector)),gt(2,o.ICommandService),gt(3,o.IConfigService)],U.UniverSheetsDataValidationMobileUIPlugin);var ir=Object.defineProperty,or=Object.getOwnPropertyDescriptor,sr=(e,t,n)=>t in e?ir(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,lr=(e,t,n,r)=>{for(var a=r>1?void 0:r?or(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ft=(e,t)=>(n,r)=>t(n,r,e),Ge=(e,t,n)=>sr(e,typeof t!="symbol"?t+"":t,n);U.UniverSheetsDataValidationUIPlugin=class extends o.Plugin{constructor(t=je,n,r,a){super(),this._config=t,this._injector=n,this._commandService=r,this._configService=a;const{menu:i,...s}=o.merge({},je,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Ne,s)}onStarting(){[[ue],[Se],[Ue],[Me],[Re],[Te],[be],[Ee],[Le]].forEach(t=>{this._injector.add(t)}),[$e,We,_t,et,_e,St].forEach(t=>{this._commandService.registerCommand(t)})}onReady(){this._injector.get(be),this._injector.get(Te),this._injector.get(Ee),this._injector.get(Ue),this._injector.get(O.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[He])}onRendered(){this._injector.get(Le),this._injector.get(Re)}onSteady(){this._injector.get(Me)}},Ge(U.UniverSheetsDataValidationUIPlugin,"pluginName","SHEET_DATA_VALIDATION_UI_PLUGIN"),Ge(U.UniverSheetsDataValidationUIPlugin,"packageName",ke.name),Ge(U.UniverSheetsDataValidationUIPlugin,"version",ke.version),Ge(U.UniverSheetsDataValidationUIPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),U.UniverSheetsDataValidationUIPlugin=lr([o.DependentOn(_.UniverSheetsDataValidationPlugin),ft(1,o.Inject(o.Injector)),ft(2,o.ICommandService),ft(3,o.IConfigService)],U.UniverSheetsDataValidationUIPlugin),Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})}));
|
|
19
|
-
|
|
11
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-render`),require(`@univerjs/sheets`),require(`@univerjs/sheets-data-validation`),require(`@univerjs/data-validation`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/sheets-numfmt`),require(`@univerjs/sheets-ui`),require(`@univerjs/design`),require(`react`),require(`@univerjs/engine-formula`),require(`@univerjs/sheets-formula-ui`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets`,`@univerjs/sheets-data-validation`,`@univerjs/data-validation`,`@univerjs/ui`,`rxjs`,`@univerjs/sheets-numfmt`,`@univerjs/sheets-ui`,`@univerjs/design`,`react`,`@univerjs/engine-formula`,`@univerjs/sheets-formula-ui`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidationUi={},e.UniverCore,e.UniverEngineRender,e.UniverSheets,e.UniverSheetsDataValidation,e.UniverDataValidation,e.UniverUi,e.rxjs,e.UniverSheetsNumfmt,e.UniverSheetsUi,e.UniverDesign,e.React,e.UniverEngineFormula,e.UniverSheetsFormulaUi,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var h=Object.create,g=Object.defineProperty,_=Object.getOwnPropertyDescriptor,v=Object.getOwnPropertyNames,y=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty,x=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=v(t),a=0,o=i.length,s;a<o;a++)s=i[a],!b.call(e,s)&&s!==n&&g(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=_(t,s))||r.enumerable});return e};d=((e,t,n)=>(n=e==null?{}:h(y(e)),x(t||!e||!e.__esModule?g(n,`default`,{value:e,enumerable:!0}):n,e)))(d);var S=`@univerjs/sheets-data-validation-ui`,C=`0.19.0`;function w(e){"@babel/helpers - typeof";return w=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},w(e)}function T(e,t){if(w(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(w(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function E(e){var t=T(e,`string`);return w(t)==`symbol`?t:t+``}function D(e,t,n){return(t=E(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(e,t){return function(n,r){t(n,r,e)}}function k(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 A=class extends t.Disposable{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,n){super(),this._univerInstanceService=e,this._sidebarService=n,D(this,`_open$`,new s.BehaviorSubject(!1)),D(this,`open$`,this._open$.pipe((0,s.distinctUntilChanged)())),D(this,`_activeRule`,void 0),D(this,`_activeRule$`,new s.BehaviorSubject(void 0)),D(this,`activeRule$`,this._activeRule$.asObservable()),D(this,`_closeDisposable`,null),D(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,s.filter)(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=(0,t.toDisposable)(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};A=k([O(0,t.IUniverInstanceService),O(1,o.ISidebarService)],A);let j=`sheets-data-validation-ui.config`;Symbol(j);let M={},N=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(r.VALIDATE_CELL,{handler:async(e,n,r)=>{let i=await e,{row:a,col:o,unitId:s,subUnitId:c}=n,l=this._dataValidationModel.getRuleIdByLocation(s,c,a,o),f=l?this._dataValidationModel.getRuleById(s,c,l):void 0;if(i===!1)return r(Promise.resolve(!1));if(!f||f.errorStyle!==t.DataValidationErrorStyle.STOP)return r(Promise.resolve(!0));let p=this._dataValidatorRegistryService.getValidatorItem(f.type);return!p||await this._sheetsDataValidationValidatorService.validatorCell(s,c,a,o)===t.DataValidationStatus.VALID?r(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:p.getRuleFinalError(f,{row:a,col:o,unitId:s,subUnitId:c})},footer:{title:(0,d.createElement)(u.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),r(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:(0,d.createElement)(u.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};N=k([O(0,(0,t.Inject)(r.SheetInterceptorService)),O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(a.DataValidatorRegistryService)),O(3,o.IDialogService),O(4,(0,t.Inject)(t.LocaleService)),O(5,(0,t.Inject)(i.SheetsDataValidationValidatorService))],N);let P=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return(0,t.dayjs)();if(typeof e==`number`||!Number.isNaN(+e))return(0,t.dayjs)(t.numfmt.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let n=(0,t.dayjs)(e);if(n.isValid())return n};function F(e,t){if(e===(0,c.getPatternType)(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let I=class extends t.Disposable{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,c,l,u,d){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=c,this._editorBridgeService=l,this._injector=u,this._configService=d,D(this,`_activeDropdown`,void 0),D(this,`_activeDropdown$`,new s.Subject),D(this,`_currentPopup`,null),D(this,`activeDropdown$`,this._activeDropdown$.asObservable()),D(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,n,r,i){let a=e?this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!a)return;let o=n?a.getSheetBySheetId(n):a.getActiveSheet();if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),r,i);if(!s)return;let c=this._dataValidatorRegistryService.getValidatorItem(s.type);return c==null?void 0:c.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(e){let{location:s}=e,{row:c,col:u,unitId:d,subUnitId:f,workbook:p,worksheet:m}=s;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=e,this._activeDropdown$.next(this._activeDropdown);let h=this._sheetDataValidationModel.getRuleByLocation(d,f,c,u);if(!h)return;let g=this._dataValidatorRegistryService.getValidatorItem(h.type);if(!(g!=null&&g.dropdownType))return;let _,v=async(e,i)=>{var a,s,_;if(!e)return!0;let v=e,y=m.getCell(c,u),b=v.format(i===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),x=(a=t.numfmt.parseDate(b))==null?void 0:a.v,S=i===`time`?x%1:x,C=p.getStyles().getStyleByCell(y),w=(s=C==null||(_=C.n)==null?void 0:_.pattern)==null?``:s;return h.errorStyle!==t.DataValidationErrorStyle.STOP||await g.validator({value:S,unitId:d,subUnitId:f,row:c,column:u,worksheet:m,workbook:p,interceptValue:b.replace(`Z`,``).replace(`T`,` `),t:t.CellValueType.NUMBER},h)?(await this._commandService.executeCommand(r.SetRangeValuesCommand.id,{unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:S,t:2,p:null,f:null,si:null,s:{n:{pattern:F(i,w)}}}}),await this._commandService.executeCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!0):(this._injector.has(N)&&this._injector.get(N).showReject(g.getRuleFinalError(h,{row:c,col:u,unitId:d,subUnitId:f})),!1)},y;switch(g.dropdownType){case a.DataValidatorDropdownType.DATE:{var b;let e=P((0,i.getCellValueOrigin)(m.getCellRaw(c,u))),t=!!((b=h.bizInfo)!=null&&b.showTime);y={location:s,type:`datepicker`,props:{showTime:t,onChange:e=>v(e,t?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case a.DataValidatorDropdownType.TIME:y={location:s,type:`datepicker`,props:{onChange:e=>v(e,`time`),defaultValue:P((0,i.getCellValueOrigin)(m.getCellRaw(c,u))),patternType:`time`}};break;case a.DataValidatorDropdownType.DATETIME:y={location:s,type:`datepicker`,props:{onChange:e=>v(e,`datetime`),defaultValue:P((0,i.getCellValueOrigin)(m.getCellRaw(c,u))),patternType:`datetime`}};break;case a.DataValidatorDropdownType.LIST:case a.DataValidatorDropdownType.MULTIPLE_LIST:{var x,S,C,w;let e=g.dropdownType===a.DataValidatorDropdownType.MULTIPLE_LIST,p=async t=>{let a=(0,i.serializeListOptions)(t),s={unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:a,p:null,f:null,si:null}};return this._commandService.executeCommand(r.SetRangeValuesCommand.id,s),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!e},v=(h==null?void 0:h.renderMode)===t.DataValidationRenderMode.CUSTOM||(h==null?void 0:h.renderMode)===void 0,b=g.getListWithColor(h,d,f),T=(0,i.getDataValidationCellValue)(m.getCellRaw(c,u));y={location:s,type:`list`,props:{onChange:e=>p(e),options:b.map(e=>({label:e.label,value:e.label,color:v||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(R.id,{ruleId:h.uid}),_==null||_.dispose()},defaultValue:T,multiple:e,showEdit:(x=(S=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:S.showEditOnDropdown)==null?!0:x,showSearch:(C=(w=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:w.showSearchOnDropdown)==null?!0:C}};break}case a.DataValidatorDropdownType.CASCADE:var T;y={type:`cascader`,props:{onChange:e=>{let t={unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(r.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!0},defaultValue:(0,i.getDataValidationCellValue)(m.getCellRaw(c,u)).split(`/`),options:JSON.parse((T=h.formula1)==null?`[]`:T)},location:s};break;case a.DataValidatorDropdownType.COLOR:y={type:`color`,props:{onChange:e=>{let t={unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(r.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!0},defaultValue:(0,i.getDataValidationCellValue)(m.getCellRaw(c,u))},location:s};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(_=this._cellDropdownManagerService.showDropdown({...y,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!_)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let E=new t.DisposableCollection;E.add(_),E.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=E}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,n,r,i,a){let o=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!o)return;let s=o.getSheetBySheetId(n);if(!s)return;let c=this._dataValidationModel.getRuleByLocation(o.getUnitId(),s.getSheetId(),r,i);if(!c)return;let l=this._dataValidatorRegistryService.getValidatorItem(c.type);if(!l||!l.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:o,worksheet:s,row:r,col:i,unitId:e,subUnitId:n},onHide:a})}};I=k([O(0,t.IUniverInstanceService),O(1,(0,t.Inject)(a.DataValidatorRegistryService)),O(2,o.IZenZoneService),O(3,(0,t.Inject)(i.SheetDataValidationModel)),O(4,(0,t.Inject)(r.SheetsSelectionsService)),O(5,(0,t.Inject)(l.ISheetCellDropdownManagerService)),O(6,(0,t.Inject)(i.SheetDataValidationModel)),O(7,t.ICommandService),O(8,l.IEditorBridgeService),O(9,(0,t.Inject)(t.Injector)),O(10,t.IConfigService)],I);let L=`DataValidationPanel`,R={id:`data-validation.operation.open-validation-panel`,type:t.CommandType.OPERATION,handler(e,n){if(!n)return!1;let{ruleId:i,isAdd:s}=n,c=e.get(A),l=e.get(a.DataValidationModel),u=e.get(t.IUniverInstanceService),d=e.get(o.ISidebarService),f=(0,r.getSheetCommandTarget)(u);if(!f)return!1;let{unitId:p,subUnitId:m}=f,h=i?l.getRuleById(p,m,i):void 0;c.open(),c.setActiveRule(h&&{unitId:p,subUnitId:m,rule:h});let g=d.open({id:L,header:{title:s?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:L},width:312,onClose:()=>c.close()});return c.setCloseDisposable(g),!0}},z={id:`data-validation.operation.close-validation-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(A).close(),!0}},B={id:`data-validation.operation.toggle-validation-panel`,type:t.CommandType.OPERATION,handler(e){let n=e.get(t.ICommandService),r=e.get(A);return r.open(),r.isOpen?n.executeCommand(z.id):n.executeCommand(R.id),!0}},V={type:t.CommandType.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(I),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},H={type:t.CommandType.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(I).hideDropdown(),!0):!1}},U={type:t.CommandType.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let n=(0,r.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!n)return!1;let{workbook:a,worksheet:o}=n,s=(0,i.createDefaultNewRule)(e),c=e.get(t.ICommandService),l={rule:s,unitId:a.getUnitId(),subUnitId:o.getSheetId()};return c.syncExecuteCommand(i.AddSheetDataValidationCommand.id,l)?(c.syncExecuteCommand(R.id,{ruleId:s.uid,isAdd:!0}),!0):!1}},W=`SHEET_DATA_VALIDATION_ALERT`,G=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,s.debounceTime)(100)).subscribe(e=>{if(e){let r=this._univerInstanceService.getUnit(e.location.unitId,t.UniverInstanceType.UNIVER_SHEET),i=r.getSheetBySheetId(e.location.subUnitId);if(!i)return;let a=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!a){this._cellAlertManagerService.removeAlert(W);return}if(this._dataValidationModel.validator(a,{...e.location,workbook:r,worksheet:i})===t.DataValidationStatus.INVALID){var n;let t=this._cellAlertManagerService.currentAlert.get(W),r=t==null||(n=t.alert)==null?void 0:n.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(W);return}let i=this._dataValidationModel.getValidator(a.type);if(!i){this._cellAlertManagerService.removeAlert(W);return}this._cellAlertManagerService.showAlert({type:l.CellAlertType.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:i==null?void 0:i.getRuleFinalError(a,e.location),location:e.location,width:200,height:74,key:W});return}}this._cellAlertManagerService.removeAlert(W)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(W)}))}};G=k([O(0,(0,t.Inject)(l.HoverManagerService)),O(1,(0,t.Inject)(l.CellAlertManagerService)),O(2,t.IUniverInstanceService),O(3,(0,t.Inject)(t.LocaleService)),O(4,o.IZenZoneService),O(5,(0,t.Inject)(i.SheetDataValidationModel))],G);let K=class extends t.Disposable{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),n=(e,n)=>{let{source:a,target:o,unitId:s,subUnitId:c}=e,u=this._sheetDataValidationModel.getRuleObjectMatrix(s,c).clone(),d=(0,l.virtualizeDiscreteRanges)([a,o]),[f,p]=d.ranges,{mapFunc:m}=d,h={row:f.startRow,col:f.startColumn},g=r.AutoFillTools.getAutoFillRepeatRange(f,p),_=new t.ObjectMatrix,v=new Set;g.forEach(e=>{let n=e.repeatStartCell,r=e.relativeRange,i={startRow:h.row,startColumn:h.col,endColumn:h.col,endRow:h.row},a={startRow:n.row,startColumn:n.col,endColumn:n.col,endRow:n.row};t.Range.foreach(r,(e,n)=>{let r=t.Rectangle.getPositionRange({startRow:e,startColumn:n,endColumn:n,endRow:e},i),{row:o,col:l}=m(r.startRow,r.startColumn),u=this._sheetDataValidationModel.getRuleIdByLocation(s,c,o,l)||``,d=t.Rectangle.getPositionRange({startRow:e,startColumn:n,endColumn:n,endRow:e},a),{row:f,col:p}=m(d.startRow,d.startColumn);_.setValue(f,p,u),v.add(u)})});let y=Array.from(v).map(e=>({id:e,ranges:(0,t.queryObjectMatrix)(_,t=>t===e)}));u.addRangeRules(y);let{redoMutations:b,undoMutations:x}=(0,i.getDataValidationDiffMutations)(s,c,u.diff(this._sheetDataValidationModel.getRules(s,c)),this._injector,`patched`,n===r.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);return{undos:x,redos:b}},a={id:i.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:e=>{let{source:n,unitId:i,subUnitId:a}=e;for(let e of n.rows)for(let o of n.cols){let n=this._sheetDataValidationModel.getRuleByLocation(i,a,e,o);if(n&&n.type===t.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(r.AUTO_FILL_APPLY_TYPE.SERIES,!0);return}}},onFillData:(t,i,a)=>a===r.AUTO_FILL_APPLY_TYPE.COPY||a===r.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT||a===r.AUTO_FILL_APPLY_TYPE.SERIES?n(t,a):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(a))}};K=k([O(0,r.IAutoFillService),O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(t.Injector))],K);let ee=[l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],q=class extends t.Disposable{constructor(e,t,n,r){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,this._univerInstanceService=r,D(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:i.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>!e||!this._copyInfo||ee.includes(r.pasteType)?{redos:[],undos:[]}:this._generateMutations(e,t,r)})}_collect(e,n,i){let a=new t.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:n,matrix:a};let o=this._injector.invoke(t=>(0,r.rangeToDiscreteRange)(i,t,e,n));if(!o)return;let{rows:s,cols:c}=o;s.forEach((t,r)=>{c.forEach((i,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,n,t,i);a.setValue(r,o,s==null?``:s)})})}_generateMutations(e,n,a){let{unitId:o,subUnitId:s,range:c}=e,{unitId:u,subUnitId:d,range:f}=n,{copyType:p=l.COPY_TYPE.COPY}=a;if(!(0,r.getSheetCommandTarget)(this._univerInstanceService,{unitId:u,subUnitId:d}))return{redos:[],undos:[]};if(p===l.COPY_TYPE.CUT&&u===o&&d===s)return this._copyInfo=null,{redos:[],undos:[]};if(u!==o||d!==s){let e=this._sheetDataValidationModel.getRuleObjectMatrix(u,d).clone(),n=new t.ObjectMatrix,r=new Set,{ranges:[a,m],mapFunc:h}=(0,l.virtualizeDiscreteRanges)([c,f]),g=(0,l.getRepeatRange)(a,m,!0),_=new Map;g.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,a,c)=>{let l=t.Rectangle.getPositionRange({startRow:i,endRow:i,startColumn:a,endColumn:a},e),f=`${s}-${c}`,p=this._sheetDataValidationModel.getRuleById(o,s,c);!this._sheetDataValidationModel.getRuleById(u,d,f)&&p&&_.set(f,{...p,uid:f});let{row:m,col:g}=h(l.startRow,l.startColumn);r.add(f),n.setValue(m,g,f)})});let v=Array.from(r).map(e=>({id:e,ranges:(0,t.queryObjectMatrix)(n,t=>t===e)}));e.addRangeRules(v);let{redoMutations:y,undoMutations:b}=(0,i.getDataValidationDiffMutations)(u,d,e.diffWithAddition(this._sheetDataValidationModel.getRules(u,d),_.values()),this._injector,`patched`,!1);if(p===l.COPY_TYPE.CUT){let e=this._sheetDataValidationModel.getRuleObjectMatrix(o,s).clone(),t=h(a.startRow,a.startColumn),n=h(a.endRow,a.endColumn);e.addRangeRules([{id:``,ranges:[{startRow:t.row,endRow:n.row,startColumn:t.col,endColumn:n.col}]}]);let{redoMutations:r,undoMutations:c}=(0,i.getDataValidationDiffMutations)(o,s,e.diff(this._sheetDataValidationModel.getRules(o,s)),this._injector,`patched`,!1);y.push(...r),b.push(...c)}return{redos:y,undos:b}}else{let e=this._sheetDataValidationModel.getRuleObjectMatrix(o,s).clone(),n=new t.ObjectMatrix,r=new Set,{ranges:[a,p],mapFunc:m}=(0,l.virtualizeDiscreteRanges)([c,f]);(0,l.getRepeatRange)(a,p,!0).forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,a,o)=>{let s=t.Rectangle.getPositionRange({startRow:i,endRow:i,startColumn:a,endColumn:a},e),{row:c,col:l}=m(s.startRow,s.startColumn);n.setValue(c,l,o),r.add(o)})});let h=Array.from(r).map(e=>({id:e,ranges:(0,t.queryObjectMatrix)(n,t=>t===e)}));e.addRangeRules(h);let{redoMutations:g,undoMutations:_}=(0,i.getDataValidationDiffMutations)(u,d,e.diff(this._sheetDataValidationModel.getRules(o,s)),this._injector,`patched`,!1);return{redos:g,undos:_}}}};q=k([O(0,l.ISheetClipboardService),O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(t.Injector)),O(3,(0,t.Inject)(t.IUniverInstanceService))],q);let J=class extends t.Disposable{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===i.AddSheetDataValidationCommand.id){let{unitId:t,subUnitId:n,rule:{ranges:i}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[r.WorkbookEditablePermission],rangeTypes:[r.RangeProtectionPermissionEditPoint],worksheetTypes:[r.WorksheetEditPermission,r.WorksheetSetCellStylePermission]},i,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===i.UpdateSheetDataValidationRangeCommand.id){let{unitId:t,subUnitId:n,ranges:i}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[r.WorkbookEditablePermission],rangeTypes:[r.RangeProtectionPermissionEditPoint],worksheetTypes:[r.WorksheetEditPermission,r.WorksheetSetCellStylePermission]},i,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};J=k([O(0,(0,t.Inject)(t.LocaleService)),O(1,t.ICommandService),O(2,(0,t.Inject)(r.SheetPermissionCheckController))],J);let Y=`sheet.menu.data-validation`;function te(e){return{id:Y,type:o.MenuItemType.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,l.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetSetCellStylePermission,r.WorksheetEditPermission],rangeTypes:[r.RangeProtectionPermissionEditPoint]})}}function ne(e){return{id:R.id,title:`dataValidation.panel.title`,type:o.MenuItemType.BUTTON}}function re(e){return{id:U.id,title:`dataValidation.panel.add`,type:o.MenuItemType.BUTTON}}let ie={[o.RibbonDataGroup.RULES]:{[Y]:{order:0,menuItemFactory:te,[R.id]:{order:0,menuItemFactory:ne},[U.id]:{order:1,menuItemFactory:re}}}},ae={tr:{size:6,color:`#fe4b4b`}},X=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(ie)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:r.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,n,r)=>{var a,o,s,c,u;let{row:d,col:f,unitId:p,subUnitId:m,workbook:h,worksheet:g}=n,_=this._sheetDataValidationModel.getRuleIdByLocation(p,m,d,f);if(!_)return r(e);let v=this._sheetDataValidationModel.getRuleById(p,m,_);if(!v)return r(e);let y=(a=this._dataValidationCacheService.getValue(p,m,d,f))==null?t.DataValidationStatus.VALID:a,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=n.rawData,S,C={get value(){var e;return S===void 0&&(S=(e=(0,i.getCellValueOrigin)(x))==null?null:e),S}},w={get value(){var e;return`${(e=C.value)==null?``:e}`}};return(!e||e===n.rawData)&&(e={...n.rawData}),e.markers={...e==null?void 0:e.markers,...y===t.DataValidationStatus.INVALID?ae:null},e.customRender=[...(o=e==null?void 0:e.customRender)==null?[]:o,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(s=e.fontRenderExtension)==null?void 0:s.isSkip)||(b==null||(c=b.skipDefaultFontRender)==null?void 0:c.call(b,v,C.value,n))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,w.value,{get style(){let t=h.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},d,f)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((u=e==null?void 0:e.coverable)==null?!0:u)&&!(v.type===t.DataValidationType.LIST||v.type===t.DataValidationType.LIST_MULTIPLE),r(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,s.filter)(e=>e.source===`command`),(0,s.bufferTime)(100)).subscribe(e=>{if(e.length===0)return;let n=[];e.forEach(e=>{if(e.rule.type===t.DataValidationType.LIST_MULTIPLE||e.rule.type===t.DataValidationType.LIST){var r;(r=e.rule)!=null&&r.ranges&&n.push(...e.rule.ranges)}}),n.length&&(0,t.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(n).redos,this._commandService)})}};X=k([O(0,t.ICommandService),O(1,o.IMenuManagerService),O(2,n.IRenderManagerService),O(3,t.IUniverInstanceService),O(4,(0,t.Inject)(l.AutoHeightController)),O(5,(0,t.Inject)(I)),O(6,(0,t.Inject)(i.SheetDataValidationModel)),O(7,(0,t.Inject)(a.DataValidatorRegistryService)),O(8,(0,t.Inject)(r.SheetInterceptorService)),O(9,(0,t.Inject)(i.DataValidationCacheService)),O(10,(0,t.Optional)(l.IEditorBridgeService))],X);let oe=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:r.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,n,r)=>{var a,o,s,c,u;let{row:d,col:f,unitId:p,subUnitId:m,workbook:h,worksheet:g}=n,_=this._sheetDataValidationModel.getRuleIdByLocation(p,m,d,f);if(!_)return r(e);let v=this._sheetDataValidationModel.getRuleById(p,m,_);if(!v)return r(e);let y=(a=this._dataValidationCacheService.getValue(p,m,d,f))==null?t.DataValidationStatus.VALID:a,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=(0,i.getCellValueOrigin)(g.getCellRaw(d,f)),S=`${x==null?``:x}`;return(!e||e===n.rawData)&&(e={...n.rawData}),e.markers={...e==null?void 0:e.markers,...y===t.DataValidationStatus.INVALID?ae:null},e.customRender=[...(o=e==null?void 0:e.customRender)==null?[]:o,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(s=e.fontRenderExtension)==null?void 0:s.isSkip)||(b==null||(c=b.skipDefaultFontRender)==null?void 0:c.call(b,v,x,n))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,S,{get style(){let t=h.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},d,f)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((u=e==null?void 0:e.coverable)==null?!0:u)&&!(v.type===t.DataValidationType.LIST||v.type===t.DataValidationType.LIST_MULTIPLE),r(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,s.filter)(e=>e.source===`command`),(0,s.bufferTime)(16)).subscribe(e=>{let n=[];e.forEach(e=>{if(e.rule.type===t.DataValidationType.LIST_MULTIPLE||e.rule.type===t.DataValidationType.LIST){var r;(r=e.rule)!=null&&r.ranges&&n.push(...e.rule.ranges)}}),n.length&&(0,t.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(n).redos,this._commandService)})}};oe=k([O(0,t.ICommandService),O(1,n.IRenderManagerService),O(2,(0,t.Inject)(l.AutoHeightController)),O(3,(0,t.Inject)(a.DataValidatorRegistryService)),O(4,(0,t.Inject)(r.SheetInterceptorService)),O(5,(0,t.Inject)(i.SheetDataValidationModel)),O(6,(0,t.Inject)(i.DataValidationCacheService))],oe);let se=class extends t.Disposable{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0,t.bufferDebounceTime)(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};se=k([O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(l.SheetSkeletonManagerService))],se);function Z({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,d.useRef)(`_${de()}`);return ce(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function ce(e,t,n,r,i){return(0,d.createElement)(e.tag,{key:t,...le(e,n,i),...r},(ue(e,n).children||[]).map((r,a)=>ce(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function le(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function ue(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function de(){return Math.random().toString(36).substring(2,8)}Z.displayName=`UniverIcon`;let fe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.4917 3.07803C1.4917 2.19437 2.20804 1.47803 3.0917 1.47803H5.6917C6.57536 1.47803 7.2917 2.19437 7.2917 3.07803V5.67803C7.2917 6.56168 6.57535 7.27803 5.6917 7.27803H3.0917C2.20804 7.27803 1.4917 6.56168 1.4917 5.67803V3.07803ZM3.0917 2.67803C2.87078 2.67803 2.6917 2.85711 2.6917 3.07803V5.67803C2.6917 5.89894 2.87079 6.07803 3.0917 6.07803H5.6917C5.91261 6.07803 6.0917 5.89894 6.0917 5.67803V3.07803C6.0917 2.85711 5.91261 2.67803 5.6917 2.67803H3.0917Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M14.6175 2.45279C14.8518 2.68711 14.8518 3.06701 14.6175 3.30132L11.6151 6.30365C11.3957 6.52307 11.0451 6.53897 10.8067 6.34031L8.80915 4.67566C8.55458 4.46352 8.52019 4.08518 8.73233 3.83062C8.94447 3.57605 9.32281 3.54166 9.57737 3.7538L11.154 5.06767L13.769 2.45278C14.0033 2.21847 14.3832 2.21848 14.6175 2.45279Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M14.1175 9.19746C14.3518 9.43178 14.3518 9.81168 14.1175 10.046L12.5418 11.6217L14.1175 13.1975C14.3518 13.4318 14.3518 13.8117 14.1175 14.046C13.8832 14.2803 13.5033 14.2803 13.269 14.046L11.6933 12.4703L10.1175 14.046C9.88321 14.2803 9.50331 14.2803 9.269 14.046C9.03468 13.8117 9.03468 13.4318 9.269 13.1975L10.8447 11.6217L9.269 10.046C9.03468 9.81168 9.03468 9.43178 9.269 9.19746C9.50331 8.96315 9.88321 8.96315 10.1175 9.19746L11.6933 10.7732L13.269 9.19746C13.5033 8.96315 13.8832 8.96315 14.1175 9.19746Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.0917 8.72168C2.20804 8.72168 1.4917 9.43802 1.4917 10.3217V12.9217C1.4917 13.8053 2.20804 14.5217 3.0917 14.5217H5.6917C6.57535 14.5217 7.2917 13.8053 7.2917 12.9217V10.3217C7.2917 9.43802 6.57536 8.72168 5.6917 8.72168H3.0917ZM2.6917 10.3217C2.6917 10.1008 2.87078 9.92168 3.0917 9.92168H5.6917C5.91261 9.92168 6.0917 10.1008 6.0917 10.3217V12.9217C6.0917 13.1426 5.91261 13.3217 5.6917 13.3217H3.0917C2.87079 13.3217 2.6917 13.1426 2.6917 12.9217V10.3217Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},pe=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(Z,Object.assign({},e,{id:`data-validation-icon`,ref:t,icon:fe}))});pe.displayName=`DataValidationIcon`;let me={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},he=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(Z,Object.assign({},e,{id:`delete-icon`,ref:t,icon:me}))});he.displayName=`DeleteIcon`;let ge={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z`}}]},_e=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(Z,Object.assign({},e,{id:`increase-icon`,ref:t,icon:ge}))});_e.displayName=`IncreaseIcon`;let ve={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},ye=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(Z,Object.assign({},e,{id:`more-down-icon`,ref:t,icon:ve}))});ye.displayName=`MoreDownIcon`;let be={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M4.64645 9.85355C4.45118 9.65829 4.45118 9.34171 4.64645 9.14645L7.64645 6.14645C7.84171 5.95118 8.15829 5.95118 8.35355 6.14645L11.3536 9.14645C11.5488 9.34171 11.5488 9.65829 11.3536 9.85355C11.1583 10.0488 10.8417 10.0488 10.6464 9.85355L8 7.20711L5.35355 9.85355C5.15829 10.0488 4.84171 10.0488 4.64645 9.85355Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},xe=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(Z,Object.assign({},e,{id:`more-up-icon`,ref:t,icon:be}))});xe.displayName=`MoreUpIcon`;let Se={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M6 5C6.55228 5 7 4.55228 7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4C5 4.55228 5.44772 5 6 5Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6 9C6.55228 9 7 8.55229 7 8C7 7.44772 6.55228 7 6 7C5.44772 7 5 7.44772 5 8C5 8.55229 5.44772 9 6 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M7 12C7 12.5523 6.55228 13 6 13C5.44772 13 5 12.5523 5 12C5 11.4477 5.44772 11 6 11C6.55228 11 7 11.4477 7 12Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10 5C10.5523 5 11 4.55228 11 4C11 3.44772 10.5523 3 10 3C9.44771 3 9 3.44772 9 4C9 4.55228 9.44771 5 10 5Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M11 8C11 8.55229 10.5523 9 10 9C9.44771 9 9 8.55229 9 8C9 7.44772 9.44771 7 10 7C10.5523 7 11 7.44772 11 8Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10 13C10.5523 13 11 12.5523 11 12C11 11.4477 10.5523 11 10 11C9.44771 11 9 11.4477 9 12C9 12.5523 9.44771 13 10 13Z`}}]},Ce=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(Z,Object.assign({},e,{id:`sequence-icon`,ref:t,icon:Se}))});Ce.displayName=`SequenceIcon`;function we(e){var n;let r=(0,o.useDependency)(t.LocaleService),i=(0,o.useDependency)(o.ComponentManager),{value:a,onChange:s,extraComponent:c}=e,[l,f]=(0,d.useState)(!1),p=c?i.get(c):null;return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`div`,{className:`univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white`,onClick:()=>f(!l),children:[r.t(`dataValidation.panel.options`),l?(0,m.jsx)(xe,{className:`univer-ml-1`}):(0,m.jsx)(ye,{className:`univer-ml-1`})]}),l&&(0,m.jsxs)(m.Fragment,{children:[p?(0,m.jsx)(p,{value:a,onChange:s}):null,(0,m.jsx)(u.FormLayout,{label:r.t(`dataValidation.panel.invalid`),children:(0,m.jsxs)(u.RadioGroup,{value:`${(n=a.errorStyle)==null?t.DataValidationErrorStyle.WARNING:n}`,onChange:e=>s({...a,errorStyle:+e}),children:[(0,m.jsx)(u.Radio,{value:`${t.DataValidationErrorStyle.WARNING}`,children:r.t(`dataValidation.panel.showWarning`)}),(0,m.jsx)(u.Radio,{value:`${t.DataValidationErrorStyle.STOP}`,children:r.t(`dataValidation.panel.rejectInput`)})]})}),(0,m.jsx)(u.FormLayout,{label:r.t(`dataValidation.panel.messageInfo`),children:(0,m.jsx)(u.Checkbox,{checked:a.showErrorMessage,onChange:()=>s({...a,showErrorMessage:!a.showErrorMessage}),children:r.t(`dataValidation.panel.showInfo`)})}),a.showErrorMessage?(0,m.jsx)(u.FormLayout,{children:(0,m.jsx)(u.Input,{value:a.error,onChange:e=>s({...a,error:e})})}):null]})]})}let Te=e=>(0,t.debounce)(async(t,n,r,i)=>{let a=await e.executeCommand(t,n,r);i==null||i(a)},1e3);function Ee(e,n,r){var i;if(n){var a;return((a=e.getUnit(n))==null||(a=a.getSheetBySheetName(r))==null?void 0:a.getSheetId())||``}return((i=e.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET))==null||(i=i.getSheetBySheetName(r))==null?void 0:i.getSheetId())||``}function De(){var e,n;let[c,l]=(0,d.useState)(0),h=(0,o.useDependency)(A),{unitId:g,subUnitId:_,rule:v}=(0,o.useObservable)(h.activeRule$,h.activeRule)||{},y=v.uid,b=(0,o.useDependency)(a.DataValidatorRegistryService),x=(0,o.useDependency)(t.IUniverInstanceService),S=(0,o.useDependency)(o.ComponentManager),C=(0,o.useDependency)(t.ICommandService),w=(0,o.useDependency)(a.DataValidationModel),T=(0,o.useDependency)(t.LocaleService),E=(0,o.useObservable)(()=>x.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),D=(0,o.useObservable)(()=>{var e;return(e=E==null?void 0:E.activeSheet$)==null?(0,s.of)(null):e},void 0,void 0,[]),[O,k]=(0,d.useState)(v),j=b.getValidatorItem(O.type),[M,N]=(0,d.useState)(!1),P=b.getValidatorsByScope(a.DataValidatorRegistryScope.SHEET),[F,I]=(0,d.useState)(()=>O.ranges.map(e=>({unitId:``,sheetId:``,range:e}))),L=(0,d.useMemo)(()=>Te(C),[C]),[R,z]=(0,d.useState)(!1),[B,V]=(0,d.useState)(!1),H=(0,d.useRef)(null),U=(0,o.useDependency)(r.SheetsSelectionsService);if((0,d.useEffect)(()=>()=>{let e=U.getCurrentLastSelection();e&&U.setSelections([e])},[U]),(0,d.useEffect)(()=>{C.onCommandExecuted(e=>{(e.id===t.UndoCommand.id||e.id===t.RedoCommand.id)&&setTimeout(()=>{let e=w.getRuleById(g,_,y);l(e=>e+1),e&&(k(e),I(e.ranges.map(e=>({unitId:``,sheetId:``,range:e}))))},20)})},[C,w,y,_,g]),!j)return null;let W=j.operators,G=j.operatorNames,K=O.operator?a.TWO_FORMULA_OPERATOR_COUNT.includes(O.operator):!1,ee=()=>{(D==null?void 0:D.getSheetId())!==_&&C.syncExecuteCommand(r.SetWorksheetActiveOperation.id,{unitId:g,subUnitId:_})},q=()=>{var e;if(!((e=H.current)==null||(e=e.editor)==null)&&e.isFocus()){var t;J((t=H.current)==null?void 0:t.getValue())}!O.ranges.length||R||(j.validatorFormula(O,g,_).success?h.setActiveRule(null):N(!0),ee())},J=(0,o.useEvent)(e=>{let n=e.split(`,`).filter(Boolean).map(f.deserializeRangeWithSheet).map(e=>{let t=e.sheetName;if(t){let n=Ee(x,e.unitId,t);return{...e,sheetId:n}}return{...e,sheetId:``}});if((0,t.isUnitRangesEqual)(n,F))return;I(n);let r=n.filter(e=>(!e.unitId||e.unitId===g)&&(!e.sheetId||e.sheetId===_)).map(e=>e.range);if(k({...O,ranges:r}),r.length===0)return;let a={unitId:g,subUnitId:_,ruleId:y,ranges:r};L(i.UpdateSheetDataValidationRangeCommand.id,a)}),Y=e=>{if((0,t.shallowEqual)(e,(0,a.getRuleSetting)(O)))return;k({...O,...e});let n={unitId:g,subUnitId:_,ruleId:y,setting:e};L(i.UpdateSheetDataValidationSettingCommand.id,n,void 0)},te=async()=>{await C.executeCommand(i.RemoveSheetDataValidationCommand.id,{ruleId:y,unitId:g,subUnitId:_}),h.setActiveRule(null),ee()},ne={type:O.type,operator:O.operator,formula1:O.formula1,formula2:O.formula2,allowBlank:O.allowBlank},re=e=>{let t=b.getValidatorItem(e);if(!t)return;let n=t.operators,r=w.getRuleById(g,_,y),o=e===(r==null?void 0:r.type)||e.includes(`list`)&&r!=null&&r.type.includes(`list`)?{...r,type:e}:{...O,type:e,operator:n[0],formula1:void 0,formula2:void 0};k(o),C.executeCommand(i.UpdateSheetDataValidationSettingCommand.id,{unitId:g,subUnitId:_,ruleId:O.uid,setting:(0,a.getRuleSetting)(o)})},ie=S.get(j.formulaInput),ae=(0,d.useMemo)(()=>F.map(e=>(0,f.serializeRange)(e.range)).join(`,`),[]),X=(0,a.getRuleOptions)(O),oe=e=>{(0,t.shallowEqual)(e,(0,a.getRuleOptions)(O))||(k({...O,...e}),L(i.UpdateSheetDataValidationOptionsCommand.id,{unitId:g,subUnitId:_,ruleId:y,options:e}))},se=W.length&&!O.operator;return(0,m.jsxs)(`div`,{"data-u-comp":`data-validation-detail`,className:`univer-py-2`,children:[(0,m.jsx)(u.FormLayout,{label:T.t(`dataValidation.panel.range`),error:!O.ranges.length||R?T.t(`dataValidation.panel.rangeError`):``,children:(0,m.jsx)(p.RangeSelector,{selectorRef:H,unitId:g,subUnitId:_,initialValue:ae,onChange:(e,t)=>{var n;!B&&(n=H.current)!=null&&n.verify()&&J(t)},onFocusChange:(e,t)=>{var n;V(e),!e&&t&&(n=H.current)!=null&&n.verify()&&J(t)},onVerify:e=>z(!e)})}),(0,m.jsx)(u.FormLayout,{label:T.t(`dataValidation.panel.type`),children:(0,m.jsx)(u.Select,{className:`univer-w-full`,value:O.type,options:P==null||(e=P.sort((e,t)=>e.order-t.order))==null?void 0:e.map(e=>({label:T.t(e.title),value:e.id})),onChange:re})}),W!=null&&W.length?(0,m.jsx)(u.FormLayout,{label:T.t(`dataValidation.panel.operator`),children:(0,m.jsx)(u.Select,{className:`univer-w-full`,value:`${O.operator}`,options:[{value:``,label:T.t(`dataValidation.operators.legal`)},...W.map((e,t)=>({value:`${e}`,label:G[t]}))],onChange:e=>{Y({...ne,operator:e})}})}):null,ie&&!se?(0,m.jsx)(ie,{isTwoFormula:K,value:{formula1:O.formula1,formula2:O.formula2},onChange:e=>{Y({...ne,...e})},showError:M,validResult:j.validatorFormula(O,g,_),unitId:g,subUnitId:_,ruleId:y},c+O.type):null,(0,m.jsx)(u.FormLayout,{children:(0,m.jsx)(u.Checkbox,{checked:(n=O.allowBlank)==null?!0:n,onChange:()=>{var e;return Y({...ne,allowBlank:!((e=O.allowBlank)==null||e)})},children:T.t(`dataValidation.panel.allowBlank`)})}),(0,m.jsx)(we,{value:X,onChange:oe,extraComponent:j.optionsInput}),(0,m.jsxs)(`div`,{className:`univer-mt-5 univer-flex univer-flex-row univer-justify-end`,children:[(0,m.jsx)(u.Button,{className:`univer-ml-3`,onClick:te,children:T.t(`dataValidation.panel.removeRule`)}),(0,m.jsx)(u.Button,{className:`univer-ml-3`,variant:`primary`,onClick:q,children:T.t(`dataValidation.panel.done`)})]})]})}let Oe=e=>{let{rule:n,onClick:r,unitId:s,subUnitId:c,disable:p}=e,h=(0,o.useDependency)(a.DataValidatorRegistryService),g=(0,o.useDependency)(t.ICommandService),_=(0,o.useDependency)(l.IMarkSelectionService),v=h.getValidatorItem(n.type),y=(0,d.useRef)(void 0),[b,x]=(0,d.useState)(!1),S=(0,o.useDependency)(t.ThemeService),C=(0,d.useMemo)(()=>{var e;let n=S.getColorFromTheme(`primary.600`),r=S.getColorFromTheme(`loop-color.2`),i=(e=S.getColorFromTheme(r))==null?n:e,a=new t.ColorKit(i).toRgb();return{fill:`rgba(${a.r}, ${a.g}, ${a.b}, 0.1)`,stroke:i}},[(0,o.useObservable)(S.currentTheme$)]),w=e=>{g.executeCommand(i.RemoveSheetDataValidationCommand.id,{ruleId:n.uid,unitId:s,subUnitId:c}),e.stopPropagation()};return(0,d.useEffect)(()=>()=>{if(y.current){var e;(e=y.current)==null||e.forEach(e=>{e&&_.removeShape(e)})}},[_]),(0,m.jsxs)(`div`,{className:(0,u.clsx)(`univer-bg-secondary univer-relative univer--mx-2 univer-box-border univer-flex univer-w-[287px] univer-cursor-pointer univer-flex-col univer-justify-between univer-overflow-hidden univer-rounded-md univer-p-2 univer-pr-9`,{"hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700":!p,"univer-opacity-50":p}),onClick:r,onMouseEnter:()=>{p||(x(!0),y.current=n.ranges.map(e=>_.addShape({range:e,style:C,primary:null})))},onMouseLeave:()=>{var e;x(!1),(e=y.current)==null||e.forEach(e=>{e&&_.removeShape(e)}),y.current=void 0},children:[(0,m.jsx)(`div`,{className:`univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900 dark:!univer-text-white`,children:v==null?void 0:v.generateRuleName(n)}),(0,m.jsx)(`div`,{className:`univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px] dark:!univer-text-gray-300`,children:n.ranges.map(e=>(0,f.serializeRange)(e)).join(`,`)}),b?(0,m.jsx)(`div`,{className:`univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-size-5 univer-items-center univer-justify-center univer-rounded hover:univer-bg-gray-200 dark:!univer-text-gray-300 dark:hover:!univer-bg-gray-700`,onClick:w,children:(0,m.jsx)(he,{})}):null]})};function ke(e){let n=(0,o.useDependency)(i.SheetDataValidationModel),a=(0,o.useDependency)(t.IUniverInstanceService),s=(0,o.useDependency)(t.ICommandService),c=(0,o.useDependency)(t.Injector),l=(0,o.useDependency)(A),f=(0,o.useDependency)(t.LocaleService),[p,h]=(0,d.useState)([]),{workbook:g}=e,_=(0,o.useObservable)(g.activeSheet$,void 0,!0),v=g.getUnitId(),y=_==null?void 0:_.getSheetId();(0,d.useEffect)(()=>{h(n.getRules(v,y));let e=n.ruleChange$.subscribe(e=>{e.unitId===v&&e.subUnitId===y&&h(n.getRules(v,y))});return()=>{e.unsubscribe()}},[v,y,n]);let b=async()=>{let e=(0,i.createDefaultNewRule)(c),t={unitId:v,subUnitId:y,rule:e};await s.executeCommand(i.AddSheetDataValidationCommand.id,t),l.setActiveRule({unitId:v,subUnitId:y,rule:e})},x=()=>{s.executeCommand(i.RemoveSheetAllDataValidationCommand.id,{unitId:v,subUnitId:y})},S=(e=>{let n=a.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),i=n.getActiveSheet(),o=n.getUnitId(),s=i.getSheetId();return e.map(e=>(0,r.checkRangesEditablePermission)(c,o,s,e.ranges)?{...e}:{...e,disable:!0})})(p),C=S==null?void 0:S.some(e=>e.disable);return(0,m.jsxs)(`div`,{className:`univer-pb-4`,children:[S==null?void 0:S.map(e=>{var t;return(0,m.jsx)(Oe,{unitId:v,subUnitId:y,onClick:()=>{e.disable||l.setActiveRule({unitId:v,subUnitId:y,rule:e})},rule:e,disable:(t=e.disable)==null?!1:t},e.uid)}),(0,m.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2`,children:[p.length&&!C?(0,m.jsx)(u.Button,{onClick:x,children:f.t(`dataValidation.panel.removeAll`)}):null,(0,m.jsx)(u.Button,{variant:`primary`,onClick:b,children:f.t(`dataValidation.panel.add`)})]})]})}let Ae=()=>{let e=(0,o.useDependency)(A),n=(0,o.useObservable)(e.activeRule$,e.activeRule),r=(0,o.useDependency)(t.IUniverInstanceService),i=(0,o.useObservable)(()=>r.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),a=(0,o.useObservable)(()=>{var e;return(e=i==null?void 0:i.activeSheet$)==null?(0,s.of)(null):e},void 0,void 0,[]);return!i||!a?null:n&&(n.subUnitId===a.getSheetId()||n.subUnitId===e.getFocusFormulaEditorActiveRuleSubUnitId())?(0,m.jsx)(De,{},n.rule.uid):(0,m.jsx)(ke,{workbook:i})},je=e=>{let{isTwoFormula:n=!1,value:r,onChange:i,showError:a,validResult:s}=e,c=(0,o.useDependency)(t.LocaleService),l=a?s==null?void 0:s.formula1:``,d=a?s==null?void 0:s.formula2:``;return n?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(u.FormLayout,{error:l,children:(0,m.jsx)(u.Input,{className:`univer-w-full`,placeholder:c.t(`dataValidation.panel.formulaPlaceholder`),value:r==null?void 0:r.formula1,onChange:e=>{i==null||i({...r,formula1:e})}})}),(0,m.jsx)(`div`,{className:`-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400`,children:c.t(`dataValidation.panel.formulaAnd`)}),(0,m.jsx)(u.FormLayout,{error:d,children:(0,m.jsx)(u.Input,{className:`univer-w-full`,placeholder:c.t(`dataValidation.panel.formulaPlaceholder`),value:r==null?void 0:r.formula2,onChange:e=>{i==null||i({...r,formula2:e})}})})]}):(0,m.jsx)(u.FormLayout,{error:l,children:(0,m.jsx)(u.Input,{className:`univer-w-full`,placeholder:c.t(`dataValidation.panel.formulaPlaceholder`),value:r==null?void 0:r.formula1,onChange:e=>{i==null||i({formula1:e})}})})};function Me(e){let{value:n,onChange:r,showError:i,validResult:a}=e,s=(0,o.useDependency)(t.LocaleService),c=i?a==null?void 0:a.formula1:``,l=i?a==null?void 0:a.formula2:``,[f,p]=(0,d.useState)(!((n==null?void 0:n.formula1)===void 0&&(n==null?void 0:n.formula2)===void 0));return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(u.FormLayout,{children:(0,m.jsx)(u.Checkbox,{checked:f,onChange:e=>{e?p(!0):(p(!1),r==null||r({...n,formula1:void 0,formula2:void 0}))},children:s.t(`dataValidation.checkbox.tips`)})}),f?(0,m.jsx)(u.FormLayout,{label:s.t(`dataValidation.checkbox.checked`),error:c,children:(0,m.jsx)(u.Input,{className:`univer-w-full`,placeholder:s.t(`dataValidation.panel.valuePlaceholder`),value:n==null?void 0:n.formula1,onChange:e=>{r==null||r({...n,formula1:e||void 0})}})}):null,f?(0,m.jsx)(u.FormLayout,{label:s.t(`dataValidation.checkbox.unchecked`),error:l,children:(0,m.jsx)(u.Input,{className:`univer-w-full`,placeholder:s.t(`dataValidation.panel.valuePlaceholder`),value:n==null?void 0:n.formula2,onChange:e=>{r==null||r({...n,formula2:e||void 0})}})}):null]})}function Ne(e){var t;let{unitId:n,subUnitId:r,value:i,onChange:a,showError:s,validResult:c}=e,l=s?c==null?void 0:c.formula1:void 0,f=(0,d.useRef)(null),[h,g]=(0,d.useState)(!1);return(0,o.useSidebarClick)(e=>{var t;(t=f.current)!=null&&t.isClickOutSide(e)&&g(!1)}),(0,m.jsx)(u.FormLayout,{error:l,children:(0,m.jsx)(p.FormulaEditor,{ref:f,className:(0,u.clsx)(`univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent`,u.borderClassName),initValue:(t=i==null?void 0:i.formula1)==null?`=`:t,unitId:n,subUnitId:r,isFocus:h,isSupportAcrossSheet:!0,onChange:e=>{let t=(e==null?``:e).trim();t!==(i==null?void 0:i.formula1)&&(a==null||a({...i,formula1:t}))},onFocus:()=>g(!0)})})}let Pe=[`#FFFFFF`,`#FEE7E7`,`#FEF0E6`,`#EFFBD0`,`#E4F4FE`,`#E8ECFD`,`#F1EAFA`,`#FDE8F3`,`#E5E5E5`,`#FDCECE`,`#FDC49B`,`#DEF6A2`,`#9FDAFF`,`#D0D9FB`,`#E3D5F6`,`#FBD0E8`,`#656565`,`#FE4B4B`,`#FF8C51`,`#8BBB11`,`#0B9EFB`,`#3A60F7`,`#9E6DE3`,`#F248A6`],Fe=e=>{let{value:t,onChange:n,disabled:r}=e,[i,a]=(0,d.useState)(!1);return(0,m.jsx)(u.Dropdown,{align:`start`,disabled:r,open:i,onOpenChange:a,overlay:(0,m.jsx)(`div`,{className:`univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5`,children:Pe.map(e=>(0,m.jsx)(`div`,{className:(0,u.clsx)(`univer-box-border univer-size-4 univer-cursor-pointer univer-rounded`,u.borderClassName),style:{background:e},onClick:()=>{n(e),a(!1)}},e))}),children:(0,m.jsxs)(`div`,{className:(0,u.clsx)(`univer-box-border univer-inline-flex univer-h-8 univer-w-16 univer-cursor-pointer univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white`,u.borderClassName),children:[(0,m.jsx)(`div`,{className:`univer-box-border univer-size-4 univer-rounded univer-text-base`,style:{background:t}}),(0,m.jsx)(ye,{})]})})},Ie=e=>{let{item:t,commonProps:n,className:r}=e,{onItemChange:i,onItemDelete:a}=n;return(0,m.jsxs)(`div`,{className:(0,u.clsx)(`univer-flex univer-items-center univer-gap-2`,r),children:[!t.isRef&&(0,m.jsx)(`div`,{className:(0,u.clsx)(`univer-cursor-move`,`draggableHandle`),children:(0,m.jsx)(Ce,{})}),(0,m.jsx)(Fe,{value:t.color,onChange:e=>{i(t.id,t.label,e)}}),(0,m.jsx)(u.Input,{disabled:t.isRef,value:t.label,onChange:e=>{i(t.id,e,t.color)}}),t.isRef?null:(0,m.jsx)(`div`,{className:`univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200`,children:(0,m.jsx)(he,{onClick:()=>a(t.id)})})]})};function Le(e){let{value:n,onChange:r=()=>{},unitId:c,subUnitId:l,validResult:f,showError:h,ruleId:g}=e,{formula1:_=``,formula2:v=``}=n||{},[y,b]=(0,d.useState)(()=>(0,t.isFormulaString)(_)?`1`:`0`),[x,S]=(0,d.useState)(y===`1`?_:`=`),[C,w]=(0,d.useState)(y===`1`?_:`=`),T=(0,o.useDependency)(t.LocaleService),E=(0,o.useDependency)(a.DataValidatorRegistryService),D=(0,o.useDependency)(a.DataValidationModel),O=(0,o.useDependency)(i.DataValidationFormulaController),k=(0,o.useDependency)(A),[j,M]=(0,d.useState)(()=>v.split(`,`)),N=E.getValidatorItem(t.DataValidationType.LIST),[P,F]=(0,d.useState)([]),[I,L]=(0,d.useState)(``),R=h?f==null?void 0:f.formula1:``,z=(0,o.useObservable)((0,d.useMemo)(()=>D.ruleChange$.pipe((0,s.debounceTime)(16)),[])),B=(0,o.useEvent)(r);(0,d.useEffect)(()=>{(async()=>{await new Promise(e=>{setTimeout(()=>e(!0),100)});let e=D.getRuleById(c,l,g);(0,t.isFormulaString)(e==null?void 0:e.formula1)&&N&&e&&F(await N.getListAsync(e,c,l))})()},[D,z,N,g,l,c]),(0,d.useEffect)(()=>{(0,t.isFormulaString)(_)&&_!==C&&(S(_),w(C))},[C,_]);let[V,H]=(0,d.useState)(()=>{let e=y===`1`?[]:(0,i.deserializeListOptions)(_),n=v.split(`,`);return e.map((e,r)=>({label:e,color:n[r]||`#ECECEC`,isRef:!1,id:(0,t.generateRandomId)(4)}))}),U=(e,t,n)=>{let r=V.find(t=>t.id===e);r&&(r.label=t,r.color=n,H([...V]))},W=e=>{let t=V.findIndex(t=>t.id===e);t!==-1&&(V.splice(t,1),H([...V]))},G=v.split(`,`),K=(0,d.useMemo)(()=>P.map((e,t)=>({label:e,color:G[t]||`#ECECEC`,id:`${t}`,isRef:!0})),[G,P]),ee=(e,t,n)=>{let r=[...j];r[+e]=n,M(r),B({formula1:_,formula2:r.join(`,`)})},q=()=>{H([...V,{label:``,color:`#ECECEC`,isRef:!1,id:(0,t.generateRandomId)(4)}])};(0,d.useEffect)(()=>{if(y===`1`)return;let e=new Set,t=[];V.map(e=>({labelList:e.label.split(`,`),item:e})).forEach(({item:n,labelList:r})=>{r.forEach(r=>{e.has(r)||(e.add(r),t.push({label:r,color:n.color}))})}),B({formula1:(0,i.serializeListOptions)(t.map(e=>e.label)),formula2:t.map(e=>e.color===`#ECECEC`?``:e.color).join(`,`)})},[V,B,y,C,j]);let J=(0,o.useEvent)(async e=>{if(!(0,t.isFormulaString)(e)){B==null||B({formula1:``,formula2:v});return}O.getFormulaRefCheck(e)?(B==null||B({formula1:(0,t.isFormulaString)(e)?e:``,formula2:v}),L(``)):(B==null||B({formula1:``,formula2:v}),S(`=`),L(T.t(`dataValidation.validFail.formulaError`)))}),Y=(0,d.useRef)(null),[te,ne]=(0,d.useState)(!1);return(0,o.useSidebarClick)(e=>{var t;(t=Y.current)!=null&&t.isClickOutSide(e)&&ne(!1)}),(0,d.useEffect)(()=>{te?k.setFocusFormulaEditorActiveRuleSubUnitId(l):k.setFocusFormulaEditorActiveRuleSubUnitId(null)},[te,l,k]),(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(u.FormLayout,{label:T.t(`dataValidation.list.options`),children:(0,m.jsxs)(u.RadioGroup,{value:y,onChange:e=>{b(e),S(C),e===`1`&&B({formula1:C===`=`?``:C,formula2:j.join(`,`)})},children:[(0,m.jsx)(u.Radio,{value:`0`,children:T.t(`dataValidation.list.customOptions`)}),(0,m.jsx)(u.Radio,{value:`1`,children:T.t(`dataValidation.list.refOptions`)})]})}),y===`1`?(0,m.jsxs)(u.FormLayout,{error:R||I||void 0,children:[(0,m.jsx)(p.FormulaEditor,{ref:Y,className:(0,u.clsx)(`univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent`,u.borderClassName),initValue:x,unitId:c,subUnitId:l,isFocus:te,isSupportAcrossSheet:!0,onFocus:()=>ne(!0),onChange:(e=``)=>{let t=(e==null?``:e).trim();w(t),J(t)}}),K.length>0&&(0,m.jsx)(`div`,{className:`univer-mt-3`,children:K.map(e=>(0,m.jsx)(Ie,{className:`univer-mb-3`,item:e,commonProps:{onItemChange:ee}},e.id))})]}):(0,m.jsx)(u.FormLayout,{error:R,children:(0,m.jsxs)(`div`,{className:`-univer-mt-3`,children:[(0,m.jsx)(u.DraggableList,{list:V,onListChange:H,rowHeight:28,margin:[0,12],draggableHandle:`.draggableHandle`,itemRender:e=>(0,m.jsx)(Ie,{item:e,commonProps:{onItemChange:U,onItemDelete:W}},e.id),idKey:`id`}),(0,m.jsxs)(`a`,{className:`univer-text-primary univer-flex univer-w-fit univer-cursor-pointer univer-flex-row univer-items-center univer-rounded univer-p-1 univer-px-2 univer-text-sm hover:univer-bg-primary-50 dark:hover:!univer-bg-gray-800`,onClick:q,children:[(0,m.jsx)(_e,{className:`univer-mr-1`}),T.t(`dataValidation.list.add`)]})]})})]})}let Re=[[i.CUSTOM_FORMULA_INPUT_NAME,Ne],[i.BASE_FORMULA_INPUT_NAME,je],[i.LIST_FORMULA_INPUT_NAME,Le],[i.CHECKBOX_FORMULA_INPUT_NAME,Me]];function ze(e){var n;let{value:r,onChange:i}=e,a=(0,o.useDependency)(t.LocaleService);return(0,m.jsx)(u.FormLayout,{label:a.t(`dataValidation.renderMode.label`),children:(0,m.jsxs)(u.RadioGroup,{value:`${(n=r.renderMode)==null?t.DataValidationRenderMode.CUSTOM:n}`,onChange:e=>i({...r,renderMode:+e}),children:[(0,m.jsx)(u.Radio,{value:`${t.DataValidationRenderMode.CUSTOM}`,children:a.t(`dataValidation.renderMode.chip`)}),(0,m.jsx)(u.Radio,{value:`${t.DataValidationRenderMode.ARROW}`,children:a.t(`dataValidation.renderMode.arrow`)}),(0,m.jsx)(u.Radio,{value:`${t.DataValidationRenderMode.TEXT}`,children:a.t(`dataValidation.renderMode.text`)})]})})}ze.componentKey=`LIST_RENDER_MODE_OPTION_INPUT`;function Be(e){var n;let{value:r,onChange:i}=e,a=(0,o.useDependency)(t.LocaleService);return(0,m.jsx)(u.FormLayout,{children:(0,m.jsx)(u.Checkbox,{checked:(n=r.bizInfo)==null?void 0:n.showTime,onChange:e=>{i({...r,bizInfo:{...r.bizInfo,showTime:e}})},children:a.t(`dataValidation.showTime.label`)})})}Be.componentKey=`DATE_SHOW_TIME_OPTION`;let Ve=class{_calc(e,n){var r,i,a;let{vt:o,ht:s}=n||{},c=e.endX-e.startX-12,l=e.endY-e.startY,u=((r=n==null?void 0:n.fs)==null?10:r)*1.6,d=0,f=0;switch(o){case t.VerticalAlign.TOP:f=0;break;case t.VerticalAlign.BOTTOM:f=0+(l-u);break;default:f=0+(l-u)/2;break}switch(s){case t.HorizontalAlign.LEFT:d=6;break;case t.HorizontalAlign.RIGHT:d=6+(c-u);break;default:d=6+(c-u)/2;break}return{left:e.startX+d,top:e.startY+f,width:((i=n==null?void 0:n.fs)==null?10:i)*1.6,height:((a=n==null?void 0:n.fs)==null?10:a)*1.6}}constructor(e,t,n,r,i,a){this._commandService=e,this._univerInstanceService=t,this._formulaService=n,this._themeService=r,this._renderManagerService=i,this._dataValidationModel=a}calcCellAutoHeight(e){var t;let{style:n}=e;return((t=n==null?void 0:n.fs)==null?10:t)*1.6}calcCellAutoWidth(e){var t;let{style:n}=e;return((t=n==null?void 0:n.fs)==null?10:t)*1.6}async _parseFormula(e,n,r){var a,o,s;let{formula1:c=i.CHECKBOX_FORMULA_1,formula2:l=i.CHECKBOX_FORMULA_2}=e,u=await this._formulaService.getRuleFormulaResult(n,r,e.uid),d=(0,i.getFormulaResult)(u==null||(a=u[0])==null||(a=a.result)==null||(a=a[0])==null?void 0:a[0]),f=(0,i.getFormulaResult)(u==null||(o=u[1])==null||(o=o.result)==null||(o=o[0])==null?void 0:o[0]),p=(0,i.isLegalFormulaResult)(String(d))&&(0,i.isLegalFormulaResult)(String(f));return{formula1:(0,t.isFormulaString)(c)?(0,i.getFormulaResult)(u==null||(s=u[0])==null||(s=s.result)==null||(s=s[0])==null?void 0:s[0]):c,formula2:(0,t.isFormulaString)(l)?f:l,isFormulaValid:p}}drawWith(e,t){var r,a,o,s;let{style:c,primaryWithCoord:l,unitId:u,subUnitId:d,worksheet:f,row:p,col:m}=t,h=l.isMergedMainCell?l.mergeInfo:l,g=(0,i.getCellValueOrigin)(f.getCellRaw(p,m)),_=this._dataValidationModel.getRuleByLocation(u,d,p,m);if(!_)return;let v=this._dataValidationModel.getValidator(_.type);if(!v||!((r=v.skipDefaultFontRender)!=null&&r.call(v,_,g,{unitId:u,subUnitId:d,row:p,column:m})))return;let{formula1:y}=v.parseFormulaSync(_,u,d),b=this._calc(h,c),{a:x,d:S}=e.getTransform(),C=(0,n.fixLineWidthByScale)(b.left,x),w=(0,n.fixLineWidthByScale)(b.top,S),T=n.Transform.create().composeMatrix({left:C,top:w,scaleX:1,scaleY:1,angle:0,skewX:0,skewY:0,flipX:!1,flipY:!1}),E=h.endX-h.startX,D=h.endY-h.startY;e.save(),e.beginPath(),e.rect(h.startX,h.startY,E,D),e.clip();let O=T.getMatrix();e.transform(O[0],O[1],O[2],O[3],O[4],O[5]);let k=((a=c==null?void 0:c.fs)==null?10:a)*1.6,A=String(g)===String(y),j=this._themeService.getColorFromTheme(`primary.600`);n.CheckboxShape.drawWith(e,{checked:A,width:k,height:k,fill:(o=c==null||(s=c.cl)==null?void 0:s.rgb)==null?j:o}),e.restore()}isHit(e,t){let n=t.primaryWithCoord.isMergedMainCell?t.primaryWithCoord.mergeInfo:t.primaryWithCoord,r=this._calc(n,t.style),i=r.top,a=r.top+r.height,o=r.left,s=r.left+r.width,{x:c,y:l}=e;return c<=s&&c>=o&&l<=a&&l>=i}async onPointerDown(e,t){var n;if(t.button===2)return;let{primaryWithCoord:a,unitId:o,subUnitId:s,worksheet:c,row:l,col:u}=e,d=(0,i.getCellValueOrigin)(c.getCellRaw(l,u)),f=this._dataValidationModel.getRuleByLocation(o,s,l,u);if(!f)return;let p=this._dataValidationModel.getValidator(f.type);if(!p||!((n=p.skipDefaultFontRender)!=null&&n.call(p,f,d,{unitId:o,subUnitId:s,row:l,column:u})))return;let{formula1:m,formula2:h}=await this._parseFormula(f,o,s),g={range:{startColumn:a.actualColumn,endColumn:a.actualColumn,startRow:a.actualRow,endRow:a.actualRow},value:{v:String(d)===(0,i.transformCheckboxValue)(String(m))?h:m,p:null}};this._commandService.executeCommand(r.SetRangeValuesCommand.id,g)}onPointerEnter(e,r){var i;(i=(0,n.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(i=i.mainComponent)==null||i.setCursor(n.CURSOR_TYPE.POINTER)}onPointerLeave(e,r){var i;(i=(0,n.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(i=i.mainComponent)==null||i.setCursor(n.CURSOR_TYPE.DEFAULT)}};Ve=k([O(0,t.ICommandService),O(1,t.IUniverInstanceService),O(2,(0,t.Inject)(i.DataValidationFormulaService)),O(3,(0,t.Inject)(t.ThemeService)),O(4,(0,t.Inject)(n.IRenderManagerService)),O(5,(0,t.Inject)(i.SheetDataValidationModel))],Ve);let Q=class{constructor(e){this.injector=e,D(this,`canvasRender`,null),D(this,`dropdownType`,void 0),D(this,`optionsInput`,void 0),D(this,`formulaInput`,i.LIST_FORMULA_INPUT_NAME)}};Q=k([O(0,(0,t.Inject)(t.Injector))],Q);var He=class extends Q{constructor(...e){super(...e),D(this,`id`,t.DataValidationType.CHECKBOX),D(this,`canvasRender`,this.injector.createInstance(Ve)),D(this,`formulaInput`,i.CHECKBOX_FORMULA_INPUT_NAME)}},Ue=class extends Q{constructor(...e){super(...e),D(this,`id`,t.DataValidationType.CUSTOM),D(this,`formulaInput`,i.CUSTOM_FORMULA_INPUT_NAME)}},We=class extends Q{constructor(...e){super(...e),D(this,`id`,t.DataValidationType.DATE),D(this,`formulaInput`,`data-validation.formula-input`),D(this,`optionsInput`,Be.componentKey),D(this,`dropdownType`,a.DataValidatorDropdownType.DATE)}},Ge=class extends Q{constructor(...e){super(...e),D(this,`id`,t.DataValidationType.DECIMAL),D(this,`formulaInput`,i.BASE_FORMULA_INPUT_NAME)}};function Ke(e,t){let r=n.FontCache.getTextSize(e,t),i=r.width+8,{ba:a,bd:o}=r;return{width:i,height:a+o+0,ba:a}}function qe(e,t,n,r){let i=n-26,a=r-12,o=e.map(e=>({layout:Ke(e,t),text:e})),s,c=[];o.forEach(e=>{let{layout:t}=e,{width:n,height:r}=t;!s||s.width+n+4>i?(s={width:n,height:r,items:[{...e,left:0}]},c.push(s)):(s.items.push({...e,left:s.width+4}),s.width=s.width+n+4)});let l=0,u=0;return c.forEach((e,t)=>{u=Math.max(u,e.width),t===c.length-1?l+=e.height:l+=e.height+4}),{lines:c,totalHeight:l,contentWidth:i,contentHeight:a,cellAutoHeight:l+12,calcAutoWidth:u+26}}var Je=class extends n.Shape{static drawWith(e,t){let{fontString:r,info:i,fill:a,color:o}=t,{layout:s,text:c}=i;e.save(),n.Rect.drawWith(e,{width:s.width,height:s.height,radius:8,fill:a||`#ECECEC`}),e.translateWithPrecision(4,s.ba),e.font=r,e.fillStyle=o,e.fillText(c,0,0),e.restore()}};let Ye=new Path2D(`M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z`),Xe=class{constructor(e,t,n,r){this._commandService=e,this._univerInstanceService=t,this._renderManagerService=n,this._dataValidationModel=r,D(this,`zIndex`,void 0),D(this,`_dropdownInfoMap`,new Map)}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,n,r,i,a){let o=r-14+4,s=4;switch(a){case t.VerticalAlign.MIDDLE:s=(i-14)/2+4;break;case t.VerticalAlign.BOTTOM:s=i-14+4;break;default:break}e.save(),e.translateWithPrecision(n.startX+o,n.startY+s),e.fillStyle=`#565656`,e.fill(Ye),e.restore()}drawWith(e,r,a,o){var s,c;let{primaryWithCoord:l,row:u,col:d,style:f,data:p,subUnitId:m}=r,h=l.isMergedMainCell?l.mergeInfo:l,{leftOffset:g=0,rightOffset:_=0,topOffset:v=0,downOffset:y=0}=(p==null?void 0:p.fontRenderExtension)||{},b=this._ensureMap(m),x=this._generateKey(u,d),S=l.isMergedMainCell?l.mergeInfo.startRow:u,C=l.isMergedMainCell?l.mergeInfo.startColumn:d,w=this._dataValidationModel.getRuleByLocation(r.unitId,r.subUnitId,S,C);if(!w)return;let T=this._dataValidationModel.getValidator(w.type);if(!T)return;let E={startX:h.startX+g,endX:h.endX-_,startY:h.startY+v,endY:h.endY-y},D=E.endX-E.startX,O=E.endY-E.startY,{cl:k}=f||{},A=(s=typeof k==`object`?k==null?void 0:k.rgb:k)==null?`#000`:s,j=(0,n.getFontStyleString)(f==null?void 0:f),{vt:M,ht:N}=f||{},P=M==null?t.VerticalAlign.MIDDLE:M,F=(c=(0,i.getCellValueOrigin)(p))==null?``:c,I=T.parseCellValue(F),L=T.getListWithColorMap(w),R=qe(I,j,D,O);this._drawDownIcon(e,E,D,O,P),e.save(),e.translateWithPrecision(E.startX,E.startY),e.beginPath(),e.rect(0,0,D-14,O),e.clip(),e.translateWithPrecision(6,6);let z=0;switch(P){case t.VerticalAlign.MIDDLE:z=(R.contentHeight-R.totalHeight)/2;break;case t.VerticalAlign.BOTTOM:z=R.contentHeight-R.totalHeight;break;default:break}e.translateWithPrecision(0,z),R.lines.forEach((n,r)=>{e.save();let{width:i,height:a,items:o}=n,s=0;switch(N){case t.HorizontalAlign.RIGHT:s=R.contentWidth-i;break;case t.HorizontalAlign.CENTER:s=(R.contentWidth-i)/2;break;default:break}e.translate(s,r*(a+4)),o.forEach(t=>{e.save(),e.translateWithPrecision(t.left,0),Je.drawWith(e,{...j,info:t,color:A,fill:L[t.text]}),e.restore()}),e.restore()}),e.restore(),b.set(x,{left:E.startX,top:E.startY,width:R.contentWidth+6+14,height:R.contentHeight+12})}calcCellAutoHeight(e){var t;let{primaryWithCoord:r,style:a,data:o,row:s,col:c}=e,{leftOffset:l=0,rightOffset:u=0,topOffset:d=0,downOffset:f=0}=(o==null?void 0:o.fontRenderExtension)||{},p=r.isMergedMainCell?r.mergeInfo:r,m={startX:p.startX+l,endX:p.endX-u,startY:p.startY+d,endY:p.endY-f},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,s,c);if(!h)return;let g=this._dataValidationModel.getValidator(h.type);if(!g)return;let _=m.endX-m.startX,v=m.endY-m.startY,y=(t=(0,i.getCellValueOrigin)(o))==null?``:t;return qe(g.parseCellValue(y),(0,n.getFontStyleString)(a==null?void 0:a),_,v).cellAutoHeight}calcCellAutoWidth(e){var t;let{primaryWithCoord:r,style:a,data:o,row:s,col:c}=e,{leftOffset:l=0,rightOffset:u=0,topOffset:d=0,downOffset:f=0}=(o==null?void 0:o.fontRenderExtension)||{},p=r.isMergedMainCell?r.mergeInfo:r,m={startX:p.startX+l,endX:p.endX-u,startY:p.startY+d,endY:p.endY-f},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,s,c);if(!h)return;let g=this._dataValidationModel.getValidator(h.type);if(!g)return;let _=m.endX-m.startX,v=m.endY-m.startY,y=(t=(0,i.getCellValueOrigin)(o))==null?``:t;return qe(g.parseCellValue(y),(0,n.getFontStyleString)(a==null?void 0:a),_,v).calcAutoWidth}isHit(e,t){let{primaryWithCoord:n}=t,{endX:r}=n.isMergedMainCell?n.mergeInfo:n,{x:i}=e;return i>=r-14&&i<=r}onPointerDown(e,t){if(t.button===2)return;let{unitId:n,subUnitId:r,row:i,col:a}=e,o={unitId:n,subUnitId:r,row:i,column:a};this._commandService.executeCommand(V.id,o)}onPointerEnter(e,r){var i;return(i=(0,n.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(i=i.mainComponent)==null?void 0:i.setCursor(n.CURSOR_TYPE.POINTER)}onPointerLeave(e,r){var i;return(i=(0,n.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(i=i.mainComponent)==null?void 0:i.setCursor(n.CURSOR_TYPE.DEFAULT)}};Xe=k([O(0,t.ICommandService),O(1,t.IUniverInstanceService),O(2,(0,t.Inject)(n.IRenderManagerService)),O(3,(0,t.Inject)(i.SheetDataValidationModel))],Xe);var Ze=class extends Q{constructor(...e){super(...e),D(this,`id`,t.DataValidationType.LIST_MULTIPLE),D(this,`canvasRender`,this.injector.createInstance(Xe)),D(this,`dropdownType`,a.DataValidatorDropdownType.MULTIPLE_LIST)}};let Qe=new Path2D(`M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z`);function $e(e,n,r,i,a,o,s=!0){let c=0,l=s?3:0;switch(a){case t.VerticalAlign.BOTTOM:c=n-i-l;break;case t.VerticalAlign.MIDDLE:c=(n-i)/2;break;default:c=l;break}c=Math.max(3,c);let u=0;switch(o){case t.HorizontalAlign.CENTER:u=(e-r)/2;break;case t.HorizontalAlign.RIGHT:u=e-r;break;default:break}return u=Math.max(6,u),{paddingLeft:u,paddingTop:c}}let et=class{constructor(e,t,n,r,i){this._univerInstanceService=e,this._localeService=t,this._commandService=n,this._renderManagerService=r,this._dataValidationModel=i,D(this,`_dropdownInfoMap`,new Map),D(this,`zIndex`,void 0)}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,n,r,i,a,o,s){let{t:c=t.DEFAULT_STYLES.pd.t,b:l=t.DEFAULT_STYLES.pd.b}=s,u=r-14,d;switch(o){case t.VerticalAlign.MIDDLE:d=(i-4)/2;break;case t.VerticalAlign.BOTTOM:d=i-l-a-3+(a/2-4/2);break;default:d=c+3+(a/2-4/2);break}e.save(),e.translateWithPrecision(n.startX+u,n.startY+d),e.fillStyle=`#565656`,e.fill(Qe),e.restore()}drawWith(e,r,a){var o,s,c,l;let{primaryWithCoord:u,row:d,col:f,style:p,data:m,subUnitId:h}=r,g=u.isMergedMainCell?u.mergeInfo:u,_=u.isMergedMainCell?u.mergeInfo.startRow:d,v=u.isMergedMainCell?u.mergeInfo.startColumn:f,y=this._dataValidationModel.getRuleByLocation(r.unitId,r.subUnitId,_,v);if(!y)return;let b=this._dataValidationModel.getValidator(y.type);if(!b)return;let{leftOffset:x=0,rightOffset:S=0,topOffset:C=0,downOffset:w=0}=(m==null?void 0:m.fontRenderExtension)||{};if(!y||!b||!b||b.id.indexOf(t.DataValidationType.LIST)!==0||!b.skipDefaultFontRender(y))return;let T={startX:g.startX+x,endX:g.endX-S,startY:g.startY+C,endY:g.endY-w},E=T.endX-T.startX,D=T.endY-T.startY,O=this._ensureMap(h),k=this._generateKey(d,f),A=b.getListWithColorMap(y),j=(0,i.getCellValueOrigin)(m),M=`${j==null?``:j}`,N=A[M],{tb:P,vt:F,ht:I,pd:L}=p||{};P=(o=P)==null?t.WrapStrategy.WRAP:o,F=(s=F)==null?t.VerticalAlign.BOTTOM:s,I=(c=I)==null?t.DEFAULT_STYLES.ht:c,L=(l=L)==null?t.DEFAULT_STYLES.pd:l;let R=(0,n.getFontStyleString)(p).fontCache;if(y.renderMode===t.DataValidationRenderMode.ARROW){var z,B,V;let{l:r=t.DEFAULT_STYLES.pd.l,t:i=t.DEFAULT_STYLES.pd.t,r:o=t.DEFAULT_STYLES.pd.r,b:s=t.DEFAULT_STYLES.pd.b}=L,c=E-r-o-14-4,l=new n.DocSimpleSkeleton(M,R,P===t.WrapStrategy.WRAP,c,1/0);l.calculate();let u=l.getTotalWidth(),d=l.getTotalHeight(),{paddingTop:f,paddingLeft:m}=$e(c,D-i-s,u,d,F,I,!0);this._drawDownIcon(e,T,E,D,d,F,L),e.save(),e.translateWithPrecision(T.startX+r,T.startY+i),e.beginPath(),e.rect(0,0,E-r-o,D-i-s),e.clip(),e.translateWithPrecision(0,f),e.save(),e.translateWithPrecision(m,0),e.beginPath(),e.rect(0,0,c,d),e.clip(),n.Text.drawWith(e,{text:M,fontStyle:R,width:c,height:d,color:p==null||(z=p.cl)==null?void 0:z.rgb,strokeLine:!!(!(p==null||(B=p.st)==null)&&B.s),underline:!!(!(p==null||(V=p.ul)==null)&&V.s),warp:P===t.WrapStrategy.WRAP,hAlign:t.HorizontalAlign.LEFT},l),e.restore(),e.restore(),O.set(k,{left:T.endX-14+a.rowHeaderWidth,top:T.startY+i+a.columnHeaderHeight,width:14,height:D-i-s})}else{var H,U,W;e.save(),e.translateWithPrecision(T.startX,T.startY),e.beginPath(),e.rect(0,0,E,D),e.clip();let r=E-12-4-14-4,i=new n.DocSimpleSkeleton(M,R,P===t.WrapStrategy.WRAP,r,1/0);i.calculate();let o=i.getTotalWidth(),s=i.getTotalHeight(),c=s+2,l=Math.max(E-12,1),{paddingTop:u}=$e(l,D,o,c,F,I);e.translateWithPrecision(6,u),n.Rect.drawWith(e,{width:l,height:c,fill:N||`#ECECEC`,radius:8}),e.save(),e.translateWithPrecision(4,1),e.beginPath(),e.rect(0,0,r,s),e.clip(),n.Text.drawWith(e,{text:M,fontStyle:R,width:r,height:s,color:p==null||(H=p.cl)==null?void 0:H.rgb,strokeLine:!!(!(p==null||(U=p.st)==null)&&U.s),underline:!!(!(p==null||(W=p.ul)==null)&&W.s),warp:P===t.WrapStrategy.WRAP,hAlign:t.HorizontalAlign.LEFT},i),e.restore(),e.translateWithPrecision(r+4+4,(s-4)/2),e.fillStyle=`#565656`,e.fill(Qe),e.restore(),O.set(k,{left:T.startX+6+a.rowHeaderWidth,top:T.startY+u+a.columnHeaderHeight,width:l,height:c})}}calcCellAutoHeight(e){var r;let{primaryWithCoord:a,style:o,data:s,row:c,col:l}=e,u=a.isMergedMainCell?a.mergeInfo:a,{leftOffset:d=0,rightOffset:f=0,topOffset:p=0,downOffset:m=0}=(s==null?void 0:s.fontRenderExtension)||{},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,c,l);if(!h||h.renderMode===t.DataValidationRenderMode.TEXT)return;let g={startX:u.startX+d,endX:u.endX-f,startY:u.startY+p,endY:u.endY-m},_=g.endX-g.startX,v=(0,i.getCellValueOrigin)(s),y=`${v==null?``:v}`,{tb:b,pd:x}=o||{},{t:S=t.DEFAULT_STYLES.pd.t,b:C=t.DEFAULT_STYLES.pd.b}=x==null?{}:x;if(b=(r=b)==null?t.WrapStrategy.WRAP:r,h.renderMode===t.DataValidationRenderMode.ARROW){let{l:e=t.DEFAULT_STYLES.pd.l,r=t.DEFAULT_STYLES.pd.r}=x==null?{}:x,i=_-e-r-14-4,a=new n.DocSimpleSkeleton(y,(0,n.getFontStyleString)(o).fontCache,b===t.WrapStrategy.WRAP,i,1/0);return a.calculate(),a.getTotalHeight()+S+C+6}else{let e=Math.max(_-12-4-14-4,10),r=new n.DocSimpleSkeleton(y,(0,n.getFontStyleString)(o).fontCache,b===t.WrapStrategy.WRAP,e,1/0);return r.calculate(),r.getTotalHeight()+6+2}}calcCellAutoWidth(e){var r;let{primaryWithCoord:a,style:o,data:s,row:c,col:l}=e,u=a.isMergedMainCell?a.mergeInfo:a,{leftOffset:d=0,rightOffset:f=0,topOffset:p=0,downOffset:m=0}=(s==null?void 0:s.fontRenderExtension)||{},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,c,l);if(!h||h.renderMode===t.DataValidationRenderMode.TEXT)return;let g={startX:u.startX+d,endX:u.endX-f,startY:u.startY+p,endY:u.endY-m},_=g.endX-g.startX,v=(0,i.getCellValueOrigin)(s),y=`${v==null?``:v}`,{tb:b,pd:x}=o||{},{l:S=t.DEFAULT_STYLES.pd.l,r:C=t.DEFAULT_STYLES.pd.r}=x==null?{}:x;b=(r=b)==null?t.WrapStrategy.WRAP:r;let w=26;switch(h.renderMode){case t.DataValidationRenderMode.ARROW:w=18+C+S;break;case t.DataValidationRenderMode.CUSTOM:w=34+C+S+8/2+1;break;default:w=34+C+S+8/2+1}let T=_-w,E=new n.DocSimpleSkeleton(y,(0,n.getFontStyleString)(o).fontCache,b===t.WrapStrategy.WRAP,T,1/0);return E.calculate(),E.getTotalWidth()+w}isHit(e,n){let{subUnitId:r,row:i,col:a}=n,o=this._ensureMap(r).get(this._generateKey(i,a)),s=this._dataValidationModel.getRuleByLocation(n.unitId,n.subUnitId,i,a);if(!s||!o||s.renderMode===t.DataValidationRenderMode.TEXT)return!1;let{top:c,left:l,width:u,height:d}=o,{x:f,y:p}=e;return f>=l&&f<=l+u&&p>=c&&p<=c+d}onPointerDown(e,t){if(t.button===2)return;let{unitId:n,subUnitId:r,row:i,col:a}=e,o={unitId:n,subUnitId:r,row:i,column:a};this._commandService.executeCommand(V.id,o)}onPointerEnter(e,r){var i;(i=(0,n.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(i=i.mainComponent)==null||i.setCursor(n.CURSOR_TYPE.POINTER)}onPointerLeave(e,r){var i;(i=(0,n.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(i=i.mainComponent)==null||i.setCursor(n.CURSOR_TYPE.DEFAULT)}};et=k([O(0,t.IUniverInstanceService),O(1,(0,t.Inject)(t.LocaleService)),O(2,t.ICommandService),O(3,(0,t.Inject)(n.IRenderManagerService)),O(4,(0,t.Inject)(i.SheetDataValidationModel))],et);var tt=class extends Q{constructor(...e){super(...e),D(this,`id`,t.DataValidationType.LIST),D(this,`canvasRender`,this.injector.createInstance(et)),D(this,`dropdownType`,a.DataValidatorDropdownType.LIST),D(this,`optionsInput`,ze.componentKey),D(this,`formulaInput`,i.LIST_FORMULA_INPUT_NAME)}},nt=class extends Q{constructor(...e){super(...e),D(this,`id`,t.DataValidationType.TEXT_LENGTH),D(this,`formulaInput`,i.BASE_FORMULA_INPUT_NAME)}},rt=class extends Q{constructor(...e){super(...e),D(this,`id`,t.DataValidationType.WHOLE),D(this,`formulaInput`,i.BASE_FORMULA_INPUT_NAME)}};let it=class extends t.RxDisposable{constructor(e,t,n){super(),this._injector=e,this._componentManger=t,this._dataValidatorRegistryService=n,this._initComponents(),this._registerValidatorViews()}_initComponents(){[[`DataValidationIcon`,pe],[L,Ae],[ze.componentKey,ze],[Be.componentKey,Be],...Re].forEach(([e,t])=>{this.disposeWithMe(this._componentManger.register(e,t))})}_registerValidatorViews(){[Ge,rt,nt,We,He,tt,Ze,Ue].forEach(e=>{let t=this._injector.createInstance(e),n=this._dataValidatorRegistryService.getValidatorItem(t.id);n&&(n.formulaInput=t.formulaInput,n.canvasRender=t.canvasRender,n.dropdownType=t.dropdownType,n.optionsInput=t.optionsInput)})}};it=k([O(0,(0,t.Inject)(t.Injector)),O(1,(0,t.Inject)(o.ComponentManager)),O(2,(0,t.Inject)(a.DataValidatorRegistryService))],it);let $=class extends t.Plugin{constructor(e=M,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},M,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(j,o)}onStarting(){[[A],[I],[G],[K],[X],[J],[q],[it]].forEach(e=>{this._injector.add(e)}),[U,V,H,z,R,B].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(q),this._injector.get(J),this._injector.get(n.IRenderManagerService).registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,[se])}onRendered(){this._injector.get(it),this._injector.get(X)}onSteady(){this._injector.get(K)}};D($,`pluginName`,`SHEET_DATA_VALIDATION_UI_PLUGIN`),D($,`packageName`,S),D($,`version`,C),D($,`type`,t.UniverInstanceType.UNIVER_SHEET),$=k([O(1,(0,t.Inject)(t.Injector)),O(2,t.ICommandService),O(3,t.IConfigService)],$);let at=class extends t.Plugin{constructor(e=M,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},M,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(j,o)}onStarting(){[[A],[I],[G],[K],[X],[J],[q],[N],[it]].forEach(e=>{this._injector.add(e)}),[U,V,H,z,R,B].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(q),this._injector.get(J),this._injector.get(N),this._injector.get(G),this._injector.get(n.IRenderManagerService).registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,[se])}onRendered(){this._injector.get(it),this._injector.get(X)}onSteady(){this._injector.get(K)}};D(at,`pluginName`,`SHEET_DATA_VALIDATION_UI_PLUGIN`),D(at,`packageName`,S),D(at,`version`,C),D(at,`type`,t.UniverInstanceType.UNIVER_SHEET),at=k([(0,t.DependentOn)(i.UniverSheetsDataValidationPlugin),O(1,(0,t.Inject)(t.Injector)),O(2,t.ICommandService),O(3,t.IConfigService)],at),Object.defineProperty(e,`BaseSheetDataValidatorView`,{enumerable:!0,get:function(){return Q}}),Object.defineProperty(e,`UniverSheetsDataValidationMobileUIPlugin`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(e,`UniverSheetsDataValidationUIPlugin`,{enumerable:!0,get:function(){return at}})});
|
|
20
12
|
|
|
21
13
|
// index
|
|
22
14
|
(function(e,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/data-validation"),require("@univerjs/sheets-data-validation"),require("@univerjs/sheets-data-validation-ui"),require("@univerjs/sheets-data-validation/lib/facade")):typeof define=="function"&&define.amd?define(["exports","@univerjs/data-validation","@univerjs/sheets-data-validation","@univerjs/sheets-data-validation-ui","@univerjs/sheets-data-validation/lib/facade"],i):(e=typeof globalThis<"u"?globalThis:e||self,i(e.UniverPresetSheetsDataValidation={},e.UniverDataValidation,e.UniverSheetsDataValidation,e.UniverSheetsDataValidationUi))})(this,(function(e,i,a,t){"use strict";function n(s={}){const{showEditOnDropdown:d,showSearchOnDropdown:r}=s;return{plugins:[i.UniverDataValidationPlugin,a.UniverSheetsDataValidationPlugin,[t.UniverSheetsDataValidationUIPlugin,{showEditOnDropdown:d,showSearchOnDropdown:r}]].filter(o=>!!o)}}e.UniverSheetsDataValidationPreset=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|