react-intlayer 7.6.0-canary.0 → 8.0.0-canary.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/dist/assets/markdown/_fixture.md +896 -0
  2. package/dist/cjs/client/IntlayerProvider.cjs +30 -3
  3. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
  4. package/dist/cjs/client/format/index.cjs +2 -0
  5. package/dist/cjs/client/format/useIntl.cjs +45 -0
  6. package/dist/cjs/client/format/useIntl.cjs.map +1 -0
  7. package/dist/cjs/client/t.cjs +21 -2
  8. package/dist/cjs/client/t.cjs.map +1 -1
  9. package/dist/cjs/client/useIntlayer.cjs +16 -3
  10. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  11. package/dist/cjs/client/useLocale.cjs +27 -7
  12. package/dist/cjs/client/useLocale.cjs.map +1 -1
  13. package/dist/cjs/getDictionary.cjs +2 -0
  14. package/dist/cjs/getDictionary.cjs.map +1 -1
  15. package/dist/cjs/getIntlayer.cjs +2 -0
  16. package/dist/cjs/getIntlayer.cjs.map +1 -1
  17. package/dist/cjs/html/HTMLProvider.cjs +18 -0
  18. package/dist/cjs/html/HTMLProvider.cjs.map +1 -0
  19. package/dist/cjs/html/HTMLRenderer.cjs +59 -0
  20. package/dist/cjs/html/HTMLRenderer.cjs.map +1 -0
  21. package/dist/cjs/html/HTMLRendererPlugin.cjs +36 -0
  22. package/dist/cjs/html/HTMLRendererPlugin.cjs.map +1 -0
  23. package/dist/cjs/html/index.cjs +11 -0
  24. package/dist/cjs/html/types.cjs +0 -0
  25. package/dist/cjs/index.cjs +13 -1
  26. package/dist/cjs/markdown/MarkdownProvider.cjs +76 -5
  27. package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
  28. package/dist/cjs/markdown/MarkdownRenderer.cjs +192 -32
  29. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
  30. package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +33 -0
  31. package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -0
  32. package/dist/cjs/markdown/index.cjs +19 -2
  33. package/dist/cjs/markdown/processor.cjs +61 -0
  34. package/dist/cjs/markdown/processor.cjs.map +1 -0
  35. package/dist/cjs/markdown/runtime.cjs +45 -0
  36. package/dist/cjs/markdown/runtime.cjs.map +1 -0
  37. package/dist/cjs/plugins.cjs +83 -7
  38. package/dist/cjs/plugins.cjs.map +1 -1
  39. package/dist/cjs/reactElement/renderReactElement.cjs +8 -8
  40. package/dist/cjs/reactElement/renderReactElement.cjs.map +1 -1
  41. package/dist/cjs/server/IntlayerServerProvider.cjs +2 -2
  42. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
  43. package/dist/cjs/server/format/useIntl.cjs +44 -0
  44. package/dist/cjs/server/format/useIntl.cjs.map +1 -0
  45. package/dist/cjs/server/index.cjs +2 -0
  46. package/dist/esm/IntlayerNode.mjs +2 -2
  47. package/dist/esm/IntlayerNode.mjs.map +1 -1
  48. package/dist/esm/client/IntlayerProvider.mjs +30 -3
  49. package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
  50. package/dist/esm/client/format/index.mjs +2 -1
  51. package/dist/esm/client/format/useIntl.mjs +44 -0
  52. package/dist/esm/client/format/useIntl.mjs.map +1 -0
  53. package/dist/esm/client/t.mjs +21 -2
  54. package/dist/esm/client/t.mjs.map +1 -1
  55. package/dist/esm/client/useIntlayer.mjs +16 -3
  56. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  57. package/dist/esm/client/useLocale.mjs +27 -7
  58. package/dist/esm/client/useLocale.mjs.map +1 -1
  59. package/dist/esm/editor/IntlayerEditorProvider.mjs +3 -3
  60. package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
  61. package/dist/esm/getDictionary.mjs +3 -1
  62. package/dist/esm/getDictionary.mjs.map +1 -1
  63. package/dist/esm/getIntlayer.mjs +3 -1
  64. package/dist/esm/getIntlayer.mjs.map +1 -1
  65. package/dist/esm/html/HTMLProvider.mjs +16 -0
  66. package/dist/esm/html/HTMLProvider.mjs.map +1 -0
  67. package/dist/esm/html/HTMLRenderer.mjs +55 -0
  68. package/dist/esm/html/HTMLRenderer.mjs.map +1 -0
  69. package/dist/esm/html/HTMLRendererPlugin.mjs +35 -0
  70. package/dist/esm/html/HTMLRendererPlugin.mjs.map +1 -0
  71. package/dist/esm/html/index.mjs +5 -0
  72. package/dist/esm/html/types.mjs +0 -0
  73. package/dist/esm/index.mjs +5 -1
  74. package/dist/esm/markdown/MarkdownProvider.mjs +76 -5
  75. package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
  76. package/dist/esm/markdown/MarkdownRenderer.mjs +191 -32
  77. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
  78. package/dist/esm/markdown/MarkdownRendererPlugin.mjs +31 -0
  79. package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -0
  80. package/dist/esm/markdown/index.mjs +5 -2
  81. package/dist/esm/markdown/processor.mjs +54 -0
  82. package/dist/esm/markdown/processor.mjs.map +1 -0
  83. package/dist/esm/markdown/runtime.mjs +41 -0
  84. package/dist/esm/markdown/runtime.mjs.map +1 -0
  85. package/dist/esm/plugins.mjs +82 -8
  86. package/dist/esm/plugins.mjs.map +1 -1
  87. package/dist/esm/reactElement/renderReactElement.mjs +8 -8
  88. package/dist/esm/reactElement/renderReactElement.mjs.map +1 -1
  89. package/dist/esm/server/IntlayerServerProvider.mjs +2 -2
  90. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
  91. package/dist/esm/server/format/useIntl.mjs +42 -0
  92. package/dist/esm/server/format/useIntl.mjs.map +1 -0
  93. package/dist/esm/server/index.mjs +2 -1
  94. package/dist/types/IntlayerNode.d.ts.map +1 -1
  95. package/dist/types/UI/ContentSelector.d.ts.map +1 -1
  96. package/dist/types/client/IntlayerProvider.d.ts +50 -5
  97. package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
  98. package/dist/types/client/format/index.d.ts +2 -1
  99. package/dist/types/client/format/useCompact.d.ts +2 -3
  100. package/dist/types/client/format/useCompact.d.ts.map +1 -1
  101. package/dist/types/client/format/useCurrency.d.ts +2 -3
  102. package/dist/types/client/format/useCurrency.d.ts.map +1 -1
  103. package/dist/types/client/format/useDate.d.ts +0 -1
  104. package/dist/types/client/format/useDate.d.ts.map +1 -1
  105. package/dist/types/client/format/useIntl.d.ts +92 -0
  106. package/dist/types/client/format/useIntl.d.ts.map +1 -0
  107. package/dist/types/client/format/useList.d.ts +2 -3
  108. package/dist/types/client/format/useList.d.ts.map +1 -1
  109. package/dist/types/client/format/useNumber.d.ts +2 -3
  110. package/dist/types/client/format/useNumber.d.ts.map +1 -1
  111. package/dist/types/client/format/usePercentage.d.ts +2 -3
  112. package/dist/types/client/format/usePercentage.d.ts.map +1 -1
  113. package/dist/types/client/format/useRelativeTime.d.ts +2 -3
  114. package/dist/types/client/format/useRelativeTime.d.ts.map +1 -1
  115. package/dist/types/client/format/useUnit.d.ts +2 -3
  116. package/dist/types/client/format/useUnit.d.ts.map +1 -1
  117. package/dist/types/client/t.d.ts +21 -3
  118. package/dist/types/client/t.d.ts.map +1 -1
  119. package/dist/types/client/useDictionary.d.ts +2 -3
  120. package/dist/types/client/useDictionary.d.ts.map +1 -1
  121. package/dist/types/client/useDictionaryAsync.d.ts +0 -1
  122. package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
  123. package/dist/types/client/useDictionaryDynamic.d.ts +0 -1
  124. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
  125. package/dist/types/client/useI18n.d.ts +0 -1
  126. package/dist/types/client/useI18n.d.ts.map +1 -1
  127. package/dist/types/client/useIntlayer.d.ts +18 -6
  128. package/dist/types/client/useIntlayer.d.ts.map +1 -1
  129. package/dist/types/client/useLoadDynamic.d.ts.map +1 -1
  130. package/dist/types/client/useLocale.d.ts +21 -1
  131. package/dist/types/client/useLocale.d.ts.map +1 -1
  132. package/dist/types/client/useLocaleBase.d.ts +5 -5
  133. package/dist/types/client/useLocaleBase.d.ts.map +1 -1
  134. package/dist/types/client/useLocaleStorage.d.ts +5 -6
  135. package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
  136. package/dist/types/client/useTraduction.d.ts +0 -1
  137. package/dist/types/client/useTraduction.d.ts.map +1 -1
  138. package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
  139. package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
  140. package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -1
  141. package/dist/types/getDictionary.d.ts.map +1 -1
  142. package/dist/types/getIntlayer.d.ts.map +1 -1
  143. package/dist/types/html/HTMLProvider.d.ts +17 -0
  144. package/dist/types/html/HTMLProvider.d.ts.map +1 -0
  145. package/dist/types/html/HTMLRenderer.d.ts +46 -0
  146. package/dist/types/html/HTMLRenderer.d.ts.map +1 -0
  147. package/dist/types/html/HTMLRendererPlugin.d.ts +15 -0
  148. package/dist/types/html/HTMLRendererPlugin.d.ts.map +1 -0
  149. package/dist/types/html/index.d.ts +5 -0
  150. package/dist/types/html/types.d.ts +26 -0
  151. package/dist/types/html/types.d.ts.map +1 -0
  152. package/dist/types/index.d.ts +8 -2
  153. package/dist/types/index.d.ts.map +1 -1
  154. package/dist/types/markdown/MarkdownProvider.d.ts +42 -3
  155. package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -1
  156. package/dist/types/markdown/MarkdownRenderer.d.ts +251 -11
  157. package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
  158. package/dist/types/markdown/MarkdownRendererPlugin.d.ts +19 -0
  159. package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -0
  160. package/dist/types/markdown/index.d.ts +6 -3
  161. package/dist/types/markdown/processor.d.ts +92 -0
  162. package/dist/types/markdown/processor.d.ts.map +1 -0
  163. package/dist/types/markdown/runtime.d.ts +19 -0
  164. package/dist/types/markdown/runtime.d.ts.map +1 -0
  165. package/dist/types/plugins.d.ts +35 -13
  166. package/dist/types/plugins.d.ts.map +1 -1
  167. package/dist/types/reactElement/renderReactElement.d.ts +2 -2
  168. package/dist/types/reactElement/renderReactElement.d.ts.map +1 -1
  169. package/dist/types/server/IntlayerServerProvider.d.ts +2 -2
  170. package/dist/types/server/IntlayerServerProvider.d.ts.map +1 -1
  171. package/dist/types/server/format/useCompact.d.ts +0 -1
  172. package/dist/types/server/format/useCompact.d.ts.map +1 -1
  173. package/dist/types/server/format/useCurrency.d.ts +0 -1
  174. package/dist/types/server/format/useCurrency.d.ts.map +1 -1
  175. package/dist/types/server/format/useDate.d.ts +0 -1
  176. package/dist/types/server/format/useDate.d.ts.map +1 -1
  177. package/dist/types/server/format/useIntl.d.ts +92 -0
  178. package/dist/types/server/format/useIntl.d.ts.map +1 -0
  179. package/dist/types/server/format/useList.d.ts +0 -1
  180. package/dist/types/server/format/useList.d.ts.map +1 -1
  181. package/dist/types/server/format/useNumber.d.ts +0 -1
  182. package/dist/types/server/format/useNumber.d.ts.map +1 -1
  183. package/dist/types/server/format/usePercentage.d.ts +0 -1
  184. package/dist/types/server/format/usePercentage.d.ts.map +1 -1
  185. package/dist/types/server/format/useRelativeTime.d.ts +0 -1
  186. package/dist/types/server/format/useRelativeTime.d.ts.map +1 -1
  187. package/dist/types/server/format/useUnit.d.ts +0 -1
  188. package/dist/types/server/format/useUnit.d.ts.map +1 -1
  189. package/dist/types/server/index.d.ts +2 -1
  190. package/dist/types/server/serverContext.d.ts +0 -1
  191. package/dist/types/server/serverContext.d.ts.map +1 -1
  192. package/dist/types/server/t.d.ts +0 -1
  193. package/dist/types/server/t.d.ts.map +1 -1
  194. package/dist/types/server/useDictionary.d.ts +2 -3
  195. package/dist/types/server/useDictionary.d.ts.map +1 -1
  196. package/dist/types/server/useDictionaryAsync.d.ts +2 -3
  197. package/dist/types/server/useDictionaryAsync.d.ts.map +1 -1
  198. package/dist/types/server/useDictionaryDynamic.d.ts +0 -1
  199. package/dist/types/server/useDictionaryDynamic.d.ts.map +1 -1
  200. package/dist/types/server/useI18n.d.ts +0 -1
  201. package/dist/types/server/useI18n.d.ts.map +1 -1
  202. package/dist/types/server/useIntlayer.d.ts +3 -3
  203. package/dist/types/server/useIntlayer.d.ts.map +1 -1
  204. package/dist/types/server/useLoadDynamic.d.ts.map +1 -1
  205. package/dist/types/server/useLocale.d.ts.map +1 -1
  206. package/package.json +22 -12
