@team-monolith/cds 1.129.2-alpha.2 → 1.130.0-alpha

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 (105) hide show
  1. package/dist/emotion.d.ts +185 -0
  2. package/dist/index.d.ts +8 -1
  3. package/dist/patterns/LexicalEditor/LexicalCustomConfigContext.d.ts +1 -0
  4. package/dist/patterns/LexicalEditor/LexicalCustomConfigContext.js +2 -1
  5. package/dist/patterns/LexicalEditor/LexicalEditor.d.ts +4 -0
  6. package/dist/patterns/LexicalEditor/LexicalEditor.js +9 -7
  7. package/dist/patterns/LexicalEditor/Plugins.d.ts +1 -0
  8. package/dist/patterns/LexicalEditor/Plugins.js +65 -61
  9. package/dist/patterns/LexicalEditor/components/FileSelectInput.js +24 -23
  10. package/dist/patterns/LexicalEditor/components/UploadFileDialog/UploadFileDialog.js +2 -1
  11. package/dist/patterns/LexicalEditor/nodes/FileNode/CompactFileView.d.ts +7 -0
  12. package/dist/patterns/LexicalEditor/nodes/FileNode/CompactFileView.js +53 -0
  13. package/dist/patterns/LexicalEditor/nodes/FileNode/FileComponent.d.ts +0 -27
  14. package/dist/patterns/LexicalEditor/nodes/FileNode/FileComponent.js +44 -115
  15. package/dist/patterns/LexicalEditor/nodes/FileNode/FileDownloadButton.js +1 -1
  16. package/dist/patterns/LexicalEditor/nodes/FileNode/fileStyles.d.ts +27 -0
  17. package/dist/patterns/LexicalEditor/nodes/FileNode/fileStyles.js +85 -0
  18. package/dist/patterns/LexicalEditor/nodes/ImageNode/CompactImageView.d.ts +6 -0
  19. package/dist/patterns/LexicalEditor/nodes/ImageNode/CompactImageView.js +91 -0
  20. package/dist/patterns/LexicalEditor/nodes/ImageNode/ImageComponent.js +108 -102
  21. package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/InputComponent.js +7 -7
  22. package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectComponent.js +4 -4
  23. package/dist/patterns/LexicalEditor/nodes/SheetInputNode/InputComponent.js +4 -4
  24. package/dist/patterns/LexicalEditor/nodes/SheetSelectNode/SelectComponent/SelectComponent.js +4 -4
  25. package/dist/patterns/LexicalEditor/plugins/CompactToolbarPlugin/CompactToolbarPlugin.d.ts +1 -0
  26. package/dist/patterns/LexicalEditor/plugins/CompactToolbarPlugin/CompactToolbarPlugin.js +106 -0
  27. package/dist/patterns/LexicalEditor/plugins/CompactToolbarPlugin/compactAttachmentNodes.d.ts +8 -0
  28. package/dist/patterns/LexicalEditor/plugins/CompactToolbarPlugin/compactAttachmentNodes.js +6 -0
  29. package/dist/patterns/LexicalEditor/plugins/CompactToolbarPlugin/index.d.ts +1 -0
  30. package/dist/patterns/LexicalEditor/plugins/DragDropPastePlugin/index.js +15 -14
  31. package/dist/patterns/LexicalEditor/uploadConstants.d.ts +6 -0
  32. package/dist/patterns/LexicalEditor/uploadConstants.js +4 -0
  33. package/package.json +3 -7
  34. package/@types/emotion.d.ts +0 -197
  35. package/node_modules/react-i18next/.eslintrc.json +0 -74
  36. package/node_modules/react-i18next/.husky/pre-commit +0 -1
  37. package/node_modules/react-i18next/.prettierignore +0 -4
  38. package/node_modules/react-i18next/CHANGELOG.md +0 -1433
  39. package/node_modules/react-i18next/LICENSE +0 -22
  40. package/node_modules/react-i18next/README.md +0 -181
  41. package/node_modules/react-i18next/TransWithoutContext.d.mts +0 -1
  42. package/node_modules/react-i18next/TransWithoutContext.d.ts +0 -129
  43. package/node_modules/react-i18next/dist/amd/react-i18next.js +0 -867
  44. package/node_modules/react-i18next/dist/amd/react-i18next.min.js +0 -1
  45. package/node_modules/react-i18next/dist/commonjs/I18nextProvider.js +0 -21
  46. package/node_modules/react-i18next/dist/commonjs/Trans.js +0 -54
  47. package/node_modules/react-i18next/dist/commonjs/TransWithoutContext.js +0 -330
  48. package/node_modules/react-i18next/dist/commonjs/Translation.js +0 -19
  49. package/node_modules/react-i18next/dist/commonjs/context.js +0 -81
  50. package/node_modules/react-i18next/dist/commonjs/defaults.js +0 -26
  51. package/node_modules/react-i18next/dist/commonjs/i18nInstance.js +0 -13
  52. package/node_modules/react-i18next/dist/commonjs/index.js +0 -128
  53. package/node_modules/react-i18next/dist/commonjs/initReactI18next.js +0 -15
  54. package/node_modules/react-i18next/dist/commonjs/unescape.js +0 -32
  55. package/node_modules/react-i18next/dist/commonjs/useSSR.js +0 -34
  56. package/node_modules/react-i18next/dist/commonjs/useTranslation.js +0 -114
  57. package/node_modules/react-i18next/dist/commonjs/utils.js +0 -76
  58. package/node_modules/react-i18next/dist/commonjs/withSSR.js +0 -27
  59. package/node_modules/react-i18next/dist/commonjs/withTranslation.js +0 -39
  60. package/node_modules/react-i18next/dist/es/I18nextProvider.js +0 -15
  61. package/node_modules/react-i18next/dist/es/Trans.js +0 -43
  62. package/node_modules/react-i18next/dist/es/TransWithoutContext.js +0 -321
  63. package/node_modules/react-i18next/dist/es/Translation.js +0 -12
  64. package/node_modules/react-i18next/dist/es/context.js +0 -42
  65. package/node_modules/react-i18next/dist/es/defaults.js +0 -18
  66. package/node_modules/react-i18next/dist/es/i18nInstance.js +0 -5
  67. package/node_modules/react-i18next/dist/es/index.js +0 -18
  68. package/node_modules/react-i18next/dist/es/initReactI18next.js +0 -9
  69. package/node_modules/react-i18next/dist/es/package.json +0 -1
  70. package/node_modules/react-i18next/dist/es/unescape.js +0 -25
  71. package/node_modules/react-i18next/dist/es/useSSR.js +0 -27
  72. package/node_modules/react-i18next/dist/es/useTranslation.js +0 -107
  73. package/node_modules/react-i18next/dist/es/utils.js +0 -62
  74. package/node_modules/react-i18next/dist/es/withSSR.js +0 -20
  75. package/node_modules/react-i18next/dist/es/withTranslation.js +0 -32
  76. package/node_modules/react-i18next/dist/umd/react-i18next.js +0 -871
  77. package/node_modules/react-i18next/dist/umd/react-i18next.min.js +0 -1
  78. package/node_modules/react-i18next/helpers.d.ts +0 -3
  79. package/node_modules/react-i18next/icu.macro.d.mts +0 -1
  80. package/node_modules/react-i18next/icu.macro.d.ts +0 -103
  81. package/node_modules/react-i18next/icu.macro.js +0 -729
  82. package/node_modules/react-i18next/index.d.mts +0 -1
  83. package/node_modules/react-i18next/index.d.ts +0 -209
  84. package/node_modules/react-i18next/initReactI18next.d.mts +0 -1
  85. package/node_modules/react-i18next/initReactI18next.d.ts +0 -3
  86. package/node_modules/react-i18next/lint-staged.config.mjs +0 -4
  87. package/node_modules/react-i18next/package.json +0 -167
  88. package/node_modules/react-i18next/react-i18next.js +0 -871
  89. package/node_modules/react-i18next/react-i18next.min.js +0 -1
  90. package/node_modules/react-i18next/src/I18nextProvider.js +0 -7
  91. package/node_modules/react-i18next/src/Trans.js +0 -45
  92. package/node_modules/react-i18next/src/TransWithoutContext.js +0 -479
  93. package/node_modules/react-i18next/src/Translation.js +0 -14
  94. package/node_modules/react-i18next/src/context.js +0 -54
  95. package/node_modules/react-i18next/src/defaults.js +0 -20
  96. package/node_modules/react-i18next/src/i18nInstance.js +0 -7
  97. package/node_modules/react-i18next/src/index.js +0 -22
  98. package/node_modules/react-i18next/src/initReactI18next.js +0 -11
  99. package/node_modules/react-i18next/src/unescape.js +0 -31
  100. package/node_modules/react-i18next/src/useSSR.js +0 -33
  101. package/node_modules/react-i18next/src/useTranslation.js +0 -171
  102. package/node_modules/react-i18next/src/utils.js +0 -93
  103. package/node_modules/react-i18next/src/withSSR.js +0 -21
  104. package/node_modules/react-i18next/src/withTranslation.js +0 -35
  105. package/node_modules/react-i18next/vitest.workspace.typescript.mts +0 -52
