@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
5 lines • 1.95 kB
JavaScript
/*!
* All material copyright ESRI, All Rights Reserved, unless otherwise specified.
* See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
*/
import{c as n}from"./p-8f3a3e4e.js";import{h as t}from"./p-6b7b23d0.js";function e(n){return"checked"in n}const o=new WeakMap,i=new WeakSet;function r(t){const{el:o,value:r}=t,u=n(o,"form");if(!u||function(n,t){const e="calciteInternalFormComponentRegister";let o=!1;return n.addEventListener(e,(n=>{o=n.composedPath().some((n=>i.has(n))),n.stopPropagation()}),{once:!0}),t.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0})),o}(u,o))return;t.formEl=u,t.defaultValue=r,e(t)&&(t.defaultChecked=t.checked);const c=(t.onFormReset||s).bind(t);u.addEventListener("reset",c),i.add(o)}function s(){e(this)?this.checked=this.defaultChecked:this.value=this.defaultValue}function u(n){const{el:t,formEl:e}=n;if(!e)return;const r=o.get(t);e.removeEventListener("reset",r),o.delete(t),n.formEl=null,i.delete(t)}function c(n,t){n.defaultValue=t}function l(n,t,o){var i;const{defaultValue:r,disabled:s,name:u,required:c}=n;t.defaultValue=r,t.disabled=s,t.name=u,t.required=c,t.tabIndex=-1,e(n)?(t.defaultChecked=n.defaultChecked,t.value=n.checked?o||"on":"",s||n.checked||(t.disabled=!0)):t.value=o||"",null===(i=n.syncHiddenFormInput)||void 0===i||i.call(n,t)}const a=({component:n})=>(function(n){const{el:t,formEl:e,name:o,value:i}=n,{ownerDocument:r}=t,s=t.querySelectorAll('input[slot="hidden-form-input"]');if(!e||!o)return void s.forEach((n=>n.remove()));const u=Array.isArray(i)?i:[i],c=[],a=new Set;let f;s.forEach((t=>{const e=u.find((n=>n==t.value));null!=e?(a.add(e),l(n,t,e)):c.push(t)})),u.forEach((t=>{if(a.has(t))return;let e=c.pop();e||(e=r.createElement("input"),e.slot="hidden-form-input"),f||(f=r.createDocumentFragment()),f.append(e),l(n,e,t)})),f&&t.append(f),c.forEach((n=>n.remove()))}(n),t("slot",{name:"hidden-form-input"}));export{a as H,c as a,r as c,u as d}