@@ -12,7 +12,7 @@ _intlayer_config_built = require_rolldown_runtime.__toESM(_intlayer_config_built
12
12
 
13
13
  //#region src/client/IntlayerProvider.tsx
14
14
  /**
15
- * Context that store the current locale on the client side
15
+ * Context that stores the current locale on the client side.
16
16
  */
17
17
  const IntlayerClientContext = (0, react.createContext)({
18
18
  locale: require_client_useLocaleStorage.localeInStorage ?? _intlayer_config_built.default?.internationalization?.defaultLocale,
@@ -21,11 +21,18 @@ const IntlayerClientContext = (0, react.createContext)({
21
21
  disableEditor: false
22
22
  });
23
23
  /**
24
- * Hook that provides the current locale
24
+ * Hook that provides the current Intlayer client context.
25
+ *
26
+ * @returns The current Intlayer context values.
25
27
  */
26
28
  const useIntlayerContext = () => (0, react.useContext)(IntlayerClientContext);
27
29
  /**
28
- * Provider that store the current locale on the client side
30
+ * Provider that stores the current locale on the client side.
31
+ *
32
+ * This component is focused on content delivery without the editor features.
33
+ *
34
+ * @param props - The provider props.
35
+ * @returns The provider component.
29
36
  */
30
37
  const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLocaleProp, children, setLocale: setLocaleProp, disableEditor, isCookieEnabled }) => {
31
38
  const { internationalization } = _intlayer_config_built.default ?? {};
@@ -55,6 +62,26 @@ const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLoc
55
62
  children
56
63
  });
