@intlayer/editor-react 8.7.0-canary.0 → 8.7.0-canary.1
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 +22 -8
- package/dist/cjs/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/DictionariesRecordContext.cjs +1 -0
- package/dist/cjs/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/EditedContentContext.cjs +1 -0
- package/dist/cjs/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/EditorEnabledContext.cjs +1 -0
- package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/EditorProvider.cjs +1 -0
- package/dist/cjs/EditorProvider.cjs.map +1 -1
- package/dist/cjs/EditorStateContext.cjs +1 -0
- package/dist/cjs/EditorStateContext.cjs.map +1 -1
- package/dist/cjs/FocusDictionaryContext.cjs +42 -8
- package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/useCrossFrameMessageListener.cjs +1 -0
- package/dist/cjs/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/useCrossFrameState.cjs +1 -0
- package/dist/cjs/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/useCrossURLPathState.cjs +1 -0
- package/dist/cjs/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/useEditorLocale.cjs +1 -0
- package/dist/cjs/useEditorLocale.cjs.map +1 -1
- package/dist/cjs/useFocusUnmergedDictionary.cjs +1 -0
- package/dist/cjs/useFocusUnmergedDictionary.cjs.map +1 -1
- package/dist/cjs/useIframeClickInterceptor.cjs +1 -0
- package/dist/cjs/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/esm/ConfigurationContext.mjs +22 -9
- package/dist/esm/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/FocusDictionaryContext.mjs +41 -10
- package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/index.mjs +2 -2
- package/dist/types/ConfigurationContext.d.ts.map +1 -1
- package/dist/types/FocusDictionaryContext.d.ts +3 -4
- package/dist/types/FocusDictionaryContext.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/package.json +7 -7
|
@@ -1,34 +1,48 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
6
|
let react = require("react");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
8
|
|
|
7
9
|
//#region src/ConfigurationContext.tsx
|
|
10
|
+
const ConfigurationReactContext = (0, react.createContext)(void 0);
|
|
8
11
|
const ConfigurationProvider = ({ configuration, children }) => {
|
|
9
12
|
const manager = require_EditorStateContext.useEditorStateManager();
|
|
10
13
|
(0, react.useEffect)(() => {
|
|
11
14
|
if (!manager || !configuration) return;
|
|
12
15
|
manager.configuration.set(configuration);
|
|
13
16
|
}, [manager, configuration]);
|
|
14
|
-
return
|
|
17
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConfigurationReactContext.Provider, {
|
|
18
|
+
value: configuration,
|
|
19
|
+
children
|
|
20
|
+
});
|
|
15
21
|
};
|
|
16
22
|
const useConfiguration = () => {
|
|
17
23
|
const manager = require_EditorStateContext.useEditorStateManager();
|
|
18
|
-
const
|
|
24
|
+
const reactConfig = (0, react.useContext)(ConfigurationReactContext);
|
|
25
|
+
const [config, setConfig] = (0, react.useState)(manager?.configuration.value ?? reactConfig);
|
|
19
26
|
(0, react.useEffect)(() => {
|
|
20
|
-
if (!manager)
|
|
21
|
-
|
|
27
|
+
if (!manager) {
|
|
28
|
+
setConfig(reactConfig);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const handler = (e) => {
|
|
32
|
+
const detail = e.detail;
|
|
33
|
+
setConfig(detail ?? reactConfig);
|
|
34
|
+
};
|
|
22
35
|
manager.configuration.addEventListener("change", handler);
|
|
23
36
|
return () => manager.configuration.removeEventListener("change", handler);
|
|
24
|
-
}, [manager]);
|
|
25
|
-
return config;
|
|
37
|
+
}, [manager, reactConfig]);
|
|
38
|
+
return config ?? reactConfig;
|
|
26
39
|
};
|
|
27
40
|
const useConfigurationState = () => {
|
|
28
41
|
const manager = require_EditorStateContext.useEditorStateManager();
|
|
29
|
-
const
|
|
42
|
+
const reactConfig = (0, react.useContext)(ConfigurationReactContext);
|
|
43
|
+
const [config, setConfig] = (0, react.useState)(manager?.configuration.value ?? reactConfig);
|
|
30
44
|
return [
|
|
31
|
-
config,
|
|
45
|
+
config ?? reactConfig,
|
|
32
46
|
setConfig,
|
|
33
47
|
() => manager?.configuration.postCurrentValue()
|
|
34
48
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.cjs","names":["useEditorStateManager"],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport {
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.cjs","names":["useEditorStateManager"],"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 ?? 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 ?? reactConfig\n );\n\n return [\n config ?? reactConfig,\n setConfig,\n () => manager?.configuration.postCurrentValue(),\n ] as const;\n};\n"],"mappings":";;;;;;;;;AAcA,MAAM,qDACJ,OACD;AAMD,MAAa,yBAAyD,EACpE,eACA,eACI;CACJ,MAAM,UAAUA,kDAAuB;AAEvC,4BAAgB;AACd,MAAI,CAAC,WAAW,CAAC,cAAe;AAEhC,UAAQ,cAAc,IAAI,cAAc;IACvC,CAAC,SAAS,cAAc,CAAC;AAG5B,QACE,2CAAC,0BAA0B,UAA3B;EAAoC,OAAO;EACxC;EACkC;;AAIzC,MAAa,yBAAqD;CAChE,MAAM,UAAUA,kDAAuB;CACvC,MAAM,oCAAyB,0BAA0B;CAEzD,MAAM,CAAC,QAAQ,iCACb,SAAS,cAAc,SAAS,YACjC;AAED,4BAAgB;AACd,MAAI,CAAC,SAAS;AACZ,aAAU,YAAY;AACtB;;EAGF,MAAM,WAAW,MAAa;GAC5B,MAAM,SAAU,EAAkC;AAClD,aAAU,UAAU,YAAY;;AAGlC,UAAQ,cAAc,iBAAiB,UAAU,QAAQ;AACzD,eAAa,QAAQ,cAAc,oBAAoB,UAAU,QAAQ;IACxE,CAAC,SAAS,YAAY,CAAC;AAG1B,QAAO,UAAU;;AAGnB,MAAa,8BAA8B;CACzC,MAAM,UAAUA,kDAAuB;CACvC,MAAM,oCAAyB,0BAA0B;CAEzD,MAAM,CAAC,QAAQ,iCACb,SAAS,cAAc,SAAS,YACjC;AAED,QAAO;EACL,UAAU;EACV;QACM,SAAS,cAAc,kBAAkB;EAChD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
6
|
let react = require("react");
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionariesRecordContext.cjs","names":["useEditorStateManager"],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { DictionaryContent } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: (value: DictionaryContent) => void;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nexport const useDictionariesRecord = (): DictionariesRecordStatesContextType &\n DictionariesRecordActionsContextType => {\n const manager = useEditorStateManager();\n const [localeDictionaries, setLocaleDictionariesState] =\n useState<DictionaryContent>(manager?.localeDictionaries.value ?? {});\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setLocaleDictionariesState(\n (e as CustomEvent<DictionaryContent>).detail ?? {}\n );\n\n manager.localeDictionaries.addEventListener('change', handler);\n\n return () =>\n manager.localeDictionaries.removeEventListener('change', handler);\n }, [manager]);\n\n const setLocaleDictionaries = useCallback(\n (value: DictionaryContent) => manager?.localeDictionaries.set(value),\n [manager]\n );\n\n const setLocaleDictionary = useCallback(\n (dictionary: Dictionary) => manager?.setLocaleDictionary(dictionary),\n [manager]\n );\n\n return { localeDictionaries, setLocaleDictionaries, setLocaleDictionary };\n};\n\nexport const useDictionariesRecordActions =\n (): DictionariesRecordActionsContextType => {\n const { setLocaleDictionaries, setLocaleDictionary } =\n useDictionariesRecord();\n return { setLocaleDictionaries, setLocaleDictionary };\n };\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.cjs","names":["useEditorStateManager"],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { DictionaryContent } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: (value: DictionaryContent) => void;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nexport const useDictionariesRecord = (): DictionariesRecordStatesContextType &\n DictionariesRecordActionsContextType => {\n const manager = useEditorStateManager();\n const [localeDictionaries, setLocaleDictionariesState] =\n useState<DictionaryContent>(manager?.localeDictionaries.value ?? {});\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setLocaleDictionariesState(\n (e as CustomEvent<DictionaryContent>).detail ?? {}\n );\n\n manager.localeDictionaries.addEventListener('change', handler);\n\n return () =>\n manager.localeDictionaries.removeEventListener('change', handler);\n }, [manager]);\n\n const setLocaleDictionaries = useCallback(\n (value: DictionaryContent) => manager?.localeDictionaries.set(value),\n [manager]\n );\n\n const setLocaleDictionary = useCallback(\n (dictionary: Dictionary) => manager?.setLocaleDictionary(dictionary),\n [manager]\n );\n\n return { localeDictionaries, setLocaleDictionaries, setLocaleDictionary };\n};\n\nexport const useDictionariesRecordActions =\n (): DictionariesRecordActionsContextType => {\n const { setLocaleDictionaries, setLocaleDictionary } =\n useDictionariesRecord();\n return { setLocaleDictionaries, setLocaleDictionary };\n };\n"],"mappings":";;;;;;;;AAiBA,MAAa,8BAC6B;CACxC,MAAM,UAAUA,kDAAuB;CACvC,MAAM,CAAC,oBAAoB,kDACG,SAAS,mBAAmB,SAAS,EAAE,CAAC;AAEtE,4BAAgB;AACd,MAAI,CAAC,QAAS;EAEd,MAAM,WAAW,MACf,2BACG,EAAqC,UAAU,EAAE,CACnD;AAEH,UAAQ,mBAAmB,iBAAiB,UAAU,QAAQ;AAE9D,eACE,QAAQ,mBAAmB,oBAAoB,UAAU,QAAQ;IAClE,CAAC,QAAQ,CAAC;AAYb,QAAO;EAAE;EAAoB,+CAT1B,UAA6B,SAAS,mBAAmB,IAAI,MAAM,EACpE,CAAC,QAAQ,CACV;EAOmD,6CAJjD,eAA2B,SAAS,oBAAoB,WAAW,EACpE,CAAC,QAAQ,CACV;EAEwE;;AAG3E,MAAa,qCACiC;CAC1C,MAAM,EAAE,uBAAuB,wBAC7B,uBAAuB;AACzB,QAAO;EAAE;EAAuB;EAAqB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
6
|
let react = require("react");
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.cjs","names":["useEditorStateManager"],"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport type { DictionaryContent } from '@intlayer/editor';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (editedContent: DictionaryContent) => void;\n setEditedDictionary: (dict: Dictionary) => void;\n setEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n localDictionaryId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedDictionaryContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nexport const useEditedContentActions = (): EditedContentActionsContextType => {\n const manager = useEditorStateManager();\n\n return {\n setEditedContentState: (value: DictionaryContent) =>\n manager?.editedContent.set(value),\n setEditedDictionary: (dict: Dictionary) =>\n manager?.setEditedDictionary(dict),\n setEditedContent: (\n localId: LocalDictionaryId,\n value: Dictionary['content']\n ) => manager?.setEditedContent(localId, value),\n addEditedContent: (localId, value, keyPath, overwrite) =>\n manager?.addContent(localId, value, keyPath, overwrite),\n renameEditedContent: (localId, newKey, keyPath) =>\n manager?.renameContent(localId, newKey, keyPath),\n removeEditedContent: (localId, keyPath) =>\n manager?.removeContent(localId, keyPath),\n restoreEditedContent: (localId) => manager?.restoreContent(localId),\n clearEditedDictionaryContent: (localId) => manager?.clearContent(localId),\n clearEditedContent: () => manager?.clearAllContent(),\n getEditedContentValue: (localIdOrKey, keyPath) =>\n manager?.getContentValue(localIdOrKey, keyPath),\n };\n};\n\nexport const useEditedContent = () => {\n const manager = useEditorStateManager();\n const [editedContent, setEditedContentState] = useState<\n DictionaryContent | undefined\n >(manager?.editedContent.value);\n\n useEffect(() => {\n if (!manager) return;\n const handler = (e: Event) =>\n setEditedContentState((e as CustomEvent<DictionaryContent>).detail);\n manager.editedContent.addEventListener('change', handler);\n return () => manager.editedContent.removeEventListener('change', handler);\n }, [manager]);\n\n const actions = useEditedContentActions();\n return { editedContent, ...actions };\n};\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) => {\n const manager = useEditorStateManager();\n useEffect(() => {\n if (!onEventTriggered || !manager) return;\n return manager.messenger.subscribe(\n `INTLAYER_EDITED_CONTENT_CHANGED/post`,\n onEventTriggered as (data: unknown) => void\n );\n }, [manager, onEventTriggered]);\n};\n\nexport const useGetEditedContentState = () => {\n const manager = useEditorStateManager();\n return () => {\n manager?.messenger.send('INTLAYER_EDITED_CONTENT_CHANGED/get');\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditedContentContext.cjs","names":["useEditorStateManager"],"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport type { DictionaryContent } from '@intlayer/editor';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (editedContent: DictionaryContent) => void;\n setEditedDictionary: (dict: Dictionary) => void;\n setEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n localDictionaryId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedDictionaryContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nexport const useEditedContentActions = (): EditedContentActionsContextType => {\n const manager = useEditorStateManager();\n\n return {\n setEditedContentState: (value: DictionaryContent) =>\n manager?.editedContent.set(value),\n setEditedDictionary: (dict: Dictionary) =>\n manager?.setEditedDictionary(dict),\n setEditedContent: (\n localId: LocalDictionaryId,\n value: Dictionary['content']\n ) => manager?.setEditedContent(localId, value),\n addEditedContent: (localId, value, keyPath, overwrite) =>\n manager?.addContent(localId, value, keyPath, overwrite),\n renameEditedContent: (localId, newKey, keyPath) =>\n manager?.renameContent(localId, newKey, keyPath),\n removeEditedContent: (localId, keyPath) =>\n manager?.removeContent(localId, keyPath),\n restoreEditedContent: (localId) => manager?.restoreContent(localId),\n clearEditedDictionaryContent: (localId) => manager?.clearContent(localId),\n clearEditedContent: () => manager?.clearAllContent(),\n getEditedContentValue: (localIdOrKey, keyPath) =>\n manager?.getContentValue(localIdOrKey, keyPath),\n };\n};\n\nexport const useEditedContent = () => {\n const manager = useEditorStateManager();\n const [editedContent, setEditedContentState] = useState<\n DictionaryContent | undefined\n >(manager?.editedContent.value);\n\n useEffect(() => {\n if (!manager) return;\n const handler = (e: Event) =>\n setEditedContentState((e as CustomEvent<DictionaryContent>).detail);\n manager.editedContent.addEventListener('change', handler);\n return () => manager.editedContent.removeEventListener('change', handler);\n }, [manager]);\n\n const actions = useEditedContentActions();\n return { editedContent, ...actions };\n};\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) => {\n const manager = useEditorStateManager();\n useEffect(() => {\n if (!onEventTriggered || !manager) return;\n return manager.messenger.subscribe(\n `INTLAYER_EDITED_CONTENT_CHANGED/post`,\n onEventTriggered as (data: unknown) => void\n );\n }, [manager, onEventTriggered]);\n};\n\nexport const useGetEditedContentState = () => {\n const manager = useEditorStateManager();\n return () => {\n manager?.messenger.send('INTLAYER_EDITED_CONTENT_CHANGED/get');\n };\n};\n"],"mappings":";;;;;;;;AA6CA,MAAa,gCAAiE;CAC5E,MAAM,UAAUA,kDAAuB;AAEvC,QAAO;EACL,wBAAwB,UACtB,SAAS,cAAc,IAAI,MAAM;EACnC,sBAAsB,SACpB,SAAS,oBAAoB,KAAK;EACpC,mBACE,SACA,UACG,SAAS,iBAAiB,SAAS,MAAM;EAC9C,mBAAmB,SAAS,OAAO,SAAS,cAC1C,SAAS,WAAW,SAAS,OAAO,SAAS,UAAU;EACzD,sBAAsB,SAAS,QAAQ,YACrC,SAAS,cAAc,SAAS,QAAQ,QAAQ;EAClD,sBAAsB,SAAS,YAC7B,SAAS,cAAc,SAAS,QAAQ;EAC1C,uBAAuB,YAAY,SAAS,eAAe,QAAQ;EACnE,+BAA+B,YAAY,SAAS,aAAa,QAAQ;EACzE,0BAA0B,SAAS,iBAAiB;EACpD,wBAAwB,cAAc,YACpC,SAAS,gBAAgB,cAAc,QAAQ;EAClD;;AAGH,MAAa,yBAAyB;CACpC,MAAM,UAAUA,kDAAuB;CACvC,MAAM,CAAC,eAAe,6CAEpB,SAAS,cAAc,MAAM;AAE/B,4BAAgB;AACd,MAAI,CAAC,QAAS;EACd,MAAM,WAAW,MACf,sBAAuB,EAAqC,OAAO;AACrE,UAAQ,cAAc,iBAAiB,UAAU,QAAQ;AACzD,eAAa,QAAQ,cAAc,oBAAoB,UAAU,QAAQ;IACxE,CAAC,QAAQ,CAAC;AAGb,QAAO;EAAE;EAAe,GADR,yBAAyB;EACL;;AAGtC,MAAa,6BACX,qBACG;CACH,MAAM,UAAUA,kDAAuB;AACvC,4BAAgB;AACd,MAAI,CAAC,oBAAoB,CAAC,QAAS;AACnC,SAAO,QAAQ,UAAU,UACvB,wCACA,iBACD;IACA,CAAC,SAAS,iBAAiB,CAAC;;AAGjC,MAAa,iCAAiC;CAC5C,MAAM,UAAUA,kDAAuB;AACvC,cAAa;AACX,WAAS,UAAU,KAAK,sCAAsC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
6
|
let react = require("react");
|
|
6
7
|
let _intlayer_editor = require("@intlayer/editor");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorEnabledContext.cjs","names":["useEditorStateManager","MessageKey"],"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\n/**\n * Returns the current editor-enabled state, kept in sync with the shared\n * EditorStateManager. Replaces the old EditorEnabledContext + EditorEnabledProvider.\n */\nexport const useEditorEnabled = (): EditorEnabledStateProps => {\n const manager = useEditorStateManager();\n const [enabled, setEnabled] = useState<boolean>(\n manager?.editorEnabled.value ?? false\n );\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setEnabled((e as CustomEvent<boolean>).detail);\n manager.editorEnabled.addEventListener('change', handler);\n return () => manager.editorEnabled.removeEventListener('change', handler);\n }, [manager]);\n\n return { enabled };\n};\n\n/**\n * Subscribes to incoming \"get\" requests for editor-enabled state and calls\n * the provided callback so the caller can respond.\n * Used by the editor side to respond when the client asks for the current state.\n */\nexport const useGetEditorEnabledState = (onRequest?: () => void) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onRequest) return;\n\n return manager?.messenger.subscribe(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onRequest\n );\n }, [manager, onRequest]);\n};\n\n/**\n * Returns a function that sets the editor-enabled state and broadcasts it.\n */\nexport const usePostEditorEnabledState = () => {\n const manager = useEditorStateManager();\n\n return (value: boolean) => {\n manager?.editorEnabled.set(value);\n manager?.editorEnabled.postCurrentValue();\n };\n};\n\nexport const useEditorEnabledState = () => {\n const { enabled } = useEditorEnabled();\n const manager = useEditorStateManager();\n const setter = (value: boolean) => manager?.editorEnabled.set(value);\n\n return [enabled, setter] as const;\n};\n\n/**\n * Returns a function that re-pings the client via ARE_YOU_THERE.\n * Use this as the onClick for an \"Enable Editor\" / reconnect button.\n */\nexport const useEditorPingClient = (): (() => void) => {\n const manager = useEditorStateManager();\n\n return () => manager?.pingClient();\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorEnabledContext.cjs","names":["useEditorStateManager","MessageKey"],"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\n/**\n * Returns the current editor-enabled state, kept in sync with the shared\n * EditorStateManager. Replaces the old EditorEnabledContext + EditorEnabledProvider.\n */\nexport const useEditorEnabled = (): EditorEnabledStateProps => {\n const manager = useEditorStateManager();\n const [enabled, setEnabled] = useState<boolean>(\n manager?.editorEnabled.value ?? false\n );\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setEnabled((e as CustomEvent<boolean>).detail);\n manager.editorEnabled.addEventListener('change', handler);\n return () => manager.editorEnabled.removeEventListener('change', handler);\n }, [manager]);\n\n return { enabled };\n};\n\n/**\n * Subscribes to incoming \"get\" requests for editor-enabled state and calls\n * the provided callback so the caller can respond.\n * Used by the editor side to respond when the client asks for the current state.\n */\nexport const useGetEditorEnabledState = (onRequest?: () => void) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onRequest) return;\n\n return manager?.messenger.subscribe(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onRequest\n );\n }, [manager, onRequest]);\n};\n\n/**\n * Returns a function that sets the editor-enabled state and broadcasts it.\n */\nexport const usePostEditorEnabledState = () => {\n const manager = useEditorStateManager();\n\n return (value: boolean) => {\n manager?.editorEnabled.set(value);\n manager?.editorEnabled.postCurrentValue();\n };\n};\n\nexport const useEditorEnabledState = () => {\n const { enabled } = useEditorEnabled();\n const manager = useEditorStateManager();\n const setter = (value: boolean) => manager?.editorEnabled.set(value);\n\n return [enabled, setter] as const;\n};\n\n/**\n * Returns a function that re-pings the client via ARE_YOU_THERE.\n * Use this as the onClick for an \"Enable Editor\" / reconnect button.\n */\nexport const useEditorPingClient = (): (() => void) => {\n const manager = useEditorStateManager();\n\n return () => manager?.pingClient();\n};\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,yBAAkD;CAC7D,MAAM,UAAUA,kDAAuB;CACvC,MAAM,CAAC,SAAS,kCACd,SAAS,cAAc,SAAS,MACjC;AAED,4BAAgB;AACd,MAAI,CAAC,QAAS;EAEd,MAAM,WAAW,MACf,WAAY,EAA2B,OAAO;AAChD,UAAQ,cAAc,iBAAiB,UAAU,QAAQ;AACzD,eAAa,QAAQ,cAAc,oBAAoB,UAAU,QAAQ;IACxE,CAAC,QAAQ,CAAC;AAEb,QAAO,EAAE,SAAS;;;;;;;AAQpB,MAAa,4BAA4B,cAA2B;CAClE,MAAM,UAAUA,kDAAuB;AAEvC,4BAAgB;AACd,MAAI,CAAC,UAAW;AAEhB,SAAO,SAAS,UAAU,UACxB,GAAGC,4BAAW,wBAAwB,OACtC,UACD;IACA,CAAC,SAAS,UAAU,CAAC;;;;;AAM1B,MAAa,kCAAkC;CAC7C,MAAM,UAAUD,kDAAuB;AAEvC,SAAQ,UAAmB;AACzB,WAAS,cAAc,IAAI,MAAM;AACjC,WAAS,cAAc,kBAAkB;;;AAI7C,MAAa,8BAA8B;CACzC,MAAM,EAAE,YAAY,kBAAkB;CACtC,MAAM,UAAUA,kDAAuB;CACvC,MAAM,UAAU,UAAmB,SAAS,cAAc,IAAI,MAAM;AAEpE,QAAO,CAAC,SAAS,OAAO;;;;;;AAO1B,MAAa,4BAA0C;CACrD,MAAM,UAAUA,kDAAuB;AAEvC,cAAa,SAAS,YAAY"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
6
|
let react = require("react");
|
|
6
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorProvider.cjs","names":["EditorStateManager","EditorStateProvider"],"sources":["../../src/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n defineIntlayerElements,\n EditorStateManager,\n type MessengerConfig,\n setGlobalEditorManager,\n} from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FC, type PropsWithChildren, useEffect, useRef } from 'react';\nimport { EditorStateProvider } from './EditorStateContext';\n\nexport type EditorProviderProps = {\n configuration: IntlayerConfig;\n postMessage: (data: any) => void;\n allowedOrigins: string[];\n};\n\n/**\n * EditorProvider creates and manages the lifecycle of an EditorStateManager,\n * provides it to all descendants, and registers the Lit web components.\n */\nexport const EditorProvider: FC<PropsWithChildren<EditorProviderProps>> = ({\n children,\n configuration,\n postMessage,\n allowedOrigins,\n}) => {\n const managerRef = useRef<EditorStateManager | null>(null);\n\n if (!managerRef.current) {\n const messengerConfig: MessengerConfig = {\n allowedOrigins,\n postMessageFn: postMessage,\n };\n\n managerRef.current = new EditorStateManager({\n mode: 'editor',\n messenger: messengerConfig,\n configuration,\n });\n }\n const manager = managerRef.current;\n\n useEffect(() => {\n defineIntlayerElements();\n setGlobalEditorManager(manager);\n\n manager.start();\n return () => {\n manager.stop();\n setGlobalEditorManager(null);\n };\n }, [manager]);\n\n return (\n <EditorStateProvider manager={manager}>{children}</EditorStateProvider>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorProvider.cjs","names":["EditorStateManager","EditorStateProvider"],"sources":["../../src/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n defineIntlayerElements,\n EditorStateManager,\n type MessengerConfig,\n setGlobalEditorManager,\n} from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FC, type PropsWithChildren, useEffect, useRef } from 'react';\nimport { EditorStateProvider } from './EditorStateContext';\n\nexport type EditorProviderProps = {\n configuration: IntlayerConfig;\n postMessage: (data: any) => void;\n allowedOrigins: string[];\n};\n\n/**\n * EditorProvider creates and manages the lifecycle of an EditorStateManager,\n * provides it to all descendants, and registers the Lit web components.\n */\nexport const EditorProvider: FC<PropsWithChildren<EditorProviderProps>> = ({\n children,\n configuration,\n postMessage,\n allowedOrigins,\n}) => {\n const managerRef = useRef<EditorStateManager | null>(null);\n\n if (!managerRef.current) {\n const messengerConfig: MessengerConfig = {\n allowedOrigins,\n postMessageFn: postMessage,\n };\n\n managerRef.current = new EditorStateManager({\n mode: 'editor',\n messenger: messengerConfig,\n configuration,\n });\n }\n const manager = managerRef.current;\n\n useEffect(() => {\n defineIntlayerElements();\n setGlobalEditorManager(manager);\n\n manager.start();\n return () => {\n manager.stop();\n setGlobalEditorManager(null);\n };\n }, [manager]);\n\n return (\n <EditorStateProvider manager={manager}>{children}</EditorStateProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAa,kBAA8D,EACzE,UACA,eACA,aACA,qBACI;CACJ,MAAM,+BAA+C,KAAK;AAE1D,KAAI,CAAC,WAAW,QAMd,YAAW,UAAU,IAAIA,oCAAmB;EAC1C,MAAM;EACN,WAPuC;GACvC;GACA,eAAe;GAChB;EAKC;EACD,CAAC;CAEJ,MAAM,UAAU,WAAW;AAE3B,4BAAgB;AACd,gDAAwB;AACxB,+CAAuB,QAAQ;AAE/B,UAAQ,OAAO;AACf,eAAa;AACX,WAAQ,MAAM;AACd,gDAAuB,KAAK;;IAE7B,CAAC,QAAQ,CAAC;AAEb,QACE,2CAACC,gDAAD;EAA8B;EAAU;EAA+B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorStateContext.cjs","names":[],"sources":["../../src/EditorStateContext.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\n\nconst EditorStateContext = createContext<EditorStateManager | null>(null);\n\nexport const EditorStateProvider: FC<\n PropsWithChildren<{ manager: EditorStateManager }>\n> = ({ children, manager }) => (\n <EditorStateContext.Provider value={manager}>\n {children}\n </EditorStateContext.Provider>\n);\n\nexport const useEditorStateManager = (): EditorStateManager | null =>\n useContext(EditorStateContext);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorStateContext.cjs","names":[],"sources":["../../src/EditorStateContext.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\n\nconst EditorStateContext = createContext<EditorStateManager | null>(null);\n\nexport const EditorStateProvider: FC<\n PropsWithChildren<{ manager: EditorStateManager }>\n> = ({ children, manager }) => (\n <EditorStateContext.Provider value={manager}>\n {children}\n </EditorStateContext.Provider>\n);\n\nexport const useEditorStateManager = (): EditorStateManager | null =>\n useContext(EditorStateContext);\n"],"mappings":";;;;;;;;AAUA,MAAM,8CAA8D,KAAK;AAEzE,MAAa,uBAER,EAAE,UAAU,cACf,2CAAC,mBAAmB,UAApB;CAA6B,OAAO;CACjC;CAC2B;AAGhC,MAAa,oDACA,mBAAmB"}
|
|
@@ -1,26 +1,59 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
6
|
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);
|
|
6
10
|
|
|
7
11
|
//#region src/FocusDictionaryContext.tsx
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
};
|
|
11
40
|
const useFocusDictionary = () => {
|
|
12
41
|
const manager = require_EditorStateContext.useEditorStateManager();
|
|
13
|
-
const
|
|
42
|
+
const reactContext = (0, react.useContext)(FocusDictionaryReactContext);
|
|
43
|
+
const [focusedContent, setFocusedContentState] = (0, react.useState)(manager?.focusedContent.value ?? reactContext?.focusedContent ?? null);
|
|
14
44
|
(0, react.useEffect)(() => {
|
|
15
|
-
if (!manager)
|
|
45
|
+
if (!manager) {
|
|
46
|
+
setFocusedContentState(reactContext?.focusedContent ?? null);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
16
49
|
const handler = (e) => setFocusedContentState(e.detail);
|
|
17
50
|
manager.focusedContent.addEventListener("change", handler);
|
|
18
51
|
return () => manager.focusedContent.removeEventListener("change", handler);
|
|
19
|
-
}, [manager]);
|
|
52
|
+
}, [manager, reactContext?.focusedContent]);
|
|
20
53
|
return {
|
|
21
54
|
focusedContent,
|
|
22
|
-
setFocusedContent: (
|
|
23
|
-
setFocusedContentKeyPath: (
|
|
55
|
+
setFocusedContent: reactContext?.setFocusedContent ?? (() => {}),
|
|
56
|
+
setFocusedContentKeyPath: reactContext?.setFocusedContentKeyPath ?? (() => {})
|
|
24
57
|
};
|
|
25
58
|
};
|
|
26
59
|
const useFocusDictionaryActions = () => {
|
|
@@ -32,6 +65,7 @@ const useFocusDictionaryActions = () => {
|
|
|
32
65
|
};
|
|
33
66
|
|
|
34
67
|
//#endregion
|
|
68
|
+
exports.FocusDictionaryProvider = FocusDictionaryProvider;
|
|
35
69
|
exports.useFocusDictionary = useFocusDictionary;
|
|
36
70
|
exports.useFocusDictionaryActions = useFocusDictionaryActions;
|
|
37
71
|
//# sourceMappingURL=FocusDictionaryContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.cjs","names":["useEditorStateManager"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { FileContent } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.cjs","names":["useEditorStateManager","NodeTypes"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { 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 setFocusedContent: (value: 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: 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 return {\n focusedContent,\n setFocusedContent: reactContext?.setFocusedContent ?? (() => {}),\n setFocusedContentKeyPath:\n reactContext?.setFocusedContentKeyPath ?? (() => {}),\n };\n};\n\nexport const useFocusDictionaryActions = (): FocusDictionaryActions => {\n const { setFocusedContent, setFocusedContentKeyPath } = useFocusDictionary();\n return { setFocusedContent, setFocusedContentKeyPath };\n};\n"],"mappings":";;;;;;;;;;;AA8BA,MAAM,uDAEJ,OAAU;AAGZ,MAAa,2BAAkD,EAC7D,eACI;CACJ,MAAM,UAAUA,kDAAuB;CACvC,MAAM,CAAC,iBAAiB,0CACtB,KACD;CAED,MAAM,4CACH,UAA8B;AAC7B,MAAI,QACF,SAAQ,eAAe,IAAI,MAAM;MAEjC,oBAAmB,MAAM;IAG7B,CAAC,QAAQ,CACV;CAED,MAAM,mDACH,YAAuB;AACtB,MAAI,QACF,SAAQ,yBAAyB,QAAQ;MAEzC,qBAAoB,SAAS;AAC3B,OAAI,CAAC,KAAM,QAAO;GAClB,MAAM,WAAW,QAAQ,QACtB,QAAQ,IAAI,SAASC,yBAAU,YACjC;AACD,UAAO;IAAE,GAAG;IAAM,SAAS;IAAU;IACrC;IAGN,CAAC,QAAQ,CACV;AAED,QACE,2CAAC,4BAA4B,UAA7B;EACE,OAAO;GACL,gBAAgB,SAAS,eAAe,SAAS;GACjD;GACA;GACD;EAEA;EACoC;;AAK3C,MAAa,2BACe;CAC1B,MAAM,UAAUD,kDAAuB;CACvC,MAAM,qCAA0B,4BAA4B;CAE5D,MAAM,CAAC,gBAAgB,8CACrB,SAAS,eAAe,SAAS,cAAc,kBAAkB,KAClE;AAED,4BAAgB;AACd,MAAI,CAAC,SAAS;AACZ,0BAAuB,cAAc,kBAAkB,KAAK;AAC5D;;EAGF,MAAM,WAAW,MACf,uBAAwB,EAAsC,OAAO;AACvE,UAAQ,eAAe,iBAAiB,UAAU,QAAQ;AAE1D,eAAa,QAAQ,eAAe,oBAAoB,UAAU,QAAQ;IACzE,CAAC,SAAS,cAAc,eAAe,CAAC;AAE3C,QAAO;EACL;EACA,mBAAmB,cAAc,4BAA4B;EAC7D,0BACE,cAAc,mCAAmC;EACpD;;AAGH,MAAa,kCAA0D;CACrE,MAAM,EAAE,mBAAmB,6BAA6B,oBAAoB;AAC5E,QAAO;EAAE;EAAmB;EAA0B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
3
4
|
const require_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
|
|
4
5
|
const require_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
@@ -18,6 +19,7 @@ let _intlayer_editor = require("@intlayer/editor");
|
|
|
18
19
|
exports.ConfigurationProvider = require_ConfigurationContext.ConfigurationProvider;
|
|
19
20
|
exports.EditorProvider = require_EditorProvider.EditorProvider;
|
|
20
21
|
exports.EditorStateProvider = require_EditorStateContext.EditorStateProvider;
|
|
22
|
+
exports.FocusDictionaryProvider = require_FocusDictionaryContext.FocusDictionaryProvider;
|
|
21
23
|
Object.defineProperty(exports, 'MessageKey', {
|
|
22
24
|
enumerable: true,
|
|
23
25
|
get: function () {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
6
|
let react = require("react");
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useEditorStateManager"],"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport type { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\n/**\n * Listens for cross-frame messages of the specified type and calls the callback.\n * Returns a function to manually send a message of the same type.\n *\n * Backed by CrossFrameMessenger from EditorStateManager.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onEventTriggered) return;\n return manager?.messenger.subscribe<S>(key, onEventTriggered);\n }, [manager, key, revalidator]);\n\n return (data?: S) => {\n manager?.messenger.send(key, data);\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useEditorStateManager"],"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport type { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\n/**\n * Listens for cross-frame messages of the specified type and calls the callback.\n * Returns a function to manually send a message of the same type.\n *\n * Backed by CrossFrameMessenger from EditorStateManager.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onEventTriggered) return;\n return manager?.messenger.subscribe<S>(key, onEventTriggered);\n }, [manager, key, revalidator]);\n\n return (data?: S) => {\n manager?.messenger.send(key, data);\n };\n};\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAa,gCACX,KACA,kBACA,gBACG;CACH,MAAM,UAAUA,kDAAuB;AAEvC,4BAAgB;AACd,MAAI,CAAC,iBAAkB;AACvB,SAAO,SAAS,UAAU,UAAa,KAAK,iBAAiB;IAC5D;EAAC;EAAS;EAAK;EAAY,CAAC;AAE/B,SAAQ,SAAa;AACnB,WAAS,UAAU,KAAK,KAAK,KAAK"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
6
|
let react = require("react");
|
|
6
7
|
let _intlayer_editor = require("@intlayer/editor");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameState.cjs","names":["useEditorStateManager","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 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":"
|
|
1
|
+
{"version":3,"file":"useCrossFrameState.cjs","names":["useEditorStateManager","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 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,kDAAuB;CAEvC,MAAM,kBACJ,OAAO,iBAAiB,aACnB,cAA0B,GAC3B;CAEN,MAAM,CAAC,OAAO,qCAA6B,gBAAqB;CAChE,MAAM,6BAAqB,gBAAqB;CAEhD,MAAM,oCAA2D,KAAK;AAEtE,4BAAgB;EACd,MAAM,EAAE,OAAO,MAAM,UAAU,SAAS,WAAW,EAAE;EACrD,MAAM,eAAe,IAAIC,wCACvB,KACA,SAAS,WACT;GACE;GACA;GACA,cAAc;GACf,CACF;AACD,kBAAgB,UAAU;EAE1B,MAAM,WAAW,MAAa;GAC5B,MAAM,WAAY,EAAqB;AACvC,YAAS,UAAU;AACnB,iBAAc,SAAS;;AAEzB,eAAa,iBAAiB,UAAU,QAAQ;AAChD,eAAa,OAAO;AAEpB,eAAa;AACX,gBAAa,oBAAoB,UAAU,QAAQ;AACnD,gBAAa,MAAM;AACnB,mBAAgB,UAAU;;IAE3B;EAAC;EAAK,SAAS;EAAW,SAAS;EAAM,SAAS;EAAQ,CAAC;CAE9D,MAAM,YAAyC,mBAAmB;AAChE,iBAAe,SAAS;GACtB,MAAM,WACJ,OAAO,mBAAmB,aACrB,eAAkC,KAAK,GACxC;AACN,YAAS,UAAU;AACnB,mBAAgB,SAAS,IAAI,SAAS;AACtC,UAAO;IACP;;CAGJ,MAAM,kBAAkB;AACtB,kBAAgB,SAAS,kBAAkB;;AAG7C,QAAO;EAAC;EAAO;EAAU;EAAU"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
5
6
|
let _intlayer_editor = require("@intlayer/editor");
|
|
6
7
|
|
|
@@ -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":"
|
|
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,QAAQ;AAE9E,MAAa,yBAAyB,iBAA0B;AAG9D,QAAO,qBAAqB,cAAc;EAAE,MAAM;EAAM,SAAS;EAAO,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
6
|
let react = require("react");
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditorLocale.cjs","names":["useEditorStateManager"],"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":"
|
|
1
|
+
{"version":3,"file":"useEditorLocale.cjs","names":["useEditorStateManager"],"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,kDAAuB;CACvC,MAAM,CAAC,QAAQ,iCACb,SAAS,cAAc,MACxB;AAED,4BAAgB;AACd,MAAI,CAAC,QAAS;EAEd,MAAM,WAAW,MAAa,UAAW,EAA0B,OAAO;AAC1E,UAAQ,cAAc,iBAAiB,UAAU,QAAQ;AAEzD,eAAa,QAAQ,cAAc,oBAAoB,UAAU,QAAQ;IACxE,CAAC,QAAQ,CAAC;AAEb,QAAO;;AAGT,MAAa,2BAA2B;CACtC,MAAM,UAAUA,kDAAuB;AACvC,SAAQ,WAAmB,SAAS,cAAc,IAAI,OAAO"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
|
|
5
6
|
const require_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
|
|
6
7
|
const require_useEditorLocale = require('./useEditorLocale.cjs');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusUnmergedDictionary.cjs","names":["useDictionariesRecord","useEditorLocale","useFocusDictionary"],"sources":["../../src/useFocusUnmergedDictionary.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useMemo } from 'react';\nimport { useDictionariesRecord } from './DictionariesRecordContext';\nimport { type FileContent, useFocusDictionary } from './FocusDictionaryContext';\nimport { useEditorLocale } from './useEditorLocale';\n\ntype UnmergedKeyPath = {\n keyPath: KeyPath[];\n dictionaryLocalId?: LocalDictionaryId;\n};\n\n/**\n * Converts merged keypath format to unmerged format.\n * Merged: [{type: \"translation\", key: \"fr\"}, {type: \"object\", key: \"title\"}]\n * Unmerged: [{type: \"object\", key: \"title\"}, {type: \"translation\", key: \"fr\"}]\n */\nconst mergedKeyPathToUnmergedKeyPath = (\n keyPath: KeyPath[],\n dictionaries: Dictionary[],\n locale?: Locale\n): UnmergedKeyPath | undefined => {\n // If we have a dictionary, verify the path exists\n // Try to find the correct position for the translation key\n // by checking which path actually exists in the dictionary\n for (const dictionary of dictionaries) {\n try {\n const result = getContentNodeByKeyPath(\n dictionary.content,\n keyPath ?? [],\n locale\n );\n\n if (result) {\n return { keyPath, dictionaryLocalId: dictionary.localId };\n }\n } catch {\n // Continue to next candidate\n }\n }\n};\n\nexport const useFocusUnmergedDictionary = () => {\n const { localeDictionaries } = useDictionariesRecord();\n const currentLocale = useEditorLocale();\n const {\n setFocusedContent,\n setFocusedContentKeyPath,\n focusedContent: mergedFocusedContent,\n } = useFocusDictionary();\n\n const focusedContent = useMemo<FileContent | null>(() => {\n if (!mergedFocusedContent) return mergedFocusedContent;\n if (!localeDictionaries) return mergedFocusedContent;\n if (mergedFocusedContent.dictionaryLocalId) return mergedFocusedContent;\n\n const dictionaries = Object.values(localeDictionaries).filter(\n (dictionary) => dictionary.key === mergedFocusedContent.dictionaryKey\n );\n\n const unmergedKeyPath = mergedKeyPathToUnmergedKeyPath(\n mergedFocusedContent.keyPath ?? [],\n dictionaries,\n currentLocale\n );\n\n return {\n ...mergedFocusedContent,\n ...unmergedKeyPath,\n };\n }, [mergedFocusedContent, localeDictionaries, currentLocale]);\n\n return {\n focusedContent,\n setFocusedContent,\n setFocusedContentKeyPath,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFocusUnmergedDictionary.cjs","names":["useDictionariesRecord","useEditorLocale","useFocusDictionary"],"sources":["../../src/useFocusUnmergedDictionary.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useMemo } from 'react';\nimport { useDictionariesRecord } from './DictionariesRecordContext';\nimport { type FileContent, useFocusDictionary } from './FocusDictionaryContext';\nimport { useEditorLocale } from './useEditorLocale';\n\ntype UnmergedKeyPath = {\n keyPath: KeyPath[];\n dictionaryLocalId?: LocalDictionaryId;\n};\n\n/**\n * Converts merged keypath format to unmerged format.\n * Merged: [{type: \"translation\", key: \"fr\"}, {type: \"object\", key: \"title\"}]\n * Unmerged: [{type: \"object\", key: \"title\"}, {type: \"translation\", key: \"fr\"}]\n */\nconst mergedKeyPathToUnmergedKeyPath = (\n keyPath: KeyPath[],\n dictionaries: Dictionary[],\n locale?: Locale\n): UnmergedKeyPath | undefined => {\n // If we have a dictionary, verify the path exists\n // Try to find the correct position for the translation key\n // by checking which path actually exists in the dictionary\n for (const dictionary of dictionaries) {\n try {\n const result = getContentNodeByKeyPath(\n dictionary.content,\n keyPath ?? [],\n locale\n );\n\n if (result) {\n return { keyPath, dictionaryLocalId: dictionary.localId };\n }\n } catch {\n // Continue to next candidate\n }\n }\n};\n\nexport const useFocusUnmergedDictionary = () => {\n const { localeDictionaries } = useDictionariesRecord();\n const currentLocale = useEditorLocale();\n const {\n setFocusedContent,\n setFocusedContentKeyPath,\n focusedContent: mergedFocusedContent,\n } = useFocusDictionary();\n\n const focusedContent = useMemo<FileContent | null>(() => {\n if (!mergedFocusedContent) return mergedFocusedContent;\n if (!localeDictionaries) return mergedFocusedContent;\n if (mergedFocusedContent.dictionaryLocalId) return mergedFocusedContent;\n\n const dictionaries = Object.values(localeDictionaries).filter(\n (dictionary) => dictionary.key === mergedFocusedContent.dictionaryKey\n );\n\n const unmergedKeyPath = mergedKeyPathToUnmergedKeyPath(\n mergedFocusedContent.keyPath ?? [],\n dictionaries,\n currentLocale\n );\n\n return {\n ...mergedFocusedContent,\n ...unmergedKeyPath,\n };\n }, [mergedFocusedContent, localeDictionaries, currentLocale]);\n\n return {\n focusedContent,\n setFocusedContent,\n setFocusedContentKeyPath,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,MAAM,kCACJ,SACA,cACA,WACgC;AAIhC,MAAK,MAAM,cAAc,aACvB,KAAI;AAOF,wEALE,WAAW,SACX,WAAW,EAAE,EACb,OACD,CAGC,QAAO;GAAE;GAAS,mBAAmB,WAAW;GAAS;SAErD;;AAMZ,MAAa,mCAAmC;CAC9C,MAAM,EAAE,uBAAuBA,yDAAuB;CACtD,MAAM,gBAAgBC,yCAAiB;CACvC,MAAM,EACJ,mBACA,0BACA,gBAAgB,yBACdC,mDAAoB;AAuBxB,QAAO;EACL,yCAtBuD;AACvD,OAAI,CAAC,qBAAsB,QAAO;AAClC,OAAI,CAAC,mBAAoB,QAAO;AAChC,OAAI,qBAAqB,kBAAmB,QAAO;GAEnD,MAAM,eAAe,OAAO,OAAO,mBAAmB,CAAC,QACpD,eAAe,WAAW,QAAQ,qBAAqB,cACzD;GAED,MAAM,kBAAkB,+BACtB,qBAAqB,WAAW,EAAE,EAClC,cACA,cACD;AAED,UAAO;IACL,GAAG;IACH,GAAG;IACJ;KACA;GAAC;GAAsB;GAAoB;GAAc,CAAC;EAI3D;EACA;EACD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
4
5
|
const require_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
|
|
5
6
|
let _intlayer_editor = require("@intlayer/editor");
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIframeClickInterceptor.cjs","names":["MessageKey","mergeIframeClick"],"sources":["../../src/useIframeClickInterceptor.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey, mergeIframeClick } from '@intlayer/editor';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\n/**\n * Broadcasts mousedown events from within an iframe to the parent frame.\n * Called in the client application (inside the iframe).\n * Note: EditorStateManager.start() already sets this up in client mode.\n * This hook exists for explicit / standalone use cases.\n */\nexport const useIframeClickInterceptor = () => {\n useCrossFrameMessageListener<undefined>(MessageKey.INTLAYER_IFRAME_CLICKED);\n};\n\n/**\n * Merges received iframe click events into the parent's DOM event stream.\n * Called in the editor (parent frame).\n */\nexport const useIframeClickMerger = () => {\n useCrossFrameMessageListener<MessageEvent>(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIframeClickInterceptor.cjs","names":["MessageKey","mergeIframeClick"],"sources":["../../src/useIframeClickInterceptor.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey, mergeIframeClick } from '@intlayer/editor';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\n/**\n * Broadcasts mousedown events from within an iframe to the parent frame.\n * Called in the client application (inside the iframe).\n * Note: EditorStateManager.start() already sets this up in client mode.\n * This hook exists for explicit / standalone use cases.\n */\nexport const useIframeClickInterceptor = () => {\n useCrossFrameMessageListener<undefined>(MessageKey.INTLAYER_IFRAME_CLICKED);\n};\n\n/**\n * Merges received iframe click events into the parent's DOM event stream.\n * Called in the editor (parent frame).\n */\nexport const useIframeClickMerger = () => {\n useCrossFrameMessageListener<MessageEvent>(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick\n );\n};\n"],"mappings":";;;;;;;;;;;;;;AAWA,MAAa,kCAAkC;AAC7C,mEAAwCA,4BAAW,wBAAwB;;;;;;AAO7E,MAAa,6BAA6B;AACxC,mEACEA,4BAAW,yBACXC,kCACD"}
|
|
@@ -1,33 +1,46 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useEditorStateManager } from "./EditorStateContext.mjs";
|
|
4
|
-
import { useEffect, useState } from "react";
|
|
4
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
|
|
6
7
|
//#region src/ConfigurationContext.tsx
|
|
8
|
+
const ConfigurationReactContext = createContext(void 0);
|
|
7
9
|
const ConfigurationProvider = ({ configuration, children }) => {
|
|
8
10
|
const manager = useEditorStateManager();
|
|
9
11
|
useEffect(() => {
|
|
10
12
|
if (!manager || !configuration) return;
|
|
11
13
|
manager.configuration.set(configuration);
|
|
12
14
|
}, [manager, configuration]);
|
|
13
|
-
return
|
|
15
|
+
return /* @__PURE__ */ jsx(ConfigurationReactContext.Provider, {
|
|
16
|
+
value: configuration,
|
|
17
|
+
children
|
|
18
|
+
});
|
|
14
19
|
};
|
|
15
20
|
const useConfiguration = () => {
|
|
16
21
|
const manager = useEditorStateManager();
|
|
17
|
-
const
|
|
22
|
+
const reactConfig = useContext(ConfigurationReactContext);
|
|
23
|
+
const [config, setConfig] = useState(manager?.configuration.value ?? reactConfig);
|
|
18
24
|
useEffect(() => {
|
|
19
|
-
if (!manager)
|
|
20
|
-
|
|
25
|
+
if (!manager) {
|
|
26
|
+
setConfig(reactConfig);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const handler = (e) => {
|
|
30
|
+
const detail = e.detail;
|
|
31
|
+
setConfig(detail ?? reactConfig);
|
|
32
|
+
};
|
|
21
33
|
manager.configuration.addEventListener("change", handler);
|
|
22
34
|
return () => manager.configuration.removeEventListener("change", handler);
|
|
23
|
-
}, [manager]);
|
|
24
|
-
return config;
|
|
35
|
+
}, [manager, reactConfig]);
|
|
36
|
+
return config ?? reactConfig;
|
|
25
37
|
};
|
|
26
38
|
const useConfigurationState = () => {
|
|
27
39
|
const manager = useEditorStateManager();
|
|
28
|
-
const
|
|
40
|
+
const reactConfig = useContext(ConfigurationReactContext);
|
|
41
|
+
const [config, setConfig] = useState(manager?.configuration.value ?? reactConfig);
|
|
29
42
|
return [
|
|
30
|
-
config,
|
|
43
|
+
config ?? reactConfig,
|
|
31
44
|
setConfig,
|
|
32
45
|
() => manager?.configuration.postCurrentValue()
|
|
33
46
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.mjs","names":[],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport {
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.mjs","names":[],"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 ?? 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 ?? reactConfig\n );\n\n return [\n config ?? reactConfig,\n setConfig,\n () => manager?.configuration.postCurrentValue(),\n ] as const;\n};\n"],"mappings":";;;;;;;AAcA,MAAM,4BAA4B,cAChC,OACD;AAMD,MAAa,yBAAyD,EACpE,eACA,eACI;CACJ,MAAM,UAAU,uBAAuB;AAEvC,iBAAgB;AACd,MAAI,CAAC,WAAW,CAAC,cAAe;AAEhC,UAAQ,cAAc,IAAI,cAAc;IACvC,CAAC,SAAS,cAAc,CAAC;AAG5B,QACE,oBAAC,0BAA0B,UAA3B;EAAoC,OAAO;EACxC;EACkC;;AAIzC,MAAa,yBAAqD;CAChE,MAAM,UAAU,uBAAuB;CACvC,MAAM,cAAc,WAAW,0BAA0B;CAEzD,MAAM,CAAC,QAAQ,aAAa,SAC1B,SAAS,cAAc,SAAS,YACjC;AAED,iBAAgB;AACd,MAAI,CAAC,SAAS;AACZ,aAAU,YAAY;AACtB;;EAGF,MAAM,WAAW,MAAa;GAC5B,MAAM,SAAU,EAAkC;AAClD,aAAU,UAAU,YAAY;;AAGlC,UAAQ,cAAc,iBAAiB,UAAU,QAAQ;AACzD,eAAa,QAAQ,cAAc,oBAAoB,UAAU,QAAQ;IACxE,CAAC,SAAS,YAAY,CAAC;AAG1B,QAAO,UAAU;;AAGnB,MAAa,8BAA8B;CACzC,MAAM,UAAU,uBAAuB;CACvC,MAAM,cAAc,WAAW,0BAA0B;CAEzD,MAAM,CAAC,QAAQ,aAAa,SAC1B,SAAS,cAAc,SAAS,YACjC;AAED,QAAO;EACL,UAAU;EACV;QACM,SAAS,cAAc,kBAAkB;EAChD"}
|
|
@@ -1,25 +1,56 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useEditorStateManager } from "./EditorStateContext.mjs";
|
|
4
|
-
import { useEffect, useState } from "react";
|
|
4
|
+
import { createContext, useCallback, useContext, useEffect, useState } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import * as NodeTypes from "@intlayer/types/nodeType";
|
|
5
7
|
|
|
6
8
|
//#region src/FocusDictionaryContext.tsx
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const FocusDictionaryReactContext = createContext(void 0);
|
|
10
|
+
const FocusDictionaryProvider = ({ children }) => {
|
|
11
|
+
const manager = useEditorStateManager();
|
|
12
|
+
const [fallbackContent, setFallbackContent] = useState(null);
|
|
13
|
+
const setFocusedContent = useCallback((value) => {
|
|
14
|
+
if (manager) manager.focusedContent.set(value);
|
|
15
|
+
else setFallbackContent(value);
|
|
16
|
+
}, [manager]);
|
|
17
|
+
const setFocusedContentKeyPath = useCallback((keyPath) => {
|
|
18
|
+
if (manager) manager.setFocusedContentKeyPath(keyPath);
|
|
19
|
+
else setFallbackContent((prev) => {
|
|
20
|
+
if (!prev) return null;
|
|
21
|
+
const filtered = keyPath.filter((key) => key.type !== NodeTypes.TRANSLATION);
|
|
22
|
+
return {
|
|
23
|
+
...prev,
|
|
24
|
+
keyPath: filtered
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}, [manager]);
|
|
28
|
+
return /* @__PURE__ */ jsx(FocusDictionaryReactContext.Provider, {
|
|
29
|
+
value: {
|
|
30
|
+
focusedContent: manager?.focusedContent.value ?? fallbackContent,
|
|
31
|
+
setFocusedContent,
|
|
32
|
+
setFocusedContentKeyPath
|
|
33
|
+
},
|
|
34
|
+
children
|
|
35
|
+
});
|
|
36
|
+
};
|
|
10
37
|
const useFocusDictionary = () => {
|
|
11
38
|
const manager = useEditorStateManager();
|
|
12
|
-
const
|
|
39
|
+
const reactContext = useContext(FocusDictionaryReactContext);
|
|
40
|
+
const [focusedContent, setFocusedContentState] = useState(manager?.focusedContent.value ?? reactContext?.focusedContent ?? null);
|
|
13
41
|
useEffect(() => {
|
|
14
|
-
if (!manager)
|
|
42
|
+
if (!manager) {
|
|
43
|
+
setFocusedContentState(reactContext?.focusedContent ?? null);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
15
46
|
const handler = (e) => setFocusedContentState(e.detail);
|
|
16
47
|
manager.focusedContent.addEventListener("change", handler);
|
|
17
48
|
return () => manager.focusedContent.removeEventListener("change", handler);
|
|
18
|
-
}, [manager]);
|
|
49
|
+
}, [manager, reactContext?.focusedContent]);
|
|
19
50
|
return {
|
|
20
51
|
focusedContent,
|
|
21
|
-
setFocusedContent: (
|
|
22
|
-
setFocusedContentKeyPath: (
|
|
52
|
+
setFocusedContent: reactContext?.setFocusedContent ?? (() => {}),
|
|
53
|
+
setFocusedContentKeyPath: reactContext?.setFocusedContentKeyPath ?? (() => {})
|
|
23
54
|
};
|
|
24
55
|
};
|
|
25
56
|
const useFocusDictionaryActions = () => {
|
|
@@ -31,5 +62,5 @@ const useFocusDictionaryActions = () => {
|
|
|
31
62
|
};
|
|
32
63
|
|
|
33
64
|
//#endregion
|
|
34
|
-
export { useFocusDictionary, useFocusDictionaryActions };
|
|
65
|
+
export { FocusDictionaryProvider, useFocusDictionary, useFocusDictionaryActions };
|
|
35
66
|
//# sourceMappingURL=FocusDictionaryContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.mjs","names":[],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { FileContent } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.mjs","names":[],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { 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 setFocusedContent: (value: 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: 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 return {\n focusedContent,\n setFocusedContent: reactContext?.setFocusedContent ?? (() => {}),\n setFocusedContentKeyPath:\n reactContext?.setFocusedContentKeyPath ?? (() => {}),\n };\n};\n\nexport const useFocusDictionaryActions = (): FocusDictionaryActions => {\n const { setFocusedContent, setFocusedContentKeyPath } = useFocusDictionary();\n return { setFocusedContent, setFocusedContentKeyPath };\n};\n"],"mappings":";;;;;;;;AA8BA,MAAM,8BAA8B,cAElC,OAAU;AAGZ,MAAa,2BAAkD,EAC7D,eACI;CACJ,MAAM,UAAU,uBAAuB;CACvC,MAAM,CAAC,iBAAiB,sBAAsB,SAC5C,KACD;CAED,MAAM,oBAAoB,aACvB,UAA8B;AAC7B,MAAI,QACF,SAAQ,eAAe,IAAI,MAAM;MAEjC,oBAAmB,MAAM;IAG7B,CAAC,QAAQ,CACV;CAED,MAAM,2BAA2B,aAC9B,YAAuB;AACtB,MAAI,QACF,SAAQ,yBAAyB,QAAQ;MAEzC,qBAAoB,SAAS;AAC3B,OAAI,CAAC,KAAM,QAAO;GAClB,MAAM,WAAW,QAAQ,QACtB,QAAQ,IAAI,SAAS,UAAU,YACjC;AACD,UAAO;IAAE,GAAG;IAAM,SAAS;IAAU;IACrC;IAGN,CAAC,QAAQ,CACV;AAED,QACE,oBAAC,4BAA4B,UAA7B;EACE,OAAO;GACL,gBAAgB,SAAS,eAAe,SAAS;GACjD;GACA;GACD;EAEA;EACoC;;AAK3C,MAAa,2BACe;CAC1B,MAAM,UAAU,uBAAuB;CACvC,MAAM,eAAe,WAAW,4BAA4B;CAE5D,MAAM,CAAC,gBAAgB,0BAA0B,SAC/C,SAAS,eAAe,SAAS,cAAc,kBAAkB,KAClE;AAED,iBAAgB;AACd,MAAI,CAAC,SAAS;AACZ,0BAAuB,cAAc,kBAAkB,KAAK;AAC5D;;EAGF,MAAM,WAAW,MACf,uBAAwB,EAAsC,OAAO;AACvE,UAAQ,eAAe,iBAAiB,UAAU,QAAQ;AAE1D,eAAa,QAAQ,eAAe,oBAAoB,UAAU,QAAQ;IACzE,CAAC,SAAS,cAAc,eAAe,CAAC;AAE3C,QAAO;EACL;EACA,mBAAmB,cAAc,4BAA4B;EAC7D,0BACE,cAAc,mCAAmC;EACpD;;AAGH,MAAa,kCAA0D;CACrE,MAAM,EAAE,mBAAmB,6BAA6B,oBAAoB;AAC5E,QAAO;EAAE;EAAmB;EAA0B"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EditorStateProvider, useEditorStateManager } from "./EditorStateContext.mjs";
|
|
2
|
-
import { useFocusDictionary, useFocusDictionaryActions } from "./FocusDictionaryContext.mjs";
|
|
2
|
+
import { FocusDictionaryProvider, useFocusDictionary, useFocusDictionaryActions } from "./FocusDictionaryContext.mjs";
|
|
3
3
|
import { useCrossFrameState } from "./useCrossFrameState.mjs";
|
|
4
4
|
import { useCrossURLPathSetter, useCrossURLPathState } from "./useCrossURLPathState.mjs";
|
|
5
5
|
import { useDictionariesRecord, useDictionariesRecordActions } from "./DictionariesRecordContext.mjs";
|
|
@@ -14,4 +14,4 @@ import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs
|
|
|
14
14
|
import { useIframeClickInterceptor, useIframeClickMerger } from "./useIframeClickInterceptor.mjs";
|
|
15
15
|
import { MessageKey } from "@intlayer/editor";
|
|
16
16
|
|
|
17
|
-
export { ConfigurationProvider, EditorProvider, EditorStateProvider, MessageKey, useCommunicator, useConfiguration, useConfigurationState, useCrossFrameMessageListener, useCrossFrameState, useCrossURLPathSetter, useCrossURLPathState, useDictionariesRecord, useDictionariesRecordActions, useEditedContent, useEditedContentActions, useEditorEnabled, useEditorEnabledState, useEditorLocale, useEditorPingClient, useEditorStateManager, useFocusDictionary, useFocusDictionaryActions, useFocusUnmergedDictionary, useGetEditedContentState, useGetEditorEnabledState, useIframeClickInterceptor, useIframeClickMerger, usePostEditedContentState, usePostEditorEnabledState, useSetEditorLocale };
|
|
17
|
+
export { ConfigurationProvider, EditorProvider, EditorStateProvider, FocusDictionaryProvider, MessageKey, useCommunicator, useConfiguration, useConfigurationState, useCrossFrameMessageListener, useCrossFrameState, useCrossURLPathSetter, useCrossURLPathState, useDictionariesRecord, useDictionariesRecordActions, useEditedContent, useEditedContentActions, useEditorEnabled, useEditorEnabledState, useEditorLocale, useEditorPingClient, useEditorStateManager, useFocusDictionary, useFocusDictionaryActions, useFocusUnmergedDictionary, useGetEditedContentState, useGetEditorEnabledState, useIframeClickInterceptor, useIframeClickMerger, usePostEditedContentState, usePostEditorEnabledState, useSetEditorLocale };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.d.ts","names":[],"sources":["../../src/ConfigurationContext.tsx"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.d.ts","names":[],"sources":["../../src/ConfigurationContext.tsx"],"mappings":";;;;;KAkBY,0BAAA,GAA6B,iBAAA;EACvC,aAAA,GAAgB,cAAA;AAAA;AAAA,cAGL,qBAAA,EAAuB,EAAA,CAAG,0BAAA;AAAA,cAoB1B,gBAAA,QAAuB,cAAA;AAAA,cA2BvB,qBAAA,kBAAqB,cAAA,EAAA,OAAA,CAAA,QAAA,CAAA,OAAA,CAAA,cAAA,CAAA,cAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FileContent, FileContent as FileContent$1 } from "@intlayer/editor";
|
|
2
|
+
import { FC, PropsWithChildren } from "react";
|
|
2
3
|
import { KeyPath } from "@intlayer/types/keyPath";
|
|
3
4
|
|
|
4
5
|
//#region src/FocusDictionaryContext.d.ts
|
|
@@ -9,11 +10,9 @@ type FocusDictionaryActions = {
|
|
|
9
10
|
setFocusedContent: (value: FileContent$1 | null) => void;
|
|
10
11
|
setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
* Returns the focused-content state and setters, backed by EditorStateManager.
|
|
14
|
-
*/
|
|
13
|
+
declare const FocusDictionaryProvider: FC<PropsWithChildren>;
|
|
15
14
|
declare const useFocusDictionary: () => FocusDictionaryState & FocusDictionaryActions;
|
|
16
15
|
declare const useFocusDictionaryActions: () => FocusDictionaryActions;
|
|
17
16
|
//#endregion
|
|
18
|
-
export { type FileContent, FocusDictionaryActions, FocusDictionaryState, useFocusDictionary, useFocusDictionaryActions };
|
|
17
|
+
export { type FileContent, FocusDictionaryActions, FocusDictionaryProvider, FocusDictionaryState, useFocusDictionary, useFocusDictionaryActions };
|
|
19
18
|
//# sourceMappingURL=FocusDictionaryContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.d.ts","names":[],"sources":["../../src/FocusDictionaryContext.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.d.ts","names":[],"sources":["../../src/FocusDictionaryContext.tsx"],"mappings":";;;;;KAkBY,oBAAA;EACV,cAAA,EAAgB,aAAA;AAAA;AAAA,KAGN,sBAAA;EACV,iBAAA,GAAoB,KAAA,EAAO,aAAA;EAC3B,wBAAA,GAA2B,OAAA,EAAS,OAAA;AAAA;AAAA,cAWzB,uBAAA,EAAyB,EAAA,CAAG,iBAAA;AAAA,cAkD5B,kBAAA,QAAyB,oBAAA,GACpC,sBAAA;AAAA,cA6BW,yBAAA,QAAgC,sBAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { useEditedContent, useEditedContentActions, useGetEditedContentState, us
|
|
|
5
5
|
import { EditorEnabledStateProps, useEditorEnabled, useEditorEnabledState, useEditorPingClient, useGetEditorEnabledState, usePostEditorEnabledState } from "./EditorEnabledContext.js";
|
|
6
6
|
import { EditorProvider, EditorProviderProps } from "./EditorProvider.js";
|
|
7
7
|
import { EditorStateProvider, useEditorStateManager } from "./EditorStateContext.js";
|
|
8
|
-
import { FileContent, FocusDictionaryActions, FocusDictionaryState, useFocusDictionary, useFocusDictionaryActions } from "./FocusDictionaryContext.js";
|
|
8
|
+
import { FileContent, FocusDictionaryActions, FocusDictionaryProvider, FocusDictionaryState, useFocusDictionary, useFocusDictionaryActions } from "./FocusDictionaryContext.js";
|
|
9
9
|
import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.js";
|
|
10
10
|
import { CrossFrameStateOptions, useCrossFrameState } from "./useCrossFrameState.js";
|
|
11
11
|
import { useCrossURLPathSetter, useCrossURLPathState } from "./useCrossURLPathState.js";
|
|
@@ -13,4 +13,4 @@ import { useEditorLocale, useSetEditorLocale } from "./useEditorLocale.js";
|
|
|
13
13
|
import { useFocusUnmergedDictionary } from "./useFocusUnmergedDictionary.js";
|
|
14
14
|
import { useIframeClickInterceptor, useIframeClickMerger } from "./useIframeClickInterceptor.js";
|
|
15
15
|
import { MessageKey } from "@intlayer/editor";
|
|
16
|
-
export { ConfigurationProvider, ConfigurationProviderProps, CrossFrameStateOptions, EditorEnabledStateProps, EditorProvider, EditorProviderProps, EditorStateProvider, FileContent, FocusDictionaryActions, FocusDictionaryState, MessageKey, MessengerConfig, UseCrossPlatformStateProps, useCommunicator, useConfiguration, useConfigurationState, useCrossFrameMessageListener, useCrossFrameState, useCrossURLPathSetter, useCrossURLPathState, useDictionariesRecord, useDictionariesRecordActions, useEditedContent, useEditedContentActions, useEditorEnabled, useEditorEnabledState, useEditorLocale, useEditorPingClient, useEditorStateManager, useFocusDictionary, useFocusDictionaryActions, useFocusUnmergedDictionary, useGetEditedContentState, useGetEditorEnabledState, useIframeClickInterceptor, useIframeClickMerger, usePostEditedContentState, usePostEditorEnabledState, useSetEditorLocale };
|
|
16
|
+
export { ConfigurationProvider, ConfigurationProviderProps, CrossFrameStateOptions, EditorEnabledStateProps, EditorProvider, EditorProviderProps, EditorStateProvider, FileContent, FocusDictionaryActions, FocusDictionaryProvider, FocusDictionaryState, MessageKey, MessengerConfig, UseCrossPlatformStateProps, useCommunicator, useConfiguration, useConfigurationState, useCrossFrameMessageListener, useCrossFrameState, useCrossURLPathSetter, useCrossURLPathState, useDictionariesRecord, useDictionariesRecordActions, useEditedContent, useEditedContentActions, useEditorEnabled, useEditorEnabledState, useEditorLocale, useEditorPingClient, useEditorStateManager, useFocusDictionary, useFocusDictionaryActions, useFocusUnmergedDictionary, useGetEditedContentState, useGetEditorEnabledState, useIframeClickInterceptor, useIframeClickMerger, usePostEditedContentState, usePostEditorEnabledState, useSetEditorLocale };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/editor-react",
|
|
3
|
-
"version": "8.7.0-canary.
|
|
3
|
+
"version": "8.7.0-canary.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Provides the states, contexts, hooks and components to interact with the Intlayer editor for a React application",
|
|
6
6
|
"keywords": [
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@intlayer/config": "8.7.0-canary.
|
|
74
|
-
"@intlayer/core": "8.7.0-canary.
|
|
75
|
-
"@intlayer/editor": "8.7.0-canary.
|
|
76
|
-
"@intlayer/types": "8.7.0-canary.
|
|
77
|
-
"@intlayer/unmerged-dictionaries-entry": "8.7.0-canary.
|
|
73
|
+
"@intlayer/config": "8.7.0-canary.1",
|
|
74
|
+
"@intlayer/core": "8.7.0-canary.1",
|
|
75
|
+
"@intlayer/editor": "8.7.0-canary.1",
|
|
76
|
+
"@intlayer/types": "8.7.0-canary.1",
|
|
77
|
+
"@intlayer/unmerged-dictionaries-entry": "8.7.0-canary.1"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/node": "25.5.2",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"rimraf": "6.1.3",
|
|
89
89
|
"tsdown": "0.21.7",
|
|
90
90
|
"typescript": "6.0.2",
|
|
91
|
-
"vitest": "4.1.
|
|
91
|
+
"vitest": "4.1.4"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"react": ">=16.0.0",
|