preact-intlayer 5.5.5 → 5.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/dist/cjs/IntlayerNode.cjs +47 -0
  2. package/dist/cjs/IntlayerNode.cjs.map +1 -0
  3. package/dist/cjs/UI/ContentSelector.cjs +127 -0
  4. package/dist/cjs/UI/ContentSelector.cjs.map +1 -0
  5. package/dist/cjs/client/IntlayerProvider.cjs +98 -0
  6. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
  7. package/dist/cjs/client/getBrowserLocale.cjs +173 -0
  8. package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
  9. package/dist/cjs/client/index.cjs +69 -0
  10. package/dist/cjs/client/index.cjs.map +1 -0
  11. package/dist/cjs/client/t.cjs +37 -0
  12. package/dist/cjs/client/t.cjs.map +1 -0
  13. package/dist/cjs/client/useContent.cjs +39 -0
  14. package/dist/cjs/client/useContent.cjs.map +1 -0
  15. package/dist/cjs/client/useDictionary.cjs +42 -0
  16. package/dist/cjs/client/useDictionary.cjs.map +1 -0
  17. package/dist/cjs/client/useDictionaryDynamic.cjs +42 -0
  18. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -0
  19. package/dist/cjs/client/useIntlayer.cjs +43 -0
  20. package/dist/cjs/client/useIntlayer.cjs.map +1 -0
  21. package/dist/cjs/client/useIntlayerAsync.cjs +54 -0
  22. package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -0
  23. package/dist/cjs/client/useLoadDynamic.cjs +56 -0
  24. package/dist/cjs/client/useLoadDynamic.cjs.map +1 -0
  25. package/dist/cjs/client/useLocale.cjs +69 -0
  26. package/dist/cjs/client/useLocale.cjs.map +1 -0
  27. package/dist/cjs/client/useLocaleBase.cjs +56 -0
  28. package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
  29. package/dist/cjs/client/useLocaleCookie.cjs +60 -0
  30. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -0
  31. package/dist/cjs/client/useTraduction.cjs +35 -0
  32. package/dist/cjs/client/useTraduction.cjs.map +1 -0
  33. package/dist/cjs/editor/ChangedContentContext.cjs +77 -0
  34. package/dist/cjs/editor/ChangedContentContext.cjs.map +1 -0
  35. package/dist/cjs/editor/CommunicatorContext.cjs +66 -0
  36. package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -0
  37. package/dist/cjs/editor/ConfigurationContext.cjs +50 -0
  38. package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -0
  39. package/dist/cjs/editor/ContentSelectorWrapper.cjs +66 -0
  40. package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -0
  41. package/dist/cjs/editor/DictionariesRecordContext.cjs +77 -0
  42. package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -0
  43. package/dist/cjs/editor/EditedContentContext.cjs +217 -0
  44. package/dist/cjs/editor/EditedContentContext.cjs.map +1 -0
  45. package/dist/cjs/editor/EditorEnabledContext.cjs +62 -0
  46. package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -0
  47. package/dist/cjs/editor/EditorProvider.cjs +72 -0
  48. package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
  49. package/dist/cjs/editor/FocusDictionaryContext.cjs +81 -0
  50. package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -0
  51. package/dist/cjs/editor/IntlayerEditorProvider.cjs +122 -0
  52. package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -0
  53. package/dist/cjs/editor/index.cjs +23 -0
  54. package/dist/cjs/editor/index.cjs.map +1 -0
  55. package/dist/cjs/editor/useCrossFrameMessageListener.cjs +53 -0
  56. package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -0
  57. package/dist/cjs/editor/useCrossFrameState.cjs +77 -0
  58. package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -0
  59. package/dist/cjs/editor/useCrossURLPathState.cjs +69 -0
  60. package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -0
  61. package/dist/cjs/editor/useEditedContentRenderer.cjs +63 -0
  62. package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -0
  63. package/dist/cjs/editor/useIframeClickInterceptor.cjs +50 -0
  64. package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -0
  65. package/dist/cjs/getDictionary.cjs +43 -0
  66. package/dist/cjs/getDictionary.cjs.map +1 -0
  67. package/dist/cjs/getIntlayer.cjs +39 -0
  68. package/dist/cjs/getIntlayer.cjs.map +1 -0
  69. package/dist/cjs/index.cjs +42 -5
  70. package/dist/cjs/index.cjs.map +1 -1
  71. package/dist/cjs/markdown/MarkdownProvider.cjs +41 -0
  72. package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -0
  73. package/dist/cjs/markdown/MarkdownRenderer.cjs +83 -0
  74. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
  75. package/dist/cjs/markdown/index.cjs +25 -0
  76. package/dist/cjs/markdown/index.cjs.map +1 -0
  77. package/dist/cjs/plugins.cjs +128 -0
  78. package/dist/cjs/plugins.cjs.map +1 -0
  79. package/dist/cjs/preactElement/renderPreactElement.cjs +62 -0
  80. package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -0
  81. package/dist/esm/IntlayerNode.mjs +27 -0
  82. package/dist/esm/IntlayerNode.mjs.map +1 -0
  83. package/dist/esm/UI/ContentSelector.mjs +103 -0
  84. package/dist/esm/UI/ContentSelector.mjs.map +1 -0
  85. package/dist/esm/client/IntlayerProvider.mjs +63 -0
  86. package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
  87. package/dist/esm/client/getBrowserLocale.mjs +138 -0
  88. package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
  89. package/dist/esm/client/index.mjs +39 -0
  90. package/dist/esm/client/index.mjs.map +1 -0
  91. package/dist/esm/client/t.mjs +13 -0
  92. package/dist/esm/client/t.mjs.map +1 -0
  93. package/dist/esm/client/useContent.mjs +15 -0
  94. package/dist/esm/client/useContent.mjs.map +1 -0
  95. package/dist/esm/client/useDictionary.mjs +18 -0
  96. package/dist/esm/client/useDictionary.mjs.map +1 -0
  97. package/dist/esm/client/useDictionaryDynamic.mjs +18 -0
  98. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -0
  99. package/dist/esm/client/useIntlayer.mjs +19 -0
  100. package/dist/esm/client/useIntlayer.mjs.map +1 -0
  101. package/dist/esm/client/useIntlayerAsync.mjs +33 -0
  102. package/dist/esm/client/useIntlayerAsync.mjs.map +1 -0
  103. package/dist/esm/client/useLoadDynamic.mjs +32 -0
  104. package/dist/esm/client/useLoadDynamic.mjs.map +1 -0
  105. package/dist/esm/client/useLocale.mjs +35 -0
  106. package/dist/esm/client/useLocale.mjs.map +1 -0
  107. package/dist/esm/client/useLocaleBase.mjs +22 -0
  108. package/dist/esm/client/useLocaleBase.mjs.map +1 -0
  109. package/dist/esm/client/useLocaleCookie.mjs +24 -0
  110. package/dist/esm/client/useLocaleCookie.mjs.map +1 -0
  111. package/dist/esm/client/useTraduction.mjs +11 -0
  112. package/dist/esm/client/useTraduction.mjs.map +1 -0
  113. package/dist/esm/editor/ChangedContentContext.mjs +55 -0
  114. package/dist/esm/editor/ChangedContentContext.mjs.map +1 -0
  115. package/dist/esm/editor/CommunicatorContext.mjs +33 -0
  116. package/dist/esm/editor/CommunicatorContext.mjs.map +1 -0
  117. package/dist/esm/editor/ConfigurationContext.mjs +27 -0
  118. package/dist/esm/editor/ConfigurationContext.mjs.map +1 -0
  119. package/dist/esm/editor/ContentSelectorWrapper.mjs +45 -0
  120. package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -0
  121. package/dist/esm/editor/DictionariesRecordContext.mjs +55 -0
  122. package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -0
  123. package/dist/esm/editor/EditedContentContext.mjs +198 -0
  124. package/dist/esm/editor/EditedContentContext.mjs.map +1 -0
  125. package/dist/esm/editor/EditorEnabledContext.mjs +39 -0
  126. package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -0
  127. package/dist/esm/editor/EditorProvider.mjs +62 -0
  128. package/dist/esm/editor/EditorProvider.mjs.map +1 -0
  129. package/dist/esm/editor/FocusDictionaryContext.mjs +58 -0
  130. package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -0
  131. package/dist/esm/editor/IntlayerEditorProvider.mjs +88 -0
  132. package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -0
  133. package/dist/esm/editor/index.mjs +2 -0
  134. package/dist/esm/editor/index.mjs.map +1 -0
  135. package/dist/esm/editor/useCrossFrameMessageListener.mjs +29 -0
  136. package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -0
  137. package/dist/esm/editor/useCrossFrameState.mjs +53 -0
  138. package/dist/esm/editor/useCrossFrameState.mjs.map +1 -0
  139. package/dist/esm/editor/useCrossURLPathState.mjs +46 -0
  140. package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -0
  141. package/dist/esm/editor/useEditedContentRenderer.mjs +38 -0
  142. package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -0
  143. package/dist/esm/editor/useIframeClickInterceptor.mjs +25 -0
  144. package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -0
  145. package/dist/esm/getDictionary.mjs +25 -0
  146. package/dist/esm/getDictionary.mjs.map +1 -0
  147. package/dist/esm/getIntlayer.mjs +21 -0
  148. package/dist/esm/getIntlayer.mjs.map +1 -0
  149. package/dist/esm/index.mjs +38 -2
  150. package/dist/esm/index.mjs.map +1 -1
  151. package/dist/esm/markdown/MarkdownProvider.mjs +19 -0
  152. package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -0
  153. package/dist/esm/markdown/MarkdownRenderer.mjs +62 -0
  154. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
  155. package/dist/esm/markdown/index.mjs +3 -0
  156. package/dist/esm/markdown/index.mjs.map +1 -0
  157. package/dist/esm/plugins.mjs +104 -0
  158. package/dist/esm/plugins.mjs.map +1 -0
  159. package/dist/esm/preactElement/renderPreactElement.mjs +38 -0
  160. package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -0
  161. package/dist/types/IntlayerNode.d.ts +15 -0
  162. package/dist/types/IntlayerNode.d.ts.map +1 -0
  163. package/dist/types/UI/ContentSelector.d.ts +10 -0
  164. package/dist/types/UI/ContentSelector.d.ts.map +1 -0
  165. package/dist/types/client/IntlayerProvider.d.ts +29 -0
  166. package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
  167. package/dist/types/client/getBrowserLocale.d.ts +25 -0
  168. package/dist/types/client/getBrowserLocale.d.ts.map +1 -0
  169. package/dist/types/client/index.d.ts +12 -0
  170. package/dist/types/client/index.d.ts.map +1 -0
  171. package/dist/types/client/t.d.ts +9 -0
  172. package/dist/types/client/t.d.ts.map +1 -0
  173. package/dist/types/client/useContent.d.ts +10 -0
  174. package/dist/types/client/useContent.d.ts.map +1 -0
  175. package/dist/types/client/useDictionary.d.ts +9 -0
  176. package/dist/types/client/useDictionary.d.ts.map +1 -0
  177. package/dist/types/client/useDictionaryDynamic.d.ts +9 -0
  178. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
  179. package/dist/types/client/useIntlayer.d.ts +11 -0
  180. package/dist/types/client/useIntlayer.d.ts.map +1 -0
  181. package/dist/types/client/useIntlayerAsync.d.ts +14 -0
  182. package/dist/types/client/useIntlayerAsync.d.ts.map +1 -0
  183. package/dist/types/client/useLoadDynamic.d.ts +2 -0
  184. package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
  185. package/dist/types/client/useLocale.d.ts +15 -0
  186. package/dist/types/client/useLocale.d.ts.map +1 -0
  187. package/dist/types/client/useLocaleBase.d.ts +10 -0
  188. package/dist/types/client/useLocaleBase.d.ts.map +1 -0
  189. package/dist/types/client/useLocaleCookie.d.ts +17 -0
  190. package/dist/types/client/useLocaleCookie.d.ts.map +1 -0
  191. package/dist/types/client/useTraduction.d.ts +24 -0
  192. package/dist/types/client/useTraduction.d.ts.map +1 -0
  193. package/dist/types/editor/ChangedContentContext.d.ts +13 -0
  194. package/dist/types/editor/ChangedContentContext.d.ts.map +1 -0
  195. package/dist/types/editor/CommunicatorContext.d.ts +14 -0
  196. package/dist/types/editor/CommunicatorContext.d.ts.map +1 -0
  197. package/dist/types/editor/ConfigurationContext.d.ts +9 -0
  198. package/dist/types/editor/ConfigurationContext.d.ts.map +1 -0
  199. package/dist/types/editor/ContentSelectorWrapper.d.ts +5 -0
  200. package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -0
  201. package/dist/types/editor/DictionariesRecordContext.d.ts +16 -0
  202. package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -0
  203. package/dist/types/editor/EditedContentContext.d.ts +33 -0
  204. package/dist/types/editor/EditedContentContext.d.ts.map +1 -0
  205. package/dist/types/editor/EditorEnabledContext.d.ts +11 -0
  206. package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -0
  207. package/dist/types/editor/EditorProvider.d.ts +6 -0
  208. package/dist/types/editor/EditorProvider.d.ts.map +1 -0
  209. package/dist/types/editor/FocusDictionaryContext.d.ts +21 -0
  210. package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -0
  211. package/dist/types/editor/IntlayerEditorProvider.d.ts +5 -0
  212. package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -0
  213. package/dist/types/editor/index.d.ts +2 -0
  214. package/dist/types/editor/index.d.ts.map +1 -0
  215. package/dist/types/editor/useCrossFrameMessageListener.d.ts +19 -0
  216. package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -0
  217. package/dist/types/editor/useCrossFrameState.d.ts +30 -0
  218. package/dist/types/editor/useCrossFrameState.d.ts.map +1 -0
  219. package/dist/types/editor/useCrossURLPathState.d.ts +4 -0
  220. package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -0
  221. package/dist/types/editor/useEditedContentRenderer.d.ts +13 -0
  222. package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -0
  223. package/dist/types/editor/useIframeClickInterceptor.d.ts +3 -0
  224. package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -0
  225. package/dist/types/getDictionary.d.ts +5 -0
  226. package/dist/types/getDictionary.d.ts.map +1 -0
  227. package/dist/types/getIntlayer.d.ts +5 -0
  228. package/dist/types/getIntlayer.d.ts.map +1 -0
  229. package/dist/types/index.d.ts +8 -2
  230. package/dist/types/index.d.ts.map +1 -1
  231. package/dist/types/markdown/MarkdownProvider.d.ts +9 -0
  232. package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
  233. package/dist/types/markdown/MarkdownRenderer.d.ts +16 -0
  234. package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
  235. package/dist/types/markdown/index.d.ts +3 -0
  236. package/dist/types/markdown/index.d.ts.map +1 -0
  237. package/dist/types/plugins.d.ts +54 -0
  238. package/dist/types/plugins.d.ts.map +1 -0
  239. package/dist/types/preactElement/renderPreactElement.d.ts +5 -0
  240. package/dist/types/preactElement/renderPreactElement.d.ts.map +1 -0
  241. package/package.json +17 -10
  242. package/dist/cjs/intlayerMiddlewarePlugin.cjs +0 -224
  243. package/dist/cjs/intlayerMiddlewarePlugin.cjs.map +0 -1
  244. package/dist/cjs/intlayerPlugin.cjs +0 -76
  245. package/dist/cjs/intlayerPlugin.cjs.map +0 -1
  246. package/dist/esm/intlayerMiddlewarePlugin.mjs +0 -200
  247. package/dist/esm/intlayerMiddlewarePlugin.mjs.map +0 -1
  248. package/dist/esm/intlayerPlugin.mjs +0 -52
  249. package/dist/esm/intlayerPlugin.mjs.map +0 -1
  250. package/dist/types/intlayerMiddlewarePlugin.d.ts +0 -6
  251. package/dist/types/intlayerMiddlewarePlugin.d.ts.map +0 -1
  252. package/dist/types/intlayerPlugin.d.ts +0 -16
  253. package/dist/types/intlayerPlugin.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core';\nimport {\n type ComponentChildren,\n Fragment,\n type VNode,\n h,\n isValidElement,\n} from 'preact';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = {},\n> = VNode & {\n value: T;\n} & AdditionalProps;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: ComponentChildren;\n additionalProps?: { [key: string]: any };\n};\n\nexport const renderIntlayerNode = <\n T extends number | string | boolean | undefined | null,\n>({\n children,\n value,\n additionalProps,\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n // If children is not a valid VNode, wrap it in a fragment\n const element: VNode<any> = isValidElement(children)\n ? children\n : h(Fragment, {}, children);\n\n // Return a Proxy that pretends to be the original element\n // but also has a .value getter.\n return new Proxy(element as VNode, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return value;\n }\n\n if (\n additionalProps &&\n Object.keys(additionalProps).includes(prop as string)\n ) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n};\n"],"mappings":"AACA;AAAA,EAEE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AAeA,MAAM,qBAAqB,CAEhC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAmD;AAEjD,QAAM,UAAsB,eAAe,QAAQ,IAC/C,WACA,EAAE,UAAU,CAAC,GAAG,QAAQ;AAI5B,SAAO,IAAI,MAAM,SAAkB;AAAA,IACjC,IAAI,QAAQ,MAAM,UAAU;AAC1B,UAAI,SAAS,SAAS;AACpB,eAAO;AAAA,MACT;AAEA,UACE,mBACA,OAAO,KAAK,eAAe,EAAE,SAAS,IAAc,GACpD;AACA,eAAO,gBAAgB,IAAoC;AAAA,MAC7D;AAEA,aAAO,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAAA,IAC3C;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,103 @@