57
64
  };
65
+ /**
66
+ * Main provider for Intlayer in React applications.
67
+ *
68
+ * It includes the editor provider by default, allowing for live content editing
69
+ * if configured.
70
+ *
71
+ * @param props - The provider props.
72
+ * @returns The provider component with editor support.
73
+ *
74
+ * @example
75
+ * ```tsx
76
+ * import { IntlayerProvider } from 'react-intlayer';
77
+ *
78
+ * const App = () => (
79
+ * <IntlayerProvider>
80
+ * <MyComponent />
81
+ * </IntlayerProvider>
82
+ * );
83
+ * ```
84
+ */
58
85
  const IntlayerProvider = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_IntlayerEditorProvider.IntlayerEditorProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntlayerProviderContent, { ...props }) });
59
86
 
60
87
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"IntlayerProvider.cjs","names":["localeInStorage","configuration","MessageKey","IntlayerEditorProvider"],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { localeResolver } from '@intlayer/core';\nimport { MessageKey, useCrossFrameState } from '@intlayer/editor-react';\nimport type { LocalesValues } from '@intlayer/types';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useEffect,\n} from 'react';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeInStorage ?? configuration?.internationalization?.defaultLocale,\n setLocale: () => null,\n isCookieEnabled: true,\n disableEditor: false,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren<{\n locale?: LocalesValues;\n defaultLocale?: LocalesValues;\n setLocale?: (locale: LocalesValues) => void;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { internationalization } = configuration ?? {};\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n const initialLocale =\n localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] = useCrossFrameState(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n initialLocale\n );\n\n // Sync the prop to state if the prop changes from the parent\n useEffect(() => {\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }, [localeProp]);\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);\n setLocaleInStorage(newLocale, isCookieEnabled);\n };\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(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: FC<IntlayerProviderProps> = (props) => (\n <IntlayerEditorProvider>\n <IntlayerProviderContent {...props} />\n </IntlayerEditorProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,MAAa,iDAAqD;CAChE,QAAQA,mDAAmBC,gCAAe,sBAAsB;CAChE,iBAAiB;CACjB,iBAAiB;CACjB,eAAe;CAChB,CAAC;;;;AAKF,MAAa,iDAAsC,sBAAsB;;;;AAazE,MAAa,2BAAsD,EACjE,QAAQ,YACR,eAAe,mBACf,UACA,WAAW,eACX,eACA,sBACI;CACJ,MAAM,EAAE,yBAAyBA,kCAAiB,EAAE;CACpD,MAAM,EAAE,SAAS,kBAAkB,eAAe,wBAChD,wBAAwB,EAAE;CAE5B,MAAM,gBACJ,cAAcD,mDAAmB,qBAAqB;CAExD,MAAM,CAAC,eAAe,mEACpBE,kCAAW,yBACX,cACD;AAGD,4BAAgB;AACd,MAAI,cAAc,eAAe,cAC/B,kBAAiB,WAAW;IAE7B,CAAC,WAAW,CAAC;CAEhB,MAAM,iBAAiB,cAA6B;AAClD,MAAI,cAAc,UAAU,KAAK,UAAU,UAAU,CAAE;AAEvD,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AACtD,WAAQ,MAAM,UAAU,UAAU,mBAAmB;AACrD;;AAGF,mBAAiB,UAAU;AAC3B,qDAAmB,WAAW,gBAAgB;;CAGhD,MAAM,YAAY,iBAAiB;CAGnC,MAAM,oDAAgC,cAAc;AAEpD,QACE,2CAAC,sBAAsB;EACrB,OAAO;GACL,QAAQ;GACR;GACA;GACD;EAEA;GAC8B;;AAIrC,MAAa,oBAA+C,UAC1D,2CAACC,0EACC,2CAAC,2BAAwB,GAAI,QAAS,GACf"}
1
+ {"version":3,"file":"IntlayerProvider.cjs","names":["localeInStorage","configuration","MessageKey","IntlayerEditorProvider"],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { localeResolver } from '@intlayer/core';\nimport { MessageKey, useCrossFrameState } from '@intlayer/editor-react';\nimport type { LocalesValues } from '@intlayer/types';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useEffect,\n} from 'react';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that stores the current locale on the client side.\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeInStorage ?? configuration?.internationalization?.defaultLocale,\n setLocale: () => null,\n isCookieEnabled: true,\n disableEditor: false,\n});\n\n/**\n * Hook that provides the current Intlayer client context.\n *\n * @returns The current Intlayer context values.\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\n/**\n * Props for the IntlayerProvider component.\n */\nexport type IntlayerProviderProps = PropsWithChildren<{\n /**\n * The locale to use. If not provided, it will be detected from storage or configuration.\n */\n locale?: LocalesValues;\n /**\n * The default locale to use as a fallback.\n */\n defaultLocale?: LocalesValues;\n /**\n * Function to set the locale.\n */\n setLocale?: (locale: LocalesValues) => void;\n /**\n * Whether to disable the editor.\n */\n disableEditor?: boolean;\n /**\n * Whether to enable cookies for storing the locale.\n */\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that stores the current locale on the client side.\n *\n * This component is focused on content delivery without the editor features.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { internationalization } = configuration ?? {};\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n const initialLocale =\n localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] = useCrossFrameState(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n initialLocale\n );\n\n // Sync the prop to state if the prop changes from the parent\n useEffect(() => {\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }, [localeProp]);\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);\n setLocaleInStorage(newLocale, isCookieEnabled);\n };\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(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\n/**\n * Main provider for Intlayer in React applications.\n *\n * It includes the editor provider by default, allowing for live content editing\n * if configured.\n *\n * @param props - The provider props.\n * @returns The provider component with editor support.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'react-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerEditorProvider>\n <IntlayerProviderContent {...props} />\n </IntlayerEditorProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,MAAa,iDAAqD;CAChE,QAAQA,mDAAmBC,gCAAe,sBAAsB;CAChE,iBAAiB;CACjB,iBAAiB;CACjB,eAAe;CAChB,CAAC;;;;;;AAOF,MAAa,iDAAsC,sBAAsB;;;;;;;;;AAoCzE,MAAa,2BAAsD,EACjE,QAAQ,YACR,eAAe,mBACf,UACA,WAAW,eACX,eACA,sBACI;CACJ,MAAM,EAAE,yBAAyBA,kCAAiB,EAAE;CACpD,MAAM,EAAE,SAAS,kBAAkB,eAAe,wBAChD,wBAAwB,EAAE;CAE5B,MAAM,gBACJ,cAAcD,mDAAmB,qBAAqB;CAExD,MAAM,CAAC,eAAe,mEACpBE,kCAAW,yBACX,cACD;AAGD,4BAAgB;AACd,MAAI,cAAc,eAAe,cAC/B,kBAAiB,WAAW;IAE7B,CAAC,WAAW,CAAC;CAEhB,MAAM,iBAAiB,cAA6B;AAClD,MAAI,cAAc,UAAU,KAAK,UAAU,UAAU,CAAE;AAEvD,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AACtD,WAAQ,MAAM,UAAU,UAAU,mBAAmB;AACrD;;AAGF,mBAAiB,UAAU;AAC3B,qDAAmB,WAAW,gBAAgB;;CAGhD,MAAM,YAAY,iBAAiB;CAGnC,MAAM,oDAAgC,cAAc;AAEpD,QACE,2CAAC,sBAAsB;EACrB,OAAO;GACL,QAAQ;GACR;GACA;GACD;EAEA;GAC8B;;;;;;;;;;;;;;;;;;;;;;AAwBrC,MAAa,oBAA+C,UAC1D,2CAACC,0EACC,2CAAC,2BAAwB,GAAI,QAAS,GACf"}
@@ -1,3 +1,4 @@
1
+ const require_client_format_useIntl = require('./useIntl.cjs');
1
2
  const require_client_format_useCompact = require('./useCompact.cjs');
