@intlayer/editor-react 8.4.3 → 8.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/cjs/CommunicatorContext.cjs +19 -1
  2. package/dist/cjs/CommunicatorContext.cjs.map +1 -1
  3. package/dist/cjs/ConfigurationContext.cjs +40 -1
  4. package/dist/cjs/ConfigurationContext.cjs.map +1 -1
  5. package/dist/cjs/DictionariesRecordContext.cjs +33 -1
  6. package/dist/cjs/DictionariesRecordContext.cjs.map +1 -1
  7. package/dist/cjs/EditedContentContext.cjs +55 -1
  8. package/dist/cjs/EditedContentContext.cjs.map +1 -1
  9. package/dist/cjs/EditorEnabledContext.cjs +66 -1
  10. package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
  11. package/dist/cjs/EditorProvider.cjs +41 -1
  12. package/dist/cjs/EditorProvider.cjs.map +1 -1
  13. package/dist/cjs/EditorStateContext.cjs +17 -1
  14. package/dist/cjs/EditorStateContext.cjs.map +1 -1
  15. package/dist/cjs/FocusDictionaryContext.cjs +36 -1
  16. package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
  17. package/dist/cjs/index.cjs +52 -1
  18. package/dist/cjs/useCrossFrameMessageListener.cjs +30 -1
  19. package/dist/cjs/useCrossFrameMessageListener.cjs.map +1 -1
  20. package/dist/cjs/useCrossFrameState.cjs +63 -1
  21. package/dist/cjs/useCrossFrameState.cjs.map +1 -1
  22. package/dist/cjs/useCrossURLPathState.cjs +18 -1
  23. package/dist/cjs/useCrossURLPathState.cjs.map +1 -1
  24. package/dist/cjs/useEditorLocale.cjs +26 -1
  25. package/dist/cjs/useEditorLocale.cjs.map +1 -1
  26. package/dist/cjs/useFocusUnmergedDictionary.cjs +50 -1
  27. package/dist/cjs/useFocusUnmergedDictionary.cjs.map +1 -1
  28. package/dist/cjs/useIframeClickInterceptor.cjs +27 -1
  29. package/dist/cjs/useIframeClickInterceptor.cjs.map +1 -1
  30. package/dist/esm/CommunicatorContext.mjs +18 -1
  31. package/dist/esm/CommunicatorContext.mjs.map +1 -1
  32. package/dist/esm/ConfigurationContext.mjs +37 -1
  33. package/dist/esm/ConfigurationContext.mjs.map +1 -1
  34. package/dist/esm/DictionariesRecordContext.mjs +31 -1
  35. package/dist/esm/DictionariesRecordContext.mjs.map +1 -1
  36. package/dist/esm/EditedContentContext.mjs +51 -1
  37. package/dist/esm/EditedContentContext.mjs.map +1 -1
  38. package/dist/esm/EditorEnabledContext.mjs +61 -1
  39. package/dist/esm/EditorEnabledContext.mjs.map +1 -1
  40. package/dist/esm/EditorProvider.mjs +40 -1
  41. package/dist/esm/EditorProvider.mjs.map +1 -1
  42. package/dist/esm/EditorStateContext.mjs +15 -1
  43. package/dist/esm/EditorStateContext.mjs.map +1 -1
  44. package/dist/esm/FocusDictionaryContext.mjs +34 -1
  45. package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
  46. package/dist/esm/index.mjs +17 -1
  47. package/dist/esm/useCrossFrameMessageListener.mjs +29 -1
  48. package/dist/esm/useCrossFrameMessageListener.mjs.map +1 -1
  49. package/dist/esm/useCrossFrameState.mjs +62 -1
  50. package/dist/esm/useCrossFrameState.mjs.map +1 -1
  51. package/dist/esm/useCrossURLPathState.mjs +16 -1
  52. package/dist/esm/useCrossURLPathState.mjs.map +1 -1
  53. package/dist/esm/useEditorLocale.mjs +24 -1
  54. package/dist/esm/useEditorLocale.mjs.map +1 -1
  55. package/dist/esm/useFocusUnmergedDictionary.mjs +49 -1
  56. package/dist/esm/useFocusUnmergedDictionary.mjs.map +1 -1
  57. package/dist/esm/useIframeClickInterceptor.mjs +25 -1
  58. package/dist/esm/useIframeClickInterceptor.mjs.map +1 -1
  59. package/package.json +6 -6
