@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.
Files changed (71) hide show
  1. package/dist/cjs/ConfigurationContext.cjs +10 -39
  2. package/dist/cjs/ConfigurationContext.cjs.map +1 -1
  3. package/dist/cjs/EditedContentContext.cjs +0 -17
  4. package/dist/cjs/EditedContentContext.cjs.map +1 -1
  5. package/dist/cjs/EditorEnabledContext.cjs +0 -32
  6. package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
  7. package/dist/cjs/FocusDictionaryContext.cjs +11 -59
  8. package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
  9. package/dist/cjs/index.cjs +4 -20
  10. package/dist/cjs/useCrossFrameState.cjs +5 -50
  11. package/dist/cjs/useCrossFrameState.cjs.map +1 -1
  12. package/dist/cjs/useCrossURLPathState.cjs +4 -8
  13. package/dist/cjs/useCrossURLPathState.cjs.map +1 -1
  14. package/dist/cjs/useEditedContentPersistence.cjs +33 -0
  15. package/dist/cjs/useEditedContentPersistence.cjs.map +1 -0
  16. package/dist/cjs/useEditorLocale.cjs +0 -5
  17. package/dist/cjs/useEditorLocale.cjs.map +1 -1
  18. package/dist/esm/ConfigurationContext.mjs +12 -39
  19. package/dist/esm/ConfigurationContext.mjs.map +1 -1
  20. package/dist/esm/EditedContentContext.mjs +1 -16
  21. package/dist/esm/EditedContentContext.mjs.map +1 -1
  22. package/dist/esm/EditorEnabledContext.mjs +1 -30
  23. package/dist/esm/EditorEnabledContext.mjs.map +1 -1
  24. package/dist/esm/FocusDictionaryContext.mjs +13 -57
  25. package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
  26. package/dist/esm/index.mjs +8 -10
  27. package/dist/esm/useCrossFrameState.mjs +6 -51
  28. package/dist/esm/useCrossFrameState.mjs.map +1 -1
  29. package/dist/esm/useCrossURLPathState.mjs +5 -8
  30. package/dist/esm/useCrossURLPathState.mjs.map +1 -1
  31. package/dist/esm/useEditedContentPersistence.mjs +32 -0
  32. package/dist/esm/useEditedContentPersistence.mjs.map +1 -0
  33. package/dist/esm/useEditorLocale.mjs +1 -5
  34. package/dist/esm/useEditorLocale.mjs.map +1 -1
  35. package/dist/types/ConfigurationContext.d.ts +3 -6
  36. package/dist/types/ConfigurationContext.d.ts.map +1 -1
  37. package/dist/types/EditedContentContext.d.ts +0 -6
  38. package/dist/types/EditedContentContext.d.ts.map +1 -1
  39. package/dist/types/EditorEnabledContext.d.ts +0 -11
  40. package/dist/types/EditorEnabledContext.d.ts.map +1 -1
  41. package/dist/types/FocusDictionaryContext.d.ts +6 -7
  42. package/dist/types/FocusDictionaryContext.d.ts.map +1 -1
  43. package/dist/types/index.d.ts +9 -11
  44. package/dist/types/useCrossFrameState.d.ts +2 -7
  45. package/dist/types/useCrossFrameState.d.ts.map +1 -1
  46. package/dist/types/useCrossURLPathState.d.ts +4 -3
  47. package/dist/types/useCrossURLPathState.d.ts.map +1 -1
  48. package/dist/types/useEditedContentPersistence.d.ts +8 -0
  49. package/dist/types/useEditedContentPersistence.d.ts.map +1 -0
  50. package/dist/types/useEditorLocale.d.ts +0 -1
  51. package/dist/types/useEditorLocale.d.ts.map +1 -1
  52. package/package.json +5 -5
  53. package/dist/cjs/CommunicatorContext.cjs +0 -20
  54. package/dist/cjs/CommunicatorContext.cjs.map +0 -1
  55. package/dist/cjs/_virtual/_rolldown/runtime.cjs +0 -28
  56. package/dist/cjs/useCrossFrameMessageListener.cjs +0 -31
  57. package/dist/cjs/useCrossFrameMessageListener.cjs.map +0 -1
  58. package/dist/cjs/useIframeClickInterceptor.cjs +0 -28
  59. package/dist/cjs/useIframeClickInterceptor.cjs.map +0 -1
  60. package/dist/esm/CommunicatorContext.mjs +0 -19
  61. package/dist/esm/CommunicatorContext.mjs.map +0 -1
  62. package/dist/esm/useCrossFrameMessageListener.mjs +0 -30
  63. package/dist/esm/useCrossFrameMessageListener.mjs.map +0 -1
  64. package/dist/esm/useIframeClickInterceptor.mjs +0 -26
  65. package/dist/esm/useIframeClickInterceptor.mjs.map +0 -1
  66. package/dist/types/CommunicatorContext.d.ts +0 -14
  67. package/dist/types/CommunicatorContext.d.ts.map +0 -1
  68. package/dist/types/useCrossFrameMessageListener.d.ts +0 -11
  69. package/dist/types/useCrossFrameMessageListener.d.ts.map +0 -1
  70. package/dist/types/useIframeClickInterceptor.d.ts +0 -15
  71. 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
