react-intlayer 8.4.4 → 8.4.5

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 (251) hide show
  1. package/dist/cjs/IntlayerNode.cjs +17 -1
  2. package/dist/cjs/IntlayerNode.cjs.map +1 -1
  3. package/dist/cjs/UI/ContentSelector.cjs +96 -1
  4. package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
  5. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -1
  6. package/dist/cjs/client/IntlayerProvider.cjs +92 -1
  7. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
  8. package/dist/cjs/client/format/index.cjs +20 -1
  9. package/dist/cjs/client/format/useCompact.cjs +29 -1
  10. package/dist/cjs/client/format/useCompact.cjs.map +1 -1
  11. package/dist/cjs/client/format/useCurrency.cjs +43 -1
  12. package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
  13. package/dist/cjs/client/format/useDate.cjs +45 -1
  14. package/dist/cjs/client/format/useDate.cjs.map +1 -1
  15. package/dist/cjs/client/format/useIntl.cjs +45 -1
  16. package/dist/cjs/client/format/useIntl.cjs.map +1 -1
  17. package/dist/cjs/client/format/useList.cjs +40 -1
  18. package/dist/cjs/client/format/useList.cjs.map +1 -1
  19. package/dist/cjs/client/format/useNumber.cjs +41 -1
  20. package/dist/cjs/client/format/useNumber.cjs.map +1 -1
  21. package/dist/cjs/client/format/usePercentage.cjs +37 -1
  22. package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
  23. package/dist/cjs/client/format/useRelativeTime.cjs +37 -1
  24. package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
  25. package/dist/cjs/client/format/useUnit.cjs +36 -1
  26. package/dist/cjs/client/format/useUnit.cjs.map +1 -1
  27. package/dist/cjs/client/index.cjs +34 -1
  28. package/dist/cjs/client/t.cjs +40 -1
  29. package/dist/cjs/client/t.cjs.map +1 -1
  30. package/dist/cjs/client/useDictionary.cjs +27 -1
  31. package/dist/cjs/client/useDictionary.cjs.map +1 -1
  32. package/dist/cjs/client/useDictionaryAsync.cjs +24 -1
  33. package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
  34. package/dist/cjs/client/useDictionaryDynamic.cjs +25 -1
  35. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
  36. package/dist/cjs/client/useI18n.cjs +45 -1
  37. package/dist/cjs/client/useI18n.cjs.map +1 -1
  38. package/dist/cjs/client/useIntlayer.cjs +42 -1
  39. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  40. package/dist/cjs/client/useLoadDynamic.cjs +27 -1
  41. package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
  42. package/dist/cjs/client/useLocale.cjs +60 -1
  43. package/dist/cjs/client/useLocale.cjs.map +1 -1
  44. package/dist/cjs/client/useLocaleBase.cjs +26 -1
  45. package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
  46. package/dist/cjs/client/useLocaleStorage.cjs +62 -1
  47. package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
  48. package/dist/cjs/client/useRewriteURL.cjs +42 -1
  49. package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
  50. package/dist/cjs/client/useTraduction.cjs +35 -1
  51. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  52. package/dist/cjs/editor/ContentSelector.cjs +18 -1
  53. package/dist/cjs/editor/ContentSelector.cjs.map +1 -1
  54. package/dist/cjs/editor/EditorProvider.cjs +11 -1
  55. package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
  56. package/dist/cjs/editor/useEditor.cjs +39 -1
  57. package/dist/cjs/editor/useEditor.cjs.map +1 -1
  58. package/dist/cjs/getDictionary.cjs +10 -1
  59. package/dist/cjs/getDictionary.cjs.map +1 -1
  60. package/dist/cjs/getIntlayer.cjs +10 -1
  61. package/dist/cjs/getIntlayer.cjs.map +1 -1
  62. package/dist/cjs/html/HTMLProvider.cjs +18 -1
  63. package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
  64. package/dist/cjs/html/HTMLRenderer.cjs +60 -1
  65. package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
  66. package/dist/cjs/html/HTMLRendererPlugin.cjs +23 -1
  67. package/dist/cjs/html/HTMLRendererPlugin.cjs.map +1 -1
  68. package/dist/cjs/html/index.cjs +12 -1
  69. package/dist/cjs/index.cjs +52 -1
  70. package/dist/cjs/markdown/MarkdownProvider.cjs +80 -1
  71. package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
  72. package/dist/cjs/markdown/MarkdownRenderer.cjs +201 -1
  73. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
  74. package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +17 -1
  75. package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
  76. package/dist/cjs/markdown/index.cjs +24 -1
  77. package/dist/cjs/markdown/processor.cjs +66 -1
  78. package/dist/cjs/markdown/processor.cjs.map +1 -1
  79. package/dist/cjs/markdown/runtime.cjs +43 -1
  80. package/dist/cjs/markdown/runtime.cjs.map +1 -1
  81. package/dist/cjs/plugins.cjs +200 -1
  82. package/dist/cjs/plugins.cjs.map +1 -1
  83. package/dist/cjs/reactElement/renderReactElement.cjs +52 -1
  84. package/dist/cjs/reactElement/renderReactElement.cjs.map +1 -1
  85. package/dist/cjs/server/IntlayerServerProvider.cjs +34 -1
  86. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
  87. package/dist/cjs/server/format/index.cjs +18 -1
  88. package/dist/cjs/server/format/useCompact.cjs +27 -1
  89. package/dist/cjs/server/format/useCompact.cjs.map +1 -1
  90. package/dist/cjs/server/format/useCurrency.cjs +38 -1
  91. package/dist/cjs/server/format/useCurrency.cjs.map +1 -1
  92. package/dist/cjs/server/format/useDate.cjs +43 -1
  93. package/dist/cjs/server/format/useDate.cjs.map +1 -1
  94. package/dist/cjs/server/format/useIntl.cjs +44 -1
  95. package/dist/cjs/server/format/useIntl.cjs.map +1 -1
  96. package/dist/cjs/server/format/useList.cjs +35 -1
  97. package/dist/cjs/server/format/useList.cjs.map +1 -1
  98. package/dist/cjs/server/format/useNumber.cjs +39 -1
  99. package/dist/cjs/server/format/useNumber.cjs.map +1 -1
  100. package/dist/cjs/server/format/usePercentage.cjs +35 -1
  101. package/dist/cjs/server/format/usePercentage.cjs.map +1 -1
  102. package/dist/cjs/server/format/useRelativeTime.cjs +35 -1
  103. package/dist/cjs/server/format/useRelativeTime.cjs.map +1 -1
  104. package/dist/cjs/server/format/useUnit.cjs +34 -1
  105. package/dist/cjs/server/format/useUnit.cjs.map +1 -1
  106. package/dist/cjs/server/index.cjs +24 -1
  107. package/dist/cjs/server/serverContext.cjs +58 -1
  108. package/dist/cjs/server/serverContext.cjs.map +1 -1
  109. package/dist/cjs/server/t.cjs +35 -1
  110. package/dist/cjs/server/t.cjs.map +1 -1
  111. package/dist/cjs/server/useDictionary.cjs +17 -1
  112. package/dist/cjs/server/useDictionary.cjs.map +1 -1
  113. package/dist/cjs/server/useDictionaryAsync.cjs +21 -1
  114. package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
  115. package/dist/cjs/server/useDictionaryDynamic.cjs +22 -1
  116. package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
  117. package/dist/cjs/server/useI18n.cjs +38 -1
  118. package/dist/cjs/server/useI18n.cjs.map +1 -1
  119. package/dist/cjs/server/useIntlayer.cjs +17 -1
  120. package/dist/cjs/server/useIntlayer.cjs.map +1 -1
  121. package/dist/cjs/server/useLoadDynamic.cjs +14 -1
  122. package/dist/cjs/server/useLoadDynamic.cjs.map +1 -1
  123. package/dist/cjs/server/useLocale.cjs +24 -1
  124. package/dist/cjs/server/useLocale.cjs.map +1 -1
  125. package/dist/esm/IntlayerNode.mjs +15 -1
  126. package/dist/esm/IntlayerNode.mjs.map +1 -1
  127. package/dist/esm/UI/ContentSelector.mjs +94 -1
  128. package/dist/esm/UI/ContentSelector.mjs.map +1 -1
  129. package/dist/esm/client/IntlayerProvider.mjs +86 -1
  130. package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
  131. package/dist/esm/client/format/index.mjs +11 -1
  132. package/dist/esm/client/format/useCompact.mjs +27 -1
  133. package/dist/esm/client/format/useCompact.mjs.map +1 -1
  134. package/dist/esm/client/format/useCurrency.mjs +41 -1
  135. package/dist/esm/client/format/useCurrency.mjs.map +1 -1
  136. package/dist/esm/client/format/useDate.mjs +43 -1
  137. package/dist/esm/client/format/useDate.mjs.map +1 -1
  138. package/dist/esm/client/format/useIntl.mjs +43 -1
  139. package/dist/esm/client/format/useIntl.mjs.map +1 -1
  140. package/dist/esm/client/format/useList.mjs +38 -1
  141. package/dist/esm/client/format/useList.mjs.map +1 -1
  142. package/dist/esm/client/format/useNumber.mjs +39 -1
  143. package/dist/esm/client/format/useNumber.mjs.map +1 -1
  144. package/dist/esm/client/format/usePercentage.mjs +35 -1
  145. package/dist/esm/client/format/usePercentage.mjs.map +1 -1
  146. package/dist/esm/client/format/useRelativeTime.mjs +35 -1
  147. package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
  148. package/dist/esm/client/format/useUnit.mjs +34 -1
  149. package/dist/esm/client/format/useUnit.mjs.map +1 -1
  150. package/dist/esm/client/index.mjs +14 -1
  151. package/dist/esm/client/t.mjs +38 -1
  152. package/dist/esm/client/t.mjs.map +1 -1
  153. package/dist/esm/client/useDictionary.mjs +25 -1
  154. package/dist/esm/client/useDictionary.mjs.map +1 -1
  155. package/dist/esm/client/useDictionaryAsync.mjs +21 -1
  156. package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
  157. package/dist/esm/client/useDictionaryDynamic.mjs +22 -1
  158. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
  159. package/dist/esm/client/useI18n.mjs +43 -1
  160. package/dist/esm/client/useI18n.mjs.map +1 -1
  161. package/dist/esm/client/useIntlayer.mjs +40 -1
  162. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  163. package/dist/esm/client/useLoadDynamic.mjs +25 -1
  164. package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
  165. package/dist/esm/client/useLocale.mjs +57 -1
  166. package/dist/esm/client/useLocale.mjs.map +1 -1
  167. package/dist/esm/client/useLocaleBase.mjs +23 -1
  168. package/dist/esm/client/useLocaleBase.mjs.map +1 -1
  169. package/dist/esm/client/useLocaleStorage.mjs +55 -1
  170. package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
  171. package/dist/esm/client/useRewriteURL.mjs +39 -1
  172. package/dist/esm/client/useRewriteURL.mjs.map +1 -1
  173. package/dist/esm/client/useTraduction.mjs +33 -1
  174. package/dist/esm/client/useTraduction.mjs.map +1 -1
  175. package/dist/esm/editor/ContentSelector.mjs +16 -1
  176. package/dist/esm/editor/ContentSelector.mjs.map +1 -1
  177. package/dist/esm/editor/EditorProvider.mjs +10 -1
  178. package/dist/esm/editor/EditorProvider.mjs.map +1 -1
  179. package/dist/esm/editor/useEditor.mjs +37 -1
  180. package/dist/esm/editor/useEditor.mjs.map +1 -1
  181. package/dist/esm/getDictionary.mjs +8 -1
  182. package/dist/esm/getDictionary.mjs.map +1 -1
  183. package/dist/esm/getIntlayer.mjs +8 -1
  184. package/dist/esm/getIntlayer.mjs.map +1 -1
  185. package/dist/esm/html/HTMLProvider.mjs +15 -1
  186. package/dist/esm/html/HTMLProvider.mjs.map +1 -1
  187. package/dist/esm/html/HTMLRenderer.mjs +55 -1
  188. package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
  189. package/dist/esm/html/HTMLRendererPlugin.mjs +21 -1
  190. package/dist/esm/html/HTMLRendererPlugin.mjs.map +1 -1
  191. package/dist/esm/html/index.mjs +5 -1
  192. package/dist/esm/index.mjs +21 -1
  193. package/dist/esm/markdown/MarkdownProvider.mjs +77 -1
  194. package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
  195. package/dist/esm/markdown/MarkdownRenderer.mjs +197 -1
  196. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
  197. package/dist/esm/markdown/MarkdownRendererPlugin.mjs +16 -1
  198. package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
  199. package/dist/esm/markdown/index.mjs +7 -1
  200. package/dist/esm/markdown/processor.mjs +58 -1
  201. package/dist/esm/markdown/processor.mjs.map +1 -1
  202. package/dist/esm/markdown/runtime.mjs +39 -1
  203. package/dist/esm/markdown/runtime.mjs.map +1 -1
  204. package/dist/esm/plugins.mjs +190 -1
  205. package/dist/esm/plugins.mjs.map +1 -1
  206. package/dist/esm/reactElement/renderReactElement.mjs +50 -1
  207. package/dist/esm/reactElement/renderReactElement.mjs.map +1 -1
  208. package/dist/esm/server/IntlayerServerProvider.mjs +28 -1
  209. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
  210. package/dist/esm/server/format/index.mjs +10 -1
  211. package/dist/esm/server/format/useCompact.mjs +25 -1
  212. package/dist/esm/server/format/useCompact.mjs.map +1 -1
  213. package/dist/esm/server/format/useCurrency.mjs +36 -1
  214. package/dist/esm/server/format/useCurrency.mjs.map +1 -1
  215. package/dist/esm/server/format/useDate.mjs +41 -1
  216. package/dist/esm/server/format/useDate.mjs.map +1 -1
  217. package/dist/esm/server/format/useIntl.mjs +41 -1
  218. package/dist/esm/server/format/useIntl.mjs.map +1 -1
  219. package/dist/esm/server/format/useList.mjs +33 -1
  220. package/dist/esm/server/format/useList.mjs.map +1 -1
  221. package/dist/esm/server/format/useNumber.mjs +37 -1
  222. package/dist/esm/server/format/useNumber.mjs.map +1 -1
  223. package/dist/esm/server/format/usePercentage.mjs +33 -1
  224. package/dist/esm/server/format/usePercentage.mjs.map +1 -1
  225. package/dist/esm/server/format/useRelativeTime.mjs +33 -1
  226. package/dist/esm/server/format/useRelativeTime.mjs.map +1 -1
  227. package/dist/esm/server/format/useUnit.mjs +32 -1
  228. package/dist/esm/server/format/useUnit.mjs.map +1 -1
  229. package/dist/esm/server/index.mjs +12 -1
  230. package/dist/esm/server/serverContext.mjs +54 -1
  231. package/dist/esm/server/serverContext.mjs.map +1 -1
  232. package/dist/esm/server/t.mjs +33 -1
  233. package/dist/esm/server/t.mjs.map +1 -1
  234. package/dist/esm/server/useDictionary.mjs +16 -1
  235. package/dist/esm/server/useDictionary.mjs.map +1 -1
  236. package/dist/esm/server/useDictionaryAsync.mjs +18 -1
  237. package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
  238. package/dist/esm/server/useDictionaryDynamic.mjs +19 -1
  239. package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
  240. package/dist/esm/server/useI18n.mjs +37 -1
  241. package/dist/esm/server/useI18n.mjs.map +1 -1
  242. package/dist/esm/server/useIntlayer.mjs +16 -1
  243. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  244. package/dist/esm/server/useLoadDynamic.mjs +11 -1
  245. package/dist/esm/server/useLoadDynamic.mjs.map +1 -1
  246. package/dist/esm/server/useLocale.mjs +21 -1
  247. package/dist/esm/server/useLocale.mjs.map +1 -1
  248. package/dist/types/html/HTMLRenderer.d.ts +1 -1
  249. package/dist/types/plugins.d.ts +4 -3
  250. package/dist/types/plugins.d.ts.map +1 -1
  251. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"file":"processor.mjs","names":["coreCompile"],"sources":["../../../src/markdown/processor.tsx"],"sourcesContent":["/**\n * it's a fork\n * [markdown-to-jsx v7.7.14](https://github.com/quantizor/markdown-to-jsx) from quantizor\n * [simple-markdown v0.2.2](https://github.com/Khan/simple-markdown) from Khan Academy.\n */\n\nimport {\n compile as coreCompile,\n sanitizer as defaultSanitizer,\n slugify as defaultSlugify,\n type MarkdownContext,\n type MarkdownOptions,\n type MarkdownRuntime,\n type RenderRuleHook,\n RuleType,\n} from '@intlayer/core/markdown';\nimport {\n cloneElement,\n createElement,\n type FC,\n Fragment,\n type HTMLAttributes,\n type JSX,\n type ReactNode,\n} from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\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\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: HTMLComponents;\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<HTMLComponents> = {\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"],"mappings":"kKA8HA,MAAM,EAAmC,CACxB,gBACf,eACA,WACA,gBAAiB,EAAM,IAAU,EAClC,CAMY,GACX,EAAmB,GACnB,EAAmC,EAAE,GACrB,CAChB,GAAM,CACJ,cAAe,EACf,kBACA,wBACA,qBACA,aACA,cACA,eACA,sBACA,aACA,aACA,YACA,UACA,UACA,sBACA,aACE,EA2BJ,OAAOA,EAAY,EArB0B,CAC3C,QALc,EACZ,CAAE,GAAG,EAAiB,cAAe,EAA4B,CACjE,EAIF,aACA,sBACW,YACX,UACD,CAEwC,CACvC,kBACA,wBACA,qBACA,aACA,cACA,eACA,aACA,UACA,sBACA,YACD,CAEiD,EAIvC,EAAW,EACX,EAAU,EAKV,GAKR,CAAE,WAAW,GAAI,UAAS,GAAG,MAC5B,QAAQ,IAAI,WAAa,cAAgB,OAAO,GAAa,UAC/D,QAAQ,MACN,oFACA,EACD,CAGI,EACL,EAAS,EAAU,EAAQ,CAC3B,EACD"}
