@intlayer/editor-react 8.4.4 → 8.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/CommunicatorContext.cjs +19 -1
- package/dist/cjs/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/ConfigurationContext.cjs +40 -1
- package/dist/cjs/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/DictionariesRecordContext.cjs +33 -1
- package/dist/cjs/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/EditedContentContext.cjs +55 -1
- package/dist/cjs/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/EditorEnabledContext.cjs +66 -1
- package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/EditorProvider.cjs +41 -1
- package/dist/cjs/EditorProvider.cjs.map +1 -1
- package/dist/cjs/EditorStateContext.cjs +17 -1
- package/dist/cjs/EditorStateContext.cjs.map +1 -1
- package/dist/cjs/FocusDictionaryContext.cjs +36 -1
- package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/index.cjs +52 -1
- package/dist/cjs/useCrossFrameMessageListener.cjs +30 -1
- package/dist/cjs/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/useCrossFrameState.cjs +63 -1
- package/dist/cjs/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/useCrossURLPathState.cjs +18 -1
- package/dist/cjs/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/useEditorLocale.cjs +26 -1
- package/dist/cjs/useEditorLocale.cjs.map +1 -1
- package/dist/cjs/useFocusUnmergedDictionary.cjs +50 -1
- package/dist/cjs/useFocusUnmergedDictionary.cjs.map +1 -1
- package/dist/cjs/useIframeClickInterceptor.cjs +27 -1
- package/dist/cjs/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/esm/CommunicatorContext.mjs +18 -1
- package/dist/esm/CommunicatorContext.mjs.map +1 -1
- package/dist/esm/ConfigurationContext.mjs +37 -1
- package/dist/esm/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/DictionariesRecordContext.mjs +31 -1
- package/dist/esm/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/EditedContentContext.mjs +51 -1
- package/dist/esm/EditedContentContext.mjs.map +1 -1
- package/dist/esm/EditorEnabledContext.mjs +61 -1
- package/dist/esm/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/EditorProvider.mjs +40 -1
- package/dist/esm/EditorProvider.mjs.map +1 -1
- package/dist/esm/EditorStateContext.mjs +15 -1
- package/dist/esm/EditorStateContext.mjs.map +1 -1
- package/dist/esm/FocusDictionaryContext.mjs +34 -1
- package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/index.mjs +17 -1
- package/dist/esm/useCrossFrameMessageListener.mjs +29 -1
- package/dist/esm/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/useCrossFrameState.mjs +62 -1
- package/dist/esm/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/useCrossURLPathState.mjs +16 -1
- package/dist/esm/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/useEditorLocale.mjs +24 -1
- package/dist/esm/useEditorLocale.mjs.map +1 -1
- package/dist/esm/useFocusUnmergedDictionary.mjs +49 -1
- package/dist/esm/useFocusUnmergedDictionary.mjs.map +1 -1
- package/dist/esm/useIframeClickInterceptor.mjs +25 -1
- package/dist/esm/useIframeClickInterceptor.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -1,2 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let _intlayer_editor = require("@intlayer/editor");
|
|
7
|
+
|
|
8
|
+
//#region src/useCrossFrameState.tsx
|
|
9
|
+
/**
|
|
10
|
+
* Synchronizes a React state value across frames using CrossFrameStateManager.
|
|
11
|
+
*/
|
|
12
|
+
const useCrossFrameState = (key, initialState, options) => {
|
|
13
|
+
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
|
+
const stateManager = new _intlayer_editor.CrossFrameStateManager(key, manager?.messenger, {
|
|
21
|
+
emit,
|
|
22
|
+
receive,
|
|
23
|
+
initialValue: resolvedInitial
|
|
24
|
+
});
|
|
25
|
+
stateManagerRef.current = stateManager;
|
|
26
|
+
const handler = (e) => {
|
|
27
|
+
const newValue = e.detail;
|
|
28
|
+
valueRef.current = newValue;
|
|
29
|
+
setValueState(newValue);
|
|
30
|
+
};
|
|
31
|
+
stateManager.addEventListener("change", handler);
|
|
32
|
+
stateManager.start();
|
|
33
|
+
return () => {
|
|
34
|
+
stateManager.removeEventListener("change", handler);
|
|
35
|
+
stateManager.stop();
|
|
36
|
+
stateManagerRef.current = null;
|
|
37
|
+
};
|
|
38
|
+
}, [
|
|
39
|
+
key,
|
|
40
|
+
manager?.messenger,
|
|
41
|
+
options?.emit,
|
|
42
|
+
options?.receive
|
|
43
|
+
]);
|
|
44
|
+
const setValue = (valueOrUpdater) => {
|
|
45
|
+
setValueState((prev) => {
|
|
46
|
+
const newValue = typeof valueOrUpdater === "function" ? valueOrUpdater(prev) : valueOrUpdater;
|
|
47
|
+
valueRef.current = newValue;
|
|
48
|
+
stateManagerRef.current?.set(newValue);
|
|
49
|
+
return newValue;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const postState = () => {
|
|
53
|
+
stateManagerRef.current?.postCurrentValue();
|
|
54
|
+
};
|
|
55
|
+
return [
|
|
56
|
+
value,
|
|
57
|
+
setValue,
|
|
58
|
+
postState
|
|
59
|
+
];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
exports.useCrossFrameState = useCrossFrameState;
|
|
2
64
|
//# sourceMappingURL=useCrossFrameState.cjs.map
|
|
@@ -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,2 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
5
|
+
let _intlayer_editor = require("@intlayer/editor");
|
|
6
|
+
|
|
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
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.useCrossURLPathSetter = useCrossURLPathSetter;
|
|
18
|
+
exports.useCrossURLPathState = useCrossURLPathState;
|
|
2
19
|
//# 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":"
|
|
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,2 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_EditorStateContext = require('./EditorStateContext.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/useEditorLocale.tsx
|
|
8
|
+
const useEditorLocale = () => {
|
|
9
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
10
|
+
const [locale, setLocale] = (0, react.useState)(manager?.currentLocale.value);
|
|
11
|
+
(0, react.useEffect)(() => {
|
|
12
|
+
if (!manager) return;
|
|
13
|
+
const handler = (e) => setLocale(e.detail);
|
|
14
|
+
manager.currentLocale.addEventListener("change", handler);
|
|
15
|
+
return () => manager.currentLocale.removeEventListener("change", handler);
|
|
16
|
+
}, [manager]);
|
|
17
|
+
return locale;
|
|
18
|
+
};
|
|
19
|
+
const useSetEditorLocale = () => {
|
|
20
|
+
const manager = require_EditorStateContext.useEditorStateManager();
|
|
21
|
+
return (locale) => manager?.currentLocale.set(locale);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.useEditorLocale = useEditorLocale;
|
|
26
|
+
exports.useSetEditorLocale = useSetEditorLocale;
|
|
2
27
|
//# sourceMappingURL=useEditorLocale.cjs.map
|
|
@@ -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,2 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
|
|
5
|
+
const require_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
|
|
6
|
+
const require_useEditorLocale = require('./useEditorLocale.cjs');
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
9
|
+
|
|
10
|
+
//#region src/useFocusUnmergedDictionary.tsx
|
|
11
|
+
/**
|
|
12
|
+
* Converts merged keypath format to unmerged format.
|
|
13
|
+
* Merged: [{type: "translation", key: "fr"}, {type: "object", key: "title"}]
|
|
14
|
+
* Unmerged: [{type: "object", key: "title"}, {type: "translation", key: "fr"}]
|
|
15
|
+
*/
|
|
16
|
+
const mergedKeyPathToUnmergedKeyPath = (keyPath, dictionaries, locale) => {
|
|
17
|
+
for (const dictionary of dictionaries) try {
|
|
18
|
+
if ((0, _intlayer_core_dictionaryManipulator.getContentNodeByKeyPath)(dictionary.content, keyPath ?? [], locale)) return {
|
|
19
|
+
keyPath,
|
|
20
|
+
dictionaryLocalId: dictionary.localId
|
|
21
|
+
};
|
|
22
|
+
} catch {}
|
|
23
|
+
};
|
|
24
|
+
const useFocusUnmergedDictionary = () => {
|
|
25
|
+
const { localeDictionaries } = require_DictionariesRecordContext.useDictionariesRecord();
|
|
26
|
+
const currentLocale = require_useEditorLocale.useEditorLocale();
|
|
27
|
+
const { setFocusedContent, setFocusedContentKeyPath, focusedContent: mergedFocusedContent } = require_FocusDictionaryContext.useFocusDictionary();
|
|
28
|
+
return {
|
|
29
|
+
focusedContent: (0, react.useMemo)(() => {
|
|
30
|
+
if (!mergedFocusedContent) return mergedFocusedContent;
|
|
31
|
+
if (!localeDictionaries) return mergedFocusedContent;
|
|
32
|
+
if (mergedFocusedContent.dictionaryLocalId) return mergedFocusedContent;
|
|
33
|
+
const dictionaries = Object.values(localeDictionaries).filter((dictionary) => dictionary.key === mergedFocusedContent.dictionaryKey);
|
|
34
|
+
const unmergedKeyPath = mergedKeyPathToUnmergedKeyPath(mergedFocusedContent.keyPath ?? [], dictionaries, currentLocale);
|
|
35
|
+
return {
|
|
36
|
+
...mergedFocusedContent,
|
|
37
|
+
...unmergedKeyPath
|
|
38
|
+
};
|
|
39
|
+
}, [
|
|
40
|
+
mergedFocusedContent,
|
|
41
|
+
localeDictionaries,
|
|
42
|
+
currentLocale
|
|
43
|
+
]),
|
|
44
|
+
setFocusedContent,
|
|
45
|
+
setFocusedContentKeyPath
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.useFocusUnmergedDictionary = useFocusUnmergedDictionary;
|
|
2
51
|
//# sourceMappingURL=useFocusUnmergedDictionary.cjs.map
|
|
@@ -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,2 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
|
|
5
|
+
let _intlayer_editor = require("@intlayer/editor");
|
|
6
|
+
|
|
7
|
+
//#region src/useIframeClickInterceptor.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Broadcasts mousedown events from within an iframe to the parent frame.
|
|
10
|
+
* Called in the client application (inside the iframe).
|
|
11
|
+
* Note: EditorStateManager.start() already sets this up in client mode.
|
|
12
|
+
* This hook exists for explicit / standalone use cases.
|
|
13
|
+
*/
|
|
14
|
+
const useIframeClickInterceptor = () => {
|
|
15
|
+
require_useCrossFrameMessageListener.useCrossFrameMessageListener(_intlayer_editor.MessageKey.INTLAYER_IFRAME_CLICKED);
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Merges received iframe click events into the parent's DOM event stream.
|
|
19
|
+
* Called in the editor (parent frame).
|
|
20
|
+
*/
|
|
21
|
+
const useIframeClickMerger = () => {
|
|
22
|
+
require_useCrossFrameMessageListener.useCrossFrameMessageListener(_intlayer_editor.MessageKey.INTLAYER_IFRAME_CLICKED, _intlayer_editor.mergeIframeClick);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.useIframeClickInterceptor = useIframeClickInterceptor;
|
|
27
|
+
exports.useIframeClickMerger = useIframeClickMerger;
|
|
2
28
|
//# sourceMappingURL=useIframeClickInterceptor.cjs.map
|
|
@@ -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,2 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEditorStateManager } from "./EditorStateContext.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/CommunicatorContext.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Returns the communicator API backed by the shared EditorStateManager messenger.
|
|
8
|
+
*/
|
|
9
|
+
const useCommunicator = () => {
|
|
10
|
+
const manager = useEditorStateManager();
|
|
11
|
+
return {
|
|
12
|
+
postMessage: (payload) => manager?.messenger.send(payload.type, payload.data),
|
|
13
|
+
senderId: manager?.messenger.senderId ?? ""
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { useCommunicator };
|
|
2
19
|
//# sourceMappingURL=CommunicatorContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommunicatorContext.mjs","names":[],"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport type { MessagePayload } from '@intlayer/editor';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type UseCrossPlatformStateProps = {\n postMessage: (payload: MessagePayload) => void;\n allowedOrigins?: string[];\n senderId: string;\n};\n\n/**\n * Returns the communicator API backed by the shared EditorStateManager messenger.\n */\nexport const useCommunicator = (): UseCrossPlatformStateProps => {\n const manager = useEditorStateManager();\n\n return {\n postMessage: (payload: MessagePayload) =>\n manager?.messenger.send(payload.type, payload.data),\n senderId: manager?.messenger.senderId ?? '',\n };\n};\n\n// Re-export type for backward compatibility\nexport type { MessengerConfig } from '@intlayer/editor';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CommunicatorContext.mjs","names":[],"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport type { MessagePayload } from '@intlayer/editor';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type UseCrossPlatformStateProps = {\n postMessage: (payload: MessagePayload) => void;\n allowedOrigins?: string[];\n senderId: string;\n};\n\n/**\n * Returns the communicator API backed by the shared EditorStateManager messenger.\n */\nexport const useCommunicator = (): UseCrossPlatformStateProps => {\n const manager = useEditorStateManager();\n\n return {\n postMessage: (payload: MessagePayload) =>\n manager?.messenger.send(payload.type, payload.data),\n senderId: manager?.messenger.senderId ?? '',\n };\n};\n\n// Re-export type for backward compatibility\nexport type { MessengerConfig } from '@intlayer/editor';\n"],"mappings":";;;;;;;;AAcA,MAAa,wBAAoD;CAC/D,MAAM,UAAU,uBAAuB;AAEvC,QAAO;EACL,cAAc,YACZ,SAAS,UAAU,KAAK,QAAQ,MAAM,QAAQ,KAAK;EACrD,UAAU,SAAS,UAAU,YAAY;EAC1C"}
|
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEditorStateManager } from "./EditorStateContext.mjs";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/ConfigurationContext.tsx
|
|
7
|
+
const ConfigurationProvider = ({ configuration, children }) => {
|
|
8
|
+
const manager = useEditorStateManager();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!manager || !configuration) return;
|
|
11
|
+
manager.configuration.set(configuration);
|
|
12
|
+
}, [manager, configuration]);
|
|
13
|
+
return children;
|
|
14
|
+
};
|
|
15
|
+
const useConfiguration = () => {
|
|
16
|
+
const manager = useEditorStateManager();
|
|
17
|
+
const [config, setConfig] = useState(manager?.configuration.value);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!manager) return;
|
|
20
|
+
const handler = (e) => setConfig(e.detail);
|
|
21
|
+
manager.configuration.addEventListener("change", handler);
|
|
22
|
+
return () => manager.configuration.removeEventListener("change", handler);
|
|
23
|
+
}, [manager]);
|
|
24
|
+
return config;
|
|
25
|
+
};
|
|
26
|
+
const useConfigurationState = () => {
|
|
27
|
+
const manager = useEditorStateManager();
|
|
28
|
+
const [config, setConfig] = useState(manager?.configuration.value);
|
|
29
|
+
return [
|
|
30
|
+
config,
|
|
31
|
+
setConfig,
|
|
32
|
+
() => manager?.configuration.postCurrentValue()
|
|
33
|
+
];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { ConfigurationProvider, useConfiguration, useConfigurationState };
|
|
2
38
|
//# sourceMappingURL=ConfigurationContext.mjs.map
|
|
@@ -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 { type FC, type PropsWithChildren, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type ConfigurationProviderProps = PropsWithChildren<{\n configuration?: IntlayerConfig;\n}>;\n\nexport const ConfigurationProvider: FC<ConfigurationProviderProps> = ({\n configuration,\n children,\n}) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!manager || !configuration) return;\n\n manager.configuration.set(configuration);\n }, [manager, configuration]);\n\n return children;\n};\n\nexport const useConfiguration = (): IntlayerConfig | undefined => {\n const manager = useEditorStateManager();\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager?.configuration.value\n );\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setConfig((e as CustomEvent<IntlayerConfig>).detail);\n manager.configuration.addEventListener('change', handler);\n return () => manager.configuration.removeEventListener('change', handler);\n }, [manager]);\n\n return config;\n};\n\nexport const useConfigurationState = () => {\n const manager = useEditorStateManager();\n\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager?.configuration.value\n );\n\n return [\n config,\n setConfig,\n () => manager?.configuration.postCurrentValue(),\n ] as const;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.mjs","names":[],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FC, type PropsWithChildren, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type ConfigurationProviderProps = PropsWithChildren<{\n configuration?: IntlayerConfig;\n}>;\n\nexport const ConfigurationProvider: FC<ConfigurationProviderProps> = ({\n configuration,\n children,\n}) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!manager || !configuration) return;\n\n manager.configuration.set(configuration);\n }, [manager, configuration]);\n\n return children;\n};\n\nexport const useConfiguration = (): IntlayerConfig | undefined => {\n const manager = useEditorStateManager();\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager?.configuration.value\n );\n\n useEffect(() => {\n if (!manager) return;\n\n const handler = (e: Event) =>\n setConfig((e as CustomEvent<IntlayerConfig>).detail);\n manager.configuration.addEventListener('change', handler);\n return () => manager.configuration.removeEventListener('change', handler);\n }, [manager]);\n\n return config;\n};\n\nexport const useConfigurationState = () => {\n const manager = useEditorStateManager();\n\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager?.configuration.value\n );\n\n return [\n config,\n setConfig,\n () => manager?.configuration.postCurrentValue(),\n ] as const;\n};\n"],"mappings":";;;;;;AAUA,MAAa,yBAAyD,EACpE,eACA,eACI;CACJ,MAAM,UAAU,uBAAuB;AAEvC,iBAAgB;AACd,MAAI,CAAC,WAAW,CAAC,cAAe;AAEhC,UAAQ,cAAc,IAAI,cAAc;IACvC,CAAC,SAAS,cAAc,CAAC;AAE5B,QAAO;;AAGT,MAAa,yBAAqD;CAChE,MAAM,UAAU,uBAAuB;CACvC,MAAM,CAAC,QAAQ,aAAa,SAC1B,SAAS,cAAc,MACxB;AAED,iBAAgB;AACd,MAAI,CAAC,QAAS;EAEd,MAAM,WAAW,MACf,UAAW,EAAkC,OAAO;AACtD,UAAQ,cAAc,iBAAiB,UAAU,QAAQ;AACzD,eAAa,QAAQ,cAAc,oBAAoB,UAAU,QAAQ;IACxE,CAAC,QAAQ,CAAC;AAEb,QAAO;;AAGT,MAAa,8BAA8B;CACzC,MAAM,UAAU,uBAAuB;CAEvC,MAAM,CAAC,QAAQ,aAAa,SAC1B,SAAS,cAAc,MACxB;AAED,QAAO;EACL;EACA;QACM,SAAS,cAAc,kBAAkB;EAChD"}
|
|
@@ -1,2 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEditorStateManager } from "./EditorStateContext.mjs";
|
|
4
|
+
import { useCallback, useEffect, useState } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/DictionariesRecordContext.tsx
|
|
7
|
+
const useDictionariesRecord = () => {
|
|
8
|
+
const manager = useEditorStateManager();
|
|
9
|
+
const [localeDictionaries, setLocaleDictionariesState] = useState(manager?.localeDictionaries.value ?? {});
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!manager) return;
|
|
12
|
+
const handler = (e) => setLocaleDictionariesState(e.detail ?? {});
|
|
13
|
+
manager.localeDictionaries.addEventListener("change", handler);
|
|
14
|
+
return () => manager.localeDictionaries.removeEventListener("change", handler);
|
|
15
|
+
}, [manager]);
|
|
16
|
+
return {
|
|
17
|
+
localeDictionaries,
|
|
18
|
+
setLocaleDictionaries: useCallback((value) => manager?.localeDictionaries.set(value), [manager]),
|
|
19
|
+
setLocaleDictionary: useCallback((dictionary) => manager?.setLocaleDictionary(dictionary), [manager])
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const useDictionariesRecordActions = () => {
|
|
23
|
+
const { setLocaleDictionaries, setLocaleDictionary } = useDictionariesRecord();
|
|
24
|
+
return {
|
|
25
|
+
setLocaleDictionaries,
|
|
26
|
+
setLocaleDictionary
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { useDictionariesRecord, useDictionariesRecordActions };
|
|
2
32
|
//# sourceMappingURL=DictionariesRecordContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionariesRecordContext.mjs","names":[],"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.mjs","names":[],"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,UAAU,uBAAuB;CACvC,MAAM,CAAC,oBAAoB,8BACzB,SAA4B,SAAS,mBAAmB,SAAS,EAAE,CAAC;AAEtE,iBAAgB;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,uBAVC,aAC3B,UAA6B,SAAS,mBAAmB,IAAI,MAAM,EACpE,CAAC,QAAQ,CACV;EAOmD,qBALxB,aACzB,eAA2B,SAAS,oBAAoB,WAAW,EACpE,CAAC,QAAQ,CACV;EAEwE;;AAG3E,MAAa,qCACiC;CAC1C,MAAM,EAAE,uBAAuB,wBAC7B,uBAAuB;AACzB,QAAO;EAAE;EAAuB;EAAqB"}
|
|
@@ -1,2 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEditorStateManager } from "./EditorStateContext.mjs";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/EditedContentContext.tsx
|
|
7
|
+
const useEditedContentActions = () => {
|
|
8
|
+
const manager = useEditorStateManager();
|
|
9
|
+
return {
|
|
10
|
+
setEditedContentState: (value) => manager?.editedContent.set(value),
|
|
11
|
+
setEditedDictionary: (dict) => manager?.setEditedDictionary(dict),
|
|
12
|
+
setEditedContent: (localId, value) => manager?.setEditedContent(localId, value),
|
|
13
|
+
addEditedContent: (localId, value, keyPath, overwrite) => manager?.addContent(localId, value, keyPath, overwrite),
|
|
14
|
+
renameEditedContent: (localId, newKey, keyPath) => manager?.renameContent(localId, newKey, keyPath),
|
|
15
|
+
removeEditedContent: (localId, keyPath) => manager?.removeContent(localId, keyPath),
|
|
16
|
+
restoreEditedContent: (localId) => manager?.restoreContent(localId),
|
|
17
|
+
clearEditedDictionaryContent: (localId) => manager?.clearContent(localId),
|
|
18
|
+
clearEditedContent: () => manager?.clearAllContent(),
|
|
19
|
+
getEditedContentValue: (localIdOrKey, keyPath) => manager?.getContentValue(localIdOrKey, keyPath)
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const useEditedContent = () => {
|
|
23
|
+
const manager = useEditorStateManager();
|
|
24
|
+
const [editedContent, setEditedContentState] = useState(manager?.editedContent.value);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!manager) return;
|
|
27
|
+
const handler = (e) => setEditedContentState(e.detail);
|
|
28
|
+
manager.editedContent.addEventListener("change", handler);
|
|
29
|
+
return () => manager.editedContent.removeEventListener("change", handler);
|
|
30
|
+
}, [manager]);
|
|
31
|
+
return {
|
|
32
|
+
editedContent,
|
|
33
|
+
...useEditedContentActions()
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const usePostEditedContentState = (onEventTriggered) => {
|
|
37
|
+
const manager = useEditorStateManager();
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!onEventTriggered || !manager) return;
|
|
40
|
+
return manager.messenger.subscribe(`INTLAYER_EDITED_CONTENT_CHANGED/post`, onEventTriggered);
|
|
41
|
+
}, [manager, onEventTriggered]);
|
|
42
|
+
};
|
|
43
|
+
const useGetEditedContentState = () => {
|
|
44
|
+
const manager = useEditorStateManager();
|
|
45
|
+
return () => {
|
|
46
|
+
manager?.messenger.send("INTLAYER_EDITED_CONTENT_CHANGED/get");
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { useEditedContent, useEditedContentActions, useGetEditedContentState, usePostEditedContentState };
|
|
2
52
|
//# sourceMappingURL=EditedContentContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.mjs","names":[],"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.mjs","names":[],"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,UAAU,uBAAuB;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,UAAU,uBAAuB;CACvC,MAAM,CAAC,eAAe,yBAAyB,SAE7C,SAAS,cAAc,MAAM;AAE/B,iBAAgB;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,UAAU,uBAAuB;AACvC,iBAAgB;AACd,MAAI,CAAC,oBAAoB,CAAC,QAAS;AACnC,SAAO,QAAQ,UAAU,UACvB,wCACA,iBACD;IACA,CAAC,SAAS,iBAAiB,CAAC;;AAGjC,MAAa,iCAAiC;CAC5C,MAAM,UAAU,uBAAuB;AACvC,cAAa;AACX,WAAS,UAAU,KAAK,sCAAsC"}
|
|
@@ -1,2 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEditorStateManager } from "./EditorStateContext.mjs";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import { MessageKey } from "@intlayer/editor";
|
|
6
|
+
|
|
7
|
+
//#region src/EditorEnabledContext.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Returns the current editor-enabled state, kept in sync with the shared
|
|
10
|
+
* EditorStateManager. Replaces the old EditorEnabledContext + EditorEnabledProvider.
|
|
11
|
+
*/
|
|
12
|
+
const useEditorEnabled = () => {
|
|
13
|
+
const manager = useEditorStateManager();
|
|
14
|
+
const [enabled, setEnabled] = useState(manager?.editorEnabled.value ?? false);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!manager) return;
|
|
17
|
+
const handler = (e) => setEnabled(e.detail);
|
|
18
|
+
manager.editorEnabled.addEventListener("change", handler);
|
|
19
|
+
return () => manager.editorEnabled.removeEventListener("change", handler);
|
|
20
|
+
}, [manager]);
|
|
21
|
+
return { enabled };
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Subscribes to incoming "get" requests for editor-enabled state and calls
|
|
25
|
+
* the provided callback so the caller can respond.
|
|
26
|
+
* Used by the editor side to respond when the client asks for the current state.
|
|
27
|
+
*/
|
|
28
|
+
const useGetEditorEnabledState = (onRequest) => {
|
|
29
|
+
const manager = useEditorStateManager();
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!onRequest) return;
|
|
32
|
+
return manager?.messenger.subscribe(`${MessageKey.INTLAYER_EDITOR_ENABLED}/get`, onRequest);
|
|
33
|
+
}, [manager, onRequest]);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Returns a function that sets the editor-enabled state and broadcasts it.
|
|
37
|
+
*/
|
|
38
|
+
const usePostEditorEnabledState = () => {
|
|
39
|
+
const manager = useEditorStateManager();
|
|
40
|
+
return (value) => {
|
|
41
|
+
manager?.editorEnabled.set(value);
|
|
42
|
+
manager?.editorEnabled.postCurrentValue();
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const useEditorEnabledState = () => {
|
|
46
|
+
const { enabled } = useEditorEnabled();
|
|
47
|
+
const manager = useEditorStateManager();
|
|
48
|
+
const setter = (value) => manager?.editorEnabled.set(value);
|
|
49
|
+
return [enabled, setter];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Returns a function that re-pings the client via ARE_YOU_THERE.
|
|
53
|
+
* Use this as the onClick for an "Enable Editor" / reconnect button.
|
|
54
|
+
*/
|
|
55
|
+
const useEditorPingClient = () => {
|
|
56
|
+
const manager = useEditorStateManager();
|
|
57
|
+
return () => manager?.pingClient();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { useEditorEnabled, useEditorEnabledState, useEditorPingClient, useGetEditorEnabledState, usePostEditorEnabledState };
|
|
2
62
|
//# sourceMappingURL=EditorEnabledContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorEnabledContext.mjs","names":[],"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.mjs","names":[],"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,UAAU,uBAAuB;CACvC,MAAM,CAAC,SAAS,cAAc,SAC5B,SAAS,cAAc,SAAS,MACjC;AAED,iBAAgB;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,UAAU,uBAAuB;AAEvC,iBAAgB;AACd,MAAI,CAAC,UAAW;AAEhB,SAAO,SAAS,UAAU,UACxB,GAAG,WAAW,wBAAwB,OACtC,UACD;IACA,CAAC,SAAS,UAAU,CAAC;;;;;AAM1B,MAAa,kCAAkC;CAC7C,MAAM,UAAU,uBAAuB;AAEvC,SAAQ,UAAmB;AACzB,WAAS,cAAc,IAAI,MAAM;AACjC,WAAS,cAAc,kBAAkB;;;AAI7C,MAAa,8BAA8B;CACzC,MAAM,EAAE,YAAY,kBAAkB;CACtC,MAAM,UAAU,uBAAuB;CACvC,MAAM,UAAU,UAAmB,SAAS,cAAc,IAAI,MAAM;AAEpE,QAAO,CAAC,SAAS,OAAO;;;;;;AAO1B,MAAa,4BAA0C;CACrD,MAAM,UAAU,uBAAuB;AAEvC,cAAa,SAAS,YAAY"}
|