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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.mjs","names":["coreCompile"],"sources":["../../../src/markdown/processor.tsx"],"sourcesContent":["import {\n type Overrides as CoreOverrides,\n compile as coreCompile,\n sanitizer as defaultSanitizer,\n slugify as defaultSlugify,\n type MarkdownContext,\n type MarkdownOptions,\n type MarkdownRuntime,\n type ParserResult,\n type ParseState,\n type RenderRuleHook,\n type RuleOutput,\n RuleType,\n} from '@intlayer/core';\nimport {\n cloneElement,\n createElement,\n type FC,\n Fragment,\n type HTMLAttributes,\n type JSX,\n type ReactNode,\n} from 'react';\n\n// Re-export RuleType for compatibility\nexport { RuleType };\n\n// Re-export utilities for compatibility\nexport { defaultSlugify as slugify, defaultSanitizer as sanitizer };\n\ntype HTMLTags = keyof JSX.IntrinsicElements;\n\ntype State = ParseState;\n\n/**\n * Refined MarkdownRendererOptions type.\n */\nexport type MarkdownRendererOptions = Partial<{\n /**\n * Ultimate control over the output of all rendered JSX.\n */\n createElement: (\n tag: Parameters<typeof createElement>[0],\n props: JSX.IntrinsicAttributes,\n ...children: ReactNode[]\n ) => ReactNode;\n\n /**\n * The library automatically generates an anchor tag for bare URLs included in the markdown\n * document, but this behavior can be disabled if desired.\n */\n disableAutoLink: boolean;\n\n /**\n * Disable the compiler's best-effort transcription of provided raw HTML\n * into JSX-equivalent.\n */\n disableParsingRawHTML: boolean;\n\n /**\n * Forces the compiler to have space between hash sign and the header text.\n */\n enforceAtxHeadings: boolean;\n\n /**\n * Forces the compiler to always output content with a block-level wrapper.\n */\n forceBlock: boolean;\n\n /**\n * Forces the compiler to always output content with an inline wrapper.\n */\n forceInline: boolean;\n\n /**\n * Forces the compiler to wrap results, even if there is only a single child.\n */\n forceWrapper: boolean;\n\n /**\n * Supply additional HTML entity: unicode replacement mappings.\n */\n namedCodesToUnicode: {\n [key: string]: string;\n };\n\n /**\n * Selectively control the output of particular HTML tags.\n */\n components: CoreOverrides;\n\n /**\n * Allows for full control over rendering of particular rules.\n */\n renderRule: RenderRuleHook;\n\n /**\n * Override the built-in sanitizer function for URLs.\n */\n sanitizer: (value: string, tag: HTMLTags, attribute: string) => string | null;\n\n /**\n * Override normalization of non-URI-safe characters for anchor linking.\n */\n slugify: (input: string) => string;\n\n /**\n * Declare the type of the wrapper to be used when there are multiple children.\n */\n wrapper: any | null;\n\n /**\n * Whether to preserve frontmatter in the markdown content.\n */\n preserveFrontmatter: boolean;\n\n /**\n * Whether to use the GitHub Tag Filter.\n */\n tagfilter: boolean;\n}>;\n\n/**\n * Default React runtime for markdown rendering.\n */\nconst DEFAULT_RUNTIME: MarkdownRuntime = {\n createElement: createElement as any,\n cloneElement,\n Fragment,\n normalizeProps: (_tag, props) => props,\n};\n\n/**\n * Compile markdown to React elements.\n * This is the primary export - use this for new code.\n */\nexport const compileMarkdown = (\n markdown: string = '',\n options: MarkdownRendererOptions = {}\n): JSX.Element => {\n const {\n createElement: customCreateElement,\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n namedCodesToUnicode,\n components,\n renderRule,\n sanitizer,\n slugify,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n } = options;\n\n const runtime = customCreateElement\n ? { ...DEFAULT_RUNTIME, createElement: customCreateElement as any }\n : DEFAULT_RUNTIME;\n\n const ctx: MarkdownContext = {\n runtime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n const compilerOptions: MarkdownOptions = {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n renderRule,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return coreCompile(markdown, ctx, compilerOptions) as JSX.Element;\n};\n\n// Backward compatibility aliases\nexport const compiler = compileMarkdown;\nexport const compile = compileMarkdown;\n\n/**\n * React component that renders markdown to JSX (legacy).\n */\nexport const LegacyMarkdownRenderer: FC<\n Omit<HTMLAttributes<Element>, 'children'> & {\n children: string;\n options?: MarkdownRendererOptions;\n }\n> = ({ children = '', options, ...props }) => {\n if (process.env.NODE_ENV !== 'production' && typeof children !== 'string') {\n console.error(\n 'intlayer: <Markdown> component only accepts a single string as a child, received:',\n children\n );\n }\n\n return cloneElement(\n compiler(children, options),\n props as JSX.IntrinsicAttributes\n );\n};\n\nexport type {\n State,\n ParseState,\n ParserResult,\n RuleOutput,\n CoreOverrides as Overrides,\n};\n"],"mappings":";;;;;;;AA6HA,MAAM,kBAAmC;CACxB;CACf;CACA;CACA,iBAAiB,MAAM,UAAU;CAClC;;;;;AAMD,MAAa,mBACX,WAAmB,IACnB,UAAmC,EAAE,KACrB;CAChB,MAAM,EACJ,eAAe,qBACf,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,YACA,WACA,SACA,SACA,qBACA,cACE;AA2BJ,QAAOA,UAAY,UArBU;EAC3B,SALc,sBACZ;GAAE,GAAG;GAAiB,eAAe;GAA4B,GACjE;EAIF;EACA;EACW;EACX;EACD,EAEwC;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAEiD;;AAIpD,MAAa,WAAW;AACxB,MAAa,UAAU;;;;AAKvB,MAAa,0BAKR,EAAE,WAAW,IAAI,SAAS,GAAG,YAAY;AAC5C,KAAI,QAAQ,IAAI,aAAa,gBAAgB,OAAO,aAAa,SAC/D,SAAQ,MACN,qFACA,SACD;AAGH,QAAO,aACL,SAAS,UAAU,QAAQ,EAC3B,MACD"}
@@ -0,0 +1,41 @@
1
+ import { Fragment, cloneElement, createElement } from "react";
2
+
3
+ //#region src/markdown/runtime.ts
4
+ /**
5
+ * React-specific runtime for the markdown processor.
6
+ * Implements the MarkdownRuntime interface using React's primitives.
7
+ */
8
+ const reactRuntime = {
9
+ createElement: (type, props, ...children) => {
10
+ if (children.length === 0) return createElement(type, props);
11
+ if (children.length === 1) return createElement(type, props, children[0]);
12
+ return createElement(type, props, ...children);
13
+ },
14
+ cloneElement: (element, props, ...children) => {
15
+ if (children.length === 0) return cloneElement(element, props);
16
+ return cloneElement(element, props, ...children);
17
+ },
18
+ Fragment,
19
+ normalizeProps: (_tag, props) => {
20
+ return props;
21
+ }
22
+ };
23
+ /**
24
+ * Creates a React runtime with custom createElement for advanced use cases.
25
+ * Useful for wrapping elements or adding middleware.
26
+ */
27
+ const createReactRuntime = (options = {}) => {
28
+ const { onCreateElement } = options;
29
+ if (onCreateElement) return {
30
+ ...reactRuntime,
31
+ createElement: (type, props, ...children) => {
32
+ return onCreateElement(type, props, children);
33
+ }
34
+ };
35
+ return reactRuntime;
36
+ };
37
+ var runtime_default = reactRuntime;
38
+
39
+ //#endregion
40
+ export { createReactRuntime, runtime_default as default, reactRuntime };
41
+ //# sourceMappingURL=runtime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.mjs","names":[],"sources":["../../../src/markdown/runtime.ts"],"sourcesContent":["/**\n * React-specific MarkdownRuntime implementation.\n *\n * This provides the React-specific createElement, cloneElement, and Fragment\n * implementations for the framework-agnostic markdown processor.\n *\n * This is part of the Solution F (Hybrid AST + Callback Pattern) implementation\n * for GitHub Issue #289: Adapt markdown parser in custom packages\n */\n\nimport type { HTMLTag, MarkdownRuntime } from '@intlayer/core';\nimport {\n cloneElement,\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\n/**\n * React-specific runtime for the markdown processor.\n * Implements the MarkdownRuntime interface using React's primitives.\n */\nexport const reactRuntime: MarkdownRuntime = {\n /**\n * Creates a React element.\n * Handles the conversion of props and children to React format.\n */\n createElement: (\n type: string | any,\n props: Record<string, any> | null,\n ...children: any[]\n ): ReactNode => {\n // React accepts children as rest args or as a single array\n // If there's only one child, pass it directly to avoid unnecessary array\n if (children.length === 0) {\n return createElement(type, props);\n }\n if (children.length === 1) {\n return createElement(type, props, children[0]);\n }\n return createElement(type, props, ...children);\n },\n\n /**\n * Clones a React element with new props.\n */\n cloneElement: (\n element: unknown,\n props: Record<string, any>,\n ...children: any[]\n ): ReactNode => {\n if (children.length === 0) {\n return cloneElement(element as ReactElement, props);\n }\n return cloneElement(element as ReactElement, props, ...children);\n },\n\n /**\n * React Fragment component.\n */\n Fragment,\n\n /**\n * React-specific prop normalization.\n * React uses className instead of class, htmlFor instead of for, etc.\n * The core processor already handles ATTRIBUTE_TO_NODE_PROP_MAP,\n * so this is mostly a no-op but can be used for additional React-specific transforms.\n */\n normalizeProps: (\n _tag: HTMLTag,\n props: Record<string, any>\n ): Record<string, any> => {\n // The core already handles class -> className and for -> htmlFor\n // via ATTRIBUTE_TO_NODE_PROP_MAP in the attrStringToMap function.\n // This hook is available for any additional React-specific transforms.\n return props;\n },\n};\n\n/**\n * Creates a React runtime with custom createElement for advanced use cases.\n * Useful for wrapping elements or adding middleware.\n */\nexport const createReactRuntime = (\n options: {\n onCreateElement?: (\n type: string | any,\n props: Record<string, any> | null,\n children: any[]\n ) => ReactNode;\n } = {}\n): MarkdownRuntime => {\n const { onCreateElement } = options;\n\n if (onCreateElement) {\n return {\n ...reactRuntime,\n createElement: (\n type: string | any,\n props: Record<string, any> | null,\n ...children: any[]\n ): ReactNode => {\n return onCreateElement(type, props, children);\n },\n };\n }\n\n return reactRuntime;\n};\n\nexport default reactRuntime;\n"],"mappings":";;;;;;;AAuBA,MAAa,eAAgC;CAK3C,gBACE,MACA,OACA,GAAG,aACW;AAGd,MAAI,SAAS,WAAW,EACtB,QAAO,cAAc,MAAM,MAAM;AAEnC,MAAI,SAAS,WAAW,EACtB,QAAO,cAAc,MAAM,OAAO,SAAS,GAAG;AAEhD,SAAO,cAAc,MAAM,OAAO,GAAG,SAAS;;CAMhD,eACE,SACA,OACA,GAAG,aACW;AACd,MAAI,SAAS,WAAW,EACtB,QAAO,aAAa,SAAyB,MAAM;AAErD,SAAO,aAAa,SAAyB,OAAO,GAAG,SAAS;;CAMlE;CAQA,iBACE,MACA,UACwB;AAIxB,SAAO;;CAEV;;;;;AAMD,MAAa,sBACX,UAMI,EAAE,KACc;CACpB,MAAM,EAAE,oBAAoB;AAE5B,KAAI,gBACF,QAAO;EACL,GAAG;EACH,gBACE,MACA,OACA,GAAG,aACW;AACd,UAAO,gBAAgB,MAAM,OAAO,SAAS;;EAEhD;AAGH,QAAO;;AAGT,sBAAe"}
@@ -1,10 +1,12 @@
1
1
  import { renderIntlayerNode } from "./IntlayerNode.mjs";
