1 line
5.5 KiB
JavaScript
1 line
5.5 KiB
JavaScript
|
|
(()=>{"use strict";var e,t={3892:(e,t,r)=>{var i=r(1002),n=r(2833),s=r(6032);const o=(e,t)=>{const r=e.forEach?e:[e];for(let e=0;e<r.length;e+=1){const i=r[e];if(i.nodeType===Node.ELEMENT_NODE){if(i.matches(t))return i;const e=i.querySelector(t);if(e)return e}}return null};class a extends Error{constructor(e){super(`No input found with name "${e}"`),this.name="InputNotFoundError"}}class l{constructor(e,t,r){const i=`:is(input,select,textarea,button)[name="${t}"]`;if(this.input=o(e,i),!this.input)throw new a(t);this.idForLabel=this.input.id,this.parentCapabilities=r||new Map}getValue(){return this.input.value}getState(){return this.input.value}setState(e){this.input.value=e}setInvalid(e){e?this.input.setAttribute("aria-invalid","true"):this.input.removeAttribute("aria-invalid")}getValueForLabel(){return this.getValue()}getTextLabel(e){const t=this.getValueForLabel();if(!["string","number","boolean"].includes(typeof t))return null;const r=String(t).trim(),i=e&&e.maxLength;return i&&r.length>i?r.substring(0,i-1)+"…":r}focus(){this.input.focus()}setCapabilityOptions(e,t){Object.assign(this.parentCapabilities.get(e),t)}}class u{constructor(e){this.html=e}boundWidgetClass=l;render(e,t,r,n,o,a={}){const l=this.html.replace(/__NAME__/g,t).replace(/__ID__/g,r),u=document.createElement("div");u.innerHTML=l.trim();const c=Array.from(u.childNodes);e.replaceWith(...c);const h=c.filter(e=>e.nodeType===Node.ELEMENT_NODE);h.forEach(e=>{(0,s.v)(e)}),"object"==typeof a?.attributes&&(0,i.$)(h[0],a.attributes);const d=new this.boundWidgetClass(1===h.length?h[0]:c,t,o);return d.setState(n),d}getByName(e,t){return new this.boundWidgetClass(t,e)}}class c extends l{getValue(){return this.input.checked}getState(){return this.input.checked}setState(e){this.input.checked=e}getValueForLabel(){return this.getValue()?(0,n.AP)("Yes"):(0,n.AP)("No")}}class h{constructor(e,t){this.element=e,this.name=t,this.idForLabel="",this.isMultiple=!!this.element.querySelector(`input[name="${t}"][type="checkbox"]`),this.selector=`input[name="${t}"]:checked`}getValueForLabel(){const e=e=>Array.from(e?.labels||[]).map(e=>e.textContent.trim()).filter(Boolean).join(", ");return this.isMultiple?Array.from(this.element.querySelectorAll(this.selector)).map(e).join(", "):e(this.element.querySelector(this.selector))}getTextLabel(){return this.getValueForLabel()}getValue(){return this.isMultiple?Array.from(this.element.querySelectorAll(this.selector)).map(e=>e.value):this.element.querySelector(this.selector)?.value}getState(){return Array.from(this.element.querySelectorAll(this.selector)).map(e=>e.value)}setState(e){const t=this.element.querySelectorAll(`input[name="${this.name}"]`);for(let r=0;r<t.length;r+=1)t[r].checked=e.includes(t[r].value)}setInvalid(e){this.element.querySelectorAll(`input[name="${this.name}"]`).forEach(t=>{e?t.setAttribute("aria-invalid","true"):t.removeAttribute("aria-invalid")})}focus(){this.element.querySelector(`input[name="${this.name}"]`)?.focus()}}class d extends l{getValueForLabel(){return Array.from(this.input.selectedOptions).map(e=>e.text).join(", ")}getValue(){return this.input.multiple?Array.from(this.input.selectedOptions).map(e=>e.value):this.input.value}getState(){return Array.from(this.input.selectedOptions).map(e=>e.value)}setState(e){const t=this.input.options;for(let r=0;r<t.length;r+=1)t[r].selected=e.includes(t[r].value)}}window.telepath.register("wagtail.widgets.Widget",u),window.telepath.register("wagtail.widgets.CheckboxInput",class extends u{boundWidgetClass=c}),window.telepath.register("wagtail.widgets.RadioSelect",class extends u{boundWidgetClass=h}),window.telepath.register("wagtail.widgets.Select",class extends u{boundWidgetClass=d}),window.telepath.register("wagtail.widgets.BlockWidget",class extends u{constructor(){super("")}render(){throw new Error("BlockWidget does not support rendering")}getByName(e,t){const r=o(t,`#${e}-root`);if(!r)throw new a(e);if(!r.rootBlock)throw new Error(`BlockWidget with name "${e}" does not have a root block attached.`);return r.rootBlock}}),window.telepath.register("wagtail.errors.Vali
|