1class m{constructor(){const a=document.querySelectorAll(".js-matrix-add");Array.from(a).forEach((e,r)=>{e.addEventListener("click",this.addRow.bind(this))}),document.addEventListener("click",e=>{for(let r=e.target;r&&!r.isSameNode(document);r=r.parentElement)if(r.matches(".js-remove-row")){e.preventDefault();const t=r.closest(".js-row"),s=t.parentElement;s.removeChild(t),this.triggerChange(s.querySelectorAll(".js-row").length,t.getAttribute("data-s-type"));const n=document.querySelector(`.js-matrix-add[data-s-type=${t.getAttribute("data-s-type")}]`);n.disabled=!1;break}},!1)}addRow(a){a.preventDefault();const e=a.target,r=document.querySelectorAll("."+e.getAttribute("data-s-type")),t=r.length;let s=1;const n=e.getAttribute("data-add-index");n&&(s=parseInt(n),s++,e.setAttribute("data-add-index",`${s}`));const l=Array.from(r).pop();if(l){const i=e.getAttribute("data-s-template"),d=this.getTemplate(i).replace(new RegExp("%%block%%","g"),"new_"+s);l.parentElement.insertAdjacentHTML("beforeend",d),this.triggerChange(t,e.getAttribute("data-s-type"))}const o=e.getAttribute("data-s-max");if(o){const i=parseInt(o);t+1>=i&&(e.disabled=!0)}}getTemplate(a){const e=document.querySelector("#"+a);return e?e.innerHTML:""}triggerChange(a,e){console.log(a);let r;typeof CustomEvent=="function"?r=new CustomEvent("matrix-changed",{detail:{amount:a,type:e}}):(r=document.createEvent("Event"),r.initEvent("matrix-changed",!1,!0,{detail:{amount:a,type:e}})),document.dispatchEvent(r);const t=document.querySelectorAll(`.js-matrix-optional[data-s-type='${e}']`);console.log(e,t),Array.from(t).forEach(s=>{a>0?(s.classList.remove("hidden"),this.disableAllFormElements(!1,s)):(s.classList.add("hidden"),this.disableAllFormElements(!0,s))})}disableAllFormElements(a=!0,e){const r=e.querySelectorAll("input, textarea, select");Array.from(r).forEach(t=>{a?(t.hasAttribute("required")&&(t.removeAttribute("required"),t.setAttribute("data-has-required","true")),t.setAttribute("disabled","disabled")):(t.hasAttribute("data-has-required")&&(t.setAttribute("required","required"),t.removeAttribute("data-has-required")),t.removeAttribute("disabled"))})}}export{m as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.