@duffcloudservices/cms 0.1.1 → 0.1.3

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.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Editor Bridge — injected into customer site iframes by the DCS visual editor.
3
+ *
4
+ * Responsibilities:
5
+ * 1. Report available sections and text keys to the parent portal
6
+ * 2. Enable inline contenteditable editing on data-text-key elements (double-click)
7
+ * 3. Render section overlay highlights on hover/select from parent
8
+ * 4. Communicate all interactions back to the parent via postMessage
9
+ * 5. Monitor navigation within the iframe and notify the parent
10
+ * 6. Show floating edit icon on hover for text-key elements
11
+ *
12
+ * NOTE: AI ✨ buttons are rendered by the portal-side SectionOverlayLayer,
13
+ * NOT by this bridge. The bridge only reports section/text key data and
14
+ * handles inline text editing.
15
+ *
16
+ * This script runs inside the iframe (customer site). The parent portal
17
+ * communicates via postMessage using the `dcs:*` message protocol.
18
+ */
19
+ interface SectionInfo {
20
+ id: string;
21
+ label: string | null;
22
+ bounds: {
23
+ x: number;
24
+ y: number;
25
+ width: number;
26
+ height: number;
27
+ };
28
+ textKeyCount: number;
29
+ }
30
+ interface EditorReadyPayload {
31
+ sections: SectionInfo[];
32
+ textKeys: string[];
33
+ contentHeight: number;
34
+ }
35
+ declare function initEditorBridge(): void;
36
+
37
+ export { type EditorReadyPayload, type SectionInfo, initEditorBridge };
@@ -0,0 +1,526 @@
1
+ // src/editor/editorBridge.ts
2
+ function isInIframe() {
3
+ try {
4
+ return globalThis.self !== globalThis.self.parent;
5
+ } catch {
6
+ return true;
7
+ }
8
+ }
9
+ function postToParent(type, data) {
10
+ if (!isInIframe()) return;
11
+ globalThis.self.parent.postMessage({ type, data }, "*");
12
+ }
13
+ var editorActive = false;
14
+ var bridgeInitialized = false;
15
+ var activeEditElement = null;
16
+ var lastKnownPathname = "";
17
+ var editIconElement = null;
18
+ var editIconTarget = null;
19
+ var arrayEditIconElement = null;
20
+ var arrayEditIconTarget = null;
21
+ var editingEnabled = true;
22
+ var originalTextValues = /* @__PURE__ */ new Map();
23
+ function discoverSections() {
24
+ const elements = document.querySelectorAll("[data-section]");
25
+ return Array.from(elements).map((el) => {
26
+ const rect = el.getBoundingClientRect();
27
+ const textKeyCount = el.querySelectorAll("[data-text-key]").length;
28
+ return {
29
+ id: el.dataset.section,
30
+ label: el.dataset.sectionLabel ?? null,
31
+ bounds: {
32
+ x: rect.left + scrollX,
33
+ y: rect.top + scrollY,
34
+ width: rect.width,
35
+ height: rect.height
36
+ },
37
+ textKeyCount
38
+ };
39
+ });
40
+ }
41
+ function discoverTextKeys() {
42
+ return Array.from(document.querySelectorAll("[data-text-key]")).map(
43
+ (el) => el.dataset.textKey
44
+ );
45
+ }
46
+ function showSectionHighlight(_sectionId) {
47
+ }
48
+ function monitorNavigation() {
49
+ lastKnownPathname = globalThis.location.pathname;
50
+ setInterval(() => {
51
+ checkForNavigation();
52
+ }, 250);
53
+ globalThis.addEventListener("popstate", () => {
54
+ checkForNavigation();
55
+ });
56
+ const handleLinkClick = (e) => {
57
+ const link = e.target.closest?.("a[href]");
58
+ if (!link) return;
59
+ const href = link.getAttribute("href");
60
+ if (!href || href.startsWith("#") || href === "javascript:void(0)") return;
61
+ try {
62
+ const resolved = new URL(href, globalThis.location.href);
63
+ if (resolved.origin !== globalThis.location.origin) {
64
+ e.preventDefault();
65
+ e.stopPropagation();
66
+ e.stopImmediatePropagation();
67
+ }
68
+ } catch {
69
+ e.preventDefault();
70
+ }
71
+ };
72
+ globalThis.addEventListener("click", handleLinkClick, true);
73
+ document.addEventListener("click", handleLinkClick, true);
74
+ document.addEventListener("submit", (e) => {
75
+ e.preventDefault();
76
+ e.stopPropagation();
77
+ }, true);
78
+ window.addEventListener("beforeunload", (e) => {
79
+ e.preventDefault();
80
+ });
81
+ }
82
+ function checkForNavigation() {
83
+ const currentPathname = globalThis.location.pathname;
84
+ if (currentPathname === lastKnownPathname) return;
85
+ lastKnownPathname = currentPathname;
86
+ postToParent("dcs:navigation", { pathname: currentPathname });
87
+ if (activeEditElement) {
88
+ finishEdit(activeEditElement);
89
+ }
90
+ removeEditIcon();
91
+ removeArrayEditIcon();
92
+ setTimeout(() => {
93
+ rediscoverAndNotify();
94
+ }, 500);
95
+ }
96
+ function setMode(mode) {
97
+ if (mode === "explore") {
98
+ if (activeEditElement) {
99
+ finishEdit(activeEditElement);
100
+ }
101
+ }
102
+ }
103
+ function rediscoverAndNotify() {
104
+ activeEditElement = null;
105
+ const sections = discoverSections();
106
+ const textKeys = discoverTextKeys();
107
+ const contentHeight = document.body.scrollHeight;
108
+ postToParent("dcs:ready", { sections, textKeys, contentHeight });
109
+ if (editorActive) {
110
+ editorActive = false;
111
+ enableEditorMode();
112
+ }
113
+ }
114
+ function enableEditorMode() {
115
+ if (editorActive) return;
116
+ editorActive = true;
117
+ injectEditorStyles();
118
+ const textElements = document.querySelectorAll("[data-text-key]");
119
+ textElements.forEach((htmlEl) => {
120
+ htmlEl.classList.add("dcs-editable");
121
+ htmlEl.addEventListener("dblclick", handleTextKeyDblClick);
122
+ htmlEl.addEventListener("blur", handleTextKeyBlur);
123
+ htmlEl.addEventListener("keydown", handleTextKeyKeydown);
124
+ htmlEl.addEventListener("mouseenter", () => {
125
+ if (activeEditElement) return;
126
+ const key = htmlEl.dataset.textKey;
127
+ if (isArrayTextKey(key)) {
128
+ showArrayEditIcon(htmlEl);
129
+ } else {
130
+ showEditIcon(htmlEl);
131
+ }
132
+ });
133
+ htmlEl.addEventListener("mouseleave", (e) => {
134
+ const related = e.relatedTarget;
135
+ if (related && (related.classList?.contains("dcs-edit-icon") || related.closest?.(".dcs-edit-icon") || related.classList?.contains("dcs-array-edit-icon") || related.closest?.(".dcs-array-edit-icon"))) return;
136
+ removeEditIcon();
137
+ removeArrayEditIcon();
138
+ });
139
+ });
140
+ const sections = document.querySelectorAll("[data-section]");
141
+ sections.forEach((el) => {
142
+ const sectionId = el.dataset.section;
143
+ el.addEventListener("mouseenter", () => {
144
+ postToParent("dcs:section-hover", { sectionId });
145
+ });
146
+ el.addEventListener("mouseleave", () => {
147
+ postToParent("dcs:section-hover", { sectionId: null });
148
+ });
149
+ el.addEventListener("click", (e) => {
150
+ const target = e.target;
151
+ if (!target.closest("[data-text-key]")) {
152
+ postToParent("dcs:section-click", { sectionId });
153
+ }
154
+ });
155
+ });
156
+ }
157
+ function handleTextKeyDblClick(e) {
158
+ if (!editingEnabled) return;
159
+ e.preventDefault();
160
+ e.stopPropagation();
161
+ e.stopImmediatePropagation();
162
+ const el = e.currentTarget;
163
+ const key = el.dataset.textKey;
164
+ const sectionParent = el.closest("[data-section]");
165
+ const sectionId = sectionParent?.dataset.section ?? null;
166
+ postToParent("dcs:text-key-dblclick", { key, sectionId });
167
+ startInlineEdit(el, key, sectionId);
168
+ }
169
+ function startInlineEdit(el, key, sectionId) {
170
+ if (activeEditElement && activeEditElement !== el) {
171
+ finishEdit(activeEditElement);
172
+ }
173
+ originalTextValues.set(el, el.innerText.trim());
174
+ el.setAttribute("contenteditable", "true");
175
+ el.classList.add("dcs-editing");
176
+ el.focus();
177
+ activeEditElement = el;
178
+ const selection = getSelection();
179
+ const range = document.createRange();
180
+ range.selectNodeContents(el);
181
+ selection?.removeAllRanges();
182
+ selection?.addRange(range);
183
+ postToParent("dcs:text-key-click", { key, sectionId });
184
+ }
185
+ function handleTextKeyBlur(e) {
186
+ const el = e.currentTarget;
187
+ finishEdit(el);
188
+ }
189
+ function handleTextKeyKeydown(e) {
190
+ if (e.key === "Enter" && !e.shiftKey) {
191
+ e.preventDefault();
192
+ e.currentTarget.blur();
193
+ }
194
+ if (e.key === "Escape") {
195
+ e.preventDefault();
196
+ e.currentTarget.blur();
197
+ }
198
+ }
199
+ function finishEdit(el) {
200
+ if (!el.hasAttribute("contenteditable")) return;
201
+ el.removeAttribute("contenteditable");
202
+ el.classList.remove("dcs-editing");
203
+ const key = el.dataset.textKey;
204
+ const sectionParent = el.closest("[data-section]");
205
+ const sectionId = sectionParent?.dataset.section ?? null;
206
+ const newValue = el.innerText.trim();
207
+ const originalValue = originalTextValues.get(el) ?? "";
208
+ if (activeEditElement === el) {
209
+ activeEditElement = null;
210
+ }
211
+ if (newValue !== originalValue) {
212
+ postToParent("dcs:text-key-changed", { key, value: newValue, sectionId });
213
+ }
214
+ originalTextValues.delete(el);
215
+ }
216
+ function focusTextKey(key) {
217
+ const el = document.querySelector(`[data-text-key="${key}"]`);
218
+ if (!el) return;
219
+ el.scrollIntoView({ behavior: "smooth", block: "center" });
220
+ const sectionParent = el.closest("[data-section]");
221
+ const sectionId = sectionParent?.dataset.section ?? null;
222
+ startInlineEdit(el, key, sectionId);
223
+ }
224
+ function updateTextInPlace(key, value) {
225
+ const el = document.querySelector(`[data-text-key="${key}"]`);
226
+ if (!el) return;
227
+ if (el === activeEditElement) return;
228
+ el.innerText = value;
229
+ }
230
+ function createEditIcon() {
231
+ const icon = document.createElement("button");
232
+ icon.className = "dcs-edit-icon";
233
+ icon.setAttribute("type", "button");
234
+ icon.setAttribute("title", "Edit text");
235
+ icon.setAttribute("aria-label", "Edit text inline");
236
+ icon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 7 4 4 20 4 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="4" x2="12" y2="20"/></svg>`;
237
+ icon.addEventListener("click", (e) => {
238
+ e.preventDefault();
239
+ e.stopPropagation();
240
+ e.stopImmediatePropagation();
241
+ if (!editIconTarget) return;
242
+ const el = editIconTarget;
243
+ const key = el.dataset.textKey;
244
+ const sectionParent = el.closest("[data-section]");
245
+ const sectionId = sectionParent?.dataset.section ?? null;
246
+ postToParent("dcs:text-key-dblclick", { key, sectionId });
247
+ startInlineEdit(el, key, sectionId);
248
+ removeEditIcon();
249
+ }, true);
250
+ icon.addEventListener("mouseleave", (e) => {
251
+ const related = e.relatedTarget;
252
+ if (related && editIconTarget && (related === editIconTarget || editIconTarget.contains(related))) return;
253
+ removeEditIcon();
254
+ });
255
+ return icon;
256
+ }
257
+ function showEditIcon(el) {
258
+ if (!editingEnabled) return;
259
+ if (!editIconElement) {
260
+ editIconElement = createEditIcon();
261
+ document.body.appendChild(editIconElement);
262
+ }
263
+ editIconTarget = el;
264
+ const rect = el.getBoundingClientRect();
265
+ editIconElement.style.top = `${rect.top + scrollY - 4}px`;
266
+ editIconElement.style.left = `${rect.left + scrollX - 4}px`;
267
+ editIconElement.style.display = "flex";
268
+ }
269
+ function removeEditIcon() {
270
+ if (editIconElement) {
271
+ editIconElement.style.display = "none";
272
+ }
273
+ editIconTarget = null;
274
+ }
275
+ function isArrayTextKey(key) {
276
+ return /\.\d+\./.test(key) || /\.\w+-\d+\./.test(key);
277
+ }
278
+ function getArrayBaseKey(key) {
279
+ const hyphenMatch = key.match(/^(.+?)-\d+\./);
280
+ if (hyphenMatch) return hyphenMatch[1];
281
+ const numMatch = key.match(/^(.+?)\.\d+\./);
282
+ return numMatch ? numMatch[1] : null;
283
+ }
284
+ function createArrayEditIcon() {
285
+ const icon = document.createElement("button");
286
+ icon.className = "dcs-array-edit-icon";
287
+ icon.setAttribute("type", "button");
288
+ icon.setAttribute("title", "Edit list items");
289
+ icon.setAttribute("aria-label", "Edit list items in panel");
290
+ icon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>`;
291
+ icon.addEventListener("click", (e) => {
292
+ e.preventDefault();
293
+ e.stopPropagation();
294
+ e.stopImmediatePropagation();
295
+ if (!arrayEditIconTarget) return;
296
+ const el = arrayEditIconTarget;
297
+ const key = el.dataset.textKey;
298
+ const arrayKey = getArrayBaseKey(key);
299
+ if (!arrayKey) return;
300
+ const sectionParent = el.closest("[data-section]");
301
+ const sectionId = sectionParent?.dataset.section ?? null;
302
+ postToParent("dcs:array-key-click", { arrayKey, sectionId });
303
+ removeArrayEditIcon();
304
+ }, true);
305
+ icon.addEventListener("mouseleave", (e) => {
306
+ const related = e.relatedTarget;
307
+ if (related && arrayEditIconTarget && (related === arrayEditIconTarget || arrayEditIconTarget.contains(related))) return;
308
+ removeArrayEditIcon();
309
+ });
310
+ return icon;
311
+ }
312
+ function showArrayEditIcon(el) {
313
+ if (!editingEnabled) return;
314
+ if (!arrayEditIconElement) {
315
+ arrayEditIconElement = createArrayEditIcon();
316
+ document.body.appendChild(arrayEditIconElement);
317
+ }
318
+ arrayEditIconTarget = el;
319
+ const rect = el.getBoundingClientRect();
320
+ arrayEditIconElement.style.top = `${rect.top + scrollY - 4}px`;
321
+ arrayEditIconElement.style.left = `${rect.left + scrollX - 4}px`;
322
+ arrayEditIconElement.style.display = "flex";
323
+ }
324
+ function removeArrayEditIcon() {
325
+ if (arrayEditIconElement) {
326
+ arrayEditIconElement.style.display = "none";
327
+ }
328
+ arrayEditIconTarget = null;
329
+ }
330
+ function injectEditorStyles() {
331
+ if (document.getElementById("dcs-editor-styles")) return;
332
+ const style = document.createElement("style");
333
+ style.id = "dcs-editor-styles";
334
+ style.textContent = `
335
+ [data-text-key].dcs-editable {
336
+ cursor: text !important;
337
+ border-radius: 4px;
338
+ position: relative;
339
+ }
340
+
341
+ [data-text-key].dcs-editable:hover {
342
+ outline: 2px dashed hsl(221.2 83.2% 53.3% / 0.4) !important;
343
+ outline-offset: 4px;
344
+ background-color: hsl(221.2 83.2% 53.3% / 0.03);
345
+ }
346
+
347
+ [data-text-key].dcs-editing {
348
+ outline: 2px solid hsl(221.2 83.2% 53.3%) !important;
349
+ outline-offset: 4px;
350
+ background-color: hsl(221.2 83.2% 53.3% / 0.06);
351
+ min-height: 1em;
352
+ }
353
+
354
+ [data-text-key].dcs-editing:focus {
355
+ outline: 2px solid hsl(221.2 83.2% 53.3%) !important;
356
+ outline-offset: 4px;
357
+ }
358
+
359
+ .dcs-section-highlight {
360
+ pointer-events: none;
361
+ }
362
+
363
+ /* Floating edit icon button */
364
+ .dcs-edit-icon {
365
+ position: absolute;
366
+ z-index: 99999;
367
+ display: none;
368
+ align-items: center;
369
+ justify-content: center;
370
+ width: 24px;
371
+ height: 24px;
372
+ padding: 0;
373
+ margin: 0;
374
+ border: 1.5px solid hsl(221.2 83.2% 53.3%);
375
+ border-radius: 4px;
376
+ background: hsl(221.2 83.2% 53.3% / 0.1);
377
+ backdrop-filter: blur(4px);
378
+ color: hsl(221.2 83.2% 53.3%);
379
+ cursor: pointer;
380
+ pointer-events: auto;
381
+ transition: background 0.15s, transform 0.1s;
382
+ box-shadow: 0 1px 3px rgba(0,0,0,0.12);
383
+ }
384
+
385
+ .dcs-edit-icon:hover {
386
+ background: hsl(221.2 83.2% 53.3% / 0.25);
387
+ transform: scale(1.1);
388
+ }
389
+
390
+ .dcs-edit-icon svg {
391
+ display: block;
392
+ }
393
+
394
+ /* Floating array edit icon button */
395
+ .dcs-array-edit-icon {
396
+ position: absolute;
397
+ z-index: 99999;
398
+ display: none;
399
+ align-items: center;
400
+ justify-content: center;
401
+ width: 24px;
402
+ height: 24px;
403
+ padding: 0;
404
+ margin: 0;
405
+ border: 1.5px solid hsl(271 91% 65%);
406
+ border-radius: 4px;
407
+ background: hsl(271 91% 65% / 0.1);
408
+ backdrop-filter: blur(4px);
409
+ color: hsl(271 91% 65%);
410
+ cursor: pointer;
411
+ pointer-events: auto;
412
+ transition: background 0.15s, transform 0.1s;
413
+ box-shadow: 0 1px 3px rgba(0,0,0,0.12);
414
+ }
415
+
416
+ .dcs-array-edit-icon:hover {
417
+ background: hsl(271 91% 65% / 0.25);
418
+ transform: scale(1.1);
419
+ }
420
+
421
+ .dcs-array-edit-icon svg {
422
+ display: block;
423
+ }
424
+ `;
425
+ document.head.appendChild(style);
426
+ }
427
+ function handleMessage(event) {
428
+ const msg = event.data;
429
+ if (!msg || typeof msg !== "object" || typeof msg.type !== "string") return;
430
+ if (!msg.type.startsWith("dcs:")) return;
431
+ const { type, data } = msg;
432
+ switch (type) {
433
+ case "dcs:init-editor":
434
+ enableEditorMode();
435
+ break;
436
+ case "dcs:highlight-section":
437
+ if (data && typeof data === "object" && "sectionId" in data) {
438
+ showSectionHighlight(data.sectionId);
439
+ }
440
+ break;
441
+ case "dcs:clear-highlight":
442
+ break;
443
+ case "dcs:select-text-key":
444
+ if (data && typeof data === "object" && "key" in data) {
445
+ focusTextKey(data.key);
446
+ }
447
+ break;
448
+ case "dcs:update-text":
449
+ if (data && typeof data === "object" && "key" in data && "value" in data) {
450
+ const d = data;
451
+ updateTextInPlace(d.key, d.value);
452
+ }
453
+ break;
454
+ case "dcs:set-mode":
455
+ if (data && typeof data === "object" && "mode" in data) {
456
+ setMode(data.mode);
457
+ }
458
+ break;
459
+ case "dcs:set-editing-enabled":
460
+ if (data && typeof data === "object" && "enabled" in data) {
461
+ editingEnabled = data.enabled;
462
+ if (editingEnabled) {
463
+ document.querySelectorAll("[data-text-key]").forEach((el) => {
464
+ el.classList.add("dcs-editable");
465
+ });
466
+ } else {
467
+ if (activeEditElement) {
468
+ finishEdit(activeEditElement);
469
+ }
470
+ removeEditIcon();
471
+ removeArrayEditIcon();
472
+ document.querySelectorAll(".dcs-editable").forEach((el) => {
473
+ el.classList.remove("dcs-editable");
474
+ });
475
+ }
476
+ }
477
+ break;
478
+ }
479
+ }
480
+ function initEditorBridge() {
481
+ if (!isInIframe()) return;
482
+ if (!bridgeInitialized) {
483
+ bridgeInitialized = true;
484
+ monitorNavigation();
485
+ document.addEventListener("contextmenu", (e) => {
486
+ e.preventDefault();
487
+ const sectionEl = e.target.closest?.("[data-section]");
488
+ postToParent("dcs:contextmenu", {
489
+ x: e.clientX,
490
+ y: e.clientY,
491
+ sectionId: sectionEl?.dataset.section ?? null,
492
+ sectionLabel: sectionEl?.dataset.sectionLabel ?? null
493
+ });
494
+ }, true);
495
+ document.addEventListener("click", () => {
496
+ postToParent("dcs:click", {});
497
+ }, true);
498
+ globalThis.self.addEventListener("message", handleMessage);
499
+ if (import.meta.hot) {
500
+ import.meta.hot.on("vite:afterUpdate", () => {
501
+ setTimeout(rediscoverAndNotify, 300);
502
+ });
503
+ }
504
+ }
505
+ const sections = discoverSections();
506
+ const textKeys = discoverTextKeys();
507
+ const contentHeight = document.body.scrollHeight;
508
+ postToParent("dcs:ready", {
509
+ sections,
510
+ textKeys,
511
+ contentHeight
512
+ });
513
+ }
514
+ if (typeof globalThis.self !== "undefined" && isInIframe()) {
515
+ if (document.readyState === "loading") {
516
+ document.addEventListener("DOMContentLoaded", () => {
517
+ setTimeout(initEditorBridge, 200);
518
+ });
519
+ } else {
520
+ setTimeout(initEditorBridge, 200);
521
+ }
522
+ }
523
+
524
+ export { initEditorBridge };
525
+ //# sourceMappingURL=editorBridge.js.map
526
+ //# sourceMappingURL=editorBridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/editor/editorBridge.ts"],"names":[],"mappings":";AAyDA,SAAS,UAAA,GAAsB;AAC7B,EAAA,IAAI;AAAE,IAAA,OAAO,UAAA,CAAW,IAAA,KAAS,UAAA,CAAW,IAAA,CAAK,MAAA;AAAA,EAAO,CAAA,CAAA,MAAQ;AAAE,IAAA,OAAO,IAAA;AAAA,EAAK;AAChF;AAEA,SAAS,YAAA,CAAa,MAA2B,IAAA,EAAe;AAC9D,EAAA,IAAI,CAAC,YAAW,EAAG;AAKnB,EAAA,UAAA,CAAW,KAAK,MAAA,CAAO,WAAA,CAAY,EAAE,IAAA,EAAM,IAAA,IAAQ,GAAG,CAAA;AACxD;AAIA,IAAI,YAAA,GAAe,KAAA;AACnB,IAAI,iBAAA,GAAoB,KAAA;AACxB,IAAI,iBAAA,GAAwC,IAAA;AAE5C,IAAI,iB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AA,MAAM,WAAW,gBAAA,EAAiB;AAClC,EAAA,MAAM,WAAW,gBAAA,EAAiB;AAClC,EAAA,MAAM,aAAA,GAAgB,SAAS,IAAA,CAAK,YAAA;AAEpC,EAAA,YAAA,CAAa,WAAA,EAAa;AAAA,IACxB,QAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GAC4B,CAAA;AAChC;AAIA,IAAI,OAAO,UAAA,CAAW,IAAA,KAAS,WAAA,IAAe,YAAW,EAAG;AAC1D,EAAA,IAAI,QAAA,CAAS,eAAe,SAAA,EAAW;AACrC,IAAA,QAAA,CAAS,gBAAA,CAAiB,oBAAoB,MAAM;AAElD,MAAA,UAAA,CAAW,kBAAkB,GAAG,CAAA;AAAA,IAClC,CAAC,CAAA;AAAA,EACH,CAAA,MAAO;AACL,IAAA,UAAA,CAAW,kBAAkB,GAAG,CAAA;AAAA,EAClC;AACF","file":"editorBridge.js","sourcesContent":["/**\r\n * Editor Bridge — injected into customer site iframes by the DCS visual editor.\r\n *\r\n * Responsibilities:\r\n * 1. Report available sections and text keys to the parent portal\r\n * 2. Enable inline contenteditable editing on data-text-key elements (double-click)\r\n * 3. Render section overlay highlights on hover/select from parent\r\n * 4. Communicate all interactions back to the parent via postMessage\r\n * 5. Monitor navigation within the iframe and notify the parent\r\n * 6. Show floating edit icon on hover for text-key elements\r\n *\r\n * NOTE: AI ✨ buttons are rendered by the portal-side SectionOverlayLayer,\r\n * NOT by this bridge. The bridge only reports section/text key data and\r\n * handles inline text editing.\r\n *\r\n * This script runs inside the iframe (customer site). The parent portal\r\n * communicates via postMessage using the `dcs:*` message protocol.\r\n */\r\n\r\n// ─── Types ───────────────────────────────────────────────────────\r\n\r\nexport interface SectionInfo {\r\n id: string\r\n label: string | null\r\n bounds: { x: number; y: number; width: number; height: number }\r\n textKeyCount: number\r\n}\r\n\r\nexport interface EditorReadyPayload {\r\n sections: SectionInfo[]\r\n textKeys: string[]\r\n contentHeight: number\r\n}\r\n\r\n// ─── Message Protocol ────────────────────────────────────────────\r\n\r\ntype InboundMessageType =\r\n | 'dcs:init-editor'\r\n | 'dcs:highlight-section'\r\n | 'dcs:clear-highlight'\r\n | 'dcs:select-text-key'\r\n | 'dcs:update-text'\r\n | 'dcs:set-mode'\r\n | 'dcs:set-editing-enabled'\r\n\r\ntype OutboundMessageType =\r\n | 'dcs:ready'\r\n | 'dcs:text-key-click'\r\n | 'dcs:text-key-changed'\r\n | 'dcs:section-click'\r\n | 'dcs:section-hover'\r\n | 'dcs:text-key-dblclick'\r\n | 'dcs:contextmenu'\r\n | 'dcs:click'\r\n | 'dcs:navigation'\r\n | 'dcs:array-key-click'\r\n\r\nfunction isInIframe(): boolean {\r\n try { return globalThis.self !== globalThis.self.parent } catch { return true }\r\n}\r\n\r\nfunction postToParent(type: OutboundMessageType, data: unknown) {\r\n if (!isInIframe()) return\r\n // Use '*' because the portal origin varies between dev and production\r\n // and this script doesn't know the parent origin at injection time.\r\n // Security: messages are validated by the portal's useIframeBridge.\r\n // Origin validated via dcs: prefix check on all messages\r\n globalThis.self.parent.postMessage({ type, data }, '*') // NOSONAR\r\n}\r\n\r\n// ─── State ───────────────────────────────────────────────────────\r\n\r\nlet editorActive = false\r\nlet bridgeInitialized = false\r\nlet activeEditElement: HTMLElement | null = null\r\n/** The current pathname tracked for navigation detection */\r\nlet lastKnownPathname: string = ''\r\n/** The floating edit icon element shown on hover over text keys */\r\nlet editIconElement: HTMLElement | null = null\r\n/** The element the edit icon is currently attached to */\r\nlet editIconTarget: HTMLElement | null = null\r\n/** The floating edit icon for array/list text keys */\r\nlet arrayEditIconElement: HTMLElement | null = null\r\n/** The element the array edit icon is currently attached to */\r\nlet arrayEditIconTarget: HTMLElement | null = null\r\n/** Whether editing features are enabled (disabled on unmanaged pages) */\r\nlet editingEnabled = true\r\n/** Original text values captured when inline editing starts, for change detection */\r\nconst originalTextValues = new Map<HTMLElement, string>()\r\n\r\n// ─── Section Discovery ───────────────────────────────────────────\r\n\r\nfunction discoverSections(): SectionInfo[] {\r\n const elements = document.querySelectorAll<HTMLElement>('[data-section]')\r\n return Array.from(elements).map((el) => {\r\n const rect = el.getBoundingClientRect()\r\n const textKeyCount = el.querySelectorAll('[data-text-key]').length\r\n return {\r\n id: el.dataset.section!,\r\n label: el.dataset.sectionLabel ?? null,\r\n bounds: {\r\n x: rect.left + scrollX,\r\n y: rect.top + scrollY,\r\n width: rect.width,\r\n height: rect.height,\r\n },\r\n textKeyCount,\r\n }\r\n })\r\n}\r\n\r\nfunction discoverTextKeys(): string[] {\r\n return Array.from(document.querySelectorAll<HTMLElement>('[data-text-key]')).map(\r\n (el) => el.dataset.textKey!,\r\n )\r\n}\r\n\r\n// ─── Section Overlay ─────────────────────────────────────────────\r\n\r\n/**\r\n * Section highlight is now handled entirely by the portal-side\r\n * SectionOverlayLayer rendered on top of the iframe. The bridge\r\n * only reports section bounds and hover events — no visual\r\n * overlays are rendered inside the iframe itself.\r\n */\r\nfunction showSectionHighlight(_sectionId: string) {\r\n // No-op: portal overlay layer handles section highlights\r\n}\r\n\r\nfunction clearSectionHighlight() {\r\n // No-op: portal overlay layer handles section highlights\r\n}\r\n\r\n// ─── Navigation Monitoring ───────────────────────────────────────\r\n\r\n/**\r\n * Monitor navigation within the iframe and notify the parent portal.\r\n * Instead of blocking all navigation, we allow SPA routing and inform\r\n * the portal when the iframe navigates to a different page. The portal\r\n * then updates its own URL and loads editing context for the new page.\r\n *\r\n * Strategy:\r\n * 1. Poll location.pathname on a short interval — this reliably detects\r\n * SPA navigation regardless of which router or framework is used,\r\n * since frameworks may cache History API references before our script loads.\r\n * 2. Block external/cross-origin link clicks (actual page reloads).\r\n * 3. Block form submissions.\r\n * 4. Monitor popstate for back/forward navigation.\r\n * 5. After navigation, re-discover sections and report them to the portal.\r\n */\r\nfunction monitorNavigation() {\r\n lastKnownPathname = globalThis.location.pathname\r\n\r\n // ── Poll for URL changes — reliable with any SPA router ──────\r\n // Frameworks like VitePress/Vue Router may cache history.pushState before\r\n // our bridge loads, so prototype overrides are unreliable. Polling\r\n // location.pathname directly is simple and always works.\r\n setInterval(() => {\r\n checkForNavigation()\r\n }, 250)\r\n\r\n // ── Catch back/forward navigation ────────────────────────────\r\n globalThis.addEventListener('popstate', () => {\r\n checkForNavigation()\r\n })\r\n\r\n // ── Block external link clicks (cross-origin / full page reloads) ──\r\n const handleLinkClick = (e: MouseEvent) => {\r\n const link = (e.target as HTMLElement).closest?.('a[href]') as HTMLAnchorElement | null\r\n if (!link) return\r\n\r\n const href = link.getAttribute('href')\r\n if (!href || href.startsWith('#') || href === 'javascript:void(0)') return\r\n\r\n // Check if this is an external link (different origin)\r\n try {\r\n const resolved = new URL(href, globalThis.location.href)\r\n if (resolved.origin !== globalThis.location.origin) {\r\n // Block external navigation — can't leave the iframe\r\n e.preventDefault()\r\n e.stopPropagation()\r\n e.stopImmediatePropagation()\r\n }\r\n // Same-origin links: let the SPA router handle them.\r\n // The History API override above will detect the navigation.\r\n } catch {\r\n // Malformed URL — block it\r\n e.preventDefault()\r\n }\r\n }\r\n\r\n // Register on window first to beat VitePress's capture-phase handler\r\n globalThis.addEventListener('click', handleLinkClick, true)\r\n document.addEventListener('click', handleLinkClick, true)\r\n\r\n // Intercept form submissions\r\n document.addEventListener('submit', (e: Event) => {\r\n e.preventDefault()\r\n e.stopPropagation()\r\n }, true)\r\n\r\n // Block actual page reloads (location.href = ..., etc.)\r\n window.addEventListener('beforeunload', (e: BeforeUnloadEvent) => {\r\n e.preventDefault()\r\n })\r\n}\r\n\r\n/**\r\n * Check if the iframe pathname has changed and notify the portal.\r\n * Also re-initializes the editor bridge for the new page.\r\n */\r\nfunction checkForNavigation() {\r\n const currentPathname = globalThis.location.pathname\r\n if (currentPathname === lastKnownPathname) return\r\n\r\n lastKnownPathname = currentPathname\r\n\r\n // Notify parent about the navigation\r\n postToParent('dcs:navigation', { pathname: currentPathname })\r\n\r\n // Clean up current edit state\r\n if (activeEditElement) {\r\n finishEdit(activeEditElement)\r\n }\r\n removeEditIcon()\r\n removeArrayEditIcon()\r\n\r\n // Wait for the SPA router to finish rendering the new page,\r\n // then re-discover sections and text keys\r\n setTimeout(() => {\r\n rediscoverAndNotify()\r\n }, 500)\r\n}\r\n\r\n// ─── Mode Management ─────────────────────────────────────────────\r\n\r\n/**\r\n * Set the current interaction mode. Both modes allow normal browsing —\r\n * inline editing works via double-click regardless of mode.\r\n * Switching to explore finishes any active inline edit.\r\n */\r\nfunction setMode(mode: 'edit' | 'explore') {\r\n if (mode === 'explore') {\r\n // When explicitly switching to explore, finish any active inline edit\r\n if (activeEditElement) {\r\n finishEdit(activeEditElement)\r\n }\r\n }\r\n}\r\n\r\n// ─── Inline Text Editing ─────────────────────────────────────────\r\n\r\n/**\r\n * Re-discover sections and text keys after an HMR update and\r\n * notify the parent portal so the overlay layer updates.\r\n */\r\nfunction rediscoverAndNotify() {\r\n activeEditElement = null\r\n\r\n const sections = discoverSections()\r\n const textKeys = discoverTextKeys()\r\n const contentHeight = document.body.scrollHeight\r\n postToParent('dcs:ready', { sections, textKeys, contentHeight } satisfies EditorReadyPayload)\r\n\r\n // Re-enable editor mode on the new elements\r\n if (editorActive) {\r\n editorActive = false // allow re-initialization\r\n enableEditorMode()\r\n }\r\n}\r\n\r\nfunction enableEditorMode() {\r\n if (editorActive) return\r\n editorActive = true\r\n\r\n // Inject editor styles\r\n injectEditorStyles()\r\n\r\n // Set up all text key elements — double-click to start editing\r\n const textElements = document.querySelectorAll<HTMLElement>('[data-text-key]')\r\n textElements.forEach((htmlEl) => {\r\n htmlEl.classList.add('dcs-editable')\r\n\r\n // Double-click to start inline editing (signals parent to switch to edit mode)\r\n htmlEl.addEventListener('dblclick', handleTextKeyDblClick)\r\n // Blur to finish editing\r\n htmlEl.addEventListener('blur', handleTextKeyBlur)\r\n // Keyboard: Enter to finish, Escape to cancel\r\n htmlEl.addEventListener('keydown', handleTextKeyKeydown)\r\n\r\n // Show/hide the floating edit icon on hover (T icon for regular text, List icon for array keys)\r\n htmlEl.addEventListener('mouseenter', () => {\r\n // Don't show icon while actively editing this or another element\r\n if (activeEditElement) return\r\n const key = htmlEl.dataset.textKey!\r\n if (isArrayTextKey(key)) {\r\n showArrayEditIcon(htmlEl)\r\n } else {\r\n showEditIcon(htmlEl)\r\n }\r\n })\r\n htmlEl.addEventListener('mouseleave', (e: MouseEvent) => {\r\n // Don't hide if moving to the edit icon or array edit icon\r\n const related = e.relatedTarget as HTMLElement | null\r\n if (related && (\r\n related.classList?.contains('dcs-edit-icon') || related.closest?.('.dcs-edit-icon') ||\r\n related.classList?.contains('dcs-array-edit-icon') || related.closest?.('.dcs-array-edit-icon')\r\n )) return\r\n removeEditIcon()\r\n removeArrayEditIcon()\r\n })\r\n })\r\n\r\n // Set up section hover reporting (portal overlay handles the visual treatment)\r\n const sections = document.querySelectorAll<HTMLElement>('[data-section]')\r\n sections.forEach((el) => {\r\n const sectionId = el.dataset.section!\r\n\r\n el.addEventListener('mouseenter', () => {\r\n postToParent('dcs:section-hover', { sectionId })\r\n })\r\n el.addEventListener('mouseleave', () => {\r\n postToParent('dcs:section-hover', { sectionId: null })\r\n })\r\n el.addEventListener('click', (e) => {\r\n // Only fire section click if not clicking on a text-key element\r\n const target = e.target as HTMLElement\r\n if (!target.closest('[data-text-key]')) {\r\n postToParent('dcs:section-click', { sectionId })\r\n }\r\n })\r\n })\r\n}\r\n\r\n/**\r\n * Handle double-click on a text key element.\r\n * Notifies the parent portal to switch to edit mode and begins inline editing.\r\n */\r\nfunction handleTextKeyDblClick(e: Event) {\r\n if (!editingEnabled) return\r\n\r\n e.preventDefault()\r\n e.stopPropagation()\r\n e.stopImmediatePropagation()\r\n\r\n const el = e.currentTarget as HTMLElement\r\n const key = el.dataset.textKey!\r\n const sectionParent = el.closest<HTMLElement>('[data-section]')\r\n const sectionId = sectionParent?.dataset.section ?? null\r\n\r\n // Always notify the parent to switch to edit mode when starting inline editing.\r\n // In explore mode this triggers the mode switch; in edit mode it's a no-op on the parent side.\r\n postToParent('dcs:text-key-dblclick', { key, sectionId })\r\n\r\n // Start inline editing\r\n startInlineEdit(el, key, sectionId)\r\n}\r\n\r\n/**\r\n * Start inline contenteditable editing on a text key element.\r\n * Called by double-click or when the parent sends dcs:select-text-key.\r\n */\r\nfunction startInlineEdit(el: HTMLElement, key: string, sectionId: string | null) {\r\n // Finish any active edit first\r\n if (activeEditElement && activeEditElement !== el) {\r\n finishEdit(activeEditElement)\r\n }\r\n\r\n // Store original text for change detection on finish\r\n originalTextValues.set(el, el.innerText.trim())\r\n\r\n // Enable contenteditable\r\n el.setAttribute('contenteditable', 'true')\r\n el.classList.add('dcs-editing')\r\n el.focus()\r\n activeEditElement = el\r\n\r\n // Select all text for easy replacement\r\n const selection = getSelection()\r\n const range = document.createRange()\r\n range.selectNodeContents(el)\r\n selection?.removeAllRanges()\r\n selection?.addRange(range)\r\n\r\n postToParent('dcs:text-key-click', { key, sectionId })\r\n}\r\n\r\nfunction handleTextKeyBlur(e: Event) {\r\n const el = e.currentTarget as HTMLElement\r\n finishEdit(el)\r\n}\r\n\r\nfunction handleTextKeyKeydown(e: KeyboardEvent) {\r\n if (e.key === 'Enter' && !e.shiftKey) {\r\n e.preventDefault()\r\n ;(e.currentTarget as HTMLElement).blur()\r\n }\r\n if (e.key === 'Escape') {\r\n e.preventDefault()\r\n ;(e.currentTarget as HTMLElement).blur()\r\n }\r\n}\r\n\r\nfunction finishEdit(el: HTMLElement) {\r\n if (!el.hasAttribute('contenteditable')) return\r\n\r\n el.removeAttribute('contenteditable')\r\n el.classList.remove('dcs-editing')\r\n\r\n const key = el.dataset.textKey!\r\n const sectionParent = el.closest<HTMLElement>('[data-section]')\r\n const sectionId = sectionParent?.dataset.section ?? null\r\n const newValue = el.innerText.trim()\r\n const originalValue = originalTextValues.get(el) ?? ''\r\n\r\n if (activeEditElement === el) {\r\n activeEditElement = null\r\n }\r\n\r\n // Only report to the portal when text was actually modified\r\n if (newValue !== originalValue) {\r\n postToParent('dcs:text-key-changed', { key, value: newValue, sectionId })\r\n }\r\n\r\n originalTextValues.delete(el)\r\n}\r\n\r\nfunction focusTextKey(key: string) {\r\n const el = document.querySelector<HTMLElement>(`[data-text-key=\"${key}\"]`)\r\n if (!el) return\r\n el.scrollIntoView({ behavior: 'smooth', block: 'center' })\r\n\r\n const sectionParent = el.closest<HTMLElement>('[data-section]')\r\n const sectionId = sectionParent?.dataset.section ?? null\r\n\r\n // Start inline editing directly\r\n startInlineEdit(el, key, sectionId)\r\n}\r\n\r\nfunction updateTextInPlace(key: string, value: string) {\r\n const el = document.querySelector<HTMLElement>(`[data-text-key=\"${key}\"]`)\r\n if (!el) return\r\n // Don't update if we're currently editing this element\r\n if (el === activeEditElement) return\r\n el.innerText = value\r\n}\r\n\r\n// ─── Edit Icon (Floating Text Cursor Button) ────────────────────\r\n\r\n/**\r\n * Create the floating edit icon element. This small button appears\r\n * in the top-left corner of a hovered [data-text-key] element,\r\n * providing a click target to start inline editing without triggering\r\n * navigation (important for text inside buttons/links).\r\n */\r\nfunction createEditIcon(): HTMLElement {\r\n const icon = document.createElement('button')\r\n icon.className = 'dcs-edit-icon'\r\n icon.setAttribute('type', 'button')\r\n icon.setAttribute('title', 'Edit text')\r\n icon.setAttribute('aria-label', 'Edit text inline')\r\n // SVG: Type icon (text cursor) — matches lucide \"Type\" icon\r\n icon.innerHTML = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><polyline points=\"4 7 4 4 20 4 20 7\"/><line x1=\"9\" y1=\"20\" x2=\"15\" y2=\"20\"/><line x1=\"12\" y1=\"4\" x2=\"12\" y2=\"20\"/></svg>`\r\n\r\n icon.addEventListener('click', (e) => {\r\n e.preventDefault()\r\n e.stopPropagation()\r\n e.stopImmediatePropagation()\r\n\r\n if (!editIconTarget) return\r\n const el = editIconTarget\r\n const key = el.dataset.textKey!\r\n const sectionParent = el.closest<HTMLElement>('[data-section]')\r\n const sectionId = sectionParent?.dataset.section ?? null\r\n\r\n // Signal parent to switch to edit mode\r\n postToParent('dcs:text-key-dblclick', { key, sectionId })\r\n // Start inline editing\r\n startInlineEdit(el, key, sectionId)\r\n // Hide the icon while editing\r\n removeEditIcon()\r\n }, true)\r\n\r\n // Hide icon when mouse leaves it (and isn't going to the target element)\r\n icon.addEventListener('mouseleave', (e: MouseEvent) => {\r\n const related = e.relatedTarget as HTMLElement | null\r\n if (related && editIconTarget && (related === editIconTarget || editIconTarget.contains(related))) return\r\n removeEditIcon()\r\n })\r\n\r\n return icon\r\n}\r\n\r\n/**\r\n * Show the edit icon positioned at the top-left corner of the given element.\r\n */\r\nfunction showEditIcon(el: HTMLElement) {\r\n if (!editingEnabled) return\r\n\r\n if (!editIconElement) {\r\n editIconElement = createEditIcon()\r\n document.body.appendChild(editIconElement)\r\n }\r\n\r\n editIconTarget = el\r\n\r\n // Position relative to the element's bounding box\r\n const rect = el.getBoundingClientRect()\r\n editIconElement.style.top = `${rect.top + scrollY - 4}px`\r\n editIconElement.style.left = `${rect.left + scrollX - 4}px`\r\n editIconElement.style.display = 'flex'\r\n}\r\n\r\n/**\r\n * Hide and detach the edit icon.\r\n */\r\nfunction removeEditIcon() {\r\n if (editIconElement) {\r\n editIconElement.style.display = 'none'\r\n }\r\n editIconTarget = null\r\n}\r\n\r\n// ─── Array Key Detection ─────────────────────────────────────────\r\n\r\n/**\r\n * Check if a text key is part of an array pattern (e.g., \"conditions.0.title\").\r\n * Array text keys contain an indexed segment — either:\r\n * - Pure numeric: `baseKey.N.field` (e.g., `conditions.0.title`)\r\n * - Hyphenated index: `baseKey.prefix-N.field` (e.g., `steps.step-0.title`)\r\n */\r\nfunction isArrayTextKey(key: string): boolean {\r\n // Match pure numeric segment (.0.) or hyphenated index (.prefix-0.)\r\n return /\\.\\d+\\./.test(key) || /\\.\\w+-\\d+\\./.test(key)\r\n}\r\n\r\n/**\r\n * Extract the base array key from an array text key.\r\n * - `conditions.0.title` → `conditions`\r\n * - `steps.step-0.title` → `steps.step`\r\n */\r\nfunction getArrayBaseKey(key: string): string | null {\r\n // Try hyphenated pattern first (more specific)\r\n const hyphenMatch = key.match(/^(.+?)-\\d+\\./)\r\n if (hyphenMatch) return hyphenMatch[1]\r\n // Fall back to pure numeric pattern\r\n const numMatch = key.match(/^(.+?)\\.\\d+\\./)\r\n return numMatch ? numMatch[1] : null\r\n}\r\n\r\n// ─── Array Edit Icon (Floating List Button) ──────────────────────\r\n\r\n/**\r\n * Create the floating array edit icon element. This small button appears\r\n * in the top-left corner of a hovered [data-text-key] element whose key\r\n * matches an array pattern. Clicking it sends dcs:array-key-click to the\r\n * portal to open the array editor sheet.\r\n */\r\nfunction createArrayEditIcon(): HTMLElement {\r\n const icon = document.createElement('button')\r\n icon.className = 'dcs-array-edit-icon'\r\n icon.setAttribute('type', 'button')\r\n icon.setAttribute('title', 'Edit list items')\r\n icon.setAttribute('aria-label', 'Edit list items in panel')\r\n // SVG: List icon — matches lucide \"List\" icon\r\n icon.innerHTML = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><line x1=\"8\" y1=\"6\" x2=\"21\" y2=\"6\"/><line x1=\"8\" y1=\"12\" x2=\"21\" y2=\"12\"/><line x1=\"8\" y1=\"18\" x2=\"21\" y2=\"18\"/><line x1=\"3\" y1=\"6\" x2=\"3.01\" y2=\"6\"/><line x1=\"3\" y1=\"12\" x2=\"3.01\" y2=\"12\"/><line x1=\"3\" y1=\"18\" x2=\"3.01\" y2=\"18\"/></svg>`\r\n\r\n icon.addEventListener('click', (e) => {\r\n e.preventDefault()\r\n e.stopPropagation()\r\n e.stopImmediatePropagation()\r\n\r\n if (!arrayEditIconTarget) return\r\n const el = arrayEditIconTarget\r\n const key = el.dataset.textKey!\r\n const arrayKey = getArrayBaseKey(key)\r\n if (!arrayKey) return\r\n\r\n const sectionParent = el.closest<HTMLElement>('[data-section]')\r\n const sectionId = sectionParent?.dataset.section ?? null\r\n\r\n // Signal parent to open array editor sheet\r\n postToParent('dcs:array-key-click', { arrayKey, sectionId })\r\n // Hide the icon\r\n removeArrayEditIcon()\r\n }, true)\r\n\r\n // Hide icon when mouse leaves it (and isn't going to the target element)\r\n icon.addEventListener('mouseleave', (e: MouseEvent) => {\r\n const related = e.relatedTarget as HTMLElement | null\r\n if (related && arrayEditIconTarget && (related === arrayEditIconTarget || arrayEditIconTarget.contains(related))) return\r\n removeArrayEditIcon()\r\n })\r\n\r\n return icon\r\n}\r\n\r\n/**\r\n * Show the array edit icon positioned at the top-left corner of the given element.\r\n */\r\nfunction showArrayEditIcon(el: HTMLElement) {\r\n if (!editingEnabled) return\r\n\r\n if (!arrayEditIconElement) {\r\n arrayEditIconElement = createArrayEditIcon()\r\n document.body.appendChild(arrayEditIconElement)\r\n }\r\n\r\n arrayEditIconTarget = el\r\n\r\n // Position relative to the element's bounding box\r\n const rect = el.getBoundingClientRect()\r\n arrayEditIconElement.style.top = `${rect.top + scrollY - 4}px`\r\n arrayEditIconElement.style.left = `${rect.left + scrollX - 4}px`\r\n arrayEditIconElement.style.display = 'flex'\r\n}\r\n\r\n/**\r\n * Hide and detach the array edit icon.\r\n */\r\nfunction removeArrayEditIcon() {\r\n if (arrayEditIconElement) {\r\n arrayEditIconElement.style.display = 'none'\r\n }\r\n arrayEditIconTarget = null\r\n}\r\n\r\nfunction injectEditorStyles() {\r\n if (document.getElementById('dcs-editor-styles')) return\r\n\r\n const style = document.createElement('style')\r\n style.id = 'dcs-editor-styles'\r\n style.textContent = `\r\n [data-text-key].dcs-editable {\r\n cursor: text !important;\r\n border-radius: 4px;\r\n position: relative;\r\n }\r\n\r\n [data-text-key].dcs-editable:hover {\r\n outline: 2px dashed hsl(221.2 83.2% 53.3% / 0.4) !important;\r\n outline-offset: 4px;\r\n background-color: hsl(221.2 83.2% 53.3% / 0.03);\r\n }\r\n\r\n [data-text-key].dcs-editing {\r\n outline: 2px solid hsl(221.2 83.2% 53.3%) !important;\r\n outline-offset: 4px;\r\n background-color: hsl(221.2 83.2% 53.3% / 0.06);\r\n min-height: 1em;\r\n }\r\n\r\n [data-text-key].dcs-editing:focus {\r\n outline: 2px solid hsl(221.2 83.2% 53.3%) !important;\r\n outline-offset: 4px;\r\n }\r\n\r\n .dcs-section-highlight {\r\n pointer-events: none;\r\n }\r\n\r\n /* Floating edit icon button */\r\n .dcs-edit-icon {\r\n position: absolute;\r\n z-index: 99999;\r\n display: none;\r\n align-items: center;\r\n justify-content: center;\r\n width: 24px;\r\n height: 24px;\r\n padding: 0;\r\n margin: 0;\r\n border: 1.5px solid hsl(221.2 83.2% 53.3%);\r\n border-radius: 4px;\r\n background: hsl(221.2 83.2% 53.3% / 0.1);\r\n backdrop-filter: blur(4px);\r\n color: hsl(221.2 83.2% 53.3%);\r\n cursor: pointer;\r\n pointer-events: auto;\r\n transition: background 0.15s, transform 0.1s;\r\n box-shadow: 0 1px 3px rgba(0,0,0,0.12);\r\n }\r\n\r\n .dcs-edit-icon:hover {\r\n background: hsl(221.2 83.2% 53.3% / 0.25);\r\n transform: scale(1.1);\r\n }\r\n\r\n .dcs-edit-icon svg {\r\n display: block;\r\n }\r\n\r\n /* Floating array edit icon button */\r\n .dcs-array-edit-icon {\r\n position: absolute;\r\n z-index: 99999;\r\n display: none;\r\n align-items: center;\r\n justify-content: center;\r\n width: 24px;\r\n height: 24px;\r\n padding: 0;\r\n margin: 0;\r\n border: 1.5px solid hsl(271 91% 65%);\r\n border-radius: 4px;\r\n background: hsl(271 91% 65% / 0.1);\r\n backdrop-filter: blur(4px);\r\n color: hsl(271 91% 65%);\r\n cursor: pointer;\r\n pointer-events: auto;\r\n transition: background 0.15s, transform 0.1s;\r\n box-shadow: 0 1px 3px rgba(0,0,0,0.12);\r\n }\r\n\r\n .dcs-array-edit-icon:hover {\r\n background: hsl(271 91% 65% / 0.25);\r\n transform: scale(1.1);\r\n }\r\n\r\n .dcs-array-edit-icon svg {\r\n display: block;\r\n }\r\n `\r\n document.head.appendChild(style)\r\n}\r\n\r\n// ─── Inbound Message Handler ─────────────────────────────────────\r\n\r\nfunction handleMessage(event: MessageEvent) {\r\n // Validate message structure (origin is not checked because\r\n // the parent portal origin varies between dev and production)\r\n const msg = event.data\r\n if (!msg || typeof msg !== 'object' || typeof msg.type !== 'string') return\r\n if (!msg.type.startsWith('dcs:')) return\r\n\r\n const { type, data } = msg as { type: InboundMessageType; data: unknown }\r\n\r\n switch (type) {\r\n case 'dcs:init-editor':\r\n enableEditorMode()\r\n break\r\n\r\n case 'dcs:highlight-section':\r\n if (data && typeof data === 'object' && 'sectionId' in data) {\r\n showSectionHighlight((data as { sectionId: string }).sectionId)\r\n }\r\n break\r\n\r\n case 'dcs:clear-highlight':\r\n clearSectionHighlight()\r\n break\r\n\r\n case 'dcs:select-text-key':\r\n if (data && typeof data === 'object' && 'key' in data) {\r\n focusTextKey((data as { key: string }).key)\r\n }\r\n break\r\n\r\n case 'dcs:update-text':\r\n if (data && typeof data === 'object' && 'key' in data && 'value' in data) {\r\n const d = data as { key: string; value: string }\r\n updateTextInPlace(d.key, d.value)\r\n }\r\n break\r\n\r\n case 'dcs:set-mode':\r\n if (data && typeof data === 'object' && 'mode' in data) {\r\n setMode((data as { mode: 'edit' | 'explore' }).mode)\r\n }\r\n break\r\n\r\n case 'dcs:set-editing-enabled':\r\n if (data && typeof data === 'object' && 'enabled' in data) {\r\n editingEnabled = (data as { enabled: boolean }).enabled\r\n if (editingEnabled) {\r\n // Re-add dcs-editable class to text key elements\r\n document.querySelectorAll<HTMLElement>('[data-text-key]').forEach(el => {\r\n el.classList.add('dcs-editable')\r\n })\r\n } else {\r\n // Clean up: finish any active edit, remove edit icon, remove hover styles\r\n if (activeEditElement) {\r\n finishEdit(activeEditElement)\r\n }\r\n removeEditIcon()\r\n removeArrayEditIcon()\r\n // Remove dcs-editable class to disable hover outlines\r\n document.querySelectorAll<HTMLElement>('.dcs-editable').forEach(el => {\r\n el.classList.remove('dcs-editable')\r\n })\r\n }\r\n }\r\n break\r\n }\r\n}\r\n\r\n// ─── Bootstrap ───────────────────────────────────────────────────\r\n\r\nexport function initEditorBridge() {\r\n if (!isInIframe()) return // Not in iframe\r\n\r\n // Prevent duplicate listener registration on HMR re-execution\r\n if (!bridgeInitialized) {\r\n bridgeInitialized = true\r\n\r\n // Monitor navigation within the iframe — notify the portal of page changes\r\n monitorNavigation()\r\n\r\n // Forward right-click events to the portal so the context menu\r\n // works when right-clicking inside the iframe (cross-origin boundary\r\n // prevents the parent from receiving native contextmenu events).\r\n document.addEventListener('contextmenu', (e: MouseEvent) => {\r\n e.preventDefault()\r\n const sectionEl = (e.target as HTMLElement).closest?.('[data-section]') as HTMLElement | null\r\n postToParent('dcs:contextmenu', {\r\n x: e.clientX,\r\n y: e.clientY,\r\n sectionId: sectionEl?.dataset.section ?? null,\r\n sectionLabel: sectionEl?.dataset.sectionLabel ?? null,\r\n })\r\n }, true)\r\n\r\n // Forward click events to the portal so it can dismiss context menus\r\n // when the user clicks inside the iframe.\r\n document.addEventListener('click', () => {\r\n postToParent('dcs:click', {})\r\n }, true)\r\n\r\n // Listen for portal commands. Origin is not validated because\r\n // the portal origin varies between environments and all inbound\r\n // messages are type-checked before processing.\r\n // Origin cannot be pre-validated because the portal URL varies by environment.\r\n // All inbound messages are type-checked via the dcs: prefix guard.\r\n globalThis.self.addEventListener('message', handleMessage) // NOSONAR\r\n\r\n // Watch for VitePress / Vite HMR page updates. When the framework\r\n // replaces DOM content, our event listeners and AI buttons are lost.\r\n // Re-discover sections after each update so the portal overlay stays in sync.\r\n if (import.meta.hot) {\r\n import.meta.hot.on('vite:afterUpdate', () => {\r\n // Small delay for the framework to finish DOM updates\r\n setTimeout(rediscoverAndNotify, 300)\r\n })\r\n }\r\n }\r\n\r\n // Report available sections, text keys, and content height\r\n const sections = discoverSections()\r\n const textKeys = discoverTextKeys()\r\n const contentHeight = document.body.scrollHeight\r\n\r\n postToParent('dcs:ready', {\r\n sections,\r\n textKeys,\r\n contentHeight,\r\n } satisfies EditorReadyPayload)\r\n}\r\n\r\n// Auto-initialize when the script is loaded (e.g., injected by Vite plugin)\r\n// Delay slightly to ensure the page is fully rendered\r\nif (typeof globalThis.self !== 'undefined' && isInIframe()) {\r\n if (document.readyState === 'loading') {\r\n document.addEventListener('DOMContentLoaded', () => {\r\n // Small delay for Vue/framework hydration\r\n setTimeout(initEditorBridge, 200)\r\n })\r\n } else {\r\n setTimeout(initEditorBridge, 200)\r\n }\r\n}\r\n"]}