1
+ "use client";
2
+ import { jsx } from "preact/jsx-runtime";
3
+ import { useCallback, useEffect, useRef, useState } from "preact/hooks";
4
+ const DEFAULT_PRESS_DETECT_DURATION = 250;
5
+ const ContentSelector = ({
6
+ children,
7
+ onPress: onSelect,
8
+ onClickOutside: onUnselect,
9
+ pressDuration = DEFAULT_PRESS_DETECT_DURATION,
10
+ isSelecting: isSelectingProp,
11
+ ...props
12
+ }) => {
13
+ const divRef = useRef(null);
14
+ const [isHovered, setIsHovered] = useState(false);
15
+ const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);
16
+ const pressTimerRef = useRef(null);
17
+ const isChildrenString = typeof children === "string";
18
+ const handleOnLongPress = () => {
19
+ setIsSelectingState(true);
20
+ onSelect();
21
+ };
22
+ const startPressTimer = () => {
23
+ pressTimerRef.current = setTimeout(() => {
24
+ handleOnLongPress();
25
+ }, pressDuration);
26
+ };
27
+ const clearPressTimer = () => {
28
+ if (pressTimerRef.current) {
29
+ clearTimeout(pressTimerRef.current);
30
+ pressTimerRef.current = null;
31
+ }
32
+ };
33
+ const handleMouseDown = () => {
34
+ clearPressTimer();
35
+ startPressTimer();
36
+ };
37
+ const handleMouseEnter = () => {
38
+ setIsHovered(true);
39
+ };
40
+ const handleMouseUp = () => {
41
+ setIsHovered(false);
42
+ clearPressTimer();
43
+ };
44
+ const handleClickOutside = useCallback(
45
+ (event) => {
46
+ if (divRef.current && !divRef.current.contains(event.target)) {
47
+ setIsSelectingState(false);
48
+ onUnselect?.();
49
+ }
50
+ },
51
+ [onUnselect]
52
+ );
53
+ useEffect(() => {
54
+ document.addEventListener("mousedown", handleClickOutside);
55
+ return () => {
56
+ document.removeEventListener("mousedown", handleClickOutside);
57
+ };
58
+ }, [handleClickOutside]);
59
+ const handleOnClick = (e) => {
60
+ if (isSelectingState) {
61
+ e.preventDefault();
62
+ e.stopPropagation();
63
+ }
64
+ };
65
+ const handleOnBlur = () => {
66
+ setIsSelectingState(false);
67
+ };
68
+ return /* @__PURE__ */ jsx(
69
+ "span",
70
+ {
71
+ style: {
72
+ display: isChildrenString ? "inline" : "inline-block",
73
+ cursor: "pointer",
74
+ userSelect: "none",
75
+ borderRadius: "0.375rem",
76
+ outlineWidth: "2px",
77
+ outlineOffset: "4px",
78
+ outlineStyle: "solid",
79
+ outlineColor: isSelectingProp || isSelectingState || isHovered ? "inherit" : "transparent",
80
+ transition: "all 100ms 50ms ease-in-out"
81
+ },
82
+ role: "button",
83
+ tabIndex: 0,
84
+ onKeyUp: () => null,
85
+ onClick: handleOnClick,
86
+ onMouseDown: handleMouseDown,
87
+ onMouseUp: handleMouseUp,
88
+ onMouseLeave: handleMouseUp,
89
+ onTouchStart: handleMouseDown,
90
+ onTouchEnd: handleMouseUp,
91
+ onTouchCancel: handleMouseUp,
92
+ onBlur: handleOnBlur,
93
+ onMouseEnter: handleMouseEnter,
94
+ ref: divRef,
95
+ ...props,
96
+ children
97
+ }
98
+ );
99
+ };
100
+ export {
101
+ ContentSelector
102
+ };
103
+ //# sourceMappingURL=ContentSelector.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport { FC, HTMLAttributes, MouseEventHandler } from 'preact/compat';\nimport { useCallback, useEffect, useRef, useState } from 'preact/hooks';\n\nconst DEFAULT_PRESS_DETECT_DURATION = 250;\n\ntype ContentSelectorProps = {\n onPress: () => void;\n onClickOutside?: () => void;\n pressDuration?: number;\n isSelecting?: boolean;\n} & Omit<HTMLAttributes<HTMLDivElement>, 'content'>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n onPress: onSelect,\n onClickOutside: onUnselect,\n pressDuration = DEFAULT_PRESS_DETECT_DURATION,\n isSelecting: isSelectingProp,\n ...props\n}) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isHovered, setIsHovered] = useState(false);\n const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const isChildrenString = typeof children === 'string';\n\n const handleOnLongPress = () => {\n setIsSelectingState(true);\n onSelect();\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, pressDuration);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseEnter = () => {\n setIsHovered(true);\n };\n\n const handleMouseUp = () => {\n setIsHovered(false);\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsSelectingState(false);\n onUnselect?.();\n }\n },\n [onUnselect]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n // clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: MouseEventHandler<HTMLDivElement> = (e) => {\n if (isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsSelectingState(false);\n };\n\n return (\n <span\n style={{\n display: isChildrenString ? 'inline' : 'inline-block',\n cursor: 'pointer',\n userSelect: 'none',\n borderRadius: '0.375rem',\n outlineWidth: '2px',\n outlineOffset: '4px',\n outlineStyle: 'solid',\n outlineColor:\n isSelectingProp || isSelectingState || isHovered\n ? 'inherit'\n : 'transparent',\n transition: 'all 100ms 50ms ease-in-out',\n }}\n role=\"button\"\n tabIndex={0}\n onKeyUp={() => null}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n onMouseEnter={handleMouseEnter}\n ref={divRef}\n {...props}\n >\n {children}\n </span>\n );\n};\n"],"mappings":";AA+FI;AA5FJ,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAEzD,MAAM,gCAAgC;AAS/B,MAAM,kBAA4C,CAAC;AAAA,EACxD;AAAA,EACA,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,GAAG;AACL,MAAM;AACJ,QAAM,SAAS,OAAuB,IAAI;AAC1C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAS,eAAe;AACxE,QAAM,gBAAgB,OAA6C,IAAI;AACvE,QAAM,mBAAmB,OAAO,aAAa;AAE7C,QAAM,oBAAoB,MAAM;AAC9B,wBAAoB,IAAI;AACxB,aAAS;AAAA,EACX;AAEA,QAAM,kBAAkB,MAAM;AAC5B,kBAAc,UAAU,WAAW,MAAM;AACvC,wBAAkB;AAAA,IACpB,GAAG,aAAa;AAAA,EAClB;AAEA,QAAM,kBAAkB,MAAM;AAC5B,QAAI,cAAc,SAAS;AACzB,mBAAa,cAAc,OAAO;AAClC,oBAAc,UAAU;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,kBAAkB,MAAM;AAC5B,oBAAgB;AAChB,oBAAgB;AAAA,EAClB;AAEA,QAAM,mBAAmB,MAAM;AAC7B,iBAAa,IAAI;AAAA,EACnB;AAEA,QAAM,gBAAgB,MAAM;AAC1B,iBAAa,KAAK;AAClB,oBAAgB;AAAA,EAClB;AAGA,QAAM,qBAAqB;AAAA,IACzB,CAAC,UAAsB;AACrB,UAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,MAAc,GAAG;AACpE,4BAAoB,KAAK;AACzB,qBAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,YAAU,MAAM;AAEd,aAAS,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AAEX,eAAS,oBAAoB,aAAa,kBAAkB;AAAA,IAE9D;AAAA,EACF,GAAG,CAAC,kBAAkB,CAAC;AAEvB,QAAM,gBAAmD,CAAC,MAAM;AAC9D,QAAI,kBAAkB;AACpB,QAAE,eAAe;AACjB,QAAE,gBAAgB;AAAA,IACpB;AAAA,EACF;AAEA,QAAM,eAAe,MAAM;AAEzB,wBAAoB,KAAK;AAAA,EAC3B;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,SAAS,mBAAmB,WAAW;AAAA,QACvC,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,cAAc;AAAA,QACd,eAAe;AAAA,QACf,cAAc;AAAA,QACd,cACE,mBAAmB,oBAAoB,YACnC,YACA;AAAA,QACN,YAAY;AAAA,MACd;AAAA,MACA,MAAK;AAAA,MACL,UAAU;AAAA,MACV,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,MACT,aAAa;AAAA,MACb,WAAW;AAAA,MACX,cAAc;AAAA,MACd,cAAc;AAAA,MACd,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,QAAQ;AAAA,MACR,cAAc;AAAA,MACd,KAAK;AAAA,MACJ,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;","names":[]}
@@ -0,0 +1,63 @@
1
+ "use client";
2
+ import { jsx } from "preact/jsx-runtime";
3
+ import configuration from "@intlayer/config/built";
4
+ import { localeResolver } from "@intlayer/core";
5
+ import { MessageKey } from "@intlayer/editor";
6
+ import {
7
+ createContext
8
+ } from "preact";
9
+ import { useContext } from "preact/hooks";
10
+ import { IntlayerEditorProvider } from "../editor/IntlayerEditorProvider.mjs";
11
+ import { useCrossFrameState } from "../editor/useCrossFrameState.mjs";
12
+ import { localeCookie, setLocaleCookie } from "./useLocaleCookie.mjs";
13
+ const IntlayerClientContext = createContext({
14
+ locale: localeCookie ?? configuration?.internationalization?.defaultLocale,
15
+ setLocale: () => null,
16
+ disableEditor: false
17
+ });
18
+ const useIntlayerContext = () => useContext(IntlayerClientContext);
19
+ const IntlayerProviderContent = ({
20
+ locale: localeProp,
21
+ defaultLocale: defaultLocaleProp,
22
+ children,
23
+ setLocale: setLocaleProp,
24
+ disableEditor
25
+ }) => {
26
+ const { internationalization } = configuration ?? {};
27
+ const { defaultLocale: defaultLocaleConfig, locales: availableLocales } = internationalization ?? {};
28
+ const defaultLocale = localeProp ?? localeCookie ?? defaultLocaleProp ?? defaultLocaleConfig;
29
+ const [currentLocale, setCurrentLocale] = useCrossFrameState(
30
+ MessageKey.INTLAYER_CURRENT_LOCALE,
31
+ defaultLocale
32
+ );
33
+ const setLocaleBase = (newLocale) => {
34
+ if (currentLocale.toString() === newLocale.toString()) return;
35
+ if (!availableLocales?.map(String).includes(newLocale)) {
36
+ console.error(`Locale ${newLocale} is not available`);
37
+ return;
38
+ }
39
+ setCurrentLocale(newLocale);
40
+ setLocaleCookie(newLocale);
41
+ };
42
+ const setLocale = setLocaleProp ?? setLocaleBase;
43
+ const resolvedLocale = localeResolver(localeProp ?? currentLocale);
44
+ return /* @__PURE__ */ jsx(
45
+ IntlayerClientContext.Provider,
46
+ {
47
+ value: {
48
+ locale: resolvedLocale,
49
+ setLocale,
50
+ disableEditor
51
+ },
52
+ children
53
+ }
54
+ );
55
+ };
56
+ const IntlayerProvider = (props) => /* @__PURE__ */ jsx(IntlayerEditorProvider, { children: /* @__PURE__ */ jsx(IntlayerProviderContent, { ...props }) });
57
+ export {
58
+ IntlayerClientContext,
59
+ IntlayerProvider,
60
+ IntlayerProviderContent,
61
+ useIntlayerContext
62
+ };
63
+ //# sourceMappingURL=IntlayerProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\nimport { localeResolver } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type ComponentChild,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { useCrossFrameState } from '../editor/useCrossFrameState';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n disableEditor?: boolean;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? configuration?.internationalization?.defaultLocale,\n setLocale: () => null,\n disableEditor: false,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = {\n children?: ComponentChild;\n locale?: LocalesValues;\n defaultLocale?: LocalesValues;\n setLocale?: (locale: LocalesValues) => void;\n disableEditor?: boolean;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProviderContent: FunctionComponent<\n IntlayerProviderProps\n> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n}) => {\n const { internationalization } = configuration ?? {};\n const { defaultLocale: defaultLocaleConfig, locales: availableLocales } =\n internationalization ?? {};\n\n const defaultLocale =\n localeProp ?? localeCookie ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] = useCrossFrameState(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n defaultLocale\n );\n\n const setLocaleBase = (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n };\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const resolvedLocale = localeResolver(localeProp ?? currentLocale);\n\n return (\n <IntlayerClientContext.Provider\n value={{\n locale: resolvedLocale,\n setLocale,\n disableEditor,\n }}\n >\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\nexport const IntlayerProvider: FunctionComponent<IntlayerProviderProps> = (\n props\n) => (\n <IntlayerEditorProvider>\n <IntlayerProviderContent {...props} />\n </IntlayerEditorProvider>\n);\n"],"mappings":";AAqFI;AAnFJ,OAAO,mBAAmB;AAE1B,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,kBAAkB;AAC3B,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,cAAc,uBAAuB;AAWvC,MAAM,wBAAwB,cAA6B;AAAA,EAChE,QAAQ,gBAAgB,eAAe,sBAAsB;AAAA,EAC7D,WAAW,MAAM;AAAA,EACjB,eAAe;AACjB,CAAC;AAKM,MAAM,qBAAqB,MAAM,WAAW,qBAAqB;AAajE,MAAM,0BAET,CAAC;AAAA,EACH,QAAQ;AAAA,EACR,eAAe;AAAA,EACf;AAAA,EACA,WAAW;AAAA,EACX;AACF,MAAM;AACJ,QAAM,EAAE,qBAAqB,IAAI,iBAAiB,CAAC;AACnD,QAAM,EAAE,eAAe,qBAAqB,SAAS,iBAAiB,IACpE,wBAAwB,CAAC;AAE3B,QAAM,gBACJ,cAAc,gBAAgB,qBAAqB;AAErD,QAAM,CAAC,eAAe,gBAAgB,IAAI;AAAA,IACxC,WAAW;AAAA,IACX;AAAA,EACF;AAEA,QAAM,gBAAgB,CAAC,cAA6B;AAClD,QAAI,cAAc,SAAS,MAAM,UAAU,SAAS,EAAG;AAEvD,QAAI,CAAC,kBAAkB,IAAI,MAAM,EAAE,SAAS,SAAS,GAAG;AACtD,cAAQ,MAAM,UAAU,SAAS,mBAAmB;AACpD;AAAA,IACF;AAEA,qBAAiB,SAAS;AAC1B,oBAAgB,SAAS;AAAA,EAC3B;AAEA,QAAM,YAAY,iBAAiB;AAEnC,QAAM,iBAAiB,eAAe,cAAc,aAAa;AAEjE,SACE;AAAA,IAAC,sBAAsB;AAAA,IAAtB;AAAA,MACC,OAAO;AAAA,QACL,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,MAAM,mBAA6D,CACxE,UAEA,oBAAC,0BACC,8BAAC,2BAAyB,GAAG,OAAO,GACtC;","names":[]}
@@ -0,0 +1,138 @@
1
+ import configuration from "@intlayer/config/built";
2
+ import { Locales } from "@intlayer/config/client";
3
+ var LanguageDetector = /* @__PURE__ */ ((LanguageDetector2) => {
4
+ LanguageDetector2["Querystring"] = "querystring";
5
+ LanguageDetector2["Cookie"] = "cookie";
6
+ LanguageDetector2["LocalStorage"] = "localStorage";
7
+ LanguageDetector2["SessionStorage"] = "sessionStorage";
8
+ LanguageDetector2["Navigator"] = "navigator";
9
+ LanguageDetector2["HtmlTag"] = "htmlTag";
10
+ return LanguageDetector2;
11
+ })(LanguageDetector || {});
12
+ const getDefaultsOptions = () => {
13
+ const { middleware } = configuration;
14
+ return {
15
+ order: [
16
+ "querystring" /* Querystring */,
17
+ "cookie" /* Cookie */,
18
+ "navigator" /* Navigator */,
19
+ "htmlTag" /* HtmlTag */
20
+ ],
21
+ lookupQuerystring: "locale",
22
+ lookupCookie: middleware?.cookieName,
23
+ htmlTag: document.documentElement
24
+ };
25
+ };
26
+ const isLocalStorageAvailable = () => {
27
+ try {
28
+ if (typeof window === "undefined") return false;
29
+ const testKey = "intlayer.translate.boo";
30
+ window.localStorage.setItem(testKey, "foo");
31
+ window.localStorage.removeItem(testKey);
32
+ return true;
33
+ } catch {
34
+ return false;
35
+ }
36
+ };
37
+ const isSessionStorageAvailable = () => {
38
+ try {
39
+ if (typeof window === "undefined") return false;
40
+ const testKey = "intlayer.translate.boo";
41
+ window.sessionStorage.setItem(testKey, "foo");
42
+ window.sessionStorage.removeItem(testKey);
43
+ return true;
44
+ } catch {
45
+ return false;
46
+ }
47
+ };
48
+ const detectLanguage = (order, options) => {
49
+ const detected = {};
50
+ const queryStringDetector = () => {
51
+ if (typeof window === "undefined") return;
52
+ const search = window.location.search || "";
53
+ const params = new URLSearchParams(search);
54
+ const value = params.get(options.lookupQuerystring ?? "");
55
+ if (value) {
56
+ detected["querystring" /* Querystring */] = value;
57
+ }
58
+ };
59
+ const cookieDetector = () => {
60
+ if (typeof document === "undefined") return;
61
+ const cookies = document.cookie.split(";");
62
+ const cookieName = `${options.lookupCookie ?? ""}=`;
63
+ const cookie = cookies.find((c) => c.trim().startsWith(cookieName));
64
+ if (cookie) {
65
+ const value = cookie.split("=")[1].trim();
66
+ detected["cookie" /* Cookie */] = value;
67
+ }
68
+ };
69
+ const localStorageDetector = () => {
70
+ if (!isLocalStorageAvailable()) return;
71
+ const value = window.localStorage.getItem(options.lookupLocalStorage ?? "");
72
+ if (value) {
73
+ detected["localStorage" /* LocalStorage */] = value;
74
+ }
75
+ };
76
+ const sessionStorageDetector = () => {
77
+ if (!isSessionStorageAvailable()) return;
78
+ const value = window.sessionStorage.getItem(
79
+ options.lookupSessionStorage ?? ""
80
+ );
81
+ if (value) {
82
+ detected["sessionStorage" /* SessionStorage */] = value;
83
+ }
84
+ };
85
+ const navigatorDetector = () => {
86
+ if (typeof navigator === "undefined") return;
87
+ if (navigator.language) {
88
+ detected["navigator" /* Navigator */] = navigator.language;
89
+ }
90
+ };
91
+ const htmlTagDetector = () => {
92
+ const htmlTag = options.htmlTag;
93
+ if (htmlTag && typeof htmlTag.getAttribute === "function") {
94
+ const lang = htmlTag.getAttribute("lang");
95
+ if (lang) {
96
+ detected["htmlTag" /* HtmlTag */] = lang;
97
+ }
98
+ }
99
+ };
100
+ const detectors = {
101
+ ["querystring" /* Querystring */]: queryStringDetector,
102
+ ["cookie" /* Cookie */]: cookieDetector,
103
+ ["localStorage" /* LocalStorage */]: localStorageDetector,
104
+ ["sessionStorage" /* SessionStorage */]: sessionStorageDetector,
105
+ ["navigator" /* Navigator */]: navigatorDetector,
106
+ ["htmlTag" /* HtmlTag */]: htmlTagDetector
107
+ };
108
+ order.forEach((detectorName) => {
109
+ detectors[detectorName]?.();
110
+ });
111
+ return detected;
112
+ };
113
+ const getFirstAvailableLocale = (locales, order) => {
114
+ const { internationalization } = configuration;
115
+ for (const detector of order) {
116
+ const localesArray = [locales[detector]].flat();
117
+ for (const locale of localesArray) {
118
+ if (locale && (internationalization?.locales).includes(locale)) {
119
+ return locale;
120
+ } else if (locale?.includes("-") && (internationalization?.locales).includes(
121
+ locale.split("-")[0]
122
+ )) {
123
+ return locale.split("-")[0];
124
+ }
125
+ }
126
+ }
127
+ return internationalization?.defaultLocale ?? Locales.ENGLISH;
128
+ };
129
+ const getBrowserLocale = (userOptions = {}) => {
130
+ const options = { ...getDefaultsOptions(), ...userOptions };
131
+ const locales = detectLanguage(options.order ?? [], options);
132
+ return getFirstAvailableLocale(locales, options.order ?? []);
133
+ };
134
+ export {
135
+ LanguageDetector,
136
+ getBrowserLocale
137
+ };
138
+ //# sourceMappingURL=getBrowserLocale.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/getBrowserLocale.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { Locales } from '@intlayer/config/client';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Cookie = 'cookie',\n LocalStorage = 'localStorage',\n SessionStorage = 'sessionStorage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n lookupCookie?: string;\n lookupLocalStorage?: string;\n lookupSessionStorage?: string;\n excludeCacheFor?: string[];\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n const { middleware } = configuration;\n\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Cookie,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n lookupCookie: middleware?.cookieName,\n htmlTag: document.documentElement,\n };\n};\n\n// Helper functions for various checks and operations\nconst isLocalStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.localStorage.setItem(testKey, 'foo');\n window.localStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isSessionStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.sessionStorage.setItem(testKey, 'foo');\n window.sessionStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\n// Function to detect language using different detectors\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locales | Locales[]> => {\n const detected: Record<LanguageDetector, Locales | Locales[]> = {} as Record<\n LanguageDetector,\n Locales | Locales[]\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locales;\n }\n };\n\n const cookieDetector = () => {\n if (typeof document === 'undefined') return;\n const cookies = document.cookie.split(';');\n const cookieName = `${options.lookupCookie ?? ''}=`;\n const cookie = cookies.find((c) => c.trim().startsWith(cookieName));\n if (cookie) {\n const value = cookie.split('=')[1].trim();\n\n detected[LanguageDetector.Cookie] = value as Locales;\n }\n };\n\n const localStorageDetector = () => {\n if (!isLocalStorageAvailable()) return;\n const value = window.localStorage.getItem(options.lookupLocalStorage ?? '');\n if (value) {\n detected[LanguageDetector.LocalStorage] = value as Locales;\n }\n };\n\n const sessionStorageDetector = () => {\n if (!isSessionStorageAvailable()) return;\n const value = window.sessionStorage.getItem(\n options.lookupSessionStorage ?? ''\n );\n if (value) {\n detected[LanguageDetector.SessionStorage] = value as Locales;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n if (navigator.language) {\n detected[LanguageDetector.Navigator] = navigator.language as Locales;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n detected[LanguageDetector.HtmlTag] = lang as Locales;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Cookie]: cookieDetector,\n [LanguageDetector.LocalStorage]: localStorageDetector,\n [LanguageDetector.SessionStorage]: sessionStorageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locales | Locales[]>,\n order: LanguageDetector[]\n): Locales => {\n const { internationalization } = configuration;\n\n for (const detector of order) {\n const localesArray = [locales[detector]].flat();\n\n for (const locale of localesArray) {\n if (locale && (internationalization?.locales).includes(locale)) {\n return locale;\n } else if (\n locale?.includes('-') &&\n (internationalization?.locales).includes(\n locale.split('-')[0] as Locales\n )\n ) {\n return locale.split('-')[0] as Locales;\n }\n }\n }\n\n return internationalization?.defaultLocale ?? Locales.ENGLISH;\n};\n\n/**\n * Core language detector function\n * const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locales => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":"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","names":["LanguageDetector"]}
@@ -0,0 +1,39 @@
1
+ import { getBrowserLocale } from "./getBrowserLocale.mjs";
2
+ import {
3
+ IntlayerClientContext,
4
+ IntlayerProvider,
5
+ IntlayerProviderContent,
6
+ useIntlayerContext
7
+ } from "./IntlayerProvider.mjs";
8
+ import { t } from "./t.mjs";
9
+ import { useDictionary } from "./useDictionary.mjs";
10
+ import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
11
+ import { useIntlayer } from "./useIntlayer.mjs";
12
+ import { useIntlayerAsync } from "./useIntlayerAsync.mjs";
13
+ import { useLoadDynamic } from "./useLoadDynamic.mjs";
14
+ import { useLocale } from "./useLocale.mjs";
15
+ import { useLocaleBase } from "./useLocaleBase.mjs";
16
+ import {
17
+ localeCookie,
18
+ setLocaleCookie,
19
+ useLocaleCookie
20
+ } from "./useLocaleCookie.mjs";
21
+ export {
22
+ IntlayerClientContext,
23
+ IntlayerProvider,
24
+ IntlayerProviderContent,
25
+ getBrowserLocale,
26
+ localeCookie,
27
+ setLocaleCookie,
28
+ t,
29
+ useDictionary,
30
+ useDictionaryDynamic,
31
+ useIntlayer,
32
+ useIntlayerAsync,
33
+ useIntlayerContext,
34
+ useLoadDynamic,
35
+ useLocale,
36
+ useLocaleBase,
37
+ useLocaleCookie
38
+ };
39
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export { getBrowserLocale } from './getBrowserLocale';\nexport {\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n useIntlayerContext,\n type IntlayerProviderProps,\n} from './IntlayerProvider';\nexport { t } from './t';\nexport { useDictionary } from './useDictionary';\nexport { useDictionaryDynamic } from './useDictionaryDynamic';\nexport { useIntlayer } from './useIntlayer';\nexport { useIntlayerAsync } from './useIntlayerAsync';\nexport { useLoadDynamic } from './useLoadDynamic';\nexport { useLocale } from './useLocale';\nexport { useLocaleBase } from './useLocaleBase';\nexport {\n localeCookie,\n setLocaleCookie,\n useLocaleCookie,\n} from './useLocaleCookie';\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,SAAS;AAClB,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import { getTranslation } from "@intlayer/core";
3
+ import { useContext } from "preact/hooks";
4
+ import { IntlayerClientContext } from "./IntlayerProvider.mjs";
5
+ const t = (multilangContent, locale) => {
6
+ const { locale: currentLocale } = useContext(IntlayerClientContext);
7
+ const localeTarget = locale ?? currentLocale;
8
+ return getTranslation(multilangContent, localeTarget);
9
+ };
10
+ export {
11
+ t
12
+ };
13
+ //# sourceMappingURL=t.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslation } from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, this function returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const t = <Content = string>(\n multilangContent: LanguageContent<Content>,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":";AAGA,SAA+B,sBAAsB;AACrD,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAO/B,MAAM,IAAI,CACf,kBACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,eAAwB,kBAAkB,YAAY;AAC/D;","names":[]}
@@ -0,0 +1,15 @@
1
+ import { useLocaleBase } from "./useLocaleBase.mjs";
2
+ import { useTranslation } from "./useTraduction.mjs";
3
+ const useContent = (languageContent) => {
4
+ const { locale } = useLocaleBase();
5
+ const content = useTranslation(languageContent);
6
+ return {
7
+ locale,
8
+ content,
9
+ t: useTranslation
10
+ };
11
+ };
12
+ export {
13
+ useContent
14
+ };
15
+ //# sourceMappingURL=useContent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocaleBase } from './useLocaleBase';\nimport { useTranslation } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const { locale } = useLocaleBase();\n\n const content = useTranslation(languageContent);\n\n return {\n locale,\n content,\n t: useTranslation,\n };\n};\n"],"mappings":"AACA,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAKxB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,IAAI,cAAc;AAEjC,QAAM,UAAU,eAAe,eAAe;AAE9C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { useContext } from "preact/hooks";
3
+ import { useChangedContent } from "../editor/ChangedContentContext.mjs";
4
+ import { getDictionary } from "../getDictionary.mjs";
5
+ import { IntlayerClientContext } from "./IntlayerProvider.mjs";
6
+ const useDictionary = (dictionary, locale) => {
7
+ const { locale: currentLocale } = useContext(IntlayerClientContext);
8
+ const localeTarget = locale ?? currentLocale;
9
+ const { changedContent } = useChangedContent();
10
+ if (changedContent?.[dictionary.key]) {
11
+ return getDictionary(changedContent?.[dictionary.key], localeTarget);
12
+ }
13
+ return getDictionary(dictionary, localeTarget);
14
+ };
15
+ export {
16
+ useDictionary
17
+ };
18
+ //# sourceMappingURL=useDictionary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { useChangedContent } from '../editor/ChangedContentContext';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n const { changedContent } = useChangedContent();\n\n if (changedContent?.[dictionary.key]) {\n // @ts-ignore fix instantiation is excessively deep and possibly infinite\n return getDictionary(changedContent?.[dictionary.key], localeTarget);\n }\n\n return getDictionary<T, LocalesValues>(dictionary, localeTarget);\n};\n"],"mappings":";AAIA,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAO/B,MAAM,gBAAgB,CAC3B,YACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAC/B,QAAM,EAAE,eAAe,IAAI,kBAAkB;AAE7C,MAAI,iBAAiB,WAAW,GAAG,GAAG;AAEpC,WAAO,cAAc,iBAAiB,WAAW,GAAG,GAAG,YAAY;AAAA,EACrE;AAEA,SAAO,cAAgC,YAAY,YAAY;AACjE;","names":[]}
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { useContext } from "preact/hooks";
3
+ import { IntlayerClientContext } from "./IntlayerProvider.mjs";
4
+ import { useDictionary } from "./useDictionary.mjs";
5
+ import { useLoadDynamic } from "./useLoadDynamic.mjs";
6
+ const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
7
+ const { locale: currentLocale } = useContext(IntlayerClientContext);
8
+ const localeTarget = locale ?? currentLocale;
9
+ const dictionary = useLoadDynamic(
10
+ `${String(key)}.${localeTarget}`,
11
+ dictionaryPromise[localeTarget]()
12
+ );
13
+ return useDictionary(dictionary, localeTarget);
14
+ };
15
+ export {
16
+ useDictionaryDynamic
17
+ };
18
+ //# sourceMappingURL=useDictionaryDynamic.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type {\n Dictionary,\n DictionaryKeys,\n LanguageContent,\n} from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: LanguageContent<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n dictionaryPromise[localeTarget]!()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":";AAQA,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAOxB,MAAM,uBAAuB,CAIlC,mBACA,KACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,QAAM,aAAa;AAAA,IACjB,GAAG,OAAO,GAAG,CAAC,IAAI,YAAY;AAAA,IAC9B,kBAAkB,YAAY,EAAG;AAAA,EACnC;AAEA,SAAO,cAAc,YAAY,YAAY;AAC/C;","names":[]}
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { useContext } from "preact/hooks";
3
+ import { useChangedContent } from "../editor/ChangedContentContext.mjs";
4
+ import { getDictionary } from "../getDictionary.mjs";
5
+ import { getIntlayer } from "../getIntlayer.mjs";
6
+ import { IntlayerClientContext } from "./IntlayerProvider.mjs";
7
+ const useIntlayer = (key, locale) => {
8
+ const { locale: currentLocale } = useContext(IntlayerClientContext);
9
+ const { changedContent } = useChangedContent();
10
+ const localeTarget = locale ?? currentLocale;
11
+ if (changedContent?.[key]) {
12
+ return getDictionary(changedContent?.[key], localeTarget);
13
+ }
14
+ return getIntlayer(key, localeTarget);
15
+ };
16
+ export {
17
+ useIntlayer
18
+ };
19
+ //# sourceMappingURL=useIntlayer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { DictionaryKeys } from '@intlayer/core';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { useContext } from 'preact/hooks';\nimport { useChangedContent } from '../editor/ChangedContentContext';\nimport { getDictionary } from '../getDictionary';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content']> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const { changedContent } = useChangedContent();\n const localeTarget = locale ?? currentLocale;\n\n if (changedContent?.[key as unknown as keyof typeof changedContent]) {\n // @ts-ignore fix instantiation is excessively deep and possibly infinite\n return getDictionary(changedContent?.[key], localeTarget);\n }\n\n return getIntlayer(key, localeTarget);\n};\n"],"mappings":";AAMA,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAE5B,SAAS,6BAA6B;AAO/B,MAAM,cAAc,CACzB,KACA,WACyE;AACzE,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,EAAE,eAAe,IAAI,kBAAkB;AAC7C,QAAM,eAAe,UAAU;AAE/B,MAAI,iBAAiB,GAA6C,GAAG;AAEnE,WAAO,cAAc,iBAAiB,GAAG,GAAG,YAAY;AAAA,EAC1D;AAEA,SAAO,YAAY,KAAK,YAAY;AACtC;","names":[]}
@@ -0,0 +1,33 @@
1
+ "use client";
2
+ import {
3
+ getIntlayer,
4
+ getIntlayerAsync
5
+ } from "@intlayer/core";
6
+ import { useContext, useEffect, useMemo, useState } from "preact/hooks";
7
+ import { IntlayerClientContext } from "./IntlayerProvider.mjs";
8
+ const useIntlayerAsync = (key, locale) => {
9
+ const { locale: currentLocale } = useContext(IntlayerClientContext);
10
+ const localeTarget = locale ?? currentLocale;
11
+ const localeDictionary = getIntlayer(key, localeTarget);
12
+ const [distantDictionary, setDistantDictionary] = useState(void 0);
13
+ const [isLoading, setIsLoading] = useState(false);
14
+ useEffect(() => {
15
+ setIsLoading(true);
16
+ getIntlayerAsync(key).then((distantDictionary2) => {
17
+ if (distantDictionary2) {
18
+ setDistantDictionary(distantDictionary2);
19
+ }
20
+ }).finally(() => {
21
+ setIsLoading(false);
22
+ });
23
+ }, []);
24
+ const dictionary = useMemo(
25
+ () => distantDictionary ?? localeDictionary,
26
+ [distantDictionary, localeDictionary]
27
+ );
28
+ return { ...dictionary, isLoading };
29
+ };
30
+ export {
31
+ useIntlayerAsync
32
+ };
33
+ //# sourceMappingURL=useIntlayerAsync.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/useIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n getIntlayer,\n getIntlayerAsync,\n} from '@intlayer/core';\nimport { useContext, useEffect, useMemo, useState } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayerAsync = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n const localeDictionary = getIntlayer(key, localeTarget);\n const [distantDictionary, setDistantDictionary] = useState<\n typeof localeDictionary | null | undefined\n >(undefined);\n const [isLoading, setIsLoading] = useState(false);\n\n useEffect(() => {\n setIsLoading(true);\n\n getIntlayerAsync(key)\n .then((distantDictionary) => {\n if (distantDictionary) {\n setDistantDictionary(distantDictionary);\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, []);\n\n const dictionary = useMemo(\n () => distantDictionary ?? localeDictionary,\n [distantDictionary, localeDictionary]\n );\n\n return { ...(dictionary as object), isLoading } as typeof localeDictionary & {\n isLoading: boolean;\n };\n};\n"],"mappings":";AAGA;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAY,WAAW,SAAS,gBAAgB;AACzD,SAAS,6BAA6B;AAU/B,MAAM,mBAAmB,CAC9B,KACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAC/B,QAAM,mBAAmB,YAAY,KAAK,YAAY;AACtD,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAEhD,MAAS;AACX,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,YAAU,MAAM;AACd,iBAAa,IAAI;AAEjB,qBAAiB,GAAG,EACjB,KAAK,CAACA,uBAAsB;AAC3B,UAAIA,oBAAmB;AACrB,6BAAqBA,kBAAiB;AAAA,MACxC;AAAA,IACF,CAAC,EACA,QAAQ,MAAM;AACb,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa;AAAA,IACjB,MAAM,qBAAqB;AAAA,IAC3B,CAAC,mBAAmB,gBAAgB;AAAA,EACtC;AAEA,SAAO,EAAE,GAAI,YAAuB,UAAU;AAGhD;","names":["distantDictionary"]}
@@ -0,0 +1,32 @@
1
+ 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
+ };
21
+ };
22
+ const cache = /* @__PURE__ */ new Map();
23
+ 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
31
+ };
32
+ //# sourceMappingURL=useLoadDynamic.mjs.map
@@ -0,0 +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":[]}
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ import configuration from "@intlayer/config/built";
3
+ 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
34
+ };
35
+ //# sourceMappingURL=useLocale.mjs.map
@@ -0,0 +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"]}