react-intlayer 2.0.1 → 2.0.3
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/ContentEditionLayout.cjs +10 -6
- package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs +4 -3
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/IntlayerProvider.d.ts +1 -0
- package/dist/cjs/client/getBrowserLocale.cjs +7 -14
- package/dist/cjs/client/getBrowserLocale.cjs.map +1 -1
- package/dist/cjs/client/index.d.ts +1 -1
- package/dist/cjs/client/useContent.d.ts +1 -1
- package/dist/cjs/client/useIntlayer.d.ts +1 -0
- package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
- package/dist/cjs/index.cjs +0 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/processDictionary/index.cjs +2 -2
- package/dist/cjs/processDictionary/index.cjs.map +1 -1
- package/dist/cjs/renderIntlayerEditor.cjs +55 -0
- package/dist/cjs/renderIntlayerEditor.cjs.map +1 -0
- package/dist/cjs/renderIntlayerEditor.d.ts +5 -0
- package/dist/cjs/server/IntlayerServerProvider.d.ts +5 -6
- package/dist/cjs/server/serverContext.cjs +1 -2
- package/dist/cjs/server/serverContext.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.d.ts +1 -0
- package/dist/cjs/useIntlayerBase.cjs +19 -38
- package/dist/cjs/useIntlayerBase.cjs.map +1 -1
- package/dist/cjs/useIntlayerBase.d.ts +24 -13
- package/dist/esm/{chunk-ZNCO4QRF.mjs → chunk-ZD7AOCMD.mjs} +1 -1
- package/dist/esm/client/ContentEditionLayout.mjs +10 -9
- package/dist/esm/client/ContentEditionLayout.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.d.mts +1 -0
- package/dist/esm/client/IntlayerProvider.mjs +5 -4
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/getBrowserLocale.mjs +8 -15
- package/dist/esm/client/getBrowserLocale.mjs.map +1 -1
- package/dist/esm/client/index.d.mts +1 -1
- package/dist/esm/client/index.mjs +1 -1
- package/dist/esm/client/useContent.d.mts +1 -1
- package/dist/esm/client/useContent.mjs +1 -1
- package/dist/esm/client/useIntlayer.d.mts +1 -0
- package/dist/esm/client/useIntlayer.mjs +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -1
- package/dist/esm/client/useLocaleCookie.mjs +1 -1
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +1 -1
- package/dist/esm/craco/craco.config.mjs +1 -1
- package/dist/esm/craco/intlayerCracoPlugin.mjs +1 -1
- package/dist/esm/getEnumeration.mjs +1 -1
- package/dist/esm/getTranslation.mjs +1 -1
- package/dist/esm/index.d.mts +1 -1
- package/dist/esm/index.mjs +1 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/index.mjs +3 -3
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/esm/renderIntlayerEditor.d.mts +5 -0
- package/dist/esm/renderIntlayerEditor.mjs +31 -0
- package/dist/esm/renderIntlayerEditor.mjs.map +1 -0
- package/dist/esm/server/IntlayerServerProvider.d.mts +5 -6
- package/dist/esm/server/IntlayerServerProvider.mjs +1 -1
- package/dist/esm/server/getLocaleTranslation.mjs +1 -1
- package/dist/esm/server/index.mjs +1 -1
- package/dist/esm/server/serverContext.mjs +2 -3
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.d.mts +1 -0
- package/dist/esm/server/useIntlayer.mjs +1 -1
- package/dist/esm/server/useTraduction.mjs +1 -1
- package/dist/esm/useIntlayerBase.d.mts +24 -13
- package/dist/esm/useIntlayerBase.mjs +20 -38
- package/dist/esm/useIntlayerBase.mjs.map +1 -1
- package/dist/esm/vite/intlayerPlugin.mjs +1 -1
- package/package.json +18 -18
- package/src/index.ts +1 -1
- /package/dist/esm/{chunk-ZNCO4QRF.mjs.map → chunk-ZD7AOCMD.mjs.map} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Locales } from '@intlayer/config';
|
|
2
|
+
import { NodeType } from '@intlayer/core';
|
|
2
3
|
import { IntlayerDictionaryTypesConnector } from 'intlayer';
|
|
3
4
|
import { ReactNode } from 'react';
|
|
4
5
|
|
|
@@ -20,12 +21,26 @@ type StringFallback<T> = T extends never ? string : T;
|
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
23
|
type DictionaryKeys = StringFallback<keyof IntlayerDictionaryTypesConnector>;
|
|
23
|
-
type IntlayerNode = ReactNode & {
|
|
24
|
-
value:
|
|
24
|
+
type IntlayerNode<T = string> = ReactNode & {
|
|
25
|
+
value: T;
|
|
25
26
|
};
|
|
26
|
-
type
|
|
27
|
-
[
|
|
28
|
-
|
|
27
|
+
type TransformNodeType<T, L extends Locales> = T extends {
|
|
28
|
+
[NodeType.Enumeration]: {
|
|
29
|
+
'1': any;
|
|
30
|
+
};
|
|
31
|
+
} ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L> : T extends {
|
|
32
|
+
[NodeType.Translation]: object;
|
|
33
|
+
} ? L extends keyof T[NodeType.Translation] ? DeepTransformContent<T[NodeType.Translation][L], L> : never : T;
|
|
34
|
+
type DeepTransformContent<T, L extends Locales> = T extends object ? T extends (infer U)[] ? DeepTransformContent<U, L>[] : T extends {
|
|
35
|
+
nodeType: NodeType | string;
|
|
36
|
+
} ? TransformNodeType<T, L> : T extends {
|
|
37
|
+
_owner: any;
|
|
38
|
+
key: any;
|
|
39
|
+
props: any;
|
|
40
|
+
ref: any;
|
|
41
|
+
} ? ReactNode : {
|
|
42
|
+
[K in keyof T]: DeepTransformContent<T[K], L>;
|
|
43
|
+
} : T extends undefined ? never : IntlayerNode<T>;
|
|
29
44
|
/**
|
|
30
45
|
* Excludes the 'id' and 'filePath' keys from the dictionary content,
|
|
31
46
|
* as they are not part of the IntlayerDictionaryTypesConnector type.
|
|
@@ -35,25 +50,21 @@ type ExcludeIntlayerUtilsKeys<T> = Omit<T, 'id' | 'filePath'>;
|
|
|
35
50
|
* Represents the data type returned by the useIntlayer hook,
|
|
36
51
|
* excluding the 'id' and 'filePath' keys from the dictionary content.
|
|
37
52
|
*/
|
|
38
|
-
type Data<T extends DictionaryKeys> = ExcludeIntlayerUtilsKeys<DeepTransformContent<IntlayerDictionaryTypesConnector[T]>>;
|
|
53
|
+
type Data<T extends DictionaryKeys, K extends Locales> = ExcludeIntlayerUtilsKeys<DeepTransformContent<IntlayerDictionaryTypesConnector[T], K>>;
|
|
39
54
|
/**
|
|
40
55
|
* Parcourt the object. If a object has a keyPath, render the intlayer editor if editor enabled.
|
|
41
56
|
*/
|
|
42
|
-
declare const recursiveTransformContent: (
|
|
43
|
-
type DeepStrinfifyContent<T> = T extends React.ComponentType<unknown> ? string : T extends object ? {
|
|
44
|
-
[K in keyof T]: DeepStrinfifyContent<T[K]>;
|
|
45
|
-
} : T;
|
|
46
|
-
declare const recursiveStringifyContent: <T extends object>(obj: T) => DeepStrinfifyContent<T>;
|
|
57
|
+
declare const recursiveTransformContent: (value: any) => object;
|
|
47
58
|
/**
|
|
48
59
|
* Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,
|
|
49
60
|
* and returns the deeply transformed dictionary content.
|
|
50
61
|
*
|
|
51
62
|
*/
|
|
52
|
-
type UseIntlayer = <T extends DictionaryKeys>(id: T, locale?:
|
|
63
|
+
type UseIntlayer = <T extends DictionaryKeys, L extends Locales>(id: T, locale?: L) => Data<T, L>;
|
|
53
64
|
/**
|
|
54
65
|
* Hook that picks one dictionary by its ID and returns the content,
|
|
55
66
|
* deeply transformed according to the dictionary structure and metadata.
|
|
56
67
|
*/
|
|
57
68
|
declare const useIntlayerBase: UseIntlayer;
|
|
58
69
|
|
|
59
|
-
export { type DictionaryKeys, type IntlayerNode, type StringFallback, type UseIntlayer,
|
|
70
|
+
export { type DictionaryKeys, type IntlayerNode, type StringFallback, type UseIntlayer, recursiveTransformContent, useIntlayerBase };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-ZD7AOCMD.mjs";
|
|
2
2
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
ContentEditionLayout as ContentEditionLayoutBase
|
|
6
|
-
} from "intlayer-editor/client";
|
|
7
|
-
const {
|
|
8
|
-
editor: { enabled }
|
|
9
|
-
} = getConfiguration();
|
|
3
|
+
import { createRequire } from "module";
|
|
10
4
|
const BlankLayout = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
|
|
11
|
-
const
|
|
5
|
+
const requireFunction = (packagePath) => {
|
|
6
|
+
try {
|
|
7
|
+
return typeof import.meta.url === "undefined" ? require(packagePath) : createRequire(import.meta.url)(packagePath);
|
|
8
|
+
} catch (error) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const ContentEditionLayout = typeof requireFunction("intlayer-editor/client")?.ContentEditionLayoutBase === "undefined" ? BlankLayout : requireFunction("intlayer-editor/client").ContentEditionLayoutBase;
|
|
12
13
|
export {
|
|
13
14
|
ContentEditionLayout
|
|
14
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import { createRequire } from 'module';\nimport type { ContentEditionLayoutProps } from 'intlayer-editor/client';\nimport type { FC } from 'react';\n\nconst BlankLayout: FC<ContentEditionLayoutProps> = ({ children }) => (\n <>{children}</>\n);\n\nconst requireFunction = (packagePath: string) => {\n try {\n return typeof import.meta.url === 'undefined'\n ? require(packagePath)\n : createRequire(import.meta.url)(packagePath);\n } catch (error) {\n return undefined;\n }\n};\n// intlayer-editor is an optional dependency. If it's not installed, return the blank layout\nexport const ContentEditionLayout: FC<ContentEditionLayoutProps> =\n typeof requireFunction('intlayer-editor/client')?.ContentEditionLayoutBase ===\n 'undefined'\n ? BlankLayout\n : requireFunction('intlayer-editor/client').ContentEditionLayoutBase;\n"],"mappings":";AAKE;AALF,SAAS,qBAAqB;AAI9B,MAAM,cAA6C,CAAC,EAAE,SAAS,MAC7D,gCAAG,UAAS;AAGd,MAAM,kBAAkB,CAAC,gBAAwB;AAC/C,MAAI;AACF,WAAO,OAAO,YAAY,QAAQ,cAC9B,QAAQ,WAAW,IACnB,cAAc,YAAY,GAAG,EAAE,WAAW;AAAA,EAChD,SAAS,OAAO;AACd,WAAO;AAAA,EACT;AACF;AAEO,MAAM,uBACX,OAAO,gBAAgB,wBAAwB,GAAG,6BAClD,cACI,cACA,gBAAgB,wBAAwB,EAAE;","names":[]}
|
|
@@ -17,6 +17,7 @@ declare const useIntlayerContext: () => IntlayerValue;
|
|
|
17
17
|
type IntlayerProviderProps = PropsWithChildren & {
|
|
18
18
|
locale?: Locales;
|
|
19
19
|
setLocale?: (locale: Locales) => void;
|
|
20
|
+
editorEnabled?: boolean;
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* Provider that store the current locale on the client side
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import "../chunk-
|
|
2
|
+
import "../chunk-ZD7AOCMD.mjs";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
import { getConfiguration } from "@intlayer/config/client";
|
|
5
5
|
import {
|
|
@@ -19,7 +19,8 @@ const useIntlayerContext = () => useContext(IntlayerClientContext);
|
|
|
19
19
|
const IntlayerProvider = ({
|
|
20
20
|
locale,
|
|
21
21
|
children,
|
|
22
|
-
setLocale: setLocaleProp
|
|
22
|
+
setLocale: setLocaleProp,
|
|
23
|
+
editorEnabled
|
|
23
24
|
}) => {
|
|
24
25
|
const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
|
|
25
26
|
const [currentLocale, setCurrentLocale] = useState(
|
|
@@ -27,8 +28,7 @@ const IntlayerProvider = ({
|
|
|
27
28
|
);
|
|
28
29
|
const setLocaleBase = useCallback(
|
|
29
30
|
(newLocale) => {
|
|
30
|
-
if (currentLocale.toString() === newLocale.toString())
|
|
31
|
-
return;
|
|
31
|
+
if (currentLocale.toString() === newLocale.toString()) return;
|
|
32
32
|
if (!availableLocales.includes(newLocale)) {
|
|
33
33
|
console.error(`Locale ${locale} is not available`);
|
|
34
34
|
return;
|
|
@@ -49,6 +49,7 @@ const IntlayerProvider = ({
|
|
|
49
49
|
locale: currentLocale,
|
|
50
50
|
setLocale,
|
|
51
51
|
localeList: availableLocales,
|
|
52
|
+
editorEnabled,
|
|
52
53
|
children
|
|
53
54
|
}
|
|
54
55
|
) });
|
|
@@ -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 { ContentEditionLayout } from './ContentEditionLayout';\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 */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\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 = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <ContentEditionLayout\n locale={currentLocale}\n setLocale={setLocale}\n localeList={availableLocales}\n >\n {children}\n </ContentEditionLayout>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;
|
|
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 { ContentEditionLayout } from './ContentEditionLayout';\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 editorEnabled?: boolean;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n editorEnabled,\n}) => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\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 = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <ContentEditionLayout\n locale={currentLocale}\n setLocale={setLocale}\n localeList={availableLocales}\n editorEnabled={editorEnabled}\n >\n {children}\n </ContentEditionLayout>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;AA+EM;AA7EN,SAAS,wBAAsC;AAC/C;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AACrC,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;AAWjE,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AACF,MAAM;AACJ,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AAErB,QAAM,CAAC,eAAe,gBAAgB,IAAI;AAAA,IACxC,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,iBAAiB;AAEnC,QAAM,QAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAqB;AAAA,IACrD,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAC9B;AAAA,IAAC;AAAA;AAAA,MACC,QAAQ;AAAA,MACR;AAAA,MACA,YAAY;AAAA,MACZ;AAAA,MAEC;AAAA;AAAA,EACH,GACF;AAEJ;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-ZD7AOCMD.mjs";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config/client";
|
|
3
3
|
import { localeList } from "@intlayer/core";
|
|
4
4
|
var LanguageDetector = /* @__PURE__ */ ((LanguageDetector2) => {
|
|
@@ -26,8 +26,7 @@ const getDefaultsOptions = () => {
|
|
|
26
26
|
};
|
|
27
27
|
const isLocalStorageAvailable = () => {
|
|
28
28
|
try {
|
|
29
|
-
if (typeof window === "undefined")
|
|
30
|
-
return false;
|
|
29
|
+
if (typeof window === "undefined") return false;
|
|
31
30
|
const testKey = "intlayer.translate.boo";
|
|
32
31
|
window.localStorage.setItem(testKey, "foo");
|
|
33
32
|
window.localStorage.removeItem(testKey);
|
|
@@ -38,8 +37,7 @@ const isLocalStorageAvailable = () => {
|
|
|
38
37
|
};
|
|
39
38
|
const isSessionStorageAvailable = () => {
|
|
40
39
|
try {
|
|
41
|
-
if (typeof window === "undefined")
|
|
42
|
-
return false;
|
|
40
|
+
if (typeof window === "undefined") return false;
|
|
43
41
|
const testKey = "intlayer.translate.boo";
|
|
44
42
|
window.sessionStorage.setItem(testKey, "foo");
|
|
45
43
|
window.sessionStorage.removeItem(testKey);
|
|
@@ -51,8 +49,7 @@ const isSessionStorageAvailable = () => {
|
|
|
51
49
|
const detectLanguage = (order, options) => {
|
|
52
50
|
const detected = {};
|
|
53
51
|
const queryStringDetector = () => {
|
|
54
|
-
if (typeof window === "undefined")
|
|
55
|
-
return;
|
|
52
|
+
if (typeof window === "undefined") return;
|
|
56
53
|
const search = window.location.search || "";
|
|
57
54
|
const params = new URLSearchParams(search);
|
|
58
55
|
const value = params.get(options.lookupQuerystring ?? "");
|
|
@@ -61,8 +58,7 @@ const detectLanguage = (order, options) => {
|
|
|
61
58
|
}
|
|
62
59
|
};
|
|
63
60
|
const cookieDetector = () => {
|
|
64
|
-
if (typeof document === "undefined")
|
|
65
|
-
return;
|
|
61
|
+
if (typeof document === "undefined") return;
|
|
66
62
|
const cookies = document.cookie.split(";");
|
|
67
63
|
const cookieName = `${options.lookupCookie ?? ""}=`;
|
|
68
64
|
const cookie = cookies.find((c) => c.trim().startsWith(cookieName));
|
|
@@ -72,16 +68,14 @@ const detectLanguage = (order, options) => {
|
|
|
72
68
|
}
|
|
73
69
|
};
|
|
74
70
|
const localStorageDetector = () => {
|
|
75
|
-
if (!isLocalStorageAvailable())
|
|
76
|
-
return;
|
|
71
|
+
if (!isLocalStorageAvailable()) return;
|
|
77
72
|
const value = window.localStorage.getItem(options.lookupLocalStorage ?? "");
|
|
78
73
|
if (value) {
|
|
79
74
|
detected["localStorage" /* LocalStorage */] = value;
|
|
80
75
|
}
|
|
81
76
|
};
|
|
82
77
|
const sessionStorageDetector = () => {
|
|
83
|
-
if (!isSessionStorageAvailable())
|
|
84
|
-
return;
|
|
78
|
+
if (!isSessionStorageAvailable()) return;
|
|
85
79
|
const value = window.sessionStorage.getItem(
|
|
86
80
|
options.lookupSessionStorage ?? ""
|
|
87
81
|
);
|
|
@@ -90,8 +84,7 @@ const detectLanguage = (order, options) => {
|
|
|
90
84
|
}
|
|
91
85
|
};
|
|
92
86
|
const navigatorDetector = () => {
|
|
93
|
-
if (typeof navigator === "undefined")
|
|
94
|
-
return;
|
|
87
|
+
if (typeof navigator === "undefined") return;
|
|
95
88
|
if (navigator.language) {
|
|
96
89
|
detected["navigator" /* Navigator */] = navigator.language;
|
|
97
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/getBrowserLocale.tsx"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Cookie = 'cookie',\n LocalStorage = 'localStorage',\n SessionStorage = 'sessionStorage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n lookupCookie?: string;\n lookupLocalStorage?: string;\n lookupSessionStorage?: string;\n excludeCacheFor?: string[];\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n const { middleware } = getConfiguration();\n\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Cookie,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n lookupCookie: middleware.cookieName,\n htmlTag: document.documentElement,\n };\n};\n\n// Helper functions for various checks and operations\nconst isLocalStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.localStorage.setItem(testKey, 'foo');\n window.localStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isSessionStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.sessionStorage.setItem(testKey, 'foo');\n window.sessionStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\n// Function to detect language using different detectors\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locales | Locales[]> => {\n const detected: Record<LanguageDetector, Locales | Locales[]> = {} as Record<\n LanguageDetector,\n Locales | Locales[]\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locales;\n }\n };\n\n const cookieDetector = () => {\n if (typeof document === 'undefined') return;\n const cookies = document.cookie.split(';');\n const cookieName = `${options.lookupCookie ?? ''}=`;\n const cookie = cookies.find((c) => c.trim().startsWith(cookieName));\n if (cookie) {\n const value = cookie.split('=')[1].trim();\n\n detected[LanguageDetector.Cookie] = value as Locales;\n }\n };\n\n const localStorageDetector = () => {\n if (!isLocalStorageAvailable()) return;\n const value = window.localStorage.getItem(options.lookupLocalStorage ?? '');\n if (value) {\n detected[LanguageDetector.LocalStorage] = value as Locales;\n }\n };\n\n const sessionStorageDetector = () => {\n if (!isSessionStorageAvailable()) return;\n const value = window.sessionStorage.getItem(\n options.lookupSessionStorage ?? ''\n );\n if (value) {\n detected[LanguageDetector.SessionStorage] = value as Locales;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n if (navigator.language) {\n detected[LanguageDetector.Navigator] = navigator.language as Locales;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n detected[LanguageDetector.HtmlTag] = lang as Locales;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Cookie]: cookieDetector,\n [LanguageDetector.LocalStorage]: localStorageDetector,\n [LanguageDetector.SessionStorage]: sessionStorageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locales | Locales[]>,\n order: LanguageDetector[]\n): Locales => {\n const { internationalization } = getConfiguration();\n\n for (const detector of order) {\n const localesArray = [locales[detector]].flat() as Locales[];\n\n for (const locale of localesArray) {\n if (\n locale &&\n (internationalization.locales ?? localeList).includes(locale)\n ) {\n return locale;\n } else if (\n locale?.includes('-') &&\n (internationalization.locales ?? localeList).includes(\n locale.split('-')[0] as Locales\n )\n ) {\n return locale.split('-')[0] as Locales;\n }\n }\n }\n\n return internationalization.defaultLocale;\n};\n\n/**\n * Core language detector function\n * const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locales => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":";AAAA,SAAS,wBAAsC;AAC/C,SAAS,kBAAkB;AAEpB,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,iBAAc;AACd,EAAAA,kBAAA,YAAS;AACT,EAAAA,kBAAA,kBAAe;AACf,EAAAA,kBAAA,oBAAiB;AACjB,EAAAA,kBAAA,eAAY;AACZ,EAAAA,kBAAA,aAAU;AANA,SAAAA;AAAA,GAAA;AAoBZ,MAAM,qBAAqB,MAA+B;AACxD,QAAM,EAAE,WAAW,IAAI,iBAAiB;AAExC,SAAO;AAAA,IACL,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,IACnB,cAAc,WAAW;AAAA,IACzB,SAAS,SAAS;AAAA,EACpB;AACF;AAGA,MAAM,0BAA0B,MAAe;AAC7C,MAAI;AACF,QAAI,OAAO,WAAW
|
|
1
|
+
{"version":3,"sources":["../../../src/client/getBrowserLocale.tsx"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Cookie = 'cookie',\n LocalStorage = 'localStorage',\n SessionStorage = 'sessionStorage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n lookupCookie?: string;\n lookupLocalStorage?: string;\n lookupSessionStorage?: string;\n excludeCacheFor?: string[];\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n const { middleware } = getConfiguration();\n\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Cookie,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n lookupCookie: middleware.cookieName,\n htmlTag: document.documentElement,\n };\n};\n\n// Helper functions for various checks and operations\nconst isLocalStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.localStorage.setItem(testKey, 'foo');\n window.localStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isSessionStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.sessionStorage.setItem(testKey, 'foo');\n window.sessionStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\n// Function to detect language using different detectors\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locales | Locales[]> => {\n const detected: Record<LanguageDetector, Locales | Locales[]> = {} as Record<\n LanguageDetector,\n Locales | Locales[]\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locales;\n }\n };\n\n const cookieDetector = () => {\n if (typeof document === 'undefined') return;\n const cookies = document.cookie.split(';');\n const cookieName = `${options.lookupCookie ?? ''}=`;\n const cookie = cookies.find((c) => c.trim().startsWith(cookieName));\n if (cookie) {\n const value = cookie.split('=')[1].trim();\n\n detected[LanguageDetector.Cookie] = value as Locales;\n }\n };\n\n const localStorageDetector = () => {\n if (!isLocalStorageAvailable()) return;\n const value = window.localStorage.getItem(options.lookupLocalStorage ?? '');\n if (value) {\n detected[LanguageDetector.LocalStorage] = value as Locales;\n }\n };\n\n const sessionStorageDetector = () => {\n if (!isSessionStorageAvailable()) return;\n const value = window.sessionStorage.getItem(\n options.lookupSessionStorage ?? ''\n );\n if (value) {\n detected[LanguageDetector.SessionStorage] = value as Locales;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n if (navigator.language) {\n detected[LanguageDetector.Navigator] = navigator.language as Locales;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n detected[LanguageDetector.HtmlTag] = lang as Locales;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Cookie]: cookieDetector,\n [LanguageDetector.LocalStorage]: localStorageDetector,\n [LanguageDetector.SessionStorage]: sessionStorageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locales | Locales[]>,\n order: LanguageDetector[]\n): Locales => {\n const { internationalization } = getConfiguration();\n\n for (const detector of order) {\n const localesArray = [locales[detector]].flat() as Locales[];\n\n for (const locale of localesArray) {\n if (\n locale &&\n (internationalization.locales ?? localeList).includes(locale)\n ) {\n return locale;\n } else if (\n locale?.includes('-') &&\n (internationalization.locales ?? localeList).includes(\n locale.split('-')[0] as Locales\n )\n ) {\n return locale.split('-')[0] as Locales;\n }\n }\n }\n\n return internationalization.defaultLocale;\n};\n\n/**\n * Core language detector function\n * const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locales => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":";AAAA,SAAS,wBAAsC;AAC/C,SAAS,kBAAkB;AAEpB,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,iBAAc;AACd,EAAAA,kBAAA,YAAS;AACT,EAAAA,kBAAA,kBAAe;AACf,EAAAA,kBAAA,oBAAiB;AACjB,EAAAA,kBAAA,eAAY;AACZ,EAAAA,kBAAA,aAAU;AANA,SAAAA;AAAA,GAAA;AAoBZ,MAAM,qBAAqB,MAA+B;AACxD,QAAM,EAAE,WAAW,IAAI,iBAAiB;AAExC,SAAO;AAAA,IACL,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,IACnB,cAAc,WAAW;AAAA,IACzB,SAAS,SAAS;AAAA,EACpB;AACF;AAGA,MAAM,0BAA0B,MAAe;AAC7C,MAAI;AACF,QAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,UAAM,UAAU;AAChB,WAAO,aAAa,QAAQ,SAAS,KAAK;AAC1C,WAAO,aAAa,WAAW,OAAO;AACtC,WA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B;AAC9B;AAMO,MAAM,mBAAmB,CAC9B,cAAmD,CAAC,MACxC;AACZ,QAAM,UAAU,EAAE,GAAG,mBAAmB,GAAG,GAAG,YAAY;AAE1D,QAAM,UAAU,eAAe,QAAQ,SAAS,CAAC,GAAG,OAAO;AAE3D,SAAO,wBAAwB,SAAS,QAAQ,SAAS,CAAC,CAAC;AAC7D;","names":["LanguageDetector"]}
|
|
@@ -7,7 +7,7 @@ import { LanguageContent } from '@intlayer/core';
|
|
|
7
7
|
declare const useContent: <Content>(languageContent: LanguageContent<Content>) => {
|
|
8
8
|
locale: intlayer.Locales;
|
|
9
9
|
content: Content;
|
|
10
|
-
t: <Content_1 = string>(languageContent:
|
|
10
|
+
t: <Content_1 = string>(languageContent: LanguageContent<Content_1>) => Content_1;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { useContent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = getConfiguration().middleware;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = getConfiguration().middleware;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as unknown as\n | Locales\n | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: Locales) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":";AAAA,SAAuB,wBAAwB;AAC/C,OAAO,aAAa;AAEpB,MAAM,EAAE,WAAW,IAAI,iBAAiB,EAAE;AAE1C,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,QAAQ,IAAI,UAAU;AAO3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,UAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":[]}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ export { useLocale } from './client/useLocale.mjs';
|
|
|
6
6
|
export { useTraduction } from './client/useTraduction.mjs';
|
|
7
7
|
export { localeCookie, setLocaleCookie, useLocaleCookie } from './client/useLocaleCookie.mjs';
|
|
8
8
|
export { getBrowserLocale } from './client/getBrowserLocale.mjs';
|
|
9
|
-
export {
|
|
9
|
+
export { IntlayerNode } from './useIntlayerBase.mjs';
|
|
10
10
|
import '@intlayer/config/client';
|
|
11
11
|
import '@intlayer/core';
|
|
12
12
|
import 'react';
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./chunk-
|
|
1
|
+
import "./chunk-ZD7AOCMD.mjs";
|
|
2
2
|
import { getTranslation } from './getTranslation.mjs';
|
|
3
3
|
import {
|
|
4
4
|
IntlayerProvider,
|
|
@@ -12,14 +12,12 @@ import {
|
|
|
12
12
|
getBrowserLocale,
|
|
13
13
|
useLocaleBase
|
|
14
14
|
} from './client/index.mjs';
|
|
15
|
-
import { recursiveStringifyContent } from './useIntlayerBase.mjs';
|
|
16
15
|
export {
|
|
17
16
|
IntlayerClientContext,
|
|
18
17
|
IntlayerProvider,
|
|
19
18
|
getBrowserLocale,
|
|
20
19
|
getTranslation,
|
|
21
20
|
localeCookie,
|
|
22
|
-
recursiveStringifyContent,
|
|
23
21
|
setLocaleCookie,
|
|
24
22
|
useIntlayer,
|
|
25
23
|
useLocale,
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerProvider,\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n} from './client/index';\nexport {
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerProvider,\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n} from './client/index';\nexport type { IntlayerNode } from './useIntlayerBase';\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-ZD7AOCMD.mjs";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config/client";
|
|
3
3
|
import {
|
|
4
4
|
NodeType,
|
|
@@ -53,7 +53,7 @@ const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = [])
|
|
|
53
53
|
if (typeof field === "object") {
|
|
54
54
|
if (field.nodeType === NodeType.Translation) {
|
|
55
55
|
return processTranslation(
|
|
56
|
-
field,
|
|
56
|
+
field[NodeType.Translation],
|
|
57
57
|
locale,
|
|
58
58
|
dictionaryId,
|
|
59
59
|
dictionaryPath,
|
|
@@ -62,7 +62,7 @@ const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = [])
|
|
|
62
62
|
}
|
|
63
63
|
if (field.nodeType === NodeType.Enumeration) {
|
|
64
64
|
return processEnumeration(
|
|
65
|
-
field,
|
|
65
|
+
field[NodeType.Enumeration],
|
|
66
66
|
locale,
|
|
67
67
|
dictionaryId,
|
|
68
68
|
dictionaryPath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n findMatchingCondition,\n type KeyPath,\n type Dictionary,\n type DictionaryValue,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<DictionaryValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: DictionaryValue = getTranslation<DictionaryValue>(\n languageContent,\n locale\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Translation, key: locale },\n ];\n\n return processDictionary(\n translationResult,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration =\n (\n enumerationContent: QuantityContent<DictionaryValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n ): TransformedContentValue =>\n (quantity: number): TransformedContentValue => {\n const enumerationResult: DictionaryValue = getEnumeration<DictionaryValue>(\n enumerationContent,\n quantity\n );\n\n const matchingCondition = findMatchingCondition(\n enumerationContent,\n quantity\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Enumeration, key: matchingCondition.toString() },\n ];\n\n return processDictionary(\n enumerationResult,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n ) as TransformedContentValue;\n };\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: DictionaryValue | undefined,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (\n (field as TranslationContent<DictionaryValue>).nodeType ===\n NodeType.Translation\n ) {\n return processTranslation(\n field as LanguageContent<DictionaryValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n ) as TransformedContentValue;\n }\n\n if (\n (field as EnumerationContent<DictionaryValue>).nodeType ===\n NodeType.Enumeration\n ) {\n return processEnumeration(\n field as QuantityContent<DictionaryValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n field!,\n dictionaryId,\n dictionaryPath,\n keyPath,\n locale\n ) as TransformedContentValue;\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n // Destructure the component properties\n\n const convertChildrenAsArray = (element: ReactElement): ReactElement => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children).forEach((key) => {\n childrenResult.push(createReactElement(children[key]));\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(element);\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(type ?? 'div', props, ...props.children);\n};\n\nconst traceKeys: string[] = ['filePath', 'nodeType'];\n\n/**\n * Function that process a dictionary and return the result to be used in the application.\n */\nexport const processDictionary = (\n content: Dictionary | DictionaryValue,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = [],\n locale: Locales = defaultLocale\n // eslint-disable-next-line sonarjs/cognitive-complexity\n): TransformedContent => {\n // If it's a React element, render it\n if (isReactNode(content as Record<string, unknown>)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const isArray = Array.isArray(content);\n\n let result: TransformedContent = {};\n\n if (typeof (content as TypedNode).nodeType !== 'undefined') {\n return processNode(\n content as DictionaryValue,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n ) as TransformedContent;\n } else if (isArray) {\n // Eslint fix because promises are awaited during build stage\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n result = (content as DictionaryValue[]).map((field, key) => {\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ArrayExpression', key },\n ];\n\n return processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n }) as TransformedContent;\n } else {\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key as keyof typeof content];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ObjectExpression', key },\n ];\n\n const nodeResult = processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n\n result[key] = nodeResult;\n }\n }\n\n return result;\n }\n\n return {\n content,\n keyPath,\n dictionaryId,\n dictionaryPath,\n };\n};\n"],"mappings":";AACA,SAAuB,wBAAwB;AAC/C;AAAA,EACE;AAAA,EAGA;AAAA,OAOK;AACP,SAA4B,qBAAqC;AACjE,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAM/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AAC1D,cAAM,gBAA2B;AAAA,UAC/B,GAAG;AAAA,UACH,EAAE,MAAM,mBAAmB,IAAI;AAAA,QACjC;AAEA,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,OAAO;AAEL,iBAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,cAAM,QAAQ,QAAQ,GAA2B;AAEjD,YAAI,UAAU,SAAS,GAAG,GAAG;AAC3B,iBAAO,GAAG,IAAI;AACd;AAAA,QACF;AAEA,cAAM,gBAA2B;AAAA,UAC/B,GAAG;AAAA,UACH,EAAE,MAAM,oBAAoB,IAAI;AAAA,QAClC;AAEA,cAAM,aAAa;AAAA,UACjB;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["element"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n findMatchingCondition,\n type KeyPath,\n type Dictionary,\n type DictionaryValue,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<DictionaryValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: DictionaryValue = getTranslation<DictionaryValue>(\n languageContent,\n locale\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Translation, key: locale },\n ];\n\n return processDictionary(\n translationResult,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration =\n (\n enumerationContent: QuantityContent<DictionaryValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n ): TransformedContentValue =>\n (quantity: number): TransformedContentValue => {\n const enumerationResult: DictionaryValue = getEnumeration<DictionaryValue>(\n enumerationContent,\n quantity\n );\n\n const matchingCondition = findMatchingCondition(\n enumerationContent,\n quantity\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Enumeration, key: matchingCondition.toString() },\n ];\n\n return processDictionary(\n enumerationResult,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n ) as TransformedContentValue;\n };\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: DictionaryValue | undefined,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (\n (field as TranslationContent<DictionaryValue>).nodeType ===\n NodeType.Translation\n ) {\n return processTranslation(\n field[\n NodeType.Translation as keyof typeof field\n ] as LanguageContent<DictionaryValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n ) as TransformedContentValue;\n }\n\n if (\n (field as EnumerationContent<DictionaryValue>).nodeType ===\n NodeType.Enumeration\n ) {\n return processEnumeration(\n field[\n NodeType.Enumeration as keyof typeof field\n ] as QuantityContent<DictionaryValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n field!,\n dictionaryId,\n dictionaryPath,\n keyPath,\n locale\n ) as TransformedContentValue;\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n const convertChildrenAsArray = (element: ReactElement): ReactElement => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children).forEach((key) => {\n childrenResult.push(createReactElement(children[key]));\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(element);\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(type ?? 'div', props, ...props.children);\n};\n\nconst traceKeys: string[] = ['filePath', 'nodeType'];\n\n/**\n * Function that process a dictionary and return the result to be used in the application.\n */\nexport const processDictionary = (\n content: Dictionary | DictionaryValue,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = [],\n locale: Locales = defaultLocale\n // eslint-disable-next-line sonarjs/cognitive-complexity\n): TransformedContent => {\n // If it's a React element, render it\n if (isReactNode(content as Record<string, unknown>)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const isArray = Array.isArray(content);\n\n let result: TransformedContent = {};\n\n if (typeof (content as TypedNode).nodeType !== 'undefined') {\n return processNode(\n content as DictionaryValue,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n ) as TransformedContent;\n } else if (isArray) {\n // Eslint fix because promises are awaited during build stage\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n result = (content as DictionaryValue[]).map((field, key) => {\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ArrayExpression', key },\n ];\n\n return processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n }) as TransformedContent;\n } else {\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key as keyof typeof content];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ObjectExpression', key },\n ];\n\n const nodeResult = processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n\n result[key] = nodeResult;\n }\n }\n\n return result;\n }\n\n return {\n content,\n keyPath,\n dictionaryId,\n dictionaryPath,\n };\n};\n"],"mappings":";AACA,SAAuB,wBAAwB;AAC/C;AAAA,EACE;AAAA,EAGA;AAAA,OAOK;AACP,SAA4B,qBAAqC;AACjE,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAM/B,MAAM;AAAA,EACJ,sBAAsB,EAAE,cAAc;AACxC,IAAI,iBAAiB;AAErB,MAAM,qBAAqB,CACzB,iBACA,QACA,cACA,gBACA,UAAqB,CAAC,MACC;AACvB,QAAM,oBAAqC;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAA2B;AAAA,IAC/B,GAAG;AAAA,IACH,EAAE,MAAM,SAAS,aAAa,KAAK,OAAO;AAAA,EAC5C;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,MAAM,qBACJ,CACE,oBACA,QACA,cACA,gBACA,UAAqB,CAAC,MAExB,CAAC,aAA8C;AAC7C,QAAM,oBAAqC;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,oBAAoB;AAAA,IACxB;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAA2B;AAAA,IAC/B,GAAG;AAAA,IACH,EAAE,MAAM,SAAS,aAAa,KAAK,kBAAkB,SAAS,EAAE;AAAA,EAClE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEF,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eAAe,OAAO,MAAM,UAA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
3
|
+
import { createRequire } from "module";
|
|
4
|
+
const requireFunction = (packagePath) => {
|
|
5
|
+
try {
|
|
6
|
+
return typeof import.meta.url === "undefined" ? require(packagePath) : createRequire(import.meta.url)(packagePath);
|
|
7
|
+
} catch (error) {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const IntlayerEditorElement = ({
|
|
12
|
+
content,
|
|
13
|
+
..._props
|
|
14
|
+
}) => {
|
|
15
|
+
return content;
|
|
16
|
+
};
|
|
17
|
+
IntlayerEditorElement.content = "";
|
|
18
|
+
const renderIntlayerEditor = (props) => {
|
|
19
|
+
const _renderIntlayerEditor = requireFunction(
|
|
20
|
+
"intlayer-editor/client"
|
|
21
|
+
)?.renderIntlayerEditor;
|
|
22
|
+
if (typeof _renderIntlayerEditor === "undefined") {
|
|
23
|
+
const Result = /* @__PURE__ */ jsx(IntlayerEditorElement, { ...props });
|
|
24
|
+
return { ...Result, value: props.content };
|
|
25
|
+
}
|
|
26
|
+
return _renderIntlayerEditor(props);
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
renderIntlayerEditor
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=renderIntlayerEditor.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/renderIntlayerEditor.tsx"],"sourcesContent":["import { createRequire } from 'module';\nimport type { IntlayerEditorElementProps } from 'intlayer-editor/client';\n\nconst requireFunction = (packagePath: string) => {\n try {\n return typeof import.meta.url === 'undefined'\n ? require(packagePath)\n : createRequire(import.meta.url)(packagePath);\n } catch (error) {\n return undefined;\n }\n};\n\nconst IntlayerEditorElement = ({\n content,\n ..._props\n}: IntlayerEditorElementProps) => {\n return content;\n};\n\nIntlayerEditorElement.content = '';\n\nexport const renderIntlayerEditor = (props: IntlayerEditorElementProps) => {\n const _renderIntlayerEditor = requireFunction(\n 'intlayer-editor/client'\n )?.renderIntlayerEditor;\n\n if (typeof _renderIntlayerEditor === 'undefined') {\n const Result = <IntlayerEditorElement {...props} />;\n\n return { ...Result, value: props.content };\n }\n\n return _renderIntlayerEditor(props);\n};\n"],"mappings":";AA4BmB;AA5BnB,SAAS,qBAAqB;AAG9B,MAAM,kBAAkB,CAAC,gBAAwB;AAC/C,MAAI;AACF,WAAO,OAAO,YAAY,QAAQ,cAC9B,QAAQ,WAAW,IACnB,cAAc,YAAY,GAAG,EAAE,WAAW;AAAA,EAChD,SAAS,OAAO;AACd,WAAO;AAAA,EACT;AACF;AAEA,MAAM,wBAAwB,CAAC;AAAA,EAC7B;AAAA,EACA,GAAG;AACL,MAAkC;AAChC,SAAO;AACT;AAEA,sBAAsB,UAAU;AAEzB,MAAM,uBAAuB,CAAC,UAAsC;AACzE,QAAM,wBAAwB;AAAA,IAC5B;AAAA,EACF,GAAG;AAEH,MAAI,OAAO,0BAA0B,aAAa;AAChD,UAAM,SAAS,oBAAC,yBAAuB,GAAG,OAAO;AAEjD,WAAO,EAAE,GAAG,QAAQ,OAAO,MAAM,QAAQ;AAAA,EAC3C;AAEA,SAAO,sBAAsB,KAAK;AACpC;","names":[]}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import { PropsWithChildren, FC } from 'react';
|
|
3
1
|
import { Locales } from '@intlayer/config/client';
|
|
2
|
+
import { PropsWithChildren, FC } from 'react';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Context that store the current locale on the server side
|
|
7
6
|
*/
|
|
8
7
|
declare const IntlayerServerContext: {
|
|
9
8
|
Provider: ({ children, value, }: {
|
|
10
|
-
children:
|
|
9
|
+
children: React.ReactNode;
|
|
11
10
|
value: Locales;
|
|
12
|
-
}) =>
|
|
11
|
+
}) => React.ReactNode;
|
|
13
12
|
Consumer: ({ children, }: {
|
|
14
|
-
children: (context: Locales | undefined) =>
|
|
15
|
-
}) =>
|
|
13
|
+
children: (context: Locales | undefined) => React.ReactNode;
|
|
14
|
+
}) => React.ReactNode;
|
|
16
15
|
_storage: () => {
|
|
17
16
|
value: Locales | undefined;
|
|
18
17
|
};
|