@intlayer/editor 9.6.0 → 9.7.1

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 (92) 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 +70 -17
  4. package/dist/cjs/components/ContentSelector.cjs.map +1 -1
  5. package/dist/cjs/components/ContentSelectorWrapper.cjs +63 -6
  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 +65 -0
  9. package/dist/cjs/components/isInteractiveClickTarget.cjs.map +1 -0
  10. package/dist/cjs/core/CrossFrameMessenger.cjs +2 -3
  11. package/dist/cjs/core/CrossFrameStateManager.cjs +1 -2
  12. package/dist/cjs/core/EditorStateManager.cjs +79 -18
  13. package/dist/cjs/core/EditorStateManager.cjs.map +1 -1
  14. package/dist/cjs/core/IframeClickInterceptor.cjs +17 -10
  15. package/dist/cjs/core/IframeClickInterceptor.cjs.map +1 -1
  16. package/dist/cjs/core/UrlStateManager.cjs +2 -3
  17. package/dist/cjs/core/getLocalEditorParentOrigin.cjs +32 -0
  18. package/dist/cjs/core/getLocalEditorParentOrigin.cjs.map +1 -0
  19. package/dist/cjs/core/globalManager.cjs +1 -2
  20. package/dist/cjs/core/index.cjs +10 -8
  21. package/dist/cjs/core/initEditorClient.cjs +8 -6
  22. package/dist/cjs/core/initEditorClient.cjs.map +1 -1
  23. package/dist/cjs/core/selectionClick.cjs +24 -0
  24. package/dist/cjs/core/selectionClick.cjs.map +1 -0
  25. package/dist/cjs/core/sharedWindowState.cjs +1 -2
  26. package/dist/cjs/index.cjs +13 -11
  27. package/dist/cjs/isEnabled.cjs +1 -2
  28. package/dist/cjs/messageKey.cjs +5 -2
  29. package/dist/cjs/messageKey.cjs.map +1 -1
  30. package/dist/esm/compareUrls.mjs +1 -2
  31. package/dist/esm/components/ContentSelector.mjs +69 -16
  32. package/dist/esm/components/ContentSelector.mjs.map +1 -1
  33. package/dist/esm/components/ContentSelectorWrapper.mjs +61 -4
  34. package/dist/esm/components/ContentSelectorWrapper.mjs.map +1 -1
  35. package/dist/esm/components/index.mjs +1 -1
  36. package/dist/esm/components/isInteractiveClickTarget.mjs +64 -0
  37. package/dist/esm/components/isInteractiveClickTarget.mjs.map +1 -0
  38. package/dist/esm/core/CrossFrameMessenger.mjs +1 -2
  39. package/dist/esm/core/CrossFrameStateManager.mjs +1 -2
  40. package/dist/esm/core/EditorStateManager.mjs +71 -12
  41. package/dist/esm/core/EditorStateManager.mjs.map +1 -1
  42. package/dist/esm/core/IframeClickInterceptor.mjs +16 -9
  43. package/dist/esm/core/IframeClickInterceptor.mjs.map +1 -1
  44. package/dist/esm/core/UrlStateManager.mjs +1 -2
  45. package/dist/esm/core/getLocalEditorParentOrigin.mjs +31 -0
  46. package/dist/esm/core/getLocalEditorParentOrigin.mjs.map +1 -0
  47. package/dist/esm/core/globalManager.mjs +1 -2
  48. package/dist/esm/core/index.mjs +4 -4
  49. package/dist/esm/core/initEditorClient.mjs +6 -4
  50. package/dist/esm/core/initEditorClient.mjs.map +1 -1
  51. package/dist/esm/core/selectionClick.mjs +22 -0
  52. package/dist/esm/core/selectionClick.mjs.map +1 -0
  53. package/dist/esm/core/sharedWindowState.mjs +1 -2
  54. package/dist/esm/index.mjs +3 -3
  55. package/dist/esm/isEnabled.mjs +1 -2
  56. package/dist/esm/messageKey.mjs +5 -2
  57. package/dist/esm/messageKey.mjs.map +1 -1
  58. package/dist/types/compareUrls.d.ts +0 -2
  59. package/dist/types/compareUrls.d.ts.map +1 -1
  60. package/dist/types/components/ContentSelector.d.ts +10 -4
  61. package/dist/types/components/ContentSelector.d.ts.map +1 -1
  62. package/dist/types/components/ContentSelectorWrapper.d.ts +5 -2
  63. package/dist/types/components/ContentSelectorWrapper.d.ts.map +1 -1
  64. package/dist/types/components/isInteractiveClickTarget.d.ts +14 -0
  65. package/dist/types/components/isInteractiveClickTarget.d.ts.map +1 -0
  66. package/dist/types/core/CrossFrameMessenger.d.ts +1 -2
  67. package/dist/types/core/CrossFrameMessenger.d.ts.map +1 -1
  68. package/dist/types/core/CrossFrameStateManager.d.ts +0 -2
  69. package/dist/types/core/CrossFrameStateManager.d.ts.map +1 -1
  70. package/dist/types/core/EditorStateManager.d.ts +34 -3
  71. package/dist/types/core/EditorStateManager.d.ts.map +1 -1
  72. package/dist/types/core/IframeClickInterceptor.d.ts +8 -4
  73. package/dist/types/core/IframeClickInterceptor.d.ts.map +1 -1
  74. package/dist/types/core/UrlStateManager.d.ts +0 -2
  75. package/dist/types/core/UrlStateManager.d.ts.map +1 -1
  76. package/dist/types/core/getLocalEditorParentOrigin.d.ts +11 -0
  77. package/dist/types/core/getLocalEditorParentOrigin.d.ts.map +1 -0
  78. package/dist/types/core/globalManager.d.ts +0 -2
  79. package/dist/types/core/globalManager.d.ts.map +1 -1
  80. package/dist/types/core/index.d.ts +4 -4
  81. package/dist/types/core/initEditorClient.d.ts +0 -2
  82. package/dist/types/core/initEditorClient.d.ts.map +1 -1
  83. package/dist/types/core/selectionClick.d.ts +15 -0
  84. package/dist/types/core/selectionClick.d.ts.map +1 -0
  85. package/dist/types/core/sharedWindowState.d.ts +1 -2
  86. package/dist/types/core/sharedWindowState.d.ts.map +1 -1
  87. package/dist/types/index.d.ts +3 -2
  88. package/dist/types/isEnabled.d.ts +0 -2
  89. package/dist/types/isEnabled.d.ts.map +1 -1
  90. package/dist/types/messageKey.d.ts +5 -3
  91. package/dist/types/messageKey.d.ts.map +1 -1
  92. package/package.json +8 -8
