@intlayer/editor 8.9.7 → 8.10.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.
Files changed (67) hide show
  1. package/README.md +14 -0
  2. package/dist/cjs/compareUrls.cjs.map +1 -1
  3. package/dist/cjs/components/ContentSelector.cjs.map +1 -1
  4. package/dist/cjs/components/ContentSelectorWrapper.cjs.map +1 -1
  5. package/dist/cjs/components/EditedContent.cjs.map +1 -1
  6. package/dist/cjs/components/IntlayerEditor.cjs.map +1 -1
  7. package/dist/cjs/core/CrossFrameMessenger.cjs.map +1 -1
  8. package/dist/cjs/core/CrossFrameStateManager.cjs.map +1 -1
  9. package/dist/cjs/core/EditorStateManager.cjs +115 -0
  10. package/dist/cjs/core/EditorStateManager.cjs.map +1 -1
  11. package/dist/cjs/core/IframeClickInterceptor.cjs.map +1 -1
  12. package/dist/cjs/core/UrlStateManager.cjs.map +1 -1
  13. package/dist/cjs/core/editedContentBus.cjs +37 -0
  14. package/dist/cjs/core/editedContentBus.cjs.map +1 -0
  15. package/dist/cjs/core/focusedContentBus.cjs +43 -0
  16. package/dist/cjs/core/focusedContentBus.cjs.map +1 -0
  17. package/dist/cjs/core/globalManager.cjs.map +1 -1
  18. package/dist/cjs/core/index.cjs +9 -1
  19. package/dist/cjs/core/initEditorClient.cjs.map +1 -1
  20. package/dist/cjs/index.cjs +9 -1
  21. package/dist/cjs/mergeIframeClick.cjs.map +1 -1
  22. package/dist/cjs/messageKey.cjs +2 -0
  23. package/dist/cjs/messageKey.cjs.map +1 -1
  24. package/dist/esm/compareUrls.mjs.map +1 -1
  25. package/dist/esm/components/ContentSelector.mjs.map +1 -1
  26. package/dist/esm/components/ContentSelectorWrapper.mjs.map +1 -1
  27. package/dist/esm/components/EditedContent.mjs.map +1 -1
  28. package/dist/esm/components/IntlayerEditor.mjs.map +1 -1
  29. package/dist/esm/core/CrossFrameMessenger.mjs.map +1 -1
  30. package/dist/esm/core/CrossFrameStateManager.mjs.map +1 -1
  31. package/dist/esm/core/EditorStateManager.mjs +115 -0
  32. package/dist/esm/core/EditorStateManager.mjs.map +1 -1
  33. package/dist/esm/core/IframeClickInterceptor.mjs.map +1 -1
  34. package/dist/esm/core/UrlStateManager.mjs.map +1 -1
  35. package/dist/esm/core/editedContentBus.mjs +33 -0
  36. package/dist/esm/core/editedContentBus.mjs.map +1 -0
  37. package/dist/esm/core/focusedContentBus.mjs +39 -0
  38. package/dist/esm/core/focusedContentBus.mjs.map +1 -0
  39. package/dist/esm/core/globalManager.mjs.map +1 -1
  40. package/dist/esm/core/index.mjs +3 -1
  41. package/dist/esm/core/initEditorClient.mjs.map +1 -1
  42. package/dist/esm/index.mjs +3 -1
  43. package/dist/esm/mergeIframeClick.mjs.map +1 -1
  44. package/dist/esm/messageKey.mjs +2 -0
  45. package/dist/esm/messageKey.mjs.map +1 -1
  46. package/dist/types/compareUrls.d.ts.map +1 -1
  47. package/dist/types/components/ContentSelector.d.ts.map +1 -1
  48. package/dist/types/components/ContentSelectorWrapper.d.ts.map +1 -1
  49. package/dist/types/components/EditedContent.d.ts.map +1 -1
  50. package/dist/types/core/CrossFrameMessenger.d.ts.map +1 -1
  51. package/dist/types/core/CrossFrameStateManager.d.ts.map +1 -1
  52. package/dist/types/core/EditorStateManager.d.ts +17 -0
  53. package/dist/types/core/EditorStateManager.d.ts.map +1 -1
  54. package/dist/types/core/IframeClickInterceptor.d.ts.map +1 -1
  55. package/dist/types/core/UrlStateManager.d.ts.map +1 -1
  56. package/dist/types/core/editedContentBus.d.ts +9 -0
  57. package/dist/types/core/editedContentBus.d.ts.map +1 -0
  58. package/dist/types/core/focusedContentBus.d.ts +9 -0
  59. package/dist/types/core/focusedContentBus.d.ts.map +1 -0
  60. package/dist/types/core/globalManager.d.ts.map +1 -1
  61. package/dist/types/core/index.d.ts +3 -1
  62. package/dist/types/core/initEditorClient.d.ts.map +1 -1
  63. package/dist/types/index.d.ts +3 -1
  64. package/dist/types/mergeIframeClick.d.ts.map +1 -1
  65. package/dist/types/messageKey.d.ts +3 -1
  66. package/dist/types/messageKey.d.ts.map +1 -1
  67. package/package.json +6 -6
package/README.md CHANGED
@@ -67,6 +67,7 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
67
67
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/mcp.png?raw=true" alt="Feature" width="700"> | **MCP Server Integration**<br><br>Provides an MCP (Model Context Protocol) server for IDE automation, enabling seamless content management and i18n workflows directly within your development environment. <br><br> - [MCP Server](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/mcp_server.md) |
68
68
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/vscode_extension.png?raw=true" alt="Feature" width="700"> | **VSCode Extension**<br><br>Intlayer provides a VSCode extension to help you manage your content and translations, building your dictionaries, translating your content, and more. <br><br> - [VSCode Extension](https://intlayer.org/doc/vs-code-extension) |
69
69
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/interoperability.png?raw=true" alt="Feature" width="700"> | **Interoperability**<br><br>Allow interoperability with react-i18next, next-i18next, next-intl, react-intl, vue-i18n. <br><br> - [Intlayer and react-intl](https://intlayer.org/blog/intlayer-with-react-intl) <br> - [Intlayer and next-intl](https://intlayer.org/blog/intlayer-with-next-intl) <br> - [Intlayer and next-i18next](https://intlayer.org/blog/intlayer-with-next-i18next) <br> - [Intlayer and vue-i18n](https://intlayer.org/blog/intlayer-with-vue-i18n) |
70
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/benchmark.png?raw=true" alt="Feature" width="700"> | **Performances & Benchmark**<br><br>Uses advanced tree-shaking and dynamic loading to boost performances and keep the solution as light as possible. <br><br> - [Performances & Benchmark](https://intlayer.org/doc/benchmark) |
70
71
 
71
72
  ---
72
73
 
@@ -249,6 +250,19 @@ Explore our comprehensive documentation to get started with Intlayer and learn h
249
250
  </ul>
250
251
  </details>
251
252
 
