@intlayer/editor 8.7.6 → 8.7.8-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 (51) hide show
  1. package/dist/cjs/components/ContentSelector.cjs +85 -75
  2. package/dist/cjs/components/ContentSelector.cjs.map +1 -1
  3. package/dist/cjs/components/ContentSelectorWrapper.cjs +131 -95
  4. package/dist/cjs/components/ContentSelectorWrapper.cjs.map +1 -1
  5. package/dist/cjs/components/EditedContent.cjs +74 -49
  6. package/dist/cjs/components/EditedContent.cjs.map +1 -1
  7. package/dist/cjs/components/IntlayerEditor.cjs +34 -27
  8. package/dist/cjs/components/IntlayerEditor.cjs.map +1 -1
  9. package/dist/cjs/core/CrossFrameMessenger.cjs +6 -3
  10. package/dist/cjs/core/CrossFrameMessenger.cjs.map +1 -1
  11. package/dist/cjs/core/CrossFrameStateManager.cjs +5 -1
  12. package/dist/cjs/core/CrossFrameStateManager.cjs.map +1 -1
  13. package/dist/cjs/core/EditorStateManager.cjs +14 -3
  14. package/dist/cjs/core/EditorStateManager.cjs.map +1 -1
  15. package/dist/cjs/core/IframeClickInterceptor.cjs +3 -2
  16. package/dist/cjs/core/IframeClickInterceptor.cjs.map +1 -1
  17. package/dist/cjs/core/UrlStateManager.cjs +4 -3
  18. package/dist/cjs/core/UrlStateManager.cjs.map +1 -1
  19. package/dist/cjs/core/globalManager.cjs.map +1 -1
  20. package/dist/cjs/core/initEditorClient.cjs.map +1 -1
  21. package/dist/esm/components/ContentSelector.mjs +85 -74
  22. package/dist/esm/components/ContentSelector.mjs.map +1 -1
  23. package/dist/esm/components/ContentSelectorWrapper.mjs +131 -95
  24. package/dist/esm/components/ContentSelectorWrapper.mjs.map +1 -1
  25. package/dist/esm/components/EditedContent.mjs +74 -49
  26. package/dist/esm/components/EditedContent.mjs.map +1 -1
  27. package/dist/esm/components/IntlayerEditor.mjs +34 -26
  28. package/dist/esm/components/IntlayerEditor.mjs.map +1 -1
  29. package/dist/esm/core/CrossFrameMessenger.mjs +6 -3
  30. package/dist/esm/core/CrossFrameMessenger.mjs.map +1 -1
  31. package/dist/esm/core/CrossFrameStateManager.mjs +5 -1
  32. package/dist/esm/core/CrossFrameStateManager.mjs.map +1 -1
  33. package/dist/esm/core/EditorStateManager.mjs +14 -3
  34. package/dist/esm/core/EditorStateManager.mjs.map +1 -1
  35. package/dist/esm/core/IframeClickInterceptor.mjs +3 -2
  36. package/dist/esm/core/IframeClickInterceptor.mjs.map +1 -1
  37. package/dist/esm/core/UrlStateManager.mjs +4 -3
  38. package/dist/esm/core/UrlStateManager.mjs.map +1 -1
  39. package/dist/esm/core/globalManager.mjs.map +1 -1
  40. package/dist/esm/core/initEditorClient.mjs.map +1 -1
  41. package/dist/types/components/ContentSelector.d.ts +15 -10
  42. package/dist/types/components/ContentSelector.d.ts.map +1 -1
  43. package/dist/types/components/ContentSelectorWrapper.d.ts +22 -12
  44. package/dist/types/components/ContentSelectorWrapper.d.ts.map +1 -1
  45. package/dist/types/components/EditedContent.d.ts +21 -10
  46. package/dist/types/components/EditedContent.d.ts.map +1 -1
  47. package/dist/types/components/IntlayerEditor.d.ts +16 -10
  48. package/dist/types/components/IntlayerEditor.d.ts.map +1 -1
  49. package/package.json +7 -8
  50. package/dist/cjs/_virtual/_@oxc-project_runtime@0.126.0/helpers/decorate.cjs +0 -11
  51. package/dist/esm/_virtual/_@oxc-project_runtime@0.126.0/helpers/decorate.mjs +0 -10
@@ -1,16 +1,14 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
3
  const require_core_globalManager = require('../core/globalManager.cjs');
4
- const require_decorate = require('../_virtual/_@oxc-project_runtime@0.126.0/helpers/decorate.cjs');
5
- let lit = require("lit");
6
- let lit_decorators_js = require("lit/decorators.js");
7
4
  let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
8
5
 
9
6
  //#region src/components/EditedContent.ts
7
+ const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
10
8
  /**
11
9
  * <intlayer-edited-content>
12
10
  *
13
- * Framework-agnostic Lit element that displays edited content from the Intlayer
11
+ * Framework-agnostic web component that displays edited content from the Intlayer
14
12
  * editor. When the editor has an edited value for the given dictionary key and
15
13
  * key path, it renders the edited value; otherwise it renders the original
16
14
  * content via a slot.
@@ -21,29 +19,67 @@ let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
21
19
  * @attr {string} key-path - JSON-serialized KeyPath[] for this content node
22
20
  * @attr {string} locale - The current locale string
23
21
  */
