@bigbinary/neeto-webhooks-frontend 1.5.9 → 1.6.1
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/app/javascript/src/translations/en.json +81 -0
- package/app/javascript/src/translations/index.js +1 -0
- package/dist/index.cjs.js +563 -3231
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +557 -3227
- package/dist/index.js.map +1 -1
- package/package.json +11 -5
package/dist/index.cjs.js
CHANGED
|
@@ -4,18 +4,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var reactRouterDom = require('react-router-dom');
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var utils = require('@bigbinary/neeto-commons-frontend/utils');
|
|
10
|
-
var neetoIcons = require('@bigbinary/neeto-icons');
|
|
7
|
+
var neetoCist = require('@bigbinary/neeto-cist');
|
|
8
|
+
var Container = require('@bigbinary/neeto-molecules/Container');
|
|
11
9
|
var Header$2 = require('@bigbinary/neeto-molecules/Header');
|
|
12
10
|
var PageLoader = require('@bigbinary/neeto-molecules/PageLoader');
|
|
11
|
+
var TableWrapper = require('@bigbinary/neeto-molecules/TableWrapper');
|
|
13
12
|
var neetoui = require('@bigbinary/neetoui');
|
|
14
|
-
var
|
|
13
|
+
var reactI18next = require('react-i18next');
|
|
15
14
|
var reactQuery = require('react-query');
|
|
16
15
|
var devtools = require('react-query/devtools');
|
|
16
|
+
var constants = require('@bigbinary/neeto-commons-frontend/constants');
|
|
17
17
|
var axios = require('axios');
|
|
18
|
+
var DateFormat = require('@bigbinary/neeto-molecules/DateFormat');
|
|
19
|
+
var i18next = require('i18next');
|
|
20
|
+
var ramda = require('ramda');
|
|
21
|
+
var neetoIcons = require('@bigbinary/neeto-icons');
|
|
18
22
|
var formik = require('@bigbinary/neetoui/formik');
|
|
23
|
+
var utils = require('@bigbinary/neeto-commons-frontend/utils');
|
|
19
24
|
var yup = require('yup');
|
|
20
25
|
|
|
21
26
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -39,2955 +44,166 @@ function _interopNamespace(e) {
|
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
42
|
-
var
|
|
47
|
+
var Container__default = /*#__PURE__*/_interopDefaultLegacy(Container);
|
|
43
48
|
var Header__default = /*#__PURE__*/_interopDefaultLegacy(Header$2);
|
|
44
49
|
var PageLoader__default = /*#__PURE__*/_interopDefaultLegacy(PageLoader);
|
|
50
|
+
var TableWrapper__default = /*#__PURE__*/_interopDefaultLegacy(TableWrapper);
|
|
45
51
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
52
|
+
var DateFormat__default = /*#__PURE__*/_interopDefaultLegacy(DateFormat);
|
|
46
53
|
var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
log(args) {
|
|
51
|
-
this.output('log', args);
|
|
52
|
-
},
|
|
53
|
-
warn(args) {
|
|
54
|
-
this.output('warn', args);
|
|
55
|
-
},
|
|
56
|
-
error(args) {
|
|
57
|
-
this.output('error', args);
|
|
58
|
-
},
|
|
59
|
-
output(type, args) {
|
|
60
|
-
if (console && console[type]) console[type].apply(console, args);
|
|
61
|
-
}
|
|
55
|
+
var getDeliveriesPath = function getDeliveriesPath(webhooksPath) {
|
|
56
|
+
return "".concat(webhooksPath, "/:webhookId/deliveries");
|
|
62
57
|
};
|
|
63
|
-
class Logger {
|
|
64
|
-
constructor(concreteLogger) {
|
|
65
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
66
|
-
this.init(concreteLogger, options);
|
|
67
|
-
}
|
|
68
|
-
init(concreteLogger) {
|
|
69
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
70
|
-
this.prefix = options.prefix || 'i18next:';
|
|
71
|
-
this.logger = concreteLogger || consoleLogger;
|
|
72
|
-
this.options = options;
|
|
73
|
-
this.debug = options.debug;
|
|
74
|
-
}
|
|
75
|
-
log() {
|
|
76
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
77
|
-
args[_key] = arguments[_key];
|
|
78
|
-
}
|
|
79
|
-
return this.forward(args, 'log', '', true);
|
|
80
|
-
}
|
|
81
|
-
warn() {
|
|
82
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
83
|
-
args[_key2] = arguments[_key2];
|
|
84
|
-
}
|
|
85
|
-
return this.forward(args, 'warn', '', true);
|
|
86
|
-
}
|
|
87
|
-
error() {
|
|
88
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
89
|
-
args[_key3] = arguments[_key3];
|
|
90
|
-
}
|
|
91
|
-
return this.forward(args, 'error', '');
|
|
92
|
-
}
|
|
93
|
-
deprecate() {
|
|
94
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
95
|
-
args[_key4] = arguments[_key4];
|
|
96
|
-
}
|
|
97
|
-
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
98
|
-
}
|
|
99
|
-
forward(args, lvl, prefix, debugOnly) {
|
|
100
|
-
if (debugOnly && !this.debug) return null;
|
|
101
|
-
if (typeof args[0] === 'string') args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
102
|
-
return this.logger[lvl](args);
|
|
103
|
-
}
|
|
104
|
-
create(moduleName) {
|
|
105
|
-
return new Logger(this.logger, {
|
|
106
|
-
...{
|
|
107
|
-
prefix: `${this.prefix}:${moduleName}:`
|
|
108
|
-
},
|
|
109
|
-
...this.options
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
clone(options) {
|
|
113
|
-
options = options || this.options;
|
|
114
|
-
options.prefix = options.prefix || this.prefix;
|
|
115
|
-
return new Logger(this.logger, options);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
var baseLogger = new Logger();
|
|
119
58
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
on(events, listener) {
|
|
125
|
-
events.split(' ').forEach(event => {
|
|
126
|
-
this.observers[event] = this.observers[event] || [];
|
|
127
|
-
this.observers[event].push(listener);
|
|
128
|
-
});
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
off(event, listener) {
|
|
132
|
-
if (!this.observers[event]) return;
|
|
133
|
-
if (!listener) {
|
|
134
|
-
delete this.observers[event];
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
this.observers[event] = this.observers[event].filter(l => l !== listener);
|
|
138
|
-
}
|
|
139
|
-
emit(event) {
|
|
140
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
141
|
-
args[_key - 1] = arguments[_key];
|
|
142
|
-
}
|
|
143
|
-
if (this.observers[event]) {
|
|
144
|
-
const cloned = [].concat(this.observers[event]);
|
|
145
|
-
cloned.forEach(observer => {
|
|
146
|
-
observer(...args);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
if (this.observers['*']) {
|
|
150
|
-
const cloned = [].concat(this.observers['*']);
|
|
151
|
-
cloned.forEach(observer => {
|
|
152
|
-
observer.apply(observer, [event, ...args]);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
59
|
+
function _arrayLikeToArray(arr, len) {
|
|
60
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
61
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
62
|
+
return arr2;
|
|
156
63
|
}
|
|
157
64
|
|
|
158
|
-
function
|
|
159
|
-
|
|
160
|
-
let rej;
|
|
161
|
-
const promise = new Promise((resolve, reject) => {
|
|
162
|
-
res = resolve;
|
|
163
|
-
rej = reject;
|
|
164
|
-
});
|
|
165
|
-
promise.resolve = res;
|
|
166
|
-
promise.reject = rej;
|
|
167
|
-
return promise;
|
|
168
|
-
}
|
|
169
|
-
function makeString(object) {
|
|
170
|
-
if (object == null) return '';
|
|
171
|
-
return '' + object;
|
|
172
|
-
}
|
|
173
|
-
function copy(a, s, t) {
|
|
174
|
-
a.forEach(m => {
|
|
175
|
-
if (s[m]) t[m] = s[m];
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
function getLastOfPath(object, path, Empty) {
|
|
179
|
-
function cleanKey(key) {
|
|
180
|
-
return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
|
|
181
|
-
}
|
|
182
|
-
function canNotTraverseDeeper() {
|
|
183
|
-
return !object || typeof object === 'string';
|
|
184
|
-
}
|
|
185
|
-
const stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
|
|
186
|
-
while (stack.length > 1) {
|
|
187
|
-
if (canNotTraverseDeeper()) return {};
|
|
188
|
-
const key = cleanKey(stack.shift());
|
|
189
|
-
if (!object[key] && Empty) object[key] = new Empty();
|
|
190
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
191
|
-
object = object[key];
|
|
192
|
-
} else {
|
|
193
|
-
object = {};
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (canNotTraverseDeeper()) return {};
|
|
197
|
-
return {
|
|
198
|
-
obj: object,
|
|
199
|
-
k: cleanKey(stack.shift())
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function setPath(object, path, newValue) {
|
|
203
|
-
const {
|
|
204
|
-
obj,
|
|
205
|
-
k
|
|
206
|
-
} = getLastOfPath(object, path, Object);
|
|
207
|
-
obj[k] = newValue;
|
|
208
|
-
}
|
|
209
|
-
function pushPath(object, path, newValue, concat) {
|
|
210
|
-
const {
|
|
211
|
-
obj,
|
|
212
|
-
k
|
|
213
|
-
} = getLastOfPath(object, path, Object);
|
|
214
|
-
obj[k] = obj[k] || [];
|
|
215
|
-
if (concat) obj[k] = obj[k].concat(newValue);
|
|
216
|
-
if (!concat) obj[k].push(newValue);
|
|
217
|
-
}
|
|
218
|
-
function getPath(object, path) {
|
|
219
|
-
const {
|
|
220
|
-
obj,
|
|
221
|
-
k
|
|
222
|
-
} = getLastOfPath(object, path);
|
|
223
|
-
if (!obj) return undefined;
|
|
224
|
-
return obj[k];
|
|
65
|
+
function _arrayWithoutHoles(arr) {
|
|
66
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
225
67
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
return value;
|
|
230
|
-
}
|
|
231
|
-
return getPath(defaultData, key);
|
|
68
|
+
|
|
69
|
+
function _iterableToArray(iter) {
|
|
70
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
232
71
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
} else {
|
|
243
|
-
target[prop] = source[prop];
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return target;
|
|
72
|
+
|
|
73
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
74
|
+
if (!o) return;
|
|
75
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
76
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
77
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
78
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
79
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
248
80
|
}
|
|
249
|
-
|
|
250
|
-
|
|
81
|
+
|
|
82
|
+
function _nonIterableSpread() {
|
|
83
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
251
84
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
'>': '>',
|
|
256
|
-
'"': '"',
|
|
257
|
-
"'": ''',
|
|
258
|
-
'/': '/'
|
|
259
|
-
};
|
|
260
|
-
function escape(data) {
|
|
261
|
-
if (typeof data === 'string') {
|
|
262
|
-
return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
|
|
263
|
-
}
|
|
264
|
-
return data;
|
|
85
|
+
|
|
86
|
+
function _toConsumableArray(arr) {
|
|
87
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
265
88
|
}
|
|
266
|
-
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
keySeparator = keySeparator || '';
|
|
270
|
-
const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
271
|
-
if (possibleChars.length === 0) return true;
|
|
272
|
-
const r = new RegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
|
|
273
|
-
let matched = !r.test(key);
|
|
274
|
-
if (!matched) {
|
|
275
|
-
const ki = key.indexOf(keySeparator);
|
|
276
|
-
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
277
|
-
matched = true;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return matched;
|
|
89
|
+
|
|
90
|
+
function _arrayWithHoles(arr) {
|
|
91
|
+
if (Array.isArray(arr)) return arr;
|
|
281
92
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (typeof mix === 'string') return mix;
|
|
306
|
-
if (p && typeof mix[p] === 'string') return mix[p];
|
|
93
|
+
|
|
94
|
+
function _iterableToArrayLimit(arr, i) {
|
|
95
|
+
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
96
|
+
if (null != _i) {
|
|
97
|
+
var _s,
|
|
98
|
+
_e,
|
|
99
|
+
_x,
|
|
100
|
+
_r,
|
|
101
|
+
_arr = [],
|
|
102
|
+
_n = !0,
|
|
103
|
+
_d = !1;
|
|
104
|
+
try {
|
|
105
|
+
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
106
|
+
if (Object(_i) !== _i) return;
|
|
107
|
+
_n = !1;
|
|
108
|
+
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
_d = !0, _e = err;
|
|
111
|
+
} finally {
|
|
112
|
+
try {
|
|
113
|
+
if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
|
|
114
|
+
} finally {
|
|
115
|
+
if (_d) throw _e;
|
|
307
116
|
}
|
|
308
|
-
const joinedPath = paths.slice(i + j).join(keySeparator);
|
|
309
|
-
if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
|
|
310
|
-
return undefined;
|
|
311
117
|
}
|
|
312
|
-
|
|
118
|
+
return _arr;
|
|
313
119
|
}
|
|
314
|
-
return current;
|
|
315
|
-
}
|
|
316
|
-
function getCleanedCode(code) {
|
|
317
|
-
if (code && code.indexOf('_') > 0) return code.replace('_', '-');
|
|
318
|
-
return code;
|
|
319
120
|
}
|
|
320
121
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
324
|
-
ns: ['translation'],
|
|
325
|
-
defaultNS: 'translation'
|
|
326
|
-
};
|
|
327
|
-
super();
|
|
328
|
-
this.data = data || {};
|
|
329
|
-
this.options = options;
|
|
330
|
-
if (this.options.keySeparator === undefined) {
|
|
331
|
-
this.options.keySeparator = '.';
|
|
332
|
-
}
|
|
333
|
-
if (this.options.ignoreJSONStructure === undefined) {
|
|
334
|
-
this.options.ignoreJSONStructure = true;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
addNamespaces(ns) {
|
|
338
|
-
if (this.options.ns.indexOf(ns) < 0) {
|
|
339
|
-
this.options.ns.push(ns);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
removeNamespaces(ns) {
|
|
343
|
-
const index = this.options.ns.indexOf(ns);
|
|
344
|
-
if (index > -1) {
|
|
345
|
-
this.options.ns.splice(index, 1);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
getResource(lng, ns, key) {
|
|
349
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
350
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
351
|
-
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
352
|
-
let path = [lng, ns];
|
|
353
|
-
if (key && typeof key !== 'string') path = path.concat(key);
|
|
354
|
-
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
355
|
-
if (lng.indexOf('.') > -1) {
|
|
356
|
-
path = lng.split('.');
|
|
357
|
-
}
|
|
358
|
-
const result = getPath(this.data, path);
|
|
359
|
-
if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
|
|
360
|
-
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
361
|
-
}
|
|
362
|
-
addResource(lng, ns, key, value) {
|
|
363
|
-
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
364
|
-
silent: false
|
|
365
|
-
};
|
|
366
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
367
|
-
let path = [lng, ns];
|
|
368
|
-
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
369
|
-
if (lng.indexOf('.') > -1) {
|
|
370
|
-
path = lng.split('.');
|
|
371
|
-
value = ns;
|
|
372
|
-
ns = path[1];
|
|
373
|
-
}
|
|
374
|
-
this.addNamespaces(ns);
|
|
375
|
-
setPath(this.data, path, value);
|
|
376
|
-
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
377
|
-
}
|
|
378
|
-
addResources(lng, ns, resources) {
|
|
379
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
380
|
-
silent: false
|
|
381
|
-
};
|
|
382
|
-
for (const m in resources) {
|
|
383
|
-
if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
|
|
384
|
-
silent: true
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
388
|
-
}
|
|
389
|
-
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
390
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
391
|
-
silent: false
|
|
392
|
-
};
|
|
393
|
-
let path = [lng, ns];
|
|
394
|
-
if (lng.indexOf('.') > -1) {
|
|
395
|
-
path = lng.split('.');
|
|
396
|
-
deep = resources;
|
|
397
|
-
resources = ns;
|
|
398
|
-
ns = path[1];
|
|
399
|
-
}
|
|
400
|
-
this.addNamespaces(ns);
|
|
401
|
-
let pack = getPath(this.data, path) || {};
|
|
402
|
-
if (deep) {
|
|
403
|
-
deepExtend(pack, resources, overwrite);
|
|
404
|
-
} else {
|
|
405
|
-
pack = {
|
|
406
|
-
...pack,
|
|
407
|
-
...resources
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
setPath(this.data, path, pack);
|
|
411
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
412
|
-
}
|
|
413
|
-
removeResourceBundle(lng, ns) {
|
|
414
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
415
|
-
delete this.data[lng][ns];
|
|
416
|
-
}
|
|
417
|
-
this.removeNamespaces(ns);
|
|
418
|
-
this.emit('removed', lng, ns);
|
|
419
|
-
}
|
|
420
|
-
hasResourceBundle(lng, ns) {
|
|
421
|
-
return this.getResource(lng, ns) !== undefined;
|
|
422
|
-
}
|
|
423
|
-
getResourceBundle(lng, ns) {
|
|
424
|
-
if (!ns) ns = this.options.defaultNS;
|
|
425
|
-
if (this.options.compatibilityAPI === 'v1') return {
|
|
426
|
-
...{},
|
|
427
|
-
...this.getResource(lng, ns)
|
|
428
|
-
};
|
|
429
|
-
return this.getResource(lng, ns);
|
|
430
|
-
}
|
|
431
|
-
getDataByLanguage(lng) {
|
|
432
|
-
return this.data[lng];
|
|
433
|
-
}
|
|
434
|
-
hasLanguageSomeTranslations(lng) {
|
|
435
|
-
const data = this.getDataByLanguage(lng);
|
|
436
|
-
const n = data && Object.keys(data) || [];
|
|
437
|
-
return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
|
|
438
|
-
}
|
|
439
|
-
toJSON() {
|
|
440
|
-
return this.data;
|
|
441
|
-
}
|
|
122
|
+
function _nonIterableRest() {
|
|
123
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
442
124
|
}
|
|
443
125
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
addPostProcessor(module) {
|
|
447
|
-
this.processors[module.name] = module;
|
|
448
|
-
},
|
|
449
|
-
handle(processors, value, key, options, translator) {
|
|
450
|
-
processors.forEach(processor => {
|
|
451
|
-
if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
|
|
452
|
-
});
|
|
453
|
-
return value;
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
const checkedLoadedFor = {};
|
|
458
|
-
class Translator extends EventEmitter {
|
|
459
|
-
constructor(services) {
|
|
460
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
461
|
-
super();
|
|
462
|
-
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
|
|
463
|
-
this.options = options;
|
|
464
|
-
if (this.options.keySeparator === undefined) {
|
|
465
|
-
this.options.keySeparator = '.';
|
|
466
|
-
}
|
|
467
|
-
this.logger = baseLogger.create('translator');
|
|
468
|
-
}
|
|
469
|
-
changeLanguage(lng) {
|
|
470
|
-
if (lng) this.language = lng;
|
|
471
|
-
}
|
|
472
|
-
exists(key) {
|
|
473
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
474
|
-
interpolation: {}
|
|
475
|
-
};
|
|
476
|
-
if (key === undefined || key === null) {
|
|
477
|
-
return false;
|
|
478
|
-
}
|
|
479
|
-
const resolved = this.resolve(key, options);
|
|
480
|
-
return resolved && resolved.res !== undefined;
|
|
481
|
-
}
|
|
482
|
-
extractFromKey(key, options) {
|
|
483
|
-
let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
|
|
484
|
-
if (nsSeparator === undefined) nsSeparator = ':';
|
|
485
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
486
|
-
let namespaces = options.ns || this.options.defaultNS || [];
|
|
487
|
-
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
488
|
-
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
489
|
-
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
490
|
-
const m = key.match(this.interpolator.nestingRegexp);
|
|
491
|
-
if (m && m.length > 0) {
|
|
492
|
-
return {
|
|
493
|
-
key,
|
|
494
|
-
namespaces
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
const parts = key.split(nsSeparator);
|
|
498
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
499
|
-
key = parts.join(keySeparator);
|
|
500
|
-
}
|
|
501
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
502
|
-
return {
|
|
503
|
-
key,
|
|
504
|
-
namespaces
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
translate(keys, options, lastKey) {
|
|
508
|
-
if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
509
|
-
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
510
|
-
}
|
|
511
|
-
if (typeof options === 'object') options = {
|
|
512
|
-
...options
|
|
513
|
-
};
|
|
514
|
-
if (!options) options = {};
|
|
515
|
-
if (keys === undefined || keys === null) return '';
|
|
516
|
-
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
517
|
-
const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
518
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
519
|
-
const {
|
|
520
|
-
key,
|
|
521
|
-
namespaces
|
|
522
|
-
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
523
|
-
const namespace = namespaces[namespaces.length - 1];
|
|
524
|
-
const lng = options.lng || this.language;
|
|
525
|
-
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
526
|
-
if (lng && lng.toLowerCase() === 'cimode') {
|
|
527
|
-
if (appendNamespaceToCIMode) {
|
|
528
|
-
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
529
|
-
if (returnDetails) {
|
|
530
|
-
return {
|
|
531
|
-
res: `${namespace}${nsSeparator}${key}`,
|
|
532
|
-
usedKey: key,
|
|
533
|
-
exactUsedKey: key,
|
|
534
|
-
usedLng: lng,
|
|
535
|
-
usedNS: namespace
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
return `${namespace}${nsSeparator}${key}`;
|
|
539
|
-
}
|
|
540
|
-
if (returnDetails) {
|
|
541
|
-
return {
|
|
542
|
-
res: key,
|
|
543
|
-
usedKey: key,
|
|
544
|
-
exactUsedKey: key,
|
|
545
|
-
usedLng: lng,
|
|
546
|
-
usedNS: namespace
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
return key;
|
|
550
|
-
}
|
|
551
|
-
const resolved = this.resolve(keys, options);
|
|
552
|
-
let res = resolved && resolved.res;
|
|
553
|
-
const resUsedKey = resolved && resolved.usedKey || key;
|
|
554
|
-
const resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
555
|
-
const resType = Object.prototype.toString.apply(res);
|
|
556
|
-
const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
557
|
-
const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
|
|
558
|
-
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
559
|
-
const handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
|
|
560
|
-
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
|
|
561
|
-
if (!options.returnObjects && !this.options.returnObjects) {
|
|
562
|
-
if (!this.options.returnedObjectHandler) {
|
|
563
|
-
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
564
|
-
}
|
|
565
|
-
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
566
|
-
...options,
|
|
567
|
-
ns: namespaces
|
|
568
|
-
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
569
|
-
if (returnDetails) {
|
|
570
|
-
resolved.res = r;
|
|
571
|
-
return resolved;
|
|
572
|
-
}
|
|
573
|
-
return r;
|
|
574
|
-
}
|
|
575
|
-
if (keySeparator) {
|
|
576
|
-
const resTypeIsArray = resType === '[object Array]';
|
|
577
|
-
const copy = resTypeIsArray ? [] : {};
|
|
578
|
-
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
579
|
-
for (const m in res) {
|
|
580
|
-
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
581
|
-
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
582
|
-
copy[m] = this.translate(deepKey, {
|
|
583
|
-
...options,
|
|
584
|
-
...{
|
|
585
|
-
joinArrays: false,
|
|
586
|
-
ns: namespaces
|
|
587
|
-
}
|
|
588
|
-
});
|
|
589
|
-
if (copy[m] === deepKey) copy[m] = res[m];
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
res = copy;
|
|
593
|
-
}
|
|
594
|
-
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
|
|
595
|
-
res = res.join(joinArrays);
|
|
596
|
-
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
597
|
-
} else {
|
|
598
|
-
let usedDefault = false;
|
|
599
|
-
let usedKey = false;
|
|
600
|
-
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
601
|
-
const hasDefaultValue = Translator.hasDefaultValue(options);
|
|
602
|
-
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
|
|
603
|
-
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
604
|
-
ordinal: false
|
|
605
|
-
}) : '';
|
|
606
|
-
const defaultValue = options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
607
|
-
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
608
|
-
usedDefault = true;
|
|
609
|
-
res = defaultValue;
|
|
610
|
-
}
|
|
611
|
-
if (!this.isValidLookup(res)) {
|
|
612
|
-
usedKey = true;
|
|
613
|
-
res = key;
|
|
614
|
-
}
|
|
615
|
-
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
616
|
-
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
617
|
-
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
618
|
-
if (usedKey || usedDefault || updateMissing) {
|
|
619
|
-
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
620
|
-
if (keySeparator) {
|
|
621
|
-
const fk = this.resolve(key, {
|
|
622
|
-
...options,
|
|
623
|
-
keySeparator: false
|
|
624
|
-
});
|
|
625
|
-
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.');
|
|
626
|
-
}
|
|
627
|
-
let lngs = [];
|
|
628
|
-
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
629
|
-
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
630
|
-
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
631
|
-
lngs.push(fallbackLngs[i]);
|
|
632
|
-
}
|
|
633
|
-
} else if (this.options.saveMissingTo === 'all') {
|
|
634
|
-
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
635
|
-
} else {
|
|
636
|
-
lngs.push(options.lng || this.language);
|
|
637
|
-
}
|
|
638
|
-
const send = (l, k, specificDefaultValue) => {
|
|
639
|
-
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
640
|
-
if (this.options.missingKeyHandler) {
|
|
641
|
-
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
642
|
-
} else if (this.backendConnector && this.backendConnector.saveMissing) {
|
|
643
|
-
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
644
|
-
}
|
|
645
|
-
this.emit('missingKey', l, namespace, k, res);
|
|
646
|
-
};
|
|
647
|
-
if (this.options.saveMissing) {
|
|
648
|
-
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
649
|
-
lngs.forEach(language => {
|
|
650
|
-
this.pluralResolver.getSuffixes(language, options).forEach(suffix => {
|
|
651
|
-
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
652
|
-
});
|
|
653
|
-
});
|
|
654
|
-
} else {
|
|
655
|
-
send(lngs, key, defaultValue);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
660
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
661
|
-
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
662
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
663
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
|
|
664
|
-
} else {
|
|
665
|
-
res = this.options.parseMissingKeyHandler(res);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
if (returnDetails) {
|
|
670
|
-
resolved.res = res;
|
|
671
|
-
return resolved;
|
|
672
|
-
}
|
|
673
|
-
return res;
|
|
674
|
-
}
|
|
675
|
-
extendTranslation(res, key, options, resolved, lastKey) {
|
|
676
|
-
var _this = this;
|
|
677
|
-
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
678
|
-
res = this.i18nFormat.parse(res, {
|
|
679
|
-
...this.options.interpolation.defaultVariables,
|
|
680
|
-
...options
|
|
681
|
-
}, resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
682
|
-
resolved
|
|
683
|
-
});
|
|
684
|
-
} else if (!options.skipInterpolation) {
|
|
685
|
-
if (options.interpolation) this.interpolator.init({
|
|
686
|
-
...options,
|
|
687
|
-
...{
|
|
688
|
-
interpolation: {
|
|
689
|
-
...this.options.interpolation,
|
|
690
|
-
...options.interpolation
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
});
|
|
694
|
-
const skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
695
|
-
let nestBef;
|
|
696
|
-
if (skipOnVariables) {
|
|
697
|
-
const nb = res.match(this.interpolator.nestingRegexp);
|
|
698
|
-
nestBef = nb && nb.length;
|
|
699
|
-
}
|
|
700
|
-
let data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
|
|
701
|
-
if (this.options.interpolation.defaultVariables) data = {
|
|
702
|
-
...this.options.interpolation.defaultVariables,
|
|
703
|
-
...data
|
|
704
|
-
};
|
|
705
|
-
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
706
|
-
if (skipOnVariables) {
|
|
707
|
-
const na = res.match(this.interpolator.nestingRegexp);
|
|
708
|
-
const nestAft = na && na.length;
|
|
709
|
-
if (nestBef < nestAft) options.nest = false;
|
|
710
|
-
}
|
|
711
|
-
if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
|
|
712
|
-
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
713
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
714
|
-
args[_key] = arguments[_key];
|
|
715
|
-
}
|
|
716
|
-
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
717
|
-
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
718
|
-
return null;
|
|
719
|
-
}
|
|
720
|
-
return _this.translate(...args, key);
|
|
721
|
-
}, options);
|
|
722
|
-
if (options.interpolation) this.interpolator.reset();
|
|
723
|
-
}
|
|
724
|
-
const postProcess = options.postProcess || this.options.postProcess;
|
|
725
|
-
const postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
|
|
726
|
-
if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
727
|
-
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
728
|
-
i18nResolved: resolved,
|
|
729
|
-
...options
|
|
730
|
-
} : options, this);
|
|
731
|
-
}
|
|
732
|
-
return res;
|
|
733
|
-
}
|
|
734
|
-
resolve(keys) {
|
|
735
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
736
|
-
let found;
|
|
737
|
-
let usedKey;
|
|
738
|
-
let exactUsedKey;
|
|
739
|
-
let usedLng;
|
|
740
|
-
let usedNS;
|
|
741
|
-
if (typeof keys === 'string') keys = [keys];
|
|
742
|
-
keys.forEach(k => {
|
|
743
|
-
if (this.isValidLookup(found)) return;
|
|
744
|
-
const extracted = this.extractFromKey(k, options);
|
|
745
|
-
const key = extracted.key;
|
|
746
|
-
usedKey = key;
|
|
747
|
-
let namespaces = extracted.namespaces;
|
|
748
|
-
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
749
|
-
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
750
|
-
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
751
|
-
const needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
|
|
752
|
-
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
753
|
-
namespaces.forEach(ns => {
|
|
754
|
-
if (this.isValidLookup(found)) return;
|
|
755
|
-
usedNS = ns;
|
|
756
|
-
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
|
|
757
|
-
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
758
|
-
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!!!');
|
|
759
|
-
}
|
|
760
|
-
codes.forEach(code => {
|
|
761
|
-
if (this.isValidLookup(found)) return;
|
|
762
|
-
usedLng = code;
|
|
763
|
-
const finalKeys = [key];
|
|
764
|
-
if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
|
|
765
|
-
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
766
|
-
} else {
|
|
767
|
-
let pluralSuffix;
|
|
768
|
-
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
769
|
-
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
770
|
-
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
771
|
-
if (needsPluralHandling) {
|
|
772
|
-
finalKeys.push(key + pluralSuffix);
|
|
773
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
774
|
-
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
775
|
-
}
|
|
776
|
-
if (needsZeroSuffixLookup) {
|
|
777
|
-
finalKeys.push(key + zeroSuffix);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
if (needsContextHandling) {
|
|
781
|
-
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
782
|
-
finalKeys.push(contextKey);
|
|
783
|
-
if (needsPluralHandling) {
|
|
784
|
-
finalKeys.push(contextKey + pluralSuffix);
|
|
785
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
786
|
-
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
787
|
-
}
|
|
788
|
-
if (needsZeroSuffixLookup) {
|
|
789
|
-
finalKeys.push(contextKey + zeroSuffix);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
let possibleKey;
|
|
795
|
-
while (possibleKey = finalKeys.pop()) {
|
|
796
|
-
if (!this.isValidLookup(found)) {
|
|
797
|
-
exactUsedKey = possibleKey;
|
|
798
|
-
found = this.getResource(code, ns, possibleKey, options);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
});
|
|
802
|
-
});
|
|
803
|
-
});
|
|
804
|
-
return {
|
|
805
|
-
res: found,
|
|
806
|
-
usedKey,
|
|
807
|
-
exactUsedKey,
|
|
808
|
-
usedLng,
|
|
809
|
-
usedNS
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
isValidLookup(res) {
|
|
813
|
-
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
814
|
-
}
|
|
815
|
-
getResource(code, ns, key) {
|
|
816
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
817
|
-
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
818
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
819
|
-
}
|
|
820
|
-
static hasDefaultValue(options) {
|
|
821
|
-
const prefix = 'defaultValue';
|
|
822
|
-
for (const option in options) {
|
|
823
|
-
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
824
|
-
return true;
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
return false;
|
|
828
|
-
}
|
|
126
|
+
function _slicedToArray(arr, i) {
|
|
127
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
829
128
|
}
|
|
830
129
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
this.options = options;
|
|
837
|
-
this.supportedLngs = this.options.supportedLngs || false;
|
|
838
|
-
this.logger = baseLogger.create('languageUtils');
|
|
839
|
-
}
|
|
840
|
-
getScriptPartFromCode(code) {
|
|
841
|
-
code = getCleanedCode(code);
|
|
842
|
-
if (!code || code.indexOf('-') < 0) return null;
|
|
843
|
-
const p = code.split('-');
|
|
844
|
-
if (p.length === 2) return null;
|
|
845
|
-
p.pop();
|
|
846
|
-
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
847
|
-
return this.formatLanguageCode(p.join('-'));
|
|
848
|
-
}
|
|
849
|
-
getLanguagePartFromCode(code) {
|
|
850
|
-
code = getCleanedCode(code);
|
|
851
|
-
if (!code || code.indexOf('-') < 0) return code;
|
|
852
|
-
const p = code.split('-');
|
|
853
|
-
return this.formatLanguageCode(p[0]);
|
|
854
|
-
}
|
|
855
|
-
formatLanguageCode(code) {
|
|
856
|
-
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
857
|
-
const specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
|
|
858
|
-
let p = code.split('-');
|
|
859
|
-
if (this.options.lowerCaseLng) {
|
|
860
|
-
p = p.map(part => part.toLowerCase());
|
|
861
|
-
} else if (p.length === 2) {
|
|
862
|
-
p[0] = p[0].toLowerCase();
|
|
863
|
-
p[1] = p[1].toUpperCase();
|
|
864
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
865
|
-
} else if (p.length === 3) {
|
|
866
|
-
p[0] = p[0].toLowerCase();
|
|
867
|
-
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
868
|
-
if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
869
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
870
|
-
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
|
|
871
|
-
}
|
|
872
|
-
return p.join('-');
|
|
873
|
-
}
|
|
874
|
-
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
875
|
-
}
|
|
876
|
-
isSupportedCode(code) {
|
|
877
|
-
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
878
|
-
code = this.getLanguagePartFromCode(code);
|
|
879
|
-
}
|
|
880
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
881
|
-
}
|
|
882
|
-
getBestMatchFromCodes(codes) {
|
|
883
|
-
if (!codes) return null;
|
|
884
|
-
let found;
|
|
885
|
-
codes.forEach(code => {
|
|
886
|
-
if (found) return;
|
|
887
|
-
const cleanedLng = this.formatLanguageCode(code);
|
|
888
|
-
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
889
|
-
});
|
|
890
|
-
if (!found && this.options.supportedLngs) {
|
|
891
|
-
codes.forEach(code => {
|
|
892
|
-
if (found) return;
|
|
893
|
-
const lngOnly = this.getLanguagePartFromCode(code);
|
|
894
|
-
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
895
|
-
found = this.options.supportedLngs.find(supportedLng => {
|
|
896
|
-
if (supportedLng === lngOnly) return supportedLng;
|
|
897
|
-
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
898
|
-
if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
|
|
899
|
-
});
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
903
|
-
return found;
|
|
904
|
-
}
|
|
905
|
-
getFallbackCodes(fallbacks, code) {
|
|
906
|
-
if (!fallbacks) return [];
|
|
907
|
-
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
908
|
-
if (typeof fallbacks === 'string') fallbacks = [fallbacks];
|
|
909
|
-
if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
|
|
910
|
-
if (!code) return fallbacks.default || [];
|
|
911
|
-
let found = fallbacks[code];
|
|
912
|
-
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
913
|
-
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
914
|
-
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
915
|
-
if (!found) found = fallbacks.default;
|
|
916
|
-
return found || [];
|
|
917
|
-
}
|
|
918
|
-
toResolveHierarchy(code, fallbackCode) {
|
|
919
|
-
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
920
|
-
const codes = [];
|
|
921
|
-
const addCode = c => {
|
|
922
|
-
if (!c) return;
|
|
923
|
-
if (this.isSupportedCode(c)) {
|
|
924
|
-
codes.push(c);
|
|
925
|
-
} else {
|
|
926
|
-
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
927
|
-
}
|
|
928
|
-
};
|
|
929
|
-
if (typeof code === 'string' && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
|
|
930
|
-
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
931
|
-
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
932
|
-
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
933
|
-
} else if (typeof code === 'string') {
|
|
934
|
-
addCode(this.formatLanguageCode(code));
|
|
130
|
+
var queryClient = new reactQuery.QueryClient({
|
|
131
|
+
queryCache: new reactQuery.QueryCache(),
|
|
132
|
+
defaultOptions: {
|
|
133
|
+
queries: {
|
|
134
|
+
staleTime: constants.DEFAULT_STALE_TIME
|
|
935
135
|
}
|
|
936
|
-
fallbackCodes.forEach(fc => {
|
|
937
|
-
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
938
|
-
});
|
|
939
|
-
return codes;
|
|
940
136
|
}
|
|
941
|
-
}
|
|
137
|
+
});
|
|
942
138
|
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
fc: 3
|
|
955
|
-
}, {
|
|
956
|
-
lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
|
|
957
|
-
nr: [1, 2, 5],
|
|
958
|
-
fc: 4
|
|
959
|
-
}, {
|
|
960
|
-
lngs: ['ar'],
|
|
961
|
-
nr: [0, 1, 2, 3, 11, 100],
|
|
962
|
-
fc: 5
|
|
963
|
-
}, {
|
|
964
|
-
lngs: ['cs', 'sk'],
|
|
965
|
-
nr: [1, 2, 5],
|
|
966
|
-
fc: 6
|
|
967
|
-
}, {
|
|
968
|
-
lngs: ['csb', 'pl'],
|
|
969
|
-
nr: [1, 2, 5],
|
|
970
|
-
fc: 7
|
|
971
|
-
}, {
|
|
972
|
-
lngs: ['cy'],
|
|
973
|
-
nr: [1, 2, 3, 8],
|
|
974
|
-
fc: 8
|
|
975
|
-
}, {
|
|
976
|
-
lngs: ['fr'],
|
|
977
|
-
nr: [1, 2],
|
|
978
|
-
fc: 9
|
|
979
|
-
}, {
|
|
980
|
-
lngs: ['ga'],
|
|
981
|
-
nr: [1, 2, 3, 7, 11],
|
|
982
|
-
fc: 10
|
|
983
|
-
}, {
|
|
984
|
-
lngs: ['gd'],
|
|
985
|
-
nr: [1, 2, 3, 20],
|
|
986
|
-
fc: 11
|
|
987
|
-
}, {
|
|
988
|
-
lngs: ['is'],
|
|
989
|
-
nr: [1, 2],
|
|
990
|
-
fc: 12
|
|
991
|
-
}, {
|
|
992
|
-
lngs: ['jv'],
|
|
993
|
-
nr: [0, 1],
|
|
994
|
-
fc: 13
|
|
995
|
-
}, {
|
|
996
|
-
lngs: ['kw'],
|
|
997
|
-
nr: [1, 2, 3, 4],
|
|
998
|
-
fc: 14
|
|
999
|
-
}, {
|
|
1000
|
-
lngs: ['lt'],
|
|
1001
|
-
nr: [1, 2, 10],
|
|
1002
|
-
fc: 15
|
|
1003
|
-
}, {
|
|
1004
|
-
lngs: ['lv'],
|
|
1005
|
-
nr: [1, 2, 0],
|
|
1006
|
-
fc: 16
|
|
1007
|
-
}, {
|
|
1008
|
-
lngs: ['mk'],
|
|
1009
|
-
nr: [1, 2],
|
|
1010
|
-
fc: 17
|
|
1011
|
-
}, {
|
|
1012
|
-
lngs: ['mnk'],
|
|
1013
|
-
nr: [0, 1, 2],
|
|
1014
|
-
fc: 18
|
|
1015
|
-
}, {
|
|
1016
|
-
lngs: ['mt'],
|
|
1017
|
-
nr: [1, 2, 11, 20],
|
|
1018
|
-
fc: 19
|
|
1019
|
-
}, {
|
|
1020
|
-
lngs: ['or'],
|
|
1021
|
-
nr: [2, 1],
|
|
1022
|
-
fc: 2
|
|
1023
|
-
}, {
|
|
1024
|
-
lngs: ['ro'],
|
|
1025
|
-
nr: [1, 2, 20],
|
|
1026
|
-
fc: 20
|
|
1027
|
-
}, {
|
|
1028
|
-
lngs: ['sl'],
|
|
1029
|
-
nr: [5, 1, 2, 3],
|
|
1030
|
-
fc: 21
|
|
1031
|
-
}, {
|
|
1032
|
-
lngs: ['he', 'iw'],
|
|
1033
|
-
nr: [1, 2, 20, 21],
|
|
1034
|
-
fc: 22
|
|
1035
|
-
}];
|
|
1036
|
-
let _rulesPluralsTypes = {
|
|
1037
|
-
1: function (n) {
|
|
1038
|
-
return Number(n > 1);
|
|
1039
|
-
},
|
|
1040
|
-
2: function (n) {
|
|
1041
|
-
return Number(n != 1);
|
|
1042
|
-
},
|
|
1043
|
-
3: function (n) {
|
|
1044
|
-
return 0;
|
|
1045
|
-
},
|
|
1046
|
-
4: function (n) {
|
|
1047
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1048
|
-
},
|
|
1049
|
-
5: function (n) {
|
|
1050
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
|
|
1051
|
-
},
|
|
1052
|
-
6: function (n) {
|
|
1053
|
-
return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
|
|
1054
|
-
},
|
|
1055
|
-
7: function (n) {
|
|
1056
|
-
return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1057
|
-
},
|
|
1058
|
-
8: function (n) {
|
|
1059
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
|
|
1060
|
-
},
|
|
1061
|
-
9: function (n) {
|
|
1062
|
-
return Number(n >= 2);
|
|
1063
|
-
},
|
|
1064
|
-
10: function (n) {
|
|
1065
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
|
|
1066
|
-
},
|
|
1067
|
-
11: function (n) {
|
|
1068
|
-
return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
|
|
1069
|
-
},
|
|
1070
|
-
12: function (n) {
|
|
1071
|
-
return Number(n % 10 != 1 || n % 100 == 11);
|
|
1072
|
-
},
|
|
1073
|
-
13: function (n) {
|
|
1074
|
-
return Number(n !== 0);
|
|
1075
|
-
},
|
|
1076
|
-
14: function (n) {
|
|
1077
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
|
|
1078
|
-
},
|
|
1079
|
-
15: function (n) {
|
|
1080
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1081
|
-
},
|
|
1082
|
-
16: function (n) {
|
|
1083
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
|
|
1084
|
-
},
|
|
1085
|
-
17: function (n) {
|
|
1086
|
-
return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
|
|
1087
|
-
},
|
|
1088
|
-
18: function (n) {
|
|
1089
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
|
|
1090
|
-
},
|
|
1091
|
-
19: function (n) {
|
|
1092
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
|
|
1093
|
-
},
|
|
1094
|
-
20: function (n) {
|
|
1095
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
|
|
1096
|
-
},
|
|
1097
|
-
21: function (n) {
|
|
1098
|
-
return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
|
|
1099
|
-
},
|
|
1100
|
-
22: function (n) {
|
|
1101
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
|
|
1102
|
-
}
|
|
1103
|
-
};
|
|
1104
|
-
const nonIntlVersions = ['v1', 'v2', 'v3'];
|
|
1105
|
-
const intlVersions = ['v4'];
|
|
1106
|
-
const suffixesOrder = {
|
|
1107
|
-
zero: 0,
|
|
1108
|
-
one: 1,
|
|
1109
|
-
two: 2,
|
|
1110
|
-
few: 3,
|
|
1111
|
-
many: 4,
|
|
1112
|
-
other: 5
|
|
139
|
+
/* eslint-disable @bigbinary/neeto/file-name-and-export-name-standards */
|
|
140
|
+
var withReactQuery = function withReactQuery(Component) {
|
|
141
|
+
var QueryWrapper = function QueryWrapper(props) {
|
|
142
|
+
return /*#__PURE__*/React__default["default"].createElement(reactQuery.QueryClientProvider, {
|
|
143
|
+
client: queryClient
|
|
144
|
+
}, /*#__PURE__*/React__default["default"].createElement(Component, props), /*#__PURE__*/React__default["default"].createElement(devtools.ReactQueryDevtools, {
|
|
145
|
+
initialIsOpen: false,
|
|
146
|
+
position: "bottom-right"
|
|
147
|
+
}));
|
|
148
|
+
};
|
|
149
|
+
return QueryWrapper;
|
|
1113
150
|
};
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
numbers: set.nr,
|
|
1120
|
-
plurals: _rulesPluralsTypes[set.fc]
|
|
1121
|
-
};
|
|
1122
|
-
});
|
|
151
|
+
|
|
152
|
+
var baseUrl$2 = "/webhooks/deliveries";
|
|
153
|
+
var fetch$1 = function fetch(params) {
|
|
154
|
+
return axios__default["default"].get(baseUrl$2, {
|
|
155
|
+
params: params
|
|
1123
156
|
});
|
|
1124
|
-
return rules;
|
|
1125
|
-
}
|
|
1126
|
-
class PluralResolver {
|
|
1127
|
-
constructor(languageUtils) {
|
|
1128
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1129
|
-
this.languageUtils = languageUtils;
|
|
1130
|
-
this.options = options;
|
|
1131
|
-
this.logger = baseLogger.create('pluralResolver');
|
|
1132
|
-
if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
|
|
1133
|
-
this.options.compatibilityJSON = 'v3';
|
|
1134
|
-
this.logger.error('Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.');
|
|
1135
|
-
}
|
|
1136
|
-
this.rules = createRules();
|
|
1137
|
-
}
|
|
1138
|
-
addRule(lng, obj) {
|
|
1139
|
-
this.rules[lng] = obj;
|
|
1140
|
-
}
|
|
1141
|
-
getRule(code) {
|
|
1142
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1143
|
-
if (this.shouldUseIntlApi()) {
|
|
1144
|
-
try {
|
|
1145
|
-
return new Intl.PluralRules(getCleanedCode(code), {
|
|
1146
|
-
type: options.ordinal ? 'ordinal' : 'cardinal'
|
|
1147
|
-
});
|
|
1148
|
-
} catch {
|
|
1149
|
-
return;
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
1153
|
-
}
|
|
1154
|
-
needsPlural(code) {
|
|
1155
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1156
|
-
const rule = this.getRule(code, options);
|
|
1157
|
-
if (this.shouldUseIntlApi()) {
|
|
1158
|
-
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
1159
|
-
}
|
|
1160
|
-
return rule && rule.numbers.length > 1;
|
|
1161
|
-
}
|
|
1162
|
-
getPluralFormsOfKey(code, key) {
|
|
1163
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1164
|
-
return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
|
|
1165
|
-
}
|
|
1166
|
-
getSuffixes(code) {
|
|
1167
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1168
|
-
const rule = this.getRule(code, options);
|
|
1169
|
-
if (!rule) {
|
|
1170
|
-
return [];
|
|
1171
|
-
}
|
|
1172
|
-
if (this.shouldUseIntlApi()) {
|
|
1173
|
-
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
|
|
1174
|
-
}
|
|
1175
|
-
return rule.numbers.map(number => this.getSuffix(code, number, options));
|
|
1176
|
-
}
|
|
1177
|
-
getSuffix(code, count) {
|
|
1178
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1179
|
-
const rule = this.getRule(code, options);
|
|
1180
|
-
if (rule) {
|
|
1181
|
-
if (this.shouldUseIntlApi()) {
|
|
1182
|
-
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
|
|
1183
|
-
}
|
|
1184
|
-
return this.getSuffixRetroCompatible(rule, count);
|
|
1185
|
-
}
|
|
1186
|
-
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1187
|
-
return '';
|
|
1188
|
-
}
|
|
1189
|
-
getSuffixRetroCompatible(rule, count) {
|
|
1190
|
-
const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
1191
|
-
let suffix = rule.numbers[idx];
|
|
1192
|
-
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1193
|
-
if (suffix === 2) {
|
|
1194
|
-
suffix = 'plural';
|
|
1195
|
-
} else if (suffix === 1) {
|
|
1196
|
-
suffix = '';
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
|
|
1200
|
-
if (this.options.compatibilityJSON === 'v1') {
|
|
1201
|
-
if (suffix === 1) return '';
|
|
1202
|
-
if (typeof suffix === 'number') return `_plural_${suffix.toString()}`;
|
|
1203
|
-
return returnSuffix();
|
|
1204
|
-
} else if (this.options.compatibilityJSON === 'v2') {
|
|
1205
|
-
return returnSuffix();
|
|
1206
|
-
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1207
|
-
return returnSuffix();
|
|
1208
|
-
}
|
|
1209
|
-
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
1210
|
-
}
|
|
1211
|
-
shouldUseIntlApi() {
|
|
1212
|
-
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
function deepFindWithDefaults(data, defaultData, key) {
|
|
1217
|
-
let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
1218
|
-
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1219
|
-
let path = getPathWithDefaults(data, defaultData, key);
|
|
1220
|
-
if (!path && ignoreJSONStructure && typeof key === 'string') {
|
|
1221
|
-
path = deepFind(data, key, keySeparator);
|
|
1222
|
-
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
1223
|
-
}
|
|
1224
|
-
return path;
|
|
1225
|
-
}
|
|
1226
|
-
class Interpolator {
|
|
1227
|
-
constructor() {
|
|
1228
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1229
|
-
this.logger = baseLogger.create('interpolator');
|
|
1230
|
-
this.options = options;
|
|
1231
|
-
this.format = options.interpolation && options.interpolation.format || (value => value);
|
|
1232
|
-
this.init(options);
|
|
1233
|
-
}
|
|
1234
|
-
init() {
|
|
1235
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1236
|
-
if (!options.interpolation) options.interpolation = {
|
|
1237
|
-
escapeValue: true
|
|
1238
|
-
};
|
|
1239
|
-
const iOpts = options.interpolation;
|
|
1240
|
-
this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
|
|
1241
|
-
this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
|
|
1242
|
-
this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
|
|
1243
|
-
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
|
|
1244
|
-
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
|
|
1245
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1246
|
-
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
|
|
1247
|
-
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
|
|
1248
|
-
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
|
|
1249
|
-
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
|
|
1250
|
-
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
|
|
1251
|
-
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
|
|
1252
|
-
this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
|
|
1253
|
-
this.resetRegExp();
|
|
1254
|
-
}
|
|
1255
|
-
reset() {
|
|
1256
|
-
if (this.options) this.init(this.options);
|
|
1257
|
-
}
|
|
1258
|
-
resetRegExp() {
|
|
1259
|
-
const regexpStr = `${this.prefix}(.+?)${this.suffix}`;
|
|
1260
|
-
this.regexp = new RegExp(regexpStr, 'g');
|
|
1261
|
-
const regexpUnescapeStr = `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`;
|
|
1262
|
-
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
|
|
1263
|
-
const nestingRegexpStr = `${this.nestingPrefix}(.+?)${this.nestingSuffix}`;
|
|
1264
|
-
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
|
|
1265
|
-
}
|
|
1266
|
-
interpolate(str, data, lng, options) {
|
|
1267
|
-
let match;
|
|
1268
|
-
let value;
|
|
1269
|
-
let replaces;
|
|
1270
|
-
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1271
|
-
function regexSafe(val) {
|
|
1272
|
-
return val.replace(/\$/g, '$$$$');
|
|
1273
|
-
}
|
|
1274
|
-
const handleFormat = key => {
|
|
1275
|
-
if (key.indexOf(this.formatSeparator) < 0) {
|
|
1276
|
-
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1277
|
-
return this.alwaysFormat ? this.format(path, undefined, lng, {
|
|
1278
|
-
...options,
|
|
1279
|
-
...data,
|
|
1280
|
-
interpolationkey: key
|
|
1281
|
-
}) : path;
|
|
1282
|
-
}
|
|
1283
|
-
const p = key.split(this.formatSeparator);
|
|
1284
|
-
const k = p.shift().trim();
|
|
1285
|
-
const f = p.join(this.formatSeparator).trim();
|
|
1286
|
-
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1287
|
-
...options,
|
|
1288
|
-
...data,
|
|
1289
|
-
interpolationkey: k
|
|
1290
|
-
});
|
|
1291
|
-
};
|
|
1292
|
-
this.resetRegExp();
|
|
1293
|
-
const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1294
|
-
const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1295
|
-
const todos = [{
|
|
1296
|
-
regex: this.regexpUnescape,
|
|
1297
|
-
safeValue: val => regexSafe(val)
|
|
1298
|
-
}, {
|
|
1299
|
-
regex: this.regexp,
|
|
1300
|
-
safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
1301
|
-
}];
|
|
1302
|
-
todos.forEach(todo => {
|
|
1303
|
-
replaces = 0;
|
|
1304
|
-
while (match = todo.regex.exec(str)) {
|
|
1305
|
-
const matchedVar = match[1].trim();
|
|
1306
|
-
value = handleFormat(matchedVar);
|
|
1307
|
-
if (value === undefined) {
|
|
1308
|
-
if (typeof missingInterpolationHandler === 'function') {
|
|
1309
|
-
const temp = missingInterpolationHandler(str, match, options);
|
|
1310
|
-
value = typeof temp === 'string' ? temp : '';
|
|
1311
|
-
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1312
|
-
value = '';
|
|
1313
|
-
} else if (skipOnVariables) {
|
|
1314
|
-
value = match[0];
|
|
1315
|
-
continue;
|
|
1316
|
-
} else {
|
|
1317
|
-
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1318
|
-
value = '';
|
|
1319
|
-
}
|
|
1320
|
-
} else if (typeof value !== 'string' && !this.useRawValueToEscape) {
|
|
1321
|
-
value = makeString(value);
|
|
1322
|
-
}
|
|
1323
|
-
const safeValue = todo.safeValue(value);
|
|
1324
|
-
str = str.replace(match[0], safeValue);
|
|
1325
|
-
if (skipOnVariables) {
|
|
1326
|
-
todo.regex.lastIndex += value.length;
|
|
1327
|
-
todo.regex.lastIndex -= match[0].length;
|
|
1328
|
-
} else {
|
|
1329
|
-
todo.regex.lastIndex = 0;
|
|
1330
|
-
}
|
|
1331
|
-
replaces++;
|
|
1332
|
-
if (replaces >= this.maxReplaces) {
|
|
1333
|
-
break;
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
});
|
|
1337
|
-
return str;
|
|
1338
|
-
}
|
|
1339
|
-
nest(str, fc) {
|
|
1340
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1341
|
-
let match;
|
|
1342
|
-
let value;
|
|
1343
|
-
let clonedOptions;
|
|
1344
|
-
function handleHasOptions(key, inheritedOptions) {
|
|
1345
|
-
const sep = this.nestingOptionsSeparator;
|
|
1346
|
-
if (key.indexOf(sep) < 0) return key;
|
|
1347
|
-
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
1348
|
-
let optionsString = `{${c[1]}`;
|
|
1349
|
-
key = c[0];
|
|
1350
|
-
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1351
|
-
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1352
|
-
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1353
|
-
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
1354
|
-
optionsString = optionsString.replace(/'/g, '"');
|
|
1355
|
-
}
|
|
1356
|
-
try {
|
|
1357
|
-
clonedOptions = JSON.parse(optionsString);
|
|
1358
|
-
if (inheritedOptions) clonedOptions = {
|
|
1359
|
-
...inheritedOptions,
|
|
1360
|
-
...clonedOptions
|
|
1361
|
-
};
|
|
1362
|
-
} catch (e) {
|
|
1363
|
-
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1364
|
-
return `${key}${sep}${optionsString}`;
|
|
1365
|
-
}
|
|
1366
|
-
delete clonedOptions.defaultValue;
|
|
1367
|
-
return key;
|
|
1368
|
-
}
|
|
1369
|
-
while (match = this.nestingRegexp.exec(str)) {
|
|
1370
|
-
let formatters = [];
|
|
1371
|
-
clonedOptions = {
|
|
1372
|
-
...options
|
|
1373
|
-
};
|
|
1374
|
-
clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
|
|
1375
|
-
clonedOptions.applyPostProcessor = false;
|
|
1376
|
-
delete clonedOptions.defaultValue;
|
|
1377
|
-
let doReduce = false;
|
|
1378
|
-
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1379
|
-
const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
|
|
1380
|
-
match[1] = r.shift();
|
|
1381
|
-
formatters = r;
|
|
1382
|
-
doReduce = true;
|
|
1383
|
-
}
|
|
1384
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1385
|
-
if (value && match[0] === str && typeof value !== 'string') return value;
|
|
1386
|
-
if (typeof value !== 'string') value = makeString(value);
|
|
1387
|
-
if (!value) {
|
|
1388
|
-
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1389
|
-
value = '';
|
|
1390
|
-
}
|
|
1391
|
-
if (doReduce) {
|
|
1392
|
-
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1393
|
-
...options,
|
|
1394
|
-
interpolationkey: match[1].trim()
|
|
1395
|
-
}), value.trim());
|
|
1396
|
-
}
|
|
1397
|
-
str = str.replace(match[0], value);
|
|
1398
|
-
this.regexp.lastIndex = 0;
|
|
1399
|
-
}
|
|
1400
|
-
return str;
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
function parseFormatStr(formatStr) {
|
|
1405
|
-
let formatName = formatStr.toLowerCase().trim();
|
|
1406
|
-
const formatOptions = {};
|
|
1407
|
-
if (formatStr.indexOf('(') > -1) {
|
|
1408
|
-
const p = formatStr.split('(');
|
|
1409
|
-
formatName = p[0].toLowerCase().trim();
|
|
1410
|
-
const optStr = p[1].substring(0, p[1].length - 1);
|
|
1411
|
-
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
1412
|
-
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1413
|
-
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
1414
|
-
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1415
|
-
} else {
|
|
1416
|
-
const opts = optStr.split(';');
|
|
1417
|
-
opts.forEach(opt => {
|
|
1418
|
-
if (!opt) return;
|
|
1419
|
-
const [key, ...rest] = opt.split(':');
|
|
1420
|
-
const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
1421
|
-
if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
|
|
1422
|
-
if (val === 'false') formatOptions[key.trim()] = false;
|
|
1423
|
-
if (val === 'true') formatOptions[key.trim()] = true;
|
|
1424
|
-
if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
|
|
1425
|
-
});
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
return {
|
|
1429
|
-
formatName,
|
|
1430
|
-
formatOptions
|
|
1431
|
-
};
|
|
1432
|
-
}
|
|
1433
|
-
function createCachedFormatter(fn) {
|
|
1434
|
-
const cache = {};
|
|
1435
|
-
return function invokeFormatter(val, lng, options) {
|
|
1436
|
-
const key = lng + JSON.stringify(options);
|
|
1437
|
-
let formatter = cache[key];
|
|
1438
|
-
if (!formatter) {
|
|
1439
|
-
formatter = fn(getCleanedCode(lng), options);
|
|
1440
|
-
cache[key] = formatter;
|
|
1441
|
-
}
|
|
1442
|
-
return formatter(val);
|
|
1443
|
-
};
|
|
1444
|
-
}
|
|
1445
|
-
class Formatter {
|
|
1446
|
-
constructor() {
|
|
1447
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1448
|
-
this.logger = baseLogger.create('formatter');
|
|
1449
|
-
this.options = options;
|
|
1450
|
-
this.formats = {
|
|
1451
|
-
number: createCachedFormatter((lng, opt) => {
|
|
1452
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1453
|
-
...opt
|
|
1454
|
-
});
|
|
1455
|
-
return val => formatter.format(val);
|
|
1456
|
-
}),
|
|
1457
|
-
currency: createCachedFormatter((lng, opt) => {
|
|
1458
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1459
|
-
...opt,
|
|
1460
|
-
style: 'currency'
|
|
1461
|
-
});
|
|
1462
|
-
return val => formatter.format(val);
|
|
1463
|
-
}),
|
|
1464
|
-
datetime: createCachedFormatter((lng, opt) => {
|
|
1465
|
-
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1466
|
-
...opt
|
|
1467
|
-
});
|
|
1468
|
-
return val => formatter.format(val);
|
|
1469
|
-
}),
|
|
1470
|
-
relativetime: createCachedFormatter((lng, opt) => {
|
|
1471
|
-
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1472
|
-
...opt
|
|
1473
|
-
});
|
|
1474
|
-
return val => formatter.format(val, opt.range || 'day');
|
|
1475
|
-
}),
|
|
1476
|
-
list: createCachedFormatter((lng, opt) => {
|
|
1477
|
-
const formatter = new Intl.ListFormat(lng, {
|
|
1478
|
-
...opt
|
|
1479
|
-
});
|
|
1480
|
-
return val => formatter.format(val);
|
|
1481
|
-
})
|
|
1482
|
-
};
|
|
1483
|
-
this.init(options);
|
|
1484
|
-
}
|
|
1485
|
-
init(services) {
|
|
1486
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1487
|
-
interpolation: {}
|
|
1488
|
-
};
|
|
1489
|
-
const iOpts = options.interpolation;
|
|
1490
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1491
|
-
}
|
|
1492
|
-
add(name, fc) {
|
|
1493
|
-
this.formats[name.toLowerCase().trim()] = fc;
|
|
1494
|
-
}
|
|
1495
|
-
addCached(name, fc) {
|
|
1496
|
-
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1497
|
-
}
|
|
1498
|
-
format(value, format, lng) {
|
|
1499
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1500
|
-
const formats = format.split(this.formatSeparator);
|
|
1501
|
-
const result = formats.reduce((mem, f) => {
|
|
1502
|
-
const {
|
|
1503
|
-
formatName,
|
|
1504
|
-
formatOptions
|
|
1505
|
-
} = parseFormatStr(f);
|
|
1506
|
-
if (this.formats[formatName]) {
|
|
1507
|
-
let formatted = mem;
|
|
1508
|
-
try {
|
|
1509
|
-
const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
1510
|
-
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1511
|
-
formatted = this.formats[formatName](mem, l, {
|
|
1512
|
-
...formatOptions,
|
|
1513
|
-
...options,
|
|
1514
|
-
...valOptions
|
|
1515
|
-
});
|
|
1516
|
-
} catch (error) {
|
|
1517
|
-
this.logger.warn(error);
|
|
1518
|
-
}
|
|
1519
|
-
return formatted;
|
|
1520
|
-
} else {
|
|
1521
|
-
this.logger.warn(`there was no format function for ${formatName}`);
|
|
1522
|
-
}
|
|
1523
|
-
return mem;
|
|
1524
|
-
}, value);
|
|
1525
|
-
return result;
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
function removePending(q, name) {
|
|
1530
|
-
if (q.pending[name] !== undefined) {
|
|
1531
|
-
delete q.pending[name];
|
|
1532
|
-
q.pendingCount--;
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
class Connector extends EventEmitter {
|
|
1536
|
-
constructor(backend, store, services) {
|
|
1537
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1538
|
-
super();
|
|
1539
|
-
this.backend = backend;
|
|
1540
|
-
this.store = store;
|
|
1541
|
-
this.services = services;
|
|
1542
|
-
this.languageUtils = services.languageUtils;
|
|
1543
|
-
this.options = options;
|
|
1544
|
-
this.logger = baseLogger.create('backendConnector');
|
|
1545
|
-
this.waitingReads = [];
|
|
1546
|
-
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1547
|
-
this.readingCalls = 0;
|
|
1548
|
-
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1549
|
-
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1550
|
-
this.state = {};
|
|
1551
|
-
this.queue = [];
|
|
1552
|
-
if (this.backend && this.backend.init) {
|
|
1553
|
-
this.backend.init(services, options.backend, options);
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
queueLoad(languages, namespaces, options, callback) {
|
|
1557
|
-
const toLoad = {};
|
|
1558
|
-
const pending = {};
|
|
1559
|
-
const toLoadLanguages = {};
|
|
1560
|
-
const toLoadNamespaces = {};
|
|
1561
|
-
languages.forEach(lng => {
|
|
1562
|
-
let hasAllNamespaces = true;
|
|
1563
|
-
namespaces.forEach(ns => {
|
|
1564
|
-
const name = `${lng}|${ns}`;
|
|
1565
|
-
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
1566
|
-
this.state[name] = 2;
|
|
1567
|
-
} else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
|
|
1568
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
1569
|
-
} else {
|
|
1570
|
-
this.state[name] = 1;
|
|
1571
|
-
hasAllNamespaces = false;
|
|
1572
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
1573
|
-
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
1574
|
-
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
1575
|
-
}
|
|
1576
|
-
});
|
|
1577
|
-
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1578
|
-
});
|
|
1579
|
-
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1580
|
-
this.queue.push({
|
|
1581
|
-
pending,
|
|
1582
|
-
pendingCount: Object.keys(pending).length,
|
|
1583
|
-
loaded: {},
|
|
1584
|
-
errors: [],
|
|
1585
|
-
callback
|
|
1586
|
-
});
|
|
1587
|
-
}
|
|
1588
|
-
return {
|
|
1589
|
-
toLoad: Object.keys(toLoad),
|
|
1590
|
-
pending: Object.keys(pending),
|
|
1591
|
-
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1592
|
-
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1593
|
-
};
|
|
1594
|
-
}
|
|
1595
|
-
loaded(name, err, data) {
|
|
1596
|
-
const s = name.split('|');
|
|
1597
|
-
const lng = s[0];
|
|
1598
|
-
const ns = s[1];
|
|
1599
|
-
if (err) this.emit('failedLoading', lng, ns, err);
|
|
1600
|
-
if (data) {
|
|
1601
|
-
this.store.addResourceBundle(lng, ns, data);
|
|
1602
|
-
}
|
|
1603
|
-
this.state[name] = err ? -1 : 2;
|
|
1604
|
-
const loaded = {};
|
|
1605
|
-
this.queue.forEach(q => {
|
|
1606
|
-
pushPath(q.loaded, [lng], ns);
|
|
1607
|
-
removePending(q, name);
|
|
1608
|
-
if (err) q.errors.push(err);
|
|
1609
|
-
if (q.pendingCount === 0 && !q.done) {
|
|
1610
|
-
Object.keys(q.loaded).forEach(l => {
|
|
1611
|
-
if (!loaded[l]) loaded[l] = {};
|
|
1612
|
-
const loadedKeys = q.loaded[l];
|
|
1613
|
-
if (loadedKeys.length) {
|
|
1614
|
-
loadedKeys.forEach(n => {
|
|
1615
|
-
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
1616
|
-
});
|
|
1617
|
-
}
|
|
1618
|
-
});
|
|
1619
|
-
q.done = true;
|
|
1620
|
-
if (q.errors.length) {
|
|
1621
|
-
q.callback(q.errors);
|
|
1622
|
-
} else {
|
|
1623
|
-
q.callback();
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
});
|
|
1627
|
-
this.emit('loaded', loaded);
|
|
1628
|
-
this.queue = this.queue.filter(q => !q.done);
|
|
1629
|
-
}
|
|
1630
|
-
read(lng, ns, fcName) {
|
|
1631
|
-
let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1632
|
-
let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
1633
|
-
let callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
1634
|
-
if (!lng.length) return callback(null, {});
|
|
1635
|
-
if (this.readingCalls >= this.maxParallelReads) {
|
|
1636
|
-
this.waitingReads.push({
|
|
1637
|
-
lng,
|
|
1638
|
-
ns,
|
|
1639
|
-
fcName,
|
|
1640
|
-
tried,
|
|
1641
|
-
wait,
|
|
1642
|
-
callback
|
|
1643
|
-
});
|
|
1644
|
-
return;
|
|
1645
|
-
}
|
|
1646
|
-
this.readingCalls++;
|
|
1647
|
-
const resolver = (err, data) => {
|
|
1648
|
-
this.readingCalls--;
|
|
1649
|
-
if (this.waitingReads.length > 0) {
|
|
1650
|
-
const next = this.waitingReads.shift();
|
|
1651
|
-
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1652
|
-
}
|
|
1653
|
-
if (err && data && tried < this.maxRetries) {
|
|
1654
|
-
setTimeout(() => {
|
|
1655
|
-
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1656
|
-
}, wait);
|
|
1657
|
-
return;
|
|
1658
|
-
}
|
|
1659
|
-
callback(err, data);
|
|
1660
|
-
};
|
|
1661
|
-
const fc = this.backend[fcName].bind(this.backend);
|
|
1662
|
-
if (fc.length === 2) {
|
|
1663
|
-
try {
|
|
1664
|
-
const r = fc(lng, ns);
|
|
1665
|
-
if (r && typeof r.then === 'function') {
|
|
1666
|
-
r.then(data => resolver(null, data)).catch(resolver);
|
|
1667
|
-
} else {
|
|
1668
|
-
resolver(null, r);
|
|
1669
|
-
}
|
|
1670
|
-
} catch (err) {
|
|
1671
|
-
resolver(err);
|
|
1672
|
-
}
|
|
1673
|
-
return;
|
|
1674
|
-
}
|
|
1675
|
-
return fc(lng, ns, resolver);
|
|
1676
|
-
}
|
|
1677
|
-
prepareLoading(languages, namespaces) {
|
|
1678
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1679
|
-
let callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
1680
|
-
if (!this.backend) {
|
|
1681
|
-
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
1682
|
-
return callback && callback();
|
|
1683
|
-
}
|
|
1684
|
-
if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1685
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
1686
|
-
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1687
|
-
if (!toLoad.toLoad.length) {
|
|
1688
|
-
if (!toLoad.pending.length) callback();
|
|
1689
|
-
return null;
|
|
1690
|
-
}
|
|
1691
|
-
toLoad.toLoad.forEach(name => {
|
|
1692
|
-
this.loadOne(name);
|
|
1693
|
-
});
|
|
1694
|
-
}
|
|
1695
|
-
load(languages, namespaces, callback) {
|
|
1696
|
-
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1697
|
-
}
|
|
1698
|
-
reload(languages, namespaces, callback) {
|
|
1699
|
-
this.prepareLoading(languages, namespaces, {
|
|
1700
|
-
reload: true
|
|
1701
|
-
}, callback);
|
|
1702
|
-
}
|
|
1703
|
-
loadOne(name) {
|
|
1704
|
-
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
1705
|
-
const s = name.split('|');
|
|
1706
|
-
const lng = s[0];
|
|
1707
|
-
const ns = s[1];
|
|
1708
|
-
this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
|
|
1709
|
-
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
1710
|
-
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
1711
|
-
this.loaded(name, err, data);
|
|
1712
|
-
});
|
|
1713
|
-
}
|
|
1714
|
-
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
1715
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
1716
|
-
let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
|
|
1717
|
-
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
1718
|
-
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!!!');
|
|
1719
|
-
return;
|
|
1720
|
-
}
|
|
1721
|
-
if (key === undefined || key === null || key === '') return;
|
|
1722
|
-
if (this.backend && this.backend.create) {
|
|
1723
|
-
const opts = {
|
|
1724
|
-
...options,
|
|
1725
|
-
isUpdate
|
|
1726
|
-
};
|
|
1727
|
-
const fc = this.backend.create.bind(this.backend);
|
|
1728
|
-
if (fc.length < 6) {
|
|
1729
|
-
try {
|
|
1730
|
-
let r;
|
|
1731
|
-
if (fc.length === 5) {
|
|
1732
|
-
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
1733
|
-
} else {
|
|
1734
|
-
r = fc(languages, namespace, key, fallbackValue);
|
|
1735
|
-
}
|
|
1736
|
-
if (r && typeof r.then === 'function') {
|
|
1737
|
-
r.then(data => clb(null, data)).catch(clb);
|
|
1738
|
-
} else {
|
|
1739
|
-
clb(null, r);
|
|
1740
|
-
}
|
|
1741
|
-
} catch (err) {
|
|
1742
|
-
clb(err);
|
|
1743
|
-
}
|
|
1744
|
-
} else {
|
|
1745
|
-
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
if (!languages || !languages[0]) return;
|
|
1749
|
-
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
function get() {
|
|
1754
|
-
return {
|
|
1755
|
-
debug: false,
|
|
1756
|
-
initImmediate: true,
|
|
1757
|
-
ns: ['translation'],
|
|
1758
|
-
defaultNS: ['translation'],
|
|
1759
|
-
fallbackLng: ['dev'],
|
|
1760
|
-
fallbackNS: false,
|
|
1761
|
-
supportedLngs: false,
|
|
1762
|
-
nonExplicitSupportedLngs: false,
|
|
1763
|
-
load: 'all',
|
|
1764
|
-
preload: false,
|
|
1765
|
-
simplifyPluralSuffix: true,
|
|
1766
|
-
keySeparator: '.',
|
|
1767
|
-
nsSeparator: ':',
|
|
1768
|
-
pluralSeparator: '_',
|
|
1769
|
-
contextSeparator: '_',
|
|
1770
|
-
partialBundledLanguages: false,
|
|
1771
|
-
saveMissing: false,
|
|
1772
|
-
updateMissing: false,
|
|
1773
|
-
saveMissingTo: 'fallback',
|
|
1774
|
-
saveMissingPlurals: true,
|
|
1775
|
-
missingKeyHandler: false,
|
|
1776
|
-
missingInterpolationHandler: false,
|
|
1777
|
-
postProcess: false,
|
|
1778
|
-
postProcessPassResolved: false,
|
|
1779
|
-
returnNull: false,
|
|
1780
|
-
returnEmptyString: true,
|
|
1781
|
-
returnObjects: false,
|
|
1782
|
-
joinArrays: false,
|
|
1783
|
-
returnedObjectHandler: false,
|
|
1784
|
-
parseMissingKeyHandler: false,
|
|
1785
|
-
appendNamespaceToMissingKey: false,
|
|
1786
|
-
appendNamespaceToCIMode: false,
|
|
1787
|
-
overloadTranslationOptionHandler: function handle(args) {
|
|
1788
|
-
let ret = {};
|
|
1789
|
-
if (typeof args[1] === 'object') ret = args[1];
|
|
1790
|
-
if (typeof args[1] === 'string') ret.defaultValue = args[1];
|
|
1791
|
-
if (typeof args[2] === 'string') ret.tDescription = args[2];
|
|
1792
|
-
if (typeof args[2] === 'object' || typeof args[3] === 'object') {
|
|
1793
|
-
const options = args[3] || args[2];
|
|
1794
|
-
Object.keys(options).forEach(key => {
|
|
1795
|
-
ret[key] = options[key];
|
|
1796
|
-
});
|
|
1797
|
-
}
|
|
1798
|
-
return ret;
|
|
1799
|
-
},
|
|
1800
|
-
interpolation: {
|
|
1801
|
-
escapeValue: true,
|
|
1802
|
-
format: (value, format, lng, options) => value,
|
|
1803
|
-
prefix: '{{',
|
|
1804
|
-
suffix: '}}',
|
|
1805
|
-
formatSeparator: ',',
|
|
1806
|
-
unescapePrefix: '-',
|
|
1807
|
-
nestingPrefix: '$t(',
|
|
1808
|
-
nestingSuffix: ')',
|
|
1809
|
-
nestingOptionsSeparator: ',',
|
|
1810
|
-
maxReplaces: 1000,
|
|
1811
|
-
skipOnVariables: true
|
|
1812
|
-
}
|
|
1813
|
-
};
|
|
1814
|
-
}
|
|
1815
|
-
function transformOptions(options) {
|
|
1816
|
-
if (typeof options.ns === 'string') options.ns = [options.ns];
|
|
1817
|
-
if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
|
|
1818
|
-
if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
|
|
1819
|
-
if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
|
|
1820
|
-
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
1821
|
-
}
|
|
1822
|
-
return options;
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
function noop() {}
|
|
1826
|
-
function bindMemberFunctions(inst) {
|
|
1827
|
-
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
1828
|
-
mems.forEach(mem => {
|
|
1829
|
-
if (typeof inst[mem] === 'function') {
|
|
1830
|
-
inst[mem] = inst[mem].bind(inst);
|
|
1831
|
-
}
|
|
1832
|
-
});
|
|
1833
|
-
}
|
|
1834
|
-
class I18n extends EventEmitter {
|
|
1835
|
-
constructor() {
|
|
1836
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1837
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1838
|
-
super();
|
|
1839
|
-
this.options = transformOptions(options);
|
|
1840
|
-
this.services = {};
|
|
1841
|
-
this.logger = baseLogger;
|
|
1842
|
-
this.modules = {
|
|
1843
|
-
external: []
|
|
1844
|
-
};
|
|
1845
|
-
bindMemberFunctions(this);
|
|
1846
|
-
if (callback && !this.isInitialized && !options.isClone) {
|
|
1847
|
-
if (!this.options.initImmediate) {
|
|
1848
|
-
this.init(options, callback);
|
|
1849
|
-
return this;
|
|
1850
|
-
}
|
|
1851
|
-
setTimeout(() => {
|
|
1852
|
-
this.init(options, callback);
|
|
1853
|
-
}, 0);
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
init() {
|
|
1857
|
-
var _this = this;
|
|
1858
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1859
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1860
|
-
if (typeof options === 'function') {
|
|
1861
|
-
callback = options;
|
|
1862
|
-
options = {};
|
|
1863
|
-
}
|
|
1864
|
-
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
1865
|
-
if (typeof options.ns === 'string') {
|
|
1866
|
-
options.defaultNS = options.ns;
|
|
1867
|
-
} else if (options.ns.indexOf('translation') < 0) {
|
|
1868
|
-
options.defaultNS = options.ns[0];
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
const defOpts = get();
|
|
1872
|
-
this.options = {
|
|
1873
|
-
...defOpts,
|
|
1874
|
-
...this.options,
|
|
1875
|
-
...transformOptions(options)
|
|
1876
|
-
};
|
|
1877
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
1878
|
-
this.options.interpolation = {
|
|
1879
|
-
...defOpts.interpolation,
|
|
1880
|
-
...this.options.interpolation
|
|
1881
|
-
};
|
|
1882
|
-
}
|
|
1883
|
-
if (options.keySeparator !== undefined) {
|
|
1884
|
-
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
1885
|
-
}
|
|
1886
|
-
if (options.nsSeparator !== undefined) {
|
|
1887
|
-
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
1888
|
-
}
|
|
1889
|
-
function createClassOnDemand(ClassOrObject) {
|
|
1890
|
-
if (!ClassOrObject) return null;
|
|
1891
|
-
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
1892
|
-
return ClassOrObject;
|
|
1893
|
-
}
|
|
1894
|
-
if (!this.options.isClone) {
|
|
1895
|
-
if (this.modules.logger) {
|
|
1896
|
-
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
1897
|
-
} else {
|
|
1898
|
-
baseLogger.init(null, this.options);
|
|
1899
|
-
}
|
|
1900
|
-
let formatter;
|
|
1901
|
-
if (this.modules.formatter) {
|
|
1902
|
-
formatter = this.modules.formatter;
|
|
1903
|
-
} else if (typeof Intl !== 'undefined') {
|
|
1904
|
-
formatter = Formatter;
|
|
1905
|
-
}
|
|
1906
|
-
const lu = new LanguageUtil(this.options);
|
|
1907
|
-
this.store = new ResourceStore(this.options.resources, this.options);
|
|
1908
|
-
const s = this.services;
|
|
1909
|
-
s.logger = baseLogger;
|
|
1910
|
-
s.resourceStore = this.store;
|
|
1911
|
-
s.languageUtils = lu;
|
|
1912
|
-
s.pluralResolver = new PluralResolver(lu, {
|
|
1913
|
-
prepend: this.options.pluralSeparator,
|
|
1914
|
-
compatibilityJSON: this.options.compatibilityJSON,
|
|
1915
|
-
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1916
|
-
});
|
|
1917
|
-
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
1918
|
-
s.formatter = createClassOnDemand(formatter);
|
|
1919
|
-
s.formatter.init(s, this.options);
|
|
1920
|
-
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
1921
|
-
}
|
|
1922
|
-
s.interpolator = new Interpolator(this.options);
|
|
1923
|
-
s.utils = {
|
|
1924
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1925
|
-
};
|
|
1926
|
-
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
1927
|
-
s.backendConnector.on('*', function (event) {
|
|
1928
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1929
|
-
args[_key - 1] = arguments[_key];
|
|
1930
|
-
}
|
|
1931
|
-
_this.emit(event, ...args);
|
|
1932
|
-
});
|
|
1933
|
-
if (this.modules.languageDetector) {
|
|
1934
|
-
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
1935
|
-
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
1936
|
-
}
|
|
1937
|
-
if (this.modules.i18nFormat) {
|
|
1938
|
-
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
1939
|
-
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
1940
|
-
}
|
|
1941
|
-
this.translator = new Translator(this.services, this.options);
|
|
1942
|
-
this.translator.on('*', function (event) {
|
|
1943
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1944
|
-
args[_key2 - 1] = arguments[_key2];
|
|
1945
|
-
}
|
|
1946
|
-
_this.emit(event, ...args);
|
|
1947
|
-
});
|
|
1948
|
-
this.modules.external.forEach(m => {
|
|
1949
|
-
if (m.init) m.init(this);
|
|
1950
|
-
});
|
|
1951
|
-
}
|
|
1952
|
-
this.format = this.options.interpolation.format;
|
|
1953
|
-
if (!callback) callback = noop;
|
|
1954
|
-
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
1955
|
-
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1956
|
-
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
1957
|
-
}
|
|
1958
|
-
if (!this.services.languageDetector && !this.options.lng) {
|
|
1959
|
-
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
1960
|
-
}
|
|
1961
|
-
const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
1962
|
-
storeApi.forEach(fcName => {
|
|
1963
|
-
this[fcName] = function () {
|
|
1964
|
-
return _this.store[fcName](...arguments);
|
|
1965
|
-
};
|
|
1966
|
-
});
|
|
1967
|
-
const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
1968
|
-
storeApiChained.forEach(fcName => {
|
|
1969
|
-
this[fcName] = function () {
|
|
1970
|
-
_this.store[fcName](...arguments);
|
|
1971
|
-
return _this;
|
|
1972
|
-
};
|
|
1973
|
-
});
|
|
1974
|
-
const deferred = defer();
|
|
1975
|
-
const load = () => {
|
|
1976
|
-
const finish = (err, t) => {
|
|
1977
|
-
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
1978
|
-
this.isInitialized = true;
|
|
1979
|
-
if (!this.options.isClone) this.logger.log('initialized', this.options);
|
|
1980
|
-
this.emit('initialized', this.options);
|
|
1981
|
-
deferred.resolve(t);
|
|
1982
|
-
callback(err, t);
|
|
1983
|
-
};
|
|
1984
|
-
if (this.languages && this.options.compatibilityAPI !== 'v1' && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
1985
|
-
this.changeLanguage(this.options.lng, finish);
|
|
1986
|
-
};
|
|
1987
|
-
if (this.options.resources || !this.options.initImmediate) {
|
|
1988
|
-
load();
|
|
1989
|
-
} else {
|
|
1990
|
-
setTimeout(load, 0);
|
|
1991
|
-
}
|
|
1992
|
-
return deferred;
|
|
1993
|
-
}
|
|
1994
|
-
loadResources(language) {
|
|
1995
|
-
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
1996
|
-
let usedCallback = callback;
|
|
1997
|
-
const usedLng = typeof language === 'string' ? language : this.language;
|
|
1998
|
-
if (typeof language === 'function') usedCallback = language;
|
|
1999
|
-
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
2000
|
-
if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
|
|
2001
|
-
const toLoad = [];
|
|
2002
|
-
const append = lng => {
|
|
2003
|
-
if (!lng) return;
|
|
2004
|
-
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
2005
|
-
lngs.forEach(l => {
|
|
2006
|
-
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
2007
|
-
});
|
|
2008
|
-
};
|
|
2009
|
-
if (!usedLng) {
|
|
2010
|
-
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
2011
|
-
fallbacks.forEach(l => append(l));
|
|
2012
|
-
} else {
|
|
2013
|
-
append(usedLng);
|
|
2014
|
-
}
|
|
2015
|
-
if (this.options.preload) {
|
|
2016
|
-
this.options.preload.forEach(l => append(l));
|
|
2017
|
-
}
|
|
2018
|
-
this.services.backendConnector.load(toLoad, this.options.ns, e => {
|
|
2019
|
-
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
2020
|
-
usedCallback(e);
|
|
2021
|
-
});
|
|
2022
|
-
} else {
|
|
2023
|
-
usedCallback(null);
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
|
-
reloadResources(lngs, ns, callback) {
|
|
2027
|
-
const deferred = defer();
|
|
2028
|
-
if (!lngs) lngs = this.languages;
|
|
2029
|
-
if (!ns) ns = this.options.ns;
|
|
2030
|
-
if (!callback) callback = noop;
|
|
2031
|
-
this.services.backendConnector.reload(lngs, ns, err => {
|
|
2032
|
-
deferred.resolve();
|
|
2033
|
-
callback(err);
|
|
2034
|
-
});
|
|
2035
|
-
return deferred;
|
|
2036
|
-
}
|
|
2037
|
-
use(module) {
|
|
2038
|
-
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
2039
|
-
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
2040
|
-
if (module.type === 'backend') {
|
|
2041
|
-
this.modules.backend = module;
|
|
2042
|
-
}
|
|
2043
|
-
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
2044
|
-
this.modules.logger = module;
|
|
2045
|
-
}
|
|
2046
|
-
if (module.type === 'languageDetector') {
|
|
2047
|
-
this.modules.languageDetector = module;
|
|
2048
|
-
}
|
|
2049
|
-
if (module.type === 'i18nFormat') {
|
|
2050
|
-
this.modules.i18nFormat = module;
|
|
2051
|
-
}
|
|
2052
|
-
if (module.type === 'postProcessor') {
|
|
2053
|
-
postProcessor.addPostProcessor(module);
|
|
2054
|
-
}
|
|
2055
|
-
if (module.type === 'formatter') {
|
|
2056
|
-
this.modules.formatter = module;
|
|
2057
|
-
}
|
|
2058
|
-
if (module.type === '3rdParty') {
|
|
2059
|
-
this.modules.external.push(module);
|
|
2060
|
-
}
|
|
2061
|
-
return this;
|
|
2062
|
-
}
|
|
2063
|
-
setResolvedLanguage(l) {
|
|
2064
|
-
if (!l || !this.languages) return;
|
|
2065
|
-
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
2066
|
-
for (let li = 0; li < this.languages.length; li++) {
|
|
2067
|
-
const lngInLngs = this.languages[li];
|
|
2068
|
-
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
2069
|
-
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2070
|
-
this.resolvedLanguage = lngInLngs;
|
|
2071
|
-
break;
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
changeLanguage(lng, callback) {
|
|
2076
|
-
var _this2 = this;
|
|
2077
|
-
this.isLanguageChangingTo = lng;
|
|
2078
|
-
const deferred = defer();
|
|
2079
|
-
this.emit('languageChanging', lng);
|
|
2080
|
-
const setLngProps = l => {
|
|
2081
|
-
this.language = l;
|
|
2082
|
-
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2083
|
-
this.resolvedLanguage = undefined;
|
|
2084
|
-
this.setResolvedLanguage(l);
|
|
2085
|
-
};
|
|
2086
|
-
const done = (err, l) => {
|
|
2087
|
-
if (l) {
|
|
2088
|
-
setLngProps(l);
|
|
2089
|
-
this.translator.changeLanguage(l);
|
|
2090
|
-
this.isLanguageChangingTo = undefined;
|
|
2091
|
-
this.emit('languageChanged', l);
|
|
2092
|
-
this.logger.log('languageChanged', l);
|
|
2093
|
-
} else {
|
|
2094
|
-
this.isLanguageChangingTo = undefined;
|
|
2095
|
-
}
|
|
2096
|
-
deferred.resolve(function () {
|
|
2097
|
-
return _this2.t(...arguments);
|
|
2098
|
-
});
|
|
2099
|
-
if (callback) callback(err, function () {
|
|
2100
|
-
return _this2.t(...arguments);
|
|
2101
|
-
});
|
|
2102
|
-
};
|
|
2103
|
-
const setLng = lngs => {
|
|
2104
|
-
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2105
|
-
const l = typeof lngs === 'string' ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2106
|
-
if (l) {
|
|
2107
|
-
if (!this.language) {
|
|
2108
|
-
setLngProps(l);
|
|
2109
|
-
}
|
|
2110
|
-
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
2111
|
-
if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
|
|
2112
|
-
}
|
|
2113
|
-
this.loadResources(l, err => {
|
|
2114
|
-
done(err, l);
|
|
2115
|
-
});
|
|
2116
|
-
};
|
|
2117
|
-
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2118
|
-
setLng(this.services.languageDetector.detect());
|
|
2119
|
-
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2120
|
-
if (this.services.languageDetector.detect.length === 0) {
|
|
2121
|
-
this.services.languageDetector.detect().then(setLng);
|
|
2122
|
-
} else {
|
|
2123
|
-
this.services.languageDetector.detect(setLng);
|
|
2124
|
-
}
|
|
2125
|
-
} else {
|
|
2126
|
-
setLng(lng);
|
|
2127
|
-
}
|
|
2128
|
-
return deferred;
|
|
2129
|
-
}
|
|
2130
|
-
getFixedT(lng, ns, keyPrefix) {
|
|
2131
|
-
var _this3 = this;
|
|
2132
|
-
const fixedT = function (key, opts) {
|
|
2133
|
-
let options;
|
|
2134
|
-
if (typeof opts !== 'object') {
|
|
2135
|
-
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2136
|
-
rest[_key3 - 2] = arguments[_key3];
|
|
2137
|
-
}
|
|
2138
|
-
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2139
|
-
} else {
|
|
2140
|
-
options = {
|
|
2141
|
-
...opts
|
|
2142
|
-
};
|
|
2143
|
-
}
|
|
2144
|
-
options.lng = options.lng || fixedT.lng;
|
|
2145
|
-
options.lngs = options.lngs || fixedT.lngs;
|
|
2146
|
-
options.ns = options.ns || fixedT.ns;
|
|
2147
|
-
options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2148
|
-
const keySeparator = _this3.options.keySeparator || '.';
|
|
2149
|
-
let resultKey;
|
|
2150
|
-
if (options.keyPrefix && Array.isArray(key)) {
|
|
2151
|
-
resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
|
|
2152
|
-
} else {
|
|
2153
|
-
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
2154
|
-
}
|
|
2155
|
-
return _this3.t(resultKey, options);
|
|
2156
|
-
};
|
|
2157
|
-
if (typeof lng === 'string') {
|
|
2158
|
-
fixedT.lng = lng;
|
|
2159
|
-
} else {
|
|
2160
|
-
fixedT.lngs = lng;
|
|
2161
|
-
}
|
|
2162
|
-
fixedT.ns = ns;
|
|
2163
|
-
fixedT.keyPrefix = keyPrefix;
|
|
2164
|
-
return fixedT;
|
|
2165
|
-
}
|
|
2166
|
-
t() {
|
|
2167
|
-
return this.translator && this.translator.translate(...arguments);
|
|
2168
|
-
}
|
|
2169
|
-
exists() {
|
|
2170
|
-
return this.translator && this.translator.exists(...arguments);
|
|
2171
|
-
}
|
|
2172
|
-
setDefaultNamespace(ns) {
|
|
2173
|
-
this.options.defaultNS = ns;
|
|
2174
|
-
}
|
|
2175
|
-
hasLoadedNamespace(ns) {
|
|
2176
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2177
|
-
if (!this.isInitialized) {
|
|
2178
|
-
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
2179
|
-
return false;
|
|
2180
|
-
}
|
|
2181
|
-
if (!this.languages || !this.languages.length) {
|
|
2182
|
-
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
2183
|
-
return false;
|
|
2184
|
-
}
|
|
2185
|
-
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2186
|
-
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2187
|
-
const lastLng = this.languages[this.languages.length - 1];
|
|
2188
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
2189
|
-
const loadNotPending = (l, n) => {
|
|
2190
|
-
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2191
|
-
return loadState === -1 || loadState === 2;
|
|
2192
|
-
};
|
|
2193
|
-
if (options.precheck) {
|
|
2194
|
-
const preResult = options.precheck(this, loadNotPending);
|
|
2195
|
-
if (preResult !== undefined) return preResult;
|
|
2196
|
-
}
|
|
2197
|
-
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2198
|
-
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2199
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2200
|
-
return false;
|
|
2201
|
-
}
|
|
2202
|
-
loadNamespaces(ns, callback) {
|
|
2203
|
-
const deferred = defer();
|
|
2204
|
-
if (!this.options.ns) {
|
|
2205
|
-
if (callback) callback();
|
|
2206
|
-
return Promise.resolve();
|
|
2207
|
-
}
|
|
2208
|
-
if (typeof ns === 'string') ns = [ns];
|
|
2209
|
-
ns.forEach(n => {
|
|
2210
|
-
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
2211
|
-
});
|
|
2212
|
-
this.loadResources(err => {
|
|
2213
|
-
deferred.resolve();
|
|
2214
|
-
if (callback) callback(err);
|
|
2215
|
-
});
|
|
2216
|
-
return deferred;
|
|
2217
|
-
}
|
|
2218
|
-
loadLanguages(lngs, callback) {
|
|
2219
|
-
const deferred = defer();
|
|
2220
|
-
if (typeof lngs === 'string') lngs = [lngs];
|
|
2221
|
-
const preloaded = this.options.preload || [];
|
|
2222
|
-
const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0);
|
|
2223
|
-
if (!newLngs.length) {
|
|
2224
|
-
if (callback) callback();
|
|
2225
|
-
return Promise.resolve();
|
|
2226
|
-
}
|
|
2227
|
-
this.options.preload = preloaded.concat(newLngs);
|
|
2228
|
-
this.loadResources(err => {
|
|
2229
|
-
deferred.resolve();
|
|
2230
|
-
if (callback) callback(err);
|
|
2231
|
-
});
|
|
2232
|
-
return deferred;
|
|
2233
|
-
}
|
|
2234
|
-
dir(lng) {
|
|
2235
|
-
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
2236
|
-
if (!lng) return 'rtl';
|
|
2237
|
-
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'];
|
|
2238
|
-
const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
2239
|
-
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
2240
|
-
}
|
|
2241
|
-
static createInstance() {
|
|
2242
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2243
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
2244
|
-
return new I18n(options, callback);
|
|
2245
|
-
}
|
|
2246
|
-
cloneInstance() {
|
|
2247
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2248
|
-
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
2249
|
-
const forkResourceStore = options.forkResourceStore;
|
|
2250
|
-
if (forkResourceStore) delete options.forkResourceStore;
|
|
2251
|
-
const mergedOptions = {
|
|
2252
|
-
...this.options,
|
|
2253
|
-
...options,
|
|
2254
|
-
...{
|
|
2255
|
-
isClone: true
|
|
2256
|
-
}
|
|
2257
|
-
};
|
|
2258
|
-
const clone = new I18n(mergedOptions);
|
|
2259
|
-
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
2260
|
-
clone.logger = clone.logger.clone(options);
|
|
2261
|
-
}
|
|
2262
|
-
const membersToCopy = ['store', 'services', 'language'];
|
|
2263
|
-
membersToCopy.forEach(m => {
|
|
2264
|
-
clone[m] = this[m];
|
|
2265
|
-
});
|
|
2266
|
-
clone.services = {
|
|
2267
|
-
...this.services
|
|
2268
|
-
};
|
|
2269
|
-
clone.services.utils = {
|
|
2270
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2271
|
-
};
|
|
2272
|
-
if (forkResourceStore) {
|
|
2273
|
-
clone.store = new ResourceStore(this.store.data, mergedOptions);
|
|
2274
|
-
clone.services.resourceStore = clone.store;
|
|
2275
|
-
}
|
|
2276
|
-
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2277
|
-
clone.translator.on('*', function (event) {
|
|
2278
|
-
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
2279
|
-
args[_key4 - 1] = arguments[_key4];
|
|
2280
|
-
}
|
|
2281
|
-
clone.emit(event, ...args);
|
|
2282
|
-
});
|
|
2283
|
-
clone.init(mergedOptions, callback);
|
|
2284
|
-
clone.translator.options = mergedOptions;
|
|
2285
|
-
clone.translator.backendConnector.services.utils = {
|
|
2286
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2287
|
-
};
|
|
2288
|
-
return clone;
|
|
2289
|
-
}
|
|
2290
|
-
toJSON() {
|
|
2291
|
-
return {
|
|
2292
|
-
options: this.options,
|
|
2293
|
-
store: this.store,
|
|
2294
|
-
language: this.language,
|
|
2295
|
-
languages: this.languages,
|
|
2296
|
-
resolvedLanguage: this.resolvedLanguage
|
|
2297
|
-
};
|
|
2298
|
-
}
|
|
2299
|
-
}
|
|
2300
|
-
const instance = I18n.createInstance();
|
|
2301
|
-
instance.createInstance = I18n.createInstance;
|
|
2302
|
-
|
|
2303
|
-
instance.createInstance;
|
|
2304
|
-
instance.dir;
|
|
2305
|
-
instance.init;
|
|
2306
|
-
instance.loadResources;
|
|
2307
|
-
instance.reloadResources;
|
|
2308
|
-
instance.use;
|
|
2309
|
-
instance.changeLanguage;
|
|
2310
|
-
instance.getFixedT;
|
|
2311
|
-
const t$2 = instance.t;
|
|
2312
|
-
instance.exists;
|
|
2313
|
-
instance.setDefaultNamespace;
|
|
2314
|
-
instance.hasLoadedNamespace;
|
|
2315
|
-
instance.loadNamespaces;
|
|
2316
|
-
instance.loadLanguages;
|
|
2317
|
-
|
|
2318
|
-
function getDefaultExportFromCjs (x) {
|
|
2319
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
2320
|
-
}
|
|
2321
|
-
|
|
2322
|
-
/**
|
|
2323
|
-
* This file automatically generated from `pre-publish.js`.
|
|
2324
|
-
* Do not manually edit.
|
|
2325
|
-
*/
|
|
2326
|
-
|
|
2327
|
-
var voidElements = {
|
|
2328
|
-
"area": true,
|
|
2329
|
-
"base": true,
|
|
2330
|
-
"br": true,
|
|
2331
|
-
"col": true,
|
|
2332
|
-
"embed": true,
|
|
2333
|
-
"hr": true,
|
|
2334
|
-
"img": true,
|
|
2335
|
-
"input": true,
|
|
2336
|
-
"link": true,
|
|
2337
|
-
"meta": true,
|
|
2338
|
-
"param": true,
|
|
2339
|
-
"source": true,
|
|
2340
|
-
"track": true,
|
|
2341
|
-
"wbr": true
|
|
2342
|
-
};
|
|
2343
|
-
|
|
2344
|
-
var e$1 = /*@__PURE__*/getDefaultExportFromCjs(voidElements);
|
|
2345
|
-
|
|
2346
|
-
var t$1=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n$1(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(e$1[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t$1),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i=/^\s*$/,s=Object.create(null);function a(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c={parse:function(e,t){t||(t={}),t.components||(t.components=s);var a,c=[],o=[],l=-1,m=!1;if(0!==e.indexOf("<")){var u=e.indexOf("<");c.push({type:"text",content:-1===u?e:e.substring(0,u)});}return e.replace(r,function(r,s){if(m){if(r!=="</"+a.name+">")return;m=!1;}var u,f="/"!==r.charAt(1),h=r.startsWith("\x3c!--"),p=s+r.length,d=e.charAt(p);if(h){var v=n$1(r);return l<0?(c.push(v),c):((u=o[l]).children.push(v),c)}if(f&&(l++,"tag"===(a=n$1(r)).type&&t.components[a.name]&&(a.type="component",m=!0),a.voidElement||m||!d||"<"===d||a.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===l&&c.push(a),(u=o[l-1])&&u.children.push(a),o[l]=a),(!f||a.voidElement)&&(l>-1&&(a.voidElement||a.name===r.slice(2,-1))&&(l--,a=-1===l?c:o[l]),!m&&"<"!==d&&d)){u=-1===l?c:o[l].children;var x=e.indexOf("<",p),g=e.slice(p,-1===x?void 0:x);i.test(g)&&(g=" "),(x>-1&&l+u.length>=0||" "!==g)&&u.push({type:"text",content:g});}}),c},stringify:function(e){return e.reduce(function(e,t){return e+a("",t)},"")}};
|
|
2347
|
-
|
|
2348
|
-
function warn() {
|
|
2349
|
-
if (console && console.warn) {
|
|
2350
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2351
|
-
args[_key] = arguments[_key];
|
|
2352
|
-
}
|
|
2353
|
-
if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`;
|
|
2354
|
-
console.warn(...args);
|
|
2355
|
-
}
|
|
2356
|
-
}
|
|
2357
|
-
const alreadyWarned = {};
|
|
2358
|
-
function warnOnce() {
|
|
2359
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2360
|
-
args[_key2] = arguments[_key2];
|
|
2361
|
-
}
|
|
2362
|
-
if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
|
|
2363
|
-
if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
|
|
2364
|
-
warn(...args);
|
|
2365
|
-
}
|
|
2366
|
-
const loadedClb = (i18n, cb) => () => {
|
|
2367
|
-
if (i18n.isInitialized) {
|
|
2368
|
-
cb();
|
|
2369
|
-
} else {
|
|
2370
|
-
const initialized = () => {
|
|
2371
|
-
setTimeout(() => {
|
|
2372
|
-
i18n.off('initialized', initialized);
|
|
2373
|
-
}, 0);
|
|
2374
|
-
cb();
|
|
2375
|
-
};
|
|
2376
|
-
i18n.on('initialized', initialized);
|
|
2377
|
-
}
|
|
2378
|
-
};
|
|
2379
|
-
function loadNamespaces(i18n, ns, cb) {
|
|
2380
|
-
i18n.loadNamespaces(ns, loadedClb(i18n, cb));
|
|
2381
|
-
}
|
|
2382
|
-
function loadLanguages(i18n, lng, ns, cb) {
|
|
2383
|
-
if (typeof ns === 'string') ns = [ns];
|
|
2384
|
-
ns.forEach(n => {
|
|
2385
|
-
if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
|
|
2386
|
-
});
|
|
2387
|
-
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
2388
|
-
}
|
|
2389
|
-
function oldI18nextHasLoadedNamespace(ns, i18n) {
|
|
2390
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2391
|
-
const lng = i18n.languages[0];
|
|
2392
|
-
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
|
|
2393
|
-
const lastLng = i18n.languages[i18n.languages.length - 1];
|
|
2394
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
2395
|
-
const loadNotPending = (l, n) => {
|
|
2396
|
-
const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
|
|
2397
|
-
return loadState === -1 || loadState === 2;
|
|
2398
|
-
};
|
|
2399
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
|
|
2400
|
-
if (i18n.hasResourceBundle(lng, ns)) return true;
|
|
2401
|
-
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
|
|
2402
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2403
|
-
return false;
|
|
2404
|
-
}
|
|
2405
|
-
function hasLoadedNamespace(ns, i18n) {
|
|
2406
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2407
|
-
if (!i18n.languages || !i18n.languages.length) {
|
|
2408
|
-
warnOnce('i18n.languages were undefined or empty', i18n.languages);
|
|
2409
|
-
return true;
|
|
2410
|
-
}
|
|
2411
|
-
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
|
|
2412
|
-
if (!isNewerI18next) {
|
|
2413
|
-
return oldI18nextHasLoadedNamespace(ns, i18n, options);
|
|
2414
|
-
}
|
|
2415
|
-
return i18n.hasLoadedNamespace(ns, {
|
|
2416
|
-
lng: options.lng,
|
|
2417
|
-
precheck: (i18nInstance, loadNotPending) => {
|
|
2418
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
|
|
2419
|
-
}
|
|
2420
|
-
});
|
|
2421
|
-
}
|
|
2422
|
-
|
|
2423
|
-
const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
2424
|
-
const htmlEntities = {
|
|
2425
|
-
'&': '&',
|
|
2426
|
-
'&': '&',
|
|
2427
|
-
'<': '<',
|
|
2428
|
-
'<': '<',
|
|
2429
|
-
'>': '>',
|
|
2430
|
-
'>': '>',
|
|
2431
|
-
''': "'",
|
|
2432
|
-
''': "'",
|
|
2433
|
-
'"': '"',
|
|
2434
|
-
'"': '"',
|
|
2435
|
-
' ': ' ',
|
|
2436
|
-
' ': ' ',
|
|
2437
|
-
'©': '©',
|
|
2438
|
-
'©': '©',
|
|
2439
|
-
'®': '®',
|
|
2440
|
-
'®': '®',
|
|
2441
|
-
'…': '…',
|
|
2442
|
-
'…': '…',
|
|
2443
|
-
'/': '/',
|
|
2444
|
-
'/': '/'
|
|
2445
|
-
};
|
|
2446
|
-
const unescapeHtmlEntity = m => htmlEntities[m];
|
|
2447
|
-
const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
|
|
2448
|
-
|
|
2449
|
-
let defaultOptions = {
|
|
2450
|
-
bindI18n: 'languageChanged',
|
|
2451
|
-
bindI18nStore: '',
|
|
2452
|
-
transEmptyNodeValue: '',
|
|
2453
|
-
transSupportBasicHtmlNodes: true,
|
|
2454
|
-
transWrapTextNodes: '',
|
|
2455
|
-
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
2456
|
-
useSuspense: true,
|
|
2457
|
-
unescape
|
|
2458
|
-
};
|
|
2459
|
-
function setDefaults() {
|
|
2460
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2461
|
-
defaultOptions = {
|
|
2462
|
-
...defaultOptions,
|
|
2463
|
-
...options
|
|
2464
|
-
};
|
|
2465
|
-
}
|
|
2466
|
-
function getDefaults() {
|
|
2467
|
-
return defaultOptions;
|
|
2468
|
-
}
|
|
2469
|
-
|
|
2470
|
-
let i18nInstance;
|
|
2471
|
-
function setI18n(instance) {
|
|
2472
|
-
i18nInstance = instance;
|
|
2473
|
-
}
|
|
2474
|
-
function getI18n() {
|
|
2475
|
-
return i18nInstance;
|
|
2476
|
-
}
|
|
2477
|
-
|
|
2478
|
-
function hasChildren(node, checkLength) {
|
|
2479
|
-
if (!node) return false;
|
|
2480
|
-
const base = node.props ? node.props.children : node.children;
|
|
2481
|
-
if (checkLength) return base.length > 0;
|
|
2482
|
-
return !!base;
|
|
2483
|
-
}
|
|
2484
|
-
function getChildren(node) {
|
|
2485
|
-
if (!node) return [];
|
|
2486
|
-
return node.props ? node.props.children : node.children;
|
|
2487
|
-
}
|
|
2488
|
-
function hasValidReactChildren(children) {
|
|
2489
|
-
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
2490
|
-
return children.every(child => React.isValidElement(child));
|
|
2491
|
-
}
|
|
2492
|
-
function getAsArray(data) {
|
|
2493
|
-
return Array.isArray(data) ? data : [data];
|
|
2494
|
-
}
|
|
2495
|
-
function mergeProps(source, target) {
|
|
2496
|
-
const newTarget = {
|
|
2497
|
-
...target
|
|
2498
|
-
};
|
|
2499
|
-
newTarget.props = Object.assign(source.props, target.props);
|
|
2500
|
-
return newTarget;
|
|
2501
|
-
}
|
|
2502
|
-
function nodesToString(children, i18nOptions) {
|
|
2503
|
-
if (!children) return '';
|
|
2504
|
-
let stringNode = '';
|
|
2505
|
-
const childrenArray = getAsArray(children);
|
|
2506
|
-
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
|
|
2507
|
-
childrenArray.forEach((child, childIndex) => {
|
|
2508
|
-
if (typeof child === 'string') {
|
|
2509
|
-
stringNode += `${child}`;
|
|
2510
|
-
} else if (React.isValidElement(child)) {
|
|
2511
|
-
const childPropsCount = Object.keys(child.props).length;
|
|
2512
|
-
const shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
2513
|
-
const childChildren = child.props.children;
|
|
2514
|
-
if (!childChildren && shouldKeepChild && childPropsCount === 0) {
|
|
2515
|
-
stringNode += `<${child.type}/>`;
|
|
2516
|
-
} else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
|
|
2517
|
-
stringNode += `<${childIndex}></${childIndex}>`;
|
|
2518
|
-
} else if (child.props.i18nIsDynamicList) {
|
|
2519
|
-
stringNode += `<${childIndex}></${childIndex}>`;
|
|
2520
|
-
} else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
|
|
2521
|
-
stringNode += `<${child.type}>${childChildren}</${child.type}>`;
|
|
2522
|
-
} else {
|
|
2523
|
-
const content = nodesToString(childChildren, i18nOptions);
|
|
2524
|
-
stringNode += `<${childIndex}>${content}</${childIndex}>`;
|
|
2525
|
-
}
|
|
2526
|
-
} else if (child === null) {
|
|
2527
|
-
warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
|
|
2528
|
-
} else if (typeof child === 'object') {
|
|
2529
|
-
const {
|
|
2530
|
-
format,
|
|
2531
|
-
...clone
|
|
2532
|
-
} = child;
|
|
2533
|
-
const keys = Object.keys(clone);
|
|
2534
|
-
if (keys.length === 1) {
|
|
2535
|
-
const value = format ? `${keys[0]}, ${format}` : keys[0];
|
|
2536
|
-
stringNode += `{{${value}}}`;
|
|
2537
|
-
} else {
|
|
2538
|
-
warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
|
|
2539
|
-
}
|
|
2540
|
-
} else {
|
|
2541
|
-
warn(`Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.`, child);
|
|
2542
|
-
}
|
|
2543
|
-
});
|
|
2544
|
-
return stringNode;
|
|
2545
|
-
}
|
|
2546
|
-
function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
|
|
2547
|
-
if (targetString === '') return [];
|
|
2548
|
-
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
2549
|
-
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
|
|
2550
|
-
if (!children && !emptyChildrenButNeedsHandling) return [targetString];
|
|
2551
|
-
const data = {};
|
|
2552
|
-
function getData(childs) {
|
|
2553
|
-
const childrenArray = getAsArray(childs);
|
|
2554
|
-
childrenArray.forEach(child => {
|
|
2555
|
-
if (typeof child === 'string') return;
|
|
2556
|
-
if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !React.isValidElement(child)) Object.assign(data, child);
|
|
2557
|
-
});
|
|
2558
|
-
}
|
|
2559
|
-
getData(children);
|
|
2560
|
-
const ast = c.parse(`<0>${targetString}</0>`);
|
|
2561
|
-
const opts = {
|
|
2562
|
-
...data,
|
|
2563
|
-
...combinedTOpts
|
|
2564
|
-
};
|
|
2565
|
-
function renderInner(child, node, rootReactNode) {
|
|
2566
|
-
const childs = getChildren(child);
|
|
2567
|
-
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
2568
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
|
|
2569
|
-
}
|
|
2570
|
-
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
2571
|
-
if (child.dummy) child.children = inner;
|
|
2572
|
-
mem.push(React.cloneElement(child, {
|
|
2573
|
-
...child.props,
|
|
2574
|
-
key: i
|
|
2575
|
-
}, isVoid ? undefined : inner));
|
|
2576
|
-
}
|
|
2577
|
-
function mapAST(reactNode, astNode, rootReactNode) {
|
|
2578
|
-
const reactNodes = getAsArray(reactNode);
|
|
2579
|
-
const astNodes = getAsArray(astNode);
|
|
2580
|
-
return astNodes.reduce((mem, node, i) => {
|
|
2581
|
-
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
2582
|
-
if (node.type === 'tag') {
|
|
2583
|
-
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
2584
|
-
if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
|
|
2585
|
-
if (!tmp) tmp = {};
|
|
2586
|
-
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
2587
|
-
props: node.attrs
|
|
2588
|
-
}, tmp) : tmp;
|
|
2589
|
-
const isElement = React.isValidElement(child);
|
|
2590
|
-
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
2591
|
-
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
|
|
2592
|
-
const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
2593
|
-
if (typeof child === 'string') {
|
|
2594
|
-
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
2595
|
-
mem.push(value);
|
|
2596
|
-
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
2597
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
2598
|
-
pushTranslatedJSX(child, inner, mem, i);
|
|
2599
|
-
} else if (isEmptyTransWithHTML) {
|
|
2600
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2601
|
-
mem.push(React.cloneElement(child, {
|
|
2602
|
-
...child.props,
|
|
2603
|
-
key: i
|
|
2604
|
-
}, inner));
|
|
2605
|
-
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
2606
|
-
if (isKnownComponent) {
|
|
2607
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
2608
|
-
pushTranslatedJSX(child, inner, mem, i, node.voidElement);
|
|
2609
|
-
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
2610
|
-
if (node.voidElement) {
|
|
2611
|
-
mem.push(React.createElement(node.name, {
|
|
2612
|
-
key: `${node.name}-${i}`
|
|
2613
|
-
}));
|
|
2614
|
-
} else {
|
|
2615
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2616
|
-
mem.push(React.createElement(node.name, {
|
|
2617
|
-
key: `${node.name}-${i}`
|
|
2618
|
-
}, inner));
|
|
2619
|
-
}
|
|
2620
|
-
} else if (node.voidElement) {
|
|
2621
|
-
mem.push(`<${node.name} />`);
|
|
2622
|
-
} else {
|
|
2623
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2624
|
-
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
2625
|
-
}
|
|
2626
|
-
} else if (typeof child === 'object' && !isElement) {
|
|
2627
|
-
const content = node.children[0] ? translationContent : null;
|
|
2628
|
-
if (content) mem.push(content);
|
|
2629
|
-
} else if (node.children.length === 1 && translationContent) {
|
|
2630
|
-
mem.push(React.cloneElement(child, {
|
|
2631
|
-
...child.props,
|
|
2632
|
-
key: i
|
|
2633
|
-
}, translationContent));
|
|
2634
|
-
} else {
|
|
2635
|
-
mem.push(React.cloneElement(child, {
|
|
2636
|
-
...child.props,
|
|
2637
|
-
key: i
|
|
2638
|
-
}));
|
|
2639
|
-
}
|
|
2640
|
-
} else if (node.type === 'text') {
|
|
2641
|
-
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
2642
|
-
const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
2643
|
-
if (wrapTextNodes) {
|
|
2644
|
-
mem.push(React.createElement(wrapTextNodes, {
|
|
2645
|
-
key: `${node.name}-${i}`
|
|
2646
|
-
}, content));
|
|
2647
|
-
} else {
|
|
2648
|
-
mem.push(content);
|
|
2649
|
-
}
|
|
2650
|
-
}
|
|
2651
|
-
return mem;
|
|
2652
|
-
}, []);
|
|
2653
|
-
}
|
|
2654
|
-
const result = mapAST([{
|
|
2655
|
-
dummy: true,
|
|
2656
|
-
children: children || []
|
|
2657
|
-
}], ast, getAsArray(children || []));
|
|
2658
|
-
return getChildren(result[0]);
|
|
2659
|
-
}
|
|
2660
|
-
function Trans$1(_ref) {
|
|
2661
|
-
let {
|
|
2662
|
-
children,
|
|
2663
|
-
count,
|
|
2664
|
-
parent,
|
|
2665
|
-
i18nKey,
|
|
2666
|
-
context,
|
|
2667
|
-
tOptions = {},
|
|
2668
|
-
values,
|
|
2669
|
-
defaults,
|
|
2670
|
-
components,
|
|
2671
|
-
ns,
|
|
2672
|
-
i18n: i18nFromProps,
|
|
2673
|
-
t: tFromProps,
|
|
2674
|
-
shouldUnescape,
|
|
2675
|
-
...additionalProps
|
|
2676
|
-
} = _ref;
|
|
2677
|
-
const i18n = i18nFromProps || getI18n();
|
|
2678
|
-
if (!i18n) {
|
|
2679
|
-
warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
|
|
2680
|
-
return children;
|
|
2681
|
-
}
|
|
2682
|
-
const t = tFromProps || i18n.t.bind(i18n) || (k => k);
|
|
2683
|
-
if (context) tOptions.context = context;
|
|
2684
|
-
const reactI18nextOptions = {
|
|
2685
|
-
...getDefaults(),
|
|
2686
|
-
...(i18n.options && i18n.options.react)
|
|
2687
|
-
};
|
|
2688
|
-
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
|
|
2689
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
2690
|
-
const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
2691
|
-
const {
|
|
2692
|
-
hashTransKey
|
|
2693
|
-
} = reactI18nextOptions;
|
|
2694
|
-
const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
|
|
2695
|
-
const interpolationOverride = values ? tOptions.interpolation : {
|
|
2696
|
-
interpolation: {
|
|
2697
|
-
...tOptions.interpolation,
|
|
2698
|
-
prefix: '#$?',
|
|
2699
|
-
suffix: '?$#'
|
|
2700
|
-
}
|
|
2701
|
-
};
|
|
2702
|
-
const combinedTOpts = {
|
|
2703
|
-
...tOptions,
|
|
2704
|
-
count,
|
|
2705
|
-
...values,
|
|
2706
|
-
...interpolationOverride,
|
|
2707
|
-
defaultValue,
|
|
2708
|
-
ns: namespaces
|
|
2709
|
-
};
|
|
2710
|
-
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
2711
|
-
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
2712
|
-
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
2713
|
-
return useAsParent ? React.createElement(useAsParent, additionalProps, content) : content;
|
|
2714
|
-
}
|
|
2715
|
-
|
|
2716
|
-
const initReactI18next = {
|
|
2717
|
-
type: '3rdParty',
|
|
2718
|
-
init(instance) {
|
|
2719
|
-
setDefaults(instance.options.react);
|
|
2720
|
-
setI18n(instance);
|
|
2721
|
-
}
|
|
2722
157
|
};
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
class ReportNamespaces {
|
|
2726
|
-
constructor() {
|
|
2727
|
-
this.usedNamespaces = {};
|
|
2728
|
-
}
|
|
2729
|
-
addUsedNamespaces(namespaces) {
|
|
2730
|
-
namespaces.forEach(ns => {
|
|
2731
|
-
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
2732
|
-
});
|
|
2733
|
-
}
|
|
2734
|
-
getUsedNamespaces() {
|
|
2735
|
-
return Object.keys(this.usedNamespaces);
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
|
|
2739
|
-
function Trans(_ref) {
|
|
2740
|
-
let {
|
|
2741
|
-
children,
|
|
2742
|
-
count,
|
|
2743
|
-
parent,
|
|
2744
|
-
i18nKey,
|
|
2745
|
-
context,
|
|
2746
|
-
tOptions = {},
|
|
2747
|
-
values,
|
|
2748
|
-
defaults,
|
|
2749
|
-
components,
|
|
2750
|
-
ns,
|
|
2751
|
-
i18n: i18nFromProps,
|
|
2752
|
-
t: tFromProps,
|
|
2753
|
-
shouldUnescape,
|
|
2754
|
-
...additionalProps
|
|
2755
|
-
} = _ref;
|
|
2756
|
-
const {
|
|
2757
|
-
i18n: i18nFromContext,
|
|
2758
|
-
defaultNS: defaultNSFromContext
|
|
2759
|
-
} = React.useContext(I18nContext) || {};
|
|
2760
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
2761
|
-
const t = tFromProps || i18n && i18n.t.bind(i18n);
|
|
2762
|
-
return Trans$1({
|
|
2763
|
-
children,
|
|
2764
|
-
count,
|
|
2765
|
-
parent,
|
|
2766
|
-
i18nKey,
|
|
2767
|
-
context,
|
|
2768
|
-
tOptions,
|
|
2769
|
-
values,
|
|
2770
|
-
defaults,
|
|
2771
|
-
components,
|
|
2772
|
-
ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
|
|
2773
|
-
i18n,
|
|
2774
|
-
t: tFromProps,
|
|
2775
|
-
shouldUnescape,
|
|
2776
|
-
...additionalProps
|
|
2777
|
-
});
|
|
2778
|
-
}
|
|
2779
|
-
|
|
2780
|
-
const usePrevious = (value, ignore) => {
|
|
2781
|
-
const ref = React.useRef();
|
|
2782
|
-
React.useEffect(() => {
|
|
2783
|
-
ref.current = ignore ? ref.current : value;
|
|
2784
|
-
}, [value, ignore]);
|
|
2785
|
-
return ref.current;
|
|
2786
|
-
};
|
|
2787
|
-
function useTranslation(ns) {
|
|
2788
|
-
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2789
|
-
const {
|
|
2790
|
-
i18n: i18nFromProps
|
|
2791
|
-
} = props;
|
|
2792
|
-
const {
|
|
2793
|
-
i18n: i18nFromContext,
|
|
2794
|
-
defaultNS: defaultNSFromContext
|
|
2795
|
-
} = React.useContext(I18nContext) || {};
|
|
2796
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
2797
|
-
if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
|
|
2798
|
-
if (!i18n) {
|
|
2799
|
-
warnOnce('You will need to pass in an i18next instance by using initReactI18next');
|
|
2800
|
-
const notReadyT = (k, optsOrDefaultValue) => {
|
|
2801
|
-
if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
|
|
2802
|
-
if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
|
|
2803
|
-
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
2804
|
-
};
|
|
2805
|
-
const retNotReady = [notReadyT, {}, false];
|
|
2806
|
-
retNotReady.t = notReadyT;
|
|
2807
|
-
retNotReady.i18n = {};
|
|
2808
|
-
retNotReady.ready = false;
|
|
2809
|
-
return retNotReady;
|
|
2810
|
-
}
|
|
2811
|
-
if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
|
|
2812
|
-
const i18nOptions = {
|
|
2813
|
-
...getDefaults(),
|
|
2814
|
-
...i18n.options.react,
|
|
2815
|
-
...props
|
|
2816
|
-
};
|
|
2817
|
-
const {
|
|
2818
|
-
useSuspense,
|
|
2819
|
-
keyPrefix
|
|
2820
|
-
} = i18nOptions;
|
|
2821
|
-
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
2822
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
2823
|
-
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
2824
|
-
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
|
|
2825
|
-
function getT() {
|
|
2826
|
-
return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
2827
|
-
}
|
|
2828
|
-
const [t, setT] = React.useState(getT);
|
|
2829
|
-
let joinedNS = namespaces.join();
|
|
2830
|
-
if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
|
|
2831
|
-
const previousJoinedNS = usePrevious(joinedNS);
|
|
2832
|
-
const isMounted = React.useRef(true);
|
|
2833
|
-
React.useEffect(() => {
|
|
2834
|
-
const {
|
|
2835
|
-
bindI18n,
|
|
2836
|
-
bindI18nStore
|
|
2837
|
-
} = i18nOptions;
|
|
2838
|
-
isMounted.current = true;
|
|
2839
|
-
if (!ready && !useSuspense) {
|
|
2840
|
-
if (props.lng) {
|
|
2841
|
-
loadLanguages(i18n, props.lng, namespaces, () => {
|
|
2842
|
-
if (isMounted.current) setT(getT);
|
|
2843
|
-
});
|
|
2844
|
-
} else {
|
|
2845
|
-
loadNamespaces(i18n, namespaces, () => {
|
|
2846
|
-
if (isMounted.current) setT(getT);
|
|
2847
|
-
});
|
|
2848
|
-
}
|
|
2849
|
-
}
|
|
2850
|
-
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
2851
|
-
setT(getT);
|
|
2852
|
-
}
|
|
2853
|
-
function boundReset() {
|
|
2854
|
-
if (isMounted.current) setT(getT);
|
|
2855
|
-
}
|
|
2856
|
-
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
|
|
2857
|
-
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
2858
|
-
return () => {
|
|
2859
|
-
isMounted.current = false;
|
|
2860
|
-
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
|
|
2861
|
-
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
|
|
2862
|
-
};
|
|
2863
|
-
}, [i18n, joinedNS]);
|
|
2864
|
-
const isInitial = React.useRef(true);
|
|
2865
|
-
React.useEffect(() => {
|
|
2866
|
-
if (isMounted.current && !isInitial.current) {
|
|
2867
|
-
setT(getT);
|
|
2868
|
-
}
|
|
2869
|
-
isInitial.current = false;
|
|
2870
|
-
}, [i18n, keyPrefix]);
|
|
2871
|
-
const ret = [t, i18n, ready];
|
|
2872
|
-
ret.t = t;
|
|
2873
|
-
ret.i18n = i18n;
|
|
2874
|
-
ret.ready = ready;
|
|
2875
|
-
if (ready) return ret;
|
|
2876
|
-
if (!ready && !useSuspense) return ret;
|
|
2877
|
-
throw new Promise(resolve => {
|
|
2878
|
-
if (props.lng) {
|
|
2879
|
-
loadLanguages(i18n, props.lng, namespaces, () => resolve());
|
|
2880
|
-
} else {
|
|
2881
|
-
loadNamespaces(i18n, namespaces, () => resolve());
|
|
2882
|
-
}
|
|
2883
|
-
});
|
|
2884
|
-
}
|
|
2885
|
-
|
|
2886
|
-
var entity = {
|
|
2887
|
-
webhook: "webhook",
|
|
2888
|
-
configure: "Configure"
|
|
2889
|
-
};
|
|
2890
|
-
var buttons = {
|
|
2891
|
-
saveChanges: "Save changes",
|
|
2892
|
-
cancel: "Cancel",
|
|
2893
|
-
"delete": "Delete"
|
|
2894
|
-
};
|
|
2895
|
-
var errors = {
|
|
2896
|
-
webhook: {
|
|
2897
|
-
required: "Please enter your endpoint URL",
|
|
2898
|
-
invalidUrl: "Please enter a valid URL",
|
|
2899
|
-
invalidUrlProtocol: "Please enter a valid URL. URL must begin with http or https",
|
|
2900
|
-
urlNotUnique: "Endpoint URL must be unique"
|
|
2901
|
-
}
|
|
2902
|
-
};
|
|
2903
|
-
var delivery = {
|
|
2904
|
-
title: "Deliveries",
|
|
2905
|
-
redeliver: "Redeliver",
|
|
2906
|
-
redelivery: "redelivery",
|
|
2907
|
-
request: "Request",
|
|
2908
|
-
response: "Response",
|
|
2909
|
-
header: "Header",
|
|
2910
|
-
body: "Body",
|
|
2911
|
-
payload: "Payload",
|
|
2912
|
-
empty: {
|
|
2913
|
-
title: "There are no deliveries to show.",
|
|
2914
|
-
description: "No events have been sent to this webhook"
|
|
2915
|
-
}
|
|
2916
|
-
};
|
|
2917
|
-
var webhook = {
|
|
2918
|
-
title: "Webhooks",
|
|
2919
|
-
description: "All new action event details will be posted to the configured webhook URLs",
|
|
2920
|
-
empty: "There are no webhooks defined currently",
|
|
2921
|
-
add: "Add new webhook",
|
|
2922
|
-
endpoint: "Endpoint",
|
|
2923
|
-
endpointPlaceholder: "Enter endpoint URL",
|
|
2924
|
-
secret: "Secret key (optional) <helpLink><info></helpLink>",
|
|
2925
|
-
secretPlaceholder: "Enter secret key",
|
|
2926
|
-
edit: "Edit Webhook"
|
|
2927
|
-
};
|
|
2928
|
-
var operation = {
|
|
2929
|
-
edit: "Edit",
|
|
2930
|
-
"delete": "Delete"
|
|
2931
|
-
};
|
|
2932
|
-
var alert = {
|
|
2933
|
-
"delete": {
|
|
2934
|
-
title: "Delete {{entity}}?",
|
|
2935
|
-
message: "You are deleting the {{entity}}."
|
|
2936
|
-
}
|
|
158
|
+
var show$1 = function show(id) {
|
|
159
|
+
return axios__default["default"].get("".concat(baseUrl$2, "/").concat(id));
|
|
2937
160
|
};
|
|
2938
|
-
var
|
|
2939
|
-
|
|
2940
|
-
buttons: buttons,
|
|
2941
|
-
errors: errors,
|
|
2942
|
-
delivery: delivery,
|
|
2943
|
-
webhook: webhook,
|
|
2944
|
-
operation: operation,
|
|
2945
|
-
alert: alert
|
|
161
|
+
var redeliver = function redeliver(id) {
|
|
162
|
+
return axios__default["default"].post("".concat(baseUrl$2, "/").concat(id, "/redeliver"));
|
|
2946
163
|
};
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
translation: en
|
|
2952
|
-
}
|
|
2953
|
-
},
|
|
2954
|
-
fallbackLng: "en"
|
|
2955
|
-
});
|
|
2956
|
-
|
|
2957
|
-
var getDeliveriesPath = function getDeliveriesPath(webhooksPath) {
|
|
2958
|
-
return "".concat(webhooksPath, "/:webhookId/deliveries");
|
|
164
|
+
var deliveriesApi = {
|
|
165
|
+
fetch: fetch$1,
|
|
166
|
+
show: show$1,
|
|
167
|
+
redeliver: redeliver
|
|
2959
168
|
};
|
|
2960
169
|
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
function _iterableToArray(iter) {
|
|
2972
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
2973
|
-
}
|
|
2974
|
-
|
|
2975
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
2976
|
-
if (!o) return;
|
|
2977
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
2978
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
2979
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
2980
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
2981
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
2982
|
-
}
|
|
170
|
+
var QUERY_KEYS = {
|
|
171
|
+
DELIVERY_LIST: "delivery-list",
|
|
172
|
+
DELIVERY_DETAILS: "delivery-details",
|
|
173
|
+
WEBHOOK_LIST: "webhook-list",
|
|
174
|
+
WEBHOOK_DETAILS: "webhook-details",
|
|
175
|
+
EVENTS_LIST: "events-list"
|
|
176
|
+
};
|
|
177
|
+
var DELIVERY_STALE_TIME = 3200000; // 1 hour
|
|
178
|
+
var WEBHOOK_STALE_TIME = 3200000; // 1 hour
|
|
179
|
+
var POST_REDELIVERY_ON_SUCCESS_TIMEOUT = 5000; // 5 seconds
|
|
2983
180
|
|
|
2984
|
-
function
|
|
2985
|
-
|
|
2986
|
-
|
|
181
|
+
var useFetchDeliveries = function useFetchDeliveries(params) {
|
|
182
|
+
return reactQuery.useQuery([QUERY_KEYS.DELIVERY_LIST, params], function () {
|
|
183
|
+
return deliveriesApi.fetch(params);
|
|
184
|
+
}, {
|
|
185
|
+
staleTime: DELIVERY_STALE_TIME
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
var useShowDelivery = function useShowDelivery(id) {
|
|
189
|
+
return reactQuery.useQuery([QUERY_KEYS.DELIVERY_DETAILS, id], function () {
|
|
190
|
+
return deliveriesApi.show(id);
|
|
191
|
+
}, {
|
|
192
|
+
staleTime: DELIVERY_STALE_TIME
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
var useRedeliverWebhook = function useRedeliverWebhook() {
|
|
196
|
+
var queryClient = reactQuery.useQueryClient();
|
|
197
|
+
return reactQuery.useMutation(deliveriesApi.redeliver, {
|
|
198
|
+
onSuccess: function onSuccess() {
|
|
199
|
+
setTimeout(function () {
|
|
200
|
+
return queryClient.invalidateQueries(QUERY_KEYS.DELIVERY_LIST);
|
|
201
|
+
}, POST_REDELIVERY_ON_SUCCESS_TIMEOUT);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
};
|
|
2987
205
|
|
|
2988
|
-
|
|
2989
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
2990
|
-
}
|
|
206
|
+
var DEFAULT_PAGE_SIZE = 10;
|
|
2991
207
|
|
|
2992
208
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2993
209
|
try {
|
|
@@ -3020,6 +236,10 @@ function _asyncToGenerator(fn) {
|
|
|
3020
236
|
};
|
|
3021
237
|
}
|
|
3022
238
|
|
|
239
|
+
function getDefaultExportFromCjs (x) {
|
|
240
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
241
|
+
}
|
|
242
|
+
|
|
3023
243
|
var regeneratorRuntime$1 = {exports: {}};
|
|
3024
244
|
|
|
3025
245
|
var _typeof$1 = {exports: {}};
|
|
@@ -3369,318 +589,318 @@ try {
|
|
|
3369
589
|
|
|
3370
590
|
var _regeneratorRuntime = /*@__PURE__*/getDefaultExportFromCjs(regenerator);
|
|
3371
591
|
|
|
3372
|
-
var queryClient = new reactQuery.QueryClient({
|
|
3373
|
-
queryCache: new reactQuery.QueryCache()
|
|
3374
|
-
});
|
|
3375
|
-
|
|
3376
|
-
var withReactQuery = function withReactQuery(Component) {
|
|
3377
|
-
var QueryWrapper = function QueryWrapper(props) {
|
|
3378
|
-
return /*#__PURE__*/React__default["default"].createElement(reactQuery.QueryClientProvider, {
|
|
3379
|
-
client: queryClient
|
|
3380
|
-
}, /*#__PURE__*/React__default["default"].createElement(Component, props), /*#__PURE__*/React__default["default"].createElement(devtools.ReactQueryDevtools, {
|
|
3381
|
-
initialIsOpen: false,
|
|
3382
|
-
position: "bottom-right"
|
|
3383
|
-
}));
|
|
3384
|
-
};
|
|
3385
|
-
return QueryWrapper;
|
|
3386
|
-
};
|
|
3387
|
-
|
|
3388
|
-
var baseUrl$1 = "/webhooks/deliveries";
|
|
3389
|
-
var fetch$1 = function fetch(webhook_id) {
|
|
3390
|
-
return axios__default["default"].get(baseUrl$1, {
|
|
3391
|
-
params: {
|
|
3392
|
-
webhook_id: webhook_id
|
|
3393
|
-
}
|
|
3394
|
-
});
|
|
3395
|
-
};
|
|
3396
|
-
var show$1 = function show(id) {
|
|
3397
|
-
return axios__default["default"].get("".concat(baseUrl$1, "/").concat(id));
|
|
3398
|
-
};
|
|
3399
|
-
var redeliver = function redeliver(id) {
|
|
3400
|
-
return axios__default["default"].post("".concat(baseUrl$1, "/").concat(id, "/redeliver"));
|
|
3401
|
-
};
|
|
3402
|
-
var deliveriesApi = {
|
|
3403
|
-
fetch: fetch$1,
|
|
3404
|
-
show: show$1,
|
|
3405
|
-
redeliver: redeliver
|
|
3406
|
-
};
|
|
3407
|
-
|
|
3408
|
-
var QUERY_KEYS = {
|
|
3409
|
-
DELIVERY_LIST: "delivery-list",
|
|
3410
|
-
DELIVERY_DETAILS: "delivery-details",
|
|
3411
|
-
WEBHOOK_LIST: "webhook-list",
|
|
3412
|
-
WEBHOOK_DETAILS: "webhook-details"
|
|
3413
|
-
};
|
|
3414
|
-
var DELIVERY_STALE_TIME = 3200000; // 1 hour
|
|
3415
|
-
var WEBHOOK_STALE_TIME = 3200000; // 1 hour
|
|
3416
|
-
var POST_REDELIVERY_ON_SUCCESS_TIMEOUT = 5000; // 5 seconds
|
|
3417
|
-
|
|
3418
|
-
var useFetchDeliveries = function useFetchDeliveries(webhookId) {
|
|
3419
|
-
return reactQuery.useQuery([QUERY_KEYS.DELIVERY_LIST, webhookId], function () {
|
|
3420
|
-
return deliveriesApi.fetch(webhookId);
|
|
3421
|
-
}, {
|
|
3422
|
-
staleTime: DELIVERY_STALE_TIME
|
|
3423
|
-
});
|
|
3424
|
-
};
|
|
3425
|
-
var useShowDelivery = function useShowDelivery(id) {
|
|
3426
|
-
return reactQuery.useQuery([QUERY_KEYS.DELIVERY_DETAILS, id], function () {
|
|
3427
|
-
return deliveriesApi.show(id);
|
|
3428
|
-
}, {
|
|
3429
|
-
staleTime: DELIVERY_STALE_TIME
|
|
3430
|
-
});
|
|
3431
|
-
};
|
|
3432
|
-
var useRedeliverWebhook = function useRedeliverWebhook() {
|
|
3433
|
-
var queryClient = reactQuery.useQueryClient();
|
|
3434
|
-
return reactQuery.useMutation(deliveriesApi.redeliver, {
|
|
3435
|
-
onSuccess: function onSuccess() {
|
|
3436
|
-
setTimeout(function () {
|
|
3437
|
-
return queryClient.invalidateQueries(QUERY_KEYS.DELIVERY_LIST);
|
|
3438
|
-
}, POST_REDELIVERY_ON_SUCCESS_TIMEOUT);
|
|
3439
|
-
}
|
|
3440
|
-
});
|
|
3441
|
-
};
|
|
3442
|
-
|
|
3443
592
|
var DELIVERY_TAB = {
|
|
3444
593
|
response: "response",
|
|
3445
594
|
request: "request"
|
|
3446
595
|
};
|
|
3447
|
-
var DELIVERY_STATUS = {
|
|
3448
|
-
failure: "failure",
|
|
3449
|
-
success: "success"
|
|
3450
|
-
};
|
|
3451
|
-
|
|
3452
|
-
function _arrayWithHoles(arr) {
|
|
3453
|
-
if (Array.isArray(arr)) return arr;
|
|
3454
|
-
}
|
|
3455
|
-
|
|
3456
|
-
function _iterableToArrayLimit(arr, i) {
|
|
3457
|
-
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
3458
|
-
if (null != _i) {
|
|
3459
|
-
var _s,
|
|
3460
|
-
_e,
|
|
3461
|
-
_x,
|
|
3462
|
-
_r,
|
|
3463
|
-
_arr = [],
|
|
3464
|
-
_n = !0,
|
|
3465
|
-
_d = !1;
|
|
3466
|
-
try {
|
|
3467
|
-
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
3468
|
-
if (Object(_i) !== _i) return;
|
|
3469
|
-
_n = !1;
|
|
3470
|
-
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
3471
|
-
} catch (err) {
|
|
3472
|
-
_d = !0, _e = err;
|
|
3473
|
-
} finally {
|
|
3474
|
-
try {
|
|
3475
|
-
if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
|
|
3476
|
-
} finally {
|
|
3477
|
-
if (_d) throw _e;
|
|
3478
|
-
}
|
|
3479
|
-
}
|
|
3480
|
-
return _arr;
|
|
3481
|
-
}
|
|
3482
|
-
}
|
|
3483
|
-
|
|
3484
|
-
function _nonIterableRest() {
|
|
3485
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
3486
|
-
}
|
|
3487
|
-
|
|
3488
|
-
function _slicedToArray(arr, i) {
|
|
3489
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
3490
|
-
}
|
|
3491
596
|
|
|
3492
597
|
var Snippet = function Snippet(_ref) {
|
|
3493
598
|
var children = _ref.children;
|
|
3494
599
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3495
|
-
className: "my-2 whitespace-pre-wrap break-all
|
|
600
|
+
className: "neeto-ui-rounded neeto-ui-border-gray-300 neeto-ui-bg-gray-100 my-2 whitespace-pre-wrap break-all border p-4"
|
|
3496
601
|
}, children);
|
|
3497
602
|
};
|
|
3498
603
|
|
|
3499
|
-
var
|
|
3500
|
-
var
|
|
3501
|
-
|
|
3502
|
-
|
|
604
|
+
var TransactionDetails = function TransactionDetails(_ref) {
|
|
605
|
+
var delivery = _ref.delivery;
|
|
606
|
+
var deliveryId = delivery.id,
|
|
607
|
+
status = delivery.status,
|
|
608
|
+
identifier = delivery.identifier,
|
|
609
|
+
responseStatusCode = delivery.responseStatusCode;
|
|
3503
610
|
var _useState = React.useState(DELIVERY_TAB.request),
|
|
3504
611
|
_useState2 = _slicedToArray(_useState, 2),
|
|
3505
612
|
activeHeader = _useState2[0],
|
|
3506
613
|
setActiveHeader = _useState2[1];
|
|
3507
|
-
var _useTranslation = useTranslation(),
|
|
614
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
3508
615
|
t = _useTranslation.t;
|
|
3509
616
|
var _useShowDelivery = useShowDelivery(deliveryId),
|
|
3510
617
|
isLoading = _useShowDelivery.isLoading,
|
|
3511
618
|
_useShowDelivery$data = _useShowDelivery.data,
|
|
3512
619
|
_useShowDelivery$data2 = _useShowDelivery$data === void 0 ? {} : _useShowDelivery$data,
|
|
3513
620
|
_useShowDelivery$data3 = _useShowDelivery$data2.delivery,
|
|
3514
|
-
|
|
621
|
+
deliveryDetails = _useShowDelivery$data3 === void 0 ? {} : _useShowDelivery$data3;
|
|
3515
622
|
if (isLoading) {
|
|
3516
623
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3517
|
-
className: "flex items-center justify-center py-6"
|
|
624
|
+
className: "flex w-full items-center justify-center py-6"
|
|
3518
625
|
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Spinner, null));
|
|
3519
626
|
}
|
|
3520
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3521
|
-
className: "
|
|
3522
|
-
}, /*#__PURE__*/React__default["default"].createElement(
|
|
3523
|
-
className: "
|
|
3524
|
-
}, /*#__PURE__*/React__default["default"].createElement(
|
|
627
|
+
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
628
|
+
className: "neeto-ui-bg-white sticky top-0 mb-2 flex w-full flex-col"
|
|
629
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
630
|
+
className: "flex w-full flex-col space-y-2 pb-4"
|
|
631
|
+
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
632
|
+
className: "flex items-center space-x-1"
|
|
633
|
+
}, t("neetoWebhooks.delivery.identifier"), ":", /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
634
|
+
className: "px-2 font-bold",
|
|
635
|
+
style: "body2"
|
|
636
|
+
}, identifier)), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
637
|
+
className: "flex items-center"
|
|
638
|
+
}, t("neetoWebhooks.common.responseStatus"), ":", /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
639
|
+
className: "px-2 font-bold",
|
|
640
|
+
style: "body2"
|
|
641
|
+
}, responseStatusCode), /*#__PURE__*/React__default["default"].createElement(neetoui.Tag, {
|
|
642
|
+
style: status === "success" ? "success" : "warning"
|
|
643
|
+
}, status))), /*#__PURE__*/React__default["default"].createElement(neetoui.Tab, null, /*#__PURE__*/React__default["default"].createElement(neetoui.Tab.Item, {
|
|
3525
644
|
active: activeHeader === DELIVERY_TAB.request,
|
|
3526
645
|
onClick: function onClick() {
|
|
3527
646
|
return setActiveHeader(DELIVERY_TAB.request);
|
|
3528
647
|
}
|
|
3529
|
-
}, t("delivery.request")), /*#__PURE__*/React__default["default"].createElement(neetoui.Tab.Item, {
|
|
648
|
+
}, t("neetoWebhooks.delivery.request")), /*#__PURE__*/React__default["default"].createElement(neetoui.Tab.Item, {
|
|
3530
649
|
active: activeHeader === DELIVERY_TAB.response,
|
|
3531
650
|
onClick: function onClick() {
|
|
3532
651
|
return setActiveHeader(DELIVERY_TAB.response);
|
|
3533
652
|
}
|
|
3534
|
-
}, t("delivery.response")), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3535
|
-
className: "
|
|
3536
|
-
}, /*#__PURE__*/React__default["default"].createElement(
|
|
3537
|
-
className: "mr-2 mb-2",
|
|
3538
|
-
label: t("delivery.redeliver"),
|
|
3539
|
-
loading: isRedelivering,
|
|
3540
|
-
style: "secondary",
|
|
3541
|
-
onClick: function onClick() {
|
|
3542
|
-
return onRedeliverClick(delivery.id);
|
|
3543
|
-
}
|
|
3544
|
-
}))), activeHeader === DELIVERY_TAB.request ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
653
|
+
}, t("neetoWebhooks.delivery.response")))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
654
|
+
className: "mt-2"
|
|
655
|
+
}, activeHeader === DELIVERY_TAB.request ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3545
656
|
className: "space-y-4"
|
|
3546
657
|
}, /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3547
658
|
style: "h5"
|
|
3548
|
-
}, t("delivery.header")), /*#__PURE__*/React__default["default"].createElement(Snippet, null,
|
|
659
|
+
}, t("neetoWebhooks.delivery.header")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, deliveryDetails.requestHeader)), /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3549
660
|
style: "h5"
|
|
3550
|
-
}, t("delivery.payload")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, JSON.stringify(JSON.parse(
|
|
661
|
+
}, t("neetoWebhooks.delivery.payload")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, JSON.stringify(JSON.parse(deliveryDetails.requestBody), null, 2)))) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3551
662
|
className: "space-y-4"
|
|
3552
663
|
}, /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3553
664
|
style: "h5"
|
|
3554
|
-
}, t("delivery.header")), /*#__PURE__*/React__default["default"].createElement(Snippet, null,
|
|
665
|
+
}, t("neetoWebhooks.delivery.header")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, deliveryDetails.responseHeader)), /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3555
666
|
style: "h5"
|
|
3556
|
-
}, t("delivery.body")), /*#__PURE__*/React__default["default"].createElement(Snippet, null,
|
|
667
|
+
}, t("neetoWebhooks.delivery.body")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, deliveryDetails.responseBody)))));
|
|
3557
668
|
};
|
|
3558
669
|
|
|
3559
|
-
var
|
|
3560
|
-
var
|
|
3561
|
-
|
|
3562
|
-
var
|
|
670
|
+
var Details = function Details(_ref) {
|
|
671
|
+
var delivery = _ref.delivery,
|
|
672
|
+
onClose = _ref.onClose;
|
|
673
|
+
var createdAt = delivery.createdAt,
|
|
674
|
+
id = delivery.id,
|
|
675
|
+
event = delivery.event;
|
|
676
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
3563
677
|
t = _useTranslation.t;
|
|
3564
|
-
var _useParams = reactRouterDom.useParams(),
|
|
3565
|
-
webhookId = _useParams.webhookId;
|
|
3566
|
-
var _useFetchDeliveries = useFetchDeliveries(webhookId),
|
|
3567
|
-
isLoading = _useFetchDeliveries.isLoading,
|
|
3568
|
-
_useFetchDeliveries$d = _useFetchDeliveries.data,
|
|
3569
|
-
_useFetchDeliveries$d2 = _useFetchDeliveries$d === void 0 ? {} : _useFetchDeliveries$d,
|
|
3570
|
-
endpoint = _useFetchDeliveries$d2.endpoint,
|
|
3571
|
-
_useFetchDeliveries$d3 = _useFetchDeliveries$d2.deliveries,
|
|
3572
|
-
deliveries = _useFetchDeliveries$d3 === void 0 ? [] : _useFetchDeliveries$d3;
|
|
3573
678
|
var _useRedeliverWebhook = useRedeliverWebhook(),
|
|
3574
679
|
isRedelivering = _useRedeliverWebhook.isLoading,
|
|
3575
680
|
redeliverWebhook = _useRedeliverWebhook.mutateAsync;
|
|
3576
|
-
var
|
|
3577
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(
|
|
681
|
+
var handleRedeliverClick = /*#__PURE__*/function () {
|
|
682
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
3578
683
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
3579
684
|
while (1) switch (_context.prev = _context.next) {
|
|
3580
685
|
case 0:
|
|
3581
686
|
_context.next = 2;
|
|
3582
|
-
return redeliverWebhook(
|
|
687
|
+
return redeliverWebhook(id);
|
|
3583
688
|
case 2:
|
|
3584
689
|
case "end":
|
|
3585
690
|
return _context.stop();
|
|
3586
691
|
}
|
|
3587
692
|
}, _callee);
|
|
3588
693
|
}));
|
|
3589
|
-
return function
|
|
694
|
+
return function handleRedeliverClick() {
|
|
3590
695
|
return _ref2.apply(this, arguments);
|
|
3591
696
|
};
|
|
3592
697
|
}();
|
|
3593
|
-
|
|
3594
|
-
|
|
698
|
+
return /*#__PURE__*/React__default["default"].createElement(neetoui.Pane, {
|
|
699
|
+
isOpen: neetoCist.isPresent(delivery),
|
|
700
|
+
size: "large",
|
|
701
|
+
onClose: onClose
|
|
702
|
+
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Header, null, /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(DateFormat__default["default"].Date, {
|
|
703
|
+
date: createdAt,
|
|
704
|
+
typographyProps: {
|
|
705
|
+
style: "h2",
|
|
706
|
+
weight: "semibold"
|
|
707
|
+
}
|
|
708
|
+
}), /*#__PURE__*/React__default["default"].createElement("span", null, " \u2022 "), /*#__PURE__*/React__default["default"].createElement(DateFormat__default["default"].Time, {
|
|
709
|
+
date: createdAt,
|
|
710
|
+
typographyProps: {
|
|
711
|
+
style: "h2",
|
|
712
|
+
weight: "normal"
|
|
713
|
+
}
|
|
714
|
+
}))), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Body, null, neetoCist.isPresent(delivery) && /*#__PURE__*/React__default["default"].createElement(TransactionDetails, {
|
|
715
|
+
delivery: delivery
|
|
716
|
+
})), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Footer, {
|
|
717
|
+
className: "gap-x-2"
|
|
718
|
+
}, event && /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
719
|
+
disabled: isRedelivering,
|
|
720
|
+
label: t("neetoWebhooks.delivery.redeliver"),
|
|
721
|
+
loading: isRedelivering,
|
|
722
|
+
style: "primary",
|
|
723
|
+
onClick: handleRedeliverClick
|
|
724
|
+
}), /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
725
|
+
label: t("neetoWebhooks.buttons.cancel"),
|
|
726
|
+
style: "text",
|
|
727
|
+
onClick: onClose
|
|
728
|
+
})));
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
var buildColumns$1 = function buildColumns(_ref) {
|
|
732
|
+
var handleDetailsClick = _ref.handleDetailsClick;
|
|
733
|
+
return [{
|
|
734
|
+
title: i18next.t("neetoWebhooks.delivery.identifier", constants.SINGULAR),
|
|
735
|
+
key: "identifier",
|
|
736
|
+
width: 300,
|
|
737
|
+
render: function render(_ref2) {
|
|
738
|
+
var identifier = _ref2.identifier,
|
|
739
|
+
redelivery = _ref2.redelivery;
|
|
740
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
741
|
+
className: "flex space-x-1"
|
|
742
|
+
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
743
|
+
className: "px-2",
|
|
744
|
+
style: "body2",
|
|
745
|
+
weight: "semibold"
|
|
746
|
+
}, identifier), redelivery && /*#__PURE__*/React__default["default"].createElement(neetoui.Tag, {
|
|
747
|
+
style: "info"
|
|
748
|
+
}, i18next.t("neetoWebhooks.delivery.redelivery")));
|
|
749
|
+
}
|
|
750
|
+
}, {
|
|
751
|
+
title: i18next.t("neetoWebhooks.tableHeaders.createdAt"),
|
|
752
|
+
key: "createdAt",
|
|
753
|
+
dataIndex: "createdAt",
|
|
754
|
+
width: 300,
|
|
755
|
+
render: function render(createdAt) {
|
|
756
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
757
|
+
className: "flex items-center justify-between space-x-1"
|
|
758
|
+
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, null, /*#__PURE__*/React__default["default"].createElement(DateFormat__default["default"].Date, {
|
|
759
|
+
date: createdAt,
|
|
760
|
+
typographyProps: {
|
|
761
|
+
style: "body1",
|
|
762
|
+
weight: "semibold"
|
|
763
|
+
}
|
|
764
|
+
}), /*#__PURE__*/React__default["default"].createElement("span", null, " \u2022 "), /*#__PURE__*/React__default["default"].createElement(DateFormat__default["default"].Time, {
|
|
765
|
+
date: createdAt,
|
|
766
|
+
typographyProps: {
|
|
767
|
+
style: "body1"
|
|
768
|
+
}
|
|
769
|
+
})));
|
|
770
|
+
}
|
|
771
|
+
}, {
|
|
772
|
+
title: i18next.t("neetoWebhooks.common.responseStatus"),
|
|
773
|
+
key: "responseStatusCode",
|
|
774
|
+
width: 150,
|
|
775
|
+
render: function render(_ref3) {
|
|
776
|
+
var responseStatusCode = _ref3.responseStatusCode,
|
|
777
|
+
status = _ref3.status;
|
|
778
|
+
return /*#__PURE__*/React__default["default"].createElement("span", {
|
|
779
|
+
className: "flex items-center"
|
|
780
|
+
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
781
|
+
className: "px-2 font-bold",
|
|
782
|
+
style: "body2"
|
|
783
|
+
}, responseStatusCode), /*#__PURE__*/React__default["default"].createElement(neetoui.Tag, {
|
|
784
|
+
style: status === "success" ? "success" : "warning"
|
|
785
|
+
}, status));
|
|
786
|
+
}
|
|
787
|
+
}, {
|
|
788
|
+
title: i18next.t("neetoWebhooks.common.event", constants.SINGULAR),
|
|
789
|
+
key: "event",
|
|
790
|
+
dataIndex: "event",
|
|
791
|
+
width: 100,
|
|
792
|
+
render: ramda.prop("label")
|
|
793
|
+
}, {
|
|
794
|
+
title: i18next.t("neetoWebhooks.tableHeaders.details"),
|
|
795
|
+
key: "details",
|
|
796
|
+
dataIndex: "details",
|
|
797
|
+
width: 150,
|
|
798
|
+
render: function render(_, delivery) {
|
|
799
|
+
return /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
800
|
+
label: i18next.t("neetoWebhooks.buttons.viewDetails"),
|
|
801
|
+
size: "small",
|
|
802
|
+
onClick: function onClick() {
|
|
803
|
+
return handleDetailsClick(delivery);
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
}];
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
var Deliveries = function Deliveries(_ref) {
|
|
811
|
+
var webhooksUrl = _ref.webhooksUrl,
|
|
812
|
+
hostBreadcrumbs = _ref.breadcrumbs;
|
|
813
|
+
var _useState = React.useState(1),
|
|
814
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
815
|
+
pageNumber = _useState2[0],
|
|
816
|
+
setPageNumber = _useState2[1];
|
|
817
|
+
var _useState3 = React.useState({}),
|
|
818
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
819
|
+
selectedDelivery = _useState4[0],
|
|
820
|
+
setSelectedDelivery = _useState4[1];
|
|
821
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
822
|
+
t = _useTranslation.t;
|
|
823
|
+
var _useParams = reactRouterDom.useParams(),
|
|
824
|
+
webhookId = _useParams.webhookId;
|
|
825
|
+
var _useFetchDeliveries = useFetchDeliveries({
|
|
826
|
+
webhookId: webhookId,
|
|
827
|
+
page: pageNumber,
|
|
828
|
+
limit: DEFAULT_PAGE_SIZE
|
|
829
|
+
}),
|
|
830
|
+
isLoading = _useFetchDeliveries.isLoading,
|
|
831
|
+
isFetching = _useFetchDeliveries.isFetching,
|
|
832
|
+
_useFetchDeliveries$d = _useFetchDeliveries.data,
|
|
833
|
+
_useFetchDeliveries$d2 = _useFetchDeliveries$d === void 0 ? {} : _useFetchDeliveries$d,
|
|
834
|
+
endpoint = _useFetchDeliveries$d2.endpoint,
|
|
835
|
+
totalCount = _useFetchDeliveries$d2.totalCount,
|
|
836
|
+
_useFetchDeliveries$d3 = _useFetchDeliveries$d2.deliveries,
|
|
837
|
+
deliveries = _useFetchDeliveries$d3 === void 0 ? [] : _useFetchDeliveries$d3;
|
|
838
|
+
var breadcrumbsWithoutWebhooksTitle = neetoCist.removeBy({
|
|
839
|
+
text: t("neetoWebhooks.webhook.title")
|
|
3595
840
|
}, hostBreadcrumbs);
|
|
3596
841
|
var breadcrumbs = [].concat(_toConsumableArray(breadcrumbsWithoutWebhooksTitle), [{
|
|
3597
842
|
link: webhooksUrl,
|
|
3598
|
-
text: t("webhook.title")
|
|
843
|
+
text: t("neetoWebhooks.webhook.title")
|
|
3599
844
|
}, {
|
|
3600
845
|
link: window.location.pathname,
|
|
3601
846
|
text: endpoint
|
|
3602
847
|
}]);
|
|
3603
848
|
if (isLoading) return /*#__PURE__*/React__default["default"].createElement(PageLoader__default["default"], null);
|
|
3604
|
-
return /*#__PURE__*/React__default["default"].createElement("
|
|
3605
|
-
className: "w-full
|
|
849
|
+
return /*#__PURE__*/React__default["default"].createElement(Container__default["default"], {
|
|
850
|
+
className: "w-full"
|
|
3606
851
|
}, /*#__PURE__*/React__default["default"].createElement(Header__default["default"], {
|
|
3607
852
|
breadcrumbs: breadcrumbs,
|
|
3608
|
-
title: t("delivery.title")
|
|
3609
|
-
}), /*#__PURE__*/React__default["default"].createElement("
|
|
3610
|
-
|
|
3611
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.
|
|
3612
|
-
|
|
3613
|
-
|
|
853
|
+
title: t("neetoWebhooks.delivery.title")
|
|
854
|
+
}), neetoCist.isNotEmpty(deliveries) ? /*#__PURE__*/React__default["default"].createElement(TableWrapper__default["default"], {
|
|
855
|
+
hasPagination: totalCount > DEFAULT_PAGE_SIZE
|
|
856
|
+
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Table, {
|
|
857
|
+
totalCount: totalCount,
|
|
858
|
+
fixedHeight: true,
|
|
859
|
+
currentPageNumber: pageNumber,
|
|
860
|
+
defaultPageSize: DEFAULT_PAGE_SIZE,
|
|
861
|
+
handlePageChange: function handlePageChange(page) {
|
|
862
|
+
return setPageNumber(page);
|
|
863
|
+
},
|
|
864
|
+
loading: isFetching,
|
|
865
|
+
rowData: deliveries,
|
|
866
|
+
columnData: buildColumns$1({
|
|
867
|
+
handleDetailsClick: setSelectedDelivery
|
|
3614
868
|
})
|
|
3615
|
-
}
|
|
3616
|
-
|
|
3617
|
-
status = _ref3.status,
|
|
3618
|
-
identifier = _ref3.identifier,
|
|
3619
|
-
action = _ref3.action,
|
|
3620
|
-
redelivery = _ref3.redelivery,
|
|
3621
|
-
createdAt = _ref3.createdAt;
|
|
3622
|
-
return /*#__PURE__*/React__default["default"].createElement(neetoui.Accordion.Item, {
|
|
3623
|
-
key: id,
|
|
3624
|
-
title: /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3625
|
-
className: "flex flex-1 justify-between"
|
|
3626
|
-
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3627
|
-
className: "flex items-center gap-2"
|
|
3628
|
-
}, /*#__PURE__*/React__default["default"].createElement("span", null, status === DELIVERY_STATUS.failure ? /*#__PURE__*/React__default["default"].createElement(neetoIcons.Close, {
|
|
3629
|
-
className: "neeto-ui-text-error-600",
|
|
3630
|
-
size: 20,
|
|
3631
|
-
strokeWidth: 2.5
|
|
3632
|
-
}) : /*#__PURE__*/React__default["default"].createElement(neetoIcons.Check, {
|
|
3633
|
-
className: "neeto-ui-text-success-600",
|
|
3634
|
-
size: 24,
|
|
3635
|
-
strokeWidth: 2
|
|
3636
|
-
})), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3637
|
-
style: "h5"
|
|
3638
|
-
}, identifier), /*#__PURE__*/React__default["default"].createElement(neetoui.Tag, {
|
|
3639
|
-
label: action,
|
|
3640
|
-
style: "info"
|
|
3641
|
-
}), redelivery && /*#__PURE__*/React__default["default"].createElement(neetoui.Tag, {
|
|
3642
|
-
label: t("delivery.redelivery")
|
|
3643
|
-
})), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3644
|
-
className: "mr-8",
|
|
3645
|
-
style: "body2"
|
|
3646
|
-
}, utils.dateFormat.dateTime(createdAt)))
|
|
3647
|
-
}, /*#__PURE__*/React__default["default"].createElement(DeliveryItem, {
|
|
3648
|
-
deliveryId: id,
|
|
3649
|
-
isRedelivering: isRedelivering,
|
|
3650
|
-
onRedeliverClick: onRedeliverClick
|
|
3651
|
-
}));
|
|
3652
|
-
})), ramda.isEmpty(deliveries) && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3653
|
-
className: "flex h-full items-center justify-center"
|
|
869
|
+
})) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
870
|
+
className: "flex h-full w-full items-center justify-center"
|
|
3654
871
|
}, /*#__PURE__*/React__default["default"].createElement(neetoui.NoData, {
|
|
3655
|
-
description: t("delivery.empty.description"),
|
|
3656
|
-
title: t("delivery.empty.title")
|
|
3657
|
-
}))
|
|
872
|
+
description: t("neetoWebhooks.delivery.empty.description"),
|
|
873
|
+
title: t("neetoWebhooks.delivery.empty.title")
|
|
874
|
+
})), /*#__PURE__*/React__default["default"].createElement(Details, {
|
|
875
|
+
delivery: selectedDelivery,
|
|
876
|
+
onClose: function onClose() {
|
|
877
|
+
return setSelectedDelivery({});
|
|
878
|
+
}
|
|
879
|
+
}));
|
|
3658
880
|
};
|
|
3659
881
|
var Deliveries$1 = withReactQuery(Deliveries);
|
|
3660
882
|
|
|
3661
|
-
var baseUrl = "/webhooks/webhooks";
|
|
3662
|
-
var fetch = function fetch(
|
|
3663
|
-
return axios__default["default"].get(baseUrl, {
|
|
3664
|
-
params:
|
|
3665
|
-
entity_id: entity_id
|
|
3666
|
-
}
|
|
883
|
+
var baseUrl$1 = "/webhooks/webhooks";
|
|
884
|
+
var fetch = function fetch(params) {
|
|
885
|
+
return axios__default["default"].get(baseUrl$1, {
|
|
886
|
+
params: params
|
|
3667
887
|
});
|
|
3668
888
|
};
|
|
3669
889
|
var create = function create(payload) {
|
|
3670
|
-
return axios__default["default"].post(baseUrl, {
|
|
890
|
+
return axios__default["default"].post(baseUrl$1, {
|
|
3671
891
|
webhook: payload
|
|
3672
892
|
});
|
|
3673
893
|
};
|
|
3674
894
|
var show = function show(id) {
|
|
3675
|
-
return axios__default["default"].get("".concat(baseUrl, "/").concat(id));
|
|
895
|
+
return axios__default["default"].get("".concat(baseUrl$1, "/").concat(id));
|
|
3676
896
|
};
|
|
3677
897
|
var update = function update(id, payload) {
|
|
3678
|
-
return axios__default["default"].put("".concat(baseUrl, "/").concat(id), {
|
|
898
|
+
return axios__default["default"].put("".concat(baseUrl$1, "/").concat(id), {
|
|
3679
899
|
webhook: payload
|
|
3680
900
|
});
|
|
3681
901
|
};
|
|
3682
902
|
var destroy = function destroy(id) {
|
|
3683
|
-
return axios__default["default"]["delete"]("".concat(baseUrl, "/").concat(id));
|
|
903
|
+
return axios__default["default"]["delete"]("".concat(baseUrl$1, "/").concat(id));
|
|
3684
904
|
};
|
|
3685
905
|
var webhooksApi = {
|
|
3686
906
|
fetch: fetch,
|
|
@@ -3690,9 +910,9 @@ var webhooksApi = {
|
|
|
3690
910
|
destroy: destroy
|
|
3691
911
|
};
|
|
3692
912
|
|
|
3693
|
-
var useFetchWebhooks = function useFetchWebhooks(
|
|
3694
|
-
return reactQuery.useQuery([QUERY_KEYS.WEBHOOK_LIST,
|
|
3695
|
-
return webhooksApi.fetch(
|
|
913
|
+
var useFetchWebhooks = function useFetchWebhooks(params) {
|
|
914
|
+
return reactQuery.useQuery([QUERY_KEYS.WEBHOOK_LIST, params], function () {
|
|
915
|
+
return webhooksApi.fetch(params);
|
|
3696
916
|
}, {
|
|
3697
917
|
staleTime: WEBHOOK_STALE_TIME
|
|
3698
918
|
});
|
|
@@ -3783,16 +1003,125 @@ function _defineProperty(obj, key, value) {
|
|
|
3783
1003
|
return obj;
|
|
3784
1004
|
}
|
|
3785
1005
|
|
|
1006
|
+
var baseUrl = "/webhooks/events/all";
|
|
1007
|
+
var all = function all() {
|
|
1008
|
+
return axios__default["default"].get(baseUrl);
|
|
1009
|
+
};
|
|
1010
|
+
var eventsApi = {
|
|
1011
|
+
all: all
|
|
1012
|
+
};
|
|
1013
|
+
|
|
1014
|
+
var useFetchEvents = function useFetchEvents() {
|
|
1015
|
+
return reactQuery.useQuery([QUERY_KEYS.EVENTS_LIST], eventsApi.all, {
|
|
1016
|
+
staleTime: WEBHOOK_STALE_TIME
|
|
1017
|
+
});
|
|
1018
|
+
};
|
|
1019
|
+
|
|
3786
1020
|
var WEBHOOK_HELP_URL = "https://help.neetocal.com/articles/webhook";
|
|
3787
1021
|
|
|
1022
|
+
var Menu = neetoui.Dropdown.Menu,
|
|
1023
|
+
MenuItem = neetoui.Dropdown.MenuItem;
|
|
1024
|
+
var ActionDropdown = function ActionDropdown(_ref) {
|
|
1025
|
+
var onEdit = _ref.onEdit,
|
|
1026
|
+
onDelete = _ref.onDelete;
|
|
1027
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
1028
|
+
t = _useTranslation.t;
|
|
1029
|
+
return /*#__PURE__*/React__default["default"].createElement(neetoui.Dropdown, {
|
|
1030
|
+
buttonStyle: "text",
|
|
1031
|
+
icon: neetoIcons.MenuHorizontal,
|
|
1032
|
+
strategy: "fixed"
|
|
1033
|
+
}, /*#__PURE__*/React__default["default"].createElement(Menu, null, /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
|
|
1034
|
+
onClick: onEdit
|
|
1035
|
+
}, t("neetoWebhooks.buttons.edit")), /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
|
|
1036
|
+
style: "danger",
|
|
1037
|
+
onClick: onDelete
|
|
1038
|
+
}, t("neetoWebhooks.buttons.delete"))));
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1042
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3788
1043
|
var getValidationSchema = function getValidationSchema(webhooks) {
|
|
3789
1044
|
return yup__namespace.object().shape({
|
|
3790
|
-
endpoint: yup__namespace.string().trim().matches(/^(https?):\/\//i, t
|
|
3791
|
-
return !ramda.pluck("endpoint",
|
|
1045
|
+
endpoint: yup__namespace.string().trim().matches(/^(https?):\/\//i, i18next.t("neetoWebhooks.errors.webhook.invalidUrlProtocol")).url(i18next.t("neetoWebhooks.errors.webhook.invalidUrl")).required(i18next.t("neetoWebhooks.errors.webhook.required")).test("Is endpoint unique", i18next.t("neetoWebhooks.errors.webhook.urlNotUnique"), function (endpoint, ctx) {
|
|
1046
|
+
return !ramda.pluck("endpoint", neetoCist.removeById(ctx.parent.id, webhooks)).includes(endpoint === null || endpoint === void 0 ? void 0 : endpoint.trim());
|
|
3792
1047
|
}),
|
|
1048
|
+
events: yup__namespace.array().min(1, i18next.t("neetoWebhooks.errors.webhook.events.required")),
|
|
3793
1049
|
secret: yup__namespace.string().trim().nullable()
|
|
3794
1050
|
});
|
|
3795
1051
|
};
|
|
1052
|
+
var buildPayload = function buildPayload(_ref) {
|
|
1053
|
+
var _initialValues$events;
|
|
1054
|
+
var isEditing = _ref.isEditing,
|
|
1055
|
+
values = _ref.values,
|
|
1056
|
+
initialValues = _ref.initialValues;
|
|
1057
|
+
var events = values.events.map(function (_ref2) {
|
|
1058
|
+
var identifier = _ref2.identifier;
|
|
1059
|
+
return {
|
|
1060
|
+
identifier: identifier
|
|
1061
|
+
};
|
|
1062
|
+
});
|
|
1063
|
+
if (!isEditing) return _objectSpread$1(_objectSpread$1({}, values), {}, {
|
|
1064
|
+
eventsAttributes: events
|
|
1065
|
+
});
|
|
1066
|
+
var deletable = ((_initialValues$events = initialValues.events) !== null && _initialValues$events !== void 0 ? _initialValues$events : []).filter(function (_ref3) {
|
|
1067
|
+
var identifier = _ref3.identifier;
|
|
1068
|
+
return !neetoCist.findBy({
|
|
1069
|
+
identifier: identifier
|
|
1070
|
+
}, values.events);
|
|
1071
|
+
}).map(ramda.assoc("_destroy", true));
|
|
1072
|
+
var creatable = values.events.filter(function (_ref4) {
|
|
1073
|
+
var identifier = _ref4.identifier;
|
|
1074
|
+
return !neetoCist.findBy({
|
|
1075
|
+
identifier: identifier
|
|
1076
|
+
}, initialValues.events);
|
|
1077
|
+
});
|
|
1078
|
+
return _objectSpread$1(_objectSpread$1({}, values), {}, {
|
|
1079
|
+
eventsAttributes: [].concat(_toConsumableArray(creatable), _toConsumableArray(deletable))
|
|
1080
|
+
});
|
|
1081
|
+
};
|
|
1082
|
+
var buildColumns = function buildColumns(_ref5) {
|
|
1083
|
+
var handleDelete = _ref5.handleDelete,
|
|
1084
|
+
handleEdit = _ref5.handleEdit,
|
|
1085
|
+
deliveriesPath = _ref5.deliveriesPath;
|
|
1086
|
+
return [{
|
|
1087
|
+
title: i18next.t("neetoWebhooks.common.endpoint"),
|
|
1088
|
+
key: "endpoint",
|
|
1089
|
+
dataIndex: "endpoint",
|
|
1090
|
+
render: function render(endpoint, webhook) {
|
|
1091
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1092
|
+
className: "flex items-center justify-between space-x-3"
|
|
1093
|
+
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
1094
|
+
style: "link",
|
|
1095
|
+
to: utils.buildUrl(deliveriesPath, {
|
|
1096
|
+
webhookId: webhook.id
|
|
1097
|
+
})
|
|
1098
|
+
}, endpoint), /*#__PURE__*/React__default["default"].createElement(ActionDropdown, {
|
|
1099
|
+
onDelete: function onDelete() {
|
|
1100
|
+
return handleDelete(webhook.id);
|
|
1101
|
+
},
|
|
1102
|
+
onEdit: function onEdit() {
|
|
1103
|
+
return handleEdit(webhook.id);
|
|
1104
|
+
}
|
|
1105
|
+
}));
|
|
1106
|
+
}
|
|
1107
|
+
}, {
|
|
1108
|
+
title: i18next.t("neetoWebhooks.webhook.active"),
|
|
1109
|
+
key: "isActive",
|
|
1110
|
+
dataIndex: "isActive",
|
|
1111
|
+
render: function render(isActive) {
|
|
1112
|
+
return isActive ? i18next.t("neetoWebhooks.webhook.activeStatuses.yes") : i18next.t("neetoWebhooks.webhook.activeStatuses.no");
|
|
1113
|
+
},
|
|
1114
|
+
width: 100
|
|
1115
|
+
}, {
|
|
1116
|
+
title: i18next.t("neetoWebhooks.common.event", constants.PLURAL),
|
|
1117
|
+
dataIndex: "events",
|
|
1118
|
+
key: "events",
|
|
1119
|
+
render: function render(events) {
|
|
1120
|
+
return ramda.pluck("label", events).sort().join(", ");
|
|
1121
|
+
},
|
|
1122
|
+
width: 200
|
|
1123
|
+
}];
|
|
1124
|
+
};
|
|
3796
1125
|
|
|
3797
1126
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3798
1127
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -3803,7 +1132,7 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
3803
1132
|
isOpen = _ref.isOpen,
|
|
3804
1133
|
onClose = _ref.onClose,
|
|
3805
1134
|
webhooks = _ref.webhooks;
|
|
3806
|
-
var _useTranslation = useTranslation(),
|
|
1135
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
3807
1136
|
t = _useTranslation.t;
|
|
3808
1137
|
var _useCreateWebhook = useCreateWebhook({
|
|
3809
1138
|
onSuccess: function onSuccess() {
|
|
@@ -3823,15 +1152,25 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
3823
1152
|
}),
|
|
3824
1153
|
updateWebhook = _useUpdateWebhook.mutate;
|
|
3825
1154
|
var endpointRef = React.useRef();
|
|
1155
|
+
var _useFetchEvents = useFetchEvents(),
|
|
1156
|
+
events = _useFetchEvents.data,
|
|
1157
|
+
isLoading = _useFetchEvents.isLoading;
|
|
3826
1158
|
var initialValues = editingWebhookId ? webhook : {
|
|
3827
1159
|
endpoint: "",
|
|
3828
|
-
|
|
1160
|
+
events: events,
|
|
1161
|
+
secret: "",
|
|
1162
|
+
isActive: true
|
|
3829
1163
|
};
|
|
3830
1164
|
var handleSubmit = function handleSubmit(values) {
|
|
1165
|
+
var payload = buildPayload({
|
|
1166
|
+
isEditing: editingWebhookId,
|
|
1167
|
+
values: values,
|
|
1168
|
+
initialValues: initialValues
|
|
1169
|
+
});
|
|
3831
1170
|
editingWebhookId ? updateWebhook({
|
|
3832
1171
|
id: editingWebhookId,
|
|
3833
|
-
payload:
|
|
3834
|
-
}) : createWebhook(_objectSpread(_objectSpread({},
|
|
1172
|
+
payload: payload
|
|
1173
|
+
}) : createWebhook(_objectSpread(_objectSpread({}, payload), {}, {
|
|
3835
1174
|
entityId: entityId,
|
|
3836
1175
|
entityType: entityType
|
|
3837
1176
|
}));
|
|
@@ -3846,7 +1185,7 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
3846
1185
|
"data-cy": "add-new-webhook-pane-header",
|
|
3847
1186
|
style: "h2",
|
|
3848
1187
|
weight: "semibold"
|
|
3849
|
-
}, editingWebhookId ? t("webhook.edit") : t("webhook.add")), /*#__PURE__*/React__default["default"].createElement("a", {
|
|
1188
|
+
}, editingWebhookId ? t("neetoWebhooks.webhook.edit") : t("neetoWebhooks.webhook.add")), /*#__PURE__*/React__default["default"].createElement("a", {
|
|
3850
1189
|
href: WEBHOOK_HELP_URL,
|
|
3851
1190
|
rel: "noreferrer",
|
|
3852
1191
|
target: "_blank"
|
|
@@ -3864,21 +1203,33 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
3864
1203
|
}
|
|
3865
1204
|
}, function (_ref2) {
|
|
3866
1205
|
var dirty = _ref2.dirty,
|
|
3867
|
-
isSubmitting = _ref2.isSubmitting
|
|
3868
|
-
|
|
1206
|
+
isSubmitting = _ref2.isSubmitting,
|
|
1207
|
+
isValid = _ref2.isValid;
|
|
1208
|
+
return isLoading ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1209
|
+
className: "flex items-center justify-center"
|
|
1210
|
+
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Spinner, null)) : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Body, null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3869
1211
|
className: "w-full space-y-4"
|
|
3870
1212
|
}, /*#__PURE__*/React__default["default"].createElement(formik.Input, {
|
|
3871
1213
|
required: true,
|
|
3872
1214
|
"data-cy": "endpoint-input-field",
|
|
3873
|
-
label: t("webhook.endpoint"),
|
|
1215
|
+
label: t("neetoWebhooks.webhook.endpoint"),
|
|
3874
1216
|
name: "endpoint",
|
|
3875
|
-
placeholder: t("webhook.endpointPlaceholder"),
|
|
1217
|
+
placeholder: t("neetoWebhooks.webhook.endpointPlaceholder"),
|
|
3876
1218
|
ref: endpointRef
|
|
1219
|
+
}), !isLoading && /*#__PURE__*/React__default["default"].createElement(formik.Select, {
|
|
1220
|
+
isMulti: true,
|
|
1221
|
+
required: true,
|
|
1222
|
+
getOptionLabel: ramda.prop("label"),
|
|
1223
|
+
getOptionValue: ramda.prop("identifier"),
|
|
1224
|
+
label: t("neetoWebhooks.common.event", constants.PLURAL),
|
|
1225
|
+
name: "events",
|
|
1226
|
+
options: events,
|
|
1227
|
+
placeholder: t("neetoWebhooks.webhook.eventPlaceholder")
|
|
3877
1228
|
}), /*#__PURE__*/React__default["default"].createElement(formik.Input, {
|
|
3878
1229
|
"data-cy": "secret-key-input-field",
|
|
3879
1230
|
name: "secret",
|
|
3880
|
-
placeholder: t("webhook.secretPlaceholder"),
|
|
3881
|
-
label: /*#__PURE__*/React__default["default"].createElement(Trans, {
|
|
1231
|
+
placeholder: t("neetoWebhooks.webhook.secretPlaceholder"),
|
|
1232
|
+
label: /*#__PURE__*/React__default["default"].createElement(reactI18next.Trans, {
|
|
3882
1233
|
i18nKey: "webhook.secret",
|
|
3883
1234
|
components: {
|
|
3884
1235
|
helpLink: /*#__PURE__*/React__default["default"].createElement("a", {
|
|
@@ -3892,6 +1243,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
3892
1243
|
})
|
|
3893
1244
|
}
|
|
3894
1245
|
})
|
|
1246
|
+
}), /*#__PURE__*/React__default["default"].createElement(formik.Switch, {
|
|
1247
|
+
label: t("neetoWebhooks.webhook.active"),
|
|
1248
|
+
name: "isActive"
|
|
3895
1249
|
}))), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Footer, {
|
|
3896
1250
|
className: "flex gap-2"
|
|
3897
1251
|
}, /*#__PURE__*/React__default["default"].createElement(formik.ActionBlock, {
|
|
@@ -3899,11 +1253,11 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
3899
1253
|
cancelButtonProps: {
|
|
3900
1254
|
onClick: onClose,
|
|
3901
1255
|
disabled: false,
|
|
3902
|
-
label: t("buttons.cancel")
|
|
1256
|
+
label: t("neetoWebhooks.buttons.cancel")
|
|
3903
1257
|
},
|
|
3904
1258
|
submitButtonProps: {
|
|
3905
|
-
label: t("buttons.saveChanges"),
|
|
3906
|
-
disabled: !dirty,
|
|
1259
|
+
label: t("neetoWebhooks.buttons.saveChanges"),
|
|
1260
|
+
disabled: !dirty || !isValid,
|
|
3907
1261
|
loading: isSubmitting
|
|
3908
1262
|
}
|
|
3909
1263
|
})));
|
|
@@ -3913,14 +1267,14 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
3913
1267
|
var Header = function Header(_ref) {
|
|
3914
1268
|
var breadcrumbs = _ref.breadcrumbs,
|
|
3915
1269
|
setIsAddWebhookPaneOpen = _ref.setIsAddWebhookPaneOpen;
|
|
3916
|
-
var _useTranslation = useTranslation(),
|
|
1270
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
3917
1271
|
t = _useTranslation.t;
|
|
3918
1272
|
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(Header__default["default"], {
|
|
3919
1273
|
breadcrumbs: breadcrumbs,
|
|
3920
|
-
title: t("webhook.title"),
|
|
1274
|
+
title: t("neetoWebhooks.webhook.title"),
|
|
3921
1275
|
actionBlock: /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
3922
1276
|
"data-cy": "add-new-webhook-button",
|
|
3923
|
-
label: t("webhook.add"),
|
|
1277
|
+
label: t("neetoWebhooks.webhook.add"),
|
|
3924
1278
|
onClick: function onClick() {
|
|
3925
1279
|
return setIsAddWebhookPaneOpen(true);
|
|
3926
1280
|
}
|
|
@@ -3930,48 +1284,10 @@ var Header = function Header(_ref) {
|
|
|
3930
1284
|
"data-cy": "webhook-description-header",
|
|
3931
1285
|
style: "h5",
|
|
3932
1286
|
weight: "normal"
|
|
3933
|
-
}, t("webhook.description")));
|
|
1287
|
+
}, t("neetoWebhooks.webhook.description")));
|
|
3934
1288
|
};
|
|
3935
1289
|
var Header$1 = /*#__PURE__*/React__default["default"].memo(Header);
|
|
3936
1290
|
|
|
3937
|
-
var Menu = neetoui.Dropdown.Menu,
|
|
3938
|
-
MenuItem = neetoui.Dropdown.MenuItem;
|
|
3939
|
-
var WebhookItem = function WebhookItem(_ref) {
|
|
3940
|
-
var webhook = _ref.webhook,
|
|
3941
|
-
onDeleteClick = _ref.onDeleteClick,
|
|
3942
|
-
onEditClick = _ref.onEditClick,
|
|
3943
|
-
deliveriesPath = _ref.deliveriesPath;
|
|
3944
|
-
var _useTranslation = useTranslation(),
|
|
3945
|
-
t = _useTranslation.t;
|
|
3946
|
-
return /*#__PURE__*/React__default["default"].createElement(reactRouterDom.Link, {
|
|
3947
|
-
className: "neeto-ui-rounded-lg neeto-ui-border-gray-300 flex cursor-pointer items-center justify-between gap-4 border px-4 py-2",
|
|
3948
|
-
to: utils.buildUrl(deliveriesPath, {
|
|
3949
|
-
webhookId: webhook.id
|
|
3950
|
-
})
|
|
3951
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3952
|
-
className: "neeto-ui-text-primary-800 break-all",
|
|
3953
|
-
component: "span",
|
|
3954
|
-
style: "body1"
|
|
3955
|
-
}, webhook.endpoint), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3956
|
-
onClick: function onClick(e) {
|
|
3957
|
-
e.preventDefault();
|
|
3958
|
-
e.stopPropagation();
|
|
3959
|
-
}
|
|
3960
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Dropdown, {
|
|
3961
|
-
buttonStyle: "text",
|
|
3962
|
-
icon: neetoIcons.MenuHorizontal
|
|
3963
|
-
}, /*#__PURE__*/React__default["default"].createElement(Menu, null, /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
|
|
3964
|
-
onClick: function onClick() {
|
|
3965
|
-
return onEditClick(webhook.id);
|
|
3966
|
-
}
|
|
3967
|
-
}, t("operation.edit")), /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
|
|
3968
|
-
onClick: function onClick() {
|
|
3969
|
-
return onDeleteClick(webhook.id);
|
|
3970
|
-
}
|
|
3971
|
-
}, t("operation.delete"))))));
|
|
3972
|
-
};
|
|
3973
|
-
var WebhookItem$1 = /*#__PURE__*/React__default["default"].memo(WebhookItem);
|
|
3974
|
-
|
|
3975
1291
|
var Webhooks = function Webhooks(_ref) {
|
|
3976
1292
|
var deliveriesPath = _ref.deliveriesPath,
|
|
3977
1293
|
entityType = _ref.entityType,
|
|
@@ -3993,14 +1309,25 @@ var Webhooks = function Webhooks(_ref) {
|
|
|
3993
1309
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
3994
1310
|
isDeleteAlertOpen = _useState8[0],
|
|
3995
1311
|
setIsDeleteAlertOpen = _useState8[1];
|
|
3996
|
-
var
|
|
1312
|
+
var _useState9 = React.useState(1),
|
|
1313
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
1314
|
+
pageNumber = _useState10[0],
|
|
1315
|
+
setPageNumber = _useState10[1];
|
|
1316
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
3997
1317
|
t = _useTranslation.t;
|
|
3998
|
-
var _useFetchWebhooks = useFetchWebhooks(
|
|
1318
|
+
var _useFetchWebhooks = useFetchWebhooks({
|
|
1319
|
+
entityId: entityId,
|
|
1320
|
+
page: pageNumber,
|
|
1321
|
+
limit: DEFAULT_PAGE_SIZE
|
|
1322
|
+
}),
|
|
3999
1323
|
isLoading = _useFetchWebhooks.isLoading,
|
|
1324
|
+
isFetching = _useFetchWebhooks.isFetching,
|
|
4000
1325
|
_useFetchWebhooks$dat = _useFetchWebhooks.data,
|
|
4001
1326
|
_useFetchWebhooks$dat2 = _useFetchWebhooks$dat === void 0 ? {} : _useFetchWebhooks$dat,
|
|
4002
1327
|
_useFetchWebhooks$dat3 = _useFetchWebhooks$dat2.webhooks,
|
|
4003
|
-
webhooks = _useFetchWebhooks$dat3 === void 0 ? [] : _useFetchWebhooks$dat3
|
|
1328
|
+
webhooks = _useFetchWebhooks$dat3 === void 0 ? [] : _useFetchWebhooks$dat3,
|
|
1329
|
+
_useFetchWebhooks$dat4 = _useFetchWebhooks$dat2.totalCount,
|
|
1330
|
+
totalCount = _useFetchWebhooks$dat4 === void 0 ? 0 : _useFetchWebhooks$dat4;
|
|
4004
1331
|
var _useDestroyWebhook = useDestroyWebhook({
|
|
4005
1332
|
onSuccess: function onSuccess() {
|
|
4006
1333
|
return setIsDeleteAlertOpen(false);
|
|
@@ -4023,43 +1350,48 @@ var Webhooks = function Webhooks(_ref) {
|
|
|
4023
1350
|
if (isLoading) {
|
|
4024
1351
|
return /*#__PURE__*/React__default["default"].createElement(PageLoader__default["default"], null);
|
|
4025
1352
|
}
|
|
4026
|
-
return /*#__PURE__*/React__default["default"].createElement("
|
|
4027
|
-
className: "w-full
|
|
4028
|
-
}, /*#__PURE__*/React__default["default"].createElement(
|
|
4029
|
-
className: "neeto-ui-bg-white sticky top-0 z-50 w-full"
|
|
4030
|
-
}), /*#__PURE__*/React__default["default"].createElement(Header$1, {
|
|
1353
|
+
return /*#__PURE__*/React__default["default"].createElement(Container__default["default"], {
|
|
1354
|
+
className: "w-full"
|
|
1355
|
+
}, /*#__PURE__*/React__default["default"].createElement(Header$1, {
|
|
4031
1356
|
breadcrumbs: breadcrumbs,
|
|
4032
1357
|
setIsAddWebhookPaneOpen: setIsAddWebhookPaneOpen
|
|
4033
|
-
}), /*#__PURE__*/React__default["default"].createElement("
|
|
4034
|
-
|
|
4035
|
-
},
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
}
|
|
4043
|
-
|
|
4044
|
-
|
|
1358
|
+
}), neetoCist.isNotEmpty(webhooks) ? /*#__PURE__*/React__default["default"].createElement(TableWrapper__default["default"], {
|
|
1359
|
+
hasPagination: totalCount > DEFAULT_PAGE_SIZE
|
|
1360
|
+
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Table, {
|
|
1361
|
+
totalCount: totalCount,
|
|
1362
|
+
fixedHeight: true,
|
|
1363
|
+
currentPageNumber: pageNumber,
|
|
1364
|
+
defaultPageSize: DEFAULT_PAGE_SIZE,
|
|
1365
|
+
handlePageChange: function handlePageChange(page) {
|
|
1366
|
+
return setPageNumber(page);
|
|
1367
|
+
},
|
|
1368
|
+
loading: isFetching,
|
|
1369
|
+
rowData: webhooks,
|
|
1370
|
+
columnData: buildColumns({
|
|
1371
|
+
handleDelete: handleDelete,
|
|
1372
|
+
handleEdit: handleEdit,
|
|
1373
|
+
deliveriesPath: deliveriesPath
|
|
1374
|
+
})
|
|
1375
|
+
})) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1376
|
+
className: "flex h-full w-full items-center justify-center"
|
|
4045
1377
|
}, /*#__PURE__*/React__default["default"].createElement(neetoui.NoData, {
|
|
4046
|
-
title: t("webhook.empty")
|
|
4047
|
-
}))
|
|
1378
|
+
title: t("neetoWebhooks.webhook.empty")
|
|
1379
|
+
})), /*#__PURE__*/React__default["default"].createElement(AddWebhookPane, {
|
|
4048
1380
|
editingWebhookId: editingWebhookId,
|
|
4049
1381
|
entityId: entityId,
|
|
4050
1382
|
entityType: entityType,
|
|
4051
|
-
isOpen: isAddWebhookPaneOpen,
|
|
4052
1383
|
webhooks: webhooks,
|
|
1384
|
+
isOpen: isAddWebhookPaneOpen,
|
|
4053
1385
|
onClose: handlePaneClose
|
|
4054
1386
|
}), /*#__PURE__*/React__default["default"].createElement(neetoui.Alert, {
|
|
4055
1387
|
isOpen: isDeleteAlertOpen,
|
|
4056
1388
|
isSubmitting: isDeleting,
|
|
4057
|
-
submitButtonLabel: t("buttons.delete"),
|
|
4058
|
-
message: t("alert.delete.message", {
|
|
4059
|
-
entity: t("entity.webhook")
|
|
1389
|
+
submitButtonLabel: t("neetoWebhooks.buttons.delete"),
|
|
1390
|
+
message: t("neetoWebhooks.alert.delete.message", {
|
|
1391
|
+
entity: t("neetoWebhooks.entity.webhook")
|
|
4060
1392
|
}),
|
|
4061
|
-
title: t("alert.delete.title", {
|
|
4062
|
-
entity: t("entity.webhook")
|
|
1393
|
+
title: t("neetoWebhooks.alert.delete.title", {
|
|
1394
|
+
entity: t("neetoWebhooks.entity.webhook")
|
|
4063
1395
|
}),
|
|
4064
1396
|
onClose: function onClose() {
|
|
4065
1397
|
return setIsDeleteAlertOpen(false);
|