@intlayer/editor 9.6.0 → 9.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -2
  2. package/dist/cjs/compareUrls.cjs +1 -2
  3. package/dist/cjs/components/ContentSelector.cjs +70 -17
  4. package/dist/cjs/components/ContentSelector.cjs.map +1 -1
  5. package/dist/cjs/components/ContentSelectorWrapper.cjs +63 -6
  6. package/dist/cjs/components/ContentSelectorWrapper.cjs.map +1 -1
  7. package/dist/cjs/components/index.cjs +2 -2
  8. package/dist/cjs/components/isInteractiveClickTarget.cjs +65 -0
  9. package/dist/cjs/components/isInteractiveClickTarget.cjs.map +1 -0
  10. package/dist/cjs/core/CrossFrameMessenger.cjs +2 -3
  11. package/dist/cjs/core/CrossFrameStateManager.cjs +1 -2
  12. package/dist/cjs/core/EditorStateManager.cjs +79 -18
  13. package/dist/cjs/core/EditorStateManager.cjs.map +1 -1
  14. package/dist/cjs/core/IframeClickInterceptor.cjs +17 -10
  15. package/dist/cjs/core/IframeClickInterceptor.cjs.map +1 -1
  16. package/dist/cjs/core/UrlStateManager.cjs +2 -3
  17. package/dist/cjs/core/getLocalEditorParentOrigin.cjs +32 -0
  18. package/dist/cjs/core/getLocalEditorParentOrigin.cjs.map +1 -0
  19. package/dist/cjs/core/globalManager.cjs +1 -2
  20. package/dist/cjs/core/index.cjs +10 -8
  21. package/dist/cjs/core/initEditorClient.cjs +8 -6
  22. package/dist/cjs/core/initEditorClient.cjs.map +1 -1
  23. package/dist/cjs/core/selectionClick.cjs +24 -0
  24. package/dist/cjs/core/selectionClick.cjs.map +1 -0
  25. package/dist/cjs/core/sharedWindowState.cjs +1 -2
  26. package/dist/cjs/index.cjs +13 -11
  27. package/dist/cjs/isEnabled.cjs +1 -2
  28. package/dist/cjs/messageKey.cjs +5 -2
  29. package/dist/cjs/messageKey.cjs.map +1 -1
  30. package/dist/esm/compareUrls.mjs +1 -2
  31. package/dist/esm/components/ContentSelector.mjs +69 -16
  32. package/dist/esm/components/ContentSelector.mjs.map +1 -1
  33. package/dist/esm/components/ContentSelectorWrapper.mjs +61 -4
  34. package/dist/esm/components/ContentSelectorWrapper.mjs.map +1 -1
  35. package/dist/esm/components/index.mjs +1 -1
  36. package/dist/esm/components/isInteractiveClickTarget.mjs +64 -0
  37. package/dist/esm/components/isInteractiveClickTarget.mjs.map +1 -0
  38. package/dist/esm/core/CrossFrameMessenger.mjs +1 -2
  39. package/dist/esm/core/CrossFrameStateManager.mjs +1 -2
  40. package/dist/esm/core/EditorStateManager.mjs +71 -12
  41. package/dist/esm/core/EditorStateManager.mjs.map +1 -1
  42. package/dist/esm/core/IframeClickInterceptor.mjs +16 -9
  43. package/dist/esm/core/IframeClickInterceptor.mjs.map +1 -1
  44. package/dist/esm/core/UrlStateManager.mjs +1 -2
  45. package/dist/esm/core/getLocalEditorParentOrigin.mjs +31 -0
  46. package/dist/esm/core/getLocalEditorParentOrigin.mjs.map +1 -0
  47. package/dist/esm/core/globalManager.mjs +1 -2
  48. package/dist/esm/core/index.mjs +4 -4
  49. package/dist/esm/core/initEditorClient.mjs +6 -4
  50. package/dist/esm/core/initEditorClient.mjs.map +1 -1
  51. package/dist/esm/core/selectionClick.mjs +22 -0
  52. package/dist/esm/core/selectionClick.mjs.map +1 -0
  53. package/dist/esm/core/sharedWindowState.mjs +1 -2
  54. package/dist/esm/index.mjs +3 -3
  55. package/dist/esm/isEnabled.mjs +1 -2
  56. package/dist/esm/messageKey.mjs +5 -2
  57. package/dist/esm/messageKey.mjs.map +1 -1
  58. package/dist/types/compareUrls.d.ts +0 -2
  59. package/dist/types/compareUrls.d.ts.map +1 -1
  60. package/dist/types/components/ContentSelector.d.ts +10 -4
  61. package/dist/types/components/ContentSelector.d.ts.map +1 -1
  62. package/dist/types/components/ContentSelectorWrapper.d.ts +5 -2
  63. package/dist/types/components/ContentSelectorWrapper.d.ts.map +1 -1
  64. package/dist/types/components/isInteractiveClickTarget.d.ts +14 -0
  65. package/dist/types/components/isInteractiveClickTarget.d.ts.map +1 -0
  66. package/dist/types/core/CrossFrameMessenger.d.ts +1 -2
  67. package/dist/types/core/CrossFrameMessenger.d.ts.map +1 -1
  68. package/dist/types/core/CrossFrameStateManager.d.ts +0 -2
  69. package/dist/types/core/CrossFrameStateManager.d.ts.map +1 -1
  70. package/dist/types/core/EditorStateManager.d.ts +34 -3
  71. package/dist/types/core/EditorStateManager.d.ts.map +1 -1
  72. package/dist/types/core/IframeClickInterceptor.d.ts +8 -4
  73. package/dist/types/core/IframeClickInterceptor.d.ts.map +1 -1
  74. package/dist/types/core/UrlStateManager.d.ts +0 -2
  75. package/dist/types/core/UrlStateManager.d.ts.map +1 -1
  76. package/dist/types/core/getLocalEditorParentOrigin.d.ts +11 -0
  77. package/dist/types/core/getLocalEditorParentOrigin.d.ts.map +1 -0
  78. package/dist/types/core/globalManager.d.ts +0 -2
  79. package/dist/types/core/globalManager.d.ts.map +1 -1
  80. package/dist/types/core/index.d.ts +4 -4
  81. package/dist/types/core/initEditorClient.d.ts +0 -2
  82. package/dist/types/core/initEditorClient.d.ts.map +1 -1
  83. package/dist/types/core/selectionClick.d.ts +15 -0
  84. package/dist/types/core/selectionClick.d.ts.map +1 -0
  85. package/dist/types/core/sharedWindowState.d.ts +1 -2
  86. package/dist/types/core/sharedWindowState.d.ts.map +1 -1
  87. package/dist/types/index.d.ts +3 -2
  88. package/dist/types/isEnabled.d.ts +0 -2
  89. package/dist/types/isEnabled.d.ts.map +1 -1
  90. package/dist/types/messageKey.d.ts +5 -3
  91. package/dist/types/messageKey.d.ts.map +1 -1
  92. package/package.json +8 -8
@@ -1,6 +1,6 @@
1
1
  import { compareUrls } from "../compareUrls.mjs";
2
2
 
3
- //#region src/core/CrossFrameMessenger.ts
3
+ // src/core/CrossFrameMessenger.ts
4
4
  const randomUUID = () => Math.random().toString(36).slice(2);
5
5
  /**
6
6
  * CrossFrameMessenger manages all cross-frame postMessage communication.
@@ -83,6 +83,5 @@ var CrossFrameMessenger = class {
83
83
  }
84
84
  };
85
85
 
86
- //#endregion
87
86
  export { CrossFrameMessenger };
88
87
  //# sourceMappingURL=CrossFrameMessenger.mjs.map
@@ -1,4 +1,4 @@
1
- //#region src/core/CrossFrameStateManager.ts
1
+ // src/core/CrossFrameStateManager.ts
2
2
  /**
3
3
  * CrossFrameStateManager synchronizes a single named value across frames using
4
4
  * the postMessage API via CrossFrameMessenger.
@@ -77,6 +77,5 @@ var CrossFrameStateManager = class extends EventTarget {
77
77
  }
78
78
  };
79
79
 
80
- //#endregion
81
80
  export { CrossFrameStateManager };
82
81
  //# sourceMappingURL=CrossFrameStateManager.mjs.map
@@ -7,7 +7,16 @@ import { UrlStateManager } from "./UrlStateManager.mjs";
7
7
  import * as NodeTypes from "@intlayer/types/nodeType";
8
8
  import { editDictionaryByKeyPath, getContentNodeByKeyPath, renameContentNodeByKeyPath } from "@intlayer/core/dictionaryManipulator";
9
9
 
10
- //#region src/core/EditorStateManager.ts
10
+ // src/core/EditorStateManager.ts
11
+ /** Delay between two editor pings checking the client still answers. */
12
+ const CLIENT_HEARTBEAT_INTERVAL_MS = 3e3;
13
+ /**
14
+ * Silence after which the client counts as disconnected (e.g. its dev server
15
+ * restarted). Pings go on, so it is activated again as soon as it answers.
16
+ */
17
+ const CLIENT_HEARTBEAT_TIMEOUT_MS = 1e4;
18
+ /** Clients older than the heartbeat announce themselves without payload. */
19
+ const isClientReadyPayload = (data) => typeof data === "object" && data !== null && typeof data.isActivated === "boolean";
11
20
  const sharedEditedContent = createSharedWindowState("edited_content");
12
21
  const sharedFocusedContent = createSharedWindowState("focused_content");
