@intlayer/editor-react 8.4.3 → 8.4.5
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/CommunicatorContext.cjs +19 -1
- package/dist/cjs/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/ConfigurationContext.cjs +40 -1
- package/dist/cjs/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/DictionariesRecordContext.cjs +33 -1
- package/dist/cjs/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/EditedContentContext.cjs +55 -1
- package/dist/cjs/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/EditorEnabledContext.cjs +66 -1
- package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/EditorProvider.cjs +41 -1
- package/dist/cjs/EditorProvider.cjs.map +1 -1
- package/dist/cjs/EditorStateContext.cjs +17 -1
- package/dist/cjs/EditorStateContext.cjs.map +1 -1
- package/dist/cjs/FocusDictionaryContext.cjs +36 -1
- package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/index.cjs +52 -1
- package/dist/cjs/useCrossFrameMessageListener.cjs +30 -1
- package/dist/cjs/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/useCrossFrameState.cjs +63 -1
- package/dist/cjs/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/useCrossURLPathState.cjs +18 -1
- package/dist/cjs/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/useEditorLocale.cjs +26 -1
- package/dist/cjs/useEditorLocale.cjs.map +1 -1
- package/dist/cjs/useFocusUnmergedDictionary.cjs +50 -1
- package/dist/cjs/useFocusUnmergedDictionary.cjs.map +1 -1
- package/dist/cjs/useIframeClickInterceptor.cjs +27 -1
- package/dist/cjs/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/esm/CommunicatorContext.mjs +18 -1
- package/dist/esm/CommunicatorContext.mjs.map +1 -1
- package/dist/esm/ConfigurationContext.mjs +37 -1
- package/dist/esm/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/DictionariesRecordContext.mjs +31 -1
- package/dist/esm/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/EditedContentContext.mjs +51 -1
- package/dist/esm/EditedContentContext.mjs.map +1 -1
- package/dist/esm/EditorEnabledContext.mjs +61 -1
- package/dist/esm/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/EditorProvider.mjs +40 -1
- package/dist/esm/EditorProvider.mjs.map +1 -1
- package/dist/esm/EditorStateContext.mjs +15 -1
- package/dist/esm/EditorStateContext.mjs.map +1 -1
- package/dist/esm/FocusDictionaryContext.mjs +34 -1
- package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/index.mjs +17 -1
- package/dist/esm/useCrossFrameMessageListener.mjs +29 -1
- package/dist/esm/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/useCrossFrameState.mjs +62 -1
- package/dist/esm/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/useCrossURLPathState.mjs +16 -1
- package/dist/esm/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/useEditorLocale.mjs +24 -1
- package/dist/esm/useEditorLocale.mjs.map +1 -1
- package/dist/esm/useFocusUnmergedDictionary.mjs +49 -1
- package/dist/esm/useFocusUnmergedDictionary.mjs.map +1 -1
- package/dist/esm/useIframeClickInterceptor.mjs +25 -1
- package/dist/esm/useIframeClickInterceptor.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/CommunicatorContext.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Returns the communicator API backed by the shared EditorStateManager messenger.
|
|
9
|
+
*/
|
|
10
|
+
const useCommunicator = () => {
|
|
11
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
12
|
+
return {
|
|
13
|
+
postMessage: (payload) => manager?.messenger.send(payload.type, payload.data),
|
|
14
|
+
senderId: manager?.messenger.senderId ?? ""
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.useCommunicator = useCommunicator;
|
|
2
20
|
//# sourceMappingURL=CommunicatorContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommunicatorContext.cjs","names":["useEditorStateManager"],"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport type { MessagePayload } from '@intlayer/editor';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type UseCrossPlatformStateProps = {\n postMessage: (payload: MessagePayload) => void;\n allowedOrigins?: string[];\n senderId: string;\n};\n\n/**\n * Returns the communicator API backed by the shared EditorStateManager messenger.\n */\nexport const useCommunicator = (): UseCrossPlatformStateProps => {\n const manager = useEditorStateManager();\n\n return {\n postMessage: (payload: MessagePayload) =>\n manager?.messenger.send(payload.type, payload.data),\n senderId: manager?.messenger.senderId ?? '',\n };\n};\n\n// Re-export type for backward compatibility\nexport type { MessengerConfig } from '@intlayer/editor';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CommunicatorContext.cjs","names":["useEditorStateManager"],"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport type { MessagePayload } from '@intlayer/editor';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type UseCrossPlatformStateProps = {\n postMessage: (payload: MessagePayload) => void;\n allowedOrigins?: string[];\n senderId: string;\n};\n\n/**\n * Returns the communicator API backed by the shared EditorStateManager messenger.\n */\nexport const useCommunicator = (): UseCrossPlatformStateProps => {\n const manager = useEditorStateManager();\n\n return {\n postMessage: (payload: MessagePayload) =>\n manager?.messenger.send(payload.type, payload.data),\n senderId: manager?.messenger.senderId ?? '',\n };\n};\n\n// Re-export type for backward compatibility\nexport type { MessengerConfig } from '@intlayer/editor';\n"],"mappings":";;;;;;;;;AAcA,MAAa,wBAAoD;CAC/D,MAAM,UAAUA,kDAAuB;AAEvC,QAAO;EACL,cAAc,YACZ,SAAS,UAAU,KAAK,QAAQ,MAAM,QAAQ,KAAK;EACrD,UAAU,SAAS,UAAU,YAAY;EAC1C"}
|
|
@@ -1,2 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/ConfigurationContext.tsx
|
|
8
|
+
const ConfigurationProvider = ({ configuration, children }) => {
|
|
9
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
10
|
+
(0, react.useEffect)(() => {
|
|
11
|
+
if (!manager || !configuration) return;
|
|
12
|
+
manager.configuration.set(configuration);
|
|
13
|
+
}, [manager, configuration]);
|
|
14
|
+
return children;
|
|
15
|
+
};
|
|
16
|
+
const useConfiguration = () => {
|
|
17
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
18
|
+
const [config, setConfig] = (0, react.useState)(manager?.configuration.value);
|
|
19
|
+
(0, react.useEffect)(() => {
|
|
20
|
+
if (!manager) return;
|
|
21
|
+
const handler = (e) => setConfig(e.detail);
|
|
22
|
+
manager.configuration.addEventListener("change", handler);
|
|
23
|
+
return () => manager.configuration.removeEventListener("change", handler);
|
|
24
|
+
}, [manager]);
|
|
25
|
+
return config;
|
|
26
|
+
};
|
|
27
|
+
const useConfigurationState = () => {
|
|
28
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
29
|
+
const [config, setConfig] = (0, react.useState)(manager?.configuration.value);
|
|
30
|
+
return [
|
|
31
|
+
config,
|
|
32
|
+
setConfig,
|
|
33
|
+
() => manager?.configuration.postCurrentValue()
|
|
34
|
+
];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.ConfigurationProvider = ConfigurationProvider;
|
|
39
|
+
exports.useConfiguration = useConfiguration;
|
|
40
|
+
exports.useConfigurationState = useConfigurationState;
|
|
2
41
|
//# sourceMappingURL=ConfigurationContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.cjs","names":["useEditorStateManager"],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FC, type PropsWithChildren, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type ConfigurationProviderProps = PropsWithChildren<{\n configuration?: IntlayerConfig;\n}>;\n\nexport const ConfigurationProvider: FC<ConfigurationProviderProps> = ({\n configuration,\n children,\n}) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!manager || !configuration) return;\n\n manager.configuration.set(configuration);\n }, [manager, configuration]);\n\n return children;\n};\n\nexport const useConfiguration = (): IntlayerConfig | undefined => {\n const manager = useEditorStateManager();\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager?.configuration.value\n );\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setConfig((e as CustomEvent<IntlayerConfig>).detail);\n manager.configuration.addEventListener('change', handler);\n return () => manager.configuration.removeEventListener('change', handler);\n }, [manager]);\n\n return config;\n};\n\nexport const useConfigurationState = () => {\n const manager = useEditorStateManager();\n\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager?.configuration.value\n );\n\n return [\n config,\n setConfig,\n () => manager?.configuration.postCurrentValue(),\n ] as const;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.cjs","names":["useEditorStateManager"],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FC, type PropsWithChildren, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type ConfigurationProviderProps = PropsWithChildren<{\n configuration?: IntlayerConfig;\n}>;\n\nexport const ConfigurationProvider: FC<ConfigurationProviderProps> = ({\n configuration,\n children,\n}) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!manager || !configuration) return;\n\n manager.configuration.set(configuration);\n }, [manager, configuration]);\n\n return children;\n};\n\nexport const useConfiguration = (): IntlayerConfig | undefined => {\n const manager = useEditorStateManager();\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager?.configuration.value\n );\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setConfig((e as CustomEvent<IntlayerConfig>).detail);\n manager.configuration.addEventListener('change', handler);\n return () => manager.configuration.removeEventListener('change', handler);\n }, [manager]);\n\n return config;\n};\n\nexport const useConfigurationState = () => {\n const manager = useEditorStateManager();\n\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager?.configuration.value\n );\n\n return [\n config,\n setConfig,\n () => manager?.configuration.postCurrentValue(),\n ] as const;\n};\n"],"mappings":";;;;;;;AAUA,MAAa,yBAAyD,EACpE,eACA,eACI;CACJ,MAAM,UAAUA,kDAAuB;AAEvC,4BAAgB;AACd,MAAI,CAAC,WAAW,CAAC,cAAe;AAEhC,UAAQ,cAAc,IAAI,cAAc;IACvC,CAAC,SAAS,cAAc,CAAC;AAE5B,QAAO;;AAGT,MAAa,yBAAqD;CAChE,MAAM,UAAUA,kDAAuB;CACvC,MAAM,CAAC,QAAQ,iCACb,SAAS,cAAc,MACxB;AAED,4BAAgB;AACd,MAAI,CAAC,QAAS;EAEd,MAAM,WAAW,MACf,UAAW,EAAkC,OAAO;AACtD,UAAQ,cAAc,iBAAiB,UAAU,QAAQ;AACzD,eAAa,QAAQ,cAAc,oBAAoB,UAAU,QAAQ;IACxE,CAAC,QAAQ,CAAC;AAEb,QAAO;;AAGT,MAAa,8BAA8B;CACzC,MAAM,UAAUA,kDAAuB;CAEvC,MAAM,CAAC,QAAQ,iCACb,SAAS,cAAc,MACxB;AAED,QAAO;EACL;EACA;QACM,SAAS,cAAc,kBAAkB;EAChD"}
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/DictionariesRecordContext.tsx
|
|
8
|
+
const useDictionariesRecord = () => {
|
|
9
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
10
|
+
const [localeDictionaries, setLocaleDictionariesState] = (0, react.useState)(manager?.localeDictionaries.value ?? {});
|
|
11
|
+
(0, react.useEffect)(() => {
|
|
12
|
+
if (!manager) return;
|
|
13
|
+
const handler = (e) => setLocaleDictionariesState(e.detail ?? {});
|
|
14
|
+
manager.localeDictionaries.addEventListener("change", handler);
|
|
15
|
+
return () => manager.localeDictionaries.removeEventListener("change", handler);
|
|
16
|
+
}, [manager]);
|
|
17
|
+
return {
|
|
18
|
+
localeDictionaries,
|
|
19
|
+
setLocaleDictionaries: (0, react.useCallback)((value) => manager?.localeDictionaries.set(value), [manager]),
|
|
20
|
+
setLocaleDictionary: (0, react.useCallback)((dictionary) => manager?.setLocaleDictionary(dictionary), [manager])
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const useDictionariesRecordActions = () => {
|
|
24
|
+
const { setLocaleDictionaries, setLocaleDictionary } = useDictionariesRecord();
|
|
25
|
+
return {
|
|
26
|
+
setLocaleDictionaries,
|
|
27
|
+
setLocaleDictionary
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.useDictionariesRecord = useDictionariesRecord;
|
|
33
|
+
exports.useDictionariesRecordActions = useDictionariesRecordActions;
|
|
2
34
|
//# sourceMappingURL=DictionariesRecordContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionariesRecordContext.cjs","names":["useEditorStateManager"],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { DictionaryContent } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: (value: DictionaryContent) => void;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nexport const useDictionariesRecord = (): DictionariesRecordStatesContextType &\n DictionariesRecordActionsContextType => {\n const manager = useEditorStateManager();\n const [localeDictionaries, setLocaleDictionariesState] =\n useState<DictionaryContent>(manager?.localeDictionaries.value ?? {});\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setLocaleDictionariesState(\n (e as CustomEvent<DictionaryContent>).detail ?? {}\n );\n\n manager.localeDictionaries.addEventListener('change', handler);\n\n return () =>\n manager.localeDictionaries.removeEventListener('change', handler);\n }, [manager]);\n\n const setLocaleDictionaries = useCallback(\n (value: DictionaryContent) => manager?.localeDictionaries.set(value),\n [manager]\n );\n\n const setLocaleDictionary = useCallback(\n (dictionary: Dictionary) => manager?.setLocaleDictionary(dictionary),\n [manager]\n );\n\n return { localeDictionaries, setLocaleDictionaries, setLocaleDictionary };\n};\n\nexport const useDictionariesRecordActions =\n (): DictionariesRecordActionsContextType => {\n const { setLocaleDictionaries, setLocaleDictionary } =\n useDictionariesRecord();\n return { setLocaleDictionaries, setLocaleDictionary };\n };\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.cjs","names":["useEditorStateManager"],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { DictionaryContent } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: (value: DictionaryContent) => void;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nexport const useDictionariesRecord = (): DictionariesRecordStatesContextType &\n DictionariesRecordActionsContextType => {\n const manager = useEditorStateManager();\n const [localeDictionaries, setLocaleDictionariesState] =\n useState<DictionaryContent>(manager?.localeDictionaries.value ?? {});\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setLocaleDictionariesState(\n (e as CustomEvent<DictionaryContent>).detail ?? {}\n );\n\n manager.localeDictionaries.addEventListener('change', handler);\n\n return () =>\n manager.localeDictionaries.removeEventListener('change', handler);\n }, [manager]);\n\n const setLocaleDictionaries = useCallback(\n (value: DictionaryContent) => manager?.localeDictionaries.set(value),\n [manager]\n );\n\n const setLocaleDictionary = useCallback(\n (dictionary: Dictionary) => manager?.setLocaleDictionary(dictionary),\n [manager]\n );\n\n return { localeDictionaries, setLocaleDictionaries, setLocaleDictionary };\n};\n\nexport const useDictionariesRecordActions =\n (): DictionariesRecordActionsContextType => {\n const { setLocaleDictionaries, setLocaleDictionary } =\n useDictionariesRecord();\n return { setLocaleDictionaries, setLocaleDictionary };\n };\n"],"mappings":";;;;;;;AAiBA,MAAa,8BAC6B;CACxC,MAAM,UAAUA,kDAAuB;CACvC,MAAM,CAAC,oBAAoB,kDACG,SAAS,mBAAmB,SAAS,EAAE,CAAC;AAEtE,4BAAgB;AACd,MAAI,CAAC,QAAS;EAEd,MAAM,WAAW,MACf,2BACG,EAAqC,UAAU,EAAE,CACnD;AAEH,UAAQ,mBAAmB,iBAAiB,UAAU,QAAQ;AAE9D,eACE,QAAQ,mBAAmB,oBAAoB,UAAU,QAAQ;IAClE,CAAC,QAAQ,CAAC;AAYb,QAAO;EAAE;EAAoB,+CAT1B,UAA6B,SAAS,mBAAmB,IAAI,MAAM,EACpE,CAAC,QAAQ,CACV;EAOmD,6CAJjD,eAA2B,SAAS,oBAAoB,WAAW,EACpE,CAAC,QAAQ,CACV;EAEwE;;AAG3E,MAAa,qCACiC;CAC1C,MAAM,EAAE,uBAAuB,wBAC7B,uBAAuB;AACzB,QAAO;EAAE;EAAuB;EAAqB"}
|
|
@@ -1,2 +1,56 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/EditedContentContext.tsx
|
|
8
|
+
const useEditedContentActions = () => {
|
|
9
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
10
|
+
return {
|
|
11
|
+
setEditedContentState: (value) => manager?.editedContent.set(value),
|
|
12
|
+
setEditedDictionary: (dict) => manager?.setEditedDictionary(dict),
|
|
13
|
+
setEditedContent: (localId, value) => manager?.setEditedContent(localId, value),
|
|
14
|
+
addEditedContent: (localId, value, keyPath, overwrite) => manager?.addContent(localId, value, keyPath, overwrite),
|
|
15
|
+
renameEditedContent: (localId, newKey, keyPath) => manager?.renameContent(localId, newKey, keyPath),
|
|
16
|
+
removeEditedContent: (localId, keyPath) => manager?.removeContent(localId, keyPath),
|
|
17
|
+
restoreEditedContent: (localId) => manager?.restoreContent(localId),
|
|
18
|
+
clearEditedDictionaryContent: (localId) => manager?.clearContent(localId),
|
|
19
|
+
clearEditedContent: () => manager?.clearAllContent(),
|
|
20
|
+
getEditedContentValue: (localIdOrKey, keyPath) => manager?.getContentValue(localIdOrKey, keyPath)
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const useEditedContent = () => {
|
|
24
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
25
|
+
const [editedContent, setEditedContentState] = (0, react.useState)(manager?.editedContent.value);
|
|
26
|
+
(0, react.useEffect)(() => {
|
|
27
|
+
if (!manager) return;
|
|
28
|
+
const handler = (e) => setEditedContentState(e.detail);
|
|
29
|
+
manager.editedContent.addEventListener("change", handler);
|
|
30
|
+
return () => manager.editedContent.removeEventListener("change", handler);
|
|
31
|
+
}, [manager]);
|
|
32
|
+
return {
|
|
33
|
+
editedContent,
|
|
34
|
+
...useEditedContentActions()
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const usePostEditedContentState = (onEventTriggered) => {
|
|
38
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
39
|
+
(0, react.useEffect)(() => {
|
|
40
|
+
if (!onEventTriggered || !manager) return;
|
|
41
|
+
return manager.messenger.subscribe(`INTLAYER_EDITED_CONTENT_CHANGED/post`, onEventTriggered);
|
|
42
|
+
}, [manager, onEventTriggered]);
|
|
43
|
+
};
|
|
44
|
+
const useGetEditedContentState = () => {
|
|
45
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
46
|
+
return () => {
|
|
47
|
+
manager?.messenger.send("INTLAYER_EDITED_CONTENT_CHANGED/get");
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.useEditedContent = useEditedContent;
|
|
53
|
+
exports.useEditedContentActions = useEditedContentActions;
|
|
54
|
+
exports.useGetEditedContentState = useGetEditedContentState;
|
|
55
|
+
exports.usePostEditedContentState = usePostEditedContentState;
|
|
2
56
|
//# sourceMappingURL=EditedContentContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.cjs","names":["useEditorStateManager"],"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport type { DictionaryContent } from '@intlayer/editor';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (editedContent: DictionaryContent) => void;\n setEditedDictionary: (dict: Dictionary) => void;\n setEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n localDictionaryId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedDictionaryContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nexport const useEditedContentActions = (): EditedContentActionsContextType => {\n const manager = useEditorStateManager();\n\n return {\n setEditedContentState: (value: DictionaryContent) =>\n manager?.editedContent.set(value),\n setEditedDictionary: (dict: Dictionary) =>\n manager?.setEditedDictionary(dict),\n setEditedContent: (\n localId: LocalDictionaryId,\n value: Dictionary['content']\n ) => manager?.setEditedContent(localId, value),\n addEditedContent: (localId, value, keyPath, overwrite) =>\n manager?.addContent(localId, value, keyPath, overwrite),\n renameEditedContent: (localId, newKey, keyPath) =>\n manager?.renameContent(localId, newKey, keyPath),\n removeEditedContent: (localId, keyPath) =>\n manager?.removeContent(localId, keyPath),\n restoreEditedContent: (localId) => manager?.restoreContent(localId),\n clearEditedDictionaryContent: (localId) => manager?.clearContent(localId),\n clearEditedContent: () => manager?.clearAllContent(),\n getEditedContentValue: (localIdOrKey, keyPath) =>\n manager?.getContentValue(localIdOrKey, keyPath),\n };\n};\n\nexport const useEditedContent = () => {\n const manager = useEditorStateManager();\n const [editedContent, setEditedContentState] = useState<\n DictionaryContent | undefined\n >(manager?.editedContent.value);\n\n useEffect(() => {\n if (!manager) return;\n const handler = (e: Event) =>\n setEditedContentState((e as CustomEvent<DictionaryContent>).detail);\n manager.editedContent.addEventListener('change', handler);\n return () => manager.editedContent.removeEventListener('change', handler);\n }, [manager]);\n\n const actions = useEditedContentActions();\n return { editedContent, ...actions };\n};\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) => {\n const manager = useEditorStateManager();\n useEffect(() => {\n if (!onEventTriggered || !manager) return;\n return manager.messenger.subscribe(\n `INTLAYER_EDITED_CONTENT_CHANGED/post`,\n onEventTriggered as (data: unknown) => void\n );\n }, [manager, onEventTriggered]);\n};\n\nexport const useGetEditedContentState = () => {\n const manager = useEditorStateManager();\n return () => {\n manager?.messenger.send('INTLAYER_EDITED_CONTENT_CHANGED/get');\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditedContentContext.cjs","names":["useEditorStateManager"],"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport type { DictionaryContent } from '@intlayer/editor';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (editedContent: DictionaryContent) => void;\n setEditedDictionary: (dict: Dictionary) => void;\n setEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n localDictionaryId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedDictionaryContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nexport const useEditedContentActions = (): EditedContentActionsContextType => {\n const manager = useEditorStateManager();\n\n return {\n setEditedContentState: (value: DictionaryContent) =>\n manager?.editedContent.set(value),\n setEditedDictionary: (dict: Dictionary) =>\n manager?.setEditedDictionary(dict),\n setEditedContent: (\n localId: LocalDictionaryId,\n value: Dictionary['content']\n ) => manager?.setEditedContent(localId, value),\n addEditedContent: (localId, value, keyPath, overwrite) =>\n manager?.addContent(localId, value, keyPath, overwrite),\n renameEditedContent: (localId, newKey, keyPath) =>\n manager?.renameContent(localId, newKey, keyPath),\n removeEditedContent: (localId, keyPath) =>\n manager?.removeContent(localId, keyPath),\n restoreEditedContent: (localId) => manager?.restoreContent(localId),\n clearEditedDictionaryContent: (localId) => manager?.clearContent(localId),\n clearEditedContent: () => manager?.clearAllContent(),\n getEditedContentValue: (localIdOrKey, keyPath) =>\n manager?.getContentValue(localIdOrKey, keyPath),\n };\n};\n\nexport const useEditedContent = () => {\n const manager = useEditorStateManager();\n const [editedContent, setEditedContentState] = useState<\n DictionaryContent | undefined\n >(manager?.editedContent.value);\n\n useEffect(() => {\n if (!manager) return;\n const handler = (e: Event) =>\n setEditedContentState((e as CustomEvent<DictionaryContent>).detail);\n manager.editedContent.addEventListener('change', handler);\n return () => manager.editedContent.removeEventListener('change', handler);\n }, [manager]);\n\n const actions = useEditedContentActions();\n return { editedContent, ...actions };\n};\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) => {\n const manager = useEditorStateManager();\n useEffect(() => {\n if (!onEventTriggered || !manager) return;\n return manager.messenger.subscribe(\n `INTLAYER_EDITED_CONTENT_CHANGED/post`,\n onEventTriggered as (data: unknown) => void\n );\n }, [manager, onEventTriggered]);\n};\n\nexport const useGetEditedContentState = () => {\n const manager = useEditorStateManager();\n return () => {\n manager?.messenger.send('INTLAYER_EDITED_CONTENT_CHANGED/get');\n };\n};\n"],"mappings":";;;;;;;AA6CA,MAAa,gCAAiE;CAC5E,MAAM,UAAUA,kDAAuB;AAEvC,QAAO;EACL,wBAAwB,UACtB,SAAS,cAAc,IAAI,MAAM;EACnC,sBAAsB,SACpB,SAAS,oBAAoB,KAAK;EACpC,mBACE,SACA,UACG,SAAS,iBAAiB,SAAS,MAAM;EAC9C,mBAAmB,SAAS,OAAO,SAAS,cAC1C,SAAS,WAAW,SAAS,OAAO,SAAS,UAAU;EACzD,sBAAsB,SAAS,QAAQ,YACrC,SAAS,cAAc,SAAS,QAAQ,QAAQ;EAClD,sBAAsB,SAAS,YAC7B,SAAS,cAAc,SAAS,QAAQ;EAC1C,uBAAuB,YAAY,SAAS,eAAe,QAAQ;EACnE,+BAA+B,YAAY,SAAS,aAAa,QAAQ;EACzE,0BAA0B,SAAS,iBAAiB;EACpD,wBAAwB,cAAc,YACpC,SAAS,gBAAgB,cAAc,QAAQ;EAClD;;AAGH,MAAa,yBAAyB;CACpC,MAAM,UAAUA,kDAAuB;CACvC,MAAM,CAAC,eAAe,6CAEpB,SAAS,cAAc,MAAM;AAE/B,4BAAgB;AACd,MAAI,CAAC,QAAS;EACd,MAAM,WAAW,MACf,sBAAuB,EAAqC,OAAO;AACrE,UAAQ,cAAc,iBAAiB,UAAU,QAAQ;AACzD,eAAa,QAAQ,cAAc,oBAAoB,UAAU,QAAQ;IACxE,CAAC,QAAQ,CAAC;AAGb,QAAO;EAAE;EAAe,GADR,yBAAyB;EACL;;AAGtC,MAAa,6BACX,qBACG;CACH,MAAM,UAAUA,kDAAuB;AACvC,4BAAgB;AACd,MAAI,CAAC,oBAAoB,CAAC,QAAS;AACnC,SAAO,QAAQ,UAAU,UACvB,wCACA,iBACD;IACA,CAAC,SAAS,iBAAiB,CAAC;;AAGjC,MAAa,iCAAiC;CAC5C,MAAM,UAAUA,kDAAuB;AACvC,cAAa;AACX,WAAS,UAAU,KAAK,sCAAsC"}
|
|
@@ -1,2 +1,67 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let _intlayer_editor = require("@intlayer/editor");
|
|
7
|
+
|
|
8
|
+
//#region src/EditorEnabledContext.tsx
|
|
9
|
+
/**
|
|
10
|
+
* Returns the current editor-enabled state, kept in sync with the shared
|
|
11
|
+
* EditorStateManager. Replaces the old EditorEnabledContext + EditorEnabledProvider.
|
|
12
|
+
*/
|
|
13
|
+
const useEditorEnabled = () => {
|
|
14
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
15
|
+
const [enabled, setEnabled] = (0, react.useState)(manager?.editorEnabled.value ?? false);
|
|
16
|
+
(0, react.useEffect)(() => {
|
|
17
|
+
if (!manager) return;
|
|
18
|
+
const handler = (e) => setEnabled(e.detail);
|
|
19
|
+
manager.editorEnabled.addEventListener("change", handler);
|
|
20
|
+
return () => manager.editorEnabled.removeEventListener("change", handler);
|
|
21
|
+
}, [manager]);
|
|
22
|
+
return { enabled };
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Subscribes to incoming "get" requests for editor-enabled state and calls
|
|
26
|
+
* the provided callback so the caller can respond.
|
|
27
|
+
* Used by the editor side to respond when the client asks for the current state.
|
|
28
|
+
*/
|
|
29
|
+
const useGetEditorEnabledState = (onRequest) => {
|
|
30
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
31
|
+
(0, react.useEffect)(() => {
|
|
32
|
+
if (!onRequest) return;
|
|
33
|
+
return manager?.messenger.subscribe(`${_intlayer_editor.MessageKey.INTLAYER_EDITOR_ENABLED}/get`, onRequest);
|
|
34
|
+
}, [manager, onRequest]);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Returns a function that sets the editor-enabled state and broadcasts it.
|
|
38
|
+
*/
|
|
39
|
+
const usePostEditorEnabledState = () => {
|
|
40
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
41
|
+
return (value) => {
|
|
42
|
+
manager?.editorEnabled.set(value);
|
|
43
|
+
manager?.editorEnabled.postCurrentValue();
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const useEditorEnabledState = () => {
|
|
47
|
+
const { enabled } = useEditorEnabled();
|
|
48
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
49
|
+
const setter = (value) => manager?.editorEnabled.set(value);
|
|
50
|
+
return [enabled, setter];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Returns a function that re-pings the client via ARE_YOU_THERE.
|
|
54
|
+
* Use this as the onClick for an "Enable Editor" / reconnect button.
|
|
55
|
+
*/
|
|
56
|
+
const useEditorPingClient = () => {
|
|
57
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
58
|
+
return () => manager?.pingClient();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.useEditorEnabled = useEditorEnabled;
|
|
63
|
+
exports.useEditorEnabledState = useEditorEnabledState;
|
|
64
|
+
exports.useEditorPingClient = useEditorPingClient;
|
|
65
|
+
exports.useGetEditorEnabledState = useGetEditorEnabledState;
|
|
66
|
+
exports.usePostEditorEnabledState = usePostEditorEnabledState;
|
|
2
67
|
//# sourceMappingURL=EditorEnabledContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorEnabledContext.cjs","names":["useEditorStateManager","MessageKey"],"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\n/**\n * Returns the current editor-enabled state, kept in sync with the shared\n * EditorStateManager. Replaces the old EditorEnabledContext + EditorEnabledProvider.\n */\nexport const useEditorEnabled = (): EditorEnabledStateProps => {\n const manager = useEditorStateManager();\n const [enabled, setEnabled] = useState<boolean>(\n manager?.editorEnabled.value ?? false\n );\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setEnabled((e as CustomEvent<boolean>).detail);\n manager.editorEnabled.addEventListener('change', handler);\n return () => manager.editorEnabled.removeEventListener('change', handler);\n }, [manager]);\n\n return { enabled };\n};\n\n/**\n * Subscribes to incoming \"get\" requests for editor-enabled state and calls\n * the provided callback so the caller can respond.\n * Used by the editor side to respond when the client asks for the current state.\n */\nexport const useGetEditorEnabledState = (onRequest?: () => void) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onRequest) return;\n\n return manager?.messenger.subscribe(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onRequest\n );\n }, [manager, onRequest]);\n};\n\n/**\n * Returns a function that sets the editor-enabled state and broadcasts it.\n */\nexport const usePostEditorEnabledState = () => {\n const manager = useEditorStateManager();\n\n return (value: boolean) => {\n manager?.editorEnabled.set(value);\n manager?.editorEnabled.postCurrentValue();\n };\n};\n\nexport const useEditorEnabledState = () => {\n const { enabled } = useEditorEnabled();\n const manager = useEditorStateManager();\n const setter = (value: boolean) => manager?.editorEnabled.set(value);\n\n return [enabled, setter] as const;\n};\n\n/**\n * Returns a function that re-pings the client via ARE_YOU_THERE.\n * Use this as the onClick for an \"Enable Editor\" / reconnect button.\n */\nexport const useEditorPingClient = (): (() => void) => {\n const manager = useEditorStateManager();\n\n return () => manager?.pingClient();\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorEnabledContext.cjs","names":["useEditorStateManager","MessageKey"],"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\n/**\n * Returns the current editor-enabled state, kept in sync with the shared\n * EditorStateManager. Replaces the old EditorEnabledContext + EditorEnabledProvider.\n */\nexport const useEditorEnabled = (): EditorEnabledStateProps => {\n const manager = useEditorStateManager();\n const [enabled, setEnabled] = useState<boolean>(\n manager?.editorEnabled.value ?? false\n );\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setEnabled((e as CustomEvent<boolean>).detail);\n manager.editorEnabled.addEventListener('change', handler);\n return () => manager.editorEnabled.removeEventListener('change', handler);\n }, [manager]);\n\n return { enabled };\n};\n\n/**\n * Subscribes to incoming \"get\" requests for editor-enabled state and calls\n * the provided callback so the caller can respond.\n * Used by the editor side to respond when the client asks for the current state.\n */\nexport const useGetEditorEnabledState = (onRequest?: () => void) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onRequest) return;\n\n return manager?.messenger.subscribe(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onRequest\n );\n }, [manager, onRequest]);\n};\n\n/**\n * Returns a function that sets the editor-enabled state and broadcasts it.\n */\nexport const usePostEditorEnabledState = () => {\n const manager = useEditorStateManager();\n\n return (value: boolean) => {\n manager?.editorEnabled.set(value);\n manager?.editorEnabled.postCurrentValue();\n };\n};\n\nexport const useEditorEnabledState = () => {\n const { enabled } = useEditorEnabled();\n const manager = useEditorStateManager();\n const setter = (value: boolean) => manager?.editorEnabled.set(value);\n\n return [enabled, setter] as const;\n};\n\n/**\n * Returns a function that re-pings the client via ARE_YOU_THERE.\n * Use this as the onClick for an \"Enable Editor\" / reconnect button.\n */\nexport const useEditorPingClient = (): (() => void) => {\n const manager = useEditorStateManager();\n\n return () => manager?.pingClient();\n};\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,yBAAkD;CAC7D,MAAM,UAAUA,kDAAuB;CACvC,MAAM,CAAC,SAAS,kCACd,SAAS,cAAc,SAAS,MACjC;AAED,4BAAgB;AACd,MAAI,CAAC,QAAS;EAEd,MAAM,WAAW,MACf,WAAY,EAA2B,OAAO;AAChD,UAAQ,cAAc,iBAAiB,UAAU,QAAQ;AACzD,eAAa,QAAQ,cAAc,oBAAoB,UAAU,QAAQ;IACxE,CAAC,QAAQ,CAAC;AAEb,QAAO,EAAE,SAAS;;;;;;;AAQpB,MAAa,4BAA4B,cAA2B;CAClE,MAAM,UAAUA,kDAAuB;AAEvC,4BAAgB;AACd,MAAI,CAAC,UAAW;AAEhB,SAAO,SAAS,UAAU,UACxB,GAAGC,4BAAW,wBAAwB,OACtC,UACD;IACA,CAAC,SAAS,UAAU,CAAC;;;;;AAM1B,MAAa,kCAAkC;CAC7C,MAAM,UAAUD,kDAAuB;AAEvC,SAAQ,UAAmB;AACzB,WAAS,cAAc,IAAI,MAAM;AACjC,WAAS,cAAc,kBAAkB;;;AAI7C,MAAa,8BAA8B;CACzC,MAAM,EAAE,YAAY,kBAAkB;CACtC,MAAM,UAAUA,kDAAuB;CACvC,MAAM,UAAU,UAAmB,SAAS,cAAc,IAAI,MAAM;AAEpE,QAAO,CAAC,SAAS,OAAO;;;;;;AAO1B,MAAa,4BAA0C;CACrD,MAAM,UAAUA,kDAAuB;AAEvC,cAAa,SAAS,YAAY"}
|
|
@@ -1,2 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
let _intlayer_editor = require("@intlayer/editor");
|
|
8
|
+
|
|
9
|
+
//#region src/EditorProvider.tsx
|
|
10
|
+
/**
|
|
11
|
+
* EditorProvider creates and manages the lifecycle of an EditorStateManager,
|
|
12
|
+
* provides it to all descendants, and registers the Lit web components.
|
|
13
|
+
*/
|
|
14
|
+
const EditorProvider = ({ children, configuration, postMessage, allowedOrigins }) => {
|
|
15
|
+
const managerRef = (0, react.useRef)(null);
|
|
16
|
+
if (!managerRef.current) managerRef.current = new _intlayer_editor.EditorStateManager({
|
|
17
|
+
mode: "editor",
|
|
18
|
+
messenger: {
|
|
19
|
+
allowedOrigins,
|
|
20
|
+
postMessageFn: postMessage
|
|
21
|
+
},
|
|
22
|
+
configuration
|
|
23
|
+
});
|
|
24
|
+
const manager = managerRef.current;
|
|
25
|
+
(0, react.useEffect)(() => {
|
|
26
|
+
(0, _intlayer_editor.defineIntlayerElements)();
|
|
27
|
+
(0, _intlayer_editor.setGlobalEditorManager)(manager);
|
|
28
|
+
manager.start();
|
|
29
|
+
return () => {
|
|
30
|
+
manager.stop();
|
|
31
|
+
(0, _intlayer_editor.setGlobalEditorManager)(null);
|
|
32
|
+
};
|
|
33
|
+
}, [manager]);
|
|
34
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_EditorStateContext.EditorStateProvider, {
|
|
35
|
+
manager,
|
|
36
|
+
children
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.EditorProvider = EditorProvider;
|
|
2
42
|
//# sourceMappingURL=EditorProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorProvider.cjs","names":["EditorStateManager","EditorStateProvider"],"sources":["../../src/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n defineIntlayerElements,\n EditorStateManager,\n type MessengerConfig,\n setGlobalEditorManager,\n} from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FC, type PropsWithChildren, useEffect, useRef } from 'react';\nimport { EditorStateProvider } from './EditorStateContext';\n\nexport type EditorProviderProps = {\n configuration: IntlayerConfig;\n postMessage: (data: any) => void;\n allowedOrigins: string[];\n};\n\n/**\n * EditorProvider creates and manages the lifecycle of an EditorStateManager,\n * provides it to all descendants, and registers the Lit web components.\n */\nexport const EditorProvider: FC<PropsWithChildren<EditorProviderProps>> = ({\n children,\n configuration,\n postMessage,\n allowedOrigins,\n}) => {\n const managerRef = useRef<EditorStateManager | null>(null);\n\n if (!managerRef.current) {\n const messengerConfig: MessengerConfig = {\n allowedOrigins,\n postMessageFn: postMessage,\n };\n\n managerRef.current = new EditorStateManager({\n mode: 'editor',\n messenger: messengerConfig,\n configuration,\n });\n }\n const manager = managerRef.current;\n\n useEffect(() => {\n defineIntlayerElements();\n setGlobalEditorManager(manager);\n\n manager.start();\n return () => {\n manager.stop();\n setGlobalEditorManager(null);\n };\n }, [manager]);\n\n return (\n <EditorStateProvider manager={manager}>{children}</EditorStateProvider>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorProvider.cjs","names":["EditorStateManager","EditorStateProvider"],"sources":["../../src/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n defineIntlayerElements,\n EditorStateManager,\n type MessengerConfig,\n setGlobalEditorManager,\n} from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FC, type PropsWithChildren, useEffect, useRef } from 'react';\nimport { EditorStateProvider } from './EditorStateContext';\n\nexport type EditorProviderProps = {\n configuration: IntlayerConfig;\n postMessage: (data: any) => void;\n allowedOrigins: string[];\n};\n\n/**\n * EditorProvider creates and manages the lifecycle of an EditorStateManager,\n * provides it to all descendants, and registers the Lit web components.\n */\nexport const EditorProvider: FC<PropsWithChildren<EditorProviderProps>> = ({\n children,\n configuration,\n postMessage,\n allowedOrigins,\n}) => {\n const managerRef = useRef<EditorStateManager | null>(null);\n\n if (!managerRef.current) {\n const messengerConfig: MessengerConfig = {\n allowedOrigins,\n postMessageFn: postMessage,\n };\n\n managerRef.current = new EditorStateManager({\n mode: 'editor',\n messenger: messengerConfig,\n configuration,\n });\n }\n const manager = managerRef.current;\n\n useEffect(() => {\n defineIntlayerElements();\n setGlobalEditorManager(manager);\n\n manager.start();\n return () => {\n manager.stop();\n setGlobalEditorManager(null);\n };\n }, [manager]);\n\n return (\n <EditorStateProvider manager={manager}>{children}</EditorStateProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;AAsBA,MAAa,kBAA8D,EACzE,UACA,eACA,aACA,qBACI;CACJ,MAAM,+BAA+C,KAAK;AAE1D,KAAI,CAAC,WAAW,QAMd,YAAW,UAAU,IAAIA,oCAAmB;EAC1C,MAAM;EACN,WAPuC;GACvC;GACA,eAAe;GAChB;EAKC;EACD,CAAC;CAEJ,MAAM,UAAU,WAAW;AAE3B,4BAAgB;AACd,gDAAwB;AACxB,+CAAuB,QAAQ;AAE/B,UAAQ,OAAO;AACf,eAAa;AACX,WAAQ,MAAM;AACd,gDAAuB,KAAK;;IAE7B,CAAC,QAAQ,CAAC;AAEb,QACE,2CAACC,gDAAD;EAA8B;EAAU;EAA+B"}
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
let react = require("react");
|
|
5
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
+
|
|
7
|
+
//#region src/EditorStateContext.tsx
|
|
8
|
+
const EditorStateContext = (0, react.createContext)(null);
|
|
9
|
+
const EditorStateProvider = ({ children, manager }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EditorStateContext.Provider, {
|
|
10
|
+
value: manager,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
const useEditorStateManager = () => (0, react.useContext)(EditorStateContext);
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.EditorStateProvider = EditorStateProvider;
|
|
17
|
+
exports.useEditorStateManager = useEditorStateManager;
|
|
2
18
|
//# sourceMappingURL=EditorStateContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorStateContext.cjs","names":[],"sources":["../../src/EditorStateContext.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\n\nconst EditorStateContext = createContext<EditorStateManager | null>(null);\n\nexport const EditorStateProvider: FC<\n PropsWithChildren<{ manager: EditorStateManager }>\n> = ({ children, manager }) => (\n <EditorStateContext.Provider value={manager}>\n {children}\n </EditorStateContext.Provider>\n);\n\nexport const useEditorStateManager = (): EditorStateManager | null =>\n useContext(EditorStateContext);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorStateContext.cjs","names":[],"sources":["../../src/EditorStateContext.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\n\nconst EditorStateContext = createContext<EditorStateManager | null>(null);\n\nexport const EditorStateProvider: FC<\n PropsWithChildren<{ manager: EditorStateManager }>\n> = ({ children, manager }) => (\n <EditorStateContext.Provider value={manager}>\n {children}\n </EditorStateContext.Provider>\n);\n\nexport const useEditorStateManager = (): EditorStateManager | null =>\n useContext(EditorStateContext);\n"],"mappings":";;;;;;;AAUA,MAAM,8CAA8D,KAAK;AAEzE,MAAa,uBAER,EAAE,UAAU,cACf,2CAAC,mBAAmB,UAApB;CAA6B,OAAO;CACjC;CAC2B;AAGhC,MAAa,oDACA,mBAAmB"}
|
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/FocusDictionaryContext.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Returns the focused-content state and setters, backed by EditorStateManager.
|
|
10
|
+
*/
|
|
11
|
+
const useFocusDictionary = () => {
|
|
12
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
13
|
+
const [focusedContent, setFocusedContentState] = (0, react.useState)(manager?.focusedContent.value ?? null);
|
|
14
|
+
(0, react.useEffect)(() => {
|
|
15
|
+
if (!manager) return;
|
|
16
|
+
const handler = (e) => setFocusedContentState(e.detail);
|
|
17
|
+
manager.focusedContent.addEventListener("change", handler);
|
|
18
|
+
return () => manager.focusedContent.removeEventListener("change", handler);
|
|
19
|
+
}, [manager]);
|
|
20
|
+
return {
|
|
21
|
+
focusedContent,
|
|
22
|
+
setFocusedContent: (value) => manager?.focusedContent.set(value),
|
|
23
|
+
setFocusedContentKeyPath: (keyPath) => manager?.setFocusedContentKeyPath(keyPath)
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const useFocusDictionaryActions = () => {
|
|
27
|
+
const { setFocusedContent, setFocusedContentKeyPath } = useFocusDictionary();
|
|
28
|
+
return {
|
|
29
|
+
setFocusedContent,
|
|
30
|
+
setFocusedContentKeyPath
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.useFocusDictionary = useFocusDictionary;
|
|
36
|
+
exports.useFocusDictionaryActions = useFocusDictionaryActions;
|
|
2
37
|
//# sourceMappingURL=FocusDictionaryContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.cjs","names":["useEditorStateManager"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { FileContent } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { FileContent } from '@intlayer/editor';\n\nexport type FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\nexport type FocusDictionaryActions = {\n setFocusedContent: (value: FileContent | null) => void;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\n/**\n * Returns the focused-content state and setters, backed by EditorStateManager.\n */\nexport const useFocusDictionary = (): FocusDictionaryState &\n FocusDictionaryActions => {\n const manager = useEditorStateManager();\n const [focusedContent, setFocusedContentState] = useState<FileContent | null>(\n manager?.focusedContent.value ?? null\n );\n\n useEffect(() => {\n if (!manager) return;\n const handler = (e: Event) =>\n setFocusedContentState((e as CustomEvent<FileContent | null>).detail);\n manager.focusedContent.addEventListener('change', handler);\n return () => manager.focusedContent.removeEventListener('change', handler);\n }, [manager]);\n\n return {\n focusedContent,\n setFocusedContent: (value: FileContent | null) =>\n manager?.focusedContent.set(value),\n setFocusedContentKeyPath: (keyPath: KeyPath[]) =>\n manager?.setFocusedContentKeyPath(keyPath),\n };\n};\n\nexport const useFocusDictionaryActions = (): FocusDictionaryActions => {\n const { setFocusedContent, setFocusedContentKeyPath } = useFocusDictionary();\n return { setFocusedContent, setFocusedContentKeyPath };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.cjs","names":["useEditorStateManager"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { FileContent } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { FileContent } from '@intlayer/editor';\n\nexport type FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\nexport type FocusDictionaryActions = {\n setFocusedContent: (value: FileContent | null) => void;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\n/**\n * Returns the focused-content state and setters, backed by EditorStateManager.\n */\nexport const useFocusDictionary = (): FocusDictionaryState &\n FocusDictionaryActions => {\n const manager = useEditorStateManager();\n const [focusedContent, setFocusedContentState] = useState<FileContent | null>(\n manager?.focusedContent.value ?? null\n );\n\n useEffect(() => {\n if (!manager) return;\n const handler = (e: Event) =>\n setFocusedContentState((e as CustomEvent<FileContent | null>).detail);\n manager.focusedContent.addEventListener('change', handler);\n return () => manager.focusedContent.removeEventListener('change', handler);\n }, [manager]);\n\n return {\n focusedContent,\n setFocusedContent: (value: FileContent | null) =>\n manager?.focusedContent.set(value),\n setFocusedContentKeyPath: (keyPath: KeyPath[]) =>\n manager?.setFocusedContentKeyPath(keyPath),\n };\n};\n\nexport const useFocusDictionaryActions = (): FocusDictionaryActions => {\n const { setFocusedContent, setFocusedContentKeyPath } = useFocusDictionary();\n return { setFocusedContent, setFocusedContentKeyPath };\n};\n"],"mappings":";;;;;;;;;;AAqBA,MAAa,2BACe;CAC1B,MAAM,UAAUA,kDAAuB;CACvC,MAAM,CAAC,gBAAgB,8CACrB,SAAS,eAAe,SAAS,KAClC;AAED,4BAAgB;AACd,MAAI,CAAC,QAAS;EACd,MAAM,WAAW,MACf,uBAAwB,EAAsC,OAAO;AACvE,UAAQ,eAAe,iBAAiB,UAAU,QAAQ;AAC1D,eAAa,QAAQ,eAAe,oBAAoB,UAAU,QAAQ;IACzE,CAAC,QAAQ,CAAC;AAEb,QAAO;EACL;EACA,oBAAoB,UAClB,SAAS,eAAe,IAAI,MAAM;EACpC,2BAA2B,YACzB,SAAS,yBAAyB,QAAQ;EAC7C;;AAGH,MAAa,kCAA0D;CACrE,MAAM,EAAE,mBAAmB,6BAA6B,oBAAoB;AAC5E,QAAO;EAAE;EAAmB;EAA0B"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1,52 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
3
|
+
const require_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
|
|
4
|
+
const require_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
5
|
+
const require_useCrossURLPathState = require('./useCrossURLPathState.cjs');
|
|
6
|
+
const require_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
|
|
7
|
+
const require_useEditorLocale = require('./useEditorLocale.cjs');
|
|
8
|
+
const require_useFocusUnmergedDictionary = require('./useFocusUnmergedDictionary.cjs');
|
|
9
|
+
const require_EditorProvider = require('./EditorProvider.cjs');
|
|
10
|
+
const require_CommunicatorContext = require('./CommunicatorContext.cjs');
|
|
11
|
+
const require_ConfigurationContext = require('./ConfigurationContext.cjs');
|
|
12
|
+
const require_EditedContentContext = require('./EditedContentContext.cjs');
|
|
13
|
+
const require_EditorEnabledContext = require('./EditorEnabledContext.cjs');
|
|
14
|
+
const require_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
|
|
15
|
+
const require_useIframeClickInterceptor = require('./useIframeClickInterceptor.cjs');
|
|
16
|
+
let _intlayer_editor = require("@intlayer/editor");
|
|
17
|
+
|
|
18
|
+
exports.ConfigurationProvider = require_ConfigurationContext.ConfigurationProvider;
|
|
19
|
+
exports.EditorProvider = require_EditorProvider.EditorProvider;
|
|
20
|
+
exports.EditorStateProvider = require_EditorStateContext.EditorStateProvider;
|
|
21
|
+
Object.defineProperty(exports, 'MessageKey', {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _intlayer_editor.MessageKey;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
exports.useCommunicator = require_CommunicatorContext.useCommunicator;
|
|
28
|
+
exports.useConfiguration = require_ConfigurationContext.useConfiguration;
|
|
29
|
+
exports.useConfigurationState = require_ConfigurationContext.useConfigurationState;
|
|
30
|
+
exports.useCrossFrameMessageListener = require_useCrossFrameMessageListener.useCrossFrameMessageListener;
|
|
31
|
+
exports.useCrossFrameState = require_useCrossFrameState.useCrossFrameState;
|
|
32
|
+
exports.useCrossURLPathSetter = require_useCrossURLPathState.useCrossURLPathSetter;
|
|
33
|
+
exports.useCrossURLPathState = require_useCrossURLPathState.useCrossURLPathState;
|
|
34
|
+
exports.useDictionariesRecord = require_DictionariesRecordContext.useDictionariesRecord;
|
|
35
|
+
exports.useDictionariesRecordActions = require_DictionariesRecordContext.useDictionariesRecordActions;
|
|
36
|
+
exports.useEditedContent = require_EditedContentContext.useEditedContent;
|
|
37
|
+
exports.useEditedContentActions = require_EditedContentContext.useEditedContentActions;
|
|
38
|
+
exports.useEditorEnabled = require_EditorEnabledContext.useEditorEnabled;
|
|
39
|
+
exports.useEditorEnabledState = require_EditorEnabledContext.useEditorEnabledState;
|
|
40
|
+
exports.useEditorLocale = require_useEditorLocale.useEditorLocale;
|
|
41
|
+
exports.useEditorPingClient = require_EditorEnabledContext.useEditorPingClient;
|
|
42
|
+
exports.useEditorStateManager = require_EditorStateContext.useEditorStateManager;
|
|
43
|
+
exports.useFocusDictionary = require_FocusDictionaryContext.useFocusDictionary;
|
|
44
|
+
exports.useFocusDictionaryActions = require_FocusDictionaryContext.useFocusDictionaryActions;
|
|
45
|
+
exports.useFocusUnmergedDictionary = require_useFocusUnmergedDictionary.useFocusUnmergedDictionary;
|
|
46
|
+
exports.useGetEditedContentState = require_EditedContentContext.useGetEditedContentState;
|
|
47
|
+
exports.useGetEditorEnabledState = require_EditorEnabledContext.useGetEditorEnabledState;
|
|
48
|
+
exports.useIframeClickInterceptor = require_useIframeClickInterceptor.useIframeClickInterceptor;
|
|
49
|
+
exports.useIframeClickMerger = require_useIframeClickInterceptor.useIframeClickMerger;
|
|
50
|
+
exports.usePostEditedContentState = require_EditedContentContext.usePostEditedContentState;
|
|
51
|
+
exports.usePostEditorEnabledState = require_EditorEnabledContext.usePostEditorEnabledState;
|
|
52
|
+
exports.useSetEditorLocale = require_useEditorLocale.useSetEditorLocale;
|
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/useCrossFrameMessageListener.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Listens for cross-frame messages of the specified type and calls the callback.
|
|
10
|
+
* Returns a function to manually send a message of the same type.
|
|
11
|
+
*
|
|
12
|
+
* Backed by CrossFrameMessenger from EditorStateManager.
|
|
13
|
+
*/
|
|
14
|
+
const useCrossFrameMessageListener = (key, onEventTriggered, revalidator) => {
|
|
15
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
16
|
+
(0, react.useEffect)(() => {
|
|
17
|
+
if (!onEventTriggered) return;
|
|
18
|
+
return manager?.messenger.subscribe(key, onEventTriggered);
|
|
19
|
+
}, [
|
|
20
|
+
manager,
|
|
21
|
+
key,
|
|
22
|
+
revalidator
|
|
23
|
+
]);
|
|
24
|
+
return (data) => {
|
|
25
|
+
manager?.messenger.send(key, data);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.useCrossFrameMessageListener = useCrossFrameMessageListener;
|
|
2
31
|
//# sourceMappingURL=useCrossFrameMessageListener.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useEditorStateManager"],"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport type { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\n/**\n * Listens for cross-frame messages of the specified type and calls the callback.\n * Returns a function to manually send a message of the same type.\n *\n * Backed by CrossFrameMessenger from EditorStateManager.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onEventTriggered) return;\n return manager?.messenger.subscribe<S>(key, onEventTriggered);\n }, [manager, key, revalidator]);\n\n return (data?: S) => {\n manager?.messenger.send(key, data);\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useEditorStateManager"],"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport type { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\n/**\n * Listens for cross-frame messages of the specified type and calls the callback.\n * Returns a function to manually send a message of the same type.\n *\n * Backed by CrossFrameMessenger from EditorStateManager.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onEventTriggered) return;\n return manager?.messenger.subscribe<S>(key, onEventTriggered);\n }, [manager, key, revalidator]);\n\n return (data?: S) => {\n manager?.messenger.send(key, data);\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,gCACX,KACA,kBACA,gBACG;CACH,MAAM,UAAUA,kDAAuB;AAEvC,4BAAgB;AACd,MAAI,CAAC,iBAAkB;AACvB,SAAO,SAAS,UAAU,UAAa,KAAK,iBAAiB;IAC5D;EAAC;EAAS;EAAK;EAAY,CAAC;AAE/B,SAAQ,SAAa;AACnB,WAAS,UAAU,KAAK,KAAK,KAAK"}
|