react-intlayer 2.0.0 → 2.0.1
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 +6 -2
- package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -1
- package/dist/cjs/client/{IntlayerClientProvider.cjs → IntlayerProvider.cjs} +11 -9
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/client/{IntlayerClientProvider.d.ts → IntlayerProvider.d.ts} +4 -3
- package/dist/cjs/client/index.cjs +6 -6
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/index.d.ts +2 -1
- package/dist/cjs/client/useIntlayer.cjs +2 -2
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.d.ts +2 -1
- package/dist/cjs/client/useLocale.cjs +2 -2
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +2 -2
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +2 -2
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/index.cjs +7 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/processDictionary/contentDictionary.cjs.map +1 -1
- package/dist/cjs/processDictionary/contentDictionary.d.ts +9 -9
- package/dist/cjs/processDictionary/index.cjs +67 -51
- package/dist/cjs/processDictionary/index.cjs.map +1 -1
- package/dist/cjs/processDictionary/index.d.ts +4 -4
- package/dist/cjs/server/IntlayerServerProvider.cjs +3 -4
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.d.ts +1 -1
- package/dist/cjs/server/index.d.ts +1 -0
- package/dist/cjs/server/useIntlayer.d.ts +2 -1
- package/dist/cjs/useIntlayerBase.cjs +45 -1
- package/dist/cjs/useIntlayerBase.cjs.map +1 -1
- package/dist/cjs/useIntlayerBase.d.ts +51 -4
- package/dist/esm/client/ContentEditionLayout.mjs +5 -1
- package/dist/esm/client/ContentEditionLayout.mjs.map +1 -1
- package/dist/esm/client/{IntlayerClientProvider.d.mts → IntlayerProvider.d.mts} +4 -3
- package/dist/esm/client/{IntlayerClientProvider.mjs → IntlayerProvider.mjs} +7 -5
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +2 -1
- package/dist/esm/client/index.mjs +4 -4
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.d.mts +2 -1
- package/dist/esm/client/useIntlayer.mjs +1 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +1 -1
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/index.d.mts +3 -2
- package/dist/esm/index.mjs +6 -4
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/contentDictionary.d.mts +9 -9
- package/dist/esm/processDictionary/index.d.mts +4 -4
- package/dist/esm/processDictionary/index.mjs +67 -51
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.d.mts +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +3 -4
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/index.d.mts +1 -0
- package/dist/esm/server/useIntlayer.d.mts +2 -1
- package/dist/esm/useIntlayerBase.d.mts +51 -4
- package/dist/esm/useIntlayerBase.mjs +43 -1
- package/dist/esm/useIntlayerBase.mjs.map +1 -1
- package/package.json +8 -9
- package/src/index.ts +4 -3
- package/dist/cjs/IntlayerProvider.cjs +0 -37
- package/dist/cjs/IntlayerProvider.cjs.map +0 -1
- package/dist/cjs/IntlayerProvider.d.ts +0 -9
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +0 -1
- package/dist/esm/IntlayerProvider.d.mts +0 -9
- package/dist/esm/IntlayerProvider.mjs +0 -18
- package/dist/esm/IntlayerProvider.mjs.map +0 -1
- package/dist/esm/client/IntlayerClientProvider.mjs.map +0 -1
- package/src/IntlayerProvider.tsx +0 -24
- package/src/cli/react-intlayer.ts +0 -60
- package/src/client/ContentEditionLayout.tsx +0 -15
- package/src/client/IntlayerClientProvider.tsx +0 -83
- package/src/client/getBrowserLocale.tsx +0 -192
- package/src/client/index.ts +0 -16
- package/src/client/useContent.ts +0 -20
- package/src/client/useIntlayer.ts +0 -25
- package/src/client/useLocale.ts +0 -23
- package/src/client/useLocaleBase.ts +0 -24
- package/src/client/useLocaleCookie.ts +0 -32
- package/src/client/useTraduction.ts +0 -33
- package/src/craco/craco.config.ts +0 -11
- package/src/craco/intlayerCracoPlugin.ts +0 -89
- package/src/getEnumeration.ts +0 -41
- package/src/getTranslation.ts +0 -37
- package/src/processDictionary/contentDictionary.ts +0 -28
- package/src/processDictionary/index.ts +0 -231
- package/src/server/IntlayerServerProvider.tsx +0 -36
- package/src/server/getLocaleTranslation.ts +0 -22
- package/src/server/index.ts +0 -8
- package/src/server/serverContext.ts +0 -85
- package/src/server/useIntlayer.ts +0 -23
- package/src/server/useTraduction.ts +0 -34
- package/src/useIntlayerBase.ts +0 -38
- package/src/vite/intlayerPlugin.ts +0 -59
|
@@ -22,9 +22,13 @@ __export(ContentEditionLayout_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(ContentEditionLayout_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
-
var import_client = require("intlayer
|
|
25
|
+
var import_client = require("@intlayer/config/client");
|
|
26
|
+
var import_client2 = require("intlayer-editor/client");
|
|
27
|
+
const {
|
|
28
|
+
editor: { enabled }
|
|
29
|
+
} = (0, import_client.getConfiguration)();
|
|
26
30
|
const BlankLayout = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
27
|
-
const ContentEditionLayout = typeof
|
|
31
|
+
const ContentEditionLayout = typeof import_client2.ContentEditionLayout === "undefined" || !enabled ? BlankLayout : import_client2.ContentEditionLayout;
|
|
28
32
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
33
|
0 && (module.exports = {
|
|
30
34
|
ContentEditionLayout
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import {\n ContentEditionLayout as ContentEditionLayoutBase,\n type ContentEditionLayoutProps,\n} from 'intlayer-editor/client';\nimport type { FC } from 'react';\n\nconst BlankLayout: FC<ContentEditionLayoutProps> = ({ children }) => (\n <>{children}</>\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 ContentEditionLayoutBase === 'undefined'\n ? BlankLayout\n :
|
|
1
|
+
{"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport {\n ContentEditionLayout as ContentEditionLayoutBase,\n type ContentEditionLayoutProps,\n} from 'intlayer-editor/client';\nimport type { FC } from 'react';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nconst BlankLayout: FC<ContentEditionLayoutProps> = ({ children }) => (\n <>{children}</>\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 ContentEditionLayoutBase === 'undefined' || !enabled\n ? BlankLayout\n : ContentEditionLayoutBase;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYE;AAZF,oBAAiC;AACjC,IAAAA,iBAGO;AAGP,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,QAAI,gCAAiB;AAErB,MAAM,cAA6C,CAAC,EAAE,SAAS,MAC7D,2EAAG,UAAS;AAIP,MAAM,uBACX,OAAO,eAAAC,yBAA6B,eAAe,CAAC,UAChD,cACA,eAAAA;","names":["import_client","ContentEditionLayoutBase"]}
|
|
@@ -17,13 +17,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
20
|
+
var IntlayerProvider_exports = {};
|
|
21
|
+
__export(IntlayerProvider_exports, {
|
|
22
22
|
IntlayerClientContext: () => IntlayerClientContext,
|
|
23
|
-
|
|
23
|
+
IntlayerProvider: () => IntlayerProvider,
|
|
24
24
|
useIntlayerContext: () => useIntlayerContext
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(IntlayerProvider_exports);
|
|
27
27
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
28
|
var import_client = require("@intlayer/config/client");
|
|
29
29
|
var import_react = require("react");
|
|
@@ -34,15 +34,16 @@ const IntlayerClientContext = (0, import_react.createContext)({
|
|
|
34
34
|
setLocale: () => null
|
|
35
35
|
});
|
|
36
36
|
const useIntlayerContext = () => (0, import_react.useContext)(IntlayerClientContext);
|
|
37
|
-
const
|
|
37
|
+
const IntlayerProvider = ({
|
|
38
38
|
locale,
|
|
39
|
-
children
|
|
39
|
+
children,
|
|
40
|
+
setLocale: setLocaleProp
|
|
40
41
|
}) => {
|
|
41
42
|
const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
|
|
42
43
|
const [currentLocale, setCurrentLocale] = (0, import_react.useState)(
|
|
43
44
|
locale ?? import_useLocaleCookie.localeCookie ?? defaultLocale
|
|
44
45
|
);
|
|
45
|
-
const
|
|
46
|
+
const setLocaleBase = (0, import_react.useCallback)(
|
|
46
47
|
(newLocale) => {
|
|
47
48
|
if (currentLocale.toString() === newLocale.toString())
|
|
48
49
|
return;
|
|
@@ -55,6 +56,7 @@ const IntlayerClientProvider = ({
|
|
|
55
56
|
},
|
|
56
57
|
[availableLocales, currentLocale, locale]
|
|
57
58
|
);
|
|
59
|
+
const setLocale = setLocaleProp ?? setLocaleBase;
|
|
58
60
|
const value = (0, import_react.useMemo)(
|
|
59
61
|
() => ({ locale: currentLocale, setLocale }),
|
|
60
62
|
[currentLocale, setLocale]
|
|
@@ -72,7 +74,7 @@ const IntlayerClientProvider = ({
|
|
|
72
74
|
// Annotate the CommonJS export names for ESM import in node:
|
|
73
75
|
0 && (module.exports = {
|
|
74
76
|
IntlayerClientContext,
|
|
75
|
-
|
|
77
|
+
IntlayerProvider,
|
|
76
78
|
useIntlayerContext
|
|
77
79
|
});
|
|
78
|
-
//# sourceMappingURL=
|
|
80
|
+
//# sourceMappingURL=IntlayerProvider.cjs.map
|
|
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6EM;AA3EN,oBAA+C;AAC/C,mBAQO;AACP,kCAAqC;AACrC,6BAA8C;AAUvC,MAAM,4BAAwB,4BAA6B;AAAA,EAChE,QAAQ,2CAAgB,gCAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,UAAM,yBAAW,qBAAqB;AAUjE,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AAAA,EACA,WAAW;AACb,MAAM;AACJ,QAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AAErB,QAAM,CAAC,eAAe,gBAAgB,QAAI;AAAA,IACxC,UAAU,uCAAgB;AAAA,EAC5B;AAEA,QAAM,oBAAgB;AAAA,IACpB,CAAC,cAAuB;AACtB,UAAI,cAAc,SAAS,MAAM,UAAU,SAAS;AAAG;AAEvD,UAAI,CAAC,iBAAiB,SAAS,SAAS,GAAG;AACzC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,uBAAiB,SAAS;AAC1B,kDAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,YAAY,iBAAiB;AAEnC,QAAM,YAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAqB;AAAA,IACrD,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,4CAAC,sBAAsB,UAAtB,EAA+B,OAC9B;AAAA,IAAC;AAAA;AAAA,MACC,QAAQ;AAAA,MACR;AAAA,MACA,YAAY;AAAA,MAEX;AAAA;AAAA,EACH,GACF;AAEJ;","names":[]}
|
|
@@ -14,12 +14,13 @@ declare const IntlayerClientContext: react.Context<IntlayerValue>;
|
|
|
14
14
|
* Hook that provides the current locale
|
|
15
15
|
*/
|
|
16
16
|
declare const useIntlayerContext: () => IntlayerValue;
|
|
17
|
-
type
|
|
17
|
+
type IntlayerProviderProps = PropsWithChildren & {
|
|
18
18
|
locale?: Locales;
|
|
19
|
+
setLocale?: (locale: Locales) => void;
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
22
|
* Provider that store the current locale on the client side
|
|
22
23
|
*/
|
|
23
|
-
declare const
|
|
24
|
+
declare const IntlayerProvider: FC<IntlayerProviderProps>;
|
|
24
25
|
|
|
25
|
-
export { IntlayerClientContext,
|
|
26
|
+
export { IntlayerClientContext, IntlayerProvider, type IntlayerProviderProps, useIntlayerContext };
|
|
@@ -18,20 +18,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var client_exports = {};
|
|
20
20
|
__export(client_exports, {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
IntlayerClientContext: () => import_IntlayerProvider.IntlayerClientContext,
|
|
22
|
+
IntlayerProvider: () => import_IntlayerProvider.IntlayerProvider,
|
|
23
23
|
getBrowserLocale: () => import_getBrowserLocale.getBrowserLocale,
|
|
24
24
|
localeCookie: () => import_useLocaleCookie.localeCookie,
|
|
25
25
|
setLocaleCookie: () => import_useLocaleCookie.setLocaleCookie,
|
|
26
26
|
useIntlayer: () => import_useIntlayer.useIntlayer,
|
|
27
|
-
useIntlayerContext: () =>
|
|
27
|
+
useIntlayerContext: () => import_IntlayerProvider.useIntlayerContext,
|
|
28
28
|
useLocale: () => import_useLocale.useLocale,
|
|
29
29
|
useLocaleBase: () => import_useLocaleBase.useLocaleBase,
|
|
30
30
|
useLocaleCookie: () => import_useLocaleCookie.useLocaleCookie,
|
|
31
31
|
useTraduction: () => import_useTraduction.useTraduction
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(client_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
35
35
|
var import_useIntlayer = require('./useIntlayer.cjs');
|
|
36
36
|
var import_useLocaleBase = require('./useLocaleBase.cjs');
|
|
37
37
|
var import_useLocale = require('./useLocale.cjs');
|
|
@@ -40,8 +40,8 @@ var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
|
40
40
|
var import_getBrowserLocale = require('./getBrowserLocale.cjs');
|
|
41
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
42
42
|
0 && (module.exports = {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
IntlayerClientContext,
|
|
44
|
+
IntlayerProvider,
|
|
45
45
|
getBrowserLocale,
|
|
46
46
|
localeCookie,
|
|
47
47
|
setLocaleCookie,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayerContext,\n IntlayerProvider,\n} from './IntlayerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAKO;AACP,yBAA4B;AAC5B,2BAA8B;AAC9B,uBAA0B;AAC1B,2BAA8B;AAC9B,6BAIO;AACP,8BAAiC;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { IntlayerClientContext
|
|
1
|
+
export { IntlayerClientContext, IntlayerProvider, IntlayerProviderProps, useIntlayerContext } from './IntlayerProvider.js';
|
|
2
2
|
export { useIntlayer } from './useIntlayer.js';
|
|
3
3
|
export { useLocaleBase } from './useLocaleBase.js';
|
|
4
4
|
export { useLocale } from './useLocale.js';
|
|
@@ -8,5 +8,6 @@ export { getBrowserLocale } from './getBrowserLocale.js';
|
|
|
8
8
|
import 'react';
|
|
9
9
|
import '@intlayer/config/client';
|
|
10
10
|
import '../useIntlayerBase.js';
|
|
11
|
+
import '@intlayer/config';
|
|
11
12
|
import 'intlayer';
|
|
12
13
|
import '@intlayer/core';
|
|
@@ -24,9 +24,9 @@ __export(useIntlayer_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(useIntlayer_exports);
|
|
25
25
|
var import_react = require("react");
|
|
26
26
|
var import_useIntlayerBase = require('../useIntlayerBase.cjs');
|
|
27
|
-
var
|
|
27
|
+
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
28
28
|
const useIntlayer = (id, locale) => {
|
|
29
|
-
const { locale: currentLocale } = (0, import_react.useContext)(
|
|
29
|
+
const { locale: currentLocale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
30
30
|
const localeTarget = locale ?? currentLocale;
|
|
31
31
|
return (0, import_useIntlayerBase.useIntlayerBase)(id, localeTarget);
|
|
32
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking 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 useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA2B;AAC3B,6BAIO;AACP,8BAAsC;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,aAAO,wCAAgB,IAAI,YAAY;AACzC;","names":[]}
|
|
@@ -25,10 +25,10 @@ module.exports = __toCommonJS(useLocale_exports);
|
|
|
25
25
|
var import_client = require("@intlayer/config/client");
|
|
26
26
|
var import_core = require("@intlayer/core");
|
|
27
27
|
var import_react = require("react");
|
|
28
|
-
var
|
|
28
|
+
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
29
29
|
const useLocale = () => {
|
|
30
30
|
const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
|
|
31
|
-
const { locale, setLocale } = (0, import_react.useContext)(
|
|
31
|
+
const { locale, setLocale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
32
32
|
return {
|
|
33
33
|
locale,
|
|
34
34
|
// Current locale
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = () => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AACjC,kBAA2B;AAC3B,mBAA2B;AAC3B,8BAAsC;AAK/B,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,UAAU,QAAI,yBAAW,6CAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -25,10 +25,10 @@ module.exports = __toCommonJS(useLocaleBase_exports);
|
|
|
25
25
|
var import_client = require("@intlayer/config/client");
|
|
26
26
|
var import_core = require("@intlayer/core");
|
|
27
27
|
var import_react = require("react");
|
|
28
|
-
var
|
|
28
|
+
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
29
29
|
const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
|
|
30
30
|
const useLocaleBase = () => {
|
|
31
|
-
const { locale, setLocale } = (0, import_react.useContext)(
|
|
31
|
+
const { locale, setLocale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
32
32
|
return {
|
|
33
33
|
locale,
|
|
34
34
|
// Current locale
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AACjC,kBAA2B;AAC3B,mBAA2B;AAC3B,8BAAsC;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AAKd,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,QAAI,yBAAW,6CAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -23,9 +23,9 @@ __export(useTraduction_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(useTraduction_exports);
|
|
24
24
|
var import_react = require("react");
|
|
25
25
|
var import_getTranslation = require('../getTranslation.cjs');
|
|
26
|
-
var
|
|
26
|
+
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
27
27
|
const useTraduction = (languageContent) => {
|
|
28
|
-
const { locale } = (0, import_react.useContext)(
|
|
28
|
+
const { locale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
29
29
|
return (0, import_getTranslation.getTranslation)(languageContent, locale);
|
|
30
30
|
};
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTraduction<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA2B;AAC3B,4BAA+B;AAC/B,8BAAsC;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,QAAI,yBAAW,6CAAqB;AAEnD,aAAO,sCAAe,iBAAiB,MAAM;AAC/C;","names":[]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -18,11 +18,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var src_exports = {};
|
|
20
20
|
__export(src_exports, {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
IntlayerClientContext: () => import_client.IntlayerClientContext,
|
|
22
|
+
IntlayerProvider: () => import_client.IntlayerProvider,
|
|
23
23
|
getBrowserLocale: () => import_client.getBrowserLocale,
|
|
24
24
|
getTranslation: () => import_getTranslation.getTranslation,
|
|
25
25
|
localeCookie: () => import_client.localeCookie,
|
|
26
|
+
recursiveStringifyContent: () => import_useIntlayerBase.recursiveStringifyContent,
|
|
26
27
|
setLocaleCookie: () => import_client.setLocaleCookie,
|
|
27
28
|
useIntlayer: () => import_client.useIntlayer,
|
|
28
29
|
useLocale: () => import_client.useLocale,
|
|
@@ -33,13 +34,15 @@ __export(src_exports, {
|
|
|
33
34
|
module.exports = __toCommonJS(src_exports);
|
|
34
35
|
var import_getTranslation = require('./getTranslation.cjs');
|
|
35
36
|
var import_client = require('./client/index.cjs');
|
|
37
|
+
var import_useIntlayerBase = require('./useIntlayerBase.cjs');
|
|
36
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
39
|
0 && (module.exports = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
IntlayerClientContext,
|
|
41
|
+
IntlayerProvider,
|
|
40
42
|
getBrowserLocale,
|
|
41
43
|
getTranslation,
|
|
42
44
|
localeCookie,
|
|
45
|
+
recursiveStringifyContent,
|
|
43
46
|
setLocaleCookie,
|
|
44
47
|
useIntlayer,
|
|
45
48
|
useLocale,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n
|
|
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 { recursiveStringifyContent } from './useIntlayerBase';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAC/B,oBAYO;AACP,6BAA0C;","names":[]}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export { getTranslation } from './getTranslation.js';
|
|
2
|
-
export { IntlayerClientContext
|
|
2
|
+
export { IntlayerClientContext, IntlayerProvider, IntlayerProviderProps } from './client/IntlayerProvider.js';
|
|
3
3
|
export { useIntlayer } from './client/useIntlayer.js';
|
|
4
4
|
export { useLocaleBase } from './client/useLocaleBase.js';
|
|
5
5
|
export { useLocale } from './client/useLocale.js';
|
|
6
6
|
export { useTraduction } from './client/useTraduction.js';
|
|
7
7
|
export { localeCookie, setLocaleCookie, useLocaleCookie } from './client/useLocaleCookie.js';
|
|
8
8
|
export { getBrowserLocale } from './client/getBrowserLocale.js';
|
|
9
|
+
export { recursiveStringifyContent } from './useIntlayerBase.js';
|
|
9
10
|
import '@intlayer/config/client';
|
|
10
11
|
import '@intlayer/core';
|
|
11
12
|
import 'react';
|
|
12
|
-
import '
|
|
13
|
+
import '@intlayer/config';
|
|
13
14
|
import 'intlayer';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/processDictionary/contentDictionary.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/processDictionary/contentDictionary.ts"],"sourcesContent":["import type { KeyPath, Locales } from '@intlayer/core';\nimport type { ReactNode } from 'react';\n\nexport type TransformedContentValue =\n | string\n | ReactNode\n | {\n [key: string]: TransformedContentValue;\n }\n | undefined\n | ((quantity: number) => TransformedContentValue);\n\nexport type TransformedContentObject = {\n dictionaryId: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n locale: Locales;\n content: TransformedContentValue | TransformedContentValue[] | undefined;\n};\n\nexport type TransformedContent =\n | Record<\n string,\n | TransformedContentValue\n | TransformedContentValue[]\n | TransformedContentObject\n | undefined\n >\n | ReactNode;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KeyPath, Locales } from '@intlayer/core';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
type ContentValue = string | {
|
|
5
|
-
[key: string]: ContentValue;
|
|
6
|
-
} | TranslationContent<unknown>;
|
|
7
|
-
type Content = Record<string, ContentValue | undefined>;
|
|
8
4
|
type TransformedContentValue = string | ReactNode | {
|
|
9
5
|
[key: string]: TransformedContentValue;
|
|
10
6
|
} | undefined | ((quantity: number) => TransformedContentValue);
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
type TransformedContentObject = {
|
|
8
|
+
dictionaryId: string;
|
|
9
|
+
dictionaryPath: string;
|
|
10
|
+
keyPath: KeyPath[];
|
|
11
|
+
locale: Locales;
|
|
12
|
+
content: TransformedContentValue | TransformedContentValue[] | undefined;
|
|
14
13
|
};
|
|
14
|
+
type TransformedContent = Record<string, TransformedContentValue | TransformedContentValue[] | TransformedContentObject | undefined> | ReactNode;
|
|
15
15
|
|
|
16
|
-
export type {
|
|
16
|
+
export type { TransformedContent, TransformedContentObject, TransformedContentValue };
|
|
@@ -24,7 +24,6 @@ __export(processDictionary_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(processDictionary_exports);
|
|
25
25
|
var import_client = require("@intlayer/config/client");
|
|
26
26
|
var import_core = require("@intlayer/core");
|
|
27
|
-
var import_client2 = require("intlayer-editor/client");
|
|
28
27
|
var import_react = require("react");
|
|
29
28
|
var import_getEnumeration = require('../getEnumeration.cjs');
|
|
30
29
|
var import_getTranslation = require('../getTranslation.cjs');
|
|
@@ -48,28 +47,26 @@ const processTranslation = (languageContent, locale, dictionaryId, dictionaryPat
|
|
|
48
47
|
locale
|
|
49
48
|
);
|
|
50
49
|
};
|
|
51
|
-
const processEnumeration = (enumerationContent, locale, dictionaryId, dictionaryPath, keyPath = []) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
);
|
|
72
|
-
};
|
|
50
|
+
const processEnumeration = (enumerationContent, locale, dictionaryId, dictionaryPath, keyPath = []) => (quantity) => {
|
|
51
|
+
const enumerationResult = (0, import_getEnumeration.getEnumeration)(
|
|
52
|
+
enumerationContent,
|
|
53
|
+
quantity
|
|
54
|
+
);
|
|
55
|
+
const matchingCondition = (0, import_core.findMatchingCondition)(
|
|
56
|
+
enumerationContent,
|
|
57
|
+
quantity
|
|
58
|
+
);
|
|
59
|
+
const resultKeyPath = [
|
|
60
|
+
...keyPath,
|
|
61
|
+
{ type: import_core.NodeType.Enumeration, key: matchingCondition.toString() }
|
|
62
|
+
];
|
|
63
|
+
return processDictionary(
|
|
64
|
+
enumerationResult,
|
|
65
|
+
dictionaryId,
|
|
66
|
+
dictionaryPath,
|
|
67
|
+
resultKeyPath,
|
|
68
|
+
locale
|
|
69
|
+
);
|
|
73
70
|
};
|
|
74
71
|
const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined";
|
|
75
72
|
const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = []) => {
|
|
@@ -126,7 +123,7 @@ const createReactElement = (element) => {
|
|
|
126
123
|
const { type, props } = fixedElement;
|
|
127
124
|
return (0, import_react.createElement)(type ?? "div", props, ...props.children);
|
|
128
125
|
};
|
|
129
|
-
const traceKeys = ["filePath", "
|
|
126
|
+
const traceKeys = ["filePath", "nodeType"];
|
|
130
127
|
const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [], locale = defaultLocale) => {
|
|
131
128
|
if (isReactNode(content)) {
|
|
132
129
|
return createReactElement(
|
|
@@ -134,40 +131,59 @@ const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [],
|
|
|
134
131
|
);
|
|
135
132
|
}
|
|
136
133
|
if (content && typeof content === "object") {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
result[key] = field;
|
|
142
|
-
continue;
|
|
143
|
-
}
|
|
144
|
-
const resultKeyPath = [
|
|
145
|
-
...keyPath,
|
|
146
|
-
{ type: "ObjectExpression", key }
|
|
147
|
-
];
|
|
148
|
-
result[key] = processNode(
|
|
149
|
-
field,
|
|
150
|
-
locale,
|
|
151
|
-
dictionaryId,
|
|
152
|
-
dictionaryPath,
|
|
153
|
-
resultKeyPath
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
|
-
if (typeof content === "string") {
|
|
159
|
-
try {
|
|
160
|
-
return (0, import_client2.renderContentEditor)(
|
|
134
|
+
const isArray = Array.isArray(content);
|
|
135
|
+
let result = {};
|
|
136
|
+
if (typeof content.nodeType !== "undefined") {
|
|
137
|
+
return processNode(
|
|
161
138
|
content,
|
|
139
|
+
locale,
|
|
162
140
|
dictionaryId,
|
|
163
141
|
dictionaryPath,
|
|
164
142
|
keyPath
|
|
165
143
|
);
|
|
166
|
-
}
|
|
167
|
-
|
|
144
|
+
} else if (isArray) {
|
|
145
|
+
result = content.map((field, key) => {
|
|
146
|
+
const resultKeyPath = [
|
|
147
|
+
...keyPath,
|
|
148
|
+
{ type: "ArrayExpression", key }
|
|
149
|
+
];
|
|
150
|
+
return processNode(
|
|
151
|
+
field,
|
|
152
|
+
locale,
|
|
153
|
+
dictionaryId,
|
|
154
|
+
dictionaryPath,
|
|
155
|
+
resultKeyPath
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
for (const key of Object.keys(content)) {
|
|
160
|
+
const field = content[key];
|
|
161
|
+
if (traceKeys.includes(key)) {
|
|
162
|
+
result[key] = field;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const resultKeyPath = [
|
|
166
|
+
...keyPath,
|
|
167
|
+
{ type: "ObjectExpression", key }
|
|
168
|
+
];
|
|
169
|
+
const nodeResult = processNode(
|
|
170
|
+
field,
|
|
171
|
+
locale,
|
|
172
|
+
dictionaryId,
|
|
173
|
+
dictionaryPath,
|
|
174
|
+
resultKeyPath
|
|
175
|
+
);
|
|
176
|
+
result[key] = nodeResult;
|
|
177
|
+
}
|
|
168
178
|
}
|
|
179
|
+
return result;
|
|
169
180
|
}
|
|
170
|
-
return
|
|
181
|
+
return {
|
|
182
|
+
content,
|
|
183
|
+
keyPath,
|
|
184
|
+
dictionaryId,
|
|
185
|
+
dictionaryPath
|
|
186
|
+
};
|
|
171
187
|
};
|
|
172
188
|
// Annotate the CommonJS export names for ESM import in node:
|
|
173
189
|
0 && (module.exports = {
|
|
@@ -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
|
|
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":"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","names":["element"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Locales } from '@intlayer/config/client';
|
|
2
|
-
import { KeyPath } from '@intlayer/core';
|
|
3
|
-
import {
|
|
2
|
+
import { DictionaryValue, KeyPath, Dictionary } from '@intlayer/core';
|
|
3
|
+
import { TransformedContentValue, TransformedContent } from './contentDictionary.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
6
|
-
declare const processNode: (field:
|
|
6
|
+
declare const processNode: (field: DictionaryValue | undefined, locale: Locales, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[]) => TransformedContentValue;
|
|
7
7
|
/**
|
|
8
8
|
* Function that process a dictionary and return the result to be used in the application.
|
|
9
9
|
*/
|
|
10
|
-
declare const processDictionary: (content:
|
|
10
|
+
declare const processDictionary: (content: Dictionary | DictionaryValue, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[], locale?: Locales) => TransformedContent;
|
|
11
11
|
|
|
12
12
|
export { processDictionary, processNode };
|
|
@@ -27,14 +27,13 @@ module.exports = __toCommonJS(IntlayerServerProvider_exports);
|
|
|
27
27
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
28
|
var import_client = require("@intlayer/config/client");
|
|
29
29
|
var import_serverContext = require('./serverContext.cjs');
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
);
|
|
30
|
+
const { defaultLocale } = (0, import_client.getConfiguration)().internationalization;
|
|
31
|
+
const IntlayerServerContext = (0, import_serverContext.createServerContext)(defaultLocale);
|
|
33
32
|
const useIntlayer = () => (0, import_serverContext.getServerContext)(IntlayerServerContext);
|
|
34
33
|
const locale = (0, import_serverContext.getServerContext)(IntlayerServerContext);
|
|
35
34
|
const IntlayerServerProvider = ({
|
|
36
35
|
children,
|
|
37
|
-
locale: locale2
|
|
36
|
+
locale: locale2 = defaultLocale
|
|
38
37
|
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerServerContext.Provider, { value: locale2, children });
|
|
39
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
39
|
0 && (module.exports = {
|