@@ -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,7 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_components_ContentSelectorWrapper = require('./ContentSelectorWrapper.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");
3
5
 
4
- //#region src/components/ContentSelector.ts
6
+ // src/components/ContentSelector.ts
5
7
  const DEFAULT_PRESS_DURATION = 250;
6
8
  const STYLES = `
7
9
  :host {
@@ -23,15 +25,49 @@ const STYLES = `
23
25
  .wrapper[data-active] {
24
26
  outline-color: inherit;
25
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
+ }
26
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
+ };
27
57
  const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
28
58
  /**
29
59
  * <intlayer-content-selector>
30
60
  *
31
61
  * A framework-agnostic web component that wraps content with Intlayer editor
32
- * selection UI (hover outline, long-press to select, click-outside to deselect).
62
+ * selection UI (hover outline, click to select, click-outside to deselect).
63
+ *
64
+ * Content is selected by:
65
+ * - a click, unless it lands on something the app handles (link, button,
66
+ * form control, clickable ancestor), which keeps its behavior
67
+ * - a long press, on any content
68
+ * - a ⌘ / Ctrl + click, on any content, cancelling the click's own action
33
69
  *
34
- * @fires intlayer:press - Fired after a long press (pressDuration ms). Bubbles.
70
+ * @fires intlayer:press - Fired when the content is selected. Bubbles.
35
71
  * @fires intlayer:hover - Fired on mouseenter. Bubbles.
36
72
  * @fires intlayer:unhover - Fired on mouseleave / mouseup. Bubbles.
37
73
  * @fires intlayer:click-outside - Fired when a click occurs outside the element. Bubbles.
@@ -73,9 +109,11 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
73
109
  wrapper.className = "wrapper";
74
110
  wrapper.setAttribute("role", "button");
75
111
  wrapper.setAttribute("tabindex", "0");
76
- wrapper.appendChild(document.createElement("slot"));
112
+ const slot = document.createElement("slot");
113
+ wrapper.appendChild(slot);
77
114
  shadow.appendChild(wrapper);
78
115
  this._wrapper = wrapper;
116
+ slot.addEventListener("slotchange", () => wrapper.toggleAttribute("data-text", isTextOnlyContent(slot)));
79
117
  wrapper.addEventListener("mousedown", () => this._handleMouseDown());
80
118
  wrapper.addEventListener("mouseup", () => this._handleMouseUpOrLeave());
81
119
  wrapper.addEventListener("mouseleave", () => this._handleMouseUpOrLeave());
@@ -94,17 +132,23 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
94
132
  }
95
133
  connectedCallback() {
96
134
  this._clickOutsideHandler = (e) => {
135
+ if (!this._isSelecting && !this._isSelectingState) return;
97
136
  if (!e.composedPath().includes(this)) {
137
+ this._clearPressTimer();
98
138
  this._isSelectingState = false;
99
- this._dispatch("intlayer:click-outside");
139
+ this._isSelecting = false;
140
+ this.removeAttribute("is-selecting");
141
+ this._dispatch("intlayer:click-outside", { originalEvent: e });
100
142
  this._updateActiveState();
101
143
  }
102
144
  };
103
145
  document.addEventListener("mousedown", this._clickOutsideHandler);
146
+ document.addEventListener("touchstart", this._clickOutsideHandler);
104
147
  }
105
148
  disconnectedCallback() {
106
149
  if (this._clickOutsideHandler) {
107
150
  document.removeEventListener("mousedown", this._clickOutsideHandler);
151
+ document.removeEventListener("touchstart", this._clickOutsideHandler);
108
152
  this._clickOutsideHandler = null;
109
153
  }
110
154
  this._clearPressTimer();
@@ -119,19 +163,22 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
119
163
  this._pressTimer = null;
120
164
  }
121
165
  }
122
- _dispatch(eventName) {
166
+ _dispatch(eventName, detail) {
123
167
  this.dispatchEvent(new CustomEvent(eventName, {
168
+ detail,
124
169
  bubbles: true,
125
170
  composed: true
126
171
  }));
127
172
  }
173
+ _select() {
174
+ this._clearPressTimer();
175
+ this._isSelectingState = true;
176
+ this._updateActiveState();
177
+ this._dispatch("intlayer:press");
178
+ }
128
179
  _handleMouseDown() {
129
180
  this._clearPressTimer();
130
- this._pressTimer = setTimeout(() => {
131
- this._isSelectingState = true;
132
- this._updateActiveState();
133
- this._dispatch("intlayer:press");
134
- }, this._pressDuration);
181
+ this._pressTimer = setTimeout(() => this._select(), this._pressDuration);
135
182
  }
136
183
  _handleMouseEnter() {
137
184
  this._isHovered = true;
@@ -146,11 +193,18 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
146
193
  this._clearPressTimer();
147
194
  this._updateActiveState();
148
195
  }
149
- _handleClick(e) {
150
- if (this._isSelecting || this._isSelectingState) {
151
- e.preventDefault();
152
- e.stopPropagation();
196
+ _handleClick(event) {
197
+ if (require_core_selectionClick.isSelectionClick(event)) return;
198
+ const isModifierClick = event.metaKey || event.ctrlKey;
199
+ if (this._isSelecting || this._isSelectingState || isModifierClick) {
200
+ event.preventDefault();
201
+ event.stopPropagation();
202
+ if (isModifierClick) this._select();
203
+ return;
153
204
  }
205
+ if (require_components_isInteractiveClickTarget.isInteractiveClickTarget(event)) return;
206
+ require_core_selectionClick.markSelectionClick(event);
207
+ this._select();
154
208
  }
155
209
  _handleBlur() {
156
210
  this._isSelectingState = false;
@@ -168,7 +222,6 @@ const defineIntlayerElements = () => {
168
222
  require_components_ContentSelectorWrapper.defineIntlayerContentSelectorWrapper();
169
223
  };
170
224
 
171
- //#endregion
172
225
  exports.IntlayerContentSelectorElement = IntlayerContentSelectorElement;
173
226
  exports.defineIntlayerElements = defineIntlayerElements;
174
227
  //# sourceMappingURL=ContentSelector.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentSelector.cjs","names":[],"sources":["../../../src/components/ContentSelector.ts"],"sourcesContent":["import { defineIntlayerContentSelectorWrapper } from './ContentSelectorWrapper';\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, long-press to select, click-outside to deselect).\n *\n * @fires intlayer:press - Fired after a long press (pressDuration ms). 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 _handleMouseDown(): void {\n this._clearPressTimer();\n this._pressTimer = setTimeout(() => {\n this._isSelectingState = true;\n this._updateActiveState();\n this._dispatch('intlayer:press');\n }, 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(e: MouseEvent): void {\n if (this._isSelecting || this._isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\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":";;;;AAEA,MAAM,yBAAyB;AAE/B,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;AAsBf,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;AAgBd,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,CAAC;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,AAAQ,UAAU,WAAyB;EACzC,KAAK,cACH,IAAI,YAAY,WAAW;GAAE,SAAS;GAAM,UAAU;EAAK,CAAC,CAC9D;CACF;CAEA,AAAQ,mBAAyB;EAC/B,KAAK,iBAAiB;EACtB,KAAK,cAAc,iBAAiB;GAClC,KAAK,oBAAoB;GACzB,KAAK,mBAAmB;GACxB,KAAK,UAAU,gBAAgB;EACjC,GAAG,KAAK,cAAc;CACxB;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,GAAqB;EACxC,IAAI,KAAK,gBAAgB,KAAK,mBAAmB;GAC/C,EAAE,eAAe;GACjB,EAAE,gBAAgB;EACpB;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,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;CAC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,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.
@@ -37,6 +37,34 @@ const getPendingRevealOffset = (element) => {
37
37
  }
38
38
  return offset;
39
39
  };
40
+ /**
41
+ * Reveal callbacks of the wrappers selected by the current focus change, keyed
42
+ * by wrapper. A focus matches every wrapper under its key path (list items,
43
+ * content rendered twice…), so they are batched and only the first is revealed.
44
+ */
45
+ const pendingReveals = /* @__PURE__ */ new Map();
46
+ /** Whether `element` comes after `reference` in document order. */
47
+ const isAfterInDocument = (element, reference) => {
48
+ const position = reference.compareDocumentPosition(element);
49
+ if (position & Node.DOCUMENT_POSITION_DISCONNECTED) return true;
50
+ return Boolean(position & Node.DOCUMENT_POSITION_FOLLOWING);
51
+ };
52
+ /** Reveals the first wrapper, in document order, among the pending ones. */
53
+ const flushPendingReveals = () => {
54
+ let firstWrapper = null;
55
+ for (const wrapper of pendingReveals.keys()) {
56
+ if (!wrapper.isConnected) continue;
57
+ if (!firstWrapper || !isAfterInDocument(wrapper, firstWrapper)) firstWrapper = wrapper;
58
+ }
59
+ const reveal = firstWrapper ? pendingReveals.get(firstWrapper) : void 0;
60
+ pendingReveals.clear();
61
+ reveal?.();
62
+ };
63
+ /** Queues a wrapper to reveal once every wrapper handled the focus change. */
64
+ const scheduleReveal = (wrapper, reveal) => {
65
+ if (pendingReveals.size === 0) queueMicrotask(flushPendingReveals);
66
+ pendingReveals.set(wrapper, reveal);
67
+ };
40
68
  const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
