react-intlayer 9.4.4 → 9.5.1

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.
package/README.md CHANGED
@@ -69,8 +69,6 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
69
69
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/interoperability.png?raw=true" alt="Feature" width="700"> | **Interoperability**<br><br>Allow interoperability with react-i18next, next-i18next, next-intl, react-intl, vue-i18n. <br><br> - [Intlayer and react-intl](https://intlayer.org/blog/intlayer-with-react-intl) <br> - [Intlayer and next-intl](https://intlayer.org/blog/intlayer-with-next-intl) <br> - [Intlayer and next-i18next](https://intlayer.org/blog/intlayer-with-next-i18next) <br> - [Intlayer and vue-i18n](https://intlayer.org/blog/intlayer-with-vue-i18n) <br> - [Intlayer compat adapters](https://intlayer.org/doc/compatibility) |
70
70
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/benchmark.png?raw=true" alt="Feature" width="700"> | **Performances & Benchmark**<br><br>Uses advanced tree-shaking and dynamic loading to boost performances and keep the solution as light as possible. <br><br> - [Performances & Benchmark](https://intlayer.org/doc/benchmark) |
71
71
 
72
- ---
73
-
74
72
  ## 📦 Installation
75
73
 
76
74
  Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
@@ -7,6 +7,7 @@ let _intlayer_config_built = require("@intlayer/config/built");
7
7
  let react = require("react");
8
8
 
9
9
  //#region src/client/useLocale.ts
10
+ const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
10
11
  /**
11
12
  * Client-side hook to get the current locale and related locale management functions.
12
13
  *
@@ -31,26 +32,26 @@ let react = require("react");
31
32
  * ```
32
33
  */
33
34
  const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
34
- const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
35
35
  const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
36
+ const setLocale = (0, react.useCallback)((locale) => {
37
+ if (!availableLocales?.map(String).includes(locale)) {
38
+ console.error(`Locale ${locale} is not available`);
39
+ return;
40
+ }
41
+ setLocaleState(locale);
42
+ require_client_useLocaleStorage.setLocaleInStorage(locale, isCookieEnabled ?? isCookieEnabledContext ?? true);
43
+ onLocaleChange?.(locale);
44
+ }, [
45
+ availableLocales,
46
+ onLocaleChange,
47
+ setLocaleState,
48
+ isCookieEnabled
49
+ ]);
36
50
  return {
37
51
  locale,
38
52
  defaultLocale,
39
53
  availableLocales,
40
- setLocale: (0, react.useCallback)((locale) => {
41
- if (!availableLocales?.map(String).includes(locale)) {
42
- console.error(`Locale ${locale} is not available`);
43
- return;
44
- }
45
- setLocaleState(locale);
46
- require_client_useLocaleStorage.setLocaleInStorage(locale, isCookieEnabled ?? isCookieEnabledContext ?? true);
47
- onLocaleChange?.(locale);
48
- }, [
49
- availableLocales,
50
- onLocaleChange,
51
- setLocaleState,
52
- isCookieEnabled
53
- ])
54
+ setLocale
54
55
  };
55
56
  };
