preact-intlayer 6.1.6 → 7.0.0-canary.3

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,32 +1,26 @@
1
+ //#region src/client/useLoadDynamic.ts
1
2
  const createSuspender = (promise) => {
2
- let status = "pending";
3
- let result;
4
- const suspender = promise.then(
5
- (r) => {
6
- status = "success";
7
- result = r;
8
- },
9
- (e) => {
10
- status = "error";
11
- result = e;
12
- }
13
- );
14
- return {
15
- read() {
16
- if (status === "pending") throw suspender;
17
- if (status === "error") throw result;
18
- return result;
19
- }
20
- };
3
+ let status = "pending";
4
+ let result;
5
+ const suspender = promise.then((r) => {
6
+ status = "success";
7
+ result = r;
8
+ }, (e) => {
9
+ status = "error";
10
+ result = e;
11
+ });
12
+ return { read() {
13
+ if (status === "pending") throw suspender;
14
+ if (status === "error") throw result;
15
+ return result;
16
+ } };
21
17
  };
22
18
  const cache = /* @__PURE__ */ new Map();
23
19
  const useLoadDynamic = (key, promise) => {
24
- if (!cache.has(key)) {
25
- cache.set(key, createSuspender(promise));
26
- }
27
- return cache.get(key).read();
28
- };
29
- export {
30
- useLoadDynamic
20
+ if (!cache.has(key)) cache.set(key, createSuspender(promise));
21
+ return cache.get(key).read();
31
22
  };
23
+
24
+ //#endregion
25
+ export { useLoadDynamic };
32
26
  //# sourceMappingURL=useLoadDynamic.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, ReturnType<typeof createSuspender>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as ReturnType<typeof createSuspender>).read() as T;\n};\n"],"mappings":"AAEA,MAAM,kBAAkB,CAAI,YAAwB;AAClD,MAAI,SAAiB;AACrB,MAAI;AACJ,QAAM,YAAY,QAAQ;AAAA,IACxB,CAAC,MAAM;AACL,eAAS;AACT,eAAS;AAAA,IACX;AAAA,IACA,CAAC,MAAM;AACL,eAAS;AACT,eAAS;AAAA,IACX;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO;AACL,UAAI,WAAW,UAAW,OAAM;AAChC,UAAI,WAAW,QAAS,OAAM;AAC9B,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEA,MAAM,QAAQ,oBAAI,IAAgD;AAE3D,MAAM,iBAAiB,CAAI,KAAa,YAA2B;AACxE,MAAI,CAAC,MAAM,IAAI,GAAG,GAAG;AACnB,UAAM,IAAI,KAAK,gBAAgB,OAAO,CAAC;AAAA,EACzC;AAEA,SAAQ,MAAM,IAAI,GAAG,EAA0C,KAAK;AACtE;","names":[]}
1
+ {"version":3,"file":"useLoadDynamic.mjs","names":["status: Status","result: T"],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, ReturnType<typeof createSuspender>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as ReturnType<typeof createSuspender>).read() as T;\n};\n"],"mappings":";AAEA,MAAM,mBAAsB,YAAwB;CAClD,IAAIA,SAAiB;CACrB,IAAIC;CACJ,MAAM,YAAY,QAAQ,MACvB,MAAM;AACL,WAAS;AACT,WAAS;KAEV,MAAM;AACL,WAAS;AACT,WAAS;GAEZ;AAED,QAAO,EACL,OAAO;AACL,MAAI,WAAW,UAAW,OAAM;AAChC,MAAI,WAAW,QAAS,OAAM;AAC9B,SAAO;IAEV;;AAGH,MAAM,wBAAQ,IAAI,KAAiD;AAEnE,MAAa,kBAAqB,KAAa,YAA2B;AACxE,KAAI,CAAC,MAAM,IAAI,IAAI,CACjB,OAAM,IAAI,KAAK,gBAAgB,QAAQ,CAAC;AAG1C,QAAQ,MAAM,IAAI,IAAI,CAAyC,MAAM"}
@@ -1,35 +1,35 @@
1
- "use client";
1
+ 'use client';
2
+
3
+
4
+ import { setLocaleInStorage } from "./useLocaleStorage.mjs";
5
+ import { IntlayerClientContext } from "./IntlayerProvider.mjs";
2
6
  import configuration from "@intlayer/config/built";
3
7
  import { useContext } from "preact/hooks";
