@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
@@ -1 +1 @@
1
- {"version":3,"file":"EditedContent.mjs","names":[],"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,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mjs","names":[],"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,CAAC;;;;;;;;;;;;;;;AAgBd,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;EAAQ;CAChD;CAEA,IAAI,gBAAwB;EAC1B,OAAO,KAAK;CACd;CACA,IAAI,cAAc,GAAW;EAC3B,KAAK,iBAAiB;EACtB,KAAK,iBAAiB,aAAa,kBAAkB,CAAC;CACxD;CAEA,IAAI,cAAsB;EACxB,OAAO,KAAK;CACd;CACA,IAAI,YAAY,GAAW;EACzB,KAAK,eAAe;EACpB,KAAK,iBAAiB,aAAa,YAAY,CAAC;CAClD;CAEA,IAAI,SAAiB;EACnB,OAAO,KAAK;CACd;CACA,IAAI,OAAO,GAAW;EACpB,KAAK,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layerEditor.mjs","names":[],"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,wBAAb,cAA2C,aAAa;CACtD,AAAQ,iBAA6C;CACrD,AAAQ,UAA8B;CACtC,AAAQ,eAAe;CACvB,AAAQ,gBAAqC;CAE7C,WAAW,qBAA+B;EACxC,OAAO,CAAC,SAAS;;CAGnB,IAAI,gBAA4C;EAC9C,OAAO,KAAK;;CAEd,IAAI,cAAc,GAA+B;EAC/C,KAAK,iBAAiB;EACtB,IAAI,CAAC,KAAK,cAAc,KAAK,OAAO;;CAGtC,IAAI,SAA6B;EAC/B,OAAO,KAAK;;CAEd,IAAI,OAAO,GAAuB;EAChC,KAAK,UAAU;EACf,IAAI,KAAK,KAAK,cAAc,KAAK,YAAY,EAAE;;CAGjD,yBACE,MACA,SACA,QACM;EACN,IAAI,SAAS,YAAY,WAAW,MAAM;GACxC,KAAK,UAAU;GACf,IAAI,KAAK,cAAc,KAAK,YAAY,OAAO;;;CAInD,oBAA0B;EACxB,KAAK,OAAO;;CAGd,uBAA6B;EAC3B,KAAK,iBAAiB;EACtB,KAAK,gBAAgB;EACrB,IAAI,KAAK,cAAc;GACrB,kBAAkB;GAClB,KAAK,eAAe;;;CAIxB,AAAQ,QAAc;EACpB,IAAI,KAAK,cAAc;EACvB,kBAAkB;EAClB,KAAK,eAAe;EACpB,IAAI,KAAK,SAAS,KAAK,YAAY,KAAK,QAAQ;;CAGlD,AAAQ,YAAY,QAAsB;EACxC,MAAM,UAAU,wBAAwB;EACxC,IAAI,SACF,QAAQ,cAAc,IAAI,OAAiB;OACtC;GAEL,KAAK,iBAAiB;GACtB,KAAK,gBAAgB,6BAA6B,MAAM;IACtD,IAAI,GAAG;KACL,KAAK,iBAAiB;KACtB,KAAK,gBAAgB;KACrB,EAAE,cAAc,IAAI,OAAiB;;KAEvC;;;;AAKR,MAAa,oCAA0C;CACrD,IAAI,OAAO,mBAAmB,aAAa;CAC3C,IAAI,CAAC,eAAe,IAAI,kBAAkB,EACxC,eAAe,OAAO,mBAAmB,sBAAsB"}
1
+ {"version":3,"file":"IntlayerEditor.mjs","names":[],"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,iBAAiB;GACjB,KAAK,eAAe;EACtB;CACF;CAEA,AAAQ,QAAc;EACpB,IAAI,KAAK,cAAc;EACvB,iBAAiB;EACjB,KAAK,eAAe;EACpB,IAAI,KAAK,SAAS,KAAK,YAAY,KAAK,OAAO;CACjD;CAEA,AAAQ,YAAY,QAAsB;EACxC,MAAM,UAAU,uBAAuB;EACvC,IAAI,SACF,QAAQ,cAAc,IAAI,MAAgB;OACrC;GAEL,KAAK,gBAAgB;GACrB,KAAK,gBAAgB,6BAA6B,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.mjs","names":[],"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,gBAAg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../../../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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jC;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.mjs","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,EAAE;CAEvD,YACE,KACA,WACA,UAAyD,EAAE,EAC3D;EACA,OAAO;EACP,KAAK,OAAO;EACZ,KAAK,aAAa;EAClB,KAAK,WAAW;GACd,MAAM,QAAQ,QAAQ;GACtB,SAAS,QAAQ,WAAW;GAC7B;EACD,IAAI,QAAQ,iBAAiB,QAC3B,KAAK,SAAS,QAAQ;;CAI1B,IAAI,QAAuB;EACzB,OAAO,KAAK;;;CAId,IAAI,UAAmB;EACrB,KAAK,SAAS;EACd,KAAK,cAAc,IAAI,YAAe,UAAU,EAAE,QAAQ,UAAU,CAAC,CAAC;EACtE,IAAI,KAAK,SAAS,MAChB,KAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,SAAS;;;;;;CAQvD,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,MAAM,CAAC,CAAC;KAErE;GACD,KAAK,eAAe,KAAK,MAAM;;EAGjC,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,OAAO;KAEzD;GACD,KAAK,eAAe,KAAK,MAAM;;EAIjC,IAAI,KAAK,SAAS,WAAW,KAAK,WAAW,QAC3C,KAAK,WAAW,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.mjs","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,W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,KAAK,QAAQ,KAAK,MAAM;CAEzD;AACF"}
@@ -1,6 +1,8 @@
1
1
  import { MessageKey } from "../messageKey.mjs";
2
2
  import { CrossFrameMessenger } from "./CrossFrameMessenger.mjs";
3
3
  import { CrossFrameStateManager } from "./CrossFrameStateManager.mjs";
4
+ import { getGlobalEditedContent, setGlobalEditedContent, subscribeToGlobalEditedContent } from "./editedContentBus.mjs";
5
+ import { getGlobalFocusedContent, setGlobalFocusedContent, subscribeToGlobalFocusedContent } from "./focusedContentBus.mjs";
4
6
  import { IframeClickInterceptor } from "./IframeClickInterceptor.mjs";
5
7
  import { UrlStateManager } from "./UrlStateManager.mjs";
6
8
  import * as NodeTypes from "@intlayer/types/nodeType";
