@intlayer/editor-react 9.5.11 → 9.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ConfigurationContext.cjs +10 -39
- package/dist/cjs/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/EditedContentContext.cjs +0 -17
- package/dist/cjs/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/EditorEnabledContext.cjs +0 -32
- package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/FocusDictionaryContext.cjs +11 -59
- package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/index.cjs +4 -20
- package/dist/cjs/useCrossFrameState.cjs +5 -50
- package/dist/cjs/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/useCrossURLPathState.cjs +4 -8
- package/dist/cjs/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/useEditedContentPersistence.cjs +33 -0
- package/dist/cjs/useEditedContentPersistence.cjs.map +1 -0
- package/dist/cjs/useEditorLocale.cjs +0 -5
- package/dist/cjs/useEditorLocale.cjs.map +1 -1
- package/dist/esm/ConfigurationContext.mjs +12 -39
- package/dist/esm/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/EditedContentContext.mjs +1 -16
- package/dist/esm/EditedContentContext.mjs.map +1 -1
- package/dist/esm/EditorEnabledContext.mjs +1 -30
- package/dist/esm/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/FocusDictionaryContext.mjs +13 -57
- package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/index.mjs +8 -10
- package/dist/esm/useCrossFrameState.mjs +6 -51
- package/dist/esm/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/useCrossURLPathState.mjs +5 -8
- package/dist/esm/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/useEditedContentPersistence.mjs +32 -0
- package/dist/esm/useEditedContentPersistence.mjs.map +1 -0
- package/dist/esm/useEditorLocale.mjs +1 -5
- package/dist/esm/useEditorLocale.mjs.map +1 -1
- package/dist/types/ConfigurationContext.d.ts +3 -6
- package/dist/types/ConfigurationContext.d.ts.map +1 -1
- package/dist/types/EditedContentContext.d.ts +0 -6
- package/dist/types/EditedContentContext.d.ts.map +1 -1
- package/dist/types/EditorEnabledContext.d.ts +0 -11
- package/dist/types/EditorEnabledContext.d.ts.map +1 -1
- package/dist/types/FocusDictionaryContext.d.ts +6 -7
- package/dist/types/FocusDictionaryContext.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -11
- package/dist/types/useCrossFrameState.d.ts +2 -7
- package/dist/types/useCrossFrameState.d.ts.map +1 -1
- package/dist/types/useCrossURLPathState.d.ts +4 -3
- package/dist/types/useCrossURLPathState.d.ts.map +1 -1
- package/dist/types/useEditedContentPersistence.d.ts +8 -0
- package/dist/types/useEditedContentPersistence.d.ts.map +1 -0
- package/dist/types/useEditorLocale.d.ts +0 -1
- package/dist/types/useEditorLocale.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/cjs/CommunicatorContext.cjs +0 -20
- package/dist/cjs/CommunicatorContext.cjs.map +0 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +0 -28
- package/dist/cjs/useCrossFrameMessageListener.cjs +0 -31
- package/dist/cjs/useCrossFrameMessageListener.cjs.map +0 -1
- package/dist/cjs/useIframeClickInterceptor.cjs +0 -28
- package/dist/cjs/useIframeClickInterceptor.cjs.map +0 -1
- package/dist/esm/CommunicatorContext.mjs +0 -19
- package/dist/esm/CommunicatorContext.mjs.map +0 -1
- package/dist/esm/useCrossFrameMessageListener.mjs +0 -30
- package/dist/esm/useCrossFrameMessageListener.mjs.map +0 -1
- package/dist/esm/useIframeClickInterceptor.mjs +0 -26
- package/dist/esm/useIframeClickInterceptor.mjs.map +0 -1
- package/dist/types/CommunicatorContext.d.ts +0 -14
- package/dist/types/CommunicatorContext.d.ts.map +0 -1
- package/dist/types/useCrossFrameMessageListener.d.ts +0 -11
- package/dist/types/useCrossFrameMessageListener.d.ts.map +0 -1
- package/dist/types/useIframeClickInterceptor.d.ts +0 -15
- package/dist/types/useIframeClickInterceptor.d.ts.map +0 -1
|
@@ -3,52 +3,23 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
5
|
let react = require("react");
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
6
|
|
|
8
7
|
//#region src/ConfigurationContext.tsx
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(0, react.useEffect)(() => {
|
|
13
|
-
if (!manager || !configuration) return;
|
|
14
|
-
manager.configuration.set(configuration);
|
|
15
|
-
}, [manager, configuration]);
|
|
16
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConfigurationReactContext.Provider, {
|
|
17
|
-
value: configuration,
|
|
18
|
-
children
|
|
19
|
-
});
|
|
20
|
-
};
|
|
8
|
+
/**
|
|
9
|
+
* Returns the Intlayer configuration held by the editor state manager.
|
|
10
|
+
*/
|
|
21
11
|
const useConfiguration = () => {
|
|
22
12
|
const manager = require_EditorStateContext.useEditorStateManager();
|
|
23
|
-
const
|
|
24
|
-
const [config, setConfig] = (0, react.useState)(manager?.configuration.value ?? reactConfig);
|
|
13
|
+
const [configuration, setConfiguration] = (0, react.useState)(manager?.configuration.value);
|
|
25
14
|
(0, react.useEffect)(() => {
|
|
26
|
-
if (!manager)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
setConfig(detail ?? reactConfig);
|
|
33
|
-
};
|
|
34
|
-
manager.configuration.addEventListener("change", handler);
|
|
35
|
-
return () => manager.configuration.removeEventListener("change", handler);
|
|
36
|
-
}, [manager, reactConfig]);
|
|
37
|
-
return config ?? reactConfig;
|
|
38
|
-
};
|
|
39
|
-
const useConfigurationState = () => {
|
|
40
|
-
const manager = require_EditorStateContext.useEditorStateManager();
|
|
41
|
-
const reactConfig = (0, react.useContext)(ConfigurationReactContext);
|
|
42
|
-
const [config, setConfig] = (0, react.useState)(manager?.configuration.value ?? reactConfig);
|
|
43
|
-
return [
|
|
44
|
-
config ?? reactConfig,
|
|
45
|
-
setConfig,
|
|
46
|
-
() => manager?.configuration.postCurrentValue()
|
|
47
|
-
];
|
|
15
|
+
if (!manager) return;
|
|
16
|
+
const handleChange = (event) => setConfiguration(event.detail);
|
|
17
|
+
manager.configuration.addEventListener("change", handleChange);
|
|
18
|
+
return () => manager.configuration.removeEventListener("change", handleChange);
|
|
19
|
+
}, [manager]);
|
|
20
|
+
return configuration;
|
|
48
21
|
};
|
|
49
22
|
|
|
50
23
|
//#endregion
|
|
51
|
-
exports.ConfigurationProvider = ConfigurationProvider;
|
|
52
24
|
exports.useConfiguration = useConfiguration;
|
|
53
|
-
exports.useConfigurationState = useConfigurationState;
|
|
54
25
|
//# sourceMappingURL=ConfigurationContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.cjs","names":["
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.cjs","names":["useEditorStateManager","useState"],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\n/**\n * Returns the Intlayer configuration held by the editor state manager.\n */\nexport const useConfiguration = (): IntlayerConfig | undefined => {\n const manager = useEditorStateManager();\n const [configuration, setConfiguration] = useState<\n IntlayerConfig | undefined\n >(manager?.configuration.value as IntlayerConfig | undefined);\n\n useEffect(() => {\n if (!manager) return;\n\n const handleChange = (event: Event) =>\n setConfiguration((event as CustomEvent<IntlayerConfig>).detail);\n\n manager.configuration.addEventListener('change', handleChange);\n\n return () =>\n manager.configuration.removeEventListener('change', handleChange);\n }, [manager]);\n\n return configuration;\n};\n"],"mappings":";;;;;;;;;;AASA,MAAa,yBAAqD;CAChE,MAAM,UAAUA,iDAAsB;CACtC,MAAM,CAAC,eAAe,wBAAoBC,gBAExC,SAAS,cAAc,KAAmC;CAE5D,2BAAgB;EACd,IAAI,CAAC,SAAS;EAEd,MAAM,gBAAgB,UACpB,iBAAkB,MAAsC,MAAM;EAEhE,QAAQ,cAAc,iBAAiB,UAAU,YAAY;EAE7D,aACE,QAAQ,cAAc,oBAAoB,UAAU,YAAY;CACpE,GAAG,CAAC,OAAO,CAAC;CAEZ,OAAO;AACT"}
|
|
@@ -15,8 +15,6 @@ const useEditedContentActions = () => {
|
|
|
15
15
|
renameEditedContent: (localId, newKey, keyPath) => manager?.renameContent(localId, newKey, keyPath),
|
|
16
16
|
removeEditedContent: (localId, keyPath) => manager?.removeContent(localId, keyPath),
|
|
17
17
|
restoreEditedContent: (localId) => manager?.restoreContent(localId),
|
|
18
|
-
clearEditedDictionaryContent: (localId) => manager?.clearContent(localId),
|
|
19
|
-
clearEditedContent: () => manager?.clearAllContent(),
|
|
20
18
|
getEditedContentValue: (localIdOrKey, keyPath) => manager?.getContentValue(localIdOrKey, keyPath)
|
|
21
19
|
};
|
|
22
20
|
};
|
|
@@ -34,23 +32,8 @@ const useEditedContent = () => {
|
|
|
34
32
|
...useEditedContentActions()
|
|
35
33
|
};
|
|
36
34
|
};
|
|
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
35
|
|
|
51
36
|
//#endregion
|
|
52
37
|
exports.useEditedContent = useEditedContent;
|
|
53
38
|
exports.useEditedContentActions = useEditedContentActions;
|
|
54
|
-
exports.useGetEditedContentState = useGetEditedContentState;
|
|
55
|
-
exports.usePostEditedContentState = usePostEditedContentState;
|
|
56
39
|
//# sourceMappingURL=EditedContentContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.cjs","names":["useEditorStateManager","useState"],"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
|
|
1
|
+
{"version":3,"file":"EditedContentContext.cjs","names":["useEditorStateManager","useState"],"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 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 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"],"mappings":";;;;;;;AA2CA,MAAa,gCAAiE;CAC5E,MAAM,UAAUA,iDAAsB;CAEtC,OAAO;EACL,wBAAwB,UACtB,SAAS,cAAc,IAAI,KAAK;EAClC,sBAAsB,SACpB,SAAS,oBAAoB,IAAI;EACnC,mBACE,SACA,UACG,SAAS,iBAAiB,SAAS,KAAK;EAC7C,mBAAmB,SAAS,OAAO,SAAS,cAC1C,SAAS,WAAW,SAAS,OAAO,SAAS,SAAS;EACxD,sBAAsB,SAAS,QAAQ,YACrC,SAAS,cAAc,SAAS,QAAQ,OAAO;EACjD,sBAAsB,SAAS,YAC7B,SAAS,cAAc,SAAS,OAAO;EACzC,uBAAuB,YAAY,SAAS,eAAe,OAAO;EAClE,wBAAwB,cAAc,YACpC,SAAS,gBAAgB,cAAc,OAAO;CAClD;AACF;AAEA,MAAa,yBAAyB;CACpC,MAAM,UAAUA,iDAAsB;CACtC,MAAM,CAAC,eAAe,6BAAyBC,gBAE7C,SAAS,cAAc,KAAK;CAE9B,2BAAgB;EACd,IAAI,CAAC,SAAS;EACd,MAAM,WAAW,MACf,sBAAuB,EAAqC,MAAM;EACpE,QAAQ,cAAc,iBAAiB,UAAU,OAAO;EACxD,aAAa,QAAQ,cAAc,oBAAoB,UAAU,OAAO;CAC1E,GAAG,CAAC,OAAO,CAAC;CAGZ,OAAO;EAAE;EAAe,GADR,wBACiB;CAAE;AACrC"}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
5
|
let react = require("react");
|
|
6
|
-
let _intlayer_editor = require("@intlayer/editor");
|
|
7
6
|
|
|
8
7
|
//#region src/EditorEnabledContext.tsx
|
|
9
8
|
/**
|
|
@@ -22,34 +21,6 @@ const useEditorEnabled = () => {
|
|
|
22
21
|
return { enabled };
|
|
23
22
|
};
|
|
24
23
|
/**
|
|
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
24
|
* Returns a function that re-pings the client via ARE_YOU_THERE.
|
|
54
25
|
* Use this as the onClick for an "Enable Editor" / reconnect button.
|
|
55
26
|
*/
|
|
@@ -60,8 +31,5 @@ const useEditorPingClient = () => {
|
|
|
60
31
|
|
|
61
32
|
//#endregion
|
|
62
33
|
exports.useEditorEnabled = useEditorEnabled;
|
|
63
|
-
exports.useEditorEnabledState = useEditorEnabledState;
|
|
64
34
|
exports.useEditorPingClient = useEditorPingClient;
|
|
65
|
-
exports.useGetEditorEnabledState = useGetEditorEnabledState;
|
|
66
|
-
exports.usePostEditorEnabledState = usePostEditorEnabledState;
|
|
67
35
|
//# sourceMappingURL=EditorEnabledContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorEnabledContext.cjs","names":["useEditorStateManager","useState"
|
|
1
|
+
{"version":3,"file":"EditorEnabledContext.cjs","names":["useEditorStateManager","useState"],"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\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 * 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":";;;;;;;;;;;AAaA,MAAa,yBAAkD;CAC7D,MAAM,UAAUA,iDAAsB;CACtC,MAAM,CAAC,SAAS,kBAAcC,gBAC5B,SAAS,cAAc,SAAS,KAClC;CAEA,2BAAgB;EACd,IAAI,CAAC,SAAS;EAEd,MAAM,WAAW,MACf,WAAY,EAA2B,MAAM;EAC/C,QAAQ,cAAc,iBAAiB,UAAU,OAAO;EACxD,aAAa,QAAQ,cAAc,oBAAoB,UAAU,OAAO;CAC1E,GAAG,CAAC,OAAO,CAAC;CAEZ,OAAO,EAAE,QAAQ;AACnB;;;;;AAMA,MAAa,4BAA0C;CACrD,MAAM,UAAUD,iDAAsB;CAEtC,aAAa,SAAS,WAAW;AACnC"}
|
|
@@ -1,77 +1,29 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
6
5
|
let react = require("react");
|
|
7
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
-
let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
|
|
9
|
-
_intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
|
|
10
6
|
|
|
11
7
|
//#region src/FocusDictionaryContext.tsx
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const [fallbackContent, setFallbackContent] = (0, react.useState)(null);
|
|
16
|
-
const setFocusedContent = (0, react.useCallback)((value) => {
|
|
17
|
-
if (manager) manager.focusedContent.set(value);
|
|
18
|
-
else setFallbackContent(value);
|
|
19
|
-
}, [manager]);
|
|
20
|
-
const setFocusedContentKeyPath = (0, react.useCallback)((keyPath) => {
|
|
21
|
-
if (manager) manager.setFocusedContentKeyPath(keyPath);
|
|
22
|
-
else setFallbackContent((prev) => {
|
|
23
|
-
if (!prev) return null;
|
|
24
|
-
const filtered = keyPath.filter((key) => key.type !== _intlayer_types_nodeType.TRANSLATION);
|
|
25
|
-
return {
|
|
26
|
-
...prev,
|
|
27
|
-
keyPath: filtered
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
}, [manager]);
|
|
31
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FocusDictionaryReactContext.Provider, {
|
|
32
|
-
value: {
|
|
33
|
-
focusedContent: manager?.focusedContent.value ?? fallbackContent,
|
|
34
|
-
setFocusedContent,
|
|
35
|
-
setFocusedContentKeyPath
|
|
36
|
-
},
|
|
37
|
-
children
|
|
38
|
-
});
|
|
39
|
-
};
|
|
8
|
+
/**
|
|
9
|
+
* Returns the content focused in the editor, shared with the client frame.
|
|
10
|
+
*/
|
|
40
11
|
const useFocusDictionary = () => {
|
|
41
12
|
const manager = require_EditorStateContext.useEditorStateManager();
|
|
42
|
-
const
|
|
43
|
-
const [focusedContent, setFocusedContentState] = (0, react.useState)(manager?.focusedContent.value ?? reactContext?.focusedContent ?? null);
|
|
13
|
+
const [focusedContent, setFocusedContentState] = (0, react.useState)(manager?.focusedContent.value ?? null);
|
|
44
14
|
(0, react.useEffect)(() => {
|
|
45
|
-
if (!manager)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
manager.focusedContent.addEventListener("change", handler);
|
|
51
|
-
return () => manager.focusedContent.removeEventListener("change", handler);
|
|
52
|
-
}, [manager, reactContext?.focusedContent]);
|
|
15
|
+
if (!manager) return;
|
|
16
|
+
const handleChange = (event) => setFocusedContentState(event.detail);
|
|
17
|
+
manager.focusedContent.addEventListener("change", handleChange);
|
|
18
|
+
return () => manager.focusedContent.removeEventListener("change", handleChange);
|
|
19
|
+
}, [manager]);
|
|
53
20
|
return {
|
|
54
21
|
focusedContent,
|
|
55
|
-
setFocusedContent: (0, react.useCallback)((value) =>
|
|
56
|
-
|
|
57
|
-
else if (manager) manager.focusedContent.set(value);
|
|
58
|
-
}, [reactContext, manager]),
|
|
59
|
-
setFocusedContentKeyPath: (0, react.useCallback)((keyPath) => {
|
|
60
|
-
if (reactContext) reactContext.setFocusedContentKeyPath(keyPath);
|
|
61
|
-
else if (manager) manager.setFocusedContentKeyPath(keyPath);
|
|
62
|
-
}, [reactContext, manager])
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
const useFocusDictionaryActions = () => {
|
|
66
|
-
const { setFocusedContent, setFocusedContentKeyPath } = useFocusDictionary();
|
|
67
|
-
return {
|
|
68
|
-
setFocusedContent,
|
|
69
|
-
setFocusedContentKeyPath
|
|
22
|
+
setFocusedContent: (0, react.useCallback)((value) => manager?.focusedContent.set(value), [manager]),
|
|
23
|
+
setFocusedContentKeyPath: (0, react.useCallback)((keyPath) => manager?.setFocusedContentKeyPath(keyPath), [manager])
|
|
70
24
|
};
|
|
71
25
|
};
|
|
72
26
|
|
|
73
27
|
//#endregion
|
|
74
|
-
exports.FocusDictionaryProvider = FocusDictionaryProvider;
|
|
75
28
|
exports.useFocusDictionary = useFocusDictionary;
|
|
76
|
-
exports.useFocusDictionaryActions = useFocusDictionaryActions;
|
|
77
29
|
//# sourceMappingURL=FocusDictionaryContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.cjs","names":["
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.cjs","names":["useEditorStateManager","useState","useCallback"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { CrossFrameStateAction, FileContent } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { FileContent } from '@intlayer/editor';\n\nexport type FocusDictionaryActions = {\n /** Accepts a value or an updater — `setFocusedContent(prev => …)`. */\n setFocusedContent: (value: CrossFrameStateAction<FileContent | null>) => void;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\n/**\n * Returns the content focused in the editor, shared with the client frame.\n */\nexport const useFocusDictionary = (): FocusDictionaryActions & {\n focusedContent: FileContent | null;\n} => {\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\n const handleChange = (event: Event) =>\n setFocusedContentState((event as CustomEvent<FileContent | null>).detail);\n manager.focusedContent.addEventListener('change', handleChange);\n\n return () =>\n manager.focusedContent.removeEventListener('change', handleChange);\n }, [manager]);\n\n const setFocusedContent = useCallback(\n (value: CrossFrameStateAction<FileContent | null>) =>\n manager?.focusedContent.set(value),\n [manager]\n );\n\n const setFocusedContentKeyPath = useCallback(\n (keyPath: KeyPath[]) => manager?.setFocusedContentKeyPath(keyPath),\n [manager]\n );\n\n return { focusedContent, setFocusedContent, setFocusedContentKeyPath };\n};\n"],"mappings":";;;;;;;;;;AAkBA,MAAa,2BAER;CACH,MAAM,UAAUA,iDAAsB;CACtC,MAAM,CAAC,gBAAgB,8BAA0BC,gBAC/C,SAAS,eAAe,SAAS,IACnC;CAEA,2BAAgB;EACd,IAAI,CAAC,SAAS;EAEd,MAAM,gBAAgB,UACpB,uBAAwB,MAA0C,MAAM;EAC1E,QAAQ,eAAe,iBAAiB,UAAU,YAAY;EAE9D,aACE,QAAQ,eAAe,oBAAoB,UAAU,YAAY;CACrE,GAAG,CAAC,OAAO,CAAC;CAaZ,OAAO;EAAE;EAAgB,uBAXCC,oBACvB,UACC,SAAS,eAAe,IAAI,KAAK,GACnC,CAAC,OAAO,CAQ+B;EAAG,8BALXA,oBAC9B,YAAuB,SAAS,yBAAyB,OAAO,GACjE,CAAC,OAAO,CAGyD;CAAE;AACvE"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,51 +3,35 @@ const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
|
3
3
|
const require_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
|
|
4
4
|
const require_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
5
5
|
const require_useCrossURLPathState = require('./useCrossURLPathState.cjs');
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const require_EditedContentContext = require('./EditedContentContext.cjs');
|
|
7
|
+
const require_useEditedContentPersistence = require('./useEditedContentPersistence.cjs');
|
|
8
8
|
const require_useEditorLocale = require('./useEditorLocale.cjs');
|
|
9
|
-
const require_CommunicatorContext = require('./CommunicatorContext.cjs');
|
|
10
9
|
const require_ConfigurationContext = require('./ConfigurationContext.cjs');
|
|
11
|
-
const require_EditedContentContext = require('./EditedContentContext.cjs');
|
|
12
10
|
const require_EditorEnabledContext = require('./EditorEnabledContext.cjs');
|
|
13
11
|
const require_EditorProvider = require('./EditorProvider.cjs');
|
|
14
12
|
const require_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
|
|
15
13
|
const require_useFocusUnmergedDictionary = require('./useFocusUnmergedDictionary.cjs');
|
|
16
14
|
let _intlayer_editor = require("@intlayer/editor");
|
|
17
15
|
|
|
18
|
-
exports.ConfigurationProvider = require_ConfigurationContext.ConfigurationProvider;
|
|
19
16
|
exports.EditorProvider = require_EditorProvider.EditorProvider;
|
|
20
17
|
exports.EditorStateProvider = require_EditorStateContext.EditorStateProvider;
|
|
21
|
-
exports.FocusDictionaryProvider = require_FocusDictionaryContext.FocusDictionaryProvider;
|
|
22
18
|
Object.defineProperty(exports, 'MessageKey', {
|
|
23
19
|
enumerable: true,
|
|
24
20
|
get: function () {
|
|
25
21
|
return _intlayer_editor.MessageKey;
|
|
26
22
|
}
|
|
27
23
|
});
|
|
28
|
-
exports.useCommunicator = require_CommunicatorContext.useCommunicator;
|
|
29
24
|
exports.useConfiguration = require_ConfigurationContext.useConfiguration;
|
|
30
|
-
exports.useConfigurationState = require_ConfigurationContext.useConfigurationState;
|
|
31
|
-
exports.useCrossFrameMessageListener = require_useCrossFrameMessageListener.useCrossFrameMessageListener;
|
|
32
25
|
exports.useCrossFrameState = require_useCrossFrameState.useCrossFrameState;
|
|
33
|
-
exports.useCrossURLPathSetter = require_useCrossURLPathState.useCrossURLPathSetter;
|
|
34
26
|
exports.useCrossURLPathState = require_useCrossURLPathState.useCrossURLPathState;
|
|
35
27
|
exports.useDictionariesRecord = require_DictionariesRecordContext.useDictionariesRecord;
|
|
36
28
|
exports.useDictionariesRecordActions = require_DictionariesRecordContext.useDictionariesRecordActions;
|
|
37
29
|
exports.useEditedContent = require_EditedContentContext.useEditedContent;
|
|
38
30
|
exports.useEditedContentActions = require_EditedContentContext.useEditedContentActions;
|
|
31
|
+
exports.useEditedContentPersistence = require_useEditedContentPersistence.useEditedContentPersistence;
|
|
39
32
|
exports.useEditorEnabled = require_EditorEnabledContext.useEditorEnabled;
|
|
40
|
-
exports.useEditorEnabledState = require_EditorEnabledContext.useEditorEnabledState;
|
|
41
33
|
exports.useEditorLocale = require_useEditorLocale.useEditorLocale;
|
|
42
34
|
exports.useEditorPingClient = require_EditorEnabledContext.useEditorPingClient;
|
|
43
35
|
exports.useEditorStateManager = require_EditorStateContext.useEditorStateManager;
|
|
44
36
|
exports.useFocusDictionary = require_FocusDictionaryContext.useFocusDictionary;
|
|
45
|
-
exports.
|
|
46
|
-
exports.useFocusUnmergedDictionary = require_useFocusUnmergedDictionary.useFocusUnmergedDictionary;
|
|
47
|
-
exports.useGetEditedContentState = require_EditedContentContext.useGetEditedContentState;
|
|
48
|
-
exports.useGetEditorEnabledState = require_EditorEnabledContext.useGetEditorEnabledState;
|
|
49
|
-
exports.useIframeClickInterceptor = require_useIframeClickInterceptor.useIframeClickInterceptor;
|
|
50
|
-
exports.useIframeClickMerger = require_useIframeClickInterceptor.useIframeClickMerger;
|
|
51
|
-
exports.usePostEditedContentState = require_EditedContentContext.usePostEditedContentState;
|
|
52
|
-
exports.usePostEditorEnabledState = require_EditorEnabledContext.usePostEditorEnabledState;
|
|
53
|
-
exports.useSetEditorLocale = require_useEditorLocale.useSetEditorLocale;
|
|
37
|
+
exports.useFocusUnmergedDictionary = require_useFocusUnmergedDictionary.useFocusUnmergedDictionary;
|
|
@@ -3,61 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
5
|
let react = require("react");
|
|
6
|
-
let _intlayer_editor = require("@intlayer/editor");
|
|
7
6
|
|
|
8
7
|
//#region src/useCrossFrameState.tsx
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
9
|
+
* Returns the latest value another frame posted under `key`.
|
|
11
10
|
*/
|
|
12
|
-
const useCrossFrameState = (key,
|
|
11
|
+
const useCrossFrameState = (key, initialValue) => {
|
|
13
12
|
const manager = require_EditorStateContext.useEditorStateManager();
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const stateManagerRef = (0, react.useRef)(null);
|
|
18
|
-
(0, react.useEffect)(() => {
|
|
19
|
-
const { emit = true, receive = true } = options ?? {};
|
|
20
|
-
if (!manager?.messenger) return;
|
|
21
|
-
const stateManager = new _intlayer_editor.CrossFrameStateManager(key, manager?.messenger, {
|
|
22
|
-
emit,
|
|
23
|
-
receive,
|
|
24
|
-
initialValue: resolvedInitial
|
|
25
|
-
});
|
|
26
|
-
stateManagerRef.current = stateManager;
|
|
27
|
-
const handler = (e) => {
|
|
28
|
-
const newValue = e.detail;
|
|
29
|
-
valueRef.current = newValue;
|
|
30
|
-
setValueState(newValue);
|
|
31
|
-
};
|
|
32
|
-
stateManager.addEventListener("change", handler);
|
|
33
|
-
stateManager.start();
|
|
34
|
-
return () => {
|
|
35
|
-
stateManager.removeEventListener("change", handler);
|
|
36
|
-
stateManager.stop();
|
|
37
|
-
stateManagerRef.current = null;
|
|
38
|
-
};
|
|
39
|
-
}, [
|
|
40
|
-
key,
|
|
41
|
-
manager?.messenger,
|
|
42
|
-
options?.emit,
|
|
43
|
-
options?.receive
|
|
44
|
-
]);
|
|
45
|
-
const setValue = (valueOrUpdater) => {
|
|
46
|
-
setValueState((prev) => {
|
|
47
|
-
const newValue = typeof valueOrUpdater === "function" ? valueOrUpdater(prev) : valueOrUpdater;
|
|
48
|
-
valueRef.current = newValue;
|
|
49
|
-
stateManagerRef.current?.set(newValue);
|
|
50
|
-
return newValue;
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
const postState = () => {
|
|
54
|
-
stateManagerRef.current?.postCurrentValue();
|
|
55
|
-
};
|
|
56
|
-
return [
|
|
57
|
-
value,
|
|
58
|
-
setValue,
|
|
59
|
-
postState
|
|
60
|
-
];
|
|
13
|
+
const [value, setValue] = (0, react.useState)(initialValue);
|
|
14
|
+
(0, react.useEffect)(() => manager?.messenger.subscribe(`${key}/post`, (postedValue) => setValue(() => postedValue)), [manager, key]);
|
|
15
|
+
return value;
|
|
61
16
|
};
|
|
62
17
|
|
|
63
18
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameState.cjs","names":["useEditorStateManager","useState"
|
|
1
|
+
{"version":3,"file":"useCrossFrameState.cjs","names":["useEditorStateManager","useState"],"sources":["../../src/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport type { MessageKey } from '@intlayer/editor';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\n/**\n * Returns the latest value another frame posted under `key`.\n */\nexport const useCrossFrameState = <Value,>(\n key: `${MessageKey}`,\n initialValue: Value\n): Value => {\n const manager = useEditorStateManager();\n const [value, setValue] = useState<Value>(initialValue);\n\n useEffect(\n () =>\n manager?.messenger.subscribe<Value>(`${key}/post`, (postedValue) =>\n setValue(() => postedValue)\n ),\n [manager, key]\n );\n\n return value;\n};\n"],"mappings":";;;;;;;;;;AASA,MAAa,sBACX,KACA,iBACU;CACV,MAAM,UAAUA,iDAAsB;CACtC,MAAM,CAAC,OAAO,gBAAYC,gBAAgB,YAAY;CAEtD,2BAEI,SAAS,UAAU,UAAiB,GAAG,IAAI,SAAS,gBAClD,eAAe,WAAW,CAC5B,GACF,CAAC,SAAS,GAAG,CACf;CAEA,OAAO;AACT"}
|
|
@@ -5,15 +5,11 @@ const require_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
|
5
5
|
let _intlayer_editor = require("@intlayer/editor");
|
|
6
6
|
|
|
7
7
|
//#region src/useCrossURLPathState.tsx
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
receive: false
|
|
13
|
-
});
|
|
14
|
-
};
|
|
8
|
+
/**
|
|
9
|
+
* Returns the path currently displayed by the client application.
|
|
10
|
+
*/
|
|
11
|
+
const useCrossURLPathState = () => require_useCrossFrameState.useCrossFrameState(_intlayer_editor.MessageKey.INTLAYER_URL_CHANGE, void 0);
|
|
15
12
|
|
|
16
13
|
//#endregion
|
|
17
|
-
exports.useCrossURLPathSetter = useCrossURLPathSetter;
|
|
18
14
|
exports.useCrossURLPathState = useCrossURLPathState;
|
|
19
15
|
//# sourceMappingURL=useCrossURLPathState.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossURLPathState.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../src/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {
|
|
1
|
+
{"version":3,"file":"useCrossURLPathState.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../src/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useCrossFrameState } from './useCrossFrameState';\n\n/**\n * Returns the path currently displayed by the client application.\n */\nexport const useCrossURLPathState = (): string | undefined =>\n useCrossFrameState<string | undefined>(\n MessageKey.INTLAYER_URL_CHANGE,\n undefined\n );\n"],"mappings":";;;;;;;;;;AAQA,MAAa,6BACXA,8CACEC,4BAAW,qBACX,MACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditedContentContext = require('./EditedContentContext.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/useEditedContentPersistence.tsx
|
|
8
|
+
const EDITED_CONTENT_STORAGE_KEY = "INTLAYER_EDITED_CONTENT_CHANGED";
|
|
9
|
+
/**
|
|
10
|
+
* Persists the edited content in localStorage, and restores it on mount so
|
|
11
|
+
* unsaved edits survive a page reload.
|
|
12
|
+
*/
|
|
13
|
+
const useEditedContentPersistence = () => {
|
|
14
|
+
const { editedContent, setEditedContentState } = require_EditedContentContext.useEditedContent();
|
|
15
|
+
(0, react.useEffect)(() => {
|
|
16
|
+
if (editedContent !== void 0) return;
|
|
17
|
+
const persistedState = localStorage.getItem(EDITED_CONTENT_STORAGE_KEY);
|
|
18
|
+
if (!persistedState) return;
|
|
19
|
+
try {
|
|
20
|
+
setEditedContentState(JSON.parse(persistedState));
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error(error);
|
|
23
|
+
}
|
|
24
|
+
}, []);
|
|
25
|
+
(0, react.useEffect)(() => {
|
|
26
|
+
if (editedContent === void 0) return;
|
|
27
|
+
localStorage.setItem(EDITED_CONTENT_STORAGE_KEY, JSON.stringify(editedContent));
|
|
28
|
+
}, [editedContent]);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.useEditedContentPersistence = useEditedContentPersistence;
|
|
33
|
+
//# sourceMappingURL=useEditedContentPersistence.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditedContentPersistence.cjs","names":["useEditedContent"],"sources":["../../src/useEditedContentPersistence.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { useEditedContent } from './EditedContentContext';\n\nconst EDITED_CONTENT_STORAGE_KEY = 'INTLAYER_EDITED_CONTENT_CHANGED';\n\n/**\n * Persists the edited content in localStorage, and restores it on mount so\n * unsaved edits survive a page reload.\n */\nexport const useEditedContentPersistence = (): void => {\n const { editedContent, setEditedContentState } = useEditedContent();\n\n useEffect(() => {\n if (editedContent !== undefined) return;\n\n const persistedState = localStorage.getItem(EDITED_CONTENT_STORAGE_KEY);\n if (!persistedState) return;\n\n try {\n setEditedContentState(JSON.parse(persistedState));\n } catch (error) {\n console.error(error);\n }\n }, []);\n\n useEffect(() => {\n if (editedContent === undefined) return;\n\n localStorage.setItem(\n EDITED_CONTENT_STORAGE_KEY,\n JSON.stringify(editedContent)\n );\n }, [editedContent]);\n};\n"],"mappings":";;;;;;;AAKA,MAAM,6BAA6B;;;;;AAMnC,MAAa,oCAA0C;CACrD,MAAM,EAAE,eAAe,0BAA0BA,8CAAiB;CAElE,2BAAgB;EACd,IAAI,kBAAkB,QAAW;EAEjC,MAAM,iBAAiB,aAAa,QAAQ,0BAA0B;EACtE,IAAI,CAAC,gBAAgB;EAErB,IAAI;GACF,sBAAsB,KAAK,MAAM,cAAc,CAAC;EAClD,SAAS,OAAO;GACd,QAAQ,MAAM,KAAK;EACrB;CACF,GAAG,CAAC,CAAC;CAEL,2BAAgB;EACd,IAAI,kBAAkB,QAAW;EAEjC,aAAa,QACX,4BACA,KAAK,UAAU,aAAa,CAC9B;CACF,GAAG,CAAC,aAAa,CAAC;AACpB"}
|
|
@@ -16,12 +16,7 @@ const useEditorLocale = () => {
|
|
|
16
16
|
}, [manager]);
|
|
17
17
|
return locale;
|
|
18
18
|
};
|
|
19
|
-
const useSetEditorLocale = () => {
|
|
20
|
-
const manager = require_EditorStateContext.useEditorStateManager();
|
|
21
|
-
return (locale) => manager?.currentLocale.set(locale);
|
|
22
|
-
};
|
|
23
19
|
|
|
24
20
|
//#endregion
|
|
25
21
|
exports.useEditorLocale = useEditorLocale;
|
|
26
|
-
exports.useSetEditorLocale = useSetEditorLocale;
|
|
27
22
|
//# sourceMappingURL=useEditorLocale.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditorLocale.cjs","names":["useEditorStateManager","useState"],"sources":["../../src/useEditorLocale.tsx"],"sourcesContent":["'use client';\n\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport const useEditorLocale = (): Locale | undefined => {\n const manager = useEditorStateManager();\n const [locale, setLocale] = useState<Locale | undefined>(\n manager?.currentLocale.value\n );\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) => setLocale((e as CustomEvent<Locale>).detail);\n manager.currentLocale.addEventListener('change', handler);\n\n return () => manager.currentLocale.removeEventListener('change', handler);\n }, [manager]);\n\n return locale;\n};\n
|
|
1
|
+
{"version":3,"file":"useEditorLocale.cjs","names":["useEditorStateManager","useState"],"sources":["../../src/useEditorLocale.tsx"],"sourcesContent":["'use client';\n\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport const useEditorLocale = (): Locale | undefined => {\n const manager = useEditorStateManager();\n const [locale, setLocale] = useState<Locale | undefined>(\n manager?.currentLocale.value\n );\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) => setLocale((e as CustomEvent<Locale>).detail);\n manager.currentLocale.addEventListener('change', handler);\n\n return () => manager.currentLocale.removeEventListener('change', handler);\n }, [manager]);\n\n return locale;\n};\n"],"mappings":";;;;;;;AAMA,MAAa,wBAA4C;CACvD,MAAM,UAAUA,iDAAsB;CACtC,MAAM,CAAC,QAAQ,iBAAaC,gBAC1B,SAAS,cAAc,KACzB;CAEA,2BAAgB;EACd,IAAI,CAAC,SAAS;EAEd,MAAM,WAAW,MAAa,UAAW,EAA0B,MAAM;EACzE,QAAQ,cAAc,iBAAiB,UAAU,OAAO;EAExD,aAAa,QAAQ,cAAc,oBAAoB,UAAU,OAAO;CAC1E,GAAG,CAAC,OAAO,CAAC;CAEZ,OAAO;AACT"}
|
|
@@ -1,51 +1,24 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useEditorStateManager } from "./EditorStateContext.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
6
5
|
|
|
7
6
|
//#region src/ConfigurationContext.tsx
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (!manager || !configuration) return;
|
|
13
|
-
manager.configuration.set(configuration);
|
|
14
|
-
}, [manager, configuration]);
|
|
15
|
-
return /* @__PURE__ */ jsx(ConfigurationReactContext.Provider, {
|
|
16
|
-
value: configuration,
|
|
17
|
-
children
|
|
18
|
-
});
|
|
19
|
-
};
|
|
7
|
+
/**
|
|
8
|
+
* Returns the Intlayer configuration held by the editor state manager.
|
|
9
|
+
*/
|
|
20
10
|
const useConfiguration = () => {
|
|
21
11
|
const manager = useEditorStateManager();
|
|
22
|
-
const
|
|
23
|
-
const [config, setConfig] = useState(manager?.configuration.value ?? reactConfig);
|
|
12
|
+
const [configuration, setConfiguration] = useState(manager?.configuration.value);
|
|
24
13
|
useEffect(() => {
|
|
25
|
-
if (!manager)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
setConfig(detail ?? reactConfig);
|
|
32
|
-
};
|
|
33
|
-
manager.configuration.addEventListener("change", handler);
|
|
34
|
-
return () => manager.configuration.removeEventListener("change", handler);
|
|
35
|
-
}, [manager, reactConfig]);
|
|
36
|
-
return config ?? reactConfig;
|
|
37
|
-
};
|
|
38
|
-
const useConfigurationState = () => {
|
|
39
|
-
const manager = useEditorStateManager();
|
|
40
|
-
const reactConfig = useContext(ConfigurationReactContext);
|
|
41
|
-
const [config, setConfig] = useState(manager?.configuration.value ?? reactConfig);
|
|
42
|
-
return [
|
|
43
|
-
config ?? reactConfig,
|
|
44
|
-
setConfig,
|
|
45
|
-
() => manager?.configuration.postCurrentValue()
|
|
46
|
-
];
|
|
14
|
+
if (!manager) return;
|
|
15
|
+
const handleChange = (event) => setConfiguration(event.detail);
|
|
16
|
+
manager.configuration.addEventListener("change", handleChange);
|
|
17
|
+
return () => manager.configuration.removeEventListener("change", handleChange);
|
|
18
|
+
}, [manager]);
|
|
19
|
+
return configuration;
|
|
47
20
|
};
|
|
48
21
|
|
|
49
22
|
//#endregion
|
|
50
|
-
export {
|
|
23
|
+
export { useConfiguration };
|
|
51
24
|
//# sourceMappingURL=ConfigurationContext.mjs.map
|