4
- import { IntlayerClientContext } from "./IntlayerProvider.mjs";
5
- import { useLocaleCookie } from "./useLocaleCookie.mjs";
6
- const useLocale = ({ onLocaleChange } = {}) => {
7
- const { defaultLocale, locales: availableLocales } = configuration?.internationalization ?? {};
8
- const { locale, setLocale: setLocaleState } = useContext(
9
- IntlayerClientContext
10
- );
11
- const { setLocaleCookie } = useLocaleCookie();
12
- const setLocale = (locale2) => {
13
- if (!availableLocales?.map(String).includes(locale2)) {
14
- console.error(`Locale ${locale2} is not available`);
15
- return;
16
- }
17
- setLocaleState(locale2);
18
- setLocaleCookie(locale2);
19
- onLocaleChange?.(locale2);
20
- };
21
- return {
22
- locale,
23
- // Current locale
24
- defaultLocale,
25
- // Principal locale defined in config
26
- availableLocales,
27
- // List of the available locales defined in config
28
- setLocale
29
- // Function to set the locale
30
- };
31
- };
32
- export {
33
- useLocale
8
+
9
+ //#region src/client/useLocale.ts
10
+ /**
11
+ * On the client side, hook to get the current locale and all related fields
12
+ */
13
+ const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
14
+ const { defaultLocale, locales: availableLocales } = configuration?.internationalization ?? {};
15
+ const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = useContext(IntlayerClientContext);
16
+ const setLocale = (locale$1) => {
17
+ if (!availableLocales?.map(String).includes(locale$1)) {
18
+ console.error(`Locale ${locale$1} is not available`);
19
+ return;
20
+ }
21
+ setLocaleState(locale$1);
22
+ setLocaleInStorage(locale$1, isCookieEnabled ?? isCookieEnabledContext ?? true);
23
+ onLocaleChange?.(locale$1);
24
+ };
25
+ return {
26
+ locale,
27
+ defaultLocale,
28
+ availableLocales,
29
+ setLocale
30
+ };
34
31
  };
32
+
33
+ //#endregion
34
+ export { useLocale };
35
35
  //# sourceMappingURL=useLocale.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useLocaleCookie } from './useLocaleCookie';\n\ntype useLocaleProps = {\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({ onLocaleChange }: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const { locale, setLocale: setLocaleState } = useContext(\n IntlayerClientContext\n );\n const { setLocaleCookie } = useLocaleCookie();\n\n const setLocale = (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleCookie(locale);\n onLocaleChange?.(locale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";AAEA,OAAO,mBAAmB;AAE1B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AASzB,MAAM,YAAY,CAAC,EAAE,eAAe,IAAoB,CAAC,MAAM;AACpE,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,eAAe,wBAAwB,CAAC;AAE1C,QAAM,EAAE,QAAQ,WAAW,eAAe,IAAI;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,EAAE,gBAAgB,IAAI,gBAAgB;AAE5C,QAAM,YAAY,CAACA,YAA0B;AAC3C,QAAI,CAAC,kBAAkB,IAAI,MAAM,EAAE,SAASA,OAAM,GAAG;AACnD,cAAQ,MAAM,UAAUA,OAAM,mBAAmB;AACjD;AAAA,IACF;AAEA,mBAAeA,OAAM;AACrB,oBAAgBA,OAAM;AACtB,qBAAiBA,OAAM;AAAA,EACzB;AAEA,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":["locale"]}