- const ConfigurationReactContext = (0, react.createContext)(void 0);
10
- const ConfigurationProvider = ({ configuration, children }) => {
11
- const manager = require_EditorStateContext.useEditorStateManager();
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 reactConfig = (0, react.useContext)(ConfigurationReactContext);
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
- setConfig(reactConfig);
28
- return;
29
- }
30
- const handler = (e) => {
31
- const detail = e.detail;
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":["createContext","useEditorStateManager","useContext","useState"],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\n// 1. Create a native React context\nconst ConfigurationReactContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\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 // 2. Wrap children in the native provider\n return (\n <ConfigurationReactContext.Provider value={configuration}>\n {children}\n </ConfigurationReactContext.Provider>\n );\n};\n\nexport const useConfiguration = (): IntlayerConfig | undefined => {\n const manager = useEditorStateManager();\n const reactConfig = useContext(ConfigurationReactContext); // 3. Consume native context\n\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n (manager?.configuration.value as IntlayerConfig | undefined) ?? reactConfig\n );\n\n useEffect(() => {\n if (!manager) {\n setConfig(reactConfig);\n return;\n }\n\n const handler = (e: Event) => {\n const detail = (e as CustomEvent<IntlayerConfig>).detail;\n setConfig(detail ?? reactConfig);\n };\n\n manager.configuration.addEventListener('change', handler);\n return () => manager.configuration.removeEventListener('change', handler);\n }, [manager, reactConfig]);\n\n // Prefer event-driven config, fallback to React context config\n return config ?? reactConfig;\n};\n\nexport const useConfigurationState = () => {\n const manager = useEditorStateManager();\n const reactConfig = useContext(ConfigurationReactContext);\n\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n (manager?.configuration.value as IntlayerConfig | undefined) ?? reactConfig\n );\n\n return [\n config ?? reactConfig,\n setConfig,\n () => manager?.configuration.postCurrentValue(),\n ] as const;\n};\n"],"mappings":";;;;;;;;AAcA,MAAM,gCAA4BA,qBAChC,MACF;AAMA,MAAa,yBAAyD,EACpE,eACA,eACI;CACJ,MAAM,UAAUC,iDAAsB;CAEtC,2BAAgB;EACd,IAAI,CAAC,WAAW,CAAC,eAAe;EAEhC,QAAQ,cAAc,IAAI,aAAa;CACzC,GAAG,CAAC,SAAS,aAAa,CAAC;CAG3B,OACE,2CAAC,0BAA0B,UAA3B;EAAoC,OAAO;EACxC;CACiC;AAExC;AAEA,MAAa,yBAAqD;CAChE,MAAM,UAAUA,iDAAsB;CACtC,MAAM,kBAAcC,kBAAW,yBAAyB;CAExD,MAAM,CAAC,QAAQ,iBAAaC,gBACzB,SAAS,cAAc,SAAwC,WAClE;CAEA,2BAAgB;EACd,IAAI,CAAC,SAAS;GACZ,UAAU,WAAW;GACrB;EACF;EAEA,MAAM,WAAW,MAAa;GAC5B,MAAM,SAAU,EAAkC;GAClD,UAAU,UAAU,WAAW;EACjC;EAEA,QAAQ,cAAc,iBAAiB,UAAU,OAAO;EACxD,aAAa,QAAQ,cAAc,oBAAoB,UAAU,OAAO;CAC1E,GAAG,CAAC,SAAS,WAAW,CAAC;CAGzB,OAAO,UAAU;AACnB;AAEA,MAAa,8BAA8B;CACzC,MAAM,UAAUF,iDAAsB;CACtC,MAAM,kBAAcC,kBAAW,yBAAyB;CAExD,MAAM,CAAC,QAAQ,iBAAaC,gBACzB,SAAS,cAAc,SAAwC,WAClE;CAEA,OAAO;EACL,UAAU;EACV;QACM,SAAS,cAAc,iBAAiB;CAChD;AACF"}
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 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,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,+BAA+B,YAAY,SAAS,aAAa,OAAO;EACxE,0BAA0B,SAAS,gBAAgB;EACnD,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;AAEA,MAAa,6BACX,qBACG;CACH,MAAM,UAAUD,iDAAsB;CACtC,2BAAgB;EACd,IAAI,CAAC,oBAAoB,CAAC,SAAS;EACnC,OAAO,QAAQ,UAAU,UACvB,wCACA,gBACF;CACF,GAAG,CAAC,SAAS,gBAAgB,CAAC;AAChC;AAEA,MAAa,iCAAiC;CAC5C,MAAM,UAAUA,iDAAsB;CACtC,aAAa;EACX,SAAS,UAAU,KAAK,qCAAqC;CAC/D;AACF"}
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","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,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;;;;;;AAOA,MAAa,4BAA4B,cAA2B;CAClE,MAAM,UAAUD,iDAAsB;CAEtC,2BAAgB;EACd,IAAI,CAAC,WAAW;EAEhB,OAAO,SAAS,UAAU,UACxB,GAAGE,4BAAW,wBAAwB,OACtC,SACF;CACF,GAAG,CAAC,SAAS,SAAS,CAAC;AACzB;;;;AAKA,MAAa,kCAAkC;CAC7C,MAAM,UAAUF,iDAAsB;CAEtC,QAAQ,UAAmB;EACzB,SAAS,cAAc,IAAI,KAAK;EAChC,SAAS,cAAc,iBAAiB;CAC1C;AACF;AAEA,MAAa,8BAA8B;CACzC,MAAM,EAAE,YAAY,iBAAiB;CACrC,MAAM,UAAUA,iDAAsB;CACtC,MAAM,UAAU,UAAmB,SAAS,cAAc,IAAI,KAAK;CAEnE,OAAO,CAAC,SAAS,MAAM;AACzB;;;;;AAMA,MAAa,4BAA0C;CACrD,MAAM,UAAUA,iDAAsB;CAEtC,aAAa,SAAS,WAAW;AACnC"}
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
- const FocusDictionaryReactContext = (0, react.createContext)(void 0);
13
- const FocusDictionaryProvider = ({ children }) => {
14
- const manager = require_EditorStateContext.useEditorStateManager();
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 reactContext = (0, react.useContext)(FocusDictionaryReactContext);
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
- setFocusedContentState(reactContext?.focusedContent ?? null);
47
- return;
48
- }
49
- const handler = (e) => setFocusedContentState(e.detail);
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
- if (reactContext) reactContext.setFocusedContent(value);
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":["createContext","useEditorStateManager","useState","useCallback","NodeTypes","useContext"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { CrossFrameStateAction, FileContent } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useState,\n} 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 /** Accepts a value or an updater — `setFocusedContent(prev => …)`. */\n setFocusedContent: (value: CrossFrameStateAction<FileContent | null>) => void;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\ntype FocusDictionaryContextType = FocusDictionaryState & FocusDictionaryActions;\n\n// Create native React context fallback\nconst FocusDictionaryReactContext = createContext<\n FocusDictionaryContextType | undefined\n>(undefined);\n\n// Create the Provider\nexport const FocusDictionaryProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const manager = useEditorStateManager();\n const [fallbackContent, setFallbackContent] = useState<FileContent | null>(\n null\n );\n\n const setFocusedContent = useCallback(\n (value: CrossFrameStateAction<FileContent | null>) => {\n if (manager) {\n manager.focusedContent.set(value);\n } else {\n setFallbackContent(value);\n }\n },\n [manager]\n );\n\n const setFocusedContentKeyPath = useCallback(\n (keyPath: KeyPath[]) => {\n if (manager) {\n manager.setFocusedContentKeyPath(keyPath);\n } else {\n setFallbackContent((prev) => {\n if (!prev) return null;\n const filtered = keyPath.filter(\n (key) => key.type !== NodeTypes.TRANSLATION\n );\n return { ...prev, keyPath: filtered };\n });\n }\n },\n [manager]\n );\n\n return (\n <FocusDictionaryReactContext.Provider\n value={{\n focusedContent: manager?.focusedContent.value ?? fallbackContent,\n setFocusedContent,\n setFocusedContentKeyPath,\n }}\n >\n {children}\n </FocusDictionaryReactContext.Provider>\n );\n};\n\n// 3. Update the hook to consume the fallback context\nexport const useFocusDictionary = (): FocusDictionaryState &\n FocusDictionaryActions => {\n const manager = useEditorStateManager();\n const reactContext = useContext(FocusDictionaryReactContext);\n\n const [focusedContent, setFocusedContentState] = useState<FileContent | null>(\n manager?.focusedContent.value ?? reactContext?.focusedContent ?? null\n );\n\n useEffect(() => {\n if (!manager) {\n setFocusedContentState(reactContext?.focusedContent ?? null);\n return;\n }\n\n const handler = (e: Event) =>\n setFocusedContentState((e as CustomEvent<FileContent | null>).detail);\n manager.focusedContent.addEventListener('change', handler);\n\n return () => manager.focusedContent.removeEventListener('change', handler);\n }, [manager, reactContext?.focusedContent]);\n\n const setFocusedContent = useCallback(\n (value: CrossFrameStateAction<FileContent | null>) => {\n if (reactContext) {\n reactContext.setFocusedContent(value);\n } else if (manager) {\n manager.focusedContent.set(value);\n }\n },\n [reactContext, manager]\n );\n\n const setFocusedContentKeyPath = useCallback(\n (keyPath: KeyPath[]) => {\n if (reactContext) {\n reactContext.setFocusedContentKeyPath(keyPath);\n } else if (manager) {\n manager.setFocusedContentKeyPath(keyPath);\n }\n },\n [reactContext, manager]\n );\n\n return {\n focusedContent,\n setFocusedContent,\n setFocusedContentKeyPath,\n };\n};\n\nexport const useFocusDictionaryActions = (): FocusDictionaryActions => {\n const { setFocusedContent, setFocusedContentKeyPath } = useFocusDictionary();\n return { setFocusedContent, setFocusedContentKeyPath };\n};\n"],"mappings":";;;;;;;;;;;AA+BA,MAAM,kCAA8BA,qBAElC,MAAS;AAGX,MAAa,2BAAkD,EAC7D,eACI;CACJ,MAAM,UAAUC,iDAAsB;CACtC,MAAM,CAAC,iBAAiB,0BAAsBC,gBAC5C,IACF;CAEA,MAAM,wBAAoBC,oBACvB,UAAqD;EACpD,IAAI,SACF,QAAQ,eAAe,IAAI,KAAK;OAEhC,mBAAmB,KAAK;CAE5B,GACA,CAAC,OAAO,CACV;CAEA,MAAM,+BAA2BA,oBAC9B,YAAuB;EACtB,IAAI,SACF,QAAQ,yBAAyB,OAAO;OAExC,oBAAoB,SAAS;GAC3B,IAAI,CAAC,MAAM,OAAO;GAClB,MAAM,WAAW,QAAQ,QACtB,QAAQ,IAAI,SAASC,yBAAU,WAClC;GACA,OAAO;IAAE,GAAG;IAAM,SAAS;GAAS;EACtC,CAAC;CAEL,GACA,CAAC,OAAO,CACV;CAEA,OACE,2CAAC,4BAA4B,UAA7B;EACE,OAAO;GACL,gBAAgB,SAAS,eAAe,SAAS;GACjD;GACA;EACF;EAEC;CACmC;AAE1C;AAGA,MAAa,2BACe;CAC1B,MAAM,UAAUH,iDAAsB;CACtC,MAAM,mBAAeI,kBAAW,2BAA2B;CAE3D,MAAM,CAAC,gBAAgB,8BAA0BH,gBAC/C,SAAS,eAAe,SAAS,cAAc,kBAAkB,IACnE;CAEA,2BAAgB;EACd,IAAI,CAAC,SAAS;GACZ,uBAAuB,cAAc,kBAAkB,IAAI;GAC3D;EACF;EAEA,MAAM,WAAW,MACf,uBAAwB,EAAsC,MAAM;EACtE,QAAQ,eAAe,iBAAiB,UAAU,OAAO;EAEzD,aAAa,QAAQ,eAAe,oBAAoB,UAAU,OAAO;CAC3E,GAAG,CAAC,SAAS,cAAc,cAAc,CAAC;CAwB1C,OAAO;EACL;EACA,uBAxBwBC,oBACvB,UAAqD;GACpD,IAAI,cACF,aAAa,kBAAkB,KAAK;QAC/B,IAAI,SACT,QAAQ,eAAe,IAAI,KAAK;EAEpC,GACA,CAAC,cAAc,OAAO,CAgBN;EAChB,8BAd+BA,oBAC9B,YAAuB;GACtB,IAAI,cACF,aAAa,yBAAyB,OAAO;QACxC,IAAI,SACT,QAAQ,yBAAyB,OAAO;EAE5C,GACA,CAAC,cAAc,OAAO,CAMC;CACzB;AACF;AAEA,MAAa,kCAA0D;CACrE,MAAM,EAAE,mBAAmB,6BAA6B,mBAAmB;CAC3E,OAAO;EAAE;EAAmB;CAAyB;AACvD"}
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"}
@@ -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 require_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
7
- const require_useIframeClickInterceptor = require('./useIframeClickInterceptor.cjs');
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.useFocusDictionaryActions = require_FocusDictionaryContext.useFocusDictionaryActions;
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
- * Synchronizes a React state value across frames using CrossFrameStateManager.
9
+ * Returns the latest value another frame posted under `key`.
11
10
  */