@@ -23,6 +25,7 @@ var EditorStateManager = class {
23
25
  editedContent;
24
26
  configuration;
25
27
  currentLocale;
28
+ displayedDictionaryKeys;
26
29
  _urlManager;
27
30
  _iframeInterceptor;
28
31
  _mode;
@@ -30,6 +33,15 @@ var EditorStateManager = class {
30
33
  _unsubAreYouThere = null;
31
34
  _unsubActivate = null;
32
35
  _unsubClientReady = null;
36
+ _displayedKeysObserver = null;
37
+ _displayedKeysTimer = null;
38
+ _displayedKeysListeners = [];
39
+ _editedContentFromBus = false;
40
+ _unsubGlobalEditedContent = null;
41
+ _editedContentBusHandler = null;
42
+ _focusedContentFromBus = false;
43
+ _unsubGlobalFocusedContent = null;
44
+ _focusedContentBusHandler = null;
33
45
  constructor(config) {
34
46
  this._mode = config.mode;
35
47
  this._configuration = config.configuration;
@@ -55,6 +67,11 @@ var EditorStateManager = class {
55
67
  emit: config.mode === "client",
56
68
  receive: config.mode === "editor"
57
69
  });
70
+ this.displayedDictionaryKeys = new CrossFrameStateManager("INTLAYER_DISPLAYED_DICTIONARY_KEYS", this.messenger, {
71
+ emit: config.mode === "client",
72
+ receive: config.mode === "editor",
73
+ initialValue: []
74
+ });
58
75
  this._urlManager = new UrlStateManager(this.messenger);
59
76
  this._iframeInterceptor = new IframeClickInterceptor(this.messenger);
60
77
  }
@@ -66,10 +83,14 @@ var EditorStateManager = class {
66
83
  this.editedContent.start();
67
84
  this.configuration.start();
68
85
  this.currentLocale.start();
86
+ this.displayedDictionaryKeys.start();
87
+ this._startEditedContentBusSync();
88
+ this._startFocusedContentBusSync();
69
89
  if (this._mode === "client") {
70
90
  this._urlManager.start();
71
91
  this._iframeInterceptor.startInterceptor();
72
92
  this._loadDictionaries();
93
+ this._startDisplayedDictionariesTracking();
73
94
  this.messenger.send(`${"INTLAYER_EDITED_CONTENT_CHANGED"}/get`);
74
95
  if (this._configuration?.editor?.enabled !== false) this._setupActivationHandshake();
75
96
  } else {
@@ -91,6 +112,10 @@ var EditorStateManager = class {
91
112
  this.editedContent.stop();
92
113
  this.configuration.stop();
93
114
  this.currentLocale.stop();
115
+ this.displayedDictionaryKeys.stop();
116
+ this._stopDisplayedDictionariesTracking();
117
+ this._stopEditedContentBusSync();
118
+ this._stopFocusedContentBusSync();
94
119
  this._urlManager.stop();
95
120
  this._iframeInterceptor.stopInterceptor();
96
121
  this._iframeInterceptor.stopMerger();
@@ -221,6 +246,96 @@ var EditorStateManager = class {
221
246
  if (node) return node;
222
247
  }
223
248
  }
249
+ _startEditedContentBusSync() {
250
+ this._editedContentBusHandler = (e) => {
251
+ if (this._editedContentFromBus) return;
252
+ const content = e.detail;
253
+ setGlobalEditedContent(content, this.messenger.senderId);
254
+ };
255
+ this.editedContent.addEventListener("change", this._editedContentBusHandler);
256
+ this._unsubGlobalEditedContent = subscribeToGlobalEditedContent((content, sourceId) => {
257
+ if (sourceId === this.messenger.senderId) return;
258
+ this._editedContentFromBus = true;
259
+ this.editedContent.set(content);
260
+ this._editedContentFromBus = false;
261
+ });
262
+ const existing = getGlobalEditedContent();
263
+ if (Object.keys(existing).length > 0) {
264
+ this._editedContentFromBus = true;
265
+ this.editedContent.set(existing);
266
+ this._editedContentFromBus = false;
267
+ }
268
+ }
269
+ _stopEditedContentBusSync() {
270
+ if (this._editedContentBusHandler) {
271
+ this.editedContent.removeEventListener("change", this._editedContentBusHandler);
272
+ this._editedContentBusHandler = null;
273
+ }
274
+ this._unsubGlobalEditedContent?.();
275
+ this._unsubGlobalEditedContent = null;
276
+ }
277
+ _startFocusedContentBusSync() {
278
+ this._focusedContentBusHandler = (e) => {
279
+ if (this._focusedContentFromBus) return;
280
+ const content = e.detail;
281
+ setGlobalFocusedContent(content, this.messenger.senderId);
282
+ };
283
+ this.focusedContent.addEventListener("change", this._focusedContentBusHandler);
284
+ this._unsubGlobalFocusedContent = subscribeToGlobalFocusedContent((content, sourceId) => {
285
+ if (sourceId === this.messenger.senderId) return;
286
+ this._focusedContentFromBus = true;
287
+ this.focusedContent.set(content);
288
+ this._focusedContentFromBus = false;
289
+ });
290
+ const existing = getGlobalFocusedContent();
291
+ if (existing !== void 0) {
292
+ this._focusedContentFromBus = true;
293
+ this.focusedContent.set(existing);
294
+ this._focusedContentFromBus = false;
295
+ }
296
+ }
297
+ _stopFocusedContentBusSync() {
298
+ if (this._focusedContentBusHandler) {
299
+ this.focusedContent.removeEventListener("change", this._focusedContentBusHandler);
300
+ this._focusedContentBusHandler = null;
301
+ }
302
+ this._unsubGlobalFocusedContent?.();
303
+ this._unsubGlobalFocusedContent = null;
304
+ }
305
+ _scanDisplayedDictionaryKeys() {
306
+ if (typeof document === "undefined") return;
307
+ const elements = document.querySelectorAll("intlayer-content-selector-wrapper[dictionary-key]");
308
+ const keys = Array.from(new Set(Array.from(elements).map((el) => el.getAttribute("dictionary-key") ?? "").filter(Boolean)));
309
+ this.displayedDictionaryKeys.set(keys);
310
+ }
311
+ _startDisplayedDictionariesTracking() {
312
+ if (typeof document === "undefined" || typeof MutationObserver === "undefined") return;
313
+ const schedule = () => {
314
+ if (this._displayedKeysTimer) clearTimeout(this._displayedKeysTimer);
315
+ this._displayedKeysTimer = setTimeout(() => this._scanDisplayedDictionaryKeys(), 100);
316
+ };
317
+ this._displayedKeysObserver = new MutationObserver(schedule);
318
+ this._displayedKeysObserver.observe(document.body, {
319
+ childList: true,
320
+ subtree: true
321
+ });
322
+ for (const evt of ["locationchange", "popstate"]) {
323
+ const listener = schedule;
324
+ window.addEventListener(evt, listener);
325
+ this._displayedKeysListeners.push([evt, listener]);
326
+ }
327
+ this._scanDisplayedDictionaryKeys();
328
+ }
329
+ _stopDisplayedDictionariesTracking() {
330
+ this._displayedKeysObserver?.disconnect();
331
+ this._displayedKeysObserver = null;
332
+ if (this._displayedKeysTimer) {
333
+ clearTimeout(this._displayedKeysTimer);
334
+ this._displayedKeysTimer = null;
335
+ }
336
+ for (const [evt, listener] of this._displayedKeysListeners) window.removeEventListener(evt, listener);
337
+ this._displayedKeysListeners = [];
338
+ }
224
339
  /**
225
340
  * EDITOR mode: listen for CLIENT_READY and respond with EDITOR_ACTIVATE.
226
341
  * Also pings the client immediately in case it loaded before the editor.
@@ -1 +1 @@
1
- {"version":3,"file":"EditorStateManager.mjs","names":[],"sources":["../../../src/core/EditorStateManager.ts"],"sourcesContent":["import {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { MessageKey } from '../messageKey';\nimport {\n CrossFrameMessenger,\n type MessengerConfig,\n} from './CrossFrameMessenger';\nimport { CrossFrameStateManager } from './CrossFrameStateManager';\nimport { IframeClickInterceptor } from './IframeClickInterceptor';\nimport { UrlStateManager } from './UrlStateManager';\n\nexport type DictionaryContent = Record<LocalDictionaryId, Dictionary>;\n\nexport type FileContent = {\n dictionaryKey: string;\n dictionaryLocalId?: LocalDictionaryId;\n keyPath?: KeyPath[];\n};\n\nexport type EditorStateManagerConfig = {\n /** 'client' = the app running inside the iframe; 'editor' = the editor wrapping the app */\n mode: 'editor' | 'client';\n /** Cross-frame messaging configuration */\n messenger: MessengerConfig;\n /** Optional initial Intlayer configuration to broadcast */\n configuration?: IntlayerConfig;\n};\n\n/**\n * EditorStateManager is the single entry point for all Intlayer editor state.\n * It is framework-agnostic: instantiate one instance at the root of the application\n * and subscribe to its EventTarget-based events from any framework adapter.\n *\n * Replaces all context providers, hooks and store files across React, Preact,\n * Solid, Svelte, and Vue integrations.\n */\nexport class EditorStateManager {\n readonly messenger: CrossFrameMessenger;\n readonly editorEnabled: CrossFrameStateManager<boolean>;\n readonly focusedContent: CrossFrameStateManager<FileContent | null>;\n readonly localeDictionaries: CrossFrameStateManager<DictionaryContent>;\n readonly editedContent: CrossFrameStateManager<DictionaryContent>;\n readonly configuration: CrossFrameStateManager<IntlayerConfig>;\n readonly currentLocale: CrossFrameStateManager<Locale | undefined>;\n\n private readonly _urlManager: UrlStateManager;\n private readonly _iframeInterceptor: IframeClickInterceptor;\n private readonly _mode: 'editor' | 'client';\n private readonly _configuration: IntlayerConfig | undefined;\n\n // Client-mode handshake subscribers\n private _unsubAreYouThere: (() => void) | null = null;\n private _unsubActivate: (() => void) | null = null;\n // Editor-mode handshake subscriber\n private _unsubClientReady: (() => void) | null = null;\n\n constructor(config: EditorStateManagerConfig) {\n this._mode = config.mode;\n this._configuration = config.configuration;\n\n this.messenger = new CrossFrameMessenger(config.messenger);\n\n this.editorEnabled = new CrossFrameStateManager<boolean>(\n MessageKey.INTLAYER_EDITOR_ENABLED,\n this.messenger,\n { emit: false, receive: true, initialValue: false }\n );\n\n this.focusedContent = new CrossFrameStateManager<FileContent | null>(\n MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,\n this.messenger,\n { emit: true, receive: true, initialValue: null }\n );\n\n this.localeDictionaries = new CrossFrameStateManager<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n this.messenger\n );\n\n this.editedContent = new CrossFrameStateManager<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED,\n this.messenger\n );\n\n this.configuration = new CrossFrameStateManager<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n this.messenger,\n {\n emit: true,\n receive: false,\n ...(config.configuration ? { initialValue: config.configuration } : {}),\n }\n );\n\n // Client emits its locale to the editor; editor receives it.\n this.currentLocale = new CrossFrameStateManager<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n this.messenger,\n {\n emit: config.mode === 'client',\n receive: config.mode === 'editor',\n }\n );\n\n this._urlManager = new UrlStateManager(this.messenger);\n this._iframeInterceptor = new IframeClickInterceptor(this.messenger);\n }\n\n start(): void {\n this.messenger.start();\n this.editorEnabled.start();\n this.focusedContent.start();\n this.localeDictionaries.start();\n this.editedContent.start();\n this.configuration.start();\n this.currentLocale.start();\n\n if (this._mode === 'client') {\n this._urlManager.start();\n this._iframeInterceptor.startInterceptor();\n this._loadDictionaries();\n // Request current edited content from the editor\n this.messenger.send(`${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`);\n // Activation handshake: only participate if editor.enabled !== false\n if (this._configuration?.editor?.enabled !== false) {\n this._setupActivationHandshake();\n }\n } else {\n this._iframeInterceptor.startMerger();\n this._setupEditorHandshake();\n }\n }\n\n stop(): void {\n this._unsubAreYouThere?.();\n this._unsubActivate?.();\n this._unsubClientReady?.();\n this._unsubAreYouThere = null;\n this._unsubActivate = null;\n this._unsubClientReady = null;\n this.messenger.stop();\n this.editorEnabled.stop();\n this.focusedContent.stop();\n this.localeDictionaries.stop();\n this.editedContent.stop();\n this.configuration.stop();\n this.currentLocale.stop();\n this._urlManager.stop();\n this._iframeInterceptor.stopInterceptor();\n this._iframeInterceptor.stopMerger();\n }\n\n // ─── Handshake helpers ───────────────────────────────────────────────────────\n\n /**\n * EDITOR mode: re-send ARE_YOU_THERE to attempt re-connection with the client.\n * Call this when the user clicks \"Enable Editor\" or when the iframe reloads.\n */\n pingClient(): void {\n if (this._mode !== 'editor') return;\n\n this.messenger.send(MessageKey.INTLAYER_ARE_YOU_THERE);\n }\n\n // ─── Focus helpers ──────────────────────────────────────────────────────────\n\n setFocusedContentKeyPath(keyPath: KeyPath[]): void {\n const filtered = keyPath.filter(\n (key) => key.type !== NodeTypes.TRANSLATION\n );\n const prev = this.focusedContent.value;\n\n if (!prev) return;\n\n this.focusedContent.set({ ...prev, keyPath: filtered });\n }\n\n // ─── Dictionary record helpers ───────────────────────────────────────────\n\n setLocaleDictionary(dictionary: Dictionary): void {\n if (!dictionary.localId) return;\n const current = this.localeDictionaries.value ?? {};\n\n this.localeDictionaries.set({\n ...current,\n [dictionary.localId as LocalDictionaryId]: dictionary,\n });\n }\n\n // ─── Edited content helpers ───────────────────────────────────────────────\n\n setEditedDictionary(newDict: Dictionary): void {\n if (!newDict.localId) {\n console.error('setEditedDictionary: missing localId', newDict);\n return;\n }\n const current = this.editedContent.value ?? {};\n\n this.editedContent.set({\n ...current,\n [newDict.localId as LocalDictionaryId]: newDict,\n });\n }\n\n setEditedContent(\n localDictionaryId: LocalDictionaryId,\n newValue: Dictionary['content']\n ): void {\n const current = this.editedContent.value ?? {};\n\n this.editedContent.set({\n ...current,\n [localDictionaryId]: {\n ...current[localDictionaryId],\n content: newValue,\n },\n });\n }\n\n addContent(\n localDictionaryId: LocalDictionaryId,\n newValue: ContentNode,\n keyPath: KeyPath[] = [],\n overwrite = true\n ): void {\n const current = this.editedContent.value ?? {};\n const localeDicts = this.localeDictionaries.value ?? {};\n\n const originalContent = localeDicts[localDictionaryId]?.content;\n const currentContent = structuredClone(\n current[localDictionaryId]?.content ?? originalContent\n );\n\n let newKeyPath = keyPath;\n if (!overwrite) {\n let index = 0;\n\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath = keyPath[keyPath.length - 1];\n\n let finalKey = lastKeyPath.key;\n\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n this.editedContent.set({\n ...current,\n [localDictionaryId]: {\n ...current[localDictionaryId],\n content: updatedContent as Dictionary['content'],\n },\n });\n }\n\n renameContent(\n localDictionaryId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath: KeyPath[] = []\n ): void {\n const current = this.editedContent.value ?? {};\n const localeDicts = this.localeDictionaries.value ?? {};\n const originalContent = localeDicts[localDictionaryId]?.content;\n const currentContent = structuredClone(\n current[localDictionaryId]?.content ?? originalContent\n );\n const updated = renameContentNodeByKeyPath(currentContent, newKey, keyPath);\n\n this.editedContent.set({\n ...current,\n [localDictionaryId]: {\n ...current[localDictionaryId],\n content: updated as Dictionary['content'],\n },\n });\n }\n\n removeContent(\n localDictionaryId: LocalDictionaryId,\n keyPath: KeyPath[]\n ): void {\n const current = this.editedContent.value ?? {};\n const localeDicts = this.localeDictionaries.value ?? {};\n const originalContent = localeDicts[localDictionaryId]?.content;\n const currentContent = structuredClone(\n current[localDictionaryId]?.content ?? originalContent\n );\n const initialContent = getContentNodeByKeyPath(originalContent, keyPath);\n const restored = editDictionaryByKeyPath(\n currentContent,\n keyPath,\n initialContent\n );\n\n this.editedContent.set({\n ...current,\n [localDictionaryId]: {\n ...current[localDictionaryId],\n content: restored as Dictionary['content'],\n },\n });\n }\n\n restoreContent(localDictionaryId: LocalDictionaryId): void {\n const current = this.editedContent.value ?? {};\n const updated = { ...current };\n\n delete updated[localDictionaryId];\n\n this.editedContent.set(updated);\n }\n\n clearContent(localDictionaryId: LocalDictionaryId): void {\n const current = this.editedContent.value ?? {};\n const filtered = { ...current };\n\n delete filtered[localDictionaryId];\n\n this.editedContent.set(filtered);\n }\n\n clearAllContent(): void {\n this.editedContent.set({});\n }\n\n getContentValue(\n localDictionaryIdOrKey: LocalDictionaryId | string,\n keyPath: KeyPath[]\n ): ContentNode | undefined {\n const edited = this.editedContent.value;\n if (!edited) return undefined;\n\n const filteredKeyPath = keyPath.filter(\n (key) => key.type !== NodeTypes.TRANSLATION\n );\n\n // Only use edited content entries whose localId is known to this client.\n // This prevents stale edits from other apps (different framework demos) from\n // being applied when the editor sends back its stored editedContent.\n const localeDicts = this.localeDictionaries.value;\n\n const isDictionaryId =\n localDictionaryIdOrKey.includes(':local:') ||\n localDictionaryIdOrKey.includes(':remote:');\n\n if (isDictionaryId) {\n // If localeDictionaries is loaded, verify this localId belongs to us\n if (localeDicts && !(localDictionaryIdOrKey in localeDicts)) {\n return undefined;\n }\n const content =\n edited[localDictionaryIdOrKey as LocalDictionaryId]?.content ?? {};\n\n return getContentNodeByKeyPath(\n content,\n filteredKeyPath,\n this.currentLocale.value\n );\n }\n\n const matchingIds = Object.keys(edited).filter(\n (key) =>\n key.startsWith(`${localDictionaryIdOrKey}:`) &&\n // If localeDictionaries is loaded, only include known localIds\n (!localeDicts || key in localeDicts)\n );\n\n for (const localId of matchingIds) {\n const content = edited[localId as LocalDictionaryId]?.content ?? {};\n const node = getContentNodeByKeyPath(\n content,\n filteredKeyPath,\n this.currentLocale.value\n );\n if (node) return node;\n }\n\n return undefined;\n }\n\n /**\n * EDITOR mode: listen for CLIENT_READY and respond with EDITOR_ACTIVATE.\n * Also pings the client immediately in case it loaded before the editor.\n */\n private _setupEditorHandshake(): void {\n // When the client announces it is ready, activate it\n this._unsubClientReady = this.messenger.subscribe(\n MessageKey.INTLAYER_CLIENT_READY,\n () => {\n this.editorEnabled.set(true);\n this.messenger.send(MessageKey.INTLAYER_EDITOR_ACTIVATE);\n }\n );\n\n // Ping any already-running client (covers editor-opens-after-client scenario)\n this.messenger.send(MessageKey.INTLAYER_ARE_YOU_THERE);\n }\n\n private _setupActivationHandshake(): void {\n // Announce to the editor that the client is ready\n this.messenger.send(MessageKey.INTLAYER_CLIENT_READY);\n\n // Respond to \"are you there?\" pings from the editor\n this._unsubAreYouThere = this.messenger.subscribe(\n MessageKey.INTLAYER_ARE_YOU_THERE,\n () => {\n this.messenger.send(MessageKey.INTLAYER_CLIENT_READY);\n }\n );\n\n // When the editor activates us, enable the selector and broadcast state\n this._unsubActivate = this.messenger.subscribe(\n MessageKey.INTLAYER_EDITOR_ACTIVATE,\n () => {\n this.editorEnabled.set(true);\n this._broadcastData();\n }\n );\n }\n\n private _broadcastData(): void {\n const configVal = this.configuration.value;\n\n if (configVal) {\n this.messenger.send(\n `${MessageKey.INTLAYER_CONFIGURATION}/post`,\n configVal\n );\n }\n const localeVal = this.currentLocale.value;\n\n if (localeVal) {\n this.messenger.send(\n `${MessageKey.INTLAYER_CURRENT_LOCALE}/post`,\n localeVal\n );\n }\n const dicts = this.localeDictionaries.value;\n\n if (dicts) {\n this.messenger.send(\n `${MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED}/post`,\n dicts\n );\n }\n }\n\n private async _loadDictionaries(): Promise<void> {\n try {\n const mod = await import('@intlayer/unmerged-dictionaries-entry');\n const unmergedDictionaries = mod.getUnmergedDictionaries();\n const dictionariesList = Object.fromEntries(\n Object.values(unmergedDictionaries)\n .flat()\n .map((dictionary) => [dictionary.localId, dictionary])\n ) as DictionaryContent;\n\n this.localeDictionaries.set(dictionariesList);\n\n // If the editor already activated us before dictionaries finished loading,\n // re-broadcast now so the editor receives the dictionaries.\n if (this.editorEnabled.value) {\n this._broadcastData();\n }\n } catch (e) {\n // Dynamic entry not available (expected in editor mode or when not configured)\n console.warn('[intlayer] Failed to load unmerged dictionaries:', e);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgDA,IAAa,qBAAb,MAAgC;CAC9B,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAGjB,AAAQ,oBAAyC;CACjD,AAAQ,iBAAsC;CAE9C,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rD,KAAK,oBAAoB,KAAK,UAAU,0CAEhC;GACJ,KAAK,UAAU,6BAAsC;IAExD;EAGD,KAAK,iBAAiB,KAAK,UAAU,4CAE7B;GACJ,KAAK,cAAc,IAAI,KAAK;GAC5B,KAAK,gBAAgB;IAExB;;CAGH,AAAQ,iBAAuB;EAC7B,MAAM,YAAY,KAAK,cAAc;EAErC,IAAI,WACF,KAAK,UAAU,KACb,4BAAqC,QACrC,UACD;EAEH,MAAM,YAAY,KAAK,cAAc;EAErC,IAAI,WACF,KAAK,UAAU,KACb,6BAAsC,QACtC,UACD;EAEH,MAAM,QAAQ,KAAK,mBAAmB;EAEtC,IAAI,OACF,KAAK,UAAU,KACb,0CAAmD,QACnD,MACD;;CAIL,MAAc,oBAAmC;EAC/C,IAAI;GAEF,MAAM,wBAAuB,MADX,OAAO,0CACQ,yBAAyB;GAC1D,MAAM,mBAAmB,OAAO,YAC9B,OAAO,OAAO,qBAAqB,CAChC,MAAM,CACN,KAAK,eAAe,CAAC,WAAW,SAAS,WAAW,CAAC,CACzD;GAED,KAAK,mBAAmB,IAAI,iBAAiB;GAI7C,IAAI,KAAK,cAAc,OACrB,KAAK,gBAAgB;WAEhB,GAAG;GAEV,QAAQ,KAAK,oDAAoD,EAAE"}
1
+ {"version":3,"file":"EditorStateManager.mjs","names":[],"sources":["../../../src/core/EditorStateManager.ts"],"sourcesContent":["import {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { MessageKey } from '../messageKey';\nimport {\n CrossFrameMessenger,\n type MessengerConfig,\n} from './CrossFrameMessenger';\nimport { CrossFrameStateManager } from './CrossFrameStateManager';\nimport {\n getGlobalEditedContent,\n setGlobalEditedContent,\n subscribeToGlobalEditedContent,\n} from './editedContentBus';\nimport {\n getGlobalFocusedContent,\n setGlobalFocusedContent,\n subscribeToGlobalFocusedContent,\n} from './focusedContentBus';\nimport { IframeClickInterceptor } from './IframeClickInterceptor';\nimport { UrlStateManager } from './UrlStateManager';\n\nexport type DictionaryContent = Record<LocalDictionaryId, Dictionary>;\n\nexport type FileContent = {\n dictionaryKey: string;\n dictionaryLocalId?: LocalDictionaryId;\n keyPath?: KeyPath[];\n};\n\nexport type EditorStateManagerConfig = {\n /** 'client' = the app running inside the iframe; 'editor' = the editor wrapping the app */\n mode: 'editor' | 'client';\n /** Cross-frame messaging configuration */\n messenger: MessengerConfig;\n /** Optional initial Intlayer configuration to broadcast */\n configuration?: IntlayerConfig;\n};\n\n/**\n * EditorStateManager is the single entry point for all Intlayer editor state.\n * It is framework-agnostic: instantiate one instance at the root of the application\n * and subscribe to its EventTarget-based events from any framework adapter.\n *\n * Replaces all context providers, hooks and store files across React, Preact,\n * Solid, Svelte, and Vue integrations.\n */\nexport class EditorStateManager {\n readonly messenger: CrossFrameMessenger;\n readonly editorEnabled: CrossFrameStateManager<boolean>;\n readonly focusedContent: CrossFrameStateManager<FileContent | null>;\n readonly localeDictionaries: CrossFrameStateManager<DictionaryContent>;\n readonly editedContent: CrossFrameStateManager<DictionaryContent>;\n readonly configuration: CrossFrameStateManager<IntlayerConfig>;\n readonly currentLocale: CrossFrameStateManager<Locale | undefined>;\n readonly displayedDictionaryKeys: CrossFrameStateManager<string[]>;\n\n private readonly _urlManager: UrlStateManager;\n private readonly _iframeInterceptor: IframeClickInterceptor;\n private readonly _mode: 'editor' | 'client';\n private readonly _configuration: IntlayerConfig | undefined;\n\n // Client-mode handshake subscribers\n private _unsubAreYouThere: (() => void) | null = null;\n private _unsubActivate: (() => void) | null = null;\n // Editor-mode handshake subscriber\n private _unsubClientReady: (() => void) | null = null;\n\n // Client-mode displayed-keys tracking\n private _displayedKeysObserver: MutationObserver | null = null;\n private _displayedKeysTimer: ReturnType<typeof setTimeout> | null = null;\n private _displayedKeysListeners: Array<[string, EventListener]> = [];\n\n // Global editedContent bus sync\n private _editedContentFromBus = false;\n private _unsubGlobalEditedContent: (() => void) | null = null;\n private _editedContentBusHandler: ((e: Event) => void) | null = null;\n\n // Global focusedContent bus sync\n private _focusedContentFromBus = false;\n private _unsubGlobalFocusedContent: (() => void) | null = null;\n private _focusedContentBusHandler: ((e: Event) => void) | null = null;\n\n constructor(config: EditorStateManagerConfig) {\n this._mode = config.mode;\n this._configuration = config.configuration;\n\n this.messenger = new CrossFrameMessenger(config.messenger);\n\n this.editorEnabled = new CrossFrameStateManager<boolean>(\n MessageKey.INTLAYER_EDITOR_ENABLED,\n this.messenger,\n { emit: false, receive: true, initialValue: false }\n );\n\n this.focusedContent = new CrossFrameStateManager<FileContent | null>(\n MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,\n this.messenger,\n { emit: true, receive: true, initialValue: null }\n );\n\n this.localeDictionaries = new CrossFrameStateManager<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n this.messenger\n );\n\n this.editedContent = new CrossFrameStateManager<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED,\n this.messenger\n );\n\n this.configuration = new CrossFrameStateManager<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n this.messenger,\n {\n emit: true,\n receive: false,\n ...(config.configuration ? { initialValue: config.configuration } : {}),\n }\n );\n\n // Client emits its locale to the editor; editor receives it.\n this.currentLocale = new CrossFrameStateManager<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n this.messenger,\n {\n emit: config.mode === 'client',\n receive: config.mode === 'editor',\n }\n );\n\n // Client emits displayed dictionary keys; editor receives them.\n this.displayedDictionaryKeys = new CrossFrameStateManager<string[]>(\n MessageKey.INTLAYER_DISPLAYED_DICTIONARY_KEYS,\n this.messenger,\n {\n emit: config.mode === 'client',\n receive: config.mode === 'editor',\n initialValue: [],\n }\n );\n\n this._urlManager = new UrlStateManager(this.messenger);\n this._iframeInterceptor = new IframeClickInterceptor(this.messenger);\n }\n\n start(): void {\n this.messenger.start();\n this.editorEnabled.start();\n this.focusedContent.start();\n this.localeDictionaries.start();\n this.editedContent.start();\n this.configuration.start();\n this.currentLocale.start();\n this.displayedDictionaryKeys.start();\n this._startEditedContentBusSync();\n this._startFocusedContentBusSync();\n\n if (this._mode === 'client') {\n this._urlManager.start();\n this._iframeInterceptor.startInterceptor();\n this._loadDictionaries();\n this._startDisplayedDictionariesTracking();\n // Request current edited content from the editor\n this.messenger.send(`${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`);\n // Activation handshake: only participate if editor.enabled !== false\n if (this._configuration?.editor?.enabled !== false) {\n this._setupActivationHandshake();\n }\n } else {\n this._iframeInterceptor.startMerger();\n this._setupEditorHandshake();\n }\n }\n\n stop(): void {\n this._unsubAreYouThere?.();\n this._unsubActivate?.();\n this._unsubClientReady?.();\n this._unsubAreYouThere = null;\n this._unsubActivate = null;\n this._unsubClientReady = null;\n this.messenger.stop();\n this.editorEnabled.stop();\n this.focusedContent.stop();\n this.localeDictionaries.stop();\n this.editedContent.stop();\n this.configuration.stop();\n this.currentLocale.stop();\n this.displayedDictionaryKeys.stop();\n this._stopDisplayedDictionariesTracking();\n this._stopEditedContentBusSync();\n this._stopFocusedContentBusSync();\n this._urlManager.stop();\n this._iframeInterceptor.stopInterceptor();\n this._iframeInterceptor.stopMerger();\n }\n\n // ─── Handshake helpers ───────────────────────────────────────────────────────\n\n /**\n * EDITOR mode: re-send ARE_YOU_THERE to attempt re-connection with the client.\n * Call this when the user clicks \"Enable Editor\" or when the iframe reloads.\n */\n pingClient(): void {\n if (this._mode !== 'editor') return;\n\n this.messenger.send(MessageKey.INTLAYER_ARE_YOU_THERE);\n }\n\n // ─── Focus helpers ──────────────────────────────────────────────────────────\n\n setFocusedContentKeyPath(keyPath: KeyPath[]): void {\n const filtered = keyPath.filter(\n (key) => key.type !== NodeTypes.TRANSLATION\n );\n const prev = this.focusedContent.value;\n\n if (!prev) return;\n\n this.focusedContent.set({ ...prev, keyPath: filtered });\n }\n\n // ─── Dictionary record helpers ───────────────────────────────────────────\n\n setLocaleDictionary(dictionary: Dictionary): void {\n if (!dictionary.localId) return;\n const current = this.localeDictionaries.value ?? {};\n\n this.localeDictionaries.set({\n ...current,\n [dictionary.localId as LocalDictionaryId]: dictionary,\n });\n }\n\n // ─── Edited content helpers ───────────────────────────────────────────────\n\n setEditedDictionary(newDict: Dictionary): void {\n if (!newDict.localId) {\n console.error('setEditedDictionary: missing localId', newDict);\n return;\n }\n const current = this.editedContent.value ?? {};\n\n this.editedContent.set({\n ...current,\n [newDict.localId as LocalDictionaryId]: newDict,\n });\n }\n\n setEditedContent(\n localDictionaryId: LocalDictionaryId,\n newValue: Dictionary['content']\n ): void {\n const current = this.editedContent.value ?? {};\n\n this.editedContent.set({\n ...current,\n [localDictionaryId]: {\n ...current[localDictionaryId],\n content: newValue,\n },\n });\n }\n\n addContent(\n localDictionaryId: LocalDictionaryId,\n newValue: ContentNode,\n keyPath: KeyPath[] = [],\n overwrite = true\n ): void {\n const current = this.editedContent.value ?? {};\n const localeDicts = this.localeDictionaries.value ?? {};\n\n const originalContent = localeDicts[localDictionaryId]?.content;\n const currentContent = structuredClone(\n current[localDictionaryId]?.content ?? originalContent\n );\n\n let newKeyPath = keyPath;\n if (!overwrite) {\n let index = 0;\n\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath = keyPath[keyPath.length - 1];\n\n let finalKey = lastKeyPath.key;\n\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n this.editedContent.set({\n ...current,\n [localDictionaryId]: {\n ...current[localDictionaryId],\n content: updatedContent as Dictionary['content'],\n },\n });\n }\n\n renameContent(\n localDictionaryId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath: KeyPath[] = []\n ): void {\n const current = this.editedContent.value ?? {};\n const localeDicts = this.localeDictionaries.value ?? {};\n const originalContent = localeDicts[localDictionaryId]?.content;\n const currentContent = structuredClone(\n current[localDictionaryId]?.content ?? originalContent\n );\n const updated = renameContentNodeByKeyPath(currentContent, newKey, keyPath);\n\n this.editedContent.set({\n ...current,\n [localDictionaryId]: {\n ...current[localDictionaryId],\n content: updated as Dictionary['content'],\n },\n });\n }\n\n removeContent(\n localDictionaryId: LocalDictionaryId,\n keyPath: KeyPath[]\n ): void {\n const current = this.editedContent.value ?? {};\n const localeDicts = this.localeDictionaries.value ?? {};\n const originalContent = localeDicts[localDictionaryId]?.content;\n const currentContent = structuredClone(\n current[localDictionaryId]?.content ?? originalContent\n );\n const initialContent = getContentNodeByKeyPath(originalContent, keyPath);\n const restored = editDictionaryByKeyPath(\n currentContent,\n keyPath,\n initialContent\n );\n\n this.editedContent.set({\n ...current,\n [localDictionaryId]: {\n ...current[localDictionaryId],\n content: restored as Dictionary['content'],\n },\n });\n }\n\n restoreContent(localDictionaryId: LocalDictionaryId): void {\n const current = this.editedContent.value ?? {};\n const updated = { ...current };\n\n delete updated[localDictionaryId];\n\n this.editedContent.set(updated);\n }\n\n clearContent(localDictionaryId: LocalDictionaryId): void {\n const current = this.editedContent.value ?? {};\n const filtered = { ...current };\n\n delete filtered[localDictionaryId];\n\n this.editedContent.set(filtered);\n }\n\n clearAllContent(): void {\n this.editedContent.set({});\n }\n\n getContentValue(\n localDictionaryIdOrKey: LocalDictionaryId | string,\n keyPath: KeyPath[]\n ): ContentNode | undefined {\n const edited = this.editedContent.value;\n if (!edited) return undefined;\n\n const filteredKeyPath = keyPath.filter(\n (key) => key.type !== NodeTypes.TRANSLATION\n );\n\n // Only use edited content entries whose localId is known to this client.\n // This prevents stale edits from other apps (different framework demos) from\n // being applied when the editor sends back its stored editedContent.\n const localeDicts = this.localeDictionaries.value;\n\n const isDictionaryId =\n localDictionaryIdOrKey.includes(':local:') ||\n localDictionaryIdOrKey.includes(':remote:');\n\n if (isDictionaryId) {\n // If localeDictionaries is loaded, verify this localId belongs to us\n if (localeDicts && !(localDictionaryIdOrKey in localeDicts)) {\n return undefined;\n }\n const content =\n edited[localDictionaryIdOrKey as LocalDictionaryId]?.content ?? {};\n\n return getContentNodeByKeyPath(\n content,\n filteredKeyPath,\n this.currentLocale.value\n );\n }\n\n const matchingIds = Object.keys(edited).filter(\n (key) =>\n key.startsWith(`${localDictionaryIdOrKey}:`) &&\n // If localeDictionaries is loaded, only include known localIds\n (!localeDicts || key in localeDicts)\n );\n\n for (const localId of matchingIds) {\n const content = edited[localId as LocalDictionaryId]?.content ?? {};\n const node = getContentNodeByKeyPath(\n content,\n filteredKeyPath,\n this.currentLocale.value\n );\n if (node) return node;\n }\n\n return undefined;\n }\n\n // ─── Global editedContent bus sync ───────────────────────────────────────\n\n private _startEditedContentBusSync(): void {\n // Push local changes to the global bus (loop-guarded)\n this._editedContentBusHandler = (e: Event) => {\n if (this._editedContentFromBus) return;\n const content = (e as CustomEvent<DictionaryContent>).detail;\n setGlobalEditedContent(content, this.messenger.senderId);\n };\n this.editedContent.addEventListener(\n 'change',\n this._editedContentBusHandler\n );\n\n // Receive bus changes from other managers\n this._unsubGlobalEditedContent = subscribeToGlobalEditedContent(\n (content, sourceId) => {\n if (sourceId === this.messenger.senderId) return;\n this._editedContentFromBus = true;\n this.editedContent.set(content);\n this._editedContentFromBus = false;\n }\n );\n\n // Seed local value from the bus if bus already has content\n const existing = getGlobalEditedContent();\n if (Object.keys(existing).length > 0) {\n this._editedContentFromBus = true;\n this.editedContent.set(existing);\n this._editedContentFromBus = false;\n }\n }\n\n private _stopEditedContentBusSync(): void {\n if (this._editedContentBusHandler) {\n this.editedContent.removeEventListener(\n 'change',\n this._editedContentBusHandler\n );\n this._editedContentBusHandler = null;\n }\n this._unsubGlobalEditedContent?.();\n this._unsubGlobalEditedContent = null;\n }\n\n // ─── Global focusedContent bus sync ──────────────────────────────────────\n\n private _startFocusedContentBusSync(): void {\n this._focusedContentBusHandler = (e: Event) => {\n if (this._focusedContentFromBus) return;\n const content = (e as CustomEvent<FileContent | null>).detail;\n setGlobalFocusedContent(content, this.messenger.senderId);\n };\n this.focusedContent.addEventListener(\n 'change',\n this._focusedContentBusHandler\n );\n\n this._unsubGlobalFocusedContent = subscribeToGlobalFocusedContent(\n (content, sourceId) => {\n if (sourceId === this.messenger.senderId) return;\n this._focusedContentFromBus = true;\n this.focusedContent.set(content);\n this._focusedContentFromBus = false;\n }\n );\n\n const existing = getGlobalFocusedContent();\n if (existing !== undefined) {\n this._focusedContentFromBus = true;\n this.focusedContent.set(existing);\n this._focusedContentFromBus = false;\n }\n }\n\n private _stopFocusedContentBusSync(): void {\n if (this._focusedContentBusHandler) {\n this.focusedContent.removeEventListener(\n 'change',\n this._focusedContentBusHandler\n );\n this._focusedContentBusHandler = null;\n }\n this._unsubGlobalFocusedContent?.();\n this._unsubGlobalFocusedContent = null;\n }\n\n // ─── Displayed dictionaries tracking (client mode only) ──────────────────\n\n private _scanDisplayedDictionaryKeys(): void {\n if (typeof document === 'undefined') return;\n const elements = document.querySelectorAll(\n 'intlayer-content-selector-wrapper[dictionary-key]'\n );\n const keys = Array.from(\n new Set(\n Array.from(elements)\n .map((el) => el.getAttribute('dictionary-key') ?? '')\n .filter(Boolean)\n )\n );\n this.displayedDictionaryKeys.set(keys);\n }\n\n private _startDisplayedDictionariesTracking(): void {\n if (\n typeof document === 'undefined' ||\n typeof MutationObserver === 'undefined'\n )\n return;\n\n const schedule = () => {\n if (this._displayedKeysTimer) clearTimeout(this._displayedKeysTimer);\n this._displayedKeysTimer = setTimeout(\n () => this._scanDisplayedDictionaryKeys(),\n 100\n );\n };\n\n this._displayedKeysObserver = new MutationObserver(schedule);\n this._displayedKeysObserver.observe(document.body, {\n childList: true,\n subtree: true,\n });\n\n for (const evt of ['locationchange', 'popstate'] as const) {\n const listener = schedule as EventListener;\n window.addEventListener(evt, listener);\n this._displayedKeysListeners.push([evt, listener]);\n }\n\n this._scanDisplayedDictionaryKeys();\n }\n\n private _stopDisplayedDictionariesTracking(): void {\n this._displayedKeysObserver?.disconnect();\n this._displayedKeysObserver = null;\n if (this._displayedKeysTimer) {\n clearTimeout(this._displayedKeysTimer);\n this._displayedKeysTimer = null;\n }\n for (const [evt, listener] of this._displayedKeysListeners) {\n window.removeEventListener(evt, listener);\n }\n this._displayedKeysListeners = [];\n }\n\n // ─── Handshake helpers ───────────────────────────────────────────────────────\n\n /**\n * EDITOR mode: listen for CLIENT_READY and respond with EDITOR_ACTIVATE.\n * Also pings the client immediately in case it loaded before the editor.\n */\n private _setupEditorHandshake(): void {\n // When the client announces it is ready, activate it\n this._unsubClientReady = this.messenger.subscribe(\n MessageKey.INTLAYER_CLIENT_READY,\n () => {\n this.editorEnabled.set(true);\n this.messenger.send(MessageKey.INTLAYER_EDITOR_ACTIVATE);\n }\n );\n\n // Ping any already-running client (covers editor-opens-after-client scenario)\n this.messenger.send(MessageKey.INTLAYER_ARE_YOU_THERE);\n }\n\n private _setupActivationHandshake(): void {\n // Announce to the editor that the client is ready\n this.messenger.send(MessageKey.INTLAYER_CLIENT_READY);\n\n // Respond to \"are you there?\" pings from the editor\n this._unsubAreYouThere = this.messenger.subscribe(\n MessageKey.INTLAYER_ARE_YOU_THERE,\n () => {\n this.messenger.send(MessageKey.INTLAYER_CLIENT_READY);\n }\n );\n\n // When the editor activates us, enable the selector and broadcast state\n this._unsubActivate = this.messenger.subscribe(\n MessageKey.INTLAYER_EDITOR_ACTIVATE,\n () => {\n this.editorEnabled.set(true);\n this._broadcastData();\n }\n );\n }\n\n private _broadcastData(): void {\n const configVal = this.configuration.value;\n\n if (configVal) {\n this.messenger.send(\n `${MessageKey.INTLAYER_CONFIGURATION}/post`,\n configVal\n );\n }\n const localeVal = this.currentLocale.value;\n\n if (localeVal) {\n this.messenger.send(\n `${MessageKey.INTLAYER_CURRENT_LOCALE}/post`,\n localeVal\n );\n }\n const dicts = this.localeDictionaries.value;\n\n if (dicts) {\n this.messenger.send(\n `${MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED}/post`,\n dicts\n );\n }\n }\n\n private async _loadDictionaries(): Promise<void> {\n try {\n const mod = await import('@intlayer/unmerged-dictionaries-entry');\n const unmergedDictionaries = mod.getUnmergedDictionaries();\n const dictionariesList = Object.fromEntries(\n Object.values(unmergedDictionaries)\n .flat()\n .map((dictionary) => [dictionary.localId, dictionary])\n ) as DictionaryContent;\n\n this.localeDictionaries.set(dictionariesList);\n\n // If the editor already activated us before dictionaries finished loading,\n // re-broadcast now so the editor receives the dictionaries.\n if (this.editorEnabled.value) {\n this._broadcastData();\n }\n } catch (e) {\n // Dynamic entry not available (expected in editor mode or when not configured)\n console.warn('[intlayer] Failed to load unmerged dictionaries:', e);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0DA,IAAa,qBAAb,MAAgC;CAC9B,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAGjB,AAAQ,oBAAyC;CACjD,AAAQ,iBAAsC;CAE9C,AAAQ,oBAAyC;CAGjD,AAAQ,yBAAkD;CAC1D,AAAQ,sBAA4D;CACpE,AAAQ,0BAA0D,CAAC;CAGnE,AAAQ,wBAAwB;CAChC,AAAQ,4BAAiD;CACzD,AAAQ,2BAAwD;CAGhE,AAAQ,yBAAyB;CACjC,AAAQ,6BAAkD;CAC1D,AAAQ,4BAAyD;CAEjE,YAAY,QAAkC;EAC5C,KAAK,QAAQ,OAAO;EACpB,KAAK,iBAAiB,O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BAAoB,KAAK,UAAU,yCAEhC;GACJ,KAAK,cAAc,IAAI,IAAI;GAC3B,KAAK,UAAU,+BAAwC;EACzD,CACF;EAGA,KAAK,UAAU,6BAAsC;CACvD;CAEA,AAAQ,4BAAkC;EAExC,KAAK,UAAU,4BAAqC;EAGpD,KAAK,oBAAoB,KAAK,UAAU,0CAEhC;GACJ,KAAK,UAAU,4BAAqC;EACtD,CACF;EAGA,KAAK,iBAAiB,KAAK,UAAU,4CAE7B;GACJ,KAAK,cAAc,IAAI,IAAI;GAC3B,KAAK,eAAe;EACtB,CACF;CACF;CAEA,AAAQ,iBAAuB;EAC7B,MAAM,YAAY,KAAK,cAAc;EAErC,IAAI,WACF,KAAK,UAAU,KACb,4BAAqC,QACrC,SACF;EAEF,MAAM,YAAY,KAAK,cAAc;EAErC,IAAI,WACF,KAAK,UAAU,KACb,6BAAsC,QACtC,SACF;EAEF,MAAM,QAAQ,KAAK,mBAAmB;EAEtC,IAAI,OACF,KAAK,UAAU,KACb,0CAAmD,QACnD,KACF;CAEJ;CAEA,MAAc,oBAAmC;EAC/C,IAAI;GAEF,MAAM,wBAAuB,MADX,OAAO,0CACQ,wBAAwB;GACzD,MAAM,mBAAmB,OAAO,YAC9B,OAAO,OAAO,oBAAoB,EAC/B,KAAK,EACL,KAAK,eAAe,CAAC,WAAW,SAAS,UAAU,CAAC,CACzD;GAEA,KAAK,mBAAmB,IAAI,gBAAgB;GAI5C,IAAI,KAAK,cAAc,OACrB,KAAK,eAAe;EAExB,SAAS,GAAG;GAEV,QAAQ,KAAK,oDAAoD,CAAC;EACpE;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"IframeClickInterceptor.mjs","names":[],"sources":["../../../src/core/IframeClickInterceptor.ts"],"sourcesContent":["import { mergeIframeClick } from '../mergeIframeClick';\nimport { MessageKey } from '../messageKey';\nimport type { CrossFrameMessenger } from './CrossFrameMessenger';\n\n/**\n * IframeClickInterceptor handles click events across iframe boundaries.\n *\n * - startInterceptor(): called in the client (iframe) — broadcasts mousedown to parent\n * - startMerger(): called in the editor (parent) — merges received clicks into DOM events\n *\n * Replaces useIframeClickInterceptor / useIframeClickMerger across all frameworks.\n */\nexport class IframeClickInterceptor {\n private readonly _messenger: CrossFrameMessenger;\n private _mousedownHandler: EventListener | null = null;\n private _unsubscribeMerge: (() => void) | null = null;\n\n constructor(messenger: CrossFrameMessenger) {\n this._messenger = messenger;\n }\n\n /** Called on the client side (inside iframe). Broadcasts click events to parent. */\n startInterceptor(): void {\n if (typeof window === 'undefined') return;\n this._mousedownHandler = () => {\n this._messenger.send(MessageKey.INTLAYER_IFRAME_CLICKED);\n };\n window.addEventListener('mousedown', this._mousedownHandler);\n }\n\n /** Called on the editor side (parent frame). Merges incoming iframe clicks into DOM. */\n startMerger(): void {\n this._unsubscribeMerge = this._messenger.subscribe(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick as (data: unknown) => void\n );\n }\n\n stopInterceptor(): void {\n if (this._mousedownHandler) {\n window.removeEventListener('mousedown', this._mousedownHandler);\n this._mousedownHandler = null;\n }\n }\n\n stopMerger(): void {\n this._unsubscribeMerge?.();\n this._unsubscribeMerge = null;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,yBAAb,MAAoC;CAClC,AAAiB;CACjB,AAAQ,oBAA0C;CAClD,AAAQ,oBAAyC;CAEjD,YAAY,WAAgC;EAC1C,KAAK,aAAa;;;CAIpB,mBAAyB;EACvB,IAAI,OAAO,WAAW,aAAa;EACnC,KAAK,0BAA0B;GAC7B,KAAK,WAAW,+BAAwC;;EAE1D,OAAO,iBAAiB,aAAa,KAAK,kBAAkB;;;CAI9D,cAAoB;EAClB,KAAK,oBAAoB,KAAK,WAAW,qCAEvC,iBACD;;CAGH,kBAAwB;EACtB,IAAI,KAAK,mBAAmB;GAC1B,OAAO,oBAAoB,aAAa,KAAK,kBAAkB;GAC/D,KAAK,oBAAoB;;;CAI7B,aAAmB;EACjB,KAAK,qBAAqB;EAC1B,KAAK,oBAAoB"}
1
+ {"version":3,"file":"IframeClickInterceptor.mjs","names":[],"sources":["../../../src/core/IframeClickInterceptor.ts"],"sourcesContent":["import { mergeIframeClick } from '../mergeIframeClick';\nimport { MessageKey } from '../messageKey';\nimport type { CrossFrameMessenger } from './CrossFrameMessenger';\n\n/**\n * IframeClickInterceptor handles click events across iframe boundaries.\n *\n * - startInterceptor(): called in the client (iframe) — broadcasts mousedown to parent\n * - startMerger(): called in the editor (parent) — merges received clicks into DOM events\n *\n * Replaces useIframeClickInterceptor / useIframeClickMerger across all frameworks.\n */\nexport class IframeClickInterceptor {\n private readonly _messenger: CrossFrameMessenger;\n private _mousedownHandler: EventListener | null = null;\n private _unsubscribeMerge: (() => void) | null = null;\n\n constructor(messenger: CrossFrameMessenger) {\n this._messenger = messenger;\n }\n\n /** Called on the client side (inside iframe). Broadcasts click events to parent. */\n startInterceptor(): void {\n if (typeof window === 'undefined') return;\n this._mousedownHandler = () => {\n this._messenger.send(MessageKey.INTLAYER_IFRAME_CLICKED);\n };\n window.addEventListener('mousedown', this._mousedownHandler);\n }\n\n /** Called on the editor side (parent frame). Merges incoming iframe clicks into DOM. */\n startMerger(): void {\n this._unsubscribeMerge = this._messenger.subscribe(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick as (data: unknown) => void\n );\n }\n\n stopInterceptor(): void {\n if (this._mousedownHandler) {\n window.removeEventListener('mousedown', this._mousedownHandler);\n this._mousedownHandler = null;\n }\n }\n\n stopMerger(): void {\n this._unsubscribeMerge?.();\n this._unsubscribeMerge = null;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,yBAAb,MAAoC;CAClC,AAAiB;CACjB,AAAQ,oBAA0C;CAClD,AAAQ,oBAAyC;CAEjD,YAAY,WAAgC;EAC1C,KAAK,aAAa;CACpB;;CAGA,mBAAyB;EACvB,IAAI,OAAO,WAAW,aAAa;EACnC,KAAK,0BAA0B;GAC7B,KAAK,WAAW,8BAAuC;EACzD;EACA,OAAO,iBAAiB,aAAa,KAAK,iBAAiB;CAC7D;;CAGA,cAAoB;EAClB,KAAK,oBAAoB,KAAK,WAAW,qCAEvC,gBACF;CACF;CAEA,kBAAwB;EACtB,IAAI,KAAK,mBAAmB;GAC1B,OAAO,oBAAoB,aAAa,KAAK,iBAAiB;GAC9D,KAAK,oBAAoB;EAC3B;CACF;CAEA,aAAmB;EACjB,KAAK,oBAAoB;EACzB,KAAK,oBAAoB;CAC3B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"UrlStateManager.mjs","names":[],"sources":["../../../src/core/UrlStateManager.ts"],"sourcesContent":["import { MessageKey } from '../messageKey';\nimport type { CrossFrameMessenger } from './CrossFrameMessenger';\n\n/**\n * UrlStateManager patches window.history and broadcasts URL path changes\n * across frames via postMessage.\n *\n * Replaces useCrossURLPathSetter / useCrossURLPathState across all frameworks.\n */\nexport class UrlStateManager {\n private readonly _messenger: CrossFrameMessenger;\n private _originalPushState: typeof history.pushState | null = null;\n private _originalReplaceState: typeof history.replaceState | null = null;\n private _listeners: Array<[string, EventListener]> = [];\n\n constructor(messenger: CrossFrameMessenger) {\n this._messenger = messenger;\n }\n\n start(): void {\n if (typeof window === 'undefined') return;\n\n const updateURLState = () => {\n this._messenger.send(\n `${MessageKey.INTLAYER_URL_CHANGE}/post`,\n window.location.pathname\n );\n };\n\n this._originalPushState = history.pushState;\n this._originalReplaceState = history.replaceState;\n\n const injectLocationChange = (method: typeof history.pushState) =>\n function (\n this: typeof history,\n ...args: Parameters<typeof history.pushState>\n ) {\n method.apply(this, args);\n window.dispatchEvent(new Event('locationchange'));\n };\n\n history.pushState = injectLocationChange(\n this._originalPushState\n ) as typeof history.pushState;\n history.replaceState = injectLocationChange(\n this._originalReplaceState\n ) as typeof history.replaceState;\n\n for (const eventName of [\n 'locationchange',\n 'popstate',\n 'hashchange',\n 'load',\n ] as const) {\n const listener = updateURLState as EventListener;\n window.addEventListener(eventName, listener);\n this._listeners.push([eventName, listener]);\n }\n\n updateURLState();\n }\n\n stop(): void {\n if (typeof window === 'undefined') return;\n\n for (const [eventName, listener] of this._listeners) {\n window.removeEventListener(eventName, listener);\n }\n this._listeners = [];\n\n if (this._originalPushState) {\n history.pushState = this._originalPushState;\n this._originalPushState = null;\n }\n if (this._originalReplaceState) {\n history.replaceState = this._originalReplaceState;\n this._originalReplaceState = null;\n }\n }\n}\n"],"mappings":";;;;;;;;;AASA,IAAa,kBAAb,MAA6B;CAC3B,AAAiB;CACjB,AAAQ,qBAAsD;CAC9D,AAAQ,wBAA4D;CACpE,AAAQ,aAA6C,EAAE;CAEvD,YAAY,WAAgC;EAC1C,KAAK,aAAa;;CAGpB,QAAc;EACZ,IAAI,OAAO,WAAW,aAAa;EAEnC,MAAM,uBAAuB;GAC3B,KAAK,WAAW,KACd,yBAAkC,QAClC,OAAO,SAAS,SACjB;;EAGH,KAAK,qBAAqB,QAAQ;EAClC,KAAK,wBAAwB,QAAQ;EAErC,MAAM,wBAAwB,WAC5B,SAEE,GAAG,MACH;GACA,OAAO,MAAM,MAAM,KAAK;GACxB,OAAO,cAAc,IAAI,MAAM,iBAAiB,CAAC;;EAGrD,QAAQ,YAAY,qBAClB,KAAK,mBACN;EACD,QAAQ,eAAe,qBACrB,KAAK,sBACN;EAED,KAAK,MAAM,aAAa;GACtB;GACA;GACA;GACA;GACD,EAAW;GACV,MAAM,WAAW;GACjB,OAAO,iBAAiB,WAAW,SAAS;GAC5C,KAAK,WAAW,KAAK,CAAC,WAAW,SAAS,CAAC;;EAG7C,gBAAgB;;CAGlB,OAAa;EACX,IAAI,OAAO,WAAW,aAAa;EAEnC,KAAK,MAAM,CAAC,WAAW,aAAa,KAAK,YACvC,OAAO,oBAAoB,WAAW,SAAS;EAEjD,KAAK,aAAa,EAAE;EAEpB,IAAI,KAAK,oBAAoB;GAC3B,QAAQ,YAAY,KAAK;GACzB,KAAK,qBAAqB;;EAE5B,IAAI,KAAK,uBAAuB;GAC9B,QAAQ,eAAe,KAAK;GAC5B,KAAK,wBAAwB"}
1
+ {"version":3,"file":"UrlStateManager.mjs","names":[],"sources":["../../../src/core/UrlStateManager.ts"],"sourcesContent":["import { MessageKey } from '../messageKey';\nimport type { CrossFrameMessenger } from './CrossFrameMessenger';\n\n/**\n * UrlStateManager patches window.history and broadcasts URL path changes\n * across frames via postMessage.\n *\n * Replaces useCrossURLPathSetter / useCrossURLPathState across all frameworks.\n */\nexport class UrlStateManager {\n private readonly _messenger: CrossFrameMessenger;\n private _originalPushState: typeof history.pushState | null = null;\n private _originalReplaceState: typeof history.replaceState | null = null;\n private _listeners: Array<[string, EventListener]> = [];\n\n constructor(messenger: CrossFrameMessenger) {\n this._messenger = messenger;\n }\n\n start(): void {\n if (typeof window === 'undefined') return;\n\n const updateURLState = () => {\n this._messenger.send(\n `${MessageKey.INTLAYER_URL_CHANGE}/post`,\n window.location.pathname\n );\n };\n\n this._originalPushState = history.pushState;\n this._originalReplaceState = history.replaceState;\n\n const injectLocationChange = (method: typeof history.pushState) =>\n function (\n this: typeof history,\n ...args: Parameters<typeof history.pushState>\n ) {\n method.apply(this, args);\n window.dispatchEvent(new Event('locationchange'));\n };\n\n history.pushState = injectLocationChange(\n this._originalPushState\n ) as typeof history.pushState;\n history.replaceState = injectLocationChange(\n this._originalReplaceState\n ) as typeof history.replaceState;\n\n for (const eventName of [\n 'locationchange',\n 'popstate',\n 'hashchange',\n 'load',\n ] as const) {\n const listener = updateURLState as EventListener;\n window.addEventListener(eventName, listener);\n this._listeners.push([eventName, listener]);\n }\n\n updateURLState();\n }\n\n stop(): void {\n if (typeof window === 'undefined') return;\n\n for (const [eventName, listener] of this._listeners) {\n window.removeEventListener(eventName, listener);\n }\n this._listeners = [];\n\n if (this._originalPushState) {\n history.pushState = this._originalPushState;\n this._originalPushState = null;\n }\n if (this._originalReplaceState) {\n history.replaceState = this._originalReplaceState;\n this._originalReplaceState = null;\n }\n }\n}\n"],"mappings":";;;;;;;;;AASA,IAAa,kBAAb,MAA6B;CAC3B,AAAiB;CACjB,AAAQ,qBAAsD;CAC9D,AAAQ,wBAA4D;CACpE,AAAQ,aAA6C,CAAC;CAEtD,YAAY,WAAgC;EAC1C,KAAK,aAAa;CACpB;CAEA,QAAc;EACZ,IAAI,OAAO,WAAW,aAAa;EAEnC,MAAM,uBAAuB;GAC3B,KAAK,WAAW,KACd,yBAAkC,QAClC,OAAO,SAAS,QAClB;EACF;EAEA,KAAK,qBAAqB,QAAQ;EAClC,KAAK,wBAAwB,QAAQ;EAErC,MAAM,wBAAwB,WAC5B,SAEE,GAAG,MACH;GACA,OAAO,MAAM,MAAM,IAAI;GACvB,OAAO,cAAc,IAAI,MAAM,gBAAgB,CAAC;EAClD;EAEF,QAAQ,YAAY,qBAClB,KAAK,kBACP;EACA,QAAQ,eAAe,qBACrB,KAAK,qBACP;EAEA,KAAK,MAAM,aAAa;GACtB;GACA;GACA;GACA;EACF,GAAY;GACV,MAAM,WAAW;GACjB,OAAO,iBAAiB,WAAW,QAAQ;GAC3C,KAAK,WAAW,KAAK,CAAC,WAAW,QAAQ,CAAC;EAC5C;EAEA,eAAe;CACjB;CAEA,OAAa;EACX,IAAI,OAAO,WAAW,aAAa;EAEnC,KAAK,MAAM,CAAC,WAAW,aAAa,KAAK,YACvC,OAAO,oBAAoB,WAAW,QAAQ;EAEhD,KAAK,aAAa,CAAC;EAEnB,IAAI,KAAK,oBAAoB;GAC3B,QAAQ,YAAY,KAAK;GACzB,KAAK,qBAAqB;EAC5B;EACA,IAAI,KAAK,uBAAuB;GAC9B,QAAQ,eAAe,KAAK;GAC5B,KAAK,wBAAwB;EAC/B;CACF;AACF"}
@@ -0,0 +1,33 @@
1
+ //#region src/core/editedContentBus.ts
2
+ const BUS_KEY = "__intlayer_edited_content_bus__";
3
+ const BUS_EVENTS_KEY = "__intlayer_edited_content_bus_events__";
4
+ const getBusTarget = () => {
5
+ if (typeof window === "undefined") return new EventTarget();
6
+ const w = window;
7
+ if (!w[BUS_EVENTS_KEY]) w[BUS_EVENTS_KEY] = new EventTarget();
8
+ return w[BUS_EVENTS_KEY];
9
+ };
10
+ const getGlobalEditedContent = () => {
11
+ if (typeof window === "undefined") return {};
12
+ return window[BUS_KEY] ?? {};
13
+ };
14
+ const setGlobalEditedContent = (content, sourceId) => {
15
+ if (typeof window !== "undefined") window[BUS_KEY] = content;
16
+ getBusTarget().dispatchEvent(new CustomEvent("change", { detail: {
17
+ content,
18
+ sourceId
19
+ } }));
20
+ };
21
+ const subscribeToGlobalEditedContent = (cb) => {
22
+ const handler = (e) => {
23
+ const { content, sourceId } = e.detail;
24
+ cb(content, sourceId);
25
+ };
26
+ const target = getBusTarget();
27
+ target.addEventListener("change", handler);
28
+ return () => target.removeEventListener("change", handler);
29
+ };
30
+
31
+ //#endregion
32
+ export { getGlobalEditedContent, setGlobalEditedContent, subscribeToGlobalEditedContent };
33
+ //# sourceMappingURL=editedContentBus.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editedContentBus.mjs","names":[],"sources":["../../../src/core/editedContentBus.ts"],"sourcesContent":["import type { DictionaryContent } from './EditorStateManager';\n\nconst BUS_KEY = '__intlayer_edited_content_bus__';\nconst BUS_EVENTS_KEY = '__intlayer_edited_content_bus_events__';\n\ntype WindowWithBus = typeof window & {\n [BUS_KEY]?: DictionaryContent;\n [BUS_EVENTS_KEY]?: EventTarget;\n};\n\ntype BusEvent = { content: DictionaryContent; sourceId?: string };\n\nconst getBusTarget = (): EventTarget => {\n if (typeof window === 'undefined') return new EventTarget();\n const w = window as WindowWithBus;\n if (!w[BUS_EVENTS_KEY]) w[BUS_EVENTS_KEY] = new EventTarget();\n return w[BUS_EVENTS_KEY]!;\n};\n\nexport const getGlobalEditedContent = (): DictionaryContent => {\n if (typeof window === 'undefined') return {};\n return (window as WindowWithBus)[BUS_KEY] ?? {};\n};\n\nexport const setGlobalEditedContent = (\n content: DictionaryContent,\n sourceId?: string\n): void => {\n if (typeof window !== 'undefined') {\n (window as WindowWithBus)[BUS_KEY] = content;\n }\n getBusTarget().dispatchEvent(\n new CustomEvent<BusEvent>('change', { detail: { content, sourceId } })\n );\n};\n\nexport const subscribeToGlobalEditedContent = (\n cb: (content: DictionaryContent, sourceId?: string) => void\n): (() => void) => {\n const handler = (e: Event) => {\n const { content, sourceId } = (e as CustomEvent<BusEvent>).detail;\n cb(content, sourceId);\n };\n const target = getBusTarget();\n target.addEventListener('change', handler);\n return () => target.removeEventListener('change', handler);\n};\n"],"mappings":";AAEA,MAAM,UAAU;AAChB,MAAM,iBAAiB;AASvB,MAAM,qBAAkC;CACtC,IAAI,OAAO,WAAW,aAAa,OAAO,IAAI,YAAY;CAC1D,MAAM,IAAI;CACV,IAAI,CAAC,EAAE,iBAAiB,EAAE,kBAAkB,IAAI,YAAY;CAC5D,OAAO,EAAE;AACX;AAEA,MAAa,+BAAkD;CAC7D,IAAI,OAAO,WAAW,aAAa,OAAO,CAAC;CAC3C,OAAQ,OAAyB,YAAY,CAAC;AAChD;AAEA,MAAa,0BACX,SACA,aACS;CACT,IAAI,OAAO,WAAW,aACpB,AAAC,OAAyB,WAAW;CAEvC,aAAa,EAAE,cACb,IAAI,YAAsB,UAAU,EAAE,QAAQ;EAAE;EAAS;CAAS,EAAE,CAAC,CACvE;AACF;AAEA,MAAa,kCACX,OACiB;CACjB,MAAM,WAAW,MAAa;EAC5B,MAAM,EAAE,SAAS,aAAc,EAA4B;EAC3D,GAAG,SAAS,QAAQ;CACtB;CACA,MAAM,SAAS,aAAa;CAC5B,OAAO,iBAAiB,UAAU,OAAO;CACzC,aAAa,OAAO,oBAAoB,UAAU,OAAO;AAC3D"}
@@ -0,0 +1,39 @@
1
+ //#region src/core/focusedContentBus.ts
2
+ const BUS_KEY = "__intlayer_focused_content_bus__";
3
+ const BUS_EVENTS_KEY = "__intlayer_focused_content_bus_events__";
4
+ const getBusTarget = () => {
5
+ if (typeof window === "undefined") return new EventTarget();
6
+ const w = window;
7
+ if (!w[BUS_EVENTS_KEY]) w[BUS_EVENTS_KEY] = new EventTarget();
8
+ return w[BUS_EVENTS_KEY];
9
+ };
10
+ const getGlobalFocusedContent = () => {
11
+ if (typeof window === "undefined") return void 0;
12
+ const w = window;
13
+ if (!w.__intlayer_focused_content_bus_set__) return void 0;
14
+ return w[BUS_KEY] ?? null;
15
+ };
16
+ const setGlobalFocusedContent = (content, sourceId) => {
17
+ if (typeof window !== "undefined") {
18
+ const w = window;
19
+ w[BUS_KEY] = content;
20
+ w.__intlayer_focused_content_bus_set__ = true;
21
+ }
22
+ getBusTarget().dispatchEvent(new CustomEvent("change", { detail: {
23
+ content,
24
+ sourceId
25
+ } }));
26
+ };
27
+ const subscribeToGlobalFocusedContent = (cb) => {
28
+ const handler = (e) => {
29
+ const { content, sourceId } = e.detail;
30
+ cb(content, sourceId);
31
+ };
32
+ const target = getBusTarget();
33
+ target.addEventListener("change", handler);
34
+ return () => target.removeEventListener("change", handler);
35
+ };
36
+
37
+ //#endregion
38
+ export { getGlobalFocusedContent, setGlobalFocusedContent, subscribeToGlobalFocusedContent };
39
+ //# sourceMappingURL=focusedContentBus.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focusedContentBus.mjs","names":[],"sources":["../../../src/core/focusedContentBus.ts"],"sourcesContent":["import type { FileContent } from './EditorStateManager';\n\nconst BUS_KEY = '__intlayer_focused_content_bus__';\nconst BUS_EVENTS_KEY = '__intlayer_focused_content_bus_events__';\n\ntype WindowWithBus = typeof window & {\n [BUS_KEY]?: FileContent | null;\n [BUS_EVENTS_KEY]?: EventTarget;\n __intlayer_focused_content_bus_set__?: boolean;\n};\n\ntype BusEvent = { content: FileContent | null; sourceId?: string };\n\nconst getBusTarget = (): EventTarget => {\n if (typeof window === 'undefined') return new EventTarget();\n const w = window as WindowWithBus;\n if (!w[BUS_EVENTS_KEY]) w[BUS_EVENTS_KEY] = new EventTarget();\n return w[BUS_EVENTS_KEY]!;\n};\n\nexport const getGlobalFocusedContent = (): FileContent | null | undefined => {\n if (typeof window === 'undefined') return undefined;\n const w = window as WindowWithBus;\n if (!w.__intlayer_focused_content_bus_set__) return undefined;\n return w[BUS_KEY] ?? null;\n};\n\nexport const setGlobalFocusedContent = (\n content: FileContent | null,\n sourceId?: string\n): void => {\n if (typeof window !== 'undefined') {\n const w = window as WindowWithBus;\n w[BUS_KEY] = content;\n w.__intlayer_focused_content_bus_set__ = true;\n }\n getBusTarget().dispatchEvent(\n new CustomEvent<BusEvent>('change', { detail: { content, sourceId } })\n );\n};\n\nexport const subscribeToGlobalFocusedContent = (\n cb: (content: FileContent | null, sourceId?: string) => void\n): (() => void) => {\n const handler = (e: Event) => {\n const { content, sourceId } = (e as CustomEvent<BusEvent>).detail;\n cb(content, sourceId);\n };\n const target = getBusTarget();\n target.addEventListener('change', handler);\n return () => target.removeEventListener('change', handler);\n};\n"],"mappings":";AAEA,MAAM,UAAU;AAChB,MAAM,iBAAiB;AAUvB,MAAM,qBAAkC;CACtC,IAAI,OAAO,WAAW,aAAa,OAAO,IAAI,YAAY;CAC1D,MAAM,IAAI;CACV,IAAI,CAAC,EAAE,iBAAiB,EAAE,kBAAkB,IAAI,YAAY;CAC5D,OAAO,EAAE;AACX;AAEA,MAAa,gCAAgE;CAC3E,IAAI,OAAO,WAAW,aAAa,OAAO;CAC1C,MAAM,IAAI;CACV,IAAI,CAAC,EAAE,sCAAsC,OAAO;CACpD,OAAO,EAAE,YAAY;AACvB;AAEA,MAAa,2BACX,SACA,aACS;CACT,IAAI,OAAO,WAAW,aAAa;EACjC,MAAM,IAAI;EACV,EAAE,WAAW;EACb,EAAE,uCAAuC;CAC3C;CACA,aAAa,EAAE,cACb,IAAI,YAAsB,UAAU,EAAE,QAAQ;EAAE;EAAS;CAAS,EAAE,CAAC,CACvE;AACF;AAEA,MAAa,mCACX,OACiB;CACjB,MAAM,WAAW,MAAa;EAC5B,MAAM,EAAE,SAAS,aAAc,EAA4B;EAC3D,GAAG,SAAS,QAAQ;CACtB;CACA,MAAM,SAAS,aAAa;CAC5B,OAAO,iBAAiB,UAAU,OAAO;CACzC,aAAa,OAAO,oBAAoB,UAAU,OAAO;AAC3D"}
@@ -1 +1 @@
1
- {"version":3,"file":"globalManager.mjs","names":["windowGlobals","customEvent"],"sources":["../../../src/core/globalManager.ts"],"sourcesContent":["import type { EditorStateManager } from './EditorStateManager';\n\n/**\n * Type for storing custom properties on the global window object.\n * Used to safely attach singleton instances across multiple module instances.\n */\ntype WindowWithEditorGlobals = typeof window & {\n [MANAGER_KEY]?: EditorStateManager | null;\n [EVENTS_KEY]?: EventTarget;\n [key: string]: unknown;\n};\n\n/**\n * Keys on window used to share the singleton across multiple module instances.\n * When bundlers include @intlayer/editor more than once (e.g. framework package +\n * app), each copy has its own module-level variables. Using window ensures they\n * all read/write the same manager and event-target.\n */\nconst MANAGER_KEY = '__intlayer_editor_manager__';\nconst EVENTS_KEY = '__intlayer_editor_manager_events__';\n\n/**\n * Retrieves or creates a shared EventTarget for global editor manager events.\n * In browser environments, stores the EventTarget on window to ensure sharing\n * across multiple module instances. In SSR environments, creates a fresh\n * EventTarget (no sharing needed on server-side).\n *\n * @returns The shared EventTarget instance for dispatching manager change events\n * @private\n */\nconst getEventTarget = (): EventTarget => {\n if (typeof window === 'undefined') {\n // SSR fallback — create a fresh one (no sharing needed server-side)\n return new EventTarget();\n }\n\n const windowGlobals = window as WindowWithEditorGlobals;\n if (!windowGlobals[EVENTS_KEY]) {\n windowGlobals[EVENTS_KEY] = new EventTarget();\n }\n\n return windowGlobals[EVENTS_KEY] as EventTarget;\n};\n\n/**\n * Retrieves the global editor state manager instance.\n * Returns null if no manager has been set or in SSR environments where\n * window is undefined.\n *\n * @returns The global EditorStateManager instance or null if not set\n */\nexport const getGlobalEditorManager = (): EditorStateManager | null => {\n if (typeof window === 'undefined') {\n return null;\n }\n\n const windowGlobals = window as WindowWithEditorGlobals;\n const manager = windowGlobals[MANAGER_KEY];\n\n return manager ?? null;\n};\n\n/**\n * Sets the global editor state manager instance and notifies all listeners\n * of the change through a CustomEvent.\n *\n * @param manager - The EditorStateManager instance to set globally, or null to clear it\n */\nexport const setGlobalEditorManager = (\n manager: EditorStateManager | null\n): void => {\n if (typeof window !== 'undefined') {\n const windowGlobals = window as WindowWithEditorGlobals;\n windowGlobals[MANAGER_KEY] = manager;\n }\n\n const eventTarget = getEventTarget();\n\n eventTarget.dispatchEvent(\n new CustomEvent<EditorStateManager | null>('change', { detail: manager })\n );\n};\n\n/**\n * Registers a callback function to be invoked whenever the global editor\n * manager changes. Useful for reactive updates across the application.\n *\n * @param changeCallback - Function to invoke with the new manager state whenever it changes\n * @returns An unsubscribe function that removes the listener when called\n *\n * @example\n * ```typescript\n * const unsubscribe = onGlobalEditorManagerChange((manager) => {\n * console.log('Manager updated:', manager);\n * });\n *\n * // Later, clean up the listener\n * unsubscribe();\n * ```\n */\nexport const onGlobalEditorManagerChange = (\n changeCallback: (manager: EditorStateManager | null) => void\n): (() => void) => {\n const eventTarget = getEventTarget();\n\n const eventHandler = (event: Event) => {\n const customEvent = event as CustomEvent<EditorStateManager | null>;\n changeCallback(customEvent.detail);\n };\n\n eventTarget.addEventListener('change', eventHandler);\n\n return () => {\n eventTarget.removeEventListener('change', eventHandler);\n };\n};\n"],"mappings":";;;;;;;AAkBA,MAAM,cAAc;AACpB,MAAM,aAAa;;;;;;;;;;AAWnB,MAAM,uBAAoC;CACxC,IAAI,OAAO,WAAW,aAEpB,OAAO,IAAI,aAAa;CAG1B,MAAM,gBAAgB;CACtB,IAAI,CAAC,cAAc,aACjB,cAAc,cAAc,IAAI,aAAa;CAG/C,OAAO,cAAc;;;;;;;;;AAUvB,MAAa,+BAA0D;CACrE,IAAI,OAAO,WAAW,aACpB,OAAO;CAMT,OAFgBA,OAAc,gBAEZ;;;;;;;;AASpB,MAAa,0BACX,YACS;CACT,IAAI,OAAO,WAAW,aAAa;EACjC,MAAM,gBAAgB;EACtB,cAAc,eAAe;;CAK/B,AAFoB,gBAET,CAAC,cACV,IAAI,YAAuC,UAAU,EAAE,QAAQ,SAAS,CAAC,CAC1E;;;;;;;;;;;;;;;;;;;AAoBH,MAAa,+BACX,mBACiB;CACjB,MAAM,cAAc,gBAAgB;CAEpC,MAAM,gBAAgB,UAAiB;EAErC,eAAeC,MAAY,OAAO;;CAGpC,YAAY,iBAAiB,UAAU,aAAa;CAEpD,aAAa;EACX,YAAY,oBAAoB,UAAU,aAAa"}
1
+ {"version":3,"file":"globalManager.mjs","names":["windowGlobals","customEvent"],"sources":["../../../src/core/globalManager.ts"],"sourcesContent":["import type { EditorStateManager } from './EditorStateManager';\n\n/**\n * Type for storing custom properties on the global window object.\n * Used to safely attach singleton instances across multiple module instances.\n */\ntype WindowWithEditorGlobals = typeof window & {\n [MANAGER_KEY]?: EditorStateManager | null;\n [EVENTS_KEY]?: EventTarget;\n [key: string]: unknown;\n};\n\n/**\n * Keys on window used to share the singleton across multiple module instances.\n * When bundlers include @intlayer/editor more than once (e.g. framework package +\n * app), each copy has its own module-level variables. Using window ensures they\n * all read/write the same manager and event-target.\n */\nconst MANAGER_KEY = '__intlayer_editor_manager__';\nconst EVENTS_KEY = '__intlayer_editor_manager_events__';\n\n/**\n * Retrieves or creates a shared EventTarget for global editor manager events.\n * In browser environments, stores the EventTarget on window to ensure sharing\n * across multiple module instances. In SSR environments, creates a fresh\n * EventTarget (no sharing needed on server-side).\n *\n * @returns The shared EventTarget instance for dispatching manager change events\n * @private\n */\nconst getEventTarget = (): EventTarget => {\n if (typeof window === 'undefined') {\n // SSR fallback — create a fresh one (no sharing needed server-side)\n return new EventTarget();\n }\n\n const windowGlobals = window as WindowWithEditorGlobals;\n if (!windowGlobals[EVENTS_KEY]) {\n windowGlobals[EVENTS_KEY] = new EventTarget();\n }\n\n return windowGlobals[EVENTS_KEY] as EventTarget;\n};\n\n/**\n * Retrieves the global editor state manager instance.\n * Returns null if no manager has been set or in SSR environments where\n * window is undefined.\n *\n * @returns The global EditorStateManager instance or null if not set\n */\nexport const getGlobalEditorManager = (): EditorStateManager | null => {\n if (typeof window === 'undefined') {\n return null;\n }\n\n const windowGlobals = window as WindowWithEditorGlobals;\n const manager = windowGlobals[MANAGER_KEY];\n\n return manager ?? null;\n};\n\n/**\n * Sets the global editor state manager instance and notifies all listeners\n * of the change through a CustomEvent.\n *\n * @param manager - The EditorStateManager instance to set globally, or null to clear it\n */\nexport const setGlobalEditorManager = (\n manager: EditorStateManager | null\n): void => {\n if (typeof window !== 'undefined') {\n const windowGlobals = window as WindowWithEditorGlobals;\n windowGlobals[MANAGER_KEY] = manager;\n }\n\n const eventTarget = getEventTarget();\n\n eventTarget.dispatchEvent(\n new CustomEvent<EditorStateManager | null>('change', { detail: manager })\n );\n};\n\n/**\n * Registers a callback function to be invoked whenever the global editor\n * manager changes. Useful for reactive updates across the application.\n *\n * @param changeCallback - Function to invoke with the new manager state whenever it changes\n * @returns An unsubscribe function that removes the listener when called\n *\n * @example\n * ```typescript\n * const unsubscribe = onGlobalEditorManagerChange((manager) => {\n * console.log('Manager updated:', manager);\n * });\n *\n * // Later, clean up the listener\n * unsubscribe();\n * ```\n */\nexport const onGlobalEditorManagerChange = (\n changeCallback: (manager: EditorStateManager | null) => void\n): (() => void) => {\n const eventTarget = getEventTarget();\n\n const eventHandler = (event: Event) => {\n const customEvent = event as CustomEvent<EditorStateManager | null>;\n changeCallback(customEvent.detail);\n };\n\n eventTarget.addEventListener('change', eventHandler);\n\n return () => {\n eventTarget.removeEventListener('change', eventHandler);\n };\n};\n"],"mappings":";;;;;;;AAkBA,MAAM,cAAc;AACpB,MAAM,aAAa;;;;;;;;;;AAWnB,MAAM,uBAAoC;CACxC,IAAI,OAAO,WAAW,aAEpB,OAAO,IAAI,YAAY;CAGzB,MAAM,gBAAgB;CACtB,IAAI,CAAC,cAAc,aACjB,cAAc,cAAc,IAAI,YAAY;CAG9C,OAAO,cAAc;AACvB;;;;;;;;AASA,MAAa,+BAA0D;CACrE,IAAI,OAAO,WAAW,aACpB,OAAO;CAMT,OAFgBA,OAAc,gBAEZ;AACpB;;;;;;;AAQA,MAAa,0BACX,YACS;CACT,IAAI,OAAO,WAAW,aAAa;EACjC,MAAM,gBAAgB;EACtB,cAAc,eAAe;CAC/B;CAIA,AAFoB,eAEV,EAAE,cACV,IAAI,YAAuC,UAAU,EAAE,QAAQ,QAAQ,CAAC,CAC1E;AACF;;;;;;;;;;;;;;;;;;AAmBA,MAAa,+BACX,mBACiB;CACjB,MAAM,cAAc,eAAe;CAEnC,MAAM,gBAAgB,UAAiB;EAErC,eAAeC,MAAY,MAAM;CACnC;CAEA,YAAY,iBAAiB,UAAU,YAAY;CAEnD,aAAa;EACX,YAAY,oBAAoB,UAAU,YAAY;CACxD;AACF"}
@@ -1,9 +1,11 @@
1
1
  import { getGlobalEditorManager, onGlobalEditorManagerChange, setGlobalEditorManager } from "./globalManager.mjs";
2
2
  import { CrossFrameMessenger } from "./CrossFrameMessenger.mjs";
3
3
  import { CrossFrameStateManager } from "./CrossFrameStateManager.mjs";
4
+ import { getGlobalEditedContent, setGlobalEditedContent, subscribeToGlobalEditedContent } from "./editedContentBus.mjs";
5
+ import { getGlobalFocusedContent, setGlobalFocusedContent, subscribeToGlobalFocusedContent } from "./focusedContentBus.mjs";
4
6
  import { IframeClickInterceptor } from "./IframeClickInterceptor.mjs";
5
7
  import { UrlStateManager } from "./UrlStateManager.mjs";
6
8
  import { EditorStateManager } from "./EditorStateManager.mjs";
7
9
  import { buildClientMessengerConfig, initEditorClient, stopEditorClient } from "./initEditorClient.mjs";
8
10
 
9
- export { CrossFrameMessenger, CrossFrameStateManager, EditorStateManager, IframeClickInterceptor, UrlStateManager, buildClientMessengerConfig, getGlobalEditorManager, initEditorClient, onGlobalEditorManagerChange, setGlobalEditorManager, stopEditorClient };
11
+ export { CrossFrameMessenger, CrossFrameStateManager, EditorStateManager, IframeClickInterceptor, UrlStateManager, buildClientMessengerConfig, getGlobalEditedContent, getGlobalEditorManager, getGlobalFocusedContent, initEditorClient, onGlobalEditorManagerChange, setGlobalEditedContent, setGlobalEditorManager, setGlobalFocusedContent, stopEditorClient, subscribeToGlobalEditedContent, subscribeToGlobalFocusedContent };