preact-intlayer 5.5.4 → 5.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/dist/cjs/IntlayerNode.cjs +47 -0
  2. package/dist/cjs/IntlayerNode.cjs.map +1 -0
  3. package/dist/cjs/UI/ContentSelector.cjs +127 -0
  4. package/dist/cjs/UI/ContentSelector.cjs.map +1 -0
  5. package/dist/cjs/client/IntlayerProvider.cjs +98 -0
  6. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
  7. package/dist/cjs/client/getBrowserLocale.cjs +173 -0
  8. package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
  9. package/dist/cjs/client/index.cjs +69 -0
  10. package/dist/cjs/client/index.cjs.map +1 -0
  11. package/dist/cjs/client/t.cjs +37 -0
  12. package/dist/cjs/client/t.cjs.map +1 -0
  13. package/dist/cjs/client/useContent.cjs +39 -0
  14. package/dist/cjs/client/useContent.cjs.map +1 -0
  15. package/dist/cjs/client/useDictionary.cjs +42 -0
  16. package/dist/cjs/client/useDictionary.cjs.map +1 -0
  17. package/dist/cjs/client/useDictionaryDynamic.cjs +42 -0
  18. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -0
  19. package/dist/cjs/client/useIntlayer.cjs +43 -0
  20. package/dist/cjs/client/useIntlayer.cjs.map +1 -0
  21. package/dist/cjs/client/useIntlayerAsync.cjs +54 -0
  22. package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -0
  23. package/dist/cjs/client/useLoadDynamic.cjs +56 -0
  24. package/dist/cjs/client/useLoadDynamic.cjs.map +1 -0
  25. package/dist/cjs/client/useLocale.cjs +69 -0
  26. package/dist/cjs/client/useLocale.cjs.map +1 -0
  27. package/dist/cjs/client/useLocaleBase.cjs +56 -0
  28. package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
  29. package/dist/cjs/client/useLocaleCookie.cjs +60 -0
  30. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -0
  31. package/dist/cjs/client/useTraduction.cjs +35 -0
  32. package/dist/cjs/client/useTraduction.cjs.map +1 -0
  33. package/dist/cjs/editor/ChangedContentContext.cjs +77 -0
  34. package/dist/cjs/editor/ChangedContentContext.cjs.map +1 -0
  35. package/dist/cjs/editor/CommunicatorContext.cjs +66 -0
  36. package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -0
  37. package/dist/cjs/editor/ConfigurationContext.cjs +50 -0
  38. package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -0
  39. package/dist/cjs/editor/ContentSelectorWrapper.cjs +66 -0
  40. package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -0
  41. package/dist/cjs/editor/DictionariesRecordContext.cjs +77 -0
  42. package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -0
  43. package/dist/cjs/editor/EditedContentContext.cjs +217 -0
  44. package/dist/cjs/editor/EditedContentContext.cjs.map +1 -0
  45. package/dist/cjs/editor/EditorEnabledContext.cjs +62 -0
  46. package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -0
  47. package/dist/cjs/editor/EditorProvider.cjs +72 -0
  48. package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
  49. package/dist/cjs/editor/FocusDictionaryContext.cjs +81 -0
  50. package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -0
  51. package/dist/cjs/editor/IntlayerEditorProvider.cjs +122 -0
  52. package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -0
  53. package/dist/cjs/editor/index.cjs +23 -0
  54. package/dist/cjs/editor/index.cjs.map +1 -0
  55. package/dist/cjs/editor/useCrossFrameMessageListener.cjs +53 -0
  56. package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -0
  57. package/dist/cjs/editor/useCrossFrameState.cjs +77 -0
  58. package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -0
  59. package/dist/cjs/editor/useCrossURLPathState.cjs +69 -0
  60. package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -0
  61. package/dist/cjs/editor/useEditedContentRenderer.cjs +63 -0
  62. package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -0
  63. package/dist/cjs/editor/useIframeClickInterceptor.cjs +50 -0
  64. package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -0
  65. package/dist/cjs/getDictionary.cjs +43 -0
  66. package/dist/cjs/getDictionary.cjs.map +1 -0
  67. package/dist/cjs/getIntlayer.cjs +39 -0
  68. package/dist/cjs/getIntlayer.cjs.map +1 -0
  69. package/dist/cjs/index.cjs +42 -5
  70. package/dist/cjs/index.cjs.map +1 -1
  71. package/dist/cjs/markdown/MarkdownProvider.cjs +41 -0
  72. package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -0
  73. package/dist/cjs/markdown/MarkdownRenderer.cjs +83 -0
  74. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
  75. package/dist/cjs/markdown/index.cjs +25 -0
  76. package/dist/cjs/markdown/index.cjs.map +1 -0
  77. package/dist/cjs/plugins.cjs +128 -0
  78. package/dist/cjs/plugins.cjs.map +1 -0
  79. package/dist/cjs/preactElement/renderPreactElement.cjs +62 -0
  80. package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -0
  81. package/dist/esm/IntlayerNode.mjs +27 -0
  82. package/dist/esm/IntlayerNode.mjs.map +1 -0
  83. package/dist/esm/UI/ContentSelector.mjs +103 -0
  84. package/dist/esm/UI/ContentSelector.mjs.map +1 -0
  85. package/dist/esm/client/IntlayerProvider.mjs +63 -0
  86. package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
  87. package/dist/esm/client/getBrowserLocale.mjs +138 -0
  88. package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
  89. package/dist/esm/client/index.mjs +39 -0
  90. package/dist/esm/client/index.mjs.map +1 -0
  91. package/dist/esm/client/t.mjs +13 -0
  92. package/dist/esm/client/t.mjs.map +1 -0
  93. package/dist/esm/client/useContent.mjs +15 -0
  94. package/dist/esm/client/useContent.mjs.map +1 -0
  95. package/dist/esm/client/useDictionary.mjs +18 -0
  96. package/dist/esm/client/useDictionary.mjs.map +1 -0
  97. package/dist/esm/client/useDictionaryDynamic.mjs +18 -0
  98. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -0
  99. package/dist/esm/client/useIntlayer.mjs +19 -0
  100. package/dist/esm/client/useIntlayer.mjs.map +1 -0
  101. package/dist/esm/client/useIntlayerAsync.mjs +33 -0
  102. package/dist/esm/client/useIntlayerAsync.mjs.map +1 -0
  103. package/dist/esm/client/useLoadDynamic.mjs +32 -0
  104. package/dist/esm/client/useLoadDynamic.mjs.map +1 -0
  105. package/dist/esm/client/useLocale.mjs +35 -0
  106. package/dist/esm/client/useLocale.mjs.map +1 -0
  107. package/dist/esm/client/useLocaleBase.mjs +22 -0
  108. package/dist/esm/client/useLocaleBase.mjs.map +1 -0
  109. package/dist/esm/client/useLocaleCookie.mjs +24 -0
  110. package/dist/esm/client/useLocaleCookie.mjs.map +1 -0
  111. package/dist/esm/client/useTraduction.mjs +11 -0
  112. package/dist/esm/client/useTraduction.mjs.map +1 -0
  113. package/dist/esm/editor/ChangedContentContext.mjs +55 -0
  114. package/dist/esm/editor/ChangedContentContext.mjs.map +1 -0
  115. package/dist/esm/editor/CommunicatorContext.mjs +33 -0
  116. package/dist/esm/editor/CommunicatorContext.mjs.map +1 -0
  117. package/dist/esm/editor/ConfigurationContext.mjs +27 -0
  118. package/dist/esm/editor/ConfigurationContext.mjs.map +1 -0
  119. package/dist/esm/editor/ContentSelectorWrapper.mjs +45 -0
  120. package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -0
  121. package/dist/esm/editor/DictionariesRecordContext.mjs +55 -0
  122. package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -0
  123. package/dist/esm/editor/EditedContentContext.mjs +198 -0
  124. package/dist/esm/editor/EditedContentContext.mjs.map +1 -0
  125. package/dist/esm/editor/EditorEnabledContext.mjs +39 -0
  126. package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -0
  127. package/dist/esm/editor/EditorProvider.mjs +62 -0
  128. package/dist/esm/editor/EditorProvider.mjs.map +1 -0
  129. package/dist/esm/editor/FocusDictionaryContext.mjs +58 -0
  130. package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -0
  131. package/dist/esm/editor/IntlayerEditorProvider.mjs +88 -0
  132. package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -0
  133. package/dist/esm/editor/index.mjs +2 -0
  134. package/dist/esm/editor/index.mjs.map +1 -0
  135. package/dist/esm/editor/useCrossFrameMessageListener.mjs +29 -0
  136. package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -0
  137. package/dist/esm/editor/useCrossFrameState.mjs +53 -0
  138. package/dist/esm/editor/useCrossFrameState.mjs.map +1 -0
  139. package/dist/esm/editor/useCrossURLPathState.mjs +46 -0
  140. package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -0
  141. package/dist/esm/editor/useEditedContentRenderer.mjs +38 -0
  142. package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -0
  143. package/dist/esm/editor/useIframeClickInterceptor.mjs +25 -0
  144. package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -0
  145. package/dist/esm/getDictionary.mjs +25 -0
  146. package/dist/esm/getDictionary.mjs.map +1 -0
  147. package/dist/esm/getIntlayer.mjs +21 -0
  148. package/dist/esm/getIntlayer.mjs.map +1 -0
  149. package/dist/esm/index.mjs +38 -2
  150. package/dist/esm/index.mjs.map +1 -1
  151. package/dist/esm/markdown/MarkdownProvider.mjs +19 -0
  152. package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -0
  153. package/dist/esm/markdown/MarkdownRenderer.mjs +62 -0
  154. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
  155. package/dist/esm/markdown/index.mjs +3 -0
  156. package/dist/esm/markdown/index.mjs.map +1 -0
  157. package/dist/esm/plugins.mjs +104 -0
  158. package/dist/esm/plugins.mjs.map +1 -0
  159. package/dist/esm/preactElement/renderPreactElement.mjs +38 -0
  160. package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -0
  161. package/dist/types/IntlayerNode.d.ts +15 -0
  162. package/dist/types/IntlayerNode.d.ts.map +1 -0
  163. package/dist/types/UI/ContentSelector.d.ts +10 -0
  164. package/dist/types/UI/ContentSelector.d.ts.map +1 -0
  165. package/dist/types/client/IntlayerProvider.d.ts +29 -0
  166. package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
  167. package/dist/types/client/getBrowserLocale.d.ts +25 -0
  168. package/dist/types/client/getBrowserLocale.d.ts.map +1 -0
  169. package/dist/types/client/index.d.ts +12 -0
  170. package/dist/types/client/index.d.ts.map +1 -0
  171. package/dist/types/client/t.d.ts +9 -0
  172. package/dist/types/client/t.d.ts.map +1 -0
  173. package/dist/types/client/useContent.d.ts +10 -0
  174. package/dist/types/client/useContent.d.ts.map +1 -0
  175. package/dist/types/client/useDictionary.d.ts +9 -0
  176. package/dist/types/client/useDictionary.d.ts.map +1 -0
  177. package/dist/types/client/useDictionaryDynamic.d.ts +9 -0
  178. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
  179. package/dist/types/client/useIntlayer.d.ts +11 -0
  180. package/dist/types/client/useIntlayer.d.ts.map +1 -0
  181. package/dist/types/client/useIntlayerAsync.d.ts +14 -0
  182. package/dist/types/client/useIntlayerAsync.d.ts.map +1 -0
  183. package/dist/types/client/useLoadDynamic.d.ts +2 -0
  184. package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
  185. package/dist/types/client/useLocale.d.ts +15 -0
  186. package/dist/types/client/useLocale.d.ts.map +1 -0
  187. package/dist/types/client/useLocaleBase.d.ts +10 -0
  188. package/dist/types/client/useLocaleBase.d.ts.map +1 -0
  189. package/dist/types/client/useLocaleCookie.d.ts +17 -0
  190. package/dist/types/client/useLocaleCookie.d.ts.map +1 -0
  191. package/dist/types/client/useTraduction.d.ts +24 -0
  192. package/dist/types/client/useTraduction.d.ts.map +1 -0
  193. package/dist/types/editor/ChangedContentContext.d.ts +13 -0
  194. package/dist/types/editor/ChangedContentContext.d.ts.map +1 -0
  195. package/dist/types/editor/CommunicatorContext.d.ts +14 -0
  196. package/dist/types/editor/CommunicatorContext.d.ts.map +1 -0
  197. package/dist/types/editor/ConfigurationContext.d.ts +9 -0
  198. package/dist/types/editor/ConfigurationContext.d.ts.map +1 -0
  199. package/dist/types/editor/ContentSelectorWrapper.d.ts +5 -0
  200. package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -0
  201. package/dist/types/editor/DictionariesRecordContext.d.ts +16 -0
  202. package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -0
  203. package/dist/types/editor/EditedContentContext.d.ts +33 -0
  204. package/dist/types/editor/EditedContentContext.d.ts.map +1 -0
  205. package/dist/types/editor/EditorEnabledContext.d.ts +11 -0
  206. package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -0
  207. package/dist/types/editor/EditorProvider.d.ts +6 -0
  208. package/dist/types/editor/EditorProvider.d.ts.map +1 -0
  209. package/dist/types/editor/FocusDictionaryContext.d.ts +21 -0
  210. package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -0
  211. package/dist/types/editor/IntlayerEditorProvider.d.ts +5 -0
  212. package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -0
  213. package/dist/types/editor/index.d.ts +2 -0
  214. package/dist/types/editor/index.d.ts.map +1 -0
  215. package/dist/types/editor/useCrossFrameMessageListener.d.ts +19 -0
  216. package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -0
  217. package/dist/types/editor/useCrossFrameState.d.ts +30 -0
  218. package/dist/types/editor/useCrossFrameState.d.ts.map +1 -0
  219. package/dist/types/editor/useCrossURLPathState.d.ts +4 -0
  220. package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -0
  221. package/dist/types/editor/useEditedContentRenderer.d.ts +13 -0
  222. package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -0
  223. package/dist/types/editor/useIframeClickInterceptor.d.ts +3 -0
  224. package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -0
  225. package/dist/types/getDictionary.d.ts +5 -0
  226. package/dist/types/getDictionary.d.ts.map +1 -0
  227. package/dist/types/getIntlayer.d.ts +5 -0
  228. package/dist/types/getIntlayer.d.ts.map +1 -0
  229. package/dist/types/index.d.ts +8 -2
  230. package/dist/types/index.d.ts.map +1 -1
  231. package/dist/types/markdown/MarkdownProvider.d.ts +9 -0
  232. package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
  233. package/dist/types/markdown/MarkdownRenderer.d.ts +16 -0
  234. package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
  235. package/dist/types/markdown/index.d.ts +3 -0
  236. package/dist/types/markdown/index.d.ts.map +1 -0
  237. package/dist/types/plugins.d.ts +54 -0
  238. package/dist/types/plugins.d.ts.map +1 -0
  239. package/dist/types/preactElement/renderPreactElement.d.ts +5 -0
  240. package/dist/types/preactElement/renderPreactElement.d.ts.map +1 -0
  241. package/package.json +14 -7
  242. package/dist/cjs/intlayerMiddlewarePlugin.cjs +0 -224
  243. package/dist/cjs/intlayerMiddlewarePlugin.cjs.map +0 -1
  244. package/dist/cjs/intlayerPlugin.cjs +0 -76
  245. package/dist/cjs/intlayerPlugin.cjs.map +0 -1
  246. package/dist/esm/intlayerMiddlewarePlugin.mjs +0 -200
  247. package/dist/esm/intlayerMiddlewarePlugin.mjs.map +0 -1
  248. package/dist/esm/intlayerPlugin.mjs +0 -52
  249. package/dist/esm/intlayerPlugin.mjs.map +0 -1
  250. package/dist/types/intlayerMiddlewarePlugin.d.ts +0 -6
  251. package/dist/types/intlayerMiddlewarePlugin.d.ts.map +0 -1
  252. package/dist/types/intlayerPlugin.d.ts +0 -16
  253. package/dist/types/intlayerPlugin.d.ts.map +0 -1
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var useDictionary_exports = {};
21
+ __export(useDictionary_exports, {
22
+ useDictionary: () => useDictionary
23
+ });
24
+ module.exports = __toCommonJS(useDictionary_exports);
25
+ var import_hooks = require("preact/hooks");
26
+ var import_ChangedContentContext = require('../editor/ChangedContentContext.cjs');
27
+ var import_getDictionary = require('../getDictionary.cjs');
28
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
29
+ const useDictionary = (dictionary, locale) => {
30
+ const { locale: currentLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
31
+ const localeTarget = locale ?? currentLocale;
32
+ const { changedContent } = (0, import_ChangedContentContext.useChangedContent)();
33
+ if (changedContent?.[dictionary.key]) {
34
+ return (0, import_getDictionary.getDictionary)(changedContent?.[dictionary.key], localeTarget);
35
+ }
36
+ return (0, import_getDictionary.getDictionary)(dictionary, localeTarget);
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ useDictionary
41
+ });
42
+ //# sourceMappingURL=useDictionary.cjs.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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAA2B;AAC3B,mCAAkC;AAClC,2BAA8B;AAC9B,8BAAsC;AAO/B,MAAM,gBAAgB,CAC3B,YACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAC/B,QAAM,EAAE,eAAe,QAAI,gDAAkB;AAE7C,MAAI,iBAAiB,WAAW,GAAG,GAAG;AAEpC,eAAO,oCAAc,iBAAiB,WAAW,GAAG,GAAG,YAAY;AAAA,EACrE;AAEA,aAAO,oCAAgC,YAAY,YAAY;AACjE;","names":[]}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var useDictionaryDynamic_exports = {};
21
+ __export(useDictionaryDynamic_exports, {
22
+ useDictionaryDynamic: () => useDictionaryDynamic
23
+ });
24
+ module.exports = __toCommonJS(useDictionaryDynamic_exports);
25
+ var import_hooks = require("preact/hooks");
26
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
27
+ var import_useDictionary = require('./useDictionary.cjs');
28
+ var import_useLoadDynamic = require('./useLoadDynamic.cjs');
29
+ const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
30
+ const { locale: currentLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
31
+ const localeTarget = locale ?? currentLocale;
32
+ const dictionary = (0, import_useLoadDynamic.useLoadDynamic)(
33
+ `${String(key)}.${localeTarget}`,
34
+ dictionaryPromise[localeTarget]()
35
+ );
36
+ return (0, import_useDictionary.useDictionary)(dictionary, localeTarget);
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ useDictionaryDynamic
41
+ });
42
+ //# sourceMappingURL=useDictionaryDynamic.cjs.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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,mBAA2B;AAC3B,8BAAsC;AACtC,2BAA8B;AAC9B,4BAA+B;AAOxB,MAAM,uBAAuB,CAIlC,mBACA,KACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,QAAM,iBAAa;AAAA,IACjB,GAAG,OAAO,GAAG,CAAC,IAAI,YAAY;AAAA,IAC9B,kBAAkB,YAAY,EAAG;AAAA,EACnC;AAEA,aAAO,oCAAc,YAAY,YAAY;AAC/C;","names":[]}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var useIntlayer_exports = {};
21
+ __export(useIntlayer_exports, {
22
+ useIntlayer: () => useIntlayer
23
+ });
24
+ module.exports = __toCommonJS(useIntlayer_exports);
25
+ var import_hooks = require("preact/hooks");
26
+ var import_ChangedContentContext = require('../editor/ChangedContentContext.cjs');
27
+ var import_getDictionary = require('../getDictionary.cjs');
28
+ var import_getIntlayer = require('../getIntlayer.cjs');
29
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
30
+ const useIntlayer = (key, locale) => {
31
+ const { locale: currentLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
32
+ const { changedContent } = (0, import_ChangedContentContext.useChangedContent)();
33
+ const localeTarget = locale ?? currentLocale;
34
+ if (changedContent?.[key]) {
35
+ return (0, import_getDictionary.getDictionary)(changedContent?.[key], localeTarget);
36
+ }
37
+ return (0, import_getIntlayer.getIntlayer)(key, localeTarget);
38
+ };
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ useIntlayer
42
+ });
43
+ //# sourceMappingURL=useIntlayer.cjs.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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,mBAA2B;AAC3B,mCAAkC;AAClC,2BAA8B;AAC9B,yBAA4B;AAE5B,8BAAsC;AAO/B,MAAM,cAAc,CACzB,KACA,WACyE;AACzE,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,EAAE,eAAe,QAAI,gDAAkB;AAC7C,QAAM,eAAe,UAAU;AAE/B,MAAI,iBAAiB,GAA6C,GAAG;AAEnE,eAAO,oCAAc,iBAAiB,GAAG,GAAG,YAAY;AAAA,EAC1D;AAEA,aAAO,gCAAY,KAAK,YAAY;AACtC;","names":[]}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var useIntlayerAsync_exports = {};
21
+ __export(useIntlayerAsync_exports, {
22
+ useIntlayerAsync: () => useIntlayerAsync
23
+ });
24
+ module.exports = __toCommonJS(useIntlayerAsync_exports);
25
+ var import_core = require("@intlayer/core");
26
+ var import_hooks = require("preact/hooks");
27
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
28
+ const useIntlayerAsync = (key, locale) => {
29
+ const { locale: currentLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
30
+ const localeTarget = locale ?? currentLocale;
31
+ const localeDictionary = (0, import_core.getIntlayer)(key, localeTarget);
32
+ const [distantDictionary, setDistantDictionary] = (0, import_hooks.useState)(void 0);
33
+ const [isLoading, setIsLoading] = (0, import_hooks.useState)(false);
34
+ (0, import_hooks.useEffect)(() => {
35
+ setIsLoading(true);
36
+ (0, import_core.getIntlayerAsync)(key).then((distantDictionary2) => {
37
+ if (distantDictionary2) {
38
+ setDistantDictionary(distantDictionary2);
39
+ }
40
+ }).finally(() => {
41
+ setIsLoading(false);
42
+ });
43
+ }, []);
44
+ const dictionary = (0, import_hooks.useMemo)(
45
+ () => distantDictionary ?? localeDictionary,
46
+ [distantDictionary, localeDictionary]
47
+ );
48
+ return { ...dictionary, isLoading };
49
+ };
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ useIntlayerAsync
53
+ });
54
+ //# sourceMappingURL=useIntlayerAsync.cjs.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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAIO;AACP,mBAAyD;AACzD,8BAAsC;AAU/B,MAAM,mBAAmB,CAC9B,KACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAC/B,QAAM,uBAAmB,yBAAY,KAAK,YAAY;AACtD,QAAM,CAAC,mBAAmB,oBAAoB,QAAI,uBAEhD,MAAS;AACX,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAEhD,8BAAU,MAAM;AACd,iBAAa,IAAI;AAEjB,sCAAiB,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,iBAAa;AAAA,IACjB,MAAM,qBAAqB;AAAA,IAC3B,CAAC,mBAAmB,gBAAgB;AAAA,EACtC;AAEA,SAAO,EAAE,GAAI,YAAuB,UAAU;AAGhD;","names":["distantDictionary"]}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useLoadDynamic_exports = {};
20
+ __export(useLoadDynamic_exports, {
21
+ useLoadDynamic: () => useLoadDynamic
22
+ });
23
+ module.exports = __toCommonJS(useLoadDynamic_exports);
24
+ const createSuspender = (promise) => {
25
+ let status = "pending";
26
+ let result;
27
+ const suspender = promise.then(
28
+ (r) => {
29
+ status = "success";
30
+ result = r;
31
+ },
32
+ (e) => {
33
+ status = "error";
34
+ result = e;
35
+ }
36
+ );
37
+ return {
38
+ read() {
39
+ if (status === "pending") throw suspender;
40
+ if (status === "error") throw result;
41
+ return result;
42
+ }
43
+ };
44
+ };
45
+ const cache = /* @__PURE__ */ new Map();
46
+ const useLoadDynamic = (key, promise) => {
47
+ if (!cache.has(key)) {
48
+ cache.set(key, createSuspender(promise));
49
+ }
50
+ return cache.get(key).read();
51
+ };
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ useLoadDynamic
55
+ });
56
+ //# sourceMappingURL=useLoadDynamic.cjs.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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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,69 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var useLocale_exports = {};
31
+ __export(useLocale_exports, {
32
+ useLocale: () => useLocale
33
+ });
34
+ module.exports = __toCommonJS(useLocale_exports);
35
+ var import_built = __toESM(require("@intlayer/config/built"));
36
+ var import_hooks = require("preact/hooks");
37
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
38
+ var import_useLocaleCookie = require('./useLocaleCookie.cjs');
39
+ const useLocale = ({ onLocaleChange } = {}) => {
40
+ const { defaultLocale, locales: availableLocales } = import_built.default?.internationalization ?? {};
41
+ const { locale, setLocale: setLocaleState } = (0, import_hooks.useContext)(
42
+ import_IntlayerProvider.IntlayerClientContext
43
+ );
44
+ const { setLocaleCookie } = (0, import_useLocaleCookie.useLocaleCookie)();
45
+ const setLocale = (locale2) => {
46
+ if (!availableLocales?.map(String).includes(locale2)) {
47
+ console.error(`Locale ${locale2} is not available`);
48
+ return;
49
+ }
50
+ setLocaleState(locale2);
51
+ setLocaleCookie(locale2);
52
+ onLocaleChange?.(locale2);
53
+ };
54
+ return {
55
+ locale,
56
+ // Current locale
57
+ defaultLocale,
58
+ // Principal locale defined in config
59
+ availableLocales,
60
+ // List of the available locales defined in config
61
+ setLocale
62
+ // Function to set the locale
63
+ };
64
+ };
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ useLocale
68
+ });
69
+ //# sourceMappingURL=useLocale.cjs.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAE1B,mBAA2B;AAC3B,8BAAsC;AACtC,6BAAgC;AASzB,MAAM,YAAY,CAAC,EAAE,eAAe,IAAoB,CAAC,MAAM;AACpE,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,aAAAA,SAAe,wBAAwB,CAAC;AAE1C,QAAM,EAAE,QAAQ,WAAW,eAAe,QAAI;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,EAAE,gBAAgB,QAAI,wCAAgB;AAE5C,QAAM,YAAY,CAACC,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":["configuration","locale"]}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var useLocaleBase_exports = {};
31
+ __export(useLocaleBase_exports, {
32
+ useLocaleBase: () => useLocaleBase
33
+ });
34
+ module.exports = __toCommonJS(useLocaleBase_exports);
35
+ var import_built = __toESM(require("@intlayer/config/built"));
36
+ var import_hooks = require("preact/hooks");
37
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
38
+ const { defaultLocale, locales: availableLocales } = import_built.default.internationalization;
39
+ const useLocaleBase = () => {
40
+ const { locale, setLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
41
+ return {
42
+ locale,
43
+ // Current locale
44
+ defaultLocale,
45
+ // Principal locale defined in config
46
+ availableLocales,
47
+ // List of the available locales defined in config
48
+ setLocale
49
+ // Function to set the locale
50
+ };
51
+ };
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ useLocaleBase
55
+ });
56
+ //# sourceMappingURL=useLocaleBase.cjs.map
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAC1B,mBAA2B;AAC3B,8BAAsC;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,aAAAA,QAAc;AAKT,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,QAAI,yBAAW,6CAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":["configuration"]}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var useLocaleCookie_exports = {};
30
+ __export(useLocaleCookie_exports, {
31
+ localeCookie: () => localeCookie,
32
+ setLocaleCookie: () => setLocaleCookie,
33
+ useLocaleCookie: () => useLocaleCookie
34
+ });
35
+ module.exports = __toCommonJS(useLocaleCookie_exports);
36
+ var import_built = __toESM(require("@intlayer/config/built"));
37
+ var import_js_cookie = __toESM(require("js-cookie"));
38
+ const { cookieName } = import_built.default.middleware;
39
+ const cookieAttributes = {
40
+ path: "/",
41
+ expires: void 0,
42
+ domain: void 0,
43
+ secure: false,
44
+ sameSite: "strict"
45
+ };
46
+ const localeCookie = import_js_cookie.default.get(cookieName);
47
+ const setLocaleCookie = (locale) => {
48
+ import_js_cookie.default.set(cookieName, locale, cookieAttributes);
49
+ };
50
+ const useLocaleCookie = () => ({
51
+ localeCookie,
52
+ setLocaleCookie
53
+ });
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ localeCookie,
57
+ setLocaleCookie,
58
+ useLocaleCookie
59
+ });
60
+ //# sourceMappingURL=useLocaleCookie.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\n\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = configuration.middleware;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as unknown as\n | LocalesValues\n | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: LocalesValues) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAG1B,uBAAoB;AAEpB,MAAM,EAAE,WAAW,IAAI,aAAAA,QAAc;AAErC,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,iBAAAC,QAAQ,IAAI,UAAU;AAO3C,MAAM,kBAAkB,CAAC,WAA0B;AACxD,mBAAAA,QAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":["configuration","Cookies"]}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useTraduction_exports = {};
20
+ __export(useTraduction_exports, {
21
+ useTranslation: () => useTranslation
22
+ });
23
+ module.exports = __toCommonJS(useTraduction_exports);
24
+ var import_core = require("@intlayer/core");
25
+ var import_hooks = require("preact/hooks");
26
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
27
+ const useTranslation = (languageContent) => {
28
+ const { locale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
29
+ return (0, import_core.getTranslation)(languageContent, locale);
30
+ };
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ useTranslation
34
+ });
35
+ //# sourceMappingURL=useTraduction.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation, type LanguageContent } from '@intlayer/core';\nimport { useContext } 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 getTranslation(languageContent, locale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqD;AACrD,mBAA2B;AAC3B,8BAAsC;AAuB/B,MAAM,iBAAiB,CAC5B,oBACY;AACZ,QAAM,EAAE,OAAO,QAAI,yBAAW,6CAAqB;AAEnD,aAAO,4BAAe,iBAAiB,MAAM;AAC/C;","names":[]}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var ChangedContentContext_exports = {};
21
+ __export(ChangedContentContext_exports, {
22
+ ChangedContentProvider: () => ChangedContentProvider,
23
+ useChangedContent: () => useChangedContent,
24
+ useChangedContentActions: () => useChangedContentActions
25
+ });
26
+ module.exports = __toCommonJS(ChangedContentContext_exports);
27
+ var import_jsx_runtime = require("preact/jsx-runtime");
28
+ var import_compat = require("preact/compat");
29
+ const ChangedContentStateContext = (0, import_compat.createContext)(void 0);
30
+ const ChangedContentActionsContext = (0, import_compat.createContext)(void 0);
31
+ const ChangedContentProvider = ({ children }) => {
32
+ const [changedContent, setChangedContentState] = (0, import_compat.useState)(
33
+ {}
34
+ );
35
+ const setChangedContent = (dictionaryKey, newValue) => {
36
+ setChangedContentState((prev) => ({
37
+ ...prev,
38
+ [dictionaryKey]: {
39
+ ...prev?.[dictionaryKey],
40
+ content: newValue
41
+ }
42
+ }));
43
+ };
44
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
45
+ ChangedContentStateContext.Provider,
46
+ {
47
+ value: {
48
+ changedContent
49
+ },
50
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
51
+ ChangedContentActionsContext.Provider,
52
+ {
53
+ value: {
54
+ setChangedContent
55
+ },
56
+ children
57
+ }
58
+ )
59
+ }
60
+ );
61
+ };
62
+ const useChangedContentActions = () => {
63
+ const context = (0, import_compat.useContext)(ChangedContentActionsContext);
64
+ return context;
65
+ };
66
+ const useChangedContent = () => {
67
+ const stateContext = (0, import_compat.useContext)(ChangedContentStateContext);
68
+ const actionContext = useChangedContentActions();
69
+ return { ...stateContext, ...actionContext };
70
+ };
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ ChangedContentProvider,
74
+ useChangedContent,
75
+ useChangedContentActions
76
+ });
77
+ //# sourceMappingURL=ChangedContentContext.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/editor/ChangedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n useState,\n type FC,\n type PropsWithChildren,\n} from 'preact/compat';\nimport type { DictionaryContent } from './DictionariesRecordContext';\n\ntype ChangedContentStateContextType = {\n changedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst ChangedContentStateContext = createContext<\n ChangedContentStateContextType | undefined\n>(undefined);\n\ntype ChangedContentActionsContextType = {\n setChangedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n};\n\nconst ChangedContentActionsContext = createContext<\n ChangedContentActionsContextType | undefined\n>(undefined);\n\nexport const ChangedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const [changedContent, setChangedContentState] = useState<DictionaryContent>(\n {}\n );\n\n const setChangedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setChangedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n return (\n <ChangedContentStateContext.Provider\n value={{\n changedContent,\n }}\n >\n <ChangedContentActionsContext.Provider\n value={{\n setChangedContent,\n }}\n >\n {children}\n </ChangedContentActionsContext.Provider>\n </ChangedContentStateContext.Provider>\n );\n};\n\nexport const useChangedContentActions = () => {\n const context = useContext(ChangedContentActionsContext);\n\n return context;\n};\n\nexport const useChangedContent = () => {\n const stateContext = useContext(ChangedContentStateContext);\n const actionContext = useChangedContentActions();\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDM;AApDN,oBAMO;AAOP,MAAM,iCAA6B,6BAEjC,MAAS;AASX,MAAM,mCAA+B,6BAEnC,MAAS;AAEJ,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,CAAC,gBAAgB,sBAAsB,QAAI;AAAA,IAC/C,CAAC;AAAA,EACH;AAEA,QAAM,oBAAoB,CACxB,eACA,aACG;AACH,2BAAuB,CAAC,UAAU;AAAA,MAChC,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,QACf,GAAG,OAAO,aAAa;AAAA,QACvB,SAAS;AAAA,MACX;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,SACE;AAAA,IAAC,2BAA2B;AAAA,IAA3B;AAAA,MACC,OAAO;AAAA,QACL;AAAA,MACF;AAAA,MAEA;AAAA,QAAC,6BAA6B;AAAA,QAA7B;AAAA,UACC,OAAO;AAAA,YACL;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,2BAA2B,MAAM;AAC5C,QAAM,cAAU,0BAAW,4BAA4B;AAEvD,SAAO;AACT;AAEO,MAAM,oBAAoB,MAAM;AACrC,QAAM,mBAAe,0BAAW,0BAA0B;AAC1D,QAAM,gBAAgB,yBAAyB;AAE/C,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}