13
22
  /**
@@ -34,9 +43,12 @@ var EditorStateManager = class {
34
43
  _unsubAreYouThere = null;
35
44
  _unsubActivate = null;
36
45
  _unsubClientReady = null;
46
+ _clientHeartbeatTimer = null;
47
+ _lastClientReadyAt = 0;
37
48
  _displayedKeysObserver = null;
38
49
  _displayedKeysTimer = null;
39
50
  _displayedKeysListeners = [];
51
+ _unsubDisplayedKeysGet = null;
40
52
  _stopSharedStateSyncs = [];
41
53
  constructor(config) {
42
54
  this._mode = config.mode;
@@ -66,7 +78,7 @@ var EditorStateManager = class {
66
78
  this.displayedDictionaryKeys = new CrossFrameStateManager("INTLAYER_DISPLAYED_DICTIONARY_KEYS", this.messenger, {
67
79
  emit: config.mode === "client",
68
80
  receive: config.mode === "editor",
69
- initialValue: []
81
+ initialValue: config.mode === "client" ? [] : void 0
70
82
  });
71
83
  this._urlManager = new UrlStateManager(this.messenger);
72
84
  this._iframeInterceptor = new IframeClickInterceptor(this.messenger);
@@ -100,6 +112,7 @@ var EditorStateManager = class {
100
112
  this._unsubAreYouThere = null;
101
113
  this._unsubActivate = null;
102
114
  this._unsubClientReady = null;
115
+ this._stopClientHeartbeat();
103
116
  this.messenger.stop();
104
117
  this.editorEnabled.stop();
105
118
  this.focusedContent.stop();
@@ -124,13 +137,28 @@ var EditorStateManager = class {
124
137
  this.messenger.send("INTLAYER_ARE_YOU_THERE");
125
138
  this.messenger.send(`${"INTLAYER_EDITOR_ENABLED"}/post`, true);
126
139
  }
140
+ /**
141
+ * EDITOR mode: asks the client to switch locale. Covers applications whose
142
+ * locale is held in memory or storage only (no locale segment in the URL).
143
+ */
144
+ requestLocaleChange(locale) {
145
+ if (this._mode !== "editor") return;
146
+ this.messenger.send("INTLAYER_LOCALE_CHANGE_REQUESTED", locale);
147
+ }
148
+ /**
149
+ * CLIENT mode: subscribes to the locale changes requested by the editor.
150
+ * Returns an unsubscribe function.
151
+ */
152
+ onLocaleChangeRequested(handler) {
153
+ if (this._mode !== "client") return () => {};
154
+ return this.messenger.subscribe("INTLAYER_LOCALE_CHANGE_REQUESTED", handler);
155
+ }
127
156
  setFocusedContentKeyPath(keyPath) {
128
- const filtered = keyPath.filter((key) => key.type !== NodeTypes.TRANSLATION);
129
157
  const prev = this.focusedContent.value;
130
158
  if (!prev) return;
131
159
  this.focusedContent.set({
132
160
  ...prev,
133
- keyPath: filtered
161
+ keyPath
134
162
  });
135
163
  }
136
164
  setLocaleDictionary(dictionary) {
@@ -286,6 +314,9 @@ var EditorStateManager = class {
286
314
  window.addEventListener(evt, listener);
287
315
  this._displayedKeysListeners.push([evt, listener]);
288
316
  }
317
+ this._unsubDisplayedKeysGet = this.messenger.subscribe(`${"INTLAYER_DISPLAYED_DICTIONARY_KEYS"}/get`, () => {
318
+ this._scanDisplayedDictionaryKeys();
319
+ });
289
320
  this._scanDisplayedDictionaryKeys();
290
321
  }
291
322
  _stopDisplayedDictionariesTracking() {
@@ -297,25 +328,52 @@ var EditorStateManager = class {
297
328
  }
298
329
  for (const [evt, listener] of this._displayedKeysListeners) window.removeEventListener(evt, listener);
299
330
  this._displayedKeysListeners = [];
331
+ this._unsubDisplayedKeysGet?.();
332
+ this._unsubDisplayedKeysGet = null;
300
333
  }
301
334
  /**
302
335
  * EDITOR mode: listen for CLIENT_READY and respond with EDITOR_ACTIVATE.
303
336
  * Also pings the client immediately in case it loaded before the editor.
304
337
  */
