react-intlayer 3.5.3 → 3.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/cjs/cli/react-intlayer.cjs +4 -4
- package/dist/cjs/cli/react-intlayer.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +3 -0
- package/dist/cjs/client/index.cjs.map +1 -1
- 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/useIntlayerAsync.cjs +55 -0
- package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -0
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +59 -0
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -0
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +5 -1
- package/dist/cjs/editor/IntlayerEditorProvider.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} +20 -19
- 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/getIntlayerAsync.cjs +42 -0
- package/dist/cjs/getIntlayerAsync.cjs.map +1 -0
- package/dist/cjs/index.cjs +8 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/processDictionary/contentDictionary.cjs.map +1 -1
- package/dist/cjs/processDictionary/index.cjs +13 -13
- package/dist/cjs/processDictionary/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/cjs/utils/PoweredByMeta/index.cjs +40 -0
- package/dist/cjs/utils/PoweredByMeta/index.cjs.map +1 -0
- package/dist/esm/cli/react-intlayer.mjs +5 -5
- package/dist/esm/cli/react-intlayer.mjs.map +1 -1
- package/dist/esm/client/index.mjs +2 -0
- package/dist/esm/client/index.mjs.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/useIntlayerAsync.mjs +34 -0
- package/dist/esm/client/useIntlayerAsync.mjs.map +1 -0
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +36 -0
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -0
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +6 -2
- package/dist/esm/editor/IntlayerEditorProvider.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} +17 -14
- 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/getIntlayerAsync.mjs +19 -0
- package/dist/esm/getIntlayerAsync.mjs.map +1 -0
- package/dist/esm/index.mjs +6 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/index.mjs +13 -13
- package/dist/esm/processDictionary/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/esm/utils/PoweredByMeta/index.mjs +17 -0
- package/dist/esm/utils/PoweredByMeta/index.mjs.map +1 -0
- package/dist/types/client/index.d.ts +1 -0
- package/dist/types/client/index.d.ts.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/useIntlayerAsync.d.ts +15 -0
- package/dist/types/client/useIntlayerAsync.d.ts.map +1 -0
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +6 -0
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -0
- package/dist/types/editor/ContentSelectorWrapper.d.ts +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/renderContentEditor.d.ts +4 -4
- 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 -10
- package/dist/types/getIntlayer.d.ts.map +1 -0
- package/dist/types/getIntlayerAsync.d.ts +13 -0
- package/dist/types/getIntlayerAsync.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/processDictionary/contentDictionary.d.ts +1 -1
- package/dist/types/processDictionary/contentDictionary.d.ts.map +1 -1
- package/dist/types/processDictionary/index.d.ts +2 -2
- package/dist/types/processDictionary/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/dist/types/utils/PoweredByMeta/index.d.ts +3 -0
- package/dist/types/utils/PoweredByMeta/index.d.ts.map +1 -0
- package/package.json +15 -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
|
@@ -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 */\nexport type DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K, R>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => 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":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "./chunk-ZD7AOCMD.mjs";
|
|
3
|
+
import { fetchDistantDictionary } from './distantDictionary/fetchDistantDictionary.mjs';
|
|
4
|
+
import { getDictionary } from './getDictionary.mjs';
|
|
5
|
+
const getIntlayerAsync = async (key, locale, isRenderEditor = true) => {
|
|
6
|
+
const jsonDistantDictionary = await fetchDistantDictionary(key);
|
|
7
|
+
if (jsonDistantDictionary) {
|
|
8
|
+
return getDictionary(
|
|
9
|
+
jsonDistantDictionary,
|
|
10
|
+
locale,
|
|
11
|
+
isRenderEditor
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
getIntlayerAsync
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=getIntlayerAsync.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { DeclarationContent } from 'intlayer';\nimport { fetchDistantDictionary } from './distantDictionary/fetchDistantDictionary';\nimport { getDictionary } from './getDictionary';\nimport { DictionaryKeys, DataFromDictionaryKey } from './getIntlayer';\n\nexport type GetIntlayerAsync = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => Promise<DataFromDictionaryKey<T, L, R> | null>;\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getIntlayerAsync: GetIntlayerAsync = async <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor = true as R\n) => {\n const jsonDistantDictionary = await fetchDistantDictionary(key);\n\n if (jsonDistantDictionary) {\n return getDictionary(\n jsonDistantDictionary as unknown as DeclarationContent,\n locale,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n }\n\n return null;\n};\n"],"mappings":";;AAIA,SAAS,8BAA8B;AACvC,SAAS,qBAAqB;AAqBvB,MAAM,mBAAqC,OAKhD,KACA,QACA,iBAAiB,SACd;AACH,QAAM,wBAAwB,MAAM,uBAAuB,GAAG;AAE9D,MAAI,uBAAuB;AACzB,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
IntlayerProvider,
|
|
5
5
|
IntlayerClientContext,
|
|
6
6
|
useIntlayer,
|
|
7
|
+
useIntlayerAsync,
|
|
7
8
|
useDictionary,
|
|
8
9
|
useLocale,
|
|
9
10
|
useTraduction,
|
|
@@ -15,16 +16,21 @@ import {
|
|
|
15
16
|
useLocaleBase,
|
|
16
17
|
t
|
|
17
18
|
} from './client/index.mjs';
|
|
19
|
+
import { getDictionary } from './getDictionary.mjs';
|
|
20
|
+
import { getIntlayer } from './getIntlayer.mjs';
|
|
18
21
|
export {
|
|
19
22
|
IntlayerClientContext,
|
|
20
23
|
IntlayerProvider,
|
|
21
24
|
getBrowserLocale,
|
|
25
|
+
getDictionary,
|
|
26
|
+
getIntlayer,
|
|
22
27
|
getTranslation,
|
|
23
28
|
localeCookie,
|
|
24
29
|
setLocaleCookie,
|
|
25
30
|
t,
|
|
26
31
|
useDictionary,
|
|
27
32
|
useIntlayer,
|
|
33
|
+
useIntlayerAsync,
|
|
28
34
|
useIntlayerContext,
|
|
29
35
|
useLocale,
|
|
30
36
|
useLocaleBase,
|
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 useIntlayerAsync,\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,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;","names":[]}
|
|
@@ -10,7 +10,7 @@ import { getTranslation } from '../getTranslation.mjs';
|
|
|
10
10
|
const {
|
|
11
11
|
internationalization: { defaultLocale }
|
|
12
12
|
} = getConfiguration();
|
|
13
|
-
const processTranslation = (languageContent, locale,
|
|
13
|
+
const processTranslation = (languageContent, locale, dictionaryKey, dictionaryPath, keyPath = []) => {
|
|
14
14
|
const translationResult = getTranslation(
|
|
15
15
|
languageContent,
|
|
16
16
|
locale
|
|
@@ -21,13 +21,13 @@ const processTranslation = (languageContent, locale, dictionaryId, dictionaryPat
|
|
|
21
21
|
];
|
|
22
22
|
return processDictionary(
|
|
23
23
|
translationResult,
|
|
24
|
-
|
|
24
|
+
dictionaryKey,
|
|
25
25
|
dictionaryPath,
|
|
26
26
|
resultKeyPath,
|
|
27
27
|
locale
|
|
28
28
|
);
|
|
29
29
|
};
|
|
30
|
-
const processEnumeration = (enumerationContent, locale,
|
|
30
|
+
const processEnumeration = (enumerationContent, locale, dictionaryKey, dictionaryPath, keyPath = []) => (quantity) => {
|
|
31
31
|
const enumerationResult = getEnumeration(
|
|
32
32
|
enumerationContent,
|
|
33
33
|
quantity
|
|
@@ -42,20 +42,20 @@ const processEnumeration = (enumerationContent, locale, dictionaryId, dictionary
|
|
|
42
42
|
];
|
|
43
43
|
return processDictionary(
|
|
44
44
|
enumerationResult,
|
|
45
|
-
|
|
45
|
+
dictionaryKey,
|
|
46
46
|
dictionaryPath,
|
|
47
47
|
resultKeyPath,
|
|
48
48
|
locale
|
|
49
49
|
);
|
|
50
50
|
};
|
|
51
51
|
const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined";
|
|
52
|
-
const processNode = (field, locale,
|
|
52
|
+
const processNode = (field, locale, dictionaryKey, dictionaryPath, keyPath = []) => {
|
|
53
53
|
if (typeof field === "object") {
|
|
54
54
|
if (field.nodeType === NodeType.Translation) {
|
|
55
55
|
return processTranslation(
|
|
56
56
|
field[NodeType.Translation],
|
|
57
57
|
locale,
|
|
58
|
-
|
|
58
|
+
dictionaryKey,
|
|
59
59
|
dictionaryPath,
|
|
60
60
|
keyPath
|
|
61
61
|
);
|
|
@@ -64,7 +64,7 @@ const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = [])
|
|
|
64
64
|
return processEnumeration(
|
|
65
65
|
field[NodeType.Enumeration],
|
|
66
66
|
locale,
|
|
67
|
-
|
|
67
|
+
dictionaryKey,
|
|
68
68
|
dictionaryPath,
|
|
69
69
|
keyPath
|
|
70
70
|
);
|
|
@@ -73,7 +73,7 @@ const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = [])
|
|
|
73
73
|
return processDictionary(
|
|
74
74
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
75
75
|
field,
|
|
76
|
-
|
|
76
|
+
dictionaryKey,
|
|
77
77
|
dictionaryPath,
|
|
78
78
|
keyPath,
|
|
79
79
|
locale
|
|
@@ -105,7 +105,7 @@ const createReactElement = (element) => {
|
|
|
105
105
|
return createElement(type ?? "div", props, ...props.children);
|
|
106
106
|
};
|
|
107
107
|
const traceKeys = ["filePath", "nodeType"];
|
|
108
|
-
const processDictionary = (content,
|
|
108
|
+
const processDictionary = (content, dictionaryKey, dictionaryPath, keyPath = [], locale = defaultLocale) => {
|
|
109
109
|
if (isReactNode(content)) {
|
|
110
110
|
return createReactElement(
|
|
111
111
|
content
|
|
@@ -118,7 +118,7 @@ const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [],
|
|
|
118
118
|
return processNode(
|
|
119
119
|
content,
|
|
120
120
|
locale,
|
|
121
|
-
|
|
121
|
+
dictionaryKey,
|
|
122
122
|
dictionaryPath,
|
|
123
123
|
keyPath
|
|
124
124
|
);
|
|
@@ -131,7 +131,7 @@ const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [],
|
|
|
131
131
|
return processNode(
|
|
132
132
|
field,
|
|
133
133
|
locale,
|
|
134
|
-
|
|
134
|
+
dictionaryKey,
|
|
135
135
|
dictionaryPath,
|
|
136
136
|
resultKeyPath
|
|
137
137
|
);
|
|
@@ -150,7 +150,7 @@ const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [],
|
|
|
150
150
|
const nodeResult = processNode(
|
|
151
151
|
field,
|
|
152
152
|
locale,
|
|
153
|
-
|
|
153
|
+
dictionaryKey,
|
|
154
154
|
dictionaryPath,
|
|
155
155
|
resultKeyPath
|
|
156
156
|
);
|
|
@@ -162,7 +162,7 @@ const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [],
|
|
|
162
162
|
return {
|
|
163
163
|
content,
|
|
164
164
|
keyPath,
|
|
165
|
-
|
|
165
|
+
dictionaryKey,
|
|
166
166
|
dictionaryPath
|
|
167
167
|
};
|
|
168
168
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n findMatchingCondition,\n type KeyPath,\n type DictionaryValue,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<DictionaryValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: DictionaryValue = getTranslation<DictionaryValue>(\n languageContent,\n locale\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Translation, key: locale },\n ];\n\n return processDictionary(\n translationResult,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration =\n (\n enumerationContent: QuantityContent<DictionaryValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n ): TransformedContentValue =>\n (quantity: number): TransformedContentValue => {\n const enumerationResult: DictionaryValue = getEnumeration<DictionaryValue>(\n enumerationContent,\n quantity\n );\n\n const matchingCondition = findMatchingCondition(\n enumerationContent,\n quantity\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Enumeration, key: matchingCondition.toString() },\n ];\n\n return processDictionary(\n enumerationResult,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n ) as TransformedContentValue;\n };\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: DictionaryValue | undefined,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (\n (field as TranslationContent<DictionaryValue>).nodeType ===\n NodeType.Translation\n ) {\n return processTranslation(\n field[\n NodeType.Translation as keyof typeof field\n ] as LanguageContent<DictionaryValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n ) as TransformedContentValue;\n }\n\n if (\n (field as EnumerationContent<DictionaryValue>).nodeType ===\n NodeType.Enumeration\n ) {\n return processEnumeration(\n field[\n NodeType.Enumeration as keyof typeof field\n ] as QuantityContent<DictionaryValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n field!,\n dictionaryId,\n dictionaryPath,\n keyPath,\n locale\n ) as TransformedContentValue;\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n const convertChildrenAsArray = (element: ReactElement): ReactElement => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children).forEach((key) => {\n childrenResult.push(createReactElement(children[key]));\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(element);\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(type ?? 'div', props, ...props.children);\n};\n\nconst traceKeys: string[] = ['filePath', 'nodeType'];\n\n/**\n * Function that process a dictionary and return the result to be used in the application.\n */\nexport const processDictionary = (\n content: DictionaryValue,\n dictionaryId: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = [],\n locale: Locales = defaultLocale\n // eslint-disable-next-line sonarjs/cognitive-complexity\n): TransformedContent => {\n // If it's a React element, render it\n if (isReactNode(content as Record<string, unknown>)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const isArray = Array.isArray(content);\n\n let result: TransformedContent = {};\n\n if (typeof (content as TypedNode).nodeType !== 'undefined') {\n return processNode(\n content as DictionaryValue,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n ) as TransformedContent;\n } else if (isArray) {\n // Eslint fix because promises are awaited during build stage\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n result = (content as DictionaryValue[]).map((field, key) => {\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Array, key },\n ];\n\n return processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n }) as TransformedContent;\n } else {\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key as keyof typeof content];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Object, key },\n ];\n\n const nodeResult = processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n\n result[key] = nodeResult;\n }\n }\n\n return result;\n }\n\n return {\n content: content as TransformedContentValue,\n keyPath,\n dictionaryId,\n dictionaryPath,\n };\n};\n"],"mappings":";AACA,SAAuB,wBAAwB;AAC/C;AAAA,EACE;AAAA,EAGA;AAAA,OAMK;AACP,SAA4B,qBAAqC;AACjE,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAM/B,MAAM;AAAA,EACJ,sBAAsB,EAAE,cAAc;AACxC,IAAI,iBAAiB;AAErB,MAAM,qBAAqB,CACzB,iBACA,QACA,cACA,gBACA,UAAqB,CAAC,MACC;AACvB,QAAM,oBAAqC;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAA2B;AAAA,IAC/B,GAAG;AAAA,IACH,EAAE,MAAM,SAAS,aAAa,KAAK,OAAO;AAAA,EAC5C;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,MAAM,qBACJ,CACE,oBACA,QACA,cACA,gBACA,UAAqB,CAAC,MAExB,CAAC,aAA8C;AAC7C,QAAM,oBAAqC;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,oBAAoB;AAAA,IACxB;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAA2B;AAAA,IAC/B,GAAG;AAAA,IACH,EAAE,MAAM,SAAS,aAAa,KAAK,kBAAkB,SAAS,EAAE;AAAA,EAClE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;A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","names":["element"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n findMatchingCondition,\n type KeyPath,\n type DictionaryValue,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<DictionaryValue>,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: DictionaryValue = getTranslation<DictionaryValue>(\n languageContent,\n locale\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Translation, key: locale },\n ];\n\n return processDictionary(\n translationResult,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration =\n (\n enumerationContent: QuantityContent<DictionaryValue>,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n ): TransformedContentValue =>\n (quantity: number): TransformedContentValue => {\n const enumerationResult: DictionaryValue = getEnumeration<DictionaryValue>(\n enumerationContent,\n quantity\n );\n\n const matchingCondition = findMatchingCondition(\n enumerationContent,\n quantity\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Enumeration, key: matchingCondition.toString() },\n ];\n\n return processDictionary(\n enumerationResult,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath,\n locale\n ) as TransformedContentValue;\n };\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: DictionaryValue | undefined,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (\n (field as TranslationContent<DictionaryValue>).nodeType ===\n NodeType.Translation\n ) {\n return processTranslation(\n field[\n NodeType.Translation as keyof typeof field\n ] as LanguageContent<DictionaryValue>,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n ) as TransformedContentValue;\n }\n\n if (\n (field as EnumerationContent<DictionaryValue>).nodeType ===\n NodeType.Enumeration\n ) {\n return processEnumeration(\n field[\n NodeType.Enumeration as keyof typeof field\n ] as QuantityContent<DictionaryValue>,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n field!,\n dictionaryKey,\n dictionaryPath,\n keyPath,\n locale\n ) as TransformedContentValue;\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n const convertChildrenAsArray = (element: ReactElement): ReactElement => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children).forEach((key) => {\n childrenResult.push(createReactElement(children[key]));\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(element);\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(type ?? 'div', props, ...props.children);\n};\n\nconst traceKeys: string[] = ['filePath', 'nodeType'];\n\n/**\n * Function that process a dictionary and return the result to be used in the application.\n */\nexport const processDictionary = (\n content: DictionaryValue,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = [],\n locale: Locales = defaultLocale\n): TransformedContent => {\n // If it's a React element, render it\n if (isReactNode(content as Record<string, unknown>)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const isArray = Array.isArray(content);\n\n let result: TransformedContent = {};\n\n if (typeof (content as TypedNode).nodeType !== 'undefined') {\n return processNode(\n content as DictionaryValue,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n ) as TransformedContent;\n } else if (isArray) {\n // Eslint fix because promises are awaited during build stage\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n result = (content as DictionaryValue[]).map((field, key) => {\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Array, key },\n ];\n\n return processNode(\n field,\n locale,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath\n );\n }) as TransformedContent;\n } else {\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key as keyof typeof content];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Object, key },\n ];\n\n const nodeResult = processNode(\n field,\n locale,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath\n );\n\n result[key] = nodeResult;\n }\n }\n\n return result;\n }\n\n return {\n content: content as TransformedContentValue,\n keyPath,\n dictionaryKey,\n dictionaryPath,\n };\n};\n"],"mappings":";AACA,SAAuB,wBAAwB;AAC/C;AAAA,EACE;AAAA,EAGA;AAAA,OAMK;AACP,SAA4B,qBAAqC;AACjE,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAM/B,MAAM;AAAA,EACJ,sBAAsB,EAAE,cAAc;AACxC,IAAI,iBAAiB;AAErB,MAAM,qBAAqB,CACzB,iBACA,QACA,eACA,gBACA,UAAqB,CAAC,MACC;AACvB,QAAM,oBAAqC;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAA2B;AAAA,IAC/B,GAAG;AAAA,IACH,EAA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,OAAO;AAEL,iBAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,cAAM,QAAQ,QAAQ,GAA2B;AAEjD,YAAI,UAAU,SAAS,GAAG,GAAG;AAC3B,iBAAO,GAAG,IAAI;AACd;AAAA,QACF;AAEA,cAAM,gBAA2B;AAAA,UAC/B,GAAG;AAAA,UACH,EAAE,MAAM,SAAS,QAAQ,IAAI;AAAA,QAC/B;AAEA,cAAM,aAAa;AAAA,UACjB;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["element"]}
|
|
@@ -1,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":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../../chunk-ZD7AOCMD.mjs";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
const PoweredByMeta = () => {
|
|
5
|
+
if (process.env.NODE_ENV !== "production") return null;
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const metaTag = document.createElement("meta");
|
|
8
|
+
metaTag.name = "content-powered-by";
|
|
9
|
+
metaTag.content = "Intlayer - https://intlayer.org";
|
|
10
|
+
document.head.appendChild(metaTag);
|
|
11
|
+
}, []);
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
PoweredByMeta
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/PoweredByMeta/index.ts"],"sourcesContent":["'use client';\n\nimport { type FC, useEffect } from 'react';\n\nexport const PoweredByMeta: FC = () => {\n if (process.env.NODE_ENV !== 'production') return null;\n\n useEffect(() => {\n const metaTag = document.createElement('meta');\n metaTag.name = 'content-powered-by';\n metaTag.content = 'Intlayer - https://intlayer.org';\n document.head.appendChild(metaTag);\n }, []);\n\n return null; // This component does not render anything visible\n};\n"],"mappings":";;AAEA,SAAkB,iBAAiB;AAE5B,MAAM,gBAAoB,MAAM;AACrC,MAAI,QAAQ,IAAI,aAAa,aAAc,QAAO;AAElD,YAAU,MAAM;AACd,UAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,YAAQ,OAAO;AACf,YAAQ,UAAU;AAClB,aAAS,KAAK,YAAY,OAAO;AAAA,EACnC,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { type IntlayerProviderProps, IntlayerClientContext, useIntlayerContext, IntlayerProvider, } from './IntlayerProvider';
|
|
2
2
|
export { useIntlayer } from './useIntlayer';
|
|
3
|
+
export { useIntlayerAsync } from './useIntlayerAsync';
|
|
3
4
|
export { useDictionary } from './useDictionary';
|
|
4
5
|
export { useLocaleBase } from './useLocaleBase';
|
|
5
6
|
export { useLocale } from './useLocale';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Locales } from '@intlayer/config/client';
|
|
2
|
+
import { DataFromDictionaryKey, type DictionaryKeys } from '../getIntlayer';
|
|
3
|
+
export type UseIntlayerAsync = <T extends DictionaryKeys, L extends Locales, R extends boolean = true>(key: T, locale?: L, isRenderEditor?: R) => DataFromDictionaryKey<T, L, R> & {
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* On the client side, Hook that picking one dictionary by its key and return the content
|
|
8
|
+
*
|
|
9
|
+
* This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
13
|
+
*/
|
|
14
|
+
export declare const useIntlayerAsync: UseIntlayerAsync;
|
|
15
|
+
//# sourceMappingURL=useIntlayerAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntlayerAsync.d.ts","sourceRoot":"","sources":["../../../src/client/useIntlayerAsync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EACL,qBAAqB,EACrB,KAAK,cAAc,EAEpB,MAAM,gBAAgB,CAAC;AAIxB,MAAM,MAAM,gBAAgB,GAAG,CAC7B,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,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAiC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchDistantDictionary.d.ts","sourceRoot":"","sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKvD;;GAEG;AACH,eAAO,MAAM,sBAAsB,kBAClB,MAAM,KACpB,OAAO,CAAC,aAAa,CAoCvB,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { type KeyPath } from '@intlayer/core';
|
|
|
2
2
|
import { type FC, type ReactNode } from 'react';
|
|
3
3
|
export type ContentSelectorWrapperProps = {
|
|
4
4
|
children: ReactNode;
|
|
5
|
-
|
|
5
|
+
dictionaryKey: string;
|
|
6
6
|
dictionaryPath: string;
|
|
7
7
|
keyPath: KeyPath[];
|
|
8
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.d.ts","sourceRoot":"","sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEhD,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,SAAS,CAAC;IACpB,
|
|
1
|
+
{"version":3,"file":"ContentSelectorWrapper.d.ts","sourceRoot":"","sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEhD,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,SAAS,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,2BAA2B,CAE9C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerEditorProvider.d.ts","sourceRoot":"","sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"IntlayerEditorProvider.d.ts","sourceRoot":"","sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAI9C,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,iBAAiB,CAKxD,CAAC"}
|
|
@@ -2,13 +2,13 @@ import type { KeyPath } from '@intlayer/core';
|
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
export type IntlayerEditorElementProps = {
|
|
4
4
|
content: string;
|
|
5
|
-
|
|
5
|
+
dictionaryKey: string;
|
|
6
6
|
dictionaryPath: string;
|
|
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,
|
|
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,aAAa,EAAE,MAAM,CAAC;IACtB,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
|
+
//# s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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,13 @@ 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
|
+
export 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
|
-
|
|
36
|
-
*/
|
|
37
|
-
export declare const useIntlayerBase: UseIntlayer;
|
|
38
|
-
export {};
|
|
39
|
-
//# sourceMappingURL=useIntlayerBase.d.ts.map
|
|
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;
|
|
35
|
+
//# sourceMappingURL=getIntlayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIntlayer.d.ts","sourceRoot":"","sources":["../../src/getIntlayer.ts"],"names":[],"m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from '@intlayer/config/client';
|
|
2
|
+
import { DictionaryKeys, DataFromDictionaryKey } from './getIntlayer';
|
|
3
|
+
export type GetIntlayerAsync = <T extends DictionaryKeys, L extends Locales, R extends boolean = true>(key: T, locale?: L, isRenderEditor?: R) => Promise<DataFromDictionaryKey<T, L, R> | null>;
|
|
4
|
+
/**
|
|
5
|
+
* On the client side, Hook that picking one dictionary by its key and return the content
|
|
6
|
+
*
|
|
7
|
+
* This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
11
|
+
*/
|
|
12
|
+
export declare const getIntlayerAsync: GetIntlayerAsync;
|
|
13
|
+
//# sourceMappingURL=getIntlayerAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIntlayerAsync.d.ts","sourceRoot":"","sources":["../../src/getIntlayerAsync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIvD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtE,MAAM,MAAM,gBAAgB,GAAG,CAC7B,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,OAAO,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AAEpD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAoB9B,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { getTranslation } from './getTranslation';
|
|
2
|
-
export { IntlayerProvider, type IntlayerProviderProps, IntlayerClientContext, useIntlayer, useDictionary, useLocale, useTraduction, useLocaleCookie, useIntlayerContext, localeCookie, setLocaleCookie, getBrowserLocale, useLocaleBase, t, } from './client/index';
|
|
3
|
-
export {
|
|
2
|
+
export { IntlayerProvider, type IntlayerProviderProps, IntlayerClientContext, useIntlayer, useIntlayerAsync, useDictionary, useLocale, useTraduction, useLocaleCookie, useIntlayerContext, localeCookie, setLocaleCookie, getBrowserLocale, useLocaleBase, t, } from './client/index';
|
|
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,gBAAgB,EAChB,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"}
|
|
@@ -4,7 +4,7 @@ export type TransformedContentValue = string | ReactNode | {
|
|
|
4
4
|
[key: string]: TransformedContentValue;
|
|
5
5
|
} | undefined | ((quantity: number) => TransformedContentValue);
|
|
6
6
|
export type TransformedContentObject = {
|
|
7
|
-
|
|
7
|
+
dictionaryKey: string;
|
|
8
8
|
dictionaryPath: string;
|
|
9
9
|
keyPath: KeyPath[];
|
|
10
10
|
locale: Locales;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentDictionary.d.ts","sourceRoot":"","sources":["../../../src/processDictionary/contentDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,uBAAuB,GAC/B,MAAM,GACN,SAAS,GACT;IACE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAC;CACxC,GACD,SAAS,GACT,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,uBAAuB,CAAC,CAAC;AAEpD,MAAM,MAAM,wBAAwB,GAAG;IACrC,
|
|
1
|
+
{"version":3,"file":"contentDictionary.d.ts","sourceRoot":"","sources":["../../../src/processDictionary/contentDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,uBAAuB,GAC/B,MAAM,GACN,SAAS,GACT;IACE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAC;CACxC,GACD,SAAS,GACT,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,uBAAuB,CAAC,CAAC;AAEpD,MAAM,MAAM,wBAAwB,GAAG;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,uBAAuB,GAAG,uBAAuB,EAAE,GAAG,SAAS,CAAC;CAC1E,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC1B,MAAM,CACJ,MAAM,EACJ,uBAAuB,GACvB,uBAAuB,EAAE,GACzB,wBAAwB,GACxB,SAAS,CACZ,GACD,SAAS,CAAC"}
|