react-intlayer 3.5.2 → 3.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/cjs/client/useDictionary.cjs +3 -3
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +3 -3
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +37 -2
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs.map +1 -1
- package/dist/cjs/{useDictionaryBase.cjs → getDictionary.cjs} +19 -18
- package/dist/cjs/getDictionary.cjs.map +1 -0
- package/dist/cjs/{useIntlayerBase.cjs → getIntlayer.cjs} +13 -11
- package/dist/cjs/getIntlayer.cjs.map +1 -0
- package/dist/cjs/index.cjs +6 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +3 -3
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +3 -3
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +3 -3
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +4 -4
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +38 -3
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/editor/renderContentEditor.mjs +1 -1
- package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
- package/dist/esm/{useDictionaryBase.mjs → getDictionary.mjs} +16 -13
- package/dist/esm/getDictionary.mjs.map +1 -0
- package/dist/esm/{useIntlayerBase.mjs → getIntlayer.mjs} +9 -7
- package/dist/esm/getIntlayer.mjs.map +1 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +3 -3
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +4 -4
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/types/client/useDictionary.d.ts +1 -1
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +2 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +11 -6
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/editor/renderContentEditor.d.ts +3 -3
- package/dist/types/editor/renderContentEditor.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +35 -0
- package/dist/types/getDictionary.d.ts.map +1 -0
- package/dist/types/{useIntlayerBase.d.ts → getIntlayer.d.ts} +6 -9
- package/dist/types/getIntlayer.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/server/useDictionary.d.ts +1 -1
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useIntlayer.d.ts +2 -2
- package/dist/types/server/useIntlayer.d.ts.map +1 -1
- package/package.json +14 -14
- package/dist/cjs/useDictionaryBase.cjs.map +0 -1
- package/dist/cjs/useIntlayerBase.cjs.map +0 -1
- package/dist/esm/useDictionaryBase.mjs.map +0 -1
- package/dist/esm/useIntlayerBase.mjs.map +0 -1
- package/dist/types/useDictionaryBase.d.ts +0 -37
- package/dist/types/useDictionaryBase.d.ts.map +0 -1
- package/dist/types/useIntlayerBase.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
```tsx
|
|
37
37
|
// ./Component1/index.content.ts
|
|
38
38
|
|
|
39
|
-
import { DeclarationContent, t } from "intlayer";
|
|
39
|
+
import { type DeclarationContent, t } from "intlayer";
|
|
40
40
|
|
|
41
41
|
const component1Content = {
|
|
42
42
|
key: "component1",
|
|
@@ -115,7 +115,7 @@ const config: IntlayerConfig = {
|
|
|
115
115
|
export default config;
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
To see all available parameters, refer to the [configuration documentation here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/
|
|
118
|
+
To see all available parameters, refer to the [configuration documentation here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/configuration.md).
|
|
119
119
|
|
|
120
120
|
## Step 3: Integrate Intlayer in Your CRA Configuration
|
|
121
121
|
|
|
@@ -174,7 +174,7 @@ const appContent = {
|
|
|
174
174
|
export default appContent;
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
[See how to declare your Intlayer declaration files](https://github.com/aymericzip/intlayer/blob/main/docs/docs/content_declaration/
|
|
177
|
+
[See how to declare your Intlayer declaration files](https://github.com/aymericzip/intlayer/blob/main/docs/docs/content_declaration/get_started.md
|
|
178
178
|
|
|
179
179
|
## Step 5: Utilize Intlayer in Your Code
|
|
180
180
|
|
|
@@ -272,4 +272,4 @@ Ensure your TypeScript configuration includes the autogenerated types.
|
|
|
272
272
|
|
|
273
273
|
# Getting Started with Intlayer and Vite + React
|
|
274
274
|
|
|
275
|
-
For integration with Vite + React, refer to the [setup guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/
|
|
275
|
+
For integration with Vite + React, refer to the [setup guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/intlayer_with_vite_react.md
|
|
@@ -23,12 +23,12 @@ __export(useDictionary_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(useDictionary_exports);
|
|
25
25
|
var import_react = require("react");
|
|
26
|
-
var
|
|
26
|
+
var import_getDictionary = require('../getDictionary.cjs');
|
|
27
27
|
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
28
|
-
const useDictionary = (dictionary, locale) => {
|
|
28
|
+
const useDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
29
29
|
const { locale: currentLocale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
30
30
|
const localeTarget = locale ?? currentLocale;
|
|
31
|
-
return (0,
|
|
31
|
+
return (0, import_getDictionary.getDictionary)(dictionary, localeTarget, isRenderEditor);
|
|
32
32
|
};
|
|
33
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
34
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getDictionary, type UseDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary: UseDictionary = <T extends DeclarationContent>(\n dictionary: T,\n locale?: Locales,\n isRenderEditor = false\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary(dictionary, localeTarget, isRenderEditor);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAA2B;AAC3B,2BAAkD;AAClD,8BAAsC;AAO/B,MAAM,gBAA+B,CAC1C,YACA,QACA,iBAAiB,UACd;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,aAAO,oCAAc,YAAY,cAAc,cAAc;AAC/D;","names":[]}
|
|
@@ -23,12 +23,12 @@ __export(useIntlayer_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(useIntlayer_exports);
|
|
25
25
|
var import_react = require("react");
|
|
26
|
-
var
|
|
26
|
+
var import_getIntlayer = require('../getIntlayer.cjs');
|
|
27
27
|
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
28
|
-
const useIntlayer = (key, locale) => {
|
|
28
|
+
const useIntlayer = (key, locale, isRenderEditor = true) => {
|
|
29
29
|
const { locale: currentLocale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
30
30
|
const localeTarget = locale ?? currentLocale;
|
|
31
|
-
return (0,
|
|
31
|
+
return (0, import_getIntlayer.getIntlayer)(key, localeTarget, isRenderEditor);
|
|
32
32
|
};
|
|
33
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
34
|
0 && (module.exports = {
|
|
@@ -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
|
|
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 getIntlayer,\n type UseIntlayerEditable,\n} from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key 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: UseIntlayerEditable = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getIntlayer(key, localeTarget, isRenderEditor);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA2B;AAC3B,yBAIO;AACP,8BAAsC;AAO/B,MAAM,cAAmC,CAC9C,KACA,QACA,iBAAiB,SACd;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,aAAO,gCAAY,KAAK,cAAc,cAAc;AACtD;","names":[]}
|
|
@@ -26,9 +26,44 @@ var import_client = require("@intlayer/config/client");
|
|
|
26
26
|
var import_core = require("@intlayer/core");
|
|
27
27
|
var import_react = require("react");
|
|
28
28
|
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
29
|
-
|
|
29
|
+
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
30
|
+
const useLocale = ({ onLocaleChange } = {}) => {
|
|
31
|
+
const {
|
|
32
|
+
/**
|
|
33
|
+
* Prefix default prefix the default locale to the path as other locales.
|
|
34
|
+
*
|
|
35
|
+
* Example with prefixDefault = true and defaultLocale = 'en':
|
|
36
|
+
* path = /en/dashboard or /fr/dashboard
|
|
37
|
+
*
|
|
38
|
+
* Example with prefixDefault = false and defaultLocale = 'en':
|
|
39
|
+
* path = /dashboard or /fr/dashboard
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
prefixDefault
|
|
43
|
+
} = (0, import_client.getConfiguration)().middleware;
|
|
30
44
|
const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
|
|
31
|
-
const { locale, setLocale } = (0, import_react.useContext)(
|
|
45
|
+
const { locale, setLocale: setLocaleState } = (0, import_react.useContext)(
|
|
46
|
+
import_IntlayerProvider.IntlayerClientContext
|
|
47
|
+
);
|
|
48
|
+
const { setLocaleCookie } = (0, import_useLocaleCookie.useLocaleCookie)();
|
|
49
|
+
const setLocale = (0, import_react.useCallback)(
|
|
50
|
+
(locale2) => {
|
|
51
|
+
if (!availableLocales.includes(locale2)) {
|
|
52
|
+
console.error(`Locale ${locale2} is not available`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
setLocaleState(locale2);
|
|
56
|
+
setLocaleCookie(locale2);
|
|
57
|
+
onLocaleChange?.(locale2);
|
|
58
|
+
},
|
|
59
|
+
[
|
|
60
|
+
onLocaleChange,
|
|
61
|
+
availableLocales,
|
|
62
|
+
setLocaleState,
|
|
63
|
+
prefixDefault,
|
|
64
|
+
defaultLocale
|
|
65
|
+
]
|
|
66
|
+
);
|
|
32
67
|
return {
|
|
33
68
|
locale,
|
|
34
69
|
// 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 './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;
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type Locales } from '@intlayer/config';\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useLocaleCookie } from './useLocaleCookie';\n\ntype useLocaleProps = {\n onLocaleChange?: (locale: Locales) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({ onLocaleChange }: useLocaleProps = {}) => {\n const {\n /**\n * Prefix default prefix the default locale to the path as other locales.\n *\n * Example with prefixDefault = true and defaultLocale = 'en':\n * path = /en/dashboard or /fr/dashboard\n *\n * Example with prefixDefault = false and defaultLocale = 'en':\n * path = /dashboard or /fr/dashboard\n *\n */\n prefixDefault,\n } = getConfiguration().middleware;\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale: setLocaleState } = useContext(\n IntlayerClientContext\n );\n const { setLocaleCookie } = useLocaleCookie();\n\n const setLocale = useCallback(\n (locale: Locales) => {\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleCookie(locale);\n onLocaleChange?.(locale);\n },\n [\n onLocaleChange,\n availableLocales,\n setLocaleState,\n prefixDefault,\n defaultLocale,\n ]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAiC;AACjC,kBAA2B;AAC3B,mBAAwC;AACxC,8BAAsC;AACtC,6BAAgC;AASzB,MAAM,YAAY,CAAC,EAAE,eAAe,IAAoB,CAAC,MAAM;AACpE,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWJ;AAAA,EACF,QAAI,gCAAiB,EAAE;AACvB,QAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,WAAW,eAAe,QAAI;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,EAAE,gBAAgB,QAAI,wCAAgB;AAE5C,QAAM,gBAAY;AAAA,IAChB,CAACA,YAAoB;AACnB,UAAI,CAAC,iBAAiB,SAASA,OAAM,GAAG;AACtC,gBAAQ,MAAM,UAAUA,OAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,qBAAeA,OAAM;AACrB,sBAAgBA,OAAM;AACtB,uBAAiBA,OAAM;AAAA,IACzB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":["locale"]}
|
|
@@ -37,7 +37,7 @@ const IntlayerEditorElement = ({
|
|
|
37
37
|
}
|
|
38
38
|
return content;
|
|
39
39
|
};
|
|
40
|
-
const renderIntlayerEditor = (data, isContentSelectable) => {
|
|
40
|
+
const renderIntlayerEditor = (data, isContentSelectable = true) => {
|
|
41
41
|
const Result = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
42
42
|
IntlayerEditorElement,
|
|
43
43
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport type { KeyPath } from '@intlayer/core';\nimport type { FC, ReactNode } from 'react';\nimport { ContentSelectorConnector } from './ContentSelectorConnector';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport type IntlayerEditorElementProps = {\n content: string;\n dictionaryId: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n isContentSelectable: boolean;\n};\n\nconst IntlayerEditorElement: FC<IntlayerEditorElementProps> = ({\n content,\n isContentSelectable,\n ...props\n}) => {\n if (enabled && isContentSelectable) {\n return (\n <ContentSelectorConnector {...props}>{content}</ContentSelectorConnector>\n );\n }\n return content;\n};\n\nexport type
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport type { KeyPath } from '@intlayer/core';\nimport type { FC, ReactNode } from 'react';\nimport { ContentSelectorConnector } from './ContentSelectorConnector';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport type IntlayerEditorElementProps = {\n content: string;\n dictionaryId: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n isContentSelectable: boolean;\n};\n\nconst IntlayerEditorElement: FC<IntlayerEditorElementProps> = ({\n content,\n isContentSelectable,\n ...props\n}) => {\n if (enabled && isContentSelectable) {\n return (\n <ContentSelectorConnector {...props}>{content}</ContentSelectorConnector>\n );\n }\n return content;\n};\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\nexport const renderIntlayerEditor = (\n data: IntlayerEditorElementProps,\n isContentSelectable = true\n): IntlayerNode => {\n const Result = (\n <IntlayerEditorElement\n {...data}\n isContentSelectable={isContentSelectable}\n />\n );\n\n return { ...Result, value: data.content };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBM;AAxBN,oBAAiC;AAGjC,sCAAyC;AAEzC,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,QAAI,gCAAiB;AAUrB,MAAM,wBAAwD,CAAC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,MAAI,WAAW,qBAAqB;AAClC,WACE,4CAAC,4DAA0B,GAAG,OAAQ,mBAAQ;AAAA,EAElD;AACA,SAAO;AACT;AAMO,MAAM,uBAAuB,CAClC,MACA,sBAAsB,SACL;AACjB,QAAM,SACJ;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA;AAAA,EACF;AAGF,SAAO,EAAE,GAAG,QAAQ,OAAO,KAAK,QAAQ;AAC1C;","names":[]}
|
|
@@ -16,39 +16,40 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
var getDictionary_exports = {};
|
|
20
|
+
__export(getDictionary_exports, {
|
|
21
|
+
getDictionary: () => getDictionary,
|
|
22
|
+
recursiveTransformContent: () => recursiveTransformContent
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
24
|
+
module.exports = __toCommonJS(getDictionary_exports);
|
|
25
25
|
var import_react = require("react");
|
|
26
|
-
var import_processDictionary = require('./processDictionary/index.cjs');
|
|
27
26
|
var import_renderContentEditor = require('./editor/renderContentEditor.cjs');
|
|
28
|
-
|
|
27
|
+
var import_processDictionary = require('./processDictionary/index.cjs');
|
|
28
|
+
const recursiveTransformContent = (value, isRenderEditor = false) => {
|
|
29
29
|
if (typeof value === "function") {
|
|
30
|
-
return (props) => recursiveTransformContent(value(props),
|
|
30
|
+
return (props) => recursiveTransformContent(value(props), isRenderEditor);
|
|
31
31
|
} else if (typeof value === "object") {
|
|
32
32
|
if (typeof value.dictionaryId !== "undefined") {
|
|
33
|
-
|
|
33
|
+
if (isRenderEditor) {
|
|
34
|
+
return (0, import_renderContentEditor.renderIntlayerEditor)(value);
|
|
35
|
+
}
|
|
36
|
+
return value.content;
|
|
34
37
|
} else if (Array.isArray(value)) {
|
|
35
|
-
return value.map(
|
|
36
|
-
(el) => recursiveTransformContent(el, isContentSelectable)
|
|
37
|
-
);
|
|
38
|
+
return value.map((el) => recursiveTransformContent(el, isRenderEditor));
|
|
38
39
|
} else if ((0, import_react.isValidElement)(value)) {
|
|
39
40
|
return value;
|
|
40
41
|
}
|
|
41
42
|
return Object.entries(value).reduce(
|
|
42
43
|
(acc, [key, value2]) => ({
|
|
43
44
|
...acc,
|
|
44
|
-
[key]: recursiveTransformContent(value2,
|
|
45
|
+
[key]: recursiveTransformContent(value2, isRenderEditor)
|
|
45
46
|
}),
|
|
46
47
|
{}
|
|
47
48
|
);
|
|
48
49
|
}
|
|
49
50
|
return value;
|
|
50
51
|
};
|
|
51
|
-
const
|
|
52
|
+
const getDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
52
53
|
const result = (0, import_processDictionary.processDictionary)(
|
|
53
54
|
dictionary.content,
|
|
54
55
|
dictionary.key,
|
|
@@ -58,12 +59,12 @@ const useDictionaryBase = (dictionary, locale, isContentSelectable = false) => {
|
|
|
58
59
|
);
|
|
59
60
|
return recursiveTransformContent(
|
|
60
61
|
result,
|
|
61
|
-
|
|
62
|
+
isRenderEditor
|
|
62
63
|
);
|
|
63
64
|
};
|
|
64
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
65
66
|
0 && (module.exports = {
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
getDictionary,
|
|
68
|
+
recursiveTransformContent
|
|
68
69
|
});
|
|
69
|
-
//# sourceMappingURL=
|
|
70
|
+
//# sourceMappingURL=getDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Locales } from '@intlayer/config';\nimport type {\n DeclarationContent,\n DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement, type ReactNode } from 'react';\nimport {\n type IntlayerNode,\n renderIntlayerEditor,\n} from './editor/renderContentEditor';\nimport { processDictionary } from './processDictionary/index';\n\ntype TransformNodeType<T, L extends Locales, R extends boolean> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (\n quantity: number\n ) => DeepTransformContent<T[NodeType.Enumeration]['1'], L, R>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L, R>\n : never\n : T;\n\nexport type DeepTransformContent<\n T,\n L extends Locales,\n R extends boolean,\n> = T extends object // Check if the property is an object\n ? T extends (infer U)[] // If it's an array, infer the type of array elements\n ? DeepTransformContent<U, L, R>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L, R>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L, R>;\n }\n : T extends undefined\n ? never\n : R extends true\n ? IntlayerNode<T>\n : T;\n\n/**\n * Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.\n */\nexport const recursiveTransformContent = (\n value: any,\n isRenderEditor = false\n): object => {\n if (typeof value === 'function') {\n return (props: any) =>\n recursiveTransformContent(value(props), isRenderEditor);\n } else if (typeof value === 'object') {\n if (typeof value.dictionaryId !== 'undefined') {\n if (isRenderEditor) {\n return renderIntlayerEditor(value);\n }\n return value.content;\n } else if (Array.isArray(value)) {\n return value.map((el) => recursiveTransformContent(el, isRenderEditor));\n } else if (isValidElement(value)) {\n return value;\n }\n\n return Object.entries(value).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: recursiveTransformContent(value, isRenderEditor),\n }),\n {} as object\n );\n }\n\n return value;\n};\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<T['content'], K, R>;\n\nexport type UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionary<T, L, R>;\n\n/**\n * Hook that picks one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getDictionary: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const result = processDictionary(\n dictionary.content as DictionaryValue,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionary<T, L, R>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,mBAA+C;AAC/C,iCAGO;AACP,+BAAkC;AAyC3B,MAAM,4BAA4B,CACvC,OACA,iBAAiB,UACN;AACX,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,CAAC,UACN,0BAA0B,MAAM,KAAK,GAAG,cAAc;AAAA,EAC1D,WAAW,OAAO,UAAU,UAAU;AACpC,QAAI,OAAO,MAAM,iBAAiB,aAAa;AAC7C,UAAI,gBAAgB;AAClB,mBAAO,iDAAqB,KAAK;AAAA,MACnC;AACA,aAAO,MAAM;AAAA,IACf,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,aAAO,MAAM,IAAI,CAAC,OAAO,0BAA0B,IAAI,cAAc,CAAC;AAAA,IACxE,eAAW,6BAAe,KAAK,GAAG;AAChC,aAAO;AAAA,IACT;AAEA,WAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,MAC3B,CAAC,KAAK,CAAC,KAAKA,MAAK,OAAO;AAAA,QACtB,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,0BAA0BA,QAAO,cAAc;AAAA,MACxD;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAuBO,MAAM,gBAA+B,CAK1C,YACA,QACA,iBAAoB,UACjB;AACH,QAAM,aAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["value"]}
|
|
@@ -26,16 +26,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
29
|
+
var getIntlayer_exports = {};
|
|
30
|
+
__export(getIntlayer_exports, {
|
|
31
|
+
getIntlayer: () => getIntlayer
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(getIntlayer_exports);
|
|
34
34
|
var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
|
|
35
|
+
var import_getDictionary = require('./getDictionary.cjs');
|
|
35
36
|
var import_processDictionary = require('./processDictionary/index.cjs');
|
|
36
|
-
|
|
37
|
-
const useIntlayerBase = (key, locale) => {
|
|
37
|
+
const getIntlayer = (key, locale, isRenderEditor = false) => {
|
|
38
38
|
const dictionary = import_dictionaries_entry.default[key];
|
|
39
|
+
if (!dictionary) {
|
|
40
|
+
throw new Error(`Dictionary ${key} not found`, import_dictionaries_entry.default);
|
|
41
|
+
}
|
|
39
42
|
const result = (0, import_processDictionary.processDictionary)(
|
|
40
43
|
dictionary.content,
|
|
41
44
|
dictionary.key,
|
|
@@ -43,14 +46,13 @@ const useIntlayerBase = (key, locale) => {
|
|
|
43
46
|
[],
|
|
44
47
|
locale
|
|
45
48
|
);
|
|
46
|
-
|
|
47
|
-
return (0, import_useDictionaryBase.recursiveTransformContent)(
|
|
49
|
+
return (0, import_getDictionary.recursiveTransformContent)(
|
|
48
50
|
result,
|
|
49
|
-
|
|
51
|
+
isRenderEditor
|
|
50
52
|
);
|
|
51
53
|
};
|
|
52
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
55
|
0 && (module.exports = {
|
|
54
|
-
|
|
56
|
+
getIntlayer
|
|
55
57
|
});
|
|
56
|
-
//# sourceMappingURL=
|
|
58
|
+
//# sourceMappingURL=getIntlayer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './getDictionary';\nimport { processDictionary } from './processDictionary/index';\n\n/**\n * Provides a fallback to string type if the generic type T is never,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\ntype DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K, R>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R>;\n\nexport type UseIntlayerEditable = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R>;\n\nexport const getIntlayer: UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const dictionary: Dictionary = dictionaries[key as keyof typeof dictionaries];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key} not found`, dictionaries);\n }\n\n const result = processDictionary(\n dictionary.content,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,gCAAyB;AAEzB,2BAGO;AACP,+BAAkC;AA2D3B,MAAM,cAA2B,CAKtC,KACA,QACA,iBAAoB,UACjB;AACH,QAAM,aAAyB,0BAAAA,QAAa,GAAgC;AAE5E,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,cAAc,GAAG,cAAc,0BAAAA,OAAY;AAAA,EAC7D;AAEA,QAAM,aAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,aAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["dictionaries"]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -21,6 +21,8 @@ __export(src_exports, {
|
|
|
21
21
|
IntlayerClientContext: () => import_client.IntlayerClientContext,
|
|
22
22
|
IntlayerProvider: () => import_client.IntlayerProvider,
|
|
23
23
|
getBrowserLocale: () => import_client.getBrowserLocale,
|
|
24
|
+
getDictionary: () => import_getDictionary.getDictionary,
|
|
25
|
+
getIntlayer: () => import_getIntlayer.getIntlayer,
|
|
24
26
|
getTranslation: () => import_getTranslation.getTranslation,
|
|
25
27
|
localeCookie: () => import_client.localeCookie,
|
|
26
28
|
setLocaleCookie: () => import_client.setLocaleCookie,
|
|
@@ -36,11 +38,15 @@ __export(src_exports, {
|
|
|
36
38
|
module.exports = __toCommonJS(src_exports);
|
|
37
39
|
var import_getTranslation = require('./getTranslation.cjs');
|
|
38
40
|
var import_client = require('./client/index.cjs');
|
|
41
|
+
var import_getDictionary = require('./getDictionary.cjs');
|
|
42
|
+
var import_getIntlayer = require('./getIntlayer.cjs');
|
|
39
43
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
44
|
0 && (module.exports = {
|
|
41
45
|
IntlayerClientContext,
|
|
42
46
|
IntlayerProvider,
|
|
43
47
|
getBrowserLocale,
|
|
48
|
+
getDictionary,
|
|
49
|
+
getIntlayer,
|
|
44
50
|
getTranslation,
|
|
45
51
|
localeCookie,
|
|
46
52
|
setLocaleCookie,
|
package/dist/cjs/index.cjs.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 useDictionary,\n useLocale,\n useTraduction,\n useLocaleCookie,\n useIntlayerContext,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n t,\n} from './client/index';\nexport { type IntlayerNode } from './
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerProvider,\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayer,\n useDictionary,\n useLocale,\n useTraduction,\n useLocaleCookie,\n useIntlayerContext,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n t,\n} from './client/index';\nexport { getDictionary } from './getDictionary';\nexport { getIntlayer } from './getIntlayer';\nexport { type IntlayerNode } from './editor/renderContentEditor';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAC/B,oBAeO;AACP,2BAA8B;AAC9B,yBAA4B;","names":[]}
|
|
@@ -21,12 +21,12 @@ __export(useDictionary_exports, {
|
|
|
21
21
|
useDictionary: () => useDictionary
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(useDictionary_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_getDictionary = require('../getDictionary.cjs');
|
|
25
25
|
var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
26
26
|
var import_serverContext = require('./serverContext.cjs');
|
|
27
|
-
const useDictionary = (dictionary, locale) => {
|
|
27
|
+
const useDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
28
28
|
const localeTarget = locale ?? (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
|
|
29
|
-
return (0,
|
|
29
|
+
return (0, import_getDictionary.getDictionary)(dictionary, localeTarget, isRenderEditor);
|
|
30
30
|
};
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { getDictionary, type UseDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary: UseDictionary = <T extends DeclarationContent>(\n dictionary: T,\n locale?: Locales,\n isRenderEditor = false\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return getDictionary(dictionary, localeTarget, isRenderEditor);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,2BAAkD;AAClD,oCAAsC;AACtC,2BAAiC;AAO1B,MAAM,gBAA+B,CAC1C,YACA,QACA,iBAAiB,UACd;AACH,QAAM,eACJ,cAAU,uCAA0B,mDAAqB;AAE3D,aAAO,oCAAc,YAAY,cAAc,cAAc;AAC/D;","names":[]}
|
|
@@ -21,12 +21,12 @@ __export(useIntlayer_exports, {
|
|
|
21
21
|
useIntlayer: () => useIntlayer
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(useIntlayer_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_getIntlayer = require('../getIntlayer.cjs');
|
|
25
25
|
var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
26
26
|
var import_serverContext = require('./serverContext.cjs');
|
|
27
|
-
const useIntlayer = (key, locale) => {
|
|
27
|
+
const useIntlayer = (key, locale, isRenderEditor = true) => {
|
|
28
28
|
const localeTarget = locale ?? (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
|
|
29
|
-
return (0,
|
|
29
|
+
return (0, import_getIntlayer.getIntlayer)(key, localeTarget, isRenderEditor);
|
|
30
30
|
};
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n getIntlayer,\n type UseIntlayerEditable,\n} from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer: UseIntlayerEditable = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return getIntlayer(key, localeTarget, isRenderEditor);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAIO;AACP,oCAAsC;AACtC,2BAAiC;AAO1B,MAAM,cAAmC,CAC9C,KACA,QACA,iBAAiB,SACd;AACH,QAAM,eACJ,cAAU,uCAA0B,mDAAqB;AAE3D,aAAO,gCAAY,KAAK,cAAc,cAAc;AACtD;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "../chunk-ZD7AOCMD.mjs";
|
|
3
3
|
import { useContext } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { getDictionary } from '../getDictionary.mjs';
|
|
5
5
|
import { IntlayerClientContext } from './IntlayerProvider.mjs';
|
|
6
|
-
const useDictionary = (dictionary, locale) => {
|
|
6
|
+
const useDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
7
7
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
8
8
|
const localeTarget = locale ?? currentLocale;
|
|
9
|
-
return
|
|
9
|
+
return getDictionary(dictionary, localeTarget, isRenderEditor);
|
|
10
10
|
};
|
|
11
11
|
export {
|
|
12
12
|
useDictionary
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getDictionary, type UseDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary: UseDictionary = <T extends DeclarationContent>(\n dictionary: T,\n locale?: Locales,\n isRenderEditor = false\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary(dictionary, localeTarget, isRenderEditor);\n};\n"],"mappings":";;AAIA,SAAS,kBAAkB;AAC3B,SAAS,qBAAyC;AAClD,SAAS,6BAA6B;AAO/B,MAAM,gBAA+B,CAC1C,YACA,QACA,iBAAiB,UACd;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,cAAc,YAAY,cAAc,cAAc;AAC/D;","names":[]}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
import "../chunk-ZD7AOCMD.mjs";
|
|
3
3
|
import { useContext } from "react";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
} from '../
|
|
5
|
+
getIntlayer
|
|
6
|
+
} from '../getIntlayer.mjs';
|
|
7
7
|
import { IntlayerClientContext } from './IntlayerProvider.mjs';
|
|
8
|
-
const useIntlayer = (key, locale) => {
|
|
8
|
+
const useIntlayer = (key, locale, isRenderEditor = true) => {
|
|
9
9
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
10
10
|
const localeTarget = locale ?? currentLocale;
|
|
11
|
-
return
|
|
11
|
+
return getIntlayer(key, localeTarget, isRenderEditor);
|
|
12
12
|
};
|
|
13
13
|
export {
|
|
14
14
|
useIntlayer
|
|
@@ -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
|
|
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 getIntlayer,\n type UseIntlayerEditable,\n} from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key 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: UseIntlayerEditable = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getIntlayer(key, localeTarget, isRenderEditor);\n};\n"],"mappings":";;AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAAmC,CAC9C,KACA,QACA,iBAAiB,SACd;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,YAAY,KAAK,cAAc,cAAc;AACtD;","names":[]}
|
|
@@ -2,11 +2,46 @@
|
|
|
2
2
|
import "../chunk-ZD7AOCMD.mjs";
|
|
3
3
|
import { getConfiguration } from "@intlayer/config/client";
|
|
4
4
|
import { localeList } from "@intlayer/core";
|
|
5
|
-
import { useContext } from "react";
|
|
5
|
+
import { useCallback, useContext } from "react";
|
|
6
6
|
import { IntlayerClientContext } from './IntlayerProvider.mjs';
|
|
7
|
-
|
|
7
|
+
import { useLocaleCookie } from './useLocaleCookie.mjs';
|
|
8
|
+
const useLocale = ({ onLocaleChange } = {}) => {
|
|
9
|
+
const {
|
|
10
|
+
/**
|
|
11
|
+
* Prefix default prefix the default locale to the path as other locales.
|
|
12
|
+
*
|
|
13
|
+
* Example with prefixDefault = true and defaultLocale = 'en':
|
|
14
|
+
* path = /en/dashboard or /fr/dashboard
|
|
15
|
+
*
|
|
16
|
+
* Example with prefixDefault = false and defaultLocale = 'en':
|
|
17
|
+
* path = /dashboard or /fr/dashboard
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
prefixDefault
|
|
21
|
+
} = getConfiguration().middleware;
|
|
8
22
|
const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
|
|
9
|
-
const { locale, setLocale } = useContext(
|
|
23
|
+
const { locale, setLocale: setLocaleState } = useContext(
|
|
24
|
+
IntlayerClientContext
|
|
25
|
+
);
|
|
26
|
+
const { setLocaleCookie } = useLocaleCookie();
|
|
27
|
+
const setLocale = useCallback(
|
|
28
|
+
(locale2) => {
|
|
29
|
+
if (!availableLocales.includes(locale2)) {
|
|
30
|
+
console.error(`Locale ${locale2} is not available`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
setLocaleState(locale2);
|
|
34
|
+
setLocaleCookie(locale2);
|
|
35
|
+
onLocaleChange?.(locale2);
|
|
36
|
+
},
|
|
37
|
+
[
|
|
38
|
+
onLocaleChange,
|
|
39
|
+
availableLocales,
|
|
40
|
+
setLocaleState,
|
|
41
|
+
prefixDefault,
|
|
42
|
+
defaultLocale
|
|
43
|
+
]
|
|
44
|
+
);
|
|
10
45
|
return {
|
|
11
46
|
locale,
|
|
12
47
|
// 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 './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":";;
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type Locales } from '@intlayer/config';\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useLocaleCookie } from './useLocaleCookie';\n\ntype useLocaleProps = {\n onLocaleChange?: (locale: Locales) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({ onLocaleChange }: useLocaleProps = {}) => {\n const {\n /**\n * Prefix default prefix the default locale to the path as other locales.\n *\n * Example with prefixDefault = true and defaultLocale = 'en':\n * path = /en/dashboard or /fr/dashboard\n *\n * Example with prefixDefault = false and defaultLocale = 'en':\n * path = /dashboard or /fr/dashboard\n *\n */\n prefixDefault,\n } = getConfiguration().middleware;\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale: setLocaleState } = useContext(\n IntlayerClientContext\n );\n const { setLocaleCookie } = useLocaleCookie();\n\n const setLocale = useCallback(\n (locale: Locales) => {\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleCookie(locale);\n onLocaleChange?.(locale);\n },\n [\n onLocaleChange,\n availableLocales,\n setLocaleState,\n prefixDefault,\n defaultLocale,\n ]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;AAGA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,aAAa,kBAAkB;AACxC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AASzB,MAAM,YAAY,CAAC,EAAE,eAAe,IAAoB,CAAC,MAAM;AACpE,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWJ;AAAA,EACF,IAAI,iBAAiB,EAAE;AACvB,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,WAAW,eAAe,IAAI;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,EAAE,gBAAgB,IAAI,gBAAgB;AAE5C,QAAM,YAAY;AAAA,IAChB,CAACA,YAAoB;AACnB,UAAI,CAAC,iBAAiB,SAASA,OAAM,GAAG;AACtC,gBAAQ,MAAM,UAAUA,OAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,qBAAeA,OAAM;AACrB,sBAAgBA,OAAM;AACtB,uBAAiBA,OAAM;AAAA,IACzB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":["locale"]}
|
|
@@ -15,7 +15,7 @@ const IntlayerEditorElement = ({
|
|
|
15
15
|
}
|
|
16
16
|
return content;
|
|
17
17
|
};
|
|
18
|
-
const renderIntlayerEditor = (data, isContentSelectable) => {
|
|
18
|
+
const renderIntlayerEditor = (data, isContentSelectable = true) => {
|
|
19
19
|
const Result = /* @__PURE__ */ jsx(
|
|
20
20
|
IntlayerEditorElement,
|
|
21
21
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport type { KeyPath } from '@intlayer/core';\nimport type { FC, ReactNode } from 'react';\nimport { ContentSelectorConnector } from './ContentSelectorConnector';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport type IntlayerEditorElementProps = {\n content: string;\n dictionaryId: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n isContentSelectable: boolean;\n};\n\nconst IntlayerEditorElement: FC<IntlayerEditorElementProps> = ({\n content,\n isContentSelectable,\n ...props\n}) => {\n if (enabled && isContentSelectable) {\n return (\n <ContentSelectorConnector {...props}>{content}</ContentSelectorConnector>\n );\n }\n return content;\n};\n\nexport type
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport type { KeyPath } from '@intlayer/core';\nimport type { FC, ReactNode } from 'react';\nimport { ContentSelectorConnector } from './ContentSelectorConnector';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport type IntlayerEditorElementProps = {\n content: string;\n dictionaryId: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n isContentSelectable: boolean;\n};\n\nconst IntlayerEditorElement: FC<IntlayerEditorElementProps> = ({\n content,\n isContentSelectable,\n ...props\n}) => {\n if (enabled && isContentSelectable) {\n return (\n <ContentSelectorConnector {...props}>{content}</ContentSelectorConnector>\n );\n }\n return content;\n};\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\nexport const renderIntlayerEditor = (\n data: IntlayerEditorElementProps,\n isContentSelectable = true\n): IntlayerNode => {\n const Result = (\n <IntlayerEditorElement\n {...data}\n isContentSelectable={isContentSelectable}\n />\n );\n\n return { ...Result, value: data.content };\n};\n"],"mappings":";AAwBM;AAxBN,SAAS,wBAAwB;AAGjC,SAAS,gCAAgC;AAEzC,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,IAAI,iBAAiB;AAUrB,MAAM,wBAAwD,CAAC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,MAAI,WAAW,qBAAqB;AAClC,WACE,oBAAC,4BAA0B,GAAG,OAAQ,mBAAQ;AAAA,EAElD;AACA,SAAO;AACT;AAMO,MAAM,uBAAuB,CAClC,MACA,sBAAsB,SACL;AACjB,QAAM,SACJ;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA;AAAA,EACF;AAGF,SAAO,EAAE,GAAG,QAAQ,OAAO,KAAK,QAAQ;AAC1C;","names":[]}
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
import "./chunk-ZD7AOCMD.mjs";
|
|
2
2
|
import { isValidElement } from "react";
|
|
3
|
+
import {
|
|
4
|
+
renderIntlayerEditor
|
|
5
|
+
} from './editor/renderContentEditor.mjs';
|
|
3
6
|
import { processDictionary } from './processDictionary/index.mjs';
|
|
4
|
-
|
|
5
|
-
const recursiveTransformContent = (value, isContentSelectable = false) => {
|
|
7
|
+
const recursiveTransformContent = (value, isRenderEditor = false) => {
|
|
6
8
|
if (typeof value === "function") {
|
|
7
|
-
return (props) => recursiveTransformContent(value(props),
|
|
9
|
+
return (props) => recursiveTransformContent(value(props), isRenderEditor);
|
|
8
10
|
} else if (typeof value === "object") {
|
|
9
11
|
if (typeof value.dictionaryId !== "undefined") {
|
|
10
|
-
|
|
12
|
+
if (isRenderEditor) {
|
|
13
|
+
return renderIntlayerEditor(value);
|
|
14
|
+
}
|
|
15
|
+
return value.content;
|
|
11
16
|
} else if (Array.isArray(value)) {
|
|
12
|
-
return value.map(
|
|
13
|
-
(el) => recursiveTransformContent(el, isContentSelectable)
|
|
14
|
-
);
|
|
17
|
+
return value.map((el) => recursiveTransformContent(el, isRenderEditor));
|
|
15
18
|
} else if (isValidElement(value)) {
|
|
16
19
|
return value;
|
|
17
20
|
}
|
|
18
21
|
return Object.entries(value).reduce(
|
|
19
22
|
(acc, [key, value2]) => ({
|
|
20
23
|
...acc,
|
|
21
|
-
[key]: recursiveTransformContent(value2,
|
|
24
|
+
[key]: recursiveTransformContent(value2, isRenderEditor)
|
|
22
25
|
}),
|
|
23
26
|
{}
|
|
24
27
|
);
|
|
25
28
|
}
|
|
26
29
|
return value;
|
|
27
30
|
};
|
|
28
|
-
const
|
|
31
|
+
const getDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
29
32
|
const result = processDictionary(
|
|
30
33
|
dictionary.content,
|
|
31
34
|
dictionary.key,
|
|
@@ -35,11 +38,11 @@ const useDictionaryBase = (dictionary, locale, isContentSelectable = false) => {
|
|
|
35
38
|
);
|
|
36
39
|
return recursiveTransformContent(
|
|
37
40
|
result,
|
|
38
|
-
|
|
41
|
+
isRenderEditor
|
|
39
42
|
);
|
|
40
43
|
};
|
|
41
44
|
export {
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
getDictionary,
|
|
46
|
+
recursiveTransformContent
|
|
44
47
|
};
|
|
45
|
-
//# sourceMappingURL=
|
|
48
|
+
//# sourceMappingURL=getDictionary.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Locales } from '@intlayer/config';\nimport type {\n DeclarationContent,\n DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement, type ReactNode } from 'react';\nimport {\n type IntlayerNode,\n renderIntlayerEditor,\n} from './editor/renderContentEditor';\nimport { processDictionary } from './processDictionary/index';\n\ntype TransformNodeType<T, L extends Locales, R extends boolean> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (\n quantity: number\n ) => DeepTransformContent<T[NodeType.Enumeration]['1'], L, R>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L, R>\n : never\n : T;\n\nexport type DeepTransformContent<\n T,\n L extends Locales,\n R extends boolean,\n> = T extends object // Check if the property is an object\n ? T extends (infer U)[] // If it's an array, infer the type of array elements\n ? DeepTransformContent<U, L, R>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L, R>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L, R>;\n }\n : T extends undefined\n ? never\n : R extends true\n ? IntlayerNode<T>\n : T;\n\n/**\n * Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.\n */\nexport const recursiveTransformContent = (\n value: any,\n isRenderEditor = false\n): object => {\n if (typeof value === 'function') {\n return (props: any) =>\n recursiveTransformContent(value(props), isRenderEditor);\n } else if (typeof value === 'object') {\n if (typeof value.dictionaryId !== 'undefined') {\n if (isRenderEditor) {\n return renderIntlayerEditor(value);\n }\n return value.content;\n } else if (Array.isArray(value)) {\n return value.map((el) => recursiveTransformContent(el, isRenderEditor));\n } else if (isValidElement(value)) {\n return value;\n }\n\n return Object.entries(value).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: recursiveTransformContent(value, isRenderEditor),\n }),\n {} as object\n );\n }\n\n return value;\n};\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<T['content'], K, R>;\n\nexport type UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionary<T, L, R>;\n\n/**\n * Hook that picks one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getDictionary: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const result = processDictionary(\n dictionary.content as DictionaryValue,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionary<T, L, R>;\n};\n"],"mappings":";AAOA,SAAS,sBAAsC;AAC/C;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AAyC3B,MAAM,4BAA4B,CACvC,OACA,iBAAiB,UACN;AACX,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,CAAC,UACN,0BAA0B,MAAM,KAAK,GAAG,cAAc;AAAA,EAC1D,WAAW,OAAO,UAAU,UAAU;AACpC,QAAI,OAAO,MAAM,iBAAiB,aAAa;AAC7C,UAAI,gBAAgB;AAClB,eAAO,qBAAqB,KAAK;AAAA,MACnC;AACA,aAAO,MAAM;AAAA,IACf,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,aAAO,MAAM,IAAI,CAAC,OAAO,0BAA0B,IAAI,cAAc,CAAC;AAAA,IACxE,WAAW,eAAe,KAAK,GAAG;AAChC,aAAO;AAAA,IACT;AAEA,WAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,MAC3B,CAAC,KAAK,CAAC,KAAKA,MAAK,OAAO;AAAA,QACtB,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,0BAA0BA,QAAO,cAAc;AAAA,MACxD;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAuBO,MAAM,gBAA+B,CAK1C,YACA,QACA,iBAAoB,UACjB;AACH,QAAM,SAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["value"]}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import "./chunk-ZD7AOCMD.mjs";
|
|
2
2
|
import dictionaries from "@intlayer/dictionaries-entry";
|
|
3
|
-
import { processDictionary } from './processDictionary/index.mjs';
|
|
4
3
|
import {
|
|
5
4
|
recursiveTransformContent
|
|
6
|
-
} from './
|
|
7
|
-
|
|
5
|
+
} from './getDictionary.mjs';
|
|
6
|
+
import { processDictionary } from './processDictionary/index.mjs';
|
|
7
|
+
const getIntlayer = (key, locale, isRenderEditor = false) => {
|
|
8
8
|
const dictionary = dictionaries[key];
|
|
9
|
+
if (!dictionary) {
|
|
10
|
+
throw new Error(`Dictionary ${key} not found`, dictionaries);
|
|
11
|
+
}
|
|
9
12
|
const result = processDictionary(
|
|
10
13
|
dictionary.content,
|
|
11
14
|
dictionary.key,
|
|
@@ -13,13 +16,12 @@ const useIntlayerBase = (key, locale) => {
|
|
|
13
16
|
[],
|
|
14
17
|
locale
|
|
15
18
|
);
|
|
16
|
-
const isContentSelectable = true;
|
|
17
19
|
return recursiveTransformContent(
|
|
18
20
|
result,
|
|
19
|
-
|
|
21
|
+
isRenderEditor
|
|
20
22
|
);
|
|
21
23
|
};
|
|
22
24
|
export {
|
|
23
|
-
|
|
25
|
+
getIntlayer
|
|
24
26
|
};
|
|
25
|
-
//# sourceMappingURL=
|
|
27
|
+
//# sourceMappingURL=getIntlayer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './getDictionary';\nimport { processDictionary } from './processDictionary/index';\n\n/**\n * Provides a fallback to string type if the generic type T is never,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\ntype DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K, R>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R>;\n\nexport type UseIntlayerEditable = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R>;\n\nexport const getIntlayer: UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const dictionary: Dictionary = dictionaries[key as keyof typeof dictionaries];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key} not found`, dictionaries);\n }\n\n const result = processDictionary(\n dictionary.content,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n};\n"],"mappings":";AAOA,OAAO,kBAAkB;AAEzB;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AA2D3B,MAAM,cAA2B,CAKtC,KACA,QACA,iBAAoB,UACjB;AACH,QAAM,aAAyB,aAAa,GAAgC;AAE5E,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,cAAc,GAAG,cAAc,YAAY;AAAA,EAC7D;AAEA,QAAM,SAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -15,10 +15,14 @@ import {
|
|
|
15
15
|
useLocaleBase,
|
|
16
16
|
t
|
|
17
17
|
} from './client/index.mjs';
|
|
18
|
+
import { getDictionary } from './getDictionary.mjs';
|
|
19
|
+
import { getIntlayer } from './getIntlayer.mjs';
|
|
18
20
|
export {
|
|
19
21
|
IntlayerClientContext,
|
|
20
22
|
IntlayerProvider,
|
|
21
23
|
getBrowserLocale,
|
|
24
|
+
getDictionary,
|
|
25
|
+
getIntlayer,
|
|
22
26
|
getTranslation,
|
|
23
27
|
localeCookie,
|
|
24
28
|
setLocaleCookie,
|
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 useDictionary,\n useLocale,\n useTraduction,\n useLocaleCookie,\n useIntlayerContext,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n t,\n} from './client/index';\nexport { type IntlayerNode } from './
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerProvider,\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayer,\n useDictionary,\n useLocale,\n useTraduction,\n useLocaleCookie,\n useIntlayerContext,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n t,\n} from './client/index';\nexport { getDictionary } from './getDictionary';\nexport { getIntlayer } from './getIntlayer';\nexport { type IntlayerNode } from './editor/renderContentEditor';\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,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "../chunk-ZD7AOCMD.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { getDictionary } from '../getDictionary.mjs';
|
|
3
3
|
import { IntlayerServerContext } from './IntlayerServerProvider.mjs';
|
|
4
4
|
import { getServerContext } from './serverContext.mjs';
|
|
5
|
-
const useDictionary = (dictionary, locale) => {
|
|
5
|
+
const useDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
6
6
|
const localeTarget = locale ?? getServerContext(IntlayerServerContext);
|
|
7
|
-
return
|
|
7
|
+
return getDictionary(dictionary, localeTarget, isRenderEditor);
|
|
8
8
|
};
|
|
9
9
|
export {
|
|
10
10
|
useDictionary
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { getDictionary, type UseDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary: UseDictionary = <T extends DeclarationContent>(\n dictionary: T,\n locale?: Locales,\n isRenderEditor = false\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return getDictionary(dictionary, localeTarget, isRenderEditor);\n};\n"],"mappings":";AAEA,SAAS,qBAAyC;AAClD,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAO1B,MAAM,gBAA+B,CAC1C,YACA,QACA,iBAAiB,UACd;AACH,QAAM,eACJ,UAAU,iBAA0B,qBAAqB;AAE3D,SAAO,cAAc,YAAY,cAAc,cAAc;AAC/D;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import "../chunk-ZD7AOCMD.mjs";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from '../
|
|
3
|
+
getIntlayer
|
|
4
|
+
} from '../getIntlayer.mjs';
|
|
5
5
|
import { IntlayerServerContext } from './IntlayerServerProvider.mjs';
|
|
6
6
|
import { getServerContext } from './serverContext.mjs';
|
|
7
|
-
const useIntlayer = (key, locale) => {
|
|
7
|
+
const useIntlayer = (key, locale, isRenderEditor = true) => {
|
|
8
8
|
const localeTarget = locale ?? getServerContext(IntlayerServerContext);
|
|
9
|
-
return
|
|
9
|
+
return getIntlayer(key, localeTarget, isRenderEditor);
|
|
10
10
|
};
|
|
11
11
|
export {
|
|
12
12
|
useIntlayer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n getIntlayer,\n type UseIntlayerEditable,\n} from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer: UseIntlayerEditable = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return getIntlayer(key, localeTarget, isRenderEditor);\n};\n"],"mappings":";AACA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAO1B,MAAM,cAAmC,CAC9C,KACA,QACA,iBAAiB,SACd;AACH,QAAM,eACJ,UAAU,iBAA0B,qBAAqB;AAE3D,SAAO,YAAY,KAAK,cAAc,cAAc;AACtD;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/client/useDictionary.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/client/useDictionary.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGrE;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,aAS3B,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type UseIntlayerEditable } from '../getIntlayer';
|
|
2
2
|
/**
|
|
3
3
|
* On the client side, Hook that picking one dictionary by its key and return the content
|
|
4
4
|
*
|
|
5
5
|
* If the locale is not provided, it will use the locale from the client context
|
|
6
6
|
*/
|
|
7
|
-
export declare const useIntlayer:
|
|
7
|
+
export declare const useIntlayer: UseIntlayerEditable;
|
|
8
8
|
//# sourceMappingURL=useIntlayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/client/useIntlayer.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,
|
|
1
|
+
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/client/useIntlayer.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,gBAAgB,CAAC;AAGxB;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,mBASzB,CAAC"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { type Locales } from '@intlayer/config';
|
|
2
|
+
type useLocaleProps = {
|
|
3
|
+
onLocaleChange?: (locale: Locales) => void;
|
|
4
|
+
};
|
|
1
5
|
/**
|
|
2
6
|
* On the client side, hook to get the current locale and all related fields
|
|
3
7
|
*/
|
|
4
|
-
export declare const useLocale: () => {
|
|
5
|
-
locale:
|
|
6
|
-
defaultLocale:
|
|
7
|
-
availableLocales:
|
|
8
|
-
localeList:
|
|
9
|
-
setLocale: (
|
|
8
|
+
export declare const useLocale: ({ onLocaleChange }?: useLocaleProps) => {
|
|
9
|
+
locale: Locales;
|
|
10
|
+
defaultLocale: Locales;
|
|
11
|
+
availableLocales: Locales[];
|
|
12
|
+
localeList: Locales[];
|
|
13
|
+
setLocale: (locale: Locales) => void;
|
|
10
14
|
};
|
|
15
|
+
export {};
|
|
11
16
|
//# sourceMappingURL=useLocale.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.d.ts","sourceRoot":"","sources":["../../../src/client/useLocale.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","sourceRoot":"","sources":["../../../src/client/useLocale.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,KAAK,cAAc,GAAG;IACpB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,wBAAwB,cAAc;;;;;wBAsB/C,OAAO;CA0BnB,CAAC"}
|
|
@@ -7,8 +7,8 @@ export type IntlayerEditorElementProps = {
|
|
|
7
7
|
keyPath: KeyPath[];
|
|
8
8
|
isContentSelectable: boolean;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
11
|
-
value:
|
|
10
|
+
export type IntlayerNode<T = string> = ReactNode & {
|
|
11
|
+
value: T;
|
|
12
12
|
};
|
|
13
|
-
export declare const renderIntlayerEditor: (data: IntlayerEditorElementProps, isContentSelectable
|
|
13
|
+
export declare const renderIntlayerEditor: (data: IntlayerEditorElementProps, isContentSelectable?: boolean) => IntlayerNode;
|
|
14
14
|
//# sourceMappingURL=renderContentEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderContentEditor.d.ts","sourceRoot":"","sources":["../../../src/editor/renderContentEditor.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAM,SAAS,EAAE,MAAM,OAAO,CAAC;AAO3C,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAeF,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"renderContentEditor.d.ts","sourceRoot":"","sources":["../../../src/editor/renderContentEditor.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAM,SAAS,EAAE,MAAM,OAAO,CAAC;AAO3C,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAeF,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,MAAM,IAAI,SAAS,GAAG;IACjD,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,eAAO,MAAM,oBAAoB,SACzB,0BAA0B,oCAE/B,YASF,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Locales } from '@intlayer/config';
|
|
2
|
+
import type { DeclarationContent, NodeType } from '@intlayer/core';
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
import { type IntlayerNode } from './editor/renderContentEditor';
|
|
5
|
+
type TransformNodeType<T, L extends Locales, R extends boolean> = T extends {
|
|
6
|
+
[NodeType.Enumeration]: {
|
|
7
|
+
'1': any;
|
|
8
|
+
};
|
|
9
|
+
} ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L, R> : T extends {
|
|
10
|
+
[NodeType.Translation]: object;
|
|
11
|
+
} ? L extends keyof T[NodeType.Translation] ? DeepTransformContent<T[NodeType.Translation][L], L, R> : never : T;
|
|
12
|
+
export type DeepTransformContent<T, L extends Locales, R extends boolean> = T extends object ? T extends (infer U)[] ? DeepTransformContent<U, L, R>[] : T extends {
|
|
13
|
+
nodeType: NodeType | string;
|
|
14
|
+
} ? TransformNodeType<T, L, R> : T extends {
|
|
15
|
+
_owner: any;
|
|
16
|
+
key: any;
|
|
17
|
+
props: any;
|
|
18
|
+
ref: any;
|
|
19
|
+
} ? ReactNode : {
|
|
20
|
+
[K in keyof T]: DeepTransformContent<T[K], L, R>;
|
|
21
|
+
} : T extends undefined ? never : R extends true ? IntlayerNode<T> : T;
|
|
22
|
+
/**
|
|
23
|
+
* Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.
|
|
24
|
+
*/
|
|
25
|
+
export declare const recursiveTransformContent: (value: any, isRenderEditor?: boolean) => object;
|
|
26
|
+
type DataFromDictionary<T extends DeclarationContent, K extends Locales, R extends boolean = false> = DeepTransformContent<T['content'], K, R>;
|
|
27
|
+
export type UseDictionary = <T extends DeclarationContent, L extends Locales, R extends boolean = false>(dictionary: T, locale?: L, isRenderEditor?: R) => DataFromDictionary<T, L, R>;
|
|
28
|
+
/**
|
|
29
|
+
* Hook that picks one dictionary by its id and return the content
|
|
30
|
+
*
|
|
31
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
32
|
+
*/
|
|
33
|
+
export declare const getDictionary: UseDictionary;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=getDictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionary.d.ts","sourceRoot":"","sources":["../../src/getDictionary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EACV,kBAAkB,EAElB,QAAQ,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EACL,KAAK,YAAY,EAElB,MAAM,8BAA8B,CAAC;AAGtC,KAAK,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS;IAC1E,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QAAE,GAAG,EAAE,GAAG,CAAA;KAAE,CAAC;CACtC,GACG,CACE,QAAQ,EAAE,MAAM,KACb,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC7D,CAAC,SAAS;IACN,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAChC,GACD,CAAC,SAAS,MAAM,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,GACrC,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACtD,KAAK,GACP,CAAC,CAAC;AAER,MAAM,MAAM,oBAAoB,CAC9B,CAAC,EACD,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,IACf,CAAC,SAAS,MAAM,GAChB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACnB,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAC/B,CAAC,SAAS;IACN,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC7B,GACD,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC1B,CAAC,SAAS;IAAE,MAAM,EAAE,GAAG,CAAC;IAAC,GAAG,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,GACvD,SAAS,GACT;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;CACjD,GACP,CAAC,SAAS,SAAS,GACjB,KAAK,GACL,CAAC,SAAS,IAAI,GACZ,YAAY,CAAC,CAAC,CAAC,GACf,CAAC,CAAC;AAEV;;GAEG;AACH,eAAO,MAAM,yBAAyB,UAC7B,GAAG,+BAET,MA0BF,CAAC;AAEF,KAAK,kBAAkB,CACrB,CAAC,SAAS,kBAAkB,EAC5B,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,GAAG,KAAK,IACvB,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,aAAa,GAAG,CAC1B,CAAC,SAAS,kBAAkB,EAC5B,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,GAAG,KAAK,EAEzB,UAAU,EAAE,CAAC,EACb,MAAM,CAAC,EAAE,CAAC,EACV,cAAc,CAAC,EAAE,CAAC,KACf,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,aAqB3B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Locales } from '@intlayer/config';
|
|
2
2
|
import type { IntlayerDictionaryTypesConnector } from 'intlayer';
|
|
3
|
-
import { type DeepTransformContent } from './
|
|
3
|
+
import { type DeepTransformContent } from './getDictionary';
|
|
4
4
|
/**
|
|
5
5
|
* Provides a fallback to string type if the generic type T is never,
|
|
6
6
|
* otherwise returns T. This is useful for handling cases where no keys are found.
|
|
@@ -23,17 +23,14 @@ export type DictionaryKeys = StringFallback<keyof IntlayerDictionaryTypesConnect
|
|
|
23
23
|
* Represents the data type returned by the useIntlayer hook,
|
|
24
24
|
* excluding the 'id' and 'filePath' keys from the dictionary content.
|
|
25
25
|
*/
|
|
26
|
-
type DataFromDictionaryKey<T extends DictionaryKeys, K extends Locales> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K>;
|
|
26
|
+
type DataFromDictionaryKey<T extends DictionaryKeys, K extends Locales, R extends boolean = false> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K, R>;
|
|
27
27
|
/**
|
|
28
28
|
* Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,
|
|
29
29
|
* and returns the deeply transformed dictionary content.
|
|
30
30
|
*
|
|
31
31
|
*/
|
|
32
|
-
export type UseIntlayer = <T extends DictionaryKeys, L extends Locales>(key: T, locale?: L) => DataFromDictionaryKey<T, L>;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* deeply transformed according to the dictionary structure and metadata.
|
|
36
|
-
*/
|
|
37
|
-
export declare const useIntlayerBase: UseIntlayer;
|
|
32
|
+
export type UseIntlayer = <T extends DictionaryKeys, L extends Locales, R extends boolean = false>(key: T, locale?: L, isRenderEditor?: R) => DataFromDictionaryKey<T, L, R>;
|
|
33
|
+
export type UseIntlayerEditable = <T extends DictionaryKeys, L extends Locales, R extends boolean = true>(key: T, locale?: L, isRenderEditor?: R) => DataFromDictionaryKey<T, L, R>;
|
|
34
|
+
export declare const getIntlayer: UseIntlayer;
|
|
38
35
|
export {};
|
|
39
|
-
//# sourceMappingURL=
|
|
36
|
+
//# sourceMappingURL=getIntlayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIntlayer.d.ts","sourceRoot":"","sources":["../../src/getIntlayer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAQhD,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,iBAAiB,CAAC;AAGzB;;;;GAIG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,GAAG,cAAc,CACzC,MAAM,gCAAgC,CACvC,CAAC;AAEF;;;GAGG;AACH,KAAK,qBAAqB,CACxB,CAAC,SAAS,cAAc,EACxB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,GAAG,KAAK,IACvB,oBAAoB,CAAC,gCAAgC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CACxB,CAAC,SAAS,cAAc,EACxB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,GAAG,KAAK,EAEzB,GAAG,EAAE,CAAC,EACN,MAAM,CAAC,EAAE,CAAC,EACV,cAAc,CAAC,EAAE,CAAC,KACf,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEpC,MAAM,MAAM,mBAAmB,GAAG,CAChC,CAAC,SAAS,cAAc,EACxB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,GAAG,IAAI,EAExB,GAAG,EAAE,CAAC,EACN,MAAM,CAAC,EAAE,CAAC,EACV,cAAc,CAAC,EAAE,CAAC,KACf,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEpC,eAAO,MAAM,WAAW,EAAE,WA2BzB,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { getTranslation } from './getTranslation';
|
|
2
2
|
export { IntlayerProvider, type IntlayerProviderProps, IntlayerClientContext, useIntlayer, useDictionary, useLocale, useTraduction, useLocaleCookie, useIntlayerContext, localeCookie, setLocaleCookie, getBrowserLocale, useLocaleBase, t, } from './client/index';
|
|
3
|
-
export {
|
|
3
|
+
export { getDictionary } from './getDictionary';
|
|
4
|
+
export { getIntlayer } from './getIntlayer';
|
|
5
|
+
export { type IntlayerNode } from './editor/renderContentEditor';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,WAAW,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,CAAC,GACF,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,WAAW,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,CAAC,GACF,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/server/useDictionary.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/server/useDictionary.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIrE;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,aAS3B,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type UseIntlayerEditable } from '../getIntlayer';
|
|
2
2
|
/**
|
|
3
3
|
* On the server side, Hook that picking one dictionary by its key and return the content
|
|
4
4
|
*
|
|
5
5
|
* If the locale is not provided, it will use the locale from the server context
|
|
6
6
|
*/
|
|
7
|
-
export declare const useIntlayer:
|
|
7
|
+
export declare const useIntlayer: UseIntlayerEditable;
|
|
8
8
|
//# sourceMappingURL=useIntlayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/server/useIntlayer.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,
|
|
1
|
+
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/server/useIntlayer.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,gBAAgB,CAAC;AAIxB;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,mBASzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Internationalization layer for React applications. Declare your multilingual contant in the same lever than your component. Powered by TypeScript, declaration files.",
|
|
6
6
|
"keywords": [
|
|
@@ -91,11 +91,11 @@
|
|
|
91
91
|
"react-cookie": "^7.2.2",
|
|
92
92
|
"vite": "^6.0.3",
|
|
93
93
|
"webpack": "^5.96.1",
|
|
94
|
-
"@intlayer/
|
|
95
|
-
"@intlayer/core": "^3.5.
|
|
96
|
-
"@intlayer/
|
|
97
|
-
"@intlayer/
|
|
98
|
-
"@intlayer/
|
|
94
|
+
"@intlayer/chokidar": "^3.5.4",
|
|
95
|
+
"@intlayer/core": "^3.5.4",
|
|
96
|
+
"@intlayer/dictionaries-entry": "^3.5.4",
|
|
97
|
+
"@intlayer/webpack": "^3.5.4",
|
|
98
|
+
"@intlayer/config": "^3.5.4"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@craco/types": "^7.1.0",
|
|
@@ -114,20 +114,20 @@
|
|
|
114
114
|
"tsup": "^8.3.5",
|
|
115
115
|
"typescript": "^5.7.2",
|
|
116
116
|
"@utils/eslint-config": "^1.0.4",
|
|
117
|
+
"@utils/tsup-config": "^1.0.4",
|
|
117
118
|
"@utils/ts-config": "^1.0.4",
|
|
118
|
-
"@utils/ts-config-types": "^1.0.4"
|
|
119
|
-
"@utils/tsup-config": "^1.0.4"
|
|
119
|
+
"@utils/ts-config-types": "^1.0.4"
|
|
120
120
|
},
|
|
121
121
|
"peerDependencies": {
|
|
122
122
|
"react": ">=16.0.0 <19.0.0",
|
|
123
123
|
"react-dom": ">=16.0.0 <19.0.0",
|
|
124
124
|
"vite": ">=4.0.0",
|
|
125
|
-
"@intlayer/chokidar": "^3.5.
|
|
126
|
-
"@intlayer/
|
|
127
|
-
"@intlayer/core": "^3.5.
|
|
128
|
-
"
|
|
129
|
-
"@intlayer/
|
|
130
|
-
"intlayer": "^3.5.
|
|
125
|
+
"@intlayer/chokidar": "^3.5.4",
|
|
126
|
+
"@intlayer/webpack": "^3.5.4",
|
|
127
|
+
"@intlayer/core": "^3.5.4",
|
|
128
|
+
"intlayer": "^3.5.4",
|
|
129
|
+
"@intlayer/config": "^3.5.4",
|
|
130
|
+
"@intlayer/dictionaries-entry": "^3.5.4"
|
|
131
131
|
},
|
|
132
132
|
"engines": {
|
|
133
133
|
"node": ">=14.18"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useDictionaryBase.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Locales } from '@intlayer/config';\nimport type {\n DeclarationContent,\n DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement, type ReactNode } from 'react';\nimport { processDictionary } from './processDictionary/index';\nimport { renderIntlayerEditor } from './editor/renderContentEditor';\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\ntype TransformNodeType<T, L extends Locales> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L>\n : never\n : T;\n\nexport type DeepTransformContent<T, L extends Locales> = T extends object // Check if the property is an object\n ? T extends (infer U)[] // If it's an array, infer the type of array elements\n ? DeepTransformContent<U, L>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L>;\n }\n : T extends undefined\n ? never\n : IntlayerNode<T>;\n\n/**\n * Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.\n */\nexport const recursiveTransformContent = (\n value: any,\n isContentSelectable = false\n): object => {\n if (typeof value === 'function') {\n return (props: any) =>\n recursiveTransformContent(value(props), isContentSelectable);\n } else if (typeof value === 'object') {\n if (typeof value.dictionaryId !== 'undefined') {\n return renderIntlayerEditor(value, isContentSelectable);\n } else if (Array.isArray(value)) {\n return value.map((el) =>\n recursiveTransformContent(el, isContentSelectable)\n );\n } else if (isValidElement(value)) {\n return value;\n }\n\n return Object.entries(value).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: recursiveTransformContent(value, isContentSelectable),\n }),\n {} as object\n );\n }\n\n return value;\n};\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n> = DeepTransformContent<T['content'], K>;\n\nexport type UseDictionary = <T extends DeclarationContent, L extends Locales>(\n dictionary: T,\n locale?: L\n) => DataFromDictionary<T, L>;\n\n// Add description is JSDoc\n/**\n * Hook that picks one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryBase: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n>(\n dictionary: T,\n locale?: L,\n isContentSelectable = false\n) => {\n const result = processDictionary(\n dictionary.content as DictionaryValue,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isContentSelectable\n ) as DataFromDictionary<T, L>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,mBAA+C;AAC/C,+BAAkC;AAClC,iCAAqC;AAqC9B,MAAM,4BAA4B,CACvC,OACA,sBAAsB,UACX;AACX,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,CAAC,UACN,0BAA0B,MAAM,KAAK,GAAG,mBAAmB;AAAA,EAC/D,WAAW,OAAO,UAAU,UAAU;AACpC,QAAI,OAAO,MAAM,iBAAiB,aAAa;AAC7C,iBAAO,iDAAqB,OAAO,mBAAmB;AAAA,IACxD,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,aAAO,MAAM;AAAA,QAAI,CAAC,OAChB,0BAA0B,IAAI,mBAAmB;AAAA,MACnD;AAAA,IACF,eAAW,6BAAe,KAAK,GAAG;AAChC,aAAO;AAAA,IACT;AAEA,WAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,MAC3B,CAAC,KAAK,CAAC,KAAKA,MAAK,OAAO;AAAA,QACtB,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,0BAA0BA,QAAO,mBAAmB;AAAA,MAC7D;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAkBO,MAAM,oBAAmC,CAI9C,YACA,QACA,sBAAsB,UACnB;AACH,QAAM,aAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["value"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { processDictionary } from './processDictionary/index';\nimport {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './useDictionaryBase';\n\n/**\n * Provides a fallback to string type if the generic type T is never,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\ntype DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <T extends DictionaryKeys, L extends Locales>(\n key: T,\n locale?: L\n) => DataFromDictionaryKey<T, L>;\n\n/**\n * Hook that picks one dictionary by its ID and returns the content,\n * deeply transformed according to the dictionary structure and metadata.\n */\nexport const useIntlayerBase: UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n>(\n key: T,\n locale?: L\n) => {\n const dictionary: Dictionary = dictionaries[key as keyof typeof dictionaries];\n\n const result = processDictionary(\n dictionary.content,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n const isContentSelectable = true;\n\n return recursiveTransformContent(\n result,\n isContentSelectable\n ) as DataFromDictionaryKey<T, L>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,gCAAyB;AAEzB,+BAAkC;AAClC,+BAGO;AA+CA,MAAM,kBAA+B,CAI1C,KACA,WACG;AACH,QAAM,aAAyB,0BAAAA,QAAa,GAAgC;AAE5E,QAAM,aAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,QAAM,sBAAsB;AAE5B,aAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["dictionaries"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useDictionaryBase.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Locales } from '@intlayer/config';\nimport type {\n DeclarationContent,\n DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement, type ReactNode } from 'react';\nimport { processDictionary } from './processDictionary/index';\nimport { renderIntlayerEditor } from './editor/renderContentEditor';\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\ntype TransformNodeType<T, L extends Locales> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L>\n : never\n : T;\n\nexport type DeepTransformContent<T, L extends Locales> = T extends object // Check if the property is an object\n ? T extends (infer U)[] // If it's an array, infer the type of array elements\n ? DeepTransformContent<U, L>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L>;\n }\n : T extends undefined\n ? never\n : IntlayerNode<T>;\n\n/**\n * Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.\n */\nexport const recursiveTransformContent = (\n value: any,\n isContentSelectable = false\n): object => {\n if (typeof value === 'function') {\n return (props: any) =>\n recursiveTransformContent(value(props), isContentSelectable);\n } else if (typeof value === 'object') {\n if (typeof value.dictionaryId !== 'undefined') {\n return renderIntlayerEditor(value, isContentSelectable);\n } else if (Array.isArray(value)) {\n return value.map((el) =>\n recursiveTransformContent(el, isContentSelectable)\n );\n } else if (isValidElement(value)) {\n return value;\n }\n\n return Object.entries(value).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: recursiveTransformContent(value, isContentSelectable),\n }),\n {} as object\n );\n }\n\n return value;\n};\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n> = DeepTransformContent<T['content'], K>;\n\nexport type UseDictionary = <T extends DeclarationContent, L extends Locales>(\n dictionary: T,\n locale?: L\n) => DataFromDictionary<T, L>;\n\n// Add description is JSDoc\n/**\n * Hook that picks one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryBase: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n>(\n dictionary: T,\n locale?: L,\n isContentSelectable = false\n) => {\n const result = processDictionary(\n dictionary.content as DictionaryValue,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isContentSelectable\n ) as DataFromDictionary<T, L>;\n};\n"],"mappings":";AAOA,SAAS,sBAAsC;AAC/C,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AAqC9B,MAAM,4BAA4B,CACvC,OACA,sBAAsB,UACX;AACX,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,CAAC,UACN,0BAA0B,MAAM,KAAK,GAAG,mBAAmB;AAAA,EAC/D,WAAW,OAAO,UAAU,UAAU;AACpC,QAAI,OAAO,MAAM,iBAAiB,aAAa;AAC7C,aAAO,qBAAqB,OAAO,mBAAmB;AAAA,IACxD,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,aAAO,MAAM;AAAA,QAAI,CAAC,OAChB,0BAA0B,IAAI,mBAAmB;AAAA,MACnD;AAAA,IACF,WAAW,eAAe,KAAK,GAAG;AAChC,aAAO;AAAA,IACT;AAEA,WAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,MAC3B,CAAC,KAAK,CAAC,KAAKA,MAAK,OAAO;AAAA,QACtB,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,0BAA0BA,QAAO,mBAAmB;AAAA,MAC7D;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAkBO,MAAM,oBAAmC,CAI9C,YACA,QACA,sBAAsB,UACnB;AACH,QAAM,SAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["value"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { processDictionary } from './processDictionary/index';\nimport {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './useDictionaryBase';\n\n/**\n * Provides a fallback to string type if the generic type T is never,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\ntype DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <T extends DictionaryKeys, L extends Locales>(\n key: T,\n locale?: L\n) => DataFromDictionaryKey<T, L>;\n\n/**\n * Hook that picks one dictionary by its ID and returns the content,\n * deeply transformed according to the dictionary structure and metadata.\n */\nexport const useIntlayerBase: UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n>(\n key: T,\n locale?: L\n) => {\n const dictionary: Dictionary = dictionaries[key as keyof typeof dictionaries];\n\n const result = processDictionary(\n dictionary.content,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n const isContentSelectable = true;\n\n return recursiveTransformContent(\n result,\n isContentSelectable\n ) as DataFromDictionaryKey<T, L>;\n};\n"],"mappings":";AAOA,OAAO,kBAAkB;AAEzB,SAAS,yBAAyB;AAClC;AAAA,EAEE;AAAA,OACK;AA+CA,MAAM,kBAA+B,CAI1C,KACA,WACG;AACH,QAAM,aAAyB,aAAa,GAAgC;AAE5E,QAAM,SAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,QAAM,sBAAsB;AAE5B,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Locales } from '@intlayer/config';
|
|
2
|
-
import type { DeclarationContent, NodeType } from '@intlayer/core';
|
|
3
|
-
import { type ReactNode } from 'react';
|
|
4
|
-
export type IntlayerNode<T = string> = ReactNode & {
|
|
5
|
-
value: T;
|
|
6
|
-
};
|
|
7
|
-
type TransformNodeType<T, L extends Locales> = T extends {
|
|
8
|
-
[NodeType.Enumeration]: {
|
|
9
|
-
'1': any;
|
|
10
|
-
};
|
|
11
|
-
} ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L> : T extends {
|
|
12
|
-
[NodeType.Translation]: object;
|
|
13
|
-
} ? L extends keyof T[NodeType.Translation] ? DeepTransformContent<T[NodeType.Translation][L], L> : never : T;
|
|
14
|
-
export type DeepTransformContent<T, L extends Locales> = T extends object ? T extends (infer U)[] ? DeepTransformContent<U, L>[] : T extends {
|
|
15
|
-
nodeType: NodeType | string;
|
|
16
|
-
} ? TransformNodeType<T, L> : T extends {
|
|
17
|
-
_owner: any;
|
|
18
|
-
key: any;
|
|
19
|
-
props: any;
|
|
20
|
-
ref: any;
|
|
21
|
-
} ? ReactNode : {
|
|
22
|
-
[K in keyof T]: DeepTransformContent<T[K], L>;
|
|
23
|
-
} : T extends undefined ? never : IntlayerNode<T>;
|
|
24
|
-
/**
|
|
25
|
-
* Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.
|
|
26
|
-
*/
|
|
27
|
-
export declare const recursiveTransformContent: (value: any, isContentSelectable?: boolean) => object;
|
|
28
|
-
type DataFromDictionary<T extends DeclarationContent, K extends Locales> = DeepTransformContent<T['content'], K>;
|
|
29
|
-
export type UseDictionary = <T extends DeclarationContent, L extends Locales>(dictionary: T, locale?: L) => DataFromDictionary<T, L>;
|
|
30
|
-
/**
|
|
31
|
-
* Hook that picks one dictionary by its id and return the content
|
|
32
|
-
*
|
|
33
|
-
* If the locale is not provided, it will use the locale from the client context
|
|
34
|
-
*/
|
|
35
|
-
export declare const useDictionaryBase: UseDictionary;
|
|
36
|
-
export {};
|
|
37
|
-
//# sourceMappingURL=useDictionaryBase.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryBase.d.ts","sourceRoot":"","sources":["../../src/useDictionaryBase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EACV,kBAAkB,EAElB,QAAQ,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvD,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,MAAM,IAAI,SAAS,GAAG;IACjD,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,KAAK,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS;IACvD,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QAAE,GAAG,EAAE,GAAG,CAAA;KAAE,CAAC;CACtC,GACG,CAAC,QAAQ,EAAE,MAAM,KAAK,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAC3E,CAAC,SAAS;IACN,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAChC,GACD,CAAC,SAAS,MAAM,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,GACrC,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GACnD,KAAK,GACP,CAAC,CAAC;AAER,MAAM,MAAM,oBAAoB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS,MAAM,GACrE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACnB,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAC5B,CAAC,SAAS;IACN,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC7B,GACD,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GACvB,CAAC,SAAS;IAAE,MAAM,EAAE,GAAG,CAAC;IAAC,GAAG,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,GACvD,SAAS,GACT;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;CAC9C,GACP,CAAC,SAAS,SAAS,GACjB,KAAK,GACL,YAAY,CAAC,CAAC,CAAC,CAAC;AAEtB;;GAEG;AACH,eAAO,MAAM,yBAAyB,UAC7B,GAAG,oCAET,MAyBF,CAAC;AAEF,KAAK,kBAAkB,CACrB,CAAC,SAAS,kBAAkB,EAC5B,CAAC,SAAS,OAAO,IACf,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;AAE1C,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,SAAS,kBAAkB,EAAE,CAAC,SAAS,OAAO,EAC1E,UAAU,EAAE,CAAC,EACb,MAAM,CAAC,EAAE,CAAC,KACP,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAG9B;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,aAoB/B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayerBase.d.ts","sourceRoot":"","sources":["../../src/useIntlayerBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAQhD,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAEjE,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,qBAAqB,CAAC;AAE7B;;;;GAIG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,GAAG,cAAc,CACzC,MAAM,gCAAgC,CACvC,CAAC;AAEF;;;GAGG;AACH,KAAK,qBAAqB,CACxB,CAAC,SAAS,cAAc,EACxB,CAAC,SAAS,OAAO,IACf,oBAAoB,CAAC,gCAAgC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,OAAO,EACpE,GAAG,EAAE,CAAC,EACN,MAAM,CAAC,EAAE,CAAC,KACP,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,WAuB7B,CAAC"}
|