305
338
  _setupEditorHandshake() {
306
- this._unsubClientReady = this.messenger.subscribe("INTLAYER_CLIENT_READY", () => {
339
+ this._unsubClientReady = this.messenger.subscribe("INTLAYER_CLIENT_READY", (data) => {
340
+ if (!isClientReadyPayload(data)) {
341
+ this.editorEnabled.set(true);
342
+ this.messenger.send("INTLAYER_EDITOR_ACTIVATE");
343
+ return;
344
+ }
345
+ const isConnected = data.isActivated && this.editorEnabled.value;
346
+ this._lastClientReadyAt = Date.now();
347
+ this._startClientHeartbeat();
307
348
  this.editorEnabled.set(true);
308
- this.messenger.send("INTLAYER_EDITOR_ACTIVATE");
349
+ if (!isConnected) this.messenger.send("INTLAYER_EDITOR_ACTIVATE");
309
350
  });
310
351
  this.messenger.send("INTLAYER_ARE_YOU_THERE");
311
352
  }
353
+ /**
354
+ * EDITOR mode: keeps pinging the client. A client that stopped answering
355
+ * (dev server restart, reloaded frame, re-evaluated client module) is marked
356
+ * disconnected, then activated again on its next answer.
357
+ */
358
+ _startClientHeartbeat() {
359
+ if (this._clientHeartbeatTimer) return;
360
+ this._clientHeartbeatTimer = setInterval(() => {
361
+ const isClientSilent = Date.now() - this._lastClientReadyAt > CLIENT_HEARTBEAT_TIMEOUT_MS;
362
+ if (this.editorEnabled.value && isClientSilent) this.editorEnabled.set(false);
363
+ this.messenger.send("INTLAYER_ARE_YOU_THERE");
364
+ }, CLIENT_HEARTBEAT_INTERVAL_MS);
365
+ }
366
+ _stopClientHeartbeat() {
367
+ if (this._clientHeartbeatTimer) clearInterval(this._clientHeartbeatTimer);
368
+ this._clientHeartbeatTimer = null;
369
+ }
312
370
  _setupActivationHandshake() {
313
- this.messenger.send("INTLAYER_CLIENT_READY");
314
- this._unsubAreYouThere = this.messenger.subscribe("INTLAYER_ARE_YOU_THERE", () => {
315
- this.messenger.send("INTLAYER_CLIENT_READY");
316
- });
371
+ const announceReady = () => this.messenger.send("INTLAYER_CLIENT_READY", { isActivated: this.editorEnabled.value === true });
372
+ announceReady();
373
+ this._unsubAreYouThere = this.messenger.subscribe("INTLAYER_ARE_YOU_THERE", announceReady);
317
374
  this._unsubActivate = this.messenger.subscribe("INTLAYER_EDITOR_ACTIVATE", () => {
318
375
  this.editorEnabled.set(true);
376
+ this._scanDisplayedDictionaryKeys();
319
377
  this._broadcastData();
320
378
  });
321
379
  }
@@ -326,6 +384,8 @@ var EditorStateManager = class {
326
384
  if (localeVal) this.messenger.send(`${"INTLAYER_CURRENT_LOCALE"}/post`, localeVal);
327
385
  const dicts = this.localeDictionaries.value;
328
386
  if (dicts) this.messenger.send(`${"INTLAYER_LOCALE_DICTIONARIES_CHANGED"}/post`, dicts);
387
+ const displayedKeys = this.displayedDictionaryKeys.value;
388
+ if (displayedKeys) this.messenger.send(`${"INTLAYER_DISPLAYED_DICTIONARY_KEYS"}/post`, displayedKeys);
329
389
  }
330
390
  async _loadDictionaries() {
331
391
  try {
@@ -339,6 +399,5 @@ var EditorStateManager = class {
339
399
  }
340
400
  };
341
401
 
342
- //#endregion
343
- export { EditorStateManager };
402
+ export { CLIENT_HEARTBEAT_INTERVAL_MS, CLIENT_HEARTBEAT_TIMEOUT_MS, EditorStateManager };
344
403
  //# sourceMappingURL=EditorStateManager.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"EditorStateManager.mjs","names":[],"sources":["../../../src/core/EditorStateManager.ts"],"sourcesContent":["import {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { MessageKey } from '../messageKey';\nimport {\n CrossFrameMessenger,\n type MessengerConfig,\n} from './CrossFrameMessenger';\nimport { CrossFrameStateManager } from './CrossFrameStateManager';\nimport { IframeClickInterceptor } from './IframeClickInterceptor';\nimport {\n createSharedWindowState,\n type SharedWindowState,\n} from './sharedWindowState';\nimport { UrlStateManager } from './UrlStateManager';\n\nexport type DictionaryContent = Record<LocalDictionaryId, Dictionary>;\n\ntype EditorConfig = Pick<IntlayerConfig, 'editor'>;\n\nconst sharedEditedContent =\n createSharedWindowState<DictionaryContent>('edited_content');\nconst sharedFocusedContent = createSharedWindowState<FileContent | null>(\n 'focused_content'\n);\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?: EditorConfig;\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<EditorConfig>;\n readonly currentLocale: CrossFrameStateManager<Locale | undefined>;\n readonly displayedDictionaryKeys: CrossFrameStateManager<string[]>;\n\n private readonly _urlManager: UrlStateManager;\n private readonly _iframeInterceptor: IframeClickInterceptor;\n private readonly _mode: 'editor' | 'client';\n private readonly _configuration: EditorConfig | undefined;\n\n // Client-mode handshake subscribers\n private _unsubAreYouThere: (() => void) | null = null;\n private _unsubActivate: (() => void) | null = null;\n // Editor-mode handshake subscriber\n private _unsubClientReady: (() => void) | null = null;\n\n // Client-mode displayed-keys tracking\n private _displayedKeysObserver: MutationObserver | null = null;\n private _displayedKeysTimer: ReturnType<typeof setTimeout> | null = null;\n private _displayedKeysListeners: Array<[string, EventListener]> = [];\n\n // Sync with the other managers of this window\n private _stopSharedStateSyncs: Array<() => void> = [];\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<EditorConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n this.messenger,\n {\n emit: true,\n receive: false,\n ...(config.configuration ? { initialValue: config.configuration } : {}),\n }\n );\n\n // Client emits its locale to the editor; editor receives it.\n this.currentLocale = new CrossFrameStateManager<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n this.messenger,\n {\n emit: config.mode === 'client',\n receive: config.mode === 'editor',\n }\n );\n\n // Client emits displayed dictionary keys; editor receives them.\n this.displayedDictionaryKeys = new CrossFrameStateManager<string[]>(\n MessageKey.INTLAYER_DISPLAYED_DICTIONARY_KEYS,\n this.messenger,\n {\n emit: config.mode === 'client',\n receive: config.mode === 'editor',\n initialValue: [],\n }\n );\n\n this._urlManager = new UrlStateManager(this.messenger);\n this._iframeInterceptor = new IframeClickInterceptor(this.messenger);\n }\n\n start(): void {\n this.messenger.start();\n this.editorEnabled.start();\n this.focusedContent.start();\n this.localeDictionaries.start();\n this.editedContent.start();\n this.configuration.start();\n this.currentLocale.start();\n this.displayedDictionaryKeys.start();\n this._stopSharedStateSyncs = [\n this._syncWithSharedState(\n this.editedContent,\n sharedEditedContent,\n // An empty record carries no edit worth broadcasting to the client\n (content) => Object.keys(content).length > 0\n ),\n this._syncWithSharedState(this.focusedContent, sharedFocusedContent),\n ];\n\n if (this._mode === 'client') {\n this._urlManager.start();\n this._iframeInterceptor.startInterceptor();\n this._loadDictionaries();\n this._startDisplayedDictionariesTracking();\n // Request current edited content from the editor\n this.messenger.send(`${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`);\n // Activation handshake: only participate if editor.enabled !== false\n if (this._configuration?.editor?.enabled !== false) {\n this._setupActivationHandshake();\n }\n } else {\n this._iframeInterceptor.startMerger();\n this._setupEditorHandshake();\n }\n }\n\n stop(): void {\n this._unsubAreYouThere?.();\n this._unsubActivate?.();\n this._unsubClientReady?.();\n this._unsubAreYouThere = null;\n this._unsubActivate = null;\n this._unsubClientReady = null;\n this.messenger.stop();\n this.editorEnabled.stop();\n this.focusedContent.stop();\n this.localeDictionaries.stop();\n this.editedContent.stop();\n this.configuration.stop();\n this.currentLocale.stop();\n this.displayedDictionaryKeys.stop();\n this._stopDisplayedDictionariesTracking();\n for (const stopSync of this._stopSharedStateSyncs) stopSync();\n this._stopSharedStateSyncs = [];\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 // Clients older than v8.9.4 have no handshake and wait for this instead\n this.messenger.send(`${MessageKey.INTLAYER_EDITOR_ENABLED}/post`, true);\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 { [localDictionaryId]: _restored, ...remainingContent } =\n this.editedContent.value ?? {};\n\n this.editedContent.set(remainingContent);\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 // ─── Shared window state sync ───────────────────────────────────────────\n\n /**\n * Mirrors a state with the managers of the same window, seeding it with the\n * shared value when there is one. Returns a function stopping the sync.\n */\n private _syncWithSharedState<T>(\n state: CrossFrameStateManager<T>,\n sharedState: SharedWindowState<T>,\n shouldSeed: (sharedValue: T) => boolean = () => true\n ): () => void {\n // Guards against echoing back a value received from the shared state\n let isApplyingSharedValue = false;\n\n const applySharedValue = (value: T) => {\n isApplyingSharedValue = true;\n state.set(value);\n isApplyingSharedValue = false;\n };\n\n const publishLocalChange = (event: Event) => {\n if (isApplyingSharedValue) return;\n sharedState.set(\n (event as CustomEvent<T>).detail,\n this.messenger.senderId\n );\n };\n\n state.addEventListener('change', publishLocalChange);\n\n const unsubscribeShared = sharedState.subscribe((value, sourceId) => {\n if (sourceId !== this.messenger.senderId) applySharedValue(value);\n });\n\n const sharedValue = sharedState.get();\n if (sharedValue !== undefined && shouldSeed(sharedValue)) {\n applySharedValue(sharedValue);\n }\n\n return () => {\n state.removeEventListener('change', publishLocalChange);\n unsubscribeShared();\n };\n }\n\n // ─── Displayed dictionaries tracking (client mode only) ──────────────────\n\n private _scanDisplayedDictionaryKeys(): void {\n if (typeof document === 'undefined') return;\n const elements = document.querySelectorAll(\n 'intlayer-content-selector-wrapper[dictionary-key]'\n );\n const keys = Array.from(\n new Set(\n Array.from(elements)\n .map((el) => el.getAttribute('dictionary-key') ?? '')\n .filter(Boolean)\n )\n );\n this.displayedDictionaryKeys.set(keys);\n }\n\n private _startDisplayedDictionariesTracking(): void {\n if (\n typeof document === 'undefined' ||\n typeof MutationObserver === 'undefined'\n )\n return;\n\n const schedule = () => {\n if (this._displayedKeysTimer) clearTimeout(this._displayedKeysTimer);\n this._displayedKeysTimer = setTimeout(\n () => this._scanDisplayedDictionaryKeys(),\n 100\n );\n };\n\n this._displayedKeysObserver = new MutationObserver(schedule);\n this._displayedKeysObserver.observe(document.body, {\n childList: true,\n subtree: true,\n });\n\n for (const evt of ['locationchange', 'popstate'] as const) {\n const listener = schedule as EventListener;\n window.addEventListener(evt, listener);\n this._displayedKeysListeners.push([evt, listener]);\n }\n\n this._scanDisplayedDictionaryKeys();\n }\n\n private _stopDisplayedDictionariesTracking(): void {\n this._displayedKeysObserver?.disconnect();\n this._displayedKeysObserver = null;\n if (this._displayedKeysTimer) {\n clearTimeout(this._displayedKeysTimer);\n this._displayedKeysTimer = null;\n }\n for (const [evt, listener] of this._displayedKeysListeners) {\n window.removeEventListener(evt, listener);\n }\n this._displayedKeysListeners = [];\n }\n\n // ─── Handshake helpers ───────────────────────────────────────────────────────\n\n /**\n * EDITOR mode: listen for CLIENT_READY and respond with EDITOR_ACTIVATE.\n * Also pings the client immediately in case it loaded before the editor.\n */\n private _setupEditorHandshake(): void {\n // When the client announces it is ready, activate it\n this._unsubClientReady = this.messenger.subscribe(\n MessageKey.INTLAYER_CLIENT_READY,\n () => {\n this.editorEnabled.set(true);\n this.messenger.send(MessageKey.INTLAYER_EDITOR_ACTIVATE);\n }\n );\n\n // Ping any already-running client (covers editor-opens-after-client scenario)\n this.messenger.send(MessageKey.INTLAYER_ARE_YOU_THERE);\n }\n\n private _setupActivationHandshake(): void {\n // Announce to the editor that the client is ready\n this.messenger.send(MessageKey.INTLAYER_CLIENT_READY);\n\n // Respond to \"are you there?\" pings from the editor\n this._unsubAreYouThere = this.messenger.subscribe(\n MessageKey.INTLAYER_ARE_YOU_THERE,\n () => {\n this.messenger.send(MessageKey.INTLAYER_CLIENT_READY);\n }\n );\n\n // When the editor activates us, enable the selector and broadcast state\n this._unsubActivate = this.messenger.subscribe(\n MessageKey.INTLAYER_EDITOR_ACTIVATE,\n () => {\n this.editorEnabled.set(true);\n this._broadcastData();\n }\n );\n }\n\n private _broadcastData(): void {\n const configVal = this.configuration.value;\n\n if (configVal) {\n this.messenger.send(\n `${MessageKey.INTLAYER_CONFIGURATION}/post`,\n configVal\n );\n }\n const localeVal = this.currentLocale.value;\n\n if (localeVal) {\n this.messenger.send(\n `${MessageKey.INTLAYER_CURRENT_LOCALE}/post`,\n localeVal\n );\n }\n const dicts = this.localeDictionaries.value;\n\n if (dicts) {\n this.messenger.send(\n `${MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED}/post`,\n dicts\n );\n }\n }\n\n private async _loadDictionaries(): Promise<void> {\n try {\n const mod = await import('@intlayer/dictionaries-entry/unmerged');\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":";;;;;;;;;;AA+BA,MAAM,sBACJ,wBAA2C,gBAAgB;AAC7D,MAAM,uBAAuB,wBAC3B,iBACF;;;;;;;;;AAyBA,IAAa,qBAAb,MAAgC;CAC9B,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAGjB,AAAQ,oBAAyC;CACjD,AAAQ,iBAAsC;CAE9C,AAAQ,oBAAyC;CAGjD,AAAQ,yBAAkD;CAC1D,AAAQ,sBAA4D;CACpE,AAAQ,0BAA0D,CAAC;CAGnE,AAAQ,wBAA2C,CAAC;CAEpD,YAAY,QAAkC;EAC5C,KAAK,QAAQ,OAAO;EACpB,KAAK,iBAAiB,OAAO;EAE7B,KAAK,YAAY,IAAI,oBAAoB,OAAO,SAAS;EAEzD,KAAK,gBAAgB,IAAI,kDAEvB,KAAK,WACL;GAAE,MAAM;GAAO,SAAS;GAAM,cAAc;EAAM,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,mBAAmB,OAAO,YAC9B,OAAO,OAAO,oBAAoB,CAAC,CAChC,KAAK,CAAC,CACN,KAAK,eAAe,CAAC,WAAW,SAAS,UAAU,CAAC,CACzD;GAEA,KAAK,mBAAmB,IAAI,gBAAgB;GAI5C,IAAI,KAAK,cAAc,OACrB,KAAK,eAAe;EAExB,SAAS,GAAG;GAEV,QAAQ,KAAK,oDAAoD,CAAC;EACpE;CACF;AACF"}
1
+ {"version":3,"file":"EditorStateManager.mjs","names":[],"sources":["../../../src/core/EditorStateManager.ts"],"sourcesContent":["import {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { MessageKey } from '../messageKey';\nimport {\n CrossFrameMessenger,\n type MessengerConfig,\n} from './CrossFrameMessenger';\nimport { CrossFrameStateManager } from './CrossFrameStateManager';\nimport { IframeClickInterceptor } from './IframeClickInterceptor';\nimport {\n createSharedWindowState,\n type SharedWindowState,\n} from './sharedWindowState';\nimport { UrlStateManager } from './UrlStateManager';\n\nexport type DictionaryContent = Record<LocalDictionaryId, Dictionary>;\n\n/** Delay between two editor pings checking the client still answers. */\nexport const CLIENT_HEARTBEAT_INTERVAL_MS = 3_000;\n\n/**\n * Silence after which the client counts as disconnected (e.g. its dev server\n * restarted). Pings go on, so it is activated again as soon as it answers.\n */\nexport const CLIENT_HEARTBEAT_TIMEOUT_MS = 10_000;\n\n/** Sent by the client with `INTLAYER_CLIENT_READY`. */\nexport type ClientReadyPayload = {\n /** Whether the editor already activated this client. */\n isActivated: boolean;\n};\n\n/** Clients older than the heartbeat announce themselves without payload. */\nconst isClientReadyPayload = (data: unknown): data is ClientReadyPayload =>\n typeof data === 'object' &&\n data !== null &&\n typeof (data as ClientReadyPayload).isActivated === 'boolean';\n\ntype EditorConfig = Pick<IntlayerConfig, 'editor'>;\n\nconst sharedEditedContent =\n createSharedWindowState<DictionaryContent>('edited_content');\nconst sharedFocusedContent = createSharedWindowState<FileContent | null>(\n 'focused_content'\n);\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?: EditorConfig;\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<EditorConfig>;\n readonly currentLocale: CrossFrameStateManager<Locale | undefined>;\n readonly displayedDictionaryKeys: CrossFrameStateManager<string[]>;\n\n private readonly _urlManager: UrlStateManager;\n private readonly _iframeInterceptor: IframeClickInterceptor;\n private readonly _mode: 'editor' | 'client';\n private readonly _configuration: EditorConfig | 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 private _clientHeartbeatTimer: ReturnType<typeof setInterval> | null = null;\n private _lastClientReadyAt = 0;\n\n // Client-mode displayed-keys tracking\n private _displayedKeysObserver: MutationObserver | null = null;\n private _displayedKeysTimer: ReturnType<typeof setTimeout> | null = null;\n private _displayedKeysListeners: Array<[string, EventListener]> = [];\n private _unsubDisplayedKeysGet: (() => void) | null = null;\n\n // Sync with the other managers of this window\n private _stopSharedStateSyncs: Array<() => void> = [];\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<EditorConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n this.messenger,\n {\n emit: true,\n receive: false,\n ...(config.configuration ? { initialValue: config.configuration } : {}),\n }\n );\n\n // Client emits its locale to the editor; editor receives it.\n this.currentLocale = new CrossFrameStateManager<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n this.messenger,\n {\n emit: config.mode === 'client',\n receive: config.mode === 'editor',\n }\n );\n\n // Client emits displayed dictionary keys; editor receives them.\n this.displayedDictionaryKeys = new CrossFrameStateManager<string[]>(\n MessageKey.INTLAYER_DISPLAYED_DICTIONARY_KEYS,\n this.messenger,\n {\n emit: config.mode === 'client',\n receive: config.mode === 'editor',\n initialValue: config.mode === 'client' ? [] : undefined,\n }\n );\n\n this._urlManager = new UrlStateManager(this.messenger);\n this._iframeInterceptor = new IframeClickInterceptor(this.messenger);\n }\n\n start(): void {\n this.messenger.start();\n this.editorEnabled.start();\n this.focusedContent.start();\n this.localeDictionaries.start();\n this.editedContent.start();\n this.configuration.start();\n this.currentLocale.start();\n this.displayedDictionaryKeys.start();\n this._stopSharedStateSyncs = [\n this._syncWithSharedState(\n this.editedContent,\n sharedEditedContent,\n // An empty record carries no edit worth broadcasting to the client\n (content) => Object.keys(content).length > 0\n ),\n this._syncWithSharedState(this.focusedContent, sharedFocusedContent),\n ];\n\n if (this._mode === 'client') {\n this._urlManager.start();\n this._iframeInterceptor.startInterceptor();\n this._loadDictionaries();\n this._startDisplayedDictionariesTracking();\n // Request current edited content from the editor\n this.messenger.send(`${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`);\n // Activation handshake: only participate if editor.enabled !== false\n if (this._configuration?.editor?.enabled !== false) {\n this._setupActivationHandshake();\n }\n } else {\n this._iframeInterceptor.startMerger();\n this._setupEditorHandshake();\n }\n }\n\n stop(): void {\n this._unsubAreYouThere?.();\n this._unsubActivate?.();\n this._unsubClientReady?.();\n this._unsubAreYouThere = null;\n this._unsubActivate = null;\n this._unsubClientReady = null;\n this._stopClientHeartbeat();\n this.messenger.stop();\n this.editorEnabled.stop();\n this.focusedContent.stop();\n this.localeDictionaries.stop();\n this.editedContent.stop();\n this.configuration.stop();\n this.currentLocale.stop();\n this.displayedDictionaryKeys.stop();\n this._stopDisplayedDictionariesTracking();\n for (const stopSync of this._stopSharedStateSyncs) stopSync();\n this._stopSharedStateSyncs = [];\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 // Clients older than v8.9.4 have no handshake and wait for this instead\n this.messenger.send(`${MessageKey.INTLAYER_EDITOR_ENABLED}/post`, true);\n }\n\n // ─── Locale helpers ─────────────────────────────────────────────────────────\n\n /**\n * EDITOR mode: asks the client to switch locale. Covers applications whose\n * locale is held in memory or storage only (no locale segment in the URL).\n */\n requestLocaleChange(locale: Locale): void {\n if (this._mode !== 'editor') return;\n\n this.messenger.send(MessageKey.INTLAYER_LOCALE_CHANGE_REQUESTED, locale);\n }\n\n /**\n * CLIENT mode: subscribes to the locale changes requested by the editor.\n * Returns an unsubscribe function.\n */\n onLocaleChangeRequested(handler: (locale: Locale) => void): () => void {\n if (this._mode !== 'client') return () => {};\n\n return this.messenger.subscribe<Locale>(\n MessageKey.INTLAYER_LOCALE_CHANGE_REQUESTED,\n handler\n );\n }\n\n // ─── Focus helpers ──────────────────────────────────────────────────────────\n\n setFocusedContentKeyPath(keyPath: KeyPath[]): void {\n const prev = this.focusedContent.value;\n\n if (!prev) return;\n\n this.focusedContent.set({ ...prev, keyPath });\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 { [localDictionaryId]: _restored, ...remainingContent } =\n this.editedContent.value ?? {};\n\n this.editedContent.set(remainingContent);\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 // ─── Shared window state sync ───────────────────────────────────────────\n\n /**\n * Mirrors a state with the managers of the same window, seeding it with the\n * shared value when there is one. Returns a function stopping the sync.\n */\n private _syncWithSharedState<T>(\n state: CrossFrameStateManager<T>,\n sharedState: SharedWindowState<T>,\n shouldSeed: (sharedValue: T) => boolean = () => true\n ): () => void {\n // Guards against echoing back a value received from the shared state\n let isApplyingSharedValue = false;\n\n const applySharedValue = (value: T) => {\n isApplyingSharedValue = true;\n state.set(value);\n isApplyingSharedValue = false;\n };\n\n const publishLocalChange = (event: Event) => {\n if (isApplyingSharedValue) return;\n sharedState.set(\n (event as CustomEvent<T>).detail,\n this.messenger.senderId\n );\n };\n\n state.addEventListener('change', publishLocalChange);\n\n const unsubscribeShared = sharedState.subscribe((value, sourceId) => {\n if (sourceId !== this.messenger.senderId) applySharedValue(value);\n });\n\n const sharedValue = sharedState.get();\n if (sharedValue !== undefined && shouldSeed(sharedValue)) {\n applySharedValue(sharedValue);\n }\n\n return () => {\n state.removeEventListener('change', publishLocalChange);\n unsubscribeShared();\n };\n }\n\n // ─── Displayed dictionaries tracking (client mode only) ──────────────────\n\n private _scanDisplayedDictionaryKeys(): void {\n if (typeof document === 'undefined') return;\n const elements = document.querySelectorAll(\n 'intlayer-content-selector-wrapper[dictionary-key]'\n );\n const keys = Array.from(\n new Set(\n Array.from(elements)\n .map((el) => el.getAttribute('dictionary-key') ?? '')\n .filter(Boolean)\n )\n );\n this.displayedDictionaryKeys.set(keys);\n }\n\n private _startDisplayedDictionariesTracking(): void {\n if (\n typeof document === 'undefined' ||\n typeof MutationObserver === 'undefined'\n )\n return;\n\n const schedule = () => {\n if (this._displayedKeysTimer) clearTimeout(this._displayedKeysTimer);\n this._displayedKeysTimer = setTimeout(\n () => this._scanDisplayedDictionaryKeys(),\n 100\n );\n };\n\n this._displayedKeysObserver = new MutationObserver(schedule);\n this._displayedKeysObserver.observe(document.body, {\n childList: true,\n subtree: true,\n });\n\n for (const evt of ['locationchange', 'popstate'] as const) {\n const listener = schedule as EventListener;\n window.addEventListener(evt, listener);\n this._displayedKeysListeners.push([evt, listener]);\n }\n\n this._unsubDisplayedKeysGet = this.messenger.subscribe(\n `${MessageKey.INTLAYER_DISPLAYED_DICTIONARY_KEYS}/get`,\n () => {\n this._scanDisplayedDictionaryKeys();\n }\n );\n\n this._scanDisplayedDictionaryKeys();\n }\n\n private _stopDisplayedDictionariesTracking(): void {\n this._displayedKeysObserver?.disconnect();\n this._displayedKeysObserver = null;\n if (this._displayedKeysTimer) {\n clearTimeout(this._displayedKeysTimer);\n this._displayedKeysTimer = null;\n }\n for (const [evt, listener] of this._displayedKeysListeners) {\n window.removeEventListener(evt, listener);\n }\n this._displayedKeysListeners = [];\n this._unsubDisplayedKeysGet?.();\n this._unsubDisplayedKeysGet = null;\n }\n\n // ─── Handshake helpers ───────────────────────────────────────────────────────\n\n /**\n * EDITOR mode: listen for CLIENT_READY and respond with EDITOR_ACTIVATE.\n * Also pings the client immediately in case it loaded before the editor.\n */\n private _setupEditorHandshake(): void {\n // When the client announces it is ready, activate it\n this._unsubClientReady = this.messenger.subscribe(\n MessageKey.INTLAYER_CLIENT_READY,\n (data) => {\n if (!isClientReadyPayload(data)) {\n // Legacy client: activated on every answer, so no heartbeat\n this.editorEnabled.set(true);\n this.messenger.send(MessageKey.INTLAYER_EDITOR_ACTIVATE);\n return;\n }\n\n // A client answering a ping of this editor needs no new broadcast; a\n // re-created editor (e.g. reloaded module) needs the client data again\n const isConnected = data.isActivated && this.editorEnabled.value;\n\n this._lastClientReadyAt = Date.now();\n this._startClientHeartbeat();\n this.editorEnabled.set(true);\n\n if (!isConnected) {\n this.messenger.send(MessageKey.INTLAYER_EDITOR_ACTIVATE);\n }\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 /**\n * EDITOR mode: keeps pinging the client. A client that stopped answering\n * (dev server restart, reloaded frame, re-evaluated client module) is marked\n * disconnected, then activated again on its next answer.\n */\n private _startClientHeartbeat(): void {\n if (this._clientHeartbeatTimer) return;\n\n this._clientHeartbeatTimer = setInterval(() => {\n const isClientSilent =\n Date.now() - this._lastClientReadyAt > CLIENT_HEARTBEAT_TIMEOUT_MS;\n\n if (this.editorEnabled.value && isClientSilent) {\n this.editorEnabled.set(false);\n }\n\n this.messenger.send(MessageKey.INTLAYER_ARE_YOU_THERE);\n }, CLIENT_HEARTBEAT_INTERVAL_MS);\n }\n\n private _stopClientHeartbeat(): void {\n if (this._clientHeartbeatTimer) clearInterval(this._clientHeartbeatTimer);\n this._clientHeartbeatTimer = null;\n }\n\n private _setupActivationHandshake(): void {\n const announceReady = () =>\n this.messenger.send(MessageKey.INTLAYER_CLIENT_READY, {\n isActivated: this.editorEnabled.value === true,\n } satisfies ClientReadyPayload);\n\n // Announce to the editor that the client is ready\n announceReady();\n\n // Respond to \"are you there?\" pings from the editor\n this._unsubAreYouThere = this.messenger.subscribe(\n MessageKey.INTLAYER_ARE_YOU_THERE,\n announceReady\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._scanDisplayedDictionaryKeys();\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 const displayedKeys = this.displayedDictionaryKeys.value;\n\n if (displayedKeys) {\n this.messenger.send(\n `${MessageKey.INTLAYER_DISPLAYED_DICTIONARY_KEYS}/post`,\n displayedKeys\n );\n }\n }\n\n private async _loadDictionaries(): Promise<void> {\n try {\n const mod = await import('@intlayer/dictionaries-entry/unmerged');\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":";;;;;;;;;;;AA8BA,MAAa,+BAA+B;;;;;AAM5C,MAAa,8BAA8B;;AAS3C,MAAM,wBAAwB,SAC5B,OAAO,SAAS,YAChB,SAAS,QACT,OAAQ,KAA4B,gBAAgB;AAItD,MAAM,sBACJ,wBAA2C,gBAAgB;AAC7D,MAAM,uBAAuB,wBAC3B,iBACF;;;;;;;;;AAyBA,IAAa,qBAAb,MAAgC;CAC9B,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAGjB,AAAQ,oBAAyC;CACjD,AAAQ,iBAAsC;CAE9C,AAAQ,oBAAyC;CACjD,AAAQ,wBAA+D;CACvE,AAAQ,qBAAqB;CAG7B,AAAQ,yBAAkD;CAC1D,AAAQ,sBAA4D;CACpE,AAAQ,0BAA0D,CAAC;CACnE,AAAQ,yBAA8C;CAGtD,AAAQ,wBAA2C,CAAC;CAEpD,YAAY,QAAkC;EAC5C,KAAK,QAAQ,OAAO;EACpB,KAAK,iBAAiB,OAAO;EAE7B,KAAK,YAAY,IAAI,oBAAoB,OAAO,SAAS;EAEzD,KAAK,gBAAgB,IAAI,kDAEvB,KAAK,WACL;GAAE,MAAM;GAAO,SAAS;GAAM,cAAc;EAAM,CACpD;EAEA,KAAK,iBAAiB,IAAI,2DAExB,KAAK,WACL;GAAE,MAAM;GAAM,SAAS;GAAM,cAAc;EAAK,CAClD;EAEA,KAAK,qBAAqB,IAAI,+DAE5B,KAAK,SACP;EAEA,KAAK,gBAAgB,I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3
 
3
- //#region src/core/IframeClickInterceptor.ts
4
+ // src/core/IframeClickInterceptor.ts
4
5
  /**
5
6
  * Replays a click made inside the iframe on the editor window, so the editor's
6
7
  * "click outside" handlers (popovers, drawers) react to it.
@@ -15,30 +16,37 @@ const replayIframeClick = () => {
15
16
  /**
16
17
  * Forwards clicks across the iframe boundary.
17
18
  *
18
- * - startInterceptor(): client (iframe) side — reports each mousedown to the editor
19
+ * - startInterceptor(): client (iframe) side — reports each click to the editor
19
20
  * - startMerger(): editor (parent) side — replays reported clicks on its window
21
+ *
22
+ * Clicks are reported once released rather than on mousedown: a long press on
23
+ * content starts with a mousedown too, and reporting it closed the editor
24
+ * drawers right before the press focused content in them. A completed long
25
+ * press stops its own click (see `ContentSelector`), and a click selecting
26
+ * content is marked as such, so neither is reported.
20
27
  */
21
28
  var IframeClickInterceptor = class {
22
29
  _messenger;
23
- _mousedownHandler = null;
30
+ _clickHandler = null;
24
31
  _unsubscribeMerge = null;
25
32
  constructor(messenger) {
26
33
  this._messenger = messenger;
27
34
  }
28
35
  startInterceptor() {
29
36
  if (typeof window === "undefined") return;
30
- this._mousedownHandler = () => {
37
+ this._clickHandler = (event) => {
38
+ if (isSelectionClick(event)) return;
31
39
  this._messenger.send("INTLAYER_IFRAME_CLICKED");
32
40
  };
33
- window.addEventListener("mousedown", this._mousedownHandler);
41
+ window.addEventListener("click", this._clickHandler);
34
42
  }
35
43
  startMerger() {
36
44
  this._unsubscribeMerge = this._messenger.subscribe("INTLAYER_IFRAME_CLICKED", replayIframeClick);
37
45
  }
38
46
  stopInterceptor() {
39
- if (this._mousedownHandler) {
40
- window.removeEventListener("mousedown", this._mousedownHandler);
41
- this._mousedownHandler = null;
47
+ if (this._clickHandler) {
48
+ window.removeEventListener("click", this._clickHandler);
49
+ this._clickHandler = null;
42
50
  }
43
51
  }
44
52
  stopMerger() {
@@ -47,6 +55,5 @@ var IframeClickInterceptor = class {
47
55
  }
48
56
  };
49
57
 
50
- //#endregion
51
58
  export { IframeClickInterceptor };
52
59
  //# sourceMappingURL=IframeClickInterceptor.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"IframeClickInterceptor.mjs","names":[],"sources":["../../../src/core/IframeClickInterceptor.ts"],"sourcesContent":["import { MessageKey } from '../messageKey';\nimport type { CrossFrameMessenger } from './CrossFrameMessenger';\n\n/**\n * Replays a click made inside the iframe on the editor window, so the editor's\n * \"click outside\" handlers (popovers, drawers) react to it.\n */\nconst replayIframeClick = (): void => {\n for (const eventType of ['mousedown', 'click']) {\n window.dispatchEvent(\n new MouseEvent(eventType, {\n bubbles: true,\n cancelable: true,\n view: window,\n })\n );\n }\n};\n\n/**\n * Forwards clicks across the iframe boundary.\n *\n * - startInterceptor(): client (iframe) side — reports each mousedown to the editor\n * - startMerger(): editor (parent) side — replays reported clicks on its window\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 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 startMerger(): void {\n this._unsubscribeMerge = this._messenger.subscribe(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n replayIframeClick\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":";;;;;;;AAOA,MAAM,0BAAgC;CACpC,KAAK,MAAM,aAAa,CAAC,aAAa,OAAO,GAC3C,OAAO,cACL,IAAI,WAAW,WAAW;EACxB,SAAS;EACT,YAAY;EACZ,MAAM;CACR,CAAC,CACH;AAEJ;;;;;;;AAQA,IAAa,yBAAb,MAAoC;CAClC,AAAiB;CACjB,AAAQ,oBAA0C;CAClD,AAAQ,oBAAyC;CAEjD,YAAY,WAAgC;EAC1C,KAAK,aAAa;CACpB;CAEA,mBAAyB;EACvB,IAAI,OAAO,WAAW,aAAa;EACnC,KAAK,0BAA0B;GAC7B,KAAK,WAAW,8BAAuC;EACzD;EACA,OAAO,iBAAiB,aAAa,KAAK,iBAAiB;CAC7D;CAEA,cAAoB;EAClB,KAAK,oBAAoB,KAAK,WAAW,qCAEvC,iBACF;CACF;CAEA,kBAAwB;EACtB,IAAI,KAAK,mBAAmB;GAC1B,OAAO,oBAAoB,aAAa,KAAK,iBAAiB;GAC9D,KAAK,oBAAoB;EAC3B;CACF;CAEA,aAAmB;EACjB,KAAK,oBAAoB;EACzB,KAAK,oBAAoB;CAC3B;AACF"}
1
+ {"version":3,"file":"IframeClickInterceptor.mjs","names":[],"sources":["../../../src/core/IframeClickInterceptor.ts"],"sourcesContent":["import { MessageKey } from '../messageKey';\nimport type { CrossFrameMessenger } from './CrossFrameMessenger';\nimport { isSelectionClick } from './selectionClick';\n\n/**\n * Replays a click made inside the iframe on the editor window, so the editor's\n * \"click outside\" handlers (popovers, drawers) react to it.\n */\nconst replayIframeClick = (): void => {\n for (const eventType of ['mousedown', 'click']) {\n window.dispatchEvent(\n new MouseEvent(eventType, {\n bubbles: true,\n cancelable: true,\n view: window,\n })\n );\n }\n};\n\n/**\n * Forwards clicks across the iframe boundary.\n *\n * - startInterceptor(): client (iframe) side — reports each click to the editor\n * - startMerger(): editor (parent) side — replays reported clicks on its window\n *\n * Clicks are reported once released rather than on mousedown: a long press on\n * content starts with a mousedown too, and reporting it closed the editor\n * drawers right before the press focused content in them. A completed long\n * press stops its own click (see `ContentSelector`), and a click selecting\n * content is marked as such, so neither is reported.\n */\nexport class IframeClickInterceptor {\n private readonly _messenger: CrossFrameMessenger;\n private _clickHandler: EventListener | null = null;\n private _unsubscribeMerge: (() => void) | null = null;\n\n constructor(messenger: CrossFrameMessenger) {\n this._messenger = messenger;\n }\n\n startInterceptor(): void {\n if (typeof window === 'undefined') return;\n this._clickHandler = (event) => {\n if (isSelectionClick(event)) return;\n\n this._messenger.send(MessageKey.INTLAYER_IFRAME_CLICKED);\n };\n window.addEventListener('click', this._clickHandler);\n }\n\n startMerger(): void {\n this._unsubscribeMerge = this._messenger.subscribe(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n replayIframeClick\n );\n }\n\n stopInterceptor(): void {\n if (this._clickHandler) {\n window.removeEventListener('click', this._clickHandler);\n this._clickHandler = null;\n }\n }\n\n stopMerger(): void {\n this._unsubscribeMerge?.();\n this._unsubscribeMerge = null;\n }\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,0BAAgC;CACpC,KAAK,MAAM,aAAa,CAAC,aAAa,OAAO,GAC3C,OAAO,cACL,IAAI,WAAW,WAAW;EACxB,SAAS;EACT,YAAY;EACZ,MAAM;CACR,CAAC,CACH;AAEJ;;;;;;;;;;;;;AAcA,IAAa,yBAAb,MAAoC;CAClC,AAAiB;CACjB,AAAQ,gBAAsC;CAC9C,AAAQ,oBAAyC;CAEjD,YAAY,WAAgC;EAC1C,KAAK,aAAa;CACpB;CAEA,mBAAyB;EACvB,IAAI,OAAO,WAAW,aAAa;EACnC,KAAK,iBAAiB,UAAU;GAC9B,IAAI,iBAAiB,KAAK,GAAG;GAE7B,KAAK,WAAW,8BAAuC;EACzD;EACA,OAAO,iBAAiB,SAAS,KAAK,aAAa;CACrD;CAEA,cAAoB;EAClB,KAAK,oBAAoB,KAAK,WAAW,qCAEvC,iBACF;CACF;CAEA,kBAAwB;EACtB,IAAI,KAAK,eAAe;GACtB,OAAO,oBAAoB,SAAS,KAAK,aAAa;GACtD,KAAK,gBAAgB;EACvB;CACF;CAEA,aAAmB;EACjB,KAAK,oBAAoB;EACzB,KAAK,oBAAoB;CAC3B;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { MessageKey } from "../messageKey.mjs";
2
2
 
3
- //#region src/core/UrlStateManager.ts
3
+ // src/core/UrlStateManager.ts
4
4
  /**
5
5
  * UrlStateManager patches window.history and broadcasts URL path changes
6
6
  * across frames via postMessage.
@@ -55,6 +55,5 @@ var UrlStateManager = class {
55
55
  }
56
56
  };
57
57
 
58
- //#endregion
59
58
  export { UrlStateManager };
60
59
  //# sourceMappingURL=UrlStateManager.mjs.map
@@ -0,0 +1,31 @@
1
+ // src/core/getLocalEditorParentOrigin.ts
2
+ /** Hostnames of the local machine, as `URL.hostname` reports them. */
3
+ const LOOPBACK_HOSTNAMES = /* @__PURE__ */ new Set([
4
+ "localhost",
5
+ "127.0.0.1",
6
+ "[::1]"
7
+ ]);
8
+ const isLoopbackUrl = (url) => {
9
+ try {
10
+ return LOOPBACK_HOSTNAMES.has(new URL(url).hostname);
11
+ } catch {
12
+ return false;
13
+ }
14
+ };
15
+ /**
16
+ * Origin of the parent frame to trust as the editor, when both it and the
17
+ * configured `editorURL` are local. A local editor moves to the next free port
18
+ * when its own is taken, so the `editorURL` baked into the app can miss it.
19
+ *
20
+ * @param editorURL - Configured editor URL.
21
+ * @param parentOrigin - Origin of the frame embedding the app.
22
+ * @returns The parent origin, or `undefined` when it must not be trusted.
23
+ */
24
+ const getLocalEditorParentOrigin = (editorURL, parentOrigin) => {
25
+ if (!editorURL || !parentOrigin) return void 0;
26
+ if (!isLoopbackUrl(editorURL) || !isLoopbackUrl(parentOrigin)) return;
27
+ return new URL(parentOrigin).origin;
28
+ };
29
+
30
+ export { getLocalEditorParentOrigin };
31
+ //# sourceMappingURL=getLocalEditorParentOrigin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocalEditorParentOrigin.mjs","names":[],"sources":["../../../src/core/getLocalEditorParentOrigin.ts"],"sourcesContent":["/** Hostnames of the local machine, as `URL.hostname` reports them. */\nconst LOOPBACK_HOSTNAMES = new Set(['localhost', '127.0.0.1', '[::1]']);\n\nconst isLoopbackUrl = (url: string): boolean => {\n try {\n return LOOPBACK_HOSTNAMES.has(new URL(url).hostname);\n } catch {\n return false;\n }\n};\n\n/**\n * Origin of the parent frame to trust as the editor, when both it and the\n * configured `editorURL` are local. A local editor moves to the next free port\n * when its own is taken, so the `editorURL` baked into the app can miss it.\n *\n * @param editorURL - Configured editor URL.\n * @param parentOrigin - Origin of the frame embedding the app.\n * @returns The parent origin, or `undefined` when it must not be trusted.\n */\nexport const getLocalEditorParentOrigin = (\n editorURL: string | undefined,\n parentOrigin: string | undefined\n): string | undefined => {\n if (!editorURL || !parentOrigin) return undefined;\n if (!isLoopbackUrl(editorURL) || !isLoopbackUrl(parentOrigin)) {\n return undefined;\n }\n\n return new URL(parentOrigin).origin;\n};\n"],"mappings":";;AACA,MAAM,qCAAqB,IAAI,IAAI;CAAC;CAAa;CAAa;AAAO,CAAC;AAEtE,MAAM,iBAAiB,QAAyB;CAC9C,IAAI;EACF,OAAO,mBAAmB,IAAI,IAAI,IAAI,GAAG,CAAC,CAAC,QAAQ;CACrD,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;AAWA,MAAa,8BACX,WACA,iBACuB;CACvB,IAAI,CAAC,aAAa,CAAC,cAAc,OAAO;CACxC,IAAI,CAAC,cAAc,SAAS,KAAK,CAAC,cAAc,YAAY,GAC1D;CAGF,OAAO,IAAI,IAAI,YAAY,CAAC,CAAC;AAC/B"}
@@ -1,4 +1,4 @@
1
- //#region src/core/globalManager.ts
1
+ // src/core/globalManager.ts
2
2
  /**
3
3
  * Keys on window used to share the singleton across multiple module instances.
4
4
  * When bundlers include @intlayer/editor more than once (e.g. framework package +
@@ -74,6 +74,5 @@ const onGlobalEditorManagerChange = (changeCallback) => {
74
74
  };
75
75
  };
76
76
 
77
- //#endregion
78
77
  export { getGlobalEditorManager, onGlobalEditorManagerChange, setGlobalEditorManager };
79
78
  //# sourceMappingURL=globalManager.mjs.map
@@ -1,10 +1,10 @@
1
- import { getGlobalEditorManager, onGlobalEditorManagerChange, setGlobalEditorManager } from "./globalManager.mjs";
2
1
  import { CrossFrameMessenger } from "./CrossFrameMessenger.mjs";
3
2
  import { CrossFrameStateManager } from "./CrossFrameStateManager.mjs";
3
+ import { CLIENT_HEARTBEAT_INTERVAL_MS, CLIENT_HEARTBEAT_TIMEOUT_MS, EditorStateManager } from "./EditorStateManager.mjs";
4
+ import { getGlobalEditorManager, onGlobalEditorManagerChange, setGlobalEditorManager } from "./globalManager.mjs";
4
5
  import { IframeClickInterceptor } from "./IframeClickInterceptor.mjs";
6
+ import { initEditorClient, stopEditorClient } from "./initEditorClient.mjs";
5
7
  import { createSharedWindowState } from "./sharedWindowState.mjs";
6
8
  import { UrlStateManager } from "./UrlStateManager.mjs";
7
- import { EditorStateManager } from "./EditorStateManager.mjs";
8
- import { initEditorClient, stopEditorClient } from "./initEditorClient.mjs";
9
9
 
10
- export { CrossFrameMessenger, CrossFrameStateManager, EditorStateManager, IframeClickInterceptor, UrlStateManager, createSharedWindowState, getGlobalEditorManager, initEditorClient, onGlobalEditorManagerChange, setGlobalEditorManager, stopEditorClient };
10
+ export { CLIENT_HEARTBEAT_INTERVAL_MS, CLIENT_HEARTBEAT_TIMEOUT_MS, CrossFrameMessenger, CrossFrameStateManager, EditorStateManager, IframeClickInterceptor, UrlStateManager, createSharedWindowState, getGlobalEditorManager, initEditorClient, onGlobalEditorManagerChange, setGlobalEditorManager, stopEditorClient };
@@ -1,16 +1,19 @@
1
- import { getGlobalEditorManager, setGlobalEditorManager } from "./globalManager.mjs";
2
1
  import { defineIntlayerElements } from "../components/ContentSelector.mjs";
3
2
  import { EditorStateManager } from "./EditorStateManager.mjs";
3
+ import { getLocalEditorParentOrigin } from "./getLocalEditorParentOrigin.mjs";
4
+ import { getGlobalEditorManager, setGlobalEditorManager } from "./globalManager.mjs";
4
5
  import { editor } from "@intlayer/config/built";
5
6
 
6
- //#region src/core/initEditorClient.ts
7
+ // src/core/initEditorClient.ts
7
8
  const buildClientMessengerConfig = () => {
8
9
  const sameOrigin = typeof window !== "undefined" ? window.location.origin : void 0;
10
+ const localEditorOrigin = typeof window !== "undefined" ? getLocalEditorParentOrigin(editor?.editorURL, window.location.ancestorOrigins?.[0]) : void 0;
9
11
  return {
10
12
  allowedOrigins: [...new Set([
11
13
  editor?.editorURL,
12
14
  editor?.cmsURL,
13
- sameOrigin
15
+ sameOrigin,
16
+ localEditorOrigin
14
17
  ].filter(Boolean))],
15
18
  postMessageFn: (payload, origin) => {
16
19
  if (typeof window === "undefined") return;
@@ -52,6 +55,5 @@ const stopEditorClient = () => {
52
55
  setGlobalEditorManager(null);
53
56
  };
54
57
 
55
- //#endregion
56
58
  export { initEditorClient, stopEditorClient };
57
59
  //# sourceMappingURL=initEditorClient.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"initEditorClient.mjs","names":[],"sources":["../../../src/core/initEditorClient.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport { defineIntlayerElements } from '../components';\nimport type { MessengerConfig } from './CrossFrameMessenger';\nimport { EditorStateManager } from './EditorStateManager';\nimport {\n getGlobalEditorManager,\n setGlobalEditorManager,\n} from './globalManager';\n\nconst buildClientMessengerConfig = (): MessengerConfig => {\n // The editor/CMS origins are baked into the bundle at build time, so they can\n // diverge from the actual serving origin (e.g. a production build served on\n // localhost, or a preview deployment). A same-origin parent is always safe to\n // trust — same-origin content already has full script access to this frame —\n // so include the app's own origin to keep same-origin embeddings (like the\n // website playground embedding /demo) working regardless of the built URLs.\n const sameOrigin =\n typeof window !== 'undefined' ? window.location.origin : undefined;\n\n const allowedOrigins = [\n ...new Set([editor?.editorURL, editor?.cmsURL, sameOrigin].filter(Boolean)),\n ] as string[];\n\n return {\n allowedOrigins,\n postMessageFn: (payload: unknown, origin: string) => {\n if (typeof window === 'undefined') return;\n\n const isInIframe = window.self !== window.top;\n\n if (!isInIframe) return;\n window.parent?.postMessage(payload, origin);\n },\n };\n};\n\n/** Reference count — tracks how many providers have called initEditorClient. */\nlet _clientRefCount = 0;\n\n/**\n * Initialize the Intlayer editor client singleton.\n * Safe to call multiple times — returns the existing manager if already initialized.\n * Increments a reference counter so nested providers don't destroy the manager\n * prematurely when the inner provider unmounts.\n */\nexport const initEditorClient = (): EditorStateManager => {\n _clientRefCount++;\n\n const existing = getGlobalEditorManager();\n if (existing) return existing;\n\n const manager = new EditorStateManager({\n mode: 'client',\n messenger: buildClientMessengerConfig(),\n configuration: { editor },\n });\n\n setGlobalEditorManager(manager);\n defineIntlayerElements();\n manager.start();\n\n return manager;\n};\n\n/**\n * Decrement the reference count and stop the global editor client singleton\n * only when the last provider unmounts.\n */\nexport const stopEditorClient = (): void => {\n _clientRefCount = Math.max(0, _clientRefCount - 1);\n\n if (_clientRefCount > 0) return;\n\n const manager = getGlobalEditorManager();\n manager?.stop();\n setGlobalEditorManager(null);\n};\n"],"mappings":";;;;;;AASA,MAAM,mCAAoD;CAOxD,MAAM,aACJ,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS;CAM3D,OAAO;EACL,iBAJA,GAAG,IAAI,IAAI;GAAC,QAAQ;GAAW,QAAQ;GAAQ;EAAU,CAAC,CAAC,OAAO,OAAO,CAAC,CAI7D;EACb,gBAAgB,SAAkB,WAAmB;GACnD,IAAI,OAAO,WAAW,aAAa;GAInC,IAAI,EAFe,OAAO,SAAS,OAAO,MAEzB;GACjB,OAAO,QAAQ,YAAY,SAAS,MAAM;EAC5C;CACF;AACF;;AAGA,IAAI,kBAAkB;;;;;;;AAQtB,MAAa,yBAA6C;CACxD;CAEA,MAAM,WAAW,uBAAuB;CACxC,IAAI,UAAU,OAAO;CAErB,MAAM,UAAU,IAAI,mBAAmB;EACrC,MAAM;EACN,WAAW,2BAA2B;EACtC,eAAe,EAAE,OAAO;CAC1B,CAAC;CAED,uBAAuB,OAAO;CAC9B,uBAAuB;CACvB,QAAQ,MAAM;CAEd,OAAO;AACT;;;;;AAMA,MAAa,yBAA+B;CAC1C,kBAAkB,KAAK,IAAI,GAAG,kBAAkB,CAAC;CAEjD,IAAI,kBAAkB,GAAG;CAGzB,AADgB,uBACV,CAAC,EAAE,KAAK;CACd,uBAAuB,IAAI;AAC7B"}
1
+ {"version":3,"file":"initEditorClient.mjs","names":[],"sources":["../../../src/core/initEditorClient.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport { defineIntlayerElements } from '../components';\nimport type { MessengerConfig } from './CrossFrameMessenger';\nimport { EditorStateManager } from './EditorStateManager';\nimport { getLocalEditorParentOrigin } from './getLocalEditorParentOrigin';\nimport {\n getGlobalEditorManager,\n setGlobalEditorManager,\n} from './globalManager';\n\nconst buildClientMessengerConfig = (): MessengerConfig => {\n // The editor/CMS origins are baked into the bundle at build time, so they can\n // diverge from the actual serving origin (e.g. a production build served on\n // localhost, or a preview deployment). A same-origin parent is always safe to\n // trust — same-origin content already has full script access to this frame —\n // so include the app's own origin to keep same-origin embeddings (like the\n // website playground embedding /demo) working regardless of the built URLs.\n const sameOrigin =\n typeof window !== 'undefined' ? window.location.origin : undefined;\n\n // A local editor may run on another port than the configured one\n const localEditorOrigin =\n typeof window !== 'undefined'\n ? getLocalEditorParentOrigin(\n editor?.editorURL,\n window.location.ancestorOrigins?.[0]\n )\n : undefined;\n\n const allowedOrigins = [\n ...new Set(\n [editor?.editorURL, editor?.cmsURL, sameOrigin, localEditorOrigin].filter(\n Boolean\n )\n ),\n ] as string[];\n\n return {\n allowedOrigins,\n postMessageFn: (payload: unknown, origin: string) => {\n if (typeof window === 'undefined') return;\n\n const isInIframe = window.self !== window.top;\n\n if (!isInIframe) return;\n window.parent?.postMessage(payload, origin);\n },\n };\n};\n\n/** Reference count — tracks how many providers have called initEditorClient. */\nlet _clientRefCount = 0;\n\n/**\n * Initialize the Intlayer editor client singleton.\n * Safe to call multiple times — returns the existing manager if already initialized.\n * Increments a reference counter so nested providers don't destroy the manager\n * prematurely when the inner provider unmounts.\n */\nexport const initEditorClient = (): EditorStateManager => {\n _clientRefCount++;\n\n const existing = getGlobalEditorManager();\n if (existing) return existing;\n\n const manager = new EditorStateManager({\n mode: 'client',\n messenger: buildClientMessengerConfig(),\n configuration: { editor },\n });\n\n setGlobalEditorManager(manager);\n defineIntlayerElements();\n manager.start();\n\n return manager;\n};\n\n/**\n * Decrement the reference count and stop the global editor client singleton\n * only when the last provider unmounts.\n */\nexport const stopEditorClient = (): void => {\n _clientRefCount = Math.max(0, _clientRefCount - 1);\n\n if (_clientRefCount > 0) return;\n\n const manager = getGlobalEditorManager();\n manager?.stop();\n setGlobalEditorManager(null);\n};\n"],"mappings":";;;;;;;AAUA,MAAM,mCAAoD;CAOxD,MAAM,aACJ,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS;CAG3D,MAAM,oBACJ,OAAO,WAAW,cACd,2BACE,QAAQ,WACR,OAAO,SAAS,kBAAkB,EACpC,IACA;CAUN,OAAO;EACL,iBARA,GAAG,IAAI,IACL;GAAC,QAAQ;GAAW,QAAQ;GAAQ;GAAY;EAAiB,CAAC,CAAC,OACjE,OACF,CACF,CAIa;EACb,gBAAgB,SAAkB,WAAmB;GACnD,IAAI,OAAO,WAAW,aAAa;GAInC,IAAI,EAFe,OAAO,SAAS,OAAO,MAEzB;GACjB,OAAO,QAAQ,YAAY,SAAS,MAAM;EAC5C;CACF;AACF;;AAGA,IAAI,kBAAkB;;;;;;;AAQtB,MAAa,yBAA6C;CACxD;CAEA,MAAM,WAAW,uBAAuB;CACxC,IAAI,UAAU,OAAO;CAErB,MAAM,UAAU,IAAI,mBAAmB;EACrC,MAAM;EACN,WAAW,2BAA2B;EACtC,eAAe,EAAE,OAAO;CAC1B,CAAC;CAED,uBAAuB,OAAO;CAC9B,uBAAuB;CACvB,QAAQ,MAAM;CAEd,OAAO;AACT;;;;;AAMA,MAAa,yBAA+B;CAC1C,kBAAkB,KAAK,IAAI,GAAG,kBAAkB,CAAC;CAEjD,IAAI,kBAAkB,GAAG;CAGzB,AADgB,uBACV,CAAC,EAAE,KAAK;CACd,uBAAuB,IAAI;AAC7B"}
@@ -0,0 +1,22 @@
1
+ // src/core/selectionClick.ts
2
+ /** Clicks that selected content, shared across the selectors of a frame. */
3
+ const selectionClickEvents = /* @__PURE__ */ new WeakSet();
4
+ /**
5
+ * Marks a click as having selected content, so outer selectors don't select
6
+ * their own content too, and the iframe click interceptor doesn't report it to
7
+ * the editor as a click outside its drawers.
8
+ *
9
+ * @param event - Click that selected content
10
+ */
11
+ const markSelectionClick = (event) => {
12
+ selectionClickEvents.add(event);
13
+ };
14
+ /**
15
+ * Whether a click already selected content.
16
+ *
17
+ * @param event - Click to check
18
+ */
19
+ const isSelectionClick = (event) => selectionClickEvents.has(event);
20
+
21
+ export { isSelectionClick, markSelectionClick };
22
+ //# sourceMappingURL=selectionClick.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectionClick.mjs","names":[],"sources":["../../../src/core/selectionClick.ts"],"sourcesContent":["/** Clicks that selected content, shared across the selectors of a frame. */\nconst selectionClickEvents = new WeakSet<Event>();\n\n/**\n * Marks a click as having selected content, so outer selectors don't select\n * their own content too, and the iframe click interceptor doesn't report it to\n * the editor as a click outside its drawers.\n *\n * @param event - Click that selected content\n */\nexport const markSelectionClick = (event: Event): void => {\n selectionClickEvents.add(event);\n};\n\n/**\n * Whether a click already selected content.\n *\n * @param event - Click to check\n */\nexport const isSelectionClick = (event: Event): boolean =>\n selectionClickEvents.has(event);\n"],"mappings":";;AACA,MAAM,uCAAuB,IAAI,QAAe;;;;;;;;AAShD,MAAa,sBAAsB,UAAuB;CACxD,qBAAqB,IAAI,KAAK;AAChC;;;;;;AAOA,MAAa,oBAAoB,UAC/B,qBAAqB,IAAI,KAAK"}
@@ -1,4 +1,4 @@
1
- //#region src/core/sharedWindowState.ts
1
+ // src/core/sharedWindowState.ts
2
2
  /**
3
3
  * A value shared by every EditorStateManager of the same window — the
4
4
  * dashboard mounts several editor providers that must agree on edits and focus.
@@ -43,6 +43,5 @@ const createSharedWindowState = (name) => {
43
43
  };
44
44
  };
45
45
 
46
- //#endregion
47
46
  export { createSharedWindowState };
48
47
  //# sourceMappingURL=sharedWindowState.mjs.map
@@ -1,5 +1,5 @@
1
- import { MessageKey } from "./messageKey.mjs";
2
1
  import { getGlobalEditorManager, onGlobalEditorManagerChange, setGlobalEditorManager } from "./core/globalManager.mjs";
2
+ import { MessageKey } from "./messageKey.mjs";
3
3
  import { IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper } from "./components/ContentSelectorWrapper.mjs";
4
4
  import { IntlayerContentSelectorElement, defineIntlayerElements } from "./components/ContentSelector.mjs";
5
5
  import { CrossFrameMessenger } from "./core/CrossFrameMessenger.mjs";
@@ -7,7 +7,7 @@ import { CrossFrameStateManager } from "./core/CrossFrameStateManager.mjs";
7
7
  import { IframeClickInterceptor } from "./core/IframeClickInterceptor.mjs";
8
8
  import { createSharedWindowState } from "./core/sharedWindowState.mjs";
9
9
  import { UrlStateManager } from "./core/UrlStateManager.mjs";
10
- import { EditorStateManager } from "./core/EditorStateManager.mjs";
10
+ import { CLIENT_HEARTBEAT_INTERVAL_MS, CLIENT_HEARTBEAT_TIMEOUT_MS, EditorStateManager } from "./core/EditorStateManager.mjs";
11
11
  import { initEditorClient, stopEditorClient } from "./core/initEditorClient.mjs";
12
12
 
13
- export { CrossFrameMessenger, CrossFrameStateManager, EditorStateManager, IframeClickInterceptor, IntlayerContentSelectorElement, IntlayerContentSelectorWrapperElement, MessageKey, UrlStateManager, createSharedWindowState, defineIntlayerContentSelectorWrapper, defineIntlayerElements, getGlobalEditorManager, initEditorClient, onGlobalEditorManagerChange, setGlobalEditorManager, stopEditorClient };
13
+ export { CLIENT_HEARTBEAT_INTERVAL_MS, CLIENT_HEARTBEAT_TIMEOUT_MS, CrossFrameMessenger, CrossFrameStateManager, EditorStateManager, IframeClickInterceptor, IntlayerContentSelectorElement, IntlayerContentSelectorWrapperElement, MessageKey, UrlStateManager, createSharedWindowState, defineIntlayerContentSelectorWrapper, defineIntlayerElements, getGlobalEditorManager, initEditorClient, onGlobalEditorManagerChange, setGlobalEditorManager, stopEditorClient };
@@ -1,9 +1,8 @@
1
1
  import { editor } from "@intlayer/config/built";
2
2
 
3
- //#region src/isEnabled.ts
3
+ // src/isEnabled.ts
4
4
  const TREE_SHAKE_EDITOR = process.env.INTLAYER_EDITOR_ENABLED === "false";
5
5
  const isEnabled = !TREE_SHAKE_EDITOR && editor?.enabled && typeof window !== "undefined" && window.self !== window.top;
6
6
 
7
- //#endregion
8
7
  export { isEnabled };
9
8
  //# sourceMappingURL=isEnabled.mjs.map