var At = Object.defineProperty;
var D = (a) => {
throw TypeError(a);
};
var Tt = (a, i, t) => i in a ? At(a, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[i] = t;
var p = (a, i, t) => Tt(a, typeof i != "symbol" ? i + "" : i, t), C = (a, i, t) => i.has(a) || D("Cannot " + t);
var y = (a, i, t) => (C(a, i, "read from private field"), t ? t.call(a) : i.get(a)), _ = (a, i, t) => i.has(a) ? D("Cannot add the same private member more than once") : i instanceof WeakSet ? i.add(a) : i.set(a, t), b = (a, i, t, e) => (C(a, i, "write to private field"), e ? e.call(a, t) : i.set(a, t), t), E = (a, i, t) => (C(a, i, "access private method"), t);
class It extends HTMLElement {
constructor() {
super(), this._value = "", this.render();
}
static get observedAttributes() {
return ["data-text", "data-queryparam", "data-value"];
}
set value(i) {
this.setAttribute("data-value", i);
}
get value() {
return this.getAttribute("data-value") || "";
}
set text(i) {
this.setAttribute("data-text", i);
}
get text() {
return this.getAttribute("data-text") || "";
}
set queryparam(i) {
this.setAttribute("data-queryparam", i);
}
get queryparam() {
return this.getAttribute("data-queryparam") || "";
}
connectedCallback() {
this._filter = this.text, this._queryparam = this.queryparam, this.render(), htmx.process(this);
}
attributeChangedCallback(i, t, e) {
t !== e && (i === "data-text" && (this._filter = e), i === "data-queryparam" && (this._queryparam = e), i === "data-value" && (this._value = e), this.render());
}
getURL() {
if (this._queryparam) {
let i = new URL(window.location), t = new URLSearchParams(i.search);
return t.delete(this._queryparam), t.delete("page"), i.search = t.toString(), i.toString();
}
return "#";
}
render() {
this.innerHTML = `
`;
}
}
const S = "filter-list-list", Ct = "filter-list-item", yt = "filter-list-input", P = "filter-list-searchable";
var m, g, $;
class wt extends HTMLElement {
constructor() {
super();
_(this, g);
_(this, m, !1);
this._items = [], this._url = "", this._filterstart = !1, this._placeholder = "Liste filtern...", this._queryparam = "", this._startparams = null, this.render();
}
static get observedAttributes() {
return ["data-url"];
}
set items(t) {
Array.isArray(t) && (this._items = t, this.render());
}
get items() {
return this._items;
}
connectedCallback() {
this._url = this.getAttribute("data-url") || "./", this._filterstart = this.getAttribute("data-filterstart") === "true", this._placeholder = this.getAttribute("data-placeholder") || "Liste filtern...", this._queryparam = this.getAttribute("data-queryparam") || "", this._queryparam, this._filterstart && b(this, m, !0), this.addEventListener("input", this.onInput.bind(this)), this.addEventListener("keydown", this.onEnter.bind(this)), this.addEventListener("focusin", this.onGainFocus.bind(this)), this.addEventListener("focusout", this.onLoseFocus.bind(this));
}
attributeChangedCallback(t, e, s) {
t === "data-url" && e !== s && (this._url = s, this.render()), t === "data-filterstart" && e !== s && (this._filterstart = s === "true", this.render()), t === "data-placeholder" && e !== s && (this._placeholder = s, this.render()), t === "data-queryparam" && e !== s && (this._queryparam = s, this.render());
}
onInput(t) {
t.target && t.target.tagName.toLowerCase() === "input" && (this._filter = t.target.value, this.renderList());
}
onGainFocus(t) {
t.target && t.target.tagName.toLowerCase() === "input" && (b(this, m, !1), this.renderList());
}
onLoseFocus(t) {
let e = this.querySelector("input");
if (t.target && t.target === e) {
if (relatedElement = t.relatedTarget, relatedElement && this.contains(relatedElement))
return;
e.value = "", this._filter = "", this._filterstart && b(this, m, !0), this.renderList();
}
}
onEnter(t) {
if (t.target && t.target.tagName.toLowerCase() === "input" && t.key === "Enter") {
t.preventDefault();
const e = this.querySelector("a");
e && e.click();
}
}
mark() {
if (typeof Mark != "function")
return;
let t = this.querySelector("#" + S);
if (!t)
return;
let e = new Mark(t.querySelectorAll("." + P));
this._filter && e.mark(this._filter, {
separateWordSearch: !0
});
}
// INFO: allows for setting a custom HREF of the list item
// The function takes the item as parameter fn(item) and should return a string.
setHREFFunc(t) {
this.getHREF = t, this.render();
}
// INFO: allows for setting a custom link text of the list item
// The function takes the item as parameter fn(item) and should return a string or
// an HTML template literal.
setLinkTextFunc(t) {
this.getLinkText = t, this.render();
}
// INFO: allows for setting the text that will be filtered for.
// The function takes the item as parameter fn(item) and should return a string.
setSearchTextFunc(t) {
this.getSearchText = t, this.render();
}
getHREF(t) {
if (t) {
if (!t.id)
return "";
} else return "";
return t.id;
}
getHREFEncoded(t) {
return encodeURIComponent(this.getHREF(t));
}
getSearchText(t) {
if (t) {
if (!t.name)
return "";
} else return "";
return t.name;
}
getLinkText(t) {
let e = this.getSearchText(t);
return e === "" ? "" : `${e}`;
}
getURL(t) {
if (this._queryparam) {
let e = new URL(window.location), s = new URLSearchParams(e.search);
return s.set(this._queryparam, this.getHREF(t)), s.delete("page"), e.search = s.toString(), e.toString();
}
return this._url + this.getHREFEncoded(t);
}
renderList() {
let t = this.querySelector("#" + S);
t && (t.outerHTML = this.List()), this.mark();
}
render() {
this.innerHTML = `
`;
}
List() {
let t = this._items;
if (this._filter)
if (this._filterstart)
t = this._items.filter((e) => this.getSearchText(e).toLowerCase().startsWith(this._filter.toLowerCase()));
else {
let e = this._filter.split(" ");
t = this._items.filter((s) => e.every((n) => this.getSearchText(s).toLowerCase().includes(n.toLowerCase())));
}
return `
`;
}
_createSelectedItemElement(t) {
const e = this._getItemById(t);
if (!e) return null;
const n = this.selectedItemTemplate.content.cloneNode(!0).firstElementChild, r = n.querySelector('[data-ref="textEl"]'), l = n.querySelector('[data-ref="detailEl"]'), o = n.querySelector('[data-ref="deleteBtn"]');
r.textContent = this._normalizeText(e.name);
const h = this._normalizeText(e.additional_data);
return h ? (l.textContent = `(${h})`, l.classList.remove("hidden")) : (l.textContent = "", l.classList.add("hidden")), o.setAttribute("aria-label", `Remove ${e.name}`), o.dataset.id = t, o.disabled = this.hasAttribute("disabled"), o.addEventListener("click", (u) => {
u.stopPropagation(), this._handleDeleteSelectedItem(t);
}), n;
}
_renderSelectedItems() {
this.selectedItemsContainer && (this.selectedItemsContainer.innerHTML = "", this._value.length === 0 ? this.selectedItemsContainer.innerHTML = `Keine Sprachen ausgewählt...` : this._value.forEach((t) => {
const e = this._createSelectedItemElement(t);
e && this.selectedItemsContainer.appendChild(e);
}), this._updateRootElementStateClasses());
}
_createOptionElement(t, e) {
const n = this.optionTemplate.content.cloneNode(!0).firstElementChild, r = n.querySelector('[data-ref="nameEl"]'), l = n.querySelector('[data-ref="detailEl"]');
r.textContent = this._normalizeText(t.name);
const o = this._normalizeText(t.additional_data);
l.textContent = o ? `(${o})` : "", n.dataset.id = t.id, n.setAttribute("aria-selected", String(e === this._highlightedIndex));
const h = `option-${this.id || "mss"}-${t.id}`;
return n.id = h, e === this._highlightedIndex && (n.classList.add(at), this.inputElement && this.inputElement.setAttribute("aria-activedescendant", h)), n;
}
_renderOptionsList() {
if (!(!this.optionsListElement || !this.inputElement)) {
if (this.optionsListElement.innerHTML = "", this.inputElement.removeAttribute("aria-activedescendant"), this._filteredOptions.length === 0 || !this._isOptionsListVisible)
this.optionsListElement.classList.add("hidden"), this.inputElement.setAttribute("aria-expanded", "false");
else {
this.optionsListElement.classList.remove("hidden"), this.inputElement.setAttribute("aria-expanded", "true"), this._filteredOptions.forEach((e, s) => {
const n = this._createOptionElement(e, s);
this.optionsListElement.appendChild(n);
});
const t = this.optionsListElement.querySelector(`.${at}`);
t && (t.scrollIntoView({ block: "nearest" }), this.inputElement.setAttribute("aria-activedescendant", t.id));
}
this._updateRootElementStateClasses();
}
}
_handleSelectedItemsContainerClick(t) {
t.target === this.selectedItemsContainer && this.inputElement && !this.inputElement.disabled && this.inputElement.focus();
}
_handleCreateNewButtonClick() {
if (this.hasAttribute("disabled") || !this.showCreateButton) return;
const t = this.inputElement ? this.inputElement.value.trim() : "";
this.dispatchEvent(
new CustomEvent("createnew", {
detail: { value: t },
bubbles: !0,
composed: !0
})
);
}
_handleInput(t) {
const e = t.target.value;
if (this._remoteEndpoint) {
this._handleRemoteInput(e);
return;
}
if (e.length === 0)
this._filteredOptions = [], this._isOptionsListVisible = !1;
else {
const s = e.toLowerCase();
this._filteredOptions = this._options.filter((n) => {
if (this._value.includes(n.id)) return !1;
const l = this._normalizeText(n.name).toLowerCase().includes(s), o = this._normalizeText(n.additional_data), h = o && o.toLowerCase().includes(s);
return l || h;
}), this._isOptionsListVisible = this._filteredOptions.length > 0;
}
this._highlightedIndex = this._filteredOptions.length > 0 ? 0 : -1, this._renderOptionsList();
}
_handleKeyDown(t) {
if (!this.inputElement.disabled) {
if (!this._isOptionsListVisible || this._filteredOptions.length === 0) {
t.key === "Enter" && this.inputElement.value.length > 0 && t.preventDefault(), t.key === "Escape" && this._hideOptionsList(), (t.key === "ArrowDown" || t.key === "ArrowUp") && this.inputElement.value.length > 0 && this._handleInput({ target: this.inputElement });
return;
}
switch (t.key) {
case "ArrowDown":
t.preventDefault(), this._highlightedIndex = (this._highlightedIndex + 1) % this._filteredOptions.length, this._renderOptionsList();
break;
case "ArrowUp":
t.preventDefault(), this._highlightedIndex = (this._highlightedIndex - 1 + this._filteredOptions.length) % this._filteredOptions.length, this._renderOptionsList();
break;
case "Enter":
t.stopPropagation(), t.preventDefault(), this._highlightedIndex > -1 && this._filteredOptions[this._highlightedIndex] && this._selectItem(this._filteredOptions[this._highlightedIndex].id);
break;
case "Escape":
t.preventDefault(), this._hideOptionsList();
break;
case "Tab":
this._hideOptionsList();
break;
}
}
}
_hideOptionsList() {
this._isOptionsListVisible = !1, this._highlightedIndex = -1, this.optionsListElement && this._renderOptionsList();
}
_handleFocus() {
this.inputElement.disabled || (this.inputWrapper && this.inputWrapper.classList.add(et), this.inputElement.value.length > 0 && this._handleInput({ target: this.inputElement }), this._updateRootElementStateClasses());
}
_handleBlur() {
this.inputWrapper && this.inputWrapper.classList.remove(et), this._blurTimeout = setTimeout(() => {
this.contains(document.activeElement) || this._hideOptionsList();
}, 150);
}
_handleOptionMouseDown(t) {
t.preventDefault();
}
_handleOptionClick(t) {
const e = t.target.closest("li[data-id]");
e && e.dataset.id && this._selectItem(e.dataset.id);
}
_selectItem(t) {
t && !this._value.includes(t) && (this.value = [...this._value, t]), this.inputElement && (this.inputElement.value = ""), this._filteredOptions = [], this._hideOptionsList(), this.inputElement && !this.hasAttribute("disabled") && this.inputElement.focus();
}
_handleDeleteSelectedItem(t) {
this.value = this._value.filter((e) => e !== t), this.inputElement && this.inputElement.value && this._handleInput({ target: this.inputElement }), this.inputElement && !this.hasAttribute("disabled") && this.inputElement.focus();
}
_parsePositiveInt(t, e) {
if (!t) return e;
const s = parseInt(t, 10);
return Number.isNaN(s) || s <= 0 ? e : s;
}
_handleRemoteInput(t) {
if (this._remoteFetchTimeout && clearTimeout(this._remoteFetchTimeout), t.length < this._remoteMinChars) {
this._filteredOptions = [], this._isOptionsListVisible = !1, this._renderOptionsList();
return;
}
this._remoteFetchTimeout = setTimeout(() => {
this._fetchRemoteOptions(t);
}, ne);
}
_cancelRemoteFetch() {
this._remoteFetchController && (this._remoteFetchController.abort(), this._remoteFetchController = null);
}
async _fetchRemoteOptions(t) {
if (!this._remoteEndpoint) return;
this._cancelRemoteFetch(), this.classList.add(rt);
const e = new AbortController();
this._remoteFetchController = e;
try {
const s = new URL(this._remoteEndpoint, window.location.origin);
s.searchParams.set("q", t), this._remoteLimit && s.searchParams.set("limit", String(this._remoteLimit));
const n = await fetch(s.toString(), {
headers: { Accept: "application/json" },
signal: e.signal,
credentials: "same-origin"
});
if (!n.ok)
throw new Error(`Remote fetch failed with status ${n.status}`);
const r = await n.json();
if (e.signal.aborted)
return;
const l = this._extractRemoteOptions(r);
this._applyRemoteResults(l);
} catch (s) {
if (e.signal.aborted)
return;
console.error("MultiSelectSimple remote fetch error:", s), this._filteredOptions = [], this._isOptionsListVisible = !1, this._renderOptionsList();
} finally {
this._remoteFetchController === e && (this._remoteFetchController = null), this.classList.remove(rt);
}
}
_extractRemoteOptions(t) {
if (!t) return [];
let e = [];
return Array.isArray(t) ? e = t : this._remoteResultKey && Array.isArray(t[this._remoteResultKey]) ? e = t[this._remoteResultKey] : Array.isArray(t.items) && (e = t.items), e.map((s) => {
if (!s) return null;
const n = s.id ?? s.ID ?? s.value ?? "", r = s.name ?? s.title ?? s.label ?? "", l = s.detail ?? s.additional_data ?? s.annotation ?? "", o = this._normalizeText(r), h = this._normalizeText(l);
return !n || !o ? null : {
id: String(n),
name: o,
additional_data: h
};
}).filter(Boolean);
}
_applyRemoteResults(t) {
const e = new Set(this._value), s = /* @__PURE__ */ new Map();
this._options.forEach((n) => {
n != null && n.id && s.set(n.id, n);
}), t.forEach((n) => {
n != null && n.id && s.set(n.id, n);
}), this._options = Array.from(s.values()), this._filteredOptions = t.filter((n) => n && !e.has(n.id)), this._isOptionsListVisible = this._filteredOptions.length > 0, this._highlightedIndex = this._isOptionsListVisible ? 0 : -1, this._renderOptionsList();
}
_normalizeText(t) {
if (t == null)
return "";
let e = String(t).trim();
if (!e)
return "";
const s = e[0], n = e[e.length - 1];
return (s === '"' && n === '"' || s === "'" && n === "'") && (e = e.slice(1, -1).trim(), !e) ? "" : e;
}
}
p(gt, "formAssociated", !0);
const oe = "rbi-button", he = "rbi-icon";
class de extends HTMLElement {
constructor() {
super(), this.initialStates = /* @__PURE__ */ new Map(), this._controlledElements = [], this.button = null, this.lastOverallModifiedState = null, this.handleInputChange = this.handleInputChange.bind(this), this.handleReset = this.handleReset.bind(this);
}
static get observedAttributes() {
return ["controls", "wrapper-class", "modified-class-suffix", "button-aria-label"];
}
connectedCallback() {
const i = `
`;
this.innerHTML = i, this.button = this.querySelector("button"), this.button ? this.button.addEventListener("click", this.handleReset) : console.error("ResetButtonIndividual: Button element not found after setting innerHTML."), this.updateControlledElements(), this.updateButtonAriaLabel();
}
disconnectedCallback() {
this.button && this.button.removeEventListener("click", this.handleReset), this._controlledElements.forEach((i) => {
i.removeEventListener("input", this.handleInputChange), i.removeEventListener("change", this.handleInputChange);
});
}
attributeChangedCallback(i, t, e) {
t !== e && (i === "controls" && this.updateControlledElements(), (i === "controls" || i === "button-aria-label") && this.updateButtonAriaLabel());
}
updateControlledElements() {
this._controlledElements.forEach((e) => {
e.removeEventListener("input", this.handleInputChange), e.removeEventListener("change", this.handleInputChange);
}), this._controlledElements = [], this.lastOverallModifiedState = null;
const i = (this.getAttribute("controls") || "").split(",").map((e) => e.trim()).filter((e) => e);
if (!i.length && this.button) {
this.button.disabled = !0, this.button.setAttribute("aria-disabled", "true"), this.checkIfModified();
return;
}
const t = [];
i.forEach((e) => {
const s = document.getElementById(e);
s ? (t.push(s), this.storeInitialState(s), s.addEventListener("input", this.handleInputChange), s.addEventListener("change", this.handleInputChange)) : console.warn(`ResetButtonIndividual: Element with ID "${e}" not found.`);
}), this._controlledElements = t, this.button && (this.button.disabled = this._controlledElements.length === 0, this.button.setAttribute("aria-controls", this._controlledElements.map((e) => e.id).join(" ")), this.button.disabled ? this.button.setAttribute("aria-disabled", "true") : this.button.removeAttribute("aria-disabled")), this.checkIfModified();
}
storeInitialState(i) {
if (this.initialStates.has(i.id))
return;
let t;
switch (i.type) {
case "checkbox":
case "radio":
t = { checked: i.checked };
break;
case "select-multiple":
t = {
selectedOptions: Array.from(i.options).filter((e) => e.selected).map((e) => e.value)
};
break;
case "select-one":
default:
t = { value: i.value };
break;
}
this.initialStates.set(i.id, t);
}
resetElement(i) {
const t = this.initialStates.get(i.id);
if (t) {
switch (i.type) {
case "checkbox":
case "radio":
i.checked = t.checked;
break;
case "select-multiple":
Array.from(i.options).forEach((e) => {
e.selected = t.selectedOptions.includes(e.value);
});
break;
case "select-one":
default:
i.value = t.value;
break;
}
i.dispatchEvent(new Event("input", { bubbles: !0, cancelable: !0 })), i.dispatchEvent(new Event("change", { bubbles: !0, cancelable: !0 }));
}
}
handleReset() {
this._controlledElements.forEach((i) => {
this.resetElement(i);
}), this.checkIfModified();
}
handleInputChange(i) {
this._controlledElements.includes(i.target) && this.checkIfModified();
}
// Internal helper to check a single element
isElementModified(i) {
const t = this.initialStates.get(i.id);
if (!t) return !1;
switch (i.type) {
case "checkbox":
case "radio":
return i.checked !== t.checked;
case "select-multiple":
const e = Array.from(i.options).filter((n) => n.selected).map((n) => n.value), s = t.selectedOptions;
return e.length !== s.length || e.some((n) => !s.includes(n)) || s.some((n) => !e.includes(n));
case "select-one":
default:
return i.value !== t.value;
}
}
// Public method to check overall modification state
isCurrentlyModified() {
if (this._controlledElements.length === 0)
return !1;
for (const i of this._controlledElements)
if (this.isElementModified(i))
return !0;
return !1;
}
checkIfModified() {
const i = this.isCurrentlyModified();
this._controlledElements.forEach((e) => {
this.isElementModified(e) ? e.classList.add("modified-element") : e.classList.remove("modified-element");
});
const t = this.getAttribute("wrapper-class");
if (t) {
const e = this.closest(`.${t}`);
if (e) {
const s = this.getAttribute("modified-class-suffix") || "modified", n = `${t}-${s}`;
i ? e.classList.add(n) : e.classList.remove(n);
}
}
if (this.button && (this.button.disabled = !i || this._controlledElements.length === 0, this.button.disabled ? this.button.setAttribute("aria-disabled", "true") : this.button.removeAttribute("aria-disabled")), this.lastOverallModifiedState !== i) {
const e = new CustomEvent("rbichange", {
bubbles: !0,
composed: !0,
detail: {
modified: i,
controlledElementIds: this._controlledElements.map((s) => s.id),
instance: this
}
});
this.dispatchEvent(e), this.lastOverallModifiedState = i;
}
}
updateButtonAriaLabel() {
if (!this.button) return;
let i = this.getAttribute("button-aria-label");
if (!i) {
const t = this._controlledElements.map((e) => e.id);
if (t.length === 1 && this._controlledElements[0]) {
const e = this._controlledElements[0], s = document.querySelector(`label[for="${e.id}"]`);
let n = e.name || e.id;
s && s.textContent ? n = s.textContent.trim().replace(/[:*]$/, "").trim() : e.getAttribute("aria-label") && (n = e.getAttribute("aria-label")), i = `Reset ${n}`;
} else t.length > 1 ? i = "Reset selected fields" : i = "Reset field";
}
this.button.setAttribute("aria-label", i);
}
}
const d = "hidden", lt = "dm-stay", L = "dm-title", ot = "dm-menu-button", ce = "dm-target", ue = "data-dm-target", ht = "dm-menu", dt = "dm-menu-item", me = "dm-close-button";
var T, bt;
class pe extends HTMLElement {
constructor() {
super();
_(this, T);
E(this, T, bt).call(this), this.boundHandleClickOutside = this.handleClickOutside.bind(this);
}
connectedCallback() {
if (this._target = document.getElementById(this.getAttribute(ce)), this._target || (this._target = this), this._cildren = Array.from(this.children).filter((t) => t.nodeType === Node.ELEMENT_NODE && !t.classList.contains(ot)).map((t) => ({
node: t,
target: () => {
const e = t.getAttribute(ue);
return e ? document.getElementById(e) || this._target : this._target;
},
stay: () => t.hasAttribute(lt) && t.getAttribute(lt) == "true",
hidden: () => t.classList.contains(d),
name: () => {
const e = t.querySelector("label");
return e ? e.innerHTML : t.hasAttribute(L) ? t.getAttribute(L) : "";
},
nameText: () => {
const e = t.querySelector("label");
return e ? e.textContent.trim() : t.hasAttribute(L) ? t.getAttribute(L) : "";
}
})), this._button = this.querySelector(`.${ot}`), !this._button) {
console.error("DivManagerMenu needs a button element.");
return;
}
this._originalButtonText || (this._originalButtonText = this._button.innerHTML);
for (const t of this._cildren)
this.removeChild(t.node);
this._button.addEventListener("click", this._toggleMenu.bind(this)), this._button.classList.add("relative");
for (const t of this._cildren)
t.node.querySelectorAll(`.${me}`).forEach((s) => {
s.addEventListener("click", (n) => {
this.hideDiv(n, t.node);
});
});
this.renderIntoTarget(), this.refresh(), this._observer = new MutationObserver(() => {
this.refresh();
}), this._cildren.forEach((t) => {
this._observer.observe(t.node, { attributes: !0, attributeFilter: ["class"] });
});
}
disconnectedCallback() {
this._observer && this._observer.disconnect(), document.removeEventListener("click", this.boundHandleClickOutside);
}
refresh() {
this.renderButton(), this.renderMenu(), this.updateTargetVisibility();
}
_toggleMenu(t) {
t.preventDefault(), t.stopPropagation();
const e = this._cildren.filter((s) => s.hidden());
if (e.length === 1) {
const s = this._cildren.indexOf(e[0]);
this.showDiv(t, s);
return;
}
if (e.length === 0) {
this.hideMenu();
return;
}
this.renderMenu(), this._menu.classList.contains(d) ? (this._menu.classList.remove(d), document.addEventListener("click", this.boundHandleClickOutside)) : (this._menu.classList.add(d), document.removeEventListener("click", this.boundHandleClickOutside));
}
handleClickOutside(t) {
this._menu && !this._menu.contains(t.target) && !this._button.contains(t.target) && this.hideMenu();
}
hideMenu() {
this._menu && (this._menu.classList.add(d), document.removeEventListener("click", this.boundHandleClickOutside));
}
renderButton() {
if (!this._button)
return;
this._originalButtonText || (this._originalButtonText = this._button.innerHTML);
const t = this._cildren.filter((e) => e.hidden());
if (t.length === 0) {
this._button.classList.add(d), this._button.parentElement && this._button.parentElement.removeChild(this._button), this._menu = null, this.hideMenu();
return;
}
if (this._button.parentElement || this.appendChild(this._button), this._button.classList.remove(d), t.length === 1) {
const e = this._button.querySelector("i"), s = e ? e.outerHTML : '';
this._button.innerHTML = `${s}
${t[0].nameText()} hinzufügen`, this._menu = null, this.hideMenu();
} else
this._button.innerHTML = this._originalButtonText, this._menu = null;
}
hideDiv(t, e) {
if (t && (t.preventDefault(), t.stopPropagation()), !e || !(e instanceof HTMLElement)) {
console.error("DivManagerMenu: Invalid node provided.");
return;
}
const s = this._cildren.find((r) => r.node === e);
if (!s) {
console.error("DivManagerMenu: Child not found.");
return;
}
s.node.classList.add(d);
const n = s.target();
n && n.contains(s.node) && n.removeChild(s.node), this.renderButton(), this.renderMenu(), this.updateTargetVisibility();
}
showDiv(t, e) {
if (t && (t.preventDefault(), t.stopPropagation()), e < 0 || e >= this._cildren.length) {
console.error("DivManagerMenu: Invalid index.");
return;
}
const s = this._cildren[e];
s.node.classList.remove(d), this.insertChildInOrder(s), this.renderMenu(), this.renderButton(), this.updateTargetVisibility();
}
renderMenu() {
const t = this._cildren.filter((s) => s.hidden());
if (t.length <= 1) {
this.hideMenu();
return;
}
(!this._menu || !this._button.contains(this._menu)) && (this._button.insertAdjacentHTML("beforeend", ``), this._menu = this._button.querySelector(`.${ht}`)), this._menu.innerHTML = `${t.map((s, n) => `
`).join("")}`, this._menu.querySelectorAll(`.${dt}`).forEach((s) => {
s.addEventListener("click", (n) => {
this.showDiv(n, parseInt(s.getAttribute("dm-itemno"))), this.hideMenu(), this.renderButton();
});
});
}
renderIntoTarget() {
this._cildren.forEach((t) => {
t.hidden() || this.insertChildInOrder(t);
}), this.updateTargetVisibility();
}
insertChildInOrder(t) {
const e = t.target(), s = this._cildren.indexOf(t), n = this._cildren.slice(s + 1).filter((r) => r.target() === e).map((r) => r.node).find((r) => e && e.contains(r));
e && (n ? e.insertBefore(t.node, n) : e.appendChild(t.node));
}
updateTargetVisibility() {
new Set(
this._cildren.map((e) => e.target()).filter((e) => e && e !== this)
).forEach((e) => {
const s = Array.from(e.children).some(
(n) => !n.classList.contains(d)
);
e.classList.toggle(d, !s);
});
}
}
T = new WeakSet(), bt = function() {
this._cildren = [], this._rendered = [], this._target = null, this._button = null, this._menu = null, this._originalButtonText = null;
};
const c = "items-row", _e = "items-list", fe = "items-template", ge = "items-add-button", be = "items-cancel-button", Ee = "items-remove-button", Se = "items-edit-button", ve = "items-close-button", Le = "items-summary", Ae = "items-edit-panel", ct = "items_removed[]";
class Te extends HTMLElement {
constructor() {
super(), this._list = null, this._template = null, this._addButton = null, this._idPrefix = `items-editor-${crypto.randomUUID().slice(0, 8)}`, this._handleAdd = this._onAddClick.bind(this);
}
connectedCallback() {
if (this._list = this.querySelector(`.${_e}`), this._template = this.querySelector(`template.${fe}`), this._addButton = this.querySelector(`.${ge}`), !this._list || !this._template || !this._addButton) {
console.error("ItemsEditor: Missing list, template, or add button.");
return;
}
this._addButton.addEventListener("click", this._handleAdd), this._captureAllOriginals(), this._wireCancelButtons(), this._wireRemoveButtons(), this._wireEditButtons(), this._refreshRowIds(), this._syncAllSummaries();
}
disconnectedCallback() {
this._addButton && this._addButton.removeEventListener("click", this._handleAdd);
}
_onAddClick(i) {
i.preventDefault(), this.addItem();
}
addItem() {
const i = this._template.content.cloneNode(!0), t = i.querySelector(`.${c}`);
if (!t) {
console.error("ItemsEditor: Template is missing a row element.");
return;
}
this._list.appendChild(i), this._captureOriginalValues(t), this._wireCancelButtons(t), this._wireRemoveButtons(t), this._wireEditButtons(t), this._assignRowFieldIds(t, this._rowIndex(t)), this._wireSummarySync(t), this._syncSummary(t), this._setRowMode(t, "edit");
}
removeItem(i) {
const t = i.closest(`.${c}`);
if (!t)
return;
const e = t.querySelector('input[name="items_id[]"]'), s = e ? e.value.trim() : "";
s && this._ensureRemovalInput(s), t.remove(), this._refreshRowIds();
}
_wireRemoveButtons(i = this) {
i.querySelectorAll(`.${Ee}`).forEach((t) => {
t.dataset.itemsBound !== "true" && (t.dataset.itemsBound = "true", t.addEventListener("click", (e) => {
e.preventDefault(), this.removeItem(t);
}));
});
}
_wireCancelButtons(i = this) {
i.querySelectorAll(`.${be}`).forEach((t) => {
t.dataset.itemsBound !== "true" && (t.dataset.itemsBound = "true", t.addEventListener("click", (e) => {
e.preventDefault();
const s = t.closest(`.${c}`);
s && this._cancelEdit(s);
}));
});
}
_wireEditButtons(i = this) {
i.querySelectorAll(`.${Se}`).forEach((t) => {
t.dataset.itemsBound !== "true" && (t.dataset.itemsBound = "true", t.addEventListener("click", (e) => {
e.preventDefault();
const s = t.closest(`.${c}`);
s && this._setRowMode(s, "edit");
}));
}), i.querySelectorAll(`.${ve}`).forEach((t) => {
t.dataset.itemsBound !== "true" && (t.dataset.itemsBound = "true", t.addEventListener("click", (e) => {
e.preventDefault();
const s = t.closest(`.${c}`);
s && this._setRowMode(s, "summary");
}));
});
}
_cancelEdit(i) {
const t = i.querySelector('input[name="items_id[]"]');
if (!(t ? t.value.trim() : "")) {
i.remove(), this._refreshRowIds();
return;
}
this._resetToOriginal(i), this._setRowMode(i, "summary");
}
_setRowMode(i, t) {
const e = i.querySelector(`.${Le}`), s = i.querySelector(`.${Ae}`);
!e || !s || (t === "edit" ? (e.classList.add("hidden"), s.classList.remove("hidden")) : (e.classList.remove("hidden"), s.classList.add("hidden"), this._syncSummary(i)));
}
_captureAllOriginals() {
this.querySelectorAll(`.${c}`).forEach((i) => {
this._captureOriginalValues(i);
});
}
_captureOriginalValues(i) {
i.querySelectorAll("[data-field]").forEach((t) => {
t.dataset.originalValue === void 0 && (t.dataset.originalValue = t.value ?? "");
});
}
_resetToOriginal(i) {
i.querySelectorAll("[data-field]").forEach((t) => {
t.dataset.originalValue !== void 0 && (t.value = t.dataset.originalValue);
}), this._syncSummary(i);
}
_refreshRowIds() {
Array.from(this.querySelectorAll(`.${c}`)).forEach((t, e) => {
this._assignRowFieldIds(t, e);
});
}
_rowIndex(i) {
return Array.from(this.querySelectorAll(`.${c}`)).indexOf(i);
}
_assignRowFieldIds(i, t) {
t < 0 || i.querySelectorAll("[data-field-label]").forEach((e) => {
const s = e.getAttribute("data-field-label");
if (!s)
return;
const n = i.querySelector(`[data-field="${s}"]`);
if (!n)
return;
const r = `${this._idPrefix}-${t}-${s}`;
n.id = r, e.setAttribute("for", r);
});
}
_syncAllSummaries() {
this.querySelectorAll(`.${c}`).forEach((i) => {
this._wireSummarySync(i), this._syncSummary(i);
});
}
_wireSummarySync(i) {
i.dataset.summaryBound !== "true" && (i.dataset.summaryBound = "true", i.querySelectorAll("[data-field]").forEach((t) => {
t.addEventListener("input", () => this._syncSummary(i)), t.addEventListener("change", () => this._syncSummary(i));
}));
}
_syncSummary(i) {
i.querySelectorAll("[data-summary-field]").forEach((t) => {
const e = t.getAttribute("data-summary-field");
if (!e)
return;
const s = i.querySelector(`[data-field="${e}"]`);
if (!s)
return;
const n = this._readFieldValue(s), r = t.getAttribute("data-summary-hide-empty") === "true" ? t.closest("[data-summary-container]") : null;
n ? (this._setSummaryContent(t, n), t.classList.remove("text-gray-400"), r && r.classList.remove("hidden")) : (this._setSummaryContent(t, "—"), t.classList.add("text-gray-400"), r && r.classList.add("hidden"));
});
}
_setSummaryContent(i, t) {
const e = i.querySelector("[data-summary-link]");
e ? t && t !== "—" ? (e.setAttribute("href", t), e.textContent = t) : (e.setAttribute("href", "#"), e.textContent = "—") : i.textContent = t || "—";
}
_readFieldValue(i) {
if (i instanceof HTMLSelectElement) {
if (i.multiple)
return Array.from(i.selectedOptions).map((e) => e.textContent.trim()).filter(Boolean).join(", ");
const t = i.selectedOptions[0];
return t ? t.textContent.trim() : "";
}
return i instanceof HTMLInputElement || i instanceof HTMLTextAreaElement ? i.value.trim() : "";
}
_ensureRemovalInput(i) {
if (Array.from(this.querySelectorAll(`input[name="${ct}"]`)).some(
(s) => s.value === i
))
return;
const e = document.createElement("input");
e.type = "hidden", e.name = ct, e.value = i, this.appendChild(e);
}
}
const Ie = "ssr-wrapper", ut = "ssr-input", mt = "ssr-list", Ce = "ssr-option", ye = "ssr-option-name", we = "ssr-option-detail", xe = "ssr-option-bio", pt = "ssr-hidden-input", _t = "ssr-clear-button", B = 1, N = 10, Me = 250;
class Oe extends HTMLElement {
constructor() {
super(), this._endpoint = "", this._resultKey = "items", this._minChars = B, this._limit = N, this._placeholder = "Search...", this._options = [], this._selected = null, this._fetchTimeout = null, this._fetchController = null, this._listVisible = !1, this._boundHandleInput = this._handleInput.bind(this), this._boundHandleFocus = this._handleFocus.bind(this), this._boundHandleKeyDown = this._handleKeyDown.bind(this), this._boundHandleClear = this._handleClear.bind(this), this._boundHandleClickOutside = this._handleClickOutside.bind(this);
}
static get observedAttributes() {
return ["data-endpoint", "data-result-key", "data-minchars", "data-limit", "placeholder", "name"];
}
connectedCallback() {
this._render(), this._input = this.querySelector(`.${ut}`), this._list = this.querySelector(`.${mt}`), this._hiddenInput = this.querySelector(`.${pt}`), this._clearButton = this.querySelector(`.${_t}`), this._endpoint = this.getAttribute("data-endpoint") || "", this._resultKey = this.getAttribute("data-result-key") || "items", this._minChars = this._parsePositiveInt(this.getAttribute("data-minchars"), B), this._limit = this._parsePositiveInt(this.getAttribute("data-limit"), N), this._placeholder = this.getAttribute("placeholder") || "Search...", this._input && (this._input.placeholder = this._placeholder, this._input.addEventListener("input", this._boundHandleInput), this._input.addEventListener("focus", this._boundHandleFocus), this._input.addEventListener("keydown", this._boundHandleKeyDown)), this._clearButton && this._clearButton.addEventListener("click", this._boundHandleClear), document.addEventListener("click", this._boundHandleClickOutside);
}
disconnectedCallback() {
document.removeEventListener("click", this._boundHandleClickOutside), this._input && (this._input.removeEventListener("input", this._boundHandleInput), this._input.removeEventListener("focus", this._boundHandleFocus), this._input.removeEventListener("keydown", this._boundHandleKeyDown)), this._clearButton && this._clearButton.removeEventListener("click", this._boundHandleClear);
}
attributeChangedCallback(i, t, e) {
t !== e && (i === "data-endpoint" && (this._endpoint = e || ""), i === "data-result-key" && (this._resultKey = e || "items"), i === "data-minchars" && (this._minChars = this._parsePositiveInt(e, B)), i === "data-limit" && (this._limit = this._parsePositiveInt(e, N)), i === "placeholder" && (this._placeholder = e || "Search...", this._input && (this._input.placeholder = this._placeholder)), i === "name" && this._hiddenInput && (this._hiddenInput.name = e || ""));
}
_handleInput(i) {
const t = i.target.value.trim();
if (this._selected = null, this._syncHiddenInput(), t.length < this._minChars) {
this._options = [], this._renderOptions(), this._hideList();
return;
}
this._debouncedFetch(t);
}
_handleFocus() {
this._options.length > 0 && this._showList();
}
_handleKeyDown(i) {
i.key === "Escape" && this._hideList();
}
_handleClear(i) {
i.preventDefault(), this._selected = null, this._options = [], this._input && (this._input.value = ""), this._syncHiddenInput(), this._renderOptions(), this._hideList(), this.dispatchEvent(new CustomEvent("ssrchange", { bubbles: !0, detail: { item: null } }));
}
_handleClickOutside(i) {
this.contains(i.target) || this._hideList();
}
_debouncedFetch(i) {
this._fetchTimeout && clearTimeout(this._fetchTimeout), this._fetchTimeout = setTimeout(() => {
this._fetchOptions(i);
}, Me);
}
async _fetchOptions(i) {
if (!this._endpoint)
return;
this._fetchController && this._fetchController.abort(), this._fetchController = new AbortController();
const t = new URL(this._endpoint, window.location.origin);
t.searchParams.set("q", i), this._limit > 0 && t.searchParams.set("limit", String(this._limit));
try {
const e = await fetch(t.toString(), { signal: this._fetchController.signal });
if (!e.ok)
return;
const s = await e.json(), n = Array.isArray(s == null ? void 0 : s[this._resultKey]) ? s[this._resultKey] : [];
this._options = n.filter((r) => r && r.id && r.name), this._renderOptions(), this._options.length > 0 ? this._showList() : this._hideList();
} catch (e) {
if ((e == null ? void 0 : e.name) === "AbortError")
return;
}
}
_renderOptions() {
this._list && (this._list.innerHTML = "", this._options.forEach((i) => {
const t = document.createElement("button");
t.type = "button", t.className = [
Ce,
"w-full text-left px-3 py-2 hover:bg-slate-100 transition-colors"
].join(" ");
const e = document.createElement("div");
if (e.className = [ye, "text-sm font-semibold text-gray-800"].join(" "), e.textContent = i.name, t.appendChild(e), i.detail) {
const s = document.createElement("div");
s.className = [we, "text-xs text-gray-600"].join(" "), s.textContent = i.detail, t.appendChild(s);
}
if (i.bio) {
const s = document.createElement("div");
s.className = [xe, "text-xs text-gray-500"].join(" "), s.textContent = i.bio, t.appendChild(s);
}
t.addEventListener("click", () => {
this._selectOption(i);
}), this._list.appendChild(t);
}));
}
_selectOption(i) {
this._selected = i, this._input && (this._input.value = i.name || ""), this._syncHiddenInput(), this._hideList(), this.dispatchEvent(new CustomEvent("ssrchange", { bubbles: !0, detail: { item: i } })), this.dispatchEvent(new Event("change", { bubbles: !0 }));
}
_syncHiddenInput() {
var i;
this._hiddenInput && (this._hiddenInput.value = ((i = this._selected) == null ? void 0 : i.id) || "");
}
_showList() {
!this._list || this._listVisible || (this._list.classList.remove("hidden"), this._listVisible = !0);
}
_hideList() {
!this._list || !this._listVisible || (this._list.classList.add("hidden"), this._listVisible = !1);
}
_parsePositiveInt(i, t) {
const e = parseInt(i || "", 10);
return Number.isNaN(e) || e <= 0 ? t : e;
}
_render() {
const i = this.getAttribute("name") || "";
this.innerHTML = `
`;
}
}
const ke = "filter-list", Re = "scroll-button", Be = "tool-tip", Ne = "abbrev-tooltips", $e = "int-link", De = "popup-image", Pe = "tab-list", He = "filter-pill", qe = "image-reel", Fe = "multi-select-places", Ue = "multi-select-simple", Ke = "single-select-remote", Et = "reset-button", ze = "div-manager", Ve = "items-editor";
customElements.define($e, Rt);
customElements.define(Ne, f);
customElements.define(ke, wt);
customElements.define(Re, xt);
customElements.define(Be, Mt);
customElements.define(De, Ot);
customElements.define(Pe, kt);
customElements.define(He, It);
customElements.define(qe, Bt);
customElements.define(Fe, ft);
customElements.define(Ue, gt);
customElements.define(Ke, Oe);
customElements.define(Et, de);
customElements.define(ze, pe);
customElements.define(Ve, Te);
function Ge() {
const a = window.location.pathname, i = window.location.search, t = a + i;
return encodeURIComponent(t);
}
function We(a = 5e3, i = 100) {
return new Promise((t, e) => {
let s = 0;
const n = setInterval(() => {
typeof window.QRCode == "function" ? (clearInterval(n), t(window.QRCode)) : (s += i, s >= a && (clearInterval(n), console.error("Timed out waiting for QRCode to become available."), e(new Error("QRCode not available after " + a + "ms. Check if qrcode.min.js is loaded correctly and sets window.QRCode."))));
}, i);
});
}
async function je(a) {
const i = await We(), t = document.getElementById("qr");
t && (t.innerHTML = "", t.classList.add("hidden"), new i(t, {
text: a,
width: 1280,
height: 1280,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: i.CorrectLevel.H
}), setTimeout(() => {
t.classList.remove("hidden");
}, 20));
}
function Qe(a) {
a && (a.addEventListener("focus", (i) => {
i.preventDefault(), a.select();
}), a.addEventListener("mousedown", (i) => {
i.preventDefault(), a.select();
}), a.addEventListener("mouseup", (i) => {
i.preventDefault(), a.select();
})), a && (a.addEventListener("focus", () => {
a.select();
}), a.addEventListener("click", () => {
a.select();
}));
}
function Je() {
document.body.addEventListener("htmx:responseError", function(a) {
const i = a.detail.requestConfig;
if (i.boosted) {
document.body.innerHTML = a.detail.xhr.responseText;
const t = a.detail.xhr.responseURL || i.url;
window.history.pushState(null, "", t);
}
});
}
function Xe(a, i) {
if (!(a instanceof HTMLElement)) {
console.warn("Target must be an HTMLElement.");
return;
}
if (typeof i != "function") {
console.warn("Action must be a function.");
return;
}
const t = a.querySelectorAll(Et);
a.addEventListener("rbichange", (e) => {
for (const s of t)
if (s.isCurrentlyModified()) {
i(e.details, !0);
return;
}
i(e.details, !1);
});
}
function I(a) {
if (!(a instanceof HTMLTextAreaElement)) {
console.warn("TextareaAutoResize: Provided element is not a textarea.");
return;
}
a.style.height = "auto", a.style.height = `${a.scrollHeight}px`;
}
function St(a) {
a.key === "Enter" && a.preventDefault();
}
function vt(a) {
if (!(a instanceof HTMLTextAreaElement)) {
console.warn("HookupTextareaAutoResize: Provided element is not a textarea.");
return;
}
a.addEventListener("input", () => {
I(a);
});
}
function Ye(a) {
if (!(a instanceof HTMLTextAreaElement)) {
console.warn("DisconnectTextareaAutoResize: Provided element is not a textarea.");
return;
}
a.removeEventListener("input", () => {
I(a);
});
}
function Ze(a) {
!(a instanceof HTMLTextAreaElement) && a.classList.contains("no-enter") || a.addEventListener("keydown", St);
}
function ti(a) {
!(a instanceof HTMLTextAreaElement) && a.classList.contains("no-enter") || a.removeEventListener("keydown", St);
}
function ei(a, i) {
for (const t of a)
if (t.type === "childList") {
for (const e of t.addedNodes)
e.nodeType === Node.ELEMENT_NODE && e.matches("textarea") && (vt(e), I(e));
for (const e of t.removedNodes)
e.nodeType === Node.ELEMENT_NODE && e.matches("textarea") && (ti(e), Ye(e));
}
}
function ii(a) {
if (!(a instanceof HTMLFormElement)) {
console.warn("FormLoad: Provided element is not a form.");
return;
}
const i = document.querySelectorAll("textarea");
for (const s of i)
vt(s), I(s);
const t = document.querySelectorAll("textarea.no-enter");
for (const s of t)
Ze(s);
new MutationObserver(ei).observe(a, {
childList: !0,
subtree: !0
});
}
window.ShowBoostedErrors = Je;
window.GenQRCode = je;
window.SelectableInput = Qe;
window.PathPlusQuery = Ge;
window.HookupRBChange = Xe;
window.FormLoad = ii;
export {
f as AbbreviationTooltips,
wt as FilterList,
It as FilterPill,
Bt as ImageReel,
Rt as IntLink,
Te as ItemsEditor,
ft as MultiSelectRole,
gt as MultiSelectSimple,
Ot as PopupImage,
xt as ScrollButton,
Oe as SingleSelectRemote,
kt as TabList,
Mt as ToolTip
};