var Pe = Object.defineProperty;
var Y = (l) => {
throw TypeError(l);
};
var qe = (l, t, e) => t in l ? Pe(l, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[t] = e;
var y = (l, t, e) => qe(l, typeof t != "symbol" ? t + "" : t, e), q = (l, t, e) => t.has(l) || Y("Cannot " + e);
var H = (l, t, e) => (q(l, t, "read from private field"), e ? e.call(l) : t.get(l)), A = (l, t, e) => t.has(l) ? Y("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(l) : t.set(l, e), k = (l, t, e, i) => (q(l, t, "write to private field"), i ? i.call(l, e) : t.set(l, e), e), R = (l, t, e) => (q(l, t, "access private method"), e);
class He extends HTMLElement {
constructor() {
super(), this._value = "", this.render();
}
static get observedAttributes() {
return ["data-text", "data-queryparam", "data-value"];
}
set value(t) {
this.setAttribute("data-value", t);
}
get value() {
return this.getAttribute("data-value") || "";
}
set text(t) {
this.setAttribute("data-text", t);
}
get text() {
return this.getAttribute("data-text") || "";
}
set queryparam(t) {
this.setAttribute("data-queryparam", t);
}
get queryparam() {
return this.getAttribute("data-queryparam") || "";
}
connectedCallback() {
this._filter = this.text, this._queryparam = this.queryparam, this.render(), htmx.process(this);
}
attributeChangedCallback(t, e, i) {
e !== i && (t === "data-text" && (this._filter = i), t === "data-queryparam" && (this._queryparam = i), t === "data-value" && (this._value = i), this.render());
}
getURL() {
if (this._queryparam) {
let t = new URL(window.location), e = new URLSearchParams(t.search);
return e.delete(this._queryparam), e.delete("page"), t.search = e.toString(), t.toString();
}
return "#";
}
render() {
this.innerHTML = `
${this.renderIcon()}
${this.text}
${this.renderValue()}
`;
}
renderIcon() {
return this.value === "true" || this.value === "false" ? `
` : `
`;
}
renderValue() {
return this.value === "true" || this.value === "false" ? "" : `
${this.value}
`;
}
}
const O = "filter-list-list", Fe = "filter-list-item", Ve = "filter-list-input", Z = "filter-list-searchable";
var b, w, X;
class Ue extends HTMLElement {
constructor() {
super();
A(this, w);
A(this, b, !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(e) {
Array.isArray(e) && (this._items = e, 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 && k(this, b, !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(e, i, s) {
e === "data-url" && i !== s && (this._url = s, this.render()), e === "data-filterstart" && i !== s && (this._filterstart = s === "true", this.render()), e === "data-placeholder" && i !== s && (this._placeholder = s, this.render()), e === "data-queryparam" && i !== s && (this._queryparam = s, this.render());
}
onInput(e) {
e.target && e.target.tagName.toLowerCase() === "input" && (this._filter = e.target.value, this.renderList());
}
onGainFocus(e) {
e.target && e.target.tagName.toLowerCase() === "input" && (k(this, b, !1), this.renderList());
}
onLoseFocus(e) {
let i = this.querySelector("input");
if (e.target && e.target === i) {
if (relatedElement = e.relatedTarget, relatedElement && this.contains(relatedElement))
return;
i.value = "", this._filter = "", this._filterstart && k(this, b, !0), this.renderList();
}
}
onEnter(e) {
if (e.target && e.target.tagName.toLowerCase() === "input" && e.key === "Enter") {
e.preventDefault();
const i = this.querySelector("a");
i && i.click();
}
}
mark() {
if (typeof Mark != "function")
return;
let e = this.querySelector("#" + O);
if (!e)
return;
let i = new Mark(e.querySelectorAll("." + Z));
this._filter && i.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(e) {
this.getHREF = e, 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(e) {
this.getLinkText = e, 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(e) {
this.getSearchText = e, this.render();
}
getHREF(e) {
if (e) {
if (!e.id)
return "";
} else return "";
return e.id;
}
getHREFEncoded(e) {
return encodeURIComponent(this.getHREF(e));
}
getSearchText(e) {
if (e) {
if (!e.name)
return "";
} else return "";
return e.name;
}
getLinkText(e) {
let i = this.getSearchText(e);
return i === "" ? "" : `${i} `;
}
getURL(e) {
if (this._queryparam) {
let i = new URL(window.location), s = new URLSearchParams(i.search);
return s.set(this._queryparam, this.getHREF(e)), s.delete("page"), i.search = s.toString(), i.toString();
}
return this._url + this.getHREFEncoded(e);
}
renderList() {
let e = this.querySelector("#" + O);
e && (e.outerHTML = this.List()), this.mark();
}
render() {
this.innerHTML = `
${this.Input()}
${this.List()}
`, htmx && htmx.process(this);
}
ActiveDot(e) {
return R(this, w, X).call(this, e), "";
}
NoItems(e) {
return e.length === 0 ? 'Keine Einträge gefunden
' : "";
}
Input() {
return `
`;
}
List() {
let e = this._items;
if (this._filter)
if (this._filterstart)
e = this._items.filter((i) => this.getSearchText(i).toLowerCase().startsWith(this._filter.toLowerCase()));
else {
let i = this._filter.split(" ");
e = this._items.filter((s) => i.every((n) => this.getSearchText(s).toLowerCase().includes(n.toLowerCase())));
}
return `
`;
}
}
b = new WeakMap(), w = new WeakSet(), X = function(e) {
if (!e)
return !1;
let i = this.getHREF(e);
return i === "" ? !1 : this._queryparam && (new URLSearchParams(window.location.search).get(this._queryparam) || "") === i ? !0 : !!window.location.href.endsWith(i);
};
class ze extends HTMLElement {
constructor() {
super(), this.handleScroll = this.handleScroll.bind(this), this.scrollToTop = this.scrollToTop.bind(this);
}
connectedCallback() {
this.innerHTML = `
`, this._button = this.querySelector(".scroll-to-top"), window.addEventListener("scroll", this.handleScroll), this._button.addEventListener("click", this.scrollToTop);
}
disconnectedCallback() {
window.removeEventListener("scroll", this.handleScroll), this._button.removeEventListener("click", this.scrollToTop);
}
handleScroll() {
(window.scrollY || document.documentElement.scrollTop) > 300 ? this._button.classList.remove("hidden") : this._button.classList.add("hidden");
}
scrollToTop() {
window.scrollTo({ top: 0, behavior: "smooth" });
}
}
class Ke extends HTMLElement {
static get observedAttributes() {
return ["position", "timeout"];
}
constructor() {
super(), this._tooltipBox = null, this._timeout = 200, this._hideTimeout = null, this._hiddenTimeout = null;
}
connectedCallback() {
this.classList.add("relative", "block", "leading-none", "[&>*]:leading-normal");
const t = this.querySelector(".data-tip"), e = t ? t.innerHTML : "Tooltip";
t && t.classList.add("hidden"), this._tooltipBox = document.createElement("div"), this._tooltipBox.innerHTML = e, this._tooltipBox.className = [
"opacity-0",
"hidden",
"absolute",
"px-2",
"py-1",
"text-sm",
"text-white",
"bg-gray-900",
"rounded",
"shadow",
"z-10",
"whitespace-nowrap",
"transition-all",
"duration-200",
"font-sans"
].join(" "), this.appendChild(this._tooltipBox), this._updatePosition(), this.addEventListener("mouseenter", () => this._showTooltip()), this.addEventListener("mouseleave", () => this._hideTooltip());
}
attributeChangedCallback(t, e, i) {
t === "position" && this._tooltipBox && this._updatePosition(), t === "timeout" && i && (this._timeout = parseInt(i) || 200);
}
_showTooltip() {
clearTimeout(this._hideTimeout), clearTimeout(this._hiddenTimeout), this._tooltipBox.classList.remove("hidden"), setTimeout(() => {
this._tooltipBox.classList.remove("opacity-0"), this._tooltipBox.classList.add("opacity-100");
}, 16);
}
_hideTooltip() {
this._hideTimeout = setTimeout(() => {
this._tooltipBox.classList.remove("opacity-100"), this._tooltipBox.classList.add("opacity-0"), this._hiddenTimeout = setTimeout(() => {
this._tooltipBox.classList.add("hidden");
}, this._timeout + 100);
}, this._timeout);
}
_updatePosition() {
switch (this._tooltipBox.classList.remove(
"bottom-full",
"left-1/2",
"-translate-x-1/2",
"mb-2",
// top
"top-full",
"mt-2",
// bottom
"right-full",
"-translate-y-1/2",
"mr-2",
"top-1/2",
// left
"left-full",
"ml-2"
// right
), this.getAttribute("position") || "top") {
case "bottom":
this._tooltipBox.classList.add(
"top-full",
"left-1/2",
"transform",
"-translate-x-1/2",
"mt-0.5"
);
break;
case "left":
this._tooltipBox.classList.add(
"right-full",
"top-1/2",
"transform",
"-translate-y-1/2",
"mr-0.5"
);
break;
case "right":
this._tooltipBox.classList.add(
"left-full",
"top-1/2",
"transform",
"-translate-y-1/2",
"ml-0.5"
);
break;
case "top":
default:
this._tooltipBox.classList.add(
"bottom-full",
"left-1/2",
"transform",
"-translate-x-1/2",
"mb-0.5"
);
}
}
}
class We extends HTMLElement {
constructor() {
super(), this.overlay = null, this._others = null, this._thisindex = -1, this._preview = null, this._description = null, this._imageURL = "", this._hideDLButton = !1;
}
connectedCallback() {
this.classList.add("cursor-pointer"), this.classList.add("select-none"), this._imageURL = this.getAttribute("data-image-url") || "", this._hideDLButton = this.getAttribute("data-hide-dl-button") || !1, this._preview = this.querySelector("img"), this._description = this.querySelector(".image-description"), this._preview && this._preview.addEventListener("click", () => {
this.showOverlay();
});
let t = this.closest("image-reel, .image-reel");
t || (t = document), this._others = Array.from(t.querySelectorAll("popup-image:not(.hidden)")), this._thisindex = this._others.indexOf(this);
}
disconnectedCallback() {
this.overlay && this.overlay.parentNode && this.overlay.parentNode.removeChild(this.overlay);
}
Keys(t) {
t.repeat || (t.preventDefault(), t.key === "ArrowRight" ? this.next() : t.key === "ArrowLeft" ? this.prev() : t.key === "Escape" && this.hideOverlay());
}
next() {
this._others[this._thisindex + 1] ? (this.hideOverlay(), this._others[this._thisindex + 1].showOverlay()) : document.addEventListener("keydown", this.Keys.bind(this), { once: !0 });
}
prev() {
this._others[this._thisindex - 1] ? (this.hideOverlay(), this._others[this._thisindex - 1].showOverlay()) : document.addEventListener("keydown", this.Keys.bind(this), { once: !0 });
}
showOverlay() {
this.overlay = document.createElement("div"), this.overlay.classList.add(
"fixed",
"inset-0",
"z-50",
"bg-black/70",
"flex",
"items-center",
"justify-center",
"p-4"
), this.overlay.innerHTML = `
${this.downloadButton()}
${this.nextButton()}
${this.prevButton()}
${this.description()}
`;
const t = this.overlay.querySelector("#closebutton");
t && t.addEventListener("click", () => {
this.hideOverlay();
});
const e = this.overlay.querySelector("#nextbtn");
e && e.addEventListener("click", this.next.bind(this));
const i = this.overlay.querySelector("#prevbtn");
i && i.addEventListener("click", this.prev.bind(this)), this.overlay.addEventListener("click", (s) => {
s.target === this.overlay && this.hideOverlay();
}), document.addEventListener("keydown", this.Keys.bind(this), { once: !0 }), document.body.appendChild(this.overlay);
}
descriptionImgClass() {
return this.description ? "" : "0";
}
nextButton() {
return this._others[this._thisindex + 1] ? `
Nächstes Bild
` : "";
}
prevButton() {
return this._others[this._thisindex - 1] ? `
Vorheriges Bild
` : "";
}
description() {
return this._description ? `
${this._description.innerHTML}
` : "";
}
downloadButton() {
return this._hideDLButton ? "" : `
Bild herunterladen
`;
}
hideOverlay() {
this.overlay.parentNode.removeChild(this.overlay), this.overlay = null;
}
}
class Ge extends HTMLElement {
static get observedAttributes() {
}
constructor() {
super(), this._showall = !1, this.shown = -1, this._headings = [], this._contents = [], this._checkbox = null, this._disabled = /* @__PURE__ */ new Set(), this._defaultIndex = null;
}
connectedCallback() {
if (this._headings = Array.from(this.querySelectorAll(".tab-list-head")), this._contents = Array.from(this.querySelectorAll(".tab-list-panel")), this._readConfig(), this.hookupEvtHandlers(), this._applyDisabled(), this.hideDependent(), this._headings.length === 1) {
this.expand(0);
return;
}
this._defaultIndex !== null && this._expandFirstAvailable(this._defaultIndex);
}
expand(t) {
t < 0 || t >= this._headings.length || this._disabled.has(t) || (this.shown = t, this._contents.forEach((e, i) => {
i === t ? (e.classList.remove("hidden"), this._headings[i].setAttribute("aria-pressed", "true")) : (e.classList.add("hidden"), this._headings[i].setAttribute("aria-pressed", "false"));
}));
}
hookupShowAll(t) {
t && (this._checkbox = t, t.addEventListener("change", (e) => {
e.target.checked ? this.showAll() : this.default();
}));
}
hookupEvtHandlers() {
for (let t of this._headings)
t.addEventListener("click", this.handleTabClick.bind(this)), t.classList.add("cursor-pointer"), t.classList.add("select-none"), t.setAttribute("role", "button"), t.setAttribute("aria-pressed", "false"), t.setAttribute("tabindex", "0");
for (let t of this._contents)
t.classList.add("hidden");
}
_readConfig() {
const t = (this.getAttribute("data-disabled-indices") || "").trim(), e = (this.getAttribute("data-default-index") || "").trim();
if (this._disabled.clear(), t && t.split(",").map((i) => parseInt(i.trim(), 10)).filter((i) => Number.isFinite(i)).forEach((i) => this._disabled.add(i)), e !== "") {
const i = parseInt(e, 10);
this._defaultIndex = Number.isFinite(i) ? i : null;
} else
this._defaultIndex = null;
}
_applyDisabled() {
this._headings.forEach((t, e) => {
this._disabled.has(e) ? t.classList.add("pointer-events-none", "opacity-60") : t.classList.remove("pointer-events-none", "opacity-60");
});
}
_expandFirstAvailable(t) {
if (this._headings.length !== 0) {
if (!this._disabled.has(t)) {
this.expand(t);
return;
}
for (let e = 0; e < this._headings.length; e += 1)
if (!this._disabled.has(e)) {
this.expand(e);
return;
}
}
}
restore() {
for (let t of this._headings)
t.classList.add("cursor-pointer"), t.classList.add("select-none"), t.setAttribute("role", "button"), t.setAttribute("aria-pressed", "false"), t.setAttribute("tabindex", "0"), t.classList.remove("pointer-events-none"), t.classList.remove("!text-slate-900");
for (let t of this._contents)
t.classList.add("hidden");
}
disable() {
for (let t of this._headings)
t.classList.remove("cursor-pointer"), t.classList.remove("select-none"), t.removeAttribute("role"), t.removeAttribute("aria-pressed"), t.removeAttribute("tabindex"), t.classList.add("pointer-events-none"), t.classList.add("!text-slate-900");
}
showAll() {
this._showall = !0, this.shown = -1, this.disable(), this._contents.forEach((t, e) => {
t.classList.remove("hidden");
let i = this._headings[e], s = i.querySelectorAll(".show-opened");
for (let a of s)
a.classList.add("hidden");
let n = i.querySelectorAll(".show-closed");
for (let a of n)
a.classList.add("hidden");
});
}
default() {
this._showall = !1, this.restore(), this.hideDependent();
}
hideDependent() {
if (this.shown < 0)
for (const t of this._headings)
this._hideAllDep(t, !1);
else
this._headings.forEach((t, e) => {
this._hideAllDep(t, e === this.shown);
});
}
_hideAllDep(t, e) {
const i = t.querySelectorAll(".show-closed");
for (let n of i)
e ? n.classList.add("hidden") : n.classList.remove("hidden");
const s = Array.from(t.querySelectorAll(".show-opened"));
for (let n of s)
e ? n.classList.remove("hidden") : n.classList.add("hidden");
}
handleTabClick(t) {
if (!t.target) {
console.warn("Invalid event target");
return;
}
const e = this.findParentWithClass(t.target, "tab-list-head");
if (!e) {
console.warn("No parent found with class 'tab-list-head'");
return;
}
const i = this._headings.indexOf(e);
i === this.shown ? (this._contents[i].classList.toggle("hidden"), this._headings[i].setAttribute("aria-pressed", "false"), this.shown = -1) : this.expand(i), this.hideDependent();
}
findParentWithClass(t, e) {
for (; t; ) {
if (t.classList && t.classList.contains(e))
return t;
t = t.parentElement;
}
return null;
}
}
class T extends HTMLElement {
static get observedAttributes() {
return ["data-text", "data-abbrevmap"];
}
static get defaultAbbrevMap() {
return {
"#": "Hinweis auf weitere Informationen in der Anmerkung.",
$: "vermutlich",
"+++": "Inhalte aus mehreren Almanachen interpoliert",
B: "Blatt",
BB: "Blätter",
C: "Corrigenda",
Diagr: "Diagramm",
G: "Graphik",
"G-Verz": "Verzeichnis der Kupfer u. ä.",
GG: "Graphiken",
Hrsg: "Herausgeber",
"I-Verz": "Inhaltsverzeichnis",
Kal: "Kalendarium",
Kr: "Karte",
MusB: "Musikbeigabe",
MusBB: "Musikbeigaben",
S: "Seite",
SS: "Seiten",
Sp: "Spiegel",
T: "Titel",
TG: "Titelgraphik, Titelportrait etc",
"TG r": "Titelgraphik, Titelportrait etc recto",
"TG v": "Titelgraphik, Titelportrait etc verso",
Tab: "Tabelle",
UG: "Umschlaggraphik",
"UG r": "Umschlaggraphik recto",
"UG v": "Umschlaggraphik verso",
VB: "Vorsatzblatt",
Vf: "Verfasser",
VrlgM: "Verlagsmitteilung",
Vrwrt: "Vorwort",
ar: "arabische Paginierung",
ar1: "erste arabische Paginierung",
ar2: "zweite arabische Paginierung",
ar3: "dritte arabische Paginierung",
ar4: "vierte arabische Paginierung",
ar5: "fünfte arabische Paginierung",
ar6: "sechste arabische Paginierung",
ar7: "siebte arabische Paginierung",
gA: "graphische Anleitung",
gT: "graphischer Titel",
gTzA: "graphische Tanzanleitung",
nT: "Nachtitel",
röm: "römische Paginierung",
röm1: "erste römische Paginierung",
röm2: "zweite römische Paginierung",
röm3: "dritte römische Paginierung",
röm4: "vierte römische Paginierung",
röm5: "fünfte römische Paginierung",
röm6: "sechste römische Paginierung",
röm7: "siebte römische Paginierung",
vT: "Vortitel",
zT: "Zwischentitel",
"§§": "Hinweis auf Mängel im Almanach (Beschädigungen, fehlende Graphiken, unvollständige Sammlungen etc) in der Anmerkung"
};
}
constructor() {
super(), this._abbrevMap = T.defaultAbbrevMap;
}
connectedCallback() {
this.render();
}
attributeChangedCallback(t, e, i) {
e !== i && (t === "data-abbrevmap" && this._parseAndSetAbbrevMap(i), this.render());
}
_parseAndSetAbbrevMap(t) {
if (!t) {
this._abbrevMap = T.defaultAbbrevMap;
return;
}
try {
this._abbrevMap = JSON.parse(t);
} catch {
this._abbrevMap = T.defaultAbbrevMap;
}
}
setAbbrevMap(t) {
typeof t == "object" && t !== null && (this._abbrevMap = t, this.render());
}
get text() {
return this.getAttribute("data-text") || "";
}
set text(t) {
this.setAttribute("data-text", t);
}
render() {
this.innerHTML = this.transformText(this.text, this._abbrevMap);
}
transformText(t, e) {
let i = "", s = 0;
for (; s < t.length; ) {
if (s > 0 && !this.isSpaceOrPunct(t[s - 1])) {
i += t[s], s++;
continue;
}
const n = this.findLongestAbbrevAt(t, s, e);
if (n) {
const { match: a, meaning: r } = n;
i += `
${r}
${a}
`, s += a.length;
} else
i += t[s], s++;
}
return i;
}
findLongestAbbrevAt(t, e, i) {
let s = null, n = 0;
for (const a of Object.keys(i))
t.startsWith(a, e) && a.length > n && (s = a, n = a.length);
return s ? { match: s, meaning: i[s] } : null;
}
isSpaceOrPunct(t) {
return /\s|[.,;:!?]/.test(t);
}
}
class je extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
this.style.cursor = "pointer", this.addEventListener("click", this.handleClick);
}
disconnectedCallback() {
this.removeEventListener("click", this.handleClick);
}
handleClick(t) {
const e = this.getAttribute("data-jump");
if (e) {
const i = document.querySelector(e);
i ? i.scrollIntoView({ behavior: "smooth" }) : console.warn(`No element found for selector: ${e}`);
}
}
}
var N;
class Je extends HTMLElement {
constructor() {
super();
A(this, N, 176);
this._images = [];
}
connectedCallback() {
this._images = Array.from(this.querySelectorAll(".primages")), this.calculateShownImages();
const e = new ResizeObserver((i, s) => {
this.calculateShownImages();
});
this._resizeObserver = e, e.observe(this);
}
disconnectedCallback() {
this._resizeObserver.unobserve(this);
}
calculateShownImages() {
const e = this.getBoundingClientRect();
console.log(e);
const i = Math.floor(e.width / (H(this, N) + 10));
for (let s = 0; s < this._images.length; s++)
s < i - 1 ? this._images[s].classList.remove("hidden") : this._images[s].classList.add("hidden");
}
}
N = new WeakMap();
const Qe = "msr-component-wrapper", ee = "msr-selected-items-container", te = "msr-placeholder-no-selection-text", Xe = "msr-selected-item-pill", Ye = "msr-selected-item-text", Ze = "msr-item-name", et = "msr-item-additional-data", tt = "msr-selected-item-role", ie = "msr-selected-item-delete-btn", it = "msr-controls-area", se = "msr-pre-add-button", ne = "msr-input-area-wrapper", B = "msr-input-area-default-border", F = "msr-input-area-staged", ae = "msr-staging-area-container", st = "msr-staged-item-pill", nt = "msr-staged-item-text", V = "msr-staged-role-select", le = "msr-staged-cancel-btn", re = "msr-text-input", oe = "msr-add-button", de = "msr-options-list", he = "msr-option-item", at = "msr-option-item-name", lt = "msr-option-item-detail", ce = "msr-option-item-highlighted", U = "msr-hidden-select", rt = "msr-state-no-selection", ot = "msr-state-has-selection", dt = "msr-state-list-open", ht = "msr-state-item-staged";
class Re extends HTMLElement {
constructor() {
super();
y(this, "_blurTimeout", null);
this.internals_ = this.attachInternals(), this._value = [], this._stagedItem = null, this._showAddButton = !0, this._placeholderNoSelection = "Keine Elemente ausgewählt", this._placeholderSearch = "Elemente suchen...", this._placeholderRoleSelect = "Rolle auswählen...", this._options = [], this._roles = [
"Leitung",
"Unterstützung",
"Berater",
"Beobachter",
"Spezialist",
"Koordinator"
], this._filteredOptions = [], this._highlightedIndex = -1, this._isOptionsListVisible = !1, this._setupTemplates(), this._bindEventHandlers();
}
static get observedAttributes() {
return [
"disabled",
"name",
"value",
"show-add-button",
"placeholder-no-selection",
"placeholder-search",
"placeholder-role-select"
];
}
get showAddButton() {
return this._showAddButton;
}
set showAddButton(e) {
const i = typeof e == "string" ? e.toLowerCase() !== "false" : !!e;
this._showAddButton !== i && (this._showAddButton = i, this.setAttribute("show-add-button", String(i)), this.preAddButtonElement && this._updatePreAddButtonVisibility());
}
get placeholderNoSelection() {
return this._placeholderNoSelection;
}
set placeholderNoSelection(e) {
const i = String(e || "Keine Elemente ausgewählt");
this._placeholderNoSelection !== i && (this._placeholderNoSelection = i, this.setAttribute("placeholder-no-selection", i), this.selectedItemsContainer && this._value.length === 0 && this._renderSelectedItems());
}
get placeholderSearch() {
return this._placeholderSearch;
}
set placeholderSearch(e) {
const i = String(e || "Elemente suchen...");
this._placeholderSearch !== i && (this._placeholderSearch = i, this.setAttribute("placeholder-search", i), this.inputElement && (this.inputElement.placeholder = i));
}
get placeholderRoleSelect() {
return this._placeholderRoleSelect;
}
set placeholderRoleSelect(e) {
const i = String(e || "Rolle auswählen...");
this._placeholderRoleSelect !== i && (this._placeholderRoleSelect = i, this.setAttribute("placeholder-role-select", i), this._stagedItem && this.stagedItemPillContainer && this._renderStagedPillOrInput());
}
attributeChangedCallback(e, i, s) {
if (i !== s)
switch (e) {
case "disabled":
this.disabledCallback(this.hasAttribute("disabled"));
break;
case "name":
this.hiddenSelect && (this.hiddenSelect.name = s);
break;
case "value":
break;
case "show-add-button":
this.showAddButton = s;
break;
case "placeholder-no-selection":
this.placeholderNoSelection = s;
break;
case "placeholder-search":
this.placeholderSearch = s;
break;
case "placeholder-role-select":
this.placeholderRoleSelect = s;
break;
}
}
_setupTemplates() {
this.optionTemplate = document.createElement("template"), this.optionTemplate.innerHTML = `
`, this.selectedItemTemplate = document.createElement("template"), this.selectedItemTemplate.innerHTML = `
×
`, this.stagedPlacePillTemplate = document.createElement("template"), this.stagedPlacePillTemplate.innerHTML = `
`, this.stagedCancelBtnTemplate = document.createElement("template"), this.stagedCancelBtnTemplate.innerHTML = `
×
`, this.stagedRoleSelectTemplate = document.createElement("template"), this.stagedRoleSelectTemplate.innerHTML = `
`;
}
_bindEventHandlers() {
this._handleInput = this._handleInput.bind(this), this._handleKeyDown = this._handleKeyDown.bind(this), this._handleInputKeyDown = this._handleInputKeyDown.bind(this), this._handleFocus = this._handleFocus.bind(this), this._handleBlur = this._handleBlur.bind(this), this._handleOptionMouseDown = this._handleOptionMouseDown.bind(this), this._handleOptionClick = this._handleOptionClick.bind(this), this._handleAddButtonClick = this._handleAddButtonClick.bind(this), this._handleCancelStagedItem = this._handleCancelStagedItem.bind(this), this._handleStagedRoleChange = this._handleStagedRoleChange.bind(this);
}
_getItemById(e) {
return this._options.find((i) => i.id === e);
}
_getAvailableRolesForItem(e) {
const i = this._value.filter((s) => s.itemId === e).map((s) => s.role);
return this._roles.filter((s) => !i.includes(s));
}
setRoles(e) {
if (Array.isArray(e) && e.every((i) => typeof i == "string")) {
this._roles = [...e], this._stagedItem && this._stagedItem.item && (this._getAvailableRolesForItem(this._stagedItem.item.id).includes(this._stagedItem.currentRole) || (this._stagedItem.currentRole = ""), this._renderStagedPillOrInput(), this._updateAddButtonState());
const i = this._value.filter((s) => this._roles.includes(s.role));
i.length !== this._value.length && (this.value = i.map((s) => `${s.itemId},${s.role}`));
} else
console.error("setRoles expects an array of strings.");
}
setOptions(e) {
if (Array.isArray(e) && e.every((i) => i && typeof i.id == "string" && typeof i.name == "string")) {
this._options = [...e];
const i = this._value.filter((s) => this._getItemById(s.itemId));
i.length !== this._value.length && (this.value = i.map((s) => `${s.itemId},${s.role}`)), this._stagedItem && this._stagedItem.item && !this._getItemById(this._stagedItem.item.id) && this._handleCancelStagedItem(), this._filteredOptions = [], this._highlightedIndex = -1, this.inputElement && this.inputElement.value ? this._handleInput({ target: this.inputElement }) : this._hideOptionsList();
} else
console.error("setOptions expects an array of objects with id and name properties.");
}
get value() {
return this._value;
}
set value(e) {
if (Array.isArray(e)) {
const i = e.map((a) => {
if (typeof a == "string") {
const r = a.split(",");
if (r.length === 2) {
const o = r[0].trim(), d = r[1].trim();
if (this._getItemById(o) && this._roles.includes(d))
return { itemId: o, role: d, instanceId: crypto.randomUUID() };
}
}
return null;
}).filter((a) => a !== null), s = [], n = /* @__PURE__ */ new Set();
for (const a of i) {
const r = `${a.itemId},${a.role}`;
n.has(r) || (s.push(a), n.add(r));
}
this._value = s;
} else
this._value = [];
this._updateFormValue(), this.selectedItemsContainer && this._renderSelectedItems(), this._updateRootElementStateClasses();
}
get name() {
return this.getAttribute("name");
}
set name(e) {
this.setAttribute("name", e), this.hiddenSelect && (this.hiddenSelect.name = e);
}
connectedCallback() {
if (this.placeholderNoSelection = this.getAttribute("placeholder-no-selection") || this._placeholderNoSelection, this.placeholderSearch = this.getAttribute("placeholder-search") || this._placeholderSearch, this.placeholderRoleSelect = this.getAttribute("placeholder-role-select") || this._placeholderRoleSelect, this._render(), this.inputAreaWrapper = this.querySelector(`.${ne}`), this.inputElement = this.querySelector(`.${re}`), this.stagedItemPillContainer = this.querySelector(`.${ae}`), this.optionsListElement = this.querySelector(`.${de}`), this.selectedItemsContainer = this.querySelector(`.${ee}`), this.addButtonElement = this.querySelector(`.${oe}`), this.preAddButtonElement = this.querySelector(`.${se}`), this.hiddenSelect = this.querySelector(`.${U}`), this.name && this.hiddenSelect && (this.hiddenSelect.name = this.name), this.hasAttribute("show-add-button") ? this.showAddButton = this.getAttribute("show-add-button") : this.setAttribute("show-add-button", String(this._showAddButton)), this.inputElement && (this.inputElement.placeholder = this.placeholderSearch), this.inputElement.addEventListener("input", this._handleInput), this.inputElement.addEventListener("keydown", this._handleInputKeyDown), this.inputElement.addEventListener("focus", this._handleFocus), this.inputElement.addEventListener("blur", this._handleBlur), this.optionsListElement.addEventListener("mousedown", this._handleOptionMouseDown), this.optionsListElement.addEventListener("click", this._handleOptionClick), this.addButtonElement.addEventListener("click", this._handleAddButtonClick), this.addEventListener("keydown", this._handleKeyDown), this._renderStagedPillOrInput(), this._updateAddButtonState(), this._updatePreAddButtonVisibility(), this._updateRootElementStateClasses(), this.hasAttribute("value")) {
const e = this.getAttribute("value");
try {
const i = JSON.parse(e);
Array.isArray(i) ? this.value = i : (console.warn("Parsed value attribute is not an array:", i), this.value = []);
} catch (i) {
if (console.warn("Failed to parse value attribute as JSON array. Attribute was:", e, i), e.startsWith("[") && e.endsWith("]"))
try {
const s = e.slice(1, -1).split(",").map((n) => n.replace(/"/g, "").trim()).filter((n) => n);
this.value = s;
} catch (s) {
console.error("Manual parse of value attribute also failed:", e, s), this.value = [];
}
else e.includes(",") ? this.value = [e] : this.value = [];
}
} else
this._renderSelectedItems(), this._synchronizeHiddenSelect();
this.hasAttribute("disabled") && this.disabledCallback(!0);
}
disconnectedCallback() {
this.inputElement && (this.inputElement.removeEventListener("input", this._handleInput), this.inputElement.removeEventListener("keydown", this._handleInputKeyDown), this.inputElement.removeEventListener("focus", this._handleFocus), this.inputElement.removeEventListener("blur", this._handleBlur)), this.optionsListElement && (this.optionsListElement.removeEventListener("mousedown", this._handleOptionMouseDown), this.optionsListElement.removeEventListener("click", this._handleOptionClick)), this.addButtonElement && this.addButtonElement.removeEventListener("click", this._handleAddButtonClick), this.removeEventListener("keydown", this._handleKeyDown), clearTimeout(this._blurTimeout);
}
formAssociatedCallback(e) {
}
formDisabledCallback(e) {
this.disabledCallback(e);
}
disabledCallback(e) {
this.inputElement && (this.inputElement.disabled = e), this.classList.toggle("pointer-events-none", e), this.querySelectorAll(`.${ie}`).forEach(
(s) => s.disabled = e
);
const i = this.querySelector(`.${V}`);
i && (i.disabled = e), this.hiddenSelect && (this.hiddenSelect.disabled = e), this._updateAddButtonState(), this._updatePreAddButtonVisibility();
}
formResetCallback() {
this.value = [], this._stagedItem = null, this._renderStagedPillOrInput(), this._hideOptionsList(), this.inputElement && (this.inputElement.value = ""), this._updateRootElementStateClasses();
}
formStateRestoreCallback(e, i) {
Array.isArray(e) && e.every((s) => typeof s == "string" && s.includes(",")) ? this.value = e : this.value = [], this._updateRootElementStateClasses(), this._updatePreAddButtonVisibility();
}
_synchronizeHiddenSelect() {
this.hiddenSelect && (this.hiddenSelect.innerHTML = "", this._value.forEach((e) => {
var s;
const i = document.createElement("option");
i.value = `${e.itemId},${e.role}`, i.textContent = `${((s = this._getItemById(e.itemId)) == null ? void 0 : s.name) || e.itemId} (${e.role})`, i.selected = !0, this.hiddenSelect.appendChild(i);
}));
}
_updateFormValue() {
this.internals_.setFormValue(null), this._synchronizeHiddenSelect();
}
_updateRootElementStateClasses() {
this.classList.toggle(rt, this._value.length === 0), this.classList.toggle(ot, this._value.length > 0), this.classList.toggle(dt, this._isOptionsListVisible), this.classList.toggle(ht, !!this._stagedItem);
}
_render() {
const e = this.id || `msr-${crypto.randomUUID().slice(0, 8)}`;
this.id || this.setAttribute("id", e), this.innerHTML = `
${this._value.length === 0 ? `${this.placeholderNoSelection} ` : ""}
`;
}
_createStagedItemPillElement(e) {
const s = this.stagedPlacePillTemplate.content.cloneNode(!0).firstElementChild;
return s.querySelector('[data-ref="nameEl"]').textContent = e.name, s;
}
_createStagedRoleSelectElement(e, i) {
const n = this.stagedRoleSelectTemplate.content.cloneNode(!0).firstElementChild;
let a = `${this.placeholderRoleSelect} `;
return e.length === 0 && !this._roles.includes(i) ? (a += "Keine Rollen verfügbar ", n.disabled = !0) : (e.forEach((r) => {
a += `${r} `;
}), n.disabled = e.length === 0 && i === ""), n.innerHTML = a, n.addEventListener("change", this._handleStagedRoleChange), n;
}
_createStagedCancelButtonElement(e) {
const s = this.stagedCancelBtnTemplate.content.cloneNode(!0).firstElementChild;
return s.setAttribute("aria-label", `Auswahl von ${e} abbrechen`), s.addEventListener("click", this._handleCancelStagedItem), s;
}
_renderStagedPillOrInput() {
if (!(!this.stagedItemPillContainer || !this.inputElement || !this.inputAreaWrapper)) {
if (this.stagedItemPillContainer.innerHTML = "", this._stagedItem && this._stagedItem.item) {
this.inputAreaWrapper.classList.remove(B), this.inputAreaWrapper.classList.add(F);
const e = this._createStagedItemPillElement(this._stagedItem.item);
this.stagedItemPillContainer.appendChild(e);
const i = this._getAvailableRolesForItem(this._stagedItem.item.id), s = this._createStagedRoleSelectElement(
i,
this._stagedItem.currentRole
);
this.stagedItemPillContainer.appendChild(s);
const n = this._createStagedCancelButtonElement(this._stagedItem.item.name);
this.stagedItemPillContainer.appendChild(n), this.inputElement.classList.add("hidden"), this.inputElement.value = "", this.inputElement.removeAttribute("aria-activedescendant"), this.inputElement.setAttribute("aria-expanded", "false");
} else
this.inputAreaWrapper.classList.add(B), this.inputAreaWrapper.classList.remove(F), this.inputElement.classList.remove("hidden");
this._updateAddButtonState(), this._updatePreAddButtonVisibility(), this._updateRootElementStateClasses();
}
}
_updatePreAddButtonVisibility() {
if (!this.preAddButtonElement) return;
const e = this.hasAttribute("disabled"), i = !this._stagedItem, s = this.showAddButton && i && !e;
this.preAddButtonElement.classList.toggle("hidden", !s), this.preAddButtonElement.disabled = e;
}
_handleStagedRoleChange(e) {
this._stagedItem && (this._stagedItem.currentRole = e.target.value, this._updateAddButtonState());
}
_handleCancelStagedItem(e) {
e && e.stopPropagation(), this._stagedItem = null, this._renderStagedPillOrInput(), this.inputElement && (this.inputElement.value = "", this.inputElement.focus()), this._hideOptionsList();
}
_createSelectedItemElement(e) {
const i = this._getItemById(e.itemId);
if (!i) return null;
const n = this.selectedItemTemplate.content.cloneNode(!0).firstElementChild, a = n.querySelector('[data-ref="textEl"]');
let r = `${i.name} `, o = i.additional_data ? ` (${i.additional_data}) ` : "", d = ` ${e.role} `;
a.innerHTML = `${r}${o}${d}`;
const c = n.querySelector('[data-ref="deleteBtn"]');
return c.setAttribute("aria-label", `Entferne ${i.name} als ${e.role}`), c.dataset.instanceId = e.instanceId, c.disabled = this.hasAttribute("disabled"), c.addEventListener("click", (h) => {
h.stopPropagation(), this._handleDeleteSelectedItem(e.instanceId);
}), n;
}
_renderSelectedItems() {
this.selectedItemsContainer && (this.selectedItemsContainer.innerHTML = "", this._value.length === 0 ? this.selectedItemsContainer.innerHTML = `${this.placeholderNoSelection} ` : this._value.forEach((e) => {
const i = this._createSelectedItemElement(e);
i && this.selectedItemsContainer.appendChild(i);
}), this._updateRootElementStateClasses());
}
_updateAddButtonState() {
if (this.addButtonElement) {
const e = this.hasAttribute("disabled"), i = this._stagedItem && this._stagedItem.currentRole && this._roles.includes(this._stagedItem.currentRole), s = !this._stagedItem || !i || e;
this.addButtonElement.classList.toggle("hidden", s), this.addButtonElement.disabled = s;
}
}
_createOptionElement(e, i) {
const n = this.optionTemplate.content.cloneNode(!0).firstElementChild;
return n.querySelector('[data-ref="nameEl"]').textContent = e.name, n.querySelector('[data-ref="detailEl"]').textContent = e.additional_data ? `(${e.additional_data})` : "", n.dataset.id = e.id, n.setAttribute("aria-selected", String(i === this._highlightedIndex)), n.id = `${this.id || "msr"}-option-${e.id}`, i === this._highlightedIndex && n.classList.add(ce), n;
}
_renderOptionsList() {
if (!(!this.optionsListElement || !this.inputElement)) {
if (this.optionsListElement.innerHTML = "", this._filteredOptions.length === 0 || !this._isOptionsListVisible)
this.optionsListElement.classList.add("hidden"), this.inputElement.setAttribute("aria-expanded", "false"), this.inputElement.removeAttribute("aria-activedescendant"), this.inputElement.removeAttribute("aria-controls");
else {
this.optionsListElement.classList.remove("hidden"), this.inputElement.setAttribute("aria-expanded", "true"), this.inputElement.setAttribute("aria-controls", this.optionsListElement.id), this._filteredOptions.forEach((i, s) => {
const n = this._createOptionElement(i, s);
this.optionsListElement.appendChild(n);
});
const e = this.optionsListElement.querySelector(
`.${ce}`
);
e ? (e.scrollIntoView({ block: "nearest" }), this.inputElement.setAttribute("aria-activedescendant", e.id)) : this.inputElement.removeAttribute("aria-activedescendant");
}
this._updateRootElementStateClasses();
}
}
_stageItem(e) {
if (this._getAvailableRolesForItem(e.id).length === 0)
return;
this._stagedItem = { item: e, currentRole: "" }, this.inputElement && (this.inputElement.value = "", this.inputElement.setAttribute("aria-expanded", "false"), this.inputElement.removeAttribute("aria-activedescendant")), this._renderStagedPillOrInput(), this._hideOptionsList();
const s = this.stagedItemPillContainer.querySelector(
`.${V}`
);
s && !s.disabled ? s.focus() : this.addButtonElement && !this.addButtonElement.disabled && this.addButtonElement.focus();
}
_handleAddButtonClick() {
if (!this.hasAttribute("disabled") && this._stagedItem && this._stagedItem.item && this._stagedItem.currentRole && this._roles.includes(this._stagedItem.currentRole)) {
const e = {
itemId: this._stagedItem.item.id,
role: this._stagedItem.currentRole,
instanceId: crypto.randomUUID()
};
if (this._value.find(
(s) => s.itemId === e.itemId && s.role === e.role
)) {
this._handleCancelStagedItem();
return;
}
this._value.push(e), this._updateFormValue(), this._renderSelectedItems(), this._stagedItem = null, this._renderStagedPillOrInput(), this.inputElement && (this.inputElement.value = "", this.inputElement.focus()), this._hideOptionsList();
}
}
_handleInput(e) {
if (this.hasAttribute("disabled")) return;
this._stagedItem ? (this._stagedItem = null, this._renderStagedPillOrInput()) : this._updatePreAddButtonVisibility();
const i = e.target.value;
if (i.length === 0)
this._filteredOptions = [], this._isOptionsListVisible = !1;
else {
const s = i.toLowerCase();
this._filteredOptions = this._options.filter((n) => this._getAvailableRolesForItem(n.id).length === 0 || this._stagedItem && this._stagedItem.item.id === n.id ? !1 : n.name.toLowerCase().includes(s) || n.additional_data && n.additional_data.toLowerCase().includes(s)), this._isOptionsListVisible = this._filteredOptions.length > 0;
}
this._highlightedIndex = this._filteredOptions.length > 0 ? 0 : -1, this._renderOptionsList();
}
_handleKeyDown(e) {
var i;
if (!this.hasAttribute("disabled")) {
if (e.key === "Enter" && this._stagedItem && this._stagedItem.item) {
const s = document.activeElement, n = (i = this.stagedItemPillContainer) == null ? void 0 : i.querySelector(
`.${le}`
);
if (s === n) {
e.preventDefault(), this._handleCancelStagedItem(e);
return;
} else if (this._stagedItem.currentRole && this._roles.includes(this._stagedItem.currentRole)) {
e.preventDefault(), this._handleAddButtonClick();
return;
}
}
e.key === "Escape" && (this._isOptionsListVisible ? (e.preventDefault(), this._hideOptionsList(), this.inputElement && this.inputElement.focus()) : this._stagedItem && (e.preventDefault(), this._handleCancelStagedItem(e)));
}
}
_handleInputKeyDown(e) {
if (!(this.hasAttribute("disabled") || this.inputElement && this.inputElement.disabled)) {
if (!this._isOptionsListVisible || this._filteredOptions.length === 0) {
e.key === "Enter" && this.inputElement && this.inputElement.value === "" && e.preventDefault();
return;
}
switch (e.key) {
case "ArrowDown":
e.preventDefault(), this._highlightedIndex = (this._highlightedIndex + 1) % this._filteredOptions.length, this._renderOptionsList();
break;
case "ArrowUp":
e.preventDefault(), this._highlightedIndex = (this._highlightedIndex - 1 + this._filteredOptions.length) % this._filteredOptions.length, this._renderOptionsList();
break;
case "Enter":
case "Tab":
this._highlightedIndex > -1 && this._filteredOptions[this._highlightedIndex] ? (e.preventDefault(), this._stageItem(this._filteredOptions[this._highlightedIndex])) : e.key === "Tab" && this._hideOptionsList();
break;
}
}
}
_hideOptionsList() {
this._isOptionsListVisible = !1, this._highlightedIndex = -1, this.optionsListElement && this._renderOptionsList(), this.inputElement && (this.inputElement.setAttribute("aria-expanded", "false"), this.inputElement.removeAttribute("aria-activedescendant"));
}
_handleFocus() {
if (!(this.hasAttribute("disabled") || this.inputElement && this.inputElement.disabled || this._stagedItem)) {
if (!this._stagedItem && this.inputAreaWrapper && (this.inputAreaWrapper.classList.add(B), this.inputAreaWrapper.classList.remove(F)), this.inputElement && this.inputElement.value.length > 0) {
const e = this.inputElement.value.toLowerCase();
this._filteredOptions = this._options.filter((i) => this._getAvailableRolesForItem(i.id).length === 0 ? !1 : i.name.toLowerCase().includes(e) || i.additional_data && i.additional_data.toLowerCase().includes(e)), this._filteredOptions.length > 0 ? (this._isOptionsListVisible = !0, this._highlightedIndex = 0, this._renderOptionsList()) : this._hideOptionsList();
} else
this._hideOptionsList();
this._updateRootElementStateClasses(), this._updatePreAddButtonVisibility();
}
}
_handleBlur(e) {
this._blurTimeout = setTimeout(() => {
const i = document.activeElement;
i !== this.addButtonElement && i !== this.preAddButtonElement && !(this.stagedItemPillContainer && this.stagedItemPillContainer.contains(i)) && !(this.optionsListElement && this.optionsListElement.contains(i)) && !this.contains(i) && this._hideOptionsList();
}, 150);
}
_handleOptionMouseDown(e) {
e.preventDefault();
}
_handleOptionClick(e) {
if (this.hasAttribute("disabled")) return;
const i = e.target.closest(`li[data-id].${he}`);
if (i) {
const s = i.dataset.id, n = this._filteredOptions.find((a) => a.id === s);
n && this._stageItem(n);
}
}
_handleDeleteSelectedItem(e) {
this.hasAttribute("disabled") || (this._value = this._value.filter((i) => i.instanceId !== e), this._updateFormValue(), this._renderSelectedItems(), this._stagedItem && this._stagedItem.item && this._renderStagedPillOrInput(), this.inputElement && this.inputElement.focus(), this._updatePreAddButtonVisibility());
}
}
y(Re, "formAssociated", !0);
const ct = "mss-component-wrapper", ue = "mss-selected-items-container", ut = "mss-selected-item-pill", mt = "mss-selected-item-text", _t = "mss-selected-item-pill-detail", me = "mss-selected-item-delete-btn", _e = "mss-input-controls-container", pe = "mss-input-wrapper", fe = "mss-input-wrapper-focused", ge = "mss-text-input", be = "mss-create-new-button", Ee = "mss-toggle-button", pt = "mss-inline-row", Se = "mss-options-list", ft = "mss-option-item", gt = "mss-option-item-name", bt = "mss-option-item-detail", ve = "mss-option-item-highlighted", z = "mss-hidden-select", K = "mss-no-items-text", Le = "mss-loading", W = 1, G = 10, Et = 250, St = "mss-state-no-selection", vt = "mss-state-has-selection", Lt = "mss-state-list-open";
class Oe extends HTMLElement {
constructor() {
super();
y(this, "_blurTimeout", null);
this.internals_ = this.attachInternals(), this._value = [], this._initialValue = [], this._initialOrder = [], this._removedIds = /* @__PURE__ */ new Set(), this._initialCaptured = !1, this._allowInitialCapture = !0, this._options = [
{ id: "abk", name: "Abchasisch" },
{ id: "aar", name: "Afar" },
{ id: "afr", name: "Afrikaans" },
{ id: "aka", name: "Akan" },
{ id: "alb", name: "Albanisch" },
{ id: "amh", name: "Amharisch" },
{ id: "ara", name: "Arabisch" },
{ id: "arg", name: "Aragonesisch" },
{ id: "arm", name: "Armenisch" },
{ id: "asm", name: "Assamesisch" },
{ id: "ava", name: "Awarisch" },
{ id: "ave", name: "Avestisch" },
{ id: "aym", name: "Aymara" },
{ id: "aze", name: "Aserbaidschanisch" },
{ id: "bam", name: "Bambara" },
{ id: "bak", name: "Baschkirisch" },
{ id: "baq", name: "Baskisch" },
{ id: "bel", name: "Belarussisch" },
{ id: "ben", name: "Bengalisch" },
{ id: "bis", name: "Bislama" },
{ id: "bos", name: "Bosnisch" },
{ id: "bre", name: "Bretonisch" },
{ id: "bul", name: "Bulgarisch" },
{ id: "bur", name: "Birmanisch" },
{ id: "cat", name: "Katalanisch" },
{ id: "cha", name: "Chamorro" },
{ id: "che", name: "Tschetschenisch" },
{ id: "nya", name: "Nyanja" },
{ id: "chi", name: "Chinesisch" },
{ id: "chu", name: "Kirchenslawisch" },
{ id: "chv", name: "Tschuwaschisch" },
{ id: "cor", name: "Kornisch" },
{ id: "cos", name: "Korsisch" },
{ id: "cre", name: "Cree" },
{ id: "hrv", name: "Kroatisch" },
{ id: "cze", name: "Tschechisch" },
{ id: "dan", name: "Dänisch" },
{ id: "div", name: "Dhivehi" },
{ id: "dut", name: "Niederländisch" },
{ id: "dzo", name: "Dzongkha" },
{ id: "eng", name: "Englisch" },
{ id: "epo", name: "Esperanto" },
{ id: "est", name: "Estnisch" },
{ id: "ewe", name: "Ewe" },
{ id: "fao", name: "Färöisch" },
{ id: "fij", name: "Fidschianisch" },
{ id: "fin", name: "Finnisch" },
{ id: "fre", name: "Französisch" },
{ id: "fry", name: "Westfriesisch" },
{ id: "ful", name: "Ful" },
{ id: "gla", name: "Schottisch-Gälisch" },
{ id: "glg", name: "Galicisch" },
{ id: "lug", name: "Ganda" },
{ id: "geo", name: "Georgisch" },
{ id: "ger", name: "Deutsch" },
{ id: "gre", name: "Griechisch" },
{ id: "kal", name: "Kalaallisut" },
{ id: "grn", name: "Guaraní" },
{ id: "guj", name: "Gujarati" },
{ id: "hat", name: "Haitianisch-Kreolisch" },
{ id: "hau", name: "Hausa" },
{ id: "heb", name: "Hebräisch" },
{ id: "her", name: "Herero" },
{ id: "hin", name: "Hindi" },
{ id: "hmo", name: "Hiri Motu" },
{ id: "hun", name: "Ungarisch" },
{ id: "ice", name: "Isländisch" },
{ id: "ido", name: "Ido" },
{ id: "ibo", name: "Igbo" },
{ id: "ind", name: "Indonesisch" },
{ id: "ina", name: "Interlingua" },
{ id: "ile", name: "Interlingue" },
{ id: "iku", name: "Inuktitut" },
{ id: "ipk", name: "Inupiaq" },
{ id: "gle", name: "Irisch" },
{ id: "ita", name: "Italienisch" },
{ id: "jpn", name: "Japanisch" },
{ id: "jav", name: "Javanisch" },
{ id: "kan", name: "Kannada" },
{ id: "kau", name: "Kanuri" },
{ id: "kas", name: "Kashmiri" },
{ id: "kaz", name: "Kasachisch" },
{ id: "khm", name: "Khmer" },
{ id: "kik", name: "Kikuyu" },
{ id: "kin", name: "Kinyarwanda" },
{ id: "kir", name: "Kirgisisch" },
{ id: "kom", name: "Komi" },
{ id: "kon", name: "Kongo" },
{ id: "kor", name: "Koreanisch" },
{ id: "kua", name: "Kwanyama" },
{ id: "kur", name: "Kurdisch" },
{ id: "lao", name: "Laotisch" },
{ id: "lat", name: "Latein" },
{ id: "lav", name: "Lettisch" },
{ id: "lim", name: "Limburgisch" },
{ id: "lin", name: "Lingala" },
{ id: "lit", name: "Litauisch" },
{ id: "lub", name: "Luba-Katanga" },
{ id: "ltz", name: "Luxemburgisch" },
{ id: "mac", name: "Mazedonisch" },
{ id: "mlg", name: "Malagasy" },
{ id: "may", name: "Malaiisch" },
{ id: "mal", name: "Malayalam" },
{ id: "mlt", name: "Maltesisch" },
{ id: "glv", name: "Manx" },
{ id: "mao", name: "Maori" },
{ id: "mar", name: "Marathi" },
{ id: "mah", name: "Marshallesisch" },
{ id: "mon", name: "Mongolisch" },
{ id: "nau", name: "Nauruisch" },
{ id: "nav", name: "Navajo" },
{ id: "nde", name: "Nord-Ndebele" },
{ id: "nbl", name: "Süd-Ndebele" },
{ id: "ndo", name: "Ndonga" },
{ id: "nep", name: "Nepali" },
{ id: "nor", name: "Norwegisch" },
{ id: "nob", name: "Norwegisch Bokmål" },
{ id: "nno", name: "Norwegisch Nynorsk" },
{ id: "oci", name: "Okzitanisch" },
{ id: "oji", name: "Ojibwa" },
{ id: "ori", name: "Oriya" },
{ id: "orm", name: "Oromo" },
{ id: "oss", name: "Ossetisch" },
{ id: "pli", name: "Pali" },
{ id: "pus", name: "Paschtu" },
{ id: "per", name: "Persisch" },
{ id: "pol", name: "Polnisch" },
{ id: "por", name: "Portugiesisch" },
{ id: "pan", name: "Panjabi" },
{ id: "que", name: "Quechua" },
{ id: "rum", name: "Rumänisch" },
{ id: "roh", name: "Rätoromanisch" },
{ id: "run", name: "Rundi" },
{ id: "rus", name: "Russisch" },
{ id: "sme", name: "Nordsamisch" },
{ id: "smo", name: "Samoanisch" },
{ id: "sag", name: "Sango" },
{ id: "san", name: "Sanskrit" },
{ id: "srd", name: "Sardisch" },
{ id: "srp", name: "Serbisch" },
{ id: "sna", name: "Shona" },
{ id: "snd", name: "Sindhi" },
{ id: "sin", name: "Singhalesisch" },
{ id: "slo", name: "Slowakisch" },
{ id: "slv", name: "Slowenisch" },
{ id: "som", name: "Somali" },
{ id: "sot", name: "Süd-Sotho" },
{ id: "spa", name: "Spanisch" },
{ id: "sun", name: "Sundanesisch" },
{ id: "swa", name: "Swahili" },
{ id: "ssw", name: "Swazi" },
{ id: "swe", name: "Schwedisch" },
{ id: "tgl", name: "Tagalog" },
{ id: "tah", name: "Tahitisch" },
{ id: "tgk", name: "Tadschikisch" },
{ id: "tam", name: "Tamil" },
{ id: "tat", name: "Tatarisch" },
{ id: "tel", name: "Telugu" },
{ id: "tha", name: "Thailändisch" },
{ id: "tib", name: "Tibetisch" },
{ id: "tir", name: "Tigrinya" },
{ id: "ton", name: "Tongaisch" },
{ id: "tso", name: "Tsonga" },
{ id: "tsn", name: "Tswana" },
{ id: "tur", name: "Türkisch" },
{ id: "tuk", name: "Turkmenisch" },
{ id: "twi", name: "Twi" },
{ id: "uig", name: "Uigurisch" },
{ id: "ukr", name: "Ukrainisch" },
{ id: "urd", name: "Urdu" },
{ id: "uzb", name: "Usbekisch" },
{ id: "ven", name: "Venda" },
{ id: "vie", name: "Vietnamesisch" },
{ id: "vol", name: "Volapük" },
{ id: "wln", name: "Wallonisch" },
{ id: "wel", name: "Walisisch" },
{ id: "wol", name: "Wolof" },
{ id: "xho", name: "Xhosa" },
{ id: "iii", name: "Sichuan Yi" },
{ id: "yid", name: "Jiddisch" },
{ id: "yor", name: "Yoruba" },
{ id: "zha", name: "Zhuang" },
{ id: "zul", name: "Zulu" }
], this._filteredOptions = [], this._highlightedIndex = -1, this._isOptionsListVisible = !1, this._remoteEndpoint = null, this._remoteResultKey = "items", this._remoteMinChars = W, this._remoteLimit = G, this._remoteFetchController = null, this._remoteFetchTimeout = null, this._placeholder = this.getAttribute("placeholder") || "Search items...", this._showCreateButton = this.getAttribute("show-create-button") !== "false", this._toggleLabel = this.getAttribute("data-toggle-label") || "", this._toggleInput = this._toggleLabel !== "", this._inputCollapsed = this._toggleInput, this._setupTemplates(), this._bindEventHandlers();
}
_setupTemplates() {
this.optionTemplate = document.createElement("template"), this.optionTemplate.innerHTML = `
`, this.selectedItemTemplate = document.createElement("template"), this.selectedItemTemplate.innerHTML = `
×
`;
}
_bindEventHandlers() {
this._handleInput = this._handleInput.bind(this), this._handleKeyDown = this._handleKeyDown.bind(this), this._handleFocus = this._handleFocus.bind(this), this._handleBlur = this._handleBlur.bind(this), this._handleOptionMouseDown = this._handleOptionMouseDown.bind(this), this._handleOptionClick = this._handleOptionClick.bind(this), this._handleCreateNewButtonClick = this._handleCreateNewButtonClick.bind(this), this._handleSelectedItemsContainerClick = this._handleSelectedItemsContainerClick.bind(this), this._handleToggleClick = this._handleToggleClick.bind(this);
}
_getItemById(e) {
return this._options.find((i) => i.id === e);
}
get placeholder() {
return this._placeholder;
}
set placeholder(e) {
this._placeholder = e, this.inputElement && (this.inputElement.placeholder = this._placeholder), this.setAttribute("placeholder", e);
}
get showCreateButton() {
return this._showCreateButton;
}
set showCreateButton(e) {
const i = String(e).toLowerCase() !== "false" && e !== !1;
this._showCreateButton !== i && (this._showCreateButton = i, this.createNewButton && this.createNewButton.classList.toggle("hidden", !this._showCreateButton), this.setAttribute("show-create-button", this._showCreateButton ? "true" : "false"));
}
setOptions(e) {
if (Array.isArray(e) && e.every((i) => i && typeof i.id == "string" && typeof i.name == "string")) {
this._options = e.map((s) => {
const n = { ...s };
return n.name = this._normalizeText(n.name), n.additional_data = this._normalizeText(n.additional_data), n;
});
const i = this._value.filter((s) => this._getItemById(s));
i.length !== this._value.length ? this.value = i : this.selectedItemsContainer && this._renderSelectedItems(), this._filteredOptions = [], this._highlightedIndex = -1, this.inputElement && this.inputElement.value ? this._handleInput({ target: this.inputElement }) : this._hideOptionsList();
} else console.error("setOptions expects an array of objects with id and name properties.");
}
get value() {
return this._value;
}
set value(e) {
const i = JSON.stringify(this._value.sort());
if (Array.isArray(e))
this._value = [...new Set(e.filter((n) => typeof n == "string" && this._getItemById(n)))];
else if (typeof e == "string" && e.trim() !== "") {
const n = e.trim();
this._getItemById(n) && !this._value.includes(n) ? this._value = [n] : this._getItemById(n) || (this._value = this._value.filter((a) => a !== n));
} else this._value = [];
const s = JSON.stringify(this._value.sort());
!this._initialCaptured && this._allowInitialCapture && this._value.length > 0 && (this._initialValue = [...this._value], this._initialOrder = [...this._value], this._initialCaptured = !0), this._value.forEach((n) => {
this._removedIds.has(n) && this._removedIds.delete(n);
}), i !== s && (this._updateFormValue(), this.selectedItemsContainer && this._renderSelectedItems(), this._updateRootElementStateClasses(), this.dispatchEvent(new Event("change", { bubbles: !0 })));
}
get name() {
return this.getAttribute("name");
}
set name(e) {
this.setAttribute("name", e), this.hiddenSelect && (this.hiddenSelect.name = e);
}
connectedCallback() {
if (this._render(), this.inputControlsContainer = this.querySelector(`.${_e}`), this.inputWrapper = this.querySelector(`.${pe}`), this.inputElement = this.querySelector(`.${ge}`), this.createNewButton = this.querySelector(`.${be}`), this.toggleButton = this.querySelector(`.${Ee}`), this.optionsListElement = this.querySelector(`.${Se}`), this.selectedItemsContainer = this.querySelector(`.${ue}`), this.hiddenSelect = this.querySelector(`.${z}`), this.placeholder = this.getAttribute("placeholder") || "Search items...", this.showCreateButton = this.getAttribute("show-create-button") !== "false", this._toggleLabel = this.getAttribute("data-toggle-label") || "", this._toggleInput = this._toggleLabel !== "", this._inputCollapsed = this._toggleInput, this._remoteEndpoint = this.getAttribute("data-endpoint") || null, this._remoteResultKey = this.getAttribute("data-result-key") || "items", this._remoteMinChars = this._parsePositiveInt(this.getAttribute("data-minchars"), W), this._remoteLimit = this._parsePositiveInt(this.getAttribute("data-limit"), G), this.name && this.hiddenSelect && (this.hiddenSelect.name = this.name), this.inputElement.addEventListener("input", this._handleInput), this.inputElement.addEventListener("keydown", this._handleKeyDown), this.inputElement.addEventListener("focus", this._handleFocus), this.inputElement.addEventListener("blur", this._handleBlur), this.optionsListElement.addEventListener("mousedown", this._handleOptionMouseDown), this.optionsListElement.addEventListener("click", this._handleOptionClick), this.createNewButton.addEventListener("click", this._handleCreateNewButtonClick), this.selectedItemsContainer.addEventListener("click", this._handleSelectedItemsContainerClick), this.toggleButton && this.toggleButton.addEventListener("click", this._handleToggleClick), this._updateRootElementStateClasses(), this.hasAttribute("value")) {
const e = this.getAttribute("value");
try {
this.value = JSON.parse(e);
} catch {
this.value = e.split(",").map((s) => s.trim()).filter(Boolean);
}
} else
this._renderSelectedItems(), this._synchronizeHiddenSelect();
this.hasAttribute("disabled") && this.disabledCallback(!0), this._toggleInput && this._hideInputControls(), this._allowInitialCapture = !1, this._initialCaptured || (this._initialValue = [...this._value], this._initialOrder = [...this._value], this._initialCaptured = !0);
}
disconnectedCallback() {
this.inputElement && (this.inputElement.removeEventListener("input", this._handleInput), this.inputElement.removeEventListener("keydown", this._handleKeyDown), this.inputElement.removeEventListener("focus", this._handleFocus), this.inputElement.removeEventListener("blur", this._handleBlur)), this.optionsListElement && (this.optionsListElement.removeEventListener("mousedown", this._handleOptionMouseDown), this.optionsListElement.removeEventListener("click", this._handleOptionClick)), this.createNewButton && this.createNewButton.removeEventListener("click", this._handleCreateNewButtonClick), this.selectedItemsContainer && this.selectedItemsContainer.removeEventListener("click", this._handleSelectedItemsContainerClick), this.toggleButton && this.toggleButton.removeEventListener("click", this._handleToggleClick), clearTimeout(this._blurTimeout), this._remoteFetchTimeout && (clearTimeout(this._remoteFetchTimeout), this._remoteFetchTimeout = null), this._cancelRemoteFetch();
}
static get observedAttributes() {
return [
"disabled",
"name",
"value",
"placeholder",
"show-create-button",
"data-endpoint",
"data-result-key",
"data-minchars",
"data-limit",
"data-toggle-label"
];
}
attributeChangedCallback(e, i, s) {
if (i !== s)
if (e === "disabled") this.disabledCallback(this.hasAttribute("disabled"));
else if (e === "name" && this.hiddenSelect) this.hiddenSelect.name = s;
else if (e === "value" && this.inputElement)
try {
this.value = JSON.parse(s);
} catch {
this.value = s.split(",").map((a) => a.trim()).filter(Boolean);
}
else e === "placeholder" ? this.placeholder = s : e === "show-create-button" ? this.showCreateButton = s : e === "data-endpoint" ? this._remoteEndpoint = s || null : e === "data-result-key" ? this._remoteResultKey = s || "items" : e === "data-minchars" ? this._remoteMinChars = this._parsePositiveInt(s, W) : e === "data-limit" ? this._remoteLimit = this._parsePositiveInt(s, G) : e === "data-toggle-label" && (this._toggleLabel = s || "", this._toggleInput = this._toggleLabel !== "");
}
formAssociatedCallback(e) {
}
formDisabledCallback(e) {
this.disabledCallback(e);
}
formResetCallback() {
this.value = [], this._hideOptionsList(), this.inputElement && (this.inputElement.value = ""), this.placeholder = this.getAttribute("placeholder") || "Search items...", this.showCreateButton = this.getAttribute("show-create-button") !== "false", this._updateRootElementStateClasses(), this._renderSelectedItems(), this._toggleInput && this._hideInputControls();
}
formStateRestoreCallback(e, i) {
this.value = Array.isArray(e) ? e : [], this._updateRootElementStateClasses();
}
captureInitialSelection() {
this._initialValue = [...this._value], this._initialOrder = [...this._value], this._removedIds.clear(), this._initialCaptured = !0, this._renderSelectedItems();
}
_synchronizeHiddenSelect() {
this.hiddenSelect && (this.hiddenSelect.innerHTML = "", this._value.forEach((e) => {
const i = document.createElement("option");
i.value = e;
const s = this._getItemById(e);
i.textContent = s ? s.name : e, i.selected = !0, this.hiddenSelect.appendChild(i);
}));
}
_updateFormValue() {
this.internals_.setFormValue(null), this._synchronizeHiddenSelect();
}
disabledCallback(e) {
this.inputElement && (this.inputElement.disabled = e), this.createNewButton && (this.createNewButton.disabled = e), this.toggleAttribute("disabled", e), this.querySelectorAll(`.${me}`).forEach((i) => i.disabled = e), this.hiddenSelect && (this.hiddenSelect.disabled = e), e && this._hideOptionsList();
}
_updateRootElementStateClasses() {
this.classList.toggle(St, this._value.length === 0), this.classList.toggle(vt, this._value.length > 0), this.classList.toggle(Lt, this._isOptionsListVisible);
}
_render() {
const e = this.id || `mss-${crypto.randomUUID().slice(0, 8)}`;
this.id || this.setAttribute("id", e);
const i = this.getAttribute("data-toggle-label") || "", s = i !== "", n = s ? "hidden" : "";
this.innerHTML = `
`;
}
_createSelectedItemElement(e) {
const i = this._getItemById(e);
if (!i) return null;
const n = this.selectedItemTemplate.content.cloneNode(!0).firstElementChild, a = n.querySelector('[data-ref="textEl"]'), r = n.querySelector('[data-ref="detailEl"]'), o = n.querySelector('[data-ref="deleteBtn"]');
a.textContent = this._normalizeText(i.name);
const d = this._normalizeText(i.additional_data);
d ? (r.textContent = `(${d})`, r.classList.remove("hidden")) : (r.textContent = "", r.classList.add("hidden"));
const c = this._removedIds.has(e);
if (!this._initialValue.includes(e)) {
const u = document.createElement("span");
u.className = "ml-1 text-xs text-gray-600", u.textContent = "(Neu)", a.appendChild(u);
}
return c && (n.classList.add("bg-red-100"), n.style.position = "relative"), o.setAttribute("aria-label", c ? `Undo remove ${i.name}` : `Remove ${i.name}`), o.dataset.id = e, o.disabled = this.hasAttribute("disabled"), o.innerHTML = c ? ' ' : "×", o.addEventListener("click", (u) => {
u.stopPropagation(), this._handleDeleteSelectedItem(e);
}), n;
}
_renderSelectedItems() {
if (!this.selectedItemsContainer) return;
this.selectedItemsContainer.innerHTML = "";
const e = this._initialOrder.filter((s) => this._removedIds.has(s) && !this._value.includes(s)), i = [...this._value, ...e];
if (i.length === 0) {
const s = this.getAttribute("data-empty-text") || "Keine Auswahl...";
this.selectedItemsContainer.innerHTML = `${s} `;
} else
i.forEach((s) => {
const n = this._createSelectedItemElement(s);
n && this.selectedItemsContainer.appendChild(n);
});
this._updateRootElementStateClasses();
}
_createOptionElement(e, i) {
const n = this.optionTemplate.content.cloneNode(!0).firstElementChild, a = n.querySelector('[data-ref="nameEl"]'), r = n.querySelector('[data-ref="detailEl"]');
a.textContent = this._normalizeText(e.name);
const o = this._normalizeText(e.additional_data);
r.textContent = o ? `(${o})` : "", n.dataset.id = e.id, n.setAttribute("aria-selected", String(i === this._highlightedIndex));
const d = `option-${this.id || "mss"}-${e.id}`;
return n.id = d, i === this._highlightedIndex && (n.classList.add(ve), this.inputElement && this.inputElement.setAttribute("aria-activedescendant", d)), 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((i, s) => {
const n = this._createOptionElement(i, s);
this.optionsListElement.appendChild(n);
});
const e = this.optionsListElement.querySelector(`.${ve}`);
e && (e.scrollIntoView({ block: "nearest" }), this.inputElement.setAttribute("aria-activedescendant", e.id));
}
this._updateRootElementStateClasses();
}
}
_handleSelectedItemsContainerClick(e) {
e.target === this.selectedItemsContainer && this.inputElement && !this.inputElement.disabled && this.inputElement.focus();
}
_handleCreateNewButtonClick() {
if (this.hasAttribute("disabled") || !this.showCreateButton) return;
const e = this.inputElement ? this.inputElement.value.trim() : "";
this.dispatchEvent(
new CustomEvent("createnew", {
detail: { value: e },
bubbles: !0,
composed: !0
})
);
}
_handleInput(e) {
const i = e.target.value;
if (this._remoteEndpoint) {
this._handleRemoteInput(i);
return;
}
if (i.length === 0)
this._filteredOptions = [], this._isOptionsListVisible = !1;
else {
const s = i.toLowerCase();
this._filteredOptions = this._options.filter((n) => {
if (this._value.includes(n.id)) return !1;
const r = this._normalizeText(n.name).toLowerCase().includes(s), o = this._normalizeText(n.additional_data), d = o && o.toLowerCase().includes(s);
return r || d;
}), this._isOptionsListVisible = this._filteredOptions.length > 0;
}
this._highlightedIndex = this._filteredOptions.length > 0 ? 0 : -1, this._renderOptionsList();
}
_handleKeyDown(e) {
if (!this.inputElement.disabled) {
if (!this._isOptionsListVisible || this._filteredOptions.length === 0) {
e.key === "Enter" && this.inputElement.value.length > 0 && e.preventDefault(), e.key === "Escape" && this._hideOptionsList(), (e.key === "ArrowDown" || e.key === "ArrowUp") && this.inputElement.value.length > 0 && this._handleInput({ target: this.inputElement });
return;
}
switch (e.key) {
case "ArrowDown":
e.preventDefault(), this._highlightedIndex = (this._highlightedIndex + 1) % this._filteredOptions.length, this._renderOptionsList();
break;
case "ArrowUp":
e.preventDefault(), this._highlightedIndex = (this._highlightedIndex - 1 + this._filteredOptions.length) % this._filteredOptions.length, this._renderOptionsList();
break;
case "Enter":
e.stopPropagation(), e.preventDefault(), this._highlightedIndex > -1 && this._filteredOptions[this._highlightedIndex] && this._selectItem(this._filteredOptions[this._highlightedIndex].id);
break;
case "Escape":
e.preventDefault(), this._hideOptionsList(), this._toggleInput && this._hideInputControls();
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(fe), this.inputElement.value.length > 0 && this._handleInput({ target: this.inputElement }), this._updateRootElementStateClasses());
}
_handleBlur() {
this.inputWrapper && this.inputWrapper.classList.remove(fe), this._blurTimeout = setTimeout(() => {
this.contains(document.activeElement) || (this._hideOptionsList(), this._toggleInput && (!this.inputElement || this.inputElement.value.trim() === "") && this._hideInputControls());
}, 150);
}
_handleOptionMouseDown(e) {
e.preventDefault();
}
_handleOptionClick(e) {
const i = e.target.closest("li[data-id]");
i && i.dataset.id && this._selectItem(i.dataset.id);
}
_selectItem(e) {
e && !this._value.includes(e) && (this.value = [...this._value, e]), this.inputElement && (this.inputElement.value = ""), this._filteredOptions = [], this._hideOptionsList(), this._toggleInput ? this._hideInputControls() : this.inputElement && !this.hasAttribute("disabled") && this.inputElement.focus();
}
_handleDeleteSelectedItem(e) {
if (this._removedIds.has(e)) {
this._removedIds.delete(e), this._value.includes(e) ? this._renderSelectedItems() : this.value = [...this._value, e];
return;
}
if (this._initialValue.includes(e)) {
this._removedIds.add(e), this.value = this._value.filter((i) => i !== e);
return;
}
this.value = this._value.filter((i) => i !== e), this.inputElement && this.inputElement.value && this._handleInput({ target: this.inputElement }), this.inputElement && !this.hasAttribute("disabled") && this.inputElement.focus();
}
_handleToggleClick(e) {
e.preventDefault(), this._showInputControls();
}
_showInputControls() {
if (this.inputControlsContainer) {
if (this.inputControlsContainer.classList.remove("hidden"), this.toggleButton && this.toggleButton.classList.add("hidden"), this._value.length === 0 && this.selectedItemsContainer) {
const e = this.selectedItemsContainer.querySelector(`.${K}`);
e && e.classList.add("hidden");
}
this.inputElement && !this.hasAttribute("disabled") && this.inputElement.focus(), this._inputCollapsed = !1;
}
}
_hideInputControls() {
if (this.inputControlsContainer) {
if (this.inputControlsContainer.classList.add("hidden"), this.toggleButton && this.toggleButton.classList.remove("hidden"), this._value.length === 0 && this.selectedItemsContainer) {
const e = this.selectedItemsContainer.querySelector(`.${K}`);
e && e.classList.remove("hidden");
}
this._hideOptionsList(), this._inputCollapsed = !0;
}
}
_parsePositiveInt(e, i) {
if (!e) return i;
const s = parseInt(e, 10);
return Number.isNaN(s) || s <= 0 ? i : s;
}
_handleRemoteInput(e) {
if (this._remoteFetchTimeout && clearTimeout(this._remoteFetchTimeout), e.length < this._remoteMinChars) {
this._filteredOptions = [], this._isOptionsListVisible = !1, this._renderOptionsList();
return;
}
this._remoteFetchTimeout = setTimeout(() => {
this._fetchRemoteOptions(e);
}, Et);
}
_cancelRemoteFetch() {
this._remoteFetchController && (this._remoteFetchController.abort(), this._remoteFetchController = null);
}
async _fetchRemoteOptions(e) {
if (!this._remoteEndpoint) return;
this._cancelRemoteFetch(), this.classList.add(Le);
const i = new AbortController();
this._remoteFetchController = i;
try {
const s = new URL(this._remoteEndpoint, window.location.origin);
s.searchParams.set("q", e), this._remoteLimit && s.searchParams.set("limit", String(this._remoteLimit));
const n = await fetch(s.toString(), {
headers: { Accept: "application/json" },
signal: i.signal,
credentials: "same-origin"
});
if (!n.ok)
throw new Error(`Remote fetch failed with status ${n.status}`);
const a = await n.json();
if (i.signal.aborted)
return;
const r = this._extractRemoteOptions(a);
this._applyRemoteResults(r);
} catch (s) {
if (i.signal.aborted)
return;
console.error("MultiSelectSimple remote fetch error:", s), this._filteredOptions = [], this._isOptionsListVisible = !1, this._renderOptionsList();
} finally {
this._remoteFetchController === i && (this._remoteFetchController = null), this.classList.remove(Le);
}
}
_extractRemoteOptions(e) {
if (!e) return [];
let i = [];
return Array.isArray(e) ? i = e : this._remoteResultKey && Array.isArray(e[this._remoteResultKey]) ? i = e[this._remoteResultKey] : Array.isArray(e.items) && (i = e.items), i.map((s) => {
if (!s) return null;
const n = s.id ?? s.ID ?? s.value ?? "", a = s.name ?? s.title ?? s.label ?? "", r = s.detail ?? s.additional_data ?? s.annotation ?? "", o = this._normalizeText(a), d = this._normalizeText(r);
return !n || !o ? null : {
id: String(n),
name: o,
additional_data: d
};
}).filter(Boolean);
}
_applyRemoteResults(e) {
const i = new Set(this._value), s = /* @__PURE__ */ new Map();
this._options.forEach((n) => {
n != null && n.id && s.set(n.id, n);
}), e.forEach((n) => {
n != null && n.id && s.set(n.id, n);
}), this._options = Array.from(s.values()), this._filteredOptions = e.filter((n) => n && !i.has(n.id)), this._isOptionsListVisible = this._filteredOptions.length > 0, this._highlightedIndex = this._isOptionsListVisible ? 0 : -1, this._renderOptionsList();
}
_normalizeText(e) {
if (e == null)
return "";
let i = String(e).trim();
if (!i)
return "";
const s = i[0], n = i[i.length - 1];
return (s === '"' && n === '"' || s === "'" && n === "'") && (i = i.slice(1, -1).trim(), !i) ? "" : i;
}
}
y(Oe, "formAssociated", !0);
const yt = "rbi-button", At = "rbi-icon";
class It 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 t = `
Feld zurücksetzen
`;
this.innerHTML = t, 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((t) => {
t.removeEventListener("input", this.handleInputChange), t.removeEventListener("change", this.handleInputChange);
});
}
attributeChangedCallback(t, e, i) {
e !== i && (t === "controls" && this.updateControlledElements(), (t === "controls" || t === "button-aria-label") && this.updateButtonAriaLabel());
}
updateControlledElements() {
this._controlledElements.forEach((i) => {
i.removeEventListener("input", this.handleInputChange), i.removeEventListener("change", this.handleInputChange);
}), this._controlledElements = [], this.lastOverallModifiedState = null;
const t = (this.getAttribute("controls") || "").split(",").map((i) => i.trim()).filter((i) => i);
if (!t.length && this.button) {
this.button.disabled = !0, this.button.setAttribute("aria-disabled", "true"), this.checkIfModified();
return;
}
const e = [];
t.forEach((i) => {
const s = document.getElementById(i);
s ? (e.push(s), this.storeInitialState(s), s.addEventListener("input", this.handleInputChange), s.addEventListener("change", this.handleInputChange)) : console.warn(`ResetButtonIndividual: Element with ID "${i}" not found.`);
}), this._controlledElements = e, this.button && (this.button.disabled = this._controlledElements.length === 0, this.button.setAttribute("aria-controls", this._controlledElements.map((i) => i.id).join(" ")), this.button.disabled ? this.button.setAttribute("aria-disabled", "true") : this.button.removeAttribute("aria-disabled")), this.checkIfModified();
}
storeInitialState(t) {
if (this.initialStates.has(t.id))
return;
let e;
switch (t.type) {
case "checkbox":
case "radio":
e = { checked: t.checked };
break;
case "select-multiple":
e = {
selectedOptions: Array.from(t.options).filter((i) => i.selected).map((i) => i.value)
};
break;
case "select-one":
default:
e = { value: t.value };
break;
}
this.initialStates.set(t.id, e);
}
resetElement(t) {
const e = this.initialStates.get(t.id);
if (e) {
switch (t.type) {
case "checkbox":
case "radio":
t.checked = e.checked;
break;
case "select-multiple":
Array.from(t.options).forEach((i) => {
i.selected = e.selectedOptions.includes(i.value);
});
break;
case "select-one":
default:
t.value = e.value;
break;
}
t.dispatchEvent(new Event("input", { bubbles: !0, cancelable: !0 })), t.dispatchEvent(new Event("change", { bubbles: !0, cancelable: !0 }));
}
}
handleReset() {
this._controlledElements.forEach((t) => {
this.resetElement(t);
}), this.checkIfModified();
}
handleInputChange(t) {
this._controlledElements.includes(t.target) && this.checkIfModified();
}
// Internal helper to check a single element
isElementModified(t) {
const e = this.initialStates.get(t.id);
if (!e) return !1;
switch (t.type) {
case "checkbox":
case "radio":
return t.checked !== e.checked;
case "select-multiple":
const i = Array.from(t.options).filter((n) => n.selected).map((n) => n.value), s = e.selectedOptions;
return i.length !== s.length || i.some((n) => !s.includes(n)) || s.some((n) => !i.includes(n));
case "select-one":
default:
return t.value !== e.value;
}
}
// Public method to check overall modification state
isCurrentlyModified() {
if (this._controlledElements.length === 0)
return !1;
for (const t of this._controlledElements)
if (this.isElementModified(t))
return !0;
return !1;
}
checkIfModified() {
const t = this.isCurrentlyModified();
this._controlledElements.forEach((i) => {
this.isElementModified(i) ? i.classList.add("modified-element") : i.classList.remove("modified-element");
});
const e = this.getAttribute("wrapper-class");
if (e) {
const i = this.closest(`.${e}`);
if (i) {
const s = this.getAttribute("modified-class-suffix") || "modified", n = `${e}-${s}`;
t ? i.classList.add(n) : i.classList.remove(n);
}
}
if (this.button && (this.button.disabled = !t || this._controlledElements.length === 0, this.button.disabled ? this.button.setAttribute("aria-disabled", "true") : this.button.removeAttribute("aria-disabled")), this.lastOverallModifiedState !== t) {
const i = new CustomEvent("rbichange", {
bubbles: !0,
composed: !0,
detail: {
modified: t,
controlledElementIds: this._controlledElements.map((s) => s.id),
instance: this
}
});
this.dispatchEvent(i), this.lastOverallModifiedState = t;
}
}
updateButtonAriaLabel() {
if (!this.button) return;
let t = this.getAttribute("button-aria-label");
if (!t) {
const e = this._controlledElements.map((i) => i.id);
if (e.length === 1 && this._controlledElements[0]) {
const i = this._controlledElements[0], s = document.querySelector(`label[for="${i.id}"]`);
let n = i.name || i.id;
s && s.textContent ? n = s.textContent.trim().replace(/[:*]$/, "").trim() : i.getAttribute("aria-label") && (n = i.getAttribute("aria-label")), t = `Reset ${n}`;
} else e.length > 1 ? t = "Reset selected fields" : t = "Reset field";
}
this.button.setAttribute("aria-label", t);
}
}
const p = "hidden", ye = "dm-stay", M = "dm-title", Ae = "dm-menu-button", Ct = "dm-target", Tt = "data-dm-target", Ie = "dm-menu", Ce = "dm-menu-item", wt = "dm-close-button";
var D, Be;
class xt extends HTMLElement {
constructor() {
super();
A(this, D);
R(this, D, Be).call(this), this.boundHandleClickOutside = this.handleClickOutside.bind(this);
}
connectedCallback() {
if (this._target = document.getElementById(this.getAttribute(Ct)), this._target || (this._target = this), this._cildren = Array.from(this.children).filter((e) => e.nodeType === Node.ELEMENT_NODE && !e.classList.contains(Ae)).map((e) => ({
node: e,
target: () => {
const i = e.getAttribute(Tt);
return i ? document.getElementById(i) || this._target : this._target;
},
stay: () => e.hasAttribute(ye) && e.getAttribute(ye) == "true",
hidden: () => e.classList.contains(p),
name: () => {
const i = e.querySelector("label");
return i ? i.innerHTML : e.hasAttribute(M) ? e.getAttribute(M) : "";
},
nameText: () => {
const i = e.querySelector("label");
return i ? i.textContent.trim() : e.hasAttribute(M) ? e.getAttribute(M) : "";
}
})), this._button = this.querySelector(`.${Ae}`), !this._button) {
console.error("DivManagerMenu needs a button element.");
return;
}
this._originalButtonText || (this._originalButtonText = this._button.innerHTML);
for (const e of this._cildren)
this.removeChild(e.node);
this._button.addEventListener("click", this._toggleMenu.bind(this)), this._button.classList.add("relative");
for (const e of this._cildren)
e.node.querySelectorAll(`.${wt}`).forEach((s) => {
s.addEventListener("click", (n) => {
this.hideDiv(n, e.node);
});
});
this.renderIntoTarget(), this.refresh(), this._observer = new MutationObserver(() => {
this.refresh();
}), this._cildren.forEach((e) => {
this._observer.observe(e.node, { attributes: !0, attributeFilter: ["class"] });
});
}
disconnectedCallback() {
this._observer && this._observer.disconnect(), document.removeEventListener("click", this.boundHandleClickOutside);
}
refresh() {
this.renderButton(), this.renderMenu(), this.updateTargetVisibility();
}
_toggleMenu(e) {
e.preventDefault(), e.stopPropagation();
const i = this._cildren.filter((s) => s.hidden());
if (i.length === 1) {
const s = this._cildren.indexOf(i[0]);
this.showDiv(e, s);
return;
}
if (i.length === 0) {
this.hideMenu();
return;
}
this.renderMenu(), this._menu.classList.contains(p) ? (this._menu.classList.remove(p), document.addEventListener("click", this.boundHandleClickOutside)) : (this._menu.classList.add(p), document.removeEventListener("click", this.boundHandleClickOutside));
}
handleClickOutside(e) {
this._menu && !this._menu.contains(e.target) && !this._button.contains(e.target) && this.hideMenu();
}
hideMenu() {
this._menu && (this._menu.classList.add(p), document.removeEventListener("click", this.boundHandleClickOutside));
}
renderButton() {
if (!this._button)
return;
this._originalButtonText || (this._originalButtonText = this._button.innerHTML);
const e = this._cildren.filter((i) => i.hidden());
if (e.length === 0) {
this._button.classList.add(p), 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(p), e.length === 1) {
const i = this._button.querySelector("i"), s = i ? i.outerHTML : ' ';
this._button.innerHTML = `${s}
${e[0].nameText()} hinzufügen`, this._menu = null, this.hideMenu();
} else
this._button.innerHTML = this._originalButtonText, this._menu = null;
}
hideDiv(e, i) {
if (e && (e.preventDefault(), e.stopPropagation()), !i || !(i instanceof HTMLElement)) {
console.error("DivManagerMenu: Invalid node provided.");
return;
}
const s = this._cildren.find((a) => a.node === i);
if (!s) {
console.error("DivManagerMenu: Child not found.");
return;
}
s.node.classList.add(p);
const n = s.target();
n && n.contains(s.node) && n.removeChild(s.node), this.renderButton(), this.renderMenu(), this.updateTargetVisibility();
}
showDiv(e, i) {
if (e && (e.preventDefault(), e.stopPropagation()), i < 0 || i >= this._cildren.length) {
console.error("DivManagerMenu: Invalid index.");
return;
}
const s = this._cildren[i];
if (s.node.classList.remove(p), this.insertChildInOrder(s), this.renderMenu(), this.renderButton(), this.updateTargetVisibility(), typeof window.TextareaAutoResize == "function") {
const n = s.node.querySelectorAll("textarea");
n.length > 0 && setTimeout(() => {
n.forEach((a) => {
a.dataset.dmResizeBound !== "true" && (a.dataset.dmResizeBound = "true", a.addEventListener("input", () => {
window.TextareaAutoResize(a);
})), window.TextareaAutoResize(a);
});
}, 10);
}
}
renderMenu() {
const e = this._cildren.filter((s) => s.hidden());
if (e.length <= 1) {
this.hideMenu();
return;
}
(!this._menu || !this._button.contains(this._menu)) && (this._button.insertAdjacentHTML("beforeend", `
`), this._menu = this._button.querySelector(`.${Ie}`)), this._menu.innerHTML = `${e.map((s, n) => `
${s.name()}
`).join("")}`, this._menu.querySelectorAll(`.${Ce}`).forEach((s) => {
s.addEventListener("click", (n) => {
this.showDiv(n, parseInt(s.getAttribute("dm-itemno"))), this.hideMenu(), this.renderButton();
});
});
}
renderIntoTarget() {
this._cildren.forEach((e) => {
e.hidden() || this.insertChildInOrder(e);
}), this.updateTargetVisibility();
}
insertChildInOrder(e) {
const i = e.target(), s = this._cildren.indexOf(e), n = this._cildren.slice(s + 1).filter((a) => a.target() === i).map((a) => a.node).find((a) => i && i.contains(a));
i && (n ? i.insertBefore(e.node, n) : i.appendChild(e.node));
}
updateTargetVisibility() {
new Set(
this._cildren.map((i) => i.target()).filter((i) => i && i !== this)
).forEach((i) => {
const s = Array.from(i.children).some(
(n) => !n.classList.contains(p)
);
i.classList.toggle(p, !s);
});
}
}
D = new WeakSet(), Be = function() {
this._cildren = [], this._rendered = [], this._target = null, this._button = null, this._menu = null, this._originalButtonText = null;
};
const f = "items-row", kt = "items-list", Rt = "items-template", Ot = "items-add-button", Bt = "items-cancel-button", $ = "items-remove-button", Mt = "items-edit-button", $t = "items-close-button", Nt = "items-summary", Dt = "items-edit-panel", j = "items_removed[]", I = "data-items-removed";
class Pt 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(`.${kt}`), this._template = this.querySelector(`template.${Rt}`), this._addButton = this.querySelector(`.${Ot}`), !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(t) {
t.preventDefault(), this.addItem();
}
addItem() {
const t = this._template.content.cloneNode(!0), e = t.querySelector(`.${f}`);
if (!e) {
console.error("ItemsEditor: Template is missing a row element.");
return;
}
this._list.appendChild(t), this._captureOriginalValues(e), this._wireCancelButtons(e), this._wireRemoveButtons(e), this._wireEditButtons(e), this._assignRowFieldIds(e, this._rowIndex(e)), this._wireSummarySync(e), this._syncSummary(e), this._setRowMode(e, "edit");
}
removeItem(t) {
const e = t.closest(`.${f}`);
if (!e)
return;
const i = e.getAttribute(I) === "true";
this._setRowRemoved(e, !i);
}
_wireRemoveButtons(t = this) {
t.querySelectorAll(`.${$}`).forEach((e) => {
e.dataset.itemsBound !== "true" && (e.dataset.itemsBound = "true", e.addEventListener("click", (i) => {
i.preventDefault(), this.removeItem(e);
}), e.addEventListener("mouseenter", () => {
const i = e.closest(`.${f}`);
if (!i || i.getAttribute(I) !== "true")
return;
const s = e.querySelector("[data-delete-label]");
s && (s.textContent = s.getAttribute("data-delete-hover") || "Rückgängig");
const n = e.querySelector("i");
n && (n.classList.remove("hidden"), n.classList.add("ri-arrow-go-back-line"), n.classList.remove("ri-delete-bin-line"));
}), e.addEventListener("mouseleave", () => {
const i = e.closest(`.${f}`), s = e.querySelector("[data-delete-label]");
if (!s)
return;
i && i.getAttribute(I) === "true" ? s.textContent = s.getAttribute("data-delete-active") || "Wird entfernt" : s.textContent = s.getAttribute("data-delete-default") || "Entfernen";
const n = e.querySelector("i");
n && (i && i.getAttribute(I) === "true" ? (n.classList.add("hidden"), n.classList.remove("ri-delete-bin-line", "ri-arrow-go-back-line")) : (n.classList.remove("hidden"), n.classList.add("ri-delete-bin-line"), n.classList.remove("ri-arrow-go-back-line")));
}));
});
}
_wireCancelButtons(t = this) {
t.querySelectorAll(`.${Bt}`).forEach((e) => {
e.dataset.itemsBound !== "true" && (e.dataset.itemsBound = "true", e.addEventListener("click", (i) => {
i.preventDefault();
const s = e.closest(`.${f}`);
s && this._cancelEdit(s);
}));
});
}
_wireEditButtons(t = this) {
t.querySelectorAll(`.${Mt}`).forEach((e) => {
e.dataset.itemsBound !== "true" && (e.dataset.itemsBound = "true", e.addEventListener("click", (i) => {
i.preventDefault();
const s = e.closest(`.${f}`);
s && this._setRowMode(s, "edit");
}));
}), t.querySelectorAll(`.${$t}`).forEach((e) => {
e.dataset.itemsBound !== "true" && (e.dataset.itemsBound = "true", e.addEventListener("click", (i) => {
i.preventDefault();
const s = e.closest(`.${f}`);
s && this._setRowMode(s, "summary");
}));
});
}
_cancelEdit(t) {
const e = t.querySelector('input[name="items_id[]"]');
if (!(e ? e.value.trim() : "")) {
t.remove(), this._refreshRowIds();
return;
}
this._resetToOriginal(t), this._setRowMode(t, "summary");
}
_setRowRemoved(t, e) {
t.setAttribute(I, e ? "true" : "false"), t.classList.toggle("bg-red-50", e);
const i = t.querySelector(".items-edit-button");
i && (e ? i.classList.add("hidden") : i.classList.remove("hidden")), t.querySelectorAll("[data-delete-label]").forEach((a) => {
const r = a.closest(`.${$}`), o = r && r.matches(":hover");
let d;
e && o ? d = a.getAttribute("data-delete-hover") || "Rückgängig" : e ? d = a.getAttribute("data-delete-active") || "Wird entfernt" : d = a.getAttribute("data-delete-default") || "Entfernen", a.textContent = d;
}), t.querySelectorAll(`.${$} i`).forEach((a) => {
const r = a.closest(`.${$}`), o = r && r.matches(":hover");
e ? o ? (a.classList.remove("hidden"), a.classList.add("ri-arrow-go-back-line"), a.classList.remove("ri-delete-bin-line")) : (a.classList.add("hidden"), a.classList.remove("ri-delete-bin-line", "ri-arrow-go-back-line")) : (a.classList.remove("hidden"), a.classList.add("ri-delete-bin-line"), a.classList.remove("ri-arrow-go-back-line"));
});
const s = t.querySelector('input[name="items_id[]"]'), n = s ? s.value.trim() : "";
n && (e ? this._ensureRemovalInput(n) : this._removeRemovalInput(n)), t.querySelectorAll("[data-field]").forEach((a) => {
a.disabled = e;
});
}
_setRowMode(t, e) {
const i = t.querySelector(`.${Nt}`), s = t.querySelector(`.${Dt}`);
!i || !s || (e === "edit" ? (i.classList.add("hidden"), s.classList.remove("hidden")) : (i.classList.remove("hidden"), s.classList.add("hidden"), this._syncSummary(t)));
}
_captureAllOriginals() {
this.querySelectorAll(`.${f}`).forEach((t) => {
this._captureOriginalValues(t);
});
}
_captureOriginalValues(t) {
t.querySelectorAll("[data-field]").forEach((e) => {
e.dataset.originalValue === void 0 && (e.dataset.originalValue = e.value ?? "");
});
}
_resetToOriginal(t) {
t.querySelectorAll("[data-field]").forEach((e) => {
e.dataset.originalValue !== void 0 && (e.value = e.dataset.originalValue);
}), this._syncSummary(t);
}
_refreshRowIds() {
Array.from(this.querySelectorAll(`.${f}`)).forEach((e, i) => {
this._assignRowFieldIds(e, i);
});
}
_rowIndex(t) {
return Array.from(this.querySelectorAll(`.${f}`)).indexOf(t);
}
_assignRowFieldIds(t, e) {
e < 0 || t.querySelectorAll("[data-field-label]").forEach((i) => {
const s = i.getAttribute("data-field-label");
if (!s)
return;
const n = t.querySelector(`[data-field="${s}"]`);
if (!n)
return;
const a = `${this._idPrefix}-${e}-${s}`;
n.id = a, i.setAttribute("for", a);
});
}
_syncAllSummaries() {
this.querySelectorAll(`.${f}`).forEach((t) => {
this._wireSummarySync(t), this._syncSummary(t), this._syncNewBadge(t);
});
}
_wireSummarySync(t) {
t.dataset.summaryBound !== "true" && (t.dataset.summaryBound = "true", t.querySelectorAll("[data-field]").forEach((e) => {
e.addEventListener("input", () => this._syncSummary(t)), e.addEventListener("change", () => this._syncSummary(t));
}));
}
_syncSummary(t) {
t.querySelectorAll("[data-summary-field]").forEach((e) => {
const i = e.getAttribute("data-summary-field");
if (!i)
return;
const s = t.querySelector(`[data-field="${i}"]`);
if (!s)
return;
const n = this._readFieldValue(s), a = e.getAttribute("data-summary-hide-empty") === "true" ? e.closest("[data-summary-container]") : null;
n ? (this._setSummaryContent(e, n), e.classList.remove("text-gray-400"), a && a.classList.remove("hidden")) : (this._setSummaryContent(e, "—"), e.classList.add("text-gray-400"), a && a.classList.add("hidden"));
}), this._syncNewBadge(t);
}
_syncNewBadge(t) {
const e = t.querySelector('input[name="items_id[]"]'), i = e ? e.value.trim() : "";
t.querySelectorAll("[data-new-badge]").forEach((s) => {
s.classList.toggle("hidden", i !== "");
});
}
_setSummaryContent(t, e) {
const i = t.querySelector("[data-summary-link]");
i ? e && e !== "—" ? (i.setAttribute("href", e), i.textContent = e) : (i.setAttribute("href", "#"), i.textContent = "—") : t.textContent = e || "—";
}
_readFieldValue(t) {
if (t instanceof HTMLSelectElement) {
if (t.multiple)
return Array.from(t.selectedOptions).map((i) => i.textContent.trim()).filter(Boolean).join(", ");
const e = t.selectedOptions[0];
return e ? e.textContent.trim() : "";
}
return t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement ? t.value.trim() : "";
}
_ensureRemovalInput(t) {
if (Array.from(this.querySelectorAll(`input[name="${j}"]`)).some(
(s) => s.value === t
))
return;
const i = document.createElement("input");
i.type = "hidden", i.name = j, i.value = t, this.appendChild(i);
}
_removeRemovalInput(t) {
const e = Array.from(this.querySelectorAll(`input[name="${j}"]`));
for (const i of e)
i.value === t && i.remove();
}
}
const qt = "ssr-wrapper", Te = "ssr-input", we = "ssr-list", Ht = "ssr-option", Ft = "ssr-option-name", Vt = "ssr-option-detail", Ut = "ssr-option-bio", xe = "ssr-hidden-input", ke = "ssr-clear-button", J = 1, Q = 10, zt = 250;
class Kt extends HTMLElement {
constructor() {
super(), this._endpoint = "", this._resultKey = "items", this._minChars = J, this._limit = Q, this._placeholder = "Search...", this._options = [], this._selected = null, this._highlightedIndex = -1, 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(`.${Te}`), this._list = this.querySelector(`.${we}`), this._hiddenInput = this.querySelector(`.${xe}`), this._clearButton = this.querySelector(`.${ke}`), this._endpoint = this.getAttribute("data-endpoint") || "", this._resultKey = this.getAttribute("data-result-key") || "items", this._minChars = this._parsePositiveInt(this.getAttribute("data-minchars"), J), this._limit = this._parsePositiveInt(this.getAttribute("data-limit"), Q), 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(t, e, i) {
e !== i && (t === "data-endpoint" && (this._endpoint = i || ""), t === "data-result-key" && (this._resultKey = i || "items"), t === "data-minchars" && (this._minChars = this._parsePositiveInt(i, J)), t === "data-limit" && (this._limit = this._parsePositiveInt(i, Q)), t === "placeholder" && (this._placeholder = i || "Search...", this._input && (this._input.placeholder = this._placeholder)), t === "name" && this._hiddenInput && (this._hiddenInput.name = i || ""));
}
_handleInput(t) {
const e = t.target.value.trim();
if (this._selected = null, this._highlightedIndex = -1, this._syncHiddenInput(), e.length < this._minChars) {
this._options = [], this._renderOptions(), this._hideList();
return;
}
this._debouncedFetch(e);
}
_handleFocus() {
this._options.length > 0 && this._showList();
}
_handleKeyDown(t) {
if (t.key === "Escape") {
this._hideList();
return;
}
if (t.key === "ArrowDown") {
t.preventDefault(), this._moveHighlight(1);
return;
}
if (t.key === "ArrowUp") {
t.preventDefault(), this._moveHighlight(-1);
return;
}
if (t.key === "Home") {
t.preventDefault(), this._setHighlight(0);
return;
}
if (t.key === "End") {
t.preventDefault(), this._setHighlight(this._options.length - 1);
return;
}
if (t.key === "Enter") {
if (this._options.length === 0)
return;
t.preventDefault();
const e = this._highlightedIndex >= 0 ? this._highlightedIndex : 0;
this._selectOption(this._options[e]);
}
}
_handleClear(t) {
t.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(t) {
this.contains(t.target) || this._hideList();
}
_debouncedFetch(t) {
this._fetchTimeout && clearTimeout(this._fetchTimeout), this._fetchTimeout = setTimeout(() => {
this._fetchOptions(t);
}, zt);
}
async _fetchOptions(t) {
if (!this._endpoint)
return;
this._fetchController && this._fetchController.abort(), this.dispatchEvent(new CustomEvent("ssrbeforefetch", { bubbles: !0 })), this._fetchController = new AbortController();
const e = new URL(this._endpoint, window.location.origin);
e.searchParams.set("q", t), this._limit > 0 && e.searchParams.set("limit", String(this._limit));
try {
const i = await fetch(e.toString(), { signal: this._fetchController.signal });
if (!i.ok)
return;
const s = await i.json();
let a = (Array.isArray(s == null ? void 0 : s[this._resultKey]) ? s[this._resultKey] : []).filter((r) => r && r.id && r.name);
if (this._excludeIds && Array.isArray(this._excludeIds)) {
const r = new Set(this._excludeIds);
a = a.filter((o) => !r.has(o.id));
}
this._options = a, this._highlightedIndex = this._options.length > 0 ? 0 : -1, this._renderOptions(), this._options.length > 0 ? this._showList() : this._hideList();
} catch (i) {
if ((i == null ? void 0 : i.name) === "AbortError")
return;
}
}
_renderOptions() {
this._list && (this._list.innerHTML = "", this._options.forEach((t) => {
const e = document.createElement("button");
e.type = "button", e.setAttribute("data-index", String(this._options.indexOf(t))), e.className = [
Ht,
"w-full text-left px-3 py-2 hover:bg-slate-100 transition-colors"
].join(" ");
const s = this._options.indexOf(t) === this._highlightedIndex;
e.classList.toggle("bg-slate-100", s), e.classList.toggle("text-gray-900", s), e.setAttribute("aria-selected", s ? "true" : "false");
const n = document.createElement("div");
if (n.className = [Ft, "text-sm font-semibold text-gray-800"].join(" "), n.textContent = t.name, e.appendChild(n), t.detail) {
const a = document.createElement("div");
a.className = [Vt, "text-xs text-gray-600"].join(" "), a.textContent = t.detail, e.appendChild(a);
}
if (t.bio) {
const a = document.createElement("div");
a.className = [Ut, "text-xs text-gray-500"].join(" "), a.textContent = t.bio, e.appendChild(a);
}
e.addEventListener("click", () => {
this._selectOption(t);
}), this._list.appendChild(e);
}));
}
_setHighlight(t) {
if (this._options.length === 0) {
this._highlightedIndex = -1;
return;
}
const e = Math.max(0, Math.min(t, this._options.length - 1));
this._highlightedIndex = e, this._renderOptions(), this._scrollHighlightedIntoView(), this._showList();
}
_moveHighlight(t) {
if (this._options.length === 0) {
this._highlightedIndex = -1;
return;
}
const e = this._highlightedIndex >= 0 ? this._highlightedIndex : 0, i = Math.max(0, Math.min(e + t, this._options.length - 1));
this._highlightedIndex = i, this._renderOptions(), this._scrollHighlightedIntoView(), this._showList();
}
_scrollHighlightedIntoView() {
if (!this._list || this._highlightedIndex < 0)
return;
const t = this._list.querySelector(`[data-index="${this._highlightedIndex}"]`);
t && t.scrollIntoView({ block: "nearest" });
}
_selectOption(t) {
this._selected = t, this._input && (this._input.value = t.name || ""), this._syncHiddenInput(), this._hideList(), this.dispatchEvent(new CustomEvent("ssrchange", { bubbles: !0, detail: { item: t } })), this.dispatchEvent(new Event("change", { bubbles: !0 }));
}
_syncHiddenInput() {
var t;
this._hiddenInput && (this._hiddenInput.value = ((t = this._selected) == null ? void 0 : t.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(t, e) {
const i = parseInt(t || "", 10);
return Number.isNaN(i) || i <= 0 ? e : i;
}
_render() {
const t = this.getAttribute("name") || "";
this.innerHTML = `
`;
}
}
const Wt = "Bevorzugter Reihentitel";
class Gt extends HTMLElement {
constructor() {
super(), this._pendingAgent = null, this._form = null, this._saveButton = null, this._resetButton = null, this._deleteButton = null, this._deleteDialog = null, this._deleteConfirmButton = null, this._deleteCancelButton = null, this._statusEl = null, this._saveEndpoint = "", this._deleteEndpoint = "", this._isSaving = !1, this._handleSaveClick = this._handleSaveClick.bind(this), this._handleResetClick = this._handleResetClick.bind(this), this._handleDeleteClick = this._handleDeleteClick.bind(this), this._handleDeleteConfirmClick = this._handleDeleteConfirmClick.bind(this), this._handleDeleteCancelClick = this._handleDeleteCancelClick.bind(this);
}
connectedCallback() {
setTimeout(() => {
this._initForm(), this._initPlaces(), this._initSaveHandling();
}, 0);
}
disconnectedCallback() {
this._teardownSaveHandling();
}
_initForm() {
console.log("AlmanachEditPage: _initForm called");
const t = this.querySelector("#changealmanachform");
console.log("Form found:", !!t, "FormLoad exists:", typeof window.FormLoad == "function"), t && typeof window.FormLoad == "function" ? window.FormLoad(t) : console.error("Cannot initialize form - form or FormLoad missing");
}
_parseJSONAttr(t, e) {
if (!t)
return null;
const i = t.getAttribute(e);
if (!i)
return null;
try {
return JSON.parse(i);
} catch {
return null;
}
}
_initPlaces() {
var i;
const t = this.querySelector("#places");
if (!t)
return;
const e = () => {
const s = this._parseJSONAttr(t, "data-initial-options") || [], n = this._parseJSONAttr(t, "data-initial-values") || [];
s.length > 0 && typeof t.setOptions == "function" && t.setOptions(s), n.length > 0 && (t.value = n, typeof t.captureInitialSelection == "function" && t.captureInitialSelection());
};
if (typeof t.setOptions == "function") {
e();
return;
}
typeof ((i = window.customElements) == null ? void 0 : i.whenDefined) == "function" && window.customElements.whenDefined("multi-select-simple").then(() => {
requestAnimationFrame(() => e());
});
}
_initSaveHandling() {
this._teardownSaveHandling(), this._form = this.querySelector("#changealmanachform"), this._saveButton = this.querySelector("[data-role='almanach-save']"), this._resetButton = this.querySelector("[data-role='almanach-reset']"), this._deleteButton = this.querySelector("[data-role='almanach-delete']"), this._deleteDialog = this.querySelector("[data-role='almanach-delete-dialog']"), this._deleteConfirmButton = this.querySelector("[data-role='almanach-delete-confirm']"), this._deleteCancelButton = this.querySelector("[data-role='almanach-delete-cancel']"), this._statusEl = this.querySelector("#almanach-save-feedback"), !(!this._form || !this._saveButton) && (this._saveEndpoint = this._form.getAttribute("data-save-endpoint") || this._deriveSaveEndpoint(), this._deleteEndpoint = this._form.getAttribute("data-delete-endpoint") || "", this._saveButton.addEventListener("click", this._handleSaveClick), this._resetButton && this._resetButton.addEventListener("click", this._handleResetClick), this._deleteButton && this._deleteButton.addEventListener("click", this._handleDeleteClick), this._deleteConfirmButton && this._deleteConfirmButton.addEventListener("click", this._handleDeleteConfirmClick), this._deleteCancelButton && this._deleteCancelButton.addEventListener("click", this._handleDeleteCancelClick), this._deleteDialog && this._deleteDialog.addEventListener("cancel", this._handleDeleteCancelClick));
}
_teardownSaveHandling() {
this._saveButton && this._saveButton.removeEventListener("click", this._handleSaveClick), this._resetButton && this._resetButton.removeEventListener("click", this._handleResetClick), this._deleteButton && this._deleteButton.removeEventListener("click", this._handleDeleteClick), this._deleteConfirmButton && this._deleteConfirmButton.removeEventListener("click", this._handleDeleteConfirmClick), this._deleteCancelButton && this._deleteCancelButton.removeEventListener("click", this._handleDeleteCancelClick), this._deleteDialog && this._deleteDialog.removeEventListener("cancel", this._handleDeleteCancelClick), this._saveButton = null, this._resetButton = null, this._deleteButton = null, this._deleteDialog = null, this._deleteConfirmButton = null, this._deleteCancelButton = null, this._statusEl = null;
}
_deriveSaveEndpoint() {
var e;
return (e = window == null ? void 0 : window.location) != null && e.pathname ? `${window.location.pathname.endsWith("/") ? window.location.pathname.slice(0, -1) : window.location.pathname}/save` : "/almanach/save";
}
async _handleSaveClick(t) {
if (t.preventDefault(), this._isSaving)
return;
this._clearStatus();
let e;
try {
e = this._buildPayload();
} catch (i) {
this._showStatus(i instanceof Error ? i.message : String(i), "error");
return;
}
this._setSavingState(!0);
try {
const i = await fetch(this._saveEndpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json"
},
body: JSON.stringify(e)
});
let s = null;
try {
s = await i.clone().json();
} catch {
s = null;
}
if (!i.ok) {
const n = (s == null ? void 0 : s.error) || `Speichern fehlgeschlagen (${i.status}).`;
throw new Error(n);
}
if (s != null && s.redirect) {
window.location.assign(s.redirect);
return;
}
await this._reloadForm((s == null ? void 0 : s.message) || "Änderungen gespeichert."), this._clearStatus();
} catch (i) {
this._showStatus(i instanceof Error ? i.message : "Speichern fehlgeschlagen.", "error");
} finally {
this._setSavingState(!1);
}
}
async _handleResetClick(t) {
if (t.preventDefault(), !this._isSaving) {
this._clearStatus();
try {
await this._reloadForm("");
} catch (e) {
this._showStatus(e instanceof Error ? e.message : "Formular konnte nicht aktualisiert werden.", "error");
}
}
}
async _handleDeleteClick(t) {
t.preventDefault(), !this._isSaving && this._deleteDialog && typeof this._deleteDialog.showModal == "function" && this._deleteDialog.showModal();
}
_handleDeleteCancelClick(t) {
t && t.preventDefault(), this._deleteDialog && this._deleteDialog.open && this._deleteDialog.close();
}
async _handleDeleteConfirmClick(t) {
if (t.preventDefault(), !(!this._form || !this._deleteEndpoint || this._isSaving)) {
this._deleteDialog && this._deleteDialog.open && this._deleteDialog.close(), this._clearStatus(), this._setSavingState(!0);
try {
const e = new FormData(this._form), i = {
csrf_token: this._readValue(e, "csrf_token"),
last_edited: this._readValue(e, "last_edited")
}, s = await fetch(this._deleteEndpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json"
},
body: JSON.stringify(i)
});
let n = null;
try {
n = await s.clone().json();
} catch {
n = null;
}
if (!s.ok) {
const r = (n == null ? void 0 : n.error) || `Löschen fehlgeschlagen (${s.status}).`;
throw new Error(r);
}
const a = (n == null ? void 0 : n.redirect) || "/suche/baende";
window.location.assign(a);
} catch (e) {
this._showStatus(e instanceof Error ? e.message : "Löschen fehlgeschlagen.", "error");
} finally {
this._setSavingState(!1);
}
}
}
_buildPayload() {
if (!this._form)
throw new Error("Formular konnte nicht gefunden werden.");
const t = new FormData(this._form), e = {
preferred_title: this._readValue(t, "preferred_title"),
title: this._readValue(t, "title"),
parallel_title: this._readValue(t, "paralleltitle"),
subtitle: this._readValue(t, "subtitle"),
variant_title: this._readValue(t, "varianttitle"),
incipit: this._readValue(t, "incipit"),
responsibility_statement: this._readValue(t, "responsibility_statement"),
publication_statement: this._readValue(t, "publication_statement"),
place_statement: this._readValue(t, "place_statement"),
edition: this._readValue(t, "edition"),
annotation: this._readValue(t, "annotation"),
edit_comment: this._readValue(t, "edit_comment"),
extent: this._readValue(t, "extent"),
dimensions: this._readValue(t, "dimensions"),
references: this._readValue(t, "refs"),
status: this._readValue(t, "type")
};
if (!e.preferred_title)
throw new Error("Kurztitel ist erforderlich.");
const i = this._readValue(t, "year");
if (i === "")
throw new Error("Jahr muss angegeben werden (0 ist erlaubt).");
const s = Number.parseInt(i, 10);
if (Number.isNaN(s))
throw new Error("Jahr ist ungültig.");
e.year = s;
const n = t.getAll("languages[]").map((g) => g.trim()).filter(Boolean), a = t.getAll("places[]").map((g) => g.trim()).filter(Boolean), { items: r, removedIds: o } = this._collectItems(t), {
relations: d,
deleted: c
} = this._collectRelations(t, {
prefix: "entries_series",
targetField: "series"
}), h = this._collectNewRelations("entries_series"), u = [...d, ...h].filter(
(g) => g.type === Wt
).length;
if (u === 0)
throw new Error("Mindestens ein bevorzugter Reihentitel muss verknüpft sein.");
if (u > 1)
throw new Error("Es darf nur ein bevorzugter Reihentitel gesetzt sein.");
const {
relations: m,
deleted: _
} = this._collectRelations(t, {
prefix: "entries_agents",
targetField: "agent"
}), S = this._collectNewRelations("entries_agents"), L = [...d, ...h].map((g) => g.target_id);
if (L.filter((g, De) => L.indexOf(g) !== De).length > 0)
throw new Error("Doppelte Reihenverknüpfungen sind nicht erlaubt.");
return {
csrf_token: this._readValue(t, "csrf_token"),
last_edited: this._readValue(t, "last_edited"),
entry: e,
languages: n,
places: a,
items: r,
deleted_item_ids: o,
series_relations: d,
new_series_relations: h,
deleted_series_relation_ids: c,
agent_relations: m,
new_agent_relations: S,
deleted_agent_relation_ids: _
};
}
_collectItems(t) {
const e = t.getAll("items_id[]").map((h) => h.trim()), i = t.getAll("items_owner[]"), s = t.getAll("items_identifier[]"), n = t.getAll("items_location[]"), a = t.getAll("items_media[]"), r = t.getAll("items_annotation[]"), o = t.getAll("items_uri[]"), d = new Set(
t.getAll("items_removed[]").map((h) => h.trim()).filter(Boolean)
), c = [];
for (let h = 0; h < e.length; h += 1) {
const u = e[h] || "";
if (u && d.has(u))
continue;
const m = (i[h] || "").trim(), _ = (s[h] || "").trim(), S = (n[h] || "").trim(), P = (r[h] || "").trim(), L = (o[h] || "").trim(), x = (a[h] || "").trim();
(u || m || _ || S || P || L || x) && c.push({
id: u,
owner: m,
identifier: _,
location: S,
annotation: P,
uri: L,
media: x ? [x] : []
});
}
return {
items: c,
removedIds: Array.from(d)
};
}
_collectRelations(t, { prefix: e, targetField: i }) {
const s = [], n = [];
for (const [a, r] of t.entries()) {
if (!a.startsWith(`${e}_id[`))
continue;
const o = a.slice(a.indexOf("[") + 1, -1), d = `${e}_${i}[${o}]`, c = `${e}_type[${o}]`, h = `${e}_delete[${o}]`, u = `${e}_uncertain[${o}]`, m = (r || "").trim(), _ = (t.get(d) || "").trim();
if (!_ || !m)
continue;
if (t.has(h)) {
n.push(m);
continue;
}
const S = (t.get(c) || "").trim();
s.push({
id: m,
target_id: _,
type: S,
uncertain: t.has(u)
});
}
return { relations: s, deleted: n };
}
_collectNewRelations(t) {
const e = this.querySelector(`relations-editor[data-prefix='${t}']`);
if (!e)
return [];
const i = e.querySelectorAll("[data-role='relation-add-row'] [data-rel-row]"), s = [];
return i.forEach((n) => {
const a = n.querySelector(`input[name='${t}_new_id']`), r = n.querySelector(`select[name='${t}_new_type']`), o = n.querySelector(`input[name='${t}_new_uncertain']`);
if (!a)
return;
const d = a.value.trim();
d && s.push({
target_id: d,
type: ((r == null ? void 0 : r.value) || "").trim(),
uncertain: !!(o != null && o.checked)
});
}), s;
}
_readValue(t, e) {
const i = t.get(e);
return i ? String(i).trim() : "";
}
_setSavingState(t) {
if (this._isSaving = t, !this._saveButton)
return;
this._saveButton.disabled = t;
const e = this._saveButton.querySelector("span");
e && (e.textContent = t ? "Speichern..." : "Speichern"), this._resetButton && (this._resetButton.disabled = t), this._deleteButton && (this._deleteButton.disabled = t);
}
_clearStatus() {
this._statusEl && (this._statusEl.textContent = "", this._statusEl.classList.remove("text-red-700", "text-green-700"));
}
_showStatus(t, e) {
this._statusEl && (this._clearStatus(), this._statusEl.textContent = t, e === "success" ? this._statusEl.classList.add("text-green-700") : e === "error" && this._statusEl.classList.add("text-red-700"));
}
async _reloadForm(t) {
this._teardownSaveHandling();
const e = new URL(window.location.href);
t ? e.searchParams.set("saved_message", t) : e.searchParams.delete("saved_message");
const i = await fetch(e.toString(), {
headers: {
"X-Requested-With": "fetch"
}
});
if (!i.ok)
throw new Error("Formular konnte nicht aktualisiert werden.");
const s = await i.text(), a = new DOMParser().parseFromString(s, "text/html"), r = a.querySelector("#changealmanachform"), o = this.querySelector("#changealmanachform");
if (!r || !o)
throw new Error("Formular konnte nicht geladen werden.");
o.replaceWith(r), this._form = r;
const d = a.querySelector("#user-message"), c = this.querySelector("#user-message");
d && c && c.replaceWith(d);
const h = a.querySelector("#almanach-header-data"), u = this.querySelector("#almanach-header-data");
h && u && u.replaceWith(h), this._initForm(), this._initPlaces(), this._initSaveHandling(), typeof window.TextareaAutoResize == "function" && setTimeout(() => {
this.querySelectorAll("textarea").forEach((m) => {
window.TextareaAutoResize(m);
});
}, 100);
}
}
const jt = "[data-role='relation-add-toggle']", Jt = "[data-role='relation-add-panel']", Qt = "[data-role='relation-add-close']", Xt = "[data-role='relation-add-apply']", Yt = "[data-role='relation-add-error']", Zt = "[data-role='relation-add-row']", ei = "[data-role='relation-add-select']", ti = "[data-role='relation-type-select']", ii = "[data-role='relation-uncertain']", si = "template[data-role='relation-new-template']", ni = "[data-role='relation-new-delete']", C = "[data-rel-row]";
class ai extends HTMLElement {
constructor() {
super(), this._pendingItem = null, this._pendingApply = !1;
}
connectedCallback() {
this._prefix = this.getAttribute("data-prefix") || "", this._linkBase = this.getAttribute("data-link-base") || "", this._newLabel = this.getAttribute("data-new-label") || "(Neu)", this._addToggleId = this.getAttribute("data-add-toggle-id") || "", this._preferredLabel = (this.getAttribute("data-preferred-label") || "").trim(), this._emptyText = this.querySelector(".rel-empty-text"), this._setupAddPanel(), this._setupDeleteToggles(), this._setupPreferredOptionHandling();
}
_getExistingIds() {
const t = /* @__PURE__ */ new Set(), e = this._prefix === "entries_series" ? "series" : "agent";
return this.querySelectorAll(`input[name^="${this._prefix}_${e}["]`).forEach((i) => {
const s = i.value.trim();
s && t.add(s);
}), this._addRow && this._addRow.querySelectorAll(`input[name="${this._prefix}_new_id"]`).forEach((i) => {
const s = i.value.trim();
s && t.add(s);
}), t;
}
_updateEmptyTextVisibility() {
if (!this._emptyText)
return;
const t = this._prefix === "entries_series" ? "series" : "agent", e = this.querySelectorAll(`input[name^="${this._prefix}_${t}["]`).length > 0, i = this._addRow && this._addRow.querySelectorAll(`input[name="${this._prefix}_new_id"]`).length > 0;
this._addPanel && !this._addPanel.classList.contains("hidden") || e || i ? this._emptyText.classList.add("hidden") : this._emptyText.classList.remove("hidden");
}
_setupAddPanel() {
if (this._addToggle = this.querySelector(jt), this._addToggleId) {
const t = document.getElementById(this._addToggleId);
t && (this._addToggle = t);
}
this._addPanel = this.querySelector(Jt), this._addClose = this.querySelector(Qt), this._addApply = this.querySelector(Xt), this._addError = this.querySelector(Yt), this._addRow = this.querySelector(Zt), this._addSelect = this.querySelector(ei), this._typeSelect = this.querySelector(ti), this._uncertain = this.querySelector(ii), this._template = this.querySelector(si), this._addInput = this._addSelect ? this._addSelect.querySelector(".ssr-input") : null, !(!this._addPanel || !this._addRow || !this._addSelect || !this._typeSelect || !this._uncertain || !this._template) && (this._addSelect && this._prefix === "entries_series" && this._addSelect.addEventListener("ssrbeforefetch", () => {
this._addSelect._excludeIds = Array.from(this._getExistingIds());
}), this._addToggle && this._addToggle.addEventListener("click", () => {
this._addPanel.classList.toggle("hidden"), this._updateEmptyTextVisibility();
}), this._addClose && this._addClose.addEventListener("click", () => {
this._addPanel.classList.add("hidden"), this._updateEmptyTextVisibility();
}), this._addInput && this._addInput.addEventListener("keydown", (t) => {
t.key === "Enter" && (this._pendingApply = !0);
}), this._addApply && this._addApply.addEventListener("click", () => {
this._pendingApply = !1;
const t = this._addPanel.querySelector(`input[name='${this._prefix}_new_id']`);
if (!(t && t.value.trim().length > 0)) {
this._addError && (this._addError.textContent = this._addError.getAttribute("data-error-empty") || "Bitte Reihe auswählen.", this._addError.classList.remove("hidden"));
return;
}
if (this._pendingItem) {
if (this._prefix === "entries_series" && this._getExistingIds().has(this._pendingItem.id)) {
this._addError && (this._addError.textContent = this._addError.getAttribute("data-error-duplicate") || "Diese Verknüpfung existiert bereits.", this._addError.classList.remove("hidden"));
return;
}
this._addError && this._addError.classList.add("hidden"), this._insertNewRow();
}
}), this._addSelect.addEventListener("ssrchange", (t) => {
var e;
this._pendingItem = ((e = t.detail) == null ? void 0 : e.item) || null, this._pendingItem && this._addError && this._addError.classList.add("hidden"), this._pendingApply && this._pendingItem && this._addApply && (this._pendingApply = !1, this._addApply.click());
}));
}
_clearAddPanel() {
if (this._addSelect) {
const t = this._addSelect.querySelector(".ssr-clear-button");
t && t.click();
}
this._typeSelect && (this._typeSelect.selectedIndex = 0), this._uncertain && (this._uncertain.checked = !1), this._addError && this._addError.classList.add("hidden");
}
_insertNewRow() {
const t = this._template.content.cloneNode(!0);
if (!(t.querySelector(C) || t.firstElementChild))
return;
const i = t.querySelector("[data-rel-link]");
i && i.setAttribute("href", `${this._linkBase}${this._pendingItem.id}`);
const s = t.querySelector("[data-rel-name]");
s && (s.textContent = this._pendingItem.name || "");
const n = t.querySelector("[data-rel-detail]"), a = t.querySelector("[data-rel-detail-container]"), r = this._pendingItem.detail || this._pendingItem.bio || "";
n && r ? n.textContent = r : a && a.remove();
const o = t.querySelector("[data-rel-new]");
o && (o.textContent = this._newLabel);
const d = t.querySelector("[data-rel-input='type']");
d && this._typeSelect && (d.innerHTML = this._typeSelect.innerHTML, d.value = this._typeSelect.value, d.name = `${this._prefix}_new_type`, d.addEventListener("change", () => this._updatePreferredOptions()));
const c = t.querySelector("[data-rel-input='uncertain']");
if (c && this._uncertain) {
c.checked = this._uncertain.checked, c.name = `${this._prefix}_new_uncertain`;
const m = `${this._prefix}_new_uncertain_row`;
c.id = m;
const _ = t.querySelector("[data-rel-uncertain-label]");
_ && _.setAttribute("for", m);
}
const h = t.querySelector("[data-rel-input='id']");
h && (h.name = `${this._prefix}_new_id`, h.value = this._pendingItem.id);
const u = t.querySelector(ni);
u && u.addEventListener("click", () => {
this._addRow.innerHTML = "", this._pendingItem = null, this._clearAddPanel(), this._addPanel && this._addPanel.classList.add("hidden"), this._updateEmptyTextVisibility();
}), this._addRow.innerHTML = "", this._addRow.appendChild(t), this._pendingItem = null, this._clearAddPanel(), this._addPanel && this._addPanel.classList.add("hidden"), this._updateEmptyTextVisibility(), this._updatePreferredOptions();
}
_setupDeleteToggles() {
this.querySelectorAll("[data-delete-toggle]").forEach((t) => {
t.addEventListener("click", () => {
const e = t.getAttribute("data-delete-toggle"), i = this.querySelector(`#${CSS.escape(e)}`);
if (!i)
return;
i.checked = !i.checked;
const s = t.closest(C);
s && (s.classList.toggle("bg-red-50", i.checked), s.querySelectorAll("select, input[type='checkbox']").forEach((o) => {
o !== i && (o.disabled = i.checked);
}));
const n = t.matches(":hover"), a = t.querySelector("[data-delete-label]");
if (a) {
let o;
i.checked && n ? o = a.getAttribute("data-delete-hover") || "Rückgängig" : i.checked ? o = a.getAttribute("data-delete-active") || "Wird entfernt" : o = a.getAttribute("data-delete-default") || "Entfernen", a.textContent = o;
}
const r = t.querySelector("i");
r && (i.checked ? n ? (r.classList.remove("hidden"), r.classList.add("ri-arrow-go-back-line"), r.classList.remove("ri-delete-bin-line")) : (r.classList.add("hidden"), r.classList.remove("ri-delete-bin-line", "ri-arrow-go-back-line")) : (r.classList.remove("hidden"), r.classList.add("ri-delete-bin-line"), r.classList.remove("ri-arrow-go-back-line"))), this._updatePreferredOptions();
}), t.addEventListener("mouseenter", () => {
const e = t.getAttribute("data-delete-toggle"), i = this.querySelector(`#${CSS.escape(e)}`);
if (!i || !i.checked)
return;
const s = t.querySelector("[data-delete-label]");
s && (s.textContent = s.getAttribute("data-delete-hover") || "Rückgängig");
const n = t.querySelector("i");
n && (n.classList.remove("hidden"), n.classList.add("ri-arrow-go-back-line"), n.classList.remove("ri-delete-bin-line"));
}), t.addEventListener("mouseleave", () => {
const e = t.getAttribute("data-delete-toggle"), i = this.querySelector(`#${CSS.escape(e)}`), s = t.querySelector("[data-delete-label]");
if (!s)
return;
i && i.checked ? s.textContent = s.getAttribute("data-delete-active") || "Wird entfernt" : s.textContent = s.getAttribute("data-delete-default") || "Entfernen";
const n = t.querySelector("i");
n && (i && i.checked ? (n.classList.add("hidden"), n.classList.remove("ri-delete-bin-line", "ri-arrow-go-back-line")) : (n.classList.remove("hidden"), n.classList.add("ri-delete-bin-line"), n.classList.remove("ri-arrow-go-back-line")));
});
});
}
_setupPreferredOptionHandling() {
this._prefix !== "entries_series" || !this._preferredLabel || (this.querySelectorAll(`select[name^="${this._prefix}_type["]`).forEach((t) => {
t.addEventListener("change", () => this._updatePreferredOptions());
}), this._typeSelect && this._typeSelect.addEventListener("change", () => this._updatePreferredOptions()), this._updatePreferredOptions());
}
_updatePreferredOptions() {
if (this._prefix !== "entries_series" || !this._preferredLabel)
return;
const t = this._preferredLabel.trim(), e = [];
this.querySelectorAll(`select[name^="${this._prefix}_type["]`).forEach((s) => {
e.push({ select: s, row: s.closest(C), isAddPanel: !1 });
}), this._addRow && this._addRow.querySelectorAll(`select[name='${this._prefix}_new_type']`).forEach((s) => {
e.push({ select: s, row: s.closest(C), isAddPanel: !1 });
}), this._typeSelect && e.push({ select: this._typeSelect, row: this._typeSelect.closest(C), isAddPanel: !0 });
const i = e.some(({ select: s, row: n, isAddPanel: a }) => {
if (a)
return !1;
const r = ((s == null ? void 0 : s.value) || "").trim();
if (!s || r !== t)
return !1;
if (!n)
return !0;
const o = n.querySelector(`input[name^="${this._prefix}_delete["]`);
return !(o && o.checked);
});
e.forEach(({ select: s, row: n, isAddPanel: a }) => {
if (!s)
return;
const r = Array.from(s.options).find((m) => m.value.trim() === t);
if (!r)
return;
const o = n ? n.querySelector(`input[name^="${this._prefix}_delete["]`) : null, d = !!(o && o.checked), c = (s.value || "").trim(), h = !i || c === t && !d;
if (a && i && c === t) {
const m = Array.from(s.options).find((_) => _.value.trim() !== t);
m && (s.value = m.value);
}
const u = !h || a && i;
r.hidden = u, r.disabled = u, r.style.display = u ? "none" : "";
});
}
}
class li extends HTMLElement {
connectedCallback() {
setTimeout(() => {
const t = this.querySelector("form");
t && typeof window.FormLoad == "function" && window.FormLoad(t), this._setupDelete();
}, 0);
}
_setupDelete() {
const t = this.querySelector("form");
if (!t)
return;
const e = t.getAttribute("data-delete-endpoint");
if (!e)
return;
const i = this.querySelector("[data-role='edit-delete-dialog']"), s = this.querySelector("[data-role='edit-delete']"), n = this.querySelector("[data-role='edit-delete-confirm']"), a = this.querySelector("[data-role='edit-delete-cancel']");
if (!i || !s || !n || !a)
return;
s.addEventListener("click", (o) => {
o.preventDefault(), typeof i.showModal == "function" && i.showModal();
});
const r = (o) => {
o && o.preventDefault(), i.open && i.close();
};
a.addEventListener("click", r), i.addEventListener("cancel", r), n.addEventListener("click", async (o) => {
o.preventDefault(), r();
const d = new FormData(t), c = {
csrf_token: d.get("csrf_token") || "",
last_edited: d.get("last_edited") || ""
}, h = await fetch(e, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json"
},
body: JSON.stringify(c)
});
if (!h.ok)
return;
const u = await h.json().catch(() => null), m = (u == null ? void 0 : u.redirect) || "/";
window.location.assign(m);
});
}
}
const ri = "filter-list", oi = "scroll-button", di = "tool-tip", hi = "abbrev-tooltips", ci = "int-link", ui = "popup-image", mi = "tab-list", _i = "filter-pill", pi = "image-reel", fi = "multi-select-places", gi = "multi-select-simple", bi = "single-select-remote", Me = "reset-button", Ei = "div-manager", Si = "items-editor", vi = "almanach-edit-page", Li = "relations-editor", yi = "edit-page";
customElements.define(ci, je);
customElements.define(hi, T);
customElements.define(ri, Ue);
customElements.define(oi, ze);
customElements.define(di, Ke);
customElements.define(ui, We);
customElements.define(mi, Ge);
customElements.define(_i, He);
customElements.define(pi, Je);
customElements.define(fi, Re);
customElements.define(gi, Oe);
customElements.define(bi, Kt);
customElements.define(Me, It);
customElements.define(Ei, xt);
customElements.define(Si, Pt);
customElements.define(vi, Gt);
customElements.define(Li, ai);
customElements.define(yi, li);
function Ai() {
const l = window.location.pathname, t = window.location.search, e = l + t;
return encodeURIComponent(e);
}
function Ii(l = 5e3, t = 100) {
return new Promise((e, i) => {
let s = 0;
const n = setInterval(() => {
typeof window.QRCode == "function" ? (clearInterval(n), e(window.QRCode)) : (s += t, s >= l && (clearInterval(n), console.error("Timed out waiting for QRCode to become available."), i(new Error("QRCode not available after " + l + "ms. Check if qrcode.min.js is loaded correctly and sets window.QRCode."))));
}, t);
});
}
async function Ci(l) {
const t = await Ii(), e = document.getElementById("qr");
e && (e.innerHTML = "", e.classList.add("hidden"), new t(e, {
text: l,
width: 1280,
height: 1280,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: t.CorrectLevel.H
}), setTimeout(() => {
e.classList.remove("hidden");
}, 20));
}
function Ti(l) {
l && (l.addEventListener("focus", (t) => {
t.preventDefault(), l.select();
}), l.addEventListener("mousedown", (t) => {
t.preventDefault(), l.select();
}), l.addEventListener("mouseup", (t) => {
t.preventDefault(), l.select();
})), l && (l.addEventListener("focus", () => {
l.select();
}), l.addEventListener("click", () => {
l.select();
}));
}
function wi() {
document.body.addEventListener("htmx:responseError", function(l) {
const t = l.detail.requestConfig;
if (t.boosted) {
document.body.innerHTML = l.detail.xhr.responseText;
const e = l.detail.xhr.responseURL || t.url;
window.history.pushState(null, "", e);
}
});
}
function xi(l, t) {
if (!(l instanceof HTMLElement)) {
console.warn("Target must be an HTMLElement.");
return;
}
if (typeof t != "function") {
console.warn("Action must be a function.");
return;
}
const e = l.querySelectorAll(Me);
l.addEventListener("rbichange", (i) => {
for (const s of e)
if (s.isCurrentlyModified()) {
t(i.details, !0);
return;
}
t(i.details, !1);
});
}
let v = null;
function $e() {
return v !== null || (typeof CSS < "u" && typeof CSS.supports == "function" ? v = CSS.supports("field-sizing", "content") : v = !1, console.log("Browser supports field-sizing:", v)), v;
}
function E(l) {
if (console.log("TextareaAutoResize called for:", l.name || l.id), !(l instanceof HTMLTextAreaElement)) {
console.log("Not a textarea element");
return;
}
if (l.offsetParent === null) {
console.log("Textarea not visible");
return;
}
l.removeAttribute("rows"), l.style.overflow = "auto";
const e = l.name === "annotation" ? 76 : 38;
if (l.value.trim() === "") {
l.style.height = e + "px", console.log("Empty textarea, setting height to:", e + "px");
return;
}
l.style.height = "1px";
const i = l.scrollHeight, s = Math.max(i, e) + "px";
console.log("Setting height to:", s), l.style.height = s;
}
function Ne(l) {
l.key === "Enter" && l.preventDefault();
}
function ki(l) {
if (!(l instanceof HTMLTextAreaElement)) {
console.warn("HookupTextareaAutoResize: Provided element is not a textarea.");
return;
}
$e() || l.addEventListener("input", () => {
E(l);
});
}
function Ri(l) {
if (!(l instanceof HTMLTextAreaElement)) {
console.warn("DisconnectTextareaAutoResize: Provided element is not a textarea.");
return;
}
l.removeEventListener("input", () => {
E(l);
});
}
function Oi(l) {
!(l instanceof HTMLTextAreaElement) && l.classList.contains("no-enter") || l.addEventListener("keydown", Ne);
}
function Bi(l) {
!(l instanceof HTMLTextAreaElement) && l.classList.contains("no-enter") || l.removeEventListener("keydown", Ne);
}
function Mi(l, t) {
const e = !$e();
for (const i of l)
if (i.type === "childList") {
for (const s of i.addedNodes)
s.nodeType === Node.ELEMENT_NODE && s.matches("textarea") && e && (ki(s), E(s));
for (const s of i.removedNodes)
s.nodeType === Node.ELEMENT_NODE && s.matches("textarea") && (Bi(s), e && Ri(s));
}
}
function $i(l) {
if (console.log("=== FormLoad CALLED ==="), !(l instanceof HTMLFormElement)) {
console.warn("FormLoad: Provided element is not a form.");
return;
}
const t = document.querySelectorAll("textarea");
console.log("Found", t.length, "textareas");
for (const n of t)
console.log("Attaching input listener to:", n.name || n.id), n.addEventListener("input", function() {
console.log("Input event on textarea:", this.name || this.id), E(this);
});
setTimeout(() => {
console.log("Running initial textarea resize on", t.length, "textareas");
for (const n of t)
E(n);
}, 200);
const e = document.querySelectorAll("textarea.no-enter");
for (const n of e)
Oi(n);
new MutationObserver(Mi).observe(l, {
childList: !0,
subtree: !0
}), new MutationObserver((n) => {
for (const a of n)
if (a.type === "attributes" && a.attributeName === "class") {
const r = a.target;
if (r instanceof HTMLElement) {
const o = r.matches("textarea") ? [r] : Array.from(r.querySelectorAll("textarea"));
for (const d of o)
d.offsetParent !== null && E(d);
}
}
}).observe(l, {
attributes: !0,
attributeFilter: ["class"],
subtree: !0
});
}
document.addEventListener("keydown", (l) => {
if (l.key !== "Enter")
return;
const t = l.target;
t instanceof HTMLElement && t.matches("textarea.no-enter") && l.preventDefault();
});
window.ShowBoostedErrors = wi;
window.GenQRCode = Ci;
window.SelectableInput = Ti;
window.PathPlusQuery = Ai;
window.HookupRBChange = xi;
window.FormLoad = $i;
window.TextareaAutoResize = E;
export {
T as AbbreviationTooltips,
Gt as AlmanachEditPage,
li as EditPage,
Ue as FilterList,
He as FilterPill,
Je as ImageReel,
je as IntLink,
Pt as ItemsEditor,
Re as MultiSelectRole,
Oe as MultiSelectSimple,
We as PopupImage,
ai as RelationsEditor,
ze as ScrollButton,
Kt as SingleSelectRemote,
Ge as TabList,
Ke as ToolTip
};