56
57
 
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.cjs","names":["internationalization","useContext","IntlayerClientContext","useCallback"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * Client-side hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'react-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext) ?? {};\n\n const setLocale = useCallback(\n (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale as DeclaredLocales);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAa,aAAa,EACxB,iBACA,mBACkB,CAAC,MAAuB;CAC1C,MAAM,EAAE,eAAe,SAAS,qBAC9BA,+CAAwB,CAAC;CAE3B,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,+BACfC,kBAAWC,qDAAqB,KAAK,CAAC;CAmB1C,OAAO;EACL;EACA;EACA;EACA,eArBgBC,oBACf,WAA0B;GACzB,IAAI,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG;IACnD,QAAQ,MAAM,UAAU,OAAO,kBAAkB;IACjD;GACF;GAEA,eAAe,MAAM;GACrB,mDACE,QACA,mBAAmB,0BAA0B,IAC/C;GACA,iBAAiB,MAAyB;EAC5C,GACA;GAAC;GAAkB;GAAgB;GAAgB;EAAe,CAO1D;CACV;AACF"}
1
+ {"version":3,"file":"useLocale.cjs","names":["internationalization","useContext","IntlayerClientContext","useCallback"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\nconst { defaultLocale, locales: availableLocales } = internationalization ?? {};\n\n/**\n * Client-side hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'react-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext) ?? {};\n\n const setLocale = useCallback(\n (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale as DeclaredLocales);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;AAuBA,MAAM,EAAE,eAAe,SAAS,qBAAqBA,+CAAwB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AAyB9E,MAAa,aAAa,EACxB,iBACA,mBACkB,CAAC,MAAuB;CAC1C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,+BACfC,kBAAWC,qDAAqB,KAAK,CAAC;CAE1C,MAAM,gBAAYC,oBACf,WAA0B;EACzB,IAAI,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG;GACnD,QAAQ,MAAM,UAAU,OAAO,kBAAkB;GACjD;EACF;EAEA,eAAe,MAAM;EACrB,mDACE,QACA,mBAAmB,0BAA0B,IAC/C;EACA,iBAAiB,MAAyB;CAC5C,GACA;EAAC;EAAkB;EAAgB;EAAgB;CAAe,CACpE;CAEA,OAAO;EACL;EACA;EACA;EACA;CACF;AACF"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_markdown_runtime = require('./runtime.cjs');
2
3
  let _intlayer_core_markdown = require("@intlayer/core/markdown");
3
- let react = require("react");
4
4
 
5
5
  //#region src/markdown/processor.tsx
6
6
  /**
@@ -9,15 +9,6 @@ let react = require("react");
9
9
  * [simple-markdown v0.2.2](https://github.com/Khan/simple-markdown) from Khan Academy.
10
10
  */
11
11
  /**
12
- * Default React runtime for markdown rendering.
13
- */
14
- const DEFAULT_RUNTIME = {
15
- createElement: react.createElement,
16
- cloneElement: react.cloneElement,
17
- Fragment: react.Fragment,
18
- normalizeProps: (_tag, props) => props
19
- };
20
- /**
21
12
  * **Step 1 of 2 — parse only.**
22
13
  * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering
23
14
  * any React elements. Use this when you need to:
@@ -38,7 +29,7 @@ const DEFAULT_RUNTIME = {
38
29
  const parseMarkdown = (markdown = "", options = {}) => {
39
30
  const { disableAutoLink, disableParsingRawHTML, enforceAtxHeadings, forceBlock, forceInline, forceWrapper, namedCodesToUnicode, components, sanitizer, slugify, wrapper, preserveFrontmatter, tagfilter } = options;
40
31
  return (0, _intlayer_core_markdown.parseMarkdown)(markdown, {
41
- runtime: DEFAULT_RUNTIME,
32
+ runtime: require_markdown_runtime.reactRuntime,
42
33
  components,
43
34
  namedCodesToUnicode,
44
35
  sanitizer,
@@ -74,9 +65,9 @@ const compileMarkdown = (input = "", options = {}) => {
74
65
  const { createElement: customCreateElement, disableAutoLink, disableParsingRawHTML, enforceAtxHeadings, forceBlock, forceInline, forceWrapper, namedCodesToUnicode, components, renderRule, sanitizer, slugify, wrapper, preserveFrontmatter, tagfilter } = options;
75
66
  const ctx = {
76
67
  runtime: customCreateElement ? {
77
- ...DEFAULT_RUNTIME,
68
+ ...require_markdown_runtime.reactRuntime,
78
69
  createElement: customCreateElement
79
- } : DEFAULT_RUNTIME,
70
+ } : require_markdown_runtime.reactRuntime,
80
71
  components,
81
72
  namedCodesToUnicode,
82
73
  sanitizer,
@@ -1 +1 @@
1
- {"version":3,"file":"processor.cjs","names":["createElement","coreParseMarkdown","coreCompile","coreRenderMarkdownAst"],"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 parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n type MarkdownContext,\n type MarkdownOptions,\n type MarkdownRuntime,\n type ParsedMarkdown,\n type RenderRuleHook,\n} from '@intlayer/core/markdown';\nimport {\n cloneElement,\n createElement,\n Fragment,\n type JSX,\n type ReactNode,\n} from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\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 * Intermediate AST produced by `parseMarkdown`.\n * Pass this to `compileMarkdown` or `<MarkdownRenderer>` to skip re-parsing\n * when the same content is rendered multiple times.\n */\nexport type { ParsedMarkdown };\n\n/**\n * **Step 1 of 2 — parse only.**\n * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering\n * any React elements. Use this when you need to:\n * - Cache the parsed result and render it several times with different options.\n * - Inspect or transform the AST before rendering.\n * - Defer the render step to a later point in the pipeline.\n *\n * @param markdown - The markdown source string.\n * @param options - Options that affect parsing (sanitizer, slugify, …).\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```tsx\n * const ast = parseMarkdown('# Hello **world**');\n * const element = compileMarkdown(ast, { forceBlock: true });\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: MarkdownRendererOptions = {}\n): ParsedMarkdown => {\n const {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n namedCodesToUnicode,\n components,\n sanitizer,\n slugify,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n } = options;\n\n const ctx: MarkdownContext<HTMLComponents> = {\n runtime: DEFAULT_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 wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return coreParseMarkdown(markdown, ctx, compilerOptions);\n};\n\n/**\n * **Steps 1 + 2 — parse and render in one shot.**\n * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and\n * returns a React element. Use `parseMarkdown` first when you need to reuse\n * the same AST with different options.\n *\n * @param input - Markdown string or pre-parsed AST.\n * @param options - Rendering options (custom components, sanitizer, slugify, …).\n * @returns A React JSX element representing the rendered markdown.\n *\n * @example\n * ```tsx\n * const element = compileMarkdown('# Hello **world**', { forceBlock: true });\n * ```\n */\nexport const compileMarkdown = (\n input: string | ParsedMarkdown = '',\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 if (typeof input === 'string') {\n return coreCompile(input, ctx, compilerOptions) as JSX.Element;\n }\n\n return coreRenderMarkdownAst(input, ctx, compilerOptions) as JSX.Element;\n};\n"],"mappings":";;;;;;;;;;;;;AAsHA,MAAM,kBAAmC;CACvC,eAAeA;CACf;CACA;CACA,iBAAiB,MAAM,UAAU;AACnC;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,iBACX,WAAmB,IACnB,UAAmC,CAAC,MACjB;CACnB,MAAM,EACJ,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAsBJ,WAAOC,uCAAkB,UAAU;EAnBjC,SAAS;EACT;EACA;EACW;EACX;CAemC,GAAG;EAXtC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAGoD,CAAC;AACzD;;;;;;;;;;;;;;;;AAiBA,MAAa,mBACX,QAAiC,IACjC,UAAmC,CAAC,MACpB;CAChB,MAAM,EACJ,eAAe,qBACf,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAMJ,MAAM,MAAuC;EAC3C,SALc,sBACZ;GAAE,GAAG;GAAiB,eAAe;EAA2B,IAChE;EAIF;EACA;EACW;EACX;CACF;CAEA,MAAM,kBAAmC;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,IAAI,OAAO,UAAU,UACnB,WAAOC,iCAAY,OAAO,KAAK,eAAe;CAGhD,WAAOC,2CAAsB,OAAO,KAAK,eAAe;AAC1D"}
1
+ {"version":3,"file":"processor.cjs","names":["coreParseMarkdown","reactRuntime","coreCompile","coreRenderMarkdownAst"],"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 parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n type MarkdownContext,\n type MarkdownOptions,\n type ParsedMarkdown,\n type RenderRuleHook,\n} from '@intlayer/core/markdown';\nimport type { createElement, JSX, ReactNode } from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\nimport { reactRuntime } from './runtime';\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 */\n\n/**\n * Intermediate AST produced by `parseMarkdown`.\n * Pass this to `compileMarkdown` or `<MarkdownRenderer>` to skip re-parsing\n * when the same content is rendered multiple times.\n */\nexport type { ParsedMarkdown };\n\n/**\n * **Step 1 of 2 — parse only.**\n * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering\n * any React elements. Use this when you need to:\n * - Cache the parsed result and render it several times with different options.\n * - Inspect or transform the AST before rendering.\n * - Defer the render step to a later point in the pipeline.\n *\n * @param markdown - The markdown source string.\n * @param options - Options that affect parsing (sanitizer, slugify, …).\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```tsx\n * const ast = parseMarkdown('# Hello **world**');\n * const element = compileMarkdown(ast, { forceBlock: true });\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: MarkdownRendererOptions = {}\n): ParsedMarkdown => {\n const {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n namedCodesToUnicode,\n components,\n sanitizer,\n slugify,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n } = options;\n\n const ctx: MarkdownContext<HTMLComponents> = {\n runtime: reactRuntime,\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 wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return coreParseMarkdown(markdown, ctx, compilerOptions);\n};\n\n/**\n * **Steps 1 + 2 — parse and render in one shot.**\n * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and\n * returns a React element. Use `parseMarkdown` first when you need to reuse\n * the same AST with different options.\n *\n * @param input - Markdown string or pre-parsed AST.\n * @param options - Rendering options (custom components, sanitizer, slugify, …).\n * @returns A React JSX element representing the rendered markdown.\n *\n * @example\n * ```tsx\n * const element = compileMarkdown('# Hello **world**', { forceBlock: true });\n * ```\n */\nexport const compileMarkdown = (\n input: string | ParsedMarkdown = '',\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 ? { ...reactRuntime, createElement: customCreateElement as any }\n : reactRuntime;\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 if (typeof input === 'string') {\n return coreCompile(input, ctx, compilerOptions) as JSX.Element;\n }\n\n return coreRenderMarkdownAst(input, ctx, compilerOptions) as JSX.Element;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0IA,MAAa,iBACX,WAAmB,IACnB,UAAmC,CAAC,MACjB;CACnB,MAAM,EACJ,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAsBJ,WAAOA,uCAAkB,UAAU;EAnBjC,SAASC;EACT;EACA;EACW;EACX;CAemC,GAAG;EAXtC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAGoD,CAAC;AACzD;;;;;;;;;;;;;;;;AAiBA,MAAa,mBACX,QAAiC,IACjC,UAAmC,CAAC,MACpB;CAChB,MAAM,EACJ,eAAe,qBACf,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAMJ,MAAM,MAAuC;EAC3C,SALc,sBACZ;GAAE,GAAGA;GAAc,eAAe;EAA2B,IAC7DA;EAIF;EACA;EACW;EACX;CACF;CAEA,MAAM,kBAAmC;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,IAAI,OAAO,UAAU,UACnB,WAAOC,iCAAY,OAAO,KAAK,eAAe;CAGhD,WAAOC,2CAAsB,OAAO,KAAK,eAAe;AAC1D"}
@@ -6,15 +6,43 @@ let react = require("react");
6
6
  * React-specific runtime for the markdown processor.
7
7
  * Implements the MarkdownRuntime interface using React's primitives.
8
8
  */
9
+ let REACT_ELEMENT_TYPE;
10
+ try {
11
+ const sample = (0, react.createElement)("div");
12
+ REACT_ELEMENT_TYPE = sample && typeof sample === "object" && "$$typeof" in sample && typeof sample.$$typeof === "symbol" ? sample.$$typeof : Symbol.for("react.transitional.element");
13
+ } catch {
14
+ REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
15
+ }
16
+ /**
17
+ * React-specific runtime for the markdown processor.
18
+ * Implements the MarkdownRuntime interface using React's primitives.
19
+ */
9
20
  const reactRuntime = {
10
21
  /**
11
22
  * Creates a React element.
12
23
  * Handles the conversion of props and children to React format.
13
24
  */
14
25
  createElement: (type, props, ...children) => {
15
- if (children.length === 0) return (0, react.createElement)(type, props);
16
- if (children.length === 1) return (0, react.createElement)(type, props, children[0]);
17
- return (0, react.createElement)(type, props, ...children);
26
+ let key = null;
27
+ const finalProps = props || {};
28
+ if (props && props.key != null) {
29
+ key = String(props.key);
30
+ finalProps.key = void 0;
31
+ }
32
+ const childCount = children.length;
33
+ if (childCount === 1) finalProps.children = children[0];
34
+ else if (childCount > 1) finalProps.children = children;
35
+ return {
36
+ $$typeof: REACT_ELEMENT_TYPE,
37
+ type,
38
+ key,
39
+ ref: null,
40
+ props: finalProps,
41
+ _owner: null,
42
+ _store: {},
43
+ _debugStack: null,
44
+ _debugTask: null
45
+ };
18
46
  },
19
47
  /**
20
48
  * Clones a React element with new props.
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.cjs","names":["createElement","cloneElement"],"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"],"mappings":";;;;;;;;AAaA,MAAa,eAAgC;;;;;CAK3C,gBACE,MACA,OACA,GAAG,aACW;EAGd,IAAI,SAAS,WAAW,GACtB,WAAOA,qBAAc,MAAM,KAAK;EAElC,IAAI,SAAS,WAAW,GACtB,WAAOA,qBAAc,MAAM,OAAO,SAAS,EAAE;EAE/C,WAAOA,qBAAc,MAAM,OAAO,GAAG,QAAQ;CAC/C;;;;CAKA,eACE,SACA,OACA,GAAG,aACW;EACd,IAAI,SAAS,WAAW,GACtB,WAAOC,oBAAa,SAAyB,KAAK;EAEpD,WAAOA,oBAAa,SAAyB,OAAO,GAAG,QAAQ;CACjE;;;;CAKA;;;;;;;CAQA,iBACE,MACA,UACwB;EAIxB,OAAO;CACT;AACF;;;;;AAMA,MAAa,sBACX,UAMI,CAAC,MACe;CACpB,MAAM,EAAE,oBAAoB;CAE5B,IAAI,iBACF,OAAO;EACL,GAAG;EACH,gBACE,MACA,OACA,GAAG,aACW;GACd,OAAO,gBAAgB,MAAM,OAAO,QAAQ;EAC9C;CACF;CAGF,OAAO;AACT"}
1
+ {"version":3,"file":"runtime.cjs","names":["createElement","cloneElement"],"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 */\nlet REACT_ELEMENT_TYPE: symbol;\ntry {\n const sample = createElement('div');\n REACT_ELEMENT_TYPE =\n sample &&\n typeof sample === 'object' &&\n '$$typeof' in sample &&\n typeof sample.$$typeof === 'symbol'\n ? (sample.$$typeof as symbol)\n : Symbol.for('react.transitional.element');\n} catch {\n REACT_ELEMENT_TYPE = Symbol.for('react.transitional.element');\n}\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 let key: string | null = null;\n const finalProps: any = props || {};\n\n if (props && props.key != null) {\n key = String(props.key);\n finalProps.key = undefined;\n }\n\n const childCount = children.length;\n if (childCount === 1) {\n finalProps.children = children[0];\n } else if (childCount > 1) {\n finalProps.children = children;\n }\n\n return {\n $$typeof: REACT_ELEMENT_TYPE,\n type,\n key,\n ref: null,\n props: finalProps,\n _owner: null,\n _store: {},\n _debugStack: null,\n _debugTask: null,\n } as unknown as ReactNode;\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"],"mappings":";;;;;;;;AAaA,IAAI;AACJ,IAAI;CACF,MAAM,aAASA,qBAAc,KAAK;CAClC,qBACE,UACA,OAAO,WAAW,YAClB,cAAc,UACd,OAAO,OAAO,aAAa,WACtB,OAAO,WACR,OAAO,IAAI,4BAA4B;AAC/C,QAAQ;CACN,qBAAqB,OAAO,IAAI,4BAA4B;AAC9D;;;;;AAMA,MAAa,eAAgC;;;;;CAK3C,gBACE,MACA,OACA,GAAG,aACW;EACd,IAAI,MAAqB;EACzB,MAAM,aAAkB,SAAS,CAAC;EAElC,IAAI,SAAS,MAAM,OAAO,MAAM;GAC9B,MAAM,OAAO,MAAM,GAAG;GACtB,WAAW,MAAM;EACnB;EAEA,MAAM,aAAa,SAAS;EAC5B,IAAI,eAAe,GACjB,WAAW,WAAW,SAAS;OAC1B,IAAI,aAAa,GACtB,WAAW,WAAW;EAGxB,OAAO;GACL,UAAU;GACV;GACA;GACA,KAAK;GACL,OAAO;GACP,QAAQ;GACR,QAAQ,CAAC;GACT,aAAa;GACb,YAAY;EACd;CACF;;;;CAKA,eACE,SACA,OACA,GAAG,aACW;EACd,IAAI,SAAS,WAAW,GACtB,WAAOC,oBAAa,SAAyB,KAAK;EAEpD,WAAOA,oBAAa,SAAyB,OAAO,GAAG,QAAQ;CACjE;;;;CAKA;;;;;;;CAQA,iBACE,MACA,UACwB;EAIxB,OAAO;CACT;AACF;;;;;AAMA,MAAa,sBACX,UAMI,CAAC,MACe;CACpB,MAAM,EAAE,oBAAoB;CAE5B,IAAI,iBACF,OAAO;EACL,GAAG;EACH,gBACE,MACA,OACA,GAAG,aACW;GACd,OAAO,gBAAgB,MAAM,OAAO,QAAQ;EAC9C;CACF;CAGF,OAAO;AACT"}
@@ -4,13 +4,13 @@ const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.
4
4
  let _intlayer_config_built = require("@intlayer/config/built");
5
5
 
6
6
  //#region src/server/useLocale.ts
7
+ const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
7
8
  /**
8
9
  * On the server side, Hook that picking one dictionary by its key and return the content
9
10
  *
10
11
  * If the locale is not provided, it will use the locale from the server context
11
12
  */
12
13
  const useLocale = () => {
13
- const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
14
14
  return {
15
15
  locale: require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext) ?? defaultLocale,
16
16
  defaultLocale,
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.cjs","names":["internationalization","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useLocale = (): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n internationalization ?? {};\n\n const locale = (getServerContext(IntlayerServerContext) ??\n defaultLocale) as DeclaredLocales;\n\n return { locale, defaultLocale, availableLocales };\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,kBAAmC;CAC9C,MAAM,EAAE,eAAe,SAAS,qBAC9BA,+CAAwB,CAAC;CAK3B,OAAO;EAAE,QAHOC,8CAAiBC,2DAAqB,KACpD;EAEe;EAAe;CAAiB;AACnD"}
1
+ {"version":3,"file":"useLocale.cjs","names":["internationalization","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n};\n\nconst { defaultLocale, locales: availableLocales } = internationalization ?? {};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useLocale = (): UseLocaleResult => {\n const locale = (getServerContext(IntlayerServerContext) ??\n defaultLocale) as DeclaredLocales;\n\n return { locale, defaultLocale, availableLocales };\n};\n"],"mappings":";;;;;;AAWA,MAAM,EAAE,eAAe,SAAS,qBAAqBA,+CAAwB,CAAC;;;;;;AAO9E,MAAa,kBAAmC;CAI9C,OAAO;EAAE,QAHOC,8CAAiBC,2DAAqB,KACpD;EAEe;EAAe;CAAiB;AACnD"}
@@ -6,6 +6,7 @@ import { internationalization } from "@intlayer/config/built";
6
6
  import { useCallback, useContext } from "react";
7
7
 
8
8
  //#region src/client/useLocale.ts
9
+ const { defaultLocale, locales: availableLocales } = internationalization ?? {};
9
10
  /**
10
11
  * Client-side hook to get the current locale and related locale management functions.
11
12
  *
@@ -30,26 +31,26 @@ import { useCallback, useContext } from "react";
30
31
  * ```
31
32
  */
32
33
  const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
33
- const { defaultLocale, locales: availableLocales } = internationalization ?? {};
34
34
  const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = useContext(IntlayerClientContext) ?? {};
35
+ const setLocale = useCallback((locale) => {
36
+ if (!availableLocales?.map(String).includes(locale)) {
37
+ console.error(`Locale ${locale} is not available`);
38
+ return;
39
+ }
40
+ setLocaleState(locale);
41
+ setLocaleInStorage(locale, isCookieEnabled ?? isCookieEnabledContext ?? true);
42
+ onLocaleChange?.(locale);
43
+ }, [
44
+ availableLocales,
45
+ onLocaleChange,
46
+ setLocaleState,
47
+ isCookieEnabled
48
+ ]);
35
49
  return {
36
50
  locale,
37
51
  defaultLocale,
38
52
  availableLocales,
39
- setLocale: useCallback((locale) => {
40
- if (!availableLocales?.map(String).includes(locale)) {
41
- console.error(`Locale ${locale} is not available`);
42
- return;
43
- }
44
- setLocaleState(locale);
45
- setLocaleInStorage(locale, isCookieEnabled ?? isCookieEnabledContext ?? true);
46
- onLocaleChange?.(locale);
47
- }, [
48
- availableLocales,
49
- onLocaleChange,
50
- setLocaleState,
51
- isCookieEnabled
52
- ])
53
+ setLocale
53
54
  };
54
55
  };
55
56
 
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * Client-side hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'react-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext) ?? {};\n\n const setLocale = useCallback(\n (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale as DeclaredLocales);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAa,aAAa,EACxB,iBACA,mBACkB,CAAC,MAAuB;CAC1C,MAAM,EAAE,eAAe,SAAS,qBAC9B,wBAAwB,CAAC;CAE3B,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,2BACf,WAAW,qBAAqB,KAAK,CAAC;CAmB1C,OAAO;EACL;EACA;EACA;EACA,WArBgB,aACf,WAA0B;GACzB,IAAI,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG;IACnD,QAAQ,MAAM,UAAU,OAAO,kBAAkB;IACjD;GACF;GAEA,eAAe,MAAM;GACrB,mBACE,QACA,mBAAmB,0BAA0B,IAC/C;GACA,iBAAiB,MAAyB;EAC5C,GACA;GAAC;GAAkB;GAAgB;GAAgB;EAAe,CAO1D;CACV;AACF"}
1
+ {"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\nconst { defaultLocale, locales: availableLocales } = internationalization ?? {};\n\n/**\n * Client-side hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'react-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext) ?? {};\n\n const setLocale = useCallback(\n (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale as DeclaredLocales);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;AAuBA,MAAM,EAAE,eAAe,SAAS,qBAAqB,wBAAwB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AAyB9E,MAAa,aAAa,EACxB,iBACA,mBACkB,CAAC,MAAuB;CAC1C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,2BACf,WAAW,qBAAqB,KAAK,CAAC;CAE1C,MAAM,YAAY,aACf,WAA0B;EACzB,IAAI,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG;GACnD,QAAQ,MAAM,UAAU,OAAO,kBAAkB;GACjD;EACF;EAEA,eAAe,MAAM;EACrB,mBACE,QACA,mBAAmB,0BAA0B,IAC/C;EACA,iBAAiB,MAAyB;CAC5C,GACA;EAAC;EAAkB;EAAgB;EAAgB;CAAe,CACpE;CAEA,OAAO;EACL;EACA;EACA;EACA;CACF;AACF"}
@@ -1,5 +1,5 @@
1
+ import { reactRuntime } from "./runtime.mjs";
1
2
  import { compile, parseMarkdown as parseMarkdown$1, renderMarkdownAst } from "@intlayer/core/markdown";
2
- import { Fragment, cloneElement, createElement } from "react";
3
3
 
4
4
  //#region src/markdown/processor.tsx
5
5
  /**
@@ -8,15 +8,6 @@ import { Fragment, cloneElement, createElement } from "react";
8
8
  * [simple-markdown v0.2.2](https://github.com/Khan/simple-markdown) from Khan Academy.
9
9
  */
10
10
  /**
11
- * Default React runtime for markdown rendering.
12
- */
13
- const DEFAULT_RUNTIME = {
14
- createElement,
15
- cloneElement,
16
- Fragment,
17
- normalizeProps: (_tag, props) => props
18
- };
19
- /**
20
11
  * **Step 1 of 2 — parse only.**
21
12
  * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering
22
13
  * any React elements. Use this when you need to:
@@ -37,7 +28,7 @@ const DEFAULT_RUNTIME = {
37
28
  const parseMarkdown = (markdown = "", options = {}) => {
38
29
  const { disableAutoLink, disableParsingRawHTML, enforceAtxHeadings, forceBlock, forceInline, forceWrapper, namedCodesToUnicode, components, sanitizer, slugify, wrapper, preserveFrontmatter, tagfilter } = options;
39
30
  return parseMarkdown$1(markdown, {
40
- runtime: DEFAULT_RUNTIME,
31
+ runtime: reactRuntime,
41
32
  components,
42
33
  namedCodesToUnicode,
43
34
  sanitizer,
@@ -73,9 +64,9 @@ const compileMarkdown = (input = "", options = {}) => {
73
64
  const { createElement: customCreateElement, disableAutoLink, disableParsingRawHTML, enforceAtxHeadings, forceBlock, forceInline, forceWrapper, namedCodesToUnicode, components, renderRule, sanitizer, slugify, wrapper, preserveFrontmatter, tagfilter } = options;
74
65
  const ctx = {
75
66
  runtime: customCreateElement ? {
76
- ...DEFAULT_RUNTIME,
67
+ ...reactRuntime,
77
68
  createElement: customCreateElement
78
- } : DEFAULT_RUNTIME,
69
+ } : reactRuntime,
79
70
  components,
80
71
  namedCodesToUnicode,
81
72
  sanitizer,
@@ -1 +1 @@
1
- {"version":3,"file":"processor.mjs","names":["coreParseMarkdown","coreCompile","coreRenderMarkdownAst"],"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 parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n type MarkdownContext,\n type MarkdownOptions,\n type MarkdownRuntime,\n type ParsedMarkdown,\n type RenderRuleHook,\n} from '@intlayer/core/markdown';\nimport {\n cloneElement,\n createElement,\n Fragment,\n type JSX,\n type ReactNode,\n} from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\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 * Intermediate AST produced by `parseMarkdown`.\n * Pass this to `compileMarkdown` or `<MarkdownRenderer>` to skip re-parsing\n * when the same content is rendered multiple times.\n */\nexport type { ParsedMarkdown };\n\n/**\n * **Step 1 of 2 — parse only.**\n * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering\n * any React elements. Use this when you need to:\n * - Cache the parsed result and render it several times with different options.\n * - Inspect or transform the AST before rendering.\n * - Defer the render step to a later point in the pipeline.\n *\n * @param markdown - The markdown source string.\n * @param options - Options that affect parsing (sanitizer, slugify, …).\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```tsx\n * const ast = parseMarkdown('# Hello **world**');\n * const element = compileMarkdown(ast, { forceBlock: true });\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: MarkdownRendererOptions = {}\n): ParsedMarkdown => {\n const {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n namedCodesToUnicode,\n components,\n sanitizer,\n slugify,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n } = options;\n\n const ctx: MarkdownContext<HTMLComponents> = {\n runtime: DEFAULT_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 wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return coreParseMarkdown(markdown, ctx, compilerOptions);\n};\n\n/**\n * **Steps 1 + 2 — parse and render in one shot.**\n * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and\n * returns a React element. Use `parseMarkdown` first when you need to reuse\n * the same AST with different options.\n *\n * @param input - Markdown string or pre-parsed AST.\n * @param options - Rendering options (custom components, sanitizer, slugify, …).\n * @returns A React JSX element representing the rendered markdown.\n *\n * @example\n * ```tsx\n * const element = compileMarkdown('# Hello **world**', { forceBlock: true });\n * ```\n */\nexport const compileMarkdown = (\n input: string | ParsedMarkdown = '',\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 if (typeof input === 'string') {\n return coreCompile(input, ctx, compilerOptions) as JSX.Element;\n }\n\n return coreRenderMarkdownAst(input, ctx, compilerOptions) as JSX.Element;\n};\n"],"mappings":";;;;;;;;;;;;AAsHA,MAAM,kBAAmC;CACxB;CACf;CACA;CACA,iBAAiB,MAAM,UAAU;AACnC;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,iBACX,WAAmB,IACnB,UAAmC,CAAC,MACjB;CACnB,MAAM,EACJ,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAsBJ,OAAOA,gBAAkB,UAAU;EAnBjC,SAAS;EACT;EACA;EACW;EACX;CAemC,GAAG;EAXtC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAGoD,CAAC;AACzD;;;;;;;;;;;;;;;;AAiBA,MAAa,mBACX,QAAiC,IACjC,UAAmC,CAAC,MACpB;CAChB,MAAM,EACJ,eAAe,qBACf,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAMJ,MAAM,MAAuC;EAC3C,SALc,sBACZ;GAAE,GAAG;GAAiB,eAAe;EAA2B,IAChE;EAIF;EACA;EACW;EACX;CACF;CAEA,MAAM,kBAAmC;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,IAAI,OAAO,UAAU,UACnB,OAAOC,QAAY,OAAO,KAAK,eAAe;CAGhD,OAAOC,kBAAsB,OAAO,KAAK,eAAe;AAC1D"}
1
+ {"version":3,"file":"processor.mjs","names":["coreParseMarkdown","coreCompile","coreRenderMarkdownAst"],"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 parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n type MarkdownContext,\n type MarkdownOptions,\n type ParsedMarkdown,\n type RenderRuleHook,\n} from '@intlayer/core/markdown';\nimport type { createElement, JSX, ReactNode } from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\nimport { reactRuntime } from './runtime';\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 */\n\n/**\n * Intermediate AST produced by `parseMarkdown`.\n * Pass this to `compileMarkdown` or `<MarkdownRenderer>` to skip re-parsing\n * when the same content is rendered multiple times.\n */\nexport type { ParsedMarkdown };\n\n/**\n * **Step 1 of 2 — parse only.**\n * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering\n * any React elements. Use this when you need to:\n * - Cache the parsed result and render it several times with different options.\n * - Inspect or transform the AST before rendering.\n * - Defer the render step to a later point in the pipeline.\n *\n * @param markdown - The markdown source string.\n * @param options - Options that affect parsing (sanitizer, slugify, …).\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```tsx\n * const ast = parseMarkdown('# Hello **world**');\n * const element = compileMarkdown(ast, { forceBlock: true });\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: MarkdownRendererOptions = {}\n): ParsedMarkdown => {\n const {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n namedCodesToUnicode,\n components,\n sanitizer,\n slugify,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n } = options;\n\n const ctx: MarkdownContext<HTMLComponents> = {\n runtime: reactRuntime,\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 wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return coreParseMarkdown(markdown, ctx, compilerOptions);\n};\n\n/**\n * **Steps 1 + 2 — parse and render in one shot.**\n * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and\n * returns a React element. Use `parseMarkdown` first when you need to reuse\n * the same AST with different options.\n *\n * @param input - Markdown string or pre-parsed AST.\n * @param options - Rendering options (custom components, sanitizer, slugify, …).\n * @returns A React JSX element representing the rendered markdown.\n *\n * @example\n * ```tsx\n * const element = compileMarkdown('# Hello **world**', { forceBlock: true });\n * ```\n */\nexport const compileMarkdown = (\n input: string | ParsedMarkdown = '',\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 ? { ...reactRuntime, createElement: customCreateElement as any }\n : reactRuntime;\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 if (typeof input === 'string') {\n return coreCompile(input, ctx, compilerOptions) as JSX.Element;\n }\n\n return coreRenderMarkdownAst(input, ctx, compilerOptions) as JSX.Element;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0IA,MAAa,iBACX,WAAmB,IACnB,UAAmC,CAAC,MACjB;CACnB,MAAM,EACJ,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAsBJ,OAAOA,gBAAkB,UAAU;EAnBjC,SAAS;EACT;EACA;EACW;EACX;CAemC,GAAG;EAXtC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAGoD,CAAC;AACzD;;;;;;;;;;;;;;;;AAiBA,MAAa,mBACX,QAAiC,IACjC,UAAmC,CAAC,MACpB;CAChB,MAAM,EACJ,eAAe,qBACf,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAMJ,MAAM,MAAuC;EAC3C,SALc,sBACZ;GAAE,GAAG;GAAc,eAAe;EAA2B,IAC7D;EAIF;EACA;EACW;EACX;CACF;CAEA,MAAM,kBAAmC;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,IAAI,OAAO,UAAU,UACnB,OAAOC,QAAY,OAAO,KAAK,eAAe;CAGhD,OAAOC,kBAAsB,OAAO,KAAK,eAAe;AAC1D"}
@@ -5,15 +5,43 @@ import { Fragment, cloneElement, createElement } from "react";
5
5
  * React-specific runtime for the markdown processor.
6
6
  * Implements the MarkdownRuntime interface using React's primitives.
7
7
  */
8
+ let REACT_ELEMENT_TYPE;
9
+ try {
10
+ const sample = createElement("div");
11
+ REACT_ELEMENT_TYPE = sample && typeof sample === "object" && "$$typeof" in sample && typeof sample.$$typeof === "symbol" ? sample.$$typeof : Symbol.for("react.transitional.element");
12
+ } catch {
13
+ REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
14
+ }
15
+ /**
16
+ * React-specific runtime for the markdown processor.
17
+ * Implements the MarkdownRuntime interface using React's primitives.
18
+ */
8
19
  const reactRuntime = {
9
20
  /**
10
21
  * Creates a React element.
11
22
  * Handles the conversion of props and children to React format.
12
23
  */
13
24
  createElement: (type, props, ...children) => {
14
- if (children.length === 0) return createElement(type, props);
15
- if (children.length === 1) return createElement(type, props, children[0]);
16
- return createElement(type, props, ...children);
25
+ let key = null;
26
+ const finalProps = props || {};
27
+ if (props && props.key != null) {
28
+ key = String(props.key);
29
+ finalProps.key = void 0;
30
+ }
31
+ const childCount = children.length;
32
+ if (childCount === 1) finalProps.children = children[0];
33
+ else if (childCount > 1) finalProps.children = children;
34
+ return {
35
+ $$typeof: REACT_ELEMENT_TYPE,
36
+ type,
37
+ key,
38
+ ref: null,
39
+ props: finalProps,
40
+ _owner: null,
41
+ _store: {},
42
+ _debugStack: null,
43
+ _debugTask: null
44
+ };
17
45
  },
18
46
  /**
19
47
  * Clones a React element with new props.
@@ -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"],"mappings":";;;;;;;AAaA,MAAa,eAAgC;;;;;CAK3C,gBACE,MACA,OACA,GAAG,aACW;EAGd,IAAI,SAAS,WAAW,GACtB,OAAO,cAAc,MAAM,KAAK;EAElC,IAAI,SAAS,WAAW,GACtB,OAAO,cAAc,MAAM,OAAO,SAAS,EAAE;EAE/C,OAAO,cAAc,MAAM,OAAO,GAAG,QAAQ;CAC/C;;;;CAKA,eACE,SACA,OACA,GAAG,aACW;EACd,IAAI,SAAS,WAAW,GACtB,OAAO,aAAa,SAAyB,KAAK;EAEpD,OAAO,aAAa,SAAyB,OAAO,GAAG,QAAQ;CACjE;;;;CAKA;;;;;;;CAQA,iBACE,MACA,UACwB;EAIxB,OAAO;CACT;AACF;;;;;AAMA,MAAa,sBACX,UAMI,CAAC,MACe;CACpB,MAAM,EAAE,oBAAoB;CAE5B,IAAI,iBACF,OAAO;EACL,GAAG;EACH,gBACE,MACA,OACA,GAAG,aACW;GACd,OAAO,gBAAgB,MAAM,OAAO,QAAQ;EAC9C;CACF;CAGF,OAAO;AACT"}
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 */\nlet REACT_ELEMENT_TYPE: symbol;\ntry {\n const sample = createElement('div');\n REACT_ELEMENT_TYPE =\n sample &&\n typeof sample === 'object' &&\n '$$typeof' in sample &&\n typeof sample.$$typeof === 'symbol'\n ? (sample.$$typeof as symbol)\n : Symbol.for('react.transitional.element');\n} catch {\n REACT_ELEMENT_TYPE = Symbol.for('react.transitional.element');\n}\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 let key: string | null = null;\n const finalProps: any = props || {};\n\n if (props && props.key != null) {\n key = String(props.key);\n finalProps.key = undefined;\n }\n\n const childCount = children.length;\n if (childCount === 1) {\n finalProps.children = children[0];\n } else if (childCount > 1) {\n finalProps.children = children;\n }\n\n return {\n $$typeof: REACT_ELEMENT_TYPE,\n type,\n key,\n ref: null,\n props: finalProps,\n _owner: null,\n _store: {},\n _debugStack: null,\n _debugTask: null,\n } as unknown as ReactNode;\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"],"mappings":";;;;;;;AAaA,IAAI;AACJ,IAAI;CACF,MAAM,SAAS,cAAc,KAAK;CAClC,qBACE,UACA,OAAO,WAAW,YAClB,cAAc,UACd,OAAO,OAAO,aAAa,WACtB,OAAO,WACR,OAAO,IAAI,4BAA4B;AAC/C,QAAQ;CACN,qBAAqB,OAAO,IAAI,4BAA4B;AAC9D;;;;;AAMA,MAAa,eAAgC;;;;;CAK3C,gBACE,MACA,OACA,GAAG,aACW;EACd,IAAI,MAAqB;EACzB,MAAM,aAAkB,SAAS,CAAC;EAElC,IAAI,SAAS,MAAM,OAAO,MAAM;GAC9B,MAAM,OAAO,MAAM,GAAG;GACtB,WAAW,MAAM;EACnB;EAEA,MAAM,aAAa,SAAS;EAC5B,IAAI,eAAe,GACjB,WAAW,WAAW,SAAS;OAC1B,IAAI,aAAa,GACtB,WAAW,WAAW;EAGxB,OAAO;GACL,UAAU;GACV;GACA;GACA,KAAK;GACL,OAAO;GACP,QAAQ;GACR,QAAQ,CAAC;GACT,aAAa;GACb,YAAY;EACd;CACF;;;;CAKA,eACE,SACA,OACA,GAAG,aACW;EACd,IAAI,SAAS,WAAW,GACtB,OAAO,aAAa,SAAyB,KAAK;EAEpD,OAAO,aAAa,SAAyB,OAAO,GAAG,QAAQ;CACjE;;;;CAKA;;;;;;;CAQA,iBACE,MACA,UACwB;EAIxB,OAAO;CACT;AACF;;;;;AAMA,MAAa,sBACX,UAMI,CAAC,MACe;CACpB,MAAM,EAAE,oBAAoB;CAE5B,IAAI,iBACF,OAAO;EACL,GAAG;EACH,gBACE,MACA,OACA,GAAG,aACW;GACd,OAAO,gBAAgB,MAAM,OAAO,QAAQ;EAC9C;CACF;CAGF,OAAO;AACT"}
@@ -3,13 +3,13 @@ import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
3
3
  import { internationalization } from "@intlayer/config/built";
4
4
 
5
5
  //#region src/server/useLocale.ts
6
+ const { defaultLocale, locales: availableLocales } = internationalization ?? {};
6
7
  /**
7
8
  * On the server side, Hook that picking one dictionary by its key and return the content
8
9
  *
9
10
  * If the locale is not provided, it will use the locale from the server context
10
11
  */
11
12
  const useLocale = () => {
12
- const { defaultLocale, locales: availableLocales } = internationalization ?? {};
13
13
  return {
14
14
  locale: getServerContext(IntlayerServerContext) ?? defaultLocale,
15
15
  defaultLocale,
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/server/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useLocale = (): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n internationalization ?? {};\n\n const locale = (getServerContext(IntlayerServerContext) ??\n defaultLocale) as DeclaredLocales;\n\n return { locale, defaultLocale, availableLocales };\n};\n"],"mappings":";;;;;;;;;;AAgBA,MAAa,kBAAmC;CAC9C,MAAM,EAAE,eAAe,SAAS,qBAC9B,wBAAwB,CAAC;CAK3B,OAAO;EAAE,QAHO,iBAAiB,qBAAqB,KACpD;EAEe;EAAe;CAAiB;AACnD"}
1
+ {"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/server/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n};\n\nconst { defaultLocale, locales: availableLocales } = internationalization ?? {};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useLocale = (): UseLocaleResult => {\n const locale = (getServerContext(IntlayerServerContext) ??\n defaultLocale) as DeclaredLocales;\n\n return { locale, defaultLocale, availableLocales };\n};\n"],"mappings":";;;;;AAWA,MAAM,EAAE,eAAe,SAAS,qBAAqB,wBAAwB,CAAC;;;;;;AAO9E,MAAa,kBAAmC;CAI9C,OAAO;EAAE,QAHO,iBAAiB,qBAAqB,KACpD;EAEe;EAAe;CAAiB;AACnD"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;YAWY;EACV;EACA,kBAAkB,QAAQ;;YAGhB;EACV,QAAQ;EACR,eAAe;EACf,kBAAkB;EAClB,YAAY,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;qBA0BT,cAAS,iBAAA,mBAGnB,mBAAsB"}
1
+ {"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;YAWY;EACV;EACA,kBAAkB,QAAQ;;YAGhB;EACV,QAAQ;EACR,eAAe;EACf,kBAAkB;EAClB,YAAY,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;qBA4BT,cAAS,iBAAA,mBAGnB,mBAAsB"}
@@ -4,8 +4,8 @@
4
4
  */
5
5
  export declare const useLocaleBase: () => {
6
6
  locale: import("@intlayer/types").LocalesValues;
7
- defaultLocale: any;
8
- availableLocales: any;
7
+ defaultLocale: import("@intlayer/types").Locale;
8
+ availableLocales: import("@intlayer/types").Locale[];
9
9
  setLocale: (newLocale: import("@intlayer/types").LocalesValues) => void;
10
10
  };
11
11
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"processor.d.ts","names":[],"sources":["../../../src/markdown/processor.tsx"],"mappings":";;;;KAyBK,iBAAiB,IAAI;;;;YAKd,0BAA0B;;;;EAIpC,gBACE,KAAK,kBAAkB,mBACvB,OAAO,IAAI,wBACR,UAAU,gBACV;;;;;EAML;;;;;EAMA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;KACG;;;;;EAMH,YAAY;;;;EAKZ,YAAY;;;;EAKZ,YAAY,eAAe,KAAK,UAAU;;;;EAK1C,UAAU;;;;EAKV;;;;EAKA;;;;EAKA;;;;;;;;;;;;;;;;;;;;qBAsCW,gBAAa,mBACR,UACP,4BACR;;;;;;;;;;;;;;;;qBAuDU,kBAAe,iBACV,gBAAc,UACrB,4BACR,IAAI"}
1
+ {"version":3,"file":"processor.d.ts","names":[],"sources":["../../../src/markdown/processor.tsx"],"mappings":";;;;KAmBK,iBAAiB,IAAI;;;;YAKd,0BAA0B;;;;EAIpC,gBACE,KAAK,kBAAkB,mBACvB,OAAO,IAAI,wBACR,UAAU,gBACV;;;;;EAML;;;;;EAMA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;KACG;;;;;EAMH,YAAY;;;;EAKZ,YAAY;;;;EAKZ,YAAY,eAAe,KAAK,UAAU;;;;EAK1C,UAAU;;;;EAKV;;;;EAKA;;;;EAKA;;;;;;;;;;;;;;;;;;;;qBAgCW,gBAAa,mBACR,UACP,4BACR;;;;;;;;;;;;;;;;qBAuDU,kBAAe,iBACV,gBAAc,UACrB,4BACR,IAAI"}
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","names":[],"sources":["../../../src/markdown/runtime.ts"],"mappings":";;;;;;;qBAaa,cAAc;;;;;qBA6Dd,qBAAkB;EAE3B,mBACE,oBACA,OAAO,4BACP,oBACG;MAEN"}
1
+ {"version":3,"file":"runtime.d.ts","names":[],"sources":["../../../src/markdown/runtime.ts"],"mappings":";;;;;;;qBA+Ba,cAAc;;;;;qBA8Ed,qBAAkB;EAE3B,mBACE,oBACA,OAAO,4BACP,oBACG;MAEN"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/server/useLocale.ts"],"mappings":";;YAKY;EACV,QAAQ;EACR,eAAe;EACf,kBAAkB;;;;;;;qBAQP,iBAAgB"}
1
+ {"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/server/useLocale.ts"],"mappings":";;YAKY;EACV,QAAQ;EACR,eAAe;EACf,kBAAkB;;;;;;;qBAUP,iBAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intlayer",
3
- "version": "9.4.4",
3
+ "version": "9.5.1",
4
4
  "private": false,
5
5
  "description": "Easily internationalize i18n your React applications with type-safe multilingual content management.",
6
6
  "keywords": [
@@ -132,17 +132,17 @@
132
132
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
133
133
  },
134
134
  "dependencies": {
135
- "@intlayer/api": "9.4.4",
136
- "@intlayer/config": "9.4.4",
137
- "@intlayer/core": "9.4.4",
138
- "@intlayer/dictionaries-entry": "9.4.4",
139
- "@intlayer/editor": "9.4.4",
140
- "@intlayer/types": "9.4.4"
135
+ "@intlayer/api": "9.5.1",
136
+ "@intlayer/config": "9.5.1",
137
+ "@intlayer/core": "9.5.1",
138
+ "@intlayer/dictionaries-entry": "9.5.1",
139
+ "@intlayer/editor": "9.5.1",
140
+ "@intlayer/types": "9.5.1"
141
141
  },
142
142
  "devDependencies": {
143
143
  "@craco/types": "7.1.0",
144
144
  "@testing-library/react": "16.3.3",
145
- "@types/node": "26.4.1",
145
+ "@types/node": "26.5.0",
146
146
  "@types/react": ">=16.0.0",
147
147
  "@types/react-dom": ">=16.0.0",
148
148
  "@utils/ts-config": "1.0.4",
@@ -158,7 +158,7 @@
158
158
  "react-dom": ">=16.0.0"
159
159
  },
160
160
  "optionalDependencies": {
161
- "@intlayer/analytics": "9.4.4"
161
+ "@intlayer/analytics": "9.5.1"
162
162
  },
163
163
  "engines": {
164
164
  "node": ">=14.18"