@intlayer/editor-react 5.1.6 → 5.1.7
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/EditedContentContext.cjs +14 -11
- package/dist/cjs/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/EditorEnabledContext.cjs +16 -12
- package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/EditorProvider.cjs +29 -3
- package/dist/cjs/EditorProvider.cjs.map +1 -1
- package/dist/cjs/useCrossFrameMessageListener.cjs +6 -9
- package/dist/cjs/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/useCrossFrameState.cjs +28 -31
- package/dist/cjs/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/useCrossURLPathState.cjs +9 -7
- package/dist/cjs/useCrossURLPathState.cjs.map +1 -1
- package/dist/esm/EditedContentContext.mjs +12 -10
- package/dist/esm/EditedContentContext.mjs.map +1 -1
- package/dist/esm/EditorEnabledContext.mjs +13 -11
- package/dist/esm/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/EditorProvider.mjs +38 -5
- package/dist/esm/EditorProvider.mjs.map +1 -1
- package/dist/esm/useCrossFrameMessageListener.mjs +7 -10
- package/dist/esm/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/useCrossFrameState.mjs +29 -37
- package/dist/esm/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/useCrossURLPathState.mjs +8 -7
- package/dist/esm/useCrossURLPathState.mjs.map +1 -1
- package/dist/types/ConfigurationContext.d.ts +1 -1
- package/dist/types/ConfigurationContext.d.ts.map +1 -1
- package/dist/types/EditedContentContext.d.ts +2 -2
- package/dist/types/EditedContentContext.d.ts.map +1 -1
- package/dist/types/EditorEnabledContext.d.ts +3 -1
- package/dist/types/EditorEnabledContext.d.ts.map +1 -1
- package/dist/types/EditorProvider.d.ts +1 -3
- package/dist/types/EditorProvider.d.ts.map +1 -1
- package/dist/types/useCrossFrameMessageListener.d.ts +4 -3
- package/dist/types/useCrossFrameMessageListener.d.ts.map +1 -1
- package/dist/types/useCrossFrameState.d.ts +1 -1
- package/dist/types/useCrossFrameState.d.ts.map +1 -1
- package/dist/types/useCrossURLPathState.d.ts +2 -1
- package/dist/types/useCrossURLPathState.d.ts.map +1 -1
- package/dist/types/useIframeClickCommunicator.d.ts +1 -1
- package/dist/types/useIframeClickCommunicator.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -7,10 +7,16 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
useCrossFrameState
|
|
9
9
|
} from "./useCrossFrameState.mjs";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs";
|
|
11
|
+
const EditorEnabledContext = createContext({
|
|
12
|
+
enabled: false
|
|
13
|
+
});
|
|
13
14
|
const useEditorEnabledState = (options) => useCrossFrameState("INTLAYER_EDITOR_ENABLED", false, options);
|
|
15
|
+
const usePostEditorEnabledState = (onEventTriggered) => useCrossFrameMessageListener(
|
|
16
|
+
"INTLAYER_EDITOR_ENABLED/post",
|
|
17
|
+
onEventTriggered
|
|
18
|
+
);
|
|
19
|
+
const useGetEditorEnabledState = (onEventTriggered) => useCrossFrameMessageListener("INTLAYER_EDITOR_ENABLED/get", onEventTriggered);
|
|
14
20
|
const EditorEnabledProvider = ({ children }) => {
|
|
15
21
|
const [isEnabled] = useEditorEnabledState({
|
|
16
22
|
emit: false,
|
|
@@ -18,16 +24,12 @@ const EditorEnabledProvider = ({ children }) => {
|
|
|
18
24
|
});
|
|
19
25
|
return /* @__PURE__ */ jsx(EditorEnabledContext.Provider, { value: { enabled: isEnabled }, children });
|
|
20
26
|
};
|
|
21
|
-
const useEditorEnabled = () =>
|
|
22
|
-
const context = useContext(EditorEnabledContext);
|
|
23
|
-
if (!context) {
|
|
24
|
-
throw new Error("useEditorEnabled must be used within a EnabledProvider");
|
|
25
|
-
}
|
|
26
|
-
return context;
|
|
27
|
-
};
|
|
27
|
+
const useEditorEnabled = () => useContext(EditorEnabledContext);
|
|
28
28
|
export {
|
|
29
29
|
EditorEnabledProvider,
|
|
30
30
|
useEditorEnabled,
|
|
31
|
-
useEditorEnabledState
|
|
31
|
+
useEditorEnabledState,
|
|
32
|
+
useGetEditorEnabledState,
|
|
33
|
+
usePostEditorEnabledState
|
|
32
34
|
};
|
|
33
35
|
//# sourceMappingURL=EditorEnabledContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps
|
|
1
|
+
{"version":3,"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps>({\n enabled: false,\n});\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState('INTLAYER_EDITOR_ENABLED', false, options);\n\nexport const usePostEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n 'INTLAYER_EDITOR_ENABLED/post',\n onEventTriggered\n );\n\nexport const useGetEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener('INTLAYER_EDITOR_ENABLED/get', onEventTriggered);\n\nexport const EditorEnabledProvider: FC<PropsWithChildren> = ({ children }) => {\n const [isEnabled] = useEditorEnabledState({\n emit: false,\n receive: true,\n });\n\n return (\n <EditorEnabledContext.Provider value={{ enabled: isEnabled }}>\n {children}\n </EditorEnabledContext.Provider>\n );\n};\n\nexport const useEditorEnabled = () => useContext(EditorEnabledContext);\n"],"mappings":";AA6CI;AA3CJ;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EAEE;AAAA,OACK;AACP,SAAS,oCAAoC;AAM7C,MAAM,uBAAuB,cAAuC;AAAA,EAClE,SAAS;AACX,CAAC;AAEM,MAAM,wBAAwB,CAAC,YACpC,mBAAmB,2BAA2B,OAAO,OAAO;AAEvD,MAAM,4BAA4B,CACvC,qBAEA;AAAA,EACE;AAAA,EACA;AACF;AAEK,MAAM,2BAA2B,CACtC,qBAEA,6BAA6B,+BAA+B,gBAAgB;AAEvE,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,CAAC,SAAS,IAAI,sBAAsB;AAAA,IACxC,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AAED,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,SAAS,UAAU,GACxD,UACH;AAEJ;AAEO,MAAM,mBAAmB,MAAM,WAAW,oBAAoB;","names":[]}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
useEffect,
|
|
5
|
+
useState
|
|
6
|
+
} from "react";
|
|
3
7
|
import { ChangedContentProvider } from "./ChangedContentContext.mjs";
|
|
4
8
|
import {
|
|
5
9
|
CommunicatorProvider
|
|
@@ -8,21 +12,50 @@ import {
|
|
|
8
12
|
ConfigurationProvider
|
|
9
13
|
} from "./ConfigurationContext.mjs";
|
|
10
14
|
import { DictionariesRecordProvider } from "./DictionariesRecordContext.mjs";
|
|
11
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
EditedContentProvider,
|
|
17
|
+
useGetEditedContentState
|
|
18
|
+
} from "./EditedContentContext.mjs";
|
|
12
19
|
import {
|
|
13
20
|
EditorEnabledProvider,
|
|
14
|
-
useEditorEnabled
|
|
21
|
+
useEditorEnabled,
|
|
22
|
+
useGetEditorEnabledState
|
|
15
23
|
} from "./EditorEnabledContext.mjs";
|
|
16
24
|
import { FocusDictionaryProvider } from "./FocusDictionaryContext.mjs";
|
|
17
|
-
const
|
|
25
|
+
const EditorProvidersWrapper = ({ children }) => {
|
|
26
|
+
const getEditedContentState = useGetEditedContentState();
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
getEditedContentState();
|
|
29
|
+
}, []);
|
|
30
|
+
return /* @__PURE__ */ jsx(DictionariesRecordProvider, { children: /* @__PURE__ */ jsx(EditedContentProvider, { children: /* @__PURE__ */ jsx(FocusDictionaryProvider, { children }) }) });
|
|
31
|
+
};
|
|
32
|
+
const EditorEnabledCheckRenderer = ({
|
|
33
|
+
children,
|
|
34
|
+
fallback
|
|
35
|
+
}) => {
|
|
36
|
+
const getEditorEnabled = useGetEditorEnabledState();
|
|
18
37
|
const { enabled } = useEditorEnabled();
|
|
19
|
-
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (enabled) return;
|
|
40
|
+
getEditorEnabled();
|
|
41
|
+
}, [enabled]);
|
|
42
|
+
return enabled ? children : fallback;
|
|
43
|
+
};
|
|
44
|
+
const IframeCheckRenderer = ({
|
|
45
|
+
children,
|
|
46
|
+
fallback
|
|
47
|
+
}) => {
|
|
48
|
+
const [isInIframe, setIsInIframe] = useState(false);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
setIsInIframe(window.self !== window.top);
|
|
51
|
+
}, []);
|
|
52
|
+
return isInIframe ? children : fallback;
|
|
20
53
|
};
|
|
21
54
|
const EditorProvider = ({
|
|
22
55
|
children,
|
|
23
56
|
configuration,
|
|
24
57
|
...props
|
|
25
|
-
}) => /* @__PURE__ */ jsx(ChangedContentProvider, { children: /* @__PURE__ */ jsx(EditorEnabledProvider, { children: /* @__PURE__ */ jsx(ConfigurationProvider, { configuration, children: /* @__PURE__ */ jsx(
|
|
58
|
+
}) => /* @__PURE__ */ jsx(ChangedContentProvider, { children: /* @__PURE__ */ jsx(EditorEnabledProvider, { children: /* @__PURE__ */ jsx(ConfigurationProvider, { configuration, children: props.mode === "editor" ? /* @__PURE__ */ jsx(CommunicatorProvider, { ...props, children: /* @__PURE__ */ jsx(EditorProvidersWrapper, { children }) }) : /* @__PURE__ */ jsx(IframeCheckRenderer, { fallback: children, children: /* @__PURE__ */ jsx(CommunicatorProvider, { ...props, children: /* @__PURE__ */ jsx(EditorEnabledCheckRenderer, { fallback: children, children: /* @__PURE__ */ jsx(EditorProvidersWrapper, { children }) }) }) }) }) }) });
|
|
26
59
|
export {
|
|
27
60
|
EditorProvider
|
|
28
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n ReactNode,\n useEffect,\n useState,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport { ChangedContentProvider } from './ChangedContentContext';\nimport {\n type CommunicatorProviderProps,\n CommunicatorProvider,\n} from './CommunicatorContext';\nimport {\n type ConfigurationProviderProps,\n ConfigurationProvider,\n} from './ConfigurationContext';\nimport { DictionariesRecordProvider } from './DictionariesRecordContext';\nimport {\n EditedContentProvider,\n useGetEditedContentState,\n} from './EditedContentContext';\nimport {\n EditorEnabledProvider,\n useEditorEnabled,\n useGetEditorEnabledState,\n} from './EditorEnabledContext';\nimport { FocusDictionaryProvider } from './FocusDictionaryContext';\n\n/**\n * This component add all the providers needed by the editor.\n * It is used to wrap the application, or the editor to work together.\n */\nconst EditorProvidersWrapper: FC<PropsWithChildren> = ({ children }) => {\n const getEditedContentState = useGetEditedContentState();\n\n useEffect(() => {\n getEditedContentState();\n }, []);\n\n return (\n <DictionariesRecordProvider>\n <EditedContentProvider>\n <FocusDictionaryProvider>{children}</FocusDictionaryProvider>\n </EditedContentProvider>\n </DictionariesRecordProvider>\n );\n};\n\ntype FallbackProps = {\n fallback: ReactNode;\n};\n\n/**\n * This component check if the editor is enabled to render the editor providers.\n */\nconst EditorEnabledCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const getEditorEnabled = useGetEditorEnabledState();\n\n const { enabled } = useEditorEnabled();\n\n useEffect(() => {\n if (enabled) return;\n\n // Check if the editor is wrapping the application\n getEditorEnabled();\n }, [enabled]);\n\n return enabled ? children : fallback;\n};\n\n/**\n * This component is used to check if the editor is wrapping the application.\n * It avoid to send window.postMessage to the application if the editor is not wrapping the application.\n */\nconst IframeCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const [isInIframe, setIsInIframe] = useState(false);\n\n useEffect(() => {\n setIsInIframe(window.self !== window.top);\n }, []);\n\n return isInIframe ? children : fallback;\n};\n\nexport type EditorProviderProps = CommunicatorProviderProps &\n ConfigurationProviderProps & {\n mode: 'editor' | 'client';\n };\n\nexport const EditorProvider: FC<PropsWithChildren<EditorProviderProps>> = ({\n children,\n configuration,\n ...props\n}) => (\n <ChangedContentProvider>\n <EditorEnabledProvider>\n <ConfigurationProvider configuration={configuration}>\n {props.mode === 'editor' ? (\n <CommunicatorProvider {...props}>\n <EditorProvidersWrapper>{children}</EditorProvidersWrapper>\n </CommunicatorProvider>\n ) : (\n <IframeCheckRenderer fallback={children}>\n <CommunicatorProvider {...props}>\n <EditorEnabledCheckRenderer fallback={children}>\n <EditorProvidersWrapper>{children}</EditorProvidersWrapper>\n </EditorEnabledCheckRenderer>\n </CommunicatorProvider>\n </IframeCheckRenderer>\n )}\n </ConfigurationProvider>\n </EditorEnabledProvider>\n </ChangedContentProvider>\n);\n"],"mappings":";AA4CQ;AA1CR;AAAA,EAEE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,8BAA8B;AACvC;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@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { useEffect } from "react";
|
|
3
3
|
import { useCommunicator } from "./CommunicatorContext.mjs";
|
|
4
4
|
const compareUrls = (url1, url2) => {
|
|
5
5
|
try {
|
|
@@ -19,7 +19,7 @@ const compareUrls = (url1, url2) => {
|
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
const useCrossFrameMessageListener = (key, onEventTriggered) => {
|
|
22
|
+
const useCrossFrameMessageListener = (key, onEventTriggered, revalidator) => {
|
|
23
23
|
const { allowedOrigins, postMessage, senderId } = useCommunicator();
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
if (onEventTriggered) {
|
|
@@ -34,14 +34,11 @@ const useCrossFrameMessageListener = (key, onEventTriggered) => {
|
|
|
34
34
|
window.addEventListener("message", handleMessage);
|
|
35
35
|
return () => window.removeEventListener("message", handleMessage);
|
|
36
36
|
}
|
|
37
|
-
}, [allowedOrigins, postMessage, senderId]);
|
|
38
|
-
const postMessageWrapper =
|
|
39
|
-
(data
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
[postMessage, key, senderId]
|
|
43
|
-
);
|
|
44
|
-
return useMemo(() => postMessageWrapper, [postMessageWrapper]);
|
|
37
|
+
}, [allowedOrigins, postMessage, senderId, revalidator]);
|
|
38
|
+
const postMessageWrapper = (data) => {
|
|
39
|
+
postMessage({ type: key, data, senderId });
|
|
40
|
+
};
|
|
41
|
+
return postMessageWrapper;
|
|
45
42
|
};
|
|
46
43
|
export {
|
|
47
44
|
useCrossFrameMessageListener
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { useCommunicator } from './CommunicatorContext';\nimport { type MessageKey } from './messageKey';\n\n/**\n * Compare two URLs for equality.\n * This function is used to determine if a message originates from the same origin.\n *\n * ```js\n * // Example usage\n * console.log(compareUrls(\"http://localhost:5173/\", \"http://localhost:5173\")); // true\n * console.log(compareUrls(\"http://localhost:5173\", \"http://localhost:5173?myParam=true\")); // true\n * console.log(compareUrls(\"http://localhost:5173/subpath\", \"http://localhost:5173\")); // true\n * console.log(compareUrls(\"http://localhost:5172\", \"http://localhost:5173\")); // false\n * ```\n *\n * @param url1 - The first URL to compare.\n * @param url2 - The second URL to compare.\n * @returns Whether the two URLs are equal.\n */\nconst compareUrls = (url1: string, url2: string): boolean => {\n try {\n const parsedUrl1 = new URL(url1);\n const parsedUrl2 = new URL(url2);\n\n // Compare protocol, hostname, and port\n if (\n parsedUrl1.protocol !== parsedUrl2.protocol ||\n parsedUrl1.hostname !== parsedUrl2.hostname ||\n parsedUrl1.port !== parsedUrl2.port\n ) {\n return false;\n }\n\n // One URL should not have a subpath while the other does\n const path1 = parsedUrl1.pathname.replace(/\\/$/, ''); // Remove trailing slash\n const path2 = parsedUrl2.pathname.replace(/\\/$/, '');\n\n if (path1 !== '' && path2 !== '' && path1 !== path2) {\n return false;\n }\n\n return true;\n } catch (error) {\n console.error('Invalid URL(s)', error);\n return false;\n }\n};\n\n/**\n * useCrossFrameMessageListener\n *\n * This React hook listens for messages sent via the `postMessage` API and triggers a callback\n * whenever a message of the specified type (`key`) is received. It is useful for synchronizing\n * state or events across different windows, iframes, or contexts.\n *\n * @template S - The type of the data payload in the message.\n * @param key - A unique identifier for the message type to listen for.\n * @param [onEventTriggered] - A callback function triggered when a message\n * @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state\n * with the specified key is received. The callback receives the message data as its argument.\n *\n * @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function\n * that allows broadcasting messages with the specified key and data.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const { allowedOrigins, postMessage, senderId } = useCommunicator();\n\n useEffect(() => {\n if (onEventTriggered) {\n /**\n * Message handler to process incoming messages.\n *\n * - **Message Filtering:** Ensures only messages with the specified `key` are processed.\n * - **Origin Validation:** Checks that the origin of the message is within the allowed origins.\n *\n * @param {MessageEvent<{ type: string; data: S }>} event - The incoming message event object.\n */\n const handleMessage = (\n event: MessageEvent<{ type: string; data: S; senderId: string }>\n ) => {\n const { type, data, senderId: msgSenderId } = event.data;\n\n // Ignore messages that do not match the current key\n if (type !== key) return;\n\n // Ignore messages from myself\n if (msgSenderId === senderId) return;\n\n // Check if the message origin is allowed\n if (\n typeof allowedOrigins === 'undefined' ||\n allowedOrigins?.some((url) => compareUrls(url, event.origin)) ||\n allowedOrigins?.includes('*')\n ) {\n // Update the local state with the received data\n onEventTriggered(data);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Clean up the event listener on unmount\n return () => window.removeEventListener('message', handleMessage);\n }\n }, [allowedOrigins, postMessage, senderId, revalidator]);\n\n /**\n * A wrapper function around the `postMessage` function to broadcast messages efficiently.\n *\n * - **Encapsulation:** Ensures the `postMessage` function is scoped to the provided key.\n * - **Ease of Use:** Simplifies broadcasting messages with consistent type and format.\n *\n * @param {S} data - The data payload to include in the message.\n * @returns {void}\n */\n const postMessageWrapper: (data?: S) => void = (data) => {\n postMessage({ type: key, data, senderId });\n };\n\n return postMessageWrapper;\n};\n"],"mappings":";AAEA,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAmBhC,MAAM,cAAc,CAAC,MAAc,SAA0B;AAC3D,MAAI;AACF,UAAM,aAAa,IAAI,IAAI,IAAI;AAC/B,UAAM,aAAa,IAAI,IAAI,IAAI;AAG/B,QACE,WAAW,aAAa,WAAW,YACnC,WAAW,aAAa,WAAW,YACnC,WAAW,SAAS,WAAW,MAC/B;AACA,aAAO;AAAA,IACT;AAGA,UAAM,QAAQ,WAAW,SAAS,QAAQ,OAAO,EAAE;AACnD,UAAM,QAAQ,WAAW,SAAS,QAAQ,OAAO,EAAE;AAEnD,QAAI,UAAU,MAAM,UAAU,MAAM,UAAU,OAAO;AACnD,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,kBAAkB,KAAK;AACrC,WAAO;AAAA,EACT;AACF;AAkBO,MAAM,+BAA+B,CAC1C,KACA,kBACA,gBACG;AACH,QAAM,EAAE,gBAAgB,aAAa,SAAS,IAAI,gBAAgB;AAElE,YAAU,MAAM;AACd,QAAI,kBAAkB;AASpB,YAAM,gBAAgB,CACpB,UACG;AACH,cAAM,EAAE,MAAM,MAAM,UAAU,YAAY,IAAI,MAAM;AAGpD,YAAI,SAAS,IAAK;AAGlB,YAAI,gBAAgB,SAAU;AAG9B,YACE,OAAO,mBAAmB,eAC1B,gBAAgB,KAAK,CAAC,QAAQ,YAAY,KAAK,MAAM,MAAM,CAAC,KAC5D,gBAAgB,SAAS,GAAG,GAC5B;AAEA,2BAAiB,IAAI;AAAA,QACvB;AAAA,MACF;AAEA,aAAO,iBAAiB,WAAW,aAAa;AAGhD,aAAO,MAAM,OAAO,oBAAoB,WAAW,aAAa;AAAA,IAClE;AAAA,EACF,GAAG,CAAC,gBAAgB,aAAa,UAAU,WAAW,CAAC;AAWvD,QAAM,qBAAyC,CAAC,SAAS;AACvD,gBAAY,EAAE,MAAM,KAAK,MAAM,SAAS,CAAC;AAAA,EAC3C;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,59 +1,51 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect,
|
|
5
|
-
useMemo,
|
|
6
|
-
useState
|
|
7
|
-
} from "react";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
8
3
|
import { useCommunicator } from "./CommunicatorContext.mjs";
|
|
9
4
|
import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs";
|
|
10
5
|
const resolveState = (state, prevState) => typeof state === "function" ? state(prevState) : state;
|
|
11
6
|
const useCrossFrameState = (key, initialState, options) => {
|
|
12
7
|
const { postMessage, senderId } = useCommunicator();
|
|
13
|
-
const { emit, receive } =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
[key, postMessage, senderId]
|
|
26
|
-
);
|
|
8
|
+
const { emit, receive } = options ?? { emit: true, receive: true };
|
|
9
|
+
const handleStateChange = (state2, prevState) => {
|
|
10
|
+
const resolvedState = resolveState(state2, prevState);
|
|
11
|
+
if (emit && typeof postMessage === "function" && typeof resolvedState !== "undefined") {
|
|
12
|
+
postMessage({ type: `${key}/post`, data: resolvedState, senderId });
|
|
13
|
+
}
|
|
14
|
+
return resolvedState;
|
|
15
|
+
};
|
|
16
|
+
const postState = () => {
|
|
17
|
+
if (typeof postMessage !== "function") return;
|
|
18
|
+
postMessage({ type: `${key}/post`, data: state, senderId });
|
|
19
|
+
};
|
|
27
20
|
const [state, setState] = useState(() => handleStateChange(initialState));
|
|
28
|
-
const setStateWrapper =
|
|
29
|
-
(valueOrUpdater) => setState((prevState) => handleStateChange(valueOrUpdater, prevState)),
|
|
30
|
-
[handleStateChange]
|
|
31
|
-
);
|
|
21
|
+
const setStateWrapper = (valueOrUpdater) => setState((prevState) => handleStateChange(valueOrUpdater, prevState));
|
|
32
22
|
useCrossFrameMessageListener(
|
|
33
23
|
`${key}/post`,
|
|
34
24
|
// Only activate the state listener if the `receive` option is true
|
|
35
|
-
receive ?
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
(_, originSenderId) => {
|
|
39
|
-
if (!emit || typeof postMessage !== "function") return;
|
|
40
|
-
if (originSenderId === senderId) return;
|
|
41
|
-
if (typeof state === "undefined") return;
|
|
42
|
-
postMessage({ type: `${key}/post`, data: state, senderId });
|
|
43
|
-
},
|
|
44
|
-
[emit, key, postMessage, senderId, state]
|
|
25
|
+
receive ? (data) => {
|
|
26
|
+
setState(data);
|
|
27
|
+
} : void 0
|
|
45
28
|
);
|
|
29
|
+
const onGetMessage = (_, originSenderId) => {
|
|
30
|
+
if (!emit) return;
|
|
31
|
+
if (typeof postMessage !== "function") return;
|
|
32
|
+
if (originSenderId === senderId) return;
|
|
33
|
+
if (typeof state === "undefined") return;
|
|
34
|
+
postMessage({ type: `${key}/post`, data: state, senderId });
|
|
35
|
+
};
|
|
46
36
|
useCrossFrameMessageListener(
|
|
47
37
|
`${key}/get`,
|
|
48
38
|
// Only activate the state listener if the `emit` option is true
|
|
49
|
-
emit ? onGetMessage : void 0
|
|
39
|
+
emit ? onGetMessage : void 0,
|
|
40
|
+
state
|
|
41
|
+
// Revalidate the listener if the state changes
|
|
50
42
|
);
|
|
51
43
|
useEffect(() => {
|
|
52
|
-
if (receive && typeof postMessage === "function") {
|
|
44
|
+
if (receive && typeof postMessage === "function" && typeof state === "undefined") {
|
|
53
45
|
postMessage({ type: `${key}/get`, senderId });
|
|
54
46
|
}
|
|
55
47
|
}, []);
|
|
56
|
-
return
|
|
48
|
+
return [state, setStateWrapper, postState];
|
|
57
49
|
};
|
|
58
50
|
export {
|
|
59
51
|
useCrossFrameState
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useState, type Dispatch, type SetStateAction } from 'react';\nimport { useCommunicator } from './CommunicatorContext';\nimport { type MessageKey } from './messageKey';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport type CrossFrameStateOptions = {\n emit?: boolean;\n receive?: boolean;\n};\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\n/**\n * Configuration options for `useCrossFrameState`.\n * @typedef {Object} CrossFrameStateOptions\n * @property {boolean} [emit=true] - Whether to broadcast state changes to other instances.\n * @property {boolean} [receive=true] - Whether to listen for state updates from other instances.\n */\n\n/**\n * useCrossFrameState\n *\n * This React hook synchronizes state across multiple instances (e.g., different iframes or windows).\n * It uses the `postMessage` API to communicate state changes and updates between instances.\n *\n * @template S - The type of the state.\n * @param {`${MessageKey}`} key - A unique identifier for the state to synchronize.\n * @param {S | (() => S)} [initialState] - The initial state value or a function to compute it lazily.\n * @param {CrossFrameStateOptions} [options] - Configuration options to control emitting and receiving messages.\n * - `emit` (default: true): Whether to broadcast state changes to other instances.\n * - `receive` (default: true): Whether to listen for state updates from other instances.\n *\n * @returns {[S, Dispatch<SetStateAction<S>>]} An array containing the current state and a setter function.\n */\nexport const useCrossFrameState = <S,>(\n key: `${MessageKey}`,\n initialState?: S | (() => S),\n options?: CrossFrameStateOptions\n): [S, Dispatch<SetStateAction<S>>, typeof postState] => {\n const { postMessage, senderId } = useCommunicator();\n\n const { emit, receive } = options ?? { emit: true, receive: true };\n\n const handleStateChange = (state?: SetStateAction<S>, prevState?: S) => {\n // Initialize state from the provided initial value, if defined\n const resolvedState: S = resolveState(state, prevState);\n\n // Emit the initial state if `emit` is enabled and initial state is defined\n if (\n emit &&\n typeof postMessage === 'function' &&\n typeof resolvedState !== 'undefined'\n ) {\n postMessage({ type: `${key}/post`, data: resolvedState, senderId });\n }\n\n return resolvedState;\n };\n\n const postState = () => {\n if (typeof postMessage !== 'function') return;\n postMessage({ type: `${key}/post`, data: state, senderId });\n };\n\n const [state, setState] = useState<S>(() => handleStateChange(initialState));\n\n /**\n * A wrapper function around the `setState` function to handle messaging efficiently.\n *\n * This approach has several advantages over using an additional `useEffect`:\n * - **Avoid Redundant Re-renders:** By emitting the message directly within the `setState` logic,\n * it prevents the extra render cycle that would be triggered when using `useEffect`.\n * - **Consistency:** Ensures the message is emitted immediately when the state is updated,\n * avoiding potential delays caused by the asynchronous nature of `useEffect`.\n *\n * This function keeps the same API as `setState` and is memoized using `useCallback`\n * to prevent unnecessary re-renders of dependent components.\n *\n * @template S - The type of the state.\n * @param {SetStateAction<S>} valueOrUpdater - The new state or a function to produce it.\n * @returns {void}\n */\n const setStateWrapper: Dispatch<SetStateAction<S>> = (valueOrUpdater) =>\n setState((prevState) => handleStateChange(valueOrUpdater, prevState));\n\n /**\n * Listen for messages with the specified key and update the state accordingly.\n */\n useCrossFrameMessageListener<S>(\n `${key}/post`,\n // Only activate the state listener if the `receive` option is true\n receive\n ? (data) => {\n setState(data);\n }\n : undefined\n );\n\n const onGetMessage = (_: unknown, originSenderId?: string) => {\n if (!emit) return;\n if (typeof postMessage !== 'function') return;\n if (originSenderId === senderId) return;\n if (typeof state === 'undefined') return;\n\n postMessage({ type: `${key}/post`, data: state, senderId });\n };\n\n /**\n * Listen for messages request to get the state content and send it back.\n */\n useCrossFrameMessageListener<S>(\n `${key}/get`,\n // Only activate the state listener if the `emit` option is true\n emit ? onGetMessage : undefined,\n state // Revalidate the listener if the state changes\n );\n\n useEffect(() => {\n // If the component is mounted and the hook in receive mode,\n // Request the state from the other instance\n if (\n receive &&\n typeof postMessage === 'function' &&\n typeof state === 'undefined'\n ) {\n postMessage({ type: `${key}/get`, senderId });\n }\n }, []);\n\n // Return the useState state and setter\n return [state, setStateWrapper, postState];\n};\n"],"mappings":";AAEA,SAAS,WAAW,gBAAoD;AACxE,SAAS,uBAAuB;AAEhC,SAAS,oCAAoC;AAO7C,MAAM,eAAe,CAAK,OAA2B,cACnD,OAAO,UAAU,aACZ,MAA+B,SAAS,IACxC;AAwBA,MAAM,qBAAqB,CAChC,KACA,cACA,YACuD;AACvD,QAAM,EAAE,aAAa,SAAS,IAAI,gBAAgB;AAElD,QAAM,EAAE,MAAM,QAAQ,IAAI,WAAW,EAAE,MAAM,MAAM,SAAS,KAAK;AAEjE,QAAM,oBAAoB,CAACA,QAA2B,cAAkB;AAEtE,UAAM,gBAAmB,aAAaA,QAA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|
-
const useCrossURLPathState = (initialState, options) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
);
|
|
6
|
+
const useCrossURLPathState = (initialState, options) => useCrossFrameState("INTLAYER_URL_CHANGE", initialState, options);
|
|
7
|
+
const useCrossURLPathSetter = (initialState) => {
|
|
8
|
+
const states = useCrossURLPathState(initialState, {
|
|
9
|
+
emit: true,
|
|
10
|
+
receive: false
|
|
11
|
+
});
|
|
12
12
|
const [_state, setState] = states;
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
const originalPushState = history.pushState;
|
|
@@ -35,10 +35,11 @@ const useCrossURLPathState = (initialState, options) => {
|
|
|
35
35
|
history.pushState = originalPushState;
|
|
36
36
|
history.replaceState = originalReplaceState;
|
|
37
37
|
};
|
|
38
|
-
}, [
|
|
38
|
+
}, []);
|
|
39
39
|
return states;
|
|
40
40
|
};
|
|
41
41
|
export {
|
|
42
|
+
useCrossURLPathSetter,
|
|
42
43
|
useCrossURLPathState
|
|
43
44
|
};
|
|
44
45
|
//# sourceMappingURL=useCrossURLPathState.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport {\n useCrossFrameState,\n type CrossFrameStateOptions,\n} from './useCrossFrameState';\n\nexport const useCrossURLPathState = (\n initialState?: string,\n options?: CrossFrameStateOptions\n) => {\n const states =
|
|
1
|
+
{"version":3,"sources":["../../src/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport {\n useCrossFrameState,\n type CrossFrameStateOptions,\n} from './useCrossFrameState';\n\nexport const useCrossURLPathState = (\n initialState?: string,\n options?: CrossFrameStateOptions\n) => useCrossFrameState('INTLAYER_URL_CHANGE', initialState, options);\n\nexport const useCrossURLPathSetter = (initialState?: string) => {\n const states = useCrossURLPathState(initialState, {\n emit: true,\n receive: false,\n });\n const [_state, setState] = states;\n\n useEffect(() => {\n /**\n * 1) Monkey patch history methods (pushState, replaceState)\n * to dispatch a custom event whenever they are called.\n */\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n\n const injectLocationChangeEvent = (method: (...args: any[]) => void) =>\n function (this: typeof history, ...args: [any, string, string?]) {\n method.apply(this, args);\n window.dispatchEvent(new Event('locationchange'));\n };\n\n history.pushState = injectLocationChangeEvent(originalPushState);\n history.replaceState = injectLocationChangeEvent(originalReplaceState);\n\n /**\n * 2) The callback to update our state whenever the URL changes.\n */\n const updateURLState = () => {\n setState(window.location.pathname);\n };\n\n /**\n * 3) Attach event listeners for locationchange, popstate, hashchange.\n * - 'locationchange' is our custom event triggered by push/replaceState overrides.\n * - 'popstate' is fired on back/forward navigation.\n * - 'hashchange' is for URL hash (#) changes.\n * - 'load' is when new page is loaded\n */\n window.addEventListener('locationchange', updateURLState);\n window.addEventListener('popstate', updateURLState);\n window.addEventListener('hashchange', updateURLState);\n window.addEventListener('load', updateURLState);\n\n // Initialize our state immediately on mount\n updateURLState();\n\n /**\n * 4) Cleanup when the component unmounts:\n * - Remove event listeners.\n * - Restore original pushState & replaceState to avoid side effects.\n */\n return () => {\n window.removeEventListener('locationchange', updateURLState);\n window.removeEventListener('popstate', updateURLState);\n window.removeEventListener('hashchange', updateURLState);\n window.removeEventListener('load', updateURLState);\n history.pushState = originalPushState;\n history.replaceState = originalReplaceState;\n };\n }, []);\n\n return states;\n};\n"],"mappings":";AAEA,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,OAEK;AAEA,MAAM,uBAAuB,CAClC,cACA,YACG,mBAAmB,uBAAuB,cAAc,OAAO;AAE7D,MAAM,wBAAwB,CAAC,iBAA0B;AAC9D,QAAM,SAAS,qBAAqB,cAAc;AAAA,IAChD,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AACD,QAAM,CAAC,QAAQ,QAAQ,IAAI;AAE3B,YAAU,MAAM;AAKd,UAAM,oBAAoB,QAAQ;AAClC,UAAM,uBAAuB,QAAQ;AAErC,UAAM,4BAA4B,CAAC,WACjC,YAAmC,MAA8B;AAC/D,aAAO,MAAM,MAAM,IAAI;AACvB,aAAO,cAAc,IAAI,MAAM,gBAAgB,CAAC;AAAA,IAClD;AAEF,YAAQ,YAAY,0BAA0B,iBAAiB;AAC/D,YAAQ,eAAe,0BAA0B,oBAAoB;AAKrE,UAAM,iBAAiB,MAAM;AAC3B,eAAS,OAAO,SAAS,QAAQ;AAAA,IACnC;AASA,WAAO,iBAAiB,kBAAkB,cAAc;AACxD,WAAO,iBAAiB,YAAY,cAAc;AAClD,WAAO,iBAAiB,cAAc,cAAc;AACpD,WAAO,iBAAiB,QAAQ,cAAc;AAG9C,mBAAe;AAOf,WAAO,MAAM;AACX,aAAO,oBAAoB,kBAAkB,cAAc;AAC3D,aAAO,oBAAoB,YAAY,cAAc;AACrD,aAAO,oBAAoB,cAAc,cAAc;AACvD,aAAO,oBAAoB,QAAQ,cAAc;AACjD,cAAQ,YAAY;AACpB,cAAQ,eAAe;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type IntlayerConfig } from '@intlayer/config/client';
|
|
2
2
|
import { type FC, type PropsWithChildren } from 'react';
|
|
3
|
-
export declare const useConfigurationState: () => [IntlayerConfig, import("react").Dispatch<import("react").SetStateAction<IntlayerConfig
|
|
3
|
+
export declare const useConfigurationState: () => [IntlayerConfig, import("react").Dispatch<import("react").SetStateAction<IntlayerConfig>>, () => void];
|
|
4
4
|
export type ConfigurationProviderProps = {
|
|
5
5
|
configuration?: IntlayerConfig;
|
|
6
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.d.ts","sourceRoot":"","sources":["../../src/ConfigurationContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EACL,KAAK,EAAE,EACP,KAAK,iBAAiB,EAGvB,MAAM,OAAO,CAAC;AAOf,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.d.ts","sourceRoot":"","sources":["../../src/ConfigurationContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EACL,KAAK,EAAE,EACP,KAAK,iBAAiB,EAGvB,MAAM,OAAO,CAAC;AAOf,eAAO,MAAM,qBAAqB,8GAI9B,CAAC;AAEL,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,CAAC,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,EAAE,CACpC,iBAAiB,CAAC,0BAA0B,CAAC,CAK9C,CAAC;AAEF,eAAO,MAAM,gBAAgB,sBAA+C,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Dictionary, type ContentNode, type KeyPath } from '@intlayer/core';
|
|
2
2
|
import { type Dispatch, type SetStateAction, type FC, type PropsWithChildren } from 'react';
|
|
3
|
-
|
|
3
|
+
export declare const usePostEditedContentState: <S>(onEventTriggered?: (data: S) => void) => (data?: S) => void;
|
|
4
|
+
export declare const useGetEditedContentState: <S>(onEventTriggered?: (data: S) => void) => (data?: S) => void;
|
|
4
5
|
type EditedContentActionsContextType = {
|
|
5
6
|
setEditedContentState: (editedContent: Record<Dictionary['key'], Dictionary>) => void;
|
|
6
7
|
setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;
|
|
@@ -13,7 +14,6 @@ type EditedContentActionsContextType = {
|
|
|
13
14
|
clearEditedContent: () => void;
|
|
14
15
|
getEditedContentValue: (dictionaryKey: Dictionary['key'], keyPath: KeyPath[]) => ContentNode | undefined;
|
|
15
16
|
};
|
|
16
|
-
export declare const useEditedContentState: () => [DictionaryContent, Dispatch<SetStateAction<DictionaryContent>>];
|
|
17
17
|
export declare const EditedContentProvider: FC<PropsWithChildren>;
|
|
18
18
|
export declare const useEditedContentActions: () => EditedContentActionsContextType;
|
|
19
19
|
export declare const useEditedContent: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.d.ts","sourceRoot":"","sources":["../../src/EditedContentContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,OAAO,EAIb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,QAAQ,EAGb,KAAK,cAAc,EACnB,KAAK,EAAE,EACP,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"EditedContentContext.d.ts","sourceRoot":"","sources":["../../src/EditedContentContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,OAAO,EAIb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,QAAQ,EAGb,KAAK,cAAc,EACnB,KAAK,EAAE,EACP,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AAgBf,eAAO,MAAM,yBAAyB,GAAI,CAAC,qBACtB,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,uBAKnC,CAAC;AAEJ,eAAO,MAAM,wBAAwB,GAAI,CAAC,qBACrB,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,uBAKnC,CAAC;AAEJ,KAAK,+BAA+B,GAAG;IACrC,qBAAqB,EAAE,CACrB,aAAa,EAAE,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,KACjD,IAAI,CAAC;IACV,mBAAmB,EAAE,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,gBAAgB,EAAE,CAChB,aAAa,EAAE,UAAU,CAAC,KAAK,CAAC,EAChC,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC,KAC5B,IAAI,C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QAAQ,EAAE,WAAW,CAAC,GAAG,CAAC,EAC1B,OAAO,CAAC,EAAE,OAAO,EAAE,EACnB,SAAS,CAAC,EAAE,OAAO,KAChB,IAAI;yBACY,CACnB,aAAa,EAAE,UAAU,CAAC,KAAK,CAAC,EAChC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,EACtB,OAAO,CAAC,EAAE,OAAO,EAAE,KAChB,IAAI;yBACY,CACnB,aAAa,EAAE,UAAU,CAAC,KAAK,CAAC,EAChC,OAAO,EAAE,OAAO,EAAE,KACf,IAAI;0BACa,CAAC,aAAa,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK,IAAI;kCAClC,CAAC,aAAa,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK,IAAI;wBACpD,MAAM,IAAI;2BACP,CACrB,aAAa,EAAE,UAAU,CAAC,KAAK,CAAC,EAChC,OAAO,EAAE,OAAO,EAAE,KACf,WAAW,GAAG,SAAS;mBArDb,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,GAAG,SAAS;CAwSjE,CAAC"}
|
|
@@ -3,7 +3,9 @@ import { type CrossFrameStateOptions } from './useCrossFrameState';
|
|
|
3
3
|
export type EditorEnabledStateProps = {
|
|
4
4
|
enabled: boolean;
|
|
5
5
|
};
|
|
6
|
-
export declare const useEditorEnabledState: (options?: CrossFrameStateOptions) => [boolean, import("react").Dispatch<import("react").SetStateAction<boolean
|
|
6
|
+
export declare const useEditorEnabledState: (options?: CrossFrameStateOptions) => [boolean, import("react").Dispatch<import("react").SetStateAction<boolean>>, () => void];
|
|
7
|
+
export declare const usePostEditorEnabledState: <S>(onEventTriggered?: (data: S) => void) => (data?: S) => void;
|
|
8
|
+
export declare const useGetEditorEnabledState: <S>(onEventTriggered?: (data: S) => void) => (data?: S) => void;
|
|
7
9
|
export declare const EditorEnabledProvider: FC<PropsWithChildren>;
|
|
8
10
|
export declare const useEditorEnabled: () => EditorEnabledStateProps;
|
|
9
11
|
//# sourceMappingURL=EditorEnabledContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorEnabledContext.d.ts","sourceRoot":"","sources":["../../src/EditorEnabledContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,EAAE,EACP,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"EditorEnabledContext.d.ts","sourceRoot":"","sources":["../../src/EditorEnabledContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,EAAE,EACP,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,sBAAsB,CAAC;AAG9B,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAMF,eAAO,MAAM,qBAAqB,aAAc,sBAAsB,6FACP,CAAC;AAEhE,eAAO,MAAM,yBAAyB,GAAI,CAAC,qBACtB,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,uBAKnC,CAAC;AAEJ,eAAO,MAAM,wBAAwB,GAAI,CAAC,qBACrB,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,uBAEyC,CAAC;AAEhF,eAAO,MAAM,qBAAqB,EAAE,EAAE,CAAC,iBAAiB,CAWvD,CAAC;AAEF,eAAO,MAAM,gBAAgB,+BAAyC,CAAC"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { type FC, type PropsWithChildren } from 'react';
|
|
2
2
|
import { type CommunicatorProviderProps } from './CommunicatorContext';
|
|
3
3
|
import { type ConfigurationProviderProps } from './ConfigurationContext';
|
|
4
|
-
type
|
|
4
|
+
export type EditorProviderProps = CommunicatorProviderProps & ConfigurationProviderProps & {
|
|
5
5
|
mode: 'editor' | 'client';
|
|
6
6
|
};
|
|
7
|
-
export type EditorProviderProps = EditorProviderEnabledProps & ConfigurationProviderProps;
|
|
8
7
|
export declare const EditorProvider: FC<PropsWithChildren<EditorProviderProps>>;
|
|
9
|
-
export {};
|
|
10
8
|
//# sourceMappingURL=EditorProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorProvider.d.ts","sourceRoot":"","sources":["../../src/EditorProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"EditorProvider.d.ts","sourceRoot":"","sources":["../../src/EditorProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,EAAE,EACP,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,KAAK,yBAAyB,EAE/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,0BAA0B,EAEhC,MAAM,wBAAwB,CAAC;AA2EhC,MAAM,MAAM,mBAAmB,GAAG,yBAAyB,GACzD,0BAA0B,GAAG;IAC3B,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC3B,CAAC;AAEJ,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAwBrE,CAAC"}
|
|
@@ -7,12 +7,13 @@ import { type MessageKey } from './messageKey';
|
|
|
7
7
|
* state or events across different windows, iframes, or contexts.
|
|
8
8
|
*
|
|
9
9
|
* @template S - The type of the data payload in the message.
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
10
|
+
* @param key - A unique identifier for the message type to listen for.
|
|
11
|
+
* @param [onEventTriggered] - A callback function triggered when a message
|
|
12
|
+
* @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state
|
|
12
13
|
* with the specified key is received. The callback receives the message data as its argument.
|
|
13
14
|
*
|
|
14
15
|
* @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function
|
|
15
16
|
* that allows broadcasting messages with the specified key and data.
|
|
16
17
|
*/
|
|
17
|
-
export declare const useCrossFrameMessageListener: <S>(key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`, onEventTriggered?: (data: S) => void) => (data
|
|
18
|
+
export declare const useCrossFrameMessageListener: <S>(key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`, onEventTriggered?: (data: S) => void, revalidator?: any) => (data?: S) => void;
|
|
18
19
|
//# sourceMappingURL=useCrossFrameMessageListener.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameMessageListener.d.ts","sourceRoot":"","sources":["../../src/useCrossFrameMessageListener.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AA+C/C
|
|
1
|
+
{"version":3,"file":"useCrossFrameMessageListener.d.ts","sourceRoot":"","sources":["../../src/useCrossFrameMessageListener.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AA+C/C;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,OACvC,GAAG,UAAU,EAAE,GAAG,GAAG,UAAU,OAAO,GAAG,GAAG,UAAU,MAAM,qBAC9C,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,gBACtB,GAAG,aAoDiB,CAAC,KAAK,IAKzC,CAAC"}
|
|
@@ -25,5 +25,5 @@ export type CrossFrameStateOptions = {
|
|
|
25
25
|
*
|
|
26
26
|
* @returns {[S, Dispatch<SetStateAction<S>>]} An array containing the current state and a setter function.
|
|
27
27
|
*/
|
|
28
|
-
export declare const useCrossFrameState: <S>(key: `${MessageKey}`, initialState?: S | (() => S), options?: CrossFrameStateOptions) => [S, Dispatch<SetStateAction<S
|
|
28
|
+
export declare const useCrossFrameState: <S>(key: `${MessageKey}`, initialState?: S | (() => S), options?: CrossFrameStateOptions) => [S, Dispatch<SetStateAction<S>>, () => void];
|
|
29
29
|
//# sourceMappingURL=useCrossFrameState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameState.d.ts","sourceRoot":"","sources":["../../src/useCrossFrameState.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"useCrossFrameState.d.ts","sourceRoot":"","sources":["../../src/useCrossFrameState.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAEhF,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAOF;;;;;GAKG;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,OAC7B,GAAG,UAAU,EAAE,iBACL,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,YAClB,sBAAsB,KAC/B,CAAC,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,aA6FjC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type CrossFrameStateOptions } from './useCrossFrameState';
|
|
2
|
-
export declare const useCrossURLPathState: (initialState?: string, options?: CrossFrameStateOptions) => [string, import("react").Dispatch<import("react").SetStateAction<string
|
|
2
|
+
export declare const useCrossURLPathState: (initialState?: string, options?: CrossFrameStateOptions) => [string, import("react").Dispatch<import("react").SetStateAction<string>>, () => void];
|
|
3
|
+
export declare const useCrossURLPathSetter: (initialState?: string) => [string, import("react").Dispatch<import("react").SetStateAction<string>>, () => void];
|
|
3
4
|
//# sourceMappingURL=useCrossURLPathState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossURLPathState.d.ts","sourceRoot":"","sources":["../../src/useCrossURLPathState.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AAE9B,eAAO,MAAM,oBAAoB,kBAChB,MAAM,YACX,sBAAsB
|
|
1
|
+
{"version":3,"file":"useCrossURLPathState.d.ts","sourceRoot":"","sources":["../../src/useCrossURLPathState.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AAE9B,eAAO,MAAM,oBAAoB,kBAChB,MAAM,YACX,sBAAsB,2FACmC,CAAC;AAEtE,eAAO,MAAM,qBAAqB,kBAAmB,MAAM,2FA8D1D,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const useIframeClickInterceptor: () => void;
|
|
2
|
-
export declare const useIframeClickMerger: () => (data
|
|
2
|
+
export declare const useIframeClickMerger: () => (data?: MessageEvent<any>) => void;
|
|
3
3
|
//# sourceMappingURL=useIframeClickCommunicator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIframeClickCommunicator.d.ts","sourceRoot":"","sources":["../../src/useIframeClickCommunicator.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,yBAAyB,YAerC,CAAC;AAyBF,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"useIframeClickCommunicator.d.ts","sourceRoot":"","sources":["../../src/useIframeClickCommunicator.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,yBAAyB,YAerC,CAAC;AAyBF,eAAO,MAAM,oBAAoB,0CAI9B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/editor-react",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Provides the states, contexts, hooks and components to interact with the Intlayer editor for a React application",
|
|
6
6
|
"keywords": [
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"uuid": "^11.0.5",
|
|
55
|
-
"@intlayer/config": "5.1.
|
|
56
|
-
"@intlayer/
|
|
57
|
-
"@intlayer/
|
|
55
|
+
"@intlayer/config": "5.1.7",
|
|
56
|
+
"@intlayer/editor": "5.1.7",
|
|
57
|
+
"@intlayer/core": "5.1.7"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/node": "^22.10.6",
|
|
@@ -68,17 +68,17 @@
|
|
|
68
68
|
"tsc-alias": "^1.8.10",
|
|
69
69
|
"tsup": "^8.3.5",
|
|
70
70
|
"typescript": "^5.7.3",
|
|
71
|
-
"@utils/eslint-config": "1.0.4",
|
|
72
71
|
"@utils/ts-config": "1.0.4",
|
|
73
72
|
"@utils/ts-config-types": "1.0.4",
|
|
74
|
-
"@utils/tsup-config": "1.0.4"
|
|
73
|
+
"@utils/tsup-config": "1.0.4",
|
|
74
|
+
"@utils/eslint-config": "1.0.4"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"react": ">=16.0.0",
|
|
78
78
|
"react-dom": ">=16.0.0",
|
|
79
|
-
"@intlayer/config": "5.1.
|
|
80
|
-
"@intlayer/
|
|
81
|
-
"@intlayer/
|
|
79
|
+
"@intlayer/config": "5.1.7",
|
|
80
|
+
"@intlayer/editor": "5.1.7",
|
|
81
|
+
"@intlayer/core": "5.1.7"
|
|
82
82
|
},
|
|
83
83
|
"engines": {
|
|
84
84
|
"node": ">=14.18"
|