react-intlayer 8.4.0 → 8.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useI18n.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
- package/dist/cjs/editor/useEditor.cjs +1 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +1 -1
- package/dist/cjs/plugins.cjs +1 -1
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/server/format/useIntl.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useI18n.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs.map +1 -1
- package/dist/esm/editor/useEditor.mjs +1 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +1 -1
- package/dist/esm/plugins.mjs +1 -1
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/server/format/useIntl.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/types/client/format/useIntl.d.ts +2 -58
- package/dist/types/client/format/useIntl.d.ts.map +1 -1
- package/dist/types/client/format/useList.d.ts +5 -1
- package/dist/types/client/format/useList.d.ts.map +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useI18n.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useRewriteURL.d.ts.map +1 -1
- package/dist/types/html/HTMLRenderer.d.ts +4 -4
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts +1 -5
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -1
- package/dist/types/markdown/index.d.ts +2 -2
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/server/format/useIntl.d.ts +2 -58
- package/dist/types/server/format/useIntl.d.ts.map +1 -1
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/server/useDictionaryDynamic.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/cjs/markdown/MarkdownMetadataRendererInternal.cjs +0 -2
- package/dist/cjs/markdown/MarkdownMetadataRendererInternal.cjs.map +0 -1
- package/dist/esm/markdown/MarkdownMetadataRendererInternal.mjs +0 -2
- package/dist/esm/markdown/MarkdownMetadataRendererInternal.mjs.map +0 -1
- package/dist/types/markdown/MarkdownMetadataRendererInternal.d.ts +0 -16
- package/dist/types/markdown/MarkdownMetadataRendererInternal.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntl.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["'use client';\n\nimport { bindIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":"yOAmCA,MAAa,EAAW,GAA2B,CACjD,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAC7D,EAAgB,GAAU,EAEhC,OAAA,EAAA,EAAA,cAAA,EAAA,EAAA,
|
|
1
|
+
{"version":3,"file":"useIntl.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["'use client';\n\nimport { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo<WrappedIntl>(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":"yOAmCA,MAAa,EAAW,GAA2B,CACjD,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAC7D,EAAgB,GAAU,EAEhC,OAAA,EAAA,EAAA,cAAA,EAAA,EAAA,UAA2C,EAAc,CAAE,CAAC,EAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.cjs","names":["IntlayerClientContext","configuration","useDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.cjs","names":["IntlayerClientContext","configuration","useDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () =>\n (await dictionaryPromise[\n localeTarget as keyof typeof dictionaryPromise\n ]?.()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L) as any;\n};\n"],"mappings":"wRAkBA,MAAa,EAAqB,MAIhC,EACA,IACe,CACf,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAE7D,GAAA,EAAA,EAAA,aAEF,GACA,GACAC,EAAAA,SAAe,qBAAqB,cACtC,CAAC,EAAe,EAAO,CACxB,CAUD,OAAOC,EAAAA,cARY,MAAA,EAAA,EAAA,SACjB,SACG,MAAM,EACL,MACG,CACP,CAAC,EAAmB,EAAa,CAClC,CAEsC,EAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["IntlayerClientContext","configuration","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["IntlayerClientContext","configuration","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":"0TAmBA,MAAa,GAIX,EACA,EACA,IACG,CACH,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAC7D,GAAA,EAAA,EAAA,aAEF,GACA,GACAC,EAAAA,SAAe,qBAAqB,cACtC,CAAC,EAAe,EAAO,CACxB,CAOD,OAAOC,EAAAA,cALYC,EAAAA,eACjB,GAAG,OAAO,EAAI,CAAC,GAAG,IACjB,EAA0B,MAAiB,CAC7C,CAEgC,EAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useI18n.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/useI18n.ts"],"sourcesContent":["'use client';\n\nimport { getIntlayer } from '@intlayer/core/interpreter';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type {
|
|
1
|
+
{"version":3,"file":"useI18n.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/useI18n.ts"],"sourcesContent":["'use client';\n\nimport { getIntlayer } from '@intlayer/core/interpreter';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { GetSubPath } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Hook that provides a translation function `t()` for accessing nested content by key.\n * This hook mimics the pattern found in libraries like i18next, next-intl, and vue-i18n.\n *\n * @param namespace - The dictionary key to scope translations to\n * @param locale - Optional locale override. If not provided, uses the current context locale\n * @returns A translation function `t(key)` that returns the translated content for the given key\n *\n * @example\n * ```tsx\n * const t = useI18n('IndexPage');\n * const title = t('title'); // Returns translated string for 'IndexPage.title'\n * const nestedContent = t('section.subtitle'); // Returns 'IndexPage.section.subtitle'\n * // For attributes like `aria-label`, use `.value` to get the plain string\n * const ariaLabel = t('button.ariaLabel').value; // 'Close modal'\n * ```\n */\nexport const useI18n = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n namespace: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n // Get the dictionary content for the namespace\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const dictionaryContent: DeepTransformContent<DictionaryRegistryContent<T>> =\n useMemo(\n () => getIntlayer<T, L>(namespace, localeTarget as L),\n [namespace, localeTarget]\n );\n\n // Return the translation function\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const t = <P extends ValidDotPathsFor<T>>(\n path: P\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n ): GetSubPath<DeepTransformContent<DictionaryRegistryContent<T>>, P> => {\n if (!path) {\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return dictionaryContent as any;\n }\n\n const pathArray = (path as string).split('.');\n let current: any = dictionaryContent;\n\n for (const key of pathArray) {\n current = current?.[key];\n if (current === undefined) {\n // Return the whole dictionary as fallback if path is not found\n return dictionaryContent as any;\n }\n }\n\n return current;\n };\n\n return t;\n};\n"],"mappings":"sOAgCA,MAAa,GAIX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAC7D,GAAA,EAAA,EAAA,aACE,GAAU,EAChB,CAAC,EAAe,EAAO,CACxB,CAIK,GAAA,EAAA,EAAA,cAAA,EAAA,EAAA,aAEsB,EAAW,EAAkB,CACrD,CAAC,EAAW,EAAa,CAC1B,CA2BH,MAtBE,IAEsE,CACtE,GAAI,CAAC,EAEH,OAAO,EAGT,IAAM,EAAa,EAAgB,MAAM,IAAI,CACzC,EAAe,EAEnB,IAAK,IAAM,KAAO,EAEhB,GADA,EAAU,IAAU,GAChB,IAAY,IAAA,GAEd,OAAO,EAIX,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["IntlayerClientContext","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["IntlayerClientContext","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that picks one dictionary by its key and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The dictionary content for the specified locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? (currentLocale as L);\n\n return getIntlayer<T, L>(key, localeTarget);\n }, [key, currentLocale, locale]);\n};\n"],"mappings":"8NA+BA,MAAa,GAIX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAEnE,OAAA,EAAA,EAAA,aAGSC,EAAAA,YAAkB,EAFJ,GAAW,EAEW,CAC1C,CAAC,EAAK,EAAe,EAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRewriteURL.cjs","names":["useLocale","configuration"],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport { useEffect } from 'react';\nimport { useLocale } from './useLocale';\n\n/**\n * Client-side hook to manage URL rewrites without triggering a router navigation.\n * It uses `window.history.replaceState` to update the URL in the address bar.\n *\n * This hook is useful to \"prettify\" the URL when the user lands on a canonical path\n * that has a localized alias defined in `intlayer.config.ts`.\n *\n * @example\n * ```tsx\n * import { useRewriteURL } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * useRewriteURL();\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport const useRewriteURL = (): void => {\n const { locale } = useLocale();\n const rewrite = configuration?.routing?.rewrite;\n\n useEffect(() => {\n if (typeof window === 'undefined' || !rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(pathname, locale, rewrite);\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n }, [locale, rewrite]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRewriteURL.cjs","names":["useLocale","configuration"],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useEffect } from 'react';\nimport { useLocale } from './useLocale';\n\n/**\n * Client-side hook to manage URL rewrites without triggering a router navigation.\n * It uses `window.history.replaceState` to update the URL in the address bar.\n *\n * This hook is useful to \"prettify\" the URL when the user lands on a canonical path\n * that has a localized alias defined in `intlayer.config.ts`.\n *\n * @example\n * ```tsx\n * import { useRewriteURL } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * useRewriteURL();\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport const useRewriteURL = (): void => {\n const { locale } = useLocale();\n const rewrite = configuration?.routing?.rewrite;\n\n useEffect(() => {\n if (typeof window === 'undefined' || !rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(pathname, locale as Locale, rewrite);\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n }, [locale, rewrite]);\n};\n"],"mappings":"yRA0BA,MAAa,MAA4B,CACvC,GAAM,CAAE,UAAWA,EAAAA,WAAW,CACxB,EAAUC,EAAAA,SAAe,SAAS,SAExC,EAAA,EAAA,eAAgB,CACd,GAAI,OAAO,OAAW,KAAe,CAAC,EAAS,OAE/C,IAAM,EAAW,OAAO,SAAS,SAC3B,GAAA,EAAA,EAAA,gBAA4B,EAAU,EAAkB,EAAQ,CAElE,GAAc,IAAe,GAC/B,OAAO,QAAQ,aACb,OAAO,QAAQ,MACf,GACA,EAAa,OAAO,SAAS,OAAS,OAAO,SAAS,KACvD,EAEF,CAAC,EAAQ,EAAQ,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../client/IntlayerProvider.cjs`);let t=require(`react`),n=require(`@intlayer/editor/isEnabled`);const r=()=>{let{locale:r}=(0,t.useContext)(e.IntlayerClientContext),i=(0,t.useRef)(null);(0,t.useEffect)(()=>{if(n.isEnabled)return import(`@intlayer/editor`).then(({initEditorClient:e})=>{let t=e();i.current=t,r&&t.currentLocale.set(r)}),()=>{i.current=null,import(`@intlayer/editor`).then(({stopEditorClient:e})=>{e()})}},[]),(0,t.useEffect)(()=>{!r||!i.current||i.current.currentLocale.set(r)},[r])};exports.useEditor=r;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../client/IntlayerProvider.cjs`);let t=require(`react`),n=require(`@intlayer/editor/isEnabled`);const r=()=>{let{locale:r}=(0,t.useContext)(e.IntlayerClientContext),i=(0,t.useRef)(null);(0,t.useEffect)(()=>{if(!(process.env.INTLAYER_EDITOR_ENABLED===`false`||!n.isEnabled))return import(`@intlayer/editor`).then(({initEditorClient:e})=>{let t=e();i.current=t,r&&t.currentLocale.set(r)}),()=>{i.current=null,import(`@intlayer/editor`).then(({stopEditorClient:e})=>{e()})}},[]),(0,t.useEffect)(()=>{!r||!i.current||i.current.currentLocale.set(r)},[r])};exports.useEditor=r;
|
|
2
2
|
//# sourceMappingURL=useEditor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.cjs","names":["IntlayerClientContext","isEnabled"],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'react';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initializes the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale } = useContext(IntlayerClientContext);\n const managerRef = useRef<EditorStateManager | null>(null);\n\n useEffect(() => {\n if (!isEnabled) return;\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n });\n\n return () => {\n managerRef.current = null;\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n };\n }, []);\n\n useEffect(() => {\n if (!locale || !managerRef.current) return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":"8OAaA,MAAa,MAAkB,CAC7B,GAAM,CAAE,WAAA,EAAA,EAAA,YAAsBA,EAAAA,sBAAsB,CAC9C,GAAA,EAAA,EAAA,QAA+C,KAAK,EAE1D,EAAA,EAAA,eAAgB,
|
|
1
|
+
{"version":3,"file":"useEditor.cjs","names":["IntlayerClientContext","isEnabled"],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'react';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initializes the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale } = useContext(IntlayerClientContext);\n const managerRef = useRef<EditorStateManager | null>(null);\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n });\n\n return () => {\n managerRef.current = null;\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n };\n }, []);\n\n useEffect(() => {\n if (!locale || !managerRef.current) return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":"8OAaA,MAAa,MAAkB,CAC7B,GAAM,CAAE,WAAA,EAAA,EAAA,YAAsBA,EAAAA,sBAAsB,CAC9C,GAAA,EAAA,EAAA,QAA+C,KAAK,EAE1D,EAAA,EAAA,eAAgB,CACV,aAAQ,IAAI,0BAA4B,SAAW,CAACC,EAAAA,WASxD,OAPA,OAAO,oBAAoB,MAAM,CAAE,sBAAuB,CACxD,IAAM,EAAU,GAAkB,CAClC,EAAW,QAAU,EAEjB,GAAQ,EAAQ,cAAc,IAAI,EAAiB,EACvD,KAEW,CACX,EAAW,QAAU,KACrB,OAAO,oBAAoB,MAAM,CAAE,sBAAuB,CACxD,GAAkB,EAClB,GAEH,EAAE,CAAC,EAEN,EAAA,EAAA,eAAgB,CACV,CAAC,GAAU,CAAC,EAAW,SAE3B,EAAW,QAAQ,cAAc,IAAI,EAAiB,EACrD,CAAC,EAAO,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./processor.cjs`),t=require(`./MarkdownProvider.cjs`);let n=require(`react/jsx-runtime`);const r=(t,{components:n,wrapper:r,forceBlock:i,forceInline:a,preserveFrontmatter:o,tagfilter:s}={})=>e.compiler(t,{components:n,forceBlock:i,forceInline:a,wrapper:r,forceWrapper:!!r,preserveFrontmatter:o,tagfilter:s}),i=({components:e,wrapper:n,forceBlock:i,forceInline:a,preserveFrontmatter:o,tagfilter:s}={})=>{let c=t.useMarkdownContext();return t=>c?c.renderMarkdown(t,{forceBlock:i,forceInline:a,preserveFrontmatter:o,tagfilter:s},e,n):r(t,{components:e,wrapper:n,forceBlock:i,forceInline:a,preserveFrontmatter:o,tagfilter:s})},a=({children:r=``,components:i,wrapper:a,forceBlock:o,forceInline:s,preserveFrontmatter:c,tagfilter:l,renderMarkdown:u})=>{let d=t.useMarkdownContext();return u?(0,n.jsx)(n.Fragment,{children:u(r,{components:i,wrapper:a,forceBlock:o,forceInline:s,preserveFrontmatter:c,tagfilter:l})}):d?(0,n.jsx)(n.Fragment,{children:d.renderMarkdown(r,{forceBlock:o,forceInline:s,preserveFrontmatter:c,tagfilter:l},i,a)}):(0,n.jsx)(n.Fragment,{children:e.compiler(r,{components:i,forceBlock:o,forceInline:s,wrapper:a,forceWrapper:!!a,preserveFrontmatter:c,tagfilter:l})})};exports.MarkdownRenderer=a,exports.renderMarkdown=r,exports.useMarkdownRenderer=i;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./processor.cjs`),t=require(`./MarkdownProvider.cjs`);let n=require(`react/jsx-runtime`);const r=(t,{components:n,wrapper:r,forceBlock:i,forceInline:a,preserveFrontmatter:o,tagfilter:s}={})=>e.compiler(t,{components:n,forceBlock:i,forceInline:a,wrapper:r,forceWrapper:!!r,preserveFrontmatter:o,tagfilter:s}),i=({components:e,wrapper:n,forceBlock:i,forceInline:a,preserveFrontmatter:o,tagfilter:s}={})=>{let c=t.useMarkdownContext();return t=>c?c.renderMarkdown(t,{forceBlock:i,forceInline:a,preserveFrontmatter:o,tagfilter:s},e,n):r(t,{components:e,wrapper:n,forceBlock:i,forceInline:a,preserveFrontmatter:o,tagfilter:s})},a=({children:r=``,components:i,wrapper:a,forceBlock:o,forceInline:s,preserveFrontmatter:c,tagfilter:l,renderMarkdown:u})=>{let d=t.useMarkdownContext();return u?(0,n.jsx)(n.Fragment,{children:u(r,{components:i,wrapper:a,forceBlock:o,forceInline:s,preserveFrontmatter:c,tagfilter:l})}):d?(0,n.jsx)(n.Fragment,{children:d.renderMarkdown(r,{forceBlock:o,forceInline:s,preserveFrontmatter:c,tagfilter:l},i,a)}):(0,n.jsx)(n.Fragment,{children:e.compiler(r,{components:i,forceBlock:o,forceInline:s,wrapper:a,forceWrapper:!!a,preserveFrontmatter:c,tagfilter:l})})};exports.MarkdownRenderer=a,exports.renderMarkdown=r,exports.useMarkdownRenderer=i;
|
|
2
2
|
//# sourceMappingURL=MarkdownRenderer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRenderer.cjs","names":["compiler","useMarkdownContext"],"sources":["../../../src/markdown/MarkdownRenderer.tsx"],"sourcesContent":["import type { FC, HTMLAttributes, JSX, ReactNode } from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\nimport {\n type MarkdownProviderOptions,\n useMarkdownContext,\n} from './MarkdownProvider';\nimport { compiler, type MarkdownRendererOptions } from './processor';\n\n/**\n * Props for rendering markdown content.\n *\n * @example\n * ```tsx\n * const props: RenderMarkdownProps = {\n * components: {\n * h1: ({ children }) => <h1 className=\"text-3xl\">{children}</h1>,\n * p: ({ children }) => <p className=\"text-gray-700\">{children}</p>,\n * },\n * wrapper: ({ children }) => <article>{children}</article>,\n * options: {\n * forceBlock: true,\n * preserveFrontmatter: false,\n * tagfilter: true,\n * },\n * };\n * ```\n */\nexport type RenderMarkdownProps = MarkdownProviderOptions & {\n /**\n * Component overrides for HTML tags.\n * Allows you to customize how specific HTML elements are rendered.\n * Only used if not wrapped in a MarkdownProvider.\n *\n * @example\n * ```tsx\n * components={{\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * a: ({ href, children }) => <Link to={href}>{children}</Link>,\n * }}\n * ```\n */\n components?: HTMLComponents<'permissive', {}>;\n /**\n * Wrapper element or component to be used when there are multiple children.\n * Only used if not wrapped in a MarkdownProvider.\n *\n * @example\n * ```tsx\n * wrapper={({ children }) => <div className=\"markdown-content\">{children}</div>}\n * ```\n */\n wrapper?: FC<HTMLAttributes<HTMLElement>>;\n};\n\n/**\n * Renders markdown content to JSX with the provided components and options.\n *\n * This function does not use context from MarkdownProvider. Use `useMarkdownRenderer`\n * hook if you want to leverage provider context.\n *\n * @param content - The markdown string to render\n * @param props - Configuration options for rendering\n * @param props.components - Component overrides for HTML tags\n * @param props.wrapper - Wrapper component for multiple children\n * @returns JSX element representing the rendered markdown\n *\n * @example\n * ```tsx\n * import { renderMarkdown } from '@intlayer/react-intlayer/markdown';\n *\n * const markdown = '# Hello World\\n\\nThis is **bold** text.';\n * const jsx = renderMarkdown(markdown, {\n * components: {\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * },\n * forceBlock: true,\n * });\n * ```\n */\nexport const renderMarkdown = (\n content: string,\n {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n }: RenderMarkdownProps = {}\n): JSX.Element => {\n // Map public options to internal processor options\n const internalOptions: MarkdownRendererOptions = {\n components,\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return compiler(content, internalOptions);\n};\n\n/**\n * Hook that returns a function to render markdown content.\n *\n * This hook considers the configuration from the `MarkdownProvider` context if available,\n * falling back to the provided props or default behavior.\n *\n * @param props - Optional configuration that will override context values\n * @param props.components - Component overrides for HTML tags (overrides context)\n * @param props.wrapper - Wrapper component (overrides context)\n * @returns A function that takes markdown content and returns JSX\n *\n * @example\n * ```tsx\n * import { useMarkdownRenderer } from '@intlayer/react-intlayer/markdown';\n *\n * function MyComponent() {\n * const renderMarkdown = useMarkdownRenderer({\n * components: {\n * h1: ({ children }) => <h1 className=\"custom\">{children}</h1>,\n * },\n * });\n *\n * return (\n * <div>\n * {renderMarkdown('# Hello\\n\\nThis is **markdown**')}\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With MarkdownProvider context\n * function App() {\n * return (\n * <MarkdownProvider\n * components={{ h1: CustomHeading }}\n * forceBlock={true}\n * >\n * <MyComponent />\n * </MarkdownProvider>\n * );\n * }\n * ```\n */\nexport const useMarkdownRenderer = ({\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n}: RenderMarkdownProps = {}) => {\n const context = useMarkdownContext();\n\n return (content: string) => {\n if (context) {\n return context.renderMarkdown(\n content,\n {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n },\n components,\n wrapper\n );\n }\n\n return renderMarkdown(content, {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n });\n };\n};\n\n/**\n * Props for the MarkdownRenderer component.\n *\n * @example\n * ```tsx\n * const props: MarkdownRendererProps = {\n * children: '# Hello World\\n\\nThis is **bold** text.',\n * components: {\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * },\n * wrapper: ({ children }) => <article>{children}</article>,\n * forceBlock: true,\n * };\n * ```\n */\nexport type MarkdownRendererProps = RenderMarkdownProps & {\n /**\n * The markdown content to render as a string.\n *\n * @example\n * ```tsx\n * <MarkdownRenderer>\n * {`# Title\\n\\nParagraph with **bold** text.`}\n * </MarkdownRenderer>\n * ```\n */\n children: string;\n /**\n * Custom render function for markdown.\n * If provided, it will overwrite context and default rendering.\n *\n * @param markdown - The markdown string to render\n * @param options - Optional rendering options\n * @returns React node representing the rendered markdown\n *\n * @example\n * ```tsx\n * <MarkdownRenderer\n * renderMarkdown={(md, opts) => {\n * // Custom rendering logic\n * return <div dangerouslySetInnerHTML={{ __html: customParser(md) }} />;\n * }}\n * >\n * {markdownContent}\n * </MarkdownRenderer>\n * ```\n */\n renderMarkdown?: (\n markdown: string,\n options?: {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: FC;\n forceBlock?: boolean;\n forceInline?: boolean;\n preserveFrontmatter?: boolean;\n tagfilter?: boolean;\n }\n ) => ReactNode;\n};\n\n/**\n * React component that renders markdown content to JSX.\n *\n * This component uses the `renderMarkdown` function from the `MarkdownProvider` context\n * if available. Otherwise, it falls back to the default compiler with provided components\n * and options. You can also provide a custom `renderMarkdown` function prop to override\n * all rendering behavior.\n *\n * @example\n * ```tsx\n * import { MarkdownRenderer } from '@intlayer/react-intlayer/markdown';\n *\n * function MyComponent() {\n * return (\n * <MarkdownRenderer>\n * {`# Hello World\n *\n * This is a paragraph with **bold** and *italic* text.\n *\n * - List item 1\n * - List item 2`}\n * </MarkdownRenderer>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom components\n * <MarkdownRenderer\n * components={{\n * h1: ({ children }) => <h1 className=\"text-4xl font-bold\">{children}</h1>,\n * a: ({ href, children }) => (\n * <a href={href} className=\"text-blue-500 hover:underline\">\n * {children}\n * </a>\n * ),\n * }}\n * forceBlock={true}\n * >\n * {markdownContent}\n * </MarkdownRenderer>\n * ```\n *\n * @example\n * ```tsx\n * // With MarkdownProvider context\n * function App() {\n * return (\n * <MarkdownProvider\n * components={{ h1: CustomHeading }}\n * forceBlock={true}\n * >\n * <MarkdownRenderer>\n * {markdownContent}\n * </MarkdownRenderer>\n * </MarkdownProvider>\n * );\n * }\n * ```\n */\nexport const MarkdownRenderer: FC<MarkdownRendererProps> = ({\n children = '',\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n renderMarkdown,\n}) => {\n const context = useMarkdownContext();\n\n if (renderMarkdown) {\n return (\n <>\n {renderMarkdown(children, {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n })}\n </>\n );\n }\n\n if (context) {\n return (\n <>\n {context.renderMarkdown(\n children,\n {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n },\n components,\n wrapper\n )}\n </>\n );\n }\n\n // Map public options to internal processor options\n const internalOptions: MarkdownRendererOptions = {\n components,\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return <>{compiler(children, internalOptions)}</>;\n};\n"],"mappings":"0NA+EA,MAAa,GACX,EACA,CACE,aACA,UACA,aACA,cACA,sBACA,aACuB,EAAE,GAapBA,EAAAA,SAAS,EAViC,CAC/C,aACA,aACA,cACA,UACA,aAAc,CAAC,CAAC,EAChB,sBACA,YACD,CAEwC,CAgD9B,GAAuB,CAClC,aACA,UACA,aACA,cACA,sBACA,aACuB,EAAE,GAAK,CAC9B,IAAM,EAAUC,EAAAA,oBAAoB,CAEpC,MAAQ,IACF,EACK,EAAQ,eACb,EACA,CACE,aACA,cACA,sBACA,YACD,CACD,EACA,EACD,CAGI,EAAe,EAAS,CAC7B,aACA,UACA,aACA,cACA,sBACA,YACD,CAAC,EA6HO,GAA+C,CAC1D,WAAW,GACX,aACA,UACA,aACA,cACA,sBACA,YACA,oBACI,CACJ,IAAM,EAAUA,EAAAA,oBAAoB,CA8CpC,OA5CI,GAEA,EAAA,EAAA,KAAA,EAAA,SAAA,CAAA,SACG,EAAe,EAAU,CACxB,aACA,UACA,aACA,cACA,sBACA,YACD,CAAC,CACD,CAAA,CAIH,GAEA,EAAA,EAAA,KAAA,EAAA,SAAA,CAAA,SACG,EAAQ,eACP,EACA,CACE,aACA,cACA,sBACA,YACD,CACD,EACA,EACD,CACA,CAAA,EAeA,EAAA,EAAA,KAAA,EAAA,SAAA,CAAA,SAAGD,EAAAA,SAAS,EAV8B,CAC/C,aACA,aACA,cACA,UACA,aAAc,CAAC,CAAC,EAChB,sBACA,YACD,CAE4C,CAAI,CAAA"}
|
|
1
|
+
{"version":3,"file":"MarkdownRenderer.cjs","names":["compiler","useMarkdownContext"],"sources":["../../../src/markdown/MarkdownRenderer.tsx"],"sourcesContent":["'use client';\n\nimport type { FC, HTMLAttributes, JSX, ReactNode } from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\nimport {\n type MarkdownProviderOptions,\n useMarkdownContext,\n} from './MarkdownProvider';\nimport { compiler, type MarkdownRendererOptions } from './processor';\n\n/**\n * Props for rendering markdown content.\n *\n * @example\n * ```tsx\n * const props: RenderMarkdownProps = {\n * components: {\n * h1: ({ children }) => <h1 className=\"text-3xl\">{children}</h1>,\n * p: ({ children }) => <p className=\"text-gray-700\">{children}</p>,\n * },\n * wrapper: ({ children }) => <article>{children}</article>,\n * options: {\n * forceBlock: true,\n * preserveFrontmatter: false,\n * tagfilter: true,\n * },\n * };\n * ```\n */\nexport type RenderMarkdownProps = MarkdownProviderOptions & {\n /**\n * Component overrides for HTML tags.\n * Allows you to customize how specific HTML elements are rendered.\n * Only used if not wrapped in a MarkdownProvider.\n *\n * @example\n * ```tsx\n * components={{\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * a: ({ href, children }) => <Link to={href}>{children}</Link>,\n * }}\n * ```\n */\n components?: HTMLComponents<'permissive', {}>;\n /**\n * Wrapper element or component to be used when there are multiple children.\n * Only used if not wrapped in a MarkdownProvider.\n *\n * @example\n * ```tsx\n * wrapper={({ children }) => <div className=\"markdown-content\">{children}</div>}\n * ```\n */\n wrapper?: FC<HTMLAttributes<HTMLElement>>;\n};\n\n/**\n * Renders markdown content to JSX with the provided components and options.\n *\n * This function does not use context from MarkdownProvider. Use `useMarkdownRenderer`\n * hook if you want to leverage provider context.\n *\n * @param content - The markdown string to render\n * @param props - Configuration options for rendering\n * @param props.components - Component overrides for HTML tags\n * @param props.wrapper - Wrapper component for multiple children\n * @returns JSX element representing the rendered markdown\n *\n * @example\n * ```tsx\n * import { renderMarkdown } from '@intlayer/react-intlayer/markdown';\n *\n * const markdown = '# Hello World\\n\\nThis is **bold** text.';\n * const jsx = renderMarkdown(markdown, {\n * components: {\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * },\n * forceBlock: true,\n * });\n * ```\n */\nexport const renderMarkdown = (\n content: string,\n {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n }: RenderMarkdownProps = {}\n): JSX.Element => {\n // Map public options to internal processor options\n const internalOptions: MarkdownRendererOptions = {\n components,\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return compiler(content, internalOptions);\n};\n\n/**\n * Hook that returns a function to render markdown content.\n *\n * This hook considers the configuration from the `MarkdownProvider` context if available,\n * falling back to the provided props or default behavior.\n *\n * @param props - Optional configuration that will override context values\n * @param props.components - Component overrides for HTML tags (overrides context)\n * @param props.wrapper - Wrapper component (overrides context)\n * @returns A function that takes markdown content and returns JSX\n *\n * @example\n * ```tsx\n * import { useMarkdownRenderer } from '@intlayer/react-intlayer/markdown';\n *\n * function MyComponent() {\n * const renderMarkdown = useMarkdownRenderer({\n * components: {\n * h1: ({ children }) => <h1 className=\"custom\">{children}</h1>,\n * },\n * });\n *\n * return (\n * <div>\n * {renderMarkdown('# Hello\\n\\nThis is **markdown**')}\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With MarkdownProvider context\n * function App() {\n * return (\n * <MarkdownProvider\n * components={{ h1: CustomHeading }}\n * forceBlock={true}\n * >\n * <MyComponent />\n * </MarkdownProvider>\n * );\n * }\n * ```\n */\nexport const useMarkdownRenderer = ({\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n}: RenderMarkdownProps = {}) => {\n const context = useMarkdownContext();\n\n return (content: string) => {\n if (context) {\n return context.renderMarkdown(\n content,\n {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n },\n components,\n wrapper\n );\n }\n\n return renderMarkdown(content, {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n });\n };\n};\n\n/**\n * Props for the MarkdownRenderer component.\n *\n * @example\n * ```tsx\n * const props: MarkdownRendererProps = {\n * children: '# Hello World\\n\\nThis is **bold** text.',\n * components: {\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * },\n * wrapper: ({ children }) => <article>{children}</article>,\n * forceBlock: true,\n * };\n * ```\n */\nexport type MarkdownRendererProps = RenderMarkdownProps & {\n /**\n * The markdown content to render as a string.\n *\n * @example\n * ```tsx\n * <MarkdownRenderer>\n * {`# Title\\n\\nParagraph with **bold** text.`}\n * </MarkdownRenderer>\n * ```\n */\n children: string;\n /**\n * Custom render function for markdown.\n * If provided, it will overwrite context and default rendering.\n *\n * @param markdown - The markdown string to render\n * @param options - Optional rendering options\n * @returns React node representing the rendered markdown\n *\n * @example\n * ```tsx\n * <MarkdownRenderer\n * renderMarkdown={(md, opts) => {\n * // Custom rendering logic\n * return <div dangerouslySetInnerHTML={{ __html: customParser(md) }} />;\n * }}\n * >\n * {markdownContent}\n * </MarkdownRenderer>\n * ```\n */\n renderMarkdown?: (\n markdown: string,\n options?: {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: FC;\n forceBlock?: boolean;\n forceInline?: boolean;\n preserveFrontmatter?: boolean;\n tagfilter?: boolean;\n }\n ) => ReactNode;\n};\n\n/**\n * React component that renders markdown content to JSX.\n *\n * This component uses the `renderMarkdown` function from the `MarkdownProvider` context\n * if available. Otherwise, it falls back to the default compiler with provided components\n * and options. You can also provide a custom `renderMarkdown` function prop to override\n * all rendering behavior.\n *\n * @example\n * ```tsx\n * import { MarkdownRenderer } from '@intlayer/react-intlayer/markdown';\n *\n * function MyComponent() {\n * return (\n * <MarkdownRenderer>\n * {`# Hello World\n *\n * This is a paragraph with **bold** and *italic* text.\n *\n * - List item 1\n * - List item 2`}\n * </MarkdownRenderer>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom components\n * <MarkdownRenderer\n * components={{\n * h1: ({ children }) => <h1 className=\"text-4xl font-bold\">{children}</h1>,\n * a: ({ href, children }) => (\n * <a href={href} className=\"text-blue-500 hover:underline\">\n * {children}\n * </a>\n * ),\n * }}\n * forceBlock={true}\n * >\n * {markdownContent}\n * </MarkdownRenderer>\n * ```\n *\n * @example\n * ```tsx\n * // With MarkdownProvider context\n * function App() {\n * return (\n * <MarkdownProvider\n * components={{ h1: CustomHeading }}\n * forceBlock={true}\n * >\n * <MarkdownRenderer>\n * {markdownContent}\n * </MarkdownRenderer>\n * </MarkdownProvider>\n * );\n * }\n * ```\n */\nexport const MarkdownRenderer: FC<MarkdownRendererProps> = ({\n children = '',\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n renderMarkdown,\n}) => {\n const context = useMarkdownContext();\n\n if (renderMarkdown) {\n return (\n <>\n {renderMarkdown(children, {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n })}\n </>\n );\n }\n\n if (context) {\n return (\n <>\n {context.renderMarkdown(\n children,\n {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n },\n components,\n wrapper\n )}\n </>\n );\n }\n\n // Map public options to internal processor options\n const internalOptions: MarkdownRendererOptions = {\n components,\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return <>{compiler(children, internalOptions)}</>;\n};\n"],"mappings":"uOAiFA,MAAa,GACX,EACA,CACE,aACA,UACA,aACA,cACA,sBACA,aACuB,EAAE,GAapBA,EAAAA,SAAS,EAViC,CAC/C,aACA,aACA,cACA,UACA,aAAc,CAAC,CAAC,EAChB,sBACA,YACD,CAEwC,CAgD9B,GAAuB,CAClC,aACA,UACA,aACA,cACA,sBACA,aACuB,EAAE,GAAK,CAC9B,IAAM,EAAUC,EAAAA,oBAAoB,CAEpC,MAAQ,IACF,EACK,EAAQ,eACb,EACA,CACE,aACA,cACA,sBACA,YACD,CACD,EACA,EACD,CAGI,EAAe,EAAS,CAC7B,aACA,UACA,aACA,cACA,sBACA,YACD,CAAC,EA6HO,GAA+C,CAC1D,WAAW,GACX,aACA,UACA,aACA,cACA,sBACA,YACA,oBACI,CACJ,IAAM,EAAUA,EAAAA,oBAAoB,CA8CpC,OA5CI,GAEA,EAAA,EAAA,KAAA,EAAA,SAAA,CAAA,SACG,EAAe,EAAU,CACxB,aACA,UACA,aACA,cACA,sBACA,YACD,CAAC,CACD,CAAA,CAIH,GAEA,EAAA,EAAA,KAAA,EAAA,SAAA,CAAA,SACG,EAAQ,eACP,EACA,CACE,aACA,cACA,sBACA,YACD,CACD,EACA,EACD,CACA,CAAA,EAeA,EAAA,EAAA,KAAA,EAAA,SAAA,CAAA,SAAGD,EAAAA,SAAS,EAV8B,CAC/C,aACA,aACA,cACA,UACA,aAAc,CAAC,CAAC,EAChB,sBACA,YACD,CAE4C,CAAI,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./MarkdownProvider.cjs`),t=t=>{let{children:n,options:r,components:i}=t,a=e.useMarkdownContext();return(a?.renderMarkdown??(e=>e))(n,r,{...a?.components??{},...i??{}})};exports.MarkdownRendererPlugin=t;
|
|
2
2
|
//# sourceMappingURL=MarkdownRendererPlugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRendererPlugin.cjs","names":["useMarkdownContext"
|
|
1
|
+
{"version":3,"file":"MarkdownRendererPlugin.cjs","names":["useMarkdownContext"],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { FC, ReactNode } from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\nimport {\n type MarkdownProviderOptions,\n useMarkdownContext,\n} from './MarkdownProvider';\n\ntype MarkdownRendererPluginProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: LocalesValues;\n children: string;\n options?: MarkdownProviderOptions;\n components?: HTMLComponents<'permissive', {}>;\n};\n\nexport const MarkdownRendererPlugin: FC<MarkdownRendererPluginProps> = (\n props\n): ReactNode => {\n const { children, options, components } = props;\n const context = useMarkdownContext();\n const renderMarkdown = context?.renderMarkdown ?? ((md) => md);\n const contentToRender = children;\n\n return renderMarkdown(contentToRender, options, {\n ...(context?.components ?? {}),\n ...(components ?? {}),\n });\n};\n"],"mappings":"0HAoBa,EACX,GACc,CACd,GAAM,CAAE,WAAU,UAAS,cAAe,EACpC,EAAUA,EAAAA,oBAAoB,CAIpC,OAHuB,GAAS,iBAAoB,GAAO,IACnC,EAEe,EAAS,CAC9C,GAAI,GAAS,YAAc,EAAE,CAC7B,GAAI,GAAc,EAAE,CACrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./processor.cjs`),t=require(`./MarkdownProvider.cjs`),n=require(`./MarkdownRenderer.cjs`),r=require(`./MarkdownRendererPlugin.cjs`),i=require(`./runtime.cjs`);let a=require(`@intlayer/core/markdown`);exports.LegacyMarkdownRenderer=e.LegacyMarkdownRenderer,exports.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./processor.cjs`),t=require(`./MarkdownProvider.cjs`),n=require(`./MarkdownRenderer.cjs`),r=require(`./MarkdownRendererPlugin.cjs`),i=require(`./runtime.cjs`);let a=require(`@intlayer/core/markdown`);exports.LegacyMarkdownRenderer=e.LegacyMarkdownRenderer,exports.MarkdownProvider=t.MarkdownProvider,exports.MarkdownRenderer=n.MarkdownRenderer,exports.MarkdownRendererPlugin=r.MarkdownRendererPlugin,exports.RuleType=a.RuleType,exports.compile=e.compile,exports.compileMarkdown=e.compileMarkdown,exports.compiler=e.compiler,exports.createReactRuntime=i.createReactRuntime,exports.reactRuntime=i,exports.renderMarkdown=n.renderMarkdown,exports.sanitizer=a.sanitizer,exports.slugify=a.slugify,exports.useMarkdownContext=t.useMarkdownContext,exports.useMarkdownRenderer=n.useMarkdownRenderer;
|
package/dist/cjs/plugins.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./editor/ContentSelector.cjs`),n=require(`./html/HTMLRendererPlugin.cjs`),r=require(`./IntlayerNode.cjs`),i=require(`./markdown/MarkdownRendererPlugin.cjs`),a=require(`./reactElement/renderReactElement.cjs`);let o=require(`@intlayer/config/built`);o=e.__toESM(o);let s=require(`@intlayer/core/interpreter`),c=require(`@intlayer/core/markdown`),l=require(`@intlayer/types/nodeType`),u=require(`react`),d=require(`react/jsx-runtime`);const f={id:`intlayer-node-plugin`,canHandle:e=>typeof e==`bigint`||typeof e==`string`||typeof e==`number`,transform:(e,{plugins:n,...i})=>r.renderIntlayerNode({...i,value:i.children,children:o.default?.editor.enabled?(0,d.jsx)(t.ContentSelector,{...i,children:i.children}):i.children})},p={id:`react-node-plugin`,canHandle:e=>typeof e==`object`&&e?.props!==void 0&&e.key!==void 0,transform:(e,{plugins:n,...i})=>r.renderIntlayerNode({...i,value:`[[react-element]]`,children:o.default?.editor.enabled?(0,d.jsx)(t.ContentSelector,{...i,children:a.renderReactElement(e)}):a.renderReactElement(e)})},m=(e,t)=>{let n=(0,s.splitInsertionTemplate)(e,t);return n.isSimple?n.parts:(0,u.createElement)(u.Fragment,null,...n.parts.map((e,t)=>(0,u.createElement)(u.Fragment,{key:t},e)))},h={id:`insertion-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===l.NodeType.Insertion,transform:(e,t,n)=>{let r=[...t.keyPath,{type:l.NodeType.Insertion}],i=e[l.NodeType.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=m(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&&[l.NodeType.Enumeration,l.NodeType.Condition].includes(i.nodeType)?e=>t=>{let n=o(t);return typeof n==`function`?n(e):n}:o}},g={id:`markdown-string-plugin`,canHandle:e=>typeof e==`string`,transform:(e,n,a)=>{let{plugins:
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./editor/ContentSelector.cjs`),n=require(`./html/HTMLRendererPlugin.cjs`),r=require(`./IntlayerNode.cjs`),i=require(`./markdown/MarkdownRendererPlugin.cjs`),a=require(`./reactElement/renderReactElement.cjs`);let o=require(`@intlayer/config/built`);o=e.__toESM(o);let s=require(`@intlayer/core/interpreter`),c=require(`@intlayer/core/markdown`),l=require(`@intlayer/types/nodeType`),u=require(`react`),d=require(`react/jsx-runtime`);const f={id:`intlayer-node-plugin`,canHandle:e=>typeof e==`bigint`||typeof e==`string`||typeof e==`number`,transform:(e,{plugins:n,...i})=>r.renderIntlayerNode({...i,value:i.children,children:o.default?.editor.enabled?(0,d.jsx)(t.ContentSelector,{...i,children:i.children}):i.children})},p={id:`react-node-plugin`,canHandle:e=>typeof e==`object`&&e?.props!==void 0&&e.key!==void 0,transform:(e,{plugins:n,...i})=>r.renderIntlayerNode({...i,value:`[[react-element]]`,children:o.default?.editor.enabled?(0,d.jsx)(t.ContentSelector,{...i,children:a.renderReactElement(e)}):a.renderReactElement(e)})},m=(e,t)=>{let n=(0,s.splitInsertionTemplate)(e,t);return n.isSimple?n.parts:(0,u.createElement)(u.Fragment,null,...n.parts.map((e,t)=>(0,u.createElement)(u.Fragment,{key:t},e)))},h={id:`insertion-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===l.NodeType.Insertion,transform:(e,t,n)=>{let r=[...t.keyPath,{type:l.NodeType.Insertion}],i=e[l.NodeType.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=m(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&&[l.NodeType.Enumeration,l.NodeType.Condition].includes(i.nodeType)?e=>t=>{let n=o(t);return typeof n==`function`?n(e):n}:o}},g={id:`markdown-string-plugin`,canHandle:e=>typeof e==`string`,transform:(e,n,a)=>{let{plugins:s,...l}=n,u=a((0,c.getMarkdownMetadata)(e),{plugins:[{id:`markdown-metadata-plugin`,canHandle:e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`||!e,transform:(n,i)=>r.renderIntlayerNode({...i,value:n,children:o.default?.editor.enabled?(0,d.jsx)(t.ContentSelector,{...l,children:e}):e})}],dictionaryKey:l.dictionaryKey,keyPath:[]}),f=a=>r.renderIntlayerNode({...n,value:e,children:o.default.editor.enabled?(0,d.jsx)(t.ContentSelector,{...l,children:(0,d.jsx)(i.MarkdownRendererPlugin,{...l,components:a,children:e})}):(0,d.jsx)(i.MarkdownRendererPlugin,{...l,components:a,children:e}),additionalProps:{metadata:u}}),p=f();return new Proxy(p,{get(t,n,r){return n===`value`?e:n===`metadata`?u:n===`use`?e=>f(e):Reflect.get(t,n,r)}})}},_={id:`markdown-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===l.NodeType.Markdown,transform:(e,t,n)=>{let r=[...t.keyPath,{type:l.NodeType.Markdown}],i=e[l.NodeType.Markdown];return n(i,{...t,children:i,keyPath:r,plugins:[g,...t.plugins??[]]})}},v={id:`html-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===l.NodeType.HTML,transform:(e,t)=>{let r=e[l.NodeType.HTML],{plugins:i,...a}=t,o=e=>(0,u.createElement)(n.HTMLRendererPlugin,{...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)}})}},y=(e,t=!0)=>[(0,s.translationPlugin)(e??o.default.internationalization.defaultLocale,t?o.default.internationalization.defaultLocale:void 0),s.enumerationPlugin,s.conditionPlugin,(0,s.nestedPlugin)(e??o.default.internationalization.defaultLocale),s.filePlugin,s.genderPlugin,f,p,h,_,v];exports.getPlugins=y,exports.htmlPlugin=v,exports.insertionPlugin=h,exports.intlayerNodePlugins=f,exports.markdownPlugin=_,exports.markdownStringPlugin=g,exports.reactNodePlugins=p;
|
|
2
2
|
//# sourceMappingURL=plugins.cjs.map
|
package/dist/cjs/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["renderIntlayerNode","configuration","ContentSelector","renderReactElement","Fragment","NodeType","MarkdownMetadataRenderer","MarkdownRendererPlugin","HTMLRendererPlugin","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"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 { MarkdownMetadataRenderer, MarkdownRendererPlugin } from './markdown';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (\n _node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: rest.children,\n children: 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: (\n <ContentSelector {...rest}>\n <MarkdownMetadataRenderer\n {...rest}\n metadataKeyPath={props.keyPath}\n >\n {node}\n </MarkdownMetadataRenderer>\n </ContentSelector>\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: (\n <ContentSelector {...rest}>\n <MarkdownRendererPlugin {...rest} components={components}>\n {node}\n </MarkdownRendererPlugin>\n </ContentSelector>\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.cjs","names":["renderIntlayerNode","configuration","ContentSelector","renderReactElement","Fragment","NodeType","MarkdownRendererPlugin","HTMLRendererPlugin","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntl.cjs","names":["getServerContext","IntlayerServerContext","configuration"],"sources":["../../../../src/server/format/useIntl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { bindIntl } 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 locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return bindIntl(\n locale ??\n currentLocale ??\n configuration?.internationalization?.defaultLocale\n );\n};\n"],"mappings":"0SAkCA,MAAa,EAAW,
|
|
1
|
+
{"version":3,"file":"useIntl.cjs","names":["getServerContext","IntlayerServerContext","configuration"],"sources":["../../../../src/server/format/useIntl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { bindIntl, type WrappedIntl } 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 locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues): WrappedIntl => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return bindIntl(\n locale ??\n currentLocale ??\n configuration?.internationalization?.defaultLocale\n );\n};\n"],"mappings":"0SAkCA,MAAa,EAAW,GAAwC,CAC9D,IAAM,EAAgBA,EAAAA,iBAAgCC,EAAAA,sBAAsB,CAE5E,OAAA,EAAA,EAAA,UACE,GACE,GACAC,EAAAA,SAAe,sBAAsB,cACxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["getDictionary","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["getDictionary","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"sLAca,GAIX,EACA,EACA,IAOOA,EAAAA,cAAoB,EAJzB,GACAC,EAAAA,iBAAgCC,EAAAA,sBAAsB,EACtD,EAEuD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.cjs","names":["getServerContext","IntlayerServerContext","configuration","useDictionary"],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.cjs","names":["getServerContext","IntlayerServerContext","configuration","useDictionary"],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = await (dictionaryPromise as any)[localeTarget]?.();\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"2RAgBA,MAAa,EAAqB,MAIhC,EACA,EACA,IACG,CACH,IAAM,EACJ,GACAA,EAAAA,iBAAgCC,EAAAA,sBAAsB,EACtD,GACAC,EAAAA,SAAe,qBAAqB,cAItC,OAAOC,EAAAA,cAFY,MAAO,EAA0B,MAAiB,CAE9B,EAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["getServerContext","IntlayerServerContext","configuration","useDictionary","useLoadDynamic"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["getServerContext","IntlayerServerContext","configuration","useDictionary","useLoadDynamic"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: string,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"6TAiBA,MAAa,GAIX,EACA,EACA,EACA,IACG,CACH,IAAM,EACJ,GACAA,EAAAA,iBAAgCC,EAAAA,sBAAsB,EACtD,GACAC,EAAAA,SAAe,qBAAqB,cAOtC,OAAOC,EAAAA,cALYC,EAAAA,eACjB,GAAG,OAAO,EAAI,CAAC,GAAG,IACjB,EAA0B,MAAiB,CAC7C,CAEsC,EAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["'use client';\n\nimport { bindIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":"kLAmCA,MAAa,EAAW,GAA2B,CACjD,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAC7D,EAAgB,GAAU,EAEhC,OAAO,
|
|
1
|
+
{"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["'use client';\n\nimport { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo<WrappedIntl>(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":"kLAmCA,MAAa,EAAW,GAA2B,CACjD,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAC7D,EAAgB,GAAU,EAEhC,OAAO,MAA2B,EAAS,EAAc,CAAE,CAAC,EAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () =>\n (await dictionaryPromise[\n localeTarget as keyof typeof dictionaryPromise\n ]?.()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L) as any;\n};\n"],"mappings":"sNAkBA,MAAa,EAAqB,MAIhC,EACA,IACe,CACf,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAE7D,EAAe,MAEjB,GACA,GACA,GAAe,qBAAqB,cACtC,CAAC,EAAe,EAAO,CACxB,CAUD,OAAO,EARY,MAAM,EACvB,SACG,MAAM,EACL,MACG,CACP,CAAC,EAAmB,EAAa,CAClC,CAEsC,EAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":"4QAmBA,MAAa,GAIX,EACA,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAC7D,EAAe,MAEjB,GACA,GACA,GAAe,qBAAqB,cACtC,CAAC,EAAe,EAAO,CACxB,CAOD,OAAO,EALY,EACjB,GAAG,OAAO,EAAI,CAAC,GAAG,IACjB,EAA0B,MAAiB,CAC7C,CAEgC,EAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useI18n.mjs","names":[],"sources":["../../../src/client/useI18n.ts"],"sourcesContent":["'use client';\n\nimport { getIntlayer } from '@intlayer/core/interpreter';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type {
|
|
1
|
+
{"version":3,"file":"useI18n.mjs","names":[],"sources":["../../../src/client/useI18n.ts"],"sourcesContent":["'use client';\n\nimport { getIntlayer } from '@intlayer/core/interpreter';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { GetSubPath } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Hook that provides a translation function `t()` for accessing nested content by key.\n * This hook mimics the pattern found in libraries like i18next, next-intl, and vue-i18n.\n *\n * @param namespace - The dictionary key to scope translations to\n * @param locale - Optional locale override. If not provided, uses the current context locale\n * @returns A translation function `t(key)` that returns the translated content for the given key\n *\n * @example\n * ```tsx\n * const t = useI18n('IndexPage');\n * const title = t('title'); // Returns translated string for 'IndexPage.title'\n * const nestedContent = t('section.subtitle'); // Returns 'IndexPage.section.subtitle'\n * // For attributes like `aria-label`, use `.value` to get the plain string\n * const ariaLabel = t('button.ariaLabel').value; // 'Close modal'\n * ```\n */\nexport const useI18n = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n namespace: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n // Get the dictionary content for the namespace\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const dictionaryContent: DeepTransformContent<DictionaryRegistryContent<T>> =\n useMemo(\n () => getIntlayer<T, L>(namespace, localeTarget as L),\n [namespace, localeTarget]\n );\n\n // Return the translation function\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const t = <P extends ValidDotPathsFor<T>>(\n path: P\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n ): GetSubPath<DeepTransformContent<DictionaryRegistryContent<T>>, P> => {\n if (!path) {\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return dictionaryContent as any;\n }\n\n const pathArray = (path as string).split('.');\n let current: any = dictionaryContent;\n\n for (const key of pathArray) {\n current = current?.[key];\n if (current === undefined) {\n // Return the whole dictionary as fallback if path is not found\n return dictionaryContent as any;\n }\n }\n\n return current;\n };\n\n return t;\n};\n"],"mappings":"qLAgCA,MAAa,GAIX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAC7D,EAAe,MACb,GAAU,EAChB,CAAC,EAAe,EAAO,CACxB,CAIK,EACJ,MACQ,EAAkB,EAAW,EAAkB,CACrD,CAAC,EAAW,EAAa,CAC1B,CA2BH,MAtBE,IAEsE,CACtE,GAAI,CAAC,EAEH,OAAO,EAGT,IAAM,EAAa,EAAgB,MAAM,IAAI,CACzC,EAAe,EAEnB,IAAK,IAAM,KAAO,EAEhB,GADA,EAAU,IAAU,GAChB,IAAY,IAAA,GAEd,OAAO,EAIX,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that picks one dictionary by its key and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The dictionary content for the specified locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? (currentLocale as L);\n\n return getIntlayer<T, L>(key, localeTarget);\n }, [key, currentLocale, locale]);\n};\n"],"mappings":"6KA+BA,MAAa,GAIX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAEnE,OAAO,MAGE,EAAkB,EAFJ,GAAW,EAEW,CAC1C,CAAC,EAAK,EAAe,EAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRewriteURL.mjs","names":[],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport { useEffect } from 'react';\nimport { useLocale } from './useLocale';\n\n/**\n * Client-side hook to manage URL rewrites without triggering a router navigation.\n * It uses `window.history.replaceState` to update the URL in the address bar.\n *\n * This hook is useful to \"prettify\" the URL when the user lands on a canonical path\n * that has a localized alias defined in `intlayer.config.ts`.\n *\n * @example\n * ```tsx\n * import { useRewriteURL } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * useRewriteURL();\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport const useRewriteURL = (): void => {\n const { locale } = useLocale();\n const rewrite = configuration?.routing?.rewrite;\n\n useEffect(() => {\n if (typeof window === 'undefined' || !rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(pathname, locale, rewrite);\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n }, [locale, rewrite]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRewriteURL.mjs","names":[],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useEffect } from 'react';\nimport { useLocale } from './useLocale';\n\n/**\n * Client-side hook to manage URL rewrites without triggering a router navigation.\n * It uses `window.history.replaceState` to update the URL in the address bar.\n *\n * This hook is useful to \"prettify\" the URL when the user lands on a canonical path\n * that has a localized alias defined in `intlayer.config.ts`.\n *\n * @example\n * ```tsx\n * import { useRewriteURL } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * useRewriteURL();\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport const useRewriteURL = (): void => {\n const { locale } = useLocale();\n const rewrite = configuration?.routing?.rewrite;\n\n useEffect(() => {\n if (typeof window === 'undefined' || !rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(pathname, locale as Locale, rewrite);\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n }, [locale, rewrite]);\n};\n"],"mappings":"8LA0BA,MAAa,MAA4B,CACvC,GAAM,CAAE,UAAW,GAAW,CACxB,EAAU,GAAe,SAAS,QAExC,MAAgB,CACd,GAAI,OAAO,OAAW,KAAe,CAAC,EAAS,OAE/C,IAAM,EAAW,OAAO,SAAS,SAC3B,EAAa,EAAe,EAAU,EAAkB,EAAQ,CAElE,GAAc,IAAe,GAC/B,OAAO,QAAQ,aACb,OAAO,QAAQ,MACf,GACA,EAAa,OAAO,SAAS,OAAS,OAAO,SAAS,KACvD,EAEF,CAAC,EAAQ,EAAQ,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{IntlayerClientContext as e}from"../client/IntlayerProvider.mjs";import{useContext as t,useEffect as n,useRef as r}from"react";import{isEnabled as i}from"@intlayer/editor/isEnabled";const a=()=>{let{locale:a}=t(e),o=r(null);n(()=>{if(i)return import(`@intlayer/editor`).then(({initEditorClient:e})=>{let t=e();o.current=t,a&&t.currentLocale.set(a)}),()=>{o.current=null,import(`@intlayer/editor`).then(({stopEditorClient:e})=>{e()})}},[]),n(()=>{!a||!o.current||o.current.currentLocale.set(a)},[a])};export{a as useEditor};
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"../client/IntlayerProvider.mjs";import{useContext as t,useEffect as n,useRef as r}from"react";import{isEnabled as i}from"@intlayer/editor/isEnabled";const a=()=>{let{locale:a}=t(e),o=r(null);n(()=>{if(!(process.env.INTLAYER_EDITOR_ENABLED===`false`||!i))return import(`@intlayer/editor`).then(({initEditorClient:e})=>{let t=e();o.current=t,a&&t.currentLocale.set(a)}),()=>{o.current=null,import(`@intlayer/editor`).then(({stopEditorClient:e})=>{e()})}},[]),n(()=>{!a||!o.current||o.current.currentLocale.set(a)},[a])};export{a as useEditor};
|
|
2
2
|
//# sourceMappingURL=useEditor.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.mjs","names":[],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'react';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initializes the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale } = useContext(IntlayerClientContext);\n const managerRef = useRef<EditorStateManager | null>(null);\n\n useEffect(() => {\n if (!isEnabled) return;\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n });\n\n return () => {\n managerRef.current = null;\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n };\n }, []);\n\n useEffect(() => {\n if (!locale || !managerRef.current) return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":"yMAaA,MAAa,MAAkB,CAC7B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAC9C,EAAa,EAAkC,KAAK,CAE1D,MAAgB,
|
|
1
|
+
{"version":3,"file":"useEditor.mjs","names":[],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'react';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initializes the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale } = useContext(IntlayerClientContext);\n const managerRef = useRef<EditorStateManager | null>(null);\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n });\n\n return () => {\n managerRef.current = null;\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n };\n }, []);\n\n useEffect(() => {\n if (!locale || !managerRef.current) return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":"yMAaA,MAAa,MAAkB,CAC7B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAC9C,EAAa,EAAkC,KAAK,CAE1D,MAAgB,CACV,aAAQ,IAAI,0BAA4B,SAAW,CAAC,GASxD,OAPA,OAAO,oBAAoB,MAAM,CAAE,sBAAuB,CACxD,IAAM,EAAU,GAAkB,CAClC,EAAW,QAAU,EAEjB,GAAQ,EAAQ,cAAc,IAAI,EAAiB,EACvD,KAEW,CACX,EAAW,QAAU,KACrB,OAAO,oBAAoB,MAAM,CAAE,sBAAuB,CACxD,GAAkB,EAClB,GAEH,EAAE,CAAC,CAEN,MAAgB,CACV,CAAC,GAAU,CAAC,EAAW,SAE3B,EAAW,QAAQ,cAAc,IAAI,EAAiB,EACrD,CAAC,EAAO,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{compiler as e}from"./processor.mjs";import{useMarkdownContext as t}from"./MarkdownProvider.mjs";import{Fragment as n,jsx as r}from"react/jsx-runtime";const i=(t,{components:n,wrapper:r,forceBlock:i,forceInline:a,preserveFrontmatter:o,tagfilter:s}={})=>e(t,{components:n,forceBlock:i,forceInline:a,wrapper:r,forceWrapper:!!r,preserveFrontmatter:o,tagfilter:s}),a=({components:e,wrapper:n,forceBlock:r,forceInline:a,preserveFrontmatter:o,tagfilter:s}={})=>{let c=t();return t=>c?c.renderMarkdown(t,{forceBlock:r,forceInline:a,preserveFrontmatter:o,tagfilter:s},e,n):i(t,{components:e,wrapper:n,forceBlock:r,forceInline:a,preserveFrontmatter:o,tagfilter:s})},o=({children:i=``,components:a,wrapper:o,forceBlock:s,forceInline:c,preserveFrontmatter:l,tagfilter:u,renderMarkdown:d})=>{let f=t();return d?r(n,{children:d(i,{components:a,wrapper:o,forceBlock:s,forceInline:c,preserveFrontmatter:l,tagfilter:u})}):f?r(n,{children:f.renderMarkdown(i,{forceBlock:s,forceInline:c,preserveFrontmatter:l,tagfilter:u},a,o)}):r(n,{children:e(i,{components:a,forceBlock:s,forceInline:c,wrapper:o,forceWrapper:!!o,preserveFrontmatter:l,tagfilter:u})})};export{o as MarkdownRenderer,i as renderMarkdown,a as useMarkdownRenderer};
|
|
1
|
+
"use client";import{compiler as e}from"./processor.mjs";import{useMarkdownContext as t}from"./MarkdownProvider.mjs";import{Fragment as n,jsx as r}from"react/jsx-runtime";const i=(t,{components:n,wrapper:r,forceBlock:i,forceInline:a,preserveFrontmatter:o,tagfilter:s}={})=>e(t,{components:n,forceBlock:i,forceInline:a,wrapper:r,forceWrapper:!!r,preserveFrontmatter:o,tagfilter:s}),a=({components:e,wrapper:n,forceBlock:r,forceInline:a,preserveFrontmatter:o,tagfilter:s}={})=>{let c=t();return t=>c?c.renderMarkdown(t,{forceBlock:r,forceInline:a,preserveFrontmatter:o,tagfilter:s},e,n):i(t,{components:e,wrapper:n,forceBlock:r,forceInline:a,preserveFrontmatter:o,tagfilter:s})},o=({children:i=``,components:a,wrapper:o,forceBlock:s,forceInline:c,preserveFrontmatter:l,tagfilter:u,renderMarkdown:d})=>{let f=t();return d?r(n,{children:d(i,{components:a,wrapper:o,forceBlock:s,forceInline:c,preserveFrontmatter:l,tagfilter:u})}):f?r(n,{children:f.renderMarkdown(i,{forceBlock:s,forceInline:c,preserveFrontmatter:l,tagfilter:u},a,o)}):r(n,{children:e(i,{components:a,forceBlock:s,forceInline:c,wrapper:o,forceWrapper:!!o,preserveFrontmatter:l,tagfilter:u})})};export{o as MarkdownRenderer,i as renderMarkdown,a as useMarkdownRenderer};
|
|
2
2
|
//# sourceMappingURL=MarkdownRenderer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRenderer.mjs","names":[],"sources":["../../../src/markdown/MarkdownRenderer.tsx"],"sourcesContent":["import type { FC, HTMLAttributes, JSX, ReactNode } from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\nimport {\n type MarkdownProviderOptions,\n useMarkdownContext,\n} from './MarkdownProvider';\nimport { compiler, type MarkdownRendererOptions } from './processor';\n\n/**\n * Props for rendering markdown content.\n *\n * @example\n * ```tsx\n * const props: RenderMarkdownProps = {\n * components: {\n * h1: ({ children }) => <h1 className=\"text-3xl\">{children}</h1>,\n * p: ({ children }) => <p className=\"text-gray-700\">{children}</p>,\n * },\n * wrapper: ({ children }) => <article>{children}</article>,\n * options: {\n * forceBlock: true,\n * preserveFrontmatter: false,\n * tagfilter: true,\n * },\n * };\n * ```\n */\nexport type RenderMarkdownProps = MarkdownProviderOptions & {\n /**\n * Component overrides for HTML tags.\n * Allows you to customize how specific HTML elements are rendered.\n * Only used if not wrapped in a MarkdownProvider.\n *\n * @example\n * ```tsx\n * components={{\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * a: ({ href, children }) => <Link to={href}>{children}</Link>,\n * }}\n * ```\n */\n components?: HTMLComponents<'permissive', {}>;\n /**\n * Wrapper element or component to be used when there are multiple children.\n * Only used if not wrapped in a MarkdownProvider.\n *\n * @example\n * ```tsx\n * wrapper={({ children }) => <div className=\"markdown-content\">{children}</div>}\n * ```\n */\n wrapper?: FC<HTMLAttributes<HTMLElement>>;\n};\n\n/**\n * Renders markdown content to JSX with the provided components and options.\n *\n * This function does not use context from MarkdownProvider. Use `useMarkdownRenderer`\n * hook if you want to leverage provider context.\n *\n * @param content - The markdown string to render\n * @param props - Configuration options for rendering\n * @param props.components - Component overrides for HTML tags\n * @param props.wrapper - Wrapper component for multiple children\n * @returns JSX element representing the rendered markdown\n *\n * @example\n * ```tsx\n * import { renderMarkdown } from '@intlayer/react-intlayer/markdown';\n *\n * const markdown = '# Hello World\\n\\nThis is **bold** text.';\n * const jsx = renderMarkdown(markdown, {\n * components: {\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * },\n * forceBlock: true,\n * });\n * ```\n */\nexport const renderMarkdown = (\n content: string,\n {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n }: RenderMarkdownProps = {}\n): JSX.Element => {\n // Map public options to internal processor options\n const internalOptions: MarkdownRendererOptions = {\n components,\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return compiler(content, internalOptions);\n};\n\n/**\n * Hook that returns a function to render markdown content.\n *\n * This hook considers the configuration from the `MarkdownProvider` context if available,\n * falling back to the provided props or default behavior.\n *\n * @param props - Optional configuration that will override context values\n * @param props.components - Component overrides for HTML tags (overrides context)\n * @param props.wrapper - Wrapper component (overrides context)\n * @returns A function that takes markdown content and returns JSX\n *\n * @example\n * ```tsx\n * import { useMarkdownRenderer } from '@intlayer/react-intlayer/markdown';\n *\n * function MyComponent() {\n * const renderMarkdown = useMarkdownRenderer({\n * components: {\n * h1: ({ children }) => <h1 className=\"custom\">{children}</h1>,\n * },\n * });\n *\n * return (\n * <div>\n * {renderMarkdown('# Hello\\n\\nThis is **markdown**')}\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With MarkdownProvider context\n * function App() {\n * return (\n * <MarkdownProvider\n * components={{ h1: CustomHeading }}\n * forceBlock={true}\n * >\n * <MyComponent />\n * </MarkdownProvider>\n * );\n * }\n * ```\n */\nexport const useMarkdownRenderer = ({\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n}: RenderMarkdownProps = {}) => {\n const context = useMarkdownContext();\n\n return (content: string) => {\n if (context) {\n return context.renderMarkdown(\n content,\n {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n },\n components,\n wrapper\n );\n }\n\n return renderMarkdown(content, {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n });\n };\n};\n\n/**\n * Props for the MarkdownRenderer component.\n *\n * @example\n * ```tsx\n * const props: MarkdownRendererProps = {\n * children: '# Hello World\\n\\nThis is **bold** text.',\n * components: {\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * },\n * wrapper: ({ children }) => <article>{children}</article>,\n * forceBlock: true,\n * };\n * ```\n */\nexport type MarkdownRendererProps = RenderMarkdownProps & {\n /**\n * The markdown content to render as a string.\n *\n * @example\n * ```tsx\n * <MarkdownRenderer>\n * {`# Title\\n\\nParagraph with **bold** text.`}\n * </MarkdownRenderer>\n * ```\n */\n children: string;\n /**\n * Custom render function for markdown.\n * If provided, it will overwrite context and default rendering.\n *\n * @param markdown - The markdown string to render\n * @param options - Optional rendering options\n * @returns React node representing the rendered markdown\n *\n * @example\n * ```tsx\n * <MarkdownRenderer\n * renderMarkdown={(md, opts) => {\n * // Custom rendering logic\n * return <div dangerouslySetInnerHTML={{ __html: customParser(md) }} />;\n * }}\n * >\n * {markdownContent}\n * </MarkdownRenderer>\n * ```\n */\n renderMarkdown?: (\n markdown: string,\n options?: {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: FC;\n forceBlock?: boolean;\n forceInline?: boolean;\n preserveFrontmatter?: boolean;\n tagfilter?: boolean;\n }\n ) => ReactNode;\n};\n\n/**\n * React component that renders markdown content to JSX.\n *\n * This component uses the `renderMarkdown` function from the `MarkdownProvider` context\n * if available. Otherwise, it falls back to the default compiler with provided components\n * and options. You can also provide a custom `renderMarkdown` function prop to override\n * all rendering behavior.\n *\n * @example\n * ```tsx\n * import { MarkdownRenderer } from '@intlayer/react-intlayer/markdown';\n *\n * function MyComponent() {\n * return (\n * <MarkdownRenderer>\n * {`# Hello World\n *\n * This is a paragraph with **bold** and *italic* text.\n *\n * - List item 1\n * - List item 2`}\n * </MarkdownRenderer>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom components\n * <MarkdownRenderer\n * components={{\n * h1: ({ children }) => <h1 className=\"text-4xl font-bold\">{children}</h1>,\n * a: ({ href, children }) => (\n * <a href={href} className=\"text-blue-500 hover:underline\">\n * {children}\n * </a>\n * ),\n * }}\n * forceBlock={true}\n * >\n * {markdownContent}\n * </MarkdownRenderer>\n * ```\n *\n * @example\n * ```tsx\n * // With MarkdownProvider context\n * function App() {\n * return (\n * <MarkdownProvider\n * components={{ h1: CustomHeading }}\n * forceBlock={true}\n * >\n * <MarkdownRenderer>\n * {markdownContent}\n * </MarkdownRenderer>\n * </MarkdownProvider>\n * );\n * }\n * ```\n */\nexport const MarkdownRenderer: FC<MarkdownRendererProps> = ({\n children = '',\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n renderMarkdown,\n}) => {\n const context = useMarkdownContext();\n\n if (renderMarkdown) {\n return (\n <>\n {renderMarkdown(children, {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n })}\n </>\n );\n }\n\n if (context) {\n return (\n <>\n {context.renderMarkdown(\n children,\n {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n },\n components,\n wrapper\n )}\n </>\n );\n }\n\n // Map public options to internal processor options\n const internalOptions: MarkdownRendererOptions = {\n components,\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return <>{compiler(children, internalOptions)}</>;\n};\n"],"mappings":"6JA+EA,MAAa,GACX,EACA,CACE,aACA,UACA,aACA,cACA,sBACA,aACuB,EAAE,GAapB,EAAS,EAViC,CAC/C,aACA,aACA,cACA,UACA,aAAc,CAAC,CAAC,EAChB,sBACA,YACD,CAEwC,CAgD9B,GAAuB,CAClC,aACA,UACA,aACA,cACA,sBACA,aACuB,EAAE,GAAK,CAC9B,IAAM,EAAU,GAAoB,CAEpC,MAAQ,IACF,EACK,EAAQ,eACb,EACA,CACE,aACA,cACA,sBACA,YACD,CACD,EACA,EACD,CAGI,EAAe,EAAS,CAC7B,aACA,UACA,aACA,cACA,sBACA,YACD,CAAC,EA6HO,GAA+C,CAC1D,WAAW,GACX,aACA,UACA,aACA,cACA,sBACA,YACA,oBACI,CACJ,IAAM,EAAU,GAAoB,CA8CpC,OA5CI,EAEA,EAAA,EAAA,CAAA,SACG,EAAe,EAAU,CACxB,aACA,UACA,aACA,cACA,sBACA,YACD,CAAC,CACD,CAAA,CAIH,EAEA,EAAA,EAAA,CAAA,SACG,EAAQ,eACP,EACA,CACE,aACA,cACA,sBACA,YACD,CACD,EACA,EACD,CACA,CAAA,CAeA,EAAA,EAAA,CAAA,SAAG,EAAS,EAV8B,CAC/C,aACA,aACA,cACA,UACA,aAAc,CAAC,CAAC,EAChB,sBACA,YACD,CAE4C,CAAI,CAAA"}
|
|
1
|
+
{"version":3,"file":"MarkdownRenderer.mjs","names":[],"sources":["../../../src/markdown/MarkdownRenderer.tsx"],"sourcesContent":["'use client';\n\nimport type { FC, HTMLAttributes, JSX, ReactNode } from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\nimport {\n type MarkdownProviderOptions,\n useMarkdownContext,\n} from './MarkdownProvider';\nimport { compiler, type MarkdownRendererOptions } from './processor';\n\n/**\n * Props for rendering markdown content.\n *\n * @example\n * ```tsx\n * const props: RenderMarkdownProps = {\n * components: {\n * h1: ({ children }) => <h1 className=\"text-3xl\">{children}</h1>,\n * p: ({ children }) => <p className=\"text-gray-700\">{children}</p>,\n * },\n * wrapper: ({ children }) => <article>{children}</article>,\n * options: {\n * forceBlock: true,\n * preserveFrontmatter: false,\n * tagfilter: true,\n * },\n * };\n * ```\n */\nexport type RenderMarkdownProps = MarkdownProviderOptions & {\n /**\n * Component overrides for HTML tags.\n * Allows you to customize how specific HTML elements are rendered.\n * Only used if not wrapped in a MarkdownProvider.\n *\n * @example\n * ```tsx\n * components={{\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * a: ({ href, children }) => <Link to={href}>{children}</Link>,\n * }}\n * ```\n */\n components?: HTMLComponents<'permissive', {}>;\n /**\n * Wrapper element or component to be used when there are multiple children.\n * Only used if not wrapped in a MarkdownProvider.\n *\n * @example\n * ```tsx\n * wrapper={({ children }) => <div className=\"markdown-content\">{children}</div>}\n * ```\n */\n wrapper?: FC<HTMLAttributes<HTMLElement>>;\n};\n\n/**\n * Renders markdown content to JSX with the provided components and options.\n *\n * This function does not use context from MarkdownProvider. Use `useMarkdownRenderer`\n * hook if you want to leverage provider context.\n *\n * @param content - The markdown string to render\n * @param props - Configuration options for rendering\n * @param props.components - Component overrides for HTML tags\n * @param props.wrapper - Wrapper component for multiple children\n * @returns JSX element representing the rendered markdown\n *\n * @example\n * ```tsx\n * import { renderMarkdown } from '@intlayer/react-intlayer/markdown';\n *\n * const markdown = '# Hello World\\n\\nThis is **bold** text.';\n * const jsx = renderMarkdown(markdown, {\n * components: {\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * },\n * forceBlock: true,\n * });\n * ```\n */\nexport const renderMarkdown = (\n content: string,\n {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n }: RenderMarkdownProps = {}\n): JSX.Element => {\n // Map public options to internal processor options\n const internalOptions: MarkdownRendererOptions = {\n components,\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return compiler(content, internalOptions);\n};\n\n/**\n * Hook that returns a function to render markdown content.\n *\n * This hook considers the configuration from the `MarkdownProvider` context if available,\n * falling back to the provided props or default behavior.\n *\n * @param props - Optional configuration that will override context values\n * @param props.components - Component overrides for HTML tags (overrides context)\n * @param props.wrapper - Wrapper component (overrides context)\n * @returns A function that takes markdown content and returns JSX\n *\n * @example\n * ```tsx\n * import { useMarkdownRenderer } from '@intlayer/react-intlayer/markdown';\n *\n * function MyComponent() {\n * const renderMarkdown = useMarkdownRenderer({\n * components: {\n * h1: ({ children }) => <h1 className=\"custom\">{children}</h1>,\n * },\n * });\n *\n * return (\n * <div>\n * {renderMarkdown('# Hello\\n\\nThis is **markdown**')}\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With MarkdownProvider context\n * function App() {\n * return (\n * <MarkdownProvider\n * components={{ h1: CustomHeading }}\n * forceBlock={true}\n * >\n * <MyComponent />\n * </MarkdownProvider>\n * );\n * }\n * ```\n */\nexport const useMarkdownRenderer = ({\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n}: RenderMarkdownProps = {}) => {\n const context = useMarkdownContext();\n\n return (content: string) => {\n if (context) {\n return context.renderMarkdown(\n content,\n {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n },\n components,\n wrapper\n );\n }\n\n return renderMarkdown(content, {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n });\n };\n};\n\n/**\n * Props for the MarkdownRenderer component.\n *\n * @example\n * ```tsx\n * const props: MarkdownRendererProps = {\n * children: '# Hello World\\n\\nThis is **bold** text.',\n * components: {\n * h1: ({ children }) => <h1 className=\"title\">{children}</h1>,\n * },\n * wrapper: ({ children }) => <article>{children}</article>,\n * forceBlock: true,\n * };\n * ```\n */\nexport type MarkdownRendererProps = RenderMarkdownProps & {\n /**\n * The markdown content to render as a string.\n *\n * @example\n * ```tsx\n * <MarkdownRenderer>\n * {`# Title\\n\\nParagraph with **bold** text.`}\n * </MarkdownRenderer>\n * ```\n */\n children: string;\n /**\n * Custom render function for markdown.\n * If provided, it will overwrite context and default rendering.\n *\n * @param markdown - The markdown string to render\n * @param options - Optional rendering options\n * @returns React node representing the rendered markdown\n *\n * @example\n * ```tsx\n * <MarkdownRenderer\n * renderMarkdown={(md, opts) => {\n * // Custom rendering logic\n * return <div dangerouslySetInnerHTML={{ __html: customParser(md) }} />;\n * }}\n * >\n * {markdownContent}\n * </MarkdownRenderer>\n * ```\n */\n renderMarkdown?: (\n markdown: string,\n options?: {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: FC;\n forceBlock?: boolean;\n forceInline?: boolean;\n preserveFrontmatter?: boolean;\n tagfilter?: boolean;\n }\n ) => ReactNode;\n};\n\n/**\n * React component that renders markdown content to JSX.\n *\n * This component uses the `renderMarkdown` function from the `MarkdownProvider` context\n * if available. Otherwise, it falls back to the default compiler with provided components\n * and options. You can also provide a custom `renderMarkdown` function prop to override\n * all rendering behavior.\n *\n * @example\n * ```tsx\n * import { MarkdownRenderer } from '@intlayer/react-intlayer/markdown';\n *\n * function MyComponent() {\n * return (\n * <MarkdownRenderer>\n * {`# Hello World\n *\n * This is a paragraph with **bold** and *italic* text.\n *\n * - List item 1\n * - List item 2`}\n * </MarkdownRenderer>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom components\n * <MarkdownRenderer\n * components={{\n * h1: ({ children }) => <h1 className=\"text-4xl font-bold\">{children}</h1>,\n * a: ({ href, children }) => (\n * <a href={href} className=\"text-blue-500 hover:underline\">\n * {children}\n * </a>\n * ),\n * }}\n * forceBlock={true}\n * >\n * {markdownContent}\n * </MarkdownRenderer>\n * ```\n *\n * @example\n * ```tsx\n * // With MarkdownProvider context\n * function App() {\n * return (\n * <MarkdownProvider\n * components={{ h1: CustomHeading }}\n * forceBlock={true}\n * >\n * <MarkdownRenderer>\n * {markdownContent}\n * </MarkdownRenderer>\n * </MarkdownProvider>\n * );\n * }\n * ```\n */\nexport const MarkdownRenderer: FC<MarkdownRendererProps> = ({\n children = '',\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n renderMarkdown,\n}) => {\n const context = useMarkdownContext();\n\n if (renderMarkdown) {\n return (\n <>\n {renderMarkdown(children, {\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n })}\n </>\n );\n }\n\n if (context) {\n return (\n <>\n {context.renderMarkdown(\n children,\n {\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n },\n components,\n wrapper\n )}\n </>\n );\n }\n\n // Map public options to internal processor options\n const internalOptions: MarkdownRendererOptions = {\n components,\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return <>{compiler(children, internalOptions)}</>;\n};\n"],"mappings":"0KAiFA,MAAa,GACX,EACA,CACE,aACA,UACA,aACA,cACA,sBACA,aACuB,EAAE,GAapB,EAAS,EAViC,CAC/C,aACA,aACA,cACA,UACA,aAAc,CAAC,CAAC,EAChB,sBACA,YACD,CAEwC,CAgD9B,GAAuB,CAClC,aACA,UACA,aACA,cACA,sBACA,aACuB,EAAE,GAAK,CAC9B,IAAM,EAAU,GAAoB,CAEpC,MAAQ,IACF,EACK,EAAQ,eACb,EACA,CACE,aACA,cACA,sBACA,YACD,CACD,EACA,EACD,CAGI,EAAe,EAAS,CAC7B,aACA,UACA,aACA,cACA,sBACA,YACD,CAAC,EA6HO,GAA+C,CAC1D,WAAW,GACX,aACA,UACA,aACA,cACA,sBACA,YACA,oBACI,CACJ,IAAM,EAAU,GAAoB,CA8CpC,OA5CI,EAEA,EAAA,EAAA,CAAA,SACG,EAAe,EAAU,CACxB,aACA,UACA,aACA,cACA,sBACA,YACD,CAAC,CACD,CAAA,CAIH,EAEA,EAAA,EAAA,CAAA,SACG,EAAQ,eACP,EACA,CACE,aACA,cACA,sBACA,YACD,CACD,EACA,EACD,CACA,CAAA,CAeA,EAAA,EAAA,CAAA,SAAG,EAAS,EAV8B,CAC/C,aACA,aACA,cACA,UACA,aAAc,CAAC,CAAC,EAChB,sBACA,YACD,CAE4C,CAAI,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useMarkdownContext as e}from"./MarkdownProvider.mjs";
|
|
1
|
+
"use client";import{useMarkdownContext as e}from"./MarkdownProvider.mjs";const t=t=>{let{children:n,options:r,components:i}=t,a=e();return(a?.renderMarkdown??(e=>e))(n,r,{...a?.components??{},...i??{}})};export{t as MarkdownRendererPlugin};
|
|
2
2
|
//# sourceMappingURL=MarkdownRendererPlugin.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRendererPlugin.mjs","names":[],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"MarkdownRendererPlugin.mjs","names":[],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { FC, ReactNode } from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\nimport {\n type MarkdownProviderOptions,\n useMarkdownContext,\n} from './MarkdownProvider';\n\ntype MarkdownRendererPluginProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: LocalesValues;\n children: string;\n options?: MarkdownProviderOptions;\n components?: HTMLComponents<'permissive', {}>;\n};\n\nexport const MarkdownRendererPlugin: FC<MarkdownRendererPluginProps> = (\n props\n): ReactNode => {\n const { children, options, components } = props;\n const context = useMarkdownContext();\n const renderMarkdown = context?.renderMarkdown ?? ((md) => md);\n const contentToRender = children;\n\n return renderMarkdown(contentToRender, options, {\n ...(context?.components ?? {}),\n ...(components ?? {}),\n });\n};\n"],"mappings":"yEAoBA,MAAa,EACX,GACc,CACd,GAAM,CAAE,WAAU,UAAS,cAAe,EACpC,EAAU,GAAoB,CAIpC,OAHuB,GAAS,iBAAoB,GAAO,IACnC,EAEe,EAAS,CAC9C,GAAI,GAAS,YAAc,EAAE,CAC7B,GAAI,GAAc,EAAE,CACrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LegacyMarkdownRenderer as e,RuleType as t,compile as n,compileMarkdown as r,compiler as i,sanitizer as a,slugify as o}from"./processor.mjs";import{MarkdownProvider as s,useMarkdownContext as c}from"./MarkdownProvider.mjs";import{MarkdownRenderer as l,renderMarkdown as u,useMarkdownRenderer as d}from"./MarkdownRenderer.mjs";import{
|
|
1
|
+
import{LegacyMarkdownRenderer as e,RuleType as t,compile as n,compileMarkdown as r,compiler as i,sanitizer as a,slugify as o}from"./processor.mjs";import{MarkdownProvider as s,useMarkdownContext as c}from"./MarkdownProvider.mjs";import{MarkdownRenderer as l,renderMarkdown as u,useMarkdownRenderer as d}from"./MarkdownRenderer.mjs";import{MarkdownRendererPlugin as f}from"./MarkdownRendererPlugin.mjs";import p,{createReactRuntime as m}from"./runtime.mjs";export{e as LegacyMarkdownRenderer,s as MarkdownProvider,l as MarkdownRenderer,f as MarkdownRendererPlugin,t as RuleType,n as compile,r as compileMarkdown,i as compiler,m as createReactRuntime,p as reactRuntime,u as renderMarkdown,a as sanitizer,o as slugify,c as useMarkdownContext,d as useMarkdownRenderer};
|