1
+ {"version":3,"file":"useLocale.mjs","names":["locale"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n\n onLocaleChange?.(locale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAK;CACzB,MAAM,EAAE,eAAe,SAAS,qBAC9B,eAAe,wBAAwB,EAAE;CAE3C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,2BACf,WAAW,sBAAsB;CAErC,MAAM,aAAa,aAA0B;AAC3C,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAASA,SAAO,EAAE;AACnD,WAAQ,MAAM,UAAUA,SAAO,mBAAmB;AAClD;;AAGF,iBAAeA,SAAO;AAEtB,qBACEA,UACA,mBAAmB,0BAA0B,KAC9C;AAED,mBAAiBA,SAAO;;AAG1B,QAAO;EACL;EACA;EACA;EACA;EACD"}
@@ -1,22 +1,25 @@
1
- "use client";
1
+ 'use client';
2
+
3
+
4
+ import { IntlayerClientContext } from "./IntlayerProvider.mjs";
2
5
  import configuration from "@intlayer/config/built";
3
6
  import { useContext } from "preact/hooks";
4
- import { IntlayerClientContext } from "./IntlayerProvider.mjs";
7
+
8
+ //#region src/client/useLocaleBase.ts
5
9
  const { defaultLocale, locales: availableLocales } = configuration.internationalization;
10
+ /**
11
+ * On the client side, hook to get the current locale and all related fields
12
+ */
6
13
  const useLocaleBase = () => {
7
- const { locale, setLocale } = useContext(IntlayerClientContext);
8
- return {
9
- locale,
10
- // Current locale
11
- defaultLocale,
12
- // Principal locale defined in config
13
- availableLocales,
14
- // List of the available locales defined in config
15
- setLocale
16
- // Function to set the locale
17
- };
18
- };
19
- export {
20
- useLocaleBase
14
+ const { locale, setLocale } = useContext(IntlayerClientContext);
15
+ return {
16
+ locale,
17
+ defaultLocale,
18
+ availableLocales,
19
+ setLocale
20
+ };
21
21
  };
22
+
23
+ //#endregion
24
+ export { useLocaleBase };
22
25
  //# sourceMappingURL=useLocaleBase.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";AAEA,OAAO,mBAAmB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,cAAc;AAKT,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"useLocaleBase.mjs","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;AAMA,MAAM,EAAE,eAAe,SAAS,qBAC9B,cAAc;;;;AAKhB,MAAa,sBAAsB;CACjC,MAAM,EAAE,QAAQ,cAAc,WAAW,sBAAsB;AAE/D,QAAO;EACL;EACA;EACA;EACA;EACD"}
@@ -0,0 +1,52 @@
1
+ import { LocaleStorage, getLocaleFromStorage, localeStorageOptions, setLocaleInStorage as setLocaleInStorage$1 } from "@intlayer/core";
2
+ import { useMemo } from "preact/hooks";
3
+
4
+ //#region src/client/useLocaleStorage.ts
5
+ /**
6
+ * Get the locale cookie
7
+ */
8
+ const localeInStorage = getLocaleFromStorage(localeStorageOptions);
9
+ /**
10
+ * @deprecated Use localeInStorage instead
11
+ *
12
+ * Get the locale cookie
13
+ */
14
+ const localeCookie = localeInStorage;
15
+ /**
16
+ * Set the locale cookie
17
+ */
18
+ const setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorage$1(locale, {
19
+ ...localeStorageOptions,
20
+ isCookieEnabled
21
+ });
22
+ /**
23
+ * @deprecated Use setLocaleInStorage instead
24
+ *
25
+ * Set the locale cookie
26
+ */
27
+ const setLocaleCookie = setLocaleInStorage;
28
+ /**
29
+ * Hook that provides the locale storage and a function to set it
30
+ */
31
+ const useLocaleStorage = (isCookieEnabled) => useMemo(() => LocaleStorage({
32
+ ...localeStorageOptions,
33
+ isCookieEnabled
34
+ }), [isCookieEnabled]);
35
+ /**
36
+ * @deprecated Use useLocaleStorage instead
37
+ *
38
+ * For GDPR compliance, use useLocaleStorage instead
39
+ *
40
+ * Hook that provides the locale cookie and a function to set it
41
+ */
42
+ const useLocaleCookie = (isCookieEnabled) => {
43
+ const storage = useLocaleStorage(isCookieEnabled);
44
+ return {
45
+ localeCookie: storage.getLocale(),
46
+ setLocaleCookie: storage.setLocale
47
+ };
48
+ };
49
+
50
+ //#endregion
51
+ export { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
52
+ //# sourceMappingURL=useLocaleStorage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocaleStorage.mjs","names":["setLocaleInStorageCore"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getLocaleFromStorage,\n LocaleStorage,\n localeStorageOptions,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useMemo } from 'preact/hooks';\n\n/**\n * Get the locale cookie\n */\nexport const localeInStorage = getLocaleFromStorage(localeStorageOptions);\n/**\n * @deprecated Use localeInStorage instead\n *\n * Get the locale cookie\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead\n *\n * Set the locale cookie\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Hook that provides the locale storage and a function to set it\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) =>\n useMemo(\n () =>\n LocaleStorage({\n ...localeStorageOptions,\n isCookieEnabled,\n }),\n [isCookieEnabled]\n );\n\n/**\n * @deprecated Use useLocaleStorage instead\n *\n * For GDPR compliance, use useLocaleStorage instead\n *\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = (isCookieEnabled?: boolean) => {\n const storage = useLocaleStorage(isCookieEnabled);\n return {\n localeCookie: storage.getLocale(),\n setLocaleCookie: storage.setLocale,\n };\n};\n"],"mappings":";;;;;;;AAYA,MAAa,kBAAkB,qBAAqB,qBAAqB;;;;;;AAMzE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,oBAEAA,qBAAuB,QAAQ;CAC7B,GAAG;CACH;CACD,CAAC;;;;;;AAOJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,oBAC/B,cAEI,cAAc;CACZ,GAAG;CACH;CACD,CAAC,EACJ,CAAC,gBAAgB,CAClB;;;;;;;;AASH,MAAa,mBAAmB,oBAA8B;CAC5D,MAAM,UAAU,iBAAiB,gBAAgB;AACjD,QAAO;EACL,cAAc,QAAQ,WAAW;EACjC,iBAAiB,QAAQ;EAC1B"}
@@ -1,14 +1,34 @@
1
+ import { IntlayerClientContext } from "./IntlayerProvider.mjs";
1
2
  import { getTranslation } from "@intlayer/core";
2
3
  import { useContext, useMemo } from "preact/hooks";
3
- import { IntlayerClientContext } from "./IntlayerProvider.mjs";
4
+
5
+ //#region src/client/useTraduction.ts
6
+ /**
7
+ * On the client side, Hook that picking one dictionary by its id and return the content.
8
+ *
9
+ * If not locale found, it will return the content related to the default locale.
10
+ *
11
+ * Return either the content editor, or the content itself depending on the configuration.
12
+ *
13
+ * Usage:
14
+ *
15
+ * ```tsx
16
+ * const content = useTranslation<string>({
17
+ * en: 'Hello',
18
+ * fr: 'Bonjour',
19
+ * }, 'fr');
20
+ * // 'Bonjour'
21
+ * ```
22
+ *
23
+ * Using TypeScript:
24
+ * - this function will require each locale to be defined if defined in the project configuration.
25
+ * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
26
+ */
4
27
  const useTranslation = (languageContent) => {
5
- const { locale } = useContext(IntlayerClientContext);
6
- return useMemo(
7
- () => getTranslation(languageContent, locale),
8
- [languageContent, locale]
9
- );
10
- };
11
- export {
12
- useTranslation
28
+ const { locale } = useContext(IntlayerClientContext);
29
+ return useMemo(() => getTranslation(languageContent, locale), [languageContent, locale]);
13
30
  };
31
+
32
+ //#endregion
33
+ export { useTranslation };
14
34
  //# sourceMappingURL=useTraduction.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation, type LanguageContent } from '@intlayer/core';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTranslation = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useMemo(\n () => getTranslation(languageContent, locale),\n [languageContent, locale]\n );\n};\n"],"mappings":"AAAA,SAAS,sBAA4C;AACrD,SAAS,YAAY,eAAe;AACpC,SAAS,6BAA6B;AAuB/B,MAAM,iBAAiB,CAC5B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO;AAAA,IACL,MAAM,eAAe,iBAAiB,MAAM;AAAA,IAC5C,CAAC,iBAAiB,MAAM;AAAA,EAC1B;AACF;","names":[]}
1
+ {"version":3,"file":"useTraduction.mjs","names":[],"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core';\nimport type { StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useMemo(\n () => getTranslation(languageContent, locale),\n [languageContent, locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,kBACX,oBACY;CACZ,MAAM,EAAE,WAAW,WAAW,sBAAsB;AAEpD,QAAO,cACC,eAAe,iBAAiB,OAAO,EAC7C,CAAC,iBAAiB,OAAO,CAC1B"}
@@ -1,33 +1,37 @@
1
- "use client";
2
- import { jsx } from "preact/jsx-runtime";
1
+ 'use client';
2
+
3
+
4
+ import { createContext } from "preact";
3
5
  import configuration from "@intlayer/config/built";
4
- import {
5
- createContext
6
- } from "preact";
7
6
  import { useContext, useMemo, useRef } from "preact/hooks";
8
- import { v4 as uuid } from "uuid";
7
+ import { v4 } from "uuid";
8
+ import { jsx } from "preact/jsx-runtime";
9
+
10
+ //#region src/editor/CommunicatorContext.tsx
9
11
  const { editor } = configuration;
10
12
  const CommunicatorContext = createContext({
11
- postMessage: () => null,
12
- allowedOrigins: [
13
- editor?.applicationURL,
14
- editor?.editorURL,
15
- editor?.cmsURL
16
- ],
17
- senderId: ""
13
+ postMessage: () => null,
14
+ allowedOrigins: [
15
+ editor?.applicationURL,
16
+ editor?.editorURL,
17
+ editor?.cmsURL
18
+ ],
19
+ senderId: ""
18
20
  });
19
21
  const CommunicatorProvider = ({ children, allowedOrigins, postMessage }) => {
20
- const senderIdRef = useRef(uuid());
21
- const value = useMemo(
22
- () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),
23
- [postMessage, allowedOrigins]
24
- // senderIdRef.current is stable
25
- );
26
- return /* @__PURE__ */ jsx(CommunicatorContext.Provider, { value, children });
22
+ const senderIdRef = useRef(v4());
23
+ const value = useMemo(() => ({
24
+ postMessage,
25
+ allowedOrigins,
26
+ senderId: senderIdRef.current
27
+ }), [postMessage, allowedOrigins]);
28
+ return /* @__PURE__ */ jsx(CommunicatorContext.Provider, {
29
+ value,
30
+ children
31
+ });
27
32
  };
28
33
  const useCommunicator = () => useContext(CommunicatorContext);
29
- export {
30
- CommunicatorProvider,
31
- useCommunicator
32
- };
34
+
35
+ //#endregion
36
+ export { CommunicatorProvider, useCommunicator };
33
37
  //# sourceMappingURL=CommunicatorContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\n\nimport {\n createContext,\n type ComponentChildren,\n type FunctionComponent,\n} from 'preact';\nimport { useContext, useMemo, useRef } from 'preact/hooks';\nimport { v4 as uuid } from 'uuid'; // if you prefer a UUID library\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = configuration;\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [\n editor?.applicationURL,\n editor?.editorURL,\n editor?.cmsURL,\n ] as string[],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = {\n children?: ComponentChildren;\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n};\n\nexport const CommunicatorProvider: FunctionComponent<\n CommunicatorProviderProps\n> = ({ children, allowedOrigins, postMessage }) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(uuid());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins] // senderIdRef.current is stable\n );\n\n return (\n <CommunicatorContext.Provider value={value}>\n {children}\n </CommunicatorContext.Provider>\n );\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":";AAgDI;AA9CJ,OAAO,mBAAmB;AAE1B;AAAA,EACE;AAAA,OAGK;AACP,SAAS,YAAY,SAAS,cAAc;AAC5C,SAAS,MAAM,YAAY;AAQ3B,MAAM,EAAE,OAAO,IAAI;AAEnB,MAAM,sBAAsB,cAA0C;AAAA,EACpE,aAAa,MAAM;AAAA,EACnB,gBAAgB;AAAA,IACd,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAAA,EACA,UAAU;AACZ,CAAC;AAQM,MAAM,uBAET,CAAC,EAAE,UAAU,gBAAgB,YAAY,MAAM;AAEjD,QAAM,cAAc,OAAO,KAAK,CAAC;AAEjC,QAAM,QAAQ;AAAA,IACZ,OAAO,EAAE,aAAa,gBAAgB,UAAU,YAAY,QAAQ;AAAA,IACpE,CAAC,aAAa,cAAc;AAAA;AAAA,EAC9B;AAEA,SACE,oBAAC,oBAAoB,UAApB,EAA6B,OAC3B,UACH;AAEJ;AAEO,MAAM,kBAAkB,MAAM,WAAW,mBAAmB;","names":[]}
1
+ {"version":3,"file":"CommunicatorContext.mjs","names":["CommunicatorProvider: FunctionComponent<\n CommunicatorProviderProps\n>","uuid"],"sources":["../../../src/editor/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\n\nimport {\n type ComponentChildren,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext, useMemo, useRef } from 'preact/hooks';\nimport { v4 as uuid } from 'uuid'; // if you prefer a UUID library\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = configuration;\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [\n editor?.applicationURL,\n editor?.editorURL,\n editor?.cmsURL,\n ] as string[],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = {\n children?: ComponentChildren;\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n};\n\nexport const CommunicatorProvider: FunctionComponent<\n CommunicatorProviderProps\n> = ({ children, allowedOrigins, postMessage }) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(uuid());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins] // senderIdRef.current is stable\n );\n\n return (\n <CommunicatorContext.Provider value={value}>\n {children}\n </CommunicatorContext.Provider>\n );\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":";;;;;;;;;;AAkBA,MAAM,EAAE,WAAW;AAEnB,MAAM,sBAAsB,cAA0C;CACpE,mBAAmB;CACnB,gBAAgB;EACd,QAAQ;EACR,QAAQ;EACR,QAAQ;EACT;CACD,UAAU;CACX,CAAC;AAQF,MAAaA,wBAER,EAAE,UAAU,gBAAgB,kBAAkB;CAEjD,MAAM,cAAc,OAAOC,IAAM,CAAC;CAElC,MAAM,QAAQ,eACL;EAAE;EAAa;EAAgB,UAAU,YAAY;EAAS,GACrE,CAAC,aAAa,eAAe,CAC9B;AAED,QACE,oBAAC,oBAAoB;EAAgB;EAClC;GAC4B;;AAInC,MAAa,wBAAwB,WAAW,oBAAoB"}
@@ -1,27 +1,23 @@
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 { useCrossFrameState } from "./useCrossFrameState.mjs";
9
- const ConfigurationStatesContext = createContext(
10
- void 0
11
- );
12
- const useConfigurationState = () => useCrossFrameState(
13
- MessageKey.INTLAYER_CONFIGURATION,
14
- void 0,
15
- {
16
- receive: false,
17
- emit: true
18
- }
19
- );
20
- const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ jsx(ConfigurationStatesContext.Provider, { value: configuration, children });
5
+ import { MessageKey } from "@intlayer/editor";
6
+ import { createContext, useContext } from "preact/compat";
7
+ import { jsx } from "preact/jsx-runtime";
8
+
9
+ //#region src/editor/ConfigurationContext.tsx
10
+ const ConfigurationStatesContext = createContext(void 0);
11
+ const useConfigurationState = () => useCrossFrameState(MessageKey.INTLAYER_CONFIGURATION, void 0, {
12
+ receive: false,
13
+ emit: true
14
+ });
15
+ const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ jsx(ConfigurationStatesContext.Provider, {
16
+ value: configuration,
17
+ children
18
+ });
21
19
  const useConfiguration = () => useContext(ConfigurationStatesContext);
22
- export {
23
- ConfigurationProvider,
24
- useConfiguration,
25
- useConfigurationState
26
- };
20
+
21
+ //#endregion
22
+ export { ConfigurationProvider, useConfiguration, useConfigurationState };
27
23
  //# sourceMappingURL=ConfigurationContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type FC,\n type PropsWithChildren,\n createContext,\n useContext,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n undefined,\n {\n receive: false,\n emit: true,\n }\n );\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":";AAiCE;AA9BF,SAAS,kBAAkB;AAC3B;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AAEnC,MAAM,6BAA6B;AAAA,EACjC;AACF;AAEO,MAAM,wBAAwB,MACnC;AAAA,EACE,WAAW;AAAA,EACX;AAAA,EACA;AAAA,IACE,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACF;AAMK,MAAM,wBAET,CAAC,EAAE,UAAU,cAAc,MAC7B,oBAAC,2BAA2B,UAA3B,EAAoC,OAAO,eACzC,UACH;AAGK,MAAM,mBAAmB,MAAM,WAAW,0BAA0B;","names":[]}
1
+ {"version":3,"file":"ConfigurationContext.mjs","names":["ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n>"],"sources":["../../../src/editor/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n undefined,\n {\n receive: false,\n emit: true,\n }\n );\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":";;;;;;;;;AAYA,MAAM,6BAA6B,cACjC,OACD;AAED,MAAa,8BACX,mBACE,WAAW,wBACX,QACA;CACE,SAAS;CACT,MAAM;CACP,CACF;AAMH,MAAaA,yBAER,EAAE,UAAU,oBACf,oBAAC,2BAA2B;CAAS,OAAO;CACzC;EACmC;AAGxC,MAAa,yBAAyB,WAAW,2BAA2B"}
@@ -1,76 +1,56 @@
1
- "use client";
2
- import { jsx } from "preact/jsx-runtime";
3
- import { isSameKeyPath } from "@intlayer/core";
4
- import { MessageKey } from "@intlayer/editor";
5
- import {
6
- useCallback,
7
- useMemo
8
- } from "preact/compat";
9
- import { useIntlayerContext } from "../client/index.mjs";
10
- import { ContentSelector } from "../UI/ContentSelector.mjs";
1
+ 'use client';
2
+
3
+
11
4
  import { useCommunicator } from "./CommunicatorContext.mjs";
12
5
  import { useEditorEnabled } from "./EditorEnabledContext.mjs";
13
6
  import { useFocusDictionary } from "./FocusDictionaryContext.mjs";
14
- const ContentSelectorWrapperContent = ({
15
- children,
16
- dictionaryKey,
17
- keyPath
18
- }) => {
19
- const { focusedContent, setFocusedContent } = useFocusDictionary();
20
- const { postMessage, senderId } = useCommunicator();
21
- const handleSelect = useCallback(
22
- () => setFocusedContent({
23
- dictionaryKey,
24
- keyPath
25
- }),
26
- [dictionaryKey, keyPath]
27
- );
28
- const handleHover = useCallback(
29
- () => postMessage({
30
- type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
31
- data: {
32
- dictionaryKey,
33
- keyPath
34
- },
35
- senderId
36
- }),
37
- [dictionaryKey, keyPath]
38
- );
39
- const handleUnhover = useCallback(
40
- () => postMessage({
41
- type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
42
- data: null,
43
- senderId
44
- }),
45
- [senderId]
46
- );
47
- const isSelected = useMemo(
48
- () => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false,
49
- [focusedContent, keyPath, dictionaryKey]
50
- );
51
- return /* @__PURE__ */ jsx(
52
- ContentSelector,
53
- {
54
- onPress: handleSelect,
55
- onHover: handleHover,
56
- onUnhover: handleUnhover,
57
- isSelecting: isSelected,
58
- children
59
- }
60
- );
61
- };
62
- const ContentSelectorRenderer = ({
63
- children,
64
- ...props
65
- }) => {
66
- const { enabled } = useEditorEnabled();
67
- const { disableEditor } = useIntlayerContext();
68
- if (enabled && !disableEditor) {
69
- return /* @__PURE__ */ jsx(ContentSelectorWrapperContent, { ...props, children });
70
- }
71
- return children;
7
+ import { useIntlayerContext } from "../client/IntlayerProvider.mjs";
8
+ import { ContentSelector } from "../UI/ContentSelector.mjs";
9
+ import { isSameKeyPath } from "@intlayer/core";
10
+ import { MessageKey } from "@intlayer/editor";
11
+ import { useCallback, useMemo } from "preact/compat";
12
+ import { jsx } from "preact/jsx-runtime";
13
+
14
+ //#region src/editor/ContentSelectorWrapper.tsx
15
+ const ContentSelectorWrapperContent = ({ children, dictionaryKey, keyPath }) => {
16
+ const { focusedContent, setFocusedContent } = useFocusDictionary();
17
+ const { postMessage, senderId } = useCommunicator();
18
+ return /* @__PURE__ */ jsx(ContentSelector, {
19
+ onPress: useCallback(() => setFocusedContent({
20
+ dictionaryKey,
21
+ keyPath
22
+ }), [dictionaryKey, keyPath]),
23
+ onHover: useCallback(() => postMessage({
24
+ type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
25
+ data: {
26
+ dictionaryKey,
27
+ keyPath
28
+ },
29
+ senderId
30
+ }), [dictionaryKey, keyPath]),
31
+ onUnhover: useCallback(() => postMessage({
32
+ type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
33
+ data: null,
34
+ senderId
35
+ }), [senderId]),
36
+ isSelecting: useMemo(() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false, [
37
+ focusedContent,
38
+ keyPath,
39
+ dictionaryKey
40
+ ]),
41
+ children
42
+ });
72
43
  };
73
- export {
74
- ContentSelectorRenderer
44
+ const ContentSelectorRenderer = ({ children,...props }) => {
45
+ const { enabled } = useEditorEnabled();
46
+ const { disableEditor } = useIntlayerContext();
47
+ if (enabled && !disableEditor) return /* @__PURE__ */ jsx(ContentSelectorWrapperContent, {
48
+ ...props,
49
+ children
50
+ });
51
+ return children;
75
52
  };
53
+
54
+ //#endregion
55
+ export { ContentSelectorRenderer };
76
56
  //# sourceMappingURL=ContentSelectorWrapper.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { type NodeProps, isSameKeyPath } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type FC,\n type HTMLAttributes,\n useCallback,\n useMemo,\n} from 'preact/compat';\nimport { useIntlayerContext } from '../client';\nimport { ContentSelector } from '../UI/ContentSelector';\nimport { useCommunicator } from './CommunicatorContext';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { useFocusDictionary } from './FocusDictionaryContext';\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { postMessage, senderId } = useCommunicator();\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath,\n }),\n [dictionaryKey, keyPath]\n );\n\n const handleHover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: {\n dictionaryKey,\n keyPath,\n },\n senderId,\n }),\n [dictionaryKey, keyPath]\n );\n\n const handleUnhover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: null,\n senderId,\n }),\n [senderId]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false,\n [focusedContent, keyPath, dictionaryKey]\n );\n\n return (\n <ContentSelector\n onPress={handleSelect}\n onHover={handleHover}\n onUnhover={handleUnhover}\n isSelecting={isSelected}\n >\n {children}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorRenderer: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return children;\n};\n"],"mappings":";AAqEI;AAnEJ,SAAyB,qBAAqB;AAC9C,SAAS,kBAAkB;AAC3B;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AAKnC,MAAM,gCAAiE,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,gBAAgB,kBAAkB,IAAI,mBAAmB;AACjE,QAAM,EAAE,aAAa,SAAS,IAAI,gBAAgB;AAElD,QAAM,eAAe;AAAA,IACnB,MACE,kBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,OAAO;AAAA,EACzB;AAEA,QAAM,cAAc;AAAA,IAClB,MACE,YAAY;AAAA,MACV,MAAM,GAAG,WAAW,gCAAgC;AAAA,MACpD,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,OAAO;AAAA,EACzB;AAEA,QAAM,gBAAgB;AAAA,IACpB,MACE,YAAY;AAAA,MACV,MAAM,GAAG,WAAW,gCAAgC;AAAA,MACpD,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,IACH,CAAC,QAAQ;AAAA,EACX;AAEA,QAAM,aAAa;AAAA,IACjB,OACG,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,KACzC,cAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAAA,IACF,CAAC,gBAAgB,SAAS,aAAa;AAAA,EACzC;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAS;AAAA,MACT,SAAS;AAAA,MACT,WAAW;AAAA,MACX,aAAa;AAAA,MAEZ;AAAA;AAAA,EACH;AAEJ;AAEO,MAAM,0BAA2D,CAAC;AAAA,EACvE;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,QAAM,EAAE,cAAc,IAAI,mBAAmB;AAE7C,MAAI,WAAW,CAAC,eAAe;AAC7B,WACE,oBAAC,iCAA+B,GAAG,OAChC,UACH;AAAA,EAEJ;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"file":"ContentSelectorWrapper.mjs","names":["ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps>","ContentSelectorRenderer: FC<ContentSelectorWrapperProps>"],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type NodeProps } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type FC,\n type HTMLAttributes,\n useCallback,\n useMemo,\n} from 'preact/compat';\nimport { useIntlayerContext } from '../client';\nimport { ContentSelector } from '../UI/ContentSelector';\nimport { useCommunicator } from './CommunicatorContext';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { useFocusDictionary } from './FocusDictionaryContext';\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { postMessage, senderId } = useCommunicator();\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath,\n }),\n [dictionaryKey, keyPath]\n );\n\n const handleHover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: {\n dictionaryKey,\n keyPath,\n },\n senderId,\n }),\n [dictionaryKey, keyPath]\n );\n\n const handleUnhover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: null,\n senderId,\n }),\n [senderId]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false,\n [focusedContent, keyPath, dictionaryKey]\n );\n\n return (\n <ContentSelector\n onPress={handleSelect}\n onHover={handleHover}\n onUnhover={handleUnhover}\n isSelecting={isSelected}\n >\n {children}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorRenderer: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return children;\n};\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAMA,iCAAkE,EACtE,UACA,eACA,cACI;CACJ,MAAM,EAAE,gBAAgB,sBAAsB,oBAAoB;CAClE,MAAM,EAAE,aAAa,aAAa,iBAAiB;AA2CnD,QACE,oBAAC;EACC,SA3CiB,kBAEjB,kBAAkB;GAChB;GACA;GACD,CAAC,EACJ,CAAC,eAAe,QAAQ,CACzB;EAqCG,SAnCgB,kBAEhB,YAAY;GACV,MAAM,GAAG,WAAW,iCAAiC;GACrD,MAAM;IACJ;IACA;IACD;GACD;GACD,CAAC,EACJ,CAAC,eAAe,QAAQ,CACzB;EAyBG,WAvBkB,kBAElB,YAAY;GACV,MAAM,GAAG,WAAW,iCAAiC;GACrD,MAAM;GACN;GACD,CAAC,EACJ,CAAC,SAAS,CACX;EAgBG,aAde,eAEd,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,KACzC,cAAc,gBAAgB,WAAW,EAAE,EAAE,QAAQ,KACvD,OACF;GAAC;GAAgB;GAAS;GAAc,CACzC;EASI;GACe;;AAItB,MAAaC,2BAA4D,EACvE,SACA,GAAG,YACC;CACJ,MAAM,EAAE,YAAY,kBAAkB;CACtC,MAAM,EAAE,kBAAkB,oBAAoB;AAE9C,KAAI,WAAW,CAAC,cACd,QACE,oBAAC;EAA8B,GAAI;EAChC;GAC6B;AAIpC,QAAO"}