gt-react 3.0.4 → 3.0.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.
Files changed (63) hide show
  1. package/dist/config/I18NConfiguration.d.ts +9 -3
  2. package/dist/config/I18NConfiguration.d.ts.map +1 -1
  3. package/dist/config/I18NConfiguration.js +37 -14
  4. package/dist/config/I18NConfiguration.js.map +1 -1
  5. package/dist/config/LocalDictionaryManager.d.ts +31 -0
  6. package/dist/config/LocalDictionaryManager.d.ts.map +1 -0
  7. package/dist/config/LocalDictionaryManager.js +95 -0
  8. package/dist/config/LocalDictionaryManager.js.map +1 -0
  9. package/dist/config/{DictionaryManager.d.ts → RemoteDictionaryManager.d.ts} +2 -2
  10. package/dist/config/RemoteDictionaryManager.d.ts.map +1 -0
  11. package/dist/config/{DictionaryManager.js → RemoteDictionaryManager.js} +3 -3
  12. package/dist/config/RemoteDictionaryManager.js.map +1 -0
  13. package/dist/index.d.ts +5 -3
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +9 -5
  16. package/dist/index.js.map +1 -1
  17. package/dist/intl/createIntlFunction.d.ts.map +1 -1
  18. package/dist/intl/createIntlFunction.js +5 -3
  19. package/dist/intl/createIntlFunction.js.map +1 -1
  20. package/dist/server/ServerI18N.d.ts.map +1 -1
  21. package/dist/server/ServerI18N.js +4 -0
  22. package/dist/server/ServerI18N.js.map +1 -1
  23. package/dist/types/CreateGTProps.d.ts +2 -0
  24. package/dist/types/CreateGTProps.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/dist/I18N/ServerI18N.d.ts +0 -12
  27. package/dist/I18N/ServerI18N.d.ts.map +0 -1
  28. package/dist/I18N/ServerI18N.js +0 -84
  29. package/dist/I18N/ServerI18N.js.map +0 -1
  30. package/dist/I18N/createI18NComponent.d.ts +0 -9
  31. package/dist/I18N/createI18NComponent.d.ts.map +0 -1
  32. package/dist/I18N/createI18NComponent.js +0 -29
  33. package/dist/I18N/createI18NComponent.js.map +0 -1
  34. package/dist/I18N/helpers/addGTIdentifier.d.ts +0 -11
  35. package/dist/I18N/helpers/addGTIdentifier.d.ts.map +0 -1
  36. package/dist/I18N/helpers/addGTIdentifier.js +0 -158
  37. package/dist/I18N/helpers/addGTIdentifier.js.map +0 -1
  38. package/dist/I18N/helpers/generateHash.d.ts +0 -12
  39. package/dist/I18N/helpers/generateHash.d.ts.map +0 -1
  40. package/dist/I18N/helpers/generateHash.js +0 -34
  41. package/dist/I18N/helpers/generateHash.js.map +0 -1
  42. package/dist/I18N/helpers/writeChildrenAsObjects.d.ts +0 -11
  43. package/dist/I18N/helpers/writeChildrenAsObjects.d.ts.map +0 -1
  44. package/dist/I18N/helpers/writeChildrenAsObjects.js +0 -129
  45. package/dist/I18N/helpers/writeChildrenAsObjects.js.map +0 -1
  46. package/dist/I18N/renderChildren.d.ts +0 -24
  47. package/dist/I18N/renderChildren.d.ts.map +0 -1
  48. package/dist/I18N/renderChildren.js +0 -180
  49. package/dist/I18N/renderChildren.js.map +0 -1
  50. package/dist/I18N/resolvers/I18NResolver.d.ts +0 -16
  51. package/dist/I18N/resolvers/I18NResolver.d.ts.map +0 -1
  52. package/dist/I18N/resolvers/I18NResolver.js +0 -59
  53. package/dist/I18N/resolvers/I18NResolver.js.map +0 -1
  54. package/dist/config/DictionaryManager.d.ts.map +0 -1
  55. package/dist/config/DictionaryManager.js.map +0 -1
  56. package/dist/types/CreateI18NConfigProps.d.ts +0 -2
  57. package/dist/types/CreateI18NConfigProps.d.ts.map +0 -1
  58. package/dist/types/CreateI18NConfigProps.js +0 -4
  59. package/dist/types/CreateI18NConfigProps.js.map +0 -1
  60. package/dist/types/GTInterface.d.ts +0 -29
  61. package/dist/types/GTInterface.d.ts.map +0 -1
  62. package/dist/types/GTInterface.js +0 -3
  63. package/dist/types/GTInterface.js.map +0 -1
