@intlayer/editor 9.7.2 → 9.8.0-canary.0

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.
@@ -12,6 +12,27 @@ _intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
12
12
  * keeping it clear of fixed navbars.
13
13
  */
14
14
  const SCROLL_TOP_OFFSET_RATIO = .3;
15
+ const PRESS_END_EVENTS = [
16
+ "mouseup",
17
+ "touchend",
18
+ "touchcancel"
19
+ ];
20
+ /**
21
+ * Clears the focus once a press on other content ends, unless that press
22
+ * selected it meanwhile (long press, or the click following the release).
23
+ * Clearing on press start would leave nothing focused for the whole press,
24
+ * so the editor UI would drop its panel until the new selection lands.
25
+ */
26
+ const clearFocusAfterPress = (manager) => {
27
+ const focusedContentAtPress = manager.focusedContent.value;
28
+ const handlePressEnd = () => {
29
+ for (const eventName of PRESS_END_EVENTS) document.removeEventListener(eventName, handlePressEnd, true);
30
+ setTimeout(() => {
31
+ if (manager.focusedContent.value === focusedContentAtPress) manager.focusedContent.set(null);
32
+ });
33
+ };
34
+ for (const eventName of PRESS_END_EVENTS) document.addEventListener(eventName, handlePressEnd, true);
35
+ };
15
36
  /** Parent in the flattened tree, crossing shadow roots up to their host. */
16
37
  const getComposedParent = (element) => element.parentElement ?? element.getRootNode().host ?? null;
17
38
  /** Vertical translation applied to an element, by `transform` or `translate`. */
@@ -264,21 +285,17 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
264
285
  e.stopPropagation();
265
286
  if (e.target !== this._selector) return;
266
287
  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
288
  const manager = require_core_globalManager.getGlobalEditorManager();
281
289
  if (!manager) return;
290
+ const pressedWrappers = (e.detail?.originalEvent?.composedPath() ?? []).filter((target) => target instanceof HTMLElement && target.tagName === "INTLAYER-CONTENT-SELECTOR-WRAPPER");
291
+ if (pressedWrappers.some((wrapper) => wrapper.dictionaryKey === this._dictionaryKey && (0, _intlayer_core_utils.isSameKeyPath)(wrapper.filteredKeyPath, this._getFilteredKeyPath()))) {
292
+ this._selector?.setAttribute("is-selecting", "");
293
+ return;
294
+ }
295
+ if (pressedWrappers.length > 0) {
296
+ clearFocusAfterPress(manager);
297
+ return;
298
+ }
282
299
  manager.focusedContent.set(null);
283
300
  }