24
- var IntlayerEditedContentElement = class extends lit.LitElement {
25
- constructor(..._args) {
26
- super(..._args);
27
- this.dictionaryKey = "";
28
- this.keyPathJson = "[]";
29
- this.locale = "";
30
- this._editedText = null;
31
- this._unsubManager = null;
32
- this._unsubEditedContent = null;
22
+ var IntlayerEditedContentElement = class extends _HTMLElement {
23
+ _dictionaryKey = "";
24
+ _keyPathJson = "[]";
25
+ _locale = "";
26
+ _editedText = null;
27
+ _unsubManager = null;
28
+ _unsubEditedContent = null;
29
+ _selectorWrapper;
30
+ _slot;
31
+ static get observedAttributes() {
32
+ return [
33
+ "dictionary-key",
34
+ "key-path",
35
+ "locale"
36
+ ];
37
+ }
38
+ get dictionaryKey() {
39
+ return this._dictionaryKey;
40
+ }
41
+ set dictionaryKey(v) {
42
+ this._dictionaryKey = v;
43
+ this._selectorWrapper.setAttribute("dictionary-key", v);
44
+ }
45
+ get keyPathJson() {
46
+ return this._keyPathJson;
47
+ }
48
+ set keyPathJson(v) {
49
+ this._keyPathJson = v;
50
+ this._selectorWrapper.setAttribute("key-path", v);
51
+ }
52
+ get locale() {
53
+ return this._locale;
33
54
  }
34
- static {
35
- this.styles = lit.css`
36
- :host {
37
- display: contents;
38
- }
39
- `;
55
+ set locale(v) {
56
+ this._locale = v;
57
+ }
58
+ constructor() {
59
+ super();
60
+ const shadow = this.attachShadow({ mode: "open" });
61
+ const style = document.createElement("style");
62
+ style.textContent = ":host { display: contents; }";
63
+ shadow.appendChild(style);
64
+ this._selectorWrapper = document.createElement("intlayer-content-selector-wrapper");
65
+ this._slot = document.createElement("slot");
66
+ this._selectorWrapper.appendChild(this._slot);
67
+ shadow.appendChild(this._selectorWrapper);
68
+ }
69
+ attributeChangedCallback(name, _oldVal, newVal) {
70
+ const val = newVal ?? "";
71
+ if (name === "dictionary-key") {
72
+ this._dictionaryKey = val;
73
+ this._selectorWrapper.setAttribute("dictionary-key", val);
74
+ } else if (name === "key-path") {
75
+ this._keyPathJson = val || "[]";
76
+ this._selectorWrapper.setAttribute("key-path", this._keyPathJson);
77
+ } else if (name === "locale") this._locale = val;
40
78
  }
41
79
  connectedCallback() {
42
- super.connectedCallback();
43
80
  this._subscribeToManager();
44
81
  }
45
82
  disconnectedCallback() {
46
- super.disconnectedCallback();
47
83
  this._teardown();
48
84
  }
49
85
  _teardown() {
@@ -54,27 +90,34 @@ var IntlayerEditedContentElement = class extends lit.LitElement {
54
90
  }
55
91
  _getKeyPath() {
56
92
  try {
57
- return JSON.parse(this.keyPathJson);
93
+ return JSON.parse(this._keyPathJson);
58
94
  } catch {
59
95
  return [];
60
96
  }
61
97
  }
98
+ _render() {
99
+ while (this._selectorWrapper.firstChild) this._selectorWrapper.removeChild(this._selectorWrapper.firstChild);
100
+ if (this._editedText !== null) this._selectorWrapper.appendChild(document.createTextNode(this._editedText));
101
+ else this._selectorWrapper.appendChild(this._slot);
102
+ }
62
103
  _resolveEditedText(manager) {
63
104
  const keyPath = this._getKeyPath();
64
- const editedValue = manager.getContentValue(this.dictionaryKey, keyPath);
105
+ const editedValue = manager.getContentValue(this._dictionaryKey, keyPath);
65
106
  if (editedValue === void 0 || editedValue === null) {
66
107
  this._editedText = null;
108
+ this._render();
67
109
  return;
68
110
  }
69
111
  if (typeof editedValue === "string" || typeof editedValue === "number") {
70
112
  this._editedText = String(editedValue);
113
+ this._render();
71
114
  return;
72
115
  }
73
116
  if (typeof editedValue === "object") {
74
- const locale = this.locale || void 0;
117
+ const locale = this._locale || void 0;
75
118
  const transformed = (0, _intlayer_core_interpreter.getContent)(editedValue, {
76
119
  locale,
77
- dictionaryKey: this.dictionaryKey,
120
+ dictionaryKey: this._dictionaryKey,
78
121
  keyPath
79
122
  }, (0, _intlayer_core_interpreter.getBasePlugins)(locale));
80
123
  if (typeof transformed === "string" || typeof transformed === "number") this._editedText = String(transformed);
@@ -82,9 +125,11 @@ var IntlayerEditedContentElement = class extends lit.LitElement {
82
125
  console.error(`[intlayer-edited-content] Incorrect edited content format. Expected string. Value: ${JSON.stringify(transformed)}`);
83
126
  this._editedText = null;
84
127
  }
128
+ this._render();
85
129
  return;
86
130
  }
87
131
  this._editedText = null;
132
+ this._render();
88
133
  }
89
134
  _setupManagerSubscriptions(manager) {
90
135
  this._resolveEditedText(manager);
@@ -99,33 +144,13 @@ var IntlayerEditedContentElement = class extends lit.LitElement {
99
144
  this._unsubEditedContent?.();
100
145
  this._unsubEditedContent = null;
101
146
  if (m) this._setupManagerSubscriptions(m);
102
- else this._editedText = null;
147
+ else {
148
+ this._editedText = null;
149
+ this._render();
150
+ }
103
151
  });
104
152
  }
105
- render() {
106
- return lit.html`
107
- <intlayer-content-selector-wrapper
108
- key-path=${this.keyPathJson}
109
- dictionary-key=${this.dictionaryKey}
110
- >
111
- ${this._editedText !== null ? this._editedText : lit.html`<slot></slot>`}
112
- </intlayer-content-selector-wrapper>
113
- `;
114
- }
115
153
  };
116
- require_decorate.__decorate([(0, lit_decorators_js.property)({
117
- type: String,
118
- attribute: "dictionary-key"
119
- })], IntlayerEditedContentElement.prototype, "dictionaryKey", void 0);
120
- require_decorate.__decorate([(0, lit_decorators_js.property)({
121
- type: String,
122
- attribute: "key-path"
123
- })], IntlayerEditedContentElement.prototype, "keyPathJson", void 0);
124
- require_decorate.__decorate([(0, lit_decorators_js.property)({
125
- type: String,
126
- attribute: "locale"
127
- })], IntlayerEditedContentElement.prototype, "locale", void 0);
128
- require_decorate.__decorate([(0, lit_decorators_js.state)()], IntlayerEditedContentElement.prototype, "_editedText", void 0);
129
154
  const defineIntlayerEditedContent = () => {
130
155
  if (typeof customElements === "undefined") return;
131
156
  if (!customElements.get("intlayer-edited-content")) customElements.define("intlayer-edited-content", IntlayerEditedContentElement);
@@ -1 +1 @@
1
- {"version":3,"file":"EditedContent.cjs","names":["LitElement","getGlobalEditorManager","onGlobalEditorManagerChange"],"sources":["../../../src/components/EditedContent.ts"],"sourcesContent":["import { getBasePlugins, getContent } from '@intlayer/core/interpreter';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { css, html, LitElement } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport type { EditorStateManager } from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\n\n/**\n * <intlayer-edited-content>\n *\n * Framework-agnostic Lit element 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 LitElement {\n static styles = css`\n :host {\n display: contents;\n }\n `;\n\n @property({ type: String, attribute: 'dictionary-key' }) dictionaryKey = '';\n @property({ type: String, attribute: 'key-path' }) keyPathJson = '[]';\n @property({ type: String, attribute: 'locale' }) locale = '';\n\n @state() private _editedText: string | null = null;\n\n private _unsubManager: (() => void) | null = null;\n private _unsubEditedContent: (() => void) | null = null;\n\n connectedCallback(): void {\n super.connectedCallback();\n this._subscribeToManager();\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\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 _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 return;\n }\n\n if (typeof editedValue === 'string' || typeof editedValue === 'number') {\n this._editedText = String(editedValue);\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 return;\n }\n\n this._editedText = null;\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 }\n });\n }\n\n render() {\n return html`\n <intlayer-content-selector-wrapper\n key-path=${this.keyPathJson}\n dictionary-key=${this.dictionaryKey}\n >\n ${this._editedText !== null ? this._editedText : html`<slot></slot>`}\n </intlayer-content-selector-wrapper>\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":";;;;;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,sBAA4B;EAClC,MAAM,UAAUC,mDAAwB;AACxC,MAAI,QACF,MAAK,2BAA2B,QAAQ;AAG1C,OAAK,gBAAgBC,wDAA6B,MAAM;AACtD,QAAK,uBAAuB;AAC5B,QAAK,sBAAsB;AAC3B,OAAI,EACF,MAAK,2BAA2B,EAAE;OAElC,MAAK,cAAc;IAErB;;CAGJ,SAAS;AACP,SAAO,QAAI;;mBAEI,KAAK,YAAY;yBACX,KAAK,cAAc;;UAElC,KAAK,gBAAgB,OAAO,KAAK,cAAc,QAAI,gBAAgB;;;;;6DA1GjE;CAAE,MAAM;CAAQ,WAAW;CAAkB,CAAC;6DAC9C;CAAE,MAAM;CAAQ,WAAW;CAAY,CAAC;6DACxC;CAAE,MAAM;CAAQ,WAAW;CAAU,CAAC;2DAExC;AA4GV,MAAa,oCAA0C;AACrD,KAAI,OAAO,mBAAmB,YAAa;AAE3C,KAAI,CAAC,eAAe,IAAI,0BAA0B,CAChD,gBAAe,OACb,2BACA,6BACD"}
1
+ {"version":3,"file":"EditedContent.cjs","names":["getGlobalEditorManager","onGlobalEditorManagerChange"],"sources":["../../../src/components/EditedContent.ts"],"sourcesContent":["import { getBasePlugins, getContent } from '@intlayer/core/interpreter';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { EditorStateManager } from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-edited-content>\n *\n * Framework-agnostic web component that displays edited content from the Intlayer\n * editor. When the editor has an edited value for the given dictionary key and\n * key path, it renders the edited value; otherwise it renders the original\n * content via a slot.\n *\n * Always wraps content in <intlayer-content-selector-wrapper> for selection UI.\n *\n * @attr {string} dictionary-key - The dictionary key owning this content node\n * @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n * @attr {string} locale - The current locale string\n */\nexport class IntlayerEditedContentElement extends _HTMLElement {\n private _dictionaryKey = '';\n private _keyPathJson = '[]';\n private _locale = '';\n private _editedText: string | null = null;\n\n private _unsubManager: (() => void) | null = null;\n private _unsubEditedContent: (() => void) | null = null;\n\n private _selectorWrapper: HTMLElement;\n private _slot: HTMLSlotElement;\n\n static get observedAttributes(): string[] {\n return ['dictionary-key', 'key-path', 'locale'];\n }\n\n get dictionaryKey(): string {\n return this._dictionaryKey;\n }\n set dictionaryKey(v: string) {\n this._dictionaryKey = v;\n this._selectorWrapper.setAttribute('dictionary-key', v);\n }\n\n get keyPathJson(): string {\n return this._keyPathJson;\n }\n set keyPathJson(v: string) {\n this._keyPathJson = v;\n this._selectorWrapper.setAttribute('key-path', v);\n }\n\n get locale(): string {\n return this._locale;\n }\n set locale(v: string) {\n this._locale = v;\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n\n const style = document.createElement('style');\n style.textContent = ':host { display: contents; }';\n shadow.appendChild(style);\n\n this._selectorWrapper = document.createElement(\n 'intlayer-content-selector-wrapper'\n );\n this._slot = document.createElement('slot') as HTMLSlotElement;\n this._selectorWrapper.appendChild(this._slot);\n shadow.appendChild(this._selectorWrapper);\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n const val = newVal ?? '';\n if (name === 'dictionary-key') {\n this._dictionaryKey = val;\n this._selectorWrapper.setAttribute('dictionary-key', val);\n } else if (name === 'key-path') {\n this._keyPathJson = val || '[]';\n this._selectorWrapper.setAttribute('key-path', this._keyPathJson);\n } else if (name === 'locale') {\n this._locale = val;\n }\n }\n\n connectedCallback(): void {\n this._subscribeToManager();\n }\n\n disconnectedCallback(): void {\n this._teardown();\n }\n\n private _teardown(): void {\n this._unsubManager?.();\n this._unsubEditedContent?.();\n this._unsubManager = null;\n this._unsubEditedContent = null;\n }\n\n private _getKeyPath(): KeyPath[] {\n try {\n return JSON.parse(this._keyPathJson);\n } catch {\n return [];\n }\n }\n\n private _render(): void {\n while (this._selectorWrapper.firstChild) {\n this._selectorWrapper.removeChild(this._selectorWrapper.firstChild);\n }\n if (this._editedText !== null) {\n this._selectorWrapper.appendChild(\n document.createTextNode(this._editedText)\n );\n } else {\n this._selectorWrapper.appendChild(this._slot);\n }\n }\n\n private _resolveEditedText(manager: EditorStateManager): void {\n const keyPath = this._getKeyPath();\n const editedValue = manager.getContentValue(this._dictionaryKey, keyPath);\n\n if (editedValue === undefined || editedValue === null) {\n this._editedText = null;\n this._render();\n return;\n }\n\n if (typeof editedValue === 'string' || typeof editedValue === 'number') {\n this._editedText = String(editedValue);\n this._render();\n return;\n }\n\n if (typeof editedValue === 'object') {\n const locale = this._locale || undefined;\n const transformed = getContent(\n editedValue,\n {\n locale: locale as any,\n dictionaryKey: this._dictionaryKey,\n keyPath,\n },\n getBasePlugins(locale)\n );\n if (typeof transformed === 'string' || typeof transformed === 'number') {\n this._editedText = String(transformed);\n } else {\n console.error(\n `[intlayer-edited-content] Incorrect edited content format. Expected string. Value: ${JSON.stringify(transformed)}`\n );\n this._editedText = null;\n }\n this._render();\n return;\n }\n\n this._editedText = null;\n this._render();\n }\n\n private _setupManagerSubscriptions(manager: EditorStateManager): void {\n this._resolveEditedText(manager);\n\n const handleChange = () => this._resolveEditedText(manager);\n manager.editedContent.addEventListener('change', handleChange);\n\n this._unsubEditedContent = () =>\n manager.editedContent.removeEventListener('change', handleChange);\n }\n\n private _subscribeToManager(): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n this._setupManagerSubscriptions(manager);\n }\n\n this._unsubManager = onGlobalEditorManagerChange((m) => {\n this._unsubEditedContent?.();\n this._unsubEditedContent = null;\n if (m) {\n this._setupManagerSubscriptions(m);\n } else {\n this._editedText = null;\n this._render();\n }\n });\n }\n}\n\nexport const defineIntlayerEditedContent = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-edited-content')) {\n customElements.define(\n 'intlayer-edited-content',\n IntlayerEditedContentElement\n );\n }\n};\n"],"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,mBAAmB,QAAQ;AAC3D,UAAQ,cAAc,iBAAiB,UAAU,aAAa;AAE9D,OAAK,4BACH,QAAQ,cAAc,oBAAoB,UAAU,aAAa;;CAGrE,AAAQ,sBAA4B;EAClC,MAAM,UAAUA,mDAAwB;AACxC,MAAI,QACF,MAAK,2BAA2B,QAAQ;AAG1C,OAAK,gBAAgBC,wDAA6B,MAAM;AACtD,QAAK,uBAAuB;AAC5B,QAAK,sBAAsB;AAC3B,OAAI,EACF,MAAK,2BAA2B,EAAE;QAC7B;AACL,SAAK,cAAc;AACnB,SAAK,SAAS;;IAEhB;;;AAIN,MAAa,oCAA0C;AACrD,KAAI,OAAO,mBAAmB,YAAa;AAE3C,KAAI,CAAC,eAAe,IAAI,0BAA0B,CAChD,gBAAe,OACb,2BACA,6BACD"}
@@ -1,22 +1,19 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
2
  const require_core_globalManager = require('../core/globalManager.cjs');
4
- const require_decorate = require('../_virtual/_@oxc-project_runtime@0.126.0/helpers/decorate.cjs');
5
3
  const require_core_initEditorClient = require('../core/initEditorClient.cjs');
6
- let lit = require("lit");
7
- let lit_decorators_js = require("lit/decorators.js");
8
4
 
9
5
  //#region src/components/IntlayerEditor.ts
6
+ const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
10
7
  /**
11
8
  * <intlayer-editor>
12
9
  *
13
- * A framework-agnostic Lit element that manages the Intlayer editor singleton
10
+ * A framework-agnostic web component that manages the Intlayer editor singleton
14
11
  * lifecycle and keeps the current locale in sync with the EditorStateManager.
15
12
  *
16
13
  * Drop this element once at the root of your application to activate the editor.
17
- * It renders no UI (display: contents, empty shadow root).
14
+ * It renders no UI.
18
15
  *
19
- * @prop {IntlayerConfig} configuration - The Intlayer config (required; set as property, not attribute)
16
+ * @prop {IntlayerConfig} configuration - The Intlayer config (required; set as JS property, not attribute)
20
17
  * @prop {string} locale - The active application locale (attribute/property)
21
18
  *
22
19
  * @example
@@ -26,22 +23,38 @@ let lit_decorators_js = require("lit/decorators.js");
26
23
  * // Vue
27
24
  * <intlayer-editor :configuration="config" :locale="currentLocale" />
28
25
  */
29
- var IntlayerEditorElement = class extends lit.LitElement {
30
- constructor(..._args) {
31
- super(..._args);
32
- this._initialized = false;
33
- this._unsubManager = null;
26
+ var IntlayerEditorElement = class extends _HTMLElement {
27
+ _configuration = void 0;
28
+ _locale = void 0;
29
+ _initialized = false;
30
+ _unsubManager = null;
31
+ static get observedAttributes() {
32
+ return ["locale"];
33
+ }
34
+ get configuration() {
35
+ return this._configuration;
36
+ }
37
+ set configuration(v) {
38
+ this._configuration = v;
39
+ if (!this._initialized) this._init();
40
+ }
41
+ get locale() {
42
+ return this._locale;
34
43
  }
35
- /** No visible UI — render nothing into the shadow root */
36
- createRenderRoot() {
37
- return this;
44
+ set locale(v) {
45
+ this._locale = v;
46
+ if (v && this._initialized) this._syncLocale(v);
47
+ }
48
+ attributeChangedCallback(name, _oldVal, newVal) {
49
+ if (name === "locale" && newVal !== null) {
50
+ this._locale = newVal;
51
+ if (this._initialized) this._syncLocale(newVal);
52
+ }
38
53
  }
39
54
  connectedCallback() {
40
- super.connectedCallback();
41
55
  this._init();
42
56
  }
43
57
  disconnectedCallback() {
44
- super.disconnectedCallback();
45
58
  this._unsubManager?.();
46
59
  this._unsubManager = null;
47
60
  if (this._initialized) {
@@ -49,33 +62,27 @@ var IntlayerEditorElement = class extends lit.LitElement {
49
62
  this._initialized = false;
50
63
  }
51
64
  }
52
- updated(changedProperties) {
53
- if (changedProperties.has("configuration") && !this._initialized) this._init();
54
- if (changedProperties.has("locale") && this.locale) this._syncLocale(this.locale);
55
- }
56
65
  _init() {
57
66
  if (this._initialized) return;
58
67
  require_core_initEditorClient.initEditorClient();
59
68
  this._initialized = true;
60
- if (this.locale) this._syncLocale(this.locale);
69
+ if (this._locale) this._syncLocale(this._locale);
61
70
  }
62
71
  _syncLocale(locale) {
63
72
  const manager = require_core_globalManager.getGlobalEditorManager();
64
73
  if (manager) manager.currentLocale.set(locale);
65
74
  else {
66
75
  this._unsubManager?.();
67
- this._unsubManager = require_core_globalManager.onGlobalEditorManagerChange((manager) => {
68
- if (manager) {
76
+ this._unsubManager = require_core_globalManager.onGlobalEditorManagerChange((m) => {
77
+ if (m) {
69
78
  this._unsubManager?.();
70
79
  this._unsubManager = null;
71
- manager.currentLocale.set(locale);
80
+ m.currentLocale.set(locale);
72
81
  }
73
82
  });
74
83
  }
75
84
  }
76
85
  };
77
- require_decorate.__decorate([(0, lit_decorators_js.property)({ attribute: false })], IntlayerEditorElement.prototype, "configuration", void 0);
78
- require_decorate.__decorate([(0, lit_decorators_js.property)({ type: String })], IntlayerEditorElement.prototype, "locale", void 0);
79
86
  const defineIntlayerEditorElement = () => {
80
87
  if (typeof customElements === "undefined") return;
81
88
  if (!customElements.get("intlayer-editor")) customElements.define("intlayer-editor", IntlayerEditorElement);
@@ -1 +1 @@
1
- {"version":3,"file":"IntlayerEditor.cjs","names":["LitElement","getGlobalEditorManager","onGlobalEditorManagerChange"],"sources":["../../../src/components/IntlayerEditor.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\nimport { initEditorClient, stopEditorClient } from '../core/initEditorClient';\n\n/**\n * <intlayer-editor>\n *\n * A framework-agnostic Lit element 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 (display: contents, empty shadow root).\n *\n * @prop {IntlayerConfig} configuration - The Intlayer config (required; set as 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 LitElement {\n /** No visible UI render nothing into the shadow root */\n createRenderRoot(): this {\n return this;\n }\n\n @property({ attribute: false }) configuration?: IntlayerConfig;\n\n @property({ type: String }) locale?: string;\n\n private _initialized = false;\n private _unsubManager: (() => void) | null = null;\n\n connectedCallback(): void {\n super.connectedCallback();\n this._init();\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this._unsubManager?.();\n this._unsubManager = null;\n\n if (this._initialized) {\n stopEditorClient();\n this._initialized = false;\n }\n }\n\n updated(changedProperties: Map<string | symbol, unknown>): void {\n if (changedProperties.has('configuration') && !this._initialized) {\n this._init();\n }\n\n if (changedProperties.has('locale') && this.locale) {\n this._syncLocale(this.locale);\n }\n }\n\n private _init(): void {\n if (this._initialized) return;\n\n initEditorClient();\n\n this._initialized = true;\n\n // Sync locale immediately after init if it is already set\n if (this.locale) {\n this._syncLocale(this.locale);\n }\n }\n\n private _syncLocale(locale: string): void {\n const manager = getGlobalEditorManager();\n\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((manager) => {\n if (manager) {\n this._unsubManager?.();\n this._unsubManager = null;\n\n manager.currentLocale.set(locale as Locale);\n }\n });\n }\n }\n}\n\nexport const defineIntlayerEditorElement = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-editor')) {\n customElements.define('intlayer-editor', IntlayerEditorElement);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,wBAAb,cAA2CA,eAAW;;;sBAU7B;uBACsB;;;CAT7C,mBAAyB;AACvB,SAAO;;CAUT,oBAA0B;AACxB,QAAM,mBAAmB;AACzB,OAAK,OAAO;;CAGd,uBAA6B;AAC3B,QAAM,sBAAsB;AAC5B,OAAK,iBAAiB;AACtB,OAAK,gBAAgB;AAErB,MAAI,KAAK,cAAc;AACrB,mDAAkB;AAClB,QAAK,eAAe;;;CAIxB,QAAQ,mBAAwD;AAC9D,MAAI,kBAAkB,IAAI,gBAAgB,IAAI,CAAC,KAAK,aAClD,MAAK,OAAO;AAGd,MAAI,kBAAkB,IAAI,SAAS,IAAI,KAAK,OAC1C,MAAK,YAAY,KAAK,OAAO;;CAIjC,AAAQ,QAAc;AACpB,MAAI,KAAK,aAAc;AAEvB,kDAAkB;AAElB,OAAK,eAAe;AAGpB,MAAI,KAAK,OACP,MAAK,YAAY,KAAK,OAAO;;CAIjC,AAAQ,YAAY,QAAsB;EACxC,MAAM,UAAUC,mDAAwB;AAExC,MAAI,QACF,SAAQ,cAAc,IAAI,OAAiB;OACtC;AAEL,QAAK,iBAAiB;AACtB,QAAK,gBAAgBC,wDAA6B,YAAY;AAC5D,QAAI,SAAS;AACX,UAAK,iBAAiB;AACtB,UAAK,gBAAgB;AAErB,aAAQ,cAAc,IAAI,OAAiB;;KAE7C;;;;6DA7DI,EAAE,WAAW,OAAO,CAAC;6DAErB,EAAE,MAAM,QAAQ,CAAC;AAgE7B,MAAa,oCAA0C;AACrD,KAAI,OAAO,mBAAmB,YAAa;AAE3C,KAAI,CAAC,eAAe,IAAI,kBAAkB,CACxC,gBAAe,OAAO,mBAAmB,sBAAsB"}
1
+ {"version":3,"file":"IntlayerEditor.cjs","names":["getGlobalEditorManager","onGlobalEditorManagerChange"],"sources":["../../../src/components/IntlayerEditor.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\nimport { initEditorClient, stopEditorClient } from '../core/initEditorClient';\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-editor>\n *\n * A framework-agnostic web component that manages the Intlayer editor singleton\n * lifecycle and keeps the current locale in sync with the EditorStateManager.\n *\n * Drop this element once at the root of your application to activate the editor.\n * It renders no UI.\n *\n * @prop {IntlayerConfig} configuration - The Intlayer config (required; set as JS property, not attribute)\n * @prop {string} locale - The active application locale (attribute/property)\n *\n * @example\n * // Svelte\n * <intlayer-editor .configuration={config} locale={$locale} />\n *\n * // Vue\n * <intlayer-editor :configuration=\"config\" :locale=\"currentLocale\" />\n */\nexport class IntlayerEditorElement extends _HTMLElement {\n private _configuration: IntlayerConfig | undefined = undefined;\n private _locale: string | undefined = undefined;\n private _initialized = false;\n private _unsubManager: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['locale'];\n }\n\n get configuration(): IntlayerConfig | undefined {\n return this._configuration;\n }\n set configuration(v: IntlayerConfig | undefined) {\n this._configuration = v;\n if (!this._initialized) this._init();\n }\n\n get locale(): string | undefined {\n return this._locale;\n }\n set locale(v: string | undefined) {\n this._locale = v;\n if (v && this._initialized) this._syncLocale(v);\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'locale' && newVal !== null) {\n this._locale = newVal;\n if (this._initialized) this._syncLocale(newVal);\n }\n }\n\n connectedCallback(): void {\n this._init();\n }\n\n disconnectedCallback(): void {\n this._unsubManager?.();\n this._unsubManager = null;\n if (this._initialized) {\n stopEditorClient();\n this._initialized = false;\n }\n }\n\n private _init(): void {\n if (this._initialized) return;\n initEditorClient();\n this._initialized = true;\n if (this._locale) this._syncLocale(this._locale);\n }\n\n private _syncLocale(locale: string): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n manager.currentLocale.set(locale as Locale);\n } else {\n // Manager may not be ready yet — wait for it\n this._unsubManager?.();\n this._unsubManager = onGlobalEditorManagerChange((m) => {\n if (m) {\n this._unsubManager?.();\n this._unsubManager = null;\n m.currentLocale.set(locale as Locale);\n }\n });\n }\n }\n}\n\nexport const defineIntlayerEditorElement = (): void => {\n if (typeof customElements === 'undefined') return;\n if (!customElements.get('intlayer-editor')) {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oCAA0C;AACrD,KAAI,OAAO,mBAAmB,YAAa;AAC3C,KAAI,CAAC,eAAe,IAAI,kBAAkB,CACxC,gBAAe,OAAO,mBAAmB,sBAAsB"}
@@ -11,10 +11,13 @@ const randomUUID = () => Math.random().toString(36).slice(2);
11
11
  * Replaces CommunicatorContext + useCrossFrameMessageListener across all frameworks.
12
12
  */
13
13
  var CrossFrameMessenger = class {
14
+ senderId;
15
+ _config;
16
+ _subscribers = /* @__PURE__ */ new Map();
17
+ _windowHandler = null;
18
+ /** Tracks recently processed messageIds to discard duplicates (same payload sent to multiple origins) */
19
+ _seenMessageIds = /* @__PURE__ */ new Set();
14
20
  constructor(config) {
15
- this._subscribers = /* @__PURE__ */ new Map();
16
- this._windowHandler = null;
17
- this._seenMessageIds = /* @__PURE__ */ new Set();
18
21
  this._config = config;
19
22
  this.senderId = randomUUID();
20
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CrossFrameMessenger.cjs","names":["compareUrls"],"sources":["../../../src/core/CrossFrameMessenger.ts"],"sourcesContent":["import { compareUrls } from '../compareUrls';\n\nconst randomUUID = (): string => Math.random().toString(36).slice(2);\n\nexport type MessagePayload = {\n type: string;\n data?: unknown;\n senderId?: string;\n /** Unique ID per send() call — used to deduplicate when the same payload arrives via multiple target origins */\n messageId?: string;\n};\n\nexport type MessengerConfig = {\n /**\n * Origins allowed to send messages to this instance.\n * Use '*' to allow all origins (not recommended for production).\n */\n allowedOrigins: string[];\n /**\n * Function used to send messages to other frames.\n * Injected so the messenger is agnostic to the frame topology.\n */\n postMessageFn: (payload: MessagePayload, origin: string) => void;\n};\n\ntype MessageHandler<T = unknown> = (data: T, senderId?: string) => void;\n\n/**\n * CrossFrameMessenger manages all cross-frame postMessage communication.\n * It owns a single window message listener and routes incoming messages to\n * type-specific subscribers.\n *\n * Replaces CommunicatorContext + useCrossFrameMessageListener across all frameworks.\n */\nexport class CrossFrameMessenger {\n readonly senderId: string;\n private readonly _config: MessengerConfig;\n private readonly _subscribers = new Map<string, Set<MessageHandler>>();\n\n private _windowHandler: ((event: MessageEvent) => void) | null = null;\n /** Tracks recently processed messageIds to discard duplicates (same payload sent to multiple origins) */\n private readonly _seenMessageIds = new Set<string>();\n\n constructor(config: MessengerConfig) {\n this._config = config;\n this.senderId = randomUUID();\n }\n\n /** Start listening for incoming messages on window. */\n start(): void {\n if (typeof window === 'undefined') return;\n if (this._windowHandler) return;\n this._windowHandler = (event: MessageEvent<MessagePayload>) => {\n this._handleMessage(event);\n };\n window.addEventListener('message', this._windowHandler);\n }\n\n /** Stop listening and clean up. */\n stop(): void {\n if (this._windowHandler) {\n window.removeEventListener('message', this._windowHandler);\n this._windowHandler = null;\n }\n }\n\n /** Send a message payload to all configured target origins. */\n send(type: string, data?: unknown): void {\n const payload: MessagePayload = {\n type,\n data,\n senderId: this.senderId,\n messageId: randomUUID(),\n };\n\n for (const origin of this._config.allowedOrigins) {\n if (origin) {\n this._config.postMessageFn(payload, origin);\n }\n }\n }\n\n /**\n * Subscribe to messages of a given type.\n * Returns an unsubscribe function.\n */\n subscribe<T = unknown>(type: string, handler: MessageHandler<T>): () => void {\n if (!this._subscribers.has(type)) {\n this._subscribers.set(type, new Set());\n }\n this._subscribers.get(type)!.add(handler as MessageHandler);\n return () => {\n this._subscribers.get(type)?.delete(handler as MessageHandler);\n };\n }\n\n private _handleMessage(event: MessageEvent<MessagePayload>): void {\n const payload = event.data;\n if (!payload || typeof payload !== 'object') return;\n\n const { type, data, senderId: msgSenderId, messageId } = payload;\n if (!type || typeof type !== 'string') return;\n\n // Ignore messages originating from this instance\n if (msgSenderId === this.senderId) return;\n\n // Deduplicate: same messageId may arrive multiple times when the sender\n // posts to multiple target origins (one per allowedOrigin)\n if (messageId) {\n if (this._seenMessageIds.has(messageId)) return;\n this._seenMessageIds.add(messageId);\n // Keep the set bounded — clear when it exceeds 200 entries\n if (this._seenMessageIds.size > 200) this._seenMessageIds.clear();\n }\n\n // Validate message origin\n const { allowedOrigins } = this._config;\n const isAllowed =\n !allowedOrigins ||\n allowedOrigins.length === 0 ||\n allowedOrigins.includes('*') ||\n allowedOrigins\n .filter((url) => Boolean(url) && url !== '')\n .some((url) => compareUrls(url, event.origin));\n\n if (!isAllowed) return;\n\n const handlers = this._subscribers.get(type);\n\n if (handlers) {\n for (const handler of handlers) {\n handler(data, msgSenderId);\n }\n }\n }\n}\n"],"mappings":";;;;AAEA,MAAM,mBAA2B,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE;;;;;;;;AAgCpE,IAAa,sBAAb,MAAiC;CAS/B,YAAY,QAAyB;sCANL,IAAI,KAAkC;wBAEL;yCAE9B,IAAI,KAAa;AAGlD,OAAK,UAAU;AACf,OAAK,WAAW,YAAY;;;CAI9B,QAAc;AACZ,MAAI,OAAO,WAAW,YAAa;AACnC,MAAI,KAAK,eAAgB;AACzB,OAAK,kBAAkB,UAAwC;AAC7D,QAAK,eAAe,MAAM;;AAE5B,SAAO,iBAAiB,WAAW,KAAK,eAAe;;;CAIzD,OAAa;AACX,MAAI,KAAK,gBAAgB;AACvB,UAAO,oBAAoB,WAAW,KAAK,eAAe;AAC1D,QAAK,iBAAiB;;;;CAK1B,KAAK,MAAc,MAAsB;EACvC,MAAM,UAA0B;GAC9B;GACA;GACA,UAAU,KAAK;GACf,WAAW,YAAY;GACxB;AAED,OAAK,MAAM,UAAU,KAAK,QAAQ,eAChC,KAAI,OACF,MAAK,QAAQ,cAAc,SAAS,OAAO;;;;;;CASjD,UAAuB,MAAc,SAAwC;AAC3E,MAAI,CAAC,KAAK,aAAa,IAAI,KAAK,CAC9B,MAAK,aAAa,IAAI,sBAAM,IAAI,KAAK,CAAC;AAExC,OAAK,aAAa,IAAI,KAAK,CAAE,IAAI,QAA0B;AAC3D,eAAa;AACX,QAAK,aAAa,IAAI,KAAK,EAAE,OAAO,QAA0B;;;CAIlE,AAAQ,eAAe,OAA2C;EAChE,MAAM,UAAU,MAAM;AACtB,MAAI,CAAC,WAAW,OAAO,YAAY,SAAU;EAE7C,MAAM,EAAE,MAAM,MAAM,UAAU,aAAa,cAAc;AACzD,MAAI,CAAC,QAAQ,OAAO,SAAS,SAAU;AAGvC,MAAI,gBAAgB,KAAK,SAAU;AAInC,MAAI,WAAW;AACb,OAAI,KAAK,gBAAgB,IAAI,UAAU,CAAE;AACzC,QAAK,gBAAgB,IAAI,UAAU;AAEnC,OAAI,KAAK,gBAAgB,OAAO,IAAK,MAAK,gBAAgB,OAAO;;EAInE,MAAM,EAAE,mBAAmB,KAAK;AAShC,MAAI,EAPF,CAAC,kBACD,eAAe,WAAW,KAC1B,eAAe,SAAS,IAAI,IAC5B,eACG,QAAQ,QAAQ,QAAQ,IAAI,IAAI,QAAQ,GAAG,CAC3C,MAAM,QAAQA,gCAAY,KAAK,MAAM,OAAO,CAAC,EAElC;EAEhB,MAAM,WAAW,KAAK,aAAa,IAAI,KAAK;AAE5C,MAAI,SACF,MAAK,MAAM,WAAW,SACpB,SAAQ,MAAM,YAAY"}
1
+ {"version":3,"file":"CrossFrameMessenger.cjs","names":["compareUrls"],"sources":["../../../src/core/CrossFrameMessenger.ts"],"sourcesContent":["import { compareUrls } from '../compareUrls';\n\nconst randomUUID = (): string => Math.random().toString(36).slice(2);\n\nexport type MessagePayload = {\n type: string;\n data?: unknown;\n senderId?: string;\n /** Unique ID per send() call — used to deduplicate when the same payload arrives via multiple target origins */\n messageId?: string;\n};\n\nexport type MessengerConfig = {\n /**\n * Origins allowed to send messages to this instance.\n * Use '*' to allow all origins (not recommended for production).\n */\n allowedOrigins: string[];\n /**\n * Function used to send messages to other frames.\n * Injected so the messenger is agnostic to the frame topology.\n */\n postMessageFn: (payload: MessagePayload, origin: string) => void;\n};\n\ntype MessageHandler<T = unknown> = (data: T, senderId?: string) => void;\n\n/**\n * CrossFrameMessenger manages all cross-frame postMessage communication.\n * It owns a single window message listener and routes incoming messages to\n * type-specific subscribers.\n *\n * Replaces CommunicatorContext + useCrossFrameMessageListener across all frameworks.\n */\nexport class CrossFrameMessenger {\n readonly senderId: string;\n private readonly _config: MessengerConfig;\n private readonly _subscribers = new Map<string, Set<MessageHandler>>();\n\n private _windowHandler: ((event: MessageEvent) => void) | null = null;\n /** Tracks recently processed messageIds to discard duplicates (same payload sent to multiple origins) */\n private readonly _seenMessageIds = new Set<string>();\n\n constructor(config: MessengerConfig) {\n this._config = config;\n this.senderId = randomUUID();\n }\n\n /** Start listening for incoming messages on window. */\n start(): void {\n if (typeof window === 'undefined') return;\n if (this._windowHandler) return;\n this._windowHandler = (event: MessageEvent<MessagePayload>) => {\n this._handleMessage(event);\n };\n window.addEventListener('message', this._windowHandler);\n }\n\n /** Stop listening and clean up. */\n stop(): void {\n if (this._windowHandler) {\n window.removeEventListener('message', this._windowHandler);\n this._windowHandler = null;\n }\n }\n\n /** Send a message payload to all configured target origins. */\n send(type: string, data?: unknown): void {\n const payload: MessagePayload = {\n type,\n data,\n senderId: this.senderId,\n messageId: randomUUID(),\n };\n\n for (const origin of this._config.allowedOrigins) {\n if (origin) {\n this._config.postMessageFn(payload, origin);\n }\n }\n }\n\n /**\n * Subscribe to messages of a given type.\n * Returns an unsubscribe function.\n */\n subscribe<T = unknown>(type: string, handler: MessageHandler<T>): () => void {\n if (!this._subscribers.has(type)) {\n this._subscribers.set(type, new Set());\n }\n this._subscribers.get(type)!.add(handler as MessageHandler);\n return () => {\n this._subscribers.get(type)?.delete(handler as MessageHandler);\n };\n }\n\n private _handleMessage(event: MessageEvent<MessagePayload>): void {\n const payload = event.data;\n if (!payload || typeof payload !== 'object') return;\n\n const { type, data, senderId: msgSenderId, messageId } = payload;\n if (!type || typeof type !== 'string') return;\n\n // Ignore messages originating from this instance\n if (msgSenderId === this.senderId) return;\n\n // Deduplicate: same messageId may arrive multiple times when the sender\n // posts to multiple target origins (one per allowedOrigin)\n if (messageId) {\n if (this._seenMessageIds.has(messageId)) return;\n this._seenMessageIds.add(messageId);\n // Keep the set bounded — clear when it exceeds 200 entries\n if (this._seenMessageIds.size > 200) this._seenMessageIds.clear();\n }\n\n // Validate message origin\n const { allowedOrigins } = this._config;\n const isAllowed =\n !allowedOrigins ||\n allowedOrigins.length === 0 ||\n allowedOrigins.includes('*') ||\n allowedOrigins\n .filter((url) => Boolean(url) && url !== '')\n .some((url) => compareUrls(url, event.origin));\n\n if (!isAllowed) return;\n\n const handlers = this._subscribers.get(type);\n\n if (handlers) {\n for (const handler of handlers) {\n handler(data, msgSenderId);\n }\n }\n }\n}\n"],"mappings":";;;;AAEA,MAAM,mBAA2B,KAAK,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;AACnC,OAAK,UAAU;AACf,OAAK,WAAW,YAAY;;;CAI9B,QAAc;AACZ,MAAI,OAAO,WAAW,YAAa;AACnC,MAAI,KAAK,eAAgB;AACzB,OAAK,kBAAkB,UAAwC;AAC7D,QAAK,eAAe,MAAM;;AAE5B,SAAO,iBAAiB,WAAW,KAAK,eAAe;;;CAIzD,OAAa;AACX,MAAI,KAAK,gBAAgB;AACvB,UAAO,oBAAoB,WAAW,KAAK,eAAe;AAC1D,QAAK,iBAAiB;;;;CAK1B,KAAK,MAAc,MAAsB;EACvC,MAAM,UAA0B;GAC9B;GACA;GACA,UAAU,KAAK;GACf,WAAW,YAAY;GACxB;AAED,OAAK,MAAM,UAAU,KAAK,QAAQ,eAChC,KAAI,OACF,MAAK,QAAQ,cAAc,SAAS,OAAO;;;;;;CASjD,UAAuB,MAAc,SAAwC;AAC3E,MAAI,CAAC,KAAK,aAAa,IAAI,KAAK,CAC9B,MAAK,aAAa,IAAI,sBAAM,IAAI,KAAK,CAAC;AAExC,OAAK,aAAa,IAAI,KAAK,CAAE,IAAI,QAA0B;AAC3D,eAAa;AACX,QAAK,aAAa,IAAI,KAAK,EAAE,OAAO,QAA0B;;;CAIlE,AAAQ,eAAe,OAA2C;EAChE,MAAM,UAAU,MAAM;AACtB,MAAI,CAAC,WAAW,OAAO,YAAY,SAAU;EAE7C,MAAM,EAAE,MAAM,MAAM,UAAU,aAAa,cAAc;AACzD,MAAI,CAAC,QAAQ,OAAO,SAAS,SAAU;AAGvC,MAAI,gBAAgB,KAAK,SAAU;AAInC,MAAI,WAAW;AACb,OAAI,KAAK,gBAAgB,IAAI,UAAU,CAAE;AACzC,QAAK,gBAAgB,IAAI,UAAU;AAEnC,OAAI,KAAK,gBAAgB,OAAO,IAAK,MAAK,gBAAgB,OAAO;;EAInE,MAAM,EAAE,mBAAmB,KAAK;AAShC,MAAI,EAPF,CAAC,kBACD,eAAe,WAAW,KAC1B,eAAe,SAAS,IAAI,IAC5B,eACG,QAAQ,QAAQ,QAAQ,IAAI,IAAI,QAAQ,GAAG,CAC3C,MAAM,QAAQA,gCAAY,KAAK,MAAM,OAAO,CAAC,EAElC;EAEhB,MAAM,WAAW,KAAK,aAAa,IAAI,KAAK;AAE5C,MAAI,SACF,MAAK,MAAM,WAAW,SACpB,SAAQ,MAAM,YAAY"}
@@ -14,9 +14,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
14
14
  * @fires change — CustomEvent<T> dispatched whenever the value changes (local set or received)
15
15
  */
16
16
  var CrossFrameStateManager = class extends EventTarget {
17
+ _value;
18
+ _key;
19
+ _messenger;
20
+ _options;
21
+ _unsubscribers = [];
17
22
  constructor(key, messenger, options = {}) {
18
23
  super();
19
- this._unsubscribers = [];
20
24
  this._key = key;
21
25
  this._messenger = messenger;
22
26
  this._options = {
@@ -1 +1 @@
1
- {"version":3,"file":"CrossFrameStateManager.cjs","names":[],"sources":["../../../src/core/CrossFrameStateManager.ts"],"sourcesContent":["import type { CrossFrameMessenger } from './CrossFrameMessenger';\n\nexport type CrossFrameStateOptions = {\n /** Whether to broadcast state changes to other frames. Default: true */\n emit?: boolean;\n /** Whether to listen for state updates from other frames. Default: true */\n receive?: boolean;\n};\n\n/**\n * CrossFrameStateManager synchronizes a single named value across frames using\n * the postMessage API via CrossFrameMessenger.\n *\n * Protocol:\n * `{key}/post` — broadcast a new value\n * `{key}/get` — request the current value from other frames\n *\n * Replaces useCrossFrameState across all frameworks.\n *\n * @fires change — CustomEvent<T> dispatched whenever the value changes (local set or received)\n */\nexport class CrossFrameStateManager<T> extends EventTarget {\n private _value: T | undefined;\n private readonly _key: string;\n private readonly _messenger: CrossFrameMessenger;\n private readonly _options: Required<CrossFrameStateOptions>;\n private readonly _unsubscribers: Array<() => void> = [];\n\n constructor(\n key: string,\n messenger: CrossFrameMessenger,\n options: CrossFrameStateOptions & { initialValue?: T } = {}\n ) {\n super();\n this._key = key;\n this._messenger = messenger;\n this._options = {\n emit: options.emit ?? true,\n receive: options.receive ?? true,\n };\n if (options.initialValue !== undefined) {\n this._value = options.initialValue;\n }\n }\n\n get value(): T | undefined {\n return this._value;\n }\n\n /** Update the value locally and broadcast it to other frames if emit is enabled. */\n set(newValue: T): void {\n this._value = newValue;\n this.dispatchEvent(new CustomEvent<T>('change', { detail: newValue }));\n if (this._options.emit) {\n this._messenger.send(`${this._key}/post`, newValue);\n }\n }\n\n /**\n * Start listening for incoming state updates and responding to /get requests.\n * If receive=true and no initial value is set, sends a /get to request the current value.\n */\n start(): void {\n if (this._options.receive) {\n const unsub = this._messenger.subscribe<T>(\n `${this._key}/post`,\n (data) => {\n this._value = data;\n this.dispatchEvent(new CustomEvent<T>('change', { detail: data }));\n }\n );\n this._unsubscribers.push(unsub);\n }\n\n if (this._options.emit) {\n // Respond to /get requests by broadcasting current value\n const unsub = this._messenger.subscribe(\n `${this._key}/get`,\n (_, originSenderId) => {\n if (originSenderId === this._messenger.senderId) return;\n if (this._value === undefined) return;\n this._messenger.send(`${this._key}/post`, this._value);\n }\n );\n this._unsubscribers.push(unsub);\n }\n\n // If receiving and no initial value, request it from other frames\n if (this._options.receive && this._value === undefined) {\n this._messenger.send(`${this._key}/get`);\n }\n }\n\n /** Stop all listeners. */\n stop(): void {\n for (const unsub of this._unsubscribers) unsub();\n this._unsubscribers.length = 0;\n }\n\n /** Broadcast the current value to all frames (useful after 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;CAOzD,YACE,KACA,WACA,UAAyD,EAAE,EAC3D;AACA,SAAO;wBAP4C,EAAE;AAQrD,OAAK,OAAO;AACZ,OAAK,aAAa;AAClB,OAAK,WAAW;GACd,MAAM,QAAQ,QAAQ;GACtB,SAAS,QAAQ,WAAW;GAC7B;AACD,MAAI,QAAQ,iBAAiB,OAC3B,MAAK,SAAS,QAAQ;;CAI1B,IAAI,QAAuB;AACzB,SAAO,KAAK;;;CAId,IAAI,UAAmB;AACrB,OAAK,SAAS;AACd,OAAK,cAAc,IAAI,YAAe,UAAU,EAAE,QAAQ,UAAU,CAAC,CAAC;AACtE,MAAI,KAAK,SAAS,KAChB,MAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,SAAS;;;;;;CAQvD,QAAc;AACZ,MAAI,KAAK,SAAS,SAAS;GACzB,MAAM,QAAQ,KAAK,WAAW,UAC5B,GAAG,KAAK,KAAK,SACZ,SAAS;AACR,SAAK,SAAS;AACd,SAAK,cAAc,IAAI,YAAe,UAAU,EAAE,QAAQ,MAAM,CAAC,CAAC;KAErE;AACD,QAAK,eAAe,KAAK,MAAM;;AAGjC,MAAI,KAAK,SAAS,MAAM;GAEtB,MAAM,QAAQ,KAAK,WAAW,UAC5B,GAAG,KAAK,KAAK,QACZ,GAAG,mBAAmB;AACrB,QAAI,mBAAmB,KAAK,WAAW,SAAU;AACjD,QAAI,KAAK,WAAW,OAAW;AAC/B,SAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,OAAO;KAEzD;AACD,QAAK,eAAe,KAAK,MAAM;;AAIjC,MAAI,KAAK,SAAS,WAAW,KAAK,WAAW,OAC3C,MAAK,WAAW,KAAK,GAAG,KAAK,KAAK,MAAM;;;CAK5C,OAAa;AACX,OAAK,MAAM,SAAS,KAAK,eAAgB,QAAO;AAChD,OAAK,eAAe,SAAS;;;CAI/B,mBAAyB;AACvB,MAAI,KAAK,WAAW,OAClB,MAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,OAAO"}
1
+ {"version":3,"file":"CrossFrameStateManager.cjs","names":[],"sources":["../../../src/core/CrossFrameStateManager.ts"],"sourcesContent":["import type { CrossFrameMessenger } from './CrossFrameMessenger';\n\nexport type CrossFrameStateOptions = {\n /** Whether to broadcast state changes to other frames. Default: true */\n emit?: boolean;\n /** Whether to listen for state updates from other frames. Default: true */\n receive?: boolean;\n};\n\n/**\n * CrossFrameStateManager synchronizes a single named value across frames using\n * the postMessage API via CrossFrameMessenger.\n *\n * Protocol:\n * `{key}/post` — broadcast a new value\n * `{key}/get` — request the current value from other frames\n *\n * Replaces useCrossFrameState across all frameworks.\n *\n * @fires change — CustomEvent<T> dispatched whenever the value changes (local set or received)\n */\nexport class CrossFrameStateManager<T> extends EventTarget {\n private _value: T | undefined;\n private readonly _key: string;\n private readonly _messenger: CrossFrameMessenger;\n private readonly _options: Required<CrossFrameStateOptions>;\n private readonly _unsubscribers: Array<() => void> = [];\n\n constructor(\n key: string,\n messenger: CrossFrameMessenger,\n options: CrossFrameStateOptions & { initialValue?: T } = {}\n ) {\n super();\n this._key = key;\n this._messenger = messenger;\n this._options = {\n emit: options.emit ?? true,\n receive: options.receive ?? true,\n };\n if (options.initialValue !== undefined) {\n this._value = options.initialValue;\n }\n }\n\n get value(): T | undefined {\n return this._value;\n }\n\n /** Update the value locally and broadcast it to other frames if emit is enabled. */\n set(newValue: T): void {\n this._value = newValue;\n this.dispatchEvent(new CustomEvent<T>('change', { detail: newValue }));\n if (this._options.emit) {\n this._messenger.send(`${this._key}/post`, newValue);\n }\n }\n\n /**\n * Start listening for incoming state updates and responding to /get requests.\n * If receive=true and no initial value is set, sends a /get to request the current value.\n */\n start(): void {\n if (this._options.receive) {\n const unsub = this._messenger.subscribe<T>(\n `${this._key}/post`,\n (data) => {\n this._value = data;\n this.dispatchEvent(new CustomEvent<T>('change', { detail: data }));\n }\n );\n this._unsubscribers.push(unsub);\n }\n\n if (this._options.emit) {\n // Respond to /get requests by broadcasting current value\n const unsub = this._messenger.subscribe(\n `${this._key}/get`,\n (_, originSenderId) => {\n if (originSenderId === this._messenger.senderId) return;\n if (this._value === undefined) return;\n this._messenger.send(`${this._key}/post`, this._value);\n }\n );\n this._unsubscribers.push(unsub);\n }\n\n // If receiving and no initial value, request it from other frames\n if (this._options.receive && this._value === undefined) {\n this._messenger.send(`${this._key}/get`);\n }\n }\n\n /** Stop all listeners. */\n stop(): void {\n for (const unsub of this._unsubscribers) unsub();\n this._unsubscribers.length = 0;\n }\n\n /** Broadcast the current value to all frames (useful after reconnect). */\n postCurrentValue(): void {\n if (this._value !== undefined) {\n this._messenger.send(`${this._key}/post`, this._value);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,IAAa,yBAAb,cAA+C,YAAY;CACzD,AAAQ;CACR,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB,iBAAoC,EAAE;CAEvD,YACE,KACA,WACA,UAAyD,EAAE,EAC3D;AACA,SAAO;AACP,OAAK,OAAO;AACZ,OAAK,aAAa;AAClB,OAAK,WAAW;GACd,MAAM,QAAQ,QAAQ;GACtB,SAAS,QAAQ,WAAW;GAC7B;AACD,MAAI,QAAQ,iBAAiB,OAC3B,MAAK,SAAS,QAAQ;;CAI1B,IAAI,QAAuB;AACzB,SAAO,KAAK;;;CAId,IAAI,UAAmB;AACrB,OAAK,SAAS;AACd,OAAK,cAAc,IAAI,YAAe,UAAU,EAAE,QAAQ,UAAU,CAAC,CAAC;AACtE,MAAI,KAAK,SAAS,KAChB,MAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,SAAS;;;;;;CAQvD,QAAc;AACZ,MAAI,KAAK,SAAS,SAAS;GACzB,MAAM,QAAQ,KAAK,WAAW,UAC5B,GAAG,KAAK,KAAK,SACZ,SAAS;AACR,SAAK,SAAS;AACd,SAAK,cAAc,IAAI,YAAe,UAAU,EAAE,QAAQ,MAAM,CAAC,CAAC;KAErE;AACD,QAAK,eAAe,KAAK,MAAM;;AAGjC,MAAI,KAAK,SAAS,MAAM;GAEtB,MAAM,QAAQ,KAAK,WAAW,UAC5B,GAAG,KAAK,KAAK,QACZ,GAAG,mBAAmB;AACrB,QAAI,mBAAmB,KAAK,WAAW,SAAU;AACjD,QAAI,KAAK,WAAW,OAAW;AAC/B,SAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,OAAO;KAEzD;AACD,QAAK,eAAe,KAAK,MAAM;;AAIjC,MAAI,KAAK,SAAS,WAAW,KAAK,WAAW,OAC3C,MAAK,WAAW,KAAK,GAAG,KAAK,KAAK,MAAM;;;CAK5C,OAAa;AACX,OAAK,MAAM,SAAS,KAAK,eAAgB,QAAO;AAChD,OAAK,eAAe,SAAS;;;CAI/B,mBAAyB;AACvB,MAAI,KAAK,WAAW,OAClB,MAAK,WAAW,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,OAAO"}
@@ -19,10 +19,21 @@ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryMan
19
19
  * Solid, Svelte, and Vue integrations.
20
20
  */
21
21
  var EditorStateManager = class {
22
+ messenger;
23
+ editorEnabled;
24
+ focusedContent;
25
+ localeDictionaries;
26
+ editedContent;
27
+ configuration;
28
+ currentLocale;
29
+ _urlManager;
30
+ _iframeInterceptor;
31
+ _mode;
32
+ _configuration;
33
+ _unsubAreYouThere = null;
34
+ _unsubActivate = null;
35
+ _unsubClientReady = null;
22
36
  constructor(config) {
23
- this._unsubAreYouThere = null;
24
- this._unsubActivate = null;
25
- this._unsubClientReady = null;
26
37
  this._mode = config.mode;
27
38
  this._configuration = config.configuration;
28
39
  this.messenger = new require_core_CrossFrameMessenger.CrossFrameMessenger(config.messenger);
@@ -1 +1 @@
1
- {"version":3,"file":"EditorStateManager.cjs","names":["CrossFrameMessenger","CrossFrameStateManager","UrlStateManager","IframeClickInterceptor","NodeTypes"],"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;CAoB9B,YAAY,QAAkC;2BALG;wBACH;2BAEG;AAG/C,OAAK,QAAQ,OAAO;AACpB,OAAK,iBAAiB,OAAO;AAE7B,OAAK,YAAY,IAAIA,qDAAoB,OAAO,UAAU;AAE1D,OAAK,gBAAgB,IAAIC,sFAEvB,KAAK,WACL;GAAE,MAAM;GAAO,SAAS;GAAM,cAAc;GAAO,CACpD;AAED,OAAK,iBAAiB,IAAIA,+FAExB,KAAK,WACL;GAAE,MAAM;GAAM,SAAS;GAAM,cAAc;GAAM,CAClD;AAED,OAAK,qBAAqB,IAAIA,mGAE5B,KAAK,UACN;AAED,OAAK,gBAAgB,IAAIA,8FAEvB,KAAK,UACN;AAED,OAAK,gBAAgB,IAAIA,qFAEvB,KAAK,WACL;GACE,MAAM;GACN,SAAS;GACT,GAAI,OAAO,gBAAgB,EAAE,cAAc,O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,OAAO,YAC9B,OAAO,OAAO,qBAAqB,CAChC,MAAM,CACN,KAAK,eAAe,CAAC,WAAW,SAAS,WAAW,CAAC,CACzD;AAED,QAAK,mBAAmB,IAAI,iBAAiB;AAI7C,OAAI,KAAK,cAAc,MACrB,MAAK,gBAAgB;WAEhB,GAAG;AAEV,WAAQ,KAAK,oDAAoD,EAAE"}
1
+ {"version":3,"file":"EditorStateManager.cjs","names":["CrossFrameMessenger","CrossFrameStateManager","UrlStateManager","IframeClickInterceptor","NodeTypes"],"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,AAAQ,oBAAyC;CAEjD,YAAY,QAAkC;AAC5C,OAAK,QAAQ,OAAO;AACpB,OAAK,iBAAiB,OAAO;AAE7B,OAAK,YAAY,IAAIA,qDAAoB,OAAO,UAAU;AAE1D,OAAK,gBAAgB,IAAIC,sFAEvB,KAAK,WACL;GAAE,MAAM;GAAO,SAAS;GAAM,cAAc;GAAO,CACpD;AAED,OAA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C,UACD;EAEH,MAAM,YAAY,KAAK,cAAc;AAErC,MAAI,UACF,MAAK,UAAU,KACb,6BAAsC,QACtC,UACD;EAEH,MAAM,QAAQ,KAAK,mBAAmB;AAEtC,MAAI,MACF,MAAK,UAAU,KACb,0CAAmD,QACnD,MACD;;CAIL,MAAc,oBAAmC;AAC/C,MAAI;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;AAED,QAAK,mBAAmB,IAAI,iBAAiB;AAI7C,OAAI,KAAK,cAAc,MACrB,MAAK,gBAAgB;WAEhB,GAAG;AAEV,WAAQ,KAAK,oDAAoD,EAAE"}
@@ -12,9 +12,10 @@ const require_mergeIframeClick = require('../mergeIframeClick.cjs');
12
12
  * Replaces useIframeClickInterceptor / useIframeClickMerger across all frameworks.
13
13
  */
14
14
  var IframeClickInterceptor = class {
15
+ _messenger;
16
+ _mousedownHandler = null;
17
+ _unsubscribeMerge = null;
15
18
  constructor(messenger) {
16
- this._mousedownHandler = null;
17
- this._unsubscribeMerge = null;
18
19
  this._messenger = messenger;
19
20
  }
20
21
  /** Called on the client side (inside iframe). Broadcasts click events to parent. */
@@ -1 +1 @@
1
- {"version":3,"file":"IframeClickInterceptor.cjs","names":["mergeIframeClick"],"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;CAKlC,YAAY,WAAgC;2BAHM;2BACD;AAG/C,OAAK,aAAa;;;CAIpB,mBAAyB;AACvB,MAAI,OAAO,WAAW,YAAa;AACnC,OAAK,0BAA0B;AAC7B,QAAK,WAAW,+BAAwC;;AAE1D,SAAO,iBAAiB,aAAa,KAAK,kBAAkB;;;CAI9D,cAAoB;AAClB,OAAK,oBAAoB,KAAK,WAAW,qCAEvCA,0CACD;;CAGH,kBAAwB;AACtB,MAAI,KAAK,mBAAmB;AAC1B,UAAO,oBAAoB,aAAa,KAAK,kBAAkB;AAC/D,QAAK,oBAAoB;;;CAI7B,aAAmB;AACjB,OAAK,qBAAqB;AAC1B,OAAK,oBAAoB"}
1
+ {"version":3,"file":"IframeClickInterceptor.cjs","names":["mergeIframeClick"],"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;AAC1C,OAAK,aAAa;;;CAIpB,mBAAyB;AACvB,MAAI,OAAO,WAAW,YAAa;AACnC,OAAK,0BAA0B;AAC7B,QAAK,WAAW,+BAAwC;;AAE1D,SAAO,iBAAiB,aAAa,KAAK,kBAAkB;;;CAI9D,cAAoB;AAClB,OAAK,oBAAoB,KAAK,WAAW,qCAEvCA,0CACD;;CAGH,kBAAwB;AACtB,MAAI,KAAK,mBAAmB;AAC1B,UAAO,oBAAoB,aAAa,KAAK,kBAAkB;AAC/D,QAAK,oBAAoB;;;CAI7B,aAAmB;AACjB,OAAK,qBAAqB;AAC1B,OAAK,oBAAoB"}