import { C as e, H as t, M as n, O as r, P as i, V as a, Z as o, c as s, ct as c, f as l, g as u, h as d, it as f, l as p, m, o as h, ot as g, p as _, r as v, st as y, u as b, x } from "./draggable-BwWMFq33.js";
import { $ as S, Ft as C, _n as w, gn as T, mn as E, vn as D } from "./features-CUYy5kZQ.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-BErAJEvo.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__ */ x({
	__name: "LogicMergeTagNodeView",
	props: {
		node: {},
		editor: {},
		getPos: { type: Function },
		deleteNode: { type: Function },
		updateAttributes: { type: Function }
	},
	setup(e) {
		let i = e, { syntax: v } = S(), { t: b } = C(), x = l(() => D(i.node.attrs.value, v)), w = l(() => T(i.node.attrs.value, v)), E = o(!1), O = o(""), k = o(null), A = !1;
		function M() {
			O.value = i.node.attrs.value, A = !1, E.value = !0, r(() => {
				k.value?.focus(), k.value?.select();
			});
		}
		function N() {
			if (A) return;
			A = !0;
			let e = O.value.trim();
			if (!e) {
				E.value = !1;
				return;
			}
			e !== i.node.attrs.value && i.updateAttributes({
				value: e,
				keyword: D(e, v) ? T(e, v) : ""
			}), E.value = !1;
		}
		function P(e) {
			e.key === "Enter" ? (e.preventDefault(), N()) : e.key === "Escape" && (E.value = !1);
		}
		return (r, i) => (n(), m(f(j), {
			as: "span",
			class: g(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: y(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: a(() => [E.value ? t((n(), u("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)), [[h, O.value]]) : x.value ? (n(), u("span", {
				key: 1,
				role: "button",
				tabindex: "0",
				"aria-label": f(b).mergeTag.editValue,
				class: "tpl-tooltip tpl:cursor-pointer",
				"data-tooltip": e.node.attrs.value,
				onClick: p(M, ["stop"]),
				onKeydown: [s(p(M, ["stop"]), ["enter"]), s(p(M, ["prevent", "stop"]), ["space"])]
			}, c(w.value), 41, ee)) : (n(), u("span", {
				key: 2,
				role: "button",
				tabindex: "0",
				"aria-label": f(b).mergeTag.editValue,
				onClick: p(M, ["stop"]),
				onKeydown: [s(p(M, ["stop"]), ["enter"]), s(p(M, ["prevent", "stop"]), ["space"])]
			}, c(e.node.attrs.value), 41, te)), x.value ? (n(), u("button", {
				key: 3,
				type: "button",
				"aria-label": f(b).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] ||= p((...t) => e.deleteNode && e.deleteNode(...t), ["stop", "prevent"])
			}, [...i[2] ||= [_("svg", {
				width: "10",
				height: "10",
				viewBox: "0 0 24 24",
				fill: "none",
				stroke: "currentColor",
				"stroke-width": "3",
				"aria-hidden": "true"
			}, [_("line", {
				x1: "18",
				y1: "6",
				x2: "6",
				y2: "18"
			}), _("line", {
				x1: "6",
				y1: "6",
				x2: "18",
				y2: "18"
			})], -1)]], 8, ne)) : d("", !0)]),
			_: 1
		}, 8, ["class", "style"]));
	}
});
//#endregion
//#region src/extensions/isNodeSelected.ts
function B(e, t) {
	let { $from: n, $to: r } = e.state.selection;
	return n.pos === r.pos ? n.pos > 0 && n.nodeBefore?.type.name === t || n.nodeAfter?.type.name === t : !1;
}
//#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: E.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 (!D(e.attrs.value, this.options.syntax)) return [
			"span",
			{},
			e.attrs.value
		];
		let n = T(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 (!D(r, this.options.syntax)) return;
				let i = T(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 (!D(r, this.options.syntax)) return;
				let i = T(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__ */ x({
	__name: "MergeTagNodeView",
	props: {
		node: {},
		deleteNode: { type: Function },
		updateAttributes: { type: Function }
	},
	setup(e) {
		let i = e, { getMergeTagLabel: d } = S(), { t: g } = C(), v = l(() => d(i.node.attrs.value)), y = o(!1), b = o(""), x = o(null);
		function w() {
			b.value = i.node.attrs.value, y.value = !0, r(() => {
				x.value?.focus(), x.value?.select();
			});
		}
		function T() {
			let e = b.value.trim();
			e && e !== i.node.attrs.value && i.updateAttributes({
				value: e,
				label: d(e)
			}), y.value = !1;
		}
		function E(e) {
			e.key === "Enter" ? (e.preventDefault(), T()) : e.key === "Escape" && (y.value = !1);
		}
		return (r, i) => (n(), m(f(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: a(() => [y.value ? t((n(), u("input", {
				key: 0,
				ref_key: "inputRef",
				ref: x,
				"onUpdate:modelValue": i[0] ||= (e) => b.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)), [[h, b.value]]) : (n(), u("span", {
				key: 1,
				role: "button",
				tabindex: "0",
				"aria-label": f(g).mergeTag.editValue,
				class: "tpl-tooltip tpl:cursor-pointer",
				"data-tooltip": e.node.attrs.value,
				onClick: p(w, ["stop"]),
				onKeydown: [s(p(w, ["stop"]), ["enter"]), s(p(w, ["prevent", "stop"]), ["space"])]
			}, c(v.value), 41, U)), _("button", {
				type: "button",
				"aria-label": f(g).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] ||= p((...t) => e.deleteNode && e.deleteNode(...t), ["stop", "prevent"])
			}, [...i[2] ||= [_("svg", {
				width: "10",
				height: "10",
				viewBox: "0 0 24 24",
				fill: "none",
				stroke: "currentColor",
				"stroke-width": "3",
				"aria-hidden": "true"
			}, [_("line", {
				x1: "18",
				y1: "6",
				x2: "6",
				y2: "18"
			}), _("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: E.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 = w(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 = w(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 = w(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__ */ x({
	__name: "MergeTagSuggestionList",
	props: {
		items: {},
		selectedIndex: {},
		emptyText: {},
		listId: {}
	},
	emits: ["select", "hover"],
	setup(e) {
		let t = e;
		function r(e) {
			return t.listId ? `${t.listId}-opt-${e}` : void 0;
		}
		return (t, a) => (n(), u("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 ? (n(), u("div", J, c(e.emptyText), 1)) : d("", !0), (n(!0), u(b, null, i(e.items, (i, a) => (n(), u("button", {
			key: i.value,
			id: r(a),
			type: "button",
			role: "option",
			"aria-selected": a === e.selectedIndex,
			"data-selected": a === e.selectedIndex ? "true" : "false",
			"data-merge-tag-value": i.value,
			class: g(["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: p((e) => t.$emit("select", i), ["prevent", "stop"]),
			onMousemove: (n) => a !== e.selectedIndex && t.$emit("hover", a)
		}, [_("span", X, c(i.label), 1), _("span", re, c(i.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",
			popoverRoot: null
		};
	},
	addProseMirrorPlugins() {
		let t = this.options.mergeTags, n = this.options.emptyText, r = this.options.popoverRoot, i = {
			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, i = null, a = null, s = o([]), c = o(0), l = null, u = `tpl-merge-tag-suggestion-${++ae}`, d = null, f = [], p = null;
				function m() {
					b(d?.() ?? null);
				}
				function h() {
					m(), p !== null && cancelAnimationFrame(p), p = requestAnimationFrame(() => {
						p = null, m();
					});
				}
				function g(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 _(e) {
					f = [window, ...g(e)];
					for (let e of f) e.addEventListener("scroll", m, {
						passive: !0,
						capture: !0
					});
					window.addEventListener("resize", m, { passive: !0 });
				}
				function y() {
					for (let e of f) e.removeEventListener("scroll", m, { capture: !0 });
					window.removeEventListener("resize", m), f = [];
				}
				function b(e) {
					if (!i || !e || e.bottom < 0 || e.top > window.innerHeight) return;
					i.style.position = "fixed", i.style.left = `${e.left}px`, i.style.zIndex = "9999", i.style.top = `${e.bottom}px`;
					let t = i.offsetHeight;
					if (t !== 0 && window.innerHeight - e.bottom < t) {
						let n = Math.max(0, e.top - t);
						i.style.top = `${n}px`;
					}
				}
				function x(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 S(e) {
					a && (e ? (a.setAttribute("role", "combobox"), a.setAttribute("aria-haspopup", "listbox"), a.setAttribute("aria-expanded", "true"), a.setAttribute("aria-controls", u)) : (a.removeAttribute("aria-expanded"), a.removeAttribute("aria-controls"), a.removeAttribute("aria-activedescendant"), a.removeAttribute("aria-haspopup"), a.removeAttribute("role")));
				}
				function C() {
					if (a) {
						if (s.value.length === 0) {
							a.removeAttribute("aria-activedescendant");
							return;
						}
						a.setAttribute("aria-activedescendant", `${u}-opt-${c.value}`);
					}
				}
				function w(e) {
					l?.(e);
				}
				return {
					onStart: (o) => {
						s.value = o.items, c.value = 0, l = (e) => o.command(e), i = document.createElement("div"), i.setAttribute("data-testid", "merge-tag-suggestion-popup");
						let f = o.editor.view?.dom;
						a = f ?? null, x(i, f ?? null), (r?.value ?? document.body).appendChild(i), t = v({ render() {
							return e(ie, {
								items: s.value,
								selectedIndex: c.value,
								emptyText: n,
								listId: u,
								onSelect: (e) => w(e),
								onHover: (e) => {
									c.value = e, C();
								}
							});
						} }), t.mount(i), S(!0), C(), d = o.clientRect ?? null, h(), _(f ?? null);
					},
					onUpdate: (e) => {
						s.value = e.items, c.value >= e.items.length && (c.value = 0), l = (t) => e.command(t), C(), d = e.clientRect ?? null, h();
					},
					onKeyDown: (e) => {
						if (e.event.key === "Escape") return !0;
						let t = $(e.event, s.value, c, w);
						return t && C(), t;
					},
					onExit: () => {
						p !== null && (cancelAnimationFrame(p), p = null), y(), S(!1), t?.unmount(), i?.remove(), t = null, i = null, a = null, l = null, d = null;
					}
				};
			}
		};
		return [N({
			editor: this.editor,
			...i
		})];
	}
});
//#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-CvCoOuWB.js.map