2
2
  import { ContentSelectorRenderer } from "./editor/ContentSelectorWrapper.mjs";
3
3
  import { EditedContentRenderer } from "./editor/useEditedContentRenderer.mjs";
4
- import { MarkdownMetadataRenderer, MarkdownRenderer } from "./markdown/MarkdownRenderer.mjs";
4
+ import { HTMLRendererPlugin } from "./html/HTMLRendererPlugin.mjs";
5
+ import { MarkdownMetadataRenderer, MarkdownRendererPlugin } from "./markdown/MarkdownRendererPlugin.mjs";
5
6
  import { renderReactElement } from "./reactElement/renderReactElement.mjs";
7
+ import { Fragment, createElement } from "react";
6
8
  import { jsx } from "react/jsx-runtime";
7
- import { getMarkdownMetadata } from "@intlayer/core";
9
+ import { getMarkdownMetadata, splitInsertionTemplate } from "@intlayer/core";
8
10
  import { NodeType } from "@intlayer/types";
9
11
 
10
12
  //#region src/plugins.tsx
@@ -34,6 +36,49 @@ const reactNodePlugins = {
34
36
  })
35
37
  })
36
38
  };
39
+ /**
40
+ * Split insertion string and join with React nodes using shared core logic
41
+ */
42
+ const splitAndJoinInsertion = (template, values) => {
43
+ const result = splitInsertionTemplate(template, values);
44
+ if (result.isSimple) return result.parts;
45
+ return createElement(Fragment, null, ...result.parts.map((part, index) => createElement(Fragment, { key: index }, part)));
46
+ };
47
+ /** Insertion plugin for React. Handles component/node insertion. */
48
+ const insertionPlugin = {
49
+ id: "insertion-plugin",
50
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Insertion,
51
+ transform: (node, props, deepTransformNode) => {
52
+ const newKeyPath = [...props.keyPath, { type: NodeType.Insertion }];
53
+ const children = node[NodeType.Insertion];
54
+ /** Insertion string plugin. Replaces string node with a component that render the insertion. */
55
+ const insertionStringPlugin = {
56
+ id: "insertion-string-plugin",
57
+ canHandle: (node) => typeof node === "string",
58
+ transform: (node, subProps, deepTransformNode) => {
59
+ const transformedResult = deepTransformNode(node, {
60
+ ...subProps,
61
+ children: node,
62
+ plugins: [...(props.plugins ?? []).filter((plugin) => plugin.id !== "intlayer-node-plugin")]
63
+ });
64
+ return (values) => {
65
+ const result = splitAndJoinInsertion(transformedResult, values);
66
+ return deepTransformNode(result, {
67
+ ...subProps,
68
+ plugins: props.plugins,
69
+ children: result
70
+ });
71
+ };
72
+ }
73
+ };
74
+ return deepTransformNode(children, {
75
+ ...props,
76
+ children,
77
+ keyPath: newKeyPath,
78
+ plugins: [insertionStringPlugin, ...props.plugins ?? []]
79
+ });
80
+ }
81
+ };
37
82
  /** Markdown string plugin. Replaces string node with a component that render the markdown. */
