react-intlayer 1.2.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{ContentEditor/contentRender.cjs → client/ContentEditionLayout.cjs} +9 -14
- package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -0
- package/dist/cjs/client/ContentEditionLayout.d.ts +6 -0
- package/dist/cjs/client/IntlayerClientProvider.cjs +10 -1
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
- package/dist/cjs/client/useContent.d.ts +1 -2
- package/dist/cjs/getEnumeration.cjs +0 -4
- package/dist/cjs/getEnumeration.cjs.map +1 -1
- package/dist/cjs/getTranslation.cjs +0 -4
- package/dist/cjs/getTranslation.cjs.map +1 -1
- package/dist/cjs/processDictionary/{contentDictionary.d.cjs → contentDictionary.cjs} +3 -3
- package/dist/cjs/processDictionary/contentDictionary.cjs.map +1 -0
- package/dist/cjs/processDictionary/contentDictionary.d.ts +16 -0
- package/dist/cjs/processDictionary/index.cjs +88 -23
- package/dist/cjs/processDictionary/index.cjs.map +1 -1
- package/dist/cjs/processDictionary/index.d.ts +5 -4
- package/dist/cjs/useIntlayerBase.cjs +3 -0
- package/dist/cjs/useIntlayerBase.cjs.map +1 -1
- package/dist/cjs/vite/intlayerPlugin.cjs +1 -1
- package/dist/cjs/vite/intlayerPlugin.cjs.map +1 -1
- package/dist/esm/client/ContentEditionLayout.d.mts +6 -0
- package/dist/esm/client/ContentEditionLayout.mjs +11 -0
- package/dist/esm/client/ContentEditionLayout.mjs.map +1 -0
- package/dist/esm/client/IntlayerClientProvider.mjs +10 -1
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
- package/dist/esm/client/useContent.d.mts +1 -2
- package/dist/esm/getEnumeration.mjs +0 -4
- package/dist/esm/getEnumeration.mjs.map +1 -1
- package/dist/esm/getTranslation.mjs +0 -4
- package/dist/esm/getTranslation.mjs.map +1 -1
- package/dist/esm/processDictionary/contentDictionary.d.mts +16 -0
- package/dist/esm/processDictionary/contentDictionary.mjs +1 -0
- package/dist/esm/processDictionary/index.d.mts +5 -4
- package/dist/esm/processDictionary/index.mjs +90 -24
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/esm/useIntlayerBase.mjs +3 -0
- package/dist/esm/useIntlayerBase.mjs.map +1 -1
- package/dist/esm/vite/intlayerPlugin.mjs +1 -1
- package/dist/esm/vite/intlayerPlugin.mjs.map +1 -1
- package/package.json +14 -8
- package/src/client/ContentEditionLayout.tsx +15 -0
- package/src/client/IntlayerClientProvider.tsx +8 -1
- package/src/getEnumeration.ts +0 -5
- package/src/getTranslation.ts +0 -5
- package/src/processDictionary/{contentDictionary.d.ts → contentDictionary.ts} +6 -5
- package/src/processDictionary/index.ts +111 -24
- package/src/useIntlayerBase.ts +3 -0
- package/src/vite/intlayerPlugin.ts +1 -1
- package/dist/cjs/ContentEditor/ContentEditor.cjs +0 -110
- package/dist/cjs/ContentEditor/ContentEditor.cjs.map +0 -1
- package/dist/cjs/ContentEditor/ContentEditor.d.ts +0 -8
- package/dist/cjs/ContentEditor/contentRender.cjs.map +0 -1
- package/dist/cjs/ContentEditor/contentRender.d.ts +0 -3
- package/dist/cjs/ContentEditor/index.cjs +0 -25
- package/dist/cjs/ContentEditor/index.cjs.map +0 -1
- package/dist/cjs/ContentEditor/index.d.ts +0 -3
- package/dist/cjs/processDictionary/contentDictionary.d.cjs.map +0 -1
- package/dist/cjs/processDictionary/contentDictionary.d.d.ts +0 -29
- package/dist/esm/ContentEditor/ContentEditor.d.mts +0 -8
- package/dist/esm/ContentEditor/ContentEditor.mjs +0 -92
- package/dist/esm/ContentEditor/ContentEditor.mjs.map +0 -1
- package/dist/esm/ContentEditor/contentRender.d.mts +0 -3
- package/dist/esm/ContentEditor/contentRender.mjs +0 -14
- package/dist/esm/ContentEditor/contentRender.mjs.map +0 -1
- package/dist/esm/ContentEditor/index.d.mts +0 -3
- package/dist/esm/ContentEditor/index.mjs +0 -3
- package/dist/esm/ContentEditor/index.mjs.map +0 -1
- package/dist/esm/processDictionary/contentDictionary.d.d.mts +0 -29
- package/dist/esm/processDictionary/contentDictionary.d.mjs +0 -1
- package/src/ContentEditor/ContentEditor.tsx +0 -116
- package/src/ContentEditor/contentRender.tsx +0 -11
- package/src/ContentEditor/index.tsx +0 -2
- /package/dist/esm/processDictionary/{contentDictionary.d.mjs.map → contentDictionary.mjs.map} +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Locales } from '@intlayer/config/client';
|
|
2
|
-
import {
|
|
3
|
-
import '
|
|
2
|
+
import { KeyPath } from '@intlayer/core';
|
|
3
|
+
import { ContentValue, TransformedContentValue, Content, TransformedContent } from './contentDictionary.mjs';
|
|
4
|
+
import 'react';
|
|
4
5
|
|
|
5
|
-
declare const processNode: (field: ContentValue | undefined, locale: Locales) => TransformedContentValue;
|
|
6
|
+
declare const processNode: (field: ContentValue | undefined, locale: Locales, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[]) => TransformedContentValue;
|
|
6
7
|
/**
|
|
7
8
|
* Function that process a dictionary and return the result to be used in the application.
|
|
8
9
|
*/
|
|
9
|
-
declare const processDictionary: (content: Content, locale?: Locales) => TransformedContent;
|
|
10
|
+
declare const processDictionary: (content: Content, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[], locale?: Locales) => TransformedContent;
|
|
10
11
|
|
|
11
12
|
export { processDictionary, processNode };
|
|
@@ -1,46 +1,85 @@
|
|
|
1
1
|
import "../chunk-ZNCO4QRF.mjs";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config/client";
|
|
3
3
|
import {
|
|
4
|
-
NodeType
|
|
4
|
+
NodeType,
|
|
5
|
+
findMatchingCondition
|
|
5
6
|
} from "@intlayer/core";
|
|
7
|
+
import { renderContentEditor } from "intlayer-editor/client";
|
|
6
8
|
import { createElement } from "react";
|
|
7
9
|
import { getEnumeration } from '../getEnumeration.mjs';
|
|
8
10
|
import { getTranslation } from '../getTranslation.mjs';
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
+
const {
|
|
12
|
+
internationalization: { defaultLocale }
|
|
13
|
+
} = getConfiguration();
|
|
14
|
+
const processTranslation = (languageContent, locale, dictionaryId, dictionaryPath, keyPath = []) => {
|
|
11
15
|
const translationResult = getTranslation(
|
|
12
16
|
languageContent,
|
|
13
17
|
locale
|
|
14
18
|
);
|
|
15
|
-
|
|
19
|
+
const resultKeyPath = [
|
|
20
|
+
...keyPath,
|
|
21
|
+
{ type: NodeType.Translation, key: locale }
|
|
22
|
+
];
|
|
23
|
+
return processDictionary(
|
|
24
|
+
translationResult,
|
|
25
|
+
dictionaryId,
|
|
26
|
+
dictionaryPath,
|
|
27
|
+
resultKeyPath,
|
|
28
|
+
locale
|
|
29
|
+
);
|
|
16
30
|
};
|
|
17
|
-
const processEnumeration = (enumerationContent, locale) => {
|
|
31
|
+
const processEnumeration = (enumerationContent, locale, dictionaryId, dictionaryPath, keyPath = []) => {
|
|
18
32
|
return (quantity) => {
|
|
19
33
|
const enumerationResult = getEnumeration(
|
|
20
34
|
enumerationContent,
|
|
21
35
|
quantity
|
|
22
36
|
);
|
|
23
|
-
|
|
37
|
+
const matchingCondition = findMatchingCondition(
|
|
38
|
+
enumerationContent,
|
|
39
|
+
quantity
|
|
40
|
+
);
|
|
41
|
+
const resultKeyPath = [
|
|
42
|
+
...keyPath,
|
|
43
|
+
{ type: NodeType.Enumeration, key: matchingCondition.toString() }
|
|
44
|
+
];
|
|
45
|
+
return processDictionary(
|
|
46
|
+
enumerationResult,
|
|
47
|
+
dictionaryId,
|
|
48
|
+
dictionaryPath,
|
|
49
|
+
resultKeyPath,
|
|
50
|
+
locale
|
|
51
|
+
);
|
|
24
52
|
};
|
|
25
53
|
};
|
|
26
54
|
const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined";
|
|
27
|
-
const processNode = (field, locale) => {
|
|
28
|
-
if (typeof field
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = []) => {
|
|
56
|
+
if (typeof field === "object") {
|
|
57
|
+
if (field.nodeType === NodeType.Translation) {
|
|
58
|
+
return processTranslation(
|
|
59
|
+
field,
|
|
60
|
+
locale,
|
|
61
|
+
dictionaryId,
|
|
62
|
+
dictionaryPath,
|
|
63
|
+
keyPath
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (field.nodeType === NodeType.Enumeration) {
|
|
67
|
+
return processEnumeration(
|
|
68
|
+
field,
|
|
69
|
+
locale,
|
|
70
|
+
dictionaryId,
|
|
71
|
+
dictionaryPath,
|
|
72
|
+
keyPath
|
|
73
|
+
);
|
|
74
|
+
}
|
|
42
75
|
}
|
|
43
|
-
return
|
|
76
|
+
return processDictionary(
|
|
77
|
+
field,
|
|
78
|
+
dictionaryId,
|
|
79
|
+
dictionaryPath,
|
|
80
|
+
keyPath,
|
|
81
|
+
locale
|
|
82
|
+
);
|
|
44
83
|
};
|
|
45
84
|
const createReactElement = (element) => {
|
|
46
85
|
if (typeof element === "string") {
|
|
@@ -67,7 +106,8 @@ const createReactElement = (element) => {
|
|
|
67
106
|
const { type, props } = fixedElement;
|
|
68
107
|
return createElement(type ?? "div", props, ...props.children);
|
|
69
108
|
};
|
|
70
|
-
const
|
|
109
|
+
const traceKeys = ["filePath", "id", "nodeType"];
|
|
110
|
+
const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [], locale = defaultLocale) => {
|
|
71
111
|
if (isReactNode(content)) {
|
|
72
112
|
return createReactElement(
|
|
73
113
|
content
|
|
@@ -77,10 +117,36 @@ const processDictionary = (content, locale = defaultLocale) => {
|
|
|
77
117
|
const result = {};
|
|
78
118
|
for (const key of Object.keys(content)) {
|
|
79
119
|
const field = content[key];
|
|
80
|
-
|
|
120
|
+
if (traceKeys.includes(key)) {
|
|
121
|
+
result[key] = field;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const resultKeyPath = [
|
|
125
|
+
...keyPath,
|
|
126
|
+
{ type: "ObjectExpression", key }
|
|
127
|
+
];
|
|
128
|
+
result[key] = processNode(
|
|
129
|
+
field,
|
|
130
|
+
locale,
|
|
131
|
+
dictionaryId,
|
|
132
|
+
dictionaryPath,
|
|
133
|
+
resultKeyPath
|
|
134
|
+
);
|
|
81
135
|
}
|
|
82
136
|
return result;
|
|
83
137
|
}
|
|
138
|
+
if (typeof content === "string") {
|
|
139
|
+
try {
|
|
140
|
+
return renderContentEditor(
|
|
141
|
+
content,
|
|
142
|
+
dictionaryId,
|
|
143
|
+
dictionaryPath,
|
|
144
|
+
keyPath
|
|
145
|
+
);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
return content;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
84
150
|
return content;
|
|
85
151
|
};
|
|
86
152
|
export {
|
|
@@ -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} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst { defaultLocale } = getConfiguration()
|
|
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} from '@intlayer/core';\nimport { renderContentEditor } from 'intlayer-editor/client';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<ContentValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: ContentValue = getTranslation<ContentValue>(\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 as Content,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration = (\n enumerationContent: QuantityContent<ContentValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n return (quantity: number): TransformedContentValue => {\n const enumerationResult: ContentValue = getEnumeration<ContentValue>(\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 //\n return processDictionary(\n enumerationResult as Content,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n };\n};\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: ContentValue | undefined,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (field.nodeType === NodeType.Translation) {\n return processTranslation(\n field as LanguageContent<ContentValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n\n if (field.nodeType === NodeType.Enumeration) {\n return processEnumeration(\n field satisfies QuantityContent<ContentValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n field as Content,\n dictionaryId,\n dictionaryPath,\n keyPath,\n locale\n );\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n // Destructure the component properties\n\n const convertChildrenAsArray = (element: ReactElement): ReactElement => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children).forEach((key) => {\n childrenResult.push(createReactElement(children[key]));\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(element);\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(type ?? 'div', props, ...props.children);\n};\n\nconst traceKeys: string[] = ['filePath', 'id', '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: Content,\n dictionaryId: 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)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const result: TransformedContent = {};\n\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ObjectExpression', key },\n ];\n\n result[key] = processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n }\n\n return result;\n }\n\n if (typeof content === 'string') {\n try {\n // renderContentEditor come from intlayer-editor, which is an optional dependency.\n // intlayer-editor should be installed in the project to use the content editor.\n return renderContentEditor(\n content,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n } catch (e) {\n // If renderContentEditor not available, it will return the content as is.\n return content;\n }\n }\n\n // If it's a string, number, or function, return it\n return content;\n};\n"],"mappings":"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","names":["element"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Content } from './processDictionary/contentDictionary';\nimport { processDictionary } from './processDictionary/index';\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\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\nexport type UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => IntlayerDictionaryTypesConnector[T];\n\n/**\n * Hook that picking one dictionary by its id and return the content.\n */\nexport const useIntlayerBase: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const dictionary: Content = dictionaries[id];\n\n return processDictionary(\n dictionary,\n locale\n ) as IntlayerDictionaryTypesConnector[T];\n};\n"],"mappings":";AAMA,OAAO,kBAAkB;AAGzB,SAAS,yBAAyB;AAe3B,MAAM,kBAA+B,CAC1C,IACA,WACG;AACH,QAAM,aAAsB,aAAa,EAAE;AAE3C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Content } from './processDictionary/contentDictionary';\nimport { processDictionary } from './processDictionary/index';\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\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\nexport type UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => IntlayerDictionaryTypesConnector[T];\n\n/**\n * Hook that picking one dictionary by its id and return the content.\n */\nexport const useIntlayerBase: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const dictionary: Content = dictionaries[id];\n\n return processDictionary(\n dictionary,\n id,\n dictionary.filePath as string,\n [],\n locale\n ) as IntlayerDictionaryTypesConnector[T];\n};\n"],"mappings":";AAMA,OAAO,kBAAkB;AAGzB,SAAS,yBAAyB;AAe3B,MAAM,kBAA+B,CAC1C,IACA,WACG;AACH,QAAM,aAAsB,aAAa,EAAE;AAE3C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/intlayerPlugin.ts"],"sourcesContent":["import { join, relative, resolve } from 'path';\nimport { watch } from '@intlayer/chokidar';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { loadEnv, type Plugin } from 'vite';\n\n// Plugin options type definition\ntype PluginOptions = {\n // Custom options for your plugin, if any\n};\n\n/**\n *\n * A Vite plugin that integrates IntLayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intLayerPlugin() ],\n * });\n * ```\n * */\nexport const intLayerPlugin = (_pluginOptions: PluginOptions = {}): Plugin => ({\n name: 'vite-intlayer-plugin',\n\n config: (config, { mode }) => {\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('vite');\n\n process.env = { ...process.env, ...loadEnv(mode, process.cwd()), ...env };\n\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n },\n };\n\n return config;\n },\n\n buildStart: () => {\n // Code to run when Vite build starts\n watch({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n persistent: (import.meta as any).env === 'development',\n });\n },\n configureServer: (
|
|
1
|
+
{"version":3,"sources":["../../../src/vite/intlayerPlugin.ts"],"sourcesContent":["import { join, relative, resolve } from 'path';\nimport { watch } from '@intlayer/chokidar';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { loadEnv, type Plugin } from 'vite';\n\n// Plugin options type definition\ntype PluginOptions = {\n // Custom options for your plugin, if any\n};\n\n/**\n *\n * A Vite plugin that integrates IntLayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intLayerPlugin() ],\n * });\n * ```\n * */\nexport const intLayerPlugin = (_pluginOptions: PluginOptions = {}): Plugin => ({\n name: 'vite-intlayer-plugin',\n\n config: (config, { mode }) => {\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('vite');\n\n process.env = { ...process.env, ...loadEnv(mode, process.cwd()), ...env };\n\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n },\n };\n\n return config;\n },\n\n buildStart: () => {\n // Code to run when Vite build starts\n watch({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n persistent: (import.meta as any).env === 'development',\n });\n },\n configureServer: () => {\n // Custom server configuration, if needed\n },\n});\n"],"mappings":";AAAA,SAAS,MAAM,UAAU,eAAe;AACxC,SAAS,aAAa;AACtB,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,eAA4B;AAkB9B,MAAM,iBAAiB,CAAC,iBAAgC,CAAC,OAAe;AAAA,EAC7E,MAAM;AAAA,EAEN,QAAQ,CAAC,QAAQ,EAAE,KAAK,MAAM;AAC5B,UAAM,iBAAiB,iBAAiB;AAGxC,UAAM,MAAM,kBAAkB,MAAM;AAEpC,YAAQ,MAAM,EAAE,GAAG,QAAQ,KAAK,GAAG,QAAQ,MAAM,QAAQ,IAAI,CAAC,GAAG,GAAG,IAAI;AAExE,UAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAC5C,UAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,UAAM,2BAA2B,SAAS,SAAS,gBAAgB;AAGnE,WAAO,UAAU;AAAA,MACf,GAAG,OAAO;AAAA,MACV,OAAO;AAAA,QACL,GAAG,OAAO,SAAS;AAAA,QACnB,gCAAgC,QAAQ,wBAAwB;AAAA,MAClE;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,MAAM;AAEhB,UAAM;AAAA;AAAA,MAEJ,YAAa,YAAoB,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AAAA,EACA,iBAAiB,MAAM;AAAA,EAEvB;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Internationalization layer for React applications - Layer of abstraction between the business logic and the data access layer. Manage internationalization in a simple way, through TypeScript, JavaScript or JSON declaration file.",
|
|
6
6
|
"keywords": [
|
|
@@ -76,12 +76,12 @@
|
|
|
76
76
|
"react-cookie": "^7.1.4",
|
|
77
77
|
"vite": "^5.2.0",
|
|
78
78
|
"webpack": "^5.91.0",
|
|
79
|
-
"@intlayer/chokidar": "^
|
|
80
|
-
"@intlayer/
|
|
81
|
-
"@intlayer/
|
|
82
|
-
"@intlayer/
|
|
83
|
-
"@intlayer/
|
|
84
|
-
"intlayer": "^
|
|
79
|
+
"@intlayer/chokidar": "^2.0.0",
|
|
80
|
+
"@intlayer/core": "^2.0.0",
|
|
81
|
+
"@intlayer/config": "^2.0.0",
|
|
82
|
+
"@intlayer/webpack": "^2.0.0",
|
|
83
|
+
"@intlayer/dictionaries-entry": "^2.0.0",
|
|
84
|
+
"intlayer": "^2.0.0"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@craco/types": "^7.1.0",
|
|
@@ -99,7 +99,13 @@
|
|
|
99
99
|
},
|
|
100
100
|
"peerDependencies": {
|
|
101
101
|
"react": "^18.2.0",
|
|
102
|
-
"react-dom": "^18.2.0"
|
|
102
|
+
"react-dom": "^18.2.0",
|
|
103
|
+
"intlayer-editor": "^2.0.0"
|
|
104
|
+
},
|
|
105
|
+
"peerDependenciesMeta": {
|
|
106
|
+
"intlayer-editor": {
|
|
107
|
+
"optional": true
|
|
108
|
+
}
|
|
103
109
|
},
|
|
104
110
|
"engines": {
|
|
105
111
|
"node": ">=14.18"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContentEditionLayout as ContentEditionLayoutBase,
|
|
3
|
+
type ContentEditionLayoutProps,
|
|
4
|
+
} from 'intlayer-editor/client';
|
|
5
|
+
import type { FC } from 'react';
|
|
6
|
+
|
|
7
|
+
const BlankLayout: FC<ContentEditionLayoutProps> = ({ children }) => (
|
|
8
|
+
<>{children}</>
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
// intlayer-editor is an optional dependency. If it's not installed, return the blank layout
|
|
12
|
+
export const ContentEditionLayout: FC<ContentEditionLayoutProps> =
|
|
13
|
+
typeof ContentEditionLayoutBase === 'undefined'
|
|
14
|
+
? BlankLayout
|
|
15
|
+
: (ContentEditionLayoutBase as typeof ContentEditionLayout);
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
useState,
|
|
11
11
|
useCallback,
|
|
12
12
|
} from 'react';
|
|
13
|
+
import { ContentEditionLayout } from './ContentEditionLayout';
|
|
13
14
|
import { localeCookie, setLocaleCookie } from './useLocaleCookie';
|
|
14
15
|
|
|
15
16
|
type IntlayerValue = {
|
|
@@ -70,7 +71,13 @@ export const IntlayerClientProvider: FC<IntlayerClientProviderProps> = ({
|
|
|
70
71
|
|
|
71
72
|
return (
|
|
72
73
|
<IntlayerClientContext.Provider value={value}>
|
|
73
|
-
|
|
74
|
+
<ContentEditionLayout
|
|
75
|
+
locale={currentLocale}
|
|
76
|
+
setLocale={setLocale}
|
|
77
|
+
localeList={availableLocales}
|
|
78
|
+
>
|
|
79
|
+
{children}
|
|
80
|
+
</ContentEditionLayout>
|
|
74
81
|
</IntlayerClientContext.Provider>
|
|
75
82
|
);
|
|
76
83
|
};
|
package/src/getEnumeration.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type QuantityContent, getEnumerationContent } from '@intlayer/core';
|
|
2
|
-
import { contentRender } from './ContentEditor/contentRender';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Allow to pick a content based on a quantity.
|
|
@@ -38,9 +37,5 @@ export const getEnumeration = <Content>(
|
|
|
38
37
|
quantity
|
|
39
38
|
);
|
|
40
39
|
|
|
41
|
-
if (typeof result === 'string') {
|
|
42
|
-
return contentRender(result) as Content;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
40
|
return result;
|
|
46
41
|
};
|
package/src/getTranslation.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type Locales, getConfiguration } from '@intlayer/config/client';
|
|
2
2
|
import { type LanguageContent, getTranslationContent } from '@intlayer/core';
|
|
3
|
-
import { contentRender } from './ContentEditor/contentRender';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
*
|
|
@@ -34,9 +33,5 @@ export const getTranslation = <Content = string>(
|
|
|
34
33
|
locale ?? defaultLocale
|
|
35
34
|
);
|
|
36
35
|
|
|
37
|
-
if (typeof result === 'string') {
|
|
38
|
-
return contentRender(result) as Content;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
36
|
return result;
|
|
42
37
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TranslationContent } from '@intlayer/core';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
2
3
|
|
|
3
4
|
export type ContentValue =
|
|
4
5
|
| string
|
|
@@ -11,16 +12,16 @@ export type Content = Record<string, ContentValue | undefined>;
|
|
|
11
12
|
|
|
12
13
|
export type TransformedContentValue =
|
|
13
14
|
| string
|
|
15
|
+
| ReactNode
|
|
14
16
|
| {
|
|
15
17
|
[key: string]: TransformedContentValue;
|
|
16
18
|
}
|
|
17
19
|
| undefined
|
|
18
20
|
| ((quantity: number) => TransformedContentValue);
|
|
19
21
|
|
|
20
|
-
export type TransformedContent =
|
|
21
|
-
string,
|
|
22
|
-
|
|
23
|
-
>;
|
|
22
|
+
export type TransformedContent =
|
|
23
|
+
| Record<string, TransformedContentValue | undefined>
|
|
24
|
+
| ReactNode;
|
|
24
25
|
|
|
25
26
|
export type ContentDictionary = Content & {
|
|
26
27
|
id: string;
|
|
@@ -4,7 +4,10 @@ import {
|
|
|
4
4
|
NodeType,
|
|
5
5
|
type QuantityContent,
|
|
6
6
|
type LanguageContent,
|
|
7
|
+
findMatchingCondition,
|
|
8
|
+
type KeyPath,
|
|
7
9
|
} from '@intlayer/core';
|
|
10
|
+
import { renderContentEditor } from 'intlayer-editor/client';
|
|
8
11
|
import { type ReactElement, createElement, type ReactNode } from 'react';
|
|
9
12
|
import { getEnumeration } from '../getEnumeration';
|
|
10
13
|
import { getTranslation } from '../getTranslation';
|
|
@@ -15,23 +18,42 @@ import type {
|
|
|
15
18
|
TransformedContentValue,
|
|
16
19
|
} from './contentDictionary';
|
|
17
20
|
|
|
18
|
-
const {
|
|
21
|
+
const {
|
|
22
|
+
internationalization: { defaultLocale },
|
|
23
|
+
} = getConfiguration();
|
|
19
24
|
|
|
20
25
|
const processTranslation = (
|
|
21
26
|
languageContent: LanguageContent<ContentValue>,
|
|
22
|
-
locale: Locales
|
|
27
|
+
locale: Locales,
|
|
28
|
+
dictionaryId: string,
|
|
29
|
+
dictionaryPath: string,
|
|
30
|
+
keyPath: KeyPath[] = []
|
|
23
31
|
): TransformedContent => {
|
|
24
32
|
const translationResult: ContentValue = getTranslation<ContentValue>(
|
|
25
33
|
languageContent,
|
|
26
34
|
locale
|
|
27
35
|
);
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
const resultKeyPath: KeyPath[] = [
|
|
38
|
+
...keyPath,
|
|
39
|
+
{ type: NodeType.Translation, key: locale },
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
return processDictionary(
|
|
43
|
+
translationResult as Content,
|
|
44
|
+
dictionaryId,
|
|
45
|
+
dictionaryPath,
|
|
46
|
+
resultKeyPath,
|
|
47
|
+
locale
|
|
48
|
+
);
|
|
30
49
|
};
|
|
31
50
|
|
|
32
51
|
const processEnumeration = (
|
|
33
52
|
enumerationContent: QuantityContent<ContentValue>,
|
|
34
|
-
locale: Locales
|
|
53
|
+
locale: Locales,
|
|
54
|
+
dictionaryId: string,
|
|
55
|
+
dictionaryPath: string,
|
|
56
|
+
keyPath: KeyPath[] = []
|
|
35
57
|
): TransformedContentValue => {
|
|
36
58
|
return (quantity: number): TransformedContentValue => {
|
|
37
59
|
const enumerationResult: ContentValue = getEnumeration<ContentValue>(
|
|
@@ -39,8 +61,24 @@ const processEnumeration = (
|
|
|
39
61
|
quantity
|
|
40
62
|
);
|
|
41
63
|
|
|
64
|
+
const matchingCondition = findMatchingCondition(
|
|
65
|
+
enumerationContent,
|
|
66
|
+
quantity
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const resultKeyPath: KeyPath[] = [
|
|
70
|
+
...keyPath,
|
|
71
|
+
{ type: NodeType.Enumeration, key: matchingCondition.toString() },
|
|
72
|
+
];
|
|
73
|
+
|
|
42
74
|
//
|
|
43
|
-
return processDictionary(
|
|
75
|
+
return processDictionary(
|
|
76
|
+
enumerationResult as Content,
|
|
77
|
+
dictionaryId,
|
|
78
|
+
dictionaryPath,
|
|
79
|
+
resultKeyPath,
|
|
80
|
+
locale
|
|
81
|
+
);
|
|
44
82
|
};
|
|
45
83
|
};
|
|
46
84
|
|
|
@@ -49,28 +87,40 @@ const isReactNode = (node: Record<string, unknown>): boolean =>
|
|
|
49
87
|
|
|
50
88
|
export const processNode = (
|
|
51
89
|
field: ContentValue | undefined,
|
|
52
|
-
locale: Locales
|
|
90
|
+
locale: Locales,
|
|
91
|
+
dictionaryId: string,
|
|
92
|
+
dictionaryPath: string,
|
|
93
|
+
keyPath: KeyPath[] = []
|
|
53
94
|
): TransformedContentValue => {
|
|
54
|
-
if (typeof field
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
field satisfies QuantityContent<ContentValue>,
|
|
65
|
-
locale
|
|
66
|
-
);
|
|
67
|
-
}
|
|
95
|
+
if (typeof field === 'object') {
|
|
96
|
+
if (field.nodeType === NodeType.Translation) {
|
|
97
|
+
return processTranslation(
|
|
98
|
+
field as LanguageContent<ContentValue>,
|
|
99
|
+
locale,
|
|
100
|
+
dictionaryId,
|
|
101
|
+
dictionaryPath,
|
|
102
|
+
keyPath
|
|
103
|
+
);
|
|
104
|
+
}
|
|
68
105
|
|
|
69
|
-
|
|
70
|
-
|
|
106
|
+
if (field.nodeType === NodeType.Enumeration) {
|
|
107
|
+
return processEnumeration(
|
|
108
|
+
field satisfies QuantityContent<ContentValue>,
|
|
109
|
+
locale,
|
|
110
|
+
dictionaryId,
|
|
111
|
+
dictionaryPath,
|
|
112
|
+
keyPath
|
|
113
|
+
);
|
|
114
|
+
}
|
|
71
115
|
}
|
|
72
116
|
|
|
73
|
-
return
|
|
117
|
+
return processDictionary(
|
|
118
|
+
field as Content,
|
|
119
|
+
dictionaryId,
|
|
120
|
+
dictionaryPath,
|
|
121
|
+
keyPath,
|
|
122
|
+
locale
|
|
123
|
+
);
|
|
74
124
|
};
|
|
75
125
|
|
|
76
126
|
// This function recursively creates React elements from a given JSON-like structure
|
|
@@ -112,11 +162,16 @@ const createReactElement = (element: ReactElement) => {
|
|
|
112
162
|
return createElement(type ?? 'div', props, ...props.children);
|
|
113
163
|
};
|
|
114
164
|
|
|
165
|
+
const traceKeys: string[] = ['filePath', 'id', 'nodeType'];
|
|
166
|
+
|
|
115
167
|
/**
|
|
116
168
|
* Function that process a dictionary and return the result to be used in the application.
|
|
117
169
|
*/
|
|
118
170
|
export const processDictionary = (
|
|
119
171
|
content: Content,
|
|
172
|
+
dictionaryId: string,
|
|
173
|
+
dictionaryPath: string,
|
|
174
|
+
keyPath: KeyPath[] = [],
|
|
120
175
|
locale: Locales = defaultLocale
|
|
121
176
|
): TransformedContent => {
|
|
122
177
|
// If it's a React element, render it
|
|
@@ -133,12 +188,44 @@ export const processDictionary = (
|
|
|
133
188
|
for (const key of Object.keys(content)) {
|
|
134
189
|
const field = content[key];
|
|
135
190
|
|
|
136
|
-
|
|
191
|
+
if (traceKeys.includes(key)) {
|
|
192
|
+
result[key] = field as TransformedContentValue;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const resultKeyPath: KeyPath[] = [
|
|
197
|
+
...keyPath,
|
|
198
|
+
{ type: 'ObjectExpression', key },
|
|
199
|
+
];
|
|
200
|
+
|
|
201
|
+
result[key] = processNode(
|
|
202
|
+
field,
|
|
203
|
+
locale,
|
|
204
|
+
dictionaryId,
|
|
205
|
+
dictionaryPath,
|
|
206
|
+
resultKeyPath
|
|
207
|
+
);
|
|
137
208
|
}
|
|
138
209
|
|
|
139
210
|
return result;
|
|
140
211
|
}
|
|
141
212
|
|
|
213
|
+
if (typeof content === 'string') {
|
|
214
|
+
try {
|
|
215
|
+
// renderContentEditor come from intlayer-editor, which is an optional dependency.
|
|
216
|
+
// intlayer-editor should be installed in the project to use the content editor.
|
|
217
|
+
return renderContentEditor(
|
|
218
|
+
content,
|
|
219
|
+
dictionaryId,
|
|
220
|
+
dictionaryPath,
|
|
221
|
+
keyPath
|
|
222
|
+
);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
// If renderContentEditor not available, it will return the content as is.
|
|
225
|
+
return content;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
142
229
|
// If it's a string, number, or function, return it
|
|
143
230
|
return content;
|
|
144
231
|
};
|
package/src/useIntlayerBase.ts
CHANGED
|
@@ -53,7 +53,7 @@ export const intLayerPlugin = (_pluginOptions: PluginOptions = {}): Plugin => ({
|
|
|
53
53
|
persistent: (import.meta as any).env === 'development',
|
|
54
54
|
});
|
|
55
55
|
},
|
|
56
|
-
configureServer: (
|
|
56
|
+
configureServer: () => {
|
|
57
57
|
// Custom server configuration, if needed
|
|
58
58
|
},
|
|
59
59
|
});
|