@intlayer/editor 9.7.0 → 9.7.2

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.
Files changed (80) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -2
  2. package/dist/cjs/compareUrls.cjs +1 -2
  3. package/dist/cjs/components/ContentSelector.cjs +44 -8
  4. package/dist/cjs/components/ContentSelector.cjs.map +1 -1
  5. package/dist/cjs/components/ContentSelectorWrapper.cjs +32 -5
  6. package/dist/cjs/components/ContentSelectorWrapper.cjs.map +1 -1
  7. package/dist/cjs/components/index.cjs +2 -2
  8. package/dist/cjs/components/isInteractiveClickTarget.cjs +1 -2
  9. package/dist/cjs/core/CrossFrameMessenger.cjs +2 -3
  10. package/dist/cjs/core/CrossFrameStateManager.cjs +1 -2
  11. package/dist/cjs/core/EditorStateManager.cjs +63 -18
  12. package/dist/cjs/core/EditorStateManager.cjs.map +1 -1
  13. package/dist/cjs/core/IframeClickInterceptor.cjs +3 -4
  14. package/dist/cjs/core/UrlStateManager.cjs +2 -3
  15. package/dist/cjs/core/getLocalEditorParentOrigin.cjs +1 -2
  16. package/dist/cjs/core/globalManager.cjs +1 -2
  17. package/dist/cjs/core/index.cjs +10 -8
  18. package/dist/cjs/core/initEditorClient.cjs +5 -6
  19. package/dist/cjs/core/selectionClick.cjs +1 -2
  20. package/dist/cjs/core/sharedWindowState.cjs +1 -2
  21. package/dist/cjs/index.cjs +13 -11
  22. package/dist/cjs/isEnabled.cjs +1 -2
  23. package/dist/cjs/messageKey.cjs +1 -2
  24. package/dist/esm/compareUrls.mjs +1 -2
  25. package/dist/esm/components/ContentSelector.mjs +41 -5
  26. package/dist/esm/components/ContentSelector.mjs.map +1 -1
  27. package/dist/esm/components/ContentSelectorWrapper.mjs +30 -3
  28. package/dist/esm/components/ContentSelectorWrapper.mjs.map +1 -1
  29. package/dist/esm/components/index.mjs +1 -1
  30. package/dist/esm/components/isInteractiveClickTarget.mjs +1 -2
  31. package/dist/esm/core/CrossFrameMessenger.mjs +1 -2
  32. package/dist/esm/core/CrossFrameStateManager.mjs +1 -2
  33. package/dist/esm/core/EditorStateManager.mjs +55 -12
  34. package/dist/esm/core/EditorStateManager.mjs.map +1 -1
  35. package/dist/esm/core/IframeClickInterceptor.mjs +1 -2
  36. package/dist/esm/core/UrlStateManager.mjs +1 -2
  37. package/dist/esm/core/getLocalEditorParentOrigin.mjs +1 -2
  38. package/dist/esm/core/globalManager.mjs +1 -2
  39. package/dist/esm/core/index.mjs +4 -4
  40. package/dist/esm/core/initEditorClient.mjs +2 -3
  41. package/dist/esm/core/selectionClick.mjs +1 -2
  42. package/dist/esm/core/sharedWindowState.mjs +1 -2
  43. package/dist/esm/index.mjs +2 -2
  44. package/dist/esm/isEnabled.mjs +1 -2
  45. package/dist/esm/messageKey.mjs +1 -2
  46. package/dist/types/compareUrls.d.ts +0 -2
  47. package/dist/types/compareUrls.d.ts.map +1 -1
  48. package/dist/types/components/ContentSelector.d.ts +1 -2
  49. package/dist/types/components/ContentSelector.d.ts.map +1 -1
  50. package/dist/types/components/ContentSelectorWrapper.d.ts +5 -2
  51. package/dist/types/components/ContentSelectorWrapper.d.ts.map +1 -1
  52. package/dist/types/components/isInteractiveClickTarget.d.ts +0 -2
  53. package/dist/types/components/isInteractiveClickTarget.d.ts.map +1 -1
  54. package/dist/types/core/CrossFrameMessenger.d.ts +1 -2
  55. package/dist/types/core/CrossFrameMessenger.d.ts.map +1 -1
  56. package/dist/types/core/CrossFrameStateManager.d.ts +0 -2
  57. package/dist/types/core/CrossFrameStateManager.d.ts.map +1 -1
  58. package/dist/types/core/EditorStateManager.d.ts +24 -3
  59. package/dist/types/core/EditorStateManager.d.ts.map +1 -1
  60. package/dist/types/core/IframeClickInterceptor.d.ts +0 -2
  61. package/dist/types/core/IframeClickInterceptor.d.ts.map +1 -1
  62. package/dist/types/core/UrlStateManager.d.ts +0 -2
  63. package/dist/types/core/UrlStateManager.d.ts.map +1 -1
  64. package/dist/types/core/getLocalEditorParentOrigin.d.ts +0 -2
  65. package/dist/types/core/getLocalEditorParentOrigin.d.ts.map +1 -1
  66. package/dist/types/core/globalManager.d.ts +0 -2
  67. package/dist/types/core/globalManager.d.ts.map +1 -1
  68. package/dist/types/core/index.d.ts +4 -4
  69. package/dist/types/core/initEditorClient.d.ts +0 -2
  70. package/dist/types/core/initEditorClient.d.ts.map +1 -1
  71. package/dist/types/core/selectionClick.d.ts +0 -2
  72. package/dist/types/core/selectionClick.d.ts.map +1 -1
  73. package/dist/types/core/sharedWindowState.d.ts +1 -2
  74. package/dist/types/core/sharedWindowState.d.ts.map +1 -1
  75. package/dist/types/index.d.ts +6 -5
  76. package/dist/types/isEnabled.d.ts +0 -2
  77. package/dist/types/isEnabled.d.ts.map +1 -1
  78. package/dist/types/messageKey.d.ts +0 -2
  79. package/dist/types/messageKey.d.ts.map +1 -1
  80. package/package.json +32 -32
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -24,5 +24,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
 
