@serhii.olishevskyi/docs 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/UserPopoverComponent-BNJWFSLT.mjs +399 -0
- package/dist/chunk-CT3G3YSD.mjs +3863 -0
- package/dist/index.d.mts +55 -2
- package/dist/index.d.ts +55 -2
- package/dist/index.js +4381 -3507
- package/dist/index.mjs +243 -3767
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3170 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
rej = reject;
|
|
30
|
-
});
|
|
31
|
-
promise.resolve = res;
|
|
32
|
-
promise.reject = rej;
|
|
33
|
-
return promise;
|
|
34
|
-
};
|
|
35
|
-
var makeString = (object) => {
|
|
36
|
-
if (object == null) return "";
|
|
37
|
-
return String(object);
|
|
38
|
-
};
|
|
39
|
-
var copy = (a, s, t2) => {
|
|
40
|
-
a.forEach((m) => {
|
|
41
|
-
if (s[m]) t2[m] = s[m];
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var lastOfPathSeparatorRegExp = /###/g;
|
|
45
|
-
var cleanKey = (key) => key && key.includes("###") ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
|
|
46
|
-
var canNotTraverseDeeper = (object) => !object || isString(object);
|
|
47
|
-
var getLastOfPath = (object, path, Empty) => {
|
|
48
|
-
const stack = !isString(path) ? path : path.split(".");
|
|
49
|
-
let stackIndex = 0;
|
|
50
|
-
while (stackIndex < stack.length - 1) {
|
|
51
|
-
if (canNotTraverseDeeper(object)) return {};
|
|
52
|
-
const key = cleanKey(stack[stackIndex]);
|
|
53
|
-
if (!object[key] && Empty) object[key] = new Empty();
|
|
54
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
55
|
-
object = object[key];
|
|
56
|
-
} else {
|
|
57
|
-
object = {};
|
|
58
|
-
}
|
|
59
|
-
++stackIndex;
|
|
60
|
-
}
|
|
61
|
-
if (canNotTraverseDeeper(object)) return {};
|
|
62
|
-
return {
|
|
63
|
-
obj: object,
|
|
64
|
-
k: cleanKey(stack[stackIndex])
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
var setPath = (object, path, newValue) => {
|
|
68
|
-
const {
|
|
69
|
-
obj,
|
|
70
|
-
k
|
|
71
|
-
} = getLastOfPath(object, path, Object);
|
|
72
|
-
if (obj !== void 0 || path.length === 1) {
|
|
73
|
-
obj[k] = newValue;
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
let e = path[path.length - 1];
|
|
77
|
-
let p = path.slice(0, path.length - 1);
|
|
78
|
-
let last = getLastOfPath(object, p, Object);
|
|
79
|
-
while (last.obj === void 0 && p.length) {
|
|
80
|
-
e = `${p[p.length - 1]}.${e}`;
|
|
81
|
-
p = p.slice(0, p.length - 1);
|
|
82
|
-
last = getLastOfPath(object, p, Object);
|
|
83
|
-
if (last?.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") {
|
|
84
|
-
last.obj = void 0;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
last.obj[`${last.k}.${e}`] = newValue;
|
|
88
|
-
};
|
|
89
|
-
var pushPath = (object, path, newValue, concat) => {
|
|
90
|
-
const {
|
|
91
|
-
obj,
|
|
92
|
-
k
|
|
93
|
-
} = getLastOfPath(object, path, Object);
|
|
94
|
-
obj[k] = obj[k] || [];
|
|
95
|
-
obj[k].push(newValue);
|
|
96
|
-
};
|
|
97
|
-
var getPath = (object, path) => {
|
|
98
|
-
const {
|
|
99
|
-
obj,
|
|
100
|
-
k
|
|
101
|
-
} = getLastOfPath(object, path);
|
|
102
|
-
if (!obj) return void 0;
|
|
103
|
-
if (!Object.prototype.hasOwnProperty.call(obj, k)) return void 0;
|
|
104
|
-
return obj[k];
|
|
105
|
-
};
|
|
106
|
-
var getPathWithDefaults = (data, defaultData, key) => {
|
|
107
|
-
const value = getPath(data, key);
|
|
108
|
-
if (value !== void 0) {
|
|
109
|
-
return value;
|
|
110
|
-
}
|
|
111
|
-
return getPath(defaultData, key);
|
|
112
|
-
};
|
|
113
|
-
var deepExtend = (target, source, overwrite) => {
|
|
114
|
-
for (const prop in source) {
|
|
115
|
-
if (prop !== "__proto__" && prop !== "constructor") {
|
|
116
|
-
if (Object.prototype.hasOwnProperty.call(target, prop)) {
|
|
117
|
-
if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
|
|
118
|
-
if (overwrite) target[prop] = source[prop];
|
|
119
|
-
} else {
|
|
120
|
-
deepExtend(target[prop], source[prop], overwrite);
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
target[prop] = source[prop];
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return target;
|
|
128
|
-
};
|
|
129
|
-
var regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
130
|
-
var _entityMap = {
|
|
131
|
-
"&": "&",
|
|
132
|
-
"<": "<",
|
|
133
|
-
">": ">",
|
|
134
|
-
'"': """,
|
|
135
|
-
"'": "'",
|
|
136
|
-
"/": "/"
|
|
137
|
-
};
|
|
138
|
-
var escape = (data) => {
|
|
139
|
-
if (isString(data)) {
|
|
140
|
-
return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
|
|
141
|
-
}
|
|
142
|
-
return data;
|
|
143
|
-
};
|
|
144
|
-
var RegExpCache = class {
|
|
145
|
-
constructor(capacity) {
|
|
146
|
-
this.capacity = capacity;
|
|
147
|
-
this.regExpMap = /* @__PURE__ */ new Map();
|
|
148
|
-
this.regExpQueue = [];
|
|
149
|
-
}
|
|
150
|
-
getRegExp(pattern) {
|
|
151
|
-
const regExpFromCache = this.regExpMap.get(pattern);
|
|
152
|
-
if (regExpFromCache !== void 0) {
|
|
153
|
-
return regExpFromCache;
|
|
154
|
-
}
|
|
155
|
-
const regExpNew = new RegExp(pattern);
|
|
156
|
-
if (this.regExpQueue.length === this.capacity) {
|
|
157
|
-
this.regExpMap.delete(this.regExpQueue.shift());
|
|
158
|
-
}
|
|
159
|
-
this.regExpMap.set(pattern, regExpNew);
|
|
160
|
-
this.regExpQueue.push(pattern);
|
|
161
|
-
return regExpNew;
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
var chars = [" ", ",", "?", "!", ";"];
|
|
165
|
-
var looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
166
|
-
var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
167
|
-
nsSeparator = nsSeparator || "";
|
|
168
|
-
keySeparator = keySeparator || "";
|
|
169
|
-
const possibleChars = chars.filter((c) => !nsSeparator.includes(c) && !keySeparator.includes(c));
|
|
170
|
-
if (possibleChars.length === 0) return true;
|
|
171
|
-
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
|
|
172
|
-
let matched = !r.test(key);
|
|
173
|
-
if (!matched) {
|
|
174
|
-
const ki = key.indexOf(keySeparator);
|
|
175
|
-
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
176
|
-
matched = true;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return matched;
|
|
180
|
-
};
|
|
181
|
-
var deepFind = (obj, path, keySeparator = ".") => {
|
|
182
|
-
if (!obj) return void 0;
|
|
183
|
-
if (obj[path]) {
|
|
184
|
-
if (!Object.prototype.hasOwnProperty.call(obj, path)) return void 0;
|
|
185
|
-
return obj[path];
|
|
186
|
-
}
|
|
187
|
-
const tokens = path.split(keySeparator);
|
|
188
|
-
let current = obj;
|
|
189
|
-
for (let i = 0; i < tokens.length; ) {
|
|
190
|
-
if (!current || typeof current !== "object") {
|
|
191
|
-
return void 0;
|
|
192
|
-
}
|
|
193
|
-
let next;
|
|
194
|
-
let nextPath = "";
|
|
195
|
-
for (let j = i; j < tokens.length; ++j) {
|
|
196
|
-
if (j !== i) {
|
|
197
|
-
nextPath += keySeparator;
|
|
198
|
-
}
|
|
199
|
-
nextPath += tokens[j];
|
|
200
|
-
next = current[nextPath];
|
|
201
|
-
if (next !== void 0) {
|
|
202
|
-
if (["string", "number", "boolean"].includes(typeof next) && j < tokens.length - 1) {
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
i += j - i + 1;
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
current = next;
|
|
210
|
-
}
|
|
211
|
-
return current;
|
|
212
|
-
};
|
|
213
|
-
var getCleanedCode = (code) => code?.replace(/_/g, "-");
|
|
214
|
-
var consoleLogger = {
|
|
215
|
-
type: "logger",
|
|
216
|
-
log(args) {
|
|
217
|
-
this.output("log", args);
|
|
218
|
-
},
|
|
219
|
-
warn(args) {
|
|
220
|
-
this.output("warn", args);
|
|
221
|
-
},
|
|
222
|
-
error(args) {
|
|
223
|
-
this.output("error", args);
|
|
224
|
-
},
|
|
225
|
-
output(type, args) {
|
|
226
|
-
console?.[type]?.apply?.(console, args);
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
var Logger = class _Logger {
|
|
230
|
-
constructor(concreteLogger, options = {}) {
|
|
231
|
-
this.init(concreteLogger, options);
|
|
232
|
-
}
|
|
233
|
-
init(concreteLogger, options = {}) {
|
|
234
|
-
this.prefix = options.prefix || "i18next:";
|
|
235
|
-
this.logger = concreteLogger || consoleLogger;
|
|
236
|
-
this.options = options;
|
|
237
|
-
this.debug = options.debug;
|
|
238
|
-
}
|
|
239
|
-
log(...args) {
|
|
240
|
-
return this.forward(args, "log", "", true);
|
|
241
|
-
}
|
|
242
|
-
warn(...args) {
|
|
243
|
-
return this.forward(args, "warn", "", true);
|
|
244
|
-
}
|
|
245
|
-
error(...args) {
|
|
246
|
-
return this.forward(args, "error", "");
|
|
247
|
-
}
|
|
248
|
-
deprecate(...args) {
|
|
249
|
-
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
250
|
-
}
|
|
251
|
-
forward(args, lvl, prefix, debugOnly) {
|
|
252
|
-
if (debugOnly && !this.debug) return null;
|
|
253
|
-
args = args.map((a) => isString(a) ? a.replace(/[\r\n\x00-\x1F\x7F]/g, " ") : a);
|
|
254
|
-
if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
255
|
-
return this.logger[lvl](args);
|
|
256
|
-
}
|
|
257
|
-
create(moduleName) {
|
|
258
|
-
return new _Logger(this.logger, {
|
|
259
|
-
...{
|
|
260
|
-
prefix: `${this.prefix}:${moduleName}:`
|
|
261
|
-
},
|
|
262
|
-
...this.options
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
clone(options) {
|
|
266
|
-
options = options || this.options;
|
|
267
|
-
options.prefix = options.prefix || this.prefix;
|
|
268
|
-
return new _Logger(this.logger, options);
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
var baseLogger = new Logger();
|
|
272
|
-
var EventEmitter = class {
|
|
273
|
-
constructor() {
|
|
274
|
-
this.observers = {};
|
|
275
|
-
}
|
|
276
|
-
on(events, listener) {
|
|
277
|
-
events.split(" ").forEach((event) => {
|
|
278
|
-
if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
|
|
279
|
-
const numListeners = this.observers[event].get(listener) || 0;
|
|
280
|
-
this.observers[event].set(listener, numListeners + 1);
|
|
281
|
-
});
|
|
282
|
-
return this;
|
|
283
|
-
}
|
|
284
|
-
off(event, listener) {
|
|
285
|
-
if (!this.observers[event]) return;
|
|
286
|
-
if (!listener) {
|
|
287
|
-
delete this.observers[event];
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
this.observers[event].delete(listener);
|
|
291
|
-
}
|
|
292
|
-
once(event, listener) {
|
|
293
|
-
const wrapper = (...args) => {
|
|
294
|
-
listener(...args);
|
|
295
|
-
this.off(event, wrapper);
|
|
296
|
-
};
|
|
297
|
-
this.on(event, wrapper);
|
|
298
|
-
return this;
|
|
299
|
-
}
|
|
300
|
-
emit(event, ...args) {
|
|
301
|
-
if (this.observers[event]) {
|
|
302
|
-
const cloned = Array.from(this.observers[event].entries());
|
|
303
|
-
cloned.forEach(([observer, numTimesAdded]) => {
|
|
304
|
-
for (let i = 0; i < numTimesAdded; i++) {
|
|
305
|
-
observer(...args);
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
if (this.observers["*"]) {
|
|
310
|
-
const cloned = Array.from(this.observers["*"].entries());
|
|
311
|
-
cloned.forEach(([observer, numTimesAdded]) => {
|
|
312
|
-
for (let i = 0; i < numTimesAdded; i++) {
|
|
313
|
-
observer(event, ...args);
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
var ResourceStore = class extends EventEmitter {
|
|
320
|
-
constructor(data, options = {
|
|
321
|
-
ns: ["translation"],
|
|
322
|
-
defaultNS: "translation"
|
|
323
|
-
}) {
|
|
324
|
-
super();
|
|
325
|
-
this.data = data || {};
|
|
326
|
-
this.options = options;
|
|
327
|
-
if (this.options.keySeparator === void 0) {
|
|
328
|
-
this.options.keySeparator = ".";
|
|
329
|
-
}
|
|
330
|
-
if (this.options.ignoreJSONStructure === void 0) {
|
|
331
|
-
this.options.ignoreJSONStructure = true;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
addNamespaces(ns) {
|
|
335
|
-
if (!this.options.ns.includes(ns)) {
|
|
336
|
-
this.options.ns.push(ns);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
removeNamespaces(ns) {
|
|
340
|
-
const index = this.options.ns.indexOf(ns);
|
|
341
|
-
if (index > -1) {
|
|
342
|
-
this.options.ns.splice(index, 1);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
getResource(lng, ns, key, options = {}) {
|
|
346
|
-
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
347
|
-
const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
348
|
-
let path;
|
|
349
|
-
if (lng.includes(".")) {
|
|
350
|
-
path = lng.split(".");
|
|
351
|
-
} else {
|
|
352
|
-
path = [lng, ns];
|
|
353
|
-
if (key) {
|
|
354
|
-
if (Array.isArray(key)) {
|
|
355
|
-
path.push(...key);
|
|
356
|
-
} else if (isString(key) && keySeparator) {
|
|
357
|
-
path.push(...key.split(keySeparator));
|
|
358
|
-
} else {
|
|
359
|
-
path.push(key);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
const result = getPath(this.data, path);
|
|
364
|
-
if (!result && !ns && !key && lng.includes(".")) {
|
|
365
|
-
lng = path[0];
|
|
366
|
-
ns = path[1];
|
|
367
|
-
key = path.slice(2).join(".");
|
|
368
|
-
}
|
|
369
|
-
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
370
|
-
return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
|
|
371
|
-
}
|
|
372
|
-
addResource(lng, ns, key, value, options = {
|
|
373
|
-
silent: false
|
|
374
|
-
}) {
|
|
375
|
-
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
376
|
-
let path = [lng, ns];
|
|
377
|
-
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
378
|
-
if (lng.includes(".")) {
|
|
379
|
-
path = lng.split(".");
|
|
380
|
-
value = ns;
|
|
381
|
-
ns = path[1];
|
|
382
|
-
}
|
|
383
|
-
this.addNamespaces(ns);
|
|
384
|
-
setPath(this.data, path, value);
|
|
385
|
-
if (!options.silent) this.emit("added", lng, ns, key, value);
|
|
386
|
-
}
|
|
387
|
-
addResources(lng, ns, resources, options = {
|
|
388
|
-
silent: false
|
|
389
|
-
}) {
|
|
390
|
-
for (const m in resources) {
|
|
391
|
-
if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
|
|
392
|
-
silent: true
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
396
|
-
}
|
|
397
|
-
addResourceBundle(lng, ns, resources, deep, overwrite, options = {
|
|
398
|
-
silent: false,
|
|
399
|
-
skipCopy: false
|
|
400
|
-
}) {
|
|
401
|
-
let path = [lng, ns];
|
|
402
|
-
if (lng.includes(".")) {
|
|
403
|
-
path = lng.split(".");
|
|
404
|
-
deep = resources;
|
|
405
|
-
resources = ns;
|
|
406
|
-
ns = path[1];
|
|
407
|
-
}
|
|
408
|
-
this.addNamespaces(ns);
|
|
409
|
-
let pack = getPath(this.data, path) || {};
|
|
410
|
-
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
411
|
-
if (deep) {
|
|
412
|
-
deepExtend(pack, resources, overwrite);
|
|
413
|
-
} else {
|
|
414
|
-
pack = {
|
|
415
|
-
...pack,
|
|
416
|
-
...resources
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
setPath(this.data, path, pack);
|
|
420
|
-
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
421
|
-
}
|
|
422
|
-
removeResourceBundle(lng, ns) {
|
|
423
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
424
|
-
delete this.data[lng][ns];
|
|
425
|
-
}
|
|
426
|
-
this.removeNamespaces(ns);
|
|
427
|
-
this.emit("removed", lng, ns);
|
|
428
|
-
}
|
|
429
|
-
hasResourceBundle(lng, ns) {
|
|
430
|
-
return this.getResource(lng, ns) !== void 0;
|
|
431
|
-
}
|
|
432
|
-
getResourceBundle(lng, ns) {
|
|
433
|
-
if (!ns) ns = this.options.defaultNS;
|
|
434
|
-
return this.getResource(lng, ns);
|
|
435
|
-
}
|
|
436
|
-
getDataByLanguage(lng) {
|
|
437
|
-
return this.data[lng];
|
|
438
|
-
}
|
|
439
|
-
hasLanguageSomeTranslations(lng) {
|
|
440
|
-
const data = this.getDataByLanguage(lng);
|
|
441
|
-
const n = data && Object.keys(data) || [];
|
|
442
|
-
return !!n.find((v) => data[v] && Object.keys(data[v]).length > 0);
|
|
443
|
-
}
|
|
444
|
-
toJSON() {
|
|
445
|
-
return this.data;
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
var postProcessor = {
|
|
449
|
-
processors: {},
|
|
450
|
-
addPostProcessor(module) {
|
|
451
|
-
this.processors[module.name] = module;
|
|
452
|
-
},
|
|
453
|
-
handle(processors, value, key, options, translator) {
|
|
454
|
-
processors.forEach((processor) => {
|
|
455
|
-
value = this.processors[processor]?.process(value, key, options, translator) ?? value;
|
|
456
|
-
});
|
|
457
|
-
return value;
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
var PATH_KEY = /* @__PURE__ */ Symbol("i18next/PATH_KEY");
|
|
461
|
-
function createProxy() {
|
|
462
|
-
const state = [];
|
|
463
|
-
const handler = /* @__PURE__ */ Object.create(null);
|
|
464
|
-
let proxy;
|
|
465
|
-
handler.get = (target, key) => {
|
|
466
|
-
proxy?.revoke?.();
|
|
467
|
-
if (key === PATH_KEY) return state;
|
|
468
|
-
state.push(key);
|
|
469
|
-
proxy = Proxy.revocable(target, handler);
|
|
470
|
-
return proxy.proxy;
|
|
471
|
-
};
|
|
472
|
-
return Proxy.revocable(/* @__PURE__ */ Object.create(null), handler).proxy;
|
|
473
|
-
}
|
|
474
|
-
function keysFromSelector(selector, opts) {
|
|
475
|
-
const {
|
|
476
|
-
[PATH_KEY]: path
|
|
477
|
-
} = selector(createProxy());
|
|
478
|
-
const keySeparator = opts?.keySeparator ?? ".";
|
|
479
|
-
const nsSeparator = opts?.nsSeparator ?? ":";
|
|
480
|
-
const strict = opts?.enableSelector === "strict";
|
|
481
|
-
if (path.length > 1 && nsSeparator) {
|
|
482
|
-
const ns = opts?.ns;
|
|
483
|
-
const nsList = strict ? Array.isArray(ns) ? ns : ns ? [ns] : null : Array.isArray(ns) ? ns : null;
|
|
484
|
-
if (nsList) {
|
|
485
|
-
const candidates = strict ? nsList : nsList.length > 1 ? nsList.slice(1) : [];
|
|
486
|
-
if (candidates.includes(path[0])) {
|
|
487
|
-
return `${path[0]}${nsSeparator}${path.slice(1).join(keySeparator)}`;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return path.join(keySeparator);
|
|
492
|
-
}
|
|
493
|
-
var shouldHandleAsObject = (res) => !isString(res) && typeof res !== "boolean" && typeof res !== "number";
|
|
494
|
-
var Translator = class _Translator extends EventEmitter {
|
|
495
|
-
constructor(services, options = {}) {
|
|
496
|
-
super();
|
|
497
|
-
copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
|
|
498
|
-
this.options = options;
|
|
499
|
-
if (this.options.keySeparator === void 0) {
|
|
500
|
-
this.options.keySeparator = ".";
|
|
501
|
-
}
|
|
502
|
-
this.logger = baseLogger.create("translator");
|
|
503
|
-
this.checkedLoadedFor = {};
|
|
504
|
-
}
|
|
505
|
-
changeLanguage(lng) {
|
|
506
|
-
if (lng) this.language = lng;
|
|
507
|
-
}
|
|
508
|
-
exists(key, o = {
|
|
509
|
-
interpolation: {}
|
|
510
|
-
}) {
|
|
511
|
-
const opt = {
|
|
512
|
-
...o
|
|
513
|
-
};
|
|
514
|
-
if (key == null) return false;
|
|
515
|
-
const resolved = this.resolve(key, opt);
|
|
516
|
-
if (resolved?.res === void 0) return false;
|
|
517
|
-
const isObject = shouldHandleAsObject(resolved.res);
|
|
518
|
-
if (opt.returnObjects === false && isObject) {
|
|
519
|
-
return false;
|
|
520
|
-
}
|
|
521
|
-
return true;
|
|
522
|
-
}
|
|
523
|
-
extractFromKey(key, opt) {
|
|
524
|
-
let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
|
|
525
|
-
if (nsSeparator === void 0) nsSeparator = ":";
|
|
526
|
-
const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
|
|
527
|
-
let namespaces = opt.ns || this.options.defaultNS || [];
|
|
528
|
-
const wouldCheckForNsInKey = nsSeparator && key.includes(nsSeparator);
|
|
529
|
-
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
530
|
-
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
531
|
-
const m = key.match(this.interpolator.nestingRegexp);
|
|
532
|
-
if (m && m.length > 0) {
|
|
533
|
-
return {
|
|
534
|
-
key,
|
|
535
|
-
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
const parts = key.split(nsSeparator);
|
|
539
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.includes(parts[0])) namespaces = parts.shift();
|
|
540
|
-
key = parts.join(keySeparator);
|
|
541
|
-
}
|
|
542
|
-
return {
|
|
543
|
-
key,
|
|
544
|
-
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
translate(keys, o, lastKey) {
|
|
548
|
-
let opt = typeof o === "object" ? {
|
|
549
|
-
...o
|
|
550
|
-
} : o;
|
|
551
|
-
if (typeof opt !== "object" && this.options.overloadTranslationOptionHandler) {
|
|
552
|
-
opt = this.options.overloadTranslationOptionHandler(arguments);
|
|
553
|
-
}
|
|
554
|
-
if (typeof opt === "object") opt = {
|
|
555
|
-
...opt
|
|
556
|
-
};
|
|
557
|
-
if (!opt) opt = {};
|
|
558
|
-
if (keys == null) return "";
|
|
559
|
-
if (typeof keys === "function") keys = keysFromSelector(keys, {
|
|
560
|
-
...this.options,
|
|
561
|
-
...opt
|
|
562
|
-
});
|
|
563
|
-
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
564
|
-
keys = keys.map((k) => typeof k === "function" ? keysFromSelector(k, {
|
|
565
|
-
...this.options,
|
|
566
|
-
...opt
|
|
567
|
-
}) : String(k));
|
|
568
|
-
const returnDetails = opt.returnDetails !== void 0 ? opt.returnDetails : this.options.returnDetails;
|
|
569
|
-
const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
|
|
570
|
-
const {
|
|
571
|
-
key,
|
|
572
|
-
namespaces
|
|
573
|
-
} = this.extractFromKey(keys[keys.length - 1], opt);
|
|
574
|
-
const namespace = namespaces[namespaces.length - 1];
|
|
575
|
-
let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
|
|
576
|
-
if (nsSeparator === void 0) nsSeparator = ":";
|
|
577
|
-
const lng = opt.lng || this.language;
|
|
578
|
-
const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
579
|
-
if (lng?.toLowerCase() === "cimode") {
|
|
580
|
-
if (appendNamespaceToCIMode) {
|
|
581
|
-
if (returnDetails) {
|
|
582
|
-
return {
|
|
583
|
-
res: `${namespace}${nsSeparator}${key}`,
|
|
584
|
-
usedKey: key,
|
|
585
|
-
exactUsedKey: key,
|
|
586
|
-
usedLng: lng,
|
|
587
|
-
usedNS: namespace,
|
|
588
|
-
usedParams: this.getUsedParamsDetails(opt)
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
|
-
return `${namespace}${nsSeparator}${key}`;
|
|
592
|
-
}
|
|
593
|
-
if (returnDetails) {
|
|
594
|
-
return {
|
|
595
|
-
res: key,
|
|
596
|
-
usedKey: key,
|
|
597
|
-
exactUsedKey: key,
|
|
598
|
-
usedLng: lng,
|
|
599
|
-
usedNS: namespace,
|
|
600
|
-
usedParams: this.getUsedParamsDetails(opt)
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
return key;
|
|
604
|
-
}
|
|
605
|
-
const resolved = this.resolve(keys, opt);
|
|
606
|
-
let res = resolved?.res;
|
|
607
|
-
const resUsedKey = resolved?.usedKey || key;
|
|
608
|
-
const resExactUsedKey = resolved?.exactUsedKey || key;
|
|
609
|
-
const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
|
|
610
|
-
const joinArrays = opt.joinArrays !== void 0 ? opt.joinArrays : this.options.joinArrays;
|
|
611
|
-
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
612
|
-
const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
|
|
613
|
-
const hasDefaultValue = _Translator.hasDefaultValue(opt);
|
|
614
|
-
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : "";
|
|
615
|
-
const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
|
|
616
|
-
ordinal: false
|
|
617
|
-
}) : "";
|
|
618
|
-
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
619
|
-
const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
|
|
620
|
-
let resForObjHndl = res;
|
|
621
|
-
if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
|
|
622
|
-
resForObjHndl = defaultValue;
|
|
623
|
-
}
|
|
624
|
-
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
625
|
-
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
626
|
-
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && !noObject.includes(resType) && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
627
|
-
if (!opt.returnObjects && !this.options.returnObjects) {
|
|
628
|
-
if (!this.options.returnedObjectHandler) {
|
|
629
|
-
this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
630
|
-
}
|
|
631
|
-
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
|
|
632
|
-
...opt,
|
|
633
|
-
ns: namespaces
|
|
634
|
-
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
635
|
-
if (returnDetails) {
|
|
636
|
-
resolved.res = r;
|
|
637
|
-
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
638
|
-
return resolved;
|
|
639
|
-
}
|
|
640
|
-
return r;
|
|
641
|
-
}
|
|
642
|
-
if (keySeparator) {
|
|
643
|
-
const resTypeIsArray = Array.isArray(resForObjHndl);
|
|
644
|
-
const copy2 = resTypeIsArray ? [] : {};
|
|
645
|
-
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
646
|
-
for (const m in resForObjHndl) {
|
|
647
|
-
if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
|
|
648
|
-
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
649
|
-
if (hasDefaultValue && !res) {
|
|
650
|
-
copy2[m] = this.translate(deepKey, {
|
|
651
|
-
...opt,
|
|
652
|
-
defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : void 0,
|
|
653
|
-
...{
|
|
654
|
-
joinArrays: false,
|
|
655
|
-
ns: namespaces
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
} else {
|
|
659
|
-
copy2[m] = this.translate(deepKey, {
|
|
660
|
-
...opt,
|
|
661
|
-
...{
|
|
662
|
-
joinArrays: false,
|
|
663
|
-
ns: namespaces
|
|
664
|
-
}
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
if (copy2[m] === deepKey) copy2[m] = resForObjHndl[m];
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
res = copy2;
|
|
671
|
-
}
|
|
672
|
-
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
673
|
-
res = res.join(joinArrays);
|
|
674
|
-
if (res) res = this.extendTranslation(res, keys, opt, lastKey);
|
|
675
|
-
} else {
|
|
676
|
-
let usedDefault = false;
|
|
677
|
-
let usedKey = false;
|
|
678
|
-
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
679
|
-
usedDefault = true;
|
|
680
|
-
res = defaultValue;
|
|
681
|
-
}
|
|
682
|
-
if (!this.isValidLookup(res)) {
|
|
683
|
-
usedKey = true;
|
|
684
|
-
res = key;
|
|
685
|
-
}
|
|
686
|
-
const missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
687
|
-
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
|
|
688
|
-
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
689
|
-
if (usedKey || usedDefault || updateMissing) {
|
|
690
|
-
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, needsPluralHandling && !updateMissing ? `${key}${this.pluralResolver.getSuffix(lng, opt.count, opt)}` : key, updateMissing ? defaultValue : res);
|
|
691
|
-
if (keySeparator) {
|
|
692
|
-
const fk = this.resolve(key, {
|
|
693
|
-
...opt,
|
|
694
|
-
keySeparator: false
|
|
695
|
-
});
|
|
696
|
-
if (fk && fk.res) this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
|
|
697
|
-
}
|
|
698
|
-
let lngs = [];
|
|
699
|
-
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
|
|
700
|
-
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
|
|
701
|
-
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
702
|
-
lngs.push(fallbackLngs[i]);
|
|
703
|
-
}
|
|
704
|
-
} else if (this.options.saveMissingTo === "all") {
|
|
705
|
-
lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
|
|
706
|
-
} else {
|
|
707
|
-
lngs.push(opt.lng || this.language);
|
|
708
|
-
}
|
|
709
|
-
const send = (l, k, specificDefaultValue) => {
|
|
710
|
-
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
711
|
-
if (this.options.missingKeyHandler) {
|
|
712
|
-
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
713
|
-
} else if (this.backendConnector?.saveMissing) {
|
|
714
|
-
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
715
|
-
}
|
|
716
|
-
this.emit("missingKey", l, namespace, k, res);
|
|
717
|
-
};
|
|
718
|
-
if (this.options.saveMissing) {
|
|
719
|
-
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
720
|
-
lngs.forEach((language) => {
|
|
721
|
-
const suffixes = this.pluralResolver.getSuffixes(language, opt);
|
|
722
|
-
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && !suffixes.includes(`${this.options.pluralSeparator}zero`)) {
|
|
723
|
-
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
724
|
-
}
|
|
725
|
-
suffixes.forEach((suffix) => {
|
|
726
|
-
send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
|
|
727
|
-
});
|
|
728
|
-
});
|
|
729
|
-
} else {
|
|
730
|
-
send(lngs, key, defaultValue);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
res = this.extendTranslation(res, keys, opt, resolved, lastKey);
|
|
735
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
|
|
736
|
-
res = `${namespace}${nsSeparator}${key}`;
|
|
737
|
-
}
|
|
738
|
-
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
739
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : void 0, opt);
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
if (returnDetails) {
|
|
743
|
-
resolved.res = res;
|
|
744
|
-
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
745
|
-
return resolved;
|
|
746
|
-
}
|
|
747
|
-
return res;
|
|
748
|
-
}
|
|
749
|
-
extendTranslation(res, key, opt, resolved, lastKey) {
|
|
750
|
-
if (this.i18nFormat?.parse) {
|
|
751
|
-
res = this.i18nFormat.parse(res, {
|
|
752
|
-
...this.options.interpolation.defaultVariables,
|
|
753
|
-
...opt
|
|
754
|
-
}, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
755
|
-
resolved
|
|
756
|
-
});
|
|
757
|
-
} else if (!opt.skipInterpolation) {
|
|
758
|
-
if (opt.interpolation) this.interpolator.init({
|
|
759
|
-
...opt,
|
|
760
|
-
...{
|
|
761
|
-
interpolation: {
|
|
762
|
-
...this.options.interpolation,
|
|
763
|
-
...opt.interpolation
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
});
|
|
767
|
-
const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== void 0 ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
768
|
-
let nestBef;
|
|
769
|
-
if (skipOnVariables) {
|
|
770
|
-
const nb = res.match(this.interpolator.nestingRegexp);
|
|
771
|
-
nestBef = nb && nb.length;
|
|
772
|
-
}
|
|
773
|
-
let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
|
|
774
|
-
if (this.options.interpolation.defaultVariables) data = {
|
|
775
|
-
...this.options.interpolation.defaultVariables,
|
|
776
|
-
...data
|
|
777
|
-
};
|
|
778
|
-
res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
|
|
779
|
-
if (skipOnVariables) {
|
|
780
|
-
const na = res.match(this.interpolator.nestingRegexp);
|
|
781
|
-
const nestAft = na && na.length;
|
|
782
|
-
if (nestBef < nestAft) opt.nest = false;
|
|
783
|
-
}
|
|
784
|
-
if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
|
|
785
|
-
if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
|
|
786
|
-
if (lastKey?.[0] === args[0] && !opt.context) {
|
|
787
|
-
this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
788
|
-
return null;
|
|
789
|
-
}
|
|
790
|
-
return this.translate(...args, key);
|
|
791
|
-
}, opt);
|
|
792
|
-
if (opt.interpolation) this.interpolator.reset();
|
|
793
|
-
}
|
|
794
|
-
const postProcess = opt.postProcess || this.options.postProcess;
|
|
795
|
-
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
796
|
-
if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) {
|
|
797
|
-
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
798
|
-
i18nResolved: {
|
|
799
|
-
...resolved,
|
|
800
|
-
usedParams: this.getUsedParamsDetails(opt)
|
|
801
|
-
},
|
|
802
|
-
...opt
|
|
803
|
-
} : opt, this);
|
|
804
|
-
}
|
|
805
|
-
return res;
|
|
806
|
-
}
|
|
807
|
-
resolve(keys, opt = {}) {
|
|
808
|
-
let found;
|
|
809
|
-
let usedKey;
|
|
810
|
-
let exactUsedKey;
|
|
811
|
-
let usedLng;
|
|
812
|
-
let usedNS;
|
|
813
|
-
if (isString(keys)) keys = [keys];
|
|
814
|
-
if (Array.isArray(keys)) keys = keys.map((k) => typeof k === "function" ? keysFromSelector(k, {
|
|
815
|
-
...this.options,
|
|
816
|
-
...opt
|
|
817
|
-
}) : k);
|
|
818
|
-
keys.forEach((k) => {
|
|
819
|
-
if (this.isValidLookup(found)) return;
|
|
820
|
-
const extracted = this.extractFromKey(k, opt);
|
|
821
|
-
const key = extracted.key;
|
|
822
|
-
usedKey = key;
|
|
823
|
-
let namespaces = extracted.namespaces;
|
|
824
|
-
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
825
|
-
const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
|
|
826
|
-
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
827
|
-
const needsContextHandling = opt.context !== void 0 && (isString(opt.context) || typeof opt.context === "number") && opt.context !== "";
|
|
828
|
-
const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
|
|
829
|
-
namespaces.forEach((ns) => {
|
|
830
|
-
if (this.isValidLookup(found)) return;
|
|
831
|
-
usedNS = ns;
|
|
832
|
-
if (!this.checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
833
|
-
this.checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
834
|
-
this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
|
|
835
|
-
}
|
|
836
|
-
codes.forEach((code) => {
|
|
837
|
-
if (this.isValidLookup(found)) return;
|
|
838
|
-
usedLng = code;
|
|
839
|
-
const finalKeys = [key];
|
|
840
|
-
if (this.i18nFormat?.addLookupKeys) {
|
|
841
|
-
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
|
|
842
|
-
} else {
|
|
843
|
-
let pluralSuffix;
|
|
844
|
-
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
|
|
845
|
-
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
846
|
-
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
847
|
-
if (needsPluralHandling) {
|
|
848
|
-
if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) {
|
|
849
|
-
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
850
|
-
}
|
|
851
|
-
finalKeys.push(key + pluralSuffix);
|
|
852
|
-
if (needsZeroSuffixLookup) {
|
|
853
|
-
finalKeys.push(key + zeroSuffix);
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
if (needsContextHandling) {
|
|
857
|
-
const contextKey = `${key}${this.options.contextSeparator || "_"}${opt.context}`;
|
|
858
|
-
finalKeys.push(contextKey);
|
|
859
|
-
if (needsPluralHandling) {
|
|
860
|
-
if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) {
|
|
861
|
-
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
862
|
-
}
|
|
863
|
-
finalKeys.push(contextKey + pluralSuffix);
|
|
864
|
-
if (needsZeroSuffixLookup) {
|
|
865
|
-
finalKeys.push(contextKey + zeroSuffix);
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
let possibleKey;
|
|
871
|
-
while (possibleKey = finalKeys.pop()) {
|
|
872
|
-
if (!this.isValidLookup(found)) {
|
|
873
|
-
exactUsedKey = possibleKey;
|
|
874
|
-
found = this.getResource(code, ns, possibleKey, opt);
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
});
|
|
878
|
-
});
|
|
879
|
-
});
|
|
880
|
-
return {
|
|
881
|
-
res: found,
|
|
882
|
-
usedKey,
|
|
883
|
-
exactUsedKey,
|
|
884
|
-
usedLng,
|
|
885
|
-
usedNS
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
isValidLookup(res) {
|
|
889
|
-
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
890
|
-
}
|
|
891
|
-
getResource(code, ns, key, options = {}) {
|
|
892
|
-
if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
893
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
894
|
-
}
|
|
895
|
-
getUsedParamsDetails(options = {}) {
|
|
896
|
-
const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
|
|
897
|
-
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
898
|
-
let data = useOptionsReplaceForData ? options.replace : options;
|
|
899
|
-
if (useOptionsReplaceForData && typeof options.count !== "undefined") {
|
|
900
|
-
data = {
|
|
901
|
-
...data,
|
|
902
|
-
count: options.count
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
if (this.options.interpolation.defaultVariables) {
|
|
906
|
-
data = {
|
|
907
|
-
...this.options.interpolation.defaultVariables,
|
|
908
|
-
...data
|
|
909
|
-
};
|
|
910
|
-
}
|
|
911
|
-
if (!useOptionsReplaceForData) {
|
|
912
|
-
data = {
|
|
913
|
-
...data
|
|
914
|
-
};
|
|
915
|
-
for (const key of optionsKeys) {
|
|
916
|
-
delete data[key];
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
return data;
|
|
920
|
-
}
|
|
921
|
-
static hasDefaultValue(options) {
|
|
922
|
-
const prefix = "defaultValue";
|
|
923
|
-
for (const option in options) {
|
|
924
|
-
if (Object.prototype.hasOwnProperty.call(options, option) && option.startsWith(prefix) && void 0 !== options[option]) {
|
|
925
|
-
return true;
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
return false;
|
|
929
|
-
}
|
|
930
|
-
};
|
|
931
|
-
var LanguageUtil = class {
|
|
932
|
-
constructor(options) {
|
|
933
|
-
this.options = options;
|
|
934
|
-
this.supportedLngs = this.options.supportedLngs || false;
|
|
935
|
-
this.logger = baseLogger.create("languageUtils");
|
|
936
|
-
this.resolveHierarchyCache = {};
|
|
937
|
-
}
|
|
938
|
-
clearCache() {
|
|
939
|
-
this.resolveHierarchyCache = {};
|
|
940
|
-
}
|
|
941
|
-
getScriptPartFromCode(code) {
|
|
942
|
-
code = getCleanedCode(code);
|
|
943
|
-
if (!code || !code.includes("-")) return null;
|
|
944
|
-
const p = code.split("-");
|
|
945
|
-
if (p.length === 2) return null;
|
|
946
|
-
p.pop();
|
|
947
|
-
if (p[p.length - 1].toLowerCase() === "x") return null;
|
|
948
|
-
return this.formatLanguageCode(p.join("-"));
|
|
949
|
-
}
|
|
950
|
-
getLanguagePartFromCode(code) {
|
|
951
|
-
code = getCleanedCode(code);
|
|
952
|
-
if (!code || !code.includes("-")) return code;
|
|
953
|
-
const p = code.split("-");
|
|
954
|
-
return this.formatLanguageCode(p[0]);
|
|
955
|
-
}
|
|
956
|
-
formatLanguageCode(code) {
|
|
957
|
-
if (isString(code) && code.includes("-")) {
|
|
958
|
-
let formattedCode;
|
|
959
|
-
try {
|
|
960
|
-
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
961
|
-
} catch (e) {
|
|
962
|
-
}
|
|
963
|
-
if (formattedCode && this.options.lowerCaseLng) {
|
|
964
|
-
formattedCode = formattedCode.toLowerCase();
|
|
965
|
-
}
|
|
966
|
-
if (formattedCode) return formattedCode;
|
|
967
|
-
if (this.options.lowerCaseLng) {
|
|
968
|
-
return code.toLowerCase();
|
|
969
|
-
}
|
|
970
|
-
return code;
|
|
971
|
-
}
|
|
972
|
-
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
973
|
-
}
|
|
974
|
-
isSupportedCode(code) {
|
|
975
|
-
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
|
|
976
|
-
code = this.getLanguagePartFromCode(code);
|
|
977
|
-
}
|
|
978
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.includes(code);
|
|
979
|
-
}
|
|
980
|
-
getBestMatchFromCodes(codes) {
|
|
981
|
-
if (!codes) return null;
|
|
982
|
-
let found;
|
|
983
|
-
codes.forEach((code) => {
|
|
984
|
-
if (found) return;
|
|
985
|
-
const cleanedLng = this.formatLanguageCode(code);
|
|
986
|
-
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
987
|
-
});
|
|
988
|
-
if (!found && this.options.supportedLngs) {
|
|
989
|
-
codes.forEach((code) => {
|
|
990
|
-
if (found) return;
|
|
991
|
-
const lngScOnly = this.getScriptPartFromCode(code);
|
|
992
|
-
if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
|
|
993
|
-
const lngOnly = this.getLanguagePartFromCode(code);
|
|
994
|
-
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
995
|
-
found = this.options.supportedLngs.find((supportedLng) => {
|
|
996
|
-
if (supportedLng === lngOnly) return true;
|
|
997
|
-
if (!supportedLng.includes("-") && !lngOnly.includes("-")) return false;
|
|
998
|
-
if (supportedLng.includes("-") && !lngOnly.includes("-") && supportedLng.slice(0, supportedLng.indexOf("-")) === lngOnly) return true;
|
|
999
|
-
if (supportedLng.startsWith(lngOnly) && lngOnly.length > 1) return true;
|
|
1000
|
-
return false;
|
|
1001
|
-
});
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
1005
|
-
return found;
|
|
1006
|
-
}
|
|
1007
|
-
getFallbackCodes(fallbacks, code) {
|
|
1008
|
-
if (!fallbacks) return [];
|
|
1009
|
-
if (typeof fallbacks === "function") fallbacks = fallbacks(code);
|
|
1010
|
-
if (isString(fallbacks)) fallbacks = [fallbacks];
|
|
1011
|
-
if (Array.isArray(fallbacks)) return fallbacks;
|
|
1012
|
-
if (!code) return fallbacks.default || [];
|
|
1013
|
-
let found = fallbacks[code];
|
|
1014
|
-
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
1015
|
-
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
1016
|
-
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
1017
|
-
if (!found) found = fallbacks.default;
|
|
1018
|
-
return found || [];
|
|
1019
|
-
}
|
|
1020
|
-
toResolveHierarchy(code, fallbackCode) {
|
|
1021
|
-
const fallbackLng = this.options.fallbackLng;
|
|
1022
|
-
const fallbackLngKey = Array.isArray(fallbackLng) ? fallbackLng.join("|") : fallbackLng;
|
|
1023
|
-
if (fallbackLngKey !== this._cachedFallbackLng) {
|
|
1024
|
-
this.resolveHierarchyCache = {};
|
|
1025
|
-
this._cachedFallbackLng = fallbackLngKey;
|
|
1026
|
-
}
|
|
1027
|
-
const hasCacheableFallback = fallbackCode === void 0 || fallbackCode === false || isString(fallbackCode);
|
|
1028
|
-
const usesUncacheableOptionsFallback = fallbackCode === void 0 && typeof this.options.fallbackLng === "function";
|
|
1029
|
-
const cacheable = isString(code) && hasCacheableFallback && !usesUncacheableOptionsFallback;
|
|
1030
|
-
let cacheKey = null;
|
|
1031
|
-
if (cacheable) {
|
|
1032
|
-
let fallbackCacheKey;
|
|
1033
|
-
if (fallbackCode === void 0) fallbackCacheKey = "undefined";
|
|
1034
|
-
else if (fallbackCode === false) fallbackCacheKey = "boolean:false";
|
|
1035
|
-
else fallbackCacheKey = `string:${fallbackCode}`;
|
|
1036
|
-
cacheKey = `${code.length}:${code}|${fallbackCacheKey}`;
|
|
1037
|
-
}
|
|
1038
|
-
if (cacheKey !== null) {
|
|
1039
|
-
const cached = this.resolveHierarchyCache[cacheKey];
|
|
1040
|
-
if (cached !== void 0) return cached.slice();
|
|
1041
|
-
}
|
|
1042
|
-
const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
|
|
1043
|
-
const codes = [];
|
|
1044
|
-
const addCode = (c) => {
|
|
1045
|
-
if (!c) return;
|
|
1046
|
-
if (this.isSupportedCode(c)) {
|
|
1047
|
-
codes.push(c);
|
|
1048
|
-
} else {
|
|
1049
|
-
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
1050
|
-
}
|
|
1051
|
-
};
|
|
1052
|
-
if (isString(code) && (code.includes("-") || code.includes("_"))) {
|
|
1053
|
-
if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
|
|
1054
|
-
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
|
|
1055
|
-
if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
|
|
1056
|
-
} else if (isString(code)) {
|
|
1057
|
-
addCode(this.formatLanguageCode(code));
|
|
1058
|
-
}
|
|
1059
|
-
fallbackCodes.forEach((fc) => {
|
|
1060
|
-
if (!codes.includes(fc)) addCode(this.formatLanguageCode(fc));
|
|
1061
|
-
});
|
|
1062
|
-
if (cacheKey !== null) {
|
|
1063
|
-
this.resolveHierarchyCache[cacheKey] = codes;
|
|
1064
|
-
return codes.slice();
|
|
1065
|
-
}
|
|
1066
|
-
return codes;
|
|
1067
|
-
}
|
|
1068
|
-
};
|
|
1069
|
-
var suffixesOrder = {
|
|
1070
|
-
zero: 0,
|
|
1071
|
-
one: 1,
|
|
1072
|
-
two: 2,
|
|
1073
|
-
few: 3,
|
|
1074
|
-
many: 4,
|
|
1075
|
-
other: 5
|
|
1076
|
-
};
|
|
1077
|
-
var dummyRule = {
|
|
1078
|
-
select: (count) => count === 1 ? "one" : "other",
|
|
1079
|
-
resolvedOptions: () => ({
|
|
1080
|
-
pluralCategories: ["one", "other"]
|
|
1081
|
-
})
|
|
1082
|
-
};
|
|
1083
|
-
var PluralResolver = class {
|
|
1084
|
-
constructor(languageUtils, options = {}) {
|
|
1085
|
-
this.languageUtils = languageUtils;
|
|
1086
|
-
this.options = options;
|
|
1087
|
-
this.logger = baseLogger.create("pluralResolver");
|
|
1088
|
-
this.pluralRulesCache = {};
|
|
1089
|
-
}
|
|
1090
|
-
clearCache() {
|
|
1091
|
-
this.pluralRulesCache = {};
|
|
1092
|
-
}
|
|
1093
|
-
getRule(code, options = {}) {
|
|
1094
|
-
const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
|
|
1095
|
-
const type = options.ordinal ? "ordinal" : "cardinal";
|
|
1096
|
-
const cacheKey = JSON.stringify({
|
|
1097
|
-
cleanedCode,
|
|
1098
|
-
type
|
|
1099
|
-
});
|
|
1100
|
-
if (cacheKey in this.pluralRulesCache) {
|
|
1101
|
-
return this.pluralRulesCache[cacheKey];
|
|
1102
|
-
}
|
|
1103
|
-
let rule;
|
|
1104
|
-
try {
|
|
1105
|
-
rule = new Intl.PluralRules(cleanedCode, {
|
|
1106
|
-
type
|
|
1107
|
-
});
|
|
1108
|
-
} catch (err) {
|
|
1109
|
-
if (typeof Intl === "undefined") {
|
|
1110
|
-
this.logger.error("No Intl support, please use an Intl polyfill!");
|
|
1111
|
-
return dummyRule;
|
|
1112
|
-
}
|
|
1113
|
-
if (!code.match(/-|_/)) return dummyRule;
|
|
1114
|
-
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
1115
|
-
rule = this.getRule(lngPart, options);
|
|
1116
|
-
}
|
|
1117
|
-
this.pluralRulesCache[cacheKey] = rule;
|
|
1118
|
-
return rule;
|
|
1119
|
-
}
|
|
1120
|
-
needsPlural(code, options = {}) {
|
|
1121
|
-
let rule = this.getRule(code, options);
|
|
1122
|
-
if (!rule) rule = this.getRule("dev", options);
|
|
1123
|
-
return rule?.resolvedOptions().pluralCategories.length > 1;
|
|
1124
|
-
}
|
|
1125
|
-
getPluralFormsOfKey(code, key, options = {}) {
|
|
1126
|
-
return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
|
|
1127
|
-
}
|
|
1128
|
-
getSuffixes(code, options = {}) {
|
|
1129
|
-
let rule = this.getRule(code, options);
|
|
1130
|
-
if (!rule) rule = this.getRule("dev", options);
|
|
1131
|
-
if (!rule) return [];
|
|
1132
|
-
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
|
|
1133
|
-
}
|
|
1134
|
-
getSuffix(code, count, options = {}) {
|
|
1135
|
-
const rule = this.getRule(code, options);
|
|
1136
|
-
if (rule) {
|
|
1137
|
-
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
|
|
1138
|
-
}
|
|
1139
|
-
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1140
|
-
return this.getSuffix("dev", count, options);
|
|
1141
|
-
}
|
|
1142
|
-
};
|
|
1143
|
-
var deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJSONStructure = true) => {
|
|
1144
|
-
let path = getPathWithDefaults(data, defaultData, key);
|
|
1145
|
-
if (!path && ignoreJSONStructure && isString(key)) {
|
|
1146
|
-
path = deepFind(data, key, keySeparator);
|
|
1147
|
-
if (path === void 0) path = deepFind(defaultData, key, keySeparator);
|
|
1148
|
-
}
|
|
1149
|
-
return path;
|
|
1150
|
-
};
|
|
1151
|
-
var regexSafe = (val) => val.replace(/\$/g, "$$$$");
|
|
1152
|
-
var Interpolator = class {
|
|
1153
|
-
constructor(options = {}) {
|
|
1154
|
-
this.logger = baseLogger.create("interpolator");
|
|
1155
|
-
this.options = options;
|
|
1156
|
-
this.format = options?.interpolation?.format || ((value) => value);
|
|
1157
|
-
this.init(options);
|
|
1158
|
-
}
|
|
1159
|
-
init(options = {}) {
|
|
1160
|
-
if (!options.interpolation) options.interpolation = {
|
|
1161
|
-
escapeValue: true
|
|
1162
|
-
};
|
|
1163
|
-
const {
|
|
1164
|
-
escape: escape$1,
|
|
1165
|
-
escapeValue,
|
|
1166
|
-
useRawValueToEscape,
|
|
1167
|
-
prefix,
|
|
1168
|
-
prefixEscaped,
|
|
1169
|
-
suffix,
|
|
1170
|
-
suffixEscaped,
|
|
1171
|
-
formatSeparator,
|
|
1172
|
-
unescapeSuffix,
|
|
1173
|
-
unescapePrefix,
|
|
1174
|
-
nestingPrefix,
|
|
1175
|
-
nestingPrefixEscaped,
|
|
1176
|
-
nestingSuffix,
|
|
1177
|
-
nestingSuffixEscaped,
|
|
1178
|
-
nestingOptionsSeparator,
|
|
1179
|
-
maxReplaces,
|
|
1180
|
-
alwaysFormat
|
|
1181
|
-
} = options.interpolation;
|
|
1182
|
-
this.escape = escape$1 !== void 0 ? escape$1 : escape;
|
|
1183
|
-
this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
|
|
1184
|
-
this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
|
|
1185
|
-
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
|
|
1186
|
-
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
|
|
1187
|
-
this.formatSeparator = formatSeparator || ",";
|
|
1188
|
-
this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix ? regexEscape(unescapePrefix) : "-";
|
|
1189
|
-
this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix ? regexEscape(unescapeSuffix) : "";
|
|
1190
|
-
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
|
|
1191
|
-
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
|
|
1192
|
-
this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
|
|
1193
|
-
this.maxReplaces = maxReplaces || 1e3;
|
|
1194
|
-
this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
|
|
1195
|
-
this.resetRegExp();
|
|
1196
|
-
}
|
|
1197
|
-
reset() {
|
|
1198
|
-
if (this.options) this.init(this.options);
|
|
1199
|
-
}
|
|
1200
|
-
resetRegExp() {
|
|
1201
|
-
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
1202
|
-
if (existingRegExp?.source === pattern) {
|
|
1203
|
-
existingRegExp.lastIndex = 0;
|
|
1204
|
-
return existingRegExp;
|
|
1205
|
-
}
|
|
1206
|
-
return new RegExp(pattern, "g");
|
|
1207
|
-
};
|
|
1208
|
-
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
1209
|
-
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
1210
|
-
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
|
|
1211
|
-
}
|
|
1212
|
-
interpolate(str, data, lng, options) {
|
|
1213
|
-
let match;
|
|
1214
|
-
let value;
|
|
1215
|
-
let replaces;
|
|
1216
|
-
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1217
|
-
const handleFormat = (key) => {
|
|
1218
|
-
if (!key.includes(this.formatSeparator)) {
|
|
1219
|
-
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1220
|
-
return this.alwaysFormat ? this.format(path, void 0, lng, {
|
|
1221
|
-
...options,
|
|
1222
|
-
...data,
|
|
1223
|
-
interpolationkey: key
|
|
1224
|
-
}) : path;
|
|
1225
|
-
}
|
|
1226
|
-
const p = key.split(this.formatSeparator);
|
|
1227
|
-
const k = p.shift().trim();
|
|
1228
|
-
const f = p.join(this.formatSeparator).trim();
|
|
1229
|
-
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1230
|
-
...options,
|
|
1231
|
-
...data,
|
|
1232
|
-
interpolationkey: k
|
|
1233
|
-
});
|
|
1234
|
-
};
|
|
1235
|
-
this.resetRegExp();
|
|
1236
|
-
if (!this.escapeValue && typeof str === "string" && /\$t\([^)]*\{[^}]*\{\{/.test(str)) {
|
|
1237
|
-
this.logger.warn("nesting options string contains interpolated variables with escapeValue: false \u2014 if any of those values are attacker-controlled they can inject additional nesting options (e.g. redirect lng/ns). Sanitise untrusted input before passing it to t(), or keep escapeValue: true.");
|
|
1238
|
-
}
|
|
1239
|
-
const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1240
|
-
const skipOnVariables = options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1241
|
-
const todos = [{
|
|
1242
|
-
regex: this.regexpUnescape,
|
|
1243
|
-
safeValue: (val) => val
|
|
1244
|
-
}, {
|
|
1245
|
-
regex: this.regexp,
|
|
1246
|
-
safeValue: (val) => this.escapeValue ? this.escape(val) : val
|
|
1247
|
-
}];
|
|
1248
|
-
todos.forEach((todo) => {
|
|
1249
|
-
replaces = 0;
|
|
1250
|
-
while (match = todo.regex.exec(str)) {
|
|
1251
|
-
const matchedVar = match[1].trim();
|
|
1252
|
-
value = handleFormat(matchedVar);
|
|
1253
|
-
if (value === void 0) {
|
|
1254
|
-
if (typeof missingInterpolationHandler === "function") {
|
|
1255
|
-
const temp = missingInterpolationHandler(str, match, options);
|
|
1256
|
-
value = isString(temp) ? temp : "";
|
|
1257
|
-
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1258
|
-
value = "";
|
|
1259
|
-
} else if (skipOnVariables) {
|
|
1260
|
-
value = match[0];
|
|
1261
|
-
continue;
|
|
1262
|
-
} else {
|
|
1263
|
-
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1264
|
-
value = "";
|
|
1265
|
-
}
|
|
1266
|
-
} else if (!isString(value) && !this.useRawValueToEscape) {
|
|
1267
|
-
value = makeString(value);
|
|
1268
|
-
}
|
|
1269
|
-
const safeValue = todo.safeValue(value);
|
|
1270
|
-
str = str.replace(match[0], regexSafe(safeValue));
|
|
1271
|
-
if (skipOnVariables) {
|
|
1272
|
-
todo.regex.lastIndex += safeValue.length;
|
|
1273
|
-
todo.regex.lastIndex -= match[0].length;
|
|
1274
|
-
} else {
|
|
1275
|
-
todo.regex.lastIndex = 0;
|
|
1276
|
-
}
|
|
1277
|
-
replaces++;
|
|
1278
|
-
if (replaces >= this.maxReplaces) {
|
|
1279
|
-
break;
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
});
|
|
1283
|
-
return str;
|
|
1284
|
-
}
|
|
1285
|
-
nest(str, fc, options = {}) {
|
|
1286
|
-
let match;
|
|
1287
|
-
let value;
|
|
1288
|
-
let clonedOptions;
|
|
1289
|
-
const handleHasOptions = (key, inheritedOptions) => {
|
|
1290
|
-
const sep = this.nestingOptionsSeparator;
|
|
1291
|
-
if (!key.includes(sep)) return key;
|
|
1292
|
-
const c = key.split(new RegExp(`${regexEscape(sep)}[ ]*{`));
|
|
1293
|
-
let optionsString = `{${c[1]}`;
|
|
1294
|
-
key = c[0];
|
|
1295
|
-
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1296
|
-
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1297
|
-
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1298
|
-
if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || (matchedDoubleQuotes?.length ?? 0) % 2 !== 0) {
|
|
1299
|
-
optionsString = optionsString.replace(/'/g, '"');
|
|
1300
|
-
}
|
|
1301
|
-
try {
|
|
1302
|
-
clonedOptions = JSON.parse(optionsString);
|
|
1303
|
-
if (inheritedOptions) clonedOptions = {
|
|
1304
|
-
...inheritedOptions,
|
|
1305
|
-
...clonedOptions
|
|
1306
|
-
};
|
|
1307
|
-
} catch (e) {
|
|
1308
|
-
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1309
|
-
return `${key}${sep}${optionsString}`;
|
|
1310
|
-
}
|
|
1311
|
-
if (clonedOptions.defaultValue && clonedOptions.defaultValue.includes(this.prefix)) delete clonedOptions.defaultValue;
|
|
1312
|
-
return key;
|
|
1313
|
-
};
|
|
1314
|
-
while (match = this.nestingRegexp.exec(str)) {
|
|
1315
|
-
let formatters = [];
|
|
1316
|
-
clonedOptions = {
|
|
1317
|
-
...options
|
|
1318
|
-
};
|
|
1319
|
-
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
1320
|
-
clonedOptions.applyPostProcessor = false;
|
|
1321
|
-
delete clonedOptions.defaultValue;
|
|
1322
|
-
const keyEndIndex = /{.*}/s.test(match[1]) ? match[1].lastIndexOf("}") + 1 : match[1].indexOf(this.formatSeparator);
|
|
1323
|
-
if (keyEndIndex !== -1) {
|
|
1324
|
-
formatters = match[1].slice(keyEndIndex).split(this.formatSeparator).map((elem) => elem.trim()).filter(Boolean);
|
|
1325
|
-
match[1] = match[1].slice(0, keyEndIndex);
|
|
1326
|
-
}
|
|
1327
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1328
|
-
if (value && match[0] === str && !isString(value)) return value;
|
|
1329
|
-
if (!isString(value)) value = makeString(value);
|
|
1330
|
-
if (!value) {
|
|
1331
|
-
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1332
|
-
value = "";
|
|
1333
|
-
}
|
|
1334
|
-
if (formatters.length) {
|
|
1335
|
-
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1336
|
-
...options,
|
|
1337
|
-
interpolationkey: match[1].trim()
|
|
1338
|
-
}), value.trim());
|
|
1339
|
-
}
|
|
1340
|
-
str = str.replace(match[0], regexSafe(makeString(value)));
|
|
1341
|
-
this.regexp.lastIndex = 0;
|
|
1342
|
-
}
|
|
1343
|
-
return str;
|
|
1344
|
-
}
|
|
1345
|
-
};
|
|
1346
|
-
var parseFormatStr = (formatStr) => {
|
|
1347
|
-
let formatName = formatStr.toLowerCase().trim();
|
|
1348
|
-
const formatOptions = {};
|
|
1349
|
-
if (formatStr.includes("(")) {
|
|
1350
|
-
const p = formatStr.split("(");
|
|
1351
|
-
formatName = p[0].toLowerCase().trim();
|
|
1352
|
-
const optStr = p[1].slice(0, -1);
|
|
1353
|
-
if (formatName === "currency" && !optStr.includes(":")) {
|
|
1354
|
-
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1355
|
-
} else if (formatName === "relativetime" && !optStr.includes(":")) {
|
|
1356
|
-
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1357
|
-
} else {
|
|
1358
|
-
const opts = optStr.split(";");
|
|
1359
|
-
opts.forEach((opt) => {
|
|
1360
|
-
if (opt) {
|
|
1361
|
-
const [key, ...rest] = opt.split(":");
|
|
1362
|
-
const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
|
|
1363
|
-
const trimmedKey = key.trim();
|
|
1364
|
-
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
1365
|
-
if (val === "false") formatOptions[trimmedKey] = false;
|
|
1366
|
-
if (val === "true") formatOptions[trimmedKey] = true;
|
|
1367
|
-
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
1368
|
-
}
|
|
1369
|
-
});
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
return {
|
|
1373
|
-
formatName,
|
|
1374
|
-
formatOptions
|
|
1375
|
-
};
|
|
1376
|
-
};
|
|
1377
|
-
var createCachedFormatter = (fn) => {
|
|
1378
|
-
const cache = {};
|
|
1379
|
-
return (v, l, o) => {
|
|
1380
|
-
let optForCache = o;
|
|
1381
|
-
if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
|
|
1382
|
-
optForCache = {
|
|
1383
|
-
...optForCache,
|
|
1384
|
-
[o.interpolationkey]: void 0
|
|
1385
|
-
};
|
|
1386
|
-
}
|
|
1387
|
-
const key = l + JSON.stringify(optForCache);
|
|
1388
|
-
let frm = cache[key];
|
|
1389
|
-
if (!frm) {
|
|
1390
|
-
frm = fn(getCleanedCode(l), o);
|
|
1391
|
-
cache[key] = frm;
|
|
1392
|
-
}
|
|
1393
|
-
return frm(v);
|
|
1394
|
-
};
|
|
1395
|
-
};
|
|
1396
|
-
var createNonCachedFormatter = (fn) => (v, l, o) => fn(getCleanedCode(l), o)(v);
|
|
1397
|
-
var Formatter = class {
|
|
1398
|
-
constructor(options = {}) {
|
|
1399
|
-
this.logger = baseLogger.create("formatter");
|
|
1400
|
-
this.options = options;
|
|
1401
|
-
this.init(options);
|
|
1402
|
-
}
|
|
1403
|
-
init(services, options = {
|
|
1404
|
-
interpolation: {}
|
|
1405
|
-
}) {
|
|
1406
|
-
this.formatSeparator = options.interpolation.formatSeparator || ",";
|
|
1407
|
-
const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
|
|
1408
|
-
this.formats = {
|
|
1409
|
-
number: cf((lng, opt) => {
|
|
1410
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1411
|
-
...opt
|
|
1412
|
-
});
|
|
1413
|
-
return (val) => formatter.format(val);
|
|
1414
|
-
}),
|
|
1415
|
-
currency: cf((lng, opt) => {
|
|
1416
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1417
|
-
...opt,
|
|
1418
|
-
style: "currency"
|
|
1419
|
-
});
|
|
1420
|
-
return (val) => formatter.format(val);
|
|
1421
|
-
}),
|
|
1422
|
-
datetime: cf((lng, opt) => {
|
|
1423
|
-
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1424
|
-
...opt
|
|
1425
|
-
});
|
|
1426
|
-
return (val) => formatter.format(val);
|
|
1427
|
-
}),
|
|
1428
|
-
relativetime: cf((lng, opt) => {
|
|
1429
|
-
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1430
|
-
...opt
|
|
1431
|
-
});
|
|
1432
|
-
return (val) => formatter.format(val, opt.range || "day");
|
|
1433
|
-
}),
|
|
1434
|
-
list: cf((lng, opt) => {
|
|
1435
|
-
const formatter = new Intl.ListFormat(lng, {
|
|
1436
|
-
...opt
|
|
1437
|
-
});
|
|
1438
|
-
return (val) => formatter.format(val);
|
|
1439
|
-
})
|
|
1440
|
-
};
|
|
1441
|
-
}
|
|
1442
|
-
add(name, fc) {
|
|
1443
|
-
this.formats[name.toLowerCase().trim()] = fc;
|
|
1444
|
-
}
|
|
1445
|
-
addCached(name, fc) {
|
|
1446
|
-
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1447
|
-
}
|
|
1448
|
-
format(value, format, lng, options = {}) {
|
|
1449
|
-
if (!format) return value;
|
|
1450
|
-
if (value == null) return value;
|
|
1451
|
-
const rawFormats = format.split(this.formatSeparator);
|
|
1452
|
-
const formats = [];
|
|
1453
|
-
for (let i = 0; i < rawFormats.length; i++) {
|
|
1454
|
-
let f = rawFormats[i];
|
|
1455
|
-
while (f.indexOf("(") > -1 && !f.includes(")") && i + 1 < rawFormats.length) {
|
|
1456
|
-
f = `${f}${this.formatSeparator}${rawFormats[++i]}`;
|
|
1457
|
-
}
|
|
1458
|
-
formats.push(f);
|
|
1459
|
-
}
|
|
1460
|
-
const result = formats.reduce((mem, f) => {
|
|
1461
|
-
const {
|
|
1462
|
-
formatName,
|
|
1463
|
-
formatOptions
|
|
1464
|
-
} = parseFormatStr(f);
|
|
1465
|
-
if (this.formats[formatName]) {
|
|
1466
|
-
let formatted = mem;
|
|
1467
|
-
try {
|
|
1468
|
-
const valOptions = options?.formatParams?.[options.interpolationkey] || {};
|
|
1469
|
-
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1470
|
-
formatted = this.formats[formatName](mem, l, {
|
|
1471
|
-
...formatOptions,
|
|
1472
|
-
...options,
|
|
1473
|
-
...valOptions
|
|
1474
|
-
});
|
|
1475
|
-
} catch (error) {
|
|
1476
|
-
this.logger.warn(error);
|
|
1477
|
-
}
|
|
1478
|
-
return formatted;
|
|
1479
|
-
} else {
|
|
1480
|
-
this.logger.warn(`there was no format function for ${formatName}`);
|
|
1481
|
-
}
|
|
1482
|
-
return mem;
|
|
1483
|
-
}, value);
|
|
1484
|
-
return result;
|
|
1485
|
-
}
|
|
1486
|
-
};
|
|
1487
|
-
var removePending = (q, name) => {
|
|
1488
|
-
if (q.pending[name] !== void 0) {
|
|
1489
|
-
delete q.pending[name];
|
|
1490
|
-
q.pendingCount--;
|
|
1491
|
-
}
|
|
1492
|
-
};
|
|
1493
|
-
var Connector = class extends EventEmitter {
|
|
1494
|
-
constructor(backend, store, services, options = {}) {
|
|
1495
|
-
super();
|
|
1496
|
-
this.backend = backend;
|
|
1497
|
-
this.store = store;
|
|
1498
|
-
this.services = services;
|
|
1499
|
-
this.languageUtils = services.languageUtils;
|
|
1500
|
-
this.options = options;
|
|
1501
|
-
this.logger = baseLogger.create("backendConnector");
|
|
1502
|
-
this.waitingReads = [];
|
|
1503
|
-
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1504
|
-
this.readingCalls = 0;
|
|
1505
|
-
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1506
|
-
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1507
|
-
this.state = {};
|
|
1508
|
-
this.queue = [];
|
|
1509
|
-
this.backend?.init?.(services, options.backend, options);
|
|
1510
|
-
}
|
|
1511
|
-
queueLoad(languages, namespaces, options, callback) {
|
|
1512
|
-
const toLoad = {};
|
|
1513
|
-
const pending = {};
|
|
1514
|
-
const toLoadLanguages = {};
|
|
1515
|
-
const toLoadNamespaces = {};
|
|
1516
|
-
languages.forEach((lng) => {
|
|
1517
|
-
let hasAllNamespaces = true;
|
|
1518
|
-
namespaces.forEach((ns) => {
|
|
1519
|
-
const name = `${lng}|${ns}`;
|
|
1520
|
-
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
1521
|
-
this.state[name] = 2;
|
|
1522
|
-
} else if (this.state[name] < 0) ;
|
|
1523
|
-
else if (this.state[name] === 1) {
|
|
1524
|
-
if (pending[name] === void 0) pending[name] = true;
|
|
1525
|
-
} else {
|
|
1526
|
-
this.state[name] = 1;
|
|
1527
|
-
hasAllNamespaces = false;
|
|
1528
|
-
if (pending[name] === void 0) pending[name] = true;
|
|
1529
|
-
if (toLoad[name] === void 0) toLoad[name] = true;
|
|
1530
|
-
if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
|
|
1531
|
-
}
|
|
1532
|
-
});
|
|
1533
|
-
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1534
|
-
});
|
|
1535
|
-
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1536
|
-
this.queue.push({
|
|
1537
|
-
pending,
|
|
1538
|
-
pendingCount: Object.keys(pending).length,
|
|
1539
|
-
loaded: {},
|
|
1540
|
-
errors: [],
|
|
1541
|
-
callback
|
|
1542
|
-
});
|
|
1543
|
-
}
|
|
1544
|
-
return {
|
|
1545
|
-
toLoad: Object.keys(toLoad),
|
|
1546
|
-
pending: Object.keys(pending),
|
|
1547
|
-
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1548
|
-
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1549
|
-
};
|
|
1550
|
-
}
|
|
1551
|
-
loaded(name, err, data) {
|
|
1552
|
-
const s = name.split("|");
|
|
1553
|
-
const lng = s[0];
|
|
1554
|
-
const ns = s[1];
|
|
1555
|
-
if (err) this.emit("failedLoading", lng, ns, err);
|
|
1556
|
-
if (!err && data) {
|
|
1557
|
-
this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
|
|
1558
|
-
skipCopy: true
|
|
1559
|
-
});
|
|
1560
|
-
}
|
|
1561
|
-
this.state[name] = err ? -1 : 2;
|
|
1562
|
-
if (err && data) this.state[name] = 0;
|
|
1563
|
-
const loaded = {};
|
|
1564
|
-
this.queue.forEach((q) => {
|
|
1565
|
-
pushPath(q.loaded, [lng], ns);
|
|
1566
|
-
removePending(q, name);
|
|
1567
|
-
if (err) q.errors.push(err);
|
|
1568
|
-
if (q.pendingCount === 0 && !q.done) {
|
|
1569
|
-
Object.keys(q.loaded).forEach((l) => {
|
|
1570
|
-
if (!loaded[l]) loaded[l] = {};
|
|
1571
|
-
const loadedKeys = q.loaded[l];
|
|
1572
|
-
if (loadedKeys.length) {
|
|
1573
|
-
loadedKeys.forEach((n) => {
|
|
1574
|
-
if (loaded[l][n] === void 0) loaded[l][n] = true;
|
|
1575
|
-
});
|
|
1576
|
-
}
|
|
1577
|
-
});
|
|
1578
|
-
q.done = true;
|
|
1579
|
-
if (q.errors.length) {
|
|
1580
|
-
q.callback(q.errors);
|
|
1581
|
-
} else {
|
|
1582
|
-
q.callback();
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
});
|
|
1586
|
-
this.emit("loaded", loaded);
|
|
1587
|
-
this.queue = this.queue.filter((q) => !q.done);
|
|
1588
|
-
}
|
|
1589
|
-
read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
|
|
1590
|
-
if (!lng.length) return callback(null, {});
|
|
1591
|
-
if (this.readingCalls >= this.maxParallelReads) {
|
|
1592
|
-
this.waitingReads.push({
|
|
1593
|
-
lng,
|
|
1594
|
-
ns,
|
|
1595
|
-
fcName,
|
|
1596
|
-
tried,
|
|
1597
|
-
wait,
|
|
1598
|
-
callback
|
|
1599
|
-
});
|
|
1600
|
-
return;
|
|
1601
|
-
}
|
|
1602
|
-
this.readingCalls++;
|
|
1603
|
-
const resolver = (err, data) => {
|
|
1604
|
-
this.readingCalls--;
|
|
1605
|
-
if (this.waitingReads.length > 0) {
|
|
1606
|
-
const next = this.waitingReads.shift();
|
|
1607
|
-
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1608
|
-
}
|
|
1609
|
-
if (err && data && tried < this.maxRetries) {
|
|
1610
|
-
setTimeout(() => {
|
|
1611
|
-
this.read(lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1612
|
-
}, wait);
|
|
1613
|
-
return;
|
|
1614
|
-
}
|
|
1615
|
-
callback(err, data);
|
|
1616
|
-
};
|
|
1617
|
-
const fc = this.backend[fcName].bind(this.backend);
|
|
1618
|
-
if (fc.length === 2) {
|
|
1619
|
-
try {
|
|
1620
|
-
const r = fc(lng, ns);
|
|
1621
|
-
if (r && typeof r.then === "function") {
|
|
1622
|
-
r.then((data) => resolver(null, data)).catch(resolver);
|
|
1623
|
-
} else {
|
|
1624
|
-
resolver(null, r);
|
|
1625
|
-
}
|
|
1626
|
-
} catch (err) {
|
|
1627
|
-
resolver(err);
|
|
1628
|
-
}
|
|
1629
|
-
return;
|
|
1630
|
-
}
|
|
1631
|
-
return fc(lng, ns, resolver);
|
|
1632
|
-
}
|
|
1633
|
-
prepareLoading(languages, namespaces, options = {}, callback) {
|
|
1634
|
-
if (!this.backend) {
|
|
1635
|
-
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
1636
|
-
return callback && callback();
|
|
1637
|
-
}
|
|
1638
|
-
if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1639
|
-
if (isString(namespaces)) namespaces = [namespaces];
|
|
1640
|
-
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1641
|
-
if (!toLoad.toLoad.length) {
|
|
1642
|
-
if (!toLoad.pending.length) callback();
|
|
1643
|
-
return null;
|
|
1644
|
-
}
|
|
1645
|
-
toLoad.toLoad.forEach((name) => {
|
|
1646
|
-
this.loadOne(name);
|
|
1647
|
-
});
|
|
1648
|
-
}
|
|
1649
|
-
load(languages, namespaces, callback) {
|
|
1650
|
-
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1651
|
-
}
|
|
1652
|
-
reload(languages, namespaces, callback) {
|
|
1653
|
-
this.prepareLoading(languages, namespaces, {
|
|
1654
|
-
reload: true
|
|
1655
|
-
}, callback);
|
|
1656
|
-
}
|
|
1657
|
-
loadOne(name, prefix = "") {
|
|
1658
|
-
const s = name.split("|");
|
|
1659
|
-
const lng = s[0];
|
|
1660
|
-
const ns = s[1];
|
|
1661
|
-
this.read(lng, ns, "read", void 0, void 0, (err, data) => {
|
|
1662
|
-
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
1663
|
-
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
1664
|
-
this.loaded(name, err, data);
|
|
1665
|
-
});
|
|
1666
|
-
}
|
|
1667
|
-
saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {
|
|
1668
|
-
}) {
|
|
1669
|
-
if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
|
|
1670
|
-
this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
|
|
1671
|
-
return;
|
|
1672
|
-
}
|
|
1673
|
-
if (key === void 0 || key === null || key === "") return;
|
|
1674
|
-
if (this.backend?.create) {
|
|
1675
|
-
const opts = {
|
|
1676
|
-
...options,
|
|
1677
|
-
isUpdate
|
|
1678
|
-
};
|
|
1679
|
-
const fc = this.backend.create.bind(this.backend);
|
|
1680
|
-
if (fc.length < 6) {
|
|
1681
|
-
try {
|
|
1682
|
-
let r;
|
|
1683
|
-
if (fc.length === 5) {
|
|
1684
|
-
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
1685
|
-
} else {
|
|
1686
|
-
r = fc(languages, namespace, key, fallbackValue);
|
|
1687
|
-
}
|
|
1688
|
-
if (r && typeof r.then === "function") {
|
|
1689
|
-
r.then((data) => clb(null, data)).catch(clb);
|
|
1690
|
-
} else {
|
|
1691
|
-
clb(null, r);
|
|
1692
|
-
}
|
|
1693
|
-
} catch (err) {
|
|
1694
|
-
clb(err);
|
|
1695
|
-
}
|
|
1696
|
-
} else {
|
|
1697
|
-
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
|
-
if (!languages || !languages[0]) return;
|
|
1701
|
-
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1702
|
-
}
|
|
1703
|
-
};
|
|
1704
|
-
var get = () => ({
|
|
1705
|
-
debug: false,
|
|
1706
|
-
initAsync: true,
|
|
1707
|
-
ns: ["translation"],
|
|
1708
|
-
defaultNS: ["translation"],
|
|
1709
|
-
fallbackLng: ["dev"],
|
|
1710
|
-
fallbackNS: false,
|
|
1711
|
-
supportedLngs: false,
|
|
1712
|
-
nonExplicitSupportedLngs: false,
|
|
1713
|
-
load: "all",
|
|
1714
|
-
preload: false,
|
|
1715
|
-
keySeparator: ".",
|
|
1716
|
-
nsSeparator: ":",
|
|
1717
|
-
pluralSeparator: "_",
|
|
1718
|
-
contextSeparator: "_",
|
|
1719
|
-
enableSelector: false,
|
|
1720
|
-
partialBundledLanguages: false,
|
|
1721
|
-
saveMissing: false,
|
|
1722
|
-
updateMissing: false,
|
|
1723
|
-
saveMissingTo: "fallback",
|
|
1724
|
-
saveMissingPlurals: true,
|
|
1725
|
-
missingKeyHandler: false,
|
|
1726
|
-
missingInterpolationHandler: false,
|
|
1727
|
-
postProcess: false,
|
|
1728
|
-
postProcessPassResolved: false,
|
|
1729
|
-
returnNull: false,
|
|
1730
|
-
returnEmptyString: true,
|
|
1731
|
-
returnObjects: false,
|
|
1732
|
-
joinArrays: false,
|
|
1733
|
-
returnedObjectHandler: false,
|
|
1734
|
-
parseMissingKeyHandler: false,
|
|
1735
|
-
appendNamespaceToMissingKey: false,
|
|
1736
|
-
appendNamespaceToCIMode: false,
|
|
1737
|
-
overloadTranslationOptionHandler: (args) => {
|
|
1738
|
-
let ret = {};
|
|
1739
|
-
if (typeof args[1] === "object") ret = args[1];
|
|
1740
|
-
if (isString(args[1])) ret.defaultValue = args[1];
|
|
1741
|
-
if (isString(args[2])) ret.tDescription = args[2];
|
|
1742
|
-
if (typeof args[2] === "object" || typeof args[3] === "object") {
|
|
1743
|
-
const options = args[3] || args[2];
|
|
1744
|
-
Object.keys(options).forEach((key) => {
|
|
1745
|
-
ret[key] = options[key];
|
|
1746
|
-
});
|
|
1747
|
-
}
|
|
1748
|
-
return ret;
|
|
1749
|
-
},
|
|
1750
|
-
interpolation: {
|
|
1751
|
-
escapeValue: true,
|
|
1752
|
-
prefix: "{{",
|
|
1753
|
-
suffix: "}}",
|
|
1754
|
-
formatSeparator: ",",
|
|
1755
|
-
unescapePrefix: "-",
|
|
1756
|
-
nestingPrefix: "$t(",
|
|
1757
|
-
nestingSuffix: ")",
|
|
1758
|
-
nestingOptionsSeparator: ",",
|
|
1759
|
-
maxReplaces: 1e3,
|
|
1760
|
-
skipOnVariables: true
|
|
1761
|
-
},
|
|
1762
|
-
cacheInBuiltFormats: true
|
|
1763
|
-
});
|
|
1764
|
-
var transformOptions = (options) => {
|
|
1765
|
-
if (isString(options.ns)) options.ns = [options.ns];
|
|
1766
|
-
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
1767
|
-
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
1768
|
-
if (options.supportedLngs && !options.supportedLngs.includes("cimode")) {
|
|
1769
|
-
options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
1770
|
-
}
|
|
1771
|
-
return options;
|
|
1772
|
-
};
|
|
1773
|
-
var noop = () => {
|
|
1774
|
-
};
|
|
1775
|
-
var bindMemberFunctions = (inst) => {
|
|
1776
|
-
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
1777
|
-
mems.forEach((mem) => {
|
|
1778
|
-
if (typeof inst[mem] === "function") {
|
|
1779
|
-
inst[mem] = inst[mem].bind(inst);
|
|
1780
|
-
}
|
|
1781
|
-
});
|
|
1782
|
-
};
|
|
1783
|
-
var I18n = class _I18n extends EventEmitter {
|
|
1784
|
-
constructor(options = {}, callback) {
|
|
1785
|
-
super();
|
|
1786
|
-
this.options = transformOptions(options);
|
|
1787
|
-
this.services = {};
|
|
1788
|
-
this.logger = baseLogger;
|
|
1789
|
-
this.modules = {
|
|
1790
|
-
external: []
|
|
1791
|
-
};
|
|
1792
|
-
bindMemberFunctions(this);
|
|
1793
|
-
if (callback && !this.isInitialized && !options.isClone) {
|
|
1794
|
-
if (!this.options.initAsync) {
|
|
1795
|
-
this.init(options, callback);
|
|
1796
|
-
return this;
|
|
1797
|
-
}
|
|
1798
|
-
setTimeout(() => {
|
|
1799
|
-
this.init(options, callback);
|
|
1800
|
-
}, 0);
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
init(options = {}, callback) {
|
|
1804
|
-
this.isInitializing = true;
|
|
1805
|
-
if (typeof options === "function") {
|
|
1806
|
-
callback = options;
|
|
1807
|
-
options = {};
|
|
1808
|
-
}
|
|
1809
|
-
if (options.defaultNS == null && options.ns) {
|
|
1810
|
-
if (isString(options.ns)) {
|
|
1811
|
-
options.defaultNS = options.ns;
|
|
1812
|
-
} else if (!options.ns.includes("translation")) {
|
|
1813
|
-
options.defaultNS = options.ns[0];
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
const defOpts = get();
|
|
1817
|
-
this.options = {
|
|
1818
|
-
...defOpts,
|
|
1819
|
-
...this.options,
|
|
1820
|
-
...transformOptions(options)
|
|
1821
|
-
};
|
|
1822
|
-
this.options.interpolation = {
|
|
1823
|
-
...defOpts.interpolation,
|
|
1824
|
-
...this.options.interpolation
|
|
1825
|
-
};
|
|
1826
|
-
if (options.keySeparator !== void 0) {
|
|
1827
|
-
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
1828
|
-
}
|
|
1829
|
-
if (options.nsSeparator !== void 0) {
|
|
1830
|
-
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
1831
|
-
}
|
|
1832
|
-
if (typeof this.options.overloadTranslationOptionHandler !== "function") {
|
|
1833
|
-
this.options.overloadTranslationOptionHandler = defOpts.overloadTranslationOptionHandler;
|
|
1834
|
-
}
|
|
1835
|
-
const createClassOnDemand = (ClassOrObject) => {
|
|
1836
|
-
if (!ClassOrObject) return null;
|
|
1837
|
-
if (typeof ClassOrObject === "function") return new ClassOrObject();
|
|
1838
|
-
return ClassOrObject;
|
|
1839
|
-
};
|
|
1840
|
-
if (!this.options.isClone) {
|
|
1841
|
-
if (this.modules.logger) {
|
|
1842
|
-
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
1843
|
-
} else {
|
|
1844
|
-
baseLogger.init(null, this.options);
|
|
1845
|
-
}
|
|
1846
|
-
let formatter;
|
|
1847
|
-
if (this.modules.formatter) {
|
|
1848
|
-
formatter = this.modules.formatter;
|
|
1849
|
-
} else {
|
|
1850
|
-
formatter = Formatter;
|
|
1851
|
-
}
|
|
1852
|
-
const lu = new LanguageUtil(this.options);
|
|
1853
|
-
this.store = new ResourceStore(this.options.resources, this.options);
|
|
1854
|
-
const s = this.services;
|
|
1855
|
-
s.logger = baseLogger;
|
|
1856
|
-
s.resourceStore = this.store;
|
|
1857
|
-
s.languageUtils = lu;
|
|
1858
|
-
s.pluralResolver = new PluralResolver(lu, {
|
|
1859
|
-
prepend: this.options.pluralSeparator
|
|
1860
|
-
});
|
|
1861
|
-
if (formatter) {
|
|
1862
|
-
s.formatter = createClassOnDemand(formatter);
|
|
1863
|
-
if (s.formatter.init) s.formatter.init(s, this.options);
|
|
1864
|
-
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
1865
|
-
}
|
|
1866
|
-
s.interpolator = new Interpolator(this.options);
|
|
1867
|
-
s.utils = {
|
|
1868
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1869
|
-
};
|
|
1870
|
-
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
1871
|
-
s.backendConnector.on("*", (event, ...args) => {
|
|
1872
|
-
this.emit(event, ...args);
|
|
1873
|
-
});
|
|
1874
|
-
if (this.modules.languageDetector) {
|
|
1875
|
-
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
1876
|
-
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
1877
|
-
}
|
|
1878
|
-
if (this.modules.i18nFormat) {
|
|
1879
|
-
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
1880
|
-
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
1881
|
-
}
|
|
1882
|
-
this.translator = new Translator(this.services, this.options);
|
|
1883
|
-
this.translator.on("*", (event, ...args) => {
|
|
1884
|
-
this.emit(event, ...args);
|
|
1885
|
-
});
|
|
1886
|
-
this.modules.external.forEach((m) => {
|
|
1887
|
-
if (m.init) m.init(this);
|
|
1888
|
-
});
|
|
1889
|
-
}
|
|
1890
|
-
this.format = this.options.interpolation.format;
|
|
1891
|
-
if (!callback) callback = noop;
|
|
1892
|
-
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
1893
|
-
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1894
|
-
if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
|
|
1895
|
-
}
|
|
1896
|
-
if (!this.services.languageDetector && !this.options.lng) {
|
|
1897
|
-
this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
1898
|
-
}
|
|
1899
|
-
const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
|
|
1900
|
-
storeApi.forEach((fcName) => {
|
|
1901
|
-
this[fcName] = (...args) => this.store[fcName](...args);
|
|
1902
|
-
});
|
|
1903
|
-
const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
|
|
1904
|
-
storeApiChained.forEach((fcName) => {
|
|
1905
|
-
this[fcName] = (...args) => {
|
|
1906
|
-
this.store[fcName](...args);
|
|
1907
|
-
return this;
|
|
1908
|
-
};
|
|
1909
|
-
});
|
|
1910
|
-
const deferred = defer();
|
|
1911
|
-
const load = () => {
|
|
1912
|
-
const finish = (err, t2) => {
|
|
1913
|
-
this.isInitializing = false;
|
|
1914
|
-
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
1915
|
-
this.isInitialized = true;
|
|
1916
|
-
if (!this.options.isClone) this.logger.log("initialized", this.options);
|
|
1917
|
-
this.emit("initialized", this.options);
|
|
1918
|
-
deferred.resolve(t2);
|
|
1919
|
-
callback(err, t2);
|
|
1920
|
-
};
|
|
1921
|
-
if ((this.languages || this.isLanguageChangingTo) && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
1922
|
-
this.changeLanguage(this.options.lng, finish);
|
|
1923
|
-
};
|
|
1924
|
-
if (this.options.resources || !this.options.initAsync) {
|
|
1925
|
-
load();
|
|
1926
|
-
} else {
|
|
1927
|
-
setTimeout(load, 0);
|
|
1928
|
-
}
|
|
1929
|
-
return deferred;
|
|
1930
|
-
}
|
|
1931
|
-
loadResources(language, callback = noop) {
|
|
1932
|
-
let usedCallback = callback;
|
|
1933
|
-
const usedLng = isString(language) ? language : this.language;
|
|
1934
|
-
if (typeof language === "function") usedCallback = language;
|
|
1935
|
-
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
1936
|
-
if (usedLng?.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
1937
|
-
const toLoad = [];
|
|
1938
|
-
const append = (lng) => {
|
|
1939
|
-
if (!lng) return;
|
|
1940
|
-
if (lng === "cimode") return;
|
|
1941
|
-
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
1942
|
-
lngs.forEach((l) => {
|
|
1943
|
-
if (l === "cimode") return;
|
|
1944
|
-
if (!toLoad.includes(l)) toLoad.push(l);
|
|
1945
|
-
});
|
|
1946
|
-
};
|
|
1947
|
-
if (!usedLng) {
|
|
1948
|
-
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1949
|
-
fallbacks.forEach((l) => append(l));
|
|
1950
|
-
} else {
|
|
1951
|
-
append(usedLng);
|
|
1952
|
-
}
|
|
1953
|
-
this.options.preload?.forEach?.((l) => append(l));
|
|
1954
|
-
this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
|
|
1955
|
-
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
1956
|
-
usedCallback(e);
|
|
1957
|
-
});
|
|
1958
|
-
} else {
|
|
1959
|
-
usedCallback(null);
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
reloadResources(lngs, ns, callback) {
|
|
1963
|
-
const deferred = defer();
|
|
1964
|
-
if (typeof lngs === "function") {
|
|
1965
|
-
callback = lngs;
|
|
1966
|
-
lngs = void 0;
|
|
1967
|
-
}
|
|
1968
|
-
if (typeof ns === "function") {
|
|
1969
|
-
callback = ns;
|
|
1970
|
-
ns = void 0;
|
|
1971
|
-
}
|
|
1972
|
-
if (!lngs) lngs = this.languages;
|
|
1973
|
-
if (!ns) ns = this.options.ns;
|
|
1974
|
-
if (!callback) callback = noop;
|
|
1975
|
-
this.services.backendConnector.reload(lngs, ns, (err) => {
|
|
1976
|
-
deferred.resolve();
|
|
1977
|
-
callback(err);
|
|
1978
|
-
});
|
|
1979
|
-
return deferred;
|
|
1980
|
-
}
|
|
1981
|
-
use(module) {
|
|
1982
|
-
if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
1983
|
-
if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
1984
|
-
if (module.type === "backend") {
|
|
1985
|
-
this.modules.backend = module;
|
|
1986
|
-
}
|
|
1987
|
-
if (module.type === "logger" || module.log && module.warn && module.error) {
|
|
1988
|
-
this.modules.logger = module;
|
|
1989
|
-
}
|
|
1990
|
-
if (module.type === "languageDetector") {
|
|
1991
|
-
this.modules.languageDetector = module;
|
|
1992
|
-
}
|
|
1993
|
-
if (module.type === "i18nFormat") {
|
|
1994
|
-
this.modules.i18nFormat = module;
|
|
1995
|
-
}
|
|
1996
|
-
if (module.type === "postProcessor") {
|
|
1997
|
-
postProcessor.addPostProcessor(module);
|
|
1998
|
-
}
|
|
1999
|
-
if (module.type === "formatter") {
|
|
2000
|
-
this.modules.formatter = module;
|
|
2001
|
-
}
|
|
2002
|
-
if (module.type === "3rdParty") {
|
|
2003
|
-
this.modules.external.push(module);
|
|
2004
|
-
}
|
|
2005
|
-
return this;
|
|
2006
|
-
}
|
|
2007
|
-
setResolvedLanguage(l) {
|
|
2008
|
-
if (!l || !this.languages) return;
|
|
2009
|
-
if (["cimode", "dev"].includes(l)) return;
|
|
2010
|
-
for (let li = 0; li < this.languages.length; li++) {
|
|
2011
|
-
const lngInLngs = this.languages[li];
|
|
2012
|
-
if (["cimode", "dev"].includes(lngInLngs)) continue;
|
|
2013
|
-
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2014
|
-
this.resolvedLanguage = lngInLngs;
|
|
2015
|
-
break;
|
|
2016
|
-
}
|
|
2017
|
-
}
|
|
2018
|
-
if (!this.resolvedLanguage && !this.languages.includes(l) && this.store.hasLanguageSomeTranslations(l)) {
|
|
2019
|
-
this.resolvedLanguage = l;
|
|
2020
|
-
this.languages.unshift(l);
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
changeLanguage(lng, callback) {
|
|
2024
|
-
this.isLanguageChangingTo = lng;
|
|
2025
|
-
const deferred = defer();
|
|
2026
|
-
this.emit("languageChanging", lng);
|
|
2027
|
-
const setLngProps = (l) => {
|
|
2028
|
-
this.language = l;
|
|
2029
|
-
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2030
|
-
this.resolvedLanguage = void 0;
|
|
2031
|
-
this.setResolvedLanguage(l);
|
|
2032
|
-
};
|
|
2033
|
-
const done = (err, l) => {
|
|
2034
|
-
if (l) {
|
|
2035
|
-
if (this.isLanguageChangingTo === lng) {
|
|
2036
|
-
setLngProps(l);
|
|
2037
|
-
this.translator.changeLanguage(l);
|
|
2038
|
-
this.isLanguageChangingTo = void 0;
|
|
2039
|
-
this.emit("languageChanged", l);
|
|
2040
|
-
this.logger.log("languageChanged", l);
|
|
2041
|
-
}
|
|
2042
|
-
} else {
|
|
2043
|
-
this.isLanguageChangingTo = void 0;
|
|
2044
|
-
}
|
|
2045
|
-
deferred.resolve((...args) => this.t(...args));
|
|
2046
|
-
if (callback) callback(err, (...args) => this.t(...args));
|
|
2047
|
-
};
|
|
2048
|
-
const setLng = (lngs) => {
|
|
2049
|
-
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2050
|
-
const fl = isString(lngs) ? lngs : lngs && lngs[0];
|
|
2051
|
-
const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
|
|
2052
|
-
if (l) {
|
|
2053
|
-
if (!this.language) {
|
|
2054
|
-
setLngProps(l);
|
|
2055
|
-
}
|
|
2056
|
-
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
2057
|
-
this.services.languageDetector?.cacheUserLanguage?.(l);
|
|
2058
|
-
}
|
|
2059
|
-
this.loadResources(l, (err) => {
|
|
2060
|
-
done(err, l);
|
|
2061
|
-
});
|
|
2062
|
-
};
|
|
2063
|
-
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2064
|
-
setLng(this.services.languageDetector.detect());
|
|
2065
|
-
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2066
|
-
if (this.services.languageDetector.detect.length === 0) {
|
|
2067
|
-
this.services.languageDetector.detect().then(setLng);
|
|
2068
|
-
} else {
|
|
2069
|
-
this.services.languageDetector.detect(setLng);
|
|
2070
|
-
}
|
|
2071
|
-
} else {
|
|
2072
|
-
setLng(lng);
|
|
2073
|
-
}
|
|
2074
|
-
return deferred;
|
|
2075
|
-
}
|
|
2076
|
-
getFixedT(lng, ns, keyPrefix, fixedOpts) {
|
|
2077
|
-
const scopeNs = fixedOpts?.scopeNs;
|
|
2078
|
-
const fixedT = (key, opts, ...rest) => {
|
|
2079
|
-
let o;
|
|
2080
|
-
if (typeof opts !== "object") {
|
|
2081
|
-
o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2082
|
-
} else {
|
|
2083
|
-
o = {
|
|
2084
|
-
...opts
|
|
2085
|
-
};
|
|
2086
|
-
}
|
|
2087
|
-
o.lng = o.lng || fixedT.lng;
|
|
2088
|
-
o.lngs = o.lngs || fixedT.lngs;
|
|
2089
|
-
const explicitCallNs = o.ns !== void 0 && o.ns !== null;
|
|
2090
|
-
o.ns = o.ns || fixedT.ns;
|
|
2091
|
-
if (o.keyPrefix !== "") o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2092
|
-
const selectorOpts = {
|
|
2093
|
-
...this.options,
|
|
2094
|
-
...o
|
|
2095
|
-
};
|
|
2096
|
-
if (Array.isArray(scopeNs) && !explicitCallNs) selectorOpts.ns = scopeNs;
|
|
2097
|
-
if (typeof o.keyPrefix === "function") o.keyPrefix = keysFromSelector(o.keyPrefix, selectorOpts);
|
|
2098
|
-
const keySeparator = this.options.keySeparator || ".";
|
|
2099
|
-
let resultKey;
|
|
2100
|
-
if (o.keyPrefix && Array.isArray(key)) {
|
|
2101
|
-
resultKey = key.map((k) => {
|
|
2102
|
-
if (typeof k === "function") k = keysFromSelector(k, selectorOpts);
|
|
2103
|
-
return `${o.keyPrefix}${keySeparator}${k}`;
|
|
2104
|
-
});
|
|
2105
|
-
} else {
|
|
2106
|
-
if (typeof key === "function") key = keysFromSelector(key, selectorOpts);
|
|
2107
|
-
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
|
|
2108
|
-
}
|
|
2109
|
-
return this.t(resultKey, o);
|
|
2110
|
-
};
|
|
2111
|
-
if (isString(lng)) {
|
|
2112
|
-
fixedT.lng = lng;
|
|
2113
|
-
} else {
|
|
2114
|
-
fixedT.lngs = lng;
|
|
2115
|
-
}
|
|
2116
|
-
fixedT.ns = ns;
|
|
2117
|
-
fixedT.keyPrefix = keyPrefix;
|
|
2118
|
-
return fixedT;
|
|
2119
|
-
}
|
|
2120
|
-
t(...args) {
|
|
2121
|
-
return this.translator?.translate(...args);
|
|
2122
|
-
}
|
|
2123
|
-
exists(...args) {
|
|
2124
|
-
return this.translator?.exists(...args);
|
|
2125
|
-
}
|
|
2126
|
-
setDefaultNamespace(ns) {
|
|
2127
|
-
this.options.defaultNS = ns;
|
|
2128
|
-
}
|
|
2129
|
-
hasLoadedNamespace(ns, options = {}) {
|
|
2130
|
-
if (!this.isInitialized) {
|
|
2131
|
-
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
2132
|
-
return false;
|
|
2133
|
-
}
|
|
2134
|
-
if (!this.languages || !this.languages.length) {
|
|
2135
|
-
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
2136
|
-
return false;
|
|
2137
|
-
}
|
|
2138
|
-
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2139
|
-
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2140
|
-
const lastLng = this.languages[this.languages.length - 1];
|
|
2141
|
-
if (lng.toLowerCase() === "cimode") return true;
|
|
2142
|
-
const loadNotPending = (l, n) => {
|
|
2143
|
-
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2144
|
-
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
2145
|
-
};
|
|
2146
|
-
if (options.precheck) {
|
|
2147
|
-
const preResult = options.precheck(this, loadNotPending);
|
|
2148
|
-
if (preResult !== void 0) return preResult;
|
|
2149
|
-
}
|
|
2150
|
-
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2151
|
-
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2152
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2153
|
-
return false;
|
|
2154
|
-
}
|
|
2155
|
-
loadNamespaces(ns, callback) {
|
|
2156
|
-
const deferred = defer();
|
|
2157
|
-
if (!this.options.ns) {
|
|
2158
|
-
if (callback) callback();
|
|
2159
|
-
return Promise.resolve();
|
|
2160
|
-
}
|
|
2161
|
-
if (isString(ns)) ns = [ns];
|
|
2162
|
-
ns.forEach((n) => {
|
|
2163
|
-
if (!this.options.ns.includes(n)) this.options.ns.push(n);
|
|
2164
|
-
});
|
|
2165
|
-
this.loadResources((err) => {
|
|
2166
|
-
deferred.resolve();
|
|
2167
|
-
if (callback) callback(err);
|
|
2168
|
-
});
|
|
2169
|
-
return deferred;
|
|
2170
|
-
}
|
|
2171
|
-
loadLanguages(lngs, callback) {
|
|
2172
|
-
const deferred = defer();
|
|
2173
|
-
if (isString(lngs)) lngs = [lngs];
|
|
2174
|
-
const preloaded = this.options.preload || [];
|
|
2175
|
-
const newLngs = lngs.filter((lng) => !preloaded.includes(lng) && this.services.languageUtils.isSupportedCode(lng));
|
|
2176
|
-
if (!newLngs.length) {
|
|
2177
|
-
if (callback) callback();
|
|
2178
|
-
return Promise.resolve();
|
|
2179
|
-
}
|
|
2180
|
-
this.options.preload = preloaded.concat(newLngs);
|
|
2181
|
-
this.loadResources((err) => {
|
|
2182
|
-
deferred.resolve();
|
|
2183
|
-
if (callback) callback(err);
|
|
2184
|
-
});
|
|
2185
|
-
return deferred;
|
|
2186
|
-
}
|
|
2187
|
-
dir(lng) {
|
|
2188
|
-
if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
|
|
2189
|
-
if (!lng) return "rtl";
|
|
2190
|
-
try {
|
|
2191
|
-
const l = new Intl.Locale(lng);
|
|
2192
|
-
if (l && l.getTextInfo) {
|
|
2193
|
-
const ti = l.getTextInfo();
|
|
2194
|
-
if (ti && ti.direction) return ti.direction;
|
|
2195
|
-
}
|
|
2196
|
-
} catch (e) {
|
|
2197
|
-
}
|
|
2198
|
-
const rtlLngs = ["ar", "shu", "sqr", "ssh", "xaa", "yhd", "yud", "aao", "abh", "abv", "acm", "acq", "acw", "acx", "acy", "adf", "ads", "aeb", "aec", "afb", "ajp", "apc", "apd", "arb", "arq", "ars", "ary", "arz", "auz", "avl", "ayh", "ayl", "ayn", "ayp", "bbz", "pga", "he", "iw", "ps", "pbt", "pbu", "pst", "prp", "prd", "ug", "ur", "ydd", "yds", "yih", "ji", "yi", "hbo", "men", "xmn", "fa", "jpr", "peo", "pes", "prs", "dv", "sam", "ckb"];
|
|
2199
|
-
const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
|
|
2200
|
-
if (lng.toLowerCase().indexOf("-latn") > 1) return "ltr";
|
|
2201
|
-
return rtlLngs.includes(languageUtils.getLanguagePartFromCode(lng)) || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
2202
|
-
}
|
|
2203
|
-
static createInstance(options = {}, callback) {
|
|
2204
|
-
const instance2 = new _I18n(options, callback);
|
|
2205
|
-
instance2.createInstance = _I18n.createInstance;
|
|
2206
|
-
return instance2;
|
|
2207
|
-
}
|
|
2208
|
-
cloneInstance(options = {}, callback = noop) {
|
|
2209
|
-
const forkResourceStore = options.forkResourceStore;
|
|
2210
|
-
if (forkResourceStore) delete options.forkResourceStore;
|
|
2211
|
-
const mergedOptions = {
|
|
2212
|
-
...this.options,
|
|
2213
|
-
...options,
|
|
2214
|
-
...{
|
|
2215
|
-
isClone: true
|
|
2216
|
-
}
|
|
2217
|
-
};
|
|
2218
|
-
const clone = new _I18n(mergedOptions);
|
|
2219
|
-
if (options.debug !== void 0 || options.prefix !== void 0) {
|
|
2220
|
-
clone.logger = clone.logger.clone(options);
|
|
2221
|
-
}
|
|
2222
|
-
const membersToCopy = ["store", "services", "language"];
|
|
2223
|
-
membersToCopy.forEach((m) => {
|
|
2224
|
-
clone[m] = this[m];
|
|
2225
|
-
});
|
|
2226
|
-
clone.services = {
|
|
2227
|
-
...this.services
|
|
2228
|
-
};
|
|
2229
|
-
clone.services.utils = {
|
|
2230
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2231
|
-
};
|
|
2232
|
-
if (forkResourceStore) {
|
|
2233
|
-
const clonedData = Object.keys(this.store.data).reduce((prev, l) => {
|
|
2234
|
-
prev[l] = {
|
|
2235
|
-
...this.store.data[l]
|
|
2236
|
-
};
|
|
2237
|
-
prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
|
|
2238
|
-
acc[n] = {
|
|
2239
|
-
...prev[l][n]
|
|
2240
|
-
};
|
|
2241
|
-
return acc;
|
|
2242
|
-
}, prev[l]);
|
|
2243
|
-
return prev;
|
|
2244
|
-
}, {});
|
|
2245
|
-
clone.store = new ResourceStore(clonedData, mergedOptions);
|
|
2246
|
-
clone.services.resourceStore = clone.store;
|
|
2247
|
-
}
|
|
2248
|
-
if (options.interpolation) {
|
|
2249
|
-
const defOpts = get();
|
|
2250
|
-
const mergedInterpolation = {
|
|
2251
|
-
...defOpts.interpolation,
|
|
2252
|
-
...this.options.interpolation,
|
|
2253
|
-
...options.interpolation
|
|
2254
|
-
};
|
|
2255
|
-
const mergedForInterpolator = {
|
|
2256
|
-
...mergedOptions,
|
|
2257
|
-
interpolation: mergedInterpolation
|
|
2258
|
-
};
|
|
2259
|
-
clone.services.interpolator = new Interpolator(mergedForInterpolator);
|
|
2260
|
-
}
|
|
2261
|
-
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2262
|
-
clone.translator.on("*", (event, ...args) => {
|
|
2263
|
-
clone.emit(event, ...args);
|
|
2264
|
-
});
|
|
2265
|
-
clone.init(mergedOptions, callback);
|
|
2266
|
-
clone.translator.options = mergedOptions;
|
|
2267
|
-
clone.translator.backendConnector.services.utils = {
|
|
2268
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2269
|
-
};
|
|
2270
|
-
return clone;
|
|
2271
|
-
}
|
|
2272
|
-
toJSON() {
|
|
2273
|
-
return {
|
|
2274
|
-
options: this.options,
|
|
2275
|
-
store: this.store,
|
|
2276
|
-
language: this.language,
|
|
2277
|
-
languages: this.languages,
|
|
2278
|
-
resolvedLanguage: this.resolvedLanguage
|
|
2279
|
-
};
|
|
2280
|
-
}
|
|
2281
|
-
};
|
|
2282
|
-
var instance = I18n.createInstance();
|
|
2283
|
-
var createInstance = instance.createInstance;
|
|
2284
|
-
var dir = instance.dir;
|
|
2285
|
-
var init = instance.init;
|
|
2286
|
-
var loadResources = instance.loadResources;
|
|
2287
|
-
var reloadResources = instance.reloadResources;
|
|
2288
|
-
var use = instance.use;
|
|
2289
|
-
var changeLanguage = instance.changeLanguage;
|
|
2290
|
-
var getFixedT = instance.getFixedT;
|
|
2291
|
-
var t = instance.t;
|
|
2292
|
-
var exists = instance.exists;
|
|
2293
|
-
var setDefaultNamespace = instance.setDefaultNamespace;
|
|
2294
|
-
var hasLoadedNamespace = instance.hasLoadedNamespace;
|
|
2295
|
-
var loadNamespaces = instance.loadNamespaces;
|
|
2296
|
-
var loadLanguages = instance.loadLanguages;
|
|
2297
|
-
|
|
2298
|
-
// src/i18n/config.ts
|
|
2299
|
-
import { initReactI18next } from "react-i18next";
|
|
2300
|
-
|
|
2301
|
-
// src/i18n/customCacheBackend.ts
|
|
2302
|
-
var _SupabaseCacheBackend = class _SupabaseCacheBackend {
|
|
2303
|
-
// 1. Принимаем SupabaseClient в конструктор
|
|
2304
|
-
constructor(supabase) {
|
|
2305
|
-
this.type = "backend";
|
|
2306
|
-
this.supabase = supabase;
|
|
2307
|
-
}
|
|
2308
|
-
init(services, backendOptions, i18nextOptions) {
|
|
2309
|
-
if (backendOptions?.supabase) {
|
|
2310
|
-
this.supabase = backendOptions.supabase;
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
/**
|
|
2314
|
-
* Загрузка всего манифеста версий из Supabase в память
|
|
2315
|
-
*/
|
|
2316
|
-
async loadManifest() {
|
|
2317
|
-
if (_SupabaseCacheBackend.isManifestLoaded || !this.supabase) return;
|
|
2318
|
-
try {
|
|
2319
|
-
const { data, error } = await this.supabase.from("translation_versions").select("namespace, lang_code, version");
|
|
2320
|
-
if (error) {
|
|
2321
|
-
if (error.code === "PGRST303" || error.message?.includes("future")) {
|
|
2322
|
-
console.warn("[i18n] Time drift detected (JWT in future). Falling back to cached translations.");
|
|
2323
|
-
}
|
|
2324
|
-
throw error;
|
|
2325
|
-
}
|
|
2326
|
-
if (data) {
|
|
2327
|
-
const manifestMap = {};
|
|
2328
|
-
data.forEach((row) => {
|
|
2329
|
-
manifestMap[`${row.lang_code}:${row.namespace}`] = row.version;
|
|
2330
|
-
});
|
|
2331
|
-
_SupabaseCacheBackend.manifest = manifestMap;
|
|
2332
|
-
_SupabaseCacheBackend.isManifestLoaded = true;
|
|
2333
|
-
}
|
|
2334
|
-
} catch (err) {
|
|
2335
|
-
console.warn("[i18n] Could not load translation versions manifest, using local cache:", err);
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
/**
|
|
2339
|
-
* Основной метод чтения локализации
|
|
2340
|
-
*/
|
|
2341
|
-
async read(language, namespace, callback) {
|
|
2342
|
-
const cacheKey = `i18n_${language}_${namespace}`;
|
|
2343
|
-
const versionKey = `i18n_ver_${language}_${namespace}`;
|
|
2344
|
-
const manifestKey = `${language}:${namespace}`;
|
|
2345
|
-
try {
|
|
2346
|
-
await this.loadManifest();
|
|
2347
|
-
const cachedData = localStorage.getItem(cacheKey);
|
|
2348
|
-
const localVersion = parseInt(localStorage.getItem(versionKey) || "0", 10);
|
|
2349
|
-
const serverVersion = _SupabaseCacheBackend.manifest[manifestKey];
|
|
2350
|
-
if (cachedData && serverVersion !== void 0 && localVersion === serverVersion) {
|
|
2351
|
-
callback(null, JSON.parse(cachedData));
|
|
2352
|
-
return;
|
|
2353
|
-
}
|
|
2354
|
-
if (cachedData && !_SupabaseCacheBackend.isManifestLoaded) {
|
|
2355
|
-
callback(null, JSON.parse(cachedData));
|
|
2356
|
-
return;
|
|
2357
|
-
}
|
|
2358
|
-
if (!this.supabase) {
|
|
2359
|
-
throw new Error("[SupabaseCacheBackend]: Supabase client is not initialized.");
|
|
2360
|
-
}
|
|
2361
|
-
const { data, error } = await this.supabase.from("translations").select("key, value").eq("lang_code", language).eq("namespace", namespace);
|
|
2362
|
-
if (error) throw error;
|
|
2363
|
-
const freshData = {};
|
|
2364
|
-
if (data) {
|
|
2365
|
-
data.forEach((row) => {
|
|
2366
|
-
this.setNestedKey(freshData, row.key, row.value);
|
|
2367
|
-
});
|
|
2368
|
-
}
|
|
2369
|
-
localStorage.setItem(cacheKey, JSON.stringify(freshData));
|
|
2370
|
-
if (serverVersion !== void 0) {
|
|
2371
|
-
localStorage.setItem(versionKey, serverVersion.toString());
|
|
2372
|
-
}
|
|
2373
|
-
callback(null, freshData);
|
|
2374
|
-
} catch (err) {
|
|
2375
|
-
console.warn(`[i18n] Fallback to cache for ${language}/${namespace} due to error:`, err);
|
|
2376
|
-
const cachedData = localStorage.getItem(cacheKey);
|
|
2377
|
-
if (cachedData) {
|
|
2378
|
-
callback(null, JSON.parse(cachedData));
|
|
2379
|
-
} else {
|
|
2380
|
-
callback(err, false);
|
|
2381
|
-
}
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
setNestedKey(obj, path, value) {
|
|
2385
|
-
const keys = path.split(".");
|
|
2386
|
-
let current = obj;
|
|
2387
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
2388
|
-
const key = keys[i];
|
|
2389
|
-
if (!current[key] || typeof current[key] !== "object") {
|
|
2390
|
-
current[key] = {};
|
|
2391
|
-
}
|
|
2392
|
-
current = current[key];
|
|
2393
|
-
}
|
|
2394
|
-
current[keys[keys.length - 1]] = value;
|
|
2395
|
-
}
|
|
2396
|
-
create(languages, namespace, key, fallbackValue) {
|
|
2397
|
-
}
|
|
2398
|
-
};
|
|
2399
|
-
_SupabaseCacheBackend.type = "backend";
|
|
2400
|
-
// Локальный манифест версий
|
|
2401
|
-
_SupabaseCacheBackend.manifest = {};
|
|
2402
|
-
_SupabaseCacheBackend.isManifestLoaded = false;
|
|
2403
|
-
var SupabaseCacheBackend = _SupabaseCacheBackend;
|
|
2404
|
-
|
|
2405
|
-
// src/i18n/config.ts
|
|
2406
|
-
var config_default = instance;
|
|
2407
|
-
|
|
2408
|
-
// src/context/AuthProvider.tsx
|
|
2409
|
-
import { createContext as createContext2, useContext as useContext2, useEffect, useState, useCallback, useRef } from "react";
|
|
2410
|
-
|
|
2411
|
-
// src/context/SupabaseProvider.tsx
|
|
2412
|
-
import { createContext, useContext, useMemo } from "react";
|
|
2413
|
-
import { createClient } from "@supabase/supabase-js";
|
|
2414
|
-
import { jsx } from "react/jsx-runtime";
|
|
2415
|
-
var SupabaseContext = createContext(null);
|
|
2416
|
-
var SupabaseProvider = ({
|
|
2417
|
-
children,
|
|
2418
|
-
client,
|
|
2419
|
-
config
|
|
2420
|
-
}) => {
|
|
2421
|
-
const supabaseInstance = useMemo(() => {
|
|
2422
|
-
if (client) return client;
|
|
2423
|
-
if (config?.url && config?.anonKey) {
|
|
2424
|
-
return createClient(config.url, config.anonKey);
|
|
2425
|
-
}
|
|
2426
|
-
throw new Error(
|
|
2427
|
-
'[SupabaseProvider]: \u0412\u0430\u043C \u043D\u0443\u0436\u043D\u043E \u043F\u0435\u0440\u0435\u0434\u0430\u0442\u044C \u043B\u0438\u0431\u043E prop "client", \u043B\u0438\u0431\u043E "config" ({ url, anonKey }).'
|
|
2428
|
-
);
|
|
2429
|
-
}, [client, config]);
|
|
2430
|
-
return /* @__PURE__ */ jsx(SupabaseContext.Provider, { value: { supabase: supabaseInstance }, children });
|
|
2431
|
-
};
|
|
2432
|
-
var useSupabase = () => {
|
|
2433
|
-
const context = useContext(SupabaseContext);
|
|
2434
|
-
if (!context) {
|
|
2435
|
-
throw new Error("useSupabase \u0434\u043E\u043B\u0436\u0435\u043D \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0443\u0442\u0440\u0438 <SupabaseProvider>");
|
|
2436
|
-
}
|
|
2437
|
-
return context.supabase;
|
|
2438
|
-
};
|
|
2439
|
-
|
|
2440
|
-
// src/context/AuthProvider.tsx
|
|
2441
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
2442
|
-
var AuthContext = createContext2(void 0);
|
|
2443
|
-
var useAuth = () => {
|
|
2444
|
-
const context = useContext2(AuthContext);
|
|
2445
|
-
if (!context) {
|
|
2446
|
-
throw new Error("useAuth should be used within the AuthProvider");
|
|
2447
|
-
}
|
|
2448
|
-
return context;
|
|
2449
|
-
};
|
|
2450
|
-
|
|
2451
|
-
// src/context/TranslationEditProvider.tsx
|
|
2452
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
2453
|
-
var TranslationEditContext = createContext3(void 0);
|
|
2454
|
-
var TranslationEditProvider = ({ children }) => {
|
|
2455
|
-
const supabase = useSupabase();
|
|
2456
|
-
const { user } = useAuth();
|
|
2457
|
-
const [isTranslationMode, setIsTranslationMode] = useState2(false);
|
|
2458
|
-
const [canEdit, setCanEdit] = useState2(false);
|
|
2459
|
-
const [isLoadingPermissions, setIsLoadingPermissions] = useState2(true);
|
|
2460
|
-
const checkPermission = useCallback2(async () => {
|
|
2461
|
-
if (!user) {
|
|
2462
|
-
setCanEdit(false);
|
|
2463
|
-
setIsTranslationMode(false);
|
|
2464
|
-
setIsLoadingPermissions(false);
|
|
2465
|
-
return;
|
|
2466
|
-
}
|
|
2467
|
-
try {
|
|
2468
|
-
setIsLoadingPermissions(true);
|
|
2469
|
-
const { data, error } = await supabase.from("translation_responsible_users").select("id").eq("user_id", user.id).maybeSingle();
|
|
2470
|
-
if (error) {
|
|
2471
|
-
console.error("Error checking translation responsibilities:", error);
|
|
2472
|
-
setCanEdit(false);
|
|
2473
|
-
setIsTranslationMode(false);
|
|
2474
|
-
} else {
|
|
2475
|
-
const hasAccess = Boolean(data);
|
|
2476
|
-
setCanEdit(hasAccess);
|
|
2477
|
-
if (!hasAccess) {
|
|
2478
|
-
setIsTranslationMode(false);
|
|
2479
|
-
}
|
|
2480
|
-
}
|
|
2481
|
-
} catch (err) {
|
|
2482
|
-
console.error("Permission check failed:", err);
|
|
2483
|
-
setCanEdit(false);
|
|
2484
|
-
} finally {
|
|
2485
|
-
setIsLoadingPermissions(false);
|
|
2486
|
-
}
|
|
2487
|
-
}, [user]);
|
|
2488
|
-
useEffect2(() => {
|
|
2489
|
-
checkPermission();
|
|
2490
|
-
}, [checkPermission]);
|
|
2491
|
-
const updateTranslation = async (key, namespace, newValue) => {
|
|
2492
|
-
if (!canEdit) return;
|
|
2493
|
-
const currentLang = config_default.language;
|
|
2494
|
-
const { error } = await supabase.from("translations").upsert({
|
|
2495
|
-
key,
|
|
2496
|
-
namespace,
|
|
2497
|
-
lang_code: currentLang,
|
|
2498
|
-
value: newValue
|
|
2499
|
-
}, { onConflict: "key,namespace,lang_code" });
|
|
2500
|
-
if (error) return alert("\u041E\u0448\u0438\u0431\u043A\u0430 \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u0438\u044F \u0432 \u0411\u0414");
|
|
2501
|
-
localStorage.removeItem(`i18n_ver_${currentLang}_${namespace}`);
|
|
2502
|
-
config_default.addResource(currentLang, namespace, key, newValue);
|
|
2503
|
-
config_default.changeLanguage(currentLang);
|
|
2504
|
-
};
|
|
2505
|
-
const handleSetTranslationMode = (val) => {
|
|
2506
|
-
if (canEdit) {
|
|
2507
|
-
setIsTranslationMode(val);
|
|
2508
|
-
}
|
|
2509
|
-
};
|
|
2510
|
-
return /* @__PURE__ */ jsx3(
|
|
2511
|
-
TranslationEditContext.Provider,
|
|
2512
|
-
{
|
|
2513
|
-
value: {
|
|
2514
|
-
isTranslationMode,
|
|
2515
|
-
setIsTranslationMode: handleSetTranslationMode,
|
|
2516
|
-
canEdit,
|
|
2517
|
-
isLoadingPermissions,
|
|
2518
|
-
updateTranslation
|
|
2519
|
-
},
|
|
2520
|
-
children
|
|
2521
|
-
}
|
|
2522
|
-
);
|
|
2523
|
-
};
|
|
2524
|
-
var useTranslationEdit = () => {
|
|
2525
|
-
const context = useContext3(TranslationEditContext);
|
|
2526
|
-
if (!context) throw new Error("useTranslationEdit must be used within TranslationEditProvider");
|
|
2527
|
-
return context;
|
|
2528
|
-
};
|
|
2529
|
-
|
|
2530
|
-
// src/i18n/TranslateText.tsx
|
|
2531
|
-
import { useState as useState4, useRef as useRef2, useEffect as useEffect4 } from "react";
|
|
2532
|
-
import { useTranslation } from "react-i18next";
|
|
2533
|
-
import { Box as Box2, Popper, Paper as Paper2, MenuList, MenuItem, ListItemIcon, ListItemText } from "@mui/material";
|
|
2534
|
-
import TranslateIcon2 from "@mui/icons-material/Translate";
|
|
2535
|
-
import LaunchIcon from "@mui/icons-material/Launch";
|
|
2536
|
-
|
|
2537
|
-
// src/i18n/TranslationDialog.tsx
|
|
2538
|
-
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
2539
|
-
import {
|
|
2540
|
-
Dialog,
|
|
2541
|
-
DialogTitle,
|
|
2542
|
-
DialogContent,
|
|
2543
|
-
DialogActions,
|
|
2544
|
-
Button,
|
|
2545
|
-
TextField,
|
|
2546
|
-
Box,
|
|
2547
|
-
Typography,
|
|
2548
|
-
CircularProgress,
|
|
2549
|
-
IconButton,
|
|
2550
|
-
Tooltip,
|
|
2551
|
-
Paper,
|
|
2552
|
-
Alert
|
|
2553
|
-
} from "@mui/material";
|
|
2554
|
-
import AutoFixHighIcon from "@mui/icons-material/AutoFixHigh";
|
|
2555
|
-
import TranslateIcon from "@mui/icons-material/Translate";
|
|
2556
|
-
import LightbulbIcon from "@mui/icons-material/Lightbulb";
|
|
2557
|
-
|
|
2558
|
-
// src/services/translation.service.ts
|
|
2559
|
-
var translationService = {
|
|
2560
|
-
// 1. Принимаем client первым аргументом
|
|
2561
|
-
incrementVersion: async (client, namespace, langCodes) => {
|
|
2562
|
-
try {
|
|
2563
|
-
const { data } = await client.from("translation_versions").select("version, lang_code").eq("namespace", namespace);
|
|
2564
|
-
const currentVersion = data && data.length > 0 ? Math.max(...data.map((d) => d.version || 0)) : 0;
|
|
2565
|
-
const nextVersion = currentVersion + 1;
|
|
2566
|
-
const languagesToUpdate = langCodes && langCodes.length > 0 ? langCodes : ["uk"];
|
|
2567
|
-
const updates = languagesToUpdate.map((lang_code) => ({
|
|
2568
|
-
namespace,
|
|
2569
|
-
lang_code,
|
|
2570
|
-
version: nextVersion,
|
|
2571
|
-
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2572
|
-
}));
|
|
2573
|
-
const { error } = await client.from("translation_versions").upsert(updates, { onConflict: "namespace,lang_code" });
|
|
2574
|
-
if (error) console.error("Error updating translation version:", error);
|
|
2575
|
-
return nextVersion;
|
|
2576
|
-
} catch (err) {
|
|
2577
|
-
console.error("Failed to increment version in Supabase:", err);
|
|
2578
|
-
return null;
|
|
2579
|
-
}
|
|
2580
|
-
},
|
|
2581
|
-
translateSmart: async (client, aiGenerateFn, params) => {
|
|
2582
|
-
const languagesToTranslate = params.targetLangs || (params.targetLang ? [params.targetLang] : []);
|
|
2583
|
-
try {
|
|
2584
|
-
const { data, error } = await client.functions.invoke("translate-smart", { body: params });
|
|
2585
|
-
if (!error && data) return data;
|
|
2586
|
-
} catch {
|
|
2587
|
-
console.warn("Edge Function translate-smart \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u0430, \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0435\u043C AIProvider...");
|
|
2588
|
-
}
|
|
2589
|
-
if (aiGenerateFn) {
|
|
2590
|
-
const prompt = `Translate the source text into language codes: ${JSON.stringify(languagesToTranslate)}.
|
|
2591
|
-
Source Text: "${params.text}"
|
|
2592
|
-
${params.contextHint ? `Context Hint: "${params.contextHint}"` : ""}`;
|
|
2593
|
-
const translations = await aiGenerateFn({
|
|
2594
|
-
prompt,
|
|
2595
|
-
systemInstruction: 'Respond STRICTLY with a valid JSON mapping lang code to text. Example: {"en": "Hello"}',
|
|
2596
|
-
jsonMode: true
|
|
2597
|
-
});
|
|
2598
|
-
if (translations) {
|
|
2599
|
-
if (params.targetLang) {
|
|
2600
|
-
return { translatedText: translations[params.targetLang] || params.text };
|
|
2601
|
-
}
|
|
2602
|
-
return { translations };
|
|
2603
|
-
}
|
|
2604
|
-
}
|
|
2605
|
-
if (params.targetLang) {
|
|
2606
|
-
const fallbackUrl = `https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=${params.targetLang}&dt=t&q=${encodeURIComponent(params.text)}`;
|
|
2607
|
-
const res = await fetch(fallbackUrl);
|
|
2608
|
-
if (res.ok) {
|
|
2609
|
-
const data = await res.json();
|
|
2610
|
-
return { translatedText: data[0].map((x) => x[0]).join("") };
|
|
2611
|
-
}
|
|
2612
|
-
}
|
|
2613
|
-
throw new Error("All translation strategies failed.");
|
|
2614
|
-
}
|
|
2615
|
-
};
|
|
2616
|
-
|
|
2617
|
-
// src/context/AIProvider.tsx
|
|
2618
|
-
import { createContext as createContext4, useContext as useContext4, useMemo as useMemo2 } from "react";
|
|
2619
|
-
import { GoogleGenAI } from "@google/genai";
|
|
2620
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
2621
|
-
var AIContext = createContext4(null);
|
|
2622
|
-
var AIProvider = ({
|
|
2623
|
-
children,
|
|
2624
|
-
config,
|
|
2625
|
-
apiKey: directApiKey
|
|
2626
|
-
}) => {
|
|
2627
|
-
const apiKey = directApiKey || config?.apiKey;
|
|
2628
|
-
const provider = config?.provider || "gemini";
|
|
2629
|
-
const modelName = config?.modelName || (provider === "gemini" ? "gemini-2.5-flash" : "gpt-4o-mini");
|
|
2630
|
-
const contextValue = useMemo2(() => {
|
|
2631
|
-
return {
|
|
2632
|
-
apiKey,
|
|
2633
|
-
provider,
|
|
2634
|
-
modelName,
|
|
2635
|
-
generate: async ({
|
|
2636
|
-
prompt,
|
|
2637
|
-
systemInstruction,
|
|
2638
|
-
jsonMode = false,
|
|
2639
|
-
temperature
|
|
2640
|
-
}) => {
|
|
2641
|
-
if (!apiKey) {
|
|
2642
|
-
console.warn("[AIProvider]: API Key \u043D\u0435 \u0437\u0430\u0434\u0430\u043D.");
|
|
2643
|
-
return null;
|
|
2644
|
-
}
|
|
2645
|
-
if (provider === "gemini") {
|
|
2646
|
-
try {
|
|
2647
|
-
const ai = new GoogleGenAI({ apiKey });
|
|
2648
|
-
const response = await ai.models.generateContent({
|
|
2649
|
-
model: modelName,
|
|
2650
|
-
contents: prompt,
|
|
2651
|
-
config: {
|
|
2652
|
-
systemInstruction,
|
|
2653
|
-
temperature,
|
|
2654
|
-
responseMimeType: jsonMode ? "application/json" : "text/plain"
|
|
2655
|
-
}
|
|
2656
|
-
});
|
|
2657
|
-
const rawText = response.text?.trim() || "";
|
|
2658
|
-
if (jsonMode) {
|
|
2659
|
-
const cleanedText = rawText.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, "").trim();
|
|
2660
|
-
return JSON.parse(cleanedText);
|
|
2661
|
-
}
|
|
2662
|
-
return rawText;
|
|
2663
|
-
} catch (err) {
|
|
2664
|
-
console.error("[AIProvider Gemini Error]:", err);
|
|
2665
|
-
return null;
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
if (provider === "openai") {
|
|
2669
|
-
try {
|
|
2670
|
-
const messages = [];
|
|
2671
|
-
if (systemInstruction) {
|
|
2672
|
-
messages.push({ role: "system", content: systemInstruction });
|
|
2673
|
-
}
|
|
2674
|
-
messages.push({ role: "user", content: prompt });
|
|
2675
|
-
const res = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
2676
|
-
method: "POST",
|
|
2677
|
-
headers: {
|
|
2678
|
-
"Content-Type": "application/json",
|
|
2679
|
-
Authorization: `Bearer ${apiKey}`
|
|
2680
|
-
},
|
|
2681
|
-
body: JSON.stringify({
|
|
2682
|
-
model: modelName,
|
|
2683
|
-
messages,
|
|
2684
|
-
temperature,
|
|
2685
|
-
...jsonMode ? { response_format: { type: "json_object" } } : {}
|
|
2686
|
-
})
|
|
2687
|
-
});
|
|
2688
|
-
const data = await res.json();
|
|
2689
|
-
const content = data.choices?.[0]?.message?.content?.trim() || "";
|
|
2690
|
-
if (jsonMode) {
|
|
2691
|
-
return JSON.parse(content);
|
|
2692
|
-
}
|
|
2693
|
-
return content;
|
|
2694
|
-
} catch (err) {
|
|
2695
|
-
console.error("[AIProvider OpenAI Error]:", err);
|
|
2696
|
-
return null;
|
|
2697
|
-
}
|
|
2698
|
-
}
|
|
2699
|
-
return null;
|
|
2700
|
-
}
|
|
2701
|
-
};
|
|
2702
|
-
}, [apiKey, provider, modelName]);
|
|
2703
|
-
return /* @__PURE__ */ jsx4(AIContext.Provider, { value: contextValue, children });
|
|
2704
|
-
};
|
|
2705
|
-
var useAI = () => {
|
|
2706
|
-
const context = useContext4(AIContext);
|
|
2707
|
-
if (!context) {
|
|
2708
|
-
throw new Error("useAI \u0434\u043E\u043B\u0436\u0435\u043D \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0443\u0442\u0440\u0438 <AIProvider>");
|
|
2709
|
-
}
|
|
2710
|
-
return context;
|
|
2711
|
-
};
|
|
2712
|
-
|
|
2713
|
-
// src/i18n/TranslationDialog.tsx
|
|
2714
|
-
import { jsx as jsx5, jsxs } from "react/jsx-runtime";
|
|
2715
|
-
var TranslationDialog = ({
|
|
2716
|
-
open,
|
|
2717
|
-
onClose,
|
|
2718
|
-
translationKey,
|
|
2719
|
-
namespace,
|
|
2720
|
-
onSave
|
|
2721
|
-
}) => {
|
|
2722
|
-
const supabase = useSupabase();
|
|
2723
|
-
const { generate } = useAI();
|
|
2724
|
-
const [languages, setLanguages] = useState3([]);
|
|
2725
|
-
const [values, setValues] = useState3({});
|
|
2726
|
-
const [contextHint, setContextHint] = useState3("");
|
|
2727
|
-
const [loading, setLoading] = useState3(false);
|
|
2728
|
-
const [saving, setSaving] = useState3(false);
|
|
2729
|
-
const [translatingCode, setTranslatingCode] = useState3(null);
|
|
2730
|
-
const [isTranslatingAll, setIsTranslatingAll] = useState3(false);
|
|
2731
|
-
const [error, setError] = useState3(null);
|
|
2732
|
-
useEffect3(() => {
|
|
2733
|
-
if (!open) return;
|
|
2734
|
-
const fetchData = async () => {
|
|
2735
|
-
setLoading(true);
|
|
2736
|
-
setError(null);
|
|
2737
|
-
try {
|
|
2738
|
-
const { data: langs, error: langErr } = await supabase.from("languages").select("code, name, svg_flag").eq("enabled", true);
|
|
2739
|
-
if (langErr) throw langErr;
|
|
2740
|
-
setLanguages(langs || []);
|
|
2741
|
-
const { data: trans, error: transErr } = await supabase.from("translations").select("lang_code, value, context_hint").eq("namespace", namespace).eq("key", translationKey);
|
|
2742
|
-
if (transErr) throw transErr;
|
|
2743
|
-
const initialValues = {};
|
|
2744
|
-
let existingHint = "";
|
|
2745
|
-
langs?.forEach((l) => {
|
|
2746
|
-
const found = trans?.find((t2) => t2.lang_code === l.code);
|
|
2747
|
-
initialValues[l.code] = found ? found.value : "";
|
|
2748
|
-
if (found?.context_hint) {
|
|
2749
|
-
existingHint = found.context_hint;
|
|
2750
|
-
}
|
|
2751
|
-
});
|
|
2752
|
-
setValues(initialValues);
|
|
2753
|
-
setContextHint(existingHint);
|
|
2754
|
-
} catch (err) {
|
|
2755
|
-
console.error("Failed to load translations:", err);
|
|
2756
|
-
setError(err?.message || "Failed to load initial translation data.");
|
|
2757
|
-
} finally {
|
|
2758
|
-
setLoading(false);
|
|
2759
|
-
}
|
|
2760
|
-
};
|
|
2761
|
-
fetchData();
|
|
2762
|
-
}, [open, translationKey, namespace]);
|
|
2763
|
-
const handleAutoTranslate = async (e, targetLang) => {
|
|
2764
|
-
e.preventDefault();
|
|
2765
|
-
e.stopPropagation();
|
|
2766
|
-
setError(null);
|
|
2767
|
-
setTranslatingCode(targetLang);
|
|
2768
|
-
try {
|
|
2769
|
-
const res = await translationService.translateSmart(supabase, generate, {
|
|
2770
|
-
text: translationKey,
|
|
2771
|
-
targetLang,
|
|
2772
|
-
contextHint
|
|
2773
|
-
});
|
|
2774
|
-
if (res?.translatedText) {
|
|
2775
|
-
setValues((prev) => ({ ...prev, [targetLang]: res.translatedText }));
|
|
2776
|
-
}
|
|
2777
|
-
} catch (err) {
|
|
2778
|
-
console.log(err);
|
|
2779
|
-
setError(`Failed to translate into ${targetLang}. ${err?.message || ""}`);
|
|
2780
|
-
} finally {
|
|
2781
|
-
setTranslatingCode(null);
|
|
2782
|
-
}
|
|
2783
|
-
};
|
|
2784
|
-
const handleTranslateAll = async (e) => {
|
|
2785
|
-
e.preventDefault();
|
|
2786
|
-
e.stopPropagation();
|
|
2787
|
-
if (!translationKey || languages.length === 0) return;
|
|
2788
|
-
setIsTranslatingAll(true);
|
|
2789
|
-
setError(null);
|
|
2790
|
-
try {
|
|
2791
|
-
const targetLangs = languages.map((l) => l.code);
|
|
2792
|
-
const res = await translationService.translateSmart(supabase, generate, {
|
|
2793
|
-
text: translationKey,
|
|
2794
|
-
targetLangs,
|
|
2795
|
-
contextHint
|
|
2796
|
-
});
|
|
2797
|
-
if (res?.translations) {
|
|
2798
|
-
setValues((prev) => ({ ...prev, ...res.translations }));
|
|
2799
|
-
}
|
|
2800
|
-
} catch (err) {
|
|
2801
|
-
console.error("Batch translation error:", err);
|
|
2802
|
-
setError(err?.message || "Failed to translate all languages.");
|
|
2803
|
-
} finally {
|
|
2804
|
-
setIsTranslatingAll(false);
|
|
2805
|
-
}
|
|
2806
|
-
};
|
|
2807
|
-
const handleSaveAll = async (e) => {
|
|
2808
|
-
e.preventDefault();
|
|
2809
|
-
e.stopPropagation();
|
|
2810
|
-
setSaving(true);
|
|
2811
|
-
setError(null);
|
|
2812
|
-
try {
|
|
2813
|
-
await onSave(values, contextHint);
|
|
2814
|
-
onClose();
|
|
2815
|
-
} catch (err) {
|
|
2816
|
-
console.error("Failed to save translations:", err);
|
|
2817
|
-
setError(err?.message || "Failed to save translations. Please try again.");
|
|
2818
|
-
} finally {
|
|
2819
|
-
setSaving(false);
|
|
2820
|
-
}
|
|
2821
|
-
};
|
|
2822
|
-
const handleClose = (_, reason) => {
|
|
2823
|
-
if (reason === "backdropClick" && isBusy) return;
|
|
2824
|
-
setError(null);
|
|
2825
|
-
onClose();
|
|
2826
|
-
};
|
|
2827
|
-
const isBusy = loading || saving || isTranslatingAll || translatingCode !== null;
|
|
2828
|
-
return /* @__PURE__ */ jsxs(
|
|
2829
|
-
Dialog,
|
|
2830
|
-
{
|
|
2831
|
-
open,
|
|
2832
|
-
onClose: handleClose,
|
|
2833
|
-
fullWidth: true,
|
|
2834
|
-
maxWidth: "sm",
|
|
2835
|
-
onClick: (e) => e.stopPropagation(),
|
|
2836
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
2837
|
-
children: [
|
|
2838
|
-
/* @__PURE__ */ jsxs(DialogTitle, { sx: { pb: 1, display: "flex", justifyContent: "space-between", alignItems: "flex-start" }, children: [
|
|
2839
|
-
/* @__PURE__ */ jsxs(Box, { children: [
|
|
2840
|
-
"Context Translation",
|
|
2841
|
-
/* @__PURE__ */ jsxs(Typography, { component: "div", variant: "subtitle2", color: "text.secondary", sx: { wordBreak: "break-all", mt: 0.5 }, children: [
|
|
2842
|
-
"Original: ",
|
|
2843
|
-
/* @__PURE__ */ jsxs("strong", { children: [
|
|
2844
|
-
'"',
|
|
2845
|
-
translationKey,
|
|
2846
|
-
'"'
|
|
2847
|
-
] })
|
|
2848
|
-
] })
|
|
2849
|
-
] }),
|
|
2850
|
-
!loading && /* @__PURE__ */ jsx5(
|
|
2851
|
-
Button,
|
|
2852
|
-
{
|
|
2853
|
-
type: "button",
|
|
2854
|
-
size: "small",
|
|
2855
|
-
variant: "outlined",
|
|
2856
|
-
color: "secondary",
|
|
2857
|
-
startIcon: isTranslatingAll ? /* @__PURE__ */ jsx5(CircularProgress, { size: 16, color: "inherit" }) : /* @__PURE__ */ jsx5(TranslateIcon, { fontSize: "small" }),
|
|
2858
|
-
onClick: handleTranslateAll,
|
|
2859
|
-
disabled: isBusy,
|
|
2860
|
-
sx: { flexShrink: 0, ml: 2, whiteSpace: "nowrap" },
|
|
2861
|
-
children: isTranslatingAll ? "Translating..." : "Translate All"
|
|
2862
|
-
}
|
|
2863
|
-
)
|
|
2864
|
-
] }),
|
|
2865
|
-
/* @__PURE__ */ jsxs(DialogContent, { dividers: true, sx: { pt: 2 }, children: [
|
|
2866
|
-
error && /* @__PURE__ */ jsx5(Alert, { severity: "error", onClose: () => setError(null), sx: { mb: 2 }, children: error }),
|
|
2867
|
-
loading ? /* @__PURE__ */ jsx5(Box, { sx: { display: "flex", justifyContent: "center", py: 4 }, children: /* @__PURE__ */ jsx5(CircularProgress, {}) }) : /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", gap: 2.5 }, children: [
|
|
2868
|
-
/* @__PURE__ */ jsxs(Paper, { variant: "outlined", sx: { p: 2, bgcolor: "action.hover", borderRadius: 2 }, children: [
|
|
2869
|
-
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1, mb: 1 }, children: [
|
|
2870
|
-
/* @__PURE__ */ jsx5(LightbulbIcon, { color: "warning", fontSize: "small" }),
|
|
2871
|
-
/* @__PURE__ */ jsx5(Typography, { variant: "subtitle2", sx: { fontWeight: 600 }, children: "Context Hint / Clarification" })
|
|
2872
|
-
] }),
|
|
2873
|
-
/* @__PURE__ */ jsx5(
|
|
2874
|
-
TextField,
|
|
2875
|
-
{
|
|
2876
|
-
fullWidth: true,
|
|
2877
|
-
multiline: true,
|
|
2878
|
-
rows: 2,
|
|
2879
|
-
size: "small",
|
|
2880
|
-
value: contextHint,
|
|
2881
|
-
onChange: (e) => setContextHint(e.target.value),
|
|
2882
|
-
placeholder: "e.g. Website navigation menu link to the home page",
|
|
2883
|
-
helperText: "This hint explains the exact meaning to AI translation models.",
|
|
2884
|
-
disabled: isBusy
|
|
2885
|
-
}
|
|
2886
|
-
)
|
|
2887
|
-
] }),
|
|
2888
|
-
languages.map((lang) => /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 2 }, children: [
|
|
2889
|
-
/* @__PURE__ */ jsx5(
|
|
2890
|
-
Box,
|
|
2891
|
-
{
|
|
2892
|
-
sx: {
|
|
2893
|
-
width: 32,
|
|
2894
|
-
height: 22,
|
|
2895
|
-
flexShrink: 0,
|
|
2896
|
-
borderRadius: "4px",
|
|
2897
|
-
overflow: "hidden",
|
|
2898
|
-
boxShadow: 1,
|
|
2899
|
-
"& svg": { width: "100%", height: "100%", display: "block" }
|
|
2900
|
-
},
|
|
2901
|
-
dangerouslySetInnerHTML: { __html: lang.svg_flag }
|
|
2902
|
-
}
|
|
2903
|
-
),
|
|
2904
|
-
/* @__PURE__ */ jsx5(
|
|
2905
|
-
TextField,
|
|
2906
|
-
{
|
|
2907
|
-
fullWidth: true,
|
|
2908
|
-
label: lang.name,
|
|
2909
|
-
size: "small",
|
|
2910
|
-
value: values[lang.code] || "",
|
|
2911
|
-
onChange: (e) => setValues((prev) => ({ ...prev, [lang.code]: e.target.value })),
|
|
2912
|
-
placeholder: "Enter manual translation...",
|
|
2913
|
-
disabled: isBusy
|
|
2914
|
-
}
|
|
2915
|
-
),
|
|
2916
|
-
/* @__PURE__ */ jsx5(Tooltip, { title: "Translate with context hint", children: /* @__PURE__ */ jsx5("span", { children: /* @__PURE__ */ jsx5(
|
|
2917
|
-
IconButton,
|
|
2918
|
-
{
|
|
2919
|
-
type: "button",
|
|
2920
|
-
color: "primary",
|
|
2921
|
-
disabled: isBusy,
|
|
2922
|
-
onClick: (e) => handleAutoTranslate(e, lang.code),
|
|
2923
|
-
children: translatingCode === lang.code ? /* @__PURE__ */ jsx5(CircularProgress, { size: 20, color: "inherit" }) : /* @__PURE__ */ jsx5(AutoFixHighIcon, { fontSize: "small" })
|
|
2924
|
-
}
|
|
2925
|
-
) }) })
|
|
2926
|
-
] }, lang.code))
|
|
2927
|
-
] })
|
|
2928
|
-
] }),
|
|
2929
|
-
/* @__PURE__ */ jsxs(DialogActions, { sx: { px: 3, py: 2 }, children: [
|
|
2930
|
-
/* @__PURE__ */ jsx5(Button, { onClick: onClose, disabled: isBusy, color: "inherit", type: "button", children: "Cancel" }),
|
|
2931
|
-
/* @__PURE__ */ jsx5(
|
|
2932
|
-
Button,
|
|
2933
|
-
{
|
|
2934
|
-
onClick: handleSaveAll,
|
|
2935
|
-
variant: "contained",
|
|
2936
|
-
disabled: isBusy,
|
|
2937
|
-
type: "button",
|
|
2938
|
-
children: saving ? "Saving..." : "Save All"
|
|
2939
|
-
}
|
|
2940
|
-
)
|
|
2941
|
-
] })
|
|
2942
|
-
]
|
|
2943
|
-
}
|
|
2944
|
-
);
|
|
2945
|
-
};
|
|
2946
|
-
|
|
2947
|
-
// src/context/TranslateProvider.tsx
|
|
2948
|
-
import { createContext as createContext5, useContext as useContext5 } from "react";
|
|
2949
|
-
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
2950
|
-
var TranslationNamespaceContext = createContext5({
|
|
2951
|
-
namespace: "common"
|
|
2952
|
-
// значение по умолчанию
|
|
2953
|
-
});
|
|
2954
|
-
var TranslateProvider = ({ namespace, children }) => {
|
|
2955
|
-
return /* @__PURE__ */ jsx6(TranslationNamespaceContext.Provider, { value: { namespace }, children });
|
|
2956
|
-
};
|
|
2957
|
-
var useTranslationNamespace = (overrideNamespace) => {
|
|
2958
|
-
const context = useContext5(TranslationNamespaceContext);
|
|
2959
|
-
return overrideNamespace || context.namespace;
|
|
2960
|
-
};
|
|
2961
|
-
|
|
2962
|
-
// src/i18n/TranslateText.tsx
|
|
2963
|
-
import { Fragment, jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2964
|
-
var TranslateText = ({
|
|
2965
|
-
overrideNamespace,
|
|
2966
|
-
children,
|
|
2967
|
-
values
|
|
2968
|
-
}) => {
|
|
2969
|
-
const namespace = useTranslationNamespace(overrideNamespace);
|
|
2970
|
-
const { t: t2, i18n } = useTranslation(namespace);
|
|
2971
|
-
const { isTranslationMode, canEdit } = useTranslationEdit();
|
|
2972
|
-
const supabase = useSupabase();
|
|
2973
|
-
const [anchorEl, setAnchorEl] = useState4(null);
|
|
2974
|
-
const [isDialogOpen, setIsDialogOpen] = useState4(false);
|
|
2975
|
-
const timeoutRef = useRef2(null);
|
|
2976
|
-
const translatedValue = t2(children, values);
|
|
2977
|
-
useEffect4(() => {
|
|
2978
|
-
return () => {
|
|
2979
|
-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
2980
|
-
};
|
|
2981
|
-
}, []);
|
|
2982
|
-
if (!canEdit || !isTranslationMode) {
|
|
2983
|
-
return /* @__PURE__ */ jsx7(Fragment, { children: translatedValue });
|
|
2984
|
-
}
|
|
2985
|
-
const handleSaveTranslations = async (newValues, contextHint) => {
|
|
2986
|
-
const upsertData = Object.entries(newValues).map(([langCode, text]) => ({
|
|
2987
|
-
lang_code: langCode,
|
|
2988
|
-
namespace,
|
|
2989
|
-
key: children,
|
|
2990
|
-
value: text,
|
|
2991
|
-
context_hint: contextHint
|
|
2992
|
-
}));
|
|
2993
|
-
const { error } = await supabase.from("translations").upsert(upsertData, { onConflict: "lang_code,namespace,key" });
|
|
2994
|
-
if (error) {
|
|
2995
|
-
alert("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u0438\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043D\u043D\u044B\u0445");
|
|
2996
|
-
throw error;
|
|
2997
|
-
}
|
|
2998
|
-
await translationService.incrementVersion(supabase, namespace, Object.keys(newValues));
|
|
2999
|
-
Object.entries(newValues).forEach(([langCode, text]) => {
|
|
3000
|
-
i18n.addResource(langCode, namespace, children, text);
|
|
3001
|
-
});
|
|
3002
|
-
};
|
|
3003
|
-
const handleMouseEnter = (event) => {
|
|
3004
|
-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
3005
|
-
setAnchorEl(event.currentTarget);
|
|
3006
|
-
};
|
|
3007
|
-
const handleMouseLeave = () => {
|
|
3008
|
-
timeoutRef.current = setTimeout(() => {
|
|
3009
|
-
setAnchorEl(null);
|
|
3010
|
-
}, 200);
|
|
3011
|
-
};
|
|
3012
|
-
const handleOpenDialog = (e) => {
|
|
3013
|
-
e.preventDefault();
|
|
3014
|
-
e.stopPropagation();
|
|
3015
|
-
setAnchorEl(null);
|
|
3016
|
-
if (document.activeElement instanceof HTMLElement) {
|
|
3017
|
-
document.activeElement.blur();
|
|
3018
|
-
}
|
|
3019
|
-
setIsDialogOpen(true);
|
|
3020
|
-
};
|
|
3021
|
-
const handleLaunchAction = (_) => {
|
|
3022
|
-
setAnchorEl(null);
|
|
3023
|
-
};
|
|
3024
|
-
const open = Boolean(anchorEl);
|
|
3025
|
-
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
3026
|
-
/* @__PURE__ */ jsx7(
|
|
3027
|
-
Box2,
|
|
3028
|
-
{
|
|
3029
|
-
component: "span",
|
|
3030
|
-
onMouseEnter: handleMouseEnter,
|
|
3031
|
-
onMouseLeave: handleMouseLeave,
|
|
3032
|
-
onClick: (e) => {
|
|
3033
|
-
e.preventDefault();
|
|
3034
|
-
e.stopPropagation();
|
|
3035
|
-
},
|
|
3036
|
-
sx: {
|
|
3037
|
-
display: "inline-block",
|
|
3038
|
-
position: "relative",
|
|
3039
|
-
borderRadius: "4px",
|
|
3040
|
-
padding: "0 3px",
|
|
3041
|
-
margin: "0 1px",
|
|
3042
|
-
border: "1px dashed #f59e0b",
|
|
3043
|
-
backgroundColor: "rgba(254, 243, 199, 0.35)",
|
|
3044
|
-
cursor: "pointer",
|
|
3045
|
-
transition: "all 0.2s ease-in-out",
|
|
3046
|
-
userSelect: "none",
|
|
3047
|
-
"&:hover": {
|
|
3048
|
-
backgroundColor: "#fef08a",
|
|
3049
|
-
borderColor: "#d97706",
|
|
3050
|
-
boxShadow: "0 0 0 2px rgba(245, 158, 11, 0.35)",
|
|
3051
|
-
transform: "scale(1.02)"
|
|
3052
|
-
}
|
|
3053
|
-
},
|
|
3054
|
-
children: translatedValue
|
|
3055
|
-
}
|
|
3056
|
-
),
|
|
3057
|
-
/* @__PURE__ */ jsx7(
|
|
3058
|
-
Popper,
|
|
3059
|
-
{
|
|
3060
|
-
open,
|
|
3061
|
-
anchorEl,
|
|
3062
|
-
placement: "bottom-start",
|
|
3063
|
-
style: { zIndex: 1300 },
|
|
3064
|
-
children: /* @__PURE__ */ jsx7(
|
|
3065
|
-
Paper2,
|
|
3066
|
-
{
|
|
3067
|
-
elevation: 4,
|
|
3068
|
-
onMouseEnter: () => {
|
|
3069
|
-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
3070
|
-
},
|
|
3071
|
-
onMouseLeave: handleMouseLeave,
|
|
3072
|
-
sx: {
|
|
3073
|
-
mt: 0.5,
|
|
3074
|
-
borderRadius: 2,
|
|
3075
|
-
minWidth: 140,
|
|
3076
|
-
boxShadow: "0px 10px 15px -3px rgba(0,0,0,0.1)"
|
|
3077
|
-
},
|
|
3078
|
-
children: /* @__PURE__ */ jsxs2(MenuList, { dense: true, sx: { py: 0.5 }, children: [
|
|
3079
|
-
/* @__PURE__ */ jsxs2(MenuItem, { onClick: handleOpenDialog, sx: { py: 0.8, px: 1.5 }, children: [
|
|
3080
|
-
/* @__PURE__ */ jsx7(ListItemIcon, { sx: { minWidth: "28px !important" }, children: /* @__PURE__ */ jsx7(TranslateIcon2, { fontSize: "small", sx: { color: "#d97706" } }) }),
|
|
3081
|
-
/* @__PURE__ */ jsx7(
|
|
3082
|
-
ListItemText,
|
|
3083
|
-
{
|
|
3084
|
-
primary: "Localization",
|
|
3085
|
-
slotProps: {
|
|
3086
|
-
primary: {
|
|
3087
|
-
sx: {
|
|
3088
|
-
fontSize: "0.825rem",
|
|
3089
|
-
fontWeight: 600,
|
|
3090
|
-
color: "text.primary"
|
|
3091
|
-
}
|
|
3092
|
-
}
|
|
3093
|
-
}
|
|
3094
|
-
}
|
|
3095
|
-
)
|
|
3096
|
-
] }),
|
|
3097
|
-
/* @__PURE__ */ jsxs2(MenuItem, { onClick: handleLaunchAction, sx: { py: 0.8, px: 1.5 }, children: [
|
|
3098
|
-
/* @__PURE__ */ jsx7(ListItemIcon, { sx: { minWidth: "28px !important" }, children: /* @__PURE__ */ jsx7(LaunchIcon, { fontSize: "small", color: "secondary" }) }),
|
|
3099
|
-
/* @__PURE__ */ jsx7(
|
|
3100
|
-
ListItemText,
|
|
3101
|
-
{
|
|
3102
|
-
primary: "Launch action",
|
|
3103
|
-
slotProps: {
|
|
3104
|
-
primary: {
|
|
3105
|
-
sx: {
|
|
3106
|
-
fontSize: "0.825rem",
|
|
3107
|
-
fontWeight: 600,
|
|
3108
|
-
color: "text.primary"
|
|
3109
|
-
}
|
|
3110
|
-
}
|
|
3111
|
-
}
|
|
3112
|
-
}
|
|
3113
|
-
)
|
|
3114
|
-
] })
|
|
3115
|
-
] })
|
|
3116
|
-
}
|
|
3117
|
-
)
|
|
3118
|
-
}
|
|
3119
|
-
),
|
|
3120
|
-
/* @__PURE__ */ jsx7("span", { style: { display: "inline" }, onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsx7(
|
|
3121
|
-
TranslationDialog,
|
|
3122
|
-
{
|
|
3123
|
-
open: isDialogOpen,
|
|
3124
|
-
onClose: () => setIsDialogOpen(false),
|
|
3125
|
-
translationKey: children,
|
|
3126
|
-
namespace,
|
|
3127
|
-
onSave: handleSaveTranslations
|
|
3128
|
-
}
|
|
3129
|
-
) })
|
|
3130
|
-
] });
|
|
3131
|
-
};
|
|
3132
|
-
|
|
3133
|
-
// src/UI/components/data.display/TranslatableTooltipComponent.tsx
|
|
3134
|
-
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
3135
|
-
var TranslatableTooltipComponent = ({
|
|
3136
|
-
overrideNamespace,
|
|
3137
|
-
title,
|
|
3138
|
-
disableSpan,
|
|
3139
|
-
children,
|
|
3140
|
-
...props
|
|
3141
|
-
}) => {
|
|
3142
|
-
const { isTranslationMode } = useTranslationEdit();
|
|
3143
|
-
return /* @__PURE__ */ jsx8(
|
|
3144
|
-
Tooltip2,
|
|
3145
|
-
{
|
|
3146
|
-
title: typeof title === "string" ? /* @__PURE__ */ jsx8(TranslateText, { overrideNamespace, children: title }) : title,
|
|
3147
|
-
slotProps: {
|
|
3148
|
-
popper: {
|
|
3149
|
-
sx: isTranslationMode ? {
|
|
3150
|
-
pointerEvents: "auto",
|
|
3151
|
-
// Разрешаем клики внутри тултипа
|
|
3152
|
-
"& .MuiTooltip-tooltip": {
|
|
3153
|
-
pointerEvents: "auto"
|
|
3154
|
-
}
|
|
3155
|
-
} : void 0
|
|
3156
|
-
}
|
|
3157
|
-
},
|
|
3158
|
-
leaveDelay: isTranslationMode ? 1e3 : 100,
|
|
3159
|
-
...props,
|
|
3160
|
-
children: disableSpan ? children : /* @__PURE__ */ jsx8("span", { children })
|
|
3161
|
-
}
|
|
3162
|
-
);
|
|
3163
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
AIProvider,
|
|
3
|
+
BreadcrumbProvider,
|
|
4
|
+
ConfirmationProvider,
|
|
5
|
+
CopyClipboardButtonComponent,
|
|
6
|
+
LocalizationProvider,
|
|
7
|
+
Providers,
|
|
8
|
+
SupabaseProvider,
|
|
9
|
+
ThemeProvider,
|
|
10
|
+
ToastProvider,
|
|
11
|
+
TranslatableTooltipComponent,
|
|
12
|
+
TranslateProvider,
|
|
13
|
+
TranslateText,
|
|
14
|
+
TranslationDialog,
|
|
15
|
+
TranslationEditProvider,
|
|
16
|
+
UserRoleChipComponent,
|
|
17
|
+
UserStatusChipComponent,
|
|
18
|
+
translationService,
|
|
19
|
+
useAI,
|
|
20
|
+
useAppTheme,
|
|
21
|
+
useBreadcrumb,
|
|
22
|
+
useConfirmation,
|
|
23
|
+
useLocalization,
|
|
24
|
+
useSupabase,
|
|
25
|
+
useToast,
|
|
26
|
+
useTranslationEdit,
|
|
27
|
+
useTranslationNamespace
|
|
28
|
+
} from "./chunk-CT3G3YSD.mjs";
|
|
3164
29
|
|
|
3165
30
|
// src/UI/components/inputs/TextFieldComponent.tsx
|
|
3166
|
-
import {
|
|
3167
|
-
import {
|
|
31
|
+
import { useState } from "react";
|
|
32
|
+
import {
|
|
33
|
+
TextField,
|
|
34
|
+
InputAdornment,
|
|
35
|
+
IconButton,
|
|
36
|
+
Box,
|
|
37
|
+
Tooltip
|
|
38
|
+
} from "@mui/material";
|
|
39
|
+
import LockIcon from "@mui/icons-material/Lock";
|
|
40
|
+
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
|
|
41
|
+
import CheckIcon from "@mui/icons-material/Check";
|
|
42
|
+
import ClearIcon from "@mui/icons-material/Clear";
|
|
43
|
+
import TranslateIcon from "@mui/icons-material/Translate";
|
|
44
|
+
import { useTranslation } from "react-i18next";
|
|
45
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3168
46
|
var TextFieldComponent = ({
|
|
3169
47
|
overrideNamespace,
|
|
3170
48
|
label,
|
|
@@ -3183,15 +61,15 @@ var TextFieldComponent = ({
|
|
|
3183
61
|
}) => {
|
|
3184
62
|
const supabase = useSupabase();
|
|
3185
63
|
const namespace = useTranslationNamespace();
|
|
3186
|
-
const { t
|
|
64
|
+
const { t, i18n } = useTranslation(namespace);
|
|
3187
65
|
const { isTranslationMode } = useTranslationEdit();
|
|
3188
|
-
const [copied, setCopied] =
|
|
3189
|
-
const [isDialogOpen, setIsDialogOpen] =
|
|
66
|
+
const [copied, setCopied] = useState(false);
|
|
67
|
+
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
|
3190
68
|
const isReadOnly = Boolean(slotProps?.htmlInput?.readOnly);
|
|
3191
69
|
const isLocked = disabled || isReadOnly;
|
|
3192
70
|
const stringValue = String(value ?? "");
|
|
3193
71
|
const hasValue = stringValue.length > 0;
|
|
3194
|
-
const translatedPlaceholder = placeholderKey ?
|
|
72
|
+
const translatedPlaceholder = placeholderKey ? t(placeholderKey) : void 0;
|
|
3195
73
|
const handleClear = (e) => {
|
|
3196
74
|
e.stopPropagation();
|
|
3197
75
|
if (onChange) {
|
|
@@ -3233,11 +111,11 @@ var TextFieldComponent = ({
|
|
|
3233
111
|
i18n.addResource(langCode, namespace, placeholderKey, text);
|
|
3234
112
|
});
|
|
3235
113
|
};
|
|
3236
|
-
return /* @__PURE__ */
|
|
3237
|
-
/* @__PURE__ */
|
|
3238
|
-
|
|
114
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
115
|
+
/* @__PURE__ */ jsx(
|
|
116
|
+
TextField,
|
|
3239
117
|
{
|
|
3240
|
-
label: typeof label === "string" ? /* @__PURE__ */
|
|
118
|
+
label: typeof label === "string" ? /* @__PURE__ */ jsx(TranslateText, { overrideNamespace, children: label }) : label,
|
|
3241
119
|
value,
|
|
3242
120
|
onChange,
|
|
3243
121
|
disabled,
|
|
@@ -3259,27 +137,27 @@ var TextFieldComponent = ({
|
|
|
3259
137
|
input: {
|
|
3260
138
|
...slotProps?.input || {},
|
|
3261
139
|
readOnly: isReadOnly,
|
|
3262
|
-
endAdornment: /* @__PURE__ */
|
|
3263
|
-
hasValue && !isLocked && !disableClearButton && /* @__PURE__ */
|
|
3264
|
-
|
|
140
|
+
endAdornment: /* @__PURE__ */ jsxs(InputAdornment, { position: "end", sx: { gap: 0.5 }, children: [
|
|
141
|
+
hasValue && !isLocked && !disableClearButton && /* @__PURE__ */ jsx(TranslatableTooltipComponent, { title: /* @__PURE__ */ jsx(TranslateText, { overrideNamespace, children: clearTooltip }), children: /* @__PURE__ */ jsx(
|
|
142
|
+
IconButton,
|
|
3265
143
|
{
|
|
3266
144
|
size: "small",
|
|
3267
145
|
onClick: handleClear,
|
|
3268
146
|
edge: "end",
|
|
3269
147
|
"aria-label": "clear input",
|
|
3270
|
-
children: /* @__PURE__ */
|
|
148
|
+
children: /* @__PURE__ */ jsx(ClearIcon, { fontSize: "small" })
|
|
3271
149
|
}
|
|
3272
150
|
) }),
|
|
3273
|
-
hasValue && /* @__PURE__ */
|
|
3274
|
-
|
|
151
|
+
hasValue && /* @__PURE__ */ jsx(TranslatableTooltipComponent, { title: /* @__PURE__ */ jsx(TranslateText, { overrideNamespace, children: copied ? copiedTooltip : copyTooltip }), children: /* @__PURE__ */ jsx(
|
|
152
|
+
IconButton,
|
|
3275
153
|
{
|
|
3276
154
|
size: "small",
|
|
3277
155
|
onClick: handleCopy,
|
|
3278
156
|
edge: "end",
|
|
3279
157
|
"aria-label": "copy content",
|
|
3280
158
|
color: copied ? "success" : "default",
|
|
3281
|
-
children: /* @__PURE__ */
|
|
3282
|
-
|
|
159
|
+
children: /* @__PURE__ */ jsxs(
|
|
160
|
+
Box,
|
|
3283
161
|
{
|
|
3284
162
|
sx: {
|
|
3285
163
|
display: "flex",
|
|
@@ -3290,7 +168,7 @@ var TextFieldComponent = ({
|
|
|
3290
168
|
height: 20
|
|
3291
169
|
},
|
|
3292
170
|
children: [
|
|
3293
|
-
/* @__PURE__ */
|
|
171
|
+
/* @__PURE__ */ jsx(
|
|
3294
172
|
ContentCopyIcon,
|
|
3295
173
|
{
|
|
3296
174
|
fontSize: "small",
|
|
@@ -3302,7 +180,7 @@ var TextFieldComponent = ({
|
|
|
3302
180
|
}
|
|
3303
181
|
}
|
|
3304
182
|
),
|
|
3305
|
-
/* @__PURE__ */
|
|
183
|
+
/* @__PURE__ */ jsx(
|
|
3306
184
|
CheckIcon,
|
|
3307
185
|
{
|
|
3308
186
|
fontSize: "small",
|
|
@@ -3320,8 +198,8 @@ var TextFieldComponent = ({
|
|
|
3320
198
|
)
|
|
3321
199
|
}
|
|
3322
200
|
) }),
|
|
3323
|
-
isLocked && showLock && /* @__PURE__ */
|
|
3324
|
-
|
|
201
|
+
isLocked && showLock && /* @__PURE__ */ jsx(TranslatableTooltipComponent, { title: /* @__PURE__ */ jsx(TranslateText, { overrideNamespace, children: lockTooltip }), children: /* @__PURE__ */ jsx(
|
|
202
|
+
IconButton,
|
|
3325
203
|
{
|
|
3326
204
|
size: "small",
|
|
3327
205
|
disabled: true,
|
|
@@ -3332,12 +210,12 @@ var TextFieldComponent = ({
|
|
|
3332
210
|
color: "text.secondary"
|
|
3333
211
|
}
|
|
3334
212
|
},
|
|
3335
|
-
children: /* @__PURE__ */
|
|
213
|
+
children: /* @__PURE__ */ jsx(LockIcon, { fontSize: "small" })
|
|
3336
214
|
}
|
|
3337
215
|
) }),
|
|
3338
216
|
slotProps?.input?.endAdornment,
|
|
3339
|
-
isTranslationMode && placeholderKey && /* @__PURE__ */
|
|
3340
|
-
|
|
217
|
+
isTranslationMode && placeholderKey && /* @__PURE__ */ jsx(Tooltip, { title: `Translate placeholder: "${placeholderKey}"`, children: /* @__PURE__ */ jsx(
|
|
218
|
+
IconButton,
|
|
3341
219
|
{
|
|
3342
220
|
size: "small",
|
|
3343
221
|
onClick: (e) => {
|
|
@@ -3354,7 +232,7 @@ var TextFieldComponent = ({
|
|
|
3354
232
|
backgroundColor: "#fef08a"
|
|
3355
233
|
}
|
|
3356
234
|
},
|
|
3357
|
-
children: /* @__PURE__ */
|
|
235
|
+
children: /* @__PURE__ */ jsx(TranslateIcon, { fontSize: "small" })
|
|
3358
236
|
}
|
|
3359
237
|
) })
|
|
3360
238
|
] })
|
|
@@ -3362,7 +240,7 @@ var TextFieldComponent = ({
|
|
|
3362
240
|
}
|
|
3363
241
|
}
|
|
3364
242
|
),
|
|
3365
|
-
placeholderKey && /* @__PURE__ */
|
|
243
|
+
placeholderKey && /* @__PURE__ */ jsx(
|
|
3366
244
|
TranslationDialog,
|
|
3367
245
|
{
|
|
3368
246
|
namespace,
|
|
@@ -3376,11 +254,11 @@ var TextFieldComponent = ({
|
|
|
3376
254
|
};
|
|
3377
255
|
|
|
3378
256
|
// src/UI/components/inputs/NumberInputComponent.tsx
|
|
3379
|
-
import { useState as
|
|
3380
|
-
import { IconButton as
|
|
257
|
+
import { useState as useState2, useEffect, useCallback, useMemo } from "react";
|
|
258
|
+
import { IconButton as IconButton2, InputAdornment as InputAdornment2, Box as Box2 } from "@mui/material";
|
|
3381
259
|
import AddIcon from "@mui/icons-material/Add";
|
|
3382
260
|
import RemoveIcon from "@mui/icons-material/Remove";
|
|
3383
|
-
import { Fragment as
|
|
261
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
3384
262
|
var NumberInputComponent = ({
|
|
3385
263
|
overrideNamespace,
|
|
3386
264
|
value,
|
|
@@ -3399,17 +277,17 @@ var NumberInputComponent = ({
|
|
|
3399
277
|
onBlur,
|
|
3400
278
|
...props
|
|
3401
279
|
}) => {
|
|
3402
|
-
const [inputValue, setInputValue] =
|
|
280
|
+
const [inputValue, setInputValue] = useState2(
|
|
3403
281
|
value !== null && value !== void 0 ? String(value) : ""
|
|
3404
282
|
);
|
|
3405
|
-
|
|
283
|
+
useEffect(() => {
|
|
3406
284
|
const stringVal = value !== null && value !== void 0 ? String(value) : "";
|
|
3407
285
|
if (Number(stringVal) !== Number(inputValue) || stringVal === "" && inputValue !== "." && inputValue !== "-") {
|
|
3408
286
|
setInputValue(stringVal);
|
|
3409
287
|
}
|
|
3410
288
|
}, [value]);
|
|
3411
289
|
const effectiveMin = !allowNegative ? Math.max(0, minValue ?? 0) : minValue;
|
|
3412
|
-
const formatDisplayValue =
|
|
290
|
+
const formatDisplayValue = useCallback(
|
|
3413
291
|
(raw) => {
|
|
3414
292
|
if (!useGrouping || !raw) return raw;
|
|
3415
293
|
const isNegative2 = raw.startsWith("-");
|
|
@@ -3420,7 +298,7 @@ var NumberInputComponent = ({
|
|
|
3420
298
|
},
|
|
3421
299
|
[useGrouping]
|
|
3422
300
|
);
|
|
3423
|
-
const formatAndClampValue =
|
|
301
|
+
const formatAndClampValue = useCallback(
|
|
3424
302
|
(num) => {
|
|
3425
303
|
let clamped = num;
|
|
3426
304
|
if (effectiveMin !== void 0 && clamped < effectiveMin) {
|
|
@@ -3438,7 +316,7 @@ var NumberInputComponent = ({
|
|
|
3438
316
|
},
|
|
3439
317
|
[effectiveMin, maxValue, allowFractional, decimalPlaces]
|
|
3440
318
|
);
|
|
3441
|
-
const handleChange =
|
|
319
|
+
const handleChange = useCallback(
|
|
3442
320
|
(e) => {
|
|
3443
321
|
let raw = e.target.value.replace(/\s/g, "").replace(",", ".");
|
|
3444
322
|
if (!allowNegative) {
|
|
@@ -3481,7 +359,7 @@ var NumberInputComponent = ({
|
|
|
3481
359
|
},
|
|
3482
360
|
[allowNegative, allowFractional, decimalPlaces, maxValue, onChange]
|
|
3483
361
|
);
|
|
3484
|
-
const handleBlur =
|
|
362
|
+
const handleBlur = useCallback(
|
|
3485
363
|
(e) => {
|
|
3486
364
|
onBlur?.(e);
|
|
3487
365
|
if (inputValue === "" || inputValue === "-" || inputValue === ".") {
|
|
@@ -3498,7 +376,7 @@ var NumberInputComponent = ({
|
|
|
3498
376
|
},
|
|
3499
377
|
[inputValue, formatAndClampValue, onChange, onBlur]
|
|
3500
378
|
);
|
|
3501
|
-
const handleStep =
|
|
379
|
+
const handleStep = useCallback(
|
|
3502
380
|
(delta) => {
|
|
3503
381
|
if (disabled) return;
|
|
3504
382
|
const currentNum = typeof value === "number" ? value : Number(inputValue) || 0;
|
|
@@ -3510,12 +388,12 @@ var NumberInputComponent = ({
|
|
|
3510
388
|
[disabled, value, inputValue, formatAndClampValue, onChange]
|
|
3511
389
|
);
|
|
3512
390
|
const currentNumeric = typeof value === "number" ? value : Number(inputValue);
|
|
3513
|
-
const isNegative =
|
|
391
|
+
const isNegative = useMemo(() => {
|
|
3514
392
|
return !isNaN(currentNumeric) && currentNumeric < 0;
|
|
3515
393
|
}, [currentNumeric]);
|
|
3516
394
|
const isDecrementDisabled = disabled || effectiveMin !== void 0 && !isNaN(currentNumeric) && currentNumeric <= effectiveMin;
|
|
3517
395
|
const isIncrementDisabled = disabled || maxValue !== void 0 && !isNaN(currentNumeric) && currentNumeric >= maxValue;
|
|
3518
|
-
return /* @__PURE__ */
|
|
396
|
+
return /* @__PURE__ */ jsx2(
|
|
3519
397
|
TextFieldComponent,
|
|
3520
398
|
{
|
|
3521
399
|
...props,
|
|
@@ -3548,29 +426,29 @@ var NumberInputComponent = ({
|
|
|
3548
426
|
}
|
|
3549
427
|
}
|
|
3550
428
|
},
|
|
3551
|
-
endAdornment: /* @__PURE__ */
|
|
429
|
+
endAdornment: /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
3552
430
|
slotProps?.input?.endAdornment,
|
|
3553
|
-
showStepper && !disabled && /* @__PURE__ */
|
|
3554
|
-
/* @__PURE__ */
|
|
3555
|
-
|
|
431
|
+
showStepper && !disabled && /* @__PURE__ */ jsx2(InputAdornment2, { position: "end", sx: { ml: 0.5 }, children: /* @__PURE__ */ jsxs2(Box2, { sx: { display: "flex", alignItems: "center", gap: "2px" }, children: [
|
|
432
|
+
/* @__PURE__ */ jsx2(
|
|
433
|
+
IconButton2,
|
|
3556
434
|
{
|
|
3557
435
|
size: "small",
|
|
3558
436
|
onClick: () => handleStep(-step),
|
|
3559
437
|
disabled: isDecrementDisabled,
|
|
3560
438
|
sx: { p: "2px" },
|
|
3561
439
|
"aria-label": "decrement",
|
|
3562
|
-
children: /* @__PURE__ */
|
|
440
|
+
children: /* @__PURE__ */ jsx2(RemoveIcon, { fontSize: "small" })
|
|
3563
441
|
}
|
|
3564
442
|
),
|
|
3565
|
-
/* @__PURE__ */
|
|
3566
|
-
|
|
443
|
+
/* @__PURE__ */ jsx2(
|
|
444
|
+
IconButton2,
|
|
3567
445
|
{
|
|
3568
446
|
size: "small",
|
|
3569
447
|
onClick: () => handleStep(step),
|
|
3570
448
|
disabled: isIncrementDisabled,
|
|
3571
449
|
sx: { p: "2px" },
|
|
3572
450
|
"aria-label": "increment",
|
|
3573
|
-
children: /* @__PURE__ */
|
|
451
|
+
children: /* @__PURE__ */ jsx2(AddIcon, { fontSize: "small" })
|
|
3574
452
|
}
|
|
3575
453
|
)
|
|
3576
454
|
] }) })
|
|
@@ -3582,24 +460,24 @@ var NumberInputComponent = ({
|
|
|
3582
460
|
};
|
|
3583
461
|
|
|
3584
462
|
// src/UI/components/inputs/UrlComponent.tsx
|
|
3585
|
-
import { useState as
|
|
463
|
+
import { useState as useState3 } from "react";
|
|
3586
464
|
import {
|
|
3587
|
-
TextField as
|
|
465
|
+
TextField as TextField2,
|
|
3588
466
|
InputAdornment as InputAdornment3,
|
|
3589
|
-
IconButton as
|
|
3590
|
-
Tooltip as
|
|
467
|
+
IconButton as IconButton3,
|
|
468
|
+
Tooltip as Tooltip2,
|
|
3591
469
|
Popover,
|
|
3592
|
-
Box as
|
|
3593
|
-
Typography
|
|
3594
|
-
Button
|
|
470
|
+
Box as Box3,
|
|
471
|
+
Typography,
|
|
472
|
+
Button
|
|
3595
473
|
} from "@mui/material";
|
|
3596
474
|
import LinkIcon from "@mui/icons-material/Link";
|
|
3597
|
-
import
|
|
475
|
+
import LaunchIcon from "@mui/icons-material/Launch";
|
|
3598
476
|
import ContentCopyIcon2 from "@mui/icons-material/ContentCopy";
|
|
3599
477
|
import CheckIcon2 from "@mui/icons-material/Check";
|
|
3600
478
|
import EditNoteIcon from "@mui/icons-material/EditNote";
|
|
3601
479
|
import LockIcon2 from "@mui/icons-material/Lock";
|
|
3602
|
-
import { Fragment as
|
|
480
|
+
import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
3603
481
|
function UrlComponent({
|
|
3604
482
|
overrideNamespace,
|
|
3605
483
|
label,
|
|
@@ -3617,8 +495,8 @@ function UrlComponent({
|
|
|
3617
495
|
lockTooltip = "Field is not editable",
|
|
3618
496
|
sx
|
|
3619
497
|
}) {
|
|
3620
|
-
const [copied, setCopied] =
|
|
3621
|
-
const [anchorEl, setAnchorEl] =
|
|
498
|
+
const [copied, setCopied] = useState3(false);
|
|
499
|
+
const [anchorEl, setAnchorEl] = useState3(null);
|
|
3622
500
|
const isViewMode = disabled || readOnly;
|
|
3623
501
|
const currentUrl = typeof value === "object" && value !== null ? value.url || "" : value || "";
|
|
3624
502
|
const currentTitle = typeof value === "object" && value !== null ? value.title || "" : "";
|
|
@@ -3666,11 +544,11 @@ function UrlComponent({
|
|
|
3666
544
|
};
|
|
3667
545
|
const isTitlePopoverOpen = Boolean(anchorEl);
|
|
3668
546
|
const displayHelperText = error ? helperText : description || helperText;
|
|
3669
|
-
return /* @__PURE__ */
|
|
3670
|
-
/* @__PURE__ */
|
|
3671
|
-
|
|
547
|
+
return /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
548
|
+
/* @__PURE__ */ jsx3(
|
|
549
|
+
TextField2,
|
|
3672
550
|
{
|
|
3673
|
-
label: /* @__PURE__ */
|
|
551
|
+
label: /* @__PURE__ */ jsx3(TranslateText, { overrideNamespace, children: label }),
|
|
3674
552
|
type: isViewMode ? "text" : "url",
|
|
3675
553
|
value: isViewMode ? displayLabelText : currentUrl,
|
|
3676
554
|
onChange: (e) => handleUrlChange(e.target.value),
|
|
@@ -3700,20 +578,20 @@ function UrlComponent({
|
|
|
3700
578
|
onClick: handleInputClick
|
|
3701
579
|
},
|
|
3702
580
|
input: {
|
|
3703
|
-
startAdornment: /* @__PURE__ */
|
|
3704
|
-
endAdornment: /* @__PURE__ */
|
|
3705
|
-
!isViewMode && /* @__PURE__ */
|
|
3706
|
-
|
|
581
|
+
startAdornment: /* @__PURE__ */ jsx3(InputAdornment3, { position: "start", children: /* @__PURE__ */ jsx3(LinkIcon, { fontSize: "small", color: isViewMode && finalUrl ? "primary" : "action" }) }),
|
|
582
|
+
endAdornment: /* @__PURE__ */ jsxs3(InputAdornment3, { position: "end", sx: { gap: 0.5 }, children: [
|
|
583
|
+
!isViewMode && /* @__PURE__ */ jsx3(Tooltip2, { title: currentTitle ? `Title: "${currentTitle}"` : /* @__PURE__ */ jsx3(TranslateText, { overrideNamespace: overrideNamespace || "form_components", children: "Set link title" }), children: /* @__PURE__ */ jsx3(
|
|
584
|
+
IconButton3,
|
|
3707
585
|
{
|
|
3708
586
|
size: "small",
|
|
3709
587
|
onClick: handleOpenTitleMenu,
|
|
3710
588
|
color: currentTitle ? "primary" : "default",
|
|
3711
|
-
children: /* @__PURE__ */
|
|
589
|
+
children: /* @__PURE__ */ jsx3(EditNoteIcon, { fontSize: "small" })
|
|
3712
590
|
}
|
|
3713
591
|
) }),
|
|
3714
|
-
finalUrl && /* @__PURE__ */
|
|
3715
|
-
isViewMode && showLock && /* @__PURE__ */
|
|
3716
|
-
|
|
592
|
+
finalUrl && /* @__PURE__ */ jsx3(Tooltip2, { title: copied ? /* @__PURE__ */ jsx3(TranslateText, { overrideNamespace: overrideNamespace || "form_components", children: "Copied!" }) : /* @__PURE__ */ jsx3(TranslateText, { overrideNamespace: overrideNamespace || "form_components", children: "Copy link" }), children: /* @__PURE__ */ jsx3(IconButton3, { size: "small", onClick: handleCopy, color: copied ? "success" : "default", children: copied ? /* @__PURE__ */ jsx3(CheckIcon2, { fontSize: "small" }) : /* @__PURE__ */ jsx3(ContentCopyIcon2, { fontSize: "small" }) }) }),
|
|
593
|
+
isViewMode && showLock && /* @__PURE__ */ jsx3(Tooltip2, { title: /* @__PURE__ */ jsx3(TranslateText, { overrideNamespace, children: lockTooltip }), children: /* @__PURE__ */ jsx3(
|
|
594
|
+
IconButton3,
|
|
3717
595
|
{
|
|
3718
596
|
size: "small",
|
|
3719
597
|
disabled: true,
|
|
@@ -3724,16 +602,16 @@ function UrlComponent({
|
|
|
3724
602
|
color: "text.secondary"
|
|
3725
603
|
}
|
|
3726
604
|
},
|
|
3727
|
-
children: /* @__PURE__ */
|
|
605
|
+
children: /* @__PURE__ */ jsx3(LockIcon2, { fontSize: "small" })
|
|
3728
606
|
}
|
|
3729
607
|
) }),
|
|
3730
|
-
finalUrl && /* @__PURE__ */
|
|
608
|
+
finalUrl && /* @__PURE__ */ jsx3(Tooltip2, { title: /* @__PURE__ */ jsx3(TranslateText, { overrideNamespace: overrideNamespace || "form_components", children: "Open link" }), children: /* @__PURE__ */ jsx3(IconButton3, { size: "small", onClick: handleOpenLink, children: /* @__PURE__ */ jsx3(LaunchIcon, { fontSize: "small", color: isViewMode ? "primary" : "action" }) }) })
|
|
3731
609
|
] })
|
|
3732
610
|
}
|
|
3733
611
|
}
|
|
3734
612
|
}
|
|
3735
613
|
),
|
|
3736
|
-
/* @__PURE__ */
|
|
614
|
+
/* @__PURE__ */ jsxs3(
|
|
3737
615
|
Popover,
|
|
3738
616
|
{
|
|
3739
617
|
open: isTitlePopoverOpen,
|
|
@@ -3751,13 +629,13 @@ function UrlComponent({
|
|
|
3751
629
|
paper: { sx: { p: 2, width: 280 } }
|
|
3752
630
|
},
|
|
3753
631
|
children: [
|
|
3754
|
-
/* @__PURE__ */
|
|
3755
|
-
/* @__PURE__ */
|
|
3756
|
-
/* @__PURE__ */
|
|
632
|
+
/* @__PURE__ */ jsx3(Typography, { variant: "subtitle2", sx: { mb: 1, fontWeight: "bold" }, children: /* @__PURE__ */ jsx3(TranslateText, { overrideNamespace: overrideNamespace || "form_components", children: "Link Title (Anchor)" }) }),
|
|
633
|
+
/* @__PURE__ */ jsxs3(Typography, { variant: "caption", color: "text.secondary", sx: { mb: 1.5, display: "block" }, children: [
|
|
634
|
+
/* @__PURE__ */ jsx3(TranslateText, { overrideNamespace: overrideNamespace || "form_components", children: "Specify the text to display instead of the URL address" }),
|
|
3757
635
|
":"
|
|
3758
636
|
] }),
|
|
3759
|
-
/* @__PURE__ */
|
|
3760
|
-
|
|
637
|
+
/* @__PURE__ */ jsx3(
|
|
638
|
+
TextField2,
|
|
3761
639
|
{
|
|
3762
640
|
size: "small",
|
|
3763
641
|
fullWidth: true,
|
|
@@ -3773,7 +651,7 @@ function UrlComponent({
|
|
|
3773
651
|
}
|
|
3774
652
|
}
|
|
3775
653
|
),
|
|
3776
|
-
/* @__PURE__ */
|
|
654
|
+
/* @__PURE__ */ jsx3(Box3, { sx: { display: "flex", justifyContent: "flex-end", mt: 1.5 }, children: /* @__PURE__ */ jsx3(Button, { size: "small", variant: "contained", onClick: handleCloseTitleMenu, children: /* @__PURE__ */ jsx3(TranslateText, { overrideNamespace: overrideNamespace || "form_components", children: "Done" }) }) })
|
|
3777
655
|
]
|
|
3778
656
|
}
|
|
3779
657
|
)
|
|
@@ -3781,8 +659,8 @@ function UrlComponent({
|
|
|
3781
659
|
}
|
|
3782
660
|
|
|
3783
661
|
// src/UI/components/inputs/EmailInputComponent.tsx
|
|
3784
|
-
import { useState as
|
|
3785
|
-
import { jsx as
|
|
662
|
+
import { useState as useState4 } from "react";
|
|
663
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
3786
664
|
var EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
3787
665
|
var EmailInputComponent = ({
|
|
3788
666
|
value = "",
|
|
@@ -3795,7 +673,7 @@ var EmailInputComponent = ({
|
|
|
3795
673
|
onValidationChange,
|
|
3796
674
|
...props
|
|
3797
675
|
}) => {
|
|
3798
|
-
const [internalError, setInternalError] =
|
|
676
|
+
const [internalError, setInternalError] = useState4(null);
|
|
3799
677
|
const validateEmail = (val) => {
|
|
3800
678
|
if (disableValidation) return true;
|
|
3801
679
|
const stringVal = String(val ?? "").trim();
|
|
@@ -3827,7 +705,7 @@ var EmailInputComponent = ({
|
|
|
3827
705
|
};
|
|
3828
706
|
const hasError = Boolean(externalError || internalError);
|
|
3829
707
|
const displayHelperText = externalHelperText || internalError || void 0;
|
|
3830
|
-
return /* @__PURE__ */
|
|
708
|
+
return /* @__PURE__ */ jsx4(
|
|
3831
709
|
TextFieldComponent,
|
|
3832
710
|
{
|
|
3833
711
|
type: "email",
|
|
@@ -3841,546 +719,144 @@ var EmailInputComponent = ({
|
|
|
3841
719
|
);
|
|
3842
720
|
};
|
|
3843
721
|
|
|
3844
|
-
// src/UI/
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
}
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
es: "DD/MM/YYYY, HH:mm",
|
|
3870
|
-
fr: "DD/MM/YYYY, HH:mm",
|
|
3871
|
-
it: "DD/MM/YYYY, HH:mm"
|
|
3872
|
-
};
|
|
3873
|
-
var DEFAULT_DATE_FORMATS = {
|
|
3874
|
-
uk: "DD.MM.YYYY",
|
|
3875
|
-
de: "DD.MM.YYYY",
|
|
3876
|
-
en: "MM/DD/YYYY",
|
|
3877
|
-
es: "DD/MM/YYYY",
|
|
3878
|
-
fr: "DD/MM/YYYY",
|
|
3879
|
-
it: "DD/MM/YYYY"
|
|
3880
|
-
};
|
|
3881
|
-
var DEFAULT_TIME_FORMATS = {
|
|
3882
|
-
uk: "HH:mm:ss",
|
|
3883
|
-
de: "HH:mm:ss",
|
|
3884
|
-
en: "hh:mm:ss A",
|
|
3885
|
-
es: "HH:mm:ss",
|
|
3886
|
-
fr: "HH:mm:ss",
|
|
3887
|
-
it: "HH:mm:ss"
|
|
3888
|
-
};
|
|
3889
|
-
var LocalizationContext = createContext6(void 0);
|
|
3890
|
-
var LocalizationProvider = ({ children }) => {
|
|
722
|
+
// src/UI/components/data.display/UserAvatarComponent.tsx
|
|
723
|
+
import { useState as useState5, useEffect as useEffect2, lazy, Suspense } from "react";
|
|
724
|
+
import { Avatar, Tooltip as Tooltip3, Typography as Typography2 } from "@mui/material";
|
|
725
|
+
import { Fragment as Fragment4, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
726
|
+
var LazyUserPopover = lazy(() => import("./UserPopoverComponent-BNJWFSLT.mjs"));
|
|
727
|
+
var getInitials = (name) => {
|
|
728
|
+
if (!name) return "?";
|
|
729
|
+
const parts = name.trim().split(" ");
|
|
730
|
+
if (parts.length >= 2) {
|
|
731
|
+
return `${parts[0][0]}${parts[1][0]}`.toUpperCase();
|
|
732
|
+
}
|
|
733
|
+
return name[0].toUpperCase();
|
|
734
|
+
};
|
|
735
|
+
var UserAvatarComponent = ({
|
|
736
|
+
userId = "",
|
|
737
|
+
avatarUrl = "",
|
|
738
|
+
displayName = "",
|
|
739
|
+
employeePost = "",
|
|
740
|
+
size = 40,
|
|
741
|
+
disableBorder = false,
|
|
742
|
+
disableShadow = false,
|
|
743
|
+
disablePopover = false,
|
|
744
|
+
disableTooltip = false,
|
|
745
|
+
sx = {}
|
|
746
|
+
}) => {
|
|
3891
747
|
const supabase = useSupabase();
|
|
3892
|
-
const
|
|
3893
|
-
const [
|
|
3894
|
-
const [
|
|
3895
|
-
const
|
|
3896
|
-
|
|
748
|
+
const [anchorEl, setAnchorEl] = useState5(null);
|
|
749
|
+
const [hasInteracted, setHasInteracted] = useState5(false);
|
|
750
|
+
const [resolvedAvatarUrl, setResolvedAvatarUrl] = useState5(null);
|
|
751
|
+
const canShowPopover = !disablePopover && Boolean(userId);
|
|
752
|
+
useEffect2(() => {
|
|
3897
753
|
let isMounted = true;
|
|
3898
|
-
const
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
setLanguagesError(err.message || "Error loading languages");
|
|
3913
|
-
}
|
|
3914
|
-
} finally {
|
|
3915
|
-
if (isMounted) {
|
|
3916
|
-
setIsLoadingLangs(false);
|
|
754
|
+
const resolveAvatar = async () => {
|
|
755
|
+
if (!avatarUrl) {
|
|
756
|
+
if (isMounted) setResolvedAvatarUrl(null);
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
if (!avatarUrl.startsWith("http") && !avatarUrl.startsWith("data:")) {
|
|
760
|
+
try {
|
|
761
|
+
const { data } = await supabase.storage.from("user-media").createSignedUrl(avatarUrl, 3600);
|
|
762
|
+
if (isMounted) {
|
|
763
|
+
setResolvedAvatarUrl(data?.signedUrl || null);
|
|
764
|
+
}
|
|
765
|
+
} catch (err) {
|
|
766
|
+
console.error("Error resolving signed url for avatar:", err);
|
|
767
|
+
if (isMounted) setResolvedAvatarUrl(null);
|
|
3917
768
|
}
|
|
769
|
+
} else {
|
|
770
|
+
if (isMounted) setResolvedAvatarUrl(avatarUrl);
|
|
3918
771
|
}
|
|
3919
772
|
};
|
|
3920
|
-
|
|
773
|
+
resolveAvatar();
|
|
3921
774
|
return () => {
|
|
3922
775
|
isMounted = false;
|
|
3923
776
|
};
|
|
3924
|
-
}, [
|
|
3925
|
-
const
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
};
|
|
3933
|
-
const getDateTimeFormat = () => {
|
|
3934
|
-
return DEFAULT_DATETIME_FORMATS[currentLang] || "DD.MM.YYYY, HH:mm";
|
|
3935
|
-
};
|
|
3936
|
-
const formatDateTime = (date, customPattern) => {
|
|
3937
|
-
if (!date) return "\u2014";
|
|
3938
|
-
const pattern = customPattern || DEFAULT_DATETIME_FORMATS[currentLang] || "DD.MM.YYYY, HH:mm";
|
|
3939
|
-
return moment(date).locale(currentLang).format(pattern);
|
|
3940
|
-
};
|
|
3941
|
-
const formatDate = (date, customPattern) => {
|
|
3942
|
-
if (!date) return "\u2014";
|
|
3943
|
-
const pattern = customPattern || DEFAULT_DATE_FORMATS[currentLang] || "DD.MM.YYYY";
|
|
3944
|
-
return moment(date).locale(currentLang).format(pattern);
|
|
3945
|
-
};
|
|
3946
|
-
const formatTime = (date, customPattern) => {
|
|
3947
|
-
if (!date) return "\u2014";
|
|
3948
|
-
const pattern = customPattern || DEFAULT_TIME_FORMATS[currentLang] || "HH:mm:ss";
|
|
3949
|
-
return moment(date).locale(currentLang).format(pattern);
|
|
3950
|
-
};
|
|
3951
|
-
const formatRelativeTime = (date, withoutSuffix = false) => {
|
|
3952
|
-
if (!date) return "\u2014";
|
|
3953
|
-
return moment(date).locale(currentLang).fromNow(withoutSuffix);
|
|
3954
|
-
};
|
|
3955
|
-
const changeLanguage2 = async (lang) => {
|
|
3956
|
-
await i18n.changeLanguage(lang);
|
|
3957
|
-
};
|
|
3958
|
-
const value = useMemo4(
|
|
3959
|
-
() => ({
|
|
3960
|
-
currentLang,
|
|
3961
|
-
languages,
|
|
3962
|
-
isLoadingLangs,
|
|
3963
|
-
languagesError,
|
|
3964
|
-
changeLanguage: changeLanguage2,
|
|
3965
|
-
getDateFormat,
|
|
3966
|
-
getTimeFormat,
|
|
3967
|
-
getDateTimeFormat,
|
|
3968
|
-
formatDateTime,
|
|
3969
|
-
formatDate,
|
|
3970
|
-
formatTime,
|
|
3971
|
-
formatRelativeTime
|
|
3972
|
-
}),
|
|
3973
|
-
[currentLang, languages, isLoadingLangs, languagesError]
|
|
3974
|
-
);
|
|
3975
|
-
return /* @__PURE__ */ jsx13(LocalizationContext.Provider, { value, children });
|
|
3976
|
-
};
|
|
3977
|
-
var useLocalization = () => {
|
|
3978
|
-
const context = useContext6(LocalizationContext);
|
|
3979
|
-
if (!context) {
|
|
3980
|
-
throw new Error("useLocalization must be used within a LocalizationProvider");
|
|
3981
|
-
}
|
|
3982
|
-
return context;
|
|
3983
|
-
};
|
|
3984
|
-
|
|
3985
|
-
// src/context/ThemeProvider.tsx
|
|
3986
|
-
import { createContext as createContext7, useContext as useContext7, useMemo as useMemo5, useState as useState10, useEffect as useEffect7 } from "react";
|
|
3987
|
-
import { createTheme, ThemeProvider as MuiThemeProvider, CssBaseline, useMediaQuery } from "@mui/material";
|
|
3988
|
-
import { jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
3989
|
-
var DEFAULT_LIGHT_COLORS = {
|
|
3990
|
-
primary: "#1976d2",
|
|
3991
|
-
secondary: "#9c27b0",
|
|
3992
|
-
backgroundDefault: "#f5f5f5",
|
|
3993
|
-
backgroundPaper: "#ffffff",
|
|
3994
|
-
textPrimary: "#0f172a",
|
|
3995
|
-
textSecondary: "#475569",
|
|
3996
|
-
success: "#2e7d32",
|
|
3997
|
-
error: "#d32f2f",
|
|
3998
|
-
warning: "#ed6c02",
|
|
3999
|
-
info: "#0288d1"
|
|
4000
|
-
};
|
|
4001
|
-
var DEFAULT_DARK_COLORS = {
|
|
4002
|
-
primary: "#90caf9",
|
|
4003
|
-
secondary: "#ce93d8",
|
|
4004
|
-
backgroundDefault: "#0f172a",
|
|
4005
|
-
backgroundPaper: "#1e293b",
|
|
4006
|
-
textPrimary: "#f8fafc",
|
|
4007
|
-
textSecondary: "#94a3b8",
|
|
4008
|
-
success: "#66bb6a",
|
|
4009
|
-
error: "#f44336",
|
|
4010
|
-
warning: "#ffa726",
|
|
4011
|
-
info: "#29b6f6"
|
|
4012
|
-
};
|
|
4013
|
-
var INITIAL_THEME_CONFIG = {
|
|
4014
|
-
name: "Base MUI Theme",
|
|
4015
|
-
mode: "light",
|
|
4016
|
-
borderRadius: 12,
|
|
4017
|
-
colors: {
|
|
4018
|
-
light: DEFAULT_LIGHT_COLORS,
|
|
4019
|
-
dark: DEFAULT_DARK_COLORS
|
|
4020
|
-
},
|
|
4021
|
-
typography: {
|
|
4022
|
-
fontFamily: '"Inter", "Roboto", "Helvetica", "Arial", sans-serif',
|
|
4023
|
-
fontSize: 14,
|
|
4024
|
-
fontWeightLight: 300,
|
|
4025
|
-
fontWeightRegular: 400,
|
|
4026
|
-
fontWeightMedium: 600,
|
|
4027
|
-
fontWeightBold: 700
|
|
4028
|
-
}
|
|
4029
|
-
};
|
|
4030
|
-
var buildMuiTheme = (config) => {
|
|
4031
|
-
const currentMode = config.mode;
|
|
4032
|
-
const currentColors = config.colors?.[currentMode] || (currentMode === "light" ? DEFAULT_LIGHT_COLORS : DEFAULT_DARK_COLORS);
|
|
4033
|
-
return createTheme({
|
|
4034
|
-
palette: {
|
|
4035
|
-
mode: currentMode,
|
|
4036
|
-
primary: {
|
|
4037
|
-
main: currentColors.primary,
|
|
4038
|
-
light: currentMode === "light" ? "#63a4ff" : "#a1d2fa",
|
|
4039
|
-
dark: currentMode === "light" ? "#004ba0" : "#42a5f5"
|
|
4040
|
-
},
|
|
4041
|
-
secondary: {
|
|
4042
|
-
main: currentColors.secondary
|
|
4043
|
-
},
|
|
4044
|
-
background: {
|
|
4045
|
-
default: currentColors.backgroundDefault,
|
|
4046
|
-
paper: currentColors.backgroundPaper
|
|
4047
|
-
},
|
|
4048
|
-
text: {
|
|
4049
|
-
primary: currentColors.textPrimary,
|
|
4050
|
-
secondary: currentColors.textSecondary || (currentMode === "light" ? "#475569" : "#94a3b8")
|
|
4051
|
-
},
|
|
4052
|
-
success: { main: currentColors.success },
|
|
4053
|
-
error: { main: currentColors.error },
|
|
4054
|
-
warning: { main: currentColors.warning },
|
|
4055
|
-
info: { main: currentColors.info }
|
|
4056
|
-
},
|
|
4057
|
-
shape: {
|
|
4058
|
-
borderRadius: config.borderRadius
|
|
4059
|
-
},
|
|
4060
|
-
typography: {
|
|
4061
|
-
fontFamily: config.typography?.fontFamily || INITIAL_THEME_CONFIG.typography.fontFamily,
|
|
4062
|
-
fontSize: config.typography?.fontSize || INITIAL_THEME_CONFIG.typography.fontSize,
|
|
4063
|
-
fontWeightLight: config.typography?.fontWeightLight || INITIAL_THEME_CONFIG.typography.fontWeightLight,
|
|
4064
|
-
fontWeightRegular: config.typography?.fontWeightRegular || INITIAL_THEME_CONFIG.typography.fontWeightRegular,
|
|
4065
|
-
fontWeightMedium: config.typography?.fontWeightMedium || INITIAL_THEME_CONFIG.typography.fontWeightMedium,
|
|
4066
|
-
fontWeightBold: config.typography?.fontWeightBold || INITIAL_THEME_CONFIG.typography.fontWeightBold,
|
|
4067
|
-
h5: { fontWeight: 700, fontSize: "1.25rem" },
|
|
4068
|
-
subtitle1: { fontWeight: 600, fontSize: "0.95rem" },
|
|
4069
|
-
body2: { fontSize: "0.85rem" }
|
|
4070
|
-
},
|
|
4071
|
-
components: {
|
|
4072
|
-
MuiAutocomplete: {
|
|
4073
|
-
defaultProps: {
|
|
4074
|
-
noOptionsText: "\u041D\u0456\u0447\u043E\u0433\u043E \u043D\u0435 \u0437\u043D\u0430\u0439\u0434\u0435\u043D\u043E"
|
|
4075
|
-
}
|
|
4076
|
-
},
|
|
4077
|
-
MuiListItem: {
|
|
4078
|
-
styleOverrides: {
|
|
4079
|
-
root: {
|
|
4080
|
-
transition: "all 0.2s ease-in-out",
|
|
4081
|
-
"&:hover": {
|
|
4082
|
-
backgroundColor: currentMode === "light" ? "#f1f5f9" : "#334155"
|
|
4083
|
-
}
|
|
4084
|
-
}
|
|
4085
|
-
}
|
|
4086
|
-
},
|
|
4087
|
-
MuiListItemButton: {
|
|
4088
|
-
styleOverrides: {
|
|
4089
|
-
root: {
|
|
4090
|
-
transition: "all 0.2s ease-in-out",
|
|
4091
|
-
"&:hover": {
|
|
4092
|
-
backgroundColor: currentMode === "light" ? "#f1f5f9" : "#334155"
|
|
4093
|
-
}
|
|
4094
|
-
}
|
|
4095
|
-
}
|
|
4096
|
-
},
|
|
4097
|
-
MuiButton: {
|
|
4098
|
-
styleOverrides: {
|
|
4099
|
-
root: {
|
|
4100
|
-
textTransform: "none",
|
|
4101
|
-
fontWeight: 600,
|
|
4102
|
-
borderRadius: `${config.borderRadius}px`,
|
|
4103
|
-
padding: "10px 24px",
|
|
4104
|
-
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)"
|
|
4105
|
-
}
|
|
4106
|
-
}
|
|
4107
|
-
},
|
|
4108
|
-
MuiPaper: {
|
|
4109
|
-
styleOverrides: {
|
|
4110
|
-
rounded: {
|
|
4111
|
-
borderRadius: `${config.borderRadius * 1.25}px`
|
|
4112
|
-
}
|
|
4113
|
-
}
|
|
4114
|
-
}
|
|
4115
|
-
}
|
|
4116
|
-
});
|
|
4117
|
-
};
|
|
4118
|
-
var ThemeContext = createContext7(void 0);
|
|
4119
|
-
var THEME_STORAGE_KEY = "docsua_custom_theme_config";
|
|
4120
|
-
var THEME_MODE_STORAGE_KEY = "docsua_custom_theme_mode";
|
|
4121
|
-
var ThemeProvider = ({ children }) => {
|
|
4122
|
-
const supabase = useSupabase();
|
|
4123
|
-
const { user, isAuthenticated, loading: isAuthLoading } = useAuth();
|
|
4124
|
-
const userId = user?.id;
|
|
4125
|
-
const [themeConfig, setThemeConfig] = useState10(() => {
|
|
4126
|
-
const saved = localStorage.getItem(THEME_STORAGE_KEY);
|
|
4127
|
-
if (saved) {
|
|
4128
|
-
try {
|
|
4129
|
-
return JSON.parse(saved);
|
|
4130
|
-
} catch (e) {
|
|
777
|
+
}, [avatarUrl]);
|
|
778
|
+
const handleClick = (event) => {
|
|
779
|
+
event.stopPropagation();
|
|
780
|
+
event.preventDefault();
|
|
781
|
+
if (canShowPopover) {
|
|
782
|
+
setAnchorEl(event.currentTarget);
|
|
783
|
+
if (!hasInteracted) {
|
|
784
|
+
setHasInteracted(true);
|
|
4131
785
|
}
|
|
4132
786
|
}
|
|
4133
|
-
return INITIAL_THEME_CONFIG;
|
|
4134
|
-
});
|
|
4135
|
-
useEffect7(() => {
|
|
4136
|
-
if (isAuthLoading) return;
|
|
4137
|
-
if (isAuthenticated && userId) {
|
|
4138
|
-
const fetchActiveTheme = async () => {
|
|
4139
|
-
try {
|
|
4140
|
-
const { data, error } = await supabase.from("user_themes").select("*").eq("user_id", userId).eq("is_active", true).maybeSingle();
|
|
4141
|
-
if (error) {
|
|
4142
|
-
console.error("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0435 \u0442\u0435\u043C\u044B \u0438\u0437 Supabase:", error.message);
|
|
4143
|
-
return;
|
|
4144
|
-
}
|
|
4145
|
-
if (data) {
|
|
4146
|
-
const activeTheme = data;
|
|
4147
|
-
const savedMode = localStorage.getItem(THEME_MODE_STORAGE_KEY);
|
|
4148
|
-
setThemeConfig({
|
|
4149
|
-
id: activeTheme.id,
|
|
4150
|
-
name: activeTheme.name || INITIAL_THEME_CONFIG.name,
|
|
4151
|
-
mode: savedMode || activeTheme.config?.mode || "light",
|
|
4152
|
-
borderRadius: activeTheme.config?.borderRadius ?? INITIAL_THEME_CONFIG.borderRadius,
|
|
4153
|
-
colors: activeTheme.config?.colors || INITIAL_THEME_CONFIG.colors,
|
|
4154
|
-
typography: activeTheme.config?.typography || INITIAL_THEME_CONFIG.typography,
|
|
4155
|
-
updatedAt: activeTheme.updated_at || void 0
|
|
4156
|
-
});
|
|
4157
|
-
}
|
|
4158
|
-
} catch (err) {
|
|
4159
|
-
console.error("\u041D\u0435\u043F\u0440\u0435\u0434\u0432\u0438\u0434\u0435\u043D\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0437\u0430\u043F\u0440\u043E\u0441\u0435 \u0442\u0435\u043C\u044B:", err);
|
|
4160
|
-
}
|
|
4161
|
-
};
|
|
4162
|
-
fetchActiveTheme();
|
|
4163
|
-
} else {
|
|
4164
|
-
setThemeConfig(INITIAL_THEME_CONFIG);
|
|
4165
|
-
localStorage.removeItem(THEME_STORAGE_KEY);
|
|
4166
|
-
localStorage.removeItem(THEME_MODE_STORAGE_KEY);
|
|
4167
|
-
}
|
|
4168
|
-
}, [isAuthenticated, isAuthLoading, userId]);
|
|
4169
|
-
useEffect7(() => {
|
|
4170
|
-
if (isAuthenticated) {
|
|
4171
|
-
localStorage.setItem(THEME_STORAGE_KEY, JSON.stringify(themeConfig));
|
|
4172
|
-
localStorage.setItem(THEME_MODE_STORAGE_KEY, themeConfig.mode);
|
|
4173
|
-
}
|
|
4174
|
-
}, [themeConfig, isAuthenticated]);
|
|
4175
|
-
const mode = themeConfig.mode;
|
|
4176
|
-
const setMode = (newMode) => {
|
|
4177
|
-
setThemeConfig((prev) => ({ ...prev, mode: newMode }));
|
|
4178
|
-
};
|
|
4179
|
-
const toggleTheme = () => {
|
|
4180
|
-
setMode(mode === "light" ? "dark" : "light");
|
|
4181
|
-
};
|
|
4182
|
-
const theme = useMemo5(() => buildMuiTheme(themeConfig), [themeConfig]);
|
|
4183
|
-
const displayState = {
|
|
4184
|
-
isMobile: useMediaQuery(theme.breakpoints.down("sm")),
|
|
4185
|
-
isTablet: useMediaQuery(theme.breakpoints.between("sm", "md")),
|
|
4186
|
-
isDesktop: useMediaQuery(theme.breakpoints.between("md", "lg")),
|
|
4187
|
-
isWideDesktop: useMediaQuery(theme.breakpoints.between("lg", "xl")),
|
|
4188
|
-
isSuperWideDesktop: useMediaQuery(theme.breakpoints.up("xl"))
|
|
4189
787
|
};
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
}
|
|
4195
|
-
|
|
4196
|
-
const context = useContext7(ThemeContext);
|
|
4197
|
-
if (!context) {
|
|
4198
|
-
throw new Error("useAppTheme should be used within the ThemeProvider");
|
|
4199
|
-
}
|
|
4200
|
-
return context;
|
|
4201
|
-
};
|
|
4202
|
-
|
|
4203
|
-
// src/context/BreadcrumbProvider.tsx
|
|
4204
|
-
import { createContext as createContext8, useContext as useContext8, useState as useState11 } from "react";
|
|
4205
|
-
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
4206
|
-
var BreadcrumbContext = createContext8({
|
|
4207
|
-
breadcrumbTitles: {},
|
|
4208
|
-
setBreadcrumbTitle: () => {
|
|
4209
|
-
}
|
|
4210
|
-
});
|
|
4211
|
-
var BreadcrumbProvider = ({ children }) => {
|
|
4212
|
-
const [breadcrumbTitles, setBreadcrumbTitles] = useState11({});
|
|
4213
|
-
const setBreadcrumbTitle = (path, title) => {
|
|
4214
|
-
setBreadcrumbTitles((prev) => {
|
|
4215
|
-
if (prev[path] === title) return prev;
|
|
4216
|
-
return { ...prev, [path]: title };
|
|
4217
|
-
});
|
|
788
|
+
const handleClose = (event) => {
|
|
789
|
+
if (event) {
|
|
790
|
+
event.stopPropagation();
|
|
791
|
+
event.preventDefault();
|
|
792
|
+
}
|
|
793
|
+
setAnchorEl(null);
|
|
4218
794
|
};
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
var ToastProvider = ({ children }) => {
|
|
4229
|
-
const [toast, setToast] = useState12(null);
|
|
4230
|
-
const showToast = useCallback4((text, type = "info") => {
|
|
4231
|
-
setToast({ text, type });
|
|
4232
|
-
}, []);
|
|
4233
|
-
const hideToast = useCallback4(() => {
|
|
4234
|
-
setToast(null);
|
|
4235
|
-
}, []);
|
|
4236
|
-
const contextValue = useMemo6(() => ({
|
|
4237
|
-
showToast,
|
|
4238
|
-
hideToast
|
|
4239
|
-
}), [showToast, hideToast]);
|
|
4240
|
-
return /* @__PURE__ */ jsxs7(ToastContext.Provider, { value: contextValue, children: [
|
|
4241
|
-
children,
|
|
4242
|
-
/* @__PURE__ */ jsx16(
|
|
4243
|
-
Snackbar,
|
|
795
|
+
const isPopoverOpen = Boolean(anchorEl);
|
|
796
|
+
const initials = getInitials(displayName || "");
|
|
797
|
+
const getTooltip = /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
798
|
+
/* @__PURE__ */ jsx5(Typography2, { component: "div", variant: "caption", children: displayName }),
|
|
799
|
+
displayName && employeePost && /* @__PURE__ */ jsx5(Typography2, { component: "div", variant: "caption", children: employeePost })
|
|
800
|
+
] });
|
|
801
|
+
return /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
802
|
+
/* @__PURE__ */ jsx5(Tooltip3, { title: disableTooltip || isPopoverOpen ? "" : getTooltip, children: /* @__PURE__ */ jsx5(
|
|
803
|
+
Avatar,
|
|
4244
804
|
{
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
805
|
+
src: resolvedAvatarUrl || void 0,
|
|
806
|
+
alt: displayName || "User Avatar",
|
|
807
|
+
onClick: handleClick,
|
|
808
|
+
sx: {
|
|
809
|
+
width: size,
|
|
810
|
+
height: size,
|
|
811
|
+
fontSize: size * 0.4,
|
|
812
|
+
fontWeight: 600,
|
|
813
|
+
bgcolor: "primary.main",
|
|
814
|
+
color: "primary.contrastText",
|
|
815
|
+
cursor: canShowPopover ? "pointer" : void 0,
|
|
816
|
+
transition: "transform 0.2s ease, box-shadow 0.2s ease",
|
|
817
|
+
border: disableBorder ? "none" : "2px solid",
|
|
818
|
+
borderColor: "background.paper",
|
|
819
|
+
boxShadow: disableShadow ? "none" : 2,
|
|
820
|
+
"&:hover": {
|
|
821
|
+
transform: canShowPopover ? "scale(1.05)" : "none"
|
|
822
|
+
},
|
|
823
|
+
...sx
|
|
824
|
+
},
|
|
825
|
+
children: !resolvedAvatarUrl && initials
|
|
4258
826
|
}
|
|
4259
|
-
)
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
var useToast = () => {
|
|
4263
|
-
const context = useContext9(ToastContext);
|
|
4264
|
-
if (!context) {
|
|
4265
|
-
throw new Error("useToast must be used within a ToastProvider");
|
|
4266
|
-
}
|
|
4267
|
-
return context;
|
|
4268
|
-
};
|
|
4269
|
-
|
|
4270
|
-
// src/context/ConfirmationProvider.tsx
|
|
4271
|
-
import { createContext as createContext10, useContext as useContext10, useState as useState13, useCallback as useCallback5 } from "react";
|
|
4272
|
-
import {
|
|
4273
|
-
Button as Button3,
|
|
4274
|
-
Dialog as Dialog2,
|
|
4275
|
-
DialogActions as DialogActions2,
|
|
4276
|
-
DialogContent as DialogContent2,
|
|
4277
|
-
DialogContentText,
|
|
4278
|
-
DialogTitle as DialogTitle2,
|
|
4279
|
-
Box as Box6
|
|
4280
|
-
} from "@mui/material";
|
|
4281
|
-
import {
|
|
4282
|
-
Error as ErrorIcon,
|
|
4283
|
-
WarningAmberOutlined as WarningIcon,
|
|
4284
|
-
InfoOutlined as InfoIcon,
|
|
4285
|
-
CheckCircleOutlined as SuccessIcon
|
|
4286
|
-
} from "@mui/icons-material";
|
|
4287
|
-
import { jsx as jsx17, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
4288
|
-
var ConfirmContext = createContext10(null);
|
|
4289
|
-
var SEVERITY_ICONS = {
|
|
4290
|
-
error: /* @__PURE__ */ jsx17(ErrorIcon, { color: "error", sx: { fontSize: 40 } }),
|
|
4291
|
-
warning: /* @__PURE__ */ jsx17(WarningIcon, { color: "warning", sx: { fontSize: 40 } }),
|
|
4292
|
-
info: /* @__PURE__ */ jsx17(InfoIcon, { color: "info", sx: { fontSize: 40 } }),
|
|
4293
|
-
success: /* @__PURE__ */ jsx17(SuccessIcon, { color: "success", sx: { fontSize: 40 } })
|
|
4294
|
-
};
|
|
4295
|
-
var ConfirmationProvider = ({ children }) => {
|
|
4296
|
-
const [open, setOpen] = useState13(false);
|
|
4297
|
-
const [options, setOptions] = useState13(null);
|
|
4298
|
-
const [resolver, setResolver] = useState13(null);
|
|
4299
|
-
const confirm = useCallback5((opts) => {
|
|
4300
|
-
setOptions(opts);
|
|
4301
|
-
setOpen(true);
|
|
4302
|
-
return new Promise((resolve) => {
|
|
4303
|
-
setResolver(() => resolve);
|
|
4304
|
-
});
|
|
4305
|
-
}, []);
|
|
4306
|
-
const handleClose = (result) => {
|
|
4307
|
-
setOpen(false);
|
|
4308
|
-
if (resolver) {
|
|
4309
|
-
resolver(result);
|
|
4310
|
-
}
|
|
4311
|
-
};
|
|
4312
|
-
const severityType = options?.type || "info";
|
|
4313
|
-
return /* @__PURE__ */ jsxs8(ConfirmContext.Provider, { value: { confirm }, children: [
|
|
4314
|
-
children,
|
|
4315
|
-
/* @__PURE__ */ jsxs8(
|
|
4316
|
-
Dialog2,
|
|
827
|
+
) }),
|
|
828
|
+
canShowPopover && hasInteracted && /* @__PURE__ */ jsx5(Suspense, { fallback: null, children: /* @__PURE__ */ jsx5(
|
|
829
|
+
LazyUserPopover,
|
|
4317
830
|
{
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
disableEnforceFocus: true,
|
|
4323
|
-
disableRestoreFocus: true,
|
|
4324
|
-
children: [
|
|
4325
|
-
/* @__PURE__ */ jsxs8(DialogTitle2, { sx: { display: "flex", alignItems: "center", gap: 1.5, pb: 1 }, children: [
|
|
4326
|
-
SEVERITY_ICONS[severityType],
|
|
4327
|
-
/* @__PURE__ */ jsx17(Box6, { component: "span", sx: { fontWeight: 600 }, children: options?.title || /* @__PURE__ */ jsx17(TranslateText, { children: "Confirmation" }) })
|
|
4328
|
-
] }),
|
|
4329
|
-
/* @__PURE__ */ jsx17(DialogContent2, { sx: { py: 2 }, dividers: true, children: /* @__PURE__ */ jsx17(DialogContentText, { color: "text.secondary", children: options?.message }) }),
|
|
4330
|
-
/* @__PURE__ */ jsxs8(DialogActions2, { sx: { pt: 2, px: 2, justifyContent: "flex-end", gap: 1 }, children: [
|
|
4331
|
-
(options?.showCancelButton ?? true) && /* @__PURE__ */ jsx17(
|
|
4332
|
-
Button3,
|
|
4333
|
-
{
|
|
4334
|
-
onClick: () => handleClose("cancel"),
|
|
4335
|
-
color: "inherit",
|
|
4336
|
-
variant: "text",
|
|
4337
|
-
children: options?.cancelText || /* @__PURE__ */ jsx17(TranslateText, { children: "Cancel" })
|
|
4338
|
-
}
|
|
4339
|
-
),
|
|
4340
|
-
options?.showNoButton && /* @__PURE__ */ jsx17(
|
|
4341
|
-
Button3,
|
|
4342
|
-
{
|
|
4343
|
-
onClick: () => handleClose("no"),
|
|
4344
|
-
color: "inherit",
|
|
4345
|
-
variant: "outlined",
|
|
4346
|
-
children: options?.noText || /* @__PURE__ */ jsx17(TranslateText, { children: "No" })
|
|
4347
|
-
}
|
|
4348
|
-
),
|
|
4349
|
-
/* @__PURE__ */ jsx17(
|
|
4350
|
-
Button3,
|
|
4351
|
-
{
|
|
4352
|
-
onClick: () => handleClose("yes"),
|
|
4353
|
-
color: options?.confirmColor || (severityType === "error" ? "error" : "primary"),
|
|
4354
|
-
variant: "contained",
|
|
4355
|
-
autoFocus: true,
|
|
4356
|
-
children: options?.confirmText || /* @__PURE__ */ jsx17(TranslateText, { children: "Yes" })
|
|
4357
|
-
}
|
|
4358
|
-
)
|
|
4359
|
-
] })
|
|
4360
|
-
]
|
|
831
|
+
userId,
|
|
832
|
+
anchorEl,
|
|
833
|
+
open: isPopoverOpen,
|
|
834
|
+
onClose: handleClose
|
|
4361
835
|
}
|
|
4362
|
-
)
|
|
836
|
+
) })
|
|
4363
837
|
] });
|
|
4364
838
|
};
|
|
4365
|
-
var useConfirmation = () => {
|
|
4366
|
-
const context = useContext10(ConfirmContext);
|
|
4367
|
-
if (!context) {
|
|
4368
|
-
throw new Error("useConfirm must be used within a ConfirmProvider");
|
|
4369
|
-
}
|
|
4370
|
-
return context.confirm;
|
|
4371
|
-
};
|
|
4372
839
|
|
|
4373
|
-
// src/
|
|
4374
|
-
var
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
840
|
+
// src/UI/index.ts
|
|
841
|
+
var UI = {
|
|
842
|
+
Inputs: {
|
|
843
|
+
TextField: TextFieldComponent,
|
|
844
|
+
NumberField: NumberInputComponent,
|
|
845
|
+
EmailField: EmailInputComponent,
|
|
846
|
+
Url: UrlComponent
|
|
847
|
+
},
|
|
848
|
+
Buttons: {
|
|
849
|
+
CopyClipboardButton: CopyClipboardButtonComponent
|
|
850
|
+
},
|
|
851
|
+
DataDisplay: {
|
|
852
|
+
TranslatableTooltip: TranslatableTooltipComponent,
|
|
853
|
+
UserAvatar: UserAvatarComponent,
|
|
854
|
+
UserRoleChip: UserRoleChipComponent,
|
|
855
|
+
UserStatusChip: UserStatusChipComponent
|
|
856
|
+
}
|
|
857
|
+
/*Layout: {
|
|
858
|
+
Row: FormRow,
|
|
859
|
+
},*/
|
|
4384
860
|
};
|
|
4385
861
|
export {
|
|
4386
862
|
AIProvider,
|