@intlayer/editor 9.5.11 → 9.5.12
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/components/ContentSelector.cjs +0 -4
- package/dist/cjs/components/ContentSelector.cjs.map +1 -1
- package/dist/cjs/components/ContentSelectorWrapper.cjs +72 -76
- package/dist/cjs/components/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/components/index.cjs +0 -6
- package/dist/cjs/core/EditorStateManager.cjs +32 -75
- package/dist/cjs/core/EditorStateManager.cjs.map +1 -1
- package/dist/cjs/core/IframeClickInterceptor.cjs +15 -9
- package/dist/cjs/core/IframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/core/index.cjs +3 -10
- package/dist/cjs/core/initEditorClient.cjs +1 -2
- package/dist/cjs/core/initEditorClient.cjs.map +1 -1
- package/dist/cjs/core/sharedWindowState.cjs +49 -0
- package/dist/cjs/core/sharedWindowState.cjs.map +1 -0
- package/dist/cjs/index.cjs +4 -21
- package/dist/esm/components/ContentSelector.mjs +0 -4
- package/dist/esm/components/ContentSelector.mjs.map +1 -1
- package/dist/esm/components/ContentSelectorWrapper.mjs +72 -76
- package/dist/esm/components/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/components/index.mjs +1 -3
- package/dist/esm/core/EditorStateManager.mjs +32 -75
- package/dist/esm/core/EditorStateManager.mjs.map +1 -1
- package/dist/esm/core/IframeClickInterceptor.mjs +15 -9
- package/dist/esm/core/IframeClickInterceptor.mjs.map +1 -1
- package/dist/esm/core/index.mjs +3 -4
- package/dist/esm/core/initEditorClient.mjs +2 -2
- package/dist/esm/core/initEditorClient.mjs.map +1 -1
- package/dist/esm/core/sharedWindowState.mjs +48 -0
- package/dist/esm/core/sharedWindowState.mjs.map +1 -0
- package/dist/esm/index.mjs +4 -9
- package/dist/types/components/ContentSelector.d.ts.map +1 -1
- package/dist/types/components/ContentSelectorWrapper.d.ts +12 -9
- package/dist/types/components/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/components/index.d.ts +1 -3
- package/dist/types/core/EditorStateManager.d.ts +7 -13
- package/dist/types/core/EditorStateManager.d.ts.map +1 -1
- package/dist/types/core/IframeClickInterceptor.d.ts +3 -7
- package/dist/types/core/IframeClickInterceptor.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +3 -4
- package/dist/types/core/initEditorClient.d.ts +0 -2
- package/dist/types/core/initEditorClient.d.ts.map +1 -1
- package/dist/types/core/sharedWindowState.d.ts +18 -0
- package/dist/types/core/sharedWindowState.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -9
- package/package.json +5 -5
- package/dist/cjs/components/EditedContent.cjs +0 -161
- package/dist/cjs/components/EditedContent.cjs.map +0 -1
- package/dist/cjs/components/IntlayerEditor.cjs +0 -94
- package/dist/cjs/components/IntlayerEditor.cjs.map +0 -1
- package/dist/cjs/core/editedContentBus.cjs +0 -36
- package/dist/cjs/core/editedContentBus.cjs.map +0 -1
- package/dist/cjs/core/focusedContentBus.cjs +0 -42
- package/dist/cjs/core/focusedContentBus.cjs.map +0 -1
- package/dist/cjs/mergeIframeClick.cjs +0 -22
- package/dist/cjs/mergeIframeClick.cjs.map +0 -1
- package/dist/esm/components/EditedContent.mjs +0 -159
- package/dist/esm/components/EditedContent.mjs.map +0 -1
- package/dist/esm/components/IntlayerEditor.mjs +0 -92
- package/dist/esm/components/IntlayerEditor.mjs.map +0 -1
- package/dist/esm/core/editedContentBus.mjs +0 -33
- package/dist/esm/core/editedContentBus.mjs.map +0 -1
- package/dist/esm/core/focusedContentBus.mjs +0 -39
- package/dist/esm/core/focusedContentBus.mjs.map +0 -1
- package/dist/esm/mergeIframeClick.mjs +0 -21
- package/dist/esm/mergeIframeClick.mjs.map +0 -1
- package/dist/types/components/EditedContent.d.ts +0 -49
- package/dist/types/components/EditedContent.d.ts.map +0 -1
- package/dist/types/components/IntlayerEditor.d.ts +0 -44
- package/dist/types/components/IntlayerEditor.d.ts.map +0 -1
- package/dist/types/core/editedContentBus.d.ts +0 -7
- package/dist/types/core/editedContentBus.d.ts.map +0 -1
- package/dist/types/core/focusedContentBus.d.ts +0 -7
- package/dist/types/core/focusedContentBus.d.ts.map +0 -1
- package/dist/types/mergeIframeClick.d.ts +0 -4
- package/dist/types/mergeIframeClick.d.ts.map +0 -1
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { MessageKey } from "../messageKey.mjs";
|
|
2
|
-
import { mergeIframeClick } from "../mergeIframeClick.mjs";
|
|
3
2
|
|
|
4
3
|
//#region src/core/IframeClickInterceptor.ts
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
* Replays a click made inside the iframe on the editor window, so the editor's
|
|
6
|
+
* "click outside" handlers (popovers, drawers) react to it.
|
|
7
|
+
*/
|
|
8
|
+
const replayIframeClick = () => {
|
|
9
|
+
for (const eventType of ["mousedown", "click"]) window.dispatchEvent(new MouseEvent(eventType, {
|
|
10
|
+
bubbles: true,
|
|
11
|
+
cancelable: true,
|
|
12
|
+
view: window
|
|
13
|
+
}));
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Forwards clicks across the iframe boundary.
|
|
10
17
|
*
|
|
11
|
-
*
|
|
18
|
+
* - startInterceptor(): client (iframe) side — reports each mousedown to the editor
|
|
19
|
+
* - startMerger(): editor (parent) side — replays reported clicks on its window
|
|
12
20
|
*/
|
|
13
21
|
var IframeClickInterceptor = class {
|
|
14
22
|
_messenger;
|
|
@@ -17,7 +25,6 @@ var IframeClickInterceptor = class {
|
|
|
17
25
|
constructor(messenger) {
|
|
18
26
|
this._messenger = messenger;
|
|
19
27
|
}
|
|
20
|
-
/** Called on the client side (inside iframe). Broadcasts click events to parent. */
|
|
21
28
|
startInterceptor() {
|
|
22
29
|
if (typeof window === "undefined") return;
|
|
23
30
|
this._mousedownHandler = () => {
|
|
@@ -25,9 +32,8 @@ var IframeClickInterceptor = class {
|
|
|
25
32
|
};
|
|
26
33
|
window.addEventListener("mousedown", this._mousedownHandler);
|
|
27
34
|
}
|
|
28
|
-
/** Called on the editor side (parent frame). Merges incoming iframe clicks into DOM. */
|
|
29
35
|
startMerger() {
|
|
30
|
-
this._unsubscribeMerge = this._messenger.subscribe("INTLAYER_IFRAME_CLICKED",
|
|
36
|
+
this._unsubscribeMerge = this._messenger.subscribe("INTLAYER_IFRAME_CLICKED", replayIframeClick);
|
|
31
37
|
}
|
|
32
38
|
stopInterceptor() {
|
|
33
39
|
if (this._mousedownHandler) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeClickInterceptor.mjs","names":[],"sources":["../../../src/core/IframeClickInterceptor.ts"],"sourcesContent":["import {
|
|
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"}
|
package/dist/esm/core/index.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { getGlobalEditorManager, onGlobalEditorManagerChange, setGlobalEditorManager } from "./globalManager.mjs";
|
|
2
2
|
import { CrossFrameMessenger } from "./CrossFrameMessenger.mjs";
|
|
3
3
|
import { CrossFrameStateManager } from "./CrossFrameStateManager.mjs";
|
|
4
|
-
import { getGlobalEditedContent, setGlobalEditedContent, subscribeToGlobalEditedContent } from "./editedContentBus.mjs";
|
|
5
|
-
import { getGlobalFocusedContent, setGlobalFocusedContent, subscribeToGlobalFocusedContent } from "./focusedContentBus.mjs";
|
|
6
4
|
import { IframeClickInterceptor } from "./IframeClickInterceptor.mjs";
|
|
5
|
+
import { createSharedWindowState } from "./sharedWindowState.mjs";
|
|
7
6
|
import { UrlStateManager } from "./UrlStateManager.mjs";
|
|
8
7
|
import { EditorStateManager } from "./EditorStateManager.mjs";
|
|
9
|
-
import {
|
|
8
|
+
import { initEditorClient, stopEditorClient } from "./initEditorClient.mjs";
|
|
10
9
|
|
|
11
|
-
export { CrossFrameMessenger, CrossFrameStateManager, EditorStateManager, IframeClickInterceptor, UrlStateManager,
|
|
10
|
+
export { CrossFrameMessenger, CrossFrameStateManager, EditorStateManager, IframeClickInterceptor, UrlStateManager, createSharedWindowState, getGlobalEditorManager, initEditorClient, onGlobalEditorManagerChange, setGlobalEditorManager, stopEditorClient };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getGlobalEditorManager, setGlobalEditorManager } from "./globalManager.mjs";
|
|
2
|
-
import { EditorStateManager } from "./EditorStateManager.mjs";
|
|
3
2
|
import { defineIntlayerElements } from "../components/ContentSelector.mjs";
|
|
3
|
+
import { EditorStateManager } from "./EditorStateManager.mjs";
|
|
4
4
|
import { editor } from "@intlayer/config/built";
|
|
5
5
|
|
|
6
6
|
//#region src/core/initEditorClient.ts
|
|
@@ -53,5 +53,5 @@ const stopEditorClient = () => {
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
//#endregion
|
|
56
|
-
export {
|
|
56
|
+
export { initEditorClient, stopEditorClient };
|
|
57
57
|
//# sourceMappingURL=initEditorClient.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initEditorClient.mjs","names":[],"sources":["../../../src/core/initEditorClient.ts"],"sourcesContent":["import { editor
|
|
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"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/core/sharedWindowState.ts
|
|
2
|
+
/**
|
|
3
|
+
* A value shared by every EditorStateManager of the same window — the
|
|
4
|
+
* dashboard mounts several editor providers that must agree on edits and focus.
|
|
5
|
+
* Stored on `window` so duplicated copies of this package share it too.
|
|
6
|
+
*/
|
|
7
|
+
const createSharedWindowState = (name) => {
|
|
8
|
+
const storeKey = `__intlayer_shared_${name}__`;
|
|
9
|
+
const getStore = () => {
|
|
10
|
+
const emptyStore = {
|
|
11
|
+
isSet: false,
|
|
12
|
+
value: void 0,
|
|
13
|
+
eventTarget: new EventTarget()
|
|
14
|
+
};
|
|
15
|
+
if (typeof window === "undefined") return emptyStore;
|
|
16
|
+
const windowStores = window;
|
|
17
|
+
windowStores[storeKey] ??= emptyStore;
|
|
18
|
+
return windowStores[storeKey];
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
get: () => {
|
|
22
|
+
const store = getStore();
|
|
23
|
+
return store.isSet ? store.value : void 0;
|
|
24
|
+
},
|
|
25
|
+
set: (value, sourceId) => {
|
|
26
|
+
const store = getStore();
|
|
27
|
+
store.isSet = true;
|
|
28
|
+
store.value = value;
|
|
29
|
+
store.eventTarget.dispatchEvent(new CustomEvent("change", { detail: {
|
|
30
|
+
value,
|
|
31
|
+
sourceId
|
|
32
|
+
} }));
|
|
33
|
+
},
|
|
34
|
+
subscribe: (listener) => {
|
|
35
|
+
const { eventTarget } = getStore();
|
|
36
|
+
const handleChange = (event) => {
|
|
37
|
+
const { value, sourceId } = event.detail;
|
|
38
|
+
listener(value, sourceId);
|
|
39
|
+
};
|
|
40
|
+
eventTarget.addEventListener("change", handleChange);
|
|
41
|
+
return () => eventTarget.removeEventListener("change", handleChange);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { createSharedWindowState };
|
|
48
|
+
//# sourceMappingURL=sharedWindowState.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharedWindowState.mjs","names":[],"sources":["../../../src/core/sharedWindowState.ts"],"sourcesContent":["type SharedWindowStateStore<T> = {\n isSet: boolean;\n value: T | undefined;\n eventTarget: EventTarget;\n};\n\ntype SharedWindowStateChange<T> = { value: T; sourceId?: string };\n\ntype SharedWindowStateListener<T> = (value: T, sourceId?: string) => void;\n\nexport type SharedWindowState<T> = {\n /** Last published value, `undefined` until one is published */\n get: () => T | undefined;\n /** Publishes a value, tagged with the id of the manager publishing it */\n set: (value: T, sourceId?: string) => void;\n /** Returns an unsubscribe function */\n subscribe: (listener: SharedWindowStateListener<T>) => () => void;\n};\n\n/**\n * A value shared by every EditorStateManager of the same window — the\n * dashboard mounts several editor providers that must agree on edits and focus.\n * Stored on `window` so duplicated copies of this package share it too.\n */\nexport const createSharedWindowState = <T>(\n name: string\n): SharedWindowState<T> => {\n const storeKey = `__intlayer_shared_${name}__`;\n\n const getStore = (): SharedWindowStateStore<T> => {\n const emptyStore: SharedWindowStateStore<T> = {\n isSet: false,\n value: undefined,\n eventTarget: new EventTarget(),\n };\n\n // Server side: nothing to share\n if (typeof window === 'undefined') return emptyStore;\n\n const windowStores = window as unknown as Record<\n string,\n SharedWindowStateStore<T> | undefined\n >;\n windowStores[storeKey] ??= emptyStore;\n\n return windowStores[storeKey];\n };\n\n return {\n get: () => {\n const store = getStore();\n\n return store.isSet ? store.value : undefined;\n },\n set: (value, sourceId) => {\n const store = getStore();\n store.isSet = true;\n store.value = value;\n store.eventTarget.dispatchEvent(\n new CustomEvent<SharedWindowStateChange<T>>('change', {\n detail: { value, sourceId },\n })\n );\n },\n subscribe: (listener) => {\n const { eventTarget } = getStore();\n const handleChange = (event: Event) => {\n const { value, sourceId } = (\n event as CustomEvent<SharedWindowStateChange<T>>\n ).detail;\n listener(value, sourceId);\n };\n\n eventTarget.addEventListener('change', handleChange);\n\n return () => eventTarget.removeEventListener('change', handleChange);\n },\n };\n};\n"],"mappings":";;;;;;AAwBA,MAAa,2BACX,SACyB;CACzB,MAAM,WAAW,qBAAqB,KAAK;CAE3C,MAAM,iBAA4C;EAChD,MAAM,aAAwC;GAC5C,OAAO;GACP,OAAO;GACP,aAAa,IAAI,YAAY;EAC/B;EAGA,IAAI,OAAO,WAAW,aAAa,OAAO;EAE1C,MAAM,eAAe;EAIrB,aAAa,cAAc;EAE3B,OAAO,aAAa;CACtB;CAEA,OAAO;EACL,WAAW;GACT,MAAM,QAAQ,SAAS;GAEvB,OAAO,MAAM,QAAQ,MAAM,QAAQ;EACrC;EACA,MAAM,OAAO,aAAa;GACxB,MAAM,QAAQ,SAAS;GACvB,MAAM,QAAQ;GACd,MAAM,QAAQ;GACd,MAAM,YAAY,cAChB,IAAI,YAAwC,UAAU,EACpD,QAAQ;IAAE;IAAO;GAAS,EAC5B,CAAC,CACH;EACF;EACA,YAAY,aAAa;GACvB,MAAM,EAAE,gBAAgB,SAAS;GACjC,MAAM,gBAAgB,UAAiB;IACrC,MAAM,EAAE,OAAO,aACb,MACA;IACF,SAAS,OAAO,QAAQ;GAC1B;GAEA,YAAY,iBAAiB,UAAU,YAAY;GAEnD,aAAa,YAAY,oBAAoB,UAAU,YAAY;EACrE;CACF;AACF"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { MessageKey } from "./messageKey.mjs";
|
|
2
|
-
import { compareUrls } from "./compareUrls.mjs";
|
|
3
2
|
import { getGlobalEditorManager, onGlobalEditorManagerChange, setGlobalEditorManager } from "./core/globalManager.mjs";
|
|
4
3
|
import { IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper } from "./components/ContentSelectorWrapper.mjs";
|
|
5
|
-
import {
|
|
4
|
+
import { IntlayerContentSelectorElement, defineIntlayerElements } from "./components/ContentSelector.mjs";
|
|
6
5
|
import { CrossFrameMessenger } from "./core/CrossFrameMessenger.mjs";
|
|
7
6
|
import { CrossFrameStateManager } from "./core/CrossFrameStateManager.mjs";
|
|
8
|
-
import { getGlobalEditedContent, setGlobalEditedContent, subscribeToGlobalEditedContent } from "./core/editedContentBus.mjs";
|
|
9
|
-
import { getGlobalFocusedContent, setGlobalFocusedContent, subscribeToGlobalFocusedContent } from "./core/focusedContentBus.mjs";
|
|
10
|
-
import { mergeIframeClick } from "./mergeIframeClick.mjs";
|
|
11
7
|
import { IframeClickInterceptor } from "./core/IframeClickInterceptor.mjs";
|
|
8
|
+
import { createSharedWindowState } from "./core/sharedWindowState.mjs";
|
|
12
9
|
import { UrlStateManager } from "./core/UrlStateManager.mjs";
|
|
13
10
|
import { EditorStateManager } from "./core/EditorStateManager.mjs";
|
|
14
|
-
import {
|
|
15
|
-
import { IntlayerEditorElement, defineIntlayerEditorElement } from "./components/IntlayerEditor.mjs";
|
|
16
|
-
import { IntlayerContentSelectorElement, defineIntlayerElements } from "./components/ContentSelector.mjs";
|
|
11
|
+
import { initEditorClient, stopEditorClient } from "./core/initEditorClient.mjs";
|
|
17
12
|
|
|
18
|
-
export { CrossFrameMessenger, CrossFrameStateManager, EditorStateManager, IframeClickInterceptor, IntlayerContentSelectorElement, IntlayerContentSelectorWrapperElement,
|
|
13
|
+
export { CrossFrameMessenger, CrossFrameStateManager, EditorStateManager, IframeClickInterceptor, IntlayerContentSelectorElement, IntlayerContentSelectorWrapperElement, MessageKey, UrlStateManager, createSharedWindowState, defineIntlayerContentSelectorWrapper, defineIntlayerElements, getGlobalEditorManager, initEditorClient, onGlobalEditorManagerChange, setGlobalEditorManager, stopEditorClient };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelector.d.ts","names":[],"sources":["../../../src/components/ContentSelector.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"ContentSelector.d.ts","names":[],"sources":["../../../src/components/ContentSelector.ts"],"mappings":";cA0BM;UAAA;aAAA;;;;;;;;;;;;;;;;qBAmBO,uCAAuC;UAC1C;UACA;UACA;UACA;UACA;UACA;UACA;aAEG;MAIP;MAGA,YAAY;MAKZ;MAGA,cAAc;EAIlB;EA2BA,yBACE,cACA,wBACA;EAWF;EAYA;UAQQ;UAUA;UAOA;UAMA;UASA;UAMA;UASA;UAOA;;;;;;;qBAWG"}
|
|
@@ -27,24 +27,27 @@ export declare class IntlayerContentSelectorWrapperElement extends _HTMLElement
|
|
|
27
27
|
private _renderState;
|
|
28
28
|
private _selector;
|
|
29
29
|
private _unsubManager;
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
private _unsubEditedContent;
|
|
30
|
+
/** Removes the listeners attached to the current manager's states */
|
|
31
|
+
private _unsubManagerState;
|
|
33
32
|
static get observedAttributes(): string[];
|
|
34
|
-
get keyPathJson(): string;
|
|
35
|
-
set keyPathJson(v: string);
|
|
36
|
-
get dictionaryKey(): string;
|
|
37
|
-
set dictionaryKey(v: string);
|
|
38
33
|
constructor();
|
|
39
|
-
attributeChangedCallback(name: string,
|
|
34
|
+
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null): void;
|
|
40
35
|
connectedCallback(): void;
|
|
41
36
|
disconnectedCallback(): void;
|
|
42
|
-
private _teardown;
|
|
43
37
|
private _getRawKeyPath;
|
|
44
38
|
private _getFilteredKeyPath;
|
|
45
39
|
private _updateEditedValue;
|
|
46
40
|
private _updateIsSelected;
|
|
41
|
+
/**
|
|
42
|
+
* Scrolls the selected content to 30vh, unless it is already fully visible
|
|
43
|
+
* in this frame's viewport.
|
|
44
|
+
*/
|
|
47
45
|
private _scrollIntoViewIfNeeded;
|
|
46
|
+
/**
|
|
47
|
+
* Whether another element (a fixed navbar, a sticky header…) is painted over
|
|
48
|
+
* this content at the given viewport point.
|
|
49
|
+
*/
|
|
50
|
+
private _isCoveredAt;
|
|
48
51
|
private _updateSelectorAttr;
|
|
49
52
|
private _subscribeToManager;
|
|
50
53
|
private _setupManagerSubscriptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.d.ts","names":[],"sources":["../../../src/components/ContentSelectorWrapper.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"ContentSelectorWrapper.d.ts","names":[],"sources":["../../../src/components/ContentSelectorWrapper.ts"],"mappings":";cAuEM;UAAA;aAAA;;;;;;;;;;;;;;;;qBAmBO,8CAA8C;UACjD;UACA;UACA;UACA;UACA;UACA;UAEA;UACA;UAEA;;UAEA;aAEG;EAIX;EAQA,yBACE,cACA,0BACA;EAYF;EAQA;UAOQ;UAQA;UAMA;UAkDA;;;;;UA0BA;;;;;UA6BA;UAWA;UASA;UAoBA;UA8BA;UAWA;UAWA;UAQA;UA+BA;;qBAkCG"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { IntlayerContentSelectorElement, defineIntlayerElements } from "./ContentSelector.js";
|
|
2
2
|
import { IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper } from "./ContentSelectorWrapper.js";
|
|
3
|
-
|
|
4
|
-
import { IntlayerEditorElement, defineIntlayerEditorElement } from "./IntlayerEditor.js";
|
|
5
|
-
export { IntlayerContentSelectorElement, IntlayerContentSelectorWrapperElement, IntlayerEditedContentElement, IntlayerEditorElement, defineIntlayerContentSelectorWrapper, defineIntlayerEditedContent, defineIntlayerEditorElement, defineIntlayerElements };
|
|
3
|
+
export { IntlayerContentSelectorElement, IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper, defineIntlayerElements };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CrossFrameMessenger, MessengerConfig } from "./CrossFrameMessenger.js";
|
|
2
2
|
import { CrossFrameStateManager } from "./CrossFrameStateManager.js";
|
|
3
|
-
import { IntlayerConfig } from "@intlayer/types/config";
|
|
4
3
|
import { Locale } from "@intlayer/types/allLocales";
|
|
4
|
+
import { IntlayerConfig } from "@intlayer/types/config";
|
|
5
5
|
import { ContentNode, Dictionary, LocalDictionaryId } from "@intlayer/types/dictionary";
|
|
6
6
|
import { KeyPath } from "@intlayer/types/keyPath";
|
|
7
7
|
//#region src/core/EditorStateManager.d.ts
|
|
@@ -47,12 +47,7 @@ export declare class EditorStateManager {
|
|
|
47
47
|
private _displayedKeysObserver;
|
|
48
48
|
private _displayedKeysTimer;
|
|
49
49
|
private _displayedKeysListeners;
|
|
50
|
-
private
|
|
51
|
-
private _unsubGlobalEditedContent;
|
|
52
|
-
private _editedContentBusHandler;
|
|
53
|
-
private _focusedContentFromBus;
|
|
54
|
-
private _unsubGlobalFocusedContent;
|
|
55
|
-
private _focusedContentBusHandler;
|
|
50
|
+
private _stopSharedStateSyncs;
|
|
56
51
|
constructor(config: EditorStateManagerConfig);
|
|
57
52
|
start(): void;
|
|
58
53
|
stop(): void;
|
|
@@ -69,13 +64,12 @@ export declare class EditorStateManager {
|
|
|
69
64
|
renameContent(localDictionaryId: LocalDictionaryId, newKey: KeyPath['key'], keyPath?: KeyPath[]): void;
|
|
70
65
|
removeContent(localDictionaryId: LocalDictionaryId, keyPath: KeyPath[]): void;
|
|
71
66
|
restoreContent(localDictionaryId: LocalDictionaryId): void;
|
|
72
|
-
clearContent(localDictionaryId: LocalDictionaryId): void;
|
|
73
|
-
clearAllContent(): void;
|
|
74
67
|
getContentValue(localDictionaryIdOrKey: LocalDictionaryId | string, keyPath: KeyPath[]): ContentNode | undefined;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Mirrors a state with the managers of the same window, seeding it with the
|
|
70
|
+
* shared value when there is one. Returns a function stopping the sync.
|
|
71
|
+
*/
|
|
72
|
+
private _syncWithSharedState;
|
|
79
73
|
private _scanDisplayedDictionaryKeys;
|
|
80
74
|
private _startDisplayedDictionariesTracking;
|
|
81
75
|
private _stopDisplayedDictionariesTracking;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorStateManager.d.ts","names":[],"sources":["../../../src/core/EditorStateManager.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"EditorStateManager.d.ts","names":[],"sources":["../../../src/core/EditorStateManager.ts"],"mappings":";;;;;;;YA2BY,oBAAoB,OAAO,mBAAmB;KAErD,eAAe,KAAK;YAQb;EACV;EACA,oBAAoB;EACpB,UAAU;;YAGA;;EAEV;;EAEA,WAAW;;EAEX,gBAAgB;;;;;;;;;;qBAWL;WACF,WAAW;WACX,eAAe;WACf,gBAAgB,uBAAuB;WACvC,oBAAoB,uBAAuB;WAC3C,eAAe,uBAAuB;WACtC,eAAe,uBAAuB;WACtC,eAAe,uBAAuB;WACtC,yBAAyB;mBAEjB;mBACA;mBACA;mBACA;UAGT;UACA;UAEA;UAGA;UACA;UACA;UAGA;EAER,YAAY,QAAQ;EA+DpB;EAoCA;;;;;EA6BA;EAUA,yBAAyB,SAAS;EAalC,oBAAoB,YAAY;EAYhC,oBAAoB,SAAS;EAa7B,iBACE,mBAAmB,mBACnB,UAAU;EAaZ,WACE,mBAAmB,mBACnB,UAAU,aACV,UAAS,WACT;EAgDF,cACE,mBAAmB,mBACnB,QAAQ,gBACR,UAAS;EAmBX,cACE,mBAAmB,mBACnB,SAAS;EAwBX,eAAe,mBAAmB;EAOlC,gBACE,wBAAwB,4BACxB,SAAS,YACR;;;;;UA0DK;UAyCA;UAeA;UA8BA;;;;;UAmBA;UAcA;UAsBA;UA2BM"}
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import { CrossFrameMessenger } from "./CrossFrameMessenger.js";
|
|
2
2
|
//#region src/core/IframeClickInterceptor.d.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Forwards clicks across the iframe boundary.
|
|
5
5
|
*
|
|
6
|
-
* - startInterceptor():
|
|
7
|
-
* - startMerger():
|
|
8
|
-
*
|
|
9
|
-
* Replaces useIframeClickInterceptor / useIframeClickMerger across all frameworks.
|
|
6
|
+
* - startInterceptor(): client (iframe) side — reports each mousedown to the editor
|
|
7
|
+
* - startMerger(): editor (parent) side — replays reported clicks on its window
|
|
10
8
|
*/
|
|
11
9
|
export declare class IframeClickInterceptor {
|
|
12
10
|
private readonly _messenger;
|
|
13
11
|
private _mousedownHandler;
|
|
14
12
|
private _unsubscribeMerge;
|
|
15
13
|
constructor(messenger: CrossFrameMessenger);
|
|
16
|
-
/** Called on the client side (inside iframe). Broadcasts click events to parent. */
|
|
17
14
|
startInterceptor(): void;
|
|
18
|
-
/** Called on the editor side (parent frame). Merges incoming iframe clicks into DOM. */
|
|
19
15
|
startMerger(): void;
|
|
20
16
|
stopInterceptor(): void;
|
|
21
17
|
stopMerger(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeClickInterceptor.d.ts","names":[],"sources":["../../../src/core/IframeClickInterceptor.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IframeClickInterceptor.d.ts","names":[],"sources":["../../../src/core/IframeClickInterceptor.ts"],"mappings":";;;;;;;;qBAyBa;mBACM;UACT;UACA;EAER,YAAY,WAAW;EAIvB;EAQA;EAOA;EAOA"}
|
|
@@ -3,8 +3,7 @@ import { CrossFrameStateAction, CrossFrameStateManager, CrossFrameStateOptions }
|
|
|
3
3
|
import { DictionaryContent, EditorStateManager, EditorStateManagerConfig, FileContent } from "./EditorStateManager.js";
|
|
4
4
|
import { IframeClickInterceptor } from "./IframeClickInterceptor.js";
|
|
5
5
|
import { UrlStateManager } from "./UrlStateManager.js";
|
|
6
|
-
import { getGlobalEditedContent, setGlobalEditedContent, subscribeToGlobalEditedContent } from "./editedContentBus.js";
|
|
7
|
-
import { getGlobalFocusedContent, setGlobalFocusedContent, subscribeToGlobalFocusedContent } from "./focusedContentBus.js";
|
|
8
6
|
import { getGlobalEditorManager, onGlobalEditorManagerChange, setGlobalEditorManager } from "./globalManager.js";
|
|
9
|
-
import {
|
|
10
|
-
|
|
7
|
+
import { initEditorClient, stopEditorClient } from "./initEditorClient.js";
|
|
8
|
+
import { SharedWindowState, createSharedWindowState } from "./sharedWindowState.js";
|
|
9
|
+
export { CrossFrameMessenger, CrossFrameStateAction, CrossFrameStateManager, CrossFrameStateOptions, DictionaryContent, EditorStateManager, EditorStateManagerConfig, FileContent, IframeClickInterceptor, MessagePayload, MessengerConfig, SharedWindowState, UrlStateManager, createSharedWindowState, getGlobalEditorManager, initEditorClient, onGlobalEditorManagerChange, setGlobalEditorManager, stopEditorClient };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { MessengerConfig } from "./CrossFrameMessenger.js";
|
|
2
1
|
import { EditorStateManager } from "./EditorStateManager.js";
|
|
3
2
|
//#region src/core/initEditorClient.d.ts
|
|
4
|
-
export declare const buildClientMessengerConfig: () => MessengerConfig;
|
|
5
3
|
/**
|
|
6
4
|
* Initialize the Intlayer editor client singleton.
|
|
7
5
|
* Safe to call multiple times — returns the existing manager if already initialized.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initEditorClient.d.ts","names":[],"sources":["../../../src/core/initEditorClient.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"initEditorClient.d.ts","names":[],"sources":["../../../src/core/initEditorClient.ts"],"mappings":";;;;;;;;qBA6Ca,wBAAuB;;;;;qBAuBvB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/core/sharedWindowState.d.ts
|
|
2
|
+
type SharedWindowStateListener<T> = (value: T, sourceId?: string) => void;
|
|
3
|
+
export type SharedWindowState<T> = {
|
|
4
|
+
/** Last published value, `undefined` until one is published */
|
|
5
|
+
get: () => T | undefined;
|
|
6
|
+
/** Publishes a value, tagged with the id of the manager publishing it */
|
|
7
|
+
set: (value: T, sourceId?: string) => void;
|
|
8
|
+
/** Returns an unsubscribe function */
|
|
9
|
+
subscribe: (listener: SharedWindowStateListener<T>) => () => void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A value shared by every EditorStateManager of the same window — the
|
|
13
|
+
* dashboard mounts several editor providers that must agree on edits and focus.
|
|
14
|
+
* Stored on `window` so duplicated copies of this package share it too.
|
|
15
|
+
*/
|
|
16
|
+
export declare const createSharedWindowState: <T>(name: string) => SharedWindowState<T>;
|
|
17
|
+
//#endregion
|
|
18
|
+
//# sourceMappingURL=sharedWindowState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharedWindowState.d.ts","names":[],"sources":["../../../src/core/sharedWindowState.ts"],"mappings":";KAQK,0BAA0B,MAAM,OAAO,GAAG;YAEnC,kBAAkB;;EAE5B,WAAW;;EAEX,MAAM,OAAO,GAAG;;EAEhB,YAAY,UAAU,0BAA0B;;;;;;;qBAQrC,0BAA2B,GAAC,iBAEtC,kBAAkB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import { compareUrls } from "./compareUrls.js";
|
|
2
1
|
import { IntlayerContentSelectorElement, defineIntlayerElements } from "./components/ContentSelector.js";
|
|
3
2
|
import { IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper } from "./components/ContentSelectorWrapper.js";
|
|
4
|
-
import { IntlayerEditedContentElement, defineIntlayerEditedContent } from "./components/EditedContent.js";
|
|
5
|
-
import { IntlayerEditorElement, defineIntlayerEditorElement } from "./components/IntlayerEditor.js";
|
|
6
|
-
import "./components/index.js";
|
|
7
3
|
import { CrossFrameMessenger, MessagePayload, MessengerConfig } from "./core/CrossFrameMessenger.js";
|
|
8
4
|
import { CrossFrameStateAction, CrossFrameStateManager, CrossFrameStateOptions } from "./core/CrossFrameStateManager.js";
|
|
9
5
|
import { DictionaryContent, EditorStateManager, EditorStateManagerConfig, FileContent } from "./core/EditorStateManager.js";
|
|
10
6
|
import { IframeClickInterceptor } from "./core/IframeClickInterceptor.js";
|
|
11
7
|
import { UrlStateManager } from "./core/UrlStateManager.js";
|
|
12
|
-
import { getGlobalEditedContent, setGlobalEditedContent, subscribeToGlobalEditedContent } from "./core/editedContentBus.js";
|
|
13
|
-
import { getGlobalFocusedContent, setGlobalFocusedContent, subscribeToGlobalFocusedContent } from "./core/focusedContentBus.js";
|
|
14
8
|
import { getGlobalEditorManager, onGlobalEditorManagerChange, setGlobalEditorManager } from "./core/globalManager.js";
|
|
15
|
-
import {
|
|
9
|
+
import { initEditorClient, stopEditorClient } from "./core/initEditorClient.js";
|
|
10
|
+
import { SharedWindowState, createSharedWindowState } from "./core/sharedWindowState.js";
|
|
16
11
|
import "./core/index.js";
|
|
17
|
-
import { mergeIframeClick } from "./mergeIframeClick.js";
|
|
18
12
|
import { MessageKey } from "./messageKey.js";
|
|
19
|
-
export { CrossFrameMessenger, CrossFrameStateAction, CrossFrameStateManager, CrossFrameStateOptions, DictionaryContent, EditorStateManager, EditorStateManagerConfig, FileContent, IframeClickInterceptor, IntlayerContentSelectorElement, IntlayerContentSelectorWrapperElement,
|
|
13
|
+
export { CrossFrameMessenger, CrossFrameStateAction, CrossFrameStateManager, CrossFrameStateOptions, DictionaryContent, EditorStateManager, EditorStateManagerConfig, FileContent, IframeClickInterceptor, IntlayerContentSelectorElement, IntlayerContentSelectorWrapperElement, MessageKey, MessagePayload, MessengerConfig, SharedWindowState, UrlStateManager, createSharedWindowState, defineIntlayerContentSelectorWrapper, defineIntlayerElements, getGlobalEditorManager, initEditorClient, onGlobalEditorManagerChange, setGlobalEditorManager, stopEditorClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/editor",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.12",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Provides the utilities to interface the application with the Intlayer editor and manipulate dictionaries",
|
|
6
6
|
"keywords": [
|
|
@@ -76,10 +76,10 @@
|
|
|
76
76
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@intlayer/config": "9.5.
|
|
80
|
-
"@intlayer/core": "9.5.
|
|
81
|
-
"@intlayer/dictionaries-entry": "9.5.
|
|
82
|
-
"@intlayer/types": "9.5.
|
|
79
|
+
"@intlayer/config": "9.5.12",
|
|
80
|
+
"@intlayer/core": "9.5.12",
|
|
81
|
+
"@intlayer/dictionaries-entry": "9.5.12",
|
|
82
|
+
"@intlayer/types": "9.5.12"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@types/node": "^22",
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_core_globalManager = require('../core/globalManager.cjs');
|
|
3
|
-
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
4
|
-
|
|
5
|
-
//#region src/components/EditedContent.ts
|
|
6
|
-
const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
|
|
7
|
-
/**
|
|
8
|
-
* <intlayer-edited-content>
|
|
9
|
-
*
|
|
10
|
-
* Framework-agnostic web component that displays edited content from the Intlayer
|
|
11
|
-
* editor. When the editor has an edited value for the given dictionary key and
|
|
12
|
-
* key path, it renders the edited value; otherwise it renders the original
|
|
13
|
-
* content via a slot.
|
|
14
|
-
*
|
|
15
|
-
* Always wraps content in <intlayer-content-selector-wrapper> for selection UI.
|
|
16
|
-
*
|
|
17
|
-
* @attr {string} dictionary-key - The dictionary key owning this content node
|
|
18
|
-
* @attr {string} key-path - JSON-serialized KeyPath[] for this content node
|
|
19
|
-
* @attr {string} locale - The current locale string
|
|
20
|
-
*/
|
|
21
|
-
var IntlayerEditedContentElement = class extends _HTMLElement {
|
|
22
|
-
_dictionaryKey = "";
|
|
23
|
-
_keyPathJson = "[]";
|
|
24
|
-
_locale = "";
|
|
25
|
-
_editedText = null;
|
|
26
|
-
_unsubManager = null;
|
|
27
|
-
_unsubEditedContent = null;
|
|
28
|
-
_selectorWrapper;
|
|
29
|
-
_slot;
|
|
30
|
-
static get observedAttributes() {
|
|
31
|
-
return [
|
|
32
|
-
"dictionary-key",
|
|
33
|
-
"key-path",
|
|
34
|
-
"locale"
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
get dictionaryKey() {
|
|
38
|
-
return this._dictionaryKey;
|
|
39
|
-
}
|
|
40
|
-
set dictionaryKey(v) {
|
|
41
|
-
this._dictionaryKey = v;
|
|
42
|
-
this._selectorWrapper.setAttribute("dictionary-key", v);
|
|
43
|
-
}
|
|
44
|
-
get keyPathJson() {
|
|
45
|
-
return this._keyPathJson;
|
|
46
|
-
}
|
|
47
|
-
set keyPathJson(v) {
|
|
48
|
-
this._keyPathJson = v;
|
|
49
|
-
this._selectorWrapper.setAttribute("key-path", v);
|
|
50
|
-
}
|
|
51
|
-
get locale() {
|
|
52
|
-
return this._locale;
|
|
53
|
-
}
|
|
54
|
-
set locale(v) {
|
|
55
|
-
this._locale = v;
|
|
56
|
-
}
|
|
57
|
-
constructor() {
|
|
58
|
-
super();
|
|
59
|
-
const shadow = this.attachShadow({ mode: "open" });
|
|
60
|
-
const style = document.createElement("style");
|
|
61
|
-
style.textContent = ":host { display: contents; }";
|
|
62
|
-
shadow.appendChild(style);
|
|
63
|
-
this._selectorWrapper = document.createElement("intlayer-content-selector-wrapper");
|
|
64
|
-
this._slot = document.createElement("slot");
|
|
65
|
-
this._selectorWrapper.appendChild(this._slot);
|
|
66
|
-
shadow.appendChild(this._selectorWrapper);
|
|
67
|
-
}
|
|
68
|
-
attributeChangedCallback(name, _oldVal, newVal) {
|
|
69
|
-
const val = newVal ?? "";
|
|
70
|
-
if (name === "dictionary-key") {
|
|
71
|
-
this._dictionaryKey = val;
|
|
72
|
-
this._selectorWrapper.setAttribute("dictionary-key", val);
|
|
73
|
-
} else if (name === "key-path") {
|
|
74
|
-
this._keyPathJson = val || "[]";
|
|
75
|
-
this._selectorWrapper.setAttribute("key-path", this._keyPathJson);
|
|
76
|
-
} else if (name === "locale") this._locale = val;
|
|
77
|
-
}
|
|
78
|
-
connectedCallback() {
|
|
79
|
-
this._subscribeToManager();
|
|
80
|
-
}
|
|
81
|
-
disconnectedCallback() {
|
|
82
|
-
this._teardown();
|
|
83
|
-
}
|
|
84
|
-
_teardown() {
|
|
85
|
-
this._unsubManager?.();
|
|
86
|
-
this._unsubEditedContent?.();
|
|
87
|
-
this._unsubManager = null;
|
|
88
|
-
this._unsubEditedContent = null;
|
|
89
|
-
}
|
|
90
|
-
_getKeyPath() {
|
|
91
|
-
try {
|
|
92
|
-
return JSON.parse(this._keyPathJson);
|
|
93
|
-
} catch {
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
_render() {
|
|
98
|
-
while (this._selectorWrapper.firstChild) this._selectorWrapper.removeChild(this._selectorWrapper.firstChild);
|
|
99
|
-
if (this._editedText !== null) this._selectorWrapper.appendChild(document.createTextNode(this._editedText));
|
|
100
|
-
else this._selectorWrapper.appendChild(this._slot);
|
|
101
|
-
}
|
|
102
|
-
_resolveEditedText(manager) {
|
|
103
|
-
const keyPath = this._getKeyPath();
|
|
104
|
-
const editedValue = manager.getContentValue(this._dictionaryKey, keyPath);
|
|
105
|
-
if (editedValue === void 0 || editedValue === null) {
|
|
106
|
-
this._editedText = null;
|
|
107
|
-
this._render();
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (typeof editedValue === "string" || typeof editedValue === "number") {
|
|
111
|
-
this._editedText = String(editedValue);
|
|
112
|
-
this._render();
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (typeof editedValue === "object") {
|
|
116
|
-
const locale = this._locale || void 0;
|
|
117
|
-
const transformed = (0, _intlayer_core_interpreter.getContent)(editedValue, {
|
|
118
|
-
locale,
|
|
119
|
-
dictionaryKey: this._dictionaryKey,
|
|
120
|
-
keyPath
|
|
121
|
-
}, (0, _intlayer_core_interpreter.getBasePlugins)(locale));
|
|
122
|
-
if (typeof transformed === "string" || typeof transformed === "number") this._editedText = String(transformed);
|
|
123
|
-
else {
|
|
124
|
-
console.error(`[intlayer-edited-content] Incorrect edited content format. Expected string. Value: ${JSON.stringify(transformed)}`);
|
|
125
|
-
this._editedText = null;
|
|
126
|
-
}
|
|
127
|
-
this._render();
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
this._editedText = null;
|
|
131
|
-
this._render();
|
|
132
|
-
}
|
|
133
|
-
_setupManagerSubscriptions(manager) {
|
|
134
|
-
this._resolveEditedText(manager);
|
|
135
|
-
const handleChange = () => this._resolveEditedText(manager);
|
|
136
|
-
manager.editedContent.addEventListener("change", handleChange);
|
|
137
|
-
this._unsubEditedContent = () => manager.editedContent.removeEventListener("change", handleChange);
|
|
138
|
-
}
|
|
139
|
-
_subscribeToManager() {
|
|
140
|
-
const manager = require_core_globalManager.getGlobalEditorManager();
|
|
141
|
-
if (manager) this._setupManagerSubscriptions(manager);
|
|
142
|
-
this._unsubManager = require_core_globalManager.onGlobalEditorManagerChange((m) => {
|
|
143
|
-
this._unsubEditedContent?.();
|
|
144
|
-
this._unsubEditedContent = null;
|
|
145
|
-
if (m) this._setupManagerSubscriptions(m);
|
|
146
|
-
else {
|
|
147
|
-
this._editedText = null;
|
|
148
|
-
this._render();
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const defineIntlayerEditedContent = () => {
|
|
154
|
-
if (typeof customElements === "undefined") return;
|
|
155
|
-
if (!customElements.get("intlayer-edited-content")) customElements.define("intlayer-edited-content", IntlayerEditedContentElement);
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
//#endregion
|
|
159
|
-
exports.IntlayerEditedContentElement = IntlayerEditedContentElement;
|
|
160
|
-
exports.defineIntlayerEditedContent = defineIntlayerEditedContent;
|
|
161
|
-
//# sourceMappingURL=EditedContent.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContent.cjs","names":["getContent","getBasePlugins","getGlobalEditorManager","onGlobalEditorManagerChange"],"sources":["../../../src/components/EditedContent.ts"],"sourcesContent":["import { getBasePlugins, getContent } from '@intlayer/core/interpreter';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { EditorStateManager } from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-edited-content>\n *\n * Framework-agnostic web component that displays edited content from the Intlayer\n * editor. When the editor has an edited value for the given dictionary key and\n * key path, it renders the edited value; otherwise it renders the original\n * content via a slot.\n *\n * Always wraps content in <intlayer-content-selector-wrapper> for selection UI.\n *\n * @attr {string} dictionary-key - The dictionary key owning this content node\n * @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n * @attr {string} locale - The current locale string\n */\nexport class IntlayerEditedContentElement extends _HTMLElement {\n private _dictionaryKey = '';\n private _keyPathJson = '[]';\n private _locale = '';\n private _editedText: string | null = null;\n\n private _unsubManager: (() => void) | null = null;\n private _unsubEditedContent: (() => void) | null = null;\n\n private _selectorWrapper: HTMLElement;\n private _slot: HTMLSlotElement;\n\n static get observedAttributes(): string[] {\n return ['dictionary-key', 'key-path', 'locale'];\n }\n\n get dictionaryKey(): string {\n return this._dictionaryKey;\n }\n set dictionaryKey(v: string) {\n this._dictionaryKey = v;\n this._selectorWrapper.setAttribute('dictionary-key', v);\n }\n\n get keyPathJson(): string {\n return this._keyPathJson;\n }\n set keyPathJson(v: string) {\n this._keyPathJson = v;\n this._selectorWrapper.setAttribute('key-path', v);\n }\n\n get locale(): string {\n return this._locale;\n }\n set locale(v: string) {\n this._locale = v;\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n\n const style = document.createElement('style');\n style.textContent = ':host { display: contents; }';\n shadow.appendChild(style);\n\n this._selectorWrapper = document.createElement(\n 'intlayer-content-selector-wrapper'\n );\n this._slot = document.createElement('slot') as HTMLSlotElement;\n this._selectorWrapper.appendChild(this._slot);\n shadow.appendChild(this._selectorWrapper);\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n const val = newVal ?? '';\n if (name === 'dictionary-key') {\n this._dictionaryKey = val;\n this._selectorWrapper.setAttribute('dictionary-key', val);\n } else if (name === 'key-path') {\n this._keyPathJson = val || '[]';\n this._selectorWrapper.setAttribute('key-path', this._keyPathJson);\n } else if (name === 'locale') {\n this._locale = val;\n }\n }\n\n connectedCallback(): void {\n this._subscribeToManager();\n }\n\n disconnectedCallback(): void {\n this._teardown();\n }\n\n private _teardown(): void {\n this._unsubManager?.();\n this._unsubEditedContent?.();\n this._unsubManager = null;\n this._unsubEditedContent = null;\n }\n\n private _getKeyPath(): KeyPath[] {\n try {\n return JSON.parse(this._keyPathJson);\n } catch {\n return [];\n }\n }\n\n private _render(): void {\n while (this._selectorWrapper.firstChild) {\n this._selectorWrapper.removeChild(this._selectorWrapper.firstChild);\n }\n if (this._editedText !== null) {\n this._selectorWrapper.appendChild(\n document.createTextNode(this._editedText)\n );\n } else {\n this._selectorWrapper.appendChild(this._slot);\n }\n }\n\n private _resolveEditedText(manager: EditorStateManager): void {\n const keyPath = this._getKeyPath();\n const editedValue = manager.getContentValue(this._dictionaryKey, keyPath);\n\n if (editedValue === undefined || editedValue === null) {\n this._editedText = null;\n this._render();\n return;\n }\n\n if (typeof editedValue === 'string' || typeof editedValue === 'number') {\n this._editedText = String(editedValue);\n this._render();\n return;\n }\n\n if (typeof editedValue === 'object') {\n const locale = this._locale || undefined;\n const transformed = getContent(\n editedValue,\n {\n locale: locale as any,\n dictionaryKey: this._dictionaryKey,\n keyPath,\n },\n getBasePlugins(locale)\n );\n if (typeof transformed === 'string' || typeof transformed === 'number') {\n this._editedText = String(transformed);\n } else {\n console.error(\n `[intlayer-edited-content] Incorrect edited content format. Expected string. Value: ${JSON.stringify(transformed)}`\n );\n this._editedText = null;\n }\n this._render();\n return;\n }\n\n this._editedText = null;\n this._render();\n }\n\n private _setupManagerSubscriptions(manager: EditorStateManager): void {\n this._resolveEditedText(manager);\n\n const handleChange = () => this._resolveEditedText(manager);\n manager.editedContent.addEventListener('change', handleChange);\n\n this._unsubEditedContent = () =>\n manager.editedContent.removeEventListener('change', handleChange);\n }\n\n private _subscribeToManager(): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n this._setupManagerSubscriptions(manager);\n }\n\n this._unsubManager = onGlobalEditorManagerChange((m) => {\n this._unsubEditedContent?.();\n this._unsubEditedContent = null;\n if (m) {\n this._setupManagerSubscriptions(m);\n } else {\n this._editedText = null;\n this._render();\n }\n });\n }\n}\n\nexport const defineIntlayerEditedContent = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-edited-content')) {\n customElements.define(\n 'intlayer-edited-content',\n IntlayerEditedContentElement\n );\n }\n};\n"],"mappings":"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"}
|