1
+ {"version":3,"file":"processor.mjs","names":["coreCompile"],"sources":["../../../src/markdown/processor.tsx"],"sourcesContent":["/**\n * it's a fork\n * [markdown-to-jsx v7.7.14](https://github.com/quantizor/markdown-to-jsx) from quantizor\n * [simple-markdown v0.2.2](https://github.com/Khan/simple-markdown) from Khan Academy.\n */\n\nimport {\n compile as coreCompile,\n sanitizer as defaultSanitizer,\n slugify as defaultSlugify,\n type MarkdownContext,\n type MarkdownOptions,\n type MarkdownRuntime,\n type RenderRuleHook,\n RuleType,\n} from '@intlayer/core/markdown';\nimport {\n cloneElement,\n createElement,\n type FC,\n Fragment,\n type HTMLAttributes,\n type JSX,\n type ReactNode,\n} from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\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\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: HTMLComponents;\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<HTMLComponents> = {\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"],"mappings":";;;;;;;;;;;;AA8HA,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,UArB0B;EAC3C,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"}
@@ -1,2 +1,40 @@
1
- import{Fragment as e,cloneElement as t,createElement as n}from"react";const r={createElement:(e,t,...r)=>r.length===0?n(e,t):r.length===1?n(e,t,r[0]):n(e,t,...r),cloneElement:(e,n,...r)=>r.length===0?t(e,n):t(e,n,...r),Fragment:e,normalizeProps:(e,t)=>t},i=(e={})=>{let{onCreateElement:t}=e;return t?{...r,createElement:(e,n,...r)=>t(e,n,r)}:r};export{i as createReactRuntime,r as default,r as reactRuntime};
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
+
38
+ //#endregion
39
+ export { createReactRuntime, reactRuntime as default, reactRuntime };
2
40
  //# sourceMappingURL=runtime.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.mjs","names":[],"sources":["../../../src/markdown/runtime.ts"],"sourcesContent":["import type { HTMLTag, MarkdownRuntime } from '@intlayer/core/markdown';\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":"sEAaA,MAAa,EAAgC,CAK3C,eACE,EACA,EACA,GAAG,IAIC,EAAS,SAAW,EACf,EAAc,EAAM,EAAM,CAE/B,EAAS,SAAW,EACf,EAAc,EAAM,EAAO,EAAS,GAAG,CAEzC,EAAc,EAAM,EAAO,GAAG,EAAS,CAMhD,cACE,EACA,EACA,GAAG,IAEC,EAAS,SAAW,EACf,EAAa,EAAyB,EAAM,CAE9C,EAAa,EAAyB,EAAO,GAAG,EAAS,CAMlE,WAQA,gBACE,EACA,IAKO,EAEV,CAMY,GACX,EAMI,EAAE,GACc,CACpB,GAAM,CAAE,mBAAoB,EAe5B,OAbI,EACK,CACL,GAAG,EACH,eACE,EACA,EACA,GAAG,IAEI,EAAgB,EAAM,EAAO,EAAS,CAEhD,CAGI"}
