import { E as e, J as t, N as n, S as r, _ as i, at as a, b as o, ct as s, d as c, f as l, g as u, h as d, lt as f, m as p, st as m, y as h } from "./draggable-Bcb86AsV.js";
import { Mt as g, Xt as _, Zt as v, ht as y, q as b } from "./features-BnG-dhzy.js";
import { J as x, V as S, b as C, z as w } from "./icons-B_185qj_.js";
import { n as T, t as E } from "./RichTextEditorContent-CmOwLOeY.js";
//#region src/components/blocks/TitleEditor.vue?vue&type=script&setup=true&lang.ts
var ee = { class: "tpl-text-editor-wrapper tpl:relative" }, D = ["data-tpl-theme", "aria-label"], O = ["aria-label", "title"], k = ["aria-label", "title"], A = ["aria-label", "title"], j = {
	key: 0,
	class: "tpl:mx-1.5 tpl:h-6 tpl:w-px tpl:bg-[var(--tpl-border)]"
}, M = ["aria-label", "title"], N = {
	key: 1,
	class: "tpl:flex tpl:items-center tpl:gap-2 tpl:px-2 tpl:text-xs tpl:text-[var(--tpl-text-dim)]"
}, P = /* @__PURE__ */ r({
	__name: "TitleEditor",
	props: {
		block: {},
		toolbarPosition: {}
	},
	emits: ["done"],
	setup(r, { emit: P }) {
		let F = r, I = P, L = e(_, null), R = e(v, null), { t: z } = g(), { editor: B, EditorContent: V, isLoading: H, initError: U, retry: W, showLinkDialog: G, linkUrl: K, linkDialogRef: q, canRequestMergeTag: J, openLinkDialog: Y, insertLink: X, removeLink: Z, closeLinkDialog: Q, handleLinkKeydown: te, handleAddMergeTag: $ } = b({
			blockId: () => F.block.id,
			blockContent: () => F.block.content,
			onDone: () => I("done"),
			editorName: "TitleEditor",
			async loadExtensions({ mergeTags: e, syntax: t, triggerChar: n, autocompleteEnabled: r, suggestionEmptyText: i }) {
				let [{ Editor: a, EditorContent: o }, { default: s }, { default: c }, { MergeTagNode: l, MergeTagSuggestion: u, LogicMergeTagNode: d }] = await Promise.all([
					import("./tiptap-CPAwPMop.js").then((e) => e.i),
					import("./tiptap-CPAwPMop.js").then((e) => e.a),
					import("./tiptap-CPAwPMop.js").then((e) => e.u),
					import("./extensions-D13MqxlW.js")
				]);
				return {
					TiptapEditor: a,
					EC: o,
					extensions: [
						s.configure({
							heading: !1,
							codeBlock: !1,
							blockquote: !1,
							horizontalRule: !1,
							bulletList: !1,
							orderedList: !1,
							listItem: !1,
							strike: !1
						}),
						c.configure({
							openOnClick: !1,
							HTMLAttributes: {
								target: "_blank",
								rel: "noopener noreferrer"
							}
						}),
						l.configure({
							mergeTags: e,
							syntax: t
						}),
						d.configure({ syntax: t }),
						...r && n && e.length > 0 ? [u.configure({
							mergeTags: e,
							char: n,
							emptyText: i
						})] : []
					]
				};
			}
		});
		return (e, g) => (n(), i("div", ee, [
			(n(), d(l, { to: "body" }, [p("div", {
				"data-tpl-theme": a(R),
				role: "toolbar",
				"aria-label": a(z).titleEditor.toolbar,
				class: "tpl tpl-text-toolbar tpl:fixed tpl:z-popover tpl:flex tpl:items-center tpl:gap-1 tpl:rounded-lg tpl:border tpl:border-[var(--tpl-border)] tpl:bg-[var(--tpl-bg)] tpl:px-3 tpl:py-2 tpl:shadow-lg",
				style: s({
					...a(L),
					top: `${r.toolbarPosition.top}px`,
					left: `${r.toolbarPosition.left}px`,
					transform: "translateY(-100%)"
				})
			}, [!a(H) && a(B) ? (n(), i(c, { key: 0 }, [
				p("button", {
					type: "button",
					class: m(["tpl-text-toolbar-btn", { "tpl-text-toolbar-btn--active": a(B)?.isActive("bold") }]),
					"aria-label": a(z).titleEditor.bold,
					title: a(z).titleEditor.bold,
					onClick: g[0] ||= (e) => a(B)?.chain().focus().toggleBold().run()
				}, [o(a(x), {
					size: 16,
					"stroke-width": 2.5
				})], 10, O),
				p("button", {
					type: "button",
					class: m(["tpl-text-toolbar-btn", { "tpl-text-toolbar-btn--active": a(B)?.isActive("italic") }]),
					"aria-label": a(z).titleEditor.italic,
					title: a(z).titleEditor.italic,
					onClick: g[1] ||= (e) => a(B)?.chain().focus().toggleItalic().run()
				}, [o(a(S), {
					size: 16,
					"stroke-width": 2
				})], 10, k),
				g[6] ||= p("span", {
					class: "tpl:mx-1.5 tpl:h-6 tpl:w-px tpl:bg-[var(--tpl-border)]",
					"aria-hidden": "true"
				}, null, -1),
				p("button", {
					type: "button",
					class: m(["tpl-text-toolbar-btn", { "tpl-text-toolbar-btn--active": a(B)?.isActive("link") }]),
					"aria-label": a(z).titleEditor.addLink,
					title: a(z).titleEditor.addLink,
					onClick: g[2] ||= (...e) => a(Y) && a(Y)(...e)
				}, [o(a(w), {
					size: 16,
					"stroke-width": 2
				})], 10, A),
				a(J) ? (n(), i("span", j)) : u("", !0),
				a(J) ? (n(), i("button", {
					key: 1,
					type: "button",
					class: "tpl:flex tpl:h-8 tpl:cursor-pointer tpl:items-center tpl:justify-center tpl:gap-1.5 tpl:rounded tpl:border-none tpl:bg-transparent tpl:px-2.5 tpl:text-xs tpl:font-medium tpl:text-[var(--tpl-text)] tpl:transition-all tpl:duration-150 tpl:hover:bg-[var(--tpl-bg-active)]",
					"aria-label": a(z).mergeTag.add,
					title: a(z).mergeTag.add,
					onClick: g[3] ||= (...e) => a($) && a($)(...e)
				}, [o(a(C), {
					size: 16,
					"stroke-width": 2
				}), h(" " + f(a(z).mergeTag.add), 1)], 8, M)) : u("", !0)
			], 64)) : (n(), i("div", N, [o(a(y), {
				class: "tpl-spinner",
				size: 14,
				"stroke-width": 2
			}), h(" " + f(a(z).errors.editorLoading), 1)]))], 12, D)])),
			o(E, {
				editor: a(B),
				"editor-content": a(V),
				"is-loading": a(H),
				"init-error": a(U),
				onRetry: a(W)
			}, null, 8, [
				"editor",
				"editor-content",
				"is-loading",
				"init-error",
				"onRetry"
			]),
			o(T, {
				visible: a(G),
				"is-editing-link": a(B)?.isActive("link") ?? !1,
				"dialog-ref": a(q),
				"onUpdate:dialogRef": g[4] ||= (e) => t(q) ? q.value = e : null,
				"link-url": a(K),
				"onUpdate:linkUrl": g[5] ||= (e) => t(K) ? K.value = e : null,
				onClose: a(Q),
				onInsert: a(X),
				onRemove: a(Z),
				onKeydown: a(te)
			}, null, 8, [
				"visible",
				"is-editing-link",
				"dialog-ref",
				"link-url",
				"onClose",
				"onInsert",
				"onRemove",
				"onKeydown"
			])
		]));
	}
});
//#endregion
export { P as default };

//# sourceMappingURL=TitleEditor-CvZe3neh.js.map