@@ -1,867 +0,0 @@
1
- define(['exports', 'react'], (function (exports, react) { 'use strict';
2
-
3
- function getDefaultExportFromCjs (x) {
4
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
- }
6
-
7
- var voidElements = {
8
- "area": true,
9
- "base": true,
10
- "br": true,
11
- "col": true,
12
- "embed": true,
13
- "hr": true,
14
- "img": true,
15
- "input": true,
16
- "link": true,
17
- "meta": true,
18
- "param": true,
19
- "source": true,
20
- "track": true,
21
- "wbr": true
22
- };
23
-
24
- var e = /*@__PURE__*/getDefaultExportFromCjs(voidElements);
25
-
26
- var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
27
- function n(n) {
28
- var r = {
29
- type: "tag",
30
- name: "",
31
- voidElement: false,
32
- attrs: {},
33
- children: []
34
- },
35
- i = n.match(/<\/?([^\s]+?)[/\s>]/);
36
- if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = true), r.name.startsWith("!--"))) {
37
- var s = n.indexOf("--\x3e");
38
- return {
39
- type: "comment",
40
- comment: -1 !== s ? n.slice(4, s) : ""
41
- };
42
- }
43
- for (var a = new RegExp(t), c = null; null !== (c = a.exec(n));) if (c[0].trim()) if (c[1]) {
44
- var o = c[1].trim(),
45
- l = [o, ""];
46
- o.indexOf("=") > -1 && (l = o.split("=")), r.attrs[l[0]] = l[1], a.lastIndex--;
47
- } else c[2] && (r.attrs[c[2]] = c[3].trim().substring(1, c[3].length - 1));
48
- return r;
49
- }
50
- var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,
51
- i = /^\s*$/,
52
- s = Object.create(null);
53
- function a(e, t) {
54
- switch (t.type) {
55
- case "text":
56
- return e + t.content;
57
- case "tag":
58
- return e += "<" + t.name + (t.attrs ? function (e) {
59
- var t = [];
60
- for (var n in e) t.push(n + '="' + e[n] + '"');
61
- return t.length ? " " + t.join(" ") : "";
62
- }(t.attrs) : "") + (t.voidElement ? "/>" : ">"), t.voidElement ? e : e + t.children.reduce(a, "") + "</" + t.name + ">";
63
- case "comment":
64
- return e + "\x3c!--" + t.comment + "--\x3e";
65
- }
66
- }
67
- var c = {
68
- parse: function (e, t) {
69
- t || (t = {}), t.components || (t.components = s);
70
- var a,
71
- c = [],
72
- o = [],
73
- l = -1,
74
- m = false;
75
- if (0 !== e.indexOf("<")) {
76
- var u = e.indexOf("<");
77
- c.push({
78
- type: "text",
79
- content: -1 === u ? e : e.substring(0, u)
80
- });
81
- }
82
- return e.replace(r, function (r, s) {
83
- if (m) {
84
- if (r !== "</" + a.name + ">") return;
85
- m = false;
86
- }
87
- var u,
88
- f = "/" !== r.charAt(1),
89
- h = r.startsWith("\x3c!--"),
90
- p = s + r.length,
91
- d = e.charAt(p);
92
- if (h) {
93
- var v = n(r);
94
- return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c);
95
- }
96
- if (f && (l++, "tag" === (a = n(r)).type && t.components[a.name] && (a.type = "component", m = true), a.voidElement || m || !d || "<" === d || a.children.push({
97
- type: "text",
98
- content: e.slice(p, e.indexOf("<", p))
99
- }), 0 === l && c.push(a), (u = o[l - 1]) && u.children.push(a), o[l] = a), (!f || a.voidElement) && (l > -1 && (a.voidElement || a.name === r.slice(2, -1)) && (l--, a = -1 === l ? c : o[l]), !m && "<" !== d && d)) {
100
- u = -1 === l ? c : o[l].children;
101
- var x = e.indexOf("<", p),
102
- g = e.slice(p, -1 === x ? void 0 : x);
103
- i.test(g) && (g = " "), (x > -1 && l + u.length >= 0 || " " !== g) && u.push({
104
- type: "text",
105
- content: g
106
- });
107
- }
108
- }), c;
109
- },
110
- stringify: function (e) {
111
- return e.reduce(function (e, t) {
112
- return e + a("", t);
113
- }, "");
114
- }
115
- };
116
-
117
- const warn = (i18n, code, msg, rest) => {
118
- const args = [msg, {
119
- code,
120
- ...(rest || {})
121
- }];
122
- if (i18n?.services?.logger?.forward) {
123
- return i18n.services.logger.forward(args, 'warn', 'react-i18next::', true);
124
- }
125
- if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
126
- if (i18n?.services?.logger?.warn) {
127
- i18n.services.logger.warn(...args);
128
- } else if (console?.warn) {
129
- console.warn(...args);
130
- }
131
- };
132
- const alreadyWarned = {};
133
- const warnOnce = (i18n, code, msg, rest) => {
134
- if (isString(msg) && alreadyWarned[msg]) return;
135
- if (isString(msg)) alreadyWarned[msg] = new Date();
136
- warn(i18n, code, msg, rest);
137
- };
138
- const loadedClb = (i18n, cb) => () => {
139
- if (i18n.isInitialized) {
140
- cb();
141
- } else {
142
- const initialized = () => {
143
- setTimeout(() => {
144
- i18n.off('initialized', initialized);
145
- }, 0);
146
- cb();
147
- };
148
- i18n.on('initialized', initialized);
149
- }
150
- };
151
- const loadNamespaces = (i18n, ns, cb) => {
152
- i18n.loadNamespaces(ns, loadedClb(i18n, cb));
153
- };
154
- const loadLanguages = (i18n, lng, ns, cb) => {
155
- if (isString(ns)) ns = [ns];
156
- if (i18n.options.preload && i18n.options.preload.indexOf(lng) > -1) return loadNamespaces(i18n, ns, cb);
157
- ns.forEach(n => {
158
- if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
159
- });
160
- i18n.loadLanguages(lng, loadedClb(i18n, cb));
161
- };
162
- const hasLoadedNamespace = (ns, i18n, options = {}) => {
163
- if (!i18n.languages || !i18n.languages.length) {
164
- warnOnce(i18n, 'NO_LANGUAGES', 'i18n.languages were undefined or empty', {
165
- languages: i18n.languages
166
- });
167
- return true;
168
- }
169
- return i18n.hasLoadedNamespace(ns, {
170
- lng: options.lng,
171
- precheck: (i18nInstance, loadNotPending) => {
172
- if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
173
- }
174
- });
175
- };
176
- const getDisplayName = Component => Component.displayName || Component.name || (isString(Component) && Component.length > 0 ? Component : 'Unknown');
177
- const isString = obj => typeof obj === 'string';
178
- const isObject = obj => typeof obj === 'object' && obj !== null;
179
-
180
- const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
181
- const htmlEntities = {
182
- '&amp;': '&',
183
- '&#38;': '&',
184
- '&lt;': '<',
185
- '&#60;': '<',
186
- '&gt;': '>',
187
- '&#62;': '>',
188
- '&apos;': "'",
189
- '&#39;': "'",
190
- '&quot;': '"',
191
- '&#34;': '"',
192
- '&nbsp;': ' ',
193
- '&#160;': ' ',
194
- '&copy;': '©',
195
- '&#169;': '©',
196
- '&reg;': '®',
197
- '&#174;': '®',
198
- '&hellip;': '…',
199
- '&#8230;': '…',
200
- '&#x2F;': '/',
201
- '&#47;': '/'
202
- };
203
- const unescapeHtmlEntity = m => htmlEntities[m];
204
- const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
205
-
206
- let defaultOptions = {
207
- bindI18n: 'languageChanged',
208
- bindI18nStore: '',
209
- transEmptyNodeValue: '',
210
- transSupportBasicHtmlNodes: true,
211
- transWrapTextNodes: '',
212
- transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
213
- useSuspense: true,
214
- unescape
215
- };
216
- const setDefaults = (options = {}) => {
217
- defaultOptions = {
218
- ...defaultOptions,
219
- ...options
220
- };
221
- };
222
- const getDefaults = () => defaultOptions;
223
-
224
- let i18nInstance;
225
- const setI18n = instance => {
226
- i18nInstance = instance;
227
- };
228
- const getI18n = () => i18nInstance;
229
-
230
- const hasChildren = (node, checkLength) => {
231
- if (!node) return false;
232
- const base = node.props?.children ?? node.children;
233
- if (checkLength) return base.length > 0;
234
- return !!base;
235
- };
236
- const getChildren = node => {
237
- if (!node) return [];
238
- const children = node.props?.children ?? node.children;
239
- return node.props?.i18nIsDynamicList ? getAsArray(children) : children;
240
- };
241
- const hasValidReactChildren = children => Array.isArray(children) && children.every(react.isValidElement);
242
- const getAsArray = data => Array.isArray(data) ? data : [data];
243
- const mergeProps = (source, target) => {
244
- const newTarget = {
245
- ...target
246
- };
247
- newTarget.props = Object.assign(source.props, target.props);
248
- return newTarget;
249
- };
250
- const nodesToString = (children, i18nOptions, i18n, i18nKey) => {
251
- if (!children) return '';
252
- let stringNode = '';
253
- const childrenArray = getAsArray(children);
254
- const keepArray = i18nOptions?.transSupportBasicHtmlNodes ? i18nOptions.transKeepBasicHtmlNodesFor ?? [] : [];
255
- childrenArray.forEach((child, childIndex) => {
256
- if (isString(child)) {
257
- stringNode += `${child}`;
258
- return;
259
- }
260
- if (react.isValidElement(child)) {
261
- const {
262
- props,
263
- type
264
- } = child;
265
- const childPropsCount = Object.keys(props).length;
266
- const shouldKeepChild = keepArray.indexOf(type) > -1;
267
- const childChildren = props.children;
268
- if (!childChildren && shouldKeepChild && !childPropsCount) {
269
- stringNode += `<${type}/>`;
270
- return;
271
- }
272
- if (!childChildren && (!shouldKeepChild || childPropsCount) || props.i18nIsDynamicList) {
273
- stringNode += `<${childIndex}></${childIndex}>`;
274
- return;
275
- }
276
- if (shouldKeepChild && childPropsCount === 1 && isString(childChildren)) {
277
- stringNode += `<${type}>${childChildren}</${type}>`;
278
- return;
279
- }
280
- const content = nodesToString(childChildren, i18nOptions, i18n, i18nKey);
281
- stringNode += `<${childIndex}>${content}</${childIndex}>`;
282
- return;
283
- }
284
- if (child === null) {
285
- warn(i18n, 'TRANS_NULL_VALUE', `Passed in a null value as child`, {
286
- i18nKey
287
- });
288
- return;
289
- }
290
- if (isObject(child)) {
291
- const {
292
- format,
293
- ...clone
294
- } = child;
295
- const keys = Object.keys(clone);
296
- if (keys.length === 1) {
297
- const value = format ? `${keys[0]}, ${format}` : keys[0];
298
- stringNode += `{{${value}}}`;
299
- return;
300
- }
301
- warn(i18n, 'TRANS_INVALID_OBJ', `Invalid child - Object should only have keys {{ value, format }} (format is optional).`, {
302
- i18nKey,
303
- child
304
- });
305
- return;
306
- }
307
- warn(i18n, 'TRANS_INVALID_VAR', `Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`, {
308
- i18nKey,
309
- child
310
- });
311
- });
312
- return stringNode;
313
- };
314
- const renderNodes = (children, knownComponentsMap, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) => {
315
- if (targetString === '') return [];
316
- const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
317
- const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString);
318
- if (!children && !knownComponentsMap && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString];
319
- const data = knownComponentsMap ?? {};
320
- const getData = childs => {
321
- const childrenArray = getAsArray(childs);
322
- childrenArray.forEach(child => {
323
- if (isString(child)) return;
324
- if (hasChildren(child)) getData(getChildren(child));else if (isObject(child) && !react.isValidElement(child)) Object.assign(data, child);
325
- });
326
- };
327
- getData(children);
328
- const ast = c.parse(`<0>${targetString}</0>`);
329
- const opts = {
330
- ...data,
331
- ...combinedTOpts
332
- };
333
- const renderInner = (child, node, rootReactNode) => {
334
- const childs = getChildren(child);
335
- const mappedChildren = mapAST(childs, node.children, rootReactNode);
336
- return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props?.i18nIsDynamicList ? childs : mappedChildren;
337
- };
338
- const pushTranslatedJSX = (child, inner, mem, i, isVoid) => {
339
- if (child.dummy) {
340
- child.children = inner;
341
- mem.push(react.cloneElement(child, {
342
- key: i
343
- }, isVoid ? undefined : inner));
344
- } else {
345
- mem.push(...react.Children.map([child], c => {
346
- const props = {
347
- ...c.props
348
- };
349
- delete props.i18nIsDynamicList;
350
- return react.createElement(c.type, {
351
- ...props,
352
- key: i,
353
- ref: c.props.ref ?? c.ref
354
- }, isVoid ? null : inner);
355
- }));
356
- }
357
- };
358
- const mapAST = (reactNode, astNode, rootReactNode) => {
359
- const reactNodes = getAsArray(reactNode);
360
- const astNodes = getAsArray(astNode);
361
- return astNodes.reduce((mem, node, i) => {
362
- const translationContent = node.children?.[0]?.content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
363
- if (node.type === 'tag') {
364
- let tmp = reactNodes[parseInt(node.name, 10)];
365
- if (!tmp && knownComponentsMap) tmp = knownComponentsMap[node.name];
366
- if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name];
367
- if (!tmp) tmp = {};
368
- const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
369
- props: node.attrs
370
- }, tmp) : tmp;
371
- const isElement = react.isValidElement(child);
372
- const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
373
- const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && isObject(child) && child.dummy && !isElement;
374
- const isKnownComponent = isObject(knownComponentsMap) && Object.hasOwnProperty.call(knownComponentsMap, node.name);
375
- if (isString(child)) {
376
- const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
377
- mem.push(value);
378
- } else if (hasChildren(child) || isValidTranslationWithChildren) {
379
- const inner = renderInner(child, node, rootReactNode);
380
- pushTranslatedJSX(child, inner, mem, i);
381
- } else if (isEmptyTransWithHTML) {
382
- const inner = mapAST(reactNodes, node.children, rootReactNode);
383
- pushTranslatedJSX(child, inner, mem, i);
384
- } else if (Number.isNaN(parseFloat(node.name))) {
385
- if (isKnownComponent) {
386
- const inner = renderInner(child, node, rootReactNode);
387
- pushTranslatedJSX(child, inner, mem, i, node.voidElement);
388
- } else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
389
- if (node.voidElement) {
390
- mem.push(react.createElement(node.name, {
391
- key: `${node.name}-${i}`
392
- }));
393
- } else {
394
- const inner = mapAST(reactNodes, node.children, rootReactNode);
395
- mem.push(react.createElement(node.name, {
396
- key: `${node.name}-${i}`
397
- }, inner));
398
- }
399
- } else if (node.voidElement) {
400
- mem.push(`<${node.name} />`);
401
- } else {
402
- const inner = mapAST(reactNodes, node.children, rootReactNode);
403
- mem.push(`<${node.name}>${inner}</${node.name}>`);
404
- }
405
- } else if (isObject(child) && !isElement) {
406
- const content = node.children[0] ? translationContent : null;
407
- if (content) mem.push(content);
408
- } else {
409
- pushTranslatedJSX(child, translationContent, mem, i, node.children.length !== 1 || !translationContent);
410
- }
411
- } else if (node.type === 'text') {
412
- const wrapTextNodes = i18nOptions.transWrapTextNodes;
413
- const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
414
- if (wrapTextNodes) {
415
- mem.push(react.createElement(wrapTextNodes, {
416
- key: `${node.name}-${i}`
417
- }, content));
418
- } else {
419
- mem.push(content);
420
- }
421
- }
422
- return mem;
423
- }, []);
424
- };
425
- const result = mapAST([{
426
- dummy: true,
427
- children: children || []
428
- }], ast, getAsArray(children || []));
429
- return getChildren(result[0]);
430
- };
431
- const fixComponentProps = (component, index, translation) => {
432
- const componentKey = component.key || index;
433
- const comp = react.cloneElement(component, {
434
- key: componentKey
435
- });
436
- if (!comp.props || !comp.props.children || translation.indexOf(`${index}/>`) < 0 && translation.indexOf(`${index} />`) < 0) {
437
- return comp;
438
- }
439
- function Componentized() {
440
- return react.createElement(react.Fragment, null, comp);
441
- }
442
- return react.createElement(Componentized, {
443
- key: componentKey
444
- });
445
- };
446
- const generateArrayComponents = (components, translation) => components.map((c, index) => fixComponentProps(c, index, translation));
447
- const generateObjectComponents = (components, translation) => {
448
- const componentMap = {};
449
- Object.keys(components).forEach(c => {
450
- Object.assign(componentMap, {
451
- [c]: fixComponentProps(components[c], c, translation)
452
- });
453
- });
454
- return componentMap;
455
- };
456
- const generateComponents = (components, translation, i18n, i18nKey) => {
457
- if (!components) return null;
458
- if (Array.isArray(components)) {
459
- return generateArrayComponents(components, translation);
460
- }
461
- if (isObject(components)) {
462
- return generateObjectComponents(components, translation);
463
- }
464
- warnOnce(i18n, 'TRANS_INVALID_COMPONENTS', `<Trans /> "components" prop expects an object or array`, {
465
- i18nKey
466
- });
467
- return null;
468
- };
469
- const isComponentsMap = object => {
470
- if (!isObject(object)) return false;
471
- if (Array.isArray(object)) return false;
472
- return Object.keys(object).reduce((acc, key) => acc && Number.isNaN(Number.parseFloat(key)), true);
473
- };
474
- function Trans$1({
475
- children,
476
- count,
477
- parent,
478
- i18nKey,
479
- context,
480
- tOptions = {},
481
- values,
482
- defaults,
483
- components,
484
- ns,
485
- i18n: i18nFromProps,
486
- t: tFromProps,
487
- shouldUnescape,
488
- ...additionalProps
489
- }) {
490
- const i18n = i18nFromProps || getI18n();
491
- if (!i18n) {
492
- warnOnce(i18n, 'NO_I18NEXT_INSTANCE', `Trans: You need to pass in an i18next instance using i18nextReactModule`, {
493
- i18nKey
494
- });
495
- return children;
496
- }
497
- const t = tFromProps || i18n.t.bind(i18n) || (k => k);
498
- const reactI18nextOptions = {
499
- ...getDefaults(),
500
- ...i18n.options?.react
501
- };
502
- let namespaces = ns || t.ns || i18n.options?.defaultNS;
503
- namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
504
- const nodeAsString = nodesToString(children, reactI18nextOptions, i18n, i18nKey);
505
- const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey;
506
- const {
507
- hashTransKey
508
- } = reactI18nextOptions;
509
- const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue);
510
- if (i18n.options?.interpolation?.defaultVariables) {
511
- values = values && Object.keys(values).length > 0 ? {
512
- ...values,
513
- ...i18n.options.interpolation.defaultVariables
514
- } : {
515
- ...i18n.options.interpolation.defaultVariables
516
- };
517
- }
518
- const interpolationOverride = values || count !== undefined && !i18n.options?.interpolation?.alwaysFormat || !children ? tOptions.interpolation : {
519
- interpolation: {
520
- ...tOptions.interpolation,
521
- prefix: '#$?',
522
- suffix: '?$#'
523
- }
524
- };
525
- const combinedTOpts = {
526
- ...tOptions,
527
- context: context || tOptions.context,
528
- count,
529
- ...values,
530
- ...interpolationOverride,
531
- defaultValue,
532
- ns: namespaces
533
- };
534
- const translation = key ? t(key, combinedTOpts) : defaultValue;
535
- const generatedComponents = generateComponents(components, translation, i18n, i18nKey);
536
- let indexedChildren = generatedComponents || children;
537
- let componentsMap = null;
538
- if (isComponentsMap(generatedComponents)) {
539
- componentsMap = generatedComponents;
540
- indexedChildren = children;
541
- }
542
- const content = renderNodes(indexedChildren, componentsMap, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
543
- const useAsParent = parent ?? reactI18nextOptions.defaultTransParent;
544
- return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
545
- }
546
-
547
- const initReactI18next = {
548
- type: '3rdParty',
549
- init(instance) {
550
- setDefaults(instance.options.react);
551
- setI18n(instance);
552
- }
553
- };
554
-
555
- const I18nContext = react.createContext();
556
- class ReportNamespaces {
557
- constructor() {
558
- this.usedNamespaces = {};
559
- }
560
- addUsedNamespaces(namespaces) {
561
- namespaces.forEach(ns => {
562
- if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
563
- });
564
- }
565
- getUsedNamespaces() {
566
- return Object.keys(this.usedNamespaces);
567
- }
568
- }
569
- const composeInitialProps = ForComponent => async ctx => {
570
- const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {};
571
- const i18nInitialProps = getInitialProps();
572
- return {
573
- ...componentsInitialProps,
574
- ...i18nInitialProps
575
- };
576
- };
577
- const getInitialProps = () => {
578
- const i18n = getI18n();
579
- const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? [];
580
- const ret = {};
581
- const initialI18nStore = {};
582
- i18n.languages.forEach(l => {
583
- initialI18nStore[l] = {};
584
- namespaces.forEach(ns => {
585
- initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
586
- });
587
- });
588
- ret.initialI18nStore = initialI18nStore;
589
- ret.initialLanguage = i18n.language;
590
- return ret;
591
- };
592
-
593
- function Trans({
594
- children,
595
- count,
596
- parent,
597
- i18nKey,
598
- context,
599
- tOptions = {},
600
- values,
601
- defaults,
602
- components,
603
- ns,
604
- i18n: i18nFromProps,
605
- t: tFromProps,
606
- shouldUnescape,
607
- ...additionalProps
608
- }) {
609
- const {
610
- i18n: i18nFromContext,
611
- defaultNS: defaultNSFromContext
612
- } = react.useContext(I18nContext) || {};
613
- const i18n = i18nFromProps || i18nFromContext || getI18n();
614
- const t = tFromProps || i18n?.t.bind(i18n);
615
- return Trans$1({
616
- children,
617
- count,
618
- parent,
619
- i18nKey,
620
- context,
621
- tOptions,
622
- values,
623
- defaults,
624
- components,
625
- ns: ns || t?.ns || defaultNSFromContext || i18n?.options?.defaultNS,
626
- i18n,
627
- t: tFromProps,
628
- shouldUnescape,
629
- ...additionalProps
630
- });
631
- }
632
-
633
- const usePrevious = (value, ignore) => {
634
- const ref = react.useRef();
635
- react.useEffect(() => {
636
- ref.current = value;
637
- }, [value, ignore]);
638
- return ref.current;
639
- };
640
- const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
641
- const useMemoizedT = (i18n, language, namespace, keyPrefix) => react.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
642
- const useTranslation = (ns, props = {}) => {
643
- const {
644
- i18n: i18nFromProps
645
- } = props;
646
- const {
647
- i18n: i18nFromContext,
648
- defaultNS: defaultNSFromContext
649
- } = react.useContext(I18nContext) || {};
650
- const i18n = i18nFromProps || i18nFromContext || getI18n();
651
- if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
652
- if (!i18n) {
653
- warnOnce(i18n, 'NO_I18NEXT_INSTANCE', 'useTranslation: You will need to pass in an i18next instance by using initReactI18next');
654
- const notReadyT = (k, optsOrDefaultValue) => {
655
- if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
656
- if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
657
- return Array.isArray(k) ? k[k.length - 1] : k;
658
- };
659
- const retNotReady = [notReadyT, {}, false];
660
- retNotReady.t = notReadyT;
661
- retNotReady.i18n = {};
662
- retNotReady.ready = false;
663
- return retNotReady;
664
- }
665
- if (i18n.options.react?.wait) warnOnce(i18n, 'DEPRECATED_OPTION', 'useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
666
- const i18nOptions = {
667
- ...getDefaults(),
668
- ...i18n.options.react,
669
- ...props
670
- };
671
- const {
672
- useSuspense,
673
- keyPrefix
674
- } = i18nOptions;
675
- let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS;
676
- namespaces = isString(namespaces) ? [namespaces] : namespaces || ['translation'];
677
- i18n.reportNamespaces.addUsedNamespaces?.(namespaces);
678
- const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
679
- const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
680
- const getT = () => memoGetT;
681
- const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
682
- const [t, setT] = react.useState(getT);
683
- let joinedNS = namespaces.join();
684
- if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
685
- const previousJoinedNS = usePrevious(joinedNS);
686
- const isMounted = react.useRef(true);
687
- react.useEffect(() => {
688
- const {
689
- bindI18n,
690
- bindI18nStore
691
- } = i18nOptions;
692
- isMounted.current = true;
693
- if (!ready && !useSuspense) {
694
- if (props.lng) {
695
- loadLanguages(i18n, props.lng, namespaces, () => {
696
- if (isMounted.current) setT(getNewT);
697
- });
698
- } else {
699
- loadNamespaces(i18n, namespaces, () => {
700
- if (isMounted.current) setT(getNewT);
701
- });
702
- }
703
- }
704
- if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
705
- setT(getNewT);
706
- }
707
- const boundReset = () => {
708
- if (isMounted.current) setT(getNewT);
709
- };
710
- if (bindI18n) i18n?.on(bindI18n, boundReset);
711
- if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset);
712
- return () => {
713
- isMounted.current = false;
714
- if (i18n && bindI18n) bindI18n?.split(' ').forEach(e => i18n.off(e, boundReset));
715
- if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
716
- };
717
- }, [i18n, joinedNS]);
718
- react.useEffect(() => {
719
- if (isMounted.current && ready) {
720
- setT(getT);
721
- }
722
- }, [i18n, keyPrefix, ready]);
723
- const ret = [t, i18n, ready];
724
- ret.t = t;
725
- ret.i18n = i18n;
726
- ret.ready = ready;
727
- if (ready) return ret;
728
- if (!ready && !useSuspense) return ret;
729
- throw new Promise(resolve => {
730
- if (props.lng) {
731
- loadLanguages(i18n, props.lng, namespaces, () => resolve());
732
- } else {
733
- loadNamespaces(i18n, namespaces, () => resolve());
734
- }
735
- });
736
- };
737
-
738
- const withTranslation = (ns, options = {}) => function Extend(WrappedComponent) {
739
- function I18nextWithTranslation({
740
- forwardedRef,
741
- ...rest
742
- }) {
743
- const [t, i18n, ready] = useTranslation(ns, {
744
- ...rest,
745
- keyPrefix: options.keyPrefix
746
- });
747
- const passDownProps = {
748
- ...rest,
749
- t,
750
- i18n,
751
- tReady: ready
752
- };
753
- if (options.withRef && forwardedRef) {
754
- passDownProps.ref = forwardedRef;
755
- } else if (!options.withRef && forwardedRef) {
756
- passDownProps.forwardedRef = forwardedRef;
757
- }
758
- return react.createElement(WrappedComponent, passDownProps);
759
- }
760
- I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`;
761
- I18nextWithTranslation.WrappedComponent = WrappedComponent;
762
- const forwardRef = (props, ref) => react.createElement(I18nextWithTranslation, Object.assign({}, props, {
763
- forwardedRef: ref
764
- }));
765
- return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation;
766
- };
767
-
768
- const Translation = ({
769
- ns,
770
- children,
771
- ...options
772
- }) => {
773
- const [t, i18n, ready] = useTranslation(ns, options);
774
- return children(t, {
775
- i18n,
776
- lng: i18n.language
777
- }, ready);
778
- };
779
-
780
- function I18nextProvider({
781
- i18n,
782
- defaultNS,
783
- children
784
- }) {
785
- const value = react.useMemo(() => ({
786
- i18n,
787
- defaultNS
788
- }), [i18n, defaultNS]);
789
- return react.createElement(I18nContext.Provider, {
790
- value
791
- }, children);
792
- }
793
-
794
- const useSSR = (initialI18nStore, initialLanguage, props = {}) => {
795
- const {
796
- i18n: i18nFromProps
797
- } = props;
798
- const {
799
- i18n: i18nFromContext
800
- } = react.useContext(I18nContext) || {};
801
- const i18n = i18nFromProps || i18nFromContext || getI18n();
802
- if (i18n.options?.isClone) return;
803
- if (initialI18nStore && !i18n.initializedStoreOnce) {
804
- i18n.services.resourceStore.data = initialI18nStore;
805
- i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => {
806
- Object.keys(lngResources).forEach(ns => {
807
- if (mem.indexOf(ns) < 0) mem.push(ns);
808
- });
809
- return mem;
810
- }, i18n.options.ns);
811
- i18n.initializedStoreOnce = true;
812
- i18n.isInitialized = true;
813
- }
814
- if (initialLanguage && !i18n.initializedLanguageOnce) {
815
- i18n.changeLanguage(initialLanguage);
816
- i18n.initializedLanguageOnce = true;
817
- }
818
- };
819
-
820
- const withSSR = () => function Extend(WrappedComponent) {
821
- function I18nextWithSSR({
822
- initialI18nStore,
823
- initialLanguage,
824
- ...rest
825
- }) {
826
- useSSR(initialI18nStore, initialLanguage);
827
- return react.createElement(WrappedComponent, {
828
- ...rest
829
- });
830
- }
831
- I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
832
- I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`;
833
- I18nextWithSSR.WrappedComponent = WrappedComponent;
834
- return I18nextWithSSR;
835
- };
836
-
837
- const date = () => '';
838
- const time = () => '';
839
- const number = () => '';
840
- const select = () => '';
841
- const plural = () => '';
842
- const selectOrdinal = () => '';
843
-
844
- exports.I18nContext = I18nContext;
845
- exports.I18nextProvider = I18nextProvider;
846
- exports.Trans = Trans;
847
- exports.TransWithoutContext = Trans$1;
848
- exports.Translation = Translation;
849
- exports.composeInitialProps = composeInitialProps;
850
- exports.date = date;
851
- exports.getDefaults = getDefaults;
852
- exports.getI18n = getI18n;
853
- exports.getInitialProps = getInitialProps;
854
- exports.initReactI18next = initReactI18next;
855
- exports.number = number;
856
- exports.plural = plural;
857
- exports.select = select;
858
- exports.selectOrdinal = selectOrdinal;
859
- exports.setDefaults = setDefaults;
860
- exports.setI18n = setI18n;
861
- exports.time = time;
862
- exports.useSSR = useSSR;
863
- exports.useTranslation = useTranslation;
864
- exports.withSSR = withSSR;
865
- exports.withTranslation = withTranslation;
866
-
867
- }));