1
+ {"version":3,"file":"runtime.mjs","names":[],"sources":["../../../src/markdown/runtime.ts"],"sourcesContent":["import type { HTMLTag, MarkdownRuntime } from '@intlayer/core/markdown';\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":";;;;;;;AAaA,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"}
@@ -1,2 +1,191 @@
1
- import{ContentSelector as e}from"./editor/ContentSelector.mjs";import{HTMLRendererPlugin as t}from"./html/HTMLRendererPlugin.mjs";import{renderIntlayerNode as n}from"./IntlayerNode.mjs";import{MarkdownRendererPlugin as r}from"./markdown/MarkdownRendererPlugin.mjs";import{renderReactElement as i}from"./reactElement/renderReactElement.mjs";import a from"@intlayer/config/built";import{conditionPlugin as o,enumerationPlugin as s,filePlugin as c,genderPlugin as l,nestedPlugin as u,splitInsertionTemplate as d,translationPlugin as f}from"@intlayer/core/interpreter";import{getMarkdownMetadata as p}from"@intlayer/core/markdown";import{NodeType as m}from"@intlayer/types/nodeType";import{Fragment as h,createElement as g}from"react";import{jsx as _}from"react/jsx-runtime";const v={id:`intlayer-node-plugin`,canHandle:e=>typeof e==`bigint`||typeof e==`string`||typeof e==`number`,transform:(t,{plugins:r,...i})=>n({...i,value:i.children,children:a?.editor.enabled?_(e,{...i,children:i.children}):i.children})},y={id:`react-node-plugin`,canHandle:e=>typeof e==`object`&&e?.props!==void 0&&e.key!==void 0,transform:(t,{plugins:r,...o})=>n({...o,value:`[[react-element]]`,children:a?.editor.enabled?_(e,{...o,children:i(t)}):i(t)})},b=(e,t)=>{let n=d(e,t);return n.isSimple?n.parts:g(h,null,...n.parts.map((e,t)=>g(h,{key:t},e)))},x={id:`insertion-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===m.Insertion,transform:(e,t,n)=>{let r=[...t.keyPath,{type:m.Insertion}],i=e[m.Insertion],a={id:`insertion-string-plugin`,canHandle:e=>typeof e==`string`,transform:(e,n,r)=>{let i=r(e,{...n,children:e,plugins:[...(t.plugins??[]).filter(e=>e.id!==`intlayer-node-plugin`)]});return e=>{let a=b(i,e);return r(a,{...n,plugins:t.plugins,children:a})}}},o=n(i,{...t,children:i,keyPath:r,plugins:[a,...t.plugins??[]]});return typeof i==`object`&&i&&`nodeType`in i&&[m.Enumeration,m.Condition].includes(i.nodeType)?e=>t=>{let n=o(t);return typeof n==`function`?n(e):n}:o}},S={id:`markdown-string-plugin`,canHandle:e=>typeof e==`string`,transform:(t,i,o)=>{let{plugins:s,...c}=i,l=o(p(t),{plugins:[{id:`markdown-metadata-plugin`,canHandle:e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`||!e,transform:(r,i)=>n({...i,value:r,children:a?.editor.enabled?_(e,{...c,children:t}):t})}],dictionaryKey:c.dictionaryKey,keyPath:[]}),u=o=>n({...i,value:t,children:a.editor.enabled?_(e,{...c,children:_(r,{...c,components:o,children:t})}):_(r,{...c,components:o,children:t}),additionalProps:{metadata:l}}),d=u();return new Proxy(d,{get(e,n,r){return n===`value`?t:n===`metadata`?l:n===`use`?e=>u(e):Reflect.get(e,n,r)}})}},C={id:`markdown-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===m.Markdown,transform:(e,t,n)=>{let r=[...t.keyPath,{type:m.Markdown}],i=e[m.Markdown];return n(i,{...t,children:i,keyPath:r,plugins:[S,...t.plugins??[]]})}},w={id:`html-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===m.HTML,transform:(e,n)=>{let r=e[m.HTML],{plugins:i,...a}=n,o=e=>g(t,{...a,html:r,userComponents:e}),s=o();return new Proxy(s,{get(e,t,n){return t===`value`?r:t===`use`?e=>o(e):Reflect.get(e,t,n)}})}},T=(e,t=!0)=>[f(e??a.internationalization.defaultLocale,t?a.internationalization.defaultLocale:void 0),s,o,u(e??a.internationalization.defaultLocale),c,l,v,y,x,C,w];export{T as getPlugins,w as htmlPlugin,x as insertionPlugin,v as intlayerNodePlugins,C as markdownPlugin,S as markdownStringPlugin,y as reactNodePlugins};
1
+ import { ContentSelector } from "./editor/ContentSelector.mjs";
2
+ import { HTMLRendererPlugin } from "./html/HTMLRendererPlugin.mjs";
3
+ import { renderIntlayerNode } from "./IntlayerNode.mjs";
4
+ import { MarkdownRendererPlugin } from "./markdown/MarkdownRendererPlugin.mjs";
5
+ import { renderReactElement } from "./reactElement/renderReactElement.mjs";
6
+ import configuration from "@intlayer/config/built";
7
+ import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin, nestedPlugin, splitInsertionTemplate, translationPlugin } from "@intlayer/core/interpreter";
8
+ import { getMarkdownMetadata } from "@intlayer/core/markdown";
9
+ import * as NodeTypes from "@intlayer/types/nodeType";
10
+ import { Fragment, createElement } from "react";
11
+ import { jsx } from "react/jsx-runtime";
12
+
13
+ //#region src/plugins.tsx
14
+ /** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
15
+ const intlayerNodePlugins = {
16
+ id: "intlayer-node-plugin",
17
+ canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
18
+ transform: (_node, { plugins, ...rest }) => renderIntlayerNode({
19
+ ...rest,
20
+ value: rest.children,
21
+ children: configuration?.editor.enabled ? /* @__PURE__ */ jsx(ContentSelector, {
22
+ ...rest,
23
+ children: rest.children
24
+ }) : rest.children
25
+ })
26
+ };
27
+ /** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
28
+ const reactNodePlugins = {
29
+ id: "react-node-plugin",
30
+ canHandle: (node) => typeof node === "object" && typeof node?.props !== "undefined" && typeof node.key !== "undefined",
31
+ transform: (node, { plugins, ...rest }) => renderIntlayerNode({
32
+ ...rest,
33
+ value: "[[react-element]]",
34
+ children: configuration?.editor.enabled ? /* @__PURE__ */ jsx(ContentSelector, {
35
+ ...rest,
36
+ children: renderReactElement(node)
37
+ }) : renderReactElement(node)
38
+ })
39
+ };
40
+ /**
41
+ * Split insertion string and join with React nodes using shared core logic
42
+ */
43
+ const splitAndJoinInsertion = (template, values) => {
44
+ const result = splitInsertionTemplate(template, values);
45
+ if (result.isSimple) return result.parts;
46
+ return createElement(Fragment, null, ...result.parts.map((part, index) => createElement(Fragment, { key: index }, part)));
47
+ };
48
+ /** Insertion plugin for React. Handles component/node insertion. */
49
+ const insertionPlugin = {
50
+ id: "insertion-plugin",
51
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.INSERTION,
52
+ transform: (node, props, deepTransformNode) => {
53
+ const newKeyPath = [...props.keyPath, { type: NodeTypes.INSERTION }];
54
+ const children = node[NodeTypes.INSERTION];
55
+ /** Insertion string plugin. Replaces string node with a component that render the insertion. */
56
+ const insertionStringPlugin = {
57
+ id: "insertion-string-plugin",
58
+ canHandle: (node) => typeof node === "string",
59
+ transform: (node, subProps, deepTransformNode) => {
60
+ const transformedResult = deepTransformNode(node, {
61
+ ...subProps,
62
+ children: node,
63
+ plugins: [...(props.plugins ?? []).filter((plugin) => plugin.id !== "intlayer-node-plugin")]
64
+ });
65
+ return (values) => {
66
+ const result = splitAndJoinInsertion(transformedResult, values);
67
+ return deepTransformNode(result, {
68
+ ...subProps,
69
+ plugins: props.plugins,
70
+ children: result
71
+ });
72
+ };
73
+ }
74
+ };
75
+ const result = deepTransformNode(children, {
76
+ ...props,
77
+ children,
78
+ keyPath: newKeyPath,
79
+ plugins: [insertionStringPlugin, ...props.plugins ?? []]
80
+ });
81
+ if (typeof children === "object" && children !== null && "nodeType" in children && [NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(children.nodeType)) return (values) => (arg) => {
82
+ const inner = result(arg);
83
+ if (typeof inner === "function") return inner(values);
84
+ return inner;
85
+ };
86
+ return result;
87
+ }
88
+ };
89
+ /** Markdown string plugin. Replaces string node with a component that render the markdown. */
90
+ const markdownStringPlugin = {
91
+ id: "markdown-string-plugin",
92
+ canHandle: (node) => typeof node === "string",
93
+ transform: (node, props, deepTransformNode) => {
94
+ const { plugins, ...rest } = props;
95
+ const metadataNodes = deepTransformNode(getMarkdownMetadata(node), {
96
+ plugins: [{
97
+ id: "markdown-metadata-plugin",
98
+ canHandle: (metadataNode) => typeof metadataNode === "string" || typeof metadataNode === "number" || typeof metadataNode === "boolean" || !metadataNode,
99
+ transform: (metadataNode, props) => renderIntlayerNode({
100
+ ...props,
101
+ value: metadataNode,
102
+ children: configuration?.editor.enabled ? /* @__PURE__ */ jsx(ContentSelector, {
103
+ ...rest,
104
+ children: node
105
+ }) : node
106
+ })
107
+ }],
108
+ dictionaryKey: rest.dictionaryKey,
109
+ keyPath: []
110
+ });
111
+ const render = (components) => renderIntlayerNode({
112
+ ...props,
113
+ value: node,
114
+ children: configuration.editor.enabled ? /* @__PURE__ */ jsx(ContentSelector, {
115
+ ...rest,
116
+ children: /* @__PURE__ */ jsx(MarkdownRendererPlugin, {
117
+ ...rest,
118
+ components,
119
+ children: node
120
+ })
121
+ }) : /* @__PURE__ */ jsx(MarkdownRendererPlugin, {
122
+ ...rest,
123
+ components,
124
+ children: node
125
+ }),
126
+ additionalProps: { metadata: metadataNodes }
127
+ });
128
+ const element = render();
129
+ return new Proxy(element, { get(target, prop, receiver) {
130
+ if (prop === "value") return node;
131
+ if (prop === "metadata") return metadataNodes;
132
+ if (prop === "use") return (components) => render(components);
133
+ return Reflect.get(target, prop, receiver);
134
+ } });
135
+ }
136
+ };
137
+ const markdownPlugin = {
138
+ id: "markdown-plugin",
139
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.MARKDOWN,
140
+ transform: (node, props, deepTransformNode) => {
141
+ const newKeyPath = [...props.keyPath, { type: NodeTypes.MARKDOWN }];
142
+ const children = node[NodeTypes.MARKDOWN];
143
+ return deepTransformNode(children, {
144
+ ...props,
145
+ children,
146
+ keyPath: newKeyPath,
147
+ plugins: [markdownStringPlugin, ...props.plugins ?? []]
148
+ });
149
+ }
150
+ };
151
+ /** HTML plugin. Replaces node with a function that takes components => ReactNode. */
152
+ const htmlPlugin = {
153
+ id: "html-plugin",
154
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.HTML,
155
+ transform: (node, props) => {
156
+ const html = node[NodeTypes.HTML];
157
+ const { plugins, ...rest } = props;
158
+ const render = (userComponents) => createElement(HTMLRendererPlugin, {
159
+ ...rest,
160
+ html,
161
+ userComponents
162
+ });
163
+ const element = render();
164
+ return new Proxy(element, { get(target, prop, receiver) {
165
+ if (prop === "value") return html;
166
+ if (prop === "use") return (userComponents) => render(userComponents);
167
+ return Reflect.get(target, prop, receiver);
168
+ } });
169
+ }
170
+ };
171
+ /**
172
+ * Get the plugins array for React content transformation.
173
+ * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
174
+ */
175
+ const getPlugins = (locale, fallback = true) => [
176
+ translationPlugin(locale ?? configuration.internationalization.defaultLocale, fallback ? configuration.internationalization.defaultLocale : void 0),
177
+ enumerationPlugin,
178
+ conditionPlugin,
179
+ nestedPlugin(locale ?? configuration.internationalization.defaultLocale),
180
+ filePlugin,
181
+ genderPlugin,
182
+ intlayerNodePlugins,
183
+ reactNodePlugins,
184
+ insertionPlugin,
185
+ markdownPlugin,
186
+ htmlPlugin
187
+ ];
188
+
189
+ //#endregion
190
+ export { getPlugins, htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin, reactNodePlugins };
2
191
  //# sourceMappingURL=plugins.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport {\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { ContentSelector } from './editor/ContentSelector';\nimport { HTMLRendererPlugin } from './html';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { 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: configuration?.editor.enabled ? (\n <ContentSelector {...rest}>{rest.children}</ContentSelector>\n ) : (\n rest.children\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: configuration?.editor.enabled ? (\n <ContentSelector {...rest}>{renderReactElement(node)}</ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n }),\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: string;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<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 const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n if (\n typeof children === 'object' &&\n children !== null &&\n 'nodeType' in children &&\n [NodeType.Enumeration, NodeType.Condition].includes(\n children.nodeType as NodeType\n )\n ) {\n return (values: any) => (arg: any) => {\n const func = result as Function;\n const inner = func(arg);\n\n if (typeof inner === 'function') {\n return inner(values);\n }\n return inner;\n };\n }\n\n return result;\n },\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n use: (components: HTMLComponents<'permissive', {}>) => ReactNode;\n }\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: configuration?.editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\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?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children: configuration.editor.enabled ? (\n <ContentSelector {...rest}>\n <MarkdownRendererPlugin {...rest} components={components}>\n {node}\n </MarkdownRendererPlugin>\n </ContentSelector>\n ) : (\n <MarkdownRendererPlugin {...rest} components={components}>\n {node}\n </MarkdownRendererPlugin>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const element = render() as unknown 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?: HTMLComponents) => render(components);\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n};\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.Markdown]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\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\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\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 { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): 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 (userComponents?: HTMLComponents) => 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 type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T>;\n reactMarkdown: MarkdownCond<T>;\n reactHtml: HTMLPluginCond<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 = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n reactNode: true;\n reactIntlayerNode: true;\n reactMarkdown: true;\n reactHtml: true;\n reactInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\n/**\n * Get the plugins array for React content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => [\n translationPlugin(\n locale ?? configuration.internationalization.defaultLocale,\n fallback ? configuration.internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin(locale ?? configuration.internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n];\n"],"mappings":"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"}
1
+ {"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport {\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { ContentSelector } from './editor/ContentSelector';\nimport { HTMLRendererPlugin } from './html';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { 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: configuration?.editor.enabled ? (\n <ContentSelector {...rest}>{rest.children}</ContentSelector>\n ) : (\n rest.children\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: configuration?.editor.enabled ? (\n <ContentSelector {...rest}>{renderReactElement(node)}</ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n }),\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: string;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<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 === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.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 const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n if (\n typeof children === 'object' &&\n children !== null &&\n 'nodeType' in children &&\n [NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(\n children.nodeType as NodeType\n )\n ) {\n return (values: any) => (arg: any) => {\n const func = result as Function;\n const inner = func(arg);\n\n if (typeof inner === 'function') {\n return inner(values);\n }\n return inner;\n };\n }\n\n return result;\n },\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n use: (components: HTMLComponents<'permissive', {}>) => ReactNode;\n }\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: configuration?.editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\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?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children: configuration.editor.enabled ? (\n <ContentSelector {...rest}>\n <MarkdownRendererPlugin {...rest} components={components}>\n {node}\n </MarkdownRendererPlugin>\n </ContentSelector>\n ) : (\n <MarkdownRendererPlugin {...rest} components={components}>\n {node}\n </MarkdownRendererPlugin>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const element = render() as unknown 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?: HTMLComponents) => render(components);\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n};\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins = {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.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\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\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 === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): 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 (userComponents?: HTMLComponents) => 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 type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T>;\n reactMarkdown: MarkdownCond<T>;\n reactHtml: HTMLPluginCond<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 = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n reactNode: true;\n reactIntlayerNode: true;\n reactMarkdown: true;\n reactHtml: true;\n reactInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\n/**\n * Get the plugins array for React content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => [\n translationPlugin(\n locale ?? configuration.internationalization.defaultLocale,\n fallback ? configuration.internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin(locale ?? configuration.internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n];\n"],"mappings":"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"}
@@ -1,2 +1,51 @@
1
- import{createElement as e}from"react";const t=n=>{if(typeof n!=`object`||!n)return n;let{type:r,props:i}=(n=>{let r=n.props?.children;if(Array.isArray(r)){let i=r.map((n,r)=>{let i=t(n);if(typeof i==`object`&&i&&`type`in i){let t=i;return e(t.type,{...t.props,key:r},...Array.isArray(t.props?.children)?t.props.children:t.props?.children===void 0?[]:[t.props.children])}return i});return{...n,props:{...n.props,children:i}}}else if(r!=null){let e=t(r);return{...n,props:{...n.props,children:[e]}}}return{...n,props:{...n.props,children:[]}}})(n);return e(r??`span`,i,...i.children)};export{t as renderReactElement};
1
+ import { createElement } from "react";
2
+
3
+ //#region src/reactElement/renderReactElement.ts
4
+ const renderReactElement = (element) => {
5
+ if (element === null || typeof element !== "object") return element;
6
+ const convertChildrenAsArray = (element) => {
7
+ const children = element.props?.children;
8
+ if (Array.isArray(children)) {
9
+ const childrenResult = children.map((child, index) => {
10
+ const renderedChild = renderReactElement(child);
11
+ if (typeof renderedChild === "object" && renderedChild !== null && "type" in renderedChild) {
12
+ const childElement = renderedChild;
13
+ return createElement(childElement.type, {
14
+ ...childElement.props,
15
+ key: index
16
+ }, ...Array.isArray(childElement.props?.children) ? childElement.props.children : typeof childElement.props?.children !== "undefined" ? [childElement.props.children] : []);
17
+ }
18
+ return renderedChild;
19
+ });
20
+ return {
21
+ ...element,
22
+ props: {
23
+ ...element.props,
24
+ children: childrenResult
25
+ }
26
+ };
27
+ } else if (typeof children !== "undefined" && children !== null) {
28
+ const renderedChild = renderReactElement(children);
29
+ return {
30
+ ...element,
31
+ props: {
32
+ ...element.props,
33
+ children: [renderedChild]
34
+ }
35
+ };
36
+ }
37
+ return {
38
+ ...element,
39
+ props: {
40
+ ...element.props,
41
+ children: []
42
+ }
43
+ };
44
+ };
45
+ const { type, props } = convertChildrenAsArray(element);
46
+ return createElement(type ?? "span", props, ...props.children);
47
+ };
48
+
49
+ //#endregion
50
+ export { renderReactElement };
2
51
  //# sourceMappingURL=renderReactElement.mjs.map
