preact-intlayer 5.5.4 → 5.5.6

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 (253) hide show
  1. package/dist/cjs/IntlayerNode.cjs +47 -0
  2. package/dist/cjs/IntlayerNode.cjs.map +1 -0
  3. package/dist/cjs/UI/ContentSelector.cjs +127 -0
  4. package/dist/cjs/UI/ContentSelector.cjs.map +1 -0
  5. package/dist/cjs/client/IntlayerProvider.cjs +98 -0
  6. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
  7. package/dist/cjs/client/getBrowserLocale.cjs +173 -0
  8. package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
  9. package/dist/cjs/client/index.cjs +69 -0
  10. package/dist/cjs/client/index.cjs.map +1 -0
  11. package/dist/cjs/client/t.cjs +37 -0
  12. package/dist/cjs/client/t.cjs.map +1 -0
  13. package/dist/cjs/client/useContent.cjs +39 -0
  14. package/dist/cjs/client/useContent.cjs.map +1 -0
  15. package/dist/cjs/client/useDictionary.cjs +42 -0
  16. package/dist/cjs/client/useDictionary.cjs.map +1 -0
  17. package/dist/cjs/client/useDictionaryDynamic.cjs +42 -0
  18. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -0
  19. package/dist/cjs/client/useIntlayer.cjs +43 -0
  20. package/dist/cjs/client/useIntlayer.cjs.map +1 -0
  21. package/dist/cjs/client/useIntlayerAsync.cjs +54 -0
  22. package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -0
  23. package/dist/cjs/client/useLoadDynamic.cjs +56 -0
  24. package/dist/cjs/client/useLoadDynamic.cjs.map +1 -0
  25. package/dist/cjs/client/useLocale.cjs +69 -0
  26. package/dist/cjs/client/useLocale.cjs.map +1 -0
  27. package/dist/cjs/client/useLocaleBase.cjs +56 -0
  28. package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
  29. package/dist/cjs/client/useLocaleCookie.cjs +60 -0
  30. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -0
  31. package/dist/cjs/client/useTraduction.cjs +35 -0
  32. package/dist/cjs/client/useTraduction.cjs.map +1 -0
  33. package/dist/cjs/editor/ChangedContentContext.cjs +77 -0
  34. package/dist/cjs/editor/ChangedContentContext.cjs.map +1 -0
  35. package/dist/cjs/editor/CommunicatorContext.cjs +66 -0
  36. package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -0
  37. package/dist/cjs/editor/ConfigurationContext.cjs +50 -0
  38. package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -0
  39. package/dist/cjs/editor/ContentSelectorWrapper.cjs +66 -0
  40. package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -0
  41. package/dist/cjs/editor/DictionariesRecordContext.cjs +77 -0
  42. package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -0
  43. package/dist/cjs/editor/EditedContentContext.cjs +217 -0
  44. package/dist/cjs/editor/EditedContentContext.cjs.map +1 -0
  45. package/dist/cjs/editor/EditorEnabledContext.cjs +62 -0
  46. package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -0
  47. package/dist/cjs/editor/EditorProvider.cjs +72 -0
  48. package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
  49. package/dist/cjs/editor/FocusDictionaryContext.cjs +81 -0
  50. package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -0
  51. package/dist/cjs/editor/IntlayerEditorProvider.cjs +122 -0
  52. package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -0
  53. package/dist/cjs/editor/index.cjs +23 -0
  54. package/dist/cjs/editor/index.cjs.map +1 -0
  55. package/dist/cjs/editor/useCrossFrameMessageListener.cjs +53 -0
  56. package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -0
  57. package/dist/cjs/editor/useCrossFrameState.cjs +77 -0
  58. package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -0
  59. package/dist/cjs/editor/useCrossURLPathState.cjs +69 -0
  60. package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -0
  61. package/dist/cjs/editor/useEditedContentRenderer.cjs +63 -0
  62. package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -0
  63. package/dist/cjs/editor/useIframeClickInterceptor.cjs +50 -0
  64. package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -0
  65. package/dist/cjs/getDictionary.cjs +43 -0
  66. package/dist/cjs/getDictionary.cjs.map +1 -0
  67. package/dist/cjs/getIntlayer.cjs +39 -0
  68. package/dist/cjs/getIntlayer.cjs.map +1 -0
  69. package/dist/cjs/index.cjs +42 -5
  70. package/dist/cjs/index.cjs.map +1 -1
  71. package/dist/cjs/markdown/MarkdownProvider.cjs +41 -0
  72. package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -0
  73. package/dist/cjs/markdown/MarkdownRenderer.cjs +83 -0
  74. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
  75. package/dist/cjs/markdown/index.cjs +25 -0
  76. package/dist/cjs/markdown/index.cjs.map +1 -0
  77. package/dist/cjs/plugins.cjs +128 -0
  78. package/dist/cjs/plugins.cjs.map +1 -0
  79. package/dist/cjs/preactElement/renderPreactElement.cjs +62 -0
  80. package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -0
  81. package/dist/esm/IntlayerNode.mjs +27 -0
  82. package/dist/esm/IntlayerNode.mjs.map +1 -0
  83. package/dist/esm/UI/ContentSelector.mjs +103 -0
  84. package/dist/esm/UI/ContentSelector.mjs.map +1 -0
  85. package/dist/esm/client/IntlayerProvider.mjs +63 -0
  86. package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
  87. package/dist/esm/client/getBrowserLocale.mjs +138 -0
  88. package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
  89. package/dist/esm/client/index.mjs +39 -0
  90. package/dist/esm/client/index.mjs.map +1 -0
  91. package/dist/esm/client/t.mjs +13 -0
  92. package/dist/esm/client/t.mjs.map +1 -0
  93. package/dist/esm/client/useContent.mjs +15 -0
  94. package/dist/esm/client/useContent.mjs.map +1 -0
  95. package/dist/esm/client/useDictionary.mjs +18 -0
  96. package/dist/esm/client/useDictionary.mjs.map +1 -0
  97. package/dist/esm/client/useDictionaryDynamic.mjs +18 -0
  98. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -0
  99. package/dist/esm/client/useIntlayer.mjs +19 -0
  100. package/dist/esm/client/useIntlayer.mjs.map +1 -0
  101. package/dist/esm/client/useIntlayerAsync.mjs +33 -0
  102. package/dist/esm/client/useIntlayerAsync.mjs.map +1 -0
  103. package/dist/esm/client/useLoadDynamic.mjs +32 -0
  104. package/dist/esm/client/useLoadDynamic.mjs.map +1 -0
  105. package/dist/esm/client/useLocale.mjs +35 -0
  106. package/dist/esm/client/useLocale.mjs.map +1 -0
  107. package/dist/esm/client/useLocaleBase.mjs +22 -0
  108. package/dist/esm/client/useLocaleBase.mjs.map +1 -0
  109. package/dist/esm/client/useLocaleCookie.mjs +24 -0
  110. package/dist/esm/client/useLocaleCookie.mjs.map +1 -0
  111. package/dist/esm/client/useTraduction.mjs +11 -0
  112. package/dist/esm/client/useTraduction.mjs.map +1 -0
  113. package/dist/esm/editor/ChangedContentContext.mjs +55 -0
  114. package/dist/esm/editor/ChangedContentContext.mjs.map +1 -0
  115. package/dist/esm/editor/CommunicatorContext.mjs +33 -0
  116. package/dist/esm/editor/CommunicatorContext.mjs.map +1 -0
  117. package/dist/esm/editor/ConfigurationContext.mjs +27 -0
  118. package/dist/esm/editor/ConfigurationContext.mjs.map +1 -0
  119. package/dist/esm/editor/ContentSelectorWrapper.mjs +45 -0
  120. package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -0
  121. package/dist/esm/editor/DictionariesRecordContext.mjs +55 -0
  122. package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -0
  123. package/dist/esm/editor/EditedContentContext.mjs +198 -0
  124. package/dist/esm/editor/EditedContentContext.mjs.map +1 -0
  125. package/dist/esm/editor/EditorEnabledContext.mjs +39 -0
  126. package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -0
  127. package/dist/esm/editor/EditorProvider.mjs +62 -0
  128. package/dist/esm/editor/EditorProvider.mjs.map +1 -0
  129. package/dist/esm/editor/FocusDictionaryContext.mjs +58 -0
  130. package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -0
  131. package/dist/esm/editor/IntlayerEditorProvider.mjs +88 -0
  132. package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -0
  133. package/dist/esm/editor/index.mjs +2 -0
  134. package/dist/esm/editor/index.mjs.map +1 -0
  135. package/dist/esm/editor/useCrossFrameMessageListener.mjs +29 -0
  136. package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -0
  137. package/dist/esm/editor/useCrossFrameState.mjs +53 -0
  138. package/dist/esm/editor/useCrossFrameState.mjs.map +1 -0
  139. package/dist/esm/editor/useCrossURLPathState.mjs +46 -0
  140. package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -0
  141. package/dist/esm/editor/useEditedContentRenderer.mjs +38 -0
  142. package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -0
  143. package/dist/esm/editor/useIframeClickInterceptor.mjs +25 -0
  144. package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -0
  145. package/dist/esm/getDictionary.mjs +25 -0
  146. package/dist/esm/getDictionary.mjs.map +1 -0
  147. package/dist/esm/getIntlayer.mjs +21 -0
  148. package/dist/esm/getIntlayer.mjs.map +1 -0
  149. package/dist/esm/index.mjs +38 -2
  150. package/dist/esm/index.mjs.map +1 -1
  151. package/dist/esm/markdown/MarkdownProvider.mjs +19 -0
  152. package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -0
  153. package/dist/esm/markdown/MarkdownRenderer.mjs +62 -0
  154. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
  155. package/dist/esm/markdown/index.mjs +3 -0
  156. package/dist/esm/markdown/index.mjs.map +1 -0
  157. package/dist/esm/plugins.mjs +104 -0
  158. package/dist/esm/plugins.mjs.map +1 -0
  159. package/dist/esm/preactElement/renderPreactElement.mjs +38 -0
  160. package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -0
  161. package/dist/types/IntlayerNode.d.ts +15 -0
  162. package/dist/types/IntlayerNode.d.ts.map +1 -0
  163. package/dist/types/UI/ContentSelector.d.ts +10 -0
  164. package/dist/types/UI/ContentSelector.d.ts.map +1 -0
  165. package/dist/types/client/IntlayerProvider.d.ts +29 -0
  166. package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
  167. package/dist/types/client/getBrowserLocale.d.ts +25 -0
  168. package/dist/types/client/getBrowserLocale.d.ts.map +1 -0
  169. package/dist/types/client/index.d.ts +12 -0
  170. package/dist/types/client/index.d.ts.map +1 -0
  171. package/dist/types/client/t.d.ts +9 -0
  172. package/dist/types/client/t.d.ts.map +1 -0
  173. package/dist/types/client/useContent.d.ts +10 -0
  174. package/dist/types/client/useContent.d.ts.map +1 -0
  175. package/dist/types/client/useDictionary.d.ts +9 -0
  176. package/dist/types/client/useDictionary.d.ts.map +1 -0
  177. package/dist/types/client/useDictionaryDynamic.d.ts +9 -0
  178. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
  179. package/dist/types/client/useIntlayer.d.ts +11 -0
  180. package/dist/types/client/useIntlayer.d.ts.map +1 -0
  181. package/dist/types/client/useIntlayerAsync.d.ts +14 -0
  182. package/dist/types/client/useIntlayerAsync.d.ts.map +1 -0
  183. package/dist/types/client/useLoadDynamic.d.ts +2 -0
  184. package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
  185. package/dist/types/client/useLocale.d.ts +15 -0
  186. package/dist/types/client/useLocale.d.ts.map +1 -0
  187. package/dist/types/client/useLocaleBase.d.ts +10 -0
  188. package/dist/types/client/useLocaleBase.d.ts.map +1 -0
  189. package/dist/types/client/useLocaleCookie.d.ts +17 -0
  190. package/dist/types/client/useLocaleCookie.d.ts.map +1 -0
  191. package/dist/types/client/useTraduction.d.ts +24 -0
  192. package/dist/types/client/useTraduction.d.ts.map +1 -0
  193. package/dist/types/editor/ChangedContentContext.d.ts +13 -0
  194. package/dist/types/editor/ChangedContentContext.d.ts.map +1 -0
  195. package/dist/types/editor/CommunicatorContext.d.ts +14 -0
  196. package/dist/types/editor/CommunicatorContext.d.ts.map +1 -0
  197. package/dist/types/editor/ConfigurationContext.d.ts +9 -0
  198. package/dist/types/editor/ConfigurationContext.d.ts.map +1 -0
  199. package/dist/types/editor/ContentSelectorWrapper.d.ts +5 -0
  200. package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -0
  201. package/dist/types/editor/DictionariesRecordContext.d.ts +16 -0
  202. package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -0
  203. package/dist/types/editor/EditedContentContext.d.ts +33 -0
  204. package/dist/types/editor/EditedContentContext.d.ts.map +1 -0
  205. package/dist/types/editor/EditorEnabledContext.d.ts +11 -0
  206. package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -0
  207. package/dist/types/editor/EditorProvider.d.ts +6 -0
  208. package/dist/types/editor/EditorProvider.d.ts.map +1 -0
  209. package/dist/types/editor/FocusDictionaryContext.d.ts +21 -0
  210. package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -0
  211. package/dist/types/editor/IntlayerEditorProvider.d.ts +5 -0
  212. package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -0
  213. package/dist/types/editor/index.d.ts +2 -0
  214. package/dist/types/editor/index.d.ts.map +1 -0
  215. package/dist/types/editor/useCrossFrameMessageListener.d.ts +19 -0
  216. package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -0
  217. package/dist/types/editor/useCrossFrameState.d.ts +30 -0
  218. package/dist/types/editor/useCrossFrameState.d.ts.map +1 -0
  219. package/dist/types/editor/useCrossURLPathState.d.ts +4 -0
  220. package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -0
  221. package/dist/types/editor/useEditedContentRenderer.d.ts +13 -0
  222. package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -0
  223. package/dist/types/editor/useIframeClickInterceptor.d.ts +3 -0
  224. package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -0
  225. package/dist/types/getDictionary.d.ts +5 -0
  226. package/dist/types/getDictionary.d.ts.map +1 -0
  227. package/dist/types/getIntlayer.d.ts +5 -0
  228. package/dist/types/getIntlayer.d.ts.map +1 -0
  229. package/dist/types/index.d.ts +8 -2
  230. package/dist/types/index.d.ts.map +1 -1
  231. package/dist/types/markdown/MarkdownProvider.d.ts +9 -0
  232. package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
  233. package/dist/types/markdown/MarkdownRenderer.d.ts +16 -0
  234. package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
  235. package/dist/types/markdown/index.d.ts +3 -0
  236. package/dist/types/markdown/index.d.ts.map +1 -0
  237. package/dist/types/plugins.d.ts +54 -0
  238. package/dist/types/plugins.d.ts.map +1 -0
  239. package/dist/types/preactElement/renderPreactElement.d.ts +5 -0
  240. package/dist/types/preactElement/renderPreactElement.d.ts.map +1 -0
  241. package/package.json +14 -7
  242. package/dist/cjs/intlayerMiddlewarePlugin.cjs +0 -224
  243. package/dist/cjs/intlayerMiddlewarePlugin.cjs.map +0 -1
  244. package/dist/cjs/intlayerPlugin.cjs +0 -76
  245. package/dist/cjs/intlayerPlugin.cjs.map +0 -1
  246. package/dist/esm/intlayerMiddlewarePlugin.mjs +0 -200
  247. package/dist/esm/intlayerMiddlewarePlugin.mjs.map +0 -1
  248. package/dist/esm/intlayerPlugin.mjs +0 -52
  249. package/dist/esm/intlayerPlugin.mjs.map +0 -1
  250. package/dist/types/intlayerMiddlewarePlugin.d.ts +0 -6
  251. package/dist/types/intlayerMiddlewarePlugin.d.ts.map +0 -1
  252. package/dist/types/intlayerPlugin.d.ts +0 -16
  253. package/dist/types/intlayerPlugin.d.ts.map +0 -1
