@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.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -2
- package/dist/cjs/compareUrls.cjs +1 -2
- package/dist/cjs/components/ContentSelector.cjs +70 -17
- package/dist/cjs/components/ContentSelector.cjs.map +1 -1
- package/dist/cjs/components/ContentSelectorWrapper.cjs +63 -6
- package/dist/cjs/components/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/components/index.cjs +2 -2
- package/dist/cjs/components/isInteractiveClickTarget.cjs +65 -0
- package/dist/cjs/components/isInteractiveClickTarget.cjs.map +1 -0
- package/dist/cjs/core/CrossFrameMessenger.cjs +2 -3
- package/dist/cjs/core/CrossFrameStateManager.cjs +1 -2
- package/dist/cjs/core/EditorStateManager.cjs +79 -18
- package/dist/cjs/core/EditorStateManager.cjs.map +1 -1
- package/dist/cjs/core/IframeClickInterceptor.cjs +17 -10
- package/dist/cjs/core/IframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/core/UrlStateManager.cjs +2 -3
- package/dist/cjs/core/getLocalEditorParentOrigin.cjs +32 -0
- package/dist/cjs/core/getLocalEditorParentOrigin.cjs.map +1 -0
- package/dist/cjs/core/globalManager.cjs +1 -2
- package/dist/cjs/core/index.cjs +10 -8
- package/dist/cjs/core/initEditorClient.cjs +8 -6
- package/dist/cjs/core/initEditorClient.cjs.map +1 -1
- package/dist/cjs/core/selectionClick.cjs +24 -0
- package/dist/cjs/core/selectionClick.cjs.map +1 -0
- package/dist/cjs/core/sharedWindowState.cjs +1 -2
- package/dist/cjs/index.cjs +13 -11
- package/dist/cjs/isEnabled.cjs +1 -2
- package/dist/cjs/messageKey.cjs +5 -2
- package/dist/cjs/messageKey.cjs.map +1 -1
- package/dist/esm/compareUrls.mjs +1 -2
- package/dist/esm/components/ContentSelector.mjs +69 -16
- package/dist/esm/components/ContentSelector.mjs.map +1 -1
- package/dist/esm/components/ContentSelectorWrapper.mjs +61 -4
- package/dist/esm/components/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/components/index.mjs +1 -1
- package/dist/esm/components/isInteractiveClickTarget.mjs +64 -0
- package/dist/esm/components/isInteractiveClickTarget.mjs.map +1 -0
- package/dist/esm/core/CrossFrameMessenger.mjs +1 -2
- package/dist/esm/core/CrossFrameStateManager.mjs +1 -2
- package/dist/esm/core/EditorStateManager.mjs +71 -12
- package/dist/esm/core/EditorStateManager.mjs.map +1 -1
- package/dist/esm/core/IframeClickInterceptor.mjs +16 -9
- package/dist/esm/core/IframeClickInterceptor.mjs.map +1 -1
- package/dist/esm/core/UrlStateManager.mjs +1 -2
- package/dist/esm/core/getLocalEditorParentOrigin.mjs +31 -0
- package/dist/esm/core/getLocalEditorParentOrigin.mjs.map +1 -0
- package/dist/esm/core/globalManager.mjs +1 -2
- package/dist/esm/core/index.mjs +4 -4
- package/dist/esm/core/initEditorClient.mjs +6 -4
- package/dist/esm/core/initEditorClient.mjs.map +1 -1
- package/dist/esm/core/selectionClick.mjs +22 -0
- package/dist/esm/core/selectionClick.mjs.map +1 -0
- package/dist/esm/core/sharedWindowState.mjs +1 -2
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/isEnabled.mjs +1 -2
- package/dist/esm/messageKey.mjs +5 -2
- package/dist/esm/messageKey.mjs.map +1 -1
- package/dist/types/compareUrls.d.ts +0 -2
- package/dist/types/compareUrls.d.ts.map +1 -1
- package/dist/types/components/ContentSelector.d.ts +10 -4
- package/dist/types/components/ContentSelector.d.ts.map +1 -1
- package/dist/types/components/ContentSelectorWrapper.d.ts +5 -2
- package/dist/types/components/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/components/isInteractiveClickTarget.d.ts +14 -0
- package/dist/types/components/isInteractiveClickTarget.d.ts.map +1 -0
- package/dist/types/core/CrossFrameMessenger.d.ts +1 -2
- package/dist/types/core/CrossFrameMessenger.d.ts.map +1 -1
- package/dist/types/core/CrossFrameStateManager.d.ts +0 -2
- package/dist/types/core/CrossFrameStateManager.d.ts.map +1 -1
- package/dist/types/core/EditorStateManager.d.ts +34 -3
- package/dist/types/core/EditorStateManager.d.ts.map +1 -1
- package/dist/types/core/IframeClickInterceptor.d.ts +8 -4
- package/dist/types/core/IframeClickInterceptor.d.ts.map +1 -1
- package/dist/types/core/UrlStateManager.d.ts +0 -2
- package/dist/types/core/UrlStateManager.d.ts.map +1 -1
- package/dist/types/core/getLocalEditorParentOrigin.d.ts +11 -0
- package/dist/types/core/getLocalEditorParentOrigin.d.ts.map +1 -0
- package/dist/types/core/globalManager.d.ts +0 -2
- package/dist/types/core/globalManager.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +4 -4
- package/dist/types/core/initEditorClient.d.ts +0 -2
- package/dist/types/core/initEditorClient.d.ts.map +1 -1
- package/dist/types/core/selectionClick.d.ts +15 -0
- package/dist/types/core/selectionClick.d.ts.map +1 -0
- package/dist/types/core/sharedWindowState.d.ts +1 -2
- package/dist/types/core/sharedWindowState.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/isEnabled.d.ts +0 -2
- package/dist/types/isEnabled.d.ts.map +1 -1
- package/dist/types/messageKey.d.ts +5 -3
- package/dist/types/messageKey.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require(
|
|
3
|
-
const require_messageKey = require(
|
|
4
|
-
const require_core_CrossFrameMessenger = require(
|
|
5
|
-
const require_core_CrossFrameStateManager = require(
|
|
6
|
-
const require_core_IframeClickInterceptor = require(
|
|
7
|
-
const require_core_sharedWindowState = require(
|
|
8
|
-
const require_core_UrlStateManager = require(
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_messageKey = require("../messageKey.cjs");
|
|
4
|
+
const require_core_CrossFrameMessenger = require("./CrossFrameMessenger.cjs");
|
|
5
|
+
const require_core_CrossFrameStateManager = require("./CrossFrameStateManager.cjs");
|
|
6
|
+
const require_core_IframeClickInterceptor = require("./IframeClickInterceptor.cjs");
|
|
7
|
+
const require_core_sharedWindowState = require("./sharedWindowState.cjs");
|
|
8
|
+
const require_core_UrlStateManager = require("./UrlStateManager.cjs");
|
|
9
9
|
let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
|
|
10
10
|
_intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
|
|
11
11
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
// src/core/EditorStateManager.ts
|
|
14
|
+
/** Delay between two editor pings checking the client still answers. */
|
|
15
|
+
const CLIENT_HEARTBEAT_INTERVAL_MS = 3e3;
|
|
16
|
+
/**
|
|
17
|
+
* Silence after which the client counts as disconnected (e.g. its dev server
|
|
18
|
+
* restarted). Pings go on, so it is activated again as soon as it answers.
|
|
19
|
+
*/
|
|
20
|
+
const CLIENT_HEARTBEAT_TIMEOUT_MS = 1e4;
|
|
21
|
+
/** Clients older than the heartbeat announce themselves without payload. */
|
|
22
|
+
const isClientReadyPayload = (data) => typeof data === "object" && data !== null && typeof data.isActivated === "boolean";
|
|
14
23
|
const sharedEditedContent = require_core_sharedWindowState.createSharedWindowState("edited_content");
|
|
15
24
|
const sharedFocusedContent = require_core_sharedWindowState.createSharedWindowState("focused_content");
|
|
16
25
|
/**
|
|
@@ -37,9 +46,12 @@ var EditorStateManager = class {
|
|
|
37
46
|
_unsubAreYouThere = null;
|
|
38
47
|
_unsubActivate = null;
|
|
39
48
|
_unsubClientReady = null;
|
|
49
|
+
_clientHeartbeatTimer = null;
|
|
50
|
+
_lastClientReadyAt = 0;
|
|
40
51
|
_displayedKeysObserver = null;
|
|
41
52
|
_displayedKeysTimer = null;
|
|
42
53
|
_displayedKeysListeners = [];
|
|
54
|
+
_unsubDisplayedKeysGet = null;
|
|
43
55
|
_stopSharedStateSyncs = [];
|
|
44
56
|
constructor(config) {
|
|
45
57
|
this._mode = config.mode;
|
|
@@ -69,7 +81,7 @@ var EditorStateManager = class {
|
|
|
69
81
|
this.displayedDictionaryKeys = new require_core_CrossFrameStateManager.CrossFrameStateManager("INTLAYER_DISPLAYED_DICTIONARY_KEYS", this.messenger, {
|
|
70
82
|
emit: config.mode === "client",
|
|
71
83
|
receive: config.mode === "editor",
|
|
72
|
-
initialValue: []
|
|
84
|
+
initialValue: config.mode === "client" ? [] : void 0
|
|
73
85
|
});
|
|
74
86
|
this._urlManager = new require_core_UrlStateManager.UrlStateManager(this.messenger);
|
|
75
87
|
this._iframeInterceptor = new require_core_IframeClickInterceptor.IframeClickInterceptor(this.messenger);
|
|
@@ -103,6 +115,7 @@ var EditorStateManager = class {
|
|
|
103
115
|
this._unsubAreYouThere = null;
|
|
104
116
|
this._unsubActivate = null;
|
|
105
117
|
this._unsubClientReady = null;
|
|
118
|
+
this._stopClientHeartbeat();
|
|
106
119
|
this.messenger.stop();
|
|
107
120
|
this.editorEnabled.stop();
|
|
108
121
|
this.focusedContent.stop();
|
|
@@ -127,13 +140,28 @@ var EditorStateManager = class {
|
|
|
127
140
|
this.messenger.send("INTLAYER_ARE_YOU_THERE");
|
|
128
141
|
this.messenger.send(`${"INTLAYER_EDITOR_ENABLED"}/post`, true);
|
|
129
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* EDITOR mode: asks the client to switch locale. Covers applications whose
|
|
145
|
+
* locale is held in memory or storage only (no locale segment in the URL).
|
|
146
|
+
*/
|
|
147
|
+
requestLocaleChange(locale) {
|
|
148
|
+
if (this._mode !== "editor") return;
|
|
149
|
+
this.messenger.send("INTLAYER_LOCALE_CHANGE_REQUESTED", locale);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* CLIENT mode: subscribes to the locale changes requested by the editor.
|
|
153
|
+
* Returns an unsubscribe function.
|
|
154
|
+
*/
|
|
155
|
+
onLocaleChangeRequested(handler) {
|
|
156
|
+
if (this._mode !== "client") return () => {};
|
|
157
|
+
return this.messenger.subscribe("INTLAYER_LOCALE_CHANGE_REQUESTED", handler);
|
|
158
|
+
}
|
|
130
159
|
setFocusedContentKeyPath(keyPath) {
|
|
131
|
-
const filtered = keyPath.filter((key) => key.type !== _intlayer_types_nodeType.TRANSLATION);
|
|
132
160
|
const prev = this.focusedContent.value;
|
|
133
161
|
if (!prev) return;
|
|
134
162
|
this.focusedContent.set({
|
|
135
163
|
...prev,
|
|
136
|
-
keyPath
|
|
164
|
+
keyPath
|
|
137
165
|
});
|
|
138
166
|
}
|
|
139
167
|
setLocaleDictionary(dictionary) {
|
|
@@ -289,6 +317,9 @@ var EditorStateManager = class {
|
|
|
289
317
|
window.addEventListener(evt, listener);
|
|
290
318
|
this._displayedKeysListeners.push([evt, listener]);
|
|
291
319
|
}
|
|
320
|
+
this._unsubDisplayedKeysGet = this.messenger.subscribe(`${"INTLAYER_DISPLAYED_DICTIONARY_KEYS"}/get`, () => {
|
|
321
|
+
this._scanDisplayedDictionaryKeys();
|
|
322
|
+
});
|
|
292
323
|
this._scanDisplayedDictionaryKeys();
|
|
293
324
|
}
|
|
294
325
|
_stopDisplayedDictionariesTracking() {
|
|
@@ -300,25 +331,52 @@ var EditorStateManager = class {
|
|
|
300
331
|
}
|
|
301
332
|
for (const [evt, listener] of this._displayedKeysListeners) window.removeEventListener(evt, listener);
|
|
302
333
|
this._displayedKeysListeners = [];
|
|
334
|
+
this._unsubDisplayedKeysGet?.();
|
|
335
|
+
this._unsubDisplayedKeysGet = null;
|
|
303
336
|
}
|
|
304
337
|
/**
|
|
305
338
|
* EDITOR mode: listen for CLIENT_READY and respond with EDITOR_ACTIVATE.
|
|
306
339
|
* Also pings the client immediately in case it loaded before the editor.
|
|
307
340
|
*/
|
|
308
341
|
_setupEditorHandshake() {
|
|
309
|
-
this._unsubClientReady = this.messenger.subscribe("INTLAYER_CLIENT_READY", () => {
|
|
342
|
+
this._unsubClientReady = this.messenger.subscribe("INTLAYER_CLIENT_READY", (data) => {
|
|
343
|
+
if (!isClientReadyPayload(data)) {
|
|
344
|
+
this.editorEnabled.set(true);
|
|
345
|
+
this.messenger.send("INTLAYER_EDITOR_ACTIVATE");
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const isConnected = data.isActivated && this.editorEnabled.value;
|
|
349
|
+
this._lastClientReadyAt = Date.now();
|
|
350
|
+
this._startClientHeartbeat();
|
|
310
351
|
this.editorEnabled.set(true);
|
|
311
|
-
this.messenger.send("INTLAYER_EDITOR_ACTIVATE");
|
|
352
|
+
if (!isConnected) this.messenger.send("INTLAYER_EDITOR_ACTIVATE");
|
|
312
353
|
});
|
|
313
354
|
this.messenger.send("INTLAYER_ARE_YOU_THERE");
|
|
314
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* EDITOR mode: keeps pinging the client. A client that stopped answering
|
|
358
|
+
* (dev server restart, reloaded frame, re-evaluated client module) is marked
|
|
359
|
+
* disconnected, then activated again on its next answer.
|
|
360
|
+
*/
|
|
361
|
+
_startClientHeartbeat() {
|
|
362
|
+
if (this._clientHeartbeatTimer) return;
|
|
363
|
+
this._clientHeartbeatTimer = setInterval(() => {
|
|
364
|
+
const isClientSilent = Date.now() - this._lastClientReadyAt > CLIENT_HEARTBEAT_TIMEOUT_MS;
|
|
365
|
+
if (this.editorEnabled.value && isClientSilent) this.editorEnabled.set(false);
|
|
366
|
+
this.messenger.send("INTLAYER_ARE_YOU_THERE");
|
|
367
|
+
}, CLIENT_HEARTBEAT_INTERVAL_MS);
|
|
368
|
+
}
|
|
369
|
+
_stopClientHeartbeat() {
|
|
370
|
+
if (this._clientHeartbeatTimer) clearInterval(this._clientHeartbeatTimer);
|
|
371
|
+
this._clientHeartbeatTimer = null;
|
|
372
|
+
}
|
|
315
373
|
_setupActivationHandshake() {
|
|
316
|
-
this.messenger.send("INTLAYER_CLIENT_READY");
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
});
|
|
374
|
+
const announceReady = () => this.messenger.send("INTLAYER_CLIENT_READY", { isActivated: this.editorEnabled.value === true });
|
|
375
|
+
announceReady();
|
|
376
|
+
this._unsubAreYouThere = this.messenger.subscribe("INTLAYER_ARE_YOU_THERE", announceReady);
|
|
320
377
|
this._unsubActivate = this.messenger.subscribe("INTLAYER_EDITOR_ACTIVATE", () => {
|
|
321
378
|
this.editorEnabled.set(true);
|
|
379
|
+
this._scanDisplayedDictionaryKeys();
|
|
322
380
|
this._broadcastData();
|
|
323
381
|
});
|
|
324
382
|
}
|
|
@@ -329,6 +387,8 @@ var EditorStateManager = class {
|
|
|
329
387
|
if (localeVal) this.messenger.send(`${"INTLAYER_CURRENT_LOCALE"}/post`, localeVal);
|
|
330
388
|
const dicts = this.localeDictionaries.value;
|
|
331
389
|
if (dicts) this.messenger.send(`${"INTLAYER_LOCALE_DICTIONARIES_CHANGED"}/post`, dicts);
|
|
390
|
+
const displayedKeys = this.displayedDictionaryKeys.value;
|
|
391
|
+
if (displayedKeys) this.messenger.send(`${"INTLAYER_DISPLAYED_DICTIONARY_KEYS"}/post`, displayedKeys);
|
|
332
392
|
}
|
|
333
393
|
async _loadDictionaries() {
|
|
334
394
|
try {
|
|
@@ -342,6 +402,7 @@ var EditorStateManager = class {
|
|
|
342
402
|
}
|
|
343
403
|
};
|
|
344
404
|
|
|
345
|
-
|
|
405
|
+
exports.CLIENT_HEARTBEAT_INTERVAL_MS = CLIENT_HEARTBEAT_INTERVAL_MS;
|
|
406
|
+
exports.CLIENT_HEARTBEAT_TIMEOUT_MS = CLIENT_HEARTBEAT_TIMEOUT_MS;
|
|
346
407
|
exports.EditorStateManager = EditorStateManager;
|
|
347
408
|
//# sourceMappingURL=EditorStateManager.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorStateManager.cjs","names":["createSharedWindowState","CrossFrameMessenger","CrossFrameStateManager","UrlStateManager","IframeClickInterceptor","NodeTypes","getContentNodeByKeyPath","editDictionaryByKeyPath","renameContentNodeByKeyPath"],"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,sBACJA,uDAA2C,gBAAgB;AAC7D,MAAM,uBAAuBA,uDAC3B,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,IAAIC,qDAAoB,OAAO,SAAS;EAEzD,KAAK,gBAAgB,IAAIC,sFAEvB,KAAK,WACL;GAAE,MAAM;GAAO,SAAS;GAAM,cAAc;EAAM,CACpD;EAEA,KAAK,iBAAiB,IAAIA,+FAExB,KAAK,WACL;GAAE,MAAM;GAAM,SAAS;GAAM,cAAc;EAAK,CAClD;EAEA,KAAK,qBAAqB,IAAIA,mGAE5B,KAAK,SACP;EAEA,KAAK,gBAAgB,IAAIA,8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GAI5C,IAAI,KAAK,cAAc,OACrB,KAAK,eAAe;EAExB,SAAS,GAAG;GAEV,QAAQ,KAAK,oDAAoD,CAAC;EACpE;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"EditorStateManager.cjs","names":["createSharedWindowState","CrossFrameMessenger","CrossFrameStateManager","UrlStateManager","IframeClickInterceptor","getContentNodeByKeyPath","editDictionaryByKeyPath","renameContentNodeByKeyPath","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 {\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,sBACJA,uDAA2C,gBAAgB;AAC7D,MAAM,uBAAuBA,uDAC3B,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,IAAIC,qDAAoB,OAAO,SAAS;EAEzD,KAAK,gBAAgB,IAAIC,sFAEvB,KAAK,WACL;GAAE,MAAM;GAAO,SAAS;GAAM,cAAc;EAAM,CACpD;EAEA,KAAK,iBAAiB,IAAIA,+FAExB,KAAK,WACL;GAAE,MAAM;GAAM,SAAS;GAAM,cAAc;EAAK,CAClD;EAEA,KAAK,qBAAqB,IAAIA,mGAE5B,KAAK,SACP;EAEA,KAAK,gBAAgB,IAAIA,8FAEvB,KAAK,S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require_messageKey = require(
|
|
2
|
+
const require_messageKey = require("../messageKey.cjs");
|
|
3
|
+
const require_core_selectionClick = require("./selectionClick.cjs");
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
// src/core/IframeClickInterceptor.ts
|
|
5
6
|
/**
|
|
6
7
|
* Replays a click made inside the iframe on the editor window, so the editor's
|
|
7
8
|
* "click outside" handlers (popovers, drawers) react to it.
|
|
@@ -16,30 +17,37 @@ const replayIframeClick = () => {
|
|
|
16
17
|
/**
|
|
17
18
|
* Forwards clicks across the iframe boundary.
|
|
18
19
|
*
|
|
19
|
-
* - startInterceptor(): client (iframe) side — reports each
|
|
20
|
+
* - startInterceptor(): client (iframe) side — reports each click to the editor
|
|
20
21
|
* - startMerger(): editor (parent) side — replays reported clicks on its window
|
|
22
|
+
*
|
|
23
|
+
* Clicks are reported once released rather than on mousedown: a long press on
|
|
24
|
+
* content starts with a mousedown too, and reporting it closed the editor
|
|
25
|
+
* drawers right before the press focused content in them. A completed long
|
|
26
|
+
* press stops its own click (see `ContentSelector`), and a click selecting
|
|
27
|
+
* content is marked as such, so neither is reported.
|
|
21
28
|
*/
|
|
22
29
|
var IframeClickInterceptor = class {
|
|
23
30
|
_messenger;
|
|
24
|
-
|
|
31
|
+
_clickHandler = null;
|
|
25
32
|
_unsubscribeMerge = null;
|
|
26
33
|
constructor(messenger) {
|
|
27
34
|
this._messenger = messenger;
|
|
28
35
|
}
|
|
29
36
|
startInterceptor() {
|
|
30
37
|
if (typeof window === "undefined") return;
|
|
31
|
-
this.
|
|
38
|
+
this._clickHandler = (event) => {
|
|
39
|
+
if (require_core_selectionClick.isSelectionClick(event)) return;
|
|
32
40
|
this._messenger.send("INTLAYER_IFRAME_CLICKED");
|
|
33
41
|
};
|
|
34
|
-
window.addEventListener("
|
|
42
|
+
window.addEventListener("click", this._clickHandler);
|
|
35
43
|
}
|
|
36
44
|
startMerger() {
|
|
37
45
|
this._unsubscribeMerge = this._messenger.subscribe("INTLAYER_IFRAME_CLICKED", replayIframeClick);
|
|
38
46
|
}
|
|
39
47
|
stopInterceptor() {
|
|
40
|
-
if (this.
|
|
41
|
-
window.removeEventListener("
|
|
42
|
-
this.
|
|
48
|
+
if (this._clickHandler) {
|
|
49
|
+
window.removeEventListener("click", this._clickHandler);
|
|
50
|
+
this._clickHandler = null;
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
53
|
stopMerger() {
|
|
@@ -48,6 +56,5 @@ var IframeClickInterceptor = class {
|
|
|
48
56
|
}
|
|
49
57
|
};
|
|
50
58
|
|
|
51
|
-
//#endregion
|
|
52
59
|
exports.IframeClickInterceptor = IframeClickInterceptor;
|
|
53
60
|
//# sourceMappingURL=IframeClickInterceptor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeClickInterceptor.cjs","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
|
|
1
|
+
{"version":3,"file":"IframeClickInterceptor.cjs","names":["isSelectionClick"],"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,IAAIA,6CAAiB,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,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_messageKey = require(
|
|
2
|
+
const require_messageKey = require("../messageKey.cjs");
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/core/UrlStateManager.ts
|
|
5
5
|
/**
|
|
6
6
|
* UrlStateManager patches window.history and broadcasts URL path changes
|
|
7
7
|
* across frames via postMessage.
|
|
@@ -56,6 +56,5 @@ var UrlStateManager = class {
|
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
//#endregion
|
|
60
59
|
exports.UrlStateManager = UrlStateManager;
|
|
61
60
|
//# sourceMappingURL=UrlStateManager.cjs.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
// src/core/getLocalEditorParentOrigin.ts
|
|
3
|
+
/** Hostnames of the local machine, as `URL.hostname` reports them. */
|
|
4
|
+
const LOOPBACK_HOSTNAMES = /* @__PURE__ */ new Set([
|
|
5
|
+
"localhost",
|
|
6
|
+
"127.0.0.1",
|
|
7
|
+
"[::1]"
|
|
8
|
+
]);
|
|
9
|
+
const isLoopbackUrl = (url) => {
|
|
10
|
+
try {
|
|
11
|
+
return LOOPBACK_HOSTNAMES.has(new URL(url).hostname);
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Origin of the parent frame to trust as the editor, when both it and the
|
|
18
|
+
* configured `editorURL` are local. A local editor moves to the next free port
|
|
19
|
+
* when its own is taken, so the `editorURL` baked into the app can miss it.
|
|
20
|
+
*
|
|
21
|
+
* @param editorURL - Configured editor URL.
|
|
22
|
+
* @param parentOrigin - Origin of the frame embedding the app.
|
|
23
|
+
* @returns The parent origin, or `undefined` when it must not be trusted.
|
|
24
|
+
*/
|
|
25
|
+
const getLocalEditorParentOrigin = (editorURL, parentOrigin) => {
|
|
26
|
+
if (!editorURL || !parentOrigin) return void 0;
|
|
27
|
+
if (!isLoopbackUrl(editorURL) || !isLoopbackUrl(parentOrigin)) return;
|
|
28
|
+
return new URL(parentOrigin).origin;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.getLocalEditorParentOrigin = getLocalEditorParentOrigin;
|
|
32
|
+
//# sourceMappingURL=getLocalEditorParentOrigin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLocalEditorParentOrigin.cjs","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,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
2
|
+
// src/core/globalManager.ts
|
|
3
3
|
/**
|
|
4
4
|
* Keys on window used to share the singleton across multiple module instances.
|
|
5
5
|
* When bundlers include @intlayer/editor more than once (e.g. framework package +
|
|
@@ -75,7 +75,6 @@ const onGlobalEditorManagerChange = (changeCallback) => {
|
|
|
75
75
|
};
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
//#endregion
|
|
79
78
|
exports.getGlobalEditorManager = getGlobalEditorManager;
|
|
80
79
|
exports.onGlobalEditorManagerChange = onGlobalEditorManagerChange;
|
|
81
80
|
exports.setGlobalEditorManager = setGlobalEditorManager;
|
package/dist/cjs/core/index.cjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
2
|
+
const require_core_CrossFrameMessenger = require("./CrossFrameMessenger.cjs");
|
|
3
|
+
const require_core_CrossFrameStateManager = require("./CrossFrameStateManager.cjs");
|
|
4
|
+
const require_core_EditorStateManager = require("./EditorStateManager.cjs");
|
|
5
|
+
const require_core_globalManager = require("./globalManager.cjs");
|
|
6
|
+
const require_core_IframeClickInterceptor = require("./IframeClickInterceptor.cjs");
|
|
7
|
+
const require_core_initEditorClient = require("./initEditorClient.cjs");
|
|
8
|
+
const require_core_sharedWindowState = require("./sharedWindowState.cjs");
|
|
9
|
+
const require_core_UrlStateManager = require("./UrlStateManager.cjs");
|
|
10
10
|
|
|
11
|
+
exports.CLIENT_HEARTBEAT_INTERVAL_MS = require_core_EditorStateManager.CLIENT_HEARTBEAT_INTERVAL_MS;
|
|
12
|
+
exports.CLIENT_HEARTBEAT_TIMEOUT_MS = require_core_EditorStateManager.CLIENT_HEARTBEAT_TIMEOUT_MS;
|
|
11
13
|
exports.CrossFrameMessenger = require_core_CrossFrameMessenger.CrossFrameMessenger;
|
|
12
14
|
exports.CrossFrameStateManager = require_core_CrossFrameStateManager.CrossFrameStateManager;
|
|
13
15
|
exports.EditorStateManager = require_core_EditorStateManager.EditorStateManager;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
2
|
+
const require_components_ContentSelector = require("../components/ContentSelector.cjs");
|
|
3
|
+
const require_core_EditorStateManager = require("./EditorStateManager.cjs");
|
|
4
|
+
const require_core_getLocalEditorParentOrigin = require("./getLocalEditorParentOrigin.cjs");
|
|
5
|
+
const require_core_globalManager = require("./globalManager.cjs");
|
|
5
6
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
// src/core/initEditorClient.ts
|
|
8
9
|
const buildClientMessengerConfig = () => {
|
|
9
10
|
const sameOrigin = typeof window !== "undefined" ? window.location.origin : void 0;
|
|
11
|
+
const localEditorOrigin = typeof window !== "undefined" ? require_core_getLocalEditorParentOrigin.getLocalEditorParentOrigin(_intlayer_config_built.editor?.editorURL, window.location.ancestorOrigins?.[0]) : void 0;
|
|
10
12
|
return {
|
|
11
13
|
allowedOrigins: [...new Set([
|
|
12
14
|
_intlayer_config_built.editor?.editorURL,
|
|
13
15
|
_intlayer_config_built.editor?.cmsURL,
|
|
14
|
-
sameOrigin
|
|
16
|
+
sameOrigin,
|
|
17
|
+
localEditorOrigin
|
|
15
18
|
].filter(Boolean))],
|
|
16
19
|
postMessageFn: (payload, origin) => {
|
|
17
20
|
if (typeof window === "undefined") return;
|
|
@@ -53,7 +56,6 @@ const stopEditorClient = () => {
|
|
|
53
56
|
require_core_globalManager.setGlobalEditorManager(null);
|
|
54
57
|
};
|
|
55
58
|
|
|
56
|
-
//#endregion
|
|
57
59
|
exports.initEditorClient = initEditorClient;
|
|
58
60
|
exports.stopEditorClient = stopEditorClient;
|
|
59
61
|
//# sourceMappingURL=initEditorClient.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initEditorClient.cjs","names":["editor","getGlobalEditorManager","EditorStateManager"],"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":"
|
|
1
|
+
{"version":3,"file":"initEditorClient.cjs","names":["getLocalEditorParentOrigin","editor","getGlobalEditorManager","EditorStateManager"],"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,cACdA,mEACEC,+BAAQ,WACR,OAAO,SAAS,kBAAkB,EACpC,IACA;CAUN,OAAO;EACL,iBARA,GAAG,IAAI,IACL;GAACA,+BAAQ;GAAWA,+BAAQ;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,WAAWC,kDAAuB;CACxC,IAAI,UAAU,OAAO;CAErB,MAAM,UAAU,IAAIC,mDAAmB;EACrC,MAAM;EACN,WAAW,2BAA2B;EACtC,eAAe,EAAE,sCAAO;CAC1B,CAAC;CAED,kDAAuB,OAAO;CAC9B,0DAAuB;CACvB,QAAQ,MAAM;CAEd,OAAO;AACT;;;;;AAMA,MAAa,yBAA+B;CAC1C,kBAAkB,KAAK,IAAI,GAAG,kBAAkB,CAAC;CAEjD,IAAI,kBAAkB,GAAG;CAGzB,AADgBD,kDACV,CAAC,EAAE,KAAK;CACd,kDAAuB,IAAI;AAC7B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
// src/core/selectionClick.ts
|
|
3
|
+
/** Clicks that selected content, shared across the selectors of a frame. */
|
|
4
|
+
const selectionClickEvents = /* @__PURE__ */ new WeakSet();
|
|
5
|
+
/**
|
|
6
|
+
* Marks a click as having selected content, so outer selectors don't select
|
|
7
|
+
* their own content too, and the iframe click interceptor doesn't report it to
|
|
8
|
+
* the editor as a click outside its drawers.
|
|
9
|
+
*
|
|
10
|
+
* @param event - Click that selected content
|
|
11
|
+
*/
|
|
12
|
+
const markSelectionClick = (event) => {
|
|
13
|
+
selectionClickEvents.add(event);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Whether a click already selected content.
|
|
17
|
+
*
|
|
18
|
+
* @param event - Click to check
|
|
19
|
+
*/
|
|
20
|
+
const isSelectionClick = (event) => selectionClickEvents.has(event);
|
|
21
|
+
|
|
22
|
+
exports.isSelectionClick = isSelectionClick;
|
|
23
|
+
exports.markSelectionClick = markSelectionClick;
|
|
24
|
+
//# sourceMappingURL=selectionClick.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectionClick.cjs","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,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
2
|
+
// src/core/sharedWindowState.ts
|
|
3
3
|
/**
|
|
4
4
|
* A value shared by every EditorStateManager of the same window — the
|
|
5
5
|
* dashboard mounts several editor providers that must agree on edits and focus.
|
|
@@ -44,6 +44,5 @@ const createSharedWindowState = (name) => {
|
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
//#endregion
|
|
48
47
|
exports.createSharedWindowState = createSharedWindowState;
|
|
49
48
|
//# sourceMappingURL=sharedWindowState.cjs.map
|