import { $ as e, F as t, H as n, N as r, S as i, U as a, _ as o, at as s, ct as c, d as l, g as u, h as d, k as f, l as p, lt as m, m as h, p as g, r as _, s as v, st as y, u as b, w as x } from "./draggable-Bcb86AsV.js";
import { Mt as S, Z as C, fn as w, mn as T, pn as E, un as D } from "./features-BnG-dhzy.js";
import { _ as O, g as k, h as A, n as j, r as M, t as N, v as P, y as F } from "./tiptap-CPAwPMop.js";
//#region src/extensions/FontSize.ts
var I = A.create({
	name: "fontSize",
	addOptions() {
		return { types: ["textStyle"] };
	},
	addGlobalAttributes() {
		return [{
			types: this.options.types,
			attributes: { fontSize: {
				default: null,
				parseHTML: (e) => e.style.fontSize?.replace(/['"]+/g, "") || null,
				renderHTML: (e) => e.fontSize ? { style: `font-size: ${e.fontSize}` } : {}
			} }
		}];
	},
	addCommands() {
		return {
			setFontSize: (e) => ({ chain: t }) => t().setMark("textStyle", { fontSize: e }).run(),
			unsetFontSize: () => ({ chain: e }) => e().setMark("textStyle", { fontSize: null }).removeEmptyTextStyle().run()
		};
	}
}), L = A.create({
	name: "letterSpacing",
	addOptions() {
		return { types: ["textStyle"] };
	},
	addGlobalAttributes() {
		return [{
			types: this.options.types,
			attributes: { letterSpacing: {
				default: null,
				parseHTML: (e) => e.style.letterSpacing?.replace(/['"]+/g, "") || null,
				renderHTML: (e) => e.letterSpacing ? { style: `letter-spacing: ${e.letterSpacing}` } : {}
			} }
		}];
	},
	addCommands() {
		return {
			setLetterSpacing: (e) => ({ chain: t }) => t().setMark("textStyle", { letterSpacing: e }).run(),
			unsetLetterSpacing: () => ({ chain: e }) => e().setMark("textStyle", { letterSpacing: null }).removeEmptyTextStyle().run()
		};
	}
}), R = A.create({
	name: "lineHeight",
	addOptions() {
		return {
			types: ["paragraph"],
			defaultLineHeight: "1.5"
		};
	},
	addGlobalAttributes() {
		return [{
			types: this.options.types,
			attributes: { lineHeight: {
				default: null,
				parseHTML: (e) => e.style.lineHeight || null,
				renderHTML: (e) => e.lineHeight ? { style: `line-height: ${e.lineHeight}` } : {}
			} }
		}];
	},
	addCommands() {
		return {
			setLineHeight: (e) => ({ commands: t }) => this.options.types.every((n) => t.updateAttributes(n, { lineHeight: e })),
			unsetLineHeight: () => ({ commands: e }) => this.options.types.every((t) => e.resetAttributes(t, "lineHeight"))
		};
	}
}), ee = [
	"aria-label",
	"data-tooltip",
	"onKeydown"
], te = ["aria-label", "onKeydown"], ne = ["aria-label"], z = /* @__PURE__ */ i({
	__name: "LogicMergeTagNodeView",
	props: {
		node: {},
		editor: {},
		getPos: { type: Function },
		deleteNode: { type: Function },
		updateAttributes: { type: Function }
	},
	setup(t) {
		let i = t, { syntax: l } = C(), { t: _ } = S(), x = g(() => T(i.node.attrs.value, l)), E = g(() => w(i.node.attrs.value, l)), D = e(!1), O = e(""), k = e(null), A = !1;
		function M() {
			O.value = i.node.attrs.value, A = !1, D.value = !0, f(() => {
				k.value?.focus(), k.value?.select();
			});
		}
		function N() {
			if (A) return;
			A = !0;
			let e = O.value.trim();
			if (!e) {
				D.value = !1;
				return;
			}
			e !== i.node.attrs.value && i.updateAttributes({
				value: e,
				keyword: T(e, l) ? w(e, l) : ""
			}), D.value = !1;
		}
		function P(e) {
			e.key === "Enter" ? (e.preventDefault(), N()) : e.key === "Escape" && (D.value = !1);
		}
		return (e, i) => (r(), d(s(j), {
			as: "span",
			class: y(x.value ? "tpl-logic-merge-tag-node tpl:group tpl:mx-0.5 tpl:inline-flex tpl:items-center tpl:gap-1 tpl:rounded tpl:px-1.5 tpl:py-0.5 tpl:text-[0.8em] tpl:font-bold tpl:tracking-wide tpl:uppercase tpl:select-none" : ""),
			style: c(x.value ? "background-color: transparent; border: 1.5px solid color-mix(in srgb, var(--tpl-primary) 50%, transparent); color: var(--tpl-primary);" : ""),
			contenteditable: "false"
		}, {
			default: n(() => [D.value ? a((r(), o("input", {
				key: 0,
				ref_key: "inputRef",
				ref: k,
				"onUpdate:modelValue": i[0] ||= (e) => O.value = e,
				type: "text",
				class: "tpl:w-40 tpl:rounded tpl:border-none tpl:bg-transparent tpl:px-0.5 tpl:py-0 tpl:text-[1em] tpl:font-medium tpl:normal-case tpl:outline-none tpl:text-[var(--tpl-primary)]",
				onBlur: N,
				onKeydown: P
			}, null, 544)), [[v, O.value]]) : x.value ? (r(), o("span", {
				key: 1,
				role: "button",
				tabindex: "0",
				"aria-label": s(_).mergeTag.editValue,
				class: "tpl-tooltip tpl:cursor-pointer",
				"data-tooltip": t.node.attrs.value,
				onClick: b(M, ["stop"]),
				onKeydown: [p(b(M, ["stop"]), ["enter"]), p(b(M, ["prevent", "stop"]), ["space"])]
			}, m(E.value), 41, ee)) : (r(), o("span", {
				key: 2,
				role: "button",
				tabindex: "0",
				"aria-label": s(_).mergeTag.editValue,
				onClick: b(M, ["stop"]),
				onKeydown: [p(b(M, ["stop"]), ["enter"]), p(b(M, ["prevent", "stop"]), ["space"])]
			}, m(t.node.attrs.value), 41, te)), x.value ? (r(), o("button", {
				key: 3,
				type: "button",
				"aria-label": s(_).mergeTag.deleteMergeTag,
				class: "tpl-merge-tag-delete tpl:flex tpl:size-5 tpl:cursor-pointer tpl:items-center tpl:justify-center tpl:rounded-full tpl:border-none tpl:bg-transparent tpl:p-0 tpl:opacity-60 tpl:transition-all hover:tpl:opacity-100 tpl:text-[var(--tpl-primary)]",
				contenteditable: "false",
				onClick: i[1] ||= b((...e) => t.deleteNode && t.deleteNode(...e), ["stop", "prevent"])
			}, [...i[2] ||= [h("svg", {
				width: "10",
				height: "10",
				viewBox: "0 0 24 24",
				fill: "none",
				stroke: "currentColor",
				"stroke-width": "3",
				"aria-hidden": "true"
			}, [h("line", {
				x1: "18",
				y1: "6",
				x2: "6",
				y2: "18"
			}), h("line", {
				x1: "6",
				y1: "6",
				x2: "18",
				y2: "18"
			})], -1)]], 8, ne)) : u("", !0)]),
			_: 1
		}, 8, ["class", "style"]));
	}
});
//#endregion
//#region src/extensions/isNodeSelected.ts
function B(e, t) {
	let { selection: n } = e.state, { $from: r, $to: i } = n, a = !1;
	return e.state.doc.nodesBetween(r.pos, i.pos, (e) => {
		if (e.type.name === t) return a = !0, !1;
	}), !!(a || r.pos > 0 && r.nodeBefore?.type.name === t || r.nodeAfter?.type.name === t);
}
//#endregion
//#region src/extensions/renderVueNodeView.ts
function V(e) {
	return M(e);
}
//#endregion
//#region src/extensions/LogicMergeTagNode.ts
var H = O.create({
	name: "logicMergeTagNode",
	group: "inline",
	inline: !0,
	atom: !0,
	addOptions() {
		return { syntax: D.liquid };
	},
	addAttributes() {
		return {
			value: {
				default: "",
				parseHTML: (e) => e.getAttribute("data-logic-merge-tag") || ""
			},
			keyword: {
				default: "",
				parseHTML: (e) => e.getAttribute("data-keyword") || e.textContent || ""
			}
		};
	},
	parseHTML() {
		return [{ tag: "span[data-logic-merge-tag]" }];
	},
	renderHTML({ node: e, HTMLAttributes: t }) {
		if (!T(e.attrs.value, this.options.syntax)) return [
			"span",
			{},
			e.attrs.value
		];
		let n = w(e.attrs.value, this.options.syntax);
		return [
			"span",
			F(t, {
				"data-logic-merge-tag": e.attrs.value,
				"data-keyword": n
			}),
			n
		];
	},
	addNodeView() {
		return V(z);
	},
	addKeyboardShortcuts() {
		return {
			Backspace: () => B(this.editor, this.name),
			Delete: () => B(this.editor, this.name)
		};
	},
	addInputRules() {
		return [new k({
			find: RegExp(this.options.syntax.logic.source + "$", ""),
			handler: ({ state: e, range: t, match: n }) => {
				let r = n[0];
				if (!T(r, this.options.syntax)) return;
				let i = w(r, this.options.syntax), a = this.type.create({
					value: r,
					keyword: i
				});
				e.tr.replaceWith(t.from, t.to, a);
			}
		})];
	},
	addPasteRules() {
		return [new P({
			find: new RegExp(this.options.syntax.logic.source, "g"),
			handler: ({ state: e, range: t, match: n }) => {
				let r = n[0];
				if (!T(r, this.options.syntax)) return;
				let i = w(r, this.options.syntax), a = this.type.create({
					value: r,
					keyword: i
				});
				e.tr.replaceWith(t.from, t.to, a);
			}
		})];
	}
}), U = [
	"aria-label",
	"data-tooltip",
	"onKeydown"
], W = ["aria-label"], G = /* @__PURE__ */ i({
	__name: "MergeTagNodeView",
	props: {
		node: {},
		deleteNode: { type: Function },
		updateAttributes: { type: Function }
	},
	setup(t) {
		let i = t, { getMergeTagLabel: c } = C(), { t: l } = S(), u = g(() => c(i.node.attrs.value)), _ = e(!1), y = e(""), x = e(null);
		function w() {
			y.value = i.node.attrs.value, _.value = !0, f(() => {
				x.value?.focus(), x.value?.select();
			});
		}
		function T() {
			let e = y.value.trim();
			e && e !== i.node.attrs.value && i.updateAttributes({
				value: e,
				label: c(e)
			}), _.value = !1;
		}
		function E(e) {
			e.key === "Enter" ? (e.preventDefault(), T()) : e.key === "Escape" && (_.value = !1);
		}
		return (e, i) => (r(), d(s(j), {
			as: "span",
			class: "tpl-merge-tag-node tpl:group tpl:mx-0.5 tpl:inline-flex tpl:items-center tpl:gap-1 tpl:rounded tpl:px-1.5 tpl:py-0.5 tpl:text-[0.9em] tpl:font-medium tpl:select-none tpl:text-[var(--tpl-primary)]",
			style: { "background-color": "color-mix(in srgb, var(--tpl-primary) 20%, transparent)" },
			contenteditable: "false"
		}, {
			default: n(() => [_.value ? a((r(), o("input", {
				key: 0,
				ref_key: "inputRef",
				ref: x,
				"onUpdate:modelValue": i[0] ||= (e) => y.value = e,
				type: "text",
				class: "tpl:w-32 tpl:rounded tpl:border-none tpl:bg-transparent tpl:px-0.5 tpl:py-0 tpl:text-[1em] tpl:font-medium tpl:outline-none tpl:text-[var(--tpl-primary)]",
				onBlur: T,
				onKeydown: E
			}, null, 544)), [[v, y.value]]) : (r(), o("span", {
				key: 1,
				role: "button",
				tabindex: "0",
				"aria-label": s(l).mergeTag.editValue,
				class: "tpl-tooltip tpl:cursor-pointer",
				"data-tooltip": t.node.attrs.value,
				onClick: b(w, ["stop"]),
				onKeydown: [p(b(w, ["stop"]), ["enter"]), p(b(w, ["prevent", "stop"]), ["space"])]
			}, m(u.value), 41, U)), h("button", {
				type: "button",
				"aria-label": s(l).mergeTag.deleteMergeTag,
				class: "tpl-merge-tag-delete tpl:flex tpl:size-5 tpl:cursor-pointer tpl:items-center tpl:justify-center tpl:rounded-full tpl:border-none tpl:bg-transparent tpl:p-0 tpl:opacity-60 tpl:transition-all hover:tpl:opacity-100 tpl:text-[var(--tpl-primary)]",
				contenteditable: "false",
				onClick: i[1] ||= b((...e) => t.deleteNode && t.deleteNode(...e), ["stop", "prevent"])
			}, [...i[2] ||= [h("svg", {
				width: "10",
				height: "10",
				viewBox: "0 0 24 24",
				fill: "none",
				stroke: "currentColor",
				"stroke-width": "3",
				"aria-hidden": "true"
			}, [h("line", {
				x1: "18",
				y1: "6",
				x2: "6",
				y2: "18"
			}), h("line", {
				x1: "6",
				y1: "6",
				x2: "18",
				y2: "18"
			})], -1)]], 8, W)]),
			_: 1
		}));
	}
}), K = O.create({
	name: "mergeTagNode",
	group: "inline",
	inline: !0,
	atom: !0,
	addOptions() {
		return {
			mergeTags: [],
			syntax: D.liquid
		};
	},
	addAttributes() {
		return {
			label: {
				default: "",
				parseHTML: (e) => e.getAttribute("data-label") || e.textContent || ""
			},
			value: {
				default: "",
				parseHTML: (e) => e.getAttribute("data-merge-tag") || ""
			}
		};
	},
	parseHTML() {
		return [{ tag: "span[data-merge-tag]" }];
	},
	renderHTML({ node: e, HTMLAttributes: t }) {
		let n = E(e.attrs.value, this.options.mergeTags);
		return [
			"span",
			F(t, {
				"data-merge-tag": e.attrs.value,
				"data-label": n
			}),
			n
		];
	},
	addNodeView() {
		return V(G);
	},
	addCommands() {
		return { insertMergeTag: (e) => ({ commands: t }) => t.insertContent({
			type: this.name,
			attrs: e
		}) };
	},
	addKeyboardShortcuts() {
		return {
			Backspace: () => B(this.editor, this.name),
			Delete: () => B(this.editor, this.name)
		};
	},
	addInputRules() {
		return [new k({
			find: RegExp(this.options.syntax.value.source + "$", ""),
			handler: ({ state: e, range: t, match: n }) => {
				let r = n[0], i = E(r, this.options.mergeTags), a = this.type.create({
					label: i,
					value: r
				});
				e.tr.replaceWith(t.from, t.to, a);
			}
		})];
	},
	addPasteRules() {
		return [new P({
			find: new RegExp(this.options.syntax.value.source, "g"),
			handler: ({ state: e, range: t, match: n }) => {
				let r = n[0], i = E(r, this.options.mergeTags), a = this.type.create({
					label: i,
					value: r
				});
				e.tr.replaceWith(t.from, t.to, a);
			}
		})];
	}
}), q = ["id"], J = {
	key: 0,
	class: "tpl:px-3 tpl:py-2 tpl:text-xs tpl:text-[var(--tpl-text-dim)]",
	"data-testid": "merge-tag-suggestion-empty"
}, Y = [
	"id",
	"aria-selected",
	"data-selected",
	"data-merge-tag-value",
	"onMousedown",
	"onMousemove"
], X = { class: "tpl:font-medium" }, re = { class: "tpl:text-[var(--tpl-text-dim)] tpl:font-mono" }, ie = /* @__PURE__ */ i({
	__name: "MergeTagSuggestionList",
	props: {
		items: {},
		selectedIndex: {},
		emptyText: {},
		listId: {}
	},
	emits: ["select", "hover"],
	setup(e) {
		let n = e;
		function i(e) {
			return n.listId ? `${n.listId}-opt-${e}` : void 0;
		}
		return (n, a) => (r(), o("div", {
			id: e.listId,
			class: "tpl:min-w-[200px] tpl:max-w-[320px] tpl:max-h-[50vh] tpl:overflow-y-auto tpl:rounded-[var(--tpl-radius)] tpl:border tpl:border-[var(--tpl-border)] tpl:bg-[var(--tpl-bg-elevated)] tpl:py-1 tpl:shadow-lg",
			role: "listbox",
			"data-testid": "merge-tag-suggestion-list"
		}, [e.items.length === 0 ? (r(), o("div", J, m(e.emptyText), 1)) : u("", !0), (r(!0), o(l, null, t(e.items, (t, a) => (r(), o("button", {
			key: t.value,
			id: i(a),
			type: "button",
			role: "option",
			"aria-selected": a === e.selectedIndex,
			"data-selected": a === e.selectedIndex ? "true" : "false",
			"data-merge-tag-value": t.value,
			class: y(["tpl:flex tpl:w-full tpl:flex-col tpl:items-start tpl:gap-0.5 tpl:px-3 tpl:py-1.5 tpl:text-left tpl:text-xs tpl:transition-colors", a === e.selectedIndex ? "tpl:bg-[var(--tpl-primary-light)] tpl:text-[var(--tpl-primary)]" : "tpl:text-[var(--tpl-text)] hover:tpl:bg-[var(--tpl-bg-hover)]"]),
			onMousedown: b((e) => n.$emit("select", t), ["prevent", "stop"]),
			onMousemove: (t) => a !== e.selectedIndex && n.$emit("hover", a)
		}, [h("span", X, m(t.label), 1), h("span", re, m(t.value), 1)], 42, Y))), 128))], 8, q));
	}
}), Z = 10, ae = 0;
function Q(e, t) {
	let n = t.trim().toLowerCase();
	return n === "" ? e.slice(0, Z) : e.filter((e) => {
		let t = e.label.toLowerCase(), r = e.value.toLowerCase();
		return t.includes(n) || r.includes(n);
	}).slice(0, Z);
}
function $(e, t, n, r) {
	return t.length === 0 ? e.key === "Enter" || e.key === "Tab" : e.key === "ArrowDown" ? (n.value = (n.value + 1) % t.length, !0) : e.key === "ArrowUp" ? (n.value = (n.value - 1 + t.length) % t.length, !0) : e.key === "Enter" || e.key === "Tab" ? (r(t[n.value]), !0) : !1;
}
var oe = A.create({
	name: "mergeTagSuggestion",
	addOptions() {
		return {
			mergeTags: [],
			char: "{{",
			emptyText: "No matching merge tags"
		};
	},
	addProseMirrorPlugins() {
		let t = this.options.mergeTags, n = this.options.emptyText, r = {
			char: this.options.char,
			allowSpaces: !1,
			startOfLine: !1,
			allowedPrefixes: null,
			items: ({ query: e }) => Q(t, e),
			command: ({ editor: e, range: t, props: n }) => {
				e.chain().focus().insertContentAt(t, {
					type: "mergeTagNode",
					attrs: {
						label: n.label,
						value: n.value
					}
				}).run();
			},
			render: () => {
				let t = null, r = null, i = null, a = e([]), o = e(0), s = null, c = `tpl-merge-tag-suggestion-${++ae}`, l = null, u = [];
				function d() {
					h(l?.() ?? null);
				}
				function f(e) {
					let t = [], n = e?.parentElement ?? null;
					for (; n && n !== document.body && n !== document.documentElement;) {
						let e = window.getComputedStyle(n), r = e.overflow + e.overflowX + e.overflowY;
						/(auto|scroll|overlay)/.test(r) && t.push(n), n = n.parentElement;
					}
					return t;
				}
				function p(e) {
					u = [window, ...f(e)];
					for (let e of u) e.addEventListener("scroll", d, {
						passive: !0,
						capture: !0
					});
					window.addEventListener("resize", d, { passive: !0 });
				}
				function m() {
					for (let e of u) e.removeEventListener("scroll", d, { capture: !0 });
					window.removeEventListener("resize", d), u = [];
				}
				function h(e) {
					if (!r || !e || e.bottom < 0 || e.top > window.innerHeight) return;
					r.style.position = "fixed", r.style.left = `${e.left}px`, r.style.zIndex = "9999", r.style.top = `${e.bottom}px`;
					let t = r.offsetHeight;
					if (t !== 0 && window.innerHeight - e.bottom < t) {
						let n = Math.max(0, e.top - t);
						r.style.top = `${n}px`;
					}
				}
				function g(e, t) {
					let n = t?.closest("[data-tpl-theme]");
					if (!n) return;
					let r = n.getAttribute("data-tpl-theme");
					r && e.setAttribute("data-tpl-theme", r);
					let i = window.getComputedStyle(n);
					for (let t = 0; t < i.length; t++) {
						let n = i[t];
						n.startsWith("--tpl-") && e.style.setProperty(n, i.getPropertyValue(n));
					}
					e.style.fontFamily = i.fontFamily, e.style.fontSize = i.fontSize, e.style.lineHeight = i.lineHeight;
				}
				function v(e) {
					i && (e ? (i.setAttribute("role", "combobox"), i.setAttribute("aria-haspopup", "listbox"), i.setAttribute("aria-expanded", "true"), i.setAttribute("aria-controls", c)) : (i.removeAttribute("aria-expanded"), i.removeAttribute("aria-controls"), i.removeAttribute("aria-activedescendant"), i.removeAttribute("aria-haspopup"), i.removeAttribute("role")));
				}
				function y() {
					if (i) {
						if (a.value.length === 0) {
							i.removeAttribute("aria-activedescendant");
							return;
						}
						i.setAttribute("aria-activedescendant", `${c}-opt-${o.value}`);
					}
				}
				function b(e) {
					s?.(e);
				}
				return {
					onStart: (e) => {
						a.value = e.items, o.value = 0, s = (t) => e.command(t), r = document.createElement("div"), r.setAttribute("data-testid", "merge-tag-suggestion-popup");
						let u = e.editor.view?.dom;
						i = u ?? null, g(r, u ?? null), document.body.appendChild(r), t = _({ render() {
							return x(ie, {
								items: a.value,
								selectedIndex: o.value,
								emptyText: n,
								listId: c,
								onSelect: (e) => b(e),
								onHover: (e) => {
									o.value = e, y();
								}
							});
						} }), t.mount(r), v(!0), y(), l = e.clientRect ?? null, h(l?.() ?? null), p(u ?? null);
					},
					onUpdate: (e) => {
						a.value = e.items, o.value >= e.items.length && (o.value = 0), s = (t) => e.command(t), y(), l = e.clientRect ?? null, h(l?.() ?? null);
					},
					onKeyDown: (e) => {
						if (e.event.key === "Escape") return !0;
						let t = $(e.event, a.value, o, b);
						return t && y(), t;
					},
					onExit: () => {
						m(), v(!1), t?.unmount(), r?.remove(), t = null, r = null, i = null, s = null, l = null;
					}
				};
			}
		};
		return [N({
			editor: this.editor,
			...r
		})];
	}
});
//#endregion
export { I as FontSize, L as LetterSpacing, R as LineHeight, H as LogicMergeTagNode, K as MergeTagNode, oe as MergeTagSuggestion, Q as filterMergeTags, $ as handleSuggestionKeyDown };

//# sourceMappingURL=extensions-D13MqxlW.js.map