preact-intlayer 6.1.6 → 7.0.0-canary.2

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 (297) hide show
  1. package/dist/cjs/IntlayerNode.cjs +15 -45
  2. package/dist/cjs/IntlayerNode.cjs.map +1 -1
  3. package/dist/cjs/UI/ContentSelector.cjs +98 -130
  4. package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
  5. package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
  6. package/dist/cjs/client/IntlayerProvider.cjs +67 -95
  7. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
  8. package/dist/cjs/client/format/index.cjs +17 -50
  9. package/dist/cjs/client/format/useCompact.cjs +29 -39
  10. package/dist/cjs/client/format/useCompact.cjs.map +1 -1
  11. package/dist/cjs/client/format/useCurrency.cjs +43 -39
  12. package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
  13. package/dist/cjs/client/format/useDate.cjs +45 -36
  14. package/dist/cjs/client/format/useDate.cjs.map +1 -1
  15. package/dist/cjs/client/format/useList.cjs +40 -39
  16. package/dist/cjs/client/format/useList.cjs.map +1 -1
  17. package/dist/cjs/client/format/useNumber.cjs +41 -39
  18. package/dist/cjs/client/format/useNumber.cjs.map +1 -1
  19. package/dist/cjs/client/format/usePercentage.cjs +37 -39
  20. package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
  21. package/dist/cjs/client/format/useRelativeTime.cjs +37 -39
  22. package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
  23. package/dist/cjs/client/format/useUnit.cjs +36 -39
  24. package/dist/cjs/client/format/useUnit.cjs.map +1 -1
  25. package/dist/cjs/client/index.cjs +29 -69
  26. package/dist/cjs/client/t.cjs +21 -34
  27. package/dist/cjs/client/t.cjs.map +1 -1
  28. package/dist/cjs/client/useContent.cjs +16 -36
  29. package/dist/cjs/client/useContent.cjs.map +1 -1
  30. package/dist/cjs/client/useDictionary.cjs +26 -36
  31. package/dist/cjs/client/useDictionary.cjs.map +1 -1
  32. package/dist/cjs/client/useDictionaryAsync.cjs +23 -52
  33. package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
  34. package/dist/cjs/client/useDictionaryDynamic.cjs +22 -42
  35. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
  36. package/dist/cjs/client/useIntlayer.cjs +26 -36
  37. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  38. package/dist/cjs/client/useLoadDynamic.cjs +21 -50
  39. package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
  40. package/dist/cjs/client/useLocale.cjs +36 -67
  41. package/dist/cjs/client/useLocale.cjs.map +1 -1
  42. package/dist/cjs/client/useLocaleBase.cjs +25 -53
  43. package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
  44. package/dist/cjs/client/useLocaleStorage.cjs +60 -0
  45. package/dist/cjs/client/useLocaleStorage.cjs.map +1 -0
  46. package/dist/cjs/client/useTraduction.cjs +34 -35
  47. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  48. package/dist/cjs/editor/CommunicatorContext.cjs +40 -62
  49. package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -1
  50. package/dist/cjs/editor/ConfigurationContext.cjs +26 -47
  51. package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -1
  52. package/dist/cjs/editor/ContentSelectorWrapper.cjs +58 -94
  53. package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
  54. package/dist/cjs/editor/DictionariesRecordContext.cjs +47 -73
  55. package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -1
  56. package/dist/cjs/editor/EditedContentContext.cjs +160 -211
  57. package/dist/cjs/editor/EditedContentContext.cjs.map +1 -1
  58. package/dist/cjs/editor/EditorEnabledContext.cjs +34 -59
  59. package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -1
  60. package/dist/cjs/editor/EditorProvider.cjs +62 -66
  61. package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
  62. package/dist/cjs/editor/FocusDictionaryContext.cjs +51 -75
  63. package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -1
  64. package/dist/cjs/editor/IntlayerEditorProvider.cjs +45 -94
  65. package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
  66. package/dist/cjs/editor/index.cjs +3 -23
  67. package/dist/cjs/editor/useCrossFrameMessageListener.cjs +73 -50
  68. package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -1
  69. package/dist/cjs/editor/useCrossFrameState.cjs +106 -73
  70. package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -1
  71. package/dist/cjs/editor/useCrossURLPathState.cjs +67 -66
  72. package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -1
  73. package/dist/cjs/editor/useEditedContentRenderer.cjs +27 -59
  74. package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
  75. package/dist/cjs/editor/useIframeClickInterceptor.cjs +24 -47
  76. package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -1
  77. package/dist/cjs/getDictionary.cjs +15 -40
  78. package/dist/cjs/getDictionary.cjs.map +1 -1
  79. package/dist/cjs/getIntlayer.cjs +15 -36
  80. package/dist/cjs/getIntlayer.cjs.map +1 -1
  81. package/dist/cjs/index.cjs +30 -62
  82. package/dist/cjs/markdown/MarkdownProvider.cjs +19 -39
  83. package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
  84. package/dist/cjs/markdown/MarkdownRenderer.cjs +39 -80
  85. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
  86. package/dist/cjs/markdown/index.cjs +7 -25
  87. package/dist/cjs/plugins.cjs +97 -119
  88. package/dist/cjs/plugins.cjs.map +1 -1
  89. package/dist/cjs/preactElement/renderPreactElement.cjs +34 -59
  90. package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
  91. package/dist/esm/IntlayerNode.mjs +13 -25
  92. package/dist/esm/IntlayerNode.mjs.map +1 -1
  93. package/dist/esm/UI/ContentSelector.mjs +94 -105
  94. package/dist/esm/UI/ContentSelector.mjs.map +1 -1
  95. package/dist/esm/client/IntlayerProvider.mjs +51 -54
  96. package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
  97. package/dist/esm/client/format/index.mjs +2 -11
  98. package/dist/esm/client/format/useCompact.mjs +24 -13
  99. package/dist/esm/client/format/useCompact.mjs.map +1 -1
  100. package/dist/esm/client/format/useCurrency.mjs +38 -13
  101. package/dist/esm/client/format/useCurrency.mjs.map +1 -1
  102. package/dist/esm/client/format/useDate.mjs +40 -10
  103. package/dist/esm/client/format/useDate.mjs.map +1 -1
  104. package/dist/esm/client/format/useList.mjs +35 -13
  105. package/dist/esm/client/format/useList.mjs.map +1 -1
  106. package/dist/esm/client/format/useNumber.mjs +36 -13
  107. package/dist/esm/client/format/useNumber.mjs.map +1 -1
  108. package/dist/esm/client/format/usePercentage.mjs +32 -13
  109. package/dist/esm/client/format/usePercentage.mjs.map +1 -1
  110. package/dist/esm/client/format/useRelativeTime.mjs +32 -13
  111. package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
  112. package/dist/esm/client/format/useUnit.mjs +31 -13
  113. package/dist/esm/client/format/useUnit.mjs.map +1 -1
  114. package/dist/esm/client/index.mjs +5 -32
  115. package/dist/esm/client/t.mjs +16 -8
  116. package/dist/esm/client/t.mjs.map +1 -1
  117. package/dist/esm/client/useContent.mjs +14 -10
  118. package/dist/esm/client/useContent.mjs.map +1 -1
  119. package/dist/esm/client/useDictionary.mjs +23 -11
  120. package/dist/esm/client/useDictionary.mjs.map +1 -1
  121. package/dist/esm/client/useDictionaryAsync.mjs +18 -16
  122. package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
  123. package/dist/esm/client/useDictionaryDynamic.mjs +17 -15
  124. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
  125. package/dist/esm/client/useIntlayer.mjs +23 -11
  126. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  127. package/dist/esm/client/useLoadDynamic.mjs +20 -26
  128. package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
  129. package/dist/esm/client/useLocale.mjs +31 -31
  130. package/dist/esm/client/useLocale.mjs.map +1 -1
  131. package/dist/esm/client/useLocaleBase.mjs +19 -16
  132. package/dist/esm/client/useLocaleBase.mjs.map +1 -1
  133. package/dist/esm/client/useLocaleStorage.mjs +52 -0
  134. package/dist/esm/client/useLocaleStorage.mjs.map +1 -0
  135. package/dist/esm/client/useTraduction.mjs +29 -9
  136. package/dist/esm/client/useTraduction.mjs.map +1 -1
  137. package/dist/esm/editor/CommunicatorContext.mjs +28 -24
  138. package/dist/esm/editor/CommunicatorContext.mjs.map +1 -1
  139. package/dist/esm/editor/ConfigurationContext.mjs +20 -24
  140. package/dist/esm/editor/ConfigurationContext.mjs.map +1 -1
  141. package/dist/esm/editor/ContentSelectorWrapper.mjs +50 -70
  142. package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
  143. package/dist/esm/editor/DictionariesRecordContext.mjs +37 -47
  144. package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -1
  145. package/dist/esm/editor/EditedContentContext.mjs +146 -187
  146. package/dist/esm/editor/EditedContentContext.mjs.map +1 -1
  147. package/dist/esm/editor/EditorEnabledContext.mjs +23 -33
  148. package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -1
  149. package/dist/esm/editor/EditorProvider.mjs +57 -54
  150. package/dist/esm/editor/EditorProvider.mjs.map +1 -1
  151. package/dist/esm/editor/FocusDictionaryContext.mjs +42 -49
  152. package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -1
  153. package/dist/esm/editor/IntlayerEditorProvider.mjs +37 -55
  154. package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
  155. package/dist/esm/editor/index.mjs +3 -2
  156. package/dist/esm/editor/useCrossFrameMessageListener.mjs +68 -24
  157. package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -1
  158. package/dist/esm/editor/useCrossFrameState.mjs +102 -47
  159. package/dist/esm/editor/useCrossFrameState.mjs.map +1 -1
  160. package/dist/esm/editor/useCrossURLPathState.mjs +60 -40
  161. package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -1
  162. package/dist/esm/editor/useEditedContentRenderer.mjs +23 -33
  163. package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
  164. package/dist/esm/editor/useIframeClickInterceptor.mjs +18 -20
  165. package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -1
  166. package/dist/esm/getDictionary.mjs +13 -22
  167. package/dist/esm/getDictionary.mjs.map +1 -1
  168. package/dist/esm/getIntlayer.mjs +13 -18
  169. package/dist/esm/getIntlayer.mjs.map +1 -1
  170. package/dist/esm/index.mjs +13 -39
  171. package/dist/esm/markdown/MarkdownProvider.mjs +14 -16
  172. package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
  173. package/dist/esm/markdown/MarkdownRenderer.mjs +34 -57
  174. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
  175. package/dist/esm/markdown/index.mjs +4 -3
  176. package/dist/esm/plugins.mjs +86 -92
  177. package/dist/esm/plugins.mjs.map +1 -1
  178. package/dist/esm/preactElement/renderPreactElement.mjs +31 -34
  179. package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -1
  180. package/dist/types/IntlayerNode.d.ts +19 -12
  181. package/dist/types/IntlayerNode.d.ts.map +1 -1
  182. package/dist/types/UI/ContentSelector.d.ts +12 -9
  183. package/dist/types/UI/ContentSelector.d.ts.map +1 -1
  184. package/dist/types/client/IntlayerProvider.d.ts +22 -16
  185. package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
  186. package/dist/types/client/format/index.d.ts +9 -9
  187. package/dist/types/client/format/useCompact.d.ts +8 -2
  188. package/dist/types/client/format/useCompact.d.ts.map +1 -1
  189. package/dist/types/client/format/useCurrency.d.ts +8 -2
  190. package/dist/types/client/format/useCurrency.d.ts.map +1 -1
  191. package/dist/types/client/format/useDate.d.ts +7 -2
  192. package/dist/types/client/format/useDate.d.ts.map +1 -1
  193. package/dist/types/client/format/useList.d.ts +8 -2
  194. package/dist/types/client/format/useList.d.ts.map +1 -1
  195. package/dist/types/client/format/useNumber.d.ts +8 -2
  196. package/dist/types/client/format/useNumber.d.ts.map +1 -1
  197. package/dist/types/client/format/usePercentage.d.ts +8 -2
  198. package/dist/types/client/format/usePercentage.d.ts.map +1 -1
  199. package/dist/types/client/format/useRelativeTime.d.ts +9 -3
  200. package/dist/types/client/format/useRelativeTime.d.ts.map +1 -1
  201. package/dist/types/client/format/useUnit.d.ts +8 -2
  202. package/dist/types/client/format/useUnit.d.ts.map +1 -1
  203. package/dist/types/client/index.d.ts +11 -12
  204. package/dist/types/client/t.d.ts +7 -3
  205. package/dist/types/client/t.d.ts.map +1 -1
  206. package/dist/types/client/useContent.d.ts +10 -5
  207. package/dist/types/client/useContent.d.ts.map +1 -1
  208. package/dist/types/client/useDictionary.d.ts +9 -3
  209. package/dist/types/client/useDictionary.d.ts.map +1 -1
  210. package/dist/types/client/useDictionaryAsync.d.ts +7 -3
  211. package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
  212. package/dist/types/client/useDictionaryDynamic.d.ts +9 -3
  213. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
  214. package/dist/types/client/useIntlayer.d.ts +8 -5
  215. package/dist/types/client/useIntlayer.d.ts.map +1 -1
  216. package/dist/types/client/useLoadDynamic.d.ts +4 -1
  217. package/dist/types/client/useLoadDynamic.d.ts.map +1 -1
  218. package/dist/types/client/useLocale.d.ts +16 -8
  219. package/dist/types/client/useLocale.d.ts.map +1 -1
  220. package/dist/types/client/useLocaleBase.d.ts +10 -5
  221. package/dist/types/client/useLocaleBase.d.ts.map +1 -1
  222. package/dist/types/client/useLocaleStorage.d.ts +45 -0
  223. package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
  224. package/dist/types/client/useTraduction.d.ts +7 -2
  225. package/dist/types/client/useTraduction.d.ts.map +1 -1
  226. package/dist/types/editor/CommunicatorContext.d.ts +15 -11
  227. package/dist/types/editor/CommunicatorContext.d.ts.map +1 -1
  228. package/dist/types/editor/ConfigurationContext.d.ts +12 -7
  229. package/dist/types/editor/ConfigurationContext.d.ts.map +1 -1
  230. package/dist/types/editor/ContentSelectorWrapper.d.ts +8 -4
  231. package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
  232. package/dist/types/editor/DictionariesRecordContext.d.ts +15 -12
  233. package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -1
  234. package/dist/types/editor/EditedContentContext.d.ts +32 -29
  235. package/dist/types/editor/EditedContentContext.d.ts.map +1 -1
  236. package/dist/types/editor/EditorEnabledContext.d.ts +14 -9
  237. package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -1
  238. package/dist/types/editor/EditorProvider.d.ts +9 -5
  239. package/dist/types/editor/EditorProvider.d.ts.map +1 -1
  240. package/dist/types/editor/FocusDictionaryContext.d.ts +18 -15
  241. package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -1
  242. package/dist/types/editor/IntlayerEditorProvider.d.ts +7 -3
  243. package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
  244. package/dist/types/editor/index.d.ts +2 -2
  245. package/dist/types/editor/useCrossFrameMessageListener.d.ts +7 -2
  246. package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -1
  247. package/dist/types/editor/useCrossFrameState.d.ts +11 -7
  248. package/dist/types/editor/useCrossFrameState.d.ts.map +1 -1
  249. package/dist/types/editor/useCrossURLPathState.d.ts +8 -3
  250. package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -1
  251. package/dist/types/editor/useEditedContentRenderer.d.ts +16 -10
  252. package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -1
  253. package/dist/types/editor/useIframeClickInterceptor.d.ts +5 -2
  254. package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -1
  255. package/dist/types/getDictionary.d.ts +8 -4
  256. package/dist/types/getDictionary.d.ts.map +1 -1
  257. package/dist/types/getIntlayer.d.ts +8 -4
  258. package/dist/types/getIntlayer.d.ts.map +1 -1
  259. package/dist/types/index.d.ts +18 -6
  260. package/dist/types/index.d.ts.map +1 -1
  261. package/dist/types/markdown/MarkdownProvider.d.ts +8 -5
  262. package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -1
  263. package/dist/types/markdown/MarkdownRenderer.d.ts +13 -11
  264. package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
  265. package/dist/types/markdown/index.d.ts +3 -3
  266. package/dist/types/plugins.d.ts +33 -27
  267. package/dist/types/plugins.d.ts.map +1 -1
  268. package/dist/types/preactElement/renderPreactElement.d.ts +7 -3
  269. package/dist/types/preactElement/renderPreactElement.d.ts.map +1 -1
  270. package/package.json +40 -46
  271. package/LICENSE +0 -202
  272. package/dist/cjs/client/format/index.cjs.map +0 -1
  273. package/dist/cjs/client/getBrowserLocale.cjs +0 -173
  274. package/dist/cjs/client/getBrowserLocale.cjs.map +0 -1
  275. package/dist/cjs/client/index.cjs.map +0 -1
  276. package/dist/cjs/client/useLocaleCookie.cjs +0 -60
  277. package/dist/cjs/client/useLocaleCookie.cjs.map +0 -1
  278. package/dist/cjs/editor/index.cjs.map +0 -1
  279. package/dist/cjs/index.cjs.map +0 -1
  280. package/dist/cjs/markdown/index.cjs.map +0 -1
  281. package/dist/esm/client/format/index.mjs.map +0 -1
  282. package/dist/esm/client/getBrowserLocale.mjs +0 -138
  283. package/dist/esm/client/getBrowserLocale.mjs.map +0 -1
  284. package/dist/esm/client/index.mjs.map +0 -1
  285. package/dist/esm/client/useLocaleCookie.mjs +0 -24
  286. package/dist/esm/client/useLocaleCookie.mjs.map +0 -1
  287. package/dist/esm/editor/index.mjs.map +0 -1
  288. package/dist/esm/index.mjs.map +0 -1
  289. package/dist/esm/markdown/index.mjs.map +0 -1
  290. package/dist/types/client/format/index.d.ts.map +0 -1
  291. package/dist/types/client/getBrowserLocale.d.ts +0 -25
  292. package/dist/types/client/getBrowserLocale.d.ts.map +0 -1
  293. package/dist/types/client/index.d.ts.map +0 -1
  294. package/dist/types/client/useLocaleCookie.d.ts +0 -17
  295. package/dist/types/client/useLocaleCookie.d.ts.map +0 -1
  296. package/dist/types/editor/index.d.ts.map +0 -1
  297. package/dist/types/markdown/index.d.ts.map +0 -1