284
301
  _render() {
@@ -1 +1 @@
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,QAAQ;EAEvC,IAAI,OAAO,WAAW,MAAM,OAAO,IAAI,GAAG,UAAU,cAAc,KAAK;CACzE;CAEA,OAAO;AACT;;;;;;AAOA,MAAM,iCAAiB,IAAI,IAAyB;;AAG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Z,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
+ {"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\nconst PRESS_END_EVENTS = ['mouseup', 'touchend', 'touchcancel'] as const;\n\n/**\n * Clears the focus once a press on other content ends, unless that press\n * selected it meanwhile (long press, or the click following the release).\n * Clearing on press start would leave nothing focused for the whole press,\n * so the editor UI would drop its panel until the new selection lands.\n */\nconst clearFocusAfterPress = (manager: EditorStateManager): void => {\n const focusedContentAtPress = manager.focusedContent.value;\n\n const handlePressEnd = () => {\n for (const eventName of PRESS_END_EVENTS) {\n document.removeEventListener(eventName, handlePressEnd, true);\n }\n\n // Runs after the click dispatched with the release\n setTimeout(() => {\n if (manager.focusedContent.value === focusedContentAtPress) {\n manager.focusedContent.set(null);\n }\n });\n };\n\n for (const eventName of PRESS_END_EVENTS) {\n document.addEventListener(eventName, handlePressEnd, true);\n }\n};\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 manager = getGlobalEditorManager();\n if (!manager) return;\n\n const customEvent = e as CustomEvent<{ originalEvent?: Event }>;\n const pressedWrappers = (\n customEvent.detail?.originalEvent?.composedPath() ?? []\n ).filter(\n (target): target is IntlayerContentSelectorWrapperElement =>\n target instanceof HTMLElement &&\n target.tagName === 'INTLAYER-CONTENT-SELECTOR-WRAPPER'\n );\n\n const isClickedOnSameContent = pressedWrappers.some(\n (wrapper) =>\n wrapper.dictionaryKey === this._dictionaryKey &&\n isSameKeyPath(wrapper.filteredKeyPath, this._getFilteredKeyPath())\n );\n\n if (isClickedOnSameContent) {\n this._selector?.setAttribute('is-selecting', '');\n return;\n }\n\n if (pressedWrappers.length > 0) {\n clearFocusAfterPress(manager);\n return;\n }\n\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 IntlayerContent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a,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"}
@@ -9,6 +9,27 @@ import * as NodeTypes from "@intlayer/types/nodeType";
9
9
  * keeping it clear of fixed navbars.
10
10
  */
11
11
  const SCROLL_TOP_OFFSET_RATIO = .3;
12
+ const PRESS_END_EVENTS = [
13
+ "mouseup",
14
+ "touchend",
15
+ "touchcancel"
16
+ ];
17
+ /**
18
+ * Clears the focus once a press on other content ends, unless that press
19
+ * selected it meanwhile (long press, or the click following the release).
20
+ * Clearing on press start would leave nothing focused for the whole press,
21
+ * so the editor UI would drop its panel until the new selection lands.
22
+ */
23
+ const clearFocusAfterPress = (manager) => {
24
+ const focusedContentAtPress = manager.focusedContent.value;
25
+ const handlePressEnd = () => {
26
+ for (const eventName of PRESS_END_EVENTS) document.removeEventListener(eventName, handlePressEnd, true);
27
+ setTimeout(() => {
28
+ if (manager.focusedContent.value === focusedContentAtPress) manager.focusedContent.set(null);
29
+ });
30
+ };
31
+ for (const eventName of PRESS_END_EVENTS) document.addEventListener(eventName, handlePressEnd, true);
32
+ };
12
33
  /** Parent in the flattened tree, crossing shadow roots up to their host. */
13
34
  const getComposedParent = (element) => element.parentElement ?? element.getRootNode().host ?? null;
14
35
  /** Vertical translation applied to an element, by `transform` or `translate`. */
@@ -261,21 +282,17 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
261
282
  e.stopPropagation();
262
283
  if (e.target !== this._selector) return;
263
284
  if (!this._isSelected) return;
264
- const originalEvent = e.detail?.originalEvent;
265
- if (originalEvent) {
266
- if (originalEvent.composedPath().some((target) => {
267
- if (target instanceof HTMLElement && target.tagName === "INTLAYER-CONTENT-SELECTOR-WRAPPER") {
268
- const wrapper = target;
269
- return wrapper.dictionaryKey === this._dictionaryKey && isSameKeyPath(wrapper.filteredKeyPath, this._getFilteredKeyPath());
270
- }
271
- return false;
272
- })) {
273
- this._selector?.setAttribute("is-selecting", "");
274
- return;
275
- }
276
- }
277
285
  const manager = getGlobalEditorManager();
278
286
  if (!manager) return;
287
+ const pressedWrappers = (e.detail?.originalEvent?.composedPath() ?? []).filter((target) => target instanceof HTMLElement && target.tagName === "INTLAYER-CONTENT-SELECTOR-WRAPPER");
288
+ if (pressedWrappers.some((wrapper) => wrapper.dictionaryKey === this._dictionaryKey && isSameKeyPath(wrapper.filteredKeyPath, this._getFilteredKeyPath()))) {
289
+ this._selector?.setAttribute("is-selecting", "");
290
+ return;
291
+ }
292
+ if (pressedWrappers.length > 0) {
293
+ clearFocusAfterPress(manager);
294
+ return;
295
+ }
279
296
  manager.focusedContent.set(null);
280
297
  }