2
3
  const require_client_format_useCurrency = require('./useCurrency.cjs');
3
4
  const require_client_format_useDate = require('./useDate.cjs');
@@ -10,6 +11,7 @@ const require_client_format_useUnit = require('./useUnit.cjs');
10
11
  exports.useCompact = require_client_format_useCompact.useCompact;
11
12
  exports.useCurrency = require_client_format_useCurrency.useCurrency;
12
13
  exports.useDate = require_client_format_useDate.useDate;
14
+ exports.useIntl = require_client_format_useIntl.useIntl;
13
15
  exports.useList = require_client_format_useList.useList;
14
16
  exports.useNumber = require_client_format_useNumber.useNumber;
15
17
  exports.usePercentage = require_client_format_usePercentage.usePercentage;
@@ -0,0 +1,45 @@
1
+ 'use client';
2
+
3
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
4
+ const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
5
+ let react = require("react");
6
+ let _intlayer_core = require("@intlayer/core");
7
+
8
+ //#region src/client/format/useIntl.ts
9
+ /**
10
+ * React client hook that provides a locale-bound `Intl` object.
11
+ *
12
+ * It acts exactly like the native `Intl` object, but acts as a proxy to:
13
+ * 1. Inject the current locale automatically if none is provided.
14
+ * 2. Use the performance-optimized `CachedIntl` under the hood.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * const intl = useIntl(); // uses context locale
19
+ *
20
+ * // Standard API, but no need to pass 'en-US' as the first argument
21
+ * const formatted = new intl.NumberFormat({
22
+ * style: 'currency',
23
+ * currency: 'USD'
24
+ * }).format(123.45);
25
+ * ```
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * const intl = useIntl();
30
+ *
31
+ * // You can still override the locale if needed
32
+ * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());
33
+ * // or
34
+ * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());
35
+ * ```
36
+ */
37
+ const useIntl = (locale) => {
38
+ const { locale: contextLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
39
+ const currentLocale = locale ?? contextLocale;
40
+ return (0, react.useMemo)(() => (0, _intlayer_core.bindIntl)(currentLocale), [currentLocale]);
41
+ };
42
+
43
+ //#endregion
44
+ exports.useIntl = useIntl;
45
+ //# sourceMappingURL=useIntl.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntl.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["'use client';\n\nimport { bindIntl } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,WAAW,WAA2B;CACjD,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB;CACnE,MAAM,gBAAgB,UAAU;AAEhC,8DAA8B,cAAc,EAAE,CAAC,cAAc,CAAC"}
@@ -7,9 +7,28 @@ let _intlayer_core = require("@intlayer/core");
7
7
 
8
8
  //#region src/client/t.ts
9
9
  /**
10
- * On the client side, this function returns the translation of the provided multilang content.
10
+ * Client-side translation function that returns the translation of the provided multilang content.
11
11
  *
12
- * If the locale is not provided, it will use the locale from the client context
12
+ * If the locale is not provided, it will use the locale from the client context.
13
+ *
14
+ * @param multilangContent - An object mapping locales to their respective content.
15
+ * @param locale - Optional locale to override the current context locale.
16
+ * @returns The translation for the specified locale.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * import { t } from 'react-intlayer';
21
+ *
22
+ * const MyComponent = () => {
23
+ * const greeting = t({
24
+ * en: 'Hello',
25
+ * fr: 'Bonjour',
26
+ * es: 'Hola',
27
+ * });
28
+ *
29
+ * return <h1>{greeting}</h1>;
30
+ * };
31
+ * ```
13
32
  */
14
33
  const t = (multilangContent, locale) => {
15
34
  const { locale: currentLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
@@ -1 +1 @@
1
- {"version":3,"file":"t.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport { getTranslation } from '@intlayer/core';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext } from 'react';\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: StrictModeLocaleMap<Content>,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,KACX,kBACA,WACG;CACH,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB;AAGnE,2CAA+B,kBAFV,UAAU,cAE+B"}
1
+ {"version":3,"file":"t.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport { getTranslation } from '@intlayer/core';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side translation function that 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 *\n * @param multilangContent - An object mapping locales to their respective content.\n * @param locale - Optional locale to override the current context locale.\n * @returns The translation for the specified locale.\n *\n * @example\n * ```tsx\n * import { t } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * es: 'Hola',\n * });\n *\n * return <h1>{greeting}</h1>;\n * };\n * ```\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,KACX,kBACA,WACG;CACH,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB;AAGnE,2CAA+B,kBAFV,UAAU,cAE+B"}
@@ -7,11 +7,24 @@ let react = require("react");
7
7
 
8
8
  //#region src/client/useIntlayer.ts
9
9
  /**
10
- * On the client side, Hook that picking one dictionary by its key and return the content
10
+ * Client-side hook that picks one dictionary by its key and returns its content.
11
11
  *
12
- * If the locale is not provided, it will use the locale from the client context
12
+ * If the locale is not provided, it will use the locale from the client context.
13
13
  *
14
- * When you need the raw string for attributes like `aria-label`, access the `.value` property of the returned content
14
+ * @param key - The unique key of the dictionary to retrieve.
15
+ * @param locale - Optional locale to override the current context locale.
16
+ * @returns The dictionary content for the specified locale.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * import { useIntlayer } from 'react-intlayer';
21
+ *
22
+ * const MyComponent = () => {
23
+ * const content = useIntlayer('my-dictionary-key');
24
+ *
25
+ * return <div>{content.myField.value}</div>;
26
+ * };
27
+ * ```
15
28
  */
16
29
  const useIntlayer = (key, locale) => {
17
30
  const { locale: currentLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
@@ -1 +1 @@
1
- {"version":3,"file":"useIntlayer.cjs","names":["IntlayerClientContext","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\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 *\n * When you need the raw string for attributes like `aria-label`, access the `.value` property of the returned content\n */\nexport const useIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? (currentLocale as L);\n\n return getIntlayer<T, L>(key, localeTarget);\n }, [key, currentLocale, locale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAa,eAIX,KACA,WACG;CACH,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB;AAEnE,iCAAqB;AAGnB,SAAOC,gCAAkB,KAFJ,UAAW,cAEW;IAC1C;EAAC;EAAK;EAAe;EAAO,CAAC"}
1
+ {"version":3,"file":"useIntlayer.cjs","names":["IntlayerClientContext","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that picks one dictionary by its key and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The dictionary content for the specified locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? (currentLocale as L);\n\n return getIntlayer<T, L>(key, localeTarget);\n }, [key, currentLocale, locale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,eAIX,KACA,WACG;CACH,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB;AAEnE,iCAAqB;AAGnB,SAAOC,gCAAkB,KAFJ,UAAW,cAEW;IAC1C;EAAC;EAAK;EAAe;EAAO,CAAC"}
@@ -9,7 +9,27 @@ _intlayer_config_built = require_rolldown_runtime.__toESM(_intlayer_config_built
9
9
 
10
10
  //#region src/client/useLocale.ts
11
11
  /**
12
- * On the client side, hook to get the current locale and all related fields
12
+ * Client-side hook to get the current locale and related locale management functions.
13
+ *
14
+ * @param props - Optional properties for the hook.
15
+ * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * import { useLocale } from 'react-intlayer';
20
+ *
21
+ * const LocaleSwitcher = () => {
22
+ * const { locale, setLocale, availableLocales } = useLocale();
23
+ *
24
+ * return (
25
+ * <select value={locale} onChange={(e) => setLocale(e.target.value)}>
26
+ * {availableLocales.map((loc) => (
27
+ * <option key={loc} value={loc}>{loc}</option>
28
+ * ))}
29
+ * </select>
30
+ * );
31
+ * };
32
+ * ```
13
33
  */
14
34
  const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
15
35
  const { defaultLocale, locales: availableLocales } = _intlayer_config_built.default?.internationalization ?? {};
@@ -18,14 +38,14 @@ const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
18
38
  locale,
19
39
  defaultLocale,
20
40
  availableLocales,
21
- setLocale: (0, react.useCallback)((locale$1) => {
22
- if (!availableLocales?.map(String).includes(locale$1)) {
23
- console.error(`Locale ${locale$1} is not available`);
41
+ setLocale: (0, react.useCallback)((locale) => {
42
+ if (!availableLocales?.map(String).includes(locale)) {
43
+ console.error(`Locale ${locale} is not available`);
24
44
  return;
25
45
  }
26
- setLocaleState(locale$1);
27
- require_client_useLocaleStorage.setLocaleInStorage(locale$1, isCookieEnabled ?? isCookieEnabledContext ?? true);
28
- onLocaleChange?.(locale$1);
46
+ setLocaleState(locale);
47
+ require_client_useLocaleStorage.setLocaleInStorage(locale, isCookieEnabled ?? isCookieEnabledContext ?? true);
48
+ onLocaleChange?.(locale);
29
49
  }, [
30
50
  availableLocales,
31
51
  onLocaleChange,
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.cjs","names":["configuration","IntlayerClientContext","locale"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { DeclaredLocales, LocalesValues } from '@intlayer/types';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = useCallback(\n (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 setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\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 } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;;;;;AAuBA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAsB;CAC1C,MAAM,EAAE,eAAe,SAAS,qBAC9BA,gCAAe,wBAAwB,EAAE;CAE3C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,iDACJC,sDAAsB;AAmBrC,QAAO;EACL;EACA;EACA;EACA,mCApBC,aAA0B;AACzB,OAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAASC,SAAO,EAAE;AACnD,YAAQ,MAAM,UAAUA,SAAO,mBAAmB;AAClD;;AAGF,kBAAeA,SAAO;AACtB,sDACEA,UACA,mBAAmB,0BAA0B,KAC9C;AACD,oBAAiBA,SAAO;KAE1B;GAAC;GAAkB;GAAgB;GAAgB;GAAgB,CACpE;EAOA"}
1
+ {"version":3,"file":"useLocale.cjs","names":["configuration","IntlayerClientContext"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { DeclaredLocales, LocalesValues } from '@intlayer/types';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * Client-side hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'react-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = useCallback(\n (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 setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\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 } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAsB;CAC1C,MAAM,EAAE,eAAe,SAAS,qBAC9BA,gCAAe,wBAAwB,EAAE;CAE3C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,iDACJC,sDAAsB;AAmBrC,QAAO;EACL;EACA;EACA;EACA,mCApBC,WAA0B;AACzB,OAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,OAAO,EAAE;AACnD,YAAQ,MAAM,UAAU,OAAO,mBAAmB;AAClD;;AAGF,kBAAe,OAAO;AACtB,sDACE,QACA,mBAAmB,0BAA0B,KAC9C;AACD,oBAAiB,OAAO;KAE1B;GAAC;GAAkB;GAAgB;GAAgB;GAAgB,CACpE;EAOA"}
@@ -7,7 +7,9 @@ const getDictionary = (dictionary, locale, additionalPlugins) => {
7
7
  return (0, _intlayer_core.getDictionary)(dictionary, locale, [
8
8
  require_plugins.intlayerNodePlugins,
9
9
  require_plugins.reactNodePlugins,
10
+ require_plugins.insertionPlugin,
10
11
  require_plugins.markdownPlugin,
12
+ require_plugins.htmlPlugin,
11
13
  ...additionalPlugins ?? []
12
14
  ]);
13
15
  };
@@ -1 +1 @@
1
- {"version":3,"file":"getDictionary.cjs","names":["intlayerNodePlugins","reactNodePlugins","markdownPlugin"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import {\n getDictionary as getDictionaryCore,\n type Plugins,\n} from '@intlayer/core';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n reactNodePlugins,\n} from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n): DeepTransformContent<T['content'], L> => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n reactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n return getDictionaryCore(dictionary, locale, plugins) as any;\n};\n"],"mappings":";;;;;AAgBA,MAAa,iBAIX,YACA,QACA,sBAC0C;AAQ1C,0CAAyB,YAAY,QAPV;EACzBA;EACAC;EACAC;EACA,GAAI,qBAAqB,EAAE;EAC5B,CAEoD"}
1
+ {"version":3,"file":"getDictionary.cjs","names":["intlayerNodePlugins","reactNodePlugins","insertionPlugin","markdownPlugin","htmlPlugin"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import {\n getDictionary as getDictionaryCore,\n type Plugins,\n} from '@intlayer/core';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n htmlPlugin,\n insertionPlugin,\n intlayerNodePlugins,\n markdownPlugin,\n reactNodePlugins,\n} from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n): DeepTransformContent<T['content'], L> => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n return getDictionaryCore(dictionary, locale, plugins) as any;\n};\n"],"mappings":";;;;;AAkBA,MAAa,iBAIX,YACA,QACA,sBAC0C;AAU1C,0CAAyB,YAAY,QATV;EACzBA;EACAC;EACAC;EACAC;EACAC;EACA,GAAI,qBAAqB,EAAE;EAC5B,CAEoD"}
@@ -7,7 +7,9 @@ const getIntlayer = (key, locale, additionalPlugins) => {
7
7
  return (0, _intlayer_core.getIntlayer)(key, locale, [
8
8
  require_plugins.intlayerNodePlugins,
9
9
  require_plugins.reactNodePlugins,
10
+ require_plugins.insertionPlugin,
10
11
  require_plugins.markdownPlugin,
12
+ require_plugins.htmlPlugin,
11
13
  ...additionalPlugins ?? []
12
14
  ]);
13
15
  };
@@ -1 +1 @@
1
- {"version":3,"file":"getIntlayer.cjs","names":["intlayerNodePlugins","reactNodePlugins","markdownPlugin"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore, type Plugins } from '@intlayer/core';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n reactNodePlugins,\n} from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n): DeepTransformContent<DictionaryRegistryContent<T>, L> => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n reactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n return getIntlayerCore(key, locale, plugins) as any;\n};\n"],"mappings":";;;;;AAcA,MAAa,eAIX,KACA,QACA,sBAC0D;AAQ1D,wCAAuB,KAAK,QAPD;EACzBA;EACAC;EACAC;EACA,GAAI,qBAAqB,EAAE;EAC5B,CAE2C"}
1
+ {"version":3,"file":"getIntlayer.cjs","names":["intlayerNodePlugins","reactNodePlugins","insertionPlugin","markdownPlugin","htmlPlugin"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore, type Plugins } from '@intlayer/core';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n htmlPlugin,\n insertionPlugin,\n intlayerNodePlugins,\n markdownPlugin,\n reactNodePlugins,\n} from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n): DeepTransformContent<DictionaryRegistryContent<T>, L> => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n return getIntlayerCore(key, locale, plugins) as any;\n};\n"],"mappings":";;;;;AAgBA,MAAa,eAIX,KACA,QACA,sBAC0D;AAU1D,wCAAuB,KAAK,QATD;EACzBA;EACAC;EACAC;EACAC;EACAC;EACA,GAAI,qBAAqB,EAAE;EAC5B,CAE2C"}
@@ -0,0 +1,18 @@
1
+ 'use client';
2
+
3
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
4
+ let react = require("react");
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+
7
+ //#region src/html/HTMLProvider.tsx
8
+ const HTMLContext = (0, react.createContext)(void 0);
9
+ const useHTMLContext = () => (0, react.useContext)(HTMLContext);
10
+ const HTMLProvider = ({ children, components }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HTMLContext.Provider, {
11
+ value: { components },
12
+ children
13
+ });
14
+
15
+ //#endregion
16
+ exports.HTMLProvider = HTMLProvider;
17
+ exports.useHTMLContext = useHTMLContext;
18
+ //# sourceMappingURL=HTMLProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HTMLProvider.cjs","names":[],"sources":["../../../src/html/HTMLProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\n\ntype HTMLContextValue = {\n components?: Record<string, any>;\n};\n\ntype HTMLProviderProps = PropsWithChildren<{\n /**\n * Component overrides for HTML tags.\n */\n components?: Record<string, any>;\n}>;\n\nconst HTMLContext = createContext<HTMLContextValue | undefined>(undefined);\n\nexport const useHTMLContext = () => useContext(HTMLContext);\n\nexport const HTMLProvider: FC<HTMLProviderProps> = ({\n children,\n components,\n}) => (\n <HTMLContext.Provider value={{ components }}>{children}</HTMLContext.Provider>\n);\n"],"mappings":";;;;;;;AAoBA,MAAM,uCAA0D,OAAU;AAE1E,MAAa,6CAAkC,YAAY;AAE3D,MAAa,gBAAuC,EAClD,UACA,iBAEA,2CAAC,YAAY;CAAS,OAAO,EAAE,YAAY;CAAG;EAAgC"}
@@ -0,0 +1,59 @@
1
+ 'use client';
2
+
3
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
4
+ const require_html_HTMLProvider = require('./HTMLProvider.cjs');
5
+ let react = require("react");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ let _intlayer_core = require("@intlayer/core");
8
+
9
+ //#region src/html/HTMLRenderer.tsx
10
+ const createDefaultHTMLComponents = () => {
11
+ const components = {};
12
+ for (const tag of _intlayer_core.HTML_TAGS) components[tag] = ({ children, ...props }) => (0, react.createElement)(tag, props, children);
13
+ return components;
14
+ };
15
+ const defaultHTMLComponents = createDefaultHTMLComponents();
16
+ /**
17
+ * Renders HTML-like content to JSX with the provided components.
18
+ *
19
+ * This function does not use context from HTMLProvider. Use `useHTMLRenderer`
20
+ * hook if you want to leverage provider context.
21
+ */
22
+ const renderHTML = (content, { components } = {}) => {
23
+ const mergedComponents = {
24
+ ...defaultHTMLComponents,
25
+ ...components
26
+ };
27
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: (0, _intlayer_core.getHTML)(content, Object.fromEntries(Object.entries(mergedComponents).filter(([, Component]) => Component).map(([key, Component]) => [key, (props) => (0, react.createElement)(Component, props)]))) });
28
+ };
29
+ /**
30
+ * Hook that returns a function to render HTML content.
31
+ *
32
+ * This hook considers the configuration from the `HTMLProvider` context if available,
33
+ * falling back to the provided components.
34
+ */
35
+ const useHTMLRenderer = ({ components } = {}) => {
36
+ const context = require_html_HTMLProvider.useHTMLContext();
37
+ return (content) => {
38
+ return renderHTML(content, { components: {
39
+ ...context?.components,
40
+ ...components
41
+ } });
42
+ };
43
+ };
44
+ /**
45
+ * React component that renders HTML-like content to JSX.
46
+ *
47
+ * This component uses the components from the `HTMLProvider` context
48
+ * if available.
49
+ */
50
+ const HTMLRenderer = ({ children = "", components }) => {
51
+ return useHTMLRenderer({ components })(children);
52
+ };
53
+
54
+ //#endregion
55
+ exports.HTMLRenderer = HTMLRenderer;
56
+ exports.defaultHTMLComponents = defaultHTMLComponents;
57
+ exports.renderHTML = renderHTML;
58
+ exports.useHTMLRenderer = useHTMLRenderer;
59
+ //# sourceMappingURL=HTMLRenderer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HTMLRenderer.cjs","names":["HTML_TAGS","Fragment","useHTMLContext"],"sources":["../../../src/html/HTMLRenderer.tsx"],"sourcesContent":["'use client';\n\nimport { getHTML, HTML_TAGS } from '@intlayer/core';\nimport { createElement, type FC, Fragment, type JSX } from 'react';\nimport { useHTMLContext } from './HTMLProvider';\nimport type { ReactHTMLComponent } from './types';\n\n/**\n * Type for React HTML tag components.\n */\ntype HTMLTagComponent = ReactHTMLComponent;\n\nconst createDefaultHTMLComponents = (): Record<string, HTMLTagComponent> => {\n const components: Record<string, HTMLTagComponent> = {};\n\n for (const tag of HTML_TAGS) {\n components[tag] = ({ children, ...props }) =>\n createElement(tag, props, children);\n }\n\n return components;\n};\n\nexport const defaultHTMLComponents = createDefaultHTMLComponents();\n\nexport type RenderHTMLProps = {\n /**\n * Component overrides for HTML tags.\n * Allows you to customize how specific HTML elements are rendered.\n */\n components?: Record<string, any>;\n};\n\n/**\n * Renders HTML-like content to JSX with the provided components.\n *\n * This function does not use context from HTMLProvider. Use `useHTMLRenderer`\n * hook if you want to leverage provider context.\n */\nexport const renderHTML = (\n content: string,\n { components }: RenderHTMLProps = {}\n): JSX.Element => {\n const mergedComponents = {\n ...defaultHTMLComponents,\n ...components,\n };\n\n // Wrap all components to ensure they are rendered via React.createElement\n const wrappedComponents = Object.fromEntries(\n Object.entries(mergedComponents)\n .filter(([, Component]) => Component)\n .map(([key, Component]) => [\n key,\n (props: any) => createElement(Component as any, props),\n ])\n );\n\n return <Fragment>{getHTML(content, wrappedComponents)}</Fragment>;\n};\n\n/**\n * Hook that returns a function to render HTML content.\n *\n * This hook considers the configuration from the `HTMLProvider` context if available,\n * falling back to the provided components.\n */\nexport const useHTMLRenderer = ({ components }: RenderHTMLProps = {}) => {\n const context = useHTMLContext();\n\n return (content: string) => {\n return renderHTML(content, {\n components: {\n ...context?.components,\n ...components,\n },\n });\n };\n};\n\nexport type HTMLRendererProps = RenderHTMLProps & {\n /**\n * The HTML content to render as a string.\n */\n children: string;\n};\n\n/**\n * React component that renders HTML-like content to JSX.\n *\n * This component uses the components from the `HTMLProvider` context\n * if available.\n */\nexport const HTMLRenderer: FC<HTMLRendererProps> = ({\n children = '',\n components,\n}) => {\n const render = useHTMLRenderer({ components });\n\n return render(children);\n};\n"],"mappings":";;;;;;;;;AAYA,MAAM,oCAAsE;CAC1E,MAAM,aAA+C,EAAE;AAEvD,MAAK,MAAM,OAAOA,yBAChB,YAAW,QAAQ,EAAE,UAAU,GAAG,qCAClB,KAAK,OAAO,SAAS;AAGvC,QAAO;;AAGT,MAAa,wBAAwB,6BAA6B;;;;;;;AAgBlE,MAAa,cACX,SACA,EAAE,eAAgC,EAAE,KACpB;CAChB,MAAM,mBAAmB;EACvB,GAAG;EACH,GAAG;EACJ;AAYD,QAAO,2CAACC,wDAAkB,SATA,OAAO,YAC/B,OAAO,QAAQ,iBAAiB,CAC7B,QAAQ,GAAG,eAAe,UAAU,CACpC,KAAK,CAAC,KAAK,eAAe,CACzB,MACC,mCAA6B,WAAkB,MAAM,CACvD,CAAC,CACL,CAEoD,GAAY;;;;;;;;AASnE,MAAa,mBAAmB,EAAE,eAAgC,EAAE,KAAK;CACvE,MAAM,UAAUC,0CAAgB;AAEhC,SAAQ,YAAoB;AAC1B,SAAO,WAAW,SAAS,EACzB,YAAY;GACV,GAAG,SAAS;GACZ,GAAG;GACJ,EACF,CAAC;;;;;;;;;AAiBN,MAAa,gBAAuC,EAClD,WAAW,IACX,iBACI;AAGJ,QAFe,gBAAgB,EAAE,YAAY,CAAC,CAEhC,SAAS"}
@@ -0,0 +1,36 @@
1
+ 'use client';
2
+
3
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
4
+ const require_editor_ContentSelectorWrapper = require('../editor/ContentSelectorWrapper.cjs');
5
+ const require_editor_useEditedContentRenderer = require('../editor/useEditedContentRenderer.cjs');
6
+ const require_html_HTMLProvider = require('./HTMLProvider.cjs');
7
+ const require_html_HTMLRenderer = require('./HTMLRenderer.cjs');
8
+ let react = require("react");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ let _intlayer_core = require("@intlayer/core");
11
+
12
+ //#region src/html/HTMLRendererPlugin.tsx
13
+ const HTMLRendererPlugin = (props) => {
14
+ const { dictionaryKey, keyPath, html, userComponents } = props;
15
+ const globalComponents = require_html_HTMLProvider.useHTMLContext()?.components || {};
16
+ const editedContentContext = require_editor_useEditedContentRenderer.useEditedContentRenderer({
17
+ dictionaryKey: dictionaryKey ?? "",
18
+ keyPath: keyPath ?? [],
19
+ children: html
20
+ });
21
+ const contentToRender = typeof editedContentContext === "string" ? editedContentContext : html;
22
+ const mergedComponents = {
23
+ ...require_html_HTMLRenderer.defaultHTMLComponents,
24
+ ...globalComponents,
25
+ ...userComponents
26
+ };
27
+ const wrappedComponents = Object.fromEntries(Object.entries(mergedComponents).filter(([, Component]) => Component).map(([key, Component]) => [key, (props) => (0, react.createElement)(Component, props)]));
28
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelectorWrapper.ContentSelectorRenderer, {
29
+ ...props,
30
+ children: (0, _intlayer_core.getHTML)(contentToRender, wrappedComponents)
31
+ });
32
+ };
33
+
34
+ //#endregion
35
+ exports.HTMLRendererPlugin = HTMLRendererPlugin;
36
+ //# sourceMappingURL=HTMLRendererPlugin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HTMLRendererPlugin.cjs","names":["useHTMLContext","useEditedContentRenderer","defaultHTMLComponents","ContentSelectorRenderer"],"sources":["../../../src/html/HTMLRendererPlugin.tsx"],"sourcesContent":["'use client';\n\nimport { getHTML } from '@intlayer/core';\nimport type { KeyPath, Locale } from '@intlayer/types';\nimport { createElement, type FC, type ReactNode } from 'react';\nimport { ContentSelectorRenderer } from '../editor';\nimport { useEditedContentRenderer } from '../editor/useEditedContentRenderer';\nimport { useHTMLContext } from './HTMLProvider';\nimport { defaultHTMLComponents } from './HTMLRenderer';\nimport type { ReactComponentProps } from './types';\n\ntype HTMLRendererPluginProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n html: string;\n locale?: Locale;\n userComponents?: Record<string, any>;\n};\n\nexport const HTMLRendererPlugin: FC<HTMLRendererPluginProps> = (\n props\n): ReactNode => {\n const { dictionaryKey, keyPath, html, userComponents } = props;\n const context = useHTMLContext();\n const globalComponents = context?.components || {};\n\n const editedContentContext = useEditedContentRenderer({\n dictionaryKey: dictionaryKey ?? '',\n keyPath: keyPath ?? [],\n children: html,\n });\n\n const contentToRender =\n typeof editedContentContext === 'string' ? editedContentContext : html;\n\n const mergedComponents = {\n ...defaultHTMLComponents,\n ...globalComponents,\n ...userComponents,\n };\n\n // Wrap all components to ensure they are rendered via React.createElement\n // This is important because it allows React to handle the component's lifecycle,\n // hooks, and Babel-injected variables correctly.\n const wrappedComponents = Object.fromEntries(\n Object.entries(mergedComponents)\n .filter(([, Component]) => Component)\n .map(([key, Component]) => [\n key,\n (props: ReactComponentProps) => createElement(Component, props),\n ])\n );\n\n return (\n <ContentSelectorRenderer {...props}>\n {getHTML(contentToRender, wrappedComponents)}\n </ContentSelectorRenderer>\n );\n};\n"],"mappings":";;;;;;;;;;;;AAmBA,MAAa,sBACX,UACc;CACd,MAAM,EAAE,eAAe,SAAS,MAAM,mBAAmB;CAEzD,MAAM,mBADUA,0CAAgB,EACE,cAAc,EAAE;CAElD,MAAM,uBAAuBC,iEAAyB;EACpD,eAAe,iBAAiB;EAChC,SAAS,WAAW,EAAE;EACtB,UAAU;EACX,CAAC;CAEF,MAAM,kBACJ,OAAO,yBAAyB,WAAW,uBAAuB;CAEpE,MAAM,mBAAmB;EACvB,GAAGC;EACH,GAAG;EACH,GAAG;EACJ;CAKD,MAAM,oBAAoB,OAAO,YAC/B,OAAO,QAAQ,iBAAiB,CAC7B,QAAQ,GAAG,eAAe,UAAU,CACpC,KAAK,CAAC,KAAK,eAAe,CACzB,MACC,mCAA6C,WAAW,MAAM,CAChE,CAAC,CACL;AAED,QACE,2CAACC;EAAwB,GAAI;wCAClB,iBAAiB,kBAAkB;GACpB"}
@@ -0,0 +1,11 @@
1
+ const require_html_HTMLProvider = require('./HTMLProvider.cjs');
2
+ const require_html_HTMLRenderer = require('./HTMLRenderer.cjs');
3
+ const require_html_HTMLRendererPlugin = require('./HTMLRendererPlugin.cjs');
4
+
5
+ exports.HTMLProvider = require_html_HTMLProvider.HTMLProvider;
6
+ exports.HTMLRenderer = require_html_HTMLRenderer.HTMLRenderer;
7
+ exports.HTMLRendererPlugin = require_html_HTMLRendererPlugin.HTMLRendererPlugin;
8
+ exports.defaultHTMLComponents = require_html_HTMLRenderer.defaultHTMLComponents;
9
+ exports.renderHTML = require_html_HTMLRenderer.renderHTML;
10
+ exports.useHTMLContext = require_html_HTMLProvider.useHTMLContext;
11
+ exports.useHTMLRenderer = require_html_HTMLRenderer.useHTMLRenderer;
File without changes
@@ -10,28 +10,40 @@ const require_getIntlayer = require('./getIntlayer.cjs');
10
10
  const require_client_useIntlayer = require('./client/useIntlayer.cjs');
11
11
  const require_client_useLocale = require('./client/useLocale.cjs');
12
12
  const require_client_useLocaleBase = require('./client/useLocaleBase.cjs');
13
+ const require_html_HTMLProvider = require('./html/HTMLProvider.cjs');
14
+ const require_html_HTMLRenderer = require('./html/HTMLRenderer.cjs');
13
15
  const require_markdown_MarkdownProvider = require('./markdown/MarkdownProvider.cjs');
16
+ const require_markdown_MarkdownRenderer = require('./markdown/MarkdownRenderer.cjs');
14
17
  const require_getDictionary = require('./getDictionary.cjs');
18
+ const require_client_format_useIntl = require('./client/format/useIntl.cjs');
15
19
 
20
+ exports.HTMLProvider = require_html_HTMLProvider.HTMLProvider;
21
+ exports.HTMLRenderer = require_html_HTMLRenderer.HTMLRenderer;
16
22
  exports.IntlayerClientContext = require_client_IntlayerProvider.IntlayerClientContext;
17
23
  exports.IntlayerProvider = require_client_IntlayerProvider.IntlayerProvider;
18
24
  exports.IntlayerProviderContent = require_client_IntlayerProvider.IntlayerProviderContent;
19
25
  exports.MarkdownProvider = require_markdown_MarkdownProvider.MarkdownProvider;
26
+ exports.MarkdownRenderer = require_markdown_MarkdownRenderer.MarkdownRenderer;
20
27
  exports.getDictionary = require_getDictionary.getDictionary;
21
28
  exports.getIntlayer = require_getIntlayer.getIntlayer;
22
29
  exports.localeCookie = require_client_useLocaleStorage.localeCookie;
23
30
  exports.localeInStorage = require_client_useLocaleStorage.localeInStorage;
31
+ exports.renderHTML = require_html_HTMLRenderer.renderHTML;
32
+ exports.renderMarkdown = require_markdown_MarkdownRenderer.renderMarkdown;
24
33
  exports.setLocaleCookie = require_client_useLocaleStorage.setLocaleCookie;
25
34
  exports.setLocaleInStorage = require_client_useLocaleStorage.setLocaleInStorage;
26
35
  exports.t = require_client_t.t;
27
36
  exports.useDictionary = require_client_useDictionary.useDictionary;
28
37
  exports.useDictionaryAsync = require_client_useDictionaryAsync.useDictionaryAsync;
29
38
  exports.useDictionaryDynamic = require_client_useDictionaryDynamic.useDictionaryDynamic;
39
+ exports.useHTMLRenderer = require_html_HTMLRenderer.useHTMLRenderer;
30
40
  exports.useI18n = require_client_useI18n.useI18n;
41
+ exports.useIntl = require_client_format_useIntl.useIntl;
31
42
  exports.useIntlayer = require_client_useIntlayer.useIntlayer;
32
43
  exports.useIntlayerContext = require_client_IntlayerProvider.useIntlayerContext;
33
44
  exports.useLoadDynamic = require_client_useLoadDynamic.useLoadDynamic;
34
45
  exports.useLocale = require_client_useLocale.useLocale;
35
46
  exports.useLocaleBase = require_client_useLocaleBase.useLocaleBase;
36
47
  exports.useLocaleCookie = require_client_useLocaleStorage.useLocaleCookie;
37
- exports.useLocaleStorage = require_client_useLocaleStorage.useLocaleStorage;
48
+ exports.useLocaleStorage = require_client_useLocaleStorage.useLocaleStorage;
49
+ exports.useMarkdownRenderer = require_markdown_MarkdownRenderer.useMarkdownRenderer;
@@ -1,16 +1,87 @@
1
1
  'use client';
2
2
 
3
3
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
4
+ const require_markdown_processor = require('./processor.cjs');
4
5
  let react = require("react");
5
6
  let react_jsx_runtime = require("react/jsx-runtime");
6
7
 
7
8
  //#region src/markdown/MarkdownProvider.tsx
8
- const MarkdownContext = (0, react.createContext)({ renderMarkdown: (markdown) => markdown });
9
+ const MarkdownContext = (0, react.createContext)(void 0);
9
10
  const useMarkdownContext = () => (0, react.useContext)(MarkdownContext);
10
- const MarkdownProvider = ({ children, renderMarkdown }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MarkdownContext.Provider, {
11
- value: { renderMarkdown },
12
- children
13
- });
11
+ const isRenderMarkdownOptions = (override) => {
12
+ return override && typeof override === "object" && ("components" in override || "wrapper" in override || "forceBlock" in override || "forceInline" in override || "preserveFrontmatter" in override || "tagfilter" in override);
13
+ };
14
+ const mergeOptions = (baseOptions, overrides) => {
15
+ if (!overrides) return baseOptions;
16
+ if (!isRenderMarkdownOptions(overrides)) return {
17
+ ...baseOptions,
18
+ components: {
19
+ ...baseOptions.components,
20
+ ...overrides
21
+ }
22
+ };
23
+ const { components: overrideComponents, wrapper, forceBlock, forceInline, preserveFrontmatter, tagfilter, ...componentsFromRest } = overrides;
24
+ const components = overrideComponents || componentsFromRest;
25
+ return {
26
+ ...baseOptions,
27
+ forceBlock: forceBlock ?? baseOptions.forceBlock,
28
+ forceInline: forceInline ?? baseOptions.forceInline,
29
+ preserveFrontmatter: preserveFrontmatter ?? baseOptions.preserveFrontmatter,
30
+ tagfilter: tagfilter ?? baseOptions.tagfilter,
31
+ wrapper: wrapper || baseOptions.wrapper,
32
+ forceWrapper: !!(wrapper || baseOptions.wrapper),
33
+ components: {
34
+ ...baseOptions.components,
35
+ ...components
36
+ }
37
+ };
38
+ };
39
+ /**
40
+ * Provider for the MarkdownRenderer component.
41
+ *
42
+ * It will provide the `renderMarkdown` function to the context, which can be used to render markdown.
43
+ *
44
+ * ```tsx
45
+ * const content = useIntlayer('app');
46
+ *
47
+ * return (
48
+ * <div>
49
+ * {content.markdown} // Will be rendered with the components and options provided to the MarkdownProvider
50
+ * </div>
51
+ * );
52
+ * ```
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * <MarkdownProvider components={{ h1: CustomHeading }}>
57
+ * <MarkdownRenderer>
58
+ * {markdownContent}
59
+ * </MarkdownRenderer>
60
+ * </MarkdownProvider>
61
+ * ```
62
+ */
63
+ const MarkdownProvider = ({ children, components, wrapper, forceBlock, forceInline, preserveFrontmatter, tagfilter, renderMarkdown: customRenderFn }) => {
64
+ const baseOptions = {
65
+ components,
66
+ forceBlock,
67
+ forceInline,
68
+ wrapper,
69
+ forceWrapper: !!wrapper,
70
+ preserveFrontmatter,
71
+ tagfilter
72
+ };
73
+ const defaultRenderMarkdown = (markdown, overrides) => {
74
+ return require_markdown_processor.compiler(markdown, mergeOptions(baseOptions, overrides));
75
+ };
76
+ const customRenderMarkdownWrapper = (markdown, overrides) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MarkdownContext.Provider, {
77
+ value: void 0,
78
+ children: customRenderFn?.(markdown, overrides)
79
+ });
80
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MarkdownContext.Provider, {
81
+ value: { renderMarkdown: customRenderFn ? customRenderMarkdownWrapper : defaultRenderMarkdown },
82
+ children
83
+ });
84
+ };
14
85
 
15
86
  //#endregion
16
87
  exports.MarkdownProvider = MarkdownProvider;