1function neutralizeButtonInteractions(t){t?.querySelectorAll&&t.querySelectorAll("a[href]").forEach(t=>{t.setAttribute("role","presentation"),t.setAttribute("tabindex","-1"),t.setAttribute("aria-hidden","true")})}function createButtonEditButton(t){const e=document.createElement("div");return e.className="lexxy-floating-controls button-edit-control",e.dataset.buttonEditButton="",e.contentEditable="false",e.innerHTML=`\n <div class="lexxy-floating-controls__group">\n <button type="button" class="button-edit-button" aria-label="${escapeAttribute(t)}" title="${escapeAttribute(t)}" tabindex="-1">\n <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 18 18" aria-hidden="true" focusable="false">\n <g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" stroke="currentColor">\n <path d="M8.25 3.25H3.75C2.645 3.25 1.75 4.145 1.75 5.25V14.25C1.75 15.355 2.645 16.25 3.75 16.25H12.75C13.855 16.25 14.75 15.355 14.75 14.25V9.75"></path>\n <path d="M13.875 1.875C14.496 1.254 15.504 1.254 16.125 1.875C16.746 2.496 16.746 3.504 16.125 4.125L8.75 11.5L5.75 12.25L6.5 9.25L13.875 1.875Z"></path>\n </g>\n </svg>\n </button>\n </div>\n `,e}async function createButtonAttachment({name:t,url:e,style:n}){const s=new FormData;s.append("name",t),s.append("url",e),s.append("style",n);const i=await fetch("/action_text/embeds?embed_type=button&editor=lexxy",{method:"POST",credentials:"same-origin",headers:{Accept:"application/json","X-CSRF-Token":document.querySelector('meta[name="csrf-token"]')?.content||"","X-Requested-With":"XMLHttpRequest"},body:s});if(!i.ok)throw new Error(`Could not create button attachment (${i.status})`);const o=await i.json();if(!o.content||!o.sgid)throw new Error("Button attachment response is incomplete");return o}function normalizeButtonStyle(t){return BUTTON_STYLES.includes(t)?t:"primary"}function normalizeButtonType(t){return BUTTON_TYPES.includes(t)?t:"url"}import{$isCustomActionTextAttachmentNode,CustomActionTextAttachmentNode,Extension,Lexical}from"@37signals/lexxy";import{LEXXY_CHOICE_CARD,LEXXY_ERROR,LEXXY_FIELD,LEXXY_FIELDS,LEXXY_FIELDSET,LEXXY_FIELD_CONTROL,LEXXY_FIELD_LABEL,LEXXY_HINT,LEXXY_PRIMARY_BTN,LEXXY_SECONDARY_BTN,createSiteModal,escapeAttribute,escapeHtml}from"src/lexxy/site_modal";const{$getNodeByKey:$getNodeByKey,$getSelection:$getSelection,$setSelection:$setSelection}=Lexical,CONFIG_TEMPLATE_ID="lexxy-button-config",BUTTON_CONTENT_TYPE="application/vnd.actiontext.button",OPEN_BUTTON_BLOCK_EVENT="lexxy:open-button-block",BUTTON_STYLES=["primary","secondary"],BUTTON_TYPES=["url","message","testimonial"],DEFAULT_TESTIMONIAL_SOURCE="button",buttonDialogOpeners=new WeakMap,TYPE_ICONS={url:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" aria-hidden="true"><g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" stroke="currentColor"><path d="M8.36909 6.8934C8.06649 7.0539 7.78239 7.2617 7.52799 7.517L7.51799 7.527C6.13699 8.908 6.13699 11.146 7.51799 12.527L9.69299 14.702C11.074 16.083 13.3
112 16.083 14.693 14.702L14.703 14.692C16.084 13.311 16.084 11.073 14.703 9.692L13.9406 8.9296"></path><path d="M9.63289 11.1066C9.93549 10.9461 10.2196 10.7383 10.474 10.483L10.484 10.473C11.865 9.09199 11.865 6.85399 10.484 5.47299L8.30899 3.29799C6.92799 1.91699 4.68999 1.91699 3.30899 3.29799L3.29899 3.30799C1.91799 4.68899 1.91799 6.92699 3.29899 8.30799L4.06139 9.07039"></path></g></svg>',message:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" aria-hidden="true"><g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" stroke="currentColor"><path d="M9,1.75C4.996,1.75,1.75,4.996,1.75,9c0,1.319,.358,2.552,.973,3.617,.43,.806-.053,2.712-.973,3.633,1.25,.068,2.897-.497,3.633-.973,.489,.282,1.264,.656,2.279,.848,.433,.082,.881,.125,1.338,.125,4.004,0,7.25-3.246,7.25-7.25S13.004,1.75,9,1.75Z"></path></g></svg>',testimonial:'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" aria-hidden="true"><g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" stroke="currentColor"><polyline points="11.2726 3.7808 12.323 3.628 13.25 1.75 14.177 3.628 16.25 3.93 14.75 5.392 14.9444 6.5253"></polyline><polyline points="6.7275 3.7808 5.677 3.628 4.75 1.75 3.823 3.628 1.75 3.93 3.25 5.392 3.0556 6.5253"></polyline><polygon points="9 5.739 10.545 8.87 14 9.372 11.5 11.809 12.09 15.25 9 13.625 5.91 15.25 6.5 11.809 4 9.372 7.455 8.87 9 5.739"></polygon></g></svg>'};export function buttonsCreatable(){const t=document.getElementById(CONFIG_TEMPLATE_ID);if(!t)return!1;return"true"===(t.getAttribute("data-users-can-create")??t.dataset.usersCanCreate??t.getAttribute("data-enabled")??t.dataset.enabled)}export function buttonEnabledFor(){return buttonsCreatable()}export function buttonMessageEnabledFor(){return buttonsCreatable()&&buttonBlockConfig().admins.length>0}export function buttonTestimonialEnabledFor(){return buttonsCreatable()&&Boolean(buttonBlockConfig().testimonialBaseUrl)}export function requestButtonBlock(t,e={}){t&&buttonsCreatable()&&setTimeout(()=>{const n=buttonDialogOpeners.get(t);n?n(e):t.dispatchEvent(new CustomEvent(OPEN_BUTTON_BLOCK_EVENT,{detail:e}))},0)}export function buttonBlockConfig(){const t=document.getElementById(CONFIG_TEMPLATE_ID);let e={},n=[];try{e=JSON.parse(t?.dataset.copy||"{}")}catch(t){e={}}try{n=JSON.parse(t?.dataset.admins||"[]")}catch(t){n=[]}return{copy:{title:e.title||"Button",description:e.description||"Add a button that uses your school\u2019s colors.",closeLabel:e.close_label||"Close",nameLabel:e.name_label||"Label",namePlaceholder:e.name_placeholder||"Get started",typeLabel:e.type_label||"Type",typePlaceholder:e.type_placeholder||"Choose a type\u2026",typeUrl:e.type_url||"Custom URL",typeMessage:e.type_message||"Send a message to your team",typeTestimonial:e.type_testimonial||"Leave a testimonial",urlLabel:e.url_label||"URL",urlPlaceholder:e.url_placeholder||"https://\u2026",urlInvalid:e.url_invalid||"Enter a valid URL (http:// or https://).",adminLabel:e.admin_label||"Recipient",adminPlaceholder:e.admin_placeholder||"Choose an administrator\u2026",adminInvalid:e.admin_invalid||"Choose an administrator.",messageTitleLabel:e.message_title_label||"Default title",messageTitlePlaceholder:e.message_title_placeholder||"Optional conversation title",messageTitleHint:e.message_title_hint||"Prefills the conversation title when the member starts a new message.",sourceLabel:e.source_label||"Tracking source",sourcePlaceholder:e.source_placeholder||DEFAULT_TESTIMONIAL_SOURCE,sourceHint:e.source_hint||"Use a short label such as button, email, or coaching-call. Defaults to button.",searchPlaceholder:e.search_placeholder||"Search\u2026",noResults:e.no_results||"No results found",noMoreResults:e.no_more_results||"No more results",loading:e.loading||"Loading\u2026",styleLabel:e.style_label||"Style",stylePrimary:e.style_primary||"Primary",styleSecondary:e.style_secondary||"Secondary",cancel:e.cancel||"Cancel",insert:e.insert||"Add",update:e.update||"Update",saving:e.saving||"Saving\u2026",saveError:e.save_error||"Could not save this button block. Please try again.",editLabel:e.edit_label||"Edit button",slashLabel:e.slash_label||"Button",slashDescription:e.slash_description||"Add a primary or secondary button",plainText:e.plain_text||"Button"},admins:Array.isArray(n)?n:[],messageBaseUrl:t?.dataset.messageBaseUrl||"",testimonialBaseUrl:t?.dataset.testimonialBaseUrl||""}}export function buttonBlockCopy(){return buttonBlockConfig().copy}
1export class ButtonBlockExtension extends Extension{#t=null;#e=!1;#n=null;#s=null;#i=null;#o=null;#l=null;#a=null;#r=null;get enabled(){return this.editorElement.supportsRichText}get allowedElements(){return[{tag:"div",attributes:["class","data-button-name","data-button-url","data-button-style","data-button-type"]},{tag:"a",attributes:["class","href","target","rel"]},{tag:"span",attributes:["class"]},{tag:"svg",attributes:["class","xmlns","width","height","viewBox","viewbox","aria-hidden","focusable","fill"]},{tag:"g",attributes:["fill","stroke","stroke-linecap","stroke-linejoin","stroke-width"]},{tag:"path",attributes:["d","fill","stroke"]},{tag:"polyline",attributes:["points","fill","stroke"]},{tag:"polygon",attributes:["points","fill","stroke"]}]}get lexicalExtension(){return this.defineExtension({name:"schoolmaker/button-block",register:t=>{const e=t.registerNodeTransform(CustomActionTextAttachmentNode,t=>this.#c(t));return this.#d(),this.#u(()=>this.#h(t)),()=>{e(),this.#p(),this.#m(),this.#y()}}})}initializeToolbar(t){this.#d(),this.#u(()=>this.#h(this.editorElement.editor))}dispose(){this.#p(),this.#y(),this.#m(),this.#n?.remove(),this.#n=null,this.#a=null}#g(){return Boolean(document.getElementById(CONFIG_TEMPLATE_ID))}#u(t){const e=()=>!!this.#g()&&(t(),!0);if(e())return;this.#y();const n=()=>{this.#y(),e()};this.#l=n,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",n,{once:!0}):this.#l=setTimeout(n,0)}#y(){this.#l&&("number"==typeof this.#l?clearTimeout(this.#l):document.removeEventListener("DOMContentLoaded",this.#l),this.#l=null)}#h(t){buttonsCreatable()&&!this.#e&&(this.#e=!0,this.editorElement.setAttribute("data-lexxy-button-enabled",""),this.#b(),t&&!this.#r&&(this.#r=t.registerUpdateListener(()=>this.#L())),this.#L())}#p(){this.#E(),this.#r?.(),this.#r=null,this.#e=!1,this.editorElement.removeAttribute("data-lexxy-button-enabled"),this.#s&&this.editorElement.removeEventListener("pointerdown",this.#s,!0),this.#i&&this.editorElement.removeEventListener("click",this.#i,!0),this.#s=null,this.#i=null}#c(t){this.#g()&&(buttonsCreatable()||$isCustomActionTextAttachmentNode(t)&&t.contentType===BUTTON_CONTENT_TYPE&&t.remove())}#L(){this.#t||(this.#t=requestAnimationFrame(()=>{this.#t=requestAnimationFrame(()=>{this.#t=null,this.#v()})}))}#E(){this.#t&&(cancelAnimationFrame(this.#t),this.#t=null)}#v(){this.editorElement.querySelectorAll('action-text-attachment[content-type="application/vnd.actiontext.button"]').forEach(t=>{const e=t.querySelector(".embed--button");if(!e)return;neutralizeButtonInteractions(e);let n=t.querySelector("[data-button-edit-button]");n&&!n.classList.contains("button-edit-control")&&(n.remove(),n=null),n?n.parentElement!==t&&t.appendChild(n):(n=createButtonEditButton(this.#f.editLabel),t.appendChild(n));const s=t.querySelector("lexxy-node-delete-button");s&&s.parentElement!==t&&t.appendChild(s)})}#T(t){if(null!=t.button&&0!==t.button)return;const e=t.target?.closest?.("[data-button-edit-button]");if(!e||!this.editorElement.contains(e))return;const n=e.closest("action-text-attachment"),s=n?.querySelector(".embed--button");if(!s||!n)return;const i=n.dataset.lexicalNodeKey||null,o=this.editorElement.editor;if(!o||!i)return;let l=!1;o.getEditorState().read(()=>{l=$isCustomActionTextAttachmentNode($getNodeByKey(i))}),l&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation?.(),queueMicrotask(()=>this.#S({nodeKey:i,name:s.dataset.buttonName||s.querySelector("a")?.textContent?.trim()||"",url:s.dataset.buttonUrl||s.querySelector("a")?.getAttribute("href")||"",style:normalizeButtonStyle(s.dataset.buttonStyle)})))}#d(){this.#o||(this.#o=t=>this.#S(t?.detail||{}),this.editorElement.addEventListener(OPEN_BUTTON_BLOCK_EVENT,this.#o),buttonDialogOpeners.set(this.editorElement,(t={})=>this.#S(t)))}#m(){this.#o&&this.editorElement.removeEventListener(OPEN_BUTTON_BLOCK_EVENT,this.#o),buttonDialogOpeners.delete(this.editorElement),this.#o=null}#b(){this.#s||(this.#s=t=>this.#T(t),this.#i=t=>{const e=t.target?.closest?.('action-text-attachment[content-type="application/vnd.actiontext.button"] a[href]');e&&this.editorElement.contains(e)&&(t.preventDefault(),t.stopPropagation())},this.editorElement.addEventListener("pointerdown",this.#s,!0),this.editorElement.addEventListener("click",this.#i,!0))}#S({name:t="",url:e="",style:n="primary",type:s=null,nodeKey:i=null}={}){if(!buttonsCreatable())return;const o=this.editorElement.editor;if(!o)return;i||o.getEditorState().read(()=>{this.#a=$getSelection()?.clone()||null});const l=buttonBlockConfig();this.#n||=new ButtonBlockDialog({config:l,onSave:t=>this.#_(t)}),this.#n.config=l,this.#n.open({name:t,url:e,style:n,type:s,nodeKey:i})}#_({content:t,sgid:e,nodeKey:n}){const s=this.editorElement.editor,i=this.editorElement.contents;s&&i&&(s.update(()=>{const s=new CustomActionTextAttachmentNode({sgid:e,contentType:BUTTON_CONTENT_TYPE,innerHtml:t,plainText:this.#f.plainText});if(n){const t=$getNodeByKey(n);$isCustomActionTextAttachmentNode(t)&&t.replace(s)}else this.#a&&$setSelection(this.#a),i.insertAtCursor(s)}),this.#a=null,s.focus(),this.#L())}get#f(){return buttonBlockCopy()}}class ButtonBlockDialog{#x=null;#C;#B;#n;#I;#A;#w;#$;#N=null;#O;#D;#U;#X;#k;#F;#R=null;#P;#Y;#M;#V;constructor({config:t,onSave:e}){this.#C=t,this.#O=e,this.#F=Math.random().toString(36).slice(2,10),this.#I=`lexxy-button-dialog-${this.#F}`,this.#H()}set config(t){this.#C=t}get#f(){return this.#C.copy}open({name:t="",url:e="",style:n="primary",type:s=null,nodeKey:i=null}={}){this.#N=i,this.#$.value=t,this.#q(normalizeButtonStyle(n)),this.#U.textContent=i?this.#f.update:this.#f.insert,this.#A.textContent="";const o=parseButtonDestination(e,this.#C),l=normalizeButtonType(s||o.type);this.#z(l),this.#Y.value="url"===l?o.url||e:"",this.#w.value=o.messageTitle||"",this.#X.value=o.source||DEFAULT_TESTIMONIAL_SOURCE,this.#K(o.receiverId||""),this.#j(),this.#G(),this.#B.open().then(()=>this.#$.focus())}close(){this.#B.close()}remove(){this.#J(),this.#Z(),this.#B.remove()}#H(){const t=`lexxy-button-name-${this.#F}`,e=`lexxy-button-type-${this.#F}`,n=`lexxy-button-url-${this.#F}`,s=`lexxy-button-admin-${this.#F}`,i=`lexxy-button-message-title-${this.#F}`,o=`lexxy-button-source-${this.#F}`,l=`lexxy-button-style-${this.#F}`;this.#B=createSiteModal({id:this.#I,size:"xl",title:escapeHtml(this.#f.title),description:escapeHtml(this.#f.description),closeLabel:this.#f.closeLabel,dialogClassName:"overflow-visible",bodyHtml:`\n <div class="${LEXXY_FIELDS}">\n <div class="${LEXXY_FIELD}">\n <label class="${LEXXY_FIELD_LABEL}" for="${t}">${escapeHtml(this.#f.nameLabel)}</label>\n <input id="${t}" type="text" data-button-name required class="form-control" placeholder="${escapeAttribute(this.#f.namePlaceholder)}" autocomplete="off">\n </div>\n\n <div class="${LEXXY_FIELD}">\n <label class="${LEXXY_FIELD_LABEL}" for="${e}">${escapeHtml(this.#f.typeLabel)}</label>\n <div data-button-type-host></div>\n </div>\n\n <div class="${LEXXY_FIELD}" data-button-url-field>\n <label class="${LEXXY_FIELD_LABEL}" for="${n}">${escapeHtml(this.#f.urlLabel)}</label>\n <input id="${n}" type="text" inputmode="url" data-button-url class="form-control" placeholder="${escapeAttribute(this.#f.urlPlaceholder)}" autocomplete="off">\n </div>\n\n <div class="hidden" data-button-message-field>\n <div class="${LEXXY_FIELDS}">\n <div class="${LEXXY_FIELD}">\n <label class="${LEXXY_FIELD_LABEL}" for="${s}">${escapeHtml(this.#f.adminLabel)}</label>\n <div data-button-admin-host></div>\n </div>\n\n <div class="${LEXXY_FIELD}">\n <label class="${LEXXY_FIELD_LABEL}" for="${i}">${escapeHtml(this.#f.messageTitleLabel)}</label>\n <div class="${LEXXY_FIELD_CONTROL}">\n <input id="${i}" type="text" maxlength="255" data-button-message-title class="form-control" placeholder="${escapeAttribute(this.#f.messageTitlePlaceholder)}" autocomplete="off">\n <p class="${LEXXY_HINT}">${escapeHtml(this.#f.messageTitleHint)}</p>\n </div>\n </div>\n </div>\n </div>\n\n <div class="hidden" data-button-testimonial-field>\n <div class="${LEXXY_FIELD}">\n <label class="${LEXXY_FIELD_LABEL}" for="${o}">${escapeHtml(this.#f.sourceLabel)}</label>\n <div class="${LEXXY_FIELD_CONTROL}">\n <input id="${o}" type="text" maxlength="100" data-button-source class="form-control" placeholder="${escapeAttribute(this.#f.sourcePlaceholder)}" autocomplete="off" value="${DEFAULT_TESTIMONIAL_SOURCE}">\n <p class="${LEXXY_HINT}">${escapeHtml(this.#f.sourceHint)}</p>\n </div>\n </div>\n </div>\n\n <fieldset class="${LEXXY_FIELDSET}">\n <legend class="px-0 ${LEXXY_FIELD_LABEL}">${escapeHtml(this.#f.styleLabel)}</legend>\n <div class="mt-2 grid grid-cols-2 gap-2">\n <label class="${LEXXY_CHOICE_CARD} flex flex-col items-center gap-3">\n <input type="radio" name="${l}" value="primary" data-button-style class="sr-only" checked>
1\n <span class="lexxy-editor__toolbar-button lexxy-dialog-btn lexxy-dialog-btn--primary pointer-events-none">${escapeHtml(this.#f.stylePrimary)}</span>\n </label>\n <label class="${LEXXY_CHOICE_CARD} flex flex-col items-center gap-3">\n <input type="radio" name="${l}" value="secondary" data-button-style class="sr-only">\n <span class="lexxy-editor__toolbar-button lexxy-dialog-btn lexxy-dialog-btn--secondary pointer-events-none">${escapeHtml(this.#f.styleSecondary)}</span>\n </label>\n </div>\n </fieldset>\n </div>\n\n <p class="${LEXXY_ERROR}" data-button-error></p>\n `,footerHtml:`\n <button type="button" class="${LEXXY_SECONDARY_BTN}" data-button-cancel>${escapeHtml(this.#f.cancel)}</button>\n <button type="button" class="${LEXXY_PRIMARY_BTN}" data-button-save disabled><span>${escapeHtml(this.#f.insert)}</span></button>\n `}),this.#n=this.#B.dialog,this.#A=this.#n.querySelector("[data-button-error]"),this.#$=this.#n.querySelector("[data-button-name]"),this.#Y=this.#n.querySelector("[data-button-url]"),this.#w=this.#n.querySelector("[data-button-message-title]"),this.#P=this.#n.querySelector("[data-button-url-field]"),this.#M=this.#n.querySelector("[data-button-message-field]"),this.#V=this.#n.querySelector("[data-button-testimonial-field]"),this.#X=this.#n.querySelector("[data-button-source]"),this.#k=Array.from(this.#n.querySelectorAll("[data-button-style]")),this.#D=this.#n.querySelector("[data-button-save]"),this.#U=this.#D.querySelector("span"),this.#W(e),this.#$.addEventListener("input",()=>this.#G()),this.#Y.addEventListener("input",()=>this.#G()),this.#w.addEventListener("input",()=>this.#G()),this.#X.addEventListener("input",()=>this.#G()),this.#k.forEach(t=>t.addEventListener("change",()=>this.#G())),this.#D.addEventListener("click",()=>this.#Q()),this.#n.querySelector("[data-button-cancel]").addEventListener("click",()=>this.close()),this.#n.addEventListener("keydown",t=>{"Enter"===t.key&&"TEXTAREA"!==t.target?.tagName&&(t.target?.closest?.(".ts-dropdown, .ts-control")||this.#D.disabled||(t.preventDefault(),this.#Q()))})}#W(t){const e=this.#n.querySelector("[data-button-type-host]");if(!e)return;const n=document.createElement("select");n.id=t,n.name="button_type",n.className="w-full",n.style.visibility="hidden",n.dataset.controller="select",n.dataset.selectClearButtonValue="false",n.dataset.selectDropdownParentValue=`#${this.#I}`,n.dataset.selectDropdownZIndexValue="1080",n.dataset.selectDropdownStrategyValue="fixed",n.dataset.selectNoSearchResultsTextValue=this.#f.noResults,n.dataset.selectNoMoreResultsTextValue=this.#f.noMoreResults,n.dataset.selectLoadingTextValue=this.#f.loading,n.autocomplete="off",n.dataset.buttonType="";const s=[{value:"url",name:this.#f.typeUrl,icon:TYPE_ICONS.url}];this.#C.admins.length&&s.push({value:"message",name:this.#f.typeMessage,icon:TYPE_ICONS.message}),this.#C.testimonialBaseUrl&&s.push({value:"testimonial",name:this.#f.typeTestimonial,icon:TYPE_ICONS.testimonial}),s.forEach((t,e)=>{const s=document.createElement("option");s.value=t.value,s.selected=0===e,s.textContent=JSON.stringify({icon:t.icon,name:t.name}),n.appendChild(s)}),e.replaceChildren(n),this.#R=n,this.#R.addEventListener("change",()=>{this.#j(),this.#G()})}#K(t=""){this.#J();const e=this.#n.querySelector("[data-button-admin-host]");if(!e)return;const n=document.createElement("select");n.id=`lexxy-button-admin-${this.#F}`,n.name="admin_id",n.className="w-full",n.style.visibility="hidden",n.dataset.controller="select",n.dataset.selectDropdownInputValue="true",n.dataset.selectDropdownInputPlaceholderValue=this.#f.searchPlaceholder,n.dataset.selectClearButtonValue="false",n.dataset.selectDropdownParentValue=`#${this.#I}`,n.dataset.selectDropdownZIndexValue="1080",n.dataset.selectDropdownStrategyValue="fixed",n.dataset.selectNoSearchResultsTextValue=this.#f.noResults,n.dataset.selectNoMoreResultsTextValue=this.#f.noMoreResults,n.dataset.selectLoadingTextValue=this.#f.loading,n.autocomplete="off";const s=document.createElement("option");s.value="",s.textContent=this.#f.adminPlaceholder,n.appendChild(s),this.#C.admins.forEach(e
1=>{const s=document.createElement("option");s.value=e.id,s.selected=t&&e.id===t,s.textContent=JSON.stringify({icon:`<img class="size-4 rounded-full" src="${escapeAttribute(e.image_url||"")}" alt="">`,name:e.name||"",description:e.description||""}),n.appendChild(s)}),e.replaceChildren(n),this.#x=n,this.#x.addEventListener("change",()=>this.#G())}#Z(){this.#R&&(this.#R.tomselect&&this.#R.tomselect.destroy(),this.#R.remove(),this.#R=null)}#J(){this.#x&&(this.#x.tomselect&&this.#x.tomselect.destroy(),this.#x.remove(),this.#x=null)}#z(t){const e=normalizeButtonType(t);this.#R&&(this.#R.tomselect?this.#R.tomselect.setValue(e,!0):this.#R.value=e)}#tt(){return normalizeButtonType(this.#R?.value)}#q(t){this.#k.forEach(e=>{e.checked=e.value===t})}#et(){return this.#k.find(t=>t.checked)?.value||"primary"}#j(){const t=this.#tt(),e="url"===t,n="message"===t,s="testimonial"===t;this.#P.classList.toggle("hidden",!e),this.#M.classList.toggle("hidden",!n),this.#V.classList.toggle("hidden",!s),n&&!this.#x&&this.#K()}#nt(){const t=this.#tt(),e=this.#X.value.trim()||DEFAULT_TESTIMONIAL_SOURCE;return{name:this.#$.value.trim(),type:t,url:this.#Y.value.trim(),receiverId:this.#x?.value?.trim()||"",messageTitle:this.#w.value.trim(),source:e,style:normalizeButtonStyle(this.#et())}}#st(t=this.#nt()){return"message"===t.type?buildMessageUrl(this.#C.messageBaseUrl,t.receiverId,{title:t.messageTitle}):"testimonial"===t.type?buildTestimonialUrl(this.#C.testimonialBaseUrl,{source:t.source}):normalizeButtonUrl(t.url)}#it(t=this.#nt(),{reveal:e=!1}={}){if(!t.name)return{valid:!1,error:""};if("message"===t.type){if(!t.receiverId)return{valid:!1,error:e?this.#f.adminInvalid:""};return isValidButtonUrl(this.#st(t))?{valid:!0,error:""}:{valid:!1,error:this.#f.urlInvalid}}if("testimonial"===t.type){return isValidButtonUrl(this.#st(t))?{valid:!0,error:""}:{valid:!1,error:this.#f.urlInvalid}}return isValidButtonUrl(t.url)?{valid:!0,error:""}:{valid:!1,error:t.url?this.#f.urlInvalid:""}}#G({reveal:t=!1}={}){const e=this.#nt(),{valid:n,error:s}=this.#it(e,{reveal:t});this.#D.disabled=!n;const i=[this.#f.urlInvalid,this.#f.adminInvalid];s?this.#A.textContent=s:i.includes(this.#A.textContent)&&(this.#A.textContent="")}async#Q(){const t=this.#nt(),{valid:e}=this.#it(t,{reveal:!0});if(e){this.#ot(!0),this.#A.textContent="";try{const e=await createButtonAttachment({name:t.name,url:this.#st(t),style:t.style});this.close(),this.#O({...e,nodeKey:this.#N})}catch(t){this.#A.textContent=this.#f.saveError}finally{this.#ot(!1)}}else this.#G({reveal:!0})}#ot(t){this.#$.disabled=t,this.#Y.disabled=t,this.#w.disabled=t,this.#X.disabled=t,this.#k.forEach(e=>{e.disabled=t}),this.#lt(this.#R,t),this.#lt(this.#x,t);const{valid:e}=this.#it();this.#D.disabled=t||!e,this.#U.textContent=t?this.#f.saving:this.#N?this.#f.update:this.#f.insert}#lt(t,e){t&&(t.disabled=e,t.tomselect&&(e?t.tomselect.disable():t.tomselect.enable()))}}export function parseButtonDestination(t,e={}){const n=String(t||"").trim();if(!n)return{type:"url",url:"",receiverId:"",messageTitle:"",source:DEFAULT_TESTIMONIAL_SOURCE};try{const t=new URL(normalizeButtonUrl(n),window.location.origin),s=e.messageBaseUrl?new URL(e.messageBaseUrl,window.location.origin):null,i=e.testimonialBaseUrl?new URL(e.testimonialBaseUrl,window.location.origin):null;if(s&&t.pathname===s.pathname&&t.searchParams.get("id"))return{type:"message",url:n,receiverId:t.searchParams.get("id")||"",messageTitle:t.searchParams.get("title")||"",source:DEFAULT_TESTIMONIAL_SOURCE};if(i&&(t.pathname===i.pathname||t.pathname.includes("/testimonials/")))return{type:"testimonial",url:n,receiverId:"",messageTitle:"",source:t.searchParams.get("source")||DEFAULT_TESTIMONIAL_SOURCE}}catch(t){}return{type:"url",url:n,receiverId:"",messageTitle:"",source:DEFAULT_TESTIMONIAL_SOURCE}}export function buildMessageUrl(t,e,{title:n}={}){if(!t||!e)return"";try{const s=new URL(t,window.location.origin);s.searchParams.set("id",e);const i=String(n||"").trim();return i?s.searchParams.set("title",i):s.searchParams.delete("title"),s.toString()}catch(t){return""}}export function buildTestimonialUrl(t,{source:e}={}){if(!t)return"";try{const n=new URL(t,window.location.origin);return n.searchParams.set("source",String(e||"").trim()||DEFAULT_TESTIMONIAL_SOURCE),n.toString()}catch(t){return""}}export function normalizeButtonUrl(t){const e=String(t||"").trim();return e?/^[a-z][a-z0-9+.-]*:/i.test(e)?e:`https://${e}`:""}export function isValidButtonUrl(t){const e=String(t||"").trim();if(!e)return!1;try{const t=new URL(normalizeButtonUrl(e));return("http:"===t.protocol||"https:"===t.protocol)&&!(!t.hostname||!t.hostname.includes("."))}catch(t){return!1}}
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.