@univerjs/preset-sheets-data-validation 0.7.0 → 0.8.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1 -1
- package/lib/index.css +1 -1
- package/lib/index.js +1 -1
- package/lib/types/umd.d.ts +2 -2
- package/lib/umd/index.js +4 -4
- package/package.json +6 -6
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/data-validation"),a=require("@univerjs/sheets-data-validation"),r=require("@univerjs/sheets-data-validation-ui");require("@univerjs/sheets-data-validation/facade");function o(e={}){const{showEditOnDropdown:i}=e;return{plugins:[t.UniverDataValidationPlugin,a.UniverSheetsDataValidationPlugin,[r.UniverSheetsDataValidationUIPlugin,{showEditOnDropdown:i}]].filter(n=>!!n)}}exports.UniverSheetsDataValidationPreset=o;Object.keys(t).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});Object.keys(a).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>a[e]})});Object.keys(r).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/data-validation"),a=require("@univerjs/sheets-data-validation"),r=require("@univerjs/sheets-data-validation-ui");require("@univerjs/sheets-data-validation/lib/facade");function o(e={}){const{showEditOnDropdown:i}=e;return{plugins:[t.UniverDataValidationPlugin,a.UniverSheetsDataValidationPlugin,[r.UniverSheetsDataValidationUIPlugin,{showEditOnDropdown:i}]].filter(n=>!!n)}}exports.UniverSheetsDataValidationPreset=o;Object.keys(t).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});Object.keys(a).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>a[e]})});Object.keys(r).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
|
package/lib/es/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { UniverSheetsDataValidationPlugin as e } from "@univerjs/sheets-data-val
|
|
|
4
4
|
export * from "@univerjs/sheets-data-validation";
|
|
5
5
|
import { UniverSheetsDataValidationUIPlugin as n } from "@univerjs/sheets-data-validation-ui";
|
|
6
6
|
export * from "@univerjs/sheets-data-validation-ui";
|
|
7
|
-
import "@univerjs/sheets-data-validation/facade";
|
|
7
|
+
import "@univerjs/sheets-data-validation/lib/facade";
|
|
8
8
|
function f(t = {}) {
|
|
9
9
|
const { showEditOnDropdown: i } = t;
|
|
10
10
|
return {
|
package/lib/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.univer-absolute{position:absolute}.univer-relative{position:relative}.univer-right-2{right:8px}.univer-top-\[19px\]{top:19px}.-univer-mt-2{margin-top:-8px}.univer--ml-2{margin-left:-8px}.univer--mr-2{margin-right:-8px}.univer-mb-1{margin-bottom:4px}.univer-mb-3{margin-bottom:12px}.univer-ml-1{margin-left:4px}.univer-ml-3{margin-left:12px}.univer-mr-1{margin-right:4px}.univer-mt-4{margin-top:16px}.univer-mt-5{margin-top:20px}.univer-box-border{box-sizing:border-box}.univer-flex{display:flex}.univer-inline-flex{display:inline-flex}.univer-grid{display:grid}.univer-size-4{width:16px;height:16px}.univer-h-4{height:16px}.univer-h-5{height:20px}.univer-h-8{height:32px}.univer-w-16{width:64px}.univer-w-4{width:16px}.univer-w-5{width:20px}.univer-w-\[287px\]{width:287px}.univer-w-fit{width:-moz-fit-content;width:fit-content}.univer-w-full{width:100%}.univer-cursor-move{cursor:move}.univer-cursor-pointer{cursor:pointer}.univer-grid-cols-6{grid-template-columns:repeat(6,minmax(0,1fr))}.univer-flex-row{flex-direction:row}.univer-flex-col{flex-direction:column}.univer-flex-wrap{flex-wrap:wrap}.univer-items-center{align-items:center}.univer-justify-end{justify-content:flex-end}.univer-justify-center{justify-content:center}.univer-justify-between{justify-content:space-between}.univer-gap-2{gap:8px}.univer-overflow-hidden{overflow:hidden}.univer-truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.univer-rounded{border-radius:4px}.univer-rounded-lg{border-radius:8px}.univer-rounded-md{border-radius:6px}.univer-bg-gray-50{background-color:var(--univer-gray-50)}.univer-bg-white{background-color:var(--univer-white)}.univer-p-1{padding:4px}.univer-p-1\.5{padding:6px}.univer-p-2{padding:8px}.univer-px-2{padding-left:8px;padding-right:8px}.univer-px-2\.5{padding-left:10px;padding-right:10px}.univer-py-
|
|
1
|
+
.univer-absolute{position:absolute}.univer-relative{position:relative}.univer-right-2{right:8px}.univer-top-\[19px\]{top:19px}.-univer-mt-2{margin-top:-8px}.-univer-mt-3{margin-top:-12px}.univer--ml-2{margin-left:-8px}.univer--mr-2{margin-right:-8px}.univer-mb-1{margin-bottom:4px}.univer-mb-3{margin-bottom:12px}.univer-ml-1{margin-left:4px}.univer-ml-3{margin-left:12px}.univer-mr-1{margin-right:4px}.univer-mt-3{margin-top:12px}.univer-mt-4{margin-top:16px}.univer-mt-5{margin-top:20px}.univer-box-border{box-sizing:border-box}.univer-flex{display:flex}.univer-inline-flex{display:inline-flex}.univer-grid{display:grid}.univer-size-4{width:16px;height:16px}.univer-h-4{height:16px}.univer-h-5{height:20px}.univer-h-8{height:32px}.univer-w-16{width:64px}.univer-w-4{width:16px}.univer-w-5{width:20px}.univer-w-\[287px\]{width:287px}.univer-w-fit{width:-moz-fit-content;width:fit-content}.univer-w-full{width:100%}.univer-cursor-move{cursor:move}.univer-cursor-pointer{cursor:pointer}.univer-grid-cols-6{grid-template-columns:repeat(6,minmax(0,1fr))}.univer-flex-row{flex-direction:row}.univer-flex-col{flex-direction:column}.univer-flex-wrap{flex-wrap:wrap}.univer-items-center{align-items:center}.univer-justify-end{justify-content:flex-end}.univer-justify-center{justify-content:center}.univer-justify-between{justify-content:space-between}.univer-gap-2{gap:8px}.univer-overflow-hidden{overflow:hidden}.univer-truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.univer-rounded{border-radius:4px}.univer-rounded-lg{border-radius:8px}.univer-rounded-md{border-radius:6px}.univer-bg-gray-50{background-color:var(--univer-gray-50)}.univer-bg-white{background-color:var(--univer-white)}.univer-p-1{padding:4px}.univer-p-1\.5{padding:6px}.univer-p-2{padding:8px}.univer-px-2{padding-left:8px;padding-right:8px}.univer-px-2\.5{padding-left:10px;padding-right:10px}.univer-py-2{padding-top:8px;padding-bottom:8px}.univer-pb-4{padding-bottom:16px}.univer-pr-9{padding-right:36px}.univer-pt-2{padding-top:8px}.univer-text-base{font-size:16px;line-height:24px}.univer-text-sm{font-size:14px;line-height:20px}.univer-text-xs{font-size:12px;line-height:16px}.univer-font-medium{font-weight:500}.univer-leading-\[18px\]{line-height:18px}.univer-leading-\[22px\]{line-height:22px}.univer-text-gray-400{color:var(--univer-gray-400)}.univer-text-gray-900{color:var(--univer-gray-900)}.univer-opacity-50{opacity:.5}.univer-transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.univer-duration-200{transition-duration:.2s}.hover\:univer-border-primary-600:hover{border-color:var(--univer-primary-600)}.hover\:univer-bg-gray-200:hover{background-color:var(--univer-gray-200)}.hover\:univer-bg-gray-50:hover{background-color:var(--univer-gray-50)}.hover\:univer-bg-primary-50:hover{background-color:var(--univer-primary-50)}.dark\:\!univer-bg-gray-700:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-700)!important}.dark\:\!univer-text-gray-300:where(.univer-dark,.univer-dark *){color:var(--univer-gray-300)!important}.dark\:\!univer-text-white:where(.univer-dark,.univer-dark *){color:var(--univer-white)!important}.dark\:hover\:\!univer-bg-gray-700:hover:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-700)!important}.dark\:hover\:\!univer-bg-gray-800:hover:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-800)!important}.\[\&\>div\:first-child\]\:univer-px-2\.5>div:first-child{padding-left:10px;padding-right:10px}.\[\&\>div\]\:univer-h-5>div{height:20px}.\[\&\>div\]\:univer-ring-transparent>div{--tw-ring-color: transparent }
|
package/lib/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { UniverSheetsDataValidationPlugin as e } from "@univerjs/sheets-data-val
|
|
|
4
4
|
export * from "@univerjs/sheets-data-validation";
|
|
5
5
|
import { UniverSheetsDataValidationUIPlugin as n } from "@univerjs/sheets-data-validation-ui";
|
|
6
6
|
export * from "@univerjs/sheets-data-validation-ui";
|
|
7
|
-
import "@univerjs/sheets-data-validation/facade";
|
|
7
|
+
import "@univerjs/sheets-data-validation/lib/facade";
|
|
8
8
|
function f(t = {}) {
|
|
9
9
|
const { showEditOnDropdown: i } = t;
|
|
10
10
|
return {
|
package/lib/types/umd.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IUniverSheetsDataValidationUIConfig } from '@univerjs/sheets-data-validation-ui';
|
|
2
2
|
import { IPreset } from './types';
|
|
3
|
-
import '@univerjs/sheets-data-validation/facade';
|
|
3
|
+
import '@univerjs/sheets-data-validation/lib/facade';
|
|
4
4
|
import '@univerjs/sheets-data-validation-ui/lib/index.css';
|
|
5
|
-
export type * from '@univerjs/sheets-data-validation/facade';
|
|
5
|
+
export type * from '@univerjs/sheets-data-validation/lib/facade';
|
|
6
6
|
export interface IUniverSheetsDataValidationPresetConfig extends Pick<IUniverSheetsDataValidationUIConfig, 'showEditOnDropdown'> {
|
|
7
7
|
}
|
|
8
8
|
export declare function UniverSheetsDataValidationPreset(config?: Partial<IUniverSheetsDataValidationPresetConfig>): IPreset;
|
package/lib/umd/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
// @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/sheets"),require("rxjs"),require("@univerjs/sheets-formula"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/data-validation","@univerjs/sheets","rxjs","@univerjs/sheets-formula","@univerjs/engine-formula"],r):(m=typeof globalThis<"u"?globalThis:m||self,r(m.UniverSheetsDataValidation={},m.UniverCore,m.UniverDataValidation,m.UniverSheets,m.rxjs,m.UniverSheetsFormula,m.UniverEngineFormula))})(this,function(m,r,p,D,U,Z,y){"use strict";var It=Object.defineProperty;var Ct=(m,r,p)=>r in m?It(m,r,{enumerable:!0,configurable:!0,writable:!0,value:p}):m[r]=p;var _=(m,r,p)=>Ct(m,typeof r!="symbol"?r+"":r,p);const Re="SHEET_DATA_VALIDATION_PLUGIN";var He=Object.getOwnPropertyDescriptor,We=(o,s,e,t)=>{for(var a=t>1?void 0:t?He(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);m.DataValidationCacheService=class extends r.Disposable{constructor(e,t){super();_(this,"_cacheMatrix",new Map);_(this,"_dirtyRanges$",new U.Subject);_(this,"dirtyRanges$",this._dirtyRanges$.asObservable());this._commandService=e,this._univerInstanceService=t,this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.SetRangeValuesMutation.id){const{cellValue:t,unitId:a,subUnitId:i}=e.params;if(t){const n=new r.ObjectMatrix(t).getDataRange();if(n.endRow===-1)return;this.markRangeDirty(a,i,[n],!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.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=We([Ve(0,r.Inject(r.ICommandService)),Ve(1,r.Inject(r.IUniverInstanceService))],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 j(o){var s;return(s=o==null?void 0:o[0])==null?void 0:s[0]}function E(o){return!y.ERROR_TYPE_SET.has(o)}function P(o,s){var t;const e=s.getValidatorItem(o);return(t=e==null?void 0:e.offsetFormulaByRange)!=null?t:!1}var $e=Object.getOwnPropertyDescriptor,ke=(o,s,e,t)=>{for(var a=t>1?void 0:t?$e(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},H=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCustomFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();_(this,"_ruleFormulaMap",new Map);_(this,"_ruleFormulaMap2",new Map);this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=a,this._dataValidationCacheService=i,this._validatorRegistryService=n,this._initFormulaResultHandler(),this._initDirtyRanges()}_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,S;const c=u.get((g=d.extra)==null?void 0:g.ruleId),h=this._dataValidationModel.getRuleById(t,n,(S=d.extra)==null?void 0:S.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})}_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._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(P(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 v,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,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}async getCellFormula2Value(e,t,a,i,n){var v,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,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}getCellFormulaValueSync(e,t,a,i,n){var v,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,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}getCellFormula2ValueSync(e,t,a,i,n){var v,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,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}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=ke([H(0,r.IUniverInstanceService),H(1,r.Inject(Z.RegisterOtherFormulaService)),H(2,r.Inject(p.DataValidationModel)),H(3,r.Inject(m.DataValidationCacheService)),H(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationCustomFormulaService);var xe=Object.getOwnPropertyDescriptor,qe=(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},W=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();_(this,"_formulaRuleMap",new Map);this._instanceService=e,this._registerOtherFormulaService=t,this._dataValidationCacheService=a,this._dataValidationModel=i,this._validatorRegistryService=n,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 c,h;if(u.get((c=d.extra)==null?void 0:c.ruleId)){const g=this._dataValidationModel.getRuleById(t,n,(h=d.extra)==null?void 0:h.ruleId);g&&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})}addRule(e,t,a){if(!P(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=qe([W(0,r.IUniverInstanceService),W(1,r.Inject(Z.RegisterOtherFormulaService)),W(2,r.Inject(m.DataValidationCacheService)),W(3,r.Inject(p.DataValidationModel)),W(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationFormulaService);function L(o){return r.getOriginCellValue(o)}function De(o){var s;return String((s=L(o))!=null?s:"")}class de{constructor(s,e,t,a,i=!1){_(this,"_map");_(this,"_tree",new r.RBush);_(this,"_dirty",!0);_(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});_(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 de(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 Qe=Object.getOwnPropertyDescriptor,Ge=(o,s,e,t)=>{for(var a=t>1?void 0:t?Qe(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();_(this,"_ruleMatrixMap",new Map);_(this,"_validStatusChange$",new U.Subject);_(this,"_ruleChange$",new U.Subject);_(this,"ruleChange$",this._ruleChange$.asObservable());_(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 de(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),S=d.getCellRaw(n,i),v=L(S);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:v,unitId:l,subUnitId:u,row:n,column:i,worksheet:t.worksheet,workbook:t.workbook,interceptValue:L(h),t:S==null?void 0:S.t},e).then(f=>{const M=f?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=Ge([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 $=1,k=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);_(this,"id",r.DataValidationType.CHECKBOX);_(this,"title","dataValidation.checkbox.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",41);_(this,"offsetFormulaByRange",!1);_(this,"_formulaService",this.injector.get(m.DataValidationFormulaService));_(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,S,v;const{formula1:i=$,formula2:n=k}=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((v=(S=l==null?void 0:l[1])==null?void 0:S.result)==null?void 0:v[0][0]):n,c=E(String(u))&&E(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,S,v;const{formula1:i=$,formula2:n=k}=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((v=(S=l==null?void 0:l[1])==null?void 0:S.result)==null?void 0:v[0][0]):n,c=E(String(u))&&E(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 Ye={[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"},Xe={[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"},J=[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.NOT_BETWEEN],q="{FORMULA1}",Q="{FORMULA2}";function Ke(o){return o.filter(Boolean).join(",")}function G(o){return o.split(",").filter(Boolean)}function ze(o){const s=L(o);return s==null?"":s.toString()}function Y(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}}const ce=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);_(this,"id",r.DataValidationType.DATE);_(this,"title","dataValidation.date.title");_(this,"order",40);_(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]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.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=E(String(l==null?void 0:l.v))&&E(String(u==null?void 0:u.v));return{formula1:ce(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:ce(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(J.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:ce(i)}}get operatorNames(){return this.operators.map(e=>this.localeService.t(Ye[e]))}generateRuleName(e){var a,i;if(!e.operator)return this.localeService.t(ye.NONE);const t=this.localeService.t(ye[e.operator]).replace(q,(a=e.formula1)!=null?a:"").replace(Q,(i=e.formula2)!=null?i:"");return`${this.titleStr} ${t}`}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(Xe[e.operator]).replace(q,a!=null?a:"").replace(Q,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 ee={[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 Ze extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"id",r.DataValidationType.DECIMAL);_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"title","dataValidation.decimal.title");_(this,"order",20);_(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]);_(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=E(String(l==null?void 0:l.v))&&E(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=J.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(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function me(o){if(!o)return[];const s=new Set;return o.forEach(e=>{e.forEach(t=>{var i,n;const a=L(t);if(a!=null){if(typeof a!="string"&&typeof(t==null?void 0:t.s)=="object"&&((n=(i=t.s)==null?void 0:i.n)!=null&&n.pattern)){s.add(r.numfmt.format(t.s.n.pattern,a,{throws:!1}));return}E(a.toString())&&s.add(a.toString())}})}),[...s]}const Je=["if","indirect","choose","offset"];function et(o,s){if(!r.isFormulaString(o)||y.isReferenceString(o.slice(1)))return!0;const t=s.sequenceNodesBuilder(o);return t&&t.some(a=>typeof a=="object"&&a.nodeType===y.sequenceNodeType.FUNCTION&&Je.indexOf(a.token.toLowerCase())>-1)}function tt(o,s){const{formula1:e="",ranges:t}=o;if(y.isReferenceString(e.slice(1))){const i=y.deserializeRangeWithSheet(e.slice(1));if((!i.sheetName||i.sheetName===s)&&t.some(n=>r.Rectangle.intersects(n,i.range)))return!0}return!1}class he extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"formulaService",this.injector.get(m.DataValidationFormulaService));_(this,"_lexer",this.injector.get(y.LexerTreeBuilder));_(this,"_univerInstanceService",this.injector.get(r.IUniverInstanceService));_(this,"order",50);_(this,"offsetFormulaByRange",!1);_(this,"id",r.DataValidationType.LIST);_(this,"title","dataValidation.list.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"skipDefaultFontRender",e=>e.renderMode!==r.DataValidationRenderMode.TEXT)}validatorFormula(e,t,a){var d,c,h;const i=!r.Tools.isBlank(e.formula1),n=et((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=tt(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 G(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:E(String(n))}}async isValidType(e,t,a){var g,S;const{value:i,unitId:n,subUnitId:l}=e,{formula1:u=""}=a,d=await this.formulaService.getRuleFormulaResult(n,l,a.uid),c=r.isFormulaString(u)?me((S=(g=d==null?void 0:d[0])==null?void 0:g.result)==null?void 0:S[0][0]):G(u);return this.parseCellValue(i).every(v=>c.includes(v))}generateRuleName(){return this.localeService.t("dataValidation.list.name")}generateRuleErrorMessage(){return this.localeService.t("dataValidation.list.error")}getList(e,t,a){var g,S,v,R;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(g=t?n.getUniverSheetInstance(t):void 0)!=null?g:n.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(S=a?l.getSheetBySheetId(a):void 0)!=null?S:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),h=this.formulaService.getRuleFormulaResultSync(d,c,e.uid);return r.isFormulaString(i)?me((R=(v=h==null?void 0:h[0])==null?void 0:v.result)==null?void 0:R[0][0]):G(i)}async getListAsync(e,t,a){var g,S,v,R;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(g=t?n.getUniverSheetInstance(t):void 0)!=null?g:n.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(S=a?l.getSheetBySheetId(a):void 0)!=null?S:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),h=await this.formulaService.getRuleFormulaResult(d,c,e.uid);return r.isFormulaString(i)?me((R=(v=h==null?void 0:h[0])==null?void 0:v.result)==null?void 0:R[0][0]):G(i)}getListWithColor(e,t,a){const i=this.getList(e,t,a),n=(e.formula2||"").split(",");return i.map((l,u)=>({label:l,color:n[u]}))}getListWithColorMap(e,t,a){const i=this.getListWithColor(e,t,a),n={};return i.forEach(l=>{l.color&&(n[l.label]=l.color)}),n}}class at extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.TEXT_LENGTH);_(this,"title","dataValidation.textLength.title");_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"order",30);_(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]);_(this,"scopes",["sheet"]);_(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=J.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=E(String(l==null?void 0:l.v))&&E(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}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(p.TextLengthErrorTitleMap[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function Oe(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(y.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:S}=g,v=new r.ObjectMatrix;let R=!1;function V(f,M){i&&f.forEach(T=>{r.Range.foreach(T,(O,I)=>{const F=S.getCellRaw(O,I),B=De(F);(Oe(F)||B===M)&&!(F!=null&&F.p)&&(R=!0,v.setValue(O,I,{v:M,p:null}))})})}if(e.forEach(f=>{switch(f.type){case"delete":u.push({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.rule.uid,source:a}}),d.unshift({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:f.rule,index:f.index,source:a}});break;case"update":{if(P(f.rule.type,l)){const T=f.oldRanges[0].startRow,O=f.oldRanges[0].startColumn,I=f.newRanges[0].startRow,F=f.newRanges[0].startColumn,B=I-T,oe=F-O,se=r.isFormulaString(f.rule.formula1)?n.moveFormulaRefOffset(f.rule.formula1,oe,B):f.rule.formula1,le=r.isFormulaString(f.rule.formula2)?n.moveFormulaRefOffset(f.rule.formula2,oe,B):f.rule.formula2;se!==f.rule.formula1||le!==f.rule.formula2||!r.isRangesEqual(f.newRanges,f.oldRanges)?(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:se,formula2:le,ranges:f.newRanges}}}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:f.rule.formula1,formula2:f.rule.formula2,ranges:f.oldRanges}}}})):(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.oldRanges},source:a}}))}else u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.oldRanges},source:a}});const M=c.getRuleById(o,s,f.ruleId);if(M&&M.type===r.DataValidationType.CHECKBOX){const O=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(M,o,s);V(f.newRanges,O.formula2)}break}case"add":{if(u.push({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:f.rule,source:a}}),d.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.rule.uid,source:a}}),f.rule.type===r.DataValidationType.CHECKBOX){const T=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(f.rule,o,s);V(f.rule.ranges,T.originFormula2)}break}}}),R){const f={id:D.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:s,cellValue:v.getData()}},M={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(t,f.params)};u.push(f),d.push(M)}return{redoMutations:u,undoMutations:d}}const Fe={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:S}=K(e,t,h,o);return u.pushUndoRedo({undoMutations:S,redoMutations:g,unitID:e}),r.sequenceExecute(g,l),!0}},Ie={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:S}=K(e,t,d,o);return g.push({id:p.AddDataValidationMutation.id,params:h}),S.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:t,ruleId:a.uid}}),l.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:S}),r.sequenceExecute(g,n),!0}},Ce={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 S={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:{...d,...c.normalizeFormula(g,n,l)}}},v=[{id:p.UpdateDataValidationMutation.id,params:S}],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),O=D.getSheetCommandTarget(T,{unitId:n,subUnitId:l});if(O){const I=new r.ObjectMatrix,{worksheet:F}=O,{formula2:B=k,formula1:oe=$}=h,{formula2:se=k,formula1:le=$}=d;let fe=!1;if(M.forEach(ue=>{r.Range.foreach(ue,(z,ve)=>{const C=F.getCellRaw(z,ve),Pe=De(C);(Oe(C)||Pe===String(B))&&!(C!=null&&C.p)?(I.setValue(z,ve,{v:se,p:null}),fe=!0):Pe===String(oe)&&!(C!=null&&C.p)&&(I.setValue(z,ve,{v:le,p:null}),fe=!0)})}),fe){const ue={id:D.SetRangeValuesMutation.id,params:{unitId:n,subUnitId:l,cellValue:I.getData()}},z={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(o,ue.params)};v.push(ue),V.push(z)}}}return r.sequenceExecute(v,e).result?(t.pushUndoRedo({unitID:n,redoMutations:v,undoMutations:V}),!0):!1}},Ae={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)}},S=[{id:p.UpdateDataValidationMutation.id,params:g}];return t.pushUndoRedo({unitID:i,redoMutations:h,undoMutations:S}),e.executeCommand(p.UpdateDataValidationMutation.id,c),!0}},Ue={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:S}=K(e,t,h,o);return d.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:S}),r.sequenceExecute(g,i).result}},we={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}},it=(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)}}]},Le={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}},rt="sheets-data-validation.config",Ne={};var nt=Object.getOwnPropertyDescriptor,ot=(o,s,e,t)=>{for(var a=t>1?void 0:t?nt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},ge=(o,s)=>(e,t)=>s(e,t,o);let te=class extends r.Disposable{constructor(s,e,t){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(s,e,t)=>{P(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 S=1;S<d.length;S++){const v=d[S],R=r.generateRandomId();c.push({id:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:{...t,uid:R,formula1:v.formulas[0],formula2:v.formulas[1],ranges:v.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()}))}};te=ot([ge(0,r.Inject(m.SheetDataValidationModel)),ge(1,r.Inject(Z.FormulaRefRangeService)),ge(2,r.Inject(p.DataValidatorRegistryService))],te);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||{}),st=Object.getOwnPropertyDescriptor,lt=(o,s,e,t)=>{for(var a=t>1?void 0:t?st(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=y.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:S,startColumn:v,endColumn:R}=u.range;for(let V=g;V<=S;V++)for(let f=v;f<=R;f++){const M=(a=(t=c.getCell(V,f))==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=lt([pe(0,r.IUniverInstanceService),pe(1,r.IPermissionService),pe(2,r.Inject(y.LexerTreeBuilder))],m.DataValidationFormulaController);var ut=Object.getOwnPropertyDescriptor,dt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ut(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},N=(o,s)=>(e,t)=>s(e,t,o);let ae=class extends r.Disposable{constructor(s,e,t,a,i,n){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(s,e,t)=>{P(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 S=g[c];if(!S||S===h)return{redos:[],undos:[]};const v={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}],f=[{id:p.UpdateDataValidationMutation.id,params:R}];return{redos:V,undos:f}},u=this._dataValidationFormulaService.getRuleFormulaInfo(s,e,a);if(u){const[c,h]=u;if(c){const g=this._formulaRefRangeService.registerFormula(s,e,c.text,S=>l("formula1",S));n.add(()=>g.dispose())}if(h){const g=this._formulaRefRangeService.registerFormula(s,e,h.text,S=>l("formula2",S));n.add(()=>g.dispose())}}}register(s,e,t){var u;const a=d=>{const c=[...t.ranges],g=c.map(v=>D.handleCommonDefaultRangeChangeWithEffectRefCommands(v,d)).filter(v=>!!v).flat();if(r.isRangesEqual(g,c))return{redos:[],undos:[]};if(g.length){const v={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:g},source:"patched"},R=[{id:p.UpdateDataValidationMutation.id,params:v}],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 v={unitId:s,subUnitId:e,ruleId:t.uid},R=[{id:p.RemoveDataValidationMutation.id,params:v}],V=it(this._injector,v);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()}))}};ae=dt([N(0,r.Inject(m.SheetDataValidationModel)),N(1,r.Inject(r.Injector)),N(2,r.Inject(D.RefRangeService)),N(3,r.Inject(m.DataValidationFormulaService)),N(4,r.Inject(Z.FormulaRefRangeService)),N(5,r.Inject(p.DataValidatorRegistryService))],ae);var ct=Object.getOwnPropertyDescriptor,mt=(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},_e=(o,s)=>(e,t)=>s(e,t,o);let ie=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}]}}return{redos:[],undos:[]}}}))}};ie=mt([_e(0,r.Inject(D.SheetInterceptorService)),_e(1,r.Inject(r.IUniverInstanceService)),_e(2,r.Inject(m.SheetDataValidationModel))],ie);class ht extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.ANY);_(this,"title","dataValidation.any.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",0);_(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 gt extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.CUSTOM);_(this,"title","dataValidation.custom.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",60);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.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(y.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 E(String(c))&&r.Tools.isDefine(c)&&c!==""?d.t===r.CellValueType.BOOLEAN?!!c:typeof c=="boolean"?c:typeof c=="number"?!!c:typeof c=="string"?E(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 Be extends he{constructor(){super(...arguments);_(this,"id",r.DataValidationType.LIST_MULTIPLE);_(this,"title","dataValidation.listMultiple.title");_(this,"offsetFormulaByRange",!1);_(this,"skipDefaultFontRender",()=>!0)}}class pt extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"id",r.DataValidationType.WHOLE);_(this,"title","dataValidation.whole.title");_(this,"order",10);_(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]);_(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,S=E(`${h}`)&&E(`${g}`);return{formula1:this._parseNumber(h),formula2:this._parseNumber(g),isFormulaValid:S}}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=J.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(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}var _t=Object.getOwnPropertyDescriptor,St=(o,s,e,t)=>{for(var a=t>1?void 0:t?_t(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 re=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(){[ht,Ze,pt,at,Te,Ee,he,Be,gt].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:[]}}})}};re=St([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))],re);var ft=Object.getOwnPropertyDescriptor,vt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ft(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},ne=(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}`);const l=this._sheetDataValidationModel.getRuleByLocation(i,n,t,a);return l?new Promise(u=>{this._sheetDataValidationModel.validator(l,{unitId:i,subUnitId:n,row:t,col:a,worksheet:e,workbook:s},d=>{u(d)})}):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)}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}`);return Promise.all(t.map(n=>{const l=[];return r.Range.foreach(n,(u,d)=>{l.push(this._validatorByCell(a,i,u,d))}),Promise.all(l)}))}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))}),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=vt([ne(0,r.IUniverInstanceService),ne(1,r.Inject(m.SheetDataValidationModel)),ne(2,r.Inject(m.DataValidationCacheService)),ne(3,r.Inject(r.LifecycleService))],m.SheetsDataValidationValidatorService);var Rt=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,Dt=(o,s,e)=>s in o?Rt(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e,Mt=(o,s,e,t)=>{for(var a=t>1?void 0:t?Vt(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),je=(o,s,e)=>Dt(o,typeof s!="symbol"?s+"":s,e);m.UniverSheetsDataValidationPlugin=class extends r.Plugin{constructor(s=Ne,e,t,a){super(),this._config=s,this._injector=e,this._commandService=t,this._configService=a;const{...i}=r.merge({},Ne,this._config);this._configService.setConfig(rt,i)}onStarting(){[[m.DataValidationCacheService],[m.DataValidationFormulaService],[m.DataValidationCustomFormulaService],[m.SheetsDataValidationValidatorService],[m.SheetDataValidationModel],[re],[m.DataValidationFormulaController],[ie],[ae],[te]].forEach(s=>{this._injector.add(s)}),[Ie,Fe,Ce,Ae,Le,we,Ue].forEach(s=>{this._commandService.registerCommand(s)}),this._injector.get(m.DataValidationCacheService),this._injector.get(m.SheetsDataValidationValidatorService),this._injector.get(re),this._injector.get(te),this._injector.get(ae)}onReady(){this._injector.get(ie)}onRendered(){this._injector.get(m.DataValidationFormulaController)}},je(m.UniverSheetsDataValidationPlugin,"pluginName",Re),je(m.UniverSheetsDataValidationPlugin,"type",r.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsDataValidationPlugin=Mt([r.DependentOn(p.UniverDataValidationPlugin),Se(1,r.Inject(r.Injector)),Se(2,r.ICommandService),Se(3,r.IConfigService)],m.UniverSheetsDataValidationPlugin);function Et(o){const e=o.get(D.SheetsSelectionsService).getCurrentSelections().map(i=>i.range);return{uid:r.Tools.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 yt="data-validation.custom-formula-input",Tt="data-validation.formula-input",Ot="data-validation.list-formula-input",Ft="data-validation.checkbox-formula-input";m.AddSheetDataValidationCommand=Ie,m.BASE_FORMULA_INPUT_NAME=Tt,m.CHECKBOX_FORMULA_1=$,m.CHECKBOX_FORMULA_2=k,m.CHECKBOX_FORMULA_INPUT_NAME=Ft,m.CUSTOM_FORMULA_INPUT_NAME=yt,m.CheckboxValidator=Ee,m.ClearRangeDataValidationCommand=Ue,m.DATA_VALIDATION_PLUGIN_NAME=Re,m.DateValidator=Te,m.LIST_FORMULA_INPUT_NAME=Ot,m.ListMultipleValidator=Be,m.ListValidator=he,m.RemoveSheetAllDataValidationCommand=we,m.RemoveSheetDataValidationCommand=Le,m.UpdateSheetDataValidationOptionsCommand=Ae,m.UpdateSheetDataValidationRangeCommand=Fe,m.UpdateSheetDataValidationSettingCommand=Ce,m.createDefaultNewRule=Et,m.deserializeListOptions=G,m.getCellValueNumber=X,m.getCellValueOrigin=L,m.getDataValidationCellValue=ze,m.getDataValidationDiffMutations=K,m.getFormulaCellData=j,m.getFormulaResult=w,m.getTransformedFormula=Y,m.isLegalFormulaResult=E,m.serializeListOptions=Ke,m.transformCheckboxValue=x,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
6
|
+
(function(m,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/sheets-formula"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/data-validation","@univerjs/sheets","rxjs","@univerjs/sheets-formula","@univerjs/engine-formula"],r):(m=typeof globalThis<"u"?globalThis:m||self,r(m.UniverSheetsDataValidation={},m.UniverCore,m.UniverDataValidation,m.UniverSheets,m.rxjs,m.UniverSheetsFormula,m.UniverEngineFormula))})(this,function(m,r,p,D,U,Z,y){"use strict";var It=Object.defineProperty;var Ct=(m,r,p)=>r in m?It(m,r,{enumerable:!0,configurable:!0,writable:!0,value:p}):m[r]=p;var _=(m,r,p)=>Ct(m,typeof r!="symbol"?r+"":r,p);const Re="SHEET_DATA_VALIDATION_PLUGIN";var He=Object.getOwnPropertyDescriptor,We=(o,s,e,t)=>{for(var a=t>1?void 0:t?He(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);m.DataValidationCacheService=class extends r.Disposable{constructor(e,t){super();_(this,"_cacheMatrix",new Map);_(this,"_dirtyRanges$",new U.Subject);_(this,"dirtyRanges$",this._dirtyRanges$.asObservable());this._commandService=e,this._univerInstanceService=t,this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.SetRangeValuesMutation.id){const{cellValue:t,unitId:a,subUnitId:i}=e.params;if(t){const n=new r.ObjectMatrix(t).getDataRange();if(n.endRow===-1)return;this.markRangeDirty(a,i,[n],!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=We([Ve(0,r.Inject(r.ICommandService)),Ve(1,r.Inject(r.IUniverInstanceService))],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 j(o){var s;return(s=o==null?void 0:o[0])==null?void 0:s[0]}function E(o){return!y.ERROR_TYPE_SET.has(o)}function P(o,s){var t;const e=s.getValidatorItem(o);return(t=e==null?void 0:e.offsetFormulaByRange)!=null?t:!1}var $e=Object.getOwnPropertyDescriptor,ke=(o,s,e,t)=>{for(var a=t>1?void 0:t?$e(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},H=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCustomFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();_(this,"_ruleFormulaMap",new Map);_(this,"_ruleFormulaMap2",new Map);this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=a,this._dataValidationCacheService=i,this._validatorRegistryService=n,this._initFormulaResultHandler(),this._initDirtyRanges()}_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,S;const c=u.get((g=d.extra)==null?void 0:g.ruleId),h=this._dataValidationModel.getRuleById(t,n,(S=d.extra)==null?void 0:S.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})}_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._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(P(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 v,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,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}async getCellFormula2Value(e,t,a,i,n){var v,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,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}getCellFormulaValueSync(e,t,a,i,n){var v,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,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}getCellFormula2ValueSync(e,t,a,i,n){var v,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,S=n-h;return j((R=(v=d==null?void 0:d.result)==null?void 0:v[g])==null?void 0:R[S])}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=ke([H(0,r.IUniverInstanceService),H(1,r.Inject(Z.RegisterOtherFormulaService)),H(2,r.Inject(p.DataValidationModel)),H(3,r.Inject(m.DataValidationCacheService)),H(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationCustomFormulaService);var xe=Object.getOwnPropertyDescriptor,qe=(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},W=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();_(this,"_formulaRuleMap",new Map);this._instanceService=e,this._registerOtherFormulaService=t,this._dataValidationCacheService=a,this._dataValidationModel=i,this._validatorRegistryService=n,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 c,h;if(u.get((c=d.extra)==null?void 0:c.ruleId)){const g=this._dataValidationModel.getRuleById(t,n,(h=d.extra)==null?void 0:h.ruleId);g&&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})}addRule(e,t,a){if(!P(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=qe([W(0,r.IUniverInstanceService),W(1,r.Inject(Z.RegisterOtherFormulaService)),W(2,r.Inject(m.DataValidationCacheService)),W(3,r.Inject(p.DataValidationModel)),W(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationFormulaService);function L(o){return r.getOriginCellValue(o)}function De(o){var s;return String((s=L(o))!=null?s:"")}class de{constructor(s,e,t,a,i=!1){_(this,"_map");_(this,"_tree",new r.RBush);_(this,"_dirty",!0);_(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});_(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 de(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 Qe=Object.getOwnPropertyDescriptor,Ge=(o,s,e,t)=>{for(var a=t>1?void 0:t?Qe(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();_(this,"_ruleMatrixMap",new Map);_(this,"_validStatusChange$",new U.Subject);_(this,"_ruleChange$",new U.Subject);_(this,"ruleChange$",this._ruleChange$.asObservable());_(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 de(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),S=d.getCellRaw(n,i),v=L(S);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:v,unitId:l,subUnitId:u,row:n,column:i,worksheet:t.worksheet,workbook:t.workbook,interceptValue:L(h),t:S==null?void 0:S.t},e).then(f=>{const M=f?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=Ge([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 $=1,k=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);_(this,"id",r.DataValidationType.CHECKBOX);_(this,"title","dataValidation.checkbox.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",41);_(this,"offsetFormulaByRange",!1);_(this,"_formulaService",this.injector.get(m.DataValidationFormulaService));_(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,S,v;const{formula1:i=$,formula2:n=k}=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((v=(S=l==null?void 0:l[1])==null?void 0:S.result)==null?void 0:v[0][0]):n,c=E(String(u))&&E(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,S,v;const{formula1:i=$,formula2:n=k}=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((v=(S=l==null?void 0:l[1])==null?void 0:S.result)==null?void 0:v[0][0]):n,c=E(String(u))&&E(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 Ye={[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"},Xe={[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"},J=[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.NOT_BETWEEN],q="{FORMULA1}",Q="{FORMULA2}";function Ke(o){return o.filter(Boolean).join(",")}function G(o){return o.split(",").filter(Boolean)}function ze(o){const s=L(o);return s==null?"":s.toString()}function Y(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}}const ce=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);_(this,"id",r.DataValidationType.DATE);_(this,"title","dataValidation.date.title");_(this,"order",40);_(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]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.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=E(String(l==null?void 0:l.v))&&E(String(u==null?void 0:u.v));return{formula1:ce(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:ce(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(J.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:ce(i)}}get operatorNames(){return this.operators.map(e=>this.localeService.t(Ye[e]))}generateRuleName(e){var a,i;if(!e.operator)return this.localeService.t(ye.NONE);const t=this.localeService.t(ye[e.operator]).replace(q,(a=e.formula1)!=null?a:"").replace(Q,(i=e.formula2)!=null?i:"");return`${this.titleStr} ${t}`}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(Xe[e.operator]).replace(q,a!=null?a:"").replace(Q,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 ee={[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 Ze extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"id",r.DataValidationType.DECIMAL);_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"title","dataValidation.decimal.title");_(this,"order",20);_(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]);_(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=E(String(l==null?void 0:l.v))&&E(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=J.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(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function me(o){if(!o)return[];const s=new Set;return o.forEach(e=>{e.forEach(t=>{var i,n;const a=L(t);if(a!=null){if(typeof a!="string"&&typeof(t==null?void 0:t.s)=="object"&&((n=(i=t.s)==null?void 0:i.n)!=null&&n.pattern)){s.add(r.numfmt.format(t.s.n.pattern,a,{throws:!1}));return}E(a.toString())&&s.add(a.toString())}})}),[...s]}const Je=["if","indirect","choose","offset"];function et(o,s){if(!r.isFormulaString(o)||y.isReferenceString(o.slice(1)))return!0;const t=s.sequenceNodesBuilder(o);return t&&t.some(a=>typeof a=="object"&&a.nodeType===y.sequenceNodeType.FUNCTION&&Je.indexOf(a.token.toLowerCase())>-1)}function tt(o,s){const{formula1:e="",ranges:t}=o;if(y.isReferenceString(e.slice(1))){const i=y.deserializeRangeWithSheet(e.slice(1));if((!i.sheetName||i.sheetName===s)&&t.some(n=>r.Rectangle.intersects(n,i.range)))return!0}return!1}class he extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"formulaService",this.injector.get(m.DataValidationFormulaService));_(this,"_lexer",this.injector.get(y.LexerTreeBuilder));_(this,"_univerInstanceService",this.injector.get(r.IUniverInstanceService));_(this,"order",50);_(this,"offsetFormulaByRange",!1);_(this,"id",r.DataValidationType.LIST);_(this,"title","dataValidation.list.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"skipDefaultFontRender",e=>e.renderMode!==r.DataValidationRenderMode.TEXT)}validatorFormula(e,t,a){var d,c,h;const i=!r.Tools.isBlank(e.formula1),n=et((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=tt(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 G(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:E(String(n))}}async isValidType(e,t,a){var g,S;const{value:i,unitId:n,subUnitId:l}=e,{formula1:u=""}=a,d=await this.formulaService.getRuleFormulaResult(n,l,a.uid),c=r.isFormulaString(u)?me((S=(g=d==null?void 0:d[0])==null?void 0:g.result)==null?void 0:S[0][0]):G(u);return this.parseCellValue(i).every(v=>c.includes(v))}generateRuleName(){return this.localeService.t("dataValidation.list.name")}generateRuleErrorMessage(){return this.localeService.t("dataValidation.list.error")}getList(e,t,a){var g,S,v,R;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(g=t?n.getUniverSheetInstance(t):void 0)!=null?g:n.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(S=a?l.getSheetBySheetId(a):void 0)!=null?S:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),h=this.formulaService.getRuleFormulaResultSync(d,c,e.uid);return r.isFormulaString(i)?me((R=(v=h==null?void 0:h[0])==null?void 0:v.result)==null?void 0:R[0][0]):G(i)}async getListAsync(e,t,a){var g,S,v,R;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(g=t?n.getUniverSheetInstance(t):void 0)!=null?g:n.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(S=a?l.getSheetBySheetId(a):void 0)!=null?S:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),h=await this.formulaService.getRuleFormulaResult(d,c,e.uid);return r.isFormulaString(i)?me((R=(v=h==null?void 0:h[0])==null?void 0:v.result)==null?void 0:R[0][0]):G(i)}getListWithColor(e,t,a){const i=this.getList(e,t,a),n=(e.formula2||"").split(",");return i.map((l,u)=>({label:l,color:n[u]}))}getListWithColorMap(e,t,a){const i=this.getListWithColor(e,t,a),n={};return i.forEach(l=>{l.color&&(n[l.label]=l.color)}),n}}class at extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.TEXT_LENGTH);_(this,"title","dataValidation.textLength.title");_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"order",30);_(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]);_(this,"scopes",["sheet"]);_(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=J.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=E(String(l==null?void 0:l.v))&&E(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}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(p.TextLengthErrorTitleMap[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function Oe(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(y.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:S}=g,v=new r.ObjectMatrix;let R=!1;function V(f,M){i&&f.forEach(T=>{r.Range.foreach(T,(O,I)=>{const F=S.getCellRaw(O,I),B=De(F);(Oe(F)||B===M)&&!(F!=null&&F.p)&&(R=!0,v.setValue(O,I,{v:M,p:null}))})})}if(e.forEach(f=>{switch(f.type){case"delete":u.push({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.rule.uid,source:a}}),d.unshift({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:f.rule,index:f.index,source:a}});break;case"update":{if(P(f.rule.type,l)){const T=f.oldRanges[0].startRow,O=f.oldRanges[0].startColumn,I=f.newRanges[0].startRow,F=f.newRanges[0].startColumn,B=I-T,oe=F-O,se=r.isFormulaString(f.rule.formula1)?n.moveFormulaRefOffset(f.rule.formula1,oe,B):f.rule.formula1,le=r.isFormulaString(f.rule.formula2)?n.moveFormulaRefOffset(f.rule.formula2,oe,B):f.rule.formula2;se!==f.rule.formula1||le!==f.rule.formula2||!r.isRangesEqual(f.newRanges,f.oldRanges)?(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:se,formula2:le,ranges:f.newRanges}}}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:f.rule.formula1,formula2:f.rule.formula2,ranges:f.oldRanges}}}})):(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.oldRanges},source:a}}))}else u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.oldRanges},source:a}});const M=c.getRuleById(o,s,f.ruleId);if(M&&M.type===r.DataValidationType.CHECKBOX){const O=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(M,o,s);V(f.newRanges,O.formula2)}break}case"add":{if(u.push({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:f.rule,source:a}}),d.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.rule.uid,source:a}}),f.rule.type===r.DataValidationType.CHECKBOX){const T=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(f.rule,o,s);V(f.rule.ranges,T.originFormula2)}break}}}),R){const f={id:D.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:s,cellValue:v.getData()}},M={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(t,f.params)};u.push(f),d.push(M)}return{redoMutations:u,undoMutations:d}}const Fe={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:S}=K(e,t,h,o);return u.pushUndoRedo({undoMutations:S,redoMutations:g,unitID:e}),r.sequenceExecute(g,l),!0}},Ie={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:S}=K(e,t,d,o);return g.push({id:p.AddDataValidationMutation.id,params:h}),S.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:t,ruleId:a.uid}}),l.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:S}),r.sequenceExecute(g,n),!0}},Ce={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 S={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:{...d,...c.normalizeFormula(g,n,l)}}},v=[{id:p.UpdateDataValidationMutation.id,params:S}],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),O=D.getSheetCommandTarget(T,{unitId:n,subUnitId:l});if(O){const I=new r.ObjectMatrix,{worksheet:F}=O,{formula2:B=k,formula1:oe=$}=h,{formula2:se=k,formula1:le=$}=d;let fe=!1;if(M.forEach(ue=>{r.Range.foreach(ue,(z,ve)=>{const C=F.getCellRaw(z,ve),Pe=De(C);(Oe(C)||Pe===String(B))&&!(C!=null&&C.p)?(I.setValue(z,ve,{v:se,p:null}),fe=!0):Pe===String(oe)&&!(C!=null&&C.p)&&(I.setValue(z,ve,{v:le,p:null}),fe=!0)})}),fe){const ue={id:D.SetRangeValuesMutation.id,params:{unitId:n,subUnitId:l,cellValue:I.getData()}},z={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(o,ue.params)};v.push(ue),V.push(z)}}}return r.sequenceExecute(v,e).result?(t.pushUndoRedo({unitID:n,redoMutations:v,undoMutations:V}),!0):!1}},Ae={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)}},S=[{id:p.UpdateDataValidationMutation.id,params:g}];return t.pushUndoRedo({unitID:i,redoMutations:h,undoMutations:S}),e.executeCommand(p.UpdateDataValidationMutation.id,c),!0}},Ue={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:S}=K(e,t,h,o);return d.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:S}),r.sequenceExecute(g,i).result}},we={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}},it=(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)}}]},Le={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}},rt="sheets-data-validation.config",Ne={};var nt=Object.getOwnPropertyDescriptor,ot=(o,s,e,t)=>{for(var a=t>1?void 0:t?nt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},ge=(o,s)=>(e,t)=>s(e,t,o);let te=class extends r.Disposable{constructor(s,e,t){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(s,e,t)=>{P(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 S=1;S<d.length;S++){const v=d[S],R=r.generateRandomId();c.push({id:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:{...t,uid:R,formula1:v.formulas[0],formula2:v.formulas[1],ranges:v.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()}))}};te=ot([ge(0,r.Inject(m.SheetDataValidationModel)),ge(1,r.Inject(Z.FormulaRefRangeService)),ge(2,r.Inject(p.DataValidatorRegistryService))],te);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||{}),st=Object.getOwnPropertyDescriptor,lt=(o,s,e,t)=>{for(var a=t>1?void 0:t?st(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=y.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:S,startColumn:v,endColumn:R}=u.range;for(let V=g;V<=S;V++)for(let f=v;f<=R;f++){const M=(a=(t=c.getCell(V,f))==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=lt([pe(0,r.IUniverInstanceService),pe(1,r.IPermissionService),pe(2,r.Inject(y.LexerTreeBuilder))],m.DataValidationFormulaController);var ut=Object.getOwnPropertyDescriptor,dt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ut(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},N=(o,s)=>(e,t)=>s(e,t,o);let ae=class extends r.Disposable{constructor(s,e,t,a,i,n){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(s,e,t)=>{P(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 S=g[c];if(!S||S===h)return{redos:[],undos:[]};const v={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}],f=[{id:p.UpdateDataValidationMutation.id,params:R}];return{redos:V,undos:f}},u=this._dataValidationFormulaService.getRuleFormulaInfo(s,e,a);if(u){const[c,h]=u;if(c){const g=this._formulaRefRangeService.registerFormula(s,e,c.text,S=>l("formula1",S));n.add(()=>g.dispose())}if(h){const g=this._formulaRefRangeService.registerFormula(s,e,h.text,S=>l("formula2",S));n.add(()=>g.dispose())}}}register(s,e,t){var u;const a=d=>{const c=[...t.ranges],g=c.map(v=>D.handleCommonDefaultRangeChangeWithEffectRefCommands(v,d)).filter(v=>!!v).flat();if(r.isRangesEqual(g,c))return{redos:[],undos:[]};if(g.length){const v={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:g},source:"patched"},R=[{id:p.UpdateDataValidationMutation.id,params:v}],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 v={unitId:s,subUnitId:e,ruleId:t.uid},R=[{id:p.RemoveDataValidationMutation.id,params:v}],V=it(this._injector,v);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()}))}};ae=dt([N(0,r.Inject(m.SheetDataValidationModel)),N(1,r.Inject(r.Injector)),N(2,r.Inject(D.RefRangeService)),N(3,r.Inject(m.DataValidationFormulaService)),N(4,r.Inject(Z.FormulaRefRangeService)),N(5,r.Inject(p.DataValidatorRegistryService))],ae);var ct=Object.getOwnPropertyDescriptor,mt=(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},_e=(o,s)=>(e,t)=>s(e,t,o);let ie=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}]}}return{redos:[],undos:[]}}}))}};ie=mt([_e(0,r.Inject(D.SheetInterceptorService)),_e(1,r.Inject(r.IUniverInstanceService)),_e(2,r.Inject(m.SheetDataValidationModel))],ie);class ht extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.ANY);_(this,"title","dataValidation.any.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",0);_(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 gt extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.CUSTOM);_(this,"title","dataValidation.custom.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"order",60);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.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(y.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 E(String(c))&&r.Tools.isDefine(c)&&c!==""?d.t===r.CellValueType.BOOLEAN?!!c:typeof c=="boolean"?c:typeof c=="number"?!!c:typeof c=="string"?E(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 Be extends he{constructor(){super(...arguments);_(this,"id",r.DataValidationType.LIST_MULTIPLE);_(this,"title","dataValidation.listMultiple.title");_(this,"offsetFormulaByRange",!1);_(this,"skipDefaultFontRender",()=>!0)}}class pt extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));_(this,"id",r.DataValidationType.WHOLE);_(this,"title","dataValidation.whole.title");_(this,"order",10);_(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]);_(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,S=E(`${h}`)&&E(`${g}`);return{formula1:this._parseNumber(h),formula2:this._parseNumber(g),isFormulaValid:S}}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=J.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(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}var _t=Object.getOwnPropertyDescriptor,St=(o,s,e,t)=>{for(var a=t>1?void 0:t?_t(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 re=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(){[ht,Ze,pt,at,Te,Ee,he,Be,gt].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:[]}}})}};re=St([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))],re);var ft=Object.getOwnPropertyDescriptor,vt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ft(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},ne=(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}`);const l=this._sheetDataValidationModel.getRuleByLocation(i,n,t,a);return l?new Promise(u=>{this._sheetDataValidationModel.validator(l,{unitId:i,subUnitId:n,row:t,col:a,worksheet:e,workbook:s},d=>{u(d)})}):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)}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}`);return Promise.all(t.map(n=>{const l=[];return r.Range.foreach(n,(u,d)=>{l.push(this._validatorByCell(a,i,u,d))}),Promise.all(l)}))}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))}),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=vt([ne(0,r.IUniverInstanceService),ne(1,r.Inject(m.SheetDataValidationModel)),ne(2,r.Inject(m.DataValidationCacheService)),ne(3,r.Inject(r.LifecycleService))],m.SheetsDataValidationValidatorService);var Rt=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,Dt=(o,s,e)=>s in o?Rt(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e,Mt=(o,s,e,t)=>{for(var a=t>1?void 0:t?Vt(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),je=(o,s,e)=>Dt(o,typeof s!="symbol"?s+"":s,e);m.UniverSheetsDataValidationPlugin=class extends r.Plugin{constructor(s=Ne,e,t,a){super(),this._config=s,this._injector=e,this._commandService=t,this._configService=a;const{...i}=r.merge({},Ne,this._config);this._configService.setConfig(rt,i)}onStarting(){[[m.DataValidationCacheService],[m.DataValidationFormulaService],[m.DataValidationCustomFormulaService],[m.SheetsDataValidationValidatorService],[m.SheetDataValidationModel],[re],[m.DataValidationFormulaController],[ie],[ae],[te]].forEach(s=>{this._injector.add(s)}),[Ie,Fe,Ce,Ae,Le,we,Ue].forEach(s=>{this._commandService.registerCommand(s)}),this._injector.get(m.DataValidationCacheService),this._injector.get(m.SheetsDataValidationValidatorService),this._injector.get(re),this._injector.get(te),this._injector.get(ae)}onReady(){this._injector.get(ie)}onRendered(){this._injector.get(m.DataValidationFormulaController)}},je(m.UniverSheetsDataValidationPlugin,"pluginName",Re),je(m.UniverSheetsDataValidationPlugin,"type",r.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsDataValidationPlugin=Mt([r.DependentOn(p.UniverDataValidationPlugin),Se(1,r.Inject(r.Injector)),Se(2,r.ICommandService),Se(3,r.IConfigService)],m.UniverSheetsDataValidationPlugin);function Et(o){const e=o.get(D.SheetsSelectionsService).getCurrentSelections().map(i=>i.range);return{uid:r.Tools.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 yt="data-validation.custom-formula-input",Tt="data-validation.formula-input",Ot="data-validation.list-formula-input",Ft="data-validation.checkbox-formula-input";m.AddSheetDataValidationCommand=Ie,m.BASE_FORMULA_INPUT_NAME=Tt,m.CHECKBOX_FORMULA_1=$,m.CHECKBOX_FORMULA_2=k,m.CHECKBOX_FORMULA_INPUT_NAME=Ft,m.CUSTOM_FORMULA_INPUT_NAME=yt,m.CheckboxValidator=Ee,m.ClearRangeDataValidationCommand=Ue,m.DATA_VALIDATION_PLUGIN_NAME=Re,m.DateValidator=Te,m.LIST_FORMULA_INPUT_NAME=Ot,m.ListMultipleValidator=Be,m.ListValidator=he,m.RemoveSheetAllDataValidationCommand=we,m.RemoveSheetDataValidationCommand=Le,m.UpdateSheetDataValidationOptionsCommand=Ae,m.UpdateSheetDataValidationRangeCommand=Fe,m.UpdateSheetDataValidationSettingCommand=Ce,m.createDefaultNewRule=Et,m.deserializeListOptions=G,m.getCellValueNumber=X,m.getCellValueOrigin=L,m.getDataValidationCellValue=ze,m.getDataValidationDiffMutations=K,m.getFormulaCellData=j,m.getFormulaResult=w,m.getTransformedFormula=Y,m.isLegalFormulaResult=E,m.serializeListOptions=Ke,m.transformCheckboxValue=x,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
// @univerjs/sheets-data-validation/facade
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
// @univerjs/sheets-data-validation-ui/index
|
|
14
|
-
(function(L,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/sheets-data-validation"),require("react/jsx-runtime"),require("@univerjs/design"),require("@univerjs/ui"),require("react"),require("@univerjs/sheets-formula-ui"),require("@univerjs/data-validation"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-data-validation","react/jsx-runtime","@univerjs/design","@univerjs/ui","react","@univerjs/sheets-formula-ui","@univerjs/data-validation","rxjs","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/engine-formula"],o):(L=typeof globalThis<"u"?globalThis:L||self,o(L.UniverSheetsDataValidationUi={},L.UniverCore,L.UniverSheetsDataValidation,L.React,L.UniverDesign,L.UniverUi,L.React,L.UniverSheetsFormulaUi,L.UniverDataValidation,L.rxjs,L.UniverEngineRender,L.UniverSheets,L.UniverSheetsNumfmt,L.UniverSheetsUi,L.UniverEngineFormula))})(this,function(L,o,f,v,M,b,V,Ke,Y,te,N,$,Nt,H,Ge){"use strict";var ur=Object.defineProperty;var hr=(L,o,f)=>o in L?ur(L,o,{enumerable:!0,configurable:!0,writable:!0,value:f}):L[o]=f;var R=(L,o,f)=>hr(L,typeof o!="symbol"?o+"":o,f);var Xe,ze;const Ut=e=>{const{isTwoFormula:t=!1,value:r,onChange:n,showError:a,validResult:i}=e,s=b.useDependency(o.LocaleService),d=a?i==null?void 0:i.formula1:"",l=a?i==null?void 0:i.formula2:"";return t?v.jsxs(v.Fragment,{children:[v.jsx(M.FormLayout,{error:d,children:v.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:r==null?void 0:r.formula1,onChange:c=>{n==null||n({...r,formula1:c})}})}),v.jsx("div",{className:"-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400",children:s.t("dataValidation.panel.formulaAnd")}),v.jsx(M.FormLayout,{error:l,children:v.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:r==null?void 0:r.formula2,onChange:c=>{n==null||n({...r,formula2:c})}})})]}):v.jsx(M.FormLayout,{error:d,children:v.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:r==null?void 0:r.formula1,onChange:c=>{n==null||n({formula1:c})}})})};function Ft(e){const{value:t,onChange:r,showError:n,validResult:a}=e,i=b.useDependency(o.LocaleService),s=n?a==null?void 0:a.formula1:"",d=n?a==null?void 0:a.formula2:"",[l,c]=V.useState(!((t==null?void 0:t.formula1)===void 0&&(t==null?void 0:t.formula2)===void 0));return v.jsxs(v.Fragment,{children:[v.jsx(M.FormLayout,{children:v.jsx(M.Checkbox,{checked:l,onChange:h=>{h?c(!0):(c(!1),r==null||r({...t,formula1:void 0,formula2:void 0}))},children:i.t("dataValidation.checkbox.tips")})}),l?v.jsx(M.FormLayout,{label:i.t("dataValidation.checkbox.checked"),error:s,children:v.jsx(M.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula1,onChange:h=>{r==null||r({...t,formula1:h||void 0})}})}):null,l?v.jsx(M.FormLayout,{label:i.t("dataValidation.checkbox.unchecked"),error:d,children:v.jsx(M.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula2,onChange:h=>{r==null||r({...t,formula2:h||void 0})}})}):null]})}function kt(e){var p;const{unitId:t,subUnitId:r,value:n,onChange:a,showError:i,validResult:s}=e,d=i?s==null?void 0:s.formula1:void 0,l=V.useRef(null),[c,h]=V.useState(!1);return b.useSidebarClick(u=>{var g;((g=l.current)==null?void 0:g.isClickOutSide(u))&&h(!1)}),v.jsx(M.FormLayout,{error:d,children:v.jsx(Ke.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 [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent dark:univer-bg-gray-700 dark:univer-text-white hover:univer-border-primary-600",M.borderClassName),initValue:(p=n==null?void 0:n.formula1)!=null?p:"=",unitId:t,subUnitId:r,isFocus:c,isSupportAcrossSheet:!0,onChange:u=>{const _=(u!=null?u:"").trim();_!==(n==null?void 0:n.formula1)&&(a==null||a({...n,formula1:_}))},onFocus:()=>h(!0)})})}var ne=function(){return ne=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},ne.apply(this,arguments)},jt=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]]);return r},ge=V.forwardRef(function(e,t){var r=e.icon,n=e.id,a=e.className,i=e.extend,s=jt(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(a||"").trim(),l=V.useRef("_".concat(Wt()));return pt(r,"".concat(n),{defIds:r.defIds,idSuffix:l.current},ne({ref:t,className:d},s),i)});function pt(e,t,r,n,a){return V.createElement(e.tag,ne(ne({key:t},Bt(e,r,a)),n),(Ht(e,r).children||[]).map(function(i,s){return pt(i,"".concat(t,"-").concat(e.tag,"-").concat(s),r,void 0,a)}))}function Bt(e,t,r){var n=ne({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(i){var s=i[0],d=i[1];s==="mask"&&typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var a=t.defIds;return!a||a.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(i){var s=i[0],d=i[1];typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Ht(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?ne(ne({},e),{children:e.children.map(function(a){return typeof a.attrs.id=="string"&&n&&n.indexOf(a.attrs.id)>-1?ne(ne({},a),{attrs:ne(ne({},a.attrs),{id:a.attrs.id+t.idSuffix})}):a})}):e}function Wt(){return Math.random().toString(36).substring(2,8)}ge.displayName="UniverIcon";var xt={tag:"svg",attrs:{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.83062 8.94447 3.57605 9.32281 3.54166 9.57737 3.7538L11.154 5.06767 13.769 2.45278C14.0033 2.21847 14.3832 2.21848 14.6175 2.45279zM14.1175 9.19746C14.3518 9.43178 14.3518 9.81168 14.1175 10.046L12.5418 11.6217 14.1175 13.1975C14.3518 13.4318 14.3518 13.8117 14.1175 14.046 13.8832 14.2803 13.5033 14.2803 13.269 14.046L11.6933 12.4703 10.1175 14.046C9.88321 14.2803 9.50331 14.2803 9.269 14.046 9.03468 13.8117 9.03468 13.4318 9.269 13.1975L10.8447 11.6217 9.269 10.046C9.03468 9.81168 9.03468 9.43178 9.269 9.19746 9.50331 8.96315 9.88321 8.96315 10.1175 9.19746L11.6933 10.7732 13.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"}}]},gt=V.forwardRef(function(e,t){return V.createElement(ge,Object.assign({},e,{id:"data-validation-single",ref:t,icon:xt}))});gt.displayName="DataValidationSingle";var $t={tag:"svg",attrs:{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.866699 5.9313.866699H10.069C10.4004.866699 10.669 1.13533 10.669 1.4667 10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667zM1.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.64443 14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443zM6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928 9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171 10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778 9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539 9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263 6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539 5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778 6.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"}}]},qe=V.forwardRef(function(e,t){return V.createElement(ge,Object.assign({},e,{id:"delete-single",ref:t,icon:$t}))});qe.displayName="DeleteSingle";var Yt={tag:"svg",attrs:{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"}}]},ft=V.forwardRef(function(e,t){return V.createElement(ge,Object.assign({},e,{id:"increase-single",ref:t,icon:Yt}))});ft.displayName="IncreaseSingle";var Xt={tag:"svg",attrs:{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"}}]},Ze=V.forwardRef(function(e,t){return V.createElement(ge,Object.assign({},e,{id:"more-down-single",ref:t,icon:Xt}))});Ze.displayName="MoreDownSingle";var zt={tag:"svg",attrs:{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"}}]},mt=V.forwardRef(function(e,t){return V.createElement(ge,Object.assign({},e,{id:"more-up-single",ref:t,icon:zt}))});mt.displayName="MoreUpSingle";var Kt={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_622_8",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_622_8)"},children:[{tag:"path",attrs:{d:"M6 5C6.55228 5 7 4.55228 7 4 7 3.44772 6.55228 3 6 3 5.44772 3 5 3.44772 5 4 5 4.55228 5.44772 5 6 5zM6 9C6.55228 9 7 8.55229 7 8 7 7.44772 6.55228 7 6 7 5.44772 7 5 7.44772 5 8 5 8.55229 5.44772 9 6 9zM7 12C7 12.5523 6.55228 13 6 13 5.44772 13 5 12.5523 5 12 5 11.4477 5.44772 11 6 11 6.55228 11 7 11.4477 7 12zM10 5C10.5523 5 11 4.55228 11 4 11 3.44772 10.5523 3 10 3 9.44771 3 9 3.44772 9 4 9 4.55228 9.44771 5 10 5zM11 8C11 8.55229 10.5523 9 10 9 9.44771 9 9 8.55229 9 8 9 7.44772 9.44771 7 10 7 10.5523 7 11 7.44772 11 8zM10 13C10.5523 13 11 12.5523 11 12 11 11.4477 10.5523 11 10 11 9.44771 11 9 11.4477 9 12 9 12.5523 9.44771 13 10 13z"}}]}]},St=V.forwardRef(function(e,t){return V.createElement(ge,Object.assign({},e,{id:"sequence-single",ref:t,icon:Kt}))});St.displayName="SequenceSingle";const Ce="#ECECEC",Gt=["#FFFFFF","#FEE7E7","#FEF0E6","#EFFBD0","#E4F4FE","#E8ECFD","#F1EAFA","#FDE8F3","#E5E5E5","#FDCECE","#FDC49B","#DEF6A2","#9FDAFF","#D0D9FB","#E3D5F6","#FBD0E8","#656565","#FE4B4B","#FF8C51","#8BBB11","#0B9EFB","#3A60F7","#9E6DE3","#F248A6"],qt=e=>{const{value:t,onChange:r,disabled:n}=e,[a,i]=V.useState(!1);return v.jsx(M.Dropdown,{align:"start",disabled:n,open:a,onOpenChange:i,overlay:v.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:Gt.map(s=>v.jsx("div",{className:M.clsx("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded",M.borderClassName),style:{background:s},onClick:()=>{r(s),i(!1)}},s))}),children:v.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 dark:univer-bg-gray-700 dark:univer-text-white hover:univer-border-primary-600",M.borderClassName),children:[v.jsx("div",{className:"univer-box-border univer-h-4 univer-w-4 univer-rounded univer-text-base",style:{background:t}}),v.jsx(Ze,{})]})})},_t=e=>{const{item:t,commonProps:r,style:n}=e,{onItemChange:a,onItemDelete:i}=r;return v.jsxs("div",{className:"univer-flex univer-items-center univer-gap-2",style:n,children:[t.isRef?null:v.jsx("div",{className:M.clsx("univer-cursor-move","draggableHandle"),children:v.jsx(St,{})}),v.jsx(qt,{value:t.color,onChange:s=>{a(t.id,t.label,s)}}),v.jsx(M.Input,{disabled:t.isRef,value:t.label,onChange:s=>{a(t.id,s,t.color)}}),t.isRef?null:v.jsx("div",{className:"univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",children:v.jsx(qe,{onClick:()=>i(t.id)})})]})};function Zt(e){const{value:t,onChange:r=()=>{},unitId:n,subUnitId:a,validResult:i,showError:s,ruleId:d}=e,{formula1:l="",formula2:c=""}=t||{},[h,p]=V.useState(()=>o.isFormulaString(l)?"1":"0"),[u,_]=V.useState(h==="1"?l:"="),[g,O]=V.useState(h==="1"?l:"="),T=b.useDependency(o.LocaleService),m=b.useDependency(Y.DataValidatorRegistryService),C=b.useDependency(Y.DataValidationModel),S=b.useDependency(f.DataValidationFormulaController),[y,D]=V.useState(()=>c.split(",")),w=m.getValidatorItem(o.DataValidationType.LIST),[E,F]=V.useState([]),[x,P]=V.useState(""),k=s?i==null?void 0:i.formula1:"",j=V.useMemo(()=>C.ruleChange$.pipe(te.debounceTime(16)),[]),B=b.useObservable(j),A=b.useEvent(r);V.useEffect(()=>{(async()=>{await new Promise(I=>{setTimeout(()=>I(!0),100)});const U=C.getRuleById(n,a,d),G=U==null?void 0:U.formula1;if(o.isFormulaString(G)&&w&&U){const I=await w.getListAsync(U,n,a);F(I)}})()},[C,B,w,d,a,n]),V.useEffect(()=>{o.isFormulaString(l)&&l!==g&&(_(l),O(g))},[g,l]);const[X,z]=V.useState(()=>{const U=h!=="1"?f.deserializeListOptions(l):[],G=c.split(",");return U.map((I,W)=>({label:I,color:G[W]||Ce,isRef:!1,id:o.Tools.generateRandomId(4)}))}),Z=(U,G,I)=>{const W=X.find(K=>K.id===U);W&&(W.label=G,W.color=I,z([...X]))},Q=U=>{const G=X.findIndex(I=>I.id===U);G!==-1&&(X.splice(G,1),z([...X]))},J=c.split(","),re=V.useMemo(()=>E.map((U,G)=>({label:U,color:J[G]||Ce,id:`${G}`,isRef:!0})),[J,E]),ue=(U,G,I)=>{const W=[...y];W[+U]=I,D(W),A({formula1:l,formula2:W.join(",")})},se=()=>{z([...X,{label:"",color:Ce,isRef:!1,id:o.Tools.generateRandomId(4)}])};V.useEffect(()=>{if(h==="1")return;const U=new Set,G=[];X.map(I=>({labelList:I.label.split(","),item:I})).forEach(({item:I,labelList:W})=>{W.forEach(K=>{U.has(K)||(U.add(K),G.push({label:K,color:I.color}))})}),A({formula1:f.serializeListOptions(G.map(I=>I.label)),formula2:G.map(I=>I.color===Ce?"":I.color).join(",")})},[X,A,h,g,y]);const ae=b.useEvent(async U=>{if(!o.isFormulaString(U)){A==null||A({formula1:"",formula2:c});return}S.getFormulaRefCheck(U)?(A==null||A({formula1:o.isFormulaString(U)?U:"",formula2:c}),P("")):(A==null||A({formula1:"",formula2:c}),_("="),P(T.t("dataValidation.validFail.formulaError")))}),le=V.useRef(null),[ve,he]=V.useState(!1);return b.useSidebarClick(U=>{var I;((I=le.current)==null?void 0:I.isClickOutSide(U))&&he(!1)}),v.jsxs(v.Fragment,{children:[v.jsx(M.FormLayout,{label:T.t("dataValidation.list.options"),children:v.jsxs(M.RadioGroup,{value:h,onChange:U=>{p(U),_(g),U==="1"&&A({formula1:g==="="?"":g,formula2:y.join(",")})},children:[v.jsx(M.Radio,{value:"0",children:T.t("dataValidation.list.customOptions")}),v.jsx(M.Radio,{value:"1",children:T.t("dataValidation.list.refOptions")})]})}),h==="1"?v.jsxs(M.FormLayout,{error:k||x||void 0,children:[v.jsx(Ke.FormulaEditor,{ref:le,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 [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent dark:univer-bg-gray-700 dark:univer-text-white hover:univer-border-primary-600",M.borderClassName),initValue:u,unitId:n,subUnitId:a,isFocus:ve,isSupportAcrossSheet:!0,onFocus:()=>he(!0),onChange:(U="")=>{const G=(U!=null?U:"").trim();O(G),ae(G)}}),re.length>0&&v.jsx("div",{style:{marginTop:"12px"},children:re.map(U=>v.jsx(_t,{item:U,commonProps:{onItemChange:ue},style:{marginBottom:12}},U.id))})]}):v.jsx(M.FormLayout,{error:k,children:v.jsxs("div",{style:{marginTop:"-12px"},children:[v.jsx(M.DraggableList,{list:X,onListChange:z,rowHeight:28,margin:[0,12],draggableHandle:".draggableHandle",itemRender:U=>v.jsx(_t,{item:U,commonProps:{onItemChange:Z,onItemDelete:Q}},U.id),idKey:"id"}),v.jsxs("a",{className:"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 univer-text-primary hover:univer-bg-primary-50",onClick:se,children:[v.jsx(ft,{className:"univer-mr-1"}),T.t("dataValidation.list.add")]})]})})]})}const Jt=[[f.CUSTOM_FORMULA_INPUT_NAME,kt],[f.BASE_FORMULA_INPUT_NAME,Ut],[f.LIST_FORMULA_INPUT_NAME,Zt],[f.CHECKBOX_FORMULA_INPUT_NAME,Ft]];var Qt=Object.getOwnPropertyDescriptor,en=(e,t,r,n)=>{for(var a=n>1?void 0:n?Qt(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},tn=(e,t)=>(r,n)=>t(r,n,e);L.BaseSheetDataValidatorView=class{constructor(t){R(this,"canvasRender",null);R(this,"dropdownType");R(this,"optionsInput");R(this,"formulaInput",f.LIST_FORMULA_INPUT_NAME);this.injector=t}},L.BaseSheetDataValidatorView=en([tn(0,o.Inject(o.Injector))],L.BaseSheetDataValidatorView);var nn=Object.getOwnPropertyDescriptor,rn=(e,t,r,n)=>{for(var a=n>1?void 0:n?nn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},It=(e,t)=>(r,n)=>t(r,n,e);let de=class extends o.Disposable{constructor(t,r){super();R(this,"_open$",new te.BehaviorSubject(!1));R(this,"open$",this._open$.pipe(te.distinctUntilChanged()));R(this,"_activeRule");R(this,"_activeRule$",new te.BehaviorSubject(void 0));R(this,"activeRule$",this._activeRule$.asObservable());R(this,"_closeDisposable",null);this._univerInstanceService=t,this._sidebarService=r,this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).pipe(te.filter(n=>!n)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(n=>{n.id===Ne&&(n.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)}};de=rn([It(0,o.IUniverInstanceService),It(1,b.ISidebarService)],de);const Je="sheets-data-validation-ui.config",Le={};var an=Object.getOwnPropertyDescriptor,on=(e,t,r,n)=>{for(var a=n>1?void 0:n?an(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ye=(e,t)=>(r,n)=>t(r,n,e);let we=class extends o.Disposable{constructor(e,t,r,n,a,i){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=r,this._dialogService=n,this._localeService=a,this._sheetsDataValidationValidatorService=i,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this._sheetInterceptorService.writeCellInterceptor.intercept($.VALIDATE_CELL,{handler:async(e,t,r)=>{const n=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(n===!1)return r(Promise.resolve(!1));if(!c||c.errorStyle!==o.DataValidationErrorStyle.STOP)return r(Promise.resolve(!0));const h=this._dataValidatorRegistryService.getValidatorItem(c.type);return!h||await this._sheetsDataValidationValidatorService.validatorCell(s,d,a,i)===o.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:h.getRuleFinalError(c,{row:a,col:i,unitId:s,subUnitId:d})},footer:{title:V.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")}}),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:V.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")}})}};we=on([ye(0,o.Inject($.SheetInterceptorService)),ye(1,o.Inject(f.SheetDataValidationModel)),ye(2,o.Inject(Y.DataValidatorRegistryService)),ye(3,b.IDialogService),ye(4,o.Inject(o.LocaleService)),ye(5,o.Inject(f.SheetsDataValidationValidatorService))],we);var sn=Object.getOwnPropertyDescriptor,ln=(e,t,r,n)=>{for(var a=n>1?void 0:n?sn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ie=(e,t)=>(r,n)=>t(r,n,e);const Qe=e=>{if(e==null||typeof e=="boolean")return;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 dn(e,t){const r=Nt.getPatternType(t);if(e===r)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 fe=class extends o.Disposable{constructor(t,r,n,a,i,s,d,l,c,h,p){super();R(this,"_activeDropdown");R(this,"_activeDropdown$",new te.Subject);R(this,"_currentPopup",null);R(this,"activeDropdown$",this._activeDropdown$.asObservable());R(this,"_zenVisible",!1);this._univerInstanceService=t,this._dataValidatorRegistryService=r,this._zenZoneService=n,this._dataValidationModel=a,this._sheetsSelectionsService=i,this._cellDropdownManagerService=s,this._sheetDataValidationModel=d,this._commandService=l,this._editorBridgeService=c,this._injector=h,this._configService=p,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,r,n,a){const i=t?this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!i)return;const s=r?i.getSheetBySheetId(r):i.getActiveSheet();if(!s)return;const d=this._dataValidationModel.getRuleByLocation(i.getUnitId(),s.getSheetId(),n,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(r=>!(r.primary&&this._getDropdownByCell(r.primary.unitId,r.primary.sheetId,r.primary.actualRow,r.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){var O,T,m,C;const{location:r}=t,{row:n,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=r;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);const c=this._sheetDataValidationModel.getRuleByLocation(i,s,n,a);if(!c)return;const h=this._dataValidatorRegistryService.getValidatorItem(c.type);if(!(h!=null&&h.dropdownType))return;let p;const u=async(S,y)=>{var j,B,A;if(!S)return!0;const D=S,w=l.getCell(n,a),E=D.format(y==="date"?"YYYY-MM-DD 00:00:00":"YYYY-MM-DD HH:mm:ss"),F=(j=o.numfmt.parseDate(E))==null?void 0:j.v,x=y==="time"?F%1:F,P=d.getStyles().getStyleByCell(w),k=(A=(B=P==null?void 0:P.n)==null?void 0:B.pattern)!=null?A:"";return c.errorStyle!==o.DataValidationErrorStyle.STOP||await h.validator({value:x,unitId:i,subUnitId:s,row:n,column:a,worksheet:l,workbook:d,interceptValue:E.replace("Z","").replace("T"," "),t:o.CellValueType.NUMBER},c)?(await this._commandService.executeCommand(H.SetCellEditVisibleOperation.id,{visible:!1,eventType:N.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),await this._commandService.executeCommand($.SetRangeValuesCommand.id,{unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:n,endRow:n},value:{v:x,t:2,p:null,f:null,si:null,s:{n:{pattern:dn(y,k)}}}}),!0):(this._injector.has(we)&&this._injector.get(we).showReject(h.getRuleFinalError(c,{row:n,col:a,unitId:i,subUnitId:s})),!1)};let _;switch(h.dropdownType){case Y.DataValidatorDropdownType.DATE:{const S=f.getCellValueOrigin(l.getCellRaw(n,a)),y=Qe(S),D=!!((O=c.bizInfo)!=null&&O.showTime);_={location:r,type:"datepicker",props:{showTime:D,onChange:w=>u(w,D?"datetime":"date"),defaultValue:y,patternType:"date"}};break}case Y.DataValidatorDropdownType.TIME:{const S=f.getCellValueOrigin(l.getCellRaw(n,a)),y=Qe(S);_={location:r,type:"datepicker",props:{onChange:D=>u(D,"time"),defaultValue:y,patternType:"time"}};break}case Y.DataValidatorDropdownType.DATETIME:{const S=f.getCellValueOrigin(l.getCellRaw(n,a)),y=Qe(S);_={location:r,type:"datepicker",props:{onChange:D=>u(D,"datetime"),defaultValue:y,patternType:"datetime"}};break}case Y.DataValidatorDropdownType.LIST:case Y.DataValidatorDropdownType.MULTIPLE_LIST:{const S=h.dropdownType===Y.DataValidatorDropdownType.MULTIPLE_LIST,y=async P=>{const k=f.serializeListOptions(P),j={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:n,endRow:n},value:{v:k,p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(H.SetCellEditVisibleOperation.id,{visible:!1,eventType:N.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),this._commandService.executeCommand($.SetRangeValuesCommand.id,j),!S},D=(c==null?void 0:c.renderMode)===o.DataValidationRenderMode.CUSTOM||(c==null?void 0:c.renderMode)===void 0,w=h.getListWithColor(c,i,s),E=f.getDataValidationCellValue(l.getCellRaw(n,a)),F=()=>{this._commandService.executeCommand(me.id,{ruleId:c.uid}),p==null||p.dispose()},x=w.map(P=>({label:P.label,value:P.label,color:D||P.color?P.color:"transparent"}));_={location:r,type:"list",props:{onChange:P=>y(P),options:x,onEdit:F,defaultValue:E,multiple:S,showEdit:(m=(T=this._configService.getConfig(Je))==null?void 0:T.showEditOnDropdown)!=null?m:!0}};break}case Y.DataValidatorDropdownType.CASCADE:{_={type:"cascader",props:{onChange:y=>{const D={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:n,endRow:n},value:{v:y.join("/"),p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(H.SetCellEditVisibleOperation.id,{visible:!1,eventType:N.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),this._commandService.syncExecuteCommand($.SetRangeValuesCommand.id,D),!0},defaultValue:f.getDataValidationCellValue(l.getCellRaw(n,a)).split("/"),options:JSON.parse((C=c.formula1)!=null?C:"[]")},location:r};break}case Y.DataValidatorDropdownType.COLOR:{_={type:"color",props:{onChange:y=>{const D={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:n,endRow:n},value:{v:y,p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(H.SetCellEditVisibleOperation.id,{visible:!1,eventType:N.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),this._commandService.syncExecuteCommand($.SetRangeValuesCommand.id,D),!0},defaultValue:f.getDataValidationCellValue(l.getCellRaw(n,a))},location:r};break}default:throw new Error("[DataValidationDropdownManagerService]: unknown type!")}if(p=this._cellDropdownManagerService.showDropdown(_),!p)throw new Error("[DataValidationDropdownManagerService]: cannot show dropdown!");const g=new o.DisposableCollection;g.add(p),g.add({dispose:()=>{var S,y;(y=(S=this._activeDropdown)==null?void 0:S.onHide)==null||y.call(S)}}),this._currentPopup=g}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(t,r,n,a,i){const s=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!s)return;const d=s.getSheetBySheetId(r);if(!d)return;const l=this._dataValidationModel.getRuleByLocation(s.getUnitId(),d.getSheetId(),n,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:n,col:a,unitId:t,subUnitId:r},onHide:i})}};fe=ln([ie(0,o.IUniverInstanceService),ie(1,o.Inject(Y.DataValidatorRegistryService)),ie(2,b.IZenZoneService),ie(3,o.Inject(f.SheetDataValidationModel)),ie(4,o.Inject($.SheetsSelectionsService)),ie(5,o.Inject(H.ISheetCellDropdownManagerService)),ie(6,o.Inject(f.SheetDataValidationModel)),ie(7,o.ICommandService),ie(8,H.IEditorBridgeService),ie(9,o.Inject(o.Injector)),ie(10,o.IConfigService)],fe);const Ne="DataValidationPanel",me={id:"data-validation.operation.open-validation-panel",type:o.CommandType.OPERATION,handler(e,t){if(!t)return!1;const{ruleId:r,isAdd:n}=t,a=e.get(de),i=e.get(Y.DataValidationModel),s=e.get(o.IUniverInstanceService),d=e.get(b.ISidebarService),l=$.getSheetCommandTarget(s);if(!l)return!1;const{unitId:c,subUnitId:h}=l,p=r?i.getRuleById(c,h,r):void 0;a.open(),a.setActiveRule(p&&{unitId:c,subUnitId:h,rule:p});const u=d.open({id:Ne,header:{title:n?"dataValidation.panel.addTitle":"dataValidation.panel.title"},children:{label:Ne},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(de).close(),!0}},Ct={id:"data-validation.operation.toggle-validation-panel",type:o.CommandType.OPERATION,handler(e){const t=e.get(o.ICommandService),r=e.get(de);return r.open(),r.isOpen?t.executeCommand(et.id):t.executeCommand(me.id),!0}},Ue={type:o.CommandType.OPERATION,id:"sheet.operation.show-data-validation-dropdown",handler(e,t){if(!t)return!1;const r=e.get(fe),{unitId:n,subUnitId:a,row:i,column:s}=t,d=r.activeDropdown,l=d==null?void 0:d.location;return l&&l.unitId===n&&l.subUnitId===a&&l.row===i&&l.col===s||r.showDataValidationDropdown(n,a,i,s),!0}},yt={type:o.CommandType.OPERATION,id:"sheet.operation.hide-data-validation-dropdown",handler(e,t){return t?(e.get(fe).hideDropdown(),!0):!1}},Fe={type:o.CommandType.COMMAND,id:"data-validation.command.addRuleAndOpen",handler(e){const t=e.get(o.IUniverInstanceService),r=$.getSheetCommandTarget(t);if(!r)return!1;const{workbook:n,worksheet:a}=r,i=f.createDefaultNewRule(e),s=e.get(o.ICommandService),d=n.getUnitId(),l=a.getSheetId(),c={rule:i,unitId:d,subUnitId:l};return s.syncExecuteCommand(f.AddSheetDataValidationCommand.id,c)?(s.syncExecuteCommand(me.id,{ruleId:i.uid,isAdd:!0}),!0):!1}};var cn=Object.getOwnPropertyDescriptor,un=(e,t,r,n)=>{for(var a=n>1?void 0:n?cn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},De=(e,t)=>(r,n)=>t(r,n,e);const Se="SHEET_DATA_VALIDATION_ALERT";let Pe=class extends o.Disposable{constructor(e,t,r,n,a,i){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=r,this._localeService=n,this._zenZoneService=a,this._dataValidationModel=i,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(te.debounceTime(100)).subscribe(e=>{var t;if(e){const r=this._univerInstanceService.getUnit(e.location.unitId,o.UniverInstanceType.UNIVER_SHEET),n=r.getSheetBySheetId(e.location.subUnitId);if(!n)return;const a=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!a){this._cellAlertManagerService.removeAlert(Se);return}if(this._dataValidationModel.validator(a,{...e.location,workbook:r,worksheet:n})===o.DataValidationStatus.INVALID){const s=this._cellAlertManagerService.currentAlert.get(Se),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(Se);return}const l=this._dataValidationModel.getValidator(a.type);if(!l){this._cellAlertManagerService.removeAlert(Se);return}this._cellAlertManagerService.showAlert({type:H.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:Se});return}}this._cellAlertManagerService.removeAlert(Se)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(Se)}))}};Pe=un([De(0,o.Inject(H.HoverManagerService)),De(1,o.Inject(H.CellAlertManagerService)),De(2,o.IUniverInstanceService),De(3,o.Inject(o.LocaleService)),De(4,b.IZenZoneService),De(5,o.Inject(f.SheetDataValidationModel))],Pe);var hn=Object.getOwnPropertyDescriptor,vn=(e,t,r,n)=>{for(var a=n>1?void 0:n?hn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},tt=(e,t)=>(r,n)=>t(r,n,e);let Ee=class extends o.Disposable{constructor(e,t,r){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=r,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),t=(n,a)=>{const{source:i,target:s,unitId:d,subUnitId:l}=n,c=this._sheetDataValidationModel.getRuleObjectMatrix(d,l).clone(),h=H.virtualizeDiscreteRanges([i,s]),[p,u]=h.ranges,{mapFunc:_}=h,g={row:p.startRow,col:p.startColumn},O=H.getAutoFillRepeatRange(p,u),T=new o.ObjectMatrix,m=new Set;O.forEach(w=>{const E=w.repeatStartCell,F=w.relativeRange,x={startRow:g.row,startColumn:g.col,endColumn:g.col,endRow:g.row},P={startRow:E.row,startColumn:E.col,endColumn:E.col,endRow:E.row};o.Range.foreach(F,(k,j)=>{const B=o.Rectangle.getPositionRange({startRow:k,startColumn:j,endColumn:j,endRow:k},x),{row:A,col:X}=_(B.startRow,B.startColumn),z=this._sheetDataValidationModel.getRuleIdByLocation(d,l,A,X)||"",Z=o.Rectangle.getPositionRange({startRow:k,startColumn:j,endColumn:j,endRow:k},P),{row:Q,col:J}=_(Z.startRow,Z.startColumn);T.setValue(Q,J,z),m.add(z)})});const C=Array.from(m).map(w=>({id:w,ranges:o.queryObjectMatrix(T,E=>E===w)}));c.addRangeRules(C);const S=c.diff(this._sheetDataValidationModel.getRules(d,l)),{redoMutations:y,undoMutations:D}=f.getDataValidationDiffMutations(d,l,S,this._injector,"patched",a===H.APPLY_TYPE.ONLY_FORMAT);return{undos:D,redos:y}},r={id:f.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:n=>{const{source:a,unitId:i,subUnitId:s}=n;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(H.APPLY_TYPE.SERIES,!0);return}}},onFillData:(n,a,i)=>i===H.APPLY_TYPE.COPY||i===H.APPLY_TYPE.ONLY_FORMAT||i===H.APPLY_TYPE.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(r))}};Ee=vn([tt(0,H.IAutoFillService),tt(1,o.Inject(f.SheetDataValidationModel)),tt(2,o.Inject(o.Injector))],Ee);var pn=Object.getOwnPropertyDescriptor,gn=(e,t,r,n)=>{for(var a=n>1?void 0:n?pn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},nt=(e,t)=>(r,n)=>t(r,n,e);let Me=class extends o.Disposable{constructor(t,r,n){super();R(this,"_copyInfo");this._sheetClipboardService=t,this._sheetDataValidationModel=r,this._injector=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:f.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(t,r,n)=>this._collect(t,r,n),onPasteCells:(t,r,n,a)=>{const{copyType:i=H.COPY_TYPE.COPY,pasteType:s}=a,{range:d}=t||{},{range:l,unitId:c,subUnitId:h}=r;return this._generateMutations(l,{copyType:i,pasteType:s,copyRange:d,unitId:c,subUnitId:h})}})}_collect(t,r,n){const a=new o.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:r,matrix:a};const i=this._injector.invoke(l=>$.rangeToDiscreteRange(n,l,t,r));if(!i)return;const{rows:s,cols:d}=i;s.forEach((l,c)=>{d.forEach((h,p)=>{const u=this._sheetDataValidationModel.getRuleIdByLocation(t,r,l,h);a.setValue(c,p,u!=null?u:"")})})}_generateMutations(t,r){if(!this._copyInfo)return{redos:[],undos:[]};if(r.copyType===H.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!r.copyRange)return{redos:[],undos:[]};if([H.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,H.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,H.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,H.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{unitId:a,subUnitId:i}=this._copyInfo;if(r.unitId!==a||i!==r.subUnitId){const s=this._sheetDataValidationModel.getRuleObjectMatrix(r.unitId,r.subUnitId).clone(),d=new o.ObjectMatrix,l=new Set,{ranges:[c,h],mapFunc:p}=H.virtualizeDiscreteRanges([r.copyRange,t]),u=H.getRepeatRange(c,h,!0),_=new Map;u.forEach(({startRange:m})=>{var C;(C=this._copyInfo)==null||C.matrix.forValue((S,y,D)=>{const w=o.Rectangle.getPositionRange({startRow:S,endRow:S,startColumn:y,endColumn:y},m),E=`${i}-${D}`,F=this._sheetDataValidationModel.getRuleById(a,i,D);!this._sheetDataValidationModel.getRuleById(r.unitId,r.subUnitId,E)&&F&&_.set(E,{...F,uid:E});const{row:x,col:P}=p(w.startRow,w.startColumn);l.add(E),d.setValue(x,P,E)})});const g=Array.from(l).map(m=>({id:m,ranges:o.queryObjectMatrix(d,C=>C===m)}));s.addRangeRules(g);const{redoMutations:O,undoMutations:T}=f.getDataValidationDiffMutations(r.unitId,r.subUnitId,s.diffWithAddition(this._sheetDataValidationModel.getRules(r.unitId,r.subUnitId),_.values()),this._injector,"patched",!1);return{redos:O,undos:T}}else{const s=this._sheetDataValidationModel.getRuleObjectMatrix(a,i).clone(),d=new o.ObjectMatrix,l=new Set,{ranges:[c,h],mapFunc:p}=H.virtualizeDiscreteRanges([r.copyRange,t]);H.getRepeatRange(c,h,!0).forEach(({startRange:T})=>{var m;(m=this._copyInfo)==null||m.matrix.forValue((C,S,y)=>{const D=o.Rectangle.getPositionRange({startRow:C,endRow:C,startColumn:S,endColumn:S},T),{row:w,col:E}=p(D.startRow,D.startColumn);d.setValue(w,E,y),l.add(y)})});const _=Array.from(l).map(T=>({id:T,ranges:o.queryObjectMatrix(d,m=>m===T)}));s.addRangeRules(_);const{redoMutations:g,undoMutations:O}=f.getDataValidationDiffMutations(a,i,s.diff(this._sheetDataValidationModel.getRules(a,i)),this._injector,"patched",!1);return{redos:g,undos:O}}}};Me=gn([nt(0,H.ISheetClipboardService),nt(1,o.Inject(f.SheetDataValidationModel)),nt(2,o.Inject(o.Injector))],Me);var fn=Object.getOwnPropertyDescriptor,mn=(e,t,r,n)=>{for(var a=n>1?void 0:n?fn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},rt=(e,t)=>(r,n)=>t(r,n,e);let be=class extends o.Disposable{constructor(e,t,r){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=r,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{e.id===f.AddSheetDataValidationCommand.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[$.WorkbookEditablePermission],rangeTypes:[$.RangeProtectionPermissionEditPoint],worksheetTypes:[$.WorksheetEditPermission,$.WorksheetSetCellStylePermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))),e.id===f.UpdateSheetDataValidationRangeCommand.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[$.WorkbookEditablePermission],rangeTypes:[$.RangeProtectionPermissionEditPoint],worksheetTypes:[$.WorksheetEditPermission,$.WorksheetSetCellStylePermission]},e.params.ranges)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr")))}))}};be=mn([rt(0,o.Inject(o.LocaleService)),rt(1,o.ICommandService),rt(2,o.Inject($.SheetPermissionCheckController))],be);const wt="data-validation-single",Dt="sheet.menu.data-validation";function Sn(e){return{id:Dt,type:b.MenuItemType.SUBITEMS,icon:wt,tooltip:"dataValidation.title",hidden$:b.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:H.getCurrentRangeDisable$(e,{workbookTypes:[$.WorkbookEditablePermission],worksheetTypes:[$.WorksheetSetCellStylePermission,$.WorksheetEditPermission],rangeTypes:[$.RangeProtectionPermissionEditPoint]})}}function _n(e){return{id:me.id,title:"dataValidation.panel.title",type:b.MenuItemType.BUTTON}}function In(e){return{id:Fe.id,title:"dataValidation.panel.add",type:b.MenuItemType.BUTTON}}const Cn={[b.RibbonStartGroup.FORMULAS_INSERT]:{[Dt]:{order:9,menuItemFactory:Sn,[me.id]:{order:0,menuItemFactory:_n},[Fe.id]:{order:1,menuItemFactory:In}}}};var yn=Object.getOwnPropertyDescriptor,Et=(e,t,r,n)=>{for(var a=n>1?void 0:n?yn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},q=(e,t)=>(r,n)=>t(r,n,e);const Mt={tr:{size:6,color:"#fe4b4b"}};let Te=class extends o.RxDisposable{constructor(e,t,r,n,a,i,s,d,l,c,h){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=r,this._univerInstanceService=n,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(Cn)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{var r;if(!e.visible){((r=this._dropdownManagerService.activeDropdown)==null?void 0:r.trigger)==="editor-bridge"&&this._dropdownManagerService.hideDropdown();return}const t=this._editorBridgeService.getEditCellState();if(t){const{unitId:n,sheetId:a,row:i,column:s}=t,d=this._univerInstanceService.getUniverSheetInstance(n);if(!d)return;const l=this._sheetDataValidationModel.getRuleByLocation(n,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 p=this._dropdownManagerService.activeDropdown,u=p==null?void 0:p.location;if(u&&u.unitId===n&&u.subUnitId===a&&u.row===i&&u.col===s)return;this._dropdownManagerService.showDropdown({location:{unitId:n,subUnitId:a,row:i,col:s,workbook:d,worksheet:h},trigger:"editor-bridge",closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept($.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:$.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,r)=>{var m,C,S,y,D;const{row:n,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=t,c=this._sheetDataValidationModel.getRuleIdByLocation(i,s,n,a);if(!c)return r(e);const h=this._sheetDataValidationModel.getRuleById(i,s,c);if(!h)return r(e);const p=(m=this._dataValidationCacheService.getValue(i,s,n,a))!=null?m:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),_=t.rawData;let g;const O={get value(){var w;return g!==void 0||(g=(w=f.getCellValueOrigin(_))!=null?w:null),g}},T={get value(){var w;return`${(w=O.value)!=null?w:""}`}};return r({...e,markers:{...e==null?void 0:e.markers,...p===o.DataValidationStatus.INVALID?Mt:null},customRender:[...(C=e==null?void 0:e.customRender)!=null?C:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],fontRenderExtension:{...e==null?void 0:e.fontRenderExtension,isSkip:((S=e==null?void 0:e.fontRenderExtension)==null?void 0:S.isSkip)||((y=u==null?void 0:u.skipDefaultFontRender)==null?void 0:y.call(u,h,O.value,t))},interceptorStyle:{...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,T.value,{get style(){const w=d.getStyles();return(typeof(e==null?void 0:e.s)=="string"?w.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},n,a)},interceptorAutoHeight:()=>{var x,P,k,j,B,A;const w=(P=(x=this._renderManagerService.getRenderById(i))==null?void 0:x.with(H.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!w)return;const E=w.worksheet.getMergedCell(n,a),F={data:e,style:w.getStyles().getStyleByCell(e),primaryWithCoord:w.getCellWithCoordByIndex((k=E==null?void 0:E.startRow)!=null?k:n,(j=E==null?void 0:E.startColumn)!=null?j:a),unitId:i,subUnitId:s,row:n,col:a,workbook:d,worksheet:l};return(A=(B=u==null?void 0:u.canvasRender)==null?void 0:B.calcCellAutoHeight)==null?void 0:A.call(B,F)},interceptorAutoWidth:()=>{var x,P,k,j,B,A;const w=(P=(x=this._renderManagerService.getRenderById(i))==null?void 0:x.with(H.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!w)return;const E=w.worksheet.getMergedCell(n,a),F={data:e,style:w.getStyles().getStyleByCell(e),primaryWithCoord:w.getCellWithCoordByIndex((k=E==null?void 0:E.startRow)!=null?k:n,(j=E==null?void 0:E.startColumn)!=null?j:a),unitId:i,subUnitId:s,row:n,col:a,workbook:d,worksheet:l};return(A=(B=u==null?void 0:u.canvasRender)==null?void 0:B.calcCellAutoWidth)==null?void 0:A.call(B,F)},coverable:((D=e==null?void 0:e.coverable)!=null?D:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE)})}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(te.filter(e=>e.source==="command"),te.bufferTime(100)).subscribe(e=>{if(e.length===0)return;const t=[];if(e.forEach(r=>{var n;(r.rule.type===o.DataValidationType.LIST_MULTIPLE||r.rule.type===o.DataValidationType.LIST)&&(n=r.rule)!=null&&n.ranges&&t.push(...r.rule.ranges)}),t.length){const r=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(r.redos,this._commandService)}})}};Te=Et([q(0,o.ICommandService),q(1,b.IMenuManagerService),q(2,N.IRenderManagerService),q(3,o.IUniverInstanceService),q(4,o.Inject(H.AutoHeightController)),q(5,o.Inject(fe)),q(6,o.Inject(f.SheetDataValidationModel)),q(7,o.Inject(Y.DataValidatorRegistryService)),q(8,o.Inject($.SheetInterceptorService)),q(9,o.Inject(f.DataValidationCacheService)),q(10,o.Optional(H.IEditorBridgeService))],Te);let bt=class extends o.RxDisposable{constructor(e,t,r,n,a,i,s){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=r,this._dataValidatorRegistryService=n,this._sheetInterceptorService=a,this._sheetDataValidationModel=i,this._dataValidationCacheService=s,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept($.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:$.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,r)=>{var T,m,C,S,y;const{row:n,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=t,c=this._sheetDataValidationModel.getRuleIdByLocation(i,s,n,a);if(!c)return r(e);const h=this._sheetDataValidationModel.getRuleById(i,s,c);if(!h)return r(e);const p=(T=this._dataValidationCacheService.getValue(i,s,n,a))!=null?T:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),_=l.getCellRaw(n,a),g=f.getCellValueOrigin(_),O=`${g!=null?g:""}`;return r({...e,markers:{...e==null?void 0:e.markers,...p===o.DataValidationStatus.INVALID?Mt:null},customRender:[...(m=e==null?void 0:e.customRender)!=null?m:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],fontRenderExtension:{...e==null?void 0:e.fontRenderExtension,isSkip:((C=e==null?void 0:e.fontRenderExtension)==null?void 0:C.isSkip)||((S=u==null?void 0:u.skipDefaultFontRender)==null?void 0:S.call(u,h,g,t))},interceptorStyle:{...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,O,{get style(){const D=d.getStyles();return(typeof(e==null?void 0:e.s)=="string"?D.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},n,a)},interceptorAutoHeight:()=>{var F,x,P,k,j,B;const D=(x=(F=this._renderManagerService.getRenderById(i))==null?void 0:F.with(H.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:x.skeleton;if(!D)return;const w=D.worksheet.getMergedCell(n,a),E={data:e,style:D.getStyles().getStyleByCell(e),primaryWithCoord:D.getCellWithCoordByIndex((P=w==null?void 0:w.startRow)!=null?P:n,(k=w==null?void 0:w.startColumn)!=null?k:a),unitId:i,subUnitId:s,row:n,col:a,workbook:d,worksheet:l};return(B=(j=u==null?void 0:u.canvasRender)==null?void 0:j.calcCellAutoHeight)==null?void 0:B.call(j,E)},coverable:((y=e==null?void 0:e.coverable)!=null?y:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE)})}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(te.filter(e=>e.source==="command"),te.bufferTime(16)).subscribe(e=>{const t=[];if(e.forEach(r=>{var n;(n=r.rule)!=null&&n.ranges&&t.push(...r.rule.ranges)}),t.length){const r=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(r.redos,this._commandService)}})}};bt=Et([q(0,o.ICommandService),q(1,N.IRenderManagerService),q(2,o.Inject(H.AutoHeightController)),q(3,o.Inject(Y.DataValidatorRegistryService)),q(4,o.Inject($.SheetInterceptorService)),q(5,o.Inject(f.SheetDataValidationModel)),q(6,o.Inject(f.DataValidationCacheService))],bt);var wn=Object.getOwnPropertyDescriptor,Dn=(e,t,r,n)=>{for(var a=n>1?void 0:n?wn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Tt=(e,t)=>(r,n)=>t(r,n,e);let ke=class extends o.Disposable{constructor(e,t,r){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=r,this._initSkeletonChange()}_initSkeletonChange(){const e=t=>{var n;if(!t.length)return;const r=new Set;t.forEach(a=>{r.add(a.subUnitId)}),r.forEach(a=>{var i;(i=this._sheetSkeletonManagerService.getSkeletonParam(a))==null||i.skeleton.makeDirty(!0)}),(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(o.bufferDebounceTime(16)).subscribe(e))}};ke=Dn([Tt(1,o.Inject(f.SheetDataValidationModel)),Tt(2,o.Inject(H.SheetSkeletonManagerService))],ke);function En(e){var c;const t=b.useDependency(o.LocaleService),r=b.useDependency(b.ComponentManager),{value:n,onChange:a,extraComponent:i}=e,[s,d]=V.useState(!1),l=i?r.get(i):null;return v.jsxs(v.Fragment,{children:[v.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?v.jsx(mt,{className:"univer-ml-1"}):v.jsx(Ze,{className:"univer-ml-1"})]}),s&&v.jsxs(v.Fragment,{children:[l?v.jsx(l,{value:n,onChange:a}):null,v.jsx(M.FormLayout,{label:t.t("dataValidation.panel.invalid"),children:v.jsxs(M.RadioGroup,{value:`${(c=n.errorStyle)!=null?c:o.DataValidationErrorStyle.WARNING}`,onChange:h=>a({...n,errorStyle:+h}),children:[v.jsx(M.Radio,{value:`${o.DataValidationErrorStyle.WARNING}`,children:t.t("dataValidation.panel.showWarning")}),v.jsx(M.Radio,{value:`${o.DataValidationErrorStyle.STOP}`,children:t.t("dataValidation.panel.rejectInput")})]})}),v.jsx(M.FormLayout,{label:t.t("dataValidation.panel.messageInfo"),children:v.jsx(M.Checkbox,{checked:n.showErrorMessage,onChange:()=>a({...n,showErrorMessage:!n.showErrorMessage}),children:t.t("dataValidation.panel.showInfo")})}),n.showErrorMessage?v.jsx(M.FormLayout,{children:v.jsx(M.Input,{value:n.error,onChange:h=>a({...n,error:h})})}):null]})]})}const Mn=e=>o.debounce(async(t,r,n,a)=>{const i=await e.executeCommand(t,r,n);a==null||a(i)},1e3);function bn(e,t,r){var n,a,i,s;return t?((a=(n=e.getUnit(t))==null?void 0:n.getSheetBySheetName(r))==null?void 0:a.getSheetId())||"":((s=(i=e.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetName(r))==null?void 0:s.getSheetId())||""}function Tn(){var U,G;const[e,t]=V.useState(0),r=b.useDependency(de),n=b.useObservable(r.activeRule$,r.activeRule),{unitId:a,subUnitId:i,rule:s}=n||{},d=s.uid,l=b.useDependency(Y.DataValidatorRegistryService),c=b.useDependency(o.IUniverInstanceService),h=b.useDependency(b.ComponentManager),p=b.useDependency(o.ICommandService),u=b.useDependency(Y.DataValidationModel),_=b.useDependency(o.LocaleService),[g,O]=V.useState(s),T=l.getValidatorItem(g.type),[m,C]=V.useState(!1),S=l.getValidatorsByScope(Y.DataValidatorRegistryScope.SHEET),[y,D]=V.useState(()=>g.ranges.map(I=>({unitId:"",sheetId:"",range:I}))),w=V.useMemo(()=>Mn(p),[p]),[E,F]=V.useState(!1),[x,P]=V.useState(!1),k=V.useRef(null),j=b.useDependency($.SheetsSelectionsService);if(V.useEffect(()=>()=>{const I=j.getCurrentLastSelection();I&&j.setSelections([I])},[j]),V.useEffect(()=>{p.onCommandExecuted(I=>{(I.id===o.UndoCommand.id||I.id===o.RedoCommand.id)&&setTimeout(()=>{const W=u.getRuleById(a,i,d);t(K=>K+1),W&&(O(W),D(W.ranges.map(K=>({unitId:"",sheetId:"",range:K}))))},20)})},[p,u,d,i,a]),!T)return null;const B=T.operators,A=T.operatorNames,X=g.operator?Y.TWO_FORMULA_OPERATOR_COUNT.includes(g.operator):!1,z=()=>{var I,W,K;(W=(I=k.current)==null?void 0:I.editor)!=null&&W.isFocus()&&Z((K=k.current)==null?void 0:K.getValue()),!(!g.ranges.length||E)&&(T.validatorFormula(g,a,i).success?r.setActiveRule(null):C(!0))},Z=b.useEvent(I=>{const W=I.split(",").filter(Boolean).map(Ge.deserializeRangeWithSheet).map(ee=>{const Lt=ee.sheetName;if(Lt){const cr=bn(c,ee.unitId,Lt);return{...ee,sheetId:cr}}return{...ee,sheetId:""}});if(o.isUnitRangesEqual(W,y))return;D(W);const K=W.filter(ee=>(!ee.unitId||ee.unitId===a)&&(!ee.sheetId||ee.sheetId===i)).map(ee=>ee.range);if(O({...g,ranges:K}),K.length===0)return;const pe={unitId:a,subUnitId:i,ruleId:d,ranges:K};w(f.UpdateSheetDataValidationRangeCommand.id,pe)}),Q=I=>{if(o.shallowEqual(I,Y.getRuleSetting(g)))return;O({...g,...I});const W={unitId:a,subUnitId:i,ruleId:d,setting:I};w(f.UpdateSheetDataValidationSettingCommand.id,W,void 0)},J=async()=>{await p.executeCommand(f.RemoveSheetDataValidationCommand.id,{ruleId:d,unitId:a,subUnitId:i}),r.setActiveRule(null)},re={type:g.type,operator:g.operator,formula1:g.formula1,formula2:g.formula2,allowBlank:g.allowBlank},ue=I=>{const W=l.getValidatorItem(I);if(!W)return;const K=W.operators,pe=u.getRuleById(a,i,d),ee=I===(pe==null?void 0:pe.type)||I.includes("list")&&(pe!=null&&pe.type.includes("list"))?{...pe,type:I}:{...g,type:I,operator:K[0],formula1:void 0,formula2:void 0};O(ee),p.executeCommand(f.UpdateSheetDataValidationSettingCommand.id,{unitId:a,subUnitId:i,ruleId:g.uid,setting:Y.getRuleSetting(ee)})},se=h.get(T.formulaInput),ae=V.useMemo(()=>y.map(I=>Ge.serializeRange(I.range)).join(","),[]),le=Y.getRuleOptions(g),ve=I=>{o.shallowEqual(I,Y.getRuleOptions(g))||(O({...g,...I}),w(f.UpdateSheetDataValidationOptionsCommand.id,{unitId:a,subUnitId:i,ruleId:d,options:I}))},he=B.length&&!g.operator;return v.jsxs("div",{className:"univer-py-4",children:[v.jsx(M.FormLayout,{label:_.t("dataValidation.panel.range"),error:!g.ranges.length||E?_.t("dataValidation.panel.rangeError"):"",children:v.jsx(Ke.RangeSelector,{selectorRef:k,unitId:a,subUnitId:i,initialValue:ae,onChange:(I,W)=>{var K;!x&&((K=k.current)!=null&&K.verify())&&Z(W)},onFocusChange:(I,W)=>{var K;P(I),!I&&W&&((K=k.current)!=null&&K.verify())&&Z(W)},onVerify:I=>F(!I)})}),v.jsx(M.FormLayout,{label:_.t("dataValidation.panel.type"),children:v.jsx(M.Select,{className:"univer-w-full",value:g.type,options:(U=S==null?void 0:S.sort((I,W)=>I.order-W.order))==null?void 0:U.map(I=>({label:_.t(I.title),value:I.id})),onChange:ue})}),B!=null&&B.length?v.jsx(M.FormLayout,{label:_.t("dataValidation.panel.operator"),children:v.jsx(M.Select,{className:"univer-w-full",value:`${g.operator}`,options:[{value:"",label:_.t("dataValidation.operators.legal")},...B.map((I,W)=>({value:`${I}`,label:A[W]}))],onChange:I=>{Q({...re,operator:I})}})}):null,se&&!he?v.jsx(se,{isTwoFormula:X,value:{formula1:g.formula1,formula2:g.formula2},onChange:I=>{Q({...re,...I})},showError:m,validResult:T.validatorFormula(g,a,i),unitId:a,subUnitId:i,ruleId:d},e+g.type):null,v.jsx(M.FormLayout,{children:v.jsx(M.Checkbox,{checked:(G=g.allowBlank)!=null?G:!0,onChange:()=>{var I;return Q({...re,allowBlank:!((I=g.allowBlank)==null||I)})},children:_.t("dataValidation.panel.allowBlank")})}),v.jsx(En,{value:le,onChange:ve,extraComponent:T.optionsInput}),v.jsxs("div",{className:"univer-mt-5 univer-flex univer-flex-row univer-justify-end",children:[v.jsx(M.Button,{className:"univer-ml-3",onClick:J,children:_.t("dataValidation.panel.removeRule")}),v.jsx(M.Button,{className:"univer-ml-3",variant:"primary",onClick:z,children:_.t("dataValidation.panel.done")})]})]})}const Vn=e=>{const{rule:t,onClick:r,unitId:n,subUnitId:a,disable:i}=e,s=b.useDependency(Y.DataValidatorRegistryService),d=b.useDependency(o.ICommandService),l=b.useDependency(H.IMarkSelectionService),c=s.getValidatorItem(t.type),h=V.useRef(void 0),[p,u]=V.useState(!1),_=b.useDependency(o.ThemeService),g=b.useObservable(_.currentTheme$),O=V.useMemo(()=>{var D;const m=_.getColorFromTheme("primary.600"),C=_.getColorFromTheme("loop-color.2"),S=(D=_.getColorFromTheme(C))!=null?D:m,y=new o.ColorKit(S).toRgb();return{fill:`rgba(${y.r}, ${y.g}, ${y.b}, 0.1)`,stroke:S}},[g]),T=m=>{d.executeCommand(f.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:n,subUnitId:a}),m.stopPropagation()};return V.useEffect(()=>()=>{var m;h.current&&((m=h.current)==null||m.forEach(C=>{C&&l.removeShape(C)}))},[l]),v.jsxs("div",{className:M.clsx(`
|
|
14
|
+
(function(F,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/sheets-data-validation"),require("react/jsx-runtime"),require("@univerjs/design"),require("@univerjs/ui"),require("react"),require("@univerjs/sheets-formula-ui"),require("@univerjs/data-validation"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-data-validation","react/jsx-runtime","@univerjs/design","@univerjs/ui","react","@univerjs/sheets-formula-ui","@univerjs/data-validation","rxjs","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/engine-formula"],o):(F=typeof globalThis<"u"?globalThis:F||self,o(F.UniverSheetsDataValidationUi={},F.UniverCore,F.UniverSheetsDataValidation,F.React,F.UniverDesign,F.UniverUi,F.React,F.UniverSheetsFormulaUi,F.UniverDataValidation,F.rxjs,F.UniverEngineRender,F.UniverSheets,F.UniverSheetsNumfmt,F.UniverSheetsUi,F.UniverEngineFormula))})(this,function(F,o,f,v,M,b,R,ze,X,ie,P,$,Lt,B,Ke){"use strict";var lr=Object.defineProperty;var dr=(F,o,f)=>o in F?lr(F,o,{enumerable:!0,configurable:!0,writable:!0,value:f}):F[o]=f;var A=(F,o,f)=>dr(F,typeof o!="symbol"?o+"":o,f);var Ye,Xe;const Pt=e=>{const{isTwoFormula:t=!1,value:r,onChange:n,showError:a,validResult:i}=e,s=b.useDependency(o.LocaleService),d=a?i==null?void 0:i.formula1:"",l=a?i==null?void 0:i.formula2:"";return t?v.jsxs(v.Fragment,{children:[v.jsx(M.FormLayout,{error:d,children:v.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:r==null?void 0:r.formula1,onChange:c=>{n==null||n({...r,formula1:c})}})}),v.jsx("div",{className:"-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400",children:s.t("dataValidation.panel.formulaAnd")}),v.jsx(M.FormLayout,{error:l,children:v.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:r==null?void 0:r.formula2,onChange:c=>{n==null||n({...r,formula2:c})}})})]}):v.jsx(M.FormLayout,{error:d,children:v.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:r==null?void 0:r.formula1,onChange:c=>{n==null||n({formula1:c})}})})};function kt(e){const{value:t,onChange:r,showError:n,validResult:a}=e,i=b.useDependency(o.LocaleService),s=n?a==null?void 0:a.formula1:"",d=n?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 v.jsxs(v.Fragment,{children:[v.jsx(M.FormLayout,{children:v.jsx(M.Checkbox,{checked:l,onChange:h=>{h?c(!0):(c(!1),r==null||r({...t,formula1:void 0,formula2:void 0}))},children:i.t("dataValidation.checkbox.tips")})}),l?v.jsx(M.FormLayout,{label:i.t("dataValidation.checkbox.checked"),error:s,children:v.jsx(M.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula1,onChange:h=>{r==null||r({...t,formula1:h||void 0})}})}):null,l?v.jsx(M.FormLayout,{label:i.t("dataValidation.checkbox.unchecked"),error:d,children:v.jsx(M.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula2,onChange:h=>{r==null||r({...t,formula2:h||void 0})}})}):null]})}function Ft(e){var p;const{unitId:t,subUnitId:r,value:n,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 b.useSidebarClick(u=>{var g;((g=l.current)==null?void 0:g.isClickOutSide(u))&&h(!1)}),v.jsx(M.FormLayout,{error:d,children:v.jsx(ze.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 [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent dark:!univer-bg-gray-700 dark:!univer-text-white hover:univer-border-primary-600",M.borderClassName),initValue:(p=n==null?void 0:n.formula1)!=null?p:"=",unitId:t,subUnitId:r,isFocus:c,isSupportAcrossSheet:!0,onChange:u=>{const I=(u!=null?u:"").trim();I!==(n==null?void 0:n.formula1)&&(a==null||a({...n,formula1:I}))},onFocus:()=>h(!0)})})}var oe=function(){return oe=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},oe.apply(this,arguments)},Ut=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]]);return r},ge=R.forwardRef(function(e,t){var r=e.icon,n=e.id,a=e.className,i=e.extend,s=Ut(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(a||"").trim(),l=R.useRef("_".concat(Bt()));return vt(r,"".concat(n),{defIds:r.defIds,idSuffix:l.current},oe({ref:t,className:d},s),i)});function vt(e,t,r,n,a){return R.createElement(e.tag,oe(oe({key:t},Nt(e,r,a)),n),(jt(e,r).children||[]).map(function(i,s){return vt(i,"".concat(t,"-").concat(e.tag,"-").concat(s),r,void 0,a)}))}function Nt(e,t,r){var n=oe({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(i){var s=i[0],d=i[1];s==="mask"&&typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var a=t.defIds;return!a||a.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(i){var s=i[0],d=i[1];typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function jt(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?oe(oe({},e),{children:e.children.map(function(a){return typeof a.attrs.id=="string"&&n&&n.includes(a.attrs.id)?oe(oe({},a),{attrs:oe(oe({},a.attrs),{id:a.attrs.id+t.idSuffix})}):a})}):e}function Bt(){return Math.random().toString(36).substring(2,8)}ge.displayName="UniverIcon";var Wt={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"}}]},pt=R.forwardRef(function(e,t){return R.createElement(ge,Object.assign({},e,{id:"data-validation-icon",ref:t,icon:Wt}))});pt.displayName="DataValidationIcon";var Ht={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"}}]},Ze=R.forwardRef(function(e,t){return R.createElement(ge,Object.assign({},e,{id:"delete-icon",ref:t,icon:Ht}))});Ze.displayName="DeleteIcon";var xt={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"}}]},gt=R.forwardRef(function(e,t){return R.createElement(ge,Object.assign({},e,{id:"increase-icon",ref:t,icon:xt}))});gt.displayName="IncreaseIcon";var $t={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"}}]},Ge=R.forwardRef(function(e,t){return R.createElement(ge,Object.assign({},e,{id:"more-down-icon",ref:t,icon:$t}))});Ge.displayName="MoreDownIcon";var Yt={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"}}]},ft=R.forwardRef(function(e,t){return R.createElement(ge,Object.assign({},e,{id:"more-up-icon",ref:t,icon:Yt}))});ft.displayName="MoreUpIcon";var Xt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_622_8",width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_622_8)"},children:[{tag:"path",attrs:{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:{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:{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:{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:{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:{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"}}]}]},mt=R.forwardRef(function(e,t){return R.createElement(ge,Object.assign({},e,{id:"sequence-icon",ref:t,icon:Xt}))});mt.displayName="SequenceIcon";const Ce="#ECECEC",zt=["#FFFFFF","#FEE7E7","#FEF0E6","#EFFBD0","#E4F4FE","#E8ECFD","#F1EAFA","#FDE8F3","#E5E5E5","#FDCECE","#FDC49B","#DEF6A2","#9FDAFF","#D0D9FB","#E3D5F6","#FBD0E8","#656565","#FE4B4B","#FF8C51","#8BBB11","#0B9EFB","#3A60F7","#9E6DE3","#F248A6"],Kt=e=>{const{value:t,onChange:r,disabled:n}=e,[a,i]=R.useState(!1);return v.jsx(M.Dropdown,{align:"start",disabled:n,open:a,onOpenChange:i,overlay:v.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:zt.map(s=>v.jsx("div",{className:M.clsx("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded",M.borderClassName),style:{background:s},onClick:()=>{r(s),i(!1)}},s))}),children:v.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 dark:!univer-bg-gray-700 dark:!univer-text-white hover:univer-border-primary-600",M.borderClassName),children:[v.jsx("div",{className:"univer-box-border univer-h-4 univer-w-4 univer-rounded univer-text-base",style:{background:t}}),v.jsx(Ge,{})]})})},St=e=>{const{item:t,commonProps:r,className:n}=e,{onItemChange:a,onItemDelete:i}=r;return v.jsxs("div",{className:M.clsx("univer-flex univer-items-center univer-gap-2",n),children:[!t.isRef&&v.jsx("div",{className:M.clsx("univer-cursor-move","draggableHandle"),children:v.jsx(mt,{})}),v.jsx(Kt,{value:t.color,onChange:s=>{a(t.id,t.label,s)}}),v.jsx(M.Input,{disabled:t.isRef,value:t.label,onChange:s=>{a(t.id,s,t.color)}}),t.isRef?null:v.jsx("div",{className:"univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",children:v.jsx(Ze,{onClick:()=>i(t.id)})})]})};function Zt(e){const{value:t,onChange:r=()=>{},unitId:n,subUnitId:a,validResult:i,showError:s,ruleId:d}=e,{formula1:l="",formula2:c=""}=t||{},[h,p]=R.useState(()=>o.isFormulaString(l)?"1":"0"),[u,I]=R.useState(h==="1"?l:"="),[g,V]=R.useState(h==="1"?l:"="),T=b.useDependency(o.LocaleService),m=b.useDependency(X.DataValidatorRegistryService),y=b.useDependency(X.DataValidationModel),S=b.useDependency(f.DataValidationFormulaController),[D,w]=R.useState(()=>c.split(",")),C=m.getValidatorItem(o.DataValidationType.LIST),[E,W]=R.useState([]),[x,O]=R.useState(""),U=s?i==null?void 0:i.formula1:"",k=R.useMemo(()=>y.ruleChange$.pipe(ie.debounceTime(16)),[]),N=b.useObservable(k),H=b.useEvent(r);R.useEffect(()=>{(async()=>{await new Promise(_=>{setTimeout(()=>_(!0),100)});const L=y.getRuleById(n,a,d),Y=L==null?void 0:L.formula1;if(o.isFormulaString(Y)&&C&&L){const _=await C.getListAsync(L,n,a);W(_)}})()},[y,N,C,d,a,n]),R.useEffect(()=>{o.isFormulaString(l)&&l!==g&&(I(l),V(g))},[g,l]);const[Z,K]=R.useState(()=>{const L=h!=="1"?f.deserializeListOptions(l):[],Y=c.split(",");return L.map((_,j)=>({label:_,color:Y[j]||Ce,isRef:!1,id:o.Tools.generateRandomId(4)}))}),te=(L,Y,_)=>{const j=Z.find(z=>z.id===L);j&&(j.label=Y,j.color=_,K([...Z]))},ae=L=>{const Y=Z.findIndex(_=>_.id===L);Y!==-1&&(Z.splice(Y,1),K([...Z]))},se=c.split(","),ce=R.useMemo(()=>E.map((L,Y)=>({label:L,color:se[Y]||Ce,id:`${Y}`,isRef:!0})),[se,E]),J=(L,Y,_)=>{const j=[...D];j[+L]=_,w(j),H({formula1:l,formula2:j.join(",")})},q=()=>{K([...Z,{label:"",color:Ce,isRef:!1,id:o.Tools.generateRandomId(4)}])};R.useEffect(()=>{if(h==="1")return;const L=new Set,Y=[];Z.map(_=>({labelList:_.label.split(","),item:_})).forEach(({item:_,labelList:j})=>{j.forEach(z=>{L.has(z)||(L.add(z),Y.push({label:z,color:_.color}))})}),H({formula1:f.serializeListOptions(Y.map(_=>_.label)),formula2:Y.map(_=>_.color===Ce?"":_.color).join(",")})},[Z,H,h,g,D]);const ve=b.useEvent(async L=>{if(!o.isFormulaString(L)){H==null||H({formula1:"",formula2:c});return}S.getFormulaRefCheck(L)?(H==null||H({formula1:o.isFormulaString(L)?L:"",formula2:c}),O("")):(H==null||H({formula1:"",formula2:c}),I("="),O(T.t("dataValidation.validFail.formulaError")))}),ne=R.useRef(null),[ee,Q]=R.useState(!1);return b.useSidebarClick(L=>{var _;((_=ne.current)==null?void 0:_.isClickOutSide(L))&&Q(!1)}),v.jsxs(v.Fragment,{children:[v.jsx(M.FormLayout,{label:T.t("dataValidation.list.options"),children:v.jsxs(M.RadioGroup,{value:h,onChange:L=>{p(L),I(g),L==="1"&&H({formula1:g==="="?"":g,formula2:D.join(",")})},children:[v.jsx(M.Radio,{value:"0",children:T.t("dataValidation.list.customOptions")}),v.jsx(M.Radio,{value:"1",children:T.t("dataValidation.list.refOptions")})]})}),h==="1"?v.jsxs(M.FormLayout,{error:U||x||void 0,children:[v.jsx(ze.FormulaEditor,{ref:ne,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 [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent dark:!univer-bg-gray-700 dark:!univer-text-white hover:univer-border-primary-600",M.borderClassName),initValue:u,unitId:n,subUnitId:a,isFocus:ee,isSupportAcrossSheet:!0,onFocus:()=>Q(!0),onChange:(L="")=>{const Y=(L!=null?L:"").trim();V(Y),ve(Y)}}),ce.length>0&&v.jsx("div",{className:"univer-mt-3",children:ce.map(L=>v.jsx(St,{className:"univer-mb-3",item:L,commonProps:{onItemChange:J}},L.id))})]}):v.jsx(M.FormLayout,{error:U,children:v.jsxs("div",{className:"-univer-mt-3",children:[v.jsx(M.DraggableList,{list:Z,onListChange:K,rowHeight:28,margin:[0,12],draggableHandle:".draggableHandle",itemRender:L=>v.jsx(St,{item:L,commonProps:{onItemChange:te,onItemDelete:ae}},L.id),idKey:"id"}),v.jsxs("a",{className:"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 univer-text-primary dark:hover:!univer-bg-gray-800 hover:univer-bg-primary-50",onClick:q,children:[v.jsx(gt,{className:"univer-mr-1"}),T.t("dataValidation.list.add")]})]})})]})}const Gt=[[f.CUSTOM_FORMULA_INPUT_NAME,Ft],[f.BASE_FORMULA_INPUT_NAME,Pt],[f.LIST_FORMULA_INPUT_NAME,Zt],[f.CHECKBOX_FORMULA_INPUT_NAME,kt]];var qt=Object.getOwnPropertyDescriptor,Jt=(e,t,r,n)=>{for(var a=n>1?void 0:n?qt(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Qt=(e,t)=>(r,n)=>t(r,n,e);F.BaseSheetDataValidatorView=class{constructor(t){A(this,"canvasRender",null);A(this,"dropdownType");A(this,"optionsInput");A(this,"formulaInput",f.LIST_FORMULA_INPUT_NAME);this.injector=t}},F.BaseSheetDataValidatorView=Jt([Qt(0,o.Inject(o.Injector))],F.BaseSheetDataValidatorView);var en=Object.getOwnPropertyDescriptor,tn=(e,t,r,n)=>{for(var a=n>1?void 0:n?en(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},_t=(e,t)=>(r,n)=>t(r,n,e);let ue=class extends o.Disposable{constructor(t,r){super();A(this,"_open$",new ie.BehaviorSubject(!1));A(this,"open$",this._open$.pipe(ie.distinctUntilChanged()));A(this,"_activeRule");A(this,"_activeRule$",new ie.BehaviorSubject(void 0));A(this,"activeRule$",this._activeRule$.asObservable());A(this,"_closeDisposable",null);this._univerInstanceService=t,this._sidebarService=r,this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).pipe(ie.filter(n=>!n)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(n=>{n.id===ke&&(n.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)}};ue=tn([_t(0,o.IUniverInstanceService),_t(1,b.ISidebarService)],ue);const qe="sheets-data-validation-ui.config",Pe={};var nn=Object.getOwnPropertyDescriptor,rn=(e,t,r,n)=>{for(var a=n>1?void 0:n?nn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ye=(e,t)=>(r,n)=>t(r,n,e);let we=class extends o.Disposable{constructor(e,t,r,n,a,i){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=r,this._dialogService=n,this._localeService=a,this._sheetsDataValidationValidatorService=i,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this._sheetInterceptorService.writeCellInterceptor.intercept($.VALIDATE_CELL,{handler:async(e,t,r)=>{const n=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(n===!1)return r(Promise.resolve(!1));if(!c||c.errorStyle!==o.DataValidationErrorStyle.STOP)return r(Promise.resolve(!0));const h=this._dataValidatorRegistryService.getValidatorItem(c.type);return!h||await this._sheetsDataValidationValidatorService.validatorCell(s,d,a,i)===o.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: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")}}),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: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")}})}};we=rn([ye(0,o.Inject($.SheetInterceptorService)),ye(1,o.Inject(f.SheetDataValidationModel)),ye(2,o.Inject(X.DataValidatorRegistryService)),ye(3,b.IDialogService),ye(4,o.Inject(o.LocaleService)),ye(5,o.Inject(f.SheetsDataValidationValidatorService))],we);var an=Object.getOwnPropertyDescriptor,on=(e,t,r,n)=>{for(var a=n>1?void 0:n?an(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},le=(e,t)=>(r,n)=>t(r,n,e);const Je=e=>{if(e==null||typeof e=="boolean")return;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 sn(e,t){const r=Lt.getPatternType(t);if(e===r)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 fe=class extends o.Disposable{constructor(t,r,n,a,i,s,d,l,c,h,p){super();A(this,"_activeDropdown");A(this,"_activeDropdown$",new ie.Subject);A(this,"_currentPopup",null);A(this,"activeDropdown$",this._activeDropdown$.asObservable());A(this,"_zenVisible",!1);this._univerInstanceService=t,this._dataValidatorRegistryService=r,this._zenZoneService=n,this._dataValidationModel=a,this._sheetsSelectionsService=i,this._cellDropdownManagerService=s,this._sheetDataValidationModel=d,this._commandService=l,this._editorBridgeService=c,this._injector=h,this._configService=p,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,r,n,a){const i=t?this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!i)return;const s=r?i.getSheetBySheetId(r):i.getActiveSheet();if(!s)return;const d=this._dataValidationModel.getRuleByLocation(i.getUnitId(),s.getSheetId(),n,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(r=>!(r.primary&&this._getDropdownByCell(r.primary.unitId,r.primary.sheetId,r.primary.actualRow,r.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){var V,T,m,y;const{location:r}=t,{row:n,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=r;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);const c=this._sheetDataValidationModel.getRuleByLocation(i,s,n,a);if(!c)return;const h=this._dataValidatorRegistryService.getValidatorItem(c.type);if(!(h!=null&&h.dropdownType))return;let p;const u=async(S,D)=>{var k,N,H;if(!S)return!0;const w=S,C=l.getCell(n,a),E=w.format(D==="date"?"YYYY-MM-DD 00:00:00":"YYYY-MM-DD HH:mm:ss"),W=(k=o.numfmt.parseDate(E))==null?void 0:k.v,x=D==="time"?W%1:W,O=d.getStyles().getStyleByCell(C),U=(H=(N=O==null?void 0:O.n)==null?void 0:N.pattern)!=null?H:"";return c.errorStyle!==o.DataValidationErrorStyle.STOP||await h.validator({value:x,unitId:i,subUnitId:s,row:n,column:a,worksheet:l,workbook:d,interceptValue:E.replace("Z","").replace("T"," "),t:o.CellValueType.NUMBER},c)?(await this._commandService.executeCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:P.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),await this._commandService.executeCommand($.SetRangeValuesCommand.id,{unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:n,endRow:n},value:{v:x,t:2,p:null,f:null,si:null,s:{n:{pattern:sn(D,U)}}}}),!0):(this._injector.has(we)&&this._injector.get(we).showReject(h.getRuleFinalError(c,{row:n,col:a,unitId:i,subUnitId:s})),!1)};let I;switch(h.dropdownType){case X.DataValidatorDropdownType.DATE:{const S=f.getCellValueOrigin(l.getCellRaw(n,a)),D=Je(S),w=!!((V=c.bizInfo)!=null&&V.showTime);I={location:r,type:"datepicker",props:{showTime:w,onChange:C=>u(C,w?"datetime":"date"),defaultValue:D,patternType:"date"}};break}case X.DataValidatorDropdownType.TIME:{const S=f.getCellValueOrigin(l.getCellRaw(n,a)),D=Je(S);I={location:r,type:"datepicker",props:{onChange:w=>u(w,"time"),defaultValue:D,patternType:"time"}};break}case X.DataValidatorDropdownType.DATETIME:{const S=f.getCellValueOrigin(l.getCellRaw(n,a)),D=Je(S);I={location:r,type:"datepicker",props:{onChange:w=>u(w,"datetime"),defaultValue:D,patternType:"datetime"}};break}case X.DataValidatorDropdownType.LIST:case X.DataValidatorDropdownType.MULTIPLE_LIST:{const S=h.dropdownType===X.DataValidatorDropdownType.MULTIPLE_LIST,D=async O=>{const U=f.serializeListOptions(O),k={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:n,endRow:n},value:{v:U,p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:P.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),this._commandService.executeCommand($.SetRangeValuesCommand.id,k),!S},w=(c==null?void 0:c.renderMode)===o.DataValidationRenderMode.CUSTOM||(c==null?void 0:c.renderMode)===void 0,C=h.getListWithColor(c,i,s),E=f.getDataValidationCellValue(l.getCellRaw(n,a)),W=()=>{this._commandService.executeCommand(me.id,{ruleId:c.uid}),p==null||p.dispose()},x=C.map(O=>({label:O.label,value:O.label,color:w||O.color?O.color:"transparent"}));I={location:r,type:"list",props:{onChange:O=>D(O),options:x,onEdit:W,defaultValue:E,multiple:S,showEdit:(m=(T=this._configService.getConfig(qe))==null?void 0:T.showEditOnDropdown)!=null?m:!0}};break}case X.DataValidatorDropdownType.CASCADE:{I={type:"cascader",props:{onChange:D=>{const w={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:n,endRow:n},value:{v:D.join("/"),p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:P.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),this._commandService.syncExecuteCommand($.SetRangeValuesCommand.id,w),!0},defaultValue:f.getDataValidationCellValue(l.getCellRaw(n,a)).split("/"),options:JSON.parse((y=c.formula1)!=null?y:"[]")},location:r};break}case X.DataValidatorDropdownType.COLOR:{I={type:"color",props:{onChange:D=>{const w={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:n,endRow:n},value:{v:D,p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:P.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),this._commandService.syncExecuteCommand($.SetRangeValuesCommand.id,w),!0},defaultValue:f.getDataValidationCellValue(l.getCellRaw(n,a))},location:r};break}default:throw new Error("[DataValidationDropdownManagerService]: unknown type!")}if(p=this._cellDropdownManagerService.showDropdown(I),!p)throw new Error("[DataValidationDropdownManagerService]: cannot show dropdown!");const g=new o.DisposableCollection;g.add(p),g.add({dispose:()=>{var S,D;(D=(S=this._activeDropdown)==null?void 0:S.onHide)==null||D.call(S)}}),this._currentPopup=g}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(t,r,n,a,i){const s=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!s)return;const d=s.getSheetBySheetId(r);if(!d)return;const l=this._dataValidationModel.getRuleByLocation(s.getUnitId(),d.getSheetId(),n,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:n,col:a,unitId:t,subUnitId:r},onHide:i})}};fe=on([le(0,o.IUniverInstanceService),le(1,o.Inject(X.DataValidatorRegistryService)),le(2,b.IZenZoneService),le(3,o.Inject(f.SheetDataValidationModel)),le(4,o.Inject($.SheetsSelectionsService)),le(5,o.Inject(B.ISheetCellDropdownManagerService)),le(6,o.Inject(f.SheetDataValidationModel)),le(7,o.ICommandService),le(8,B.IEditorBridgeService),le(9,o.Inject(o.Injector)),le(10,o.IConfigService)],fe);const ke="DataValidationPanel",me={id:"data-validation.operation.open-validation-panel",type:o.CommandType.OPERATION,handler(e,t){if(!t)return!1;const{ruleId:r,isAdd:n}=t,a=e.get(ue),i=e.get(X.DataValidationModel),s=e.get(o.IUniverInstanceService),d=e.get(b.ISidebarService),l=$.getSheetCommandTarget(s);if(!l)return!1;const{unitId:c,subUnitId:h}=l,p=r?i.getRuleById(c,h,r):void 0;a.open(),a.setActiveRule(p&&{unitId:c,subUnitId:h,rule:p});const u=d.open({id:ke,header:{title:n?"dataValidation.panel.addTitle":"dataValidation.panel.title"},children:{label:ke},width:312,onClose:()=>a.close()});return a.setCloseDisposable(u),!0}},Qe={id:"data-validation.operation.close-validation-panel",type:o.CommandType.OPERATION,handler(e){return e.get(ue).close(),!0}},It={id:"data-validation.operation.toggle-validation-panel",type:o.CommandType.OPERATION,handler(e){const t=e.get(o.ICommandService),r=e.get(ue);return r.open(),r.isOpen?t.executeCommand(Qe.id):t.executeCommand(me.id),!0}},Fe={type:o.CommandType.OPERATION,id:"sheet.operation.show-data-validation-dropdown",handler(e,t){if(!t)return!1;const r=e.get(fe),{unitId:n,subUnitId:a,row:i,column:s}=t,d=r.activeDropdown,l=d==null?void 0:d.location;return l&&l.unitId===n&&l.subUnitId===a&&l.row===i&&l.col===s||r.showDataValidationDropdown(n,a,i,s),!0}},Ct={type:o.CommandType.OPERATION,id:"sheet.operation.hide-data-validation-dropdown",handler(e,t){return t?(e.get(fe).hideDropdown(),!0):!1}},Ue={type:o.CommandType.COMMAND,id:"data-validation.command.addRuleAndOpen",handler(e){const t=e.get(o.IUniverInstanceService),r=$.getSheetCommandTarget(t);if(!r)return!1;const{workbook:n,worksheet:a}=r,i=f.createDefaultNewRule(e),s=e.get(o.ICommandService),d=n.getUnitId(),l=a.getSheetId(),c={rule:i,unitId:d,subUnitId:l};return s.syncExecuteCommand(f.AddSheetDataValidationCommand.id,c)?(s.syncExecuteCommand(me.id,{ruleId:i.uid,isAdd:!0}),!0):!1}};var ln=Object.getOwnPropertyDescriptor,dn=(e,t,r,n)=>{for(var a=n>1?void 0:n?ln(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},De=(e,t)=>(r,n)=>t(r,n,e);const Se="SHEET_DATA_VALIDATION_ALERT";let Ae=class extends o.Disposable{constructor(e,t,r,n,a,i){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=r,this._localeService=n,this._zenZoneService=a,this._dataValidationModel=i,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(ie.debounceTime(100)).subscribe(e=>{var t;if(e){const r=this._univerInstanceService.getUnit(e.location.unitId,o.UniverInstanceType.UNIVER_SHEET),n=r.getSheetBySheetId(e.location.subUnitId);if(!n)return;const a=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!a){this._cellAlertManagerService.removeAlert(Se);return}if(this._dataValidationModel.validator(a,{...e.location,workbook:r,worksheet:n})===o.DataValidationStatus.INVALID){const s=this._cellAlertManagerService.currentAlert.get(Se),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(Se);return}const l=this._dataValidationModel.getValidator(a.type);if(!l){this._cellAlertManagerService.removeAlert(Se);return}this._cellAlertManagerService.showAlert({type:B.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:Se});return}}this._cellAlertManagerService.removeAlert(Se)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(Se)}))}};Ae=dn([De(0,o.Inject(B.HoverManagerService)),De(1,o.Inject(B.CellAlertManagerService)),De(2,o.IUniverInstanceService),De(3,o.Inject(o.LocaleService)),De(4,b.IZenZoneService),De(5,o.Inject(f.SheetDataValidationModel))],Ae);var cn=Object.getOwnPropertyDescriptor,un=(e,t,r,n)=>{for(var a=n>1?void 0:n?cn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},et=(e,t)=>(r,n)=>t(r,n,e);let Ee=class extends o.Disposable{constructor(e,t,r){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=r,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),t=(n,a)=>{const{source:i,target:s,unitId:d,subUnitId:l}=n,c=this._sheetDataValidationModel.getRuleObjectMatrix(d,l).clone(),h=B.virtualizeDiscreteRanges([i,s]),[p,u]=h.ranges,{mapFunc:I}=h,g={row:p.startRow,col:p.startColumn},V=B.getAutoFillRepeatRange(p,u),T=new o.ObjectMatrix,m=new Set;V.forEach(C=>{const E=C.repeatStartCell,W=C.relativeRange,x={startRow:g.row,startColumn:g.col,endColumn:g.col,endRow:g.row},O={startRow:E.row,startColumn:E.col,endColumn:E.col,endRow:E.row};o.Range.foreach(W,(U,k)=>{const N=o.Rectangle.getPositionRange({startRow:U,startColumn:k,endColumn:k,endRow:U},x),{row:H,col:Z}=I(N.startRow,N.startColumn),K=this._sheetDataValidationModel.getRuleIdByLocation(d,l,H,Z)||"",te=o.Rectangle.getPositionRange({startRow:U,startColumn:k,endColumn:k,endRow:U},O),{row:ae,col:se}=I(te.startRow,te.startColumn);T.setValue(ae,se,K),m.add(K)})});const y=Array.from(m).map(C=>({id:C,ranges:o.queryObjectMatrix(T,E=>E===C)}));c.addRangeRules(y);const S=c.diff(this._sheetDataValidationModel.getRules(d,l)),{redoMutations:D,undoMutations:w}=f.getDataValidationDiffMutations(d,l,S,this._injector,"patched",a===B.APPLY_TYPE.ONLY_FORMAT);return{undos:w,redos:D}},r={id:f.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:n=>{const{source:a,unitId:i,subUnitId:s}=n;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(B.APPLY_TYPE.SERIES,!0);return}}},onFillData:(n,a,i)=>i===B.APPLY_TYPE.COPY||i===B.APPLY_TYPE.ONLY_FORMAT||i===B.APPLY_TYPE.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(r))}};Ee=un([et(0,B.IAutoFillService),et(1,o.Inject(f.SheetDataValidationModel)),et(2,o.Inject(o.Injector))],Ee);var hn=Object.getOwnPropertyDescriptor,vn=(e,t,r,n)=>{for(var a=n>1?void 0:n?hn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},tt=(e,t)=>(r,n)=>t(r,n,e);let Me=class extends o.Disposable{constructor(t,r,n){super();A(this,"_copyInfo");this._sheetClipboardService=t,this._sheetDataValidationModel=r,this._injector=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:f.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(t,r,n)=>this._collect(t,r,n),onPasteCells:(t,r,n,a)=>{const{copyType:i=B.COPY_TYPE.COPY,pasteType:s}=a,{range:d}=t||{},{range:l,unitId:c,subUnitId:h}=r;return this._generateMutations(l,{copyType:i,pasteType:s,copyRange:d,unitId:c,subUnitId:h})}})}_collect(t,r,n){const a=new o.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:r,matrix:a};const i=this._injector.invoke(l=>$.rangeToDiscreteRange(n,l,t,r));if(!i)return;const{rows:s,cols:d}=i;s.forEach((l,c)=>{d.forEach((h,p)=>{const u=this._sheetDataValidationModel.getRuleIdByLocation(t,r,l,h);a.setValue(c,p,u!=null?u:"")})})}_generateMutations(t,r){if(!this._copyInfo)return{redos:[],undos:[]};if(r.copyType===B.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!r.copyRange)return{redos:[],undos:[]};if([B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{unitId:a,subUnitId:i}=this._copyInfo;if(r.unitId!==a||i!==r.subUnitId){const s=this._sheetDataValidationModel.getRuleObjectMatrix(r.unitId,r.subUnitId).clone(),d=new o.ObjectMatrix,l=new Set,{ranges:[c,h],mapFunc:p}=B.virtualizeDiscreteRanges([r.copyRange,t]),u=B.getRepeatRange(c,h,!0),I=new Map;u.forEach(({startRange:m})=>{var y;(y=this._copyInfo)==null||y.matrix.forValue((S,D,w)=>{const C=o.Rectangle.getPositionRange({startRow:S,endRow:S,startColumn:D,endColumn:D},m),E=`${i}-${w}`,W=this._sheetDataValidationModel.getRuleById(a,i,w);!this._sheetDataValidationModel.getRuleById(r.unitId,r.subUnitId,E)&&W&&I.set(E,{...W,uid:E});const{row:x,col:O}=p(C.startRow,C.startColumn);l.add(E),d.setValue(x,O,E)})});const g=Array.from(l).map(m=>({id:m,ranges:o.queryObjectMatrix(d,y=>y===m)}));s.addRangeRules(g);const{redoMutations:V,undoMutations:T}=f.getDataValidationDiffMutations(r.unitId,r.subUnitId,s.diffWithAddition(this._sheetDataValidationModel.getRules(r.unitId,r.subUnitId),I.values()),this._injector,"patched",!1);return{redos:V,undos:T}}else{const s=this._sheetDataValidationModel.getRuleObjectMatrix(a,i).clone(),d=new o.ObjectMatrix,l=new Set,{ranges:[c,h],mapFunc:p}=B.virtualizeDiscreteRanges([r.copyRange,t]);B.getRepeatRange(c,h,!0).forEach(({startRange:T})=>{var m;(m=this._copyInfo)==null||m.matrix.forValue((y,S,D)=>{const w=o.Rectangle.getPositionRange({startRow:y,endRow:y,startColumn:S,endColumn:S},T),{row:C,col:E}=p(w.startRow,w.startColumn);d.setValue(C,E,D),l.add(D)})});const I=Array.from(l).map(T=>({id:T,ranges:o.queryObjectMatrix(d,m=>m===T)}));s.addRangeRules(I);const{redoMutations:g,undoMutations:V}=f.getDataValidationDiffMutations(a,i,s.diff(this._sheetDataValidationModel.getRules(a,i)),this._injector,"patched",!1);return{redos:g,undos:V}}}};Me=vn([tt(0,B.ISheetClipboardService),tt(1,o.Inject(f.SheetDataValidationModel)),tt(2,o.Inject(o.Injector))],Me);var pn=Object.getOwnPropertyDescriptor,gn=(e,t,r,n)=>{for(var a=n>1?void 0:n?pn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},nt=(e,t)=>(r,n)=>t(r,n,e);let be=class extends o.Disposable{constructor(e,t,r){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=r,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{e.id===f.AddSheetDataValidationCommand.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[$.WorkbookEditablePermission],rangeTypes:[$.RangeProtectionPermissionEditPoint],worksheetTypes:[$.WorksheetEditPermission,$.WorksheetSetCellStylePermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))),e.id===f.UpdateSheetDataValidationRangeCommand.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[$.WorkbookEditablePermission],rangeTypes:[$.RangeProtectionPermissionEditPoint],worksheetTypes:[$.WorksheetEditPermission,$.WorksheetSetCellStylePermission]},e.params.ranges)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr")))}))}};be=gn([nt(0,o.Inject(o.LocaleService)),nt(1,o.ICommandService),nt(2,o.Inject($.SheetPermissionCheckController))],be);const yt="sheet.menu.data-validation";function fn(e){return{id:yt,type:b.MenuItemType.SUBITEMS,icon:"DataValidationIcon",tooltip:"dataValidation.title",hidden$:b.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:B.getCurrentRangeDisable$(e,{workbookTypes:[$.WorkbookEditablePermission],worksheetTypes:[$.WorksheetSetCellStylePermission,$.WorksheetEditPermission],rangeTypes:[$.RangeProtectionPermissionEditPoint]})}}function mn(e){return{id:me.id,title:"dataValidation.panel.title",type:b.MenuItemType.BUTTON}}function Sn(e){return{id:Ue.id,title:"dataValidation.panel.add",type:b.MenuItemType.BUTTON}}const _n={[b.RibbonDataGroup.RULES]:{[yt]:{order:0,menuItemFactory:fn,[me.id]:{order:0,menuItemFactory:mn},[Ue.id]:{order:1,menuItemFactory:Sn}}}};var In=Object.getOwnPropertyDescriptor,wt=(e,t,r,n)=>{for(var a=n>1?void 0:n?In(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},G=(e,t)=>(r,n)=>t(r,n,e);const Dt={tr:{size:6,color:"#fe4b4b"}};let Te=class extends o.RxDisposable{constructor(e,t,r,n,a,i,s,d,l,c,h){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=r,this._univerInstanceService=n,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(_n)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{var r;if(!e.visible){((r=this._dropdownManagerService.activeDropdown)==null?void 0:r.trigger)==="editor-bridge"&&this._dropdownManagerService.hideDropdown();return}const t=this._editorBridgeService.getEditCellState();if(t){const{unitId:n,sheetId:a,row:i,column:s}=t,d=this._univerInstanceService.getUniverSheetInstance(n);if(!d)return;const l=this._sheetDataValidationModel.getRuleByLocation(n,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 p=this._dropdownManagerService.activeDropdown,u=p==null?void 0:p.location;if(u&&u.unitId===n&&u.subUnitId===a&&u.row===i&&u.col===s)return;this._dropdownManagerService.showDropdown({location:{unitId:n,subUnitId:a,row:i,col:s,workbook:d,worksheet:h},trigger:"editor-bridge",closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept($.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:$.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,r)=>{var m,y,S,D,w;const{row:n,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=t,c=this._sheetDataValidationModel.getRuleIdByLocation(i,s,n,a);if(!c)return r(e);const h=this._sheetDataValidationModel.getRuleById(i,s,c);if(!h)return r(e);const p=(m=this._dataValidationCacheService.getValue(i,s,n,a))!=null?m:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),I=t.rawData;let g;const V={get value(){var C;return g!==void 0||(g=(C=f.getCellValueOrigin(I))!=null?C:null),g}},T={get value(){var C;return`${(C=V.value)!=null?C:""}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...p===o.DataValidationStatus.INVALID?Dt: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:((S=e==null?void 0:e.fontRenderExtension)==null?void 0:S.isSkip)||((D=u==null?void 0:u.skipDefaultFontRender)==null?void 0:D.call(u,h,V.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,T.value,{get style(){const C=d.getStyles();return(typeof(e==null?void 0:e.s)=="string"?C.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},n,a)},e.interceptorAutoHeight=()=>{var x,O,U,k,N,H;const C=(O=(x=this._renderManagerService.getRenderById(i))==null?void 0:x.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:O.skeleton;if(!C)return;const E=C.worksheet.getMergedCell(n,a),W={data:e,style:C.getStyles().getStyleByCell(e),primaryWithCoord:C.getCellWithCoordByIndex((U=E==null?void 0:E.startRow)!=null?U:n,(k=E==null?void 0:E.startColumn)!=null?k:a),unitId:i,subUnitId:s,row:n,col:a,workbook:d,worksheet:l};return(H=(N=u==null?void 0:u.canvasRender)==null?void 0:N.calcCellAutoHeight)==null?void 0:H.call(N,W)},e.interceptorAutoWidth=()=>{var x,O,U,k,N,H;const C=(O=(x=this._renderManagerService.getRenderById(i))==null?void 0:x.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:O.skeleton;if(!C)return;const E=C.worksheet.getMergedCell(n,a),W={data:e,style:C.getStyles().getStyleByCell(e),primaryWithCoord:C.getCellWithCoordByIndex((U=E==null?void 0:E.startRow)!=null?U:n,(k=E==null?void 0:E.startColumn)!=null?k:a),unitId:i,subUnitId:s,row:n,col:a,workbook:d,worksheet:l};return(H=(N=u==null?void 0:u.canvasRender)==null?void 0:N.calcCellAutoWidth)==null?void 0:H.call(N,W)},e.coverable=((w=e==null?void 0:e.coverable)!=null?w:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE),r(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(ie.filter(e=>e.source==="command"),ie.bufferTime(100)).subscribe(e=>{if(e.length===0)return;const t=[];if(e.forEach(r=>{var n;(r.rule.type===o.DataValidationType.LIST_MULTIPLE||r.rule.type===o.DataValidationType.LIST)&&(n=r.rule)!=null&&n.ranges&&t.push(...r.rule.ranges)}),t.length){const r=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(r.redos,this._commandService)}})}};Te=wt([G(0,o.ICommandService),G(1,b.IMenuManagerService),G(2,P.IRenderManagerService),G(3,o.IUniverInstanceService),G(4,o.Inject(B.AutoHeightController)),G(5,o.Inject(fe)),G(6,o.Inject(f.SheetDataValidationModel)),G(7,o.Inject(X.DataValidatorRegistryService)),G(8,o.Inject($.SheetInterceptorService)),G(9,o.Inject(f.DataValidationCacheService)),G(10,o.Optional(B.IEditorBridgeService))],Te);let Et=class extends o.RxDisposable{constructor(e,t,r,n,a,i,s){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=r,this._dataValidatorRegistryService=n,this._sheetInterceptorService=a,this._sheetDataValidationModel=i,this._dataValidationCacheService=s,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept($.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:$.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,r)=>{var T,m,y,S,D;const{row:n,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=t,c=this._sheetDataValidationModel.getRuleIdByLocation(i,s,n,a);if(!c)return r(e);const h=this._sheetDataValidationModel.getRuleById(i,s,c);if(!h)return r(e);const p=(T=this._dataValidationCacheService.getValue(i,s,n,a))!=null?T:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),I=l.getCellRaw(n,a),g=f.getCellValueOrigin(I),V=`${g!=null?g:""}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...p===o.DataValidationStatus.INVALID?Dt:null},e.customRender=[...(m=e==null?void 0:e.customRender)!=null?m:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:((y=e==null?void 0:e.fontRenderExtension)==null?void 0:y.isSkip)||((S=u==null?void 0:u.skipDefaultFontRender)==null?void 0:S.call(u,h,g,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,V,{get style(){const w=d.getStyles();return(typeof(e==null?void 0:e.s)=="string"?w.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},n,a)},e.interceptorAutoHeight=()=>{var W,x,O,U,k,N;const w=(x=(W=this._renderManagerService.getRenderById(i))==null?void 0:W.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:x.skeleton;if(!w)return;const C=w.worksheet.getMergedCell(n,a),E={data:e,style:w.getStyles().getStyleByCell(e),primaryWithCoord:w.getCellWithCoordByIndex((O=C==null?void 0:C.startRow)!=null?O:n,(U=C==null?void 0:C.startColumn)!=null?U:a),unitId:i,subUnitId:s,row:n,col:a,workbook:d,worksheet:l};return(N=(k=u==null?void 0:u.canvasRender)==null?void 0:k.calcCellAutoHeight)==null?void 0:N.call(k,E)},e.interceptorAutoWidth=()=>{var W,x,O,U,k,N;const w=(x=(W=this._renderManagerService.getRenderById(i))==null?void 0:W.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:x.skeleton;if(!w)return;const C=w.worksheet.getMergedCell(n,a),E={data:e,style:w.getStyles().getStyleByCell(e),primaryWithCoord:w.getCellWithCoordByIndex((O=C==null?void 0:C.startRow)!=null?O:n,(U=C==null?void 0:C.startColumn)!=null?U:a),unitId:i,subUnitId:s,row:n,col:a,workbook:d,worksheet:l};return(N=(k=u==null?void 0:u.canvasRender)==null?void 0:k.calcCellAutoWidth)==null?void 0:N.call(k,E)},e.coverable=((D=e==null?void 0:e.coverable)!=null?D:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE),r(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(ie.filter(e=>e.source==="command"),ie.bufferTime(16)).subscribe(e=>{const t=[];if(e.forEach(r=>{var n;(r.rule.type===o.DataValidationType.LIST_MULTIPLE||r.rule.type===o.DataValidationType.LIST)&&(n=r.rule)!=null&&n.ranges&&t.push(...r.rule.ranges)}),t.length){const r=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(r.redos,this._commandService)}})}};Et=wt([G(0,o.ICommandService),G(1,P.IRenderManagerService),G(2,o.Inject(B.AutoHeightController)),G(3,o.Inject(X.DataValidatorRegistryService)),G(4,o.Inject($.SheetInterceptorService)),G(5,o.Inject(f.SheetDataValidationModel)),G(6,o.Inject(f.DataValidationCacheService))],Et);var Cn=Object.getOwnPropertyDescriptor,yn=(e,t,r,n)=>{for(var a=n>1?void 0:n?Cn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Mt=(e,t)=>(r,n)=>t(r,n,e);let Ne=class extends o.Disposable{constructor(e,t,r){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=r,this._initSkeletonChange()}_initSkeletonChange(){const e=t=>{var n;if(!t.length)return;const r=new Set;t.forEach(a=>{r.add(a.subUnitId)}),r.forEach(a=>{var i;(i=this._sheetSkeletonManagerService.getSkeletonParam(a))==null||i.skeleton.makeDirty(!0)}),(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(o.bufferDebounceTime(16)).subscribe(e))}};Ne=yn([Mt(1,o.Inject(f.SheetDataValidationModel)),Mt(2,o.Inject(B.SheetSkeletonManagerService))],Ne);function wn(e){var c;const t=b.useDependency(o.LocaleService),r=b.useDependency(b.ComponentManager),{value:n,onChange:a,extraComponent:i}=e,[s,d]=R.useState(!1),l=i?r.get(i):null;return v.jsxs(v.Fragment,{children:[v.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?v.jsx(ft,{className:"univer-ml-1"}):v.jsx(Ge,{className:"univer-ml-1"})]}),s&&v.jsxs(v.Fragment,{children:[l?v.jsx(l,{value:n,onChange:a}):null,v.jsx(M.FormLayout,{label:t.t("dataValidation.panel.invalid"),children:v.jsxs(M.RadioGroup,{value:`${(c=n.errorStyle)!=null?c:o.DataValidationErrorStyle.WARNING}`,onChange:h=>a({...n,errorStyle:+h}),children:[v.jsx(M.Radio,{value:`${o.DataValidationErrorStyle.WARNING}`,children:t.t("dataValidation.panel.showWarning")}),v.jsx(M.Radio,{value:`${o.DataValidationErrorStyle.STOP}`,children:t.t("dataValidation.panel.rejectInput")})]})}),v.jsx(M.FormLayout,{label:t.t("dataValidation.panel.messageInfo"),children:v.jsx(M.Checkbox,{checked:n.showErrorMessage,onChange:()=>a({...n,showErrorMessage:!n.showErrorMessage}),children:t.t("dataValidation.panel.showInfo")})}),n.showErrorMessage?v.jsx(M.FormLayout,{children:v.jsx(M.Input,{value:n.error,onChange:h=>a({...n,error:h})})}):null]})]})}const Dn=e=>o.debounce(async(t,r,n,a)=>{const i=await e.executeCommand(t,r,n);a==null||a(i)},1e3);function En(e,t,r){var n,a,i,s;return t?((a=(n=e.getUnit(t))==null?void 0:n.getSheetBySheetName(r))==null?void 0:a.getSheetId())||"":((s=(i=e.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetName(r))==null?void 0:s.getSheetId())||""}function Mn(){var L,Y;const[e,t]=R.useState(0),r=b.useDependency(ue),n=b.useObservable(r.activeRule$,r.activeRule),{unitId:a,subUnitId:i,rule:s}=n||{},d=s.uid,l=b.useDependency(X.DataValidatorRegistryService),c=b.useDependency(o.IUniverInstanceService),h=b.useDependency(b.ComponentManager),p=b.useDependency(o.ICommandService),u=b.useDependency(X.DataValidationModel),I=b.useDependency(o.LocaleService),[g,V]=R.useState(s),T=l.getValidatorItem(g.type),[m,y]=R.useState(!1),S=l.getValidatorsByScope(X.DataValidatorRegistryScope.SHEET),[D,w]=R.useState(()=>g.ranges.map(_=>({unitId:"",sheetId:"",range:_}))),C=R.useMemo(()=>Dn(p),[p]),[E,W]=R.useState(!1),[x,O]=R.useState(!1),U=R.useRef(null),k=b.useDependency($.SheetsSelectionsService);if(R.useEffect(()=>()=>{const _=k.getCurrentLastSelection();_&&k.setSelections([_])},[k]),R.useEffect(()=>{p.onCommandExecuted(_=>{(_.id===o.UndoCommand.id||_.id===o.RedoCommand.id)&&setTimeout(()=>{const j=u.getRuleById(a,i,d);t(z=>z+1),j&&(V(j),w(j.ranges.map(z=>({unitId:"",sheetId:"",range:z}))))},20)})},[p,u,d,i,a]),!T)return null;const N=T.operators,H=T.operatorNames,Z=g.operator?X.TWO_FORMULA_OPERATOR_COUNT.includes(g.operator):!1,K=()=>{var _,j,z;(j=(_=U.current)==null?void 0:_.editor)!=null&&j.isFocus()&&te((z=U.current)==null?void 0:z.getValue()),!(!g.ranges.length||E)&&(T.validatorFormula(g,a,i).success?r.setActiveRule(null):y(!0))},te=b.useEvent(_=>{const j=_.split(",").filter(Boolean).map(Ke.deserializeRangeWithSheet).map(re=>{const At=re.sheetName;if(At){const sr=En(c,re.unitId,At);return{...re,sheetId:sr}}return{...re,sheetId:""}});if(o.isUnitRangesEqual(j,D))return;w(j);const z=j.filter(re=>(!re.unitId||re.unitId===a)&&(!re.sheetId||re.sheetId===i)).map(re=>re.range);if(V({...g,ranges:z}),z.length===0)return;const pe={unitId:a,subUnitId:i,ruleId:d,ranges:z};C(f.UpdateSheetDataValidationRangeCommand.id,pe)}),ae=_=>{if(o.shallowEqual(_,X.getRuleSetting(g)))return;V({...g,..._});const j={unitId:a,subUnitId:i,ruleId:d,setting:_};C(f.UpdateSheetDataValidationSettingCommand.id,j,void 0)},se=async()=>{await p.executeCommand(f.RemoveSheetDataValidationCommand.id,{ruleId:d,unitId:a,subUnitId:i}),r.setActiveRule(null)},ce={type:g.type,operator:g.operator,formula1:g.formula1,formula2:g.formula2,allowBlank:g.allowBlank},J=_=>{const j=l.getValidatorItem(_);if(!j)return;const z=j.operators,pe=u.getRuleById(a,i,d),re=_===(pe==null?void 0:pe.type)||_.includes("list")&&(pe!=null&&pe.type.includes("list"))?{...pe,type:_}:{...g,type:_,operator:z[0],formula1:void 0,formula2:void 0};V(re),p.executeCommand(f.UpdateSheetDataValidationSettingCommand.id,{unitId:a,subUnitId:i,ruleId:g.uid,setting:X.getRuleSetting(re)})},q=h.get(T.formulaInput),ve=R.useMemo(()=>D.map(_=>Ke.serializeRange(_.range)).join(","),[]),ne=X.getRuleOptions(g),ee=_=>{o.shallowEqual(_,X.getRuleOptions(g))||(V({...g,..._}),C(f.UpdateSheetDataValidationOptionsCommand.id,{unitId:a,subUnitId:i,ruleId:d,options:_}))},Q=N.length&&!g.operator;return v.jsxs("div",{"data-u-comp":"data-validation-detail",className:"univer-py-2",children:[v.jsx(M.FormLayout,{label:I.t("dataValidation.panel.range"),error:!g.ranges.length||E?I.t("dataValidation.panel.rangeError"):"",children:v.jsx(ze.RangeSelector,{selectorRef:U,unitId:a,subUnitId:i,initialValue:ve,onChange:(_,j)=>{var z;!x&&((z=U.current)!=null&&z.verify())&&te(j)},onFocusChange:(_,j)=>{var z;O(_),!_&&j&&((z=U.current)!=null&&z.verify())&&te(j)},onVerify:_=>W(!_)})}),v.jsx(M.FormLayout,{label:I.t("dataValidation.panel.type"),children:v.jsx(M.Select,{className:"univer-w-full",value:g.type,options:(L=S==null?void 0:S.sort((_,j)=>_.order-j.order))==null?void 0:L.map(_=>({label:I.t(_.title),value:_.id})),onChange:J})}),N!=null&&N.length?v.jsx(M.FormLayout,{label:I.t("dataValidation.panel.operator"),children:v.jsx(M.Select,{className:"univer-w-full",value:`${g.operator}`,options:[{value:"",label:I.t("dataValidation.operators.legal")},...N.map((_,j)=>({value:`${_}`,label:H[j]}))],onChange:_=>{ae({...ce,operator:_})}})}):null,q&&!Q?v.jsx(q,{isTwoFormula:Z,value:{formula1:g.formula1,formula2:g.formula2},onChange:_=>{ae({...ce,..._})},showError:m,validResult:T.validatorFormula(g,a,i),unitId:a,subUnitId:i,ruleId:d},e+g.type):null,v.jsx(M.FormLayout,{children:v.jsx(M.Checkbox,{checked:(Y=g.allowBlank)!=null?Y:!0,onChange:()=>{var _;return ae({...ce,allowBlank:!((_=g.allowBlank)==null||_)})},children:I.t("dataValidation.panel.allowBlank")})}),v.jsx(wn,{value:ne,onChange:ee,extraComponent:T.optionsInput}),v.jsxs("div",{className:"univer-mt-5 univer-flex univer-flex-row univer-justify-end",children:[v.jsx(M.Button,{className:"univer-ml-3",onClick:se,children:I.t("dataValidation.panel.removeRule")}),v.jsx(M.Button,{className:"univer-ml-3",variant:"primary",onClick:K,children:I.t("dataValidation.panel.done")})]})]})}const bn=e=>{const{rule:t,onClick:r,unitId:n,subUnitId:a,disable:i}=e,s=b.useDependency(X.DataValidatorRegistryService),d=b.useDependency(o.ICommandService),l=b.useDependency(B.IMarkSelectionService),c=s.getValidatorItem(t.type),h=R.useRef(void 0),[p,u]=R.useState(!1),I=b.useDependency(o.ThemeService),g=b.useObservable(I.currentTheme$),V=R.useMemo(()=>{var w;const m=I.getColorFromTheme("primary.600"),y=I.getColorFromTheme("loop-color.2"),S=(w=I.getColorFromTheme(y))!=null?w:m,D=new o.ColorKit(S).toRgb();return{fill:`rgba(${D.r}, ${D.g}, ${D.b}, 0.1)`,stroke:S}},[g]),T=m=>{d.executeCommand(f.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:n,subUnitId:a}),m.stopPropagation()};return R.useEffect(()=>()=>{var m;h.current&&((m=h.current)==null||m.forEach(y=>{y&&l.removeShape(y)}))},[l]),v.jsxs("div",{className:M.clsx(`
|
|
15
15
|
univer-rounded-md univer-bg-secondary univer-relative univer--ml-2 univer--mr-2 univer-box-border
|
|
16
16
|
univer-flex univer-w-[287px] univer-cursor-pointer univer-flex-col univer-justify-between
|
|
17
17
|
univer-overflow-hidden univer-p-2 univer-pr-9
|
|
18
|
-
`,{"hover:univer-bg-gray-50":!i,"univer-opacity-50":i}),onClick:r,onMouseEnter:()=>{i||(u(!0),h.current=t.ranges.map(m=>l.addShape({range:m,style:O,primary:null})))},onMouseLeave:()=>{var m;u(!1),(m=h.current)==null||m.forEach(C=>{C&&l.removeShape(C)}),h.current=void 0},children:[v.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)}),v.jsx("div",{className:"univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px]",children:t.ranges.map(m=>Ge.serializeRange(m)).join(",")}),p?v.jsx("div",{className:"univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-h-5 univer-w-5 univer-items-center univer-justify-center univer-rounded hover:univer-bg-gray-200",onClick:T,children:v.jsx(qe,{})}):null]})};function On(e){const t=b.useDependency(f.SheetDataValidationModel),r=b.useDependency(o.IUniverInstanceService),n=b.useDependency(o.ICommandService),a=b.useDependency(o.Injector),i=b.useDependency(de),s=b.useDependency(o.LocaleService),[d,l]=V.useState([]),{workbook:c}=e,h=b.useObservable(c.activeSheet$,void 0,!0),p=c.getUnitId(),u=h==null?void 0:h.getSheetId();V.useEffect(()=>{l(t.getRules(p,u));const C=t.ruleChange$.subscribe(S=>{S.unitId===p&&S.subUnitId===u&&l(t.getRules(p,u))});return()=>{C.unsubscribe()}},[p,u,t]);const _=async()=>{const C=f.createDefaultNewRule(a),S={unitId:p,subUnitId:u,rule:C};await n.executeCommand(f.AddSheetDataValidationCommand.id,S),i.setActiveRule({unitId:p,subUnitId:u,rule:C})},g=()=>{n.executeCommand(f.RemoveSheetAllDataValidationCommand.id,{unitId:p,subUnitId:u})},T=(C=>{const S=r.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),y=S.getActiveSheet(),D=S.getUnitId(),w=y.getSheetId();return C.map(F=>$.checkRangesEditablePermission(a,D,w,F.ranges)?{...F}:{...F,disable:!0})})(d),m=T==null?void 0:T.some(C=>C.disable);return v.jsxs("div",{className:"univer-pb-4",children:[T==null?void 0:T.map(C=>{var S;return v.jsx(Vn,{unitId:p,subUnitId:u,onClick:()=>{C.disable||i.setActiveRule({unitId:p,subUnitId:u,rule:C})},rule:C,disable:(S=C.disable)!=null?S:!1},C.uid)}),v.jsxs("div",{className:"univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[d.length&&!m?v.jsx(M.Button,{onClick:g,children:s.t("dataValidation.panel.removeAll")}):null,v.jsx(M.Button,{variant:"primary",onClick:_,children:s.t("dataValidation.panel.add")})]})]})}const Rn=()=>{const e=b.useDependency(de),t=b.useObservable(e.activeRule$,e.activeRule),r=b.useDependency(o.IUniverInstanceService),n=b.useObservable(()=>r.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),a=b.useObservable(()=>{var i;return(i=n==null?void 0:n.activeSheet$)!=null?i:te.of(null)},void 0,void 0,[]);return!n||!a?null:t&&t.subUnitId===a.getSheetId()?v.jsx(Tn,{},t.rule.uid):v.jsx(On,{workbook:n})},Pn="LIST_RENDER_MODE_OPTION_INPUT";function je(e){var a;const{value:t,onChange:r}=e,n=b.useDependency(o.LocaleService);return v.jsx(M.FormLayout,{label:n.t("dataValidation.renderMode.label"),children:v.jsxs(M.RadioGroup,{value:`${(a=t.renderMode)!=null?a:o.DataValidationRenderMode.CUSTOM}`,onChange:i=>r({...t,renderMode:+i}),children:[v.jsx(M.Radio,{value:`${o.DataValidationRenderMode.CUSTOM}`,children:n.t("dataValidation.renderMode.chip")}),v.jsx(M.Radio,{value:`${o.DataValidationRenderMode.ARROW}`,children:n.t("dataValidation.renderMode.arrow")}),v.jsx(M.Radio,{value:`${o.DataValidationRenderMode.TEXT}`,children:n.t("dataValidation.renderMode.text")})]})})}je.componentKey=Pn;const An="DATE_SHOW_TIME_OPTION";function Be(e){var a;const{value:t,onChange:r}=e,n=b.useDependency(o.LocaleService);return v.jsx(M.FormLayout,{children:v.jsx(M.Checkbox,{checked:(a=t.bizInfo)==null?void 0:a.showTime,onChange:i=>{r({...t,bizInfo:{...t.bizInfo,showTime:i}})},children:n.t("dataValidation.showTime.label")})})}Be.componentKey=An;var Ln=Object.getOwnPropertyDescriptor,Nn=(e,t,r,n)=>{for(var a=n>1?void 0:n?Ln(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Ve=(e,t)=>(r,n)=>t(r,n,e);const He=6;let at=class{constructor(e,t,r,n,a,i){this._commandService=e,this._univerInstanceService=t,this._formulaService=r,this._themeService=n,this._renderManagerService=a,this._dataValidationModel=i}_calc(e,t){var c,h,p;const{vt:r,ht:n}=t||{},a=e.endX-e.startX-He*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(r){case o.VerticalAlign.TOP:l=0;break;case o.VerticalAlign.BOTTOM:l=0+(i-s);break;default:l=0+(i-s)/2;break}switch(n){case o.HorizontalAlign.LEFT:d=He;break;case o.HorizontalAlign.RIGHT:d=He+(a-s);break;default:d=He+(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:((p=t==null?void 0:t.fs)!=null?p:10)*1.6}}calcCellAutoHeight(e){var r;const{style:t}=e;return((r=t==null?void 0:t.fs)!=null?r:10)*1.6}calcCellAutoWidth(e){var r;const{style:t}=e;return((r=t==null?void 0:t.fs)!=null?r:10)*1.6}async _parseFormula(e,t,r){var c,h,p,u,_,g,O,T,m;const{formula1:n=f.CHECKBOX_FORMULA_1,formula2:a=f.CHECKBOX_FORMULA_2}=e,i=await this._formulaService.getRuleFormulaResult(t,r,e.uid),s=f.getFormulaResult((p=(h=(c=i==null?void 0:i[0])==null?void 0:c.result)==null?void 0:h[0])==null?void 0:p[0]),d=f.getFormulaResult((g=(_=(u=i==null?void 0:i[1])==null?void 0:u.result)==null?void 0:_[0])==null?void 0:g[0]),l=f.isLegalFormulaResult(String(s))&&f.isLegalFormulaResult(String(d));return{formula1:o.isFormulaString(n)?f.getFormulaResult((m=(T=(O=i==null?void 0:i[0])==null?void 0:O.result)==null?void 0:T[0])==null?void 0:m[0]):n,formula2:o.isFormulaString(a)?d:a,isFormulaValid:l}}drawWith(e,t){var k,j,B,A;const{style:r,primaryWithCoord:n,unitId:a,subUnitId:i,worksheet:s,row:d,col:l}=t,c=n.isMergedMainCell?n.mergeInfo:n,h=f.getCellValueOrigin(s.getCellRaw(d,l)),p=this._dataValidationModel.getRuleByLocation(a,i,d,l);if(!p)return;const u=this._dataValidationModel.getValidator(p.type);if(!u||!((k=u.skipDefaultFontRender)!=null&&k.call(u,p,h,{unitId:a,subUnitId:i,row:d,column:l})))return;const _=u.parseFormulaSync(p,a,i),{formula1:g}=_,O=this._calc(c,r),{a:T,d:m}=e.getTransform(),C=N.fixLineWidthByScale(O.left,T),S=N.fixLineWidthByScale(O.top,m),y=N.Transform.create().composeMatrix({left:C,top:S,scaleX:1,scaleY:1,angle:0,skewX:0,skewY:0,flipX:!1,flipY:!1}),D=c.endX-c.startX,w=c.endY-c.startY;e.save(),e.beginPath(),e.rect(c.startX,c.startY,D,w),e.clip();const E=y.getMatrix();e.transform(E[0],E[1],E[2],E[3],E[4],E[5]);const F=((j=r==null?void 0:r.fs)!=null?j:10)*1.6,x=String(h)===String(g),P=this._themeService.getColorFromTheme("primary.600");N.CheckboxShape.drawWith(e,{checked:x,width:F,height:F,fill:(A=(B=r==null?void 0:r.cl)==null?void 0:B.rgb)!=null?A:P}),e.restore()}isHit(e,t){const r=t.primaryWithCoord.isMergedMainCell?t.primaryWithCoord.mergeInfo:t.primaryWithCoord,n=this._calc(r,t.style),a=n.top,i=n.top+n.height,s=n.left,d=n.left+n.width,{x:l,y:c}=e;return l<=d&&l>=s&&c<=i&&c>=a}async onPointerDown(e,t){var g;if(t.button===2)return;const{primaryWithCoord:r,unitId:n,subUnitId:a,worksheet:i,row:s,col:d}=e,l=f.getCellValueOrigin(i.getCellRaw(s,d)),c=this._dataValidationModel.getRuleByLocation(n,a,s,d);if(!c)return;const h=this._dataValidationModel.getValidator(c.type);if(!h||!((g=h.skipDefaultFontRender)!=null&&g.call(h,c,l,{unitId:n,subUnitId:a,row:s,column:d})))return;const{formula1:p,formula2:u}=await this._parseFormula(c,n,a),_={range:{startColumn:r.actualColumn,endColumn:r.actualColumn,startRow:r.actualRow,endRow:r.actualRow},value:{v:String(l)===f.transformCheckboxValue(String(p))?u:p,p:null}};this._commandService.executeCommand($.SetRangeValuesCommand.id,_)}onPointerEnter(e,t){var r,n;(n=(r=N.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null||n.setCursor(N.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var r,n;(n=(r=N.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null||n.setCursor(N.CURSOR_TYPE.DEFAULT)}};at=Nn([Ve(0,o.ICommandService),Ve(1,o.IUniverInstanceService),Ve(2,o.Inject(f.DataValidationFormulaService)),Ve(3,o.Inject(o.ThemeService)),Ve(4,o.Inject(N.IRenderManagerService)),Ve(5,o.Inject(f.SheetDataValidationModel))],at);class Un extends L.BaseSheetDataValidatorView{constructor(){super(...arguments);R(this,"id",o.DataValidationType.CHECKBOX);R(this,"canvasRender",this.injector.createInstance(at));R(this,"formulaInput",f.CHECKBOX_FORMULA_INPUT_NAME)}}class Fn extends L.BaseSheetDataValidatorView{constructor(){super(...arguments);R(this,"id",o.DataValidationType.CUSTOM);R(this,"formulaInput",f.CUSTOM_FORMULA_INPUT_NAME)}}const kn="data-validation.formula-input";class jn extends L.BaseSheetDataValidatorView{constructor(){super(...arguments);R(this,"id",o.DataValidationType.DATE);R(this,"formulaInput",kn);R(this,"optionsInput",Be.componentKey);R(this,"dropdownType",Y.DataValidatorDropdownType.DATE)}}class Bn extends L.BaseSheetDataValidatorView{constructor(){super(...arguments);R(this,"id",o.DataValidationType.DECIMAL);R(this,"formulaInput",f.BASE_FORMULA_INPUT_NAME)}}const Vt=4,Hn=0,it=4,Ot=4,ot=6,We=6,_e=14;function Wn(e,t){const r=N.FontCache.getTextSize(e,t),n=r.width+Vt*2,{ba:a,bd:i}=r,s=a+i;return{width:n,height:s+Hn*2,ba:a}}function st(e,t,r,n){const a=_e+ot*2,i=r-a,s=n-We*2,d=e.map(u=>({layout:Wn(u,t),text:u}));let l;const c=[];d.forEach(u=>{const{layout:_}=u,{width:g,height:O}=_;!l||l.width+g+it>i?(l={width:g,height:O,items:[{...u,left:0}]},c.push(l)):(l.items.push({...u,left:l.width+it}),l.width=l.width+g+it)});let h=0,p=0;return c.forEach((u,_)=>{p=Math.max(p,u.width),_===c.length-1?h+=u.height:h+=u.height+Ot}),{lines:c,totalHeight:h,contentWidth:i,contentHeight:s,cellAutoHeight:h+We*2,calcAutoWidth:p+a}}const xn=8;class $n extends N.Shape{static drawWith(t,r){const{fontString:n,info:a,fill:i,color:s}=r,{layout:d,text:l}=a;t.save(),N.Rect.drawWith(t,{width:d.width,height:d.height,radius:xn,fill:i||Ce}),t.translateWithPrecision(Vt,d.ba),t.font=n,t.fillStyle=s,t.fillText(l,0,0),t.restore()}}var Yn=Object.getOwnPropertyDescriptor,Xn=(e,t,r,n)=>{for(var a=n>1?void 0:n?Yn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},xe=(e,t)=>(r,n)=>t(r,n,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 lt=class{constructor(e,t,r,n){R(this,"zIndex");R(this,"_dropdownInfoMap",new Map);this._commandService=e,this._univerInstanceService=t,this._renderManagerService=r,this._dataValidationModel=n}_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,r,n,a){const i=r-_e+4;let s=4;switch(a){case o.VerticalAlign.MIDDLE:s=(n-_e)/2+4;break;case o.VerticalAlign.BOTTOM:s=n-_e+4;break}e.save(),e.translateWithPrecision(t.startX+i,t.startY+s),e.fillStyle="#565656",e.fill(zn),e.restore()}drawWith(e,t,r,n){var Q,J;const{primaryWithCoord:a,row:i,col:s,style:d,data:l,subUnitId:c}=t,h=a.isMergedMainCell?a.mergeInfo:a,p=l==null?void 0:l.fontRenderExtension,{leftOffset:u=0,rightOffset:_=0,topOffset:g=0,downOffset:O=0}=p||{},T=this._ensureMap(c),m=this._generateKey(i,s),C=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,i,s);if(!C)return;const S=this._dataValidationModel.getValidator(C.type);if(!S)return;const y={startX:h.startX+u,endX:h.endX-_,startY:h.startY+g,endY:h.endY-O},D=y.endX-y.startX,w=y.endY-y.startY,{cl:E}=d||{},F=(Q=typeof E=="object"?E==null?void 0:E.rgb:E)!=null?Q:"#000",x=N.getFontStyleString(d!=null?d:void 0),{vt:P,ht:k}=d||{},j=P!=null?P:o.VerticalAlign.MIDDLE,B=(J=f.getCellValueOrigin(l))!=null?J:"",A=S.parseCellValue(B),X=S.getListWithColorMap(C),z=st(A,x,D,w);this._drawDownIcon(e,y,D,w,j),e.save(),e.translateWithPrecision(y.startX,y.startY),e.beginPath(),e.rect(0,0,D-_e,w),e.clip(),e.translateWithPrecision(ot,We);let Z=0;switch(j){case o.VerticalAlign.MIDDLE:Z=(z.contentHeight-z.totalHeight)/2;break;case o.VerticalAlign.BOTTOM:Z=z.contentHeight-z.totalHeight;break}e.translateWithPrecision(0,Z),z.lines.forEach((re,ue)=>{e.save();const{width:se,height:ae,items:le}=re;let ve=0;switch(k){case o.HorizontalAlign.RIGHT:ve=z.contentWidth-se;break;case o.HorizontalAlign.CENTER:ve=(z.contentWidth-se)/2;break}e.translate(ve,ue*(ae+Ot)),le.forEach(he=>{e.save(),e.translateWithPrecision(he.left,0),$n.drawWith(e,{...x,info:he,color:F,fill:X[he.text]}),e.restore()}),e.restore()}),e.restore(),T.set(m,{left:y.startX,top:y.startY,width:z.contentWidth+ot+_e,height:z.contentHeight+We*2})}calcCellAutoHeight(e){var D;const{primaryWithCoord:t,style:r,data:n,row:a,col:i}=e,s=n==null?void 0:n.fontRenderExtension,{leftOffset:d=0,rightOffset:l=0,topOffset:c=0,downOffset:h=0}=s||{},p=t.isMergedMainCell?t.mergeInfo:t,u={startX:p.startX+d,endX:p.endX-l,startY:p.startY+c,endY:p.endY-h},_=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!_)return;const g=this._dataValidationModel.getValidator(_.type);if(!g)return;const O=u.endX-u.startX,T=u.endY-u.startY,m=(D=f.getCellValueOrigin(n))!=null?D:"",C=g.parseCellValue(m),S=N.getFontStyleString(r!=null?r:void 0);return st(C,S,O,T).cellAutoHeight}calcCellAutoWidth(e){var D;const{primaryWithCoord:t,style:r,data:n,row:a,col:i}=e,s=n==null?void 0:n.fontRenderExtension,{leftOffset:d=0,rightOffset:l=0,topOffset:c=0,downOffset:h=0}=s||{},p=t.isMergedMainCell?t.mergeInfo:t,u={startX:p.startX+d,endX:p.endX-l,startY:p.startY+c,endY:p.endY-h},_=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!_)return;const g=this._dataValidationModel.getValidator(_.type);if(!g)return;const O=u.endX-u.startX,T=u.endY-u.startY,m=(D=f.getCellValueOrigin(n))!=null?D:"",C=g.parseCellValue(m),S=N.getFontStyleString(r!=null?r:void 0);return st(C,S,O,T).calcAutoWidth}isHit(e,t){const{primaryWithCoord:r}=t,n=r.isMergedMainCell?r.mergeInfo:r,{endX:a}=n,{x:i}=e;return i>=a-_e&&i<=a}onPointerDown(e,t){if(t.button===2)return;const{unitId:r,subUnitId:n,row:a,col:i}=e,s={unitId:r,subUnitId:n,row:a,column:i};this._commandService.executeCommand(Ue.id,s)}onPointerEnter(e,t){var r,n;return(n=(r=N.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null?void 0:n.setCursor(N.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var r,n;return(n=(r=N.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null?void 0:n.setCursor(N.CURSOR_TYPE.DEFAULT)}};lt=Xn([xe(0,o.ICommandService),xe(1,o.IUniverInstanceService),xe(2,o.Inject(N.IRenderManagerService)),xe(3,o.Inject(f.SheetDataValidationModel))],lt);class Kn extends L.BaseSheetDataValidatorView{constructor(){super(...arguments);R(this,"id",o.DataValidationType.LIST_MULTIPLE);R(this,"canvasRender",this.injector.createInstance(lt));R(this,"dropdownType",Y.DataValidatorDropdownType.MULTIPLE_LIST)}}var Gn=Object.getOwnPropertyDescriptor,qn=(e,t,r,n)=>{for(var a=n>1?void 0:n?Gn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Ae=(e,t)=>(r,n)=>t(r,n,e);const Ie=4,$e=4,oe=14,ce=6,Oe=4,dt=8,Zn="#565656",Rt=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 Jn(e,t){const r=e.length;return{id:"d",body:{dataStream:`${e}${o.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[{ts:{fs:11,ff:void 0,it:o.BooleanNumber.FALSE,bl:o.BooleanNumber.FALSE,ul:{s:o.BooleanNumber.FALSE},st:{s:o.BooleanNumber.FALSE},ol:{s:o.BooleanNumber.FALSE},cl:void 0,...t,bg:void 0,bd:void 0},st:0,ed:r}]},documentStyle:{pageSize:{width:Number.POSITIVE_INFINITY,height:Number.POSITIVE_INFINITY}}}}function Pt(e,t,r){const n=Jn(e,r),a=new o.DocumentDataModel(n),i=new N.DocumentViewModel(a);return{documentSkeleton:N.DocumentSkeleton.create(i,t),docModel:a,docViewModel:i}}function Ye(e,t,r){const{documentSkeleton:n,docModel:a,docViewModel:i}=Pt(e,t,r);return{documents:new N.Documents(`DOCUMENTS_${o.Tools.generateRandomId()}`,n,{pageMarginLeft:0,pageMarginTop:0}),documentSkeleton:n,docModel:a,docViewModel:i}}function At(e,t,r,n,a,i,s=!0){let d=0;const l=s?Oe:0;switch(a){case o.VerticalAlign.BOTTOM:d=t-n-l;break;case o.VerticalAlign.MIDDLE:d=(t-n)/2;break;default:d=l;break}d=Math.max(Oe,d);let c=0;switch(i){case o.HorizontalAlign.CENTER:c=(e-r)/2;break;case o.HorizontalAlign.RIGHT:c=e-r;break}return c=Math.max(ce,c),{paddingLeft:c,paddingTop:d}}let ct=class{constructor(e,t,r,n,a){R(this,"_dropdownInfoMap",new Map);R(this,"zIndex");this._univerInstanceService=e,this._localeService=t,this._commandService=r,this._renderManagerService=n,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,r,n,a,i,s){const{t:d=o.DEFAULT_STYLES.pd.t,b:l=o.DEFAULT_STYLES.pd.b}=s,c=r-oe;let h;switch(i){case o.VerticalAlign.MIDDLE:h=(n-$e)/2;break;case o.VerticalAlign.BOTTOM:h=n-l-a-Oe+(a/2-$e/2);break;default:h=d+Oe+(a/2-$e/2);break}e.save(),e.translateWithPrecision(t.startX+c,t.startY+h),e.fillStyle="#565656",e.fill(Rt),e.restore()}drawWith(e,t,r){const{primaryWithCoord:n,row:a,col:i,style:s,data:d,subUnitId:l}=t,c=n.isMergedMainCell?n.mergeInfo:n,h=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,a,i);if(!h)return;const p=this._dataValidationModel.getValidator(h.type);if(!p)return;const u=d==null?void 0:d.fontRenderExtension,{leftOffset:_=0,rightOffset:g=0,topOffset:O=0,downOffset:T=0}=u||{};if(!h||!p||!p||p.id.indexOf(o.DataValidationType.LIST)!==0||!p.skipDefaultFontRender(h))return;const m={startX:c.startX+_,endX:c.endX-g,startY:c.startY+O,endY:c.endY-T},C=m.endX-m.startX,S=m.endY-m.startY,y=this._ensureMap(l),D=this._generateKey(a,i),w=p.getListWithColor(h),E=f.getCellValueOrigin(d),F=`${E!=null?E:""}`,x=w.find(A=>A.label===F);let{tb:P,vt:k,ht:j,pd:B}=s||{};if(P=P!=null?P:o.WrapStrategy.WRAP,k=k!=null?k:o.VerticalAlign.BOTTOM,j=j!=null?j:o.DEFAULT_STYLES.ht,B=B!=null?B:o.DEFAULT_STYLES.pd,h.renderMode===o.DataValidationRenderMode.ARROW){const{l:A=o.DEFAULT_STYLES.pd.l,t:X=o.DEFAULT_STYLES.pd.t,r:z=o.DEFAULT_STYLES.pd.r,b:Z=o.DEFAULT_STYLES.pd.b}=B,Q=C-A-z-oe-4,{documentSkeleton:J,documents:re,docModel:ue}=Ye(F,this._localeService,s);P===o.WrapStrategy.WRAP&&ue.updateDocumentDataPageSize(Math.max(Q,1)),J.calculate(),J.getActualSize();const se=N.getDocsSkeletonPageSize(J),{height:ae,width:le}=se,{paddingTop:ve,paddingLeft:he}=At(Q,S-X-Z,le,ae,k,j,!0);this._drawDownIcon(e,m,C,S,ae,k,B),e.save(),e.translateWithPrecision(m.startX+A,m.startY+X),e.beginPath(),e.rect(0,0,C-A-z,S-X-Z),e.clip(),e.translateWithPrecision(0,ve),e.save(),e.translateWithPrecision(Ie,0),e.beginPath(),e.rect(0,0,Q,ae),e.clip(),re.render(e),e.translateWithPrecision(he,0),e.restore(),e.restore(),y.set(D,{left:m.endX+A+r.rowHeaderWidth-oe,top:m.startY+X+r.columnHeaderHeight,width:oe,height:S-X-Z})}else{e.save(),e.translateWithPrecision(m.startX,m.startY),e.beginPath(),e.rect(0,0,C,S),e.clip();const A=C-ce*2-Ie-oe-4,{documentSkeleton:X,documents:z,docModel:Z}=Ye(F,this._localeService,s);P===o.WrapStrategy.WRAP&&Z.updateDocumentDataPageSize(Math.max(A,1)),X.calculate();const Q=N.getDocsSkeletonPageSize(X),{height:J,width:re}=Q,{paddingTop:ue,paddingLeft:se}=At(A,S,re,J,k,j);e.translateWithPrecision(ce,ue);const ae=Math.max(C-ce*2,1),le=J;N.Rect.drawWith(e,{width:ae,height:le,fill:(x==null?void 0:x.color)||Ce,radius:dt}),e.save(),e.translateWithPrecision(Ie,0),e.beginPath(),e.rect(0,0,A,J),e.clip(),e.translateWithPrecision(se,0),z.render(e),e.restore(),e.translateWithPrecision(A+Ie+4,(J-$e)/2),e.fillStyle=Zn,e.fill(Rt),e.restore(),y.set(D,{left:m.startX+ce+r.rowHeaderWidth,top:m.startY+ue+r.columnHeaderHeight,width:ae,height:le})}}calcCellAutoHeight(e){const{primaryWithCoord:t,style:r,data:n,row:a,col:i}=e,s=t.isMergedMainCell?t.mergeInfo:t,d=n==null?void 0:n.fontRenderExtension,{leftOffset:l=0,rightOffset:c=0,topOffset:h=0,downOffset:p=0}=d||{},u=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!u||u.renderMode===o.DataValidationRenderMode.TEXT)return;const _={startX:s.startX+l,endX:s.endX-c,startY:s.startY+h,endY:s.endY-p},g=_.endX-_.startX,O=f.getCellValueOrigin(n),T=`${O!=null?O:""}`;let{tb:m,pd:C}=r||{};const{t:S=o.DEFAULT_STYLES.pd.t,b:y=o.DEFAULT_STYLES.pd.b}=C!=null?C:{};if(m=m!=null?m:o.WrapStrategy.WRAP,u.renderMode===o.DataValidationRenderMode.ARROW){const D=g-oe,{documentSkeleton:w,docModel:E}=Ye(T,this._localeService,r);m===o.WrapStrategy.WRAP&&E.updateDocumentDataPageSize(Math.max(D,1)),w.calculate(),w.getActualSize();const F=N.getDocsSkeletonPageSize(w),{height:x}=F;return x+S+y+Oe*2}else{const D=g-ce*2-Ie-oe,{documentSkeleton:w,docModel:E}=Pt(T,this._localeService,r);m===o.WrapStrategy.WRAP&&E.updateDocumentDataPageSize(Math.max(D,1)),w.calculate();const F=N.getDocsSkeletonPageSize(w),{height:x}=F;return x+Oe*2}}calcCellAutoWidth(e){const{primaryWithCoord:t,style:r,data:n,row:a,col:i}=e,s=t.isMergedMainCell?t.mergeInfo:t,d=n==null?void 0:n.fontRenderExtension,{leftOffset:l=0,rightOffset:c=0,topOffset:h=0,downOffset:p=0}=d||{},u=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!u||u.renderMode===o.DataValidationRenderMode.TEXT)return;const _={startX:s.startX+l,endX:s.endX-c,startY:s.startY+h,endY:s.endY-p},g=_.endX-_.startX,O=f.getCellValueOrigin(n),T=`${O!=null?O:""}`;let{tb:m,pd:C}=r||{};const{l:S=o.DEFAULT_STYLES.pd.l,r:y=o.DEFAULT_STYLES.pd.r}=C!=null?C:{};m=m!=null?m:o.WrapStrategy.WRAP;let D=ce*2+oe;switch(u.renderMode){case o.DataValidationRenderMode.ARROW:D=oe+ce*2+y+S;break;case o.DataValidationRenderMode.CUSTOM:D=oe+ce*2+Ie*2+y+S+dt/2+1;break;default:D=oe+ce*2+Ie*2+y+S+dt/2+1}const w=g-D,{documentSkeleton:E,docModel:F}=Ye(T,this._localeService,r);return m===o.WrapStrategy.WRAP&&F.updateDocumentDataPageSize(Math.max(w,1)),E.calculate(),E.getActualSize(),N.getDocsSkeletonPageSize(E).width+D}isHit(e,t){const{subUnitId:r,row:n,col:a}=t,s=this._ensureMap(r).get(this._generateKey(n,a)),d=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,n,a);if(!d||!s||d.renderMode===o.DataValidationRenderMode.TEXT)return!1;const{top:l,left:c,width:h,height:p}=s,{x:u,y:_}=e;return u>=c&&u<=c+h&&_>=l&&_<=l+p}onPointerDown(e,t){if(t.button===2)return;const{unitId:r,subUnitId:n,row:a,col:i}=e,s={unitId:r,subUnitId:n,row:a,column:i};this._commandService.executeCommand(Ue.id,s)}onPointerEnter(e,t){var r,n;(n=(r=N.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null||n.setCursor(N.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var r,n;(n=(r=N.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null||n.setCursor(N.CURSOR_TYPE.DEFAULT)}};ct=qn([Ae(0,o.IUniverInstanceService),Ae(1,o.Inject(o.LocaleService)),Ae(2,o.ICommandService),Ae(3,o.Inject(N.IRenderManagerService)),Ae(4,o.Inject(f.SheetDataValidationModel))],ct);class Qn extends L.BaseSheetDataValidatorView{constructor(){super(...arguments);R(this,"id",o.DataValidationType.LIST);R(this,"canvasRender",this.injector.createInstance(ct));R(this,"dropdownType",Y.DataValidatorDropdownType.LIST);R(this,"optionsInput",je.componentKey);R(this,"formulaInput",f.LIST_FORMULA_INPUT_NAME)}}class er extends L.BaseSheetDataValidatorView{constructor(){super(...arguments);R(this,"id",o.DataValidationType.TEXT_LENGTH);R(this,"formulaInput",f.BASE_FORMULA_INPUT_NAME)}}class tr extends L.BaseSheetDataValidatorView{constructor(){super(...arguments);R(this,"id",o.DataValidationType.WHOLE);R(this,"formulaInput",f.BASE_FORMULA_INPUT_NAME)}}var nr=Object.getOwnPropertyDescriptor,rr=(e,t,r,n)=>{for(var a=n>1?void 0:n?nr(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ut=(e,t)=>(r,n)=>t(r,n,e);let Re=class extends o.RxDisposable{constructor(e,t,r){super(),this._injector=e,this._componentManger=t,this._dataValidatorRegistryService=r,this._initComponents(),this._registerValidatorViews()}_initComponents(){[[wt,gt],[Ne,Rn],[je.componentKey,je],[Be.componentKey,Be],...Jt].forEach(([e,t])=>{this.disposeWithMe(this._componentManger.register(e,t))})}_registerValidatorViews(){[Bn,tr,er,jn,Un,Qn,Kn,Fn].forEach(e=>{const t=this._injector.createInstance(e),r=this._dataValidatorRegistryService.getValidatorItem(t.id);r&&(r.formulaInput=t.formulaInput,r.canvasRender=t.canvasRender,r.dropdownType=t.dropdownType,r.optionsInput=t.optionsInput)})}};Re=rr([ut(0,o.Inject(o.Injector)),ut(1,o.Inject(b.ComponentManager)),ut(2,o.Inject(Y.DataValidatorRegistryService))],Re);var ar=Object.getOwnPropertyDescriptor,ir=(e,t,r,n)=>{for(var a=n>1?void 0:n?ar(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ht=(e,t)=>(r,n)=>t(r,n,e);const or="SHEET_DATA_VALIDATION_UI_PLUGIN";L.UniverSheetsDataValidationUIPlugin=(Xe=class extends o.Plugin{constructor(t=Le,r,n,a){super(),this._config=t,this._injector=r,this._commandService=n,this._configService=a;const{menu:i,...s}=o.merge({},Le,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Je,s)}onStarting(){[[de],[fe],[Pe],[Ee],[Te],[be],[Me],[we],[Re]].forEach(t=>{this._injector.add(t)}),[Fe,Ue,yt,et,me,Ct].forEach(t=>{this._commandService.registerCommand(t)})}onReady(){this._injector.get(Me),this._injector.get(be),this._injector.get(we),this._injector.get(Pe),this._injector.get(N.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[ke])}onRendered(){this._injector.get(Re),this._injector.get(Te)}onSteady(){this._injector.get(Ee)}},R(Xe,"pluginName",or),R(Xe,"type",o.UniverInstanceType.UNIVER_SHEET),Xe),L.UniverSheetsDataValidationUIPlugin=ir([ht(1,o.Inject(o.Injector)),ht(2,o.ICommandService),ht(3,o.IConfigService)],L.UniverSheetsDataValidationUIPlugin);var sr=Object.getOwnPropertyDescriptor,lr=(e,t,r,n)=>{for(var a=n>1?void 0:n?sr(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},vt=(e,t)=>(r,n)=>t(r,n,e);const dr="SHEET_DATA_VALIDATION_UI_PLUGIN";L.UniverSheetsDataValidationMobileUIPlugin=(ze=class extends o.Plugin{constructor(t=Le,r,n,a){super(),this._config=t,this._injector=r,this._commandService=n,this._configService=a;const{menu:i,...s}=o.merge({},Le,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Je,s)}onStarting(){[[de],[fe],[Pe],[Ee],[Te],[be],[Me],[Re]].forEach(t=>{this._injector.add(t)}),[Fe,Ue,yt,et,me,Ct].forEach(t=>{this._commandService.registerCommand(t)})}onReady(){this._injector.get(Me),this._injector.get(be),this._injector.get(N.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[ke])}onRendered(){this._injector.get(Re),this._injector.get(Te)}onSteady(){this._injector.get(Ee)}},R(ze,"pluginName",dr),R(ze,"type",o.UniverInstanceType.UNIVER_SHEET),ze),L.UniverSheetsDataValidationMobileUIPlugin=lr([vt(1,o.Inject(o.Injector)),vt(2,o.ICommandService),vt(3,o.IConfigService)],L.UniverSheetsDataValidationMobileUIPlugin),Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});
|
|
18
|
+
`,{"dark:hover:!univer-bg-gray-700 hover:univer-bg-gray-50":!i,"univer-opacity-50":i}),onClick:r,onMouseEnter:()=>{i||(u(!0),h.current=t.ranges.map(m=>l.addShape({range:m,style:V,primary:null})))},onMouseLeave:()=>{var m;u(!1),(m=h.current)==null||m.forEach(y=>{y&&l.removeShape(y)}),h.current=void 0},children:[v.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)}),v.jsx("div",{className:"univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px] dark:!univer-text-gray-300",children:t.ranges.map(m=>Ke.serializeRange(m)).join(",")}),p?v.jsx("div",{className:"univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-h-5 univer-w-5 univer-items-center univer-justify-center univer-rounded dark:!univer-text-gray-300 dark:hover:!univer-bg-gray-700 hover:univer-bg-gray-200",onClick:T,children:v.jsx(Ze,{})}):null]})};function Tn(e){const t=b.useDependency(f.SheetDataValidationModel),r=b.useDependency(o.IUniverInstanceService),n=b.useDependency(o.ICommandService),a=b.useDependency(o.Injector),i=b.useDependency(ue),s=b.useDependency(o.LocaleService),[d,l]=R.useState([]),{workbook:c}=e,h=b.useObservable(c.activeSheet$,void 0,!0),p=c.getUnitId(),u=h==null?void 0:h.getSheetId();R.useEffect(()=>{l(t.getRules(p,u));const y=t.ruleChange$.subscribe(S=>{S.unitId===p&&S.subUnitId===u&&l(t.getRules(p,u))});return()=>{y.unsubscribe()}},[p,u,t]);const I=async()=>{const y=f.createDefaultNewRule(a),S={unitId:p,subUnitId:u,rule:y};await n.executeCommand(f.AddSheetDataValidationCommand.id,S),i.setActiveRule({unitId:p,subUnitId:u,rule:y})},g=()=>{n.executeCommand(f.RemoveSheetAllDataValidationCommand.id,{unitId:p,subUnitId:u})},T=(y=>{const S=r.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),D=S.getActiveSheet(),w=S.getUnitId(),C=D.getSheetId();return y.map(W=>$.checkRangesEditablePermission(a,w,C,W.ranges)?{...W}:{...W,disable:!0})})(d),m=T==null?void 0:T.some(y=>y.disable);return v.jsxs("div",{className:"univer-pb-4",children:[T==null?void 0:T.map(y=>{var S;return v.jsx(bn,{unitId:p,subUnitId:u,onClick:()=>{y.disable||i.setActiveRule({unitId:p,subUnitId:u,rule:y})},rule:y,disable:(S=y.disable)!=null?S:!1},y.uid)}),v.jsxs("div",{className:"univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[d.length&&!m?v.jsx(M.Button,{onClick:g,children:s.t("dataValidation.panel.removeAll")}):null,v.jsx(M.Button,{variant:"primary",onClick:I,children:s.t("dataValidation.panel.add")})]})]})}const Rn=()=>{const e=b.useDependency(ue),t=b.useObservable(e.activeRule$,e.activeRule),r=b.useDependency(o.IUniverInstanceService),n=b.useObservable(()=>r.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),a=b.useObservable(()=>{var i;return(i=n==null?void 0:n.activeSheet$)!=null?i:ie.of(null)},void 0,void 0,[]);return!n||!a?null:t&&t.subUnitId===a.getSheetId()?v.jsx(Mn,{},t.rule.uid):v.jsx(Tn,{workbook:n})},Vn="LIST_RENDER_MODE_OPTION_INPUT";function je(e){var a;const{value:t,onChange:r}=e,n=b.useDependency(o.LocaleService);return v.jsx(M.FormLayout,{label:n.t("dataValidation.renderMode.label"),children:v.jsxs(M.RadioGroup,{value:`${(a=t.renderMode)!=null?a:o.DataValidationRenderMode.CUSTOM}`,onChange:i=>r({...t,renderMode:+i}),children:[v.jsx(M.Radio,{value:`${o.DataValidationRenderMode.CUSTOM}`,children:n.t("dataValidation.renderMode.chip")}),v.jsx(M.Radio,{value:`${o.DataValidationRenderMode.ARROW}`,children:n.t("dataValidation.renderMode.arrow")}),v.jsx(M.Radio,{value:`${o.DataValidationRenderMode.TEXT}`,children:n.t("dataValidation.renderMode.text")})]})})}je.componentKey=Vn;const On="DATE_SHOW_TIME_OPTION";function Be(e){var a;const{value:t,onChange:r}=e,n=b.useDependency(o.LocaleService);return v.jsx(M.FormLayout,{children:v.jsx(M.Checkbox,{checked:(a=t.bizInfo)==null?void 0:a.showTime,onChange:i=>{r({...t,bizInfo:{...t.bizInfo,showTime:i}})},children:n.t("dataValidation.showTime.label")})})}Be.componentKey=On;var An=Object.getOwnPropertyDescriptor,Ln=(e,t,r,n)=>{for(var a=n>1?void 0:n?An(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Re=(e,t)=>(r,n)=>t(r,n,e);const We=6;let rt=class{constructor(e,t,r,n,a,i){this._commandService=e,this._univerInstanceService=t,this._formulaService=r,this._themeService=n,this._renderManagerService=a,this._dataValidationModel=i}_calc(e,t){var c,h,p;const{vt:r,ht:n}=t||{},a=e.endX-e.startX-We*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(r){case o.VerticalAlign.TOP:l=0;break;case o.VerticalAlign.BOTTOM:l=0+(i-s);break;default:l=0+(i-s)/2;break}switch(n){case o.HorizontalAlign.LEFT:d=We;break;case o.HorizontalAlign.RIGHT:d=We+(a-s);break;default:d=We+(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:((p=t==null?void 0:t.fs)!=null?p:10)*1.6}}calcCellAutoHeight(e){var r;const{style:t}=e;return((r=t==null?void 0:t.fs)!=null?r:10)*1.6}calcCellAutoWidth(e){var r;const{style:t}=e;return((r=t==null?void 0:t.fs)!=null?r:10)*1.6}async _parseFormula(e,t,r){var c,h,p,u,I,g,V,T,m;const{formula1:n=f.CHECKBOX_FORMULA_1,formula2:a=f.CHECKBOX_FORMULA_2}=e,i=await this._formulaService.getRuleFormulaResult(t,r,e.uid),s=f.getFormulaResult((p=(h=(c=i==null?void 0:i[0])==null?void 0:c.result)==null?void 0:h[0])==null?void 0:p[0]),d=f.getFormulaResult((g=(I=(u=i==null?void 0:i[1])==null?void 0:u.result)==null?void 0:I[0])==null?void 0:g[0]),l=f.isLegalFormulaResult(String(s))&&f.isLegalFormulaResult(String(d));return{formula1:o.isFormulaString(n)?f.getFormulaResult((m=(T=(V=i==null?void 0:i[0])==null?void 0:V.result)==null?void 0:T[0])==null?void 0:m[0]):n,formula2:o.isFormulaString(a)?d:a,isFormulaValid:l}}drawWith(e,t){var U,k,N,H;const{style:r,primaryWithCoord:n,unitId:a,subUnitId:i,worksheet:s,row:d,col:l}=t,c=n.isMergedMainCell?n.mergeInfo:n,h=f.getCellValueOrigin(s.getCellRaw(d,l)),p=this._dataValidationModel.getRuleByLocation(a,i,d,l);if(!p)return;const u=this._dataValidationModel.getValidator(p.type);if(!u||!((U=u.skipDefaultFontRender)!=null&&U.call(u,p,h,{unitId:a,subUnitId:i,row:d,column:l})))return;const I=u.parseFormulaSync(p,a,i),{formula1:g}=I,V=this._calc(c,r),{a:T,d:m}=e.getTransform(),y=P.fixLineWidthByScale(V.left,T),S=P.fixLineWidthByScale(V.top,m),D=P.Transform.create().composeMatrix({left:y,top:S,scaleX:1,scaleY:1,angle:0,skewX:0,skewY:0,flipX:!1,flipY:!1}),w=c.endX-c.startX,C=c.endY-c.startY;e.save(),e.beginPath(),e.rect(c.startX,c.startY,w,C),e.clip();const E=D.getMatrix();e.transform(E[0],E[1],E[2],E[3],E[4],E[5]);const W=((k=r==null?void 0:r.fs)!=null?k:10)*1.6,x=String(h)===String(g),O=this._themeService.getColorFromTheme("primary.600");P.CheckboxShape.drawWith(e,{checked:x,width:W,height:W,fill:(H=(N=r==null?void 0:r.cl)==null?void 0:N.rgb)!=null?H:O}),e.restore()}isHit(e,t){const r=t.primaryWithCoord.isMergedMainCell?t.primaryWithCoord.mergeInfo:t.primaryWithCoord,n=this._calc(r,t.style),a=n.top,i=n.top+n.height,s=n.left,d=n.left+n.width,{x:l,y:c}=e;return l<=d&&l>=s&&c<=i&&c>=a}async onPointerDown(e,t){var g;if(t.button===2)return;const{primaryWithCoord:r,unitId:n,subUnitId:a,worksheet:i,row:s,col:d}=e,l=f.getCellValueOrigin(i.getCellRaw(s,d)),c=this._dataValidationModel.getRuleByLocation(n,a,s,d);if(!c)return;const h=this._dataValidationModel.getValidator(c.type);if(!h||!((g=h.skipDefaultFontRender)!=null&&g.call(h,c,l,{unitId:n,subUnitId:a,row:s,column:d})))return;const{formula1:p,formula2:u}=await this._parseFormula(c,n,a),I={range:{startColumn:r.actualColumn,endColumn:r.actualColumn,startRow:r.actualRow,endRow:r.actualRow},value:{v:String(l)===f.transformCheckboxValue(String(p))?u:p,p:null}};this._commandService.executeCommand($.SetRangeValuesCommand.id,I)}onPointerEnter(e,t){var r,n;(n=(r=P.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null||n.setCursor(P.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var r,n;(n=(r=P.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null||n.setCursor(P.CURSOR_TYPE.DEFAULT)}};rt=Ln([Re(0,o.ICommandService),Re(1,o.IUniverInstanceService),Re(2,o.Inject(f.DataValidationFormulaService)),Re(3,o.Inject(o.ThemeService)),Re(4,o.Inject(P.IRenderManagerService)),Re(5,o.Inject(f.SheetDataValidationModel))],rt);class Pn extends F.BaseSheetDataValidatorView{constructor(){super(...arguments);A(this,"id",o.DataValidationType.CHECKBOX);A(this,"canvasRender",this.injector.createInstance(rt));A(this,"formulaInput",f.CHECKBOX_FORMULA_INPUT_NAME)}}class kn extends F.BaseSheetDataValidatorView{constructor(){super(...arguments);A(this,"id",o.DataValidationType.CUSTOM);A(this,"formulaInput",f.CUSTOM_FORMULA_INPUT_NAME)}}const Fn="data-validation.formula-input";class Un extends F.BaseSheetDataValidatorView{constructor(){super(...arguments);A(this,"id",o.DataValidationType.DATE);A(this,"formulaInput",Fn);A(this,"optionsInput",Be.componentKey);A(this,"dropdownType",X.DataValidatorDropdownType.DATE)}}class Nn extends F.BaseSheetDataValidatorView{constructor(){super(...arguments);A(this,"id",o.DataValidationType.DECIMAL);A(this,"formulaInput",f.BASE_FORMULA_INPUT_NAME)}}const bt=4,jn=0,at=4,Tt=4,it=6,He=6,_e=14;function Bn(e,t){const r=P.FontCache.getTextSize(e,t),n=r.width+bt*2,{ba:a,bd:i}=r,s=a+i;return{width:n,height:s+jn*2,ba:a}}function ot(e,t,r,n){const a=_e+it*2,i=r-a,s=n-He*2,d=e.map(u=>({layout:Bn(u,t),text:u}));let l;const c=[];d.forEach(u=>{const{layout:I}=u,{width:g,height:V}=I;!l||l.width+g+at>i?(l={width:g,height:V,items:[{...u,left:0}]},c.push(l)):(l.items.push({...u,left:l.width+at}),l.width=l.width+g+at)});let h=0,p=0;return c.forEach((u,I)=>{p=Math.max(p,u.width),I===c.length-1?h+=u.height:h+=u.height+Tt}),{lines:c,totalHeight:h,contentWidth:i,contentHeight:s,cellAutoHeight:h+He*2,calcAutoWidth:p+a}}const Wn=8;class Hn extends P.Shape{static drawWith(t,r){const{fontString:n,info:a,fill:i,color:s}=r,{layout:d,text:l}=a;t.save(),P.Rect.drawWith(t,{width:d.width,height:d.height,radius:Wn,fill:i||Ce}),t.translateWithPrecision(bt,d.ba),t.font=n,t.fillStyle=s,t.fillText(l,0,0),t.restore()}}var xn=Object.getOwnPropertyDescriptor,$n=(e,t,r,n)=>{for(var a=n>1?void 0:n?xn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},xe=(e,t)=>(r,n)=>t(r,n,e);const Yn=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 st=class{constructor(e,t,r,n){A(this,"zIndex");A(this,"_dropdownInfoMap",new Map);this._commandService=e,this._univerInstanceService=t,this._renderManagerService=r,this._dataValidationModel=n}_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,r,n,a){const i=r-_e+4;let s=4;switch(a){case o.VerticalAlign.MIDDLE:s=(n-_e)/2+4;break;case o.VerticalAlign.BOTTOM:s=n-_e+4;break}e.save(),e.translateWithPrecision(t.startX+i,t.startY+s),e.fillStyle="#565656",e.fill(Yn),e.restore()}drawWith(e,t,r,n){var ae,se;const{primaryWithCoord:a,row:i,col:s,style:d,data:l,subUnitId:c}=t,h=a.isMergedMainCell?a.mergeInfo:a,p=l==null?void 0:l.fontRenderExtension,{leftOffset:u=0,rightOffset:I=0,topOffset:g=0,downOffset:V=0}=p||{},T=this._ensureMap(c),m=this._generateKey(i,s),y=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,i,s);if(!y)return;const S=this._dataValidationModel.getValidator(y.type);if(!S)return;const D={startX:h.startX+u,endX:h.endX-I,startY:h.startY+g,endY:h.endY-V},w=D.endX-D.startX,C=D.endY-D.startY,{cl:E}=d||{},W=(ae=typeof E=="object"?E==null?void 0:E.rgb:E)!=null?ae:"#000",x=P.getFontStyleString(d!=null?d:void 0),{vt:O,ht:U}=d||{},k=O!=null?O:o.VerticalAlign.MIDDLE,N=(se=f.getCellValueOrigin(l))!=null?se:"",H=S.parseCellValue(N),Z=S.getListWithColorMap(y),K=ot(H,x,w,C);this._drawDownIcon(e,D,w,C,k),e.save(),e.translateWithPrecision(D.startX,D.startY),e.beginPath(),e.rect(0,0,w-_e,C),e.clip(),e.translateWithPrecision(it,He);let te=0;switch(k){case o.VerticalAlign.MIDDLE:te=(K.contentHeight-K.totalHeight)/2;break;case o.VerticalAlign.BOTTOM:te=K.contentHeight-K.totalHeight;break}e.translateWithPrecision(0,te),K.lines.forEach((ce,J)=>{e.save();const{width:q,height:ve,items:ne}=ce;let ee=0;switch(U){case o.HorizontalAlign.RIGHT:ee=K.contentWidth-q;break;case o.HorizontalAlign.CENTER:ee=(K.contentWidth-q)/2;break}e.translate(ee,J*(ve+Tt)),ne.forEach(Q=>{e.save(),e.translateWithPrecision(Q.left,0),Hn.drawWith(e,{...x,info:Q,color:W,fill:Z[Q.text]}),e.restore()}),e.restore()}),e.restore(),T.set(m,{left:D.startX,top:D.startY,width:K.contentWidth+it+_e,height:K.contentHeight+He*2})}calcCellAutoHeight(e){var w;const{primaryWithCoord:t,style:r,data:n,row:a,col:i}=e,s=n==null?void 0:n.fontRenderExtension,{leftOffset:d=0,rightOffset:l=0,topOffset:c=0,downOffset:h=0}=s||{},p=t.isMergedMainCell?t.mergeInfo:t,u={startX:p.startX+d,endX:p.endX-l,startY:p.startY+c,endY:p.endY-h},I=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!I)return;const g=this._dataValidationModel.getValidator(I.type);if(!g)return;const V=u.endX-u.startX,T=u.endY-u.startY,m=(w=f.getCellValueOrigin(n))!=null?w:"",y=g.parseCellValue(m),S=P.getFontStyleString(r!=null?r:void 0);return ot(y,S,V,T).cellAutoHeight}calcCellAutoWidth(e){var w;const{primaryWithCoord:t,style:r,data:n,row:a,col:i}=e,s=n==null?void 0:n.fontRenderExtension,{leftOffset:d=0,rightOffset:l=0,topOffset:c=0,downOffset:h=0}=s||{},p=t.isMergedMainCell?t.mergeInfo:t,u={startX:p.startX+d,endX:p.endX-l,startY:p.startY+c,endY:p.endY-h},I=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!I)return;const g=this._dataValidationModel.getValidator(I.type);if(!g)return;const V=u.endX-u.startX,T=u.endY-u.startY,m=(w=f.getCellValueOrigin(n))!=null?w:"",y=g.parseCellValue(m),S=P.getFontStyleString(r!=null?r:void 0);return ot(y,S,V,T).calcAutoWidth}isHit(e,t){const{primaryWithCoord:r}=t,n=r.isMergedMainCell?r.mergeInfo:r,{endX:a}=n,{x:i}=e;return i>=a-_e&&i<=a}onPointerDown(e,t){if(t.button===2)return;const{unitId:r,subUnitId:n,row:a,col:i}=e,s={unitId:r,subUnitId:n,row:a,column:i};this._commandService.executeCommand(Fe.id,s)}onPointerEnter(e,t){var r,n;return(n=(r=P.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null?void 0:n.setCursor(P.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var r,n;return(n=(r=P.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null?void 0:n.setCursor(P.CURSOR_TYPE.DEFAULT)}};st=$n([xe(0,o.ICommandService),xe(1,o.IUniverInstanceService),xe(2,o.Inject(P.IRenderManagerService)),xe(3,o.Inject(f.SheetDataValidationModel))],st);class Xn extends F.BaseSheetDataValidatorView{constructor(){super(...arguments);A(this,"id",o.DataValidationType.LIST_MULTIPLE);A(this,"canvasRender",this.injector.createInstance(st));A(this,"dropdownType",X.DataValidatorDropdownType.MULTIPLE_LIST)}}var zn=Object.getOwnPropertyDescriptor,Kn=(e,t,r,n)=>{for(var a=n>1?void 0:n?zn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Le=(e,t)=>(r,n)=>t(r,n,e);const Ie=4,$e=4,de=14,Rt=1,he=6,Ve=3,lt=8,Zn="#565656",Vt=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 Ot(e,t,r,n,a,i,s=!0){let d=0;const l=s?Ve:0;switch(a){case o.VerticalAlign.BOTTOM:d=t-n-l;break;case o.VerticalAlign.MIDDLE:d=(t-n)/2;break;default:d=l;break}d=Math.max(Ve,d);let c=0;switch(i){case o.HorizontalAlign.CENTER:c=(e-r)/2;break;case o.HorizontalAlign.RIGHT:c=e-r;break}return c=Math.max(he,c),{paddingLeft:c,paddingTop:d}}let dt=class{constructor(e,t,r,n,a){A(this,"_dropdownInfoMap",new Map);A(this,"zIndex");this._univerInstanceService=e,this._localeService=t,this._commandService=r,this._renderManagerService=n,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,r,n,a,i,s){const{t:d=o.DEFAULT_STYLES.pd.t,b:l=o.DEFAULT_STYLES.pd.b}=s,c=r-de;let h;switch(i){case o.VerticalAlign.MIDDLE:h=(n-$e)/2;break;case o.VerticalAlign.BOTTOM:h=n-l-a-Ve+(a/2-$e/2);break;default:h=d+Ve+(a/2-$e/2);break}e.save(),e.translateWithPrecision(t.startX+c,t.startY+h),e.fillStyle="#565656",e.fill(Vt),e.restore()}drawWith(e,t,r){var Z,K,te,ae,se,ce;const{primaryWithCoord:n,row:a,col:i,style:s,data:d,subUnitId:l}=t,c=n.isMergedMainCell?n.mergeInfo:n,h=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,a,i);if(!h)return;const p=this._dataValidationModel.getValidator(h.type);if(!p)return;const u=d==null?void 0:d.fontRenderExtension,{leftOffset:I=0,rightOffset:g=0,topOffset:V=0,downOffset:T=0}=u||{};if(!h||!p||!p||p.id.indexOf(o.DataValidationType.LIST)!==0||!p.skipDefaultFontRender(h))return;const m={startX:c.startX+I,endX:c.endX-g,startY:c.startY+V,endY:c.endY-T},y=m.endX-m.startX,S=m.endY-m.startY,D=this._ensureMap(l),w=this._generateKey(a,i),C=p.getListWithColor(h),E=f.getCellValueOrigin(d),W=`${E!=null?E:""}`,x=C.find(J=>J.label===W);let{tb:O,vt:U,ht:k,pd:N}=s||{};O=O!=null?O:o.WrapStrategy.WRAP,U=U!=null?U:o.VerticalAlign.BOTTOM,k=k!=null?k:o.DEFAULT_STYLES.ht,N=N!=null?N:o.DEFAULT_STYLES.pd;const H=P.getFontStyleString(s).fontCache;if(h.renderMode===o.DataValidationRenderMode.ARROW){const{l:J=o.DEFAULT_STYLES.pd.l,t:q=o.DEFAULT_STYLES.pd.t,r:ve=o.DEFAULT_STYLES.pd.r,b:ne=o.DEFAULT_STYLES.pd.b}=N,ee=y-J-ve-de-4,Q=new P.DocSimpleSkeleton(W,H,O===o.WrapStrategy.WRAP,ee,1/0);Q.calculate();const L=Q.getTotalWidth(),Y=Q.getTotalHeight(),{paddingTop:_,paddingLeft:j}=Ot(ee,S-q-ne,L,Y,U,k,!0);this._drawDownIcon(e,m,y,S,Y,U,N),e.save(),e.translateWithPrecision(m.startX+J,m.startY+q),e.beginPath(),e.rect(0,0,y-J-ve,S-q-ne),e.clip(),e.translateWithPrecision(0,_),e.save(),e.translateWithPrecision(Ie,0),e.beginPath(),e.rect(0,0,ee,Y),e.clip(),P.Text.drawWith(e,{text:W,fontStyle:H,width:ee,height:Y,color:(Z=s==null?void 0:s.cl)==null?void 0:Z.rgb,strokeLine:!!((K=s==null?void 0:s.st)!=null&&K.s),underline:!!((te=s==null?void 0:s.ul)!=null&&te.s),warp:O===o.WrapStrategy.WRAP,hAlign:o.HorizontalAlign.LEFT},Q),e.translateWithPrecision(j,0),e.restore(),e.restore(),D.set(w,{left:m.endX+J+r.rowHeaderWidth-de,top:m.startY+q+r.columnHeaderHeight,width:de,height:S-q-ne})}else{e.save(),e.translateWithPrecision(m.startX,m.startY),e.beginPath(),e.rect(0,0,y,S),e.clip();const J=y-he*2-Ie-de-4,q=new P.DocSimpleSkeleton(W,H,O===o.WrapStrategy.WRAP,J,1/0);q.calculate();const ve=q.getTotalWidth(),ne=q.getTotalHeight(),ee=ne+Rt*2,Q=Math.max(y-he*2,1),{paddingTop:L,paddingLeft:Y}=Ot(Q,S,ve,ee,U,k);e.translateWithPrecision(he,L),P.Rect.drawWith(e,{width:Q,height:ee,fill:(x==null?void 0:x.color)||Ce,radius:lt}),e.save(),e.translateWithPrecision(Ie,Rt),e.beginPath(),e.rect(0,0,J,ne),e.clip(),e.translateWithPrecision(Y,0),P.Text.drawWith(e,{text:W,fontStyle:H,width:J,height:ne,color:(ae=s==null?void 0:s.cl)==null?void 0:ae.rgb,strokeLine:!!((se=s==null?void 0:s.st)!=null&&se.s),underline:!!((ce=s==null?void 0:s.ul)!=null&&ce.s),warp:O===o.WrapStrategy.WRAP,hAlign:o.HorizontalAlign.LEFT},q),e.restore(),e.translateWithPrecision(J+Ie+4,(ne-$e)/2),e.fillStyle=Zn,e.fill(Vt),e.restore(),D.set(w,{left:m.startX+he+r.rowHeaderWidth,top:m.startY+L+r.columnHeaderHeight,width:Q,height:ee})}}calcCellAutoHeight(e){const{primaryWithCoord:t,style:r,data:n,row:a,col:i}=e,s=t.isMergedMainCell?t.mergeInfo:t,d=n==null?void 0:n.fontRenderExtension,{leftOffset:l=0,rightOffset:c=0,topOffset:h=0,downOffset:p=0}=d||{},u=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!u||u.renderMode===o.DataValidationRenderMode.TEXT)return;const I={startX:s.startX+l,endX:s.endX-c,startY:s.startY+h,endY:s.endY-p},g=I.endX-I.startX,V=f.getCellValueOrigin(n),T=`${V!=null?V:""}`;let{tb:m,pd:y}=r||{};const{t:S=o.DEFAULT_STYLES.pd.t,b:D=o.DEFAULT_STYLES.pd.b}=y!=null?y:{};if(m=m!=null?m:o.WrapStrategy.WRAP,u.renderMode===o.DataValidationRenderMode.ARROW){const w=g-de,C=new P.DocSimpleSkeleton(T,P.getFontStyleString(r).fontCache,m===o.WrapStrategy.WRAP,w,1/0);return C.calculate(),C.getTotalHeight()+S+D+Ve*2}else{const w=Math.max(g-he*2-Ie-de,10),C=new P.DocSimpleSkeleton(T,P.getFontStyleString(r).fontCache,m===o.WrapStrategy.WRAP,w,1/0);return C.calculate(),C.getTotalHeight()+Ve*2+2}}calcCellAutoWidth(e){const{primaryWithCoord:t,style:r,data:n,row:a,col:i}=e,s=t.isMergedMainCell?t.mergeInfo:t,d=n==null?void 0:n.fontRenderExtension,{leftOffset:l=0,rightOffset:c=0,topOffset:h=0,downOffset:p=0}=d||{},u=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!u||u.renderMode===o.DataValidationRenderMode.TEXT)return;const I={startX:s.startX+l,endX:s.endX-c,startY:s.startY+h,endY:s.endY-p},g=I.endX-I.startX,V=f.getCellValueOrigin(n),T=`${V!=null?V:""}`;let{tb:m,pd:y}=r||{};const{l:S=o.DEFAULT_STYLES.pd.l,r:D=o.DEFAULT_STYLES.pd.r}=y!=null?y:{};m=m!=null?m:o.WrapStrategy.WRAP;let w=he*2+de;switch(u.renderMode){case o.DataValidationRenderMode.ARROW:w=de+he*2+D+S;break;case o.DataValidationRenderMode.CUSTOM:w=de+he*2+Ie*2+D+S+lt/2+1;break;default:w=de+he*2+Ie*2+D+S+lt/2+1}const C=g-w,E=new P.DocSimpleSkeleton(T,P.getFontStyleString(r).fontCache,m===o.WrapStrategy.WRAP,C,1/0);return E.calculate(),E.getTotalWidth()+w}isHit(e,t){const{subUnitId:r,row:n,col:a}=t,s=this._ensureMap(r).get(this._generateKey(n,a)),d=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,n,a);if(!d||!s||d.renderMode===o.DataValidationRenderMode.TEXT)return!1;const{top:l,left:c,width:h,height:p}=s,{x:u,y:I}=e;return u>=c&&u<=c+h&&I>=l&&I<=l+p}onPointerDown(e,t){if(t.button===2)return;const{unitId:r,subUnitId:n,row:a,col:i}=e,s={unitId:r,subUnitId:n,row:a,column:i};this._commandService.executeCommand(Fe.id,s)}onPointerEnter(e,t){var r,n;(n=(r=P.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null||n.setCursor(P.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var r,n;(n=(r=P.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:r.mainComponent)==null||n.setCursor(P.CURSOR_TYPE.DEFAULT)}};dt=Kn([Le(0,o.IUniverInstanceService),Le(1,o.Inject(o.LocaleService)),Le(2,o.ICommandService),Le(3,o.Inject(P.IRenderManagerService)),Le(4,o.Inject(f.SheetDataValidationModel))],dt);class Gn extends F.BaseSheetDataValidatorView{constructor(){super(...arguments);A(this,"id",o.DataValidationType.LIST);A(this,"canvasRender",this.injector.createInstance(dt));A(this,"dropdownType",X.DataValidatorDropdownType.LIST);A(this,"optionsInput",je.componentKey);A(this,"formulaInput",f.LIST_FORMULA_INPUT_NAME)}}class qn extends F.BaseSheetDataValidatorView{constructor(){super(...arguments);A(this,"id",o.DataValidationType.TEXT_LENGTH);A(this,"formulaInput",f.BASE_FORMULA_INPUT_NAME)}}class Jn extends F.BaseSheetDataValidatorView{constructor(){super(...arguments);A(this,"id",o.DataValidationType.WHOLE);A(this,"formulaInput",f.BASE_FORMULA_INPUT_NAME)}}var Qn=Object.getOwnPropertyDescriptor,er=(e,t,r,n)=>{for(var a=n>1?void 0:n?Qn(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ct=(e,t)=>(r,n)=>t(r,n,e);let Oe=class extends o.RxDisposable{constructor(e,t,r){super(),this._injector=e,this._componentManger=t,this._dataValidatorRegistryService=r,this._initComponents(),this._registerValidatorViews()}_initComponents(){[["DataValidationIcon",pt],[ke,Rn],[je.componentKey,je],[Be.componentKey,Be],...Gt].forEach(([e,t])=>{this.disposeWithMe(this._componentManger.register(e,t))})}_registerValidatorViews(){[Nn,Jn,qn,Un,Pn,Gn,Xn,kn].forEach(e=>{const t=this._injector.createInstance(e),r=this._dataValidatorRegistryService.getValidatorItem(t.id);r&&(r.formulaInput=t.formulaInput,r.canvasRender=t.canvasRender,r.dropdownType=t.dropdownType,r.optionsInput=t.optionsInput)})}};Oe=er([ct(0,o.Inject(o.Injector)),ct(1,o.Inject(b.ComponentManager)),ct(2,o.Inject(X.DataValidatorRegistryService))],Oe);var tr=Object.getOwnPropertyDescriptor,nr=(e,t,r,n)=>{for(var a=n>1?void 0:n?tr(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ut=(e,t)=>(r,n)=>t(r,n,e);const rr="SHEET_DATA_VALIDATION_UI_PLUGIN";F.UniverSheetsDataValidationUIPlugin=(Ye=class extends o.Plugin{constructor(t=Pe,r,n,a){super(),this._config=t,this._injector=r,this._commandService=n,this._configService=a;const{menu:i,...s}=o.merge({},Pe,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(qe,s)}onStarting(){[[ue],[fe],[Ae],[Ee],[Te],[be],[Me],[we],[Oe]].forEach(t=>{this._injector.add(t)}),[Ue,Fe,Ct,Qe,me,It].forEach(t=>{this._commandService.registerCommand(t)})}onReady(){this._injector.get(Me),this._injector.get(be),this._injector.get(we),this._injector.get(Ae),this._injector.get(P.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[Ne])}onRendered(){this._injector.get(Oe),this._injector.get(Te)}onSteady(){this._injector.get(Ee)}},A(Ye,"pluginName",rr),A(Ye,"type",o.UniverInstanceType.UNIVER_SHEET),Ye),F.UniverSheetsDataValidationUIPlugin=nr([ut(1,o.Inject(o.Injector)),ut(2,o.ICommandService),ut(3,o.IConfigService)],F.UniverSheetsDataValidationUIPlugin);var ar=Object.getOwnPropertyDescriptor,ir=(e,t,r,n)=>{for(var a=n>1?void 0:n?ar(t,r):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ht=(e,t)=>(r,n)=>t(r,n,e);const or="SHEET_DATA_VALIDATION_UI_PLUGIN";F.UniverSheetsDataValidationMobileUIPlugin=(Xe=class extends o.Plugin{constructor(t=Pe,r,n,a){super(),this._config=t,this._injector=r,this._commandService=n,this._configService=a;const{menu:i,...s}=o.merge({},Pe,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(qe,s)}onStarting(){[[ue],[fe],[Ae],[Ee],[Te],[be],[Me],[Oe]].forEach(t=>{this._injector.add(t)}),[Ue,Fe,Ct,Qe,me,It].forEach(t=>{this._commandService.registerCommand(t)})}onReady(){this._injector.get(Me),this._injector.get(be),this._injector.get(P.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[Ne])}onRendered(){this._injector.get(Oe),this._injector.get(Te)}onSteady(){this._injector.get(Ee)}},A(Xe,"pluginName",or),A(Xe,"type",o.UniverInstanceType.UNIVER_SHEET),Xe),F.UniverSheetsDataValidationMobileUIPlugin=ir([ht(1,o.Inject(o.Injector)),ht(2,o.ICommandService),ht(3,o.IConfigService)],F.UniverSheetsDataValidationMobileUIPlugin),Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})});
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
// index
|
|
22
|
-
(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/facade")):typeof define=="function"&&define.amd?define(["exports","@univerjs/data-validation","@univerjs/sheets-data-validation","@univerjs/sheets-data-validation-ui","@univerjs/sheets-data-validation/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}=s;return{plugins:[i.UniverDataValidationPlugin,a.UniverSheetsDataValidationPlugin,[t.UniverSheetsDataValidationUIPlugin,{showEditOnDropdown:d}]].filter(r=>!!r)}}e.UniverSheetsDataValidationPreset=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
22
|
+
(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}=s;return{plugins:[i.UniverDataValidationPlugin,a.UniverSheetsDataValidationPlugin,[t.UniverSheetsDataValidationUIPlugin,{showEditOnDropdown:d}]].filter(r=>!!r)}}e.UniverSheetsDataValidationPreset=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/preset-sheets-data-validation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -57,17 +57,17 @@
|
|
|
57
57
|
"rxjs": ">=7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/data-validation": "0.
|
|
61
|
-
"@univerjs/sheets-data-validation": "0.
|
|
62
|
-
"@univerjs/sheets-data-validation-ui": "0.
|
|
60
|
+
"@univerjs/data-validation": "0.8.0-beta.1",
|
|
61
|
+
"@univerjs/sheets-data-validation": "0.8.0-beta.1",
|
|
62
|
+
"@univerjs/sheets-data-validation-ui": "0.8.0-beta.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@univerjs/core": "0.
|
|
65
|
+
"@univerjs/core": "0.8.0-beta.1",
|
|
66
66
|
"react": "18.3.1",
|
|
67
67
|
"react-dom": "18.3.1",
|
|
68
68
|
"rxjs": "7.8.2",
|
|
69
69
|
"typescript": "^5.8.3",
|
|
70
|
-
"@univerjs-infra/shared": "0.
|
|
70
|
+
"@univerjs-infra/shared": "0.8.0-beta.1"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"prebuild:preset": "tsx prepare.ts",
|