react-intlayer 8.6.2 → 8.6.4
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 +6 -4
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -2
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -2
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -2
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +1 -2
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +1 -2
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelector.cjs +6 -2
- package/dist/cjs/editor/ContentSelector.cjs.map +1 -1
- package/dist/cjs/editor/useEditor.cjs +2 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +47 -14
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs +1 -2
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/format/useIntl.cjs +1 -2
- package/dist/cjs/server/format/useIntl.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs +1 -2
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +1 -2
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/server/useLocale.cjs +1 -2
- package/dist/cjs/server/useLocale.cjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +6 -3
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +2 -2
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +2 -2
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +2 -2
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +2 -2
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs +2 -2
- package/dist/esm/client/useRewriteURL.mjs.map +1 -1
- package/dist/esm/editor/ContentSelector.mjs +6 -2
- package/dist/esm/editor/ContentSelector.mjs.map +1 -1
- package/dist/esm/editor/useEditor.mjs +2 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -1
- package/dist/esm/plugins.mjs +48 -14
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +2 -2
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/format/useIntl.mjs +2 -2
- package/dist/esm/server/format/useIntl.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs +2 -2
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs +2 -2
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/server/useLocale.mjs +2 -2
- package/dist/esm/server/useLocale.mjs.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts.map +1 -1
- package/dist/types/editor/ContentSelector.d.ts.map +1 -1
- package/dist/types/editor/useEditor.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRenderer.d.ts +1 -1
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -5,9 +5,9 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
|
5
5
|
const require_editor_EditorProvider = require('../editor/EditorProvider.cjs');
|
|
6
6
|
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
7
7
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
9
8
|
let react = require("react");
|
|
10
9
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
let _intlayer_config_client = require("@intlayer/config/client");
|
|
11
11
|
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
12
12
|
|
|
13
13
|
//#region src/client/IntlayerProvider.tsx
|
|
@@ -15,7 +15,7 @@ let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
|
15
15
|
* Context that stores the current locale on the client side.
|
|
16
16
|
*/
|
|
17
17
|
const IntlayerClientContext = (0, react.createContext)({
|
|
18
|
-
locale: require_client_useLocaleStorage.localeInStorage ?? _intlayer_config_built.
|
|
18
|
+
locale: require_client_useLocaleStorage.localeInStorage ?? _intlayer_config_built.internationalization?.defaultLocale,
|
|
19
19
|
setLocale: () => null,
|
|
20
20
|
isCookieEnabled: true
|
|
21
21
|
});
|
|
@@ -34,12 +34,14 @@ const useIntlayerContext = () => (0, react.useContext)(IntlayerClientContext) ??
|
|
|
34
34
|
* @returns The provider component.
|
|
35
35
|
*/
|
|
36
36
|
const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLocaleProp, children, setLocale: setLocaleProp, disableEditor, isCookieEnabled }) => {
|
|
37
|
-
const {
|
|
38
|
-
const { locales: availableLocales, defaultLocale: defaultLocaleConfig } = internationalization ?? {};
|
|
37
|
+
const { locales: availableLocales, defaultLocale: defaultLocaleConfig } = _intlayer_config_built.internationalization ?? {};
|
|
39
38
|
const [currentLocale, setCurrentLocale] = (0, react.useState)(localeProp ?? require_client_useLocaleStorage.localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig);
|
|
40
39
|
(0, react.useEffect)(() => {
|
|
41
40
|
if (localeProp && localeProp !== currentLocale) setCurrentLocale(localeProp);
|
|
42
41
|
}, [localeProp]);
|
|
42
|
+
(0, react.useEffect)(() => {
|
|
43
|
+
(0, _intlayer_config_client.setIntlayerIdentifier)();
|
|
44
|
+
}, []);
|
|
43
45
|
const setLocaleBase = (newLocale) => {
|
|
44
46
|
if (currentLocale.toString() === newLocale.toString()) return;
|
|
45
47
|
if (!availableLocales?.map(String).includes(newLocale)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.cjs","names":["localeInStorage","
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.cjs","names":["localeInStorage","internationalization","EditorProvider"],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\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 ?? 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 { 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 useEffect(() => {\n setIntlayerIdentifier();\n }, []);\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":";;;;;;;;;;;;;;;;AA2BA,MAAa,iDAAqD;CAChE,QAAQA,mDAAmBC,6CAAsB;CACjD,iBAAiB;CACjB,iBAAiB;CAClB,CAAC;;;;;;AAOF,MAAa,iDAAsC,sBAAsB,IAAI,EAAE;;;;;;;;;AAoC/E,MAAa,2BAAsD,EACjE,QAAQ,YACR,eAAe,mBACf,UACA,WAAW,eACX,eACA,sBACI;CACJ,MAAM,EAAE,SAAS,kBAAkB,eAAe,wBAChDA,+CAAwB,EAAE;CAK5B,MAAM,CAAC,eAAe,wCAFpB,cAAcD,mDAAmB,qBAAqB,oBAGhB;AAGxC,4BAAgB;AACd,MAAI,cAAc,eAAe,cAC/B,kBAAiB,WAAW;IAE7B,CAAC,WAAW,CAAC;AAEhB,4BAAgB;AACd,sDAAuB;IACtB,EAAE,CAAC;CAEN,MAAM,iBAAiB,cAA6B;AAClD,MAAI,cAAc,UAAU,KAAK,UAAU,UAAU,CAAE;AAEvD,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AACtD,WAAQ,MAAM,UAAU,UAAU,mBAAmB;AACrD;;AAGF,mBAAiB,UAAU;AAC3B,qDAAmB,WAAW,gBAAgB;;CAGhD,MAAM,YAAY,iBAAiB;CAGnC,MAAM,iEAAgC,cAAc;AAEpD,QACE,2CAAC,sBAAsB,UAAvB;EACE,OAAO;GACL,QAAQ;GACR;GACA;GACD;EAEA;EAC8B;;;;;;;;;;;;;;;;;;;;;;AAwBrC,MAAa,oBAA+C,EAC1D,UACA,GAAG,YAEH,4CAAC,yBAAD;CAAyB,GAAI;WAA7B,CACE,2CAACE,8CAAD,EAAkB,GACjB,SACuB"}
|
|
@@ -5,7 +5,6 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
|
5
5
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
6
|
const require_client_useDictionary = require('./useDictionary.cjs');
|
|
7
7
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
9
8
|
let react = require("react");
|
|
10
9
|
|
|
11
10
|
//#region src/client/useDictionaryAsync.ts
|
|
@@ -16,7 +15,7 @@ let react = require("react");
|
|
|
16
15
|
*/
|
|
17
16
|
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
18
17
|
const { locale: currentLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
19
|
-
const localeTarget = (0, react.useMemo)(() => locale ?? currentLocale ?? _intlayer_config_built.
|
|
18
|
+
const localeTarget = (0, react.useMemo)(() => locale ?? currentLocale ?? _intlayer_config_built.internationalization.defaultLocale, [currentLocale, locale]);
|
|
20
19
|
return require_client_useDictionary.useDictionary(await (0, react.useMemo)(async () => await dictionaryPromise[localeTarget]?.(), [dictionaryPromise, localeTarget]), localeTarget);
|
|
21
20
|
};
|
|
22
21
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.cjs","names":["IntlayerClientContext","
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.cjs","names":["IntlayerClientContext","internationalization","useDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const localeTarget = useMemo(\n () => locale ?? currentLocale ?? internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () =>\n (await dictionaryPromise[\n localeTarget as keyof typeof dictionaryPromise\n ]?.()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L) as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAa,qBAAqB,OAIhC,mBACA,WACe;CACf,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB,IAAI,EAAE;CAEzE,MAAM,wCACE,UAAU,iBAAiBC,4CAAqB,eACtD,CAAC,eAAe,OAAO,CACxB;AAUD,QAAOC,2CARY,yBACjB,YACG,MAAM,kBACL,iBACG,EACP,CAAC,mBAAmB,aAAa,CAClC,EAEsC,aAAkB"}
|
|
@@ -6,7 +6,6 @@ const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
|
6
6
|
const require_client_useDictionary = require('./useDictionary.cjs');
|
|
7
7
|
const require_client_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
8
8
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
9
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
10
9
|
let react = require("react");
|
|
11
10
|
|
|
12
11
|
//#region src/client/useDictionaryDynamic.ts
|
|
@@ -17,7 +16,7 @@ let react = require("react");
|
|
|
17
16
|
*/
|
|
18
17
|
const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
|
|
19
18
|
const { locale: currentLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
20
|
-
const localeTarget = (0, react.useMemo)(() => locale ?? currentLocale ?? _intlayer_config_built.
|
|
19
|
+
const localeTarget = (0, react.useMemo)(() => locale ?? currentLocale ?? _intlayer_config_built.internationalization.defaultLocale, [currentLocale, locale]);
|
|
21
20
|
return require_client_useDictionary.useDictionary(require_client_useLoadDynamic.useLoadDynamic(`${String(key)}.${localeTarget}`, dictionaryPromise[localeTarget]?.()), localeTarget);
|
|
22
21
|
};
|
|
23
22
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["IntlayerClientContext","
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["IntlayerClientContext","internationalization","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n const localeTarget = useMemo(\n () => locale ?? currentLocale ?? internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,MAAa,wBAIX,mBACA,KACA,WACG;CACH,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB,IAAI,EAAE;CACzE,MAAM,wCACE,UAAU,iBAAiBC,4CAAqB,eACtD,CAAC,eAAe,OAAO,CACxB;AAOD,QAAOC,2CALYC,6CACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBACjB,kBAA0B,iBAAiB,CAC7C,EAEgC,aAAa"}
|
|
@@ -5,7 +5,6 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
|
5
5
|
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
6
6
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
7
7
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
9
8
|
let react = require("react");
|
|
10
9
|
|
|
11
10
|
//#region src/client/useLocale.ts
|
|
@@ -33,7 +32,7 @@ let react = require("react");
|
|
|
33
32
|
* ```
|
|
34
33
|
*/
|
|
35
34
|
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
36
|
-
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.
|
|
35
|
+
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
|
|
37
36
|
const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
38
37
|
return {
|
|
39
38
|
locale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["internationalization","IntlayerClientContext"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\ntype UseLocaleResult = {\n locale: LocalesValues;\n defaultLocale: LocalesValues;\n availableLocales: LocalesValues[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * Client-side hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'react-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext) ?? {};\n\n const setLocale = useCallback(\n (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale as DeclaredLocales);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAsB;CAC1C,MAAM,EAAE,eAAe,SAAS,qBAC9BA,+CAAwB,EAAE;CAE5B,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,iDACJC,sDAAsB,IAAI,EAAE;AAmB3C,QAAO;EACL;EACA;EACA;EACA,mCApBC,WAA0B;AACzB,OAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,OAAO,EAAE;AACnD,YAAQ,MAAM,UAAU,OAAO,mBAAmB;AAClD;;AAGF,kBAAe,OAAO;AACtB,sDACE,QACA,mBAAmB,0BAA0B,KAC9C;AACD,oBAAiB,OAA0B;KAE7C;GAAC;GAAkB;GAAgB;GAAgB;GAAgB,CACpE;EAOA"}
|
|
@@ -4,11 +4,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
5
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
6
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
7
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
8
7
|
let react = require("react");
|
|
9
8
|
|
|
10
9
|
//#region src/client/useLocaleBase.ts
|
|
11
|
-
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.
|
|
10
|
+
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization;
|
|
12
11
|
/**
|
|
13
12
|
* On the client side, hook to get the current locale and all related fields
|
|
14
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleBase.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useLocaleBase.cjs","names":["internationalization","IntlayerClientContext"],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } = internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext) ?? {};\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;AAMA,MAAM,EAAE,eAAe,SAAS,qBAAqBA;;;;AAKrD,MAAa,sBAAsB;CACjC,MAAM,EAAE,QAAQ,oCAAyBC,sDAAsB,IAAI,EAAE;AAErE,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
5
|
const require_client_useLocale = require('./useLocale.cjs');
|
|
6
6
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
7
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
8
7
|
let react = require("react");
|
|
9
8
|
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
10
9
|
|
|
@@ -29,7 +28,7 @@ let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
|
29
28
|
*/
|
|
30
29
|
const useRewriteURL = () => {
|
|
31
30
|
const { locale } = require_client_useLocale.useLocale();
|
|
32
|
-
const rewrite = _intlayer_config_built.
|
|
31
|
+
const rewrite = _intlayer_config_built.routing?.rewrite;
|
|
33
32
|
(0, react.useEffect)(() => {
|
|
34
33
|
if (typeof window === "undefined" || !rewrite) return;
|
|
35
34
|
const pathname = window.location.pathname;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRewriteURL.cjs","names":["useLocale","
|
|
1
|
+
{"version":3,"file":"useRewriteURL.cjs","names":["useLocale","routing"],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["'use client';\n\nimport { routing } from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useEffect } from 'react';\nimport { useLocale } from './useLocale';\n\n/**\n * Client-side hook to manage URL rewrites without triggering a router navigation.\n * It uses `window.history.replaceState` to update the URL in the address bar.\n *\n * This hook is useful to \"prettify\" the URL when the user lands on a canonical path\n * that has a localized alias defined in `intlayer.config.ts`.\n *\n * @example\n * ```tsx\n * import { useRewriteURL } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * useRewriteURL();\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport const useRewriteURL = (): void => {\n const { locale } = useLocale();\n const rewrite = routing?.rewrite;\n\n useEffect(() => {\n if (typeof window === 'undefined' || !rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(pathname, locale as Locale, rewrite);\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n }, [locale, rewrite]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,sBAA4B;CACvC,MAAM,EAAE,WAAWA,oCAAW;CAC9B,MAAM,UAAUC,gCAAS;AAEzB,4BAAgB;AACd,MAAI,OAAO,WAAW,eAAe,CAAC,QAAS;EAE/C,MAAM,WAAW,OAAO,SAAS;EACjC,MAAM,6DAA4B,UAAU,QAAkB,QAAQ;AAEtE,MAAI,cAAc,eAAe,SAC/B,QAAO,QAAQ,aACb,OAAO,QAAQ,OACf,IACA,aAAa,OAAO,SAAS,SAAS,OAAO,SAAS,KACvD;IAEF,CAAC,QAAQ,QAAQ,CAAC"}
|
|
@@ -6,12 +6,16 @@ let react = require("react");
|
|
|
6
6
|
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
7
7
|
|
|
8
8
|
//#region src/editor/ContentSelector.tsx
|
|
9
|
+
/**
|
|
10
|
+
* True when the editor is explicitly disabled at build time.
|
|
11
|
+
*/
|
|
12
|
+
const TREE_SHAKE_EDITOR = process.env["INTLAYER_EDITOR_ENABLED"] === "false";
|
|
9
13
|
const ContentSelector = ({ children, dictionaryKey, keyPath }) => {
|
|
10
|
-
if (_intlayer_editor_isEnabled.isEnabled) return
|
|
14
|
+
if (TREE_SHAKE_EDITOR || !_intlayer_editor_isEnabled.isEnabled) return children;
|
|
15
|
+
return (0, react.createElement)("intlayer-content-selector-wrapper", {
|
|
11
16
|
"key-path": JSON.stringify(keyPath),
|
|
12
17
|
"dictionary-key": dictionaryKey
|
|
13
18
|
}, children);
|
|
14
|
-
return children;
|
|
15
19
|
};
|
|
16
20
|
|
|
17
21
|
//#endregion
|
|
@@ -1 +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
|
|
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\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when the editor is explicitly disabled at build time.\n */\nconst TREE_SHAKE_EDITOR = process.env['INTLAYER_EDITOR_ENABLED'] === 'false';\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n if (TREE_SHAKE_EDITOR || !isEnabled) {\n return children;\n }\n\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"],"mappings":";;;;;;;;;;;AAgBA,MAAM,oBAAoB,QAAQ,IAAI,+BAA+B;AAErE,MAAa,mBAA6C,EACxD,UACA,eACA,cACI;AACJ,KAAI,qBAAqB,CAACA,qCACxB,QAAO;AAGT,iCACE,qCACA;EACE,YAAY,KAAK,UAAU,QAAQ;EACnC,kBAAkB;EACnB,EACD,SACD"}
|
|
@@ -7,6 +7,7 @@ let react = require("react");
|
|
|
7
7
|
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
8
8
|
|
|
9
9
|
//#region src/editor/useEditor.tsx
|
|
10
|
+
const TREE_SHAKE_EDITOR = process.env["INTLAYER_EDITOR_ENABLED"] === "false";
|
|
10
11
|
/**
|
|
11
12
|
* Initializes the Intlayer editor client singleton when the editor is enabled.
|
|
12
13
|
* Syncs the current locale from the Intlayer context into the editor manager so
|
|
@@ -16,7 +17,7 @@ const useEditor = () => {
|
|
|
16
17
|
const { locale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
17
18
|
const managerRef = (0, react.useRef)(null);
|
|
18
19
|
(0, react.useEffect)(() => {
|
|
19
|
-
if (!_intlayer_editor_isEnabled.isEnabled) return;
|
|
20
|
+
if (TREE_SHAKE_EDITOR || !_intlayer_editor_isEnabled.isEnabled) return;
|
|
20
21
|
import("@intlayer/editor").then(({ initEditorClient }) => {
|
|
21
22
|
const manager = initEditorClient();
|
|
22
23
|
managerRef.current = manager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.cjs","names":["IntlayerClientContext","isEnabled"],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'react';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initializes the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n const managerRef = useRef<EditorStateManager | null>(null);\n\n useEffect(() => {\n if (!isEnabled) return;\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n });\n\n return () => {\n managerRef.current = null;\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n };\n }, []);\n\n useEffect(() => {\n if (!locale || !managerRef.current) return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":"
|
|
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\nconst TREE_SHAKE_EDITOR = process.env['INTLAYER_EDITOR_ENABLED'] === 'false';\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 (TREE_SHAKE_EDITOR || !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":";;;;;;;;;AAQA,MAAM,oBAAoB,QAAQ,IAAI,+BAA+B;;;;;;AAOrE,MAAa,kBAAkB;CAC7B,MAAM,EAAE,iCAAsBA,sDAAsB,IAAI,EAAE;CAC1D,MAAM,+BAA+C,KAAK;AAE1D,4BAAgB;AACd,MAAI,qBAAqB,CAACC,qCAAW;AAErC,SAAO,oBAAoB,MAAM,EAAE,uBAAuB;GACxD,MAAM,UAAU,kBAAkB;AAClC,cAAW,UAAU;AAErB,OAAI,OAAQ,SAAQ,cAAc,IAAI,OAAiB;IACvD;AAEF,eAAa;AACX,cAAW,UAAU;AACrB,UAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,sBAAkB;KAClB;;IAEH,EAAE,CAAC;AAEN,4BAAgB;AACd,MAAI,CAAC,UAAU,CAAC,WAAW,QAAS;AAEpC,aAAW,QAAQ,cAAc,IAAI,OAAiB;IACrD,CAAC,OAAO,CAAC"}
|
package/dist/cjs/plugins.cjs
CHANGED
|
@@ -4,7 +4,6 @@ const require_editor_ContentSelector = require('./editor/ContentSelector.cjs');
|
|
|
4
4
|
const require_IntlayerNode = require('./IntlayerNode.cjs');
|
|
5
5
|
const require_reactElement_renderReactElement = require('./reactElement/renderReactElement.cjs');
|
|
6
6
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
7
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
8
7
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
9
8
|
let _intlayer_core_markdown = require("@intlayer/core/markdown");
|
|
10
9
|
let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
|
|
@@ -13,29 +12,53 @@ let react = require("react");
|
|
|
13
12
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
14
13
|
|
|
15
14
|
//#region src/plugins.tsx
|
|
15
|
+
/**
|
|
16
|
+
* True when the intlayer node type is explicitly disabled at build time.
|
|
17
|
+
*/
|
|
18
|
+
const TREE_SHAKE_INTLAYER_NODE = process.env["INTLAYER_NODE_TYPE_INTLAYER_NODE"] === "false";
|
|
19
|
+
/**
|
|
20
|
+
* True when the react node type is explicitly disabled at build time.
|
|
21
|
+
*/
|
|
22
|
+
const TREE_SHAKE_REACT_NODE = process.env["INTLAYER_NODE_TYPE_REACT_NODE"] === "false";
|
|
23
|
+
/**
|
|
24
|
+
* True when the markdown node type is explicitly disabled at build time.
|
|
25
|
+
*/
|
|
26
|
+
const TREE_SHAKE_MARKDOWN = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "false";
|
|
27
|
+
/**
|
|
28
|
+
* True when the HTML node type is explicitly disabled at build time.
|
|
29
|
+
*/
|
|
30
|
+
const TREE_SHAKE_HTML = process.env["INTLAYER_NODE_TYPE_HTML"] === "false";
|
|
31
|
+
/**
|
|
32
|
+
* True when the insertion node type is explicitly disabled at build time.
|
|
33
|
+
*/
|
|
34
|
+
const TREE_SHAKE_INSERTION = process.env["INTLAYER_NODE_TYPE_INSERTION"] === "false";
|
|
35
|
+
/**
|
|
36
|
+
* True when the editor is explicitly disabled at build time.
|
|
37
|
+
*/
|
|
38
|
+
const TREE_SHAKE_EDITOR = process.env["INTLAYER_EDITOR_ENABLED"] === "false";
|
|
16
39
|
const LazyMarkdownRendererPlugin = (0, react.lazy)(() => Promise.resolve().then(() => require("./markdown/MarkdownRendererPlugin.cjs")).then((m) => ({ default: m.MarkdownRendererPlugin })));
|
|
17
40
|
const LazyHTMLRendererPlugin = (0, react.lazy)(() => Promise.resolve().then(() => require("./html/HTMLRendererPlugin.cjs")).then((m) => ({ default: m.HTMLRendererPlugin })));
|
|
18
41
|
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
19
|
-
const intlayerNodePlugins =
|
|
42
|
+
const intlayerNodePlugins = TREE_SHAKE_INTLAYER_NODE ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
20
43
|
id: "intlayer-node-plugin",
|
|
21
44
|
canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
|
|
22
45
|
transform: (_node, { plugins, ...rest }) => require_IntlayerNode.renderIntlayerNode({
|
|
23
46
|
...rest,
|
|
24
47
|
value: rest.children,
|
|
25
|
-
children: _intlayer_config_built.
|
|
48
|
+
children: !TREE_SHAKE_EDITOR && _intlayer_config_built.editor.enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
|
|
26
49
|
...rest,
|
|
27
50
|
children: rest.children
|
|
28
51
|
}) : rest.children
|
|
29
52
|
})
|
|
30
53
|
};
|
|
31
54
|
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
32
|
-
const reactNodePlugins =
|
|
55
|
+
const reactNodePlugins = TREE_SHAKE_REACT_NODE ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
33
56
|
id: "react-node-plugin",
|
|
34
57
|
canHandle: (node) => typeof node === "object" && typeof node?.props !== "undefined" && typeof node.key !== "undefined",
|
|
35
58
|
transform: (node, { plugins, ...rest }) => require_IntlayerNode.renderIntlayerNode({
|
|
36
59
|
...rest,
|
|
37
60
|
value: "[[react-element]]",
|
|
38
|
-
children: _intlayer_config_built.
|
|
61
|
+
children: !TREE_SHAKE_EDITOR && _intlayer_config_built.editor.enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
|
|
39
62
|
...rest,
|
|
40
63
|
children: require_reactElement_renderReactElement.renderReactElement(node)
|
|
41
64
|
}) : require_reactElement_renderReactElement.renderReactElement(node)
|
|
@@ -50,7 +73,7 @@ const splitAndJoinInsertion = (template, values) => {
|
|
|
50
73
|
return (0, react.createElement)(react.Fragment, null, ...result.parts.map((part, index) => (0, react.createElement)(react.Fragment, { key: index }, part)));
|
|
51
74
|
};
|
|
52
75
|
/** Insertion plugin for React. Handles component/node insertion. */
|
|
53
|
-
const insertionPlugin =
|
|
76
|
+
const insertionPlugin = TREE_SHAKE_INSERTION ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
54
77
|
id: "insertion-plugin",
|
|
55
78
|
canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.INSERTION,
|
|
56
79
|
transform: (node, props, deepTransformNode) => {
|
|
@@ -91,7 +114,7 @@ const insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? _
|
|
|
91
114
|
}
|
|
92
115
|
};
|
|
93
116
|
/** Markdown string plugin. Replaces string node with a component that render the markdown. */
|
|
94
|
-
const markdownStringPlugin =
|
|
117
|
+
const markdownStringPlugin = TREE_SHAKE_MARKDOWN ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
95
118
|
id: "markdown-string-plugin",
|
|
96
119
|
canHandle: (node) => typeof node === "string",
|
|
97
120
|
transform: (node, props, deepTransformNode) => {
|
|
@@ -103,7 +126,7 @@ const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false"
|
|
|
103
126
|
transform: (metadataNode, props) => require_IntlayerNode.renderIntlayerNode({
|
|
104
127
|
...props,
|
|
105
128
|
value: metadataNode,
|
|
106
|
-
children: _intlayer_config_built.
|
|
129
|
+
children: !TREE_SHAKE_EDITOR && _intlayer_config_built.editor.enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
|
|
107
130
|
...rest,
|
|
108
131
|
children: node
|
|
109
132
|
}) : node
|
|
@@ -115,7 +138,7 @@ const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false"
|
|
|
115
138
|
const render = (components) => require_IntlayerNode.renderIntlayerNode({
|
|
116
139
|
...props,
|
|
117
140
|
value: node,
|
|
118
|
-
children: _intlayer_config_built.
|
|
141
|
+
children: !TREE_SHAKE_EDITOR && _intlayer_config_built.editor.enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
|
|
119
142
|
...rest,
|
|
120
143
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
|
|
121
144
|
fallback: node,
|
|
@@ -144,7 +167,7 @@ const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false"
|
|
|
144
167
|
} });
|
|
145
168
|
}
|
|
146
169
|
};
|
|
147
|
-
const markdownPlugin = {
|
|
170
|
+
const markdownPlugin = TREE_SHAKE_MARKDOWN ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
148
171
|
id: "markdown-plugin",
|
|
149
172
|
canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.MARKDOWN,
|
|
150
173
|
transform: (node, props, deepTransformNode) => {
|
|
@@ -159,7 +182,7 @@ const markdownPlugin = {
|
|
|
159
182
|
}
|
|
160
183
|
};
|
|
161
184
|
/** HTML plugin. Replaces node with a function that takes components => ReactNode. */
|
|
162
|
-
const htmlPlugin =
|
|
185
|
+
const htmlPlugin = TREE_SHAKE_HTML ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
163
186
|
id: "html-plugin",
|
|
164
187
|
canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.HTML,
|
|
165
188
|
transform: (node, props) => {
|
|
@@ -168,7 +191,17 @@ const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? _intlayer_c
|
|
|
168
191
|
const render = (userComponents) => require_IntlayerNode.renderIntlayerNode({
|
|
169
192
|
...rest,
|
|
170
193
|
value: html,
|
|
171
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
194
|
+
children: !TREE_SHAKE_EDITOR && _intlayer_config_built.editor.enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
|
|
195
|
+
...rest,
|
|
196
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
|
|
197
|
+
fallback: html,
|
|
198
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LazyHTMLRendererPlugin, {
|
|
199
|
+
...rest,
|
|
200
|
+
html,
|
|
201
|
+
userComponents
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
|
|
172
205
|
fallback: html,
|
|
173
206
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LazyHTMLRendererPlugin, {
|
|
174
207
|
...rest,
|
|
@@ -190,10 +223,10 @@ const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? _intlayer_c
|
|
|
190
223
|
* This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
|
|
191
224
|
*/
|
|
192
225
|
const getPlugins = (locale, fallback = true) => [
|
|
193
|
-
(0, _intlayer_core_interpreter.translationPlugin)(locale ?? _intlayer_config_built.
|
|
226
|
+
(0, _intlayer_core_interpreter.translationPlugin)(locale ?? _intlayer_config_built.internationalization.defaultLocale, fallback ? _intlayer_config_built.internationalization.defaultLocale : void 0),
|
|
194
227
|
_intlayer_core_interpreter.enumerationPlugin,
|
|
195
228
|
_intlayer_core_interpreter.conditionPlugin,
|
|
196
|
-
(0, _intlayer_core_interpreter.nestedPlugin)(locale ?? _intlayer_config_built.
|
|
229
|
+
(0, _intlayer_core_interpreter.nestedPlugin)(locale ?? _intlayer_config_built.internationalization.defaultLocale),
|
|
197
230
|
_intlayer_core_interpreter.filePlugin,
|
|
198
231
|
_intlayer_core_interpreter.genderPlugin,
|
|
199
232
|
intlayerNodePlugins,
|
package/dist/cjs/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["fallbackPlugin","renderIntlayerNode","configuration","ContentSelector","renderReactElement","Fragment","NodeTypes","Suspense","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 fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport {\n createElement,\n Fragment,\n lazy,\n type ReactElement,\n type ReactNode,\n Suspense,\n} from 'react';\nimport { ContentSelector } from './editor/ContentSelector';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\n// React.lazy for heavy renderer components — creates separate code-split chunks\n// and properly suspends until the module is loaded\nconst LazyMarkdownRendererPlugin = lazy(() =>\n import('./markdown/MarkdownRendererPlugin').then((m) => ({\n default: m.MarkdownRendererPlugin,\n }))\n);\n\nconst LazyHTMLRendererPlugin = lazy(() =>\n import('./html/HTMLRendererPlugin').then((m) => ({\n default: m.HTMLRendererPlugin,\n }))\n);\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 process.env.INTLAYER_NODE_TYPE_INTLAYER_NODE === 'false'\n ? fallbackPlugin\n : {\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 process.env.INTLAYER_NODE_TYPE_REACT_NODE === 'false'\n ? fallbackPlugin\n : {\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}>\n {renderReactElement(node)}\n </ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n }),\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: string;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<ReactNode>\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n if (\n typeof children === 'object' &&\n children !== null &&\n 'nodeType' in children &&\n [NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(\n children.nodeType as\n | typeof NodeTypes.ENUMERATION\n | typeof NodeTypes.CONDITION\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 process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children: configuration.editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children: configuration.editor.enabled ? (\n <ContentSelector {...rest}>\n <Suspense fallback={node}>\n <LazyMarkdownRendererPlugin\n {...rest}\n components={components}\n >\n {node}\n </LazyMarkdownRendererPlugin>\n </Suspense>\n </ContentSelector>\n ) : (\n <Suspense fallback={node}>\n <LazyMarkdownRendererPlugin {...rest} components={components}>\n {node}\n </LazyMarkdownRendererPlugin>\n </Suspense>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const element = render() as unknown as ReactElement;\n\n return new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return node;\n }\n if (prop === 'metadata') {\n return metadataNodes;\n }\n\n if (prop === 'use') {\n return (components?: HTMLComponents) => render(components);\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins = {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_HTML === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): ReactNode =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children: (\n <Suspense fallback={html}>\n <LazyHTMLRendererPlugin\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </Suspense>\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 html;\n }\n\n if (prop === 'use') {\n // Return a properly typed function based on custom components\n return (userComponents?: HTMLComponents) =>\n render(userComponents);\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport 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 [\n // Env var allows the bundler to to remove the plugin if not used to make the bundle smaller\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 // Always include: handle plain strings/numbers and React elements\n intlayerNodePlugins,\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ].filter(Boolean) as Plugins[];\n"],"mappings":";;;;;;;;;;;;;;;AA0CA,MAAM,wFACJ,0CAA4C,MAAM,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AAM,OAAO,KAAKA,yBAAU;EAC5B,MAAM,EAAE,SAAS,GAAG,SAAS;EAG7B,MAAM,UAAU,mBACdL,wCAAmB;GACjB,GAAG;GACH,OAAO;GACP,UACE,2CAACM,gBAAD;IAAU,UAAU;cAClB,2CAAC,wBAAD;KACE,GAAI;KACE;KACU;KAChB;IACO;GAEd,CAAC;EAEJ,MAAM,UAAU,QAAQ;AAExB,SAAO,IAAI,MAAM,SAAS,EACxB,IAAI,QAAQ,MAAM,UAAU;AAC1B,OAAI,SAAS,QACX,QAAO;AAGT,OAAI,SAAS,MAEX,SAAQ,mBACN,OAAO,eAAe;AAG1B,UAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;KAE7C,CAAC;;CAEL;;;;;AAuCP,MAAa,cACX,QACA,WAAoB,SAEpB;mDAGI,UAAUL,+BAAc,qBAAqB,eAC7C,WAAWA,+BAAc,qBAAqB,gBAAgB,OAC/D;CACDM;CACAC;8CACa,UAAUP,+BAAc,qBAAqB,cAAc;CACxEQ;CACAC;CAEA;CACA;CACA;CACA;CACA;CACD,CAAC,OAAO,QAAQ"}
|
|
1
|
+
{"version":3,"file":"plugins.cjs","names":["fallbackPlugin","renderIntlayerNode","editor","ContentSelector","renderReactElement","Fragment","NodeTypes","Suspense","internationalization","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.tsx"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport {\n createElement,\n Fragment,\n lazy,\n type ReactElement,\n type ReactNode,\n Suspense,\n} from 'react';\nimport { ContentSelector } from './editor/ContentSelector';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when the intlayer node type is explicitly disabled at build time.\n */\nconst TREE_SHAKE_INTLAYER_NODE =\n process.env['INTLAYER_NODE_TYPE_INTLAYER_NODE'] === 'false';\n\n/**\n * True when the react node type is explicitly disabled at build time.\n */\nconst TREE_SHAKE_REACT_NODE =\n process.env['INTLAYER_NODE_TYPE_REACT_NODE'] === 'false';\n\n/**\n * True when the markdown node type is explicitly disabled at build time.\n */\nconst TREE_SHAKE_MARKDOWN =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false';\n\n/**\n * True when the HTML node type is explicitly disabled at build time.\n */\nconst TREE_SHAKE_HTML = process.env['INTLAYER_NODE_TYPE_HTML'] === 'false';\n\n/**\n * True when the insertion node type is explicitly disabled at build time.\n */\nconst TREE_SHAKE_INSERTION =\n process.env['INTLAYER_NODE_TYPE_INSERTION'] === 'false';\n\n/**\n * True when the editor is explicitly disabled at build time.\n */\nconst TREE_SHAKE_EDITOR = process.env['INTLAYER_EDITOR_ENABLED'] === 'false';\n\n// React.lazy for heavy renderer components — creates separate code-split chunks\n// and properly suspends until the module is loaded\nconst LazyMarkdownRendererPlugin = lazy(() =>\n import('./markdown/MarkdownRendererPlugin').then((m) => ({\n default: m.MarkdownRendererPlugin,\n }))\n);\n\nconst LazyHTMLRendererPlugin = lazy(() =>\n import('./html/HTMLRendererPlugin').then((m) => ({\n default: m.HTMLRendererPlugin,\n }))\n);\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 = TREE_SHAKE_INTLAYER_NODE\n ? fallbackPlugin\n : {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (\n _node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: rest.children,\n children:\n !TREE_SHAKE_EDITOR && 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 = TREE_SHAKE_REACT_NODE\n ? fallbackPlugin\n : {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children:\n !TREE_SHAKE_EDITOR && editor.enabled ? (\n <ContentSelector {...rest}>\n {renderReactElement(node)}\n </ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n }),\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: string;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<ReactNode>\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins = TREE_SHAKE_INSERTION\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n if (\n typeof children === 'object' &&\n children !== null &&\n 'nodeType' in children &&\n [NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(\n children.nodeType as\n | typeof NodeTypes.ENUMERATION\n | typeof NodeTypes.CONDITION\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 = TREE_SHAKE_MARKDOWN\n ? fallbackPlugin\n : {\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 !TREE_SHAKE_EDITOR && editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children:\n !TREE_SHAKE_EDITOR && editor.enabled ? (\n <ContentSelector {...rest}>\n <Suspense fallback={node}>\n <LazyMarkdownRendererPlugin\n {...rest}\n components={components}\n >\n {node}\n </LazyMarkdownRendererPlugin>\n </Suspense>\n </ContentSelector>\n ) : (\n <Suspense fallback={node}>\n <LazyMarkdownRendererPlugin {...rest} components={components}>\n {node}\n </LazyMarkdownRendererPlugin>\n </Suspense>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const element = render() as unknown as ReactElement;\n\n return new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return node;\n }\n if (prop === 'metadata') {\n return metadataNodes;\n }\n\n if (prop === 'use') {\n return (components?: HTMLComponents) => render(components);\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins = TREE_SHAKE_MARKDOWN\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins = TREE_SHAKE_HTML\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): ReactNode =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n !TREE_SHAKE_EDITOR && editor.enabled ? (\n <ContentSelector {...rest}>\n <Suspense fallback={html}>\n <LazyHTMLRendererPlugin\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </Suspense>\n </ContentSelector>\n ) : (\n <Suspense fallback={html}>\n <LazyHTMLRendererPlugin\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </Suspense>\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 html;\n }\n\n if (prop === 'use') {\n // Return a properly typed function based on custom components\n return (userComponents?: HTMLComponents) =>\n render(userComponents);\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport 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 [\n // Env var allows the bundler to to remove the plugin if not used to make the bundle smaller\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n\n filePlugin,\n genderPlugin,\n // Always include: handle plain strings/numbers and React elements\n intlayerNodePlugins,\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ].filter(Boolean) as Plugins[];\n"],"mappings":";;;;;;;;;;;;;;;;;AA+CA,MAAM,2BACJ,QAAQ,IAAI,wCAAwC;;;;AAKtD,MAAM,wBACJ,QAAQ,IAAI,qCAAqC;;;;AAKnD,MAAM,sBACJ,QAAQ,IAAI,mCAAmC;;;;AAKjD,MAAM,kBAAkB,QAAQ,IAAI,+BAA+B;;;;AAKnE,MAAM,uBACJ,QAAQ,IAAI,oCAAoC;;;;AAKlD,MAAM,oBAAoB,QAAQ,IAAI,+BAA+B;AAIrE,MAAM,wFACJ,0CAA4C,MAAM,OAAO,EACvD,SAAS,EAAE,wBACZ,EAAE,CACJ;AAED,MAAM,oFACJ,kCAAoC,MAAM,OAAO,EAC/C,SAAS,EAAE,oBACZ,EAAE,CACJ;;AAWD,MAAa,sBAA+B,2BACxCA,4CACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YACE,OACA,EACE,SACA,GAAG,WAGLC,wCAAmB;EACjB,GAAG;EACH,OAAO,KAAK;EACZ,UACE,CAAC,qBAAqBC,8BAAO,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AAU,QAAQ;AAExB,SAAO,IAAI,MAAM,SAAS,EACxB,IAAI,QAAQ,MAAM,UAAU;AAC1B,OAAI,SAAS,QACX,QAAO;AAGT,OAAI,SAAS,MAEX,SAAQ,mBACN,OAAO,eAAe;AAG1B,UAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;KAE7C,CAAC;;CAEL;;;;;AAuCL,MAAa,cACX,QACA,WAAoB,SAEpB;mDAGI,UAAUC,4CAAqB,eAC/B,WAAWA,4CAAqB,gBAAgB,OACjD;CACDC;CACAC;8CACa,UAAUF,4CAAqB,cAAc;CAE1DG;CACAC;CAEA;CACA;CACA;CACA;CACA;CACD,CAAC,OAAO,QAAQ"}
|
|
@@ -2,11 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_server_serverContext = require('./serverContext.cjs');
|
|
4
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
6
5
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
6
|
|
|
8
7
|
//#region src/server/IntlayerServerProvider.tsx
|
|
9
|
-
const { defaultLocale } = _intlayer_config_built.
|
|
8
|
+
const { defaultLocale } = _intlayer_config_built.internationalization ?? {};
|
|
10
9
|
/**
|
|
11
10
|
* Context that store the current locale on the server side
|
|
12
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerServerProvider.cjs","names":["
|
|
1
|
+
{"version":3,"file":"IntlayerServerProvider.cjs","names":["internationalization","createServerContext","getServerContext"],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = internationalization ?? {};\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<LocalesValues>(defaultLocale);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: LocalesValues;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n {children}\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;;;AAMA,MAAM,EAAE,kBAAkBA,+CAAwB,EAAE;;;;AAKpD,MAAa,wBACXC,iDAAmC,cAAc;;;;AAKnD,MAAa,oBAAoBC,8CAAiB,sBAAsB;;;;AAKxE,MAAa,SAASA,8CAAiB,sBAAsB;;;;AAS7D,MAAa,0BAA2D,EACtE,UACA,SAAS,oBAET,2CAAC,sBAAsB,UAAvB;CAAgC,OAAO;CACpC;CAC8B"}
|
|
@@ -3,7 +3,6 @@ const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
|
3
3
|
const require_server_serverContext = require('../serverContext.cjs');
|
|
4
4
|
const require_server_IntlayerServerProvider = require('../IntlayerServerProvider.cjs');
|
|
5
5
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
6
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
7
6
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
8
7
|
|
|
9
8
|
//#region src/server/format/useIntl.ts
|
|
@@ -37,7 +36,7 @@ let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
|
37
36
|
*/
|
|
38
37
|
const useIntl = (locale) => {
|
|
39
38
|
const currentLocale = require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext);
|
|
40
|
-
return (0, _intlayer_core_formatters.bindIntl)(locale ?? currentLocale ?? _intlayer_config_built.
|
|
39
|
+
return (0, _intlayer_core_formatters.bindIntl)(locale ?? currentLocale ?? _intlayer_config_built.internationalization?.defaultLocale);
|
|
41
40
|
};
|
|
42
41
|
|
|
43
42
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntl.cjs","names":["getServerContext","IntlayerServerContext","
|
|
1
|
+
{"version":3,"file":"useIntl.cjs","names":["getServerContext","IntlayerServerContext","internationalization"],"sources":["../../../../src/server/format/useIntl.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues): WrappedIntl => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return bindIntl(\n locale ?? currentLocale ?? internationalization?.defaultLocale\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,WAAW,WAAwC;CAC9D,MAAM,gBAAgBA,8CAAgCC,4DAAsB;AAE5E,gDACE,UAAU,iBAAiBC,6CAAsB,cAClD"}
|