38
83
  const markdownStringPlugin = {
39
84
  id: "markdown-string-plugin",
@@ -44,14 +89,14 @@ const markdownStringPlugin = {
44
89
  plugins: [{
45
90
  id: "markdown-metadata-plugin",
46
91
  canHandle: (metadataNode) => typeof metadataNode === "string" || typeof metadataNode === "number" || typeof metadataNode === "boolean" || !metadataNode,
47
- transform: (metadataNode, props$1) => renderIntlayerNode({
48
- ...props$1,
92
+ transform: (metadataNode, props) => renderIntlayerNode({
93
+ ...props,
49
94
  value: metadataNode,
50
95
  children: /* @__PURE__ */ jsx(ContentSelectorRenderer, {
51
96
  ...rest,
52
97
  children: /* @__PURE__ */ jsx(MarkdownMetadataRenderer, {
53
98
  ...rest,
54
- metadataKeyPath: props$1.keyPath,
99
+ metadataKeyPath: props.keyPath,
55
100
  children: node
56
101
  })
57
102
  })
@@ -60,18 +105,26 @@ const markdownStringPlugin = {
60
105
  dictionaryKey: rest.dictionaryKey,
61
106
  keyPath: []
62
107
  });
63
- return renderIntlayerNode({
108
+ const render = (components) => renderIntlayerNode({
64
109
  ...props,
65
110
  value: node,
66
111
  children: /* @__PURE__ */ jsx(ContentSelectorRenderer, {
67
112
  ...rest,
68
- children: /* @__PURE__ */ jsx(MarkdownRenderer, {
113
+ children: /* @__PURE__ */ jsx(MarkdownRendererPlugin, {
69
114
  ...rest,
115
+ ...components,
70
116
  children: node
71
117
  })
72
118
  }),
73
119
  additionalProps: { metadata: metadataNodes }
74
120
  });
121
+ const element = render();
122
+ return new Proxy(element, { get(target, prop, receiver) {
123
+ if (prop === "value") return node;
124
+ if (prop === "metadata") return metadataNodes;
125
+ if (prop === "use") return (components) => render(components);
126
+ return Reflect.get(target, prop, receiver);
127
+ } });
75
128
  }
76
129
  };
77
130
  const markdownPlugin = {
@@ -88,7 +141,28 @@ const markdownPlugin = {
88
141
  });
89
142
  }
90
143
  };
144
+ /** HTML plugin. Replaces node with a function that takes components => ReactNode. */
145
+ const htmlPlugin = {
146
+ id: "html-plugin",
147
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.HTML,
148
+ transform: (node, props) => {
149
+ const html = node[NodeType.HTML];
150
+ node.tags;
151
+ const { plugins, ...rest } = props;
152
+ const render = (userComponents) => createElement(HTMLRendererPlugin, {
153
+ ...rest,
154
+ html,
155
+ userComponents
156
+ });
157
+ const element = render();
158
+ return new Proxy(element, { get(target, prop, receiver) {
159
+ if (prop === "value") return html;
160
+ if (prop === "use") return (userComponents) => render(userComponents);
161
+ return Reflect.get(target, prop, receiver);
162
+ } });
163
+ }
164
+ };
91
165
 
92
166
  //#endregion
93
- export { intlayerNodePlugins, markdownPlugin, markdownStringPlugin, reactNodePlugins };
167
+ export { htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin, reactNodePlugins };
94
168
  //# sourceMappingURL=plugins.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.mjs","names":["props"],"sources":["../../src/plugins.tsx"],"sourcesContent":["import {\n type DeepTransformContent as DeepTransformContentCore,\n getMarkdownMetadata,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n type MarkdownContent,\n type Plugins,\n} from '@intlayer/core';\nimport type { DeclaredLocales, KeyPath, LocalesValues } from '@intlayer/types';\nimport { NodeType } from '@intlayer/types';\nimport type { ReactNode } from 'react';\nimport { ContentSelectorRenderer } from './editor';\nimport { EditedContentRenderer } from './editor/useEditedContentRenderer';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { MarkdownMetadataRenderer, MarkdownRenderer } from './markdown';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (\n _node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: rest.children,\n children: (\n <EditedContentRenderer {...rest}>{rest.children}</EditedContentRenderer>\n ),\n }),\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins = {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children: (\n <ContentSelectorRenderer {...rest}>\n {renderReactElement(node)}\n </ContentSelectorRenderer>\n ),\n }),\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<string, { metadata: DeepTransformContent<string> }>\n : never;\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins = {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node);\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children: (\n <ContentSelectorRenderer {...rest}>\n <MarkdownMetadataRenderer\n {...rest}\n metadataKeyPath={props.keyPath}\n >\n {node}\n </MarkdownMetadataRenderer>\n </ContentSelectorRenderer>\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n return renderIntlayerNode({\n ...props,\n value: node,\n children: (\n <ContentSelectorRenderer {...rest}>\n <MarkdownRenderer {...rest}>{node}</MarkdownRenderer>\n </ContentSelectorRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n },\n};\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.Markdown]: infer M;\n metadata?: infer U;\n}\n ? IntlayerNode<DeepTransformContent<M>, { metadata: DeepTransformContent<U> }>\n : never;\n\nexport const markdownPlugin: Plugins = {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Markdown,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Markdown,\n },\n ];\n\n const children = node[NodeType.Markdown];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport interface IInterpreterPluginReact<T> {\n reactNode: ReactNodeCond<T>;\n intlayerNode: IntlayerNodeCond<T>;\n markdown: MarkdownCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = IInterpreterPluginStateCore & {\n reactNode: true;\n intlayerNode: true;\n markdown: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n"],"mappings":";;;;;;;;;;;AAyBA,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YACE,OACA,EACE,SACA,GAAG,WAGL,mBAAmB;EACjB,GAAG;EACH,OAAO,KAAK;EACZ,UACE,oBAAC;GAAsB,GAAI;aAAO,KAAK;IAAiC;EAE3E,CAAC;CACL;;AAcD,MAAa,mBAA4B;CACvC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,MAAM,UAAU,eACvB,OAAO,KAAK,QAAQ;CAEtB,YACE,MACA,EACE,SACA,GAAG,WAGL,mBAAmB;EACjB,GAAG;EACH,OAAO;EACP,UACE,oBAAC;GAAwB,GAAI;aAC1B,mBAAmB,KAAK;IACD;EAE7B,CAAC;CACL;;AAWD,MAAa,uBAAgC;CAC3C,IAAI;CACJ,YAAY,SAAS,OAAO,SAAS;CACrC,YAAY,MAAc,OAAO,sBAAsB;EACrD,MAAM,EACJ,SACA,GAAG,SACD;EA6BJ,MAAM,gBAAgB,kBA3BL,oBAAoB,KAAK,EA2BQ;GAChD,SAAS,CA1BsB;IAC/B,IAAI;IACJ,YAAY,iBACV,OAAO,iBAAiB,YACxB,OAAO,iBAAiB,YACxB,OAAO,iBAAiB,aACxB,CAAC;IACH,YAAY,cAAc,YACxB,mBAAmB;KACjB,GAAGA;KACH,OAAO;KACP,UACE,oBAAC;MAAwB,GAAI;gBAC3B,oBAAC;OACC,GAAI;OACJ,iBAAiBA,QAAM;iBAEtB;QACwB;OACH;KAE7B,CAAC;IACL,CAI2B;GAC1B,eAAe,KAAK;GACpB,SAAS,EAAE;GACZ,CAAC;AAEF,SAAO,mBAAmB;GACxB,GAAG;GACH,OAAO;GACP,UACE,oBAAC;IAAwB,GAAI;cAC3B,oBAAC;KAAiB,GAAI;eAAO;MAAwB;KAC7B;GAE5B,iBAAiB,EACf,UAAU,eACX;GACF,CAAC;;CAEL;AAUD,MAAa,iBAA0B;CACrC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;CAC1D,YAAY,MAAuB,OAAO,sBAAsB;EAC9D,MAAM,aAAwB,CAC5B,GAAG,MAAM,SACT,EACE,MAAM,SAAS,UAChB,CACF;EAED,MAAM,WAAW,KAAK,SAAS;AAE/B,SAAO,kBAAkB,UAAU;GACjC,GAAG;GACH;GACA,SAAS;GACT,SAAS,CAAC,sBAAsB,GAAI,MAAM,WAAW,EAAE,CAAE;GAC1D,CAAC;;CAEL"}
1
+ {"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.tsx"],"sourcesContent":["import {\n type DeepTransformContent as DeepTransformContentCore,\n getMarkdownMetadata,\n type HTMLCond,\n type HTMLContent,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n type InsertionContent,\n type MarkdownContent,\n type Plugins,\n splitInsertionTemplate,\n} from '@intlayer/core';\nimport {\n type DeclaredLocales,\n type KeyPath,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport {\n type ComponentType,\n createElement,\n type ElementType,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { ContentSelectorRenderer } from './editor';\nimport { EditedContentRenderer } from './editor/useEditedContentRenderer';\nimport { HTMLRendererPlugin } from './html';\nimport type { ReactHTMLComponentMap } from './html/types';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { MarkdownMetadataRenderer, MarkdownRendererPlugin } from './markdown';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (\n _node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: rest.children,\n children: (\n <EditedContentRenderer {...rest}>{rest.children}</EditedContentRenderer>\n ),\n }),\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins = {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children: (\n <ContentSelectorRenderer {...rest}>\n {renderReactElement(node)}\n </ContentSelectorRenderer>\n ),\n }),\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: string;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: ReactNode;\n }\n ) => ReactNode\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.Insertion];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n { metadata: DeepTransformContent<string>; use: (components: any) => any }\n >\n : never;\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins = {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node);\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children: (\n <ContentSelectorRenderer {...rest}>\n <MarkdownMetadataRenderer\n {...rest}\n metadataKeyPath={props.keyPath}\n >\n {node}\n </MarkdownMetadataRenderer>\n </ContentSelectorRenderer>\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: any) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children: (\n <ContentSelectorRenderer {...rest}>\n <MarkdownRendererPlugin {...rest} {...components}>\n {node}\n </MarkdownRendererPlugin>\n </ContentSelectorRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const element = render() as ReactElement;\n\n return new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return node;\n }\n if (prop === 'metadata') {\n return metadataNodes;\n }\n\n if (prop === 'use') {\n return (components?: any) => render(components);\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n};\n\ntype MarkdownComponentMap = Record<string, ComponentType<any> | ElementType>;\n\nexport type MarkdownCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeType.Markdown]: infer M;\n metadata?: infer U;\n}\n ? {\n use: (components?: MarkdownComponentMap) => ReactNode;\n metadata: DeepTransformContent<U, L>;\n } & any\n : never;\n\nexport const markdownPlugin: Plugins = {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Markdown,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Markdown,\n },\n ];\n\n const children = node[NodeType.Markdown];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\nexport type HTMLPluginCond<T, S, L> = HTMLCond<T, S, L>;\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins = {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeType.HTML];\n const tags = node.tags ?? [];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = <\n T = typeof tags extends readonly (infer U extends string)[]\n ? U\n : typeof tags,\n >(\n userComponents?: ReactHTMLComponentMap<T>\n ): ReactNode =>\n createElement(HTMLRendererPlugin, { ...rest, html, userComponents });\n\n const element = render() as ReactElement;\n\n return new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return html;\n }\n\n if (prop === 'use') {\n // Return a properly typed function based on custom components\n return <\n T = typeof tags extends readonly (infer U extends string)[]\n ? U\n : typeof tags,\n >(\n userComponents?: ReactHTMLComponentMap<T>\n ) => render(userComponents);\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n};\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport interface IInterpreterPluginReact<T, S, L extends LocalesValues> {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T, S, L>;\n reactMarkdown: MarkdownCond<T, S, L>;\n reactHtml: HTMLPluginCond<T, S, L>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = IInterpreterPluginStateCore & {\n reactNode: true;\n reactIntlayerNode: true;\n reactInsertion: true;\n reactMarkdown: true;\n reactHtml: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n"],"mappings":";;;;;;;;;;;;;AA0CA,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YACE,OACA,EACE,SACA,GAAG,WAGL,mBAAmB;EACjB,GAAG;EACH,OAAO,KAAK;EACZ,UACE,oBAAC;GAAsB,GAAI;aAAO,KAAK;IAAiC;EAE3E,CAAC;CACL;;AAcD,MAAa,mBAA4B;CACvC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,MAAM,UAAU,eACvB,OAAO,KAAK,QAAQ;CAEtB,YACE,MACA,EACE,SACA,GAAG,WAGL,mBAAmB;EACjB,GAAG;EACH,OAAO;EACP,UACE,oBAAC;GAAwB,GAAI;aAC1B,mBAAmB,KAAK;IACD;EAE7B,CAAC;CACL;;;;AAqBD,MAAM,yBACJ,UACA,WACc;CACd,MAAM,SAAS,uBAAuB,UAAU,OAAO;AAEvD,KAAI,OAAO,SAET,QAAO,OAAO;AAIhB,QAAO,cACL,UACA,MACA,GAAI,OAAO,MAAgB,KAAK,MAAM,UACpC,cAAc,UAAU,EAAE,KAAK,OAAO,EAAE,KAAK,CAC9C,CACF;;;AAIH,MAAa,kBAA2B;CACtC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;CAC1D,YAAY,MAAwB,OAAO,sBAAsB;EAC/D,MAAM,aAAwB,CAC5B,GAAG,MAAM,SACT,EACE,MAAM,SAAS,WAChB,CACF;EAED,MAAM,WAAW,KAAK,SAAS;;EAG/B,MAAM,wBAAiC;GACrC,IAAI;GACJ,YAAY,SAAS,OAAO,SAAS;GACrC,YAAY,MAAc,UAAU,sBAAsB;IACxD,MAAM,oBAAoB,kBAAkB,MAAM;KAChD,GAAG;KACH,UAAU;KACV,SAAS,CACP,IAAI,MAAM,WAAY,EAAE,EAAgB,QACrC,WAAW,OAAO,OAAO,uBAC3B,CACF;KACF,CAAC;AAEF,YACE,WAMG;KACH,MAAM,SAAS,sBAAsB,mBAAmB,OAAO;AAE/D,YAAO,kBAAkB,QAAQ;MAC/B,GAAG;MACH,SAAS,MAAM;MACf,UAAU;MACX,CAAC;;;GAGP;AAED,SAAO,kBAAkB,UAAU;GACjC,GAAG;GACH;GACA,SAAS;GACT,SAAS,CAAC,uBAAuB,GAAI,MAAM,WAAW,EAAE,CAAE;GAC3D,CAAC;;CAEL;;AAcD,MAAa,uBAAgC;CAC3C,IAAI;CACJ,YAAY,SAAS,OAAO,SAAS;CACrC,YAAY,MAAc,OAAO,sBAAsB;EACrD,MAAM,EACJ,SACA,GAAG,SACD;EA6BJ,MAAM,gBAAgB,kBA3BL,oBAAoB,KAAK,EA2BQ;GAChD,SAAS,CA1BsB;IAC/B,IAAI;IACJ,YAAY,iBACV,OAAO,iBAAiB,YACxB,OAAO,iBAAiB,YACxB,OAAO,iBAAiB,aACxB,CAAC;IACH,YAAY,cAAc,UACxB,mBAAmB;KACjB,GAAG;KACH,OAAO;KACP,UACE,oBAAC;MAAwB,GAAI;gBAC3B,oBAAC;OACC,GAAI;OACJ,iBAAiB,MAAM;iBAEtB;QACwB;OACH;KAE7B,CAAC;IACL,CAI2B;GAC1B,eAAe,KAAK;GACpB,SAAS,EAAE;GACZ,CAAC;EAEF,MAAM,UAAU,eACd,mBAAmB;GACjB,GAAG;GACH,OAAO;GACP,UACE,oBAAC;IAAwB,GAAI;cAC3B,oBAAC;KAAuB,GAAI;KAAM,GAAI;eACnC;MACsB;KACD;GAE5B,iBAAiB,EACf,UAAU,eACX;GACF,CAAC;EAEJ,MAAM,UAAU,QAAQ;AAExB,SAAO,IAAI,MAAM,SAAS,EACxB,IAAI,QAAQ,MAAM,UAAU;AAC1B,OAAI,SAAS,QACX,QAAO;AAET,OAAI,SAAS,WACX,QAAO;AAGT,OAAI,SAAS,MACX,SAAQ,eAAqB,OAAO,WAAW;AAGjD,UAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;KAE7C,CAAC;;CAEL;AAeD,MAAa,iBAA0B;CACrC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;CAC1D,YAAY,MAAuB,OAAO,sBAAsB;EAC9D,MAAM,aAAwB,CAC5B,GAAG,MAAM,SACT,EACE,MAAM,SAAS,UAChB,CACF;EAED,MAAM,WAAW,KAAK,SAAS;AAE/B,SAAO,kBAAkB,UAAU;GACjC,GAAG;GACH;GACA,SAAS;GACT,SAAS,CAAC,sBAAsB,GAAI,MAAM,WAAW,EAAE,CAAE;GAC1D,CAAC;;CAEL;;AASD,MAAa,aAAsB;CACjC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;CAE1D,YAAY,MAA2B,UAAU;EAC/C,MAAM,OAAO,KAAK,SAAS;AACd,OAAK;EAClB,MAAM,EAAE,SAAS,GAAG,SAAS;EAG7B,MAAM,UAKJ,mBAEA,cAAc,oBAAoB;GAAE,GAAG;GAAM;GAAM;GAAgB,CAAC;EAEtE,MAAM,UAAU,QAAQ;AAExB,SAAO,IAAI,MAAM,SAAS,EACxB,IAAI,QAAQ,MAAM,UAAU;AAC1B,OAAI,SAAS,QACX,QAAO;AAGT,OAAI,SAAS,MAEX,SAKE,mBACG,OAAO,eAAe;AAG7B,UAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;KAE7C,CAAC;;CAEL"}
@@ -3,10 +3,10 @@ import { createElement } from "react";
3
3
  //#region src/reactElement/renderReactElement.ts
4
4
  const renderReactElement = (element) => {
5
5
  if (typeof element === "string") return element;
6
- const convertChildrenAsArray = (element$1) => {
7
- if (element$1?.props && typeof element$1.props.children === "object") {
6
+ const convertChildrenAsArray = (element) => {
7
+ if (element?.props && typeof element.props.children === "object") {
8
8
  const childrenResult = [];
9
- const { children } = element$1.props;
9
+ const { children } = element.props;
10
10
  Object.keys(children ?? {}).forEach((key) => {
11
11
  const childElement = renderReactElement(children?.[key]);
12
12
  if (typeof childElement === "object" && childElement !== null && "type" in childElement) childrenResult.push(createElement(childElement.type, {
@@ -16,18 +16,18 @@ const renderReactElement = (element) => {
16
16
  else childrenResult.push(childElement);
17
17
  });
18
18
  return {
19
- ...element$1,
19
+ ...element,
20
20
  props: {
21
- ...element$1.props,
21
+ ...element.props,
22
22
  children: childrenResult
23
23
  }
24
24
  };
25
25
  }
26
26
  return {
27
- ...element$1,
27
+ ...element,
28
28
  props: {
29
- ...element$1.props,
30
- children: element$1.props?.children ?? []
29
+ ...element.props,
30
+ children: element.props?.children ?? []
31
31
  }
32
32
  };
33
33
  };
@@ -1 +1 @@
1
- {"version":3,"file":"renderReactElement.mjs","names":["element"],"sources":["../../../src/reactElement/renderReactElement.ts"],"sourcesContent":["import { createElement, type ReactElement, type ReactNode } from 'react';\n\n// This function recursively creates React elements from a given JSON-like structure\nexport const renderReactElement = (element: ReactElement<any>) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n const convertChildrenAsArray = (\n element: ReactElement<{ children?: ReactNode }>\n ): ReactElement<{ children?: ReactNode }> => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children ?? {}).forEach((key) => {\n const childElement = renderReactElement(\n children?.[\n key as keyof typeof children\n ] as unknown as ReactElement<any>\n );\n\n // Add key prop if the child is a React element\n if (\n typeof childElement === 'object' &&\n childElement !== null &&\n 'type' in childElement\n ) {\n childrenResult.push(\n createElement(\n childElement.type,\n { ...childElement.props, key },\n ...(Array.isArray(childElement.props?.children)\n ? childElement.props.children\n : [childElement.props?.children])\n )\n );\n } else {\n childrenResult.push(childElement);\n }\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props?.children ?? [] },\n };\n };\n\n const fixedElement = convertChildrenAsArray(\n element as ReactElement<{ children?: ReactNode }>\n );\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(\n type ?? 'span',\n props,\n ...(props.children as ReactNode[])\n );\n};\n"],"mappings":";;;AAGA,MAAa,sBAAsB,YAA+B;AAChE,KAAI,OAAO,YAAY,SAErB,QAAO;CAGT,MAAM,0BACJ,cAC2C;AAC3C,MAAIA,WAAS,SAAS,OAAOA,UAAQ,MAAM,aAAa,UAAU;GAChE,MAAM,iBAA8B,EAAE;GACtC,MAAM,EAAE,aAAaA,UAAQ;AAG7B,UAAO,KAAK,YAAY,EAAE,CAAC,CAAC,SAAS,QAAQ;IAC3C,MAAM,eAAe,mBACnB,WACE,KAEH;AAGD,QACE,OAAO,iBAAiB,YACxB,iBAAiB,QACjB,UAAU,aAEV,gBAAe,KACb,cACE,aAAa,MACb;KAAE,GAAG,aAAa;KAAO;KAAK,EAC9B,GAAI,MAAM,QAAQ,aAAa,OAAO,SAAS,GAC3C,aAAa,MAAM,WACnB,CAAC,aAAa,OAAO,SAAS,CACnC,CACF;QAED,gBAAe,KAAK,aAAa;KAEnC;AAEF,UAAO;IACL,GAAGA;IACH,OAAO;KAAE,GAAGA,UAAQ;KAAO,UAAU;KAAgB;IACtD;;AAGH,SAAO;GACL,GAAGA;GACH,OAAO;IAAE,GAAGA,UAAQ;IAAO,UAAUA,UAAQ,OAAO,YAAY,EAAE;IAAE;GACrE;;CAOH,MAAM,EAAE,MAAM,UAJO,uBACnB,QACD;AAKD,QAAO,cACL,QAAQ,QACR,OACA,GAAI,MAAM,SACX"}
1
+ {"version":3,"file":"renderReactElement.mjs","names":[],"sources":["../../../src/reactElement/renderReactElement.ts"],"sourcesContent":["import { createElement, type ReactElement, type ReactNode } from 'react';\n\n// This function recursively creates React elements from a given JSON-like structure\nexport const renderReactElement = (element: ReactElement<any>) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n const convertChildrenAsArray = (\n element: ReactElement<{ children?: ReactNode }>\n ): ReactElement<{ children?: ReactNode }> => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children ?? {}).forEach((key) => {\n const childElement = renderReactElement(\n children?.[\n key as keyof typeof children\n ] as unknown as ReactElement<any>\n );\n\n // Add key prop if the child is a React element\n if (\n typeof childElement === 'object' &&\n childElement !== null &&\n 'type' in childElement\n ) {\n childrenResult.push(\n createElement(\n childElement.type,\n { ...childElement.props, key },\n ...(Array.isArray(childElement.props?.children)\n ? childElement.props.children\n : [childElement.props?.children])\n )\n );\n } else {\n childrenResult.push(childElement);\n }\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props?.children ?? [] },\n };\n };\n\n const fixedElement = convertChildrenAsArray(\n element as ReactElement<{ children?: ReactNode }>\n );\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(\n type ?? 'span',\n props,\n ...(props.children as ReactNode[])\n );\n};\n"],"mappings":";;;AAGA,MAAa,sBAAsB,YAA+B;AAChE,KAAI,OAAO,YAAY,SAErB,QAAO;CAGT,MAAM,0BACJ,YAC2C;AAC3C,MAAI,SAAS,SAAS,OAAO,QAAQ,MAAM,aAAa,UAAU;GAChE,MAAM,iBAA8B,EAAE;GACtC,MAAM,EAAE,aAAa,QAAQ;AAG7B,UAAO,KAAK,YAAY,EAAE,CAAC,CAAC,SAAS,QAAQ;IAC3C,MAAM,eAAe,mBACnB,WACE,KAEH;AAGD,QACE,OAAO,iBAAiB,YACxB,iBAAiB,QACjB,UAAU,aAEV,gBAAe,KACb,cACE,aAAa,MACb;KAAE,GAAG,aAAa;KAAO;KAAK,EAC9B,GAAI,MAAM,QAAQ,aAAa,OAAO,SAAS,GAC3C,aAAa,MAAM,WACnB,CAAC,aAAa,OAAO,SAAS,CACnC,CACF;QAED,gBAAe,KAAK,aAAa;KAEnC;AAEF,UAAO;IACL,GAAG;IACH,OAAO;KAAE,GAAG,QAAQ;KAAO,UAAU;KAAgB;IACtD;;AAGH,SAAO;GACL,GAAG;GACH,OAAO;IAAE,GAAG,QAAQ;IAAO,UAAU,QAAQ,OAAO,YAAY,EAAE;IAAE;GACrE;;CAOH,MAAM,EAAE,MAAM,UAJO,uBACnB,QACD;AAKD,QAAO,cACL,QAAQ,QACR,OACA,GAAI,MAAM,SACX"}
@@ -19,8 +19,8 @@ const locale = getServerContext(IntlayerServerContext);
19
19
  /**
20
20
  * Provider that store the current locale on the server side
21
21
  */
22
- const IntlayerServerProvider = ({ children, locale: locale$1 = defaultLocale }) => /* @__PURE__ */ jsx(IntlayerServerContext.Provider, {
23
- value: locale$1,
22
+ const IntlayerServerProvider = ({ children, locale = defaultLocale }) => /* @__PURE__ */ jsx(IntlayerServerContext.Provider, {
23
+ value: locale,
24
24
  children
25
25
  });
26
26
 
@@ -1 +1 @@
1
- {"version":3,"file":"IntlayerServerProvider.mjs","names":["locale"],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\n\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = configuration?.internationalization ?? {};\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<LocalesValues>(defaultLocale);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: LocalesValues;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n {children}\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;AAMA,MAAM,EAAE,kBAAkB,eAAe,wBAAwB,EAAE;;;;AAKnE,MAAa,wBACX,oBAAmC,cAAc;;;;AAKnD,MAAa,oBAAoB,iBAAiB,sBAAsB;;;;AAKxE,MAAa,SAAS,iBAAiB,sBAAsB;;;;AAS7D,MAAa,0BAA2D,EACtE,UACA,mBAAS,oBAET,oBAAC,sBAAsB;CAAS,OAAOA;CACpC;EAC8B"}
1
+ {"version":3,"file":"IntlayerServerProvider.mjs","names":[],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\n\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = configuration?.internationalization ?? {};\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<LocalesValues>(defaultLocale);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: LocalesValues;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n {children}\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;AAMA,MAAM,EAAE,kBAAkB,eAAe,wBAAwB,EAAE;;;;AAKnE,MAAa,wBACX,oBAAmC,cAAc;;;;AAKnD,MAAa,oBAAoB,iBAAiB,sBAAsB;;;;AAKxE,MAAa,SAAS,iBAAiB,sBAAsB;;;;AAS7D,MAAa,0BAA2D,EACtE,UACA,SAAS,oBAET,oBAAC,sBAAsB;CAAS,OAAO;CACpC;EAC8B"}
@@ -0,0 +1,42 @@
1
+ import { getServerContext } from "../serverContext.mjs";
2
+ import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
3
+ import { bindIntl } from "@intlayer/core";
4
+ import configuration from "@intlayer/config/built";
5
+
6
+ //#region src/server/format/useIntl.ts
7
+ /**
8
+ * React client hook that provides a locale-bound `Intl` object.
9
+ *
10
+ * It acts exactly like the native `Intl` object, but acts as a proxy to:
11
+ * 1. Inject the current locale automatically if none is provided.
12
+ * 2. Use the performance-optimized `CachedIntl` under the hood.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * const intl = useIntl(); // uses context locale
17
+ *
18
+ * // Standard API, but no need to pass 'en-US' as the first argument
19
+ * const formatted = new intl.NumberFormat({
20
+ * style: 'currency',
21
+ * currency: 'USD'
22
+ * }).format(123.45);
23
+ * ```
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * const intl = useIntl();
28
+ *
29
+ * // You can still override the locale if needed
30
+ * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());
31
+ * // or
32
+ * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());
33
+ * ```
34
+ */
35
+ const useIntl = (locale) => {
36
+ const currentLocale = getServerContext(IntlayerServerContext);
37
+ return bindIntl(locale ?? currentLocale ?? configuration?.internationalization?.defaultLocale);
38
+ };
39
+
40
+ //#endregion
41
+ export { useIntl };
42
+ //# sourceMappingURL=useIntl.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/server/format/useIntl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { bindIntl } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\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 currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return bindIntl(\n locale ??\n currentLocale ??\n configuration?.internationalization?.defaultLocale\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,WAAW,WAA2B;CACjD,MAAM,gBAAgB,iBAAgC,sBAAsB;AAE5E,QAAO,SACL,UACE,iBACA,eAAe,sBAAsB,cACxC"}
@@ -1,4 +1,5 @@
1
1
  import { IntlayerServerContext, IntlayerServerProvider, locale } from "./IntlayerServerProvider.mjs";
2
+ import { useIntl } from "./format/useIntl.mjs";
2
3
  import { t } from "./t.mjs";
3
4
  import { useDictionary } from "./useDictionary.mjs";
4
5
  import { useDictionaryAsync } from "./useDictionaryAsync.mjs";
@@ -8,4 +9,4 @@ import { useI18n } from "./useI18n.mjs";
8
9
  import { useIntlayer } from "./useIntlayer.mjs";
9
10
  import { useLocale } from "./useLocale.mjs";
10
11
 
11
- export { IntlayerServerContext as IntlayerServer, IntlayerServerProvider, locale, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntlayer, useLoadDynamic, useLocale };
12
+ export { IntlayerServerContext as IntlayerServer, IntlayerServerProvider, locale, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocale };
@@ -1 +1 @@
1
- {"version":3,"file":"IntlayerNode.d.ts","names":[],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":[],"mappings":";;;;KAQY,iBACN,yCACc,yBAChB;SACK;AAJT,CAAA,GAKI,eALoB;KAOnB,uBANC,CAAA,CAAA,CAAA,GAM4B,iBAN5B,CAAA;EACc,KAAA,EAMX,CANW;EAChB,QAAA,EAMQ,SANR;EACK,eAAA,CAAA,EAAA;IACL,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,GAAA;EAAe,CAAA;AAAC,CAAA,CAAA;AAGX,cAKI,kBALJ,EAAA,CAAA,UAAA,MAAA,GAAA,MAAA,GAAA,OAAA,GAAA,SAAA,GAAA,IAAA,CAAA,CAAA;EAAA,QAAA;EAAA,KAAA;EAAA;AAAA,CAAA,EAWN,uBAXM,CAWkB,CAXlB,CAAA,EAAA,GAWuB,YAXvB,CAWoC,CAXpC,CAAA"}
1
+ {"version":3,"file":"IntlayerNode.d.ts","names":[],"sources":["../../src/IntlayerNode.tsx"],"mappings":";;;;KAQY,YAAA,KACN,SAAA,gCACc,MAAA,mBAChB,SAAA;EACF,KAAA,EAAO,CAAA;AAAA,IACL,eAAA;AAAA,KAEC,uBAAA,MAA6B,iBAAA;EAChC,KAAA,EAAO,CAAA;EACP,QAAA,EAAU,SAAA;EACV,eAAA;IAAA,CAAqB,GAAA;EAAA;AAAA;AAAA,cAGV,kBAAA;EAEX,QAAA;EAAA,KAAA;EAAA;AAAA,GAIC,uBAAA,CAAwB,CAAA,MAAK,YAAA,CAAa,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"ContentSelector.d.ts","names":[],"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":[],"mappings":";;;KAcK,oBAAA;;EAAA,OAAA,CAAA,EAAA,GAAA,GAAA,IAAA;EAOmB,SAAA,CAAA,EAAA,GAAA,GAAA,IAAA;EAAf,cAAA,CAAA,EAAA,GAAA,GAAA,IAAA;EAAL,aAAA,CAAA,EAAA,MAAA;EAAI,WAAA,CAAA,EAAA,OAAA;AAER,CAAA,GAFI,IAES,CAFJ,cAwHR,CAxHuB,cAES,CAAA,EAAA,SAAA,CAAA;cAApB,iBAAiB,GAAG"}
1
+ {"version":3,"file":"ContentSelector.d.ts","names":[],"sources":["../../../src/UI/ContentSelector.tsx"],"mappings":";;;KAcK,oBAAA;EACH,OAAA;EACA,OAAA;EACA,SAAA;EACA,cAAA;EACA,aAAA;EACA,WAAA;AAAA,IACE,IAAA,CAAK,cAAA,CAAe,cAAA;AAAA,cAEX,eAAA,EAAiB,EAAA,CAAG,oBAAA"}
@@ -1,4 +1,4 @@
1
- import * as react1 from "react";
1
+ import * as react0 from "react";
2
2
  import { FC, PropsWithChildren } from "react";
3
3
  import { LocalesValues } from "@intlayer/types";
4
4
 
@@ -10,24 +10,69 @@ type IntlayerValue = {
10
10
  isCookieEnabled?: boolean;
11
11
  };
12
12
  /**
13
- * Context that store the current locale on the client side
13
+ * Context that stores the current locale on the client side.
14
14
  */
15
- declare const IntlayerClientContext: react1.Context<IntlayerValue>;
15
+ declare const IntlayerClientContext: react0.Context<IntlayerValue>;
16
16
  /**
17
- * Hook that provides the current locale
17
+ * Hook that provides the current Intlayer client context.
18
+ *
19
+ * @returns The current Intlayer context values.
18
20
  */
19
21
  declare const useIntlayerContext: () => IntlayerValue;
22
+ /**
23
+ * Props for the IntlayerProvider component.
24
+ */
20
25
  type IntlayerProviderProps = PropsWithChildren<{
26
+ /**
27
+ * The locale to use. If not provided, it will be detected from storage or configuration.
28
+ */
21
29
  locale?: LocalesValues;
30
+ /**
31
+ * The default locale to use as a fallback.
32
+ */
22
33
  defaultLocale?: LocalesValues;
34
+ /**
35
+ * Function to set the locale.
36
+ */
23
37
  setLocale?: (locale: LocalesValues) => void;
38
+ /**
39
+ * Whether to disable the editor.
40
+ */
24
41
  disableEditor?: boolean;
42
+ /**
43
+ * Whether to enable cookies for storing the locale.
44
+ */
25
45
  isCookieEnabled?: boolean;
26
46
  }>;
27
47
  /**
28
- * Provider that store the current locale on the client side
48
+ * Provider that stores the current locale on the client side.
49
+ *
50
+ * This component is focused on content delivery without the editor features.
51
+ *
52
+ * @param props - The provider props.
53
+ * @returns The provider component.
29
54
  */
30
55
  declare const IntlayerProviderContent: FC<IntlayerProviderProps>;
56
+ /**
57
+ * Main provider for Intlayer in React applications.
58
+ *
59
+ * It includes the editor provider by default, allowing for live content editing
60
+ * if configured.
61
+ *
62
+ * @param props - The provider props.
63
+ * @returns The provider component with editor support.
64
+ *
65
+ * @example
66
+ * ```tsx
67
+ * import { IntlayerProvider } from 'react-intlayer';
68
+ *
69
+ * const App = () => (
70
+ * <IntlayerProvider>
71
+ * <MyComponent />
72
+ * </IntlayerProvider>
73
+ * );
74
+ * ```
75
+ */
31
76
  declare const IntlayerProvider: FC<IntlayerProviderProps>;
32
77
  //#endregion
33
78
  export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, IntlayerProviderProps, useIntlayerContext };
@@ -1 +1 @@
1
- {"version":3,"file":"IntlayerProvider.d.ts","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":[],"mappings":";;;;;KAgBK,aAAA;UACK;yBACe;EAFpB,aAAA,CAAA,EAAa,OAAA;EAUL,eAAA,CAAA,EAAA,OAKX;AAKF,CAAA;AAEA;;;AAGuB,cAfV,qBAeU,EAfW,MAAA,CAAA,OAeX,CAfW,aAeX,CAAA;;;AAQvB;AAyDa,cAtEA,kBAsEqB,EAAA,GAAA,GAtEH,aAsEA;KApEnB,qBAAA,GAAwB;WACzB;kBACO;uBACK;;;;;;;cAQV,yBAAyB,GAAG;cAyD5B,kBAAkB,GAAG"}
1
+ {"version":3,"file":"IntlayerProvider.d.ts","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"mappings":";;;;;KAgBK,aAAA;EACH,MAAA,EAAQ,aAAA;EACR,SAAA,GAAY,SAAA,EAAW,aAAA;EACvB,aAAA;EACA,eAAA;AAAA;;;;cAMW,qBAAA,EAAqB,MAAA,CAAA,OAAA,CAAA,aAAA;;;;;;cAYrB,kBAAA,QAAkB,aAAA;AAZ/B;;;AAAA,KAiBY,qBAAA,GAAwB,iBAAA;EAjBF;AAYlC;;EASE,MAAA,GAAS,aAAA;EAToB;;AAK/B;EAQE,aAAA,GAAgB,aAAA;;;;EAIhB,SAAA,IAAa,MAAA,EAAQ,aAAA;EAZa;;;EAgBlC,aAAA;EAZA;;;EAgBA,eAAA;AAAA;;;;;;;AAWF;;cAAa,uBAAA,EAAyB,EAAA,CAAG,qBAAA;;;AA6EzC;;;;;;;;;;;;;;;;;;cAAa,gBAAA,EAAkB,EAAA,CAAG,qBAAA"}
@@ -1,9 +1,10 @@
1
1
  import { useCompact } from "./useCompact.js";
2
2
  import { useCurrency } from "./useCurrency.js";
3
3
  import { useDate } from "./useDate.js";
4
+ import { useIntl } from "./useIntl.js";
4
5
  import { useList } from "./useList.js";
5
6
  import { useNumber } from "./useNumber.js";
6
7
  import { usePercentage } from "./usePercentage.js";
7
8
  import { useRelativeTime } from "./useRelativeTime.js";
8
9
  import { useUnit } from "./useUnit.js";
9
- export { useCompact, useCurrency, useDate, useList, useNumber, usePercentage, useRelativeTime, useUnit };
10
+ export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
@@ -1,7 +1,6 @@
1
- import * as _intlayer_types1 from "@intlayer/types";
1
+ import * as _intlayer_types10 from "@intlayer/types";
2
2
 
3
3
  //#region src/client/format/useCompact.d.ts
4
-
5
4
  /**
6
5
  * React client hook that provides a compact number formatter
7
6
  * bound to the current application locale.
@@ -13,7 +12,7 @@ import * as _intlayer_types1 from "@intlayer/types";
13
12
  * ```
14
13
  */
15
14
  declare const useCompact: () => (value: string | number, options?: Intl.NumberFormatOptions & {
16
- locale?: _intlayer_types1.LocalesValues;
15
+ locale?: _intlayer_types10.LocalesValues;
17
16
  }) => string;
18
17
  //#endregion
19
18
  export { useCompact };
@@ -1 +1 @@
1
- {"version":3,"file":"useCompact.d.ts","names":[],"sources":["../../../../src/client/format/useCompact.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;;;;;;;cAAa,qDAAU,IAAA,CAAA;WAAA,gBAAA,CAAA"}
1
+ {"version":3,"file":"useCompact.d.ts","names":[],"sources":["../../../../src/client/format/useCompact.ts"],"mappings":";;;;;;AAgBA;;;;;;;cAAa,UAAA,SAAU,KAAA,mBAAA,OAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,iBAAA,CAAA,aAAA;AAAA"}
@@ -1,7 +1,6 @@
1
- import * as _intlayer_types6 from "@intlayer/types";
1
+ import * as _intlayer_types12 from "@intlayer/types";
2
2
 
3
3
  //#region src/client/format/useCurrency.d.ts
4
-
5
4
  /**
6
5
  * React client hook that provides a currency formatter
7
6
  * bound to the current application locale.
@@ -27,7 +26,7 @@ import * as _intlayer_types6 from "@intlayer/types";
27
26
  * ```
28
27
  */
29
28
  declare const useCurrency: () => (value: string | number, options?: Intl.NumberFormatOptions & {
30
- locale?: _intlayer_types6.LocalesValues;
29
+ locale?: _intlayer_types12.LocalesValues;
31
30
  }) => string;
32
31
  //#endregion
33
32
  export { useCurrency };
@@ -1 +1 @@
1
- {"version":3,"file":"useCurrency.d.ts","names":[],"sources":["../../../../src/client/format/useCurrency.ts"],"sourcesContent":[],"mappings":";;;;;;;AA8BA;;;;;;;;;;;;;;;;;;;;;cAAa,sDAAW,IAAA,CAAA;WAAA,gBAAA,CAAA"}
1
+ {"version":3,"file":"useCurrency.d.ts","names":[],"sources":["../../../../src/client/format/useCurrency.ts"],"mappings":";;;;;;AA8BA;;;;;;;;;;;;;;;;;;;;;cAAa,WAAA,SAAW,KAAA,mBAAA,OAAA,GAAA,IAAA,CAAA,mBAAA;WAAA,iBAAA,CAAA,aAAA;AAAA"}
@@ -1,7 +1,6 @@
1
1
  import { date } from "@intlayer/core";
2
2
 
3
3
  //#region src/client/format/useDate.d.ts
4
-
5
4
  /**
6
5
  * React client hook that provides a localized date/time formatter
7
6
  * bound to the current application locale.
@@ -1 +1 @@
1
- {"version":3,"file":"useDate.d.ts","names":[],"sources":["../../../../src/client/format/useDate.ts"],"sourcesContent":[],"mappings":";;;;;;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;cAAa,yBAGM,kBAAkB"}
1
+ {"version":3,"file":"useDate.d.ts","names":[],"sources":["../../../../src/client/format/useDate.ts"],"mappings":";;;;;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;cAAa,OAAA,YAGA,IAAA,EAAM,UAAA,QAAkB,IAAA"}