react-intlayer 4.0.3 → 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/UI/ContentSelector.cjs +2 -2
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs +11 -5
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/PoweredByMeta.cjs +9 -4
- package/dist/cjs/client/PoweredByMeta.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +13 -3
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +61 -7
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs +3 -23
- package/dist/cjs/editor/renderContentEditor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +4 -31
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +2 -2
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/getIntlayerAsync.cjs +2 -2
- package/dist/cjs/getIntlayerAsync.cjs.map +1 -1
- package/dist/cjs/recursiveTransformContent.cjs +54 -0
- package/dist/cjs/recursiveTransformContent.cjs.map +1 -0
- package/dist/esm/UI/ContentSelector.mjs +2 -2
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +13 -8
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/PoweredByMeta.mjs +9 -4
- package/dist/esm/client/PoweredByMeta.mjs.map +1 -1
- package/dist/esm/client/index.mjs +10 -10
- package/dist/esm/client/t.mjs +2 -2
- package/dist/esm/client/useContent.mjs +2 -2
- package/dist/esm/client/useDictionary.mjs +2 -2
- package/dist/esm/client/useIntlayer.mjs +2 -2
- package/dist/esm/client/useIntlayerAsync.mjs +3 -3
- package/dist/esm/client/useLocale.mjs +2 -2
- package/dist/esm/client/useLocaleBase.mjs +1 -1
- package/dist/esm/client/useTraduction.mjs +2 -2
- package/dist/esm/editor/ContentSelectorWrapper.mjs +19 -8
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +60 -9
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +2 -2
- package/dist/esm/editor/renderContentEditor.mjs +6 -24
- package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +4 -30
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +2 -2
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/getIntlayerAsync.mjs +2 -2
- package/dist/esm/getIntlayerAsync.mjs.map +1 -1
- package/dist/esm/index.mjs +4 -4
- package/dist/esm/processDictionary/index.mjs +2 -2
- package/dist/esm/recursiveTransformContent.mjs +32 -0
- package/dist/esm/recursiveTransformContent.mjs.map +1 -0
- package/dist/esm/server/IntlayerServerProvider.mjs +1 -1
- package/dist/esm/server/getLocaleTranslation.mjs +2 -2
- package/dist/esm/server/index.mjs +6 -6
- package/dist/esm/server/t.mjs +3 -3
- package/dist/esm/server/useDictionary.mjs +3 -3
- package/dist/esm/server/useIntlayer.mjs +3 -3
- package/dist/esm/server/useTraduction.mjs +3 -3
- package/dist/types/client/IntlayerProvider.d.ts +0 -3
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/PoweredByMeta.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/renderContentEditor.d.ts +5 -9
- package/dist/types/editor/renderContentEditor.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +3 -25
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +3 -3
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/getIntlayerAsync.d.ts.map +1 -1
- package/dist/types/recursiveTransformContent.d.ts +27 -0
- package/dist/types/recursiveTransformContent.d.ts.map +1 -0
- package/package.json +16 -15
- package/dist/cjs/UI/PressableSpan/index.cjs +0 -23
- package/dist/cjs/UI/PressableSpan/index.cjs.map +0 -1
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +0 -59
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +0 -1
- package/dist/esm/UI/PressableSpan/index.mjs +0 -2
- package/dist/esm/UI/PressableSpan/index.mjs.map +0 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +0 -35
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +0 -1
- package/dist/types/UI/PressableSpan/index.d.ts +0 -2
- package/dist/types/UI/PressableSpan/index.d.ts.map +0 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +0 -6
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +0 -1
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { getConfiguration } from "@intlayer/config/client";
|
|
4
|
+
import { useCrossFrameState } from "@intlayer/editor-react";
|
|
4
5
|
import {
|
|
5
6
|
createContext,
|
|
6
7
|
useContext,
|
|
7
8
|
useMemo,
|
|
8
|
-
useState,
|
|
9
9
|
useCallback
|
|
10
10
|
} from "react";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import { IntlayerEditorProvider } from "../editor/IntlayerEditorProvider.mjs";
|
|
12
|
+
import { PoweredByMeta } from "./PoweredByMeta.mjs";
|
|
13
|
+
import { localeCookie, setLocaleCookie } from "./useLocaleCookie.mjs";
|
|
14
14
|
const IntlayerClientContext = createContext({
|
|
15
15
|
locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,
|
|
16
16
|
setLocale: () => null
|
|
17
17
|
});
|
|
18
18
|
const useIntlayerContext = () => useContext(IntlayerClientContext);
|
|
19
|
-
const
|
|
19
|
+
const IntlayerProviderContent = ({
|
|
20
20
|
locale,
|
|
21
21
|
children,
|
|
22
22
|
setLocale: setLocaleProp
|
|
23
23
|
}) => {
|
|
24
24
|
const { internationalization } = getConfiguration();
|
|
25
25
|
const { defaultLocale, locales: availableLocales } = internationalization;
|
|
26
|
-
const [currentLocale, setCurrentLocale] =
|
|
26
|
+
const [currentLocale, setCurrentLocale] = useCrossFrameState(
|
|
27
|
+
"INTLAYER_CURRENT_LOCALE",
|
|
27
28
|
locale ?? localeCookie ?? defaultLocale
|
|
28
29
|
);
|
|
29
30
|
const setLocaleBase = useCallback(
|
|
@@ -38,16 +39,20 @@ const IntlayerProvider = ({
|
|
|
38
39
|
},
|
|
39
40
|
[availableLocales, currentLocale, locale]
|
|
40
41
|
);
|
|
41
|
-
const setLocale =
|
|
42
|
+
const setLocale = useMemo(
|
|
43
|
+
() => setLocaleProp ?? setLocaleBase,
|
|
44
|
+
[setLocaleProp, setLocaleBase]
|
|
45
|
+
);
|
|
42
46
|
const value = useMemo(
|
|
43
47
|
() => ({ locale: currentLocale, setLocale }),
|
|
44
48
|
[currentLocale, setLocale]
|
|
45
49
|
);
|
|
46
50
|
return /* @__PURE__ */ jsxs(IntlayerClientContext.Provider, { value, children: [
|
|
47
51
|
/* @__PURE__ */ jsx(PoweredByMeta, {}),
|
|
48
|
-
|
|
52
|
+
children
|
|
49
53
|
] });
|
|
50
54
|
};
|
|
55
|
+
const IntlayerProvider = (props) => /* @__PURE__ */ jsx(IntlayerEditorProvider, { children: /* @__PURE__ */ jsx(IntlayerProviderContent, { ...props }) });
|
|
51
56
|
export {
|
|
52
57
|
IntlayerClientContext,
|
|
53
58
|
IntlayerProvider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport { useCrossFrameState } from '@intlayer/editor-react';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { PoweredByMeta } from './PoweredByMeta';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nconst IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { internationalization } = getConfiguration();\n const { defaultLocale, locales: availableLocales } = internationalization;\n\n const [currentLocale, setCurrentLocale] = useCrossFrameState(\n 'INTLAYER_CURRENT_LOCALE',\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const setLocale = useMemo(\n () => setLocaleProp ?? setLocaleBase,\n [setLocaleProp, setLocaleBase]\n );\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <PoweredByMeta />\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\nexport const IntlayerProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerEditorProvider>\n <IntlayerProviderContent {...props} />\n </IntlayerEditorProvider>\n);\n"],"mappings":";AAkFI,SACE,KADF;AAhFJ,SAAS,wBAAsC;AAC/C,SAAS,0BAA0B;AACnC;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,OACK;AACP,SAAS,8BAA8B;AACvC,SAAS,qBAAqB;AAC9B,SAAS,cAAc,uBAAuB;AAUvC,MAAM,wBAAwB,cAA6B;AAAA,EAChE,QAAQ,gBAAgB,iBAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,MAAM,WAAW,qBAAqB;AAUxE,MAAM,0BAAqD,CAAC;AAAA,EAC1D;AAAA,EACA;AAAA,EACA,WAAW;AACb,MAAM;AACJ,QAAM,EAAE,qBAAqB,IAAI,iBAAiB;AAClD,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAErD,QAAM,CAAC,eAAe,gBAAgB,IAAI;AAAA,IACxC;AAAA,IACA,UAAU,gBAAgB;AAAA,EAC5B;AAEA,QAAM,gBAAgB;AAAA,IACpB,CAAC,cAAuB;AACtB,UAAI,cAAc,SAAS,MAAM,UAAU,SAAS,EAAG;AAEvD,UAAI,CAAC,iBAAiB,SAAS,SAAS,GAAG;AACzC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,uBAAiB,SAAS;AAC1B,sBAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,YAAY;AAAA,IAChB,MAAM,iBAAiB;AAAA,IACvB,CAAC,eAAe,aAAa;AAAA,EAC/B;AAEA,QAAM,QAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAU;AAAA,IAC1C,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,qBAAC,sBAAsB,UAAtB,EAA+B,OAC9B;AAAA,wBAAC,iBAAc;AAAA,IACd;AAAA,KACH;AAEJ;AAEO,MAAM,mBAA8C,CAAC,UAC1D,oBAAC,0BACC,8BAAC,2BAAyB,GAAG,OAAO,GACtC;","names":[]}
|
|
@@ -3,10 +3,15 @@ import { useEffect } from "react";
|
|
|
3
3
|
const PoweredByMeta = () => {
|
|
4
4
|
if (process.env.NODE_ENV !== "production") return null;
|
|
5
5
|
useEffect(() => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const existingMeta = document.head.querySelector(
|
|
7
|
+
'meta[name="content-powered-by"]'
|
|
8
|
+
);
|
|
9
|
+
if (!existingMeta) {
|
|
10
|
+
const metaTag = document.createElement("meta");
|
|
11
|
+
metaTag.name = "content-powered-by";
|
|
12
|
+
metaTag.content = "Intlayer - https://intlayer.org";
|
|
13
|
+
document.head.appendChild(metaTag);
|
|
14
|
+
}
|
|
10
15
|
}, []);
|
|
11
16
|
return null;
|
|
12
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/PoweredByMeta.ts"],"sourcesContent":["'use client';\n\nimport { type FC, useEffect } from 'react';\n\nexport const PoweredByMeta: FC = () => {\n if (process.env.NODE_ENV !== 'production') return null;\n\n useEffect(() => {\n const metaTag = document.createElement('meta');\n
|
|
1
|
+
{"version":3,"sources":["../../../src/client/PoweredByMeta.ts"],"sourcesContent":["'use client';\n\nimport { type FC, useEffect } from 'react';\n\nexport const PoweredByMeta: FC = () => {\n if (process.env.NODE_ENV !== 'production') return null;\n\n useEffect(() => {\n // Check if the meta tag already exists\n const existingMeta = document.head.querySelector(\n 'meta[name=\"content-powered-by\"]'\n );\n\n if (!existingMeta) {\n const metaTag = document.createElement('meta');\n metaTag.name = 'content-powered-by';\n metaTag.content = 'Intlayer - https://intlayer.org';\n document.head.appendChild(metaTag);\n }\n }, []);\n\n return null; // This component does not render anything visible\n};\n"],"mappings":";AAEA,SAAkB,iBAAiB;AAE5B,MAAM,gBAAoB,MAAM;AACrC,MAAI,QAAQ,IAAI,aAAa,aAAc,QAAO;AAElD,YAAU,MAAM;AAEd,UAAM,eAAe,SAAS,KAAK;AAAA,MACjC;AAAA,IACF;AAEA,QAAI,CAAC,cAAc;AACjB,YAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,cAAQ,OAAO;AACf,cAAQ,UAAU;AAClB,eAAS,KAAK,YAAY,OAAO;AAAA,IACnC;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
|
|
@@ -2,20 +2,20 @@ import {
|
|
|
2
2
|
IntlayerClientContext,
|
|
3
3
|
useIntlayerContext,
|
|
4
4
|
IntlayerProvider
|
|
5
|
-
} from
|
|
6
|
-
import { useIntlayer } from
|
|
7
|
-
import { useIntlayerAsync } from
|
|
8
|
-
import { useDictionary } from
|
|
9
|
-
import { useLocaleBase } from
|
|
10
|
-
import { useLocale } from
|
|
11
|
-
import { useTraduction } from
|
|
5
|
+
} from "./IntlayerProvider.mjs";
|
|
6
|
+
import { useIntlayer } from "./useIntlayer.mjs";
|
|
7
|
+
import { useIntlayerAsync } from "./useIntlayerAsync.mjs";
|
|
8
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
9
|
+
import { useLocaleBase } from "./useLocaleBase.mjs";
|
|
10
|
+
import { useLocale } from "./useLocale.mjs";
|
|
11
|
+
import { useTraduction } from "./useTraduction.mjs";
|
|
12
12
|
import {
|
|
13
13
|
useLocaleCookie,
|
|
14
14
|
localeCookie,
|
|
15
15
|
setLocaleCookie
|
|
16
|
-
} from
|
|
17
|
-
import { getBrowserLocale } from
|
|
18
|
-
import { t } from
|
|
16
|
+
} from "./useLocaleCookie.mjs";
|
|
17
|
+
import { getBrowserLocale } from "./getBrowserLocale.mjs";
|
|
18
|
+
import { t } from "./t.mjs";
|
|
19
19
|
export {
|
|
20
20
|
IntlayerClientContext,
|
|
21
21
|
IntlayerProvider,
|
package/dist/esm/client/t.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import { getTranslation } from
|
|
4
|
-
import { IntlayerClientContext } from
|
|
3
|
+
import { getTranslation } from "../getTranslation.mjs";
|
|
4
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
5
|
const t = (multilangContent, locale) => {
|
|
6
6
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
7
7
|
const localeTarget = locale ?? currentLocale;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useLocaleBase } from
|
|
2
|
-
import { useTraduction } from
|
|
1
|
+
import { useLocaleBase } from "./useLocaleBase.mjs";
|
|
2
|
+
import { useTraduction } from "./useTraduction.mjs";
|
|
3
3
|
const useContent = (languageContent) => {
|
|
4
4
|
const { locale } = useLocaleBase();
|
|
5
5
|
const content = useTraduction(languageContent);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import { getDictionary } from
|
|
4
|
-
import { IntlayerClientContext } from
|
|
3
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
4
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
5
|
const useDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
6
6
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
7
7
|
const localeTarget = locale ?? currentLocale;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import {
|
|
4
4
|
getIntlayer
|
|
5
|
-
} from
|
|
6
|
-
import { IntlayerClientContext } from
|
|
5
|
+
} from "../getIntlayer.mjs";
|
|
6
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
7
7
|
const useIntlayer = (key, locale, isRenderEditor = true) => {
|
|
8
8
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
9
9
|
const localeTarget = locale ?? currentLocale;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { useContext, useEffect, useMemo, useState } from "react";
|
|
3
3
|
import {
|
|
4
4
|
getIntlayer
|
|
5
|
-
} from
|
|
6
|
-
import { getIntlayerAsync } from
|
|
7
|
-
import { IntlayerClientContext } from
|
|
5
|
+
} from "../getIntlayer.mjs";
|
|
6
|
+
import { getIntlayerAsync } from "../getIntlayerAsync.mjs";
|
|
7
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
8
8
|
const useIntlayerAsync = (key, locale, isRenderEditor = true) => {
|
|
9
9
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
10
10
|
const localeTarget = locale ?? currentLocale;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { getConfiguration } from "@intlayer/config/client";
|
|
3
3
|
import { localeList } from "@intlayer/core";
|
|
4
4
|
import { useCallback, useContext } from "react";
|
|
5
|
-
import { IntlayerClientContext } from
|
|
6
|
-
import { useLocaleCookie } from
|
|
5
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
6
|
+
import { useLocaleCookie } from "./useLocaleCookie.mjs";
|
|
7
7
|
const useLocale = ({ onLocaleChange } = {}) => {
|
|
8
8
|
const {
|
|
9
9
|
/**
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { getConfiguration } from "@intlayer/config/client";
|
|
3
3
|
import { localeList } from "@intlayer/core";
|
|
4
4
|
import { useContext } from "react";
|
|
5
|
-
import { IntlayerClientContext } from
|
|
5
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
6
6
|
const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
|
|
7
7
|
const useLocaleBase = () => {
|
|
8
8
|
const { locale, setLocale } = useContext(IntlayerClientContext);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
|
-
import { getTranslation } from
|
|
3
|
-
import { IntlayerClientContext } from
|
|
2
|
+
import { getTranslation } from "../getTranslation.mjs";
|
|
3
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
4
|
const useTraduction = (languageContent) => {
|
|
5
5
|
const { locale } = useContext(IntlayerClientContext);
|
|
6
6
|
return getTranslation(languageContent, locale);
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
3
|
import { isSameKeyPath } from "@intlayer/core";
|
|
4
|
+
import {
|
|
5
|
+
useFocusDictionary,
|
|
6
|
+
useEditedContentActions,
|
|
7
|
+
useEditorEnabled
|
|
8
|
+
} from "@intlayer/editor-react";
|
|
4
9
|
import {
|
|
5
10
|
useCallback,
|
|
6
11
|
useEffect,
|
|
7
12
|
useState,
|
|
8
13
|
useMemo
|
|
9
14
|
} from "react";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
useEditedContentActions
|
|
13
|
-
} from "@intlayer/editor-react";
|
|
14
|
-
import { ContentSelector } from '../UI/ContentSelector.mjs';
|
|
15
|
-
const ContentSelectorWrapper = ({
|
|
15
|
+
import { ContentSelector } from "../UI/ContentSelector.mjs";
|
|
16
|
+
const ContentSelectorWrapperContent = ({
|
|
16
17
|
children,
|
|
17
18
|
dictionaryKey,
|
|
18
19
|
dictionaryPath,
|
|
@@ -35,7 +36,7 @@ const ContentSelectorWrapper = ({
|
|
|
35
36
|
[dictionaryKey, dictionaryPath, keyPath, setFocusedContent]
|
|
36
37
|
);
|
|
37
38
|
const isSelected = useMemo(
|
|
38
|
-
() => ((focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
39
|
+
() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
39
40
|
[focusedContent, keyPath]
|
|
40
41
|
);
|
|
41
42
|
useEffect(() => {
|
|
@@ -47,6 +48,16 @@ const ContentSelectorWrapper = ({
|
|
|
47
48
|
}, [editedValue, focusedContent, children]);
|
|
48
49
|
return /* @__PURE__ */ jsx(ContentSelector, { onPress: handleSelect, isSelecting: isSelected, ...props, children: displayedChildren });
|
|
49
50
|
};
|
|
51
|
+
const ContentSelectorWrapper = ({
|
|
52
|
+
children,
|
|
53
|
+
...props
|
|
54
|
+
}) => {
|
|
55
|
+
const { enabled } = useEditorEnabled();
|
|
56
|
+
if (enabled) {
|
|
57
|
+
return /* @__PURE__ */ jsx(ContentSelectorWrapperContent, { ...props, children });
|
|
58
|
+
}
|
|
59
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
60
|
+
};
|
|
50
61
|
export {
|
|
51
62
|
ContentSelectorWrapper
|
|
52
63
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type KeyPath } from '@intlayer/core';\nimport {\n useCallback,\n useEffect,\n useState,\n useMemo,\n type FC,\n type ReactNode,\n HTMLAttributes,\n} from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type KeyPath } from '@intlayer/core';\nimport {\n useFocusDictionary,\n useEditedContentActions,\n useEditorEnabled,\n} from '@intlayer/editor-react';\nimport {\n useCallback,\n useEffect,\n useState,\n useMemo,\n type FC,\n type ReactNode,\n HTMLAttributes,\n} from 'react';\nimport { ContentSelector } from '../UI/ContentSelector';\n\ntype ContentData = {\n dictionaryKey: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n};\n\nexport type ContentSelectorWrapperProps = ContentData &\n HTMLAttributes<HTMLDivElement>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n dictionaryPath,\n keyPath,\n ...props\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { getEditedContentValue } = useEditedContentActions();\n\n const editedValue = useMemo(\n () => getEditedContentValue(dictionaryKey, keyPath),\n [dictionaryKey, keyPath, getEditedContentValue]\n );\n\n const [displayedChildren, setDisplayedChildren] =\n useState<ReactNode>(children);\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n dictionaryPath,\n keyPath,\n }),\n [dictionaryKey, dictionaryPath, keyPath, setFocusedContent]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false,\n [focusedContent, keyPath]\n );\n\n useEffect(() => {\n // Use useEffect to avoid 'Text content does not match server-rendered HTML' error\n if (editedValue && typeof editedValue === 'string') {\n setDisplayedChildren(editedValue);\n } else {\n setDisplayedChildren(children);\n }\n }, [editedValue, focusedContent, children]);\n\n return (\n <ContentSelector onPress={handleSelect} isSelecting={isSelected} {...props}>\n {displayedChildren}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n\n if (enabled) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return <>{children}</>;\n};\n"],"mappings":";AA2EI,SAoBK,UApBL;AAzEJ,SAAS,qBAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,uBAAuB;AAWhC,MAAM,gCAAiE,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,gBAAgB,kBAAkB,IAAI,mBAAmB;AACjE,QAAM,EAAE,sBAAsB,IAAI,wBAAwB;AAE1D,QAAM,cAAc;AAAA,IAClB,MAAM,sBAAsB,eAAe,OAAO;AAAA,IAClD,CAAC,eAAe,SAAS,qBAAqB;AAAA,EAChD;AAEA,QAAM,CAAC,mBAAmB,oBAAoB,IAC5C,SAAoB,QAAQ;AAE9B,QAAM,eAAe;AAAA,IACnB,MACE,kBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,gBAAgB,SAAS,iBAAiB;AAAA,EAC5D;AAEA,QAAM,aAAa;AAAA,IACjB,OACG,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,KACzC,cAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAAA,IACF,CAAC,gBAAgB,OAAO;AAAA,EAC1B;AAEA,YAAU,MAAM;AAEd,QAAI,eAAe,OAAO,gBAAgB,UAAU;AAClD,2BAAqB,WAAW;AAAA,IAClC,OAAO;AACL,2BAAqB,QAAQ;AAAA,IAC/B;AAAA,EACF,GAAG,CAAC,aAAa,gBAAgB,QAAQ,CAAC;AAE1C,SACE,oBAAC,mBAAgB,SAAS,cAAc,aAAa,YAAa,GAAG,OAClE,6BACH;AAEJ;AAEO,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAErC,MAAI,SAAS;AACX,WACE,oBAAC,iCAA+B,GAAG,OAChC,UACH;AAAA,EAEJ;AAEA,SAAO,gCAAG,UAAS;AACrB;","names":[]}
|
|
@@ -1,14 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { getConfiguration } from "@intlayer/config/client";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import dictionaries from "@intlayer/dictionaries-entry";
|
|
5
|
+
import {
|
|
6
|
+
EditorProvider,
|
|
7
|
+
useCrossURLPathState,
|
|
8
|
+
useDictionariesRecordActions,
|
|
9
|
+
useConfigurationState,
|
|
10
|
+
useIframeClickInterceptor,
|
|
11
|
+
useEditorEnabled
|
|
12
|
+
} from "@intlayer/editor-react";
|
|
13
|
+
import { useEffect } from "react";
|
|
14
|
+
const IntlayerEditorHooksEnabled = () => {
|
|
15
|
+
useCrossURLPathState(void 0, {
|
|
16
|
+
receive: false,
|
|
17
|
+
emit: true
|
|
18
|
+
});
|
|
19
|
+
const [, setConfiguration] = useConfigurationState();
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const config = getConfiguration();
|
|
22
|
+
setConfiguration(config);
|
|
23
|
+
}, [setConfiguration]);
|
|
24
|
+
const { setLocaleDictionaries } = useDictionariesRecordActions();
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
setLocaleDictionaries(dictionaries);
|
|
27
|
+
}, [setLocaleDictionaries]);
|
|
28
|
+
useIframeClickInterceptor();
|
|
29
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
30
|
+
};
|
|
31
|
+
const IntlayerEditorHook = () => {
|
|
32
|
+
const { enabled } = useEditorEnabled();
|
|
33
|
+
return enabled ? /* @__PURE__ */ jsx(IntlayerEditorHooksEnabled, {}) : /* @__PURE__ */ jsx(Fragment, {});
|
|
34
|
+
};
|
|
7
35
|
const IntlayerEditorProvider = ({ children }) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
36
|
+
const { editor } = getConfiguration();
|
|
37
|
+
return /* @__PURE__ */ jsxs(
|
|
38
|
+
EditorProvider,
|
|
39
|
+
{
|
|
40
|
+
postMessage: (data) => {
|
|
41
|
+
if (typeof window === "undefined") return;
|
|
42
|
+
window?.postMessage(
|
|
43
|
+
data,
|
|
44
|
+
// Use to restrict the origin of the editor for security reasons.
|
|
45
|
+
// Correspond to the current application URL to synchronize the locales states.
|
|
46
|
+
editor.applicationURL
|
|
47
|
+
);
|
|
48
|
+
window.parent?.postMessage(
|
|
49
|
+
data,
|
|
50
|
+
// Use to restrict the origin of the editor for security reasons.
|
|
51
|
+
// Correspond to the current editor URL.
|
|
52
|
+
editor.editorURL
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
allowedOrigins: [editor.editorURL, editor.applicationURL],
|
|
56
|
+
mode: "client",
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsx(IntlayerEditorHook, {}),
|
|
59
|
+
children
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
);
|
|
12
63
|
};
|
|
13
64
|
export {
|
|
14
65
|
IntlayerEditorProvider
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport {\n EditorProvider,\n useCrossURLPathState,\n useDictionariesRecordActions,\n useConfigurationState,\n useIframeClickInterceptor,\n useEditorEnabled,\n} from '@intlayer/editor-react';\nimport { useEffect, type FC, type PropsWithChildren } from 'react';\n\nconst IntlayerEditorHooksEnabled: FC = () => {\n /**\n * URL Messages\n */\n useCrossURLPathState(undefined, {\n receive: false,\n emit: true,\n });\n\n /**\n * Configuration Messages\n */\n const [, setConfiguration] = useConfigurationState();\n\n useEffect(() => {\n const config = getConfiguration();\n setConfiguration(config);\n }, [setConfiguration]);\n\n /**\n * Locale Dictionaries Messages\n */\n const { setLocaleDictionaries } = useDictionariesRecordActions();\n\n useEffect(() => {\n setLocaleDictionaries(dictionaries);\n }, [setLocaleDictionaries]);\n\n /**\n * Click Messages\n */\n useIframeClickInterceptor();\n\n return <></>;\n};\n\nconst IntlayerEditorHook: FC = () => {\n const { enabled } = useEditorEnabled();\n\n return enabled ? <IntlayerEditorHooksEnabled /> : <></>;\n};\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => {\n const { editor } = getConfiguration();\n\n return (\n <EditorProvider\n postMessage={(data: any) => {\n if (typeof window === 'undefined') return;\n\n window?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the current application URL to synchronize the locales states.\n editor.applicationURL\n );\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the current editor URL.\n editor.editorURL\n );\n }}\n allowedOrigins={[editor.editorURL, editor.applicationURL]}\n mode=\"client\"\n >\n <IntlayerEditorHook />\n {children}\n </EditorProvider>\n );\n};\n"],"mappings":";AAsDS,wBAaL,YAbK;AAlDT,SAAS,wBAAwB;AAMjC,OAAO,kBAAkB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAkD;AAE3D,MAAM,6BAAiC,MAAM;AAI3C,uBAAqB,QAAW;AAAA,IAC9B,SAAS;AAAA,IACT,MAAM;AAAA,EACR,CAAC;AAKD,QAAM,CAAC,EAAE,gBAAgB,IAAI,sBAAsB;AAEnD,YAAU,MAAM;AACd,UAAM,SAAS,iBAAiB;AAChC,qBAAiB,MAAM;AAAA,EACzB,GAAG,CAAC,gBAAgB,CAAC;AAKrB,QAAM,EAAE,sBAAsB,IAAI,6BAA6B;AAE/D,YAAU,MAAM;AACd,0BAAsB,YAAY;AAAA,EACpC,GAAG,CAAC,qBAAqB,CAAC;AAK1B,4BAA0B;AAE1B,SAAO,gCAAE;AACX;AAEA,MAAM,qBAAyB,MAAM;AACnC,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAErC,SAAO,UAAU,oBAAC,8BAA2B,IAAK,gCAAE;AACtD;AAEO,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,EAAE,OAAO,IAAI,iBAAiB;AAEpC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAa,CAAC,SAAc;AAC1B,YAAI,OAAO,WAAW,YAAa;AAEnC,gBAAQ;AAAA,UACN;AAAA;AAAA;AAAA,UAGA,OAAO;AAAA,QACT;AACA,eAAO,QAAQ;AAAA,UACb;AAAA;AAAA;AAAA,UAGA,OAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,gBAAgB,CAAC,OAAO,WAAW,OAAO,cAAc;AAAA,MACxD,MAAK;AAAA,MAEL;AAAA,4BAAC,sBAAmB;AAAA,QACnB;AAAA;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./ContentSelectorWrapper.mjs";
|
|
2
|
+
export * from "./renderContentEditor.mjs";
|
|
3
3
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
content,
|
|
9
|
-
isContentSelectable,
|
|
10
|
-
...props
|
|
11
|
-
}) => {
|
|
12
|
-
if (enabled && isContentSelectable) {
|
|
13
|
-
return /* @__PURE__ */ jsx(ContentSelectorWrapper, { ...props, children: content });
|
|
14
|
-
}
|
|
15
|
-
return content;
|
|
16
|
-
};
|
|
17
|
-
const renderIntlayerEditor = (data, isContentSelectable = true) => {
|
|
18
|
-
const Result = /* @__PURE__ */ jsx(
|
|
19
|
-
IntlayerEditorElement,
|
|
20
|
-
{
|
|
21
|
-
...data,
|
|
22
|
-
isContentSelectable
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
return { ...Result, value: data.content };
|
|
2
|
+
import {
|
|
3
|
+
ContentSelectorWrapper
|
|
4
|
+
} from "./ContentSelectorWrapper.mjs";
|
|
5
|
+
const renderIntlayerEditor = (props) => {
|
|
6
|
+
const Result = /* @__PURE__ */ jsx(ContentSelectorWrapper, { ...props, children: props.content });
|
|
7
|
+
return { ...Result, value: props.content };
|
|
26
8
|
};
|
|
27
9
|
export {
|
|
28
10
|
renderIntlayerEditor
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport {\n ContentSelectorWrapper,\n type ContentSelectorWrapperProps,\n} from './ContentSelectorWrapper';\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\nexport type RenderIntlayerEditorProps = Omit<\n ContentSelectorWrapperProps,\n 'children'\n> & {\n content: string;\n};\n\nexport const renderIntlayerEditor = (\n props: RenderIntlayerEditorProps\n): IntlayerNode => {\n const Result = (\n <ContentSelectorWrapper {...props}>{props.content}</ContentSelectorWrapper>\n );\n\n return { ...Result, value: props.content };\n};\n"],"mappings":"AAqBI;AApBJ;AAAA,EACE;AAAA,OAEK;AAaA,MAAM,uBAAuB,CAClC,UACiB;AACjB,QAAM,SACJ,oBAAC,0BAAwB,GAAG,OAAQ,gBAAM,SAAQ;AAGpD,SAAO,EAAE,GAAG,QAAQ,OAAO,MAAM,QAAQ;AAC3C;","names":[]}
|
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { processDictionary } from "./processDictionary/index.mjs";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from
|
|
5
|
-
import { processDictionary } from './processDictionary/index.mjs';
|
|
6
|
-
const recursiveTransformContent = (value, isRenderEditor = false) => {
|
|
7
|
-
if (typeof value === "function") {
|
|
8
|
-
return (props) => recursiveTransformContent(value(props), isRenderEditor);
|
|
9
|
-
} else if (typeof value === "object") {
|
|
10
|
-
if (typeof value.dictionaryKey !== "undefined") {
|
|
11
|
-
if (isRenderEditor) {
|
|
12
|
-
return renderIntlayerEditor(value);
|
|
13
|
-
}
|
|
14
|
-
return value.content;
|
|
15
|
-
} else if (Array.isArray(value)) {
|
|
16
|
-
return value.map((el) => recursiveTransformContent(el, isRenderEditor));
|
|
17
|
-
} else if (isValidElement(value)) {
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
return Object.entries(value).reduce(
|
|
21
|
-
(acc, [key, value2]) => ({
|
|
22
|
-
...acc,
|
|
23
|
-
[key]: recursiveTransformContent(value2, isRenderEditor)
|
|
24
|
-
}),
|
|
25
|
-
{}
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
};
|
|
3
|
+
recursiveTransformContent
|
|
4
|
+
} from "./recursiveTransformContent.mjs";
|
|
30
5
|
const getDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
31
6
|
const result = processDictionary(
|
|
32
7
|
dictionary.content,
|
|
@@ -41,7 +16,6 @@ const getDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
|
41
16
|
);
|
|
42
17
|
};
|
|
43
18
|
export {
|
|
44
|
-
getDictionary
|
|
45
|
-
recursiveTransformContent
|
|
19
|
+
getDictionary
|
|
46
20
|
};
|
|
47
21
|
//# sourceMappingURL=getDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { DeclarationContent, DictionaryValue } from '@intlayer/core';\nimport { processDictionary } from './processDictionary/index';\nimport {\n DeepTransformContent,\n recursiveTransformContent,\n} from './recursiveTransformContent';\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<T['content'], K, R>;\n\nexport type UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor?: R,\n isContentSelectable?: boolean\n) => DataFromDictionary<T, L, R>;\n\n/**\n * Hook that picks one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getDictionary: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const result = processDictionary(\n dictionary.content as DictionaryValue,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionary<T, L, R>;\n};\n"],"mappings":"AAEA,SAAS,yBAAyB;AAClC;AAAA,EAEE;AAAA,OACK;AAwBA,MAAM,gBAA+B,CAK1C,YACA,QACA,iBAAoB,UACjB;AACH,QAAM,SAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/esm/getIntlayer.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import dictionaries from "@intlayer/dictionaries-entry";
|
|
2
|
+
import { processDictionary } from "./processDictionary/index.mjs";
|
|
2
3
|
import {
|
|
3
4
|
recursiveTransformContent
|
|
4
|
-
} from
|
|
5
|
-
import { processDictionary } from './processDictionary/index.mjs';
|
|
5
|
+
} from "./recursiveTransformContent.mjs";
|
|
6
6
|
const getIntlayer = (key, locale, isRenderEditor = false) => {
|
|
7
7
|
const dictionary = dictionaries[key];
|
|
8
8
|
if (!dictionary) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { processDictionary } from './processDictionary/index';\nimport {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './recursiveTransformContent';\n\n/**\n * Provides a fallback to string type if the generic type T is never,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\nexport type DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K, R>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R,\n isContentSelectable?: boolean\n) => DataFromDictionaryKey<T, L, R>;\n\nexport type UseIntlayerEditable = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R,\n isContentSelectable?: boolean\n) => DataFromDictionaryKey<T, L, R>;\n\nexport const getIntlayer: UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const dictionary: Dictionary = dictionaries[key as keyof typeof dictionaries];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key} not found`, dictionaries);\n }\n\n const result = processDictionary(\n dictionary.content,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n};\n"],"mappings":"AAOA,OAAO,kBAAkB;AAEzB,SAAS,yBAAyB;AAClC;AAAA,EAEE;AAAA,OACK;AA6DA,MAAM,cAA2B,CAKtC,KACA,QACA,iBAAoB,UACjB;AACH,QAAM,aAAyB,aAAa,GAAgC;AAE5E,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,cAAc,GAAG,cAAc,YAAY;AAAA,EAC7D;AAEA,QAAM,SAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { fetchDistantDictionary } from
|
|
3
|
-
import { getDictionary } from
|
|
2
|
+
import { fetchDistantDictionary } from "@intlayer/api";
|
|
3
|
+
import { getDictionary } from "./getDictionary.mjs";
|
|
4
4
|
const getIntlayerAsync = async (key, locale, isRenderEditor = true) => {
|
|
5
5
|
const jsonDistantDictionary = await fetchDistantDictionary(key);
|
|
6
6
|
if (jsonDistantDictionary) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/getIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport { fetchDistantDictionary } from '@intlayer/api';\nimport type { Locales } from '@intlayer/config/client';\nimport { DeclarationContent } from 'intlayer';\nimport { getDictionary } from './getDictionary';\nimport { DictionaryKeys, DataFromDictionaryKey } from './getIntlayer';\n\nexport type GetIntlayerAsync = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => Promise<DataFromDictionaryKey<T, L, R> | null>;\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getIntlayerAsync: GetIntlayerAsync = async <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor = true as R\n) => {\n const jsonDistantDictionary = await fetchDistantDictionary(key);\n\n if (jsonDistantDictionary) {\n return getDictionary(\n jsonDistantDictionary as unknown as DeclarationContent,\n locale,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n }\n\n return null;\n};\n"],"mappings":";AAEA,SAAS,8BAA8B;AAGvC,SAAS,qBAAqB;AAqBvB,MAAM,mBAAqC,OAKhD,KACA,QACA,iBAAiB,SACd;AACH,QAAM,wBAAwB,MAAM,uBAAuB,GAAG;AAE9D,MAAI,uBAAuB;AACzB,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getTranslation } from
|
|
1
|
+
import { getTranslation } from "./getTranslation.mjs";
|
|
2
2
|
import {
|
|
3
3
|
IntlayerProvider,
|
|
4
4
|
IntlayerClientContext,
|
|
@@ -14,9 +14,9 @@ import {
|
|
|
14
14
|
getBrowserLocale,
|
|
15
15
|
useLocaleBase,
|
|
16
16
|
t
|
|
17
|
-
} from
|
|
18
|
-
import { getDictionary } from
|
|
19
|
-
import { getIntlayer } from
|
|
17
|
+
} from "./client/index.mjs";
|
|
18
|
+
import { getDictionary } from "./getDictionary.mjs";
|
|
19
|
+
import { getIntlayer } from "./getIntlayer.mjs";
|
|
20
20
|
export {
|
|
21
21
|
IntlayerClientContext,
|
|
22
22
|
IntlayerProvider,
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
findMatchingCondition
|
|
5
5
|
} from "@intlayer/core";
|
|
6
6
|
import { createElement } from "react";
|
|
7
|
-
import { getEnumeration } from
|
|
8
|
-
import { getTranslation } from
|
|
7
|
+
import { getEnumeration } from "../getEnumeration.mjs";
|
|
8
|
+
import { getTranslation } from "../getTranslation.mjs";
|
|
9
9
|
const {
|
|
10
10
|
internationalization: { defaultLocale }
|
|
11
11
|
} = getConfiguration();
|