@@ -1,55 +1,45 @@
1
- "use client";
2
- import { jsx } from "preact/jsx-runtime";
3
- import { MessageKey } from "@intlayer/editor";
4
- import {
5
- createContext,
6
- useContext,
7
- useMemo
8
- } from "preact/compat";
1
+ 'use client';
2
+
3
+
9
4
  import { useCrossFrameState } from "./useCrossFrameState.mjs";
5
+ import { MessageKey } from "@intlayer/editor";
6
+ import { createContext, useContext, useMemo } from "preact/compat";
7
+ import { jsx } from "preact/jsx-runtime";
8
+
9
+ //#region src/editor/DictionariesRecordContext.tsx
10
10
  const DictionariesRecordStatesContext = createContext(void 0);
11
11
  const DictionariesRecordActionsContext = createContext(void 0);
12
- const DictionariesRecordProvider = ({
13
- children
14
- }) => {
15
- const [localeDictionaries, setLocaleDictionaries] = useCrossFrameState(
16
- MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,
17
- void 0
18
- );
19
- const stateValue = useMemo(
20
- () => ({
21
- localeDictionaries: localeDictionaries ?? {}
22
- }),
23
- [localeDictionaries]
24
- );
25
- const actionValue = useMemo(
26
- () => ({
27
- setLocaleDictionaries,
28
- setLocaleDictionary: (dictionary) => {
29
- setLocaleDictionaries((dictionaries) => ({
30
- ...dictionaries,
31
- [dictionary.localId]: dictionary
32
- }));
33
- }
34
- }),
35
- [setLocaleDictionaries]
36
- );
37
- return /* @__PURE__ */ jsx(DictionariesRecordStatesContext.Provider, { value: stateValue, children: /* @__PURE__ */ jsx(DictionariesRecordActionsContext.Provider, { value: actionValue, children }) });
12
+ const DictionariesRecordProvider = ({ children }) => {
13
+ const [localeDictionaries, setLocaleDictionaries] = useCrossFrameState(MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED, void 0);
14
+ const stateValue = useMemo(() => ({ localeDictionaries: localeDictionaries ?? {} }), [localeDictionaries]);
15
+ const actionValue = useMemo(() => ({
16
+ setLocaleDictionaries,
17
+ setLocaleDictionary: (dictionary) => {
18
+ setLocaleDictionaries((dictionaries) => ({
19
+ ...dictionaries,
20
+ [String(dictionary.localId)]: dictionary
21
+ }));
22
+ }
23
+ }), [setLocaleDictionaries]);
24
+ return /* @__PURE__ */ jsx(DictionariesRecordStatesContext.Provider, {
25
+ value: stateValue,
26
+ children: /* @__PURE__ */ jsx(DictionariesRecordActionsContext.Provider, {
27
+ value: actionValue,
28
+ children
29
+ })
30
+ });
38
31
  };
39
32
  const useDictionariesRecordActions = () => useContext(DictionariesRecordActionsContext);
40
33
  const useDictionariesRecord = () => {
41
- const actionsContext = useDictionariesRecordActions();
42
- const statesContext = useContext(DictionariesRecordStatesContext);
43
- if (!statesContext) {
44
- throw new Error(
45
- "useDictionariesRecordStates must be used within a DictionariesRecordProvider"
46
- );
47
- }
48
- return { ...statesContext, ...actionsContext };
49
- };
50
- export {
51
- DictionariesRecordProvider,
52
- useDictionariesRecord,
53
- useDictionariesRecordActions
34
+ const actionsContext = useDictionariesRecordActions();
35
+ const statesContext = useContext(DictionariesRecordStatesContext);
36
+ if (!statesContext) throw new Error("useDictionariesRecordStates must be used within a DictionariesRecordProvider");
37
+ return {
38
+ ...statesContext,
39
+ ...actionsContext
40
+ };
54
41
  };
42
+
43
+ //#endregion
44
+ export { DictionariesRecordProvider, useDictionariesRecord, useDictionariesRecordActions };
55
45
  //# sourceMappingURL=DictionariesRecordContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n useMemo,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: Dispatch<SetStateAction<DictionaryContent>>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [dictionary.localId]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":";AA+DM;AA5DN,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AAYnC,MAAM,kCAAkC,cAEtC,MAAS;AACX,MAAM,mCAAmC,cAEvC,MAAS;AAEJ,MAAM,6BAAoD,CAAC;AAAA,EAChE;AACF,MAAM;AACJ,QAAM,CAAC,oBAAoB,qBAAqB,IAC9C;AAAA,IACE,WAAW;AAAA,IACX;AAAA,EACF;AAEF,QAAM,aAAa;AAAA,IACjB,OAAO;AAAA,MACL,oBAAoB,sBAAsB,CAAC;AAAA,IAC7C;AAAA,IACA,CAAC,kBAAkB;AAAA,EACrB;AAEA,QAAM,cAAc;AAAA,IAClB,OAAO;AAAA,MACL;AAAA,MACA,qBAAqB,CAAC,eAA2B;AAC/C,8BAAsB,CAAC,kBAAkB;AAAA,UACvC,GAAG;AAAA,UACH,CAAC,WAAW,OAAO,GAAG;AAAA,QACxB,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,IACA,CAAC,qBAAqB;AAAA,EACxB;AAEA,SACE,oBAAC,gCAAgC,UAAhC,EAAyC,OAAO,YAC/C,8BAAC,iCAAiC,UAAjC,EAA0C,OAAO,aAC/C,UACH,GACF;AAEJ;AAEO,MAAM,+BAA+B,MAC1C,WAAW,gCAAgC;AAEtC,MAAM,wBAAwB,MAAM;AACzC,QAAM,iBAAiB,6BAA6B;AACpD,QAAM,gBAAgB,WAAW,+BAA+B;AAEhE,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,eAAe,GAAG,eAAe;AAC/C;","names":[]}
1
+ {"version":3,"file":"DictionariesRecordContext.mjs","names":["DictionariesRecordProvider: FC<PropsWithChildren>"],"sources":["../../../src/editor/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n useMemo,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: Dispatch<SetStateAction<DictionaryContent>>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [String(dictionary.localId)]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":";;;;;;;;;AAyBA,MAAM,kCAAkC,cAEtC,OAAU;AACZ,MAAM,mCAAmC,cAEvC,OAAU;AAEZ,MAAaA,8BAAqD,EAChE,eACI;CACJ,MAAM,CAAC,oBAAoB,yBACzB,mBACE,WAAW,sCACX,OACD;CAEH,MAAM,aAAa,eACV,EACL,oBAAoB,sBAAsB,EAAE,EAC7C,GACD,CAAC,mBAAmB,CACrB;CAED,MAAM,cAAc,eACX;EACL;EACA,sBAAsB,eAA2B;AAC/C,0BAAuB,kBAAkB;IACvC,GAAG;KACF,OAAO,WAAW,QAAQ,GAAG;IAC/B,EAAE;;EAEN,GACD,CAAC,sBAAsB,CACxB;AAED,QACE,oBAAC,gCAAgC;EAAS,OAAO;YAC/C,oBAAC,iCAAiC;GAAS,OAAO;GAC/C;IACyC;GACH;;AAI/C,MAAa,qCACX,WAAW,iCAAiC;AAE9C,MAAa,8BAA8B;CACzC,MAAM,iBAAiB,8BAA8B;CACrD,MAAM,gBAAgB,WAAW,gCAAgC;AAEjE,KAAI,CAAC,cACH,OAAM,IAAI,MACR,+EACD;AAGH,QAAO;EAAE,GAAG;EAAe,GAAG;EAAgB"}
@@ -1,198 +1,157 @@
1
- "use client";
2
- import { jsx } from "preact/jsx-runtime";
3
- import {
4
- editDictionaryByKeyPath,
5
- getContentNodeByKeyPath,
6
- renameContentNodeByKeyPath
7
- } from "@intlayer/core";
8
- import { MessageKey } from "@intlayer/editor";
9
- import {
10
- createContext,
11
- useContext
12
- } from "preact/compat";
13
- import {
14
- useDictionariesRecord
15
- } from "./DictionariesRecordContext.mjs";
1
+ 'use client';
2
+
3
+
16
4
  import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs";
17
5
  import { useCrossFrameState } from "./useCrossFrameState.mjs";
6
+ import { useDictionariesRecord } from "./DictionariesRecordContext.mjs";
7
+ import { editDictionaryByKeyPath, getContentNodeByKeyPath, renameContentNodeByKeyPath } from "@intlayer/core";
8
+ import { MessageKey } from "@intlayer/editor";
9
+ import { createContext, useContext } from "preact/compat";
10
+ import { jsx } from "preact/jsx-runtime";
11
+
12
+ //#region src/editor/EditedContentContext.tsx
18
13
  const EditedContentStateContext = createContext(void 0);
19
- const usePostEditedContentState = (onEventTriggered) => useCrossFrameMessageListener(
20
- `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,
21
- onEventTriggered
22
- );
23
- const useGetEditedContentState = (onEventTriggered) => useCrossFrameMessageListener(
24
- `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,
25
- onEventTriggered
26
- );
14
+ const usePostEditedContentState = (onEventTriggered) => useCrossFrameMessageListener(`${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`, onEventTriggered);
15
+ const useGetEditedContentState = (onEventTriggered) => useCrossFrameMessageListener(`${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`, onEventTriggered);
27
16
  const EditedContentActionsContext = createContext(void 0);
28
17
  const resolveState = (state, prevState) => typeof state === "function" ? state(prevState) : state;
29
18
  const EditedContentProvider = ({ children }) => {
30
- const { localeDictionaries } = useDictionariesRecord();
31
- const [editedContent, setEditedContentState] = useCrossFrameState(
32
- MessageKey.INTLAYER_EDITED_CONTENT_CHANGED
33
- );
34
- const setEditedDictionary = (newValue) => {
35
- let updatedDictionaries = resolveState(newValue);
36
- setEditedContentState((prev) => {
37
- updatedDictionaries = resolveState(
38
- newValue,
39
- prev?.[updatedDictionaries.key]
40
- );
41
- return {
42
- ...prev,
43
- [updatedDictionaries.key]: updatedDictionaries
44
- };
45
- });
46
- return updatedDictionaries;
47
- };
48
- const setEditedContent = (dictionaryKey, newValue) => {
49
- setEditedContentState((prev) => ({
50
- ...prev,
51
- [dictionaryKey]: {
52
- ...prev?.[dictionaryKey],
53
- content: newValue
54
- }
55
- }));
56
- };
57
- const addEditedContent = (dictionaryKey, newValue, keyPath = [], overwrite = true) => {
58
- setEditedContentState((prev) => {
59
- const originalContent = localeDictionaries[dictionaryKey]?.content;
60
- const currentContent = structuredClone(
61
- prev?.[dictionaryKey]?.content ?? originalContent
62
- );
63
- let newKeyPath = keyPath;
64
- if (!overwrite) {
65
- let index = 0;
66
- const otherKeyPath = keyPath.slice(0, -1);
67
- const lastKeyPath = keyPath[keyPath.length - 1];
68
- let finalKey = lastKeyPath.key;
69
- while (typeof getContentNodeByKeyPath(currentContent, newKeyPath) !== "undefined") {
70
- index++;
71
- finalKey = index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;
72
- newKeyPath = [
73
- ...otherKeyPath,
74
- { ...lastKeyPath, key: finalKey }
75
- ];
76
- }
77
- }
78
- const updatedContent = editDictionaryByKeyPath(
79
- currentContent,
80
- newKeyPath,
81
- newValue
82
- );
83
- return {
84
- ...prev,
85
- [dictionaryKey]: {
86
- ...prev?.[dictionaryKey],
87
- content: updatedContent
88
- }
89
- };
90
- });
91
- };
92
- const renameEditedContent = (dictionaryKey, newKey, keyPath = []) => {
93
- setEditedContentState((prev) => {
94
- const originalContent = localeDictionaries[dictionaryKey]?.content;
95
- const currentContent = structuredClone(
96
- prev?.[dictionaryKey]?.content ?? originalContent
97
- );
98
- const contentWithNewField = renameContentNodeByKeyPath(
99
- currentContent,
100
- newKey,
101
- keyPath
102
- );
103
- return {
104
- ...prev,
105
- [dictionaryKey]: {
106
- ...prev?.[dictionaryKey],
107
- content: contentWithNewField
108
- }
109
- };
110
- });
111
- };
112
- const removeEditedContent = (dictionaryKey, keyPath) => {
113
- setEditedContentState((prev) => {
114
- const originalContent = localeDictionaries[dictionaryKey]?.content;
115
- const currentContent = structuredClone(
116
- prev?.[dictionaryKey]?.content ?? originalContent
117
- );
118
- const initialContent = getContentNodeByKeyPath(originalContent, keyPath);
119
- const restoredContent = editDictionaryByKeyPath(
120
- currentContent,
121
- keyPath,
122
- initialContent
123
- );
124
- return {
125
- ...prev,
126
- [dictionaryKey]: {
127
- ...prev?.[dictionaryKey],
128
- content: restoredContent
129
- }
130
- };
131
- });
132
- };
133
- const restoreEditedContent = (dictionaryKey) => {
134
- setEditedContentState((prev) => {
135
- const updated = { ...prev };
136
- delete updated[dictionaryKey];
137
- return updated;
138
- });
139
- };
140
- const clearEditedDictionaryContent = (dictionaryKey) => {
141
- setEditedContentState((prev) => {
142
- const filtered = Object.entries(prev).reduce((acc, [key, value]) => {
143
- if (key === dictionaryKey) {
144
- return acc;
145
- }
146
- return { ...acc, [key]: value };
147
- }, {});
148
- return filtered;
149
- });
150
- };
151
- const clearEditedContent = () => {
152
- setEditedContentState({});
153
- };
154
- const getEditedContentValue = (dictionaryKey, keyPath) => {
155
- const currentContent = editedContent?.[dictionaryKey]?.content ?? {};
156
- return getContentNodeByKeyPath(currentContent, keyPath);
157
- };
158
- return /* @__PURE__ */ jsx(
159
- EditedContentStateContext.Provider,
160
- {
161
- value: {
162
- editedContent
163
- },
164
- children: /* @__PURE__ */ jsx(
165
- EditedContentActionsContext.Provider,
166
- {
167
- value: {
168
- setEditedContentState,
169
- setEditedDictionary,
170
- setEditedContent,
171
- addEditedContent,
172
- renameEditedContent,
173
- removeEditedContent,
174
- restoreEditedContent,
175
- clearEditedDictionaryContent,
176
- clearEditedContent,
177
- getEditedContentValue
178
- },
179
- children
180
- }
181
- )
182
- }
183
- );
19
+ const { localeDictionaries } = useDictionariesRecord();
20
+ const [editedContent, setEditedContentState] = useCrossFrameState(MessageKey.INTLAYER_EDITED_CONTENT_CHANGED);
21
+ const setEditedDictionary = (newValue) => {
22
+ let updatedDictionaries = resolveState(newValue);
23
+ setEditedContentState((prev) => {
24
+ updatedDictionaries = resolveState(newValue, prev?.[updatedDictionaries.key]);
25
+ return {
26
+ ...prev,
27
+ [updatedDictionaries.key]: updatedDictionaries
28
+ };
29
+ });
30
+ return updatedDictionaries;
31
+ };
32
+ const setEditedContent = (dictionaryLocalId, newValue) => {
33
+ setEditedContentState((prev) => ({
34
+ ...prev,
35
+ [dictionaryLocalId]: {
36
+ ...prev?.[dictionaryLocalId],
37
+ content: newValue
38
+ }
39
+ }));
40
+ };
41
+ const addEditedContent = (dictionaryLocalId, newValue, keyPath = [], overwrite = true) => {
42
+ setEditedContentState((prev) => {
43
+ const originalContent = localeDictionaries[dictionaryLocalId]?.content;
44
+ const currentContent = structuredClone(prev?.[dictionaryLocalId]?.content ?? originalContent);
45
+ let newKeyPath = keyPath;
46
+ if (!overwrite) {
47
+ let index = 0;
48
+ const otherKeyPath = keyPath.slice(0, -1);
49
+ const lastKeyPath = keyPath[keyPath.length - 1];
50
+ let finalKey = lastKeyPath.key;
51
+ while (typeof getContentNodeByKeyPath(currentContent, newKeyPath) !== "undefined") {
52
+ index++;
53
+ finalKey = index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;
54
+ newKeyPath = [...otherKeyPath, {
55
+ ...lastKeyPath,
56
+ key: finalKey
57
+ }];
58
+ }
59
+ }
60
+ const updatedContent = editDictionaryByKeyPath(currentContent, newKeyPath, newValue);
61
+ return {
62
+ ...prev,
63
+ [dictionaryLocalId]: {
64
+ ...prev?.[dictionaryLocalId],
65
+ content: updatedContent
66
+ }
67
+ };
68
+ });
69
+ };
70
+ const renameEditedContent = (dictionaryLocalId, newKey, keyPath = []) => {
71
+ setEditedContentState((prev) => {
72
+ const originalContent = localeDictionaries[dictionaryLocalId]?.content;
73
+ const contentWithNewField = renameContentNodeByKeyPath(structuredClone(prev?.[dictionaryLocalId]?.content ?? originalContent), newKey, keyPath);
74
+ return {
75
+ ...prev,
76
+ [dictionaryLocalId]: {
77
+ ...prev?.[dictionaryLocalId],
78
+ content: contentWithNewField
79
+ }
80
+ };
81
+ });
82
+ };
83
+ const removeEditedContent = (dictionaryLocalId, keyPath) => {
84
+ setEditedContentState((prev) => {
85
+ const originalContent = localeDictionaries[dictionaryLocalId]?.content;
86
+ const restoredContent = editDictionaryByKeyPath(structuredClone(prev?.[dictionaryLocalId]?.content ?? originalContent), keyPath, getContentNodeByKeyPath(originalContent, keyPath));
87
+ return {
88
+ ...prev,
89
+ [dictionaryLocalId]: {
90
+ ...prev?.[dictionaryLocalId],
91
+ content: restoredContent
92
+ }
93
+ };
94
+ });
95
+ };
96
+ const restoreEditedContent = (dictionaryLocalId) => {
97
+ setEditedContentState((prev) => {
98
+ const updated = { ...prev };
99
+ delete updated[dictionaryLocalId];
100
+ return updated;
101
+ });
102
+ };
103
+ const clearEditedDictionaryContent = (dictionaryLocalId) => {
104
+ setEditedContentState((prev) => {
105
+ return Object.entries(prev).reduce((acc, [key, value]) => {
106
+ if (key === dictionaryLocalId) return acc;
107
+ return {
108
+ ...acc,
109
+ [key]: value
110
+ };
111
+ }, {});
112
+ });
113
+ };
114
+ const clearEditedContent = () => {
115
+ setEditedContentState({});
116
+ };
117
+ const getEditedContentValue = (localDictionaryIdOrKey, keyPath) => {
118
+ if (!editedContent) return void 0;
119
+ if (localDictionaryIdOrKey.includes(":local:") || localDictionaryIdOrKey.includes(":remote:")) return getContentNodeByKeyPath(editedContent?.[localDictionaryIdOrKey]?.content ?? {}, keyPath);
120
+ const filteredDictionariesLocalId = Object.keys(editedContent).filter((key) => key.startsWith(`${localDictionaryIdOrKey}:`));
121
+ for (const localDictionaryId of filteredDictionariesLocalId) {
122
+ const contentNode = getContentNodeByKeyPath(editedContent?.[localDictionaryId]?.content ?? {}, keyPath);
123
+ if (contentNode) return contentNode;
124
+ }
125
+ };
126
+ return /* @__PURE__ */ jsx(EditedContentStateContext.Provider, {
127
+ value: { editedContent },
128
+ children: /* @__PURE__ */ jsx(EditedContentActionsContext.Provider, {
129
+ value: {
130
+ setEditedContentState,
131
+ setEditedDictionary,
132
+ setEditedContent,
133
+ addEditedContent,
134
+ renameEditedContent,
135
+ removeEditedContent,
136
+ restoreEditedContent,
137
+ clearEditedDictionaryContent,
138
+ clearEditedContent,
139
+ getEditedContentValue
140
+ },
141
+ children
142
+ })
143
+ });
184
144
  };
185
145
  const useEditedContentActions = () => useContext(EditedContentActionsContext);
186
146
  const useEditedContent = () => {
187
- const stateContext = useContext(EditedContentStateContext);
188
- const actionContext = useEditedContentActions();
189
- return { ...stateContext, ...actionContext };
190
- };
191
- export {
192
- EditedContentProvider,
193
- useEditedContent,
194
- useEditedContentActions,
195
- useGetEditedContentState,
196
- usePostEditedContentState
147
+ const stateContext = useContext(EditedContentStateContext);
148
+ const actionContext = useEditedContentActions();
149
+ return {
150
+ ...stateContext,
151
+ ...actionContext
152
+ };
197
153
  };
154
+
155
+ //#endregion
156
+ export { EditedContentProvider, useEditedContent, useEditedContentActions, useGetEditedContentState, usePostEditedContentState };
198
157
  //# sourceMappingURL=EditedContentContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n type ContentNode,\n type Dictionary,\n type KeyPath,\n} 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 {\n useDictionariesRecord,\n type DictionaryContent,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype EditedContentStateContextType = {\n editedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst EditedContentStateContext = createContext<\n EditedContentStateContextType | undefined\n>(undefined);\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,\n onEventTriggered\n );\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<Dictionary['key'], Dictionary>\n ) => void;\n setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;\n setEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n dictionaryKey: Dictionary['key'],\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (dictionaryKey: Dictionary['key']) => void;\n clearEditedDictionaryContent: (dictionaryKey: Dictionary['key']) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: Dispatch<SetStateAction<Dictionary>> = (\n newValue\n ) => {\n let updatedDictionaries: Dictionary = resolveState(newValue);\n\n setEditedContentState((prev) => {\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.key]\n );\n\n return {\n ...prev,\n [updatedDictionaries.key]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setEditedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n const addEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: ContentNode,\n keyPath: KeyPath[] = [],\n overwrite: boolean = true\n ) => {\n setEditedContentState((prev) => {\n // Get the starting content: edited version if available, otherwise a deep copy of the original\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n let newKeyPath = keyPath;\n if (!overwrite) {\n // Find a unique key based on the keyPath provided\n let index = 0;\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath: KeyPath = keyPath[keyPath.length - 1];\n let finalKey = lastKeyPath.key;\n\n // Loop until we find a key that does not exist\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: updatedContent as Dictionary['content'],\n },\n };\n });\n };\n\n const renameEditedContent = (\n dictionaryKey: Dictionary['key'],\n newKey: KeyPath['key'],\n keyPath: KeyPath[] = []\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the base content: use edited version if available, otherwise deep copy of original\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n const contentWithNewField = renameContentNodeByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: contentWithNewField as Dictionary['content'],\n },\n };\n });\n };\n\n const removeEditedContent = (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the original content as reference\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n // Get the initial value from the original dictionary content\n const initialContent = getContentNodeByKeyPath(originalContent, keyPath);\n\n // Restore the value at the given keyPath\n const restoredContent = editDictionaryByKeyPath(\n currentContent,\n keyPath,\n initialContent\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: restoredContent as Dictionary['content'],\n },\n };\n });\n };\n\n const restoreEditedContent = (dictionaryKey: Dictionary['key']) => {\n setEditedContentState((prev) => {\n const updated = { ...prev };\n delete updated[dictionaryKey];\n return updated;\n });\n };\n\n const clearEditedDictionaryContent = (dictionaryKey: Dictionary['key']) => {\n setEditedContentState((prev) => {\n const filtered = Object.entries(prev).reduce((acc, [key, value]) => {\n if (key === dictionaryKey) {\n return acc;\n }\n return { ...acc, [key]: value };\n }, {} as DictionaryContent);\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ): ContentNode | undefined => {\n const currentContent = editedContent?.[dictionaryKey]?.content ?? {};\n return getContentNodeByKeyPath(currentContent, keyPath);\n };\n\n return (\n <EditedContentStateContext.Provider\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext.Provider\n value={{\n setEditedContentState,\n setEditedDictionary,\n setEditedContent,\n addEditedContent,\n renameEditedContent,\n removeEditedContent,\n restoreEditedContent,\n clearEditedDictionaryContent,\n clearEditedContent,\n getEditedContentValue,\n }}\n >\n {children}\n </EditedContentActionsContext.Provider>\n </EditedContentStateContext.Provider>\n );\n};\n\nexport const useEditedContentActions = () =>\n useContext(EditedContentActionsContext);\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";AA0RM;AAxRN;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,oCAAoC;AAC7C,SAAS,0BAA0B;AAMnC,MAAM,4BAA4B,cAEhC,MAAS;AAEJ,MAAM,4BAA4B,CACvC,qBAEA;AAAA,EACE,GAAG,W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AG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
1
+ {"version":3,"file":"EditedContentContext.mjs","names":["EditedContentProvider: FC<PropsWithChildren>","setEditedDictionary: Dispatch<SetStateAction<Dictionary>>","updatedDictionaries: Dictionary","lastKeyPath: KeyPath"],"sources":["../../../src/editor/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport type {\n ContentNode,\n Dictionary,\n KeyPath,\n LocalDictionaryId,\n} from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n} from 'preact/compat';\nimport {\n type DictionaryContent,\n useDictionariesRecord,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype EditedContentStateContextType = {\n editedContent: Record<LocalDictionaryId, Dictionary> | undefined;\n};\n\nconst EditedContentStateContext = createContext<\n EditedContentStateContextType | undefined\n>(undefined);\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,\n onEventTriggered\n );\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<LocalDictionaryId, Dictionary>\n ) => void;\n setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;\n setEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (dictionaryLocalId: LocalDictionaryId) => void;\n clearEditedDictionaryContent: (dictionaryLocalId: LocalDictionaryId) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: Dispatch<SetStateAction<Dictionary>> = (\n newValue\n ) => {\n let updatedDictionaries: Dictionary = resolveState(newValue);\n\n setEditedContentState((prev) => {\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.key]\n );\n\n return {\n ...prev,\n [updatedDictionaries.key]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => {\n setEditedContentState((prev) => ({\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: newValue,\n },\n }));\n };\n\n const addEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n newValue: ContentNode,\n keyPath: KeyPath[] = [],\n overwrite: boolean = true\n ) => {\n setEditedContentState((prev) => {\n // Get the starting content: edited version if available, otherwise a deep copy of the original\n const originalContent = localeDictionaries[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.content ?? originalContent\n );\n\n let newKeyPath = keyPath;\n if (!overwrite) {\n // Find a unique key based on the keyPath provided\n let index = 0;\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath: KeyPath = keyPath[keyPath.length - 1];\n let finalKey = lastKeyPath.key;\n\n // Loop until we find a key that does not exist\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n return {\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: updatedContent as Dictionary['content'],\n },\n };\n });\n };\n\n const renameEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath: KeyPath[] = []\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the base content: use edited version if available, otherwise deep copy of original\n const originalContent = localeDictionaries[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.content ?? originalContent\n );\n\n const contentWithNewField = renameContentNodeByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: contentWithNewField as Dictionary['content'],\n },\n };\n });\n };\n\n const removeEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the original content as reference\n const originalContent = localeDictionaries[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.content ?? originalContent\n );\n\n // Get the initial value from the original dictionary content\n const initialContent = getContentNodeByKeyPath(originalContent, keyPath);\n\n // Restore the value at the given keyPath\n const restoredContent = editDictionaryByKeyPath(\n currentContent,\n keyPath,\n initialContent\n );\n\n return {\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: restoredContent as Dictionary['content'],\n },\n };\n });\n };\n\n const restoreEditedContent = (dictionaryLocalId: LocalDictionaryId) => {\n setEditedContentState((prev) => {\n const updated = { ...prev };\n delete updated[dictionaryLocalId];\n return updated;\n });\n };\n\n const clearEditedDictionaryContent = (\n dictionaryLocalId: LocalDictionaryId\n ) => {\n setEditedContentState((prev) => {\n const filtered = Object.entries(prev).reduce((acc, [key, value]) => {\n if (key === dictionaryLocalId) {\n return acc;\n }\n return { ...acc, [key]: value };\n }, {} as DictionaryContent);\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ): ContentNode | undefined => {\n if (!editedContent) return undefined;\n\n const isDictionaryId =\n localDictionaryIdOrKey.includes(':local:') ||\n localDictionaryIdOrKey.includes(':remote:');\n\n if (isDictionaryId) {\n const currentContent =\n editedContent?.[localDictionaryIdOrKey as LocalDictionaryId]?.content ??\n {};\n\n const contentNode = getContentNodeByKeyPath(currentContent, keyPath);\n\n return contentNode;\n }\n\n const filteredDictionariesLocalId = Object.keys(editedContent).filter(\n (key) => key.startsWith(`${localDictionaryIdOrKey}:`)\n );\n\n for (const localDictionaryId of filteredDictionariesLocalId) {\n const currentContent =\n editedContent?.[localDictionaryId as LocalDictionaryId]?.content ?? {};\n const contentNode = getContentNodeByKeyPath(currentContent, keyPath);\n\n if (contentNode) return contentNode;\n }\n\n return undefined;\n };\n\n return (\n <EditedContentStateContext.Provider\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext.Provider\n value={{\n setEditedContentState,\n setEditedDictionary,\n setEditedContent,\n addEditedContent,\n renameEditedContent,\n removeEditedContent,\n restoreEditedContent,\n clearEditedDictionaryContent,\n clearEditedContent,\n getEditedContentValue,\n }}\n >\n {children}\n </EditedContentActionsContext.Provider>\n </EditedContentStateContext.Provider>\n );\n};\n\nexport const useEditedContentActions = () =>\n useContext(EditedContentActionsContext);\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;AAiCA,MAAM,4BAA4B,cAEhC,OAAU;AAEZ,MAAa,6BACX,qBAEA,6BACE,GAAG,WAAW,gCAAgC,QAC9C,iBACD;AAEH,MAAa,4BACX,qBAEA,6BACE,GAAG,WAAW,gCAAgC,OAC9C,iBACD;AAmCH,MAAM,8BAA8B,cAElC,OAAU;AAEZ,MAAM,gBAAoB,OAA2B,cACnD,OAAO,UAAU,aACZ,MAA+B,UAAU,GACzC;AAEP,MAAaA,yBAAgD,EAAE,eAAe;CAC5E,MAAM,EAAE,uBAAuB,uBAAuB;CAEtD,MAAM,CAAC,eAAe,yBACpB,mBACE,WAAW,gCACZ;CAEH,MAAMC,uBACJ,aACG;EACH,IAAIC,sBAAkC,aAAa,SAAS;AAE5D,yBAAuB,SAAS;AAC9B,yBAAsB,aACpB,UACA,OAAO,oBAAoB,KAC5B;AAED,UAAO;IACL,GAAG;KACF,oBAAoB,MAAM;IAC5B;IACD;AAEF,SAAO;;CAGT,MAAM,oBACJ,mBACA,aACG;AACH,yBAAuB,UAAU;GAC/B,GAAG;IACF,oBAAoB;IACnB,GAAG,OAAO;IACV,SAAS;IACV;GACF,EAAE;;CAGL,MAAM,oBACJ,mBACA,UACA,UAAqB,EAAE,EACvB,YAAqB,SAClB;AACH,yBAAuB,SAAS;GAE9B,MAAM,kBAAkB,mBAAmB,oBAAoB;GAC/D,MAAM,iBAAiB,gBACrB,OAAO,oBAAoB,WAAW,gBACvC;GAED,IAAI,aAAa;AACjB,OAAI,CAAC,WAAW;IAEd,IAAI,QAAQ;IACZ,MAAM,eAAe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AE,GAAG;MAAM,MAAM;KAAO;MAC9B,EAAE,CAAsB;IAE3B;;CAGJ,MAAM,2BAA2B;AAC/B,wBAAsB,EAAE,CAAC;;CAG3B,MAAM,yBACJ,wBACA,YAC4B;AAC5B,MAAI,CAAC,cAAe,QAAO;AAM3B,MAHE,uBAAuB,SAAS,UAAU,IAC1C,uBAAuB,SAAS,WAAW,CAS3C,QAFoB,wBAHlB,gBAAgB,yBAA8C,WAC9D,EAAE,EAEwD,QAAQ;EAKtE,MAAM,8BAA8B,OAAO,KAAK,cAAc,CAAC,QAC5D,QAAQ,IAAI,WAAW,GAAG,uBAAuB,GAAG,CACtD;AAED,OAAK,MAAM,qBAAqB,6BAA6B;GAG3D,MAAM,cAAc,wBADlB,gBAAgB,oBAAyC,WAAW,EAAE,EACZ,QAAQ;AAEpE,OAAI,YAAa,QAAO;;;AAM5B,QACE,oBAAC,0BAA0B;EACzB,OAAO,EACL,eACD;YAED,oBAAC,4BAA4B;GAC3B,OAAO;IACL;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACD;GAEA;IACoC;GACJ;;AAIzC,MAAa,gCACX,WAAW,4BAA4B;AAEzC,MAAa,yBAAyB;CACpC,MAAM,eAAe,WAAW,0BAA0B;CAC1D,MAAM,gBAAgB,yBAAyB;AAE/C,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
@@ -1,39 +1,29 @@
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";
1
+ 'use client';
2
+
3
+
8
4
  import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs";
9
- import {
10
- useCrossFrameState
11
- } from "./useCrossFrameState.mjs";
12
- const EditorEnabledContext = createContext({
13
- enabled: false
14
- });
5
+ import { useCrossFrameState } from "./useCrossFrameState.mjs";
6
+ import { MessageKey } from "@intlayer/editor";
7
+ import { createContext, useContext } from "preact/compat";
8
+ import { jsx } from "preact/jsx-runtime";
9
+
10
+ //#region src/editor/EditorEnabledContext.tsx
11
+ const EditorEnabledContext = createContext({ enabled: false });
15
12
  const useEditorEnabledState = (options) => useCrossFrameState(MessageKey.INTLAYER_EDITOR_ENABLED, false, options);
16
- const usePostEditorEnabledState = (onEventTriggered) => useCrossFrameMessageListener(
17
- `${MessageKey.INTLAYER_EDITOR_ENABLED}/post`,
18
- onEventTriggered
19
- );
20
- const useGetEditorEnabledState = (onEventTriggered) => useCrossFrameMessageListener(
21
- `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,
22
- onEventTriggered
23
- );
13
+ const usePostEditorEnabledState = (onEventTriggered) => useCrossFrameMessageListener(`${MessageKey.INTLAYER_EDITOR_ENABLED}/post`, onEventTriggered);
14
+ const useGetEditorEnabledState = (onEventTriggered) => useCrossFrameMessageListener(`${MessageKey.INTLAYER_EDITOR_ENABLED}/get`, onEventTriggered);
24
15
  const EditorEnabledProvider = ({ children }) => {
25
- const [isEnabled] = useEditorEnabledState({
26
- emit: false,
27
- receive: true
28
- });
29
- return /* @__PURE__ */ jsx(EditorEnabledContext.Provider, { value: { enabled: isEnabled }, children });
16
+ const [isEnabled] = useEditorEnabledState({
17
+ emit: false,
18
+ receive: true
19
+ });
20
+ return /* @__PURE__ */ jsx(EditorEnabledContext.Provider, {
21
+ value: { enabled: isEnabled },
22
+ children
23
+ });
30
24
  };
31
25
  const useEditorEnabled = () => useContext(EditorEnabledContext);
32
- export {
33
- EditorEnabledProvider,
34
- useEditorEnabled,
35
- useEditorEnabledState,
36
- useGetEditorEnabledState,
37
- usePostEditorEnabledState
38
- };
26
+
27
+ //#endregion
28
+ export { EditorEnabledProvider, useEditorEnabled, useEditorEnabledState, useGetEditorEnabledState, usePostEditorEnabledState };
39
29
  //# sourceMappingURL=EditorEnabledContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'preact/compat';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport {\n useCrossFrameState,\n type CrossFrameStateOptions,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps>({\n enabled: false,\n});\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState(MessageKey.INTLAYER_EDITOR_ENABLED, false, options);\n\nexport const usePostEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onEventTriggered\n );\n\nexport const EditorEnabledProvider: FC<PropsWithChildren> = ({ children }) => {\n const [isEnabled] = useEditorEnabledState({\n emit: false,\n receive: true,\n });\n\n return (\n <EditorEnabledContext.Provider value={{ enabled: isEnabled }}>\n {children}\n </EditorEnabledContext.Provider>\n );\n};\n\nexport const useEditorEnabled = () => useContext(EditorEnabledContext);\n"],"mappings":";AAiDI;AA/CJ,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,oCAAoC;AAC7C;AAAA,EACE;AAAA,OAEK;AAMP,MAAM,uBAAuB,cAAuC;AAAA,EAClE,SAAS;AACX,CAAC;AAEM,MAAM,wBAAwB,CAAC,YACpC,mBAAmB,WAAW,yBAAyB,OAAO,OAAO;AAEhE,MAAM,4BAA4B,CACvC,qBAEA;AAAA,EACE,GAAG,WAAW,uBAAuB;AAAA,EACrC;AACF;AAEK,MAAM,2BAA2B,CACtC,qBAEA;AAAA,EACE,GAAG,WAAW,uBAAuB;AAAA,EACrC;AACF;AAEK,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,CAAC,SAAS,IAAI,sBAAsB;AAAA,IACxC,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AAED,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,SAAS,UAAU,GACxD,UACH;AAEJ;AAEO,MAAM,mBAAmB,MAAM,WAAW,oBAAoB;","names":[]}
1
+ {"version":3,"file":"EditorEnabledContext.mjs","names":["EditorEnabledProvider: FC<PropsWithChildren>"],"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'preact/compat';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps>({\n enabled: false,\n});\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState(MessageKey.INTLAYER_EDITOR_ENABLED, false, options);\n\nexport const usePostEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onEventTriggered\n );\n\nexport const EditorEnabledProvider: FC<PropsWithChildren> = ({ children }) => {\n const [isEnabled] = useEditorEnabledState({\n emit: false,\n receive: true,\n });\n\n return (\n <EditorEnabledContext.Provider value={{ enabled: isEnabled }}>\n {children}\n </EditorEnabledContext.Provider>\n );\n};\n\nexport const useEditorEnabled = () => useContext(EditorEnabledContext);\n"],"mappings":";;;;;;;;;;AAmBA,MAAM,uBAAuB,cAAuC,EAClE,SAAS,OACV,CAAC;AAEF,MAAa,yBAAyB,YACpC,mBAAmB,WAAW,yBAAyB,OAAO,QAAQ;AAExE,MAAa,6BACX,qBAEA,6BACE,GAAG,WAAW,wBAAwB,QACtC,iBACD;AAEH,MAAa,4BACX,qBAEA,6BACE,GAAG,WAAW,wBAAwB,OACtC,iBACD;AAEH,MAAaA,yBAAgD,EAAE,eAAe;CAC5E,MAAM,CAAC,aAAa,sBAAsB;EACxC,MAAM;EACN,SAAS;EACV,CAAC;AAEF,QACE,oBAAC,qBAAqB;EAAS,OAAO,EAAE,SAAS,WAAW;EACzD;GAC6B;;AAIpC,MAAa,yBAAyB,WAAW,qBAAqB"}