react-intlayer 8.3.4 → 8.4.0-canary.0
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/IntlayerProvider.cjs +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +1 -1
- package/dist/cjs/editor/ContentSelector.cjs +2 -0
- package/dist/cjs/editor/ContentSelector.cjs.map +1 -0
- package/dist/cjs/editor/EditorProvider.cjs +2 -0
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
- package/dist/cjs/editor/useEditor.cjs +2 -0
- package/dist/cjs/editor/useEditor.cjs.map +1 -0
- package/dist/cjs/html/HTMLRendererPlugin.cjs +1 -1
- package/dist/cjs/html/HTMLRendererPlugin.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/markdown/MarkdownMetadataRendererInternal.cjs +2 -0
- package/dist/cjs/markdown/MarkdownMetadataRendererInternal.cjs.map +1 -0
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +1 -1
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +1 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +1 -1
- package/dist/esm/editor/ContentSelector.mjs +2 -0
- package/dist/esm/editor/ContentSelector.mjs.map +1 -0
- package/dist/esm/editor/EditorProvider.mjs +2 -0
- package/dist/esm/editor/EditorProvider.mjs.map +1 -0
- package/dist/esm/editor/useEditor.mjs +2 -0
- package/dist/esm/editor/useEditor.mjs.map +1 -0
- package/dist/esm/html/HTMLRendererPlugin.mjs +1 -1
- package/dist/esm/html/HTMLRendererPlugin.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/markdown/MarkdownMetadataRendererInternal.mjs +2 -0
- package/dist/esm/markdown/MarkdownMetadataRendererInternal.mjs.map +1 -0
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/plugins.mjs +1 -1
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/editor/ContentSelector.d.ts +9 -0
- package/dist/types/editor/ContentSelector.d.ts.map +1 -0
- package/dist/types/editor/EditorProvider.d.ts +7 -0
- package/dist/types/editor/EditorProvider.d.ts.map +1 -0
- package/dist/types/editor/useEditor.d.ts +10 -0
- package/dist/types/editor/useEditor.d.ts.map +1 -0
- package/dist/types/html/HTMLRenderer.d.ts +3 -3
- package/dist/types/html/HTMLRendererPlugin.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownMetadataRendererInternal.d.ts +16 -0
- package/dist/types/markdown/MarkdownMetadataRendererInternal.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +0 -2
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +0 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +0 -2
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +0 -1
- package/dist/cjs/editor/index.cjs +0 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs +0 -2
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +0 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +0 -2
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +0 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +0 -2
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +0 -1
- package/dist/esm/editor/index.mjs +0 -1
- package/dist/esm/editor/useEditedContentRenderer.mjs +0 -2
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +0 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +0 -19
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +0 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts +0 -11
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +0 -1
- package/dist/types/editor/index.d.ts +0 -2
- package/dist/types/editor/useEditedContentRenderer.d.ts +0 -20
- package/dist/types/editor/useEditedContentRenderer.d.ts.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../editor/
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../editor/EditorProvider.cjs`),n=require(`./useLocaleStorage.cjs`);let r=require(`@intlayer/config/built`);r=e.__toESM(r);let i=require(`react`),a=require(`react/jsx-runtime`),o=require(`@intlayer/core/localization`);const s=(0,i.createContext)({locale:n.localeInStorage??r.default?.internationalization?.defaultLocale,setLocale:()=>null,isCookieEnabled:!0}),c=()=>(0,i.useContext)(s),l=({locale:e,defaultLocale:t,children:c,setLocale:l,disableEditor:u,isCookieEnabled:d})=>{let{internationalization:f}=r.default??{},{locales:p,defaultLocale:m}=f??{},[h,g]=(0,i.useState)(e??n.localeInStorage??t??m);(0,i.useEffect)(()=>{e&&e!==h&&g(e)},[e]);let _=l??(e=>{if(h.toString()!==e.toString()){if(!p?.map(String).includes(e)){console.error(`Locale ${e} is not available`);return}g(e),n.setLocaleInStorage(e,d)}}),v=(0,o.localeResolver)(h);return(0,a.jsx)(s.Provider,{value:{locale:v,setLocale:_,disableEditor:u},children:c})},u=({children:e,...n})=>(0,a.jsxs)(l,{...n,children:[(0,a.jsx)(t.EditorProvider,{}),e]});exports.IntlayerClientContext=s,exports.IntlayerProvider=u,exports.IntlayerProviderContent=l,exports.useIntlayerContext=c;
|
|
2
2
|
//# sourceMappingURL=IntlayerProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.cjs","names":["localeInStorage","configuration","
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.cjs","names":["localeInStorage","configuration","EditorProvider"],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { localeResolver } from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that stores the current locale on the client side.\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeInStorage ?? configuration?.internationalization?.defaultLocale,\n setLocale: () => null,\n isCookieEnabled: true,\n});\n\n/**\n * Hook that provides the current Intlayer client context.\n *\n * @returns The current Intlayer context values.\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\n/**\n * Props for the IntlayerProvider component.\n */\nexport type IntlayerProviderProps = PropsWithChildren<{\n /**\n * The locale to use. If not provided, it will be detected from storage or configuration.\n */\n locale?: LocalesValues;\n /**\n * The default locale to use as a fallback.\n */\n defaultLocale?: LocalesValues;\n /**\n * Function to set the locale.\n */\n setLocale?: (locale: LocalesValues) => void;\n /**\n * Whether to disable the editor.\n */\n disableEditor?: boolean;\n /**\n * Whether to enable cookies for storing the locale.\n */\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that stores the current locale on the client side.\n *\n * This component is focused on content delivery without the editor features.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { internationalization } = configuration ?? {};\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n const initialLocale =\n localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] =\n useState<LocalesValues>(initialLocale);\n\n // Sync the prop to state if the prop changes from the parent\n useEffect(() => {\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }, [localeProp]);\n\n const setLocaleBase = (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale);\n setLocaleInStorage(newLocale, isCookieEnabled);\n };\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(currentLocale);\n\n return (\n <IntlayerClientContext.Provider\n value={{\n locale: resolvedLocale,\n setLocale,\n disableEditor,\n }}\n >\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\n/**\n * Main provider for Intlayer in React applications.\n *\n * It includes the editor provider by default, allowing for live content editing\n * if configured.\n *\n * @param props - The provider props.\n * @returns The provider component with editor support.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'react-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n ...props\n}) => (\n <IntlayerProviderContent {...props}>\n <EditorProvider />\n {children}\n </IntlayerProviderContent>\n);\n"],"mappings":"yWA0BA,MAAa,GAAA,EAAA,EAAA,eAAqD,CAChE,OAAQA,EAAAA,iBAAmBC,EAAAA,SAAe,sBAAsB,cAChE,cAAiB,KACjB,gBAAiB,GAClB,CAAC,CAOW,OAAA,EAAA,EAAA,YAAsC,EAAsB,CAoC5D,GAAsD,CACjE,OAAQ,EACR,cAAe,EACf,WACA,UAAW,EACX,gBACA,qBACI,CACJ,GAAM,CAAE,wBAAyBA,EAAAA,SAAiB,EAAE,CAC9C,CAAE,QAAS,EAAkB,cAAe,GAChD,GAAwB,EAAE,CAKtB,CAAC,EAAe,IAAA,EAAA,EAAA,UAFpB,GAAcD,EAAAA,iBAAmB,GAAqB,EAGhB,EAGxC,EAAA,EAAA,eAAgB,CACV,GAAc,IAAe,GAC/B,EAAiB,EAAW,EAE7B,CAAC,EAAW,CAAC,CAchB,IAAM,EAAY,IAZK,GAA6B,CAC9C,KAAc,UAAU,GAAK,EAAU,UAAU,CAErD,IAAI,CAAC,GAAkB,IAAI,OAAO,CAAC,SAAS,EAAU,CAAE,CACtD,QAAQ,MAAM,UAAU,EAAU,mBAAmB,CACrD,OAGF,EAAiB,EAAU,CAC3B,EAAA,mBAAmB,EAAW,EAAgB,IAM1C,GAAA,EAAA,EAAA,gBAAgC,EAAc,CAEpD,OACE,EAAA,EAAA,KAAC,EAAsB,SAAvB,CACE,MAAO,CACL,OAAQ,EACR,YACA,gBACD,CAEA,WAC8B,CAAA,EAwBxB,GAA+C,CAC1D,WACA,GAAG,MAEH,EAAA,EAAA,MAAC,EAAD,CAAyB,GAAI,WAA7B,EACE,EAAA,EAAA,KAACE,EAAAA,eAAD,EAAkB,CAAA,CACjB,EACuB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../getDictionary.cjs`),t=require(`./IntlayerProvider.cjs`);let n=require(`react`);const r=(r,i)=>{let{locale:a}=(0,n.useContext)(t.IntlayerClientContext);return(0,n.useMemo)(()=>e.getDictionary(r,i??a),[r.key,a,i])};exports.useDictionary=r;
|
|
2
2
|
//# sourceMappingURL=useDictionary.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../getIntlayer.cjs`),t=require(`./IntlayerProvider.cjs`);let n=require(`react`);const r=(r,i)=>{let{locale:a}=(0,n.useContext)(t.IntlayerClientContext);return(0,n.useMemo)(()=>e.getIntlayer(r,i??a),[r,a,i])};exports.useIntlayer=r;
|
|
2
2
|
//# sourceMappingURL=useIntlayer.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`react`),t=require(`@intlayer/core/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`react`),t=require(`@intlayer/core/localization`),n=require(`@intlayer/core/utils`);const r=(0,n.getLocaleFromStorage)(t.localeStorageOptions),i=r,a=(e,r)=>(0,n.setLocaleInStorage)(e,{...t.localeStorageOptions,isCookieEnabled:r}),o=a,s=r=>(0,e.useMemo)(()=>(0,n.LocaleStorage)({...t.localeStorageOptions,isCookieEnabled:r}),[r]),c=e=>{let t=s(e);return{localeCookie:t.getLocale(),setLocaleCookie:t.setLocale}};exports.localeCookie=i,exports.localeInStorage=r,exports.setLocaleCookie=o,exports.setLocaleInStorage=a,exports.useLocaleCookie=c,exports.useLocaleStorage=s;
|
|
2
2
|
//# sourceMappingURL=useLocaleStorage.cjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`react`),t=require(`@intlayer/editor/isEnabled`);const n=({children:n,dictionaryKey:r,keyPath:i})=>t.isEnabled?(0,e.createElement)(`intlayer-content-selector-wrapper`,{"key-path":JSON.stringify(i),"dictionary-key":r},n):n;exports.ContentSelector=n;
|
|
2
|
+
//# sourceMappingURL=ContentSelector.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentSelector.cjs","names":["isEnabled"],"sources":["../../../src/editor/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport type { NodeProps } from '@intlayer/core/interpreter';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport { createElement, type FC, type HTMLAttributes } from 'react';\n\nexport type ContentSelectorProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n if (isEnabled) {\n return createElement(\n 'intlayer-content-selector-wrapper',\n {\n 'key-path': JSON.stringify(keyPath),\n 'dictionary-key': dictionaryKey,\n },\n children\n );\n }\n\n return children;\n};\n"],"mappings":"4LASA,MAAa,GAA6C,CACxD,WACA,gBACA,aAEIA,EAAAA,WACF,EAAA,EAAA,eACE,oCACA,CACE,WAAY,KAAK,UAAU,EAAQ,CACnC,iBAAkB,EACnB,CACD,EACD,CAGI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditorProvider.cjs","names":[],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport { useEditor } from './useEditor';\n\nexport const EditorProvider: FC<PropsWithChildren> = ({ children }) => {\n useEditor();\n\n return children;\n};\n"],"mappings":"sGAGa,GAAyC,CAAE,eACtD,EAAA,WAAW,CAEJ"}
|
|
@@ -0,0 +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;
|
|
2
|
+
//# sourceMappingURL=useEditor.cjs.map
|
|
@@ -0,0 +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,CACTC,KAAAA,UASL,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
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./HTMLProvider.cjs`),t=require(`./HTMLRenderer.cjs`);let n=require(`@intlayer/core/interpreter`),r=require(`react`);const i=i=>{let{html:a,userComponents:o}=i,s=e.useHTMLContext()?.components||{},c={...t.defaultHTMLComponents,...s,...o};return(0,n.getHTML)(a,Object.fromEntries(Object.entries(c).filter(([,e])=>e).map(([e,t])=>[e,e=>(0,r.createElement)(t,e)])))};exports.HTMLRendererPlugin=i;
|
|
2
2
|
//# sourceMappingURL=HTMLRendererPlugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLRendererPlugin.cjs","names":["useHTMLContext","
|
|
1
|
+
{"version":3,"file":"HTMLRendererPlugin.cjs","names":["useHTMLContext","defaultHTMLComponents"],"sources":["../../../src/html/HTMLRendererPlugin.tsx"],"sourcesContent":["'use client';\n\nimport { getHTML } from '@intlayer/core/interpreter';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { createElement, type FC, type ReactNode } from 'react';\nimport { useHTMLContext } from './HTMLProvider';\nimport { defaultHTMLComponents } from './HTMLRenderer';\nimport type { ReactComponentProps } from './types';\n\ntype HTMLRendererPluginProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n html: string;\n locale?: Locale;\n userComponents?: Record<string, any>;\n};\n\nexport const HTMLRendererPlugin: FC<HTMLRendererPluginProps> = (\n props\n): ReactNode => {\n const { html, userComponents } = props;\n const context = useHTMLContext();\n const globalComponents = context?.components || {};\n\n const mergedComponents = {\n ...defaultHTMLComponents,\n ...globalComponents,\n ...userComponents,\n };\n\n // Wrap all components to ensure they are rendered via React.createElement\n // This is important because it allows React to handle the component's lifecycle,\n // hooks, and Babel-injected variables correctly.\n const wrappedComponents = Object.fromEntries(\n Object.entries(mergedComponents)\n .filter(([, Component]) => Component)\n .map(([key, Component]) => [\n key,\n (props: ReactComponentProps) => createElement(Component, props),\n ])\n );\n\n return getHTML(html, wrappedComponents);\n};\n"],"mappings":"kQAkBA,MAAa,EACX,GACc,CACd,GAAM,CAAE,OAAM,kBAAmB,EAE3B,EADUA,EAAAA,gBAAgB,EACE,YAAc,EAAE,CAE5C,EAAmB,CACvB,GAAGC,EAAAA,sBACH,GAAG,EACH,GAAG,EACJ,CAcD,OAAA,EAAA,EAAA,SAAe,EATW,OAAO,YAC/B,OAAO,QAAQ,EAAiB,CAC7B,QAAQ,EAAG,KAAe,EAAU,CACpC,KAAK,CAAC,EAAK,KAAe,CACzB,EACC,IAAA,EAAA,EAAA,eAA6C,EAAW,EAAM,CAChE,CAAC,CACL,CAEsC"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./html/HTMLProvider.cjs`),t=require(`./html/HTMLRenderer.cjs`),n=require(`./markdown/MarkdownProvider.cjs`),r=require(`./markdown/MarkdownRenderer.cjs`),i=require(`./getIntlayer.cjs`),a=require(`./getDictionary.cjs`),o=require(`./client/useLocaleStorage.cjs`),s=require(`./client/IntlayerProvider.cjs`),c=require(`./client/format/useIntl.cjs`),l=require(`./client/t.cjs`),u=require(`./client/useDictionary.cjs`),d=require(`./client/useDictionaryAsync.cjs`),f=require(`./client/useLoadDynamic.cjs`),p=require(`./client/useDictionaryDynamic.cjs`),m=require(`./client/useI18n.cjs`),h=require(`./client/useIntlayer.cjs`),g=require(`./client/useLocale.cjs`),_=require(`./client/useLocaleBase.cjs`),v=require(`./client/useRewriteURL.cjs`);exports.HTMLProvider=e.HTMLProvider,exports.HTMLRenderer=t.HTMLRenderer,exports.IntlayerClientContext=s.IntlayerClientContext,exports.IntlayerProvider=s.IntlayerProvider,exports.IntlayerProviderContent=s.IntlayerProviderContent,exports.MarkdownProvider=n.MarkdownProvider,exports.MarkdownRenderer=r.MarkdownRenderer,exports.getDictionary=a.getDictionary,exports.getIntlayer=i.getIntlayer,exports.localeCookie=o.localeCookie,exports.localeInStorage=o.localeInStorage,exports.renderHTML=t.renderHTML,exports.renderMarkdown=r.renderMarkdown,exports.setLocaleCookie=o.setLocaleCookie,exports.setLocaleInStorage=o.setLocaleInStorage,exports.t=l.t,exports.useDictionary=u.useDictionary,exports.useDictionaryAsync=d.useDictionaryAsync,exports.useDictionaryDynamic=p.useDictionaryDynamic,exports.useHTMLRenderer=t.useHTMLRenderer,exports.useI18n=m.useI18n,exports.useIntl=c.useIntl,exports.useIntlayer=h.useIntlayer,exports.useIntlayerContext=s.useIntlayerContext,exports.useLoadDynamic=f.useLoadDynamic,exports.useLocale=g.useLocale,exports.useLocaleBase=_.useLocaleBase,exports.useLocaleCookie=o.useLocaleCookie,exports.useLocaleStorage=o.useLocaleStorage,exports.useMarkdownRenderer=r.useMarkdownRenderer,exports.useRewriteURL=v.useRewriteURL;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/core/markdown`),t=require(`react`),n=require(`@intlayer/editor/isEnabled`),r=require(`@intlayer/core/dictionaryManipulator`);const i=(e,r,i)=>{let[a,o]=(0,t.useState)(i);return(0,t.useEffect)(()=>{if(!n.isEnabled)return;let t=!1,i,a,s=t=>{let n=()=>{let n=t.getContentValue(e,r);typeof n==`string`&&o(n)};n(),t.editedContent.addEventListener(`change`,n),i=()=>t.editedContent.removeEventListener(`change`,n)};return import(`@intlayer/editor`).then(({getGlobalEditorManager:e,onGlobalEditorManagerChange:n})=>{if(t)return;let r=e();r?s(r):a=n(e=>{t||(i&&=(i(),void 0),e&&s(e))})}),()=>{t=!0,i?.(),a?.()}},[e,r,i]),a},a=({dictionaryKey:t,keyPath:n,children:a,metadataKeyPath:o})=>(0,r.getContentNodeByKeyPath)((0,e.getMarkdownMetadata)(i(t,n,a)),o);exports.MarkdownMetadataRendererInternal=a;
|
|
2
|
+
//# sourceMappingURL=MarkdownMetadataRendererInternal.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownMetadataRendererInternal.cjs","names":["isEnabled"],"sources":["../../../src/markdown/MarkdownMetadataRendererInternal.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { FC, ReactNode } from 'react';\nimport { useEffect, useState } from 'react';\n\ntype MarkdownMetadataRendererProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: LocalesValues;\n children: string;\n metadataKeyPath: KeyPath[];\n};\n\n/**\n * Gets the edited markdown string for this node from the global manager,\n * falling back to the original children string.\n */\nconst useEditedMarkdown = (\n dictionaryKey: string,\n keyPath: KeyPath[],\n children: string\n): string => {\n const [editedMarkdown, setEditedMarkdown] = useState<string>(children);\n\n useEffect(() => {\n if (!isEnabled) return;\n\n let stopped = false;\n let unsubscribeFromManager: (() => void) | undefined;\n let unsubscribeFromGlobalChange: (() => void) | undefined;\n\n const setupManager = (manager: EditorStateManager) => {\n const updateValue = () => {\n const edited = manager.getContentValue(dictionaryKey, keyPath);\n if (typeof edited === 'string') {\n setEditedMarkdown(edited);\n }\n };\n\n updateValue();\n manager.editedContent.addEventListener('change', updateValue);\n unsubscribeFromManager = () =>\n manager.editedContent.removeEventListener('change', updateValue);\n };\n\n import('@intlayer/editor').then(\n ({ getGlobalEditorManager, onGlobalEditorManagerChange }) => {\n if (stopped) return;\n\n const manager = getGlobalEditorManager();\n\n if (manager) {\n setupManager(manager);\n } else {\n unsubscribeFromGlobalChange = onGlobalEditorManagerChange(\n (newManager) => {\n if (stopped) return;\n\n if (unsubscribeFromManager) {\n unsubscribeFromManager();\n unsubscribeFromManager = undefined;\n }\n\n if (newManager) {\n setupManager(newManager);\n }\n }\n );\n }\n }\n );\n\n return () => {\n stopped = true;\n unsubscribeFromManager?.();\n unsubscribeFromGlobalChange?.();\n };\n }, [dictionaryKey, keyPath, children]);\n\n return editedMarkdown;\n};\n\nexport const MarkdownMetadataRendererInternal: FC<\n MarkdownMetadataRendererProps\n> = ({ dictionaryKey, keyPath, children, metadataKeyPath }): ReactNode => {\n const markdownContent = useEditedMarkdown(dictionaryKey, keyPath, children);\n\n const metadata = getMarkdownMetadata(markdownContent);\n\n const metadataEl = getContentNodeByKeyPath(\n metadata as ContentNode,\n metadataKeyPath\n );\n\n return metadataEl as ReactNode;\n};\n"],"mappings":"mRAwBA,MAAM,GACJ,EACA,EACA,IACW,CACX,GAAM,CAAC,EAAgB,IAAA,EAAA,EAAA,UAAsC,EAAS,CAyDtE,OAvDA,EAAA,EAAA,eAAgB,CACd,GAAI,CAACA,EAAAA,UAAW,OAEhB,IAAI,EAAU,GACV,EACA,EAEE,EAAgB,GAAgC,CACpD,IAAM,MAAoB,CACxB,IAAM,EAAS,EAAQ,gBAAgB,EAAe,EAAQ,CAC1D,OAAO,GAAW,UACpB,EAAkB,EAAO,EAI7B,GAAa,CACb,EAAQ,cAAc,iBAAiB,SAAU,EAAY,CAC7D,MACE,EAAQ,cAAc,oBAAoB,SAAU,EAAY,EA8BpE,OA3BA,OAAO,oBAAoB,MACxB,CAAE,yBAAwB,iCAAkC,CAC3D,GAAI,EAAS,OAEb,IAAM,EAAU,GAAwB,CAEpC,EACF,EAAa,EAAQ,CAErB,EAA8B,EAC3B,GAAe,CACV,IAEJ,AAEE,KADA,GAAwB,CACC,IAAA,IAGvB,GACF,EAAa,EAAW,GAG7B,EAGN,KAEY,CACX,EAAU,GACV,KAA0B,CAC1B,KAA+B,GAEhC,CAAC,EAAe,EAAS,EAAS,CAAC,CAE/B,GAGI,GAER,CAAE,gBAAe,UAAS,WAAU,sBAUvC,EAAA,EAAA,0BAAA,EAAA,EAAA,qBATwB,EAAkB,EAAe,EAAS,EAAS,CAEtB,CAInD,EACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./MarkdownProvider.cjs`);let n=require(`@intlayer/config/built`);n=e.__toESM(n);let r=require(`react`),i=require(`react/jsx-runtime`);const a=e=>{let{children:n,options:r,components:i}=e,a=t.useMarkdownContext();return(a?.renderMarkdown??(e=>e))(n,r,{...a?.components??{},...i??{}})},o=(0,r.lazy)(()=>Promise.resolve().then(()=>require(`./MarkdownMetadataRendererInternal.cjs`)).then(e=>({default:e.MarkdownMetadataRendererInternal}))),s=e=>{let{editor:t}=n.default??{},a=t?.enabled??!1;return typeof window<`u`&&a?(0,i.jsx)(r.Suspense,{fallback:null,children:(0,i.jsx)(o,{...e})}):null};exports.MarkdownMetadataRenderer=s,exports.MarkdownRendererPlugin=a;
|
|
2
2
|
//# sourceMappingURL=MarkdownRendererPlugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRendererPlugin.cjs","names":["useMarkdownContext","
|
|
1
|
+
{"version":3,"file":"MarkdownRendererPlugin.cjs","names":["useMarkdownContext","configuration","Suspense"],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { type FC, lazy, type ReactNode, Suspense } 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\ntype MarkdownMetadataRendererProps = MarkdownRendererPluginProps & {\n metadataKeyPath: KeyPath[];\n};\n\nconst DynamicMarkdownMetadataRendererInternal = lazy(() =>\n import('./MarkdownMetadataRendererInternal').then((m) => ({\n default: m.MarkdownMetadataRendererInternal,\n }))\n);\n\nexport const MarkdownMetadataRenderer: FC<MarkdownMetadataRendererProps> = (\n props\n): ReactNode => {\n const { editor } = configuration ?? {};\n const isEnabled = editor?.enabled ?? false;\n\n if (typeof window !== 'undefined' && isEnabled) {\n return (\n <Suspense fallback={null}>\n <DynamicMarkdownMetadataRendererInternal {...props} />\n </Suspense>\n );\n }\n\n return null;\n};\n"],"mappings":"yQAmBA,MAAa,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,EAOE,GAAA,EAAA,EAAA,UAAA,QAAA,SAAA,CAAA,SAAA,QACJ,yCAAA,CAAA,CAA6C,KAAM,IAAO,CACxD,QAAS,EAAE,iCACZ,EAAE,CACJ,CAEY,EACX,GACc,CACd,GAAM,CAAE,UAAWC,EAAAA,SAAiB,EAAE,CAChC,EAAY,GAAQ,SAAW,GAUrC,OARI,OAAO,OAAW,KAAe,GAEjC,EAAA,EAAA,KAACC,EAAAA,SAAD,CAAU,SAAU,eAClB,EAAA,EAAA,KAAC,EAAD,CAAyC,GAAI,EAAS,CAAA,CAC7C,CAAA,CAIR"}
|
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/
|
|
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:o,...s}=n,l=a((0,c.getMarkdownMetadata)(e),{plugins:[{id:`markdown-metadata-plugin`,canHandle:e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`||!e,transform:(n,a)=>r.renderIntlayerNode({...a,value:n,children:(0,d.jsx)(t.ContentSelector,{...s,children:(0,d.jsx)(i.MarkdownMetadataRenderer,{...s,metadataKeyPath:a.keyPath,children:e})})})}],dictionaryKey:s.dictionaryKey,keyPath:[]}),u=a=>r.renderIntlayerNode({...n,value:e,children:(0,d.jsx)(t.ContentSelector,{...s,children:(0,d.jsx)(i.MarkdownRendererPlugin,{...s,components:a,children:e})}),additionalProps:{metadata:l}}),f=u();return new Proxy(f,{get(t,n,r){return n===`value`?e:n===`metadata`?l:n===`use`?e=>u(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","EditedContentRenderer","ContentSelectorRenderer","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 { ContentSelectorRenderer } from './editor';\nimport { EditedContentRenderer } from './editor/useEditedContentRenderer';\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 <EditedContentRenderer {...rest}>{rest.children}</EditedContentRenderer>\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 <ContentSelectorRenderer {...rest}>\n {renderReactElement(node)}\n </ContentSelectorRenderer>\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 <ContentSelectorRenderer {...rest}>\n <MarkdownMetadataRenderer\n {...rest}\n metadataKeyPath={props.keyPath}\n >\n {node}\n </MarkdownMetadataRenderer>\n </ContentSelectorRenderer>\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children: (\n <ContentSelectorRenderer {...rest}>\n <MarkdownRendererPlugin {...rest} components={components}>\n {node}\n </MarkdownRendererPlugin>\n </ContentSelectorRenderer>\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":"4mBAgDA,MAAa,EAA+B,CAC1C,GAAI,uBACJ,UAAY,GACV,OAAO,GAAS,UAChB,OAAO,GAAS,UAChB,OAAO,GAAS,SAClB,WACE,EACA,CACE,UACA,GAAG,KAGLA,EAAAA,mBAAmB,CACjB,GAAG,EACH,MAAO,EAAK,SACZ,SAAUC,EAAAA,SAAe,OAAO,SAC9B,EAAA,EAAA,KAACC,EAAAA,sBAAD,CAAuB,GAAI,WAAO,EAAK,SAAiC,CAAA,CAExE,EAAK,SAER,CAAC,CACL,CAcY,EAA4B,CACvC,GAAI,oBACJ,UAAY,GACV,OAAO,GAAS,UACT,GAAM,QAAU,QAChB,EAAK,MAAQ,OAEtB,WACE,EACA,CACE,UACA,GAAG,KAGLF,EAAAA,mBAAmB,CACjB,GAAG,EACH,MAAO,oBACP,SAAUC,EAAAA,SAAe,OAAO,SAC9B,EAAA,EAAA,KAACE,EAAAA,wBAAD,CAAyB,GAAI,WAC1BC,EAAAA,mBAAmB,EAAK,CACD,CAAA,CAE1BA,EAAAA,mBAAm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,CACE,KAAMA,EAAAA,SAAS,SAChB,CACF,CAEK,EAAW,EAAKA,EAAAA,SAAS,UAE/B,OAAO,EAAkB,EAAU,CACjC,GAAG,EACH,WACA,QAAS,EACT,QAAS,CAAC,EAAsB,GAAI,EAAM,SAAW,EAAE,CAAE,CAC1D,CAAC,EAEL,CA4BY,EAAsB,CACjC,GAAI,cACJ,UAAY,GACV,OAAO,GAAS,UAAY,GAAM,WAAaA,EAAAA,SAAS,KAE1D,WAAY,EAA2B,IAAU,CAC/C,IAAM,EAAO,EAAKA,EAAAA,SAAS,MACrB,CAAE,UAAS,GAAG,GAAS,EAGvB,EAAU,IAAA,EAAA,EAAA,eACAG,EAAAA,mBAAoB,CAAE,GAAG,EAAM,OAAM,iBAAgB,CAAC,CAEhE,EAAU,GAAQ,CAExB,OAAO,IAAI,MAAM,EAAS,CACxB,IAAI,EAAQ,EAAM,EAAU,CAU1B,OATI,IAAS,QACJ,EAGL,IAAS,MAEH,GAAoC,EAAO,EAAe,CAG7D,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE7C,CAAC,EAEL,CAuCY,GACX,EACA,EAAoB,KACN,yBAEZ,GAAUR,EAAAA,QAAc,qBAAqB,cAC7C,EAAWA,EAAAA,QAAc,qBAAqB,cAAgB,IAAA,GAC/D,CACDS,EAAAA,kBACAC,EAAAA,mCACa,GAAUV,EAAAA,QAAc,qBAAqB,cAAc,CACxEW,EAAAA,WACAC,EAAAA,aACA,EACA,EACA,EACA,EACA,EACD"}
|
|
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":"kjBA+CA,MAAa,EAA+B,CAC1C,GAAI,uBACJ,UAAY,GACV,OAAO,GAAS,UAChB,OAAO,GAAS,UAChB,OAAO,GAAS,SAClB,WACE,EACA,CACE,UACA,GAAG,KAGLA,EAAAA,mBAAmB,CACjB,GAAG,EACH,MAAO,EAAK,SACZ,SAAUC,EAAAA,SAAe,OAAO,SAC9B,EAAA,EAAA,KAACC,EAAAA,gBAAD,CAAiB,GAAI,WAAO,EAAK,SAA2B,CAAA,CAE5D,EAAK,SAER,CAAC,CACL,CAcY,EAA4B,CACvC,GAAI,oBACJ,UAAY,GACV,OAAO,GAAS,UACT,GAAM,QAAU,QAChB,EAAK,MAAQ,OAEtB,WACE,EACA,CACE,UACA,GAAG,KAGLF,EAAAA,mBAAmB,CACjB,GAAG,EACH,MAAO,oBACP,SAAUC,EAAAA,SAAe,OAAO,SAC9B,EAAA,EAAA,KAACC,EAAAA,gBAAD,CAAiB,GAAI,WAAOC,EAAAA,mBAAmB,EAAK,CAAmB,CAAA,CAEvEA,EAAAA,mBAAmB,EAAK,CAE3B,CAAC,CACL,CAqBK,GACJ,EACA,IACc,CACd,IAAM,GAAA,EAAA,EAAA,wBAAgC,EAAU,EAAO,CAQvD,OANI,EAAO,SAEF,EAAO,OAIhB,EAAA,EAAA,eACEC,EAAAA,SACA,KACA,GAAI,EAAO,MAAgB,KAAK,EAAM,KAAA,EAAA,EAAA,eACtBA,EAAAA,SAAU,CAAE,IAAK,EAAO,CAAE,EAAK,CAC9C,CACF,EAIU,EAA2B,CACtC,GAA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U,CAC/C,IAAM,EAAO,EAAKA,EAAAA,SAAS,MACrB,CAAE,UAAS,GAAG,GAAS,EAGvB,EAAU,IAAA,EAAA,EAAA,eACAG,EAAAA,mBAAoB,CAAE,GAAG,EAAM,OAAM,iBAAgB,CAAC,CAEhE,EAAU,GAAQ,CAExB,OAAO,IAAI,MAAM,EAAS,CACxB,IAAI,EAAQ,EAAM,EAAU,CAU1B,OATI,IAAS,QACJ,EAGL,IAAS,MAEH,GAAoC,EAAO,EAAe,CAG7D,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE7C,CAAC,EAEL,CAuCY,GACX,EACA,EAAoB,KACN,yBAEZ,GAAUP,EAAAA,QAAc,qBAAqB,cAC7C,EAAWA,EAAAA,QAAc,qBAAqB,cAAgB,IAAA,GAC/D,CACDQ,EAAAA,kBACAC,EAAAA,mCACa,GAAUT,EAAAA,QAAc,qBAAqB,cAAc,CACxEU,EAAAA,WACAC,EAAAA,aACA,EACA,EACA,EACA,EACA,EACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{EditorProvider as e}from"../editor/EditorProvider.mjs";import{localeInStorage as t,setLocaleInStorage as n}from"./useLocaleStorage.mjs";import r from"@intlayer/config/built";import{createContext as i,useContext as a,useEffect as o,useState as s}from"react";import{jsx as c,jsxs as l}from"react/jsx-runtime";import{localeResolver as u}from"@intlayer/core/localization";const d=i({locale:t??r?.internationalization?.defaultLocale,setLocale:()=>null,isCookieEnabled:!0}),f=()=>a(d),p=({locale:e,defaultLocale:i,children:a,setLocale:l,disableEditor:f,isCookieEnabled:p})=>{let{internationalization:m}=r??{},{locales:h,defaultLocale:g}=m??{},[_,v]=s(e??t??i??g);o(()=>{e&&e!==_&&v(e)},[e]);let y=l??(e=>{if(_.toString()!==e.toString()){if(!h?.map(String).includes(e)){console.error(`Locale ${e} is not available`);return}v(e),n(e,p)}}),b=u(_);return c(d.Provider,{value:{locale:b,setLocale:y,disableEditor:f},children:a})},m=({children:t,...n})=>l(p,{...n,children:[c(e,{}),t]});export{d as IntlayerClientContext,m as IntlayerProvider,p as IntlayerProviderContent,f as useIntlayerContext};
|
|
2
2
|
//# sourceMappingURL=IntlayerProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { localeResolver } from '@intlayer/core/localization';\nimport
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { localeResolver } from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that stores the current locale on the client side.\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeInStorage ?? configuration?.internationalization?.defaultLocale,\n setLocale: () => null,\n isCookieEnabled: true,\n});\n\n/**\n * Hook that provides the current Intlayer client context.\n *\n * @returns The current Intlayer context values.\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\n/**\n * Props for the IntlayerProvider component.\n */\nexport type IntlayerProviderProps = PropsWithChildren<{\n /**\n * The locale to use. If not provided, it will be detected from storage or configuration.\n */\n locale?: LocalesValues;\n /**\n * The default locale to use as a fallback.\n */\n defaultLocale?: LocalesValues;\n /**\n * Function to set the locale.\n */\n setLocale?: (locale: LocalesValues) => void;\n /**\n * Whether to disable the editor.\n */\n disableEditor?: boolean;\n /**\n * Whether to enable cookies for storing the locale.\n */\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that stores the current locale on the client side.\n *\n * This component is focused on content delivery without the editor features.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { internationalization } = configuration ?? {};\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n const initialLocale =\n localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] =\n useState<LocalesValues>(initialLocale);\n\n // Sync the prop to state if the prop changes from the parent\n useEffect(() => {\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }, [localeProp]);\n\n const setLocaleBase = (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale);\n setLocaleInStorage(newLocale, isCookieEnabled);\n };\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(currentLocale);\n\n return (\n <IntlayerClientContext.Provider\n value={{\n locale: resolvedLocale,\n setLocale,\n disableEditor,\n }}\n >\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\n/**\n * Main provider for Intlayer in React applications.\n *\n * It includes the editor provider by default, allowing for live content editing\n * if configured.\n *\n * @param props - The provider props.\n * @returns The provider component with editor support.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'react-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n ...props\n}) => (\n <IntlayerProviderContent {...props}>\n <EditorProvider />\n {children}\n </IntlayerProviderContent>\n);\n"],"mappings":"oYA0BA,MAAa,EAAwB,EAA6B,CAChE,OAAQ,GAAmB,GAAe,sBAAsB,cAChE,cAAiB,KACjB,gBAAiB,GAClB,CAAC,CAOW,MAA2B,EAAW,EAAsB,CAoC5D,GAAsD,CACjE,OAAQ,EACR,cAAe,EACf,WACA,UAAW,EACX,gBACA,qBACI,CACJ,GAAM,CAAE,wBAAyB,GAAiB,EAAE,CAC9C,CAAE,QAAS,EAAkB,cAAe,GAChD,GAAwB,EAAE,CAKtB,CAAC,EAAe,GACpB,EAHA,GAAc,GAAmB,GAAqB,EAGhB,CAGxC,MAAgB,CACV,GAAc,IAAe,GAC/B,EAAiB,EAAW,EAE7B,CAAC,EAAW,CAAC,CAchB,IAAM,EAAY,IAZK,GAA6B,CAC9C,KAAc,UAAU,GAAK,EAAU,UAAU,CAErD,IAAI,CAAC,GAAkB,IAAI,OAAO,CAAC,SAAS,EAAU,CAAE,CACtD,QAAQ,MAAM,UAAU,EAAU,mBAAmB,CACrD,OAGF,EAAiB,EAAU,CAC3B,EAAmB,EAAW,EAAgB,IAM1C,EAAiB,EAAe,EAAc,CAEpD,OACE,EAAC,EAAsB,SAAvB,CACE,MAAO,CACL,OAAQ,EACR,YACA,gBACD,CAEA,WAC8B,CAAA,EAwBxB,GAA+C,CAC1D,WACA,GAAG,KAEH,EAAC,EAAD,CAAyB,GAAI,WAA7B,CACE,EAAC,EAAD,EAAkB,CAAA,CACjB,EACuB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{getDictionary as e}from"../getDictionary.mjs";import{IntlayerClientContext as t}from"./IntlayerProvider.mjs";import{useContext as n,useMemo as r}from"react";const i=(i,a)=>{let{locale:o}=n(t);return r(()=>e(i,a??o),[i.key,o,a])};export{i as useDictionary};
|
|
2
2
|
//# sourceMappingURL=useDictionary.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{getIntlayer as e}from"../getIntlayer.mjs";import{IntlayerClientContext as t}from"./IntlayerProvider.mjs";import{useContext as n,useMemo as r}from"react";const i=(i,a)=>{let{locale:o}=n(t);return r(()=>e(i,a??o),[i,o,a])};export{i as useIntlayer};
|
|
2
2
|
//# sourceMappingURL=useIntlayer.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useMemo as e}from"react";import{
|
|
1
|
+
import{useMemo as e}from"react";import{localeStorageOptions as t}from"@intlayer/core/localization";import{LocaleStorage as n,getLocaleFromStorage as r,setLocaleInStorage as i}from"@intlayer/core/utils";const a=r(t),o=a,s=(e,n)=>i(e,{...t,isCookieEnabled:n}),c=s,l=r=>e(()=>n({...t,isCookieEnabled:r}),[r]),u=e=>{let t=l(e);return{localeCookie:t.getLocale(),setLocaleCookie:t.setLocale}};export{o as localeCookie,a as localeInStorage,c as setLocaleCookie,s as setLocaleInStorage,u as useLocaleCookie,l as useLocaleStorage};
|
|
2
2
|
//# sourceMappingURL=useLocaleStorage.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{createElement as e}from"react";import{isEnabled as t}from"@intlayer/editor/isEnabled";const n=({children:n,dictionaryKey:r,keyPath:i})=>t?e(`intlayer-content-selector-wrapper`,{"key-path":JSON.stringify(i),"dictionary-key":r},n):n;export{n as ContentSelector};
|
|
2
|
+
//# sourceMappingURL=ContentSelector.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentSelector.mjs","names":[],"sources":["../../../src/editor/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport type { NodeProps } from '@intlayer/core/interpreter';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport { createElement, type FC, type HTMLAttributes } from 'react';\n\nexport type ContentSelectorProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n if (isEnabled) {\n return createElement(\n 'intlayer-content-selector-wrapper',\n {\n 'key-path': JSON.stringify(keyPath),\n 'dictionary-key': dictionaryKey,\n },\n children\n );\n }\n\n return children;\n};\n"],"mappings":"0GASA,MAAa,GAA6C,CACxD,WACA,gBACA,aAEI,EACK,EACL,oCACA,CACE,WAAY,KAAK,UAAU,EAAQ,CACnC,iBAAkB,EACnB,CACD,EACD,CAGI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditorProvider.mjs","names":[],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport { useEditor } from './useEditor';\n\nexport const EditorProvider: FC<PropsWithChildren> = ({ children }) => {\n useEditor();\n\n return children;\n};\n"],"mappings":"4CAGA,MAAa,GAAyC,CAAE,eACtD,GAAW,CAEJ"}
|
|
@@ -0,0 +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};
|
|
2
|
+
//# sourceMappingURL=useEditor.mjs.map
|
|
@@ -0,0 +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,CACT,KASL,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
|
-
"use client";import{
|
|
1
|
+
"use client";import{useHTMLContext as e}from"./HTMLProvider.mjs";import{defaultHTMLComponents as t}from"./HTMLRenderer.mjs";import{getHTML as n}from"@intlayer/core/interpreter";import{createElement as r}from"react";const i=i=>{let{html:a,userComponents:o}=i,s=e()?.components||{},c={...t,...s,...o};return n(a,Object.fromEntries(Object.entries(c).filter(([,e])=>e).map(([e,t])=>[e,e=>r(t,e)])))};export{i as HTMLRendererPlugin};
|
|
2
2
|
//# sourceMappingURL=HTMLRendererPlugin.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLRendererPlugin.mjs","names":[],"sources":["../../../src/html/HTMLRendererPlugin.tsx"],"sourcesContent":["'use client';\n\nimport { getHTML } from '@intlayer/core/interpreter';\nimport type {
|
|
1
|
+
{"version":3,"file":"HTMLRendererPlugin.mjs","names":[],"sources":["../../../src/html/HTMLRendererPlugin.tsx"],"sourcesContent":["'use client';\n\nimport { getHTML } from '@intlayer/core/interpreter';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { createElement, type FC, type ReactNode } from 'react';\nimport { useHTMLContext } from './HTMLProvider';\nimport { defaultHTMLComponents } from './HTMLRenderer';\nimport type { ReactComponentProps } from './types';\n\ntype HTMLRendererPluginProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n html: string;\n locale?: Locale;\n userComponents?: Record<string, any>;\n};\n\nexport const HTMLRendererPlugin: FC<HTMLRendererPluginProps> = (\n props\n): ReactNode => {\n const { html, userComponents } = props;\n const context = useHTMLContext();\n const globalComponents = context?.components || {};\n\n const mergedComponents = {\n ...defaultHTMLComponents,\n ...globalComponents,\n ...userComponents,\n };\n\n // Wrap all components to ensure they are rendered via React.createElement\n // This is important because it allows React to handle the component's lifecycle,\n // hooks, and Babel-injected variables correctly.\n const wrappedComponents = Object.fromEntries(\n Object.entries(mergedComponents)\n .filter(([, Component]) => Component)\n .map(([key, Component]) => [\n key,\n (props: ReactComponentProps) => createElement(Component, props),\n ])\n );\n\n return getHTML(html, wrappedComponents);\n};\n"],"mappings":"uNAkBA,MAAa,EACX,GACc,CACd,GAAM,CAAE,OAAM,kBAAmB,EAE3B,EADU,GAAgB,EACE,YAAc,EAAE,CAE5C,EAAmB,CACvB,GAAG,EACH,GAAG,EACH,GAAG,EACJ,CAcD,OAAO,EAAQ,EATW,OAAO,YAC/B,OAAO,QAAQ,EAAiB,CAC7B,QAAQ,EAAG,KAAe,EAAU,CACpC,KAAK,CAAC,EAAK,KAAe,CACzB,EACC,GAA+B,EAAc,EAAW,EAAM,CAChE,CAAC,CACL,CAEsC"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{HTMLProvider as e}from"./html/HTMLProvider.mjs";import{HTMLRenderer as t,renderHTML as n,useHTMLRenderer as r}from"./html/HTMLRenderer.mjs";import{MarkdownProvider as i}from"./markdown/MarkdownProvider.mjs";import{MarkdownRenderer as a,renderMarkdown as o,useMarkdownRenderer as s}from"./markdown/MarkdownRenderer.mjs";import{getIntlayer as c}from"./getIntlayer.mjs";import{getDictionary as l}from"./getDictionary.mjs";import{localeCookie as u,localeInStorage as d,setLocaleCookie as f,setLocaleInStorage as p,useLocaleCookie as m,useLocaleStorage as h}from"./client/useLocaleStorage.mjs";import{IntlayerClientContext as g,IntlayerProvider as _,IntlayerProviderContent as v,useIntlayerContext as y}from"./client/IntlayerProvider.mjs";import{useIntl as b}from"./client/format/useIntl.mjs";import{t as x}from"./client/t.mjs";import{useDictionary as S}from"./client/useDictionary.mjs";import{useDictionaryAsync as C}from"./client/useDictionaryAsync.mjs";import{useLoadDynamic as w}from"./client/useLoadDynamic.mjs";import{useDictionaryDynamic as T}from"./client/useDictionaryDynamic.mjs";import{useI18n as E}from"./client/useI18n.mjs";import{useIntlayer as D}from"./client/useIntlayer.mjs";import{useLocale as O}from"./client/useLocale.mjs";import{useLocaleBase as k}from"./client/useLocaleBase.mjs";import{useRewriteURL as A}from"./client/useRewriteURL.mjs";export{e as HTMLProvider,t as HTMLRenderer,g as IntlayerClientContext,_ as IntlayerProvider,v as IntlayerProviderContent,i as MarkdownProvider,a as MarkdownRenderer,l as getDictionary,c as getIntlayer,u as localeCookie,d as localeInStorage,n as renderHTML,o as renderMarkdown,f as setLocaleCookie,p as setLocaleInStorage,x as t,S as useDictionary,C as useDictionaryAsync,T as useDictionaryDynamic,r as useHTMLRenderer,E as useI18n,b as useIntl,D as useIntlayer,y as useIntlayerContext,w as useLoadDynamic,O as useLocale,k as useLocaleBase,m as useLocaleCookie,h as useLocaleStorage,s as useMarkdownRenderer,A as useRewriteURL};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{getMarkdownMetadata as e}from"@intlayer/core/markdown";import{useEffect as t,useState as n}from"react";import{isEnabled as r}from"@intlayer/editor/isEnabled";import{getContentNodeByKeyPath as i}from"@intlayer/core/dictionaryManipulator";const a=(e,i,a)=>{let[o,s]=n(a);return t(()=>{if(!r)return;let t=!1,n,a,o=t=>{let r=()=>{let n=t.getContentValue(e,i);typeof n==`string`&&s(n)};r(),t.editedContent.addEventListener(`change`,r),n=()=>t.editedContent.removeEventListener(`change`,r)};return import(`@intlayer/editor`).then(({getGlobalEditorManager:e,onGlobalEditorManagerChange:r})=>{if(t)return;let i=e();i?o(i):a=r(e=>{t||(n&&=(n(),void 0),e&&o(e))})}),()=>{t=!0,n?.(),a?.()}},[e,i,a]),o},o=({dictionaryKey:t,keyPath:n,children:r,metadataKeyPath:o})=>i(e(a(t,n,r)),o);export{o as MarkdownMetadataRendererInternal};
|
|
2
|
+
//# sourceMappingURL=MarkdownMetadataRendererInternal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownMetadataRendererInternal.mjs","names":[],"sources":["../../../src/markdown/MarkdownMetadataRendererInternal.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { FC, ReactNode } from 'react';\nimport { useEffect, useState } from 'react';\n\ntype MarkdownMetadataRendererProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: LocalesValues;\n children: string;\n metadataKeyPath: KeyPath[];\n};\n\n/**\n * Gets the edited markdown string for this node from the global manager,\n * falling back to the original children string.\n */\nconst useEditedMarkdown = (\n dictionaryKey: string,\n keyPath: KeyPath[],\n children: string\n): string => {\n const [editedMarkdown, setEditedMarkdown] = useState<string>(children);\n\n useEffect(() => {\n if (!isEnabled) return;\n\n let stopped = false;\n let unsubscribeFromManager: (() => void) | undefined;\n let unsubscribeFromGlobalChange: (() => void) | undefined;\n\n const setupManager = (manager: EditorStateManager) => {\n const updateValue = () => {\n const edited = manager.getContentValue(dictionaryKey, keyPath);\n if (typeof edited === 'string') {\n setEditedMarkdown(edited);\n }\n };\n\n updateValue();\n manager.editedContent.addEventListener('change', updateValue);\n unsubscribeFromManager = () =>\n manager.editedContent.removeEventListener('change', updateValue);\n };\n\n import('@intlayer/editor').then(\n ({ getGlobalEditorManager, onGlobalEditorManagerChange }) => {\n if (stopped) return;\n\n const manager = getGlobalEditorManager();\n\n if (manager) {\n setupManager(manager);\n } else {\n unsubscribeFromGlobalChange = onGlobalEditorManagerChange(\n (newManager) => {\n if (stopped) return;\n\n if (unsubscribeFromManager) {\n unsubscribeFromManager();\n unsubscribeFromManager = undefined;\n }\n\n if (newManager) {\n setupManager(newManager);\n }\n }\n );\n }\n }\n );\n\n return () => {\n stopped = true;\n unsubscribeFromManager?.();\n unsubscribeFromGlobalChange?.();\n };\n }, [dictionaryKey, keyPath, children]);\n\n return editedMarkdown;\n};\n\nexport const MarkdownMetadataRendererInternal: FC<\n MarkdownMetadataRendererProps\n> = ({ dictionaryKey, keyPath, children, metadataKeyPath }): ReactNode => {\n const markdownContent = useEditedMarkdown(dictionaryKey, keyPath, children);\n\n const metadata = getMarkdownMetadata(markdownContent);\n\n const metadataEl = getContentNodeByKeyPath(\n metadata as ContentNode,\n metadataKeyPath\n );\n\n return metadataEl as ReactNode;\n};\n"],"mappings":"iQAwBA,MAAM,GACJ,EACA,EACA,IACW,CACX,GAAM,CAAC,EAAgB,GAAqB,EAAiB,EAAS,CAyDtE,OAvDA,MAAgB,CACd,GAAI,CAAC,EAAW,OAEhB,IAAI,EAAU,GACV,EACA,EAEE,EAAgB,GAAgC,CACpD,IAAM,MAAoB,CACxB,IAAM,EAAS,EAAQ,gBAAgB,EAAe,EAAQ,CAC1D,OAAO,GAAW,UACpB,EAAkB,EAAO,EAI7B,GAAa,CACb,EAAQ,cAAc,iBAAiB,SAAU,EAAY,CAC7D,MACE,EAAQ,cAAc,oBAAoB,SAAU,EAAY,EA8BpE,OA3BA,OAAO,oBAAoB,MACxB,CAAE,yBAAwB,iCAAkC,CAC3D,GAAI,EAAS,OAEb,IAAM,EAAU,GAAwB,CAEpC,EACF,EAAa,EAAQ,CAErB,EAA8B,EAC3B,GAAe,CACV,IAEJ,AAEE,KADA,GAAwB,CACC,IAAA,IAGvB,GACF,EAAa,EAAW,GAG7B,EAGN,KAEY,CACX,EAAU,GACV,KAA0B,CAC1B,KAA+B,GAEhC,CAAC,EAAe,EAAS,EAAS,CAAC,CAE/B,GAGI,GAER,CAAE,gBAAe,UAAS,WAAU,qBAKpB,EAFF,EAFO,EAAkB,EAAe,EAAS,EAAS,CAEtB,CAInD,EACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useMarkdownContext as e}from"./MarkdownProvider.mjs";import t from"@intlayer/config/built";import{Suspense as n,lazy as r}from"react";import{jsx as i}from"react/jsx-runtime";const a=t=>{let{children:n,options:r,components:i}=t,a=e();return(a?.renderMarkdown??(e=>e))(n,r,{...a?.components??{},...i??{}})},o=r(()=>import(`./MarkdownMetadataRendererInternal.mjs`).then(e=>({default:e.MarkdownMetadataRendererInternal}))),s=e=>{let{editor:r}=t??{},a=r?.enabled??!1;return typeof window<`u`&&a?i(n,{fallback:null,children:i(o,{...e})}):null};export{s as MarkdownMetadataRenderer,a 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":["import configuration from '@intlayer/config/built';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { type FC, lazy, type ReactNode, Suspense } 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\ntype MarkdownMetadataRendererProps = MarkdownRendererPluginProps & {\n metadataKeyPath: KeyPath[];\n};\n\nconst DynamicMarkdownMetadataRendererInternal = lazy(() =>\n import('./MarkdownMetadataRendererInternal').then((m) => ({\n default: m.MarkdownMetadataRendererInternal,\n }))\n);\n\nexport const MarkdownMetadataRenderer: FC<MarkdownMetadataRendererProps> = (\n props\n): ReactNode => {\n const { editor } = configuration ?? {};\n const isEnabled = editor?.enabled ?? false;\n\n if (typeof window !== 'undefined' && isEnabled) {\n return (\n <Suspense fallback={null}>\n <DynamicMarkdownMetadataRendererInternal {...props} />\n </Suspense>\n );\n }\n\n return null;\n};\n"],"mappings":"qLAmBA,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,EAOE,EAA0C,MAC9C,OAAO,0CAAsC,KAAM,IAAO,CACxD,QAAS,EAAE,iCACZ,EAAE,CACJ,CAEY,EACX,GACc,CACd,GAAM,CAAE,UAAW,GAAiB,EAAE,CAChC,EAAY,GAAQ,SAAW,GAUrC,OARI,OAAO,OAAW,KAAe,EAEjC,EAAC,EAAD,CAAU,SAAU,cAClB,EAAC,EAAD,CAAyC,GAAI,EAAS,CAAA,CAC7C,CAAA,CAIR"}
|
package/dist/esm/plugins.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ContentSelector as e}from"./editor/ContentSelector.mjs";import{HTMLRendererPlugin as t}from"./html/HTMLRendererPlugin.mjs";import{renderIntlayerNode as n}from"./IntlayerNode.mjs";import{MarkdownMetadataRenderer as r,MarkdownRendererPlugin as i}from"./markdown/MarkdownRendererPlugin.mjs";import{renderReactElement as a}from"./reactElement/renderReactElement.mjs";import o from"@intlayer/config/built";import{conditionPlugin as s,enumerationPlugin as c,filePlugin as l,genderPlugin as u,nestedPlugin as d,splitInsertionTemplate as f,translationPlugin as p}from"@intlayer/core/interpreter";import{getMarkdownMetadata as m}from"@intlayer/core/markdown";import{NodeType as h}from"@intlayer/types/nodeType";import{Fragment as g,createElement as _}from"react";import{jsx as v}from"react/jsx-runtime";const y={id:`intlayer-node-plugin`,canHandle:e=>typeof e==`bigint`||typeof e==`string`||typeof e==`number`,transform:(t,{plugins:r,...i})=>n({...i,value:i.children,children:o?.editor.enabled?v(e,{...i,children:i.children}):i.children})},b={id:`react-node-plugin`,canHandle:e=>typeof e==`object`&&e?.props!==void 0&&e.key!==void 0,transform:(t,{plugins:r,...i})=>n({...i,value:`[[react-element]]`,children:o?.editor.enabled?v(e,{...i,children:a(t)}):a(t)})},x=(e,t)=>{let n=f(e,t);return n.isSimple?n.parts:_(g,null,...n.parts.map((e,t)=>_(g,{key:t},e)))},S={id:`insertion-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===h.Insertion,transform:(e,t,n)=>{let r=[...t.keyPath,{type:h.Insertion}],i=e[h.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=x(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&&[h.Enumeration,h.Condition].includes(i.nodeType)?e=>t=>{let n=o(t);return typeof n==`function`?n(e):n}:o}},C={id:`markdown-string-plugin`,canHandle:e=>typeof e==`string`,transform:(t,a,o)=>{let{plugins:s,...c}=a,l=o(m(t),{plugins:[{id:`markdown-metadata-plugin`,canHandle:e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`||!e,transform:(i,a)=>n({...a,value:i,children:v(e,{...c,children:v(r,{...c,metadataKeyPath:a.keyPath,children:t})})})}],dictionaryKey:c.dictionaryKey,keyPath:[]}),u=r=>n({...a,value:t,children:v(e,{...c,children:v(i,{...c,components:r,children:t})}),additionalProps:{metadata:l}}),d=u();return new Proxy(d,{get(e,n,r){return n===`value`?t:n===`metadata`?l:n===`use`?e=>u(e):Reflect.get(e,n,r)}})}},w={id:`markdown-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===h.Markdown,transform:(e,t,n)=>{let r=[...t.keyPath,{type:h.Markdown}],i=e[h.Markdown];return n(i,{...t,children:i,keyPath:r,plugins:[C,...t.plugins??[]]})}},T={id:`html-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===h.HTML,transform:(e,n)=>{let r=e[h.HTML],{plugins:i,...a}=n,o=e=>_(t,{...a,html:r,userComponents:e}),s=o();return new Proxy(s,{get(e,t,n){return t===`value`?r:t===`use`?e=>o(e):Reflect.get(e,t,n)}})}},E=(e,t=!0)=>[p(e??o.internationalization.defaultLocale,t?o.internationalization.defaultLocale:void 0),c,s,d(e??o.internationalization.defaultLocale),l,u,y,b,S,w,T];export{E as getPlugins,T as htmlPlugin,S as insertionPlugin,y as intlayerNodePlugins,w as markdownPlugin,C as markdownStringPlugin,b as reactNodePlugins};
|
|
2
2
|
//# sourceMappingURL=plugins.mjs.map
|
package/dist/esm/plugins.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport {\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { ContentSelectorRenderer } from './editor';\nimport { EditedContentRenderer } from './editor/useEditedContentRenderer';\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 <EditedContentRenderer {...rest}>{rest.children}</EditedContentRenderer>\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 <ContentSelectorRenderer {...rest}>\n {renderReactElement(node)}\n </ContentSelectorRenderer>\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 <ContentSelectorRenderer {...rest}>\n <MarkdownMetadataRenderer\n {...rest}\n metadataKeyPath={props.keyPath}\n >\n {node}\n </MarkdownMetadataRenderer>\n </ContentSelectorRenderer>\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children: (\n <ContentSelectorRenderer {...rest}>\n <MarkdownRendererPlugin {...rest} components={components}>\n {node}\n </MarkdownRendererPlugin>\n </ContentSelectorRenderer>\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":"83BAgDA,MAAa,EAA+B,CAC1C,GAAI,uBACJ,UAAY,GACV,OAAO,GAAS,UAChB,OAAO,GAAS,UAChB,OAAO,GAAS,SAClB,WACE,EACA,CACE,UACA,GAAG,KAGL,EAAmB,CACjB,GAAG,EACH,MAAO,EAAK,SACZ,SAAU,GAAe,OAAO,QAC9B,EAAC,EAAD,CAAuB,GAAI,WAAO,EAAK,SAAiC,CAAA,CAExE,EA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AuB,EAAO,IAAsB,CAC9D,IAAM,EAAwB,CAC5B,GAAG,EAAM,QACT,CACE,KAAM,EAAS,SAChB,CACF,CAEK,EAAW,EAAK,EAAS,UAE/B,OAAO,EAAkB,EAAU,CACjC,GAAG,EACH,WACA,QAAS,EACT,QAAS,CAAC,EAAsB,GAAI,EAAM,SAAW,EAAE,CAAE,CAC1D,CAAC,EAEL,CA4BY,EAAsB,CACjC,GAAI,cACJ,UAAY,GACV,OAAO,GAAS,UAAY,GAAM,WAAa,EAAS,KAE1D,WAAY,EAA2B,IAAU,CAC/C,IAAM,EAAO,EAAK,EAAS,MACrB,CAAE,UAAS,GAAG,GAAS,EAGvB,EAAU,GACd,EAAc,EAAoB,CAAE,GAAG,EAAM,OAAM,iBAAgB,CAAC,CAEhE,EAAU,GAAQ,CAExB,OAAO,IAAI,MAAM,EAAS,CACxB,IAAI,EAAQ,EAAM,EAAU,CAU1B,OATI,IAAS,QACJ,EAGL,IAAS,MAEH,GAAoC,EAAO,EAAe,CAG7D,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE7C,CAAC,EAEL,CAuCY,GACX,EACA,EAAoB,KACN,CACd,EACE,GAAU,EAAc,qBAAqB,cAC7C,EAAW,EAAc,qBAAqB,cAAgB,IAAA,GAC/D,CACD,EACA,EACA,EAAa,GAAU,EAAc,qBAAqB,cAAc,CACxE,EACA,EACA,EACA,EACA,EACA,EACA,EACD"}
|
|
1
|
+
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport {\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { ContentSelector } from './editor/ContentSelector';\nimport { HTMLRendererPlugin } from './html';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { 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":"iyBA+CA,MAAa,EAA+B,CAC1C,GAAI,uBACJ,UAAY,GACV,OAAO,GAAS,UAChB,OAAO,GAAS,UAChB,OAAO,GAAS,SAClB,WACE,EACA,CACE,UACA,GAAG,KAGL,EAAmB,CACjB,GAAG,EACH,MAAO,EAAK,SACZ,SAAU,GAAe,OAAO,QAC9B,EAAC,EAAD,CAAiB,GAAI,WAAO,EAAK,SAA2B,CAAA,CAE5D,EAAK,SAER,CAAC,CACL,CAcY,EAA4B,CACvC,GAAI,oBACJ,UAAY,GACV,OAAO,GAAS,UACT,GAAM,QAAU,QAChB,EAAK,MAAQ,OAEtB,WACE,EACA,CACE,UACA,GAAG,KAGL,EAAmB,CACjB,GAAG,EACH,MAAO,oBACP,SAAU,GAAe,OAAO,QAC9B,EAAC,EAAD,CAAiB,GAAI,WAAO,EAAmB,EAAK,CAAmB,CAAA,CAEvE,EAAmB,EAAK,CAE3B,CAAC,CACL,CAqBK,GACJ,EACA,IACc,CACd,IAAM,EAAS,EAAuB,EAAU,EAAO,CAQvD,OANI,EAAO,SAEF,EAAO,MAIT,EACL,EACA,KACA,GAAI,EAAO,MAAgB,KAAK,EAAM,IACpC,EAAc,EAAU,CAAE,IAAK,EAAO,CAAE,EAAK,CAC9C,CACF,EAIU,EAA2B,CACtC,GAAI,mBACJ,UAAY,GACV,OAAO,GAAS,UAAY,GAAM,WAAa,EAAS,UAC1D,WAAY,EAAwB,EAAO,IAAsB,CAC/D,IAAM,EAAwB,CAC5B,GAAG,EAAM,QACT,CACE,KAAM,EAAS,UAChB,CACF,CAEK,EAAW,EAAK,EAAS,WAGzB,EAAiC,CACrC,GAAI,0BACJ,UAAY,GAAS,OAAO,GAAS,SACrC,WAAY,EAAc,EAAU,IAAsB,CACxD,IAAM,EAAoB,EAAkB,EAAM,CAChD,GAAG,EACH,SAA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ACA,EACA,EACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.d.ts","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"mappings":";;;;;KAgBK,aAAA;EACH,MAAA,EAAQ,aAAA;EACR,SAAA,GAAY,SAAA,EAAW,aAAA;EACvB,aAAA;EACA,eAAA;AAAA;;;;cAMW,qBAAA,EAAqB,KAAA,CAAA,OAAA,CAAA,aAAA;;;;;;
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.d.ts","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"mappings":";;;;;KAgBK,aAAA;EACH,MAAA,EAAQ,aAAA;EACR,SAAA,GAAY,SAAA,EAAW,aAAA;EACvB,aAAA;EACA,eAAA;AAAA;;;;cAMW,qBAAA,EAAqB,KAAA,CAAA,OAAA,CAAA,aAAA;;;;;;cAWrB,kBAAA,QAAkB,aAAA;AAX/B;;;AAAA,KAgBY,qBAAA,GAAwB,iBAAA;EAhBF;AAWlC;;EASE,MAAA,GAAS,aAAA;EAToB;;AAK/B;EAQE,aAAA,GAAgB,aAAA;;;;EAIhB,SAAA,IAAa,MAAA,EAAQ,aAAA;EAZa;;;EAgBlC,aAAA;EAZA;;;EAgBA,eAAA;AAAA;;;;;;;AAWF;;cAAa,uBAAA,EAAyB,EAAA,CAAG,qBAAA;;;AA2EzC;;;;;;;;;;;;;;;;;;cAAa,gBAAA,EAAkB,EAAA,CAAG,qBAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NodeProps } from "@intlayer/core/interpreter";
|
|
2
|
+
import { FC, HTMLAttributes } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/editor/ContentSelector.d.ts
|
|
5
|
+
type ContentSelectorProps = NodeProps & Omit<HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
6
|
+
declare const ContentSelector: FC<ContentSelectorProps>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ContentSelector, ContentSelectorProps };
|
|
9
|
+
//# sourceMappingURL=ContentSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentSelector.d.ts","names":[],"sources":["../../../src/editor/ContentSelector.tsx"],"mappings":";;;;KAMY,oBAAA,GAAuB,SAAA,GACjC,IAAA,CAAK,cAAA,CAAe,cAAA;AAAA,cAET,eAAA,EAAiB,EAAA,CAAG,oBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditorProvider.d.ts","names":[],"sources":["../../../src/editor/EditorProvider.tsx"],"mappings":";;;cAGa,cAAA,EAAgB,EAAA,CAAG,iBAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/editor/useEditor.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Initializes the Intlayer editor client singleton when the editor is enabled.
|
|
4
|
+
* Syncs the current locale from the Intlayer context into the editor manager so
|
|
5
|
+
* the editor always knows which locale the app is displaying.
|
|
6
|
+
*/
|
|
7
|
+
declare const useEditor: () => void;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { useEditor };
|
|
10
|
+
//# sourceMappingURL=useEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditor.d.ts","names":[],"sources":["../../../src/editor/useEditor.tsx"],"mappings":";;AAaA;;;;cAAa,SAAA"}
|
|
@@ -8,6 +8,9 @@ declare const defaultHTMLComponents: {} & {
|
|
|
8
8
|
hr?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
9
9
|
th?: FC<react.DetailedHTMLProps<react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
10
10
|
tr?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
11
|
+
small?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
12
|
+
sub?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
13
|
+
sup?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
11
14
|
slot?: FC<react.DetailedHTMLProps<react.SlotHTMLAttributes<HTMLSlotElement>, HTMLSlotElement>>;
|
|
12
15
|
html?: FC<react.DetailedHTMLProps<react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
13
16
|
head?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>>;
|
|
@@ -38,9 +41,6 @@ declare const defaultHTMLComponents: {} & {
|
|
|
38
41
|
del?: FC<react.DetailedHTMLProps<react.DelHTMLAttributes<HTMLModElement>, HTMLModElement>>;
|
|
39
42
|
ins?: FC<react.DetailedHTMLProps<react.InsHTMLAttributes<HTMLModElement>, HTMLModElement>>;
|
|
40
43
|
mark?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
41
|
-
small?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
42
|
-
sub?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
43
|
-
sup?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
44
44
|
code?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
45
45
|
pre?: FC<react.DetailedHTMLProps<react.HTMLAttributes<HTMLPreElement>, HTMLPreElement>>;
|
|
46
46
|
blockquote?: FC<react.DetailedHTMLProps<react.BlockquoteHTMLAttributes<HTMLQuoteElement>, HTMLQuoteElement>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLRendererPlugin.d.ts","names":[],"sources":["../../../src/html/HTMLRendererPlugin.tsx"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"HTMLRendererPlugin.d.ts","names":[],"sources":["../../../src/html/HTMLRendererPlugin.tsx"],"mappings":";;;;;KAUK,uBAAA;EACH,aAAA;EACA,OAAA,EAAS,OAAA;EACT,IAAA;EACA,MAAA,GAAS,MAAA;EACT,cAAA,GAAiB,MAAA;AAAA;AAAA,cAGN,kBAAA,EAAoB,EAAA,CAAG,uBAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { FC } from "react";
|
|
3
|
+
import { KeyPath } from "@intlayer/types/keyPath";
|
|
4
|
+
|
|
5
|
+
//#region src/markdown/MarkdownMetadataRendererInternal.d.ts
|
|
6
|
+
type MarkdownMetadataRendererProps = {
|
|
7
|
+
dictionaryKey: string;
|
|
8
|
+
keyPath: KeyPath[];
|
|
9
|
+
locale?: LocalesValues;
|
|
10
|
+
children: string;
|
|
11
|
+
metadataKeyPath: KeyPath[];
|
|
12
|
+
};
|
|
13
|
+
declare const MarkdownMetadataRendererInternal: FC<MarkdownMetadataRendererProps>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { MarkdownMetadataRendererInternal };
|
|
16
|
+
//# sourceMappingURL=MarkdownMetadataRendererInternal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownMetadataRendererInternal.d.ts","names":[],"sources":["../../../src/markdown/MarkdownMetadataRendererInternal.tsx"],"mappings":";;;;;KAYK,6BAAA;EACH,aAAA;EACA,OAAA,EAAS,OAAA;EACT,MAAA,GAAS,aAAA;EACT,QAAA;EACA,eAAA,EAAiB,OAAA;AAAA;AAAA,cAwEN,gCAAA,EAAkC,EAAA,CAC7C,6BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRendererPlugin.d.ts","names":[],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"MarkdownRendererPlugin.d.ts","names":[],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"mappings":";;;;;;;KAUK,2BAAA;EACH,aAAA;EACA,OAAA,EAAS,OAAA;EACT,MAAA,GAAS,aAAA;EACT,QAAA;EACA,OAAA,GAAU,uBAAA;EACV,UAAA,GAAa,cAAA;AAAA;AAAA,cAGF,sBAAA,EAAwB,EAAA,CAAG,2BAAA;AAAA,KAcnC,6BAAA,GAAgC,2BAAA;EACnC,eAAA,EAAiB,OAAA;AAAA;AAAA,cASN,wBAAA,EAA0B,EAAA,CAAG,6BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.d.ts","names":[],"sources":["../../src/plugins.tsx"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","names":[],"sources":["../../src/plugins.tsx"],"mappings":";;;;;;;;;;AA0CA;KAAY,gBAAA,MAAsB,CAAA,2BAC9B,YAAA,CAAa,CAAA;;cAIJ,mBAAA,EAAqB,OAAA;;;;KA4BtB,aAAA,MAAmB,CAAA;EAC7B,KAAA;EACA,GAAA;AAAA,IAEE,SAAA;;cAIS,gBAAA,EAAkB,OAAA;;AApC/B;;KAiEY,aAAA,MAAmB,CAAA;EAC7B,QAAA,EAAU,QAAA;EAAA,CACT,QAAA,CAAS,SAAA;EACV,MAAA;AAAA,uBAEqB,CAAA,qBAAsB,SAAA,IACvC,MAAA,EAAQ,CAAA,KACL,CAAA,OAAQ,CAAA,4BACT,YAAA,WACA,YAAA,CAAa,SAAA;;cA4BR,eAAA,EAAiB,OAAA;;;;KAkFlB,kBAAA,MAAwB,CAAA,kBAChC,YAAA;EAGI,QAAA,EAAU,oBAAA;EACV,GAAA,GAAM,UAAA,EAAY,cAAA,uBAAqC,SAAA;AAAA;;cAMlD,oBAAA,EAAsB,OAAA;AAAA,KA+EvB,YAAA,MAAkB,CAAA;EAC5B,QAAA,EAAU,QAAA;EAAA,CACT,QAAA,CAAS,QAAA;EACV,IAAA;EACA,QAAA;AAAA,IAEE,YAAA,CACE,CAAA;EAEE,GAAA,GAAM,UAAA,GAAa,cAAA,eAA6B,CAAA,MAAO,SAAA;EACvD,QAAA,EAAU,oBAAA,CAAqB,CAAA;AAAA;AAAA,cAK1B,cAAA,EAAgB,OAAA;;;;;;;;;;;;KAmCjB,cAAA,MAAoB,CAAA;EAC9B,QAAA,EAAU,QAAA;EAAA,CACT,QAAA,CAAS,IAAA;EACV,IAAA;AAAA,IAEE,YAAA,CACE,CAAA;EAEE,GAAA,GAAM,UAAA,GAAa,cAAA,eAA6B,CAAA,MAAO,SAAA;AAAA;;cAMlD,UAAA,EAAY,OAAA;;;;KAoCb,uBAAA,mBAA0C,aAAA;EACpD,SAAA,EAAW,aAAA,CAAc,CAAA;EACzB,iBAAA,EAAmB,gBAAA,CAAiB,CAAA;EACpC,cAAA,EAAgB,aAAA,CAAc,CAAA;EAC9B,aAAA,EAAe,YAAA,CAAa,CAAA;EAC5B,SAAA,EAAW,cAAA,CAAe,CAAA;AAAA;;;;AAnM5B;;KA2MY,uBAAA,GAA0B,IAAA,CACpC,yBAAA;EAGA,SAAA;EACA,iBAAA;EACA,aAAA;EACA,SAAA;EACA,cAAA;AAAA;AAAA,KAGU,oBAAA,cAEA,aAAA,GAAgB,eAAA,IACxB,sBAAA,CAAyB,CAAA,EAAG,uBAAA,EAAyB,CAAA;;;;;cAM5C,UAAA,GACX,MAAA,GAAS,aAAA,EACT,QAAA,eACC,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0-canary.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your React applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -115,14 +115,14 @@
|
|
|
115
115
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
116
116
|
},
|
|
117
117
|
"dependencies": {
|
|
118
|
-
"@intlayer/api": "8.
|
|
119
|
-
"@intlayer/config": "8.
|
|
120
|
-
"@intlayer/core": "8.
|
|
121
|
-
"@intlayer/dictionaries-entry": "8.
|
|
122
|
-
"@intlayer/editor": "8.
|
|
123
|
-
"@intlayer/editor-react": "8.
|
|
124
|
-
"@intlayer/types": "8.
|
|
125
|
-
"intlayer": "8.
|
|
118
|
+
"@intlayer/api": "8.4.0-canary.0",
|
|
119
|
+
"@intlayer/config": "8.4.0-canary.0",
|
|
120
|
+
"@intlayer/core": "8.4.0-canary.0",
|
|
121
|
+
"@intlayer/dictionaries-entry": "8.4.0-canary.0",
|
|
122
|
+
"@intlayer/editor": "8.4.0-canary.0",
|
|
123
|
+
"@intlayer/editor-react": "8.4.0-canary.0",
|
|
124
|
+
"@intlayer/types": "8.4.0-canary.0",
|
|
125
|
+
"intlayer": "8.4.0-canary.0"
|
|
126
126
|
},
|
|
127
127
|
"devDependencies": {
|
|
128
128
|
"@craco/types": "7.1.0",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../client/IntlayerProvider.cjs`);let t=require(`@intlayer/types/nodeType`),n=require(`react`),r=require(`@intlayer/core/utils`),i=require(`@intlayer/editor`),a=require(`@intlayer/editor-react`),o=require(`react/jsx-runtime`);const s=({children:e,dictionaryKey:s,keyPath:c})=>{let{focusedContent:l,setFocusedContent:u}=(0,a.useFocusDictionary)(),{postMessage:d,senderId:f}=(0,a.useCommunicator)(),p=(0,n.useRef)(null),m=c.filter(e=>e.type!==t.NodeType.Translation),h=(l?.dictionaryKey===s&&(l?.keyPath?.length??0)>0&&(0,r.isSameKeyPath)(l?.keyPath??[],m))??!1;return(0,n.useEffect)(()=>{let e=p.current;if(!e)return;let t=()=>{u({dictionaryKey:s,keyPath:m})},n=()=>{d({type:`${i.MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,data:{dictionaryKey:s,keyPath:m},senderId:f})},r=()=>{d({type:`${i.MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,data:null,senderId:f})};return e.addEventListener(`intlayer:press`,t),e.addEventListener(`intlayer:hover`,n),e.addEventListener(`intlayer:unhover`,r),()=>{e.removeEventListener(`intlayer:press`,t),e.removeEventListener(`intlayer:hover`,n),e.removeEventListener(`intlayer:unhover`,r)}}),(0,o.jsx)(`intlayer-content-selector`,{ref:p,"is-selecting":h||void 0,children:e})},c=({children:t,...n})=>{let{enabled:r}=(0,a.useEditorEnabled)(),{disableEditor:i}=e.useIntlayerContext();return r&&!i?(0,o.jsx)(s,{...n,children:t}):t};exports.ContentSelectorRenderer=c;
|
|
2
|
-
//# sourceMappingURL=ContentSelectorWrapper.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.cjs","names":["NodeType","MessageKey","useIntlayerContext"],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport type { NodeProps } from '@intlayer/core/interpreter';\nimport { isSameKeyPath } from '@intlayer/core/utils';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n useCommunicator,\n useEditorEnabled,\n useFocusDictionary,\n} from '@intlayer/editor-react';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport { type FC, type HTMLAttributes, useEffect, useRef } from 'react';\nimport { useIntlayerContext } from '../client';\n\n// JSX declaration for the Lit web component\ndeclare global {\n namespace JSX {\n interface IntrinsicElements {\n 'intlayer-content-selector': React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement> & {\n 'is-selecting'?: boolean;\n 'press-duration'?: number;\n },\n HTMLElement\n >;\n }\n }\n}\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { postMessage, senderId } = useCommunicator();\n const ref = useRef<HTMLElement>(null);\n\n const filteredKeyPath = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n const isSelected =\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], filteredKeyPath)) ??\n false;\n\n // React 18: web component custom events are not forwarded via JSX — use addEventListener\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n\n const handlePress = () => {\n setFocusedContent({ dictionaryKey, keyPath: filteredKeyPath });\n };\n\n const handleHover = () => {\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: { dictionaryKey, keyPath: filteredKeyPath },\n senderId,\n });\n };\n\n const handleUnhover = () => {\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: null,\n senderId,\n });\n };\n\n el.addEventListener('intlayer:press', handlePress);\n el.addEventListener('intlayer:hover', handleHover);\n el.addEventListener('intlayer:unhover', handleUnhover);\n return () => {\n el.removeEventListener('intlayer:press', handlePress);\n el.removeEventListener('intlayer:hover', handleHover);\n el.removeEventListener('intlayer:unhover', handleUnhover);\n };\n });\n\n return (\n // @ts-ignore — ref typing for custom elements\n <intlayer-content-selector ref={ref} is-selecting={isSelected || undefined}>\n {children}\n </intlayer-content-selector>\n );\n};\n\nexport const ContentSelectorRenderer: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return children;\n};\n"],"mappings":"+WAgCA,MAAM,GAAkE,CACtE,WACA,gBACA,aACI,CACJ,GAAM,CAAE,iBAAgB,sBAAA,EAAA,EAAA,qBAA0C,CAC5D,CA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`../_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/editor-react`),t=require(`react/jsx-runtime`);const n=({children:n})=>(0,t.jsx)(e.EditorProvider,{mode:`client`,children:n});exports.IntlayerEditorProvider=n;
|
|
2
|
-
//# sourceMappingURL=IntlayerEditorProvider.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerEditorProvider.cjs","names":["EditorProvider"],"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport { EditorProvider } from '@intlayer/editor-react';\nimport type { FC, PropsWithChildren } from 'react';\n\n/**\n * Wraps the application with the Intlayer editor provider in client mode.\n * All configuration (URLs, origins) is read from @intlayer/config/built.\n */\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => (\n <EditorProvider mode=\"client\">{children}</EditorProvider>\n);\n"],"mappings":"oMASA,MAAa,GAAiD,CAAE,eAC9D,EAAA,EAAA,KAACA,EAAAA,eAAD,CAAgB,KAAK,SAAU,WAA0B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./ContentSelectorWrapper.cjs`);exports.ContentSelectorRenderer=e.ContentSelectorRenderer;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./ContentSelectorWrapper.cjs`);let t=require(`@intlayer/core/interpreter`),n=require(`react`),r=require(`@intlayer/editor-react`);const i=({dictionaryKey:e,keyPath:t,children:n})=>{let i=(0,r.useEditedContentActions)();return i?i.getEditedContentValue(e,t)??n:n},a=r=>{let a=i(r);if(typeof a==`object`){let i=(0,t.getContent)(a,{...r,locale:r.locale},(0,t.getBasePlugins)(r.locale));return typeof i==`string`?(0,n.createElement)(e.ContentSelectorRenderer,{...r,key:r.children},i):(console.error(`Incorrect edited content format. Content type: ${typeof i}. Expected string. Value ${JSON.stringify(i)}`),(0,n.createElement)(e.ContentSelectorRenderer,{...r,key:r.children},r.children))}return(0,n.createElement)(e.ContentSelectorRenderer,{...r,key:r.children},a)};exports.EditedContentRenderer=a,exports.useEditedContentRenderer=i;
|
|
2
|
-
//# sourceMappingURL=useEditedContentRenderer.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEditedContentRenderer.cjs","names":["ContentSelectorRenderer"],"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["'use client';\n\nimport { getBasePlugins, getContent } from '@intlayer/core/interpreter';\nimport { useEditedContentActions } from '@intlayer/editor-react';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { FC } from 'react';\nimport { ContentSelectorRenderer } from './ContentSelectorWrapper';\n\ntype EditedContentRendererProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n children: string;\n locale?: Locale;\n};\n\nexport const useEditedContentRenderer = ({\n dictionaryKey,\n keyPath,\n children,\n}: EditedContentRendererProps) => {\n const editedContentContext = useEditedContentActions();\n\n if (editedContentContext) {\n const editedValue = editedContentContext.getEditedContentValue(\n dictionaryKey,\n keyPath\n ) as string;\n\n const value = editedValue ?? children;\n\n return value;\n }\n\n return children;\n};\n\nexport const EditedContentRenderer: FC<EditedContentRendererProps> = (\n props\n) => {\n const content = useEditedContentRenderer(props);\n\n if (typeof content === 'object') {\n const transformedEditedContent = getContent(\n content,\n { ...props, locale: props.locale },\n getBasePlugins(props.locale)\n );\n\n if (typeof transformedEditedContent !== 'string') {\n console.error(\n `Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`\n );\n\n return (\n <ContentSelectorRenderer {...props} key={props.children}>\n {props.children}\n </ContentSelectorRenderer>\n );\n }\n\n return (\n <ContentSelectorRenderer {...props} key={props.children}>\n {transformedEditedContent}\n </ContentSelectorRenderer>\n );\n }\n\n return (\n <ContentSelectorRenderer {...props} key={props.children}>\n {content}\n </ContentSelectorRenderer>\n );\n};\n"],"mappings":"gRAgBA,MAAa,GAA4B,CACvC,gBACA,UACA,cACgC,CAChC,IAAM,GAAA,EAAA,EAAA,0BAAgD,CAatD,OAXI,EACkB,EAAqB,sBACvC,EACA,EACD,EAE4B,EAKxB,GAGI,EACX,GACG,CACH,IAAM,EAAU,EAAyB,EAAM,CAE/C,GAAI,OAAO,GAAY,SAAU,CAC/B,IAAM,GAAA,EAAA,EAAA,YACJ,EACA,CAAE,GAAG,EAAO,OAAQ,EAAM,OAAQ,EAAA,EAAA,EAAA,gBACnB,EAAM,OAAO,CAC7B,CAcD,OAZI,OAAO,GAA6B,UAatC,EAAA,EAAA,eAACA,EAAAA,wBAAD,CAAyB,GAAI,EAAO,IAAK,EAAM,SAErB,CADvB,EACuB,EAd1B,QAAQ,MACN,kDAAkD,OAAO,EAAyB,2BAA2B,KAAK,UAAU,EAAyB,GACtJ,EAGC,EAAA,EAAA,eAACA,EAAAA,wBAAD,CAAyB,GAAI,EAAO,IAAK,EAAM,SAErB,CADvB,EAAM,SACiB,EAWhC,OACE,EAAA,EAAA,eAACA,EAAAA,wBAAD,CAAyB,GAAI,EAAO,IAAK,EAAM,SAErB,CADvB,EACuB"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";import{useIntlayerContext as e}from"../client/IntlayerProvider.mjs";import{NodeType as t}from"@intlayer/types/nodeType";import{useEffect as n,useRef as r}from"react";import{isSameKeyPath as i}from"@intlayer/core/utils";import{MessageKey as a}from"@intlayer/editor";import{useCommunicator as o,useEditorEnabled as s,useFocusDictionary as c}from"@intlayer/editor-react";import{jsx as l}from"react/jsx-runtime";const u=({children:e,dictionaryKey:s,keyPath:u})=>{let{focusedContent:d,setFocusedContent:f}=c(),{postMessage:p,senderId:m}=o(),h=r(null),g=u.filter(e=>e.type!==t.Translation),_=(d?.dictionaryKey===s&&(d?.keyPath?.length??0)>0&&i(d?.keyPath??[],g))??!1;return n(()=>{let e=h.current;if(!e)return;let t=()=>{f({dictionaryKey:s,keyPath:g})},n=()=>{p({type:`${a.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,data:{dictionaryKey:s,keyPath:g},senderId:m})},r=()=>{p({type:`${a.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,data:null,senderId:m})};return e.addEventListener(`intlayer:press`,t),e.addEventListener(`intlayer:hover`,n),e.addEventListener(`intlayer:unhover`,r),()=>{e.removeEventListener(`intlayer:press`,t),e.removeEventListener(`intlayer:hover`,n),e.removeEventListener(`intlayer:unhover`,r)}}),l(`intlayer-content-selector`,{ref:h,"is-selecting":_||void 0,children:e})},d=({children:t,...n})=>{let{enabled:r}=s(),{disableEditor:i}=e();return r&&!i?l(u,{...n,children:t}):t};export{d as ContentSelectorRenderer};
|
|
2
|
-
//# sourceMappingURL=ContentSelectorWrapper.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.mjs","names":[],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport type { NodeProps } from '@intlayer/core/interpreter';\nimport { isSameKeyPath } from '@intlayer/core/utils';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n useCommunicator,\n useEditorEnabled,\n useFocusDictionary,\n} from '@intlayer/editor-react';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport { type FC, type HTMLAttributes, useEffect, useRef } from 'react';\nimport { useIntlayerContext } from '../client';\n\n// JSX declaration for the Lit web component\ndeclare global {\n namespace JSX {\n interface IntrinsicElements {\n 'intlayer-content-selector': React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement> & {\n 'is-selecting'?: boolean;\n 'press-duration'?: number;\n },\n HTMLElement\n >;\n }\n }\n}\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { postMessage, senderId } = useCommunicator();\n const ref = useRef<HTMLElement>(null);\n\n const filteredKeyPath = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n const isSelected =\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], filteredKeyPath)) ??\n false;\n\n // React 18: web component custom events are not forwarded via JSX — use addEventListener\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n\n const handlePress = () => {\n setFocusedContent({ dictionaryKey, keyPath: filteredKeyPath });\n };\n\n const handleHover = () => {\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: { dictionaryKey, keyPath: filteredKeyPath },\n senderId,\n });\n };\n\n const handleUnhover = () => {\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: null,\n senderId,\n });\n };\n\n el.addEventListener('intlayer:press', handlePress);\n el.addEventListener('intlayer:hover', handleHover);\n el.addEventListener('intlayer:unhover', handleUnhover);\n return () => {\n el.removeEventListener('intlayer:press', handlePress);\n el.removeEventListener('intlayer:hover', handleHover);\n el.removeEventListener('intlayer:unhover', handleUnhover);\n };\n });\n\n return (\n // @ts-ignore — ref typing for custom elements\n <intlayer-content-selector ref={ref} is-selecting={isSelected || undefined}>\n {children}\n </intlayer-content-selector>\n );\n};\n\nexport const ContentSelectorRenderer: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return children;\n};\n"],"mappings":"qaAgCA,MAAM,GAAkE,CACtE,WACA,gBACA,aACI,CACJ,GAAM,CAAE,iBAAgB,qBAAsB,GAAoB,CAC5D,CAAE,cAAa,YAAa,GAAiB,CAC7C,EAAM,EAAoB,KAAK,CAE/B,EAAkB,EAAQ,OAC7B,GAAQ,EAAI,OAAS,EAAS,YAChC,CAEK,GACH,GAAgB,gBAAkB,IAChC,GAAgB,SAAS,QAAU,GAAK,GACzC,EAAc,GAAgB,SAAW,EAAE,CAAE,EAAgB,GAC/D,GAqCF,OAlCA,MAAgB,CACd,IAAM,EAAK,EAAI,QACf,GAAI,CAAC,EAAI,OAET,IAAM,MAAoB,CACxB,EAAkB,CAAE,gBAAe,QAAS,EAAiB,CAAC,EAG1D,MAAoB,CACxB,EAAY,CACV,KAAM,GAAG,EAAW,iCAAiC,OACrD,KAAM,CAAE,gBAAe,QAAS,EAAiB,CACjD,WACD,CAAC,EAGE,MAAsB,CAC1B,EAAY,CACV,KAAM,GAAG,EAAW,iCAAiC,OACrD,KAAM,KACN,WACD,CAAC,EAMJ,OAHA,EAAG,iBAAiB,iBAAkB,EAAY,CAClD,EAAG,iBAAiB,iBAAkB,EAAY,CAClD,EAAG,iBAAiB,mBAAoB,EAAc,KACzC,CACX,EAAG,oBAAoB,iBAAkB,EAAY,CACrD,EAAG,oBAAoB,iBAAkB,EAAY,CACrD,EAAG,oBAAoB,mBAAoB,EAAc,GAE3D,CAIA,EAAC,4BAAD,CAAgC,MAAK,eAAc,GAAc,IAAA,GAC9D,WACyB,CAAA,EAInB,GAA4D,CACvE,WACA,GAAG,KACC,CACJ,GAAM,CAAE,WAAY,GAAkB,CAChC,CAAE,iBAAkB,GAAoB,CAU9C,OARI,GAAW,CAAC,EAEZ,EAAC,EAAD,CAA+B,GAAI,EAChC,WAC6B,CAAA,CAI7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerEditorProvider.mjs","names":[],"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport { EditorProvider } from '@intlayer/editor-react';\nimport type { FC, PropsWithChildren } from 'react';\n\n/**\n * Wraps the application with the Intlayer editor provider in client mode.\n * All configuration (URLs, origins) is read from @intlayer/config/built.\n */\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => (\n <EditorProvider mode=\"client\">{children}</EditorProvider>\n);\n"],"mappings":"6GASA,MAAa,GAAiD,CAAE,cAC9D,EAAC,EAAD,CAAgB,KAAK,SAAU,WAA0B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ContentSelectorRenderer as e}from"./ContentSelectorWrapper.mjs";export{e as ContentSelectorRenderer};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";import{ContentSelectorRenderer as e}from"./ContentSelectorWrapper.mjs";import{getBasePlugins as t,getContent as n}from"@intlayer/core/interpreter";import{createElement as r}from"react";import{useEditedContentActions as i}from"@intlayer/editor-react";const a=({dictionaryKey:e,keyPath:t,children:n})=>{let r=i();return r?r.getEditedContentValue(e,t)??n:n},o=i=>{let o=a(i);if(typeof o==`object`){let a=n(o,{...i,locale:i.locale},t(i.locale));return typeof a==`string`?r(e,{...i,key:i.children},a):(console.error(`Incorrect edited content format. Content type: ${typeof a}. Expected string. Value ${JSON.stringify(a)}`),r(e,{...i,key:i.children},i.children))}return r(e,{...i,key:i.children},o)};export{o as EditedContentRenderer,a as useEditedContentRenderer};
|
|
2
|
-
//# sourceMappingURL=useEditedContentRenderer.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEditedContentRenderer.mjs","names":[],"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["'use client';\n\nimport { getBasePlugins, getContent } from '@intlayer/core/interpreter';\nimport { useEditedContentActions } from '@intlayer/editor-react';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { FC } from 'react';\nimport { ContentSelectorRenderer } from './ContentSelectorWrapper';\n\ntype EditedContentRendererProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n children: string;\n locale?: Locale;\n};\n\nexport const useEditedContentRenderer = ({\n dictionaryKey,\n keyPath,\n children,\n}: EditedContentRendererProps) => {\n const editedContentContext = useEditedContentActions();\n\n if (editedContentContext) {\n const editedValue = editedContentContext.getEditedContentValue(\n dictionaryKey,\n keyPath\n ) as string;\n\n const value = editedValue ?? children;\n\n return value;\n }\n\n return children;\n};\n\nexport const EditedContentRenderer: FC<EditedContentRendererProps> = (\n props\n) => {\n const content = useEditedContentRenderer(props);\n\n if (typeof content === 'object') {\n const transformedEditedContent = getContent(\n content,\n { ...props, locale: props.locale },\n getBasePlugins(props.locale)\n );\n\n if (typeof transformedEditedContent !== 'string') {\n console.error(\n `Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`\n );\n\n return (\n <ContentSelectorRenderer {...props} key={props.children}>\n {props.children}\n </ContentSelectorRenderer>\n );\n }\n\n return (\n <ContentSelectorRenderer {...props} key={props.children}>\n {transformedEditedContent}\n </ContentSelectorRenderer>\n );\n }\n\n return (\n <ContentSelectorRenderer {...props} key={props.children}>\n {content}\n </ContentSelectorRenderer>\n );\n};\n"],"mappings":"uQAgBA,MAAa,GAA4B,CACvC,gBACA,UACA,cACgC,CAChC,IAAM,EAAuB,GAAyB,CAatD,OAXI,EACkB,EAAqB,sBACvC,EACA,EACD,EAE4B,EAKxB,GAGI,EACX,GACG,CACH,IAAM,EAAU,EAAyB,EAAM,CAE/C,GAAI,OAAO,GAAY,SAAU,CAC/B,IAAM,EAA2B,EAC/B,EACA,CAAE,GAAG,EAAO,OAAQ,EAAM,OAAQ,CAClC,EAAe,EAAM,OAAO,CAC7B,CAcD,OAZI,OAAO,GAA6B,SAatC,EAAC,EAAD,CAAyB,GAAI,EAAO,IAAK,EAAM,SAErB,CADvB,EACuB,EAd1B,QAAQ,MACN,kDAAkD,OAAO,EAAyB,2BAA2B,KAAK,UAAU,EAAyB,GACtJ,CAGC,EAAC,EAAD,CAAyB,GAAI,EAAO,IAAK,EAAM,SAErB,CADvB,EAAM,SACiB,EAWhC,OACE,EAAC,EAAD,CAAyB,GAAI,EAAO,IAAK,EAAM,SAErB,CADvB,EACuB"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { NodeProps } from "@intlayer/core/interpreter";
|
|
2
|
-
import { FC, HTMLAttributes } from "react";
|
|
3
|
-
|
|
4
|
-
//#region src/editor/ContentSelectorWrapper.d.ts
|
|
5
|
-
declare global {
|
|
6
|
-
namespace JSX {
|
|
7
|
-
interface IntrinsicElements {
|
|
8
|
-
'intlayer-content-selector': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
|
|
9
|
-
'is-selecting'?: boolean;
|
|
10
|
-
'press-duration'?: number;
|
|
11
|
-
}, HTMLElement>;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
type ContentSelectorWrapperProps = NodeProps & Omit<HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
16
|
-
declare const ContentSelectorRenderer: FC<ContentSelectorWrapperProps>;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { ContentSelectorRenderer, ContentSelectorWrapperProps };
|
|
19
|
-
//# sourceMappingURL=ContentSelectorWrapper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.d.ts","names":[],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"mappings":";;;;QAeQ,MAAA;EAAA,UACI,GAAA;IAAA,UACE,iBAAA;MACR,2BAAA,EAA6B,KAAA,CAAM,iBAAA,CACjC,KAAA,CAAM,cAAA,CAAe,WAAA;QACnB,cAAA;QACA,gBAAA;MAAA,GAEF,WAAA;IAAA;EAAA;AAAA;AAAA,KAMI,2BAAA,GAA8B,SAAA,GACxC,IAAA,CAAK,cAAA,CAAe,cAAA;AAAA,cAgET,uBAAA,EAAyB,EAAA,CAAG,2BAAA"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from "react";
|
|
2
|
-
|
|
3
|
-
//#region src/editor/IntlayerEditorProvider.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Wraps the application with the Intlayer editor provider in client mode.
|
|
6
|
-
* All configuration (URLs, origins) is read from @intlayer/config/built.
|
|
7
|
-
*/
|
|
8
|
-
declare const IntlayerEditorProvider: FC<PropsWithChildren>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { IntlayerEditorProvider };
|
|
11
|
-
//# sourceMappingURL=IntlayerEditorProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerEditorProvider.d.ts","names":[],"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"mappings":";;;;;AASA;;cAAa,sBAAA,EAAwB,EAAA,CAAG,iBAAA"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { FC } from "react";
|
|
2
|
-
import { Locale } from "@intlayer/types/allLocales";
|
|
3
|
-
import { KeyPath } from "@intlayer/types/keyPath";
|
|
4
|
-
|
|
5
|
-
//#region src/editor/useEditedContentRenderer.d.ts
|
|
6
|
-
type EditedContentRendererProps = {
|
|
7
|
-
dictionaryKey: string;
|
|
8
|
-
keyPath: KeyPath[];
|
|
9
|
-
children: string;
|
|
10
|
-
locale?: Locale;
|
|
11
|
-
};
|
|
12
|
-
declare const useEditedContentRenderer: ({
|
|
13
|
-
dictionaryKey,
|
|
14
|
-
keyPath,
|
|
15
|
-
children
|
|
16
|
-
}: EditedContentRendererProps) => string;
|
|
17
|
-
declare const EditedContentRenderer: FC<EditedContentRendererProps>;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { EditedContentRenderer, useEditedContentRenderer };
|
|
20
|
-
//# sourceMappingURL=useEditedContentRenderer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEditedContentRenderer.d.ts","names":[],"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"mappings":";;;;;KASK,0BAAA;EACH,aAAA;EACA,OAAA,EAAS,OAAA;EACT,QAAA;EACA,MAAA,GAAS,MAAA;AAAA;AAAA,cAGE,wBAAA;EAA4B,aAAA;EAAA,OAAA;EAAA;AAAA,GAItC,0BAAA;AAAA,cAiBU,qBAAA,EAAuB,EAAA,CAAG,0BAAA"}
|