gt-react 2.0.120
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 +7 -0
- package/dist/client/ClientProvider.d.ts +11 -0
- package/dist/client/ClientProvider.d.ts.map +1 -0
- package/dist/client/ClientProvider.js +17 -0
- package/dist/client/ClientProvider.js.map +1 -0
- package/dist/client/GTProvider.d.ts +12 -0
- package/dist/client/GTProvider.d.ts.map +1 -0
- package/dist/client/GTProvider.js +56 -0
- package/dist/client/GTProvider.js.map +1 -0
- package/dist/client/t.d.ts +2 -0
- package/dist/client/t.d.ts.map +1 -0
- package/dist/client/t.js +14 -0
- package/dist/client/t.js.map +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +17 -0
- package/dist/client.js.map +1 -0
- package/dist/config/I18NConfig.d.ts +90 -0
- package/dist/config/I18NConfig.d.ts.map +1 -0
- package/dist/config/I18NConfig.js +219 -0
- package/dist/config/I18NConfig.js.map +1 -0
- package/dist/config/PageManager.d.ts +16 -0
- package/dist/config/PageManager.d.ts.map +1 -0
- package/dist/config/PageManager.js +66 -0
- package/dist/config/PageManager.js.map +1 -0
- package/dist/config/local/getConfigData.d.ts +8 -0
- package/dist/config/local/getConfigData.d.ts.map +1 -0
- package/dist/config/local/getConfigData.js +29 -0
- package/dist/config/local/getConfigData.js.map +1 -0
- package/dist/config/local/getDefaultFromEnv.d.ts +12 -0
- package/dist/config/local/getDefaultFromEnv.d.ts.map +1 -0
- package/dist/config/local/getDefaultFromEnv.js +21 -0
- package/dist/config/local/getDefaultFromEnv.js.map +1 -0
- package/dist/config/local/getI18NPage.d.ts +10 -0
- package/dist/config/local/getI18NPage.d.ts.map +1 -0
- package/dist/config/local/getI18NPage.js +34 -0
- package/dist/config/local/getI18NPage.js.map +1 -0
- package/dist/config/placeholderCache.d.ts +8 -0
- package/dist/config/placeholderCache.d.ts.map +1 -0
- package/dist/config/placeholderCache.js +71 -0
- package/dist/config/placeholderCache.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/intl/intl.d.ts +14 -0
- package/dist/intl/intl.d.ts.map +1 -0
- package/dist/intl/intl.js +38 -0
- package/dist/intl/intl.js.map +1 -0
- package/dist/next/NextGTProvider.d.ts +15 -0
- package/dist/next/NextGTProvider.d.ts.map +1 -0
- package/dist/next/NextGTProvider.js +48 -0
- package/dist/next/NextGTProvider.js.map +1 -0
- package/dist/next/NextI18N.d.ts +15 -0
- package/dist/next/NextI18N.d.ts.map +1 -0
- package/dist/next/NextI18N.js +48 -0
- package/dist/next/NextI18N.js.map +1 -0
- package/dist/next/headerFunctions.d.ts +21 -0
- package/dist/next/headerFunctions.d.ts.map +1 -0
- package/dist/next/headerFunctions.js +77 -0
- package/dist/next/headerFunctions.js.map +1 -0
- package/dist/next/intl.d.ts +8 -0
- package/dist/next/intl.d.ts.map +1 -0
- package/dist/next/intl.js +47 -0
- package/dist/next/intl.js.map +1 -0
- package/dist/next.d.ts +9 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +21 -0
- package/dist/next.js.map +1 -0
- package/dist/primitives/numeric/Numeric.d.ts +23 -0
- package/dist/primitives/numeric/Numeric.d.ts.map +1 -0
- package/dist/primitives/numeric/Numeric.js +42 -0
- package/dist/primitives/numeric/Numeric.js.map +1 -0
- package/dist/primitives/numeric/client/ClientNumeric.d.ts +23 -0
- package/dist/primitives/numeric/client/ClientNumeric.d.ts.map +1 -0
- package/dist/primitives/numeric/client/ClientNumeric.js +43 -0
- package/dist/primitives/numeric/client/ClientNumeric.js.map +1 -0
- package/dist/primitives/numeric/getNumericBranch.d.ts +14 -0
- package/dist/primitives/numeric/getNumericBranch.d.ts.map +1 -0
- package/dist/primitives/numeric/getNumericBranch.js +84 -0
- package/dist/primitives/numeric/getNumericBranch.js.map +1 -0
- package/dist/primitives/private/Private.d.ts +19 -0
- package/dist/primitives/private/Private.d.ts.map +1 -0
- package/dist/primitives/private/Private.js +29 -0
- package/dist/primitives/private/Private.js.map +1 -0
- package/dist/primitives/value/Value.d.ts +21 -0
- package/dist/primitives/value/Value.d.ts.map +1 -0
- package/dist/primitives/value/Value.js +42 -0
- package/dist/primitives/value/Value.js.map +1 -0
- package/dist/primitives/value/client/ClientValue.d.ts +21 -0
- package/dist/primitives/value/client/ClientValue.d.ts.map +1 -0
- package/dist/primitives/value/client/ClientValue.js +43 -0
- package/dist/primitives/value/client/ClientValue.js.map +1 -0
- package/dist/primitives/value/client/renderClientVariable.d.ts +9 -0
- package/dist/primitives/value/client/renderClientVariable.d.ts.map +1 -0
- package/dist/primitives/value/client/renderClientVariable.js +60 -0
- package/dist/primitives/value/client/renderClientVariable.js.map +1 -0
- package/dist/primitives/value/getValueBranch.d.ts +9 -0
- package/dist/primitives/value/getValueBranch.d.ts.map +1 -0
- package/dist/primitives/value/getValueBranch.js +64 -0
- package/dist/primitives/value/getValueBranch.js.map +1 -0
- package/dist/primitives/value/isValidReactNode.d.ts +15 -0
- package/dist/primitives/value/isValidReactNode.d.ts.map +1 -0
- package/dist/primitives/value/isValidReactNode.js +27 -0
- package/dist/primitives/value/isValidReactNode.js.map +1 -0
- package/dist/primitives/value/processBranches.d.ts +9 -0
- package/dist/primitives/value/processBranches.d.ts.map +1 -0
- package/dist/primitives/value/processBranches.js +44 -0
- package/dist/primitives/value/processBranches.js.map +1 -0
- package/dist/primitives/value/renderVariable.d.ts +8 -0
- package/dist/primitives/value/renderVariable.d.ts.map +1 -0
- package/dist/primitives/value/renderVariable.js +57 -0
- package/dist/primitives/value/renderVariable.js.map +1 -0
- package/dist/primitives/variable/Variable.d.ts +13 -0
- package/dist/primitives/variable/Variable.d.ts.map +1 -0
- package/dist/primitives/variable/Variable.js +24 -0
- package/dist/primitives/variable/Variable.js.map +1 -0
- package/dist/server/ServerI18N.d.ts +18 -0
- package/dist/server/ServerI18N.d.ts.map +1 -0
- package/dist/server/ServerI18N.js +81 -0
- package/dist/server/ServerI18N.js.map +1 -0
- package/dist/server/helpers/addGTIdentifier.d.ts +11 -0
- package/dist/server/helpers/addGTIdentifier.d.ts.map +1 -0
- package/dist/server/helpers/addGTIdentifier.js +152 -0
- package/dist/server/helpers/addGTIdentifier.js.map +1 -0
- package/dist/server/helpers/generateHash.d.ts +12 -0
- package/dist/server/helpers/generateHash.d.ts.map +1 -0
- package/dist/server/helpers/generateHash.js +34 -0
- package/dist/server/helpers/generateHash.js.map +1 -0
- package/dist/server/helpers/writeChildrenAsObjects.d.ts +11 -0
- package/dist/server/helpers/writeChildrenAsObjects.d.ts.map +1 -0
- package/dist/server/helpers/writeChildrenAsObjects.js +129 -0
- package/dist/server/helpers/writeChildrenAsObjects.js.map +1 -0
- package/dist/server/renderChildren.d.ts +19 -0
- package/dist/server/renderChildren.d.ts.map +1 -0
- package/dist/server/renderChildren.js +153 -0
- package/dist/server/renderChildren.js.map +1 -0
- package/dist/server/resolvers/I18NResolver.d.ts +13 -0
- package/dist/server/resolvers/I18NResolver.d.ts.map +1 -0
- package/dist/server/resolvers/I18NResolver.js +41 -0
- package/dist/server/resolvers/I18NResolver.js.map +1 -0
- package/dist/server/resolvers/renderResolvedChildren.d.ts +19 -0
- package/dist/server/resolvers/renderResolvedChildren.d.ts.map +1 -0
- package/dist/server/resolvers/renderResolvedChildren.js +157 -0
- package/dist/server/resolvers/renderResolvedChildren.js.map +1 -0
- package/package.json +39 -0
- package/scratchpad.js +33 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.default = renderClientVariable;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const isValidReactNode_1 = __importDefault(require("../isValidReactNode"));
|
|
11
|
+
const Variable_1 = __importDefault(require("../../variable/Variable"));
|
|
12
|
+
/**
|
|
13
|
+
* Handles a single child element by cloning it with new properties if it is a valid React element,
|
|
14
|
+
* or wrapping it in a React Fragment if it is a valid React node object.
|
|
15
|
+
*
|
|
16
|
+
* @param {any} child - The child element to handle.
|
|
17
|
+
* @returns {any} The handled child element.
|
|
18
|
+
*/
|
|
19
|
+
const handleSingleChild = (child, variables) => {
|
|
20
|
+
var _a;
|
|
21
|
+
if (!react_1.default.isValidElement(child) && typeof child === 'object' && Object.keys(child).length === 1) {
|
|
22
|
+
const key = Object.keys(child)[0];
|
|
23
|
+
const value = child[key];
|
|
24
|
+
if ((typeof value !== 'undefined' && value !== null) && (0, isValidReactNode_1.default)(value)) {
|
|
25
|
+
return (0, jsx_runtime_1.jsx)(Variable_1.default, { defaultValue: value, name: key });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!child || typeof child === 'string' || typeof child === 'number' || typeof child === 'boolean')
|
|
29
|
+
return child;
|
|
30
|
+
child = (_a = react_1.default.Children.map(child, current => current)) === null || _a === void 0 ? void 0 : _a[0];
|
|
31
|
+
if (react_1.default.isValidElement(child)) {
|
|
32
|
+
const { props, type } = child;
|
|
33
|
+
if (variables && props['data-gt-variable-name']) {
|
|
34
|
+
const value = variables[props['data-gt-variable-name']];
|
|
35
|
+
if (value !== null && typeof value !== 'undefined') {
|
|
36
|
+
return (0, jsx_runtime_1.jsx)(Variable_1.default, { defaultValue: value, name: props['data-gt-variable-name'] });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let newProps = Object.assign({}, props);
|
|
40
|
+
if (props === null || props === void 0 ? void 0 : props.children) {
|
|
41
|
+
newProps.children = renderClientVariable(props.children, variables);
|
|
42
|
+
}
|
|
43
|
+
return react_1.default.cloneElement(child, newProps);
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
return child;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Recursively renders a variable structure of children, handling arrays of children and single child elements.
|
|
50
|
+
*
|
|
51
|
+
* @param {any} children - The children elements to render.
|
|
52
|
+
* @returns {any} The rendered children elements.
|
|
53
|
+
*/
|
|
54
|
+
function renderClientVariable(children, variables) {
|
|
55
|
+
if (Array.isArray(children))
|
|
56
|
+
return children.map((child, index) => (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: handleSingleChild(child, variables) }, index));
|
|
57
|
+
else
|
|
58
|
+
return handleSingleChild(children, variables);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=renderClientVariable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderClientVariable.js","sourceRoot":"","sources":["../../../../src/primitives/value/client/renderClientVariable.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAmDZ,uCAGC;;AApDD,kDAAwC;AACxC,2EAAmD;AACnD,uEAA+C;AAE/C;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAU,EAAE,SAA+B,EAAO,EAAE;;IAE3E,IAAI,CAAC,eAAK,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/F,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAClC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,OAAO,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,IAAI,CAAC,IAAI,IAAA,0BAAgB,EAAC,KAAK,CAAC,EAAE,CAAC;YAC9E,OAAO,uBAAC,kBAAQ,IAAC,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,GA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AAO,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,KAAa,EAAE,EAAE,CAAC,uBAAC,eAAK,CAAC,QAAQ,cAAc,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,IAA3C,KAAK,CAAwD,CAAC,CAAC;;QAC/J,OAAO,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;AACtD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively navigates through a branch object based on the provided values and returns the matched React node.
|
|
3
|
+
*
|
|
4
|
+
* @param {Record<string, any>} values - An object containing key-value pairs used to navigate through the branches.
|
|
5
|
+
* @param {Record<string, any>} branches - An object representing the branches to be navigated based on the values.
|
|
6
|
+
* @returns {any} - Returns the matched React node or undefined if no match is found.
|
|
7
|
+
*/
|
|
8
|
+
export default function getValueBranch(values: Record<string, any>, branches: Record<string, any>): any;
|
|
9
|
+
//# sourceMappingURL=getValueBranch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getValueBranch.d.ts","sourceRoot":"","sources":["../../../src/primitives/value/getValueBranch.ts"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,CA6BtG"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = getValueBranch;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const isValidReactNode_1 = __importDefault(require("./isValidReactNode"));
|
|
9
|
+
/*
|
|
10
|
+
{
|
|
11
|
+
"gender": {
|
|
12
|
+
"male": {
|
|
13
|
+
"VIP": {
|
|
14
|
+
"true": <>Customer name is {{name}}. He is a valued customer.</>,
|
|
15
|
+
"false": "He is a customer."
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"female": {
|
|
19
|
+
"VIP": {
|
|
20
|
+
"true": <>Customer name is {{name}}. She is a valued customer.</>,
|
|
21
|
+
"false": "She is a customer."
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"other": "They are a customer."
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Recursively navigates through a branch object based on the provided values and returns the matched React node.
|
|
30
|
+
*
|
|
31
|
+
* @param {Record<string, any>} values - An object containing key-value pairs used to navigate through the branches.
|
|
32
|
+
* @param {Record<string, any>} branches - An object representing the branches to be navigated based on the values.
|
|
33
|
+
* @returns {any} - Returns the matched React node or undefined if no match is found.
|
|
34
|
+
*/
|
|
35
|
+
function getValueBranch(values, branches) {
|
|
36
|
+
/**
|
|
37
|
+
* Handles the navigation through a given branch object.
|
|
38
|
+
*
|
|
39
|
+
* @param {any} branch - The current branch object to navigate.
|
|
40
|
+
* @returns {any} - Returns the matched React node or undefined if no match is found.
|
|
41
|
+
*/
|
|
42
|
+
const handleBranch = (branch) => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
for (const key of Object.keys(branch)) {
|
|
45
|
+
let value = values[key];
|
|
46
|
+
if (value) {
|
|
47
|
+
// we know branch[key] exists
|
|
48
|
+
if (branch[key][value]) {
|
|
49
|
+
if (typeof ((_b = (_a = branch[key][value].props) === null || _a === void 0 ? void 0 : _a['data-generaltranslation']) === null || _b === void 0 ? void 0 : _b.id) === 'number') {
|
|
50
|
+
return branch[key][value];
|
|
51
|
+
}
|
|
52
|
+
/* @ts-expect-error Lazy components are meant to return a promise */
|
|
53
|
+
if ((0, isValidReactNode_1.default)(branch[key][value]) || branch[key][value].$$typeof === react_1.default.lazy(() => { }).$$typeof) {
|
|
54
|
+
return branch[key][value];
|
|
55
|
+
}
|
|
56
|
+
return handleBranch(branch[key][value]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
// Start the recursive navigation from the root branches
|
|
62
|
+
return handleBranch(branches);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=getValueBranch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getValueBranch.js","sourceRoot":"","sources":["../../../src/primitives/value/getValueBranch.ts"],"names":[],"mappings":";;;;;AA8BA,iCA6BC;AA3DD,kDAA0B;AAC1B,0EAAkD;AAElD;;;;;;;;;;;;;;;;;;EAkBE;AAEF;;;;;;GAMG;AACH,SAAwB,cAAc,CAAC,MAA2B,EAAE,QAA6B;IAE7F;;;;;OAKG;IACH,MAAM,YAAY,GAAG,CAAC,MAAW,EAAO,EAAE;;QACtC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACpC,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YACxB,IAAI,KAAK,EAAE,CAAC;gBACR,6BAA6B;gBAC7B,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;oBACrB,IAAI,OAAO,CAAA,MAAA,MAAA,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,0CAAG,yBAAyB,CAAC,0CAAE,EAAE,CAAA,KAAK,QAAQ,EAAE,CAAC;wBAChF,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;oBAC9B,CAAC;oBACD,oEAAoE;oBACpE,IAAI,IAAA,0BAAgB,EAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,KAAK,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;wBACxG,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;oBAC9B,CAAC;oBACD,OAAO,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;gBAC3C,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC,CAAA;IAED,wDAAwD;IACxD,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to determine if a given node is a valid ReactNode. Excludes null and undefined nodes.
|
|
4
|
+
* A ReactNode can be:
|
|
5
|
+
* - string
|
|
6
|
+
* - number
|
|
7
|
+
* - boolean
|
|
8
|
+
* - a valid React element
|
|
9
|
+
* - an array of valid ReactNodes
|
|
10
|
+
*
|
|
11
|
+
* @param {any} node - The node to check.
|
|
12
|
+
* @returns {node is ReactNode} - True if the node is a valid ReactNode, false otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export default function isValidReactNode(node: any): node is ReactNode;
|
|
15
|
+
//# sourceMappingURL=isValidReactNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidReactNode.d.ts","sourceRoot":"","sources":["../../../src/primitives/value/isValidReactNode.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,SAAS,CAQrE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = isValidReactNode;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
/**
|
|
9
|
+
* Type guard to determine if a given node is a valid ReactNode. Excludes null and undefined nodes.
|
|
10
|
+
* A ReactNode can be:
|
|
11
|
+
* - string
|
|
12
|
+
* - number
|
|
13
|
+
* - boolean
|
|
14
|
+
* - a valid React element
|
|
15
|
+
* - an array of valid ReactNodes
|
|
16
|
+
*
|
|
17
|
+
* @param {any} node - The node to check.
|
|
18
|
+
* @returns {node is ReactNode} - True if the node is a valid ReactNode, false otherwise.
|
|
19
|
+
*/
|
|
20
|
+
function isValidReactNode(node) {
|
|
21
|
+
return (typeof node === 'string' ||
|
|
22
|
+
typeof node === 'number' ||
|
|
23
|
+
typeof node === 'boolean' ||
|
|
24
|
+
react_1.default.isValidElement(node) ||
|
|
25
|
+
(Array.isArray(node) && node.every(isValidReactNode)));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=isValidReactNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidReactNode.js","sourceRoot":"","sources":["../../../src/primitives/value/isValidReactNode.ts"],"names":[],"mappings":";;;;;AAcA,mCAQC;AAtBD,kDAAyC;AAEzC;;;;;;;;;;;GAWG;AACH,SAAwB,gBAAgB,CAAC,IAAS;IAC9C,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ;QACxB,OAAO,IAAI,KAAK,QAAQ;QACxB,OAAO,IAAI,KAAK,SAAS;QACzB,eAAK,CAAC,cAAc,CAAC,IAAI,CAAC;QAC1B,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CACtD,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively processes branches of a tree structure with a given function.
|
|
3
|
+
*
|
|
4
|
+
* @param {any} branches The branches of the tree structure. This can be any type, but is typically an object or an array.
|
|
5
|
+
* @param {Function} f The function to apply to each leaf node of the tree.
|
|
6
|
+
* @returns {any} The processed tree structure with the function applied to each leaf node.
|
|
7
|
+
*/
|
|
8
|
+
export default function processBranches(branches: any, f: Function): any;
|
|
9
|
+
//# sourceMappingURL=processBranches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processBranches.d.ts","sourceRoot":"","sources":["../../../src/primitives/value/processBranches.tsx"],"names":[],"mappings":"AA2BA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,QAAQ,GAAG,GAAG,CASvE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = processBranches;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
function isValidNestedGTNode(node) {
|
|
9
|
+
return (node === null ||
|
|
10
|
+
typeof node === 'undefined' ||
|
|
11
|
+
(typeof node === 'object' && Object.keys(node).length === 1 && Object.values(node).length === 1) ||
|
|
12
|
+
typeof node === 'string' ||
|
|
13
|
+
typeof node === 'number' ||
|
|
14
|
+
typeof node === 'boolean' ||
|
|
15
|
+
react_1.default.isValidElement(node) ||
|
|
16
|
+
(Array.isArray(node) && node.every(isValidNestedGTNode)));
|
|
17
|
+
}
|
|
18
|
+
function isValidGTNode(node) {
|
|
19
|
+
return (node === null ||
|
|
20
|
+
typeof node === 'undefined' ||
|
|
21
|
+
typeof node === 'string' ||
|
|
22
|
+
typeof node === 'number' ||
|
|
23
|
+
typeof node === 'boolean' ||
|
|
24
|
+
react_1.default.isValidElement(node) ||
|
|
25
|
+
(Array.isArray(node) && node.every(isValidNestedGTNode)));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Recursively processes branches of a tree structure with a given function.
|
|
29
|
+
*
|
|
30
|
+
* @param {any} branches The branches of the tree structure. This can be any type, but is typically an object or an array.
|
|
31
|
+
* @param {Function} f The function to apply to each leaf node of the tree.
|
|
32
|
+
* @returns {any} The processed tree structure with the function applied to each leaf node.
|
|
33
|
+
*/
|
|
34
|
+
function processBranches(branches, f) {
|
|
35
|
+
if (isValidGTNode(branches)) {
|
|
36
|
+
return f(branches);
|
|
37
|
+
}
|
|
38
|
+
let processedBranches = {};
|
|
39
|
+
for (const key of Object.keys(branches)) {
|
|
40
|
+
processedBranches[key] = processBranches(branches[key], f);
|
|
41
|
+
}
|
|
42
|
+
return processedBranches;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=processBranches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processBranches.js","sourceRoot":"","sources":["../../../src/primitives/value/processBranches.tsx"],"names":[],"mappings":";;;;;AAkCA,kCASC;AA3CD,kDAA0B;AAE1B,SAAS,mBAAmB,CAAC,IAAS;IAClC,OAAO,CACH,IAAI,KAAK,IAAI;QACb,OAAO,IAAI,KAAK,WAAW;QAC3B,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;QAChG,OAAO,IAAI,KAAK,QAAQ;QACxB,OAAO,IAAI,KAAK,QAAQ;QACxB,OAAO,IAAI,KAAK,SAAS;QACzB,eAAK,CAAC,cAAc,CAAC,IAAI,CAAC;QAC1B,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAC3D,CAAC;AACN,CAAC;AAED,SAAS,aAAa,CAAC,IAAS;IAC5B,OAAO,CACH,IAAI,KAAK,IAAI;QACb,OAAO,IAAI,KAAK,WAAW;QAC3B,OAAO,IAAI,KAAK,QAAQ;QACxB,OAAO,IAAI,KAAK,QAAQ;QACxB,OAAO,IAAI,KAAK,SAAS;QACzB,eAAK,CAAC,cAAc,CAAC,IAAI,CAAC;QAC1B,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAC3D,CAAC;AACN,CAAC;AAED;;;;;;GAMG;AACH,SAAwB,eAAe,CAAC,QAAa,EAAE,CAAW;IAC9D,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC;IACD,IAAI,iBAAiB,GAAQ,EAAE,CAAC;IAChC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtC,iBAAiB,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9D,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively renders a variable structure of children, handling arrays of children and single child elements.
|
|
3
|
+
*
|
|
4
|
+
* @param {any} children - The children elements to render.
|
|
5
|
+
* @returns {any} The rendered children elements.
|
|
6
|
+
*/
|
|
7
|
+
export default function renderVariable(children: any, variables?: Record<string, any>): any;
|
|
8
|
+
//# sourceMappingURL=renderVariable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderVariable.d.ts","sourceRoot":"","sources":["../../../src/primitives/value/renderVariable.tsx"],"names":[],"mappings":"AAuCA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,QAAQ,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,CAG1F"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = renderVariable;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const isValidReactNode_1 = __importDefault(require("./isValidReactNode"));
|
|
10
|
+
const Variable_1 = __importDefault(require("../variable/Variable"));
|
|
11
|
+
/**
|
|
12
|
+
* Handles a single child element by cloning it with new properties if it is a valid React element,
|
|
13
|
+
* or wrapping it in a React Fragment if it is a valid React node object.
|
|
14
|
+
*
|
|
15
|
+
* @param {any} child - The child element to handle.
|
|
16
|
+
* @returns {any} The handled child element.
|
|
17
|
+
*/
|
|
18
|
+
const handleSingleChild = (child, variables) => {
|
|
19
|
+
var _a;
|
|
20
|
+
if (react_1.default.isValidElement(child)) {
|
|
21
|
+
const { props, type } = child;
|
|
22
|
+
// Check if a variable component
|
|
23
|
+
const transformation = typeof type === 'function' ? (type.gtTransformation || '') : '';
|
|
24
|
+
if (variables && transformation === "variable" && (props === null || props === void 0 ? void 0 : props.name)) {
|
|
25
|
+
const name = props.name;
|
|
26
|
+
const value = variables[props.name];
|
|
27
|
+
return (0, jsx_runtime_1.jsx)(Variable_1.default, { defaultValue: value, name: name });
|
|
28
|
+
}
|
|
29
|
+
let newProps = Object.assign({}, props);
|
|
30
|
+
if (props === null || props === void 0 ? void 0 : props.children) {
|
|
31
|
+
newProps.children = renderVariable(props.children, variables);
|
|
32
|
+
}
|
|
33
|
+
return react_1.default.cloneElement(child, newProps);
|
|
34
|
+
}
|
|
35
|
+
if (typeof child === 'object') {
|
|
36
|
+
const key = (_a = Object.keys(child)) === null || _a === void 0 ? void 0 : _a[0];
|
|
37
|
+
const value = child[key];
|
|
38
|
+
if ((typeof value !== 'undefined' && value !== null) && (0, isValidReactNode_1.default)(value)) {
|
|
39
|
+
return (0, jsx_runtime_1.jsx)(Variable_1.default, { defaultValue: value, name: key });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
return child;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Recursively renders a variable structure of children, handling arrays of children and single child elements.
|
|
47
|
+
*
|
|
48
|
+
* @param {any} children - The children elements to render.
|
|
49
|
+
* @returns {any} The rendered children elements.
|
|
50
|
+
*/
|
|
51
|
+
function renderVariable(children, variables) {
|
|
52
|
+
if (Array.isArray(children))
|
|
53
|
+
return children.map((child, index) => (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: handleSingleChild(child, variables) }, index));
|
|
54
|
+
else
|
|
55
|
+
return handleSingleChild(children, variables);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=renderVariable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderVariable.js","sourceRoot":"","sources":["../../../src/primitives/value/renderVariable.tsx"],"names":[],"mappings":";;;;;AA6CA,iCAGC;;AAhDD,kDAAyB;AACzB,0EAAkD;AAClD,oEAA4C;AAE5C;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAU,EAAE,SAA+B,EAAO,EAAE;;IAC3E,IAAI,eAAK,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAQ,KAAK,CAAC;QACnC,gCAAgC;QAChC,MAAM,cAAc,GAAW,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAAE,IAAY,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC,CAAC,CA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,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,KAAa,EAAE,EAAE,CAAC,uBAAC,eAAK,CAAC,QAAQ,cAAc,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,IAA3C,KAAK,CAAwD,CAAC,CAAC;;QAC/J,OAAO,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;AACtD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
type VariableProps = {
|
|
3
|
+
children?: any;
|
|
4
|
+
name: string;
|
|
5
|
+
defaultValue?: any;
|
|
6
|
+
"data-generaltranslation"?: Record<string, any> | undefined;
|
|
7
|
+
};
|
|
8
|
+
declare const Variable: {
|
|
9
|
+
({ children, name, defaultValue, ...props }: VariableProps): ReactNode;
|
|
10
|
+
gtTransformation: string;
|
|
11
|
+
};
|
|
12
|
+
export default Variable;
|
|
13
|
+
//# sourceMappingURL=Variable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Variable.d.ts","sourceRoot":"","sources":["../../../src/primitives/variable/Variable.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGzC,KAAK,aAAa,GAAG;IACjB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,yBAAyB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAA;CAC9D,CAAA;AAED,QAAA,MAAM,QAAQ;iDAAgD,aAAa,GAAG,SAAS;;CAYtF,CAAC;AAIF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
15
|
+
const Variable = (_a) => {
|
|
16
|
+
var { children, name, defaultValue } = _a, props = __rest(_a, ["children", "name", "defaultValue"]);
|
|
17
|
+
if (typeof children !== 'undefined' && typeof defaultValue === 'undefined')
|
|
18
|
+
defaultValue = children;
|
|
19
|
+
const { "data-generaltranslation": generaltranslation } = props;
|
|
20
|
+
return ((0, jsx_runtime_1.jsx)("span", { "data-generaltranslation": generaltranslation, "data-gt-variable-name": name, children: defaultValue }));
|
|
21
|
+
};
|
|
22
|
+
Variable.gtTransformation = "variable";
|
|
23
|
+
exports.default = Variable;
|
|
24
|
+
//# sourceMappingURL=Variable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Variable.js","sourceRoot":"","sources":["../../../src/primitives/variable/Variable.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AAUA,MAAM,QAAQ,GAAG,CAAC,EAAyD,EAAa,EAAE;QAAxE,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,OAA2B,EAAtB,KAAK,cAAxC,oCAA0C,CAAF;IAEtD,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,YAAY,KAAK,WAAW;QAAE,YAAY,GAAG,QAAQ,CAAC;IAEpG,MAAM,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC;IAEhE,OAAO,CACH,4DAA+B,kBAAkB,2BAAyB,IAAI,YACzE,YAAY,GACV,CACV,CAAC;AAEN,CAAC,CAAC;AAEF,QAAQ,CAAC,gBAAgB,GAAG,UAAU,CAAC;AAEvC,kBAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type ServerI18NProps = {
|
|
2
|
+
children: any;
|
|
3
|
+
userLanguage: string;
|
|
4
|
+
page?: string;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* ServerI18N component for handling internationalization on the server side.
|
|
9
|
+
*
|
|
10
|
+
* @param {any} children - Children to be translated and rendered.
|
|
11
|
+
* @param {string} userLanguage - The ISO-639 language code of the target language, e.g. "en". Also accepts extended browser language codes, e.g. "en-US".
|
|
12
|
+
* @param {string} id - Optional user-defined id for better I18N page structure.
|
|
13
|
+
* @param {Record<string, any>} ...props - Additional metadata for use as a translation aid.
|
|
14
|
+
* @returns {Promise<any>} The rendered component.
|
|
15
|
+
*/
|
|
16
|
+
export default function ServerI18N({ children, userLanguage, ...props }: ServerI18NProps): Promise<any>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=ServerI18N.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerI18N.d.ts","sourceRoot":"","sources":["../../src/server/ServerI18N.tsx"],"names":[],"mappings":"AASA,KAAK,eAAe,GAAG;IACnB,QAAQ,EAAE,GAAG,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAA;AAED;;;;;;;;GAQG;AACH,wBAA8B,UAAU,CAAC,EACrC,QAAQ,EAAE,YAAY,EAAE,GAAG,KAAK,EACnC,EAAE,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,CA+DhC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.default = ServerI18N;
|
|
27
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
|
+
const I18NConfig_1 = __importDefault(require("../config/I18NConfig"));
|
|
29
|
+
const addGTIdentifier_js_1 = __importDefault(require("./helpers/addGTIdentifier.js"));
|
|
30
|
+
const writeChildrenAsObjects_js_1 = __importDefault(require("./helpers/writeChildrenAsObjects.js"));
|
|
31
|
+
const generateHash_js_1 = __importDefault(require("./helpers/generateHash.js"));
|
|
32
|
+
const renderChildren_1 = __importDefault(require("./renderChildren"));
|
|
33
|
+
const I18NResolver_1 = __importDefault(require("./resolvers/I18NResolver"));
|
|
34
|
+
/**
|
|
35
|
+
* ServerI18N component for handling internationalization on the server side.
|
|
36
|
+
*
|
|
37
|
+
* @param {any} children - Children to be translated and rendered.
|
|
38
|
+
* @param {string} userLanguage - The ISO-639 language code of the target language, e.g. "en". Also accepts extended browser language codes, e.g. "en-US".
|
|
39
|
+
* @param {string} id - Optional user-defined id for better I18N page structure.
|
|
40
|
+
* @param {Record<string, any>} ...props - Additional metadata for use as a translation aid.
|
|
41
|
+
* @returns {Promise<any>} The rendered component.
|
|
42
|
+
*/
|
|
43
|
+
function ServerI18N(_a) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
var { children, userLanguage } = _a, props = __rest(_a, ["children", "userLanguage"]);
|
|
46
|
+
// Handle case where translation is not required, for example if the user's browser is in the defaultLanguage
|
|
47
|
+
const translationRequired = (children && I18NConfig_1.default.translationRequired(userLanguage)) ? true : false;
|
|
48
|
+
if (!translationRequired) {
|
|
49
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }));
|
|
50
|
+
}
|
|
51
|
+
const taggedChildren = (0, addGTIdentifier_js_1.default)(children);
|
|
52
|
+
const childrenAsObjects = (0, writeChildrenAsObjects_js_1.default)(taggedChildren);
|
|
53
|
+
const hash = yield (0, generateHash_js_1.default)(childrenAsObjects);
|
|
54
|
+
// Fetch an I18N page (from the cache, locally, or remotely)
|
|
55
|
+
const I18NEntry = yield I18NConfig_1.default.getI18NEntry(userLanguage, hash, props.id, props.page);
|
|
56
|
+
// Check if a translation for this site already exists and return it if it does
|
|
57
|
+
const translationExists = I18NEntry ? true : false;
|
|
58
|
+
if (translationExists) {
|
|
59
|
+
const I18NChildren = (0, renderChildren_1.default)(taggedChildren, I18NEntry);
|
|
60
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: I18NChildren }));
|
|
61
|
+
}
|
|
62
|
+
// Create a new translation for this site and render it
|
|
63
|
+
const I18NChildrenPromise = I18NConfig_1.default.translateChildren({ children: childrenAsObjects, targetLanguage: userLanguage, metadata: Object.assign({}, props) });
|
|
64
|
+
const renderMethod = I18NConfig_1.default.getRenderMethod();
|
|
65
|
+
if (renderMethod === "replace") {
|
|
66
|
+
// Return the site in the default language
|
|
67
|
+
// Replace with translated site when ready
|
|
68
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(I18NResolver_1.default, { promise: I18NChildrenPromise, children: taggedChildren }) }));
|
|
69
|
+
}
|
|
70
|
+
if (renderMethod === "hang") {
|
|
71
|
+
// Wait until the site is translated to return
|
|
72
|
+
const I18NChildren = (0, renderChildren_1.default)(taggedChildren, yield I18NChildrenPromise);
|
|
73
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: I18NChildren }));
|
|
74
|
+
}
|
|
75
|
+
return (
|
|
76
|
+
// return the children, with no special rendering
|
|
77
|
+
// a translation may be available from a cached page next time the component is loaded
|
|
78
|
+
(0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=ServerI18N.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerI18N.js","sourceRoot":"","sources":["../../src/server/ServerI18N.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,6BAiEC;;AAxFD,sEAA8C;AAC9C,sFAA2D;AAC3D,oGAAyE;AACzE,gFAAqD;AACrD,sEAA8C;AAC9C,4EAAoD;AASpD;;;;;;;;GAQG;AACH,SAA8B,UAAU,CAAC,EAEvB;;YAFuB,EACrC,QAAQ,EAAE,YAAY,OACR,EADa,KAAK,cADK,4BAExC,CADmC;QAGhC,6GAA6G;QAC7G,MAAM,mBAAm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N,CAAA;QACL,CAAC;QAED,IAAI,YAAY,KAAK,MAAM,EAAE,CAAC;YAC1B,8CAA8C;YAC9C,MAAM,YAAY,GAAG,IAAA,wBAAc,EAAC,cAAc,EAAE,MAAM,mBAAmB,CAAC,CAAC;YAC/E,OAAO,CACH,2DACK,YAAY,GACd,CACN,CAAA;QACL,CAAC;QAED,OAAO;QACH,iDAAiD;QACjD,sFAAsF;QACtF,2DACK,QAAQ,GACV,CACN,CAAA;IAEL,CAAC;CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
type Child = ReactNode | Record<string, any>;
|
|
3
|
+
type Children = Child[] | Child;
|
|
4
|
+
/**
|
|
5
|
+
* Main function to add GT (General Translation) identifiers to the children
|
|
6
|
+
* @param children - The children elements to which GT identifiers will be added
|
|
7
|
+
* @returns - The children with added GT identifiers
|
|
8
|
+
*/
|
|
9
|
+
export default function addGTIdentifier(children: Children): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | Record<string, any> | (string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | Record<string, any> | null | undefined)[] | null | undefined;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=addGTIdentifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addGTIdentifier.d.ts","sourceRoot":"","sources":["../../../src/server/helpers/addGTIdentifier.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAgB,MAAM,OAAO,CAAA;AAGtD,KAAK,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC7C,KAAK,QAAQ,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;AAkBhC;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,QAAQ,EAAE,QAAQ,iVA0IzD"}
|