27
- //#endregion
28
27
  exports.__toESM = __toESM;
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- //#region src/compareUrls.ts
2
+ // src/compareUrls.ts
3
3
  /**
4
4
  * Compare two URLs for equality.
5
5
  * This function is used to determine if a message originates from the same origin.
@@ -34,6 +34,5 @@ const compareUrls = (url1, url2) => {
34
34
  }
35
35
  };
36
36
 
37
- //#endregion
38
37
  exports.compareUrls = compareUrls;
39
38
  //# sourceMappingURL=compareUrls.cjs.map
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_core_selectionClick = require('../core/selectionClick.cjs');
3
- const require_components_ContentSelectorWrapper = require('./ContentSelectorWrapper.cjs');
4
- const require_components_isInteractiveClickTarget = require('./isInteractiveClickTarget.cjs');
2
+ const require_core_selectionClick = require("../core/selectionClick.cjs");
3
+ const require_components_ContentSelectorWrapper = require("./ContentSelectorWrapper.cjs");
4
+ const require_components_isInteractiveClickTarget = require("./isInteractiveClickTarget.cjs");
5
5
 
6
- //#region src/components/ContentSelector.ts
6
+ // src/components/ContentSelector.ts
7
7
  const DEFAULT_PRESS_DURATION = 250;
8
8
  const STYLES = `
9
9
  :host {
@@ -25,7 +25,35 @@ const STYLES = `
25
25
  .wrapper[data-active] {
26
26
  outline-color: inherit;
27
27
  }
28
+
29
+ /*
30
+ * Text content wraps over several lines: an outline would frame the whole
31
+ * block, so each line fragment gets its own ring instead. The padding keeps
32
+ * the ring 4px away from the text, the negative margin cancels its layout.
33
+ */
34
+ .wrapper[data-text] {
35
+ display: inline;
36
+ outline: none;
37
+ padding: 4px;
38
+ margin: -4px;
39
+ box-shadow: 0 0 0 2px transparent;
40
+ -webkit-box-decoration-break: clone;
41
+ box-decoration-break: clone;
42
+ }
43
+
44
+ .wrapper[data-text][data-active] {
45
+ box-shadow: 0 0 0 2px currentColor;
46
+ }
28
47
  `;
48
+ /**
49
+ * Whether the slotted content is only text, so it can be rendered inline and
50
+ * highlighted line by line. Elements (markdown blocks, framework nodes) may
51
+ * not lay out inline, and fall back to the outline.
52
+ */
53
+ const isTextOnlyContent = (slot) => {
54
+ const assignedNodes = slot.assignedNodes({ flatten: true });
55
+ return assignedNodes.length > 0 && assignedNodes.every((node) => node.nodeType === Node.TEXT_NODE);
56
+ };
29
57
  const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
30
58
  /**
31
59
  * <intlayer-content-selector>
@@ -81,9 +109,11 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
81
109
  wrapper.className = "wrapper";
82
110
  wrapper.setAttribute("role", "button");
83
111
  wrapper.setAttribute("tabindex", "0");
84
- wrapper.appendChild(document.createElement("slot"));
112
+ const slot = document.createElement("slot");
113
+ wrapper.appendChild(slot);
85
114
  shadow.appendChild(wrapper);
86
115
  this._wrapper = wrapper;
116
+ slot.addEventListener("slotchange", () => wrapper.toggleAttribute("data-text", isTextOnlyContent(slot)));
87
117
  wrapper.addEventListener("mousedown", () => this._handleMouseDown());
88
118
  wrapper.addEventListener("mouseup", () => this._handleMouseUpOrLeave());
89
119
  wrapper.addEventListener("mouseleave", () => this._handleMouseUpOrLeave());
@@ -102,17 +132,23 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
102
132
  }
103
133
  connectedCallback() {
104
134
  this._clickOutsideHandler = (e) => {
135
+ if (!this._isSelecting && !this._isSelectingState) return;
105
136
  if (!e.composedPath().includes(this)) {
137
+ this._clearPressTimer();
106
138
  this._isSelectingState = false;
107
- this._dispatch("intlayer:click-outside");
139
+ this._isSelecting = false;
140
+ this.removeAttribute("is-selecting");
141
+ this._dispatch("intlayer:click-outside", { originalEvent: e });
108
142
  this._updateActiveState();
109
143
  }
110
144
  };
111
145
  document.addEventListener("mousedown", this._clickOutsideHandler);
146
+ document.addEventListener("touchstart", this._clickOutsideHandler);
112
147
  }
113
148
  disconnectedCallback() {
114
149
  if (this._clickOutsideHandler) {
115
150
  document.removeEventListener("mousedown", this._clickOutsideHandler);
151
+ document.removeEventListener("touchstart", this._clickOutsideHandler);
116
152
  this._clickOutsideHandler = null;
117
153
  }
118
154
  this._clearPressTimer();
@@ -127,8 +163,9 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
127
163
  this._pressTimer = null;
128
164
  }
129
165
  }
130
- _dispatch(eventName) {
166
+ _dispatch(eventName, detail) {
131
167
  this.dispatchEvent(new CustomEvent(eventName, {
168
+ detail,
132
169
  bubbles: true,
133
170
  composed: true
134
171
  }));
@@ -185,7 +222,6 @@ const defineIntlayerElements = () => {
185
222
  require_components_ContentSelectorWrapper.defineIntlayerContentSelectorWrapper();
186
223
  };
187
224
 
188
- //#endregion
189
225
  exports.IntlayerContentSelectorElement = IntlayerContentSelectorElement;
190
226
  exports.defineIntlayerElements = defineIntlayerElements;
191
227
  //# sourceMappingURL=ContentSelector.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentSelector.cjs","names":["isSelectionClick","isInteractiveClickTarget"],"sources":["../../../src/components/ContentSelector.ts"],"sourcesContent":["import { isSelectionClick, markSelectionClick } from '../core/selectionClick';\nimport { defineIntlayerContentSelectorWrapper } from './ContentSelectorWrapper';\nimport { isInteractiveClickTarget } from './isInteractiveClickTarget';\n\nconst DEFAULT_PRESS_DURATION = 250;\n\nconst STYLES = `\n :host {\n display: contents;\n }\n\n .wrapper {\n display: inline-block;\n cursor: pointer;\n user-select: none;\n border-radius: 0.375rem;\n outline-width: 2px;\n outline-offset: 4px;\n outline-style: solid;\n outline-color: transparent;\n transition: all 100ms 50ms ease-in-out;\n }\n\n .wrapper[data-active] {\n outline-color: inherit;\n }\n`;\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector>\n *\n * A framework-agnostic web component that wraps content with Intlayer editor\n * selection UI (hover outline, click to select, click-outside to deselect).\n *\n * Content is selected by:\n * - a click, unless it lands on something the app handles (link, button,\n * form control, clickable ancestor), which keeps its behavior\n * - a long press, on any content\n * - a ⌘ / Ctrl + click, on any content, cancelling the click's own action\n *\n * @fires intlayer:press - Fired when the content is selected. Bubbles.\n * @fires intlayer:hover - Fired on mouseenter. Bubbles.\n * @fires intlayer:unhover - Fired on mouseleave / mouseup. Bubbles.\n * @fires intlayer:click-outside - Fired when a click occurs outside the element. Bubbles.\n *\n * @prop {boolean} isSelecting - Whether this element is currently selected (external state)\n * @prop {number} pressDuration - Long-press threshold in ms. Default: 250\n */\nexport class IntlayerContentSelectorElement extends _HTMLElement {\n private _isSelecting = false;\n private _pressDuration = DEFAULT_PRESS_DURATION;\n private _isHovered = false;\n private _isSelectingState = false;\n private _wrapper: HTMLSpanElement;\n private _pressTimer: ReturnType<typeof setTimeout> | null = null;\n private _clickOutsideHandler: ((e: MouseEvent) => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['is-selecting', 'press-duration'];\n }\n\n get isSelecting(): boolean {\n return this._isSelecting;\n }\n set isSelecting(v: boolean) {\n this._isSelecting = v;\n this._updateActiveState();\n }\n\n get pressDuration(): number {\n return this._pressDuration;\n }\n set pressDuration(v: number) {\n this._pressDuration = v;\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n\n const style = document.createElement('style');\n style.textContent = STYLES;\n shadow.appendChild(style);\n\n const wrapper = document.createElement('span');\n wrapper.className = 'wrapper';\n wrapper.setAttribute('role', 'button');\n wrapper.setAttribute('tabindex', '0');\n wrapper.appendChild(document.createElement('slot'));\n shadow.appendChild(wrapper);\n this._wrapper = wrapper;\n\n wrapper.addEventListener('mousedown', () => this._handleMouseDown());\n wrapper.addEventListener('mouseup', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('mouseleave', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('mouseenter', () => this._handleMouseEnter());\n wrapper.addEventListener('click', (e) => this._handleClick(e));\n wrapper.addEventListener('touchstart', () => this._handleMouseDown());\n wrapper.addEventListener('touchend', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('touchcancel', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('blur', () => this._handleBlur());\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'is-selecting') {\n this._isSelecting = newVal !== null;\n this._updateActiveState();\n } else if (name === 'press-duration') {\n this._pressDuration =\n newVal !== null ? parseInt(newVal, 10) : DEFAULT_PRESS_DURATION;\n }\n }\n\n connectedCallback(): void {\n this._clickOutsideHandler = (e: MouseEvent) => {\n // composedPath() pierces shadow boundaries\n if (!e.composedPath().includes(this)) {\n this._isSelectingState = false;\n this._dispatch('intlayer:click-outside');\n this._updateActiveState();\n }\n };\n document.addEventListener('mousedown', this._clickOutsideHandler);\n }\n\n disconnectedCallback(): void {\n if (this._clickOutsideHandler) {\n document.removeEventListener('mousedown', this._clickOutsideHandler);\n this._clickOutsideHandler = null;\n }\n this._clearPressTimer();\n }\n\n private _updateActiveState(): void {\n const isActive =\n this._isSelecting || this._isSelectingState || this._isHovered;\n if (isActive) {\n this._wrapper.setAttribute('data-active', '');\n } else {\n this._wrapper.removeAttribute('data-active');\n }\n }\n\n private _clearPressTimer(): void {\n if (this._pressTimer !== null) {\n clearTimeout(this._pressTimer);\n this._pressTimer = null;\n }\n }\n\n private _dispatch(eventName: string): void {\n this.dispatchEvent(\n new CustomEvent(eventName, { bubbles: true, composed: true })\n );\n }\n\n private _select(): void {\n this._clearPressTimer();\n this._isSelectingState = true;\n this._updateActiveState();\n this._dispatch('intlayer:press');\n }\n\n private _handleMouseDown(): void {\n this._clearPressTimer();\n this._pressTimer = setTimeout(() => this._select(), this._pressDuration);\n }\n\n private _handleMouseEnter(): void {\n this._isHovered = true;\n this._updateActiveState();\n this._dispatch('intlayer:hover');\n }\n\n private _handleMouseUpOrLeave(): void {\n if (this._isHovered) {\n this._isHovered = false;\n this._dispatch('intlayer:unhover');\n }\n this._clearPressTimer();\n this._updateActiveState();\n }\n\n private _handleClick(event: MouseEvent): void {\n // A nested selector already selected its own content\n if (isSelectionClick(event)) return;\n\n const isModifierClick = event.metaKey || event.ctrlKey;\n\n // Selected content (by a long press, or from the editor) and modifier\n // clicks never reach the app, so a link or button doesn't fire\n if (this._isSelecting || this._isSelectingState || isModifierClick) {\n event.preventDefault();\n event.stopPropagation();\n\n if (isModifierClick) this._select();\n return;\n }\n\n if (isInteractiveClickTarget(event)) return;\n\n // Left to propagate: the app's own handlers still run\n markSelectionClick(event);\n this._select();\n }\n\n private _handleBlur(): void {\n this._isSelectingState = false;\n this._updateActiveState();\n }\n}\n\n/**\n * Register all Intlayer custom elements.\n * Call this once at application startup (inside IntlayerEditorProvider or similar).\n * Safe to call multiple times — only registers elements that are not yet defined.\n */\nexport const defineIntlayerElements = (): void => {\n if (typeof customElements === 'undefined') return;\n if (!customElements.get('intlayer-content-selector')) {\n customElements.define(\n 'intlayer-content-selector',\n IntlayerContentSelectorElement\n );\n }\n defineIntlayerContentSelectorWrapper();\n};\n"],"mappings":";;;;;;AAIA,MAAM,yBAAyB;AAE/B,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;AAsBf,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;AAsBd,IAAa,iCAAb,cAAoD,aAAa;CAC/D,AAAQ,eAAe;CACvB,AAAQ,iBAAiB;CACzB,AAAQ,aAAa;CACrB,AAAQ,oBAAoB;CAC5B,AAAQ;CACR,AAAQ,cAAoD;CAC5D,AAAQ,uBAAyD;CAEjE,WAAW,qBAA+B;EACxC,OAAO,CAAC,gBAAgB,gBAAgB;CAC1C;CAEA,IAAI,cAAuB;EACzB,OAAO,KAAK;CACd;CACA,IAAI,YAAY,GAAY;EAC1B,KAAK,eAAe;EACpB,KAAK,mBAAmB;CAC1B;CAEA,IAAI,gBAAwB;EAC1B,OAAO,KAAK;CACd;CACA,IAAI,cAAc,GAAW;EAC3B,KAAK,iBAAiB;CACxB;CAEA,cAAc;EACZ,MAAM;EACN,MAAM,SAAS,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAEjD,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;EACpB,OAAO,YAAY,KAAK;EAExB,MAAM,UAAU,SAAS,cAAc,MAAM;EAC7C,QAAQ,YAAY;EACpB,QAAQ,aAAa,QAAQ,QAAQ;EACrC,QAAQ,aAAa,YAAY,GAAG;EACpC,QAAQ,YAAY,SAAS,cAAc,MAAM,CAAC;EAClD,OAAO,YAAY,OAAO;EAC1B,KAAK,WAAW;EAEhB,QAAQ,iBAAiB,mBAAmB,KAAK,iBAAiB,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;CAEA,AAAQ,UAAU,WAAyB;EACzC,KAAK,cACH,IAAI,YAAY,WAAW;GAAE,SAAS;GAAM,UAAU;EAAK,CAAC,CAC9D;CACF;CAEA,AAAQ,UAAgB;EACtB,KAAK,iBAAiB;EACtB,KAAK,oBAAoB;EACzB,KAAK,mBAAmB;EACxB,KAAK,UAAU,gBAAgB;CACjC;CAEA,AAAQ,mBAAyB;EAC/B,KAAK,iBAAiB;EACtB,KAAK,cAAc,iBAAiB,KAAK,QAAQ,GAAG,KAAK,cAAc;CACzE;CAEA,AAAQ,oBAA0B;EAChC,KAAK,aAAa;EAClB,KAAK,mBAAmB;EACxB,KAAK,UAAU,gBAAgB;CACjC;CAEA,AAAQ,wBAA8B;EACpC,IAAI,KAAK,YAAY;GACnB,KAAK,aAAa;GAClB,KAAK,UAAU,kBAAkB;EACnC;EACA,KAAK,iBAAiB;EACtB,KAAK,mBAAmB;CAC1B;CAEA,AAAQ,aAAa,OAAyB;EAE5C,IAAIA,6CAAiB,KAAK,GAAG;EAE7B,MAAM,kBAAkB,MAAM,WAAW,MAAM;EAI/C,IAAI,KAAK,gBAAgB,KAAK,qBAAqB,iBAAiB;GAClE,MAAM,eAAe;GACrB,MAAM,gBAAgB;GAEtB,IAAI,iBAAiB,KAAK,QAAQ;GAClC;EACF;EAEA,IAAIC,qEAAyB,KAAK,GAAG;EAGrC,+CAAmB,KAAK;EACxB,KAAK,QAAQ;CACf;CAEA,AAAQ,cAAoB;EAC1B,KAAK,oBAAoB;EACzB,KAAK,mBAAmB;CAC1B;AACF;;;;;;AAOA,MAAa,+BAAqC;CAChD,IAAI,OAAO,mBAAmB,aAAa;CAC3C,IAAI,CAAC,eAAe,IAAI,2BAA2B,GACjD,eAAe,OACb,6BACA,8BACF;CAEF,+EAAqC;AACvC"}
1
+ {"version":3,"file":"ContentSelector.cjs","names":["isSelectionClick","isInteractiveClickTarget"],"sources":["../../../src/components/ContentSelector.ts"],"sourcesContent":["import { isSelectionClick, markSelectionClick } from '../core/selectionClick';\nimport { defineIntlayerContentSelectorWrapper } from './ContentSelectorWrapper';\nimport { isInteractiveClickTarget } from './isInteractiveClickTarget';\n\nconst DEFAULT_PRESS_DURATION = 250;\n\nconst STYLES = `\n :host {\n display: contents;\n }\n\n .wrapper {\n display: inline-block;\n cursor: pointer;\n user-select: none;\n border-radius: 0.375rem;\n outline-width: 2px;\n outline-offset: 4px;\n outline-style: solid;\n outline-color: transparent;\n transition: all 100ms 50ms ease-in-out;\n }\n\n .wrapper[data-active] {\n outline-color: inherit;\n }\n\n /*\n * Text content wraps over several lines: an outline would frame the whole\n * block, so each line fragment gets its own ring instead. The padding keeps\n * the ring 4px away from the text, the negative margin cancels its layout.\n */\n .wrapper[data-text] {\n display: inline;\n outline: none;\n padding: 4px;\n margin: -4px;\n box-shadow: 0 0 0 2px transparent;\n -webkit-box-decoration-break: clone;\n box-decoration-break: clone;\n }\n\n .wrapper[data-text][data-active] {\n box-shadow: 0 0 0 2px currentColor;\n }\n`;\n\n/**\n * Whether the slotted content is only text, so it can be rendered inline and\n * highlighted line by line. Elements (markdown blocks, framework nodes) may\n * not lay out inline, and fall back to the outline.\n */\nconst isTextOnlyContent = (slot: HTMLSlotElement): boolean => {\n const assignedNodes = slot.assignedNodes({ flatten: true });\n\n return (\n assignedNodes.length > 0 &&\n assignedNodes.every((node) => node.nodeType === Node.TEXT_NODE)\n );\n};\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector>\n *\n * A framework-agnostic web component that wraps content with Intlayer editor\n * selection UI (hover outline, click to select, click-outside to deselect).\n *\n * Content is selected by:\n * - a click, unless it lands on something the app handles (link, button,\n * form control, clickable ancestor), which keeps its behavior\n * - a long press, on any content\n * - a ⌘ / Ctrl + click, on any content, cancelling the click's own action\n *\n * @fires intlayer:press - Fired when the content is selected. Bubbles.\n * @fires intlayer:hover - Fired on mouseenter. Bubbles.\n * @fires intlayer:unhover - Fired on mouseleave / mouseup. Bubbles.\n * @fires intlayer:click-outside - Fired when a click occurs outside the element. Bubbles.\n *\n * @prop {boolean} isSelecting - Whether this element is currently selected (external state)\n * @prop {number} pressDuration - Long-press threshold in ms. Default: 250\n */\nexport class IntlayerContentSelectorElement extends _HTMLElement {\n private _isSelecting = false;\n private _pressDuration = DEFAULT_PRESS_DURATION;\n private _isHovered = false;\n private _isSelectingState = false;\n private _wrapper: HTMLSpanElement;\n private _pressTimer: ReturnType<typeof setTimeout> | null = null;\n private _clickOutsideHandler: ((e: Event) => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['is-selecting', 'press-duration'];\n }\n\n get isSelecting(): boolean {\n return this._isSelecting;\n }\n set isSelecting(v: boolean) {\n this._isSelecting = v;\n this._updateActiveState();\n }\n\n get pressDuration(): number {\n return this._pressDuration;\n }\n set pressDuration(v: number) {\n this._pressDuration = v;\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n\n const style = document.createElement('style');\n style.textContent = STYLES;\n shadow.appendChild(style);\n\n const wrapper = document.createElement('span');\n wrapper.className = 'wrapper';\n wrapper.setAttribute('role', 'button');\n wrapper.setAttribute('tabindex', '0');\n const slot = document.createElement('slot');\n wrapper.appendChild(slot);\n shadow.appendChild(wrapper);\n this._wrapper = wrapper;\n\n slot.addEventListener('slotchange', () =>\n wrapper.toggleAttribute('data-text', isTextOnlyContent(slot))\n );\n\n wrapper.addEventListener('mousedown', () => this._handleMouseDown());\n wrapper.addEventListener('mouseup', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('mouseleave', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('mouseenter', () => this._handleMouseEnter());\n wrapper.addEventListener('click', (e) => this._handleClick(e));\n wrapper.addEventListener('touchstart', () => this._handleMouseDown());\n wrapper.addEventListener('touchend', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('touchcancel', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('blur', () => this._handleBlur());\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'is-selecting') {\n this._isSelecting = newVal !== null;\n this._updateActiveState();\n } else if (name === 'press-duration') {\n this._pressDuration =\n newVal !== null ? parseInt(newVal, 10) : DEFAULT_PRESS_DURATION;\n }\n }\n\n connectedCallback(): void {\n this._clickOutsideHandler = (e: Event) => {\n if (!this._isSelecting && !this._isSelectingState) return;\n\n // composedPath() pierces shadow boundaries\n if (!e.composedPath().includes(this)) {\n this._clearPressTimer();\n this._isSelectingState = false;\n this._isSelecting = false;\n this.removeAttribute('is-selecting');\n this._dispatch('intlayer:click-outside', { originalEvent: e });\n this._updateActiveState();\n }\n };\n document.addEventListener('mousedown', this._clickOutsideHandler);\n document.addEventListener('touchstart', this._clickOutsideHandler);\n }\n\n disconnectedCallback(): void {\n if (this._clickOutsideHandler) {\n document.removeEventListener('mousedown', this._clickOutsideHandler);\n document.removeEventListener('touchstart', this._clickOutsideHandler);\n this._clickOutsideHandler = null;\n }\n this._clearPressTimer();\n }\n\n private _updateActiveState(): void {\n const isActive =\n this._isSelecting || this._isSelectingState || this._isHovered;\n if (isActive) {\n this._wrapper.setAttribute('data-active', '');\n } else {\n this._wrapper.removeAttribute('data-active');\n }\n }\n\n private _clearPressTimer(): void {\n if (this._pressTimer !== null) {\n clearTimeout(this._pressTimer);\n this._pressTimer = null;\n }\n }\n\n private _dispatch(eventName: string, detail?: unknown): void {\n this.dispatchEvent(\n new CustomEvent(eventName, { detail, bubbles: true, composed: true })\n );\n }\n\n private _select(): void {\n this._clearPressTimer();\n this._isSelectingState = true;\n this._updateActiveState();\n this._dispatch('intlayer:press');\n }\n\n private _handleMouseDown(): void {\n this._clearPressTimer();\n this._pressTimer = setTimeout(() => this._select(), this._pressDuration);\n }\n\n private _handleMouseEnter(): void {\n this._isHovered = true;\n this._updateActiveState();\n this._dispatch('intlayer:hover');\n }\n\n private _handleMouseUpOrLeave(): void {\n if (this._isHovered) {\n this._isHovered = false;\n this._dispatch('intlayer:unhover');\n }\n this._clearPressTimer();\n this._updateActiveState();\n }\n\n private _handleClick(event: MouseEvent): void {\n // A nested selector already selected its own content\n if (isSelectionClick(event)) return;\n\n const isModifierClick = event.metaKey || event.ctrlKey;\n\n // Selected content (by a long press, or from the editor) and modifier\n // clicks never reach the app, so a link or button doesn't fire\n if (this._isSelecting || this._isSelectingState || isModifierClick) {\n event.preventDefault();\n event.stopPropagation();\n\n if (isModifierClick) this._select();\n return;\n }\n\n if (isInteractiveClickTarget(event)) return;\n\n // Left to propagate: the app's own handlers still run\n markSelectionClick(event);\n this._select();\n }\n\n private _handleBlur(): void {\n this._isSelectingState = false;\n this._updateActiveState();\n }\n}\n\n/**\n * Register all Intlayer custom elements.\n * Call this once at application startup (inside IntlayerEditorProvider or similar).\n * Safe to call multiple times — only registers elements that are not yet defined.\n */\nexport const defineIntlayerElements = (): void => {\n if (typeof customElements === 'undefined') return;\n if (!customElements.get('intlayer-content-selector')) {\n customElements.define(\n 'intlayer-content-selector',\n IntlayerContentSelectorElement\n );\n }\n defineIntlayerContentSelectorWrapper();\n};\n"],"mappings":";;;;;;AAIA,MAAM,yBAAyB;AAE/B,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8Cf,MAAM,qBAAqB,SAAmC;CAC5D,MAAM,gBAAgB,KAAK,cAAc,EAAE,SAAS,KAAK,CAAC;CAE1D,OACE,cAAc,SAAS,KACvB,cAAc,OAAO,SAAS,KAAK,aAAa,KAAK,SAAS;AAElE;AAEA,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;AAsBd,IAAa,iCAAb,cAAoD,aAAa;CAC/D,AAAQ,eAAe;CACvB,AAAQ,iBAAiB;CACzB,AAAQ,aAAa;CACrB,AAAQ,oBAAoB;CAC5B,AAAQ;CACR,AAAQ,cAAoD;CAC5D,AAAQ,uBAAoD;CAE5D,WA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;CAEA,AAAQ,mBAAyB;EAC/B,KAAK,iBAAiB;EACtB,KAAK,cAAc,iBAAiB,KAAK,QAAQ,GAAG,KAAK,cAAc;CACzE;CAEA,AAAQ,oBAA0B;EAChC,KAAK,aAAa;EAClB,KAAK,mBAAmB;EACxB,KAAK,UAAU,gBAAgB;CACjC;CAEA,AAAQ,wBAA8B;EACpC,IAAI,KAAK,YAAY;GACnB,KAAK,aAAa;GAClB,KAAK,UAAU,kBAAkB;EACnC;EACA,KAAK,iBAAiB;EACtB,KAAK,mBAAmB;CAC1B;CAEA,AAAQ,aAAa,OAAyB;EAE5C,IAAIA,6CAAiB,KAAK,GAAG;EAE7B,MAAM,kBAAkB,MAAM,WAAW,MAAM;EAI/C,IAAI,KAAK,gBAAgB,KAAK,qBAAqB,iBAAiB;GAClE,MAAM,eAAe;GACrB,MAAM,gBAAgB;GAEtB,IAAI,iBAAiB,KAAK,QAAQ;GAClC;EACF;EAEA,IAAIC,qEAAyB,KAAK,GAAG;EAGrC,+CAAmB,KAAK;EACxB,KAAK,QAAQ;CACf;CAEA,AAAQ,cAAoB;EAC1B,KAAK,oBAAoB;EACzB,KAAK,mBAAmB;CAC1B;AACF;;;;;;AAOA,MAAa,+BAAqC;CAChD,IAAI,OAAO,mBAAmB,aAAa;CAC3C,IAAI,CAAC,eAAe,IAAI,2BAA2B,GACjD,eAAe,OACb,6BACA,8BACF;CAEF,+EAAqC;AACvC"}
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_messageKey = require('../messageKey.cjs');
4
- const require_core_globalManager = require('../core/globalManager.cjs');
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
3
+ const require_core_globalManager = require("../core/globalManager.cjs");
4
+ const require_messageKey = require("../messageKey.cjs");
5
5
  let _intlayer_core_utils = require("@intlayer/core/utils");
6
6
  let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
7
7
  _intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
8
8
 
9
- //#region src/components/ContentSelectorWrapper.ts
9
+ // src/components/ContentSelectorWrapper.ts
10
10
  /**
11
11
  * Share of the viewport height left above content scrolled into view (30vh),
12
12
  * keeping it clear of fixed navbars.
@@ -95,6 +95,12 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
95
95
  static get observedAttributes() {
96
96
  return ["key-path", "dictionary-key"];
97
97
  }
98
+ get dictionaryKey() {
99
+ return this._dictionaryKey;
100
+ }
101
+ get filteredKeyPath() {
102
+ return this._getFilteredKeyPath();
103
+ }
98
104
  constructor() {
99
105
  super();
100
106
  const shadow = this.attachShadow({ mode: "open" });
@@ -254,6 +260,27 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
254
260
  e.stopPropagation();
255
261
  require_core_globalManager.getGlobalEditorManager()?.messenger.send(`${"INTLAYER_HOVERED_CONTENT_CHANGED"}/post`, null);
256
262
  }
263
+ _handleClickOutside(e) {
264
+ e.stopPropagation();
265
+ if (e.target !== this._selector) return;
266
+ if (!this._isSelected) return;
267
+ const originalEvent = e.detail?.originalEvent;
268
+ if (originalEvent) {
269
+ if (originalEvent.composedPath().some((target) => {
270
+ if (target instanceof HTMLElement && target.tagName === "INTLAYER-CONTENT-SELECTOR-WRAPPER") {
271
+ const wrapper = target;
272
+ return wrapper.dictionaryKey === this._dictionaryKey && (0, _intlayer_core_utils.isSameKeyPath)(wrapper.filteredKeyPath, this._getFilteredKeyPath());
273
+ }
274
+ return false;
275
+ })) {
276
+ this._selector?.setAttribute("is-selecting", "");
277
+ return;
278
+ }
279
+ }
280
+ const manager = require_core_globalManager.getGlobalEditorManager();
281
+ if (!manager) return;
282
+ manager.focusedContent.set(null);
283
+ }
257
284
  _render() {
258
285
  const useWrapper = this._isInIframe && this._editorEnabled;
259
286
  const editedValue = this._editedValue;
@@ -279,6 +306,7 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
279
306
  selector.addEventListener("intlayer:press", (e) => this._handlePress(e));
280
307
  selector.addEventListener("intlayer:hover", (e) => this._handleHover(e));
281
308
  selector.addEventListener("intlayer:unhover", (e) => this._handleUnhover(e));
309
+ selector.addEventListener("intlayer:click-outside", (e) => this._handleClickOutside(e));
282
310
  if (state === "wrapped-text") selector.appendChild(document.createTextNode(String(this._editedValue)));
283
311
  else selector.appendChild(document.createElement("slot"));
284
312
  shadow.appendChild(selector);
@@ -291,7 +319,6 @@ const defineIntlayerContentSelectorWrapper = () => {
291
319
  if (!customElements.get("intlayer-content-selector-wrapper")) customElements.define("intlayer-content-selector-wrapper", IntlayerContentSelectorWrapperElement);
292
320
  };
293
321
 
294
- //#endregion
295
322
  exports.IntlayerContentSelectorWrapperElement = IntlayerContentSelectorWrapperElement;
296
323
  exports.defineIntlayerContentSelectorWrapper = defineIntlayerContentSelectorWrapper;
297
324
  //# sourceMappingURL=ContentSelectorWrapper.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentSelectorWrapper.cjs","names":["getGlobalEditorManager","NodeTypes","node","isSameKeyPath","onGlobalEditorManagerChange"],"sources":["../../../src/components/ContentSelectorWrapper.ts"],"sourcesContent":["import { isSameKeyPath } from '@intlayer/core/utils';\n\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n EditorStateManager,\n FileContent,\n} from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\nimport { MessageKey } from '../messageKey';\n\ntype RenderState = 'simple' | 'wrapped-slot' | 'wrapped-text';\n\n/**\n * Share of the viewport height left above content scrolled into view (30vh),\n * keeping it clear of fixed navbars.\n */\nconst SCROLL_TOP_OFFSET_RATIO = 0.3;\n\n/** Parent in the flattened tree, crossing shadow roots up to their host. */\nconst getComposedParent = (element: Element): Element | null =>\n element.parentElement ??\n ((element.getRootNode() as ShadowRoot).host as Element | undefined) ??\n null;\n\n/** Vertical translation applied to an element, by `transform` or `translate`. */\nconst getTranslateY = (style: CSSStyleDeclaration): number => {\n const transformOffset =\n style.transform && style.transform !== 'none'\n ? new DOMMatrixReadOnly(style.transform).m42\n : 0;\n // `translate: <x> <y>` — a single value only moves along x\n const translateOffset = Number.parseFloat(\n style.translate?.split(' ')[1] ?? ''\n );\n\n return (\n transformOffset + (Number.isNaN(translateOffset) ? 0 : translateOffset)\n );\n};\n\n/**\n * Vertical offset the element will lose once its reveal animations end.\n *\n * Scroll-reveal effects (`whileInView`, AOS…) keep off-screen content\n * transparent and shifted until it enters the viewport, then slide it into\n * place: measuring it as-is would scroll too far by that shift. Only\n * translucent ancestors are counted, so permanent transforms (centering…)\n * stay part of the position.\n */\nconst getPendingRevealOffset = (element: Element): number => {\n let offset = 0;\n\n for (\n let ancestor: Element | null = element;\n ancestor;\n ancestor = getComposedParent(ancestor)\n ) {\n const style = getComputedStyle(ancestor);\n\n if (Number.parseFloat(style.opacity) < 1) offset += getTranslateY(style);\n }\n\n return offset;\n};\n\n/**\n * Reveal callbacks of the wrappers selected by the current focus change, keyed\n * by wrapper. A focus matches every wrapper under its key path (list items,\n * content rendered twice…), so they are batched and only the first is revealed.\n */\nconst pendingReveals = new Map<Element, () => void>();\n\n/** Whether `element` comes after `reference` in document order. */\nconst isAfterInDocument = (element: Element, reference: Element): boolean => {\n const position = reference.compareDocumentPosition(element);\n\n // Across unrelated trees the order is arbitrary: keep the earlier selection\n if (position & Node.DOCUMENT_POSITION_DISCONNECTED) return true;\n\n return Boolean(position & Node.DOCUMENT_POSITION_FOLLOWING);\n};\n\n/** Reveals the first wrapper, in document order, among the pending ones. */\nconst flushPendingReveals = (): void => {\n let firstWrapper: Element | null = null;\n\n for (const wrapper of pendingReveals.keys()) {\n if (!wrapper.isConnected) continue;\n if (!firstWrapper || !isAfterInDocument(wrapper, firstWrapper)) {\n firstWrapper = wrapper;\n }\n }\n\n const reveal = firstWrapper ? pendingReveals.get(firstWrapper) : undefined;\n pendingReveals.clear();\n reveal?.();\n};\n\n/** Queues a wrapper to reveal once every wrapper handled the focus change. */\nconst scheduleReveal = (wrapper: Element, reveal: () => void): void => {\n if (pendingReveals.size === 0) queueMicrotask(flushPendingReveals);\n pendingReveals.set(wrapper, reveal);\n};\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector-wrapper>\n *\n * Framework-agnostic web component that wraps content with the Intlayer editor\n * selection UI. It replaces the per-framework ContentSelectorWrapper components\n * (Vue, Svelte, Solid, Preact).\n *\n * It reads from the global EditorStateManager singleton (set by initEditorClient)\n * and conditionally renders <intlayer-content-selector> around its slot content\n * when the editor is active and the app is running inside an iframe.\n *\n * @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n * @attr {string} dictionary-key - The dictionary key owning this content node\n */\nexport class IntlayerContentSelectorWrapperElement extends _HTMLElement {\n private _keyPathJson = '[]';\n private _dictionaryKey = '';\n private _editorEnabled = false;\n private _isInIframe = false;\n private _isSelected = false;\n private _editedValue: ContentNode | undefined = undefined;\n\n private _renderState: RenderState | null = null;\n private _selector: HTMLElement | null = null;\n\n private _unsubManager: (() => void) | null = null;\n /** Removes the listeners attached to the current manager's states */\n private _unsubManagerState: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['key-path', 'dictionary-key'];\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = ':host { display: contents; }';\n shadow.appendChild(style);\n }\n\n attributeChangedCallback(\n name: string,\n _oldValue: string | null,\n newValue: string | null\n ): void {\n if (name === 'key-path') {\n this._keyPathJson = newValue ?? '[]';\n } else {\n this._dictionaryKey = newValue ?? '';\n }\n\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\n\n connectedCallback(): void {\n if (typeof window !== 'undefined') {\n this._isInIframe = window.self !== window.top;\n }\n this._subscribeToManager();\n this._render();\n }\n\n disconnectedCallback(): void {\n this._unsubManager?.();\n this._unsubManager = null;\n this._unsubManagerState?.();\n this._unsubManagerState = null;\n }\n\n private _getRawKeyPath(): KeyPath[] {\n try {\n return JSON.parse(this._keyPathJson) as KeyPath[];\n } catch {\n return [];\n }\n }\n\n private _getFilteredKeyPath(): KeyPath[] {\n return this._getRawKeyPath().filter(\n (keyPath) => keyPath.type !== NodeTypes.TRANSLATION\n );\n }\n\n private _updateEditedValue(manager: EditorStateManager): void {\n const filteredKeyPath = this._getFilteredKeyPath();\n if (!this._dictionaryKey || filteredKeyPath.length === 0) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n // Node types whose display requires framework-level rendering (markdown,\n // HTML, insertion, file): do not override the slot — the framework handles\n // those. Only plain / translated strings can be substituted here.\n const rawKeyPath = this._getRawKeyPath();\n const lastStepType = rawKeyPath[rawKeyPath.length - 1]?.type;\n if (\n lastStepType === NodeTypes.MARKDOWN ||\n lastStepType === NodeTypes.HTML ||\n lastStepType === NodeTypes.INSERTION ||\n lastStepType === NodeTypes.FILE\n ) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n let value = manager.getContentValue(this._dictionaryKey, filteredKeyPath);\n\n // getContentNodeByKeyPath resolves translation nodes only at intermediate\n // steps, not the final leaf. Resolve manually when the returned value is\n // still a translation object (happens when Translation steps are filtered\n // out and the leaf IS the translation object).\n if (\n value !== null &&\n value !== undefined &&\n typeof value === 'object' &&\n (value as { nodeType?: unknown }).nodeType === NodeTypes.TRANSLATION\n ) {\n const locale = manager.currentLocale.value as string | undefined;\n // TypedNodeModel<Translation, …> structurally satisfies TypedNode<BaseNode>\n // (both have nodeType), so this narrowing cast is sound.\n const node = value as TypedNodeModel<\n typeof NodeTypes.TRANSLATION,\n Record<string, ContentNode>\n >;\n value = locale ? node[NodeTypes.TRANSLATION][locale] : undefined;\n }\n\n this._editedValue = value;\n this._render();\n }\n\n private _updateIsSelected(\n focusedContent: FileContent | null | undefined\n ): void {\n if (!focusedContent) {\n this._isSelected = false;\n pendingReveals.delete(this);\n this._updateSelectorAttr();\n return;\n }\n const keyPath = this._getFilteredKeyPath();\n const wasSelected = this._isSelected;\n this._isSelected =\n focusedContent.dictionaryKey === this._dictionaryKey &&\n (focusedContent.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent.keyPath ?? [], keyPath);\n this._updateSelectorAttr();\n\n // Reveal content the editor focuses while it is off-screen in the app\n if (this._isSelected && !wasSelected) {\n scheduleReveal(this, () => this._scrollIntoViewIfNeeded());\n } else if (!this._isSelected) {\n pendingReveals.delete(this);\n }\n }\n\n /**\n * Scrolls the selected content to 30vh, unless it is already fully visible\n * in this frame's viewport.\n */\n private _scrollIntoViewIfNeeded(): void {\n // `.wrapper` is the only real box: this host and the selector are\n // `display: contents`. No selector means the editor UI is inactive.\n const target = this._selector?.shadowRoot?.querySelector('.wrapper');\n if (!target) return;\n\n const rect = target.getBoundingClientRect();\n // Where the content settles once revealed\n const top = rect.top - getPendingRevealOffset(target);\n const bottom = top + rect.height;\n\n const isFullyVisible = top >= 0 && bottom <= window.innerHeight;\n if (\n isFullyVisible &&\n !this._isCoveredAt((rect.left + rect.right) / 2, top + 1)\n ) {\n return;\n }\n\n window.scrollBy({\n top: top - window.innerHeight * SCROLL_TOP_OFFSET_RATIO,\n behavior: 'smooth',\n });\n }\n\n /**\n * Whether another element (a fixed navbar, a sticky header…) is painted over\n * this content at the given viewport point.\n */\n private _isCoveredAt(x: number, y: number): boolean {\n // Query from this element's own root so apps rendered in a shadow root\n // (Lit…) don't get their outer host back\n const root = this.getRootNode() as Document | ShadowRoot;\n if (typeof root.elementFromPoint !== 'function') return false;\n\n const topElement = root.elementFromPoint(x, y);\n\n return Boolean(topElement) && !this.contains(topElement);\n }\n\n private _updateSelectorAttr(): void {\n if (!this._selector) return;\n if (this._isSelected) {\n this._selector.setAttribute('is-selecting', '');\n } else {\n this._selector.removeAttribute('is-selecting');\n }\n }\n\n private _subscribeToManager(): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n this._setupManagerSubscriptions(manager);\n }\n // Keep listening for manager changes (handles stop + re-init cycles)\n this._unsubManager = onGlobalEditorManagerChange((nextManager) => {\n this._unsubManagerState?.();\n this._unsubManagerState = null;\n if (nextManager) {\n this._setupManagerSubscriptions(nextManager);\n } else {\n this._editorEnabled = false;\n this._isSelected = false;\n this._editedValue = undefined;\n this._render();\n }\n });\n }\n\n private _setupManagerSubscriptions(manager: EditorStateManager): void {\n this._editorEnabled = manager.editorEnabled.value ?? false;\n this._updateIsSelected(manager.focusedContent.value);\n this._updateEditedValue(manager);\n\n const handleEnabledChange = (e: Event) => {\n this._editorEnabled = (e as CustomEvent<boolean>).detail;\n this._render();\n };\n const handleFocusedChange = (e: Event) => {\n this._updateIsSelected((e as CustomEvent<FileContent | null>).detail);\n };\n const handleEditedContentChange = () => {\n this._updateEditedValue(manager);\n };\n\n manager.editorEnabled.addEventListener('change', handleEnabledChange);\n manager.focusedContent.addEventListener('change', handleFocusedChange);\n manager.editedContent.addEventListener('change', handleEditedContentChange);\n\n this._unsubManagerState = () => {\n manager.editorEnabled.removeEventListener('change', handleEnabledChange);\n manager.focusedContent.removeEventListener('change', handleFocusedChange);\n manager.editedContent.removeEventListener(\n 'change',\n handleEditedContentChange\n );\n };\n }\n\n private _handlePress(e: Event): void {\n // Stop propagation so nested wrappers don't also fire (composed + bubbles)\n e.stopPropagation();\n const manager = getGlobalEditorManager();\n if (!manager) return;\n manager.focusedContent.set({\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n });\n }\n\n private _handleHover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n {\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n }\n );\n }\n\n private _handleUnhover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n null\n );\n }\n\n private _render(): void {\n const useWrapper = this._isInIframe && this._editorEnabled;\n const editedValue = this._editedValue;\n const isSimpleValue =\n typeof editedValue === 'string' ||\n typeof editedValue === 'number' ||\n typeof editedValue === 'boolean';\n\n const newState: RenderState = !useWrapper\n ? 'simple'\n : isSimpleValue\n ? 'wrapped-text'\n : 'wrapped-slot';\n\n if (this._renderState !== newState) {\n this._rebuildContent(newState);\n return;\n }\n\n // Structure unchanged — update only dynamic parts\n if (newState !== 'simple' && this._selector) {\n this._updateSelectorAttr();\n if (\n newState === 'wrapped-text' &&\n this._selector.firstChild?.nodeType === Node.TEXT_NODE\n ) {\n (this._selector.firstChild as Text).data = String(editedValue);\n }\n }\n }\n\n private _rebuildContent(state: RenderState): void {\n const shadow = this.shadowRoot!;\n // Remove all nodes except the style element (first child)\n while (shadow.childNodes.length > 1) {\n shadow.removeChild(shadow.lastChild!);\n }\n this._selector = null;\n\n if (state === 'simple') {\n shadow.appendChild(document.createElement('slot'));\n } else {\n const selector = document.createElement('intlayer-content-selector');\n this._selector = selector;\n if (this._isSelected) selector.setAttribute('is-selecting', '');\n selector.addEventListener('intlayer:press', (e) => this._handlePress(e));\n selector.addEventListener('intlayer:hover', (e) => this._handleHover(e));\n selector.addEventListener('intlayer:unhover', (e) =>\n this._handleUnhover(e)\n );\n\n if (state === 'wrapped-text') {\n selector.appendChild(\n document.createTextNode(String(this._editedValue))\n );\n } else {\n selector.appendChild(document.createElement('slot'));\n }\n shadow.appendChild(selector);\n }\n\n this._renderState = state;\n }\n}\n\nexport const defineIntlayerContentSelectorWrapper = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-content-selector-wrapper')) {\n customElements.define(\n 'intlayer-content-selector-wrapper',\n IntlayerContentSelectorWrapperElement\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;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jB,IAAI,UAAU,UACZ,OAAO,YAAY,SAAS,cAAc,MAAM,CAAC;OAC5C;GACL,MAAM,WAAW,SAAS,cAAc,2BAA2B;GACnE,KAAK,YAAY;GACjB,IAAI,KAAK,aAAa,SAAS,aAAa,gBAAgB,EAAE;GAC9D,SAAS,iBAAiB,mBAAmB,MAAM,KAAK,aAAa,CAAC,CAAC;GACvE,SAAS,iBAAiB,mBAAmB,MAAM,KAAK,aAAa,CAAC,CAAC;GACvE,SAAS,iBAAiB,qBAAqB,MAC7C,KAAK,eAAe,CAAC,CACvB;GAEA,IAAI,UAAU,gBACZ,SAAS,YACP,SAAS,eAAe,OAAO,KAAK,YAAY,CAAC,CACnD;QAEA,SAAS,YAAY,SAAS,cAAc,MAAM,CAAC;GAErD,OAAO,YAAY,QAAQ;EAC7B;EAEA,KAAK,eAAe;CACtB;AACF;AAEA,MAAa,6CAAmD;CAC9D,IAAI,OAAO,mBAAmB,aAAa;CAE3C,IAAI,CAAC,eAAe,IAAI,mCAAmC,GACzD,eAAe,OACb,qCACA,qCACF;AAEJ"}
1
+ {"version":3,"file":"ContentSelectorWrapper.cjs","names":["getGlobalEditorManager","NodeTypes","node","isSameKeyPath","onGlobalEditorManagerChange","customEvent"],"sources":["../../../src/components/ContentSelectorWrapper.ts"],"sourcesContent":["import { isSameKeyPath } from '@intlayer/core/utils';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n EditorStateManager,\n FileContent,\n} from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\nimport { MessageKey } from '../messageKey';\n\ntype RenderState = 'simple' | 'wrapped-slot' | 'wrapped-text';\n\n/**\n * Share of the viewport height left above content scrolled into view (30vh),\n * keeping it clear of fixed navbars.\n */\nconst SCROLL_TOP_OFFSET_RATIO = 0.3;\n\n/** Parent in the flattened tree, crossing shadow roots up to their host. */\nconst getComposedParent = (element: Element): Element | null =>\n element.parentElement ??\n ((element.getRootNode() as ShadowRoot).host as Element | undefined) ??\n null;\n\n/** Vertical translation applied to an element, by `transform` or `translate`. */\nconst getTranslateY = (style: CSSStyleDeclaration): number => {\n const transformOffset =\n style.transform && style.transform !== 'none'\n ? new DOMMatrixReadOnly(style.transform).m42\n : 0;\n // `translate: <x> <y>` — a single value only moves along x\n const translateOffset = Number.parseFloat(\n style.translate?.split(' ')[1] ?? ''\n );\n\n return (\n transformOffset + (Number.isNaN(translateOffset) ? 0 : translateOffset)\n );\n};\n\n/**\n * Vertical offset the element will lose once its reveal animations end.\n *\n * Scroll-reveal effects (`whileInView`, AOS…) keep off-screen content\n * transparent and shifted until it enters the viewport, then slide it into\n * place: measuring it as-is would scroll too far by that shift. Only\n * translucent ancestors are counted, so permanent transforms (centering…)\n * stay part of the position.\n */\nconst getPendingRevealOffset = (element: Element): number => {\n let offset = 0;\n\n for (\n let ancestor: Element | null = element;\n ancestor;\n ancestor = getComposedParent(ancestor)\n ) {\n const style = getComputedStyle(ancestor);\n\n if (Number.parseFloat(style.opacity) < 1) offset += getTranslateY(style);\n }\n\n return offset;\n};\n\n/**\n * Reveal callbacks of the wrappers selected by the current focus change, keyed\n * by wrapper. A focus matches every wrapper under its key path (list items,\n * content rendered twice…), so they are batched and only the first is revealed.\n */\nconst pendingReveals = new Map<Element, () => void>();\n\n/** Whether `element` comes after `reference` in document order. */\nconst isAfterInDocument = (element: Element, reference: Element): boolean => {\n const position = reference.compareDocumentPosition(element);\n\n // Across unrelated trees the order is arbitrary: keep the earlier selection\n if (position & Node.DOCUMENT_POSITION_DISCONNECTED) return true;\n\n return Boolean(position & Node.DOCUMENT_POSITION_FOLLOWING);\n};\n\n/** Reveals the first wrapper, in document order, among the pending ones. */\nconst flushPendingReveals = (): void => {\n let firstWrapper: Element | null = null;\n\n for (const wrapper of pendingReveals.keys()) {\n if (!wrapper.isConnected) continue;\n if (!firstWrapper || !isAfterInDocument(wrapper, firstWrapper)) {\n firstWrapper = wrapper;\n }\n }\n\n const reveal = firstWrapper ? pendingReveals.get(firstWrapper) : undefined;\n pendingReveals.clear();\n reveal?.();\n};\n\n/** Queues a wrapper to reveal once every wrapper handled the focus change. */\nconst scheduleReveal = (wrapper: Element, reveal: () => void): void => {\n if (pendingReveals.size === 0) queueMicrotask(flushPendingReveals);\n pendingReveals.set(wrapper, reveal);\n};\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector-wrapper>\n *\n * Framework-agnostic web component that wraps content with the Intlayer editor\n * selection UI. It replaces the per-framework ContentSelectorWrapper components\n * (Vue, Svelte, Solid, Preact).\n *\n * It reads from the global EditorStateManager singleton (set by initEditorClient)\n * and conditionally renders <intlayer-content-selector> around its slot content\n * when the editor is active and the app is running inside an iframe.\n *\n * @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n * @attr {string} dictionary-key - The dictionary key owning this content node\n */\nexport class IntlayerContentSelectorWrapperElement extends _HTMLElement {\n private _keyPathJson = '[]';\n private _dictionaryKey = '';\n private _editorEnabled = false;\n private _isInIframe = false;\n private _isSelected = false;\n private _editedValue: ContentNode | undefined = undefined;\n\n private _renderState: RenderState | null = null;\n private _selector: HTMLElement | null = null;\n\n private _unsubManager: (() => void) | null = null;\n /** Removes the listeners attached to the current manager's states */\n private _unsubManagerState: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['key-path', 'dictionary-key'];\n }\n\n get dictionaryKey(): string {\n return this._dictionaryKey;\n }\n\n get filteredKeyPath(): KeyPath[] {\n return this._getFilteredKeyPath();\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = ':host { display: contents; }';\n shadow.appendChild(style);\n }\n\n attributeChangedCallback(\n name: string,\n _oldValue: string | null,\n newValue: string | null\n ): void {\n if (name === 'key-path') {\n this._keyPathJson = newValue ?? '[]';\n } else {\n this._dictionaryKey = newValue ?? '';\n }\n\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\n\n connectedCallback(): void {\n if (typeof window !== 'undefined') {\n this._isInIframe = window.self !== window.top;\n }\n this._subscribeToManager();\n this._render();\n }\n\n disconnectedCallback(): void {\n this._unsubManager?.();\n this._unsubManager = null;\n this._unsubManagerState?.();\n this._unsubManagerState = null;\n }\n\n private _getRawKeyPath(): KeyPath[] {\n try {\n return JSON.parse(this._keyPathJson) as KeyPath[];\n } catch {\n return [];\n }\n }\n\n private _getFilteredKeyPath(): KeyPath[] {\n return this._getRawKeyPath().filter(\n (keyPath) => keyPath.type !== NodeTypes.TRANSLATION\n );\n }\n\n private _updateEditedValue(manager: EditorStateManager): void {\n const filteredKeyPath = this._getFilteredKeyPath();\n if (!this._dictionaryKey || filteredKeyPath.length === 0) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n // Node types whose display requires framework-level rendering (markdown,\n // HTML, insertion, file): do not override the slot — the framework handles\n // those. Only plain / translated strings can be substituted here.\n const rawKeyPath = this._getRawKeyPath();\n const lastStepType = rawKeyPath[rawKeyPath.length - 1]?.type;\n if (\n lastStepType === NodeTypes.MARKDOWN ||\n lastStepType === NodeTypes.HTML ||\n lastStepType === NodeTypes.INSERTION ||\n lastStepType === NodeTypes.FILE\n ) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n let value = manager.getContentValue(this._dictionaryKey, filteredKeyPath);\n\n // getContentNodeByKeyPath resolves translation nodes only at intermediate\n // steps, not the final leaf. Resolve manually when the returned value is\n // still a translation object (happens when Translation steps are filtered\n // out and the leaf IS the translation object).\n if (\n value !== null &&\n value !== undefined &&\n typeof value === 'object' &&\n (value as { nodeType?: unknown }).nodeType === NodeTypes.TRANSLATION\n ) {\n const locale = manager.currentLocale.value as string | undefined;\n // TypedNodeModel<Translation, …> structurally satisfies TypedNode<BaseNode>\n // (both have nodeType), so this narrowing cast is sound.\n const node = value as TypedNodeModel<\n typeof NodeTypes.TRANSLATION,\n Record<string, ContentNode>\n >;\n value = locale ? node[NodeTypes.TRANSLATION][locale] : undefined;\n }\n\n this._editedValue = value;\n this._render();\n }\n\n private _updateIsSelected(\n focusedContent: FileContent | null | undefined\n ): void {\n if (!focusedContent) {\n this._isSelected = false;\n pendingReveals.delete(this);\n this._updateSelectorAttr();\n return;\n }\n const keyPath = this._getFilteredKeyPath();\n const wasSelected = this._isSelected;\n this._isSelected =\n focusedContent.dictionaryKey === this._dictionaryKey &&\n (focusedContent.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent.keyPath ?? [], keyPath);\n this._updateSelectorAttr();\n\n // Reveal content the editor focuses while it is off-screen in the app\n if (this._isSelected && !wasSelected) {\n scheduleReveal(this, () => this._scrollIntoViewIfNeeded());\n } else if (!this._isSelected) {\n pendingReveals.delete(this);\n }\n }\n\n /**\n * Scrolls the selected content to 30vh, unless it is already fully visible\n * in this frame's viewport.\n */\n private _scrollIntoViewIfNeeded(): void {\n // `.wrapper` is the only real box: this host and the selector are\n // `display: contents`. No selector means the editor UI is inactive.\n const target = this._selector?.shadowRoot?.querySelector('.wrapper');\n if (!target) return;\n\n const rect = target.getBoundingClientRect();\n // Where the content settles once revealed\n const top = rect.top - getPendingRevealOffset(target);\n const bottom = top + rect.height;\n\n const isFullyVisible = top >= 0 && bottom <= window.innerHeight;\n if (\n isFullyVisible &&\n !this._isCoveredAt((rect.left + rect.right) / 2, top + 1)\n ) {\n return;\n }\n\n window.scrollBy({\n top: top - window.innerHeight * SCROLL_TOP_OFFSET_RATIO,\n behavior: 'smooth',\n });\n }\n\n /**\n * Whether another element (a fixed navbar, a sticky header…) is painted over\n * this content at the given viewport point.\n */\n private _isCoveredAt(x: number, y: number): boolean {\n // Query from this element's own root so apps rendered in a shadow root\n // (Lit…) don't get their outer host back\n const root = this.getRootNode() as Document | ShadowRoot;\n if (typeof root.elementFromPoint !== 'function') return false;\n\n const topElement = root.elementFromPoint(x, y);\n\n return Boolean(topElement) && !this.contains(topElement);\n }\n\n private _updateSelectorAttr(): void {\n if (!this._selector) return;\n if (this._isSelected) {\n this._selector.setAttribute('is-selecting', '');\n } else {\n this._selector.removeAttribute('is-selecting');\n }\n }\n\n private _subscribeToManager(): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n this._setupManagerSubscriptions(manager);\n }\n // Keep listening for manager changes (handles stop + re-init cycles)\n this._unsubManager = onGlobalEditorManagerChange((nextManager) => {\n this._unsubManagerState?.();\n this._unsubManagerState = null;\n if (nextManager) {\n this._setupManagerSubscriptions(nextManager);\n } else {\n this._editorEnabled = false;\n this._isSelected = false;\n this._editedValue = undefined;\n this._render();\n }\n });\n }\n\n private _setupManagerSubscriptions(manager: EditorStateManager): void {\n this._editorEnabled = manager.editorEnabled.value ?? false;\n this._updateIsSelected(manager.focusedContent.value);\n this._updateEditedValue(manager);\n\n const handleEnabledChange = (e: Event) => {\n this._editorEnabled = (e as CustomEvent<boolean>).detail;\n this._render();\n };\n const handleFocusedChange = (e: Event) => {\n this._updateIsSelected((e as CustomEvent<FileContent | null>).detail);\n };\n const handleEditedContentChange = () => {\n this._updateEditedValue(manager);\n };\n\n manager.editorEnabled.addEventListener('change', handleEnabledChange);\n manager.focusedContent.addEventListener('change', handleFocusedChange);\n manager.editedContent.addEventListener('change', handleEditedContentChange);\n\n this._unsubManagerState = () => {\n manager.editorEnabled.removeEventListener('change', handleEnabledChange);\n manager.focusedContent.removeEventListener('change', handleFocusedChange);\n manager.editedContent.removeEventListener(\n 'change',\n handleEditedContentChange\n );\n };\n }\n\n private _handlePress(e: Event): void {\n // Stop propagation so nested wrappers don't also fire (composed + bubbles)\n e.stopPropagation();\n const manager = getGlobalEditorManager();\n if (!manager) return;\n manager.focusedContent.set({\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n });\n }\n\n private _handleHover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n {\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n }\n );\n }\n\n private _handleUnhover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n null\n );\n }\n\n private _handleClickOutside(e: Event): void {\n e.stopPropagation();\n if (e.target !== this._selector) return;\n if (!this._isSelected) return;\n\n const customEvent = e as CustomEvent<{ originalEvent?: Event }>;\n const originalEvent = customEvent.detail?.originalEvent;\n if (originalEvent) {\n const path = originalEvent.composedPath();\n const isClickedOnSameContent = path.some((target) => {\n if (\n target instanceof HTMLElement &&\n target.tagName === 'INTLAYER-CONTENT-SELECTOR-WRAPPER'\n ) {\n const wrapper = target as IntlayerContentSelectorWrapperElement;\n return (\n wrapper.dictionaryKey === this._dictionaryKey &&\n isSameKeyPath(wrapper.filteredKeyPath, this._getFilteredKeyPath())\n );\n }\n return false;\n });\n if (isClickedOnSameContent) {\n this._selector?.setAttribute('is-selecting', '');\n return;\n }\n }\n\n const manager = getGlobalEditorManager();\n if (!manager) return;\n manager.focusedContent.set(null);\n }\n\n private _render(): void {\n const useWrapper = this._isInIframe && this._editorEnabled;\n const editedValue = this._editedValue;\n const isSimpleValue =\n typeof editedValue === 'string' ||\n typeof editedValue === 'number' ||\n typeof editedValue === 'boolean';\n\n const newState: RenderState = !useWrapper\n ? 'simple'\n : isSimpleValue\n ? 'wrapped-text'\n : 'wrapped-slot';\n\n if (this._renderState !== newState) {\n this._rebuildContent(newState);\n return;\n }\n\n // Structure unchanged — update only dynamic parts\n if (newState !== 'simple' && this._selector) {\n this._updateSelectorAttr();\n if (\n newState === 'wrapped-text' &&\n this._selector.firstChild?.nodeType === Node.TEXT_NODE\n ) {\n (this._selector.firstChild as Text).data = String(editedValue);\n }\n }\n }\n\n private _rebuildContent(state: RenderState): void {\n const shadow = this.shadowRoot!;\n // Remove all nodes except the style element (first child)\n while (shadow.childNodes.length > 1) {\n shadow.removeChild(shadow.lastChild!);\n }\n this._selector = null;\n\n if (state === 'simple') {\n shadow.appendChild(document.createElement('slot'));\n } else {\n const selector = document.createElement('intlayer-content-selector');\n this._selector = selector;\n if (this._isSelected) selector.setAttribute('is-selecting', '');\n selector.addEventListener('intlayer:press', (e) => this._handlePress(e));\n selector.addEventListener('intlayer:hover', (e) => this._handleHover(e));\n selector.addEventListener('intlayer:unhover', (e) =>\n this._handleUnhover(e)\n );\n selector.addEventListener('intlayer:click-outside', (e) =>\n this._handleClickOutside(e)\n );\n\n if (state === 'wrapped-text') {\n selector.appendChild(\n document.createTextNode(String(this._editedValue))\n );\n } else {\n selector.appendChild(document.createElement('slot'));\n }\n shadow.appendChild(selector);\n }\n\n this._renderState = state;\n }\n}\n\nexport const defineIntlayerContentSelectorWrapper = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-content-selector-wrapper')) {\n customElements.define(\n 'intlayer-content-selector-wrapper',\n IntlayerContentSelectorWrapperElement\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAqBA,MAAM,0BAA0B;;AAGhC,MAAM,qBAAqB,YACzB,QAAQ,iBACN,QAAQ,YAAY,CAAC,CAAgB,QACvC;;AAGF,MAAM,iBAAiB,UAAuC;CAC5D,MAAM,kBACJ,MAAM,aAAa,MAAM,cAAc,SACnC,IAAI,kBAAkB,MAAM,SAAS,CAAC,CAAC,MACvC;CAEN,MAAM,kBAAkB,OAAO,WAC7B,MAAM,WAAW,MAAM,GAAG,CAAC,CAAC,MAAM,EACpC;CAEA,OACE,mBAAmB,OAAO,MAAM,eAAe,IAAI,IAAI;AAE3D;;;;;;;;;;AAWA,MAAM,0BAA0B,YAA6B;CAC3D,IAAI,SAAS;CAEb,KACE,IAAI,WAA2B,SAC/B,UACA,WAAW,kBAAkB,QAAQ,GACrC;EACA,MAAM,QAAQ,iBAAiB,QAA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AgB,OAA0B;EAChD,MAAM,SAAS,KAAK;EAEpB,OAAO,OAAO,WAAW,SAAS,GAChC,OAAO,YAAY,OAAO,SAAU;EAEtC,KAAK,YAAY;EAEjB,IAAI,UAAU,UACZ,OAAO,YAAY,SAAS,cAAc,MAAM,CAAC;OAC5C;GACL,MAAM,WAAW,SAAS,cAAc,2BAA2B;GACnE,KAAK,YAAY;GACjB,IAAI,KAAK,aAAa,SAAS,aAAa,gBAAgB,EAAE;GAC9D,SAAS,iBAAiB,mBAAmB,MAAM,KAAK,aAAa,CAAC,CAAC;GACvE,SAAS,iBAAiB,mBAAmB,MAAM,KAAK,aAAa,CAAC,CAAC;GACvE,SAAS,iBAAiB,qBAAqB,MAC7C,KAAK,eAAe,CAAC,CACvB;GACA,SAAS,iBAAiB,2BAA2B,MACnD,KAAK,oBAAoB,CAAC,CAC5B;GAEA,IAAI,UAAU,gBACZ,SAAS,YACP,SAAS,eAAe,OAAO,KAAK,YAAY,CAAC,CACnD;QAEA,SAAS,YAAY,SAAS,cAAc,MAAM,CAAC;GAErD,OAAO,YAAY,QAAQ;EAC7B;EAEA,KAAK,eAAe;CACtB;AACF;AAEA,MAAa,6CAAmD;CAC9D,IAAI,OAAO,mBAAmB,aAAa;CAE3C,IAAI,CAAC,eAAe,IAAI,mCAAmC,GACzD,eAAe,OACb,qCACA,qCACF;AAEJ"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_components_ContentSelectorWrapper = require('./ContentSelectorWrapper.cjs');
3
- const require_components_ContentSelector = require('./ContentSelector.cjs');
2
+ const require_components_ContentSelector = require("./ContentSelector.cjs");
3
+ const require_components_ContentSelectorWrapper = require("./ContentSelectorWrapper.cjs");
4
4
 
5
5
  exports.IntlayerContentSelectorElement = require_components_ContentSelector.IntlayerContentSelectorElement;
6
6
  exports.IntlayerContentSelectorWrapperElement = require_components_ContentSelectorWrapper.IntlayerContentSelectorWrapperElement;
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- //#region src/components/isInteractiveClickTarget.ts
2
+ // src/components/isInteractiveClickTarget.ts
3
3
  /** Elements whose click already does something in the application. */
4
4
  const INTERACTIVE_ELEMENT_SELECTOR = [
5
5
  "a[href]",
@@ -61,6 +61,5 @@ const isInteractiveClickTarget = (event) => {
61
61
  });
62
62
  };
63
63
 
64
- //#endregion
65
64
  exports.isInteractiveClickTarget = isInteractiveClickTarget;
66
65
  //# sourceMappingURL=isInteractiveClickTarget.cjs.map
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_compareUrls = require('../compareUrls.cjs');
2
+ const require_compareUrls = require("../compareUrls.cjs");
3
3
 
4
- //#region src/core/CrossFrameMessenger.ts
4
+ // src/core/CrossFrameMessenger.ts
5
5
  const randomUUID = () => Math.random().toString(36).slice(2);
6
6
  /**
7
7
  * CrossFrameMessenger manages all cross-frame postMessage communication.
@@ -84,6 +84,5 @@ var CrossFrameMessenger = class {
84
84
  }
85
85
  };
86
86
 
87
- //#endregion
88
87
  exports.CrossFrameMessenger = CrossFrameMessenger;
89
88
  //# sourceMappingURL=CrossFrameMessenger.cjs.map
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- //#region src/core/CrossFrameStateManager.ts
2
+ // src/core/CrossFrameStateManager.ts
3
3
  /**
4
4
  * CrossFrameStateManager synchronizes a single named value across frames using
5
5
  * the postMessage API via CrossFrameMessenger.
@@ -78,6 +78,5 @@ var CrossFrameStateManager = class extends EventTarget {
78
78
  }
79
79
  };
80
80
 
81
- //#endregion
82
81
  exports.CrossFrameStateManager = CrossFrameStateManager;
83
82
  //# sourceMappingURL=CrossFrameStateManager.cjs.map
@@ -1,16 +1,25 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_messageKey = require('../messageKey.cjs');
4
- const require_core_CrossFrameMessenger = require('./CrossFrameMessenger.cjs');
5
- const require_core_CrossFrameStateManager = require('./CrossFrameStateManager.cjs');
6
- const require_core_IframeClickInterceptor = require('./IframeClickInterceptor.cjs');
7
- const require_core_sharedWindowState = require('./sharedWindowState.cjs');
8
- const require_core_UrlStateManager = require('./UrlStateManager.cjs');
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
3
+ const require_messageKey = require("../messageKey.cjs");
4
+ const require_core_CrossFrameMessenger = require("./CrossFrameMessenger.cjs");
5
+ const require_core_CrossFrameStateManager = require("./CrossFrameStateManager.cjs");
6
+ const require_core_IframeClickInterceptor = require("./IframeClickInterceptor.cjs");
7
+ const require_core_sharedWindowState = require("./sharedWindowState.cjs");
8
+ const require_core_UrlStateManager = require("./UrlStateManager.cjs");
9
9
  let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
10
10
  _intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
11
11
  let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
12
12
 
13
- //#region src/core/EditorStateManager.ts
13
+ // src/core/EditorStateManager.ts
14
+ /** Delay between two editor pings checking the client still answers. */
15
+ const CLIENT_HEARTBEAT_INTERVAL_MS = 3e3;
16
+ /**
17
+ * Silence after which the client counts as disconnected (e.g. its dev server
18
+ * restarted). Pings go on, so it is activated again as soon as it answers.
19
+ */
20
+ const CLIENT_HEARTBEAT_TIMEOUT_MS = 1e4;
21
+ /** Clients older than the heartbeat announce themselves without payload. */
22
+ const isClientReadyPayload = (data) => typeof data === "object" && data !== null && typeof data.isActivated === "boolean";
14
23
  const sharedEditedContent = require_core_sharedWindowState.createSharedWindowState("edited_content");
15
24
  const sharedFocusedContent = require_core_sharedWindowState.createSharedWindowState("focused_content");
16
25
  /**
@@ -37,9 +46,12 @@ var EditorStateManager = class {
37
46
  _unsubAreYouThere = null;
38
47
  _unsubActivate = null;
39
48
  _unsubClientReady = null;
49
+ _clientHeartbeatTimer = null;
50
+ _lastClientReadyAt = 0;
40
51
  _displayedKeysObserver = null;
41
52
  _displayedKeysTimer = null;
42
53
  _displayedKeysListeners = [];
54
+ _unsubDisplayedKeysGet = null;
43
55
  _stopSharedStateSyncs = [];
44
56
  constructor(config) {
45
57
  this._mode = config.mode;
@@ -69,7 +81,7 @@ var EditorStateManager = class {
69
81
  this.displayedDictionaryKeys = new require_core_CrossFrameStateManager.CrossFrameStateManager("INTLAYER_DISPLAYED_DICTIONARY_KEYS", this.messenger, {
70
82
  emit: config.mode === "client",
71
83
  receive: config.mode === "editor",
72
- initialValue: []
84
+ initialValue: config.mode === "client" ? [] : void 0
73
85
  });
74
86
  this._urlManager = new require_core_UrlStateManager.UrlStateManager(this.messenger);
75
87
  this._iframeInterceptor = new require_core_IframeClickInterceptor.IframeClickInterceptor(this.messenger);
@@ -103,6 +115,7 @@ var EditorStateManager = class {
103
115
  this._unsubAreYouThere = null;
104
116
  this._unsubActivate = null;
105
117
  this._unsubClientReady = null;
118
+ this._stopClientHeartbeat();
106
119
  this.messenger.stop();
107
120
  this.editorEnabled.stop();
108
121
  this.focusedContent.stop();
@@ -144,12 +157,11 @@ var EditorStateManager = class {
144
157
  return this.messenger.subscribe("INTLAYER_LOCALE_CHANGE_REQUESTED", handler);
145
158
  }
146
159
  setFocusedContentKeyPath(keyPath) {
147
- const filtered = keyPath.filter((key) => key.type !== _intlayer_types_nodeType.TRANSLATION);
148
160
  const prev = this.focusedContent.value;
149
161
  if (!prev) return;
150
162
  this.focusedContent.set({
151
163
  ...prev,
152
- keyPath: filtered
164
+ keyPath
153
165
  });
154
166
  }
155
167
  setLocaleDictionary(dictionary) {
@@ -305,6 +317,9 @@ var EditorStateManager = class {
305
317
  window.addEventListener(evt, listener);
306
318
  this._displayedKeysListeners.push([evt, listener]);
307
319
  }
320
+ this._unsubDisplayedKeysGet = this.messenger.subscribe(`${"INTLAYER_DISPLAYED_DICTIONARY_KEYS"}/get`, () => {
321
+ this._scanDisplayedDictionaryKeys();
322
+ });
308
323
  this._scanDisplayedDictionaryKeys();
309
324
  }
310
325
  _stopDisplayedDictionariesTracking() {
@@ -316,25 +331,52 @@ var EditorStateManager = class {
316
331
  }
317
332
  for (const [evt, listener] of this._displayedKeysListeners) window.removeEventListener(evt, listener);
318
333
  this._displayedKeysListeners = [];
334
+ this._unsubDisplayedKeysGet?.();
335
+ this._unsubDisplayedKeysGet = null;
319
336
  }
320
337
  /**
321
338
  * EDITOR mode: listen for CLIENT_READY and respond with EDITOR_ACTIVATE.
322
339
  * Also pings the client immediately in case it loaded before the editor.
323
340
  */
324
341
  _setupEditorHandshake() {
325
- this._unsubClientReady = this.messenger.subscribe("INTLAYER_CLIENT_READY", () => {
342
+ this._unsubClientReady = this.messenger.subscribe("INTLAYER_CLIENT_READY", (data) => {
343
+ if (!isClientReadyPayload(data)) {
344
+ this.editorEnabled.set(true);
345
+ this.messenger.send("INTLAYER_EDITOR_ACTIVATE");
346
+ return;
347
+ }
348
+ const isConnected = data.isActivated && this.editorEnabled.value;
349
+ this._lastClientReadyAt = Date.now();
350
+ this._startClientHeartbeat();
326
351
  this.editorEnabled.set(true);
327
- this.messenger.send("INTLAYER_EDITOR_ACTIVATE");
352
+ if (!isConnected) this.messenger.send("INTLAYER_EDITOR_ACTIVATE");
328
353
  });
329
354
  this.messenger.send("INTLAYER_ARE_YOU_THERE");
330
355
  }
356
+ /**
357
+ * EDITOR mode: keeps pinging the client. A client that stopped answering
358
+ * (dev server restart, reloaded frame, re-evaluated client module) is marked
359
+ * disconnected, then activated again on its next answer.
360
+ */
361
+ _startClientHeartbeat() {
362
+ if (this._clientHeartbeatTimer) return;
363
+ this._clientHeartbeatTimer = setInterval(() => {
364
+ const isClientSilent = Date.now() - this._lastClientReadyAt > CLIENT_HEARTBEAT_TIMEOUT_MS;
365
+ if (this.editorEnabled.value && isClientSilent) this.editorEnabled.set(false);
366
+ this.messenger.send("INTLAYER_ARE_YOU_THERE");
367
+ }, CLIENT_HEARTBEAT_INTERVAL_MS);
368
+ }
369
+ _stopClientHeartbeat() {
370
+ if (this._clientHeartbeatTimer) clearInterval(this._clientHeartbeatTimer);
371
+ this._clientHeartbeatTimer = null;
372
+ }
331
373
  _setupActivationHandshake() {
332
- this.messenger.send("INTLAYER_CLIENT_READY");
333
- this._unsubAreYouThere = this.messenger.subscribe("INTLAYER_ARE_YOU_THERE", () => {
334
- this.messenger.send("INTLAYER_CLIENT_READY");
335
- });
374
+ const announceReady = () => this.messenger.send("INTLAYER_CLIENT_READY", { isActivated: this.editorEnabled.value === true });
375
+ announceReady();
376
+ this._unsubAreYouThere = this.messenger.subscribe("INTLAYER_ARE_YOU_THERE", announceReady);
336
377
  this._unsubActivate = this.messenger.subscribe("INTLAYER_EDITOR_ACTIVATE", () => {
337
378
  this.editorEnabled.set(true);
379
+ this._scanDisplayedDictionaryKeys();
338
380
  this._broadcastData();
339
381
  });
340
382
  }
@@ -345,6 +387,8 @@ var EditorStateManager = class {
345
387
  if (localeVal) this.messenger.send(`${"INTLAYER_CURRENT_LOCALE"}/post`, localeVal);
346
388
  const dicts = this.localeDictionaries.value;
347
389
  if (dicts) this.messenger.send(`${"INTLAYER_LOCALE_DICTIONARIES_CHANGED"}/post`, dicts);
390
+ const displayedKeys = this.displayedDictionaryKeys.value;
391
+ if (displayedKeys) this.messenger.send(`${"INTLAYER_DISPLAYED_DICTIONARY_KEYS"}/post`, displayedKeys);
348
392
  }
349
393
  async _loadDictionaries() {
350
394
  try {
@@ -358,6 +402,7 @@ var EditorStateManager = class {
358
402
  }
359
403
  };
360
404
 
361
- //#endregion
405
+ exports.CLIENT_HEARTBEAT_INTERVAL_MS = CLIENT_HEARTBEAT_INTERVAL_MS;
406
+ exports.CLIENT_HEARTBEAT_TIMEOUT_MS = CLIENT_HEARTBEAT_TIMEOUT_MS;
362
407
  exports.EditorStateManager = EditorStateManager;
363
408
  //# sourceMappingURL=EditorStateManager.cjs.map