41
69
  /**
42
70
  * <intlayer-content-selector-wrapper>
@@ -67,6 +95,12 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
67
95
  static get observedAttributes() {
68
96
  return ["key-path", "dictionary-key"];
69
97
  }
98
+ get dictionaryKey() {
99
+ return this._dictionaryKey;
100
+ }
101
+ get filteredKeyPath() {
102
+ return this._getFilteredKeyPath();
103
+ }
70
104
  constructor() {
71
105
  super();
72
106
  const shadow = this.attachShadow({ mode: "open" });
@@ -126,6 +160,7 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
126
160
  _updateIsSelected(focusedContent) {
127
161
  if (!focusedContent) {
128
162
  this._isSelected = false;
163
+ pendingReveals.delete(this);
129
164
  this._updateSelectorAttr();
130
165
  return;
131
166
  }
@@ -133,7 +168,8 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
133
168
  const wasSelected = this._isSelected;
134
169
  this._isSelected = focusedContent.dictionaryKey === this._dictionaryKey && (focusedContent.keyPath?.length ?? 0) > 0 && (0, _intlayer_core_utils.isSameKeyPath)(focusedContent.keyPath ?? [], keyPath);
135
170
  this._updateSelectorAttr();
136
- if (this._isSelected && !wasSelected) this._scrollIntoViewIfNeeded();
171
+ if (this._isSelected && !wasSelected) scheduleReveal(this, () => this._scrollIntoViewIfNeeded());
172
+ else if (!this._isSelected) pendingReveals.delete(this);
137
173
  }
138
174
  /**
139
175
  * Scrolls the selected content to 30vh, unless it is already fully visible
@@ -224,6 +260,27 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
224
260
  e.stopPropagation();
225
261
  require_core_globalManager.getGlobalEditorManager()?.messenger.send(`${"INTLAYER_HOVERED_CONTENT_CHANGED"}/post`, null);
226
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
+ }
227
284
  _render() {
228
285
  const useWrapper = this._isInIframe && this._editorEnabled;
229
286
  const editedValue = this._editedValue;
@@ -249,6 +306,7 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
249
306
  selector.addEventListener("intlayer:press", (e) => this._handlePress(e));
250
307
  selector.addEventListener("intlayer:hover", (e) => this._handleHover(e));
251
308
  selector.addEventListener("intlayer:unhover", (e) => this._handleUnhover(e));
309
+ selector.addEventListener("intlayer:click-outside", (e) => this._handleClickOutside(e));
252
310
  if (state === "wrapped-text") selector.appendChild(document.createTextNode(String(this._editedValue)));
253
311
  else selector.appendChild(document.createElement("slot"));
254
312
  shadow.appendChild(selector);
@@ -261,7 +319,6 @@ const defineIntlayerContentSelectorWrapper = () => {
261
319
  if (!customElements.get("intlayer-content-selector-wrapper")) customElements.define("intlayer-content-selector-wrapper", IntlayerContentSelectorWrapperElement);
262
320
  };
263
321
 
264
- //#endregion
265
322
  exports.IntlayerContentSelectorWrapperElement = IntlayerContentSelectorWrapperElement;
266
323
  exports.defineIntlayerContentSelectorWrapper = defineIntlayerContentSelectorWrapper;
267
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\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 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 this._scrollIntoViewIfNeeded();\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":";;;;;;;;;;;;;AAsBA,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,QAAQ;EAEvC,IAAI,OAAO,WAAW,MAAM,OAAO,IAAI,GAAG,UAAU,cAAc,KAAK;CACzE;CAEA,OAAO;AACT;AAEA,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;AAgBd,IAAa,wCAAb,cAA2D,aAAa;CACtE,AAAQ,eAAe;CACvB,AAAQ,iBAAiB;CACzB,AAAQ,iBAAiB;CACzB,AA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,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';\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 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":";;;;;;;;;;;;;AAsBA,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,QAAQ;EAEvC,IAAI,OAAO,WAAW,MAAM,OAAO,IAAI,GAAG,UAAU,cAAc,KAAK;CACzE;CAEA,OAAO;AACT;;;;;;AAOA,MAAM,iCAAiB,IAAI,IAAyB;;AAGpD,MAAM,qBAAqB,SAAkB,cAAgC;CAC3E,MAAM,WAAW,UAAU,wBAAwB,OAAO;CAG1D,IAAI,WAAW,KAA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,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;
@@ -0,0 +1,65 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ // src/components/isInteractiveClickTarget.ts
3
+ /** Elements whose click already does something in the application. */
4
+ const INTERACTIVE_ELEMENT_SELECTOR = [
5
+ "a[href]",
6
+ "button",
7
+ "input",
8
+ "select",
9
+ "textarea",
10
+ "label",
11
+ "summary",
12
+ "option",
13
+ "video[controls]",
14
+ "audio[controls]",
15
+ "[contenteditable=\"\"]",
16
+ "[contenteditable=\"true\"]",
17
+ "[onclick]",
18
+ ...[
19
+ "button",
20
+ "link",
21
+ "checkbox",
22
+ "radio",
23
+ "switch",
24
+ "tab",
25
+ "menuitem",
26
+ "menuitemcheckbox",
27
+ "menuitemradio",
28
+ "option",
29
+ "combobox",
30
+ "slider",
31
+ "spinbutton",
32
+ "textbox"
33
+ ].map((role) => `[role="${role}"]`)
34
+ ].join(",");
35
+ /** Tag prefix of the editor's own elements, which are never app controls. */
36
+ const EDITOR_ELEMENT_PREFIX = "intlayer-";
37
+ const isEditorElement = (element) => {
38
+ if (element.localName.startsWith(EDITOR_ELEMENT_PREFIX)) return true;
39
+ const root = element.getRootNode();
40
+ return root instanceof ShadowRoot && root.host.localName.startsWith(EDITOR_ELEMENT_PREFIX);
41
+ };
42
+ /**
43
+ * Whether a click on editable content lands on something the application
44
+ * handles itself: a link, a button, a form control, or an ancestor rendered as
45
+ * clickable (`cursor: pointer`, the mark of delegated handlers such as React
46
+ * `onClick`). Such clicks keep their behavior; the content is then selected
47
+ * with a long press or a modifier click instead.
48
+ *
49
+ * The cursor is only read on ancestors of the editor elements: content inside
50
+ * them inherits the selector's own pointer cursor.
51
+ *
52
+ * @param event - Click event, read through its composed path
53
+ */
54
+ const isInteractiveClickTarget = (event) => {
55
+ const elements = event.composedPath().filter((node) => node instanceof Element);
56
+ const outermostEditorIndex = elements.findLastIndex(isEditorElement);
57
+ return elements.some((element, index) => {
58
+ if (isEditorElement(element)) return false;
59
+ if (element.matches(INTERACTIVE_ELEMENT_SELECTOR)) return true;
60
+ return index > outermostEditorIndex && getComputedStyle(element).cursor === "pointer";
61
+ });
62
+ };
63
+
64
+ exports.isInteractiveClickTarget = isInteractiveClickTarget;
65
+ //# sourceMappingURL=isInteractiveClickTarget.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isInteractiveClickTarget.cjs","names":[],"sources":["../../../src/components/isInteractiveClickTarget.ts"],"sourcesContent":["/** Elements whose click already does something in the application. */\nconst INTERACTIVE_ELEMENT_SELECTOR = [\n 'a[href]',\n 'button',\n 'input',\n 'select',\n 'textarea',\n 'label',\n 'summary',\n 'option',\n 'video[controls]',\n 'audio[controls]',\n '[contenteditable=\"\"]',\n '[contenteditable=\"true\"]',\n '[onclick]',\n ...[\n 'button',\n 'link',\n 'checkbox',\n 'radio',\n 'switch',\n 'tab',\n 'menuitem',\n 'menuitemcheckbox',\n 'menuitemradio',\n 'option',\n 'combobox',\n 'slider',\n 'spinbutton',\n 'textbox',\n ].map((role) => `[role=\"${role}\"]`),\n].join(',');\n\n/** Tag prefix of the editor's own elements, which are never app controls. */\nconst EDITOR_ELEMENT_PREFIX = 'intlayer-';\n\nconst isEditorElement = (element: Element): boolean => {\n if (element.localName.startsWith(EDITOR_ELEMENT_PREFIX)) return true;\n\n const root = element.getRootNode();\n\n // Internals of the editor elements (their `role=\"button\"` wrapper, slots…)\n return (\n root instanceof ShadowRoot &&\n root.host.localName.startsWith(EDITOR_ELEMENT_PREFIX)\n );\n};\n\n/**\n * Whether a click on editable content lands on something the application\n * handles itself: a link, a button, a form control, or an ancestor rendered as\n * clickable (`cursor: pointer`, the mark of delegated handlers such as React\n * `onClick`). Such clicks keep their behavior; the content is then selected\n * with a long press or a modifier click instead.\n *\n * The cursor is only read on ancestors of the editor elements: content inside\n * them inherits the selector's own pointer cursor.\n *\n * @param event - Click event, read through its composed path\n */\nexport const isInteractiveClickTarget = (event: Event): boolean => {\n const elements = event\n .composedPath()\n .filter((node): node is Element => node instanceof Element);\n\n const outermostEditorIndex = elements.findLastIndex(isEditorElement);\n\n return elements.some((element, index) => {\n if (isEditorElement(element)) return false;\n if (element.matches(INTERACTIVE_ELEMENT_SELECTOR)) return true;\n\n const isAncestorOfEditorElement = index > outermostEditorIndex;\n\n return (\n isAncestorOfEditorElement &&\n getComputedStyle(element).cursor === 'pointer'\n );\n });\n};\n"],"mappings":";;;AACA,MAAM,+BAA+B;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,SAAS,UAAU,KAAK,GAAG;AACpC,CAAC,CAAC,KAAK,GAAG;;AAGV,MAAM,wBAAwB;AAE9B,MAAM,mBAAmB,YAA8B;CACrD,IAAI,QAAQ,UAAU,WAAW,qBAAqB,GAAG,OAAO;CAEhE,MAAM,OAAO,QAAQ,YAAY;CAGjC,OACE,gBAAgB,cAChB,KAAK,KAAK,UAAU,WAAW,qBAAqB;AAExD;;;;;;;;;;;;;AAcA,MAAa,4BAA4B,UAA0B;CACjE,MAAM,WAAW,MACd,aAAa,CAAC,CACd,QAAQ,SAA0B,gBAAgB,OAAO;CAE5D,MAAM,uBAAuB,SAAS,cAAc,eAAe;CAEnE,OAAO,SAAS,MAAM,SAAS,UAAU;EACvC,IAAI,gBAAgB,OAAO,GAAG,OAAO;EACrC,IAAI,QAAQ,QAAQ,4BAA4B,GAAG,OAAO;EAI1D,OAFkC,QAAQ,wBAIxC,iBAAiB,OAAO,CAAC,CAAC,WAAW;CAEzC,CAAC;AACH"}
@@ -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