@@ -1,2 +1,64 @@
1
- "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./EditorStateContext.cjs`);let t=require(`react`),n=require(`@intlayer/editor`);const r=(r,i,a)=>{let o=e.useEditorStateManager(),s=typeof i==`function`?i():i,[c,l]=(0,t.useState)(s),u=(0,t.useRef)(s),d=(0,t.useRef)(null);return(0,t.useEffect)(()=>{let{emit:e=!0,receive:t=!0}=a??{},i=new n.CrossFrameStateManager(r,o?.messenger,{emit:e,receive:t,initialValue:s});d.current=i;let c=e=>{let t=e.detail;u.current=t,l(t)};return i.addEventListener(`change`,c),i.start(),()=>{i.removeEventListener(`change`,c),i.stop(),d.current=null}},[r,o?.messenger,a?.emit,a?.receive]),[c,e=>{l(t=>{let n=typeof e==`function`?e(t):e;return u.current=n,d.current?.set(n),n})},()=>{d.current?.postCurrentValue()}]};exports.useCrossFrameState=r;
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":"iLAqBA,MAAa,GACX,EACA,EACA,IACiD,CACjD,IAAM,EAAUA,EAAAA,uBAAuB,CAEjC,EACJ,OAAO,GAAiB,WACnB,GAA0B,CAC3B,EAEA,CAAC,EAAO,IAAA,EAAA,EAAA,UAA6B,EAAqB,CAC1D,GAAA,EAAA,EAAA,QAAqB,EAAqB,CAE1C,GAAA,EAAA,EAAA,QAA2D,KAAK,CA8CtE,OA5CA,EAAA,EAAA,eAAgB,CACd,GAAM,CAAE,OAAO,GAAM,UAAU,IAAS,GAAW,EAAE,CAC/C,EAAe,IAAIC,EAAAA,uBACvB,EACA,GAAS,UACT,CACE,OACA,UACA,aAAc,EACf,CACF,CACD,EAAgB,QAAU,EAE1B,IAAM,EAAW,GAAa,CAC5B,IAAM,EAAY,EAAqB,OACvC,EAAS,QAAU,EACnB,EAAc,EAAS,EAKzB,OAHA,EAAa,iBAAiB,SAAU,EAAQ,CAChD,EAAa,OAAO,KAEP,CACX,EAAa,oBAAoB,SAAU,EAAQ,CACnD,EAAa,MAAM,CACnB,EAAgB,QAAU,OAE3B,CAAC,EAAK,GAAS,UAAW,GAAS,KAAM,GAAS,QAAQ,CAAC,CAkBvD,CAAC,EAhBuC,GAAmB,CAChE,EAAe,GAAS,CACtB,IAAM,EACJ,OAAO,GAAmB,WACrB,EAAkC,EAAK,CACxC,EAGN,MAFA,GAAS,QAAU,EACnB,EAAgB,SAAS,IAAI,EAAS,CAC/B,GACP,MAGoB,CACtB,EAAgB,SAAS,kBAAkB,EAGV"}
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
- "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useCrossFrameState.cjs`);let t=require(`@intlayer/editor`);const n=(n,r)=>e.useCrossFrameState(t.MessageKey.INTLAYER_URL_CHANGE,n,r),r=e=>n(e,{emit:!0,receive:!1});exports.useCrossURLPathSetter=r,exports.useCrossURLPathState=n;
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":"8JAQA,MAAa,GACX,EACA,IACGA,EAAAA,mBAAmBC,EAAAA,WAAW,oBAAqB,EAAc,EAAQ,CAEjE,EAAyB,GAG7B,EAAqB,EAAc,CAAE,KAAM,GAAM,QAAS,GAAO,CAAC"}
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
- "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./EditorStateContext.cjs`);let t=require(`react`);const n=()=>{let n=e.useEditorStateManager(),[r,i]=(0,t.useState)(n?.currentLocale.value);return(0,t.useEffect)(()=>{if(!n)return;let e=e=>i(e.detail);return n.currentLocale.addEventListener(`change`,e),()=>n.currentLocale.removeEventListener(`change`,e)},[n]),r},r=()=>{let t=e.useEditorStateManager();return e=>t?.currentLocale.set(e)};exports.useEditorLocale=n,exports.useSetEditorLocale=r;
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":"mJAMA,MAAa,MAA4C,CACvD,IAAM,EAAUA,EAAAA,uBAAuB,CACjC,CAAC,EAAQ,IAAA,EAAA,EAAA,UACb,GAAS,cAAc,MACxB,CAWD,OATA,EAAA,EAAA,eAAgB,CACd,GAAI,CAAC,EAAS,OAEd,IAAM,EAAW,GAAa,EAAW,EAA0B,OAAO,CAG1E,OAFA,EAAQ,cAAc,iBAAiB,SAAU,EAAQ,KAE5C,EAAQ,cAAc,oBAAoB,SAAU,EAAQ,EACxE,CAAC,EAAQ,CAAC,CAEN,GAGI,MAA2B,CACtC,IAAM,EAAUA,EAAAA,uBAAuB,CACvC,MAAQ,IAAmB,GAAS,cAAc,IAAI,EAAO"}
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
- "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./FocusDictionaryContext.cjs`),t=require(`./DictionariesRecordContext.cjs`),n=require(`./useEditorLocale.cjs`);let r=require(`react`),i=require(`@intlayer/core/dictionaryManipulator`);const a=(e,t,n)=>{for(let r of t)try{if((0,i.getContentNodeByKeyPath)(r.content,e??[],n))return{keyPath:e,dictionaryLocalId:r.localId}}catch{}},o=()=>{let{localeDictionaries:i}=t.useDictionariesRecord(),o=n.useEditorLocale(),{setFocusedContent:s,setFocusedContentKeyPath:c,focusedContent:l}=e.useFocusDictionary();return{focusedContent:(0,r.useMemo)(()=>{if(!l||!i||l.dictionaryLocalId)return l;let e=Object.values(i).filter(e=>e.key===l.dictionaryKey),t=a(l.keyPath??[],e,o);return{...l,...t}},[l,i,o]),setFocusedContent:s,setFocusedContentKeyPath:c}};exports.useFocusUnmergedDictionary=o;
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":"yRAqBA,MAAM,GACJ,EACA,EACA,IACgC,CAIhC,IAAK,IAAM,KAAc,EACvB,GAAI,CAOF,IAAA,EAAA,EAAA,yBALE,EAAW,QACX,GAAW,EAAE,CACb,EACD,CAGC,MAAO,CAAE,UAAS,kBAAmB,EAAW,QAAS,MAErD,IAMC,MAAmC,CAC9C,GAAM,CAAE,sBAAuBA,EAAAA,uBAAuB,CAChD,EAAgBC,EAAAA,iBAAiB,CACjC,CACJ,oBACA,2BACA,eAAgB,GACdC,EAAAA,oBAAoB,CAuBxB,MAAO,CACL,gBAAA,EAAA,EAAA,aAtBuD,CAGvD,GAFI,CAAC,GACD,CAAC,GACD,EAAqB,kBAAmB,OAAO,EAEnD,IAAM,EAAe,OAAO,OAAO,EAAmB,CAAC,OACpD,GAAe,EAAW,MAAQ,EAAqB,cACzD,CAEK,EAAkB,EACtB,EAAqB,SAAW,EAAE,CAClC,EACA,EACD,CAED,MAAO,CACL,GAAG,EACH,GAAG,EACJ,EACA,CAAC,EAAsB,EAAoB,EAAc,CAAC,CAI3D,oBACA,2BACD"}
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
- "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useCrossFrameMessageListener.cjs`);let t=require(`@intlayer/editor`);const n=()=>{e.useCrossFrameMessageListener(t.MessageKey.INTLAYER_IFRAME_CLICKED)},r=()=>{e.useCrossFrameMessageListener(t.MessageKey.INTLAYER_IFRAME_CLICKED,t.mergeIframeClick)};exports.useIframeClickInterceptor=n,exports.useIframeClickMerger=r;
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":"wKAWA,MAAa,MAAkC,CAC7C,EAAA,6BAAwCA,EAAAA,WAAW,wBAAwB,EAOhE,MAA6B,CACxC,EAAA,6BACEA,EAAAA,WAAW,wBACXC,EAAAA,iBACD"}
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
- "use client";import{useEditorStateManager as e}from"./EditorStateContext.mjs";const t=()=>{let t=e();return{postMessage:e=>t?.messenger.send(e.type,e.data),senderId:t?.messenger.senderId??``}};export{t as useCommunicator};
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":"8EAcA,MAAa,MAAoD,CAC/D,IAAM,EAAU,GAAuB,CAEvC,MAAO,CACL,YAAc,GACZ,GAAS,UAAU,KAAK,EAAQ,KAAM,EAAQ,KAAK,CACrD,SAAU,GAAS,UAAU,UAAY,GAC1C"}
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
- "use client";import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEffect as t,useState as n}from"react";const r=({configuration:n,children:r})=>{let i=e();return t(()=>{!i||!n||i.configuration.set(n)},[i,n]),r},i=()=>{let r=e(),[i,a]=n(r?.configuration.value);return t(()=>{if(!r)return;let e=e=>a(e.detail);return r.configuration.addEventListener(`change`,e),()=>r.configuration.removeEventListener(`change`,e)},[r]),i},a=()=>{let t=e(),[r,i]=n(t?.configuration.value);return[r,i,()=>t?.configuration.postCurrentValue()]};export{r as ConfigurationProvider,i as useConfiguration,a as useConfigurationState};
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":"8HAUA,MAAa,GAAyD,CACpE,gBACA,cACI,CACJ,IAAM,EAAU,GAAuB,CAQvC,OANA,MAAgB,CACV,CAAC,GAAW,CAAC,GAEjB,EAAQ,cAAc,IAAI,EAAc,EACvC,CAAC,EAAS,EAAc,CAAC,CAErB,GAGI,MAAqD,CAChE,IAAM,EAAU,GAAuB,CACjC,CAAC,EAAQ,GAAa,EAC1B,GAAS,cAAc,MACxB,CAWD,OATA,MAAgB,CACd,GAAI,CAAC,EAAS,OAEd,IAAM,EAAW,GACf,EAAW,EAAkC,OAAO,CAEtD,OADA,EAAQ,cAAc,iBAAiB,SAAU,EAAQ,KAC5C,EAAQ,cAAc,oBAAoB,SAAU,EAAQ,EACxE,CAAC,EAAQ,CAAC,CAEN,GAGI,MAA8B,CACzC,IAAM,EAAU,GAAuB,CAEjC,CAAC,EAAQ,GAAa,EAC1B,GAAS,cAAc,MACxB,CAED,MAAO,CACL,EACA,MACM,GAAS,cAAc,kBAAkB,CAChD"}
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
- "use client";import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useCallback as t,useEffect as n,useState as r}from"react";const i=()=>{let i=e(),[a,o]=r(i?.localeDictionaries.value??{});return n(()=>{if(!i)return;let e=e=>o(e.detail??{});return i.localeDictionaries.addEventListener(`change`,e),()=>i.localeDictionaries.removeEventListener(`change`,e)},[i]),{localeDictionaries:a,setLocaleDictionaries:t(e=>i?.localeDictionaries.set(e),[i]),setLocaleDictionary:t(e=>i?.setLocaleDictionary(e),[i])}},a=()=>{let{setLocaleDictionaries:e,setLocaleDictionary:t}=i();return{setLocaleDictionaries:e,setLocaleDictionary:t}};export{i as useDictionariesRecord,a as useDictionariesRecordActions};
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":"+IAiBA,MAAa,MAC6B,CACxC,IAAM,EAAU,GAAuB,CACjC,CAAC,EAAoB,GACzB,EAA4B,GAAS,mBAAmB,OAAS,EAAE,CAAC,CA0BtE,OAxBA,MAAgB,CACd,GAAI,CAAC,EAAS,OAEd,IAAM,EAAW,GACf,EACG,EAAqC,QAAU,EAAE,CACnD,CAIH,OAFA,EAAQ,mBAAmB,iBAAiB,SAAU,EAAQ,KAG5D,EAAQ,mBAAmB,oBAAoB,SAAU,EAAQ,EAClE,CAAC,EAAQ,CAAC,CAYN,CAAE,qBAAoB,sBAVC,EAC3B,GAA6B,GAAS,mBAAmB,IAAI,EAAM,CACpE,CAAC,EAAQ,CACV,CAOmD,oBALxB,EACzB,GAA2B,GAAS,oBAAoB,EAAW,CACpE,CAAC,EAAQ,CACV,CAEwE,EAG9D,MACiC,CAC1C,GAAM,CAAE,wBAAuB,uBAC7B,GAAuB,CACzB,MAAO,CAAE,wBAAuB,sBAAqB"}
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
- "use client";import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEffect as t,useState as n}from"react";const r=()=>{let t=e();return{setEditedContentState:e=>t?.editedContent.set(e),setEditedDictionary:e=>t?.setEditedDictionary(e),setEditedContent:(e,n)=>t?.setEditedContent(e,n),addEditedContent:(e,n,r,i)=>t?.addContent(e,n,r,i),renameEditedContent:(e,n,r)=>t?.renameContent(e,n,r),removeEditedContent:(e,n)=>t?.removeContent(e,n),restoreEditedContent:e=>t?.restoreContent(e),clearEditedDictionaryContent:e=>t?.clearContent(e),clearEditedContent:()=>t?.clearAllContent(),getEditedContentValue:(e,n)=>t?.getContentValue(e,n)}},i=()=>{let i=e(),[a,o]=n(i?.editedContent.value);return t(()=>{if(!i)return;let e=e=>o(e.detail);return i.editedContent.addEventListener(`change`,e),()=>i.editedContent.removeEventListener(`change`,e)},[i]),{editedContent:a,...r()}},a=n=>{let r=e();t(()=>{if(!(!n||!r))return r.messenger.subscribe(`INTLAYER_EDITED_CONTENT_CHANGED/post`,n)},[r,n])},o=()=>{let t=e();return()=>{t?.messenger.send(`INTLAYER_EDITED_CONTENT_CHANGED/get`)}};export{i as useEditedContent,r as useEditedContentActions,o as useGetEditedContentState,a as usePostEditedContentState};
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":"8HA6CA,MAAa,MAAiE,CAC5E,IAAM,EAAU,GAAuB,CAEvC,MAAO,CACL,sBAAwB,GACtB,GAAS,cAAc,IAAI,EAAM,CACnC,oBAAsB,GACpB,GAAS,oBAAoB,EAAK,CACpC,kBACE,EACA,IACG,GAAS,iBAAiB,EAAS,EAAM,CAC9C,kBAAmB,EAAS,EAAO,EAAS,IAC1C,GAAS,WAAW,EAAS,EAAO,EAAS,EAAU,CACzD,qBAAsB,EAAS,EAAQ,IACrC,GAAS,cAAc,EAAS,EAAQ,EAAQ,CAClD,qBAAsB,EAAS,IAC7B,GAAS,cAAc,EAAS,EAAQ,CAC1C,qBAAuB,GAAY,GAAS,eAAe,EAAQ,CACnE,6BAA+B,GAAY,GAAS,aAAa,EAAQ,CACzE,uBAA0B,GAAS,iBAAiB,CACpD,uBAAwB,EAAc,IACpC,GAAS,gBAAgB,EAAc,EAAQ,CAClD,EAGU,MAAyB,CACpC,IAAM,EAAU,GAAuB,CACjC,CAAC,EAAe,GAAyB,EAE7C,GAAS,cAAc,MAAM,CAW/B,OATA,MAAgB,CACd,GAAI,CAAC,EAAS,OACd,IAAM,EAAW,GACf,EAAuB,EAAqC,OAAO,CAErE,OADA,EAAQ,cAAc,iBAAiB,SAAU,EAAQ,KAC5C,EAAQ,cAAc,oBAAoB,SAAU,EAAQ,EACxE,CAAC,EAAQ,CAAC,CAGN,CAAE,gBAAe,GADR,GAAyB,CACL,EAGzB,EACX,GACG,CACH,IAAM,EAAU,GAAuB,CACvC,MAAgB,CACV,MAAC,GAAoB,CAAC,GAC1B,OAAO,EAAQ,UAAU,UACvB,uCACA,EACD,EACA,CAAC,EAAS,EAAiB,CAAC,EAGpB,MAAiC,CAC5C,IAAM,EAAU,GAAuB,CACvC,UAAa,CACX,GAAS,UAAU,KAAK,sCAAsC"}
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
- "use client";import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEffect as t,useState as n}from"react";import{MessageKey as r}from"@intlayer/editor";const i=()=>{let r=e(),[i,a]=n(r?.editorEnabled.value??!1);return t(()=>{if(!r)return;let e=e=>a(e.detail);return r.editorEnabled.addEventListener(`change`,e),()=>r.editorEnabled.removeEventListener(`change`,e)},[r]),{enabled:i}},a=n=>{let i=e();t(()=>{if(n)return i?.messenger.subscribe(`${r.INTLAYER_EDITOR_ENABLED}/get`,n)},[i,n])},o=()=>{let t=e();return e=>{t?.editorEnabled.set(e),t?.editorEnabled.postCurrentValue()}},s=()=>{let{enabled:t}=i(),n=e();return[t,e=>n?.editorEnabled.set(e)]},c=()=>{let t=e();return()=>t?.pingClient()};export{i as useEditorEnabled,s as useEditorEnabledState,c as useEditorPingClient,a as useGetEditorEnabledState,o as usePostEditorEnabledState};
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":"4KAcA,MAAa,MAAkD,CAC7D,IAAM,EAAU,GAAuB,CACjC,CAAC,EAAS,GAAc,EAC5B,GAAS,cAAc,OAAS,GACjC,CAWD,OATA,MAAgB,CACd,GAAI,CAAC,EAAS,OAEd,IAAM,EAAW,GACf,EAAY,EAA2B,OAAO,CAEhD,OADA,EAAQ,cAAc,iBAAiB,SAAU,EAAQ,KAC5C,EAAQ,cAAc,oBAAoB,SAAU,EAAQ,EACxE,CAAC,EAAQ,CAAC,CAEN,CAAE,UAAS,EAQP,EAA4B,GAA2B,CAClE,IAAM,EAAU,GAAuB,CAEvC,MAAgB,CACT,KAEL,OAAO,GAAS,UAAU,UACxB,GAAG,EAAW,wBAAwB,MACtC,EACD,EACA,CAAC,EAAS,EAAU,CAAC,EAMb,MAAkC,CAC7C,IAAM,EAAU,GAAuB,CAEvC,MAAQ,IAAmB,CACzB,GAAS,cAAc,IAAI,EAAM,CACjC,GAAS,cAAc,kBAAkB,GAIhC,MAA8B,CACzC,GAAM,CAAE,WAAY,GAAkB,CAChC,EAAU,GAAuB,CAGvC,MAAO,CAAC,EAFQ,GAAmB,GAAS,cAAc,IAAI,EAAM,CAE5C,EAOb,MAA0C,CACrD,IAAM,EAAU,GAAuB,CAEvC,UAAa,GAAS,YAAY"}
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"}