@@ -1 +1 @@
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>): any => {\n if (element === null || typeof element !== 'object') {\n return element;\n }\n\n const convertChildrenAsArray = (\n element: ReactElement<{ children?: ReactNode }>\n ): ReactElement<{ children?: ReactNode }> => {\n const children = element.props?.children;\n\n if (Array.isArray(children)) {\n const childrenResult: ReactNode[] = children.map((child, index) => {\n const renderedChild = renderReactElement(child as ReactElement<any>);\n\n if (\n typeof renderedChild === 'object' &&\n renderedChild !== null &&\n 'type' in renderedChild\n ) {\n const childElement = renderedChild as ReactElement<any>;\n return createElement(\n childElement.type,\n { ...childElement.props, key: index },\n ...(Array.isArray(childElement.props?.children)\n ? childElement.props.children\n : typeof childElement.props?.children !== 'undefined'\n ? [childElement.props.children]\n : [])\n );\n }\n return renderedChild;\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n } else if (typeof children !== 'undefined' && children !== null) {\n const renderedChild = renderReactElement(children as ReactElement<any>);\n return {\n ...element,\n props: { ...element.props, children: [renderedChild] },\n };\n }\n\n return {\n ...element,\n props: { ...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":"sCAGA,MAAa,EAAsB,GAAoC,CACrE,GAAwB,OAAO,GAAY,WAAvC,EACF,OAAO,EAqDT,GAAM,CAAE,OAAM,UAjDZ,GAC2C,CAC3C,IAAM,EAAW,EAAQ,OAAO,SAEhC,GAAI,MAAM,QAAQ,EAAS,CAAE,CAC3B,IAAM,EAA8B,EAAS,KAAK,EAAO,IAAU,CACjE,IAAM,EAAgB,EAAmB,EAA2B,CAEpE,GACE,OAAO,GAAkB,UACzB,GACA,SAAU,EACV,CACA,IAAM,EAAe,EACrB,OAAO,EACL,EAAa,KACb,CAAE,GAAG,EAAa,MAAO,IAAK,EAAO,CACrC,GAAI,MAAM,QAAQ,EAAa,OAAO,SAAS,CAC3C,EAAa,MAAM,SACZ,EAAa,OAAO,WAAa,OAEtC,EAAE,CADF,CAAC,EAAa,MAAM,SAAS,CAEpC,CAEH,OAAO,GACP,CAEF,MAAO,CACL,GAAG,EACH,MAAO,CAAE,GAAG,EAAQ,MAAO,SAAU,EAAgB,CACtD,SACe,GAAyC,KAAM,CAC/D,IAAM,EAAgB,EAAmB,EAA8B,CACvE,MAAO,CACL,GAAG,EACH,MAAO,CAAE,GAAG,EAAQ,MAAO,SAAU,CAAC,EAAc,CAAE,CACvD,CAGH,MAAO,CACL,GAAG,EACH,MAAO,CAAE,GAAG,EAAQ,MAAO,SAAU,EAAE,CAAE,CAC1C,GAID,EACD,CAKD,OAAO,EACL,GAAQ,OACR,EACA,GAAI,EAAM,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>): any => {\n if (element === null || typeof element !== 'object') {\n return element;\n }\n\n const convertChildrenAsArray = (\n element: ReactElement<{ children?: ReactNode }>\n ): ReactElement<{ children?: ReactNode }> => {\n const children = element.props?.children;\n\n if (Array.isArray(children)) {\n const childrenResult: ReactNode[] = children.map((child, index) => {\n const renderedChild = renderReactElement(child as ReactElement<any>);\n\n if (\n typeof renderedChild === 'object' &&\n renderedChild !== null &&\n 'type' in renderedChild\n ) {\n const childElement = renderedChild as ReactElement<any>;\n return createElement(\n childElement.type,\n { ...childElement.props, key: index },\n ...(Array.isArray(childElement.props?.children)\n ? childElement.props.children\n : typeof childElement.props?.children !== 'undefined'\n ? [childElement.props.children]\n : [])\n );\n }\n return renderedChild;\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n } else if (typeof children !== 'undefined' && children !== null) {\n const renderedChild = renderReactElement(children as ReactElement<any>);\n return {\n ...element,\n props: { ...element.props, children: [renderedChild] },\n };\n }\n\n return {\n ...element,\n props: { ...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,YAAoC;AACrE,KAAI,YAAY,QAAQ,OAAO,YAAY,SACzC,QAAO;CAGT,MAAM,0BACJ,YAC2C;EAC3C,MAAM,WAAW,QAAQ,OAAO;AAEhC,MAAI,MAAM,QAAQ,SAAS,EAAE;GAC3B,MAAM,iBAA8B,SAAS,KAAK,OAAO,UAAU;IACjE,MAAM,gBAAgB,mBAAmB,MAA2B;AAEpE,QACE,OAAO,kBAAkB,YACzB,kBAAkB,QAClB,UAAU,eACV;KACA,MAAM,eAAe;AACrB,YAAO,cACL,aAAa,MACb;MAAE,GAAG,aAAa;MAAO,KAAK;MAAO,EACrC,GAAI,MAAM,QAAQ,aAAa,OAAO,SAAS,GAC3C,aAAa,MAAM,WACnB,OAAO,aAAa,OAAO,aAAa,cACtC,CAAC,aAAa,MAAM,SAAS,GAC7B,EAAE,CACT;;AAEH,WAAO;KACP;AAEF,UAAO;IACL,GAAG;IACH,OAAO;KAAE,GAAG,QAAQ;KAAO,UAAU;KAAgB;IACtD;aACQ,OAAO,aAAa,eAAe,aAAa,MAAM;GAC/D,MAAM,gBAAgB,mBAAmB,SAA8B;AACvE,UAAO;IACL,GAAG;IACH,OAAO;KAAE,GAAG,QAAQ;KAAO,UAAU,CAAC,cAAc;KAAE;IACvD;;AAGH,SAAO;GACL,GAAG;GACH,OAAO;IAAE,GAAG,QAAQ;IAAO,UAAU,EAAE;IAAE;GAC1C;;CAOH,MAAM,EAAE,MAAM,UAJO,uBACnB,QACD;AAKD,QAAO,cACL,QAAQ,QACR,OACA,GAAI,MAAM,SACX"}
@@ -1,2 +1,29 @@
1
- import{createServerContext as e,getServerContext as t}from"./serverContext.mjs";import n from"@intlayer/config/built";import{jsx as r}from"react/jsx-runtime";const{defaultLocale:i}=n?.internationalization??{},a=e(i),o=()=>t(a),s=t(a),c=({children:e,locale:t=i})=>r(a.Provider,{value:t,children:e});export{a as IntlayerServerContext,c as IntlayerServerProvider,s as locale,o as useIntlayer};
1
+ import { createServerContext, getServerContext } from "./serverContext.mjs";
2
+ import configuration from "@intlayer/config/built";
3
+ import { jsx } from "react/jsx-runtime";
4
+
5
+ //#region src/server/IntlayerServerProvider.tsx
6
+ const { defaultLocale } = configuration?.internationalization ?? {};
7
+ /**
8
+ * Context that store the current locale on the server side
9
+ */
10
+ const IntlayerServerContext = createServerContext(defaultLocale);
11
+ /**
12
+ * Hook that provides the current locale
13
+ */
14
+ const useIntlayer = () => getServerContext(IntlayerServerContext);
15
+ /**
16
+ * Get the current locale
17
+ */
18
+ const locale = getServerContext(IntlayerServerContext);
19
+ /**
20
+ * Provider that store the current locale on the server side
21
+ */
22
+ const IntlayerServerProvider = ({ children, locale = defaultLocale }) => /* @__PURE__ */ jsx(IntlayerServerContext.Provider, {
23
+ value: locale,
24
+ children
25
+ });
26
+
27
+ //#endregion
28
+ export { IntlayerServerContext, IntlayerServerProvider, locale, useIntlayer };
2
29
  //# sourceMappingURL=IntlayerServerProvider.mjs.map
@@ -1 +1 @@
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/module_augmentation';\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":"8JAMA,KAAM,CAAE,iBAAkB,GAAe,sBAAwB,EAAE,CAKtD,EACX,EAAmC,EAAc,CAKtC,MAAoB,EAAiB,EAAsB,CAK3D,EAAS,EAAiB,EAAsB,CAShD,GAA2D,CACtE,WACA,SAAS,KAET,EAAC,EAAsB,SAAvB,CAAgC,MAAO,EACpC,WAC8B,CAAA"}
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/module_augmentation';\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,UAAvB;CAAgC,OAAO;CACpC;CAC8B"}
@@ -1 +1,10 @@
1
- import{useUnit as e}from"./useUnit.mjs";import{useDate as t}from"./useDate.mjs";import{useNumber as n}from"./useNumber.mjs";import{useRelativeTime as r}from"./useRelativeTime.mjs";import{useCompact as i}from"./useCompact.mjs";import{useList as a}from"./useList.mjs";import{usePercentage as o}from"./usePercentage.mjs";import{useCurrency as s}from"./useCurrency.mjs";export{i as useCompact,s as useCurrency,t as useDate,a as useList,n as useNumber,o as usePercentage,r as useRelativeTime,e as useUnit};
1
+ import { useUnit } from "./useUnit.mjs";
2
+ import { useDate } from "./useDate.mjs";
3
+ import { useNumber } from "./useNumber.mjs";
4
+ import { useRelativeTime } from "./useRelativeTime.mjs";
5
+ import { useCompact } from "./useCompact.mjs";
6
+ import { useList } from "./useList.mjs";
7
+ import { usePercentage } from "./usePercentage.mjs";
8
+ import { useCurrency } from "./useCurrency.mjs";
9
+
10
+ export { useCompact, useCurrency, useDate, useList, useNumber, usePercentage, useRelativeTime, useUnit };
@@ -1,2 +1,26 @@
1
- import{getServerContext as e}from"../serverContext.mjs";import{IntlayerServerContext as t}from"../IntlayerServerProvider.mjs";import{compact as n}from"@intlayer/core/formatters";const r=()=>{let r=e(t);return(...e)=>n(e[0],{...e[1],locale:e[1]?.locale??r})};export{r as useCompact};
1
+ import { getServerContext } from "../serverContext.mjs";
2
+ import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
3
+ import { compact } from "@intlayer/core/formatters";
4
+
5
+ //#region src/server/format/useCompact.ts
6
+ /**
7
+ * React client hook that provides a compact number formatter
8
+ * bound to the current application locale.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const formatCompact = useCompact();
13
+ * formatCompact(1500); // "1.5K"
14
+ * ```
15
+ */
16
+ const useCompact = () => {
17
+ const locale = getServerContext(IntlayerServerContext);
18
+ return (...args) => compact(args[0], {
19
+ ...args[1],
20
+ locale: args[1]?.locale ?? locale
21
+ });
22
+ };
23
+
24
+ //#endregion
25
+ export { useCompact };
2
26
  //# sourceMappingURL=useCompact.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCompact.mjs","names":[],"sources":["../../../../src/server/format/useCompact.ts"],"sourcesContent":["import { compact } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a compact number formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCompact = useCompact();\n * formatCompact(1500); // \"1.5K\"\n * ```\n */\nexport const useCompact = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"kLAeA,MAAa,MAAmB,CAC9B,IAAM,EAAS,EAAgC,EAAsB,CAErE,OAAQ,GAAG,IACT,EAAQ,EAAK,GAAI,CACf,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC"}
1
+ {"version":3,"file":"useCompact.mjs","names":[],"sources":["../../../../src/server/format/useCompact.ts"],"sourcesContent":["import { compact } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a compact number formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCompact = useCompact();\n * formatCompact(1500); // \"1.5K\"\n * ```\n */\nexport const useCompact = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,mBAAmB;CAC9B,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,QAAQ,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
@@ -1,2 +1,37 @@
1
- import{getServerContext as e}from"../serverContext.mjs";import{IntlayerServerContext as t}from"../IntlayerServerProvider.mjs";import{currency as n}from"@intlayer/core/formatters";const r=()=>{let r=e(t);return(...e)=>n(e[0],{...e[1],locale:e[1]?.locale??r})};export{r as useCurrency};
1
+ import { getServerContext } from "../serverContext.mjs";
2
+ import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
3
+ import { currency } from "@intlayer/core/formatters";
4
+
5
+ //#region src/server/format/useCurrency.ts
6
+ /**
7
+ * React client hook that provides a currency formatter
8
+ * bound to the current application locale.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const formatCurrency = useCurrency();
13
+ *
14
+ * formatCurrency(1500, { currency: "USD" });
15
+ * // "$1,500.00"
16
+ *
17
+ * formatCurrency(1500, { currency: "EUR", locale: "de-DE" });
18
+ * // "1.500,00 €"
19
+ *
20
+ * formatCurrency(9876543.21, {
21
+ * currency: "JPY",
22
+ * fractionDigits: 0,
23
+ * });
24
+ * // "¥9,876,543"
25
+ * ```
26
+ */
27
+ const useCurrency = () => {
28
+ const locale = getServerContext(IntlayerServerContext);
29
+ return (...args) => currency(args[0], {
30
+ ...args[1],
31
+ locale: args[1]?.locale ?? locale
32
+ });
33
+ };
34
+
35
+ //#endregion
36
+ export { useCurrency };
2
37
  //# sourceMappingURL=useCurrency.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCurrency.mjs","names":[],"sources":["../../../../src/server/format/useCurrency.ts"],"sourcesContent":["import { currency } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a currency formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCurrency = useCurrency();\n *\n * formatCurrency(1500, { currency: \"USD\" });\n * // \"$1,500.00\"\n *\n * formatCurrency(1500, { currency: \"EUR\", locale: \"de-DE\" });\n * // \"1.500,00 €\"\n *\n * formatCurrency(9876543.21, {\n * currency: \"JPY\",\n * fractionDigits: 0,\n * });\n * // \"¥9,876,543\"\n * ```\n */\nexport const useCurrency = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"mLA0BA,MAAa,MAAoB,CAC/B,IAAM,EAAS,EAAgC,EAAsB,CAErE,OAAQ,GAAG,IACT,EAAS,EAAK,GAAI,CAChB,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC"}
1
+ {"version":3,"file":"useCurrency.mjs","names":[],"sources":["../../../../src/server/format/useCurrency.ts"],"sourcesContent":["import { currency } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a currency formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCurrency = useCurrency();\n *\n * formatCurrency(1500, { currency: \"USD\" });\n * // \"$1,500.00\"\n *\n * formatCurrency(1500, { currency: \"EUR\", locale: \"de-DE\" });\n * // \"1.500,00 €\"\n *\n * formatCurrency(9876543.21, {\n * currency: \"JPY\",\n * fractionDigits: 0,\n * });\n * // \"¥9,876,543\"\n * ```\n */\nexport const useCurrency = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,oBAAoB;CAC/B,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,SAAS,KAAK,IAAI;EAChB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}