@broberg/cms-inline-edit 0.4.17 → 0.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +70 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +70 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -60,6 +60,8 @@ function resolveOptions(options) {
|
|
|
60
60
|
// No emoji in defaults — the square-pen SVG is the icon; some sites ban emoji.
|
|
61
61
|
connectLabel: "Log ind for at redigere",
|
|
62
62
|
disconnectLabel: "Afbryd",
|
|
63
|
+
logoutLabel: "Log ud",
|
|
64
|
+
connectPrompt: false,
|
|
63
65
|
...options,
|
|
64
66
|
labels: { ...DEFAULT_LABELS, ...options.labels ?? {} }
|
|
65
67
|
};
|
|
@@ -68,16 +70,20 @@ async function initInlineEdit(options) {
|
|
|
68
70
|
if (typeof window === "undefined") return;
|
|
69
71
|
const resolved = resolveOptions(options);
|
|
70
72
|
uiLabels = resolved.labels;
|
|
71
|
-
captureTokenFromUrl(resolved);
|
|
73
|
+
const freshFromUrl = captureTokenFromUrl(resolved);
|
|
72
74
|
const enabled = await checkEnabled(resolved);
|
|
73
75
|
if (!enabled) return;
|
|
74
76
|
const token = getConnectedToken(options);
|
|
75
|
-
if (token) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
if (!token) {
|
|
78
|
+
if (resolved.connectPrompt) {
|
|
79
|
+
showConnectPrompt(resolved);
|
|
80
|
+
listenForTokenMessage(resolved);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
80
83
|
}
|
|
84
|
+
setupFields(token, resolved);
|
|
85
|
+
if (freshFromUrl) enterEditMode();
|
|
86
|
+
else showIdlePill();
|
|
81
87
|
}
|
|
82
88
|
function listenForTokenMessage(options) {
|
|
83
89
|
let cmsOrigin;
|
|
@@ -95,7 +101,8 @@ function listenForTokenMessage(options) {
|
|
|
95
101
|
if (document.querySelector("[data-cms-inline-edit-badge]")) return;
|
|
96
102
|
localStorage.setItem(options.storageKey, data.token);
|
|
97
103
|
document.querySelector("[data-cms-inline-edit-connect]")?.remove();
|
|
98
|
-
|
|
104
|
+
setupFields(data.token, options);
|
|
105
|
+
enterEditMode();
|
|
99
106
|
});
|
|
100
107
|
}
|
|
101
108
|
function getConnectedToken(options) {
|
|
@@ -121,10 +128,11 @@ function disconnect(options) {
|
|
|
121
128
|
function captureTokenFromUrl(options) {
|
|
122
129
|
const url = new URL(window.location.href);
|
|
123
130
|
const urlToken = url.searchParams.get(options.tokenParam);
|
|
124
|
-
if (!urlToken) return;
|
|
131
|
+
if (!urlToken) return false;
|
|
125
132
|
localStorage.setItem(options.storageKey, urlToken);
|
|
126
133
|
url.searchParams.delete(options.tokenParam);
|
|
127
134
|
window.history.replaceState({}, "", url.toString());
|
|
135
|
+
return true;
|
|
128
136
|
}
|
|
129
137
|
async function checkEnabled(options) {
|
|
130
138
|
try {
|
|
@@ -170,11 +178,58 @@ function showConnectPrompt(options) {
|
|
|
170
178
|
});
|
|
171
179
|
document.body.appendChild(link);
|
|
172
180
|
}
|
|
173
|
-
|
|
181
|
+
var editingActive = false;
|
|
182
|
+
var fieldsWired = false;
|
|
183
|
+
var stateOptions = null;
|
|
184
|
+
function setupFields(token, options) {
|
|
185
|
+
stateOptions = options;
|
|
186
|
+
if (fieldsWired) return;
|
|
174
187
|
injectStyles();
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
188
|
+
document.querySelectorAll("[data-cms-field]").forEach((el) => wireField(el, token, options));
|
|
189
|
+
fieldsWired = true;
|
|
190
|
+
}
|
|
191
|
+
function enterEditMode() {
|
|
192
|
+
if (!stateOptions || editingActive) return;
|
|
193
|
+
editingActive = true;
|
|
194
|
+
removeIdlePill();
|
|
195
|
+
showActiveBadge(stateOptions);
|
|
196
|
+
}
|
|
197
|
+
function exitEditMode() {
|
|
198
|
+
if (!stateOptions || !editingActive) return;
|
|
199
|
+
deactivateRich();
|
|
200
|
+
editingActive = false;
|
|
201
|
+
document.querySelector("[data-cms-inline-edit-badge]")?.remove();
|
|
202
|
+
showIdlePill();
|
|
203
|
+
}
|
|
204
|
+
function removeIdlePill() {
|
|
205
|
+
document.querySelector("[data-cms-inline-edit-idle]")?.remove();
|
|
206
|
+
}
|
|
207
|
+
function showIdlePill() {
|
|
208
|
+
if (!stateOptions) return;
|
|
209
|
+
const options = stateOptions;
|
|
210
|
+
removeIdlePill();
|
|
211
|
+
const wrap = document.createElement("div");
|
|
212
|
+
wrap.setAttribute("data-cms-inline-edit-idle", "");
|
|
213
|
+
wrap.style.cssText = "position:fixed;bottom:16px;left:16px;display:inline-flex;align-items:stretch;z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);border-radius:999px;overflow:hidden;";
|
|
214
|
+
const edit = document.createElement("button");
|
|
215
|
+
edit.type = "button";
|
|
216
|
+
edit.setAttribute("data-cms-inline-edit-enter", "");
|
|
217
|
+
edit.style.cssText = "display:inline-flex;align-items:center;gap:7px;background:#1c2027;color:#fff;font:600 12px system-ui,sans-serif;padding:8px 14px;border:none;cursor:pointer;";
|
|
218
|
+
const editText = document.createElement("span");
|
|
219
|
+
editText.textContent = options.connectLabel;
|
|
220
|
+
edit.append(makeIcon(), editText);
|
|
221
|
+
edit.addEventListener("click", enterEditMode);
|
|
222
|
+
const out = document.createElement("button");
|
|
223
|
+
out.type = "button";
|
|
224
|
+
out.setAttribute("data-cms-inline-edit-logout", "");
|
|
225
|
+
out.textContent = options.logoutLabel;
|
|
226
|
+
out.style.cssText = "background:#141821;color:#9aa4b2;font:600 11px system-ui,sans-serif;padding:8px 12px;border:none;border-left:1px solid rgba(255,255,255,.12);cursor:pointer;";
|
|
227
|
+
out.addEventListener("click", () => {
|
|
228
|
+
disconnect(options);
|
|
229
|
+
removeIdlePill();
|
|
230
|
+
});
|
|
231
|
+
wrap.append(edit, out);
|
|
232
|
+
document.body.appendChild(wrap);
|
|
178
233
|
}
|
|
179
234
|
function wireField(el, token, options) {
|
|
180
235
|
if (el.dataset.cmsRichtext === "true") {
|
|
@@ -186,6 +241,7 @@ function wireField(el, token, options) {
|
|
|
186
241
|
return;
|
|
187
242
|
}
|
|
188
243
|
el.addEventListener("click", (e) => {
|
|
244
|
+
if (!editingActive) return;
|
|
189
245
|
if (el.getAttribute("contenteditable") === "true") return;
|
|
190
246
|
e.preventDefault();
|
|
191
247
|
e.stopPropagation();
|
|
@@ -216,6 +272,7 @@ var richCtx = null;
|
|
|
216
272
|
var richToolbar = null;
|
|
217
273
|
function wireRichField(el, token, options, mode) {
|
|
218
274
|
el.addEventListener("click", (e) => {
|
|
275
|
+
if (!editingActive) return;
|
|
219
276
|
if (richCtx && richCtx.el === el) return;
|
|
220
277
|
e.preventDefault();
|
|
221
278
|
e.stopPropagation();
|
|
@@ -604,10 +661,7 @@ function showActiveBadge(options) {
|
|
|
604
661
|
badge.append(makeIcon(), text);
|
|
605
662
|
badge.addEventListener("mouseenter", () => badge.style.opacity = "1");
|
|
606
663
|
badge.addEventListener("mouseleave", () => badge.style.opacity = ".9");
|
|
607
|
-
badge.addEventListener("click",
|
|
608
|
-
disconnect(options);
|
|
609
|
-
window.location.reload();
|
|
610
|
-
});
|
|
664
|
+
badge.addEventListener("click", exitEditMode);
|
|
611
665
|
document.body.appendChild(badge);
|
|
612
666
|
}
|
|
613
667
|
function decodeJwtPayload(token) {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/field-slice.ts"],"sourcesContent":["/**\n * Browser entry — zero dependencies. Site-wide: activated once per browser\n * via a \"connect\" link (see docs/features/F157-inline-editing.md), then\n * every page load on the site automatically offers click-to-edit on any\n * element carrying data-cms-collection/data-cms-slug/data-cms-field\n * (F129's attribute convention) — no per-document step.\n */\nimport { applyFieldSlice } from \"./field-slice\";\nexport { applyFieldSlice } from \"./field-slice\";\n\n/**\n * Labels for the in-editor UI — the rich-text toolbar (bold/italic/underline\n * tooltips, the visible \"colour\" + \"done\" buttons, the emoji tooltip) and the\n * save-status pill. Every field is optional; unset fields keep the Danish\n * default. Pass an English (or any-locale) set on a non-Danish site so the\n * toolbar and status text match the page language.\n */\nexport interface InlineEditLabels {\n bold?: string;\n italic?: string;\n underline?: string;\n orderedList?: string;\n unorderedList?: string;\n color?: string;\n emoji?: string;\n done?: string;\n saving?: string;\n saved?: string;\n error?: string;\n}\n\nexport interface InlineEditOptions {\n /** Base URL of the CMS API, e.g. \"https://webhouse.app\". */\n cmsBaseUrl: string;\n /** Site id passed as ?site= on every CMS API call, e.g. \"broberg-ai\". */\n siteId: string;\n /** URL query param carrying a freshly-minted token from the connect redirect. Default \"cms_edit\". */\n tokenParam?: string;\n /** localStorage key the token is persisted under — survives across sessions/tabs. Default \"wh-inline-edit-token\". */\n storageKey?: string;\n /** Text for the \"not connected yet\" prompt (a square-pen icon is prepended). Default \"Log ind for at redigere\". */\n connectLabel?: string;\n /** Text for the \"connected\" badge — the whole pill is the exit-edit action (icon prepended). Default \"Afbryd\". */\n disconnectLabel?: string;\n /** Localised labels for the toolbar + save-status pill. Defaults are Danish. */\n labels?: InlineEditLabels;\n}\n\ninterface ResolvedOptions extends Required<Omit<InlineEditOptions, \"labels\">> {\n labels: Required<InlineEditLabels>;\n}\n\nconst DEFAULT_LABELS: Required<InlineEditLabels> = {\n bold: \"Fed\",\n italic: \"Kursiv\",\n underline: \"Understreget\",\n orderedList: \"Nummereret liste\",\n unorderedList: \"Punktliste\",\n color: \"Farve\",\n emoji: \"Indsæt emoji\",\n done: \"Færdig\",\n saving: \"Gemmer…\",\n saved: \"Gemt ✓\",\n error: \"Fejl — prøv igen\",\n};\n\n// Set once from resolved options in initInlineEdit(); read by the (singleton)\n// toolbar and the save-status pill so their signatures stay unchanged. One edit\n// session per page → a single module-level value is safe.\nlet uiLabels: Required<InlineEditLabels> = DEFAULT_LABELS;\n\nfunction resolveOptions(options: InlineEditOptions): ResolvedOptions {\n return {\n tokenParam: \"cms_edit\",\n storageKey: \"wh-inline-edit-token\",\n // No emoji in defaults — the square-pen SVG is the icon; some sites ban emoji.\n connectLabel: \"Log ind for at redigere\",\n disconnectLabel: \"Afbryd\",\n ...options,\n labels: { ...DEFAULT_LABELS, ...(options.labels ?? {}) },\n };\n}\n\nexport async function initInlineEdit(options: InlineEditOptions): Promise<void> {\n if (typeof window === \"undefined\") return;\n const resolved = resolveOptions(options);\n uiLabels = resolved.labels;\n\n captureTokenFromUrl(resolved);\n\n const enabled = await checkEnabled(resolved);\n if (!enabled) return;\n\n const token = getConnectedToken(options);\n if (token) {\n activateEditMode(token, resolved);\n } else {\n showConnectPrompt(resolved);\n // F158 — the connect flow opens in a popup; it posts the freshly-minted\n // token back to this tab. Arm the (origin-validated) receiver.\n listenForTokenMessage(resolved);\n }\n}\n\n/**\n * F158 — receive the edit token from the connect popup via postMessage.\n * Hard origin check (message MUST come from cmsBaseUrl) + type + site + expiry\n * guards before the token is trusted. On success: persist, swap the connect\n * prompt for edit mode — no page reload.\n */\nfunction listenForTokenMessage(options: ResolvedOptions): void {\n let cmsOrigin: string;\n try {\n cmsOrigin = new URL(options.cmsBaseUrl).origin;\n } catch {\n return;\n }\n window.addEventListener(\"message\", (event: MessageEvent) => {\n if (event.origin !== cmsOrigin) return;\n const data = event.data as { type?: string; token?: string; site?: string } | null;\n if (!data || data.type !== \"wh-inline-edit-token\" || typeof data.token !== \"string\") return;\n if (data.site && data.site !== options.siteId) return;\n if (isExpired(data.token)) return;\n if (document.querySelector(\"[data-cms-inline-edit-badge]\")) return; // already active\n localStorage.setItem(options.storageKey, data.token);\n document.querySelector(\"[data-cms-inline-edit-connect]\")?.remove();\n activateEditMode(data.token, options);\n });\n}\n\n/**\n * A valid (non-expired) token already connected in this browser for this\n * site, or null. Also captures a fresh `?cms_edit=` token from the URL\n * first, so a page can call this directly right after the connect redirect\n * without going through initInlineEdit(). Exposed so a site's own /admin\n * page (or any other tool built on the same connected session) can reuse\n * the same storage/expiry logic instead of re-implementing it.\n */\nexport function getConnectedToken(options: InlineEditOptions): string | null {\n if (typeof window === \"undefined\") return null;\n const resolved = resolveOptions(options);\n captureTokenFromUrl(resolved);\n const token = localStorage.getItem(resolved.storageKey);\n if (!token) return null;\n if (isExpired(token)) {\n localStorage.removeItem(resolved.storageKey);\n return null;\n }\n return token;\n}\n\n/** The URL that mints a fresh 30-day site-scoped token and redirects back to `returnUrl`. */\nexport function buildConnectUrl(options: InlineEditOptions, returnUrl: string): string {\n const resolved = resolveOptions(options);\n return (\n `${resolved.cmsBaseUrl}/admin/inline-edit/connect?site=${encodeURIComponent(resolved.siteId)}` +\n `&return=${encodeURIComponent(returnUrl)}`\n );\n}\n\n/** Clears the connected token in this browser (e.g. a \"log out\" action in a site's own /admin panel). */\nexport function disconnect(options: InlineEditOptions): void {\n if (typeof window === \"undefined\") return;\n localStorage.removeItem(resolveOptions(options).storageKey);\n}\n\n/** Captures a token minted by /admin/inline-edit/connect, then strips it from the URL. */\nfunction captureTokenFromUrl(options: ResolvedOptions): void {\n const url = new URL(window.location.href);\n const urlToken = url.searchParams.get(options.tokenParam);\n if (!urlToken) return;\n localStorage.setItem(options.storageKey, urlToken);\n url.searchParams.delete(options.tokenParam);\n window.history.replaceState({}, \"\", url.toString());\n}\n\nasync function checkEnabled(options: ResolvedOptions): Promise<boolean> {\n try {\n const res = await fetch(`${options.cmsBaseUrl}/api/inline-edit/status?site=${options.siteId}`);\n if (!res.ok) return false;\n const body = (await res.json()) as { enabled?: boolean };\n return body.enabled === true;\n } catch {\n return false;\n }\n}\n\nfunction isExpired(token: string): boolean {\n const claims = decodeJwtPayload(token);\n const exp = typeof claims?.exp === \"number\" ? claims.exp : 0;\n return exp <= Date.now() / 1000;\n}\n\n// Lucide \"square-pen\" (https://lucide.dev/icons/square-pen), MIT. Inline SVG so\n// the pill needs no icon-font/runtime dep and inherits `currentColor`. Emoji are\n// deliberately avoided — some consumer sites ban them outright.\nconst SQUARE_PEN_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<path d=\"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7\"/>' +\n '<path d=\"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z\"/>' +\n \"</svg>\";\n\n// Toolbar list-button faces (lucide \"list\" / \"list-ordered\"), inline so no\n// icon-font/runtime dep; stroke inherits the button's white `currentColor`.\nconst UL_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<line x1=\"8\" x2=\"21\" y1=\"6\" y2=\"6\"/><line x1=\"8\" x2=\"21\" y1=\"12\" y2=\"12\"/>' +\n '<line x1=\"8\" x2=\"21\" y1=\"18\" y2=\"18\"/><line x1=\"3\" x2=\"3.01\" y1=\"6\" y2=\"6\"/>' +\n '<line x1=\"3\" x2=\"3.01\" y1=\"12\" y2=\"12\"/><line x1=\"3\" x2=\"3.01\" y1=\"18\" y2=\"18\"/>' +\n \"</svg>\";\n\nconst OL_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<line x1=\"10\" x2=\"21\" y1=\"6\" y2=\"6\"/><line x1=\"10\" x2=\"21\" y1=\"12\" y2=\"12\"/>' +\n '<line x1=\"10\" x2=\"21\" y1=\"18\" y2=\"18\"/><path d=\"M4 6h1v4\"/><path d=\"M4 10h2\"/>' +\n '<path d=\"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1\"/>' +\n \"</svg>\";\n\nfunction makeIcon(): HTMLSpanElement {\n const icon = document.createElement(\"span\");\n icon.style.cssText = \"display:inline-flex;line-height:0;flex:0 0 auto\";\n icon.innerHTML = SQUARE_PEN_SVG;\n return icon;\n}\n\nfunction showConnectPrompt(options: ResolvedOptions): void {\n const connectUrl = buildConnectUrl(options, window.location.href);\n\n const link = document.createElement(\"a\");\n link.href = connectUrl;\n link.setAttribute(\"data-cms-inline-edit-connect\", \"\");\n link.style.cssText =\n \"position:fixed;bottom:16px;left:16px;background:#1c2027;color:#fff;\" +\n \"font:600 12px system-ui,sans-serif;padding:8px 14px;border-radius:999px;\" +\n \"text-decoration:none;z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);\" +\n \"display:inline-flex;align-items:center;gap:7px;\";\n const text = document.createElement(\"span\");\n text.textContent = options.connectLabel;\n link.append(makeIcon(), text);\n // F158 — open the connect flow in a popup so the CMS confirmation screen can\n // say \"close this window\". A user-gesture window.open is not popup-blocked;\n // if it is blocked anyway, fall back to the same-tab redirect (F157 path).\n link.addEventListener(\"click\", (e) => {\n e.preventDefault();\n const popup = window.open(\n connectUrl,\n \"wh-inline-edit-connect\",\n \"width=460,height=640,menubar=no,toolbar=no,location=yes,status=no\",\n );\n if (!popup) window.location.href = connectUrl;\n });\n document.body.appendChild(link);\n}\n\nfunction activateEditMode(token: string, options: ResolvedOptions): void {\n injectStyles();\n showActiveBadge(options);\n\n const fields = document.querySelectorAll<HTMLElement>(\"[data-cms-field]\");\n fields.forEach((el) => wireField(el, token, options));\n}\n\nfunction wireField(el: HTMLElement, token: string, options: ResolvedOptions): void {\n // Rich fields get the floating formatting toolbar. Two save modes:\n // - data-cms-richtext=\"true\" → save as Markdown (article bodies; cms\n // `richtext` contract renders Markdown via marked).\n // - data-cms-html=\"true\" → save innerHTML VERBATIM (intentional-HTML\n // fields: headings/bios/hero with a branded <em class=\"o\"> accent that\n // has no Markdown equivalent — converting would strip it).\n // Everything else stays a plain single-line contenteditable saving textContent.\n if (el.dataset.cmsRichtext === \"true\") {\n wireRichField(el, token, options, \"markdown\");\n return;\n }\n if (el.dataset.cmsHtml === \"true\") {\n wireRichField(el, token, options, \"html\");\n return;\n }\n\n el.addEventListener(\"click\", (e) => {\n if (el.getAttribute(\"contenteditable\") === \"true\") return;\n // Many editable fields (card titles/blurbs) sit inside a clickable <a>/\n // <button> ancestor (the card itself) — without this, \"click to edit\"\n // would immediately navigate away instead of focusing the field.\n e.preventDefault();\n e.stopPropagation();\n el.dataset.cmsOriginalValue = el.textContent ?? \"\";\n el.setAttribute(\"contenteditable\", \"true\");\n el.focus();\n });\n\n el.addEventListener(\"blur\", () => {\n el.removeAttribute(\"contenteditable\");\n const original = el.dataset.cmsOriginalValue ?? \"\";\n const current = el.textContent ?? \"\";\n if (current.trim() === original.trim()) return;\n void saveField(el, current.trim(), token, options);\n });\n\n el.addEventListener(\"paste\", (e) => {\n e.preventDefault();\n const text = e.clipboardData?.getData(\"text/plain\") ?? \"\";\n document.execCommand(\"insertText\", false, text);\n });\n\n el.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Enter\") {\n e.preventDefault();\n el.blur();\n }\n });\n}\n\n/* ─── Rich-text mode (article bodies) ──────────────────────────────────────\n * A single editable region + a floating B/I/U · color · emoji · Done toolbar\n * (the Pitch Vault pattern, minus the iframe/postMessage — we run in the live\n * page's own document). On \"Done\" the region's innerHTML is converted back to\n * Markdown (the cms `richtext` contract: fields store Markdown, not HTML) and\n * saved. Only ONE region is active at a time. */\n\ntype RichMode = \"markdown\" | \"html\";\ninterface RichContext {\n el: HTMLElement;\n token: string;\n options: ResolvedOptions;\n originalHtml: string;\n mode: RichMode;\n}\nlet richCtx: RichContext | null = null;\nlet richToolbar: HTMLElement | null = null;\n\nfunction wireRichField(el: HTMLElement, token: string, options: ResolvedOptions, mode: RichMode): void {\n el.addEventListener(\"click\", (e) => {\n if (richCtx && richCtx.el === el) return; // already editing this region\n e.preventDefault();\n e.stopPropagation();\n activateRich(el, token, options, mode);\n });\n}\n\nfunction activateRich(el: HTMLElement, token: string, options: ResolvedOptions, mode: RichMode): void {\n deactivateRich(); // commit any previously-active region first\n richCtx = { el, token, options, originalHtml: el.innerHTML, mode };\n el.setAttribute(\"contenteditable\", \"true\");\n el.classList.add(\"cms-rich-editing\");\n el.focus();\n showRichToolbar();\n // Let the host page react (e.g. pause a rotating hero carousel while editing).\n document.dispatchEvent(new CustomEvent(\"cms-inline-edit:activate\", { detail: { el } }));\n}\n\nfunction deactivateRich(): void {\n if (!richCtx) return;\n const { el, token, options, originalHtml, mode } = richCtx;\n richCtx = null;\n el.removeAttribute(\"contenteditable\");\n el.classList.remove(\"cms-rich-editing\");\n hideRichToolbar();\n if (el.innerHTML !== originalHtml) {\n const value = mode === \"html\" ? el.innerHTML : htmlToMarkdown(el.innerHTML);\n void saveField(el, value, token, options);\n }\n document.dispatchEvent(new CustomEvent(\"cms-inline-edit:deactivate\", { detail: { el } }));\n}\n\nfunction showRichToolbar(): void {\n if (!richToolbar) richToolbar = buildRichToolbar();\n richToolbar.style.display = \"flex\";\n}\n\nfunction hideRichToolbar(): void {\n if (richToolbar) richToolbar.style.display = \"none\";\n hideEmojiPicker();\n}\n\nfunction toolbarButton(label: string, title: string, onDown: () => void): HTMLButtonElement {\n const b = document.createElement(\"button\");\n b.type = \"button\";\n b.innerHTML = label;\n b.title = title;\n b.style.cssText =\n \"background:none;border:1px solid #3a3f4a;color:#fff;min-width:30px;height:30px;\" +\n \"border-radius:6px;cursor:pointer;font-size:14px;padding:0 8px;line-height:1;\";\n b.addEventListener(\"mouseenter\", () => (b.style.background = \"#2a2f38\"));\n b.addEventListener(\"mouseleave\", () => (b.style.background = \"none\"));\n // mousedown + preventDefault so the contenteditable selection isn't lost.\n b.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n onDown();\n });\n return b;\n}\n\nfunction buildRichToolbar(): HTMLElement {\n const t = document.createElement(\"div\");\n t.setAttribute(\"data-cms-inline-edit-toolbar\", \"\");\n t.style.cssText =\n \"position:fixed;top:14px;left:50%;transform:translateX(-50%);\" +\n \"background:#1c2027;border:1px solid #3a3f4a;border-radius:10px;\" +\n \"padding:6px 10px;display:flex;gap:6px;align-items:center;\" +\n \"z-index:2147483647;box-shadow:0 8px 32px rgba(0,0,0,.5);\" +\n \"font-family:system-ui,sans-serif;\";\n\n t.appendChild(toolbarButton(\"<b>B</b>\", uiLabels.bold, () => document.execCommand(\"bold\")));\n t.appendChild(toolbarButton(\"<i>I</i>\", uiLabels.italic, () => document.execCommand(\"italic\")));\n t.appendChild(toolbarButton(\"<u>U</u>\", uiLabels.underline, () => document.execCommand(\"underline\")));\n\n const sep = () => {\n const s = document.createElement(\"div\");\n s.style.cssText = \"width:1px;height:20px;background:#3a3f4a;\";\n return s;\n };\n t.appendChild(sep());\n\n // Bullet + numbered lists — native execCommand, and the Markdown serializer\n // already round-trips <ul>/<ol> to \"- \" / \"1. \" so no save-path change needed.\n t.appendChild(toolbarButton(UL_SVG, uiLabels.unorderedList, () => document.execCommand(\"insertUnorderedList\")));\n t.appendChild(toolbarButton(OL_SVG, uiLabels.orderedList, () => document.execCommand(\"insertOrderedList\")));\n\n t.appendChild(sep());\n\n // Text color — execCommand foreColor applies to the current selection.\n const clrLabel = document.createElement(\"label\");\n clrLabel.style.cssText = \"display:flex;align-items:center;gap:5px;color:#9aa4b2;font-size:12px;cursor:pointer;\";\n clrLabel.textContent = uiLabels.color;\n const clr = document.createElement(\"input\");\n clr.type = \"color\";\n clr.style.cssText = \"width:28px;height:24px;border:1px solid #3a3f4a;border-radius:5px;cursor:pointer;padding:1px;background:none;\";\n clr.addEventListener(\"mousedown\", (e) => e.stopPropagation());\n clr.addEventListener(\"input\", () => document.execCommand(\"foreColor\", false, clr.value));\n clrLabel.prepend(clr);\n t.appendChild(clrLabel);\n\n t.appendChild(sep());\n\n const emojiBtn = toolbarButton(\"😀\", uiLabels.emoji, () => toggleEmojiPicker(emojiBtn));\n emojiBtn.style.fontSize = \"16px\";\n t.appendChild(emojiBtn);\n\n t.appendChild(sep());\n\n const done = document.createElement(\"button\");\n done.type = \"button\";\n done.textContent = uiLabels.done;\n done.style.cssText =\n \"background:#00b2ff;border:none;color:#04121c;padding:0 14px;height:30px;\" +\n \"border-radius:6px;cursor:pointer;font-size:12px;font-weight:700;\";\n done.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n deactivateRich();\n });\n t.appendChild(done);\n\n document.body.appendChild(t);\n return t;\n}\n\n/* ─── emoji picker (compact) ────────────────────────────────────────────── */\nconst EMOJIS =\n \"😀 😃 😄 😁 😆 😉 😊 😍 🤩 😎 🤔 🙌 👏 👍 👎 🙏 💪 🔥 ⚡ ✨ 🎉 ✅ ❌ 💯 ⭐ 🚀 💡 📈 📉 🧠 ❤️ 🧡 💛 💚 💙 💜 🇩🇰 🇪🇺\".split(\n \" \",\n );\nlet emojiPicker: HTMLElement | null = null;\nlet savedRange: Range | null = null;\n\nfunction toggleEmojiPicker(anchor: HTMLElement): void {\n if (!emojiPicker) emojiPicker = buildEmojiPicker();\n if (emojiPicker.style.display === \"block\") {\n hideEmojiPicker();\n return;\n }\n const sel = window.getSelection();\n if (sel && sel.rangeCount > 0) savedRange = sel.getRangeAt(0).cloneRange();\n const rect = anchor.getBoundingClientRect();\n emojiPicker.style.top = `${rect.bottom + 6}px`;\n emojiPicker.style.left = `${Math.min(rect.left, window.innerWidth - 240)}px`;\n emojiPicker.style.display = \"block\";\n}\n\nfunction hideEmojiPicker(): void {\n if (emojiPicker) emojiPicker.style.display = \"none\";\n}\n\nfunction buildEmojiPicker(): HTMLElement {\n const p = document.createElement(\"div\");\n p.setAttribute(\"data-cms-inline-edit-toolbar\", \"\");\n p.style.cssText =\n \"position:fixed;z-index:2147483646;background:#1c2027;border:1px solid #3a3f4a;\" +\n \"border-radius:10px;padding:8px;width:230px;max-height:200px;overflow-y:auto;\" +\n \"display:none;box-shadow:0 8px 32px rgba(0,0,0,.5);\";\n const grid = document.createElement(\"div\");\n grid.style.cssText = \"display:flex;flex-wrap:wrap;gap:2px;\";\n EMOJIS.forEach((em) => {\n const b = document.createElement(\"button\");\n b.type = \"button\";\n b.textContent = em;\n b.style.cssText =\n \"background:none;border:none;cursor:pointer;border-radius:5px;width:32px;height:32px;font-size:18px;\";\n b.addEventListener(\"mouseenter\", () => (b.style.background = \"#2a2f38\"));\n b.addEventListener(\"mouseleave\", () => (b.style.background = \"none\"));\n b.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n insertEmoji(em);\n });\n grid.appendChild(b);\n });\n p.appendChild(grid);\n document.body.appendChild(p);\n return p;\n}\n\nfunction insertEmoji(emoji: string): void {\n if (!richCtx) return;\n richCtx.el.focus();\n const sel = window.getSelection();\n if (savedRange && sel) {\n sel.removeAllRanges();\n sel.addRange(savedRange);\n }\n document.execCommand(\"insertText\", false, emoji);\n savedRange = null;\n hideEmojiPicker();\n}\n\n// Click outside the active region (and outside the toolbar) commits the edit.\nif (typeof document !== \"undefined\") {\n document.addEventListener(\n \"mousedown\",\n (e) => {\n if (!richCtx) return;\n const target = e.target as HTMLElement | null;\n if (!target) return;\n if (target.closest(\"[data-cms-inline-edit-toolbar]\")) return;\n if (richCtx.el.contains(target)) return;\n deactivateRich();\n },\n true,\n );\n}\n\n/**\n * Sets a value at a dot-path into a plain-data tree, where a numeric segment\n * indexes into an array (e.g. \"slides.2.eyebrow\" — flagship-style nested\n * content; a flat \"heroEyebrow\" is still just a 1-segment path). Bails\n * silently (no throw) if the path doesn't resolve — a stale/malformed path\n * must never crash the save, just fail to apply.\n */\nfunction setDeepField(data: Record<string, unknown>, path: string, value: string): void {\n const parts = path.split(\".\");\n let obj: any = data;\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i] ?? \"\";\n const key: string | number = /^\\d+$/.test(part) ? Number(part) : part;\n if (obj == null || typeof obj !== \"object\" || obj[key] === undefined) return;\n obj = obj[key];\n }\n const last = parts[parts.length - 1] ?? \"\";\n const lastKey: string | number = /^\\d+$/.test(last) ? Number(last) : last;\n if (obj == null || typeof obj !== \"object\") return;\n obj[lastKey] = value;\n}\n\n/**\n * Converts an edited contenteditable region's innerHTML back to Markdown so a\n * rich article body round-trips through the cms `richtext` contract (fields\n * store Markdown, `marked` renders it — NOT HTML). Handles the structures a\n * marked-rendered body + the toolbar produce: headings, paragraphs, emphasis,\n * links, lists, blockquote, code. Formatting with no clean Markdown equivalent\n * (underline, coloured spans) is passed through as inline HTML — `marked`\n * renders inline HTML, so it survives without corrupting the source. Tables and\n * anything unrecognised are passed through as their outerHTML for the same\n * reason: never drop content just because it doesn't map to a Markdown token.\n */\nfunction htmlToMarkdown(html: string): string {\n const container = document.createElement(\"div\");\n container.innerHTML = html;\n return serializeBlockChildren(container).replace(/\\n{3,}/g, \"\\n\\n\").trim() + \"\\n\";\n}\n\nfunction serializeBlockChildren(parent: Node): string {\n const blocks: string[] = [];\n parent.childNodes.forEach((node) => {\n const s = serializeBlock(node).trim();\n if (s) blocks.push(s);\n });\n return blocks.join(\"\\n\\n\");\n}\n\nfunction serializeBlock(node: Node): string {\n if (node.nodeType === Node.TEXT_NODE) return (node.textContent ?? \"\").trim();\n if (node.nodeType !== Node.ELEMENT_NODE) return \"\";\n const el = node as HTMLElement;\n const tag = el.tagName.toLowerCase();\n switch (tag) {\n case \"h1\": return \"# \" + serializeInline(el);\n case \"h2\": return \"## \" + serializeInline(el);\n case \"h3\": return \"### \" + serializeInline(el);\n case \"h4\": return \"#### \" + serializeInline(el);\n case \"h5\": return \"##### \" + serializeInline(el);\n case \"h6\": return \"###### \" + serializeInline(el);\n case \"p\":\n case \"div\":\n return serializeInline(el);\n case \"ul\":\n return serializeList(el, false);\n case \"ol\":\n return serializeList(el, true);\n case \"blockquote\":\n // Serialize the quote's OWN block children (it usually wraps <p>s), then\n // prefix each line with \"> \" — treating it as inline dropped the <p> and\n // left a stray leading space.\n return serializeBlockChildren(el)\n .split(\"\\n\")\n .map((l) => (l ? \"> \" + l : \">\"))\n .join(\"\\n\");\n case \"pre\":\n return \"```\\n\" + (el.textContent ?? \"\").replace(/\\n+$/, \"\") + \"\\n```\";\n case \"hr\":\n return \"---\";\n case \"br\":\n return \"\";\n case \"table\":\n // Rebuild the Markdown pipe table (NOT raw-HTML passthrough) so the\n // consumer's marked renderer re-applies its own table treatment (e.g.\n // broberg's mobile scroll-wrapper) instead of getting a bare <table>.\n return serializeTable(el);\n default:\n return serializeInline(el);\n }\n}\n\nfunction serializeTable(table: HTMLElement): string {\n const cellText = (c: Element) => serializeInline(c).trim().replace(/\\|/g, \"\\\\|\");\n const rows: string[] = [];\n const headCells = Array.from(table.querySelectorAll(\"thead tr\")).flatMap((tr) =>\n Array.from(tr.children).map(cellText),\n );\n if (headCells.length) {\n rows.push(\"| \" + headCells.join(\" | \") + \" |\");\n rows.push(\"| \" + headCells.map(() => \"---\").join(\" | \") + \" |\");\n }\n const bodyRows = table.querySelector(\"tbody\")\n ? Array.from(table.querySelectorAll(\"tbody tr\"))\n : Array.from(table.querySelectorAll(\"tr\")).filter((tr) => !tr.closest(\"thead\"));\n bodyRows.forEach((tr) => {\n rows.push(\"| \" + Array.from(tr.children).map(cellText).join(\" | \") + \" |\");\n });\n return rows.join(\"\\n\");\n}\n\nfunction serializeList(listEl: HTMLElement, ordered: boolean): string {\n const items: string[] = [];\n let n = 1;\n listEl.childNodes.forEach((child) => {\n if (child.nodeType === Node.ELEMENT_NODE && (child as HTMLElement).tagName.toLowerCase() === \"li\") {\n const marker = ordered ? `${n++}. ` : \"- \";\n items.push(marker + serializeInline(child as HTMLElement).trim());\n }\n });\n return items.join(\"\\n\");\n}\n\nfunction serializeInline(node: Node): string {\n let out = \"\";\n node.childNodes.forEach((child) => {\n if (child.nodeType === Node.TEXT_NODE) {\n out += (child.textContent ?? \"\").replace(/\\s+/g, \" \");\n return;\n }\n if (child.nodeType !== Node.ELEMENT_NODE) return;\n const el = child as HTMLElement;\n const tag = el.tagName.toLowerCase();\n const inner = serializeInline(el);\n switch (tag) {\n case \"strong\":\n case \"b\":\n out += inner.trim() ? `**${inner.trim()}**` : \"\";\n break;\n case \"em\":\n case \"i\":\n out += inner.trim() ? `*${inner.trim()}*` : \"\";\n break;\n case \"code\":\n out += \"`\" + inner + \"`\";\n break;\n case \"br\":\n out += \" \\n\";\n break;\n case \"a\": {\n const href = el.getAttribute(\"href\") || \"\";\n out += href ? `[${inner}](${href})` : inner;\n break;\n }\n case \"img\": {\n // Content images embedded in the body () — dropping them\n // would silently delete images from an article on save. Void element,\n // no children, so this must be handled explicitly.\n const src = el.getAttribute(\"src\") || \"\";\n const alt = el.getAttribute(\"alt\") || \"\";\n if (src) out += ``;\n break;\n }\n case \"u\":\n out += `<u>${inner}</u>`; // no Markdown for underline — pass through\n break;\n case \"span\":\n case \"font\": {\n const color = el.style.color || el.getAttribute(\"color\") || \"\";\n out += color ? `<span style=\"color:${color}\">${inner}</span>` : inner;\n break;\n }\n default:\n out += inner;\n }\n });\n return out;\n}\n\nasync function saveField(el: HTMLElement, value: string, token: string, options: ResolvedOptions): Promise<void> {\n const collection = el.dataset.cmsCollection;\n const slug = el.dataset.cmsSlug;\n const field = el.dataset.cmsField;\n if (!collection || !slug || !field) return;\n const slice = el.dataset.cmsSlice;\n\n showPill(el, \"saving\");\n try {\n const getRes = await fetch(\n `${options.cmsBaseUrl}/api/cms/${collection}/${slug}?site=${options.siteId}`,\n { headers: { Authorization: `Bearer ${token}` } },\n );\n if (!getRes.ok) throw new Error(`GET failed: ${getRes.status}`);\n const doc = (await getRes.json()) as { data?: Record<string, unknown> };\n // Deep-clone so mutating a nested array/object (dot-path saves) never\n // aliases the fetched doc — same safety whether field is flat or nested.\n const mergedData = JSON.parse(JSON.stringify(doc.data ?? {})) as Record<string, unknown>;\n if (slice !== undefined) {\n // Field-slice save: replace just this segment inside the full field value,\n // preserving every other segment + embed. Aborts on a non-unique match.\n const currentVal = typeof mergedData[field] === \"string\" ? (mergedData[field] as string) : \"\";\n mergedData[field] = applyFieldSlice(currentVal, slice, value);\n } else if (field.includes(\".\")) {\n setDeepField(mergedData, field, value);\n } else {\n mergedData[field] = value;\n }\n\n const patchRes = await fetch(\n `${options.cmsBaseUrl}/api/cms/${collection}/${slug}?site=${options.siteId}`,\n {\n method: \"PATCH\",\n headers: { Authorization: `Bearer ${token}`, \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ data: mergedData }),\n },\n );\n if (!patchRes.ok) throw new Error(`PATCH failed: ${patchRes.status}`);\n // The slice we just wrote is now the current text — track it so a second\n // edit of the same segment (no reload) matches against the new value.\n if (slice !== undefined) el.dataset.cmsSlice = value;\n showPill(el, \"saved\");\n } catch {\n showPill(el, \"error\");\n }\n}\n\nconst pills = new WeakMap<HTMLElement, HTMLElement>();\n\nfunction showPill(el: HTMLElement, state: \"saving\" | \"saved\" | \"error\"): void {\n let pill = pills.get(el);\n if (!pill) {\n pill = document.createElement(\"span\");\n pill.setAttribute(\"data-cms-inline-edit-pill\", \"\");\n document.body.appendChild(pill);\n pills.set(el, pill);\n }\n const rect = el.getBoundingClientRect();\n pill.style.cssText =\n `position:fixed;top:${rect.top - 26}px;left:${rect.left}px;font:600 11px system-ui,sans-serif;` +\n `padding:3px 9px;border-radius:5px;z-index:2147483647;pointer-events:none;` +\n `box-shadow:0 2px 8px rgba(0,0,0,.25);`;\n\n if (state === \"saving\") {\n pill.textContent = uiLabels.saving;\n pill.style.background = \"#1c2027\";\n pill.style.color = \"#fff\";\n } else if (state === \"saved\") {\n pill.textContent = uiLabels.saved;\n pill.style.background = \"#16a34a\";\n pill.style.color = \"#fff\";\n setTimeout(() => {\n pill?.remove();\n pills.delete(el);\n }, 1500);\n } else {\n pill.textContent = uiLabels.error;\n pill.style.background = \"#dc2626\";\n pill.style.color = \"#fff\";\n }\n}\n\nfunction showActiveBadge(options: ResolvedOptions): void {\n // The connected badge IS the exit-edit action: [icon] \"Afslut redigering\".\n // No \"Redigerer som {name}\" — the whole pill is one click to leave edit mode.\n const badge = document.createElement(\"button\");\n badge.type = \"button\";\n badge.setAttribute(\"data-cms-inline-edit-badge\", \"\");\n badge.style.cssText =\n \"position:fixed;bottom:16px;left:16px;display:inline-flex;align-items:center;gap:7px;\" +\n \"background:#1c2027;color:#fff;font:600 12px system-ui,sans-serif;padding:8px 14px;\" +\n \"border-radius:999px;z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);\" +\n \"border:none;cursor:pointer;opacity:.9;transition:opacity .15s;\";\n const text = document.createElement(\"span\");\n text.textContent = options.disconnectLabel;\n badge.append(makeIcon(), text);\n badge.addEventListener(\"mouseenter\", () => (badge.style.opacity = \"1\"));\n badge.addEventListener(\"mouseleave\", () => (badge.style.opacity = \".9\"));\n badge.addEventListener(\"click\", () => {\n disconnect(options);\n window.location.reload();\n });\n document.body.appendChild(badge);\n}\n\n/** Reads JWT claims for DISPLAY ONLY — never used for authorization decisions. */\nfunction decodeJwtPayload(token: string): Record<string, unknown> | null {\n try {\n const payload = token.split(\".\")[1];\n if (!payload) return null;\n return JSON.parse(atob(payload.replace(/-/g, \"+\").replace(/_/g, \"/\")));\n } catch {\n return null;\n }\n}\n\nfunction injectStyles(): void {\n const style = document.createElement(\"style\");\n style.textContent = `\n [data-cms-field] { outline: 1px dashed transparent; outline-offset: 2px; cursor: text; transition: outline-color .15s; }\n [data-cms-field]:hover { outline-color: rgba(0,178,255,.5); }\n [data-cms-field][contenteditable=\"true\"] { outline: 2px solid #00b2ff; outline-offset: 2px; }\n [data-cms-field][data-cms-richtext=\"true\"] { cursor: text; }\n .cms-rich-editing { outline: 2px solid #00b2ff !important; outline-offset: 6px; border-radius: 4px; }\n `;\n document.head.appendChild(style);\n}\n","/**\n * Replace ONE slice of a larger text field.\n *\n * Used when an element renders a single SEGMENT of a bigger field — e.g. one\n * prose paragraph of a `content` body that is interleaved with `[block:]`\n * embeds — so editing that segment must write back into the full field without\n * clobbering the other segments or the embeds.\n *\n * Safety-first: throws if `original` is not found EXACTLY once, so an ambiguous\n * or stale slice ABORTS the save (surfaced as the error pill) instead of\n * corrupting the whole field. Pure + framework-agnostic; unit-tested.\n */\nexport function applyFieldSlice(current: string, original: string, next: string): string {\n const first = current.indexOf(original);\n if (first === -1) throw new Error(\"field-slice: original not found\");\n if (current.indexOf(original, first + original.length) !== -1) {\n throw new Error(\"field-slice: original found more than once (ambiguous)\");\n }\n return current.slice(0, first) + next + current.slice(first + original.length);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,SAAS,gBAAgB,SAAiB,UAAkB,MAAsB;AACvF,QAAM,QAAQ,QAAQ,QAAQ,QAAQ;AACtC,MAAI,UAAU,GAAI,OAAM,IAAI,MAAM,iCAAiC;AACnE,MAAI,QAAQ,QAAQ,UAAU,QAAQ,SAAS,MAAM,MAAM,IAAI;AAC7D,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO,QAAQ,MAAM,GAAG,KAAK,IAAI,OAAO,QAAQ,MAAM,QAAQ,SAAS,MAAM;AAC/E;;;ADiCA,IAAM,iBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,aAAa;AAAA,EACb,eAAe;AAAA,EACf,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AACT;AAKA,IAAI,WAAuC;AAE3C,SAAS,eAAe,SAA6C;AACnE,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,YAAY;AAAA;AAAA,IAEZ,cAAc;AAA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K,QAAQ,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG,CAAC,CAAC;AAAA,EACvE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,eAAqB;AAC5B,QAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,QAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOpB,WAAS,KAAK,YAAY,KAAK;AACjC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/field-slice.ts"],"sourcesContent":["/**\n * Browser entry — zero dependencies. Site-wide: activated once per browser\n * via a \"connect\" link (see docs/features/F157-inline-editing.md), then\n * every page load on the site automatically offers click-to-edit on any\n * element carrying data-cms-collection/data-cms-slug/data-cms-field\n * (F129's attribute convention) — no per-document step.\n */\nimport { applyFieldSlice } from \"./field-slice\";\nexport { applyFieldSlice } from \"./field-slice\";\n\n/**\n * Labels for the in-editor UI — the rich-text toolbar (bold/italic/underline\n * tooltips, the visible \"colour\" + \"done\" buttons, the emoji tooltip) and the\n * save-status pill. Every field is optional; unset fields keep the Danish\n * default. Pass an English (or any-locale) set on a non-Danish site so the\n * toolbar and status text match the page language.\n */\nexport interface InlineEditLabels {\n bold?: string;\n italic?: string;\n underline?: string;\n orderedList?: string;\n unorderedList?: string;\n color?: string;\n emoji?: string;\n done?: string;\n saving?: string;\n saved?: string;\n error?: string;\n}\n\nexport interface InlineEditOptions {\n /** Base URL of the CMS API, e.g. \"https://webhouse.app\". */\n cmsBaseUrl: string;\n /** Site id passed as ?site= on every CMS API call, e.g. \"broberg-ai\". */\n siteId: string;\n /** URL query param carrying a freshly-minted token from the connect redirect. Default \"cms_edit\". */\n tokenParam?: string;\n /** localStorage key the token is persisted under — survives across sessions/tabs. Default \"wh-inline-edit-token\". */\n storageKey?: string;\n /** Text for the \"not connected yet\" prompt (a square-pen icon is prepended). Default \"Log ind for at redigere\". */\n connectLabel?: string;\n /** Text for the \"connected + editing\" badge — clicking it LEAVES edit mode but keeps the login (icon prepended). Default \"Afbryd\". */\n disconnectLabel?: string;\n /** Text for the explicit \"log out\" action on the idle pill — clicking it clears the token (back to the logged-out state). Default \"Log ud\". */\n logoutLabel?: string;\n /** Show an on-site \"connect\" pill to LOGGED-OUT visitors (click → connect flow).\n * Default FALSE — customer-safe: a visitor without a token sees NOTHING. Only\n * enable for a site with no real customers (e.g. an internal/first-party site)\n * where a self-contained on-site login entry is wanted. The safe entry for a\n * customer site is always the \"Redigér live\" button in webhouse.app CMS-admin. */\n connectPrompt?: boolean;\n /** Localised labels for the toolbar + save-status pill. Defaults are Danish. */\n labels?: InlineEditLabels;\n}\n\ninterface ResolvedOptions extends Required<Omit<InlineEditOptions, \"labels\">> {\n labels: Required<InlineEditLabels>;\n}\n\nconst DEFAULT_LABELS: Required<InlineEditLabels> = {\n bold: \"Fed\",\n italic: \"Kursiv\",\n underline: \"Understreget\",\n orderedList: \"Nummereret liste\",\n unorderedList: \"Punktliste\",\n color: \"Farve\",\n emoji: \"Indsæt emoji\",\n done: \"Færdig\",\n saving: \"Gemmer…\",\n saved: \"Gemt ✓\",\n error: \"Fejl — prøv igen\",\n};\n\n// Set once from resolved options in initInlineEdit(); read by the (singleton)\n// toolbar and the save-status pill so their signatures stay unchanged. One edit\n// session per page → a single module-level value is safe.\nlet uiLabels: Required<InlineEditLabels> = DEFAULT_LABELS;\n\nfunction resolveOptions(options: InlineEditOptions): ResolvedOptions {\n return {\n tokenParam: \"cms_edit\",\n storageKey: \"wh-inline-edit-token\",\n // No emoji in defaults — the square-pen SVG is the icon; some sites ban emoji.\n connectLabel: \"Log ind for at redigere\",\n disconnectLabel: \"Afbryd\",\n logoutLabel: \"Log ud\",\n connectPrompt: false,\n ...options,\n labels: { ...DEFAULT_LABELS, ...(options.labels ?? {}) },\n };\n}\n\nexport async function initInlineEdit(options: InlineEditOptions): Promise<void> {\n if (typeof window === \"undefined\") return;\n const resolved = resolveOptions(options);\n uiLabels = resolved.labels;\n\n // Capture BEFORE checkEnabled so we know whether the token JUST arrived from\n // the connect redirect (→ drop straight into edit mode) vs. a normal load\n // with a stored token (→ idle \"Rediger\" pill, don't force edit mode).\n const freshFromUrl = captureTokenFromUrl(resolved);\n\n const enabled = await checkEnabled(resolved);\n if (!enabled) return;\n\n const token = getConnectedToken(options);\n if (!token) {\n // Logged-out visitor / customer. DEFAULT: show NOTHING (customer-safe) —\n // the consumer can now call initInlineEdit() unconditionally without leaking\n // an edit affordance. Only sites that opt in (connectPrompt: true) get the\n // on-site connect pill + its popup token receiver.\n if (resolved.connectPrompt) {\n showConnectPrompt(resolved);\n // F158 — the connect flow opens in a popup; it posts the freshly-minted\n // token back to this tab. Arm the (origin-validated) receiver.\n listenForTokenMessage(resolved);\n }\n return;\n }\n\n // Connected editor. Wire fields once, then pick the entry state: arrived from\n // connect → edit now; normal load with a stored token → idle \"Rediger\" pill\n // (one click enters edit mode; the token persists so \"Rediger\" stays visible\n // on every page while logged in — no trip back to admin).\n setupFields(token, resolved);\n if (freshFromUrl) enterEditMode();\n else showIdlePill();\n}\n\n/**\n * F158 — receive the edit token from the connect popup via postMessage.\n * Hard origin check (message MUST come from cmsBaseUrl) + type + site + expiry\n * guards before the token is trusted. On success: persist, swap the connect\n * prompt for edit mode — no page reload.\n */\nfunction listenForTokenMessage(options: ResolvedOptions): void {\n let cmsOrigin: string;\n try {\n cmsOrigin = new URL(options.cmsBaseUrl).origin;\n } catch {\n return;\n }\n window.addEventListener(\"message\", (event: MessageEvent) => {\n if (event.origin !== cmsOrigin) return;\n const data = event.data as { type?: string; token?: string; site?: string } | null;\n if (!data || data.type !== \"wh-inline-edit-token\" || typeof data.token !== \"string\") return;\n if (data.site && data.site !== options.siteId) return;\n if (isExpired(data.token)) return;\n if (document.querySelector(\"[data-cms-inline-edit-badge]\")) return; // already active\n localStorage.setItem(options.storageKey, data.token);\n document.querySelector(\"[data-cms-inline-edit-connect]\")?.remove();\n // Fresh connect via popup → wire fields + drop straight into edit mode.\n setupFields(data.token, options);\n enterEditMode();\n });\n}\n\n/**\n * A valid (non-expired) token already connected in this browser for this\n * site, or null. Also captures a fresh `?cms_edit=` token from the URL\n * first, so a page can call this directly right after the connect redirect\n * without going through initInlineEdit(). Exposed so a site's own /admin\n * page (or any other tool built on the same connected session) can reuse\n * the same storage/expiry logic instead of re-implementing it.\n */\nexport function getConnectedToken(options: InlineEditOptions): string | null {\n if (typeof window === \"undefined\") return null;\n const resolved = resolveOptions(options);\n captureTokenFromUrl(resolved);\n const token = localStorage.getItem(resolved.storageKey);\n if (!token) return null;\n if (isExpired(token)) {\n localStorage.removeItem(resolved.storageKey);\n return null;\n }\n return token;\n}\n\n/** The URL that mints a fresh 30-day site-scoped token and redirects back to `returnUrl`. */\nexport function buildConnectUrl(options: InlineEditOptions, returnUrl: string): string {\n const resolved = resolveOptions(options);\n return (\n `${resolved.cmsBaseUrl}/admin/inline-edit/connect?site=${encodeURIComponent(resolved.siteId)}` +\n `&return=${encodeURIComponent(returnUrl)}`\n );\n}\n\n/** Clears the connected token in this browser (e.g. a \"log out\" action in a site's own /admin panel). */\nexport function disconnect(options: InlineEditOptions): void {\n if (typeof window === \"undefined\") return;\n localStorage.removeItem(resolveOptions(options).storageKey);\n}\n\n/** Captures a token minted by /admin/inline-edit/connect, then strips it from\n * the URL. Returns true when a FRESH token was just captured from the URL\n * (i.e. this is the connect-redirect landing) so the caller can auto-enter\n * edit mode; false on a normal load where the token comes from localStorage. */\nfunction captureTokenFromUrl(options: ResolvedOptions): boolean {\n const url = new URL(window.location.href);\n const urlToken = url.searchParams.get(options.tokenParam);\n if (!urlToken) return false;\n localStorage.setItem(options.storageKey, urlToken);\n url.searchParams.delete(options.tokenParam);\n window.history.replaceState({}, \"\", url.toString());\n return true;\n}\n\nasync function checkEnabled(options: ResolvedOptions): Promise<boolean> {\n try {\n const res = await fetch(`${options.cmsBaseUrl}/api/inline-edit/status?site=${options.siteId}`);\n if (!res.ok) return false;\n const body = (await res.json()) as { enabled?: boolean };\n return body.enabled === true;\n } catch {\n return false;\n }\n}\n\nfunction isExpired(token: string): boolean {\n const claims = decodeJwtPayload(token);\n const exp = typeof claims?.exp === \"number\" ? claims.exp : 0;\n return exp <= Date.now() / 1000;\n}\n\n// Lucide \"square-pen\" (https://lucide.dev/icons/square-pen), MIT. Inline SVG so\n// the pill needs no icon-font/runtime dep and inherits `currentColor`. Emoji are\n// deliberately avoided — some consumer sites ban them outright.\nconst SQUARE_PEN_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<path d=\"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7\"/>' +\n '<path d=\"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z\"/>' +\n \"</svg>\";\n\n// Toolbar list-button faces (lucide \"list\" / \"list-ordered\"), inline so no\n// icon-font/runtime dep; stroke inherits the button's white `currentColor`.\nconst UL_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<line x1=\"8\" x2=\"21\" y1=\"6\" y2=\"6\"/><line x1=\"8\" x2=\"21\" y1=\"12\" y2=\"12\"/>' +\n '<line x1=\"8\" x2=\"21\" y1=\"18\" y2=\"18\"/><line x1=\"3\" x2=\"3.01\" y1=\"6\" y2=\"6\"/>' +\n '<line x1=\"3\" x2=\"3.01\" y1=\"12\" y2=\"12\"/><line x1=\"3\" x2=\"3.01\" y1=\"18\" y2=\"18\"/>' +\n \"</svg>\";\n\nconst OL_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<line x1=\"10\" x2=\"21\" y1=\"6\" y2=\"6\"/><line x1=\"10\" x2=\"21\" y1=\"12\" y2=\"12\"/>' +\n '<line x1=\"10\" x2=\"21\" y1=\"18\" y2=\"18\"/><path d=\"M4 6h1v4\"/><path d=\"M4 10h2\"/>' +\n '<path d=\"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1\"/>' +\n \"</svg>\";\n\nfunction makeIcon(): HTMLSpanElement {\n const icon = document.createElement(\"span\");\n icon.style.cssText = \"display:inline-flex;line-height:0;flex:0 0 auto\";\n icon.innerHTML = SQUARE_PEN_SVG;\n return icon;\n}\n\nfunction showConnectPrompt(options: ResolvedOptions): void {\n const connectUrl = buildConnectUrl(options, window.location.href);\n\n const link = document.createElement(\"a\");\n link.href = connectUrl;\n link.setAttribute(\"data-cms-inline-edit-connect\", \"\");\n link.style.cssText =\n \"position:fixed;bottom:16px;left:16px;background:#1c2027;color:#fff;\" +\n \"font:600 12px system-ui,sans-serif;padding:8px 14px;border-radius:999px;\" +\n \"text-decoration:none;z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);\" +\n \"display:inline-flex;align-items:center;gap:7px;\";\n const text = document.createElement(\"span\");\n text.textContent = options.connectLabel;\n link.append(makeIcon(), text);\n // F158 — open the connect flow in a popup so the CMS confirmation screen can\n // say \"close this window\". A user-gesture window.open is not popup-blocked;\n // if it is blocked anyway, fall back to the same-tab redirect (F157 path).\n link.addEventListener(\"click\", (e) => {\n e.preventDefault();\n const popup = window.open(\n connectUrl,\n \"wh-inline-edit-connect\",\n \"width=460,height=640,menubar=no,toolbar=no,location=yes,status=no\",\n );\n if (!popup) window.location.href = connectUrl;\n });\n document.body.appendChild(link);\n}\n\n// ─── Connected-editor state machine ────────────────────────────────────────\n// A connected editor (valid token) is ALWAYS in one of two visible states:\n// idle → a \"Rediger\" pill (options.connectLabel); one click enters editing.\n// editing → fields are contenteditable + an \"Afslut redigering\" pill.\n// Leaving edit mode returns to idle and KEEPS the token — the editor stays\n// logged in and can re-enter with one click, on every page, for the token's\n// whole life. Only an explicit \"Log ud\" clears the token (→ logged-out state:\n// no pill at all, same as a customer). Fields are wired ONCE; their click\n// handlers no-op while editingActive is false, so idle is truly inert.\nlet editingActive = false;\nlet fieldsWired = false;\nlet stateOptions: ResolvedOptions | null = null;\n\nfunction setupFields(token: string, options: ResolvedOptions): void {\n stateOptions = options;\n if (fieldsWired) return;\n injectStyles();\n document.querySelectorAll<HTMLElement>(\"[data-cms-field]\").forEach((el) => wireField(el, token, options));\n fieldsWired = true;\n}\n\nfunction enterEditMode(): void {\n if (!stateOptions || editingActive) return;\n editingActive = true;\n removeIdlePill();\n showActiveBadge(stateOptions);\n}\n\nfunction exitEditMode(): void {\n if (!stateOptions || !editingActive) return;\n deactivateRich(); // commit any active rich region first\n editingActive = false;\n document.querySelector(\"[data-cms-inline-edit-badge]\")?.remove();\n showIdlePill();\n}\n\nfunction removeIdlePill(): void {\n document.querySelector(\"[data-cms-inline-edit-idle]\")?.remove();\n}\n\nfunction showIdlePill(): void {\n if (!stateOptions) return;\n const options = stateOptions;\n removeIdlePill();\n const wrap = document.createElement(\"div\");\n wrap.setAttribute(\"data-cms-inline-edit-idle\", \"\");\n wrap.style.cssText =\n \"position:fixed;bottom:16px;left:16px;display:inline-flex;align-items:stretch;\" +\n \"z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);border-radius:999px;overflow:hidden;\";\n // Main action: \"Rediger\" → enter edit mode (no server round-trip; the token\n // already exists locally).\n const edit = document.createElement(\"button\");\n edit.type = \"button\";\n edit.setAttribute(\"data-cms-inline-edit-enter\", \"\");\n edit.style.cssText =\n \"display:inline-flex;align-items:center;gap:7px;background:#1c2027;color:#fff;\" +\n \"font:600 12px system-ui,sans-serif;padding:8px 14px;border:none;cursor:pointer;\";\n const editText = document.createElement(\"span\");\n editText.textContent = options.connectLabel;\n edit.append(makeIcon(), editText);\n edit.addEventListener(\"click\", enterEditMode);\n // Secondary: \"Log ud\" → clear the token (back to the logged-out state).\n const out = document.createElement(\"button\");\n out.type = \"button\";\n out.setAttribute(\"data-cms-inline-edit-logout\", \"\");\n out.textContent = options.logoutLabel;\n out.style.cssText =\n \"background:#141821;color:#9aa4b2;font:600 11px system-ui,sans-serif;padding:8px 12px;\" +\n \"border:none;border-left:1px solid rgba(255,255,255,.12);cursor:pointer;\";\n out.addEventListener(\"click\", () => {\n disconnect(options);\n removeIdlePill();\n });\n wrap.append(edit, out);\n document.body.appendChild(wrap);\n}\n\nfunction wireField(el: HTMLElement, token: string, options: ResolvedOptions): void {\n // Rich fields get the floating formatting toolbar. Two save modes:\n // - data-cms-richtext=\"true\" → save as Markdown (article bodies; cms\n // `richtext` contract renders Markdown via marked).\n // - data-cms-html=\"true\" → save innerHTML VERBATIM (intentional-HTML\n // fields: headings/bios/hero with a branded <em class=\"o\"> accent that\n // has no Markdown equivalent — converting would strip it).\n // Everything else stays a plain single-line contenteditable saving textContent.\n if (el.dataset.cmsRichtext === \"true\") {\n wireRichField(el, token, options, \"markdown\");\n return;\n }\n if (el.dataset.cmsHtml === \"true\") {\n wireRichField(el, token, options, \"html\");\n return;\n }\n\n el.addEventListener(\"click\", (e) => {\n if (!editingActive) return; // idle: the field behaves normally, not editable\n if (el.getAttribute(\"contenteditable\") === \"true\") return;\n // Many editable fields (card titles/blurbs) sit inside a clickable <a>/\n // <button> ancestor (the card itself) — without this, \"click to edit\"\n // would immediately navigate away instead of focusing the field.\n e.preventDefault();\n e.stopPropagation();\n el.dataset.cmsOriginalValue = el.textContent ?? \"\";\n el.setAttribute(\"contenteditable\", \"true\");\n el.focus();\n });\n\n el.addEventListener(\"blur\", () => {\n el.removeAttribute(\"contenteditable\");\n const original = el.dataset.cmsOriginalValue ?? \"\";\n const current = el.textContent ?? \"\";\n if (current.trim() === original.trim()) return;\n void saveField(el, current.trim(), token, options);\n });\n\n el.addEventListener(\"paste\", (e) => {\n e.preventDefault();\n const text = e.clipboardData?.getData(\"text/plain\") ?? \"\";\n document.execCommand(\"insertText\", false, text);\n });\n\n el.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Enter\") {\n e.preventDefault();\n el.blur();\n }\n });\n}\n\n/* ─── Rich-text mode (article bodies) ──────────────────────────────────────\n * A single editable region + a floating B/I/U · color · emoji · Done toolbar\n * (the Pitch Vault pattern, minus the iframe/postMessage — we run in the live\n * page's own document). On \"Done\" the region's innerHTML is converted back to\n * Markdown (the cms `richtext` contract: fields store Markdown, not HTML) and\n * saved. Only ONE region is active at a time. */\n\ntype RichMode = \"markdown\" | \"html\";\ninterface RichContext {\n el: HTMLElement;\n token: string;\n options: ResolvedOptions;\n originalHtml: string;\n mode: RichMode;\n}\nlet richCtx: RichContext | null = null;\nlet richToolbar: HTMLElement | null = null;\n\nfunction wireRichField(el: HTMLElement, token: string, options: ResolvedOptions, mode: RichMode): void {\n el.addEventListener(\"click\", (e) => {\n if (!editingActive) return; // idle: the field behaves normally, not editable\n if (richCtx && richCtx.el === el) return; // already editing this region\n e.preventDefault();\n e.stopPropagation();\n activateRich(el, token, options, mode);\n });\n}\n\nfunction activateRich(el: HTMLElement, token: string, options: ResolvedOptions, mode: RichMode): void {\n deactivateRich(); // commit any previously-active region first\n richCtx = { el, token, options, originalHtml: el.innerHTML, mode };\n el.setAttribute(\"contenteditable\", \"true\");\n el.classList.add(\"cms-rich-editing\");\n el.focus();\n showRichToolbar();\n // Let the host page react (e.g. pause a rotating hero carousel while editing).\n document.dispatchEvent(new CustomEvent(\"cms-inline-edit:activate\", { detail: { el } }));\n}\n\nfunction deactivateRich(): void {\n if (!richCtx) return;\n const { el, token, options, originalHtml, mode } = richCtx;\n richCtx = null;\n el.removeAttribute(\"contenteditable\");\n el.classList.remove(\"cms-rich-editing\");\n hideRichToolbar();\n if (el.innerHTML !== originalHtml) {\n const value = mode === \"html\" ? el.innerHTML : htmlToMarkdown(el.innerHTML);\n void saveField(el, value, token, options);\n }\n document.dispatchEvent(new CustomEvent(\"cms-inline-edit:deactivate\", { detail: { el } }));\n}\n\nfunction showRichToolbar(): void {\n if (!richToolbar) richToolbar = buildRichToolbar();\n richToolbar.style.display = \"flex\";\n}\n\nfunction hideRichToolbar(): void {\n if (richToolbar) richToolbar.style.display = \"none\";\n hideEmojiPicker();\n}\n\nfunction toolbarButton(label: string, title: string, onDown: () => void): HTMLButtonElement {\n const b = document.createElement(\"button\");\n b.type = \"button\";\n b.innerHTML = label;\n b.title = title;\n b.style.cssText =\n \"background:none;border:1px solid #3a3f4a;color:#fff;min-width:30px;height:30px;\" +\n \"border-radius:6px;cursor:pointer;font-size:14px;padding:0 8px;line-height:1;\";\n b.addEventListener(\"mouseenter\", () => (b.style.background = \"#2a2f38\"));\n b.addEventListener(\"mouseleave\", () => (b.style.background = \"none\"));\n // mousedown + preventDefault so the contenteditable selection isn't lost.\n b.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n onDown();\n });\n return b;\n}\n\nfunction buildRichToolbar(): HTMLElement {\n const t = document.createElement(\"div\");\n t.setAttribute(\"data-cms-inline-edit-toolbar\", \"\");\n t.style.cssText =\n \"position:fixed;top:14px;left:50%;transform:translateX(-50%);\" +\n \"background:#1c2027;border:1px solid #3a3f4a;border-radius:10px;\" +\n \"padding:6px 10px;display:flex;gap:6px;align-items:center;\" +\n \"z-index:2147483647;box-shadow:0 8px 32px rgba(0,0,0,.5);\" +\n \"font-family:system-ui,sans-serif;\";\n\n t.appendChild(toolbarButton(\"<b>B</b>\", uiLabels.bold, () => document.execCommand(\"bold\")));\n t.appendChild(toolbarButton(\"<i>I</i>\", uiLabels.italic, () => document.execCommand(\"italic\")));\n t.appendChild(toolbarButton(\"<u>U</u>\", uiLabels.underline, () => document.execCommand(\"underline\")));\n\n const sep = () => {\n const s = document.createElement(\"div\");\n s.style.cssText = \"width:1px;height:20px;background:#3a3f4a;\";\n return s;\n };\n t.appendChild(sep());\n\n // Bullet + numbered lists — native execCommand, and the Markdown serializer\n // already round-trips <ul>/<ol> to \"- \" / \"1. \" so no save-path change needed.\n t.appendChild(toolbarButton(UL_SVG, uiLabels.unorderedList, () => document.execCommand(\"insertUnorderedList\")));\n t.appendChild(toolbarButton(OL_SVG, uiLabels.orderedList, () => document.execCommand(\"insertOrderedList\")));\n\n t.appendChild(sep());\n\n // Text color — execCommand foreColor applies to the current selection.\n const clrLabel = document.createElement(\"label\");\n clrLabel.style.cssText = \"display:flex;align-items:center;gap:5px;color:#9aa4b2;font-size:12px;cursor:pointer;\";\n clrLabel.textContent = uiLabels.color;\n const clr = document.createElement(\"input\");\n clr.type = \"color\";\n clr.style.cssText = \"width:28px;height:24px;border:1px solid #3a3f4a;border-radius:5px;cursor:pointer;padding:1px;background:none;\";\n clr.addEventListener(\"mousedown\", (e) => e.stopPropagation());\n clr.addEventListener(\"input\", () => document.execCommand(\"foreColor\", false, clr.value));\n clrLabel.prepend(clr);\n t.appendChild(clrLabel);\n\n t.appendChild(sep());\n\n const emojiBtn = toolbarButton(\"😀\", uiLabels.emoji, () => toggleEmojiPicker(emojiBtn));\n emojiBtn.style.fontSize = \"16px\";\n t.appendChild(emojiBtn);\n\n t.appendChild(sep());\n\n const done = document.createElement(\"button\");\n done.type = \"button\";\n done.textContent = uiLabels.done;\n done.style.cssText =\n \"background:#00b2ff;border:none;color:#04121c;padding:0 14px;height:30px;\" +\n \"border-radius:6px;cursor:pointer;font-size:12px;font-weight:700;\";\n done.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n deactivateRich();\n });\n t.appendChild(done);\n\n document.body.appendChild(t);\n return t;\n}\n\n/* ─── emoji picker (compact) ────────────────────────────────────────────── */\nconst EMOJIS =\n \"😀 😃 😄 😁 😆 😉 😊 😍 🤩 😎 🤔 🙌 👏 👍 👎 🙏 💪 🔥 ⚡ ✨ 🎉 ✅ ❌ 💯 ⭐ 🚀 💡 📈 📉 🧠 ❤️ 🧡 💛 💚 💙 💜 🇩🇰 🇪🇺\".split(\n \" \",\n );\nlet emojiPicker: HTMLElement | null = null;\nlet savedRange: Range | null = null;\n\nfunction toggleEmojiPicker(anchor: HTMLElement): void {\n if (!emojiPicker) emojiPicker = buildEmojiPicker();\n if (emojiPicker.style.display === \"block\") {\n hideEmojiPicker();\n return;\n }\n const sel = window.getSelection();\n if (sel && sel.rangeCount > 0) savedRange = sel.getRangeAt(0).cloneRange();\n const rect = anchor.getBoundingClientRect();\n emojiPicker.style.top = `${rect.bottom + 6}px`;\n emojiPicker.style.left = `${Math.min(rect.left, window.innerWidth - 240)}px`;\n emojiPicker.style.display = \"block\";\n}\n\nfunction hideEmojiPicker(): void {\n if (emojiPicker) emojiPicker.style.display = \"none\";\n}\n\nfunction buildEmojiPicker(): HTMLElement {\n const p = document.createElement(\"div\");\n p.setAttribute(\"data-cms-inline-edit-toolbar\", \"\");\n p.style.cssText =\n \"position:fixed;z-index:2147483646;background:#1c2027;border:1px solid #3a3f4a;\" +\n \"border-radius:10px;padding:8px;width:230px;max-height:200px;overflow-y:auto;\" +\n \"display:none;box-shadow:0 8px 32px rgba(0,0,0,.5);\";\n const grid = document.createElement(\"div\");\n grid.style.cssText = \"display:flex;flex-wrap:wrap;gap:2px;\";\n EMOJIS.forEach((em) => {\n const b = document.createElement(\"button\");\n b.type = \"button\";\n b.textContent = em;\n b.style.cssText =\n \"background:none;border:none;cursor:pointer;border-radius:5px;width:32px;height:32px;font-size:18px;\";\n b.addEventListener(\"mouseenter\", () => (b.style.background = \"#2a2f38\"));\n b.addEventListener(\"mouseleave\", () => (b.style.background = \"none\"));\n b.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n insertEmoji(em);\n });\n grid.appendChild(b);\n });\n p.appendChild(grid);\n document.body.appendChild(p);\n return p;\n}\n\nfunction insertEmoji(emoji: string): void {\n if (!richCtx) return;\n richCtx.el.focus();\n const sel = window.getSelection();\n if (savedRange && sel) {\n sel.removeAllRanges();\n sel.addRange(savedRange);\n }\n document.execCommand(\"insertText\", false, emoji);\n savedRange = null;\n hideEmojiPicker();\n}\n\n// Click outside the active region (and outside the toolbar) commits the edit.\nif (typeof document !== \"undefined\") {\n document.addEventListener(\n \"mousedown\",\n (e) => {\n if (!richCtx) return;\n const target = e.target as HTMLElement | null;\n if (!target) return;\n if (target.closest(\"[data-cms-inline-edit-toolbar]\")) return;\n if (richCtx.el.contains(target)) return;\n deactivateRich();\n },\n true,\n );\n}\n\n/**\n * Sets a value at a dot-path into a plain-data tree, where a numeric segment\n * indexes into an array (e.g. \"slides.2.eyebrow\" — flagship-style nested\n * content; a flat \"heroEyebrow\" is still just a 1-segment path). Bails\n * silently (no throw) if the path doesn't resolve — a stale/malformed path\n * must never crash the save, just fail to apply.\n */\nfunction setDeepField(data: Record<string, unknown>, path: string, value: string): void {\n const parts = path.split(\".\");\n let obj: any = data;\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i] ?? \"\";\n const key: string | number = /^\\d+$/.test(part) ? Number(part) : part;\n if (obj == null || typeof obj !== \"object\" || obj[key] === undefined) return;\n obj = obj[key];\n }\n const last = parts[parts.length - 1] ?? \"\";\n const lastKey: string | number = /^\\d+$/.test(last) ? Number(last) : last;\n if (obj == null || typeof obj !== \"object\") return;\n obj[lastKey] = value;\n}\n\n/**\n * Converts an edited contenteditable region's innerHTML back to Markdown so a\n * rich article body round-trips through the cms `richtext` contract (fields\n * store Markdown, `marked` renders it — NOT HTML). Handles the structures a\n * marked-rendered body + the toolbar produce: headings, paragraphs, emphasis,\n * links, lists, blockquote, code. Formatting with no clean Markdown equivalent\n * (underline, coloured spans) is passed through as inline HTML — `marked`\n * renders inline HTML, so it survives without corrupting the source. Tables and\n * anything unrecognised are passed through as their outerHTML for the same\n * reason: never drop content just because it doesn't map to a Markdown token.\n */\nfunction htmlToMarkdown(html: string): string {\n const container = document.createElement(\"div\");\n container.innerHTML = html;\n return serializeBlockChildren(container).replace(/\\n{3,}/g, \"\\n\\n\").trim() + \"\\n\";\n}\n\nfunction serializeBlockChildren(parent: Node): string {\n const blocks: string[] = [];\n parent.childNodes.forEach((node) => {\n const s = serializeBlock(node).trim();\n if (s) blocks.push(s);\n });\n return blocks.join(\"\\n\\n\");\n}\n\nfunction serializeBlock(node: Node): string {\n if (node.nodeType === Node.TEXT_NODE) return (node.textContent ?? \"\").trim();\n if (node.nodeType !== Node.ELEMENT_NODE) return \"\";\n const el = node as HTMLElement;\n const tag = el.tagName.toLowerCase();\n switch (tag) {\n case \"h1\": return \"# \" + serializeInline(el);\n case \"h2\": return \"## \" + serializeInline(el);\n case \"h3\": return \"### \" + serializeInline(el);\n case \"h4\": return \"#### \" + serializeInline(el);\n case \"h5\": return \"##### \" + serializeInline(el);\n case \"h6\": return \"###### \" + serializeInline(el);\n case \"p\":\n case \"div\":\n return serializeInline(el);\n case \"ul\":\n return serializeList(el, false);\n case \"ol\":\n return serializeList(el, true);\n case \"blockquote\":\n // Serialize the quote's OWN block children (it usually wraps <p>s), then\n // prefix each line with \"> \" — treating it as inline dropped the <p> and\n // left a stray leading space.\n return serializeBlockChildren(el)\n .split(\"\\n\")\n .map((l) => (l ? \"> \" + l : \">\"))\n .join(\"\\n\");\n case \"pre\":\n return \"```\\n\" + (el.textContent ?? \"\").replace(/\\n+$/, \"\") + \"\\n```\";\n case \"hr\":\n return \"---\";\n case \"br\":\n return \"\";\n case \"table\":\n // Rebuild the Markdown pipe table (NOT raw-HTML passthrough) so the\n // consumer's marked renderer re-applies its own table treatment (e.g.\n // broberg's mobile scroll-wrapper) instead of getting a bare <table>.\n return serializeTable(el);\n default:\n return serializeInline(el);\n }\n}\n\nfunction serializeTable(table: HTMLElement): string {\n const cellText = (c: Element) => serializeInline(c).trim().replace(/\\|/g, \"\\\\|\");\n const rows: string[] = [];\n const headCells = Array.from(table.querySelectorAll(\"thead tr\")).flatMap((tr) =>\n Array.from(tr.children).map(cellText),\n );\n if (headCells.length) {\n rows.push(\"| \" + headCells.join(\" | \") + \" |\");\n rows.push(\"| \" + headCells.map(() => \"---\").join(\" | \") + \" |\");\n }\n const bodyRows = table.querySelector(\"tbody\")\n ? Array.from(table.querySelectorAll(\"tbody tr\"))\n : Array.from(table.querySelectorAll(\"tr\")).filter((tr) => !tr.closest(\"thead\"));\n bodyRows.forEach((tr) => {\n rows.push(\"| \" + Array.from(tr.children).map(cellText).join(\" | \") + \" |\");\n });\n return rows.join(\"\\n\");\n}\n\nfunction serializeList(listEl: HTMLElement, ordered: boolean): string {\n const items: string[] = [];\n let n = 1;\n listEl.childNodes.forEach((child) => {\n if (child.nodeType === Node.ELEMENT_NODE && (child as HTMLElement).tagName.toLowerCase() === \"li\") {\n const marker = ordered ? `${n++}. ` : \"- \";\n items.push(marker + serializeInline(child as HTMLElement).trim());\n }\n });\n return items.join(\"\\n\");\n}\n\nfunction serializeInline(node: Node): string {\n let out = \"\";\n node.childNodes.forEach((child) => {\n if (child.nodeType === Node.TEXT_NODE) {\n out += (child.textContent ?? \"\").replace(/\\s+/g, \" \");\n return;\n }\n if (child.nodeType !== Node.ELEMENT_NODE) return;\n const el = child as HTMLElement;\n const tag = el.tagName.toLowerCase();\n const inner = serializeInline(el);\n switch (tag) {\n case \"strong\":\n case \"b\":\n out += inner.trim() ? `**${inner.trim()}**` : \"\";\n break;\n case \"em\":\n case \"i\":\n out += inner.trim() ? `*${inner.trim()}*` : \"\";\n break;\n case \"code\":\n out += \"`\" + inner + \"`\";\n break;\n case \"br\":\n out += \" \\n\";\n break;\n case \"a\": {\n const href = el.getAttribute(\"href\") || \"\";\n out += href ? `[${inner}](${href})` : inner;\n break;\n }\n case \"img\": {\n // Content images embedded in the body () — dropping them\n // would silently delete images from an article on save. Void element,\n // no children, so this must be handled explicitly.\n const src = el.getAttribute(\"src\") || \"\";\n const alt = el.getAttribute(\"alt\") || \"\";\n if (src) out += ``;\n break;\n }\n case \"u\":\n out += `<u>${inner}</u>`; // no Markdown for underline — pass through\n break;\n case \"span\":\n case \"font\": {\n const color = el.style.color || el.getAttribute(\"color\") || \"\";\n out += color ? `<span style=\"color:${color}\">${inner}</span>` : inner;\n break;\n }\n default:\n out += inner;\n }\n });\n return out;\n}\n\nasync function saveField(el: HTMLElement, value: string, token: string, options: ResolvedOptions): Promise<void> {\n const collection = el.dataset.cmsCollection;\n const slug = el.dataset.cmsSlug;\n const field = el.dataset.cmsField;\n if (!collection || !slug || !field) return;\n const slice = el.dataset.cmsSlice;\n\n showPill(el, \"saving\");\n try {\n const getRes = await fetch(\n `${options.cmsBaseUrl}/api/cms/${collection}/${slug}?site=${options.siteId}`,\n { headers: { Authorization: `Bearer ${token}` } },\n );\n if (!getRes.ok) throw new Error(`GET failed: ${getRes.status}`);\n const doc = (await getRes.json()) as { data?: Record<string, unknown> };\n // Deep-clone so mutating a nested array/object (dot-path saves) never\n // aliases the fetched doc — same safety whether field is flat or nested.\n const mergedData = JSON.parse(JSON.stringify(doc.data ?? {})) as Record<string, unknown>;\n if (slice !== undefined) {\n // Field-slice save: replace just this segment inside the full field value,\n // preserving every other segment + embed. Aborts on a non-unique match.\n const currentVal = typeof mergedData[field] === \"string\" ? (mergedData[field] as string) : \"\";\n mergedData[field] = applyFieldSlice(currentVal, slice, value);\n } else if (field.includes(\".\")) {\n setDeepField(mergedData, field, value);\n } else {\n mergedData[field] = value;\n }\n\n const patchRes = await fetch(\n `${options.cmsBaseUrl}/api/cms/${collection}/${slug}?site=${options.siteId}`,\n {\n method: \"PATCH\",\n headers: { Authorization: `Bearer ${token}`, \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ data: mergedData }),\n },\n );\n if (!patchRes.ok) throw new Error(`PATCH failed: ${patchRes.status}`);\n // The slice we just wrote is now the current text — track it so a second\n // edit of the same segment (no reload) matches against the new value.\n if (slice !== undefined) el.dataset.cmsSlice = value;\n showPill(el, \"saved\");\n } catch {\n showPill(el, \"error\");\n }\n}\n\nconst pills = new WeakMap<HTMLElement, HTMLElement>();\n\nfunction showPill(el: HTMLElement, state: \"saving\" | \"saved\" | \"error\"): void {\n let pill = pills.get(el);\n if (!pill) {\n pill = document.createElement(\"span\");\n pill.setAttribute(\"data-cms-inline-edit-pill\", \"\");\n document.body.appendChild(pill);\n pills.set(el, pill);\n }\n const rect = el.getBoundingClientRect();\n pill.style.cssText =\n `position:fixed;top:${rect.top - 26}px;left:${rect.left}px;font:600 11px system-ui,sans-serif;` +\n `padding:3px 9px;border-radius:5px;z-index:2147483647;pointer-events:none;` +\n `box-shadow:0 2px 8px rgba(0,0,0,.25);`;\n\n if (state === \"saving\") {\n pill.textContent = uiLabels.saving;\n pill.style.background = \"#1c2027\";\n pill.style.color = \"#fff\";\n } else if (state === \"saved\") {\n pill.textContent = uiLabels.saved;\n pill.style.background = \"#16a34a\";\n pill.style.color = \"#fff\";\n setTimeout(() => {\n pill?.remove();\n pills.delete(el);\n }, 1500);\n } else {\n pill.textContent = uiLabels.error;\n pill.style.background = \"#dc2626\";\n pill.style.color = \"#fff\";\n }\n}\n\nfunction showActiveBadge(options: ResolvedOptions): void {\n // The connected badge IS the exit-edit action: [icon] \"Afslut redigering\".\n // No \"Redigerer som {name}\" — the whole pill is one click to leave edit mode.\n const badge = document.createElement(\"button\");\n badge.type = \"button\";\n badge.setAttribute(\"data-cms-inline-edit-badge\", \"\");\n badge.style.cssText =\n \"position:fixed;bottom:16px;left:16px;display:inline-flex;align-items:center;gap:7px;\" +\n \"background:#1c2027;color:#fff;font:600 12px system-ui,sans-serif;padding:8px 14px;\" +\n \"border-radius:999px;z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);\" +\n \"border:none;cursor:pointer;opacity:.9;transition:opacity .15s;\";\n const text = document.createElement(\"span\");\n text.textContent = options.disconnectLabel;\n badge.append(makeIcon(), text);\n badge.addEventListener(\"mouseenter\", () => (badge.style.opacity = \"1\"));\n badge.addEventListener(\"mouseleave\", () => (badge.style.opacity = \".9\"));\n // Clicking the badge LEAVES edit mode but KEEPS the login → back to the idle\n // \"Rediger\" pill (not a logout). Explicit logout lives on the idle pill.\n badge.addEventListener(\"click\", exitEditMode);\n document.body.appendChild(badge);\n}\n\n/** Reads JWT claims for DISPLAY ONLY — never used for authorization decisions. */\nfunction decodeJwtPayload(token: string): Record<string, unknown> | null {\n try {\n const payload = token.split(\".\")[1];\n if (!payload) return null;\n return JSON.parse(atob(payload.replace(/-/g, \"+\").replace(/_/g, \"/\")));\n } catch {\n return null;\n }\n}\n\nfunction injectStyles(): void {\n const style = document.createElement(\"style\");\n style.textContent = `\n [data-cms-field] { outline: 1px dashed transparent; outline-offset: 2px; cursor: text; transition: outline-color .15s; }\n [data-cms-field]:hover { outline-color: rgba(0,178,255,.5); }\n [data-cms-field][contenteditable=\"true\"] { outline: 2px solid #00b2ff; outline-offset: 2px; }\n [data-cms-field][data-cms-richtext=\"true\"] { cursor: text; }\n .cms-rich-editing { outline: 2px solid #00b2ff !important; outline-offset: 6px; border-radius: 4px; }\n `;\n document.head.appendChild(style);\n}\n","/**\n * Replace ONE slice of a larger text field.\n *\n * Used when an element renders a single SEGMENT of a bigger field — e.g. one\n * prose paragraph of a `content` body that is interleaved with `[block:]`\n * embeds — so editing that segment must write back into the full field without\n * clobbering the other segments or the embeds.\n *\n * Safety-first: throws if `original` is not found EXACTLY once, so an ambiguous\n * or stale slice ABORTS the save (surfaced as the error pill) instead of\n * corrupting the whole field. Pure + framework-agnostic; unit-tested.\n */\nexport function applyFieldSlice(current: string, original: string, next: string): string {\n const first = current.indexOf(original);\n if (first === -1) throw new Error(\"field-slice: original not found\");\n if (current.indexOf(original, first + original.length) !== -1) {\n throw new Error(\"field-slice: original found more than once (ambiguous)\");\n }\n return current.slice(0, first) + next + current.slice(first + original.length);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AA,EACT,OAAO;AACL,SAAK,cAAc,SAAS;AAC5B,SAAK,MAAM,aAAa;AACxB,SAAK,MAAM,QAAQ;AAAA,EACrB;AACF;AAEA,SAAS,gBAAgB,SAAgC;AAGvD,QAAM,QAAQ,SAAS,cAAc,QAAQ;AAC7C,QAAM,OAAO;AACb,QAAM,aAAa,8BAA8B,EAAE;AACnD,QAAM,MAAM,UACV;AAIF,QAAM,OAAO,SAAS,cAAc,MAAM;AAC1C,OAAK,cAAc,QAAQ;AAC3B,QAAM,OAAO,SAAS,GAAG,IAAI;AAC7B,QAAM,iBAAiB,cAAc,MAAO,MAAM,MAAM,UAAU,GAAI;AACtE,QAAM,iBAAiB,cAAc,MAAO,MAAM,MAAM,UAAU,IAAK;AAGvE,QAAM,iBAAiB,SAAS,YAAY;AAC5C,WAAS,KAAK,YAAY,KAAK;AACjC;AAGA,SAAS,iBAAiB,OAA+C;AACvE,MAAI;AACF,UAAM,UAAU,MAAM,MAAM,GAAG,EAAE,CAAC;AAClC,QAAI,CAAC,QAAS,QAAO;AACrB,WAAO,KAAK,MAAM,KAAK,QAAQ,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG,CAAC,CAAC;AAAA,EACvE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,eAAqB;AAC5B,QAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,QAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOpB,WAAS,KAAK,YAAY,KAAK;AACjC;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -43,8 +43,16 @@ interface InlineEditOptions {
|
|
|
43
43
|
storageKey?: string;
|
|
44
44
|
/** Text for the "not connected yet" prompt (a square-pen icon is prepended). Default "Log ind for at redigere". */
|
|
45
45
|
connectLabel?: string;
|
|
46
|
-
/** Text for the "connected" badge —
|
|
46
|
+
/** Text for the "connected + editing" badge — clicking it LEAVES edit mode but keeps the login (icon prepended). Default "Afbryd". */
|
|
47
47
|
disconnectLabel?: string;
|
|
48
|
+
/** Text for the explicit "log out" action on the idle pill — clicking it clears the token (back to the logged-out state). Default "Log ud". */
|
|
49
|
+
logoutLabel?: string;
|
|
50
|
+
/** Show an on-site "connect" pill to LOGGED-OUT visitors (click → connect flow).
|
|
51
|
+
* Default FALSE — customer-safe: a visitor without a token sees NOTHING. Only
|
|
52
|
+
* enable for a site with no real customers (e.g. an internal/first-party site)
|
|
53
|
+
* where a self-contained on-site login entry is wanted. The safe entry for a
|
|
54
|
+
* customer site is always the "Redigér live" button in webhouse.app CMS-admin. */
|
|
55
|
+
connectPrompt?: boolean;
|
|
48
56
|
/** Localised labels for the toolbar + save-status pill. Defaults are Danish. */
|
|
49
57
|
labels?: InlineEditLabels;
|
|
50
58
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -43,8 +43,16 @@ interface InlineEditOptions {
|
|
|
43
43
|
storageKey?: string;
|
|
44
44
|
/** Text for the "not connected yet" prompt (a square-pen icon is prepended). Default "Log ind for at redigere". */
|
|
45
45
|
connectLabel?: string;
|
|
46
|
-
/** Text for the "connected" badge —
|
|
46
|
+
/** Text for the "connected + editing" badge — clicking it LEAVES edit mode but keeps the login (icon prepended). Default "Afbryd". */
|
|
47
47
|
disconnectLabel?: string;
|
|
48
|
+
/** Text for the explicit "log out" action on the idle pill — clicking it clears the token (back to the logged-out state). Default "Log ud". */
|
|
49
|
+
logoutLabel?: string;
|
|
50
|
+
/** Show an on-site "connect" pill to LOGGED-OUT visitors (click → connect flow).
|
|
51
|
+
* Default FALSE — customer-safe: a visitor without a token sees NOTHING. Only
|
|
52
|
+
* enable for a site with no real customers (e.g. an internal/first-party site)
|
|
53
|
+
* where a self-contained on-site login entry is wanted. The safe entry for a
|
|
54
|
+
* customer site is always the "Redigér live" button in webhouse.app CMS-admin. */
|
|
55
|
+
connectPrompt?: boolean;
|
|
48
56
|
/** Localised labels for the toolbar + save-status pill. Defaults are Danish. */
|
|
49
57
|
labels?: InlineEditLabels;
|
|
50
58
|
}
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,8 @@ function resolveOptions(options) {
|
|
|
30
30
|
// No emoji in defaults — the square-pen SVG is the icon; some sites ban emoji.
|
|
31
31
|
connectLabel: "Log ind for at redigere",
|
|
32
32
|
disconnectLabel: "Afbryd",
|
|
33
|
+
logoutLabel: "Log ud",
|
|
34
|
+
connectPrompt: false,
|
|
33
35
|
...options,
|
|
34
36
|
labels: { ...DEFAULT_LABELS, ...options.labels ?? {} }
|
|
35
37
|
};
|
|
@@ -38,16 +40,20 @@ async function initInlineEdit(options) {
|
|
|
38
40
|
if (typeof window === "undefined") return;
|
|
39
41
|
const resolved = resolveOptions(options);
|
|
40
42
|
uiLabels = resolved.labels;
|
|
41
|
-
captureTokenFromUrl(resolved);
|
|
43
|
+
const freshFromUrl = captureTokenFromUrl(resolved);
|
|
42
44
|
const enabled = await checkEnabled(resolved);
|
|
43
45
|
if (!enabled) return;
|
|
44
46
|
const token = getConnectedToken(options);
|
|
45
|
-
if (token) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
if (!token) {
|
|
48
|
+
if (resolved.connectPrompt) {
|
|
49
|
+
showConnectPrompt(resolved);
|
|
50
|
+
listenForTokenMessage(resolved);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
50
53
|
}
|
|
54
|
+
setupFields(token, resolved);
|
|
55
|
+
if (freshFromUrl) enterEditMode();
|
|
56
|
+
else showIdlePill();
|
|
51
57
|
}
|
|
52
58
|
function listenForTokenMessage(options) {
|
|
53
59
|
let cmsOrigin;
|
|
@@ -65,7 +71,8 @@ function listenForTokenMessage(options) {
|
|
|
65
71
|
if (document.querySelector("[data-cms-inline-edit-badge]")) return;
|
|
66
72
|
localStorage.setItem(options.storageKey, data.token);
|
|
67
73
|
document.querySelector("[data-cms-inline-edit-connect]")?.remove();
|
|
68
|
-
|
|
74
|
+
setupFields(data.token, options);
|
|
75
|
+
enterEditMode();
|
|
69
76
|
});
|
|
70
77
|
}
|
|
71
78
|
function getConnectedToken(options) {
|
|
@@ -91,10 +98,11 @@ function disconnect(options) {
|
|
|
91
98
|
function captureTokenFromUrl(options) {
|
|
92
99
|
const url = new URL(window.location.href);
|
|
93
100
|
const urlToken = url.searchParams.get(options.tokenParam);
|
|
94
|
-
if (!urlToken) return;
|
|
101
|
+
if (!urlToken) return false;
|
|
95
102
|
localStorage.setItem(options.storageKey, urlToken);
|
|
96
103
|
url.searchParams.delete(options.tokenParam);
|
|
97
104
|
window.history.replaceState({}, "", url.toString());
|
|
105
|
+
return true;
|
|
98
106
|
}
|
|
99
107
|
async function checkEnabled(options) {
|
|
100
108
|
try {
|
|
@@ -140,11 +148,58 @@ function showConnectPrompt(options) {
|
|
|
140
148
|
});
|
|
141
149
|
document.body.appendChild(link);
|
|
142
150
|
}
|
|
143
|
-
|
|
151
|
+
var editingActive = false;
|
|
152
|
+
var fieldsWired = false;
|
|
153
|
+
var stateOptions = null;
|
|
154
|
+
function setupFields(token, options) {
|
|
155
|
+
stateOptions = options;
|
|
156
|
+
if (fieldsWired) return;
|
|
144
157
|
injectStyles();
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
158
|
+
document.querySelectorAll("[data-cms-field]").forEach((el) => wireField(el, token, options));
|
|
159
|
+
fieldsWired = true;
|
|
160
|
+
}
|
|
161
|
+
function enterEditMode() {
|
|
162
|
+
if (!stateOptions || editingActive) return;
|
|
163
|
+
editingActive = true;
|
|
164
|
+
removeIdlePill();
|
|
165
|
+
showActiveBadge(stateOptions);
|
|
166
|
+
}
|
|
167
|
+
function exitEditMode() {
|
|
168
|
+
if (!stateOptions || !editingActive) return;
|
|
169
|
+
deactivateRich();
|
|
170
|
+
editingActive = false;
|
|
171
|
+
document.querySelector("[data-cms-inline-edit-badge]")?.remove();
|
|
172
|
+
showIdlePill();
|
|
173
|
+
}
|
|
174
|
+
function removeIdlePill() {
|
|
175
|
+
document.querySelector("[data-cms-inline-edit-idle]")?.remove();
|
|
176
|
+
}
|
|
177
|
+
function showIdlePill() {
|
|
178
|
+
if (!stateOptions) return;
|
|
179
|
+
const options = stateOptions;
|
|
180
|
+
removeIdlePill();
|
|
181
|
+
const wrap = document.createElement("div");
|
|
182
|
+
wrap.setAttribute("data-cms-inline-edit-idle", "");
|
|
183
|
+
wrap.style.cssText = "position:fixed;bottom:16px;left:16px;display:inline-flex;align-items:stretch;z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);border-radius:999px;overflow:hidden;";
|
|
184
|
+
const edit = document.createElement("button");
|
|
185
|
+
edit.type = "button";
|
|
186
|
+
edit.setAttribute("data-cms-inline-edit-enter", "");
|
|
187
|
+
edit.style.cssText = "display:inline-flex;align-items:center;gap:7px;background:#1c2027;color:#fff;font:600 12px system-ui,sans-serif;padding:8px 14px;border:none;cursor:pointer;";
|
|
188
|
+
const editText = document.createElement("span");
|
|
189
|
+
editText.textContent = options.connectLabel;
|
|
190
|
+
edit.append(makeIcon(), editText);
|
|
191
|
+
edit.addEventListener("click", enterEditMode);
|
|
192
|
+
const out = document.createElement("button");
|
|
193
|
+
out.type = "button";
|
|
194
|
+
out.setAttribute("data-cms-inline-edit-logout", "");
|
|
195
|
+
out.textContent = options.logoutLabel;
|
|
196
|
+
out.style.cssText = "background:#141821;color:#9aa4b2;font:600 11px system-ui,sans-serif;padding:8px 12px;border:none;border-left:1px solid rgba(255,255,255,.12);cursor:pointer;";
|
|
197
|
+
out.addEventListener("click", () => {
|
|
198
|
+
disconnect(options);
|
|
199
|
+
removeIdlePill();
|
|
200
|
+
});
|
|
201
|
+
wrap.append(edit, out);
|
|
202
|
+
document.body.appendChild(wrap);
|
|
148
203
|
}
|
|
149
204
|
function wireField(el, token, options) {
|
|
150
205
|
if (el.dataset.cmsRichtext === "true") {
|
|
@@ -156,6 +211,7 @@ function wireField(el, token, options) {
|
|
|
156
211
|
return;
|
|
157
212
|
}
|
|
158
213
|
el.addEventListener("click", (e) => {
|
|
214
|
+
if (!editingActive) return;
|
|
159
215
|
if (el.getAttribute("contenteditable") === "true") return;
|
|
160
216
|
e.preventDefault();
|
|
161
217
|
e.stopPropagation();
|
|
@@ -186,6 +242,7 @@ var richCtx = null;
|
|
|
186
242
|
var richToolbar = null;
|
|
187
243
|
function wireRichField(el, token, options, mode) {
|
|
188
244
|
el.addEventListener("click", (e) => {
|
|
245
|
+
if (!editingActive) return;
|
|
189
246
|
if (richCtx && richCtx.el === el) return;
|
|
190
247
|
e.preventDefault();
|
|
191
248
|
e.stopPropagation();
|
|
@@ -574,10 +631,7 @@ function showActiveBadge(options) {
|
|
|
574
631
|
badge.append(makeIcon(), text);
|
|
575
632
|
badge.addEventListener("mouseenter", () => badge.style.opacity = "1");
|
|
576
633
|
badge.addEventListener("mouseleave", () => badge.style.opacity = ".9");
|
|
577
|
-
badge.addEventListener("click",
|
|
578
|
-
disconnect(options);
|
|
579
|
-
window.location.reload();
|
|
580
|
-
});
|
|
634
|
+
badge.addEventListener("click", exitEditMode);
|
|
581
635
|
document.body.appendChild(badge);
|
|
582
636
|
}
|
|
583
637
|
function decodeJwtPayload(token) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/field-slice.ts","../src/index.ts"],"sourcesContent":["/**\n * Replace ONE slice of a larger text field.\n *\n * Used when an element renders a single SEGMENT of a bigger field — e.g. one\n * prose paragraph of a `content` body that is interleaved with `[block:]`\n * embeds — so editing that segment must write back into the full field without\n * clobbering the other segments or the embeds.\n *\n * Safety-first: throws if `original` is not found EXACTLY once, so an ambiguous\n * or stale slice ABORTS the save (surfaced as the error pill) instead of\n * corrupting the whole field. Pure + framework-agnostic; unit-tested.\n */\nexport function applyFieldSlice(current: string, original: string, next: string): string {\n const first = current.indexOf(original);\n if (first === -1) throw new Error(\"field-slice: original not found\");\n if (current.indexOf(original, first + original.length) !== -1) {\n throw new Error(\"field-slice: original found more than once (ambiguous)\");\n }\n return current.slice(0, first) + next + current.slice(first + original.length);\n}\n","/**\n * Browser entry — zero dependencies. Site-wide: activated once per browser\n * via a \"connect\" link (see docs/features/F157-inline-editing.md), then\n * every page load on the site automatically offers click-to-edit on any\n * element carrying data-cms-collection/data-cms-slug/data-cms-field\n * (F129's attribute convention) — no per-document step.\n */\nimport { applyFieldSlice } from \"./field-slice\";\nexport { applyFieldSlice } from \"./field-slice\";\n\n/**\n * Labels for the in-editor UI — the rich-text toolbar (bold/italic/underline\n * tooltips, the visible \"colour\" + \"done\" buttons, the emoji tooltip) and the\n * save-status pill. Every field is optional; unset fields keep the Danish\n * default. Pass an English (or any-locale) set on a non-Danish site so the\n * toolbar and status text match the page language.\n */\nexport interface InlineEditLabels {\n bold?: string;\n italic?: string;\n underline?: string;\n orderedList?: string;\n unorderedList?: string;\n color?: string;\n emoji?: string;\n done?: string;\n saving?: string;\n saved?: string;\n error?: string;\n}\n\nexport interface InlineEditOptions {\n /** Base URL of the CMS API, e.g. \"https://webhouse.app\". */\n cmsBaseUrl: string;\n /** Site id passed as ?site= on every CMS API call, e.g. \"broberg-ai\". */\n siteId: string;\n /** URL query param carrying a freshly-minted token from the connect redirect. Default \"cms_edit\". */\n tokenParam?: string;\n /** localStorage key the token is persisted under — survives across sessions/tabs. Default \"wh-inline-edit-token\". */\n storageKey?: string;\n /** Text for the \"not connected yet\" prompt (a square-pen icon is prepended). Default \"Log ind for at redigere\". */\n connectLabel?: string;\n /** Text for the \"connected\" badge — the whole pill is the exit-edit action (icon prepended). Default \"Afbryd\". */\n disconnectLabel?: string;\n /** Localised labels for the toolbar + save-status pill. Defaults are Danish. */\n labels?: InlineEditLabels;\n}\n\ninterface ResolvedOptions extends Required<Omit<InlineEditOptions, \"labels\">> {\n labels: Required<InlineEditLabels>;\n}\n\nconst DEFAULT_LABELS: Required<InlineEditLabels> = {\n bold: \"Fed\",\n italic: \"Kursiv\",\n underline: \"Understreget\",\n orderedList: \"Nummereret liste\",\n unorderedList: \"Punktliste\",\n color: \"Farve\",\n emoji: \"Indsæt emoji\",\n done: \"Færdig\",\n saving: \"Gemmer…\",\n saved: \"Gemt ✓\",\n error: \"Fejl — prøv igen\",\n};\n\n// Set once from resolved options in initInlineEdit(); read by the (singleton)\n// toolbar and the save-status pill so their signatures stay unchanged. One edit\n// session per page → a single module-level value is safe.\nlet uiLabels: Required<InlineEditLabels> = DEFAULT_LABELS;\n\nfunction resolveOptions(options: InlineEditOptions): ResolvedOptions {\n return {\n tokenParam: \"cms_edit\",\n storageKey: \"wh-inline-edit-token\",\n // No emoji in defaults — the square-pen SVG is the icon; some sites ban emoji.\n connectLabel: \"Log ind for at redigere\",\n disconnectLabel: \"Afbryd\",\n ...options,\n labels: { ...DEFAULT_LABELS, ...(options.labels ?? {}) },\n };\n}\n\nexport async function initInlineEdit(options: InlineEditOptions): Promise<void> {\n if (typeof window === \"undefined\") return;\n const resolved = resolveOptions(options);\n uiLabels = resolved.labels;\n\n captureTokenFromUrl(resolved);\n\n const enabled = await checkEnabled(resolved);\n if (!enabled) return;\n\n const token = getConnectedToken(options);\n if (token) {\n activateEditMode(token, resolved);\n } else {\n showConnectPrompt(resolved);\n // F158 — the connect flow opens in a popup; it posts the freshly-minted\n // token back to this tab. Arm the (origin-validated) receiver.\n listenForTokenMessage(resolved);\n }\n}\n\n/**\n * F158 — receive the edit token from the connect popup via postMessage.\n * Hard origin check (message MUST come from cmsBaseUrl) + type + site + expiry\n * guards before the token is trusted. On success: persist, swap the connect\n * prompt for edit mode — no page reload.\n */\nfunction listenForTokenMessage(options: ResolvedOptions): void {\n let cmsOrigin: string;\n try {\n cmsOrigin = new URL(options.cmsBaseUrl).origin;\n } catch {\n return;\n }\n window.addEventListener(\"message\", (event: MessageEvent) => {\n if (event.origin !== cmsOrigin) return;\n const data = event.data as { type?: string; token?: string; site?: string } | null;\n if (!data || data.type !== \"wh-inline-edit-token\" || typeof data.token !== \"string\") return;\n if (data.site && data.site !== options.siteId) return;\n if (isExpired(data.token)) return;\n if (document.querySelector(\"[data-cms-inline-edit-badge]\")) return; // already active\n localStorage.setItem(options.storageKey, data.token);\n document.querySelector(\"[data-cms-inline-edit-connect]\")?.remove();\n activateEditMode(data.token, options);\n });\n}\n\n/**\n * A valid (non-expired) token already connected in this browser for this\n * site, or null. Also captures a fresh `?cms_edit=` token from the URL\n * first, so a page can call this directly right after the connect redirect\n * without going through initInlineEdit(). Exposed so a site's own /admin\n * page (or any other tool built on the same connected session) can reuse\n * the same storage/expiry logic instead of re-implementing it.\n */\nexport function getConnectedToken(options: InlineEditOptions): string | null {\n if (typeof window === \"undefined\") return null;\n const resolved = resolveOptions(options);\n captureTokenFromUrl(resolved);\n const token = localStorage.getItem(resolved.storageKey);\n if (!token) return null;\n if (isExpired(token)) {\n localStorage.removeItem(resolved.storageKey);\n return null;\n }\n return token;\n}\n\n/** The URL that mints a fresh 30-day site-scoped token and redirects back to `returnUrl`. */\nexport function buildConnectUrl(options: InlineEditOptions, returnUrl: string): string {\n const resolved = resolveOptions(options);\n return (\n `${resolved.cmsBaseUrl}/admin/inline-edit/connect?site=${encodeURIComponent(resolved.siteId)}` +\n `&return=${encodeURIComponent(returnUrl)}`\n );\n}\n\n/** Clears the connected token in this browser (e.g. a \"log out\" action in a site's own /admin panel). */\nexport function disconnect(options: InlineEditOptions): void {\n if (typeof window === \"undefined\") return;\n localStorage.removeItem(resolveOptions(options).storageKey);\n}\n\n/** Captures a token minted by /admin/inline-edit/connect, then strips it from the URL. */\nfunction captureTokenFromUrl(options: ResolvedOptions): void {\n const url = new URL(window.location.href);\n const urlToken = url.searchParams.get(options.tokenParam);\n if (!urlToken) return;\n localStorage.setItem(options.storageKey, urlToken);\n url.searchParams.delete(options.tokenParam);\n window.history.replaceState({}, \"\", url.toString());\n}\n\nasync function checkEnabled(options: ResolvedOptions): Promise<boolean> {\n try {\n const res = await fetch(`${options.cmsBaseUrl}/api/inline-edit/status?site=${options.siteId}`);\n if (!res.ok) return false;\n const body = (await res.json()) as { enabled?: boolean };\n return body.enabled === true;\n } catch {\n return false;\n }\n}\n\nfunction isExpired(token: string): boolean {\n const claims = decodeJwtPayload(token);\n const exp = typeof claims?.exp === \"number\" ? claims.exp : 0;\n return exp <= Date.now() / 1000;\n}\n\n// Lucide \"square-pen\" (https://lucide.dev/icons/square-pen), MIT. Inline SVG so\n// the pill needs no icon-font/runtime dep and inherits `currentColor`. Emoji are\n// deliberately avoided — some consumer sites ban them outright.\nconst SQUARE_PEN_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<path d=\"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7\"/>' +\n '<path d=\"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z\"/>' +\n \"</svg>\";\n\n// Toolbar list-button faces (lucide \"list\" / \"list-ordered\"), inline so no\n// icon-font/runtime dep; stroke inherits the button's white `currentColor`.\nconst UL_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<line x1=\"8\" x2=\"21\" y1=\"6\" y2=\"6\"/><line x1=\"8\" x2=\"21\" y1=\"12\" y2=\"12\"/>' +\n '<line x1=\"8\" x2=\"21\" y1=\"18\" y2=\"18\"/><line x1=\"3\" x2=\"3.01\" y1=\"6\" y2=\"6\"/>' +\n '<line x1=\"3\" x2=\"3.01\" y1=\"12\" y2=\"12\"/><line x1=\"3\" x2=\"3.01\" y1=\"18\" y2=\"18\"/>' +\n \"</svg>\";\n\nconst OL_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<line x1=\"10\" x2=\"21\" y1=\"6\" y2=\"6\"/><line x1=\"10\" x2=\"21\" y1=\"12\" y2=\"12\"/>' +\n '<line x1=\"10\" x2=\"21\" y1=\"18\" y2=\"18\"/><path d=\"M4 6h1v4\"/><path d=\"M4 10h2\"/>' +\n '<path d=\"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1\"/>' +\n \"</svg>\";\n\nfunction makeIcon(): HTMLSpanElement {\n const icon = document.createElement(\"span\");\n icon.style.cssText = \"display:inline-flex;line-height:0;flex:0 0 auto\";\n icon.innerHTML = SQUARE_PEN_SVG;\n return icon;\n}\n\nfunction showConnectPrompt(options: ResolvedOptions): void {\n const connectUrl = buildConnectUrl(options, window.location.href);\n\n const link = document.createElement(\"a\");\n link.href = connectUrl;\n link.setAttribute(\"data-cms-inline-edit-connect\", \"\");\n link.style.cssText =\n \"position:fixed;bottom:16px;left:16px;background:#1c2027;color:#fff;\" +\n \"font:600 12px system-ui,sans-serif;padding:8px 14px;border-radius:999px;\" +\n \"text-decoration:none;z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);\" +\n \"display:inline-flex;align-items:center;gap:7px;\";\n const text = document.createElement(\"span\");\n text.textContent = options.connectLabel;\n link.append(makeIcon(), text);\n // F158 — open the connect flow in a popup so the CMS confirmation screen can\n // say \"close this window\". A user-gesture window.open is not popup-blocked;\n // if it is blocked anyway, fall back to the same-tab redirect (F157 path).\n link.addEventListener(\"click\", (e) => {\n e.preventDefault();\n const popup = window.open(\n connectUrl,\n \"wh-inline-edit-connect\",\n \"width=460,height=640,menubar=no,toolbar=no,location=yes,status=no\",\n );\n if (!popup) window.location.href = connectUrl;\n });\n document.body.appendChild(link);\n}\n\nfunction activateEditMode(token: string, options: ResolvedOptions): void {\n injectStyles();\n showActiveBadge(options);\n\n const fields = document.querySelectorAll<HTMLElement>(\"[data-cms-field]\");\n fields.forEach((el) => wireField(el, token, options));\n}\n\nfunction wireField(el: HTMLElement, token: string, options: ResolvedOptions): void {\n // Rich fields get the floating formatting toolbar. Two save modes:\n // - data-cms-richtext=\"true\" → save as Markdown (article bodies; cms\n // `richtext` contract renders Markdown via marked).\n // - data-cms-html=\"true\" → save innerHTML VERBATIM (intentional-HTML\n // fields: headings/bios/hero with a branded <em class=\"o\"> accent that\n // has no Markdown equivalent — converting would strip it).\n // Everything else stays a plain single-line contenteditable saving textContent.\n if (el.dataset.cmsRichtext === \"true\") {\n wireRichField(el, token, options, \"markdown\");\n return;\n }\n if (el.dataset.cmsHtml === \"true\") {\n wireRichField(el, token, options, \"html\");\n return;\n }\n\n el.addEventListener(\"click\", (e) => {\n if (el.getAttribute(\"contenteditable\") === \"true\") return;\n // Many editable fields (card titles/blurbs) sit inside a clickable <a>/\n // <button> ancestor (the card itself) — without this, \"click to edit\"\n // would immediately navigate away instead of focusing the field.\n e.preventDefault();\n e.stopPropagation();\n el.dataset.cmsOriginalValue = el.textContent ?? \"\";\n el.setAttribute(\"contenteditable\", \"true\");\n el.focus();\n });\n\n el.addEventListener(\"blur\", () => {\n el.removeAttribute(\"contenteditable\");\n const original = el.dataset.cmsOriginalValue ?? \"\";\n const current = el.textContent ?? \"\";\n if (current.trim() === original.trim()) return;\n void saveField(el, current.trim(), token, options);\n });\n\n el.addEventListener(\"paste\", (e) => {\n e.preventDefault();\n const text = e.clipboardData?.getData(\"text/plain\") ?? \"\";\n document.execCommand(\"insertText\", false, text);\n });\n\n el.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Enter\") {\n e.preventDefault();\n el.blur();\n }\n });\n}\n\n/* ─── Rich-text mode (article bodies) ──────────────────────────────────────\n * A single editable region + a floating B/I/U · color · emoji · Done toolbar\n * (the Pitch Vault pattern, minus the iframe/postMessage — we run in the live\n * page's own document). On \"Done\" the region's innerHTML is converted back to\n * Markdown (the cms `richtext` contract: fields store Markdown, not HTML) and\n * saved. Only ONE region is active at a time. */\n\ntype RichMode = \"markdown\" | \"html\";\ninterface RichContext {\n el: HTMLElement;\n token: string;\n options: ResolvedOptions;\n originalHtml: string;\n mode: RichMode;\n}\nlet richCtx: RichContext | null = null;\nlet richToolbar: HTMLElement | null = null;\n\nfunction wireRichField(el: HTMLElement, token: string, options: ResolvedOptions, mode: RichMode): void {\n el.addEventListener(\"click\", (e) => {\n if (richCtx && richCtx.el === el) return; // already editing this region\n e.preventDefault();\n e.stopPropagation();\n activateRich(el, token, options, mode);\n });\n}\n\nfunction activateRich(el: HTMLElement, token: string, options: ResolvedOptions, mode: RichMode): void {\n deactivateRich(); // commit any previously-active region first\n richCtx = { el, token, options, originalHtml: el.innerHTML, mode };\n el.setAttribute(\"contenteditable\", \"true\");\n el.classList.add(\"cms-rich-editing\");\n el.focus();\n showRichToolbar();\n // Let the host page react (e.g. pause a rotating hero carousel while editing).\n document.dispatchEvent(new CustomEvent(\"cms-inline-edit:activate\", { detail: { el } }));\n}\n\nfunction deactivateRich(): void {\n if (!richCtx) return;\n const { el, token, options, originalHtml, mode } = richCtx;\n richCtx = null;\n el.removeAttribute(\"contenteditable\");\n el.classList.remove(\"cms-rich-editing\");\n hideRichToolbar();\n if (el.innerHTML !== originalHtml) {\n const value = mode === \"html\" ? el.innerHTML : htmlToMarkdown(el.innerHTML);\n void saveField(el, value, token, options);\n }\n document.dispatchEvent(new CustomEvent(\"cms-inline-edit:deactivate\", { detail: { el } }));\n}\n\nfunction showRichToolbar(): void {\n if (!richToolbar) richToolbar = buildRichToolbar();\n richToolbar.style.display = \"flex\";\n}\n\nfunction hideRichToolbar(): void {\n if (richToolbar) richToolbar.style.display = \"none\";\n hideEmojiPicker();\n}\n\nfunction toolbarButton(label: string, title: string, onDown: () => void): HTMLButtonElement {\n const b = document.createElement(\"button\");\n b.type = \"button\";\n b.innerHTML = label;\n b.title = title;\n b.style.cssText =\n \"background:none;border:1px solid #3a3f4a;color:#fff;min-width:30px;height:30px;\" +\n \"border-radius:6px;cursor:pointer;font-size:14px;padding:0 8px;line-height:1;\";\n b.addEventListener(\"mouseenter\", () => (b.style.background = \"#2a2f38\"));\n b.addEventListener(\"mouseleave\", () => (b.style.background = \"none\"));\n // mousedown + preventDefault so the contenteditable selection isn't lost.\n b.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n onDown();\n });\n return b;\n}\n\nfunction buildRichToolbar(): HTMLElement {\n const t = document.createElement(\"div\");\n t.setAttribute(\"data-cms-inline-edit-toolbar\", \"\");\n t.style.cssText =\n \"position:fixed;top:14px;left:50%;transform:translateX(-50%);\" +\n \"background:#1c2027;border:1px solid #3a3f4a;border-radius:10px;\" +\n \"padding:6px 10px;display:flex;gap:6px;align-items:center;\" +\n \"z-index:2147483647;box-shadow:0 8px 32px rgba(0,0,0,.5);\" +\n \"font-family:system-ui,sans-serif;\";\n\n t.appendChild(toolbarButton(\"<b>B</b>\", uiLabels.bold, () => document.execCommand(\"bold\")));\n t.appendChild(toolbarButton(\"<i>I</i>\", uiLabels.italic, () => document.execCommand(\"italic\")));\n t.appendChild(toolbarButton(\"<u>U</u>\", uiLabels.underline, () => document.execCommand(\"underline\")));\n\n const sep = () => {\n const s = document.createElement(\"div\");\n s.style.cssText = \"width:1px;height:20px;background:#3a3f4a;\";\n return s;\n };\n t.appendChild(sep());\n\n // Bullet + numbered lists — native execCommand, and the Markdown serializer\n // already round-trips <ul>/<ol> to \"- \" / \"1. \" so no save-path change needed.\n t.appendChild(toolbarButton(UL_SVG, uiLabels.unorderedList, () => document.execCommand(\"insertUnorderedList\")));\n t.appendChild(toolbarButton(OL_SVG, uiLabels.orderedList, () => document.execCommand(\"insertOrderedList\")));\n\n t.appendChild(sep());\n\n // Text color — execCommand foreColor applies to the current selection.\n const clrLabel = document.createElement(\"label\");\n clrLabel.style.cssText = \"display:flex;align-items:center;gap:5px;color:#9aa4b2;font-size:12px;cursor:pointer;\";\n clrLabel.textContent = uiLabels.color;\n const clr = document.createElement(\"input\");\n clr.type = \"color\";\n clr.style.cssText = \"width:28px;height:24px;border:1px solid #3a3f4a;border-radius:5px;cursor:pointer;padding:1px;background:none;\";\n clr.addEventListener(\"mousedown\", (e) => e.stopPropagation());\n clr.addEventListener(\"input\", () => document.execCommand(\"foreColor\", false, clr.value));\n clrLabel.prepend(clr);\n t.appendChild(clrLabel);\n\n t.appendChild(sep());\n\n const emojiBtn = toolbarButton(\"😀\", uiLabels.emoji, () => toggleEmojiPicker(emojiBtn));\n emojiBtn.style.fontSize = \"16px\";\n t.appendChild(emojiBtn);\n\n t.appendChild(sep());\n\n const done = document.createElement(\"button\");\n done.type = \"button\";\n done.textContent = uiLabels.done;\n done.style.cssText =\n \"background:#00b2ff;border:none;color:#04121c;padding:0 14px;height:30px;\" +\n \"border-radius:6px;cursor:pointer;font-size:12px;font-weight:700;\";\n done.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n deactivateRich();\n });\n t.appendChild(done);\n\n document.body.appendChild(t);\n return t;\n}\n\n/* ─── emoji picker (compact) ────────────────────────────────────────────── */\nconst EMOJIS =\n \"😀 😃 😄 😁 😆 😉 😊 😍 🤩 😎 🤔 🙌 👏 👍 👎 🙏 💪 🔥 ⚡ ✨ 🎉 ✅ ❌ 💯 ⭐ 🚀 💡 📈 📉 🧠 ❤️ 🧡 💛 💚 💙 💜 🇩🇰 🇪🇺\".split(\n \" \",\n );\nlet emojiPicker: HTMLElement | null = null;\nlet savedRange: Range | null = null;\n\nfunction toggleEmojiPicker(anchor: HTMLElement): void {\n if (!emojiPicker) emojiPicker = buildEmojiPicker();\n if (emojiPicker.style.display === \"block\") {\n hideEmojiPicker();\n return;\n }\n const sel = window.getSelection();\n if (sel && sel.rangeCount > 0) savedRange = sel.getRangeAt(0).cloneRange();\n const rect = anchor.getBoundingClientRect();\n emojiPicker.style.top = `${rect.bottom + 6}px`;\n emojiPicker.style.left = `${Math.min(rect.left, window.innerWidth - 240)}px`;\n emojiPicker.style.display = \"block\";\n}\n\nfunction hideEmojiPicker(): void {\n if (emojiPicker) emojiPicker.style.display = \"none\";\n}\n\nfunction buildEmojiPicker(): HTMLElement {\n const p = document.createElement(\"div\");\n p.setAttribute(\"data-cms-inline-edit-toolbar\", \"\");\n p.style.cssText =\n \"position:fixed;z-index:2147483646;background:#1c2027;border:1px solid #3a3f4a;\" +\n \"border-radius:10px;padding:8px;width:230px;max-height:200px;overflow-y:auto;\" +\n \"display:none;box-shadow:0 8px 32px rgba(0,0,0,.5);\";\n const grid = document.createElement(\"div\");\n grid.style.cssText = \"display:flex;flex-wrap:wrap;gap:2px;\";\n EMOJIS.forEach((em) => {\n const b = document.createElement(\"button\");\n b.type = \"button\";\n b.textContent = em;\n b.style.cssText =\n \"background:none;border:none;cursor:pointer;border-radius:5px;width:32px;height:32px;font-size:18px;\";\n b.addEventListener(\"mouseenter\", () => (b.style.background = \"#2a2f38\"));\n b.addEventListener(\"mouseleave\", () => (b.style.background = \"none\"));\n b.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n insertEmoji(em);\n });\n grid.appendChild(b);\n });\n p.appendChild(grid);\n document.body.appendChild(p);\n return p;\n}\n\nfunction insertEmoji(emoji: string): void {\n if (!richCtx) return;\n richCtx.el.focus();\n const sel = window.getSelection();\n if (savedRange && sel) {\n sel.removeAllRanges();\n sel.addRange(savedRange);\n }\n document.execCommand(\"insertText\", false, emoji);\n savedRange = null;\n hideEmojiPicker();\n}\n\n// Click outside the active region (and outside the toolbar) commits the edit.\nif (typeof document !== \"undefined\") {\n document.addEventListener(\n \"mousedown\",\n (e) => {\n if (!richCtx) return;\n const target = e.target as HTMLElement | null;\n if (!target) return;\n if (target.closest(\"[data-cms-inline-edit-toolbar]\")) return;\n if (richCtx.el.contains(target)) return;\n deactivateRich();\n },\n true,\n );\n}\n\n/**\n * Sets a value at a dot-path into a plain-data tree, where a numeric segment\n * indexes into an array (e.g. \"slides.2.eyebrow\" — flagship-style nested\n * content; a flat \"heroEyebrow\" is still just a 1-segment path). Bails\n * silently (no throw) if the path doesn't resolve — a stale/malformed path\n * must never crash the save, just fail to apply.\n */\nfunction setDeepField(data: Record<string, unknown>, path: string, value: string): void {\n const parts = path.split(\".\");\n let obj: any = data;\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i] ?? \"\";\n const key: string | number = /^\\d+$/.test(part) ? Number(part) : part;\n if (obj == null || typeof obj !== \"object\" || obj[key] === undefined) return;\n obj = obj[key];\n }\n const last = parts[parts.length - 1] ?? \"\";\n const lastKey: string | number = /^\\d+$/.test(last) ? Number(last) : last;\n if (obj == null || typeof obj !== \"object\") return;\n obj[lastKey] = value;\n}\n\n/**\n * Converts an edited contenteditable region's innerHTML back to Markdown so a\n * rich article body round-trips through the cms `richtext` contract (fields\n * store Markdown, `marked` renders it — NOT HTML). Handles the structures a\n * marked-rendered body + the toolbar produce: headings, paragraphs, emphasis,\n * links, lists, blockquote, code. Formatting with no clean Markdown equivalent\n * (underline, coloured spans) is passed through as inline HTML — `marked`\n * renders inline HTML, so it survives without corrupting the source. Tables and\n * anything unrecognised are passed through as their outerHTML for the same\n * reason: never drop content just because it doesn't map to a Markdown token.\n */\nfunction htmlToMarkdown(html: string): string {\n const container = document.createElement(\"div\");\n container.innerHTML = html;\n return serializeBlockChildren(container).replace(/\\n{3,}/g, \"\\n\\n\").trim() + \"\\n\";\n}\n\nfunction serializeBlockChildren(parent: Node): string {\n const blocks: string[] = [];\n parent.childNodes.forEach((node) => {\n const s = serializeBlock(node).trim();\n if (s) blocks.push(s);\n });\n return blocks.join(\"\\n\\n\");\n}\n\nfunction serializeBlock(node: Node): string {\n if (node.nodeType === Node.TEXT_NODE) return (node.textContent ?? \"\").trim();\n if (node.nodeType !== Node.ELEMENT_NODE) return \"\";\n const el = node as HTMLElement;\n const tag = el.tagName.toLowerCase();\n switch (tag) {\n case \"h1\": return \"# \" + serializeInline(el);\n case \"h2\": return \"## \" + serializeInline(el);\n case \"h3\": return \"### \" + serializeInline(el);\n case \"h4\": return \"#### \" + serializeInline(el);\n case \"h5\": return \"##### \" + serializeInline(el);\n case \"h6\": return \"###### \" + serializeInline(el);\n case \"p\":\n case \"div\":\n return serializeInline(el);\n case \"ul\":\n return serializeList(el, false);\n case \"ol\":\n return serializeList(el, true);\n case \"blockquote\":\n // Serialize the quote's OWN block children (it usually wraps <p>s), then\n // prefix each line with \"> \" — treating it as inline dropped the <p> and\n // left a stray leading space.\n return serializeBlockChildren(el)\n .split(\"\\n\")\n .map((l) => (l ? \"> \" + l : \">\"))\n .join(\"\\n\");\n case \"pre\":\n return \"```\\n\" + (el.textContent ?? \"\").replace(/\\n+$/, \"\") + \"\\n```\";\n case \"hr\":\n return \"---\";\n case \"br\":\n return \"\";\n case \"table\":\n // Rebuild the Markdown pipe table (NOT raw-HTML passthrough) so the\n // consumer's marked renderer re-applies its own table treatment (e.g.\n // broberg's mobile scroll-wrapper) instead of getting a bare <table>.\n return serializeTable(el);\n default:\n return serializeInline(el);\n }\n}\n\nfunction serializeTable(table: HTMLElement): string {\n const cellText = (c: Element) => serializeInline(c).trim().replace(/\\|/g, \"\\\\|\");\n const rows: string[] = [];\n const headCells = Array.from(table.querySelectorAll(\"thead tr\")).flatMap((tr) =>\n Array.from(tr.children).map(cellText),\n );\n if (headCells.length) {\n rows.push(\"| \" + headCells.join(\" | \") + \" |\");\n rows.push(\"| \" + headCells.map(() => \"---\").join(\" | \") + \" |\");\n }\n const bodyRows = table.querySelector(\"tbody\")\n ? Array.from(table.querySelectorAll(\"tbody tr\"))\n : Array.from(table.querySelectorAll(\"tr\")).filter((tr) => !tr.closest(\"thead\"));\n bodyRows.forEach((tr) => {\n rows.push(\"| \" + Array.from(tr.children).map(cellText).join(\" | \") + \" |\");\n });\n return rows.join(\"\\n\");\n}\n\nfunction serializeList(listEl: HTMLElement, ordered: boolean): string {\n const items: string[] = [];\n let n = 1;\n listEl.childNodes.forEach((child) => {\n if (child.nodeType === Node.ELEMENT_NODE && (child as HTMLElement).tagName.toLowerCase() === \"li\") {\n const marker = ordered ? `${n++}. ` : \"- \";\n items.push(marker + serializeInline(child as HTMLElement).trim());\n }\n });\n return items.join(\"\\n\");\n}\n\nfunction serializeInline(node: Node): string {\n let out = \"\";\n node.childNodes.forEach((child) => {\n if (child.nodeType === Node.TEXT_NODE) {\n out += (child.textContent ?? \"\").replace(/\\s+/g, \" \");\n return;\n }\n if (child.nodeType !== Node.ELEMENT_NODE) return;\n const el = child as HTMLElement;\n const tag = el.tagName.toLowerCase();\n const inner = serializeInline(el);\n switch (tag) {\n case \"strong\":\n case \"b\":\n out += inner.trim() ? `**${inner.trim()}**` : \"\";\n break;\n case \"em\":\n case \"i\":\n out += inner.trim() ? `*${inner.trim()}*` : \"\";\n break;\n case \"code\":\n out += \"`\" + inner + \"`\";\n break;\n case \"br\":\n out += \" \\n\";\n break;\n case \"a\": {\n const href = el.getAttribute(\"href\") || \"\";\n out += href ? `[${inner}](${href})` : inner;\n break;\n }\n case \"img\": {\n // Content images embedded in the body () — dropping them\n // would silently delete images from an article on save. Void element,\n // no children, so this must be handled explicitly.\n const src = el.getAttribute(\"src\") || \"\";\n const alt = el.getAttribute(\"alt\") || \"\";\n if (src) out += ``;\n break;\n }\n case \"u\":\n out += `<u>${inner}</u>`; // no Markdown for underline — pass through\n break;\n case \"span\":\n case \"font\": {\n const color = el.style.color || el.getAttribute(\"color\") || \"\";\n out += color ? `<span style=\"color:${color}\">${inner}</span>` : inner;\n break;\n }\n default:\n out += inner;\n }\n });\n return out;\n}\n\nasync function saveField(el: HTMLElement, value: string, token: string, options: ResolvedOptions): Promise<void> {\n const collection = el.dataset.cmsCollection;\n const slug = el.dataset.cmsSlug;\n const field = el.dataset.cmsField;\n if (!collection || !slug || !field) return;\n const slice = el.dataset.cmsSlice;\n\n showPill(el, \"saving\");\n try {\n const getRes = await fetch(\n `${options.cmsBaseUrl}/api/cms/${collection}/${slug}?site=${options.siteId}`,\n { headers: { Authorization: `Bearer ${token}` } },\n );\n if (!getRes.ok) throw new Error(`GET failed: ${getRes.status}`);\n const doc = (await getRes.json()) as { data?: Record<string, unknown> };\n // Deep-clone so mutating a nested array/object (dot-path saves) never\n // aliases the fetched doc — same safety whether field is flat or nested.\n const mergedData = JSON.parse(JSON.stringify(doc.data ?? {})) as Record<string, unknown>;\n if (slice !== undefined) {\n // Field-slice save: replace just this segment inside the full field value,\n // preserving every other segment + embed. Aborts on a non-unique match.\n const currentVal = typeof mergedData[field] === \"string\" ? (mergedData[field] as string) : \"\";\n mergedData[field] = applyFieldSlice(currentVal, slice, value);\n } else if (field.includes(\".\")) {\n setDeepField(mergedData, field, value);\n } else {\n mergedData[field] = value;\n }\n\n const patchRes = await fetch(\n `${options.cmsBaseUrl}/api/cms/${collection}/${slug}?site=${options.siteId}`,\n {\n method: \"PATCH\",\n headers: { Authorization: `Bearer ${token}`, \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ data: mergedData }),\n },\n );\n if (!patchRes.ok) throw new Error(`PATCH failed: ${patchRes.status}`);\n // The slice we just wrote is now the current text — track it so a second\n // edit of the same segment (no reload) matches against the new value.\n if (slice !== undefined) el.dataset.cmsSlice = value;\n showPill(el, \"saved\");\n } catch {\n showPill(el, \"error\");\n }\n}\n\nconst pills = new WeakMap<HTMLElement, HTMLElement>();\n\nfunction showPill(el: HTMLElement, state: \"saving\" | \"saved\" | \"error\"): void {\n let pill = pills.get(el);\n if (!pill) {\n pill = document.createElement(\"span\");\n pill.setAttribute(\"data-cms-inline-edit-pill\", \"\");\n document.body.appendChild(pill);\n pills.set(el, pill);\n }\n const rect = el.getBoundingClientRect();\n pill.style.cssText =\n `position:fixed;top:${rect.top - 26}px;left:${rect.left}px;font:600 11px system-ui,sans-serif;` +\n `padding:3px 9px;border-radius:5px;z-index:2147483647;pointer-events:none;` +\n `box-shadow:0 2px 8px rgba(0,0,0,.25);`;\n\n if (state === \"saving\") {\n pill.textContent = uiLabels.saving;\n pill.style.background = \"#1c2027\";\n pill.style.color = \"#fff\";\n } else if (state === \"saved\") {\n pill.textContent = uiLabels.saved;\n pill.style.background = \"#16a34a\";\n pill.style.color = \"#fff\";\n setTimeout(() => {\n pill?.remove();\n pills.delete(el);\n }, 1500);\n } else {\n pill.textContent = uiLabels.error;\n pill.style.background = \"#dc2626\";\n pill.style.color = \"#fff\";\n }\n}\n\nfunction showActiveBadge(options: ResolvedOptions): void {\n // The connected badge IS the exit-edit action: [icon] \"Afslut redigering\".\n // No \"Redigerer som {name}\" — the whole pill is one click to leave edit mode.\n const badge = document.createElement(\"button\");\n badge.type = \"button\";\n badge.setAttribute(\"data-cms-inline-edit-badge\", \"\");\n badge.style.cssText =\n \"position:fixed;bottom:16px;left:16px;display:inline-flex;align-items:center;gap:7px;\" +\n \"background:#1c2027;color:#fff;font:600 12px system-ui,sans-serif;padding:8px 14px;\" +\n \"border-radius:999px;z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);\" +\n \"border:none;cursor:pointer;opacity:.9;transition:opacity .15s;\";\n const text = document.createElement(\"span\");\n text.textContent = options.disconnectLabel;\n badge.append(makeIcon(), text);\n badge.addEventListener(\"mouseenter\", () => (badge.style.opacity = \"1\"));\n badge.addEventListener(\"mouseleave\", () => (badge.style.opacity = \".9\"));\n badge.addEventListener(\"click\", () => {\n disconnect(options);\n window.location.reload();\n });\n document.body.appendChild(badge);\n}\n\n/** Reads JWT claims for DISPLAY ONLY — never used for authorization decisions. */\nfunction decodeJwtPayload(token: string): Record<string, unknown> | null {\n try {\n const payload = token.split(\".\")[1];\n if (!payload) return null;\n return JSON.parse(atob(payload.replace(/-/g, \"+\").replace(/_/g, \"/\")));\n } catch {\n return null;\n }\n}\n\nfunction injectStyles(): void {\n const style = document.createElement(\"style\");\n style.textContent = `\n [data-cms-field] { outline: 1px dashed transparent; outline-offset: 2px; cursor: text; transition: outline-color .15s; }\n [data-cms-field]:hover { outline-color: rgba(0,178,255,.5); }\n [data-cms-field][contenteditable=\"true\"] { outline: 2px solid #00b2ff; outline-offset: 2px; }\n [data-cms-field][data-cms-richtext=\"true\"] { cursor: text; }\n .cms-rich-editing { outline: 2px solid #00b2ff !important; outline-offset: 6px; border-radius: 4px; }\n `;\n document.head.appendChild(style);\n}\n"],"mappings":";AAYO,SAAS,gBAAgB,SAAiB,UAAkB,MAAsB;AACvF,QAAM,QAAQ,QAAQ,QAAQ,QAAQ;AACtC,MAAI,UAAU,GAAI,OAAM,IAAI,MAAM,iCAAiC;AACnE,MAAI,QAAQ,QAAQ,UAAU,QAAQ,SAAS,MAAM,MAAM,IAAI;AAC7D,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO,QAAQ,MAAM,GAAG,KAAK,IAAI,OAAO,QAAQ,MAAM,QAAQ,SAAS,MAAM;AAC/E;;;ACiCA,IAAM,iBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,aAAa;AAAA,EACb,eAAe;AAAA,EACf,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AACT;AAKA,IAAI,WAAuC;AAE3C,SAAS,eAAe,SAA6C;AACnE,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,YAAY;AAAA;AAAA,IAEZ,cAAc;AAAA,IACd,iBAAiB;AAAA,IACjB,GAAG;AAAA,IACH,QAAQ,EAAE,GAAG,gBAAgB,GAAI,QAAQ,UAAU,CAAC,EAAG;AAAA,EACzD;AACF;AAEA,eAAsB,eAAe,SAA2C;AAC9E,MAAI,OAAO,WAAW,YAAa;AACnC,QAAM,WAAW,eAAe,OAAO;AACvC,aAAW,SAAS;AAEpB,sBAAoB,QAAQ;AAE5B,QAAM,UAAU,MAAM,aAAa,QAAQ;AAC3C,MAAI,CAAC,QAAS;AAEd,QAAM,QAA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":["/**\n * Replace ONE slice of a larger text field.\n *\n * Used when an element renders a single SEGMENT of a bigger field — e.g. one\n * prose paragraph of a `content` body that is interleaved with `[block:]`\n * embeds — so editing that segment must write back into the full field without\n * clobbering the other segments or the embeds.\n *\n * Safety-first: throws if `original` is not found EXACTLY once, so an ambiguous\n * or stale slice ABORTS the save (surfaced as the error pill) instead of\n * corrupting the whole field. Pure + framework-agnostic; unit-tested.\n */\nexport function applyFieldSlice(current: string, original: string, next: string): string {\n const first = current.indexOf(original);\n if (first === -1) throw new Error(\"field-slice: original not found\");\n if (current.indexOf(original, first + original.length) !== -1) {\n throw new Error(\"field-slice: original found more than once (ambiguous)\");\n }\n return current.slice(0, first) + next + current.slice(first + original.length);\n}\n","/**\n * Browser entry — zero dependencies. Site-wide: activated once per browser\n * via a \"connect\" link (see docs/features/F157-inline-editing.md), then\n * every page load on the site automatically offers click-to-edit on any\n * element carrying data-cms-collection/data-cms-slug/data-cms-field\n * (F129's attribute convention) — no per-document step.\n */\nimport { applyFieldSlice } from \"./field-slice\";\nexport { applyFieldSlice } from \"./field-slice\";\n\n/**\n * Labels for the in-editor UI — the rich-text toolbar (bold/italic/underline\n * tooltips, the visible \"colour\" + \"done\" buttons, the emoji tooltip) and the\n * save-status pill. Every field is optional; unset fields keep the Danish\n * default. Pass an English (or any-locale) set on a non-Danish site so the\n * toolbar and status text match the page language.\n */\nexport interface InlineEditLabels {\n bold?: string;\n italic?: string;\n underline?: string;\n orderedList?: string;\n unorderedList?: string;\n color?: string;\n emoji?: string;\n done?: string;\n saving?: string;\n saved?: string;\n error?: string;\n}\n\nexport interface InlineEditOptions {\n /** Base URL of the CMS API, e.g. \"https://webhouse.app\". */\n cmsBaseUrl: string;\n /** Site id passed as ?site= on every CMS API call, e.g. \"broberg-ai\". */\n siteId: string;\n /** URL query param carrying a freshly-minted token from the connect redirect. Default \"cms_edit\". */\n tokenParam?: string;\n /** localStorage key the token is persisted under — survives across sessions/tabs. Default \"wh-inline-edit-token\". */\n storageKey?: string;\n /** Text for the \"not connected yet\" prompt (a square-pen icon is prepended). Default \"Log ind for at redigere\". */\n connectLabel?: string;\n /** Text for the \"connected + editing\" badge — clicking it LEAVES edit mode but keeps the login (icon prepended). Default \"Afbryd\". */\n disconnectLabel?: string;\n /** Text for the explicit \"log out\" action on the idle pill — clicking it clears the token (back to the logged-out state). Default \"Log ud\". */\n logoutLabel?: string;\n /** Show an on-site \"connect\" pill to LOGGED-OUT visitors (click → connect flow).\n * Default FALSE — customer-safe: a visitor without a token sees NOTHING. Only\n * enable for a site with no real customers (e.g. an internal/first-party site)\n * where a self-contained on-site login entry is wanted. The safe entry for a\n * customer site is always the \"Redigér live\" button in webhouse.app CMS-admin. */\n connectPrompt?: boolean;\n /** Localised labels for the toolbar + save-status pill. Defaults are Danish. */\n labels?: InlineEditLabels;\n}\n\ninterface ResolvedOptions extends Required<Omit<InlineEditOptions, \"labels\">> {\n labels: Required<InlineEditLabels>;\n}\n\nconst DEFAULT_LABELS: Required<InlineEditLabels> = {\n bold: \"Fed\",\n italic: \"Kursiv\",\n underline: \"Understreget\",\n orderedList: \"Nummereret liste\",\n unorderedList: \"Punktliste\",\n color: \"Farve\",\n emoji: \"Indsæt emoji\",\n done: \"Færdig\",\n saving: \"Gemmer…\",\n saved: \"Gemt ✓\",\n error: \"Fejl — prøv igen\",\n};\n\n// Set once from resolved options in initInlineEdit(); read by the (singleton)\n// toolbar and the save-status pill so their signatures stay unchanged. One edit\n// session per page → a single module-level value is safe.\nlet uiLabels: Required<InlineEditLabels> = DEFAULT_LABELS;\n\nfunction resolveOptions(options: InlineEditOptions): ResolvedOptions {\n return {\n tokenParam: \"cms_edit\",\n storageKey: \"wh-inline-edit-token\",\n // No emoji in defaults — the square-pen SVG is the icon; some sites ban emoji.\n connectLabel: \"Log ind for at redigere\",\n disconnectLabel: \"Afbryd\",\n logoutLabel: \"Log ud\",\n connectPrompt: false,\n ...options,\n labels: { ...DEFAULT_LABELS, ...(options.labels ?? {}) },\n };\n}\n\nexport async function initInlineEdit(options: InlineEditOptions): Promise<void> {\n if (typeof window === \"undefined\") return;\n const resolved = resolveOptions(options);\n uiLabels = resolved.labels;\n\n // Capture BEFORE checkEnabled so we know whether the token JUST arrived from\n // the connect redirect (→ drop straight into edit mode) vs. a normal load\n // with a stored token (→ idle \"Rediger\" pill, don't force edit mode).\n const freshFromUrl = captureTokenFromUrl(resolved);\n\n const enabled = await checkEnabled(resolved);\n if (!enabled) return;\n\n const token = getConnectedToken(options);\n if (!token) {\n // Logged-out visitor / customer. DEFAULT: show NOTHING (customer-safe) —\n // the consumer can now call initInlineEdit() unconditionally without leaking\n // an edit affordance. Only sites that opt in (connectPrompt: true) get the\n // on-site connect pill + its popup token receiver.\n if (resolved.connectPrompt) {\n showConnectPrompt(resolved);\n // F158 — the connect flow opens in a popup; it posts the freshly-minted\n // token back to this tab. Arm the (origin-validated) receiver.\n listenForTokenMessage(resolved);\n }\n return;\n }\n\n // Connected editor. Wire fields once, then pick the entry state: arrived from\n // connect → edit now; normal load with a stored token → idle \"Rediger\" pill\n // (one click enters edit mode; the token persists so \"Rediger\" stays visible\n // on every page while logged in — no trip back to admin).\n setupFields(token, resolved);\n if (freshFromUrl) enterEditMode();\n else showIdlePill();\n}\n\n/**\n * F158 — receive the edit token from the connect popup via postMessage.\n * Hard origin check (message MUST come from cmsBaseUrl) + type + site + expiry\n * guards before the token is trusted. On success: persist, swap the connect\n * prompt for edit mode — no page reload.\n */\nfunction listenForTokenMessage(options: ResolvedOptions): void {\n let cmsOrigin: string;\n try {\n cmsOrigin = new URL(options.cmsBaseUrl).origin;\n } catch {\n return;\n }\n window.addEventListener(\"message\", (event: MessageEvent) => {\n if (event.origin !== cmsOrigin) return;\n const data = event.data as { type?: string; token?: string; site?: string } | null;\n if (!data || data.type !== \"wh-inline-edit-token\" || typeof data.token !== \"string\") return;\n if (data.site && data.site !== options.siteId) return;\n if (isExpired(data.token)) return;\n if (document.querySelector(\"[data-cms-inline-edit-badge]\")) return; // already active\n localStorage.setItem(options.storageKey, data.token);\n document.querySelector(\"[data-cms-inline-edit-connect]\")?.remove();\n // Fresh connect via popup → wire fields + drop straight into edit mode.\n setupFields(data.token, options);\n enterEditMode();\n });\n}\n\n/**\n * A valid (non-expired) token already connected in this browser for this\n * site, or null. Also captures a fresh `?cms_edit=` token from the URL\n * first, so a page can call this directly right after the connect redirect\n * without going through initInlineEdit(). Exposed so a site's own /admin\n * page (or any other tool built on the same connected session) can reuse\n * the same storage/expiry logic instead of re-implementing it.\n */\nexport function getConnectedToken(options: InlineEditOptions): string | null {\n if (typeof window === \"undefined\") return null;\n const resolved = resolveOptions(options);\n captureTokenFromUrl(resolved);\n const token = localStorage.getItem(resolved.storageKey);\n if (!token) return null;\n if (isExpired(token)) {\n localStorage.removeItem(resolved.storageKey);\n return null;\n }\n return token;\n}\n\n/** The URL that mints a fresh 30-day site-scoped token and redirects back to `returnUrl`. */\nexport function buildConnectUrl(options: InlineEditOptions, returnUrl: string): string {\n const resolved = resolveOptions(options);\n return (\n `${resolved.cmsBaseUrl}/admin/inline-edit/connect?site=${encodeURIComponent(resolved.siteId)}` +\n `&return=${encodeURIComponent(returnUrl)}`\n );\n}\n\n/** Clears the connected token in this browser (e.g. a \"log out\" action in a site's own /admin panel). */\nexport function disconnect(options: InlineEditOptions): void {\n if (typeof window === \"undefined\") return;\n localStorage.removeItem(resolveOptions(options).storageKey);\n}\n\n/** Captures a token minted by /admin/inline-edit/connect, then strips it from\n * the URL. Returns true when a FRESH token was just captured from the URL\n * (i.e. this is the connect-redirect landing) so the caller can auto-enter\n * edit mode; false on a normal load where the token comes from localStorage. */\nfunction captureTokenFromUrl(options: ResolvedOptions): boolean {\n const url = new URL(window.location.href);\n const urlToken = url.searchParams.get(options.tokenParam);\n if (!urlToken) return false;\n localStorage.setItem(options.storageKey, urlToken);\n url.searchParams.delete(options.tokenParam);\n window.history.replaceState({}, \"\", url.toString());\n return true;\n}\n\nasync function checkEnabled(options: ResolvedOptions): Promise<boolean> {\n try {\n const res = await fetch(`${options.cmsBaseUrl}/api/inline-edit/status?site=${options.siteId}`);\n if (!res.ok) return false;\n const body = (await res.json()) as { enabled?: boolean };\n return body.enabled === true;\n } catch {\n return false;\n }\n}\n\nfunction isExpired(token: string): boolean {\n const claims = decodeJwtPayload(token);\n const exp = typeof claims?.exp === \"number\" ? claims.exp : 0;\n return exp <= Date.now() / 1000;\n}\n\n// Lucide \"square-pen\" (https://lucide.dev/icons/square-pen), MIT. Inline SVG so\n// the pill needs no icon-font/runtime dep and inherits `currentColor`. Emoji are\n// deliberately avoided — some consumer sites ban them outright.\nconst SQUARE_PEN_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<path d=\"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7\"/>' +\n '<path d=\"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z\"/>' +\n \"</svg>\";\n\n// Toolbar list-button faces (lucide \"list\" / \"list-ordered\"), inline so no\n// icon-font/runtime dep; stroke inherits the button's white `currentColor`.\nconst UL_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<line x1=\"8\" x2=\"21\" y1=\"6\" y2=\"6\"/><line x1=\"8\" x2=\"21\" y1=\"12\" y2=\"12\"/>' +\n '<line x1=\"8\" x2=\"21\" y1=\"18\" y2=\"18\"/><line x1=\"3\" x2=\"3.01\" y1=\"6\" y2=\"6\"/>' +\n '<line x1=\"3\" x2=\"3.01\" y1=\"12\" y2=\"12\"/><line x1=\"3\" x2=\"3.01\" y1=\"18\" y2=\"18\"/>' +\n \"</svg>\";\n\nconst OL_SVG =\n '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" ' +\n 'fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" ' +\n 'stroke-linejoin=\"round\" aria-hidden=\"true\">' +\n '<line x1=\"10\" x2=\"21\" y1=\"6\" y2=\"6\"/><line x1=\"10\" x2=\"21\" y1=\"12\" y2=\"12\"/>' +\n '<line x1=\"10\" x2=\"21\" y1=\"18\" y2=\"18\"/><path d=\"M4 6h1v4\"/><path d=\"M4 10h2\"/>' +\n '<path d=\"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1\"/>' +\n \"</svg>\";\n\nfunction makeIcon(): HTMLSpanElement {\n const icon = document.createElement(\"span\");\n icon.style.cssText = \"display:inline-flex;line-height:0;flex:0 0 auto\";\n icon.innerHTML = SQUARE_PEN_SVG;\n return icon;\n}\n\nfunction showConnectPrompt(options: ResolvedOptions): void {\n const connectUrl = buildConnectUrl(options, window.location.href);\n\n const link = document.createElement(\"a\");\n link.href = connectUrl;\n link.setAttribute(\"data-cms-inline-edit-connect\", \"\");\n link.style.cssText =\n \"position:fixed;bottom:16px;left:16px;background:#1c2027;color:#fff;\" +\n \"font:600 12px system-ui,sans-serif;padding:8px 14px;border-radius:999px;\" +\n \"text-decoration:none;z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);\" +\n \"display:inline-flex;align-items:center;gap:7px;\";\n const text = document.createElement(\"span\");\n text.textContent = options.connectLabel;\n link.append(makeIcon(), text);\n // F158 — open the connect flow in a popup so the CMS confirmation screen can\n // say \"close this window\". A user-gesture window.open is not popup-blocked;\n // if it is blocked anyway, fall back to the same-tab redirect (F157 path).\n link.addEventListener(\"click\", (e) => {\n e.preventDefault();\n const popup = window.open(\n connectUrl,\n \"wh-inline-edit-connect\",\n \"width=460,height=640,menubar=no,toolbar=no,location=yes,status=no\",\n );\n if (!popup) window.location.href = connectUrl;\n });\n document.body.appendChild(link);\n}\n\n// ─── Connected-editor state machine ────────────────────────────────────────\n// A connected editor (valid token) is ALWAYS in one of two visible states:\n// idle → a \"Rediger\" pill (options.connectLabel); one click enters editing.\n// editing → fields are contenteditable + an \"Afslut redigering\" pill.\n// Leaving edit mode returns to idle and KEEPS the token — the editor stays\n// logged in and can re-enter with one click, on every page, for the token's\n// whole life. Only an explicit \"Log ud\" clears the token (→ logged-out state:\n// no pill at all, same as a customer). Fields are wired ONCE; their click\n// handlers no-op while editingActive is false, so idle is truly inert.\nlet editingActive = false;\nlet fieldsWired = false;\nlet stateOptions: ResolvedOptions | null = null;\n\nfunction setupFields(token: string, options: ResolvedOptions): void {\n stateOptions = options;\n if (fieldsWired) return;\n injectStyles();\n document.querySelectorAll<HTMLElement>(\"[data-cms-field]\").forEach((el) => wireField(el, token, options));\n fieldsWired = true;\n}\n\nfunction enterEditMode(): void {\n if (!stateOptions || editingActive) return;\n editingActive = true;\n removeIdlePill();\n showActiveBadge(stateOptions);\n}\n\nfunction exitEditMode(): void {\n if (!stateOptions || !editingActive) return;\n deactivateRich(); // commit any active rich region first\n editingActive = false;\n document.querySelector(\"[data-cms-inline-edit-badge]\")?.remove();\n showIdlePill();\n}\n\nfunction removeIdlePill(): void {\n document.querySelector(\"[data-cms-inline-edit-idle]\")?.remove();\n}\n\nfunction showIdlePill(): void {\n if (!stateOptions) return;\n const options = stateOptions;\n removeIdlePill();\n const wrap = document.createElement(\"div\");\n wrap.setAttribute(\"data-cms-inline-edit-idle\", \"\");\n wrap.style.cssText =\n \"position:fixed;bottom:16px;left:16px;display:inline-flex;align-items:stretch;\" +\n \"z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);border-radius:999px;overflow:hidden;\";\n // Main action: \"Rediger\" → enter edit mode (no server round-trip; the token\n // already exists locally).\n const edit = document.createElement(\"button\");\n edit.type = \"button\";\n edit.setAttribute(\"data-cms-inline-edit-enter\", \"\");\n edit.style.cssText =\n \"display:inline-flex;align-items:center;gap:7px;background:#1c2027;color:#fff;\" +\n \"font:600 12px system-ui,sans-serif;padding:8px 14px;border:none;cursor:pointer;\";\n const editText = document.createElement(\"span\");\n editText.textContent = options.connectLabel;\n edit.append(makeIcon(), editText);\n edit.addEventListener(\"click\", enterEditMode);\n // Secondary: \"Log ud\" → clear the token (back to the logged-out state).\n const out = document.createElement(\"button\");\n out.type = \"button\";\n out.setAttribute(\"data-cms-inline-edit-logout\", \"\");\n out.textContent = options.logoutLabel;\n out.style.cssText =\n \"background:#141821;color:#9aa4b2;font:600 11px system-ui,sans-serif;padding:8px 12px;\" +\n \"border:none;border-left:1px solid rgba(255,255,255,.12);cursor:pointer;\";\n out.addEventListener(\"click\", () => {\n disconnect(options);\n removeIdlePill();\n });\n wrap.append(edit, out);\n document.body.appendChild(wrap);\n}\n\nfunction wireField(el: HTMLElement, token: string, options: ResolvedOptions): void {\n // Rich fields get the floating formatting toolbar. Two save modes:\n // - data-cms-richtext=\"true\" → save as Markdown (article bodies; cms\n // `richtext` contract renders Markdown via marked).\n // - data-cms-html=\"true\" → save innerHTML VERBATIM (intentional-HTML\n // fields: headings/bios/hero with a branded <em class=\"o\"> accent that\n // has no Markdown equivalent — converting would strip it).\n // Everything else stays a plain single-line contenteditable saving textContent.\n if (el.dataset.cmsRichtext === \"true\") {\n wireRichField(el, token, options, \"markdown\");\n return;\n }\n if (el.dataset.cmsHtml === \"true\") {\n wireRichField(el, token, options, \"html\");\n return;\n }\n\n el.addEventListener(\"click\", (e) => {\n if (!editingActive) return; // idle: the field behaves normally, not editable\n if (el.getAttribute(\"contenteditable\") === \"true\") return;\n // Many editable fields (card titles/blurbs) sit inside a clickable <a>/\n // <button> ancestor (the card itself) — without this, \"click to edit\"\n // would immediately navigate away instead of focusing the field.\n e.preventDefault();\n e.stopPropagation();\n el.dataset.cmsOriginalValue = el.textContent ?? \"\";\n el.setAttribute(\"contenteditable\", \"true\");\n el.focus();\n });\n\n el.addEventListener(\"blur\", () => {\n el.removeAttribute(\"contenteditable\");\n const original = el.dataset.cmsOriginalValue ?? \"\";\n const current = el.textContent ?? \"\";\n if (current.trim() === original.trim()) return;\n void saveField(el, current.trim(), token, options);\n });\n\n el.addEventListener(\"paste\", (e) => {\n e.preventDefault();\n const text = e.clipboardData?.getData(\"text/plain\") ?? \"\";\n document.execCommand(\"insertText\", false, text);\n });\n\n el.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Enter\") {\n e.preventDefault();\n el.blur();\n }\n });\n}\n\n/* ─── Rich-text mode (article bodies) ──────────────────────────────────────\n * A single editable region + a floating B/I/U · color · emoji · Done toolbar\n * (the Pitch Vault pattern, minus the iframe/postMessage — we run in the live\n * page's own document). On \"Done\" the region's innerHTML is converted back to\n * Markdown (the cms `richtext` contract: fields store Markdown, not HTML) and\n * saved. Only ONE region is active at a time. */\n\ntype RichMode = \"markdown\" | \"html\";\ninterface RichContext {\n el: HTMLElement;\n token: string;\n options: ResolvedOptions;\n originalHtml: string;\n mode: RichMode;\n}\nlet richCtx: RichContext | null = null;\nlet richToolbar: HTMLElement | null = null;\n\nfunction wireRichField(el: HTMLElement, token: string, options: ResolvedOptions, mode: RichMode): void {\n el.addEventListener(\"click\", (e) => {\n if (!editingActive) return; // idle: the field behaves normally, not editable\n if (richCtx && richCtx.el === el) return; // already editing this region\n e.preventDefault();\n e.stopPropagation();\n activateRich(el, token, options, mode);\n });\n}\n\nfunction activateRich(el: HTMLElement, token: string, options: ResolvedOptions, mode: RichMode): void {\n deactivateRich(); // commit any previously-active region first\n richCtx = { el, token, options, originalHtml: el.innerHTML, mode };\n el.setAttribute(\"contenteditable\", \"true\");\n el.classList.add(\"cms-rich-editing\");\n el.focus();\n showRichToolbar();\n // Let the host page react (e.g. pause a rotating hero carousel while editing).\n document.dispatchEvent(new CustomEvent(\"cms-inline-edit:activate\", { detail: { el } }));\n}\n\nfunction deactivateRich(): void {\n if (!richCtx) return;\n const { el, token, options, originalHtml, mode } = richCtx;\n richCtx = null;\n el.removeAttribute(\"contenteditable\");\n el.classList.remove(\"cms-rich-editing\");\n hideRichToolbar();\n if (el.innerHTML !== originalHtml) {\n const value = mode === \"html\" ? el.innerHTML : htmlToMarkdown(el.innerHTML);\n void saveField(el, value, token, options);\n }\n document.dispatchEvent(new CustomEvent(\"cms-inline-edit:deactivate\", { detail: { el } }));\n}\n\nfunction showRichToolbar(): void {\n if (!richToolbar) richToolbar = buildRichToolbar();\n richToolbar.style.display = \"flex\";\n}\n\nfunction hideRichToolbar(): void {\n if (richToolbar) richToolbar.style.display = \"none\";\n hideEmojiPicker();\n}\n\nfunction toolbarButton(label: string, title: string, onDown: () => void): HTMLButtonElement {\n const b = document.createElement(\"button\");\n b.type = \"button\";\n b.innerHTML = label;\n b.title = title;\n b.style.cssText =\n \"background:none;border:1px solid #3a3f4a;color:#fff;min-width:30px;height:30px;\" +\n \"border-radius:6px;cursor:pointer;font-size:14px;padding:0 8px;line-height:1;\";\n b.addEventListener(\"mouseenter\", () => (b.style.background = \"#2a2f38\"));\n b.addEventListener(\"mouseleave\", () => (b.style.background = \"none\"));\n // mousedown + preventDefault so the contenteditable selection isn't lost.\n b.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n onDown();\n });\n return b;\n}\n\nfunction buildRichToolbar(): HTMLElement {\n const t = document.createElement(\"div\");\n t.setAttribute(\"data-cms-inline-edit-toolbar\", \"\");\n t.style.cssText =\n \"position:fixed;top:14px;left:50%;transform:translateX(-50%);\" +\n \"background:#1c2027;border:1px solid #3a3f4a;border-radius:10px;\" +\n \"padding:6px 10px;display:flex;gap:6px;align-items:center;\" +\n \"z-index:2147483647;box-shadow:0 8px 32px rgba(0,0,0,.5);\" +\n \"font-family:system-ui,sans-serif;\";\n\n t.appendChild(toolbarButton(\"<b>B</b>\", uiLabels.bold, () => document.execCommand(\"bold\")));\n t.appendChild(toolbarButton(\"<i>I</i>\", uiLabels.italic, () => document.execCommand(\"italic\")));\n t.appendChild(toolbarButton(\"<u>U</u>\", uiLabels.underline, () => document.execCommand(\"underline\")));\n\n const sep = () => {\n const s = document.createElement(\"div\");\n s.style.cssText = \"width:1px;height:20px;background:#3a3f4a;\";\n return s;\n };\n t.appendChild(sep());\n\n // Bullet + numbered lists — native execCommand, and the Markdown serializer\n // already round-trips <ul>/<ol> to \"- \" / \"1. \" so no save-path change needed.\n t.appendChild(toolbarButton(UL_SVG, uiLabels.unorderedList, () => document.execCommand(\"insertUnorderedList\")));\n t.appendChild(toolbarButton(OL_SVG, uiLabels.orderedList, () => document.execCommand(\"insertOrderedList\")));\n\n t.appendChild(sep());\n\n // Text color — execCommand foreColor applies to the current selection.\n const clrLabel = document.createElement(\"label\");\n clrLabel.style.cssText = \"display:flex;align-items:center;gap:5px;color:#9aa4b2;font-size:12px;cursor:pointer;\";\n clrLabel.textContent = uiLabels.color;\n const clr = document.createElement(\"input\");\n clr.type = \"color\";\n clr.style.cssText = \"width:28px;height:24px;border:1px solid #3a3f4a;border-radius:5px;cursor:pointer;padding:1px;background:none;\";\n clr.addEventListener(\"mousedown\", (e) => e.stopPropagation());\n clr.addEventListener(\"input\", () => document.execCommand(\"foreColor\", false, clr.value));\n clrLabel.prepend(clr);\n t.appendChild(clrLabel);\n\n t.appendChild(sep());\n\n const emojiBtn = toolbarButton(\"😀\", uiLabels.emoji, () => toggleEmojiPicker(emojiBtn));\n emojiBtn.style.fontSize = \"16px\";\n t.appendChild(emojiBtn);\n\n t.appendChild(sep());\n\n const done = document.createElement(\"button\");\n done.type = \"button\";\n done.textContent = uiLabels.done;\n done.style.cssText =\n \"background:#00b2ff;border:none;color:#04121c;padding:0 14px;height:30px;\" +\n \"border-radius:6px;cursor:pointer;font-size:12px;font-weight:700;\";\n done.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n deactivateRich();\n });\n t.appendChild(done);\n\n document.body.appendChild(t);\n return t;\n}\n\n/* ─── emoji picker (compact) ────────────────────────────────────────────── */\nconst EMOJIS =\n \"😀 😃 😄 😁 😆 😉 😊 😍 🤩 😎 🤔 🙌 👏 👍 👎 🙏 💪 🔥 ⚡ ✨ 🎉 ✅ ❌ 💯 ⭐ 🚀 💡 📈 📉 🧠 ❤️ 🧡 💛 💚 💙 💜 🇩🇰 🇪🇺\".split(\n \" \",\n );\nlet emojiPicker: HTMLElement | null = null;\nlet savedRange: Range | null = null;\n\nfunction toggleEmojiPicker(anchor: HTMLElement): void {\n if (!emojiPicker) emojiPicker = buildEmojiPicker();\n if (emojiPicker.style.display === \"block\") {\n hideEmojiPicker();\n return;\n }\n const sel = window.getSelection();\n if (sel && sel.rangeCount > 0) savedRange = sel.getRangeAt(0).cloneRange();\n const rect = anchor.getBoundingClientRect();\n emojiPicker.style.top = `${rect.bottom + 6}px`;\n emojiPicker.style.left = `${Math.min(rect.left, window.innerWidth - 240)}px`;\n emojiPicker.style.display = \"block\";\n}\n\nfunction hideEmojiPicker(): void {\n if (emojiPicker) emojiPicker.style.display = \"none\";\n}\n\nfunction buildEmojiPicker(): HTMLElement {\n const p = document.createElement(\"div\");\n p.setAttribute(\"data-cms-inline-edit-toolbar\", \"\");\n p.style.cssText =\n \"position:fixed;z-index:2147483646;background:#1c2027;border:1px solid #3a3f4a;\" +\n \"border-radius:10px;padding:8px;width:230px;max-height:200px;overflow-y:auto;\" +\n \"display:none;box-shadow:0 8px 32px rgba(0,0,0,.5);\";\n const grid = document.createElement(\"div\");\n grid.style.cssText = \"display:flex;flex-wrap:wrap;gap:2px;\";\n EMOJIS.forEach((em) => {\n const b = document.createElement(\"button\");\n b.type = \"button\";\n b.textContent = em;\n b.style.cssText =\n \"background:none;border:none;cursor:pointer;border-radius:5px;width:32px;height:32px;font-size:18px;\";\n b.addEventListener(\"mouseenter\", () => (b.style.background = \"#2a2f38\"));\n b.addEventListener(\"mouseleave\", () => (b.style.background = \"none\"));\n b.addEventListener(\"mousedown\", (e) => {\n e.preventDefault();\n e.stopPropagation();\n insertEmoji(em);\n });\n grid.appendChild(b);\n });\n p.appendChild(grid);\n document.body.appendChild(p);\n return p;\n}\n\nfunction insertEmoji(emoji: string): void {\n if (!richCtx) return;\n richCtx.el.focus();\n const sel = window.getSelection();\n if (savedRange && sel) {\n sel.removeAllRanges();\n sel.addRange(savedRange);\n }\n document.execCommand(\"insertText\", false, emoji);\n savedRange = null;\n hideEmojiPicker();\n}\n\n// Click outside the active region (and outside the toolbar) commits the edit.\nif (typeof document !== \"undefined\") {\n document.addEventListener(\n \"mousedown\",\n (e) => {\n if (!richCtx) return;\n const target = e.target as HTMLElement | null;\n if (!target) return;\n if (target.closest(\"[data-cms-inline-edit-toolbar]\")) return;\n if (richCtx.el.contains(target)) return;\n deactivateRich();\n },\n true,\n );\n}\n\n/**\n * Sets a value at a dot-path into a plain-data tree, where a numeric segment\n * indexes into an array (e.g. \"slides.2.eyebrow\" — flagship-style nested\n * content; a flat \"heroEyebrow\" is still just a 1-segment path). Bails\n * silently (no throw) if the path doesn't resolve — a stale/malformed path\n * must never crash the save, just fail to apply.\n */\nfunction setDeepField(data: Record<string, unknown>, path: string, value: string): void {\n const parts = path.split(\".\");\n let obj: any = data;\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i] ?? \"\";\n const key: string | number = /^\\d+$/.test(part) ? Number(part) : part;\n if (obj == null || typeof obj !== \"object\" || obj[key] === undefined) return;\n obj = obj[key];\n }\n const last = parts[parts.length - 1] ?? \"\";\n const lastKey: string | number = /^\\d+$/.test(last) ? Number(last) : last;\n if (obj == null || typeof obj !== \"object\") return;\n obj[lastKey] = value;\n}\n\n/**\n * Converts an edited contenteditable region's innerHTML back to Markdown so a\n * rich article body round-trips through the cms `richtext` contract (fields\n * store Markdown, `marked` renders it — NOT HTML). Handles the structures a\n * marked-rendered body + the toolbar produce: headings, paragraphs, emphasis,\n * links, lists, blockquote, code. Formatting with no clean Markdown equivalent\n * (underline, coloured spans) is passed through as inline HTML — `marked`\n * renders inline HTML, so it survives without corrupting the source. Tables and\n * anything unrecognised are passed through as their outerHTML for the same\n * reason: never drop content just because it doesn't map to a Markdown token.\n */\nfunction htmlToMarkdown(html: string): string {\n const container = document.createElement(\"div\");\n container.innerHTML = html;\n return serializeBlockChildren(container).replace(/\\n{3,}/g, \"\\n\\n\").trim() + \"\\n\";\n}\n\nfunction serializeBlockChildren(parent: Node): string {\n const blocks: string[] = [];\n parent.childNodes.forEach((node) => {\n const s = serializeBlock(node).trim();\n if (s) blocks.push(s);\n });\n return blocks.join(\"\\n\\n\");\n}\n\nfunction serializeBlock(node: Node): string {\n if (node.nodeType === Node.TEXT_NODE) return (node.textContent ?? \"\").trim();\n if (node.nodeType !== Node.ELEMENT_NODE) return \"\";\n const el = node as HTMLElement;\n const tag = el.tagName.toLowerCase();\n switch (tag) {\n case \"h1\": return \"# \" + serializeInline(el);\n case \"h2\": return \"## \" + serializeInline(el);\n case \"h3\": return \"### \" + serializeInline(el);\n case \"h4\": return \"#### \" + serializeInline(el);\n case \"h5\": return \"##### \" + serializeInline(el);\n case \"h6\": return \"###### \" + serializeInline(el);\n case \"p\":\n case \"div\":\n return serializeInline(el);\n case \"ul\":\n return serializeList(el, false);\n case \"ol\":\n return serializeList(el, true);\n case \"blockquote\":\n // Serialize the quote's OWN block children (it usually wraps <p>s), then\n // prefix each line with \"> \" — treating it as inline dropped the <p> and\n // left a stray leading space.\n return serializeBlockChildren(el)\n .split(\"\\n\")\n .map((l) => (l ? \"> \" + l : \">\"))\n .join(\"\\n\");\n case \"pre\":\n return \"```\\n\" + (el.textContent ?? \"\").replace(/\\n+$/, \"\") + \"\\n```\";\n case \"hr\":\n return \"---\";\n case \"br\":\n return \"\";\n case \"table\":\n // Rebuild the Markdown pipe table (NOT raw-HTML passthrough) so the\n // consumer's marked renderer re-applies its own table treatment (e.g.\n // broberg's mobile scroll-wrapper) instead of getting a bare <table>.\n return serializeTable(el);\n default:\n return serializeInline(el);\n }\n}\n\nfunction serializeTable(table: HTMLElement): string {\n const cellText = (c: Element) => serializeInline(c).trim().replace(/\\|/g, \"\\\\|\");\n const rows: string[] = [];\n const headCells = Array.from(table.querySelectorAll(\"thead tr\")).flatMap((tr) =>\n Array.from(tr.children).map(cellText),\n );\n if (headCells.length) {\n rows.push(\"| \" + headCells.join(\" | \") + \" |\");\n rows.push(\"| \" + headCells.map(() => \"---\").join(\" | \") + \" |\");\n }\n const bodyRows = table.querySelector(\"tbody\")\n ? Array.from(table.querySelectorAll(\"tbody tr\"))\n : Array.from(table.querySelectorAll(\"tr\")).filter((tr) => !tr.closest(\"thead\"));\n bodyRows.forEach((tr) => {\n rows.push(\"| \" + Array.from(tr.children).map(cellText).join(\" | \") + \" |\");\n });\n return rows.join(\"\\n\");\n}\n\nfunction serializeList(listEl: HTMLElement, ordered: boolean): string {\n const items: string[] = [];\n let n = 1;\n listEl.childNodes.forEach((child) => {\n if (child.nodeType === Node.ELEMENT_NODE && (child as HTMLElement).tagName.toLowerCase() === \"li\") {\n const marker = ordered ? `${n++}. ` : \"- \";\n items.push(marker + serializeInline(child as HTMLElement).trim());\n }\n });\n return items.join(\"\\n\");\n}\n\nfunction serializeInline(node: Node): string {\n let out = \"\";\n node.childNodes.forEach((child) => {\n if (child.nodeType === Node.TEXT_NODE) {\n out += (child.textContent ?? \"\").replace(/\\s+/g, \" \");\n return;\n }\n if (child.nodeType !== Node.ELEMENT_NODE) return;\n const el = child as HTMLElement;\n const tag = el.tagName.toLowerCase();\n const inner = serializeInline(el);\n switch (tag) {\n case \"strong\":\n case \"b\":\n out += inner.trim() ? `**${inner.trim()}**` : \"\";\n break;\n case \"em\":\n case \"i\":\n out += inner.trim() ? `*${inner.trim()}*` : \"\";\n break;\n case \"code\":\n out += \"`\" + inner + \"`\";\n break;\n case \"br\":\n out += \" \\n\";\n break;\n case \"a\": {\n const href = el.getAttribute(\"href\") || \"\";\n out += href ? `[${inner}](${href})` : inner;\n break;\n }\n case \"img\": {\n // Content images embedded in the body () — dropping them\n // would silently delete images from an article on save. Void element,\n // no children, so this must be handled explicitly.\n const src = el.getAttribute(\"src\") || \"\";\n const alt = el.getAttribute(\"alt\") || \"\";\n if (src) out += ``;\n break;\n }\n case \"u\":\n out += `<u>${inner}</u>`; // no Markdown for underline — pass through\n break;\n case \"span\":\n case \"font\": {\n const color = el.style.color || el.getAttribute(\"color\") || \"\";\n out += color ? `<span style=\"color:${color}\">${inner}</span>` : inner;\n break;\n }\n default:\n out += inner;\n }\n });\n return out;\n}\n\nasync function saveField(el: HTMLElement, value: string, token: string, options: ResolvedOptions): Promise<void> {\n const collection = el.dataset.cmsCollection;\n const slug = el.dataset.cmsSlug;\n const field = el.dataset.cmsField;\n if (!collection || !slug || !field) return;\n const slice = el.dataset.cmsSlice;\n\n showPill(el, \"saving\");\n try {\n const getRes = await fetch(\n `${options.cmsBaseUrl}/api/cms/${collection}/${slug}?site=${options.siteId}`,\n { headers: { Authorization: `Bearer ${token}` } },\n );\n if (!getRes.ok) throw new Error(`GET failed: ${getRes.status}`);\n const doc = (await getRes.json()) as { data?: Record<string, unknown> };\n // Deep-clone so mutating a nested array/object (dot-path saves) never\n // aliases the fetched doc — same safety whether field is flat or nested.\n const mergedData = JSON.parse(JSON.stringify(doc.data ?? {})) as Record<string, unknown>;\n if (slice !== undefined) {\n // Field-slice save: replace just this segment inside the full field value,\n // preserving every other segment + embed. Aborts on a non-unique match.\n const currentVal = typeof mergedData[field] === \"string\" ? (mergedData[field] as string) : \"\";\n mergedData[field] = applyFieldSlice(currentVal, slice, value);\n } else if (field.includes(\".\")) {\n setDeepField(mergedData, field, value);\n } else {\n mergedData[field] = value;\n }\n\n const patchRes = await fetch(\n `${options.cmsBaseUrl}/api/cms/${collection}/${slug}?site=${options.siteId}`,\n {\n method: \"PATCH\",\n headers: { Authorization: `Bearer ${token}`, \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ data: mergedData }),\n },\n );\n if (!patchRes.ok) throw new Error(`PATCH failed: ${patchRes.status}`);\n // The slice we just wrote is now the current text — track it so a second\n // edit of the same segment (no reload) matches against the new value.\n if (slice !== undefined) el.dataset.cmsSlice = value;\n showPill(el, \"saved\");\n } catch {\n showPill(el, \"error\");\n }\n}\n\nconst pills = new WeakMap<HTMLElement, HTMLElement>();\n\nfunction showPill(el: HTMLElement, state: \"saving\" | \"saved\" | \"error\"): void {\n let pill = pills.get(el);\n if (!pill) {\n pill = document.createElement(\"span\");\n pill.setAttribute(\"data-cms-inline-edit-pill\", \"\");\n document.body.appendChild(pill);\n pills.set(el, pill);\n }\n const rect = el.getBoundingClientRect();\n pill.style.cssText =\n `position:fixed;top:${rect.top - 26}px;left:${rect.left}px;font:600 11px system-ui,sans-serif;` +\n `padding:3px 9px;border-radius:5px;z-index:2147483647;pointer-events:none;` +\n `box-shadow:0 2px 8px rgba(0,0,0,.25);`;\n\n if (state === \"saving\") {\n pill.textContent = uiLabels.saving;\n pill.style.background = \"#1c2027\";\n pill.style.color = \"#fff\";\n } else if (state === \"saved\") {\n pill.textContent = uiLabels.saved;\n pill.style.background = \"#16a34a\";\n pill.style.color = \"#fff\";\n setTimeout(() => {\n pill?.remove();\n pills.delete(el);\n }, 1500);\n } else {\n pill.textContent = uiLabels.error;\n pill.style.background = \"#dc2626\";\n pill.style.color = \"#fff\";\n }\n}\n\nfunction showActiveBadge(options: ResolvedOptions): void {\n // The connected badge IS the exit-edit action: [icon] \"Afslut redigering\".\n // No \"Redigerer som {name}\" — the whole pill is one click to leave edit mode.\n const badge = document.createElement(\"button\");\n badge.type = \"button\";\n badge.setAttribute(\"data-cms-inline-edit-badge\", \"\");\n badge.style.cssText =\n \"position:fixed;bottom:16px;left:16px;display:inline-flex;align-items:center;gap:7px;\" +\n \"background:#1c2027;color:#fff;font:600 12px system-ui,sans-serif;padding:8px 14px;\" +\n \"border-radius:999px;z-index:2147483647;box-shadow:0 4px 16px rgba(0,0,0,.3);\" +\n \"border:none;cursor:pointer;opacity:.9;transition:opacity .15s;\";\n const text = document.createElement(\"span\");\n text.textContent = options.disconnectLabel;\n badge.append(makeIcon(), text);\n badge.addEventListener(\"mouseenter\", () => (badge.style.opacity = \"1\"));\n badge.addEventListener(\"mouseleave\", () => (badge.style.opacity = \".9\"));\n // Clicking the badge LEAVES edit mode but KEEPS the login → back to the idle\n // \"Rediger\" pill (not a logout). Explicit logout lives on the idle pill.\n badge.addEventListener(\"click\", exitEditMode);\n document.body.appendChild(badge);\n}\n\n/** Reads JWT claims for DISPLAY ONLY — never used for authorization decisions. */\nfunction decodeJwtPayload(token: string): Record<string, unknown> | null {\n try {\n const payload = token.split(\".\")[1];\n if (!payload) return null;\n return JSON.parse(atob(payload.replace(/-/g, \"+\").replace(/_/g, \"/\")));\n } catch {\n return null;\n }\n}\n\nfunction injectStyles(): void {\n const style = document.createElement(\"style\");\n style.textContent = `\n [data-cms-field] { outline: 1px dashed transparent; outline-offset: 2px; cursor: text; transition: outline-color .15s; }\n [data-cms-field]:hover { outline-color: rgba(0,178,255,.5); }\n [data-cms-field][contenteditable=\"true\"] { outline: 2px solid #00b2ff; outline-offset: 2px; }\n [data-cms-field][data-cms-richtext=\"true\"] { cursor: text; }\n .cms-rich-editing { outline: 2px solid #00b2ff !important; outline-offset: 6px; border-radius: 4px; }\n `;\n document.head.appendChild(style);\n}\n"],"mappings":";AAYO,SAAS,gBAAgB,SAAiB,UAAkB,MAAsB;AACvF,QAAM,QAAQ,QAAQ,QAAQ,QAAQ;AACtC,MAAI,UAAU,GAAI,OAAM,IAAI,MAAM,iCAAiC;AACnE,MAAI,QAAQ,QAAQ,UAAU,QAAQ,SAAS,MAAM,MAAM,IAAI;AAC7D,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO,QAAQ,MAAM,GAAG,KAAK,IAAI,OAAO,QAAQ,MAAM,QAAQ,SAAS,MAAM;AAC/E;;;ACyCA,IAAM,iBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,QAAQ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