12
- const useCrossFrameState = (key, initialState, options) => {
11
+ const useCrossFrameState = (key, initialValue) => {
13
12
  const manager = require_EditorStateContext.useEditorStateManager();
14
- const resolvedInitial = typeof initialState === "function" ? initialState() : initialState;
15
- const [value, setValueState] = (0, react.useState)(resolvedInitial);
16
- const valueRef = (0, react.useRef)(resolvedInitial);
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","useRef","CrossFrameStateManager"],"sources":["../../src/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport type { MessageKey } from '@intlayer/editor';\nimport { CrossFrameStateManager } from '@intlayer/editor';\nimport {\n type Dispatch,\n type SetStateAction,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type CrossFrameStateOptions = {\n emit?: boolean;\n receive?: boolean;\n};\n\n/**\n * Synchronizes a React state value across frames using CrossFrameStateManager.\n */\nexport const useCrossFrameState = <S,>(\n key: `${MessageKey}`,\n initialState?: S | (() => S),\n options?: CrossFrameStateOptions\n): [S, Dispatch<SetStateAction<S>>, () => void] => {\n const manager = useEditorStateManager();\n\n const resolvedInitial =\n typeof initialState === 'function'\n ? (initialState as () => S)()\n : initialState;\n\n const [value, setValueState] = useState<S>(resolvedInitial as S);\n const valueRef = useRef<S>(resolvedInitial as S);\n\n const stateManagerRef = useRef<CrossFrameStateManager<S> | null>(null);\n\n useEffect(() => {\n const { emit = true, receive = true } = options ?? {};\n\n if (!manager?.messenger) return;\n\n const stateManager = new CrossFrameStateManager<S>(\n key,\n manager?.messenger,\n {\n emit,\n receive,\n initialValue: resolvedInitial,\n }\n );\n stateManagerRef.current = stateManager;\n\n const handler = (e: Event) => {\n const newValue = (e as CustomEvent<S>).detail;\n valueRef.current = newValue;\n setValueState(newValue);\n };\n stateManager.addEventListener('change', handler);\n stateManager.start();\n\n return () => {\n stateManager.removeEventListener('change', handler);\n stateManager.stop();\n stateManagerRef.current = null;\n };\n }, [key, manager?.messenger, options?.emit, options?.receive]);\n\n const setValue: Dispatch<SetStateAction<S>> = (valueOrUpdater) => {\n setValueState((prev) => {\n const newValue =\n typeof valueOrUpdater === 'function'\n ? (valueOrUpdater as (prev: S) => S)(prev)\n : valueOrUpdater;\n valueRef.current = newValue;\n stateManagerRef.current?.set(newValue);\n return newValue;\n });\n };\n\n const postState = () => {\n stateManagerRef.current?.postCurrentValue();\n };\n\n return [value, setValue, postState];\n};\n"],"mappings":";;;;;;;;;;;AAqBA,MAAa,sBACX,KACA,cACA,YACiD;CACjD,MAAM,UAAUA,iDAAsB;CAEtC,MAAM,kBACJ,OAAO,iBAAiB,aACnB,aAAyB,IAC1B;CAEN,MAAM,CAAC,OAAO,qBAAiBC,gBAAY,eAAoB;CAC/D,MAAM,eAAWC,cAAU,eAAoB;CAE/C,MAAM,sBAAkBA,cAAyC,IAAI;CAErE,2BAAgB;EACd,MAAM,EAAE,OAAO,MAAM,UAAU,SAAS,WAAW,CAAC;EAEpD,IAAI,CAAC,SAAS,WAAW;EAEzB,MAAM,eAAe,IAAIC,wCACvB,KACA,SAAS,WACT;GACE;GACA;GACA,cAAc;EAChB,CACF;EACA,gBAAgB,UAAU;EAE1B,MAAM,WAAW,MAAa;GAC5B,MAAM,WAAY,EAAqB;GACvC,SAAS,UAAU;GACnB,cAAc,QAAQ;EACxB;EACA,aAAa,iBAAiB,UAAU,OAAO;EAC/C,aAAa,MAAM;EAEnB,aAAa;GACX,aAAa,oBAAoB,UAAU,OAAO;GAClD,aAAa,KAAK;GAClB,gBAAgB,UAAU;EAC5B;CACF,GAAG;EAAC;EAAK,SAAS;EAAW,SAAS;EAAM,SAAS;CAAO,CAAC;CAE7D,MAAM,YAAyC,mBAAmB;EAChE,eAAe,SAAS;GACtB,MAAM,WACJ,OAAO,mBAAmB,aACrB,eAAkC,IAAI,IACvC;GACN,SAAS,UAAU;GACnB,gBAAgB,SAAS,IAAI,QAAQ;GACrC,OAAO;EACT,CAAC;CACH;CAEA,MAAM,kBAAkB;EACtB,gBAAgB,SAAS,iBAAiB;CAC5C;CAEA,OAAO;EAAC;EAAO;EAAU;CAAS;AACpC"}
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
- const useCrossURLPathState = (initialState, options) => require_useCrossFrameState.useCrossFrameState(_intlayer_editor.MessageKey.INTLAYER_URL_CHANGE, initialState, options);
9
- const useCrossURLPathSetter = (initialState) => {
10
- return useCrossURLPathState(initialState, {
11
- emit: true,
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 {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport const useCrossURLPathState = (\n initialState?: string,\n options?: CrossFrameStateOptions\n) => useCrossFrameState(MessageKey.INTLAYER_URL_CHANGE, initialState, options);\n\nexport const useCrossURLPathSetter = (initialState?: string) => {\n // The EditorStateManager already handles URL tracking in client mode via\n // UrlStateManager.start(). This hook remains for explicit use cases.\n return useCrossURLPathState(initialState, { emit: true, receive: false });\n};\n"],"mappings":";;;;;;;AAQA,MAAa,wBACX,cACA,YACGA,8CAAmBC,4BAAW,qBAAqB,cAAc,OAAO;AAE7E,MAAa,yBAAyB,iBAA0B;CAG9D,OAAO,qBAAqB,cAAc;EAAE,MAAM;EAAM,SAAS;CAAM,CAAC;AAC1E"}
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\nexport const useSetEditorLocale = () => {\n const manager = useEditorStateManager();\n return (locale: Locale) => manager?.currentLocale.set(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;AAEA,MAAa,2BAA2B;CACtC,MAAM,UAAUD,iDAAsB;CACtC,QAAQ,WAAmB,SAAS,cAAc,IAAI,MAAM;AAC9D"}
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 { createContext, useContext, useEffect, useState } from "react";
5
- import { jsx } from "react/jsx-runtime";
4
+ import { useEffect, useState } from "react";
6
5
 
7
6
  //#region src/ConfigurationContext.tsx
8
- const ConfigurationReactContext = createContext(void 0);
9
- const ConfigurationProvider = ({ configuration, children }) => {
10
- const manager = useEditorStateManager();
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 reactConfig = useContext(ConfigurationReactContext);
23
- const [config, setConfig] = useState(manager?.configuration.value ?? reactConfig);
12
+ const [configuration, setConfiguration] = useState(manager?.configuration.value);
24
13
  useEffect(() => {
25
- if (!manager) {
26
- setConfig(reactConfig);
27
- return;
28
- }
29
- const handler = (e) => {
30
- const detail = e.detail;
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 { ConfigurationProvider, useConfiguration, useConfigurationState };
23
+ export { useConfiguration };
51
24
  //# sourceMappingURL=ConfigurationContext.mjs.map