253
+ ## Multilingual content management system
254
+
255
+ More than an i18n library, Intlayer is a complete **multilingual content management system**. A full CMS is available for free at [app.intlayer.org](https://app.intlayer.org).
256
+
257
+ Intlayer connects **developers**, **copywriters**, and **AI agents** in one workflow for creating and maintaining multilingual websites effortlessly.Intlayer replaces the following stack in a single solution:
258
+
259
+ - i18n solutions (e.g. `i18next`, `next-intl`, `vue-i18n`)
260
+ - TMSs (Translation Management Systems) (e.g. Crowdin, Phrase, Lokalise)
261
+ - Feature flags
262
+ - Headless CMSs (e.g. Contentful, Strapi, Sanity)
263
+
264
+ ![CMS Preview](https://github.com/aymericzip/intlayer/blob/main/docs/assets/CMS.png?raw=true)
265
+
252
266
  ## 🌐 Readme in other languages
253
267
 
254
268
  <p align="center">
@@ -1 +1 @@
1
- {"version":3,"file":"compareUrls.cjs","names":[],"sources":["../../src/compareUrls.ts"],"sourcesContent":["/**\n * Compare two URLs for equality.\n * This function is used to determine if a message originates from the same origin.\n *\n * ```js\n * // Example usage\n * console.log(compareUrls(\"http://localhost:5173/\", \"http://localhost:5173\")); // true\n * console.log(compareUrls(\"http://localhost:5173\", \"http://localhost:5173?myParam=true\")); // true\n * console.log(compareUrls(\"http://localhost:5173/subpath\", \"http://localhost:5173\")); // true\n * console.log(compareUrls(\"http://localhost:5172\", \"http://localhost:5173\")); // false\n * ```\n *\n * @param url1 - The first URL to compare.\n * @param url2 - The second URL to compare.\n * @returns Whether the two URLs are equal.\n */\nexport const compareUrls = (url1: string, url2: string): boolean => {\n try {\n const parsedUrl1 = new URL(url1);\n const parsedUrl2 = new URL(url2);\n\n // Compare protocol, hostname, and port\n if (\n parsedUrl1.protocol !== parsedUrl2.protocol ||\n parsedUrl1.hostname !== parsedUrl2.hostname ||\n parsedUrl1.port !== parsedUrl2.port\n ) {\n return false;\n }\n\n // One URL should not have a subpath while the other does\n const path1 = parsedUrl1.pathname.replace(/\\/$/, ''); // Remove trailing slash\n const path2 = parsedUrl2.pathname.replace(/\\/$/, '');\n\n if (path1 !== '' && path2 !== '' && path1 !== path2) {\n return false;\n }\n\n return true;\n } catch (error) {\n console.error('Invalid URL(s)', error, { url1, url2 });\n return false;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,MAAa,eAAe,MAAc,SAA0B;CAClE,IAAI;EACF,MAAM,aAAa,IAAI,IAAI,KAAK;EAChC,MAAM,aAAa,IAAI,IAAI,KAAK;EAGhC,IACE,WAAW,aAAa,WAAW,YACnC,WAAW,aAAa,WAAW,YACnC,WAAW,SAAS,WAAW,MAE/B,OAAO;EAIT,MAAM,QAAQ,WAAW,SAAS,QAAQ,OAAO,GAAG;EACpD,MAAM,QAAQ,WAAW,SAAS,QAAQ,OAAO,GAAG;EAEpD,IAAI,UAAU,MAAM,UAAU,MAAM,UAAU,OAC5C,OAAO;EAGT,OAAO;UACA,OAAO;EACd,QAAQ,MAAM,kBAAkB,OAAO;GAAE;GAAM;GAAM,CAAC;EACtD,OAAO"}
1
+ {"version":3,"file":"compareUrls.cjs","names":[],"sources":["../../src/compareUrls.ts"],"sourcesContent":["/**\n * Compare two URLs for equality.\n * This function is used to determine if a message originates from the same origin.\n *\n * ```js\n * // Example usage\n * console.log(compareUrls(\"http://localhost:5173/\", \"http://localhost:5173\")); // true\n * console.log(compareUrls(\"http://localhost:5173\", \"http://localhost:5173?myParam=true\")); // true\n * console.log(compareUrls(\"http://localhost:5173/subpath\", \"http://localhost:5173\")); // true\n * console.log(compareUrls(\"http://localhost:5172\", \"http://localhost:5173\")); // false\n * ```\n *\n * @param url1 - The first URL to compare.\n * @param url2 - The second URL to compare.\n * @returns Whether the two URLs are equal.\n */\nexport const compareUrls = (url1: string, url2: string): boolean => {\n try {\n const parsedUrl1 = new URL(url1);\n const parsedUrl2 = new URL(url2);\n\n // Compare protocol, hostname, and port\n if (\n parsedUrl1.protocol !== parsedUrl2.protocol ||\n parsedUrl1.hostname !== parsedUrl2.hostname ||\n parsedUrl1.port !== parsedUrl2.port\n ) {\n return false;\n }\n\n // One URL should not have a subpath while the other does\n const path1 = parsedUrl1.pathname.replace(/\\/$/, ''); // Remove trailing slash\n const path2 = parsedUrl2.pathname.replace(/\\/$/, '');\n\n if (path1 !== '' && path2 !== '' && path1 !== path2) {\n return false;\n }\n\n return true;\n } catch (error) {\n console.error('Invalid URL(s)', error, { url1, url2 });\n return false;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,MAAa,eAAe,MAAc,SAA0B;CAClE,IAAI;EACF,MAAM,aAAa,IAAI,IAAI,IAAI;EAC/B,MAAM,aAAa,IAAI,IAAI,IAAI;EAG/B,IACE,WAAW,aAAa,WAAW,YACnC,WAAW,aAAa,WAAW,YACnC,WAAW,SAAS,WAAW,MAE/B,OAAO;EAIT,MAAM,QAAQ,WAAW,SAAS,QAAQ,OAAO,EAAE;EACnD,MAAM,QAAQ,WAAW,SAAS,QAAQ,OAAO,EAAE;EAEnD,IAAI,UAAU,MAAM,UAAU,MAAM,UAAU,OAC5C,OAAO;EAGT,OAAO;CACT,SAAS,OAAO;EACd,QAAQ,MAAM,kBAAkB,OAAO;GAAE;GAAM;EAAK,CAAC;EACrD,OAAO;CACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"ContentSelector.cjs","names":[],"sources":["../../../src/components/ContentSelector.ts"],"sourcesContent":["import { defineIntlayerContentSelectorWrapper } from './ContentSelectorWrapper';\nimport { defineIntlayerEditedContent } from './EditedContent';\nimport { defineIntlayerEditorElement } from './IntlayerEditor';\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 defineIntlayerEditedContent();\n defineIntlayerEditorElement();\n};\n"],"mappings":";;;;;;AAIA,MAAM,yBAAyB;AAE/B,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;AAsBf,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM;;;;;;;;;;;;;;;AAgBb,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,iBAAiB;;CAG3C,IAAI,cAAuB;EACzB,OAAO,KAAK;;CAEd,IAAI,YAAY,GAAY;EAC1B,KAAK,eAAe;EACpB,KAAK,oBAAoB;;CAG3B,IAAI,gBAAwB;EAC1B,OAAO,KAAK;;CAEd,IAAI,cAAc,GAAW;EAC3B,KAAK,iBAAiB;;CAGxB,cAAc;EACZ,OAAO;EACP,MAAM,SAAS,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;EAElD,MAAM,QAAQ,SAAS,cAAc,QAAQ;EAC7C,MAAM,cAAc;EACpB,OAAO,YAAY,MAAM;EAEzB,MAAM,UAAU,SAAS,cAAc,OAAO;EAC9C,QAAQ,YAAY;EACpB,QAAQ,aAAa,QAAQ,SAAS;EACtC,QAAQ,aAAa,YAAY,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BAAyB;EAC/B,IAAI,KAAK,gBAAgB,MAAM;GAC7B,aAAa,KAAK,YAAY;GAC9B,KAAK,cAAc;;;CAIvB,AAAQ,UAAU,WAAyB;EACzC,KAAK,cACH,IAAI,YAAY,WAAW;GAAE,SAAS;GAAM,UAAU;GAAM,CAAC,CAC9D;;CAGH,AAAQ,mBAAyB;EAC/B,KAAK,kBAAkB;EACvB,KAAK,cAAc,iBAAiB;GAClC,KAAK,oBAAoB;GACzB,KAAK,oBAAoB;GACzB,KAAK,UAAU,iBAAiB;KAC/B,KAAK,eAAe;;CAGzB,AAAQ,oBAA0B;EAChC,KAAK,aAAa;EAClB,KAAK,oBAAoB;EACzB,KAAK,UAAU,iBAAiB;;CAGlC,AAAQ,wBAA8B;EACpC,IAAI,KAAK,YAAY;GACnB,KAAK,aAAa;GAClB,KAAK,UAAU,mBAAmB;;EAEpC,KAAK,kBAAkB;EACvB,KAAK,oBAAoB;;CAG3B,AAAQ,aAAa,GAAqB;EACxC,IAAI,KAAK,gBAAgB,KAAK,mBAAmB;GAC/C,EAAE,gBAAgB;GAClB,EAAE,iBAAiB;;;CAIvB,AAAQ,cAAoB;EAC1B,KAAK,oBAAoB;EACzB,KAAK,oBAAoB;;;;;;;;AAS7B,MAAa,+BAAqC;CAChD,IAAI,OAAO,mBAAmB,aAAa;CAC3C,IAAI,CAAC,eAAe,IAAI,4BAA4B,EAClD,eAAe,OACb,6BACA,+BACD;CAEH,gFAAsC;CACtC,8DAA6B;CAC7B,+DAA6B"}
1
+ {"version":3,"file":"ContentSelector.cjs","names":[],"sources":["../../../src/components/ContentSelector.ts"],"sourcesContent":["import { defineIntlayerContentSelectorWrapper } from './ContentSelectorWrapper';\nimport { defineIntlayerEditedContent } from './EditedContent';\nimport { defineIntlayerEditorElement } from './IntlayerEditor';\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 defineIntlayerEditedContent();\n defineIntlayerEditorElement();\n};\n"],"mappings":";;;;;;AAIA,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,M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qC;CACrC,6DAA4B;CAC5B,8DAA4B;AAC9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"ContentSelectorWrapper.cjs","names":["getGlobalEditorManager","NodeTypes","node","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\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 private _unsubEnabled: (() => void) | null = null;\n private _unsubFocused: (() => void) | null = null;\n private _unsubEditedContent: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['key-path', 'dictionary-key'];\n }\n\n get keyPathJson(): string {\n return this._keyPathJson;\n }\n set keyPathJson(v: string) {\n this._keyPathJson = v;\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\n\n get dictionaryKey(): string {\n return this._dictionaryKey;\n }\n set dictionaryKey(v: string) {\n this._dictionaryKey = v;\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\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 _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'key-path') {\n this._keyPathJson = newVal ?? '[]';\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n } else if (name === 'dictionary-key') {\n this._dictionaryKey = newVal ?? '';\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\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._teardown();\n }\n\n private _teardown(): void {\n this._unsubManager?.();\n this._unsubEnabled?.();\n this._unsubFocused?.();\n this._unsubEditedContent?.();\n this._unsubManager = null;\n this._unsubEnabled = null;\n this._unsubFocused = null;\n this._unsubEditedContent = 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 this._isSelected =\n focusedContent.dictionaryKey === this._dictionaryKey &&\n (focusedContent.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent.keyPath ?? [], keyPath);\n this._updateSelectorAttr();\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((m) => {\n this._unsubEnabled?.();\n this._unsubFocused?.();\n this._unsubEditedContent?.();\n this._unsubEnabled = null;\n this._unsubFocused = null;\n this._unsubEditedContent = null;\n if (m) {\n this._setupManagerSubscriptions(m);\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._unsubEnabled = () =>\n manager.editorEnabled.removeEventListener('change', handleEnabledChange);\n this._unsubFocused = () =>\n manager.focusedContent.removeEventListener('change', handleFocusedChange);\n this._unsubEditedContent = () =>\n manager.editedContent.removeEventListener(\n 'change',\n handleEditedContentChange\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":";;;;;;;;;AAkBA,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM;;;;;;;;;;;;;;;AAgBb,IAAa,wCAAb,cAA2D,aAAa;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AC7C,KAAK,eAAe,EAAE,CACvB;GAED,IAAI,UAAU,gBACZ,SAAS,YACP,SAAS,eAAe,OAAO,KAAK,aAAa,CAAC,CACnD;QAED,SAAS,YAAY,SAAS,cAAc,OAAO,CAAC;GAEtD,OAAO,YAAY,SAAS;;EAG9B,KAAK,eAAe;;;AAIxB,MAAa,6CAAmD;CAC9D,IAAI,OAAO,mBAAmB,aAAa;CAE3C,IAAI,CAAC,eAAe,IAAI,oCAAoC,EAC1D,eAAe,OACb,qCACA,sCACD"}
1
+ {"version":3,"file":"ContentSelectorWrapper.cjs","names":["getGlobalEditorManager","NodeTypes","node","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\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 private _unsubEnabled: (() => void) | null = null;\n private _unsubFocused: (() => void) | null = null;\n private _unsubEditedContent: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['key-path', 'dictionary-key'];\n }\n\n get keyPathJson(): string {\n return this._keyPathJson;\n }\n set keyPathJson(v: string) {\n this._keyPathJson = v;\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\n\n get dictionaryKey(): string {\n return this._dictionaryKey;\n }\n set dictionaryKey(v: string) {\n this._dictionaryKey = v;\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\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 _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'key-path') {\n this._keyPathJson = newVal ?? '[]';\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n } else if (name === 'dictionary-key') {\n this._dictionaryKey = newVal ?? '';\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\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._teardown();\n }\n\n private _teardown(): void {\n this._unsubManager?.();\n this._unsubEnabled?.();\n this._unsubFocused?.();\n this._unsubEditedContent?.();\n this._unsubManager = null;\n this._unsubEnabled = null;\n this._unsubFocused = null;\n this._unsubEditedContent = 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 this._isSelected =\n focusedContent.dictionaryKey === this._dictionaryKey &&\n (focusedContent.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent.keyPath ?? [], keyPath);\n this._updateSelectorAttr();\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((m) => {\n this._unsubEnabled?.();\n this._unsubFocused?.();\n this._unsubEditedContent?.();\n this._unsubEnabled = null;\n this._unsubFocused = null;\n this._unsubEditedContent = null;\n if (m) {\n this._setupManagerSubscriptions(m);\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._unsubEnabled = () =>\n manager.editorEnabled.removeEventListener('change', handleEnabledChange);\n this._unsubFocused = () =>\n manager.focusedContent.removeEventListener('change', handleFocusedChange);\n this._unsubEditedContent = () =>\n manager.editedContent.removeEventListener(\n 'change',\n handleEditedContentChange\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":";;;;;;;;;AAkBA,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;AAgBd,IAAa,wCAAb,cAA2D,aAAa;CACtE,AAAQ,eAAe;CACvB,AAAQ,iBAAiB;CACzB,AAAQ,iBAAiB;CACzB,AAAQ,cAAc;CACtB,AAAQ,cAAc;CACtB,AAAQ,eAAwC;CAEhD,AAAQ,eAAmC;CAC3C,AAAQ,YAAgC;CAExC,AAAQ,gBAAqC;CAC7C,AAAQ,gBAAqC;CAC7C,AAAQ,gBAAqC;CAC7C,AAAQ,sBAA2C;CAEnD,WAAW,qBAA+B;EACxC,OAAO,CAAC,YAAY,gBAAgB;CACtC;CAEA,IAAI,cAAsB;EACxB,OAAO,KAAK;CACd;CACA,IAAI,YAAY,GAAW;EACzB,KAAK,eAAe;EACpB,MAAM,UAAUA,kDAAuB;EACvC,IAAI,SAAS,KAAK,mBAAmB,OAAO;CAC9C;CAEA,IAAI,gBAAwB;EAC1B,OAAO,KAAK;CACd;CACA,IAAI,cAAc,GAAW;EAC3B,KAAK,iBAAiB;EACtB,MAAM,UAAUA,kDAAuB;EACvC,IAAI,SAAS,KAAK,mBAAmB,OAAO;CAC9C;CAEA,cAAc;EACZ,MAAM;EACN,MAAM,SAAS,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EACjD,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;EACpB,OAAO,YAAY,KAAK;CAC1B;CAEA,yBACE,MACA,SACA,QACM;EACN,IAAI,SAAS,YAAY;GACvB,KAAK,eAAe,UAAU;GAC9B,MAAM,UAAUA,kDAAuB;GACvC,IAAI,SAAS,KAAK,mBAAmB,OAAO;EAC9C,OAAO,IAAI,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,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;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":"EditedContent.cjs","names":["getGlobalEditorManager","onGlobalEditorManagerChange"],"sources":["../../../src/components/EditedContent.ts"],"sourcesContent":["import { getBasePlugins, getContent } from '@intlayer/core/interpreter';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { EditorStateManager } from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-edited-content>\n *\n * Framework-agnostic web component that displays edited content from the Intlayer\n * editor. When the editor has an edited value for the given dictionary key and\n * key path, it renders the edited value; otherwise it renders the original\n * content via a slot.\n *\n * Always wraps content in <intlayer-content-selector-wrapper> for selection UI.\n *\n * @attr {string} dictionary-key - The dictionary key owning this content node\n * @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n * @attr {string} locale - The current locale string\n */\nexport class IntlayerEditedContentElement extends _HTMLElement {\n private _dictionaryKey = '';\n private _keyPathJson = '[]';\n private _locale = '';\n private _editedText: string | null = null;\n\n private _unsubManager: (() => void) | null = null;\n private _unsubEditedContent: (() => void) | null = null;\n\n private _selectorWrapper: HTMLElement;\n private _slot: HTMLSlotElement;\n\n static get observedAttributes(): string[] {\n return ['dictionary-key', 'key-path', 'locale'];\n }\n\n get dictionaryKey(): string {\n return this._dictionaryKey;\n }\n set dictionaryKey(v: string) {\n this._dictionaryKey = v;\n this._selectorWrapper.setAttribute('dictionary-key', v);\n }\n\n get keyPathJson(): string {\n return this._keyPathJson;\n }\n set keyPathJson(v: string) {\n this._keyPathJson = v;\n this._selectorWrapper.setAttribute('key-path', v);\n }\n\n get locale(): string {\n return this._locale;\n }\n set locale(v: string) {\n this._locale = v;\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n\n const style = document.createElement('style');\n style.textContent = ':host { display: contents; }';\n shadow.appendChild(style);\n\n this._selectorWrapper = document.createElement(\n 'intlayer-content-selector-wrapper'\n );\n this._slot = document.createElement('slot') as HTMLSlotElement;\n this._selectorWrapper.appendChild(this._slot);\n shadow.appendChild(this._selectorWrapper);\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n const val = newVal ?? '';\n if (name === 'dictionary-key') {\n this._dictionaryKey = val;\n this._selectorWrapper.setAttribute('dictionary-key', val);\n } else if (name === 'key-path') {\n this._keyPathJson = val || '[]';\n this._selectorWrapper.setAttribute('key-path', this._keyPathJson);\n } else if (name === 'locale') {\n this._locale = val;\n }\n }\n\n connectedCallback(): void {\n this._subscribeToManager();\n }\n\n disconnectedCallback(): void {\n this._teardown();\n }\n\n private _teardown(): void {\n this._unsubManager?.();\n this._unsubEditedContent?.();\n this._unsubManager = null;\n this._unsubEditedContent = null;\n }\n\n private _getKeyPath(): KeyPath[] {\n try {\n return JSON.parse(this._keyPathJson);\n } catch {\n return [];\n }\n }\n\n private _render(): void {\n while (this._selectorWrapper.firstChild) {\n this._selectorWrapper.removeChild(this._selectorWrapper.firstChild);\n }\n if (this._editedText !== null) {\n this._selectorWrapper.appendChild(\n document.createTextNode(this._editedText)\n );\n } else {\n this._selectorWrapper.appendChild(this._slot);\n }\n }\n\n private _resolveEditedText(manager: EditorStateManager): void {\n const keyPath = this._getKeyPath();\n const editedValue = manager.getContentValue(this._dictionaryKey, keyPath);\n\n if (editedValue === undefined || editedValue === null) {\n this._editedText = null;\n this._render();\n return;\n }\n\n if (typeof editedValue === 'string' || typeof editedValue === 'number') {\n this._editedText = String(editedValue);\n this._render();\n return;\n }\n\n if (typeof editedValue === 'object') {\n const locale = this._locale || undefined;\n const transformed = getContent(\n editedValue,\n {\n locale: locale as any,\n dictionaryKey: this._dictionaryKey,\n keyPath,\n },\n getBasePlugins(locale)\n );\n if (typeof transformed === 'string' || typeof transformed === 'number') {\n this._editedText = String(transformed);\n } else {\n console.error(\n `[intlayer-edited-content] Incorrect edited content format. Expected string. Value: ${JSON.stringify(transformed)}`\n );\n this._editedText = null;\n }\n this._render();\n return;\n }\n\n this._editedText = null;\n this._render();\n }\n\n private _setupManagerSubscriptions(manager: EditorStateManager): void {\n this._resolveEditedText(manager);\n\n const handleChange = () => this._resolveEditedText(manager);\n manager.editedContent.addEventListener('change', handleChange);\n\n this._unsubEditedContent = () =>\n manager.editedContent.removeEventListener('change', handleChange);\n }\n\n private _subscribeToManager(): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n this._setupManagerSubscriptions(manager);\n }\n\n this._unsubManager = onGlobalEditorManagerChange((m) => {\n this._unsubEditedContent?.();\n this._unsubEditedContent = null;\n if (m) {\n this._setupManagerSubscriptions(m);\n } else {\n this._editedText = null;\n this._render();\n }\n });\n }\n}\n\nexport const defineIntlayerEditedContent = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-edited-content')) {\n customElements.define(\n 'intlayer-edited-content',\n IntlayerEditedContentElement\n );\n }\n};\n"],"mappings":";;;;;;AAQA,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM;;;;;;;;;;;;;;;AAgBb,IAAa,+BAAb,cAAkD,aAAa;CAC7D,AAAQ,iBAAiB;CACzB,AAAQ,eAAe;CACvB,AAAQ,UAAU;CAClB,AAAQ,cAA6B;CAErC,AAAQ,gBAAqC;CAC7C,AAAQ,sBAA2C;CAEnD,AAAQ;CACR,AAAQ;CAER,WAAW,qBAA+B;EACxC,OAAO;GAAC;GAAkB;GAAY;GAAS;;CAGjD,IAAI,gBAAwB;EAC1B,OAAO,KAAK;;CAEd,IAAI,cAAc,GAAW;EAC3B,KAAK,iBAAiB;EACtB,KAAK,iBAAiB,aAAa,kBAAkB,EAAE;;CAGzD,IAAI,cAAsB;EACxB,OAAO,KAAK;;CAEd,IAAI,YAAY,GAAW;EACzB,KAAK,eAAe;EACpB,KAAK,iBAAiB,aAAa,YAAY,EAAE;;CAGnD,IAAI,SAAiB;EACnB,OAAO,KAAK;;CAEd,IAAI,OAAO,GAAW;EACpB,KAAK,UAAU;;CAGjB,cAAc;EACZ,OAAO;EACP,MAAM,SAAS,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;EAElD,MAAM,QAAQ,SAAS,cAAc,QAAQ;EAC7C,MAAM,cAAc;EACpB,OAAO,YAAY,MAAM;EAEzB,KAAK,mBAAmB,SAAS,cAC/B,oCACD;EACD,KAAK,QAAQ,SAAS,cAAc,OAAO;EAC3C,KAAK,iBAAiB,YAAY,KAAK,MAAM;EAC7C,OAAO,YAAY,KAAK,iBAAiB;;CAG3C,yBACE,MACA,SACA,QACM;EACN,MAAM,MAAM,UAAU;EACtB,IAAI,SAAS,kBAAkB;GAC7B,KAAK,iBAAiB;GACtB,KAAK,iBAAiB,aAAa,kBAAk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AErB,KAAK,SAAS;GACd;;EAGF,KAAK,cAAc;EACnB,KAAK,SAAS;;CAGhB,AAAQ,2BAA2B,SAAmC;EACpE,KAAK,mBAAmB,QAAQ;EAEhC,MAAM,qBAAqB,KAAK,mBAAmB,QAAQ;EAC3D,QAAQ,cAAc,iBAAiB,UAAU,aAAa;EAE9D,KAAK,4BACH,QAAQ,cAAc,oBAAoB,UAAU,aAAa;;CAGrE,AAAQ,sBAA4B;EAClC,MAAM,UAAUA,mDAAwB;EACxC,IAAI,SACF,KAAK,2BAA2B,QAAQ;EAG1C,KAAK,gBAAgBC,wDAA6B,MAAM;GACtD,KAAK,uBAAuB;GAC5B,KAAK,sBAAsB;GAC3B,IAAI,GACF,KAAK,2BAA2B,EAAE;QAC7B;IACL,KAAK,cAAc;IACnB,KAAK,SAAS;;IAEhB;;;AAIN,MAAa,oCAA0C;CACrD,IAAI,OAAO,mBAAmB,aAAa;CAE3C,IAAI,CAAC,eAAe,IAAI,0BAA0B,EAChD,eAAe,OACb,2BACA,6BACD"}
1
+ {"version":3,"file":"EditedContent.cjs","names":["getGlobalEditorManager","onGlobalEditorManagerChange"],"sources":["../../../src/components/EditedContent.ts"],"sourcesContent":["import { getBasePlugins, getContent } from '@intlayer/core/interpreter';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { EditorStateManager } from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-edited-content>\n *\n * Framework-agnostic web component that displays edited content from the Intlayer\n * editor. When the editor has an edited value for the given dictionary key and\n * key path, it renders the edited value; otherwise it renders the original\n * content via a slot.\n *\n * Always wraps content in <intlayer-content-selector-wrapper> for selection UI.\n *\n * @attr {string} dictionary-key - The dictionary key owning this content node\n * @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n * @attr {string} locale - The current locale string\n */\nexport class IntlayerEditedContentElement extends _HTMLElement {\n private _dictionaryKey = '';\n private _keyPathJson = '[]';\n private _locale = '';\n private _editedText: string | null = null;\n\n private _unsubManager: (() => void) | null = null;\n private _unsubEditedContent: (() => void) | null = null;\n\n private _selectorWrapper: HTMLElement;\n private _slot: HTMLSlotElement;\n\n static get observedAttributes(): string[] {\n return ['dictionary-key', 'key-path', 'locale'];\n }\n\n get dictionaryKey(): string {\n return this._dictionaryKey;\n }\n set dictionaryKey(v: string) {\n this._dictionaryKey = v;\n this._selectorWrapper.setAttribute('dictionary-key', v);\n }\n\n get keyPathJson(): string {\n return this._keyPathJson;\n }\n set keyPathJson(v: string) {\n this._keyPathJson = v;\n this._selectorWrapper.setAttribute('key-path', v);\n }\n\n get locale(): string {\n return this._locale;\n }\n set locale(v: string) {\n this._locale = v;\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n\n const style = document.createElement('style');\n style.textContent = ':host { display: contents; }';\n shadow.appendChild(style);\n\n this._selectorWrapper = document.createElement(\n 'intlayer-content-selector-wrapper'\n );\n this._slot = document.createElement('slot') as HTMLSlotElement;\n this._selectorWrapper.appendChild(this._slot);\n shadow.appendChild(this._selectorWrapper);\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n const val = newVal ?? '';\n if (name === 'dictionary-key') {\n this._dictionaryKey = val;\n this._selectorWrapper.setAttribute('dictionary-key', val);\n } else if (name === 'key-path') {\n this._keyPathJson = val || '[]';\n this._selectorWrapper.setAttribute('key-path', this._keyPathJson);\n } else if (name === 'locale') {\n this._locale = val;\n }\n }\n\n connectedCallback(): void {\n this._subscribeToManager();\n }\n\n disconnectedCallback(): void {\n this._teardown();\n }\n\n private _teardown(): void {\n this._unsubManager?.();\n this._unsubEditedContent?.();\n this._unsubManager = null;\n this._unsubEditedContent = null;\n }\n\n private _getKeyPath(): KeyPath[] {\n try {\n return JSON.parse(this._keyPathJson);\n } catch {\n return [];\n }\n }\n\n private _render(): void {\n while (this._selectorWrapper.firstChild) {\n this._selectorWrapper.removeChild(this._selectorWrapper.firstChild);\n }\n if (this._editedText !== null) {\n this._selectorWrapper.appendChild(\n document.createTextNode(this._editedText)\n );\n } else {\n this._selectorWrapper.appendChild(this._slot);\n }\n }\n\n private _resolveEditedText(manager: EditorStateManager): void {\n const keyPath = this._getKeyPath();\n const editedValue = manager.getContentValue(this._dictionaryKey, keyPath);\n\n if (editedValue === undefined || editedValue === null) {\n this._editedText = null;\n this._render();\n return;\n }\n\n if (typeof editedValue === 'string' || typeof editedValue === 'number') {\n this._editedText = String(editedValue);\n this._render();\n return;\n }\n\n if (typeof editedValue === 'object') {\n const locale = this._locale || undefined;\n const transformed = getContent(\n editedValue,\n {\n locale: locale as any,\n dictionaryKey: this._dictionaryKey,\n keyPath,\n },\n getBasePlugins(locale)\n );\n if (typeof transformed === 'string' || typeof transformed === 'number') {\n this._editedText = String(transformed);\n } else {\n console.error(\n `[intlayer-edited-content] Incorrect edited content format. Expected string. Value: ${JSON.stringify(transformed)}`\n );\n this._editedText = null;\n }\n this._render();\n return;\n }\n\n this._editedText = null;\n this._render();\n }\n\n private _setupManagerSubscriptions(manager: EditorStateManager): void {\n this._resolveEditedText(manager);\n\n const handleChange = () => this._resolveEditedText(manager);\n manager.editedContent.addEventListener('change', handleChange);\n\n this._unsubEditedContent = () =>\n manager.editedContent.removeEventListener('change', handleChange);\n }\n\n private _subscribeToManager(): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n this._setupManagerSubscriptions(manager);\n }\n\n this._unsubManager = onGlobalEditorManagerChange((m) => {\n this._unsubEditedContent?.();\n this._unsubEditedContent = null;\n if (m) {\n this._setupManagerSubscriptions(m);\n } else {\n this._editedText = null;\n this._render();\n }\n });\n }\n}\n\nexport const defineIntlayerEditedContent = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-edited-content')) {\n customElements.define(\n 'intlayer-edited-content',\n IntlayerEdited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;GACb;EACF;EAEA,KAAK,cAAc;EACnB,KAAK,QAAQ;CACf;CAEA,AAAQ,2BAA2B,SAAmC;EACpE,KAAK,mBAAmB,OAAO;EAE/B,MAAM,qBAAqB,KAAK,mBAAmB,OAAO;EAC1D,QAAQ,cAAc,iBAAiB,UAAU,YAAY;EAE7D,KAAK,4BACH,QAAQ,cAAc,oBAAoB,UAAU,YAAY;CACpE;CAEA,AAAQ,sBAA4B;EAClC,MAAM,UAAUA,kDAAuB;EACvC,IAAI,SACF,KAAK,2BAA2B,OAAO;EAGzC,KAAK,gBAAgBC,wDAA6B,MAAM;GACtD,KAAK,sBAAsB;GAC3B,KAAK,sBAAsB;GAC3B,IAAI,GACF,KAAK,2BAA2B,CAAC;QAC5B;IACL,KAAK,cAAc;IACnB,KAAK,QAAQ;GACf;EACF,CAAC;CACH;AACF;AAEA,MAAa,oCAA0C;CACrD,IAAI,OAAO,mBAAmB,aAAa;CAE3C,IAAI,CAAC,eAAe,IAAI,yBAAyB,GAC/C,eAAe,OACb,2BACA,4BACF;AAEJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"IntlayerEditor.cjs","names":["getGlobalEditorManager","onGlobalEditorManagerChange"],"sources":["../../../src/components/IntlayerEditor.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\nimport { initEditorClient, stopEditorClient } from '../core/initEditorClient';\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-editor>\n *\n * A framework-agnostic web component that manages the Intlayer editor singleton\n * lifecycle and keeps the current locale in sync with the EditorStateManager.\n *\n * Drop this element once at the root of your application to activate the editor.\n * It renders no UI.\n *\n * @prop {IntlayerConfig} configuration - The Intlayer config (required; set as JS property, not attribute)\n * @prop {string} locale - The active application locale (attribute/property)\n *\n * @example\n * // Svelte\n * <intlayer-editor .configuration={config} locale={$locale} />\n *\n * // Vue\n * <intlayer-editor :configuration=\"config\" :locale=\"currentLocale\" />\n */\nexport class IntlayerEditorElement extends _HTMLElement {\n private _configuration: IntlayerConfig | undefined = undefined;\n private _locale: string | undefined = undefined;\n private _initialized = false;\n private _unsubManager: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['locale'];\n }\n\n get configuration(): IntlayerConfig | undefined {\n return this._configuration;\n }\n set configuration(v: IntlayerConfig | undefined) {\n this._configuration = v;\n if (!this._initialized) this._init();\n }\n\n get locale(): string | undefined {\n return this._locale;\n }\n set locale(v: string | undefined) {\n this._locale = v;\n if (v && this._initialized) this._syncLocale(v);\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'locale' && newVal !== null) {\n this._locale = newVal;\n if (this._initialized) this._syncLocale(newVal);\n }\n }\n\n connectedCallback(): void {\n this._init();\n }\n\n disconnectedCallback(): void {\n this._unsubManager?.();\n this._unsubManager = null;\n if (this._initialized) {\n stopEditorClient();\n this._initialized = false;\n }\n }\n\n private _init(): void {\n if (this._initialized) return;\n initEditorClient();\n this._initialized = true;\n if (this._locale) this._syncLocale(this._locale);\n }\n\n private _syncLocale(locale: string): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n manager.currentLocale.set(locale as Locale);\n } else {\n // Manager may not be ready yet — wait for it\n this._unsubManager?.();\n this._unsubManager = onGlobalEditorManagerChange((m) => {\n if (m) {\n this._unsubManager?.();\n this._unsubManager = null;\n m.currentLocale.set(locale as Locale);\n }\n });\n }\n }\n}\n\nexport const defineIntlayerEditorElement = (): void => {\n if (typeof customElements === 'undefined') return;\n if (!customElements.get('intlayer-editor')) {\n customElements.define('intlayer-editor', IntlayerEditorElement);\n }\n};\n"],"mappings":";;;;;AAQA,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM;;;;;;;;;;;;;;;;;;;;AAqBb,IAAa,wB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.cjs","names":["getGlobalEditorManager","onGlobalEditorManagerChange"],"sources":["../../../src/components/IntlayerEditor.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\nimport { initEditorClient, stopEditorClient } from '../core/initEditorClient';\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-editor>\n *\n * A framework-agnostic web component that manages the Intlayer editor singleton\n * lifecycle and keeps the current locale in sync with the EditorStateManager.\n *\n * Drop this element once at the root of your application to activate the editor.\n * It renders no UI.\n *\n * @prop {IntlayerConfig} configuration - The Intlayer config (required; set as JS property, not attribute)\n * @prop {string} locale - The active application locale (attribute/property)\n *\n * @example\n * // Svelte\n * <intlayer-editor .configuration={config} locale={$locale} />\n *\n * // Vue\n * <intlayer-editor :configuration=\"config\" :locale=\"currentLocale\" />\n */\nexport class IntlayerEditorElement extends _HTMLElement {\n private _configuration: IntlayerConfig | undefined = undefined;\n private _locale: string | undefined = undefined;\n private _initialized = false;\n private _unsubManager: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['locale'];\n }\n\n get configuration(): IntlayerConfig | undefined {\n return this._configuration;\n }\n set configuration(v: IntlayerConfig | undefined) {\n this._configuration = v;\n if (!this._initialized) this._init();\n }\n\n get locale(): string | undefined {\n return this._locale;\n }\n set locale(v: string | undefined) {\n this._locale = v;\n if (v && this._initialized) this._syncLocale(v);\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'locale' && newVal !== null) {\n this._locale = newVal;\n if (this._initialized) this._syncLocale(newVal);\n }\n }\n\n connectedCallback(): void {\n this._init();\n }\n\n disconnectedCallback(): void {\n this._unsubManager?.();\n this._unsubManager = null;\n if (this._initialized) {\n stopEditorClient();\n this._initialized = false;\n }\n }\n\n private _init(): void {\n if (this._initialized) return;\n initEditorClient();\n this._initialized = true;\n if (this._locale) this._syncLocale(this._locale);\n }\n\n private _syncLocale(locale: string): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n manager.currentLocale.set(locale as Locale);\n } else {\n // Manager may not be ready yet — wait for it\n this._unsubManager?.();\n this._unsubManager = onGlobalEditorManagerChange((m) => {\n if (m) {\n this._unsubManager?.();\n this._unsubManager = null;\n m.currentLocale.set(locale as Locale);\n }\n });\n }\n }\n}\n\nexport const defineIntlayerEditorElement = (): void => {\n if (typeof customElements === 'undefined') return;\n if (!customElements.get('intlayer-editor')) {\n customElements.define('intlayer-editor', IntlayerEditorElement);\n }\n};\n"],"mappings":";;;;;AAQA,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;AAqBd,IAAa,wBAAb,cAA2C,aAAa;CACtD,AAAQ,iBAA6C;CACrD,AAAQ,UAA8B;CACtC,AAAQ,eAAe;CACvB,AAAQ,gBAAqC;CAE7C,WAAW,qBAA+B;EACxC,OAAO,CAAC,QAAQ;CAClB;CAEA,IAAI,gBAA4C;EAC9C,OAAO,KAAK;CACd;CACA,IAAI,cAAc,GAA+B;EAC/C,KAAK,iBAAiB;EACtB,IAAI,CAAC,KAAK,cAAc,KAAK,MAAM;CACrC;CAEA,IAAI,SAA6B;EAC/B,OAAO,KAAK;CACd;CACA,IAAI,OAAO,GAAuB;EAChC,KAAK,UAAU;EACf,IAAI,KAAK,KAAK,cAAc,KAAK,YAAY,CAAC;CAChD;CAEA,yBACE,MACA,SACA,QACM;EACN,IAAI,SAAS,YAAY,WAAW,MAAM;GACxC,KAAK,UAAU;GACf,IAAI,KAAK,cAAc,KAAK,YAAY,MAAM;EAChD;CACF;CAEA,oBAA0B;EACxB,KAAK,MAAM;CACb;CAEA,uBAA6B;EAC3B,KAAK,gBAAgB;EACrB,KAAK,gBAAgB;EACrB,IAAI,KAAK,cAAc;GACrB,+CAAiB;GACjB,KAAK,eAAe;EACtB;CACF;CAEA,AAAQ,QAAc;EACpB,IAAI,KAAK,cAAc;EACvB,+CAAiB;EACjB,KAAK,eAAe;EACpB,IAAI,KAAK,SAAS,KAAK,YAAY,KAAK,OAAO;CACjD;CAEA,AAAQ,YAAY,QAAsB;EACxC,MAAM,UAAUA,kDAAuB;EACvC,IAAI,SACF,QAAQ,cAAc,IAAI,MAAgB;OACrC;GAEL,KAAK,gBAAgB;GACrB,KAAK,gBAAgBC,wDAA6B,MAAM;IACtD,IAAI,GAAG;KACL,KAAK,gBAAgB;KACrB,KAAK,gBAAgB;KACrB,EAAE,cAAc,IAAI,MAAgB;IACtC;GACF,CAAC;EACH;CACF;AACF;AAEA,MAAa,oCAA0C;CACrD,IAAI,OAAO,mBAAmB,aAAa;CAC3C,IAAI,CAAC,eAAe,IAAI,iBAAiB,GACvC,eAAe,OAAO,mBAAmB,qBAAqB;AAElE"}
@@ -1 +1 @@
1
- {"version":3,"file":"CrossFrameMessenger.cjs","names":["compareUrls"],"sources":["../../../src/core/CrossFrameMessenger.ts"],"sourcesContent":["import { compareUrls } from '../compareUrls';\n\nconst randomUUID = (): string => Math.random().toString(36).slice(2);\n\nexport type MessagePayload = {\n type: string;\n data?: unknown;\n senderId?: string;\n /** Unique ID per send() call — used to deduplicate when the same payload arrives via multiple target origins */\n messageId?: string;\n};\n\nexport type MessengerConfig = {\n /**\n * Origins allowed to send messages to this instance.\n * Use '*' to allow all origins (not recommended for production).\n */\n allowedOrigins: string[];\n /**\n * Function used to send messages to other frames.\n * Injected so the messenger is agnostic to the frame topology.\n */\n postMessageFn: (payload: MessagePayload, origin: string) => void;\n};\n\ntype MessageHandler<T = unknown> = (data: T, senderId?: string) => void;\n\n/**\n * CrossFrameMessenger manages all cross-frame postMessage communication.\n * It owns a single window message listener and routes incoming messages to\n * type-specific subscribers.\n *\n * Replaces CommunicatorContext + useCrossFrameMessageListener across all frameworks.\n */\nexport class CrossFrameMessenger {\n readonly senderId: string;\n private readonly _config: MessengerConfig;\n private readonly _subscribers = new Map<string, Set<MessageHandler>>();\n\n private _windowHandler: ((event: MessageEvent) => void) | null = null;\n /** Tracks recently processed messageIds to discard duplicates (same payload sent to multiple origins) */\n private readonly _seenMessageIds = new Set<string>();\n\n constructor(config: MessengerConfig) {\n this._config = config;\n this.senderId = randomUUID();\n }\n\n /** Start listening for incoming messages on window. */\n start(): void {\n if (typeof window === 'undefined') return;\n if (this._windowHandler) return;\n this._windowHandler = (event: MessageEvent<MessagePayload>) => {\n this._handleMessage(event);\n };\n window.addEventListener('message', this._windowHandler);\n }\n\n /** Stop listening and clean up. */\n stop(): void {\n if (this._windowHandler) {\n window.removeEventListener('message', this._windowHandler);\n this._windowHandler = null;\n }\n }\n\n /** Send a message payload to all configured target origins. */\n send(type: string, data?: unknown): void {\n const payload: MessagePayload = {\n type,\n data,\n senderId: this.senderId,\n messageId: randomUUID(),\n };\n\n for (const origin of this._config.allowedOrigins) {\n if (origin) {\n this._config.postMessageFn(payload, origin);\n }\n }\n }\n\n /**\n * Subscribe to messages of a given type.\n * Returns an unsubscribe function.\n */\n subscribe<T = unknown>(type: string, handler: MessageHandler<T>): () => void {\n if (!this._subscribers.has(type)) {\n this._subscribers.set(type, new Set());\n }\n this._subscribers.get(type)!.add(handler as MessageHandler);\n return () => {\n this._subscribers.get(type)?.delete(handler as MessageHandler);\n };\n }\n\n private _handleMessage(event: MessageEvent<MessagePayload>): void {\n const payload = event.data;\n if (!payload || typeof payload !== 'object') return;\n\n const { type, data, senderId: msgSenderId, messageId } = payload;\n if (!type || typeof type !== 'string') return;\n\n // Ignore messages originating from this instance\n if (msgSenderId === this.senderId) return;\n\n // Deduplicate: same messageId may arrive multiple times when the sender\n // posts to multiple target origins (one per allowedOrigin)\n if (messageId) {\n if (this._seenMessageIds.has(messageId)) return;\n this._seenMessageIds.add(messageId);\n // Keep the set bounded — clear when it exceeds 200 entries\n if (this._seenMessageIds.size > 200) this._seenMessageIds.clear();\n }\n\n // Validate message origin\n const { allowedOrigins } = this._config;\n const isAllowed =\n !allowedOrigins ||\n allowedOrigins.length === 0 ||\n allowedOrigins.includes('*') ||\n allowedOrigins\n .filter((url) => Boolean(url) && url !== '')\n .some((url) => compareUrls(url, event.origin));\n\n if (!isAllowed) return;\n\n const handlers = this._subscribers.get(type);\n\n if (handlers) {\n for (const handler of handlers) {\n handler(data, msgSenderId);\n }\n }\n }\n}\n"],"mappings":";;;;AAEA,MAAM,mBAA2B,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE;;;;;;;;AAgCpE,IAAa,sBAAb,MAAiC;CAC/B,AAAS;CACT,AAAiB;CACjB,AAAiB,+BAAe,IAAI,KAAkC;CAEtE,AAAQ,iBAAyD;;CAEjE,AAAiB,kCAAkB,IAAI,KAAa;CAEpD,YAAY,QAAyB;EACnC,KAAK,UAAU;EACf,KAAK,WAAW,YAAY;;;CAI9B,QAAc;EACZ,IAAI,OAAO,WAAW,aAAa;EACnC,IAAI,KAAK,gBAAgB;EACzB,KAAK,kBAAkB,UAAwC;GAC7D,KAAK,eAAe,MAAM;;EAE5B,OAAO,iBAAiB,WAAW,KAAK,eAAe;;;CAIzD,OAAa;EACX,IAAI,KAAK,gBAAgB;GACvB,OAAO,oBAAoB,WAAW,KAAK,eAAe;GAC1D,KAAK,iBAAiB;;;;CAK1B,KAAK,MAAc,MAAsB;EACvC,MAAM,UAA0B;GAC9B;GACA;GACA,UAAU,KAAK;GACf,WAAW,YAAY;GACxB;EAED,KAAK,MAAM,UAAU,KAAK,QAAQ,gBAChC,IAAI,QACF,KAAK,QAAQ,cAAc,SAAS,OAAO;;;;;;CASjD,UAAuB,MAAc,SAAwC;EAC3E,IAAI,CAAC,KAAK,aAAa,IAAI,KAAK,EAC9B,KAAK,aAAa,IAAI,sBAAM,IAAI,KAAK,CAAC;EAExC,KAAK,aAAa,IAAI,KAAK,CAAE,IAAI,QAA0B;EAC3D,aAAa;GACX,KAAK,aAAa,IAAI,KAAK,EAAE,OAAO,QAA0B;;;CAIlE,AAAQ,eAAe,OAA2C;EAChE,MAAM,UAAU,MAAM;EACtB,IAAI,CAAC,WAAW,OAAO,YAAY,UAAU;EAE7C,MAAM,EAAE,MAAM,MAAM,UAAU,aAAa,cAAc;EACzD,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU;EAGvC,IAAI,gBAAgB,KAAK,UAAU;EAInC,IAAI,WAAW;GACb,IAAI,KAAK,gBAAgB,IAAI,UAAU,EAAE;GACzC,KAAK,gBAAgB,IAAI,UAAU;GAEnC,IAAI,KAAK,gBAAgB,OAAO,KAAK,KAAK,gBAAgB,OAAO;;EAInE,MAAM,EAAE,mBAAmB,KAAK;EAShC,IAAI,EAPF,CAAC,kBACD,eAAe,WAAW,KAC1B,eAAe,SAAS,IAAI,IAC5B,eACG,QAAQ,QAAQ,QAAQ,IAAI,IAAI,QAAQ,GAAG,CAC3C,MAAM,QAAQA,gCAAY,KAAK,MAAM,OAAO,CAAC,GAElC;EAEhB,MAAM,WAAW,KAAK,aAAa,IAAI,KAAK;EAE5C,IAAI,UACF,KAAK,MAAM,WAAW,UACpB,QAAQ,MAAM,YAAY"}
1
+ {"version":3,"file":"CrossFrameMessenger.cjs","names":["compareUrls"],"sources":["../../../src/core/CrossFrameMessenger.ts"],"sourcesContent":["import { compareUrls } from '../compareUrls';\n\nconst randomUUID = (): string => Math.random().toString(36).slice(2);\n\nexport type MessagePayload = {\n type: string;\n data?: unknown;\n senderId?: string;\n /** Unique ID per send() call — used to deduplicate when the same payload arrives via multiple target origins */\n messageId?: string;\n};\n\nexport type MessengerConfig = {\n /**\n * Origins allowed to send messages to this instance.\n * Use '*' to allow all origins (not recommended for production).\n */\n allowedOrigins: string[];\n /**\n * Function used to send messages to other frames.\n * Injected so the messenger is agnostic to the frame topology.\n */\n postMessageFn: (payload: MessagePayload, origin: string) => void;\n};\n\ntype MessageHandler<T = unknown> = (data: T, senderId?: string) => void;\n\n/**\n * CrossFrameMessenger manages all cross-frame postMessage communication.\n * It owns a single window message listener and routes incoming messages to\n * type-specific subscribers.\n *\n * Replaces CommunicatorContext + useCrossFrameMessageListener across all frameworks.\n */\nexport class CrossFrameMessenger {\n readonly senderId: string;\n private readonly _config: MessengerConfig;\n private readonly _subscribers = new Map<string, Set<MessageHandler>>();\n\n private _windowHandler: ((event: MessageEvent) => void) | null = null;\n /** Tracks recently processed messageIds to discard duplicates (same payload sent to multiple origins) */\n private readonly _seenMessageIds = new Set<string>();\n\n constructor(config: MessengerConfig) {\n this._config = config;\n this.senderId = randomUUID();\n }\n\n /** Start listening for incoming messages on window. */\n start(): void {\n if (typeof window === 'undefined') return;\n if (this._windowHandler) return;\n this._windowHandler = (event: MessageEvent<MessagePayload>) => {\n this._handleMessage(event);\n };\n window.addEventListener('message', this._windowHandler);\n }\n\n /** Stop listening and clean up. */\n stop(): void {\n if (this._windowHandler) {\n window.removeEventListener('message', this._windowHandler);\n this._windowHandler = null;\n }\n }\n\n /** Send a message payload to all configured target origins. */\n send(type: string, data?: unknown): void {\n const payload: MessagePayload = {\n type,\n data,\n senderId: this.senderId,\n messageId: randomUUID(),\n };\n\n for (const origin of this._config.allowedOrigins) {\n if (origin) {\n this._config.postMessageFn(payload, origin);\n }\n }\n }\n\n /**\n * Subscribe to messages of a given type.\n * Returns an unsubscribe function.\n */\n subscribe<T = unknown>(type: string, handler: MessageHandler<T>): () => void {\n if (!this._subscribers.has(type)) {\n this._subscribers.set(type, new Set());\n }\n this._subscribers.get(type)!.add(handler as MessageHandler);\n return () => {\n this._subscribers.get(type)?.delete(handler as MessageHandler);\n };\n }\n\n private _handleMessage(event: MessageEvent<MessagePayload>): void {\n const payload = event.data;\n if (!payload || typeof payload !== 'object') return;\n\n const { type, data, senderId: msgSenderId, messageId } = payload;\n if (!type || typeof type !== 'string') return;\n\n // Ignore messages originating from this instance\n if (msgSenderId === this.senderId) return;\n\n // Deduplicate: same messageId may arrive multiple times when the sender\n // posts to multiple target origins (one per allowedOrigin)\n if (messageId) {\n if (this._seenMessageIds.has(messageId)) return;\n this._seenMessageIds.add(messageId);\n // Keep the set bounded — clear when it exceeds 200 entries\n if (this._seenMessageIds.size > 200) this._seenMessageIds.clear();\n }\n\n // Validate message origin\n const { allowedOrigins } = this._config;\n const isAllowed =\n !allowedOrigins ||\n allowedOrigins.length === 0 ||\n allowedOrigins.includes('*') ||\n allowedOrigins\n .filter((url) => Boolean(url) && url !== '')\n .some((url) => compareUrls(url, event.origin));\n\n if (!isAllowed) return;\n\n const handlers = this._subscribers.get(type);\n\n if (handlers) {\n for (const handler of handlers) {\n handler(data, msgSenderId);\n }\n }\n }\n}\n"],"mappings":";;;;AAEA,MAAM,mBAA2B,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC;;;;;;;;AAgCnE,IAAa,sBAAb,MAAiC;CAC/B,AAAS;CACT,AAAiB;CACjB,AAAiB,+BAAe,IAAI,IAAiC;CAErE,AAAQ,iBAAyD;;CAEjE,AAAiB,kCAAkB,IAAI,IAAY;CAEnD,YAAY,QAAyB;EACnC,KAAK,UAAU;EACf,KAAK,WAAW,WAAW;CAC7B;;CAGA,QAAc;EACZ,IAAI,OAAO,WAAW,aAAa;EACnC,IAAI,KAAK,gBAAgB;EACzB,KAAK,kBAAkB,UAAwC;GAC7D,KAAK,eAAe,KAAK;EAC3B;EACA,OAAO,iBAAiB,WAAW,KAAK,cAAc;CACxD;;CAGA,OAAa;EACX,IAAI,KAAK,gBAAgB;GACvB,OAAO,oBAAoB,WAAW,KAAK,cAAc;GACzD,KAAK,iBAAiB;EACxB;CACF;;CAGA,KAAK,MAAc,MAAsB;EACvC,MAAM,UAA0B;GAC9B;GACA;GACA,UAAU,KAAK;GACf,WAAW,WAAW;EACxB;EAEA,KAAK,MAAM,UAAU,KAAK,QAAQ,gBAChC,IAAI,QACF,KAAK,QAAQ,cAAc,SAAS,MAAM;CAGhD;;;;;CAMA,UAAuB,MAAc,SAAwC;EAC3E,IAAI,CAAC,KAAK,aAAa,IAAI,IAAI,GAC7B,KAAK,aAAa,IAAI,sBAAM,IAAI,IAAI,CAAC;EAEvC,KAAK,aAAa,IAAI,IAAI,EAAG,IAAI,OAAyB;EAC1D,aAAa;GACX,KAAK,aAAa,IAAI,IAAI,GAAG,OAAO,OAAyB;EAC/D;CACF;CAEA,AAAQ,eAAe,OAA2C;EAChE,MAAM,UAAU,MAAM;EACtB,IAAI,CAAC,WAAW,OAAO,YAAY,UAAU;EAE7C,MAAM,EAAE,MAAM,MAAM,UAAU,aAAa,cAAc;EACzD,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU;EAGvC,IAAI,gBAAgB,KAAK,UAAU;EAInC,IAAI,WAAW;GACb,IAAI,KAAK,gBAAgB,IAAI,SAAS,GAAG;GACzC,KAAK,gBAAgB,IAAI,SAAS;GAElC,IAAI,KAAK,gBAAgB,OAAO,KAAK,KAAK,gBAAgB,MAAM;EAClE;EAGA,MAAM,EAAE,mBAAmB,KAAK;EAShC,IAAI,EAPF,CAAC,kBACD,eAAe,WAAW,KAC1B,eAAe,SAAS,GAAG,KAC3B,eACG,QAAQ,QAAQ,QAAQ,GAAG,KAAK,QAAQ,EAAE,EAC1C,MAAM,QAAQA,gCAAY,KAAK,MAAM,MAAM,CAAC,IAEjC;EAEhB,MAAM,WAAW,KAAK,aAAa,IAAI,IAAI;EAE3C,IAAI,UACF,KAAK,MAAM,WAAW,UACpB,QAAQ,MAAM,WAAW;CAG/B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"CrossFrameStateManager.cjs","names":[],"sources":["../../../src/core/CrossFrameStateManager.ts"],"sourcesContent":["import type { CrossFrameMessenger } from './CrossFrameMessenger';\n\nexport type CrossFrameStateOptions = {\n /** Whether to broadcast state changes to other frames. Default: true */\n emit?: boolean;\n /** Whether to listen for state updates from other frames. Default: true */\n receive?: boolean;\n};\n\n/**\n * CrossFrameStateManager synchronizes a single named value across frames using\n * the postMessage API via CrossFrameMessenger.\n *\n * Protocol:\n * `{key}/post` — broadcast a new value\n * `{key}/get` — request the current value from other frames\n *\n * Replaces useCrossFrameState across all frameworks.\n *\n * @fires change — CustomEvent<T> dispatched whenever the value changes (local set or received)\n */\nexport class CrossFrameStateManager<T> extends EventTarget {\n private _value: T | undefined;\n private readonly _key: string;\n private readonly _messenger: CrossFrameMessenger;\n private readonly _options: Required<CrossFrameStateOptions>;\n private readonly _unsubscribers: Array<() => void> = [];\n\n constructor(\n key: string,\n messenger: CrossFrameMessenger,\n options: CrossFrameStateOptions & { initialValue?: T } = {}\n ) {\n super();\n this._key = key;\n this._messenger = messenger;\n this._options = {\n emit: options.emit ?? true,\n receive: options.receive ?? true,\n };\n if (options.initialValue !== undefined) {\n this._value = options.initialValue;\n }\n }\n\n get value(): T | undefined {\n return this._value;\n }\n\n /** Update the value locally and broadcast it to other frames if emit is enabled. */\n set(newValue: T): void {\n this._value = newValue;\n this.dispatchEvent(new CustomEvent<T>('change', { detail: newValue }));\n if (this._options.emit) {\n this._messenger.send(`${this._key}/post`, newValue);\n }\n }\n\n /**\n * Start listening for incoming state updates and responding to /get requests.\n * If receive=true and no initial value is set, sends a /get to request the current value.\n */\n start(): void {\n if (this._options.receive) {\n const unsub = this._messenger.subscribe<T>(\n `${this._key}/post`,\n (data) => {\n this._value = data;\n this.dispatchEvent(new CustomEvent<T>('change', { detail: data }));\n }\n );\n this._unsubscribers.push(unsub);\n }\n\n if (this._options.emit) {\n // Respond to /get requests by broadcasting current value\n const unsub = this._messenger.subscribe(\n `${this._key}/get`,\n (_, originSenderId) => {\n if (originSenderId === this._messenger.senderId) return;\n if (this._value === undefined) return;\n this._messenger.send(`${this._key}/post`, this._value);\n }\n );\n this._unsubscribers.push(unsub);\n }\n\n // If receiving and no initial value, request it from other frames\n if (this._options.receive && this._value === undefined) {\n this._messenger.send(`${this._key}/get`);\n }\n }\n\n /** Stop all listeners. */\n stop(): void {\n for (const unsub of this._unsubscribers) unsub();\n this._unsubscribers.length = 0;\n }\n\n /** Broadcast the current value to all frames (useful after recon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AAW,KAAK,GAAG,KAAK,KAAK,MAAM;;;CAK5C,OAAa;EACX,KAAK,MAAM,SAAS,KAAK,gBAAgB,OAAO;EAChD,KAAK,eAAe,SAAS;;;CAI/B,mBAAyB;EACvB,IAAI,KAAK,WAAW,QAClB,KAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,OAAO"}
1
+ {"version":3,"file":"CrossFrameStateManager.cjs","names":[],"sources":["../../../src/core/CrossFrameStateManager.ts"],"sourcesContent":["import type { CrossFrameMessenger } from './CrossFrameMessenger';\n\nexport type CrossFrameStateOptions = {\n /** Whether to broadcast state changes to other frames. Default: true */\n emit?: boolean;\n /** Whether to listen for state updates from other frames. Default: true */\n receive?: boolean;\n};\n\n/**\n * CrossFrameStateManager synchronizes a single named value across frames using\n * the postMessage API via CrossFrameMessenger.\n *\n * Protocol:\n * `{key}/post` — broadcast a new value\n * `{key}/get` — request the current value from other frames\n *\n * Replaces useCrossFrameState across all frameworks.\n *\n * @fires change — CustomEvent<T> dispatched whenever the value changes (local set or received)\n */\nexport class CrossFrameStateManager<T> extends EventTarget {\n private _value: T | undefined;\n private readonly _key: string;\n private readonly _messenger: CrossFrameMessenger;\n private readonly _options: Required<CrossFrameStateOptions>;\n private readonly _unsubscribers: Array<() => void> = [];\n\n constructor(\n key: string,\n messenger: CrossFrameMessenger,\n options: CrossFrameStateOptions & { initialValue?: T } = {}\n ) {\n super();\n this._key = key;\n this._messenger = messenger;\n this._options = {\n emit: options.emit ?? true,\n receive: options.receive ?? true,\n };\n if (options.initialValue !== undefined) {\n this._value = options.initialValue;\n }\n }\n\n get value(): T | undefined {\n return this._value;\n }\n\n /** Update the value locally and broadcast it to other frames if emit is enabled. */\n set(newValue: T): void {\n this._value = newValue;\n this.dispatchEvent(new CustomEvent<T>('change', { detail: newValue }));\n if (this._options.emit) {\n this._messenger.send(`${this._key}/post`, newValue);\n }\n }\n\n /**\n * Start listening for incoming state updates and responding to /get requests.\n * If receive=true and no initial value is set, sends a /get to request the current value.\n */\n start(): void {\n if (this._options.receive) {\n const unsub = this._messenger.subscribe<T>(\n `${this._key}/post`,\n (data) => {\n this._value = data;\n this.dispatchEvent(new CustomEvent<T>('change', { detail: data }));\n }\n );\n this._unsubscribers.push(unsub);\n }\n\n if (this._options.emit) {\n // Respond to /get requests by broadcasting current value\n const unsub = this._messenger.subscribe(\n `${this._key}/get`,\n (_, originSenderId) => {\n if (originSenderId === this._messenger.senderId) return;\n if (this._value === undefined) return;\n this._messenger.send(`${this._key}/post`, this._value);\n }\n );\n this._unsubscribers.push(unsub);\n }\n\n // If receiving and no initial value, request it from other frames\n if (this._options.receive && this._value === undefined) {\n this._messenger.send(`${this._key}/get`);\n }\n }\n\n /** Stop all listeners. */\n stop(): void {\n for (const unsub of this._unsubscribers) unsub();\n this._unsubscribers.length = 0;\n }\n\n /** Broadcast the current value to all frames (useful after reconnect). */\n postCurrentValue(): void {\n if (this._value !== undefined) {\n this._messenger.send(`${this._key}/post`, this._value);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,IAAa,yBAAb,cAA+C,YAAY;CACzD,AAAQ;CACR,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB,iBAAoC,CAAC;CAEtD,YACE,KACA,WACA,UAAyD,CAAC,GAC1D;EACA,MAAM;EACN,KAAK,OAAO;EACZ,KAAK,aAAa;EAClB,KAAK,WAAW;GACd,MAAM,QAAQ,QAAQ;GACtB,SAAS,QAAQ,WAAW;EAC9B;EACA,IAAI,QAAQ,iBAAiB,QAC3B,KAAK,SAAS,QAAQ;CAE1B;CAEA,IAAI,QAAuB;EACzB,OAAO,KAAK;CACd;;CAGA,IAAI,UAAmB;EACrB,KAAK,SAAS;EACd,KAAK,cAAc,IAAI,YAAe,UAAU,EAAE,QAAQ,SAAS,CAAC,CAAC;EACrE,IAAI,KAAK,SAAS,MAChB,KAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,QAAQ;CAEtD;;;;;CAMA,QAAc;EACZ,IAAI,KAAK,SAAS,SAAS;GACzB,MAAM,QAAQ,KAAK,WAAW,UAC5B,GAAG,KAAK,KAAK,SACZ,SAAS;IACR,KAAK,SAAS;IACd,KAAK,cAAc,IAAI,YAAe,UAAU,EAAE,QAAQ,KAAK,CAAC,CAAC;GACnE,CACF;GACA,KAAK,eAAe,KAAK,KAAK;EAChC;EAEA,IAAI,KAAK,SAAS,MAAM;GAEtB,MAAM,QAAQ,KAAK,WAAW,UAC5B,GAAG,KAAK,KAAK,QACZ,GAAG,mBAAmB;IACrB,IAAI,mBAAmB,KAAK,WAAW,UAAU;IACjD,IAAI,KAAK,WAAW,QAAW;IAC/B,KAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,MAAM;GACvD,CACF;GACA,KAAK,eAAe,KAAK,KAAK;EAChC;EAGA,IAAI,KAAK,SAAS,WAAW,KAAK,WAAW,QAC3C,KAAK,WAAW,KAAK,GAAG,KAAK,KAAK,KAAK;CAE3C;;CAGA,OAAa;EACX,KAAK,MAAM,SAAS,KAAK,gBAAgB,MAAM;EAC/C,KAAK,eAAe,SAAS;CAC/B;;CAGA,mBAAyB;EACvB,IAAI,KAAK,WAAW,QAClB,KAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,MAAM;CAEzD;AACF"}
@@ -3,6 +3,8 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
3
  const require_messageKey = require('../messageKey.cjs');
4
4
  const require_core_CrossFrameMessenger = require('./CrossFrameMessenger.cjs');
5
5
  const require_core_CrossFrameStateManager = require('./CrossFrameStateManager.cjs');
6
+ const require_core_editedContentBus = require('./editedContentBus.cjs');
7
+ const require_core_focusedContentBus = require('./focusedContentBus.cjs');
6
8
  const require_core_IframeClickInterceptor = require('./IframeClickInterceptor.cjs');
7
9
  const require_core_UrlStateManager = require('./UrlStateManager.cjs');
8
10
  let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
@@ -26,6 +28,7 @@ var EditorStateManager = class {
26
28
  editedContent;
27
29
  configuration;
28
30
  currentLocale;
31
+ displayedDictionaryKeys;
29
32
  _urlManager;
30
33
  _iframeInterceptor;
31
34
  _mode;
@@ -33,6 +36,15 @@ var EditorStateManager = class {
33
36
  _unsubAreYouThere = null;
34
37
  _unsubActivate = null;
35
38
  _unsubClientReady = null;
39
+ _displayedKeysObserver = null;
40
+ _displayedKeysTimer = null;
41
+ _displayedKeysListeners = [];
42
+ _editedContentFromBus = false;
43
+ _unsubGlobalEditedContent = null;
44
+ _editedContentBusHandler = null;
45
+ _focusedContentFromBus = false;
46
+ _unsubGlobalFocusedContent = null;
47
+ _focusedContentBusHandler = null;
36
48
  constructor(config) {
37
49
  this._mode = config.mode;
38
50
  this._configuration = config.configuration;
@@ -58,6 +70,11 @@ var EditorStateManager = class {
58
70
  emit: config.mode === "client",
59
71
  receive: config.mode === "editor"
60
72
  });
73
+ this.displayedDictionaryKeys = new require_core_CrossFrameStateManager.CrossFrameStateManager("INTLAYER_DISPLAYED_DICTIONARY_KEYS", this.messenger, {
74
+ emit: config.mode === "client",
75
+ receive: config.mode === "editor",
76
+ initialValue: []
77
+ });
61
78
  this._urlManager = new require_core_UrlStateManager.UrlStateManager(this.messenger);
62
79
  this._iframeInterceptor = new require_core_IframeClickInterceptor.IframeClickInterceptor(this.messenger);
63
80
  }
@@ -69,10 +86,14 @@ var EditorStateManager = class {
69
86
  this.editedContent.start();
70
87
  this.configuration.start();
71
88
  this.currentLocale.start();
89
+ this.displayedDictionaryKeys.start();
90
+ this._startEditedContentBusSync();
91
+ this._startFocusedContentBusSync();
72
92
  if (this._mode === "client") {
73
93
  this._urlManager.start();
74
94
  this._iframeInterceptor.startInterceptor();
75
95
  this._loadDictionaries();
96
+ this._startDisplayedDictionariesTracking();
76
97
  this.messenger.send(`${"INTLAYER_EDITED_CONTENT_CHANGED"}/get`);
77
98
  if (this._configuration?.editor?.enabled !== false) this._setupActivationHandshake();
78
99
  } else {
@@ -94,6 +115,10 @@ var EditorStateManager = class {
94
115
  this.editedContent.stop();
95
116
  this.configuration.stop();
96
117
  this.currentLocale.stop();
118
+ this.displayedDictionaryKeys.stop();
119
+ this._stopDisplayedDictionariesTracking();
120
+ this._stopEditedContentBusSync();
121
+ this._stopFocusedContentBusSync();
97
122
  this._urlManager.stop();
98
123
  this._iframeInterceptor.stopInterceptor();
99
124
  this._iframeInterceptor.stopMerger();
@@ -224,6 +249,96 @@ var EditorStateManager = class {
224
249
  if (node) return node;
225
250
  }
226
251
  }
252
+ _startEditedContentBusSync() {
253
+ this._editedContentBusHandler = (e) => {
254
+ if (this._editedContentFromBus) return;
255
+ const content = e.detail;
256
+ require_core_editedContentBus.setGlobalEditedContent(content, this.messenger.senderId);
257
+ };
258
+ this.editedContent.addEventListener("change", this._editedContentBusHandler);
259
+ this._unsubGlobalEditedContent = require_core_editedContentBus.subscribeToGlobalEditedContent((content, sourceId) => {
260
+ if (sourceId === this.messenger.senderId) return;
261
+ this._editedContentFromBus = true;
262
+ this.editedContent.set(content);
263
+ this._editedContentFromBus = false;
264
+ });
265
+ const existing = require_core_editedContentBus.getGlobalEditedContent();
266
+ if (Object.keys(existing).length > 0) {
267
+ this._editedContentFromBus = true;
268
+ this.editedContent.set(existing);
269
+ this._editedContentFromBus = false;
270
+ }
271
+ }
272
+ _stopEditedContentBusSync() {
273
+ if (this._editedContentBusHandler) {
274
+ this.editedContent.removeEventListener("change", this._editedContentBusHandler);
275
+ this._editedContentBusHandler = null;
276
+ }
277
+ this._unsubGlobalEditedContent?.();
278
+ this._unsubGlobalEditedContent = null;
279
+ }
280
+ _startFocusedContentBusSync() {
281
+ this._focusedContentBusHandler = (e) => {
282
+ if (this._focusedContentFromBus) return;
283
+ const content = e.detail;
284
+ require_core_focusedContentBus.setGlobalFocusedContent(content, this.messenger.senderId);
285
+ };
286
+ this.focusedContent.addEventListener("change", this._focusedContentBusHandler);
287
+ this._unsubGlobalFocusedContent = require_core_focusedContentBus.subscribeToGlobalFocusedContent((content, sourceId) => {
288
+ if (sourceId === this.messenger.senderId) return;
289
+ this._focusedContentFromBus = true;
290
+ this.focusedContent.set(content);
291
+ this._focusedContentFromBus = false;
292
+ });
293
+ const existing = require_core_focusedContentBus.getGlobalFocusedContent();
294
+ if (existing !== void 0) {
295
+ this._focusedContentFromBus = true;
296
+ this.focusedContent.set(existing);
297
+ this._focusedContentFromBus = false;
298
+ }
299
+ }
300
+ _stopFocusedContentBusSync() {
301
+ if (this._focusedContentBusHandler) {
302
+ this.focusedContent.removeEventListener("change", this._focusedContentBusHandler);
303
+ this._focusedContentBusHandler = null;
304
+ }
305
+ this._unsubGlobalFocusedContent?.();
306
+ this._unsubGlobalFocusedContent = null;
307
+ }
308
+ _scanDisplayedDictionaryKeys() {
309
+ if (typeof document === "undefined") return;
310
+ const elements = document.querySelectorAll("intlayer-content-selector-wrapper[dictionary-key]");
311
+ const keys = Array.from(new Set(Array.from(elements).map((el) => el.getAttribute("dictionary-key") ?? "").filter(Boolean)));
312
+ this.displayedDictionaryKeys.set(keys);
313
+ }
314
+ _startDisplayedDictionariesTracking() {
315
+ if (typeof document === "undefined" || typeof MutationObserver === "undefined") return;
316
+ const schedule = () => {
317
+ if (this._displayedKeysTimer) clearTimeout(this._displayedKeysTimer);
318
+ this._displayedKeysTimer = setTimeout(() => this._scanDisplayedDictionaryKeys(), 100);
319
+ };
320
+ this._displayedKeysObserver = new MutationObserver(schedule);
321
+ this._displayedKeysObserver.observe(document.body, {
322
+ childList: true,
323
+ subtree: true
324
+ });
325
+ for (const evt of ["locationchange", "popstate"]) {
326
+ const listener = schedule;
327
+ window.addEventListener(evt, listener);
328
+ this._displayedKeysListeners.push([evt, listener]);
329
+ }
330
+ this._scanDisplayedDictionaryKeys();
331
+ }
332
+ _stopDisplayedDictionariesTracking() {
333
+ this._displayedKeysObserver?.disconnect();
334
+ this._displayedKeysObserver = null;
335
+ if (this._displayedKeysTimer) {
336
+ clearTimeout(this._displayedKeysTimer);
337
+ this._displayedKeysTimer = null;
338
+ }
339
+ for (const [evt, listener] of this._displayedKeysListeners) window.removeEventListener(evt, listener);
340
+ this._displayedKeysListeners = [];
341
+ }
227
342
  /**
228
343
  * EDITOR mode: listen for CLIENT_READY and respond with EDITOR_ACTIVATE.
229
344
  * Also pings the client immediately in case it loaded before the editor.