@univerjs/sheets-data-validation-ui 0.7.0-nightly.202505151607 → 0.7.0-nightly.202505171606

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var jt=Object.defineProperty;var xt=(e,t,a)=>t in e?jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a;var O=(e,t,a)=>xt(e,typeof t!="symbol"?t+"":t,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),_=require("@univerjs/sheets-data-validation"),p=require("react/jsx-runtime"),E=require("@univerjs/design"),w=require("@univerjs/ui"),b=require("react"),lt=require("@univerjs/sheets-formula-ui"),$=require("@univerjs/data-validation"),ae=require("rxjs"),L=require("@univerjs/engine-render"),W=require("@univerjs/sheets"),Ut=require("@univerjs/sheets-numfmt"),B=require("@univerjs/sheets-ui"),at=require("@univerjs/engine-formula"),kt=e=>{const{isTwoFormula:t=!1,value:a,onChange:n,showError:r,validResult:i}=e,s=w.useDependency(o.LocaleService),c=r?i==null?void 0:i.formula1:"",l=r?i==null?void 0:i.formula2:"";return t?p.jsxs(p.Fragment,{children:[p.jsx(E.FormLayout,{error:c,children:p.jsx(E.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:a==null?void 0:a.formula1,onChange:d=>{n==null||n({...a,formula1:d})}})}),p.jsx("div",{className:"-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400",children:s.t("dataValidation.panel.formulaAnd")}),p.jsx(E.FormLayout,{error:l,children:p.jsx(E.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:a==null?void 0:a.formula2,onChange:d=>{n==null||n({...a,formula2:d})}})})]}):p.jsx(E.FormLayout,{error:c,children:p.jsx(E.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:a==null?void 0:a.formula1,onChange:d=>{n==null||n({formula1:d})}})})};function Ft(e){const{value:t,onChange:a,showError:n,validResult:r}=e,i=w.useDependency(o.LocaleService),s=n?r==null?void 0:r.formula1:"",c=n?r==null?void 0:r.formula2:"",[l,d]=b.useState(!((t==null?void 0:t.formula1)===void 0&&(t==null?void 0:t.formula2)===void 0));return p.jsxs(p.Fragment,{children:[p.jsx(E.FormLayout,{children:p.jsx(E.Checkbox,{checked:l,onChange:h=>{h?d(!0):(d(!1),a==null||a({...t,formula1:void 0,formula2:void 0}))},children:i.t("dataValidation.checkbox.tips")})}),l?p.jsx(E.FormLayout,{label:i.t("dataValidation.checkbox.checked"),error:s,children:p.jsx(E.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula1,onChange:h=>{a==null||a({...t,formula1:h||void 0})}})}):null,l?p.jsx(E.FormLayout,{label:i.t("dataValidation.checkbox.unchecked"),error:c,children:p.jsx(E.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula2,onChange:h=>{a==null||a({...t,formula2:h||void 0})}})}):null]})}function Nt(e){var g;const{unitId:t,subUnitId:a,value:n,onChange:r,showError:i,validResult:s}=e,c=i?s==null?void 0:s.formula1:void 0,l=b.useRef(null),[d,h]=b.useState(!1);return w.useSidebarClick(u=>{var v;((v=l.current)==null?void 0:v.isClickOutSide(u))&&h(!1)}),p.jsx(E.FormLayout,{error:c,children:p.jsx(lt.FormulaEditor,{ref:l,className:E.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",E.borderClassName),initValue:(g=n==null?void 0:n.formula1)!=null?g:"=",unitId:t,subUnitId:a,isFocus:d,isSupportAcrossSheet:!0,onChange:u=>{const S=(u!=null?u:"").trim();S!==(n==null?void 0:n.formula1)&&(r==null||r({...n,formula1:S}))},onFocus:()=>h(!0)})})}var ne=function(){return ne=Object.assign||function(e){for(var t,a=1,n=arguments.length;a<n;a++){t=arguments[a];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},ne.apply(this,arguments)},Bt=function(e,t){var a={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(a[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(a[n[r]]=e[n[r]]);return a},Se=b.forwardRef(function(e,t){var a=e.icon,n=e.id,r=e.className,i=e.extend,s=Bt(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(n," ").concat(r||"").trim(),l=b.useRef("_".concat($t()));return It(a,"".concat(n),{defIds:a.defIds,idSuffix:l.current},ne({ref:t,className:c},s),i)});function It(e,t,a,n,r){return b.createElement(e.tag,ne(ne({key:t},Ht(e,a,r)),n),(Wt(e,a).children||[]).map(function(i,s){return It(i,"".concat(t,"-").concat(e.tag,"-").concat(s),a,void 0,r)}))}function Ht(e,t,a){var n=ne({},e.attrs);a!=null&&a.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=a.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(i){var s=i[0],c=i[1];s==="mask"&&typeof c=="string"&&(n[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var r=t.defIds;return!r||r.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],c=i[1];typeof c=="string"&&(n[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Wt(e,t){var a,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((a=e.children)===null||a===void 0)&&a.length)?ne(ne({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&n&&n.indexOf(r.attrs.id)>-1?ne(ne({},r),{attrs:ne(ne({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):e}function $t(){return Math.random().toString(36).substring(2,8)}Se.displayName="UniverIcon";var Yt={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"}}]},Ct=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"data-validation-single",ref:t,icon:Yt}))});Ct.displayName="DataValidationSingle";var Xt={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"}}]},ct=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"delete-single",ref:t,icon:Xt}))});ct.displayName="DeleteSingle";var zt={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"}}]},yt=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"increase-single",ref:t,icon:zt}))});yt.displayName="IncreaseSingle";var Kt={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"}}]},dt=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"more-down-single",ref:t,icon:Kt}))});dt.displayName="MoreDownSingle";var Gt={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"}}]},Dt=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"more-up-single",ref:t,icon:Gt}))});Dt.displayName="MoreUpSingle";var qt={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"}}]}]},Rt=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"sequence-single",ref:t,icon:qt}))});Rt.displayName="SequenceSingle";const De="#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"],Jt=e=>{const{value:t,onChange:a,disabled:n}=e,[r,i]=b.useState(!1);return p.jsx(E.Dropdown,{align:"start",disabled:n,open:r,onOpenChange:i,overlay:p.jsx("div",{className:"univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5",children:Zt.map(s=>p.jsx("div",{className:E.clsx("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded",E.borderClassName),style:{background:s},onClick:()=>{a(s),i(!1)}},s))}),children:p.jsxs("div",{className:E.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",E.borderClassName),children:[p.jsx("div",{className:"univer-box-border univer-h-4 univer-w-4 univer-rounded univer-text-base",style:{background:t}}),p.jsx(dt,{})]})})},pt=e=>{const{item:t,commonProps:a,style:n}=e,{onItemChange:r,onItemDelete:i}=a;return p.jsxs("div",{className:"univer-flex univer-items-center univer-gap-2",style:n,children:[t.isRef?null:p.jsx("div",{className:E.clsx("univer-cursor-move","draggableHandle"),children:p.jsx(Rt,{})}),p.jsx(Jt,{value:t.color,onChange:s=>{r(t.id,t.label,s)}}),p.jsx(E.Input,{disabled:t.isRef,value:t.label,onChange:s=>{r(t.id,s,t.color)}}),t.isRef?null:p.jsx("div",{className:"univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",children:p.jsx(ct,{onClick:()=>i(t.id)})})]})};function Qt(e){const{value:t,onChange:a=()=>{},unitId:n,subUnitId:r,validResult:i,showError:s,ruleId:c}=e,{formula1:l="",formula2:d=""}=t||{},[h,g]=b.useState(()=>o.isFormulaString(l)?"1":"0"),[u,S]=b.useState(h==="1"?l:"="),[v,T]=b.useState(h==="1"?l:"="),M=w.useDependency(o.LocaleService),m=w.useDependency($.DataValidatorRegistryService),C=w.useDependency($.DataValidationModel),f=w.useDependency(_.DataValidationFormulaController),[y,R]=b.useState(()=>d.split(",")),D=m.getValidatorItem(o.DataValidationType.LIST),[V,x]=b.useState([]),[H,P]=b.useState(""),U=s?i==null?void 0:i.formula1:"",k=b.useMemo(()=>C.ruleChange$.pipe(ae.debounceTime(16)),[]),F=w.useObservable(k),A=w.useEvent(a);b.useEffect(()=>{(async()=>{await new Promise(I=>{setTimeout(()=>I(!0),100)});const j=C.getRuleById(n,r,c),K=j==null?void 0:j.formula1;if(o.isFormulaString(K)&&D&&j){const I=await D.getListAsync(j,n,r);x(I)}})()},[C,F,D,c,r,n]),b.useEffect(()=>{o.isFormulaString(l)&&l!==v&&(S(l),T(v))},[v,l]);const[Y,X]=b.useState(()=>{const j=h!=="1"?_.deserializeListOptions(l):[],K=d.split(",");return j.map((I,N)=>({label:I,color:K[N]||De,isRef:!1,id:o.Tools.generateRandomId(4)}))}),G=(j,K,I)=>{const N=Y.find(z=>z.id===j);N&&(N.label=K,N.color=I,X([...Y]))},J=j=>{const K=Y.findIndex(I=>I.id===j);K!==-1&&(Y.splice(K,1),X([...Y]))},q=d.split(","),ee=b.useMemo(()=>V.map((j,K)=>({label:j,color:q[K]||De,id:`${K}`,isRef:!0})),[q,V]),le=(j,K,I)=>{const N=[...y];N[+j]=I,R(N),A({formula1:l,formula2:N.join(",")})},re=()=>{X([...Y,{label:"",color:De,isRef:!1,id:o.Tools.generateRandomId(4)}])};b.useEffect(()=>{if(h==="1")return;const j=new Set,K=[];Y.map(I=>({labelList:I.label.split(","),item:I})).forEach(({item:I,labelList:N})=>{N.forEach(z=>{j.has(z)||(j.add(z),K.push({label:z,color:I.color}))})}),A({formula1:_.serializeListOptions(K.map(I=>I.label)),formula2:K.map(I=>I.color===De?"":I.color).join(",")})},[Y,A,h,v,y]);const te=w.useEvent(async j=>{if(!o.isFormulaString(j)){A==null||A({formula1:"",formula2:d});return}f.getFormulaRefCheck(j)?(A==null||A({formula1:o.isFormulaString(j)?j:"",formula2:d}),P("")):(A==null||A({formula1:"",formula2:d}),S("="),P(M.t("dataValidation.validFail.formulaError")))}),ie=b.useRef(null),[he,ce]=b.useState(!1);return w.useSidebarClick(j=>{var I;((I=ie.current)==null?void 0:I.isClickOutSide(j))&&ce(!1)}),p.jsxs(p.Fragment,{children:[p.jsx(E.FormLayout,{label:M.t("dataValidation.list.options"),children:p.jsxs(E.RadioGroup,{value:h,onChange:j=>{g(j),S(v),j==="1"&&A({formula1:v==="="?"":v,formula2:y.join(",")})},children:[p.jsx(E.Radio,{value:"0",children:M.t("dataValidation.list.customOptions")}),p.jsx(E.Radio,{value:"1",children:M.t("dataValidation.list.refOptions")})]})}),h==="1"?p.jsxs(E.FormLayout,{error:U||H||void 0,children:[p.jsx(lt.FormulaEditor,{ref:ie,className:E.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",E.borderClassName),initValue:u,unitId:n,subUnitId:r,isFocus:he,isSupportAcrossSheet:!0,onFocus:()=>ce(!0),onChange:(j="")=>{const K=(j!=null?j:"").trim();T(K),te(K)}}),ee.length>0&&p.jsx("div",{style:{marginTop:"12px"},children:ee.map(j=>p.jsx(pt,{item:j,commonProps:{onItemChange:le},style:{marginBottom:12}},j.id))})]}):p.jsx(E.FormLayout,{error:U,children:p.jsxs("div",{style:{marginTop:"-12px"},children:[p.jsx(E.DraggableList,{list:Y,onListChange:X,rowHeight:28,margin:[0,12],draggableHandle:".draggableHandle",itemRender:j=>p.jsx(pt,{item:j,commonProps:{onItemChange:G,onItemDelete:J}},j.id),idKey:"id"}),p.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:re,children:[p.jsx(yt,{className:"univer-mr-1"}),M.t("dataValidation.list.add")]})]})})]})}const en=[[_.CUSTOM_FORMULA_INPUT_NAME,Nt],[_.BASE_FORMULA_INPUT_NAME,kt],[_.LIST_FORMULA_INPUT_NAME,Qt],[_.CHECKBOX_FORMULA_INPUT_NAME,Ft]];var tn=Object.getOwnPropertyDescriptor,nn=(e,t,a,n)=>{for(var r=n>1?void 0:n?tn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},an=(e,t)=>(a,n)=>t(a,n,e);exports.BaseSheetDataValidatorView=class{constructor(t){O(this,"canvasRender",null);O(this,"dropdownType");O(this,"optionsInput");O(this,"formulaInput",_.LIST_FORMULA_INPUT_NAME);this.injector=t}};exports.BaseSheetDataValidatorView=nn([an(0,o.Inject(o.Injector))],exports.BaseSheetDataValidatorView);var rn=Object.getOwnPropertyDescriptor,on=(e,t,a,n)=>{for(var r=n>1?void 0:n?rn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},vt=(e,t)=>(a,n)=>t(a,n,e);let ue=class extends o.Disposable{constructor(t,a){super();O(this,"_open$",new ae.BehaviorSubject(!1));O(this,"open$",this._open$.pipe(ae.distinctUntilChanged()));O(this,"_activeRule");O(this,"_activeRule$",new ae.BehaviorSubject(void 0));O(this,"activeRule$",this._activeRule$.asObservable());O(this,"_closeDisposable",null);this._univerInstanceService=t,this._sidebarService=a,this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).pipe(ae.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)}};ue=on([vt(0,o.IUniverInstanceService),vt(1,w.ISidebarService)],ue);const ut="sheets-data-validation-ui.config",Fe={};var sn=Object.getOwnPropertyDescriptor,ln=(e,t,a,n)=>{for(var r=n>1?void 0:n?sn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ie=(e,t)=>(a,n)=>t(a,n,e);let Ve=class extends o.Disposable{constructor(e,t,a,n,r,i){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=a,this._dialogService=n,this._localeService=r,this._sheetsDataValidationValidatorService=i,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this._sheetInterceptorService.writeCellInterceptor.intercept(W.VALIDATE_CELL,{handler:async(e,t,a)=>{const n=await e,{row:r,col:i,unitId:s,subUnitId:c}=t,l=this._dataValidationModel.getRuleIdByLocation(s,c,r,i),d=l?this._dataValidationModel.getRuleById(s,c,l):void 0;if(n===!1)return a(Promise.resolve(!1));if(!d||d.errorStyle!==o.DataValidationErrorStyle.STOP)return a(Promise.resolve(!0));const h=this._dataValidatorRegistryService.getValidatorItem(d.type);return!h||await this._sheetsDataValidationValidatorService.validatorCell(s,c,r,i)===o.DataValidationStatus.VALID?a(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t("dataValidation.alert.title")},id:"reject-input-dialog",children:{title:h.getRuleFinalError(d,{row:r,col:i,unitId:s,subUnitId:c})},footer:{title:b.createElement(E.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}}),a(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:b.createElement(E.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}})}};Ve=ln([Ie(0,o.Inject(W.SheetInterceptorService)),Ie(1,o.Inject(_.SheetDataValidationModel)),Ie(2,o.Inject($.DataValidatorRegistryService)),Ie(3,w.IDialogService),Ie(4,o.Inject(o.LocaleService)),Ie(5,o.Inject(_.SheetsDataValidationValidatorService))],Ve);var cn=Object.getOwnPropertyDescriptor,dn=(e,t,a,n)=>{for(var r=n>1?void 0:n?cn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},oe=(e,t)=>(a,n)=>t(a,n,e);const ze=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 un(e,t){const a=Ut.getPatternType(t);if(e===a)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,a,n,r,i,s,c,l,d,h,g){super();O(this,"_activeDropdown");O(this,"_activeDropdown$",new ae.Subject);O(this,"_currentPopup",null);O(this,"activeDropdown$",this._activeDropdown$.asObservable());O(this,"_zenVisible",!1);this._univerInstanceService=t,this._dataValidatorRegistryService=a,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=s,this._sheetDataValidationModel=c,this._commandService=l,this._editorBridgeService=d,this._injector=h,this._configService=g,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,a,n,r){const i=t?this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!i)return;const s=a?i.getSheetBySheetId(a):i.getActiveSheet();if(!s)return;const c=this._dataValidationModel.getRuleByLocation(i.getUnitId(),s.getSheetId(),n,r);if(!c)return;const l=this._dataValidatorRegistryService.getValidatorItem(c.type);return l==null?void 0:l.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(t=>{t&&t.every(a=>!(a.primary&&this._getDropdownByCell(a.primary.unitId,a.primary.sheetId,a.primary.actualRow,a.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){var T,M,m,C;const{location:a}=t,{row:n,col:r,unitId:i,subUnitId:s,workbook:c,worksheet:l}=a;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);const d=this._sheetDataValidationModel.getRuleByLocation(i,s,n,r);if(!d)return;const h=this._dataValidatorRegistryService.getValidatorItem(d.type);if(!(h!=null&&h.dropdownType))return;let g;const u=async(f,y)=>{var k,F,A;if(!f)return!0;const R=f,D=l.getCell(n,r),V=R.format(y==="date"?"YYYY-MM-DD 00:00:00":"YYYY-MM-DD HH:mm:ss"),x=(k=o.numfmt.parseDate(V))==null?void 0:k.v,H=y==="time"?x%1:x,P=c.getStyles().getStyleByCell(D),U=(A=(F=P==null?void 0:P.n)==null?void 0:F.pattern)!=null?A:"";return d.errorStyle!==o.DataValidationErrorStyle.STOP||await h.validator({value:H,unitId:i,subUnitId:s,row:n,column:r,worksheet:l,workbook:c,interceptValue:V.replace("Z","").replace("T"," "),t:o.CellValueType.NUMBER},d)?(await this._commandService.executeCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),await this._commandService.executeCommand(W.SetRangeValuesCommand.id,{unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:H,t:2,p:null,f:null,si:null,s:{n:{pattern:un(y,U)}}}}),!0):(this._injector.has(Ve)&&this._injector.get(Ve).showReject(h.getRuleFinalError(d,{row:n,col:r,unitId:i,subUnitId:s})),!1)};let S;switch(h.dropdownType){case $.DataValidatorDropdownType.DATE:{const f=_.getCellValueOrigin(l.getCellRaw(n,r)),y=ze(f),R=!!((T=d.bizInfo)!=null&&T.showTime);S={location:a,type:"datepicker",props:{showTime:R,onChange:D=>u(D,R?"datetime":"date"),defaultValue:y,patternType:"date"}};break}case $.DataValidatorDropdownType.TIME:{const f=_.getCellValueOrigin(l.getCellRaw(n,r)),y=ze(f);S={location:a,type:"datepicker",props:{onChange:R=>u(R,"time"),defaultValue:y,patternType:"time"}};break}case $.DataValidatorDropdownType.DATETIME:{const f=_.getCellValueOrigin(l.getCellRaw(n,r)),y=ze(f);S={location:a,type:"datepicker",props:{onChange:R=>u(R,"datetime"),defaultValue:y,patternType:"datetime"}};break}case $.DataValidatorDropdownType.LIST:case $.DataValidatorDropdownType.MULTIPLE_LIST:{const f=h.dropdownType===$.DataValidatorDropdownType.MULTIPLE_LIST,y=async P=>{const U=_.serializeListOptions(P),k={unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,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:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),this._commandService.executeCommand(W.SetRangeValuesCommand.id,k),!f},R=(d==null?void 0:d.renderMode)===o.DataValidationRenderMode.CUSTOM||(d==null?void 0:d.renderMode)===void 0,D=h.getListWithColor(d,i,s),V=_.getDataValidationCellValue(l.getCellRaw(n,r)),x=()=>{this._commandService.executeCommand(_e.id,{ruleId:d.uid}),g==null||g.dispose()},H=D.map(P=>({label:P.label,value:P.label,color:R||P.color?P.color:"transparent"}));S={location:a,type:"list",props:{onChange:P=>y(P),options:H,onEdit:x,defaultValue:V,multiple:f,showEdit:(m=(M=this._configService.getConfig(ut))==null?void 0:M.showEditOnDropdown)!=null?m:!0}};break}case $.DataValidatorDropdownType.CASCADE:{S={type:"cascader",props:{onChange:y=>{const R={unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:y.join("/"),p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),this._commandService.syncExecuteCommand(W.SetRangeValuesCommand.id,R),!0},defaultValue:_.getDataValidationCellValue(l.getCellRaw(n,r)).split("/"),options:JSON.parse((C=d.formula1)!=null?C:"[]")},location:a};break}case $.DataValidatorDropdownType.COLOR:{S={type:"color",props:{onChange:y=>{const R={unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:y,p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),this._commandService.syncExecuteCommand(W.SetRangeValuesCommand.id,R),!0},defaultValue:_.getDataValidationCellValue(l.getCellRaw(n,r))},location:a};break}default:throw new Error("[DataValidationDropdownManagerService]: unknown type!")}if(g=this._cellDropdownManagerService.showDropdown(S),!g)throw new Error("[DataValidationDropdownManagerService]: cannot show dropdown!");const v=new o.DisposableCollection;v.add(g),v.add({dispose:()=>{var f,y;(y=(f=this._activeDropdown)==null?void 0:f.onHide)==null||y.call(f)}}),this._currentPopup=v}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(t,a,n,r,i){const s=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!s)return;const c=s.getSheetBySheetId(a);if(!c)return;const l=this._dataValidationModel.getRuleByLocation(s.getUnitId(),c.getSheetId(),n,r);if(!l)return;const d=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!d||!d.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:s,worksheet:c,row:n,col:r,unitId:t,subUnitId:a},onHide:i})}};fe=dn([oe(0,o.IUniverInstanceService),oe(1,o.Inject($.DataValidatorRegistryService)),oe(2,w.IZenZoneService),oe(3,o.Inject(_.SheetDataValidationModel)),oe(4,o.Inject(W.SheetsSelectionsService)),oe(5,o.Inject(B.ISheetCellDropdownManagerService)),oe(6,o.Inject(_.SheetDataValidationModel)),oe(7,o.ICommandService),oe(8,B.IEditorBridgeService),oe(9,o.Inject(o.Injector)),oe(10,o.IConfigService)],fe);const Ne="DataValidationPanel",_e={id:"data-validation.operation.open-validation-panel",type:o.CommandType.OPERATION,handler(e,t){if(!t)return!1;const{ruleId:a,isAdd:n}=t,r=e.get(ue),i=e.get($.DataValidationModel),s=e.get(o.IUniverInstanceService),c=e.get(w.ISidebarService),l=W.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:h}=l,g=a?i.getRuleById(d,h,a):void 0;r.open(),r.setActiveRule(g&&{unitId:d,subUnitId:h,rule:g});const u=c.open({id:Ne,header:{title:n?"dataValidation.panel.addTitle":"dataValidation.panel.title"},children:{label:Ne},width:312,onClose:()=>r.close()});return r.setCloseDisposable(u),!0}},ht={id:"data-validation.operation.close-validation-panel",type:o.CommandType.OPERATION,handler(e){return e.get(ue).close(),!0}},Vt={id:"data-validation.operation.toggle-validation-panel",type:o.CommandType.OPERATION,handler(e){const t=e.get(o.ICommandService),a=e.get(ue);return a.open(),a.isOpen?t.executeCommand(ht.id):t.executeCommand(_e.id),!0}},Ye={type:o.CommandType.OPERATION,id:"sheet.operation.show-data-validation-dropdown",handler(e,t){if(!t)return!1;const a=e.get(fe),{unitId:n,subUnitId:r,row:i,column:s}=t,c=a.activeDropdown,l=c==null?void 0:c.location;return l&&l.unitId===n&&l.subUnitId===r&&l.row===i&&l.col===s||a.showDataValidationDropdown(n,r,i,s),!0}},wt={type:o.CommandType.OPERATION,id:"sheet.operation.hide-data-validation-dropdown",handler(e,t){return t?(e.get(fe).hideDropdown(),!0):!1}},Xe={type:o.CommandType.COMMAND,id:"data-validation.command.addRuleAndOpen",handler(e){const t=e.get(o.IUniverInstanceService),a=W.getSheetCommandTarget(t);if(!a)return!1;const{workbook:n,worksheet:r}=a,i=_.createDefaultNewRule(e),s=e.get(o.ICommandService),c=n.getUnitId(),l=r.getSheetId(),d={rule:i,unitId:c,subUnitId:l};return s.syncExecuteCommand(_.AddSheetDataValidationCommand.id,d)?(s.syncExecuteCommand(_e.id,{ruleId:i.uid,isAdd:!0}),!0):!1}};var hn=Object.getOwnPropertyDescriptor,gn=(e,t,a,n)=>{for(var r=n>1?void 0:n?hn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ce=(e,t)=>(a,n)=>t(a,n,e);const pe="SHEET_DATA_VALIDATION_ALERT";let Pe=class extends o.Disposable{constructor(e,t,a,n,r,i){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=a,this._localeService=n,this._zenZoneService=r,this._dataValidationModel=i,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(ae.debounceTime(100)).subscribe(e=>{var t;if(e){const a=this._univerInstanceService.getUnit(e.location.unitId,o.UniverInstanceType.UNIVER_SHEET),n=a.getSheetBySheetId(e.location.subUnitId);if(!n)return;const r=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!r){this._cellAlertManagerService.removeAlert(pe);return}if(this._dataValidationModel.validator(r,{...e.location,workbook:a,worksheet:n})===o.DataValidationStatus.INVALID){const s=this._cellAlertManagerService.currentAlert.get(pe),c=(t=s==null?void 0:s.alert)==null?void 0:t.location;if(c&&c.row===e.location.row&&c.col===e.location.col&&c.subUnitId===e.location.subUnitId&&c.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(pe);return}const l=this._dataValidationModel.getValidator(r.type);if(!l){this._cellAlertManagerService.removeAlert(pe);return}this._cellAlertManagerService.showAlert({type:B.CellAlertType.ERROR,title:this._localeService.t("dataValidation.error.title"),message:l==null?void 0:l.getRuleFinalError(r,e.location),location:e.location,width:200,height:74,key:pe});return}}this._cellAlertManagerService.removeAlert(pe)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(pe)}))}};Pe=gn([Ce(0,o.Inject(B.HoverManagerService)),Ce(1,o.Inject(B.CellAlertManagerService)),Ce(2,o.IUniverInstanceService),Ce(3,o.Inject(o.LocaleService)),Ce(4,w.IZenZoneService),Ce(5,o.Inject(_.SheetDataValidationModel))],Pe);var pn=Object.getOwnPropertyDescriptor,vn=(e,t,a,n)=>{for(var r=n>1?void 0:n?pn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ke=(e,t)=>(a,n)=>t(a,n,e);let we=class extends o.Disposable{constructor(e,t,a){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=a,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),t=(n,r)=>{const{source:i,target:s,unitId:c,subUnitId:l}=n,d=this._sheetDataValidationModel.getRuleObjectMatrix(c,l).clone(),h=B.virtualizeDiscreteRanges([i,s]),[g,u]=h.ranges,{mapFunc:S}=h,v={row:g.startRow,col:g.startColumn},T=B.getAutoFillRepeatRange(g,u),M=new o.ObjectMatrix,m=new Set;T.forEach(D=>{const V=D.repeatStartCell,x=D.relativeRange,H={startRow:v.row,startColumn:v.col,endColumn:v.col,endRow:v.row},P={startRow:V.row,startColumn:V.col,endColumn:V.col,endRow:V.row};o.Range.foreach(x,(U,k)=>{const F=o.Rectangle.getPositionRange({startRow:U,startColumn:k,endColumn:k,endRow:U},H),{row:A,col:Y}=S(F.startRow,F.startColumn),X=this._sheetDataValidationModel.getRuleIdByLocation(c,l,A,Y)||"",G=o.Rectangle.getPositionRange({startRow:U,startColumn:k,endColumn:k,endRow:U},P),{row:J,col:q}=S(G.startRow,G.startColumn);M.setValue(J,q,X),m.add(X)})});const C=Array.from(m).map(D=>({id:D,ranges:o.queryObjectMatrix(M,V=>V===D)}));d.addRangeRules(C);const f=d.diff(this._sheetDataValidationModel.getRules(c,l)),{redoMutations:y,undoMutations:R}=_.getDataValidationDiffMutations(c,l,f,this._injector,"patched",r===B.APPLY_TYPE.ONLY_FORMAT);return{undos:R,redos:y}},a={id:_.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:n=>{const{source:r,unitId:i,subUnitId:s}=n;for(const c of r.rows)for(const l of r.cols){const d=this._sheetDataValidationModel.getRuleByLocation(i,s,c,l);if(d&&d.type===o.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(B.APPLY_TYPE.SERIES,!0);return}}},onFillData:(n,r,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(a))}};we=vn([Ke(0,B.IAutoFillService),Ke(1,o.Inject(_.SheetDataValidationModel)),Ke(2,o.Inject(o.Injector))],we);var mn=Object.getOwnPropertyDescriptor,fn=(e,t,a,n)=>{for(var r=n>1?void 0:n?mn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ge=(e,t)=>(a,n)=>t(a,n,e);let Ee=class extends o.Disposable{constructor(t,a,n){super();O(this,"_copyInfo");this._sheetClipboardService=t,this._sheetDataValidationModel=a,this._injector=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:_.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(t,a,n)=>this._collect(t,a,n),onPasteCells:(t,a,n,r)=>{const{copyType:i=B.COPY_TYPE.COPY,pasteType:s}=r,{range:c}=t||{},{range:l,unitId:d,subUnitId:h}=a;return this._generateMutations(l,{copyType:i,pasteType:s,copyRange:c,unitId:d,subUnitId:h})}})}_collect(t,a,n){const r=new o.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:a,matrix:r};const i=this._injector.invoke(l=>W.rangeToDiscreteRange(n,l,t,a));if(!i)return;const{rows:s,cols:c}=i;s.forEach((l,d)=>{c.forEach((h,g)=>{const u=this._sheetDataValidationModel.getRuleIdByLocation(t,a,l,h);r.setValue(d,g,u!=null?u:"")})})}_generateMutations(t,a){if(!this._copyInfo)return{redos:[],undos:[]};if(a.copyType===B.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!a.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(a.pasteType))return{redos:[],undos:[]};const{unitId:r,subUnitId:i}=this._copyInfo;if(a.unitId!==r||i!==a.subUnitId){const s=this._sheetDataValidationModel.getRuleObjectMatrix(a.unitId,a.subUnitId).clone(),c=new o.ObjectMatrix,l=new Set,{ranges:[d,h],mapFunc:g}=B.virtualizeDiscreteRanges([a.copyRange,t]),u=B.getRepeatRange(d,h,!0),S=new Map;u.forEach(({startRange:m})=>{var C;(C=this._copyInfo)==null||C.matrix.forValue((f,y,R)=>{const D=o.Rectangle.getPositionRange({startRow:f,endRow:f,startColumn:y,endColumn:y},m),V=`${i}-${R}`,x=this._sheetDataValidationModel.getRuleById(r,i,R);!this._sheetDataValidationModel.getRuleById(a.unitId,a.subUnitId,V)&&x&&S.set(V,{...x,uid:V});const{row:H,col:P}=g(D.startRow,D.startColumn);l.add(V),c.setValue(H,P,V)})});const v=Array.from(l).map(m=>({id:m,ranges:o.queryObjectMatrix(c,C=>C===m)}));s.addRangeRules(v);const{redoMutations:T,undoMutations:M}=_.getDataValidationDiffMutations(a.unitId,a.subUnitId,s.diffWithAddition(this._sheetDataValidationModel.getRules(a.unitId,a.subUnitId),S.values()),this._injector,"patched",!1);return{redos:T,undos:M}}else{const s=this._sheetDataValidationModel.getRuleObjectMatrix(r,i).clone(),c=new o.ObjectMatrix,l=new Set,{ranges:[d,h],mapFunc:g}=B.virtualizeDiscreteRanges([a.copyRange,t]);B.getRepeatRange(d,h,!0).forEach(({startRange:M})=>{var m;(m=this._copyInfo)==null||m.matrix.forValue((C,f,y)=>{const R=o.Rectangle.getPositionRange({startRow:C,endRow:C,startColumn:f,endColumn:f},M),{row:D,col:V}=g(R.startRow,R.startColumn);c.setValue(D,V,y),l.add(y)})});const S=Array.from(l).map(M=>({id:M,ranges:o.queryObjectMatrix(c,m=>m===M)}));s.addRangeRules(S);const{redoMutations:v,undoMutations:T}=_.getDataValidationDiffMutations(r,i,s.diff(this._sheetDataValidationModel.getRules(r,i)),this._injector,"patched",!1);return{redos:v,undos:T}}}};Ee=fn([Ge(0,B.ISheetClipboardService),Ge(1,o.Inject(_.SheetDataValidationModel)),Ge(2,o.Inject(o.Injector))],Ee);var Sn=Object.getOwnPropertyDescriptor,_n=(e,t,a,n)=>{for(var r=n>1?void 0:n?Sn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},qe=(e,t)=>(a,n)=>t(a,n,e);let Me=class extends o.Disposable{constructor(e,t,a){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=a,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{e.id===_.AddSheetDataValidationCommand.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[W.WorkbookEditablePermission],rangeTypes:[W.RangeProtectionPermissionEditPoint],worksheetTypes:[W.WorksheetEditPermission,W.WorksheetSetCellStylePermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))),e.id===_.UpdateSheetDataValidationRangeCommand.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[W.WorkbookEditablePermission],rangeTypes:[W.RangeProtectionPermissionEditPoint],worksheetTypes:[W.WorksheetEditPermission,W.WorksheetSetCellStylePermission]},e.params.ranges)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr")))}))}};Me=_n([qe(0,o.Inject(o.LocaleService)),qe(1,o.ICommandService),qe(2,o.Inject(W.SheetPermissionCheckController))],Me);const Et="data-validation-single",Mt="sheet.menu.data-validation";function In(e){return{id:Mt,type:w.MenuItemType.SUBITEMS,icon:Et,tooltip:"dataValidation.title",hidden$:w.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:B.getCurrentRangeDisable$(e,{workbookTypes:[W.WorkbookEditablePermission],worksheetTypes:[W.WorksheetSetCellStylePermission,W.WorksheetEditPermission],rangeTypes:[W.RangeProtectionPermissionEditPoint]})}}function Cn(e){return{id:_e.id,title:"dataValidation.panel.title",type:w.MenuItemType.BUTTON}}function yn(e){return{id:Xe.id,title:"dataValidation.panel.add",type:w.MenuItemType.BUTTON}}const Dn={[w.RibbonDataGroup.RULES]:{[Mt]:{order:0,menuItemFactory:In,[_e.id]:{order:0,menuItemFactory:Cn},[Xe.id]:{order:1,menuItemFactory:yn}}}};var Rn=Object.getOwnPropertyDescriptor,bt=(e,t,a,n)=>{for(var r=n>1?void 0:n?Rn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Z=(e,t)=>(a,n)=>t(a,n,e);const Tt={tr:{size:6,color:"#fe4b4b"}};let be=class extends o.RxDisposable{constructor(e,t,a,n,r,i,s,c,l,d,h){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=a,this._univerInstanceService=n,this._autoHeightController=r,this._dropdownManagerService=i,this._sheetDataValidationModel=s,this._dataValidatorRegistryService=c,this._sheetInterceptorService=l,this._dataValidationCacheService=d,this._editorBridgeService=h,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(Dn)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{var a;if(!e.visible){((a=this._dropdownManagerService.activeDropdown)==null?void 0:a.trigger)==="editor-bridge"&&this._dropdownManagerService.hideDropdown();return}const t=this._editorBridgeService.getEditCellState();if(t){const{unitId:n,sheetId:r,row:i,column:s}=t,c=this._univerInstanceService.getUniverSheetInstance(n);if(!c)return;const l=this._sheetDataValidationModel.getRuleByLocation(n,r,i,s);if(!l)return;const d=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!(d!=null&&d.dropdownType))return;const h=c.getActiveSheet();if(!h)return;const g=this._dropdownManagerService.activeDropdown,u=g==null?void 0:g.location;if(u&&u.unitId===n&&u.subUnitId===r&&u.row===i&&u.col===s)return;this._dropdownManagerService.showDropdown({location:{unitId:n,subUnitId:r,row:i,col:s,workbook:c,worksheet:h},trigger:"editor-bridge",closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(W.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:W.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,a)=>{var m,C,f,y,R;const{row:n,col:r,unitId:i,subUnitId:s,workbook:c,worksheet:l}=t,d=this._sheetDataValidationModel.getRuleIdByLocation(i,s,n,r);if(!d)return a(e);const h=this._sheetDataValidationModel.getRuleById(i,s,d);if(!h)return a(e);const g=(m=this._dataValidationCacheService.getValue(i,s,n,r))!=null?m:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=t.rawData;let v;const T={get value(){var D;return v!==void 0||(v=(D=_.getCellValueOrigin(S))!=null?D:null),v}},M={get value(){var D;return`${(D=T.value)!=null?D:""}`}};return a({...e,markers:{...e==null?void 0:e.markers,...g===o.DataValidationStatus.INVALID?Tt: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:((f=e==null?void 0:e.fontRenderExtension)==null?void 0:f.isSkip)||((y=u==null?void 0:u.skipDefaultFontRender)==null?void 0:y.call(u,h,T.value,t))},interceptorStyle:{...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,M.value,{get style(){const D=c.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,r)},interceptorAutoHeight:()=>{var H,P,U,k,F,A;const D=(P=(H=this._renderManagerService.getRenderById(i))==null?void 0:H.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!D)return;const V=D.worksheet.getMergedCell(n,r),x={data:e,style:D.getStyles().getStyleByCell(e),primaryWithCoord:D.getCellWithCoordByIndex((U=V==null?void 0:V.startRow)!=null?U:n,(k=V==null?void 0:V.startColumn)!=null?k:r),unitId:i,subUnitId:s,row:n,col:r,workbook:c,worksheet:l};return(A=(F=u==null?void 0:u.canvasRender)==null?void 0:F.calcCellAutoHeight)==null?void 0:A.call(F,x)},interceptorAutoWidth:()=>{var H,P,U,k,F,A;const D=(P=(H=this._renderManagerService.getRenderById(i))==null?void 0:H.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!D)return;const V=D.worksheet.getMergedCell(n,r),x={data:e,style:D.getStyles().getStyleByCell(e),primaryWithCoord:D.getCellWithCoordByIndex((U=V==null?void 0:V.startRow)!=null?U:n,(k=V==null?void 0:V.startColumn)!=null?k:r),unitId:i,subUnitId:s,row:n,col:r,workbook:c,worksheet:l};return(A=(F=u==null?void 0:u.canvasRender)==null?void 0:F.calcCellAutoWidth)==null?void 0:A.call(F,x)},coverable:((R=e==null?void 0:e.coverable)!=null?R:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE)})}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(ae.filter(e=>e.source==="command"),ae.bufferTime(100)).subscribe(e=>{if(e.length===0)return;const t=[];if(e.forEach(a=>{var n;(a.rule.type===o.DataValidationType.LIST_MULTIPLE||a.rule.type===o.DataValidationType.LIST)&&(n=a.rule)!=null&&n.ranges&&t.push(...a.rule.ranges)}),t.length){const a=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(a.redos,this._commandService)}})}};be=bt([Z(0,o.ICommandService),Z(1,w.IMenuManagerService),Z(2,L.IRenderManagerService),Z(3,o.IUniverInstanceService),Z(4,o.Inject(B.AutoHeightController)),Z(5,o.Inject(fe)),Z(6,o.Inject(_.SheetDataValidationModel)),Z(7,o.Inject($.DataValidatorRegistryService)),Z(8,o.Inject(W.SheetInterceptorService)),Z(9,o.Inject(_.DataValidationCacheService)),Z(10,o.Optional(B.IEditorBridgeService))],be);let mt=class extends o.RxDisposable{constructor(e,t,a,n,r,i,s){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=a,this._dataValidatorRegistryService=n,this._sheetInterceptorService=r,this._sheetDataValidationModel=i,this._dataValidationCacheService=s,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(W.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:W.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,a)=>{var M,m,C,f,y;const{row:n,col:r,unitId:i,subUnitId:s,workbook:c,worksheet:l}=t,d=this._sheetDataValidationModel.getRuleIdByLocation(i,s,n,r);if(!d)return a(e);const h=this._sheetDataValidationModel.getRuleById(i,s,d);if(!h)return a(e);const g=(M=this._dataValidationCacheService.getValue(i,s,n,r))!=null?M:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=l.getCellRaw(n,r),v=_.getCellValueOrigin(S),T=`${v!=null?v:""}`;return a({...e,markers:{...e==null?void 0:e.markers,...g===o.DataValidationStatus.INVALID?Tt: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)||((f=u==null?void 0:u.skipDefaultFontRender)==null?void 0:f.call(u,h,v,t))},interceptorStyle:{...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,T,{get style(){const R=c.getStyles();return(typeof(e==null?void 0:e.s)=="string"?R.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},n,r)},interceptorAutoHeight:()=>{var x,H,P,U,k,F;const R=(H=(x=this._renderManagerService.getRenderById(i))==null?void 0:x.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:H.skeleton;if(!R)return;const D=R.worksheet.getMergedCell(n,r),V={data:e,style:R.getStyles().getStyleByCell(e),primaryWithCoord:R.getCellWithCoordByIndex((P=D==null?void 0:D.startRow)!=null?P:n,(U=D==null?void 0:D.startColumn)!=null?U:r),unitId:i,subUnitId:s,row:n,col:r,workbook:c,worksheet:l};return(F=(k=u==null?void 0:u.canvasRender)==null?void 0:k.calcCellAutoHeight)==null?void 0:F.call(k,V)},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(ae.filter(e=>e.source==="command"),ae.bufferTime(16)).subscribe(e=>{const t=[];if(e.forEach(a=>{var n;(n=a.rule)!=null&&n.ranges&&t.push(...a.rule.ranges)}),t.length){const a=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(a.redos,this._commandService)}})}};mt=bt([Z(0,o.ICommandService),Z(1,L.IRenderManagerService),Z(2,o.Inject(B.AutoHeightController)),Z(3,o.Inject($.DataValidatorRegistryService)),Z(4,o.Inject(W.SheetInterceptorService)),Z(5,o.Inject(_.SheetDataValidationModel)),Z(6,o.Inject(_.DataValidationCacheService))],mt);var Vn=Object.getOwnPropertyDescriptor,wn=(e,t,a,n)=>{for(var r=n>1?void 0:n?Vn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},ft=(e,t)=>(a,n)=>t(a,n,e);let Be=class extends o.Disposable{constructor(e,t,a){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=a,this._initSkeletonChange()}_initSkeletonChange(){const e=t=>{var n;if(!t.length)return;const a=new Set;t.forEach(r=>{a.add(r.subUnitId)}),a.forEach(r=>{var i;(i=this._sheetSkeletonManagerService.getSkeletonParam(r))==null||i.skeleton.makeDirty(!0)}),(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(o.bufferDebounceTime(16)).subscribe(e))}};Be=wn([ft(1,o.Inject(_.SheetDataValidationModel)),ft(2,o.Inject(B.SheetSkeletonManagerService))],Be);function En(e){var d;const t=w.useDependency(o.LocaleService),a=w.useDependency(w.ComponentManager),{value:n,onChange:r,extraComponent:i}=e,[s,c]=b.useState(!1),l=i?a.get(i):null;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white",onClick:()=>c(!s),children:[t.t("dataValidation.panel.options"),s?p.jsx(Dt,{className:"univer-ml-1"}):p.jsx(dt,{className:"univer-ml-1"})]}),s&&p.jsxs(p.Fragment,{children:[l?p.jsx(l,{value:n,onChange:r}):null,p.jsx(E.FormLayout,{label:t.t("dataValidation.panel.invalid"),children:p.jsxs(E.RadioGroup,{value:`${(d=n.errorStyle)!=null?d:o.DataValidationErrorStyle.WARNING}`,onChange:h=>r({...n,errorStyle:+h}),children:[p.jsx(E.Radio,{value:`${o.DataValidationErrorStyle.WARNING}`,children:t.t("dataValidation.panel.showWarning")}),p.jsx(E.Radio,{value:`${o.DataValidationErrorStyle.STOP}`,children:t.t("dataValidation.panel.rejectInput")})]})}),p.jsx(E.FormLayout,{label:t.t("dataValidation.panel.messageInfo"),children:p.jsx(E.Checkbox,{checked:n.showErrorMessage,onChange:()=>r({...n,showErrorMessage:!n.showErrorMessage}),children:t.t("dataValidation.panel.showInfo")})}),n.showErrorMessage?p.jsx(E.FormLayout,{children:p.jsx(E.Input,{value:n.error,onChange:h=>r({...n,error:h})})}):null]})]})}const Mn=e=>o.debounce(async(t,a,n,r)=>{const i=await e.executeCommand(t,a,n);r==null||r(i)},1e3);function bn(e,t,a){var n,r,i,s;return t?((r=(n=e.getUnit(t))==null?void 0:n.getSheetBySheetName(a))==null?void 0:r.getSheetId())||"":((s=(i=e.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetName(a))==null?void 0:s.getSheetId())||""}function Tn(){var j,K;const[e,t]=b.useState(0),a=w.useDependency(ue),n=w.useObservable(a.activeRule$,a.activeRule),{unitId:r,subUnitId:i,rule:s}=n||{},c=s.uid,l=w.useDependency($.DataValidatorRegistryService),d=w.useDependency(o.IUniverInstanceService),h=w.useDependency(w.ComponentManager),g=w.useDependency(o.ICommandService),u=w.useDependency($.DataValidationModel),S=w.useDependency(o.LocaleService),[v,T]=b.useState(s),M=l.getValidatorItem(v.type),[m,C]=b.useState(!1),f=l.getValidatorsByScope($.DataValidatorRegistryScope.SHEET),[y,R]=b.useState(()=>v.ranges.map(I=>({unitId:"",sheetId:"",range:I}))),D=b.useMemo(()=>Mn(g),[g]),[V,x]=b.useState(!1),[H,P]=b.useState(!1),U=b.useRef(null),k=w.useDependency(W.SheetsSelectionsService);if(b.useEffect(()=>()=>{const I=k.getCurrentLastSelection();I&&k.setSelections([I])},[k]),b.useEffect(()=>{g.onCommandExecuted(I=>{(I.id===o.UndoCommand.id||I.id===o.RedoCommand.id)&&setTimeout(()=>{const N=u.getRuleById(r,i,c);t(z=>z+1),N&&(T(N),R(N.ranges.map(z=>({unitId:"",sheetId:"",range:z}))))},20)})},[g,u,c,i,r]),!M)return null;const F=M.operators,A=M.operatorNames,Y=v.operator?$.TWO_FORMULA_OPERATOR_COUNT.includes(v.operator):!1,X=()=>{var I,N,z;(N=(I=U.current)==null?void 0:I.editor)!=null&&N.isFocus()&&G((z=U.current)==null?void 0:z.getValue()),!(!v.ranges.length||V)&&(M.validatorFormula(v,r,i).success?a.setActiveRule(null):C(!0))},G=w.useEvent(I=>{const N=I.split(",").filter(Boolean).map(at.deserializeRangeWithSheet).map(Q=>{const gt=Q.sheetName;if(gt){const Lt=bn(d,Q.unitId,gt);return{...Q,sheetId:Lt}}return{...Q,sheetId:""}});if(o.isUnitRangesEqual(N,y))return;R(N);const z=N.filter(Q=>(!Q.unitId||Q.unitId===r)&&(!Q.sheetId||Q.sheetId===i)).map(Q=>Q.range);if(T({...v,ranges:z}),z.length===0)return;const ge={unitId:r,subUnitId:i,ruleId:c,ranges:z};D(_.UpdateSheetDataValidationRangeCommand.id,ge)}),J=I=>{if(o.shallowEqual(I,$.getRuleSetting(v)))return;T({...v,...I});const N={unitId:r,subUnitId:i,ruleId:c,setting:I};D(_.UpdateSheetDataValidationSettingCommand.id,N,void 0)},q=async()=>{await g.executeCommand(_.RemoveSheetDataValidationCommand.id,{ruleId:c,unitId:r,subUnitId:i}),a.setActiveRule(null)},ee={type:v.type,operator:v.operator,formula1:v.formula1,formula2:v.formula2,allowBlank:v.allowBlank},le=I=>{const N=l.getValidatorItem(I);if(!N)return;const z=N.operators,ge=u.getRuleById(r,i,c),Q=I===(ge==null?void 0:ge.type)||I.includes("list")&&(ge!=null&&ge.type.includes("list"))?{...ge,type:I}:{...v,type:I,operator:z[0],formula1:void 0,formula2:void 0};T(Q),g.executeCommand(_.UpdateSheetDataValidationSettingCommand.id,{unitId:r,subUnitId:i,ruleId:v.uid,setting:$.getRuleSetting(Q)})},re=h.get(M.formulaInput),te=b.useMemo(()=>y.map(I=>at.serializeRange(I.range)).join(","),[]),ie=$.getRuleOptions(v),he=I=>{o.shallowEqual(I,$.getRuleOptions(v))||(T({...v,...I}),D(_.UpdateSheetDataValidationOptionsCommand.id,{unitId:r,subUnitId:i,ruleId:c,options:I}))},ce=F.length&&!v.operator;return p.jsxs("div",{"data-u-comp":"data-validation-detail",children:[p.jsx(E.FormLayout,{label:S.t("dataValidation.panel.range"),error:!v.ranges.length||V?S.t("dataValidation.panel.rangeError"):"",children:p.jsx(lt.RangeSelector,{selectorRef:U,unitId:r,subUnitId:i,initialValue:te,onChange:(I,N)=>{var z;!H&&((z=U.current)!=null&&z.verify())&&G(N)},onFocusChange:(I,N)=>{var z;P(I),!I&&N&&((z=U.current)!=null&&z.verify())&&G(N)},onVerify:I=>x(!I)})}),p.jsx(E.FormLayout,{label:S.t("dataValidation.panel.type"),children:p.jsx(E.Select,{className:"univer-w-full",value:v.type,options:(j=f==null?void 0:f.sort((I,N)=>I.order-N.order))==null?void 0:j.map(I=>({label:S.t(I.title),value:I.id})),onChange:le})}),F!=null&&F.length?p.jsx(E.FormLayout,{label:S.t("dataValidation.panel.operator"),children:p.jsx(E.Select,{className:"univer-w-full",value:`${v.operator}`,options:[{value:"",label:S.t("dataValidation.operators.legal")},...F.map((I,N)=>({value:`${I}`,label:A[N]}))],onChange:I=>{J({...ee,operator:I})}})}):null,re&&!ce?p.jsx(re,{isTwoFormula:Y,value:{formula1:v.formula1,formula2:v.formula2},onChange:I=>{J({...ee,...I})},showError:m,validResult:M.validatorFormula(v,r,i),unitId:r,subUnitId:i,ruleId:c},e+v.type):null,p.jsx(E.FormLayout,{children:p.jsx(E.Checkbox,{checked:(K=v.allowBlank)!=null?K:!0,onChange:()=>{var I;return J({...ee,allowBlank:!((I=v.allowBlank)==null||I)})},children:S.t("dataValidation.panel.allowBlank")})}),p.jsx(En,{value:ie,onChange:he,extraComponent:M.optionsInput}),p.jsxs("div",{className:"univer-mt-5 univer-flex univer-flex-row univer-justify-end",children:[p.jsx(E.Button,{className:"univer-ml-3",onClick:q,children:S.t("dataValidation.panel.removeRule")}),p.jsx(E.Button,{className:"univer-ml-3",variant:"primary",onClick:X,children:S.t("dataValidation.panel.done")})]})]})}const On=e=>{const{rule:t,onClick:a,unitId:n,subUnitId:r,disable:i}=e,s=w.useDependency($.DataValidatorRegistryService),c=w.useDependency(o.ICommandService),l=w.useDependency(B.IMarkSelectionService),d=s.getValidatorItem(t.type),h=b.useRef(void 0),[g,u]=b.useState(!1),S=w.useDependency(o.ThemeService),v=w.useObservable(S.currentTheme$),T=b.useMemo(()=>{var R;const m=S.getColorFromTheme("primary.600"),C=S.getColorFromTheme("loop-color.2"),f=(R=S.getColorFromTheme(C))!=null?R:m,y=new o.ColorKit(f).toRgb();return{fill:`rgba(${y.r}, ${y.g}, ${y.b}, 0.1)`,stroke:f}},[v]),M=m=>{c.executeCommand(_.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:n,subUnitId:r}),m.stopPropagation()};return b.useEffect(()=>()=>{var m;h.current&&((m=h.current)==null||m.forEach(C=>{C&&l.removeShape(C)}))},[l]),p.jsxs("div",{className:E.clsx(`
1
+ "use strict";var jt=Object.defineProperty;var xt=(e,t,a)=>t in e?jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a;var O=(e,t,a)=>xt(e,typeof t!="symbol"?t+"":t,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),_=require("@univerjs/sheets-data-validation"),p=require("react/jsx-runtime"),E=require("@univerjs/design"),w=require("@univerjs/ui"),b=require("react"),lt=require("@univerjs/sheets-formula-ui"),$=require("@univerjs/data-validation"),ae=require("rxjs"),L=require("@univerjs/engine-render"),W=require("@univerjs/sheets"),Ut=require("@univerjs/sheets-numfmt"),B=require("@univerjs/sheets-ui"),at=require("@univerjs/engine-formula"),kt=e=>{const{isTwoFormula:t=!1,value:a,onChange:n,showError:r,validResult:i}=e,s=w.useDependency(o.LocaleService),c=r?i==null?void 0:i.formula1:"",l=r?i==null?void 0:i.formula2:"";return t?p.jsxs(p.Fragment,{children:[p.jsx(E.FormLayout,{error:c,children:p.jsx(E.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:a==null?void 0:a.formula1,onChange:d=>{n==null||n({...a,formula1:d})}})}),p.jsx("div",{className:"-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400",children:s.t("dataValidation.panel.formulaAnd")}),p.jsx(E.FormLayout,{error:l,children:p.jsx(E.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:a==null?void 0:a.formula2,onChange:d=>{n==null||n({...a,formula2:d})}})})]}):p.jsx(E.FormLayout,{error:c,children:p.jsx(E.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:a==null?void 0:a.formula1,onChange:d=>{n==null||n({formula1:d})}})})};function Ft(e){const{value:t,onChange:a,showError:n,validResult:r}=e,i=w.useDependency(o.LocaleService),s=n?r==null?void 0:r.formula1:"",c=n?r==null?void 0:r.formula2:"",[l,d]=b.useState(!((t==null?void 0:t.formula1)===void 0&&(t==null?void 0:t.formula2)===void 0));return p.jsxs(p.Fragment,{children:[p.jsx(E.FormLayout,{children:p.jsx(E.Checkbox,{checked:l,onChange:h=>{h?d(!0):(d(!1),a==null||a({...t,formula1:void 0,formula2:void 0}))},children:i.t("dataValidation.checkbox.tips")})}),l?p.jsx(E.FormLayout,{label:i.t("dataValidation.checkbox.checked"),error:s,children:p.jsx(E.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula1,onChange:h=>{a==null||a({...t,formula1:h||void 0})}})}):null,l?p.jsx(E.FormLayout,{label:i.t("dataValidation.checkbox.unchecked"),error:c,children:p.jsx(E.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula2,onChange:h=>{a==null||a({...t,formula2:h||void 0})}})}):null]})}function Nt(e){var g;const{unitId:t,subUnitId:a,value:n,onChange:r,showError:i,validResult:s}=e,c=i?s==null?void 0:s.formula1:void 0,l=b.useRef(null),[d,h]=b.useState(!1);return w.useSidebarClick(u=>{var v;((v=l.current)==null?void 0:v.isClickOutSide(u))&&h(!1)}),p.jsx(E.FormLayout,{error:c,children:p.jsx(lt.FormulaEditor,{ref:l,className:E.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",E.borderClassName),initValue:(g=n==null?void 0:n.formula1)!=null?g:"=",unitId:t,subUnitId:a,isFocus:d,isSupportAcrossSheet:!0,onChange:u=>{const S=(u!=null?u:"").trim();S!==(n==null?void 0:n.formula1)&&(r==null||r({...n,formula1:S}))},onFocus:()=>h(!0)})})}var ne=function(){return ne=Object.assign||function(e){for(var t,a=1,n=arguments.length;a<n;a++){t=arguments[a];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},ne.apply(this,arguments)},Bt=function(e,t){var a={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(a[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(a[n[r]]=e[n[r]]);return a},Se=b.forwardRef(function(e,t){var a=e.icon,n=e.id,r=e.className,i=e.extend,s=Bt(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(n," ").concat(r||"").trim(),l=b.useRef("_".concat($t()));return It(a,"".concat(n),{defIds:a.defIds,idSuffix:l.current},ne({ref:t,className:c},s),i)});function It(e,t,a,n,r){return b.createElement(e.tag,ne(ne({key:t},Ht(e,a,r)),n),(Wt(e,a).children||[]).map(function(i,s){return It(i,"".concat(t,"-").concat(e.tag,"-").concat(s),a,void 0,r)}))}function Ht(e,t,a){var n=ne({},e.attrs);a!=null&&a.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=a.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(i){var s=i[0],c=i[1];s==="mask"&&typeof c=="string"&&(n[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var r=t.defIds;return!r||r.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],c=i[1];typeof c=="string"&&(n[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Wt(e,t){var a,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((a=e.children)===null||a===void 0)&&a.length)?ne(ne({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&n&&n.indexOf(r.attrs.id)>-1?ne(ne({},r),{attrs:ne(ne({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):e}function $t(){return Math.random().toString(36).substring(2,8)}Se.displayName="UniverIcon";var Yt={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"}}]},Ct=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"data-validation-single",ref:t,icon:Yt}))});Ct.displayName="DataValidationSingle";var Xt={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"}}]},ct=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"delete-single",ref:t,icon:Xt}))});ct.displayName="DeleteSingle";var zt={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"}}]},yt=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"increase-single",ref:t,icon:zt}))});yt.displayName="IncreaseSingle";var Kt={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"}}]},dt=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"more-down-single",ref:t,icon:Kt}))});dt.displayName="MoreDownSingle";var Gt={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"}}]},Dt=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"more-up-single",ref:t,icon:Gt}))});Dt.displayName="MoreUpSingle";var qt={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"}}]}]},Rt=b.forwardRef(function(e,t){return b.createElement(Se,Object.assign({},e,{id:"sequence-single",ref:t,icon:qt}))});Rt.displayName="SequenceSingle";const De="#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"],Jt=e=>{const{value:t,onChange:a,disabled:n}=e,[r,i]=b.useState(!1);return p.jsx(E.Dropdown,{align:"start",disabled:n,open:r,onOpenChange:i,overlay:p.jsx("div",{className:"univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5",children:Zt.map(s=>p.jsx("div",{className:E.clsx("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded",E.borderClassName),style:{background:s},onClick:()=>{a(s),i(!1)}},s))}),children:p.jsxs("div",{className:E.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",E.borderClassName),children:[p.jsx("div",{className:"univer-box-border univer-h-4 univer-w-4 univer-rounded univer-text-base",style:{background:t}}),p.jsx(dt,{})]})})},pt=e=>{const{item:t,commonProps:a,style:n}=e,{onItemChange:r,onItemDelete:i}=a;return p.jsxs("div",{className:"univer-flex univer-items-center univer-gap-2",style:n,children:[t.isRef?null:p.jsx("div",{className:E.clsx("univer-cursor-move","draggableHandle"),children:p.jsx(Rt,{})}),p.jsx(Jt,{value:t.color,onChange:s=>{r(t.id,t.label,s)}}),p.jsx(E.Input,{disabled:t.isRef,value:t.label,onChange:s=>{r(t.id,s,t.color)}}),t.isRef?null:p.jsx("div",{className:"univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",children:p.jsx(ct,{onClick:()=>i(t.id)})})]})};function Qt(e){const{value:t,onChange:a=()=>{},unitId:n,subUnitId:r,validResult:i,showError:s,ruleId:c}=e,{formula1:l="",formula2:d=""}=t||{},[h,g]=b.useState(()=>o.isFormulaString(l)?"1":"0"),[u,S]=b.useState(h==="1"?l:"="),[v,T]=b.useState(h==="1"?l:"="),M=w.useDependency(o.LocaleService),m=w.useDependency($.DataValidatorRegistryService),C=w.useDependency($.DataValidationModel),f=w.useDependency(_.DataValidationFormulaController),[y,R]=b.useState(()=>d.split(",")),D=m.getValidatorItem(o.DataValidationType.LIST),[V,x]=b.useState([]),[H,P]=b.useState(""),U=s?i==null?void 0:i.formula1:"",k=b.useMemo(()=>C.ruleChange$.pipe(ae.debounceTime(16)),[]),F=w.useObservable(k),A=w.useEvent(a);b.useEffect(()=>{(async()=>{await new Promise(I=>{setTimeout(()=>I(!0),100)});const j=C.getRuleById(n,r,c),K=j==null?void 0:j.formula1;if(o.isFormulaString(K)&&D&&j){const I=await D.getListAsync(j,n,r);x(I)}})()},[C,F,D,c,r,n]),b.useEffect(()=>{o.isFormulaString(l)&&l!==v&&(S(l),T(v))},[v,l]);const[Y,X]=b.useState(()=>{const j=h!=="1"?_.deserializeListOptions(l):[],K=d.split(",");return j.map((I,N)=>({label:I,color:K[N]||De,isRef:!1,id:o.Tools.generateRandomId(4)}))}),G=(j,K,I)=>{const N=Y.find(z=>z.id===j);N&&(N.label=K,N.color=I,X([...Y]))},J=j=>{const K=Y.findIndex(I=>I.id===j);K!==-1&&(Y.splice(K,1),X([...Y]))},q=d.split(","),ee=b.useMemo(()=>V.map((j,K)=>({label:j,color:q[K]||De,id:`${K}`,isRef:!0})),[q,V]),le=(j,K,I)=>{const N=[...y];N[+j]=I,R(N),A({formula1:l,formula2:N.join(",")})},re=()=>{X([...Y,{label:"",color:De,isRef:!1,id:o.Tools.generateRandomId(4)}])};b.useEffect(()=>{if(h==="1")return;const j=new Set,K=[];Y.map(I=>({labelList:I.label.split(","),item:I})).forEach(({item:I,labelList:N})=>{N.forEach(z=>{j.has(z)||(j.add(z),K.push({label:z,color:I.color}))})}),A({formula1:_.serializeListOptions(K.map(I=>I.label)),formula2:K.map(I=>I.color===De?"":I.color).join(",")})},[Y,A,h,v,y]);const te=w.useEvent(async j=>{if(!o.isFormulaString(j)){A==null||A({formula1:"",formula2:d});return}f.getFormulaRefCheck(j)?(A==null||A({formula1:o.isFormulaString(j)?j:"",formula2:d}),P("")):(A==null||A({formula1:"",formula2:d}),S("="),P(M.t("dataValidation.validFail.formulaError")))}),ie=b.useRef(null),[he,ce]=b.useState(!1);return w.useSidebarClick(j=>{var I;((I=ie.current)==null?void 0:I.isClickOutSide(j))&&ce(!1)}),p.jsxs(p.Fragment,{children:[p.jsx(E.FormLayout,{label:M.t("dataValidation.list.options"),children:p.jsxs(E.RadioGroup,{value:h,onChange:j=>{g(j),S(v),j==="1"&&A({formula1:v==="="?"":v,formula2:y.join(",")})},children:[p.jsx(E.Radio,{value:"0",children:M.t("dataValidation.list.customOptions")}),p.jsx(E.Radio,{value:"1",children:M.t("dataValidation.list.refOptions")})]})}),h==="1"?p.jsxs(E.FormLayout,{error:U||H||void 0,children:[p.jsx(lt.FormulaEditor,{ref:ie,className:E.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",E.borderClassName),initValue:u,unitId:n,subUnitId:r,isFocus:he,isSupportAcrossSheet:!0,onFocus:()=>ce(!0),onChange:(j="")=>{const K=(j!=null?j:"").trim();T(K),te(K)}}),ee.length>0&&p.jsx("div",{style:{marginTop:"12px"},children:ee.map(j=>p.jsx(pt,{item:j,commonProps:{onItemChange:le},style:{marginBottom:12}},j.id))})]}):p.jsx(E.FormLayout,{error:U,children:p.jsxs("div",{style:{marginTop:"-12px"},children:[p.jsx(E.DraggableList,{list:Y,onListChange:X,rowHeight:28,margin:[0,12],draggableHandle:".draggableHandle",itemRender:j=>p.jsx(pt,{item:j,commonProps:{onItemChange:G,onItemDelete:J}},j.id),idKey:"id"}),p.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:re,children:[p.jsx(yt,{className:"univer-mr-1"}),M.t("dataValidation.list.add")]})]})})]})}const en=[[_.CUSTOM_FORMULA_INPUT_NAME,Nt],[_.BASE_FORMULA_INPUT_NAME,kt],[_.LIST_FORMULA_INPUT_NAME,Qt],[_.CHECKBOX_FORMULA_INPUT_NAME,Ft]];var tn=Object.getOwnPropertyDescriptor,nn=(e,t,a,n)=>{for(var r=n>1?void 0:n?tn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},an=(e,t)=>(a,n)=>t(a,n,e);exports.BaseSheetDataValidatorView=class{constructor(t){O(this,"canvasRender",null);O(this,"dropdownType");O(this,"optionsInput");O(this,"formulaInput",_.LIST_FORMULA_INPUT_NAME);this.injector=t}};exports.BaseSheetDataValidatorView=nn([an(0,o.Inject(o.Injector))],exports.BaseSheetDataValidatorView);var rn=Object.getOwnPropertyDescriptor,on=(e,t,a,n)=>{for(var r=n>1?void 0:n?rn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},vt=(e,t)=>(a,n)=>t(a,n,e);let ue=class extends o.Disposable{constructor(t,a){super();O(this,"_open$",new ae.BehaviorSubject(!1));O(this,"open$",this._open$.pipe(ae.distinctUntilChanged()));O(this,"_activeRule");O(this,"_activeRule$",new ae.BehaviorSubject(void 0));O(this,"activeRule$",this._activeRule$.asObservable());O(this,"_closeDisposable",null);this._univerInstanceService=t,this._sidebarService=a,this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).pipe(ae.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)}};ue=on([vt(0,o.IUniverInstanceService),vt(1,w.ISidebarService)],ue);const ut="sheets-data-validation-ui.config",Fe={};var sn=Object.getOwnPropertyDescriptor,ln=(e,t,a,n)=>{for(var r=n>1?void 0:n?sn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ie=(e,t)=>(a,n)=>t(a,n,e);let Ve=class extends o.Disposable{constructor(e,t,a,n,r,i){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=a,this._dialogService=n,this._localeService=r,this._sheetsDataValidationValidatorService=i,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this._sheetInterceptorService.writeCellInterceptor.intercept(W.VALIDATE_CELL,{handler:async(e,t,a)=>{const n=await e,{row:r,col:i,unitId:s,subUnitId:c}=t,l=this._dataValidationModel.getRuleIdByLocation(s,c,r,i),d=l?this._dataValidationModel.getRuleById(s,c,l):void 0;if(n===!1)return a(Promise.resolve(!1));if(!d||d.errorStyle!==o.DataValidationErrorStyle.STOP)return a(Promise.resolve(!0));const h=this._dataValidatorRegistryService.getValidatorItem(d.type);return!h||await this._sheetsDataValidationValidatorService.validatorCell(s,c,r,i)===o.DataValidationStatus.VALID?a(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t("dataValidation.alert.title")},id:"reject-input-dialog",children:{title:h.getRuleFinalError(d,{row:r,col:i,unitId:s,subUnitId:c})},footer:{title:b.createElement(E.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}}),a(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:b.createElement(E.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}})}};Ve=ln([Ie(0,o.Inject(W.SheetInterceptorService)),Ie(1,o.Inject(_.SheetDataValidationModel)),Ie(2,o.Inject($.DataValidatorRegistryService)),Ie(3,w.IDialogService),Ie(4,o.Inject(o.LocaleService)),Ie(5,o.Inject(_.SheetsDataValidationValidatorService))],Ve);var cn=Object.getOwnPropertyDescriptor,dn=(e,t,a,n)=>{for(var r=n>1?void 0:n?cn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},oe=(e,t)=>(a,n)=>t(a,n,e);const ze=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 un(e,t){const a=Ut.getPatternType(t);if(e===a)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,a,n,r,i,s,c,l,d,h,g){super();O(this,"_activeDropdown");O(this,"_activeDropdown$",new ae.Subject);O(this,"_currentPopup",null);O(this,"activeDropdown$",this._activeDropdown$.asObservable());O(this,"_zenVisible",!1);this._univerInstanceService=t,this._dataValidatorRegistryService=a,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=s,this._sheetDataValidationModel=c,this._commandService=l,this._editorBridgeService=d,this._injector=h,this._configService=g,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,a,n,r){const i=t?this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!i)return;const s=a?i.getSheetBySheetId(a):i.getActiveSheet();if(!s)return;const c=this._dataValidationModel.getRuleByLocation(i.getUnitId(),s.getSheetId(),n,r);if(!c)return;const l=this._dataValidatorRegistryService.getValidatorItem(c.type);return l==null?void 0:l.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(t=>{t&&t.every(a=>!(a.primary&&this._getDropdownByCell(a.primary.unitId,a.primary.sheetId,a.primary.actualRow,a.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){var T,M,m,C;const{location:a}=t,{row:n,col:r,unitId:i,subUnitId:s,workbook:c,worksheet:l}=a;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);const d=this._sheetDataValidationModel.getRuleByLocation(i,s,n,r);if(!d)return;const h=this._dataValidatorRegistryService.getValidatorItem(d.type);if(!(h!=null&&h.dropdownType))return;let g;const u=async(f,y)=>{var k,F,A;if(!f)return!0;const R=f,D=l.getCell(n,r),V=R.format(y==="date"?"YYYY-MM-DD 00:00:00":"YYYY-MM-DD HH:mm:ss"),x=(k=o.numfmt.parseDate(V))==null?void 0:k.v,H=y==="time"?x%1:x,P=c.getStyles().getStyleByCell(D),U=(A=(F=P==null?void 0:P.n)==null?void 0:F.pattern)!=null?A:"";return d.errorStyle!==o.DataValidationErrorStyle.STOP||await h.validator({value:H,unitId:i,subUnitId:s,row:n,column:r,worksheet:l,workbook:c,interceptValue:V.replace("Z","").replace("T"," "),t:o.CellValueType.NUMBER},d)?(await this._commandService.executeCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),await this._commandService.executeCommand(W.SetRangeValuesCommand.id,{unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:H,t:2,p:null,f:null,si:null,s:{n:{pattern:un(y,U)}}}}),!0):(this._injector.has(Ve)&&this._injector.get(Ve).showReject(h.getRuleFinalError(d,{row:n,col:r,unitId:i,subUnitId:s})),!1)};let S;switch(h.dropdownType){case $.DataValidatorDropdownType.DATE:{const f=_.getCellValueOrigin(l.getCellRaw(n,r)),y=ze(f),R=!!((T=d.bizInfo)!=null&&T.showTime);S={location:a,type:"datepicker",props:{showTime:R,onChange:D=>u(D,R?"datetime":"date"),defaultValue:y,patternType:"date"}};break}case $.DataValidatorDropdownType.TIME:{const f=_.getCellValueOrigin(l.getCellRaw(n,r)),y=ze(f);S={location:a,type:"datepicker",props:{onChange:R=>u(R,"time"),defaultValue:y,patternType:"time"}};break}case $.DataValidatorDropdownType.DATETIME:{const f=_.getCellValueOrigin(l.getCellRaw(n,r)),y=ze(f);S={location:a,type:"datepicker",props:{onChange:R=>u(R,"datetime"),defaultValue:y,patternType:"datetime"}};break}case $.DataValidatorDropdownType.LIST:case $.DataValidatorDropdownType.MULTIPLE_LIST:{const f=h.dropdownType===$.DataValidatorDropdownType.MULTIPLE_LIST,y=async P=>{const U=_.serializeListOptions(P),k={unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,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:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),this._commandService.executeCommand(W.SetRangeValuesCommand.id,k),!f},R=(d==null?void 0:d.renderMode)===o.DataValidationRenderMode.CUSTOM||(d==null?void 0:d.renderMode)===void 0,D=h.getListWithColor(d,i,s),V=_.getDataValidationCellValue(l.getCellRaw(n,r)),x=()=>{this._commandService.executeCommand(_e.id,{ruleId:d.uid}),g==null||g.dispose()},H=D.map(P=>({label:P.label,value:P.label,color:R||P.color?P.color:"transparent"}));S={location:a,type:"list",props:{onChange:P=>y(P),options:H,onEdit:x,defaultValue:V,multiple:f,showEdit:(m=(M=this._configService.getConfig(ut))==null?void 0:M.showEditOnDropdown)!=null?m:!0}};break}case $.DataValidatorDropdownType.CASCADE:{S={type:"cascader",props:{onChange:y=>{const R={unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:y.join("/"),p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),this._commandService.syncExecuteCommand(W.SetRangeValuesCommand.id,R),!0},defaultValue:_.getDataValidationCellValue(l.getCellRaw(n,r)).split("/"),options:JSON.parse((C=d.formula1)!=null?C:"[]")},location:a};break}case $.DataValidatorDropdownType.COLOR:{S={type:"color",props:{onChange:y=>{const R={unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:y,p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),this._commandService.syncExecuteCommand(W.SetRangeValuesCommand.id,R),!0},defaultValue:_.getDataValidationCellValue(l.getCellRaw(n,r))},location:a};break}default:throw new Error("[DataValidationDropdownManagerService]: unknown type!")}if(g=this._cellDropdownManagerService.showDropdown(S),!g)throw new Error("[DataValidationDropdownManagerService]: cannot show dropdown!");const v=new o.DisposableCollection;v.add(g),v.add({dispose:()=>{var f,y;(y=(f=this._activeDropdown)==null?void 0:f.onHide)==null||y.call(f)}}),this._currentPopup=v}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(t,a,n,r,i){const s=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!s)return;const c=s.getSheetBySheetId(a);if(!c)return;const l=this._dataValidationModel.getRuleByLocation(s.getUnitId(),c.getSheetId(),n,r);if(!l)return;const d=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!d||!d.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:s,worksheet:c,row:n,col:r,unitId:t,subUnitId:a},onHide:i})}};fe=dn([oe(0,o.IUniverInstanceService),oe(1,o.Inject($.DataValidatorRegistryService)),oe(2,w.IZenZoneService),oe(3,o.Inject(_.SheetDataValidationModel)),oe(4,o.Inject(W.SheetsSelectionsService)),oe(5,o.Inject(B.ISheetCellDropdownManagerService)),oe(6,o.Inject(_.SheetDataValidationModel)),oe(7,o.ICommandService),oe(8,B.IEditorBridgeService),oe(9,o.Inject(o.Injector)),oe(10,o.IConfigService)],fe);const Ne="DataValidationPanel",_e={id:"data-validation.operation.open-validation-panel",type:o.CommandType.OPERATION,handler(e,t){if(!t)return!1;const{ruleId:a,isAdd:n}=t,r=e.get(ue),i=e.get($.DataValidationModel),s=e.get(o.IUniverInstanceService),c=e.get(w.ISidebarService),l=W.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:h}=l,g=a?i.getRuleById(d,h,a):void 0;r.open(),r.setActiveRule(g&&{unitId:d,subUnitId:h,rule:g});const u=c.open({id:Ne,header:{title:n?"dataValidation.panel.addTitle":"dataValidation.panel.title"},children:{label:Ne},width:312,onClose:()=>r.close()});return r.setCloseDisposable(u),!0}},ht={id:"data-validation.operation.close-validation-panel",type:o.CommandType.OPERATION,handler(e){return e.get(ue).close(),!0}},Vt={id:"data-validation.operation.toggle-validation-panel",type:o.CommandType.OPERATION,handler(e){const t=e.get(o.ICommandService),a=e.get(ue);return a.open(),a.isOpen?t.executeCommand(ht.id):t.executeCommand(_e.id),!0}},Ye={type:o.CommandType.OPERATION,id:"sheet.operation.show-data-validation-dropdown",handler(e,t){if(!t)return!1;const a=e.get(fe),{unitId:n,subUnitId:r,row:i,column:s}=t,c=a.activeDropdown,l=c==null?void 0:c.location;return l&&l.unitId===n&&l.subUnitId===r&&l.row===i&&l.col===s||a.showDataValidationDropdown(n,r,i,s),!0}},wt={type:o.CommandType.OPERATION,id:"sheet.operation.hide-data-validation-dropdown",handler(e,t){return t?(e.get(fe).hideDropdown(),!0):!1}},Xe={type:o.CommandType.COMMAND,id:"data-validation.command.addRuleAndOpen",handler(e){const t=e.get(o.IUniverInstanceService),a=W.getSheetCommandTarget(t);if(!a)return!1;const{workbook:n,worksheet:r}=a,i=_.createDefaultNewRule(e),s=e.get(o.ICommandService),c=n.getUnitId(),l=r.getSheetId(),d={rule:i,unitId:c,subUnitId:l};return s.syncExecuteCommand(_.AddSheetDataValidationCommand.id,d)?(s.syncExecuteCommand(_e.id,{ruleId:i.uid,isAdd:!0}),!0):!1}};var hn=Object.getOwnPropertyDescriptor,gn=(e,t,a,n)=>{for(var r=n>1?void 0:n?hn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ce=(e,t)=>(a,n)=>t(a,n,e);const pe="SHEET_DATA_VALIDATION_ALERT";let Pe=class extends o.Disposable{constructor(e,t,a,n,r,i){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=a,this._localeService=n,this._zenZoneService=r,this._dataValidationModel=i,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(ae.debounceTime(100)).subscribe(e=>{var t;if(e){const a=this._univerInstanceService.getUnit(e.location.unitId,o.UniverInstanceType.UNIVER_SHEET),n=a.getSheetBySheetId(e.location.subUnitId);if(!n)return;const r=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!r){this._cellAlertManagerService.removeAlert(pe);return}if(this._dataValidationModel.validator(r,{...e.location,workbook:a,worksheet:n})===o.DataValidationStatus.INVALID){const s=this._cellAlertManagerService.currentAlert.get(pe),c=(t=s==null?void 0:s.alert)==null?void 0:t.location;if(c&&c.row===e.location.row&&c.col===e.location.col&&c.subUnitId===e.location.subUnitId&&c.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(pe);return}const l=this._dataValidationModel.getValidator(r.type);if(!l){this._cellAlertManagerService.removeAlert(pe);return}this._cellAlertManagerService.showAlert({type:B.CellAlertType.ERROR,title:this._localeService.t("dataValidation.error.title"),message:l==null?void 0:l.getRuleFinalError(r,e.location),location:e.location,width:200,height:74,key:pe});return}}this._cellAlertManagerService.removeAlert(pe)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(pe)}))}};Pe=gn([Ce(0,o.Inject(B.HoverManagerService)),Ce(1,o.Inject(B.CellAlertManagerService)),Ce(2,o.IUniverInstanceService),Ce(3,o.Inject(o.LocaleService)),Ce(4,w.IZenZoneService),Ce(5,o.Inject(_.SheetDataValidationModel))],Pe);var pn=Object.getOwnPropertyDescriptor,vn=(e,t,a,n)=>{for(var r=n>1?void 0:n?pn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ke=(e,t)=>(a,n)=>t(a,n,e);let we=class extends o.Disposable{constructor(e,t,a){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=a,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),t=(n,r)=>{const{source:i,target:s,unitId:c,subUnitId:l}=n,d=this._sheetDataValidationModel.getRuleObjectMatrix(c,l).clone(),h=B.virtualizeDiscreteRanges([i,s]),[g,u]=h.ranges,{mapFunc:S}=h,v={row:g.startRow,col:g.startColumn},T=B.getAutoFillRepeatRange(g,u),M=new o.ObjectMatrix,m=new Set;T.forEach(D=>{const V=D.repeatStartCell,x=D.relativeRange,H={startRow:v.row,startColumn:v.col,endColumn:v.col,endRow:v.row},P={startRow:V.row,startColumn:V.col,endColumn:V.col,endRow:V.row};o.Range.foreach(x,(U,k)=>{const F=o.Rectangle.getPositionRange({startRow:U,startColumn:k,endColumn:k,endRow:U},H),{row:A,col:Y}=S(F.startRow,F.startColumn),X=this._sheetDataValidationModel.getRuleIdByLocation(c,l,A,Y)||"",G=o.Rectangle.getPositionRange({startRow:U,startColumn:k,endColumn:k,endRow:U},P),{row:J,col:q}=S(G.startRow,G.startColumn);M.setValue(J,q,X),m.add(X)})});const C=Array.from(m).map(D=>({id:D,ranges:o.queryObjectMatrix(M,V=>V===D)}));d.addRangeRules(C);const f=d.diff(this._sheetDataValidationModel.getRules(c,l)),{redoMutations:y,undoMutations:R}=_.getDataValidationDiffMutations(c,l,f,this._injector,"patched",r===B.APPLY_TYPE.ONLY_FORMAT);return{undos:R,redos:y}},a={id:_.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:n=>{const{source:r,unitId:i,subUnitId:s}=n;for(const c of r.rows)for(const l of r.cols){const d=this._sheetDataValidationModel.getRuleByLocation(i,s,c,l);if(d&&d.type===o.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(B.APPLY_TYPE.SERIES,!0);return}}},onFillData:(n,r,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(a))}};we=vn([Ke(0,B.IAutoFillService),Ke(1,o.Inject(_.SheetDataValidationModel)),Ke(2,o.Inject(o.Injector))],we);var mn=Object.getOwnPropertyDescriptor,fn=(e,t,a,n)=>{for(var r=n>1?void 0:n?mn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ge=(e,t)=>(a,n)=>t(a,n,e);let Ee=class extends o.Disposable{constructor(t,a,n){super();O(this,"_copyInfo");this._sheetClipboardService=t,this._sheetDataValidationModel=a,this._injector=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:_.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(t,a,n)=>this._collect(t,a,n),onPasteCells:(t,a,n,r)=>{const{copyType:i=B.COPY_TYPE.COPY,pasteType:s}=r,{range:c}=t||{},{range:l,unitId:d,subUnitId:h}=a;return this._generateMutations(l,{copyType:i,pasteType:s,copyRange:c,unitId:d,subUnitId:h})}})}_collect(t,a,n){const r=new o.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:a,matrix:r};const i=this._injector.invoke(l=>W.rangeToDiscreteRange(n,l,t,a));if(!i)return;const{rows:s,cols:c}=i;s.forEach((l,d)=>{c.forEach((h,g)=>{const u=this._sheetDataValidationModel.getRuleIdByLocation(t,a,l,h);r.setValue(d,g,u!=null?u:"")})})}_generateMutations(t,a){if(!this._copyInfo)return{redos:[],undos:[]};if(a.copyType===B.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!a.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(a.pasteType))return{redos:[],undos:[]};const{unitId:r,subUnitId:i}=this._copyInfo;if(a.unitId!==r||i!==a.subUnitId){const s=this._sheetDataValidationModel.getRuleObjectMatrix(a.unitId,a.subUnitId).clone(),c=new o.ObjectMatrix,l=new Set,{ranges:[d,h],mapFunc:g}=B.virtualizeDiscreteRanges([a.copyRange,t]),u=B.getRepeatRange(d,h,!0),S=new Map;u.forEach(({startRange:m})=>{var C;(C=this._copyInfo)==null||C.matrix.forValue((f,y,R)=>{const D=o.Rectangle.getPositionRange({startRow:f,endRow:f,startColumn:y,endColumn:y},m),V=`${i}-${R}`,x=this._sheetDataValidationModel.getRuleById(r,i,R);!this._sheetDataValidationModel.getRuleById(a.unitId,a.subUnitId,V)&&x&&S.set(V,{...x,uid:V});const{row:H,col:P}=g(D.startRow,D.startColumn);l.add(V),c.setValue(H,P,V)})});const v=Array.from(l).map(m=>({id:m,ranges:o.queryObjectMatrix(c,C=>C===m)}));s.addRangeRules(v);const{redoMutations:T,undoMutations:M}=_.getDataValidationDiffMutations(a.unitId,a.subUnitId,s.diffWithAddition(this._sheetDataValidationModel.getRules(a.unitId,a.subUnitId),S.values()),this._injector,"patched",!1);return{redos:T,undos:M}}else{const s=this._sheetDataValidationModel.getRuleObjectMatrix(r,i).clone(),c=new o.ObjectMatrix,l=new Set,{ranges:[d,h],mapFunc:g}=B.virtualizeDiscreteRanges([a.copyRange,t]);B.getRepeatRange(d,h,!0).forEach(({startRange:M})=>{var m;(m=this._copyInfo)==null||m.matrix.forValue((C,f,y)=>{const R=o.Rectangle.getPositionRange({startRow:C,endRow:C,startColumn:f,endColumn:f},M),{row:D,col:V}=g(R.startRow,R.startColumn);c.setValue(D,V,y),l.add(y)})});const S=Array.from(l).map(M=>({id:M,ranges:o.queryObjectMatrix(c,m=>m===M)}));s.addRangeRules(S);const{redoMutations:v,undoMutations:T}=_.getDataValidationDiffMutations(r,i,s.diff(this._sheetDataValidationModel.getRules(r,i)),this._injector,"patched",!1);return{redos:v,undos:T}}}};Ee=fn([Ge(0,B.ISheetClipboardService),Ge(1,o.Inject(_.SheetDataValidationModel)),Ge(2,o.Inject(o.Injector))],Ee);var Sn=Object.getOwnPropertyDescriptor,_n=(e,t,a,n)=>{for(var r=n>1?void 0:n?Sn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},qe=(e,t)=>(a,n)=>t(a,n,e);let Me=class extends o.Disposable{constructor(e,t,a){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=a,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{e.id===_.AddSheetDataValidationCommand.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[W.WorkbookEditablePermission],rangeTypes:[W.RangeProtectionPermissionEditPoint],worksheetTypes:[W.WorksheetEditPermission,W.WorksheetSetCellStylePermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))),e.id===_.UpdateSheetDataValidationRangeCommand.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[W.WorkbookEditablePermission],rangeTypes:[W.RangeProtectionPermissionEditPoint],worksheetTypes:[W.WorksheetEditPermission,W.WorksheetSetCellStylePermission]},e.params.ranges)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr")))}))}};Me=_n([qe(0,o.Inject(o.LocaleService)),qe(1,o.ICommandService),qe(2,o.Inject(W.SheetPermissionCheckController))],Me);const Et="data-validation-single",Mt="sheet.menu.data-validation";function In(e){return{id:Mt,type:w.MenuItemType.SUBITEMS,icon:Et,tooltip:"dataValidation.title",hidden$:w.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:B.getCurrentRangeDisable$(e,{workbookTypes:[W.WorkbookEditablePermission],worksheetTypes:[W.WorksheetSetCellStylePermission,W.WorksheetEditPermission],rangeTypes:[W.RangeProtectionPermissionEditPoint]})}}function Cn(e){return{id:_e.id,title:"dataValidation.panel.title",type:w.MenuItemType.BUTTON}}function yn(e){return{id:Xe.id,title:"dataValidation.panel.add",type:w.MenuItemType.BUTTON}}const Dn={[w.RibbonDataGroup.RULES]:{[Mt]:{order:0,menuItemFactory:In,[_e.id]:{order:0,menuItemFactory:Cn},[Xe.id]:{order:1,menuItemFactory:yn}}}};var Rn=Object.getOwnPropertyDescriptor,bt=(e,t,a,n)=>{for(var r=n>1?void 0:n?Rn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Z=(e,t)=>(a,n)=>t(a,n,e);const Tt={tr:{size:6,color:"#fe4b4b"}};let be=class extends o.RxDisposable{constructor(e,t,a,n,r,i,s,c,l,d,h){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=a,this._univerInstanceService=n,this._autoHeightController=r,this._dropdownManagerService=i,this._sheetDataValidationModel=s,this._dataValidatorRegistryService=c,this._sheetInterceptorService=l,this._dataValidationCacheService=d,this._editorBridgeService=h,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(Dn)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{var a;if(!e.visible){((a=this._dropdownManagerService.activeDropdown)==null?void 0:a.trigger)==="editor-bridge"&&this._dropdownManagerService.hideDropdown();return}const t=this._editorBridgeService.getEditCellState();if(t){const{unitId:n,sheetId:r,row:i,column:s}=t,c=this._univerInstanceService.getUniverSheetInstance(n);if(!c)return;const l=this._sheetDataValidationModel.getRuleByLocation(n,r,i,s);if(!l)return;const d=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!(d!=null&&d.dropdownType))return;const h=c.getActiveSheet();if(!h)return;const g=this._dropdownManagerService.activeDropdown,u=g==null?void 0:g.location;if(u&&u.unitId===n&&u.subUnitId===r&&u.row===i&&u.col===s)return;this._dropdownManagerService.showDropdown({location:{unitId:n,subUnitId:r,row:i,col:s,workbook:c,worksheet:h},trigger:"editor-bridge",closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(W.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:W.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,a)=>{var m,C,f,y,R;const{row:n,col:r,unitId:i,subUnitId:s,workbook:c,worksheet:l}=t,d=this._sheetDataValidationModel.getRuleIdByLocation(i,s,n,r);if(!d)return a(e);const h=this._sheetDataValidationModel.getRuleById(i,s,d);if(!h)return a(e);const g=(m=this._dataValidationCacheService.getValue(i,s,n,r))!=null?m:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=t.rawData;let v;const T={get value(){var D;return v!==void 0||(v=(D=_.getCellValueOrigin(S))!=null?D:null),v}},M={get value(){var D;return`${(D=T.value)!=null?D:""}`}};return a({...e,markers:{...e==null?void 0:e.markers,...g===o.DataValidationStatus.INVALID?Tt: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:((f=e==null?void 0:e.fontRenderExtension)==null?void 0:f.isSkip)||((y=u==null?void 0:u.skipDefaultFontRender)==null?void 0:y.call(u,h,T.value,t))},interceptorStyle:{...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,M.value,{get style(){const D=c.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,r)},interceptorAutoHeight:()=>{var H,P,U,k,F,A;const D=(P=(H=this._renderManagerService.getRenderById(i))==null?void 0:H.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!D)return;const V=D.worksheet.getMergedCell(n,r),x={data:e,style:D.getStyles().getStyleByCell(e),primaryWithCoord:D.getCellWithCoordByIndex((U=V==null?void 0:V.startRow)!=null?U:n,(k=V==null?void 0:V.startColumn)!=null?k:r),unitId:i,subUnitId:s,row:n,col:r,workbook:c,worksheet:l};return(A=(F=u==null?void 0:u.canvasRender)==null?void 0:F.calcCellAutoHeight)==null?void 0:A.call(F,x)},interceptorAutoWidth:()=>{var H,P,U,k,F,A;const D=(P=(H=this._renderManagerService.getRenderById(i))==null?void 0:H.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!D)return;const V=D.worksheet.getMergedCell(n,r),x={data:e,style:D.getStyles().getStyleByCell(e),primaryWithCoord:D.getCellWithCoordByIndex((U=V==null?void 0:V.startRow)!=null?U:n,(k=V==null?void 0:V.startColumn)!=null?k:r),unitId:i,subUnitId:s,row:n,col:r,workbook:c,worksheet:l};return(A=(F=u==null?void 0:u.canvasRender)==null?void 0:F.calcCellAutoWidth)==null?void 0:A.call(F,x)},coverable:((R=e==null?void 0:e.coverable)!=null?R:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE)})}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(ae.filter(e=>e.source==="command"),ae.bufferTime(100)).subscribe(e=>{if(e.length===0)return;const t=[];if(e.forEach(a=>{var n;(a.rule.type===o.DataValidationType.LIST_MULTIPLE||a.rule.type===o.DataValidationType.LIST)&&(n=a.rule)!=null&&n.ranges&&t.push(...a.rule.ranges)}),t.length){const a=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(a.redos,this._commandService)}})}};be=bt([Z(0,o.ICommandService),Z(1,w.IMenuManagerService),Z(2,L.IRenderManagerService),Z(3,o.IUniverInstanceService),Z(4,o.Inject(B.AutoHeightController)),Z(5,o.Inject(fe)),Z(6,o.Inject(_.SheetDataValidationModel)),Z(7,o.Inject($.DataValidatorRegistryService)),Z(8,o.Inject(W.SheetInterceptorService)),Z(9,o.Inject(_.DataValidationCacheService)),Z(10,o.Optional(B.IEditorBridgeService))],be);let mt=class extends o.RxDisposable{constructor(e,t,a,n,r,i,s){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=a,this._dataValidatorRegistryService=n,this._sheetInterceptorService=r,this._sheetDataValidationModel=i,this._dataValidationCacheService=s,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(W.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:W.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,a)=>{var M,m,C,f,y;const{row:n,col:r,unitId:i,subUnitId:s,workbook:c,worksheet:l}=t,d=this._sheetDataValidationModel.getRuleIdByLocation(i,s,n,r);if(!d)return a(e);const h=this._sheetDataValidationModel.getRuleById(i,s,d);if(!h)return a(e);const g=(M=this._dataValidationCacheService.getValue(i,s,n,r))!=null?M:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=l.getCellRaw(n,r),v=_.getCellValueOrigin(S),T=`${v!=null?v:""}`;return a({...e,markers:{...e==null?void 0:e.markers,...g===o.DataValidationStatus.INVALID?Tt: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)||((f=u==null?void 0:u.skipDefaultFontRender)==null?void 0:f.call(u,h,v,t))},interceptorStyle:{...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,T,{get style(){const R=c.getStyles();return(typeof(e==null?void 0:e.s)=="string"?R.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},n,r)},interceptorAutoHeight:()=>{var x,H,P,U,k,F;const R=(H=(x=this._renderManagerService.getRenderById(i))==null?void 0:x.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:H.skeleton;if(!R)return;const D=R.worksheet.getMergedCell(n,r),V={data:e,style:R.getStyles().getStyleByCell(e),primaryWithCoord:R.getCellWithCoordByIndex((P=D==null?void 0:D.startRow)!=null?P:n,(U=D==null?void 0:D.startColumn)!=null?U:r),unitId:i,subUnitId:s,row:n,col:r,workbook:c,worksheet:l};return(F=(k=u==null?void 0:u.canvasRender)==null?void 0:k.calcCellAutoHeight)==null?void 0:F.call(k,V)},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(ae.filter(e=>e.source==="command"),ae.bufferTime(16)).subscribe(e=>{const t=[];if(e.forEach(a=>{var n;(n=a.rule)!=null&&n.ranges&&t.push(...a.rule.ranges)}),t.length){const a=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(a.redos,this._commandService)}})}};mt=bt([Z(0,o.ICommandService),Z(1,L.IRenderManagerService),Z(2,o.Inject(B.AutoHeightController)),Z(3,o.Inject($.DataValidatorRegistryService)),Z(4,o.Inject(W.SheetInterceptorService)),Z(5,o.Inject(_.SheetDataValidationModel)),Z(6,o.Inject(_.DataValidationCacheService))],mt);var Vn=Object.getOwnPropertyDescriptor,wn=(e,t,a,n)=>{for(var r=n>1?void 0:n?Vn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},ft=(e,t)=>(a,n)=>t(a,n,e);let Be=class extends o.Disposable{constructor(e,t,a){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=a,this._initSkeletonChange()}_initSkeletonChange(){const e=t=>{var n;if(!t.length)return;const a=new Set;t.forEach(r=>{a.add(r.subUnitId)}),a.forEach(r=>{var i;(i=this._sheetSkeletonManagerService.getSkeletonParam(r))==null||i.skeleton.makeDirty(!0)}),(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(o.bufferDebounceTime(16)).subscribe(e))}};Be=wn([ft(1,o.Inject(_.SheetDataValidationModel)),ft(2,o.Inject(B.SheetSkeletonManagerService))],Be);function En(e){var d;const t=w.useDependency(o.LocaleService),a=w.useDependency(w.ComponentManager),{value:n,onChange:r,extraComponent:i}=e,[s,c]=b.useState(!1),l=i?a.get(i):null;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white",onClick:()=>c(!s),children:[t.t("dataValidation.panel.options"),s?p.jsx(Dt,{className:"univer-ml-1"}):p.jsx(dt,{className:"univer-ml-1"})]}),s&&p.jsxs(p.Fragment,{children:[l?p.jsx(l,{value:n,onChange:r}):null,p.jsx(E.FormLayout,{label:t.t("dataValidation.panel.invalid"),children:p.jsxs(E.RadioGroup,{value:`${(d=n.errorStyle)!=null?d:o.DataValidationErrorStyle.WARNING}`,onChange:h=>r({...n,errorStyle:+h}),children:[p.jsx(E.Radio,{value:`${o.DataValidationErrorStyle.WARNING}`,children:t.t("dataValidation.panel.showWarning")}),p.jsx(E.Radio,{value:`${o.DataValidationErrorStyle.STOP}`,children:t.t("dataValidation.panel.rejectInput")})]})}),p.jsx(E.FormLayout,{label:t.t("dataValidation.panel.messageInfo"),children:p.jsx(E.Checkbox,{checked:n.showErrorMessage,onChange:()=>r({...n,showErrorMessage:!n.showErrorMessage}),children:t.t("dataValidation.panel.showInfo")})}),n.showErrorMessage?p.jsx(E.FormLayout,{children:p.jsx(E.Input,{value:n.error,onChange:h=>r({...n,error:h})})}):null]})]})}const Mn=e=>o.debounce(async(t,a,n,r)=>{const i=await e.executeCommand(t,a,n);r==null||r(i)},1e3);function bn(e,t,a){var n,r,i,s;return t?((r=(n=e.getUnit(t))==null?void 0:n.getSheetBySheetName(a))==null?void 0:r.getSheetId())||"":((s=(i=e.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetName(a))==null?void 0:s.getSheetId())||""}function Tn(){var j,K;const[e,t]=b.useState(0),a=w.useDependency(ue),n=w.useObservable(a.activeRule$,a.activeRule),{unitId:r,subUnitId:i,rule:s}=n||{},c=s.uid,l=w.useDependency($.DataValidatorRegistryService),d=w.useDependency(o.IUniverInstanceService),h=w.useDependency(w.ComponentManager),g=w.useDependency(o.ICommandService),u=w.useDependency($.DataValidationModel),S=w.useDependency(o.LocaleService),[v,T]=b.useState(s),M=l.getValidatorItem(v.type),[m,C]=b.useState(!1),f=l.getValidatorsByScope($.DataValidatorRegistryScope.SHEET),[y,R]=b.useState(()=>v.ranges.map(I=>({unitId:"",sheetId:"",range:I}))),D=b.useMemo(()=>Mn(g),[g]),[V,x]=b.useState(!1),[H,P]=b.useState(!1),U=b.useRef(null),k=w.useDependency(W.SheetsSelectionsService);if(b.useEffect(()=>()=>{const I=k.getCurrentLastSelection();I&&k.setSelections([I])},[k]),b.useEffect(()=>{g.onCommandExecuted(I=>{(I.id===o.UndoCommand.id||I.id===o.RedoCommand.id)&&setTimeout(()=>{const N=u.getRuleById(r,i,c);t(z=>z+1),N&&(T(N),R(N.ranges.map(z=>({unitId:"",sheetId:"",range:z}))))},20)})},[g,u,c,i,r]),!M)return null;const F=M.operators,A=M.operatorNames,Y=v.operator?$.TWO_FORMULA_OPERATOR_COUNT.includes(v.operator):!1,X=()=>{var I,N,z;(N=(I=U.current)==null?void 0:I.editor)!=null&&N.isFocus()&&G((z=U.current)==null?void 0:z.getValue()),!(!v.ranges.length||V)&&(M.validatorFormula(v,r,i).success?a.setActiveRule(null):C(!0))},G=w.useEvent(I=>{const N=I.split(",").filter(Boolean).map(at.deserializeRangeWithSheet).map(Q=>{const gt=Q.sheetName;if(gt){const Lt=bn(d,Q.unitId,gt);return{...Q,sheetId:Lt}}return{...Q,sheetId:""}});if(o.isUnitRangesEqual(N,y))return;R(N);const z=N.filter(Q=>(!Q.unitId||Q.unitId===r)&&(!Q.sheetId||Q.sheetId===i)).map(Q=>Q.range);if(T({...v,ranges:z}),z.length===0)return;const ge={unitId:r,subUnitId:i,ruleId:c,ranges:z};D(_.UpdateSheetDataValidationRangeCommand.id,ge)}),J=I=>{if(o.shallowEqual(I,$.getRuleSetting(v)))return;T({...v,...I});const N={unitId:r,subUnitId:i,ruleId:c,setting:I};D(_.UpdateSheetDataValidationSettingCommand.id,N,void 0)},q=async()=>{await g.executeCommand(_.RemoveSheetDataValidationCommand.id,{ruleId:c,unitId:r,subUnitId:i}),a.setActiveRule(null)},ee={type:v.type,operator:v.operator,formula1:v.formula1,formula2:v.formula2,allowBlank:v.allowBlank},le=I=>{const N=l.getValidatorItem(I);if(!N)return;const z=N.operators,ge=u.getRuleById(r,i,c),Q=I===(ge==null?void 0:ge.type)||I.includes("list")&&(ge!=null&&ge.type.includes("list"))?{...ge,type:I}:{...v,type:I,operator:z[0],formula1:void 0,formula2:void 0};T(Q),g.executeCommand(_.UpdateSheetDataValidationSettingCommand.id,{unitId:r,subUnitId:i,ruleId:v.uid,setting:$.getRuleSetting(Q)})},re=h.get(M.formulaInput),te=b.useMemo(()=>y.map(I=>at.serializeRange(I.range)).join(","),[]),ie=$.getRuleOptions(v),he=I=>{o.shallowEqual(I,$.getRuleOptions(v))||(T({...v,...I}),D(_.UpdateSheetDataValidationOptionsCommand.id,{unitId:r,subUnitId:i,ruleId:c,options:I}))},ce=F.length&&!v.operator;return p.jsxs("div",{"data-u-comp":"data-validation-detail",children:[p.jsx(E.FormLayout,{label:S.t("dataValidation.panel.range"),error:!v.ranges.length||V?S.t("dataValidation.panel.rangeError"):"",children:p.jsx(lt.RangeSelector,{selectorRef:U,unitId:r,subUnitId:i,initialValue:te,onChange:(I,N)=>{var z;!H&&((z=U.current)!=null&&z.verify())&&G(N)},onFocusChange:(I,N)=>{var z;P(I),!I&&N&&((z=U.current)!=null&&z.verify())&&G(N)},onVerify:I=>x(!I)})}),p.jsx(E.FormLayout,{label:S.t("dataValidation.panel.type"),children:p.jsx(E.Select,{className:"univer-w-full",value:v.type,options:(j=f==null?void 0:f.sort((I,N)=>I.order-N.order))==null?void 0:j.map(I=>({label:S.t(I.title),value:I.id})),onChange:le})}),F!=null&&F.length?p.jsx(E.FormLayout,{label:S.t("dataValidation.panel.operator"),children:p.jsx(E.Select,{className:"univer-w-full",value:`${v.operator}`,options:[{value:"",label:S.t("dataValidation.operators.legal")},...F.map((I,N)=>({value:`${I}`,label:A[N]}))],onChange:I=>{J({...ee,operator:I})}})}):null,re&&!ce?p.jsx(re,{isTwoFormula:Y,value:{formula1:v.formula1,formula2:v.formula2},onChange:I=>{J({...ee,...I})},showError:m,validResult:M.validatorFormula(v,r,i),unitId:r,subUnitId:i,ruleId:c},e+v.type):null,p.jsx(E.FormLayout,{children:p.jsx(E.Checkbox,{checked:(K=v.allowBlank)!=null?K:!0,onChange:()=>{var I;return J({...ee,allowBlank:!((I=v.allowBlank)==null||I)})},children:S.t("dataValidation.panel.allowBlank")})}),p.jsx(En,{value:ie,onChange:he,extraComponent:M.optionsInput}),p.jsxs("div",{className:"univer-mt-5 univer-flex univer-flex-row univer-justify-end",children:[p.jsx(E.Button,{className:"univer-ml-3",onClick:q,children:S.t("dataValidation.panel.removeRule")}),p.jsx(E.Button,{className:"univer-ml-3",variant:"primary",onClick:X,children:S.t("dataValidation.panel.done")})]})]})}const On=e=>{const{rule:t,onClick:a,unitId:n,subUnitId:r,disable:i}=e,s=w.useDependency($.DataValidatorRegistryService),c=w.useDependency(o.ICommandService),l=w.useDependency(B.IMarkSelectionService),d=s.getValidatorItem(t.type),h=b.useRef(void 0),[g,u]=b.useState(!1),S=w.useDependency(o.ThemeService),v=w.useObservable(S.currentTheme$),T=b.useMemo(()=>{var R;const m=S.getColorFromTheme("primary.600"),C=S.getColorFromTheme("loop-color.2"),f=(R=S.getColorFromTheme(C))!=null?R:m,y=new o.ColorKit(f).toRgb();return{fill:`rgba(${y.r}, ${y.g}, ${y.b}, 0.1)`,stroke:f}},[v]),M=m=>{c.executeCommand(_.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:n,subUnitId:r}),m.stopPropagation()};return b.useEffect(()=>()=>{var m;h.current&&((m=h.current)==null||m.forEach(C=>{C&&l.removeShape(C)}))},[l]),p.jsxs("div",{className:E.clsx(`
2
2
  univer-rounded-md univer-bg-secondary univer-relative univer--ml-2 univer--mr-2 univer-box-border
3
3
  univer-flex univer-w-[287px] univer-cursor-pointer univer-flex-col univer-justify-between
4
4
  univer-overflow-hidden univer-p-2 univer-pr-9
package/lib/es/index.js CHANGED
@@ -491,7 +491,7 @@ function Qi(e) {
491
491
  /* @__PURE__ */ W(
492
492
  "a",
493
493
  {
494
- 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",
494
+ 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",
495
495
  onClick: de,
496
496
  children: [
497
497
  /* @__PURE__ */ _(Ir, { className: "univer-mr-1" }),
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-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}.\[\&\>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 }
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-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
@@ -491,7 +491,7 @@ function Qi(e) {
491
491
  /* @__PURE__ */ W(
492
492
  "a",
493
493
  {
494
- 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",
494
+ 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",
495
495
  onClick: de,
496
496
  children: [
497
497
  /* @__PURE__ */ _(Ir, { className: "univer-mr-1" }),
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (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,k,$,kt,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 Nt(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 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=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(xt()));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 xt(){return Math.random().toString(36).substring(2,8)}ge.displayName="UniverIcon";var Wt={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:Wt}))});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,N]=V.useState([]),[W,P]=V.useState(""),F=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);N(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,x)=>({label:I,color:G[x]||Ce,isRef:!1,id:o.Tools.generateRandomId(4)}))}),Z=(U,G,I)=>{const x=X.find(K=>K.id===U);x&&(x.label=G,x.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 x=[...y];x[+U]=I,D(x),A({formula1:l,formula2:x.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:x})=>{x.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:F||W||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:F,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,Ft],[f.BASE_FORMULA_INPUT_NAME,Ut],[f.LIST_FORMULA_INPUT_NAME,Zt],[f.CHECKBOX_FORMULA_INPUT_NAME,Nt]];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===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)}};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=kt.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"),N=(j=o.numfmt.parseDate(E))==null?void 0:j.v,W=y==="time"?N%1:N,P=d.getStyles().getStyleByCell(w),F=(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:W,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:k.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:W,t:2,p:null,f:null,si:null,s:{n:{pattern:dn(y,F)}}}}),!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 F=f.serializeListOptions(P),j={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:n,endRow:n},value:{v:F,p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(H.SetCellEditVisibleOperation.id,{visible:!1,eventType:k.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)),N=()=>{this._commandService.executeCommand(me.id,{ruleId:c.uid}),p==null||p.dispose()},W=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:W,onEdit:N,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:k.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:k.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 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(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:ke,header:{title:n?"dataValidation.panel.addTitle":"dataValidation.panel.title"},children:{label:ke},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}},Ne={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,N=w.relativeRange,W={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(N,(F,j)=>{const B=o.Rectangle.getPositionRange({startRow:F,startColumn:j,endColumn:j,endRow:F},W),{row:A,col:X}=_(B.startRow,B.startColumn),z=this._sheetDataValidationModel.getRuleIdByLocation(d,l,A,X)||"",Z=o.Rectangle.getPositionRange({startRow:F,startColumn:j,endColumn:j,endRow:F},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}`,N=this._sheetDataValidationModel.getRuleById(a,i,D);!this._sheetDataValidationModel.getRuleById(r.unitId,r.subUnitId,E)&&N&&_.set(E,{...N,uid:E});const{row:W,col:P}=p(w.startRow,w.startColumn);l.add(E),d.setValue(W,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:Ne.id,title:"dataValidation.panel.add",type:b.MenuItemType.BUTTON}}const Cn={[b.RibbonDataGroup.RULES]:{[Dt]:{order:0,menuItemFactory:Sn,[me.id]:{order:0,menuItemFactory:_n},[Ne.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 W,P,F,j,B,A;const w=(P=(W=this._renderManagerService.getRenderById(i))==null?void 0:W.with(H.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!w)return;const E=w.worksheet.getMergedCell(n,a),N={data:e,style:w.getStyles().getStyleByCell(e),primaryWithCoord:w.getCellWithCoordByIndex((F=E==null?void 0:E.startRow)!=null?F: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,N)},interceptorAutoWidth:()=>{var W,P,F,j,B,A;const w=(P=(W=this._renderManagerService.getRenderById(i))==null?void 0:W.with(H.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!w)return;const E=w.worksheet.getMergedCell(n,a),N={data:e,style:w.getStyles().getStyleByCell(e),primaryWithCoord:w.getCellWithCoordByIndex((F=E==null?void 0:E.startRow)!=null?F: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,N)},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,k.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 N,W,P,F,j,B;const D=(W=(N=this._renderManagerService.getRenderById(i))==null?void 0:N.with(H.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:W.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,(F=w==null?void 0:w.startColumn)!=null?F: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,k.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 Fe=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))}};Fe=Dn([Tt(1,o.Inject(f.SheetDataValidationModel)),Tt(2,o.Inject(H.SheetSkeletonManagerService))],Fe);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,N]=V.useState(!1),[W,P]=V.useState(!1),F=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 x=u.getRuleById(a,i,d);t(K=>K+1),x&&(O(x),D(x.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,x,K;(x=(I=F.current)==null?void 0:I.editor)!=null&&x.isFocus()&&Z((K=F.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 x=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(x,y))return;D(x);const K=x.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 x={unitId:a,subUnitId:i,ruleId:d,setting:I};w(f.UpdateSheetDataValidationSettingCommand.id,x,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 x=l.getValidatorItem(I);if(!x)return;const K=x.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",{"data-u-comp":"data-validation-detail",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:F,unitId:a,subUnitId:i,initialValue:ae,onChange:(I,x)=>{var K;!W&&((K=F.current)!=null&&K.verify())&&Z(x)},onFocusChange:(I,x)=>{var K;P(I),!I&&x&&((K=F.current)!=null&&K.verify())&&Z(x)},onVerify:I=>N(!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,x)=>I.order-x.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,x)=>({value:`${I}`,label:A[x]}))],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(`
1
+ (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,k,$,kt,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 Nt(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 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=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(xt()));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 xt(){return Math.random().toString(36).substring(2,8)}ge.displayName="UniverIcon";var Wt={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:Wt}))});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,N]=V.useState([]),[W,P]=V.useState(""),F=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);N(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,x)=>({label:I,color:G[x]||Ce,isRef:!1,id:o.Tools.generateRandomId(4)}))}),Z=(U,G,I)=>{const x=X.find(K=>K.id===U);x&&(x.label=G,x.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 x=[...y];x[+U]=I,D(x),A({formula1:l,formula2:x.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:x})=>{x.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:F||W||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:F,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 dark:hover:!univer-bg-gray-800 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,Ft],[f.BASE_FORMULA_INPUT_NAME,Ut],[f.LIST_FORMULA_INPUT_NAME,Zt],[f.CHECKBOX_FORMULA_INPUT_NAME,Nt]];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===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)}};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=kt.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"),N=(j=o.numfmt.parseDate(E))==null?void 0:j.v,W=y==="time"?N%1:N,P=d.getStyles().getStyleByCell(w),F=(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:W,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:k.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:W,t:2,p:null,f:null,si:null,s:{n:{pattern:dn(y,F)}}}}),!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 F=f.serializeListOptions(P),j={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:n,endRow:n},value:{v:F,p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(H.SetCellEditVisibleOperation.id,{visible:!1,eventType:k.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)),N=()=>{this._commandService.executeCommand(me.id,{ruleId:c.uid}),p==null||p.dispose()},W=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:W,onEdit:N,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:k.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:k.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 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(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:ke,header:{title:n?"dataValidation.panel.addTitle":"dataValidation.panel.title"},children:{label:ke},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}},Ne={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,N=w.relativeRange,W={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(N,(F,j)=>{const B=o.Rectangle.getPositionRange({startRow:F,startColumn:j,endColumn:j,endRow:F},W),{row:A,col:X}=_(B.startRow,B.startColumn),z=this._sheetDataValidationModel.getRuleIdByLocation(d,l,A,X)||"",Z=o.Rectangle.getPositionRange({startRow:F,startColumn:j,endColumn:j,endRow:F},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}`,N=this._sheetDataValidationModel.getRuleById(a,i,D);!this._sheetDataValidationModel.getRuleById(r.unitId,r.subUnitId,E)&&N&&_.set(E,{...N,uid:E});const{row:W,col:P}=p(w.startRow,w.startColumn);l.add(E),d.setValue(W,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:Ne.id,title:"dataValidation.panel.add",type:b.MenuItemType.BUTTON}}const Cn={[b.RibbonDataGroup.RULES]:{[Dt]:{order:0,menuItemFactory:Sn,[me.id]:{order:0,menuItemFactory:_n},[Ne.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 W,P,F,j,B,A;const w=(P=(W=this._renderManagerService.getRenderById(i))==null?void 0:W.with(H.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!w)return;const E=w.worksheet.getMergedCell(n,a),N={data:e,style:w.getStyles().getStyleByCell(e),primaryWithCoord:w.getCellWithCoordByIndex((F=E==null?void 0:E.startRow)!=null?F: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,N)},interceptorAutoWidth:()=>{var W,P,F,j,B,A;const w=(P=(W=this._renderManagerService.getRenderById(i))==null?void 0:W.with(H.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!w)return;const E=w.worksheet.getMergedCell(n,a),N={data:e,style:w.getStyles().getStyleByCell(e),primaryWithCoord:w.getCellWithCoordByIndex((F=E==null?void 0:E.startRow)!=null?F: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,N)},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,k.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 N,W,P,F,j,B;const D=(W=(N=this._renderManagerService.getRenderById(i))==null?void 0:N.with(H.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:W.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,(F=w==null?void 0:w.startColumn)!=null?F: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,k.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 Fe=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))}};Fe=Dn([Tt(1,o.Inject(f.SheetDataValidationModel)),Tt(2,o.Inject(H.SheetSkeletonManagerService))],Fe);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,N]=V.useState(!1),[W,P]=V.useState(!1),F=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 x=u.getRuleById(a,i,d);t(K=>K+1),x&&(O(x),D(x.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,x,K;(x=(I=F.current)==null?void 0:I.editor)!=null&&x.isFocus()&&Z((K=F.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 x=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(x,y))return;D(x);const K=x.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 x={unitId:a,subUnitId:i,ruleId:d,setting:I};w(f.UpdateSheetDataValidationSettingCommand.id,x,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 x=l.getValidatorItem(I);if(!x)return;const K=x.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",{"data-u-comp":"data-validation-detail",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:F,unitId:a,subUnitId:i,initialValue:ae,onChange:(I,x)=>{var K;!W&&((K=F.current)!=null&&K.verify())&&Z(x)},onFocusChange:(I,x)=>{var K;P(I),!I&&x&&((K=F.current)!=null&&K.verify())&&Z(x)},onVerify:I=>N(!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,x)=>I.order-x.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,x)=>({value:`${I}`,label:A[x]}))],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(`
2
2
  univer-rounded-md univer-bg-secondary univer-relative univer--ml-2 univer--mr-2 univer-box-border
3
3
  univer-flex univer-w-[287px] univer-cursor-pointer univer-flex-col univer-justify-between
4
4
  univer-overflow-hidden univer-p-2 univer-pr-9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-data-validation-ui",
3
- "version": "0.7.0-nightly.202505151607",
3
+ "version": "0.7.0-nightly.202505171606",
4
4
  "private": false,
5
5
  "description": "Data validation UI for Univer Sheets",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -56,17 +56,17 @@
56
56
  "dependencies": {
57
57
  "@flatten-js/interval-tree": "^1.1.3",
58
58
  "@univerjs/icons": "^0.3.24",
59
- "@univerjs/core": "0.7.0-nightly.202505151607",
60
- "@univerjs/design": "0.7.0-nightly.202505151607",
61
- "@univerjs/engine-formula": "0.7.0-nightly.202505151607",
62
- "@univerjs/data-validation": "0.7.0-nightly.202505151607",
63
- "@univerjs/sheets-data-validation": "0.7.0-nightly.202505151607",
64
- "@univerjs/engine-render": "0.7.0-nightly.202505151607",
65
- "@univerjs/sheets": "0.7.0-nightly.202505151607",
66
- "@univerjs/sheets-formula-ui": "0.7.0-nightly.202505151607",
67
- "@univerjs/sheets-numfmt": "0.7.0-nightly.202505151607",
68
- "@univerjs/ui": "0.7.0-nightly.202505151607",
69
- "@univerjs/sheets-ui": "0.7.0-nightly.202505151607"
59
+ "@univerjs/core": "0.7.0-nightly.202505171606",
60
+ "@univerjs/data-validation": "0.7.0-nightly.202505171606",
61
+ "@univerjs/design": "0.7.0-nightly.202505171606",
62
+ "@univerjs/engine-formula": "0.7.0-nightly.202505171606",
63
+ "@univerjs/engine-render": "0.7.0-nightly.202505171606",
64
+ "@univerjs/sheets": "0.7.0-nightly.202505171606",
65
+ "@univerjs/sheets-data-validation": "0.7.0-nightly.202505171606",
66
+ "@univerjs/sheets-formula-ui": "0.7.0-nightly.202505171606",
67
+ "@univerjs/sheets-numfmt": "0.7.0-nightly.202505171606",
68
+ "@univerjs/sheets-ui": "0.7.0-nightly.202505171606",
69
+ "@univerjs/ui": "0.7.0-nightly.202505171606"
70
70
  },
71
71
  "devDependencies": {
72
72
  "postcss": "^8.5.3",