Jacks_Bastards_Website/static/wagtailadmin/js/telepath/widgets.js

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.ValidationError",class{constructor(e){this.messages=e}})}},r={};function i(e){var n=r[e];if(void 0!==n)return n.exports;var s=r[e]={exports:{}};return t[e](s,s.exports,i),s.exports}i.m=t,e=[],i.O=(t,r,n,s)=>{if(!r){var o=1/0;for(c=0;c<e.length;c++){for(var[r,n,s]=e[c],a=!0,l=0;l<r.length;l++)(!1&s||o>=s)&&Object.keys(i.O).every(e=>i.O[e](r[l]))?r.splice(l--,1):(a=!1,s<o&&(o=s));if(a){e.splice(c--,1);var u=n();void 0!==u&&(t=u)}}return t}s=s||0;for(var c=e.length;c>0&&e[c-1][2]>s;c--)e[c]=e[c-1];e[c]=[r,n,s]},i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.j=136,(()=>{var e={136:0};i.O.j=t=>0===e[t];var t=(t,r)=>{var n,s,[o,a,l]=r,u=0;if(o.some(t=>0!==e[t])){for(n in a)i.o(a,n)&&(i.m[n]=a[n]);if(l)var c=l(i)}for(t&&t(r);u<o.length;u++)s=o[u],i.o(e,s)&&e[s]&&e[s][0](),e[s]=0;return i.O(c)},r=globalThis.webpackChunkwagtail=globalThis.webpackChunkwagtail||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var n=i.O(void 0,[321],()=>i(3892));n=i.O(n)})();