281
298
  _render() {
@@ -1 +1 @@
1
- {"version":3,"file":"ContentSelectorWrapper.mjs","names":["node","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,O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,YAAY,KAAK,WAAW;GAC3C,KAAK,oBAAoB;GACzB,IACE,aAAa,kBACb,KAAK,UAAU,YAAY,aAAa,KAAK,WAE7C,AAAC,KAAK,UAAU,WAAoB,OAAO,OAAO,WAAW;EAEjE;CACF;CAEA,AAAQ,gBAAgB,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
+ {"version":3,"file":"ContentSelectorWrapper.mjs","names":["node","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\nconst PRESS_END_EVENTS = ['mouseup', 'touchend', 'touchcancel'] as const;\n\n/**\n * Clears the focus once a press on other content ends, unless that press\n * selected it meanwhile (long press, or the click following the release).\n * Clearing on press start would leave nothing focused for the whole press,\n * so the editor UI would drop its panel until the new selection lands.\n */\nconst clearFocusAfterPress = (manager: EditorStateManager): void => {\n const focusedContentAtPress = manager.focusedContent.value;\n\n const handlePressEnd = () => {\n for (const eventName of PRESS_END_EVENTS) {\n document.removeEventListener(eventName, handlePressEnd, true);\n }\n\n // Runs after the click dispatched with the release\n setTimeout(() => {\n if (manager.focusedContent.value === focusedContentAtPress) {\n manager.focusedContent.set(null);\n }\n });\n };\n\n for (const eventName of PRESS_END_EVENTS) {\n document.addEventListener(eventName, handlePressEnd, true);\n }\n};\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 manager = getGlobalEditorManager();\n if (!manager) return;\n\n const customEvent = e as CustomEvent<{ originalEvent?: Event }>;\n const pressedWrappers = (\n customEvent.detail?.originalEvent?.composedPath() ?? []\n ).filter(\n (target): target is IntlayerContentSelectorWrapperElement =>\n target instanceof HTMLElement &&\n target.tagName === 'INTLAYER-CONTENT-SELECTOR-WRAPPER'\n );\n\n const isClickedOnSameContent = pressedWrappers.some(\n (wrapper) =>\n wrapper.dictionaryKey === this._dictionaryKey &&\n isSameKeyPath(wrapper.filteredKeyPath, this._getFilteredKeyPath())\n );\n\n if (isClickedOnSameContent) {\n this._selector?.setAttribute('is-selecting', '');\n return;\n }\n\n if (pressedWrappers.length > 0) {\n clearFocusAfterPress(manager);\n return;\n }\n\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;AAEhC,MAAM,mBAAmB;CAAC;CAAW;CAAY;AAAa;;;;;;;AAQ9D,MAAM,wBAAwB,YAAsC;CAClE,MAAM,wBAAwB,QAAQ,eAAe;CAErD,MAAM,uBAAuB;EAC3B,KAAK,MAAM,aAAa,kBACtB,SAAS,oBAAoB,WAAW,gBAAgB,IAAI;EAI9D,iBAAiB;GACf,IAAI,QAAQ,eAAe,UAAU,uBACnC,QAAQ,eAAe,IAAI,IAAI;EAEnC,CAAC;CACH;CAEA,KAAK,MAAM,aAAa,kBACtB,SAAS,iBAAiB,WAAW,gBAAgB,IAAI;AAE7D;;AAGA,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,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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 +1 @@
1
- {"version":3,"file":"ContentSelectorWrapper.d.ts","names":[],"sources":["../../../src/components/ContentSelectorWrapper.ts"],"mappings":";cA6GM;;;;;;;;;;;;;;;;;;qBAmBO,8CAA8C;UACjD;UACA;UACA;UACA;UACA;UACA;UAEA;UACA;UAEA;;UAEA;aAEG;MAIP;MAIA,mBAAmB;EAIvB;EAQA,yBACE,cACA,0BACA;EAYF;EAQA;UAOQ;UAQA;UAMA;UAkDA;;;;;UA6BA;;;;;UA6BA;UAWA;UASA;UAoBA;UA8BA;UAWA;UAWA;UAQA;UAiCA;UA+BA;;qBAqCG"}
1
+ {"version":3,"file":"ContentSelectorWrapper.d.ts","names":[],"sources":["../../../src/components/ContentSelectorWrapper.ts"],"mappings":";cA0IM;;;;;;;;;;;;;;;;;;qBAmBO,8CAA8C;UACjD;UACA;UACA;UACA;UACA;UACA;UAEA;UACA;UAEA;;UAEA;aAEG;MAIP;MAIA,mBAAmB;EAIvB;EAQA,yBACE,cACA,0BACA;EAYF;EAQA;UAOQ;UAQA;UAMA;UAkDA;;;;;UA6BA;;;;;UA6BA;UAWA;UASA;UAoBA;UA8BA;UAWA;UAWA;UAQA;UAoCA;UA+BA;;qBAqCG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/editor",
3
- "version": "9.7.2",
3
+ "version": "9.8.0-canary.0",
4
4
  "private": false,
5
5
  "description": "Provides the utilities to interface the application with the Intlayer editor and manipulate dictionaries",
6
6
  "keywords": [
@@ -76,10 +76,10 @@
76
76
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
77
77
  },
78
78
  "dependencies": {
79
- "@intlayer/config": "9.7.2",
80
- "@intlayer/core": "9.7.2",
81
- "@intlayer/dictionaries-entry": "9.7.2",
82
- "@intlayer/types": "9.7.2"
79
+ "@intlayer/config": "9.8.0-canary.0",
80
+ "@intlayer/core": "9.8.0-canary.0",
81
+ "@intlayer/dictionaries-entry": "9.8.0-canary.0",
82
+ "@intlayer/types": "9.8.0-canary.0"
83
83
  },
84
84
  "devDependencies": {
85
85
  "@types/node": "^26",