@@ -0,0 +1,62 @@
1
+ "use client";
2
+ import { jsx } from "preact/jsx-runtime";
3
+ import {
4
+ useEffect,
5
+ useState
6
+ } from "preact/compat";
7
+ import { ChangedContentProvider } from "./ChangedContentContext.mjs";
8
+ import {
9
+ CommunicatorProvider
10
+ } from "./CommunicatorContext.mjs";
11
+ import {
12
+ ConfigurationProvider
13
+ } from "./ConfigurationContext.mjs";
14
+ import { DictionariesRecordProvider } from "./DictionariesRecordContext.mjs";
15
+ import {
16
+ EditedContentProvider,
17
+ useGetEditedContentState
18
+ } from "./EditedContentContext.mjs";
19
+ import {
20
+ EditorEnabledProvider,
21
+ useEditorEnabled,
22
+ useGetEditorEnabledState
23
+ } from "./EditorEnabledContext.mjs";
24
+ import { FocusDictionaryProvider } from "./FocusDictionaryContext.mjs";
25
+ const EditorProvidersWrapper = ({ children }) => {
26
+ const getEditedContentState = useGetEditedContentState();
27
+ useEffect(() => {
28
+ getEditedContentState();
29
+ }, []);
30
+ return /* @__PURE__ */ jsx(DictionariesRecordProvider, { children: /* @__PURE__ */ jsx(EditedContentProvider, { children: /* @__PURE__ */ jsx(FocusDictionaryProvider, { children }) }) });
31
+ };
32
+ const EditorEnabledCheckRenderer = ({
33
+ children,
34
+ fallback
35
+ }) => {
36
+ const getEditorEnabled = useGetEditorEnabledState();
37
+ const { enabled } = useEditorEnabled();
38
+ useEffect(() => {
39
+ if (enabled) return;
40
+ getEditorEnabled();
41
+ }, [enabled]);
42
+ return enabled ? children : fallback;
43
+ };
44
+ const IframeCheckRenderer = ({
45
+ children,
46
+ fallback
47
+ }) => {
48
+ const [isInIframe, setIsInIframe] = useState(false);
49
+ useEffect(() => {
50
+ setIsInIframe(window.self !== window.top);
51
+ }, []);
52
+ return isInIframe ? children : fallback;
53
+ };
54
+ const EditorProvider = ({
55
+ children,
56
+ configuration,
57
+ ...props
58
+ }) => /* @__PURE__ */ jsx(ChangedContentProvider, { children: /* @__PURE__ */ jsx(EditorEnabledProvider, { children: /* @__PURE__ */ jsx(ConfigurationProvider, { configuration, children: /* @__PURE__ */ jsx(IframeCheckRenderer, { fallback: children, children: /* @__PURE__ */ jsx(CommunicatorProvider, { ...props, children: /* @__PURE__ */ jsx(EditorEnabledCheckRenderer, { fallback: children, children: /* @__PURE__ */ jsx(EditorProvidersWrapper, { children }) }) }) }) }) }) });
59
+ export {
60
+ EditorProvider
61
+ };
62
+ //# sourceMappingURL=EditorProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FC,\n type PropsWithChildren,\n ReactNode,\n useEffect,\n useState,\n} from 'preact/compat';\nimport { ChangedContentProvider } from './ChangedContentContext';\nimport {\n type CommunicatorProviderProps,\n CommunicatorProvider,\n} from './CommunicatorContext';\nimport {\n type ConfigurationProviderProps,\n ConfigurationProvider,\n} from './ConfigurationContext';\nimport { DictionariesRecordProvider } from './DictionariesRecordContext';\nimport {\n EditedContentProvider,\n useGetEditedContentState,\n} from './EditedContentContext';\nimport {\n EditorEnabledProvider,\n useEditorEnabled,\n useGetEditorEnabledState,\n} from './EditorEnabledContext';\nimport { FocusDictionaryProvider } from './FocusDictionaryContext';\n\n/**\n * This component add all the providers needed by the editor.\n * It is used to wrap the application, or the editor to work together.\n */\nconst EditorProvidersWrapper: FC<PropsWithChildren> = ({ children }) => {\n const getEditedContentState = useGetEditedContentState();\n\n useEffect(() => {\n getEditedContentState();\n }, []);\n\n return (\n <DictionariesRecordProvider>\n <EditedContentProvider>\n <FocusDictionaryProvider>{children}</FocusDictionaryProvider>\n </EditedContentProvider>\n </DictionariesRecordProvider>\n );\n};\n\ntype FallbackProps = {\n fallback: ReactNode;\n};\n\n/**\n * This component check if the editor is enabled to render the editor providers.\n */\nconst EditorEnabledCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const getEditorEnabled = useGetEditorEnabledState();\n\n const { enabled } = useEditorEnabled();\n\n useEffect(() => {\n if (enabled) return;\n\n // Check if the editor is wrapping the application\n getEditorEnabled();\n }, [enabled]);\n\n return enabled ? children : fallback;\n};\n\n/**\n * This component is used to check if the editor is wrapping the application.\n * It avoid to send window.postMessage to the application if the editor is not wrapping the application.\n */\nconst IframeCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const [isInIframe, setIsInIframe] = useState(false);\n\n useEffect(() => {\n setIsInIframe(window.self !== window.top);\n }, []);\n\n return isInIframe ? children : fallback;\n};\n\nexport type EditorProviderProps = CommunicatorProviderProps &\n ConfigurationProviderProps;\n\nexport const EditorProvider: FC<PropsWithChildren<EditorProviderProps>> = ({\n children,\n configuration,\n ...props\n}) => (\n <ChangedContentProvider>\n <EditorEnabledProvider>\n <ConfigurationProvider configuration={configuration}>\n <IframeCheckRenderer fallback={children}>\n <CommunicatorProvider {...props}>\n <EditorEnabledCheckRenderer fallback={children}>\n <EditorProvidersWrapper>{children}</EditorProvidersWrapper>\n </EditorEnabledCheckRenderer>\n </CommunicatorProvider>\n </IframeCheckRenderer>\n </ConfigurationProvider>\n </EditorEnabledProvider>\n </ChangedContentProvider>\n);\n"],"mappings":";AA4CQ;AA1CR;AAAA,EAIE;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AACvC;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,+BAA+B;AAMxC,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AACtE,QAAM,wBAAwB,yBAAyB;AAEvD,YAAU,MAAM;AACd,0BAAsB;AAAA,EACxB,GAAG,CAAC,CAAC;AAEL,SACE,oBAAC,8BACC,8BAAC,yBACC,8BAAC,2BAAyB,UAAS,GACrC,GACF;AAEJ;AASA,MAAM,6BAAmE,CAAC;AAAA,EACxE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,mBAAmB,yBAAyB;AAElD,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAErC,YAAU,MAAM;AACd,QAAI,QAAS;AAGb,qBAAiB;AAAA,EACnB,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,UAAU,WAAW;AAC9B;AAMA,MAAM,sBAA4D,CAAC;AAAA,EACjE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,KAAK;AAElD,YAAU,MAAM;AACd,kBAAc,OAAO,SAAS,OAAO,GAAG;AAAA,EAC1C,GAAG,CAAC,CAAC;AAEL,SAAO,aAAa,WAAW;AACjC;AAKO,MAAM,iBAA6D,CAAC;AAAA,EACzE;AAAA,EACA;AAAA,EACA,GAAG;AACL,MACE,oBAAC,0BACC,8BAAC,yBACC,8BAAC,yBAAsB,eACrB,8BAAC,uBAAoB,UAAU,UAC7B,8BAAC,wBAAsB,GAAG,OACxB,8BAAC,8BAA2B,UAAU,UACpC,8BAAC,0BAAwB,UAAS,GACpC,GACF,GACF,GACF,GACF,GACF;","names":[]}
@@ -0,0 +1,58 @@
1
+ "use client";
2
+ import { jsx } from "preact/jsx-runtime";
3
+ import { MessageKey } from "@intlayer/editor";
4
+ import {
5
+ createContext,
6
+ useContext
7
+ } from "preact/compat";
8
+ import { useCrossFrameState } from "./useCrossFrameState.mjs";
9
+ const FocusDictionaryStateContext = createContext(void 0);
10
+ const FocusDictionaryActionsContext = createContext(void 0);
11
+ const FocusDictionaryProvider = ({
12
+ children
13
+ }) => {
14
+ const [focusedContent, setFocusedContent] = useCrossFrameState(
15
+ MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,
16
+ null
17
+ );
18
+ const setFocusedContentKeyPath = (keyPath) => {
19
+ setFocusedContent((prev) => {
20
+ if (!prev) {
21
+ return prev;
22
+ }
23
+ return { ...prev, keyPath };
24
+ });
25
+ };
26
+ return /* @__PURE__ */ jsx(FocusDictionaryStateContext.Provider, { value: { focusedContent }, children: /* @__PURE__ */ jsx(
27
+ FocusDictionaryActionsContext.Provider,
28
+ {
29
+ value: { setFocusedContent, setFocusedContentKeyPath },
30
+ children
31
+ }
32
+ ) });
33
+ };
34
+ const useFocusDictionaryActions = () => {
35
+ const context = useContext(FocusDictionaryActionsContext);
36
+ if (context === void 0) {
37
+ throw new Error(
38
+ "useFocusDictionaryActions must be used within a FocusDictionaryProvider"
39
+ );
40
+ }
41
+ return context;
42
+ };
43
+ const useFocusDictionary = () => {
44
+ const actionContext = useFocusDictionaryActions();
45
+ const stateContext = useContext(FocusDictionaryStateContext);
46
+ if (stateContext === void 0) {
47
+ throw new Error(
48
+ "useFocusDictionaryState must be used within a FocusDictionaryProvider"
49
+ );
50
+ }
51
+ return { ...stateContext, ...actionContext };
52
+ };
53
+ export {
54
+ FocusDictionaryProvider,
55
+ useFocusDictionary,
56
+ useFocusDictionaryActions
57
+ };
58
+ //# sourceMappingURL=FocusDictionaryContext.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/editor/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype DictionaryPath = string;\n\nexport type FileContent = {\n dictionaryKey: string;\n keyPath?: KeyPath[];\n dictionaryPath?: DictionaryPath;\n};\n\ntype FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\ntype FocusDictionaryActions = {\n setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\nconst FocusDictionaryStateContext = createContext<\n FocusDictionaryState | undefined\n>(undefined);\nconst FocusDictionaryActionsContext = createContext<\n FocusDictionaryActions | undefined\n>(undefined);\n\nexport const FocusDictionaryProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [focusedContent, setFocusedContent] =\n useCrossFrameState<FileContent | null>(\n MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,\n null\n );\n\n const setFocusedContentKeyPath = (keyPath: KeyPath[]) => {\n setFocusedContent((prev) => {\n if (!prev) {\n return prev; // nothing to update if there's no focused content\n }\n return { ...prev, keyPath };\n });\n };\n\n return (\n <FocusDictionaryStateContext.Provider value={{ focusedContent }}>\n <FocusDictionaryActionsContext.Provider\n value={{ setFocusedContent, setFocusedContentKeyPath }}\n >\n {children}\n </FocusDictionaryActionsContext.Provider>\n </FocusDictionaryStateContext.Provider>\n );\n};\n\nexport const useFocusDictionaryActions = () => {\n const context = useContext(FocusDictionaryActionsContext);\n if (context === undefined) {\n throw new Error(\n 'useFocusDictionaryActions must be used within a FocusDictionaryProvider'\n );\n }\n return context;\n};\n\nexport const useFocusDictionary = () => {\n const actionContext = useFocusDictionaryActions();\n const stateContext = useContext(FocusDictionaryStateContext);\n\n if (stateContext === undefined) {\n throw new Error(\n 'useFocusDictionaryState must be used within a FocusDictionaryProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";AA0DM;AAvDN,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AAmBnC,MAAM,8BAA8B,cAElC,MAAS;AACX,MAAM,gCAAgC,cAEpC,MAAS;AAEJ,MAAM,0BAAiD,CAAC;AAAA,EAC7D;AACF,MAAM;AACJ,QAAM,CAAC,gBAAgB,iBAAiB,IACtC;AAAA,IACE,WAAW;AAAA,IACX;AAAA,EACF;AAEF,QAAM,2BAA2B,CAAC,YAAuB;AACvD,sBAAkB,CAAC,SAAS;AAC1B,UAAI,CAAC,MAAM;AACT,eAAO;AAAA,MACT;AACA,aAAO,EAAE,GAAG,MAAM,QAAQ;AAAA,IAC5B,CAAC;AAAA,EACH;AAEA,SACE,oBAAC,4BAA4B,UAA5B,EAAqC,OAAO,EAAE,eAAe,GAC5D;AAAA,IAAC,8BAA8B;AAAA,IAA9B;AAAA,MACC,OAAO,EAAE,mBAAmB,yBAAyB;AAAA,MAEpD;AAAA;AAAA,EACH,GACF;AAEJ;AAEO,MAAM,4BAA4B,MAAM;AAC7C,QAAM,UAAU,WAAW,6BAA6B;AACxD,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,qBAAqB,MAAM;AACtC,QAAM,gBAAgB,0BAA0B;AAChD,QAAM,eAAe,WAAW,2BAA2B;AAE3D,MAAI,iBAAiB,QAAW;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
@@ -0,0 +1,88 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
3
+ import { IntlayerEventListener } from "@intlayer/api";
4
+ import configuration from "@intlayer/config/built";
5
+ import { useEffect } from "preact/hooks";
6
+ import { useChangedContentActions } from "./ChangedContentContext.mjs";
7
+ import { useEditorEnabled } from "./EditorEnabledContext.mjs";
8
+ import { EditorProvider } from "./EditorProvider.mjs";
9
+ import { useCrossURLPathSetter } from "./useCrossURLPathState.mjs";
10
+ import { useIframeClickInterceptor } from "./useIframeClickInterceptor.mjs";
11
+ const IntlayerEditorHooksEnabled = () => {
12
+ useCrossURLPathSetter();
13
+ useIframeClickInterceptor();
14
+ return /* @__PURE__ */ jsx(Fragment, {});
15
+ };
16
+ const { editor } = configuration;
17
+ const IntlayerEditorHook = () => {
18
+ const { enabled } = useEditorEnabled();
19
+ const changedContentContext = useChangedContentActions();
20
+ useEffect(() => {
21
+ if (!editor.hotReload) return;
22
+ if (!editor.clientId) return;
23
+ if (!editor.clientSecret) return;
24
+ const eventSource = new IntlayerEventListener();
25
+ try {
26
+ eventSource.initialize().then(() => {
27
+ eventSource.onDictionaryChange = (dictionary) => changedContentContext?.setChangedContent(
28
+ dictionary.key,
29
+ dictionary.content
30
+ );
31
+ });
32
+ } catch (error) {
33
+ console.error("Error initializing IntlayerEventListener:", error);
34
+ }
35
+ return () => eventSource.cleanup();
36
+ }, []);
37
+ return enabled ? /* @__PURE__ */ jsx(IntlayerEditorHooksEnabled, {}) : /* @__PURE__ */ jsx(Fragment, {});
38
+ };
39
+ const IntlayerEditorProvider = ({ children }) => {
40
+ return /* @__PURE__ */ jsxs(
41
+ EditorProvider,
42
+ {
43
+ postMessage: (data) => {
44
+ if (typeof window === "undefined") return;
45
+ const isInIframe = window.self !== window.top;
46
+ if (!isInIframe) return;
47
+ if (editor.applicationURL.length > 0) {
48
+ window?.postMessage(
49
+ data,
50
+ // Use to restrict the origin of the editor for security reasons.
51
+ // Correspond to the current application URL to synchronize the locales states.
52
+ editor.applicationURL
53
+ );
54
+ }
55
+ if (editor.editorURL.length > 0) {
56
+ window.parent?.postMessage(
57
+ data,
58
+ // Use to restrict the origin of the editor for security reasons.
59
+ // Correspond to the editor URL to synchronize the locales states.
60
+ editor.editorURL
61
+ );
62
+ }
63
+ if (editor.cmsURL.length > 0) {
64
+ window.parent?.postMessage(
65
+ data,
66
+ // Use to restrict the origin of the CMS for security reasons.
67
+ // Correspond to the CMS URL.
68
+ editor.cmsURL
69
+ );
70
+ }
71
+ },
72
+ allowedOrigins: [
73
+ editor?.editorURL,
74
+ editor?.cmsURL,
75
+ editor?.applicationURL
76
+ ],
77
+ configuration,
78
+ children: [
79
+ /* @__PURE__ */ jsx(IntlayerEditorHook, {}),
80
+ children
81
+ ]
82
+ }
83
+ );
84
+ };
85
+ export {
86
+ IntlayerEditorProvider
87
+ };
88
+ //# sourceMappingURL=IntlayerEditorProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport { IntlayerEventListener } from '@intlayer/api';\nimport configuration from '@intlayer/config/built';\nimport { type ComponentChildren, type FunctionComponent } from 'preact';\nimport { useEffect } from 'preact/hooks';\nimport { useChangedContentActions } from './ChangedContentContext';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { EditorProvider } from './EditorProvider';\nimport { useCrossURLPathSetter } from './useCrossURLPathState';\nimport { useIframeClickInterceptor } from './useIframeClickInterceptor';\n\nconst IntlayerEditorHooksEnabled: FunctionComponent = () => {\n /**\n * URL Messages\n */\n useCrossURLPathSetter();\n\n /**\n * Click Messages\n */\n useIframeClickInterceptor();\n\n return <></>;\n};\n\nconst { editor } = configuration;\n\nconst IntlayerEditorHook: FunctionComponent = () => {\n const { enabled } = useEditorEnabled();\n\n /**\n * Hot reloading\n */\n const changedContentContext = useChangedContentActions();\n\n useEffect(() => {\n if (!editor.hotReload) return;\n if (!editor.clientId) return;\n if (!editor.clientSecret) return;\n\n const eventSource = new IntlayerEventListener();\n try {\n eventSource.initialize().then(() => {\n eventSource.onDictionaryChange = (dictionary) =>\n changedContentContext?.setChangedContent(\n dictionary.key,\n dictionary.content\n );\n });\n } catch (error) {\n console.error('Error initializing IntlayerEventListener:', error);\n }\n\n return () => eventSource.cleanup();\n }, []);\n\n return enabled ? <IntlayerEditorHooksEnabled /> : <></>;\n};\n\nexport const IntlayerEditorProvider: FunctionComponent<{\n children?: ComponentChildren;\n}> = ({ children }) => {\n return (\n <EditorProvider\n postMessage={(data: any) => {\n if (typeof window === 'undefined') return;\n\n const isInIframe = window.self !== window.top;\n if (!isInIframe) return;\n\n if (editor.applicationURL.length > 0) {\n window?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the current application URL to synchronize the locales states.\n editor.applicationURL\n );\n }\n\n if (editor.editorURL.length > 0) {\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the editor URL to synchronize the locales states.\n editor.editorURL\n );\n }\n\n if (editor.cmsURL.length > 0) {\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the CMS for security reasons.\n // Correspond to the CMS URL.\n editor.cmsURL\n );\n }\n }}\n allowedOrigins={[\n editor?.editorURL,\n editor?.cmsURL,\n editor?.applicationURL,\n ]}\n configuration={configuration}\n >\n <IntlayerEditorHook />\n {children}\n </EditorProvider>\n );\n};\n"],"mappings":";AAuBS,wBAyCL,YAzCK;AArBT,SAAS,6BAA6B;AACtC,OAAO,mBAAmB;AAE1B,SAAS,iBAAiB;AAC1B,SAAS,gCAAgC;AACzC,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,iCAAiC;AAE1C,MAAM,6BAAgD,MAAM;AAI1D,wBAAsB;AAKtB,4BAA0B;AAE1B,SAAO,gCAAE;AACX;AAEA,MAAM,EAAE,OAAO,IAAI;AAEnB,MAAM,qBAAwC,MAAM;AAClD,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAKrC,QAAM,wBAAwB,yBAAyB;AAEvD,YAAU,MAAM;AACd,QAAI,CAAC,OAAO,UAAW;AACvB,QAAI,CAAC,OAAO,SAAU;AACtB,QAAI,CAAC,OAAO,aAAc;AAE1B,UAAM,cAAc,IAAI,sBAAsB;AAC9C,QAAI;AACF,kBAAY,WAAW,EAAE,KAAK,MAAM;AAClC,oBAAY,qBAAqB,CAAC,eAChC,uBAAuB;AAAA,UACrB,WAAW;AAAA,UACX,WAAW;AAAA,QACb;AAAA,MACJ,CAAC;AAAA,IACH,SAAS,OAAO;AACd,cAAQ,MAAM,6CAA6C,KAAK;AAAA,IAClE;AAEA,WAAO,MAAM,YAAY,QAAQ;AAAA,EACnC,GAAG,CAAC,CAAC;AAEL,SAAO,UAAU,oBAAC,8BAA2B,IAAK,gCAAE;AACtD;AAEO,MAAM,yBAER,CAAC,EAAE,SAAS,MAAM;AACrB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAa,CAAC,SAAc;AAC1B,YAAI,OAAO,WAAW,YAAa;AAEnC,cAAM,aAAa,OAAO,SAAS,OAAO;AAC1C,YAAI,CAAC,WAAY;AAEjB,YAAI,OAAO,eAAe,SAAS,GAAG;AACpC,kBAAQ;AAAA,YACN;AAAA;AAAA;AAAA,YAGA,OAAO;AAAA,UACT;AAAA,QACF;AAEA,YAAI,OAAO,UAAU,SAAS,GAAG;AAC/B,iBAAO,QAAQ;AAAA,YACb;AAAA;AAAA;AAAA,YAGA,OAAO;AAAA,UACT;AAAA,QACF;AAEA,YAAI,OAAO,OAAO,SAAS,GAAG;AAC5B,iBAAO,QAAQ;AAAA,YACb;AAAA;AAAA;AAAA,YAGA,OAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAAA,MACA,gBAAgB;AAAA,QACd,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,QAAQ;AAAA,MACV;AAAA,MACA;AAAA,MAEA;AAAA,4BAAC,sBAAmB;AAAA,QACnB;AAAA;AAAA;AAAA,EACH;AAEJ;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./ContentSelectorWrapper.mjs";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/editor/index.ts"],"sourcesContent":["export * from './ContentSelectorWrapper';\n"],"mappings":"AAAA,cAAc;","names":[]}
@@ -0,0 +1,29 @@
1
+ "use client";
2
+ import { compareUrls } from "@intlayer/editor";
3
+ import { useEffect } from "preact/hooks";
4
+ import { useCommunicator } from "./CommunicatorContext.mjs";
5
+ const useCrossFrameMessageListener = (key, onEventTriggered, revalidator) => {
6
+ const { allowedOrigins, postMessage, senderId } = useCommunicator();
7
+ useEffect(() => {
8
+ if (onEventTriggered) {
9
+ const handleMessage = (event) => {
10
+ const { type, data, senderId: msgSenderId } = event.data;
11
+ if (type !== key) return;
12
+ if (msgSenderId === senderId) return;
13
+ if (typeof allowedOrigins === "undefined" || allowedOrigins?.some((url) => compareUrls(url, event.origin)) || allowedOrigins?.includes("*")) {
14
+ onEventTriggered(data);
15
+ }
16
+ };
17
+ window.addEventListener("message", handleMessage);
18
+ return () => window.removeEventListener("message", handleMessage);
19
+ }
20
+ }, [allowedOrigins, postMessage, senderId, revalidator]);
21
+ const postMessageWrapper = (data) => {
22
+ postMessage({ type: key, data, senderId });
23
+ };
24
+ return postMessageWrapper;
25
+ };
26
+ export {
27
+ useCrossFrameMessageListener
28
+ };
29
+ //# sourceMappingURL=useCrossFrameMessageListener.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/editor/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport { type MessageKey, compareUrls } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport { useCommunicator } from './CommunicatorContext';\n\n/**\n * useCrossFrameMessageListener\n *\n * This React hook listens for messages sent via the `postMessage` API and triggers a callback\n * whenever a message of the specified type (`key`) is received. It is useful for synchronizing\n * state or events across different windows, iframes, or contexts.\n *\n * @template S - The type of the data payload in the message.\n * @param key - A unique identifier for the message type to listen for.\n * @param [onEventTriggered] - A callback function triggered when a message\n * @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state\n * with the specified key is received. The callback receives the message data as its argument.\n *\n * @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function\n * that allows broadcasting messages with the specified key and data.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const { allowedOrigins, postMessage, senderId } = useCommunicator();\n\n useEffect(() => {\n if (onEventTriggered) {\n /**\n * Message handler to process incoming messages.\n *\n * - **Message Filtering:** Ensures only messages with the specified `key` are processed.\n * - **Origin Validation:** Checks that the origin of the message is within the allowed origins.\n *\n * @param {MessageEvent<{ type: string; data: S }>} event - The incoming message event object.\n */\n const handleMessage = (\n event: MessageEvent<{ type: string; data: S; senderId: string }>\n ) => {\n const { type, data, senderId: msgSenderId } = event.data;\n\n // Ignore messages that do not match the current key\n if (type !== key) return;\n\n // Ignore messages from myself\n if (msgSenderId === senderId) return;\n\n // Check if the message origin is allowed\n if (\n typeof allowedOrigins === 'undefined' ||\n allowedOrigins?.some((url) => compareUrls(url, event.origin)) ||\n allowedOrigins?.includes('*')\n ) {\n // Update the local state with the received data\n onEventTriggered(data);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Clean up the event listener on unmount\n return () => window.removeEventListener('message', handleMessage);\n }\n }, [allowedOrigins, postMessage, senderId, revalidator]);\n\n /**\n * A wrapper function around the `postMessage` function to broadcast messages efficiently.\n *\n * - **Encapsulation:** Ensures the `postMessage` function is scoped to the provided key.\n * - **Ease of Use:** Simplifies broadcasting messages with consistent type and format.\n *\n * @param {S} data - The data payload to include in the message.\n * @returns {void}\n */\n const postMessageWrapper: (data?: S) => void = (data) => {\n postMessage({ type: key, data, senderId });\n };\n\n return postMessageWrapper;\n};\n"],"mappings":";AAEA,SAA0B,mBAAmB;AAC7C,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAkBzB,MAAM,+BAA+B,CAC1C,KACA,kBACA,gBACG;AACH,QAAM,EAAE,gBAAgB,aAAa,SAAS,IAAI,gBAAgB;AAElE,YAAU,MAAM;AACd,QAAI,kBAAkB;AASpB,YAAM,gBAAgB,CACpB,UACG;AACH,cAAM,EAAE,MAAM,MAAM,UAAU,YAAY,IAAI,MAAM;AAGpD,YAAI,SAAS,IAAK;AAGlB,YAAI,gBAAgB,SAAU;AAG9B,YACE,OAAO,mBAAmB,eAC1B,gBAAgB,KAAK,CAAC,QAAQ,YAAY,KAAK,MAAM,MAAM,CAAC,KAC5D,gBAAgB,SAAS,GAAG,GAC5B;AAEA,2BAAiB,IAAI;AAAA,QACvB;AAAA,MACF;AAEA,aAAO,iBAAiB,WAAW,aAAa;AAGhD,aAAO,MAAM,OAAO,oBAAoB,WAAW,aAAa;AAAA,IAClE;AAAA,EACF,GAAG,CAAC,gBAAgB,aAAa,UAAU,WAAW,CAAC;AAWvD,QAAM,qBAAyC,CAAC,SAAS;AACvD,gBAAY,EAAE,MAAM,KAAK,MAAM,SAAS,CAAC;AAAA,EAC3C;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,53 @@
1
+ "use client";
2
+ import { useEffect, useState } from "preact/hooks";
3
+ import { useCommunicator } from "./CommunicatorContext.mjs";
4
+ import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs";
5
+ const resolveState = (valueOrUpdater, prevState) => typeof valueOrUpdater === "function" ? valueOrUpdater(prevState) : valueOrUpdater;
6
+ const useCrossFrameState = (key, initialState, options) => {
7
+ const { postMessage, senderId } = useCommunicator();
8
+ const { emit, receive } = options ?? { emit: true, receive: true };
9
+ const handleStateChange = (valueOrUpdater, prevState) => {
10
+ const resolvedState = resolveState(valueOrUpdater, prevState);
11
+ if (emit && typeof postMessage === "function" && typeof resolvedState !== "undefined") {
12
+ postMessage({ type: `${key}/post`, data: resolvedState, senderId });
13
+ }
14
+ return resolvedState;
15
+ };
16
+ const postState = () => {
17
+ if (typeof postMessage !== "function") return;
18
+ postMessage({ type: `${key}/post`, data: state, senderId });
19
+ };
20
+ const [state, setState] = useState(() => handleStateChange(initialState));
21
+ const setStateWrapper = (valueOrUpdater) => setState((prevState) => handleStateChange(valueOrUpdater, prevState));
22
+ useCrossFrameMessageListener(
23
+ `${key}/post`,
24
+ // Only activate the state listener if the `receive` option is true
25
+ receive ? (data) => {
26
+ setState(data);
27
+ } : void 0
28
+ );
29
+ const onGetMessage = (_, originSenderId) => {
30
+ if (!emit) return;
31
+ if (typeof postMessage !== "function") return;
32
+ if (originSenderId === senderId) return;
33
+ if (typeof state === "undefined") return;
34
+ postMessage({ type: `${key}/post`, data: state, senderId });
35
+ };
36
+ useCrossFrameMessageListener(
37
+ `${key}/get`,
38
+ // Only activate the state listener if the `emit` option is true
39
+ emit ? onGetMessage : void 0,
40
+ state
41
+ // Revalidate the listener if the state changes
42
+ );
43
+ useEffect(() => {
44
+ if (receive && typeof postMessage === "function" && typeof state === "undefined") {
45
+ postMessage({ type: `${key}/get`, senderId });
46
+ }
47
+ }, []);
48
+ return [state, setStateWrapper, postState];
49
+ };
50
+ export {
51
+ useCrossFrameState
52
+ };
53
+ //# sourceMappingURL=useCrossFrameState.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/editor/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport { type MessageKey } from '@intlayer/editor';\nimport { SetStateAction } from 'preact/compat';\nimport { Dispatch, useEffect, useState, type StateUpdater } from 'preact/hooks';\nimport { useCommunicator } from './CommunicatorContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport type CrossFrameStateOptions = {\n emit?: boolean;\n receive?: boolean;\n};\n\nconst resolveState = <S,>(\n valueOrUpdater?: S | ((prevState: S) => S),\n prevState?: S\n): S =>\n typeof valueOrUpdater === 'function'\n ? (valueOrUpdater as (prevState?: S) => S)(prevState)\n : (valueOrUpdater as S);\n\n/**\n * Configuration options for `useCrossFrameState`.\n * @typedef {Object} CrossFrameStateOptions\n * @property {boolean} [emit=true] - Whether to broadcast state changes to other instances.\n * @property {boolean} [receive=true] - Whether to listen for state updates from other instances.\n */\n\n/**\n * useCrossFrameState\n *\n * This Preact hook synchronizes state across multiple instances (e.g., different iframes or windows).\n * It uses the `postMessage` API to communicate state changes and updates between instances.\n *\n * @template S - The type of the state.\n * @param key - A unique identifier for the state to synchronize.\n * @param initialState - The initial state value or a function to compute it lazily.\n * @param options - Configuration options to control emitting and receiving messages.\n * - `emit` (default: true): Whether to broadcast state changes to other instances.\n * - `receive` (default: true): Whether to listen for state updates from other instances.\n *\n * @returns {[S, StateUpdater<S>, typeof postState]} An array containing the current state and a setter function, and a function to manually post the state.\n */\nexport const useCrossFrameState = <S,>(\n key: `${MessageKey}`,\n initialState?: S | (() => S),\n options?: CrossFrameStateOptions\n): [S, Dispatch<SetStateAction<S>>, typeof postState] => {\n const { postMessage, senderId } = useCommunicator();\n\n const { emit, receive } = options ?? { emit: true, receive: true };\n\n const handleStateChange = (\n valueOrUpdater?: S | ((prevState: S) => S),\n prevState?: S\n ): S => {\n // Initialize state from the provided initial value, if defined\n const resolvedState: S = resolveState(valueOrUpdater, prevState);\n\n // Emit the initial state if `emit` is enabled and initial state is defined\n if (\n emit &&\n typeof postMessage === 'function' &&\n typeof resolvedState !== 'undefined'\n ) {\n postMessage({ type: `${key}/post`, data: resolvedState, senderId });\n }\n\n return resolvedState;\n };\n\n const postState = () => {\n if (typeof postMessage !== 'function') return;\n postMessage({ type: `${key}/post`, data: state, senderId });\n };\n\n const [state, setState] = useState<S>(() => handleStateChange(initialState));\n\n /**\n * A wrapper function around the `setState` function to handle messaging efficiently.\n *\n * This approach has several advantages over using an additional `useEffect`:\n * - **Avoid Redundant Re-renders:** By emitting the message directly within the `setState` logic,\n * it prevents the extra render cycle that would be triggered when using `useEffect`.\n * - **Consistency:** Ensures the message is emitted immediately when the state is updated,\n * avoiding potential delays caused by the asynchronous nature of `useEffect`.\n *\n * This function keeps the same API as `setState` and is memoized using `useCallback`\n * to prevent unnecessary re-renders of dependent components.\n *\n * @template S - The type of the state.\n * @param {S | ((prevState: S) => S)} valueOrUpdater - The new state or a function to produce it.\n * @returns {void}\n */\n const setStateWrapper: Dispatch<SetStateAction<S>> = (\n valueOrUpdater: S | ((prevState: S) => S)\n ) => setState((prevState) => handleStateChange(valueOrUpdater, prevState));\n\n /**\n * Listen for messages with the specified key and update the state accordingly.\n */\n useCrossFrameMessageListener<S>(\n `${key}/post`,\n // Only activate the state listener if the `receive` option is true\n receive\n ? (data) => {\n setState(data);\n }\n : undefined\n );\n\n const onGetMessage = (_: unknown, originSenderId?: string) => {\n if (!emit) return;\n if (typeof postMessage !== 'function') return;\n if (originSenderId === senderId) return;\n if (typeof state === 'undefined') return;\n\n postMessage({ type: `${key}/post`, data: state, senderId });\n };\n\n /**\n * Listen for messages request to get the state content and send it back.\n */\n useCrossFrameMessageListener<S>(\n `${key}/get`,\n // Only activate the state listener if the `emit` option is true\n emit ? onGetMessage : undefined,\n state // Revalidate the listener if the state changes\n );\n\n useEffect(() => {\n // If the component is mounted and the hook in receive mode,\n // Request the state from the other instance\n if (\n receive &&\n typeof postMessage === 'function' &&\n typeof state === 'undefined'\n ) {\n postMessage({ type: `${key}/get`, senderId });\n }\n }, []);\n\n // Return the useState state and setter\n return [state, setStateWrapper, postState];\n};\n"],"mappings":";AAIA,SAAmB,WAAW,gBAAmC;AACjE,SAAS,uBAAuB;AAChC,SAAS,oCAAoC;AAO7C,MAAM,eAAe,CACnB,gBACA,cAEA,OAAO,mBAAmB,aACrB,eAAwC,SAAS,IACjD;AAwBA,MAAM,qBAAqB,CAChC,KACA,cACA,YACuD;AACvD,QAAM,EAAE,aAAa,SAAS,IAAI,gBAAgB;AAElD,QAAM,EAAE,MAAM,QAAQ,IAAI,WAAW,EAAE,MAAM,MAAM,SAAS,KAAK;AAEjE,QAAM,oBAAoB,CACxB,gBACA,cACM;AAEN,UAAM,gBAAmB,aAAa,gBAAgB,SAAS;AAG/D,QACE,QACA,OAAO,gBAAgB,cACvB,OAAO,kBAAkB,aACzB;AACA,kBAAY,EAAE,MAAM,GAAG,GAAG,SAAS,MAAM,eAAe,SAAS,CAAC;AAAA,IACpE;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,MAAM;AACtB,QAAI,OAAO,gBAAgB,WAAY;AACvC,gBAAY,EAAE,MAAM,GAAG,GAAG,SAAS,MAAM,OAAO,SAAS,CAAC;AAAA,EAC5D;AAEA,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAY,MAAM,kBAAkB,YAAY,CAAC;AAkB3E,QAAM,kBAA+C,CACnD,mBACG,SAAS,CAAC,cAAc,kBAAkB,gBAAgB,SAAS,CAAC;AAKzE;AAAA,IACE,GAAG,GAAG;AAAA;AAAA,IAEN,UACI,CAAC,SAAS;AACR,eAAS,IAAI;AAAA,IACf,IACA;AAAA,EACN;AAEA,QAAM,eAAe,CAAC,GAAY,mBAA4B;AAC5D,QAAI,CAAC,KAAM;AACX,QAAI,OAAO,gBAAgB,WAAY;AACvC,QAAI,mBAAmB,SAAU;AACjC,QAAI,OAAO,UAAU,YAAa;AAElC,gBAAY,EAAE,MAAM,GAAG,GAAG,SAAS,MAAM,OAAO,SAAS,CAAC;AAAA,EAC5D;AAKA;AAAA,IACE,GAAG,GAAG;AAAA;AAAA,IAEN,OAAO,eAAe;AAAA,IACtB;AAAA;AAAA,EACF;AAEA,YAAU,MAAM;AAGd,QACE,WACA,OAAO,gBAAgB,cACvB,OAAO,UAAU,aACjB;AACA,kBAAY,EAAE,MAAM,GAAG,GAAG,QAAQ,SAAS,CAAC;AAAA,IAC9C;AAAA,EACF,GAAG,CAAC,CAAC;AAGL,SAAO,CAAC,OAAO,iBAAiB,SAAS;AAC3C;","names":[]}
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ import { MessageKey } from "@intlayer/editor";
3
+ import { useEffect } from "preact/hooks";
4
+ import {
5
+ useCrossFrameState
6
+ } from "./useCrossFrameState.mjs";
7
+ const useCrossURLPathState = (initialState, options) => useCrossFrameState(MessageKey.INTLAYER_URL_CHANGE, initialState, options);
8
+ const useCrossURLPathSetter = (initialState) => {
9
+ const states = useCrossURLPathState(initialState, {
10
+ emit: true,
11
+ receive: false
12
+ });
13
+ const [_state, setState] = states;
14
+ useEffect(() => {
15
+ const originalPushState = history.pushState;
16
+ const originalReplaceState = history.replaceState;
17
+ const injectLocationChangeEvent = (method) => function(...args) {
18
+ method.apply(this, args);
19
+ window.dispatchEvent(new Event("locationchange"));
20
+ };
21
+ history.pushState = injectLocationChangeEvent(originalPushState);
22
+ history.replaceState = injectLocationChangeEvent(originalReplaceState);
23
+ const updateURLState = () => {
24
+ setState(window.location.pathname);
25
+ };
26
+ window.addEventListener("locationchange", updateURLState);
27
+ window.addEventListener("popstate", updateURLState);
28
+ window.addEventListener("hashchange", updateURLState);
29
+ window.addEventListener("load", updateURLState);
30
+ updateURLState();
31
+ return () => {
32
+ window.removeEventListener("locationchange", updateURLState);
33
+ window.removeEventListener("popstate", updateURLState);
34
+ window.removeEventListener("hashchange", updateURLState);
35
+ window.removeEventListener("load", updateURLState);
36
+ history.pushState = originalPushState;
37
+ history.replaceState = originalReplaceState;
38
+ };
39
+ }, []);
40
+ return states;
41
+ };
42
+ export {
43
+ useCrossURLPathSetter,
44
+ useCrossURLPathState
45
+ };
46
+ //# sourceMappingURL=useCrossURLPathState.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/editor/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport {\n useCrossFrameState,\n type CrossFrameStateOptions,\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 const states = useCrossURLPathState(initialState, {\n emit: true,\n receive: false,\n });\n const [_state, setState] = states;\n\n useEffect(() => {\n /**\n * 1) Monkey patch history methods (pushState, replaceState)\n * to dispatch a custom event whenever they are called.\n */\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n\n const injectLocationChangeEvent = (method: (...args: any[]) => void) =>\n function (this: typeof history, ...args: [any, string, string?]) {\n method.apply(this, args);\n window.dispatchEvent(new Event('locationchange'));\n };\n\n history.pushState = injectLocationChangeEvent(originalPushState);\n history.replaceState = injectLocationChangeEvent(originalReplaceState);\n\n /**\n * 2) The callback to update our state whenever the URL changes.\n */\n const updateURLState = () => {\n setState(window.location.pathname);\n };\n\n /**\n * 3) Attach event listeners for locationchange, popstate, hashchange.\n * - 'locationchange' is our custom event triggered by push/replaceState overrides.\n * - 'popstate' is fired on back/forward navigation.\n * - 'hashchange' is for URL hash (#) changes.\n * - 'load' is when new page is loaded\n */\n window.addEventListener('locationchange', updateURLState);\n window.addEventListener('popstate', updateURLState);\n window.addEventListener('hashchange', updateURLState);\n window.addEventListener('load', updateURLState);\n\n // Initialize our state immediately on mount\n updateURLState();\n\n /**\n * 4) Cleanup when the component unmounts:\n * - Remove event listeners.\n * - Restore original pushState & replaceState to avoid side effects.\n */\n return () => {\n window.removeEventListener('locationchange', updateURLState);\n window.removeEventListener('popstate', updateURLState);\n window.removeEventListener('hashchange', updateURLState);\n window.removeEventListener('load', updateURLState);\n history.pushState = originalPushState;\n history.replaceState = originalReplaceState;\n };\n }, []);\n\n return states;\n};\n"],"mappings":";AAEA,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,OAEK;AAEA,MAAM,uBAAuB,CAClC,cACA,YACG,mBAAmB,WAAW,qBAAqB,cAAc,OAAO;AAEtE,MAAM,wBAAwB,CAAC,iBAA0B;AAC9D,QAAM,SAAS,qBAAqB,cAAc;AAAA,IAChD,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AACD,QAAM,CAAC,QAAQ,QAAQ,IAAI;AAE3B,YAAU,MAAM;AAKd,UAAM,oBAAoB,QAAQ;AAClC,UAAM,uBAAuB,QAAQ;AAErC,UAAM,4BAA4B,CAAC,WACjC,YAAmC,MAA8B;AAC/D,aAAO,MAAM,MAAM,IAAI;AACvB,aAAO,cAAc,IAAI,MAAM,gBAAgB,CAAC;AAAA,IAClD;AAEF,YAAQ,YAAY,0BAA0B,iBAAiB;AAC/D,YAAQ,eAAe,0BAA0B,oBAAoB;AAKrE,UAAM,iBAAiB,MAAM;AAC3B,eAAS,OAAO,SAAS,QAAQ;AAAA,IACnC;AASA,WAAO,iBAAiB,kBAAkB,cAAc;AACxD,WAAO,iBAAiB,YAAY,cAAc;AAClD,WAAO,iBAAiB,cAAc,cAAc;AACpD,WAAO,iBAAiB,QAAQ,cAAc;AAG9C,mBAAe;AAOf,WAAO,MAAM;AACX,aAAO,oBAAoB,kBAAkB,cAAc;AAC3D,aAAO,oBAAoB,YAAY,cAAc;AACrD,aAAO,oBAAoB,cAAc,cAAc;AACvD,aAAO,oBAAoB,QAAQ,cAAc;AACjD,cAAQ,YAAY;AACpB,cAAQ,eAAe;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ import { getContent } from "@intlayer/core";
3
+ import { useEditedContentActions } from "./EditedContentContext.mjs";
4
+ const useEditedContentRenderer = ({
5
+ dictionaryKey,
6
+ keyPath,
7
+ children
8
+ }) => {
9
+ const editedContentContext = useEditedContentActions();
10
+ if (editedContentContext) {
11
+ const editedValue = editedContentContext.getEditedContentValue(
12
+ dictionaryKey,
13
+ keyPath
14
+ );
15
+ const value = editedValue ?? children;
16
+ return value;
17
+ }
18
+ return children;
19
+ };
20
+ const EditedContentRenderer = (props) => {
21
+ const content = useEditedContentRenderer(props);
22
+ if (typeof content === "object") {
23
+ const transformedEditedContent = getContent(content, props, props.locale);
24
+ if (typeof transformedEditedContent !== "string") {
25
+ console.error(
26
+ `Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`
27
+ );
28
+ return props.children;
29
+ }
30
+ return transformedEditedContent;
31
+ }
32
+ return content;
33
+ };
34
+ export {
35
+ EditedContentRenderer,
36
+ useEditedContentRenderer
37
+ };
38
+ //# sourceMappingURL=useEditedContentRenderer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["'use client';\n\nimport { Locales } from '@intlayer/config/client';\nimport { getContent, type KeyPath } from '@intlayer/core';\nimport { FC } from 'preact/compat';\nimport { useEditedContentActions } from './EditedContentContext';\n\ntype EditedContentRendererProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n children: string;\n locale?: Locales;\n};\n\nexport const useEditedContentRenderer = ({\n dictionaryKey,\n keyPath,\n children,\n}: EditedContentRendererProps) => {\n const editedContentContext = useEditedContentActions();\n\n if (editedContentContext) {\n const editedValue = editedContentContext.getEditedContentValue(\n dictionaryKey,\n keyPath\n ) as string;\n\n const value = editedValue ?? children;\n\n return value;\n }\n\n return children;\n};\n\nexport const EditedContentRenderer: FC<EditedContentRendererProps> = (\n props\n) => {\n const content = useEditedContentRenderer(props);\n\n if (typeof content === 'object') {\n const transformedEditedContent = getContent(content, props, props.locale);\n\n if (typeof transformedEditedContent !== 'string') {\n console.error(\n `Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`\n );\n\n return props.children;\n }\n\n return transformedEditedContent;\n }\n\n return content;\n};\n"],"mappings":";AAGA,SAAS,kBAAgC;AAEzC,SAAS,+BAA+B;AASjC,MAAM,2BAA2B,CAAC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AACF,MAAkC;AAChC,QAAM,uBAAuB,wBAAwB;AAErD,MAAI,sBAAsB;AACxB,UAAM,cAAc,qBAAqB;AAAA,MACvC;AAAA,MACA;AAAA,IACF;AAEA,UAAM,QAAQ,eAAe;AAE7B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,wBAAwD,CACnE,UACG;AACH,QAAM,UAAU,yBAAyB,KAAK;AAE9C,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAM,2BAA2B,WAAW,SAAS,OAAO,MAAM,MAAM;AAExE,QAAI,OAAO,6BAA6B,UAAU;AAChD,cAAQ;AAAA,QACN,kDAAkD,OAAO,wBAAwB,4BAA4B,KAAK,UAAU,wBAAwB,CAAC;AAAA,MACvJ;AAEA,aAAO,MAAM;AAAA,IACf;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ import { MessageKey, mergeIframeClick } from "@intlayer/editor";
3
+ import { useEffect } from "preact/hooks";
4
+ import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs";
5
+ const useIframeClickInterceptor = () => {
6
+ const postMessage = useCrossFrameMessageListener(
7
+ MessageKey.INTLAYER_IFRAME_CLICKED
8
+ );
9
+ const handlePostMessageEvent = () => {
10
+ postMessage();
11
+ };
12
+ useEffect(() => {
13
+ window.addEventListener("mousedown", handlePostMessageEvent);
14
+ return () => window.removeEventListener("mousedown", handlePostMessageEvent);
15
+ }, [postMessage]);
16
+ };
17
+ const useIframeClickMerger = () => useCrossFrameMessageListener(
18
+ MessageKey.INTLAYER_IFRAME_CLICKED,
19
+ mergeIframeClick
20
+ );
21
+ export {
22
+ useIframeClickInterceptor,
23
+ useIframeClickMerger
24
+ };
25
+ //# sourceMappingURL=useIframeClickInterceptor.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/editor/useIframeClickInterceptor.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey, mergeIframeClick } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport const useIframeClickInterceptor = () => {\n const postMessage = useCrossFrameMessageListener<undefined>(\n MessageKey.INTLAYER_IFRAME_CLICKED\n );\n const handlePostMessageEvent: EventListener = () => {\n postMessage();\n };\n\n useEffect(() => {\n window.addEventListener('mousedown', handlePostMessageEvent);\n\n return () =>\n window.removeEventListener('mousedown', handlePostMessageEvent);\n }, [postMessage]);\n};\n\nexport const useIframeClickMerger = () =>\n useCrossFrameMessageListener<MessageEvent>(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick\n );\n"],"mappings":";AAEA,SAAS,YAAY,wBAAwB;AAC7C,SAAS,iBAAiB;AAC1B,SAAS,oCAAoC;AAEtC,MAAM,4BAA4B,MAAM;AAC7C,QAAM,cAAc;AAAA,IAClB,WAAW;AAAA,EACb;AACA,QAAM,yBAAwC,MAAM;AAClD,gBAAY;AAAA,EACd;AAEA,YAAU,MAAM;AACd,WAAO,iBAAiB,aAAa,sBAAsB;AAE3D,WAAO,MACL,OAAO,oBAAoB,aAAa,sBAAsB;AAAA,EAClE,GAAG,CAAC,WAAW,CAAC;AAClB;AAEO,MAAM,uBAAuB,MAClC;AAAA,EACE,WAAW;AAAA,EACX;AACF;","names":[]}
@@ -0,0 +1,25 @@
1
+ import {
2
+ getDictionary as getDictionaryCore
3
+ } from "@intlayer/core";
4
+ import {
5
+ intlayerNodePlugins,
6
+ markdownPlugin,
7
+ preactNodePlugins
8
+ } from "./plugins.mjs";
9
+ const getDictionary = (dictionary, locale, additionalPlugins) => {
10
+ const plugins = [
11
+ intlayerNodePlugins,
12
+ preactNodePlugins,
13
+ markdownPlugin,
14
+ ...additionalPlugins ?? []
15
+ ];
16
+ return getDictionaryCore(
17
+ dictionary,
18
+ locale,
19
+ plugins
20
+ );
21
+ };
22
+ export {
23
+ getDictionary
24
+ };
25
+ //# sourceMappingURL=getDictionary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport {\n type Dictionary,\n type Plugins,\n getDictionary as getDictionaryCore,\n} from '@intlayer/core';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n preactNodePlugins,\n} from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = Locales,\n>(\n dictionary: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n) => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n preactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n return getDictionaryCore(\n dictionary,\n locale,\n plugins\n ) as any as DeepTransformContent<T['content']>;\n};\n"],"mappings":"AACA;AAAA,EAGE,iBAAiB;AAAA,OACZ;AACP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM,gBAAgB,CAI3B,YACA,QACA,sBACG;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,qBAAqB,CAAC;AAAA,EAC5B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,21 @@
1
+ import {
2
+ getIntlayer as getIntlayerCore
3
+ } from "@intlayer/core";
4
+ import {
5
+ intlayerNodePlugins,
6
+ markdownPlugin,
7
+ preactNodePlugins
8
+ } from "./plugins.mjs";
9
+ const getIntlayer = (key, locale, additionalPlugins) => {
10
+ const plugins = [
11
+ intlayerNodePlugins,
12
+ preactNodePlugins,
13
+ markdownPlugin,
14
+ ...additionalPlugins ?? []
15
+ ];
16
+ return getIntlayerCore(key, locale, plugins);
17
+ };
18
+ export {
19
+ getIntlayer
20
+ };
21
+ //# sourceMappingURL=getIntlayer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import {\n type DictionaryKeys,\n type Plugins,\n getIntlayer as getIntlayerCore,\n} from '@intlayer/core';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector, LocalesValues } from 'intlayer';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n preactNodePlugins,\n} from './plugins';\n\nexport const getIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n) => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n preactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n return getIntlayerCore(key, locale, plugins) as any as DeepTransformContent<\n IntlayerDictionaryTypesConnector[T]['content']\n >;\n};\n"],"mappings":"AAAA;AAAA,EAGE,eAAe;AAAA,OACV;AAGP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM,cAAc,CACzB,KACA,QACA,sBACG;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,qBAAqB,CAAC;AAAA,EAC5B;AAEA,SAAO,gBAAgB,KAAK,QAAQ,OAAO;AAG7C;","names":[]}
@@ -1,3 +1,39 @@
1
- export * from "./intlayerPlugin.mjs";
2
- export * from "./intlayerMiddlewarePlugin.mjs";
1
+ import {
2
+ getBrowserLocale,
3
+ IntlayerClientContext,
4
+ IntlayerProvider,
5
+ IntlayerProviderContent,
6
+ localeCookie,
7
+ setLocaleCookie,
8
+ t,
9
+ useDictionary,
10
+ useDictionaryDynamic,
11
+ useIntlayer,
12
+ useIntlayerAsync,
13
+ useIntlayerContext,
14
+ useLoadDynamic,
15
+ useLocale,
16
+ useLocaleBase,
17
+ useLocaleCookie
18
+ } from "./client/index.mjs";
19
+ import { MarkdownProvider } from "./markdown/index.mjs";
20
+ export {
21
+ IntlayerClientContext,
22
+ IntlayerProvider,
23
+ IntlayerProviderContent,
24
+ MarkdownProvider,
25
+ getBrowserLocale,
26
+ localeCookie,
27
+ setLocaleCookie,
28
+ t,
29
+ useDictionary,
30
+ useDictionaryDynamic,
31
+ useIntlayer,
32
+ useIntlayerAsync,
33
+ useIntlayerContext,
34
+ useLoadDynamic,
35
+ useLocale,
36
+ useLocaleBase,
37
+ useLocaleCookie
38
+ };
3
39
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './intlayerPlugin';\nexport * from './intlayerMiddlewarePlugin';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import type { IInterpreterPluginPreact } from './plugins';\n\ndeclare module '@intlayer/core' {\n interface IInterpreterPlugin<T, S> extends IInterpreterPluginPreact<T> {}\n}\n\nexport {\n getBrowserLocale,\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n localeCookie,\n setLocaleCookie,\n t,\n useDictionary,\n useDictionaryDynamic,\n useIntlayer,\n useIntlayerAsync,\n useIntlayerContext,\n useLoadDynamic,\n useLocale,\n useLocaleBase,\n useLocaleCookie,\n type IntlayerProviderProps,\n} from './client/index';\nexport { type IntlayerNode } from './IntlayerNode';\nexport { MarkdownProvider } from './markdown/index';\n"],"mappings":"AAMA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,wBAAwB;","names":[]}
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { jsx } from "preact/jsx-runtime";
3
+ import {
4
+ createContext,
5
+ useContext
6
+ } from "preact/compat";
7
+ const MarkdownContext = createContext({
8
+ renderMarkdown: (markdown) => markdown
9
+ });
10
+ const useMarkdownContext = () => useContext(MarkdownContext);
11
+ const MarkdownProvider = ({
12
+ children,
13
+ renderMarkdown
14
+ }) => /* @__PURE__ */ jsx(MarkdownContext.Provider, { value: { renderMarkdown }, children });
15
+ export {
16
+ MarkdownProvider,
17
+ useMarkdownContext
18
+ };
19
+ //# sourceMappingURL=MarkdownProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/markdown/MarkdownProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n type ReactNode,\n} from 'preact/compat';\n\ntype MarkdownContextValue = {\n renderMarkdown: (markdown: string) => ReactNode;\n};\n\ntype MarkdownProviderProps = PropsWithChildren<MarkdownContextValue>;\n\nconst MarkdownContext = createContext<MarkdownContextValue>({\n renderMarkdown: (markdown: string) => markdown,\n});\n\nexport const useMarkdownContext = () => useContext(MarkdownContext);\n\nexport const MarkdownProvider: FC<MarkdownProviderProps> = ({\n children,\n renderMarkdown,\n}) => (\n <MarkdownContext.Provider value={{ renderMarkdown }}>\n {children}\n </MarkdownContext.Provider>\n);\n"],"mappings":";AA0BE;AAxBF;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAQP,MAAM,kBAAkB,cAAoC;AAAA,EAC1D,gBAAgB,CAAC,aAAqB;AACxC,CAAC;AAEM,MAAM,qBAAqB,MAAM,WAAW,eAAe;AAE3D,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AACF,MACE,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,EAAE,eAAe,GAC/C,UACH;","names":[]}