@@ -1,12 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import I18NConfiguration from '../config/I18NConfiguration.js';
3
- type ServerI18NProps = {
4
- I18NConfig: I18NConfiguration;
5
- children: any;
6
- locale: string;
7
- id?: string;
8
- [key: string]: any;
9
- };
10
- export default function ServerI18N({ I18NConfig, children, locale, ...props }: ServerI18NProps): Promise<ReactNode>;
11
- export {};
12
- //# sourceMappingURL=ServerI18N.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ServerI18N.d.ts","sourceRoot":"","sources":["../../src/i18n/ServerI18N.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAOxC,OAAO,iBAAiB,MAAM,gCAAgC,CAAC;AAE/D,KAAK,eAAe,GAAG;IACnB,UAAU,EAAE,iBAAiB,CAAA;IAC7B,QAAQ,EAAE,GAAG,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAA;AAED,wBAA8B,UAAU,CAAC,EACrC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,KAAK,EACzC,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC,CAgFtC"}
@@ -1,84 +0,0 @@
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 addGTIdentifier_js_1 = __importDefault(require("./helpers/addGTIdentifier.js"));
29
- const writeChildrenAsObjects_js_1 = __importDefault(require("./helpers/writeChildrenAsObjects.js"));
30
- const generateHash_js_1 = __importDefault(require("./helpers/generateHash.js"));
31
- const renderChildren_js_1 = __importDefault(require("./renderChildren.js"));
32
- const I18NResolver_js_1 = __importDefault(require("./resolvers/I18NResolver.js"));
33
- const generaltranslation_1 = require("generaltranslation");
34
- function ServerI18N(_a) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- var { I18NConfig, children, locale } = _a, props = __rest(_a, ["I18NConfig", "children", "locale"]);
37
- // Handle case where translation is not required, for example if the user's browser is in the default locale
38
- const translationRequired = (children && I18NConfig.translationRequired(locale)) ? true : false;
39
- if (!translationRequired) {
40
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }));
41
- }
42
- // Fetch translations
43
- const translationsPromise = I18NConfig.getTranslations(locale, props.dictionaryName);
44
- const defaultLocale = I18NConfig.getDefaultLocale();
45
- let renderAttributes = {};
46
- const dir = (0, generaltranslation_1.getLanguageDirection)(locale);
47
- if (dir === 'rtl')
48
- renderAttributes = Object.assign(Object.assign({}, renderAttributes), { dir });
49
- const taggedChildren = (0, addGTIdentifier_js_1.default)(children);
50
- const childrenAsObjects = (0, writeChildrenAsObjects_js_1.default)(taggedChildren);
51
- const key = yield (0, generateHash_js_1.default)(childrenAsObjects);
52
- const id = props.id ? props.id : key;
53
- const translations = yield translationsPromise;
54
- const translation = (translations && translations[id] && translations[id].k === key) ? translations[id].t : null;
55
- // Check if a translation for this site already exists and return it if it does
56
- const translationExists = translation ? true : false;
57
- if (translationExists) {
58
- const I18NChildren = (0, renderChildren_js_1.default)({ source: taggedChildren, target: translation, renderAttributes, locale, defaultLocale });
59
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: I18NChildren }));
60
- }
61
- // Create a new translation for this site and render it
62
- const I18NChildrenPromise = I18NConfig.translateChildren({ children: childrenAsObjects, targetLanguage: locale, metadata: Object.assign({}, props) });
63
- const renderMethod = (props === null || props === void 0 ? void 0 : props.renderMethod) || I18NConfig.getRenderMethod();
64
- if (renderMethod === "replace") {
65
- // Return the site in the default language
66
- // Replace with translated site when ready
67
- const InnerResolver = () => __awaiter(this, void 0, void 0, function* () {
68
- const I18NChildren = yield I18NChildrenPromise;
69
- return (0, renderChildren_js_1.default)({ source: taggedChildren, target: I18NChildren, renderAttributes, locale, defaultLocale });
70
- });
71
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(I18NResolver_js_1.default, { fallback: children, children: (0, jsx_runtime_1.jsx)(InnerResolver, {}) }) }));
72
- }
73
- if (renderMethod === "hang") {
74
- // Wait until the site is translated to return
75
- const I18NChildren = (0, renderChildren_js_1.default)({ source: taggedChildren, target: yield I18NChildrenPromise, renderAttributes, locale, defaultLocale });
76
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: I18NChildren }));
77
- }
78
- return (
79
- // return the children, with no special rendering
80
- // a translation may be available from a cached translation dictionary next time the component is loaded
81
- (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }));
82
- });
83
- }
84
- //# sourceMappingURL=ServerI18N.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ServerI18N.js","sourceRoot":"","sources":["../../src/i18n/ServerI18N.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;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;QAED,IAAI,YAAY,KAAK,MAAM,EAAE,CAAC;YAC1B,8CAA8C;YAC9C,MAAM,YAAY,GAAG,IAAA,2BAAc,EAAC,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;YAC5I,OAAO,CACH,2DACK,YAAY,GACd,CACN,CAAA;QACL,CAAC;QAED,OAAO;QACH,iDAAiD;QACjD,wGAAwG;QACxG,2DACK,QAAQ,GACV,CACN,CAAA;IAEL,CAAC;CAAA"}
@@ -1,9 +0,0 @@
1
- import I18NConfiguration from "../config/I18NConfiguration";
2
- export default function createI18NComponent({ I18NConfig, ...metadata }: {
3
- I18NConfig: I18NConfiguration;
4
- [key: string]: any;
5
- }): ({ children, ...props }: {
6
- children?: any;
7
- [key: string]: any;
8
- }) => import("react/jsx-runtime").JSX.Element;
9
- //# sourceMappingURL=createI18NComponent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createI18NComponent.d.ts","sourceRoot":"","sources":["../../src/i18n/createI18NComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAE5D,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EACxC,UAAU,EAAE,GAAG,QAAQ,EAC1B,EAAE;IAAE,UAAU,EAAE,iBAAiB,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,4BACpB;IAAE,QAAQ,CAAC,EAAE,GAAG,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,6CAKzE"}
@@ -1,29 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.default = createI18NComponent;
18
- const jsx_runtime_1 = require("react/jsx-runtime");
19
- const ServerI18N_1 = __importDefault(require("./ServerI18N"));
20
- function createI18NComponent(_a) {
21
- var { I18NConfig } = _a, metadata = __rest(_a, ["I18NConfig"]);
22
- return (_a) => {
23
- var { children } = _a, props = __rest(_a, ["children"]);
24
- const locale = I18NConfig.getLocale();
25
- /* @ts-expect-error Server Component */
26
- return (0, jsx_runtime_1.jsx)(ServerI18N_1.default, Object.assign({ I18NConfig: I18NConfig, locale: locale }, metadata, props, { children: children }));
27
- };
28
- }
29
- //# sourceMappingURL=createI18NComponent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createI18NComponent.js","sourceRoot":"","sources":["../../src/i18n/createI18NComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAIA,sCAQC;;AAXD,8DAAsC;AAGtC,SAAwB,mBAAmB,CAAC,EAEY;QAFZ,EACxC,UAAU,OAC0C,EADrC,QAAQ,cADiB,cAE3C,CAD0B;IAEvB,OAAO,CAAC,EAA8D,EAAE,EAAE;YAAlE,EAAE,QAAQ,OAAoD,EAA/C,KAAK,cAApB,YAAsB,CAAF;QACxB,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC;QACtC,uCAAuC;QACvC,OAAO,uBAAC,oBAAU,kBAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,IAAM,QAAQ,EAAM,KAAK,cAAG,QAAQ,IAAc,CAAA;IAC/G,CAAC,CAAA;AACL,CAAC"}
@@ -1,11 +0,0 @@
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 | Record<string, any> | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | (string | number | boolean | Record<string, any> | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined)[] | null | undefined;
10
- export {};
11
- //# sourceMappingURL=addGTIdentifier.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addGTIdentifier.d.ts","sourceRoot":"","sources":["../../../src/i18n/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,iVAkJzD"}
@@ -1,158 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.default = addGTIdentifier;
18
- const react_1 = __importDefault(require("react"));
19
- const processBranches_1 = __importDefault(require("../../primitives/value/processBranches"));
20
- /**
21
- * Helper function to validate the properties of the component to prevent nested translations
22
- * @param props - The properties of the current React element
23
- */
24
- const validateProps = (props) => {
25
- if (props && props['data-generaltranslation'] && typeof props['data-generaltranslation'].id === 'number') {
26
- throw new Error(`Nesting of I18N components is not permitted. This prevents components from being translated twice.
27
- Found nested component with ID: ${props['data-generaltranslation'].id}`);
28
- }
29
- };
30
- /**
31
- * Main function to add GT (General Translation) identifiers to the children
32
- * @param children - The children elements to which GT identifiers will be added
33
- * @returns - The children with added GT identifiers
34
- */
35
- function addGTIdentifier(children) {
36
- // Object to keep track of the current index for GT IDs
37
- let indexObject = { index: 0 };
38
- /**
39
- * Function to create a GTProp object for a ReactElement
40
- * @param child - The ReactElement for which the GTProp is created
41
- * @returns - The GTProp object
42
- */
43
- const createGTProp = (child) => {
44
- const { type, props } = child;
45
- indexObject.index += 1;
46
- let result = { id: indexObject.index };
47
- const transformation = typeof type === 'function' ? (type.gtTransformation || '') : '';
48
- if (transformation) {
49
- const transformationParts = transformation.split('-');
50
- if (transformationParts[0] === "variable") {
51
- result.variableType = (transformationParts === null || transformationParts === void 0 ? void 0 : transformationParts[1]) || "variable";
52
- }
53
- result.transformation = transformationParts[0];
54
- if (transformation === "private") {
55
- if (typeof props.label === 'string') {
56
- result.label = props.label;
57
- }
58
- }
59
- }
60
- return result;
61
- };
62
- /**
63
- * Function to handle valid React elements and add GT identifiers
64
- * @param child - The ReactElement to handle
65
- * @returns - The new ReactElement with added GT identifiers
66
- */
67
- const handleValidReactElement = (child) => {
68
- // Destructure the props from the child element
69
- const { props } = child;
70
- // Validate the props to ensure there are no nested translations
71
- validateProps(props);
72
- // Create new props for the element, including the GT identifier and a key
73
- let generaltranslation = createGTProp(child);
74
- let newProps = Object.assign(Object.assign({}, props), { 'data-generaltranslation': generaltranslation, key: generaltranslation.id });
75
- // If branches are needed for a number or value variable
76
- const transformation = generaltranslation.transformation;
77
- if (transformation === "numeric" || transformation === "value") {
78
- // Updates indices to keep a consistent identification system across branches
79
- let frozenIndex = indexObject.index;
80
- let championIndex = indexObject.index;
81
- const updateIndices = () => {
82
- if (indexObject.index > frozenIndex) {
83
- if (indexObject.index > championIndex) {
84
- championIndex = indexObject.index;
85
- }
86
- indexObject.index = frozenIndex;
87
- }
88
- };
89
- // Adds ID to children
90
- if (props.children) {
91
- newProps.children = addIdentifierRecursively(props.children);
92
- }
93
- // define branches
94
- let branches = {};
95
- // add identifier to number branches (e.g. singular, plural, ranges)
96
- if (transformation === "numeric") {
97
- const { n, children } = props, options = __rest(props, ["n", "children"]);
98
- let { ranges } = options, others = __rest(options, ["ranges"]);
99
- if (ranges)
100
- branches.ranges = options.ranges.map((range) => {
101
- updateIndices();
102
- return { min: range.min, max: range.max, children: addIdentifierRecursively(range.children) };
103
- });
104
- for (const option of Object.keys(others)) {
105
- updateIndices();
106
- branches[option] = addIdentifierRecursively(others[option]);
107
- }
108
- newProps = Object.assign(Object.assign({}, newProps), branches);
109
- }
110
- // or add identifier to value branches, e.g. name={"Kernighan"}
111
- else if (transformation === "value") {
112
- const { "branches": rawBranches } = props;
113
- if (rawBranches) {
114
- branches = (0, processBranches_1.default)(rawBranches, (branch) => { updateIndices(); return addIdentifierRecursively(branch); });
115
- }
116
- newProps.branches = branches;
117
- }
118
- // modify newProps if necessary
119
- if (Object.keys(branches).length > 0)
120
- newProps['data-generaltranslation'].branches = branches;
121
- if (newProps.children)
122
- newProps['data-generaltranslation'].defaultChildren = newProps.children;
123
- // reset index
124
- indexObject.index = championIndex;
125
- }
126
- // if no transformation is required
127
- if (!transformation) {
128
- if (props.children) {
129
- newProps.children = addIdentifierRecursively(props.children);
130
- }
131
- }
132
- // return the element with new props
133
- return react_1.default.cloneElement(child, newProps);
134
- };
135
- /**
136
- * Function to handle a single child element and determine if it's a valid React element
137
- * @param child - The child element to handle
138
- * @returns - The handled child element
139
- */
140
- const handleSingleChild = (child) => {
141
- if (react_1.default.isValidElement(child))
142
- return handleValidReactElement(child);
143
- return child;
144
- };
145
- /**
146
- * Recursive function to add GT identifiers to all child elements
147
- * @param children - The children elements to process
148
- * @returns - The children elements with added GT identifiers
149
- */
150
- const addIdentifierRecursively = (children) => {
151
- if (Array.isArray(children)) {
152
- return children.map(child => handleSingleChild(child));
153
- }
154
- return handleSingleChild(children);
155
- };
156
- return addIdentifierRecursively(children);
157
- }
158
- //# sourceMappingURL=addGTIdentifier.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addGTIdentifier.js","sourceRoot":"","sources":["../../../src/i18n/helpers/addGTIdentifier.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA2BA,kCAkJC;AA7KD,kDAAsD;AACtD,6FAAqE;AAUrE;;;GAGG;AACH,MAAM,aAAa,GAAG,CAAC,KAA0B,EAAQ,EAAE;IACvD,IAAI,KAAK,IAAI,KAAK,CAAC,yBAAyB,CAAC,IAAI,OAAO,KAAK,CAAC,yBAAyB,CAAC,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACvG,MAAM,IAAI,KAAK,CAAC;8CACsB,KAAK,CAAC,yBAAyB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjF,CAAC;AACL,CAAC,CAAA;AAED;;;;GAIG;AACH,SAAwB,eAAe,CAAC,QAAkB;IAEtD,uDAAuD;IACvD,IAAI,WAAW,GAAsB,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAElD;;;;OAIG;IACH,MAAM,YAAY,GAAG,CAAC,KAAmB,EAAU,EAAE;QACjD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QAC9B,WAAW,CAAC,KAAK,IAAI,CAAC,CAAC;QACvB,IAAI,MAAM,GAAW,EAAE,EAAE,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC;QAC/C,MAAM,cAAc,GAAW,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAA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K,CAAC,cAAc,CAAC,KAAK,CAAC;YAAE,OAAO,uBAAuB,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,KAAK,CAAC;IACjB,CAAC,CAAA;IAED;;;;OAIG;IACH,MAAM,wBAAwB,GAAG,CAAC,QAAa,EAAE,EAAE;QAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1B,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAA;QAC1D,CAAC;QACD,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC,CAAA;IAED,OAAO,wBAAwB,CAAC,QAAQ,CAAC,CAAC;AAE9C,CAAC"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Generates a SHA-256 hash for the given message.
3
- *
4
- * @param {any} message - The message to be hashed. This can be of any type.
5
- * If the message is an object or array, it will be
6
- * converted to a JSON string.
7
- * @returns {Promise<string>} A promise that resolves to the SHA-256 hash of the
8
- * message in hexadecimal format. If the message is
9
- * falsy, an empty string is returned.
10
- */
11
- export default function generateHash(message: any): Promise<string>;
12
- //# sourceMappingURL=generateHash.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateHash.d.ts","sourceRoot":"","sources":["../../../src/i18n/helpers/generateHash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAA8B,YAAY,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAOxE"}
@@ -1,34 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.default = generateHash;
13
- /**
14
- * Generates a SHA-256 hash for the given message.
15
- *
16
- * @param {any} message - The message to be hashed. This can be of any type.
17
- * If the message is an object or array, it will be
18
- * converted to a JSON string.
19
- * @returns {Promise<string>} A promise that resolves to the SHA-256 hash of the
20
- * message in hexadecimal format. If the message is
21
- * falsy, an empty string is returned.
22
- */
23
- function generateHash(message) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- message = JSON.stringify(message);
26
- const msgBuffer = new TextEncoder().encode(message);
27
- const hashBuffer = yield crypto.subtle.digest('SHA-256', msgBuffer);
28
- const hashArray = Array.from(new Uint8Array(hashBuffer));
29
- const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
30
- return hashHex;
31
- });
32
- }
33
- ;
34
- //# sourceMappingURL=generateHash.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateHash.js","sourceRoot":"","sources":["../../../src/i18n/helpers/generateHash.ts"],"names":[],"mappings":";;;;;;;;;;;AAUA,+BAOC;AAjBD;;;;;;;;;GASG;AACH,SAA8B,YAAY,CAAC,OAAY;;QACnD,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAc,CAAC,CAAC;QAC3D,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACpE,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;QACzD,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7E,OAAO,OAAO,CAAC;IACnB,CAAC;CAAA;AAAA,CAAC"}
@@ -1,11 +0,0 @@
1
- import { ReactNode } from 'react';
2
- type Child = ReactNode | Record<string, any>;
3
- type Children = Child | Child[];
4
- /**
5
- * Transforms children elements into objects, processing each child recursively if needed.
6
- * @param {Children} children - The children to process.
7
- * @returns {object} - The processed children as objects.
8
- */
9
- export default function writeChildrenAsObjects(children: Children): any;
10
- export {};
11
- //# sourceMappingURL=writeChildrenAsObjects.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"writeChildrenAsObjects.d.ts","sourceRoot":"","sources":["../../../src/i18n/helpers/writeChildrenAsObjects.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAgB,MAAM,OAAO,CAAA;AAItD,KAAK,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC7C,KAAK,QAAQ,GAAG,KAAK,GAAG,KAAK,EAAE,CAAC;AA2GhC;;;;EAIE;AACF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,GAAG,GAAG,CAKtE"}
@@ -1,129 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.default = writeChildrenAsObjects;
18
- const react_1 = __importDefault(require("react"));
19
- const processBranches_1 = __importDefault(require("../../primitives/value/processBranches"));
20
- const defaultVariableNames_1 = __importDefault(require("../../primitives/helpers/defaultVariableNames"));
21
- /**
22
- * Checks if the props indicate that the component should be not be processed.
23
- * @param {Record<string, any>} props - The props to check.
24
- * @returns {boolean} - True if the component is private, otherwise false.
25
- */
26
- const isPrivate = (props) => { var _a; return ((_a = props['data-generaltranslation']) === null || _a === void 0 ? void 0 : _a.transformation) === "private"; };
27
- /**
28
- * Gets the tag name of a React element.
29
- * @param {ReactElement} child - The React element.
30
- * @returns {string} - The tag name of the React element.
31
- */
32
- const getTagName = (child) => {
33
- var _a;
34
- if (!child)
35
- return '';
36
- const { type, props } = child;
37
- if (type && typeof type === 'function') {
38
- if ('displayName' in type && typeof type.displayName === 'string' && type.displayName)
39
- return type.displayName;
40
- if ('name' in type && typeof type.name === 'string' && type.name)
41
- return type.name;
42
- }
43
- if (type && typeof type === 'string')
44
- return type;
45
- if (props.href)
46
- return 'a';
47
- if ((_a = props['data-generaltranslation']) === null || _a === void 0 ? void 0 : _a.id)
48
- return `C${props['data-generaltranslation'].id}`;
49
- return 'function';
50
- };
51
- /**
52
- * Handles processing of a valid React element, transforming its properties and children as needed.
53
- * @param {ReactElement} child - The React element to process.
54
- * @returns {object} - The processed element with its type and transformed props.
55
- */
56
- const handleValidReactElement = (child) => {
57
- const { type, props } = child;
58
- let newProps = {};
59
- // Transform children if they exist and are not private
60
- if (props.children && !isPrivate(props)) {
61
- newProps.children = writeChildrenAsObjects(props.children);
62
- }
63
- // Write the branches of 'data-generaltranslation' as objects
64
- if (props['data-generaltranslation']) {
65
- const generaltranslation = props['data-generaltranslation'];
66
- let result = Object.assign({}, generaltranslation);
67
- if (generaltranslation.transformation && generaltranslation.transformation === "variable") {
68
- const variableName = props.name || defaultVariableNames_1.default[generaltranslation.variableType] || "value";
69
- return { variable: generaltranslation.variableType || "variable", key: variableName };
70
- }
71
- // Write all the branches as objects
72
- if (generaltranslation.transformation && generaltranslation.branches) {
73
- const transformation = generaltranslation.transformation;
74
- // Write the branches of a number variable transformation
75
- if (transformation === "numeric") {
76
- const _a = generaltranslation.branches, { ranges } = _a, others = __rest(_a, ["ranges"]);
77
- if (ranges) {
78
- result.branches.ranges = ranges.map((range) => {
79
- return { min: range.min, max: range.max, children: writeChildrenAsObjects(range.children) };
80
- });
81
- }
82
- for (const option of Object.keys(others)) {
83
- result.branches[option] = writeChildrenAsObjects(others[option]);
84
- }
85
- }
86
- // Write the branches of a value variable transformation
87
- else if (transformation === "value") {
88
- if (generaltranslation.branches) {
89
- result.branches = (0, processBranches_1.default)(generaltranslation.branches, (branch) => writeChildrenAsObjects(branch));
90
- }
91
- }
92
- // Write defaultChildren
93
- if (generaltranslation.defaultChildren) {
94
- result.defaultChildren = writeChildrenAsObjects(generaltranslation.defaultChildren);
95
- }
96
- }
97
- newProps['data-generaltranslation'] = result;
98
- }
99
- return {
100
- type: getTagName(child),
101
- props: newProps
102
- };
103
- };
104
- /**
105
- * Handles processing of a single child, determining if it is a valid React element or an object.
106
- * @param {any} child - The child to process.
107
- * @returns {object} - The processed child or the original child if no transformation is needed.
108
- */
109
- const handleSingleChild = (child) => {
110
- if (react_1.default.isValidElement(child))
111
- return handleValidReactElement(child);
112
- else if (child && typeof child === 'object') {
113
- return { variable: true, keys: Object.keys(child) };
114
- }
115
- else
116
- return child;
117
- };
118
- /**
119
- * Transforms children elements into objects, processing each child recursively if needed.
120
- * @param {Children} children - The children to process.
121
- * @returns {object} - The processed children as objects.
122
- */
123
- function writeChildrenAsObjects(children) {
124
- if (Array.isArray(children)) {
125
- return children.map(child => handleSingleChild(child));
126
- }
127
- return handleSingleChild(children);
128
- }
129
- //# sourceMappingURL=writeChildrenAsObjects.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"writeChildrenAsObjects.js","sourceRoot":"","sources":["../../../src/i18n/helpers/writeChildrenAsOb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AC;AACtB,CAAC,CAAA;AAED;;;;EAIE;AACF,SAAwB,sBAAsB,CAAC,QAAkB;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAA;IAC1D,CAAC;IACD,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAA;AACtC,CAAC"}
@@ -1,24 +0,0 @@
1
- import { ReactNode } from 'react';
2
- type TargetElement = Record<string, any>;
3
- type TargetChild = TargetElement | string | number | boolean | object;
4
- type Target = TargetChild | TargetChild[];
5
- type SourceChild = ReactNode | Record<string, any>;
6
- type Source = SourceChild | SourceChild[];
7
- /**
8
- * Renders children elements based on the provided source and target.
9
- * Handles transformations and branching for number and value variables.
10
- *
11
- * @param {Source} source - The source elements to be rendered.
12
- * @param {Target} [target] - The target elements that may alter the rendering of the source.
13
- * @param {Record<string, Source>} [variables] - An optional set of variables for transformations and branching.
14
- *
15
- * @returns {ReactNode} The rendered children elements.
16
- */
17
- export default function renderChildren({ source, target, ...metadata }: {
18
- source: Source;
19
- target?: Target;
20
- variables?: Record<string, Source>;
21
- [key: string]: any;
22
- }): ReactNode;
23
- export {};
24
- //# sourceMappingURL=renderChildren.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderChildren.d.ts","sourceRoot":"","sources":["../../src/i18n/renderChildren.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAgB,SAAS,EAAE,MAAM,OAAO,CAAA;AAWtD,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACzC,KAAK,WAAW,GAAG,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AACtE,KAAK,MAAM,GAAG,WAAW,GAAG,WAAW,EAAE,CAAC;AAE1C,KAAK,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACnD,KAAK,MAAM,GAAG,WAAW,GAAG,WAAW,EAAE,CAAC;AA6E1C;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACnC,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAC9B,EAAE;IACC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACrB,GAAG,SAAS,CAoGZ"}